Native PHP5 code for Nag.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 27 Jan 2011 21:51:59 +0000 (16:51 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 27 Jan 2011 21:53:33 +0000 (16:53 -0500)
Only thing not touched is the Kolab driver code, as Gunnar indicated
they all need to be rewritten.

29 files changed:
nag/data.php
nag/lib/Api.php
nag/lib/Application.php
nag/lib/Block/summary.php
nag/lib/Driver.php
nag/lib/Driver/Sql.php
nag/lib/Form/CreateTaskList.php [new file with mode: 0644]
nag/lib/Form/DeleteTaskList.php [new file with mode: 0644]
nag/lib/Form/EditTaskList.php [new file with mode: 0644]
nag/lib/Form/Renderer/Task.php [new file with mode: 0644]
nag/lib/Form/Type/NagAlarm.php [new file with mode: 0644]
nag/lib/Form/Type/NagDue.php [new file with mode: 0644]
nag/lib/Form/Type/NagMethod.php [new file with mode: 0644]
nag/lib/Form/Type/NagStart.php [new file with mode: 0644]
nag/lib/Form/task.php [new file with mode: 0644]
nag/lib/Forms/CreateTaskList.php [deleted file]
nag/lib/Forms/DeleteTaskList.php [deleted file]
nag/lib/Forms/EditTaskList.php [deleted file]
nag/lib/Forms/task.php [deleted file]
nag/lib/Nag.php
nag/lib/Task.php
nag/lib/Ui/VarRenderer/Nag.php
nag/list.php
nag/mobile.php
nag/quick.php
nag/scripts/import_vtodos.php
nag/task.php
nag/tasks/index.php
nag/view.php

index b9222d9..92022a5 100644 (file)
@@ -87,47 +87,49 @@ case 'export':
     }
 
     /* Get the full, sorted task list. */
-    $tasks = Nag::listTasks(null, null, null, $tasklists,
-                            Horde_Util::getFormData('exportTasks'));
-    if (is_a($tasks, 'PEAR_Error')) {
-        $notification->push($tasks);
-        $error = true;
-    } elseif (!$tasks->hasTasks()) {
-        $notification->push(_("There were no tasks to export."), 'horde.message');
-        $error = true;
-    } else {
-        $tasks->reset();
-        switch ($exportID) {
-        case Horde_Data::EXPORT_CSV:
-            $data = array();
-            while ($task = $tasks->each()) {
-                $task = $task->toHash();
-                unset($task['task_id']);
-                $task['desc'] = str_replace(',', '', $task['desc']);
-                unset($task['tasklist_id']);
-                unset($task['parent']);
-                unset($task['view_link']);
-                unset($task['complete_link']);
-                unset($task['edit_link']);
-                unset($task['delete_link']);
-                $data[] = $task;
-            }
-            $injector->getInstance('Horde_Core_Factory_Data')->create('Csv', array('cleanup' => '_cleanupData'))->exportFile(_("tasks.csv"), $data, true);
-            exit;
+    try {
+        $tasks = Nag::listTasks(null, null, null, $tasklists,
+                                Horde_Util::getFormData('exportTasks'));
+        if (!$tasks->hasTasks()) {
+            $notification->push(_("There were no tasks to export."), 'horde.message');
+            $error = true;
+        } else {
+            $tasks->reset();
+            switch ($exportID) {
+            case Horde_Data::EXPORT_CSV:
+                $data = array();
+                while ($task = $tasks->each()) {
+                    $task = $task->toHash();
+                    unset($task['task_id']);
+                    $task['desc'] = str_replace(',', '', $task['desc']);
+                    unset($task['tasklist_id']);
+                    unset($task['parent']);
+                    unset($task['view_link']);
+                    unset($task['complete_link']);
+                    unset($task['edit_link']);
+                    unset($task['delete_link']);
+                    $data[] = $task;
+                }
+                $injector->getInstance('Horde_Core_Factory_Data')->create('Csv', array('cleanup' => '_cleanupData'))->exportFile(_("tasks.csv"), $data, true);
+                exit;
 
-        case Horde_Data::EXPORT_ICALENDAR:
-            $iCal = new Horde_Icalendar();
-            $iCal->setAttribute(
-                'PRODID',
-                '-//The Horde Project//Nag ' . $registry->getVersion() . '//EN');
-            while ($task = $tasks->each()) {
-                $iCal->addComponent($task->toiCalendar($iCal));
+            case Horde_Data::EXPORT_ICALENDAR:
+                $iCal = new Horde_Icalendar();
+                $iCal->setAttribute(
+                    'PRODID',
+                    '-//The Horde Project//Nag ' . $registry->getVersion() . '//EN');
+                while ($task = $tasks->each()) {
+                    $iCal->addComponent($task->toiCalendar($iCal));
+                }
+                $data = $iCal->exportvCalendar();
+                $browser->downloadHeaders(_("tasks.ics"), 'text/calendar', false, strlen($data));
+                echo $data;
+                exit;
             }
-            $data = $iCal->exportvCalendar();
-            $browser->downloadHeaders(_("tasks.ics"), 'text/calendar', false, strlen($data));
-            echo $data;
-            exit;
         }
+    } catch (Nag_Exception $e) {
+        $notification->push($e->getMessage());
+        $error = true;
     }
     break;
 
@@ -187,14 +189,20 @@ if (is_array($next_step)) {
             }
         }
 
-        $result = $storage->add($row['name'], $row['desc'], $row['start'],
-                                $row['due'], $row['priority'],
-                                $row['estimate'], $row['completed'],
-                                $row['category'], $row['alarm'], $row['uid'],
-                                isset($row['parent']) ? $row['parent'] : '',
-                                $row['private'], $GLOBALS['registry']->getAuth(),
-                                $row['assignee']);
-        if (is_a($result, 'PEAR_Error')) {
+        try {
+            $storage->add(
+                $row['name'], $row['desc'], $row['start'],
+                $row['due'], $row['priority'],
+                $row['estimate'], $row['completed'],
+                $row['category'], $row['alarm'], $row['uid'],
+                isset($row['parent']) ? $row['parent'] : '',
+                $row['private'], $GLOBALS['registry']->getAuth(),
+                $row['assignee']
+            );
+        } catch (Nag_Exception $e) {
+            $haveError = true;
+            $notification->push(sprintf(_("There was an error importing the data: %s"),
+                                        $result->getMessage()), 'horde.error');
             break;
         }
 
@@ -211,10 +219,7 @@ if (is_array($next_step)) {
     if (!count($next_step)) {
         $notification->push(sprintf(_("The %s file didn't contain any tasks."),
                                     $file_types[$session->get('horde', 'import_data/format')]), 'horde.error');
-    } elseif (is_a($result, 'PEAR_Error')) {
-        $notification->push(sprintf(_("There was an error importing the data: %s"),
-                                    $result->getMessage()), 'horde.error');
-    } else {
+    } elseif (empty($haveError)) {
         $notification->push(sprintf(_("%s successfully imported"),
                                     $file_types[$session->get('horde', 'import_data/format')]), 'horde.success');
     }
index efd58a9..34bc94f 100644 (file)
@@ -118,9 +118,6 @@ class Nag_Api extends Horde_Registry_Api
     public function addTasklist($name, $description = '', $color = '')
     {
         $tasklist = Nag::addTasklist(array('name' => $name, 'description' => $description, 'color' => $color));
-        if (is_a($tasklist, 'PEAR_Error')) {
-            return $tasklist;
-        }
         return $tasklist->getName();
     }
 
@@ -150,9 +147,6 @@ class Nag_Api extends Horde_Registry_Api
     public function deleteTasklist($id)
     {
         $tasklist = $GLOBALS['nag_shares']->getShare($id);
-        if (is_a($tasklist, 'PEAR_Error')) {
-            return $tasklist;
-        }
         return Nag::deleteTasklist($tasklist);
     }
 
@@ -315,12 +309,11 @@ class Nag_Api extends Horde_Registry_Api
                 return PEAR::raiseError(_("Invalid tasklist requested."), 404);
             }
             $storage = Nag_Driver::singleton($parts[1]);
-            $result = $storage->retrieve();
-            if (is_a($result, 'PEAR_Error')) {
-                $result->code = 500;
-                return $result;
+            try {
+                $storage->retrieve();
+            } catch (Nag_Exception $e) {
+                 throw new Nag_Exception($e->getMessage, 500);
             }
-
             $icon = Horde_Themes::img('nag.png');
             $results = array();
             $storage->tasks->reset();
@@ -360,40 +353,39 @@ class Nag_Api extends Horde_Registry_Api
             // The only valid request left is for either a specific task item.
             //
             if (count($parts) == 3 &&
-                array_key_exists($parts[1], Nag::listTasklists(false,
-                    Horde_Perms::READ))) {
-                        //
-                        // This request is for a specific item within a given task list.
-                        //
-                        /* Create a Nag storage instance. */
-                        $storage = Nag_Driver::singleton($parts[1]);
-                        if (is_a($storage, 'PEAR_Error')) {
-                            return PEAR::raiseError(sprintf(_("Connection failed: %s"), $storage->getMessage()));
-                        }
-                        $storage->retrieve();
+                array_key_exists($parts[1], Nag::listTasklists(false, Horde_Perms::READ))) {
+
+                //
+                // This request is for a specific item within a given task list.
+                //
+                /* Create a Nag storage instance. */
+                $storage = Nag_Driver::singleton($parts[1]);
+                $storage->retrieve();
+                try {
+                    $storage->get($parts[2]);
+                } catch (Nag_Exception $e) {
+                    throw new Nag_Exception($e->getMessage(), 500);
+                }
+                $result = array(
+                    'data' => $this->export($task->uid, 'text/calendar'),
+                    'mimetype' => 'text/calendar');
+                $modified = $this->modified($task->uid, $parts[1]);
+                if (!empty($modified)) {
+                    $result['mtime'] = $modified;
+                }
+                return $result;
+            } elseif (count($parts) == 2 &&
+                substr($parts[1], -4) == '.ics' &&
+                array_key_exists(substr($parts[1], 0, -4), Nag::listTasklists(false, Horde_Perms::READ))) {
 
-                        $task = $storage->get($parts[2]);
-                        if (is_a($task, 'PEAR_Error')) {
-                            $task->code = 500;
-                            return $task;
-                        }
+                // ??
 
-                        $result = array('data' => $this->export($task->uid, 'text/calendar'),
-                            'mimetype' => 'text/calendar');
-                        $modified = $this->modified($task->uid, $parts[1]);
-                        if (!empty($modified)) {
-                            $result['mtime'] = $modified;
-                        }
-                        return $result;
-                    } elseif (count($parts) == 2 &&
-                        substr($parts[1], -4) == '.ics' &&
-                        array_key_exists(substr($parts[1], 0, -4), Nag::listTasklists(false, Horde_Perms::READ))) {
-                        } else {
-                            //
-                            // All other requests are a 404: Not Found
-                            //
-                            return false;
-                        }
+            } else {
+                //
+                // All other requests are a 404: Not Found
+                //
+                return false;
+            }
         }
     }
 
@@ -404,7 +396,7 @@ class Nag_Api extends Horde_Registry_Api
      * @param string $content       The file content.
      * @param string $content_type  The file's content type.
      *
-     * @return array  The event UIDs, or a PEAR_Error on failure.
+     * @return array  The event UIDs
      */
     public function put($path, $content, $content_type)
     {
@@ -433,13 +425,13 @@ class Nag_Api extends Horde_Registry_Api
                     $content_type = 'text/calendar';
                 }
             } else {
-                return PEAR::raiseError(_("Invalid tasklist name supplied."), 403);
+                throw new Nag_Exception(_("Invalid tasklist name supplied."), 403);
             }
 
         if (!array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::EDIT))) {
             // FIXME: Should we attempt to create a tasklist based on the filename
             // in the case that the requested tasklist does not exist?
-            return PEAR::raiseError(_("Tasklist does not exist or no permission to edit"), 403);
+            throw new Nag_Exception(_("Tasklist does not exist or no permission to edit"), 403);
         }
 
         // Store all currently existings UIDs. Use this info to delete UIDs not
