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

/*
 * ITMS ValleyData source file version 1.0 May 11, 2001
 *
 * Delete 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="Delete Task";

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

if(isset($delete_now)) // If the user has hit the 'save changes' button
{
    db_open();
    db_use();
    $queryDeleteType = "DELETE FROM task_types WHERE ttid='$delete_now'";
    $queryDeleteProcess = "DELETE FROM process_tasks WHERE ttid='$delete_now'";
    
	// delete task template and remove from associated process
	if(db_query($queryDeleteType) && db_query($queryDeleteProcess)) 
    {
        message_box("Task deleted successfully, name: $task_name, info: $task_info");
    }
    else
        message_box("Couldn't delete task, ttid=$delete_now, title=$task_name, info=$task_info", "warning");
}

?>

<table>
<tr>
<td>
    <form METHOD=POST action="task_delete.php">
    <table>
    <tr>
        <td>Available Tasks to Delete:</td>
    </tr>
    <tr>
	    <td>
            <SELECT NAME="delete_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 available private task templates to delete
                while($row = db_fetch_row($resultPrivate))
                {
                    print("<option value=\"" . $row["ttid"] . "\" width=\"30\">" . $row["title"] . "</option>\n");
                }

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

if(isset($delete_task_type)) // If the user has hit the 'delete task' button
{
    $processes = get_processes_with_task($delete_task_type);
    $processes_string = "";
    foreach($processes as $process)
    {
        $processes_string .= "<B>" . $process["title"] . "</B><br>\n"; 
    }

    db_open();
    db_use();
    $query = "SELECT * FROM task_types WHERE ttid = '$delete_task_type'";
    $result = db_query($query); // Get task type info with task ID
    if($row = db_fetch_row($result)) // Display info about selected task template
    {
        $delete_task_name = $row["title"];
        print("<h3>Are you sure you wish to delete this task?</h3>\n");
        print("Task Name: <B>" . $delete_task_name . "</B><br>\n");
        print("Task Info: <B>" . $row["default_info"] . "</B><br>\n");
        print("Owned By: <B>" . get_task_owner($delete_task_type) . "</B><br>\n");
        if($processes_string != "")
        {
            print("This task belongs to the following processes:<br>\n");
            print($processes_string);
            print("If this task is deleted, it will be removed from all processes it belongs to as well. <br>\n");
        }
        else
            print("This task currently belongs to no processes.<br>\n");
        print("<form method=\"post\" action=\"task_delete.php\">\n");
        print("<table>\n");
        print("<tr>\n");
        
        print("</tr>\n");
        print("<tr>\n");
        print("<td>\n");
        print("<INPUT TYPE=\"hidden\" name=\"task_name\" value=\"$delete_task_name\">");
        print("<INPUT TYPE=\"hidden\" name=\"task_info\" value=\"" . $row["default_info"] . "\">");
        print("<INPUT TYPE=\"hidden\" name=\"delete_now\" value=\"$delete_task_type\">");
        print("<INPUT TYPE=\"submit\" value=\"Delete Task\">\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: $delete_task_type.", "error"));
    }
}//end if isset($delete_task_type)

include("footer.php");

?>
Return current item: Internet Task Management System