Location: PHPKode > projects > ERPSOD > erpsod/user_edit2.php
<?PHP
include_once("config.php");

session_start(); // This connects to the existing session 
$id=$_SESSION ["suser"] ;
if ($_POST["command"]){
	$action=$_POST["command"];
}else{
	$action=$_SESSION ["saction"] ;
}
if ($_GET["form"]){
	$form1=$_GET["form"];
}else{
	$form1=$_SESSION ["sform"] ;
}

$tasktel=0;

if ($form1=="user_edit2"){
	if ($action == "Cancel") {
		header('Location: user_list2.php');
	} else{
		$id=$_POST["id"] ;
		$logonid = $_POST["logonid"] ;
		$name = $_POST["name"] ;
		$dept = $_POST["deptlist"] ;
		$unit = $_POST["unitlist"] ;
		$role = $_POST["rolelist"] ;
		$error_txt = '';
		
		if ($logonid =="" ){
			$error_txt = "Logonid can not be blank";
		} else{
			if ($id==0){
				$sql = "select * from erpuser where upper(logonid)=upper('$logonid')" ;
				$result = mysql_query($sql);
				$num_rows = mysql_num_rows($result);

				if ($num_rows ==0){
					$sql="INSERT INTO erpuser (logonid,name,deptid,unitid,roleid) VALUES ( '$logonid','$name',$dept,$unit,$role)";
					$result = mysql_query($sql);
				}
			} else{
				$sql="UPDATE erpuser SET name='$name', deptid=$dept, unitid=$unit, roleid=$role WHERE erpuserid = $id";
				$result = mysql_query($sql);
			} 
		}
		header('Location: user_list2.php');
	}
} else {
	if ($form1<>"user_list2"){
		header('Location: user_list2.php');
	}

	if ($action == "New"){
		$id = 0;
		$logonid= "";
		$name="";
		$dept=0;
		$unit=0;
		$role=0;
	}
	if ($action == "Delete"){
		$sql="DELETE FROM usertask WHERE erpuserid = $id";
		$result = mysql_query($sql);
		$sql="delete from erpuser where erpuserid = $id";
		$result = mysql_query($sql);
		header('Location: user_list2.php');
	}
	if ($action == "Edit"){
		$sql="SELECT * FROM erpuser WHERE erpuserid = $id";
		$result = mysql_query($sql);
		$num_rows = mysql_num_rows($result);
		if ($num_rows <>0){
			$row = mysql_fetch_row($result);
			$id1 = $row[0];
			$logonid= $row[1];
			$name = $row[2];
			$dept = $row[3];
			$unit = $row[4];
			$role = $row[5];
			$sql1 ="select usertask.taskid,taskname from usertask,erptask where usertask.taskid=erptask.taskid and usertask.erpuserid=$id1 order by taskname";
			$result1 = mysql_query($sql1);
			$tasktel = mysql_num_rows($result1);
		}
	}
}
?>
<HTML>
<HEAD>
<link rel="stylesheet" type="text/css" href="<?PHP echo $style ?>">
<script language="JavaScript1.2" src="js/coolmenus4.js">
</script>
</HEAD>
<body bgcolor="#ffffff">
<script language="JavaScript1.2" src="js/erpsod.js">
</script><br><br>
<center>
<h3>User</h3>
<?php
if ($error_txt <>""){
	echo $error_txt ;
	echo "<br>";
}
?>
<FORM ACTION="user_edit2.php?form=user_edit2" METHOD="POST">
<INPUT TYPE="HIDDEN" NAME="id" VALUE="<?php echo $id ?>">
<table border=0 cellpadding=4 cellspacing=0 bgcolor="AQUA"><tr><td>
<tr>
<td>Logonid</td>
<td><Input Name="logonid" MaxLength="25" Size="25" Value="<?php echo $logonid ?>"></td>
</tr>
<tr>
<td>Username</td>
<td><Input Name="name" MaxLength="25" Size="25" Value="<?php echo $name ?>"></td>
</tr>
<tr>
<td>Role</td><td>	
<?PHP echo html_drop_down(1,"rolelist","erprole","roleid","rolename","roleid","",$role); ?>
</td></tr>
<tr>
<td>Department</td>	<td>
<?PHP echo html_drop_down(1,"deptlist","erpdept","deptid","deptdesc","deptid","",$dept); ?>
</td></tr>
<tr>
<td>Unit</td><td>
<?PHP echo html_drop_down (1,"unitlist","erpunit","unitid","unitdesc","unitid","",$unit); ?>
</td></tr>
<br>
<?php 
if ($id <>0){ ?>
	<tr >
	<td align="right"><u><a href="usertask2.php" >Maintain Tasks for this User</a></u></td>
	</tr>
<?PHP } 
If ($tasktel>0){
	while ($row1 = mysql_fetch_array($result1, MYSQL_NUM)) {
		?>
		<tr>
		<?php
		$status=checksod2($id,$row1[0]);
		$stat = explode("|", $status);
		if ($stat[0]== "1"){
			?>
			<td bgcolor="GREEN" Nowrap>
		<?PHP }
		if ($stat[0]== "2"){
			?>
			<td bgcolor="ORANGE" Nowrap>
		<?php }
		if ($stat[0]== "3"){
			?>
			<td bgcolor="RED" Nowrap>
		<?php } 
		echo $row1[1];
		if ($stat[1]<>""){
			echo " <=> ";
			echo $stat[1];
		}
		?>
		</td></tr>
		<?PHP
	}
}
?>
<br>
<tr>
<td colspan=2 align="center">
<?php if (role_check("Updater")) { ?>
<INPUT TYPE="SUBMIT" NAME="command" VALUE="Submit">
<?PHP } ?>
<INPUT TYPE="SUBMIT" NAME="command" VALUE="Cancel">
</td></tr>
</table>
</td></tr></table>
</FORM>
</BODY>
<?php
include_once("footer.php");
?>
</HTML>
Return current item: ERPSOD