1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
|
<?php
/**
* $Horde: nag/task.php,v 1.80.8.14 2009-01-06 15:25:04 jan Exp $
*
* Copyright 2001-2009 The Horde Project (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
*
* @author Jon Parise <jon@horde.org>
* @author Jan Schneider <jan@horde.org>
*/
function _delete($task_id, $tasklist_id)
{
if (!empty($task_id)) {
$task = Nag::getTask($tasklist_id, $task_id);
if (is_a($task, 'PEAR_Error')) {
$GLOBALS['notification']->push(
sprintf(_("Error deleting task: %s"),
$task->getMessage()), 'horde.error');
} else {
$share = $GLOBALS['nag_shares']->getShare($tasklist_id);
if (is_a($share, 'PEAR_Error') ||
!$share->hasPermission(Auth::getAuth(), PERMS_DELETE)) {
$GLOBALS['notification']->push(
_("Access denied deleting task."), 'horde.error');
} else {
$storage = &Nag_Driver::singleton($tasklist_id);
$result = $storage->delete($task_id);
if (is_a($result, 'PEAR_Error')) {
$GLOBALS['notification']->push(
sprintf(_("There was a problem deleting %s: %s"),
$task->name, $result->getMessage()),
'horde.error');
} else {
$GLOBALS['notification']->push(sprintf(_("Deleted %s."),
$task->name),
'horde.success');
}
}
}
}
/* Return to the task list. */
header('Location: ' . Horde::applicationUrl('list.php', true));
exit;
}
@define('NAG_BASE', dirname(__FILE__));
require_once NAG_BASE . '/lib/base.php';
require_once NAG_BASE . '/lib/Forms/task.php';
$vars = Variables::getDefaultVariables();
/* Redirect to the task list if no action has been requested. */
$actionID = $vars->get('actionID');
if (is_null($actionID)) {
header('Location: ' . Horde::applicationUrl('list.php', true));
exit;
}
/* Run through the action handlers. */
switch ($actionID) {
case 'add_task':
/* Check permissions. */
if (Nag::hasPermission('max_tasks') !== true &&
Nag::hasPermission('max_tasks') <= Nag::countTasks()) {
$message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d tasks."), Nag::hasPermission('max_tasks')), ENT_COMPAT, NLS::getCharset());
if (!empty($conf['hooks']['permsdenied'])) {
$message = Horde::callHook('_perms_hook_denied', array('nag:max_tasks'), 'horde', $message);
}
$notification->push($message, 'horde.error', array('content.raw'));
header('Location: ' . Horde::applicationUrl('list.php', true));
exit;
}
$vars->set('actionID', 'save_task');
if (!$vars->exists('tasklist_id')) {
$vars->set('tasklist_id', Nag::getDefaultTasklist(PERMS_EDIT));
}
$form = new Nag_TaskForm($vars, _("New Task"));
break;
case 'modify_task':
$task_id = $vars->get('task');
$tasklist_id = $vars->get('tasklist');
$share = $GLOBALS['nag_shares']->getShare($tasklist_id);
if (is_a($share, 'PEAR_Error')) {
$notification->push(sprintf(_("Access denied editing task: %s"), $share->getMessage()), 'horde.error');
} elseif (!$share->hasPermission(Auth::getAuth(), PERMS_EDIT)) {
$notification->push(_("Access denied editing task."), 'horde.error');
} else {
$task = Nag::getTask($tasklist_id, $task_id);
if (!isset($task) || !isset($task->id)) {
$notification->push(_("Task not found."), 'horde.error');
} elseif ($task->private && $task->owner != Auth::getAuth()) {
$notification->push(_("Access denied editing task."), 'horde.error');
} else {
$vars = new Variables($task->toHash());
$vars->set('actionID', 'save_task');
$vars->set('old_tasklist', $task->tasklist);
$form = new Nag_TaskForm($vars, sprintf(_("Edit: %s"), $task->name), $share->hasPermission(Auth::getAuth(), PERMS_DELETE));
break;
}
}
/* Return to the task list. */
header('Location: ' . Horde::applicationUrl('list.php', true));
exit;
case 'save_task':
if ($vars->get('submitbutton') == _("Delete this task")) {
_delete($vars->get('task_id'), $vars->get('old_tasklist'));
}
$form = new Nag_TaskForm($vars, $vars->get('task_id') ? sprintf(_("Edit: %s"), $vars->get('name')) : _("New Task"));
if (!$form->validate($vars)) {
break;
}
$form->getInfo($vars, $info);
if ($prefs->isLocked('default_tasklist') ||
count(Nag::listTasklists(false, PERMS_EDIT)) <= 1) {
$info['tasklist_id'] = $info['old_tasklist'] = Nag::getDefaultTasklist(PERMS_EDIT);
}
$share = $GLOBALS['nag_shares']->getShare($info['tasklist_id']);
if (is_a($share, 'PEAR_Error')) {
$notification->push(sprintf(_("Access denied saving task: %s"), $share->getMessage()), 'horde.error');
header('Location: ' . Horde::applicationUrl('list.php', true));
exit;
} elseif (!$share->hasPermission(Auth::getAuth(), PERMS_EDIT)) {
$notification->push(sprintf(_("Access denied saving task to %s."), $share->get('name')), 'horde.error');
header('Location: ' . Horde::applicationUrl('list.php', true));
exit;
}
/* Add new category. */
if ($info['category']['new']) {
require_once 'Horde/Prefs/CategoryManager.php';
$cManager = new Prefs_CategoryManager();
$cManager->add($info['category']['value']);
}
/* 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 = &Nag_Driver::singleton($info['old_tasklist']);
$result = $storage->modify($info['task_id'], $info['name'],
$info['desc'], $info['start'],
$info['due'], $info['priority'],
(float)$info['estimate'],
(int)$info['completed'],
$info['category']['value'],
$info['alarm'], $info['parent'],
(int)$info['private'], Auth::getAuth(),
$info['assignee'], null,
$info['tasklist_id']);
} else {
/* Check permissions. */
if (Nag::hasPermission('max_tasks') !== true &&
Nag::hasPermission('max_tasks') <= Nag::countTasks()) {
header('Location: ' . Horde::applicationUrl('list.php', true));
exit;
}
/* Creating a new task. */
$storage = &Nag_Driver::singleton($info['tasklist_id']);
$result = $storage->add($info['name'], $info['desc'],
$info['start'], $info['due'],
$info['priority'],
(float)$info['estimate'],
(int)$info['completed'],
$info['category']['value'],
$info['alarm'], null, $info['parent'],
(int)$info['private'],
Auth::getAuth(),
$info['assignee']);
}
/* Check our results. */
if (is_a($result, 'PEAR_Error')) {
$notification->push(sprintf(_("There was a problem saving the task: %s."), $result->getMessage()), 'horde.error');
} else {
$notification->push(sprintf(_("Saved %s."), $info['name']), 'horde.success');
/* Return to the task list. */
header('Location: ' . Horde::applicationUrl('list.php', true));
exit;
}
break;
case 'delete_tasks':
/* Delete the task if we're provided with a valid task ID. */
_delete(Util::getFormData('task'), Util::getFormData('tasklist'));
case 'complete_task':
/* Toggle the task's completion status if we're provided with a
* valid task ID. */
$task_id = Util::getFormData('task');
$tasklist_id = Util::getFormData('tasklist');
if (isset($task_id)) {
$share = $GLOBALS['nag_shares']->getShare($tasklist_id);
$task = Nag::getTask($tasklist_id, $task_id);
if (is_a($share, 'PEAR_Error') || !$share->hasPermission(Auth::getAuth(), PERMS_EDIT)) {
$notification->push(sprintf(_("Access denied completing task %s."), $task->name), 'horde.error');
} else {
$task->completed = !$task->completed;
if ($task->completed) {
$task->completed_date = time();
} else {
$task->completed_date = null;
}
$result = $task->save();
if (is_a($result, 'PEAR_Error')) {
$notification->push(sprintf(_("There was a problem completing %s: %s"),
$task->name, $result->getMessage()), 'horde.error');
} else {
if ($task->completed) {
$notification->push(sprintf(_("Completed %s."), $task->name), 'horde.success');
} else {
$notification->push(sprintf(_("%s is now incomplete."), $task->name), 'horde.success');
}
}
}
}
$url = $vars->get('url');
if (!empty($url)) {
header('Location: ' . $url);
} else {
header('Location: ' . Horde::applicationUrl('list.php', true));
}
exit;
default:
header('Location: ' . Horde::applicationUrl('list.php', true));
exit;
}
$title = $form->getTitle();
require NAG_TEMPLATES . '/common-header.inc';
require NAG_TEMPLATES . '/menu.inc';
$form->renderActive();
require $registry->get('templates', 'horde') . '/common-footer.inc';
|