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

session_start(); 
$id=$_SESSION["stask"] ;
if ($_POST["command"]){
$action=$_POST["command"];
}else{
$action=$_SESSION["saction"] ;
}
if ($_GET["form"]){
	$form1=$_GET["form"];
}else{
	$form1=$_SESSION["sform"] ;
}


$sodtel=0;
$transtel=0;

if ($form1=="task_edit"){
		if ($action == "Cancel") {
		header('Location: task_list.php');
	} else{
		$id=$_POST["id"] ;
		$taskname = $_POST["taskname"] ;
		$taskdesc = $_POST["taskdesc"] ;
		$reftaskid = $_POST["reftask"] ;
		
		$error_txt = '';
		if ($taskname =="" ){
			$error_txt = "Taskname can not be blank";
		} else{
			if ($id==0){
				$sql = "select * from erptask where upper(taskname)=upper('$taskname')" ;
				$result = mysql_query($sql);
				$num_rows = mysql_num_rows($result);

				if ($num_rows ==0){
					$sql="INSERT INTO erptask (taskname,taskdesc,reftaskid) VALUES ( '$taskname','$taskdesc',$reftaskid)";
					$result = mysql_query($sql);
				}
			} else{
				$sql="UPDATE erptask SET taskname='$taskname', taskdesc='$taskdesc', reftaskid=$reftaskid WHERE taskid = $id";
				$result = mysql_query($sql);
			} 
		}
		header('Location: task_list.php');
	}
} else {
	if ($form1<>"task_list"){
		header('Location: task_list.php');
	}
	if ($action == "New"){
		$id = 0;
		$taskname= "";
		$taskdesc="";
		$reftask = 0;
	}
	if ($action == "Delete"){
		$sql="DELETE FROM erptask WHERE taskID = $id";
		$result = mysql_query($sql);
		$sql="delete from tasksod where taskid = $id";
		$result = mysql_query($sql);
		$sql="delete from tasksod where sodid = $id";
		$result = mysql_query($sql);
		header('Location: task_list.php');
	}
	if ($action == "Edit"){
		$sql="SELECT * FROM erptask WHERE taskID = $id";
		$result = mysql_query($sql);
		$num_rows = mysql_num_rows($result);
		if ($num_rows <>0){
			$row = mysql_fetch_row($result);
			$id = $row[0];
			$taskname= $row[1];
			$taskdesc = $row[2];
			$reftaskid = $row[3];
			$sql1 ="select taskname,mitigated from erptask,tasksod where tasksod.sodid=erptask.taskid and tasksod.taskid=$reftaskid";
			$result1 = mysql_query($sql1);
			$sodtel = 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>Tasks</h3></center>
<?php
if ($error_txt <>""){
	echo $error_txt ;
	echo "<br>";
}
?>
<FORM ACTION="task_edit.php?form=task_edit" METHOD="POST">
<INPUT TYPE="HIDDEN" NAME="id" VALUE="<?php echo $id ?>">
<center>
<table border=0 cellpadding=4 cellspacing=0 bgcolor="AQUA"><tr><td>
<tr>
<td>Task name</td>
<td><Input Name="taskname" MaxLength="50" Size="50" Value="<?php echo $taskname ?>"></td>
</tr>
<tr>
<td>Task description</td>
<td colspan=2><textarea rows="2" name="taskdesc" cols="75"><?php echo $taskdesc ?></textarea></td>
</tr>
<tr>
<td>Reference Task</td>
<td>
<?PHP echo html_drop_down(1,"reftask","erptask","taskid","taskname",0,"Not yet Assigned",$reftaskid); ?>
</td>
</tr>
<br>
<?php 
if ($id <>0){ ?>
	<tr >
	<?php
	if ($id==$reftaskid){
	?>
		<td><u><a href="soddep.php" >Maintain Conficting Tasks for this task</a></u></td>
	<?php
	} else {
	?>
		<td><u>Conficting Tasks for this task</u></td>
	<?PHP
	}
	?>
	<td align="right"><u><a href="transdep.php" >View/Maintain Transactions for this task</a></u>&nbsp;&nbsp;&nbsp;&nbsp;<u><a href="userdep.php" >View Users for this task</a></u></td>
	</tr>
<?PHP } 
If ($sodtel>0){
	while ($row1 = mysql_fetch_array($result1, MYSQL_NUM)) {
		?>
		<tr>
		<?php
		if ($row1[1]== "Y"){
			?>
			<td bgcolor="ORANGE" Nowrap>
		<?php }else{ ?>
			<td bgcolor="RED" Nowrap>
		<?php } 
		echo $row1[0];
		?>
		</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>
</center>
</FORM>
</BODY>
<?php
include_once("footer.php");
?>
</HTML>
Return current item: ERPSOD