[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/administrator/components/com_modules/ -> admin.modules.php (source)

   1  <?php
   2  /**
   3  * @version $Id: admin.modules.php 5014 2006-09-11 19:35:26Z friesengeist $
   4  * @package Joomla
   5  * @subpackage Modules
   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, 'modules', 'all' ) | $acl->acl_check( 'administration', 'install', 'users', $my->usertype, 'modules', 'all' ))) {
  20      mosRedirect( 'index2.php', _NOT_AUTH );
  21  }
  22  
  23  require_once( $mainframe->getPath( 'admin_html' ) );
  24  
  25  $client     = strval( mosGetParam( $_REQUEST, 'client', '' ) );
  26  $moduleid     = mosGetParam( $_REQUEST, 'moduleid', null );
  27  
  28  $cid         = josGetArrayInts( 'cid' );
  29  
  30  if ($cid[0] == 0 && isset($moduleid) ) {
  31      $cid[0] = $moduleid;
  32  }
  33  
  34  switch ( $task ) {
  35      case 'copy':
  36          copyModule( $option, intval( $cid[0] ), $client );
  37          break;
  38  
  39      case 'new':
  40          editModule( $option, 0, $client );
  41          break;
  42  
  43      case 'edit':
  44          editModule( $option, intval( $cid[0] ), $client );
  45          break;
  46  
  47      case 'editA':
  48          editModule( $option, $id, $client );
  49          break;
  50  
  51      case 'save':
  52      case 'apply':
  53          saveModule( $option, $client, $task );
  54          break;
  55  
  56      case 'remove':
  57          removeModule( $cid, $option, $client );
  58          break;
  59  
  60      case 'cancel':
  61          cancelModule( $option, $client );
  62          break;
  63  
  64      case 'publish':
  65      case 'unpublish':
  66          publishModule( $cid, ($task == 'publish'), $option, $client );
  67          break;
  68  
  69      case 'orderup':
  70      case 'orderdown':
  71          orderModule( intval( $cid[0] ), ($task == 'orderup' ? -1 : 1), $option );
  72          break;
  73  
  74      case 'accesspublic':
  75      case 'accessregistered':
  76      case 'accessspecial':
  77          accessMenu( intval( $cid[0] ), $task, $option, $client );
  78          break;
  79  
  80      case 'saveorder':
  81          saveOrder( $cid, $client );
  82          break;
  83  
  84      default:
  85          viewModules( $option, $client );
  86          break;
  87  }
  88  
  89  /**
  90  * Compiles a list of installed or defined modules
  91  */
  92  function viewModules( $option, $client ) {
  93      global $database, $my, $mainframe, $mosConfig_list_limit, $mosConfig_absolute_path;
  94  
  95      $filter_position     = $mainframe->getUserStateFromRequest( "filter_position{$option}{$client}", 'filter_position', 0 );
  96      $filter_type         = $mainframe->getUserStateFromRequest( "filter_type{$option}{$client}", 'filter_type', 0 );
  97      $limit                 = intval( $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ) );
  98      $limitstart         = intval( $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 ) );
  99      $search             = $mainframe->getUserStateFromRequest( "search{$option}{$client}", 'search', '' );
 100      if (get_magic_quotes_gpc()) {
 101          $search                = stripslashes( $search );
 102          $filter_position    = stripslashes( $filter_position );
 103          $filter_type        = stripslashes( $filter_type );
 104      }
 105  
 106      if ($client == 'admin') {
 107          $where[]     = "m.client_id = 1";
 108          $client_id     = 1;
 109      } else {
 110          $where[]     = "m.client_id = 0";
 111          $client_id     = 0;
 112          $client     = '';
 113      }
 114  
 115      // used by filter
 116      if ( $filter_position ) {
 117          $where[] = "m.position = " . $database->Quote( $filter_position );
 118      }
 119      if ( $filter_type ) {
 120          $where[] = "m.module = " . $database->Quote( $filter_type );
 121      }
 122      if ( $search ) {
 123          $where[] = "LOWER( m.title ) LIKE '%" . $database->getEscaped( trim( strtolower( $search ) ) ) . "%'";
 124      }
 125  
 126      // get the total number of records
 127      $query = "SELECT COUNT(*)"
 128      . "\n FROM #__modules AS m"
 129      . ( count( $where ) ? "\n WHERE " . implode( ' AND ', $where ) : '' )
 130      ;
 131      $database->setQuery( $query );
 132      $total = $database->loadResult();
 133  
 134      require_once ( $mosConfig_absolute_path . '/administrator/includes/pageNavigation.php' );
 135      $pageNav = new mosPageNav( $total, $limitstart, $limit );
 136  
 137      $query = "SELECT m.*, u.name AS editor, g.name AS groupname, MIN(mm.menuid) AS pages"
 138      . "\n FROM #__modules AS m"
 139      . "\n LEFT JOIN #__users AS u ON u.id = m.checked_out"
 140      . "\n LEFT JOIN #__groups AS g ON g.id = m.access"
 141      . "\n LEFT JOIN #__modules_menu AS mm ON mm.moduleid = m.id"
 142      . ( count( $where ) ? "\n WHERE " . implode( ' AND ', $where ) : '' )
 143      . "\n GROUP BY m.id"
 144      . "\n ORDER BY position ASC, ordering ASC"
 145      ;
 146      $database->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
 147      $rows = $database->loadObjectList();
 148      if ($database->getErrorNum()) {
 149          echo $database->stderr();
 150          return false;
 151      }
 152  
 153      // get list of Positions for dropdown filter
 154      $query = "SELECT t.position AS value, t.position AS text"
 155      . "\n FROM #__template_positions as t"
 156      . "\n LEFT JOIN #__modules AS m ON m.position = t.position"
 157      . "\n WHERE m.client_id = " . (int) $client_id
 158      . "\n GROUP BY t.position"
 159      . "\n ORDER BY t.position"
 160      ;
 161      $positions[] = mosHTML::makeOption( '0', _SEL_POSITION );
 162      $database->setQuery( $query );
 163      $positions = array_merge( $positions, $database->loadObjectList() );
 164      $lists['position']    = mosHTML::selectList( $positions, 'filter_position', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', "$filter_position" );
 165  
 166      // get list of Positions for dropdown filter
 167      $query = "SELECT module AS value, module AS text"
 168      . "\n FROM #__modules"
 169      . "\n WHERE client_id = " . (int) $client_id
 170      . "\n GROUP BY module"
 171      . "\n ORDER BY module"
 172      ;
 173      $types[] = mosHTML::makeOption( '0', _SEL_TYPE );
 174      $database->setQuery( $query );
 175      $types = array_merge( $types, $database->loadObjectList() );
 176      $lists['type']    = mosHTML::selectList( $types, 'filter_type', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', "$filter_type" );
 177  
 178      HTML_modules::showModules( $rows, $my->id, $client, $pageNav, $option, $lists, $search );
 179  }
 180  
 181  /**
 182  * Compiles information to add or edit a module
 183  * @param string The current GET/POST option
 184  * @param integer The unique id of the record to edit
 185  */
 186  function copyModule( $option, $uid, $client ) {
 187      global $database, $my;
 188  
 189      $row = new mosModule( $database );
 190      // load the row from the db table
 191      $row->load( (int)$uid );
 192      $row->title         = 'Copy of '.$row->title;
 193      $row->id             = 0;
 194      $row->iscore         = 0;
 195      $row->published     = 0;
 196  
 197      if (!$row->check()) {
 198          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 199          exit();
 200      }
 201      if (!$row->store()) {
 202          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 203          exit();
 204      }
 205      $row->checkin();
 206      if ($client == 'admin') {
 207          $where = "client_id='1'";
 208      } else {
 209          $where = "client_id='0'";
 210      }
 211      $row->updateOrder( 'position=' . $database->Quote( $row->position ) . " AND ($where)" );
 212  
 213      $query = "SELECT menuid"
 214      . "\n FROM #__modules_menu"
 215      . "\n WHERE moduleid = " . (int) $uid
 216      ;
 217      $database->setQuery( $query );
 218      $rows = $database->loadResultArray();
 219  
 220      foreach($rows as $menuid) {
 221          $query = "INSERT INTO #__modules_menu"
 222          . "\n SET moduleid = " . (int) $row->id . ", menuid = " . (int) $menuid
 223          ;
 224          $database->setQuery( $query );
 225          $database->query();
 226      }
 227  
 228      mosCache::cleanCache( 'com_content' );
 229      
 230      $msg = 'Module Copied ['. $row->title .']';
 231      mosRedirect( 'index2.php?option='. $option .'&client='. $client, $msg );
 232  }
 233  
 234  /**
 235  * Saves the module after an edit form submit
 236  */
 237  function saveModule( $option, $client, $task ) {
 238      global $database;
 239  
 240      $params = mosGetParam( $_POST, 'params', '' );
 241      if (is_array( $params )) {
 242          $txt = array();
 243          foreach ($params as $k=>$v) {
 244              $txt[] = "$k=$v";
 245          }
 246          $_POST['params'] = mosParameters::textareaHandling( $txt );
 247      }
 248  
 249      $row = new mosModule( $database );
 250      if (!$row->bind( $_POST, 'selections' )) {
 251          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 252          exit();
 253      }
 254      if (!$row->check()) {
 255          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 256          exit();
 257      }
 258      if (!$row->store()) {
 259          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 260          exit();
 261      }
 262      
 263      $row->checkin();
 264      if ($client == 'admin') {
 265          $where = "client_id=1";
 266      } else {
 267          $where = "client_id=0";
 268      }
 269      $row->updateOrder( 'position=' . $database->Quote( $row->position ) . " AND ($where)" );
 270  
 271      $menus     = josGetArrayInts( 'selections' );
 272  
 273      // delete old module to menu item associations
 274      $query = "DELETE FROM #__modules_menu"
 275      . "\n WHERE moduleid = " . (int) $row->id
 276      ;
 277      $database->setQuery( $query );
 278      $database->query();
 279  
 280      // check needed to stop a module being assigned to `All` 
 281      // and other menu items resulting in a module being displayed twice
 282      if ( in_array( '0', $menus ) ) {
 283          // assign new module to `all` menu item associations
 284          $query = "INSERT INTO #__modules_menu"
 285          . "\n SET moduleid = " . (int) $row->id . ", menuid = 0"
 286          ;
 287          $database->setQuery( $query );
 288          $database->query();
 289      } else {
 290          foreach ($menus as $menuid){
 291              // this check for the blank spaces in the select box that have been added for cosmetic reasons
 292              if ( $menuid != "-999" ) {
 293                  // assign new module to menu item associations
 294                  $query = "INSERT INTO #__modules_menu"
 295                  . "\n SET moduleid = " . (int) $row->id . ", menuid = " . (int) $menuid
 296                  ;
 297                  $database->setQuery( $query );
 298                  $database->query();
 299              }
 300          }                
 301      }
 302  
 303      mosCache::cleanCache( 'com_content' );
 304      
 305      switch ( $task ) {
 306          case 'apply':
 307              $msg = 'Successfully Saved changes to Module: '. $row->title;
 308              mosRedirect( 'index2.php?option='. $option .'&client='. $client .'&task=editA&hidemainmenu=1&id='. $row->id, $msg );
 309              break;
 310  
 311          case 'save':
 312          default:
 313              $msg = 'Successfully Saved Module: '. $row->title;
 314              mosRedirect( 'index2.php?option='. $option .'&client='. $client, $msg );
 315              break;
 316      }
 317  }
 318  
 319  /**
 320  * Compiles information to add or edit a module
 321  * @param string The current GET/POST option
 322  * @param integer The unique id of the record to edit
 323  */
 324  function editModule( $option, $uid, $client ) {
 325      global $database, $my, $mainframe;
 326      global $mosConfig_absolute_path;
 327  
 328      $lists = array();
 329      $row = new mosModule( $database );
 330      // load the row from the db table
 331      $row->load( (int)$uid );
 332      // fail if checked out not by 'me'
 333      if ($row->isCheckedOut( $my->id )) {
 334          mosErrorAlert( "The module ".$row->title." is currently being edited by another administrator" );
 335      }
 336  
 337      $row->content = htmlspecialchars( $row->content );
 338  
 339      if ( $uid ) {
 340          $row->checkout( $my->id );
 341      }
 342      // if a new record we must still prime the mosModule object with a default
 343      // position and the order; also add an extra item to the order list to
 344      // place the 'new' record in last position if desired
 345      if ($uid == 0) {
 346          $row->position     = 'left';
 347          $row->showtitle = true;
 348          //$row->ordering = $l;
 349          $row->published = 1;
 350      }
 351  
 352  
 353      if ( $client == 'admin' ) {
 354          $where                 = "client_id = 1";
 355          $lists['client_id'] = 1;
 356          $path                = 'mod1_xml';
 357      } else {
 358          $where                 = "client_id = 0";
 359          $lists['client_id'] = 0;
 360          $path                = 'mod0_xml';
 361      }
 362      $query = "SELECT position, ordering, showtitle, title"
 363      . "\n FROM #__modules"
 364      . "\n WHERE $where"
 365      . "\n ORDER BY ordering"
 366      ;
 367      $database->setQuery( $query );
 368      if ( !($orders = $database->loadObjectList()) ) {
 369          echo $database->stderr();
 370          return false;
 371      }
 372  
 373      $query = "SELECT position, description"
 374      . "\n FROM #__template_positions"
 375      . "\n WHERE position != ''"
 376      . "\n ORDER BY position"
 377      ;
 378      $database->setQuery( $query );
 379      // hard code options for now
 380      $positions = $database->loadObjectList();
 381  
 382      $orders2 = array();
 383      $pos = array();
 384      foreach ($positions as $position) {
 385          $orders2[$position->position] = array();
 386          $pos[] = mosHTML::makeOption( $position->position, $position->description );
 387      }
 388  
 389      $l = 0;
 390      $r = 0;
 391      for ($i=0, $n=count( $orders ); $i < $n; $i++) {
 392          $ord = 0;
 393          if (array_key_exists( $orders[$i]->position, $orders2 )) {
 394              $ord =count( array_keys( $orders2[$orders[$i]->position] ) ) + 1;
 395          }
 396  
 397          $orders2[$orders[$i]->position][] = mosHTML::makeOption( $ord, $ord.'::'.addslashes( $orders[$i]->title ) );
 398      }
 399  
 400      // build the html select list
 401      $pos_select = 'onchange="changeDynaList(\'ordering\',orders,document.adminForm.position.options[document.adminForm.position.selectedIndex].value, originalPos, originalOrder)"';
 402      $active = ( $row->position ? $row->position : 'left' );
 403      $lists['position'] = mosHTML::selectList( $pos, 'position', 'class="inputbox" size="1" '. $pos_select, 'value', 'text', $active );
 404  
 405      // get selected pages for $lists['selections']
 406      if ( $uid ) {
 407          $query = "SELECT menuid AS value"
 408          . "\n FROM #__modules_menu"
 409          . "\n WHERE moduleid = " . (int) $row->id
 410          ;
 411          $database->setQuery( $query );
 412          $lookup = $database->loadObjectList();
 413      } else {
 414          $lookup = array( mosHTML::makeOption( 0, 'All' ) );
 415      }
 416  
 417      if ( $row->access == 99 || $row->client_id == 1 || $lists['client_id'] ) {
 418          $lists['access']             = 'Administrator<input type="hidden" name="access" value="99" />';
 419          $lists['showtitle']         = 'N/A <input type="hidden" name="showtitle" value="1" />';
 420          $lists['selections']         = 'N/A';
 421      } else {
 422          if ( $client == 'admin' ) {
 423              $lists['access']         = 'N/A';
 424              $lists['selections']     = 'N/A';
 425          } else {
 426              $lists['access']         = mosAdminMenus::Access( $row );
 427              $lists['selections']     = mosAdminMenus::MenuLinks( $lookup, 1, 1 );
 428          }
 429          $lists['showtitle'] = mosHTML::yesnoRadioList( 'showtitle', 'class="inputbox"', $row->showtitle );
 430      }
 431  
 432      // build the html select list for published
 433      $lists['published']             = mosAdminMenus::Published( $row );
 434  
 435      $row->description = '';
 436      // XML library
 437      require_once ( $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php' );
 438      // xml file for module
 439      $xmlfile = $mainframe->getPath( $path, $row->module );
 440      $xmlDoc = new DOMIT_Lite_Document();
 441      $xmlDoc->resolveErrors( true );
 442      if ($xmlDoc->loadXML( $xmlfile, false, true )) {
 443          $root = &$xmlDoc->documentElement;
 444  
 445          if ($root->getTagName() == 'mosinstall' && $root->getAttribute( 'type' ) == 'module' ) {
 446              $element = &$root->getElementsByPath( 'description', 1 );
 447              $row->description = $element ? trim( $element->getText() ) : '';
 448          }
 449      }
 450  
 451      // get params definitions
 452      $params = new mosParameters( $row->params, $xmlfile, 'module' );
 453  
 454      HTML_modules::editModule( $row, $orders2, $lists, $params, $option );
 455  }
 456  
 457  /**
 458  * Deletes one or more modules
 459  *
 460  * Also deletes associated entries in the #__module_menu table.
 461  * @param array An array of unique category id numbers
 462  */
 463  function removeModule( &$cid, $option, $client ) {
 464      global $database, $my;
 465  
 466      if (count( $cid ) < 1) {
 467          echo "<script> alert('Select a module to delete'); window.history.go(-1);</script>\n";
 468          exit;
 469      }
 470  
 471      mosArrayToInts( $cid );
 472      $cids = 'id=' . implode( ' OR id=', $cid );
 473  
 474      $query = "SELECT id, module, title, iscore, params"
 475      . "\n FROM #__modules WHERE ( $cids )"
 476      ;
 477      $database->setQuery( $query );
 478      if (!($rows = $database->loadObjectList())) {
 479          echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 480          exit;
 481      }
 482  
 483      $err = array();
 484      $cid = array();
 485      foreach ($rows as $row) {
 486          if ($row->module == '' || $row->iscore == 0) {
 487              $cid[] = $row->id;
 488          } else {
 489              $err[] = $row->title;
 490          }
 491          // mod_mainmenu modules only deletable via Menu Manager
 492          if ( $row->module == 'mod_mainmenu' ) {
 493              if ( strstr( $row->params, 'mainmenu' ) ) {
 494                  echo "<script> alert('You cannot delete mod_mainmenu module that displays the \'mainmenu\' as it is a core Menu'); window.history.go(-1); </script>\n";
 495                  exit;
 496              }
 497          }
 498      }
 499  
 500      if (count( $cid )) {
 501          mosArrayToInts( $cid );
 502          $cids = 'id=' . implode( ' OR id=', $cid );
 503          $query = "DELETE FROM #__modules"
 504          . "\n WHERE ( $cids )"
 505          ;
 506          $database->setQuery( $query );
 507          if (!$database->query()) {
 508              echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 509              exit;
 510          }
 511          // mosArrayToInts( $cid ); // just done a few lines earlier
 512          $cids = 'moduleid=' . implode( ' OR moduleid=', $cid );
 513          $query = "DELETE FROM #__modules_menu"
 514          . "\n WHERE ( $cids )"
 515          ;
 516          $database->setQuery( $query );
 517          if (!$database->query()) {
 518              echo "<script> alert('".$database->getErrorMsg()."');</script>\n";
 519              exit;
 520          }
 521          $mod = new mosModule( $database );
 522          $mod->ordering = 0;
 523          $mod->updateOrder( "position='left'" );
 524          $mod->updateOrder( "position='right'" );
 525      }
 526  
 527      if (count( $err )) {
 528          $cids = addslashes( implode( "', '", $err ) );
 529          echo "<script>alert('Module(s): \'$cids\' cannot be deleted they can only be un-installed as they are Joomla! modules.');</script>\n";
 530      }
 531  
 532      mosCache::cleanCache( 'com_content' );
 533      
 534      mosRedirect( 'index2.php?option='. $option .'&client='. $client );
 535  }
 536  
 537  /**
 538  * Publishes or Unpublishes one or more modules
 539  * @param array An array of unique record id numbers
 540  * @param integer 0 if unpublishing, 1 if publishing
 541  */
 542  function publishModule( $cid=null, $publish=1, $option, $client ) {
 543      global $database, $my;
 544  
 545      if (count( $cid ) < 1) {
 546          $action = $publish ? 'publish' : 'unpublish';
 547          echo "<script> alert('Select a module to $action'); window.history.go(-1);</script>\n";
 548          exit;
 549      }
 550  
 551      mosArrayToInts( $cid );
 552      $cids = 'id=' . implode( ' OR id=', $cid );
 553  
 554      $query = "UPDATE #__modules"
 555      . "\n SET published = " . (int) $publish
 556      . "\n WHERE ( $cids )"
 557      . "\n AND ( checked_out = 0 OR ( checked_out = " . (int) $my->id . " ) )"
 558      ;
 559      $database->setQuery( $query );
 560      if (!$database->query()) {
 561          echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 562          exit();
 563      }
 564  
 565      if (count( $cid ) == 1) {
 566          $row = new mosModule( $database );
 567          $row->checkin( $cid[0] );
 568      }
 569  
 570      mosCache::cleanCache( 'com_content' );
 571      
 572      mosRedirect( 'index2.php?option='. $option .'&client='. $client );
 573  }
 574  
 575  /**
 576  * Cancels an edit operation
 577  */
 578  function cancelModule( $option, $client ) {
 579      global $database;
 580  
 581      $row = new mosModule( $database );
 582      // ignore array elements
 583      $row->bind( $_POST, 'selections params' );
 584      $row->checkin();
 585  
 586      mosRedirect( 'index2.php?option='. $option .'&client='. $client );
 587  }
 588  
 589  /**
 590  * Moves the order of a record
 591  * @param integer The unique id of record
 592  * @param integer The increment to reorder by
 593  */
 594  function orderModule( $uid, $inc, $option ) {
 595      global $database;
 596  
 597      $client = strval( mosGetParam( $_POST, 'client', '' ) );
 598  
 599      $row = new mosModule( $database );
 600      $row->load( (int)$uid );
 601      if ($client == 'admin') {
 602          $where = "client_id = 1";
 603      } else {
 604          $where = "client_id = 0";
 605      }
 606  
 607      $row->move( $inc, "position = " . $database->Quote( $row->position ) . " AND ( $where )"  );
 608      if ( $client ) {
 609          $client = '&client=admin' ;
 610      } else {
 611          $client = '';
 612      }
 613  
 614      mosCache::cleanCache( 'com_content' );
 615      
 616      mosRedirect( 'index2.php?option='. $option .'&client='. $client );
 617  }
 618  
 619  /**
 620  * changes the access level of a record
 621  * @param integer The increment to reorder by
 622  */
 623  function accessMenu( $uid, $access, $option, $client ) {
 624      global $database;
 625  
 626      switch ( $access ) {
 627          case 'accesspublic':
 628              $access = 0;
 629              break;
 630  
 631          case 'accessregistered':
 632              $access = 1;
 633              break;
 634  
 635          case 'accessspecial':
 636              $access = 2;
 637              break;
 638      }
 639  
 640      $row = new mosModule( $database );
 641      $row->load( (int)$uid );
 642      $row->access = $access;
 643  
 644      if ( !$row->check() ) {
 645          return $row->getError();
 646      }
 647      if ( !$row->store() ) {
 648          return $row->getError();
 649      }
 650  
 651      mosCache::cleanCache( 'com_content' );
 652      
 653      mosRedirect( 'index2.php?option='. $option .'&client='. $client );
 654  }
 655  
 656  function saveOrder( &$cid, $client ) {
 657      global $database;
 658  
 659      $total        = count( $cid );
 660      $order         = josGetArrayInts( 'order' );
 661      
 662      $row         = new mosModule( $database );
 663      $conditions = array();
 664  
 665      // update ordering values
 666      for( $i=0; $i < $total; $i++ ) {
 667          $row->load( (int) $cid[$i] );
 668          if ($row->ordering != $order[$i]) {
 669              $row->ordering = $order[$i];
 670              if (!$row->store()) {
 671                  echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 672                  exit();
 673              } // if
 674              // remember to updateOrder this group
 675              $condition = "position = " . $database->Quote( $row->position ) . " AND client_id = " . (int) $row->client_id;
 676              $found = false;
 677              foreach ( $conditions as $cond )
 678                  if ($cond[1]==$condition) {
 679                      $found = true;
 680                      break;
 681                  } // if
 682              if (!$found) $conditions[] = array($row->id, $condition);
 683          } // if
 684      } // for
 685  
 686      // execute updateOrder for each group
 687      foreach ( $conditions as $cond ) {
 688          $row->load( $cond[0] );
 689          $row->updateOrder( $cond[1] );
 690      } // foreach
 691  
 692      mosCache::cleanCache( 'com_content' );
 693      
 694      $msg     = 'New ordering saved';
 695      mosRedirect( 'index2.php?option=com_modules&client='. $client, $msg );
 696  } // saveOrder
 697  ?>


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