<?php require_once('../Connections/BE2.php'); ?>
<?php

function sel($cid){
require('../Connections/BE2.php');
mysql_select_db($database_BE2, $BE2);
$query_R2 = "SELECT * FROM jscookmenu WHERE cid = $cid ORDER BY idx ASC";
$R2 = mysql_query($query_R2, $BE2) or die(mysql_error());
$row_R2 = mysql_fetch_assoc($R2);
$totalRows_R2 = mysql_num_rows($R2);
$arr1=array();
$i=1;
do {
 $arr1[$i][0]=$row_R2['mid'];
 $arr1[$i][1]=$row_R2['cid']; 
 $arr1[$i][2]=$row_R2['title'];
 $arr1[$i][3]=$_SERVER["PHP_SELF"]."?id=".$row_R2['mid']; //$row_R2['link'];
 $arr1[$i][4]="_self";//$row_R2['link_tag']; 
 $i++;
  } while ($row_R2 = mysql_fetch_assoc($R2));
 if (count($arr1)<1 ){return 0; }else{return $arr1;} 
 
}

mysql_select_db($database_BE2, $BE2);
$query_R1 = "SELECT * FROM jscookmenu WHERE cid = 0 ORDER BY idx ASC";
$R1 = mysql_query($query_R1, $BE2) or die(mysql_error());
$row_R1 = mysql_fetch_assoc($R1);
$totalRows_R1 = mysql_num_rows($R1);
$arr2=array();
$mycc=0;
$c=0;
$menutxt='';
$menutxt .= '<script language="JavaScript" type="text/javascript">
var myMenu =
[';


 do {
   $c++;
   $chkc=$c;
   $currentPage = $_SERVER["PHP_SELF"]."?id=".$row_R1['mid'];
 //  $str1=$currentPage;
   
//   $str2="_self";
   $str1=$row_R1['link']<>'NULL'?"'".$row_R1['link']."'" :'null';
   $str2="'_self'" ;//
  // $row_R1['link_tag']<>''?"'".$row_R1['link_tag']."'" :'null';
   //if ($c<>0){ $menutxt .= '], _cmSplit,'."\n"; }
   $str0=$row_R1['pic']<>''?'\'<img name="" src="'.$row_R1['pic'].'" width="30" height="20" alt="" />\'':'null';
   $menutxt .= "[".$str0.", '".$row_R1['title']."', ".$str1 .",". $str2 .", null ";  
   $re2=($row_R1['mid']<>"")?sel($row_R1['mid']) :0;
   if ((count($re2)>0 )&&($re2[1][0]<>"")){
     $menutxt .=","; 
     for($i=1;$i<=count($re2);$i++){
	   if($re2[$i][0]<>""){  
	   $c++;
	   $str1=$re2[$i][3]<>''?"'".$re2[$i][3]."'" :'null';
	   $str2=$re2[$i][4]<>''?"'".$re2[$i][4]."'" :'null';
       $menutxt .= "[null, '".$re2[$i][2]."', ". $str1 .",". $str2 .", null"; 
       $re3=sel($re2[$i][0]);
	   if ((count($re3)>0 )&&($re3[1][0]<>"")){
	    $menutxt .=","; 
	    for($j=1;$j<=count($re3);$j++){
	      if($re3[$j][0]<>""){
	       
		   $str1=$re3[$j][3]<>''?"'".$re3[$j][3]."'" :'null';
	       $str2=$re3[$j][4]<>''?"'".$re3[$j][4]."'" :'null';		  
		   
		   $menutxt .= "[null, '".$re3[$j][2]."',". $str1 .",". $str2 .", null "; 
		   $re4=sel($re3[$j][0]) ;
		   if ((count($re4)>0 )&&($re4[1][0]<>"")){
		   $menutxt .=","; 
		    for($k=1;$k<=count($re4);$k++){
		      if($re4[$k][0]<>""){
			   $str1=$re4[$k][3]<>''?"'".$re4[$k][3]."'" :'null';
	           $str2=$re4[$k][4]<>''?"'".$re4[$k][4]."'" :'null';	
			  
               $menutxt .= "[null, '".$re4[$k][2]."',". $str1 .",". $str2 .", null "; 
		        }
		      $menutxt .="],\n";
			  }
		    }
			$menutxt .="],\n";
		  }
	   }
	   
	   }
	  $menutxt .="],\n";
	    
	 }
    }
   }

  $menutxt .= "], _cmSplit, \n"; 
 } while ($row_R1 = mysql_fetch_assoc($R1));


mysql_free_result($R1);
?>
<table width="165" height="300" border="0" align="left">
  <tr>
    <td width="159" valign="top" bgcolor="#B9E6F3"><div ID=myMenuID></div></td>
  </tr>
</table>
<?
//echo count($arr2)."<br>";
echo $menutxt .=" ] ;";
echo "cmDraw ('myMenuID', myMenu, 'vbr', cmThemeOffice, 'ThemeOffice');</script>";
?>

