Overview

Packages

  • Nag
  • None

Classes

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