| [ Index ] | PHP Cross Reference of Mambo 4.6.5 |
|
| [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Mambo 4 * @author Mambo Foundation Inc see README.php 5 * @copyright (C) 2000 - 2009 Mambo Foundation Inc. 6 * See COPYRIGHT.php for copyright notices and details. 7 * @license GNU/GPL Version 2, see LICENSE.php 8 * 9 * Redistributions of files must retain the above copyright notice. 10 * 11 * Mambo is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU General Public License 13 * as published by the Free Software Foundation; version 2 of the License. 14 */ 15 16 /** ensure this file is being included by a parent file */ 17 defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); 18 19 require_once( $mainframe->getPath( 'front_html' ) ); 20 require_once( $mainframe->getPath( 'class' ) ); 21 22 $tabclass = 'sectiontableentry2,sectiontableentry1'; 23 $polls_graphwidth = 200; 24 $polls_barheight = 2; 25 $polls_maxcolors = 5; 26 $polls_barcolor = 0; 27 28 $poll = new mosPoll( $database ); 29 30 $id = intval( mosGetParam( $_REQUEST, 'id', 0 ) ); 31 $task = mosGetParam( $_REQUEST, 'task', '' ); 32 33 switch ($task) { 34 35 case 'vote': 36 pollAddVote( $id, $Itemid ); 37 break; 38 39 default: 40 pollresult( $id, $option, $task, $Itemid ); 41 break; 42 } 43 44 function pollAddVote( $uid, $Itemid ) { 45 global $database, $mosConfig_offset, $Itemid; 46 47 $redirect = 1; 48 49 $sessionCookieName = md5( 'site'.$GLOBALS['mosConfig_live_site'] ); 50 $sessioncookie = mosGetParam( $_REQUEST, $sessionCookieName, '' ); 51 52 if (!$sessioncookie) { 53 echo '<h3>'. T_('Cookies must be enabled!') .'"</h3>'; 54 echo '<input class="button" type="button" value="'. T_('Continue') .'" onClick="window.history.go(-1);">'; 55 return; 56 } 57 58 $poll = new mosPoll( $database ); 59 if (!$poll->load( $uid )) { 60 echo '<h3>'. T_('You are not authorized to view this resource.') .'</h3>'; 61 echo '<input class="button" type="button" value="'. T_('Continue') .'" onClick="window.history.go(-1);">'; 62 return; 63 } 64 65 $cookiename = "voted$poll->id"; 66 $voted = mosGetParam( $_COOKIE, $cookiename, '0' ); 67 68 if ($voted) { 69 echo "<h3>".T_('You already voted for this poll today!')."</h3>"; 70 echo "<input class=\"button\" type=\"button\" value=\"".T_('Continue')."\" onClick=\"window.history.go(-1);\">"; 71 return; 72 } 73 74 $voteid = mosGetParam( $_POST, 'voteid', 0 ); 75 if (!$voteid) { 76 echo "<h3>".T_('No selection has been made, please try again')."</h3>"; 77 echo '<input class="button" type="button" value="'. T_('Continue') .'" onClick="window.history.go(-1);">'; 78 return; 79 } 80 81 setcookie( $cookiename, '1', time()+$poll->lag ); 82 83 $database->setQuery( "UPDATE #__poll_data SET hits=hits + 1" 84 ."\n WHERE pollid='$poll->id' AND id='$voteid'"); 85 86 $database->query(); 87 88 $database->setQuery( "UPDATE #__polls SET voters=voters + 1" 89 ."\n WHERE id='$poll->id'"); 90 91 $database->query(); 92 93 $now = date("Y-m-d G:i:s"); 94 $database->setQuery( "INSERT INTO #__poll_date SET date='$now', vote_id='$voteid', poll_id='$poll->id'"); 95 96 $database->query(); 97 if ( $redirect ) { 98 mosRedirect( sefRelToAbs( 'index.php?option=com_poll&task=results&id='. $uid . ($Itemid?"&Itemid=$Itemid":'')), T_('Thanks for your vote!')); 99 } else { 100 echo '<h3>'. T_('Thanks for your vote!') .'</h3>'; 101 echo '<form action="" method="GET">'; 102 echo '<input class="button" type="button" value="'. T_('Results') .'" onClick="window.location=\''. sefRelToAbs( 'index.php?option=com_poll&task=results&id='. $uid . ($Itemid?"&Itemid=$Itemid":'')) .'\'">'; 103 echo '</form>'; 104 } 105 } 106 107 108 function pollresult( $uid, $option, $task, $Itemid ) { 109 global $database, $mosConfig_offset, $mosConfig_live_site; 110 global $mainframe; 111 112 $poll = new mosPoll( $database ); 113 $poll->load( $uid ); 114 115 if (empty($poll->title)) { 116 $poll->id = ''; 117 $poll->title = T_('Select Poll from the list'); 118 } 119 120 $first_vote = ''; 121 $last_vote = ''; 122 123 if (isset($poll->id) && $poll->id != "") { 124 $query = "SELECT MIN(date) AS mindate, MAX(date) AS maxdate" 125 ."\n FROM #__poll_date" 126 ."\n WHERE poll_id='$poll->id'" 127 ; 128 $database->setQuery( $query ); 129 130 $dates = $database->loadObjectList(); 131 132 if (isset($dates[0]->mindate)) { 133 $first_vote = mosFormatDate( $dates[0]->mindate, _DATE_FORMAT_LC2 ); 134 $last_vote = mosFormatDate( $dates[0]->maxdate, _DATE_FORMAT_LC2 ); 135 } 136 } 137 138 $query = "SELECT a.id, a.text, count( DISTINCT b.id ) AS hits, count( DISTINCT b.id )/COUNT( DISTINCT a.id )*100.0 AS percent" 139 . "\n FROM #__poll_data AS a" 140 . "\n LEFT JOIN #__poll_date AS b ON b.vote_id = a.id" 141 . "\n WHERE a.pollid='$poll->id' AND a.text <> ''" 142 . "\n GROUP BY a.id" 143 . "\n ORDER BY a.id" 144 ; 145 $database->setQuery( $query ); 146 $votes = $database->loadObjectList(); 147 148 $query = "SELECT id, title" 149 . "\n FROM #__polls" 150 . "\n WHERE published=1" 151 . "\n ORDER BY id" 152 ; 153 $database->setQuery( $query ); 154 $polls = $database->loadObjectList(); 155 156 reset( $polls ); 157 $script = "this.options[selectedIndex].value"; 158 $link = sefRelToAbs( "index.php?option=com_poll&task=results&id=0".($Itemid?"&Itemid=$Itemid":'') ); 159 if (mamboCore::get('mosConfig_sef')) 160 $link = str_replace('/id,0', "/id,'+$script+'", $link); 161 else 162 $link = str_replace('&id=0', "&id='+$script+'", $link); 163 $pollist = '<select name="id" class="inputbox" size="1" style="width:200px" onchange="if (this.options[selectedIndex].value != \'\') {document.location.href=\''. $link .'\'}">'; 164 $pollist .= '<option value="">'. T_('Select Poll from the list') .'</option>'; 165 for ($i=0, $n=count( $polls ); $i < $n; $i++ ) { 166 $k = $polls[$i]->id; 167 $t = $polls[$i]->title; 168 169 $sel = ($k == intval( $poll->id ) ? " selected=\"selected\"" : ''); 170 $pollist .= "\n\t<option value=\"".$k."\"$sel>" . $t . "</option>"; 171 } 172 $pollist .= '</select>'; 173 174 // Adds parameter handling 175 $menu =& new mosMenu( $database ); 176 $menu->load( $Itemid ); 177 $params =& new mosParameters( $menu->params ); 178 $params->def( 'page_title', 1 ); 179 $params->def( 'pageclass_sfx', '' ); 180 $params->def( 'back_button', $mainframe->getCfg( 'back_button' ) ); 181 $params->def( 'header', ($menu->id ? $menu->name : T_('Polls')) ); 182 183 // get pathway stuff 184 $pathway =& mosPathway::getInstance(); 185 $basePath = mamboCore::get('mosConfig_live_site').'/index.php?option=com_poll&task=results'; 186 $uri = new mosUriHelper(); 187 $uri->setUri($basePath); 188 if (!$Itemid) { 189 $pathway->addItem($params->get('header'), sefRelToAbs($uri->toString())); 190 } 191 if ($poll->id) { 192 if ($Itemid) $uri->popParam('Itemid'); 193 $uri->pushParam('id', $poll->id); 194 if ($Itemid) $uri->pushParam('Itemid', $Itemid); 195 $pathway->addItem($poll->title, sefRelToAbs($uri->toString())); 196 } 197 198 $mainframe->SetPageTitle( ($poll->id ? $poll->title : T_('Polls')) ); 199 poll_html::showResults( $poll, $votes, $first_vote, $last_vote, $pollist, $params ); 200 } 201 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed May 23 00:05:01 2012 | Cross-referenced by PHPXref 0.7 |
| Mambo API: Mambo is Free software released under the GNU/General Public License, Version 2 |