/** * Copyright 2001-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.horde.org/licenses/gpl. * * @author Jon Parise <*****@*****.**> * @author Jan Schneider <*****@*****.**> */ function _delete($task_id, $tasklist_id) { global $injector, $nag_shares, $notification, $registry; if (!empty($task_id)) { try { $task = Nag::getTask($tasklist_id, $task_id); $task->loadChildren(); try { $share = $nag_shares->getShare($tasklist_id); } catch (Horde_Share_Exception $e) { throw new Nag_Exception($e); } if (!$share->hasPermission($registry->getAuth(), Horde_Perms::DELETE)) { $notification->push(_("Access denied deleting task."), 'horde.error'); } else { $storage = $injector->getInstance('Nag_Factory_Driver')->create($tasklist_id); try { $storage->delete($task_id); } catch (Nag_Exception $e) { $notification->push(sprintf(_("There was a problem deleting %s: %s"), $task->name, $e->getMessage()), 'horde.error'); } $notification->push(sprintf(_("Deleted %s."), $task->name), 'horde.success'); } } catch (Nag_Exception $e) { $notification->push(sprintf(_("Error deleting task: %s"), $e->getMessage()), 'horde.error'); } } /* Return to the last page or to the task list. */ if ($url = Horde_Util::getFormData('url')) { header('Location: ' . $url); exit; } Horde::url('list.php', true)->redirect(); }
/** */ public function result($task, $tasklist) { global $nag_shares, $notification, $registry; try { $share = $nag_shares->getShare($tasklist); $task = Nag::getTask($tasklist, $task); if (!$share->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $result = array('error' => 'permission denied'); $notification->push(_("Access denied completing this task."), 'horde.error'); } else { $wasCompleted = $task->completed; $task->toggleComplete(); $task->save(); if ($task->completed) { $result = array('data' => 'complete'); $notification->push(sprintf(_("Completed %s."), $task->name), 'horde.success'); } elseif (!$wasCompleted) { $result = array('data' => 'incomplete'); $notification->push(sprintf(_("%s is still incomplete."), $task->name), 'horde.success'); } else { $result = array('data' => 'incomplete'); $notification->push(sprintf(_("%s is now incomplete."), $task->name), 'horde.success'); } } } catch (Exception $e) { $result = array('error' => $e->getMessage()); $notification->push(sprintf(_("There was a problem completing %s: %s"), $task->name, $e->getMessage()), 'horde.error'); } return $result; }
public function getTask() { $out = new StdClass(); if (!isset($this->vars->task) || !isset($this->vars->tasklist)) { $out->error = 'Missing Parameters'; } else { $task = Nag::getTask($this->vars->tasklist, $this->vars->task); $out->task = $task->toJson(true); } return $out; }
/** * Returns the parent task of this task, if one exists. * * @return mixed The parent task, null if none exists */ public function getParent() { if (!$this->parent_id) { return null; } return Nag::getTask($this->tasklist, $this->parent_id); }
$notification->push(_("Task not found"), 'horde.error'); Horde::url('list.php', true)->redirect(); } $task_id = $task->id; $tasklist_id = $task->tasklist; } else { /* If we aren't provided with a task and tasklist, redirect to * list.php. */ $task_id = Horde_Util::getFormData('task'); $tasklist_id = Horde_Util::getFormData('tasklist'); if (!isset($task_id) || !$tasklist_id) { Horde::url('list.php', true)->redirect(); } /* Get the current task. */ try { $task = Nag::getTask($tasklist_id, $task_id); } catch (Horde_Exception_NotFound $e) { $notification->push(_("Task not found"), 'horde.error'); Horde::url('list.php', true)->redirect(); } } /* Load child tasks */ $task->loadChildren(false); /* Check permissions on $tasklist_id. */ $share = $GLOBALS['nag_shares']->getShare($tasklist_id); if (!$share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) { $notification->push(_("You do not have permission to view this task list."), 'horde.error'); Horde::url('list.php', true)->redirect(); } $links = array(); $page_output->addScriptFile('stripe.js', 'horde');
/** */ public function davPutObject($collection, $object, $data) { $dav = $GLOBALS['injector']->getInstance('Horde_Dav_Storage'); $internal = $dav->getInternalCollectionId($collection, 'tasks') ?: $collection; if (!Nag::hasPermission($internal, Horde_Perms::EDIT)) { throw new Nag_Exception("Task List does not exist or no permission to edit"); } $ical = new Horde_Icalendar(); if (!$ical->parsevCalendar($data)) { throw new Nag_Exception(_("There was an error importing the iCalendar data.")); } $storage = $GLOBALS['injector']->getInstance('Nag_Factory_Driver')->create($internal); foreach ($ical->getComponents() as $content) { if (!$content instanceof Horde_Icalendar_Vtodo) { continue; } $task = new Nag_Task(); $task->fromiCalendar($content); try { try { $existing_id = $dav->getInternalObjectId($object, $internal) ?: preg_replace('/\\.ics$/', '', $object); } catch (Horde_Dav_Exception $e) { $existing_id = $object; } $existing_task = Nag::getTask($internal, $existing_id); /* Check if our task is newer then the existing - get the * task's history. */ $modified = $this->_modified($internal, $existing_task->uid); try { if (!empty($modified) && $content->getAttribute('LAST-MODIFIED') < $modified) { /* LAST-MODIFIED timestamp of existing entry is newer: * don't replace it. */ continue; } } catch (Horde_Icalendar_Exception $e) { } $task->owner = $existing_task->owner; $storage->modify($existing_task->id, $task->toHash()); } catch (Horde_Exception_NotFound $e) { $hash = $task->toHash(); $newTask = $storage->add($hash); $dav->addObjectMap($newTask[0], $object, $internal); } } }
/** * Returns a task object. * * @param string $tasklist A tasklist id. * @param string $id A task id. * * @return Nag_Task The matching task object. */ public function getTask($tasklist, $id) { if (!Nag::hasPermission($tasklist, Horde_Perms::READ)) { throw new Horde_Exception_PermissionDenied(); } return Nag::getTask($tasklist, $id); }
public function processRequest(Horde_Controller_Request $request, Horde_Controller_Response $response) { global $nag_shares, $prefs, $conf; $vars = Horde_Variables::getDefaultVariables(); $registry = $this->getInjector()->getInstance('Horde_Registry'); $notification = $this->getInjector()->getInstance('Horde_Notification'); $form = new Nag_Form_Task($vars, $vars->get('task_id') ? sprintf(_("Edit: %s"), $vars->get('name')) : _("New Task")); if (!$form->validate($vars)) { // Hideous $_REQUEST['actionID'] = 'task_form'; require NAG_BASE . '/task.php'; exit; } $form->getInfo($vars, $info); // Check if we are here due to a search_return push. if ($vars->search_return) { Horde::url('list.php', true)->add(array('actionID' => 'search_return', 'list' => $vars->list, 'tab_name' => $vars->tab_name))->redirect(); } // Check if we are here due to a deletebutton push if ($vars->deletebutton) { try { $share = $nag_shares->getShare($info['old_tasklist']); } catch (Horde_Share_Exception $e) { $notification->push(sprintf(_("Access denied deleting task: %s"), $e->getMessage()), 'horde.error'); Horde::url('list.php', true)->redirect(); } $task = Nag::getTask($info['old_tasklist'], $info['task_id']); $task->loadChildren(); if (!$share->hasPermission($registry->getAuth(), Horde_Perms::DELETE)) { $notification->push(_("Access denied deleting task"), 'horde.error'); Horde::url('list.php', true)->redirect(); } else { $storage = $this->getInjector()->getInstance('Nag_Factory_Driver')->create($info['old_tasklist']); try { $storage->delete($info['task_id']); $notification->push(_("Task successfully deleted"), 'horde.success'); Horde::url('list.php', true)->redirect(); } catch (Nag_Exception $e) { $notification->push(sprintf(_("Error deleting task: %s"), $e->getMessage()), 'horde.error'); Horde::url('list.php', true)->redirect(); } } } if ($prefs->isLocked('default_tasklist') || count($this->_getTasklists()) <= 1) { $info['tasklist_id'] = $info['old_tasklist'] = Nag::getDefaultTasklist(Horde_Perms::EDIT); } try { $share = $nag_shares->getShare($info['tasklist_id']); } catch (Horde_Share_Exception $e) { $notification->push(sprintf(_("Access denied saving task: %s"), $e->getMessage()), 'horde.error'); Horde::url('list.php', true)->redirect(); } if (!$share->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $notification->push(_("Access denied saving task to this task list."), 'horde.error'); Horde::url('list.php', true)->redirect(); } /* If a task id is set, we're modifying an existing task. Otherwise, * we're adding a new task with the provided attributes. */ if (!empty($info['task_id']) && !empty($info['old_tasklist'])) { $storage = $this->getInjector()->getInstance('Nag_Factory_Driver')->create($info['old_tasklist']); $info['tasklist'] = $info['tasklist_id']; try { $storage->modify($info['task_id'], $info); } catch (Nag_Exception $e) { $notification->push(sprintf(_("There was a problem saving the task: %s."), $e->getMessage()), 'horde.error'); Horde::url('list.php', true)->redirect(); } $method = Nag::ITIP_UPDATE; $newid = array($info['task_id']); } else { /* Check permissions. */ $perms = $this->getInjector()->getInstance('Horde_Core_Perms'); if ($perms->hasAppPermission('max_tasks') !== true && $perms->hasAppPermission('max_tasks') <= Nag::countTasks()) { Horde::url('list.php', true)->redirect(); } /* Creating a new task. */ $storage = $this->getInjector()->getInstance('Nag_Factory_Driver')->create($info['tasklist_id']); // These must be unset since the form sets them to NULL unset($info['owner']); unset($info['uid']); try { $newid = $storage->add($info); } catch (Nag_Exception $e) { $notification->push(sprintf(_("There was a problem saving the task: %s."), $e->getMessage()), 'horde.error'); Horde::url('list.php', true)->redirect(); } $method = Nag::ITIP_REQUEST; } if ($conf['assignees']['allow_external']) { Nag::sendITipNotifications($storage->get($newid[0]), $notification, $method); } $notification->push(sprintf(_("Saved %s."), $info['name']), 'horde.success'); /* Return to the last page or to the task list. */ if ($vars->savenewbutton) { $url = Horde::url('task.php', true)->add(array('actionID' => 'add_task', 'tasklist_id' => $info['tasklist_id'], 'parent' => $info['parent'])); } else { $url = Horde_Util::getFormData('url', (string) Horde::url('list.php', true)); $url = Horde::url($url, true); } $response->setRedirectUrl($url); }