Adding Tasks to a Project Management Application (
Page 1 of 4 )
The previous articles covered adding, editing and viewing a project, capabilities any project management application needs. The next couple of articles will cover the "optional" parts of the application. They include adding project files and adding tasks to a project, both of which are not strictly necessary. We will also look at adding staff members to a particular project a little later on. This article, the fourth of seven parts, will deal with adding tasks to a project, after which we will look at editing a task.A task in this case refer to a action that the project manager wants done by a certain date or time. The tasks for the project are not displayed on the view project page (the page that shows project contents in detail). Instead, you get a link that points you toward the different tasks that should be done on the given project.
The only link between all the scripts that deal with handling tasks, and the project itself, is the project id. As you may remember, all database tables for this application have a project id in them. So in order for this script work effectively, it will need to be given a project id by whatever script is referencing it. Otherwise the task that you create cannot be linked to any project. Below is a screen shot of what the page actually looks like:
_html_3284e556.png)
And as always, here's the entire code for the page:
<?php
include "dbcon.php";
include "functions.php";
$cpid=mysql_escape_String($_GET['pid']);
$getname = "SELECT title FROM projects WHERE pid = '".$cpid."'";
$g_result = mysql_query($getname);
if(!$g_result){
echo mysql_error();
}else{
$rowname = mysql_fetch_assoc($g_result);
$title = $row['title'];
}
if(isset($_POST['submit'])){
//check vars
$descr=mysql_escape_string($_POST['descr']);
$p_pid=mysql_escape_string($_POST['p_pid']);
//due 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'];
}
//insert
$insert = "INSERT INTO tasks SET task_description = '".$descr."',";
$insert .= "complete_by = '".$duedt."',p_id= '".$p_pid."'";
if(!mysql_query($insert)){
echo mysql_error();
}
}
?>
<!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 action="add_task.php" method="post" name="f1">
<table width="100%" border="0">
<tr>
<td colspan="2" class="loginheader"><?php echo $title;?></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Complete by</td>
<td><?php $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 name="p_pid" type="hidden" value="<?php echo $_GET['pid']?>" /></td>
</tr>
<tr>
<td valign="top">Description</td>
<td><label>
<textarea name="textarea"></textarea>
</label></td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="submit" name="submit" value="Add task!" />
</label></td>
</tr>
</table>
</form>
<!-- InstanceEndEditable --></td>
</tr>
<tr>
<td colspan="3"><!-- InstanceBeginEditable name="nav" --><a href="main.php">View Project List</a> | <a href="admin/login.php">Administrators Corner </a><!-- InstanceEndEditable --></td>
</tr>
<tr>
<td align="right" class="cright" colspan="3">copyright © 2007 PM </td>
</tr>
</table>
</body><!-- InstanceEnd -->
</html>