Exemple #1
0
 /**
  * Show a form for editing a wish
  *
  * @return     void
  */
 public function editwishTask()
 {
     $refid = Request::getInt('rid', 0);
     $cat = Request::getCmd('category', '');
     $status = Request::getWord('status', '');
     $vid = Request::getInt('vid', 0);
     // Check if wish exists on this list
     if ($id = Request::getInt('id', 0)) {
         $wishlist = Wishlist::getInstance(Request::getInt('id', 0));
     } else {
         $wishlist = Wishlist::getInstance($refid, $cat);
     }
     if (!$wishlist->exists()) {
         throw new Exception(Lang::txt('COM_WISHLIST_ERROR_WISHLIST_NOT_FOUND'), 404);
     }
     // load wish
     $wish = new Wish(Request::getInt('wishid', 0));
     if (!$wish->exists()) {
         throw new Exception(Lang::txt('COM_WISHLIST_ERROR_WISH_NOT_FOUND'), 404);
     }
     $changed = false;
     // Login required
     if (User::isGuest()) {
         // Set page title
         $this->_list_title = ($wishlist->isPublic() or !$wishlist->isPublic() && $wishlist->get('admin') == 2) ? $wishlist->get('title') : '';
         $this->_buildTitle();
         // Set the pathway
         $this->_taskpath = $wish->link();
         $this->_taskname = Lang::txt(strtoupper($this->_option) . '_' . strtoupper($this->_task));
         $this->_buildPathway($wishlist);
         $this->loginTask();
         return;
     }
     if (!$wishlist->access('manage') && $wish->get('proposed_by') != User::get('id')) {
         throw new Exception(Lang::txt('COM_WISHLIST_ALERTNOTAUTH'), 403);
     }
     if ($this->_task == 'editprivacy') {
         $private = Request::getInt('private', 0, 'get');
         if ($wish->get('private') != $private) {
             $wish->set('private', $private);
             $changed = true;
         }
     }
     if ($this->_task == 'editwish' && ($status = Request::getWord('status', ''))) {
         $former_status = $wish->get('status');
         $former_accepted = $wish->get('accepted');
         switch ($status) {
             case 'pending':
                 $wish->set('status', 0);
                 $wish->set('accepted', 0);
                 break;
             case 'accepted':
                 $wish->set('status', 0);
                 $wish->set('accepted', 1);
                 $wish->set('assigned', User::get('id'));
                 // assign to person who accepted the wish
                 break;
             case 'rejected':
                 $wish->set('accepted', 0);
                 $wish->set('status', 3);
                 // return bonuses
                 if ($this->banking) {
                     $WE = new Economy($this->database);
                     $WE->cleanupBonus($wish->get('id'));
                 }
                 break;
             case 'granted':
                 $wish->set('status', 1);
                 $wish->set('granted', Date::toSql());
                 $wish->set('granted_by', User::get('id'));
                 $wish->set('granted_vid', $vid ? $vid : 0);
                 $objWish = new Tables\Wish($this->database);
                 $w = $objWish->get_wish($wish->get('id'), User::get('id'));
                 $wish->set('points', $w->bonus);
                 if ($this->banking) {
                     // Distribute bonus and earned points
                     $WE = new Economy($this->database);
                     $WE->distribute_points($wish->get('id'));
                 }
                 break;
         }
         if ($former_status != $wish->get('status') or $former_accepted != $wish->get('accepted')) {
             $changed = true;
         }
         if ($changed) {
             // Build e-mail components
             // to wish author
             $subject1 = Lang::txt(strtoupper($this->_option)) . ', ' . Lang::txt('COM_WISHLIST_YOUR_WISH') . ' #' . $wish->get('id') . ' is ' . $status;
             // to wish assignee
             $subject2 = Lang::txt(strtoupper($this->_option)) . ', ' . Lang::txt('COM_WISHLIST_WISH') . ' #' . $wish->get('id') . ' ' . Lang::txt('COM_WISHLIST_HAS_BEEN') . ' ' . Lang::txt('COM_WISHLIST_MSG_ASSIGNED_TO_YOU');
             $from = array('name' => Config::get('sitename') . ' ' . Lang::txt(strtoupper($this->_option)), 'email' => Config::get('mailfrom'));
             $message = array();
             // Plain text email
             $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'wish_plain'));
             $eview->option = $this->_option;
             $eview->controller = $this->_controller;
             $eview->wish = $wish;
             $eview->wishlist = $wishlist;
             $eview->action = 'updated';
             $eview->status = $status;
             $message['plaintext'] = $eview->loadTemplate(false);
             $message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']);
             // HTML email
             $eview->setLayout('wish_html');
             $message['multipart'] = $eview->loadTemplate();
             $message['multipart'] = str_replace("\n", "\r\n", $message['multipart']);
         }
     } else {
         if ($this->_task == 'editwish') {
             $this->addwishTask($wish->get('id'));
             return;
         }
     }
     if ($changed) {
         // save changes
         if (!$wish->store()) {
             throw new Exception($wish->getError(), 500);
         } else {
             if ($this->_task == 'editwish') {
                 if (!Event::trigger('xmessage.onSendMessage', array('wishlist_status_changed', $subject1, $message, $from, array($wish->get('proposed_by')), $this->_option))) {
                     $this->setError(Lang::txt('COM_WISHLIST_ERROR_FAILED_MSG_AUTHOR'));
                 }
                 if ($wish->get('assigned') && $wish->get('proposed_by') != $wish->get('assigned') && $status == 'accepted') {
                     if (!Event::trigger('xmessage.onSendMessage', array('wishlist_wish_assigned', $subject2, $message, $from, array($wish->get('assigned')), $this->_option))) {
                         $this->setError(Lang::txt('COM_WISHLIST_ERROR_FAILED_MSG_ASSIGNEE'));
                     }
                 }
             }
         }
     }
     App::redirect(Route::url($wish->link()));
 }