Ejemplo n.º 1
0
 /**
  * Save item
  *
  * @return	   string
  */
 public function save()
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     // Incoming
     $listcolor = Request::getVar('list', '');
     $content = Request::getVar('content', '');
     $todoid = Request::getInt('todoid', 0);
     $newlist = Request::getVar('newlist', '', 'post');
     $newcolor = Request::getVar('newcolor', '', 'post');
     $page = Request::getVar('page', 'list', 'post');
     $assigned = Request::getInt('assigned', 0);
     $mine = Request::getInt('mine', 0);
     $state = Request::getInt('state', 0);
     $ajax = Request::getInt('ajax', 0);
     $task = $this->_task;
     $new = 0;
     // Check permission
     if (!$this->model->access('content')) {
         throw new Exception(Lang::txt('ALERTNOTAUTH'), 403);
         return;
     }
     // Check if assignee is owner
     $objO = $this->model->table('Owner');
     if ($assigned && !$objO->isOwner($assigned, $this->model->get('id'))) {
         $assigned = 0;
     }
     if ($mine && !$assigned) {
         $assigned = $this->_uid;
     }
     // Initiate extended database class
     $objTD = new \Components\Projects\Tables\Todo($this->_database);
     // Load up todo if exists
     if (!$objTD->loadTodo($this->model->get('id'), $todoid)) {
         $objTD->created_by = $this->_uid;
         $objTD->created = Date::toSql();
         $objTD->projectid = $this->model->get('id');
         $assigned = $assigned;
         $new = 1;
     } else {
         $content = $content ? $content : $objTD->content;
     }
     // Prevent resubmit
     if ($task == 'save' && $content == '' && $newlist == '') {
         App::redirect($this->model->link('todo'));
         return;
     }
     // Save if not empty
     if ($task == 'save' && $content != '') {
         $content = rtrim(stripslashes($content));
         $objTD->content = $content ? $content : $objTD->content;
         $objTD->content = \Hubzero\Utility\Sanitize::stripAll($objTD->content);
         // Save access under details
         if (strlen($objTD->content) > 255) {
             $objTD->details = $objTD->content;
         }
         $objTD->content = \Hubzero\Utility\String::truncate($objTD->content, 255);
         $objTD->color = $listcolor == 'none' ? '' : $listcolor;
         $objTD->assigned_to = $assigned;
         $objTD->state = $state;
         // Get due date
         $due = trim(Request::getVar('due', ''));
         if ($due && $due != 'mm/dd/yyyy') {
             $date = explode('/', $due);
             if (count($date) == 3) {
                 $month = $date[0];
                 $day = $date[1];
                 $year = $date[2];
                 if (intval($month) && intval($day) && intval($year)) {
                     if (strlen($day) == 1) {
                         $day = '0' . $day;
                     }
                     if (strlen($month) == 1) {
                         $month = '0' . $month;
                     }
                     if (checkdate($month, $day, $year)) {
                         $objTD->duedate = Date::of(mktime(0, 0, 0, $month, $day, $year))->toSql();
                     }
                 }
             } else {
                 $this->setError(Lang::txt('PLG_PROJECTS_TODO_TODO_WRONG_DATE_FORMAT'));
             }
         } else {
             $objTD->duedate = '';
         }
         // Get last order
         $lastorder = $objTD->getLastOrder($this->model->get('id'));
         $neworder = $lastorder ? $lastorder + 1 : 1;
         $objTD->priority = $todoid ? $objTD->priority : $neworder;
         // Get list name
         $objTD->todolist = $listcolor == 'none' ? NULL : $objTD->getListName($this->model->get('id'), $objTD->color);
         // Store content
         if (!$objTD->store()) {
             $this->setError($objTD->getError());
         } else {
             $this->_msg = $todoid ? Lang::txt('PLG_PROJECTS_TODO_TODO_ITEM_SAVED') : Lang::txt('PLG_PROJECTS_TODO_TODO_NEW_ITEM_SAVED');
         }
     } elseif ($task == 'assign') {
         $changed = $objTD->assigned_to == $assigned ? 0 : 1;
         if ($changed) {
             $objTD->assigned_to = $assigned;
             $this->_mine = 0;
             // do not send to My Todo's list
             // Store content
             if (!$objTD->store()) {
                 $this->setError($objTD->getError());
             } else {
                 $this->_msg = $mine ? Lang::txt('PLG_PROJECTS_TODO_TODO_ASSIGNED_TO_MINE') : Lang::txt('PLG_PROJECTS_TODO_TODO_REASSIGNED');
             }
         }
     } else {
         if ($task == 'changestate') {
             $changed = $objTD->state == $state ? 0 : 1;
             if ($changed) {
                 $objTD->state = $state;
                 if ($state == 1) {
                     $objTD->closed = Date::toSql();
                     $objTD->closed_by = $this->_uid;
                 }
                 // Store content
                 if (!$objTD->store()) {
                     $this->setError($objTD->getError());
                 } else {
                     $this->_msg = $state == 1 ? Lang::txt('PLG_PROJECTS_TODO_TODO_MARKED_COMPLETED') : Lang::txt('PLG_PROJECTS_TODO_TODO_MARKED_INCOMPLETE');
                     if ($state == 1) {
                         // Record activity
                         $aid = $this->model->recordActivity(Lang::txt('PLG_PROJECTS_TODO_ACTIVITY_TODO_COMPLETED'), $objTD->id, 'to do', Route::url('index.php?option=' . $this->_option . '&alias=' . $this->model->get('alias') . '&active=todo' . '&action=view&todoid=' . $objTD->id), 'todo', 1);
                     }
                 }
             }
         }
     }
     // Save new empty list information
     if ($newlist != '' && $newcolor != '') {
         $new = 0;
         $newlist = \Hubzero\Utility\Sanitize::stripAll(trim($newlist));
         if (!$objTD->getListName($this->model->get('id'), $newcolor)) {
             $objTD = new \Components\Projects\Tables\Todo($this->_database);
             $objTD->created_by = $this->_uid;
             $objTD->created = Date::toSql();
             $objTD->projectid = $this->model->get('id');
             $objTD->content = 'provisioned';
             $objTD->state = 2;
             // inactive
             $objTD->todolist = $newlist;
             $objTD->color = $newcolor;
             // Store content
             if (!$objTD->store()) {
                 $this->setError(Lang::txt('PLG_PROJECTS_TODO_TODO_ERROR_LIST_SAVE'));
             } else {
                 $this->_msg = Lang::txt('PLG_PROJECTS_TODO_TODO_LIST_SAVED');
             }
         }
     }
     // Record activity
     if ($new) {
         $aid = $this->model->recordActivity(Lang::txt('PLG_PROJECTS_TODO_ACTIVITY_TODO_ADDED'), $objTD->id, 'to do', Route::url('index.php?option=' . $this->_option . '&alias=' . $this->model->get('alias') . '&active=todo' . '&action=view&todoid=' . $objTD->id), 'todo', 1);
         // Store activity ID
         if ($aid) {
             $objTD->activityid = $aid;
             $objTD->store();
         }
     }
     // Set redirect path
     if ($page == 'item') {
         $url = Route::url('index.php?option=' . $this->_option . '&alias=' . $this->model->get('alias') . '&active=todo' . '&action=view&todoid=' . $objTD->id);
     } else {
         $url = Route::url('index.php?option=' . $this->_option . '&alias=' . $this->model->get('alias') . '&active=todo&list=' . $objTD->color);
     }
     // Go to view
     if ($ajax) {
         $this->_todoid = $todoid;
         return $page == 'item' ? $this->item() : $this->page();
     }
     // Pass error or success message
     if ($this->getError()) {
         \Notify::message($this->getError(), 'error', 'projects');
     } elseif (!empty($this->_msg)) {
         \Notify::message($this->_msg, 'success', 'projects');
     }
     // Redirect
     App::redirect(Route::url($url));
 }
