PageRenderTime 50ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/equilibrium.php

https://github.com/obenauer/equilibrium
PHP | 1845 lines | 1626 code | 103 blank | 116 comment | 246 complexity | 51067564049f7c319f68ead5793eb38f MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0
  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. function build_todolist($staff, $status, $todostatus, $priority, $calmode,
  16. $project, $duty, $pageflag, $dragonly, $page, $maxresults) {
  17. global $displayed_user;
  18. //global $page;
  19. //global $maxresults;
  20. global $heading_color;
  21. global $background_color;
  22. // Only allow authorized people to sort or mark off to-do items
  23. if (($_SESSION['SESSION_ADMIN'] == "Y")
  24. || ($staff == $_SESSION['SESSION_USERID'])) {
  25. $edit_priv = "Y";
  26. } else {
  27. $edit_priv = "N";
  28. }
  29. if ($staff == 0) {
  30. $staffclause = "";
  31. } else {
  32. $staffclause = "and t.staff_assigned = \"$staff\" ";
  33. }
  34. if ($priority == "All") {
  35. $priorityclause = "";
  36. } else {
  37. $priorityclause = "and t.priority = \"$priority\" ";
  38. }
  39. if (($project == 0) && ($duty == 0)) {
  40. // Query conditions for To Do page
  41. if ($status == "All") {
  42. $statusclause = "";
  43. } else if ($status == "Open") {
  44. $statusclause = "and ((p.status in ('Pending', 'Active', 'Suspended') " .
  45. "or t.project_id = 0) " .
  46. "and (d.status = \"Active\" or t.duty_id = 0)) ";
  47. } else {
  48. $statusclause = "and ((p.status = \"$status\" " .
  49. "or t.project_id = 0) " .
  50. "and (d.status = \"Active\" or t.duty_id = 0)) ";
  51. }
  52. if ($todostatus == "Pending") {
  53. if ($calmode) {
  54. $orderclause = "order by u.last_name, u.first_name, " .
  55. "schedulenull asc, t.schedule_date, t.order_number asc ";
  56. } else {
  57. $orderclause = "order by u.last_name, u.first_name, " .
  58. "t.order_number asc ";
  59. }
  60. } else {
  61. $orderclause = "order by u.last_name, u.first_name, t.completed_date desc, " .
  62. "t.completed_time desc ";
  63. }
  64. } else if ($project == 0) {
  65. // Query conditions for Duties page
  66. $statusclause = "and t.duty_id = \"$duty\" ";
  67. $staffclause = "";
  68. if ($todostatus == "Pending") {
  69. $orderclause = "order by t.priority, t.duty_order asc ";
  70. } else {
  71. $orderclause = "order by t.completed_date desc, t.completed_time desc ";
  72. }
  73. } else {
  74. // Query conditions for Projects page
  75. $statusclause = "and t.project_id = \"$project\" ";
  76. $staffclause = "";
  77. if ($todostatus == "Pending") {
  78. $orderclause = "order by t.priority, t.project_order asc ";
  79. } else {
  80. $orderclause = "order by t.completed_date desc, t.completed_time desc ";
  81. }
  82. }
  83. if ($todostatus == "Completed") {
  84. $todoflag = "Y";
  85. $dateheading = "Completed";
  86. $checkimage = "checkmark.png";
  87. $checkother = "checkbox.png";
  88. $marktext = "Undo Completion";
  89. } else {
  90. $todoflag = "N";
  91. $dateheading = "Schedule";
  92. $checkimage = "checkbox.png";
  93. $checkother = "checkmark.png";
  94. $marktext = "Mark Completed";
  95. }
  96. // Get staff list for reassigning
  97. $conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
  98. $query = "select user_id, first_name, last_name " .
  99. "from users where staff_flag = \"Y\" " .
  100. "order by last_name asc, first_name asc ";
  101. $get_staff = $conn->query($query);
  102. $stafflist = array();
  103. $staffnames = array();
  104. $nstaff = 0;
  105. while ($row = $get_staff->fetch_array(MYSQLI_ASSOC)) {
  106. $stafflist[$nstaff] = $row['user_id'];
  107. $staffnames[$nstaff] = $row['first_name'] . " " . $row['last_name'];
  108. $nstaff++;
  109. }
  110. $get_staff->free_result();
  111. $conn->close();
  112. // Create JavaScript array of staff names
  113. printf("<script language='JavaScript'>\n");
  114. printf("var stafflist = new Array(%d);\n", $nstaff);
  115. printf("var staffnames = new Array(%d);\n", $nstaff);
  116. for ($i = 0; $i < $nstaff; $i++) {
  117. printf("stafflist[$i] = '$stafflist[$i]';\n");
  118. printf("staffnames[$i] = '$staffnames[$i]';\n");
  119. }
  120. printf("</script>\n");
  121. // Get open projects for this staff member
  122. $conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
  123. $query = "select t.project_id, t.title from projects as t " .
  124. "where t.status in ('Pending', 'Active', 'Suspended') " .
  125. $staffclause .
  126. "order by t.date_entered desc ";
  127. //printf("query = $query<br>\n");
  128. $get_projects = $conn->query($query);
  129. $project_ids = array();
  130. $projects = array();
  131. $nprojects = 0;
  132. while ($row = $get_projects->fetch_array(MYSQLI_ASSOC)) {
  133. if (strlen($row['title']) > 40) {
  134. $project_title = substr($row['title'], 0, 37) . "...";
  135. } else {
  136. $project_title = $row['title'];
  137. }
  138. $project_ids[$nprojects] = $row['project_id'];
  139. $projects[$nprojects] = $project_title;
  140. $nprojects++;
  141. }
  142. $get_projects->free_result();
  143. $conn->close();
  144. // Get active duties for this staff member
  145. $conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
  146. $query = "select t.duty_id, t.title from duties as t " .
  147. "where t.status = 'Active' " .
  148. $staffclause .
  149. "order by t.date_entered desc ";
  150. $get_duties = $conn->query($query);
  151. $duty_ids = array();
  152. $duties = array();
  153. $nduties = 0;
  154. while ($row = $get_duties->fetch_array(MYSQLI_ASSOC)) {
  155. if (strlen($row['title']) > 40) {
  156. $duty_title = substr($row['title'], 0, 37) . "...";
  157. } else {
  158. $duty_title = $row['title'];
  159. }
  160. $duty_ids[$nduties] = $row['duty_id'];
  161. $duties[$nduties] = $duty_title;
  162. $nduties++;
  163. }
  164. $get_duties->free_result();
  165. $conn->close();
  166. // Choose dates to display in schedule options
  167. $weekend = 0;
  168. $dates = array();
  169. if ($weekend) {
  170. // Show all dates for next two weeks
  171. for ($i = 0; $i <= 14; $i++) {
  172. $day = mktime(0, 0, 0, date("m"), date("d") + $i, date("Y"));
  173. $dates[$i] = date("Y", $day) . "-" . date("m", $day) . "-" .
  174. date("d", $day);
  175. }
  176. } else {
  177. // Show only weekdays for next two weeks
  178. $count = 0;
  179. for ($i = 0; $i <= 14; $i++) {
  180. $day = mktime(0, 0, 0, date("m"), date("d") + $i, date("Y"));
  181. $dayofweek = date('l', $day);
  182. if (($dayofweek != "Saturday") && ($dayofweek != "Sunday")) {
  183. $dates[$count] = date("Y", $day) . "-" . date("m", $day) . "-" .
  184. date("d", $day);
  185. $count++;
  186. }
  187. }
  188. }
  189. // Put relevant to-do's in order
  190. $conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
  191. //$query = "select t.todo_id, t.schedule_date is null as schedulenull " .
  192. // "from todos as t left join users as u on t.staff_assigned = u.user_id " .
  193. // "left join projects as p on t.project_id = p.project_id " .
  194. // "left join duties as d on t.duty_id = d.duty_id " .
  195. // "where t.completed = \"$todoflag\" " .
  196. // $staffclause .
  197. // $statusclause .
  198. // $priorityclause .
  199. // $orderclause;
  200. //$todo_order = $conn->query($query);
  201. //$count = 1;
  202. //if ($project) {
  203. // $order_var = "project_order";
  204. //} else if ($duty) {
  205. // $order_var = "duty_order";
  206. //} else {
  207. // $order_var = "order_number";
  208. //}
  209. //while ($row = $todo_order->fetch_array(MYSQLI_ASSOC)) {
  210. // $set_order = $conn->query("update todos set $order_var = \"$count\" " .
  211. // "where todo_id = \"" . $row['todo_id'] . "\" ");
  212. // $count++;
  213. //}
  214. //$todo_order->free_result();
  215. // Define visibility clause
  216. if ($_SESSION['SESSION_USERID'] != $staff) {
  217. $visclause = "and t.visibility = 'Public' ";
  218. } else {
  219. $visclause = "";
  220. }
  221. // Get to-do items and display them
  222. $query = "select t.todo_id, t.completed, t.schedule_date, t.completed_date, " .
  223. "t.priority, t.visibility, u.first_name, u.last_name, u.user_id, " .
  224. "u2.user_id as project_owner, u3.user_id as duty_owner, " .
  225. "p.project_id, p.icon_id as project_icon, p.title as project_title, " .
  226. "d.duty_id, d.icon_id as duty_icon, d.title as duty_title, t.description, " .
  227. "(t.schedule_date is null or t.schedule_date = '0000-00-00') as schedulenull " .
  228. "from todos as t left join users as u on t.staff_assigned = u.user_id " .
  229. "left join projects as p on t.project_id = p.project_id " .
  230. "left join users as u2 on p.staff_assigned = u2.user_id " .
  231. "left join duties as d on t.duty_id = d.duty_id " .
  232. "left join users as u3 on d.staff_assigned = u3.user_id " .
  233. "where t.completed = \"$todoflag\" " .
  234. $staffclause .
  235. $statusclause .
  236. $visclause .
  237. $priorityclause .
  238. $orderclause;
  239. //printf("query = $query limit " . (($page - 1) * $maxresults) . ", $maxresults <br>\n");
  240. $list_full = $conn->query($query);
  241. if ($pageflag) {
  242. $list_page = $conn->query($query . "limit " . (($page - 1) * $maxresults) .
  243. ", $maxresults ");
  244. } else {
  245. $list_page = $list_full;
  246. }
  247. $list = "<div id='$todostatus" . "_todoblock'>\n";
  248. //printf("query = $query limit %d, %d<br>\n", (($page - 1) * $maxresults), $maxresults);
  249. //$list .= "query = $query<br>\n";
  250. //$list .= "projectclause = $projectclause<br>\n";
  251. if ($list_full->num_rows) {
  252. // Show "Pending" or "Completed" label for individual projects and duties
  253. if (($project) || ($duty)) {
  254. $list .= "<b>$todostatus</b><br>\n";
  255. }
  256. // Show page numbers for results
  257. if ($pageflag) {
  258. $page_url = "todolist.php?staff=$staff&status=$status&todostatus=$todostatus" .
  259. "&priority=$priority&calmode=$calmode";
  260. $list .= page_results($list_full->num_rows, $page, $maxresults, $page_url);
  261. //$list .= "BUILD_TODOLIST PAGEFLAG=$pageflag<BR>\n";
  262. }
  263. // Start div for to do list
  264. $list .= "<div id='$todostatus" . "_todolist' class='sortable_list'>\n";
  265. //$list .= "<div id='todolist' onmouseup='update_list(\"todolist\", " .
  266. // "\"common.php?cmd=updatelist&staff=$staff&status=$status" .
  267. // "&todostatus=$todostatus&edit_priv=$edit_priv&project=$project&duty=$duty&pageflag=$pageflag\");'>\n";
  268. $lastscheduledate = "";
  269. while ($row = $list_page->fetch_array(MYSQLI_ASSOC)) {
  270. // If schedule date is present, convert it to Unix time
  271. $pastscheduledate = 0;
  272. if (($row['schedule_date'] == "0000-00-00") ||
  273. ($row['schedule_date'] == "NULL") ||
  274. ($row['schedule_date'] == NULL)) {
  275. $row['schedule_date'] = "";
  276. }
  277. if ($row['schedule_date']) {
  278. $parts = explode("-", $row['schedule_date']);
  279. $calday = mktime(0, 0, 0, $parts[1], $parts[2], $parts[0]);
  280. $schedule_column = $row['schedule_date'];
  281. // Check if scheduled date is before current day
  282. $today = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
  283. if ($calday < $today) {
  284. $pastscheduledate = 1;
  285. }
  286. } else {
  287. $schedule_column = "";
  288. }
  289. // If all staff members selected, show their initials
  290. if ($staff == 0) {
  291. $initials = substr($row['first_name'], 0, 1) .
  292. substr($row['last_name'], 0, 1) . " ";
  293. } else {
  294. $initials = "";
  295. }
  296. // Identify to-do owner
  297. if ($row['user_id']) {
  298. $todo_owner = $row['user_id'];
  299. } else {
  300. $todo_owner = 0;
  301. }
  302. // Identify project owner
  303. if ($row['project_owner']) {
  304. $project_owner = $row['project_owner'];
  305. } else {
  306. $project_owner = 0;
  307. }
  308. // Identify duty owner
  309. if ($row['duty_owner']) {
  310. $duty_owner = $row['duty_owner'];
  311. } else {
  312. $duty_owner = 0;
  313. }
  314. // Check whether this is a private or public to-do item
  315. if ($row['visibility'] == 'Private') {
  316. $bgcolor = "style='background-color: $heading_color'";
  317. } else {
  318. $bgcolor = "";
  319. }
  320. // Draw lines between to-do's with different schedule dates
  321. // (in Calendar Mode)
  322. if ($calmode) {
  323. if (($lastscheduledate == "") && ($pastscheduledate)) {
  324. $list .= "<div id='A" . $row['todo_id'] . "'>";
  325. $list .= "<font color='blue' size='-1'><b>" .
  326. "Overdue</b></font><br clear=left></div>\n";
  327. } else if (($row['schedule_date'] != $lastscheduledate)
  328. && (!$pastscheduledate)) {
  329. $list .= "<div id='A" . $row['todo_id'] . "'>";
  330. if ($row['schedule_date']) {
  331. $list .= "<font color='blue' size='-1'><b>" .
  332. short_date($row['schedule_date']) .
  333. "</b></font><br clear=left></div>\n";
  334. } else {
  335. $list .= "<font color='blue' size='-1'><b>" .
  336. "Unscheduled</b></font><br clear=left></div>\n";
  337. }
  338. }
  339. $lastscheduledate = $row['schedule_date'];
  340. }
  341. $list .= "<div class='todo_item' id='" . $row['todo_id']. "' style='background-color: " . $background_color . "'>\n";
  342. $list .= "<table style='font-size: 14px'><tr valign='top'>\n";
  343. // Mark to-do completed, or undo it
  344. if ($dragonly == 0) {
  345. if ($edit_priv == "Y") {
  346. //$list .= "<td style=\"width:30px\">\n";
  347. $list .= "<td>\n";
  348. $list .= "<img id='check_image_" . $row['todo_id'] .
  349. "' src=\"images/$checkimage\" title='$marktext' ";
  350. if (($project) || ($duty)) {
  351. $list .= "onclick='{ $(\"check_image_" . $row['todo_id'] .
  352. "\").src=\"images/$checkother\"; modify_two_lists(\"" .
  353. $row['todo_id'] . "\", \"togglecomplete\", \"$staff\", " .
  354. "\"$status\", \"$priority\", \"$calmode\", " .
  355. "\"$project\", \"$duty\", \"$pageflag\", " .
  356. "\"$dragonly\", \"$page\", \"$maxresults\");}'>\n";
  357. } else {
  358. $list .= "onclick='{ $(\"check_image_" . $row['todo_id'] .
  359. "\").src=\"images/$checkother\"; modify_todo(\"" .
  360. $row['todo_id'] . "\", \"togglecomplete\", \"$staff\", " .
  361. "\"$status\", \"$todostatus\", \"$priority\", \"$calmode\", " .
  362. "\"$project\", \"$duty\", " .
  363. "\"$pageflag\", \"$dragonly\", \"$page\", \"$maxresults\"" .
  364. ");}'>\n";
  365. }
  366. $list .= "</td>\n";
  367. } else {
  368. //$list .= "<td style=\"width:30px\">\n";
  369. $list .= "<td>\n";
  370. $list .= "<img id='check_image_" . $row['todo_id'] .
  371. "' src=\"images/$checkimage\" ";
  372. $list .= "title='$marktext'>\n";
  373. $list .= "</td>\n";
  374. }
  375. }
  376. // Show staff initials if "All" staff is selected
  377. $list .= "<td><font color='blue'>$initials</font>\n";
  378. // Show project icon (if any), unless only one project is being viewed
  379. if (!$project) {
  380. if (($row['project_id']) && ($row['project_id'] != "NULL")) {
  381. $list .= "<a href='projects.php?action=view&project=" .
  382. $row['project_id'] . "'><img src=\"icons18/icon_" .
  383. $row['project_icon'] . ".png\" title='" .
  384. $row['project_title'] . "' border='0'></a>\n";
  385. }
  386. }
  387. // Show duty icon (if any), unless only one duty is being viewed
  388. if (!$duty) {
  389. if (($row['duty_id']) && ($row['duty_id'] != "NULL")) {
  390. $list .= "<a href='duties.php?action=view&duty=" .
  391. $row['duty_id'] . "'><img src=\"icons18/icon_" .
  392. $row['duty_icon'] . ".png\" title='" .
  393. $row['duty_title'] . "' border='0'></a>\n";
  394. }
  395. }
  396. // Show to-do item description
  397. $list .= "<span class='draghandle' onclick='modify_todo(\"$todostatus" .
  398. "_todolist\", \"updatelist\", \"$staff\", \"$status\", \"$todostatus\", " .
  399. "\"$priority\", \"$calmode\", \"$project\", \"$duty\", \"$pageflag\", " .
  400. "\"$dragonly\", \"$page\", " .
  401. "\"$maxresults\");' $bgcolor>" . $row['description'] . "</span>\n";
  402. // Show to-do owner if different from project owner
  403. if ($project && $project_owner && $todo_owner) {
  404. if ($project_owner != $todo_owner) {
  405. $todoname = $staffnames[array_search($todo_owner, $stafflist, true)];
  406. } else {
  407. $todoname = "";
  408. }
  409. }
  410. if ($duty) {
  411. if ($duty_owner != $todo_owner) {
  412. $todoname = $staffnames[array_search($todo_owner, $stafflist, true)];
  413. } else {
  414. $todoname = "";
  415. }
  416. }
  417. if ($dragonly) {
  418. //$list .= "</td></tr></table></div>\n";
  419. $list .= "</td></tr></table>\n";
  420. } else if ($todostatus == "Completed") {
  421. if ($todoname) {
  422. $list .= " (<b>$todoname</b>, " . short_date($row['completed_date']) . ")\n";
  423. } else {
  424. $list .= " (" . short_date($row['completed_date']) . ")\n";
  425. }
  426. $list .= "</tr></table>\n";
  427. } else {
  428. if ($calmode) {
  429. if ($pastscheduledate) {
  430. if ($todoname && $schedule_column) {
  431. $list .= " (<b>$todoname</b>, " . short_date($schedule_column) . ")\n";
  432. } else if ($schedule_column) {
  433. $list .= " (" . short_date($schedule_column) . ")\n";
  434. } else if ($todoname) {
  435. $list .= " (<b>$todoname</b>)\n";
  436. }
  437. } else {
  438. if ($todoname) {
  439. $list .= " (<b>$todoname</b>)\n";
  440. }
  441. }
  442. } else {
  443. if ($todoname && $schedule_column) {
  444. $list .= " (<b>$todoname</b>, " . short_date($schedule_column) . ")\n";
  445. } else if ($schedule_column) {
  446. $list .= " (" . short_date($schedule_column) . ")\n";
  447. } else if ($todoname) {
  448. $list .= " (<b>$todoname</b>)\n";
  449. }
  450. }
  451. // Priority icon
  452. if ($row['priority'] == 'High') {
  453. $list .= "&nbsp; &nbsp; <img src='images/plus.png' height='16' " .
  454. "title='Priority' onclick='modify_todo(\"" . $row['todo_id'] .
  455. "\", \"togglepriority\", \"$staff\", \"$status\", " .
  456. "\"$todostatus\", \"$priority\", \"$calmode\", " .
  457. "\"$project\", \"$duty\", " .
  458. "\"$pageflag\", \"$dragonly\", \"$page\", " .
  459. "\"$maxresults\");'>";
  460. } else {
  461. $list .= "&nbsp; <img src='images/minus.png' height='16' " .
  462. "title='Priority' onclick='modify_todo(\"" . $row['todo_id'] .
  463. "\", \"togglepriority\", \"$staff\", \"$status\", " .
  464. "\"$todostatus\", \"$priority\", \"$calmode\", " .
  465. "\"$project\", \"$duty\", " .
  466. "\"$pageflag\", \"$dragonly\", \"$page\", " .
  467. "\"$maxresults\");'>";
  468. }
  469. // Edit icon
  470. $list .= "&nbsp; <img src='images/edit.png' height='16' " .
  471. "title='Edit' " .
  472. "onclick='show_item(\"edit_" . $row['todo_id'] . "\");'>";
  473. // Delete icon
  474. $list .= "&nbsp; <img src='images/delete.png' height='16' " .
  475. "title='Delete' " .
  476. "onclick='show_item(\"confirm_" . $row['todo_id'] . "\");'>";
  477. $list .= "</td>";
  478. $list .= "</tr></table>\n";
  479. //$list .= "</div>\n";
  480. // Div for edit box
  481. $list .= "<div style='display: none' id='edit_" . $row['todo_id'] . "' >" .
  482. "<center>Edit: <input type='text' " .
  483. " id='txtEditItem_" .
  484. $row['todo_id'] .
  485. "' size='100' maxlength='255' value=\"" . $row['description'] ."\" " .
  486. ">\n<br>";
  487. // Project/duty selection
  488. if ($row['project_id']) {
  489. $pstyle = "style='font-weight: bold' ";
  490. $dstyle = "style='font-weight: normal' ";
  491. $selectname = "name = 'projectchange_" . $row['todo_id'] .
  492. "' ";
  493. } else if ($row['duty_id']) {
  494. $pstyle = "style='font-weight: normal' ";
  495. $dstyle = "style='font-weight: bold' ";
  496. $selectname = "name = 'dutychange_" . $row['todo_id'] .
  497. "' ";
  498. } else {
  499. $pstyle = "style='font-weight: bold' ";
  500. $dstyle = "style='font-weight: normal' ";
  501. $selectname = "name = 'projectchange_" . $row['todo_id'] .
  502. "' ";
  503. }
  504. $list .= "<font id='projectlabel_" . $row['todo_id'] . "' onclick='pdflag_" . $row['todo_id'] . " = \"Project\"; populate_projects( $(\"pdlist_" . $row['todo_id'] . "\"), $(\"projectlabel_" . $row['todo_id'] . "\"), $(\"dutylabel_" . $row['todo_id'] . "\"), project_ids, projects, \"" .
  505. $row['project_id'] . "\");' $pstyle>";
  506. $list .= "Project</font> / ";
  507. $list .= "<font id='dutylabel_" . $row['todo_id'] . "' onclick='pdflag_" . $row['todo_id'] . " = \"Duty\"; populate_duties( $(\"pdlist_" . $row['todo_id'] . "\"), $(\"projectlabel_" . $row['todo_id'] . "\"), $(\"dutylabel_" . $row['todo_id'] . "\"), duty_ids, duties, \"" .
  508. $row['duty_id'] . "\");' $dstyle>Duty</font>: \n";
  509. $list .= "<select id='pdlist_" . $row['todo_id'] . "' size='1' onChange=\"if (pdflag_" . $row['todo_id'] . " == 'Project') {duty = 0; project = project_ids[$('pdlist_" . $row['todo_id'] . "').selectedIndex - 1];} else {project = 0; duty = duty_ids[$('pdlist_" . $row['todo_id'] . "').selectedIndex - 1];}\" $selectname>\n";
  510. if ($row['project_id']) {
  511. $list .= "<option value='P0'></option>\n";
  512. for ($i = 0; $i < $nprojects; $i++) {
  513. if ($row['project_id'] == $project_ids[$i]) {
  514. $list .= "<option value='P" . $project_ids[$i] .
  515. "' selected>" . $projects[$i] . "</option>\n";
  516. } else {
  517. $list .= "<option value='P" . $project_ids[$i] .
  518. "'>" . $projects[$i] . "</option>\n";
  519. }
  520. }
  521. } else if ($row['duty_id']) {
  522. $list .= "<option value='D0'></option>\n";
  523. for ($i = 0; $i < $nduties; $i++) {
  524. if ($row['duty_id'] == $duty_ids[$i]) {
  525. $list .= "<option value='D" . $duty_ids[$i] .
  526. "' selected>" . $duties[$i] . "</option>\n";
  527. } else {
  528. $list .= "<option value='D" . $duty_ids[$i] .
  529. "'>" . $duties[$i] . "</option>\n";
  530. }
  531. }
  532. } else {
  533. $list .= "<option value='P0'></option>\n";
  534. for ($i = 0; $i < $nprojects; $i++) {
  535. if ($row['project_id'] == $project_ids[$i]) {
  536. $list .= "<option value='P" . $project_ids[$i] .
  537. "' selected>" . $projects[$i] . "</option>\n";
  538. } else {
  539. $list .= "<option value='P" . $project_ids[$i] .
  540. "'>" . $projects[$i] . "</option>\n";
  541. }
  542. }
  543. }
  544. $list .= "</select> &nbsp; \n";
  545. // Staff assigned selection
  546. $list .= "Staff assigned: ";
  547. $list .= "<select id='staff_assigned_" . $row['todo_id'] .
  548. "' name='staff_assigned_" . $row['todo_id'] .
  549. "'>\n";
  550. for ($i = 0; $i < $nstaff; $i++) {
  551. if ($stafflist[$i] == $todo_owner) {
  552. $list .= "<option value='" . $stafflist[$i].
  553. "' selected>" . $staffnames[$i] . "</option>\n";
  554. } else {
  555. $list .= "<option value='" . $stafflist[$i].
  556. "'>" . $staffnames[$i] . "</option>\n";
  557. }
  558. }
  559. $list .= "</select><br>\n";
  560. // Visibility selection
  561. $list .= "Visibility: ";
  562. $list .= "<select id='visibility_" . $row['todo_id'] .
  563. "' name='visibility_" . $row['todo_id'] .
  564. "'>\n";
  565. if ($row['visibility'] == 'Public') {
  566. $list .= "<option value='Public' selected>Public</option>\n";
  567. } else {
  568. $list .= "<option value='Public'>Public</option>\n";
  569. }
  570. if ($row['visibility'] == 'Private') {
  571. $list .= "<option value='Private' selected>Private</option>\n";
  572. } else {
  573. $list .= "<option value='Private'>Private</option>\n";
  574. }
  575. $list .= "</select>\n";
  576. // Schedule date selection
  577. $list .= "Schedule: ";
  578. $list .= "<select id='schedule_" . $row['todo_id'] .
  579. "' name='schedule_" . $row['todo_id'] .
  580. "'>\n";
  581. if ($pastscheduledate) {
  582. $list .= "<option value='$schedule_column' selected " .
  583. "style='background-color: $heading_color'>" .
  584. short_date($schedule_column) . "</option>\n";
  585. }
  586. if ($schedule_column == "") {
  587. $list .= "<option value='NULL' selected></option>\n";
  588. } else {
  589. $list .= "<option value='NULL'></option>\n";
  590. }
  591. for ($i = 0; $i < count($dates); $i++) {
  592. if ($schedule_column == $dates[$i]) {
  593. $list .= "<option value='$dates[$i]' selected>" .
  594. short_date($dates[$i]) . "</option>\n";
  595. } else {
  596. $list .= "<option value='$dates[$i]'>" .
  597. short_date($dates[$i]) . "</option>\n";
  598. }
  599. }
  600. $list .= "</select><br>\n";
  601. // Update and cancel icons
  602. $list .= "<input type='button' value='Update' " .
  603. "onclick='{modify_todo(\"" . $row['todo_id'] .
  604. "\", \"edititem\", \"$staff\", \"$status\", \"$todostatus\", " .
  605. "\"$priority\", \"$calmode\", \"$project\", \"$duty\", \"$pageflag\", " .
  606. "\"$dragonly\", \"$page\", \"$maxresults\");}'> &nbsp; &nbsp; " .
  607. "<input type='button' value='Cancel' onclick='hide_item(\"edit_" .
  608. $row['todo_id'] . "\");'></center></div>\n";
  609. // Set variable for project/duty flag
  610. printf("<script type='text/javascript'>\n");
  611. if ($row['project_id']) {
  612. printf("var pdflag_" . $row['todo_id'] . " = \"Project\";\n");
  613. } else if ($row['duty_id']) {
  614. printf("var pdflag_" . $row['todo_id'] . " = \"Duty\";\n");
  615. } else {
  616. printf("var pdflag_" . $row['todo_id'] . " = \"Project\";\n");
  617. }
  618. printf("</script>\n");
  619. // Div to confirm deletion
  620. $list .= "<div class='confirm' id='confirm_" . $row['todo_id'] .
  621. "' ><font color='red'>" .
  622. "<center>Are you sure you want to delete this item?</font><br>" .
  623. "<input type='button' value='Confirm Deletion' " .
  624. "onclick='{Element.hide(\$(\"confirm_" . $row['todo_id'] .
  625. "\").id); modify_todo(\"" . $row['todo_id'] .
  626. "\", \"deleteitem\", \"$staff\", \"$status\", \"$todostatus\", " .
  627. "\"$priority\", \"$calmode\", \"$project\", \"$duty\", \"$pageflag\", " .
  628. "\"$dragonly\", \"$page\", \"$maxresults\");" .
  629. "}'> &nbsp; &nbsp; " .
  630. "<input type='button' value='Cancel' onclick='hide_item(\"confirm_" .
  631. $row['todo_id'] . "\");'></center></div>\n";
  632. // End the div for this to-do item (containing edit and delete divs)
  633. $list .= "</div>\n";
  634. }
  635. }
  636. // End the div for all to-do items
  637. $list .= "</div>\n";
  638. } else {
  639. if ($project) {
  640. $list .= "<b>No " . strtolower($todostatus) . " to-do items found " .
  641. "for this project.</b><br>\n";
  642. } else if ($duty) {
  643. $list .= "<b>No " . strtolower($todostatus) . " to-do items found " .
  644. "for this duty.</b><br>\n";
  645. } else {
  646. if ($displayed_user == "All") {
  647. if ($status == "All") {
  648. $list .= "<b>No " . strtolower($todostatus) . " to-do items found " .
  649. "in database.</b><br>\n";
  650. } else {
  651. $list .= "<b>No " . strtolower($todostatus) . " to-do items for " .
  652. strtolower($status) . " projects found in database.</b><br>\n";
  653. }
  654. } else {
  655. if ($status == "All") {
  656. $list .= "<b>No " . strtolower($todostatus) . " to-do items found " .
  657. "for $displayed_user.</b><br>\n";
  658. } else {
  659. $list .= "<b>No " . strtolower($todostatus) . " to-do items for " .
  660. strtolower($status) . " projects found for " .
  661. "$displayed_user.</b><br>\n";
  662. }
  663. }
  664. }
  665. }
  666. // End the "to do block" div
  667. $list .= "</div>\n";
  668. // Close the database connection
  669. $list_full->free_result();
  670. if ($pageflag) {
  671. $list_page->free_result();
  672. }
  673. $conn->close();
  674. // Make list sortable
  675. if (($todostatus == "Pending") && ($_SESSION['SESSION_USERID'] == $staff)) {
  676. $list .= "<script type='text/javascript'>\n";
  677. $list .= "Sortable.create('$todostatus" . "_todolist', {tag:'div', handle:'draghandle'});\n";
  678. $list .= "</script>\n";
  679. }
  680. return $list;
  681. }
  682. function build_two_lists($staff, $status, $priority, $calmode, $project, $duty,
  683. $pageflag, $dragonly, $page, $maxresults) {
  684. $two_lists = build_todolist($staff, $status, "Pending", $priority, $calmode,
  685. $project, $duty, '0', '0', $page, $maxresults);
  686. $two_lists .= "<br>\n";
  687. $two_lists .= build_todolist($staff, $status, "Completed", $priority, $calmode,
  688. $project, $duty, '0', '0', $page, $maxresults);
  689. return $two_lists;
  690. }
  691. function build_commentlist($staff, $project, $duty, $fromdate, $todate,
  692. $pageflag, $page, $maxresults) {
  693. global $displayed_user;
  694. //global $page;
  695. //global $maxresults;
  696. global $heading_color;
  697. global $background_color;
  698. // Only the assigned staff or administrators can edit this project, unless it's not assigned
  699. if (($_SESSION['SESSION_ADMIN'] == "Y") || ($staff == $_SESSION['SESSION_USERID'])) {
  700. $edit_priv = "Y";
  701. } else {
  702. $edit_priv = "N";
  703. }
  704. if ($staff == 0) {
  705. $staffclause = "";
  706. } else {
  707. $staffclause = "where c.submitter_id = \"$staff\" ";
  708. }
  709. // Define visibility clause
  710. if ($_SESSION['SESSION_USERID'] != $staff) {
  711. $visclause = "and c.visibility = 'Public' ";
  712. } else {
  713. $visclause = "";
  714. }
  715. // Define date clause
  716. if ($project) {
  717. $dateclause = "";
  718. $pdclause = "and c.project_id = \"$project\" ";
  719. } else if ($duty) {
  720. $dateclause = "";
  721. $pdclause = "and c.duty_id = \"$duty\" ";
  722. } else {
  723. $dateclause = "and c.submit_date >= \"$fromdate\" " .
  724. "and c.submit_date <= \"$todate\" ";
  725. $pdclause = "";
  726. }
  727. // Fill Javascript arrays with open projects and active duties
  728. fill_pdlist_arrays($staff, $projects, $project_ids, $duties, $duty_ids);
  729. // Get to-do items for active projects and display them
  730. $conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
  731. $query = "select c.comment_id, c.comment_text, c.submit_date, " .
  732. "u.user_id, u.first_name, u.last_name, c.visibility, " .
  733. "p.project_id, p.icon_id as project_icon, p.title as project_title, " .
  734. "d.duty_id, d.icon_id as duty_icon, d.title as duty_title " .
  735. "from comments as c left join users as u on c.submitter_id = u.user_id " .
  736. "left join projects as p on c.project_id = p.project_id " .
  737. "left join duties as d on c.duty_id = d.duty_id " .
  738. $staffclause . $visclause . $dateclause . $pdclause .
  739. "order by c.submit_time desc ";
  740. //printf("query = $query<br>\n");
  741. $list_full = $conn->query($query);
  742. if ($pageflag) {
  743. $list_page = $conn->query($query . "limit " . (($page - 1) * $maxresults) .
  744. ", $maxresults ");
  745. } else {
  746. $list_page = $list_full;
  747. }
  748. $list = "<div id='commentblock'>\n";
  749. //$list .= "fromdate = $fromdate, todate = $todate<br>\n";
  750. if ($list_page->num_rows) {
  751. // Show page numbers for results
  752. if ($pageflag) {
  753. $page_url = "logbook.php?staff=$staff&fromdate=$fromdate&todate=$todate";
  754. $list .= page_results($list_full->num_rows, $page, $maxresults, $page_url);
  755. }
  756. while ($row = $list_page->fetch_array(MYSQLI_ASSOC)) {
  757. // If all staff members selected, show their initials
  758. if ($staff == 0) {
  759. $initials = substr($row['first_name'], 0, 1) .
  760. substr($row['last_name'], 0, 1) . " ";
  761. } else {
  762. $initials = "";
  763. }
  764. $list .= "<div id='comment_" . $row['comment_id'] . "'>";
  765. // Check whether this is a private or public to-do item
  766. if ($row['visibility'] == 'Private') {
  767. $bgcolor = "$heading_color";
  768. } else {
  769. $bgcolor = "white";
  770. }
  771. // Date submitted
  772. $list .= "<table><tr valign='top'><td>" . short_date($row['submit_date']) . "</td>\n";
  773. $list .= "<td bgcolor='$bgcolor' style='{border: 1px solid $heading_color; padding-left: 5px; padding-right: 5px;}'><font color='blue'>$initials</font>";
  774. // Show project icon (if any), unless only one project is being viewed
  775. if (!$project) {
  776. if (($row['project_id']) && ($row['project_id'] != "NULL")) {
  777. $list .= "<a href='projects.php?action=view&project=" .
  778. $row['project_id'] . "'><img src=\"icons18/icon_" .
  779. $row['project_icon'] . ".png\" title='" .
  780. $row['project_title'] . "' border='0'></a>\n";
  781. }
  782. }
  783. // Show duty icon (if any), unless only one duty is being viewed
  784. if (!$duty) {
  785. if (($row['duty_id']) && ($row['duty_id'] != "NULL")) {
  786. $list .= "<a href='duties.php?action=view&duty=" .
  787. $row['duty_id'] . "'><img src=\"icons18/icon_" .
  788. $row['duty_icon'] . ".png\" title='" .
  789. $row['duty_title'] . "' border='0'></a>\n";
  790. }
  791. }
  792. // Comment text
  793. $comment_text = str_replace("\'", "'", $row['comment_text']);
  794. $comment_text = str_replace('\"', '"', $comment_text);
  795. $comment_text = str_replace("%", "%%", $comment_text);
  796. $list .= $comment_text . "</td>\n";
  797. // Don't show edit or delete icons if user does not have edit_priv
  798. if ($edit_priv == "Y") {
  799. // "Edit" icon
  800. $list .= "<td><img src='images/edit.png' height='16' style='{position:relative; padding-left:20px;}' " .
  801. "onclick='show_item(\"editcomment_" . $row['comment_id'] . "\");'></td>";
  802. // "Delete" icon
  803. $list .= "<td style='background-color:" . $background_color . "'><img src='images/delete.png' height='16' onclick='show_item(\"confirmcomment_" . $row['comment_id'] . "\");'>" .
  804. "</td></tr></table>\n";
  805. // Div for edit box
  806. $list .= "<div style='display: none' id='editcomment_" .
  807. $row['comment_id'] . "'><center>Edit: <textarea id='txtEditEntry_" .
  808. $row['comment_id'] .
  809. "' rows='4' cols='120' class='description'>" .$comment_text .
  810. "</textarea>\n<br>";
  811. // Project/duty selection
  812. $list .= make_pdlist($staff, $row['comment_id'], $row['project_id'],
  813. $projects, $project_ids, $row['duty_id'], $duties, $duty_ids, 0);
  814. // Visibility selection
  815. $list .= "Visibility: ";
  816. $list .= "<select id='viscomment_" . $row['comment_id'] .
  817. "' name='viscomment_" . $row['comment_id'] .
  818. "'>\n";
  819. if ($row['visibility'] == 'Public') {
  820. $list .= "<option value='Public' selected>Public</option>\n";
  821. } else {
  822. $list .= "<option value='Public'>Public</option>\n";
  823. }
  824. if ($row['visibility'] == 'Private') {
  825. $list .= "<option value='Private' selected>Private</option>\n";
  826. } else {
  827. $list .= "<option value='Private'>Private</option>\n";
  828. }
  829. $list .= "</select><br>\n";
  830. // Update and cancel icons
  831. $list .= "<input type='button' value='Update' " .
  832. "onclick='{modify_comment(\"" . $row['comment_id'] .
  833. "\", \"editcomment\", \"$staff\", \"$project\", \"$duty\", " .
  834. "\"$fromdate\", \"$todate\", \"$pageflag\", \"$page\", \"$maxresults\");}'> &nbsp; &nbsp; " .
  835. "<input type='button' value='Cancel' onclick='hide_item(\"editcomment_" .
  836. $row['comment_id'] . "\");'></center><br></div>\n";
  837. // Set variable for project/duty flag
  838. printf("<script type='text/javascript'>\n");
  839. if ($row['project_id']) {
  840. printf("var pdflag_" . $row['comment_id'] . " = \"Project\";\n");
  841. } else if ($row['duty_id']) {
  842. printf("var pdflag_" . $row['comment_id'] . " = \"Duty\";\n");
  843. } else {
  844. printf("var pdflag_" . $row['comment_id'] . " = \"Project\";\n");
  845. }
  846. printf("</script>\n");
  847. // Div to confirm deletion
  848. $list .= "<div class='confirm' id='confirmcomment_" . $row['comment_id'] .
  849. "' ><font color='red'>" .
  850. "<center>Are you sure you want to delete this comment?</font><br>" .
  851. "<input type='button' value='Confirm Deletion' " .
  852. "onclick='{modify_comment(\"" . $row['comment_id'] .
  853. "\", \"deletecomment\", \"$staff\", \"$project\", \"$duty\", " .
  854. "\"$fromdate\", \"$todate\", \"$pageflag\", \"$page\", \"$maxresults\");" .
  855. "}'> &nbsp; &nbsp; " .
  856. "<input type='button' value='Cancel' onclick='hide_item(\"confirmcomment_" .
  857. $row['comment_id'] . "\");'></center><br></div>\n";
  858. $list .= "</div>\n";
  859. } else {
  860. // Don't show "Edit" icon
  861. $list .= "<td></td>";
  862. // Don't show "Delete" icon
  863. $list .= "<td></td></tr></table>\n";
  864. $list .= "</div>\n";
  865. }
  866. }
  867. // End comment block div
  868. $list .= "</div>\n";
  869. } else {
  870. if ($project) {
  871. $list .= "<b>No comments entered for this project.</b><br>\n";
  872. } else if ($duty) {
  873. $list .= "<b>No comments entered for this duty.</b><br>\n";
  874. } else {
  875. if ($displayed_user == "All") {
  876. $list .= "<b>No comments entered during this date range.</b><br>\n";
  877. } else {
  878. $list .= "<b>No comments entered by $displayed_user in this date range.</b><br>\n";
  879. }
  880. }
  881. }
  882. // Close the database connection
  883. $list_full->free_result();
  884. if ($pageflag) {
  885. $list_page->free_result();
  886. }
  887. $conn->close();
  888. return $list;
  889. }
  890. function show_project_comments($project, $edit_priv) {
  891. global $background_color;
  892. global $heading_color;
  893. $myList = "";
  894. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  895. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  896. mysql_select_db(DB_DATABASE);
  897. $get_comments = mysql_query("select comment_id, comment_text, submit_date, " .
  898. "submit_time from comments where project_id = \"$project\" " .
  899. "order by submit_time desc ");
  900. if (mysql_num_rows($get_comments) == 0) {
  901. $myList .= "No comments entered for this project.<br>\n";
  902. }
  903. // Don't show edit or delete icons if user does not have edit_priv
  904. if ($edit_priv == "Y") {
  905. while ($row = mysql_fetch_array($get_comments, MYSQL_ASSOC))
  906. {
  907. $myList .= "<div id='comment_" . $row['comment_id'] . "'>";
  908. // Date submitted
  909. $myList .= "<table><tr valign='top'><td>" . short_date($row['submit_date
  910. ']) . "</td>\n";
  911. // Comment text
  912. $myList .= "<td bgcolor='white' style='{border: 1px solid $heading_color
  913. ; padding-left: 5px; padding-right: 5px;}'>"
  914. . $row['comment_text'] . "</td>\n";
  915. // "Edit" icon
  916. $myList .= "<td><img src='images/pencil.gif' style='{position:relative;
  917. padding-left:20px;}' " .
  918. "onclick='show_editbox(\"editcomment_" . $row['comment_id'] . "\");'
  919. ></td>";
  920. // "Delete" icon
  921. $myList .= "<td style='background-color:" . $background_color . "'><img src='images/trash.gif' onclick='show_confirm(\"confirmcomment_" . $row['comment_id'] . "\");'>" .
  922. "</td></tr></table>\n";
  923. // Div for edit box
  924. $myList .= "<div class='editbox' id='editcomment_" . $row['comment_id'] . "' style='background-color: white;'>" .
  925. "<center><font color='red'>Edit:</font><br>\n<textarea id='txtEditComment_" .
  926. $row['comment_id'] .
  927. "' rows='3' cols='100'>\n" .
  928. //"onkeydown='handleKeyEditComment(event, $project, " . $row['comment_id'] . ")'>\n" .
  929. $row['comment_text'] . "</textarea><br>" .
  930. "<img src='images/update_icon.png' " .
  931. "onclick='{var editcomm = $(\"comment_" . $row['comment_id'] . "\"); Element.hide(editcomm); " .
  932. "process_comments(" . $row['comment_id'] . ", \"editComment\", \"" . $project . "\");}'> &nbsp; &nbsp; " .
  933. //"process_comments(editcomm.id, \"editComment\", \"" . $project . "\");}'> &nbsp; &nbsp; " .
  934. "<img src='images/cancel_icon.png' onclick='hide_editbox(\"editcomment_" . $row['comment_id'] . "\");'></center></div>\n";
  935. // Div to confirm deletion
  936. $myList .= "<div class='confirm' id='confirmcomment_" . $row['comment_id'] . "' style='background-color: white;'><font color='red'>" .
  937. "<center>Are you sure you want to delete this item?</font><br>" .
  938. "<img src='images/confirm_delete_icon.png' " .
  939. "onclick='{var remcomm = $(\"comment_" . $row['comment_id'] . "\"); Element.hide(remcomm); " .
  940. "process_comments(" . $row['comment_id'] . ", \"delComment\", \"" .
  941. $project . "\");}'> &nbsp; &nbsp; " .
  942. "<img src='images/cancel_icon.png' onclick='hide_confirm(\"confirmcomment_" . $row['comment_id'] . "\");'></center></div>";
  943. $myList .= "</div>\n";
  944. }
  945. } else {
  946. while ($row = mysql_fetch_array($get_comments, MYSQL_ASSOC))
  947. {
  948. $myList .= "<div id='comment_" . $row['comment_id'] . "' style='background-color: white'>";
  949. // Date submitted
  950. $myList .= "<table><tr valign='top'><td>" . short_date($row['submit_date']) . "</td>\n";
  951. // Comment text
  952. $myList .= "<td bgcolor='white' style='border: 1px solid $heading_color;'>"
  953. . $row['comment_text'] . "</td>\n";
  954. // Don't show "Edit" icon
  955. $myList .= "<td></td>";
  956. // Don't show "Delete" icon
  957. $myList .= "<td></td></tr></table>\n";
  958. $myList .= "</div>\n";
  959. }
  960. }
  961. mysql_free_result($get_comments);
  962. mysql_close($conn);
  963. return $myList;
  964. }
  965. function ugly_date($formatted_date) {
  966. if ($formatted_date) {
  967. $parts = explode(" ", $formatted_date);
  968. $months = array("January", "February", "March", "April", "May", "June", "July",
  969. "August", "September", "October", "November", "December");
  970. $monthnum = array_search($parts[0], $months) + 1;
  971. if (strlen($monthnum) < 2) {
  972. $monthnum = "0" . $monthnum;
  973. }
  974. $daynum = substr($parts[1], 0, strlen($parts[1]) - 1);
  975. if (strlen($daynum) < 2) {
  976. $daynum = "0" . $daynum;
  977. }
  978. $year = $parts[2];
  979. $newformat = $year . "-" . $monthnum . "-" . $daynum;
  980. return $newformat;
  981. } else {
  982. return $formatted_date;
  983. }
  984. }
  985. function pretty_date($formatted_date) {
  986. if ($formatted_date) {
  987. if ($formatted_date == "0000-00-00") {
  988. return "";
  989. }
  990. $parts = explode("-", $formatted_date);
  991. $months = array("January", "February", "March", "April", "May", "June", "July",
  992. "August", "September", "October", "November", "December");
  993. $monthname = $months[$parts[1] - 1];
  994. $daynum = $parts[2];
  995. if (substr($daynum, 0, 1) == "0") {
  996. $daynum = substr($daynum, 1);
  997. }
  998. $year = $parts[0];
  999. $newformat = "$monthname $daynum, $year";
  1000. return $newformat;
  1001. } else {
  1002. return $formatted_date;
  1003. }
  1004. }
  1005. function short_date($formatted_date) {
  1006. if ($formatted_date) {
  1007. if ($formatted_date == "0000-00-00") {
  1008. return "";
  1009. }
  1010. $parts = explode("-", $formatted_date);
  1011. $monthnum = $parts[1];
  1012. if (substr($monthnum, 0, 1) == "0") {
  1013. $monthnum = substr($monthnum, 1);
  1014. }
  1015. $daynum = $parts[2];
  1016. if (substr($daynum, 0, 1) == "0") {
  1017. $daynum = substr($daynum, 1);
  1018. }
  1019. $year = $parts[0];
  1020. $weekday = date("D", mktime(0, 0, 0, $monthnum, $daynum, $year));
  1021. $shortyear = date("y", mktime(0, 0, 0, $monthnum, $daynum, $year));
  1022. // If the date isn't in the current year, specify the year
  1023. if ($year != date("Y")) {
  1024. $newformat = "$weekday $monthnum/$daynum/$shortyear";
  1025. } else {
  1026. $newformat = "$weekday $monthnum/$daynum";
  1027. }
  1028. return $newformat;
  1029. } else {
  1030. return "";
  1031. }
  1032. }
  1033. function shorter_date($formatted_date) {
  1034. if ($formatted_date) {
  1035. if ($formatted_date == "0000-00-00") {
  1036. return "";
  1037. }
  1038. $parts = explode("-", $formatted_date);
  1039. $monthnum = $parts[1];
  1040. if (substr($monthnum, 0, 1) == "0") {
  1041. $monthnum = substr($monthnum, 1);
  1042. }
  1043. $daynum = $parts[2];
  1044. if (substr($daynum, 0, 1) == "0") {
  1045. $daynum = substr($daynum, 1);
  1046. }
  1047. $year = $parts[0];
  1048. $weekday = date("D", mktime(0, 0, 0, $monthnum, $daynum, $year));
  1049. $shortyear = date("y", mktime(0, 0, 0, $monthnum, $daynum, $year));
  1050. // If the date isn't in the current year, specify the year
  1051. if ($year != date("Y")) {
  1052. $newformat = "$monthnum/$daynum/$shortyear";
  1053. } else {
  1054. $newformat = "$monthnum/$daynum";
  1055. }
  1056. return $newformat;
  1057. } else {
  1058. return "";
  1059. }
  1060. }
  1061. function mysql_date($standard_date) {
  1062. if ($standard_date) {
  1063. $parts = explode("/", $standard_date);
  1064. $monthnum = $parts[0];
  1065. if (strlen($monthnum) < 2) {
  1066. $monthnum = "0" . $monthnum;
  1067. }
  1068. $daynum = $parts[1];
  1069. if (strlen($daynum) < 2) {
  1070. $daynum = "0" . $daynum;
  1071. }
  1072. $year = $parts[2];
  1073. $newformat = $year . "-" . $monthnum . "-" . $daynum;
  1074. return $newformat;
  1075. } else {
  1076. return $standard_date;
  1077. }
  1078. }
  1079. function standard_date($mysql_date) {
  1080. if ($mysql_date) {
  1081. if ($mysql_date == "0000-00-00") {
  1082. return "";
  1083. }
  1084. $parts = explode("-", $mysql_date);
  1085. $monthnum = $parts[1];
  1086. //if (substr($monthnum, 0, 1) == "0") {
  1087. // $monthnum = substr($monthnum, 1);
  1088. //}
  1089. $daynum = $parts[2];
  1090. //if (substr($daynum, 0, 1) == "0") {
  1091. // $daynum = substr($daynum, 1);
  1092. //}
  1093. $longyear = $parts[0];
  1094. // If the date isn't in the current year, specify the year
  1095. $newformat = "$monthnum/$daynum/$longyear";
  1096. return $newformat;
  1097. } else {
  1098. return "";
  1099. }
  1100. }
  1101. function display_controls($fields, $values) {
  1102. // Make sure at least one field was passed
  1103. if (count($fields) < 1) {
  1104. return "";
  1105. }
  1106. // Start table for controls
  1107. printf("<table class='smalltext'><tr>\n");
  1108. // Store passed arguments into local variables
  1109. for ($i = 0; $i < count($fields); $i++) {
  1110. if ($fields[$i] == "Staff") {
  1111. // Staff Member
  1112. $staff = $values[$i];
  1113. //printf("<td>Staff Member: \n");
  1114. printf("<td>Staff: \n");
  1115. printf("<select name='staff' size='1' onChange='viewform.submit()'>\n");
  1116. // Retrieve and display list of staff members
  1117. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  1118. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  1119. mysql_select_db (DB_DATABASE);
  1120. $get_staff = mysql_query("select user_id, first_name, last_name from users " .
  1121. "where staff_flag = \"Y\" order by last_name ");
  1122. if ($staff == 0) {
  1123. printf("<option value='0' selected>All\n");
  1124. } else {
  1125. printf("<option value='0'>All\n");
  1126. }
  1127. $displayed_user = "All";
  1128. while ($row = mysql_fetch_array($get_staff)) {
  1129. if ($staff == $row[0]) {
  1130. printf("<option value='$row[0]' selected>$row[1] $row[2]\n");
  1131. $displayed_user = "$row[1] $row[2]";
  1132. } else {
  1133. printf("<option value='$row[0]'>$row[1] $row[2]\n");
  1134. }
  1135. }
  1136. mysql_free_result($get_staff);
  1137. mysql_close($conn);
  1138. printf("</select></td>\n");
  1139. continue;
  1140. }
  1141. if ($fields[$i] == "Pstatus") {
  1142. // Project status
  1143. $status = $values[$i];
  1144. //printf("<td>Project Status: \n");
  1145. printf("<td>Projects: \n");
  1146. printf("<select name='status' size='1' onChange='viewform.submit()'>\n");
  1147. // Default status is Active
  1148. if ($status == "") {
  1149. $status = "Active";
  1150. }
  1151. // Show list of status values
  1152. if ($status == "All") {
  1153. printf("<option value='All' selected>All\n");
  1154. } else {
  1155. printf("<option value='All'>All\n");
  1156. }
  1157. if ($status == "Open") {
  1158. printf("<option value='Open' selected>Open\n");
  1159. } else {
  1160. printf("<option value='Open'>Open\n");
  1161. }
  1162. if ($status == "Proposed") {
  1163. printf("<option value='Proposed' selected>Proposed\n");
  1164. } else {
  1165. printf("<option value='Proposed'>Proposed\n");
  1166. }
  1167. if ($status == "Pending") {
  1168. printf("<option value='Pending' selected>Pending\n");
  1169. } else {
  1170. printf("<option value='Pending'>Pending\n");
  1171. }
  1172. if ($status == "Active") {
  1173. printf("<option value='Active' selected>Active\n");
  1174. } else {
  1175. printf("<option value='Active'>Active\n");
  1176. }
  1177. if ($status == "Suspended") {
  1178. printf("<option value='Suspended' selected>Suspended\n");
  1179. } else {
  1180. printf("<option value='Suspended'>Suspended\n");
  1181. }
  1182. if ($status == "Aborted") {
  1183. printf("<option value='Aborted' selected>Aborted\n");
  1184. } else {
  1185. printf("<option value='Aborted'>Aborted\n");
  1186. }
  1187. if ($status == "Completed") {
  1188. printf("<option value='Completed' selected>Completed\n");
  1189. } else {
  1190. printf("<option value='Completed'>Completed\n");
  1191. }
  1192. printf("</select></td>\n");
  1193. continue;
  1194. }
  1195. if ($fields[$i] == "Dstatus") {
  1196. // Duty Status
  1197. $dutystatus = $values[$i];
  1198. //printf("<td>Duty Status: \n");
  1199. printf("<td>Duties: \n");
  1200. printf("<select name='status' size='1' onChange='viewform.submit()'>\n");
  1201. // Default status is Active
  1202. if ($dutystatus == "") {
  1203. $dutystatus = "Active";
  1204. }
  1205. // Show list of status values
  1206. if ($dutystatus == "All") {
  1207. printf("<option value='All' selected>All\n");
  1208. } else {
  1209. printf("<option value='All'>All\n");
  1210. }
  1211. if ($dutystatus == "Active") {
  1212. printf("<option value='Active' selected>Active\n");
  1213. } else {
  1214. printf("<option value='Active'>Active\n");
  1215. }
  1216. if ($dutystatus == "Inactive") {
  1217. printf("<option value='Inactive' selected>Inactive\n");
  1218. } else {
  1219. printf("<option value='Inactive'>Inactive\n");
  1220. }
  1221. printf("</select></td>\n");
  1222. continue;
  1223. }
  1224. if ($fields[$i] == "Tstatus") {
  1225. // ToDo Status
  1226. $todostatus = $values[$i];
  1227. //printf("<td>To Do Status: \n");
  1228. printf("<td>To Do Status: \n");
  1229. printf("<select name='todostatus' size='1' onChange='viewform.submit()'>\n");
  1230. // Default todo status is Pending
  1231. if ($todostatus == "") {
  1232. $todostatus = "Pending";
  1233. }
  1234. // Show list of status values
  1235. if ($todostatus == "Pending") {
  1236. printf("<option value='Pending' selected>Pending\n");
  1237. } else {
  1238. printf("<option value='Pending'>Pending\n");
  1239. }
  1240. if ($todostatus == "Completed") {
  1241. printf("<option value='Completed' selected>Completed\n");
  1242. } else {
  1243. printf("<option value='Completed'>Completed\n");
  1244. }
  1245. printf("</select></td>\n");
  1246. continue;
  1247. }
  1248. if ($fields[$i] == "Priority") {
  1249. // ToDo Status
  1250. $priority = $values[$i];
  1251. printf("<td>Priority: \n");
  1252. printf("<select name='priority' size='1' onChange='viewform.submit()'>\n");
  1253. // Default priority is High
  1254. if ($priority == "") {
  1255. $priority = "High";
  1256. }
  1257. // Show list of status values
  1258. if ($priority == "High") {
  1259. printf("<option value='High' selected>High\n");
  1260. } else {
  1261. printf("<option value='High'>High\n");
  1262. }
  1263. if ($priority == "Low") {
  1264. printf("<option value='Low' selected>Low\n");
  1265. } else {
  1266. printf("<option value='Low'>Low\n");
  1267. }
  1268. printf("</select></td>\n");
  1269. continue;
  1270. }
  1271. if ($fields[$i] == "FromDate") {
  1272. // From Date
  1273. $fromdate = $values[$i];
  1274. printf("<td>From: \n");
  1275. show_date_form_onchange('fromdate', $fromdate);
  1276. printf("</td>\n");
  1277. continue;
  1278. }
  1279. if ($fields[$i] == "ToDate") {
  1280. // To Date
  1281. $todate = $values[$i];
  1282. printf("<td>To: \n");
  1283. show_date_form_onchange('todate', $todate);
  1284. printf("</td>\n");
  1285. continue;
  1286. }
  1287. if ($fields[$i] == "Ftype") {
  1288. // File Type
  1289. $filetype = $values[$i];
  1290. printf("<td>File Type: \n");
  1291. printf("<select name='filetype' size='1' onChange='viewform.submit()'>\n");
  1292. // Default todo status is Pending
  1293. if ($todostatus == "") {
  1294. $todostatus = "Pending";
  1295. }
  1296. // Show list of file type values
  1297. if ($filetype == "") {
  1298. printf("<option value='NULL' selected>\n");
  1299. } else {
  1300. printf("<option value='NULL'>\n");
  1301. }
  1302. if ($filetype == "Report") {
  1303. printf("<option value='Report' selected>Report\n");
  1304. } else {
  1305. printf("<option value='Report'>Report\n");
  1306. }
  1307. if ($filetype == "Program") {
  1308. printf("<option value='Program' selected>Program\n");
  1309. } else {
  1310. printf("<option value='Program'>Program\n");
  1311. }
  1312. if ($filetype == "Protocol") {
  1313. printf("<option value='Protocol' selected>Protocol\n");
  1314. } else {
  1315. printf("<option value='Protocol'>Protocol\n");
  1316. }
  1317. printf("</select></td>\n");
  1318. continue;
  1319. }
  1320. if ($fields[$i] == "Results") {
  1321. // Results Per Page
  1322. $maxresults = $values[$i];
  1323. printf("<td>Results Per Page: \n");
  1324. printf("<input type='text' name='maxresults' size='2' value='$maxresults' onChange='viewform.submit()'>\n");
  1325. printf("</td>\n");
  1326. continue;
  1327. }
  1328. }
  1329. printf("</tr></table>\n");
  1330. return $displayed_user;
  1331. }
  1332. function show_date_form($datevar, $defaultvalue) {
  1333. // Show a date variable in a form
  1334. printf("<input type='text' name='$datevar' id='$datevar' size='12' value='$defaultvalue'>\n");
  1335. printf("<img src='images/calendar.gif' id='$datevar" . "_cal' ");
  1336. printf("style='cursor: pointer; border: 1px solid red;' title='Date selector' ");
  1337. printf("onmouseover=\"this.style.background='red';\" ");
  1338. printf("onmouseout=\"this.style.background=''\">\n");
  1339. printf("<script type='text/javascript'>\n");
  1340. printf(" Calendar.setup({\n");
  1341. printf(" inputField : \"$datevar\", // id of the input field\n");
  1342. printf(" ifFormat : \"%%m/%%d/%%Y\", // format of the input field\n");
  1343. printf(" button : \"$datevar" . "_cal\", // trigger for the calendar (button ID)\n");
  1344. printf(" align : \"Tl\", // alignment (defaults to \"Bl\")\n");
  1345. printf(" singleClick : true\n");
  1346. printf(" });\n");
  1347. printf("</script>\n");
  1348. }
  1349. function show_date_form_onchange($datevar, $defaultvalue) {
  1350. // Show a date variable in a form
  1351. printf("<input type='text' name='$datevar' id='$datevar' size='12' value='$defaultvalue' onChange='viewform.submit()'>\n");
  1352. printf("<img src='images/calendar.gif' id='$datevar" . "_cal' ");
  1353. printf("style='cursor: pointer; border: 1px solid red;' title='Date selector' ");
  1354. printf("onmouseover=\"this.style.background='red';\" ");
  1355. printf("onmouseout=\"this.style.background=''\">\n");
  1356. printf("<script type='text/javascript'>\n");
  1357. printf(" Calendar.setup({\n");
  1358. printf(" inputField : \"$datevar\", // id of the input field\n");
  1359. printf(" ifFormat : \"%%m/%%d/%%Y\", // format of the input field\n");
  1360. printf(" button : \"$datevar" . "_cal\", // trigger for the calendar (button ID)\n");
  1361. printf(" align : \"Tl\", // alignment (defaults to \"Bl\")\n");
  1362. printf(" singleClick : true\n");
  1363. printf(" });\n");
  1364. printf("</script>\n");
  1365. }
  1366. function page_results($rowcount, $page, $maxresults, $url) {
  1367. // Show total number of results
  1368. $paging = "<table cellspacing='5' cellpadding='0' class='smalltext'><tr>";
  1369. $paging .= "<td><b>Results: $rowcount</b></td>\n";
  1370. // Show page number
  1371. $maxpage = ceil($rowcount / $maxresults);
  1372. $paging .= "<td>&nbsp; Page $page of $maxpage</td>\n";
  1373. // Previous page button
  1374. if ($page > 1) {
  1375. $paging .= "<td>&nbsp; <a href='$url&page=" . ($page - 1) .
  1376. "&maxresults=$maxresults'>Prev</a></td>\n";
  1377. }
  1378. // Next page button
  1379. if ($page < $maxpage) {
  1380. $paging .= "<td>&nbsp; <a href='$url&page=" . ($page + 1) .
  1381. "&maxresults=$maxresults'>Next</a></td>\n";
  1382. }
  1383. $paging .= "</tr></table>\n";
  1384. return $paging;
  1385. }
  1386. function fill_pdlist_arrays($staff, &$projects, &$project_ids, &$duties, &$duty_ids) {
  1387. // Create JavaScript array of open projects
  1388. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  1389. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  1390. mysql_select_db (DB_DATABASE);
  1391. $get_projects = mysql_query("select project_id, title from projects " .
  1392. "where staff_assigned = \"$staff\" " .
  1393. "and status in ('Pending', 'Active', 'Suspended') " .
  1394. "order by date_entered desc ");
  1395. $project_ids = array();
  1396. $projects = array();
  1397. $nprojects = 0;
  1398. while ($row = mysql_fetch_array($get_projects, MYSQL_ASSOC)) {
  1399. if (strlen($row['title']) > 40) {
  1400. $project_title = substr($row['title'], 0, 37) . "...";
  1401. } else {
  1402. $project_title = $row['title'];
  1403. }
  1404. $project_ids[$nprojects] = $row['project_id'];
  1405. $projects[$nprojects] = $project_title;
  1406. $nprojects++;
  1407. }
  1408. mysql_free_result($get_projects);
  1409. mysql_close($conn);
  1410. printf("<script language='JavaScript'>\n");
  1411. printf("var project_ids = new Array(%d);\n", $nprojects);
  1412. printf("var projects = new Array(%d);\n", $nprojects);
  1413. for ($i = 0; $i < $nprojects; $i++) {
  1414. printf("project_ids[$i] = '$project_ids[$i]';\n");
  1415. printf("projects[$i] = '$projects[$i]';\n");
  1416. }
  1417. printf("</script>\n");
  1418. // Create JavaScript array of active duties
  1419. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  1420. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  1421. mysql_select_db (DB_DATABASE);
  1422. $get_duties = mysql_query("select duty_id, title from duties " .
  1423. "where staff_assigned = \"$staff\" " .
  1424. "and status = 'Active' " .
  1425. "order by date_entered desc ");
  1426. $duty_ids = array();
  1427. $duties = array();
  1428. $nduties = 0;
  1429. while ($row = mysql_fetch_array($get_duties, MYSQL_ASSOC)) {
  1430. if (strlen($row['title']) > 40) {
  1431. $duty_title = substr($row['title'], 0, 37) . "...";
  1432. } else {
  1433. $duty_title = $row['title'];
  1434. }
  1435. $duty_ids[$nduties] = $row['duty_id'];
  1436. $duties[$nduties] = $duty_title;
  1437. $nduties++;
  1438. }
  1439. mysql_free_result($get_duties);
  1440. mysql_close($conn);
  1441. printf("<script language='JavaScript'>\n");
  1442. printf("var duty_ids = new Array(%d);\n", $nduties);
  1443. printf("var duties = new Array(%d);\n", $nduties);
  1444. for ($i = 0; $i < $nduties; $i++) {
  1445. printf("duty_ids[$i] = '$duty_ids[$i]';\n");
  1446. printf("duties[$i] = '$duties[$i]';\n");
  1447. }
  1448. printf("</script>\n");
  1449. return;
  1450. }
  1451. function make_pdlist($staff, $id, $project, $projects, $project_ids,
  1452. $duty, $duties, $duty_ids, $breakflag) {
  1453. if ($id) {
  1454. $suffix = "_" . $id;
  1455. } else {
  1456. $suffix = "";
  1457. }
  1458. $nprojects = count($projects);
  1459. $nduties = count($duties);
  1460. if ($row['project_id']) {
  1461. $pstyle = "style='font-weight: bold' ";
  1462. $dstyle = "style='font-weight: normal' ";
  1463. } else if ($row['duty_id']) {
  1464. $pstyle = "style='font-weight: normal' ";
  1465. $dstyle = "style='font-weight: bold' ";
  1466. } else {
  1467. $pstyle = "style='font-weight: bold' ";
  1468. $dstyle = "style='font-weight: normal' ";
  1469. }
  1470. // Project/Duty selection
  1471. $list = "<font id='projectlabel$suffix' onclick='pdflag$suffix = \"Project\"; " .
  1472. "populate_projects( $(\"pdlist$suffix\"), $(\"projectlabel$suffix\"), " .
  1473. "$(\"dutylabel$suffix\"), project_ids, projects, \"$project\");' $pstyle>";
  1474. $list .= "Project</font> / ";
  1475. $list .= "<font id='dutylabel$suffix' onclick='pdflag$suffix = \"Duty\"; " .
  1476. "populate_duties( $(\"pdlist$suffix\"), $(\"projectlabel$suffix\"), " .
  1477. "$(\"dutylabel$suffix\"), duty_ids, duties, \"$duty\");' $dstyle>Duty</font>";
  1478. if ($breakflag) {
  1479. $list .= "<br>\n";
  1480. } else {
  1481. $list .= "\n";
  1482. }
  1483. $list .= "<select id='pdlist$suffix' size='1' " .
  1484. "onChange=\"if (pdflag$suffix == 'Project') {duty = 0; " .
  1485. "project = project_ids[$('pdlist$suffix').selectedIndex - 1];} " .
  1486. "else {project = 0; duty = duty_ids[$('pdlist$suffix').selectedIndex - 1];}\" >\n";
  1487. if ($project) {
  1488. $list .= "<option value='P0'></option>\n";
  1489. for ($i = 0; $i < $nprojects; $i++) {
  1490. if ($project == $project_ids[$i]) {
  1491. $list .= "<option value='P" . $project_ids[$i] .
  1492. "' selected>" . $projects[$i] . "</option>\n";
  1493. } else {
  1494. $list .= "<option value='P" . $project_ids[$i] .
  1495. "'>" . $projects[$i] . "</option>\n";
  1496. }
  1497. }
  1498. } else if ($duty) {
  1499. $list .= "<option value='D0'></option>\n";
  1500. for ($i = 0; $i < $nduties; $i++) {
  1501. if ($duty == $duty_ids[$i]) {
  1502. $list .= "<option value='D" . $duty_ids[$i] .
  1503. "' selected>" . $duties[$i] . "</option>\n";
  1504. } else {
  1505. $list .= "<option value='D" . $duty_ids[$i] .
  1506. "'>" . $duties[$i] . "</option>\n";
  1507. }
  1508. }
  1509. } else {
  1510. $list .= "<option value='P0'></option>\n";
  1511. for ($i = 0; $i < $nprojects; $i++) {
  1512. if ($project == $project_ids[$i]) {
  1513. $list .= "<option value='P" . $project_ids[$i] .
  1514. "' selected>" . $projects[$i] . "</option>\n";
  1515. } else {
  1516. $list .= "<option value='P" . $project_ids[$i] .
  1517. "'>" . $projects[$i] . "</option>\n";
  1518. }
  1519. }
  1520. }
  1521. $list .= "</select>\n";
  1522. return $list;
  1523. }
  1524. function find_mover($oldorderlist1, $neworderlist, &$mover, &$datepartner) {
  1525. // Find date borders in the new order
  1526. $borders = array();
  1527. $nborders = 0;
  1528. for ($i = 0; $i < count($neworderlist); $i++) {
  1529. if (substr($neworderlist[$i], 0, 1) == "A") {
  1530. $borders[$nborders] = $neworderlist[$i];
  1531. $nborders++;
  1532. }
  1533. }
  1534. // Fill in missing borders in old order
  1535. $oldorderlist = array();
  1536. $count = 0;
  1537. for ($i = 0; $i < count($oldorderlist1); $i++) {
  1538. $testborder = "A" . $oldorderlist1[$i];
  1539. if (in_array($testborder, $borders)) {
  1540. $oldorderlist[$count] = $testborder;
  1541. $count++;
  1542. }
  1543. $oldorderlist[$count] = $oldorderlist1[$i];
  1544. $count++;
  1545. }
  1546. // Find first change in lists, from front and back
  1547. for ($i = 0; $i < count($neworderlist); $i++) {
  1548. if ($neworderlist[$i] != $oldorderlist[$i]) {
  1549. $candidate1 = $neworderlist[$i];
  1550. $c1new = $i;
  1551. break;
  1552. }
  1553. }
  1554. for ($i = (count($neworderlist) - 1); $i >= 0; $i--) {
  1555. if ($neworderlist[$i] != $oldorderlist[$i]) {
  1556. $candidate2 = $neworderlist[$i];
  1557. $c2new = $i;
  1558. break;
  1559. }
  1560. }
  1561. // Find positions of candidates in old order
  1562. $c1old = array_search($neworderlist[$c1new], $oldorderlist);
  1563. $c2old = array_search($neworderlist[$c2new], $oldorderlist);
  1564. // The real moved item will have two different neighbors
  1565. if (($oldorderlist[$c1old - 1] != $neworderlist[$c1new - 1]) &&
  1566. ($oldorderlist[$c1old + 1] != $neworderlist[$c1new + 1])) {
  1567. // Candidate 1 is the mover
  1568. $mover = $candidate1;
  1569. // Find date partner
  1570. if (substr($neworderlist[$c1new - 1], 0, 1) == "A") {
  1571. $datepartner = $neworderlist[$c1new + 1];
  1572. } else if (substr($neworderlist[$c1new + 1], 0, 1) == "A") {
  1573. $datepartner = $neworderlist[$c1new - 1];
  1574. } else {
  1575. $datepartner = $neworderlist[$c1new + 1];
  1576. }
  1577. } else {
  1578. // Candidate 2 is the mover
  1579. $mover = $candidate2;
  1580. // Find date partner
  1581. if (substr($neworderlist[$c2new - 1], 0, 1) == "A") {
  1582. $datepartner = $neworderlist[$c2new + 1];
  1583. } else if (substr($neworderlist[$c2new + 1], 0, 1) == "A") {
  1584. $datepartner = $neworderlist[$c2new - 1];
  1585. } else {
  1586. $datepartner = $neworderlist[$c2new + 1];
  1587. }
  1588. }
  1589. return;
  1590. }
  1591. ?>