<?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";

if (!authen())
{ header ("location: login.php");
		}
else
{ $userlist="";
		$quser="SELECT * 
										FROM $db_appusergroups 
										WHERE usergroupid<>'1' 
										ORDER BY usergroupname ASC
										";
		$ruser=mysqli_query($dbConnection, $quser);
		$datataken=mysqli_num_rows($ruser);
		if (mysqli_num_rows($ruser)>0)
		{ while ($groupdata=mysqli_fetch_array($ruser))
				{ $userlist.="<tr>
																			<td align='left' valign='top'>
																				<a href='user_group_menu.php?menuid=".$_GET['menuid']."&idgroup=".$groupdata['usergroupid']."&namagroup=".$groupdata['usergroupname']."' style='text-decoration:none'>
																					<img src='images/zoom_in.png' align='absmiddle' title='Detail'>
																				</a> &nbsp; ".$groupdata['usergroupname']."
																			</td>
																			";
						if (fullaccess($_GET['menuid'], $_SESSION['SES_GROUPID']) || editaccess($_GET['menuid'], $_SESSION['SES_GROUPID']))
						{ $userlist.="<td align='center' valign='top' nowrap>
																					<a href='user_group_edit.php?menuid=".$_GET['menuid']."&idgroup=".$groupdata['usergroupid']."&menuid=".$_GET['menuid']."'><img src='images/database_edit.png' align='absmiddle' title='Edit'></a>
																				</td>
																				";
								}
						else
						{ $userlist.="<td></td>";
								}
						if (fullaccess($_GET['menuid'], $_SESSION['SES_GROUPID']) || deleteaccess($_GET['menuid'], $_SESSION['SES_GROUPID']))
						{ $tablenameusr=$db_appusers;
								$fieldArrayusr=array("userid");
								$conditionusr="usergroupid='".$groupdata['usergroupid']."'";
								$orderArrayusr=array();
								$orderruleusr="";
								$limitusr="";
								$selectdbusr=simpleselect($tablenameusr, $fieldArrayusr, $conditionusr, $orderArrayusr, $orderruleusr, $limitusr);
								if (mysqli_num_rows($selectdbusr)==0)
								{ $delusr="<a href='user_group_delete.php?menuid=".$_GET['menuid']."&idgroup=".$groupdata['usergroupid']."&menuid=".$_GET['menuid']."'>
																				<img src='images/database_delete.png' align='absmiddle' title='Hapus'>
																			</a>
																			";
										}
								else
								{ $delusr="<a href=\"javascript:window.alert('Masih ada user dalam group ini.')\">
																				<img src='images/database_delete.png' align='absmiddle' title='Hapus'>
																			</a>
																			";
										}
								$userlist.="<td align='center' valign='top' nowrap>
																					".$delusr."
																				</td>
																				";
								}											
						else
						{ $userlist.="<td></td>";
								}
						$userlist.="</tr>";
						}
				}
		else
		{ $userlist.="<tr>
																	<td align='center' valign='middle' colspan='5' nowrap>
																		<br>Group admin tidak ditemukan.<br><br>
																	</td>
																</tr>
																";
				}			

		$qq="SELECT a.appmenuname, b.parentmenuname FROM $db_appmenus a, $db_parent_menus b ";
		$qq.="WHERE a.appmenuid='".mysqli_real_escape_string($dbConnection, $_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']."</b>
															<br><hr size='1' color='#000000'><br>
															<table border='0' cellpadding='0' cellspacing='0' width='100%'>
																<tr>
																	<td align='left' valign='top' width='100%'>
																	";
		if (fullaccess($_GET['menuid'], $_SESSION['SES_GROUPID']) || addaccess($_GET['menuid'], $_SESSION['SES_GROUPID']))
		{ $content.="<input type='button' value=' Tambah Group Admin ' onclick=\"document.location='user_group_add.php?menuid=".$_GET['menuid']."'\"><br><br>";
				}
		$content.="<table id='' class='display'>
														<thead>
															<tr>
																<th align='center' valign='middle' nowrap>
																	<b>Nama Group</b>
																</th>
																<th align='center' valign='middle' width='50px' nowrap>
																	<b>Edit</b>
																</th>
																<th align='center' valign='middle' width='50px' nowrap>
																	<b>Hapus</b>
																</th>
															</tr>
														</thead>
														<tbody>	
															".$userlist."
														</tbody>	
													</table>
												</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();

?>