<?php

session_name("SIGNADMAUTH");
session_start();

include "common/config/config.php";
include "common/config/dbconfig.php";
include "common/functions/funcconnect.php";
openDB();

include "common/functions/funcselectdb.php";
include "common/functions/funcauthen.php";
include "common/functions/funcvalidateinput.php";

if (!authen())
{ header ("location: login.php");
		}
else
{ $idgroup=isset($_GET['idgroup']) ? cleanval($_GET['idgroup']) : NULL;
		$namagroup=isset($_GET['namagroup']) ? cleanval($_GET['namagroup']) : NULL;
		$userlist="";
		$qm="SELECT * FROM $db_parent_menu ORDER BY parentmenuid ASC";
		$rm=mysqli_query($dbConnection, $qm);
		while ($dm=mysqli_fetch_array($rm))
		{ $userlist.="<tr>
																	<td align='left' valign='middle' colspan='5'>
																		".$dm['parentmenuname']."
																	</td>
																</tr>	
																";
				// ambil data sub menu
				$qsm="SELECT * 
										FROM $db_appmenu 
										WHERE parentid='".$dm['parentmenuid']."' 
																AND parentid<>'0' 
										ORDER BY appmenuid ASC";
				$rsm=mysqli_query($dbConnection, $qsm);
				while ($dsm=mysqli_fetch_array($rsm))
				{ $baca="<img src='images/bullet_white.png'>";
						$tambah="<img src='images/bullet_white.png'>";
						$edit="<img src='images/bullet_white.png'>";
						$hapus="<img src='images/bullet_white.png'>";
						// ambil data hak akses
						$qha="SELECT * 
												FROM $db_appauthorization 
												WHERE appgroupid='".$idgroup."' 
																		AND appmenuid='".$dsm['appmenuid']."'
												";
						$rha=mysqli_query($dbConnection, $qha);
						if (mysqli_num_rows($rha)>0)
						{ $dha=mysqli_fetch_array($rha);
								if ($dha['semua']==1)
								{ $baca="<img src='images/bullet_green.png'>";
										$tambah="<img src='images/bullet_green.png'>";
										$edit="<img src='images/bullet_green.png'>";
										$hapus="<img src='images/bullet_green.png'>";
										}
								else
								{ if ($dha['baca']==1)
										{ $baca="<img src='images/bullet_green.png'>";
												}
										if ($dha['tambah']==1)
										{ $tambah="<img src='images/bullet_green.png'>";
												}
										if ($dha['edit']==1)
										{ $edit="<img src='images/bullet_green.png'>";
												}
										if ($dha['hapus']==1)
										{ $hapus="<img src='images/bullet_green.png'>";
												}
										}
								}
						$userlist.="<tr>
																			<td align='left' valign='middle' style='padding-left:15px'>
																				".$dsm['appmenuname']."
																			</td>
																			<td align='center' valign='middle' nowrap>
																				".$baca."
																			</td>
																			<td align='center' valign='middle' nowrap>
																				".$tambah."
																			</td>
																			<td align='center' valign='middle' nowrap>
																				".$edit."
																			</td>
																			<td align='center' valign='middle' nowrap>
																				".$hapus."
																			</td>
																		</tr>	
																		";
						}
				}
		
		$qq="SELECT a.appmenuname, b.parentmenuname FROM $db_appmenus a, $db_parent_menus b 
							WHERE a.appmenuid='".cleanval($_GET['menuid'])."' AND b.parentmenuid=a.parentid
							";
		$rr=mysqli_query($dbConnection, $qq);
		$dd=mysqli_fetch_array($rr);

		$content="<table border='0' cellpadding='6px' cellspacing='0' width='100%'>
													<tr>
														<td align='left' valign='top' width='100%'>
															<b class='title'>".$dd['parentmenuname']." &gt; ".$dd['appmenuname']." &gt; ".$namagroup."</b>
															<br><hr size='1' color='#000000'><br>
															<table border='0' cellpadding='0' cellspacing='0'>
																<tr>
																	<td align='left' valign='top'>
																		".$linkback."<br><br><br>
																		<table border='1' bordercolor='#cfcfcf' cellpadding='6px' cellspacing='0' style='border-collapse:collapse'>
																			<tr bgcolor='#efefef'>
																				<td align='center' valign='middle' width='150px' nowrap>
																					<b>Nama Menu Aplikasi</b>
																				</td>
																				<td align='center' valign='middle' width='50px' nowrap>
																					<b>Baca</b>
																				</td>
																				<td align='center' valign='middle' width='50px' nowrap>
																					<b>Tambah</b>
																				</td>
																				<td align='center' valign='middle' width='50px' nowrap>
																					<b>Edit</b>
																				</td>
																				<td align='center' valign='middle' width='50px' nowrap>
																					<b>Hapus</b>
																				</td>
																			</tr>
																			".$userlist."
																		</table><br>
																	</td>
																</tr>
															</table>		
														</td>
													</tr>
												</table>
												";
		}
		
include "webmenu.php";
include "common/include/template.php";
$temp=new template;
$temp->define_theme("themes/theme1.html");
$temp->define_tag("{PAGETITLE}", $namaaplikasi);
$temp->define_tag("{NAMAUSER}", strtoupper($_SESSION['SES_FULLNAME']));
$temp->define_tag("{APPMENU}", $webmenu);
$temp->define_tag("{APPCONTENT}", $content);
$temp->parse();
$temp->printproses();

closeDB();

?>