[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

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

   1  <?php
   2  /**
   3  * @version        $Id: admin.sections.php 19343 2010-11-03 18:12:02Z ian $
   4  * @package        Joomla
   5  * @subpackage    Sections
   6  * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7  * @license        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( '_JEXEC' ) or die( 'Restricted access' );
  17  
  18  require_once( JApplicationHelper::getPath( 'admin_html' ) );
  19  
  20  // get parameters from the URL or submitted form
  21  $scope         = JRequest::getCmd( 'scope' );
  22  $cid         = JRequest::getVar( 'cid', array(0), '', 'array' );
  23  JArrayHelper::toInteger($cid, array(0));
  24  
  25  $task = JRequest::getCmd('task');
  26  
  27  switch ($task)
  28  {
  29      case 'add' :
  30          editSection(false );
  31          break;
  32  
  33      case 'edit':
  34          editSection(true );
  35          break;
  36  
  37      case 'go2menu':
  38      case 'go2menuitem':
  39      case 'save':
  40      case 'apply':
  41          saveSection( $option, $scope, $task );
  42          break;
  43  
  44      case 'remove':
  45          removeSections( $cid, $scope, $option );
  46          break;
  47  
  48      case 'copyselect':
  49          copySectionSelect( $option, $cid, $scope );
  50          break;
  51  
  52      case 'copysave':
  53          copySectionSave( $cid, $scope );
  54          break;
  55  
  56      case 'publish':
  57          publishSections( $scope, $cid, 1, $option );
  58          break;
  59  
  60      case 'unpublish':
  61          publishSections( $scope, $cid, 0, $option );
  62          break;
  63  
  64      case 'cancel':
  65          cancelSection( $option, $scope );
  66          break;
  67  
  68      case 'orderup':
  69          orderSection( $cid[0], -1, $option, $scope );
  70          break;
  71  
  72      case 'orderdown':
  73          orderSection( $cid[0], 1, $option, $scope );
  74          break;
  75  
  76      case 'accesspublic':
  77          accessMenu( $cid[0], 0, $option );
  78          break;
  79  
  80      case 'accessregistered':
  81          accessMenu( $cid[0], 1, $option );
  82          break;
  83  
  84      case 'accessspecial':
  85          accessMenu( $cid[0], 2, $option );
  86          break;
  87  
  88      case 'saveorder':
  89          saveOrder( $cid );
  90          break;
  91  
  92      default:
  93          showSections( $scope, $option );
  94          break;
  95  }
  96  
  97  /**
  98  * Compiles a list of categories for a section
  99  * @param database A database connector object
 100  * @param string The name of the category section
 101  * @param string The name of the current user
 102  */
 103  function showSections( $scope, $option )
 104  {
 105      global $mainframe;
 106  
 107      $db                    =& JFactory::getDBO();
 108      $user                =& JFactory::getUser();
 109      $filter_order        = $mainframe->getUserStateFromRequest( $option.'.filter_order',        'filter_order',        's.ordering',    'cmd' );
 110      $filter_order_Dir    = $mainframe->getUserStateFromRequest( $option.'.filter_order_Dir',    'filter_order_Dir',    '',                'word' );
 111      $filter_state        = $mainframe->getUserStateFromRequest( $option.'.filter_state',        'filter_state',        '',                'word' );
 112      $search                = $mainframe->getUserStateFromRequest( $option.'.search',            'search',            '',                'string' );
 113      if (strpos($search, '"') !== false) {
 114          $search = str_replace(array('=', '<'), '', $search);
 115      }
 116      $search = JString::strtolower($search);
 117  
 118      $limit        = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
 119      $limitstart    = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
 120  
 121      $where[] = 's.scope = '.$db->Quote($scope);
 122  
 123      if ( $filter_state ) {
 124          if ( $filter_state == 'P' ) {
 125              $where[] = 's.published = 1';
 126          } else if ($filter_state == 'U' ) {
 127              $where[] = 's.published = 0';
 128          }
 129      }
 130      if ($search) {
 131          $where[] = 'LOWER(s.title) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
 132      }
 133  
 134      $where         = ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' );
 135  
 136      // ensure filter_order has a valid value
 137      if (!in_array($filter_order, array('s.title', 's.published', 's.ordering', 'groupname', 's.id'))) {
 138          $filter_order = 's.ordering';
 139      }
 140  
 141      if (!in_array(strtoupper($filter_order_Dir), array('ASC', 'DESC'))) {
 142          $filter_order_Dir = '';
 143      }
 144  
 145      $orderby     = ' ORDER BY '.$filter_order.' '. $filter_order_Dir .', s.ordering';
 146  
 147      // get the total number of records
 148      $query = 'SELECT COUNT(*)'
 149      . ' FROM #__sections AS s'
 150      . $where
 151      ;
 152      $db->setQuery( $query );
 153      $total = $db->loadResult();
 154  
 155      jimport('joomla.html.pagination');
 156      $pageNav = new JPagination( $total, $limitstart, $limit );
 157  
 158      $query = 'SELECT s.*, g.name AS groupname, u.name AS editor'
 159      . ' FROM #__sections AS s'
 160      . ' LEFT JOIN #__content AS cc ON s.id = cc.sectionid'
 161      . ' LEFT JOIN #__users AS u ON u.id = s.checked_out'
 162      . ' LEFT JOIN #__groups AS g ON g.id = s.access'
 163      . $where
 164      . ' GROUP BY s.id'
 165      . $orderby
 166      ;
 167      $db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
 168      $rows = $db->loadObjectList();
 169      if ($db->getErrorNum()) {
 170          echo $db->stderr();
 171          return false;
 172      }
 173  
 174      $count = count( $rows );
 175      // number of Active Categories
 176      for ( $i = 0; $i < $count; $i++ ) {
 177          $query = 'SELECT COUNT( a.id )'
 178          . ' FROM #__categories AS a'
 179          . ' WHERE a.section = '.$db->Quote($rows[$i]->id)
 180          . ' AND a.published <> -2'
 181          ;
 182          $db->setQuery( $query );
 183          $active = $db->loadResult();
 184          $rows[$i]->categories = $active;
 185      }
 186      // number of Active Items
 187      for ( $i = 0; $i < $count; $i++ ) {
 188          $query = 'SELECT COUNT( a.id )'
 189          . ' FROM #__content AS a'
 190          . ' WHERE a.sectionid = '.(int) $rows[$i]->id
 191          . ' AND a.state <> -2'
 192          ;
 193          $db->setQuery( $query );
 194          $active = $db->loadResult();
 195          $rows[$i]->active = $active;
 196      }
 197      // number of Trashed Items
 198      for ( $i = 0; $i < $count; $i++ ) {
 199          $query = 'SELECT COUNT( a.id )'
 200          . ' FROM #__content AS a'
 201          . ' WHERE a.sectionid = '.(int) $rows[$i]->id
 202          . ' AND a.state = -2'
 203          ;
 204          $db->setQuery( $query );
 205          $trash = $db->loadResult();
 206          $rows[$i]->trash = $trash;
 207      }
 208  
 209      // state filter
 210      $lists['state']    = JHTML::_('grid.state',  $filter_state );
 211  
 212      // table ordering
 213      $lists['order_Dir']    = $filter_order_Dir;
 214      $lists['order']        = $filter_order;
 215  
 216      // search filter
 217      $lists['search']= $search;
 218  
 219      sections_html::show( $rows, $scope, $user->get('id'), $pageNav, $option, $lists );
 220  }
 221  
 222  /**
 223  * Compiles information to add or edit a section
 224  * @param database A database connector object
 225  * @param string The name of the category section
 226  * @param integer The unique id of the category to edit (0 if new)
 227  * @param string The name of the current user
 228  */
 229  function editSection( $edit)
 230  {
 231      global $mainframe;
 232  
 233      $db            =& JFactory::getDBO();
 234      $user         =& JFactory::getUser();
 235  
 236      $option        = JRequest::getCmd( 'option');
 237      $scope        = JRequest::getCmd( 'scope' );
 238      $cid        = JRequest::getVar( 'cid', array(0), '', 'array' );
 239      JArrayHelper::toInteger($cid, array(0));
 240  
 241      $row =& JTable::getInstance('section');
 242      // load the row from the db table
 243      if ($edit)
 244          $row->load( $cid[0] );
 245  
 246      // fail if checked out not by 'me'
 247      if ($row->isCheckedOut( $user->get('id') )) {
 248          $msg = JText::sprintf( 'DESCBEINGEDITTED', JText::_( 'The section' ), $row->title );
 249          $mainframe->redirect( 'index.php?option='. $option .'&scope='. $row->scope, $msg );
 250      }
 251  
 252      if ( $edit ) {
 253          $row->checkout( $user->get('id') );
 254      } else {
 255          $row->scope         = $scope;
 256          $row->published     = 1;
 257      }
 258  
 259      // build the html select list for ordering
 260      $query = 'SELECT ordering AS value, title AS text'
 261      . ' FROM #__sections'
 262      . ' WHERE scope='.$db->Quote($row->scope).' ORDER BY ordering'
 263      ;
 264      if($edit)
 265          $lists['ordering']             = JHTML::_('list.specificordering',  $row, $cid[0], $query );
 266      else
 267          $lists['ordering']             = JHTML::_('list.specificordering',  $row, '', $query );
 268      // build the select list for the image positions
 269      $active =  ( $row->image_position ? $row->image_position : 'left' );
 270      $lists['image_position']     = JHTML::_('list.positions',  'image_position', $active, NULL, 0 );
 271      // build the html select list for images
 272      $lists['image']             = JHTML::_('list.images',  'image', $row->image );
 273      // build the html select list for the group access
 274      $lists['access']             = JHTML::_('list.accesslevel',  $row );
 275      // build the html radio buttons for published
 276      $lists['published']         = JHTML::_('select.booleanlist',  'published', 'class="inputbox"', $row->published );
 277  
 278      sections_html::edit( $row, $option, $lists );
 279  }
 280  
 281  /**
 282  * Saves the catefory after an edit form submit
 283  * @param database A database connector object
 284  * @param string The name of the category section
 285  */
 286  function saveSection( $option, $scope, $task )
 287  {
 288      global $mainframe;
 289  
 290      require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_content'.DS.'helper.php');
 291  
 292      // Check for request forgeries
 293      JRequest::checkToken() or jexit( 'Invalid Token' );
 294  
 295      $db            =& JFactory::getDBO();
 296      $menu        = JRequest::getVar( 'menu', 'mainmenu', 'post', 'menutype' );
 297      $menuid        = JRequest::getVar( 'menuid', 0, 'post', 'int' );
 298      $oldtitle    = JRequest::getVar( 'oldtitle', '', '', 'post', 'string' );
 299  
 300      $post = JRequest::get('post');
 301  
 302      // fix up special html fields
 303      $post['description'] = ContentHelper::filterText(JRequest::getVar( 'description', '', 'post', 'string', JREQUEST_ALLOWRAW ));
 304  
 305      $row =& JTable::getInstance('section');
 306      if (!$row->bind($post)) {
 307          JError::raiseError(500, $row->getError() );
 308      }
 309      if (!$row->check()) {
 310          JError::raiseError(500, $row->getError() );
 311      }
 312      if ( $oldtitle ) {
 313          if ( $oldtitle != $row->title ) {
 314              $query = 'UPDATE #__menu'
 315              . ' SET name = '.$db->Quote($row->title)
 316              . ' WHERE name = '.$db->Quote($oldtitle)
 317              . ' AND type = "content_section"'
 318              ;
 319              $db->setQuery( $query );
 320              $db->query();
 321          }
 322      }
 323  
 324      // if new item order last in appropriate group
 325      if (!$row->id) {
 326          $row->ordering = $row->getNextOrder();
 327      }
 328  
 329      if (!$row->store()) {
 330          JError::raiseError(500, $row->getError() );
 331      }
 332      $row->checkin();
 333  
 334      switch ( $task )
 335      {
 336          case 'go2menu':
 337              $mainframe->redirect( 
 338                  'index.php?option=com_menus&menutype=' . $menu 
 339              );
 340              break;
 341  
 342          case 'go2menuitem':
 343              $mainframe->redirect( 
 344                  'index.php?option=com_menus&menutype=' . $menu
 345                  . '&task=edit&id=' . $menuid 
 346              );
 347              break;
 348  
 349          case 'apply':
 350              $msg = JText::_( 'Changes to Section saved' );
 351              $mainframe->redirect( 'index.php?option='. $option .'&scope='. $scope .'&task=edit&cid[]='. $row->id, $msg );
 352              break;
 353  
 354          case 'save':
 355          default:
 356              $msg = JText::_( 'Section saved' );
 357              $mainframe->redirect( 'index.php?option='. $option .'&scope='. $scope, $msg );
 358              break;
 359      }
 360  }
 361  /**
 362  * Deletes one or more categories from the categories table
 363  * @param database A database connector object
 364  * @param string The name of the category section
 365  * @param array An array of unique category id numbers
 366  */
 367  function removeSections( $cid, $scope, $option )
 368  {
 369      global $mainframe;
 370  
 371      // Check for request forgeries
 372      JRequest::checkToken() or jexit( 'Invalid Token' );
 373  
 374      $db =& JFactory::getDBO();
 375      if (count( $cid ) < 1) {
 376          JError::raiseError(500, JText::_( 'Select a section to delete', true ) );
 377      }
 378  
 379      JArrayHelper::toInteger( $cid );
 380      $cids = implode( ',', $cid );
 381  
 382      $query = 'SELECT s.id, s.title, COUNT(c.id) AS numcat'
 383      . ' FROM #__sections AS s'
 384      . ' LEFT JOIN #__categories AS c ON c.section=s.id'
 385      . ' WHERE s.id IN ( '.$cids.' )'
 386      . ' GROUP BY s.id'
 387      ;
 388      $db->setQuery( $query );
 389      if (!($rows = $db->loadObjectList())) {
 390          echo "<script> alert('".$db->getErrorMsg(true)."'); window.history.go(-1); </script>\n";
 391      }
 392  
 393      $name = array();
 394      $err = array();
 395      $cid = array();
 396      foreach ($rows as $row) {
 397          if ($row->numcat == 0) {
 398              $cid[]    = (int) $row->id;
 399              $name[]    = $row->title;
 400          } else {
 401              $err[]    = $row->title;
 402          }
 403      }
 404  
 405      if (count( $cid ))
 406      {
 407          $cids = implode( ',', $cid );
 408          $query = 'DELETE FROM #__sections'
 409          . ' WHERE id IN ( '.$cids.' )'
 410          ;
 411          $db->setQuery( $query );
 412          if (!$db->query()) {
 413              echo "<script> alert('".$db->getErrorMsg(true)."'); window.history.go(-1); </script>\n";
 414          }
 415      }
 416  
 417      if (count( $err ))
 418      {
 419          $cids = implode( ', ', $err );
 420          $msg = JText::sprintf( 'DESCCANNOTBEREMOVED', $cids );
 421          $mainframe->redirect( 'index.php?option='. $option .'&scope='. $scope, $msg );
 422      }
 423  
 424      $names = implode( ', ', $name );
 425      $msg = JText::sprintf( 'Sections successfully deleted', $names );
 426      $mainframe->redirect( 'index.php?option='. $option .'&scope='. $scope, $msg );
 427  }
 428  
 429  /**
 430  * Publishes or Unpublishes one or more categories
 431  * @param database A database connector object
 432  * @param string The name of the category section
 433  * @param integer A unique category id (passed from an edit form)
 434  * @param array An array of unique category id numbers
 435  * @param integer 0 if unpublishing, 1 if publishing
 436  * @param string The name of the current user
 437  */
 438  function publishSections( $scope, $cid=null, $publish=1, $option )
 439  {
 440      global $mainframe;
 441  
 442      // Check for request forgeries
 443      JRequest::checkToken() or jexit( 'Invalid Token' );
 444  
 445      $db     =& JFactory::getDBO();
 446      $user     =& JFactory::getUser();
 447  
 448      JArrayHelper::toInteger($cid);
 449  
 450      if ( count( $cid ) < 1 ) {
 451          $action = $publish ? 'publish' : 'unpublish';
 452          JError::raiseError(500, JText::_( 'Select a section to '.$action, true ) );
 453      }
 454  
 455      $cids = implode( ',', $cid );
 456      $count = count( $cid );
 457      $query = 'UPDATE #__sections'
 458      . ' SET published = '.(int) $publish
 459      . ' WHERE id IN ( '.$cids.' )'
 460      . ' AND ( checked_out = 0 OR ( checked_out = '.(int) $user->get('id').' ) )'
 461      ;
 462      $db->setQuery( $query );
 463      if (!$db->query()) {
 464          JError::raiseError(500, $db->getErrorMsg() );
 465      }
 466  
 467      if ( $count == 1 ) {
 468          $row =& JTable::getInstance('section');
 469          $row->checkin( $cid[0] );
 470      }
 471  
 472      // check if section linked to menu items if unpublishing
 473      if ( $publish == 0 ) {
 474          $query = 'SELECT id'
 475          . ' FROM #__menu'
 476          . ' WHERE type = "content_section"'
 477          . ' AND componentid IN ( '.$cids.' )'
 478          ;
 479          $db->setQuery( $query );
 480          $menus = $db->loadObjectList();
 481  
 482          if ($menus) {
 483              foreach ($menus as $menu) {
 484                  $query = 'UPDATE #__menu'
 485                  . ' SET published = '.(int) $publish
 486                  . ' WHERE id = '.(int) $menu->id
 487                  ;
 488                  $db->setQuery( $query );
 489                  $db->query();
 490              }
 491          }
 492      }
 493  
 494      $mainframe->redirect( 'index.php?option='. $option .'&scope='. $scope );
 495  }
 496  
 497  /**
 498  * Cancels an edit operation
 499  * @param database A database connector object
 500  * @param string The name of the category section
 501  * @param integer A unique category id
 502  */
 503  function cancelSection( $option, $scope )
 504  {
 505      global $mainframe;
 506  
 507      // Check for request forgeries
 508      JRequest::checkToken() or jexit( 'Invalid Token' );
 509  
 510      $db =& JFactory::getDBO();
 511      $row =& JTable::getInstance('section');
 512      $row->bind(JRequest::get('post'));
 513      $row->checkin();
 514  
 515      $mainframe->redirect( 'index.php?option='. $option .'&scope='. $scope );
 516  }
 517  
 518  /**
 519  * Moves the order of a record
 520  * @param integer The increment to reorder by
 521  */
 522  function orderSection( $uid, $inc, $option, $scope )
 523  {
 524      global $mainframe;
 525  
 526      // Check for request forgeries
 527      JRequest::checkToken() or jexit( 'Invalid Token' );
 528  
 529      $db =& JFactory::getDBO();
 530      $row =& JTable::getInstance('section');
 531      $row->load( $uid );
 532      $row->move( $inc, 'scope = '.$db->Quote($row->scope) );
 533  
 534      $mainframe->redirect( 'index.php?option='. $option .'&scope='. $scope );
 535  }
 536  
 537  /**
 538  * Form for copying item(s) to a specific menu
 539  */
 540  function copySectionSelect( $option, $cid, $section )
 541  {
 542      global $mainframe;
 543  
 544      // Check for request forgeries
 545      JRequest::checkToken() or jexit( 'Invalid Token' );
 546  
 547      $db =& JFactory::getDBO();
 548  
 549      JArrayHelper::toInteger($cid);
 550  
 551      if ( count( $cid ) < 1) {
 552          JError::raiseError(500, JText::_( 'Select an item to move', true ) );
 553      }
 554  
 555      ## query to list selected categories
 556      $cids = implode( ',', $cid );
 557      $query = 'SELECT a.title, a.id'
 558      . ' FROM #__categories AS a'
 559      . ' WHERE a.section IN ( '.$cids.' )'
 560      ;
 561      $db->setQuery( $query );
 562      $categories = $db->loadObjectList();
 563  
 564      ## query to list items from categories
 565      $query = 'SELECT a.title, a.id'
 566      . ' FROM #__content AS a'
 567      . ' WHERE a.sectionid IN ( '.$cids.' )'
 568      . ' ORDER BY a.sectionid, a.catid, a.title'
 569      ;
 570      $db->setQuery( $query );
 571      $contents = $db->loadObjectList();
 572  
 573      sections_html::copySectionSelect( $option, $cid, $categories, $contents, $section );
 574  }
 575  
 576  
 577  /**
 578  * Save the item(s) to the menu selected
 579  */
 580  function copySectionSave( $sectionid, $scope )
 581  {
 582      global $mainframe;
 583  
 584      // Check for request forgeries
 585      JRequest::checkToken() or jexit( 'Invalid Token' );
 586  
 587      $db            =& JFactory::getDBO();
 588      $title        = JRequest::getString( 'title' );
 589      $contentid    = JRequest::getVar( 'content' );
 590      $categoryid = JRequest::getVar( 'category' );
 591      JArrayHelper::toInteger($contentid);
 592      JArrayHelper::toInteger($categoryid);
 593  
 594      // copy section
 595      $section =& JTable::getInstance('section');
 596      foreach( $sectionid as $id ) {
 597          $section->load( $id );
 598          $section->id     = NULL;
 599          $section->title = $title;
 600          $section->name     = $title;
 601          if ( !$section->check() ) {
 602              copySectionSelect('com_sections', $sectionid, $scope );
 603              JError::raiseWarning(500, $section->getError() );
 604              return;
 605          }
 606  
 607          if ( !$section->store() ) {
 608              JError::raiseError(500, $section->getError() );
 609          }
 610          $section->checkin();
 611          $section->reorder( 'scope = '.$db->Quote($section->scope) );
 612          // stores original catid
 613          $newsectids[]["old"] = $id;
 614          // pulls new catid
 615          $newsectids[]["new"] = $section->id;
 616      }
 617      $sectionMove = $section->id;
 618  
 619      // copy categories
 620      $category =& JTable::getInstance('category');
 621      foreach( $categoryid as $id ) {
 622          $category->load( $id );
 623          $category->id = NULL;
 624          $category->section = $sectionMove;
 625          foreach( $newsectids as $newsectid ) {
 626              if ( $category->section == $newsectid["old"] ) {
 627                  $category->section = $newsectid["new"];
 628              }
 629          }
 630          if (!$category->check()) {
 631              JError::raiseError(500, $category->getError() );
 632          }
 633  
 634          if (!$category->store()) {
 635              JError::raiseError(500, $category->getError() );
 636          }
 637          $category->checkin();
 638          $category->reorder( 'section = '.$db->Quote($category->section) );
 639          // stores original catid
 640          $newcatids[]["old"] = $id;
 641          // pulls new catid
 642          $newcatids[]["new"] = $category->id;
 643      }
 644  
 645      $content =& JTable::getInstance('content');
 646      foreach( $contentid as $id) {
 647          $content->load( $id );
 648          $content->id = NULL;
 649          $content->hits = 0;
 650          foreach( $newsectids as $newsectid ) {
 651              if ( $content->sectionid == $newsectid["old"] ) {
 652                  $content->sectionid = $newsectid["new"];
 653              }
 654          }
 655          foreach( $newcatids as $newcatid ) {
 656              if ( $content->catid == $newcatid["old"] ) {
 657                  $content->catid = $newcatid["new"];
 658              }
 659          }
 660          if (!$content->check()) {
 661              JError::raiseError(500, $content->getError() );
 662          }
 663  
 664          if (!$content->store()) {
 665              JError::raiseError(500, $content->getError() );
 666          }
 667          $content->checkin();
 668      }
 669      $sectionOld =& JTable::getInstance('section');
 670      $sectionOld->load( $sectionMove );
 671  
 672      $msg = JText::sprintf( 'DESCCATANDITEMSCOPIED', $sectionOld-> name, $title );
 673      $mainframe->redirect( 'index.php?option=com_sections&scope=content', $msg );
 674  }
 675  
 676  /**
 677  * changes the access level of a record
 678  * @param integer The increment to reorder by
 679  */
 680  function accessMenu( $uid, $access, $option )
 681  {
 682      global $mainframe;
 683  
 684      // Check for request forgeries
 685      JRequest::checkToken() or jexit( 'Invalid Token' );
 686  
 687      $db    =& JFactory::getDBO();
 688      $row =& JTable::getInstance('section');
 689      $row->load( $uid );
 690      $row->access = $access;
 691  
 692      if ( !$row->check() ) {
 693          return $row->getError();
 694      }
 695      if ( !$row->store() ) {
 696          return $row->getError();
 697      }
 698  
 699      $mainframe->redirect( 'index.php?option='. $option .'&scope='. $row->scope );
 700  }
 701  
 702  function saveOrder( &$cid )
 703  {
 704      global $mainframe;
 705  
 706      // Check for request forgeries
 707      JRequest::checkToken() or jexit( 'Invalid Token' );
 708  
 709      $db            =& JFactory::getDBO();
 710      $row        =& JTable::getInstance('section');
 711  
 712      $total        = count( $cid );
 713      $order        = JRequest::getVar( 'order', array(0), 'post', 'array' );
 714      JArrayHelper::toInteger($order, array(0));
 715  
 716      // update ordering values
 717      for( $i=0; $i < $total; $i++ )
 718      {
 719          $row->load( (int) $cid[$i] );
 720          if ($row->ordering != $order[$i]) {
 721              $row->ordering = $order[$i];
 722              if (!$row->store()) {
 723                  JError::raiseError(500, $db->getErrorMsg() );
 724              }
 725          }
 726      }
 727  
 728      $row->reorder( );
 729  
 730      $msg     = JText::_( 'New ordering saved' );
 731      $mainframe->redirect( 'index.php?option=com_sections&scope=content', $msg );
 732  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1