Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64
Your IP : 18.118.205.123
<?php
include ("../database.php");
session_start();
if(isset($_SESSION['REGNO']) && $_SESSION['UNIVCODE'])
{
$final['UNIVCODE'] = $_SESSION['UNIVCODE'];
$final['FUNIVNAME'] = $_SESSION['UNIVNAME'];
$menu_query = "select funivcode, fid, fposition, fmenuid, fclickfuctn, fsubmenu,fismainmenu,
ficon, fdispname from menu_schema_new
where funivcode = '{$_SESSION['UNIVCODE']}'
and factive = 'T' and fmodtype = 'web'
order by forder";
$menu_result = mysqli_query($conn, $menu_query);
$menu = array();
$arr = array();
$val = array();
//================================ OLD code =================//
// $i = 0;
// while($row1 = mysqli_fetch_assoc($menu_result))
// {
// $menu[$i] = $row1;
// $i++;
// }
// $row['menu'] = $menu;
// $row['status'] = 'loggedin';
// echo json_encode($row);
//============= new code ========================//
$prevparnt = "";
$i = 0;
while($row1 = mysqli_fetch_assoc($menu_result))
{
$menu[$i] = $row1;
$i++;
if ($row1['fsubmenu'] == "F") {
$arr[$row1['fid']]['children'] = array() ;
$arr[$row1['fid']]['icon'] = $row1['ficon'];
$arr[$row1['fid']]['name'] = $row1['fdispname'];
$arr[$row1['fid']]['url'] = $row1['fclickfuctn'];
$arr[$row1['fid']]['fmenuid'] = $row1['fmenuid'];
}
else {
$parnt = substr($row1['fposition'],0,2);
$prevparnt = $parnt;
// $prevparnt == $parnt ? $arr[$parnt]['children'] = array() :$arr[$parnt]['children'];
$val['icon'] = $row1['ficon'];
$val['url'] = $row1['fclickfuctn'];
$val['name'] = $row1['fdispname'];
$val['fmenuid'] = $row1['fmenuid'];
array_push($arr[$parnt]['children'], $val);
// $prevparnt = $parnt;
// var_dump($arr);
}
}
// var_dump($arr);
$res = array();
$i = 0;
foreach ($arr as $value) {
$res[$i] = $value;
$i++;
}
$final['status'] = 'loggedin';
$final['menu'] = $res;
echo json_encode($final);
}
else
{
$row['status'] = 'loggedout';
echo json_encode($row);
}
|