/includes/cleanup_functions.php
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
- <?php
- /**
- * This file exists in order to list individual functions which need to be
- * cleaned up, reorganized or eliminated based on usage. Before you touch
- * these, please ensure there are Unit Tests to validate that things work
- * before and after.
- * @todo/TODO: Every single function in this file.
- *
- * WARNING: The functions in this file are likely to move to other files as they
- * are updated. Since this file is included within main_functions.php
- * this shouldn't be a problem.
- */
- function is_task_in_gantt_arr($task)
- {
- global $gantt_arr;
- $n = count($gantt_arr);
- for ($x = 0; $x < $n; $x++) {
- if ($gantt_arr[$x][0]['task_id'] == $task['task_id']) {
- return true;
- }
- }
- return false;
- }
- function notifyHR($address, $notUsed, $uaddress, $uusername, $logname, $notUsed2, $userid)
- {
- global $AppUI;
- $emailManager = new w2p_Output_EmailManager($AppUI);
- $body = $emailManager->notifyHR($uusername, $logname, $uaddress, $userid);
- $mail = new w2p_Utilities_Mail();
- $mail->To($address);
- $mail->Subject('New External User Created');
- $mail->Body($body);
- return $mail->Send();
- }
- function notifyNewUserCredentials($address, $username, $logname, $logpwd)
- {
- global $AppUI;
- $emailManager = new w2p_Output_EmailManager($AppUI);
- $body = $emailManager->notifyNewUserCredentials($username, $logname, $logpwd);
- $mail = new w2p_Utilities_Mail();
- $mail->To($address);
- $mail->Subject('New Account Created - web2Project Project Management System');
- $mail->Body($body);
- return $mail->Send();
- }
- function clean_value($str)
- {
- $bad_values = array("'");
- return str_replace($bad_values, '', $str);
- }
- function strUTF8Decode($text)
- {
- if (extension_loaded('mbstring')) {
- $encoding = mb_detect_encoding($text.' ');
- }
- if (function_exists('iconv')) {
- $text = mb_convert_encoding($text, 'UTF-8', $encoding);
- //iconv($encoding, 'UTF-8', $text);
- } elseif (function_exists('utf8_decode')) {
- $text = utf8_decode($text);
- }
- // mb functions don't seam to work well here for some reason as the output gets corrupted.
- // iconv is doing the job just fine though
- return $text;
- }
- /**
- * utility functions for the preparation of task data for GANTT PDF
- *
- * @todo some of these functions are not needed, need to trim this down
- *
- */
- // PYS : utf_8 decoding as suggested in Vbulletin #3987
- function strEzPdf($text)
- {
- if (function_exists('iconv') && function_exists('mb_detect_encoding')) {
- $text = iconv(mb_detect_encoding($text." "), 'UTF-8', $text);
- }
- return $text;
- }
- function dumb_slice( $gantt_arr, $length = 25 )
- {
- $sliced_array = array();
- $pages = (int) count($gantt_arr) / $length;
- for ( $i = 0; $i <= $pages; $i++ ) {
- $sliced_array[] = array_slice($gantt_arr, $i * $length, $length);
- }
- return $sliced_array;
- }
- /**
- *
- * END OF GANTT PDF UTILITY FUNCTIONS
- *
- */
- /**
- * This is a kludgy mess because of how the arraySelectTree function is used..
- * it expects - nay, demands! - that the first element of the subarray is the
- * id and the third is the parent id. In most cases, that is fine.. in this
- * one we're using the existing ACL-respecting functions and it has additional
- * fields in "improper" places.
- */
- function temp_filterArrayForSelectTree($projectData)
- {
- unset($projectData['project_id']);
- unset($projectData['project_color_identifier']);
- unset($projectData['project_name']);
- unset($projectData['project_start_date']);
- unset($projectData['project_end_date']);
- unset($projectData['project_company']);
- unset($projectData['project_parent']);
- unset($projectData[1]);
- unset($projectData[3]);
- unset($projectData[4]);
- unset($projectData[5]);
- $projectData[6] = ($projectData[0] == $projectData[6]) ? '' : $projectData[6];
- return array_values($projectData);
- }
- function getReadableModule()
- {
- $q = new w2p_Database_Query;
- $q->addTable('modules');
- $q->addQuery('mod_directory');
- $q->addWhere('mod_active = 1');
- $q->addOrder('mod_ui_order');
- $modules = $q->loadColumn();
- foreach ($modules as $mod) {
- if (canAccess($mod)) {
- return $mod;
- }
- }
- return null;
- }
- /**
- * This function is used to check permissions.
- */
- function checkFlag($flag, $perm_type, $old_flag)
- {
- if ($old_flag) {
- return (($flag == PERM_DENY) || // permission denied
- ($perm_type == PERM_EDIT && $flag == PERM_READ) // we ask for editing, but are only allowed to read
- ) ? 0 : 1;
- } else {
- if ($perm_type == PERM_READ) {
- return ($flag != PERM_DENY) ? 1 : 0;
- } else {
- // => $perm_type == PERM_EDIT
- return ($flag == $perm_type) ? 1 : 0;
- }
- }
- }
- /**
- * This function checks certain permissions for
- * a given module and optionally an item_id.
- *
- * $perm_type can be PERM_READ or PERM_EDIT
- */
- function isAllowed($perm_type, $mod, $item_id = 0)
- {
- $invert = false;
- switch ($perm_type) {
- case PERM_READ:
- $perm_type = 'view';
- break;
- case PERM_EDIT:
- $perm_type = 'edit';
- break;
- case PERM_ALL:
- $perm_type = 'edit';
- break;
- case PERM_DENY:
- $perm_type = 'view';
- $invert = true;
- break;
- }
- $allowed = getPermission($mod, $perm_type, $item_id);
- if ($invert) {
- return !$allowed;
- }
- return $allowed;
- }
- function getPermission($mod, $perm, $item_id = 0)
- {
- // First check if the module is readable, i.e. has view permission.
- $perms = &$GLOBALS['AppUI']->acl();
- $result = $perms->checkModule($mod, $perm);
- // If we have access then we need to ensure we are not denied access to the particular
- // item.
- if ($result && $item_id) {
- if ($perms->checkModuleItemDenied($mod, $perm, $item_id)) {
- $result = false;
- }
- }
- // If denied we need to check if we are allowed the task. This can be done
- // a lot better in PHPGACL, but is here for compatibility.
- if ($mod == 'tasks' && !$result && $item_id > 0) {
- $q = new w2p_Database_Query;
- $q->addTable('tasks');
- $q->addQuery('task_project');
- $q->addWhere('task_id = ' . (int) $item_id);
- $project_id = $q->loadResult();
- $result = getPermission('projects', $perm, $project_id);
- }
- return $result;
- }
- function canView($mod, $item_id = 0)
- {
- return getPermission($mod, 'view', $item_id);
- }
- function canEdit($mod, $item_id = 0)
- {
- return getPermission($mod, 'edit', $item_id);
- }
- function canAdd($mod, $item_id = 0)
- {
- return getPermission($mod, 'add', $item_id);
- }
- function canDelete($mod, $item_id = 0)
- {
- return getPermission($mod, 'delete', $item_id);
- }
- function canAccess($mod)
- {
- return getPermission($mod, 'access');
- }
- function buildTaskTree($task_data, $depth = 0, $projTasks, $all_tasks, $parents, $task_parent, $task_id)
- {
- $output = '';
- $projTasks[$task_data['task_id']] = $task_data['task_name'];
- $task_data['task_name'] = mb_strlen($task_data['task_name']) > 45 ? mb_substr($task_data['task_name'], 0, 45) . '...' : $task_data['task_name'];
- $selected = $task_data['task_id'] == $task_parent ? ' selected="selected"' : '';
- $output .= '<option value="' . $task_data['task_id'] . '"' . $selected . '>' . str_repeat(' ', $depth * 3) . w2PFormSafe($task_data['task_name']) . '</option>';
- if (isset($parents[$task_data['task_id']])) {
- foreach ($parents[$task_data['task_id']] as $child_task) {
- if ($child_task != $task_id) {
- $output .= buildTaskTree($all_tasks[$child_task], ($depth + 1), $projTasks, $all_tasks, $parents, $task_parent, $task_id);
- }
- }
- }
- return $output;
- }
- // from modules/tasks/addedit.php and modules/projectdesigners/vw_actions.php
- function build_date_list(&$date_array, $row)
- {
- global $project;
- // if this task_dynamic is not tracked, set end date to proj start date
- if (!in_array($row['task_dynamic'], CTask::$tracked_dynamics)) {
- $date = new w2p_Utilities_Date($project->project_start_date);
- } elseif ($row['task_milestone'] == 0) {
- $date = new w2p_Utilities_Date($row['task_end_date']);
- } else {
- $date = new w2p_Utilities_Date($row['task_start_date']);
- }
- $sdate = $date->format('%d/%m/%Y');
- $shour = $date->format('%H');
- $smin = $date->format('%M');
- $date_array[$row['task_id']] = array($row['task_name'], $sdate, $shour, $smin);
- }
- // from modules/tasks/ae_dates.php
- function cal_work_day_conv($val)
- {
- global $locale_char_set, $AppUI;
- setlocale(LC_TIME, 'en');
- $wk = Date_Calc::getCalendarWeek(null, null, null, '%a', LOCALE_FIRST_DAY);
- setlocale(LC_ALL, $AppUI->user_lang);
- $day_name = $AppUI->_($wk[($val - LOCALE_FIRST_DAY) % 7]);
- $day_name = utf8_encode($day_name);
- return htmlspecialchars($day_name, ENT_COMPAT, $locale_char_set);
- }
- function __extract_from_showtask(&$arr, $level, $today_view, $listTable, $fields = array())
- {
- return '';
- }
- /**
- * @param $arr
- * @param $level
- * @param $today_view
- * @param $s
- * @param $m
- * @param $jsTaskId
- * @param $expanded
- * @return array
- */
- function __extract_from_showtask2($arr, $level, $today_view, $s, $m, $jsTaskId, $expanded)
- {
- $s .= '<td style="width: ' . (($today_view) ? '50%' : '90%') . '" class="data _name">';
- //level
- if ($level == -1) {
- $s .= '...';
- }
- for ($y = 0; $y < $level; $y++) {
- if ($y + 1 == $level) {
- $image = w2PfindImage('corner-dots.gif', $m);
- } else {
- $image = w2PfindImage('shim.gif', $m);
- }
- $s .= '<img src="' . $image . '" width="16" height="12" border="0" alt=""/>';
- }
- if ($arr['task_description'] && !$arr['task_milestone']) {
- $s .= w2PtoolTip('Task Description', substr($arr['task_description'], 0, 1000), true);
- }
- if (isset($arr['task_nr_of_children']) && $arr['task_nr_of_children']) {
- $is_parent = true;
- } else {
- $is_parent = false;
- }
- if ($arr['task_milestone'] > 0) {
- $s .= ' <a href="./index.php?m=tasks&a=view&task_id=' . $arr['task_id'] . '" ><b>' . $arr['task_name'] . '</b></a> <img src="' . w2PfindImage('icons/milestone.gif') . '" />';
- } elseif ($arr['task_dynamic'] == '1' || $is_parent) {
- $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>';
- $s .= $open_link;
- if ($arr['task_dynamic'] == '1') {
- $s .= ' <a href="./index.php?m=tasks&a=view&task_id=' . $arr['task_id'] . '" ><b><i>' . $arr['task_name'] . '</i></b></a>';
- } else {
- $s .= ' <a href="./index.php?m=tasks&a=view&task_id=' . $arr['task_id'] . '" >' . $arr['task_name'] . '</a>';
- }
- } else {
- $s .= ' <a href="./index.php?m=tasks&a=view&task_id=' . $arr['task_id'] . '" >' . $arr['task_name'] . '</a>';
- }
- if ($arr['task_description'] && !$arr['task_milestone']) {
- $s .= w2PendTip();
- }
- $s .= '</td>';
- return $s;
- }
- function showtask_new(&$arr, $level = 0, $today_view = false, $listTable = null, $fields = array())
- {
- return __extract_from_showtask($arr, $level, $today_view, $listTable, $fields);
- }
- /*
- * gantt_arr [ project_id ] [ 0 ] is a task "object" : task['task_id'], task['task_access'], task['task_owner'], task['task_name'], task['project_name']
- * task['task_start_date'], task['task_end_date'], task['task_percent_complete'], ['task_milestone']
- * gantt_arr [ project_id ] [ 1 ] is the level
- *
- * project_id is "optional": a 0 value means we re not handling projects
- *
- * adds a bidimensional array:
- * -1st level: composed of integer project_id
- * -2nd level: composed of an array of two items: task "object", integer level
- */
- function showgtask(&$a, $level = 0, $notUsed = 0)
- {
- /* Add tasks to gantt chart */
- global $gantt_arr;
- if (!is_task_in_gantt_arr($a)) {
- $gantt_arr[] = array($a, $level);
- }
- }
- function findchild_new(&$tarr, $parent, $level = 0)
- {
- global $shown_tasks;
- $level++;
- $n = count($tarr);
- for ($x = 0; $x < $n; $x++) {
- if ($tarr[$x]['task_parent'] == $parent && $tarr[$x]['task_parent'] != $tarr[$x]['task_id']) {
- echo showtask_new($tarr[$x], $level, true);
- $shown_tasks[$tarr[$x]['task_id']] = $tarr[$x]['task_id'];
- findchild_new($tarr, $tarr[$x]['task_id'], $level);
- }
- }
- }
- function findchild_gantt(&$tarr, $parent, $level = 0)
- {
- $level++;
- $n = count($tarr);
- for ($x = 0; $x < $n; $x++) {
- if ($tarr[$x]['task_parent'] == $parent && $tarr[$x]['task_parent'] != $tarr[$x]['task_id']) {
- showgtask($tarr[$x], $level, $tarr[$x]['project_id']);
- findchild_gantt($tarr, $tarr[$x]['task_id'], $level);
- }
- }
- }
- // from modules/tasks/tasks.class.php
- function array_csort() { //coded by Ichier2003
- $args = func_get_args();
- $marray = array_shift($args);
- if (empty($marray)) {
- return array();
- }
- $i = 0;
- $msortline = 'return(array_multisort(';
- $sortarr = array();
- foreach ($args as $arg) {
- $i++;
- if (is_string($arg)) {
- for ($j = 0, $j_cmp = count($marray); $j < $j_cmp; $j++) {
- /* we have to calculate the end_date via start_date+duration for
- ** end='0000-00-00 00:00:00' before sorting, see mantis #1509:
- ** Task definition writes the following to the DB:
- ** A without start date: start = end = NULL
- ** B with start date and empty end date: start = startdate,
- end = '0000-00-00 00:00:00'
- ** C start + end date: start= startdate, end = end date
- ** A the end_date for the middle task (B) is ('dynamically') calculated on display
- ** via start_date+duration, it may be that the order gets wrong due to the fact
- ** that sorting has taken place _before_.
- */
- if ($marray[$j]['task_end_date'] == '0000-00-00 00:00:00') {
- $marray[$j]['task_end_date'] = calcEndByStartAndDuration($marray[$j]);
- }
- if ('' == $arg) { continue; }
- $sortarr[$i][] = $marray[$j][$arg];
- }
- } else {
- $sortarr[$i] = $arg;
- }
- if (!is_array($sortarr[$i])) {
- continue;
- }
- $msortline .= '$sortarr[' . $i . '],';
- }
- $msortline .= '$marray));';
- eval($msortline);
- return $marray;
- }
- // from modules/tasks/tasks.class.php
- /*
- ** Calc End Date via Startdate + Duration
- ** @param array task A DB row from the earlier fetched tasklist
- ** @return string Return calculated end date in MySQL-TIMESTAMP format
- */
- function calcEndByStartAndDuration($task)
- {
- $end_date = new w2p_Utilities_Date($task['task_start_date']);
- $end_date->addSeconds($task['task_duration'] * $task['task_duration_type'] * 3600);
- return $end_date->format(FMT_DATETIME_MYSQL);
- }
- // from modules/tasks/tasks.class.php
- function sort_by_item_title($title, $item_name, $item_type, $a = '')
- {
- global $AppUI, $project_id, $task_id, $m;
- global $task_sort_item1, $task_sort_type1, $task_sort_order1;
- global $task_sort_item2, $task_sort_type2, $task_sort_order2;
- if ($task_sort_item2 == $item_name) {
- $item_order = $task_sort_order2;
- }
- if ($task_sort_item1 == $item_name) {
- $item_order = $task_sort_order1;
- }
- $s = '';
- if (isset($item_order)) {
- $show_icon = true;
- } else {
- $show_icon = false;
- $item_order = SORT_DESC;
- }
- /* flip the sort order for the link */
- $item_order = ($item_order == SORT_ASC) ? SORT_DESC : SORT_ASC;
- if ($m == 'tasks') {
- $s .= '<a href="./index.php?m=tasks' . (($task_id > 0) ? ('&a=view&task_id=' . $task_id) : $a);
- } elseif ($m == 'calendar') {
- $s .= '<a href="./index.php?m=events&a=day_view';
- } else {
- $s .= '<a href="./index.php?m=projects&bypass=1' . (($project_id > 0) ? ('&a=view&project_id=' . $project_id) : '');
- }
- $s .= '&task_sort_item1=' . $item_name;
- $s .= '&task_sort_type1=' . $item_type;
- $s .= '&task_sort_order1=' . $item_order;
- if ($task_sort_item1 == $item_name) {
- $s .= '&task_sort_item2=' . $task_sort_item2;
- $s .= '&task_sort_type2=' . $task_sort_type2;
- $s .= '&task_sort_order2=' . $task_sort_order2;
- } else {
- $s .= '&task_sort_item2=' . $task_sort_item1;
- $s .= '&task_sort_type2=' . $task_sort_type1;
- $s .= '&task_sort_order2=' . $task_sort_order1;
- }
- $s .= '" class="hdr">' . $AppUI->_($title);
- if ($show_icon) {
- $s .= ' <img src="' . w2PfindImage('arrow-' . (($item_order == SORT_ASC) ? 'up' : 'down') . '.gif') . '" />';
- }
- return $s.'</a>';
- }
- // from modules/tasks/tasksperuser_sub.php
- function doChildren($list, $N, $id, $uid, $level, $maxlevels, $display_week_hours, $ss, $se)
- {
- $tmp = '';
- if ($maxlevels == -1 || $level < $maxlevels) {
- for ($c = 0; $c < $N; $c++) {
- $task = $list[$c];
- if (($task->task_parent == $id) and isChildTask($task)) {
- // we have a child, do we have the user as a member?
- if (isMemberOfTask($list, $N, $uid, $task)) {
- $tmp .= displayTask($list, $task, $level, $display_week_hours, $ss, $se, $uid);
- $tmp .= doChildren($list, $N, $task->task_id, $uid, $level++, $maxlevels, $display_week_hours, $ss, $se);
- }
- }
- }
- }
- return $tmp;
- }
- // from modules/reports/tasksperuser.php
- function doChildren_r($list, $Lusers, $N, $id, $uid, $level, $maxlevels, $display_week_hours, $ss, $se, $log_all_projects = false)
- {
- $tmp = "";
- if ($maxlevels == -1 || $level < $maxlevels) {
- for ($c = 0; $c < $N; $c++) {
- $task = $list[$c];
- if (($task->task_parent == $id) and isChildTask($task)) {
- // we have a child, do we have the user as a member?
- if (isMemberOfTask_r($list, $Lusers, $N, $uid, $task)) {
- $tmp .= displayTask_r($list, $task, $level, $display_week_hours, $ss, $se, $log_all_projects, $uid);
- $tmp .= doChildren_r($list, $Lusers, $N, $task->task_id, $uid, $level++, $maxlevels, $display_week_hours, $ss, $se, $log_all_projects);
- }
- }
- }
- }
- return $tmp;
- }
- // from modules/tasks/tasksperuser_sub.php
- function isMemberOfTask($notUsed, $notUsed2, $user_id, $task)
- {
- global $user_assigned_tasks;
- if (isset($user_assigned_tasks[$user_id])) {
- if (in_array($task->task_id, $user_assigned_tasks[$user_id])) {
- return true;
- }
- }
- return false;
- }
- // from modules/reports/tasksperuser.php
- function isMemberOfTask_r($list, $Lusers, $N, $user_id, $task)
- {
- for ($i = 0; $i < $N && $list[$i]->task_id != $task->task_id; $i++)
- ;
- $users = $Lusers[$i];
- foreach ($users as $task_user_id => $notUsed) {
- if ($task_user_id == $user_id) {
- return true;
- }
- }
- // check child tasks if any
- for ($c = 0; $c < $N; $c++) {
- $ntask = $list[$c];
- if (($ntask->task_parent == $task->task_id) and isChildTask($ntask)) {
- // we have a child task
- if (isMemberOfTask_r($list, $Lusers, $N, $user_id, $ntask)) {
- return true;
- }
- }
- }
- return false;
- }
- // from modules/tasks/tasksperuser_sub.php
- function displayTask($list, $task, $level, $display_week_hours, $fromPeriod, $toPeriod, $user_id)
- {
- global $AppUI, $durnTypes, $active_users, $zi, $projects;
- //if the user has no permission to the project don't show the tasks
- if (!(key_exists($task->task_project, $projects))) {
- return;
- }
- $htmlHelper = new w2p_Output_HTMLHelper($AppUI);
- $zi++;
- $users = $task->task_assigned_users;
- $task->userPriority = $task->getUserSpecificTaskPriority($user_id);
- $project = $task->getProject();
- $tmp = '<tr>';
- $tmp .= '<td align="center" nowrap="nowrap">';
- $tmp .= '<input type="checkbox" name="selected_task[' . $task->task_id . ']" value="' . $task->task_id . '" />';
- $tmp .= '</td>';
- $tmp .= $htmlHelper->createCell('user_priority', $task->userPriority);
- $tmp .= '<td class="_name">';
- for ($i = 0; $i < $level; $i++) {
- $tmp .= ' ';
- }
- if ($task->task_milestone == true) {
- $tmp .= '<b>';
- }
- if ($level >= 1) {
- $tmp .= '<img src="' . w2PfindImage('corner-dots.gif') . '" width="16" height="12" alt="" style="float: left;">';
- }
- $tmp .= '<a href="?m=tasks&a=view&task_id=' . $task->task_id . '">' . $task->task_name . '</a>';
- if ($task->task_milestone == true) {
- $tmp .= '</b>';
- }
- if ($task->task_priority < 0) {
- $tmp .= ' (<img src="' . w2PfindImage('icons/priority-' . -$task->task_priority . '.gif') . '" width="13" height="16" alt="" />)';
- } elseif ($task->task_priority > 0) {
- $tmp .= ' (<img src="' . w2PfindImage('icons/priority+' . $task->task_priority . '.gif') . '" width="13" height="16" alt="" />)';
- }
- $tmp .= '</td>';
- $tmp .= '<td align="left">';
- $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>';
- $tmp .= '</td>';
- $tmp .= $htmlHelper->createCell('task_duration', $task->task_duration . ' ' . mb_substr($AppUI->_($durnTypes[$task->task_duration_type]), 0, 1));
- $tmp .= $htmlHelper->createCell('task_start_date', $task->task_start_date);
- $tmp .= $htmlHelper->createCell('task_end_date', $task->task_end_date);
- if ($display_week_hours) {
- $tmp .= displayWeeks($list, $task, $level, $fromPeriod, $toPeriod);
- }
- $tmp .= '<td>';
- $sep = $us = '';
- foreach ($users as $notUsed => $row) {
- if ($row['user_id']) {
- $us .= '<a href="?m=users&a=view&user_id=' . $row[0] . '">' . $sep . $row['contact_name'] . ' (' . $row['perc_assignment'] . '%)</a>';
- $sep = ', ';
- }
- }
- $tmp .= $us;
- $tmp .= '</td>';
- // create the list of possible assignees
- $size = (count($active_users) > 5) ? 5 : 3;
- $tmp .= '<td valign="top" align="center" nowrap="nowrap">';
- $tmp .= '<select name="add_users" style="width:200px" size="'.$size.'" class="text" multiple="multiple" ondblclick="javascript:chAssignment(' . $user_id . ', 0, false)">';
- foreach ($active_users as $id => $name) {
- $tmp .= '<option value="' . $id . '">' . $name . '</option>';
- }
- $tmp .= '</select>';
- $tmp .= '</td>';
- $tmp .= '</tr>';
- return $tmp;
- }
- // from modules/reports/tasksperuser.php
- function displayTask_r($list, $task, $level, $display_week_hours, $fromPeriod, $toPeriod, $log_all_projects = false, $user_id = 0)
- {
- global $AppUI;
- $htmlHelper = new w2p_Output_HTMLHelper($AppUI);
- $tmp = '';
- $tmp .= '<tr><td align="left" nowrap="nowrap">   ';
- for ($i = 0; $i < $level; $i++) {
- $tmp .= '   ';
- }
- if ($level == 0) {
- $tmp .= '<b>';
- } elseif ($level == 1) {
- $tmp .= '<i>';
- }
- $tmp .= $task->task_name;
- if ($level == 0) {
- $tmp .= '</b>';
- } elseif ($level == 1) {
- $tmp .= '</i>';
- }
- $tmp .= '   </td>';
- if ($log_all_projects) {
- //Show project name when we are logging all projects
- $project = $task->getProject();
- $tmp .= '<td nowrap="nowrap">';
- if (!isChildTask($task)) {
- //However only show the name on parent tasks and not the children to make it a bit cleaner
- $tmp .= $project['project_name'];
- }
- $tmp .= '</td>';
- }
- $tmp .= $htmlHelper->createCell('task_start_date', $task->task_start_date);
- $tmp .= $htmlHelper->createCell('task_end_date', $task->task_end_date);
- if ($display_week_hours) {
- $tmp .= displayWeeks_r($list, $task, $level, $fromPeriod, $toPeriod, $user_id);
- }
- $tmp .= "</tr>\n";
- return $tmp;
- }
- // from modules/tasks/tasksperuser_sub.php
- function isChildTask($task)
- {
- return $task->task_id != $task->task_parent;
- }
- // from modules/tasks/tasksperuser_sub.php
- function weekDates($display_allocated_hours, $fromPeriod, $toPeriod)
- {
- if ($fromPeriod == -1) {
- return '';
- }
- if (!$display_allocated_hours) {
- return '';
- }
- $s = new w2p_Utilities_Date($fromPeriod);
- $e = new w2p_Utilities_Date($toPeriod);
- $sw = getBeginWeek($s);
- $dw = ceil($e->dateDiff($s) / 7);
- $ew = $sw + $dw;
- $row = '';
- for ($i = $sw; $i <= $ew; $i++) {
- $wn = $s->getWeekofYear() % 52;
- $wn = ($wn != 0) ? $wn : 52;
- $row .= '<th title="' . $s->getYear() . '" nowrap="nowrap">' . $wn . '</th>';
- $s->addSeconds(168 * 3600); // + one week
- }
- return $row;
- }
- // from modules/reports/tasksperuser.php
- function weekDates_r($display_allocated_hours, $fromPeriod, $toPeriod)
- {
- global $AppUI;
- if ($fromPeriod == -1) {
- return '';
- }
- if (!$display_allocated_hours) {
- return '';
- }
- $s = new w2p_Utilities_Date($fromPeriod);
- $e = new w2p_Utilities_Date($toPeriod);
- $sw = getBeginWeek($s);
- $ew = getEndWeek($e);
- $row = '';
- for ($i = $sw; $i <= $ew; $i++) {
- $sdf = substr($AppUI->getPref('SHDATEFORMAT'), 3);
- $row .= '<td nowrap="nowrap" bgcolor="#A0A0A0"><font color="black"><b>' . $s->format($sdf) . '</b></font></td>';
- $s->addSeconds(168 * 3600); // + one week
- }
- return $row;
- }
- // from modules/tasks/tasksperuser_sub.php
- function weekCells($display_allocated_hours, $fromPeriod, $toPeriod)
- {
- if ($fromPeriod == -1) {
- return 0;
- }
- if (!$display_allocated_hours) {
- return 0;
- }
- $s = new w2p_Utilities_Date($fromPeriod);
- $e = new w2p_Utilities_Date($toPeriod);
- $sw = getBeginWeek($s);
- $dw = ceil($e->dateDiff($s) / 7);
- $ew = $sw + $dw;
- return $ew - $sw + 1;
- }
- // from modules/reports/tasksperuser.php
- function weekCells_r($display_allocated_hours, $fromPeriod, $toPeriod)
- {
- if ($fromPeriod == -1) {
- return 0;
- }
- if (!$display_allocated_hours) {
- return 0;
- }
- $s = new w2p_Utilities_Date($fromPeriod);
- $e = new w2p_Utilities_Date($toPeriod);
- $sw = getBeginWeek($s);
- $ew = getEndWeek($e);
- return $ew - $sw + 1;
- }
- // from modules/tasks/tasksperuser_sub.php
- // Look for a user when he/she has been allocated
- // to this task and when. Report this in weeks
- // This function is called within 'displayTask()'
- function displayWeeks($list, $task, $level, $fromPeriod, $toPeriod)
- {
- if ($fromPeriod == -1) {
- return '';
- }
- $s = new w2p_Utilities_Date($fromPeriod);
- $e = new w2p_Utilities_Date($toPeriod);
- $sw = getBeginWeek($s);
- $dw = ceil($e->dateDiff($s) / 7);
- $ew = $sw + $dw;
- $st = new w2p_Utilities_Date($task->task_start_date);
- $et = new w2p_Utilities_Date($task->task_end_date);
- $stw = getBeginWeek($st);
- $dtw = ceil($et->dateDiff($st) / 7);
- $etw = $stw + $dtw;
- $row = '';
- for ($i = $sw; $i <= $ew; $i++) {
- if ($i >= $stw and $i < $etw) {
- $color = 'blue';
- if ($level == 0 and hasChildren($list, $task)) {
- $color = '#C0C0FF';
- } elseif ($level == 1 and hasChildren($list, $task)) {
- $color = '#9090FF';
- }
- $row .= '<td nowrap="nowrap" bgcolor="' . $color . '">';
- } else {
- $row .= '<td nowrap="nowrap">';
- }
- $row .= '  </td>';
- }
- return $row;
- }
- // Look for a user when he/she has been allocated
- // to this task and when. Report this in weeks
- // This function is called within 'displayTask_r()'
- // from modules/reports/tasksperuser.php
- function displayWeeks_r($list, $task, $level, $fromPeriod, $toPeriod, $user_id = 0)
- {
- if ($fromPeriod == -1) {
- return '';
- }
- $s = new w2p_Utilities_Date($fromPeriod);
- $e = new w2p_Utilities_Date($toPeriod);
- $sw = getBeginWeek($s);
- $ew = getEndWeek($e);
- $st = new w2p_Utilities_Date($task->task_start_date);
- $et = new w2p_Utilities_Date($task->task_end_date);
- $stw = getBeginWeek($st);
- $etw = getEndWeek($et);
- $row = '';
- for ($i = $sw; $i <= $ew; $i++) {
- $assignment = '';
- if ($i >= $stw and $i < $etw) {
- $color = '#0000FF';
- if ($level == 0 and hasChildren($list, $task)) {
- $color = '#C0C0FF';
- } elseif ($level == 1 and hasChildren($list, $task)) {
- $color = '#9090FF';
- }
- if ($user_id) {
- $users = $task->getAssignedUsers($task->task_id);
- $assignment = ($users[$user_id]['perc_assignment']) ? $users[$user_id]['perc_assignment'].'%' : '';
- }
- } else {
- $color = '#FFFFFF';
- }
- $row .= '<td bgcolor="' . $color . '" class="center">';
- $row .= '<font color="'.bestColor($color).'">';
- $row .= $assignment;
- $row .= '</font>';
- $row .= '</td>';
- }
- return $row;
- }
- // from modules/tasks/tasksperuser_sub.php
- // from modules/reports/tasksperuser.php
- function getBeginWeek($d)
- {
- $dn = (int) $d->Format('%w');
- $dd = new w2p_Utilities_Date($d);
- $dd->subtractSeconds($dn * 24 * 3600);
- return (int) $dd->Format('%U');
- }
- // from modules/tasks/tasksperuser_sub.php
- // from modules/reports/tasksperuser.php
- function getEndWeek($d)
- {
- $dn = (int) $d->Format('%w');
- if ($dn > 0) {
- $dn = 7 - $dn;
- }
- $dd = new w2p_Utilities_Date($d);
- $dd->addSeconds($dn * 24 * 3600);
- return (int) $dd->Format('%U');
- }
- // from modules/tasks/tasksperuser_sub.php
- // from modules/reports/tasksperuser.php
- function hasChildren($list, $task)
- {
- foreach ($list as $t) {
- if ($t->task_parent == $task->task_id) {
- return true;
- }
- }
- return false;
- }
- // from modules/tasks/tasksperuser_sub.php
- function getOrphanedTasks($tval)
- {
- return (sizeof($tval->task_assigned_users) > 0) ? null : $tval;
- }
- // from modules/tasks/viewgantt.php
- function showfiltertask(&$a, $level=0)
- {
- /* Add tasks to the filter task aray */
- global $filter_task_list, $parents;
- $filter_task_list[] = array($a, $level);
- $parents[$a['task_parent']] = true;
- }
- // from modules/tasks/viewgantt.php
- function findfiltertaskchild(&$tarr, $parent, $level=0)
- {
- $level++;
- $n = count($tarr);
- for ($x=0; $x < $n; $x++) {
- if ($tarr[$x]['task_parent'] == $parent && $tarr[$x]['task_parent'] != $tarr[$x]['task_id']) {
- showfiltertask($tarr[$x], $level);
- findfiltertaskchild($tarr, $tarr[$x]['task_id'], $level);
- }
- }
- }
- // from modules/system/roles/roles.class.php
- function showRoleRow($role = null)
- {
- global $canEdit, $canDelete, $role_id, $AppUI, $roles;
- $id = $role['id'];
- $name = $role['value'];
- $description = $role['name'];
- if (!$id) {
- $roles_arr = array(0 => '(' . $AppUI->_('Copy Role') . '...)');
- foreach ($roles as $role) {
- $roles_arr[$role['id']] = $role['name'];
- }
- }
- $s = '';
- if (($role_id == $id || $id == 0) && $canEdit) {
- // edit form
- $s .= '<form name="roleFrm" method="post" action="?m=system&u=roles" accept-charset="utf-8">';
- $s .= '<input type="hidden" name="dosql" value="do_role_aed" />';
- $s .= '<input type="hidden" name="del" value="0" />';
- $s .= '<input type="hidden" name="role_id" value="' . $id . '" />';
- $s .= '<tr><td> </td>';
- $s .= '<td valign="top"><input type="text" size="20" name="role_name" value="' . $name . '" class="text" /></td>';
- $s .= '<td valign="top"><input type="text" size="50" name="role_description" class="text" value="' . $description . '">' . ($id ? '' : ' ' . arraySelect($roles_arr, 'copy_role_id', 'class="text"', 0, true));
- $s .= '<input type="submit" value="' . $AppUI->_($id ? 'save' : 'add') . '" class="button btn btn-primary btn-mini right" /></td>';
- } else {
- $s .= '<tr><td width="50" valign="top">';
- if ($canEdit) {
- $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>';
- }
- if ($canDelete && strpos($name, 'admin') === false) {
- $s .= '<a href=\'javascript:delIt(' . $id . ')\'>' . w2PshowImage('icons/stock_delete-16.png') . '</a>';
- }
- $s .= '</td><td valign="top">' . $name . '</td><td valign="top">' . $AppUI->_($description) . '</td>';
- }
- $s .= '</tr>';
- return $s;
- }
- // from modules/system/syskeys/syskeys.class.php
- function parseFormatSysval($text, $syskey)
- {
- $q = new w2p_Database_Query;
- $q->addTable('syskeys');
- $q->addQuery('syskey_type, syskey_sep1, syskey_sep2');
- $q->addWhere('syskey_id = ' . (int) $syskey);
- $q->exec();
- $row = $q->fetchRow();
- $q->clear();
- // type 0 = list
- $sep1 = $row['syskey_sep1']; // item separator
- $sep2 = $row['syskey_sep2']; // alias separator
- // A bit of magic to handle newlines and returns as separators
- // Missing sep1 is treated as a newline.
- if (!isset($sep1) || empty($sep1)) {
- $sep1 = "\n";
- }
- if ($sep1 == "\\n") {
- $sep1 = "\n";
- }
- if ($sep1 == "\\r") {
- $sep1 = "\r";
- }
- $temp = explode($sep1, $text);
- $arr = array();
- // We use trim() to make sure a numeric that has spaces
- // is properly treated as a numeric
- foreach ($temp as $item) {
- if ($item) {
- $sep2 = empty($sep2) ? "\n" : $sep2;
- $temp2 = explode($sep2, $item);
- if (isset($temp2[1])) {
- $arr[mb_trim($temp2[0])] = mb_trim($temp2[1]);
- } else {
- $arr[mb_trim($temp2[0])] = mb_trim($temp2[0]);
- }
- }
- }
- return $arr;
- }
- // from modules/system/billingcode.php
- function showcodes(&$a)
- {
- global $AppUI, $company_id;
- $s = '
- <tr>
- <td width=40>
- <a href="?m=system&a=billingcode&company_id=' . $company_id . '&billingcode_id=' . $a['billingcode_id'] . '" title="' . $AppUI->_('edit') . '">
- <img src="' . w2PfindImage('icons/stock_edit-16.png') . '" alt="Edit" /></a>';
- if ($a['billingcode_status'] == 0)
- $s .= '<a href="javascript:delIt2(' . $a['billingcode_id'] . ');" title="' . $AppUI->_('delete') . '">
- <img src="' . w2PfindImage('icons/stock_delete-16.png') . '" alt="Delete" /></a>';
- $s .= '
- </td>
- <td align="left"> ' . $a['billingcode_name'] . ($a['billingcode_status'] == 1 ? ' (deleted)' : '') . '</td>
- <td nowrap="nowrap" align="center">' . $a['billingcode_value'] . '</td>
- <td nowrap="nowrap">' . $a['billingcode_desc'] . '</td>
- </tr>';
- return $s;
- }
- // from modules/smartsearch/smartsearch.class.php
- function highlight($text, $keyval)
- {
- global $ssearch;
- $txt = $text;
- $keys = (!is_array($keyval)) ? array($keyval) : $keyval;
- foreach ($keys as $key_idx => $key) {
- if (mb_strlen($key) > 0) {
- $key = stripslashes($key);
- $metacharacters = array('\\', '(', ')', '$', '[', '*', '+', '|', '.', '^', '?');
- $metareplacement = array('\\\\', '\(', '\)', '\$', '\[', '\*', '\+', '\|', '\.', '\^', '\?');
- $key = mb_str_replace($metacharacters, $metareplacement, $key);
- if (isset($ssearch['ignore_specchar']) && ($ssearch['ignore_specchar'] == 'on')) {
- if ($ssearch['ignore_case'] == 'on') {
- $txt = preg_replace('/'.recode2regexp_utf8($key).'/i', '<span class="highlight' . $key_idx . '" >\\0</span>', $txt);
- } else {
- $txt = preg_replace('/'.(recode2regexp_utf8($key)).'/', '<span class="highlight' . $key_idx . '" >\\0</span>', $txt);
- }
- } elseif (!isset($ssearch['ignore_specchar']) || ($ssearch['ignore_specchar'] == '')) {
- if ($ssearch['ignore_case'] == 'on') {
- $txt = preg_replace('/'.$key.'/i', '<span class="highlight' . $key_idx . '" >\\0</span>', $txt);
- } else {
- $txt = preg_replace('/'.$key.'/', '<span class="highlight' . $key_idx . '" >\\0</span>', $txt);
- }
- } else {
- $txt = preg_replace('/'.$key.'/i', '<span class="highlight:' . $key_idx . '" >\\0</span>', $txt);
- }
- }
- }
- return $txt;
- }
- // from modules/smartsearch/smartsearch.class.php
- function recode2regexp_utf8($input)
- {
- $result = '';
- for ($i = 0, $i_cmp = mb_strlen($input); $i < $i_cmp; ++$i)
- switch ($input[$i]) {
- case 'A':
- case 'a':
- $result .= '(a|A!|A�|A?|A�)';
- break;
- case 'C':
- case 'c':
- $result .= '(c|�?|�O)';
- break;
- case 'D':
- case 'd':
- $result .= '(d|�?|Ď)';
- break;
- case 'E':
- case 'e':
- $result .= '(e|A�|ě|A�|Ě)';
- break;
- case 'I':
- case 'i':
- $result .= '(i|A�|A?)';
- break;
- case 'L':
- case 'l':
- $result .= '(l|�o|�3|�1|�1)';
- break;
- case 'N':
- case 'n':
- $result .= '(n|A^|A�)';
- break;
- case 'O':
- case 'o':
- $result .= '(o|A3|A�|A�|A�)';
- break;
- case 'R':
- case 'r':
- $result .= '(r|A�|A�|A�|A~)';
- break;
- case 'S':
- case 's':
- $result .= '(s|A!|A�)';
- break;
- case 'T':
- case 't':
- $result .= '(t|AY|A�)';
- break;
- case 'U':
- case 'u':
- $result .= '(u|Ao|A�|A�|A�)';
- break;
- case 'Y':
- case 'y':
- $result .= '(y|A1|A?)';
- break;
- case 'Z':
- case 'z':
- $result .= '(z|A3|A1)';
- break;
- default:
- $result .= $input[$i];
- }
- return $result;
- }
- // from modules/public/selector.php
- function selPermWhere($obj, $idfld, $namefield, $prefix = '')
- {
- global $AppUI;
- $allowed = $obj->getAllowedRecords($AppUI->user_id, $idfld . ', ' . $namefield, '', '', '', $prefix);
- if (count($allowed)) {
- return ' ' . $idfld . ' IN (' . implode(',', array_keys($allowed)) . ') ';
- } else {
- return null;
- }
- }
- //comes from modules/departments/departments.class.php
- //writes out a single <option> element for display of departments
- function showchilddept(&$a, $level = 1)
- {
- global $department;
- $s = '<option value="' . $a['dept_id'] . '"' . (isset($department) && $department == $a['dept_id'] ? 'selected="selected"' : '') . '>';
- for ($y = 0; $y < $level; $y++) {
- if ($y + 1 == $level) {
- $s .= '';
- } else {
- $s .= ' ';
- }
- }
- $s .= ' ' . $a['dept_name'] . '</option>';
- return $s;
- }
- //comes from modules/departments/departments.class.php
- //recursive function to display children departments.
- function findchilddept(&$tarr, $parent, $level = 1)
- {
- $level++;
- $n = count($tarr);
- for ($x = 0; $x < $n; $x++) {
- if ($tarr[$x]['dept_parent'] == $parent && $tarr[$x]['dept_parent'] != $tarr[$x]['dept_id']) {
- findchilddept($tarr, $tarr[$x]['dept_id'], $level);
- }
- }
- }
- //comes from modules/departments/departments.class.php
- function addDeptId($dataset, $parent)
- {
- global $dept_ids;
- foreach ($dataset as $data) {
- if ($data['dept_parent'] == $parent) {
- $dept_ids[] = $data['dept_id'];
- addDeptId($dataset, $data['dept_id']);
- }
- }
- }
- // From: modules/files/filefolder.class.php
- function getFolderSelectList()
- {
- global $AppUI;
- $q = new w2p_Database_Query();
- $q->addTable('file_folders');
- $q->addQuery('file_folder_id, file_folder_name, file_folder_parent');
- $q->addOrder('file_folder_name');
- $folderList = $q->loadHashList('file_folder_id');
- $folders = array(0 => 'Root');
- foreach($folderList as $folder => $data) {
- $folders[$folder] = $data['file_folder_name'];
- }
- return $folders;
- }
- /*
- * $parent is the parent of the children we want to see
- * $level is increased when we go deeper into the tree, used to display a nice indented tree
- */
- // From: modules/files/filefolder.class.php
- function getFolders($parent)
- {
- global $AppUI, $allowed_folders_ary, $tab, $m, $a, $company_id, $project_id, $task_id;
- // retrieve all children of $parent
- $file_folder = new CFile_Folder();
- $folders = $file_folder->getFoldersByParent($parent);
- $s = '';
- // display each child
- foreach ($folders as $row) {
- if (array_key_exists($row['file_folder_id'], $allowed_folders_ary) or array_key_exists($parent, $allowed_folders_ary)) {
- $file_count = countFiles($row['file_folder_id']);
- $s .= '<tr><td colspan="20">';
- $s .= '<ul>';
- $s .= '<li><a href="./index.php?m=files&a=addedit_folder&file_folder_parent=' . $row['file_folder_id'] . '&file_folder_id=0">' . w2PshowImage('edit_add.png', '', '', 'new folder', 'add a new subfolder', 'files') . '</a></li>';
- $s .= '<li><a href="./index.php?m=files&a=addedit&folder=' . $row['file_folder_id'] . '&project_id=' . $project_id . '&file_id=0">' . w2PshowImage('folder_new.png', '', '', 'new file', 'add new file to this folder', 'files') . '</a></li>';
- $s .= '<li><a href="./index.php?m=files&a=addedit_folder&folder=' . $row['file_folder_id'] . '">' . w2PshowImage('filesaveas.png', '', '', 'edit icon', 'edit this folder', 'files') . '</a></li>';
- if ($m == 'files') {
- $s .= '<li class="info-text"><a href="./index.php?m=' . $m . '&a=' . $a . '&tab=' . $tab . '&folder=' . $row['file_folder_id'] . '" name="ff' . $row['file_folder_id'] . '">';
- }
- $s .= w2PshowImage('folder5_small.png', '22', '22', '', '', 'files');
- $s .= $row['file_folder_name'];
- if ($m == 'files') {
- $s .= '</a></li>';
- }
- if ($file_count > 0) {
- $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>';
- }
- $s .= '<form name="frm_remove_folder_' . $row['file_folder_id'] . '" action="?m=files" method="post" accept-charset="utf-8">
- <input type="hidden" name="dosql" value="do_folder_aed" />
- <input type="hidden" name="del" value="1" />
- <input type="hidden" name="file_folder_id" value="' . $row['file_folder_id'] . '" />
- </form>';
- $s .= '</ul>';
- $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>';
- $s .= '</td></tr>';
- if ($file_count > 0) {
- $s .= '<div class="files-list" id="files_' . $row['file_folder_id'] . '" style="display: none;">';
- $s .= displayFiles($AppUI, $row['file_folder_id'], $task_id, $project_id, $company_id);
- $s .= "</div>";
- }
- }
- }
- return $s;
- }
- // From: modules/files/filefolder.class.php
- function countFiles($folder)
- {
- global $company_id, $allowed_companies;
- global $deny1, $deny2, $project_id, $task_id;
- $q = new w2p_Database_Query();
- $q->addTable('files');
- $q->addQuery('count(files.file_id)');
- $q->addJoin('projects', 'p', 'p.project_id = file_project');
- $q->addJoin('users', 'u', 'u.user_id = file_owner');
- $q->addJoin('tasks', 't', 't.task_id = file_task');
- $q->addJoin('file_folders', 'ff', 'ff.file_folder_id = file_folder');
- $q->addWhere('file_folder = ' . (int) $folder);
- if (count($deny1) > 0) {
- $q->addWhere('file_project NOT IN (' . implode(',', $deny1) . ')');
- }
- if (count($deny2) > 0) {
- $q->addWhere('file_task NOT IN (' . implode(',', $deny2) . ')');
- }
- if ($project_id) {
- $q->addWhere('file_project = ' . (int) $project_id);
- }
- if ($task_id) {
- $q->addWhere('file_task = ' . (int) $task_id);
- }
- if ($company_id) {
- $q->innerJoin('companies', 'co', 'co.company_id = p.project_company');
- $q->addWhere('company_id = ' . (int) $company_id);
- $q->addWhere('company_id IN (' . $allowed_companies . ')');
- }
- $files_in_folder = $q->loadResult();
- $q->clear();
- return $files_in_folder;
- }
- // From: modules/files/filefolder.class.php
- function displayFiles($AppUI, $folder_id, $task_id, $project_id, $company_id)
- {
- global $m, $tab, $xpg_min, $xpg_pagesize, $showProject, $file_types,
- $company_id, $current_uri, $canEdit;
- // SETUP FOR FILE LIST
- $q = new w2p_Database_Query();
- $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');
- $q->addQuery('ff.*, max(file_version) as file_version, f.file_date as file_datetime');
- $q->addTable('files', 'f');
- $q->addJoin('file_folders', 'ff', 'ff.file_folder_id = file_folder');
- $q->addJoin('projects', 'p', 'p.project_id = file_project');
- $q->addJoin('tasks', 't', 't.task_id = file_task');
- $q->addJoin('users', 'u', 'u.user_id = file_owner');
- $q->leftJoin('project_departments', 'project_departments', 'p.project_id = project_departments.project_id OR project_departments.project_id IS NULL');
- $q->leftJoin('departments', 'departments', 'departments.dept_id = project_departments.department_id OR dept_id IS NULL');
- //TODO: apply permissions properly
- $project = new CProject();
- $deny1 = $project->getDeniedRecords($AppUI->user_id);
- if (count($deny1) > 0) {
- $q->addWhere('file_project NOT IN (' . implode(',', $deny1) . ')');
- }
- //TODO: apply permissions properly
- $task = new CTask();
- $deny2 = $task->getDeniedRecords($AppUI->user_id);
- if (count($deny2) > 0) {
- $q->addWhere('file_task NOT IN (' . implode(',', $deny2) . ')');
- }
- if ($project_id) {
- $q->addWhere('file_project = ' . (int) $project_id);
- }
- if ($task_id) {
- $q->addWhere('file_task = ' . (int) $task_id);
- }
- if ($company_id) {
- $q->addWhere('project_company = ' . (int) $company_id);
- }
- //$tab = ($m == 'files') ? $tab-1 : -1;
- $temp_tab = ($m == 'files') ? $tab - 1 : -1;
- if (($temp_tab >= 0) and ((count($file_types) - 1) > $temp_tab)) {
- //if ($tab >= 0) {
- $q->addWhere('file_category = ' . (int) $temp_tab);
- }
- $q->setLimit($xpg_pagesize, $xpg_min);
- if ($folder_id > -1) {
- $q->addWhere('file_folder = ' . (int) $folder_id);
- }
- $q->addGroup('file_version_id DESC');
- $q->addOrder('project_name ASC, file_parent ASC, file_id DESC');
- $qv = new w2p_Database_Query();
- $qv->addTable('files');
- $qv->addQuery('file_id, file_version, file_project, file_name, file_task,
- file_description, file_owner, file_size, file_category,
- task_name, file_version_id, file_date as file_datetime, file_checkout, file_co_reason, file_type,
- file_date, cu.user_username as co_user, project_name,
- project_color_identifier, project_owner, u.user_id,
- con.contact_first_name, con.contact_last_name, con.contact_display_name as contact_name,
- co.contact_first_name as co_contact_first_name, co.contact_last_name as co_contact_last_name,
- co.contact_display_name as co_contact_name ');
- $qv->addJoin('projects', 'p', 'p.project_id = file_project');
- $qv->addJoin('users', 'u', 'u.user_id = file_owner');
- $qv->addJoin('contacts', 'con', 'con.contact_id = u.user_contact');
- $qv->addJoin('tasks', 't', 't.task_id = file_task');
- $qv->addJoin('file_folders', 'ff', 'ff.file_folder_id = file_folder');
- if ($project_id) {
- $qv->addWhere('file_project = ' . (int) $project_id);
- }
- if ($task_id) {
- $qv->addWhere('fil…
Large files files are truncated, but you can click here to view the full file