diff --git a/oss/joomla/trunk/components/com_apoll/apoll.php b/oss/joomla/trunk/components/com_apoll/apoll.php new file mode 100644 index 00000000..68778aaf --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/apoll.php @@ -0,0 +1,49 @@ +registerTask( 'results', 'display' ); + +// Perform the Request task +$controller->execute(JRequest::getCmd('task')); + +// Redirect if set by the controller +$controller->redirect(); + +?> \ No newline at end of file diff --git a/oss/joomla/trunk/components/com_apoll/controller.php b/oss/joomla/trunk/components/com_apoll/controller.php new file mode 100644 index 00000000..cdc1d56b --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/controller.php @@ -0,0 +1,100 @@ + + * @package Joomla + * @subpackage Poll + * @since 1.5 + */ +class ApollController extends JController +{ + function display() + { + + //Set the default view, just in case + $view = JRequest::getCmd('view'); + if(empty($view)) { + JRequest::setVar('view', 'apolls'); + }; + parent::display(); + } + + /** + * Add a vote to an option + */ + function vote() + { + global $mainframe; + + // Check for request forgeries + JRequest::checkToken() or jexit( 'Invalid Token' ); + + $db =& JFactory::getDBO(); + $apoll_id = JRequest::getVar( 'id', 0, '', 'int' ); + $option_id = JRequest::getVar( 'voteid', 0, 'post', 'int' ); + $apoll =& JTable::getInstance('apoll','Table'); + if (!$apoll->load( $apoll_id ) || $apoll->published != 1) { + JError::raiseWarning( 404, JText::_('ALERTNOTAUTH') ); + return; + } + + $cookieName = JUtility::getHash( $mainframe->getName() . 'apoll' . $apoll_id ); + $voted = JRequest::getVar( $cookieName, '0', 'COOKIE', 'INT'); + + if ($voted || !$option_id ) + { + if($voted) { + $msg = JText::_('You already voted for this poll!'); + $tom = "error"; + } + + if(!$option_id){ + $msg = JText::_('WARNSELECT'); + $tom = "error"; + } + } + else + { + require_once(JPATH_COMPONENT.DS.'models'.DS.'apoll.php'); + $model = new ApollModelApoll(); + if ( $model->vote( $apoll_id, $option_id )) { + //Set cookie showing that user has voted + setcookie( $cookieName, '1', time() + 60*$apoll->lag ); + } + + $msg = JText::_( 'Thanks for your vote!' ); + $tom = ""; + } + + // set Itemid id for links + $menu = &JSite::getMenu(); + $items = $menu->getItems('link', 'index.php?option=com_apoll&view=apoll'); + + $itemid = isset($items[0]) ? '&Itemid='.$items[0]->id : ''; + + $this->setRedirect( JRoute::_('index.php?option=com_apoll&view=apoll&id='. $apoll_id.':'.$apoll->alias.$itemid, false), $msg, $tom); + } +} +?> \ No newline at end of file diff --git a/oss/joomla/trunk/components/com_apoll/index.html b/oss/joomla/trunk/components/com_apoll/index.html new file mode 100644 index 00000000..fa6d84e8 --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/oss/joomla/trunk/components/com_apoll/models/ajaxvote.php b/oss/joomla/trunk/components/com_apoll/models/ajaxvote.php new file mode 100644 index 00000000..50c719e5 --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/models/ajaxvote.php @@ -0,0 +1,113 @@ +load( $apoll_id ) || $apoll->published != 1) { + JError::raiseWarning( 404, JText::_('ALERTNOTAUTH') ); + return; + } + + $cookieName = JUtility::getHash( $mainframe->getName() . 'apoll' . $apoll_id ); + $voted = JRequest::getVar( $cookieName, '0', 'COOKIE', 'INT'); + + if ($voted || !$option_id ) + { + if($voted) { + $msg = JText::_('You already voted for this poll!'); + $tom = "error"; + } + if(!$option_id){ + $msg = JText::_('WARNSELECT'); + $tom = "error"; + } + $this->_voted = 0; + } + else + { + require_once(JPATH_COMPONENT.DS.'models'.DS.'apoll.php'); + $model = new ApollModelApoll(); + if($model->vote( $apoll_id, $option_id )) { + $this->_voted = 1; + //Set cookie showing that user has voted + setcookie( $cookieName, '1', time() + 60*$apoll->lag ); + } else { + $this->_voted = 0; + } + } + return $this->_voted = 1; + } + + function getData() + { + // Lets load the content if it doesn't already exist + if (empty($this->_data)) + { + $query = $this->_buildQuery(); + $this->_data = $this->_getList($query); + } + return $this->_data; + } + + function getTotal() + { + if (empty($this->_total)) + { + $db =& JFactory::getDBO(); + $query = $this->_buildQuery(); + $this->_total = $this->_getListCount($query); + } + return $this->_total; + } + + function _buildQuery() + { + $db =& JFactory::getDBO(); + $apoll_id = JRequest::getVar( 'id', 0, 'POST', 'int' ); + $query = "SELECT o.id, o.text, o.color, COUNT(v.id) AS votes" + ." FROM ".$db->nameQuote('#__apoll_options')." AS o " + ." LEFT JOIN ".$db->nameQuote('#__apoll_votes')." AS v " + ." ON o.id = v.option_id " + ." WHERE o.apoll_id=".(int)$apoll_id + ." GROUP BY o.id " + ; + return $query; + } +} +?> diff --git a/oss/joomla/trunk/components/com_apoll/models/apoll.php b/oss/joomla/trunk/components/com_apoll/models/apoll.php new file mode 100644 index 00000000..556673ef --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/models/apoll.php @@ -0,0 +1,101 @@ +getDBO(); + $apoll_id = (int) $apoll_id; + $option_id = (int) $option_id; + + $date = &JFactory::getDate(); + $date->setOffset($mainframe->getCfg('offset')); + $ip = $_SERVER['REMOTE_ADDR']; + $user =& JFactory::getUser(); + + $query = "INSERT INTO ".$db->nameQuote('#__apoll_votes')." + SET date = ".$db->Quote($date->toFormat()).", + option_id = ".(int) $option_id.", + apoll_id = ".(int) $apoll_id.", + ip = INET_ATON('".$ip."')".", + user_id =".$user->id; + + //Save the vote to the database + $db->setQuery( $query ); + if(!$db->query()) { + $msg = $db->stderr(); + $tom = "error"; + } + return true; + } + function getOptions() { + $db = $this->getDBO(); + $apoll_id = JRequest::getInt('id', 0); + + $query = "SELECT o.*, COUNT(v.id) AS hits, + (SELECT COUNT(id) FROM ".$db->nameQuote('#__apoll_votes')." WHERE apoll_id=".$apoll_id.") AS voters" + ." FROM ".$db->nameQuote('#__apoll_options')." AS o" + ." LEFT JOIN ".$db->nameQuote('#__apoll_votes')." AS v" + ." ON (o.id = v.option_id AND v.apoll_id = " . $apoll_id . ")" + ." WHERE o.apoll_id = ". $apoll_id + ." AND o.text <> ''" + ." GROUP BY o.id " + ." ORDER BY o.ordering " + ; + + $db->setQuery( $query ); + if($votes = $db->loadObjectList()) { + return $votes; + } else { + return $db->stderr(); + } + + } + + function getApolls() { + $db = $this->getDBO(); + + $query = "SELECT id, title, CASE WHEN CHAR_LENGTH(alias) THEN CONCAT_WS(':', id, alias) ELSE id END AS slug + FROM ".$db->nameQuote('#__apoll_polls')." + WHERE published = 1 + ORDER BY id"; + + $db->setQuery( $query ); + + if($pList = $db->loadObjectList()) { + return $pList; + } else { + return $db->stderr(); + } + } +} +?> \ No newline at end of file diff --git a/oss/joomla/trunk/components/com_apoll/models/apolls.php b/oss/joomla/trunk/components/com_apoll/models/apolls.php new file mode 100644 index 00000000..c6eb84ae --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/models/apolls.php @@ -0,0 +1,177 @@ +setState('limit', $mainframe->getUserStateFromRequest('com_apoll.limit', 'limit', $config->getValue('config.list_limit'), 'int')); + $this->setState('limitstart', JRequest::getVar('limitstart', 0, '', 'int')); + + // In case limit has been changed, adjust limitstart accordingly + $this->setState('limitstart', ($this->getState('limit') != 0 ? (floor($this->getState('limitstart') / $this->getState('limit')) * $this->getState('limit')) : 0)); + + // Get the filter request variables + $this->setState('filter_order', JRequest::getCmd('filter_order', 'ordering')); + $this->setState('filter_order_dir', JRequest::getCmd('filter_order_Dir', 'ASC')); + + } + /** + * Method to get poll item data + * + * @access public + * @return array + */ + function getData() + { + // Lets load the content if it doesn't already exist + if (empty($this->_data)) + { + $query = $this->_buildQuery(); + $this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit')); + } + + return $this->_data; + } + /** + * Method to get the total number of weblink items + * + * @access public + * @return integer + */ + function getTotal() + { + // Lets load the content if it doesn't already exist + if (empty($this->_total)) + { + $query = $this->_buildQuery(); + $this->_total = $this->_getListCount($query); + } + + return $this->_total; + } + + /** + * Method to get a pagination object for the weblinks + * + * @access public + * @return integer + */ + function getPagination() + { + // Lets load the content if it doesn't already exist + if (empty($this->_pagination)) + { + jimport('joomla.html.pagination'); + $this->_pagination = new JPagination( $this->getTotal(), $this->getState('limitstart'), $this->getState('limit') ); + } + + return $this->_pagination; + } + function _buildQuery() + { + $where = $this->_buildContentWhere(); + $orderby = $this->_buildContentOrderBy(); + $db =& JFactory::getDBO(); + $query = "SELECT m.*, + CASE WHEN CHAR_LENGTH(m.alias) THEN CONCAT_WS(':', m.id, m.alias) ELSE m.id END as slug, + CASE WHEN publish_down>NOW() THEN 'active' ELSE 'ended' END AS status," + . " (SELECT COUNT(v.id) FROM ".$db->nameQuote('#__apoll_votes')." AS v WHERE v.apoll_id = m.id) AS voters," . " COUNT(o.id) AS numoptions " + . " FROM ".$db->nameQuote('#__apoll_polls') ." AS m " + . " LEFT JOIN ".$db->nameQuote('#__apoll_options')." AS o " + . " ON o.apoll_id = m.id " + . " WHERE m.published=1 AND o.text <> ''" + . $where + . " GROUP BY m.id" + . $orderby + ; + + return $query; + } + function _buildContentOrderBy() + { + global $mainframe, $option; + + $filter_order = $mainframe->getUserStateFromRequest( "$option.filter_order.apolls", 'filter_order', 'm.id', 'cmd' ); + $filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.filter_order_Dir.apolls", 'filter_order_Dir', '', 'word' ); + + $orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir; + + return $orderby; + } + + function _buildContentWhere() + { + global $mainframe, $option; + $db =& JFactory::getDBO(); + $filter_order = $mainframe->getUserStateFromRequest( "$option.filter_order.apolls", 'filter_order', 'm.id', 'cmd' ); + $filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.filter_order_Dir.apolls", 'filter_order_Dir', '', 'word' ); + $search = $mainframe->getUserStateFromRequest( "$option.search.apolls",'search','','string'); + + $where = array(); + + if ($search) + { + $search = JString::strtolower( $search ); + $where[] = 'LOWER(m.title) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false ); + } + + $where = ( count( $where ) ? ' AND '. implode( ' AND ', $where ) : '' ); + + return $where; + } +} +?> diff --git a/oss/joomla/trunk/components/com_apoll/models/index.html b/oss/joomla/trunk/components/com_apoll/models/index.html new file mode 100644 index 00000000..fa6d84e8 --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/models/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/oss/joomla/trunk/components/com_apoll/router.php b/oss/joomla/trunk/components/com_apoll/router.php new file mode 100644 index 00000000..9a2fa7ca --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/router.php @@ -0,0 +1,148 @@ +getItems('componentid', $component->id); + } + + // Search for an appropriate menu item. + // First we will search for menu item linking to this poll, + // if we can't find we will look for a menu item linking to the apolls view. + + if (is_array($items)) + { + // If only the option and itemid are specified in the query, return that item. + if (!isset($query['view']) && !isset($query['id']) && isset($query['Itemid'])) { + $itemid = (int) $query['Itemid']; + } + + // Search for a menu that links to the same view and id + if (!$itemid) { + foreach ($items as $item) + { + // Check if this menu item links to this view. + // menu-view must be equal to the query-view + // also menu-id must be equal to the query-id + if (isset($item->query['view']) && isset($query['view']) + && $item->query['view'] == $query['view'] + && isset($item->query['id']) + && $item->query['id'] == $query['id']) + { + $itemid = $item->id; + + } + } + } + + // If no specific link has been found, search for a general one. + // Search for a menu linking to apolls view + if (!$itemid) { + foreach ($items as $item) + { + if (isset($query['view']) && $query['view'] == 'apoll' && isset($item->query['view']) && $item->query['view'] == 'apolls') + { + // Check for an undealt with poll id. + if (isset($query['id'])) + { + // This menu item links to the apolls view but we need to append the poll id to it. + $itemid = $item->id; + $segments[] = isset($query['alias']) ? $query['id'].':'.$query['alias'] : $query['id']; + break; + } + } + } + } + } + + // Check if the router found an appropriate itemid. + if (!$itemid) + { + //if item id was not found that means that there is no link to either apolls view or apoll view + // Check if a id was specified. + if (isset($query['id'])) + { + if (isset($query['alias'])) { + $query['id'] .= ':'.$query['alias']; + } + + // Push the id onto the stack. + $segments[] = 'apoll'; + $segments[] = $query['id']; + + unset($query['id']); + unset($query['alias']); + } + unset($query['view']); + } + else + { + $query['Itemid'] = $itemid; + + // Remove the unnecessary URL segments. + unset($query['view']); + unset($query['id']); + unset($query['alias']); + } + //print_r($segments); exit; + return $segments; +} + +/** + * @param array + * @return array + */ +function ApollParseRoute( $segments ) +{ + $vars = array(); + + //Get the active menu item if there is a menu link to apolls view + $menu =& JSite::getMenu(); + $item =& $menu->getActive(); + // Count route segments + $count = count( $segments ); + + //if item is not set, there is no menu linking to this view - apoll + if(!isset($item)) + { + $vars['view'] = 'apoll'; + $vars['id'] = $segments[$count - 1]; + return $vars; + } + //if there is a menu to apolls view -> + $vars['view'] = 'apoll'; + $vars['id'] = $segments[$count-1]; + + return $vars; +} \ No newline at end of file diff --git a/oss/joomla/trunk/components/com_apoll/views/apoll/index.html b/oss/joomla/trunk/components/com_apoll/views/apoll/index.html new file mode 100644 index 00000000..fa6d84e8 --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/views/apoll/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/oss/joomla/trunk/components/com_apoll/views/apoll/metadata.xml b/oss/joomla/trunk/components/com_apoll/views/apoll/metadata.xml new file mode 100644 index 00000000..8deb646d --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/views/apoll/metadata.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/default.php b/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/default.php new file mode 100644 index 00000000..2bc8bb34 --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/default.php @@ -0,0 +1,125 @@ + + + +params->get( 'show_title', 1)) : ?> +
+ escape($this->params->get('page_title')); ?> +
+ + +
+ +allowToVote) : ?> +
+
+ options as $option) : ?> + + id : ''; ?> + +
+ +
+ + + + + + +
+
+
+ +params->get('show_component_msg')) : + echo "

