[ Index ]

Source Code Reference for V1.00

title

Body

[close]

/modules/tasks/ -> view.php (source)

   1  <?php /* $Id: view.php 197 2008-08-01 13:49:43Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/tasks/view.php $ */
   2  if (!defined('W2P_BASE_DIR')) {
   3      die('You should not access this file directly.');
   4  }
   5  
   6  $task_id = intval(w2PgetParam($_GET, 'task_id', 0));
   7  $task_log_id = intval(w2PgetParam($_GET, 'task_log_id', 0));
   8  $reminded = intval(w2PgetParam($_GET, 'reminded', 0));
   9  
  10  // check permissions for this record
  11  $canRead = !getDenyRead($m, $task_id);
  12  $canEdit = !getDenyEdit($m, $task_id);
  13  
  14  if (!$canRead) {
  15      $AppUI->redirect('m=public&a=access_denied');
  16  }
  17  $q = &new DBQuery;
  18  $perms = &$AppUI->acl();
  19  
  20  $q->addTable('tasks');
  21  $q->addJoin('users', 'u1', 'u1.user_id = task_owner', 'inner');
  22  $q->addJoin('contacts', 'ct', 'ct.contact_id = u1.user_contact', 'inner');
  23  $q->addJoin('projects', 'p', 'p.project_id = task_project', 'inner');
  24  $q->leftJoin('task_log', 'tl', 'tl.task_log_task = task_id');
  25  $q->addWhere('task_id = ' . (int)$task_id);
  26  $q->addQuery('tasks.*');
  27  $q->addQuery('project_name, project_color_identifier');
  28  $q->addQuery('CONCAT(contact_first_name, \' \', contact_last_name) as username');
  29  $q->addQuery('ROUND(SUM(task_log_hours),2) as log_hours_worked');
  30  $q->addGroup('task_id');
  31  
  32  // check if this record has dependencies to prevent deletion
  33  $msg = '';
  34  $obj = new CTask();
  35  $obj->load($task_id);
  36  $canDelete = $obj->canDelete($msg, $task_id);
  37  
  38  //$obj = null;
  39  $q->loadObject($obj, true, false);
  40  $q->clear();
  41  
  42  if (!$obj) {
  43      $AppUI->setMsg('Task');
  44      $AppUI->setMsg('invalidID', UI_MSG_ERROR, true);
  45      $AppUI->redirect();
  46  } else {
  47      $AppUI->savePlace();
  48  }
  49  
  50  if (!$obj->canAccess($AppUI->user_id)) {
  51      $AppUI->redirect('m=public&a=access_denied');
  52  }
  53  
  54  // Clear any reminders
  55  if ($reminded) {
  56      $obj->clearReminder();
  57  }
  58  
  59  // retrieve any state parameters
  60  if (isset($_GET['tab'])) {
  61      $AppUI->setState('TaskLogVwTab', w2PgetParam($_GET, 'tab', null));
  62  }
  63  $tab = $AppUI->getState('TaskLogVwTab') !== null ? $AppUI->getState('TaskLogVwTab') : 0;
  64  
  65  // get the prefered date format
  66  $df = $AppUI->getPref('SHDATEFORMAT');
  67  //Also view the time
  68  $df .= ' ' . $AppUI->getPref('TIMEFORMAT');
  69  
  70  $start_date = intval($obj->task_start_date) ? new CDate($obj->task_start_date) : null;
  71  $end_date = intval($obj->task_end_date) ? new CDate($obj->task_end_date) : null;
  72  
  73  //check permissions for the associated project
  74  $canReadProject = !getDenyRead('projects', $obj->task_project);
  75  
  76  // get the users on this task
  77  $q->addTable('users', 'u');
  78  $q->addTable('user_tasks', 't');
  79  $q->addJoin('contacts', 'c', 'user_contact = contact_id', 'inner');
  80  $q->addQuery('u.user_id, u.user_username, contact_email, perc_assignment');
  81  $q->addWhere('t.task_id = ' . (int)$task_id);
  82  $q->addWhere('t.user_id = u.user_id');
  83  $q->addOrder('u.user_username');
  84  
  85  $users = $q->loadList();
  86  $q->clear();
  87  
  88  $durnTypes = w2PgetSysVal('TaskDurationType');
  89  
  90  // setup the title block
  91  $titleBlock = new CTitleBlock('View Task', 'applet-48.png', $m, $m . '.' . $a);
  92  $titleBlock->addCell();
  93  if ($canEdit) {
  94      $titleBlock->addCell('<input type="submit" class="button" value="' . $AppUI->_('new task') . '">', '', '<form action="?m=tasks&a=addedit&task_project=' . $obj->task_project . '&task_parent=' . $task_id . '" method="post">', '</form>');
  95      $titleBlock->addCell('<input type="submit" class="button" value="' . $AppUI->_('new file') . '">', '', '<form action="?m=files&a=addedit&project_id=' . $obj->task_project . '&file_task=' . $obj->task_id . '" method="post">', '</form>');
  96  }
  97  $titleBlock->addCrumb('?m=tasks', 'tasks list');
  98  if ($canReadProject) {
  99      $titleBlock->addCrumb('?m=projects&a=view&project_id=' . $obj->task_project, 'view this project');
 100  }
 101  if ($canEdit) {
 102      $titleBlock->addCrumb('?m=tasks&a=addedit&task_id=' . $task_id, 'edit this task');
 103  }
 104  if ($canDelete) {
 105      $titleBlock->addCrumbDelete('delete task', $canDelete, $msg);
 106  }
 107  $titleBlock->show();
 108  
 109  $task_types = w2PgetSysVal('TaskType');
 110  
 111  ?>
 112  
 113  <script language="JavaScript">
 114  <?php
 115  // security improvement:
 116  // some javascript functions may not appear on client side in case of user not having write permissions
 117  // else users would be able to arbitrarily run 'bad' functions
 118  if ($canEdit) {
 119  ?>
 120  
 121  function updateTask() {
 122      var f = document.editFrm;
 123      if (f.task_log_description.value.length < 1) {
 124          alert( '<?php echo $AppUI->_('tasksComment', UI_OUTPUT_JS); ?>' );
 125          f.task_log_description.focus();
 126      } else if (isNaN( parseInt( f.task_percent_complete.value+0 ) )) {
 127          alert( '<?php echo $AppUI->_('tasksPercent', UI_OUTPUT_JS); ?>' );
 128          f.task_percent_complete.focus();
 129      } else if(f.task_percent_complete.value  < 0 || f.task_percent_complete.value > 100) {
 130          alert( '<?php echo $AppUI->_('tasksPercentValue', UI_OUTPUT_JS); ?>' );
 131          f.task_percent_complete.focus();
 132      } else {
 133          f.submit();
 134      }
 135  }
 136  function delIt() {
 137      if (confirm( '<?php echo $AppUI->_('doDelete', UI_OUTPUT_JS) . ' ' . $AppUI->_('Task', UI_OUTPUT_JS) . '?'; ?>' )) {
 138          document.frmDelete.submit();
 139      }
 140  }
 141  <?php } ?>
 142  </script>
 143  
 144  
 145  <form name="frmDelete" action="./index.php?m=tasks" method="post">
 146      <input type="hidden" name="dosql" value="do_task_aed" />
 147      <input type="hidden" name="del" value="1" />
 148      <input type="hidden" name="task_id" value="<?php echo $task_id; ?>" />
 149  </form>
 150  
 151  <table border="0" cellpadding="4" cellspacing="0" width="100%" class="std">
 152  <tr valign="top">
 153      <td width="50%">
 154          <table width="100%" cellspacing="1" cellpadding="2">
 155          <tr>
 156              <td nowrap="nowrap" colspan="2"><strong><?php echo $AppUI->_('Details'); ?></strong></td>
 157          </tr>
 158          <tr>
 159              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Project'); ?>:</td>
 160              <td style="background-color:#<?php echo $obj->project_color_identifier; ?>">
 161                  <font color="<?php echo bestColor($obj->project_color_identifier); ?>">
 162                      <?php echo $obj->project_name; ?>
 163                  </font>
 164              </td>
 165          </tr>
 166          <tr>
 167              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Task'); ?>:</td>
 168              <td class="hilite"><strong><?php echo $obj->task_name; ?></strong></td>
 169          </tr>
 170          <?php if ($obj->task_parent != $obj->task_id) {
 171      $obj_parent = new CTask();
 172      $obj_parent->load($obj->task_parent);
 173  ?>
 174          <tr>
 175              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Task Parent'); ?>:</td>
 176              <td class="hilite"><a href="<?php echo "./index.php?m=tasks&a=view&task_id=" . $obj_parent->task_id; ?>"><?php echo $obj_parent->task_name; ?></a></td>
 177          </tr>
 178          <?php } ?>
 179          <tr>
 180              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Owner'); ?>:</td>
 181              <td class="hilite"> <?php echo $obj->username; ?></td>
 182          </tr>                <tr>
 183              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Priority'); ?>:</td>
 184              <td class="hilite">
 185          <?php
 186  $task_priotities = w2PgetSysVal('TaskPriority');
 187  echo $AppUI->_($task_priotities[$obj->task_priority]);
 188  ?>
 189              </td>
 190          </tr>
 191          <tr>
 192              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Web Address'); ?>:</td>
 193              <td class="hilite" width="300"><a href="<?php echo $obj->task_related_url; ?>" target="task<?php echo $task_id; ?>"><?php echo $obj->task_related_url; ?></a></td>
 194          </tr>
 195          <tr>
 196              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Milestone'); ?>:</td>
 197              <td class="hilite" width="300">
 198  <?php if ($obj->task_milestone) {
 199      echo $AppUI->_('Yes');
 200  } else {
 201      echo $AppUI->_('No');
 202  } ?></td>
 203          </tr>
 204          <tr>
 205              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Progress'); ?>:</td>
 206              <td class="hilite" width="300"><?php echo $obj->task_percent_complete; ?>%</td>
 207          </tr>
 208          <tr>
 209              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Time Worked'); ?>:</td>
 210              <td class="hilite" width="300"><?php echo ($obj->task_hours_worked + @rtrim($obj->log_hours_worked, '0')); ?></td>
 211          </tr>
 212          <tr>
 213              <td nowrap="nowrap" colspan="2"><strong><?php echo $AppUI->_('Dates and Targets'); ?></strong></td>
 214          </tr>
 215          <tr>
 216              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Start Date'); ?>:</td>
 217              <td class="hilite" width="300"><?php echo $start_date ? $start_date->format($df) : '-'; ?></td>
 218          </tr>
 219          <tr>
 220              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Finish Date'); ?>:</td>
 221              <td class="hilite" width="300"><?php echo $end_date ? $end_date->format($df) : '-'; ?></td>
 222          </tr>
 223          <tr>
 224              <td align="right" nowrap="nowrap" valign="top"><?php echo $AppUI->_('Expected Duration'); ?>:</td>
 225              <td class="hilite" width="300"><?php echo $obj->task_duration . ' ' . $AppUI->_($durnTypes[$obj->task_duration_type]); ?></td>
 226          </tr>
 227          <tr>
 228              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Target Budget'); ?> <?php echo $w2Pconfig['currency_symbol'] ?>:</td>
 229              <td class="hilite" width="300"><?php echo $obj->task_target_budget; ?></td>
 230          </tr>
 231          <tr>
 232              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Task Type'); ?> :</td>
 233              <td class="hilite" width="300"><?php echo $AppUI->_($task_types[$obj->task_type]); ?></td>
 234          </tr>
 235  
 236          </table>
 237      </td>
 238  
 239      <td width="50%">
 240          <table cellspacing="1" cellpadding="2" border="0" width="100%">
 241          <tr>
 242              <td colspan="3"><strong><?php echo $AppUI->_('Assigned Users'); ?></strong></td>
 243          </tr>
 244          <tr>
 245              <td colspan="3">
 246              <?php
 247  $s = '';
 248  $s = count($users) == 0 ? '<tr><td bgcolor="#ffffff">' . $AppUI->_('none') . '</td></tr>' : '';
 249  foreach ($users as $row) {
 250      $s .= '<tr>';
 251      $s .= '<td class="hilite"><a href="mailto:' . $row['contact_email'] . '">' . w2PgetUsernameFromID($row['user_id']) . '</a></td>';
 252      $s .= '<td class="hilite" align="right">' . $row['perc_assignment'] . '%</td>';
 253      $s .= '</tr>';
 254  }
 255  echo '<table width="100%" cellspacing="1" bgcolor="black">' . $s . '</table>';
 256  ?>
 257              </td>
 258          </tr>
 259  
 260          <?php
 261  // Pull tasks dependencies
 262  $q->addQuery('td.dependencies_req_task_id, t.task_name');
 263  $q->addTable('tasks', 't');
 264  $q->addTable('task_dependencies', 'td');
 265  $q->addWhere('td.dependencies_req_task_id = t.task_id');
 266  $q->addWhere('td.dependencies_task_id = ' . (int)$task_id);
 267  
 268  $taskDep = $q->loadHashList();
 269  $q->clear();
 270  ?>
 271          <tr>
 272              <td colspan="3"><strong><?php echo $AppUI->_('Dependencies'); ?></strong></td>
 273          </tr>
 274          <tr>
 275              <td colspan="3">
 276              <?php
 277  $s = count($taskDep) == 0 ? '<tr><td bgcolor="#ffffff">' . $AppUI->_('none') . '</td></tr>' : '';
 278  foreach ($taskDep as $key => $value) {
 279      $s .= '<tr><td class="hilite">';
 280      $s .= '<a href="./index.php?m=tasks&a=view&task_id=' . $key . '">' . $value . '</a>';
 281      $s .= '</td></tr>';
 282  }
 283  echo '<table width="100%" cellspacing="1" bgcolor="black">' . $s . '</table>';
 284  ?>
 285              </td>
 286          </tr>
 287                  <?php
 288  // Pull the tasks depending on this Task
 289  $q->addQuery('td.dependencies_task_id, t.task_name');
 290  $q->addTable('tasks', 't');
 291  $q->addTable('task_dependencies', 'td');
 292  $q->addWhere('td.dependencies_task_id = t.task_id');
 293  $q->addWhere('td.dependencies_req_task_id = ' . (int)$task_id);
 294  $dependingTasks = $q->loadHashList();
 295  $q->clear();
 296  ?>
 297          <tr>
 298              <td colspan="3"><strong><?php echo $AppUI->_('Tasks depending on this Task'); ?></strong></td>
 299          </tr>
 300          <tr>
 301              <td colspan="3">
 302              <?php
 303  $s = count($dependingTasks) == 0 ? '<tr><td bgcolor="#ffffff">' . $AppUI->_('none') . '</td></tr>' : '';
 304  foreach ($dependingTasks as $key => $value) {
 305      $s .= '<tr><td class="hilite">';
 306      $s .= '<a href="./index.php?m=tasks&a=view&task_id=' . $key . '">' . $value . '</a>';
 307      $s .= '</td></tr>';
 308  }
 309  echo '<table width="100%" cellspacing="1" bgcolor="black">' . $s . '</table>';
 310  ?>
 311              </td>
 312          </tr>
 313          <tr>
 314              <td colspan="3" nowrap="nowrap">
 315                  <strong><?php echo $AppUI->_('Description'); ?></strong><br />
 316              </td>
 317           </tr>
 318           <tr>
 319            <td class="hilite" colspan="3">
 320                  <?php $newstr = str_replace(chr(10), '<br />', $obj->task_description);
 321  echo $newstr; ?>
 322            </td>
 323          </tr>
 324  <?php
 325  $q->addTable('departments', 'd');
 326  $q->addTable('task_departments', 't');
 327  $q->addWhere('t.department_id = d.dept_id');
 328  $q->addWhere('t.task_id = ' . (int)$task_id);
 329  $q->addQuery('dept_id, dept_name, dept_phone');
 330  $department = new CDepartment;
 331  $department->setAllowedSQL($AppUI->user_id, $q);
 332  $depts = $q->loadHashList('dept_id');
 333  $q->clear();
 334  if (count($depts)) {
 335  ?>
 336              <tr>
 337                  <td><strong><?php echo $AppUI->_('Departments'); ?></strong></td>
 338              </tr>
 339              <tr>
 340                  <td colspan="3" class="hilite">
 341                      <?php
 342      foreach ($depts as $dept_id => $dept_info) {
 343          echo '<div>' . $dept_info['dept_name'];
 344          if ($dept_info['dept_phone'] != '') {
 345              echo '( ' . $dept_info['dept_phone'] . ' )';
 346          }
 347          echo '</div>';
 348      }
 349  ?>
 350                  </td>
 351              </tr>
 352  <?php
 353  }
 354  
 355  if ($AppUI->isActiveModule('contacts') && $perms->checkModule('contacts', 'view')) {
 356      $q->addTable('contacts', 'c');
 357      $q->addJoin('task_contacts', 'tc', 'tc.contact_id = c.contact_id', 'inner');
 358      $q->leftJoin('departments', 'd', 'dept_id = contact_department');
 359      $q->addWhere('tc.task_id = ' . (int)$obj->task_id);
 360      $q->addQuery('c.contact_id, contact_first_name, contact_last_name, contact_email');
 361      $q->addQuery('contact_phone, dept_name');
 362      $q->addWhere('(contact_owner = ' . (int)$AppUI->user_id . ' OR contact_private = 0)');
 363      $department->setAllowedSQL($AppUI->user_id, $q);
 364      $contacts = $q->loadHashList('contact_id');
 365      $q->clear();
 366      if (count($contacts) > 0) {
 367  ?>
 368                  <tr>
 369                      <td><strong><?php echo $AppUI->_('Task Contacts'); ?></strong></td>
 370                  </tr>
 371                  <tr>
 372                      <td colspan="3" class="hilite">
 373  <?php
 374          echo '<table cellspacing="1" cellpadding="2" border="0" width="100%" bgcolor="black">';
 375          echo '<tr><th>' . $AppUI->_('Name') . '</font></th><th>' . $AppUI->_('Email') . '</th><th>' . $AppUI->_('Phone') . '</th><th>' . $AppUI->_('Department') . '</th></tr>';
 376          foreach ($contacts as $contact_id => $contact_data) {
 377              echo '<tr>';
 378              echo '<td class="hilite"><a href="index.php?m=contacts&a=addedit&contact_id=' . $contact_id . '">' . $contact_data['contact_first_name'] . ' ' . $contact_data['contact_last_name'] . '</a></td>';
 379              echo '<td class="hilite"><a href="mailto: ' . $contact_data['contact_email'] . '">' . $contact_data['contact_email'] . '</a></td>';
 380              echo '<td class="hilite">' . $contact_data['contact_phone'] . '</td>';
 381              echo '<td class="hilite">' . $contact_data['dept_name'] . '</td>';
 382              echo '</tr>';
 383          }
 384          echo '</table>';
 385  ?>
 386                      </td>
 387                  </tr>
 388           <?php
 389      }
 390  
 391      $q->addTable('contacts', 'c');
 392      $q->addJoin('project_contacts', 'pc', 'pc.contact_id = c.contact_id', 'inner');
 393      $q->leftJoin('departments', 'd', 'd.dept_id = c.contact_department');
 394      $q->addWhere('pc.project_id = ' . (int)$obj->task_project);
 395      $q->addQuery('c.contact_id, contact_first_name, contact_last_name, contact_email');
 396      $q->addQuery('contact_phone, dept_name');
 397      $q->addWhere('(contact_owner = ' . (int)$AppUI->user_id . ' OR contact_private = 0)');
 398      $department->setAllowedSQL($AppUI->user_id, $q);
 399      $contacts = $q->loadHashList('contact_id');
 400      $q->clear();
 401      if (count($contacts) > 0) {
 402  ?>
 403                  <tr>
 404                      <td><strong><?php echo $AppUI->_('Project Contacts'); ?></strong></td>
 405                  </tr>
 406                  <tr>
 407                      <td colspan="3" class="hilite">
 408  <?php
 409          echo '<table cellspacing="1" cellpadding="2" border="0" width="100%" bgcolor="black">';
 410          echo '<tr><th color="white">' . $AppUI->_('Name') . '</th><th>' . $AppUI->_('Email') . '</th><th>' . $AppUI->_('Phone') . '</th><th>' . $AppUI->_('Department') . '</th></tr>';
 411          foreach ($contacts as $contact_id => $contact_data) {
 412              echo '<tr>';
 413              echo '<td class="hilite"><a href="index.php?m=contacts&a=addedit&contact_id=' . $contact_id . '">' . $contact_data['contact_first_name'] . ' ' . $contact_data['contact_last_name'] . '</a></td>';
 414              echo '<td class="hilite"><a href="mailto: ' . $contact_data['contact_email'] . '">' . $contact_data['contact_email'] . '</a></td>';
 415              echo '<td class="hilite">' . $contact_data['contact_phone'] . '</td>';
 416              echo '<td class="hilite">' . $contact_data['dept_name'] . '</td>';
 417              echo '</tr>';
 418          }
 419          echo '</table>';
 420  ?>
 421                      </td>
 422                  </tr>
 423           <?php
 424      }
 425  
 426  }
 427  ?>
 428              <tr>
 429                  <td colspan="3">
 430  <?php
 431  require_once $AppUI->getSystemClass('CustomFields');
 432  $custom_fields = new CustomFields($m, $a, $obj->task_id, 'view');
 433  $custom_fields->printHTML();
 434  ?>
 435                   </td>
 436               </tr>
 437              </table>
 438           </td>
 439       </tr>
 440  </table>
 441  
 442  <?php
 443  $query_string = '?m=tasks&a=view&task_id=' . $task_id;
 444  $tabBox = new