Ejemplo n.º 1
0
 /**
  * This function will return application data object that matches action and in object ID
  *
  * @param void
  * @return ApplicationDataObject
  */
 function getInObject()
 {
     if (is_null($this->in_object)) {
         if ($this->getAction() == self::ADD_COMMENT_ACTION) {
             $this->in_object = ProjectMessages::findById($this->getInObjectId());
         } elseif ($this->getAction() == self::ADD_TASK_ACTION) {
             $this->in_object = ProjectTaskLists::findById($this->getInObjectId());
         }
         // if
     }
     // if
     return $this->in_object;
 }
Ejemplo n.º 2
0
 /**
  * Edit existing project form
  *
  * @param void
  * @return null
  */
 function edit()
 {
     $this->setTemplate('add_project_form');
     $project_form = ProjectForms::findById(get_id());
     if (!$project_form instanceof ProjectForm) {
         flash_error(lang('project form dnx'));
         if (ProjectForm::canAdd(logged_user(), active_project())) {
             $this->redirectTo('form');
         } else {
             $this->redirectToUrl(active_project()->getOverviewUrl());
         }
         // if
     }
     // if
     if (!$project_form->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         if (ProjectForm::canAdd(logged_user(), active_project())) {
             $this->redirectTo('form');
         } else {
             $this->redirectToUrl(active_project()->getOverviewUrl());
         }
         // if
     }
     // if
     $project_form_data = array_var($_POST, 'project_form');
     if (!is_array($project_form_data)) {
         $project_form_data = array('name' => $project_form->getName(), 'description' => $project_form->getDescription(), 'success_message' => $project_form->getSuccessMessage(), 'action' => $project_form->getAction(), 'is_enabled' => $project_form->getIsEnabled(), 'is_visible' => $project_form->getIsVisible());
         // array
         if ($project_form->getAction() == ProjectForm::ADD_COMMENT_ACTION) {
             $project_form_data['message_id'] = $project_form->getInObjectId();
         } else {
             $project_form_data['task_list_id'] = $project_form->getInObjectId();
         }
         // if
     }
     // if
     tpl_assign('project_form', $project_form);
     tpl_assign('project_form_data', $project_form_data);
     if (is_array(array_var($_POST, 'project_form'))) {
         $project_form->setFromAttributes($project_form_data);
         if ($project_form->getAction() == ProjectForm::ADD_COMMENT_ACTION) {
             $in_object = ProjectMessages::findById(get_id('message_id', $project_form_data));
             $relation_error_message = lang('project form select message');
         } else {
             $in_object = ProjectTaskLists::findById(get_id('task_list_id', $project_form_data));
             $relation_error_message = lang('project form select task lists');
         }
         // if
         if (!$in_object instanceof ProjectDataObject) {
             tpl_assign('error', new Error($relation_error_message));
             $this->render();
         }
         // if
         $project_form->setInObjectId($in_object->getObjectId());
         // set related object ID
         try {
             DB::beginWork();
             $project_form->save();
             ApplicationLogs::createLog($project_form, active_project(), ApplicationLogs::ACTION_EDIT, true);
             DB::commit();
             flash_success(lang('success edit project form', $project_form->getName()));
             $this->redirectTo('form');
         } catch (Exception $e) {
             DB::rollback();
             tpl_assign('error', $e);
         }
         // try
     }
     // if
 }