".JText::_($this->msg)."

"; + endif; + endif; ?> + +params->get('show_dropdown')) : ?> +
+
+ +
+
+ +
+: +
+
+params->get('show_what')) : + echo $this->loadTemplate('chart'); + else : + echo $this->loadTemplate('pie'); + endif; +?> +
+ + + params->get('show_voters')) : ?> + + + + + + + params->get('show_times')) : ?> + + + + + + + + + + +
+ + +  :  + options[0])) echo $this->options[0]->voters; ?> +
+ + +  :  + apoll->publish_up; ?> +
+ + +  :  + apoll->publish_down; ?> +
+
+
\ No newline at end of file diff --git a/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/default.xml b/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/default.xml new file mode 100644 index 00000000..abc32fac --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/default.xml @@ -0,0 +1,17 @@ + + + + + + + + + Single Poll Layout + STANDARD POLL LAYOUT DESC + + + + + + + diff --git a/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/default_chart.php b/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/default_chart.php new file mode 100644 index 00000000..a25f41e5 --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/default_chart.php @@ -0,0 +1,42 @@ + + + +options as $option) : ?> + + + + + + + + + +
+ text; ?> +
+ params->get('show_hits')) { ?> + hits; ?> + + +
+
percent; ?>% 
+
\ No newline at end of file diff --git a/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/default_pie.php b/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/default_pie.php new file mode 100644 index 00000000..dcf0dde5 --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/default_pie.php @@ -0,0 +1,38 @@ +addScriptDeclaration($this->js); +$document->addScript(JURI::base().'media/system/js/json.js'); +?> +
+ + + + + + + + +

No Flash Player Installed

+ +
+ +
+
\ No newline at end of file diff --git a/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/index.html b/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/index.html new file mode 100644 index 00000000..fa6d84e8 --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/raw.php b/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/raw.php new file mode 100644 index 00000000..d988a06c --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/raw.php @@ -0,0 +1,23 @@ +setMimeEncoding('text/xml'); + +echo ''."\n"; +echo $this->xml; \ No newline at end of file diff --git a/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/raw.xml b/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/raw.xml new file mode 100644 index 00000000..26bff6d9 --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/views/apoll/tmpl/raw.xml @@ -0,0 +1,4 @@ + + + \ No newline at end of file diff --git a/oss/joomla/trunk/components/com_apoll/views/apoll/view.html.php b/oss/joomla/trunk/components/com_apoll/views/apoll/view.html.php new file mode 100644 index 00000000..9119fc07 --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/views/apoll/view.html.php @@ -0,0 +1,292 @@ +getPathway(); + + $apoll_id = JRequest::getInt('id', 0); + + $apoll =& JTable::getInstance('apoll', 'Table'); + $apoll->load( $apoll_id ); + + // if id value is passed and apoll not published then exit + if ($apoll->id > 0 && $apoll->published != 1) { + JError::raiseError( 403, JText::_('Access Forbidden') ); + return; + } + + // Adds parameter handling + $params =& $mainframe->getParams(); + $apollParams = new JParameter($apoll->params); + $params->merge($apollParams, $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', $apoll->title); + } + } else { + $params->set('page_title', $apoll->title); + } + $document->setTitle( $params->get( 'page_title' ) ); + + //Set pathway information + $pathway->addItem($apoll->title, ''); + + $params->def( 'show_page_title', 1 ); + $params->def( 'page_title', $apoll->title ); + + + + // Check if there is a apoll corresponding to id and if apoll is published + if ($apoll->id > 0) { + if (empty( $apoll->title )) { + $apoll->id = 0; + $apoll->title = JText::_( 'Select poll from the list' ); + } + //get the array of options + $options =& $this->get('Options'); + + } else { + $options = array(); + } + + // list of apolls for dropdown selection + $pList = $this->get('Apolls'); + + foreach ($pList as $k=>$p) { + $pList[$k]->url = JRoute::_('index.php?option=com_apoll&view=apoll&id='.$p->slug); + } + + array_unshift( $pList, JHTML::_('select.option', '', JText::_( 'Select Poll from the list' ), 'url', 'title' )); + + // dropdown output + $lists = array(); + + $lists['apolls'] = 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_apoll&view=apoll&id='.$apoll->id.':'.$apoll->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 + $cookieName = JUtility::getHash( $mainframe->getName() . 'apoll' . $apoll_id ); + $cookieVoted= JRequest::getVar( $cookieName, '0', 'COOKIE', 'INT'); + $user =& JFactory::getUser(); + $query = "SELECT date FROM ".$db->nameQuote('#__apoll_votes') + ." WHERE apoll_id=".(int)$apoll_id + ." AND user_id=".(int)$user->id + ; + $db->setQuery($query); + $userVoted =($db->loadResult())?1:0; + $ip = $_SERVER['REMOTE_ADDR']; + $query = "SELECT ip FROM ".$db->nameQuote('#__apoll_votes') + ." WHERE apoll_id=".(int) $apoll_id + ." AND ip = INET_ATON('".$ip."')"; + $db->setQuery($query); + $ipVoted = ($db->loadResult())?1:0; + + $date = &JFactory::getDate(); + $date->setOffset($mainframe->getCfg('offset')); + $now = $date->toFormat(); + + //Algorithm for shoiwing or not the poll in the component + if ($params->get('allow_voting')) { + if(($now>$apoll->publish_up) && ($now<$apoll->publish_down)) { + if ($params->get('only_registered')) { + if (!$user->guest) { + if($params->get('one_vote_per_user')) { + if ($userVoted) { + $allowToVote = 0; + $msg = "You have already voted"; + } else { + $allowToVote = 1; + } + } else { + if ($cookieVoted) { + $allowToVote = 0; + $msg = "You have already voted"; + } else { + $allowToVote = 1; + } + } + } else { + $allowToVote = 0; + $msg = "Please register to vote"; + } + } else { + if ($cookieVoted) { + $allowToVote = 0; + $msg = "You have already voted"; + } else { + if ($params->get('ip_check')) { + if($ipVoted) { + $allowToVote = 0; + $msg = "You have already voted"; + } else { + $allowToVote = 1; + } + } else { + $allowToVote = 1; + } + } + } + } else { + $allowToVote = 0; + } + + if($now<$apoll->publish_up) { + $msg = "Voting for this poll has not started yet"; + } + if($now>$apoll->publish_down) { + $msg = "Voting for this poll has ended."; + } + } else { + $allowToVote = 0; + } + + + $this->assignRef('lists', $lists); + $this->assignRef('params', $params); + $this->assignRef('apoll', $apoll); + $this->assignRef('options', $options); + $this->assignRef('allowToVote', $allowToVote); + $this->assignRef('msg', $msg); + $this->assignRef('js', $js); + + parent::display($tpl); + } +} +?> diff --git a/oss/joomla/trunk/components/com_apoll/views/apoll/view.raw.php b/oss/joomla/trunk/components/com_apoll/views/apoll/view.raw.php new file mode 100644 index 00000000..bcce5baf --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/views/apoll/view.raw.php @@ -0,0 +1,80 @@ +getVoted(); + $data = $model->getData(); + $total = $model->getTotal(); + + //print_r($data); exit; + $apoll_id = JRequest::getVar( 'id', 0, 'POST', 'int' ); + + // import library + jimport('joomla.utilities.simplexml'); + // create root node + $xml = new JSimpleXMLElement('apoll', array('id' => $apoll_id)); + // add children + + //get total votes + $sum = 0; + foreach ($data as $row) + { + $sum += $row->votes; + } + + $number_voters = 0; + + $options =& $xml->addChild('options'); + + function toPercent($val, $sum) { + return round($val*100/$sum, 1); + } + for($i=0; $i<$total; $i++) + { + $option =& $options->addChild('option', + array('id'=>$data[$i]->id, 'percentage'=>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()); + $this->setLayout('raw'); + parent::display($tpl); + } +} \ No newline at end of file diff --git a/oss/joomla/trunk/components/com_apoll/views/apolls/index.html b/oss/joomla/trunk/components/com_apoll/views/apolls/index.html new file mode 100644 index 00000000..fa6d84e8 --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/views/apolls/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/oss/joomla/trunk/components/com_apoll/views/apolls/tmpl/default.php b/oss/joomla/trunk/components/com_apoll/views/apolls/tmpl/default.php new file mode 100644 index 00000000..f6e2ec21 --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/views/apolls/tmpl/default.php @@ -0,0 +1,148 @@ + + + +

params->get('page_title'); ?>

+
+ + + + + +
+ params->get('show_filter_box')) : + echo JText::_( 'Filter' ); ?>: + + + + + + pagination->getLimitBox(); + ?> +
+ + + + + + params->get('show_start_date')) { ?> + + params->get('show_end_date')) { ?> + + params->get('show_status')) { ?> + + params->get('show_num_voters')) { ?> + + params->get('show_num_options')) { ?> + + + + + + items ); $i < $n; $i++) + { + $row = &$this->items[$i]; + //find the Itemid that correspondents to the link if any. + $component =& JComponentHelper::getComponent('com_apoll'); + $menus =& JApplication::getMenu('site', array()); + $menu_items = $menus->getItems('componentid', $component->id); + $itemid = null; + + if (isset($menu_items)) { + foreach ($menu_items as $item) { + if ((@$item->query['view'] == 'apoll') && (@$item->query['id'] == $row->id)) { + $itemid = '&Itemid='.$item->id; + break; + } + } + } + $link = JRoute::_( 'index.php?option=com_apoll&view=apoll&id='.$row->slug.$itemid); + + ?> + + + + params->get('show_start_date')) { ?> + + + params->get('show_end_date')) { ?> + + + params->get('show_status')) { ?> + + params->get('show_num_voters')) { ?> + + + params->get('show_num_options')) { ?> + + + + + +
+ + + lists['order_Dir'], @$this->lists['order'] ); ?> + + lists['order_Dir'], @$this->lists['order'] ); ?> + + lists['order_Dir'], @$this->lists['order'] ); ?> + + lists['order_Dir'], @$this->lists['order'] ); ?> + + lists['order_Dir'], @$this->lists['order'] ); ?> + + lists['order_Dir'], @$this->lists['order'] ); ?> +
pagination->getRowOffset($i); ?> + title; ?>publish_up)->toFormat($this->params->get('date_format')) +; ?>publish_down)->toFormat($this->params->get('date_format')) +; ?> + params->get('show_status_as')) { ?> + + status); + } ?>voters; ?>numoptions; ?>
+ +
+ pagination->getPagesLinks(); ?> +
+
+ pagination->getPagesCounter(); ?> +
+ + + + +
+
\ No newline at end of file diff --git a/oss/joomla/trunk/components/com_apoll/views/apolls/tmpl/default.xml b/oss/joomla/trunk/components/com_apoll/views/apolls/tmpl/default.xml new file mode 100644 index 00000000..7c291a2f --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/views/apolls/tmpl/default.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/oss/joomla/trunk/components/com_apoll/views/apolls/tmpl/index.html b/oss/joomla/trunk/components/com_apoll/views/apolls/tmpl/index.html new file mode 100644 index 00000000..fa6d84e8 --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/views/apolls/tmpl/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/oss/joomla/trunk/components/com_apoll/views/apolls/view.html.php b/oss/joomla/trunk/components/com_apoll/views/apolls/view.html.php new file mode 100644 index 00000000..85112ad7 --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/views/apolls/view.html.php @@ -0,0 +1,63 @@ +getUserStateFromRequest( "$option.filter_order.apolls", 'filter_order', 'm.id', 'cmd' ); + $filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.filter_order_Dir.apolls", 'filter_order_Dir', '', 'word' ); + $search = $mainframe->getUserStateFromRequest( "$option.search.apolls",'search','','string'); + + // Get data from the model + $items =& $this->get( 'Data'); + $total =& $this->get( 'Total'); + $pagination =& $this->get( 'Pagination' ); + // table ordering + $lists['order_Dir'] = $filter_order_Dir; + $lists['order'] = $filter_order; + + // search filter + $lists['search'] = $search; + // get menu params + $params =& $mainframe->getParams(); + + $this->assignRef('lists', $lists); + $this->assignRef('items', $items); + $this->assignRef('params', $params); + $this->assignRef('pagination', $pagination); + $this->assignRef('action', $uri->toString()); + + parent::display($tpl); + } +} \ No newline at end of file diff --git a/oss/joomla/trunk/components/com_apoll/views/index.html b/oss/joomla/trunk/components/com_apoll/views/index.html new file mode 100644 index 00000000..fa6d84e8 --- /dev/null +++ b/oss/joomla/trunk/components/com_apoll/views/index.html @@ -0,0 +1 @@ + \ No newline at end of file