Index: TaskController.class.php =================================================================== --- TaskController.class.php (revision 177) +++ TaskController.class.php (working copy) @@ -28,6 +28,7 @@ * @return null */ function index() { + $this->addHelper('textile'); tpl_assign('open_task_lists', active_project()->getOpenTaskLists()); tpl_assign('completed_task_lists', active_project()->getCompletedTaskLists()); @@ -44,6 +45,7 @@ * @return null */ function view_list() { + $this->addHelper('textile'); $task_list = ProjectTaskLists::findById(get_id()); if (!($task_list instanceof ProjectTaskList)) { flash_error(lang('task list dnx')); @@ -87,7 +89,7 @@ tpl_assign('task_list_data', $task_list_data); tpl_assign('task_list', $task_list); - + if (is_array(array_var($_POST, 'task_list'))) { $task_list->setFromAttributes($task_list_data); @@ -103,7 +105,8 @@ $tasks[] = array( 'text' => array_var($task_list_data["task$i"], 'text'), 'assigned_to_company_id' => array_var($assigned_to, 0, 0), - 'assigned_to_user_id' => array_var($assigned_to, 1, 0) + 'assigned_to_user_id' => array_var($assigned_to, 1, 0), + 'send_notification' => array_var($task_list_data["task$i"], 'send_notification'), ); // array } // if } // for @@ -119,11 +122,25 @@ $task->setFromAttributes($task_data); $task_list->attachTask($task); $task->save(); + + tpl_assign('task', $task); + + // notify user + if (array_var($task_data, 'send_notification') == 'checked') { + try { + if (Notifier::nodifyNeeded($task->getAssignedTo(), null)) { + Notifier::taskAssigned($task); + } + } catch(Exception $e) { + Logger::log("Error: Notification failed, " . $e->getMessage(), Logger::ERROR); + } // try + } // if + } // foreach ApplicationLogs::createLog($task_list, active_project(), ApplicationLogs::ACTION_ADD); DB::commit(); - + flash_success(lang('success add task list', $task_list->getName())); $this->redirectToUrl($task_list->getViewUrl()); @@ -332,7 +349,8 @@ $task = new ProjectTask(); $task_data = array_var($_POST, 'task'); - + $old_owner = $task->getAssignedTo(); + tpl_assign('task', $task); tpl_assign('task_list', $task_list); tpl_assign('back_to_list', $back_to_list); @@ -353,7 +371,18 @@ $task_list->attachTask($task); ApplicationLogs::createLog($task, active_project(), ApplicationLogs::ACTION_ADD); DB::commit(); - + + // notify user + if (array_var($task_data, 'send_notification') == 'checked') { + try { + if (Notifier::nodifyNeeded($task->getAssignedTo(), $old_owner)) { + Notifier::taskAssigned($task); + } + } catch(Exception $e) { + Logger::log("Error: Notification failed, " . $e->getMessage(), Logger::ERROR); + } // try + } // if + flash_success(lang('success add task')); if ($back_to_list) { $this->redirectToUrl($task_list->getViewUrl()); @@ -378,7 +407,7 @@ */ function edit_task() { $this->setTemplate('add_task'); - + $task = ProjectTasks::findById(get_id()); if (!($task instanceof ProjectTask)) { flash_error(lang('task dnx')); @@ -410,6 +439,7 @@ tpl_assign('task_data', $task_data); if (is_array(array_var($_POST, 'task'))) { + $old_owner = $task->getAssignedTo(); $task->setFromAttributes($task_data); $task->setTaskListId($task_list->getId()); // keep old task list id @@ -435,7 +465,18 @@ ApplicationLogs::createLog($task, active_project(), ApplicationLogs::ACTION_EDIT); DB::commit(); - + + // notify user + if (array_var($task_data, 'send_notification') == 'checked') { + try { + if (Notifier::nodifyNeeded($task->getAssignedTo(), $old_owner)) { + Notifier::taskAssigned($task); + } + } catch(Exception $e) { + Logger::log("Error: Notification failed, " . $e->getMessage(), Logger::ERROR); + } // try + } // if + flash_success(lang('success edit task')); // Redirect to task list. Check if we have updated task list ID first @@ -453,8 +494,52 @@ } // if } // edit_task - + /** + * View task details page + * + * @access public + * @param void + * @return null + */ + function view_task() { + $this->setTemplate('view_task'); + $this->addHelper('textile'); + + $task = ProjectTasks::findById(get_id()); + if (!($task instanceof ProjectTask)) { + flash_error(lang('task dnx')); + $this->redirectTo('task'); + } // if + + $task_list = $task->getTaskList(); + if (!($task_list instanceof ProjectTaskList)) { + flash_error('task list dnx'); + $this->redirectTo('task'); + } // if + + + if (!$task_list->canView(logged_user())){ + flash_error(lang('no access permissions')); + $this->redirectTo('task'); + } // if + + $task_data = array_var($_POST, 'task'); + if (!is_array($task_data)) { + $task_data = array( + 'text' => $task->getText(), + 'task_list_id' => $task->getTaskListId(), + 'assigned_to' => $task->getAssignedToCompanyId() . ':' . $task->getAssignedToUserId() + ); // array + } // if + + tpl_assign('task', $task); + tpl_assign('task_list', $task_list); + tpl_assign('task_data', $task_data); + + } // task_details + + /** * Delete specific task * * @access public