Ejemplo n.º 3
0
 /**
  * Edit task
  *
  * @access public
  * @param void
  * @return null
  */
 function edit_task()
 {
     $this->setTemplate('add_task');
     $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->canEdit(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(), 'start_date' => $task->getStartDate(), 'due_date' => $task->getDueDate(), 'task_list_id' => $task->getTaskListId(), 'assigned_to' => $task->getAssignedToCompanyId() . ':' . $task->getAssignedToUserId(), 'send_notification' => config_option('send_notification_default', '0'));
         // array
     }
     // if
     tpl_assign('task', $task);
     tpl_assign('task_list', $task_list);
     tpl_assign('task_data', $task_data);
     if (is_array(array_var($_POST, 'task'))) {
         $old_owner = $task->getAssignedTo();
         //$task_data['due_date'] = DateTimeValueLib::make(0, 0, 0, array_var($_POST, 'task_due_date_month', 1), array_var($_POST, 'task_due_date_day', 1), array_var($_POST, 'task_due_date_year', 1970));
         if (isset($_POST['task_start_date'])) {
             $task_data['start_date'] = DateTimeValueLib::makeFromString($_POST['task_start_date']);
         } else {
             $task_data['start_date'] = DateTimeValueLib::make(0, 0, 0, array_var($_POST, 'task_start_date_month', 1), array_var($_POST, 'task_start_date_day', 1), array_var($_POST, 'task_start_date_year', 1970));
         }
         if (isset($_POST['task_due_date'])) {
             $task_data['due_date'] = DateTimeValueLib::makeFromString($_POST['task_due_date']);
         } else {
             $task_data['due_date'] = DateTimeValueLib::make(0, 0, 0, array_var($_POST, 'task_due_date_month', 1), array_var($_POST, 'task_due_date_day', 1), array_var($_POST, 'task_due_date_year', 1970));
         }
         $task->setFromAttributes($task_data);
         $task->setTaskListId($task_list->getId());
         // keep old task list id
         $assigned_to = explode(':', array_var($task_data, 'assigned_to', ''));
         $task->setAssignedToCompanyId(array_var($assigned_to, 0, 0));
         $task->setAssignedToUserId(array_var($assigned_to, 1, 0));
         try {
             DB::beginWork();
             $task->save();
             // Move?
             $new_task_list_id = (int) array_var($task_data, 'task_list_id');
             if ($new_task_list_id && $task->getTaskListId() != $new_task_list_id) {
                 // Move!
                 $new_task_list = ProjectTaskLists::findById($new_task_list_id);
                 if ($new_task_list instanceof ProjectTaskList) {
                     $task_list->detachTask($task, $new_task_list);
                     // detach from old and attach to new list
                 }
                 // if
             }
             // if
             ApplicationLogs::createLog($task, active_project(), ApplicationLogs::ACTION_EDIT);
             DB::commit();
             trace(__FILE__, 'edit_task: notify user');
             // notify user
             if (array_var($task_data, 'send_notification') == 'checked') {
                 try {
                     if (Notifier::notifyNeeded($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
             if (isset($new_task_list) && $new_task_list instanceof ProjectTaskList) {
                 $this->redirectToUrl($new_task_list->getViewUrl());
             } else {
                 $this->redirectToUrl($task_list->getViewUrl());
             }
             // if
         } catch (Exception $e) {
             DB::rollback();
             tpl_assign('error', $e);
         }
         // try
     }
     // if
 }
Ejemplo n.º 4
0
 /**
  * Edit task
  *
  * @access public
  * @param void
  * @return null
  */
 function edit_task()
 {
     $this->setTemplate('add_task');
     $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->canEdit(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);
     if (is_array(array_var($_POST, 'task'))) {
         $task->setFromAttributes($task_data);
         $task->setTaskListId($task_list->getId());
         // keep old task list id
         $assigned_to = explode(':', array_var($task_data, 'assigned_to', ''));
         $task->setAssignedToCompanyId(array_var($assigned_to, 0, 0));
         $task->setAssignedToUserId(array_var($assigned_to, 1, 0));
         try {
             DB::beginWork();
             $task->save();
             // Move?
             $new_task_list_id = (int) array_var($task_data, 'task_list_id');
             if ($new_task_list_id && $task->getTaskListId() != $new_task_list_id) {
                 // Move!
                 $new_task_list = ProjectTaskLists::findById($new_task_list_id);
                 if ($new_task_list instanceof ProjectTaskList) {
                     $task_list->detachTask($task, $new_task_list);
                     // detach from old and attach to new list
                 }
                 // if
             }
             // if
             ApplicationLogs::createLog($task, active_project(), ApplicationLogs::ACTION_EDIT);
             DB::commit();
             flash_success(lang('success edit task'));
             // Redirect to task list. Check if we have updated task list ID first
             if (isset($new_task_list) && $new_task_list instanceof ProjectTaskList) {
                 $this->redirectToUrl($new_task_list->getViewUrl());
             } else {
                 $this->redirectToUrl($task_list->getViewUrl());
             }
             // if
         } catch (Exception $e) {
             DB::rollback();
             tpl_assign('error', $e);
         }
         // try
     }
     // if
 }
Ejemplo n.º 5
0
 /**
  * Return parent task lists
  *
  * @access public
  * @param void
  * @return ProjectTaskList
  */
 function getTaskList()
 {
     return ProjectTaskLists::findById($this->getTaskListId());
 }