[ Index ]

Source Code Reference for V1.00

title

Body

[close]

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

   1  <?php /* $Id: vw_tasks.php 210 2008-08-18 17:40:05Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/projectdesigner/vw_tasks.php $ */
   2  if (!defined('W2P_BASE_DIR')) {
   3      die('You should not access this file directly.');
   4  }
   5  global $m, $a, $project_id, $f, $task_status, $min_view, $query_string, $durnTypes, $tpl;
   6  global $task_sort_item1, $task_sort_type1, $task_sort_order1;
   7  global $task_sort_item2, $task_sort_type2, $task_sort_order2;
   8  global $user_id, $w2Pconfig, $currentTabId, $currentTabName, $canEdit, $showEditCheckbox;
   9  
  10  if (empty($query_string)) {
  11      $query_string = '?m=' . $m . '&amp;a=' . $a;
  12  }
  13  
  14  // Number of columns (used to calculate how many columns to span things through)
  15  $cols = 13;
  16  
  17  /****
  18  // Let's figure out which tasks are selected
  19  */
  20  $task_id = intval(w2PgetParam($_GET, 'task_id', 0));
  21  
  22  $q = new DBQuery;
  23  $pinned_only = intval(w2PgetParam($_GET, 'pinned', 0));
  24  if (isset($_GET['pin'])) {
  25      $pin = intval(w2PgetParam($_GET, 'pin', 0));
  26      $msg = '';
  27  
  28      // load the record data
  29      if ($pin) {
  30          $q->addTable('user_task_pin');
  31          $q->addInsert('user_id', $AppUI->user_id);
  32          $q->addInsert('task_id', $task_id);
  33      } else {
  34          $q->setDelete('user_task_pin');
  35          $q->addWhere('user_id = ' . (int)$AppUI->user_id);
  36          $q->addWhere('task_id = ' . (int)$task_id);
  37      }
  38  
  39      if (!$q->exec()) {
  40          $AppUI->setMsg('ins/del err', UI_MSG_ERROR, true);
  41      } else {
  42          $q->clear();
  43      }
  44  
  45      $AppUI->redirect('', -1);
  46  }
  47  
  48  $AppUI->savePlace();
  49  
  50  $durnTypes = w2PgetSysVal('TaskDurationType');
  51  $taskPriority = w2PgetSysVal('TaskPriority');
  52  
  53  $task_project = $project_id;
  54  
  55  $task_sort_item1 = w2PgetParam($_GET, 'task_sort_item1', '');
  56  $task_sort_type1 = w2PgetParam($_GET, 'task_sort_type1', '');
  57  $task_sort_item2 = w2PgetParam($_GET, 'task_sort_item2', '');
  58  $task_sort_type2 = w2PgetParam($_GET, 'task_sort_type2', '');
  59  $task_sort_order1 = intval(w2PgetParam($_GET, 'task_sort_order1', 0));
  60  $task_sort_order2 = intval(w2PgetParam($_GET, 'task_sort_order2', 0));
  61  if (isset($_POST['show_task_options'])) {
  62      $AppUI->setState('TaskListShowIncomplete', w2PgetParam($_POST, 'show_incomplete', 0));
  63  }
  64  $showIncomplete = $AppUI->getState('TaskListShowIncomplete', 0);
  65  
  66  $project = &new CProject;
  67  // $allowedProjects = $project->getAllowedRecords($AppUI->user_id, 'project_id, project_name');
  68  $allowedProjects = $project->getAllowedSQL($AppUI->user_id, 'projects.project_id');
  69  $working_hours = ($w2Pconfig['daily_working_hours'] ? $w2Pconfig['daily_working_hours'] : 8);
  70  
  71  $q->addQuery('projects.project_id, project_color_identifier, project_name');
  72  $q->addQuery('SUM(task_duration * task_percent_complete * IF(task_duration_type = 24, ' . $working_hours . ', task_duration_type)) / SUM(task_duration * IF(task_duration_type = 24, ' . $working_hours . ', task_duration_type)) AS project_percent_complete');
  73  $q->addQuery('company_name');
  74  $q->addTable('projects');
  75  $q->leftJoin('tasks', 't1', 'projects.project_id = t1.task_project');
  76  $q->leftJoin('companies', 'c', 'company_id = project_company');
  77  $q->leftJoin('project_departments', 'project_departments', 'projects.project_id = project_departments.project_id OR project_departments.project_id IS NULL');
  78  $q->leftJoin('departments', 'departments', 'departments.dept_id = project_departments.department_id OR dept_id IS NULL');
  79  $q->addWhere('t1.task_id = t1.task_parent');
  80  $q->addWhere('projects.project_id=' . $project_id);
  81  if (count($allowedProjects)) {
  82      $q->addWhere($allowedProjects);
  83  }
  84  $q->addGroup('projects.project_id');
  85  $q2 = new DBQuery;
  86  $q2 = $q;
  87  $q2->addQuery('projects.project_id, COUNT(t1.task_id) as total_tasks');
  88  
  89  $perms = &$AppUI->acl();
  90  $projects = array();
  91  if ($canViewTasks) {
  92      $prc = $q->exec();
  93      echo db_error();
  94      while ($row = $q->fetchRow()) {
  95          $projects[$row['project_id']] = $row;
  96      }
  97  
  98      $prc2 = $q2->exec();
  99      echo db_error();
 100      while ($row2 = $q2->fetchRow()) {
 101          $projects[$row2['project_id']] = ((!($projects[$row2['project_id']])) ? array() : $projects[$row2['project_id']]);
 102          array_push($projects[$row2['project_id']], $row2);
 103      }
 104  }
 105  $q->clear();
 106  $q2->clear();
 107  
 108  $q->addQuery('tasks.task_id, task_parent, task_name');
 109  $q->addQuery('task_start_date, task_end_date, task_dynamic');
 110  $q->addQuery('count(tasks.task_parent) as children');
 111  $q->addQuery('task_pinned, pin.user_id as pin_user');
 112  $q->addQuery('task_priority, task_percent_complete');
 113  $q->addQuery('task_duration, task_duration_type');
 114  $q->addQuery('task_project');
 115  $q->addQuery('task_access, task_type');
 116  $q->addQuery('task_description, task_owner, task_status');
 117  $q->addQuery('usernames.user_username, usernames.user_id');
 118  $q->addQuery('assignees.user_username as assignee_username');
 119  $q->addQuery('count(distinct assignees.user_id) as assignee_count');
 120  $q->addQuery('co.contact_first_name, co.contact_last_name');
 121  $q->addQuery('task_milestone');
 122  $q->addQuery('count(distinct f.file_task) as file_count');
 123  $q->addQuery('tlog.task_log_problem');
 124  $q->addQuery('evtq.queue_id');
 125  
 126  $q->addTable('tasks');
 127  $mods = $AppUI->getActiveModules();
 128  if (!empty($mods['history']) && !getDenyRead('history')) {
 129      $q->addQuery('MAX(history_date) as last_update');
 130      $q->leftJoin('history', 'h', 'history_item = tasks.task_id AND history_table=\'tasks\'');
 131  }
 132  $q->leftJoin('projects', 'projects', 'projects.project_id = task_project');
 133  $q->leftJoin('users', 'usernames', 'task_owner = usernames.user_id');
 134  $q->leftJoin('user_tasks', 'ut', 'ut.task_id = tasks.task_id');
 135  $q->leftJoin('users', 'assignees', 'assignees.user_id = ut.user_id');
 136  $q->leftJoin('contacts', 'co', 'co.contact_id = usernames.user_contact');
 137  $q->leftJoin('task_log', 'tlog', 'tlog.task_log_task = tasks.task_id AND tlog.task_log_problem > 0');
 138  $q->leftJoin('files', 'f', 'tasks.task_id = f.file_task');
 139  $q->leftJoin('user_task_pin', 'pin', 'tasks.task_id = pin.task_id AND pin.user_id = ' . (int)$AppUI->user_id);
 140  $q->leftJoin('event_queue', 'evtq', 'tasks.task_id = evtq.queue_origin_id AND evtq.queue_module = "tasks"');
 141  $q->leftJoin('project_departments', 'project_departments', 'projects.project_id = project_departments.project_id OR project_departments.project_id IS NULL');
 142  $q->leftJoin('departments', 'departments', 'departments.dept_id = project_departments.department_id OR dept_id IS NULL');
 143  
 144  $q->addWhere('task_project = ' . (int)$project_id);
 145  
 146  $allowedProjects = $project->getAllowedSQL($AppUI->user_id, 'task_project');
 147  if (count($allowedProjects)) {
 148      $q->addWhere($allowedProjects);
 149  }
 150  $obj = &new CTask;
 151  $allowedTasks = $obj->getAllowedSQL($AppUI->user_id, 'tasks.task_id');
 152  if (count($allowedTasks)) {
 153      $q->addWhere($allowedTasks);
 154  }
 155  $q->addGroup('tasks.task_id');
 156  $q->addOrder('task_start_date');
 157  if ($canViewTasks) {
 158      $tasks = $q->loadList();
 159  }
 160  // POST PROCESSING TASKS
 161  foreach ($tasks as $row) {
 162      //add information about assigned users into the page output
 163      $q->clear();
 164      $q->addQuery('ut.user_id,    u.user_username');
 165      $q->addQuery('contact_email, ut.perc_assignment, SUM(ut.perc_assignment) AS assign_extent');
 166      $q->addQuery('contact_first_name, contact_last_name');
 167      $q->addTable('user_tasks', 'ut');
 168      $q->leftJoin('users', 'u', 'u.user_id = ut.user_id');
 169      $q->leftJoin('contacts', 'c', 'u.user_contact = c.contact_id');
 170      $q->addWhere('ut.task_id = ' . (int)$row['task_id']);
 171      $q->addGroup('ut.user_id');
 172      $q->addOrder('perc_assignment desc, user_username');
 173  
 174      $assigned_users = array();
 175      $row['task_assigned_users'] = $q->loadList();
 176      $q->addQuery('count(task_id) as children');
 177      $q->addTable('tasks');
 178      $q->addWhere('task_parent = ' . (int)$row['task_id']);
 179      $q->addWhere('task_id <> task_parent');
 180      $row['children'] = $q->loadResult();
 181      $row['style'] = taskstyle_pd($row);
 182      $i = count($projects[$row['task_project']]['tasks']) + 1;
 183      $row['task_number'] = $i;
 184      $row['node_id'] = 'node_' . $i . '-' . $row['task_id'];
 185      if (strpos($row['task_duration'], '.') && $row['task_duration_type'] == 1) {
 186          $row['task_duration'] = floor($row['task_duration']) . ':' . round(60 * ($row['task_duration'] - floor($row['task_duration'])));
 187      }
 188      //pull the final task row into array
 189      $projects[$row['task_project']]['tasks'][] = $row;
 190  }
 191  
 192  $showEditCheckbox = isset($canEditTasks) && $canEditTasks || $perms->checkModule('admin', 'view');
 193  
 194  $durnTypes = w2PgetSysVal('TaskDurationType');
 195  $tempoTask = new CTask();
 196  $userAlloc = $tempoTask->getAllocation('user_id');
 197  global $expanded;
 198  $expanded = $AppUI->getPref('TASKSEXPANDED');
 199  $open_link = w2PtoolTip($m, 'click to expand/collapse all the tasks for this project.') . '<a href="javascript: void(0);"><img onclick="expand_collapse(\'project_' . $project_id . '_\', \'tblProjects\',\'collapse\',0,2);" id="project_' . $project_id . '__collapse" src="' . w2PfindImage('up22.png', $m) . '" border="0" width="22" height="22" align="center" ' . (!$expanded ? 'style="display:none"' : '') . ' /><img onclick="expand_collapse(\'project_' . $project_id . '_\', \'tblProjects\',\'expand\',0,2);" id="project_' . $project_id . '__expand" src="' . w2PfindImage('down22.png', $m) . '" border="0" width="22" height="22" align="center" ' . ($expanded ? 'style="display:none"' : '') . ' /></a>' . w2PendTip();
 200  ?>
 201  <form name='frm_tasks'>
 202  <table id="tblTasks" width="100%" border="0" cellpadding="2" cellspacing="1" class="tbl">
 203  <tr>
 204    <td colspan="16" align='left'>
 205          <?php echo $open_link; ?>
 206    </td>
 207  </tr>
 208  <tr>
 209          <th width="10">&nbsp;</th>
 210          <th width="20"><?php echo $AppUI->_('Work'); ?></th>
 211          <th align="center"><?php echo $AppUI->_('P'); ?></th>
 212          <th align="center"><?php echo $AppUI->_('A'); ?></th>
 213          <th align="center"><?php echo $AppUI->_('T'); ?></th>
 214          <th align="center"><?php echo $AppUI->_('R'); ?></th>
 215          <th align="center"><?php echo $AppUI->_('I'); ?></th>
 216          <th align="center"><?php echo $AppUI->_('Log'); ?></th>
 217          <th width="40%"><?php echo $AppUI->_('Task Name'); ?></th>
 218  <?php if ($PROJDESIGN_CONFIG['show_task_descriptions']) { ?>
 219          <th width="200"><?php echo $AppUI->_('Task Description'); ?></th>
 220  <?php } ?>
 221          <th nowrap="nowrap"><?php echo $AppUI->_('Task Owner'); ?></th>
 222          <th nowrap="nowrap"><?php echo $AppUI->_('Start'); ?></th>
 223          <th nowrap="nowrap"><?php echo $AppUI->_('Duration'); ?>&nbsp;&nbsp;</th>
 224          <th nowrap="nowrap"><?php echo $AppUI->_('Finish'); ?></th>
 225          <th nowrap="nowrap"><?php echo $AppUI->_('Assigned Users') ?></th>
 226          <?php if ($showEditCheckbox) {
 227      echo '<th width="1"><input type="checkbox" onclick="mult_sel(this, \'selected_task_\', \'frm_tasks\')" name="multi_check"/></th>';
 228  } ?>
 229  </tr>
 230  <?php
 231  reset($projects);
 232  
 233  foreach ($projects as $k => $p) {
 234      $tnums = count($p['tasks']);
 235      //echo '<pre>'; print_r($p['tasks']); echo '</pre>';
 236      if ($tnums > 0 || $project_id == $p['project_id']) {
 237          if ($task_sort_item1 != '') {
 238              if ($task_sort_item2 != '' && $task_sort_item1 != $task_sort_item2) {
 239                  $p['tasks'] = array_csort($p['tasks'], $task_sort_item1, $task_sort_order1, $task_sort_type1, $task_sort_item2, $task_sort_order2, $task_sort_type2);
 240              } else {
 241                  $p['tasks'] = array_csort($p['tasks'], $task_sort_item1, $task_sort_order1, $task_sort_type1);
 242              }
 243          }
 244  
 245          for ($i = 0; $i < $tnums; $i++) {
 246              $t = $p['tasks'][$i];
 247              if ($t['task_parent'] == $t['task_id']) {
 248                  showtask_pd($t, 0);
 249                  findchild_pd($p['tasks'], $t['task_id']);
 250              }
 251          }
 252      }
 253  }
 254  ?>
 255  </table>
 256  </form>
 257  <table>
 258  <tr>
 259          <td><?php echo $AppUI->_('Key'); ?>:</td>
 260          <th>&nbsp;P&nbsp;</th>
 261          <td>=<?php echo $AppUI->_('Priority'); ?></td>
 262          <th>&nbsp;A&nbsp;</th>
 263          <td>=<?php echo $AppUI->_('Access'); ?></td>
 264          <th>&nbsp;T&nbsp;</th>
 265          <td>=<?php echo $AppUI->_('Type'); ?></td>
 266          <th>&nbsp;R&nbsp;</th>
 267          <td>=<?php echo $AppUI->_('Reminder'); ?></td>
 268          <th>&nbsp;I&nbsp;</th>
 269          <td>=<?php echo $AppUI->_('Inactive'); ?></td>
 270          <td>&nbsp; &nbsp;</td>
 271          <td style="border-style:solid;border-width:1px" bgcolor="#ffffff">&nbsp; &nbsp;</td>
 272          <td>=<?php echo $AppUI->_('Future Task'); ?></td>
 273          <td>&nbsp; &nbsp;</td>
 274          <td style="border-style:solid;border-width:1px" bgcolor="#e6eedd">&nbsp; &nbsp;</td>
 275          <td>=<?php echo $AppUI->_('Started and on time'); ?></td>
 276          <td style="border-style:solid;border-width:1px" bgcolor="#ffeebb">&nbsp; &nbsp;</td>
 277          <td>=<?php echo $AppUI->_('Should have started'); ?></td>
 278          <td>&nbsp; &nbsp;</td>
 279          <td style="border-style:solid;border-width:1px" bgcolor="#CC6666">&nbsp; &nbsp;</td>
 280          <td>=<?php echo $AppUI->_('Overdue'); ?></td>
 281          <td>&nbsp; &nbsp;</td>
 282          <td style="border-style:solid;border-width:1px" bgcolor="#aaddaa">&nbsp; &nbsp;</td>
 283          <td>=<?php echo $AppUI->_('Done'); ?></td>
 284  </tr>
 285  </table>


Generated: Fri Jan 9 03:00:02 2009 Cross-referenced by PHPXref 0.7