[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

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

   1  <?php
   2  /**
   3  * @package Mambo
   4  * @subpackage Sections
   5  * @author Mambo Foundation Inc see README.php
   6  * @copyright (C) 2000 - 2009 Mambo Foundation Inc.
   7  * See COPYRIGHT.php for copyright notices and details.
   8  * @license GNU/GPL Version 2, see LICENSE.php
   9  *
  10  * Redistributions of files must retain the above copyright notice.
  11  *
  12  * Mambo is free software; you can redistribute it and/or
  13  * modify it under the terms of the GNU General Public License
  14  * as published by the Free Software Foundation; version 2 of the License.
  15  */
  16  
  17  /** ensure this file is being included by a parent file */
  18  defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  19  
  20  require_once( $mainframe->getPath( 'admin_html' ) );
  21  require_once ($mosConfig_absolute_path.'/components/com_content/content.class.php');
  22  
  23  // get parameters from the URL or submitted form
  24  $scope         = mosGetParam( $_REQUEST, 'scope', '' );
  25  $cid         = mosGetParam( $_REQUEST, 'cid', array(0) );
  26  $section     = mosGetParam( $_REQUEST, 'scope', '' );
  27  if (!is_array( $cid )) {
  28      $cid = array(0);
  29  }
  30  
  31  switch ($task) {
  32      case 'new':
  33          editSection( 0, $scope, $option );
  34          break;
  35  
  36      case 'edit':
  37          editSection( $cid[0], '', $option );
  38          break;
  39  
  40      case 'editA':
  41          editSection( $id, '', $option );
  42          break;
  43  
  44      case 'go2menu':
  45      case 'go2menuitem':
  46      case 'menulink':
  47      case 'save':
  48      case 'apply':
  49          saveSection( $option, $scope, $task );
  50          break;
  51  
  52      case 'remove':
  53          removeSections( $cid, $scope, $option );
  54          break;
  55  
  56      case 'copyselect':
  57          copySectionSelect( $option, $cid, $section );
  58          break;
  59  
  60      case 'copysave':
  61          copySectionSave( $cid );
  62          break;
  63  
  64      case 'publish':
  65          publishSections( $scope, $cid, 1, $option );
  66          break;
  67  
  68      case 'unpublish':
  69          publishSections( $scope, $cid, 0, $option );
  70          break;
  71  
  72      case 'cancel':
  73          cancelSection( $option, $scope );
  74          break;
  75  
  76      case 'orderup':
  77          orderSection( $cid[0], -1, $option, $scope );
  78          break;
  79  
  80      case 'orderdown':
  81          orderSection( $cid[0], 1, $option, $scope );
  82          break;
  83  
  84      case 'accesspublic':
  85          accessMenu( $cid[0], 0, $option );
  86          break;
  87  
  88      case 'accessregistered':
  89          accessMenu( $cid[0], 1, $option );
  90          break;
  91  
  92      case 'accessspecial':
  93          accessMenu( $cid[0], 2, $option );
  94          break;
  95  
  96      case 'saveorder':
  97          saveOrder( $cid );
  98          break;
  99  
 100      default:
 101          showSections( $scope, $option );
 102          break;
 103  }
 104  
 105  /**
 106  * Compiles a list of categories for a section
 107  * @param database A database connector object
 108  * @param string The name of the category section
 109  * @param string The name of the current user
 110  */
 111  function showSections( $scope, $option ) {
 112      global $database, $my, $mainframe, $mosConfig_list_limit;
 113  
 114      $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit );
 115      $limitstart = $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 );
 116  
 117      // get the total number of records
 118      // @RawSQLUse, trivial_implementation, SELECT
 119      $database->setQuery( "SELECT count(*) FROM #__sections WHERE scope='$scope'" );
 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='$scope'"
 131      . "\n GROUP BY c.id"
 132      . "\n ORDER BY c.ordering, c.name"
 133      . "\n LIMIT $pageNav->limitstart,$pageNav->limit"
 134      ;
 135      $database->setQuery( $query );
 136      $rows = $database->loadObjectList();
 137      if ($rows) {
 138          foreach($rows as $row) {
 139              $row->title = htmlspecialchars( str_replace( '&amp;', '&', $row->title ) );
 140              $row->name = htmlspecialchars( str_replace( '&amp;', '&', $row->name ) );
 141          }
 142      }
 143      if ($database->getErrorNum()) {
 144          echo $database->stderr();
 145          return false;
 146      }
 147  
 148      $count = count( $rows );
 149      // number of Active Items
 150      for ( $i = 0; $i < $count; $i++ ) {
 151          $query = "SELECT COUNT( a.id )"
 152          . "\n FROM #__categories AS a"
 153          . "\n WHERE a.section = ". $rows[$i]->id
 154          . "\n AND a.published <> '-2'"
 155          ;
 156          $database->setQuery( $query );
 157          $active = $database->loadResult();
 158          $rows[$i]->categories = $active;
 159      }
 160      // number of Active Items
 161      for ( $i = 0; $i < $count; $i++ ) {
 162          $query = "SELECT COUNT( a.id )"
 163          . "\n FROM #__content AS a"
 164          . "\n WHERE a.sectionid = ". $rows[$i]->id
 165          . "\n AND a.state <> '-2'"
 166          ;
 167          $database->setQuery( $query );
 168          $active = $database->loadResult();
 169          $rows[$i]->active = $active;
 170      }
 171      // number of Trashed Items
 172      for ( $i = 0; $i < $count; $i++ ) {
 173          $query = "SELECT COUNT( a.id )"
 174          . "\n FROM #__content AS a"
 175          . "\n WHERE a.sectionid = ". $rows[$i]->id
 176          . "\n AND a.state = '-2'"
 177          ;
 178          $database->setQuery( $query );
 179          $trash = $database->loadResult();
 180          $rows[$i]->trash = $trash;
 181      }
 182  
 183      sections_html::show( $rows, $scope, $my->id, $pageNav, $option );
 184  }
 185  
 186  /**
 187  * Compiles information to add or edit a section
 188  * @param database A database connector object
 189  * @param string The name of the category section
 190  * @param integer The unique id of the category to edit (0 if new)
 191  * @param string The name of the current user
 192  */
 193  function editSection( $uid=0, $scope='', $option ) {
 194      global $database, $my;
 195  
 196      $row = new mosSection( $database );
 197      // load the row from the db table
 198      $row->load( $uid );
 199      $row->title = htmlspecialchars( str_replace( '&amp;', '&', $row->title ) );
 200      $row->name = htmlspecialchars( str_replace( '&amp;', '&', $row->name ) );
 201  
 202      // fail if checked out not by 'me'
 203      if ( $row->checked_out && $row->checked_out <> $my->id ) {
 204          $msg = sprintf(T_('The section %s is currently being edited by another administrator'), $row->title);
 205          mosRedirect( 'index2.php?option='. $option .'&scope='. $row->scope .'&mosmsg='. $msg );
 206      }
 207  
 208      if ( $uid ) {
 209          $row->checkout( $my->id );
 210          if ( $row->id > 0 ) {
 211              $query = "SELECT *"
 212              . "\n FROM #__menu"
 213              . "\n WHERE componentid = ". $row->id
 214              . "\n AND ( type = 'content_archive_section' OR type = 'content_blog_section' OR type = 'content_section' )"
 215              ;
 216              $database->setQuery( $query );
 217              $menus = $database->loadObjectList();
 218              $count = count( $menus );
 219              for( $i = 0; $i < $count; $i++ ) {
 220                  switch ( $menus[$i]->type ) {
 221                      case 'content_section':
 222                          $menus[$i]->type = T_('Section Table');
 223                          break;
 224  
 225                      case 'content_blog_section':
 226                          $menus[$i]->type = T_('Section Blog');
 227                          break;
 228  
 229                      case 'content_archive_section':
 230                          $menus[$i]->type = T_('Section Blog Archive');
 231                          break;
 232                  }
 233              }
 234          } else {
 235              $menus = array();
 236          }
 237      } else {
 238          $row->scope         = $scope;
 239          $row->published     = 1;
 240          $menus             = array();
 241      }
 242  
 243      // build the html select list for section types
 244      $types[] = mosHTML::makeOption( '', T_('Select Type') );
 245      $types[] = mosHTML::makeOption( 'content_section', T_('Section List') );
 246      $types[] = mosHTML::makeOption( 'content_blog_section', T_('Section Blog') );
 247      $types[] = mosHTML::makeOption( 'content_archive_section', T_('Section Archive Blog') );
 248      $lists['link_type']         = mosHTML::selectList( $types, 'link_type', 'class="inputbox" size="1"', 'value', 'text' );;
 249  
 250      // build the html select list for ordering
 251      $query = "SELECT ordering AS value, title AS text"
 252      . "\n FROM #__sections"
 253      . "\n WHERE scope='$row->scope' ORDER BY ordering"
 254      ;
 255      $lists['ordering']             = mosAdminMenus::SpecificOrdering( $row, $uid, $query );
 256  
 257      // build the select list for the image positions
 258      $active =  ( $row->image_position ? $row->image_position : 'left' );
 259      $lists['image_position']     = mosAdminMenus::Positions( 'image_position', $active, NULL, 0 );
 260      // build the html select list for images
 261      $lists['image']             = mosAdminMenus::Images( 'image', $row->image );
 262      // build the html select list for the group access
 263      $lists['access']             = mosAdminMenus::Access( $row );
 264      // build the html radio buttons for published
 265      $lists['published']         = mosHTML::yesnoRadioList( 'published', 'class="inputbox"', $row->published );
 266      // build the html select list for menu selection
 267      $lists['menuselect']        = mosAdminMenus::MenuSelect( );
 268  
 269      sections_html::edit( $row, $option, $lists, $menus );
 270  }
 271  
 272  /**
 273  * Saves the catefory after an edit form submit
 274  * @param database A database connector object
 275  * @param string The name of the category section
 276  */
 277  function saveSection( $option, $scope, $task ) {
 278      global $database;
 279  
 280      $menu         = mosGetParam( $_POST, 'menu', 'mainmenu' );
 281      $menuid        = mosGetParam( $_POST, 'menuid', 0 );
 282      $oldtitle     = mosGetParam( $_POST, 'oldtitle', null );
 283  
 284      $row = new mosSection( $database );
 285      if (!$row->bind( $_POST )) {
 286          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 287          exit();
 288      }
 289      if (!$row->check()) {
 290          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 291          exit();
 292      }
 293      if ( $oldtitle ) {
 294          if ( $oldtitle <> $row->title ) {
 295              // @RawSQLUse, trivial_implementation, UPDATE
 296              $database->setQuery( "UPDATE #__menu SET name='$row->title' WHERE name='$oldtitle' AND type='content_section'" );
 297              $database->query();
 298          }
 299      }
 300  
 301      if (!$row->store()) {
 302          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 303          exit();
 304      }
 305      $row->checkin();
 306      $row->updateOrder( "scope='$row->scope'" );
 307  
 308      switch ( $task ) {
 309          case 'go2menu':
 310              mosRedirect( 'index2.php?option=com_menus&menutype='. $menu );
 311              break;
 312  
 313          case 'go2menuitem':
 314              mosRedirect( 'index2.php?option=com_menus&menutype='. $menu .'&task=edit&hidemainmenu=1&id='. $menuid );
 315              break;
 316  
 317          case 'menulink':
 318              menuLink( $row->id );
 319              break;
 320  
 321          case 'apply':
 322              $msg = T_('Changes to Section saved');
 323              mosRedirect( 'index2.php?option='. $option .'&scope='. $scope .'&task=editA&hidemainmenu=1&id='. $row->id, $msg );
 324              break;
 325  
 326              case 'save':
 327          default:
 328              $msg = T_('Section saved');
 329              mosRedirect( 'index2.php?option='. $option .'&scope='. $scope, $msg );
 330              break;
 331      }
 332  }
 333  /**
 334  * Deletes one or more categories from the categories table
 335  * @param database A database connector object
 336  * @param string The name of the category section
 337  * @param array An array of unique category id numbers
 338  */
 339  function removeSections( $cid, $scope, $option ) {
 340      global $database;
 341  
 342      if (count( $cid ) < 1) {
 343          echo "<script> alert('".T_('Select a section to delete')."'); window.history.go(-1);</script>\n";
 344          exit;
 345      }
 346  
 347      $cids = implode( ',', $cid );
 348  
 349      $query = "SELECT s.id, s.name, COUNT(c.id) AS numcat"
 350      . "\n FROM #__sections AS s"
 351      . "\n LEFT JOIN #__categories AS c ON c.section=s.id"
 352      . "\n WHERE s.id IN ($cids)"
 353      . "\n GROUP BY s.id"
 354      ;
 355      $database->setQuery( $query );
 356      if (!($rows = $database->loadObjectList())) {
 357          echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 358      }
 359  
 360      $err = array();
 361      $cid = array();
 362      foreach ($rows as $row) {
 363          if ($row->numcat == 0) {
 364              $cid[] = $row->id;
 365              $name[] = $row->name;
 366          } else {
 367              $err[] = $row->name;
 368          }
 369      }
 370  
 371      if (count( $cid )) {
 372          $cids = implode( ',', $cid );
 373          // @RawSQLUse, trivial_implementation, DELETE
 374          $database->setQuery( "DELETE FROM #__sections WHERE id IN ($cids)" );
 375          if (!$database->query()) {
 376              echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 377          }
 378      }
 379  
 380      if (count( $err )) {
 381          $cids = implode( ', ', $err );
 382          $msg = sprintf(T_('Sections(s): %s cannot be removed as they contain categories'), $cids);
 383          mosRedirect( 'index2.php?option='. $option .'&scope='. $scope, $msg );
 384      }
 385  
 386      $names = implode( ', ', $name );
 387      $msg = sprintf(T_('Section(s): %s successfully deleted'), $names);
 388      mosRedirect( 'index2.php?option='. $option .'&scope='. $scope, $msg );
 389  }
 390  
 391  /**
 392  * Publishes or Unpublishes one or more categories
 393  * @param database A database connector object
 394  * @param string The name of the category section
 395  * @param integer A unique category id (passed from an edit form)
 396  * @param array An array of unique category id numbers
 397  * @param integer 0 if unpublishing, 1 if publishing
 398  * @param string The name of the current user
 399  */
 400  function publishSections( $scope, $cid=null, $publish=1, $option ) {
 401      global $database, $my;
 402  
 403      if ( !is_array( $cid ) || count( $cid ) < 1 ) {
 404          $action = $publish ? T_('publish') : T_('unpublish');
 405          echo "<script> alert('".sprintf(T_('Select a section to '), $action)."'); window.history.go(-1);</script>\n";
 406          exit;
 407      }
 408  
 409      $cids = implode( ',', $cid );
 410      $count = count( $cid );
 411      if ( $publish ) {
 412          if ( !$count ){
 413              echo "<script> alert('".T_('Cannot Publish an Empty Section')."'); window.history.go(-1);</script>\n";
 414              return;
 415          }
 416      }
 417  
 418      $database->setQuery( "UPDATE #__sections SET published='$publish'"
 419      . "\n WHERE id IN ($cids) AND (checked_out=0 OR (checked_out='$my->id'))"
 420      );
 421      if (!$database->query()) {
 422          echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 423          exit();
 424      }
 425  
 426      if ( $count == 1 ) {
 427          $row = new mosSection( $database );
 428          $row->checkin( $cid[0] );
 429      }
 430  
 431      // check if section linked to menu items if unpublishing
 432      if ( $publish == 0 ) {
 433          // @RawSQLUse, trivial_implementation, SELECT
 434          $database->setQuery( "SELECT id FROM #__menu WHERE type='content_section' AND componentid IN ($cids)" );
 435          $menus = $database->loadObjectList();
 436  
 437          if ($menus) {
 438              foreach ($menus as $menu) {
 439                  // @RawSQLUse, trivial_implementation, UPDATE
 440                  $database->setQuery( "UPDATE #__menu SET published=$publish WHERE id=$menu->id" );
 441                  $database->query();
 442              }
 443          }
 444      }
 445  
 446      mosRedirect( 'index2.php?option='. $option .'&scope='. $scope );
 447  }
 448  
 449  /**
 450  * Cancels an edit operation
 451  * @param database A database connector object
 452  * @param string The name of the category section
 453  * @param integer A unique category id
 454  */
 455  function cancelSection( $option, $scope ) {
 456      global $database;
 457      $row = new mosSection( $database );
 458      $row->bind( $_POST );
 459      // sanitize
 460      $row->id = intval($row->id);
 461      $row->checkin();
 462  
 463      mosRedirect( 'index2.php?option='. $option .'&scope='. $scope );
 464  }
 465  
 466  /**
 467  * Moves the order of a record
 468  * @param integer The increment to reorder by
 469  */
 470  function orderSection( $uid, $inc, $option, $scope ) {
 471      global $database;
 472  
 473      $row = new mosSection( $database );
 474      $row->load( $uid );
 475      $row->move( $inc, "scope='$row->scope'" );
 476  
 477      mosRedirect( 'index2.php?option='. $option .'&scope='. $scope );
 478  }
 479  
 480  
 481  /**
 482  * Form for copying item(s) to a specific menu
 483  */
 484  function copySectionSelect( $option, $cid, $section ) {
 485      global $database;
 486  
 487      if (!is_array( $cid ) || count( $cid ) < 1) {
 488          echo "<script> alert('".T_('Select an item to move')."'); window.history.go(-1);</script>\n";
 489          exit;
 490      }
 491  
 492      ## query to list selected categories
 493      $cids = implode( ',', $cid );
 494      // @RawSQLUse, trivial_implementation, SELECT
 495      $query = "SELECT a.name, a.id"
 496      . "\n FROM #__categories AS a"
 497      . "\n WHERE a.section IN ( ". $cids ." )"
 498      ;
 499      $database->setQuery( $query );
 500      $categories = $database->loadObjectList();
 501  
 502      ## query to list items from categories
 503      // @RawSQLUse, trivial_implementation, SELECT
 504      $query = "SELECT a.title, a.id"
 505      . "\n FROM #__content AS a"
 506      . "\n WHERE a.sectionid IN ( ". $cids ." )"
 507      . "\n ORDER BY a.sectionid, a.catid, a.title"
 508      ;
 509      $database->setQuery( $query );
 510      $contents = $database->loadObjectList();
 511  
 512      sections_html::copySectionSelect( $option, $cid, $categories, $contents, $section );
 513  }
 514  
 515  
 516  /**
 517  * Save the item(s) to the menu selected
 518  */
 519  function copySectionSave( $sectionid ) {
 520      global $database;
 521  
 522      $title         = mosGetParam( $_REQUEST, 'title', '' );
 523      $contentid     = mosGetParam( $_REQUEST, 'content', '' );
 524      $categoryid = mosGetParam( $_REQUEST, 'category', '' );
 525  
 526      // copy section
 527      $section = new mosSection ( $database );
 528      foreach( $sectionid as $id ) {
 529          $section->load( $id );
 530          $section->id     = NULL;
 531          $section->title = $title;
 532          $section->name     = $title;
 533          if ( !$section->check() ) {
 534              echo "<script> alert('".$section->getError()."'); window.history.go(-1); </script>\n";
 535              exit();
 536          }
 537  
 538          if ( !$section->store() ) {
 539              echo "<script> alert('".$section->getError()."'); window.history.go(-1); </script>\n";
 540              exit();
 541          }
 542          $section->checkin();
 543          $section->updateOrder( "section='". $section->id ."'" );
 544          // stores original catid
 545          $newsectids[]["old"] = $id;
 546          // pulls new catid
 547          $newsectids[]["new"] = $section->id;
 548      }
 549      $sectionMove = $section->id;
 550  
 551      // copy categories
 552      $category = new mosCategory ( $database );
 553      foreach( $categoryid as $id ) {
 554          $category->load( $id );
 555          $category->id = NULL;
 556          $category->section = $sectionMove;
 557          foreach( $newsectids as $newsectid ) {
 558              if ( $category->section == $newsectid["old"] ) {
 559                  $category->section = $newsectid["new"];
 560              }
 561          }
 562          if (!$category->check()) {
 563              echo "<script> alert('".$category->getError()."'); window.history.go(-1); </script>\n";
 564              exit();
 565          }
 566  
 567          if (!$category->store()) {
 568              echo "<script> alert('".$category->getError()."'); window.history.go(-1); </script>\n";
 569              exit();
 570          }
 571          $category->checkin();
 572          $category->updateOrder( "section='". $category->section ."'" );
 573          // stores original catid
 574          $newcatids[]["old"] = $id;
 575          // pulls new catid
 576          $newcatids[]["new"] = $category->id;
 577      }
 578  
 579      $content = new mosContent ( $database );
 580      foreach( $contentid as $id) {
 581          $content->load( $id );
 582          $content->id = NULL;
 583          $content->hits = 0;
 584          foreach( $newsectids as $newsectid ) {
 585              if ( $content->sectionid == $newsectid["old"] ) {
 586                  $content->sectionid = $newsectid["new"];
 587              }
 588          }
 589          foreach( $newcatids as $newcatid ) {
 590              if ( $content->catid == $newcatid["old"] ) {
 591                  $content->catid = $newcatid["new"];
 592              }
 593          }
 594          if (!$content->check()) {
 595              echo "<script> alert('".$content->getError()."'); window.history.go(-1); </script>\n";
 596              exit();
 597          }
 598  
 599          if (!$content->store()) {
 600              echo "<script> alert('".$content->getError()."'); window.history.go(-1); </script>\n";
 601              exit();
 602          }
 603          $content->checkin();
 604      }
 605      $sectionOld = new mosSection ( $database );
 606      $sectionOld->load( $sectionMove );
 607  
 608      $msg = sprintf(T_('Section %s and all its Categories and Items have been copied as %s'), $sectionOld-> name, $title);
 609      mosRedirect( 'index2.php?option=com_sections&scope=content&mosmsg='. $msg );
 610  }
 611  
 612  /**
 613  * changes the access level of a record
 614  * @param integer The increment to reorder by
 615  */
 616  function accessMenu( $uid, $access, $option ) {
 617      global $database;
 618  
 619      $row = new mosSection( $database );
 620      $row->load( $uid );
 621      $row->access = $access;
 622  
 623      if ( !$row->check() ) {
 624          return $row->getError();
 625      }
 626      if ( !$row->store() ) {
 627          return $row->getError();
 628      }
 629  
 630      mosRedirect( 'index2.php?option='. $option .'&scope='. $row->scope );
 631  }
 632  
 633  function menuLink( $id ) {
 634      global $database;
 635  
 636      $section = new mosSection( $database );
 637      $section->bind( $_POST );
 638      $section->checkin();
 639  
 640      $menu         = mosGetParam( $_POST, 'menuselect', '' );
 641      $name         = mosGetParam( $_POST, 'link_name', '' );
 642      $type         = mosGetParam( $_POST, 'link_type', '' );
 643  
 644      switch ( $type ) {
 645          case 'content_section':
 646              $link         = 'index.php?option=com_content&task=section&id='. $id;
 647              $menutype    = T_('Section Table');
 648              break;
 649  
 650          case 'content_blog_section':
 651              $link         = 'index.php?option=com_content&task=blogsection&id='. $id;
 652              $menutype    = T_('Section Blog');
 653              break;
 654  
 655          case 'content_archive_section':
 656              $link         = 'index.php?option=com_content&task=archivesection&id='. $id;
 657              $menutype    = T_('Section Blog Archive');
 658              break;
 659      }
 660  
 661      $row                 = new mosMenu( $database );
 662      $row->menutype         = $menu;
 663      $row->name             = $name;
 664      $row->type             = $type;
 665      $row->published        = 1;
 666      $row->componentid    = $id;
 667      $row->link            = $link;
 668      $row->ordering        = 9999;
 669  
 670      if (!$row->check()) {
 671          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 672          exit();
 673      }
 674      if (!$row->store()) {
 675          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 676          exit();
 677      }
 678      $row->checkin();
 679      $row->updateOrder( 'scope="'. $row->scope .'"' );
 680  
 681      $msg = sprintf(T_('%s ( %s ) in menu: %s successfully created'), $name, $menutype, $menu);
 682      mosRedirect( 'index2.php?option=com_sections&scope=content&task=editA&hidemainmenu=1&id='. $id,  $msg );
 683  }
 684  
 685  function saveOrder( &$cid ) {
 686      global $database;
 687      $order         = mosGetParam( $_POST, 'order', array(0) );
 688      $row        = new mosMenu( $database );
 689      $scopes = array();
 690      // update ordering values
 691      foreach ($cid as $i=>$ciditem) {
 692          $row->load( $ciditem );
 693          if ($row->ordering != $order[$i]) {
 694              $row->ordering = $order[$i];
 695              if (!$row->store()) {
 696                  echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 697                  exit();
 698              }
 699              // remember to updateOrder this group
 700              $scopes[$row->scope] = $row->id;
 701          }
 702      }
 703      // execute updateOrder for each group
 704      foreach ($scopes as $scope=>$rowid) {
 705          $row->updateOrder("scope = '$scope'");
 706      } // foreach
 707  
 708      $msg     = T_('New ordering saved');
 709      mosRedirect( 'index2.php?option=com_sections&scope=content', $msg );
 710  } // saveOrder
 711  ?>