Exemple #1
0
 /**
  * Add a vote to an option
  *
  * @return  void
  */
 public function voteTask()
 {
     // Check for request forgeries
     Request::checkToken();
     $poll_id = Request::getVar('id', 0, '', 'int');
     $option_id = Request::getVar('voteid', 0, 'post', 'int');
     $poll = Poll::oneOrFail($poll_id);
     if ($poll->get('state') != 1) {
         App::abort(404, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     $cookieName = App::hash(App::get('client')->name . 'poll' . $poll_id);
     // ToDo - may be adding those information to the session?
     $voted = Request::getVar($cookieName, '0', 'COOKIE', 'INT');
     if ($voted || !$option_id) {
         if ($voted) {
             Notify::warning(Lang::txt('COM_POLL_ALREADY_VOTED'));
         }
         if (!$option_id) {
             Notify::warning(Lang::txt('COM_POLL_WARNSELECT'));
         }
     } else {
         // Determine whether cookie should be 'secure' or not
         $secure = false;
         $forceSsl = \Config::get('force_ssl', false);
         if (App::isAdmin() && $forceSsl >= 1) {
             $secure = true;
         } else {
             if (App::isSite() && $forceSsl == 2) {
                 $secure = true;
             }
         }
         setcookie($cookieName, '1', time() + $poll->get('lag'), '/', '', $secure, true);
         $poll->vote($option_id);
         Notify::success(Lang::txt('COM_POLL_THANK_YOU'));
     }
     // set Itemid id for links
     $menu = App::get('menu');
     $items = $menu->getItems('link', 'index.php?option=com_poll&view=poll');
     $itemid = isset($items[0]) ? '&Itemid=' . $items[0]->id : '';
     App::redirect(Route::url('index.php?option=com_poll&id=' . $poll_id . ':' . $poll->get('alias') . $itemid, false));
 }
Exemple #2
0
 /**
  * Cancels a task and redirects to listing
  *
  * @return  void
  */
 public function cancelTask()
 {
     // Check for request forgeries
     Request::checkToken();
     if ($id = Request::getVar('id', 0, '', 'int')) {
         if (is_int($id)) {
             $row = Poll::oneOrFail($id);
             $row->checkin();
         }
     }
     App::redirect(Route::url('index.php?option=' . $this->_option, false));
 }