[Index]    [Classes]    [Variables]

PHP Cross Reference of Joomla 1.0.15 Documentation

title

Body

[close]

/administrator/components/com_typedcontent/ -> admin.typedcontent.php (source)

   1  <?php
   2  /**
   3  * @version $Id: admin.typedcontent.php 10002 2008-02-08 10:56:57Z willebil $
   4  * @package Joomla
   5  * @subpackage Content
   6  * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
   7  * @license http://www.gnu.org/licenses/gpl-2.0.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  $cid = josGetArrayInts( 'cid' );
  21  
  22  switch ( $task ) {
  23      case 'cancel':
  24          cancel( $option );
  25          break;
  26  
  27      case 'new':
  28          edit( 0, $option );
  29          break;
  30  
  31      case 'edit':
  32          edit( $id, $option );
  33          break;
  34  
  35      case 'editA':
  36          edit( intval( $cid[0] ), $option );
  37          break;
  38  
  39      case 'go2menu':
  40      case 'go2menuitem':
  41      case 'resethits':
  42      case 'menulink':
  43      case 'save':
  44      case 'apply':
  45          save( $option, $task );
  46          break;
  47  
  48      case 'remove':
  49          trash( $cid, $option );
  50          break;
  51  
  52      case 'publish':
  53          changeState( $cid, 1, $option );
  54          break;
  55  
  56      case 'unpublish':
  57          changeState( $cid, 0, $option );
  58          break;
  59  
  60      case 'accesspublic':
  61          changeAccess( intval( $cid[0] ), 0, $option );
  62          break;
  63  
  64      case 'accessregistered':
  65          changeAccess( intval( $cid[0] ), 1, $option );
  66          break;
  67  
  68      case 'accessspecial':
  69          changeAccess( intval( $cid[0] ), 2, $option );
  70          break;
  71  
  72      case 'saveorder':
  73          saveOrder( $cid );
  74          break;
  75  
  76      default:
  77          view( $option );
  78          break;
  79  }
  80  
  81  /**
  82  * Compiles a list of installed or defined modules
  83  * @param database A database connector object
  84  */
  85  function view( $option ) {
  86      global $database, $mainframe, $mosConfig_list_limit;
  87  
  88      $filter_authorid     = intval( $mainframe->getUserStateFromRequest( "filter_authorid{$option}", 'filter_authorid', 0 ) );
  89      $order                 = $mainframe->getUserStateFromRequest( "zorder", 'zorder', 'c.ordering DESC' );
  90      $limit                 = intval( $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ) );
  91      $limitstart         = intval( $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 ) );
  92      $search             = $mainframe->getUserStateFromRequest( "search{$option}", 'search', '' );
  93      if (get_magic_quotes_gpc()) {
  94          $search            = stripslashes( $search );
  95      }
  96  
  97      // used by filter
  98      if ( $search ) {
  99          $searchEscaped = $database->getEscaped( trim( strtolower( $search ) ) );
 100          $search_query = "\n AND ( LOWER( c.title ) LIKE '%$searchEscaped%' OR LOWER( c.title_alias ) LIKE '%$searchEscaped%' )";
 101      } else {
 102          $search_query = '';
 103      }
 104  
 105      $filter = '';
 106      if ( $filter_authorid > 0 ) {
 107          $filter = "\n AND c.created_by = " . (int) $filter_authorid;
 108      }
 109  
 110      $orderAllowed = array( 'c.ordering ASC', 'c.ordering DESC', 'c.id ASC', 'c.id DESC', 'c.title ASC', 'c.title DESC', 'c.created ASC', 'c.created DESC', 'z.name ASC', 'z.name DESC', 'c.state ASC', 'c.state DESC', 'c.access ASC', 'c.access DESC' );
 111      if (!in_array( $order, $orderAllowed )) {
 112          $order = 'c.ordering DESC';
 113      }
 114  
 115      // get the total number of records
 116      $query = "SELECT count(*)"
 117      . "\n FROM #__content AS c"
 118      . "\n WHERE c.sectionid = 0"
 119      . "\n AND c.catid = 0"
 120      . "\n AND c.state != -2"
 121      . $search_query
 122      . $filter
 123      ;
 124      $database->setQuery( $query );
 125      $total = $database->loadResult();
 126      require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
 127      $pageNav = new mosPageNav( $total, $limitstart, $limit );
 128  
 129      $query = "SELECT c.*, g.name AS groupname, u.name AS editor, z.name AS creator"
 130      . "\n FROM #__content AS c"
 131      . "\n LEFT JOIN #__groups AS g ON g.id = c.access"
 132      . "\n LEFT JOIN #__users AS u ON u.id = c.checked_out"
 133      . "\n LEFT JOIN #__users AS z ON z.id = c.created_by"
 134      . "\n WHERE c.sectionid = 0"
 135      . "\n AND c.catid = 0"
 136      . "\n AND c.state != -2"
 137      . $search_query
 138      . $filter
 139      . "\n ORDER BY ". $order
 140      ;
 141      $database->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
 142      $rows = $database->loadObjectList();
 143  
 144      if ($database->getErrorNum()) {
 145          echo $database->stderr();
 146          return false;
 147      }
 148  
 149      $count = count( $rows );
 150      for( $i = 0; $i < $count; $i++ ) {
 151          $query = "SELECT COUNT( id )"
 152          . "\n FROM #__menu"
 153          . "\n WHERE componentid = " . (int) $rows[$i]->id
 154          . "\n AND type = 'content_typed'"
 155          . "\n AND published != -2"
 156          ;
 157          $database->setQuery( $query );
 158          $rows[$i]->links = $database->loadResult();
 159      }
 160  
 161      $ordering[] = mosHTML::makeOption( 'c.ordering ASC', 'Ordering asc' );
 162      $ordering[] = mosHTML::makeOption( 'c.ordering DESC', 'Ordering desc' );
 163      $ordering[] = mosHTML::makeOption( 'c.id ASC', 'ID asc' );
 164      $ordering[] = mosHTML::makeOption( 'c.id DESC', 'ID desc' );
 165      $ordering[] = mosHTML::makeOption( 'c.title ASC', 'Title asc' );
 166      $ordering[] = mosHTML::makeOption( 'c.title DESC', 'Title desc' );
 167      $ordering[] = mosHTML::makeOption( 'c.created ASC', 'Date asc' );
 168      $ordering[] = mosHTML::makeOption( 'c.created DESC', 'Date desc' );
 169      $ordering[] = mosHTML::makeOption( 'z.name ASC', 'Author asc' );
 170      $ordering[] = mosHTML::makeOption( 'z.name DESC', 'Author desc' );
 171      $ordering[] = mosHTML::makeOption( 'c.state ASC', 'Published asc' );
 172      $ordering[] = mosHTML::makeOption( 'c.state DESC', 'Published desc' );
 173      $ordering[] = mosHTML::makeOption( 'c.access ASC', 'Access asc' );
 174      $ordering[] = mosHTML::makeOption( 'c.access DESC', 'Access desc' );
 175      $javascript = 'onchange="document.adminForm.submit();"';
 176      $lists['order'] = mosHTML::selectList( $ordering, 'zorder', 'class="inputbox" size="1"'. $javascript, 'value', 'text', $order );
 177  
 178      // get list of Authors for dropdown filter
 179      $query = "SELECT c.created_by AS value, u.name AS text"
 180      . "\n FROM #__content AS c"
 181      . "\n LEFT JOIN #__users AS u ON u.id = c.created_by"
 182      . "\n WHERE c.sectionid = 0"
 183      . "\n GROUP BY u.name"
 184      . "\n ORDER BY u.name"
 185      ;
 186      $authors[] = mosHTML::makeOption( '0', _SEL_AUTHOR );
 187      $database->setQuery( $query );
 188      $authors = array_merge( $authors, $database->loadObjectList() );
 189      $lists['authorid']    = mosHTML::selectList( $authors, 'filter_authorid', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', $filter_authorid );
 190  
 191      HTML_typedcontent::showContent( $rows, $pageNav, $option, $search, $lists );
 192  }
 193  
 194  /**
 195  * Compiles information to add or edit content
 196  * @param database A database connector object
 197  * @param string The name of the category section
 198  * @param integer The unique id of the category to edit (0 if new)
 199  */
 200  function edit( $uid, $option ) {
 201      global $database, $my, $mainframe;
 202      global $mosConfig_absolute_path, $mosConfig_live_site, $mosConfig_offset;
 203  
 204      $row = new mosContent( $database );
 205      $row->load( (int)$uid );
 206  
 207      $lists         = array();
 208      $nullDate     = $database->getNullDate();
 209  
 210      if ($uid) {
 211          // fail if checked out not by 'me'
 212          if ($row->isCheckedOut( $my->id )) {
 213              mosErrorAlert( "The module ".$row->title." is currently being edited by another administrator" );
 214          }
 215  
 216          $row->checkout( $my->id );
 217  
 218          if (trim( $row->images )) {
 219              $row->images = explode( "\n", $row->images );
 220          } else {
 221              $row->images = array();
 222          }
 223  
 224          $row->created         = mosFormatDate( $row->created, _CURRENT_SERVER_TIME_FORMAT );
 225          $row->modified         = $row->modified == $nullDate ? '' : mosFormatDate( $row->modified, _CURRENT_SERVER_TIME_FORMAT );
 226          $row->publish_up     = mosFormatDate( $row->publish_up, _CURRENT_SERVER_TIME_FORMAT );
 227  
 228          if (trim( $row->publish_down ) == $nullDate || trim( $row->publish_down ) == '' || trim( $row->publish_down ) == '-' ) {
 229              $row->publish_down = 'Never';
 230          }
 231          $row->publish_down     = mosFormatDate( $row->publish_down, _CURRENT_SERVER_TIME_FORMAT );
 232  
 233          $query = "SELECT name"
 234          . "\n FROM #__users"
 235          . "\n WHERE id = " . (int) $row->created_by
 236          ;
 237          $database->setQuery( $query );
 238          $row->creator = $database->loadResult();
 239  
 240          // test to reduce unneeded query
 241          if ( $row->created_by == $row->modified_by ) {
 242              $row->modifier = $row->creator;
 243          } else {
 244              $query = "SELECT name"
 245              . "\n FROM #__users"
 246              . "\n WHERE id = " . (int) $row->modified_by
 247              ;
 248              $database->setQuery( $query );
 249              $row->modifier = $database->loadResult();
 250          }
 251  
 252          // get list of links to this item
 253          $and     = "\n AND componentid = " . (int) $row->id;
 254          $menus     = mosAdminMenus::Links2Menu( 'content_typed', $and );
 255      } else {
 256          // initialise values for a new item
 257          $row->version         = 0;
 258          $row->state         = 1;
 259          $row->images         = array();
 260          $row->publish_up     = date( 'Y-m-d H:i:s', time() + ( $mosConfig_offset * 60 * 60 ) );
 261          $row->publish_down     = 'Never';
 262          $row->sectionid     = 0;
 263          $row->catid         = 0;
 264          $row->creator         = '';
 265          $row->modified         = $nullDate;
 266          $row->modifier         = '';
 267          $row->ordering         = 0;
 268          $menus = array();
 269      }
 270  
 271      // calls function to read image from directory
 272      $pathA         = $mosConfig_absolute_path .'/images/stories';
 273      $pathL         = $mosConfig_live_site .'/images/stories';
 274      $images     = array();
 275      $folders     = array();
 276      $folders[]     = mosHTML::makeOption( '/' );
 277      mosAdminMenus::ReadImages( $pathA, '/', $folders, $images );
 278      // list of folders in images/stories/
 279      $lists['folders']         = mosAdminMenus::GetImageFolders( $folders, $pathL );
 280      // list of images in specfic folder in images/stories/
 281      $lists['imagefiles']    = mosAdminMenus::GetImages( $images, $pathL );
 282      // list of saved images
 283      $lists['imagelist']     = mosAdminMenus::GetSavedImages( $row, $pathL );
 284  
 285      // build list of users
 286      $active = ( intval( $row->created_by ) ? intval( $row->created_by ) : $my->id );
 287      $lists['created_by']     = mosAdminMenus::UserSelect( 'created_by', $active );
 288      // build the html select list for the group access
 289      $lists['access']         = mosAdminMenus::Access( $row );
 290      // build the html select list for menu selection
 291      $lists['menuselect']    = mosAdminMenus::MenuSelect( );
 292      // build the select list for the image positions
 293      $lists['_align']         = mosAdminMenus::Positions( '_align' );
 294      // build the select list for the image caption alignment
 295      $lists['_caption_align']     = mosAdminMenus::Positions( '_caption_align' );
 296      // build the select list for the image caption position
 297      $pos[] = mosHTML::makeOption( 'bottom', _CMN_BOTTOM );
 298      $pos[] = mosHTML::makeOption( 'top', _CMN_TOP );
 299      $lists['_caption_position'] = mosHTML::selectList( $pos, '_caption_position', 'class="inputbox" size="1"', 'value', 'text' );
 300  
 301      // get params definitions
 302      $params = new mosParameters( $row->attribs, $mainframe->getPath( 'com_xml', 'com_typedcontent' ), 'component' );
 303  
 304      HTML_typedcontent::edit( $row, $images, $lists, $params, $option, $menus );
 305  }
 306  
 307  /**
 308  * Saves the typed content item
 309  */
 310  function save( $option, $task ) {
 311      global $database, $my, $mosConfig_offset;
 312      
 313      josSpoofCheck();
 314  
 315      $nullDate     = $database->getNullDate();
 316      $menu         = strval( mosGetParam( $_POST, 'menu', 'mainmenu' ) );
 317      $menuid        = intval( mosGetParam( $_POST, 'menuid', 0 ) );
 318  
 319      $row = new mosContent( $database );
 320      if (!$row->bind( $_POST )) {
 321          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 322          exit();
 323      }
 324  
 325      if ($row->id) {
 326          $row->modified         = date( 'Y-m-d H:i:s' );
 327          $row->modified_by     = $my->id;
 328      }
 329  
 330      $row->created_by     = $row->created_by ? $row->created_by : $my->id;
 331  
 332      if ($row->created && strlen(trim( $row->created )) <= 10) {
 333          $row->created     .= ' 00:00:00';
 334      }
 335      $row->created         = $row->created ? mosFormatDate( $row->created, _CURRENT_SERVER_TIME_FORMAT, -$mosConfig_offset ) : date( 'Y-m-d H:i:s' );
 336  
 337      if (strlen(trim( $row->publish_up )) <= 10) {
 338          $row->publish_up .= ' 00:00:00';
 339      }
 340      $row->publish_up = mosFormatDate($row->publish_up, _CURRENT_SERVER_TIME_FORMAT, -$mosConfig_offset );
 341  
 342      if (trim( $row->publish_down ) == 'Never' || trim( $row->publish_down ) == '') {
 343          $row->publish_down = $nullDate;
 344      } else {
 345          if (strlen(trim( $row->publish_down )) <= 10) {
 346              $row->publish_down .= ' 00:00:00';
 347          }
 348          $row->publish_down = mosFormatDate( $row->publish_down, _CURRENT_SERVER_TIME_FORMAT, -$mosConfig_offset );
 349      }
 350  
 351      $row->state = intval( mosGetParam( $_REQUEST, 'published', 0 ) );
 352  
 353      // Save Parameters
 354      $params = mosGetParam( $_POST, 'params', '' );
 355      if (is_array( $params )) {
 356          $txt = array();
 357          foreach ( $params as $k=>$v) {
 358              $txt[] = "$k=$v";
 359          }
 360          $row->attribs = implode( "\n", $txt );
 361      }
 362  
 363      // code cleaner for xhtml transitional compliance
 364      $row->introtext = str_replace( '<br>', '<br />', $row->introtext );
 365  
 366      $row->title = ampReplace( $row->title );
 367  
 368      if (!$row->check()) {
 369          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 370          exit();
 371      }
 372      if (!$row->store()) {
 373          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 374          exit();
 375      }
 376      $row->checkin();
 377  
 378      // clean any existing cache files
 379      mosCache::cleanCache( 'com_content' );
 380  
 381      switch ( $task ) {
 382          case 'go2menu':
 383              mosRedirect( 'index2.php?option=com_menus&menutype='. $menu );
 384              break;
 385  
 386          case 'go2menuitem':
 387              mosRedirect( 'index2.php?option=com_menus&menutype='. $menu .'&task=edit&hidemainmenu=1&id='. $menuid );
 388              break;
 389  
 390          case 'menulink':
 391              menuLink( $option, $row->id );
 392              break;
 393  
 394          case 'resethits':
 395              resethits( $option, $row->id );
 396              break;
 397  
 398          case 'save':
 399              $msg = 'Typed Content Item saved';
 400              mosRedirect( 'index2.php?option='. $option, $msg );
 401              break;
 402  
 403          case 'apply':
 404          default:
 405              $msg = 'Changes to Typed Content Item saved';
 406              mosRedirect( 'index2.php?option='. $option .'&task=edit&hidemainmenu=1&id='. $row->id, $msg );
 407              break;
 408      }
 409  }
 410  
 411  /**
 412  * Trashes the typed content item
 413  */
 414  function trash( &$cid, $option ) {
 415      global $database;
 416      
 417      josSpoofCheck();
 418  
 419      $total = count( $cid );
 420      if ( $total < 1) {
 421          echo "<script> alert('Select an item to delete'); window.history.go(-1);</script>\n";
 422          exit;
 423      }
 424  
 425      $state = '-2';
 426      $ordering = '0';
 427      //seperate contentids
 428      mosArrayToInts( $cid );
 429      $cids = 'id=' . implode( ' OR id=', $cid );
 430      $query = "UPDATE #__content"
 431      . "\n SET state = " . (int) $state . ", ordering = " . (int) $ordering
 432      . "\n WHERE ( $cids )"
 433      ;
 434      $database->setQuery( $query );
 435      if ( !$database->query() ) {
 436          echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 437          exit();
 438      }
 439  
 440      // clean any existing cache files
 441      mosCache::cleanCache( 'com_content' );
 442  
 443      $msg = $total ." Item(s) sent to the Trash";
 444      mosRedirect( 'index2.php?option='. $option, $msg );
 445  }
 446  
 447  /**
 448  * Changes the state of one or more content pages
 449  * @param string The name of the category section
 450  * @param integer A unique category id (passed from an edit form)
 451  * @param array An array of unique category id numbers
 452  * @param integer 0 if unpublishing, 1 if publishing
 453  * @param string The name of the current user
 454  */
 455  function changeState( $cid=null, $state=0, $option ) {
 456      global $database, $my;
 457      
 458      josSpoofCheck();
 459  
 460      if (count( $cid ) < 1) {
 461          $action = $state == 1 ? 'publish' : ($state == -1 ? 'archive' : 'unpublish');
 462          echo "<script> alert('Select an item to $action'); window.history.go(-1);</script>\n";
 463          exit;
 464      }
 465  
 466      mosArrayToInts( $cid );
 467      $total    = count ( $cid );
 468      $cids    = 'id=' . implode( ' OR id=', $cid );
 469  
 470      $query = "UPDATE #__content"
 471      . "\n SET state = " . (int) $state
 472      . "\n WHERE ( $cids )"
 473      . "\n AND ( checked_out = 0 OR ( checked_out = " . (int) $my->id . " ) )"
 474      ;
 475      $database->setQuery( $query );
 476      if (!$database->query()) {
 477          echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 478          exit();
 479      }
 480  
 481      if (count( $cid ) == 1) {
 482          $row = new mosContent( $database );
 483          $row->checkin( $cid[0] );
 484      }
 485  
 486      // clean any existing cache files
 487      mosCache::cleanCache( 'com_content' );
 488  
 489      if ( $state == "1" ) {
 490          $msg = $total ." Item(s) successfully Published";
 491      } else if ( $state == "0" ) {
 492          $msg = $total ." Item(s) successfully Unpublished";
 493      }
 494      mosRedirect( 'index2.php?option='. $option .'&msg='. $msg );
 495  }
 496  
 497  /**
 498  * changes the access level of a record
 499  * @param integer The increment to reorder by
 500  */
 501  function changeAccess( $id, $access, $option  ) {
 502      global $database;
 503      
 504      josSpoofCheck();
 505  
 506      $row = new mosContent( $database );
 507      $row->load( (int)$id );
 508      $row->access = $access;
 509  
 510      if ( !$row->check() ) {
 511          return $row->getError();
 512      }
 513      if ( !$row->store() ) {
 514          return $row->getError();
 515      }
 516  
 517      // clean any existing cache files
 518      mosCache::cleanCache( 'com_content' );
 519  
 520      mosRedirect( 'index2.php?option='. $option );
 521  }
 522  
 523  
 524  /**
 525  * Function to reset Hit count of a content item
 526  */
 527  function resethits( $option, $id ) {
 528      global $database;
 529      
 530      josSpoofCheck();
 531  
 532      $row = new mosContent($database);
 533      $row->Load( (int)$id );
 534      $row->hits = "0";
 535      $row->store();
 536      $row->checkin();
 537  
 538      $msg = 'Successfully Reset Hit';
 539      mosRedirect( 'index2.php?option='. $option .'&task=edit&hidemainmenu=1&id='. $row->id, $msg );
 540  }
 541  
 542  /**
 543  * Cancels an edit operation
 544  * @param database A database connector object
 545  */
 546  function cancel( $option ) {
 547      global $database;
 548      
 549      josSpoofCheck();
 550  
 551      $row = new mosContent( $database );
 552      $row->bind( $_POST );
 553      $row->checkin();
 554      mosRedirect( 'index2.php?option='. $option );
 555  }
 556  
 557  function menuLink( $option, $id ) {
 558      global $database;
 559      
 560      josSpoofCheck();
 561  
 562      $menu     = strval( mosGetParam( $_POST, 'menuselect', '' ) );
 563      $link     = strval( mosGetParam( $_POST, 'link_name', '' ) );
 564  
 565      $link    = stripslashes( ampReplace($link) );
 566  
 567      $row                 = new mosMenu( $database );
 568      $row->menutype         = $menu;
 569      $row->name             = $link;
 570      $row->type             = 'content_typed';
 571      $row->published        = 1;
 572      $row->componentid    = $id;
 573      $row->link            = 'index.php?option=com_content&task=view&id='. $id;
 574      $row->ordering        = 9999;
 575  
 576      if (!$row->check()) {
 577          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 578          exit();
 579      }
 580      if (!$row->store()) {
 581          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 582          exit();
 583      }
 584      $row->checkin();
 585      $row->updateOrder( "menutype=" . $database->Quote( $row->menutype ) . " AND parent=" . (int) $row->parent );
 586  
 587      // clean any existing cache files
 588      mosCache::cleanCache( 'com_content' );
 589  
 590      $msg = $link .' (Link - Static Content) in menu: '. $menu .' successfully created';
 591      mosRedirect( 'index2.php?option='. $option .'&task=edit&hidemainmenu=1&id='. $id, $msg );
 592  }
 593  
 594  function go2menu() {
 595      global $database;
 596      
 597      josSpoofCheck();
 598  
 599      // checkin content
 600      $row = new mosContent( $database );
 601      $row->bind( $_POST );
 602      $row->checkin();
 603  
 604      $menu = strval( mosGetParam( $_POST, 'menu', 'mainmenu' ) );
 605  
 606      mosRedirect( 'index2.php?option=com_menus&menutype='. $menu );
 607  }
 608  
 609  function go2menuitem() {
 610      global $database;
 611      
 612      josSpoofCheck();
 613  
 614      // checkin content
 615      $row = new mosContent( $database );
 616      $row->bind( $_POST );
 617      $row->checkin();
 618  
 619      $menu     = strval( mosGetParam( $_POST, 'menu', 'mainmenu' ) );
 620      $id        = intval( mosGetParam( $_POST, 'menuid', 0 ) );
 621  
 622      mosRedirect( 'index2.php?option=com_menus&menutype='. $menu .'&task=edit&hidemainmenu=1&id='. $id );
 623  }
 624  
 625  function saveOrder( &$cid ) {
 626      global $database;
 627      
 628      josSpoofCheck();
 629  
 630      $total        = count( $cid );
 631      $order         = josGetArrayInts( 'order' );
 632  
 633      $row         = new mosContent( $database );
 634      $conditions = array();
 635  
 636      // update ordering values
 637      for ( $i=0; $i < $total; $i++ ) {
 638          $row->load( (int) $cid[$i] );
 639          if ($row->ordering != $order[$i]) {
 640              $row->ordering = $order[$i];
 641              if (!$row->store()) {
 642                  echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 643                  exit();
 644              } // if
 645              // remember to updateOrder this group
 646              $condition = "catid=" . (int) $row->catid . " AND state >= 0";
 647              $found = false;
 648              foreach ( $conditions as $cond )
 649                  if ($cond[1]==$condition) {
 650                      $found = true;
 651                      break;
 652                  } // if
 653              if (!$found) $conditions[] = array($row->id, $condition);
 654          } // if
 655      } // for
 656  
 657      // execute updateOrder for each group
 658      foreach ( $conditions as $cond ) {
 659          $row->load( $cond[0] );
 660          $row->updateOrder( $cond[1] );
 661      } // foreach
 662  
 663      // clean any existing cache files
 664      mosCache::cleanCache( 'com_content' );
 665  
 666      $msg     = 'New ordering saved';
 667      mosRedirect( 'index2.php?option=com_typedcontent', $msg );
 668  } // saveOrder
 669  ?>