Location: PHPKode > projects > Internet Task Management System > itms_mysql_build_0111/task_edit.php
<?php

/*
 * ITMS ValleyData source file version 1.0 May 11, 2001
 *
 * Editing a task template
 *
 *
 * Internet Task Management System: An online system used for recording information about and assigning tasks and processes.
 * Copyright (C) 2001  ValleyData Programming Group
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * See file named "gpl.txt" included with source code or
 * visit http://www.gnu.org/copyleft/gpl.txt on the internet.
 */
$title="Edit Task";

include("header.php");
print("<IMG SRC=\"images/edit_tasks.jpg\" WIDTH=\"400\" HEIGHT=\"41\" BORDER=\"0\" ALT=\"Edit Task\">");

if(isset($edit_now)) // If the user hits the 'save changes' button
{
	$task_title = trim(make_clean($task_title));
    $task_info = trim(make_clean($task_info));

	if($task_title != "")
	{
		db_open();
		db_use();
		
        //make sure that name isn't taken
        $query = "SELECT * FROM task_types WHERE title like '$task_title' AND ttid != '$edit_now'";
        $result = db_query($query);
        if(db_fetch_row($result))
        {
            message_box("That name is already in use.", "error");
        }
		else
		{
			$queryUpdate = "UPDATE task_types SET title='$task_title', default_info='$task_info' WHERE ttid='$edit_now'";
			if(db_query($queryUpdate)) // Update task template details
			{
				message_box("Task edit successful, name: $task_title, info: $task_info");
			}
			else
				message_box("Couldn't edit task, ttid=$edit_now, title=$task_title, info=$task_info", "warning");
		}
	}
	else
	{
	    message_box("Name cannot be blank. Task was not changed.<br>\n", "error");
	}
}

?>

<table>
<tr>
<td>
    <form METHOD=POST action="task_edit.php">
    <table>
    <tr>
        <td>Available Tasks to Edit:</td>
    </tr>
    <tr>
	    <td>
            <SELECT NAME="edit_task_type">
            <?php
                db_open();
                db_use();
                $queryGroup = "SELECT title, ttid FROM user_groups, task_types " .
                "WHERE user_groups.uid = '$uid' AND task_types.group_owned = '1' AND task_types.owner = user_groups.gid ORDER BY title";
                $queryPrivate = "SELECT title, ttid FROM task_types " .
                "WHERE group_owned = '0' AND owner = '$uid' ORDER BY title";
                
                $resultPrivate = db_query($queryPrivate); // Display all private task templates
                while($row = db_fetch_row($resultPrivate)) 
                {
                    print("<option value=\"" . $row["ttid"] . "\" width=\"30\">" . $row["title"] . "</option>\n");
                }

                $resultGroup = db_query($queryGroup); // Display all group owned task templates
                while($row = db_fetch_row($resultGroup))
                {
                    print("<option value=\"" . $row["ttid"] . "\" width=\"30\">" . $row["title"] . "</option>\n");
                }
            ?>
            </SELECT>
            <INPUT TYPE="submit" value="Edit">
        </td>
    </table>
    </form>
</td>
</tr>
</table>
<?php

if(isset($edit_task_type)) // If the user has selected a task to edit
{
    db_open();
    db_use();
    $query = "SELECT * FROM task_types WHERE ttid = '$edit_task_type'";
    $result = db_query($query); // Get info from task type with task ID
	$owner = get_task_owner($edit_task_type);
    if($row = db_fetch_row($result)) // Display the selected task info
    {
        $edit_task_title = $row["title"];
        print("<form method=\"post\" action=\"task_edit.php\">\n");
		print("<h3><B>Edit task: $edit_task_title</B></h3>\n");
		print("Owned by: $owner");
        print("<table>\n");
        print("<tr>\n");
        print("<td>\n");
        print("Name:<INPUT TYPE=\"text\" NAME=\"task_title\" value=\"" . $edit_task_title . "\" size=\"49\">\n");
        print("</td>\n");
        print("</tr>\n");
        print("<tr>\n");
        print("<td>\n");
        print("<TEXTAREA NAME=\"task_info\" ROWS=\"10\" COLS=\"47\">" . $row["default_info"] . "</TEXTAREA>\n");
        print("</td>\n");
        print("</tr>\n");
        print("<tr>\n");
        print("<td>\n");
        print("<INPUT TYPE=\"hidden\" name=\"edit_now\" value=\"$edit_task_type\">");
        print("<INPUT TYPE=\"submit\" value=\"Save Changes\">\n");
		print("<INPUT TYPE=\"button\" value=\"Cancel\" onClick=\"location='index.php'\">\n");
        print("</td></tr></table>\n");
        print("</form>");
    }//end if row
    else
    {
        print(message_out("Task Not Found: $edit_task_type.", "warning"));
    }
}//end if isset($edit_task_type)

include("footer.php");

?>
Return current item: Internet Task Management System