Exemplo n.º 1
0
 /**
  * Show a form for editing an entry
  *
  * @param   object  $poll  Poll object
  * @return  void
  */
 public function editTask($poll = null)
 {
     Request::setVar('hidemainmenu', 1);
     $db = \App::get('db');
     $user = User::getRoot();
     if (!$poll) {
         $id = Request::getVar('cid', array(0));
         if (is_array($id) && !empty($id)) {
             $id = $id[0];
         }
         $poll = new Poll($db);
         $poll->load($id);
     }
     // Fail if checked out not by 'me'
     if ($poll->isCheckedOut($user->get('id'))) {
         App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('DESCBEINGEDITTED', Lang::txt('The poll'), $poll->title), 'warning');
         return;
     }
     if ($poll->id == 0) {
         $poll->published = 1;
     }
     $poll->checkout($user->get('id'));
     $query = 'SELECT id, text' . ' FROM `#__poll_data`' . ' WHERE pollid = ' . (int) $poll->id . ' ORDER BY id';
     $db->setQuery($query);
     $options = $db->loadObjectList();
     // Set any errors
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output the HTML
     $this->view->set('poll', $poll)->set('options', $options)->setLayout('edit')->display();
 }
Exemplo n.º 2
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);
 }