/** * TODO */ public function saveTask() { if (!$GLOBALS['registry']->hasMethod('tasks/updateTask') || !$GLOBALS['registry']->hasMethod('tasks/addTask')) { return false; } $id = $this->vars->task_id; $list = $this->vars->old_tasklist; $task = $this->vars->task; $result = $this->_signedResponse('tasklists|tasks/' . $task['tasklist']); $due = trim($task['due_date'] . ' ' . $task['due_time']); if (!empty($due)) { try { $due = Kronolith::parseDate($due); $task['due'] = $due->timestamp(); } catch (Exception $e) { $GLOBALS['notification']->push($e, 'horde.error'); return $result; } } if ($task['alarm']['on']) { $value = $task['alarm']['value']; $unit = $task['alarm']['unit']; if ($value == 0) { $value = $unit = 1; } $task['alarm'] = $value * $unit; if (isset($task['alarm_methods']) && isset($task['methods'])) { foreach (array_keys($task['methods']) as $method) { if (!in_array($method, $task['alarm_methods'])) { unset($task['methods'][$method]); } } foreach ($task['alarm_methods'] as $method) { if (!isset($task['methods'][$method])) { $task['methods'][$method] = array(); } } } else { $task['methods'] = array(); } } else { $task['alarm'] = 0; $task['methods'] = array(); } unset($task['alarm_methods']); if (!isset($task['completed'])) { $task['completed'] = false; } if ($this->vars->recur && !empty($due)) { $task['recurrence'] = Kronolith_Event::readRecurrenceForm($due, 'UTC'); } $task['tags'] = Horde_Util::getFormData('tags'); try { $ids = $id && $list ? $GLOBALS['registry']->tasks->updateTask($list, $id, $task) : $GLOBALS['registry']->tasks->addTask($task); if (!$id) { $id = $ids[0]; } $task = $GLOBALS['registry']->tasks->getTask($task['tasklist'], $id); $result->tasks = array($id => $task->toJson(false, $GLOBALS['prefs']->getValue('twentyFour') ? 'H:i' : 'h:i A')); $result->type = $task->completed ? 'complete' : 'incomplete'; $result->list = $task->tasklist; } catch (Exception $e) { $GLOBALS['notification']->push($e, 'horde.error'); return $result; } if ($due && ($kronolith_driver = $this->_getDriver('tasklists|tasks/' . $task->tasklist))) { try { $event = $kronolith_driver->getEvent('_tasks' . $id); $end = clone $due; $end->hour = 23; $end->min = $end->sec = 59; $start = clone $due; $start->hour = $start->min = $start->sec = 0; $events = array(); Kronolith::addEvents($events, $event, $start, $end, true, true); if (count($events)) { $result->events = $events; } } catch (Horde_Exception_NotFound $e) { } catch (Exception $e) { $GLOBALS['notification']->push($e, 'horde.error'); } } return $result; }