[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/administrator/components/com_sections/ -> admin.sections.php (source)

   1  <?php
   2  /**
   3  * @version $Id: admin.sections.php 5876 2006-11-29 00:21:35Z facedancer $
   4  * @package Joomla
   5  * @subpackage Sections
   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( 'admin_html' ) );
  19  
  20  define( 'COM_IMAGE_BASE', $mosConfig_absolute_path . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'stories' );
  21  
  22  // get parameters from the URL or submitted form
  23  $scope         = stripslashes( mosGetParam( $_REQUEST, 'scope', '' ) );
  24  $section     = stripslashes( mosGetParam( $_REQUEST, 'scope', '' ) );
  25  
  26  $cid         = josGetArrayInts( 'cid' );
  27  
  28  switch ($task) {
  29      case 'new':
  30          editSection( 0, $scope, $option );
  31          break;
  32  
  33      case 'edit':
  34          editSection( intval( $cid[0] ), '', $option );
  35          break;
  36  
  37      case 'editA':
  38          editSection( $id, '', $option );
  39          break;
  40  
  41      case 'go2menu':
  42      case 'go2menuitem':
  43      case 'menulink':
  44      case 'save':
  45      case 'apply':
  46          saveSection( $option, $scope, $task );
  47          break;
  48  
  49      case 'remove':
  50          removeSections( $cid, $scope, $option );
  51          break;
  52  
  53      case 'copyselect':
  54          copySectionSelect( $option, $cid, $section );
  55          break;
  56  
  57      case 'copysave':
  58          copySectionSave( $cid );
  59          break;
  60  
  61      case 'publish':
  62          publishSections( $scope, $cid, 1, $option );
  63          break;
  64  
  65      case 'unpublish':
  66          publishSections( $scope, $cid, 0, $option );
  67          break;
  68  
  69      case 'cancel':
  70          cancelSection( $option, $scope );
  71          break;
  72  
  73      case 'orderup':
  74          orderSection( intval( $cid[0] ), -1, $option, $scope );
  75          break;
  76  
  77      case 'orderdown':
  78          orderSection( intval( $cid[0] ), 1, $option, $scope );
  79          break;
  80  
  81      case 'accesspublic':
  82          accessMenu( intval( $cid[0] ), 0, $option );
  83          break;
  84  
  85      case 'accessregistered':
  86          accessMenu( intval( $cid[0] ), 1, $option );
  87          break;
  88  
  89      case 'accessspecial':
  90          accessMenu( intval( $cid[0] ), 2, $option );
  91          break;
  92  
  93      case 'saveorder':
  94          saveOrder( $cid );
  95          break;
  96  
  97      default:
  98          showSections( $scope, $option );
  99          break;
 100  }
 101  
 102  /**
 103  * Compiles a list of categories for a section
 104  * @param database A database connector object
 105  * @param string The name of the category section
 106  * @param string The name of the current user
 107  */
 108  function showSections( $scope, $option ) {
 109      global $database, $my, $mainframe, $mosConfig_list_limit;
 110  
 111      $limit         = intval( $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ) );
 112      $limitstart = intval( $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 ) );
 113  
 114      // get the total number of records
 115      $query = "SELECT COUNT(*)"
 116      . "\n FROM #__sections"
 117      . "\n WHERE scope = " . $database->Quote( $scope )
 118      ;
 119      $database->setQuery( $query );
 120      $total = $database->loadResult();
 121  
 122      require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
 123      $pageNav = new mosPageNav( $total, $limitstart, $limit );
 124  
 125      $query = "SELECT c.*, g.name AS groupname, u.name AS editor"
 126      . "\n FROM #__sections AS c"
 127      . "\n LEFT JOIN #__content AS cc ON c.id = cc.sectionid"
 128      . "\n LEFT JOIN #__users AS u ON u.id = c.checked_out"
 129      . "\n LEFT JOIN #__groups AS g ON g.id = c.access"
 130      . "\n WHERE scope = " . $database->Quote( $scope )
 131      . "\n GROUP BY c.id"
 132      . "\n ORDER BY c.ordering, c.name"
 133      ;
 134      $database->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
 135      $rows = $database->loadObjectList();
 136      if ($database->getErrorNum()) {
 137          echo $database->stderr();
 138          return false;
 139      }
 140  
 141      $count = count( $rows );
 142      // number of Active Items
 143      for ( $i = 0; $i < $count; $i++ ) {
 144          $query = "SELECT COUNT( a.id )"
 145          . "\n FROM #__categories AS a"
 146          . "\n WHERE a.section = '" . (int) $rows[$i]->id . "'"
 147          . "\n AND a.published != -2"
 148          ;
 149          $database->setQuery( $query );
 150          $active = $database->loadResult();
 151          $rows[$i]->categories = $active;
 152      }
 153      // number of Active Items
 154      for ( $i = 0; $i < $count; $i++ ) {
 155          $query = "SELECT COUNT( a.id )"
 156          . "\n FROM #__content AS a"
 157          . "\n WHERE a.sectionid = " . (int) $rows[$i]->id
 158          . "\n AND a.state != -2"
 159          ;
 160          $database->setQuery( $query );
 161          $active = $database->loadResult();
 162          $rows[$i]->active = $active;
 163      }
 164      // number of Trashed Items
 165      for ( $i = 0; $i < $count; $i++ ) {
 166          $query = "SELECT COUNT( a.id )"
 167          . "\n FROM #__content AS a"
 168          . "\n WHERE a.sectionid = " . (int) $rows[$i]->id
 169          . "\n AND a.state = -2"
 170          ;
 171          $database->setQuery( $query );
 172          $trash = $database->loadResult();
 173          $rows[$i]->trash = $trash;
 174      }
 175  
 176      sections_html::show( $rows, $scope, $my->id, $pageNav, $option );
 177  }
 178  
 179  /**
 180  * Compiles information to add or edit a section
 181  * @param database A database connector object
 182  * @param string The name of the category section
 183  * @param integer The unique id of the category to edit (0 if new)
 184  * @param string The name of the current user
 185  */
 186  function editSection( $uid=0, $scope='', $option ) {
 187      global $database, $my, $mainframe;
 188  
 189      $row = new mosSection( $database );
 190      // load the row from the db table
 191      $row->load( (int)$uid );
 192  
 193      // fail if checked out not by 'me'
 194      if ($row->isCheckedOut( $my->id )) {
 195          $msg = 'The section '. $row->title .' is currently being edited by another administrator';
 196          mosRedirect( 'index2.php?option='. $option .'&scope='. $row->scope .'&mosmsg='. $msg );
 197      }
 198  
 199      $selected_folders = NULL;
 200      if ( $uid ) {
 201          $row->checkout( $my->id );
 202          if ( $row->id > 0 ) {
 203              $query = "SELECT *"
 204              . "\n FROM #__menu"
 205              . "\n WHERE componentid = " . (int) $row->id
 206              . "\n AND ( type = 'content_archive_section' OR type = 'content_blog_section' OR type = 'content_section' )"
 207              ;
 208              $database->setQuery( $query );
 209              $menus = $database->loadObjectList();
 210              $count = count( $menus );
 211              for( $i = 0; $i < $count; $i++ ) {
 212                  switch ( $menus[$i]->type ) {
 213                      case 'content_section':
 214                          $menus[$i]->type = 'Section Table';
 215                          break;
 216  
 217                      case 'content_blog_section':
 218                          $menus[$i]->type = 'Section Blog';
 219                          break;
 220  
 221                      case 'content_archive_section':
 222                          $menus[$i]->type = 'Section Blog Archive';
 223                          break;
 224                  }
 225              }
 226          } else {
 227              $menus = array();
 228          }
 229  
 230          // handling for MOSImage directories
 231          if ( trim( $row->params ) ) {
 232              // get params definitions
 233              $params = new mosParameters( $row->params, $mainframe->getPath( 'com_xml', 'com_sections' ), 'component' );
 234              $temps     = $params->get( 'imagefolders', '' );
 235  
 236              $temps     = explode( ',', $temps );
 237              foreach( $temps as $temp ) {
 238                  $selected_folders[] = mosHTML::makeOption( $temp, $temp );
 239              }
 240          } else {
 241              $selected_folders[] = mosHTML::makeOption( '*1*' );
 242          }
 243      } else {
 244          $row->scope         = $scope;
 245          $row->published     = 1;
 246          $menus                 = array();
 247  
 248          // handling for MOSImage directories
 249          $selected_folders[]    = mosHTML::makeOption( '*1*' );
 250      }
 251  
 252      // build the html select list for section types
 253      $types[] = mosHTML::makeOption( '', 'Select Type' );
 254      $types[] = mosHTML::makeOption( 'content_section', 'Section List' );
 255      $types[] = mosHTML::makeOption( 'content_blog_section', 'Section Blog' );
 256      $types[] = mosHTML::makeOption( 'content_archive_section', 'Section Archive Blog' );
 257      $lists['link_type']         = mosHTML::selectList( $types, 'link_type', 'class="inputbox" size="1"', 'value', 'text' );;
 258  
 259      // build the html select list for ordering
 260      $query = "SELECT ordering AS value, title AS text"
 261      . "\n FROM #__sections"
 262      . "\n WHERE scope=" . $database->Quote( $row->scope ) . " ORDER BY ordering"
 263      ;
 264      $lists['ordering']             = mosAdminMenus::SpecificOrdering( $row, $uid, $query );
 265  
 266      // build the select list for the image positions
 267      $active =  ( $row->image_position ? $row->image_position : 'left' );
 268      $lists['image_position']     = mosAdminMenus::Positions( 'image_position', $active, NULL, 0 );
 269      // build the html select list for images
 270      $lists['image']             = mosAdminMenus::Images( 'image', $row->image );
 271      // build the html select list for the group access
 272      $lists['access']             = mosAdminMenus::Access( $row );
 273      // build the html radio buttons for published
 274      $lists['published']         = mosHTML::yesnoRadioList( 'published', 'class="inputbox"', $row->published );
 275      // build the html select list for menu selection
 276      $lists['menuselect']        = mosAdminMenus::MenuSelect( );
 277  
 278      // list of folders in images/stories/
 279      $imgFiles     = recursive_listdir( COM_IMAGE_BASE );
 280      $len         = strlen( COM_IMAGE_BASE );
 281  
 282      // handling for MOSImage directories
 283      $folders[]     = mosHTML::makeOption( '*1*', 'All'  );
 284      $folders[]     = mosHTML::makeOption( '*0*', 'None' );
 285      $folders[]     = mosHTML::makeOption( '*#*', '---------------------' );
 286      $folders[]     = mosHTML::makeOption( '/' );
 287      foreach ($imgFiles as $file) {
 288          $folders[] = mosHTML::makeOption( substr( $file, $len ) );
 289      }
 290  
 291      $lists['folders'] = mosHTML::selectList( $folders, 'folders[]', 'class="inputbox" size="17" multiple="multiple"', 'value', 'text', $selected_folders );
 292  
 293      sections_html::edit( $row, $option, $lists, $menus );
 294  }
 295  
 296  /**
 297  * Saves the catefory after an edit form submit
 298  * @param database A database connector object
 299  * @param string The name of the category section
 300  */
 301  function saveSection( $option, $scope, $task ) {
 302      global $database;
 303  
 304      $menu         = stripslashes( strval( mosGetParam( $_POST, 'menu', 'mainmenu' ) ) );
 305      $menuid        = intval( mosGetParam( $_POST, 'menuid', 0 ) );
 306      $oldtitle     = stripslashes( strval( mosGetParam( $_POST, 'oldtitle', null ) ) );
 307  
 308      $row = new mosSection( $database );
 309      if (!$row->bind( $_POST )) {
 310          echo "<script> alert('".$row->getError()."'); document.location.href='index2.php?option=$option&scope=$scope&task=new'; </script>\n";
 311          exit();
 312      }
 313      if (!$row->check()) {
 314          echo "<script> alert('".$row->getError()."'); document.location.href='index2.php?option=$option&scope=$scope&task=new'; </script>\n";
 315          exit();
 316      }
 317      if ( $oldtitle ) {
 318          if ( $oldtitle != $row->title ) {
 319              $query = "UPDATE #__menu"
 320              . "\n SET name = " . $database->Quote( $row->title )
 321              . "\n WHERE name = " . $database->Quote( $oldtitle )
 322              . "\n AND type = 'content_section'"
 323              ;
 324              $database->setQuery( $query );
 325              $database->query();
 326          }
 327      }
 328  
 329      // handling for MOSImage directories
 330      $folders         = mosGetParam( $_POST, 'folders', array() );
 331      $folders         = implode( ',', $folders );
 332      if ( strpos( $folders, '*1*' ) !== false  ) {
 333          $folders     = '*1*';
 334      } else if ( strpos( $folders, '*0*' ) !== false ) {
 335          $folders    = '*0*';
 336      } else if ( strpos( $folders, ',*#*' ) !== false ) {
 337          $folders     = str_replace( ',*#*', '', $folders );
 338      } else if ( strpos( $folders, '*#*,' ) !== false ) {
 339          $folders     = str_replace( '*#*,', '', $folders );
 340      } else if ( strpos( $folders, '*#*' ) !== false ) {
 341          $folders     = str_replace( '*#*', '', $folders );
 342      }
 343      $row->params    = 'imagefolders='. $folders;
 344  
 345      if (!$row->store()) {
 346          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 347          exit();
 348      }
 349      $row->checkin();
 350      $row->updateOrder( 'scope=' . $database->Quote( $row->scope ) );
 351  
 352      // clean any existing cache files
 353      mosCache::cleanCache( 'com_content' );
 354  
 355      switch ( $task ) {
 356          case 'go2menu':
 357              mosRedirect( 'index2.php?option=com_menus&menutype='. $menu );
 358              break;
 359  
 360          case 'go2menuitem':
 361              mosRedirect( 'index2.php?option=com_menus&menutype='. $menu .'&task=edit&hidemainmenu=1&id='. $menuid );
 362              break;
 363  
 364          case 'menulink':
 365              menuLink( $row->id );
 366              break;
 367  
 368          case 'apply':
 369              $msg = 'Changes to Section saved';
 370              mosRedirect( 'index2.php?option='. $option .'&scope='. $scope .'&task=editA&hidemainmenu=1&id='. $row->id, $msg );
 371              break;
 372  
 373          case 'save':
 374          default:
 375              $msg = 'Section saved';
 376              mosRedirect( 'index2.php?option='. $option .'&scope='. $scope, $msg );
 377              break;
 378      }
 379  }
 380  /**
 381  * Deletes one or more categories from the categories table
 382  * @param database A database connector object
 383  * @param string The name of the category section
 384  * @param array An array of unique category id numbers
 385  */
 386  function removeSections( $cid, $scope, $option ) {
 387      global $database;
 388  
 389      if (count( $cid ) < 1) {
 390          echo "<script> alert('Select a section to delete'); window.history.go(-1);</script>\n";
 391          exit;
 392      }
 393  
 394      mosArrayToInts( $cid );
 395      $cids = 's.id=' . implode( ' OR s.id=', $cid );
 396  
 397      $query = "SELECT s.id, s.name, COUNT(c.id) AS numcat"
 398      . "\n FROM #__sections AS s"
 399      . "\n LEFT JOIN #__categories AS c ON c.section=s.id"
 400      . "\n WHERE ( $cids )"
 401      . "\n GROUP BY s.id"
 402      ;
 403      $database->setQuery( $query );
 404      if (!($rows = $database->loadObjectList())) {
 405          echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 406      }
 407  
 408      $err = array();
 409      $cid = array();
 410      foreach ($rows as $row) {
 411          if ($row->numcat == 0) {
 412              $cid[] = $row->id;
 413              $name[] = $row->name;
 414          } else {
 415              $err[] = $row->name;
 416          }
 417      }
 418  
 419      if (count( $cid )) {
 420          mosArrayToInts( $cid );
 421          $cids = 'id=' . implode( ' OR id=', $cid );
 422          $query = "DELETE FROM #__sections"
 423          . "\n WHERE ( $cids )"
 424          ;
 425          $database->setQuery( $query );
 426          if (!$database->query()) {
 427              echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 428          }
 429      }
 430  
 431      if (count( $err )) {
 432          $cids = implode( ', ', $err );
 433          $msg = 'Sections(s): '. $cids .' cannot be removed as they contain categories';
 434          mosRedirect( 'index2.php?option='. $option .'&scope='. $scope, $msg );
 435      }
 436  
 437      // clean any existing cache files
 438      mosCache::cleanCache( 'com_content' );
 439  
 440      $names = implode( ', ', $name );
 441      $msg = 'Section(s): '. $names .' successfully deleted';
 442      mosRedirect( 'index2.php?option='. $option .'&scope='. $scope, $msg );
 443  }
 444  
 445  /**
 446  * Publishes or Unpublishes one or more categories
 447  * @param database A database connector object
 448  * @param string The name of the category section
 449  * @param integer A unique category id (passed from an edit form)
 450  * @param array An array of unique category id numbers
 451  * @param integer 0 if unpublishing, 1 if publishing
 452  * @param string The name of the current user
 453  */
 454  function publishSections( $scope, $cid=null, $publish=1, $option ) {
 455      global $database, $my;
 456  
 457      if ( !is_array( $cid ) || count( $cid ) < 1 ) {
 458          $action = $publish ? 'publish' : 'unpublish';
 459          echo "<script> alert('Select a section to $action'); window.history.go(-1);</script>\n";
 460          exit;
 461      }
 462  
 463      $count = count( $cid );
 464      if ( $publish ) {
 465          if ( !$count ){
 466              echo "<script> alert('Cannot Publish an Empty Section $count'); window.history.go(-1);</script>\n";
 467              return;
 468          }
 469      }
 470  
 471      mosArrayToInts( $cid );
 472      $cids = 'id=' . implode( ' OR id=', $cid );
 473  
 474      $query = "UPDATE #__sections"
 475      . "\n SET published = " . (int) $publish
 476      . "\n WHERE ( $cids )"
 477      . "\n AND ( checked_out = 0 OR ( checked_out = " . (int) $my->id  . " ) )"
 478      ;
 479      $database->setQuery( $query );
 480      if (!$database->query()) {
 481          echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 482          exit();
 483      }
 484  
 485      if ( $count == 1 ) {
 486          $row = new mosSection( $database );
 487          $row->checkin( $cid[0] );
 488      }
 489  
 490      // check if section linked to menu items if unpublishing
 491      if ( $publish == 0 ) {
 492          mosArrayToInts( $cid );
 493          $cids = 'componentid=' . implode( ' OR componentid=', $cid );
 494          $query = "SELECT id"
 495          . "\n FROM #__menu"
 496          . "\n WHERE type = 'content_section'"
 497          . "\n AND ( $cids )"
 498          ;
 499          $database->setQuery( $query );
 500          $menus = $database->loadObjectList();
 501  
 502          if ($menus) {
 503              foreach ($menus as $menu) {
 504                  $query = "UPDATE #__menu"
 505                  . "\n SET published = " . (int) $publish
 506                  . "\n WHERE id = " . (int) $menu->id
 507                  ;
 508                  $database->setQuery( $query );
 509                  $database->query();
 510              }
 511          }
 512      }
 513  
 514      // clean any existing cache files
 515      mosCache::cleanCache( 'com_content' );
 516  
 517      mosRedirect( 'index2.php?option='. $option .'&scope='. $scope );
 518  }
 519  
 520  /**
 521  * Cancels an edit operation
 522  * @param database A database connector object
 523  * @param string The name of the category section
 524  * @param integer A unique category id
 525  */
 526  function cancelSection( $option, $scope ) {
 527      global $database;
 528      $row = new mosSection( $database );
 529      $row->bind( $_POST );
 530      $row->checkin();
 531  
 532      mosRedirect( 'index2.php?option='. $option .'&scope='. $scope );
 533  }
 534  
 535  /**
 536  * Moves the order of a record
 537  * @param integer The increment to reorder by
 538  */
 539  function orderSection( $uid, $inc, $option, $scope ) {
 540      global $database;
 541  
 542      $row = new mosSection( $database );
 543      $row->load( (int)$uid );
 544      $row->move( $inc, "scope = " . $database->Quote( $row->scope ) );
 545  
 546      // clean any existing cache files
 547      mosCache::cleanCache( 'com_content' );
 548  
 549      mosRedirect( 'index2.php?option='. $option .'&scope='. $scope );
 550  }
 551  
 552  
 553  /**
 554  * Form for copying item(s) to a specific menu
 555  */
 556  function copySectionSelect( $option, $cid, $section ) {
 557      global $database;
 558  
 559      if (!is_array( $cid ) || count( $cid ) < 1) {
 560          echo "<script> alert('Select an item to move'); window.history.go(-1);</script>\n";
 561          exit;
 562      }
 563  
 564      ## query to list selected categories
 565      mosArrayToInts( $cid );
 566      $cids = 'a.section=' . implode( ' OR a.section=', $cid );
 567      $query = "SELECT a.name, a.id"
 568      . "\n FROM #__categories AS a"
 569      . "\n WHERE ( $cids )"
 570      ;
 571      $database->setQuery( $query );
 572      $categories = $database->loadObjectList();
 573  
 574      ## query to list items from categories
 575      //mosArrayToInts( $cid ); // Just done a few lines earlier
 576      $cids = 'a.sectionid=' . implode( ' OR a.sectionid=', $cid );
 577      $query = "SELECT a.title, a.id"
 578      . "\n FROM #__content AS a"
 579      . "\n WHERE ( $cids )"
 580      . "\n ORDER BY a.sectionid, a.catid, a.title"
 581      ;
 582      $database->setQuery( $query );
 583      $contents = $database->loadObjectList();
 584  
 585      sections_html::copySectionSelect( $option, $cid, $categories, $contents, $section );
 586  }
 587  
 588  
 589  /**
 590  * Save the item(s) to the menu selected
 591  */
 592  function copySectionSave( $sectionid ) {
 593      global $database;
 594  
 595      $title         = stripslashes( strval( mosGetParam( $_REQUEST, 'title', '' ) ) );
 596      $categories = josGetArrayInts( 'category', $_REQUEST, array(0) );
 597      $items         = josGetArrayInts( 'content', $_REQUEST, array(0) );
 598  
 599      // create new section
 600  
 601      $section = new mosSection ( $database );
 602      $section->id = null;
 603      $section->title = $title;
 604      $section->name     = $title;
 605      $section->scope = 'content';
 606      $section->published = 1;
 607      if ( !$section->check() ) {
 608          echo "<script> alert('".$section->getError()."'); window.history.go(-1); </script>\n";
 609          exit();
 610      }
 611      if ( !$section->store() ) {
 612          echo "<script> alert('".$section->getError()."'); window.history.go(-1); </script>\n";
 613          exit();
 614      }
 615      $section->checkin();
 616      $newSectionId = $section->id;
 617  
 618  
 619      // new section created, now copy categories
 620  
 621      // old/new category lookup array
 622      $newOldCatLookup = array();
 623  
 624      foreach( $categories as $categoryId ) {
 625          $category = new mosCategory( $database );
 626          $category->load( $categoryId );
 627          $category->id = null;
 628          $category->section = $newSectionId;
 629  
 630          if (!$category->check()) {
 631              echo "<script> alert('".$category->getError()."'); window.history.go(-1); </script>\n";
 632              exit();
 633          }
 634          if (!$category->store()) {
 635              echo "<script> alert('".$category->getError()."'); window.history.go(-1); </script>\n";
 636              exit();
 637          }
 638          $category->checkin();
 639          $newOldCatLookup[$categoryId] = $category->id;
 640      }
 641  
 642      // categories copied, now copy content items
 643  
 644      foreach( $items as $itemId ) {
 645          $item = new mosContent( $database );
 646          $item->load( $itemId );
 647  
 648          $item->id = null;
 649          $item->catid = $newOldCatLookup[$item->catid];
 650          $item->sectionid = $newSectionId;
 651          if (!$item->check()) {
 652              echo "<script> alert('".$item->getError()."'); window.history.go(-1); </script>\n";
 653              exit();
 654          }
 655          if (!$item->store()) {
 656              echo "<script> alert('".$item->getError()."'); window.history.go(-1); </script>\n";
 657              exit();
 658          }
 659          $item->checkin();
 660      }
 661  
 662      $msg = 'Selected sections content copied into '. $title .' section.';
 663      mosRedirect( 'index2.php?option=com_sections&scope=content&mosmsg='. $msg );
 664  }
 665  
 666  /**
 667  * changes the access level of a record
 668  * @param integer The increment to reorder by
 669  */
 670  function accessMenu( $uid, $access, $option ) {
 671      global $database;
 672  
 673      $row = new mosSection( $database );
 674      $row->load( (int)$uid );
 675      $row->access = $access;
 676  
 677      if ( !$row->check() ) {
 678          return $row->getError();
 679      }
 680      if ( !$row->store() ) {
 681          return $row->getError();
 682      }
 683  
 684      // clean any existing cache files
 685      mosCache::cleanCache( 'com_content' );
 686  
 687      mosRedirect( 'index2.php?option='. $option .'&scope='. $row->scope );
 688  }
 689  
 690  function menuLink( $id ) {
 691      global $database;
 692  
 693      $section = new mosSection( $database );
 694      $section->bind( $_POST );
 695      $section->checkin();
 696  
 697      $menu     = strval( mosGetParam( $_POST, 'menuselect', '' ) );
 698      $name     = strval( mosGetParam( $_POST, 'link_name', '' ) );
 699      $type     = strval( mosGetParam( $_POST, 'link_type', '' ) );
 700  
 701      $name    = stripslashes( ampReplace($name) );
 702  
 703      switch ( $type ) {
 704          case 'content_section':
 705              $link         = 'index.php?option=com_content&task=section&id='. $id;
 706              $menutype    = 'Section Table';
 707              break;
 708  
 709          case 'content_blog_section':
 710              $link         = 'index.php?option=com_content&task=blogsection&id='. $id;
 711              $menutype    = 'Section Blog';
 712              break;
 713  
 714          case 'content_archive_section':
 715              $link         = 'index.php?option=com_content&task=archivesection&id='. $id;
 716              $menutype    = 'Section Blog Archive';
 717              break;
 718      }
 719  
 720      $row                 = new mosMenu( $database );
 721      $row->menutype         = $menu;
 722      $row->name             = $name;
 723      $row->type             = $type;
 724      $row->published        = 1;
 725      $row->componentid    = $id;
 726      $row->link            = $link;
 727      $row->ordering        = 9999;
 728  
 729      if ( $type == 'content_blog_section' ) {
 730          $row->params = 'sectionid='. $id;
 731      }
 732  
 733      if (!$row->check()) {
 734          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 735          exit();
 736      }
 737      if (!$row->store()) {
 738          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 739          exit();
 740      }
 741      $row->checkin();
 742      $row->updateOrder( "menutype = " . $database->Quote( $menu ) );
 743  
 744      // clean any existing cache files
 745      mosCache::cleanCache( 'com_content' );
 746  
 747      $msg = $name .' ( '. $menutype .' ) in menu: '. $menu .' successfully created';
 748      mosRedirect( 'index2.php?option=com_sections&scope=content&task=editA&hidemainmenu=1&id='. $id,  $msg );
 749  }
 750  
 751  function saveOrder( &$cid ) {
 752      global $database;
 753  
 754      $total        = count( $cid );
 755      $order         = josGetArrayInts( 'order' );
 756  
 757      $row         = new mosSection( $database );
 758      $conditions = array();
 759  
 760      // update ordering values
 761      for( $i=0; $i < $total; $i++ ) {
 762          $row->load( (int) $cid[$i] );
 763          if ($row->ordering != $order[$i]) {
 764              $row->ordering = $order[$i];
 765              if (!$row->store()) {
 766                  echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 767                  exit();
 768              } // if
 769              // remember to updateOrder this group
 770              $condition = "scope = " . $database->Quote( $row->scope );
 771              $found = false;
 772              foreach ( $conditions as $cond )
 773                  if ($cond[1]==$condition) {
 774                      $found = true;
 775                      break;
 776                  } // if
 777              if (!$found) $conditions[] = array($row->id, $condition);
 778          } // if
 779      } // for
 780  
 781      // execute updateOrder for each group
 782      foreach ( $conditions as $cond ) {
 783          $row->load( $cond[0] );
 784          $row->updateOrder( $cond[1] );
 785      } // foreach
 786  
 787      // clean any existing cache files
 788      mosCache::cleanCache( 'com_content' );
 789  
 790      $msg     = 'New ordering saved';
 791      mosRedirect( 'index2.php?option=com_sections&scope=content', $msg );
 792  } // saveOrder
 793  
 794  function recursive_listdir( $base ) {
 795      static $filelist = array();
 796      static $dirlist = array();
 797  
 798      if(is_dir($base)) {
 799          $dh = opendir($base);
 800          while (false !== ($dir = readdir($dh))) {
 801              if ($dir !== '.' && $dir !== '..' && is_dir($base .'/'. $dir) && strtolower($dir) !== 'cvs' && strtolower($dir) !== '.svn') {
 802                  $subbase = $base .'/'. $dir;
 803                  $dirlist[] = $subbase;
 804                  $subdirlist = recursive_listdir($subbase);
 805              }
 806          }
 807          closedir($dh);
 808      }
 809      return $dirlist;
 810  }
 811  ?>


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