@@ -455,7 +447,7 @@ class Nag_Api extends Horde_Registry_Api
             $iCal = new Horde_Icalendar();
             if (!($content instanceof Horde_Icalendar_Vtodo)) {
                 if (!$iCal->parsevCalendar($content)) {
-                    return PEAR::raiseError(_("There was an error importing the iCalendar data."), 400);
+                    throw new Nag_Exception(_("There was an error importing the iCalendar data."), 400);
                 }
             } else {
                 $iCal->addComponent($content);
@@ -466,8 +458,8 @@ class Nag_Api extends Horde_Registry_Api
                     $task = new Nag_Task();
                     $task->fromiCalendar($content);
                     $task->tasklist = $tasklist;
-                    if (isset($task->uid) &&
-                        !is_a(($existing = $storage->getByUID($task->uid)), 'PEAR_Error')) {
+                    if (isset($task->uid)) {
+                        $existing = $storage->getByUID($task->uid);
                         // Entry exists, remove from uids_remove list so we
                         // won't delete in the end.
                         if (isset($uids_remove[$task->uid])) {
@@ -508,46 +500,46 @@ class Nag_Api extends Horde_Registry_Api
                         // Don't change creator/owner.
                         $owner = $existing->owner;
                         $taskId = $existing->id;
-                        $result = $storage->modify(
-                            $taskId,
-                            isset($task->name) ? $task->name : $existing->name,
-                            isset($task->desc) ? $task->desc : $existing->desc,
-                            isset($task->start) ? $task->start : $existing->start,
-                            isset($task->due) ? $task->due : $existing->due,
-                            isset($task->priority) ? $task->priority : $existing->priority,
-                            isset($task->estimate) ? $task->estimate : 0,
-                            isset($task->completed) ? (int)$task->completed : $existing->completed,
-                            isset($task->category) ? $task->category : $existing->category,
-                            isset($task->alarm) ? $task->alarm : $existing->alarm,
-                            isset($task->parent_id) ? $task->parent_id : $existing->parent_id,
-                            isset($task->private) ? $task->private : $existing->private,
-                            $owner,
-                            isset($task->assignee) ? $task->assignee : $existing->assignee);
-
-                        if (is_a($result, 'PEAR_Error')) {
-                            $result->code = 500;
-                            return $result;
+                        try {
+                            $storage->modify(
+                                $taskId,
+                                isset($task->name) ? $task->name : $existing->name,
+                                isset($task->desc) ? $task->desc : $existing->desc,
+                                isset($task->start) ? $task->start : $existing->start,
+                                isset($task->due) ? $task->due : $existing->due,
+                                isset($task->priority) ? $task->priority : $existing->priority,
+                                isset($task->estimate) ? $task->estimate : 0,
+                                isset($task->completed) ? (int)$task->completed : $existing->completed,
+                                isset($task->category) ? $task->category : $existing->category,
+                                isset($task->alarm) ? $task->alarm : $existing->alarm,
+                                isset($task->parent_id) ? $task->parent_id : $existing->parent_id,
+                                isset($task->private) ? $task->private : $existing->private,
+                                $owner,
+                                isset($task->assignee) ? $task->assignee : $existing->assignee
+                            );
+                        } catch (Nag_Exception $e) {
+                            throw new Nag_Exception($e->getMessage(), 500);
                         }
                         $ids[] = $task->uid;
                     } else {
-                        $newTask = $storage->add(
-                            isset($task->name) ? $task->name : '',
-                            isset($task->desc) ? $task->desc : '',
-                            isset($task->start) ? $task->start : 0,
-                            isset($task->due) ? $task->due : 0,
-                            isset($task->priority) ? $task->priority : 3,
-                            isset($task->estimate) ? $task->estimate : 0,
-                            !empty($task->completed),
-                            isset($task->category) ? $task->category : '',
-                            isset($task->alarm) ? $task->alarm : 0,
-                            isset($task->uid) ? $task->uid : null,
-                            isset($task->parent_id) ? $task->parent_id : '',
-                            !empty($task->private),
-                            $GLOBALS['registry']->getAuth(),
-                            isset($task->assignee) ? $task->assignee : null);
-                        if (is_a($newTask, 'PEAR_Error')) {
-                            $newtask->code = 500;
-                            return $newTask;
+                        try {
+                            $newTask = $storage->add(
+                                isset($task->name) ? $task->name : '',
+                                isset($task->desc) ? $task->desc : '',
+                                isset($task->start) ? $task->start : 0,
+                                isset($task->due) ? $task->due : 0,
+                                isset($task->priority) ? $task->priority : 3,
+                                isset($task->estimate) ? $task->estimate : 0,
+                                !empty($task->completed),
+                                isset($task->category) ? $task->category : '',
+                                isset($task->alarm) ? $task->alarm : 0,
+                                isset($task->uid) ? $task->uid : null,
+                                isset($task->parent_id) ? $task->parent_id : '',
+                                !empty($task->private),
+                                $GLOBALS['registry']->getAuth(),
+                                isset($task->assignee) ? $task->assignee : null);
+                        } catch (Nag_Exception $e) {
+                            throw new Nag_Exception($e->getMessage(), 500);
                         }
                         // use UID rather than ID
                         $ids[] = $newTask[1];
@@ -557,7 +549,7 @@ class Nag_Api extends Horde_Registry_Api
             break;
 
         default:
-                return PEAR::raiseError(sprintf(_("Unsupported Content-Type: %s"), $content_type), 400);
+            throw new Nag_Exception(sprintf(_("Unsupported Content-Type: %s"), $content_type), 400);
         }
 
         if (array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::DELETE))) {
@@ -574,7 +566,8 @@ class Nag_Api extends Horde_Registry_Api
      *
      * @param string $path  The path to the file.
      *
-     * @return mixed  The event's UID, or a PEAR_Error on failure.
+     * @return string  The event's UID
+     * @throws Nag_Exception
      */
     public function path_delete($path)
     {
@@ -589,7 +582,7 @@ class Nag_Api extends Horde_Registry_Api
             // Allow users to delete tasklists but not create them via WebDAV will
             // be more confusing than helpful.  They are, however, still able to
             // delete individual task items within the tasklist folder.
-            return PEAR::raiseError(_("Deleting entire tasklists is not supported."), 403);
+            throw Nag_Exception(_("Deleting entire tasklists is not supported."), 403);
             // To re-enable the functionality just remove this if {} block.
         }
 
@@ -601,36 +594,34 @@ class Nag_Api extends Horde_Registry_Api
 
         if (!(count($parts) == 2 || count($parts) == 3) ||
             !array_key_exists($tasklistID, Nag::listTasklists(false, Horde_Perms::DELETE))) {
-                return PEAR::raiseError(_("Tasklist does not exist or no permission to delete"), 403);
-            }
 
-        /* Create a Nag storage instance. */
-        $storage = Nag_Driver::singleton($tasklistID);
-        if (is_a($storage, 'PEAR_Error')) {
-            return PEAR::raiseError(sprintf(_("Connection failed: %s"), $storage->getMessage()), 500);
-        }
-        $retrieved = $storage->retrieve();
-        if (is_a($retrieved, 'PEAR_Error')) {
-            $retrieved->code = 500;
-            return $retrieved;
+            throw new Nag_Exception(_("Tasklist does not exist or no permission to delete"), 403);
         }
 
+        /* Create a Nag storage instance. */
+        try {
+            $storage = Nag_Driver::singleton($tasklistID);
+            $storage->retrieve();
+        } catch (Nag_Exception $e) {
+            throw new Nag_Exception(sprintf(_("Connection failed: %s"), $e->getMessage()), 500);
+        }
         if (count($parts) == 3) {
             // Delete just a single entry
             return $storage->delete($parts[2]);
         } else {
             // Delete the entire task list
-            $result = $storage->deleteAll();
-            if (is_a($result, 'PEAR_Error')) {
-                return PEAR::raiseError(sprintf(_("Unable to delete tasklist \"%s\": %s"), $tasklistID, $result->getMessage()), 500);
-            } else {
-                // Remove share and all groups/permissions.
-                $share = $GLOBALS['nag_shares']->getShare($tasklistID);
-                try {
-                    $GLOBALS['nag_shares']->removeShare($share);
-                } catch (Horde_Share_Exception $e) {
-                    throw new Nag_Exception($e->getMessage());
-                }
+            try {
+                $storage->deleteAll();
+            } catch (Nag_Exception $e) {
+                throw new Nag_Exception(sprintf(_("Unable to delete tasklist \"%s\": %s"), $tasklistID, $e->getMessage()), 500);
+            }
+
+            // Remove share and all groups/permissions.
+            $share = $GLOBALS['nag_shares']->getShare($tasklistID);
+            try {
+                $GLOBALS['nag_shares']->removeShare($share);
+            } catch (Horde_Share_Exception $e) {
+                throw new Nag_Exception($e->getMessage());
             }
         }
     }
@@ -639,31 +630,26 @@ class Nag_Api extends Horde_Registry_Api
      * Returns an array of UIDs for all tasks that the current user is authorized
      * to see.
      *
-     * @param variant $tasklist  The tasklist or an array of taskslists to list.
+     * @param mixed $tasklist  The tasklist or an array of taskslists to list.
      *
      * @return array             An array of UIDs for all tasks
      *                           the user can access.
+     *
+     * @throws Horde_Exception_PermissionDenied
+     * @throws Nag_Exception
      */
     public function listUids($tasklist = null)
     {
         if (!isset($GLOBALS['conf']['storage']['driver'])) {
-            return PEAR::raiseError(_("Not configured"));
+            throw new Nag_Exception(_("Not configured"));
         }
-
         if ($tasklist === null) {
             $tasklist = Nag::getDefaultTasklist(Horde_Perms::READ);
         }
-
-        if (!array_key_exists($tasklist,
-            Nag::listTasklists(false, Horde_Perms::READ))) {
-                return PEAR::raiseError(_("Permission Denied"));
-            }
-
-        $tasks = Nag::listTasks(null, null, null, $tasklist, 1);
-        if (is_a($tasks, 'PEAR_Error')) {
-            return $tasks;
+        if (!array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::READ))) {
+            throw new Horde_Exception_PermissionDenied(_("Permission Denied"));
         }
-
+        $tasks = Nag::listTasks(null, null, null, $tasklist, 1);
         $uids = array();
         $tasks->reset();
         while ($task = $tasks->each()) {
@@ -694,16 +680,17 @@ class Nag_Api extends Horde_Registry_Api
             $tasklist = Nag::getDefaultTasklist(Horde_Perms::READ);
         }
 
-        if (!array_key_exists($tasklist,
-            Nag::listTasklists(false, Horde_Perms::READ))) {
-                return PEAR::raiseError(_("Permission Denied"));
+        if (!array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::READ))) {
+           throw new Horde_Exception_PermissionDenied(_("Permission Denied"));
         }
 
         $filter = array(array('op' => '=', 'field' => 'action', 'value' => $action));
         if (!empty($end)) {
             $filter[] = array('op' => '<', 'field' => 'ts', 'value' => $end);
         }
-        $histories = $GLOBALS['injector']->getInstance('Horde_History')->getByTimestamp('>', $timestamp, $filter, 'nag:' . $tasklist);
+        $histories = $GLOBALS['injector']
+            ->getInstance('Horde_History')
+            ->getByTimestamp('>', $timestamp, $filter, 'nag:' . $tasklist);
 
         // Strip leading nag:username:.
         return preg_replace('/^([^:]*:){2}/', '', array_keys($histories));
@@ -737,6 +724,8 @@ class Nag_Api extends Horde_Registry_Api
      * @return integer  The timestamp for this action.
      *
      * @throws InvalidArgumentException
+     * @throws Horde_Exception_PermissionDenied
+     * @thorws Horde_History_Exception
      */
     public function getActionTimestamp($uid, $action, $tasklist = null)
     {
@@ -744,12 +733,13 @@ class Nag_Api extends Horde_Registry_Api
             $tasklist = Nag::getDefaultTasklist(Horde_Perms::READ);
         }
 
-        if (!array_key_exists($tasklist,
-            Nag::listTasklists(false, Horde_Perms::READ))) {
-                return PEAR::raiseError(_("Permission Denied"));
-            }
+        if (!array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::READ))) {
+            throw new Horde_Exception_PermissionDenied(_("Permission Denied"));
+        }
 
-        return $GLOBALS['injector']->getInstance('Horde_History')->getActionTimestamp('nag:' . $tasklist . ':' . $uid, $action);
+        return $GLOBALS['injector']
+            ->getInstance('Horde_History')
+            ->getActionTimestamp('nag:' . $tasklist . ':' . $uid, $action);
     }
 
     /**
@@ -767,7 +757,6 @@ class Nag_Api extends Horde_Registry_Api
      *                             tasklist will be used.
      *
      * @return string  The new UID on one import, an array of UIDs on multiple imports,
-     *                 or PEAR_Error on failure.
      */
     public function import($content, $contentType, $tasklist = null)
     {
@@ -776,7 +765,7 @@ class Nag_Api extends Horde_Registry_Api
         }
 
         if (!array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::EDIT))) {
-            return PEAR::raiseError(_("Permission Denied"));
+            throw new Horde_Exception_PermissionDenied(_("Permission Denied"));
         }
 
         /* Create a Nag_Driver instance. */
@@ -789,7 +778,7 @@ class Nag_Api extends Horde_Registry_Api
             $iCal = new Horde_Icalendar();
             if (!($content instanceof Horde_Icalendar_Vtodo)) {
                 if (!$iCal->parsevCalendar($content)) {
-                    return PEAR::raiseError(_("There was an error importing the iCalendar data."));
+                    throw new Nag_Exception(_("There was an error importing the iCalendar data."));
                 }
             } else {
                 $iCal->addComponent($content);
@@ -797,7 +786,7 @@ class Nag_Api extends Horde_Registry_Api
 
             $components = $iCal->getComponents();
             if (count($components) == 0) {
-                return PEAR::raiseError(_("No iCalendar data was found."));
+                throw new Nag_Exception(_("No iCalendar data was found."));
             }
 
             $ids = array();
@@ -805,56 +794,51 @@ class Nag_Api extends Horde_Registry_Api
                 if ($content instanceof Horde_Icalendar_Vtodo) {
                     $task = new Nag_Task();
                     $task->fromiCalendar($content);
-                    if (isset($task->uid) &&
-                        !is_a(($existing = $storage->getByUID($task->uid)), 'PEAR_Error')) {
-                            $taskId = $existing->id;
-                            $result = $storage->modify(
-                                $taskId,
-                                isset($task->name) ? $task->name : $existing->name,
-                                isset($task->desc) ? $task->desc : $existing->desc,
-                                isset($task->start) ? $task->start : $existing->start,
-                                isset($task->due) ? $task->due : $existing->due,
-                                isset($task->priority) ? $task->priority : $existing->priority,
-                                isset($task->estimate) ? $task->estimate : 0,
-                                isset($task->completed) ? (int)$task->completed : $existing->completed,
-                                isset($task->category) ? $task->category : $existing->category,
-                                isset($task->alarm) ? $task->alarm : $existing->alarm,
-                                isset($task->parent_id) ? $task->parent_id : $existing->parent_id,
-                                isset($task->private) ? $task->private : $existing->private,
-                                isset($task->owner) ? $task->owner : $existing->owner,
-                                isset($task->assignee) ? $task->assignee : $existing->assignee);
-
-                            if (is_a($result, 'PEAR_Error')) {
-                                return $result;
-                            }
-                            $ids[] = $task->uid;
-                        } else {
-                            $newTask = $storage->add(
-                                isset($task->name) ? $task->name : '',
-                                isset($task->desc) ? $task->desc : '',
-                                isset($task->start) ? $task->start : 0,
-                                isset($task->due) ? $task->due : 0,
-                                isset($task->priority) ? $task->priority : 3,
-                                isset($task->estimate) ? $task->estimate : 0,
-                                !empty($task->completed),
-                                isset($task->category) ? $task->category : '',
-                                isset($task->alarm) ? $task->alarm : 0,
-                                isset($task->methods) ? $task->methods : null,
-                                isset($task->uid) ? $task->uid : null,
-                                isset($task->parent_id) ? $task->parent_id : '',
-                                !empty($task->private),
-                                $GLOBALS['registry']->getAuth(),
-                                isset($task->assignee) ? $task->assignee : null);
-                            if (is_a($newTask, 'PEAR_Error')) {
-                                return $newTask;
-                            }
-                            // use UID rather than ID
-                            $ids[] = $newTask[1];
-                        }
+                    if (isset($task->uid)) {
+                        $existing = $storage->getByUID($task->uid);
+                        $taskId = $existing->id;
+                        $result = $storage->modify(
+                            $taskId,
+                            isset($task->name) ? $task->name : $existing->name,
+                            isset($task->desc) ? $task->desc : $existing->desc,
+                            isset($task->start) ? $task->start : $existing->start,
+                            isset($task->due) ? $task->due : $existing->due,
+                            isset($task->priority) ? $task->priority : $existing->priority,
+                            isset($task->estimate) ? $task->estimate : 0,
+                            isset($task->completed) ? (int)$task->completed : $existing->completed,
+                            isset($task->category) ? $task->category : $existing->category,
+                            isset($task->alarm) ? $task->alarm : $existing->alarm,
+                            isset($task->parent_id) ? $task->parent_id : $existing->parent_id,
+                            isset($task->private) ? $task->private : $existing->private,
+                            isset($task->owner) ? $task->owner : $existing->owner,
+                            isset($task->assignee) ? $task->assignee : $existing->assignee
+                        );
+                        $ids[] = $task->uid;
+                    } else {
+                        $newTask = $storage->add(
+                            isset($task->name) ? $task->name : '',
+                            isset($task->desc) ? $task->desc : '',
+                            isset($task->start) ? $task->start : 0,
+                            isset($task->due) ? $task->due : 0,
+                            isset($task->priority) ? $task->priority : 3,
+                            isset($task->estimate) ? $task->estimate : 0,
+                            !empty($task->completed),
+                            isset($task->category) ? $task->category : '',
+                            isset($task->alarm) ? $task->alarm : 0,
+                            isset($task->methods) ? $task->methods : null,
+                            isset($task->uid) ? $task->uid : null,
+                            isset($task->parent_id) ? $task->parent_id : '',
+                            !empty($task->private),
+                            $GLOBALS['registry']->getAuth(),
+                            isset($task->assignee) ? $task->assignee : null
+                        );
+                        // use UID rather than ID
+                        $ids[] = $newTask[1];
+                    }
                 }
             }
             if (count($ids) == 0) {
-                return PEAR::raiseError(_("No iCalendar data was found."));
+                throw Nag_Exception(_("No iCalendar data was found."));
             } else if (count($ids) == 1) {
                 return $ids[0];
             }
@@ -864,44 +848,46 @@ class Nag_Api extends Horde_Registry_Api
             $task = new Nag_Task();
             $task->fromASTask($content);
             $results = $storage->add(
-                        isset($task->name) ? $task->name : '',
-                        isset($task->desc) ? $task->desc : '',
-                        isset($task->start) ? $task->start : 0,
-                        isset($task->due) ? $task->due : 0,
-                        isset($task->priority) ? $task->priority : 3,
-                        isset($task->estimate) ? $task->estimate : 0,
-                        !empty($task->completed),
-                        isset($task->category) ? $task->category : '',
-                        isset($task->alarm) ? $task->alarm : 0,
-                        isset($task->methods) ? $task->methods : null,
-                        isset($task->uid) ? $task->uid : null,
-                        isset($task->parent_id) ? $task->parent_id : '',
-                        !empty($task->private),
-                        $GLOBALS['registry']->getAuth(),
-                        isset($task->assignee) ? $task->assignee : null);
+                isset($task->name) ? $task->name : '',
+                isset($task->desc) ? $task->desc : '',
+                isset($task->start) ? $task->start : 0,
+                isset($task->due) ? $task->due : 0,
+                isset($task->priority) ? $task->priority : 3,
+                isset($task->estimate) ? $task->estimate : 0,
+                !empty($task->completed),
+                isset($task->category) ? $task->category : '',
+                isset($task->alarm) ? $task->alarm : 0,
+                isset($task->methods) ? $task->methods : null,
+                isset($task->uid) ? $task->uid : null,
+                isset($task->parent_id) ? $task->parent_id : '',
+                !empty($task->private),
+                $GLOBALS['registry']->getAuth(),
+                isset($task->assignee) ? $task->assignee : null
+            );
 
             /* array index 0 is id, 1 is uid */
             return $results[1];
         }
 
-        return PEAR::raiseError(sprintf(_("Unsupported Content-Type: %s"), $contentType));
+        throw new Nag_Exception(sprintf(_("Unsupported Content-Type: %s"), $contentType));
     }
 
     /**
      * Adds a task.
      *
      * @param array $task  A hash with overwriting task information.
+     *
+     * @throws Horde_Exception_PermissionDenied
      */
-    public function addTask($task)
+    public function addTask(array $task)
     {
         if (!$GLOBALS['registry']->isAdmin() &&
             !array_key_exists($task['tasklist'],
                               Nag::listTasklists(false, Horde_Perms::EDIT))) {
-            return PEAR::raiseError(_("Permission Denied"));
+            throw new Horde_Exception_PermissionDenied(_("Permission Denied"));
         }
 
         $storage = Nag_Driver::singleton($task['tasklist']);
-
         return $storage->add(
             isset($task['name']) ? $task['name'] : '',
             isset($task['desc']) ? $task['desc'] : '',
@@ -917,7 +903,8 @@ class Nag_Api extends Horde_Registry_Api
             isset($task['parent_id']) ? $task['parent_id'] : '',
             !empty($task['private']),
             $GLOBALS['registry']->getAuth(),
-            isset($task['assignee']) ? $task['assignee'] : null);
+            isset($task['assignee']) ? $task['assignee'] : null
+        );
     }
 
     /**
@@ -929,6 +916,7 @@ class Nag_Api extends Horde_Registry_Api
      *                          tasklist will be used.
      *
      * @return array  The UIDs of all tasks that were added.
+     * @throws Horde_Exception_PermissionDenied
      */
     public function quickAdd($text, $tasklist = null)
     {
@@ -936,7 +924,7 @@ class Nag_Api extends Horde_Registry_Api
             $tasklist = Nag::getDefaultTasklist(Horde_Perms::EDIT);
         }
         if (!array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::EDIT))) {
-            return PEAR::raiseError(_("Permission Denied"));
+            throw new Horde_Exception_PermissionDenied(_("Permission Denied"));
         }
 
         return Nag::createTasksFromText($text, $tasklist);
