Returns the default tasklist for the current user at the specified
permissions level.
public static getDefaultTasklist ( integer $permission = Horde_Perms::SHOW ) : string | ||
$permission | integer | Horde_Perms constant for permission level required. |
return | string | The default tasklist or null if none. |
$_prefs['sync_lists'] = array('value' => 'a:0:{}', 'type' => 'multienum', 'enum' => array(), 'desc' => _("Select the task lists that, in addition to the default, should be used for synchronization with external devices:"), 'on_init' => function ($ui) { $enum = array(); $sync = @unserialize($GLOBALS['prefs']->getValue('sync_lists')); if (empty($sync)) { $GLOBALS['prefs']->setValue('sync_lists', serialize(array(Nag::getDefaultTasklist(Horde_Perms::DELETE)))); } foreach (Nag::listTasklists(false, Horde_Perms::DELETE, false) as $key => $list) { if ($list->getName() != Nag::getDefaultTasklist(Horde_Perms::DELETE)) { $enum[$key] = Nag::getLabel($list); } } $ui->prefs['sync_lists']['enum'] = $enum; }, 'on_change' => function () { $sync = @unserialize($GLOBALS['prefs']->getValue('sync_lists')); $haveDefault = false; $default = Nag::getDefaultTasklist(Horde_Perms::DELETE); foreach ($sync as $cid) { if ($cid == $default) { $haveDefault = true; break; } } if (!$haveDefault) { $sync[] = $default; $GLOBALS['prefs']->setValue('sync_lists', serialize($sync)); } if ($GLOBALS['conf']['activesync']['enabled'] && !$GLOBALS['prefs']->getValue('activesync_no_multiplex')) { try { $sm = $GLOBALS['injector']->getInstance('Horde_ActiveSyncState'); $sm->setLogger($GLOBALS['injector']->getInstance('Horde_Log_Logger')); $devices = $sm->listDevices($GLOBALS['registry']->getAuth());
public function processRequest(Horde_Controller_Request $request, Horde_Controller_Response $response) { global $nag_shares, $prefs; $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(); } if (!$share->hasPermission($registry->getAuth(), Horde_Perms::DELETE)) { $notification->push(_("Access denied deleting task"), 'horde.error'); Horde::url('list.php', true)->redirect(); } $storage = $this->getInjector()->getInstance('Nag_Factory_Driver')->create($info['old_tasklist']); try { $storage->delete($info['task_id']); } catch (Nag_Exception $e) { $notification->push(sprintf(_("Error deleting task: %s"), $e->getMessage()), 'horde.error'); Horde::url('list.php', true)->redirect(); } $notification->push(_("Task successfully deleted"), 'horde.success'); Horde::url('list.php', true)->redirect(); } if ($prefs->isLocked('default_tasklist') || count(Nag::listTasklists(false, Horde_Perms::EDIT, false)) <= 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']; $result = $storage->modify($info['task_id'], $info); } 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(); } } $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); }
$_prefs['sync_lists'] = array('value' => 'a:0:{}', 'type' => 'multienum', 'enum' => array(), 'desc' => _("Select the task lists that, in addition to the default, should be used for synchronization with external devices:"), 'on_init' => function ($ui) { $enum = array(); $sync = @unserialize($GLOBALS['prefs']->getValue('sync_lists')); if (empty($sync)) { $GLOBALS['prefs']->setValue('sync_lists', serialize(array(Nag::getDefaultTasklist()))); } foreach (Nag::listTasklists(false, Horde_Perms::EDIT, false) as $key => $list) { if ($list->getName() != Nag::getDefaultTasklist(Horde_Perms::EDIT)) { $enum[$key] = Nag::getLabel($list); } } $ui->prefs['sync_lists']['enum'] = $enum; }, 'on_change' => function () { $sync = @unserialize($GLOBALS['prefs']->getValue('sync_lists')); $haveDefault = false; $default = Nag::getDefaultTasklist(Horde_Perms::EDIT); foreach ($sync as $cid) { if ($cid == $default) { $haveDefault = true; break; } } if (!$haveDefault) { $sync[] = $default; $GLOBALS['prefs']->setValue('sync_lists', serialize($sync)); } if ($GLOBALS['conf']['activesync']['enabled'] && !$GLOBALS['prefs']->getValue('activesync_no_multiplex')) { try { $sm = $GLOBALS['injector']->getInstance('Horde_ActiveSyncState'); $sm->setLogger($GLOBALS['injector']->getInstance('Horde_Log_Logger')); $devices = $sm->listDevices($GLOBALS['registry']->getAuth());
/** * Add additional items to the sidebar. * * @param Horde_View_Sidebar $sidebar The sidebar object. */ public function sidebar($sidebar) { // @TODO: Implement an injector factory for this. global $display_tasklists, $page_output, $prefs; $perms = $GLOBALS['injector']->getInstance('Horde_Core_Perms'); if (Nag::getDefaultTasklist(Horde_Perms::EDIT) && ($perms->hasAppPermission('max_tasks') === true || $perms->hasAppPermission('max_tasks') > Nag::countTasks())) { $sidebar->addNewButton(_("_New Task"), Horde::url('task.php')->add('actionID', 'add_task')); if ($GLOBALS['browser']->hasFeature('dom')) { $page_output->addScriptFile('scriptaculous/effects.js', 'horde'); $page_output->addScriptFile('redbox.js', 'horde'); $blank = new Horde_Url(); $sidebar->newExtra = $blank->link(array_merge(array('onclick' => 'RedBox.showInline(\'quickAddInfoPanel\'); $(\'quickText\').focus(); return false;'), Horde::getAccessKeyAndTitle(_("_Quick Add"), false, true))); require_once NAG_TEMPLATES . '/quick.inc'; } } $list = Horde::url('list.php'); $edit = Horde::url('tasklists/edit.php'); $user = $GLOBALS['registry']->getAuth(); $sidebar->containers['my'] = array('header' => array('id' => 'nag-toggle-my', 'label' => _("My Task Lists"), 'collapsed' => false)); if (!$GLOBALS['prefs']->isLocked('default_tasklist')) { $sidebar->containers['my']['header']['add'] = array('url' => Horde::url('tasklists/create.php'), 'label' => _("Create a new Task List")); } if ($GLOBALS['registry']->isAdmin()) { $sidebar->containers['system'] = array('header' => array('id' => 'nag-toggle-system', 'label' => _("System Task Lists"), 'collapsed' => true)); $sidebar->containers['system']['header']['add'] = array('url' => Horde::url('tasklists/create.php')->add('system', 1), 'label' => _("Create a new System Task List")); } $sidebar->containers['shared'] = array('header' => array('id' => 'nag-toggle-shared', 'label' => _("Shared Task Lists"), 'collapsed' => true)); foreach (Nag::listTasklists(false, Horde_Perms::SHOW, false) as $name => $tasklist) { $url = $list->add(array('display_tasklist' => $name, 'actionID' => in_array($name, $display_tasklists) ? 'remove_displaylist' : 'add_displaylist')); $row = array('selected' => in_array($name, $display_tasklists), 'url' => $url, 'label' => Nag::getLabel($tasklist), 'color' => $tasklist->get('color') ?: '#dddddd', 'edit' => $edit->add('t', $tasklist->getName()), 'type' => 'checkbox'); if ($GLOBALS['registry']->isAdmin() && is_null($tasklist->get('owner'))) { $sidebar->addRow($row, 'system'); } elseif ($tasklist->get('owner') == $user) { $sidebar->addRow($row, 'my'); } else { $sidebar->addRow($row, 'shared'); } } }
/** * Retrieve the UID for the current user's default tasklist. * * @return string UID. * @since 4.2.0 */ public function getDefaultShare() { return Nag::getDefaultTasklist(Horde_Perms::EDIT); }
/* Redirect to the task list if no action has been requested. */ $actionID = $vars->get('actionID'); if (is_null($actionID)) { Horde::url('list.php', true)->redirect(); } /* Run through the action handlers. */ switch ($actionID) { case 'add_task': /* Check permissions. */ $perms = $injector->getInstance('Horde_Core_Perms'); if ($perms->hasAppPermission('max_tasks') !== true && $perms->hasAppPermission('max_tasks') <= Nag::countTasks()) { Horde::permissionDeniedError('nag', 'max_tasks', sprintf(_("You are not allowed to create more than %d tasks."), $perms->hasAppPermission('max_tasks'))); Horde::url('list.php', true)->redirect(); } if (!$vars->exists('tasklist_id')) { $vars->set('tasklist_id', Nag::getDefaultTasklist(Horde_Perms::EDIT)); } if ($parent = Horde_Util::getFormData('parent_task')) { $vars->set('parent', $parent); } $form = new Nag_Form_Task($vars, _("New Task")); break; case 'modify_task': $task_id = $vars->get('task'); $tasklist_id = $vars->get('tasklist'); try { $share = $nag_shares->getShare($tasklist_id); } catch (Horde_Share_Exception $e) { $notification->push(sprintf(_("Access denied editing task: %s"), $e->getMessage()), 'horde.error'); } if (!$share->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) {
<?php require_once __DIR__ . '/lib/Application.php'; Horde_Registry::appInit('nag'); if ($quickText = Horde_Util::getPost('quickText')) { try { $result = Nag::createTasksFromText($quickText, Nag::getDefaultTasklist(Horde_Perms::EDIT)); } catch (Nag_Exception $e) { $notification->push($e->getMessage()); } if ($result) { $notification->push(sprintf(ngettext("Added %d task", "Added %d tasks", count($result)), count($result)), 'horde.success'); } else { $notification->push(_("No tasks have been added."), 'horde.warning'); } } else { $notification->push(_("No tasks have been added."), 'horde.warning'); } Horde::url('list.php', true)->redirect();