PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/nag/lib/Block/Summary.php

https://github.com/sgtcarneiro/horde
PHP | 276 lines | 237 code | 27 blank | 12 comment | 18 complexity | c71fd0d5376568c4fc5a754f87bcab93 MD5 | raw file
  1. <?php
  2. /**
  3. */
  4. class Nag_Block_Summary extends Horde_Core_Block
  5. {
  6. /**
  7. */
  8. public function __construct($app, $params = array())
  9. {
  10. parent::__construct($app, $params);
  11. $this->_name = _("Tasks Summary");
  12. }
  13. /**
  14. */
  15. protected function _title()
  16. {
  17. global $registry;
  18. $label = !empty($this->_params['block_title'])
  19. ? $this->_params['block_title']
  20. : $registry->get('name');
  21. return Horde::url($registry->getInitialPage(), true)->link()
  22. . htmlspecialchars($label) . '</a>';
  23. }
  24. /**
  25. */
  26. protected function _params()
  27. {
  28. $cManager = new Horde_Prefs_CategoryManager();
  29. $categories = array();
  30. foreach ($cManager->get() as $c) {
  31. $categories[$c] = $c;
  32. }
  33. $categories['unfiled'] = _("Unfiled");
  34. $tasklists = array();
  35. foreach (Nag::listTasklists() as $id => $tasklist) {
  36. $tasklists[$id] = $tasklist->get('name');
  37. }
  38. return array(
  39. 'block_title' => array(
  40. 'type' => 'text',
  41. 'name' => _("Block title"),
  42. 'default' => $GLOBALS['registry']->get('name')
  43. ),
  44. 'show_pri' => array(
  45. 'type' => 'checkbox',
  46. 'name' => _("Show priorities?"),
  47. 'default' => 1
  48. ),
  49. 'show_actions' => array(
  50. 'type' => 'checkbox',
  51. 'name' => _("Show action buttons?"),
  52. 'default' => 1
  53. ),
  54. 'show_due' => array(
  55. 'type' => 'checkbox',
  56. 'name' => _("Show due dates?"),
  57. 'default' => 1
  58. ),
  59. 'show_tasklist' => array(
  60. 'type' => 'checkbox',
  61. 'name' => _("Show tasklist name?"),
  62. 'default' => 1
  63. ),
  64. 'show_alarms' => array(
  65. 'type' => 'checkbox',
  66. 'name' => _("Show task alarms?"),
  67. 'default' => 1
  68. ),
  69. 'show_category' => array(
  70. 'type' => 'checkbox',
  71. 'name' => _("Show task category?"),
  72. 'default' => 1
  73. ),
  74. 'show_overdue' => array(
  75. 'type' => 'checkbox',
  76. 'name' => _("Always show overdue tasks?"),
  77. 'default' => 1
  78. ),
  79. 'show_completed' => array(
  80. 'type' => 'checkbox',
  81. 'name' => _("Always show completed and future tasks?"),
  82. 'default' => 1
  83. ),
  84. 'show_tasklists' => array(
  85. 'type' => 'multienum',
  86. 'name' => _("Show tasks from these tasklists"),
  87. 'default' => array($GLOBALS['registry']->getAuth()),
  88. 'values' => $tasklists
  89. ),
  90. 'show_categories' => array(
  91. 'type' => 'multienum',
  92. 'name' => _("Show tasks from these categories"),
  93. 'default' => array(),
  94. 'values' => $categories
  95. )
  96. );
  97. }
  98. /**
  99. */
  100. protected function _content()
  101. {
  102. global $registry, $prefs;
  103. $now = time();
  104. $html = '';
  105. if (!empty($this->_params['show_alarms'])) {
  106. $messages = array();
  107. try {
  108. $alarmList = Nag::listAlarms($now);
  109. } catch (Nag_Exception $e) {
  110. return '<em>' . htmlspecialchars($e->getMessage())
  111. . '</em>';
  112. }
  113. foreach ($alarmList as $task) {
  114. $differential = $task->due - $now;
  115. $key = $differential;
  116. while (isset($messages[$key])) {
  117. $key++;
  118. }
  119. $viewurl = Horde_Util::addParameter(
  120. 'view.php',
  121. array('task' => $task->id,
  122. 'tasklist' => $task->tasklist));
  123. $link = Horde::link(
  124. htmlspecialchars(Horde::url($viewurl, true)))
  125. . (!empty($task->name)
  126. ? htmlspecialchars($task->name) : _("[none]"))
  127. . '</a>';
  128. if ($differential >= -60 && $differential < 60) {
  129. $messages[$key] = sprintf(_("%s is due now."), $link);
  130. } elseif ($differential >= 60) {
  131. $messages[$key] = sprintf(
  132. _("%s is due in %s"),
  133. $link, Nag::secondsToString($differential));
  134. }
  135. }
  136. ksort($messages);
  137. foreach ($messages as $message) {
  138. $html .= '<tr><td class="control">'
  139. . Horde::img('alarm_small.png') . '&nbsp;&nbsp;<strong>'
  140. . $message . '</strong></td></tr>';
  141. }
  142. if (!empty($messages)) {
  143. $html .= '</table><br /><table cellspacing="0" width="100%" class="linedRow">';
  144. }
  145. }
  146. $i = 0;
  147. try {
  148. $tasks = Nag::listTasks(
  149. null, null, null,
  150. isset($this->_params['show_tasklists']) ?
  151. $this->_params['show_tasklists'] :
  152. array_keys(Nag::listTasklists(false, Horde_Perms::READ)),
  153. empty($this->_params['show_completed']) ?
  154. 0 :
  155. 1
  156. );
  157. } catch (Nag_Exception $e) {
  158. return '<em>' . htmlspecialchars($e->getMessage()) . '</em>';
  159. }
  160. $tasks->reset();
  161. while ($task = $tasks->each()) {
  162. // Only print tasks due in the past if the show_overdue flag is
  163. // on. Only display selected categories (possibly unfiled).
  164. if (($task->due > 0 &&
  165. $now > $task->due &&
  166. empty($this->_params['show_overdue'])) ||
  167. (!empty($this->_params['show_categories']) &&
  168. (!in_array($task->category, $this->_params['show_categories']) &&
  169. !(empty($task->category) &&
  170. in_array('unfiled', $this->_params['show_categories']))))) {
  171. continue;
  172. }
  173. if ($task->completed) {
  174. $style = 'closed';
  175. } elseif (!empty($task->due) && $task->due < $now) {
  176. $style = 'overdue';
  177. } else {
  178. $style = '';
  179. }
  180. $html .= '<tr class="' . $style . '">';
  181. if (!empty($this->_params['show_actions'])) {
  182. $taskurl = Horde_Util::addParameter(
  183. 'task.php',
  184. array('task' => $task->id,
  185. 'tasklist' => $task->tasklist,
  186. 'url' => Horde::selfUrl(true)));
  187. $label = sprintf(_("Edit \"%s\""), $task->name);
  188. $html .= '<td width="1%">'
  189. . Horde::link(htmlspecialchars(Horde::url(Horde_Util::addParameter($taskurl, 'actionID', 'modify_task'), true)), $label)
  190. . Horde::img('edit.png', $label)
  191. . '</a></td>';
  192. if ($task->completed) {
  193. $html .= '<td width="1%">'
  194. . Horde::img('checked.png', _("Completed")) . '</td>';
  195. } else {
  196. $label = sprintf(_("Complete \"%s\""), $task->name);
  197. $html .= '<td width="1%">'
  198. . Horde::link(htmlspecialchars(Horde::url(Horde_Util::addParameter($taskurl, 'actionID', 'complete_task'), true)), $label)
  199. . Horde::img('unchecked.png', $label) . '</a></td>';
  200. }
  201. }
  202. if (!empty($this->_params['show_pri'])) {
  203. $html .= '<td align="center">&nbsp;'
  204. . Nag::formatPriority($task->priority) . '&nbsp;</td>';
  205. }
  206. if (!empty($this->_params['show_tasklist'])) {
  207. $owner = $task->tasklist;
  208. $shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create();
  209. $share = $shares->getShare($owner);
  210. $owner = $share->get('name');
  211. $html .= '<td width="1%" class="nowrap">'
  212. . htmlspecialchars($owner) . '&nbsp;</td>';
  213. }
  214. $html .= '<td>';
  215. $viewurl = Horde_Util::addParameter(
  216. 'view.php',
  217. array('task' => $task->id,
  218. 'tasklist' => $task->tasklist));
  219. $html .= $task->treeIcons()
  220. . Horde::link(
  221. htmlspecialchars(Horde::url($viewurl, true)),
  222. $task->desc)
  223. . (!empty($task->name)
  224. ? htmlspecialchars($task->name) : _("[none]"))
  225. . '</a>';
  226. if ($task->due > 0 &&
  227. empty($task->completed) &&
  228. !empty($this->_params['show_due'])) {
  229. $html .= ' ('
  230. . strftime($prefs->getValue('date_format'), $task->due)
  231. . ')';
  232. }
  233. $html .= '</td>';
  234. if (!empty($this->_params['show_category'])) {
  235. $html .= '<td class="base-category" width="1%" style="'
  236. . $task->getCssStyle() . '">'
  237. . htmlspecialchars($task->category
  238. ? $task->category : _("Unfiled"))
  239. . '</td>';
  240. }
  241. $html .= "</tr>\n";
  242. }
  243. if (empty($html)) {
  244. return '<em>' . _("No tasks to display") . '</em>';
  245. }
  246. return '<table cellspacing="0" width="100%" class="linedRow">'
  247. . $html . '</table>';
  248. }
  249. }