[ Index ]

PHP Cross Reference of Mambo 4.6.5

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

title

Body

[close]

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