<?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
{ $iduser=$_GET['iduser'];
		// Group name
		$tablename=$db_appusers;
		$fieldArray=array("userid", "fullname", "username", "userpass", "usergroupid", "useremail", "accessstatus");
		$condition="userid='".mysqli_real_escape_string($dbConnection, $iduser)."'";
		$orderArray=array();
		$orderrule="";
		$limit="";
		$selectdb=simpleselect($tablename, $fieldArray, $condition, $orderArray, $orderrule, $limit);
		$userdata=mysqli_fetch_array($selectdb);
		$usergroupid=explode("|", $userdata['usergroupid']);
		if ($userdata['accessstatus']==0)
		{ $checked1="";
				$checked2=" checked";
				}
		else if ($userdata['accessstatus']==1)
		{ $checked1=" checked";
				$checked2="";
				}
		// Web menu
		$menuname="";
		$n=1;
		$tablename=$db_appusergroups;
		$fieldArray=array("usergroupid", "usergroupname");
		$condition="usergroupid<>'1'";
		$orderArray=array("usergroupname");
		$orderrule="ASC";
		$limit="";
		$selectdb=simpleselect($tablename, $fieldArray, $condition, $orderArray, $orderrule, $limit);
		$grouplist="<select name='groupid[]' multiple='multiple' size='5' style='width:235px'>";
		while ($groupdata=mysqli_fetch_array($selectdb))
		{ if (in_array($groupdata['usergroupid'], $usergroupid))
				{ $selected=" selected='selected'";
						}
				else
				{ $selected="";
						}		
				$grouplist.="<option value='".$groupdata['usergroupid']."'".$selected.">".$groupdata['usergroupname']."</option>";
				}
		$grouplist.="</select>";		

		include "common/functions/funcpass.php";
		$newpassword=createnewpassword();
		
		$jscript="<script language='javascript'>
													function ubahpassword(n)
													{ if (n==1)
															{ document.getElementById('password1').value='".$newpassword."';
																	}
															else if (n==2)
															{ document.getElementById('password1').value='';
																	}
															}
												</script>
												";
				
		$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=$jscript.
											"<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'>
																		<form method='post' action='user_edit_process.php?iduser=".$iduser."&menuid=".$_GET['menuid']."' style='padding:0; margin:0'>
																			<table border='0' cellpadding='4px' cellspacing='1px'>
																				<tr>
																					<td align='left' valign='middle' nowrap>
																						Nama Lengkap
																					</td>
																					<td align='left' valign='middle'>
																						:
																					</td>
																					<td align='left' valign='middle'>
																						<input type='text' name='fullname' value='".$userdata['fullname']."' style='width:235px'>
																					</td>
																				</tr>
																				<tr>
																					<td align='left' valign='top' nowrap>
																						Group Admin
																					</td>
																					<td align='left' valign='top'>
																						:
																					</td>
																					<td align='left' valign='top'>
																						".$grouplist."
																					</td>
																				</tr>
																				<tr>
																					<td align='left' valign='middle' nowrap>
																						Username
																					</td>
																					<td align='left' valign='middle'>
																						:
																					</td>
																					<td align='left' valign='middle'>
																						<input type='text' name='username' value='".$userdata['username']."' style='width:235px'>
																					</td>
																				</tr>
																				<tr>
																					<td align='left' valign='middle' nowrap>
																						Password
																					</td>
																					<td align='left' valign='middle'>
																						:
																					</td>
																					<td align='left' valign='middle'>
																						<input type='text' id='password1' name='password1' style='width:235px' readonly>
																						&nbsp;
																						<a href='javascript:ubahpassword(1)'>Ubah Password</a> &nbsp; | &nbsp;
																						<a href='javascript:ubahpassword(2)'>Batal</a>
																					</td>
																				</tr>
																				<tr>
																					<td align='left' valign='middle' nowrap>
																						Alamat Email
																					</td>
																					<td align='left' valign='middle'>
																						:
																					</td>
																					<td align='left' valign='middle'>
																						<input type='text' name='useremail' value='".$userdata['useremail']."' style='width:235px'>
																					</td>
																				</tr>
																				<tr>
																					<td align='left' valign='top' nowrap>
																						Status
																					</td>
																					<td align='left' valign='top'>
																						:
																					</td>
																					<td align='left' valign='middle'>
																						<input type='radio' name='status' value='1'".$checked1."> Aktif &nbsp;
																						<input type='radio' name='status' value='0'".$checked2."> Tidak Aktif
																					</td>
																				</tr>
																				<tr>
																					<td></td>
																					<td></td>
																					<td align='left' valign='middle'>
																						<br>
																						<input type='submit' value=' Simpan '> &nbsp;
																						<input type='button' value=' Batal ' onclick='history.back(-1)'>
																					</td>
																				</tr>
																			</table>
																		</form><br><br>
																	</td>
																</tr>	
															</table>		
														</td>
													</tr>
												</table>
												";
		
		include "webmenu.php";
		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();

?>