[ Index ]

PHP Cross Reference of Mambo 4.6.5

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

title

Body

[close]

/administrator/components/com_content/ -> admin.content.php (source)

   1  <?php
   2  /**
   3  * @package Mambo
   4  * @subpackage Content
   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  $sectionid = mosGetParam( $_REQUEST, 'sectionid', 0 );
  24  $id = mosGetParam( $_REQUEST, 'id', '' );
  25  $cid = mosGetParam( $_POST, 'cid', array(0) );
  26  if (!is_array( $cid )) {
  27      $cid = array(0);
  28  }
  29  
  30  switch ($task) {
  31      case 'clean_cache':
  32          mosCache::cleanCache( 'com_content' );
  33          mosRedirect( 'index2.php', 'Cache cleaned' );
  34          break;
  35  
  36      case 'new':
  37          editContent( 0, $sectionid, $option );
  38          break;
  39  
  40      case 'edit':
  41          editContent( $id, $sectionid, $option );
  42          break;
  43  
  44      case 'editA':
  45          editContent( $cid[0], '', $option );
  46          break;
  47  
  48      case 'go2menu':
  49      case 'go2menuitem':
  50      case 'resethits':
  51      case 'menulink':
  52      case 'apply':
  53      case 'save':
  54          mosCache::cleanCache( 'com_content' );
  55          saveContent( $sectionid, $task );
  56          break;
  57  
  58      case 'remove':
  59          removeContent( $cid, $sectionid, $option );
  60          break;
  61  
  62      case 'publish':
  63          changeContent( $cid, 1, $option );
  64          break;
  65  
  66      case 'unpublish':
  67          changeContent( $cid, 0, $option );
  68          break;
  69  
  70      case 'toggle_frontpage':
  71          toggleFrontPage( $cid, $sectionid, $option );
  72          break;
  73  
  74      case 'archive':
  75          changeContent( $cid, -1, $option );
  76          break;
  77  
  78      case 'unarchive':
  79          changeContent( $cid, 0, $option );
  80          break;
  81  
  82      case 'cancel':
  83          cancelContent();
  84          break;
  85  
  86      case 'orderup':
  87          orderContent( $cid[0], -1, $option );
  88          break;
  89  
  90      case 'orderdown':
  91          orderContent( $cid[0], 1, $option );
  92          break;
  93  
  94      case 'showarchive':
  95          viewArchive( $sectionid, $option );
  96          break;
  97  
  98      case 'movesect':
  99          moveSection( $cid, $sectionid, $option );
 100          break;
 101  
 102      case 'movesectsave':
 103          moveSectionSave( $cid, $sectionid, $option );
 104          break;
 105  
 106      case 'copy':
 107          copyItem( $cid, $sectionid, $option );
 108          break;
 109  
 110      case 'copysave':
 111          copyItemSave( $cid, $sectionid, $option );
 112          break;
 113  
 114      case 'accesspublic':
 115          accessMenu( $cid[0], 0, $option );
 116          break;
 117  
 118      case 'accessregistered':
 119          accessMenu( $cid[0], 1, $option );
 120          break;
 121  
 122      case 'accessspecial':
 123          accessMenu( $cid[0], 2, $option );
 124          break;
 125  
 126      case 'saveorder':
 127          saveOrder( $cid );
 128          break;
 129  
 130      default:
 131          viewContent( $sectionid, $option );
 132          break;
 133  }
 134  
 135  /**
 136  * Compiles a list of installed or defined modules
 137  * @param database A database connector object
 138  */
 139  function viewContent( $sectionid, $option ) {
 140      global $database, $mainframe, $mosConfig_list_limit;
 141  
 142      $catid                 = $mainframe->getUserStateFromRequest( "catid{$option}{$sectionid}", 'catid', 0 );
 143      $filter_authorid     = $mainframe->getUserStateFromRequest( "filter_authorid{$option}{$sectionid}", 'filter_authorid', 0 );
 144      $filter_sectionid     = $mainframe->getUserStateFromRequest( "filter_sectionid{$option}{$sectionid}", 'filter_sectionid', 0 );
 145      $limit                 = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit );
 146      $limitstart         = $mainframe->getUserStateFromRequest( "view{$option}{$sectionid}limitstart", 'limitstart', 0 );
 147      $search             = $mainframe->getUserStateFromRequest( "search{$option}{$sectionid}", 'search', '' );
 148      $search             = $database->getEscaped( trim( strtolower( $search ) ) );
 149      $redirect             = $sectionid;
 150      $filter             = ''; //getting a undefined variable error
 151  
 152      if ( $sectionid == 0 ) {
 153          // used to show All content items
 154          $where = array(
 155          "c.state >= 0",
 156          "c.catid=cc.id",
 157          "cc.section=s.id",
 158          "s.scope='content'",
 159          );
 160          $order = "\n ORDER BY s.title, c.catid, cc.ordering, cc.title, c.ordering";
 161          $all = 1;
 162          //$filter = "\n , #__sections AS s WHERE s.id = c.section";
 163  
 164          if ($filter_sectionid > 0) {
 165              $filter = "\nWHERE cc.section=$filter_sectionid";
 166          }
 167          $section->title = T_('All Content Items');
 168          $section->id = 0;
 169      } else {
 170          $where = array(
 171          "c.state >= 0",
 172          "c.catid=cc.id",
 173          "cc.section=s.id",
 174          "s.scope='content'",
 175          "c.sectionid='$sectionid'"
 176          );
 177          $order = "\n ORDER BY cc.ordering, cc.title, c.ordering";
 178          $all = NULL;
 179          $filter = "\n WHERE cc.section = '$sectionid'";
 180          $section = new mosSection( $database );
 181          $section->load( $sectionid );
 182      }
 183  
 184      // used by filter
 185      if ( $filter_sectionid > 0 ) {
 186          $where[] = "c.sectionid = '$filter_sectionid'";
 187      }
 188      if ( $catid > 0 ) {
 189          $where[] = "c.catid = '$catid'";
 190      }
 191      if ( $filter_authorid > 0 ) {
 192          $where[] = "c.created_by = '$filter_authorid'";
 193      }
 194  
 195      if ( $search ) {
 196          $where[] = "LOWER( c.title ) LIKE '%$search%'";
 197      }
 198  
 199      // get the total number of records
 200      $database->setQuery( "SELECT count(*) FROM #__content AS c, #__categories AS cc, #__sections AS s"
 201      . (count( $where ) ? "\nWHERE " . implode( ' AND ', $where ) : "")
 202      );
 203      $total = $database->loadResult();
 204      require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
 205      $pageNav = new mosPageNav( $total, $limitstart, $limit );
 206  
 207      $query = "SELECT c.*, g.name AS groupname, cc.name, u.name AS editor, f.content_id AS frontpage, s.title AS section_name, v.name AS author"
 208      . "\n FROM #__categories AS cc, #__sections AS s, #__content AS c"
 209      . "\n LEFT JOIN #__groups AS g ON g.id = c.access"
 210      . "\n LEFT JOIN #__users AS u ON u.id = c.checked_out"
 211      . "\n LEFT JOIN #__users AS v ON v.id = c.created_by"
 212      . "\n LEFT JOIN #__content_frontpage AS f ON f.content_id = c.id"
 213      . ( count( $where ) ? "\nWHERE " . implode( ' AND ', $where ) : '' )
 214      . $order
 215      . "\n LIMIT $pageNav->limitstart,$pageNav->limit"
 216      ;
 217      $database->setQuery( $query );
 218      $rows = $database->loadObjectList();
 219  
 220      if ($database->getErrorNum()) {
 221          echo $database->stderr();
 222          return false;
 223      }
 224  
 225      // get list of categories for dropdown filter
 226      $query = "SELECT cc.id AS value, cc.title AS text, section"
 227      . "\n FROM #__categories AS cc"
 228      . "\n INNER JOIN #__sections AS s ON s.id=cc.section "
 229      . $filter
 230      . "\n ORDER BY s.ordering, cc.ordering"
 231      ;
 232      $lists['catid']     = filterCategory( $query, $catid );
 233  
 234      // get list of sections for dropdown filter
 235      $javascript = 'onchange="document.adminForm.submit();"';
 236      $lists['sectionid']    = mosAdminMenus::SelectSection( 'filter_sectionid', $filter_sectionid, $javascript );
 237  
 238      // get list of Authors for dropdown filter
 239      $query = "SELECT c.created_by AS value, u.name AS text"
 240      . "\n FROM #__content AS c"
 241      . "\n INNER JOIN #__sections AS s ON s.id = c.sectionid"
 242      . "\n LEFT JOIN #__users AS u ON u.id = c.created_by"
 243      . "\n WHERE c.state <> '-1'"
 244      . "\n AND c.state <> '-2'"
 245      . "\n GROUP BY u.name"
 246      . "\n ORDER BY u.name"
 247      ;
 248      $authors[] = mosHTML::makeOption( '0', T_('- All Authors -') );
 249      $database->setQuery( $query );
 250      if (is_array($database->loadObjectList())) {
 251        $authors = array_merge( $authors, $database->loadObjectList() );
 252      }
 253      $lists['authorid']    = mosHTML::selectList( $authors, 'filter_authorid', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', $filter_authorid );
 254  
 255      HTML_content::showContent( $rows, $section, $lists, $search, $pageNav, $all, $redirect );
 256  }
 257  
 258  /**
 259  * Shows a list of archived content items
 260  * @param int The section id
 261  */
 262  function viewArchive( $sectionid, $option ) {
 263      global $database, $mainframe, $mosConfig_list_limit;
 264  
 265      $catid                 = $mainframe->getUserStateFromRequest( "catidarc{$option}{$sectionid}", 'catid', 0 );
 266      $limit                 = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit );
 267      $limitstart         = $mainframe->getUserStateFromRequest( "viewarc{$option}{$sectionid}limitstart", 'limitstart', 0 );
 268      $search             = $mainframe->getUserStateFromRequest( "searcharc{$option}{$sectionid}", 'search', '' );
 269      $filter_authorid     = $mainframe->getUserStateFromRequest( "filter_authorid{$option}{$sectionid}", 'filter_authorid', 0 );
 270      $filter_sectionid     = $mainframe->getUserStateFromRequest( "filter_sectionid{$option}{$sectionid}", 'filter_sectionid', 0 );
 271      $search             = $database->getEscaped( trim( strtolower( $search ) ) );
 272      $redirect             = $sectionid;
 273  
 274      if ( $sectionid == 0 ) {
 275          $where = array(
 276          "c.state = -1",
 277          "c.catid=cc.id",
 278          "cc.section=s.id",
 279          "s.scope='content'"
 280          );
 281          $filter = "\n , #__sections AS s WHERE s.id = c.section";
 282          $all = 1;
 283      } else {
 284          $where = array(
 285          "c.state = -1",
 286          "c.catid=cc.id",
 287          "cc.section=s.id",
 288          "s.scope='content'",
 289          "c.sectionid='$sectionid'"
 290          );
 291          $filter = "\n WHERE section = '$sectionid'";
 292          $all = NULL;
 293      }
 294  
 295      // used by filter
 296      if ( $filter_sectionid > 0 ) {
 297          $where[] = "c.sectionid = '$filter_sectionid'";
 298      }
 299      if ( $filter_authorid > 0 ) {
 300          $where[] = "c.created_by = '$filter_authorid'";
 301      }
 302      if ($catid > 0) {
 303          $where[] = "c.catid='$catid'";
 304      }
 305      if ($search) {
 306          $where[] = "LOWER(c.title) LIKE '%$search%'";
 307      }
 308  
 309      // get the total number of records
 310      $query = "SELECT count(*)"
 311      . "FROM #__content AS c, #__categories AS cc, #__sections AS s"
 312      . ( count( $where ) ? "\n WHERE " . implode( ' AND ', $where ) : '' )
 313      ;
 314      $database->setQuery( $query );
 315      $total = $database->loadResult();
 316  
 317      require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
 318      $pageNav = new mosPageNav( $total, $limitstart, $limit  );
 319  
 320      $query = "SELECT c.*, g.name AS groupname, cc.name, v.name AS author"
 321      . "\n FROM #__categories AS cc, #__sections AS s, #__content AS c"
 322      . "\n LEFT JOIN #__groups AS g ON g.id = c.access"
 323      . "\n LEFT JOIN #__users AS v ON v.id = c.created_by"
 324      . ( count( $where ) ? "\nWHERE " . implode( ' AND ', $where ) : '' )
 325      . "\n ORDER BY c.catid, c.ordering"
 326      . "\n LIMIT $pageNav->limitstart,$pageNav->limit"
 327      ;
 328      $database->setQuery( $query );
 329      $rows = $database->loadObjectList();
 330      if ($database->getErrorNum()) {
 331          echo $database->stderr();
 332          return;
 333      }
 334  
 335      // get list of categories for dropdown filter
 336      // @RawSQLUse, trivial_implementation, SELECT
 337      $query = "SELECT c.id AS value, c.title AS text"
 338      . "\n FROM #__categories AS c"
 339      . $filter
 340      . "\n ORDER BY c.ordering"
 341      ;
 342      $lists['catid']             = filterCategory( $query, $catid );
 343  
 344      // get list of sections for dropdown filter
 345      $javascript = 'onchange="document.adminForm.submit();"';
 346      $lists['sectionid']            = mosAdminMenus::SelectSection( 'filter_sectionid', $filter_sectionid, $javascript );
 347  
 348      $section = new mosSection( $database );
 349      $section->load( $sectionid );
 350  
 351      // get list of Authors for dropdown filter
 352      $query = "SELECT c.created_by AS value, u.name AS text"
 353      . "\n FROM #__content AS c"
 354      . "\n INNER JOIN #__sections AS s ON s.id = c.sectionid"
 355      . "\n LEFT JOIN #__users AS u ON u.id = c.created_by"
 356      . "\n WHERE c.state = '-1'"
 357      . "\n GROUP BY u.name"
 358      . "\n ORDER BY u.name"
 359      ;
 360      $authors[] = mosHTML::makeOption( '0', T_('- All Authors -') );
 361      $database->setQuery( $query );
 362      $moreauthors = $database->loadObjectList();
 363      if ($moreauthors) $authors = array_merge( $authors, $moreauthors );
 364      $lists['authorid']    = mosHTML::selectList( $authors, 'filter_authorid', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', $filter_authorid );
 365  
 366      HTML_content::showArchive( $rows, $section, $lists, $search, $pageNav, $option, $all, $redirect );
 367  }
 368  
 369  /**
 370  * Compiles information to add or edit the record
 371  * @param database A database connector object
 372  * @param integer The unique id of the record to edit (0 if new)
 373  * @param integer The id of the content section
 374  */
 375  function editContent( $uid=0, $sectionid=0, $option ) {
 376      global $database, $my, $mainframe;
 377      global $mosConfig_absolute_path, $mosConfig_live_site, $mosConfig_offset;
 378  
 379      $redirect = mosGetParam( $_POST, 'redirect', '' );
 380      if ( !$redirect ) {
 381          $redirect = $sectionid;
 382      }
 383  
 384      // load the row from the db table
 385      $row = new mosContent( $database );
 386      $row->load( $uid );
 387  
 388      if ($uid) {
 389          $sectionid = $row->sectionid;
 390          if ($row->state < 0) {
 391              mosRedirect( 'index2.php?option=com_content&sectionid='. $row->sectionid, T_('You cannot edit an archived item') );
 392          }
 393      }
 394  
 395      if ( $sectionid == 0 ) {
 396          $where = "\n WHERE section NOT LIKE '%com_%'";
 397      } else {
 398          $where = "\n WHERE section='$sectionid'";
 399      }
 400  
 401      // get the type name - which is a special category
 402       if ($row->sectionid){
 403           // @RawSQLUse, trivial_implementation, SELECT
 404          $query = "SELECT name FROM #__sections WHERE id=$row->sectionid";
 405          $database->setQuery( $query );
 406          $section = $database->loadResult();
 407          $contentSection = $section;
 408      } else {
 409          // @RawSQLUse, trivial_implementation, SELECT
 410          $query = "SELECT name FROM #__sections WHERE id=$sectionid";
 411          $database->setQuery( $query );
 412          $section = $database->loadResult();
 413          $contentSection = $section;
 414      }
 415  
 416      // fail if checked out not by 'me'
 417      if ($row->checked_out && $row->checked_out <> $my->id) {
 418          mosRedirect( 'index2.php?option=com_content', sprintf(T_('The module %s is currently being edited by another administrator'), $row->title) );
 419      }
 420  
 421      if ($uid) {
 422          $row->checkout( $my->id );
 423          if (trim( $row->images )) {
 424              $row->images = explode( "\n", $row->images );
 425          } else {
 426              $row->images = array();
 427          }
 428  
 429           $row->created         = mosFormatDate( $row->created, '%Y-%m-%d %H:%M:%S' );
 430          $row->modified         = mosFormatDate( $row->modified, '%Y-%m-%d %H:%M:%S' );
 431          $row->publish_up     = mosFormatDate( $row->publish_up, '%Y-%m-%d %H:%M:%S' );
 432  
 433            if (trim( $row->publish_down ) == '0000-00-00 00:00:00') {
 434              $row->publish_down = T_('Never');
 435          }
 436  
 437          // @RawSQLUse, trivial_implementation, SELECT
 438          $query = "SELECT name from #__users"
 439          . "\n WHERE id=$row->created_by"
 440          ;
 441          $database->setQuery( $query );
 442          $row->creator = $database->loadResult();
 443  
 444          // @RawSQLUse, trivial_implementation, SELECT
 445          $query = "SELECT name from #__users"
 446          . "\n WHERE id=$row->modified_by"
 447          ;
 448          $database->setQuery( $query );
 449          $row->modifier = $database->loadResult();
 450  
 451          // @RawSQLUse, trivial_implementation, SELECT
 452          $query = "SELECT content_id from #__content_frontpage"
 453          . "\n WHERE content_id=$row->id"
 454          ;
 455          $database->setQuery( $query );
 456          $row->frontpage = $database->loadResult();
 457  
 458          // get list of links to this item
 459          $_and = "\n AND componentid = ". $row->id;
 460          $menus = mosAdminMenus::Links2Menu( 'content_item_link', $_and );
 461      } else {
 462          $row->sectionid     = $sectionid;
 463          $row->version         = 0;
 464          $row->state         = 1;
 465          $row->ordering         = 0;
 466          $row->images         = array();
 467          //$row->publish_up     = date( 'Y-m-d', time() );
 468          $row->publish_up     = date( 'Y-m-d', time() + $mosConfig_offset * 60 * 60 );
 469          $row->publish_down     = T_('Never');
 470          $row->catid         = NULL;
 471          $row->creator         = '';
 472          $row->modifier         = '';
 473          $row->frontpage     = 0;
 474          $menus = array();
 475      }
 476  
 477      $javascript = "onchange=\"changeDynaList( 'catid', sectioncategories, document.adminForm.sectionid.options[document.adminForm.sectionid.selectedIndex].value, 0, 0);\"";
 478  
 479      // @RawSQLUse, trivial_implementation, SELECT
 480      $query = "SELECT s.id AS value, s.title AS text"
 481      . "\n FROM #__sections AS s"
 482      . "\n ORDER BY s.ordering";
 483      $database->setQuery( $query );
 484      
 485      $sections = $database->loadObjectList();
 486          
 487      if ( $sectionid == 0 ) {        
 488          if ($sections) {
 489              array_unshift ($sections, mosHTML::makeOption( '-1', T_('Select Section')));
 490          } else {
 491              $sections[] = mosHTML::makeOption( '-1', T_('Add Section(s) First') );
 492          }    
 493          $lists['sectionid'] = mosHTML::selectList( $sections, 'sectionid', 'class="inputbox" size="1" '. $javascript, 'value', 'text' );
 494      } else {
 495              $lists['sectionid'] = mosHTML::selectList( $sections, 'sectionid', 'class="inputbox" size="1" '. $javascript, 'value', 'text', intval( $row->sectionid));
 496      }
 497              
 498      $sectioncategories             = array();
 499      $sectioncategories[-1]         = array();
 500      $sectioncategories[-1][]     = mosHTML::makeOption( '-1', T_('Select Category') );
 501      if ($sections) foreach($sections as $section) {
 502          $sectioncategories[$section->value] = array();
 503          // @RawSQLUse, trivial_implementation, SELECT
 504          $query = "SELECT id AS value, name AS text"
 505              . "\n FROM #__categories"
 506              . "\n WHERE section='$section->value'"
 507              . "\n ORDER BY ordering";
 508          $database->setQuery( $query );
 509          $rows2 = $database->loadObjectList();
 510          if ($rows2) foreach($rows2 as $row2) $sectioncategories[$section->value][] = mosHTML::makeOption( $row2->value, $row2->text );
 511          else $sectioncategories[$section->value][] = mosHTML::makeOption( "-1", T_('Add Categories First') );
 512      }
 513  
 514       // get list of categories
 515        if ( !$row->catid && !$row->sectionid ) {
 516           $categories[]         = mosHTML::makeOption( '-1', T_('Select Category') );
 517           $lists['catid']     = mosHTML::selectList( $categories, 'catid', 'class="inputbox" size="1"', 'value', 'text' );
 518        } else {
 519           $query = "SELECT id AS value, name AS text"
 520           . "\n FROM #__categories"
 521           . $where
 522           . "\n ORDER BY ordering";
 523           $database->setQuery( $query );
 524           $categories[]         = mosHTML::makeOption( '-1', T_('Select Category') );
 525           $categories         = array_merge( $categories, $database->loadObjectList() );
 526           $lists['catid']     = mosHTML::selectList( $categories, 'catid', 'class="inputbox" size="1"', 'value', 'text', intval( $row->catid ) );
 527        }
 528  
 529      // build the html select list for ordering
 530      $query = "SELECT ordering AS value, title AS text"
 531      . "\n FROM #__content"
 532      . "\n WHERE catid='$row->catid'"
 533      . "\n AND state >= 0"
 534      . "\n ORDER BY ordering"
 535      ;
 536      $lists['ordering'] = mosAdminMenus::SpecificOrdering( $row, $uid, $query, 1 );
 537  
 538      // calls function to read image from directory
 539      $pathA         = $mosConfig_absolute_path .'/images/stories';
 540      $pathL         = $mosConfig_live_site .'/images/stories';
 541      $images     = array();
 542      $folders     = array();
 543      $folders[]     = mosHTML::makeOption( '/' );
 544      mosAdminMenus::ReadImages( $pathA, '/', $folders, $images );
 545  
 546      // list of folders in images/stories/
 547      $lists['folders']             = mosAdminMenus::GetImageFolders( $folders, $pathL );
 548      // list of images in specfic folder in images/stories/
 549      $lists['imagefiles']        = mosAdminMenus::GetImages( $images, $pathL );
 550      // list of saved images
 551      $lists['imagelist']         = mosAdminMenus::GetSavedImages( $row, $pathL );
 552  
 553      // build list of users
 554      $active = ( intval( $row->created_by ) ? intval( $row->created_by ) : $my->id );
 555      $lists['created_by']         = mosAdminMenus::UserSelect( 'created_by', $active );
 556      // build the select list for the image position alignment
 557      $lists['_align']             = mosAdminMenus::Positions( '_align' );
 558      // build the select list for the image caption alignment
 559      $lists['_caption_align']     = mosAdminMenus::Positions( '_caption_align' );
 560      // build the html select list for the group access
 561      $lists['access']             = mosAdminMenus::Access( $row );
 562      // build the html select list for menu selection
 563      $lists['menuselect']        = mosAdminMenus::MenuSelect( );
 564  
 565      // build the select list for the image caption position
 566      $pos[] = mosHTML::makeOption( 'bottom', T_('Bottom') );
 567      $pos[] = mosHTML::makeOption( 'top', T_('Top') );
 568      $lists['_caption_position'] = mosHTML::selectList( $pos, '_caption_position', 'class="inputbox" size="1"', 'value', 'text' );
 569  
 570  
 571      // get params definitions
 572      $params =& new mosAdminParameters( $row->attribs, $mainframe->getPath( 'com_xml', 'com_content' ), 'component' );
 573  
 574      HTML_content::editContent( $row, $contentSection, $lists, $sectioncategories, $images, $params, $option, $redirect, $menus );
 575  }
 576  
 577  /**
 578  * Saves the content item an edit form submit
 579  * @param database A database connector object
 580  */
 581  function saveContent( $sectionid, $task ) {
 582      global $database, $my, $mainframe, $mosConfig_offset;
 583  
 584      $menu         = mosGetParam( $_POST, 'menu', 'mainmenu' );
 585      $menuid        = mosGetParam( $_POST, 'menuid', 0 );
 586  
 587      $row = new mosContent( $database );
 588      if (!$row->bind( $_POST )) {
 589          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 590          exit();
 591      }
 592  
 593      $isNew = ( $row->id < 1 );
 594      if ($isNew) {
 595          //$row->created        = $row->created ? $row->created : date( "Y-m-d H:i:s" );
 596          $row->created         = $row->created ? mosFormatDate( $row->created, '%Y-%m-%d %H:%M:%S', -$mosConfig_offset * 60 * 60 ) : date( "Y-m-d H:i:s" );
 597          $row->created_by     = $row->created_by ? $row->created_by : $my->id;
 598      } else {
 599          $row->modified         = date( "Y-m-d H:i:s" );
 600          $row->modified_by     = $my->id;
 601      }
 602  
 603      if (strlen(trim( $row->publish_up )) <= 10) {
 604            $row->publish_up .= " 00:00:00";
 605      }
 606      $row->publish_up = mosFormatDate($row->publish_up, '%Y-%m-%d %H:%M:%S', -$mosConfig_offset );
 607  
 608      if (trim( $row->publish_down ) == T_("Never")) {
 609          $row->publish_down = "0000-00-00 00:00:00";
 610      }
 611  
 612      $row->state = mosGetParam( $_REQUEST, 'published', 0 );
 613  
 614      $params = mosGetParam( $_POST, 'params', '' );
 615      if (is_array( $params )) {
 616          $txt = array();
 617          foreach ( $params as $k=>$v) {
 618              $txt[] = "$k=$v";
 619          }
 620          $row->attribs = implode( "\n", $txt );
 621      }
 622  
 623      // code cleaner for xhtml transitional compliance
 624      $row->introtext = str_replace( '<br>', '<br />', $row->introtext );
 625      $row->fulltext     = str_replace( '<br>', '<br />', $row->fulltext );
 626  
 627       // remove <br /> take being automatically added to empty fulltext
 628       $length    = strlen( $row->fulltext ) < 9;
 629       $search = strstr( $row->fulltext, '<br />');
 630       if ( $length && $search ) {
 631           $row->fulltext = NULL;
 632       }
 633  
 634       if (!$row->check()) {
 635          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 636          exit();
 637      }
 638      $row->version++;
 639      if (!$row->store()) {
 640          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 641          exit();
 642      }
 643  
 644      // manage frontpage items
 645      require_once( $mainframe->getPath( 'class', 'com_frontpage' ) );
 646      $fp = new mosFrontPage( $database );
 647  
 648      if (mosGetParam( $_REQUEST, 'frontpage', 0 )) {
 649  
 650          // toggles go to first place
 651          if (!$fp->load( $row->id )) {
 652              // new entry
 653              // @RawSQLUse, trivial_implementation, INSERT
 654              $database->setQuery( "INSERT INTO #__content_frontpage VALUES ('$row->id','1')" );
 655              if (!$database->query()) {
 656                  echo "<script> alert('".$database->stderr()."');</script>\n";
 657                  exit();
 658              }
 659              $fp->ordering = 1;
 660          }
 661      } else {
 662          // no frontpage mask
 663          if (!$fp->delete( $row->id )) {
 664              $msg .= $fp->stderr();
 665          }
 666          $fp->ordering = 0;
 667      }
 668      $fp->updateOrder();
 669  
 670      $row->checkin();
 671      $row->updateOrder( "catid='$row->catid' AND state >= 0" );
 672  
 673      $redirect = mosGetParam( $_POST, 'redirect', $sectionid );
 674      switch ( $task ) {
 675          case 'go2menu':
 676              mosRedirect( 'index2.php?option=com_menus&menutype='. $menu );
 677              break;
 678  
 679          case 'go2menuitem':
 680              mosRedirect( 'index2.php?option=com_menus&menutype='. $menu .'&task=edit&hidemainmenu=1&id='. $menuid );
 681              break;
 682  
 683          case 'menulink':
 684              menuLink( $redirect, $row->id );
 685              break;
 686  
 687          case 'resethits':
 688              resethits( $redirect, $row->id );
 689              break;
 690  
 691          case 'apply':
 692              $msg = T_('Successfully Saved changes to Item: '). $row->title;
 693              mosRedirect( 'index2.php?option=com_content&sectionid='. $redirect .'&task=edit&hidemainmenu=1&id='. $row->id, $msg );
 694  
 695          case 'save':
 696          default:
 697              $msg = T_('Successfully Saved Item: '). $row->title;
 698              mosRedirect( 'index2.php?option=com_content&sectionid='. $redirect, $msg );
 699  
 700              break;
 701      }
 702  }
 703  
 704  /**
 705  * Changes the state of one or more content pages
 706  * @param string The name of the category section
 707  * @param integer A unique category id (passed from an edit form)
 708  * @param array An array of unique category id numbers
 709  * @param integer 0 if unpublishing, 1 if publishing
 710  * @param string The name of the current user
 711  */
 712  function changeContent( $cid=null, $state=0, $option ) {
 713      global $database, $my;
 714  
 715      if (count( $cid ) < 1) {
 716          $action = $state == 1 ? T_('publish') : ($state == -1 ? T_('archive') : T_('unpublish'));
 717          echo "<script> alert('".sprintf(T_('Select an item to %s'),$action)."'); window.history.go(-1);</script>\n";
 718          exit;
 719      }
 720  
 721      $total = count ( $cid );
 722      $cids = implode( ',', $cid );
 723  
 724      $database->setQuery( "UPDATE #__content SET state='$state'"
 725      . "\nWHERE id IN ($cids) AND (checked_out=0 OR (checked_out='".$my->id."'))"
 726      );
 727      if (!$database->query()) {
 728          echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 729          exit();
 730      }
 731  
 732      if (count( $cid ) == 1) {
 733          $row = new mosContent( $database );
 734          $row->checkin( $cid[0] );
 735      }
 736  
 737      if ( $state == "-1" ) {
 738          $msg = sprintf(Tn_('%d Item successfully Archived', '%d Items successfully Archived',$total),$total);
 739      } else if ( $state == "1" ) {
 740          $msg = sprintf(Tn_('%d Item successfully Published', '%d Items successfully Published',$total),$total);
 741      } else if ( $state == "0" ) {
 742          $msg = sprintf(Tn_('%d Item successfully Unpublished', '%d Items successfully Unpublished',$total),$total);
 743      }
 744  
 745      $redirect = mosGetParam( $_POST, 'redirect', $row->sectionid );
 746      $task = mosGetParam( $_POST, 'returntask', '' );
 747      if ( $task ) {
 748          $task = '&task='. $task;
 749      } else {
 750          $task = '';
 751      }
 752  
 753      mosRedirect( 'index2.php?option='. $option . $task .'&sectionid='. $redirect .'&mosmsg='. $msg );
 754  }
 755  
 756  /**
 757  * Changes the state of one or more content pages
 758  * @param string The name of the category section
 759  * @param integer A unique category id (passed from an edit form)
 760  * @param array An array of unique category id numbers
 761  * @param integer 0 if unpublishing, 1 if publishing
 762  * @param string The name of the current user
 763  */
 764  function toggleFrontPage( $cid, $section, $option ) {
 765      global $database, $my, $mainframe;
 766  
 767      if (count( $cid ) < 1) {
 768          echo "<script> alert('".T_('Select an item to toggle')."'); window.history.go(-1);</script>\n";
 769          exit;
 770      }
 771  
 772      $msg = '';
 773      require_once( $mainframe->getPath( 'class', 'com_frontpage' ) );
 774  
 775      $fp = new mosFrontPage( $database );
 776      foreach ($cid as $id) {
 777          // toggles go to first place
 778          if ($fp->load( $id )) {
 779              if (!$fp->delete( $id )) {
 780                  $msg .= $fp->stderr();
 781              }
 782              $fp->ordering = 0;
 783          } else {
 784              // new entry
 785              // @RawSQLUse, trivial_implementation, INSERT
 786              $database->setQuery( "INSERT INTO #__content_frontpage VALUES ('$id','0')" );
 787              if (!$database->query()) {
 788                  echo "<script> alert('".$database->stderr()."');</script>\n";
 789                  exit();
 790              }
 791              $fp->ordering = 0;
 792          }
 793          $fp->updateOrder();
 794      }
 795  
 796      mosRedirect( 'index2.php?option='. $option .'&sectionid='. $section, $msg );
 797  }
 798  
 799  function removeContent( &$cid, $sectionid, $option ) {
 800      global $database, $mainframe;
 801  
 802      $total = count( $cid );
 803      if ( $total < 1) {
 804          echo "<script> alert('".T_('Select an item to delete')."'); window.history.go(-1);</script>\n";
 805          exit;
 806      }
 807  
 808      $state = '-2';
 809      $ordering = '0';
 810      //seperate contentids
 811      $cids = implode( ',', $cid );
 812      // @RawSQLUse, trivial_implementation, UPDATE
 813      $query =     "UPDATE #__content SET state = '". $state ."', ordering = '". $ordering ."'"
 814      . "\n WHERE id IN ( ". $cids ." )"
 815      ;
 816      $database->setQuery( $query );
 817      if ( !$database->query() ) {
 818          echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 819          exit();
 820      }
 821  
 822      $msg = sprintf(Tn_('%d Item sent to the Trash', '%d Items sent to the Trash',$total),$total);
 823      $return = mosGetParam( $_POST, 'returntask', '' );
 824      mosRedirect( 'index2.php?option='. $option .'&task='. $return .'&sectionid='. $sectionid, $msg );
 825  }
 826  
 827  /**
 828  * Cancels an edit operation
 829  */
 830  function cancelContent( ) {
 831      global $database;
 832  
 833      $row = new mosContent( $database );
 834      $row->bind( $_POST );
 835      // sanitize
 836      $row->id = intval($row->id);
 837      $row->checkin();
 838  
 839      $redirect = mosGetParam( $_POST, 'redirect', 0 );
 840      mosRedirect( 'index2.php?option=com_content&sectionid='. $redirect );
 841  }
 842  
 843  /**
 844  * Moves the order of a record
 845  * @param integer The increment to reorder by
 846  */
 847  function orderContent( $uid, $inc, $option ) {
 848      global $database;
 849  
 850      $row = new mosContent( $database );
 851      $row->load( $uid );
 852      $row->move( $inc, "catid='$row->catid' AND state >= 0" );
 853  
 854      $redirect = mosGetParam( $_POST, 'redirect', $row->sectionid );
 855  
 856      mosRedirect( 'index2.php?option='. $option .'&sectionid='. $redirect );
 857  }
 858  
 859  /**
 860  * Form for moving item(s) to a different section and category
 861  */
 862  function moveSection( $cid, $sectionid, $option ) {
 863      global $database;
 864  
 865      if (!is_array( $cid ) || count( $cid ) < 1) {
 866          echo "<script> alert('".T_('Select an item to move')."'); window.history.go(-1);</script>\n";
 867          exit;
 868      }
 869  
 870      //seperate contentids
 871      $cids = implode( ',', $cid );
 872      // Content Items query
 873      // @RawSQLUse, trivial_implementation, SELECT
 874      $query =     "SELECT a.title"
 875      . "\n FROM #__content AS a"
 876      . "\n WHERE ( a.id IN (". $cids .") )"
 877      . "\n ORDER BY a.title"
 878      ;
 879      $database->setQuery( $query );
 880      $items = $database->loadObjectList();
 881  
 882      $database->setQuery(
 883      $query =     "SELECT CONCAT_WS( ', ', s.id, c.id ) AS `value`, CONCAT_WS( '/', s.name, c.name ) AS `text`"
 884      . "\n FROM #__sections AS s"
 885      . "\n INNER JOIN #__categories AS c ON c.section = s.id"
 886      . "\n WHERE s.scope = 'content'"
 887      . "\n ORDER BY s.name, c.name"
 888      );
 889      $rows = $database->loadObjectList();
 890      // build the html select list
 891      $sectCatList = mosHTML::selectList( $rows, 'sectcat', 'class="inputbox" size="8"', 'value', 'text', null );
 892  
 893      HTML_content::moveSection( $cid, $sectCatList, $option, $sectionid, $items );
 894  }
 895  
 896  /**
 897  * Save the changes to move item(s) to a different section and category
 898  */
 899  function moveSectionSave( &$cid, $sectionid, $option ) {
 900      global $database, $my;
 901  
 902      $sectcat = mosGetParam( $_POST, 'sectcat', '' );
 903      list( $newsect, $newcat ) = explode( ',', $sectcat );
 904  
 905      if (!$newsect && !$newcat ) {
 906          mosRedirect( "index.php?option=com_content&sectionid=$sectionid&mosmsg=".T_('An error has occurred')."" );
 907      }
 908  
 909      // find section name
 910      // @RawSQLUse, trivial_implementation, SELECT, CONCEPT
 911      $query = "SELECT a.name"
 912      . "\n FROM #__sections AS a"
 913      . "\n WHERE a.id = ". $newsect .""
 914      ;
 915      $database->setQuery( $query );
 916      $section = $database->loadResult();
 917  
 918      // find category name
 919      // @RawSQLUse, trivial_implementation, SELECT, CONCEPT
 920      $query = "SELECT  a.name"
 921      . "\n FROM #__categories AS a"
 922      . "\n WHERE a.id = ". $newcat .""
 923      ;
 924      $database->setQuery( $query );
 925      $category = $database->loadResult();
 926  
 927      $total = count( $cid );
 928      $cids = implode( ',', $cid );
 929  
 930      $row = new mosContent( $database );
 931      // update old orders - put existing items in last place
 932      foreach ($cid as $id) {
 933          $row->load( intval( $id ) );
 934          $row->ordering = 0;
 935          $row->store();
 936          $row->updateOrder( "catid='$row->catid' AND state >= 0" );
 937      }
 938  
 939      $query = "UPDATE #__content SET sectionid = '". $newsect ."', catid='". $newcat ."'"
 940      . "\n WHERE id IN ($cids)"
 941      . "\n AND ( checked_out='0' OR ( checked_out='". $my->id ."') )"
 942      ;
 943      $database->setQuery( $query );
 944      if ( !$database->query() ) {
 945          echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 946          exit();
 947      }
 948  
 949      // update new orders - put items in last place
 950      foreach ($cid as $id) {
 951          $row->load( intval( $id ) );
 952          $row->ordering = 0;
 953          $row->store();
 954          $row->updateOrder( "catid='". $row->catid ."' AND state >= 0" );
 955      }
 956  
 957      $msg = sprintf(Tn_('%d Item successfully moved to Section: %s, Category: %s', '%d Items successfully moved to Section: %s, Category: %s',$total),$total, $section, $category);
 958      mosRedirect( 'index2.php?option='. $option .'&sectionid='. $sectionid .'&mosmsg='. $msg );
 959  }
 960  
 961  
 962  /**
 963  * Form for copying item(s)
 964  **/
 965  function copyItem( $cid, $sectionid, $option ) {
 966      global $database;
 967  
 968      if (!is_array( $cid ) || count( $cid ) < 1) {
 969          echo "<script> alert('".T_('Select an item to move')."'); window.history.go(-1);</script>\n";
 970          exit;
 971      }
 972  
 973      //seperate contentids
 974      $cids = implode( ',', $cid );
 975      ## Content Items query
 976      // @RawSQLUse, trivial_implementation, SELECT, CONCEPT
 977      $query =     "SELECT a.title"
 978      . "\n FROM #__content AS a"
 979      . "\n WHERE ( a.id IN (". $cids .") )"
 980      . "\n ORDER BY a.title"
 981      ;
 982      $database->setQuery( $query );
 983      $items = $database->loadObjectList();
 984  
 985      ## Section & Category query
 986      $query =     "SELECT CONCAT_WS(',',s.id,c.id) AS `value`, CONCAT_WS(' // ', s.name, c.name) AS `text`"
 987      . "\n FROM #__sections AS s"
 988      . "\n INNER JOIN #__categories AS c ON c.section = s.id"
 989      . "\n WHERE s.scope='content'"
 990      . "\n ORDER BY s.name, c.name"
 991      ;
 992      $database->setQuery( $query );
 993      $rows = $database->loadObjectList();
 994      // build the html select list
 995      $sectCatList = mosHTML::selectList( $rows, 'sectcat', 'class="inputbox" size="10"', 'value', 'text', NULL );
 996  
 997      HTML_content::copySection( $option, $cid, $sectCatList, $sectionid, $items );
 998  }
 999  