Ejemplo n.º 2
0
 /**
  * Save item
  *
  * @return  string
  */
 protected function _save()
 {
     if (User::isGuest()) {
         $this->setError(Lang::txt('MEMBERS_LOGIN_NOTICE'));
         return;
     }
     if (User::get('id') != $this->member->get('id')) {
         $this->setError(Lang::txt('PLG_MEMBERS_TODO_NOT_AUTHORIZED'));
         return $this->_browse();
     }
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $content = Request::getVar('content', '');
     $projectid = Request::getInt('projectid', 0);
     $due = trim(Request::getVar('due', ''));
     $model = new \Components\Projects\Models\Project($projectid);
     if (!$content) {
         $this->setError(Lang::txt('PLG_MEMBERS_TODO_ERROR_PROVIDE_CONTENT'));
         return $this->_browse();
     }
     if (!$model->exists() || !$model->access('content')) {
         $this->setError(Lang::txt('PLG_MEMBERS_TODO_ERROR_ACCESS_PROJECT'));
         return $this->_browse();
     }
     // Initiate extended database class
     $objTD = new \Components\Projects\Tables\Todo($this->database);
     $content = rtrim(stripslashes($content));
     $objTD->content = $content ? $content : $objTD->content;
     $objTD->content = \Hubzero\Utility\Sanitize::stripAll($objTD->content);
     $objTD->created_by = $this->member->get('id');
     $objTD->created = Date::toSql();
     $objTD->projectid = $model->get('id');
     if (strlen($objTD->content) > 255) {
         $objTD->details = $objTD->content;
     }
     $objTD->content = \Hubzero\Utility\String::truncate($objTD->content, 255);
     if ($due && $due != 'mm/dd/yyyy') {
         $date = explode('/', $due);
         if (count($date) == 3) {
             $month = $date[0];
             $day = $date[1];
             $year = $date[2];
             if (intval($month) && intval($day) && intval($year)) {
                 if (strlen($day) == 1) {
                     $day = '0' . $day;
                 }
                 if (strlen($month) == 1) {
                     $month = '0' . $month;
                 }
                 if (checkdate($month, $day, $year)) {
                     $objTD->duedate = Date::of(mktime(0, 0, 0, $month, $day, $year))->toSql();
                 }
             }
         }
     } else {
         $objTD->duedate = '';
     }
     // Get last order
     $lastorder = $objTD->getLastOrder($model->get('id'));
     $objTD->priority = $lastorder ? $lastorder + 1 : 1;
     // Store content
     if (!$objTD->store()) {
         $this->setError($objTD->getError());
         return $this->_browse();
     } else {
         // Record activity
         $aid = $model->recordActivity(Lang::txt('PLG_MEMBERS_TODO_ACTIVITY_TODO_ADDED'), $objTD->id, 'to do', Route::url('index.php?option=com_projects&alias=' . $model->get('alias') . '&active=todo&action=view&todoid=' . $objTD->id), 'todo', 1);
         // Store activity ID
         if ($aid) {
             $objTD->activityid = $aid;
             $objTD->store();
         }
     }
     App::redirect(Route::url($this->member->link() . '&active=' . $this->_name), Lang::txt('PLG_MEMBERS_TODO_SAVED'));
 }