[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/components/com_poll/ -> poll.php (source)

   1  <?php
   2  /**
   3  * @version $Id: poll.php 5072 2006-09-15 16:24:06Z friesengeist $
   4  * @package Joomla
   5  * @subpackage Polls
   6  * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
   7  * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
   8  * Joomla! is free software. This version may have been modified pursuant
   9  * to the GNU General Public License, and as distributed it includes or
  10  * is derivative of works licensed under the GNU General Public License or
  11  * other free or open source software licenses.
  12  * See COPYRIGHT.php for copyright notices and details.
  13  */
  14  
  15  // no direct access
  16  defined( '_VALID_MOS' ) or die( 'Restricted access' );
  17  
  18  require_once( $mainframe->getPath( 'front_html' ) );
  19  require_once( $mainframe->getPath( 'class' ) );
  20  
  21  $tabclass             = 'sectiontableentry2,sectiontableentry1';
  22  $polls_graphwidth     = 200;
  23  $polls_barheight     = 2;
  24  $polls_maxcolors     = 5;
  25  $polls_barcolor     = 0;
  26  
  27  $id     = intval( mosGetParam( $_REQUEST, 'id', 0 ) );
  28  
  29  switch ($task) {
  30      case 'vote':
  31          pollAddVote( $id );
  32          break;
  33  
  34      default:
  35          pollresult( $id );
  36          break;
  37  }
  38  
  39  function pollAddVote( $uid ) {
  40      global $database;
  41  
  42      // simple spoof check security
  43      josSpoofCheck(0,'poll');    
  44      
  45      $redirect = 1;
  46  
  47      $sessionCookieName     = mosMainFrame::sessionCookieName();
  48      $sessioncookie         = mosGetParam( $_REQUEST, $sessionCookieName, '' );
  49  
  50      if (!$sessioncookie) {
  51          echo '<h3>'. _ALERT_ENABLED .'</h3>';
  52          echo '<input class="button" type="button" value="'. _CMN_CONTINUE .'" onClick="window.history.go(-1);">';
  53          return;
  54      }
  55  
  56      $poll = new mosPoll( $database );
  57      if (!$poll->load( (int)$uid )) {
  58          echo '<h3>'. _NOT_AUTH .'</h3>';
  59          echo '<input class="button" type="button" value="'. _CMN_CONTINUE .'" onClick="window.history.go(-1);">';
  60          return;
  61      }
  62  
  63      $cookiename = "voted$poll->id";
  64      $voted = mosGetParam( $_COOKIE, $cookiename, '0' );
  65  
  66      if ($voted) {
  67          echo "<h3>"._ALREADY_VOTE."</h3>";
  68          echo "<input class=\"button\" type=\"button\" value=\""._CMN_CONTINUE."\" onClick=\"window.history.go(-1);\">";
  69          return;
  70      }
  71  
  72      $voteid = intval( mosGetParam( $_POST, 'voteid', 0 ) );
  73      if (!$voteid) {
  74          echo "<h3>"._NO_SELECTION."</h3>";
  75          echo '<input class="button" type="button" value="'. _CMN_CONTINUE .'" onClick="window.history.go(-1);">';
  76          return;
  77      }
  78  
  79      setcookie( $cookiename, '1', time()+$poll->lag );
  80  
  81      $query = "UPDATE #__poll_data"
  82      . "\n SET hits = hits + 1"
  83      . "\n WHERE pollid = ".(int) $poll->id
  84      . "\n AND id = ". (int) $voteid
  85      ;
  86      $database->setQuery( $query );
  87      $database->query();
  88  
  89      $query = "UPDATE #__polls"
  90      . "\n SET voters = voters + 1"
  91      . "\n WHERE id = ".(int) $poll->id
  92      ;
  93      $database->setQuery( $query );
  94  
  95      $database->query();
  96  
  97      $now = _CURRENT_SERVER_TIME;
  98      
  99      $query = "INSERT INTO #__poll_date"
 100      . "\n SET date = " . $database->Quote( $now ) . ", vote_id = ". (int) $voteid .", poll_id = ".(int) $poll->id
 101      ;
 102      $database->setQuery( $query );
 103      $database->query();
 104  
 105      if ( $redirect ) {
 106          mosRedirect( sefRelToAbs( 'index.php?option=com_poll&task=results&id='. $uid ), _THANKS );
 107      } else {
 108          echo '<h3>'. _THANKS .'</h3>';
 109          echo '<form action="" method="GET">';
 110          echo '<input class="button" type="button" value="'. _BUTTON_RESULTS .'" onClick="window.location=\''. sefRelToAbs( 'index.php?option=com_poll&task=results&id='. $uid ) .'\'">';
 111          echo '</form>';
 112      }
 113  }
 114  
 115  function pollresult( $uid ) {
 116      global $database, $Itemid;
 117      global $mainframe;
 118  
 119      $poll = new mosPoll( $database );
 120      $poll->load( (int)$uid );
 121  
 122      // if id value is passed and poll not published then exit
 123      if ($poll->id != '' && !$poll->published) {
 124          mosNotAuth();
 125          return;
 126      }
 127  
 128      $first_vote = '';
 129      $last_vote     = '';
 130      $votes        = '';
 131      
 132      /*
 133      Check if there is a poll corresponding to id
 134      and if poll is published
 135      */
 136      if (isset($poll->id) && $poll->id != '' && $poll->published == 1) {
 137          if (empty($poll->title)) {
 138              $poll->id = '';
 139              $poll->title = _SELECT_POLL;
 140          }
 141          
 142          $query = "SELECT MIN( date ) AS mindate, MAX( date ) AS maxdate"
 143          . "\n FROM #__poll_date"
 144          . "\n WHERE poll_id = " . (int) $poll->id
 145          ;
 146          $database->setQuery( $query );
 147          $dates = $database->loadObjectList();
 148  
 149          if (isset($dates[0]->mindate)) {
 150              $first_vote = mosFormatDate( $dates[0]->mindate, _DATE_FORMAT_LC2 );
 151              $last_vote = mosFormatDate( $dates[0]->maxdate, _DATE_FORMAT_LC2 );
 152          }
 153          
 154          $query = "SELECT a.id, a.text, a.hits, b.voters"
 155          . "\n FROM #__poll_data AS a"
 156          . "\n INNER JOIN #__polls AS b ON b.id = a.pollid"
 157          . "\n WHERE a.pollid = " . (int) $poll->id
 158          . "\n AND a.text != ''"
 159          . "\n AND b.published = 1"
 160          ;
 161  
 162          $database->setQuery( $query );
 163          $votes = $database->loadObjectList();        
 164      }
 165  
 166      // list of polls for dropdown selection
 167      $query = "SELECT id, title"
 168      . "\n FROM #__polls"
 169      . "\n WHERE published = 1"
 170      . "\n ORDER BY id"
 171      ;
 172      $database->setQuery( $query );
 173      $polls = $database->loadObjectList();
 174      
 175      // Itemid for dropdown
 176      $_Itemid = '';
 177      if ( $Itemid && $Itemid != 99999999 ) {
 178          $_Itemid = '&amp;Itemid='. $Itemid;
 179      }
 180      
 181      // dropdown output
 182      $link = sefRelToAbs( 'index.php?option=com_poll&amp;task=results&amp;id=\' + this.options[selectedIndex].value + \''. $_Itemid .'\' + \'' );
 183      $pollist = '<select name="id" class="inputbox" size="1" style="width:200px" onchange="if (this.options[selectedIndex].value != \'\') {document.location.href=\''. $link .'\'}">';
 184      $pollist .= '<option value="">'. _SELECT_POLL .'</option>';
 185      for ($i=0, $n=count( $polls ); $i < $n; $i++ ) {
 186          $k = $polls[$i]->id;
 187          $t = $polls[$i]->title;
 188  
 189          $sel = ($k == intval( $poll->id ) ? " selected=\"selected\"" : '');
 190          $pollist .= "\n\t<option value=\"".$k."\"$sel>" . $t . "</option>";
 191      }
 192      $pollist .= '</select>';
 193  
 194      // Adds parameter handling
 195      $menu = $mainframe->get( 'menu' );
 196  
 197      $params = new mosParameters( $menu->params );
 198      $params->def( 'page_title', 1 );
 199      $params->def( 'pageclass_sfx', '' );
 200      $params->def( 'back_button', $mainframe->getCfg( 'back_button' ) );
 201      $params->def( 'header', $menu->name );
 202  
 203      $mainframe->SetPageTitle($poll->title);
 204  
 205      poll_html::showResults( $poll, $votes, $first_vote, $last_vote, $pollist, $params );
 206  }
 207  ?>


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics