function display($tpl = null) { $this->mainframe = JFactory::getApplication(); $this->option = JRequest::getCmd('option'); $filter_order = $this->mainframe->getUserStateFromRequest($this->option . '.polls.filter_order', 'filter_order', 'm.title', 'string'); $filter_order_Dir = $this->mainframe->getUserStateFromRequest($this->option . '.polls.filter_order_Dir', 'filter_order_Dir', '', 'word'); $search = $this->mainframe->getUserStateFromRequest($this->option . '.polls.search', 'search', '', 'string'); // table ordering $lists['order_Dir'] = $filter_order_Dir; $lists['order'] = $filter_order; // search filter $lists['search'] = $search; JHTML::_('behavior.tooltip'); if (MijopollsHelper::is15()) { $params = $this->mainframe->getParams(); } else { $menu = JSite::getMenu()->getActive(); $menu_params = new JRegistry($menu->params); $params = clone $this->mainframe->getParams(); $params->merge($menu_params); } $this->lists = $lists; $this->params = $params; $this->items = $this->get('Data'); $this->pagination = $this->get('Pagination'); if (MijopollsHelper::is30()) { $tpl = '30'; } parent::display($tpl); }
function display($tpl = null) { // Get data from the model require_once JPATH_COMPONENT . '/models/ajaxvote.php'; $model = new MijopollsModelAjaxvote(); $vote = $model->getVoted(); $data = $model->getData(); $total = $model->getTotal(); $poll_id = JRequest::getInt('id', 0, 'post'); if (MijopollsHelper::is15()) { // create root node $xml = new JSimpleXMLElement('poll', array('id' => $poll_id)); //get total votes $sum = 0; foreach ($data as $row) { $sum += $row->votes; } $number_voters = 0; $options = $xml->addChild('options'); for ($i = 0; $i < $total; $i++) { $option = $options->addChild('option', array('id' => $data[$i]->id, 'percentage' => self::_toPercent($data[$i]->votes, $sum), 'votes' => $data[$i]->votes, 'color' => $data[$i]->color)); $text = $option->addChild('text'); $text->setData($data[$i]->text); $number_voters += $data[$i]->votes; } $voters = $xml->addChild('voters'); $voters->setData($number_voters); $this->assign('xml', $xml->toString()); } else { // create root node $xml = new JXMLElement('<poll></poll>'); $xml->addAttribute('id', $poll_id); //get total votes $sum = 0; foreach ($data as $row) { $sum += $row->votes; } $number_voters = 0; $options = $xml->addChild('options'); for ($i = 0; $i < $total; $i++) { $option = $options->addChild('option'); $option->addAttribute('id', $data[$i]->id); $option->addAttribute('percentage', self::_toPercent($data[$i]->votes, $sum)); $option->addAttribute('color', $data[$i]->color); $option->addChild('text', $data[$i]->text); $number_voters += $data[$i]->votes; } $xml->addChild('voters', $number_voters); $this->assign('xml', $xml->asFormattedXML()); } $this->setLayout('raw'); parent::display($tpl); }
function display($tpl = null) { $this->mainframe = JFactory::getApplication(); $db =& JFactory::getDBO(); $user =& JFactory::getUser(); $date =& JFactory::getDate(); $document =& JFactory::getDocument(); $pathway =& $this->mainframe->getPathway(); $poll_id = JRequest::getInt('id', 0); $poll =& JTable::getInstance('Poll', 'Table'); $poll->load($poll_id); // if id value is passed and poll not published then exit if ($poll->id > 0 && $poll->published != 1) { JError::raiseError(403, JText::_('Access Forbidden')); return; } if (MijopollsHelper::is15()) { // Adds parameter handling $params =& $this->mainframe->getParams(); $pollParams = new JParameter($poll->params); $params->merge($pollParams, $params); //Set page title information $menus =& JSite::getMenu(); $menu = $menus->getActive(); // because the application sets a default page title, we need to get it // right from the menu item itself if (is_object($menu)) { $menu_params = new JParameter($menu->params); if (!$menu_params->get('page_title')) { $params->set('page_title', $poll->title); } } else { $params->set('page_title', $poll->title); } } else { // Adds parameter handling $temp = new JRegistry($poll->params); $params = clone $this->mainframe->getParams(); $params->merge($temp); //Set page title information $menu = JSite::getMenu()->getActive(); // because the application sets a default page title, we need to get it // right from the menu item itself if (is_object($menu)) { $menu_params = new JRegistry($menu->params); if (!$menu_params->get('page_title')) { $params->set('page_title', $poll->title); } else { $params->set('page_title', $menu_params->get('page_title')); } } else { $params->set('page_title', $poll->title); } } $document->setTitle($params->get('page_title')); //Set pathway information $pathway->addItem($poll->title, ''); $params->def('show_page_title', 1); $params->def('page_title', $poll->title); // Check if there is a poll corresponding to id and if poll is published if ($poll->id > 0) { if (empty($poll->title)) { $poll->id = 0; $poll->title = JText::_('COM_MIJOPOLLS_SELECT_POLL'); } //get the array of options $options =& $this->get('Options'); } else { $options = array(); } // list of polls for dropdown selection $pList = $this->get('Polls'); foreach ($pList as $k => $p) { $pList[$k]->url = JRoute::_('index.php?option=com_mijopolls&view=poll&id=' . $p->slug); } array_unshift($pList, JHTML::_('select.option', '', JText::_('COM_MIJOPOLLS_SELECT_POLL'), 'url', 'title')); // dropdown output $lists = array(); $lists['polls'] = JHTML::_('select.genericlist', $pList, 'id', 'class="inputbox" size="1" style="width:400px" onchange="if (this.options[selectedIndex].value != \'\') {document.location.href=this.options[selectedIndex].value}"', 'url', 'title', JRoute::_('index.php?option=com_mijopolls&view=poll&id=' . $poll->id . ':' . $poll->alias)); //get the number of voters $voters = isset($options[0]) ? $options[0]->voters : 0; $num_of_options = count($options); for ($i = 0; $i < $num_of_options; $i++) { $vote =& $options[$i]; //assign pie color to colors array $colors[$i] = $vote->color; //$links[$i]=$vote->link; if ($voters > 0) { $vote->percent = round(100 * $vote->hits / $voters, 1); } else { //if nobody has voted yet if ($params->get('show_what') == 1) { $vote->percent = round(100 / $num_of_options, 1); } else { $vote->percent = 0; } } } // show_what==1 because 1=show pie, 0=joomla default, 3 may be something else later //Pie chart // pass in two arrays, one of data, the other data labels $title_lenght = $params->get('title_lenght'); foreach ($options as $vote_array) { //if show hits is true if ($params->get('show_hits')) { $hits = " (" . $vote_array->hits . ")"; } else { $hits = ''; } //if show options with zero votes is true if ($params->get('show_zero_votes')) { $text = JString::substr(html_entity_decode($vote_array->text, ENT_QUOTES, "utf-8"), 0, $title_lenght) . $hits; //$values[] = array("value" => $vote_array->percent, "label" => $text, "text" => $text); $values[] = ' "value":' . $vote_array->percent . ', "label":"' . addslashes($text) . '", "text":"' . addslashes($text) . '" '; } else { //show only options that have hits if ($vote_array->percent) { $text = JString::substr(html_entity_decode($vote_array->text, ENT_QUOTES, "utf-8"), 0, $title_lenght) . $hits; //$values[] = array("value" => $vote_array->percent, "label" => $text, "text" => $text); $values[] = ' "value":' . $vote_array->percent . ', "label":"' . addslashes($text) . '", "text":"' . addslashes($text) . '" '; } } } // prepare the javascript for the pie //colors and values array to json //TODO use json_encode some day $json_colors = '["' . implode('", "', $colors) . '"]'; $json_values = '[{' . implode('}, {', $values) . '}]'; $js = ' function ofc_ready() {} function open_flash_chart_data() { return JSON.stringify(data); } var data = { "title":{ "text" : "", "style" : "font-size: 14px; font-family: Verdana; text-align: center;" }, "bg_colour" : "#' . $params->get("bg_color") . '", "elements" : [{ "type" : "pie", "tip" : "#label# \\n#val#%", "colours" : ' . $json_colors . ', "alpha" : ' . $params->get("opacity") . ', "start-angle" : ' . $params->get("start_angle") . ', "radius" : ' . $params->get("radius") . ', "no-labels" : ' . $params->get("no_labels") . ', "values" : ' . $json_values . ', "gradient-fill" : ' . $params->get("gradient") . ', "font-size" : ' . $params->get("font_size") . ', "label-colour" : "#' . $params->get("font_color") . '", "animate":[{ "distance" : ' . $params->get("bounce_dinstance") . ', "type" : "' . $params->get("animation_type") . '" }] }] }; '; //Check if the user has voted if (MijopollsHelper::is15()) { $cookieName = JUtility::getHash($this->mainframe->getName() . 'poll' . $poll_id); } else { $cookieName = JApplication::getHash($this->mainframe->getName() . 'poll' . $poll_id); } $cookieVoted = JRequest::getVar($cookieName, '0', 'COOKIE', 'INT'); $query = "SELECT date FROM #__mijopolls_votes WHERE poll_id=" . (int) $poll_id . " AND user_id=" . (int) $user->id; $db->setQuery($query); $userVoted = $db->loadResult() ? 1 : 0; $ip = ip2long($_SERVER['REMOTE_ADDR']); $query = "SELECT ip FROM #__mijopolls_votes WHERE poll_id=" . (int) $poll_id . " AND ip = '" . $ip . "'"; $db->setQuery($query); $ipVoted = $db->loadResult() ? 1 : 0; //$date->setOffset($this->mainframe->getCfg('offset')); if (MijopollsHelper::is15()) { $now = $date->toFormat(); } else { $now = $date->toSql(); } //Algorithm for shoiwing or not the poll in the component if ($params->get('allow_voting')) { if ($now > $poll->publish_up && $now < $poll->publish_down) { if ($params->get('only_registered')) { if (!$user->guest) { if ($params->get('one_vote_per_user')) { if ($userVoted) { $allowToVote = 0; $msg = JText::_('COM_MIJOPOLLS_ALREADY_VOTED'); } else { $allowToVote = 1; } } else { if ($cookieVoted) { $allowToVote = 0; $msg = JText::_('COM_MIJOPOLLS_ALREADY_VOTED'); } else { $allowToVote = 1; } } } else { $allowToVote = 0; $return = JRequest::getURI(); $return = base64_encode($return); $user_option = MijopollsHelper::is15() ? 'com_user' : 'com_users'; $link = 'index.php?option=' . $user_option . '&view=login&return=' . $return; $msg = JText::sprintf('COM_MIJOPOLLS_REGISTER_TO_VOTE', '<a href="' . $link . '">', '</a>'); } } else { if ($cookieVoted) { $allowToVote = 0; $msg = JText::_('COM_MIJOPOLLS_ALREADY_VOTED'); } else { if ($params->get('ip_check')) { if ($ipVoted) { $allowToVote = 0; $msg = JText::_('COM_MIJOPOLLS_ALREADY_VOTED'); } else { $allowToVote = 1; } } else { $allowToVote = 1; } } } } else { $allowToVote = 0; } if ($now < $poll->publish_up) { $msg = JText::_('COM_MIJOPOLLS_VOTE_NOT_STARTED'); } if ($now > $poll->publish_down) { $msg = JText::_('COM_MIJOPOLLS_VOTE_ENDED'); } } else { $allowToVote = 0; } $this->lists = $lists; $this->params = $params; $this->poll = $poll; $this->options = $options; $this->allowToVote = $allowToVote; $this->msg = $msg; $this->js = $js; if (MijopollsHelper::is30()) { $tpl = '30'; } parent::display($tpl); }