1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: 12: 13: 14: 15: 16:
17: class Nag_Form_Task extends Horde_Form
18: {
19: public $delete;
20:
21: public function __construct($vars, $title = '', $delete = false)
22: {
23: parent::__construct($vars, $title);
24: $this->delete = $delete;
25: $tasklist_enums = array();
26: foreach (Nag::listTasklists(false, Horde_Perms::EDIT) as $tl_id => $tl) {
27: $tasklist_enums[$tl_id] = $tl->get('name');
28: }
29: $tasklist = $vars->get('tasklist_id');
30: if (empty($tasklist)) {
31: reset($tasklist_enums);
32: $tasklist = key($tasklist_enums);
33: }
34: $tasks = Nag::listTasks(null, null, null, array($tasklist), Nag::VIEW_FUTURE_INCOMPLETE);
35: $task_enums = array('' => _("No parent task"));
36: $tasks->reset();
37: while ($task = $tasks->each()) {
38: if ($vars->get('task_id') == $task->id) {
39: continue;
40: }
41: $task_enums[htmlspecialchars($task->id)] = str_repeat(' ', $task->indent * 4) . htmlspecialchars($task->name);
42: }
43: $users = array();
44: $share = $GLOBALS['nag_shares']->getShare($tasklist);
45: $users = $share->listUsers(Horde_Perms::READ);
46: $groups = $share->listGroups(Horde_Perms::READ);
47: if (count($groups)) {
48: $horde_group = $GLOBALS['injector']->getInstance('Horde_Group');
49: foreach ($groups as $group) {
50: $users = array_merge($users,
51: $horde_group->listUsers($group));
52: }
53: }
54: $users = array_flip($users);
55:
56: if (count($users)) {
57: foreach (array_keys($users) as $user) {
58: $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($user);
59: $fullname = $identity->getValue('fullname');
60: $users[$user] = strlen($fullname) ? $fullname : $user;
61: }
62: }
63: $priorities = array(
64: 1 => '1 ' . _("(highest)"),
65: 2 => 2,
66: 3 => 3,
67: 4 => 4,
68: 5 => '5 ' . _("(lowest)")
69: );
70: $this->addHidden('', 'actionID', 'text', true);
71: $this->addHidden('', 'task_id', 'text', false);
72: $this->addHidden('', 'old_tasklist', 'text', false);
73: $this->addHidden('', 'url', 'text', false);
74: $this->addVariable(_("Name"), 'name', 'text', true);
75: if (!$GLOBALS['prefs']->isLocked('default_tasklist') &&
76: count($tasklist_enums) > 1) {
77: $v = $this->addVariable(
78: _("Task List"), 'tasklist_id', 'enum', true, false, false,
79: array($tasklist_enums));
80: $v->setAction(Horde_Form_Action::factory('reload'));
81: }
82: $v = $this->addVariable(
83: _("Parent task"), 'parent', 'enum', false, false, false, array($task_enums));
84: $v->setOption('htmlchars', true);
85:
86: if (class_exists('Horde_Form_Type_category')) {
87: $this->addVariable(_("Category"), 'category', 'category', false);
88: } else {
89: $values = Horde_Array::valuesToKeys(Horde_Prefs_CategoryManager::get());
90: $this->addVariable(
91: _("Category"), 'category', 'enum', false, false, false,
92: array($values, _("Unfiled")));
93: }
94:
95: $this->addVariable(_("Assignee"), 'assignee', 'enum', false, false,
96: null, array($users, _("None")));
97: $this->addVariable(_("Private?"), 'private', 'boolean', false);
98: $this->addVariable(_("Due By"), 'due', 'Nag:NagDue', false);
99: $this->addVariable(_("Delay Start Until"), 'start', 'Nag:NagStart', false);
100: $this->addVariable(_("Alarm"), 'alarm', 'Nag:NagAlarm', false);
101:
102: $v = $this->addVariable(_("Notification"), 'methods', 'Nag:NagMethod', false);
103: $v->setAction(Horde_Form_Action::factory('reload'));
104:
105: $v = $this->addVariable(_("Priority"), 'priority', 'enum', false, false, false, array($priorities));
106: $v->setDefault(3);
107:
108: $this->addVariable(_("Estimated Time"), 'estimate', 'number', false);
109: $this->addVariable(_("Completed?"), 'completed', 'boolean', false);
110:
111: try {
112: $description = Horde::callHook('description_help', array(), 'nag');
113: } catch (Horde_Exception_HookNotSet $e) {
114: $description = '';
115: }
116: $this->addVariable(_("Description"), 'desc', 'longtext', false, false, $description);
117:
118: $buttons = array(_("Save"));
119: if ($delete) {
120: $buttons[] = _("Delete this task");
121: }
122: $this->setButtons($buttons);
123: }
124:
125: public function renderActive()
126: {
127: return parent::renderActive(new Nag_Form_Renderer_Task(array('varrenderer_driver' => array('nag', 'nag')), $this->delete), $this->_vars, Horde::url('task.php'), 'post');
128: }
129:
130: }
131: