Location: PHPKode > projects > MembersGear > membersgear/admin/admin_treeview.php
<script language="javascript" type="text/javascript">
     
      
      function toggleVisibility(tblId,imgDir)
       {
           var tbl=document.getElementById(tblId);
            if(tbl.style.display == 'none')
              {
                var  imgid="img"+tblId;
                var imgdir=imgDir+"/subtract.gif";
                 document.getElementById(tblId).style.display = 'block';
                 var imgDest = document.getElementById(imgid);
                  imgDest.setAttribute("src", imgdir);
              }
            else
             {
                 var  imgid="img"+tblId;
                 var imgdir=imgDir+"/add.gif";
                 document.getElementById(tblId).style.display = 'none' ;
                  var imgDest = document.getElementById(imgid);
                  imgDest.setAttribute("src", imgdir);
             } 

          
       }
       
      
       
       function validateCategories(checkedValue,key)
       {
           
            var checkCategories=0;
            var Categories = document.getElementsByName('Categories[]');
            for(i=0;i<Categories.length;i++)
            {
                if(Categories[i].checked==true)
                    checkCategories +=1;
            }
            
            if(checkCategories>2)
            {
                alert('You cannot select more than two categories');
                return false;   
            }    
       }
       
       
      
</script>
<?php
  require_once "../config/config.php";
  require_once(INCLUDE_DIR.'/PaygearWebserviceClient.php');
  $PaygearWebserviceClient = new PaygearWebserviceClient();
  
 //echo '<pre>';
  //print_r($PaygearWebserviceClient->GetCategories());
 //echo '<pre>'; 
    $arr=$PaygearWebserviceClient->GetCategories(); 
    $arryLength=sizeof($arr);
    if($arryLength>0)
    {

            echo "<br><table style=\"width:500px\" cellpadding=\"0\" cellspacing=\"0\">";

             foreach($arr as $key=>$value)
            { 
                $len=sizeof($value);                          
               // echo "<tr>"; 
                for($i=0;$i<$len;$i++)
                 {
                    if($i==2)
                    {
                         if($value[$i]==0)
                         {
                           $imgDir=ADMIN_IMAGE_DIR;  
                          echo  "<tr><td  width=\"500px\"><img src=".ADMIN_IMAGE_DIR."/add.gif width=14px 
                          onclick=\"toggleVisibility( $value[0],'$imgDir')\" id=\"img$value[0]\" style=\"cursor:pointer;\">
                          <font style=\"font-weight:bold\">".$value[1]."</font></td></tr><tr><td>";
                           echo  getChilds($value[0],$arr);
                           echo "</td></tr>";
                        
                         }
                    }    
                 
                 }
                // echo "</tr>";
                
            } 
            echo "</table>";
            echo '<pre>';
    }
    else
     echo "Error Occured No data retrived from web service.Please try again later ";     

    function getChilds($pClientId,$arry)
     {
           
         $arr=$arry;
        $string.="<table id=$pClientId style=\"display:none\">"; 
        $counter=0;
        foreach($arr as $key=>$value)
        { 
           $len=sizeof($value);
           //$string.="<tr><td>&nbsp;</td><td>";
            
            for($i=0;$i<$len;$i++)
             {
                
                   if($i==2)
                   {  
                         if($value[$i]==$pClientId)
                          {
                              $string.="<tr><td width=\"30px\">&nbsp;</td><td>";
                              $string.="<input type=checkbox id=\"Categories\" name=\"Categories[]\" value=$value[0] onclick=\"return validateCategories(this.value,$counter)\">";
                              $string.=$value[1];
                              $string.="</td></tr>";
                              $counter++;
                          }
                   }
             }
             
                      
        }
        
         $string.="</table>";   
        return $string;
        
     }           
                  
 
 

?>
Return current item: MembersGear