/nag/view.php

https://github.com/finger2000/horde · PHP · 127 lines · 98 code · 13 blank · 16 comment · 23 complexity · eae868a3a987fce16ef98df3bf39e32f MD5 · raw file

  1. <?php
  2. /**
  3. * Copyright 2001-2011 Horde LLC (http://www.horde.org/)
  4. *
  5. * See the enclosed file COPYING for license information (GPL). If you
  6. * did not receive this file, see http://www.horde.org/licenses/gpl.
  7. */
  8. require_once dirname(__FILE__) . '/lib/Application.php';
  9. Horde_Registry::appInit('nag');
  10. /* We can either have a UID or a taskId and a tasklist. Check for
  11. * UID first. */
  12. if ($uid = Horde_Util::getFormData('uid')) {
  13. $storage = Nag_Driver::singleton();
  14. try {
  15. $task = $storage->getByUID($uid);
  16. } catch (Nag_Exception $e) {
  17. Horde::url('list.php', true)->redirect();
  18. }
  19. $task_id = $task->id;
  20. $tasklist_id = $task->tasklist;
  21. } else {
  22. /* If we aren't provided with a task and tasklist, redirect to
  23. * list.php. */
  24. $task_id = Horde_Util::getFormData('task');
  25. $tasklist_id = Horde_Util::getFormData('tasklist');
  26. if (!isset($task_id) || !$tasklist_id) {
  27. Horde::url('list.php', true)->redirect();
  28. }
  29. /* Get the current task. */
  30. $task = Nag::getTask($tasklist_id, $task_id);
  31. }
  32. /* If the requested task doesn't exist, display an error message. */
  33. if (!isset($task) || !isset($task->id)) {
  34. $notification->push(_("Task not found."), 'horde.error');
  35. Horde::url('list.php', true)->redirect();
  36. }
  37. /* Load child tasks */
  38. $task->loadChildren();
  39. /* Check permissions on $tasklist_id. */
  40. $share = $GLOBALS['nag_shares']->getShare($tasklist_id);
  41. if (!$share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
  42. $notification->push(_("You do not have permission to view this tasklist."), 'horde.error');
  43. Horde::url('list.php', true)->redirect();
  44. }
  45. /* Get the task's history. */
  46. $created = null;
  47. $modified = null;
  48. $completed = null;
  49. $userId = $GLOBALS['registry']->getAuth();
  50. $createdby = '';
  51. $modifiedby = '';
  52. if (!empty($task->uid)) {
  53. try {
  54. $log = $GLOBALS['injector']->getInstance('Horde_History')->getHistory('nag:' . $tasklist_id . ':' . $task->uid);
  55. foreach ($log as $entry) {
  56. switch ($entry['action']) {
  57. case 'add':
  58. $created = $entry['ts'];
  59. if ($userId != $entry['who']) {
  60. $createdby = sprintf(_("by %s"), Nag::getUserName($entry['who']));
  61. } else {
  62. $createdby = _("by me");
  63. }
  64. break;
  65. case 'modify':
  66. $modified = $entry['ts'];
  67. if ($userId != $entry['who']) {
  68. $modifiedby = sprintf(_("by %s"), Nag::getUserName($entry['who']));
  69. } else {
  70. $modifiedby = _("by me");
  71. }
  72. break;
  73. case 'complete':
  74. if (!empty($entry['ts'])) {
  75. $completed = $entry['ts'];
  76. }
  77. }
  78. }
  79. } catch (Exception $e) {}
  80. }
  81. $title = $task->name;
  82. $links = array();
  83. Horde::addScriptFile('stripe.js', 'horde');
  84. $taskurl = Horde_Util::addParameter('task.php',
  85. array('task' => $task_id,
  86. 'tasklist' => $tasklist_id));
  87. try {
  88. $share = $GLOBALS['nag_shares']->getShare($tasklist_id);
  89. } catch (Horde_Share_Exception $e) {
  90. Horde::logMessage($e->getMessage(), 'ERR');
  91. throw new Nag_Exception($e);
  92. }
  93. if ($share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
  94. if (!$task->completed) {
  95. $links[] = Horde::widget(Horde::url(Horde_Util::addParameter($taskurl, 'actionID', 'complete_task')), _("Complete"), 'smallheader', '', '', _("_Complete"));
  96. }
  97. if (!$task->private || $task->owner == $GLOBALS['registry']->getAuth()) {
  98. $links[] = Horde::widget(Horde::url(Horde_Util::addParameter($taskurl, 'actionID', 'modify_task')), _("Edit"), 'smallheader', '', '', _("_Edit"));
  99. }
  100. }
  101. if ($share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) {
  102. $links[] = Horde::widget(Horde::url(Horde_Util::addParameter($taskurl, 'actionID', 'delete_task')), _("Delete"), 'smallheader', '', $prefs->getValue('delete_opt') ? 'return window.confirm(\'' . addslashes(_("Really delete this task?")) . '\');' : '', _("_Delete"));
  103. }
  104. require $registry->get('templates', 'horde') . '/common-header.inc';
  105. echo Nag::menu();
  106. Nag::status();
  107. /* Set up alarm units and value. */
  108. $task_alarm = $task->alarm;
  109. if (!$task->due) {
  110. $task_alarm = 0;
  111. }
  112. $alarm_text = Nag::formatAlarm($task_alarm);
  113. require NAG_TEMPLATES . '/view/task.inc';
  114. require $registry->get('templates', 'horde') . '/common-footer.inc';