[ Index ]

Source Code Reference for V1.00

title

Body

[close]

/modules/projectdesigner/ -> projectdesigner.class.php (source)

   1  <?php /* $Id: projectdesigner.class.php 191 2008-07-23 23:26:32Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/projectdesigner/projectdesigner.class.php $ */
   2  if (!defined('W2P_BASE_DIR')) {
   3      die('You should not access this file directly.');
   4  }
   5  
   6  //Lets require the main classes needed
   7  include_once (W2P_BASE_DIR. '/modules/projectdesigner/config.php');
   8  require_once ($AppUI->getSystemClass('libmail'));
   9  require_once ($AppUI->getSystemClass('w2p'));
  10  require_once ($AppUI->getModuleClass('companies'));
  11  require_once ($AppUI->getModuleClass('projects'));
  12  require_once ($AppUI->getModuleClass('tasks'));
  13  
  14  /**
  15   * CProjectDesignerOptions Class
  16   */
  17  class CProjectDesignerOptions extends CW2pObject {
  18      var $pd_option_id = null;
  19      var $pd_option_user = null;
  20      var $pd_option_view_project = null;
  21      var $pd_option_view_gantt = null;
  22      var $pd_option_view_tasks = null;
  23      var $pd_option_view_actions = null;
  24      var $pd_option_view_addtasks = null;
  25      var $pd_option_view_files = null;
  26  
  27  	function CProjectDesignerOptions() {
  28          $this->CW2pObject('project_designer_options', 'pd_option_id');
  29      }
  30  
  31  	function store() {
  32          $q = new DBQuery;
  33          $q->addTable('project_designer_options');
  34          $q->addReplace('pd_option_user', $this->pd_option_user);
  35          $q->addReplace('pd_option_view_project', $this->pd_option_view_project);
  36          $q->addReplace('pd_option_view_gantt', $this->pd_option_view_gantt);
  37          $q->addReplace('pd_option_view_tasks', $this->pd_option_view_tasks);
  38          $q->addReplace('pd_option_view_actions', $this->pd_option_view_actions);
  39          $q->addReplace('pd_option_view_addtasks', $this->pd_option_view_addtasks);
  40          $q->addReplace('pd_option_view_files', $this->pd_option_view_files);
  41          $q->addWhere('pd_option_user = ' . (int)$this->pd_option_user);
  42          $q->exec();
  43      }
  44  }
  45  
  46  /** Retrieve tasks with first task_end_dates within given project
  47   * @param int Project_id
  48   * @param int SQL-limit to limit the number of returned tasks
  49   * @return array List of criticalTasks
  50   */
  51  function getCriticalTasksInverted($project_id = null, $limit = 1) {
  52  
  53      if (!$project_id) {
  54          $result = array();
  55          $result[0]['task_end_date'] = '0000-00-00 00:00:00';
  56          return $result;
  57      } else {
  58          $q = new DBQuery;
  59          $q->addTable('tasks');
  60          $q->addWhere('task_project = ' . (int)$project_id  . ' AND NOT ISNULL( task_end_date ) AND task_end_date <>  \'0000-00-00 00:00:00\'');
  61          $q->addOrder('task_start_date ASC');
  62          $q->setLimit($limit);
  63  
  64          return $q->loadList();
  65      }
  66  }
  67  
  68  function taskstyle_pd($task) {
  69      $now = new CDate();
  70      $start_date = intval($task['task_start_date']) ? new CDate($task['task_start_date']) : null;
  71      $end_date = intval($task['task_end_date']) ? new CDate($task['task_end_date']) : null;
  72  
  73      if ($start_date && !$end_date) {
  74          $end_date = $start_date;
  75          $end_date->addSeconds($task['task_duration'] * $task['task_duration_type'] * SEC_HOUR);
  76      } else
  77          if (!$start_date) {
  78              return '';
  79          }
  80  
  81      $style = 'class=';
  82      if ($task['task_percent_complete'] == 0) {
  83          $style .= (($now->before($start_date)) ? '"task_future"' : '"task_notstarted"');
  84      } else
  85          if ($task['task_percent_complete'] == 100) {
  86              $t = new CTask();
  87              $t->load($task['task_id']);
  88              $actual_end_date = new CDate(get_actual_end_date_pd($t->task_id, $t));
  89              $style .= (($actual_end_date->after($end_date)) ? '"task_late"' : '"task_done"');
  90          } else {
  91              $style .= (($now->after($end_date)) ? '"task_overdue"' : '"task_started"');
  92          }
  93          return $style;
  94  }
  95  
  96  function get_actual_end_date_pd($task_id, $task) {
  97      global $AppUI;
  98      $q = new DBQuery;
  99      $mods = $AppUI->getActiveModules();
 100  
 101      if (!empty($mods['history']) && !getDenyRead('history')) {
 102          $q->addQuery('MAX(history_date) as actual_end_date');
 103          $q->addTable('history');
 104          $q->addWhere('history_table=\'tasks\' AND history_item=' . $task_id);
 105      } else {
 106          $q->addQuery('MAX(task_log_date) AS actual_end_date');
 107          $q->addTable('task_log');
 108          $q->addWhere('task_log_task = ' . (int)$task_id);
 109      }
 110  
 111      $task_log_end_date = $q->loadResult();
 112  
 113      $edate = $task_log_end_date;
 114  
 115      $edate = ($edate > $task->task_end_date || $task->task_percent_complete == 100) ? $edate : $task->task_end_date;
 116  
 117      return $edate;
 118  }
 119  
 120  //This kludgy function echos children tasks as threads on project designer (_pd)
 121  
 122  function showtask_pd(&$a, $level = 0, $today_view = false) {
 123      global $AppUI, $w2Pconfig, $done, $query_string, $durnTypes, $userAlloc, $showEditCheckbox;
 124      global $task_access, $task_priority, $PROJDESIGN_CONFIG, $m, $expanded;
 125  
 126      $types = w2Pgetsysval('TaskType');
 127  
 128      $now = new CDate();
 129      $tf = $AppUI->getPref('TIMEFORMAT');
 130      $df = $AppUI->getPref('SHDATEFORMAT');
 131      $fdf = $df . ' ' . $tf;
 132      $perms = &$AppUI->acl();
 133      $show_all_assignees = $w2Pconfig['show_all_task_assignees'] ? true : false;
 134  
 135      $done[] = $a['task_id'];
 136  
 137      $start_date = intval($a['task_start_date']) ? new CDate($a['task_start_date']) : null;
 138      $end_date = intval($a['task_end_date']) ? new CDate($a['task_end_date']) : null;
 139      $last_update = isset($a['last_update']) && intval($a['last_update']) ? new CDate($a['last_update']) : null;
 140  
 141      // prepare coloured highlight of task time information
 142      $sign = 1;
 143      $style = '';
 144      if ($start_date) {
 145          if (!$end_date) {
 146              $end_date = new CDate('0000-00-00 00:00:00');
 147          }
 148  
 149          if ($now->after($start_date) && $a['task_percent_complete'] == 0) {
 150              $style = 'background-color:#ffeebb';
 151          } elseif ($now->after($start_date) && $a['task_percent_complete'] < 100) {
 152              $style = 'background-color:#e6eedd';
 153          }
 154  
 155          if ($now->after($end_date)) {
 156              $sign = -1;
 157              $style = 'background-color:#cc6666;color:#ffffff';
 158          }
 159          if ($a['task_percent_complete'] == 100) {
 160              $style = 'background-color:#aaddaa; color:#00000';
 161          }
 162  
 163          $days = $now->dateDiff($end_date) * $sign;
 164      }
 165  
 166      if ($expanded) {
 167          $s = '<tr id="project_' . $a['task_project'] . '_level>' . $level . '<task_' . $a['task_id'] . '_" onmouseover="highlight_tds(this, true, ' . $a['task_id'] . ')" onmouseout="highlight_tds(this, false, ' . $a['task_id'] . ')" onclick="select_box(\'selected_task\', \'' . $a['task_id'] . '\', \'project_' . $a['task_project'] . '_level>' . $level . '<task_' . $a['task_id'] . '_\',\'frm_tasks\')">'; // edit icon
 168      } else {
 169          $s = '<tr id="project_' . $a['task_project'] . '_level>' . $level . '<task_' . $a['task_id'] . '_" onmouseover="highlight_tds(this, true, ' . $a['task_id'] . ')" onmouseout="highlight_tds(this, false, ' . $a['task_id'] . ')" onclick="select_box(\'selected_task\', \'' . $a['task_id'] . '\', \'project_' . $a['task_project'] . '_level>' . $level . '<task_' . $a['task_id'] . '_\',\'frm_tasks\')" ' . ($level ? 'style="display:none"' : '') . '>'; // edit icon
 170      }
 171      $s .= '<td>';
 172      $canEdit = true;
 173      $canViewLog = true;
 174      if ($canEdit) {
 175          $s .= w2PtoolTip('edit tasks panel', 'click to edit this task') . '<a href="?m=tasks&a=addedit&task_id=' . $a['task_id'] . '"><img src="' . w2PfindImage('icons/pencil.gif') . '" border="0" width="12" height="12" /></a>' . w2PendTip();
 176      }
 177      $s .= '</td>';
 178      // percent complete
 179      $s .= '<td align="right">' . intval($a['task_percent_complete']) . '%</td>';
 180      // priority
 181      $s .= '<td align="center" nowrap="nowrap">';
 182      if ($a['task_priority'] < 0) {
 183          $s .= '<img src="' . w2PfindImage('icons/priority-' . -$a['task_priority'] . '.gif') . '" width="13" height="16" />';
 184      } elseif ($a['task_priority'] > 0) {
 185          $s .= '<img src="' . w2PfindImage('icons/priority+' . $a['task_priority'] . '.gif') . '" width="13" height="16" />';
 186      }
 187      $s .= $a['file_count'] > 0 ? '<img src="' . w2PfindImage('clip.png') . '" alt="' . $AppUI->_('Files') . '" />' : '';
 188      $s .= '</td>';
 189      // access
 190      $s .= '<td nowrap="nowrap">';
 191      $s .= substr($task_access[$a['task_access']], 0, 3);
 192      $s .= '</td>';
 193      // type
 194      $s .= '<td nowrap="nowrap">';
 195      $s .= substr($types[$a['task_type']], 0, 3);
 196      $s .= '</td>';
 197      // type
 198      $s .= '<td nowrap="nowrap">';
 199      $s .= $a['queue_id'] ? 'Yes' : '';
 200      $s .= '</td>';
 201      // inactive
 202      $s .= '<td nowrap="nowrap">';
 203      $s .= $a['task_status'] == '-1' ? 'Yes' : '';
 204      $s .= '</td>';
 205      // add log
 206      $s .= '<td align="center" nowrap="nowrap">';
 207      if ($a['task_dynamic'] != 1) {
 208          $s .= w2PtoolTip('tasks', 'add work log to this task') . '<a href="?m=tasks&a=view&tab=1&project_id=' . $a['task_project'] . '&task_id=' . $a['task_id'] . '"><img src="' . w2PfindImage('add.png', $m) . '" border="0" width="16" height="16" /></a>' . w2PendTip();
 209      }
 210      $s .= '</td>';
 211      // dots
 212      if ($today_view) {
 213          $s .= '<td>';
 214      } else {
 215          $s .= '<td width="20%">';
 216      }
 217      for ($y = 0; $y < $level; $y++) {
 218          if ($y + 1 == $level) {
 219              $s .= '<img src="' . w2PfindImage('corner-dots.gif', $m) . '" width="16" height="12" border="0" />';
 220          } else {
 221              $s .= '<img src="' . w2PfindImage('shim.gif', $m) . '" width="16" height="12"  border="0" />';
 222          }
 223      }
 224      // name link
 225      if ($a['task_description']) {
 226          $s .= w2PtoolTip('Task Description', $a['task_description'], true);
 227      }
 228      $open_link = '<a href="javascript: void(0);"><img onclick="expand_collapse(\'project_' . $a['task_project'] . '_level>' . $level . '<task_' . $a['task_id'] . '_\', \'tblProjects\',\'\',' . ($level + 1) . ');" id="project_' . $a['task_project'] . '_level>' . $level . '<task_' . $a['task_id'] . '__collapse" src="' . w2PfindImage('icons/collapse.gif', $m) . '" border="0" align="center" ' . (!$expanded ? 'style="display:none"' : '') . ' /><img onclick="expand_collapse(\'project_' . $a['task_project'] . '_level>' . $level . '<task_' . $a['task_id'] . '_\', \'tblProjects\',\'\',' . ($level + 1) . ');" id="project_' . $a['task_project'] . '_level>' . $level . '<task_' . $a['task_id'] . '__expand" src="' . w2PfindImage('icons/expand.gif', $m) . '" border="0" align="center" ' . ($expanded ? 'style="display:none"' : '') . ' /></a>';
 229      $taskObj = new CTask;
 230      $taskObj->load($a['task_id']);
 231      if (count($taskObj->getChildren())) {
 232          $is_parent = true;
 233      } else {
 234          $is_parent = false;
 235      }
 236      if ($a['task_milestone'] > 0) {
 237          $s .= '&nbsp;<a href="./index.php?m=tasks&a=view&task_id=' . $a['task_id'] . '" ><b>' . $a['task_name'] . '</b></a> <img src="' . w2PfindImage('icons/milestone.gif', $m) . '" border="0" /></td>';
 238      } elseif ($a['task_dynamic'] == '1' || $is_parent) {
 239          $s .= $open_link;
 240          if ($a['task_dynamic'] == '1') {
 241              $s .= '&nbsp;<a href="./index.php?m=tasks&a=view&task_id=' . $a['task_id'] . '" ><b><i>' . $a['task_name'] . '</i></b></a></td>';
 242          } else {
 243              $s .= '&nbsp;<a href="./index.php?m=tasks&a=view&task_id=' . $a['task_id'] . '" >' . $a['task_name'] . '</a></td>';
 244          }
 245      } else {
 246          $s .= '&nbsp;<a href="./index.php?m=tasks&a=view&task_id=' . $a['task_id'] . '" >' . $a['task_name'] . '</a></td>';
 247      }
 248      if ($a['task_description']) {
 249          $s .= w2PendTip();
 250      }
 251      // task description
 252      if ($PROJDESIGN_CONFIG['show_task_descriptions']) {
 253          $s .= '<td align="justified">' . $a['task_description'] . '</td>';
 254      }
 255      // task owner
 256      $s .= '<td align="left">' . '<a href="?m=admin&a=viewuser&user_id=' . $a['user_id'] . '">' . $a['contact_first_name'] . ' ' . $a['contact_last_name'] . '</a></td>';
 257      $s .= '<td id="ignore_td_' . $a['task_id'] . '" nowrap="nowrap" align="center" style="' . $style . '">' . ($start_date ? $start_date->format($df . ' ' . $tf) : '-') . '</td>';
 258      // duration or milestone
 259      $s .= '<td id="ignore_td_' . $a['task_id'] . '" align="right" nowrap="nowrap" style="' . $style . '">';
 260      $s .= $a['task_duration'] . ' ' . substr($AppUI->_($durnTypes[$a['task_duration_type']]), 0, 1);
 261      $s .= '</td>';
 262      $s .= '<td id="ignore_td_' . $a['task_id'] . '" nowrap="nowrap" align="center" style="' . $style . '">' . ($end_date ? $end_date->format($df . ' ' . $tf) : '-') . '</td>';
 263      if (isset($a['task_assigned_users']) && ($assigned_users = $a['task_assigned_users'])) {
 264          $a_u_tmp_array = array();
 265          if ($show_all_assignees) {
 266              $s .= '<td align="left">';
 267              foreach ($assigned_users as $val) {
 268                  $aInfo = '<a href="?m=admin&a=viewuser&user_id=' . $val['user_id'] . '"';
 269                  $aInfo .= 'title="' . (w2PgetConfig('check_overallocation') ? $AppUI->_('Extent of Assignment') . ':' . $userAlloc[$val['user_id']]['charge'] . '%; ' . $AppUI->_('Free Capacity') . ':' . $userAlloc[$val['user_id']]['freeCapacity'] . '%' : '') . '">';
 270                  $aInfo .= $val['contact_first_name'] . ' ' . $val['contact_last_name'] . ' (' . $val['perc_assignment'] . '%)</a>';
 271                  $a_u_tmp_array[] = $aInfo;
 272              }
 273              $s .= join(', ', $a_u_tmp_array);
 274              $s .= '</td>';
 275          } else {
 276              $s .= '<td align="left" nowrap="nowrap">';
 277              $s .= '<a href="?m=admin&a=viewuser&user_id=' . $assigned_users[0]['user_id'] . '"';
 278              $s .= 'title="' . (w2PgetConfig('check_overallocation') ? $AppUI->_('Extent of Assignment') . ':' . $userAlloc[$assigned_users[0]['user_id']]['charge'] . '%; ' . $AppUI->_('Free Capacity') . ':' . $userAlloc[$assigned_users[0]['user_id']]['freeCapacity'] . '%' : '') . '">';
 279              $s .= $assigned_users[0]['contact_first_name'] . ' ' . $assigned_users[0]['contact_last_name'] . ' (' . $assigned_users[0]['perc_assignment'] . '%)</a>';
 280              if ($a['assignee_count'] > 1) {
 281                  $id = $a['task_id'];
 282                  $s .= '<a href="javascript: void(0);"  onclick="toggle_users(\'users_' . $id . '\');" title="' . join(', ', $a_u_tmp_array) . '">(+' . ($a['assignee_count'] - 1) . ')</a>';
 283                  $s .= '<span style="display: none" id="users_' . $id . '">';
 284                  $a_u_tmp_array[] = $assigned_users[0]['user_username'];
 285                  for ($i = 1, $i_cmp = count($assigned_users); $i < $i_cmp; $i++) {
 286                      $a_u_tmp_array[] = $assigned_users[$i]['user_username'];
 287                      $s .= '<br /><a href="?m=admin&a=viewuser&user_id=';
 288                      $s .= $assigned_users[$i]['user_id'] . '" title="' . (w2PgetConfig('check_overallocation') ? $AppUI->_('Extent of Assignment') . ':' . $userAlloc[$assigned_users[$i]['user_id']]['charge'] . '%; ' . $AppUI->_('Free Capacity') . ':' . $userAlloc[$assigned_users[$i]['user_id']]['freeCapacity'] . '%' : '') . '">';
 289                      $s .= $assigned_users[$i]['contact_first_name'] . ' ' . $assigned_users[$i]['contact_last_name'] . ' (' . $assigned_users[$i]['perc_assignment'] . '%)</a>';
 290                  }
 291                  $s .= '</span>';
 292              }
 293              $s .= '</td>';
 294          }
 295      } else {
 296          // No users asigned to task
 297          $s .= '<td align="center">-</td>';
 298      }
 299  
 300      // Assignment checkbox
 301      if ($showEditCheckbox) {
 302          $s .= '<td align="center"><input type="checkbox" onclick="select_box(\'selected_task\', ' . $a['task_id'] . ',\'project_' . $a['task_project'] . '_level>' . $level . '<task_' . $a['task_id'] . '_\',\'frm_tasks\')" onfocus="is_check=true;" onblur="is_check=false;" id="selected_task_' . $a['task_id'] . '" name="selected_task[' . $a['task_id'] . ']" value="' . $a['task_id'] . '"/></td>';
 303      }
 304      $s .= '</tr>';
 305      echo $s;
 306  }
 307  
 308  function findchild_pd(&$tarr, $parent, $level = 0) {
 309      global $projects;
 310  
 311      $level = $level + 1;
 312      $n = count($tarr);
 313  
 314      for ($x = 0; $x < $n; $x++) {
 315          if ($tarr[$x]['task_parent'] == $parent && $tarr[$x]['task_parent'] != $tarr[$x]['task_id']) {
 316              showtask_pd($tarr[$x], $level);
 317              findchild_pd($tarr, $tarr[$x]['task_id'], $level);
 318          }
 319      }
 320  }
 321  
 322  function get_dependencies_pd($task_id) {
 323      // Pull tasks dependencies
 324      $q = new DBQuery;
 325      $q->addTable('tasks', 't');
 326      $q->addTable('task_dependencies', 'td');
 327      $q->addQuery('t.task_id, t.task_name');
 328      $q->addWhere('td.dependencies_task_id = ' . (int)$task_id);
 329      $q->addWhere('t.task_id = td.dependencies_req_task_id');
 330      $taskDep = $q->loadHashList();
 331  }
 332  
 333  function showtask_pr(&$a, $level = 0,