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

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

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

if($edit_process_now == "true") // User has hit the 'edit process' button
{

    $process_name = trim(make_clean($process_name));
    $process_info = trim(make_clean($process_info));

    if($process_name != "")
    {
        db_open();
        db_use();

        //make sure that name isn't taken
        $query = "SELECT * FROM processes WHERE title like '$process_name' AND pid != '$edit_process_id'";
        $result = db_query($query);
        if(db_fetch_row($result))
        {
            message_box("That name is already in use.", "error");
        }
        else
        {
            //make sure at least one task is in the process
            $empty = true;
            $query = "SELECT ttid FROM task_types";
            $result = db_query($query);
            while($empty && $row = db_fetch_row($result))
            {
                $ttid = $row["ttid"];
                $cb = "cb$ttid";
                if(isset($$cb))
                {
                    $empty = false;
                }
            }
            if(!$empty)
            {
                $query = "UPDATE processes SET title='$process_name', default_info='$process_info' WHERE " .
                         "pid='$edit_process_id'";
                if(db_query($query)) // Updates the edited process title, info
                {

                    $query = "DELETE FROM process_tasks WHERE pid = '$edit_process_id'";
                    if(db_query($query)) // Removes all the tasks from that process
                    {
                        foreach($HTTP_POST_VARS as $checkname => $value)
                        {
                            if(substr($checkname, 0, 2) == "cb")
                            {
                                $task_num = substr($checkname, 2);
                                $query = "INSERT into process_tasks (ttid, pid) VALUES ('$task_num', '$edit_process_id')";
                                db_query($query); // Inserts all the checked task templates to the process
                            }
                        }
                        message_box("Process updated Successfully");
                    }
                }//end update successful
            }//end has at least one task
            else
            {
                message_box("Process must contain at least one task. Process was not changed.<br>\n", "error");
            }
        }//end name not duplicate name
    }
    else
    {
        message_box("Name cannot be blank. Process was not changed.<br>\n", "error");
    }
}

?>

<table>
<tr>
<td>
    <form METHOD=POST action="process_edit.php">
    <table>
    <tr>
        <td>Available Processes to Edit:</td>
    </tr>
    <tr>
	    <td>
            <SELECT NAME="edit_process_id">
            <?php
                db_open();
                db_use();
                $queryPrivate = "SELECT title, pid FROM processes " .
                "WHERE group_owned = '0' AND owner = '$uid' ORDER BY title";

                $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";
                
                $resultPrivate = db_query($queryPrivate); // Display all private task templates
                while($row = db_fetch_row($resultPrivate))
                {
                    print("<option value=\"" . $row["pid"] . "\" 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["pid"] . "\" width=\"30\">" . $row["title"] . "</option>\n");
                }
            ?>
            </SELECT>
            <INPUT TYPE="submit" value="Edit">
        </td>
    </table>
    </form>
</td>
</tr>
</table>

<?php 

if(isset($edit_process_id))  // if the user has selected a process to edit
{
    db_open();
    db_use();
    $query = "SELECT * FROM processes WHERE pid='$edit_process_id'";
    $result = db_query($query); // get process details
    $row = db_fetch_row($result);
	
	$owner = get_process_owner($edit_process_id);

    $process_name = $row["title"];
    $process_info = $row["default_info"];

    print("<form method=\"post\" action=\"process_edit.php\">\n");
    print("<H3><B>Edit Process $process_name</B></H3>\n");
	print("Owned by: $owner");
    print("<table>\n");
    print("<tr>\n");
    print("<td>\n");
    print("Name:<INPUT TYPE=\"text\" value=\"$process_name\" NAME=\"process_name\" size=\"49\">\n");
    print("</td>\n");
    print("</tr>\n");
    print("<tr>\n");
    print("<td>\n");
    print("<TEXTAREA NAME=\"process_info\" ROWS=\"10\" COLS=\"47\">$process_info</TEXTAREA>\n");
    print("</td>\n");
    print("</tr>\n");
    print("<tr>\n");
    print("<td>\n");
    print("Which tasks do you want in this process:\n");
    print("</td>\n");
    print("</tr>\n");
    print("</table>\n");
    print("<table border=\"0\">\n");
    print("<tr class=\"table-header\">\n<td>Task Name</td>\n<td>Task Owner</td>\n</tr>\n");
    //display all of the tasks that the user can perform
    db_open();
    db_use();
    $queryPrivate = "SELECT title, ttid FROM task_types " .
    "WHERE group_owned = '0' AND owner = '$uid' ORDER BY title";
    $queryGroup = "SELECT gid, 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";
    
    $row_separator_num = 0;

    $resultPrivate = db_query($queryPrivate); //  display all the private task templates
    while($row = db_fetch_row($resultPrivate))
    {
        $row_separator_num++;
        if($row_separator_num % 2 == 0)
            $table_separator_string = "table-separator-even";
        else
            $table_separator_string = "table-separator-odd";

        $checked_private = "";
        if(is_task_in_process($row["ttid"], $edit_process_id))
            $checked_private = "checked";
        print("<tr class=\"$table_separator_string\">\n");
        print("<td><input " . $checked_private . " type=\"checkbox\" name=\"cb" .
            $row["ttid"] . "\"> " . $row["title"] . "</td>\n");
        print("<td>$user</td>\n");
        print("</tr>\n");
    }
    $resultGroup = db_query($queryGroup); // display all the group owned task templates
    while($row = db_fetch_row($resultGroup))
    {
        $task_owner = get_group_name($row["gid"]);

        $row_separator_num++;
        if($row_separator_num % 2 == 0)
            $table_separator_string = "table-separator-even";
        else
            $table_separator_string = "table-separator-odd";

        $checked_group = "";
        if(is_task_in_process($row["ttid"], $edit_process_id))
            $checked_group = "checked";

        print("<tr class=\"$table_separator_string\">\n");
                print("<td><input " . $checked_group . " type=\"checkbox\" name=\"cb" .
            $row["ttid"] . "\"> " . $row["title"] . "</td>\n");
        print("<td>$task_owner</td>\n");
        print("</tr>\n");
    }

    print("</table>\n");
    print("<p>\n");
    print("<table>\n");
    print("<tr>\n");
    print("<td>\n");
    print("<INPUT TYPE=\"hidden\" name=\"edit_process_id\" value=\"$edit_process_id\">\n");
    print("<INPUT TYPE=\"hidden\" name=\"edit_process_now\" value=\"true\">\n");
    print("<INPUT TYPE=\"submit\" value=\"Save Changes\">\n");
	print("<INPUT TYPE=\"button\" value=\"Cancel\" onClick=\"location='index.php'\">\n");
    print("</td>\n");
    print("</tr>\n");
    print("</table>\n");
    print("<p>\n");
    print("</form>\n");
}

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