Пример #1
0
 /**
  * Get module contents
  *
  * @return  void
  */
 public function run()
 {
     require_once Component::path('com_poll') . DS . 'models' . DS . 'poll.php';
     $model = new Poll();
     // Load the latest poll
     $this->poll = $model->getLatest();
     require $this->getLayoutPath();
 }
Пример #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')) {
         $db = \App::get('db');
         $row = new Poll($db);
         $row->checkin($id);
     }
     App::redirect(Route::url('index.php?option=' . $this->_option, false));
 }
Пример #3
0
 /**
  * Add a vote to an option
  */
 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 = new Poll($this->database);
     if (!$poll->load($poll_id) || $poll->published != 1) {
         throw new Exception(Lang::txt('JERROR_ALERTNOAUTHOR'), 404);
     }
     $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) {
             $msg = Lang::txt('COM_POLL_ALREADY_VOTED');
         }
         if (!$option_id) {
             $msg = 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->lag, '/', '', $secure, true);
         $poll->vote($poll_id, $option_id);
         $msg = 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->alias . $itemid, false), $msg);
 }