[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

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


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