viewtask.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:14k
- <?php
- // +-------------------------------------------------------------+
- // | DeskPRO v [2.0.1 Production]
- // | Copyright (C) 2001 - 2004 Headstart Solutions Limited
- // | Supplied by WTN-WDYL
- // | Nullified by WTN-WDYL
- // | Distribution via WebForum, ForumRU and associated file dumps
- // +-------------------------------------------------------------+
- // | DESKPRO IS NOT FREE SOFTWARE
- // +-------------------------------------------------------------+
- // | License ID : Full Enterprise License =) ...
- // | License Owner : WTN-WDYL Team
- // +-------------------------------------------------------------+
- // | $RCSfile: viewtask.php,v $
- // | $Date: 2004/02/10 01:34:25 $
- // | $Revision: 1.45 $
- // +-------------------------------------------------------------+
- // | File Details:
- // | - Task details view.
- // +-------------------------------------------------------------+
- // This file both shows item details and handles certain edit operations
- // ("muting" a task, and toggling it completed). Muting a task stops it
- // repeating immediately.
- error_reporting(E_ALL ^ E_NOTICE);
- // start file
- require("./../global.php");
- require_once(INCLUDE_PATH . 'functions/calendar_functions.php');
- // globalise variables
- $global = array (
- array('id'),
- array('techid'),
- array('date'),
- array('tasktoggle') // ticketid
- );
- rg($global);
- tech_nav('calendar');
- // If there's no ID, complain and give up.
- if (!($id = trim($id)) AND !($taskdate = trim($taskdate))) {
- mistake('No valid task ID was specified. Please try your request again.');
- exit;
- }
- // Fetch the taskdata
- $taskdata = $db->query_return("SELECT calendar_task.*, tech.username AS techmaker_username FROM
- calendar_task, tech WHERE calendar_task.techmaker = tech.id AND
- calendar_task.id = '$id'");
- if (!$rows = $db->num_rows()) {
- mistake("The specified task ID ($id) doesn't exist. Please try your request again.");
- exit;
- }
- if ($taskdata['techmaker'] != $user['id']) { // This user doesn't own the task, check permissions
- $db->query("SELECT id FROM calendar_task_tech WHERE eventid = $id AND techid = $user[id]");
- if (!$db->num_rows()) {
- mistake('You do not have permission to view this task.');
- exit;
- }
- }
- $start = $taskdata['startdate'];
- $endd = $taskdata['enddate'];
- $endt = $taskdata['endtime'];
- // If a date was specified, we're looking at a repeat event, not its original.
- // We still show the original data, but replace the enddate with the date
- // specified.
- if ($date) {
- $event_due = our_date(convert_date($date), 'day');
- }
- // First, check if we're supposed to toggle a task's completed state
- if ($_REQUEST['do'] == "complete" OR $_REQUEST['do'] == "incomplete") {
- if ($_REQUEST['do'] == "complete") { $compl = 1; } else { $compl = 0; }
- if (!isset($_REQUEST['techid'])) { // If no techid is specified, the user is trying to set the complete state for *ALL* assigned techs.
- if ($taskdata['techmaker'] == $user['id']) { // If the user is the original task maker, honor the request.
- if ($date) { // If we're updating a repeating event ...
- $db->query("SELECT techid FROM calendar_task_tech WHERE eventid = $id");
- while ($res = $db->row_array()) {
- $techs[] = $res['techid'];
- }
- $db->query("DELETE FROM calendar_task_iteration WHERE taskid = $id AND date = '$date'");
- foreach ($techs as $key => $val) {
- $db->query("INSERT INTO calendar_task_iteration (task_techid, taskid, completed, date) VALUES ('$val', '$id', '$compl', '$date')");
- }
- } else {
- $db->query("UPDATE calendar_task_tech SET completed = $compl WHERE eventid = $id");
- }
- if ($taskdata['notifycompletion']) { // If the owner wants people to be mailed, start sending mail
- $db->query("SELECT techid, tech.email, tech.username FROM calendar_task_tech, tech
- WHERE calendar_task_tech.eventid = $id AND calendar_task_tech.techid = tech.id");
- while ($res = $db->row_array()) {
- $emails[$result['techid']]['username'] = $res['username'];
- $emails[$result['techid']]['email'] = $res['email'];
- }
-
- foreach ($emails as $key => $val) {
- $done = iff($compl, 'completed', 'not completed');
- $taskusername = $emails[$key]['username'];
- $taskurl = "viewtask.php?id=$id";
- $tasktitle = $taskdata['title'];
- $taskdescription = $taskdata['description'];
- $taskdone = $done;
- eval(makeemaileval('message', 'TECHBODY_task_toggled', $subject));
- dp_mail($emails[$key]['email'], $subject, $message);
- }
- }
- } else { // Otherwise, deny the request.
- mistake("You don't have the authority to set this task complete or incomplete.");
- }
- } else { // If a techid is supplied, the user is trying to set a specific user's (or his own) complete state for this task.
- $db->query("SELECT techid FROM calendar_task_tech WHERE techid = $_REQUEST[techid] AND eventid = $id");
- if ($db->num_rows() or ($taskdata['techmaker'] == $user['id'])) { // If the user is assigned this task and is trying to change his own state, or if he's the task's creator, honor the request.
- if ($taskdata['techmaker'] == $user['id']) { // Tech owns the task; can change anybody's status
- $tid = $_REQUEST['techid'];
- } else { // Only assigned, can only change own status
- $tid = $user['id'];
- }
- if ($date) { // If we're updating a repeating event ...
- $db->query("DELETE FROM calendar_task_iteration WHERE task_techid = '$tid' AND taskid = '$id' AND date = '$date'");
- $db->query("REPLACE INTO calendar_task_iteration (task_techid, taskid, completed, date) VALUES ('$tid', '$id', '$compl', '$date')");
- } else {
- $db->query("UPDATE calendar_task_tech SET completed = '$compl' WHERE eventid = '$id' AND techid = '$tid'");
- }
- $db->query("SELECT id, username, email FROM tech WHERE id = '$taskdata[techmaker]' or id = '$user[id]'");
- while ($result = $db->row_array()) {
- $emails[$result['id']]['username'] = $result['username'];
- $emails[$result['id']]['email'] = $result['email'];
- }
- if (($taskdata['techmaker'] != $user['id']) && $taskdata['notifycompletion']) { // If the user doesn't own the task but is assigned to it and if the owner wants notification, send it
- $taskusername = $emails[$user['id']]['username'];
- $taskurl = "viewtask.php?id=$id";
- $tasktitle = $_REQUEST['title'];
- $taskdescription = $_REQUEST['description'];
- $taskdone = $done;
- eval(makeemaileval('message', 'TECHBODY_task_toggled', $subject));
- dp_mail($emails[$taskdata['techmaker']]['email'], $subject, $message);
- }
- } else { // Otherwise, deny the request.
- mistake("You don't have the authority to set this task complete or incomplete.");
- }
- }
- }
- if ($_REQUEST['do'] == "mute") {
- $date = $_REQUEST['date'];
- $assigned = $db->query_return_array_id("SELECT techid FROM calendar_task_tech WHERE eventid = $id", 'techid');
- if ($taskdata['techmaker'] == $user['id']) {
- // If the user owns the task, nuke all assigned tech's occurrences of it on this date
- $db->query("DELETE FROM calendar_task_iteration WHERE date = '$date' AND taskid = '$id'");
- foreach ($assigned AS $assigned_tech) {
- $db->query("INSERT INTO calendar_task_iteration SET
- task_techid = '$assigned_tech',
- taskid = '$id',
- completed = '-1',
- date = '$date'"
- );
- jump("viewtask.php?id=$id", 'Occurrence deleted. Viewing original event.');
- exit;
- };
- } elseif ($db->num_rows()) {
- // If the user is assigned to the task, nuke his own occurrence but no one else's
- $db->query("DELETE FROM calendar_task_iteration WHERE date = '$date' AND taskid = '$id' AND task_techid = '$user[id]'");
- $db->query("INSERT INTO calendar_task_iteration SET
- task_techid = '$user[id]',
- taskid = '$id',
- completed = '-1',
- date = '$date'"
- );
- jump("viewtask.php?id=$id", 'Occurrence deleted. Viewing original event.');
- exit;
- } else {
- mistake("You don't have permission to edit this task.");
- }
- }
-
- // Fetch the techs assigned to this task
- $db->query("SELECT email_due, email_before1, email_before2, techid,
- tech.username, completed FROM calendar_task_tech, tech where
- calendar_task_tech.techid = tech.id and
- calendar_task_tech.eventid = $id GROUP BY techid");
- if (!$rows = $db->num_rows()) {
- mistake('There are no technicians assigned to this task. Please try your request again.');
- }
- $taskassigns = array();
- while ($result = $db->row_array()) {
- $taskassigns[] = $result;
- }
- $detailstable[] = array($taskdata['description']);
- // Prepare the list of assigned techs
- $techstable = array();
- $techstable[] = array('<B>Technician</B>',
- '<B>Reminder Emails</B>',
- '<B>Completed?</B>');
- if ($date) {
- $db->query("SELECT * FROM calendar_task_iteration WHERE taskid = $id AND date = '$date'");
- while ($result = $db->row_array()) {
- $date_results[$result['task_techid']] = $result;
- }
- }
- foreach($taskassigns AS $assign) {
- if ($date) {
- if ($date_results[$assign['techid']]['completed']) {
- $assign[completed] = "Yes";
- $taskdo = "incomplete";
- } else {
- $assign[completed] = "No";
- $taskdo = "complete";
- }
- } else {
- if ($assign[completed]) {
- $assign[completed] = "Yes";
- $taskdo = "incomplete";
- } else {
- $assign[completed] = "No";
- $taskdo = "complete";
- }
- }
- $emails = 0;
- $mails = '';
- if ($assign['email_due']) {
- $mails = "On due date";
- $emails++;
- }
- if ($assign['email_before1']) {
- if ($emails) {
- $mails .= ", and $assign[email_before1] day(s) prior";
- } else {
- $mails = "$assign[email_before1] day(s) prior";
- }
- $emails++;
- }
- if (($assign['email_before2']) AND ($assign['email_before2'] != $assign['email_before1'])) {
- if ($emails) {
- $mails .= ", and $assign[email_before2] day(s) prior";
- } else {
- $mails = "$assign[email_before2] day(s) prior";
- }
- }
- if ($date) { // FOOO
- if ($taskdata['techmaker'] == $user['id'] OR ($assign[techid] == $user['id'])) {
- $url = "<A HREF="viewtask.php?do=$taskdo&id=$id&techid=$assign[techid]&date=$date">$assign[completed]</A>";
- } else {
- $url = $assign[completed];
- }
- } else {
- if ($taskdata['techmaker'] == $user['id'] OR ($assign[techid] == $user['id'])) {
- $url = "<A HREF="viewtask.php?do=$taskdo&id=$id&techid=$assign[techid]">$assign[completed]</A>";
- } else {
- $url = $assign[completed];
- }
- }
- $techstable[] = array($assign[username], $mails, $url);
- if ($assign['techid'] == $user['id']) { $showall++; }
- $techs++;
- }
- if ($taskdata['enddate'] == "0000-00-00") {
- $taskdata['enddate'] = "<I>N/A</I>";
- } else {
- $taskdata['enddate'] = convert_date($taskdata['enddate']);
- $taskdata['enddate'] = our_date($taskdata['enddate'], 'day');
- }
- if ($taskdata['endtime'] AND ($taskdata['endtime'] != '00:00:00')) {
- $taskdata['endtime'] = time_ampm($taskdata['endtime']);
- } else {
- $taskdata['endtime'] = '';
- }
- if ($taskdata['multistaff']) {
- $taskdata['multistaff'] = "Yes ($rows techs)";
- } else {
- $taskdata['multistaff'] = "No";
- }
- foreach($taskassigns AS $key) {
- if ($date) {
- $completed += $date_results[$key['techid']]['completed'];
- } else {
- $completed += $key['completed'];
- }
- }
- if ($taskdata['globalcomplete']) {
- $taskdata['globalcomplete'] = "No";
- if ($completed) {
- $taskdata['completed'] = "Yes";
- } else {
- $taskdata['completed'] = "No";
- }
- } else {
- $taskdata['globalcomplete'] = "Yes";
- if ($completed == $rows) {
- $taskdata['completed'] = "Yes";
- $taskdo = "incomplete";
- } else {
- $taskdata['completed'] = "No";
- $taskdo = "complete";
- }
- }
- $taskdata['startdate'] = convert_date($taskdata['startdate']);
- if (isset($taskdata['starttime'])) {
- $starttime = time_ampm($taskdata['starttime']);
- $startdate = our_date($taskdata['startdate'], 'day') . " $starttime";
- } else {
- $startdate = our_date($taskdata['startdate'], 'day');
- }
- if ($showall AND ($techs > 1)) {
- if ($taskdata['techmaker'] == $user['id']) {
- $url = jprompt(
- 'This will update the completion status for all assigned techs.',
- "viewtask.php?do=$taskdo&id=$id&date=$date",
- $taskdata[completed]
- );
- } else {
- $url = $taskdata[completed];
- }
- } else {
- if ($taskdata['techmaker'] == $user['id']) {
- $url = "<A HREF="viewtask.php?do=$taskdo&id=$id&date=$date">$taskdata[completed]</A>";
- } else {
- $url = $taskdata[completed];
- }
- }
- if ($date AND (our_date($date) != $startdate)) {
- $orig = "(<A HREF="viewtask.php?id=$id">View Original Event</A>) (<A HREF="viewtask.php?do=mute&id=$id&date=$date">Hide This Occurrence</A>)";
- } else {
- $orig = '';
- }
- $reptype = repeat_type_text($taskdata['repeattype'], $taskdata['value1'], $taskdata['value2']);
- // Prepare the details table
- if ($reptype == "No") {
- $repdetail = NULL;
- $repends = NULL;
- } else {
- $repdetail = "<B>Repeat</B> $orig<BR>$reptype <A HREF="index.php?search=1&taskid=$taskdata[id]">View All</A>";
- $repends = "<B>Repeat Ends</B><BR>$taskdata[enddate] $taskdata[endtime]";
- }
- if ($taskdata['techmaker'] == $user['id']) {
- $url2 = "<A HREF="edit.php?id=$taskdata[id]">Edit</A>";
- }
- if ($showall AND ($techs > 1)) {
- $tmp = array("<B>Due Date</B><BR>$startdate", $repdetail, $repends,
- "<B>Creator</B><BR>$taskdata[techmaker_username]",
- "<B>Multiple Techs</B><BR>$taskdata[multistaff]",
- "<B>Everyone Must Finish</B><BR>$taskdata[globalcomplete]",
- "<B>Complete</B><BR>$url");
- if ($url2) {
- $tmp[] = $url2;
- }
- $detailstable[] = $tmp;
- } else {
- $tmp = array("<B>Start Date</B><BR>$startdate", $repdetail, $repends,
- "<B>Complete</B><BR>$url");
- if ($url2) {
- $tmp[] = $url2;
- }
- $detailstable[] = $tmp;
- }
- if ($event_due) {
- $detailstable[1][] = "<B>This Item Due</B><BR>$event_due";
- }
- // Emit the details table
- table_header("Task: $taskdata[title] (#$taskdata[id])");
- table_content('', $detailstable, '', '', '', '', $width);
- table_footer();
- // Emit the technicians list if appropriate
- if ($showall AND ($techs > 1)) {
- table_header("Technicians Assigned to This Task:");
- table_content('', $techstable, '', '', '', '', $width);
- table_footer();
- }
- tech_footer();
- ?>