<script>
			function load_page(xurl,cap)
			{
				
				document.forms.myform.action = xurl;
				document.forms.myform.submit();
			}
</script>
<?php

			echo'<div id="testdiv" style="float:right;">';
			//~ function chckmenu($menidx, $usrcde, $comcde)
			//~ {
				//~ // ini_set("display_errors", true);
				//~ // error_reporting(E_ALL);
				//~ global $link_id;
				//~ $xret = false;
				//~ $sql_check = "SELECT * FROM approvermenus WHERE menidx = ? AND usrcde = ? AND comcde = ?";
				//~ $stmt_check = $link_id->prepare($sql_check);
				//~ $stmt_check->execute(array($menidx, $usrcde, $comcde));
			//~ 
				//~ if($stmt_check->fetch())
				//~ {
					//~ 
					//~ $xret = true;
					//~ 
				//~ }
				//~ return $xret;
			//~ }
			function chckmaxcol($menrow)
			{
				// ini_set("display_errors", true);
				// error_reporting(E_ALL);
				global $link_id;
				$xret = false;
				$sql_check = "select max(mencol) as col from menus where menrow =?";
				$stmt_check = $link_id->prepare($sql_check);
				$stmt_check->execute(array($menrow));
			
				$xrs=$stmt_check->fetch();
				$xret = $xrs['col'];
				
				return $xret;
			}
			function countcol($menrow)
			{
				// ini_set("display_errors", true);
				// error_reporting(E_ALL);
				global $link_id;
				$xret = false;
				$sql_check = "select count(mencol) as col from menus where menrow =?";
				$stmt_check = $link_id->prepare($sql_check);
				$stmt_check->execute(array($menrow));
			
				$xrs=$stmt_check->fetch();
				$xret = $xrs['col'];
				
				return $xret;
			}
			function chckcolexist($menrow,$mencol)
			{
			   global $link_id;
				$xret = false;
				$sql_check = "select * from menus where menrow =? and mencol=?";
				$stmt_check = $link_id->prepare($sql_check);
				$stmt_check->execute(array($menrow,$mencol));
			
				if($stmt_check->fetch())
				{
					$xret = true;	
				}else{
					$xret=false;
				}
				return $xret;
			}
			$menufile = 'menus';
			$xusercde = $_SESSION[$xg_appkey]['usrcde'];
			$xqryfilter = ' AND modcde = ?  ';
			$arr_qry_params = array('multi');
			$xqry = "SELECT count(*) AS xcount,MAX(menrow) as row,MAX(mencol) as col FROM $menufile WHERE menidx!='x' $xqryfilter";
			$stmt = $link_id->prepare($xqry);
			$stmt->execute(array('multi'));
			$rs_max = $stmt->fetch();
			
				
			if(intval($rs_max['xcount'])==0)
			{
			    echo "Sorry, You don't have access :p";
			}
           
				
				//~ for($x=1;$x<=$rs_xx['row'];$x++)
				//~ {
					//~ echo'<table class="menutable" border=1 style="margin-top:20px;" align="center">';
					//~ echo"<tr>";
					//~ for($y=1;$y<=$rs_xx['col'];$y++)
					//~ {
						//~ $xqry = "SELECT * FROM $menufile WHERE menidx!='x' AND (usrtyp LIKE '%".$_SESSION[$xg_appkey]['usrtyp']."%' OR usrtyp2 = '".$_SESSION[$xg_appkey]['usrtyp2']."') $xqryfilter AND mengrp ='01' AND mencol=".$y." AND menrow=".$x." ORDER BY menrow,mencol asc;";
						//~ $stmt = $link_id->prepare($xqry);
						//~ $stmt->execute($arr_qry_params);
                  //~ $rs = $stmt->fetch();
                  //~ echo"<td width='20%'>";
                  //~ echo "<h4>{$rs['mencap']}</h4>";
                  //~ echo"</td>";
                  //~ var_dump(chckcolexist($x,$y));
                  if(!chckcolexist($x,$y))
                  {
							echo"<td></td>";
                  }
					//~ }
					//~ echo"</tr>";
					//~ echo"</table>";
				//~ }
				echo'<table class="menutable" border=0 style="margin-top:20px;" align="center">';	
				for($x=1;$x<=$rs_max['row'];$x++)
				{
					echo"<tr>";
					for($y=1;$y<=$rs_max['col'];$y++)
					{
						
						$xqry = "SELECT * FROM $menufile WHERE menidx!='x' AND (usrtyp LIKE '%".$_SESSION[$xg_appkey]['usrtyp']."%' OR usrtyp2 = '".$_SESSION[$xg_appkey]['usrtyp2']."') $xqryfilter AND mengrp ='01' AND mencol=".$y." AND menrow=".$x." ORDER BY menrow,mencol asc;";
						$stmt = $link_id->prepare($xqry);
						$stmt->execute($arr_qry_params);
						$rs_men = $stmt->fetch();
						echo"<td width='25%' valign='top'>";
						if($rs_men['menprg']!='')
						{
							echo "<h4 class='hover1' onclick=\"load_page('".$rs_men['menprg']."')\" style='cursor:pointer;font-size:".$rs_men['fontsize']."px'>{$rs_men['mencap']}</h4>";
						}
						else
						{	
							echo "<h4 style='font-size:".$rs_men['fontsize']."px'>{$rs_men['mencap']}</h4>";
						}
						
							$sql = "SELECT * FROM menus WHERE mengrp = ? AND (usrtyp LIKE '%".$_SESSION[$xg_appkey]['usrtyp']."%' OR usrtyp2 = '".$_SESSION[$xg_appkey]['usrtyp2']."') ORDER BY menidx";
							$stmt = $link_id->prepare($sql);
							$stmt->execute(array($rs_men['mensub']));
							
							// var_dump($sql,$mensub);
							while($rs = $stmt->fetch())
							{
								
								$xbool = false;
								$par_action = $rs['menprg'];
								$par_mendsc = $rs['mencap'];
								if(strtoupper($rs['mengrp']) == 'APR00')
								{
									$xbool = chckmenu($rs['menidx'],$xusercde, $_SESSION[$xg_appkey]['comcde']);
								}
								else
								{
									$xbool= true;
								}
								if($xbool)
								{
									echo "<li style='list-style-type: none;'><a onclick=\"load_page('".$rs['menprg']."','".$par_mendsc."')\" >{$par_mendsc}</a></li>";
								}
						}
                  echo"</td>";
                  
					}
					echo"</tr>";
					echo"<tr style='height:10px'></tr>";
				}
				
					echo"</table>";	
           
          
            
            
			echo"</div>";
        ?>
