/modules/tasks/do_updatetask.php

https://bitbucket.org/isaaczhang/dotproject · PHP · 129 lines · 103 code · 16 blank · 10 comment · 21 complexity · d9a9ccc534e859d64f1d1e81d771206f MD5 · raw file

  1. <?php /* TASKS $Id: do_updatetask.php 6149 2012-01-09 11:58:40Z ajdonnison $ */
  2. if (!defined('DP_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
  7. * letter actually takes up two letters per say in the field length, this is a problem with
  8. * costcodes sincE they are limited in size so saving a costcode as REDACI�N would actually
  9. * save REDACI� since the accent takes two characters, so lets unaccent them, other languages
  10. * should add to the replacements array too...
  11. */
  12. function cleanText($text) {
  13. //This text file is not utf, its iso so we have to decode/encode
  14. $text = utf8_decode($text);
  15. $trade = array('�'=>'a','�'=>'a','�'=>'a',
  16. '�'=>'a','�'=>'a',
  17. '�'=>'A','�'=>'A','�'=>'A',
  18. '�'=>'A','�'=>'A',
  19. '�'=>'e','�'=>'e',
  20. '�'=>'e','�'=>'e',
  21. '�'=>'E','�'=>'E',
  22. '�'=>'E','�'=>'E',
  23. '�'=>'i','�'=>'i',
  24. '�'=>'i','�'=>'i',
  25. '�'=>'I','�'=>'I',
  26. '�'=>'I','�'=>'I',
  27. '�'=>'o','�'=>'o','�'=>'o',
  28. '�'=>'o','�'=>'o',
  29. '�'=>'O','�'=>'O','�'=>'O',
  30. '�'=>'O','�'=>'O',
  31. '�'=>'u','�'=>'u',
  32. '�'=>'u','�'=>'u',
  33. '�'=>'U','�'=>'U',
  34. '�'=>'U','�'=>'U',
  35. '�'=>'N','�'=>'n');
  36. $text = strtr($text,$trade);
  37. $text = utf8_encode($text);
  38. return $text;
  39. }
  40. $notify_owner = ((isset($_POST['task_log_notify_owner'])) ? $_POST['task_log_notify_owner'] : 0);
  41. $del = (int)dPgetParam($_POST, 'del', 0);
  42. $obj = new CTaskLog();
  43. if (!($obj->bind($_POST))) {
  44. $AppUI->setMsg($obj->getError(), UI_MSG_ERROR);
  45. $AppUI->redirect();
  46. }
  47. if ($obj->task_log_date) {
  48. $date = new CDate($obj->task_log_date);
  49. $obj->task_log_date = $date->format(FMT_DATETIME_MYSQL);
  50. }
  51. $dot = mb_strpos($obj->task_log_hours, ':');
  52. if ($dot > 0) {
  53. $log_duration_minutes = sprintf('%.3F', mb_substr($obj->task_log_hours, $dot + 1)/60.0);
  54. $obj->task_log_hours = sprintf('%.3F', floor($obj->task_log_hours) + $log_duration_minutes);
  55. }
  56. $obj->task_log_hours = sprintf('%.3F', round($obj->task_log_hours, 3));
  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_labor_cost = get_labor_cost($obj->task_log_creator, $obj->task_log_hours);
  68. $obj->task_log_costcode = cleanText($obj->task_log_costcode);
  69. if (($msg = $obj->store())) {
  70. $AppUI->setMsg($msg, UI_MSG_ERROR);
  71. $AppUI->redirect();
  72. } else {
  73. $AppUI->setMsg(@$_POST['task_log_id'] ? 'updated' : 'inserted', UI_MSG_OK, true);
  74. }
  75. }
  76. $task = new CTask();
  77. $task->load($obj->task_log_task);
  78. $task->htmlDecode();
  79. $task->check();
  80. $task_end_date = new CDate($task->task_end_date);
  81. $task->task_percent_complete = dPgetCleanParam($_POST, 'task_percent_complete', null);
  82. if (dPgetCleanParam($_POST, 'task_end_date', '') != '') {
  83. $new_date = new CDate($_POST['task_end_date']);
  84. $new_date->setTime($task_end_date->hour, $task_end_date->minute, $task_end_date->second);
  85. $task->task_end_date = $new_date->format(FMT_DATETIME_MYSQL);
  86. }
  87. if ($task->task_percent_complete >= 100 && (!($task->task_end_date)
  88. || $task->task_end_date == '0000-00-00 00:00:00')) {
  89. $task->task_end_date = $obj->task_log_date;
  90. }
  91. if (($msg = $task->store())) {
  92. $AppUI->setMsg($msg, UI_MSG_ERROR, true);
  93. }
  94. $new_task_end = new CDate($task->task_end_date);
  95. if ($new_task_end->dateDiff($task_end_date)) {
  96. $task->addReminder();
  97. }
  98. if ($notify_owner && $msg = $task->notifyOwner()) {
  99. $AppUI->setMsg($msg, UI_MSG_ERROR);
  100. }
  101. // Check if we need to email the task log to anyone.
  102. $email_assignees = dPgetCleanParam($_POST, 'email_assignees', null);
  103. $email_task_contacts = dPgetCleanParam($_POST, 'email_task_contacts', null);
  104. $email_project_contacts = dPgetCleanParam($_POST, 'email_project_contacts', null);
  105. $email_others = dPgetCleanParam($_POST, 'email_others', '');
  106. $email_extras = dPgetCleanParam($_POST, 'email_extras', null);
  107. if ($task->email_log($obj, $email_assignees, $email_task_contacts, $email_project_contacts,
  108. $email_others, $email_extras)) {
  109. $obj->store(); // Save the updated message. It is not an error if this fails.
  110. }
  111. $AppUI->redirect('m=tasks&a=view&task_id=' . $obj->task_log_task . '&tab=0#tasklog'
  112. . $obj->task_log_id);
  113. ?>