[ Indice ]

Riferimento incrociato di Joomla! 1.5.14 - VM 1.1.4

Servizio fornito da VMItalia
Classe:   Funzione:   Variabile:   Costante:  
Storico Ricerche +

titolo

Corpo

[chiudi]

/administrator/components/com_categories/ -> admin.categories.php (sorgente)

   1  <?php
   2  /**
   3   * @version        $Id: admin.categories.php 11633 2009-02-19 23:59:09Z willebil $
   4   * @package        Joomla
   5   * @subpackage    Categories
   6   * @copyright    Copyright (C) 2005 - 2008 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  $section     = JRequest::getCmd( 'section', 'com_content' );
  22  $cid         = JRequest::getVar( 'cid', array(0), '', 'array' );
  23  JArrayHelper::toInteger($cid, array(0));
  24  
  25  switch (JRequest::getCmd('task'))
  26  {
  27      case 'add' :
  28          editCategory(false);
  29          break;
  30  
  31      case 'edit':
  32          editCategory(true);
  33          break;
  34  
  35      case 'moveselect':
  36          moveCategorySelect( $option, $cid, $section );
  37          break;
  38  
  39      case 'movesave':
  40          moveCategorySave( $cid, $section );
  41          break;
  42  
  43      case 'copyselect':
  44          copyCategorySelect( $option, $cid, $section );
  45          break;
  46  
  47      case 'copysave':
  48          copyCategorySave( $cid, $section );
  49          break;
  50  
  51      case 'go2menu':
  52      case 'go2menuitem':
  53      case 'save':
  54      case 'apply':
  55          saveCategory( );
  56          break;
  57  
  58      case 'remove':
  59          removeCategories( $section, $cid );
  60          break;
  61  
  62      case 'publish':
  63          publishCategories( $section, $cid, 1 );
  64          break;
  65  
  66      case 'unpublish':
  67          publishCategories( $section, $cid, 0 );
  68          break;
  69  
  70      case 'cancel':
  71          cancelCategory();
  72          break;
  73  
  74      case 'orderup':
  75          orderCategory( $cid[0], -1 );
  76          break;
  77  
  78      case 'orderdown':
  79          orderCategory( $cid[0], 1 );
  80          break;
  81  
  82      case 'accesspublic':
  83          accessMenu( $cid[0], 0, $section );
  84          break;
  85  
  86      case 'accessregistered':
  87          accessMenu( $cid[0], 1, $section );
  88          break;
  89  
  90      case 'accessspecial':
  91          accessMenu( $cid[0], 2, $section );
  92          break;
  93  
  94      case 'saveorder':
  95          saveOrder( $cid, $section );
  96          break;
  97  
  98      default:
  99          showCategories( $section, $option );
 100          break;
 101  }
 102  
 103  /**
 104  * Compiles a list of categories for a section
 105  * @param string The name of the category section
 106  */
 107  function showCategories( $section, $option )
 108  {
 109      global $mainframe;
 110  
 111      $db                    =& JFactory::getDBO();
 112      $filter_order        = $mainframe->getUserStateFromRequest( $option.'.filter_order',                    'filter_order',        'c.ordering',    'cmd' );
 113      $filter_order_Dir    = $mainframe->getUserStateFromRequest( $option.'.filter_order_Dir',                'filter_order_Dir',    '',                'word' );
 114      $filter_state        = $mainframe->getUserStateFromRequest( $option.'.'.$section.'.filter_state',    'filter_state',        '',                'word' );
 115      $sectionid            = $mainframe->getUserStateFromRequest( $option.'.'.$section.'.sectionid',        'sectionid',        0,                'int' );
 116      $search                = $mainframe->getUserStateFromRequest( $option.'.search',                        'search',            '',                'string' );
 117      $search                = JString::strtolower( $search );
 118  
 119      $limit        = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
 120      $limitstart    = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
 121  
 122      $section_name     = '';
 123      $content_add     = '';
 124      $content_join     = '';
 125      $order             = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', c.ordering';
 126      if (intval( $section ) > 0) {
 127          $table = 'content';
 128  
 129          $query = 'SELECT title'
 130          . ' FROM #__sections'
 131          . ' WHERE id = '.(int) $section;
 132          $db->setQuery( $query );
 133          $section_name = $db->loadResult();
 134          $section_name = JText::sprintf( 'Content:', JText::_( $section_name ) );
 135          $where     = ' WHERE c.section = '.$db->Quote($section);
 136          $type     = 'content';
 137      } else if (strpos( $section, 'com_' ) === 0) {
 138          $table = substr( $section, 4 );
 139  
 140          $query = 'SELECT name'
 141          . ' FROM #__components'
 142          . ' WHERE link = '.$db->Quote('option='.$section);
 143          ;
 144          $db->setQuery( $query );
 145          $section_name = $db->loadResult();
 146          $where     = ' WHERE c.section = '.$db->Quote($section);
 147          $type     = 'other';
 148          // special handling for contact component
 149          if ( $section == 'com_contact_details' ) {
 150              $section_name     = JText::_( 'Contact' );
 151          }
 152          $section_name = JText::sprintf( 'Component:', $section_name );
 153      } else {
 154          $table     = $section;
 155          $where     = ' WHERE c.section = '.$db->Quote($section);
 156          $type     = 'other';
 157      }
 158  
 159      // get the total number of records
 160      $query = 'SELECT COUNT(*)'
 161      . ' FROM #__categories'
 162      ;
 163      if ($section == 'com_content')
 164      {
 165          if($sectionid > 0)
 166          {
 167              $query .= ' WHERE section = '.(int) $sectionid;
 168          } else {
 169              $query .= ' WHERE section > 0';
 170          }
 171      } else {
 172          $query .= ' WHERE section = '.$db->quote($section);
 173      }
 174      if ( $filter_state ) {
 175          if ( $filter_state == 'P' ) {
 176              $query .= ' AND published = 1';
 177          } else if ($filter_state == 'U' ) {
 178              $query .= ' AND published = 0';
 179          }
 180      }
 181      $db->setQuery( $query );
 182      $total = $db->loadResult();
 183  
 184      // allows for viweing of all content categories
 185      if ( $section == 'com_content' ) {
 186          $table             = 'content';
 187          $content_add     = ' , z.title AS section_name';
 188          $content_join     = ' LEFT JOIN #__sections AS z ON z.id = c.section';
 189          $where             = ' WHERE c.section NOT LIKE "%com_%"';
 190          if ($filter_order == 'c.ordering'){
 191              $order             = ' ORDER BY  z.title, c.ordering '. $filter_order_Dir;
 192          } else {
 193              $order             = ' ORDER BY  '.$filter_order.' '. $filter_order_Dir.', z.title, c.ordering';
 194          }
 195  
 196          $section_name     = JText::_( 'All Content:' );
 197  
 198          $type             = 'content';
 199      }
 200  
 201      // used by filter
 202      if ( $sectionid > 0 ) {
 203          $filter = ' AND c.section = '.$db->Quote($sectionid);
 204      } else {
 205          $filter = '';
 206      }
 207      if ( $filter_state ) {
 208          if ( $filter_state == 'P' ) {
 209              $filter .= ' AND c.published = 1';
 210          } else if ($filter_state == 'U' ) {
 211              $filter .= ' AND c.published = 0';
 212          }
 213      }
 214      if ($search) {
 215          $filter .= ' AND LOWER(c.title) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
 216      }
 217  
 218      jimport('joomla.html.pagination');
 219      $pageNav = new JPagination( $total, $limitstart, $limit );
 220  
 221      $tablesAllowed = $db->getTableList();
 222      if (!in_array($db->getPrefix().$table, $tablesAllowed)) {
 223          $table = 'content';
 224      }
 225  
 226      $query = 'SELECT  c.*, c.checked_out as checked_out_contact_category, g.name AS groupname, u.name AS editor, COUNT( DISTINCT s2.checked_out ) AS checked_out_count'
 227      . $content_add
 228      . ' FROM #__categories AS c'
 229      . ' LEFT JOIN #__users AS u ON u.id = c.checked_out'
 230      . ' LEFT JOIN #__groups AS g ON g.id = c.access'
 231      . ' LEFT JOIN #__'.$table.' AS s2 ON s2.catid = c.id AND s2.checked_out > 0'
 232      . $content_join
 233      . $where
 234      . $filter
 235      . ' AND c.published != -2'
 236      . ' GROUP BY c.id'
 237      . $order
 238      ;
 239      $db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
 240      $rows = $db->loadObjectList();
 241      if ($db->getErrorNum()) {
 242          echo $db->stderr();
 243          return;
 244      }
 245  
 246      $count = count( $rows );
 247      // number of Active Items
 248      for ( $i = 0; $i < $count; $i++ ) {
 249          $query = 'SELECT COUNT( a.id )'
 250          . ' FROM #__content AS a'
 251          . ' WHERE a.catid = '. (int) $rows[$i]->id
 252          . ' AND a.state <> -2'
 253          ;
 254          $db->setQuery( $query );
 255          $active = $db->loadResult();
 256          $rows[$i]->active = $active;
 257      }
 258      // number of Trashed Items
 259      for ( $i = 0; $i < $count; $i++ ) {
 260          $query = 'SELECT COUNT( a.id )'
 261          . ' FROM #__content AS a'
 262          . ' WHERE a.catid = '. (int) $rows[$i]->id
 263          . ' AND a.state = -2'
 264          ;
 265          $db->setQuery( $query );
 266          $trash = $db->loadResult();
 267          $rows[$i]->trash = $trash;
 268      }
 269  
 270      // get list of sections for dropdown filter
 271      $javascript = 'onchange="document.adminForm.submit();"';
 272      $lists['sectionid']    = JHTML::_('list.section',  'sectionid', $sectionid, $javascript, 'ordering', false );
 273  
 274      // state filter
 275      $lists['state']    = JHTML::_('grid.state',  $filter_state );
 276  
 277      // table ordering
 278      $lists['order_Dir'] = $filter_order_Dir;
 279      $lists['order']        = $filter_order;
 280  
 281      // search filter
 282      $lists['search']= $search;
 283  
 284      categories_html::show( $rows, $section, $section_name, $pageNav, $lists, $type );
 285  }
 286  
 287  /**
 288  * Compiles information to add or edit a category
 289  * @param string The name of the category section
 290  * @param integer The unique id of the category to edit (0 if new)
 291  * @param string The name of the current user
 292  */
 293  function editCategory($edit )
 294  {
 295      global $mainframe;
 296  
 297      // Initialize variables
 298      $db            =& JFactory::getDBO();
 299      $user         =& JFactory::getUser();
 300      $uid        = $user->get('id');
 301  
 302      $type        = JRequest::getCmd( 'type' );
 303      $redirect    = JRequest::getCmd( 'section', 'com_content' );
 304      $section    = JRequest::getCmd( 'section', 'com_content' );
 305      $cid        = JRequest::getVar( 'cid', array(0), '', 'array' );
 306  
 307      JArrayHelper::toInteger($cid, array(0));
 308  
 309      // check for existance of any sections
 310      $query = 'SELECT COUNT( id )'
 311      . ' FROM #__sections'
 312      . ' WHERE scope = "content"'
 313      ;
 314      $db->setQuery( $query );
 315      $sections = $db->loadResult();
 316      if (!$sections && $type != 'other'
 317              && $section != 'com_weblinks'
 318              && $section != 'com_newsfeeds'
 319              && $section != 'com_contact_details'
 320              && $section != 'com_banner') {
 321          $mainframe->redirect( 'index.php?option=com_categories&section='. $section, JText::_( 'WARNSECTION', true ) );
 322      }
 323  
 324      $row =& JTable::getInstance('category');
 325      // load the row from the db table
 326      if ($edit)
 327          $row->load( $cid[0] );
 328  
 329      // fail if checked out not by 'me'
 330      if ( JTable::isCheckedOut($user->get ('id'), $row->checked_out )) {
 331          $msg = JText::sprintf( 'DESCBEINGEDITTED', JText::_( 'The category' ), $row->title );
 332          $mainframe->redirect( 'index.php?option=com_categories&section='. $row->section, $msg );
 333      }
 334  
 335      if ( $edit ) {
 336          $row->checkout( $user->get('id'));
 337      } else {
 338          $row->published     = 1;
 339      }
 340  
 341  
 342      // make order list
 343      $order = array();
 344      $query = 'SELECT COUNT(*)'
 345      . ' FROM #__categories'
 346      . ' WHERE section = '.$db->Quote($row->section)
 347      ;
 348      $db->setQuery( $query );
 349      $max = intval( $db->loadResult() ) + 1;
 350  
 351      for ($i=1; $i < $max; $i++) {
 352          $order[] = JHTML::_('select.option',  $i );
 353      }
 354  
 355      // build the html select list for sections
 356      if ( $section == 'com_content' ) {
 357  
 358          if (!$row->section && JRequest::getInt('sectionid')) {
 359              $row->section = JRequest::getInt('sectionid');
 360          }
 361  
 362          $query = 'SELECT s.id AS value, s.title AS text'
 363          . ' FROM #__sections AS s'
 364          . ' ORDER BY s.ordering'
 365          ;
 366          $db->setQuery( $query );
 367          $sections = $db->loadObjectList();
 368          $lists['section'] = JHTML::_('select.genericlist',   $sections, 'section', 'class="inputbox" size="1"', 'value', 'text', $row->section );
 369      } else {
 370          if ( $type == 'other' ) {
 371              $section_name = JText::_( 'N/A' );
 372          } else {
 373              $temp =& JTable::getInstance('section');
 374              $temp->load( $row->section );
 375              $section_name = $temp->name;
 376          }
 377          if(!$section_name) $section_name = JText::_( 'N/A' );
 378          $row->section = $section;
 379          $lists['section'] = '<input type="hidden" name="section" value="'. $row->section .'" />'. $section_name;
 380      }
 381  
 382      // build the html select list for ordering
 383      $query = 'SELECT ordering AS value, title AS text'
 384      . ' FROM #__categories'
 385      . ' WHERE section = '.$db->Quote($row->section)
 386      . ' ORDER BY ordering'
 387      ;
 388      if ($edit) {
 389          $lists['ordering']             = JHTML::_('list.specificordering',  $row, $cid[0], $query );
 390      }
 391      else {
 392          $lists['ordering']             = JHTML::_('list.specificordering',  $row, '', $query );
 393      }
 394      // build the select list for the image positions
 395      $active =  ( $row->image_position ? $row->image_position : 'left' );
 396      $lists['image_position']     = JHTML::_('list.positions',  'image_position', $active, NULL, 0, 0 );
 397      // Imagelist
 398      $lists['image']             = JHTML::_('list.images',  'image', $row->image );
 399      // build the html select list for the group access
 400      $lists['access']             = JHTML::_('list.accesslevel',  $row );
 401      // build the html radio buttons for published
 402      $published = ($row->id) ? $row->published : 1;
 403      $lists['published']         = JHTML::_('select.booleanlist',  'published', 'class="inputbox"', $published );
 404  
 405       categories_html::edit( $row, $lists, $redirect );
 406  }
 407  
 408  /**
 409  * Saves the catefory after an edit form submit
 410  * @param string The name of the category section
 411  */
 412  function saveCategory()
 413  {
 414      global $mainframe;
 415  
 416      // Check for request forgeries
 417      JRequest::checkToken() or jexit( 'Invalid Token' );
 418  
 419      // Initialize variables
 420      $db         =& JFactory::getDBO();
 421      $menu         = JRequest::getCmd( 'menu', 'mainmenu', 'post' );
 422      $menuid        = JRequest::getVar( 'menuid', 0, 'post', 'int' );
 423      $redirect     = JRequest::getCmd( 'redirect', '', 'post' );
 424      $oldtitle     = JRequest::getString( 'oldtitle', '', 'post' );
 425      $post        = JRequest::get( 'post' );
 426  
 427      // fix up special html fields
 428      $post['description'] = JRequest::getVar( 'description', '', 'post', 'string', JREQUEST_ALLOWRAW );
 429  
 430      $row =& JTable::getInstance('category');
 431      if (!$row->bind( $post )) {
 432          JError::raiseError(500, $row->getError() );
 433      }
 434      if (!$row->check()) {
 435          JError::raiseError(500, $row->getError() );
 436      }
 437      // if new item order last in appropriate group
 438      if (!$row->id) {
 439          $where = "section = " . $db->Quote($row->section);
 440          $row->ordering = $row->getNextOrder( $where );
 441      }
 442  
 443      if (!$row->store()) {
 444          JError::raiseError(500, $row->getError() );
 445      }
 446      $row->checkin();
 447  
 448      if ($row->section > 0) {
 449          $query = 'UPDATE #__content'
 450                  .' SET sectionid = '.$row->section
 451                  .' WHERE catid = '.$row->id
 452          ;
 453          $db->setQuery( $query );
 454          $db->query();
 455      }
 456  
 457      if ( $oldtitle ) {
 458          if ($oldtitle != $row->title) {
 459              $query = 'UPDATE #__menu'
 460              . ' SET name = '.$db->Quote($row->title)
 461              . ' WHERE name = '.$db->Quote($oldtitle)
 462              . ' AND type = "content_category"'
 463              ;
 464              $db->setQuery( $query );
 465              $db->query();
 466          }
 467      }
 468  
 469      // Update Section Count
 470      if ($row->section != 'com_contact_details' &&
 471          $row->section != 'com_newsfeeds' &&
 472          $row->section != 'com_weblinks') {
 473          $query = 'UPDATE #__sections SET count=count+1'
 474          . ' WHERE id = '.$db->Quote($row->section)
 475          ;
 476          $db->setQuery( $query );
 477      }
 478  
 479      if (!$db->query()) {
 480          JError::raiseError(500, $db->getErrorMsg() );
 481      }
 482  
 483      switch ( JRequest::getCmd('task') )
 484      {
 485          case 'go2menu':
 486              $mainframe->redirect( 'index.php?option=com_menus&menutype='. $menu );
 487              break;
 488  
 489          case 'go2menuitem':
 490              $mainframe->redirect( 'index.php?option=com_menus&menutype='. $menu .'&task=edit&id='. $menuid );
 491              break;
 492  
 493          case 'apply':
 494              $msg = JText::_( 'Changes to Category saved' );
 495              $mainframe->redirect( 'index.php?option=com_categories&section='. $redirect .'&task=edit&cid[]='. $row->id, $msg );
 496              break;
 497  
 498          case 'save':
 499          default:
 500              $msg = JText::_( 'Category saved' );
 501              $mainframe->redirect( 'index.php?option=com_categories&section='. $redirect, $msg );
 502              break;
 503      }
 504  }
 505  
 506  /**
 507  * Deletes one or more categories from the categories table
 508  * @param string The name of the category section
 509  * @param array An array of unique category id numbers
 510  */
 511  function removeCategories( $section, $cid )
 512  {
 513      global $mainframe;
 514  
 515      // Check for request forgeries
 516      JRequest::checkToken() or jexit( 'Invalid Token' );
 517  
 518      // Initialize variables
 519      $db =& JFactory::getDBO();
 520  
 521      JArrayHelper::toInteger($cid);
 522  
 523      if (count( $cid ) < 1) {
 524          JError::raiseError(500, JText::_( 'Select a category to delete', true ));
 525      }
 526  
 527      $cids = implode( ',', $cid );
 528  
 529      if (intval( $section ) > 0) {
 530          $table = 'content';
 531      } else if (strpos( $section, 'com_' ) === 0) {
 532          $table = substr( $section, 4 );
 533      } else {
 534          $table = $section;
 535      }
 536  
 537      $tablesAllowed = $db->getTableList();
 538      if (!in_array($db->getPrefix().$table, $tablesAllowed)) {
 539          $table = 'content';
 540      }
 541  
 542      $query = 'SELECT c.id, c.name, c.title, COUNT( s.catid ) AS numcat'
 543      . ' FROM #__categories AS c'
 544      . ' LEFT JOIN #__'.$table.' AS s ON s.catid = c.id'
 545      . ' WHERE c.id IN ( '.$cids.' )'
 546      . ' GROUP BY c.id'
 547      ;
 548      $db->setQuery( $query );
 549  
 550      if (!($rows = $db->loadObjectList())) {
 551          JError::raiseError( 500, $db->stderr() );
 552          return false;
 553      }
 554  
 555      $err = array();
 556      $cid = array();
 557      foreach ($rows as $row) {
 558          if ($row->numcat == 0) {
 559              $cid[] = (int) $row->id;
 560          } else {
 561              $err[] = $row->title;
 562          }
 563      }
 564  
 565      if (count( $cid )) {
 566          $cids = implode( ',', $cid );
 567          $query = 'DELETE FROM #__categories'
 568          . ' WHERE id IN ( '.$cids.' )'
 569          ;
 570          $db->setQuery( $query );
 571          if (!$db->query()) {
 572              JError::raiseError( 500, $db->stderr() );
 573              return false;
 574          }
 575      }
 576  
 577      if (count( $err )) {
 578          $cids = implode( ", ", $err );
 579          $msg = JText::sprintf( 'WARNNOTREMOVEDRECORDS', $cids );
 580          $mainframe->redirect( 'index.php?option=com_categories&section='. $section, $msg );
 581      }
 582  
 583      $mainframe->redirect( 'index.php?option=com_categories&section='. $section );
 584  }
 585  
 586  /**
 587  * Publishes or Unpublishes one or more categories
 588  * @param string The name of the category section
 589  * @param integer A unique category id (passed from an edit form)
 590  * @param array An array of unique category id numbers
 591  * @param integer 0 if unpublishing, 1 if publishing
 592  * @param string The name of the current user
 593  */
 594  function publishCategories( $section, $cid=null, $publish=1 )
 595  {
 596      global $mainframe;
 597  
 598      // Check for request forgeries
 599      JRequest::checkToken() or jexit( 'Invalid Token' );
 600  
 601      // Initialize variables
 602      $db        =& JFactory::getDBO();
 603      $user    =& JFactory::getUser();
 604      $uid    = $user->get('id');
 605  
 606      JArrayHelper::toInteger($cid);
 607  
 608      if (count( $cid ) < 1) {
 609          $action = $publish ? 'publish' : 'unpublish';
 610          JError::raiseError(500, JText::_( 'Select a category to '.$action, true ) );
 611      }
 612  
 613      $cids = implode( ',', $cid );
 614  
 615      $query = 'UPDATE #__categories'
 616      . ' SET published = ' . (int) $publish
 617      . ' WHERE id IN ( '.$cids.' )'
 618      . ' AND ( checked_out = 0 OR ( checked_out = '.(int) $uid.' ) )'
 619      ;
 620      $db->setQuery( $query );
 621      if (!$db->query()) {
 622          JError::raiseError(500, $db->getErrorMsg() );
 623      }
 624  
 625      if (count( $cid ) == 1) {
 626          $row =& JTable::getInstance('category');
 627          $row->checkin( $cid[0] );
 628      }
 629  
 630      $mainframe->redirect( 'index.php?option=com_categories&section='. $section );
 631  }
 632  
 633  /**
 634  * Cancels an edit operation
 635  * @param string The name of the category section
 636  * @param integer A unique category id
 637  */
 638  function cancelCategory()
 639  {
 640      global $mainframe;
 641  
 642      // Check for request forgeries
 643      JRequest::checkToken() or jexit( 'Invalid Token' );
 644  
 645      // Initialize variables
 646      $db =& JFactory::getDBO();
 647  
 648      $redirect = JRequest::getCmd( 'redirect', '', 'post' );
 649  
 650      $row =& JTable::getInstance('category');
 651      $row->bind( JRequest::get( 'post' ));
 652      $row->checkin();
 653  
 654      $mainframe->redirect( 'index.php?option=com_categories&section='. $redirect );
 655  }
 656  
 657  /**
 658  * Moves the order of a record
 659  * @param integer The increment to reorder by
 660  */
 661  function orderCategory( $uid, $inc )
 662  {
 663      global $mainframe;
 664  
 665      // Check for request forgeries
 666      JRequest::checkToken() or jexit( 'Invalid Token' );
 667  
 668      // Initialize variables
 669      $db        =& JFactory::getDBO();
 670      $row    =& JTable::getInstance('category' );
 671      $row->load( $uid );
 672      $row->move( $inc, 'section = '.$db->Quote($row->section) );
 673      $section = JRequest::getCmd('section');
 674      if($section) {
 675          $section = '&section='. $section;
 676      }
 677      $mainframe->redirect( 'index.php?option=com_categories'. $section );
 678  }
 679  
 680  /**
 681  * Form for moving item(s) to a specific menu
 682  */
 683  function moveCategorySelect( $option, $cid, $sectionOld )
 684  {
 685      global $mainframe;
 686  
 687      // Check for request forgeries
 688      JRequest::checkToken() or jexit( 'Invalid Token' );
 689  
 690      $db =& JFactory::getDBO();
 691      $redirect = JRequest::getCmd( 'section', 'com_content', 'post' );
 692  
 693      JArrayHelper::toInteger($cid);
 694  
 695      if (count( $cid ) < 1) {
 696          JError::raiseError(500, JText::_( 'Select an item to move', true ));
 697      }
 698  
 699      ## query to list selected categories
 700      $cids = implode( ',', $cid );
 701      $query = 'SELECT a.title, a.section'
 702      . ' FROM #__categories AS a'
 703      . ' WHERE a.id IN ( '.$cids.' )'
 704      ;
 705      $db->setQuery( $query );
 706      $items = $db->loadObjectList();
 707  
 708      ## query to list items from categories
 709      $query = 'SELECT a.title'
 710      . ' FROM #__content AS a'
 711      . ' WHERE a.catid IN ( '.$cids.' )'
 712      . ' ORDER BY a.catid, a.title'
 713      ;
 714      $db->setQuery( $query );
 715      $contents = $db->loadObjectList();
 716  
 717      ## query to choose section to move to
 718      $query = 'SELECT a.title AS text, a.id AS value'
 719      . ' FROM #__sections AS a'
 720      . ' WHERE a.published = 1'
 721      . ' ORDER BY a.title'
 722      ;
 723      $db->setQuery( $query );
 724      $sections = $db->loadObjectList();
 725  
 726      // build the html select list
 727      $SectionList = JHTML::_('select.genericlist',   $sections, 'sectionmove', 'class="inputbox" size="10"', 'value', 'text', null );
 728  
 729      categories_html::moveCategorySelect( $option, $cid, $SectionList, $items, $sectionOld, $contents, $redirect );
 730  }
 731  
 732  
 733  /**
 734  * Save the item(s) to the menu selected
 735  */
 736  function moveCategorySave( $cid, $sectionOld )
 737  {
 738      global $mainframe;
 739  
 740      // Check for request forgeries
 741      JRequest::checkToken() or jexit( 'Invalid Token' );
 742  
 743      $db =& JFactory::getDBO();
 744      $sectionMove = JRequest::getCmd( 'sectionmove' );
 745  
 746      //Check to see of a section was selected to copy the items too
 747      if (!$sectionMove)
 748      {
 749          $msg = JText::_('Please select a section from the list');
 750          moveCategorySelect( 'com_categories', $cid, $sectionOld );
 751          JError::raiseWarning(500, $msg);
 752          return;
 753      }
 754  
 755      JArrayHelper::toInteger($cid, array(0));
 756  
 757      $sectionNew =& JTable::getInstance('section');
 758      $sectionNew->load( $sectionMove );
 759  
 760      //Remove the categories was in destination section
 761      $cids = implode( ',', $cid );
 762  
 763      $query = 'SELECT id, title'
 764      . ' FROM #__categories'
 765      . ' WHERE id IN ( '.$cids.' )'
 766      . ' AND section = '.$db->Quote($sectionMove)
 767      ;
 768      $db->setQuery( $query );
 769  
 770      $scid   = $db->loadResultArray(0);
 771      $title  = $db->loadResultArray(1);
 772  
 773      $cid = array_diff($cid, $scid);
 774  
 775      //
 776      if ( !empty($cid) ) {
 777          $cids = implode( ',', $cid );
 778          $total = count( $cid );
 779  
 780          $query = 'UPDATE #__categories'
 781          . ' SET section = '.$db->Quote($sectionMove)
 782          . ' WHERE id IN ( '.$cids.' )'
 783          ;
 784          $db->setQuery( $query );
 785          if ( !$db->query() ) {
 786              JError::raiseError(500, $db->getErrorMsg() );
 787          }
 788          $query = 'UPDATE #__content'
 789          . ' SET sectionid = '.$db->Quote($sectionMove)
 790          . ' WHERE catid IN ( '.$cids.' )'
 791          ;
 792          $db->setQuery( $query );
 793          if ( !$db->query() ) {
 794              JError::raiseError(500, $db->getErrorMsg());
 795          }
 796  
 797          $msg = JText::sprintf( 'Categories moved to', $sectionNew->title );
 798          $mainframe->enqueueMessage($msg);
 799      }
 800      if ( !empty($title) && is_array($title) ) {
 801          if ( count($title) == 1 ) {
 802              $msg = JText::sprintf( 'Category already in', implode( ', ', $title ), $sectionNew->title );
 803          } else {
 804              $msg = JText::sprintf( 'Categories already in', implode( ', ', $title ), $sectionNew->title );
 805          }
 806          $mainframe->enqueueMessage($msg);
 807      }
 808  
 809      $mainframe->redirect( 'index.php?option=com_categories&section='. $sectionOld );
 810  }
 811  
 812  /**
 813  * Form for copying item(s) to a specific menu
 814  */
 815  function copyCategorySelect( $option, $cid, $sectionOld )
 816  {
 817      global $mainframe;
 818  
 819      // Check for request forgeries
 820      JRequest::checkToken() or jexit( 'Invalid Token' );
 821  
 822      $db =& JFactory::getDBO();
 823      $redirect = JRequest::getCmd( 'section', 'com_content', 'post' );
 824  
 825      JArrayHelper::toInteger($cid);
 826  
 827      if (count( $cid ) < 1) {
 828          JError::raiseError(500, JText::_( 'Select an item to move', true ));
 829      }
 830  
 831      ## query to list selected categories
 832      $cids = implode( ',', $cid );
 833      $query = 'SELECT a.title, a.section'
 834      . ' FROM #__categories AS a'
 835      . ' WHERE a.id IN ( '.$cids.' )'
 836      ;
 837      $db->setQuery( $query );
 838      $items = $db->loadObjectList();
 839  
 840      ## query to list items from categories
 841      $query = 'SELECT a.title, a.id'
 842      . ' FROM #__content AS a'
 843      . ' WHERE a.catid IN ( '.$cids.' )'
 844      . ' ORDER BY a.catid, a.title'
 845      ;
 846      $db->setQuery( $query );
 847      $contents = $db->loadObjectList();
 848  
 849      ## query to choose section to move to
 850      $query = 'SELECT a.title AS `text`, a.id AS `value`'
 851      . ' FROM #__sections AS a'
 852      . ' WHERE a.published = 1'
 853      . ' ORDER BY a.name'
 854      ;
 855      $db->setQuery( $query );
 856      $sections = $db->loadObjectList();
 857  
 858      // build the html select list
 859      $SectionList = JHTML::_('select.genericlist',   $sections, 'sectionmove', 'class="inputbox" size="10"', 'value', 'text', null );
 860  
 861      categories_html::copyCategorySelect( $option, $cid, $SectionList, $items, $sectionOld, $contents, $redirect );
 862  }
 863  
 864  
 865  /**
 866  * Save the item(s) to the menu selected
 867  */
 868  function copyCategorySave( $cid, $sectionOld )
 869  {
 870      global $mainframe;
 871  
 872      // Check for request forgeries
 873      JRequest::checkToken() or jexit( 'Invalid Token' );
 874  
 875      // Initialize variables
 876      $db =& JFactory::getDBO();
 877  
 878      $sectionMove     = JRequest::getInt( 'sectionmove' );
 879  
 880      //Check to see of a section was selected to copy the items too
 881      if (!$sectionMove)
 882      {
 883          $msg = JText::_('Please select a section from the list');
 884          copyCategorySelect( 'com_categories', $cid, $sectionOld );
 885          JError::raiseWarning(500, $msg);
 886          return;
 887      }
 888  
 889      $contentid         = JRequest::getVar( 'item', null, '', 'array' );
 890      JArrayHelper::toInteger($contentid);
 891  
 892      $category =& JTable::getInstance('category');
 893  
 894      foreach( $cid as $id )
 895      {
 896          $category->load( $id );
 897          $category->id         = NULL;
 898          $category->title     = JText::sprintf( 'Copy of', $category->title );
 899          $category->name     = JText::sprintf( 'Copy of', $category->name );
 900          $category->section     = $sectionMove;
 901          if (!$category->check()) {
 902              JError::raiseError(500, $category->getError());
 903          }
 904  
 905          if (!$category->store()) {
 906              JError::raiseError(500, $category->getError());
 907          }
 908          $category->checkin();
 909          // stores original catid
 910          $newcatids[]["old"] = $id;
 911          // pulls new catid
 912          $newcatids[]["new"] = $category->id;
 913      }
 914  
 915      $content =& JTable::getInstance('content');
 916      foreach( $contentid as $id) {
 917          $content->load( $id );
 918          $content->id         = NULL;
 919          $content->sectionid = $sectionMove;
 920          $content->hits         = 0;
 921          foreach( $newcatids as $newcatid ) {
 922              if ( $content->catid == $newcatid["old"] ) {
 923                  $content->catid = $newcatid["new"];
 924              }
 925          }
 926          if (!$content->check()) {
 927              JError::raiseError(500, $content->getError());
 928          }
 929  
 930          if (!$content->store()) {
 931              JError::raiseError(500, $content->getError());
 932          }
 933          $content->checkin();
 934      }
 935  
 936      $sectionNew =& JTable::getInstance('section');
 937      $sectionNew->load( $sectionMove );
 938  
 939      $msg = JText::sprintf( 'Categories copied to', count($cid), $sectionNew->title );
 940      $mainframe->redirect( 'index.php?option=com_categories&section='. $sectionOld, $msg );
 941  }
 942  
 943  /**
 944  * changes the access level of a record
 945  * @param integer The increment to reorder by
 946  */
 947  function accessMenu( $uid, $access, $section )
 948  {
 949      global $mainframe;
 950  
 951      // Check for request forgeries
 952      JRequest::checkToken() or jexit( 'Invalid Token' );
 953  
 954      // Initialize variables
 955      $db =& JFactory::getDBO();
 956  
 957      $row =& JTable::getInstance('category');
 958      $row->load( $uid );
 959      $row->access = $access;
 960  
 961      if ( !$row->check() ) {
 962          return $row->getError();
 963      }
 964      if ( !$row->store() ) {
 965          return $row->getError();
 966      }
 967  
 968      $mainframe->redirect( 'index.php?option=com_categories&section='. $section );
 969  }
 970  
 971  function saveOrder( &$cid, $section )
 972  {
 973      global $mainframe;
 974  
 975      // Check for request forgeries
 976      JRequest::checkToken() or jexit( 'Invalid Token' );
 977  
 978      // Initialize variables
 979      $db =& JFactory::getDBO();
 980  
 981      $total        = count( $cid );
 982      $order         = JRequest::getVar( 'order', array(0), 'post', 'array' );
 983      JArrayHelper::toInteger($order, array(0));
 984      $row        =& JTable::getInstance('category');
 985      $groupings = array();
 986  
 987      // update ordering values
 988      for( $i=0; $i < $total; $i++ ) {
 989          $row->load( (int) $cid[$i] );
 990          // track sections
 991          $groupings[] = $row->section;
 992          if ($row->ordering != $order[$i]) {
 993              $row->ordering = $order[$i];
 994              if (!$row->store()) {
 995                  JError::raiseError(500, $db->getErrorMsg());
 996              }
 997          }
 998      }
 999  
1000      // execute updateOrder for each parent group
1001      $groupings = array_unique( $groupings );
1002      foreach ($groupings as $group){
1003          $row->reorder('section = '.$db->Quote($group));
1004      }
1005  
1006      $msg     = JText::_( 'New ordering saved' );
1007      $mainframe->redirect( 'index.php?option=com_categories&section='. $section, $msg );
1008  }


Generato il: Mon Oct 19 20:29:27 2009 Generato con PHPXref 0.7