PageRenderTime 58ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/includes/cleanup_functions.php

https://github.com/web2project/web2project
PHP | 5315 lines | 3857 code | 612 blank | 846 comment | 730 complexity | 895caaf8be2a1fcf8079a875b53e6251 MD5 | raw file
Possible License(s): LGPL-2.1

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

  1. <?php
  2. /**
  3. * This file exists in order to list individual functions which need to be
  4. * cleaned up, reorganized or eliminated based on usage. Before you touch
  5. * these, please ensure there are Unit Tests to validate that things work
  6. * before and after.
  7. * @todo/TODO: Every single function in this file.
  8. *
  9. * WARNING: The functions in this file are likely to move to other files as they
  10. * are updated. Since this file is included within main_functions.php
  11. * this shouldn't be a problem.
  12. */
  13. function is_task_in_gantt_arr($task)
  14. {
  15. global $gantt_arr;
  16. $n = count($gantt_arr);
  17. for ($x = 0; $x < $n; $x++) {
  18. if ($gantt_arr[$x][0]['task_id'] == $task['task_id']) {
  19. return true;
  20. }
  21. }
  22. return false;
  23. }
  24. function notifyHR($address, $notUsed, $uaddress, $uusername, $logname, $notUsed2, $userid)
  25. {
  26. global $AppUI;
  27. $emailManager = new w2p_Output_EmailManager($AppUI);
  28. $body = $emailManager->notifyHR($uusername, $logname, $uaddress, $userid);
  29. $mail = new w2p_Utilities_Mail();
  30. $mail->To($address);
  31. $mail->Subject('New External User Created');
  32. $mail->Body($body);
  33. return $mail->Send();
  34. }
  35. function notifyNewUserCredentials($address, $username, $logname, $logpwd)
  36. {
  37. global $AppUI;
  38. $emailManager = new w2p_Output_EmailManager($AppUI);
  39. $body = $emailManager->notifyNewUserCredentials($username, $logname, $logpwd);
  40. $mail = new w2p_Utilities_Mail();
  41. $mail->To($address);
  42. $mail->Subject('New Account Created - web2Project Project Management System');
  43. $mail->Body($body);
  44. return $mail->Send();
  45. }
  46. function clean_value($str)
  47. {
  48. $bad_values = array("'");
  49. return str_replace($bad_values, '', $str);
  50. }
  51. function strUTF8Decode($text)
  52. {
  53. if (extension_loaded('mbstring')) {
  54. $encoding = mb_detect_encoding($text.' ');
  55. }
  56. if (function_exists('iconv')) {
  57. $text = mb_convert_encoding($text, 'UTF-8', $encoding);
  58. //iconv($encoding, 'UTF-8', $text);
  59. } elseif (function_exists('utf8_decode')) {
  60. $text = utf8_decode($text);
  61. }
  62. // mb functions don't seam to work well here for some reason as the output gets corrupted.
  63. // iconv is doing the job just fine though
  64. return $text;
  65. }
  66. /**
  67. * utility functions for the preparation of task data for GANTT PDF
  68. *
  69. * @todo some of these functions are not needed, need to trim this down
  70. *
  71. */
  72. // PYS : utf_8 decoding as suggested in Vbulletin #3987
  73. function strEzPdf($text)
  74. {
  75. if (function_exists('iconv') && function_exists('mb_detect_encoding')) {
  76. $text = iconv(mb_detect_encoding($text." "), 'UTF-8', $text);
  77. }
  78. return $text;
  79. }
  80. function dumb_slice( $gantt_arr, $length = 25 )
  81. {
  82. $sliced_array = array();
  83. $pages = (int) count($gantt_arr) / $length;
  84. for ( $i = 0; $i <= $pages; $i++ ) {
  85. $sliced_array[] = array_slice($gantt_arr, $i * $length, $length);
  86. }
  87. return $sliced_array;
  88. }
  89. /**
  90. *
  91. * END OF GANTT PDF UTILITY FUNCTIONS
  92. *
  93. */
  94. /**
  95. * This is a kludgy mess because of how the arraySelectTree function is used..
  96. * it expects - nay, demands! - that the first element of the subarray is the
  97. * id and the third is the parent id. In most cases, that is fine.. in this
  98. * one we're using the existing ACL-respecting functions and it has additional
  99. * fields in "improper" places.
  100. */
  101. function temp_filterArrayForSelectTree($projectData)
  102. {
  103. unset($projectData['project_id']);
  104. unset($projectData['project_color_identifier']);
  105. unset($projectData['project_name']);
  106. unset($projectData['project_start_date']);
  107. unset($projectData['project_end_date']);
  108. unset($projectData['project_company']);
  109. unset($projectData['project_parent']);
  110. unset($projectData[1]);
  111. unset($projectData[3]);
  112. unset($projectData[4]);
  113. unset($projectData[5]);
  114. $projectData[6] = ($projectData[0] == $projectData[6]) ? '' : $projectData[6];
  115. return array_values($projectData);
  116. }
  117. function getReadableModule()
  118. {
  119. $q = new w2p_Database_Query;
  120. $q->addTable('modules');
  121. $q->addQuery('mod_directory');
  122. $q->addWhere('mod_active = 1');
  123. $q->addOrder('mod_ui_order');
  124. $modules = $q->loadColumn();
  125. foreach ($modules as $mod) {
  126. if (canAccess($mod)) {
  127. return $mod;
  128. }
  129. }
  130. return null;
  131. }
  132. /**
  133. * This function is used to check permissions.
  134. */
  135. function checkFlag($flag, $perm_type, $old_flag)
  136. {
  137. if ($old_flag) {
  138. return (($flag == PERM_DENY) || // permission denied
  139. ($perm_type == PERM_EDIT && $flag == PERM_READ) // we ask for editing, but are only allowed to read
  140. ) ? 0 : 1;
  141. } else {
  142. if ($perm_type == PERM_READ) {
  143. return ($flag != PERM_DENY) ? 1 : 0;
  144. } else {
  145. // => $perm_type == PERM_EDIT
  146. return ($flag == $perm_type) ? 1 : 0;
  147. }
  148. }
  149. }
  150. /**
  151. * This function checks certain permissions for
  152. * a given module and optionally an item_id.
  153. *
  154. * $perm_type can be PERM_READ or PERM_EDIT
  155. */
  156. function isAllowed($perm_type, $mod, $item_id = 0)
  157. {
  158. $invert = false;
  159. switch ($perm_type) {
  160. case PERM_READ:
  161. $perm_type = 'view';
  162. break;
  163. case PERM_EDIT:
  164. $perm_type = 'edit';
  165. break;
  166. case PERM_ALL:
  167. $perm_type = 'edit';
  168. break;
  169. case PERM_DENY:
  170. $perm_type = 'view';
  171. $invert = true;
  172. break;
  173. }
  174. $allowed = getPermission($mod, $perm_type, $item_id);
  175. if ($invert) {
  176. return !$allowed;
  177. }
  178. return $allowed;
  179. }
  180. function getPermission($mod, $perm, $item_id = 0)
  181. {
  182. // First check if the module is readable, i.e. has view permission.
  183. $perms = &$GLOBALS['AppUI']->acl();
  184. $result = $perms->checkModule($mod, $perm);
  185. // If we have access then we need to ensure we are not denied access to the particular
  186. // item.
  187. if ($result && $item_id) {
  188. if ($perms->checkModuleItemDenied($mod, $perm, $item_id)) {
  189. $result = false;
  190. }
  191. }
  192. // If denied we need to check if we are allowed the task. This can be done
  193. // a lot better in PHPGACL, but is here for compatibility.
  194. if ($mod == 'tasks' && !$result && $item_id > 0) {
  195. $q = new w2p_Database_Query;
  196. $q->addTable('tasks');
  197. $q->addQuery('task_project');
  198. $q->addWhere('task_id = ' . (int) $item_id);
  199. $project_id = $q->loadResult();
  200. $result = getPermission('projects', $perm, $project_id);
  201. }
  202. return $result;
  203. }
  204. function canView($mod, $item_id = 0)
  205. {
  206. return getPermission($mod, 'view', $item_id);
  207. }
  208. function canEdit($mod, $item_id = 0)
  209. {
  210. return getPermission($mod, 'edit', $item_id);
  211. }
  212. function canAdd($mod, $item_id = 0)
  213. {
  214. return getPermission($mod, 'add', $item_id);
  215. }
  216. function canDelete($mod, $item_id = 0)
  217. {
  218. return getPermission($mod, 'delete', $item_id);
  219. }
  220. function canAccess($mod)
  221. {
  222. return getPermission($mod, 'access');
  223. }
  224. function buildTaskTree($task_data, $depth = 0, $projTasks, $all_tasks, $parents, $task_parent, $task_id)
  225. {
  226. $output = '';
  227. $projTasks[$task_data['task_id']] = $task_data['task_name'];
  228. $task_data['task_name'] = mb_strlen($task_data['task_name']) > 45 ? mb_substr($task_data['task_name'], 0, 45) . '...' : $task_data['task_name'];
  229. $selected = $task_data['task_id'] == $task_parent ? ' selected="selected"' : '';
  230. $output .= '<option value="' . $task_data['task_id'] . '"' . $selected . '>' . str_repeat('&nbsp;', $depth * 3) . w2PFormSafe($task_data['task_name']) . '</option>';
  231. if (isset($parents[$task_data['task_id']])) {
  232. foreach ($parents[$task_data['task_id']] as $child_task) {
  233. if ($child_task != $task_id) {
  234. $output .= buildTaskTree($all_tasks[$child_task], ($depth + 1), $projTasks, $all_tasks, $parents, $task_parent, $task_id);
  235. }
  236. }
  237. }
  238. return $output;
  239. }
  240. // from modules/tasks/addedit.php and modules/projectdesigners/vw_actions.php
  241. function build_date_list(&$date_array, $row)
  242. {
  243. global $project;
  244. // if this task_dynamic is not tracked, set end date to proj start date
  245. if (!in_array($row['task_dynamic'], CTask::$tracked_dynamics)) {
  246. $date = new w2p_Utilities_Date($project->project_start_date);
  247. } elseif ($row['task_milestone'] == 0) {
  248. $date = new w2p_Utilities_Date($row['task_end_date']);
  249. } else {
  250. $date = new w2p_Utilities_Date($row['task_start_date']);
  251. }
  252. $sdate = $date->format('%d/%m/%Y');
  253. $shour = $date->format('%H');
  254. $smin = $date->format('%M');
  255. $date_array[$row['task_id']] = array($row['task_name'], $sdate, $shour, $smin);
  256. }
  257. // from modules/tasks/ae_dates.php
  258. function cal_work_day_conv($val)
  259. {
  260. global $locale_char_set, $AppUI;
  261. setlocale(LC_TIME, 'en');
  262. $wk = Date_Calc::getCalendarWeek(null, null, null, '%a', LOCALE_FIRST_DAY);
  263. setlocale(LC_ALL, $AppUI->user_lang);
  264. $day_name = $AppUI->_($wk[($val - LOCALE_FIRST_DAY) % 7]);
  265. $day_name = utf8_encode($day_name);
  266. return htmlspecialchars($day_name, ENT_COMPAT, $locale_char_set);
  267. }
  268. function __extract_from_showtask(&$arr, $level, $today_view, $listTable, $fields = array())
  269. {
  270. return '';
  271. }
  272. /**
  273. * @param $arr
  274. * @param $level
  275. * @param $today_view
  276. * @param $s
  277. * @param $m
  278. * @param $jsTaskId
  279. * @param $expanded
  280. * @return array
  281. */
  282. function __extract_from_showtask2($arr, $level, $today_view, $s, $m, $jsTaskId, $expanded)
  283. {
  284. $s .= '<td style="width: ' . (($today_view) ? '50%' : '90%') . '" class="data _name">';
  285. //level
  286. if ($level == -1) {
  287. $s .= '...';
  288. }
  289. for ($y = 0; $y < $level; $y++) {
  290. if ($y + 1 == $level) {
  291. $image = w2PfindImage('corner-dots.gif', $m);
  292. } else {
  293. $image = w2PfindImage('shim.gif', $m);
  294. }
  295. $s .= '<img src="' . $image . '" width="16" height="12" border="0" alt=""/>';
  296. }
  297. if ($arr['task_description'] && !$arr['task_milestone']) {
  298. $s .= w2PtoolTip('Task Description', substr($arr['task_description'], 0, 1000), true);
  299. }
  300. if (isset($arr['task_nr_of_children']) && $arr['task_nr_of_children']) {
  301. $is_parent = true;
  302. } else {
  303. $is_parent = false;
  304. }
  305. if ($arr['task_milestone'] > 0) {
  306. $s .= '&nbsp;<a href="./index.php?m=tasks&amp;a=view&amp;task_id=' . $arr['task_id'] . '" ><b>' . $arr['task_name'] . '</b></a>&nbsp;<img src="' . w2PfindImage('icons/milestone.gif') . '" />';
  307. } elseif ($arr['task_dynamic'] == '1' || $is_parent) {
  308. $open_link = '<a href="javascript: void(0);"><img onclick="expand_collapse(\'' . $jsTaskId . '\', \'tblProjects\',\'\',' . ($level++) . ');" id="' . $jsTaskId . '_collapse" src="' . w2PfindImage('icons/collapse.gif') . '" class="center" ' . (!$expanded ? 'style="display:none"' : '') . ' /><img onclick="expand_collapse(\'' . $jsTaskId . '\', \'tblProjects\',\'\',' . ($level++) . ');" id="' . $jsTaskId . '_expand" src="' . w2PfindImage('icons/expand.gif') . '" class="center" ' . ($expanded ? 'style="display:none"' : '') . ' /></a>';
  309. $s .= $open_link;
  310. if ($arr['task_dynamic'] == '1') {
  311. $s .= '&nbsp;<a href="./index.php?m=tasks&amp;a=view&amp;task_id=' . $arr['task_id'] . '" ><b><i>' . $arr['task_name'] . '</i></b></a>';
  312. } else {
  313. $s .= '&nbsp;<a href="./index.php?m=tasks&amp;a=view&amp;task_id=' . $arr['task_id'] . '" >' . $arr['task_name'] . '</a>';
  314. }
  315. } else {
  316. $s .= '&nbsp;<a href="./index.php?m=tasks&amp;a=view&amp;task_id=' . $arr['task_id'] . '" >' . $arr['task_name'] . '</a>';
  317. }
  318. if ($arr['task_description'] && !$arr['task_milestone']) {
  319. $s .= w2PendTip();
  320. }
  321. $s .= '</td>';
  322. return $s;
  323. }
  324. function showtask_new(&$arr, $level = 0, $today_view = false, $listTable = null, $fields = array())
  325. {
  326. return __extract_from_showtask($arr, $level, $today_view, $listTable, $fields);
  327. }
  328. /*
  329. * gantt_arr [ project_id ] [ 0 ] is a task "object" : task['task_id'], task['task_access'], task['task_owner'], task['task_name'], task['project_name']
  330. * task['task_start_date'], task['task_end_date'], task['task_percent_complete'], ['task_milestone']
  331. * gantt_arr [ project_id ] [ 1 ] is the level
  332. *
  333. * project_id is "optional": a 0 value means we re not handling projects
  334. *
  335. * adds a bidimensional array:
  336. * -1st level: composed of integer project_id
  337. * -2nd level: composed of an array of two items: task "object", integer level
  338. */
  339. function showgtask(&$a, $level = 0, $notUsed = 0)
  340. {
  341. /* Add tasks to gantt chart */
  342. global $gantt_arr;
  343. if (!is_task_in_gantt_arr($a)) {
  344. $gantt_arr[] = array($a, $level);
  345. }
  346. }
  347. function findchild_new(&$tarr, $parent, $level = 0)
  348. {
  349. global $shown_tasks;
  350. $level++;
  351. $n = count($tarr);
  352. for ($x = 0; $x < $n; $x++) {
  353. if ($tarr[$x]['task_parent'] == $parent && $tarr[$x]['task_parent'] != $tarr[$x]['task_id']) {
  354. echo showtask_new($tarr[$x], $level, true);
  355. $shown_tasks[$tarr[$x]['task_id']] = $tarr[$x]['task_id'];
  356. findchild_new($tarr, $tarr[$x]['task_id'], $level);
  357. }
  358. }
  359. }
  360. function findchild_gantt(&$tarr, $parent, $level = 0)
  361. {
  362. $level++;
  363. $n = count($tarr);
  364. for ($x = 0; $x < $n; $x++) {
  365. if ($tarr[$x]['task_parent'] == $parent && $tarr[$x]['task_parent'] != $tarr[$x]['task_id']) {
  366. showgtask($tarr[$x], $level, $tarr[$x]['project_id']);
  367. findchild_gantt($tarr, $tarr[$x]['task_id'], $level);
  368. }
  369. }
  370. }
  371. // from modules/tasks/tasks.class.php
  372. function array_csort() { //coded by Ichier2003
  373. $args = func_get_args();
  374. $marray = array_shift($args);
  375. if (empty($marray)) {
  376. return array();
  377. }
  378. $i = 0;
  379. $msortline = 'return(array_multisort(';
  380. $sortarr = array();
  381. foreach ($args as $arg) {
  382. $i++;
  383. if (is_string($arg)) {
  384. for ($j = 0, $j_cmp = count($marray); $j < $j_cmp; $j++) {
  385. /* we have to calculate the end_date via start_date+duration for
  386. ** end='0000-00-00 00:00:00' before sorting, see mantis #1509:
  387. ** Task definition writes the following to the DB:
  388. ** A without start date: start = end = NULL
  389. ** B with start date and empty end date: start = startdate,
  390. end = '0000-00-00 00:00:00'
  391. ** C start + end date: start= startdate, end = end date
  392. ** A the end_date for the middle task (B) is ('dynamically') calculated on display
  393. ** via start_date+duration, it may be that the order gets wrong due to the fact
  394. ** that sorting has taken place _before_.
  395. */
  396. if ($marray[$j]['task_end_date'] == '0000-00-00 00:00:00') {
  397. $marray[$j]['task_end_date'] = calcEndByStartAndDuration($marray[$j]);
  398. }
  399. if ('' == $arg) { continue; }
  400. $sortarr[$i][] = $marray[$j][$arg];
  401. }
  402. } else {
  403. $sortarr[$i] = $arg;
  404. }
  405. if (!is_array($sortarr[$i])) {
  406. continue;
  407. }
  408. $msortline .= '$sortarr[' . $i . '],';
  409. }
  410. $msortline .= '$marray));';
  411. eval($msortline);
  412. return $marray;
  413. }
  414. // from modules/tasks/tasks.class.php
  415. /*
  416. ** Calc End Date via Startdate + Duration
  417. ** @param array task A DB row from the earlier fetched tasklist
  418. ** @return string Return calculated end date in MySQL-TIMESTAMP format
  419. */
  420. function calcEndByStartAndDuration($task)
  421. {
  422. $end_date = new w2p_Utilities_Date($task['task_start_date']);
  423. $end_date->addSeconds($task['task_duration'] * $task['task_duration_type'] * 3600);
  424. return $end_date->format(FMT_DATETIME_MYSQL);
  425. }
  426. // from modules/tasks/tasks.class.php
  427. function sort_by_item_title($title, $item_name, $item_type, $a = '')
  428. {
  429. global $AppUI, $project_id, $task_id, $m;
  430. global $task_sort_item1, $task_sort_type1, $task_sort_order1;
  431. global $task_sort_item2, $task_sort_type2, $task_sort_order2;
  432. if ($task_sort_item2 == $item_name) {
  433. $item_order = $task_sort_order2;
  434. }
  435. if ($task_sort_item1 == $item_name) {
  436. $item_order = $task_sort_order1;
  437. }
  438. $s = '';
  439. if (isset($item_order)) {
  440. $show_icon = true;
  441. } else {
  442. $show_icon = false;
  443. $item_order = SORT_DESC;
  444. }
  445. /* flip the sort order for the link */
  446. $item_order = ($item_order == SORT_ASC) ? SORT_DESC : SORT_ASC;
  447. if ($m == 'tasks') {
  448. $s .= '<a href="./index.php?m=tasks' . (($task_id > 0) ? ('&amp;a=view&amp;task_id=' . $task_id) : $a);
  449. } elseif ($m == 'calendar') {
  450. $s .= '<a href="./index.php?m=events&amp;a=day_view';
  451. } else {
  452. $s .= '<a href="./index.php?m=projects&amp;bypass=1' . (($project_id > 0) ? ('&amp;a=view&amp;project_id=' . $project_id) : '');
  453. }
  454. $s .= '&amp;task_sort_item1=' . $item_name;
  455. $s .= '&amp;task_sort_type1=' . $item_type;
  456. $s .= '&amp;task_sort_order1=' . $item_order;
  457. if ($task_sort_item1 == $item_name) {
  458. $s .= '&amp;task_sort_item2=' . $task_sort_item2;
  459. $s .= '&amp;task_sort_type2=' . $task_sort_type2;
  460. $s .= '&amp;task_sort_order2=' . $task_sort_order2;
  461. } else {
  462. $s .= '&amp;task_sort_item2=' . $task_sort_item1;
  463. $s .= '&amp;task_sort_type2=' . $task_sort_type1;
  464. $s .= '&amp;task_sort_order2=' . $task_sort_order1;
  465. }
  466. $s .= '" class="hdr">' . $AppUI->_($title);
  467. if ($show_icon) {
  468. $s .= '&nbsp;<img src="' . w2PfindImage('arrow-' . (($item_order == SORT_ASC) ? 'up' : 'down') . '.gif') . '" />';
  469. }
  470. return $s.'</a>';
  471. }
  472. // from modules/tasks/tasksperuser_sub.php
  473. function doChildren($list, $N, $id, $uid, $level, $maxlevels, $display_week_hours, $ss, $se)
  474. {
  475. $tmp = '';
  476. if ($maxlevels == -1 || $level < $maxlevels) {
  477. for ($c = 0; $c < $N; $c++) {
  478. $task = $list[$c];
  479. if (($task->task_parent == $id) and isChildTask($task)) {
  480. // we have a child, do we have the user as a member?
  481. if (isMemberOfTask($list, $N, $uid, $task)) {
  482. $tmp .= displayTask($list, $task, $level, $display_week_hours, $ss, $se, $uid);
  483. $tmp .= doChildren($list, $N, $task->task_id, $uid, $level++, $maxlevels, $display_week_hours, $ss, $se);
  484. }
  485. }
  486. }
  487. }
  488. return $tmp;
  489. }
  490. // from modules/reports/tasksperuser.php
  491. function doChildren_r($list, $Lusers, $N, $id, $uid, $level, $maxlevels, $display_week_hours, $ss, $se, $log_all_projects = false)
  492. {
  493. $tmp = "";
  494. if ($maxlevels == -1 || $level < $maxlevels) {
  495. for ($c = 0; $c < $N; $c++) {
  496. $task = $list[$c];
  497. if (($task->task_parent == $id) and isChildTask($task)) {
  498. // we have a child, do we have the user as a member?
  499. if (isMemberOfTask_r($list, $Lusers, $N, $uid, $task)) {
  500. $tmp .= displayTask_r($list, $task, $level, $display_week_hours, $ss, $se, $log_all_projects, $uid);
  501. $tmp .= doChildren_r($list, $Lusers, $N, $task->task_id, $uid, $level++, $maxlevels, $display_week_hours, $ss, $se, $log_all_projects);
  502. }
  503. }
  504. }
  505. }
  506. return $tmp;
  507. }
  508. // from modules/tasks/tasksperuser_sub.php
  509. function isMemberOfTask($notUsed, $notUsed2, $user_id, $task)
  510. {
  511. global $user_assigned_tasks;
  512. if (isset($user_assigned_tasks[$user_id])) {
  513. if (in_array($task->task_id, $user_assigned_tasks[$user_id])) {
  514. return true;
  515. }
  516. }
  517. return false;
  518. }
  519. // from modules/reports/tasksperuser.php
  520. function isMemberOfTask_r($list, $Lusers, $N, $user_id, $task)
  521. {
  522. for ($i = 0; $i < $N && $list[$i]->task_id != $task->task_id; $i++)
  523. ;
  524. $users = $Lusers[$i];
  525. foreach ($users as $task_user_id => $notUsed) {
  526. if ($task_user_id == $user_id) {
  527. return true;
  528. }
  529. }
  530. // check child tasks if any
  531. for ($c = 0; $c < $N; $c++) {
  532. $ntask = $list[$c];
  533. if (($ntask->task_parent == $task->task_id) and isChildTask($ntask)) {
  534. // we have a child task
  535. if (isMemberOfTask_r($list, $Lusers, $N, $user_id, $ntask)) {
  536. return true;
  537. }
  538. }
  539. }
  540. return false;
  541. }
  542. // from modules/tasks/tasksperuser_sub.php
  543. function displayTask($list, $task, $level, $display_week_hours, $fromPeriod, $toPeriod, $user_id)
  544. {
  545. global $AppUI, $durnTypes, $active_users, $zi, $projects;
  546. //if the user has no permission to the project don't show the tasks
  547. if (!(key_exists($task->task_project, $projects))) {
  548. return;
  549. }
  550. $htmlHelper = new w2p_Output_HTMLHelper($AppUI);
  551. $zi++;
  552. $users = $task->task_assigned_users;
  553. $task->userPriority = $task->getUserSpecificTaskPriority($user_id);
  554. $project = $task->getProject();
  555. $tmp = '<tr>';
  556. $tmp .= '<td align="center" nowrap="nowrap">';
  557. $tmp .= '<input type="checkbox" name="selected_task[' . $task->task_id . ']" value="' . $task->task_id . '" />';
  558. $tmp .= '</td>';
  559. $tmp .= $htmlHelper->createCell('user_priority', $task->userPriority);
  560. $tmp .= '<td class="_name">';
  561. for ($i = 0; $i < $level; $i++) {
  562. $tmp .= '&#160';
  563. }
  564. if ($task->task_milestone == true) {
  565. $tmp .= '<b>';
  566. }
  567. if ($level >= 1) {
  568. $tmp .= '<img src="' . w2PfindImage('corner-dots.gif') . '" width="16" height="12" alt="" style="float: left;">';
  569. }
  570. $tmp .= '<a href="?m=tasks&a=view&task_id=' . $task->task_id . '">' . $task->task_name . '</a>';
  571. if ($task->task_milestone == true) {
  572. $tmp .= '</b>';
  573. }
  574. if ($task->task_priority < 0) {
  575. $tmp .= '&nbsp;(<img src="' . w2PfindImage('icons/priority-' . -$task->task_priority . '.gif') . '" width="13" height="16" alt="" />)';
  576. } elseif ($task->task_priority > 0) {
  577. $tmp .= '&nbsp;(<img src="' . w2PfindImage('icons/priority+' . $task->task_priority . '.gif') . '" width="13" height="16" alt="" />)';
  578. }
  579. $tmp .= '</td>';
  580. $tmp .= '<td align="left">';
  581. $tmp .= '<a href="?m=projects&a=view&project_id=' . $task->task_project . '" style="background-color:#' . $project['project_color_identifier'] . '; color:' . bestColor($project['project_color_identifier']) . '">' . $project['project_name'] . '</a>';
  582. $tmp .= '</td>';
  583. $tmp .= $htmlHelper->createCell('task_duration', $task->task_duration . ' ' . mb_substr($AppUI->_($durnTypes[$task->task_duration_type]), 0, 1));
  584. $tmp .= $htmlHelper->createCell('task_start_date', $task->task_start_date);
  585. $tmp .= $htmlHelper->createCell('task_end_date', $task->task_end_date);
  586. if ($display_week_hours) {
  587. $tmp .= displayWeeks($list, $task, $level, $fromPeriod, $toPeriod);
  588. }
  589. $tmp .= '<td>';
  590. $sep = $us = '';
  591. foreach ($users as $notUsed => $row) {
  592. if ($row['user_id']) {
  593. $us .= '<a href="?m=users&a=view&user_id=' . $row[0] . '">' . $sep . $row['contact_name'] . '&nbsp;(' . $row['perc_assignment'] . '%)</a>';
  594. $sep = ', ';
  595. }
  596. }
  597. $tmp .= $us;
  598. $tmp .= '</td>';
  599. // create the list of possible assignees
  600. $size = (count($active_users) > 5) ? 5 : 3;
  601. $tmp .= '<td valign="top" align="center" nowrap="nowrap">';
  602. $tmp .= '<select name="add_users" style="width:200px" size="'.$size.'" class="text" multiple="multiple" ondblclick="javascript:chAssignment(' . $user_id . ', 0, false)">';
  603. foreach ($active_users as $id => $name) {
  604. $tmp .= '<option value="' . $id . '">' . $name . '</option>';
  605. }
  606. $tmp .= '</select>';
  607. $tmp .= '</td>';
  608. $tmp .= '</tr>';
  609. return $tmp;
  610. }
  611. // from modules/reports/tasksperuser.php
  612. function displayTask_r($list, $task, $level, $display_week_hours, $fromPeriod, $toPeriod, $log_all_projects = false, $user_id = 0)
  613. {
  614. global $AppUI;
  615. $htmlHelper = new w2p_Output_HTMLHelper($AppUI);
  616. $tmp = '';
  617. $tmp .= '<tr><td align="left" nowrap="nowrap">&#160&#160&#160';
  618. for ($i = 0; $i < $level; $i++) {
  619. $tmp .= '&#160&#160&#160';
  620. }
  621. if ($level == 0) {
  622. $tmp .= '<b>';
  623. } elseif ($level == 1) {
  624. $tmp .= '<i>';
  625. }
  626. $tmp .= $task->task_name;
  627. if ($level == 0) {
  628. $tmp .= '</b>';
  629. } elseif ($level == 1) {
  630. $tmp .= '</i>';
  631. }
  632. $tmp .= '&#160&#160&#160</td>';
  633. if ($log_all_projects) {
  634. //Show project name when we are logging all projects
  635. $project = $task->getProject();
  636. $tmp .= '<td nowrap="nowrap">';
  637. if (!isChildTask($task)) {
  638. //However only show the name on parent tasks and not the children to make it a bit cleaner
  639. $tmp .= $project['project_name'];
  640. }
  641. $tmp .= '</td>';
  642. }
  643. $tmp .= $htmlHelper->createCell('task_start_date', $task->task_start_date);
  644. $tmp .= $htmlHelper->createCell('task_end_date', $task->task_end_date);
  645. if ($display_week_hours) {
  646. $tmp .= displayWeeks_r($list, $task, $level, $fromPeriod, $toPeriod, $user_id);
  647. }
  648. $tmp .= "</tr>\n";
  649. return $tmp;
  650. }
  651. // from modules/tasks/tasksperuser_sub.php
  652. function isChildTask($task)
  653. {
  654. return $task->task_id != $task->task_parent;
  655. }
  656. // from modules/tasks/tasksperuser_sub.php
  657. function weekDates($display_allocated_hours, $fromPeriod, $toPeriod)
  658. {
  659. if ($fromPeriod == -1) {
  660. return '';
  661. }
  662. if (!$display_allocated_hours) {
  663. return '';
  664. }
  665. $s = new w2p_Utilities_Date($fromPeriod);
  666. $e = new w2p_Utilities_Date($toPeriod);
  667. $sw = getBeginWeek($s);
  668. $dw = ceil($e->dateDiff($s) / 7);
  669. $ew = $sw + $dw;
  670. $row = '';
  671. for ($i = $sw; $i <= $ew; $i++) {
  672. $wn = $s->getWeekofYear() % 52;
  673. $wn = ($wn != 0) ? $wn : 52;
  674. $row .= '<th title="' . $s->getYear() . '" nowrap="nowrap">' . $wn . '</th>';
  675. $s->addSeconds(168 * 3600); // + one week
  676. }
  677. return $row;
  678. }
  679. // from modules/reports/tasksperuser.php
  680. function weekDates_r($display_allocated_hours, $fromPeriod, $toPeriod)
  681. {
  682. global $AppUI;
  683. if ($fromPeriod == -1) {
  684. return '';
  685. }
  686. if (!$display_allocated_hours) {
  687. return '';
  688. }
  689. $s = new w2p_Utilities_Date($fromPeriod);
  690. $e = new w2p_Utilities_Date($toPeriod);
  691. $sw = getBeginWeek($s);
  692. $ew = getEndWeek($e);
  693. $row = '';
  694. for ($i = $sw; $i <= $ew; $i++) {
  695. $sdf = substr($AppUI->getPref('SHDATEFORMAT'), 3);
  696. $row .= '<td nowrap="nowrap" bgcolor="#A0A0A0"><font color="black"><b>' . $s->format($sdf) . '</b></font></td>';
  697. $s->addSeconds(168 * 3600); // + one week
  698. }
  699. return $row;
  700. }
  701. // from modules/tasks/tasksperuser_sub.php
  702. function weekCells($display_allocated_hours, $fromPeriod, $toPeriod)
  703. {
  704. if ($fromPeriod == -1) {
  705. return 0;
  706. }
  707. if (!$display_allocated_hours) {
  708. return 0;
  709. }
  710. $s = new w2p_Utilities_Date($fromPeriod);
  711. $e = new w2p_Utilities_Date($toPeriod);
  712. $sw = getBeginWeek($s);
  713. $dw = ceil($e->dateDiff($s) / 7);
  714. $ew = $sw + $dw;
  715. return $ew - $sw + 1;
  716. }
  717. // from modules/reports/tasksperuser.php
  718. function weekCells_r($display_allocated_hours, $fromPeriod, $toPeriod)
  719. {
  720. if ($fromPeriod == -1) {
  721. return 0;
  722. }
  723. if (!$display_allocated_hours) {
  724. return 0;
  725. }
  726. $s = new w2p_Utilities_Date($fromPeriod);
  727. $e = new w2p_Utilities_Date($toPeriod);
  728. $sw = getBeginWeek($s);
  729. $ew = getEndWeek($e);
  730. return $ew - $sw + 1;
  731. }
  732. // from modules/tasks/tasksperuser_sub.php
  733. // Look for a user when he/she has been allocated
  734. // to this task and when. Report this in weeks
  735. // This function is called within 'displayTask()'
  736. function displayWeeks($list, $task, $level, $fromPeriod, $toPeriod)
  737. {
  738. if ($fromPeriod == -1) {
  739. return '';
  740. }
  741. $s = new w2p_Utilities_Date($fromPeriod);
  742. $e = new w2p_Utilities_Date($toPeriod);
  743. $sw = getBeginWeek($s);
  744. $dw = ceil($e->dateDiff($s) / 7);
  745. $ew = $sw + $dw;
  746. $st = new w2p_Utilities_Date($task->task_start_date);
  747. $et = new w2p_Utilities_Date($task->task_end_date);
  748. $stw = getBeginWeek($st);
  749. $dtw = ceil($et->dateDiff($st) / 7);
  750. $etw = $stw + $dtw;
  751. $row = '';
  752. for ($i = $sw; $i <= $ew; $i++) {
  753. if ($i >= $stw and $i < $etw) {
  754. $color = 'blue';
  755. if ($level == 0 and hasChildren($list, $task)) {
  756. $color = '#C0C0FF';
  757. } elseif ($level == 1 and hasChildren($list, $task)) {
  758. $color = '#9090FF';
  759. }
  760. $row .= '<td nowrap="nowrap" bgcolor="' . $color . '">';
  761. } else {
  762. $row .= '<td nowrap="nowrap">';
  763. }
  764. $row .= '&#160&#160</td>';
  765. }
  766. return $row;
  767. }
  768. // Look for a user when he/she has been allocated
  769. // to this task and when. Report this in weeks
  770. // This function is called within 'displayTask_r()'
  771. // from modules/reports/tasksperuser.php
  772. function displayWeeks_r($list, $task, $level, $fromPeriod, $toPeriod, $user_id = 0)
  773. {
  774. if ($fromPeriod == -1) {
  775. return '';
  776. }
  777. $s = new w2p_Utilities_Date($fromPeriod);
  778. $e = new w2p_Utilities_Date($toPeriod);
  779. $sw = getBeginWeek($s);
  780. $ew = getEndWeek($e);
  781. $st = new w2p_Utilities_Date($task->task_start_date);
  782. $et = new w2p_Utilities_Date($task->task_end_date);
  783. $stw = getBeginWeek($st);
  784. $etw = getEndWeek($et);
  785. $row = '';
  786. for ($i = $sw; $i <= $ew; $i++) {
  787. $assignment = '';
  788. if ($i >= $stw and $i < $etw) {
  789. $color = '#0000FF';
  790. if ($level == 0 and hasChildren($list, $task)) {
  791. $color = '#C0C0FF';
  792. } elseif ($level == 1 and hasChildren($list, $task)) {
  793. $color = '#9090FF';
  794. }
  795. if ($user_id) {
  796. $users = $task->getAssignedUsers($task->task_id);
  797. $assignment = ($users[$user_id]['perc_assignment']) ? $users[$user_id]['perc_assignment'].'%' : '';
  798. }
  799. } else {
  800. $color = '#FFFFFF';
  801. }
  802. $row .= '<td bgcolor="' . $color . '" class="center">';
  803. $row .= '<font color="'.bestColor($color).'">';
  804. $row .= $assignment;
  805. $row .= '</font>';
  806. $row .= '</td>';
  807. }
  808. return $row;
  809. }
  810. // from modules/tasks/tasksperuser_sub.php
  811. // from modules/reports/tasksperuser.php
  812. function getBeginWeek($d)
  813. {
  814. $dn = (int) $d->Format('%w');
  815. $dd = new w2p_Utilities_Date($d);
  816. $dd->subtractSeconds($dn * 24 * 3600);
  817. return (int) $dd->Format('%U');
  818. }
  819. // from modules/tasks/tasksperuser_sub.php
  820. // from modules/reports/tasksperuser.php
  821. function getEndWeek($d)
  822. {
  823. $dn = (int) $d->Format('%w');
  824. if ($dn > 0) {
  825. $dn = 7 - $dn;
  826. }
  827. $dd = new w2p_Utilities_Date($d);
  828. $dd->addSeconds($dn * 24 * 3600);
  829. return (int) $dd->Format('%U');
  830. }
  831. // from modules/tasks/tasksperuser_sub.php
  832. // from modules/reports/tasksperuser.php
  833. function hasChildren($list, $task)
  834. {
  835. foreach ($list as $t) {
  836. if ($t->task_parent == $task->task_id) {
  837. return true;
  838. }
  839. }
  840. return false;
  841. }
  842. // from modules/tasks/tasksperuser_sub.php
  843. function getOrphanedTasks($tval)
  844. {
  845. return (sizeof($tval->task_assigned_users) > 0) ? null : $tval;
  846. }
  847. // from modules/tasks/viewgantt.php
  848. function showfiltertask(&$a, $level=0)
  849. {
  850. /* Add tasks to the filter task aray */
  851. global $filter_task_list, $parents;
  852. $filter_task_list[] = array($a, $level);
  853. $parents[$a['task_parent']] = true;
  854. }
  855. // from modules/tasks/viewgantt.php
  856. function findfiltertaskchild(&$tarr, $parent, $level=0)
  857. {
  858. $level++;
  859. $n = count($tarr);
  860. for ($x=0; $x < $n; $x++) {
  861. if ($tarr[$x]['task_parent'] == $parent && $tarr[$x]['task_parent'] != $tarr[$x]['task_id']) {
  862. showfiltertask($tarr[$x], $level);
  863. findfiltertaskchild($tarr, $tarr[$x]['task_id'], $level);
  864. }
  865. }
  866. }
  867. // from modules/system/roles/roles.class.php
  868. function showRoleRow($role = null)
  869. {
  870. global $canEdit, $canDelete, $role_id, $AppUI, $roles;
  871. $id = $role['id'];
  872. $name = $role['value'];
  873. $description = $role['name'];
  874. if (!$id) {
  875. $roles_arr = array(0 => '(' . $AppUI->_('Copy Role') . '...)');
  876. foreach ($roles as $role) {
  877. $roles_arr[$role['id']] = $role['name'];
  878. }
  879. }
  880. $s = '';
  881. if (($role_id == $id || $id == 0) && $canEdit) {
  882. // edit form
  883. $s .= '<form name="roleFrm" method="post" action="?m=system&u=roles" accept-charset="utf-8">';
  884. $s .= '<input type="hidden" name="dosql" value="do_role_aed" />';
  885. $s .= '<input type="hidden" name="del" value="0" />';
  886. $s .= '<input type="hidden" name="role_id" value="' . $id . '" />';
  887. $s .= '<tr><td>&nbsp;</td>';
  888. $s .= '<td valign="top"><input type="text" size="20" name="role_name" value="' . $name . '" class="text" /></td>';
  889. $s .= '<td valign="top"><input type="text" size="50" name="role_description" class="text" value="' . $description . '">' . ($id ? '' : '&nbsp;&nbsp;&nbsp;&nbsp;' . arraySelect($roles_arr, 'copy_role_id', 'class="text"', 0, true));
  890. $s .= '<input type="submit" value="' . $AppUI->_($id ? 'save' : 'add') . '" class="button btn btn-primary btn-mini right" /></td>';
  891. } else {
  892. $s .= '<tr><td width="50" valign="top">';
  893. if ($canEdit) {
  894. $s .= '<a href="?m=system&u=roles&role_id=' . $id . '">' . w2PshowImage('icons/stock_edit-16.png') . '</a><a href="?m=system&u=roles&a=viewrole&role_id=' . $id . '" title="">' . w2PshowImage('obj/lock.gif') . '</a>';
  895. }
  896. if ($canDelete && strpos($name, 'admin') === false) {
  897. $s .= '<a href=\'javascript:delIt(' . $id . ')\'>' . w2PshowImage('icons/stock_delete-16.png') . '</a>';
  898. }
  899. $s .= '</td><td valign="top">' . $name . '</td><td valign="top">' . $AppUI->_($description) . '</td>';
  900. }
  901. $s .= '</tr>';
  902. return $s;
  903. }
  904. // from modules/system/syskeys/syskeys.class.php
  905. function parseFormatSysval($text, $syskey)
  906. {
  907. $q = new w2p_Database_Query;
  908. $q->addTable('syskeys');
  909. $q->addQuery('syskey_type, syskey_sep1, syskey_sep2');
  910. $q->addWhere('syskey_id = ' . (int) $syskey);
  911. $q->exec();
  912. $row = $q->fetchRow();
  913. $q->clear();
  914. // type 0 = list
  915. $sep1 = $row['syskey_sep1']; // item separator
  916. $sep2 = $row['syskey_sep2']; // alias separator
  917. // A bit of magic to handle newlines and returns as separators
  918. // Missing sep1 is treated as a newline.
  919. if (!isset($sep1) || empty($sep1)) {
  920. $sep1 = "\n";
  921. }
  922. if ($sep1 == "\\n") {
  923. $sep1 = "\n";
  924. }
  925. if ($sep1 == "\\r") {
  926. $sep1 = "\r";
  927. }
  928. $temp = explode($sep1, $text);
  929. $arr = array();
  930. // We use trim() to make sure a numeric that has spaces
  931. // is properly treated as a numeric
  932. foreach ($temp as $item) {
  933. if ($item) {
  934. $sep2 = empty($sep2) ? "\n" : $sep2;
  935. $temp2 = explode($sep2, $item);
  936. if (isset($temp2[1])) {
  937. $arr[mb_trim($temp2[0])] = mb_trim($temp2[1]);
  938. } else {
  939. $arr[mb_trim($temp2[0])] = mb_trim($temp2[0]);
  940. }
  941. }
  942. }
  943. return $arr;
  944. }
  945. // from modules/system/billingcode.php
  946. function showcodes(&$a)
  947. {
  948. global $AppUI, $company_id;
  949. $s = '
  950. <tr>
  951. <td width=40>
  952. <a href="?m=system&amp;a=billingcode&amp;company_id=' . $company_id . '&amp;billingcode_id=' . $a['billingcode_id'] . '" title="' . $AppUI->_('edit') . '">
  953. <img src="' . w2PfindImage('icons/stock_edit-16.png') . '" alt="Edit" /></a>';
  954. if ($a['billingcode_status'] == 0)
  955. $s .= '<a href="javascript:delIt2(' . $a['billingcode_id'] . ');" title="' . $AppUI->_('delete') . '">
  956. <img src="' . w2PfindImage('icons/stock_delete-16.png') . '" alt="Delete" /></a>';
  957. $s .= '
  958. </td>
  959. <td align="left">&nbsp;' . $a['billingcode_name'] . ($a['billingcode_status'] == 1 ? ' (deleted)' : '') . '</td>
  960. <td nowrap="nowrap" align="center">' . $a['billingcode_value'] . '</td>
  961. <td nowrap="nowrap">' . $a['billingcode_desc'] . '</td>
  962. </tr>';
  963. return $s;
  964. }
  965. // from modules/smartsearch/smartsearch.class.php
  966. function highlight($text, $keyval)
  967. {
  968. global $ssearch;
  969. $txt = $text;
  970. $keys = (!is_array($keyval)) ? array($keyval) : $keyval;
  971. foreach ($keys as $key_idx => $key) {
  972. if (mb_strlen($key) > 0) {
  973. $key = stripslashes($key);
  974. $metacharacters = array('\\', '(', ')', '$', '[', '*', '+', '|', '.', '^', '?');
  975. $metareplacement = array('\\\\', '\(', '\)', '\$', '\[', '\*', '\+', '\|', '\.', '\^', '\?');
  976. $key = mb_str_replace($metacharacters, $metareplacement, $key);
  977. if (isset($ssearch['ignore_specchar']) && ($ssearch['ignore_specchar'] == 'on')) {
  978. if ($ssearch['ignore_case'] == 'on') {
  979. $txt = preg_replace('/'.recode2regexp_utf8($key).'/i', '<span class="highlight' . $key_idx . '" >\\0</span>', $txt);
  980. } else {
  981. $txt = preg_replace('/'.(recode2regexp_utf8($key)).'/', '<span class="highlight' . $key_idx . '" >\\0</span>', $txt);
  982. }
  983. } elseif (!isset($ssearch['ignore_specchar']) || ($ssearch['ignore_specchar'] == '')) {
  984. if ($ssearch['ignore_case'] == 'on') {
  985. $txt = preg_replace('/'.$key.'/i', '<span class="highlight' . $key_idx . '" >\\0</span>', $txt);
  986. } else {
  987. $txt = preg_replace('/'.$key.'/', '<span class="highlight' . $key_idx . '" >\\0</span>', $txt);
  988. }
  989. } else {
  990. $txt = preg_replace('/'.$key.'/i', '<span class="highlight:' . $key_idx . '" >\\0</span>', $txt);
  991. }
  992. }
  993. }
  994. return $txt;
  995. }
  996. // from modules/smartsearch/smartsearch.class.php
  997. function recode2regexp_utf8($input)
  998. {
  999. $result = '';
  1000. for ($i = 0, $i_cmp = mb_strlen($input); $i < $i_cmp; ++$i)
  1001. switch ($input[$i]) {
  1002. case 'A':
  1003. case 'a':
  1004. $result .= '(a|A!|A�|A?|A�)';
  1005. break;
  1006. case 'C':
  1007. case 'c':
  1008. $result .= '(c|�?|�O)';
  1009. break;
  1010. case 'D':
  1011. case 'd':
  1012. $result .= '(d|�?|Ď)';
  1013. break;
  1014. case 'E':
  1015. case 'e':
  1016. $result .= '(e|A�|ě|A�|Ě)';
  1017. break;
  1018. case 'I':
  1019. case 'i':
  1020. $result .= '(i|A�|A?)';
  1021. break;
  1022. case 'L':
  1023. case 'l':
  1024. $result .= '(l|�o|�3|�1|�1)';
  1025. break;
  1026. case 'N':
  1027. case 'n':
  1028. $result .= '(n|A^|A�)';
  1029. break;
  1030. case 'O':
  1031. case 'o':
  1032. $result .= '(o|A3|A�|A�|A�)';
  1033. break;
  1034. case 'R':
  1035. case 'r':
  1036. $result .= '(r|A�|A�|A�|A~)';
  1037. break;
  1038. case 'S':
  1039. case 's':
  1040. $result .= '(s|A!|A�)';
  1041. break;
  1042. case 'T':
  1043. case 't':
  1044. $result .= '(t|AY|A�)';
  1045. break;
  1046. case 'U':
  1047. case 'u':
  1048. $result .= '(u|Ao|A�|A�|A�)';
  1049. break;
  1050. case 'Y':
  1051. case 'y':
  1052. $result .= '(y|A1|A?)';
  1053. break;
  1054. case 'Z':
  1055. case 'z':
  1056. $result .= '(z|A3|A1)';
  1057. break;
  1058. default:
  1059. $result .= $input[$i];
  1060. }
  1061. return $result;
  1062. }
  1063. // from modules/public/selector.php
  1064. function selPermWhere($obj, $idfld, $namefield, $prefix = '')
  1065. {
  1066. global $AppUI;
  1067. $allowed = $obj->getAllowedRecords($AppUI->user_id, $idfld . ', ' . $namefield, '', '', '', $prefix);
  1068. if (count($allowed)) {
  1069. return ' ' . $idfld . ' IN (' . implode(',', array_keys($allowed)) . ') ';
  1070. } else {
  1071. return null;
  1072. }
  1073. }
  1074. //comes from modules/departments/departments.class.php
  1075. //writes out a single <option> element for display of departments
  1076. function showchilddept(&$a, $level = 1)
  1077. {
  1078. global $department;
  1079. $s = '<option value="' . $a['dept_id'] . '"' . (isset($department) && $department == $a['dept_id'] ? 'selected="selected"' : '') . '>';
  1080. for ($y = 0; $y < $level; $y++) {
  1081. if ($y + 1 == $level) {
  1082. $s .= '';
  1083. } else {
  1084. $s .= '&nbsp;&nbsp;';
  1085. }
  1086. }
  1087. $s .= '&nbsp;&nbsp;' . $a['dept_name'] . '</option>';
  1088. return $s;
  1089. }
  1090. //comes from modules/departments/departments.class.php
  1091. //recursive function to display children departments.
  1092. function findchilddept(&$tarr, $parent, $level = 1)
  1093. {
  1094. $level++;
  1095. $n = count($tarr);
  1096. for ($x = 0; $x < $n; $x++) {
  1097. if ($tarr[$x]['dept_parent'] == $parent && $tarr[$x]['dept_parent'] != $tarr[$x]['dept_id']) {
  1098. findchilddept($tarr, $tarr[$x]['dept_id'], $level);
  1099. }
  1100. }
  1101. }
  1102. //comes from modules/departments/departments.class.php
  1103. function addDeptId($dataset, $parent)
  1104. {
  1105. global $dept_ids;
  1106. foreach ($dataset as $data) {
  1107. if ($data['dept_parent'] == $parent) {
  1108. $dept_ids[] = $data['dept_id'];
  1109. addDeptId($dataset, $data['dept_id']);
  1110. }
  1111. }
  1112. }
  1113. // From: modules/files/filefolder.class.php
  1114. function getFolderSelectList()
  1115. {
  1116. global $AppUI;
  1117. $q = new w2p_Database_Query();
  1118. $q->addTable('file_folders');
  1119. $q->addQuery('file_folder_id, file_folder_name, file_folder_parent');
  1120. $q->addOrder('file_folder_name');
  1121. $folderList = $q->loadHashList('file_folder_id');
  1122. $folders = array(0 => 'Root');
  1123. foreach($folderList as $folder => $data) {
  1124. $folders[$folder] = $data['file_folder_name'];
  1125. }
  1126. return $folders;
  1127. }
  1128. /*
  1129. * $parent is the parent of the children we want to see
  1130. * $level is increased when we go deeper into the tree, used to display a nice indented tree
  1131. */
  1132. // From: modules/files/filefolder.class.php
  1133. function getFolders($parent)
  1134. {
  1135. global $AppUI, $allowed_folders_ary, $tab, $m, $a, $company_id, $project_id, $task_id;
  1136. // retrieve all children of $parent
  1137. $file_folder = new CFile_Folder();
  1138. $folders = $file_folder->getFoldersByParent($parent);
  1139. $s = '';
  1140. // display each child
  1141. foreach ($folders as $row) {
  1142. if (array_key_exists($row['file_folder_id'], $allowed_folders_ary) or array_key_exists($parent, $allowed_folders_ary)) {
  1143. $file_count = countFiles($row['file_folder_id']);
  1144. $s .= '<tr><td colspan="20">';
  1145. $s .= '<ul>';
  1146. $s .= '<li><a href="./index.php?m=files&amp;a=addedit_folder&amp;file_folder_parent=' . $row['file_folder_id'] . '&amp;file_folder_id=0">' . w2PshowImage('edit_add.png', '', '', 'new folder', 'add a new subfolder', 'files') . '</a></li>';
  1147. $s .= '<li><a href="./index.php?m=files&amp;a=addedit&amp;folder=' . $row['file_folder_id'] . '&amp;project_id=' . $project_id . '&amp;file_id=0">' . w2PshowImage('folder_new.png', '', '', 'new file', 'add new file to this folder', 'files') . '</a></li>';
  1148. $s .= '<li><a href="./index.php?m=files&amp;a=addedit_folder&amp;folder=' . $row['file_folder_id'] . '">' . w2PshowImage('filesaveas.png', '', '', 'edit icon', 'edit this folder', 'files') . '</a></li>';
  1149. if ($m == 'files') {
  1150. $s .= '<li class="info-text"><a href="./index.php?m=' . $m . '&amp;a=' . $a . '&amp;tab=' . $tab . '&folder=' . $row['file_folder_id'] . '" name="ff' . $row['file_folder_id'] . '">';
  1151. }
  1152. $s .= w2PshowImage('folder5_small.png', '22', '22', '', '', 'files');
  1153. $s .= $row['file_folder_name'];
  1154. if ($m == 'files') {
  1155. $s .= '</a></li>';
  1156. }
  1157. if ($file_count > 0) {
  1158. $s .= '<li class="info-text"><a href="javascript: void(0);" onClick="expand(\'files_' . $row['file_folder_id'] . '\')" class="has-files">(' . $file_count . ' files) +</a></li>';
  1159. }
  1160. $s .= '<form name="frm_remove_folder_' . $row['file_folder_id'] . '" action="?m=files" method="post" accept-charset="utf-8">
  1161. <input type="hidden" name="dosql" value="do_folder_aed" />
  1162. <input type="hidden" name="del" value="1" />
  1163. <input type="hidden" name="file_folder_id" value="' . $row['file_folder_id'] . '" />
  1164. </form>';
  1165. $s .= '</ul>';
  1166. $s .= '<a class="small-delete" href="javascript: void(0);" onclick="if (confirm(\'Are you sure you want to delete this folder?\')) {document.frm_remove_folder_' . $row['file_folder_id'] . '.submit()}">' . w2PshowImage('remove.png', '', '', 'delete icon', 'delete this folder', 'files') . '</a>';
  1167. $s .= '</td></tr>';
  1168. if ($file_count > 0) {
  1169. $s .= '<div class="files-list" id="files_' . $row['file_folder_id'] . '" style="display: none;">';
  1170. $s .= displayFiles($AppUI, $row['file_folder_id'], $task_id, $project_id, $company_id);
  1171. $s .= "</div>";
  1172. }
  1173. }
  1174. }
  1175. return $s;
  1176. }
  1177. // From: modules/files/filefolder.class.php
  1178. function countFiles($folder)
  1179. {
  1180. global $company_id, $allowed_companies;
  1181. global $deny1, $deny2, $project_id, $task_id;
  1182. $q = new w2p_Database_Query();
  1183. $q->addTable('files');
  1184. $q->addQuery('count(files.file_id)');
  1185. $q->addJoin('projects', 'p', 'p.project_id = file_project');
  1186. $q->addJoin('users', 'u', 'u.user_id = file_owner');
  1187. $q->addJoin('tasks', 't', 't.task_id = file_task');
  1188. $q->addJoin('file_folders', 'ff', 'ff.file_folder_id = file_folder');
  1189. $q->addWhere('file_folder = ' . (int) $folder);
  1190. if (count($deny1) > 0) {
  1191. $q->addWhere('file_project NOT IN (' . implode(',', $deny1) . ')');
  1192. }
  1193. if (count($deny2) > 0) {
  1194. $q->addWhere('file_task NOT IN (' . implode(',', $deny2) . ')');
  1195. }
  1196. if ($project_id) {
  1197. $q->addWhere('file_project = ' . (int) $project_id);
  1198. }
  1199. if ($task_id) {
  1200. $q->addWhere('file_task = ' . (int) $task_id);
  1201. }
  1202. if ($company_id) {
  1203. $q->innerJoin('companies', 'co', 'co.company_id = p.project_company');
  1204. $q->addWhere('company_id = ' . (int) $company_id);
  1205. $q->addWhere('company_id IN (' . $allowed_companies . ')');
  1206. }
  1207. $files_in_folder = $q->loadResult();
  1208. $q->clear();
  1209. return $files_in_folder;
  1210. }
  1211. // From: modules/files/filefolder.class.php
  1212. function displayFiles($AppUI, $folder_id, $task_id, $project_id, $company_id)
  1213. {
  1214. global $m, $tab, $xpg_min, $xpg_pagesize, $showProject, $file_types,
  1215. $company_id, $current_uri, $canEdit;
  1216. // SETUP FOR FILE LIST
  1217. $q = new w2p_Database_Query();
  1218. $q->addQuery('f.*, max(f.file_id) as latest_id, count(f.file_version) as file_versions, round(max(file_version), 2) as file_lastversion, file_owner, user_id');
  1219. $q->addQuery('ff.*, max(file_version) as file_version, f.file_date as file_datetime');
  1220. $q->addTable('files', 'f');
  1221. $q->addJoin('file_folders', 'ff', 'ff.file_folder_id = file_folder');
  1222. $q->addJoin('projects', 'p', 'p.project_id = file_project');
  1223. $q->addJoin('tasks', 't', 't.task_id = file_task');
  1224. $q->addJoin('users', 'u', 'u.user_id = file_owner');
  1225. $q->leftJoin('project_departments', 'project_departments', 'p.project_id = project_departments.project_id OR project_departments.project_id IS NULL');
  1226. $q->leftJoin('departments', 'departments', 'departments.dept_id = project_departments.department_id OR dept_id IS NULL');
  1227. //TODO: apply permissions properly
  1228. $project = new CProject();
  1229. $deny1 = $project->getDeniedRecords($AppUI->user_id);
  1230. if (count($deny1) > 0) {
  1231. $q->addWhere('file_project NOT IN (' . implode(',', $deny1) . ')');
  1232. }
  1233. //TODO: apply permissions properly
  1234. $task = new CTask();
  1235. $deny2 = $task->getDeniedRecords($AppUI->user_id);
  1236. if (count($deny2) > 0) {
  1237. $q->addWhere('file_task NOT IN (' . implode(',', $deny2) . ')');
  1238. }
  1239. if ($project_id) {
  1240. $q->addWhere('file_project = ' . (int) $project_id);
  1241. }
  1242. if ($task_id) {
  1243. $q->addWhere('file_task = ' . (int) $task_id);
  1244. }
  1245. if ($company_id) {
  1246. $q->addWhere('project_company = ' . (int) $company_id);
  1247. }
  1248. //$tab = ($m == 'files') ? $tab-1 : -1;
  1249. $temp_tab = ($m == 'files') ? $tab - 1 : -1;
  1250. if (($temp_tab >= 0) and ((count($file_types) - 1) > $temp_tab)) {
  1251. //if ($tab >= 0) {
  1252. $q->addWhere('file_category = ' . (int) $temp_tab);
  1253. }
  1254. $q->setLimit($xpg_pagesize, $xpg_min);
  1255. if ($folder_id > -1) {
  1256. $q->addWhere('file_folder = ' . (int) $folder_id);
  1257. }
  1258. $q->addGroup('file_version_id DESC');
  1259. $q->addOrder('project_name ASC, file_parent ASC, file_id DESC');
  1260. $qv = new w2p_Database_Query();
  1261. $qv->addTable('files');
  1262. $qv->addQuery('file_id, file_version, file_project, file_name, file_task,
  1263. file_description, file_owner, file_size, file_category,
  1264. task_name, file_version_id, file_date as file_datetime, file_checkout, file_co_reason, file_type,
  1265. file_date, cu.user_username as co_user, project_name,
  1266. project_color_identifier, project_owner, u.user_id,
  1267. con.contact_first_name, con.contact_last_name, con.contact_display_name as contact_name,
  1268. co.contact_first_name as co_contact_first_name, co.contact_last_name as co_contact_last_name,
  1269. co.contact_display_name as co_contact_name ');
  1270. $qv->addJoin('projects', 'p', 'p.project_id = file_project');
  1271. $qv->addJoin('users', 'u', 'u.user_id = file_owner');
  1272. $qv->addJoin('contacts', 'con', 'con.contact_id = u.user_contact');
  1273. $qv->addJoin('tasks', 't', 't.task_id = file_task');
  1274. $qv->addJoin('file_folders', 'ff', 'ff.file_folder_id = file_folder');
  1275. if ($project_id) {
  1276. $qv->addWhere('file_project = ' . (int) $project_id);
  1277. }
  1278. if ($task_id) {
  1279. $qv->addWhere('fil…

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