<?php 
    switch ($sf_context->getActionName()) {
        case 'list':
            $c = new Criteria();
            $c->add(TblcategoryPeer::CG_PARENTID , -1);
            $cats = TblcategoryPeer::doSelect($c);
            $tree['']='';
            foreach ($cats as $cat){
                $tree[$cat->getCgId()] = $cat->getCgName();
            }
            $catSelected = $sf_params->get('filters');
        	//var_dump($userSelected);
        	if(isset($catSelected['cg_parentid']))
        	   $catSelected = $catSelected['cg_parentid'];
        	else 
        	   $catSelected='';
            echo select_tag("filters[cg_parentid]", options_for_select($tree, $catSelected));
            break;
           
        case 'edit':
            $c = new Criteria();
        	$cats = TblcategoryPeer::doselect( $c);
        	$tree['-1']='Root';
        	foreach ($cats as $key => $cat) {
        	    if($tblcategory->getCgId()!=$cat->getCgId())
        		  $tree[$cat->getCgId()] = str_repeat('&nbsp', 4*substr_count($cat->getCgFamily(), "/")) . '+' . $cat->getCgName();
        	}
        	//var_dump($tblcategory->getCgParentid());
        	echo select_tag('tblcategory[cg_parentid]', options_for_select($tree, $tblcategory->getCgParentid()));
            break;
    }

?>