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

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

include("header.php");

print("<IMG SRC=\"images/delete_process.jpg\" WIDTH=\"400\" HEIGHT=\"41\" BORDER=\"0\" ALT=\"Delete Process\">");

if(isset($delete_process_now)) // user has hit 'delete process' button
{
    db_open();
    db_use();
    $queryDeleteType = "DELETE FROM processes WHERE pid='$delete_process_now'";
    $queryDeleteProcess = "DELETE FROM process_tasks WHERE pid='$delete_process_now'";
    
	// delete process and remove all associated task templates
	if(db_query($queryDeleteType) && db_query($queryDeleteProcess)) 
    {
        message_box("Process deleted successfully, name: $process_name, info: $process_info");
    }
    else
        message_box("Couldn't delete process, pid=$delete_process_now, title=$process_name, info=$process_info", "warning");
}

?>

<table>
<tr>
<td>
    <form METHOD=POST action="process_delete.php">
    <table>
    <tr>
        <td>Available Processes to Delete:</td>
    </tr>
    <tr>
	    <td>
            <SELECT NAME="delete_process_id">
            <?php
                db_open();
                db_use();
                $queryGroup = "SELECT title, pid FROM user_groups, processes " .
                "WHERE user_groups.uid = '$uid' AND processes.group_owned='1' " .
                "AND processes.owner = user_groups.gid ORDER BY title";
                $queryPrivate = "SELECT title, pid FROM processes " .
                "WHERE group_owned = '0' AND owner = '$uid' ORDER BY title";
                
                $resultPrivate = db_query($queryPrivate); // display private processes
                while($row = db_fetch_row($resultPrivate))
                {
                    print("<option value=\"" . $row["pid"] . "\" width=\"30\">" . $row["title"] . "</option>\n");
                }

                $resultGroup = db_query($queryGroup); // display group owned processes
                while($row = db_fetch_row($resultGroup))
                {
                    print("<option value=\"" . $row["pid"] . "\" width=\"30\">" . $row["title"] . "</option>\n");
                }
            ?>
            </SELECT>
            <INPUT TYPE="submit" value="Delete">
        </td>
    </table>
    </form>
</td>
</tr>
</table>

<?php 

if(isset($delete_process_id)) // if user has selected the process to delete
{
    $tasks = get_tasks_in_process($delete_process_id);
    $tasks_string = "";
    foreach($tasks as $task)
    {
        $tasks_string .= "<B>" . $task["title"] . "</B><br>\n"; 
    }
    db_open();
    db_use();
    $query = "SELECT * FROM processes WHERE pid='$delete_process_id'";
    $result = db_query($query); // get process info.
    if($row = db_fetch_row($result))
    {
        $delete_process_name = $row["title"];
        print("<h3>Are you sure you wish to delete this process?</h3>\n");
        print("Process Name: <B>" . $delete_process_name . "</B><br>\n");
        print("Process Info: <B>" . $row["default_info"] . "</B><br>\n");
        print("Owned By: <B>" . get_process_owner($delete_process_id) . "</B><br>\n");
        if($tasks_string != "")
        {
            print("This process contains the following tasks:<br>\n");
            print($tasks_string);
            print("These individual tasks will not be affected if this process is deleted.<br>\n");
        }
        else
            print("This process currently contains no tasks.<br>\n");
        print("<form method=\"post\" action=\"process_delete.php\">\n");
        print("<table>\n");
        print("<tr>\n");
        print("<td>\n");
        print("<INPUT TYPE=\"hidden\" name=\"process_name\" value=\"$delete_process_name\">");
        print("<INPUT TYPE=\"hidden\" name=\"process_info\" value=\"" . $row["default_info"] . "\">");
        print("<INPUT TYPE=\"hidden\" name=\"delete_process_now\" value=\"$delete_process_id\">");
        print("<INPUT TYPE=\"submit\" value=\"Delete Process\">\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_process_id.", "error"));
    }
}

include("footer.php"); 
?>
Return current item: Internet Task Management System