[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/administrator/components/com_mambots/ -> admin.mambots.php (source)

   1  <?php
   2  /**
   3  * @version $Id: admin.mambots.php 5076 2006-09-16 11:44:41Z friesengeist $
   4  * @package Joomla
   5  * @subpackage Mambots
   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, 'mambots', 'all' )
  20  | $acl->acl_check( 'administration', 'install', 'users', $my->usertype, 'mambots', 'all' ))) {
  21          mosRedirect( 'index2.php', _NOT_AUTH );
  22  }
  23  
  24  require_once( $mainframe->getPath( 'admin_html' ) );
  25  
  26  $client = strval( mosGetParam( $_REQUEST, 'client', '' ) );
  27  
  28  $cid     = josGetArrayInts( 'cid' );
  29  
  30  switch ( $task ) {
  31  
  32      case 'new':
  33      case 'edit':
  34          editMambot( $option, intval( $cid[0] ), $client );
  35          break;
  36  
  37      case 'editA':
  38          editMambot( $option, $id, $client );
  39          break;
  40  
  41      case 'save':
  42      case 'apply':
  43          saveMambot( $option, $client, $task );
  44          break;
  45  
  46      case 'remove':
  47          removeMambot( $cid, $option, $client );
  48          break;
  49  
  50      case 'cancel':
  51          cancelMambot( $option, $client );
  52          break;
  53  
  54      case 'publish':
  55      case 'unpublish':
  56          publishMambot( $cid, ($task == 'publish'), $option, $client );
  57          break;
  58  
  59      case 'orderup':
  60      case 'orderdown':
  61          orderMambot( intval( $cid[0] ), ($task == 'orderup' ? -1 : 1), $option, $client );
  62          break;
  63  
  64      case 'accesspublic':
  65      case 'accessregistered':
  66      case 'accessspecial':
  67          accessMenu( intval( $cid[0] ), $task, $option, $client );
  68          break;
  69  
  70      case 'saveorder':
  71          saveOrder( $cid );
  72          break;
  73  
  74      default:
  75          viewMambots( $option, $client );
  76          break;
  77  }
  78  
  79  /**
  80  * Compiles a list of installed or defined modules
  81  */
  82  function viewMambots( $option, $client ) {
  83      global $database, $mainframe, $mosConfig_list_limit;
  84      global $mosConfig_absolute_path;
  85  
  86      $limit             = intval( $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ) );
  87      $limitstart     = intval( $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 ) );
  88      $filter_type    = $mainframe->getUserStateFromRequest( "filter_type{$option}{$client}", 'filter_type', 1 );
  89      $search         = $mainframe->getUserStateFromRequest( "search{$option}{$client}", 'search', '' );
  90      if (get_magic_quotes_gpc()) {
  91          $search        = stripslashes( $search );
  92      }
  93  
  94      if ($client == 'admin') {
  95          $where[] = "m.client_id = '1'";
  96          $client_id = 1;
  97      } else {
  98          $where[] = "m.client_id = '0'";
  99          $client_id = 0;
 100      }
 101  
 102      // used by filter
 103      if ( $filter_type != 1 ) {
 104          $where[] = "m.folder = " . $database->Quote( $filter_type );
 105      }
 106      if ( $search ) {
 107          $where[] = "LOWER( m.name ) LIKE '%" . $database->getEscaped( trim( strtolower( $search ) ) ) . "%'";
 108      }
 109  
 110      // get the total number of records
 111      $query = "SELECT COUNT(*)"
 112      . "\n FROM #__mambots AS m"
 113      . ( count( $where ) ? "\n WHERE " . implode( ' AND ', $where ) : '' )
 114      ;
 115      $database->setQuery( $query );
 116      $total = $database->loadResult();
 117  
 118      require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
 119      $pageNav = new mosPageNav( $total, $limitstart, $limit );
 120  
 121      $query = "SELECT m.*, u.name AS editor, g.name AS groupname"
 122      . "\n FROM #__mambots AS m"
 123      . "\n LEFT JOIN #__users AS u ON u.id = m.checked_out"
 124      . "\n LEFT JOIN #__groups AS g ON g.id = m.access"
 125      . ( count( $where ) ? "\n WHERE " . implode( ' AND ', $where ) : '' )
 126      . "\n GROUP BY m.id"
 127      . "\n ORDER BY m.folder ASC, m.ordering ASC, m.name ASC"
 128      ;
 129      $database->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
 130      $rows = $database->loadObjectList();
 131      if ($database->getErrorNum()) {
 132          echo $database->stderr();
 133          return false;
 134      }
 135  
 136      // get list of Positions for dropdown filter
 137      $query = "SELECT folder AS value, folder AS text"
 138      . "\n FROM #__mambots"
 139      . "\n WHERE client_id = " . (int) $client_id
 140      . "\n GROUP BY folder"
 141      . "\n ORDER BY folder"
 142      ;
 143      $types[] = mosHTML::makeOption( 1, _SEL_TYPE );
 144      $database->setQuery( $query );
 145      $types             = array_merge( $types, $database->loadObjectList() );
 146      $lists['type']    = mosHTML::selectList( $types, 'filter_type', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', $filter_type );
 147  
 148      HTML_modules::showMambots( $rows, $client, $pageNav, $option, $lists, $search );
 149  }
 150  
 151  /**
 152  * Saves the module after an edit form submit
 153  */
 154  function saveMambot( $option, $client, $task ) {
 155      global $database;
 156  
 157      $params = mosGetParam( $_POST, 'params', '' );
 158      if (is_array( $params )) {
 159          $txt = array();
 160          foreach ($params as $k=>$v) {
 161              $txt[] = "$k=$v";
 162          }
 163  
 164           $_POST['params'] = mosParameters::textareaHandling( $txt );
 165      }
 166  
 167      $row = new mosMambot( $database );
 168      if (!$row->bind( $_POST )) {
 169          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 170          exit();
 171      }
 172      if (!$row->check()) {
 173          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 174          exit();
 175      }
 176      if (!$row->store()) {
 177          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 178          exit();
 179      }
 180      $row->checkin();
 181      if ($client == 'admin') {
 182          $where = "client_id='1'";
 183      } else {
 184          $where = "client_id='0'";
 185      }
 186      $row->updateOrder( "folder = " . $database->Quote( $row->folder ) . " AND ordering > -10000 AND ordering < 10000 AND ( $where )" );
 187  
 188      switch ( $task ) {
 189          case 'apply':
 190              $msg = 'Successfully Saved changes to Mambot: '. $row->name;
 191              mosRedirect( 'index2.php?option='. $option .'&client='. $client .'&task=editA&hidemainmenu=1&id='. $row->id, $msg );
 192  
 193          case 'save':
 194          default:
 195              $msg = 'Successfully Saved Mambot: '. $row->name;
 196              mosRedirect( 'index2.php?option='. $option .'&client='. $client, $msg );
 197              break;
 198      }
 199  }
 200  
 201  /**
 202  * Compiles information to add or edit a module
 203  * @param string The current GET/POST option
 204  * @param integer The unique id of the record to edit
 205  */
 206  function editMambot( $option, $uid, $client ) {
 207      global $database, $my, $mainframe;
 208      global $mosConfig_absolute_path;
 209  
 210      $lists     = array();
 211      $row     = new mosMambot($database);
 212  
 213      // load the row from the db table
 214      $row->load( (int)$uid );
 215  
 216      // fail if checked out not by 'me'
 217      if ($row->isCheckedOut( $my->id )) {
 218          mosErrorAlert( "The module ".$row->title." is currently being edited by another administrator" );
 219      }
 220  
 221      if ($client == 'admin') {
 222          $where = "client_id='1'";
 223      } else {
 224          $where = "client_id='0'";
 225      }
 226  
 227      // get list of groups
 228      if ($row->access == 99 || $row->client_id == 1) {
 229          $lists['access'] = 'Administrator<input type="hidden" name="access" value="99" />';
 230      } else {
 231          // build the html select list for the group access
 232          $lists['access'] = mosAdminMenus::Access( $row );
 233      }
 234  
 235      if ($uid) {
 236          $row->checkout( $my->id );
 237  
 238          if ( $row->ordering > -10000 && $row->ordering < 10000 ) {
 239              // build the html select list for ordering
 240              $query = "SELECT ordering AS value, name AS text"
 241              . "\n FROM #__mambots"
 242              . "\n WHERE folder = " . $database->Quote ( $row->folder )
 243              . "\n AND published > 0"
 244              . "\n AND $where"
 245              . "\n AND ordering > -10000"
 246              . "\n AND ordering < 10000"
 247              . "\n ORDER BY ordering"
 248              ;
 249              $order = mosGetOrderingList( $query );
 250              $lists['ordering'] = mosHTML::selectList( $order, 'ordering', 'class="inputbox" size="1"', 'value', 'text', intval( $row->ordering ) );
 251          } else {
 252              $lists['ordering'] = '<input type="hidden" name="ordering" value="'. $row->ordering .'" />This mambot cannot be reordered';
 253          }
 254          $lists['folder'] = '<input type="hidden" name="folder" value="'. $row->folder .'" />'. $row->folder;
 255  
 256          // XML library
 257          require_once ( $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php' );
 258          // xml file for module
 259          $xmlfile = $mosConfig_absolute_path . '/mambots/' .$row->folder . '/' . $row->element .'.xml';
 260          $xmlDoc = new DOMIT_Lite_Document();
 261          $xmlDoc->resolveErrors( true );
 262          if ($xmlDoc->loadXML( $xmlfile, false, true )) {
 263              $root = &$xmlDoc->documentElement;
 264              if ($root->getTagName() == 'mosinstall' && $root->getAttribute( 'type' ) == 'mambot' ) {
 265                  $element = &$root->getElementsByPath( 'description', 1 );
 266                  $row->description = $element ? trim( $element->getText() ) : '';
 267  
 268              }
 269          }
 270      } else {
 271          $row->folder         = '';
 272          $row->ordering         = 999;
 273          $row->published     = 1;
 274          $row->description     = '';
 275  
 276          $folders = mosReadDirectory( $mosConfig_absolute_path . '/mambots/' );
 277          $folders2 = array();
 278          foreach ($folders as $folder) {
 279              if (is_dir( $mosConfig_absolute_path . '/mambots/' . $folder ) && ( $folder != 'CVS' ) ) {
 280                  $folders2[] = mosHTML::makeOption( $folder );
 281              }
 282          }
 283          $lists['folder'] = mosHTML::selectList( $folders2, 'folder', 'class="inputbox" size="1"', 'value', 'text', null );
 284          $lists['ordering'] = '<input type="hidden" name="ordering" value="'. $row->ordering .'" />New items default to the last place. Ordering can be changed after this item is saved.';
 285      }
 286  
 287      $lists['published'] = mosHTML::yesnoRadioList( 'published', 'class="inputbox"', $row->published );
 288  
 289      $path = $mosConfig_absolute_path . "/mambots/$row->folder/$row->element.xml";
 290      if (!file_exists( $path )) {
 291          $path = '';
 292      }
 293  
 294      // get params definitions
 295      $params = new mosParameters( $row->params, $path, 'mambot' );
 296  
 297      HTML_modules::editMambot( $row, $lists, $params, $option );
 298  }
 299  
 300  /**
 301  * Deletes one or more mambots
 302  *
 303  * Also deletes associated entries in the #__mambots table.
 304  * @param array An array of unique category id numbers
 305  */
 306  function removeMambot( &$cid, $option, $client ) {
 307      global $database, $my;
 308  
 309      if (count( $cid ) < 1) {
 310          echo "<script> alert('Select a module to delete'); window.history.go(-1);</script>\n";
 311          exit;
 312      }
 313  
 314      mosRedirect( 'index2.php?option=com_installer&element=mambot&client='. $client .'&task=remove&cid[]='. $cid[0] );
 315  }
 316  
 317  /**
 318  * Publishes or Unpublishes one or more modules
 319  * @param array An array of unique category id numbers
 320  * @param integer 0 if unpublishing, 1 if publishing
 321  */
 322  function publishMambot( $cid=null, $publish=1, $option, $client ) {
 323      global $database, $my;
 324  
 325      if (count( $cid ) < 1) {
 326          $action = $publish ? 'publish' : 'unpublish';
 327          echo "<script> alert('Select a mambot to $action'); window.history.go(-1);</script>\n";
 328          exit;
 329      }
 330  
 331      mosArrayToInts( $cid );
 332      $cids = 'id=' . implode( ' OR id=', $cid );
 333  
 334      $query = "UPDATE #__mambots SET published = " . (int) $publish
 335      . "\n WHERE ( $cids )"
 336      . "\n AND ( checked_out = 0 OR ( checked_out = " . (int) $my->id . " ) )"
 337      ;
 338      $database->setQuery( $query );
 339      if (!$database->query()) {
 340          echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 341          exit();
 342      }
 343  
 344      if (count( $cid ) == 1) {
 345          $row = new mosMambot( $database );
 346          $row->checkin( $cid[0] );
 347      }
 348  
 349      mosRedirect( 'index2.php?option='. $option .'&client='. $client );
 350  }
 351  
 352  /**
 353  * Cancels an edit operation
 354  */
 355  function cancelMambot( $option, $client ) {
 356      global $database;
 357  
 358      $row = new mosMambot( $database );
 359      $row->bind( $_POST );
 360      $row->checkin();
 361  
 362      mosRedirect( 'index2.php?option='. $option .'&client='. $client );
 363  }
 364  
 365  /**
 366  * Moves the order of a record
 367  * @param integer The unique id of record
 368  * @param integer The increment to reorder by
 369  */
 370  function orderMambot( $uid, $inc, $option, $client ) {
 371      global $database;
 372  
 373      // Currently Unsupported
 374      if ($client == 'admin') {
 375          $where = "client_id = 1";
 376      } else {
 377          $where = "client_id = 0";
 378      }
 379      $row = new mosMambot( $database );
 380      $row->load( (int)$uid );
 381      $row->move( $inc, "folder=" . $database->Quote( $row->folder ) . " AND ordering > -10000 AND ordering < 10000 AND ($where)"  );
 382  
 383      mosRedirect( 'index2.php?option='. $option );
 384  }
 385  
 386  /**
 387  * changes the access level of a record
 388  * @param integer The increment to reorder by
 389  */
 390  function accessMenu( $uid, $access, $option, $client ) {
 391      global $database;
 392  
 393      switch ( $access ) {
 394          case 'accesspublic':
 395              $access = 0;
 396              break;
 397  
 398          case 'accessregistered':
 399              $access = 1;
 400              break;
 401  
 402          case 'accessspecial':
 403              $access = 2;
 404              break;
 405      }
 406  
 407      $row = new mosMambot( $database );
 408      $row->load( (int)$uid );
 409      $row->access = $access;
 410  
 411      if ( !$row->check() ) {
 412          return $row->getError();
 413      }
 414      if ( !$row->store() ) {
 415          return $row->getError();
 416      }
 417  
 418      mosRedirect( 'index2.php?option='. $option );
 419  }
 420  
 421  function saveOrder( &$cid ) {
 422      global $database;
 423  
 424      $total        = count( $cid );
 425      $order         = josGetArrayInts( 'order' );
 426      
 427      $row         = new mosMambot( $database );
 428      $conditions = array();
 429  
 430      // update ordering values
 431      for ( $i=0; $i < $total; $i++ ) {
 432          $row->load( (int) $cid[$i] );
 433          if ($row->ordering != $order[$i]) {
 434              $row->ordering = $order[$i];
 435              if (!$row->store()) {
 436                  echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 437                  exit();
 438              } // if
 439              // remember to updateOrder this group
 440              $condition = "folder = " . $database->Quote( $row->folder ) . " AND ordering > -10000 AND ordering < 10000 AND client_id = " . (int) $row->client_id;
 441              $found = false;
 442              foreach ( $conditions as $cond )
 443                  if ($cond[1]==$condition) {
 444                      $found = true;
 445                      break;
 446                  } // if
 447              if (!$found) $conditions[] = array($row->id, $condition);
 448          } // if
 449      } // for
 450  
 451      // execute updateOrder for each group
 452      foreach ( $conditions as $cond ) {
 453          $row->load( $cond[0] );
 454          $row->updateOrder( $cond[1] );
 455      } // foreach
 456  
 457      $msg     = 'New ordering saved';
 458      mosRedirect( 'index2.php?option=com_mambots', $msg );
 459  } // saveOrder
 460  ?>


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