[ Index ]

Source Code Reference for V1.00

title

Body

[close]

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

   1  <?php /* $Id: do_updatetask.php 168 2008-05-20 11:22:15Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/tasks/do_updatetask.php $ */
   2  if (!defined('W2P_BASE_DIR')) {
   3      die('You should not access this file directly.');
   4  }
   5  
   6  //There is an issue with international UTF characters, when stored in the database an accented letter
   7  //actually takes up two letters per say in the field length, this is a problem with costcodes since
   8  //they are limited in size so saving a costcode as REDACI�N would actually save REDACI� since the accent takes
   9  //two characters, so lets unaccent them, other languages should add to the replacements array too...
  10  function cleanText($text) {
  11      //This text file is not utf, its iso so we have to decode/encode
  12      $text = utf8_decode($text);
  13      $trade = array('�' => 'a', '�' => 'a', '�' => 'a', '�' => 'a', '�' => 'a', '�' => 'A', '�' => 'A', '�' => 'A', '�' => 'A', '�' => 'A', '�' => 'e', '�' => 'e', '�' => 'e', '�' => 'e', '�' => 'E', '�' => 'E', '�' => 'E', '�' => 'E', '�' => 'i', '�' => 'i', '�' => 'i', '�' => 'i', '�' => 'I', '�' => 'I', '�' => 'I', '�' => 'I', '�' => 'o', '�' => 'o', '�' => 'o', '�' => 'o', '�' => 'o', '�' => 'O', '�' => 'O', '�' => 'O', '�' => 'O', '�' => 'O', '�' => 'u', '�' => 'u', '�' => 'u', '�' => 'u', '�' => 'U', '�' => 'U', '�' => 'U', '�' => 'U', '�' => 'N', '�' => 'n');
  14      $text = strtr($text, $trade);
  15      $text = utf8_encode($text);
  16  
  17      return $text;
  18  }
  19  
  20  $notify_owner = isset($_POST['task_log_notify_owner']) ? $_POST['task_log_notify_owner'] : 0;
  21  
  22  $del = w2PgetParam($_POST, 'del', 0);
  23  $isNotNew = $_POST['task_log_id'];
  24  $perms = &$AppUI->acl();
  25  if ($del) {
  26      if (!$perms->checkModule('task_log', 'delete')) {
  27          $AppUI->redirect('m=public&a=access_denied');
  28      }
  29  } elseif ($isNotNew) {
  30      if (!$perms->checkModule('task_log', 'edit')) {
  31          $AppUI->redirect('m=public&a=access_denied');
  32      }
  33  } else {
  34      if (!$perms->checkModule('task_log', 'add')) {
  35          $AppUI->redirect('m=public&a=access_denied');
  36      }
  37  }
  38  
  39  $obj = new CTaskLog();
  40  
  41  if (!$obj->bind($_POST)) {
  42      $AppUI->setMsg($obj->getError(), UI_MSG_ERROR);
  43      $AppUI->redirect();
  44  }
  45  
  46  if ($obj->task_log_date) {
  47      $date = new CDate($obj->task_log_date . date('Hi'));
  48      $obj->task_log_date = $date->format(FMT_DATETIME_MYSQL);
  49  }
  50  $dot = strpos($obj->task_log_hours, ':');
  51  if ($dot > 0) {
  52      $log_duration_minutes = sprintf('%.3f', substr($obj->task_log_hours, $dot + 1) / 60.0);
  53      $obj->task_log_hours = floor($obj->task_log_hours) + $log_duration_minutes;
  54  }
  55  $obj->task_log_hours = round($obj->task_log_hours, 3);
  56  
  57  // prepare (and translate) the module name ready for the suffix
  58  $AppUI->setMsg('Task Log');
  59  if ($del) {
  60      if (($msg = $obj->delete())) {
  61          $AppUI->setMsg($msg, UI_MSG_ERROR);
  62      } else {
  63          $AppUI->setMsg('deleted', UI_MSG_ALERT);
  64      }
  65      $AppUI->redirect();
  66  } else {
  67      $obj->task_log_costcode = cleanText($obj->task_log_costcode);
  68      if (($msg = $obj->store())) {
  69          $AppUI->setMsg($msg, UI_MSG_ERROR);
  70          $AppUI->redirect();
  71      } else {
  72          $AppUI->setMsg($_POST['task_log_id'] ? 'updated' : 'inserted', UI_MSG_OK, true);
  73      }
  74  }
  75  
  76  $task = new CTask();
  77  $task->load($obj->task_log_task);
  78  
  79  $canEditTask = $perms->checkModuleItem('tasks', 'edit', $task_id);
  80  if ($canEditTask) {
  81      $task->htmlDecode();
  82      $task->check();
  83      $task_end_date = new CDate($task->task_end_date);
  84      $task->task_percent_complete = w2PgetParam($_POST, 'task_percent_complete', null);
  85      
  86      if (w2PgetParam($_POST, 'task_end_date', '') != '') {
  87          $new_date = new CDate($_POST['task_end_date']);
  88          $new_date->setTime($task_end_date->hour, $task_end_date->minute, $task_end_date->second);
  89          $task->task_end_date = $new_date->format(FMT_DATETIME_MYSQL);
  90      }
  91      
  92      if ($task->task_percent_complete >= 100 && (!$task->task_end_date || $task->task_end_date == '0000-00-00 00:00:00')) {
  93          $task->task_end_date = $obj->task_log_date;
  94      }
  95      
  96      if (($msg = $task->store())) {
  97          $AppUI->setMsg($msg, UI_MSG_ERROR, true);
  98      }
  99      
 100      $new_task_end = new CDate($task->task_end_date);
 101      if ($new_task_end->dateDiff($task_end_date)) {
 102          $task->addReminder();
 103      }
 104  }
 105  
 106  if ($notify_owner) {
 107      if ($msg = $task->notifyOwner()) {
 108          $AppUI->setMsg($msg, UI_MSG_ERROR);
 109      }
 110  }
 111  
 112  // Check if we need to email the task log to anyone.
 113  $email_assignees = w2PgetParam($_POST, 'email_assignees', null);
 114  $email_task_contacts = w2PgetParam($_POST, 'email_task_contacts', null);
 115  $email_project_contacts = w2PgetParam($_POST, 'email_project_contacts', null);
 116  $email_others = w2PgetParam($_POST, 'email_others', '');
 117  $email_extras = w2PgetParam($_POST, 'email_extras', null);
 118  
 119  if ($task->email_log($obj, $email_assignees, $email_task_contacts, $email_project_contacts, $email_others, $email_extras)) {
 120      $obj->store(); // Save the updated message. It is not an error if this fails.
 121  }
 122  
 123  $AppUI->redirect('m=tasks&a=view&task_id=' . $obj->task_log_task . '&tab=0#tasklog' . $obj->task_log_id);
 124  ?>


Generated: Thu Jan 8 03:00:03 2009 Cross-referenced by PHPXref 0.7