PageRenderTime 72ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/common.php

https://github.com/obenauer/equilibrium
PHP | 685 lines | 510 code | 109 blank | 66 comment | 135 complexity | 00a96263cb24b226c8d22e6ba9eb2096 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. require("check_login.php");
  16. require("config.php");
  17. // Check for passed arguments
  18. if (isset($_GET['action'])) {
  19. $action = $_GET['action'];
  20. } else {
  21. $action = "";
  22. }
  23. if (isset($_GET['cmd'])) {
  24. $cmd = $_GET['cmd'];
  25. } else {
  26. $cmd = "";
  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['status'])) {
  38. $status = $_REQUEST['status'];
  39. } else {
  40. $status = "Active";
  41. }
  42. if (isset($_REQUEST['todostatus'])) {
  43. $todostatus = $_REQUEST['todostatus'];
  44. } else {
  45. $todostatus = "Completed";
  46. }
  47. if (isset($_REQUEST['priority'])) {
  48. $priority = $_REQUEST['priority'];
  49. } else {
  50. $priority = "High";
  51. }
  52. if (isset($_REQUEST['calmode'])) {
  53. $calmode = $_REQUEST['calmode'];
  54. } else {
  55. $calmode = 0;
  56. }
  57. if (isset($_REQUEST['edit_priv'])) {
  58. $edit_priv = $_REQUEST['edit_priv'];
  59. } else {
  60. $edit_priv = "N";
  61. }
  62. if (isset($_REQUEST['content'])) {
  63. $content = $_REQUEST['content'];
  64. } else {
  65. $content = "";
  66. }
  67. if (isset($_REQUEST['order'])) {
  68. $order = $_REQUEST['order'];
  69. } else {
  70. $order = "";
  71. }
  72. if (isset($_REQUEST['page'])) {
  73. $page = $_REQUEST['page'];
  74. } else {
  75. $page = 1;
  76. }
  77. if (isset($_REQUEST['pageflag'])) {
  78. $pageflag = $_REQUEST['pageflag'];
  79. } else {
  80. $pageflag = 0;
  81. }
  82. if (isset($_REQUEST['dragonly'])) {
  83. $dragonly = $_REQUEST['dragonly'];
  84. } else {
  85. $dragonly = 0;
  86. }
  87. if ((isset($_REQUEST['project'])) && (is_numeric($_REQUEST['project']))) {
  88. $project = $_REQUEST['project'];
  89. } else {
  90. $project = 0;
  91. }
  92. if ((isset($_REQUEST['duty'])) && (is_numeric($_REQUEST['duty']))) {
  93. $duty = $_REQUEST['duty'];
  94. } else {
  95. $duty = 0;
  96. }
  97. if (isset($_REQUEST['maxresults'])) {
  98. $maxresults = $_REQUEST['maxresults'];
  99. if ($maxresults == 0) {
  100. $maxresults = 20;
  101. }
  102. } else {
  103. $maxresults = 20;
  104. }
  105. if (isset($_REQUEST['newtext'])) {
  106. $newtext = $_REQUEST['newtext'];
  107. } else {
  108. $newtext = 0;
  109. }
  110. if (isset($_REQUEST['pdflag'])) {
  111. $pdflag = $_REQUEST['pdflag'];
  112. } else {
  113. $pdflag = "";
  114. }
  115. if (isset($_REQUEST['pdchange'])) {
  116. $pdchange = $_REQUEST['pdchange'];
  117. } else {
  118. $pdchange = 0;
  119. }
  120. if (isset($_REQUEST['staffchange'])) {
  121. $staffchange = $_REQUEST['staffchange'];
  122. } else {
  123. $staffchange = 0;
  124. }
  125. if (isset($_REQUEST['visibility'])) {
  126. $visibility = $_REQUEST['visibility'];
  127. } else {
  128. $visibility = "Public";
  129. }
  130. if (isset($_REQUEST['scheduledate'])) {
  131. $scheduledate = $_REQUEST['scheduledate'];
  132. } else {
  133. $scheduledate = "";
  134. }
  135. if (isset($_REQUEST['fromdate'])) {
  136. $fromdate = $_REQUEST['fromdate'];
  137. } else {
  138. // Default: one month ago
  139. $prevmonth = mktime(0, 0, 0, date("m") - 1, date("d"), date("Y"));
  140. $fromdate = date("Y", $prevmonth) . "-" . date("m", $prevmonth) . "-" .
  141. date("d", $prevmonth);
  142. }
  143. if (isset($_REQUEST['todate'])) {
  144. $todate = $_REQUEST['todate'];
  145. } else {
  146. // Default: today's date
  147. $todate = date('Y') . "-" . date('m') . "-" . date('d');
  148. }
  149. // Declare PHP functions
  150. require("equilibrium.php");
  151. // Commands that don't generate HTML output
  152. switch($cmd) {
  153. case "updatelist";
  154. if ($order) {
  155. $todo_order = explode(",", $order);
  156. if ($project) {
  157. $order_var = "project_order";
  158. } else if ($duty) {
  159. $order_var = "duty_order";
  160. } else {
  161. $order_var = "order_number";
  162. }
  163. if ($calmode) {
  164. // Remove alphabetic div's from to-do order
  165. $modlist = array();
  166. $modcount = 0;
  167. for ($i = 0; $i < count($todo_order); $i++) {
  168. if (is_numeric($todo_order[$i])) {
  169. $modlist[$modcount] = $todo_order[$i];
  170. $modcount++;
  171. }
  172. }
  173. $numeric_todos = implode(",", $modlist);
  174. // Retrieve existing order of to-do's
  175. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  176. or die ("Cannot connect to database. " . mysql_error() . "\n<br>\n");
  177. mysql_select_db(DB_DATABASE);
  178. $get_orig_order = mysql_query("select todo_id from todos " .
  179. "where todo_id in ($numeric_todos) order by $order_var asc ");
  180. $oldorder = array();
  181. $oldcount = 0;
  182. while ($row = mysql_fetch_array($get_orig_order, MYSQL_ASSOC)) {
  183. $oldorder[$oldcount] = $row['todo_id'];
  184. $oldcount++;
  185. }
  186. mysql_free_result($get_orig_order);
  187. // Get schedule dates of to-do's near the moved one
  188. $mover = 0;
  189. $datepartner = 0;
  190. find_mover($oldorder, $todo_order, $mover, $datepartner);
  191. // Re-assign scheduled date of moved to-do item
  192. $get_copy_date = mysql_query("select schedule_date from todos " .
  193. "where todo_id = \"" . $datepartner . "\" ");
  194. if ($row = mysql_fetch_array($get_copy_date, MYSQL_ASSOC)) {
  195. $copied_date = $row['schedule_date'];
  196. }
  197. mysql_free_result($get_copy_date);
  198. if (($copied_date == "0000-00-00") || ($copied_date == "")) {
  199. $copied_date = "NULL";
  200. } else {
  201. // Don't allow scheduling a to-do to a past date
  202. $parts = explode("-", $copied_date);
  203. $calday = mktime(0, 0, 0, $parts[1], $parts[2], $parts[0]);
  204. $today = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
  205. if ($calday < $today) {
  206. $copied_date = "NULL";
  207. }
  208. }
  209. $query = "update todos set schedule_date = \"" . $copied_date . "\" " .
  210. "where todo_id = \"" . $mover . "\" ";
  211. $update = mysql_query($query);
  212. if ($update != 1) {
  213. $errorflag = 1;
  214. }
  215. }
  216. // Re-order to-do items in response to drag and drop
  217. $conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
  218. $errorflag = 0;
  219. $offset = ($page - 1) * $maxresults;
  220. for ($i = 0; $i < count($todo_order); $i++) {
  221. $query = "update todos set $order_var = \"" . ($offset + $i + 1) . "\" " .
  222. "where todo_id = \"" . $todo_order[$i] . "\" ";
  223. //printf("query = $query (page = $page)<br>\n");
  224. $update = $conn->query($query);
  225. if ($update != 1) {
  226. $errorflag = 1;
  227. }
  228. }
  229. // Close the database connection
  230. $conn->close();
  231. $new_todolist = build_todolist($staff, $status, $todostatus, $priority,
  232. $calmode, $project, $duty, $pageflag, $dragonly, $page, $maxresults);
  233. printf($new_todolist);
  234. exit;
  235. } else {
  236. printf("<p>Error updating to-do list: Order is not specified.</p>\n");
  237. require("footer.php");
  238. exit;
  239. }
  240. break;
  241. // Delete to-do item
  242. case "deleteitem";
  243. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  244. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  245. mysql_select_db(DB_DATABASE);
  246. $content = trim(mysql_real_escape_string($content));
  247. $result = mysql_query("DELETE FROM todos WHERE todo_id = '$content'");
  248. mysql_close($conn);
  249. $new_todolist = build_todolist($staff, $status, $todostatus, $priority,
  250. $calmode, $project, $duty, $pageflag, $dragonly, $page, $maxresults);
  251. printf($new_todolist);
  252. exit;
  253. break;
  254. case "edititem";
  255. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  256. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  257. mysql_select_db(DB_DATABASE);
  258. //$newtext = trim(mysql_real_escape_string($newtext));
  259. if (($scheduledate) && ($scheduledate != "NULL") && ($scheduledate != "000-00-00")) {
  260. $scheduleclause = "schedule_date = \"$scheduledate\", ";
  261. } else {
  262. $scheduleclause = "schedule_date = NULL, ";
  263. }
  264. if ($pdflag == "Project") {
  265. $edit_item = mysql_query("UPDATE todos set description = \"" . $newtext .
  266. "\", project_id = \"$pdchange\", duty_id = \"0\", " .
  267. "staff_assigned = \"$staffchange\", $scheduleclause " .
  268. "visibility = \"$visibility\" WHERE todo_id = '$content' ");
  269. } else if ($pdflag == "Duty") {
  270. $edit_item = mysql_query("UPDATE todos set description = \"" . $newtext .
  271. "\", duty_id = \"$pdchange\", project_id = \"0\", " .
  272. "staff_assigned = \"$staffchange\", $scheduleclause " .
  273. "visibility = \"$visibility\" WHERE todo_id = '$content' ");
  274. } else {
  275. $edit_item = mysql_query("UPDATE todos set description = \"" . $newtext .
  276. "\", staff_assigned = \"$staffchange\", $scheduleclause " .
  277. "visibility = \"$visibility\" WHERE todo_id = '$content' ");
  278. }
  279. mysql_close($conn);
  280. $new_todolist = build_todolist($staff, $status, $todostatus, $priority,
  281. $calmode, $project, $duty, $pageflag, $dragonly, $page, $maxresults);
  282. //$new_todolist .= "UPDATE todos set description = \"" . $newtext .
  283. // "\", duty_id = \"$pdchange\", project_id = \"0\", " .
  284. // "staff_assigned = \"$staffchange\", " .
  285. // "visibility = \"$visibility\" WHERE todo_id = '$content' ";
  286. printf($new_todolist);
  287. exit;
  288. break;
  289. case "additem";
  290. // Add new item
  291. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  292. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  293. mysql_select_db(DB_DATABASE);
  294. //$newtext = trim(mysql_real_escape_string($content));
  295. $newtext = trim($content);
  296. if ($newtext) {
  297. if ($pdflag == "Project") {
  298. // Move existing to-do items up in order
  299. $start_trans = mysql_query("start transaction ");
  300. $get_order = mysql_query("SELECT todo_id from todos " .
  301. "where project_id = \"$pdchange\" " .
  302. "and completed = 'N' " .
  303. "order by project_order asc ");
  304. $count = 2;
  305. while ($row = mysql_fetch_array($get_order, MYSQL_ASSOC)) {
  306. $set_order = mysql_query("update todos set project_order = \"$count\" " .
  307. "where todo_id = \"" . $row['todo_id'] . "\" ");
  308. $count++;
  309. }
  310. mysql_free_result($get_order);
  311. // Assign this to-do the same visibility as its project
  312. $get_vis = mysql_query("SELECT visibility from projects " .
  313. "where project_id = \"$pdchange\" ");
  314. if ($row = mysql_fetch_array($get_vis, MYSQL_ASSOC)) {
  315. $visibility = $row['visibility'];
  316. } else {
  317. $visibility = 'Public';
  318. }
  319. mysql_free_result($get_vis);
  320. // Add new item at top of list
  321. $add_item = mysql_query("INSERT into todos (description, " .
  322. "project_id, duty_id, staff_assigned, project_order, " .
  323. "visibility) " .
  324. "values (\"$newtext\", \"$pdchange\", \"0\", \"$staff\", " .
  325. "\"1\", \"$visibility\" ) ");
  326. $stop_trans = mysql_query("commit ");
  327. } else if ($pdflag == "Duty") {
  328. // Move existing to-do items up in order
  329. $start_trans = mysql_query("start transaction ");
  330. $get_order = mysql_query("SELECT todo_id from todos " .
  331. "where duty_id = \"$pdchange\" " .
  332. "and completed = 'N' " .
  333. "order by duty_order asc ");
  334. $count = 2;
  335. while ($row = mysql_fetch_array($get_order, MYSQL_ASSOC)) {
  336. $set_order = mysql_query("update todos set duty_order = \"$count\" " .
  337. "where todo_id = \"" . $row['todo_id'] . "\" ");
  338. $count++;
  339. }
  340. mysql_free_result($get_order);
  341. // Assign this to-do the same visibility as its duty
  342. $get_vis = mysql_query("SELECT visibility from duties " .
  343. "where duty_id = \"$pdchange\" ");
  344. if ($row = mysql_fetch_array($get_vis, MYSQL_ASSOC)) {
  345. $visibility = $row['visibility'];
  346. } else {
  347. $visibility = 'Public';
  348. }
  349. mysql_free_result($get_vis);
  350. // Add new item at top of list
  351. $add_item = mysql_query("INSERT into todos (description, " .
  352. "project_id, duty_id, staff_assigned, duty_order, " .
  353. "visibility) " .
  354. "values (\"$newtext\", \"0\", \"$pdchange\", \"$staff\", " .
  355. "\"1\", \"$visibility\" ) ");
  356. $stop_trans = mysql_query("commit ");
  357. } else {
  358. // Query conditions for To Do page
  359. if ($status == "All") {
  360. $statusclause = "";
  361. } else if ($status == "Open") {
  362. $statusclause = "and ((p.status in ('Pending', 'Active', 'Suspended') " .
  363. "or t.project_id = 0) " .
  364. "and (d.status = \"Active\" or t.duty_id = 0)) ";
  365. } else {
  366. $statusclause = "and ((p.status = \"$status\" " .
  367. "or t.project_id = 0) " .
  368. "and (d.status = \"Active\" or t.duty_id = 0)) ";
  369. }
  370. // Only let people add items as themselves, but can reassign later
  371. $staffclause = "and t.staff_assigned = \"" .
  372. $_SESSION['SESSION_USERID'] . "\" ";
  373. // Move existing to-do items up in order
  374. $start_trans = mysql_query("start transaction ");
  375. $get_order = mysql_query("SELECT t.todo_id from todos as t " .
  376. "left join projects as p on t.project_id = p.project_id " .
  377. "left join duties as d on t.duty_id = d.duty_id " .
  378. "where project_id = \"$pdchange\" " .
  379. "and completed = 'N' " .
  380. $statusclause . $staffclause .
  381. "order by order_number asc ");
  382. $count = 2;
  383. while ($row = mysql_fetch_array($get_order, MYSQL_ASSOC)) {
  384. $set_order = mysql_query("update todos set order_number = \"$count\" " .
  385. "where todo_id = \"" . $row['todo_id'] . "\" ");
  386. $count++;
  387. }
  388. mysql_free_result($get_order);
  389. // Add new item at top of list
  390. $add_item = mysql_query("INSERT into todos (description, project_id, " .
  391. "duty_id, staff_assigned, order_number) values (\"" . $newtext . "\", \"0\", " .
  392. "\"0\", \"$staff\", \"1\" ) ");
  393. $stop_trans = mysql_query("commit ");
  394. }
  395. }
  396. mysql_close($conn);
  397. $new_todolist = build_todolist($staff, $status, $todostatus, $priority,
  398. $calmode, $project, $duty, $pageflag, $dragonly, $page, $maxresults);
  399. printf($new_todolist);
  400. exit;
  401. break;
  402. // Toggle task priority
  403. case 'togglepriority':
  404. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  405. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  406. mysql_select_db(DB_DATABASE);
  407. // escape input data
  408. $content = trim(mysql_real_escape_string($content));
  409. // Check whether task is high or low priority already
  410. $result = mysql_query('SELECT priority FROM todos ' .
  411. 'where todo_id = "' . $content . '"');
  412. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  413. if ($row['priority'] == "High") {
  414. // mark task low priority
  415. $result = mysql_query('UPDATE todos set priority = "Low" WHERE todo_id="'
  416. . $content . '"');
  417. } else {
  418. // mark task completed
  419. $result = mysql_query('UPDATE todos set priority = "High" WHERE todo_id="'
  420. . $content . '"');
  421. }
  422. mysql_close($conn);
  423. $new_todolist = build_todolist($staff, $status, $todostatus, $priority,
  424. $calmode, $project, $duty, $pageflag, $dragonly, $page, $maxresults);
  425. printf($new_todolist);
  426. exit;
  427. break;
  428. //}
  429. case "togglecomplete";
  430. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  431. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  432. mysql_select_db(DB_DATABASE);
  433. $content = trim(mysql_real_escape_string($content));
  434. // Check whether task is already marked completed
  435. $result = mysql_query('SELECT completed FROM todos ' .
  436. 'where todo_id = "' . $content . '"');
  437. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  438. if ($row['completed'] == "Y") {
  439. // mark task NOT completed
  440. $result = mysql_query('UPDATE todos set completed = "N", ' .
  441. 'completed_date = NULL, completed_time = NULL ' .
  442. 'WHERE todo_id="' . $content . '"');
  443. } else {
  444. // mark task completed
  445. $result = mysql_query('UPDATE todos set completed = "Y", ' .
  446. 'completed_date = CURDATE(), completed_time = NOW() ' .
  447. 'WHERE todo_id="' . $content . '"');
  448. }
  449. mysql_close($conn);
  450. $new_todolist = build_todolist($staff, $status, $todostatus, $priority,
  451. $calmode, $project, $duty, $pageflag, $dragonly, $page, $maxresults);
  452. printf($new_todolist);
  453. exit;
  454. break;
  455. case "togglecomplete_twolists";
  456. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  457. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  458. mysql_select_db(DB_DATABASE);
  459. $content = trim(mysql_real_escape_string($content));
  460. // Check whether task is already marked completed
  461. $result = mysql_query('SELECT completed FROM todos ' .
  462. 'where todo_id = "' . $content . '"');
  463. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  464. if ($row['completed'] == "Y") {
  465. // mark task NOT completed
  466. $result = mysql_query('UPDATE todos set completed = "N", ' .
  467. 'completed_date = NULL WHERE todo_id="' . $content . '"');
  468. } else {
  469. // mark task completed
  470. $result = mysql_query('UPDATE todos set completed = "Y", ' .
  471. 'completed_date = CURDATE() WHERE todo_id="' . $content . '"');
  472. }
  473. mysql_close($conn);
  474. $new_twolists = build_two_lists($staff, $status, $priority, $calmode,
  475. $project, $duty, $pageflag, $dragonly, $page, $maxresults);
  476. printf($new_twolists);
  477. exit;
  478. break;
  479. // Delete comment
  480. case "deletecomment";
  481. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  482. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  483. mysql_select_db(DB_DATABASE);
  484. $content = trim(mysql_real_escape_string($content));
  485. $result = mysql_query("DELETE FROM comments WHERE comment_id = '$content' ");
  486. mysql_close($conn);
  487. $new_commentlist = build_commentlist($staff, $project, $duty,
  488. $fromdate, $todate, $pageflag, $page, $maxresults);
  489. printf($new_commentlist);
  490. break;
  491. // Edit comment
  492. case "editcomment";
  493. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  494. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  495. mysql_select_db(DB_DATABASE);
  496. $newtext = trim(mysql_real_escape_string($newtext));
  497. if ($pdflag == "Project") {
  498. $edit_comment = mysql_query("UPDATE comments set comment_text = \"" . $newtext .
  499. "\", project_id = \"$pdchange\", duty_id = \"0\", " .
  500. "submitter_id = \"" . $_SESSION['SESSION_USERID'] . "\", " .
  501. "visibility = \"$visibility\" WHERE comment_id = '$content' ");
  502. } else if ($pdflag == "Duty") {
  503. $edit_comment = mysql_query("UPDATE comments set comment_text = \"" . $newtext .
  504. "\", duty_id = \"$pdchange\", project_id = \"0\", " .
  505. "submitter_id = \"" . $_SESSION['SESSION_USERID'] . "\", " .
  506. "visibility = \"$visibility\" WHERE comment_id = '$content' ");
  507. } else {
  508. $edit_comment = mysql_query("UPDATE comments set comment_text = \"" . $newtext .
  509. "\", submitter_id = \"" . $_SESSION['SESSION_USERID'] . "\", " .
  510. "visibility = \"$visibility\" WHERE comment_id = '$content' ");
  511. }
  512. mysql_close($conn);
  513. $new_commentlist = build_commentlist($staff, $project, $duty,
  514. $fromdate, $todate, $pageflag, $page, $maxresults);
  515. printf($new_commentlist);
  516. exit;
  517. break;
  518. // Add comment
  519. case "addcomment";
  520. // Add new comment
  521. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  522. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  523. mysql_select_db(DB_DATABASE);
  524. $newtext = trim(mysql_real_escape_string($content));
  525. if ($newtext) {
  526. if ($pdflag == "Project") {
  527. // Assign this comment the same visibility as its project
  528. $get_vis = mysql_query("SELECT visibility from projects " .
  529. "where project_id = \"$pdchange\" ");
  530. if ($row = mysql_fetch_array($get_vis, MYSQL_ASSOC)) {
  531. $visibility = $row['visibility'];
  532. } else {
  533. $visibility = 'Public';
  534. }
  535. mysql_free_result($get_vis);
  536. // Add new comment
  537. $add_comment = mysql_query("INSERT into comments (comment_text, " .
  538. "project_id, duty_id, submitter_id, submit_date, submit_time, " .
  539. "visibility) " .
  540. "values (\"$newtext\", \"$pdchange\", \"0\", \"" .
  541. $_SESSION['SESSION_USERID'] . "\", curdate(), now(), " .
  542. "\"$visibility\" ) ");
  543. } else if ($pdflag == "Duty") {
  544. // Assign this comment the same visibility as its duty
  545. $get_vis = mysql_query("SELECT visibility from duties " .
  546. "where duty_id = \"$pdchange\" ");
  547. if ($row = mysql_fetch_array($get_vis, MYSQL_ASSOC)) {
  548. $visibility = $row['visibility'];
  549. } else {
  550. $visibility = 'Public';
  551. }
  552. mysql_free_result($get_vis);
  553. // Add new comment
  554. $add_comment = mysql_query("INSERT into comments (comment_text, " .
  555. "project_id, duty_id, submitter_id, submit_date, submit_time, " .
  556. "visibility) " .
  557. "values (\"$newtext\", \"0\", \"$pdchange\", \"" .
  558. $_SESSION['SESSION_USERID'] . "\", curdate(), now(), " .
  559. "\"$visibility\" ) ");
  560. } else {
  561. // Add new comment
  562. $add_comment = mysql_query("INSERT into comments (comment_text, " .
  563. "project_id, duty_id, submitter_id, submit_date, submit_time) " .
  564. "values (\"$newtext\", \"0\", \"$pdchange\", \"" .
  565. $_SESSION['SESSION_USERID'] . "\", curdate(), now() ) ");
  566. // Add new item at top of list
  567. }
  568. }
  569. mysql_close($conn);
  570. $new_commentlist = build_commentlist($staff, $project, $duty,
  571. $fromdate, $todate, $pageflag, $page, $maxresults);
  572. printf($new_commentlist);
  573. exit;
  574. break;
  575. }
  576. ?>