PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/duties.php

https://github.com/obenauer/equilibrium
PHP | 1830 lines | 1351 code | 285 blank | 194 comment | 354 complexity | 4fff853d547692b32e0448f1da902296 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // Copyright 2008, St. Jude Children's Research Hospital.
  3. // Written by Dr. John Obenauer, john.obenauer@stjude.org.
  4. // This file is part of Equilibrium. Equilibrium is free software:
  5. // you can redistribute it and/or modify it under the terms of the
  6. // GNU General Public License as published by the Free Software
  7. // Foundation, either version 2 of the License, or (at your option)
  8. // any later version.
  9. // Equilibrium is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License
  14. // along with Equilibrium. If not, see <http://www.gnu.org/licenses/>.
  15. require("check_login.php");
  16. require_once("config.php");
  17. // Check for passed arguments
  18. if (isset($_REQUEST['action'])) {
  19. $action = $_REQUEST['action'];
  20. } else {
  21. $action = "";
  22. }
  23. if (isset($_REQUEST['status'])) {
  24. $status = $_REQUEST['status'];
  25. } else {
  26. $status = "Active";
  27. }
  28. if (isset($_REQUEST['staff'])) {
  29. $staff = $_REQUEST['staff'];
  30. } else {
  31. if ($_SESSION['SESSION_STAFF'] == "Y") {
  32. $staff = $_SESSION['SESSION_USERID'];
  33. } else {
  34. $staff = 0;
  35. }
  36. }
  37. if (isset($_REQUEST['maxresults'])) {
  38. $maxresults = $_REQUEST['maxresults'];
  39. if ($maxresults == 0) {
  40. $maxresults = 10;
  41. }
  42. } else {
  43. $maxresults = 10;
  44. }
  45. if (isset($_REQUEST['page'])) {
  46. $page = $_REQUEST['page'];
  47. } else {
  48. $page = 1;
  49. }
  50. if (isset($_REQUEST['cmd'])) {
  51. $cmd = $_REQUEST['cmd'];
  52. } else {
  53. $cmd = "";
  54. }
  55. if (isset($_REQUEST['title'])) {
  56. $title = $_REQUEST['title'];
  57. } else {
  58. $title = "";
  59. }
  60. if (isset($_REQUEST['dtype'])) {
  61. $dtype = $_REQUEST['dtype'];
  62. } else {
  63. $dtype = "";
  64. }
  65. if (isset($_REQUEST['description'])) {
  66. $description = $_REQUEST['description'];
  67. } else {
  68. $description = "";
  69. }
  70. if (isset($_REQUEST['client'])) {
  71. $client = $_REQUEST['client'];
  72. } else {
  73. $client = "";
  74. }
  75. if (isset($_REQUEST['contact'])) {
  76. $contact = $_REQUEST['contact'];
  77. } else {
  78. $contact = "";
  79. }
  80. if (isset($_REQUEST['enterdate'])) {
  81. $enterdate = $_REQUEST['enterdate'];
  82. } else {
  83. $enterdate = "";
  84. }
  85. if (isset($_REQUEST['project'])) {
  86. $project = $_REQUEST['project'];
  87. } else {
  88. $project = 0;
  89. }
  90. if (isset($_REQUEST['duty'])) {
  91. $duty = $_REQUEST['duty'];
  92. } else {
  93. $duty = 0;
  94. }
  95. if (isset($_REQUEST['visibility'])) {
  96. $visibility = $_REQUEST['visibility'];
  97. } else {
  98. $visibility = 'Public';
  99. }
  100. if (isset($_REQUEST['fromdate'])) {
  101. $fromdate = $_REQUEST['fromdate'];
  102. } else {
  103. // Default: one month ago
  104. $prevmonth = mktime(0, 0, 0, date("m") - 1, date("d"), date("Y"));
  105. $fromdate = date("Y", $prevmonth) . "-" . date("m", $prevmonth) . "-" .
  106. date("d", $prevmonth);
  107. }
  108. if (isset($_REQUEST['todate'])) {
  109. $todate = $_REQUEST['todate'];
  110. } else {
  111. // Default: today's date
  112. $todate = date('Y') . "-" . date('m') . "-" . date('d');
  113. }
  114. if (isset($_REQUEST['newstatus'])) {
  115. $newstatus = $_REQUEST['newstatus'];
  116. } else {
  117. $newstatus = "";
  118. }
  119. if (isset($_REQUEST['comment'])) {
  120. $comment = $_REQUEST['comment'];
  121. } else {
  122. $comment = "";
  123. }
  124. if (isset($_REQUEST['submitter'])) {
  125. $submitter = $_REQUEST['submitter'];
  126. } else {
  127. $submitter = "";
  128. }
  129. if (isset($_REQUEST['dirtree'])) {
  130. $dirtree = $_REQUEST['dirtree'];
  131. } else {
  132. $dirtree = "";
  133. }
  134. if (isset($_FILES['filename'])) {
  135. $filename = $_FILES['filename']['name'];
  136. } else {
  137. $filename = "";
  138. }
  139. if (isset($_REQUEST['existingfile'])) {
  140. $existingfile = $_REQUEST['existingfile'];
  141. } else {
  142. $existingfile = "";
  143. }
  144. if (isset($_REQUEST['filecat'])) {
  145. $filecat = $_REQUEST['filecat'];
  146. } else {
  147. $filecat = "";
  148. }
  149. if (isset($_REQUEST['filedesc'])) {
  150. $filedesc = $_REQUEST['filedesc'];
  151. } else {
  152. $filedesc = "";
  153. }
  154. if (isset($_REQUEST['file_id'])) {
  155. $file_id = $_REQUEST['file_id'];
  156. } else {
  157. $file_id = "";
  158. }
  159. if (isset($_REQUEST['order'])) {
  160. $order = $_REQUEST['order'];
  161. } else {
  162. $order = "";
  163. }
  164. if (isset($_REQUEST['edit_priv'])) {
  165. $edit_priv = $_REQUEST['edit_priv'];
  166. } else {
  167. $edit_priv = "N";
  168. }
  169. if (isset($_REQUEST['todostatus'])) {
  170. $todostatus = $_REQUEST['todostatus'];
  171. } else {
  172. $todostatus = "Pending";
  173. }
  174. if (isset($_REQUEST['priority'])) {
  175. $priority = $_REQUEST['priority'];
  176. } else {
  177. $priority = "High";
  178. }
  179. if (isset($_REQUEST['calmode'])) {
  180. $calmode = $_REQUEST['calmode'];
  181. } else {
  182. $calmode = 0;
  183. }
  184. if (isset($_REQUEST['firstname'])) {
  185. $firstname = $_REQUEST['firstname'];
  186. } else {
  187. $firstname = "";
  188. }
  189. if (isset($_REQUEST['lastname'])) {
  190. $lastname = $_REQUEST['lastname'];
  191. } else {
  192. $lastname = "";
  193. }
  194. if (isset($_REQUEST['email'])) {
  195. $email = $_REQUEST['email'];
  196. } else {
  197. $email = "";
  198. }
  199. if (isset($_REQUEST['departmenttext'])) {
  200. $departmenttext = $_REQUEST['departmenttext'];
  201. } else {
  202. $departmenttext = "";
  203. }
  204. if (isset($_REQUEST['assistants'])) {
  205. $assistants = $_REQUEST['assistants'];
  206. } else {
  207. $assistants = "";
  208. }
  209. // Declare PHP functions
  210. require("equilibrium.php");
  211. function display_duty_form($action, $duty, $errormsg, $params) {
  212. require_once("config.php");
  213. global $background_color;
  214. global $heading_color;
  215. global $display_client_contact;
  216. global $client_organization_label;
  217. // Only the assigned staff or administrators can edit this duty, unless it's not assigned
  218. if (($_SESSION['SESSION_ADMIN'] == "Y") || ($staff == $_SESSION['SESSION_USERID'])
  219. || ($staff == 0)) {
  220. $edit_priv = "Y";
  221. } else {
  222. $edit_priv = "N";
  223. }
  224. // If parameters were passed, use those
  225. if ($params) {
  226. $title = $params['title'];
  227. $dtype = $params['dtype'];
  228. $description = $params['description'];
  229. $staff = $params['staff'];
  230. $client = $params['client'];
  231. $contact = $params['contact'];
  232. $enterdate = $params['enterdate'];
  233. $visibility = $params['visibility'];
  234. $status = $params['status'];
  235. $firstname = $params['firstname'];
  236. $lastname = $params['lastname'];
  237. $email = $params['email'];
  238. $departmenttext = $params['departmenttext'];
  239. $assistants = $params['assistants'];
  240. if ($enterdate == "0000-00-00") {
  241. $enterdate = "";
  242. }
  243. } else {
  244. // If adding, initialize variables
  245. if ($action == "add") {
  246. $title = "";
  247. $dtype = 0;
  248. $description = "";
  249. if ($_SESSION['SESSION_ADMIN'] == "Y") {
  250. if ($_SESSION['SESSION_STAFF'] == "Y") {
  251. $staff = $_SESSION['SESSION_USERID'];
  252. } else {
  253. $staff = 0;
  254. }
  255. } else {
  256. if ($_SESSION['SESSION_STAFF'] == "Y") {
  257. $staff = $_SESSION['SESSION_USERID'];
  258. } else {
  259. $staff = 0;
  260. }
  261. }
  262. $client = 0;
  263. $contact = "";
  264. //$enterdate = date("F") . " " . date("j") . ", " . date("Y");
  265. $enterdate = date("m") . "/" . date("d") . "/" . date("Y");
  266. $status = "Active";
  267. $icon = 0;
  268. } else if ($action == "edit") {
  269. // For editing, retrieve existing fields from database
  270. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  271. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  272. mysql_select_db(DB_DATABASE);
  273. $get_fields = mysql_query("select d.title, t.duty_type_id, d.description, " .
  274. "u.user_id, c.client_id, d.contact, d.visibility, " .
  275. "d.date_entered, d.status, d.icon_id from duties as d " .
  276. "left join duty_types as t on d.duty_type_id = t.duty_type_id " .
  277. "left join users as u on d.staff_assigned = u.user_id " .
  278. "left join clients as c on d.client_id = c.client_id " .
  279. "where d.duty_id = \"$duty\" ");
  280. if ($row = mysql_fetch_array($get_fields)) {
  281. $title = $row['title'];
  282. $dtype = $row['duty_type_id'];
  283. $description = $row['description'];
  284. $staff = $row['user_id'];
  285. $client = $row['client_id'];
  286. $contact = $row['contact'];
  287. $enterdate = standard_date($row['date_entered']);
  288. $visibility = $row['visibility'];
  289. $status = $row['status'];
  290. $icon = $row['icon_id'];
  291. } else {
  292. printf("Error: unable to retrieve this duty from database.<br>\n");
  293. }
  294. mysql_free_result($get_fields);
  295. // Get list of assistants, if any
  296. $assistants = array();
  297. $get_assistants = mysql_query("select staff_id from assistants " .
  298. "where duty_id = \"$duty\" ");
  299. while ($row = mysql_fetch_array($get_assistants, MYSQL_ASSOC)) {
  300. array_push($assistants, $row['staff_id']);
  301. }
  302. mysql_free_result($get_assistants);
  303. mysql_close($conn);
  304. }
  305. }
  306. // If this is a private duty, make sure user has access
  307. if (($visibility == "Private") && ($_SESSION['SESSION_USERID'] != $staff)) {
  308. printf("<p>This is a private duty. Only its owner has access to this page.</p>\n");
  309. printf("<p>Return to <a href='duties.php'>Duties page</a>.</p>\n");
  310. return;
  311. }
  312. // Add/Edit duty form
  313. printf("<form action='duties.php' method='post' name='duty'>\n");
  314. printf("<table cellpadding='10'><tr valign='top'><td width='50%%'>\n");
  315. //printf("<div id='project_left'>\n");
  316. printf("<table>\n");
  317. // Duty title
  318. printf("<tr><td>Title</td>\n");
  319. printf("<td><input type='text' name='title' style='{width: 25em}' value=\"$title\"></td></tr>\n");
  320. // Duty type
  321. printf("<tr><td>Type</td>\n");
  322. printf("<td><select name='dtype' id='dtype' size='1' onChange=\"document.getElementById('dtypedesc').firstChild.nodeValue = dtypedescs[document.getElementById('dtype').selectedIndex];\">\n");
  323. // Retrieve duty type names and descriptions from database
  324. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  325. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  326. mysql_select_db(DB_DATABASE);
  327. $get_types = mysql_query("select duty_type_id, name, description from duty_types " .
  328. "order by duty_type_id asc ");
  329. printf("<option value='0' selected>\n");
  330. $dutytypedesclist = array();
  331. $dutytypedesclist[0] = "Select a type for this duty.";
  332. $ndutytypes = 1;
  333. while ($row = mysql_fetch_array($get_types)) {
  334. if ($dtype == $row[0]) {
  335. printf("<option value='$row[0]' selected>$row[1]\n");
  336. } else {
  337. printf("<option value='$row[0]'>$row[1]\n");
  338. }
  339. $dutytypedesclist[$ndutytypes] = "$row[2]";
  340. $ndutytypes++;
  341. }
  342. mysql_free_result($get_types);
  343. mysql_close($conn);
  344. printf("</select></td></tr>\n");
  345. // Create JavaScript array of duty type descriptions
  346. printf("<script language='JavaScript'>\n");
  347. printf("var dtypedescs = new Array(%d);\n", $ndutytypes);
  348. for ($i = 0; $i < $ndutytypes; $i++) {
  349. printf("dtypedescs[$i] = '$dutytypedesclist[$i]';\n");
  350. }
  351. printf("</script>\n");
  352. if ($dtype == "") {
  353. $dtype = 0;
  354. }
  355. printf("<tr><td colspan='2'><div id='dtypedesc'>$dutytypedesclist[$dtype]</div></td></tr>\n");
  356. // Duty description
  357. printf("<tr><td colspan='2'>Description</td>\n");
  358. printf("<tr><td colspan='2'><textarea name='description' class='description' rows='6' cols='60'>" .
  359. "$description</textarea></td></tr>\n");
  360. printf("</table>\n");
  361. //printf("</div><div id='project_right'>\n");
  362. printf("</td><td width='50%%'>\n");
  363. printf("<table>\n");
  364. // Assigned staff member -- default is whoever's logged in
  365. printf("<tr><td align='right'>Assigned to: &nbsp; </td>");
  366. // Only administrators can assign duties to other people
  367. if ($_SESSION['SESSION_ADMIN'] == "Y") {
  368. printf("<td><select name='staff' size='1'>\n");
  369. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  370. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  371. mysql_select_db(DB_DATABASE);
  372. $get_staff = mysql_query("select user_id, first_name, last_name from users " .
  373. "where staff_flag = \"Y\" order by last_name ");
  374. if ($staff == 0) {
  375. printf("<option value='0' selected>\n");
  376. } else {
  377. printf("<option value='0'>\n");
  378. }
  379. $displayed_user = "";
  380. while ($row = mysql_fetch_array($get_staff)) {
  381. if ($staff == $row[0]) {
  382. printf("<option value='$row[0]' selected>$row[1] $row[2]\n");
  383. $displayed_user = "$row[1] $row[2]";
  384. } else {
  385. printf("<option value='$row[0]'>$row[1] $row[2]\n");
  386. }
  387. }
  388. mysql_free_result($get_staff);
  389. mysql_close($conn);
  390. printf("</select></td></tr>\n");
  391. } else {
  392. if ($staff == 0) {
  393. printf("<td><select name='staff' size='1'>\n");
  394. printf("<option value='0' selected>\n");
  395. printf("<option value='%d'>%s\n", $_SESSION['SESSION_USERID'], $_SESSION['SESSION_USER']);
  396. printf("</select></td></tr>\n");
  397. } else {
  398. printf("<td>%s\n", $_SESSION['SESSION_USER']);
  399. printf("<input type='hidden' name='staff' value='$staff'>");
  400. printf("</td></tr>\n");
  401. }
  402. }
  403. // Assisting staff
  404. printf("<tr><td align='right'>Assisting: &nbsp; </td>");
  405. // Only administrators can assign projects to other people
  406. printf("<td><select name='assistants[]' size='4' multiple>\n");
  407. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  408. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  409. mysql_select_db(DB_DATABASE);
  410. $get_staff = mysql_query("select user_id, first_name, last_name from users " .
  411. "where staff_flag = \"Y\" order by last_name ");
  412. if (isset($assistants)) {
  413. printf("<option value='0'>(None)\n");
  414. } else {
  415. printf("<option value='0' selected>(None)\n");
  416. }
  417. $selectedstaff = 0;
  418. while ($row = mysql_fetch_array($get_staff)) {
  419. if (isset($assistants)) {
  420. foreach ($assistants as $s) {
  421. if ($s == $row[0]) {
  422. $selectedstaff = 1;
  423. break;
  424. }
  425. }
  426. }
  427. if ($selectedstaff) {
  428. printf("<option value='$row[0]' selected>$row[1] $row[2]\n");
  429. } else {
  430. printf("<option value='$row[0]'>$row[1] $row[2]\n");
  431. }
  432. $selectedstaff = 0;
  433. }
  434. mysql_free_result($get_staff);
  435. mysql_close($conn);
  436. printf("</select></td></tr>\n");
  437. // Visibility
  438. printf("<tr><td align='right'>Visibility: &nbsp; </td>");
  439. printf("<td><select name='visibility' size='1'>\n");
  440. if ($visibility == 'Private') {
  441. printf("<option value='Public'>Public\n");
  442. printf("<option value='Private' selected>Private\n");
  443. } else {
  444. printf("<option value='Public' selected>Public\n");
  445. printf("<option value='Private'>Private\n");
  446. }
  447. // Duty status
  448. $statuslist = array("Active", "Inactive");
  449. printf("<tr><td align='right'>Status: &nbsp; </td>");
  450. printf("<td><select name='status' size='1'>\n");
  451. for ($i = 0; $i < count($statuslist); $i++) {
  452. if ($status == $statuslist[$i]) {
  453. printf("<option value='$statuslist[$i]' selected>$statuslist[$i]\n");
  454. } else {
  455. printf("<option value='$statuslist[$i]'>$statuslist[$i]\n");
  456. }
  457. }
  458. printf("</select></td></tr>\n");
  459. // Contact person
  460. if ($display_client_contact == "Y") {
  461. printf("<tr><td align='right'>Contact: &nbsp; </td>");
  462. printf("<td><input type='text' name='contact' size='20' value='$contact'></td></tr>\n");
  463. }
  464. // Existing client / New client selection
  465. printf("<tr><td colspan='2' align='center'><font id='exclabel' onclick='clientflag " .
  466. "= \"Existing Client\"; toggle_client_div(clientflag);' style='font-weight: bold'>");
  467. printf("Existing Client</font> / ");
  468. printf("<font id='newclabel' onclick='clientflag = \"New Client\"; toggle_client_div(clientflag);' style='font-weight: normal' >New Client</font></td></tr>\n");
  469. // Existing client form
  470. printf("<tr><td colspan='2'><div id='exc_div'>\n");
  471. printf("Client: &nbsp; <select name='client' size='1'>\n");
  472. printf("<option value='0' selected>\n");
  473. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  474. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  475. mysql_select_db(DB_DATABASE);
  476. // First list faculty members the logged-in user has worked for before
  477. $get_past_clients = mysql_query("select h.client_id, count(*) as countval, c.first_name, c.last_name " .
  478. "from client_history as h, clients as c where h.client_id = c.client_id " .
  479. "and h.staff_id = \"" . $_SESSION['SESSION_USERID'] . "\" group by h.client_id order by countval desc ");
  480. while ($row = mysql_fetch_array($get_past_clients)) {
  481. printf("<option value='$row[0]' style='background-color: %s;'>$row[2] $row[3]\n", $heading_color);
  482. }
  483. mysql_free_result($get_past_clients);
  484. printf("<option value='0'>-----------------------\n");
  485. // Now list all faculty members
  486. $get_clients = mysql_query("select client_id, first_name, last_name from clients " .
  487. "order by last_name, first_name ");
  488. while ($row = mysql_fetch_array($get_clients)) {
  489. if ($client == $row[0]) {
  490. printf("<option value='$row[0]' selected>$row[1] $row[2]\n");
  491. } else {
  492. printf("<option value='$row[0]'>$row[1] $row[2]\n");
  493. }
  494. }
  495. mysql_free_result($get_clients);
  496. mysql_close($conn);
  497. printf("</select><br>\n");
  498. printf("</div>\n");
  499. // New client form
  500. printf("<div id='newc_div' style='display:none'>\n");
  501. printf("<table>\n");
  502. printf("<tr><td>First Name: &nbsp; </td><td><input type='text' name='firstname' value='' size='20'></td></tr>\n");
  503. printf("<tr><td>Last Name: &nbsp; </td><td><input type='text' name='lastname' value='' size='20'></td></tr>\n");
  504. printf("<tr><td>Email: &nbsp; </td><td><input type='text' name='email' value='' size='20'></td></tr>\n");
  505. printf("<tr><td>$client_organization_label: &nbsp; </td><td>");
  506. // Department combo box
  507. printf("<input type='text' id='departmenttext' name='departmenttext' size='17' style='width: 160'>\n");
  508. printf("<input type='button' hidefocus='1' value='&#9660;' ");
  509. printf("style='height:23; width:22; font-family: helvetica;' ");
  510. printf("onclick=\"JavaScript:menuActivate('departmenttext', 'combodiv', 'combosel')\">\n");
  511. printf("<div id='combodiv' style='position:absolute; display:none; top:0px; ");
  512. printf("left:0px; z-index:10000' onmouseover=\"javascript:oOverMenu='combodiv';\" ");
  513. printf("onmouseout=\"javascript:oOverMenu=false;\">\n");
  514. printf("<select size='10' id='departmentsel' style='width: 160; border-style: none' ");
  515. printf("onclick=\"JavaScript:textSet('departmenttext',this.options[selectedIndex].text);\" ");
  516. printf("onkeypress=\"JavaScript:comboKey('departmenttext', this);\">\n");
  517. // List all departments
  518. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  519. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  520. mysql_select_db(DB_DATABASE);
  521. $get_depts = mysql_query("select department_id, name from departments " .
  522. "order by name asc ");
  523. while ($row = mysql_fetch_array($get_depts)) {
  524. printf("<option value='$row[0]'>$row[1]</option>\n");
  525. }
  526. mysql_free_result($get_depts);
  527. mysql_close($conn);
  528. printf("</select></div>\n");
  529. printf("</td></tr>\n");
  530. printf("</table>\n");
  531. printf("</div></td></tr>\n");
  532. // Only show date forms when editing projects
  533. if ($action == "edit") {
  534. // Date entered
  535. printf("<tr><td align='right'>Date entered: &nbsp; </td><td>\n");
  536. show_date_form('enterdate', $enterdate);
  537. printf("</td></tr>\n");
  538. }
  539. printf("</table>\n");
  540. // Print validation error message, if any
  541. if ($errormsg) {
  542. printf("$errormsg");
  543. }
  544. //printf("</div>\n");
  545. printf("</td></tr></table>\n");
  546. if ($action == "add") {
  547. printf("<input type='hidden' name='cmd' value='insert'>\n");
  548. printf("<input type='submit' value='Submit duty'>\n");
  549. } else if ($action == "edit") {
  550. printf("<input type='hidden' name='cmd' value='update'>\n");
  551. printf("<input type='hidden' name='duty' value='$duty'>\n");
  552. printf("<input type='submit' value='Update duty'>\n");
  553. }
  554. printf("</form>\n");
  555. }
  556. function display_duty_details($duty) {
  557. require_once("config.php");
  558. global $background_color;
  559. global $heading_color;
  560. // Initialize variables
  561. $title = "";
  562. $dtype = 0;
  563. $description = "";
  564. $staff = $_SESSION['SESSION_USERID'];
  565. $client = 0;
  566. $contact = "";
  567. $enterdate = "";
  568. $status = "";
  569. $visibility = "";
  570. $icon = 0;
  571. // Retrieve existing fields from database
  572. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  573. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  574. mysql_select_db(DB_DATABASE);
  575. $get_fields = mysql_query("select d.title, t.name, d.description, " .
  576. "u.first_name, u.last_name, c.first_name as client_first, " .
  577. "c.last_name as client_last, d.contact, d.visibility, " .
  578. "d.date_entered, d.status, d.icon_id from duties as d " .
  579. "left join duty_types as t on d.duty_type_id = t.duty_type_id " .
  580. "left join users as u on d.staff_assigned = u.user_id " .
  581. "left join clients as c on d.client_id = c.client_id " .
  582. "where d.duty_id = \"$duty\" ");
  583. if ($row = mysql_fetch_array($get_fields)) {
  584. $title = $row['title'];
  585. $dtype = $row['name'];
  586. $description = $row['description'];
  587. $displayed_user = $row['first_name'] . " " . $row['last_name'];
  588. $client = $row['client_first'] . " " . $row['client_last'];
  589. $contact = $row['contact'];
  590. $enterdate = pretty_date($row['date_entered']);
  591. $status = $row['status'];
  592. $visibility = $row['visibility'];
  593. $icon = $row['icon_id'];
  594. } else {
  595. printf("Error: unable to retrieve this duty from database.<br>\n");
  596. }
  597. mysql_free_result($get_fields);
  598. // Get list of assistants, if any
  599. $assistants = array();
  600. $get_assistants = mysql_query("select staff_id from assistants " .
  601. "where duty_id = \"$duty\" ");
  602. while ($row = mysql_fetch_array($get_assistants, MYSQL_ASSOC)) {
  603. array_push($assistants, $row['staff_id']);
  604. }
  605. mysql_free_result($get_assistants);
  606. mysql_close($conn);
  607. // Only the assigned staff or administrators can edit this project, unless it's not assigned
  608. if (($_SESSION['SESSION_ADMIN'] == "Y") || ($displayed_user == $_SESSION['SESSION_USER'])
  609. || (trim($displayed_user) == "")) {
  610. $edit_priv = "Y";
  611. } else {
  612. $edit_priv = "N";
  613. }
  614. // If this is a private duty, make sure user has access
  615. if (($visibility == "Private") && ($_SESSION['SESSION_USERID'] != $staff)) {
  616. printf("<p>This is a private duty. Only its owner has access to this page.</p>\n");
  617. printf("<p>Return to <a href='duties.php'>Duties page</a>.</p>\n");
  618. return;
  619. }
  620. // Page heading
  621. printf("<h2>Duty Details: $title</h2>\n");
  622. // Button: Add New Duty
  623. printf("<table><tr>\n");
  624. if (($_SESSION['SESSION_ADMIN'] == "Y") || ($_SESSION['SESSION_STAFF'] == "Y")) {
  625. printf("<td><form action='duties.php' method='post'>\n");
  626. printf("<input type='hidden' name='action' value='add'><input type='submit' value='Add New Duty'></form></td>\n");
  627. }
  628. // Button: Edit This Duty
  629. if ($edit_priv == "Y") {
  630. printf("<td><form action='duties.php' method='post'>\n");
  631. printf("<input type='hidden' name='action' value='edit'>\n");
  632. printf("<input type='hidden' name='duty' value='$duty'>\n");
  633. printf("<input type='submit' value='Edit This Duty'></form></td>\n");
  634. }
  635. printf("</tr></table>\n");
  636. // Duty description
  637. $description = ereg_replace("%", "%%", $description);
  638. printf("<p>$description</p>\n");
  639. printf("<table cellpadding='10'><tr valign='top'><td width='50%%'>\n");
  640. //printf("<table cellpadding='10'><tr valign='top'><td>\n");
  641. printf("<table>\n");
  642. // Duty type
  643. printf("<tr><td>Type: &nbsp; </td>\n");
  644. printf("<td class='values' style='border: 1px solid $heading_color;'>$dtype<br></td></tr>\n");
  645. // Assigned staff member
  646. printf("<tr><td>Assigned to: &nbsp; </td>");
  647. printf("<td class='values' style='border: 1px solid $heading_color;'>$displayed_user<br></td></tr>\n");
  648. // Assisting staff
  649. if (isset($assistants)) {
  650. // Get staff list
  651. $stafflist = array();
  652. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  653. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  654. mysql_select_db(DB_DATABASE);
  655. $get_staff = mysql_query("select user_id, first_name, last_name from users " .
  656. "order by last_name asc, first_name asc ");
  657. while ($row = mysql_fetch_array($get_staff, MYSQL_ASSOC)) {
  658. $stafflist[$row['user_id']] = $row['first_name'] . " " . $row['last_name'];
  659. }
  660. mysql_free_result($get_staff);
  661. mysql_close($conn);
  662. // Display assistants
  663. $firstassistant = 1;
  664. foreach ($assistants as $s) {
  665. if ($firstassistant) {
  666. printf("<tr><td>Assisting: &nbsp; </td>");
  667. printf("<td class='values' style='border: 1px solid " .
  668. "$heading_color;'>$stafflist[$s]<br></td></tr>\n");
  669. $firstassistant = 0;
  670. } else {
  671. printf("<tr><td><br></td>");
  672. printf("<td class='values' style='border: 1px solid " .
  673. "$heading_color;'>$stafflist[$s]<br></td></tr>\n");
  674. }
  675. }
  676. }
  677. // Client
  678. printf("<tr><td>Client PI: &nbsp; </td>");
  679. printf("<td class='values' style='border: 1px solid $heading_color;'>$client<br></td></tr>\n");
  680. // Contact person
  681. printf("<tr><td>Contact: &nbsp; </td>");
  682. printf("<td class='values' style='border: 1px solid $heading_color;'>$contact<br></td></tr>\n");
  683. // Visibility
  684. printf("<tr><td>Visibility: &nbsp; </td>");
  685. if ($visibility == "Private") {
  686. printf("<td class='values' style='border: 1px solid $heading_color; background-color: $heading_color'>$visibility<br></td></tr>\n");
  687. } else {
  688. printf("<td class='values' style='border: 1px solid $heading_color;'>$visibility<br></td></tr>\n");
  689. }
  690. printf("</table>\n");
  691. //printf("</div><div id='project_right'>\n");
  692. printf("</td><td width='50%%' valign='top'>\n");
  693. //printf("</td><td valign='bottom'>\n");
  694. printf("<table>\n");
  695. // Date entered
  696. printf("<tr><td align='right'>Date entered: &nbsp; </td>");
  697. printf("<td class='values' style='border: 1px solid $heading_color;'>$enterdate<br></td></tr>\n");
  698. // Duty status
  699. printf("<tr><td align='right'>Status: &nbsp; </td>");
  700. printf("<td class='values' style='border: 1px solid $heading_color;'>$status<br></td></tr>\n");
  701. // Duty icon
  702. printf("<tr><td align='right'>Icon: &nbsp; </td>");
  703. if ($icon == 0) {
  704. printf("<td class='values' style='border: 1px solid $heading_color;'>None<br></td></tr>\n");
  705. } else {
  706. printf("<td class='values' style='border: 1px solid $heading_color;'><img src='icons18/icon_%d.png'><br></td></tr>\n", $icon);
  707. }
  708. printf("</table>\n");
  709. printf("</td></tr></table>\n");
  710. return;
  711. }
  712. function show_duty_files($duty) {
  713. global $heading_color;
  714. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  715. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  716. mysql_select_db(DB_DATABASE);
  717. $get_files = mysql_query("select file_id, file_type, file_name, description, " .
  718. "upload_date, upload_time, file_path from files where duty_id = \"$duty\" " .
  719. "order by upload_time ");
  720. if (mysql_num_rows($get_files)) {
  721. while ($row = mysql_fetch_array($get_files, MYSQL_ASSOC)) {
  722. printf("<a href=\"%s/%s\">%s</a>, %s \n", $row['file_path'],
  723. $row['file_name'], $row['file_name'], $row['description']);
  724. if ($row['file_type']) {
  725. printf("(%s, %s) \n", $row['file_type'],
  726. short_date($row['upload_date']));
  727. } else {
  728. printf("(%s) &nbsp; \n", short_date($row['upload_date']));
  729. }
  730. printf("<img height='16' src='images/delete.png' title='Delete' " .
  731. "onclick='show_item(\"confirm_" . $row['file_id'] . "\");'><br>\n");
  732. // Div to confirm deletion
  733. printf("<div class='confirm' id='confirm_" . $row['file_id'] .
  734. "' ><font color='red'>" .
  735. "<center>Are you sure you want to delete this file?</font><br>");
  736. printf("<form action='duties.php#file_input' method='post'>\n");
  737. printf("<input type='hidden' name='file_id' value='%d'>\n",
  738. $row['file_id']);
  739. printf("<input type='hidden' name='dirtree' value='%s'>\n",
  740. $row['file_path']);
  741. printf("<input type='hidden' name='existingfile' value='%s'>\n",
  742. $row['file_name']);
  743. printf("<input type='hidden' name='cmd' value='deletefile'>\n");
  744. printf("<input type='hidden' name='duty' value='$duty'>\n");
  745. printf("<input type='submit' value='Confirm Deletion'> &nbsp; &nbsp; ");
  746. printf("<input type='button' value='Cancel' onclick='hide_item(\"confirm_" .
  747. $row['file_id'] . "\");'></center><br>");
  748. printf("</form>\n</div>\n");
  749. }
  750. } else {
  751. printf("<p>No files uploaded for this duty.</p>\n");
  752. }
  753. mysql_free_result($get_files);
  754. mysql_close($conn);
  755. return;
  756. }
  757. // Commands that don't generate HTML output
  758. switch($cmd) {
  759. case "insert":
  760. $enterdate = ugly_date($enterdate);
  761. // Validate submitted data
  762. if ((!trim($title)) || (!trim($dtype)) || (!trim($description))) {
  763. //if ((!trim($title)) || (!trim($description))) {
  764. // Missing fields; return to form
  765. $errormsg = "<p><font color='red'>* A title, type, and description are required for each duty.</font></p>\n";
  766. $activepage = "Duties";
  767. require("header.php");
  768. printf("<h2>Add New Duty</h2>\n");
  769. if (($_SESSION['SESSION_ADMIN'] == "Y") || ($_SESSION['SESSION_STAFF'] == "Y")) {
  770. $enterdate = standard_date($enterdate);
  771. $params['title'] = $title;
  772. $params['dtype'] = $dtype;
  773. $params['description'] = $description;
  774. $params['staff'] = $staff;
  775. $params['client'] = $client;
  776. $params['contact'] = $contact;
  777. $params['enterdate'] = $enterdate;
  778. $params['visibility'] = $visibility;
  779. $params['status'] = $status;
  780. $params['firstname'] = $firstname;
  781. $params['lastname'] = $lastname;
  782. $params['email'] = $email;
  783. $params['departmenttext'] = $departmenttext;
  784. $params['assistants'] = $assistants;
  785. display_duty_form("add", 0, "$errormsg", $params);
  786. } else {
  787. printf("<h3>Add New Duty -- Not Authorized</h3>");
  788. printf("<p>Only staff members and administrators can add new duties.</p>\n");
  789. printf("<p>Contact $admin_name (<a href='mailto:$admin_email'>" .
  790. "$admin_email)</a> to enable your user account to add duties.</p>\n");
  791. require("footer.php");
  792. }
  793. exit;
  794. } else {
  795. // Data passes inspection; pick an icon for this duty
  796. $icons = array();
  797. for ($i = 0; $i < $number_icons; $i++) {
  798. $icons[$i] = 0;
  799. }
  800. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  801. or die ("Cannot connect to database. " . mysql_error() .
  802. "\n<br>");
  803. mysql_select_db (DB_DATABASE);
  804. $get_used_icons = mysql_query("select icon_id, count(*) as countval from icon_usage " .
  805. //"group by icon_id order by icon_id asc, countval asc ");
  806. "group by icon_id order by countval asc ");
  807. $defaulticon = 0;
  808. if (mysql_num_rows($get_used_icons) == 0) {
  809. $icon = 1;
  810. } else {
  811. while ($row = mysql_fetch_array($get_used_icons)) {
  812. if (!$defaulticon) {
  813. $defaulticon = $row[0]; // default icon is least used one
  814. }
  815. $icons[$row[0]] = $row[1];
  816. }
  817. }
  818. mysql_free_result($get_used_icons);
  819. mysql_close($conn);
  820. $foundzero = 0;
  821. $iconstart = mt_rand(1, $number_icons);
  822. if ($iconstart < ($number_icons / 2)) {
  823. // If randomly chosen start position is closer to the
  824. // beginning of the icon list, go toward the end to
  825. // look for zeroes
  826. for ($i = $iconstart; $i <= $number_icons; $i++) {
  827. if ($icons[$i] == 0) {
  828. // Find first zero, and use that icon
  829. $icon = $i;
  830. $foundzero = 1;
  831. break;
  832. }
  833. }
  834. } else {
  835. // If randomly chosen start position is closer to the
  836. // end of the icon list, go toward the beginning to
  837. // look for zeroes
  838. for ($i = $iconstart; $i >= 1; $i--) {
  839. if ($icons[$i] == 0) {
  840. // Find first zero, and use that icon
  841. $icon = $i;
  842. $foundzero = 1;
  843. break;
  844. }
  845. }
  846. }
  847. if (!$foundzero) {
  848. $icon = $defaulticon; // If no zero-used icons found, pick least-used one
  849. }
  850. // Was a new client entered?
  851. if (($firstname) || ($lastname)) {
  852. $new_client_flag = 1;
  853. $dept_id = 0;
  854. $client = 0;
  855. // Check if a new client department was specified
  856. $departmenttext = trim($departmenttext);
  857. //printf("departmenttext = $departmenttext<br>\n");
  858. if ($departmenttext) {
  859. // Get list of departments
  860. $department_ids = array();
  861. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  862. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  863. mysql_select_db (DB_DATABASE);
  864. $get_depts = mysql_query("select department_id, name from departments order by name asc ");
  865. while ($row = mysql_fetch_array($get_depts, MYSQL_ASSOC)) {
  866. $department_ids[strtoupper($row['name'])] = $row['department_id'];
  867. }
  868. mysql_close($conn);
  869. // Is this department already in the database?
  870. if ($department_ids[strtoupper($departmenttext)]) {
  871. // Yes, it is
  872. $dept_id = $department_ids[strtoupper($departmenttext)];
  873. //printf("Known: dept_id = $dept_id<br>\n");
  874. } else {
  875. // No; add it
  876. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  877. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  878. mysql_select_db (DB_DATABASE);
  879. $get_depts = mysql_query("insert into departments (name) values (\"$departmenttext\" ) ");
  880. $dept_id = mysql_insert_id($conn);
  881. //printf("New: dept_id = $dept_id<br>\n");
  882. mysql_close($conn);
  883. }
  884. }
  885. // Add client to database
  886. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  887. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  888. mysql_select_db (DB_DATABASE);
  889. if ($dept_id) {
  890. $get_depts = mysql_query("insert into clients (first_name, last_name, email, department_id) values (\"$firstname\", \"$lastname\", \"$email\", \"$dept_id\") ");
  891. } else {
  892. $get_depts = mysql_query("insert into clients (first_name, last_name, email) values (\"$firstname\", \"$lastname\", \"$email\" ) ");
  893. }
  894. $client = mysql_insert_id($conn);
  895. }
  896. // Add new duty to database
  897. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  898. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  899. mysql_select_db (DB_DATABASE);
  900. $title = mysql_real_escape_string($title);
  901. $description = mysql_real_escape_string($description);
  902. $start_trans = mysql_query("start transaction ");
  903. $add_duty = mysql_query("insert into duties " .
  904. "(title, duty_type_id, description, staff_assigned, client_id, " .
  905. "contact, date_entered, status, icon_id) " .
  906. "values (\"$title\", \"$dtype\", \"$description\", \"$staff\", " .
  907. "\"$client\", \"$contact\", curdate(), \"$status\", \"$icon\") ");
  908. $duty = mysql_insert_id($conn);
  909. // If assistants were specified, add them to assistants table
  910. if (isset($assistants)) {
  911. foreach ($assistants as $s) {
  912. $add_assistant = mysql_query("insert into assistants " .
  913. "(project_id, duty_id, staff_id) values " .
  914. "(\"0\", \"$duty\", \"$s\") ");
  915. }
  916. }
  917. // Add current values to duty history
  918. $add_history = mysql_query("insert into duty_history " .
  919. "(duty_id, status, " .
  920. "modification_date, modification_time) " .
  921. "values (\"$duty\", \"$status\", " .
  922. "curdate(), now()) ");
  923. // Insert this duty in client history
  924. $add_client = mysql_query("insert into client_history " .
  925. "(staff_id, client_id, duty_id, client_entered_date, client_entered_time) " .
  926. "values (\"$staff\", \"$client\", \"$duty\", curdate(), now()) ");
  927. // Insert the selected icon into the icon usage table
  928. $add_icon = mysql_query("insert into icon_usage " .
  929. "(icon_id, duty_id) " .
  930. "values (\"$icon\", \"$duty\") ");
  931. // Commit transaction
  932. $stop_trans = mysql_query("commit ");
  933. if (!$stop_trans) {
  934. require("header.php");
  935. printf("<p>Error adding duty \"$title\": %s</p>\n", mysql_error());
  936. require("footer.php");
  937. mysql_close($conn);
  938. exit;
  939. }
  940. mysql_close($conn);
  941. // Send user to duty detail page
  942. header("Location: duties.php?action=view&duty=$duty");
  943. exit();
  944. }
  945. break;
  946. case "update":
  947. // Validate submitted data
  948. if ((!trim($title)) || (!trim($dtype)) || (!trim($description))) {
  949. // Missing fields; return to form
  950. $errormsg = "<p><font color='red'>* A title, type, and description are required for each duty.</font></p>\n";
  951. $activepage = "Duties";
  952. require("header.php");
  953. printf("<h2>Edit Duty</h2>\n");
  954. if (($_SESSION['SESSION_ADMIN'] == "Y") || ($_SESSION['SESSION_STAFF'] == "Y")) {
  955. $params['title'] = $title;
  956. $params['dtype'] = $dtype;
  957. $params['description'] = $description;
  958. $params['staff'] = $staff;
  959. $params['client'] = $client;
  960. $params['contact'] = $contact;
  961. $params['enterdate'] = $enterdate;
  962. $params['visibility'] = $visibility;
  963. $params['status'] = $status;
  964. $params['firstname'] = $firstname;
  965. $params['lastname'] = $lastname;
  966. $params['email'] = $email;
  967. $params['departmenttext'] = $departmenttext;
  968. $params['assistants'] = $assistants;
  969. display_duty_form("edit", $duty, "$errormsg", $params);
  970. } else {
  971. printf("<h3>Edit Duty -- Not Authorized</h3>");
  972. printf("<p>Only staff members and administrators can edit duties.</p>\n");
  973. printf("<p>Contact $admin_name (<a href='mailto:$admin_email'>" .
  974. "$admin_email)</a> to enable your user account to edit duties.</p>\n");
  975. require("footer.php");
  976. }
  977. exit;
  978. } else {
  979. // Data passes inspection; update duty in database
  980. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  981. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  982. mysql_select_db (DB_DATABASE);
  983. $title = mysql_real_escape_string($title);
  984. $description = mysql_real_escape_string($description);
  985. $start_trans = mysql_query("start transaction ");
  986. // Was a new client entered?
  987. if (($firstname) || ($lastname)) {
  988. $new_client_flag = 1;
  989. $dept_id = 0;
  990. $client = 0;
  991. // Check if a new client department was specified
  992. $departmenttext = trim($departmenttext);
  993. //printf("departmenttext = $departmenttext<br>\n");
  994. if ($departmenttext) {
  995. // Get list of departments
  996. $department_ids = array();
  997. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  998. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  999. mysql_select_db (DB_DATABASE);
  1000. $get_depts = mysql_query("select department_id, name from departments order by name asc ");
  1001. while ($row = mysql_fetch_array($get_depts, MYSQL_ASSOC)) {
  1002. $department_ids[strtoupper($row['name'])] = $row['department_id'];
  1003. }
  1004. mysql_close($conn);
  1005. // Is this department already in the database?
  1006. if ($department_ids[strtoupper($departmenttext)]) {
  1007. // Yes, it is
  1008. $dept_id = $department_ids[strtoupper($departmenttext)];
  1009. //printf("Known: dept_id = $dept_id<br>\n");
  1010. } else {
  1011. // No; add it
  1012. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  1013. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  1014. mysql_select_db (DB_DATABASE);
  1015. $get_depts = mysql_query("insert into departments (name) values (\"$departmenttext\" ) ");
  1016. $dept_id = mysql_insert_id($conn);
  1017. //printf("New: dept_id = $dept_id<br>\n");
  1018. mysql_close($conn);
  1019. }
  1020. }
  1021. // Add client to database
  1022. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  1023. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  1024. mysql_select_db (DB_DATABASE);
  1025. if ($dept_id) {
  1026. $get_depts = mysql_query("insert into clients (first_name, last_name, email, department_id) values (\"$firstname\", \"$lastname\", \"$email\", \"$dept_id\") ");
  1027. } else {
  1028. $get_depts = mysql_query("insert into clients (first_name, last_name, email) values (\"$firstname\", \"$lastname\", \"$email\" ) ");
  1029. }
  1030. $client = mysql_insert_id($conn);
  1031. }
  1032. // Convert date formats to MySQL
  1033. $enterdate = mysql_date($enterdate);
  1034. // Check what the existing duty status is
  1035. $check_status = mysql_query("select status from duties " .
  1036. "where duty_id = \"$duty\" ");
  1037. if ($row = mysql_fetch_array($check_status)) {
  1038. $starting_status = $row[0];
  1039. } else {
  1040. $starting_status = "";
  1041. }
  1042. mysql_free_result($check_status);
  1043. // Update duty fields
  1044. $edit_duty = mysql_query("update duties " .
  1045. "set title = \"$title\", duty_type_id = \"$dtype\", " .
  1046. "description = \"$description\", staff_assigned = \"$staff\", client_id = \"$client\", " .
  1047. "contact = \"$contact\", date_entered = \"$enterdate\", " .
  1048. "status = \"$status\", visibility = \"$visibility\" " .
  1049. "where duty_id = \"$duty\" ");
  1050. // If assistants were specified, add them to assistants table
  1051. if (isset($assistants)) {
  1052. // Delete previous assistants for this project to avoid duplication
  1053. $delete_assistant = mysql_query("delete from assistants " .
  1054. "where duty_id = \"$duty\" ");
  1055. // Add new assistants
  1056. foreach ($assistants as $s) {
  1057. $add_assistant = mysql_query("insert into assistants " .
  1058. "(project_id, duty_id, staff_id) values " .
  1059. "(\"0\", \"$duty\", \"$s\") ");
  1060. }
  1061. }
  1062. // Update duty history if status changed
  1063. if ($starting_status != $status) {
  1064. $edit_history = mysql_query("insert into duty_history " .
  1065. "(duty_id, status, modification_date, modification_time) " .
  1066. "values (\"$duty\", \"$status\", curdate(), now()) ");
  1067. }
  1068. // Commit transaction
  1069. $stop_trans = mysql_query("commit ");
  1070. if (!$stop_trans) {
  1071. require("header.php");
  1072. printf("<p>Error updating duty: %s</p>\n", mysql_error());
  1073. require("footer.php");
  1074. mysql_close($conn);
  1075. exit;
  1076. }
  1077. mysql_close($conn);
  1078. // Send user to duty detail page
  1079. header("Location: duties.php?action=view&duty=$duty");
  1080. exit();
  1081. }
  1082. break;
  1083. case "updatecommentlist":
  1084. // create TasksList object
  1085. //$myTasksList = new TasksList();
  1086. // read parameters
  1087. $action = $_GET['action'];
  1088. $content = $_GET['content'];
  1089. $project = $_GET['project'];
  1090. // clear the output
  1091. //if(ob_get_length()) ob_clean();
  1092. // headers are sent to prevent browsers from caching
  1093. //header('Expires: Fri, 25 Dec 1980 00:00:00 GMT'); // time in the past
  1094. //header('Last-Modified: ' . gmdate( 'D, d M Y H:i:s') . 'GMT');
  1095. //header('Cache-Control: no-cache, must-revalidate');
  1096. //header('Pragma: no-cache');
  1097. //header('Content-Type: text/html');
  1098. // execute the client request and return the updated tasks list
  1099. //echo $myTasksList->Process($content, $action, $project);
  1100. echo process_comment_changes($content, $action, $project);
  1101. break;
  1102. case "addcomment":
  1103. // Add comment to comments table
  1104. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  1105. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  1106. mysql_select_db (DB_DATABASE);
  1107. $comment = mysql_real_escape_string($comment);
  1108. $add_comment = mysql_query("insert into comments " .
  1109. "(duty_id, comment_text, submitter_id, submit_date, submit_time) " .
  1110. "values (\"$duty\", \"$comment\", \"$submitter\", curdate(), now()) ");
  1111. // Print error message if there's a problem
  1112. if (!$add_comment) {
  1113. $activepage = "Projects";
  1114. require("header.php");
  1115. printf("<p>Error adding comment: %s</p>\n", mysql_error());
  1116. require("footer.php");
  1117. mysql_close($conn);
  1118. exit;
  1119. }
  1120. mysql_close($conn);
  1121. // Return user to duty details page
  1122. header("Location: duties.php?action=view&duty=$duty");
  1123. break;
  1124. case "uploadfile":
  1125. if ($filename) {
  1126. $dirtree = "$upload_dir/D" . $duty;
  1127. if (!file_exists($dirtree)) {

Large files files are truncated, but you can click here to view the full file