<?php
/*
* ITMS ValleyData source file version 1.0 May 11, 2001
*
* This page allows ITMS administrators to reassign a user's pending tasks
*
*
*
* 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="Reassign Tasks";
include("header.php");
include("adminonly.php");
if(isset($reassign_now)) // Test if we want to reassign tasks
{
for($i = 0; $i < $num_tasks; $i++) //Loop for each task the user has assigned to them
{
$ttid = "id" . $i;
$reassigntask_touser = "reassigntask_touser" . $i;
$ttid = $$ttid;
$reassigntask_touser = $$reassigntask_touser;
$this_task_name = get_pending_task_name($ttid);
if($reassigntask_touser == "*Unassign Task*") //if the task is to be unassigned
{
db_open();
db_use();
$query = "SELECT * FROM pending_tasks, users WHERE tid='$ttid' AND users.uid='$userto_reassign'";
$result = db_query($query);
while($row = db_fetch_row($result))
{
$tid = $ttid;
$unassignedBy_email = get_user_email($uid);
//send notification
notifyUnassigned(
$row["title"],
$row["email"],
$row["assignedTo"],
get_user_name($row["assigner"]),
$unassignedBy_email,
$row["info"],
$row["due_date"],
get_priority_string($row["priority"]),
$row["html"]);
if($row["assigner"] != $uid) //if the assigner is not the current user
{
$assignedBy_email = get_user_email($row["assigner"]);
notifyUnassigned(
$row["title"],
$assignedBy_email,
$row["assignedTo"],
get_user_name($row["assigner"]),
$unassignedBy_email,
$row["info"],
$row["due_date"],
get_priority_string($row["priority"]),
$row["html"]);
}
$query = "DELETE FROM pending_tasks WHERE tid = '$tid'";
db_query($query);
message_box("$this_task_name has been unassigned.");
}
}
else if($userto_reassign != $reassigntask_touser) //If this task has been selected to be reassigned
{
$old_to = get_user_email($userto_reassign);
$new_to = get_user_email($reassigntask_touser);
$old_name = get_user_name($userto_reassign);
$new_name = get_user_name($reassigntask_touser);
$my_email = get_user_email($uid);
db_open();
db_use();
$query = "UPDATE pending_tasks SET uid='$reassigntask_touser' WHERE tid='$ttid'";
if(db_query($query)) //Change who the task is assigned to
{
message_box("$this_task_name has been reassigned to $new_name");
$query = "SELECT tid, title, name, priority, due_date, date_assigned, info FROM pending_tasks, users WHERE pending_tasks.tid='$ttid'";
$result = db_query($query);
$row = db_fetch_row($result);
$info = $row["info"];
$due_date = $row["due_date"];
$priority = $row["priority"];
$priority = get_priority_string($priority);
//send email notification that the task was unassigned to old assignee
notifyUnassigned($this_task_name, $old_to, $old_name, $user, $my_email, $info, $due_date, $priority);
//send email noticication that the task was assigned to new assignee
notifyAssigned($this_task_name, $new_to, $new_name, $user, $my_email, "", $info, $due_date, $priority);
}
else
{
error_out("Couldn't reassign task $this_task_name", "LOG_WARNING");
message_box("Couldn't reassign task: $this_task_name", "error");
}
}
else
message_box("$this_task_name was not reassigned");
}
}//end if(isset($reassign_now))
print("<IMG SRC=\"images/user_tasks_reassign.jpg\" WIDTH=\"400\" HEIGHT=\"41\" BORDER=\"0\" ALT=\"Reassign Tasks\">");
?>
<H3><B>Reassign
<?php
if(isset($userto_reassign))
{
$userto_reassign_name = get_user_name($userto_reassign);
print($userto_reassign_name . "'s ");
}
?>
Tasks</B></H3>
<table>
<tr>
<td>
<form METHOD=POST action="user_tasks_reassign.php">
<table>
<tr>
<td>Available Users for Task Reassignment:</td>
</tr>
<tr>
<td>
<?php
print("<SELECT NAME=\"userto_reassign\">");
$user_array = get_all_users();
if($user_array)
foreach ($user_array as $usr)
{
$selected="";
if($usr["uid"] == $userto_reassign)
$selected = "selected";
print("<option $selected value=\"" . $usr["uid"] . "\">" . $usr["name"] . "</option>\n");
}
print("</SELECT>");
?>
<INPUT TYPE="submit" value="Select User">
<INPUT TYPE="button" value="Cancel" onClick="location='index.php'">
</td>
</table>
</form>
</td>
</tr>
</table>
<?php
$PENDING_START = <<<PENDING_START
<table>
<tr>
<td>
<B>Pending Tasks Currently Assigned to $userto_reassign_name:</B>
<table border="0">
<tr class="table-header">
<td><a href="user_tasks_reassign.php?orderby=taskname">Task Name</a></td>
<td><a href="user_tasks_reassign.php?orderby=assigned">Assigned By</a></td>
<td><a href="user_tasks_reassign.php?orderby=priority">Priority</a></td>
<td><a href="user_tasks_reassign.php?orderby=duedate">Due Date</a></td>
<td>Reassign To</td>
</tr>
<form name="reassign_tasks" METHOD="POST" ACTION="user_tasks_reassign.php">
PENDING_START;
$PENDING_END = <<<PENDING_END
<tr class="table-header">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>
<INPUT TYPE="hidden" name="reassign_now" value="reassign_now">
<INPUT TYPE="submit" value="Reassign Tasks" name="reassign">
</td>
</tr>
</form>
</table>
<br>
PENDING_END;
if(isset($userto_reassign)) // Test if a user has been picked
{
if($orderby == "taskname")
{
$orderby = "title";
}
else if($orderby == "assigned")
{
$orderby = "name";
}
else if($orderby == "priority")
{
$orderby = "priority DESC";
}
else if($orderby == "duedate")
{
$orderby = "due_date";
}
else
{
$orderby = "due_date";
}
db_open();
db_use();
$query = "SELECT tid, title, name, priority, due_date, date_assigned, info FROM pending_tasks, users WHERE pending_tasks.uid = '$userto_reassign' AND pending_tasks.assigner = users.uid ORDER BY $orderby";
$result = db_query($query); // Get all pending tasks for the selected user
$table_separator_string = "table-separator-even";
$row_separator_num = 0;
if($result)
{
print($PENDING_START);
$tnum = 0;
while($row = db_fetch_row($result)) // Show the details for each pending task
{
$row_separator_num++;
if($row_separator_num % 2 == 0)
$table_separator_string = "table-separator-even";
else
$table_separator_string = "table-separator-odd";
$priority = get_priority_string($row["priority"]);
print("<tr class=\"$table_separator_string\">\n");
print(" <td>" . $row["title"] . "</td>\n");
print(" <td>" . $row["name"] . "</td>\n");
print(" <td>" . $priority . "</td>\n");
print(" <td>" . convert_date($row["due_date"]) . "</td>\n");
print("<td><SELECT NAME=\"reassigntask_touser$tnum\">");
// Put "unassign task" option in list box
print("<option value=\"*Unassign Task*\"><Unassign Task></option>\n");
$user_array = get_all_users();
if($user_array)
foreach ($user_array as $usr) // Put appropriate users in list box
{
$selected="";
if($usr["uid"] == $userto_reassign)
$selected = "selected";
print("<option $selected value=\"" . $usr["uid"] . "\">" . $usr["name"] . "</option>\n");
}
print("</SELECT></td>");
print("</tr>\n");
print("<tr class=\"$table_separator_string\">\n");
print("<td> </td>");
print("<td colspan=\"4\">Assigned On: " . $row["date_assigned"] . "<br>\n" . $row["info"] . "</td>");
print("</tr>");
print("<INPUT TYPE=\"hidden\" name=\"id" . $tnum . "\" value=\"" . $row["tid"] . "\">\n");
$tnum++;
}
print("<INPUT TYPE=\"hidden\" name=\"num_tasks\" value=\"$tnum\">");
print("<INPUT TYPE=\"hidden\" name=\"userto_reassign\" value=\"$userto_reassign\">");
print($PENDING_END);
}
}//end if(isset($userto_reassign))
include("footer.php");
?>