The next script that we will be looking at is the edit_project.php script. It is responsible for handling any changes that you want to make to a project. It has exactly the same form layout as the add_project.php script, except it needs to do a retrieve and update query. The reason for retrieving the project information in the first place is to display that information in a form. This way you know and see exactly what you want to change. For example, if the project name is 'ProjectX' and you want to change it to 'My Project,' then all you do is delete the 'Project X' name and add the 'My Project' name to that field. It just makes the chances of someone making the wrong entry very slim. Once you have changed the things you want, you simply click on the update button and the update query will spring into action. Below is a screen shot of what the edit_project page looks like:
Below is the entire code for this page: <?php include "dbcon.php"; include "functions.php"; //initialise variables $alert =false; // retrieve information based on the user id, that we set in the login page: if(isset($_GET['pid'])){ //clean pid if(!is_numeric($_GET['pid'])){ //the value received is not numeric. redirect the user to login header("location:login.php"); } //otherwise clean the received value for query use //get projects $projectID = mysql_escape_string($_GET['pid']); $getproject= "SELECT * FROM projects WHERE pid = '".$projectID."'"; $results = mysql_query($getproject); $projectdetails = mysql_fetch_assoc($results); } if(isset($_POST['submit'])){ //clean vars $title = mysql_escape_string($_POST['title']); $descr= mysql_escape_string($_POST['descr']); $status =mysql_escape_string($_POST['status']); $createdt = mysql_escape_string($_POST['createdt']); $p_pid = mysql_escape_string($_POST['p_pid']); //build date $duedt = $_POST['yy'] . "-"; if($_POST['mm'] < 10) { $duedt .= "0"; } $duedt .= $_POST['mm'] . "-"; if($_POST['mm'] == 4 || $_POST['mm'] == 6 || $_POST['mm'] == 9 || $_POST['mm'] == 11) { if($_POST['dd'] > 30) { $duedt .= "30"; } else { $duedt .= $_POST['dd']; } } elseif($_POST['mm'] == 2) { if($_POST['yy'] == 2008 || $_POST['yy'] == 2012) { if($_POST['dd'] > 29) { $duedt .= "29"; } else { $duedt .= $_POST['dd']; } } else { if($_POST['dd'] > 28) { $duedt .= "28"; } else { $duedt .= $_POST['dd']; } } } else { $duedt .= $_POST['dd']; } //update $query = "UPDATE projects SET title='" .$title. "', "; $query .= "project_description='" . $descr. "', status='" .$status . "',due_dt='" .$duedt."',"; $query .= "create_dt='" . $createdt. "', u_id='" .$_SESSION['uid'] . "'"; $query .= " WHERE pid='" .$p_pid. "'"; $result=mysql_query($query); if(!$result){ echo mysql_error(); }else{ header("location:main.php"); } }//submit ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/PM_Main.dwt.php" codeOutsideHTMLIsLocked="false" --> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <!-- InstanceBeginEditable name="doctitle" --> <title>Untitled Document</title> <!-- InstanceEndEditable --> <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable --> <link href="Templates/main.css" rel="stylesheet" type="text/css" /> </head> <body> <table width="100%" border="0"> <tr> <td width="33%"> </td> <td width="28%"> </td> <td width="39%">Logged in: <!-- InstanceBeginEditable name="login" --><? echo $_SESSION['name'];?> | <a href="logout.php">Logout</a><!-- InstanceEndEditable --></td> </tr> <tr> <td colspan="3" bgcolor="#6699CC" class="headertxt">Project Management Software </td> </tr> <tr> <td colspan="3"><!-- InstanceBeginEditable name="main" --> <form id="form1" name="form1" method="post" action="edit_project.php" enctype="multipart/form-data"> <table width="100%" border="0"> <tr> <td width="12%">proj name </td> <td width="88%"> </td> </tr> <tr> <td>Title</td> <td><label> <input name="title" type="text" id="title" value="<?php echo $projectdetails['title']?>"/> </label></td>
</tr> <tr> <td>Description</td> <td><label> <textarea name="descr" id="descr"><?php echo $projectdetails['project_description']?></textarea> </label></td> </tr> <tr> <td>Status</td> <td><label> <select name="status" id="status"> <?php $list=array('overdue','completed','pending'); switch($projectdetails['status']){
case "overdue": echo "<option value='overdue' selected";
break; case "completed": echo "<option value='completed' selected";
break; case "pending": echo "<option value='pending' selected";
break; } for($x=0; $x < 4; $x++){ echo ">" .$list[$x]. "</option>"; } ?> </select> <input type="hidden" name="p_pid" value="<?php echo $_GET['pid']?>"/> </label></td> </tr> <tr> <td>Date Due </td> <td><label> <? $dd = date("d"); $mm = date("m"); $yy = date("Y"); echo "<select name="dd">n"; for($i = 1; $i <= 31; $i++) { echo "<option value="" . $i . """; if($i == $dd) { echo " selected"; } echo ">" . $i . "</option>n"; } echo "</select> <select name="mm">n"; for($i = 1; $i <= 12; $i++) { echo "<option value="" . $i . """; if($i == $mm) { echo " selected"; } echo ">" . $month_names[$i] . "</option>n"; } echo "</select> <select name="yy">n"; for($i = $yy; $i <= ($yy + 1); $i++) { echo "<option value="" . $i . """; if($i == $yy) { echo " selected"; } echo ">" . $i . "</option>n"; } echo "</select>"; ?> <input type="hidden" name="createdt" value="<?php echo $projectdetails['create_dt']?>" /> </label></td> </tr> <tr> <td> </td> <td><label> <input name="submit" type="submit" id="submit" value="Update!" /> </label></td> </tr> </table> </form> <!-- InstanceEndEditable --></td> </tr> <tr> <td colspan="3"><!-- InstanceBeginEditable name="nav" --><table width="100%" border="0"> <tr> <td><a href="edit_task.php?pid=<?php echo $projectdetails['pid'];?>">Change a Task in this Project</a> | <a href="edit_staff.php?pid=<?php echo $projectdetails['pid'];?>">Change Staff members of this Project </a> | <a href="main.php">View Project List</a> | <a href="admin/login.php">Administrators Corner </a> </td> </tr> </table><!-- InstanceEndEditable --></td> </tr> <tr> <td align="right" class="cright" colspan="3">copyright © 2007 PM </td> </tr> </table> </body> <!-- InstanceEnd --></html>
blog comments powered by Disqus |
|
|
|
|
|
|
|