PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/files.php

https://github.com/obenauer/equilibrium
PHP | 311 lines | 201 code | 45 blank | 65 comment | 62 complexity | 08fc9dcd3e6adbee7dde26e69f3643ed 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($_REQUEST['action'])) {
  19. $action = $_REQUEST['action'];
  20. } else {
  21. $action = "";
  22. }
  23. if (isset($_REQUEST['cmd'])) {
  24. $cmd = $_REQUEST['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['edit_priv'])) {
  38. $edit_priv = $_REQUEST['edit_priv'];
  39. } else {
  40. $edit_priv = "N";
  41. }
  42. if (isset($_REQUEST['content'])) {
  43. $content = $_REQUEST['content'];
  44. } else {
  45. $content = "";
  46. }
  47. if (isset($_GET['filetype'])) {
  48. $filetype = $_GET['filetype'];
  49. } else {
  50. $filetype = "Report";
  51. }
  52. if (isset($_REQUEST['page'])) {
  53. $page = $_REQUEST['page'];
  54. } else {
  55. $page = 1;
  56. }
  57. if (isset($_REQUEST['pageflag'])) {
  58. $pageflag = $_REQUEST['pageflag'];
  59. } else {
  60. $pageflag = 1;
  61. }
  62. if ((isset($_REQUEST['project'])) && (is_numeric($_REQUEST['project']))) {
  63. $project = $_REQUEST['project'];
  64. } else {
  65. $project = 0;
  66. }
  67. if ((isset($_REQUEST['duty'])) && (is_numeric($_REQUEST['duty']))) {
  68. $duty = $_REQUEST['duty'];
  69. } else {
  70. $duty = 0;
  71. }
  72. if (isset($_REQUEST['maxresults'])) {
  73. $maxresults = $_REQUEST['maxresults'];
  74. if ($maxresults == 0) {
  75. $maxresults = 20;
  76. }
  77. } else {
  78. $maxresults = 20;
  79. }
  80. if (isset($_REQUEST['pdflag'])) {
  81. $pdflag = $_REQUEST['pdflag'];
  82. } else {
  83. $pdflag = "";
  84. }
  85. if (isset($_REQUEST['pdchange'])) {
  86. $pdchange = $_REQUEST['pdchange'];
  87. } else {
  88. $pdchange = 0;
  89. }
  90. if (isset($_REQUEST['staffchange'])) {
  91. $staffchange = $_REQUEST['staffchange'];
  92. } else {
  93. $staffchange = 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 year ago
  104. $prevmonth = mktime(0, 0, 0, date("m"), date("d"), date("Y") - 1);
  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. // Declare PHP functions
  115. require("equilibrium.php");
  116. function show_files($staff, $filetype, $fromdate, $todate, $pageflag,
  117. $page, $maxresults) {
  118. global $heading_color;
  119. // Define filetype clause
  120. if (($filetype == "") || ($filetype == "NULL")) {
  121. $fileclause = "and file_type is null ";
  122. } else {
  123. $fileclause = "and file_type = \"$filetype\" ";
  124. }
  125. // Define staff clause
  126. if ($staff == 0) {
  127. $staffclause = "";
  128. } else {
  129. $staffclause = "and uploaded_by = \"$staff\" ";
  130. }
  131. $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
  132. or die ("Cannot connect to database. " . mysql_error() . "\n<br>");
  133. mysql_select_db(DB_DATABASE);
  134. $query = "select file_id, file_type, file_name, description, " .
  135. "upload_date, upload_time, file_path from files " .
  136. "where upload_date >= \"$fromdate\" " .
  137. "and upload_date <= \"$todate\" " .
  138. $staffclause .
  139. $fileclause .
  140. "order by upload_time desc ";
  141. $list_full = mysql_query($query);
  142. // Allow paging option
  143. if ($pageflag) {
  144. $list_page = mysql_query($query . "limit " . (($page - 1) * $maxresults) .
  145. ", $maxresults ");
  146. $page_url = "files.php?staff=$staff&filetype=$filetype&fromdate=$fromdate" .
  147. "&todate=$todate";
  148. printf("%s", page_results(mysql_num_rows($list_page), $page, $maxresults,
  149. $page_url));
  150. } else {
  151. $list_page = $list_full;
  152. }
  153. if (mysql_num_rows($list_page)) {
  154. while ($row = mysql_fetch_array($list_page, MYSQL_ASSOC)) {
  155. printf("<a href=\"%s/%s\">%s</a>, %s \n", $row['file_path'],
  156. $row['file_name'], $row['file_name'], $row['description']);
  157. if ($row['file_type']) {
  158. printf("(%s, %s) \n", $row['file_type'],
  159. short_date($row['upload_date']));
  160. } else {
  161. printf("(%s) &nbsp; \n", short_date($row['upload_date']));
  162. }
  163. printf("<img height='16' src='images/delete.png' title='Delete' " .
  164. "onclick='show_item(\"confirm_" . $row['file_id'] . "\");'><br>\n");
  165. // Div to confirm deletion
  166. printf("<div class='confirm' id='confirm_" . $row['file_id'] .
  167. "' ><font color='red'>" .
  168. "<center>Are you sure you want to delete this file?</font><br>");
  169. printf("<form action='duties.php#file_input' method='post'>\n");
  170. printf("<input type='hidden' name='file_id' value='%d'>\n",
  171. $row['file_id']);
  172. printf("<input type='hidden' name='dirtree' value='%s'>\n",
  173. $row['file_path']);
  174. printf("<input type='hidden' name='existingfile' value='%s'>\n",
  175. $row['file_name']);
  176. printf("<input type='hidden' name='cmd' value='deletefile'>\n");
  177. printf("<input type='hidden' name='duty' value='$duty'>\n");
  178. printf("<input type='submit' value='Confirm Deletion'> &nbsp; &nbsp; ");
  179. printf("<input type='button' value='Cancel' onclick='hide_item(\"confirm_" .
  180. $row['file_id'] . "\");'></center><br>");
  181. printf("</form>\n</div>\n");
  182. }
  183. } else {
  184. printf("<p>No files found for the selected criteria.</p>\n");
  185. }
  186. mysql_free_result($list_page);
  187. @mysql_free_result($list_full);
  188. mysql_close($conn);
  189. return;
  190. }
  191. // Commands that don't generate HTML output
  192. switch($cmd) {
  193. case "":
  194. break;
  195. case "":
  196. break;
  197. case "":
  198. break;
  199. case "":
  200. break;
  201. }
  202. // Start HTML and declare Javascript functions
  203. $activepage = "Files";
  204. require("header.php");
  205. // Main functions of page
  206. switch($action) {
  207. //case "":
  208. // printf("Aloha!<br>\n");
  209. // break;
  210. //case "":
  211. // break;
  212. //case "":
  213. // break;
  214. default;
  215. printf("<h2>Files</h2>\n");
  216. // Button: Add New File
  217. // if (($_SESSION['SESSION_ADMIN'] == "Y") || ($_SESSION['SESSION_STAFF'] == "Y")) {
  218. // printf("<table><tr>\n");
  219. // printf("<td>\n");
  220. // printf("<input type='button' name='add_file_button' id='add_file_button'></td>\n");
  221. // printf("</tr></table>\n");
  222. //
  223. // // Javascript for add new file button
  224. // printf("<script type='text/javascript'>\n");
  225. // printf("set_add_file_button();");
  226. // printf("</script>\n");
  227. //
  228. // // Add new file form
  229. // printf("<div id='add_file_form' class='addbox'>\n");
  230. // printf("<table cellpadding='0' cellspacing='0'><tr valign='top'><td>Add new file<br>\n");
  231. // printf("<textarea id='txtNewFile' name='txtNewFile' " .
  232. // "rows='3' cols='80' class='description'></textarea></td>\n");
  233. // // printf("<textarea name='comment' id='txtNewEntry' rows='3' cols='80'></textarea><br>\n");
  234. //
  235. // // Project/duty selection
  236. // printf("<td>");
  237. // fill_pdlist_arrays($staff, $projects, $project_ids, $duties, $duty_ids);
  238. // printf("%s", make_pdlist($staff, $row['comment_id'], $row['project_id'],
  239. // $projects, $project_ids, $row['duty_id'], $duties, $duty_ids, 1));
  240. // printf("</td>\n");
  241. // printf("</td>\n");
  242. // printf("<td valign='top'> &nbsp; <br> &nbsp; <input type='button' value='Add entry' onclick='modify_comment(\"txtNewEntry\", \"addcomment\", \"$staff\", \"0\", \"0\", \"$fromdate\", \"$todate\", \"1\", \"$page\", \"$maxresults\");'></td></tr></table><font size='1'><br></font>\n");
  243. // printf("</div>\n");
  244. //
  245. // }
  246. // Show main controls
  247. $fields = array('Staff', 'Ftype', 'FromDate', 'ToDate', 'Results');
  248. $values = array($staff, $filetype, $fromdate, $todate, $maxresults);
  249. printf("<form action='files.php' method='get' name='viewform'>\n");
  250. $displayed_user = display_controls($fields, $values);
  251. printf("</form>\n");
  252. // Only allow authorized people to sort or mark off to-do items
  253. if (($_SESSION['SESSION_ADMIN'] == "Y") || ($displayed_user == $_SESSION['SESSION_USER'])) {
  254. //|| (trim($displayed_user) == "")) {
  255. $edit_priv = "Y";
  256. } else {
  257. $edit_priv = "N";
  258. }
  259. $filelist = show_files($staff, $filetype,
  260. $fromdate, $todate, $pageflag, $page, $maxresults);
  261. printf($filelist);
  262. break;
  263. }
  264. // End page
  265. require("footer.php");
  266. ?>