1000  
1001  /**
1002  * saves Copies of items
1003  **/
1004  function copyItemSave( $cid, $sectionid, $option ) {
1005      global $database, $my;
1006  
1007      $sectcat = mosGetParam( $_POST, 'sectcat', '' );
1008      //seperate sections and categories from selection
1009      $sectcat = explode( ',', $sectcat );
1010      list( $newsect, $newcat ) = $sectcat;
1011  
1012      if ( !$newsect && !$newcat ) {
1013          mosRedirect( 'index.php?option=com_content&sectionid='. $sectionid .'&mosmsg='.urlencode(T_('An error has occurred')));
1014      }
1015  
1016      // find section name
1017      // @RawSQLUse, trivial_implementation, SELECT, CONCEPT
1018      $query =     "SELECT a.name"
1019      . "\n FROM #__sections AS a"
1020      . "\n WHERE a.id = ". $newsect .""
1021      ;
1022      $database->setQuery( $query );
1023      $section = $database->loadResult();
1024  
1025      // find category name
1026      // @RawSQLUse, trivial_implementation, SELECT, CONCEPT
1027      $query =     "SELECT  a.name"
1028      . "\n FROM #__categories AS a"
1029      . "\n WHERE a.id = ". $newcat .""
1030      ;
1031      $database->setQuery( $query );
1032      $category = $database->loadResult();
1033  
1034      $total = count( $cid );
1035      for ( $i = 0; $i < $total; $i++ ) {
1036          $row = new mosContent( $database );
1037  
1038          // main query
1039          // @RawSQLUse, trivial_implementation, SELECT, CONCEPT
1040          $query =    "SELECT a.* FROM #__content AS a"
1041          . "\n WHERE a.id = ". $cid[$i] ."";
1042          ;
1043          $database->setQuery( $query );
1044          $item = $database->loadObjectList();
1045  
1046          // values loaded into array set for store
1047          $row->id                 = NULL;
1048          $row->sectionid         = $newsect;
1049          $row->catid             = $newcat;
1050          $row->hits                 = '0';
1051          $row->ordering            = '0';
1052          $row->title             = $item[0]->title;
1053          $row->title_alias         = $item[0]->title_alias;
1054          $row->introtext         = $item[0]->introtext;
1055          $row->fulltext             = $item[0]->fulltext;
1056          $row->state             = $item[0]->state;
1057          $row->mask                 = $item[0]->mask;
1058          $row->created             = $item[0]->created;
1059          $row->created_by         = $item[0]->created_by;
1060          $row->created_by_alias     = $item[0]->created_by_alias;
1061          $row->modified             = $item[0]->modified;
1062          $row->modified_by         = $item[0]->modified_by;
1063          $row->checked_out         = $item[0]->checked_out;
1064          $row->checked_out_time     = $item[0]->checked_out_time;
1065          $row->frontpage_up         = $item[0]->frontpage_up;
1066          $row->frontpage_down     = $item[0]->frontpage_down;
1067          $row->publish_up         = $item[0]->publish_up;
1068          $row->publish_down         = $item[0]->publish_down;
1069          $row->images             = $item[0]->images;
1070          $row->attribs             = $item[0]->attribs;
1071          $row->version             = $item[0]->parentid;
1072          $row->parentid             = $item[0]->parentid;
1073          $row->metakey             = $item[0]->metakey;
1074          $row->metadesc             = $item[0]->metadesc;
1075          $row->access             = $item[0]->access;
1076  
1077          if (!$row->check()) {
1078              echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
1079              exit();
1080          }
1081          if (!$row->store()) {
1082              echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
1083              exit();
1084          }
1085          $row->updateOrder( "catid='". $row->catid ."' AND state >= 0" );
1086      }
1087  
1088      $msg = sprintf(Tn_('%d Item successfully copied to Section: %s, Category: %s', '%d Items successfully copied to Section: %s, Category: %s',$total),$total, $section, $category);
1089      mosRedirect( 'index2.php?option='. $option .'&sectionid='. $sectionid .'&mosmsg='. $msg );
1090  }
1091  
1092  /**
1093  * Function to reset Hit count of a content item
1094  * PT
1095  */
1096  function resethits( $redirect, $id ) {
1097      global $database;
1098  
1099      $row = new mosContent($database);
1100      $row->Load($id);
1101      $row->hits = "0";
1102      $row->store();
1103      $row->checkin();
1104  
1105      $msg = T_('Successfully Reset Hit count');
1106      mosRedirect( 'index2.php?option=com_content&sectionid='. $redirect .'&task=edit&hidemainmenu=1&id='. $id, $msg );
1107  }
1108  
1109  /**
1110  * @param integer The id of the content item
1111  * @param integer The new access level
1112  * @param string The URL option
1113  */
1114  function accessMenu( $uid, $access, $option ) {
1115      global $database;
1116  
1117      $row = new mosContent( $database );
1118      $row->load( $uid );
1119      $row->access = $access;
1120  
1121      if ( !$row->check() ) {
1122          return $row->getError();
1123      }
1124      if ( !$row->store() ) {
1125          return $row->getError();
1126      }
1127  
1128      $redirect = mosGetParam( $_POST, 'redirect', $row->sectionid );
1129  
1130      mosRedirect( 'index2.php?option='. $option .'&sectionid='. $redirect );
1131  }
1132  
1133  function filterCategory( $query, $active=NULL ) {
1134      global $database;
1135  
1136      $categories[] = mosHTML::makeOption( '0', T_('- All Categories -') );
1137      $database->setQuery( $query );
1138      if (is_array($database->loadObjectList())) {
1139        $categories = array_merge( $categories, $database->loadObjectList() );
1140      }
1141      $category = mosHTML::selectList( $categories, 'catid', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', $active );
1142  
1143      return $category;
1144  }
1145  
1146  function menuLink( $redirect, $id ) {
1147      global $database;
1148  
1149      $menu = mosGetParam( $_POST, 'menuselect', '' );
1150      $link = mosGetParam( $_POST, 'link_name', '' );
1151  
1152      $row = new mosMenu( $database );
1153      $row->menutype         = $menu;
1154      $row->name             = $link;
1155      $row->type             = 'content_item_link';
1156      $row->published        = 1;
1157      $row->componentid    = $id;
1158      $row->link            = 'index.php?option=com_content&task=view&id='. $id;
1159      $row->ordering        = 9999;
1160  
1161      if (!$row->check()) {
1162          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
1163          exit();
1164      }
1165      if (!$row->store()) {
1166          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
1167          exit();
1168      }
1169      $row->checkin();
1170      $row->updateOrder( "menutype='$row->menutype' AND parent='$row->parent'" );
1171  
1172      $msg =  sprintf(T_('%s (Link - Static Content) in menu: %s successfully created'),$link, $menu);
1173      mosRedirect( 'index2.php?option=com_content&sectionid='. $redirect .'&task=edit&hidemainmenu=1&id='. $id, $msg );
1174  }
1175  
1176  function go2menu() {
1177      $menu = mosGetParam( $_POST, 'menu', 'mainmenu' );
1178  
1179      mosRedirect( 'index2.php?option=com_menus&menutype='. $menu );
1180  }
1181  
1182  function go2menuitem() {
1183      $menu     = mosGetParam( $_POST, 'menu', 'mainmenu' );
1184      $id        = mosGetParam( $_POST, 'menuid', 0 );
1185  
1186      mosRedirect( 'index2.php?option=com_menus&menutype='. $menu .'&task=edit&hidemainmenu=1&id='. $id );
1187  }
1188  
1189  function saveOrder( &$cid ) {
1190      global $database;
1191      $order         = mosGetParam( $_POST, 'order', array(0) );
1192      $redirect     = mosGetParam( $_POST, 'redirect', 0 );
1193      $rettask    = mosGetParam( $_POST, 'returntask', '' );
1194      $row        = new mosContent( $database );
1195      $categories = array();
1196      // update ordering values
1197      foreach ($cid as $i=>$ciditem) {
1198          $row->load( $ciditem );
1199          if ($row->ordering != $order[$i]) {
1200              $row->ordering = $order[$i];
1201              if (!$row->store()) {
1202                  echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
1203                  exit();
1204              }
1205              // remember to updateOrder this group
1206              $categories[$row->catid] = $row->id;
1207          }
1208      }
1209      // execute updateOrder for each group
1210      foreach ($categories as $catid=>$rowid) {
1211          $row->updateOrder("catid = $catid AND state >= 0");
1212      } // foreach
1213  
1214      $msg     = T_('New ordering saved');
1215      switch ( $rettask ) {
1216          case 'showarchive':
1217              mosRedirect( 'index2.php?option=com_content&task=showarchive&sectionid='. $redirect, $msg );
1218              break;
1219  
1220          default:
1221              mosRedirect( 'index2.php?option=com_content&sectionid='. $redirect, $msg );
1222              break;
1223      } // switch
1224  } // saveOrder
1225  ?>