edit.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:13k
- <?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: edit.php,v $
- // | $Date: 2004/02/10 01:34:25 $
- // | $Revision: 1.50 $
- // +-------------------------------------------------------------+
- // | File Details:
- // | - Calendar task edit page.
- // +-------------------------------------------------------------+
- error_reporting(E_ALL ^ E_NOTICE);
- // start file
- require("./../global.php");
- // globalise variables
- $global = array (
- array('id') // calendar event ID
- );
- rg($global);
- tech_nav('calendar');
- if (!$id) {
- jump('index.php', 'No event specified.');
- exit;
- }
- // default do
- $_REQUEST['do'] = trim($_REQUEST['do']);
- if (!isset($_REQUEST['do']) or $_REQUEST['do'] == "") {
- $_REQUEST['do'] = "edit";
- }
- $oldtaskdata = $db->query_return("SELECT * FROM calendar_task WHERE id = '$id'");
- if (!$db->num_rows()) {
- mistake('The specified task does not exist.');
- exit;
- }
- if ($oldtaskdata['techmaker'] != $user['id']) {
- if ($_REQUEST['do'] == 'edit2') {
- $db->query("UPDATE calendar_task_tech SET
- email_due = " . intval($_REQUEST['email_due']) . ",
- email_before1 = '" . intval($_REQUEST['email_before1']) . "',
- email_before2 = '" . intval($_REQUEST['email_before2']) . "'
- WHERE techid = '" . $user['id'] . "'
- AND eventid = '" . intval($id) . "'"
- );
- jump('viewtask.php?id=$id', 'Notification options updated.');
- } else {
- mistake('You don't have permission to edit this task.');
- }
- exit;
- }
- require_once(INCLUDE_PATH . 'functions/calendar_functions.php');
- ############################### EDIT TASK ###############################
- if ($_REQUEST['do'] == "edit2") {
- if ($_REQUEST['using_time']) { // sort out 24 hour clock
- if ($_REQUEST['twelvetime'] == "PM") {
- if ($_REQUEST['htime'] == "12") {
- $htime = "00";
- } else {
- $htime = $_REQUEST['htime'] + 12;
- }
- } else {
- $htime = $_REQUEST['htime'];
- }
- $starttime = "$htime:$_REQUEST[mtime]:00";
- }
- // repeat options
- if ($_REQUEST['type'] > 0) {
- if ($_REQUEST['type'] == '1') {
- $value1 = $_REQUEST['value11'];
- } elseif ($_REQUEST['type'] == '2') {
- if (is_array($_REQUEST['value22'])) {
- foreach($_REQUEST['value22'] AS $key => $var) {
- $value2 .= $key . '|';
- }
- $value2 = substr($value2, 0, -1);
- }
- $value1 = $_REQUEST['value21'];
- } elseif ($_REQUEST[type] == '3') {
- $value1 = $_REQUEST['value31'];
- $value2 = $_REQUEST['value32'];
- } elseif ($_REQUEST[type] == '4') {
- $value1 = $_REQUEST['value41'];
- $value2 = $_REQUEST['value42'];
- }
- }
- // Delete task repetition data if the task is being set to non-repeating.
- if ($oldtaskdata['repeattype'] AND !$_REQUEST['type']) {
- $db->query("DELETE FROM calendar_task_iteration WHERE taskid = '$oldtaskdata[id]'");
- }
- if (count($_REQUEST['techs']) > 1) {
- $multistaff = 1;
- }
- $startdate = "$_REQUEST[ystartdate]-$_REQUEST[mstartdate]-$_REQUEST[dstartdate]";
- $enddate = "$_REQUEST[yenddate]-$_REQUEST[menddate]-$_REQUEST[denddate]";
- $checks = xss_check(array($_REQUEST['title'], $_REQUEST['description']), 'tech');
- $db->query("UPDATE calendar_task SET
- title = '" . mysql_escape_string($checks[0]) . "',
- description = '" . mysql_escape_string($checks[1]) . "',
- starttime = '$starttime',
- repeattype = " . intval($_REQUEST['type']) . ",
- value1 = " . intval($value1) . ",
- value2 = '" . mysql_escape_string($value2) . "',
- multistaff = " . intval($multistaff) . ",
- notifycompletion = " . intval($_REQUEST['notifycompletion']) . ",
- globalcomplete = " . intval($_REQUEST['globalcomplete']) . ",
- timezone = '" . mysql_escape_string($_REQUEST['timezone']) . "',
- startdate = '$startdate',
- enddate = '$enddate'
- WHERE id = " . intval($id));
- // assignments
- if (is_array($_REQUEST['techs'])) {
- $db->query("SELECT techid, completed, stamp FROM calendar_task_tech WHERE eventid = '" . intval($id) . "'");
- while ($result = $db->row_array()) {
- $completed[$result['techid']]['completed'] = $result['completed'];
- $completed[$result['techid']]['stamp'] = $result['stamp'];
- }
- $db->query("SELECT techid FROM calendar_task_tech WHERE eventid = '$id'");
- while ($res = $db->row_array()) {
- $oldlist[] = $res['techid'];
- }
- $newlist = @array_diff($_REQUEST['techs'], $oldlist);
- $db->query("DELETE FROM calendar_task_tech WHERE eventid = '" . intval($id) . "'");
- foreach ($_REQUEST['techs'] AS $key => $var) {
- if (!isset($completed[$var])) {
- $completed[$var]['completed'] = 0;
- $completed[$var]['stamp'] = time();
- }
- $db->query("REPLACE INTO calendar_task_tech SET
- email_due = " . intval($_REQUEST['email_due']) . ",
- email_before1 = " . intval($_REQUEST['email_before1']) . ",
- email_before2 = " . intval($_REQUEST['email_before2']) . ",
- techid = " . intval($var) . ",
- eventid = " . intval($id) . ",
- completed = " . intval($completed[$var]['completed']) . ",
- stamp = " . intval($completed[$var]['stamp'])
- );
- }
- if (is_array($newlist) AND $_REQUEST['email_now']) {
- $db->query("SELECT id, username, email FROM tech WHERE id IN" .
- array2sql($_REQUEST['techs']) . " or id = '$user[id]'");
- while ($result = $db->row_array()) {
- $emails[$result['id']]['username'] = $result['username'];
- $emails[$result['id']]['email'] = $result['email'];
- }
- foreach($newlist AS $tech) {
- $taskusername = $emails[$user['id']]['username'];
- $taskurl = $settings['helpdesk_url'] . "/tech/calendar/viewtask.php?id=$id";
- $tasktitle = $_REQUEST['title'];
- $taskdescription = $_REQUEST['description'];
- eval(makeemaileval('message', 'TECHBODY_newtask', $subject));
- dp_mail($emails[$var][email], $subject, $message);
- }
- }
- }
- jump("viewtask.php?id=$id", 'Task updated.');
- }
- ############################### EDIT TASK ###############################
- if ($_REQUEST['do'] == "edit") {
- $task = $db->query_return("SELECT * FROM calendar_task WHERE id = '$id'");
- $sched = $db->query_return("SELECT * FROM calendar_task_tech WHERE eventid = '$id' AND techid = '$user[id]'");
- $task['email_before1'] = $sched['email_before1'];
- $task['email_before2'] = $sched['email_before2'];
- echo "<form action="edit.php" method="post">";
- ////////////////////////// ENTRY DETAILS //////////////////////////
- $table[] = array(table_thelp('<b>Entry Title</b>', 'Calendar', 'Events: Title') , form_input('title', $task['title']));
- $table[] = array(table_thelp('<b>Entry Date</b>', 'Calendar', 'Events: Due Date'), form_date('startdate', '', '', 1, '', $task['startdate']));
- $table[] = array(table_thelp('<b>Entry Time</b>', 'Calendar', 'Events: Time'), form_checkbox_single('using_time', 1, iff($task['starttime'] != '00:00:00', 1, 0))
- . " " . form_time('time', iff($task['starttime'] != '00:00:00', $task['starttime'], NULL), 1));
- $table[] = array(table_thelp('<b>Entry Timezone</b>', 'Calendar', 'Events: Timezone'), make_timezone($task['timezone']));
- $table[] = array(table_thelp('<b>Entry Description</b>', 'Calendar', 'Events: Description'), form_textarea('description', 60, 8, $task['description']));
- $table[] = array(table_thelp('<b>Email Reminders</b>', 'Calendar', 'Events: Reminders'),
- form_checkbox_single('email_due', 1, $task['email_due']) . " on due day<br />" .
- "and/or " . form_input('email_before1', $task['email_before1'], 2) . " day(s) before<br />" .
- "and/or " . form_input('email_before2', $task['email_before2'], 2) . " day(s) before<br />"
- );
- $width = array('60%', '40%');
- table_header("Edit Task (#$id)");
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table);
- ////////////////////////// TECH ASSIGNED //////////////////////////
- $db->query("SELECT id,username FROM tech order by username");
- while ($result = $db->row_array()) {
- $tech[$result['id']] = $result['username'];
- }
- $db->query("SELECT calendar_task_tech.techid
- FROM calendar_task_tech
- WHERE eventid = '$id'
- ");
- while ($result = $db->row_array()) {
- $assigned_techs[] = $result['techid'];
- }
- $total = $db->num_rows();
- if ($total < 10) {
- $selsize = $total;
- } else {
- $selsize = 10;
- }
- if ($selsize < 5) {
- $selsize = 5;
- }
- $tmp = form_select('techs', $tech, '', $assigned_techs, '', '', $selsize);
- $table[] = array(table_thelp('<b>Assign to Technicians</b> ', 'Calendar', 'Events: Assignments'), $tmp);
- $table[] = array(table_thelp('<b>E-mail Now</b> ', 'Calendar', 'Events: Mail Now?'), form_radio_yn('email_now'));
- $table[] = array(table_thelp('<b>Multiple or Single?</b> ', 'Calendar', 'Events: Multiple or Single?'),
- "<TABLE><TR valign="top"><TD>" .
- form_radio_single('globalcomplete', 0, iff($globalcomplete, 0, 1)) .
- "</td><td><B>Yes</B>, every assigned technician must complete the task</td></tr><tr valign="top"><td>" .
- form_radio_single('globalcomplete', 1, iff($globalcomplete, 1, 0)) .
- "</td><td><B>No</B>, once any assigned technician completes the task, it is complete for everyone</td></tr></table>");
- $table[] = array(table_thelp('<b>E-mail on Completion?</b> ', 'Calendar', 'Events: E-mail on Completion?'), form_radio_yn('notifycompletion'));
- table_header('Assigned Technicians');
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table);
- ////////////////////////// REPEAT OPTIONS //////////////////////////
-
- if ($task['repeattype']) {
- $month = array('1' => 'Jan', '2' => 'Feb', '3' => 'Mar', '4' => 'Apr', '5' => 'May', '6' => 'Jun', '7' => 'Jul', '8' => 'Aug', '9' => 'Sep', '10' => 'Oct', '11' => 'Nov', '12' => 'Dec');
- $days = array();
- switch ($task['repeattype']) {
- case '1':
- $rep1 = 'checked';
- break;
- case '2':
- $rep2 = 'checked';
- $days = explode('|', $task['value2']);
- break;
- case '3':
- $rep3 = 'checked';
- break;
- case '4':
- $rep4 = 'checked';
- break;
- }
-
- $table[] = table_midheader('Repeat Type');
- $table[] = array(table_thelp('<B>No Repeat</B> ', 'Calendar', 'Events: Repeat Type'),
- "<input type="radio" name="type" value="0" $rep0> No Repeat");
- $table[] = array(table_thelp('<b>Daily Repeat</b> ', 'Calendar', 'Events: Repeat Type'),
- "<input type="radio" name="type" value="1" $rep1> Repeat every " . form_input('value11', iff($rep1, $task['value1'], $task['value1']), 1) . " day(s)<br />");
- $table[] = array(table_thelp('<b>Weekly Repeat</b> ', 'Calendar', 'Events: Repeat Type'),
- "<input type="radio" name="type" value="2" $rep2> Repeat every " . form_input('value21', iff($rep2, $task['value1'], $task['value1']), 1) . " week(s) on <br /> " .
- form_checkbox_single('1', 1, in_array(1, $days), 'value22') . " Sun " .
- form_checkbox_single('2', 1, in_array(2, $days), 'value22') . " Mon " .
- form_checkbox_single('3', 1, in_array(3, $days), 'value22') . " Tue " .
- form_checkbox_single('4', 1, in_array(4, $days), 'value22') . " Wed " .
- form_checkbox_single('5', 1, in_array(5, $days), 'value22') . " Thu " .
- form_checkbox_single('6', 1, in_array(6, $days), 'value22') . " Fri " .
- form_checkbox_single('7', 1, in_array(7, $days), 'value22') . " Sat ");
- $table[] = array(table_thelp('<b>Monthly Repeat</b> ', 'Calendar', 'Events: Repeat Type'),
- "<input type="radio" name="type" value="3" $rep3> Repeat on date " . form_select('value31', make_numberarray(1, 31), '', iff($rep3, $task['value1'])) . " of every " . form_input('value32', iff($rep3, $task['value2']), 3) . " month(s)");
- $table[] = array(table_thelp('<b>Yearly Repeat</b> ', 'Calendar', 'Events: Repeat Type'),
- "<input type="radio" name="type" value="4" $rep4> Repeat every year on date " . form_select('value41', make_numberarray(1, 31), '', iff($rep4, $task['value1'])) . " " . form_select('value42', $month, '', iff($rep4, $task['value2'])));
- $table[] = table_midheader('Repetition Options');
- $table[] = array(table_thelp('<b>End Date</b> ', 'Calendar', 'Events: Repeat End Date'),
- form_radio_single('repeat_until', '0', iff($task['enddate'], 0, 1)) . " Repeat Forever<BR>" .
- form_radio_single('repeat_until', '1', iff($task['enddate'], 1, 0)) . " Repeat Until: " .
- form_date('enddate', '', '', 0, '', iff($task['enddate'], $task['enddate'], '')));
- table_header('Repeat Options');
- table_content('', $table, '', '', '', '', $width);
- table_footer();
- unset($table);
- echo "<script language="javascript">$js</script>";
- }
- echo form_hidden('do', 'edit2');
- echo form_hidden('id', $id);
- echo "<center><input type="submit" name="submit" value="Edit Task"></center></form>";
- }
- tech_footer();
- ?>