[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/public_html/polls/ -> index.php (source)

   1  <?php
   2  
   3  /* Reminder: always indent with 4 spaces (no tabs). */
   4  // +---------------------------------------------------------------------------+
   5  // | Polls Plugin 1.1                                                          |
   6  // +---------------------------------------------------------------------------+
   7  // | index.php                                                                 |
   8  // |                                                                           |
   9  // | Display poll results and past polls.                                      |
  10  // +---------------------------------------------------------------------------+
  11  // | Copyright (C) 2000-2006 by the following authors:                         |
  12  // |                                                                           |
  13  // | Authors: Tony Bibbs        - tony AT tonybibbs DOT com                    |
  14  // |          Mark Limburg      - mlimburg AT users DOT sourceforge DOT net    |
  15  // |          Jason Whittenburg - jwhitten AT securitygeeks DOT com            |
  16  // |          Dirk Haun         - dirk AT haun-online DOT de                   |
  17  // +---------------------------------------------------------------------------+
  18  // |                                                                           |
  19  // | This program is free software; you can redistribute it and/or             |
  20  // | modify it under the terms of the GNU General Public License               |
  21  // | as published by the Free Software Foundation; either version 2            |
  22  // | of the License, or (at your option) any later version.                    |
  23  // |                                                                           |
  24  // | This program is distributed in the hope that it will be useful,           |
  25  // | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
  26  // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
  27  // | GNU General Public License for more details.                              |
  28  // |                                                                           |
  29  // | You should have received a copy of the GNU General Public License         |
  30  // | along with this program; if not, write to the Free Software Foundation,   |
  31  // | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
  32  // |                                                                           |
  33  // +---------------------------------------------------------------------------+
  34  //
  35  // $Id: index.php,v 1.20 2006/08/21 11:38:31 dhaun Exp $
  36  
  37  require_once  ('../lib-common.php');
  38  
  39  // number of polls to list per page
  40  define ('POLLS_PER_PAGE', 50);
  41  
  42  /**
  43  * Saves a user's vote
  44  *
  45  * Saves the users vote, if allowed for the poll $qid.
  46  * NOTE: all data comes from form post
  47  *
  48  * @param    string   $qid   poll id
  49  * @param    int      $aid   selected answer
  50  * @return   string   HTML for poll results
  51  *
  52  */
  53  function pollsave($qid = '', $aid = 0) 
  54  {
  55      global $_TABLES, $LANG_POLLS;
  56  
  57      $retval = '';
  58  
  59      if (POLLS_ipAlreadyVoted ($qid)) {
  60          exit;
  61      }
  62  
  63      DB_change($_TABLES['pollquestions'],'voters',"voters + 1",'qid',$qid,'',true);
  64      $id[1] = 'qid';
  65      $value[1] = $qid;
  66      $id[2] = 'aid';
  67      $value[2] = $aid;
  68      // This call to DB-change will properly supress the insertion of quoes around $value in the sql
  69      DB_change($_TABLES['pollanswers'],'votes',"votes + 1",$id,$value, '', true);
  70      // This always does an insert so no need to provide key_field and key_value args
  71      DB_save($_TABLES['pollvoters'],'ipaddress,date,qid',"'{$_SERVER['REMOTE_ADDR']}'," . time() . ",'$qid'");
  72      $retval .= COM_startBlock ($LANG_POLLS['savedvotetitle'], '',
  73                         COM_getBlockTemplate ('_msg_block', 'header'))
  74          . $LANG_POLLS['savedvotemsg'] . ' "'
  75          . DB_getItem ($_TABLES['pollquestions'], 'question', "qid = '{$qid}'")
  76          . '"'
  77          . COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'))
  78          . POLLS_pollResults($qid);
  79  
  80      return $retval;
  81  }
  82  
  83  /**     
  84  * Shows all polls in system
  85  *       
  86  * List all the polls on the system if no $qid is provided
  87  *       
  88  * @return   string          HTML for poll listing
  89  *       
  90  */
  91  function polllist ()
  92  {
  93      global $_CONF, $_TABLES, $_USER, $_PO_CONF,
  94             $LANG25, $LANG_LOGIN, $LANG_POLLS;
  95  
  96      $retval = '';
  97  
  98      if (empty ($_USER['username']) && (($_CONF['loginrequired'] == 1) ||
  99              ($_PO_CONF['pollsloginrequired'] == 1))) {
 100          $retval = COM_startBlock ($LANG_LOGIN[1], '',
 101                            COM_getBlockTemplate ('_msg_block', 'header'));
 102          $login = new Template ($_CONF['path_layout'] . 'submit');
 103          $login->set_file (array ('login' => 'submitloginrequired.thtml'));
 104          $login->set_var ('login_message', $LANG_LOGIN[2]);
 105          $login->set_var ('site_url', $_CONF['site_url']);
 106          $login->set_var ('lang_login', $LANG_LOGIN[3]);
 107          $login->set_var ('lang_newuser', $LANG_LOGIN[4]);
 108          $login->parse ('output', 'login');
 109          $retval .= $login->finish ($login->get_var('output'));
 110          $retval .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
 111      } else {
 112          require_once( $_CONF['path_system'] . 'lib-admin.php' );
 113          $header_arr = array(    // display 'text' and use table field 'field'
 114                          array('text' => $LANG25[9], 'field' => 'question', 'sort' => true),
 115                          array('text' => $LANG25[20], 'field' => 'voters', 'sort' => true),
 116                          array('text' => $LANG25[3], 'field' => 'unixdate', 'sort' => true),
 117                          array('text' => $LANG_POLLS['open_poll'], 'field' => 'display', 'sort' => true)
 118          );
 119  
 120          $defsort_arr = array('field' => 'unixdate', 'direction' => 'desc');
 121  
 122          $menu_arr = array ();
 123  
 124          $text_arr = array('has_menu' =>  false,
 125                            'title' => $LANG_POLLS['pollstitle'], 'instructions' => "",
 126                            'icon' => '', 'form_url' => '');
 127  
 128          $query_arr = array('table' => 'pollquestions',
 129                             'sql' => $sql = "SELECT *,UNIX_TIMESTAMP(date) AS unixdate, display FROM {$_TABLES['pollquestions']} WHERE 1=1",
 130                             'query_fields' => array('question'),
 131                             'default_filter' => COM_getPermSQL (),
 132                             'query' => '',
 133                             'query_limit' => 0);
 134  
 135          $retval .= ADMIN_list ('polls', 'plugin_getListField_polls',
 136                     $header_arr, $text_arr, $query_arr, $menu_arr, $defsort_arr);
 137      }
 138  
 139      return $retval;
 140  }
 141  
 142  // MAIN
 143  //
 144  // no qid will load a list of polls
 145  // no aid will let you vote on the select poll
 146  // an aid greater than 0 will save a vote for that answer on the selected poll
 147  // an aid of -1 will display the select poll
 148  
 149  $display = '';
 150  
 151  if (isset ($_POST['reply']) && ($_POST['reply'] == $LANG01[25])) {
 152      $display .= COM_refresh ($_CONF['site_url'] . '/comment.php?sid='
 153               . $_POST['qid'] . '&pid=' . $_POST['pid']
 154               . '&type=' . $_POST['type']);
 155      echo $display;
 156      exit;            
 157  }
 158  
 159  $qid = 0;
 160  $aid = -1;
 161  if (isset ($_POST['qid'])) {
 162      $qid = COM_applyFilter ($_POST['qid']);
 163      if (isset ($_POST['aid'])) {
 164          $aid = COM_applyFilter ($_POST['aid'], true);
 165      }
 166  } else {
 167      if (isset ($_GET['qid'])) {
 168          $qid = COM_applyFilter ($_GET['qid']);
 169      }
 170      if (isset ($_GET['aid'])) {
 171          $aid = COM_applyFilter ($_GET['aid'], true);
 172          if ($aid > 0) { // you can't vote with a GET request
 173              $aid = -1;
 174          }
 175      }
 176  }
 177  $order = '';
 178  if (isset ($_REQUEST['order'])) {
 179      $order = COM_applyFilter ($_REQUEST['order']);
 180  }
 181  $mode = '';
 182  if (isset ($_REQUEST['mode'])) {
 183      $mode = COM_applyFilter ($_REQUEST['mode']);
 184  }
 185  
 186  if (empty($qid)) {
 187      $display .= COM_siteHeader ('menu', $LANG_POLLS['pollstitle'])
 188               . polllist (); 
 189  } else if ($aid == 0) {
 190      $display .= COM_siteHeader();
 191      if (!isset ($_COOKIE[$qid]) && !POLLS_ipAlreadyVoted ($qid)) {
 192          $display .= POLLS_pollVote ($qid);
 193      } else {
 194          $display .= POLLS_pollResults ($qid, 400, $order, $mode);
 195      }
 196  } else if (($aid > 0) && ($aid <= $_PO_CONF['maxanswers']) &&
 197          !isset ($_COOKIE[$qid])) {
 198      setcookie ($qid, $aid, time() + $_PO_CONF['pollcookietime'],
 199                 $_CONF['cookie_path'], $_CONF['cookiedomain'],
 200                 $_CONF['cookiesecure']);
 201      $display .= COM_siteHeader() . pollsave($qid, $aid);
 202  } else {
 203      $question = DB_query ("SELECT question FROM {$_TABLES['pollquestions']} WHERE qid='$qid'" . COM_getPermSql ('AND'));
 204      $Q = DB_fetchArray ($question);
 205      if (empty ($Q['question'])) {
 206          $display .= COM_siteHeader ('menu', $LANG_POLLS['pollstitle'])
 207                   . polllist ();
 208      } else {
 209          $display .= COM_siteHeader ('menu', $Q['question'])
 210                   . POLLS_pollResults ($qid, 400, $order, $mode);
 211      }
 212  }
 213  $display .= COM_siteFooter();
 214  
 215  echo $display;
 216  
 217  ?>


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics