Returns the number of taks in task lists that the current user owns.
public static countTasks ( ) : integer | ||
return | integer | The number of tasks that the user owns. |
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); }
Horde::url('list.php', true)->redirect(); } require_once __DIR__ . '/lib/Application.php'; Horde_Registry::appInit('nag'); $vars = Horde_Variables::getDefaultVariables(); /* 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 {
/** * 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'); } } }
} catch (Horde_Exception $e) { if ($data) { $notification->push($e, 'horde.error'); $next_step = $data->cleanup(); } else { $notification->push(_("This file format is not supported."), 'horde.error'); $next_step = Horde_Data::IMPORT_FILE; } } } /* We have a final result set. */ if (is_array($next_step)) { /* Create a Nag storage instance. */ $nag_storage = $GLOBALS['injector']->getInstance('Nag_Factory_Driver')->create($storage->get('target')); $max_tasks = $perms->hasAppPermission('max_tasks'); $num_tasks = Nag::countTasks(); $result = null; foreach ($next_step as $row) { if ($max_tasks !== true && $num_tasks >= $max_tasks) { Horde::permissionDeniedError('nag', 'max_tasks', sprintf(_("You are not allowed to create more than %d tasks."), $perms->hasAppPermission('max_tasks'))); break; } if (!is_array($row)) { if (!is_a($row, 'Horde_Icalendar_Vtodo')) { continue; } $task = new Nag_Task($nag_storage); $task->fromiCalendar($row); $row = $task->toHash(); foreach (array_keys($app_fields) as $field) { if (!isset($row[$field])) {