[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php
   2  /**
   3  * @version $Id: admin.poll.php 5014 2006-09-11 19:35:26Z 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  // ensure user has access to this function
  19  if (!($acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'all' )
  20          | $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'com_poll' ))) {
  21      mosRedirect( 'index2.php', _NOT_AUTH );
  22  }
  23  
  24  require_once( $mainframe->getPath( 'admin_html' ) );
  25  require_once( $mainframe->getPath( 'class' ) );
  26  
  27  $cid = josGetArrayInts( 'cid' );
  28  
  29  switch( $task ) {
  30      case 'new':
  31          editPoll( 0, $option );
  32          break;
  33  
  34      case 'edit':
  35          editPoll( intval( $cid[0] ), $option );
  36          break;
  37  
  38      case 'editA':
  39          editPoll( $id, $option );
  40          break;
  41  
  42      case 'save':
  43          savePoll( $option );
  44          break;
  45  
  46      case 'remove':
  47          removePoll( $cid, $option );
  48          break;
  49  
  50      case 'publish':
  51          publishPolls( $cid, 1, $option );
  52          break;
  53  
  54      case 'unpublish':
  55          publishPolls( $cid, 0, $option );
  56          break;
  57  
  58      case 'cancel':
  59          cancelPoll( $option );
  60          break;
  61  
  62      default:
  63          showPolls( $option );
  64          break;
  65  }
  66  
  67  function showPolls( $option ) {
  68      global $database, $mainframe, $mosConfig_list_limit;
  69  
  70      $limit         = intval( $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ) );
  71      $limitstart = intval( $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 ) );
  72  
  73      $query = "SELECT COUNT(*)"
  74      . "\n FROM #__polls"
  75      ;
  76      $database->setQuery( $query );
  77      $total = $database->loadResult();
  78  
  79      require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
  80      $pageNav = new mosPageNav( $total, $limitstart, $limit  );
  81  
  82      $query = "SELECT m.*, u.name AS editor,"
  83      . "\n COUNT(d.id) AS numoptions"
  84      . "\n FROM #__polls AS m"
  85      . "\n LEFT JOIN #__users AS u ON u.id = m.checked_out"
  86      . "\n LEFT JOIN #__poll_data AS d ON d.pollid = m.id AND d.text != ''"
  87      . "\n GROUP BY m.id"
  88      ;
  89      $database->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
  90      $rows = $database->loadObjectList();
  91  
  92      if ($database->getErrorNum()) {
  93          echo $database->stderr();
  94          return false;
  95      }
  96  
  97      HTML_poll::showPolls( $rows, $pageNav, $option );
  98  }
  99  
 100  function editPoll( $uid=0, $option='com_poll' ) {
 101      global $database, $my;
 102  
 103      $row = new mosPoll( $database );
 104      // load the row from the db table
 105      $row->load( (int)$uid );
 106  
 107      // fail if checked out not by 'me'
 108      if ($row->isCheckedOut( $my->id )) {
 109          mosRedirect( 'index2.php?option='. $option, 'The poll '. $row->title .' is currently being edited by another administrator.' );
 110      }
 111  
 112      $options = array();
 113  
 114      if ($uid) {
 115          $row->checkout( $my->id );
 116          $query = "SELECT id, text"
 117          . "\n FROM #__poll_data"
 118          . "\n WHERE pollid = " . (int) $uid
 119          . "\n ORDER BY id"
 120          ;
 121          $database->setQuery($query);
 122          $options = $database->loadObjectList();
 123      } else {
 124          $row->lag         = 3600 * 24;
 125          $row->published = 1;
 126      }
 127  
 128      // get selected pages
 129      if ( $uid ) {
 130          $query = "SELECT menuid AS value"
 131          . "\n FROM #__poll_menu"
 132          . "\n WHERE pollid = " . (int) $row->id
 133          ;
 134          $database->setQuery( $query );
 135          $lookup = $database->loadObjectList();
 136      } else {
 137          $lookup = array( mosHTML::makeOption( 0, 'All' ) );
 138      }
 139  
 140      // build the html select list
 141      $lists['select']     = mosAdminMenus::MenuLinks( $lookup, 1, 1 );
 142  
 143      // build the html select list for published
 144      $lists['published'] = mosAdminMenus::Published( $row );
 145      
 146      HTML_poll::editPoll($row, $options, $lists );
 147  }
 148  
 149  function savePoll( $option ) {
 150      global $database, $my;
 151  
 152      // save the poll parent information
 153      $row = new mosPoll( $database );
 154      if (!$row->bind( $_POST )) {
 155          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 156          exit();
 157      }
 158      $isNew = ($row->id == 0);
 159  
 160      if (!$row->check()) {
 161          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 162          exit();
 163      }
 164  
 165      if (!$row->store()) {
 166          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 167          exit();
 168      }
 169      $row->checkin();
 170      // save the poll options
 171      $options = mosGetParam( $_POST, 'polloption', array() );
 172  
 173      foreach ($options as $i=>$text) {
 174          if (!get_magic_quotes_gpc()) {
 175              // The poll module has always been this way, so we'll just stick with that and add
 176              // additional backslashes if needed. They will be stripped upon display
 177              $text = addslashes( $text );
 178          }
 179          if ($isNew) {
 180              $query = "INSERT INTO #__poll_data"
 181              . "\n ( pollid, text )"
 182              . "\n VALUES ( " . (int) $row->id . ", " . $database->Quote( $text ) . " )"
 183              ;
 184              $database->setQuery( $query );
 185              $database->query();
 186          } else {
 187              $query = "UPDATE #__poll_data"
 188              . "\n SET text = " . $database->Quote($text)
 189              . "\n WHERE id = " . (int) $i
 190              . "\n AND pollid = " . (int) $row->id
 191              ;
 192              $database->setQuery( $query );
 193              $database->query();
 194          }
 195      }
 196  
 197      // update the menu visibility
 198      $selections = mosGetParam( $_POST, 'selections', array() );
 199  
 200      $query = "DELETE FROM #__poll_menu"
 201      . "\n WHERE pollid = " . (int) $row->id
 202      ;
 203      $database->setQuery( $query );
 204      $database->query();
 205  
 206      for ($i=0, $n=count($selections); $i < $n; $i++) {
 207          $query = "INSERT INTO #__poll_menu"
 208          . "\n SET pollid = " . (int) $row->id . ", menuid = " . (int) $selections[$i]
 209          ;
 210          $database->setQuery( $query );
 211          $database->query();
 212      }
 213  
 214      mosRedirect( 'index2.php?option='. $option );
 215  }
 216  
 217  function removePoll( $cid, $option ) {
 218      global $database;
 219      $msg = '';
 220      for ($i=0, $n=count($cid); $i < $n; $i++) {
 221          $poll = new mosPoll( $database );
 222          if (!$poll->delete( $cid[$i] )) {
 223              $msg .= $poll->getError();
 224          }
 225      }
 226      mosRedirect( 'index2.php?option='. $option .'&mosmsg='. $msg );
 227  }
 228  
 229  /**
 230  * Publishes or Unpublishes one or more records
 231  * @param array An array of unique category id numbers
 232  * @param integer 0 if unpublishing, 1 if publishing
 233  * @param string The current url option
 234  */
 235  function publishPolls( $cid=null, $publish=1, $option ) {
 236      global $database, $my;
 237  
 238      if (!is_array( $cid ) || count( $cid ) < 1) {
 239          $action = $publish ? 'publish' : 'unpublish';
 240          echo "<script> alert('Select an item to $action'); window.history.go(-1);</script>\n";
 241          exit;
 242      }
 243  
 244      mosArrayToInts( $cid );
 245      $cids = 'id=' . implode( ' OR id=', $cid );
 246  
 247      $query = "UPDATE #__polls"
 248      . "\n SET published = " . intval( $publish )
 249      . "\n WHERE ( $cids )"
 250      . "\n AND ( checked_out = 0 OR ( checked_out = " . (int) $my->id  . " ) )"
 251      ;
 252      $database->setQuery( $query );
 253      if (!$database->query()) {
 254          echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 255          exit();
 256      }
 257  
 258      if (count( $cid ) == 1) {
 259          $row = new mosPoll( $database );
 260          $row->checkin( $cid[0] );
 261      }
 262      mosRedirect( 'index2.php?option='. $option );
 263  }
 264  
 265  function cancelPoll( $option ) {
 266      global $database;
 267      $row = new mosPoll( $database );
 268      $row->bind( $_POST );
 269      $row->checkin();
 270      mosRedirect( 'index2.php?option='. $option );
 271  }
 272  ?>


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