@@ -950,10 +938,9 @@ class Nag_Api extends Horde_Registry_Api
      */
     public function toggleCompletion($task_id, $tasklist_id)
     {
-        if (!array_key_exists($tasklist_id,
-            Nag::listTasklists(false, Horde_Perms::EDIT))) {
-                return PEAR::raiseError(_("Permission Denied"));
-            }
+        if (!array_key_exists($tasklist_id, Nag::listTasklists(false, Horde_Perms::EDIT))) {
+            throw new Horde_Exception_PermissionDenied(_("Permission Denied"));
+        }
 
         try {
             $share = $GLOBALS['nag_shares']->getShare($tasklist_id);
@@ -962,10 +949,6 @@ class Nag_Api extends Horde_Registry_Api
             throw new Nag_Exception($e);
         }
         $task = Nag::getTask($tasklist_id, $task_id);
-        if ($task instanceof PEAR_Error) {
-            return $task;
-        }
-
         $task->completed = !$task->completed;
         if ($task->completed) {
             $task->completed_date = time();
@@ -994,13 +977,8 @@ class Nag_Api extends Horde_Registry_Api
     {
         $storage = Nag_Driver::singleton();
         $task = $storage->getByUID($uid);
-        if (is_a($task, 'PEAR_Error')) {
-            return $task;
-        }
-
-        if (!array_key_exists($task->tasklist,
-                              Nag::listTasklists(false, Horde_Perms::READ))) {
-            return PEAR::raiseError(_("Permission Denied"));
+        if (!array_key_exists($task->tasklist, Nag::listTasklists(false, Horde_Perms::READ))) {
+            throw new Horde_Exception_PermimssionDenied(_("Permission Denied"));
         }
 
         $version = '2.0';
@@ -1023,7 +1001,7 @@ class Nag_Api extends Horde_Registry_Api
         case 'activesync':
             return $task->toASTask();
         default:
-            return PEAR::raiseError(sprintf(_("Unsupported Content-Type: %s"), $contentType));
+            throw new Nag_Exception(sprintf(_("Unsupported Content-Type: %s"), $contentType));
         }
     }
 
@@ -1037,9 +1015,8 @@ class Nag_Api extends Horde_Registry_Api
      */
     public function getTask($tasklist, $id)
     {
-        if (!array_key_exists($tasklist,
-                              Nag::listTasklists(false, Horde_Perms::READ))) {
-            return PEAR::raiseError(_("Permission Denied"));
+        if (!array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::READ))) {
+            throw new Horde_Exception_PermimssionDenied(_("Permission Denied"));
         }
 
         $storage = Nag_Driver::singleton($tasklist);
@@ -1063,10 +1040,9 @@ class Nag_Api extends Horde_Registry_Api
      */
     public function exportTasklist($tasklist, $contentType)
     {
-        if (!array_key_exists($tasklist,
-            Nag::listTasklists(false, Horde_Perms::READ))) {
-                return PEAR::raiseError(_("Permission Denied"));
-            }
+        if (!array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::READ))) {
+            throw new Horde_Exception_PermimssionDenied(_("Permission Denied"));
+        }
 
         $tasks = Nag::listTasks(null, null, null, array($tasklist), 1);
 
@@ -1088,7 +1064,7 @@ class Nag_Api extends Horde_Registry_Api
             return $iCal->exportvCalendar();
         }
 
-        return PEAR::raiseError(sprintf(_("Unsupported Content-Type: %s"), $contentType));
+        throw new Nag_Exception(sprintf(_("Unsupported Content-Type: %s"), $contentType));
 
     }
 
@@ -1102,14 +1078,10 @@ class Nag_Api extends Horde_Registry_Api
      */
     public function delete($uid)
     {
-        // Handle an arrray of UIDs for convenience of deleting multiple tasks at
-        // once.
+        // Handle an arrray of UIDs for convenience
         if (is_array($uid)) {
             foreach ($uid as $g) {
                 $result = $this->delete($g);
-                if (is_a($result, 'PEAR_Error')) {
-                    return $result;
-                }
             }
 
             return true;
@@ -1117,14 +1089,11 @@ class Nag_Api extends Horde_Registry_Api
 
         $storage = Nag_Driver::singleton();
         $task = $storage->getByUID($uid);
-        if (is_a($task, 'PEAR_Error')) {
-            return $task;
-        }
 
         if (!$GLOBALS['registry']->isAdmin() &&
-            !array_key_exists($task->tasklist,
-                              Nag::listTasklists(false, Horde_Perms::DELETE))) {
-            return PEAR::raiseError(_("Permission Denied"));
+            !array_key_exists($task->tasklist, Nag::listTasklists(false, Horde_Perms::DELETE))) {
+
+             throw new Horde_Exception_PermimssionDenied(_("Permission Denied"));
         }
 
         return $storage->delete($task->id);
@@ -1139,9 +1108,9 @@ class Nag_Api extends Horde_Registry_Api
     public function deleteTask($tasklist, $id)
     {
         if (!$GLOBALS['registry']->isAdmin() &&
-            !array_key_exists($tasklist,
-                              Nag::listTasklists(false, Horde_Perms::DELETE))) {
-            return PEAR::raiseError(_("Permission Denied"));
+            !array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::DELETE))) {
+
+            throw new Horde_Exception_PermimssionDenied(_("Permission Denied"));
         }
 
         $storage = Nag_Driver::singleton($tasklist);
@@ -1169,13 +1138,9 @@ class Nag_Api extends Horde_Registry_Api
     {
         $storage = Nag_Driver::singleton();
         $existing = $storage->getByUID($uid);
-        if (is_a($existing, 'PEAR_Error')) {
-            return $existing;
-        }
         $taskId = $existing->id;
-
         if (!array_key_exists($existing->tasklist, Nag::listTasklists(false, Horde_Perms::EDIT))) {
-            return PEAR::raiseError(_("Permission Denied"));
+            throw new Horde_Exception_PermimssionDenied(_("Permission Denied"));
         }
 
         switch ($contentType) {
@@ -1184,7 +1149,7 @@ class Nag_Api extends Horde_Registry_Api
             if (!($content instanceof Horde_Icalendar_Vtodo)) {
                 $iCal = new Horde_Icalendar();
                 if (!$iCal->parsevCalendar($content)) {
-                    return PEAR::raiseError(_("There was an error importing the iCalendar data."));
+                    throw new Nag_Exception(_("There was an error importing the iCalendar data."));
                 }
 
                 $components = $iCal->getComponents();
@@ -1192,14 +1157,14 @@ class Nag_Api extends Horde_Registry_Api
                 foreach ($components as $content) {
                     if ($content instanceof Horde_Icalendar_Vtodo) {
                         if ($component !== null) {
-                            return PEAR::raiseError(_("Multiple iCalendar components found; only one vTodo is supported."));
+                            throw new Nag_Exception(_("Multiple iCalendar components found; only one vTodo is supported."));
                         }
                         $component = $content;
                     }
 
                 }
                 if ($component === null) {
-                    return PEAR::raiseError(_("No iCalendar data was found."));
+                    throw new Nag_Exception(_("No iCalendar data was found."));
                 }
             }
 
@@ -1219,8 +1184,8 @@ class Nag_Api extends Horde_Registry_Api
                 isset($task->parent_id) ? $task->parent_id : $existing->parent_id,
                 isset($task->private) ? $task->private : $existing->private,
                 isset($task->owner) ? $task->owner : $existing->owner,
-                isset($task->assignee) ? $task->assignee : $existing->assignee);
-
+                isset($task->assignee) ? $task->assignee : $existing->assignee
+            );
             break;
 
         case 'activesync':
@@ -1240,10 +1205,11 @@ class Nag_Api extends Horde_Registry_Api
                 isset($task->parent_id) ? $task->parent_id : $existing->parent_id,
                 isset($task->private) ? $task->private : $existing->private,
                 isset($task->owner) ? $task->owner : $existing->owner,
-                isset($task->assignee) ? $task->assignee : $existing->assignee);
+                isset($task->assignee) ? $task->assignee : $existing->assignee
+            );
             break;
         default:
-            return PEAR::raiseError(sprintf(_("Unsupported Content-Type: %s"), $contentType));
+            throw new Nag_Exception(sprintf(_("Unsupported Content-Type: %s"), $contentType));
         }
 
         return $result;
@@ -1259,16 +1225,13 @@ class Nag_Api extends Horde_Registry_Api
     public function updateTask($tasklist, $id, $task)
     {
         if (!$GLOBALS['registry']->isAdmin() &&
-            !array_key_exists($tasklist,
-                              Nag::listTasklists(false, Horde_Perms::EDIT))) {
-            return PEAR::raiseError(_("Permission Denied"));
+            !array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::EDIT))) {
+
+            throw new Horde_Exception_PermimssionDenied(_("Permission Denied"));
         }
 
         $storage = Nag_Driver::singleton($tasklist);
         $existing = $storage->get($id);
-        if (is_a($existing, 'PEAR_Error')) {
-            return $existing;
-        }
 
         return $storage->modify(
             $id,
@@ -1287,7 +1250,8 @@ class Nag_Api extends Horde_Registry_Api
             isset($task['owner']) ? $task['owner'] : $existing->owner,
             isset($task['assignee']) ? $task['assignee'] : $existing->assignee,
             $task['completed'] && !$existing->completed ? date() : $existing->completed_date,
-            isset($task['tasklist']) ? $task['tasklist'] : $existing->tasklist);
+            isset($task['tasklist']) ? $task['tasklist'] : $existing->tasklist
+        );
     }
 
     /**
@@ -1391,19 +1355,14 @@ class Nag_Api extends Horde_Registry_Api
      * @param array $timeobject  A time object hash.
      * @throws Nag_Exception
      */
-    public function saveTimeObject($timeobject)
+    public function saveTimeObject(array $timeobject)
     {
         $storage = Nag_Driver::singleton();
         $existing = $storage->get($timeobject['id']);
-        if (is_a($existing, 'PEAR_Error')) {
-            throw new Nag_Exception($existing->getMessage());
-        }
-        if (!array_key_exists($existing->tasklist,
-                              Nag::listTasklists(false, Horde_Perms::EDIT))) {
-            throw new Horde_Exception_PermissionDenied(_("Permission Denied"));
+        if (!array_key_exists($existing->tasklist, Nag::listTasklists(false, Horde_Perms::EDIT))) {
+            throw new Horde_Exception_PermimssionDenied(_("Permission Denied"));
         }
         $storage = Nag_Driver::singleton($existing->tasklist);
-
         if (isset($timeobject['start'])) {
             $due = new Horde_Date($timeobject['start']);
             $due = $due->timestamp();
@@ -1428,7 +1387,8 @@ class Nag_Api extends Horde_Registry_Api
             $existing->owner,
             $existing->assignee,
             $existing->completed_date,
-            $existing->tasklist);
+            $existing->tasklist
+        );
     }
 
     /**
@@ -1443,19 +1403,18 @@ class Nag_Api extends Horde_Registry_Api
     {
         if ((empty($user) || $user != $GLOBALS['registry']->getAuth()) &&
             !$GLOBALS['registry']->isAdmin()) {
-            return PEAR::raiseError(_("Permission Denied"));
+
+            throw new Horde_Exception_PermimssionDenied(_("Permission Denied"));
         }
 
         $storage = Nag_Driver::singleton();
         $group = $GLOBALS['injector']->getInstance('Horde_Group');
         $alarm_list = array();
-        $tasklists = is_null($user) ? array_keys($GLOBALS['nag_shares']->listAllShares()) :  $GLOBALS['display_tasklists'];
+        $tasklists = is_null($user) ?
+            array_keys($GLOBALS['nag_shares']->listAllShares()) :
+            $GLOBALS['display_tasklists'];
 
         $alarms = Nag::listAlarms($time, $tasklists);
-        if ($alarms instanceof PEAR_Error) {
-            return $alarms;
-        }
-
         foreach ($alarms as $alarm) {
             try {
                 $share = $GLOBALS['nag_shares']->getShare($alarm->tasklist);
index 8c04bc9..1113dbb 100644 (file)
@@ -258,22 +258,18 @@ class Nag_Application extends Horde_Registry_Application
 
         /* Get the list of all tasks */
         $tasks = Nag::listTasks(null, null, null, $user, 1);
-        if ($tasks instanceof PEAR_Error) {
-            Horde::logMessage($tasks, 'ERR');
-            throw new Nag_Exception(sprintf(_("There was an error removing tasks for %s. Details have been logged."), $user));
-        } else {
-            $uids = array();
-            $tasks->reset();
-            while ($task = $tasks->each()) {
-                $uids[] = $task->uid;
-            }
+        $uids = array();
+        $tasks->reset();
+        while ($task = $tasks->each()) {
+            $uids[] = $task->uid;
+        }
 
-            /* ... and delete them. */
-            foreach ($uids as $uid) {
-                $this->delete($uid);
-            }
+        /* ... and delete them. */
+        foreach ($uids as $uid) {
+            $this->delete($uid);
         }
 
+
         /* ...and finally, delete the actual share */
         if (!empty($share)) {
             try {
@@ -317,13 +313,8 @@ class Nag_Application extends Horde_Registry_Application
             // Get any alarms in the next hour.
             $now = time();
             $alarms = Nag::listAlarms($now);
-            if ($alarms instanceof PEAR_Error) {
-                return;
-            }
-
             $alarmCount = 0;
             $horde_alarm = $GLOBALS['injector']->getInstance('Horde_Alarm');
-
             foreach ($alarms as $taskId => $task) {
                 if ($horde_alarm->isSnoozed($task->uid, $registry->getAuth())) {
                     continue;
index 8b667b6..b85f239 100644 (file)
@@ -97,9 +97,10 @@ class Horde_Block_nag_summary extends Horde_Block
 
         if (!empty($this->_params['show_alarms'])) {
             $messages = array();
-            $alarmList = Nag::listAlarms($now);
-            if (is_a($alarmList, 'PEAR_Error')) {
-                return '<em>' . htmlspecialchars($alarmList->getMessage())
+            try {
+                $alarmList = Nag::listAlarms($now);
+            } catch (Nag_Exception $e) {
+                return '<em>' . htmlspecialchars($e->getMessage())
                     . '</em>';
             }
             foreach ($alarmList as $task) {
@@ -139,14 +140,18 @@ class Horde_Block_nag_summary extends Horde_Block
         }
 
         $i = 0;
-        $tasks = Nag::listTasks(
-            null, null, null,
-            isset($this->_params['show_tasklists'])
-                ? $this->_params['show_tasklists']
-            : array_keys(Nag::listTasklists(false, Horde_Perms::READ)),
-            empty($this->_params['show_completed']) ? 0 : 1);
-        if (is_a($tasks, 'PEAR_Error')) {
-            return '<em>' . htmlspecialchars($tasks->getMessage()) . '</em>';
+        try {
+            $tasks = Nag::listTasks(
+                null, null, null,
+                isset($this->_params['show_tasklists']) ?
+                    $this->_params['show_tasklists'] :
+                    array_keys(Nag::listTasklists(false, Horde_Perms::READ)),
+                empty($this->_params['show_completed']) ?
+                        0 :
+                        1
+            );
+        } catch (Nag_Exception $e) {
+            return '<em>' . htmlspecialchars($e->getMessage()) . '</em>';
         }
 
         $tasks->reset();
index 37e5c27..5ccb157 100644 (file)
@@ -16,36 +16,39 @@ class Nag_Driver
      *
      * @var Nag_Task
      */
-    var $tasks;
+    public $tasks;
 
     /**
      * String containing the current tasklist.
      *
      * @var string
      */
-    var $_tasklist = '';
+    protected $_tasklist = '';
 
     /**
      * Hash containing connection parameters.
      *
      * @var array
      */
-    var $_params = array();
+    protected $_params = array();
 
     /**
      * An error message to throw when something is wrong.
      *
      * @var string
      */
-    var $_errormsg;
+    protected $_errormsg;
 
     /**
      * Constructor - just store the $params in our newly-created
      * object. All other work is done by initialize().
      *
-     * @param array $params  Any parameters needed for this driver.
+     * @param array $params     Any parameters needed for this driver.
+     * @param string $errormsg  Custom error message
+     *
+     * @return Nag_Driver
      */
-    function Nag_Driver($params = array(), $errormsg = null)
+    public function __construct(array $params = array(), $errormsg = null)
     {
         $this->tasks = new Nag_Task();
         $this->_params = $params;
@@ -63,13 +66,10 @@ class Nag_Driver
      *
      * @return array  An array of tasks that have alarms that match.
      */
-    function listAlarms($date)
+    public function listAlarms($date)
     {
         if (!$this->tasks->count()) {
             $result = $this->retrieve(0);
-            if (is_a($result, 'PEAR_Error')) {
-                return $result;
-            }
         }
         $alarms = array();
         $this->tasks->reset();
@@ -99,25 +99,21 @@ class Nag_Driver
      * @return mixed    The newly created concrete Nag_Driver instance, or
      *                  false on an error.
      */
-    function factory($tasklist = '', $driver = null, $params = null)
+    static public function factory($tasklist = '', $driver = null, $params = null)
     {
         if (is_null($driver)) {
             $driver = $GLOBALS['conf']['storage']['driver'];
         }
-
         $driver = ucfirst(basename($driver));
-
         if (is_null($params)) {
             $params = Horde::getDriverConfig('storage', $driver);
         }
-
-        require_once dirname(__FILE__) . '/Driver/' . $driver . '.php';
         $class = 'Nag_Driver_' . $driver;
         if (class_exists($class)) {
-            $nag = new $class($tasklist, $params);
-            $result = $nag->initialize();
-            if (is_a($result, 'PEAR_Error')) {
-                $nag = new Nag_Driver($params, sprintf(_("The Tasks backend is not currently available: %s"), $result->getMessage()));
+            try {
+                $nag = new $class($tasklist, $params);
+            } catch (Nag_Exception $e) {
+                $nag = new Nag_Driver($params, sprintf(_("The Tasks backend is not currently available: %s"), $e->getMessage()));
             }
         } else {
             $nag = new Nag_Driver($params, sprintf(_("Unable to load the definition of %s."), $class));
@@ -150,7 +146,7 @@ class Nag_Driver
      * @return mixed    The created concrete Nag_Driver instance, or false
      *                  on error.
      */
-    function &singleton($tasklist = '', $driver = null, $params = null)
+    static public function &singleton($tasklist = '', $driver = null, array $params = null)
     {
         static $instances = array();
 
@@ -191,9 +187,9 @@ class Nag_Driver
      *
      * @return array  array(ID,UID) of new task
      */
-    function add($name, $desc, $start = 0, $due = 0, $priority = 0,
+    public function add($name, $desc, $start = 0, $due = 0, $priority = 0,
                  $estimate = 0.0, $completed = 0, $category = '', $alarm = 0,
-                 $methods = null, $uid = null, $parent = '', $private = false,
+                 array $methods = null, $uid = null, $parent = '', $private = false,
                  $owner = null, $assignee = null)
     {
         if (is_null($uid)) {
@@ -206,9 +202,7 @@ class Nag_Driver
         $taskId = $this->_add($name, $desc, $start, $due, $priority, $estimate,
                               $completed, $category, $alarm, $methods, $uid,
                               $parent, $private, $owner, $assignee);
-        if (is_a($taskId, 'PEAR_Error')) {
-            return $taskId;
-        }
+
         $task = $this->get($taskId);
         $task->process();
 
@@ -231,9 +225,6 @@ class Nag_Driver
 
         /* Notify users about the new event. */
         $result = Nag::sendNotification('add', $task);
-        if (is_a($result, 'PEAR_Error')) {
-            Horde::logMessage($result, 'ERR');
-        }
 
         /* Add an alarm if necessary. */
         if (!empty($alarm) &&
@@ -266,31 +257,26 @@ class Nag_Driver
      * @param string $assignee         The assignee of the event.
      * @param integer $completed_date  The task's completion date.
      * @param string $tasklist         The new tasklist.
+     *
+     * @throws Nag_Exception
      */
-    function modify($taskId, $name, $desc, $start = 0, $due = 0, $priority = 0,
+    public function modify($taskId, $name, $desc, $start = 0, $due = 0, $priority = 0,
                     $estimate = 0.0, $completed = 0, $category = '',
-                    $alarm = 0, $methods = null, $parent = '', $private = false,
+                    $alarm = 0, array $methods = null, $parent = '', $private = false,
                     $owner = null, $assignee = null, $completed_date = null,
                     $tasklist = null)
     {
         /* Retrieve unmodified task. */
         $task = $this->get($taskId);
-        if (is_a($task, 'PEAR_Error')) {
-            return $task;
-        }
 
         /* Avoid circular reference. */
         if ($parent == $taskId) {
             $parent = '';
         }
-
         $modify = $this->_modify($taskId, $name, $desc, $start, $due,
                                  $priority, $estimate, $completed, $category,
                                  $alarm, $methods, $parent, $private, $owner,
                                  $assignee, $completed_date);
-        if (is_a($modify, 'PEAR_Error')) {
-            return $modify;
-        }
 
         $new_task = $this->get($task->id);
         $log_tasklist = $this->_tasklist;
@@ -320,9 +306,6 @@ class Nag_Driver
             }
 
             $moved = $this->_move($task->id, $tasklist);
-            if ($moved instanceof PEAR_Error) {
-                return $moved;
-            }
             $new_storage = Nag_Driver::singleton($tasklist);
             $new_task = $new_storage->get($task->id);
 
@@ -380,9 +363,10 @@ class Nag_Driver
         }
 
         /* Notify users about the changed event. */
-        $result = Nag::sendNotification('edit', $new_task, $task);
-        if (is_a($result, 'PEAR_Error')) {
-            Horde::logMessage($result, 'ERR');
+        try {
+            $result = Nag::sendNotification('edit', $new_task, $task);
+        } catch (Nag_Exception $e) {
+            Horde::logMessage($e, 'ERR');
         }
 
         return true;
@@ -393,18 +377,11 @@ class Nag_Driver
      *
      * @param string $taskId  The task to delete.
      */
-    function delete($taskId)
+    public function delete($taskId)
     {
         /* Get the task's details for use later. */
         $task = $this->get($taskId);
-        if ($task instanceof PEAR_Error) {
-            return $task;
-        }
-
         $delete = $this->_delete($taskId);
-        if (is_a($delete, 'PEAR_Error')) {
-            return $delete;
-        }
 
         /* Log the deletion of this item in the history log. */
         if (!empty($task->uid)) {
@@ -416,27 +393,26 @@ class Nag_Driver
         }
 
         /* Notify users about the deleted event. */
-        $result = Nag::sendNotification('delete', $task);
-        if (is_a($result, 'PEAR_Error')) {
-            Horde::logMessage($result, 'ERR');
+        try {
+            $result = Nag::sendNotification('delete', $task);
+        } catch (Nag_Exception $e) {
+            Horde::logMessage($e, 'ERR');
         }
 
         /* Delete alarm if necessary. */
         if (!empty($task->alarm)) {
             $GLOBALS['injector']->getInstance('Horde_Alarm')->delete($task->uid);
         }
-
-        return true;
     }
 
     /**
      * Retrieves tasks from the database.
      *
-     * @return mixed  True on success, PEAR_Error on failure.
+     * @throws Nag_Exception
      */
-    function retrieve()
+    public function retrieve()
     {
-        return PEAR::raiseError($this->_errormsg);
+        throw new Nag_Exception($this->_errormsg);
     }
 
     /**
@@ -445,10 +421,11 @@ class Nag_Driver
      * @param string $parentId  The parent id for the sub-tasks to retrieve.
      *
      * @return array  List of sub-tasks.
+     * @throws Nag_Exception
      */
-    function getChildren($parentId)
+    public function getChildren($parentId)
     {
-        return PEAR::raiseError($this->_errormsg);
+        throw new Nag_Exception($this->_errormsg);
     }
 
     /**
@@ -457,10 +434,11 @@ class Nag_Driver
      * @param string $taskId  The id of the task to retrieve.
      *
      * @return Nag_Task  A Nag_Task object.
+     * @throws Nag_Exception
      */
-    function get($taskId)
+    public function get($taskId)
     {
-        return PEAR::raiseError($this->_errormsg);
+        throw new Nag_Exception($this->_errormsg);
     }
 
     /**
@@ -469,10 +447,11 @@ class Nag_Driver
      * @param string $uid  The UID of the task to retrieve.
      *
      * @return Nag_Task  A Nag_Task object.
+     * @throws Nag_Exception
      */
-    function getByUID($uid)
+    public function getByUID($uid)
     {
-        return PEAR::raiseError($this->_errormsg);
+        throw new Nag_Exception($this->_errormsg);
     }
 
 }
index 8dfcae1..c7988ac 100644 (file)
  * @author  Jon Parise <jon@horde.org>
  * @package Nag
  */
-class Nag_Driver_Sql extends Nag_Driver {
-
+class Nag_Driver_Sql extends Nag_Driver
+{
     /**
      * Handle for the current database connection.
      *
      * @var Horde_Db_Adapter
      */
-    var $_db;
+    protected $_db;
 
     /**
      * Constructs a new SQL storage object.
@@ -29,6 +29,14 @@ class Nag_Driver_Sql extends Nag_Driver {
     {
         $this->_tasklist = $tasklist;
         $this->_params = $params;
+        if (!isset($this->_params['table'])) {
+            $this->_params['table'] = 'nag_tasks';
+        }
+
+        // @TODO: Use a bound factory for Nag_Driver and inject this from there.
+        $this->_db = $GLOBALS['injector']
+            ->getInstance('Horde_Core_Factory_Db')
+            ->create('nag', 'storage');
     }
 
     /**
@@ -37,25 +45,24 @@ class Nag_Driver_Sql extends Nag_Driver {
      * @param string $taskId  The id of the task to retrieve.
      *
      * @return Nag_Task  A Nag_Task object.
+     * @throws Horde_Exception_NotFound
+     * @throws Nag_Exception
      */
-    function get($taskId)
+    public function get($taskId)
     {
-        /* Build the SQL query. */
         $query = sprintf('SELECT * FROM %s WHERE task_id = ?',
                          $this->_params['table']);
         $values = array($taskId);
-
         try {
             $row = $this->_db->selectOne($query, $values);
         } catch (Horde_Db_Exception $e) {
-            return PEAR::raiseError($e->getMessage());
+            throw new Nag_Exception($e);
         }
-
         if (!$row) {
-            return PEAR::raiseError(_("Task not found"));
+            throw new Horde_Exception_NotFound("Task not found");
         }
 
-        /* Decode and return the task. */
+        // Decode and return the task.
         return new Nag_Task($this->_buildTask($row));
     }
 
@@ -65,27 +72,25 @@ class Nag_Driver_Sql extends Nag_Driver {
      * @param string $uid  The UID of the task to retrieve.
      *
      * @return Nag_Task  A Nag_Task object.
+     * @throws Horde_Exception_NotFound
+     * @throws Nag_Exception
      */
-    function getByUID($uid)
+    public function getByUID($uid)
     {
-        /* Build the SQL query. */
         $query = sprintf('SELECT * FROM %s WHERE task_uid = ?',
                          $this->_params['table']);
         $values = array($uid);
-
         try {
             $row = $this->_db->selectOne($query, $values);
         } catch (Horde_Db_Exception $e) {
-            return PEAR::raiseError($e->getMessage());
+            throw new Nag_Exception($e->getMessage());
         }
-
         if (!$row) {
-            return PEAR::raiseError(_("Task UID not found"));
+            throw new Horde_Exception_NotFound(_("Task UID not found"));
         }
-
-        /* Decode and return the task. */
         $this->_tasklist = $row['task_owner'];
 
+        // Decode and return the task.
         return new Nag_Task($this->_buildTask($row));
     }
 
@@ -109,10 +114,11 @@ class Nag_Driver_Sql extends Nag_Driver {
      * @param string $assignee    The assignee of the event.
      *
      * @return string  The Nag ID of the new task.
+     * @throws Nag_Exception
      */
-    function _add($name, $desc, $start = 0, $due = 0, $priority = 0,
+    protected function _add($name, $desc, $start = 0, $due = 0, $priority = 0,
                   $estimate = 0.0, $completed = 0, $category = '', $alarm = 0,
-                  $methods = null, $uid = null, $parent = '', $private = false,
+                  array $methods = null, $uid = null, $parent = '', $private = false,
                   $owner = null, $assignee = null)
     {
         $taskId = strval(new Horde_Support_Randomid());
@@ -148,7 +154,7 @@ class Nag_Driver_Sql extends Nag_Driver {
         try {
             $this->_db->insert($query, $values);
         } catch (Horde_Db_Exception $e) {
-            return PEAR::raiseError($e->getMessage());
+            throw new Nag_Exception($e->getMessage());
         }
 
         return $taskId;
@@ -174,10 +180,12 @@ class Nag_Driver_Sql extends Nag_Driver {
      * @param string $owner            The owner of the event.
      * @param string $assignee         The assignee of the event.
      * @param integer $completed_date  The task's completion date.
+     *
+     * @throws Nag_Exception
      */
-    function _modify($taskId, $name, $desc, $start = 0, $due = 0,
+    protected function _modify($taskId, $name, $desc, $start = 0, $due = 0,
                      $priority = 0, $estimate = 0.0, $completed = 0,
-                     $category = '', $alarm = 0, $methods = null,
+                     $category = '', $alarm = 0, array $methods = null,
                      $parent = '', $private = false, $owner = null,
                      $assignee = null, $completed_date = null)
     {
@@ -220,7 +228,7 @@ class Nag_Driver_Sql extends Nag_Driver {
         try {
             $this->_db->update($query, $values);
         } catch (Horde_Db_Exception $e) {
-            return PEAR::raiseError($e->getMessage());
+            throw new Nag_Exception($e->getMessage());
         }
 
         return true;
@@ -231,8 +239,10 @@ class Nag_Driver_Sql extends Nag_Driver {
      *
      * @param string $taskId       The task to move.
      * @param string $newTasklist  The new tasklist.
+     *
+     * @throws Nag_Exception
      */
-    function _move($taskId, $newTasklist)
+    protected function _move($taskId, $newTasklist)
     {
         $query = sprintf('UPDATE %s SET task_owner = ? WHERE task_owner = ? AND task_id = ?',
                          $this->_params['table']);
@@ -241,18 +251,18 @@ class Nag_Driver_Sql extends Nag_Driver {
         try {
             $this->_db->update($query, $values);
         } catch (Horde_Db_Exception $e) {
-            return PEAR::raiseError($e->getMessage());
+            throw new Nag_Exception($e->getMessage());
         }
-
-        return true;
     }
 
     /**
      * Deletes a task from the backend.
      *
      * @param string $taskId  The task to delete.
+     *
+     * @throws Nag_Exception
      */
-    function _delete($taskId)
+    protected function _delete($taskId)
     {
         /* Get the task's details for use later. */
         $task = $this->get($taskId);
@@ -264,18 +274,16 @@ class Nag_Driver_Sql extends Nag_Driver {
         try {
             $this->_db->delete($query, $values);
         } catch (Horde_Db_Exception $e) {
-            return PEAR::raiseError($e->getMessage());
+            throw Nag_Exception($e->getMessage());
         }
-
-        return true;
     }
 
     /**
      * Deletes all tasks from the backend.
      *
-     * @return mixed  True on success, PEAR_Error on failure.
+     * @throws Nag_Exception
      */
-    function deleteAll()
+    public function deleteAll()
     {
         $query = sprintf('DELETE FROM %s WHERE task_owner = ?',
                          $this->_params['table']);
@@ -285,10 +293,8 @@ class Nag_Driver_Sql extends Nag_Driver {
         try {
             $this->_db->delete($query, $values);
         } catch (Horde_Db_Exception $e) {
-            return PEAR::raiseError($e->getMessage());
+            throw new Nag_Exception($e->getMessage());
         }
-
-        return true;
     }
 
     /**
@@ -298,8 +304,7 @@ class Nag_Driver_Sql extends Nag_Driver {
      *                            0 = incomplete tasks, 2 = complete tasks,
      *                            3 = future tasks, 4 = future and incomplete
      *                            tasks).
-     *
-     * @return mixed  True on success, PEAR_Error on failure.
+     * @throws Nag_Exception
      */
     function retrieve($completed = Nag::VIEW_ALL)
     {
@@ -330,7 +335,7 @@ class Nag_Driver_Sql extends Nag_Driver {
         try {
             $result = $this->_db->selectAll($query, $values);
         } catch (Horde_Db_Exception $e) {
-            return PEAR::raiseError($e->getMessage());
+            throw new Nag_Exception($e->getMessage());
         }
 
         /* Store the retrieved values in a fresh task list. */
@@ -360,8 +365,6 @@ class Nag_Driver_Sql extends Nag_Driver {
                 $this->tasks->add($dict[$key]);
             }
         }
-
-        return true;
     }
 
     /**
@@ -370,10 +373,11 @@ class Nag_Driver_Sql extends Nag_Driver {
      * @param string $parentId  The parent id for the sub-tasks to retrieve.
      *
      * @return array  List of sub-tasks.
+     * @throws Nag_Exception
      */
-    function getChildren($parentId)
+    public function getChildren($parentId)
     {
-        /* Build the SQL query. */
+        // Build the SQL query.
         $query = sprintf('SELECT * FROM %s WHERE task_owner = ? AND task_parent = ?',
                          $this->_params['table']);
         $values = array($this->_tasklist, $parentId);
@@ -381,17 +385,14 @@ class Nag_Driver_Sql extends Nag_Driver {
         try {
             $result = $this->_db->selectAll($query, $values);
         } catch (Horde_Db_Exception $e) {
-            return PEAR::raiseError($e->getMessage());
+            throw new Nag_Exception($e->getMessage());
         }
 
-        /* Store the retrieved values in a fresh task list. */
+        // Store the retrieved values in a fresh task list.
         $tasks = array();
         foreach ($result as $row) {
             $task = new Nag_Task($this->_buildTask($row));
             $children = $this->getChildren($task->id);
-            if ($children instanceof PEAR_Error) {
-                return $children;
-            }
             $task->mergeChildren($children);
             $tasks[] = $task;
         }
@@ -405,8 +406,9 @@ class Nag_Driver_Sql extends Nag_Driver {
      * @param integer $date  The unix epoch time to check for alarms.
      *
      * @return array  An array of tasks that have alarms that match.
+     * @throws Nag_Exception
      */
-    function listAlarms($date)
+    public function listAlarms($date)
     {
         $q = 'SELECT * FROM ' . $this->_params['table'] .
             ' WHERE task_owner = ?' .
@@ -418,7 +420,7 @@ class Nag_Driver_Sql extends Nag_Driver {
         try {
             $result = $this->_db->selectAll($q, $values);
         } catch (Horde_Db_Exception $e) {
-            return PEAR::raiseError($e->getMessage());
+            throw new Nag_Exception($e->getMessage());
         }
 
         $tasks = array();
@@ -431,9 +433,9 @@ class Nag_Driver_Sql extends Nag_Driver {
 
     /**
      */
-    function _buildTask($row)
+    protected function _buildTask($row)
     {
-        /* Make sure tasks always have a UID. */
+        // Make sure tasks always have a UID.
         if (empty($row['task_uid'])) {
             $row['task_uid'] = strval(new Horde_Support_Guid());
 
@@ -470,20 +472,4 @@ class Nag_Driver_Sql extends Nag_Driver {
         );
     }
 
-    /**
-     * Attempts to open a connection to the SQL server.
-     *
-     * @return boolean  True on success, PEAR_Error on failure.
-     */
-    function initialize()
-    {
-        if (!isset($this->_params['table'])) {
-            $this->_params['table'] = 'nag_tasks';
-        }
-
-        $this->_db = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Db')->create('nag', 'storage');
-
-        return true;
-    }
-
 }
diff --git a/nag/lib/Form/CreateTaskList.php b/nag/lib/Form/CreateTaskList.php
new file mode 100644 (file)
index 0000000..8952959
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+/**
+ * Horde_Form for creating task lists.
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @package Nag
+ */
+/**
+ * The Nag_CreateTaskListForm class provides the form for
+ * creating a task list.
+ *
+ * @author  Chuck Hagenbuch <chuck@horde.org>
+ * @package Nag
+ */
+class Nag_Form_CreateTaskList extends Horde_Form
+{
+    public function __construct($vars)
+    {
+        parent::__construct($vars, _("Create Task List"));
+
+        $this->addVariable(_("Name"), 'name', 'text', true);
+        $this->addVariable(_("Color"), 'color', 'colorpicker', false);
+        $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
+        if ($GLOBALS['registry']->isAdmin()) {
+            $this->addVariable(
+                _("System Task List"), 'system', 'boolean', false, false,
+                _("System task lists don't have an owner. Only administrators can change the task list settings and permissions."));
+        }
+
+        $this->setButtons(array(_("Create")));
+    }
+
+    public function execute()
+    {
+        $info = array();
+        foreach (array('name', 'color', 'description', 'system') as $key) {
+            $info[$key] = $this->_vars->get($key);
+        }
+        return Nag::addTasklist($info);
+    }
+
+}
diff --git a/nag/lib/Form/DeleteTaskList.php b/nag/lib/Form/DeleteTaskList.php
new file mode 100644 (file)
index 0000000..2ea3233
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+/**
+ * Horde_Form for deleting task lists.
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @package Nag
+ */
+/**
+ * The Nag_DeleteTaskListForm class provides the form for
+ * deleting a task list.
+ *
+ * @author  Chuck Hagenbuch <chuck@horde.org>
+ * @package Nag
+ */
+class Nag_Form_DeleteTaskList extends Horde_Form
+{
+    /**
+     * Task list being deleted.
+     *
+     * @var Horde_Share_Object
+     */
+    protected $_tasklist;
+
+    /**
+     *
+     * @param array $vars
+     * @param Horde_Share_Object $tasklist
+     */
+    public function __construct($vars, Horde_Share_Object $tasklist)
+    {
+        $this->_tasklist = $tasklist;
+        parent::__construct($vars, sprintf(_("Delete %s"), $tasklist->get('name')));
+        $this->addHidden('', 't', 'text', true);
+        $this->addVariable(
+            sprintf(_("Really delete the task list \"%s\"? This cannot be undone and all data on this task list will be permanently removed."),
+            $this->_tasklist->get('name')), 'desc', 'description', false
+        );
+        $this->setButtons(array(_("Delete"), _("Cancel")));
+    }
+
+    public function execute()
+    {
+        // If cancel was clicked, return false.
+        if ($this->_vars->get('submitbutton') == _("Cancel")) {
+            return false;
+        }
+
+        return Nag::deleteTasklist($this->_tasklist);
+    }
+
+}
diff --git a/nag/lib/Form/EditTaskList.php b/nag/lib/Form/EditTaskList.php
new file mode 100644 (file)
index 0000000..51aecff
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+/**
+ * Horde_Form for editing task lists.
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @package Nag
+ */
+/**
+ * The Nag_EditTaskListForm class provides the form for
+ * editing a task list.
+ *
+ * @author  Chuck Hagenbuch <chuck@horde.org>
+ * @package Nag
+ */
+class Nag_Form_EditTaskList extends Horde_Form
+{
+    /**
+     * Task list being edited
+     *
+     *
+     * @var Horde_Share_Object
+     */
+    protected $_tasklist;
+
+    /**
+     *
+     * @param array $vars
+     * @param Horde_Share_Object $tasklist
+     */
+    public function __construct($vars, Horde_Share_Object $tasklist)
+    {
+        $this->_tasklist = $tasklist;
+        parent::__construct($vars, sprintf(_("Edit %s"), $tasklist->get('name')));
+        $this->addHidden('', 't', 'text', true);
+        $this->addVariable(_("Task List Name"), 'name', 'text', true);
+        $this->addVariable(_("Task List Description"), 'description', 'longtext', false, false, null, array(4, 60));
+        if ($GLOBALS['registry']->isAdmin()) {
+            $this->addVariable(
+                _("System Task List"), 'system', 'boolean', false, false,
+                _("System task lists don't have an owner. Only administrators can change the task list settings and permissions.")
+            );
+        }
+        $this->setButtons(array(_("Save")));
+    }
+
+    public function execute()
+    {
+        $info = array();
+        foreach (array('name', 'color', 'description', 'system') as $key) {
+            $info[$key] = $this->_vars->get($key);
+        }
+        return Nag::updateTasklist($this->_tasklist, $info);
+    }
+
+}
diff --git a/nag/lib/Form/Renderer/Task.php b/nag/lib/Form/Renderer/Task.php
new file mode 100644 (file)
index 0000000..96c6513
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+/**
+ * This file contains all Horde_Form extensions required for editing tasks.
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @package Nag
+ */
+/**
+ * The Nag_TaskForm class provides the form for adding and editing a task.
+ *
+ * @author  Jan Schneider <jan@horde.org>
+ * @package Nag
+ */
+class Nag_Form_Renderer_Task extends Horde_Form_Renderer
+{
+    public $delete;
+
+    /**
+     *
+     * @param array $params
+     * @param boolean $delete
+     */
+    public function __construct($params = array(), $delete = false)
+    {
+        parent::__construct($params);
+        $this->delete = $delete;
+    }
+
+    /**
+     *@TODO: visibility needs to be public until Horde_Form refactored
+     */
+    public function _renderSubmit($submit, $reset)
+    {
+        ?><div class="control" style="padding:1em;">
+            <input class="button leftFloat" name="submitbutton" type="submit" value="<?php echo _("Save") ?>" />
+        <?php if ($this->delete): ?>
+            <input class="button rightFloat" name="submitbutton" type="submit" value="<?php echo _("Delete this task") ?>" />
+        <?php endif; ?>
+            <div class="clear"></div>
+        </div>
+        <?php
+    }
+
+}
\ No newline at end of file
diff --git a/nag/lib/Form/Type/NagAlarm.php b/nag/lib/Form/Type/NagAlarm.php
new file mode 100644 (file)
index 0000000..83a5682
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+/**
+ * The Horde_Form_Type_nag_alarm class provides a form field for editing task
+ * alarms.
+ *
+ * @author  Jan Schneider <jan@horde.org>
+ * @package Nag
+ */
+class Nag_Form_Type_NagAlarm extends Horde_Form_Type
+{
+    public function getInfo(&$vars, &$var, &$info)
+    {
+        $info = $var->getValue($vars);
+        if (!$info['on']) {
+            $info = 0;
+        } else {
+            $value = $info['value'];
+            $unit = $info['unit'];
+            if ($value == 0) {
+                $value = $unit = 1;
+            }
+            $info = $value * $unit;
+        }
+    }
+
+    public function isValid(&$var, &$vars, $value, &$message)
+    {
+        if ($value['on']) {
+            if ($vars->get('due_type') == 'none') {
+                $message = _("A due date must be set to enable alarms.");
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    public function getTypeName()
+    {
+        return 'NagAlarm';
+    }
+
+}
\ No newline at end of file
diff --git a/nag/lib/Form/Type/NagDue.php b/nag/lib/Form/Type/NagDue.php
new file mode 100644 (file)
index 0000000..27eb59a
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+/**
+ * The Horde_Form_Type_nag_due class provides a form field for editing
+ * task due dates.
+ *
+ * @author  Chuck Hagenbuch <chuck@horde.org>
+ * @package Nag
+ */
+class Nag_Form_Type_NagDue extends Horde_Form_Type
+{
+    public function getInfo(&$vars, &$var, &$info)
+    {
+        $due_type = $vars->get('due_type');
+        $due = $vars->get('due');
+        if (is_array($due)) {
+            $due_day = !empty($due['day']) ? $due['day'] : null;
+            $due_month = !empty($due['month']) ? $due['month'] : null;
+            $due_year = !empty($due['year']) ? $due['year'] : null;
+            $due_hour = Horde_Util::getFormData('due_hour');
+            $due_minute = Horde_Util::getFormData('due_minute');
+            if (!$GLOBALS['prefs']->getValue('twentyFour')) {
+                $due_am_pm = Horde_Util::getFormData('due_am_pm');
+                if ($due_am_pm == 'pm') {
+                    if ($due_hour < 12) {
+                        $due_hour = $due_hour + 12;
+                    }
+                } else {
+                    // Adjust 12:xx AM times.
+                    if ($due_hour == 12) {
+                        $due_hour = 0;
+                    }
+                }
+            }
+
+            $due = (int)strtotime("$due_month/$due_day/$due_year $due_hour:$due_minute");
+        }
+
+        $info = strcasecmp($due_type, 'none') ? $due : 0;
+    }
+
+    public function isValid(&$var, &$vars, $value, &$message)
+    {
+        return true;
+    }
+
+    public function getTypeName()
+    {
+        return 'NagDue';
+    }
+
+}
\ No newline at end of file
diff --git a/nag/lib/Form/Type/NagMethod.php b/nag/lib/Form/Type/NagMethod.php
new file mode 100644 (file)
index 0000000..ef5b65c
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/**
+ * The Horde_Form_Type_nag_method class provides a form field for editing
+ * notification methods for a task alarm.
+ *
+ * @TODO: Need to refactor these to be named as Nag_Form_Type... once Horde_Form
+ *        is refactored and no longer needs
+ *
+ * @author  Alfonso Marin <almarin@um.es>
+ * @package Nag
+ */
+class Nag_Form_Type_NagMethod extends Horde_Form_Type
+{
+    public function getInfo(&$vars, &$var, &$info)
+    {
+        $info = $var->getValue($vars);
+        if (empty($info['on'])) {
+            $info = array();
+            return;
+        }
+
+        $types = $vars->get('task_alarms');
+        $info = array();
+        if (!empty($types)) {
+            foreach ($types as $type) {
+                $info[$type] = array();
+                switch ($type){
+                    case 'notify':
+                        $info[$type]['sound'] = $vars->get('task_alarms_sound');
+                        break;
+                    case 'mail':
+                        $info[$type]['email'] = $vars->get('task_alarms_email');
+                        break;
+                    case 'popup':
+                        break;
+                }
+            }
+        }
+    }
+
+    public function isValid(&$var, &$vars, $value, &$message)
+    {
+        $alarm = $vars->get('alarm');
+        if ($value['on'] && !$alarm['on']){
+            $message = _("An alarm must be set to specify a notification method");
+            return false;
+        }
+        return true;
+    }
+
+    public function getTypeName()
+    {
+        return 'NagMethod';
+    }
+
+}
diff --git a/nag/lib/Form/Type/NagStart.php b/nag/lib/Form/Type/NagStart.php
new file mode 100644 (file)
index 0000000..1da0bf8
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+/**
+ * The Horde_Form_Type_nag_start class provides a form field for editing
+ * task delayed start dates.
+ *
+ * @author  Chuck Hagenbuch <chuck@horde.org>
+ * @package Nag
+ */
+class Nag_Form_Type_NagStart extends Horde_Form_Type
+{
+    public function getInfo(&$vars, &$var, &$info)
+    {
+        $start_type = $vars->get('start_date');
+        $start = $vars->get('start');
+        if (is_array($start)) {
+            $start_day = !empty($start['day']) ? $start['day'] : null;
+            $start_month = !empty($start['month']) ? $start['month'] : null;
+            $start_year = !empty($start['year']) ? $start['year'] : null;
+            $start = (int)strtotime("$start_month/$start_day/$start_year");
+        }
+
+        $info = strcasecmp($start_type, 'none') ? $start : 0;
+    }
+
+    public function isValid(&$var, &$vars, $value, &$message)
+    {
+        return true;
+    }
+
+    public function getTypeName()
+    {
+        return 'NagStart';
+    }
+
+}
diff --git a/nag/lib/Form/task.php b/nag/lib/Form/task.php
new file mode 100644 (file)
index 0000000..855a7e2
--- /dev/null
@@ -0,0 +1,136 @@
+<?php
+/**
+ * This file contains all Horde_Form extensions required for editing tasks.
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @package Nag
+ */
+
+/**
+ * The Nag_TaskForm class provides the form for adding and editing a task.
+ *
+ * @author  Jan Schneider <jan@horde.org>
+ * @package Nag
+ */
+class Nag_Form_Task extends Horde_Form
+{
+    public $delete;
+
+    public function __construct($vars, $title = '', $delete = false)
+    {
+        parent::__construct($vars, $title);
+        $this->delete = $delete;
+        $tasklists = Nag::listTasklists(false, Horde_Perms::EDIT);
+        $tasklist_enums = array();
+        foreach ($tasklists as $tl_id => $tl) {
+            if ($tl->get('owner') != $GLOBALS['registry']->getAuth() &&
+                !empty($GLOBALS['conf']['share']['hidden']) &&
+                !in_array($tl->getName(), $GLOBALS['display_tasklists'])) {
+                continue;
+            }
+            $tasklist_enums[$tl_id] = $tl->get('name');
+        }
+        $tasklist = $vars->get('tasklist_id');
+        if (empty($tasklist)) {
+            reset($tasklist_enums);
+            $tasklist = key($tasklist_enums);
+        }
+        $tasks = Nag::listTasks(null, null, null, array($tasklist), Nag::VIEW_FUTURE_INCOMPLETE);
+        $task_enums = array('' => _("No parent task"));
+        $tasks->reset();
+        while ($task = $tasks->each()) {
+            if ($vars->get('task_id') == $task->id) {
+                continue;
+            }
+            $task_enums[htmlspecialchars($task->id)] = str_repeat('&nbsp;', $task->indent * 4) . htmlentities($task->name);
+        }
+        $users = array();
+        $share = $GLOBALS['nag_shares']->getShare($tasklist);
+        $users = $share->listUsers(Horde_Perms::READ);
+        $groups = $share->listGroups(Horde_Perms::READ);
+        if (count($groups)) {
+            $horde_group = $GLOBALS['injector']->getInstance('Horde_Group');
+            foreach ($groups as $group) {
+                $users = array_merge($users,
+                                     $horde_group->listAllUsers($group));
+            }
+        }
+        $users = array_flip($users);
+
+        if (count($users)) {
+            foreach (array_keys($users) as $user) {
+                $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($user);
+                $fullname = $identity->getValue('fullname');
+                $users[$user] = strlen($fullname) ? $fullname : $user;
+            }
+        }
+        $priorities = array(
+            1 => '1 ' . _("(highest)"),
+            2 => 2,
+            3 => 3,
+            4 => 4,
+            5 => '5 ' . _("(lowest)")
+        );
+        $this->addHidden('', 'actionID', 'text', true);
+        $this->addHidden('', 'task_id', 'text', false);
+        $this->addHidden('', 'old_tasklist', 'text', false);
+        $this->addHidden('', 'url', 'text', false);
+        $this->addVariable(_("Name"), 'name', 'text', true);
+        if (!$GLOBALS['prefs']->isLocked('default_tasklist') &&
+            count($tasklist_enums) > 1) {
+            $v = $this->addVariable(
+                _("Task List"), 'tasklist_id', 'enum', true, false, false,
+                array($tasklist_enums));
+            $v->setAction(Horde_Form_Action::factory('reload'));
+        }
+        $v = $this->addVariable(
+            _("Parent task"), 'parent', 'enum', false, false, false, array($task_enums));
+        $v->setOption('htmlchars', true);
+
+        if (class_exists('Horde_Form_Type_category')) {
+            $this->addVariable(_("Category"), 'category', 'category', false);
+        } else {
+            $values = Horde_Array::valuesToKeys(Horde_Prefs_CategoryManager::get());
+            $this->addVariable(
+                _("Category"), 'category', 'enum', false, false, false,
+                array($values, _("Unfiled")));
+        }
+
+        $this->addVariable(_("Assignee"), 'assignee', 'enum', false, false,
+                           null, array($users, _("None")));
+        $this->addVariable(_("Private?"), 'private', 'boolean', false);
+        $this->addVariable(_("Due By"), 'due', 'Nag:NagDue', false);
+        $this->addVariable(_("Delay Start Until"), 'start', 'Nag:NagStart', false);
+        $this->addVariable(_("Alarm"), 'alarm', 'Nag:NagAlarm', false);
+
+        $v = $this->addVariable(_("Notification"), 'methods', 'Nag:NagMethod', false);
+        $v->setAction(Horde_Form_Action::factory('reload'));
+
+        $v = $this->addVariable(_("Priority"), 'priority', 'enum', false, false, false, array($priorities));
+        $v->setDefault(3);
+
+        $this->addVariable(_("Estimated Time"), 'estimate', 'number', false);
+        $this->addVariable(_("Completed?"), 'completed', 'boolean', false);
+
+        try {
+            $description = Horde::callHook('description_help', array(), 'nag');
+        } catch (Horde_Exception_HookNotSet $e) {
+            $description = '';
+        }
+        $this->addVariable(_("Description"), 'desc', 'longtext', false, false, $description);
+
+        $buttons = array(_("Save"));
+        if ($delete) {
+            $buttons[] = _("Delete this task");
+        }
+        $this->setButtons($buttons);
+    }
+
+    public function renderActive()
+    {
+        return parent::renderActive(new Nag_Form_Renderer_Task(array('varrenderer_driver' => array('nag', 'nag')), $this->delete), $this->_vars, 'task.php', 'post');
+    }
+
+}
diff --git a/nag/lib/Forms/CreateTaskList.php b/nag/lib/Forms/CreateTaskList.php
deleted file mode 100644 (file)
index ccdeb98..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-/**
- * Horde_Form for creating task lists.
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @package Nag
- */
-
-/** Horde_Form */
-require_once 'Horde/Form.php';
-
-/** Horde_Form_Renderer */
-require_once 'Horde/Form/Renderer.php';
-
-/**
- * The Nag_CreateTaskListForm class provides the form for
- * creating a task list.
- *
- * @author  Chuck Hagenbuch <chuck@horde.org>
- * @package Nag
- */
-class Nag_CreateTaskListForm extends Horde_Form {
-
-    function Nag_CreateTaskListForm(&$vars)
-    {
-        parent::Horde_Form($vars, _("Create Task List"));
-
-        $this->addVariable(_("Name"), 'name', 'text', true);
-        $this->addVariable(_("Color"), 'color', 'colorpicker', false);
-        $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
-        if ($GLOBALS['registry']->isAdmin()) {
-            $this->addVariable(_("System Task List"), 'system', 'boolean', false, false, _("System task lists don't have an owner. Only administrators can change the task list settings and permissions."));
-        }
-
-        $this->setButtons(array(_("Create")));
-    }
-
-    function execute()
-    {
-        $info = array();
-        foreach (array('name', 'color', 'description', 'system') as $key) {
-            $info[$key] = $this->_vars->get($key);
-        }
-        return Nag::addTasklist($info);
-    }
-
-}
diff --git a/nag/lib/Forms/DeleteTaskList.php b/nag/lib/Forms/DeleteTaskList.php
deleted file mode 100644 (file)
index ee08674..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-<?php
-/**
- * Horde_Form for deleting task lists.
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @package Nag
- */
-
-/** Horde_Form */
-require_once 'Horde/Form.php';
-
-/** Horde_Form_Renderer */
-require_once 'Horde/Form/Renderer.php';
-
-/**
- * The Nag_DeleteTaskListForm class provides the form for
- * deleting a task list.
- *
- * @author  Chuck Hagenbuch <chuck@horde.org>
- * @package Nag
- */
-class Nag_DeleteTaskListForm extends Horde_Form {
-
-    /**
-     * Task list being deleted
-     */
-    var $_tasklist;
-
-    function Nag_DeleteTaskListForm(&$vars, &$tasklist)
-    {
-        $this->_tasklist = &$tasklist;
-        parent::Horde_Form($vars, sprintf(_("Delete %s"), $tasklist->get('name')));
-
-        $this->addHidden('', 't', 'text', true);
-        $this->addVariable(sprintf(_("Really delete the task list \"%s\"? This cannot be undone and all data on this task list will be permanently removed."), $this->_tasklist->get('name')), 'desc', 'description', false);
-
-        $this->setButtons(array(_("Delete"), _("Cancel")));
-    }
-
-    function execute()
-    {
-        // If cancel was clicked, return false.
-        if ($this->_vars->get('submitbutton') == _("Cancel")) {
-            return false;
-        }
-
-        return Nag::deleteTasklist($this->_tasklist);
-    }
-
-}
diff --git a/nag/lib/Forms/EditTaskList.php b/nag/lib/Forms/EditTaskList.php
deleted file mode 100644 (file)
index c7499da..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-/**
- * Horde_Form for editing task lists.
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @package Nag
- */
-
-/** Horde_Form */
-require_once 'Horde/Form.php';
-
-/** Horde_Form_Renderer */
-require_once 'Horde/Form/Renderer.php';
-
-/**
- * The Nag_EditTaskListForm class provides the form for
- * editing a task list.
- *
- * @author  Chuck Hagenbuch <chuck@horde.org>
- * @package Nag
- */
-class Nag_EditTaskListForm extends Horde_Form {
-
-    /**
-     * Task list being edited
-     */
-    var $_tasklist;
-
-    function Nag_EditTaskListForm(&$vars, &$tasklist)
-    {
-        $this->_tasklist = &$tasklist;
-        parent::Horde_Form($vars, sprintf(_("Edit %s"), $tasklist->get('name')));
-
-        $this->addHidden('', 't', 'text', true);
-        $this->addVariable(_("Task List Name"), 'name', 'text', true);
-        $this->addVariable(_("Task List Description"), 'description', 'longtext', false, false, null, array(4, 60));
-        if ($GLOBALS['registry']->isAdmin()) {
-            $this->addVariable(_("System Task List"), 'system', 'boolean', false, false, _("System task lists don't have an owner. Only administrators can change the task list settings and permissions."));
-        }
-
-        $this->setButtons(array(_("Save")));
-    }
-
-    function execute()
-    {
-        $info = array();
-        foreach (array('name', 'color', 'description', 'system') as $key) {
-            $info[$key] = $this->_vars->get($key);
-        }
-        return Nag::updateTasklist($this->_tasklist, $info);
-    }
-
-}
diff --git a/nag/lib/Forms/task.php b/nag/lib/Forms/task.php
deleted file mode 100644 (file)
index fa10a7c..0000000
+++ /dev/null
@@ -1,315 +0,0 @@
-<?php
-/**
- * This file contains all Horde_Form extensions required for editing tasks.
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @package Nag
- */
-
-/**
- * The Nag_TaskForm class provides the form for adding and editing a task.
- *
- * @author  Jan Schneider <jan@horde.org>
- * @package Nag
- */
-class Nag_TaskForm extends Horde_Form {
-
-    var $delete;
-
-    function Nag_TaskForm(&$vars, $title = '', $delete = false)
-    {
-        parent::Horde_Form($vars, $title);
-        $this->delete = $delete;
-
-        $tasklists = Nag::listTasklists(false, Horde_Perms::EDIT);
-        $tasklist_enums = array();
-        foreach ($tasklists as $tl_id => $tl) {
-            if ($tl->get('owner') != $GLOBALS['registry']->getAuth() &&
-                !empty($GLOBALS['conf']['share']['hidden']) &&
-                !in_array($tl->getName(), $GLOBALS['display_tasklists'])) {
-                continue;
-            }
-            $tasklist_enums[$tl_id] = $tl->get('name');
-        }
-
-        $tasklist = $vars->get('tasklist_id');
-        if (empty($tasklist)) {
-            reset($tasklist_enums);
-            $tasklist = key($tasklist_enums);
-        }
-        $tasks = Nag::listTasks(null, null, null, array($tasklist), Nag::VIEW_FUTURE_INCOMPLETE);
-        $task_enums = array('' => _("No parent task"));
-        $tasks->reset();
-        while ($task = $tasks->each()) {
-            if ($vars->get('task_id') == $task->id) {
-                continue;
-            }
-            $task_enums[htmlspecialchars($task->id)] = str_repeat('&nbsp;', $task->indent * 4) . htmlentities($task->name);
-        }
-        $users = array();
-        $share = $GLOBALS['nag_shares']->getShare($tasklist);
-        $users = $share->listUsers(Horde_Perms::READ);
-        $groups = $share->listGroups(Horde_Perms::READ);
-        if (count($groups)) {
-            $horde_group = $GLOBALS['injector']->getInstance('Horde_Group');
-            foreach ($groups as $group) {
-                $users = array_merge($users,
-                                     $horde_group->listAllUsers($group));
-            }
-        }
-        $users = array_flip($users);
-
-        if (count($users)) {
-            foreach (array_keys($users) as $user) {
-                $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($user);
-                $fullname = $identity->getValue('fullname');
-                $users[$user] = strlen($fullname) ? $fullname : $user;
-            }
-        }
-        $priorities = array(1 => '1 ' . _("(highest)"), 2 => 2, 3 => 3,
-                            4 => 4, 5 => '5 ' . _("(lowest)"));
-
-        $this->addHidden('', 'actionID', 'text', true);
-        $this->addHidden('', 'task_id', 'text', false);
-        $this->addHidden('', 'old_tasklist', 'text', false);
-        $this->addHidden('', 'url', 'text', false);
-
-        $this->addVariable(_("Name"), 'name', 'text', true);
-        if (!$GLOBALS['prefs']->isLocked('default_tasklist') &&
-            count($tasklist_enums) > 1) {
-            $v = &$this->addVariable(_("Task List"), 'tasklist_id', 'enum', true, false, false, array($tasklist_enums));
-            $v->setAction(Horde_Form_Action::factory('reload'));
-        }
-
-        $v = &$this->addVariable(_("Parent task"), 'parent', 'enum', false, false, false, array($task_enums));
-        $v->setOption('htmlchars', true);
-
-        if (class_exists('Horde_Form_Type_category')) {
-            $this->addVariable(_("Category"), 'category', 'category', false);
-        } else {
-            $values = Horde_Array::valuesToKeys(Horde_Prefs_CategoryManager::get());
-            $this->addVariable(_("Category"), 'category', 'enum', false, false, false, array($values, _("Unfiled")));
-        }
-
-        $this->addVariable(_("Assignee"), 'assignee', 'enum', false, false,
-                           null, array($users, _("None")));
-        $this->addVariable(_("Private?"), 'private', 'boolean', false);
-        $this->addVariable(_("Due By"), 'due', 'nag_due', false);
-        $this->addVariable(_("Delay Start Until"), 'start', 'nag_start', false);
-        $this->addVariable(_("Alarm"), 'alarm', 'nag_alarm', false);
-        $v = &$this->addVariable(_("Notification"), 'methods', 'nag_method', false);
-        $v->setAction(Horde_Form_Action::factory('reload'));
-
-        $v = &$this->addVariable(_("Priority"), 'priority', 'enum', false, false, false, array($priorities));
-        $v->setDefault(3);
-
-        $this->addVariable(_("Estimated Time"), 'estimate', 'number', false);
-        $this->addVariable(_("Completed?"), 'completed', 'boolean', false);
-
-        try {
-            $description = Horde::callHook('description_help', array(), 'nag');
-        } catch (Horde_Exception_HookNotSet $e) {
-            $description = '';
-        }
-        $this->addVariable(_("Description"), 'desc', 'longtext', false, false, $description);
-
-        $buttons = array(_("Save"));
-        if ($delete) {
-            $buttons[] = _("Delete this task");
-        }
-        $this->setButtons($buttons);
-    }
-
-    function renderActive()
-    {
-        return parent::renderActive(new Nag_TaskForm_Renderer(array('varrenderer_driver' => array('nag', 'nag')), $this->delete), $this->_vars, 'task.php', 'post');
-    }
-
-}
-
-class Nag_TaskForm_Renderer extends Horde_Form_Renderer {
-
-    var $delete;
-
-    function Nag_TaskForm_Renderer($params = array(), $delete = false)
-    {
-        parent::Horde_Form_Renderer($params);
-        $this->delete = $delete;
-    }
-
-    function _renderSubmit($submit, $reset)
-    {
-?><div class="control" style="padding:1em;">
-    <input class="button leftFloat" name="submitbutton" type="submit" value="<?php echo _("Save") ?>" />
-<?php if ($this->delete): ?>
-    <input class="button rightFloat" name="submitbutton" type="submit" value="<?php echo _("Delete this task") ?>" />
-<?php endif; ?>
-    <div class="clear"></div>
-</div>
-<?php
-    }
-
-}
-/**
- * The Horde_Form_Type_nag_method class provides a form field for editing
- * notification methods for a task alarm.
- *
- * @author  Alfonso Marin <almarin@um.es>
- * @package Nag
- */
-class Horde_Form_Type_nag_method extends Horde_Form_Type {
-
-    function getInfo(&$vars, &$var, &$info)
-    {
-        $info = $var->getValue($vars);
-        if (empty($info['on'])) {
-            $info = array();
-            return;
-        }
-
-        $types = $vars->get('task_alarms');
-        $info = array();
-        if (!empty($types)) {
-            foreach ($types as $type) {
-                $info[$type] = array();
-                switch ($type){
-                    case 'notify':
-                        $info[$type]['sound'] = $vars->get('task_alarms_sound');
-                        break;
-                    case 'mail':
-                        $info[$type]['email'] = $vars->get('task_alarms_email');
-                        break;
-                    case 'popup':
-                        break;
-                }
-            }
-        }
-    }
-
-    function isValid(&$var, &$vars, $value, &$message)
-    {
-        $alarm = $vars->get('alarm');
-        if ($value['on'] && !$alarm['on']){
-            $message = _("An alarm must be set to specify a notification method");
-            return false;
-        }
-        return true;
-    }
-
-}
-
-/**
- * The Horde_Form_Type_nag_alarm class provides a form field for editing task
- * alarms.
- *
- * @author  Jan Schneider <jan@horde.org>
- * @package Nag
- */
-class Horde_Form_Type_nag_alarm extends Horde_Form_Type {
-
-    function getInfo(&$vars, &$var, &$info)
-    {
-        $info = $var->getValue($vars);
-        if (!$info['on']) {
-            $info = 0;
-        } else {
-            $value = $info['value'];
-            $unit = $info['unit'];
-            if ($value == 0) {
-                $value = $unit = 1;
-            }
-            $info = $value * $unit;
-        }
-    }
-
-    function isValid(&$var, &$vars, $value, &$message)
-    {
-        if ($value['on']) {
-            if ($vars->get('due_type') == 'none') {
-                $message = _("A due date must be set to enable alarms.");
-                return false;
-            }
-        }
-
-        return true;
-    }
-
-}
-
-/**
- * The Horde_Form_Type_nag_due class provides a form field for editing
- * task due dates.
- *
- * @author  Chuck Hagenbuch <chuck@horde.org>
- * @package Nag
- */
-class Horde_Form_Type_nag_due extends Horde_Form_Type {
-
-    function getInfo(&$vars, &$var, &$info)
-    {
-        $due_type = $vars->get('due_type');
-        $due = $vars->get('due');
-        if (is_array($due)) {
-            $due_day = !empty($due['day']) ? $due['day'] : null;
-            $due_month = !empty($due['month']) ? $due['month'] : null;
-            $due_year = !empty($due['year']) ? $due['year'] : null;
-            $due_hour = Horde_Util::getFormData('due_hour');
-            $due_minute = Horde_Util::getFormData('due_minute');
-            if (!$GLOBALS['prefs']->getValue('twentyFour')) {
-                $due_am_pm = Horde_Util::getFormData('due_am_pm');
-                if ($due_am_pm == 'pm') {
-                    if ($due_hour < 12) {
-                        $due_hour = $due_hour + 12;
-                    }
-                } else {
-                    // Adjust 12:xx AM times.
-                    if ($due_hour == 12) {
-                        $due_hour = 0;
-                    }
-                }
-            }
-
-            $due = (int)strtotime("$due_month/$due_day/$due_year $due_hour:$due_minute");
-        }
-
-        $info = strcasecmp($due_type, 'none') ? $due : 0;
-    }
-
-    function isValid(&$var, &$vars, $value, &$message)
-    {
-        return true;
-    }
-
-}
-
-/**
- * The Horde_Form_Type_nag_start class provides a form field for editing
- * task delayed start dates.
- *
- * @author  Chuck Hagenbuch <chuck@horde.org>
- * @package Nag
- */
-class Horde_Form_Type_nag_start extends Horde_Form_Type {
-
-    function getInfo(&$vars, &$var, &$info)
-    {
-        $start_type = $vars->get('start_date');
-        $start = $vars->get('start');
-        if (is_array($start)) {
-            $start_day = !empty($start['day']) ? $start['day'] : null;
-            $start_month = !empty($start['month']) ? $start['month'] : null;
-            $start_year = !empty($start['year']) ? $start['year'] : null;
-            $start = (int)strtotime("$start_month/$start_day/$start_year");
-        }
-
-        $info = strcasecmp($start_type, 'none') ? $start : 0;
-    }
-
-    function isValid(&$var, &$vars, $value, &$message)
-    {
-        return true;
-    }
-
-}
index 37076d0..d9675c0 100644 (file)
@@ -92,6 +92,12 @@ class Nag
      */
     const VIEW_FUTURE_INCOMPLETE = 4;
 
+    /**
+     *
+     * @param integer $seconds
+     *
+     * @return string
+     */
     public static function secondsToString($seconds)
     {
         $hours = floor($seconds / 3600);
@@ -146,7 +152,7 @@ class Nag
     public static function listTasks($sortby = null,
                                      $sortdir = null,
                                      $altsortby = null,
-                                     $tasklists = null,
+                                     array $tasklists = null,
                                      $completed = null)
     {
         global $prefs, $registry;
@@ -178,9 +184,6 @@ class Nag
 
             /* Retrieve the tasklist from storage. */
             $result = $storage->retrieve($completed);
-            if (is_a($result, 'PEAR_Error')) {
-                return $result;
-            }
             $tasks->mergeChildren($storage->tasks->children);
         }
 
@@ -193,20 +196,21 @@ class Nag
             foreach ($apps as $app) {
                 if ($app != 'nag' &&
                     $registry->hasMethod('getListTypes', $app)) {
-                    $types = $registry->callByPackage($app, 'getListTypes');
-                    if (is_a($types, 'PEAR_Error')) {
+                    try {
+                        $types = $registry->callByPackage($app, 'getListTypes');
+                    } catch (Horde_Exception $e) {
                         continue;
                     }
                     if (!empty($types['taskHash'])) {
-                        $newtasks = $registry->callByPackage($app, 'listAs', array('taskHash'));
-                        if (is_a($newtasks, 'PEAR_Error')) {
-                            Horde::logMessage($newtasks, 'ERR');
-                        } else {
-                            foreach ($newtasks as $task) {
+                        try {
+                            $newtasks = $registry->callByPackage($app, 'listAs', array('taskHash'));
+                             foreach ($newtasks as $task) {
                                 $task['tasklist_id'] = '**EXTERNAL**';
                                 $task['tasklist_name'] = $registry->get('name', $app);
                                 $tasks->add(new Nag_Task($task));
                             }
+                        } catch (Horde_Exception $e) {
+                            Horde::logMessage($newtasks, 'ERR');
                         }
                     }
                 }
@@ -231,9 +235,6 @@ class Nag
     {
         $storage = Nag_Driver::singleton($tasklist);
         $task = $storage->get($task);
-        if (is_a($task, 'PEAR_Error')) {
-            return $task;
-        }
         $task->process();
         return $task;
     }
@@ -250,7 +251,7 @@ class Nag
             return $count;
         }
 
-        $tasklists = Nag::listTasklists(true, Horde_Perms::ALL);
+        $tasklists = self::listTasklists(true, Horde_Perms::ALL);
 
         $count = 0;
         foreach (array_keys($tasklists) as $tasklist) {
@@ -278,9 +279,9 @@ class Nag
     public static function createTasksFromText($text, $tasklist = null)
     {
         if ($tasklist === null) {
-            $tasklist = Nag::getDefaultTasklist(Horde_Perms::EDIT);
+            $tasklist = self::getDefaultTasklist(Horde_Perms::EDIT);
         }
-        if (!array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::EDIT))) {
+        if (!array_key_exists($tasklist, self::listTasklists(false, Horde_Perms::EDIT))) {
             return PEAR::raiseError(_("Permission Denied"));
         }
 
@@ -311,9 +312,6 @@ class Nag
             } else {
                 $newTask = $storage->add($name, '', 0, $due, 3);
             }
-            if (is_a($newTask, 'PEAR_Error')) {
-                return $newTask;
-            }
             $uids[] = $newTask[1];
             $task['id'] = $newTask[0];
         }
@@ -324,11 +322,12 @@ class Nag
     /**
      * Returns all the alarms active right on $date.
      *
-     * @param integer $date  The unix epoch time to check for alarms.
+     * @param integer $date     The unix epoch time to check for alarms.
+     * @param array $tasklists  An array of tasklists
      *
      * @return array  The alarms (taskId) active on $date.
      */
-    public static function listAlarms($date, $tasklists = null)
+    public static function listAlarms($date, array $tasklists = null)
     {
         if (is_null($tasklists)) {
             $tasklists = $GLOBALS['display_tasklists'];
@@ -341,9 +340,6 @@ class Nag
 
             /* Retrieve the alarms for the task list. */
             $newtasks = $storage->listAlarms($date);
-            if (is_a($newtasks, 'PEAR_Error')) {
-                return $newtasks;
-            }
 
             /* Don't show an alarm for complete tasks. */
             foreach ($newtasks as $taskID => $task) {
@@ -391,13 +387,12 @@ class Nag
      * Filters data based on permissions.
      *
      * @param array $in            The data we want filtered.
-     * @param string $filter       What type of data we are filtering.
      * @param integer $permission  The Horde_Perms::* constant we will filter
      *                             on.
      *
      * @return array  The filtered data.
      */
-    public static function permissionsFilter($in, $permission = Horde_Perms::READ)
+    public static function permissionsFilter(array $in, $permission = Horde_Perms::READ)
     {
         // FIXME: Must find a way to check individual tasklists for
         // permission.  Can't specify attributes as it does not check for the
@@ -419,13 +414,17 @@ class Nag
     /**
      * Returns the default tasklist for the current user at the specified
      * permissions level.
+     *
+     * @param integer $permission  The permission to require.
+     *
+     * @return mixed The default tasklist or false if none.
      */
     public static function getDefaultTasklist($permission = Horde_Perms::SHOW)
     {
         global $prefs;
 
         $default_tasklist = $prefs->getValue('default_tasklist');
-        $tasklists = Nag::listTasklists(false, $permission);
+        $tasklists = self::listTasklists(false, $permission);
 
         if (isset($tasklists[$default_tasklist])) {
             return $default_tasklist;
@@ -446,7 +445,7 @@ class Nag
      *
      * @return Horde_Share  The new share.
      */
-    public static function addTasklist($info)
+    public static function addTasklist(array $info)
     {
         try {
             $tasklist = $GLOBALS['nag_shares']->newShare($GLOBALS['registry']->getAuth(), strval(new Horde_Support_Randomid()));
@@ -471,13 +470,13 @@ class Nag
     /**
      * Updates an existing share.
      *
-     * @param Horde_Share $share  The share to update.
-     * @param array $info         Hash with task list information.
+     * @param Horde_Share_Object $tasklist  The share to update.
+     * @param array $info                   Hash with task list information.
      *
      * @throws Horde_Exception_PermissionDenied
      * @throws Nag_Exception
      */
-    public static function updateTasklist($tasklist, $info)
+    public static function updateTasklist(Horde_Share_Object $tasklist, array $info)
     {
         if (!$GLOBALS['registry']->getAuth() ||
             ($tasklist->get('owner') != $GLOBALS['registry']->getAuth() &&
@@ -501,9 +500,11 @@ class Nag
     /**
      * Deletes a task list.
      *
-     * @param Horde_Share $tasklist  The task list to delete.
+     * @param Horde_Share_Object $tasklist  The task list to delete.
+     * @throws Nag_Exception
+     * @throws Horde_Exception_PermissionDenied
      */
-    public static function deleteTasklist($tasklist)
+    public static function deleteTasklist(Horde_Share_Object $tasklist)
     {
         if (!$GLOBALS['registry']->getAuth() ||
             ($tasklist->get('owner') != $GLOBALS['registry']->getAuth() &&
@@ -514,9 +515,6 @@ class Nag
         // Delete the task list.
         $storage = &Nag_Driver::singleton($tasklist->getName());
         $result = $storage->deleteAll();
-        if ($result instanceof PEAR_Error) {
-            throw new Nag_Exception(sprintf(_("Unable to delete \"%s\": %s"), $tasklist->get('name'), $result->getMessage()));
-        }
 
         // Remove share and all groups/permissions.
         try {
@@ -593,7 +591,7 @@ class Nag
     /**
      * Returns the string representation of the given completion status.
      *
-     * @param int $completed  The completion value.
+     * @param integer $completed  The completion value.
      *
      * @return string  The HTML representation of $completed.
      */
@@ -607,7 +605,7 @@ class Nag
     /**
      * Returns a colored representation of a priority.
      *
-     * @param int $priority  The priority level.
+     * @param integer $priority  The priority level.
      *
      * @return string  The HTML representation of $priority.
      */
@@ -620,7 +618,7 @@ class Nag
     /**
      * Returns the string matching the given alarm value.
      *
-     * @param int $value  The alarm value in minutes.
+     * @param integer $value  The alarm value in minutes.
      *
      * @return string  The formatted alarm string.
      */
@@ -711,7 +709,7 @@ class Nag
 
         // Make sure all task lists exist now, to save on checking later.
         $_temp = $GLOBALS['display_tasklists'];
-        $GLOBALS['all_tasklists'] = Nag::listTasklists();
+        $GLOBALS['all_tasklists'] = self::listTasklists();
         $GLOBALS['display_tasklists'] = array();
         foreach ($_temp as $id) {
             if (isset($GLOBALS['all_tasklists'][$id])) {
@@ -728,7 +726,7 @@ class Nag
         /* If the user doesn't own a task list, create one. */
         if (!empty($GLOBALS['conf']['share']['auto_create']) &&
             $GLOBALS['registry']->getAuth() &&
-            !count(Nag::listTasklists(true))) {
+            !count(self::listTasklists(true))) {
             $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create();
             $share = $GLOBALS['nag_shares']->newShare($GLOBALS['registry']->getAuth(), strval(new Horde_Support_Randomid()));
             $share->set('name', sprintf(_("Task list of %s"), $identity->getName()));
@@ -756,11 +754,8 @@ class Nag
         if (empty($GLOBALS['conf']['alarms']['driver'])) {
             // Get any alarms in the next hour.
             $now = time();
-            $alarmList = Nag::listAlarms($now);
-            if (is_a($alarmList, 'PEAR_Error')) {
-                Horde::logMessage($alarmList, 'ERR');
-                $notification->push($alarmList, 'horde.error');
-            } else {
+            try {
+                $alarmList = self::listAlarms($now);
                 $messages = array();
                 foreach ($alarmList as $task) {
                     $differential = $task->due - $now;
@@ -772,7 +767,7 @@ class Nag
                         $messages[$key] = array(sprintf(_("%s is due now."), $task->name), 'horde.alarm');
                     } elseif ($differential >= 60) {
                         $messages[$key] = array(sprintf(_("%s is due in %s"), $task->name,
-                                                        Nag::secondsToString($differential)), 'horde.alarm');
+                                                        self::secondsToString($differential)), 'horde.alarm');
                     }
                 }
 
@@ -780,12 +775,15 @@ class Nag
                 foreach ($messages as $message) {
                     $notification->push($message[0], $message[1]);
                 }
+            } catch (Nag_Exception $e) {
+                Horde::logMessage($e, 'ERR');
+                $notification->push($e->getMessage(), 'horde.error');
             }
         }
 
         // Check here for guest task lists so that we don't get multiple
         // messages after redirects, etc.
-        if (!$GLOBALS['registry']->getAuth() && !count(Nag::listTasklists())) {
+        if (!$GLOBALS['registry']->getAuth() && !count(self::listTasklists())) {
             $notification->push(_("No task lists are available to guests."));
         }
 
@@ -801,11 +799,13 @@ class Nag
      *                            "delete".
      * @param Nag_Task $task      The changed task.
      * @param Nag_Task $old_task  The original task if $action is "edit".
+     *
+     * @throws Nag_Exception
      */
     public static function sendNotification($action, $task, $old_task = null)
     {
         if (!in_array($action, array('add', 'edit', 'delete'))) {
-            return PEAR::raiseError('Unknown event action: ' . $action);
+            throw new Nag_Exception('Unknown event action: ' . $action);
         }
 
         try {
@@ -822,12 +822,12 @@ class Nag
 
         $owner = $share->get('owner');
         if (strlen($owner)) {
-            $recipients[$owner] = Nag::_notificationPref($owner, 'owner');
+            $recipients[$owner] = self::_notificationPref($owner, 'owner');
         }
 
         foreach ($share->listUsers(Horde_Perms::READ) as $user) {
             if (empty($recipients[$user])) {
-                $recipients[$user] = Nag::_notificationPref($user, 'read', $task->tasklist);
+                $recipients[$user] = self::_notificationPref($user, 'read', $task->tasklist);
             }
         }
         foreach ($share->listGroups(Horde_Perms::READ) as $group) {
@@ -841,7 +841,7 @@ class Nag
 
             foreach ($group_users as $user) {
                 if (empty($recipients[$user])) {
-                    $recipients[$user] = Nag::_notificationPref($user, 'read', $task->tasklist);
+                    $recipients[$user] = self::_notificationPref($user, 'read', $task->tasklist);
                 }
             }
         }
@@ -915,14 +915,14 @@ class Nag
                 }
                 if ($old_task->parent_id != $task->parent_id) {
                     $old_parent = $old_task->getParent();
-                    $parent = $task->getParent();
-                    if (!is_a($parent, 'PEAR_Error')) {
+                    try {
+                        $parent = $task->getParent();
                         $notification_message .= "\n - "
                             . sprintf(_("Changed parent task from \"%s\" to \"%s\""),
                                       $old_parent ? $old_parent->name : _("no parent"),
                                       $parent ? $parent->name : _("no parent"));
+                    } catch (Tag_Exception $e) {
                     }
-
                 }
                 if ($old_task->category != $task->category) {
                     $notification_message .= "\n - "
@@ -951,19 +951,19 @@ class Nag
                 if ($old_task->due != $task->due) {
                     $notification_message .= "\n - "
                         . sprintf(_("Changed due date from %s to %s"),
-                                  $old_task->due ? Nag::formatDate($old_task->due) : _("no due date"),
-                                  $task->due ? Nag::formatDate($task->due) : _("no due date"));
+                                  $old_task->due ? self::formatDate($old_task->due) : _("no due date"),
+                                  $task->due ? self::formatDate($task->due) : _("no due date"));
                 }
                 if ($old_task->start != $task->start) {
                     $notification_message .= "\n - "
                         . sprintf(_("Changed start date from %s to %s"),
-                                  $old_task->start ? Nag::formatDate($old_task->start) : _("no start date"),
-                                  $task->start ? Nag::formatDate($task->start) : _("no start date"));
+                                  $old_task->start ? self::formatDate($old_task->start) : _("no start date"),
+                                  $task->start ? self::formatDate($task->start) : _("no start date"));
                 }
                 if ($old_task->alarm != $task->alarm) {
                     $notification_message .= "\n - "
                         . sprintf(_("Changed alarm from %s to %s"),
-                                  Nag::formatAlarm($old_task->alarm), Nag::formatAlarm($task->alarm));
+                                  self::formatAlarm($old_task->alarm), self::formatAlarm($task->alarm));
                 }
                 if ($old_task->priority != $task->priority) {
                     $notification_message .= "\n - "
@@ -1074,6 +1074,10 @@ class Nag
 
     /**
      * Returns the real name, if available, of a user.
+     *
+     * @param string $uid  The userid of the user to retrieve
+     *
+     * @return string  The fullname of the user.
      */
     public static function getUserName($uid)
     {
index ace88e2..7619fe1 100644 (file)
  * @author  Jan Schneider <jan@horde.org>
  * @package Nag
  */
-class Nag_Task {
-
+class Nag_Task
+{
     /**
      * The task id.
      *
      * @var string
      */
-    var $id;
+    public $id;
 
     /**
      * This task's tasklist id.
      *
      * @var string
      */
-    var $tasklist;
+    public $tasklist;
 
     /**
      * The task uid.
      *
      * @var string
      */
-    var $uid;
+    public $uid;
 
     /**
      * The task owner.
      *
      * @var string
      */
-    var $owner;
+    public $owner;
 
     /**
      * The task assignee.
      *
      * @var string
      */
-    var $assignee;
+    public $assignee;
 
     /**
      * The task title.
      *
      * @var string
      */
-    var $name;
+    public $name;
 
     /**
      * The task decription.
      *
      * @var string
      */
-    var $desc;
+    public $desc;
 
     /**
      * The start date timestamp.
      *
      * @var integer
      */
-    var $start;
+    public $start;
 
     /**
      * The due date timestamp.
      *
      * @var integer
      */
-    var $due;
+    public $due;
 
     /**
      * The task priority.
      *
      * @var integer
      */
-    var $priority;
+    public $priority;
 
     /**
      * The estimated task length.
      *
      * @var float
      */
-    var $estimate;
+    public $estimate;
 
     /**
      * Whether the task is completed.
      *
      * @var boolean
      */
-    var $completed;
+    public $completed;
 
     /**
      * The completion date timestamp.
      *
      * @var integer
      */
-    var $completed_date;
+    public $completed_date;
 
     /**
      * The task category
      *
      * @var string
      */
-    var $category;
+    public $category;
 
     /**
      * The task alarm threshold.
      *
      * @var integer
      */
-    var $alarm;
+    public $alarm;
 
     /**
      * The particular alarm methods overridden for this task.
      *
      * @var array
      */
-    var $methods;
+    public $methods;
 
     /**
      * Whether the task is private.
      *
      * @var boolean
      */
-    var $private;
+    public $private;
 
     /**
      * URL to view the task.
      *
      * @var string
      */
-    var $view_link;
+    public $view_link;
 
     /**
      * URL to complete the task.
      *
      * @var string
      */
-    var $complete_link;
+    public $complete_link;
 
     /**
      * URL to edit the task.
      *
      * @var string
      */
-    var $edit_link;
+    public $edit_link;
 
     /**
      * URL to delete the task.
      *
      * @var string
      */
-    var $delete_link;
+    public $delete_link;
 
     /**
      * The parent task's id.
      *
      * @var string
      */
-    var $parent_id = '';
+    public $parent_id = '';
 
     /**
      * The parent task.
      *
      * @var Nag_Task
      */
-    var $parent;
+    public $parent;
 
     /**
      * The sub-tasks.
      *
      * @var array
      */
-    var $children = array();
+    public $children = array();
 
     /**
      * This task's idention (child) level.
      *
      * @var integer
      */
-    var $indent = 0;
+    public $indent = 0;
 
     /**
      * Whether this is the last sub-task.
      *
      * @var boolean
      */
-    var $lastChild;
+    public $lastChild;
 
     /**
      * Internal flag.
@@ -199,7 +199,7 @@ class Nag_Task {
      * @var boolean
      * @see each()
      */
-    var $_inlist = false;
+    protected $_inlist = false;
 
     /**
      * Internal pointer.
@@ -207,14 +207,14 @@ class Nag_Task {
      * @var integer
      * @see each()
      */
-    var $_pointer;
+    protected $_pointer;
 
     /**
      * Task id => pointer dictionary.
      *
      * @var array
      */
-    var $_dict = array();
+    protected $_dict = array();
 
     /**
      * Constructor.
@@ -223,7 +223,7 @@ class Nag_Task {
      *
      * @param array $task  A task hash.
      */
-    function Nag_Task($task = null)
+    public function __construct(array $task = null)
     {
         if ($task) {
             $this->merge($task);
@@ -235,7 +235,7 @@ class Nag_Task {
      *
      * @param array $task  A task hash.
      */
-    function merge($task)
+    public function merge(array $task)
     {
         foreach ($task as $key => $val) {
             if ($key == 'tasklist_id') {
@@ -252,7 +252,7 @@ class Nag_Task {
     /**
      * Saves this task in the storage backend.
      */
-    function save()
+    public function save()
     {
         $storage = Nag_Driver::singleton($this->tasklist);
         return $storage->modify($this->id,
@@ -276,10 +276,9 @@ class Nag_Task {
     /**
      * Returns the parent task of this task, if one exists.
      *
-     * @return Nag_Task  The parent task, null if none exists, PEAR_Error on
-     *                   failure.
+     * @return mixed  The parent task, null if none exists
      */
-    function getParent()
+    public function getParent()
     {
         if (!$this->parent_id) {
             return null;
@@ -292,7 +291,7 @@ class Nag_Task {
      *
      * @param Nag_Task $task  A sub task.
      */
-    function add($task)
+    public function add(Nag_Task $task)
     {
         $this->_dict[$task->id] = count($this->children);
         $task->parent = $this;
@@ -302,13 +301,12 @@ class Nag_Task {
     /**
      * Loads all sub-tasks.
      */
-    function loadChildren()
+    public function loadChildren()
     {
         $storage = Nag_Driver::singleton($this->tasklist);
-        $children = $storage->getChildren($this->id);
-        if (!is_a($children, 'PEAR_Error')) {
-            $this->children = $children;
-        }
+        try {
+            $this->children = $storage->getChildren($this->id);
+        } catch (Nag_Exception $e) {}
     }
 
     /**
@@ -317,7 +315,7 @@ class Nag_Task {
      * @param array $children  A list of Nag_Tasks.
      *
      */
-    function mergeChildren($children)
+    public function mergeChildren(array $children)
     {
         for ($i = 0, $c = count($children); $i < $c; ++$i) {
             $this->add($children[$i]);
@@ -334,14 +332,11 @@ class Nag_Task {
      *
      * @return Nag_Task  The searched task or null.
      */
-    function get($key)
+    public function get($key)
     {
-        if (isset($this->_dict[$key])) {
-            $task = $this->children[$this->_dict[$key]];
-        } else {
-            $task = null;
-        }
-        return $task;
+        return isset($this->_dict[$key]) ?
+            $this->children[$this->_dict[$key]] :
+            null;
     }
 
     /**
@@ -350,12 +345,9 @@ class Nag_Task {
      *
      * @return boolean  True if this is a task or has sub tasks.
      */
-    function hasTasks()
+    public function hasTasks()
     {
-        if ($this->id) {
-            return true;
-        }
-        return $this->hasSubTasks();
+        return ($this->id) ? true : $this->hasSubTasks();
     }
 
     /**
@@ -363,7 +355,7 @@ class Nag_Task {
      *
      * @return boolean  True if this task has sub tasks.
      */
-    function hasSubTasks()
+    public function hasSubTasks()
     {
         foreach ($this->children as $task) {
             if ($task->hasTasks()) {
@@ -378,7 +370,7 @@ class Nag_Task {
      *
      * @return boolean  True if all sub tasks are completed.
      */
-    function childrenCompleted()
+    public function childrenCompleted()
     {
         foreach ($this->children as $task) {
             if (!$task->completed || !$task->childrenCompleted()) {
@@ -393,7 +385,7 @@ class Nag_Task {
      *
      * @return integer  The number of tasks and sub tasks.
      */
-    function count()
+    public function count()
     {
         $count = $this->id ? 1 : 0;
         foreach ($this->children as $task) {
@@ -407,7 +399,7 @@ class Nag_Task {
      *
      * @return integer  The estimated length sum.
      */
-    function estimation()
+    public function estimation()
     {
         $estimate = $this->estimate;
         foreach ($this->children as $task) {
@@ -421,9 +413,13 @@ class Nag_Task {
      *
      * @return string
      */
-    function getFormattedDescription()
+    public function getFormattedDescription()
     {
-        $desc = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($this->desc, 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO));
+        $desc = $GLOBALS['injector']
+            ->getInstance('Horde_Core_Factory_TextFilter')
+            ->filter($this->desc,
+                     'text2html',
+                     array('parselevel' => Horde_Text_Filter_Text2html::MICRO));
         try {
             return Horde::callHook('format_description', array($desc), 'nag');
         } catch (Horde_Exception_HookNotSet $e) {
@@ -438,7 +434,7 @@ class Nag_Task {
      *
      * @see each()
      */
-    function reset()
+    public function reset()
     {
         foreach (array_keys($this->children) as $key) {
             $this->children[$key]->reset();
@@ -459,7 +455,7 @@ class Nag_Task {
      *
      * @see reset()
      */
-    function each()
+    public function each()
     {
         if ($this->id && !$this->_inlist) {
             $this->_inlist = true;
@@ -483,7 +479,7 @@ class Nag_Task {
      *
      * @param integer $indent  The indention level of the tasks.
      */
-    function process($indent = 0)
+    public function process($indent = 0)
     {
         /* Link cache. */
         static $view_url_list, $task_url_list;
@@ -537,7 +533,7 @@ class Nag_Task {
      *
      * @return string  The HTML code for necessary tree icons.
      */
-    function treeIcons()
+    public function treeIcons()
     {
         $html = '';
 
@@ -571,7 +567,7 @@ class Nag_Task {
      *                           (Nag::SORT_ASCEND, Nag::SORT_DESCEND).
      * @param string $altsortby  The secondary sort field.
      */
-    function sort($sortby, $sortdir, $altsortby)
+    public function sort($sortby, $sortdir, $altsortby)
     {
         /* Sorting criteria for the task list. */
         $sort_functions = array(
@@ -627,7 +623,7 @@ class Nag_Task {
      *
      * @return array  A task hash.
      */
-    function toHash()
+    public function toHash()
     {
         return array('tasklist_id' => $this->tasklist,
                      'task_id' => $this->id,
@@ -658,7 +654,7 @@ class Nag_Task {
      *
      * @return object  A simple object.
      */
-    function toJson($full = false, $time_format = 'H:i')
+    public function toJson($full = false, $time_format = 'H:i')
     {
         $json = new stdClass;
         $json->l = $this->tasklist;
@@ -726,7 +722,7 @@ class Nag_Task {
      *
      * @return array  Alarm hash or null.
      */
-    function toAlarm($user = null, $prefs = null)
+    public function toAlarm($user = null, $prefs = null)
     {
         if (empty($this->alarm) || $this->completed) {
             return;
@@ -795,7 +791,7 @@ class Nag_Task {
      *
      * @return Horde_Icalendar_Vtodo  A vtodo component of this task.
      */
-    function toiCalendar($calendar)
+    public function toiCalendar(Horde_Icalendar $calendar)
     {
         $vTodo = Horde_Icalendar::newComponent('vtodo', $calendar);
         $v1 = $calendar->getAttribute('VERSION') == '1.0';
@@ -892,6 +888,7 @@ class Nag_Task {
     /**
      * Create an AS message from this task
      *
+     * @return Horde_ActiveSync_Message_Task
      */
     function toASTask()
     {
@@ -946,7 +943,7 @@ class Nag_Task {
      *
      * @param Horde_Icalendar_Vtodo $vTodo  The iCalendar data to update from.
      */
-    function fromiCalendar($vTodo)
+    function fromiCalendar(Horde_Icalendar_Vtodo $vTodo)
     {
         try {
             $name = $vTodo->getAttribute('SUMMARY');
@@ -972,12 +969,10 @@ class Nag_Task {
             foreach ($relations as $id => $relation) {
                 if (empty($params[$id]['RELTYPE']) ||
                     Horde_String::upper($params[$id]['RELTYPE']) == 'PARENT') {
-                    $storage = Nag_Driver::singleton($this->tasklist);
 
+                    $storage = Nag_Driver::singleton($this->tasklist);
                     $parent = $storage->getByUID($relation);
-                    if (!is_a($parent, 'PEAR_Error')) {
-                        $this->parent_id = $parent->id;
-                    }
+                    $this->parent_id = $parent->id;
                     break;
                 }
             }
@@ -1049,6 +1044,7 @@ class Nag_Task {
     /**
      * Create a nag Task object from an activesync message
      *
+     * @param Horde_ActiveSync_Message_Task $message  The task object
      */
     function fromASTask(Horde_ActiveSync_Message_Task $message)
     {
index 5b27c10..4dc95dc 100644 (file)
@@ -19,7 +19,7 @@
  */
 class Horde_Core_Ui_VarRenderer_Nag extends Horde_Core_Ui_VarRenderer_Html
 {
-    protected function _renderVarInput_nag_method($form, $var, $vars)
+    protected function _renderVarInput_NagMethod($form, $var, $vars)
     {
         $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
         $varvalue = $var->getValue($vars);
@@ -79,7 +79,7 @@ class Horde_Core_Ui_VarRenderer_Nag extends Horde_Core_Ui_VarRenderer_Html
         }
     }
 
-    protected function _renderVarInput_nag_start($form, $var, $vars)
+    protected function _renderVarInput_NagStart($form, $var, $vars)
     {
         $var->type->getInfo($vars, $var, $task_start);
         $start_date = ($task_start == 0)
@@ -112,7 +112,7 @@ class Horde_Core_Ui_VarRenderer_Nag extends Horde_Core_Ui_VarRenderer_Html
         }
     }
 
-    protected function _renderVarInput_nag_due($form, $var, $vars)
+    protected function _renderVarInput_NagDue($form, $var, $vars)
     {
         $var->type->getInfo($vars, $var, $task_due);
         if ($task_due == 0) {
@@ -171,7 +171,7 @@ class Horde_Core_Ui_VarRenderer_Nag extends Horde_Core_Ui_VarRenderer_Html
 <?php
     }
 
-    protected function _renderVarInput_nag_alarm($form, $var, $vars)
+    protected function _renderVarInput_NagAlarm($form, $var, $vars)
     {
         $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
         $value = $var->getValue($vars);
index b0bef2d..bf1f2db 100644 (file)
@@ -44,12 +44,15 @@ case 'search_tasks':
     $vars->set('show_completed', $search_completed);
 
     /* Get the full, sorted task list. */
-    $tasks = Nag::listTasks($prefs->getValue('sortby'),
-                            $prefs->getValue('sortdir'),
-                            $prefs->getValue('altsortby'),
-                            null,
-                            $search_completed);
-    if (is_a($tasks, 'PEAR_Error')) {
+    try {
+        $tasks = Nag::listTasks(
+            $prefs->getValue('sortby'),
+            $prefs->getValue('sortdir'),
+            $prefs->getValue('altsortby'),
+            null,
+            $search_completed
+        );
+    } catch (Nag_Exception $e) {
         $notification->push($tasks, 'horde.error');
         $tasks = new Nag_Task();
     }
@@ -75,10 +78,13 @@ case 'search_tasks':
 
 default:
     /* Get the full, sorted task list. */
-    $tasks = Nag::listTasks($prefs->getValue('sortby'),
-                            $prefs->getValue('sortdir'),
-                            $prefs->getValue('altsortby'));
-    if (is_a($tasks, 'PEAR_Error')) {
+    try {
+        $tasks = Nag::listTasks(
+            $prefs->getValue('sortby'),
+            $prefs->getValue('sortdir'),
+            $prefs->getValue('altsortby')
+        );
+    } catch (Nag_Exception $e) {
         $notification->push($tasks, 'horde.error');
         $tasks = new Nag_Task();
     }
index 0c6f9ea..0c69817 100644 (file)
@@ -10,16 +10,17 @@ $actionID = $vars->actionID;
 $title = _("My Tasks");
 
 /* Get the full, sorted task list. */
-$tasks = Nag::listTasks($prefs->getValue('sortby'),
-                        $prefs->getValue('sortdir'),
-                        $prefs->getValue('altsortby'));
-if (is_a($tasks, 'PEAR_Error')) {
+try {
+    $tasks = Nag::listTasks(
+        $prefs->getValue('sortby'),
+        $prefs->getValue('sortdir'),
+        $prefs->getValue('altsortby')
+     );
+} catch (Nag_Exception $e) {
     $notification->push($tasks, 'horde.error');
     $tasks = new Nag_Task();
 }
-
 require $registry->get('templates', 'horde') . '/common-header-mobile.inc';
-
 ?>
 <style type="text/css">
 .ui-icon-nag-unchecked {
index d7fd15b..b296aea 100644 (file)
@@ -4,10 +4,12 @@ require_once dirname(__FILE__) . '/lib/Application.php';
 Horde_Registry::appInit('nag');
 
 if ($quickText = Horde_Util::getPost('quickText')) {
-    $result = Nag::createTasksFromText($quickText, Nag::getDefaultTasklist(Horde_Perms::EDIT));
-    if (is_a($result, 'PEAR_Error')) {
-        $notification->push($result);
-    } elseif ($result) {
+    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');
index 7a6fec7..5ebe012 100755 (executable)
@@ -35,12 +35,11 @@ if (empty($vtodo)) {
 Horde_Auth::setAuth($user, array());
 
 // Import data.
-$result = $registry->call('tasks/import',
-                          array($vtodo, 'text/calendar', $tasklist));
-if (is_a($result, 'PEAR_Error')) {
+try {
+    $result = $registry->tasks->import($vtodo, 'text/calendar', $tasklist);
+} catch (Horde_Exception $e) {
     $cli->fatal($result->toString());
 }
-
 $cli->message('Imported successfully ' . count($result) . ' tasks', 'cli.success');
 
 function usage()
index 28275bf..5ab77f3 100644 (file)
 function _delete($task_id, $tasklist_id)
 {
     if (!empty($task_id)) {
-        $task = Nag::getTask($tasklist_id, $task_id);
-        if ($task instanceof PEAR_Error) {
-            $GLOBALS['notification']->push(
-                sprintf(_("Error deleting task: %s"),
-                        $task->getMessage()), 'horde.error');
-        } else {
+        try {
+            $task = Nag::getTask($tasklist_id, $task_id);
             try {
                 $share = $GLOBALS['nag_shares']->getShare($tasklist_id);
             } catch (Horde_Share_Exception $e) {
@@ -38,6 +34,10 @@ function _delete($task_id, $tasklist_id)
                 $GLOBALS['notification']->push(sprintf(_("Deleted %s."), $task->name),
                                                'horde.success');
             }
+        } catch (Nag_Exception $e) {
+            $GLOBALS['notification']->push(
+                sprintf(_("Error deleting task: %s"),
+                        $e->getMessage()), 'horde.error');
         }
     }
 
@@ -52,7 +52,6 @@ function _delete($task_id, $tasklist_id)
 require_once dirname(__FILE__) . '/lib/Application.php';
 Horde_Registry::appInit('nag');
 
-require_once NAG_BASE . '/lib/Forms/task.php';
 $vars = Horde_Variables::getDefaultVariables();
 
 /* Redirect to the task list if no action has been requested. */
@@ -80,7 +79,7 @@ case 'add_task':
     if (!$vars->exists('tasklist_id')) {
         $vars->set('tasklist_id', Nag::getDefaultTasklist(Horde_Perms::EDIT));
     }
-    $form = new Nag_TaskForm($vars, _("New Task"));
+    $form = new Nag_Form_Task($vars, _("New Task"));
     break;
 
 case 'modify_task':
@@ -104,7 +103,7 @@ case 'modify_task':
             $vars->set('actionID', 'save_task');
             $vars->set('old_tasklist', $task->tasklist);
             $vars->set('url', Horde_Util::getFormData('url'));
-            $form = new Nag_TaskForm($vars, sprintf(_("Edit: %s"), $task->name), $share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE));
+            $form = new Nag_Form_Task($vars, sprintf(_("Edit: %s"), $task->name), $share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE));
             break;
         }
     }
@@ -117,7 +116,7 @@ case 'save_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"));
+    $form = new Nag_Form_Task($vars, $vars->get('task_id') ? sprintf(_("Edit: %s"), $vars->get('name')) : _("New Task"));
     if (!$form->validate($vars)) {
         break;
     }
@@ -169,29 +168,31 @@ case 'save_task':
 
         /* 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'], $info['methods'], null,
-                                $info['parent'], (int)$info['private'],
-                                $GLOBALS['registry']->getAuth(), $info['assignee']);
+        try {
+            $storage->add(
+                $info['name'], $info['desc'], $info['start'],
+                $info['due'], $info['priority'],
+                (float)$info['estimate'],
+                (int)$info['completed'],
+                $info['category']['value'],
+                $info['alarm'], $info['methods'], null,
+                $info['parent'], (int)$info['private'],
+                $GLOBALS['registry']->getAuth(), $info['assignee']
+            );
+        } catch (Nag_Exception $e) {
+            $notification->push(sprintf(_("There was a problem saving the task: %s."), $result->getMessage()), 'horde.error');
+            Horde::url('list.php', true)->redirect();
+        }
     }
 
     /* Check our results. */
-    if ($result instanceof 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 last page or to the task list. */
-        if ($url = Horde_Util::getFormData('url')) {
-            header('Location: ' . $url);
-            exit;
-        }
-        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 ($url = Horde_Util::getFormData('url')) {
+        header('Location: ' . $url);
+        exit;
     }
-
+    Horde::url('list.php', true)->redirect();
     break;
 
 case 'delete_task':
@@ -215,17 +216,18 @@ case 'complete_task':
             } else {
                 $task->completed_date = null;
             }
-            $result = $task->save();
-            if ($result instanceof PEAR_Error) {
+            try {
+                $result = $task->save();
+            } catch (Nag_Exception $e) {
                 $notification->push(sprintf(_("There was a problem completing %s: %s"),
-                                            $task->name, $result->getMessage()), 'horde.error');
+                                            $task->name, $e->getMessage()), 'horde.error');
+            }
+            if ($task->completed) {
+                $notification->push(sprintf(_("Completed %s."), $task->name), 'horde.success');
             } 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');
-                }
+                $notification->push(sprintf(_("%s is now incomplete."), $task->name), 'horde.success');
             }
+
         }
     }
 
index 56c3eb4..361c408 100644 (file)
@@ -20,11 +20,8 @@ $tasks = Nag::listTasks(
     $prefs->getValue('sortdir'),
     $prefs->getValue('altsortby'),
     null,
-    1);
-if ($tasks instanceof PEAR_Error) {
-    throw new Nag_Exception($tasks);
-}
-
+    1
+);
 $search_pattern = '/^' . preg_quote($search, '/') . '/i';
 $search_results = new Nag_Task();
 $tasks->reset();
index ced4c73..27c3407 100644 (file)
@@ -13,11 +13,11 @@ Horde_Registry::appInit('nag');
  * UID first. */
 if ($uid = Horde_Util::getFormData('uid')) {
     $storage = Nag_Driver::singleton();
-    $task = $storage->getByUID($uid);
-    if ($task instanceof PEAR_Error) {
+    try {
+        $task = $storage->getByUID($uid);
+    } catch (Nag_Exception $e) {
         Horde::url('list.php', true)->redirect();
     }
-
     $task_id = $task->id;
     $tasklist_id = $task->tasklist;
 } else {