<?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/funcdeletedb.php";
include "common/functions/funcauthen.php";

if (!authen())
{ header ("location: login.php");
		}
else
{ if ($_POST['idgroup']!="")
		{ $idgroup=explode ("|", rtrim($_POST['idgroup'], "|"));
				$idgroupvalue=$_POST['idgroup'];
				}
		else
		{ $idgroup=explode ("|", rtrim($_GET['idgroup'], "|"));
				$idgroupvalue=$_GET['idgroup'];
				}
		$konfirmasi=isset($_GET['konfirmasi']) ? $_GET['konfirmasi'] : NULL;
		if ($konfirmasi=="")
		{ $cond="";
				$jmlhid=count($idgroup);
				$a=1;
				foreach ($idgroup as $id)
				{ $cond.="usergroupid='".mysqli_real_escape_string($dbConnection, $id)."'";
						if ($a<$jmlhid)
						{ $cond.=" OR ";
								}
						$a++;
						}
				// Group name
				$groupname="";
				$b=1;
				$tablename=$db_appusergroupapprovals;
				$fieldArray=array("usergroupname");
				$condition=$cond;
				$orderArray=array();
				$orderrule="";
				$limit="";
				$selectdb=simpleselect($tablename, $fieldArray, $condition, $orderArray, $orderrule, $limit);
				while ($groupdata=mysqli_fetch_array($selectdb))
				{ $groupname.=$groupdata['usergroupname'];
						$jmlidminussatu=$jmlhid-1;
						if ($b<$jmlidminussatu)
						{ $groupname.=", ";
								}
						else if ($b==$jmlidminussatu)
						{ $groupname.=" dan ";
								}
						$b++;
						}
				$msg="Anda yakin ingin menolak perubahan group admin <b>".$groupname."<b>?<br><br>";
				$msg.="<input type='button' value=' Lanjut ' onclick=\"document.location='user_group_reject.php?menuid=".$_GET['menuid']."&idgroup=".$idgroupvalue."&konfirmasi=ok'\"> &nbsp; ";
				$msg.="<input type='button' value=' Tidak ' onclick=\"document.location='user_group.php'\">";
				$resultstatus="Konfirmasi";
				}
		else
		{ $jmlhid=count($idgroup);
				// Group
				$cond="";
				$a=1;
				foreach ($idgroup as $id)
				{ $cond.="usergroupid='".mysqli_real_escape_string($dbConnection, $id)."'";
						if ($a<$jmlhid)
						{ $cond.=" OR ";
								}
						$a++;
						}
				// Otorisasi		
				$cond2="";
				$a2=1;
				foreach ($idgroup as $id)
				{ $cond2.="appgroupid='".mysqli_real_escape_string($dbConnection, $id)."'";
						if ($a2<$jmlhid)
						{ $cond2.=" OR ";
								}
						$a2++;
						}

				// Group
				$tablename=$db_appusergroupapprovals;
				$condition=$cond;
				$deletedb=simpledelete($tablename, $condition);
				
				if ($deletedb)
				{ // Otorisasi
						$tablename=$db_appauthorizationapproval;
						$condition=$cond2;
						$deletedb=simpledelete($tablename, $condition);
						$msg="Menolak perubahan group admin sukses.";
						}
				else
				{ $msg="Menolak perubahan group admin gagal.<br><br>".$linkback;
								}		
				}		

		$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'>
																<tr>
																	<td align='left' valign='top' width='45%'>
																		".$msg."
																		<br><br><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();

?>