[ Index ]

PHP Cross Reference of Mambo 4.6.5

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

title

Body

[close]

/administrator/components/com_trash/ -> admin.trash.php (source)

   1  <?php
   2  /**
   3  * @package Mambo
   4  * @subpackage Trash
   5  * @author Mambo Foundation Inc see README.php
   6  * @copyright (C) 2000 - 2009 Mambo Foundation Inc.
   7  * See COPYRIGHT.php for copyright notices and details.
   8  * @license GNU/GPL Version 2, see LICENSE.php
   9  *
  10  * Redistributions of files must retain the above copyright notice.
  11  *
  12  * Mambo is free software; you can redistribute it and/or
  13  * modify it under the terms of the GNU General Public License
  14  * as published by the Free Software Foundation; version 2 of the License.
  15  */
  16  
  17  /** ensure this file is being included by a parent file */
  18  defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  19  
  20  // ensure user has access to this function
  21  if (!($acl->acl_check( 'administration', 'manage', 'users', $my->usertype, 'components', 'com_trash' ))) {
  22      mosRedirect( 'index2.php', T_('You are not authorized to view this resource.') );
  23  }
  24  
  25  require_once( $mainframe->getPath( 'admin_html' ) );
  26  require_once( $mainframe->getPath( 'class', 'com_frontpage' ) );
  27  require_once ($mosConfig_absolute_path.'/components/com_content/content.class.php');
  28  
  29  $task = mosGetParam( $_REQUEST, 'task', array(0) );
  30  $cid = mosGetParam( $_POST, 'cid', array(0) );
  31  $mid = mosGetParam( $_POST, 'mid', array(0) );
  32  if ( !is_array( $cid ) ) {
  33      $cid = array(0);
  34  }
  35  
  36  switch ($task) {
  37      case "deleteconfirm":
  38      viewdeleteTrash( $cid, $mid, $option );
  39      break;
  40  
  41      case "delete":
  42      deleteTrash( $cid, $option );
  43      break;
  44  
  45      case "restoreconfirm":
  46      viewrestoreTrash( $cid, $mid, $option );
  47      break;
  48  
  49      case "restore":
  50      restoreTrash( $cid, $option );
  51      break;
  52  
  53      default:
  54      viewTrash( $option );
  55      break;
  56  }
  57  
  58  
  59  /**
  60  * Compiles a list of trash items
  61  */
  62  function viewTrash( $option ) {
  63      global $database, $mainframe, $mosConfig_list_limit;
  64      require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
  65  
  66      $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit );
  67      $limitstart = $mainframe->getUserStateFromRequest( "view{". $option ."}limitstart", 'limitstart', 0 );
  68      // get the total number of content
  69      $query = "SELECT count(*)"
  70      . "\n FROM #__content AS c"
  71      . "\n LEFT JOIN #__categories AS cc ON cc.id = c.catid"
  72      . "\n LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope='content'"
  73      . "\n WHERE c.state = '-2'"
  74      ;
  75      $database->setQuery( $query );
  76      $total_content = $database->loadResult();
  77      $pageNav_content = new mosPageNav( $total_content, $limitstart, $limit );
  78  
  79      // Query content items
  80      $query =     "SELECT c.*, g.name AS groupname, cc.name AS catname, s.name AS sectname"
  81      . "\n FROM #__content AS c"
  82      . "\n LEFT JOIN #__categories AS cc ON cc.id = c.catid"
  83      . "\n LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope='content'"
  84      . "\n INNER JOIN #__groups AS g ON g.id = c.access"
  85      . "\n LEFT JOIN #__users AS u ON u.id = c.checked_out"
  86      . "\n WHERE c.state = '-2'"
  87      . "\n ORDER BY s.name, cc.name, c.title"
  88      . "\n LIMIT ". $pageNav_content->limitstart .", ".$pageNav_content->limit .""
  89      ;
  90      $database->setQuery( $query );
  91      $contents = $database->loadObjectList();
  92      if (!$contents) $contents = array();
  93  
  94      $query = "SELECT count(*)"
  95      . "\n FROM #__menu AS m"
  96      . "\n LEFT JOIN #__users AS u ON u.id = m.checked_out"
  97      . "\n WHERE m.published = -2"
  98      ;
  99      $database->setQuery( $query );
 100      $total_menu = $database->loadResult();
 101      //$total_menu = count( $total_menu );
 102      $pageNav_menu = new mosPageNav( $total_menu, $limitstart, $limit );
 103  
 104      // Query menu items
 105      $query =     "SELECT m.*"
 106      . "\n FROM #__menu AS m"
 107      . "\n LEFT JOIN #__users AS u ON u.id = m.checked_out"
 108      . "\n WHERE m.published = -2"
 109      . "\n ORDER BY m.menutype, m.ordering, m.ordering, m.name"
 110      . "\n LIMIT ". $pageNav_menu->limitstart .", ".$pageNav_menu->limit .""
 111      ;
 112      $database->setQuery( $query );
 113      $menus = $database->loadObjectList();
 114      if (!$menus) $menus = array();
 115  
 116      foreach ( $contents as $i=>$content) {
 117          if ( ( $content->sectionid == 0 ) AND ( $content->catid == 0 ) ) {
 118              $contents[$i]->sectname = 'Typed Content';
 119          }
 120      }
 121      HTML_trash::showList( $option, $contents, $menus, $pageNav_content, $pageNav_menu );
 122  }
 123  
 124  
 125  /**
 126  * Compiles a list of the items you have selected to permanently delte
 127  */
 128  function viewdeleteTrash( $cid, $mid, $option ) {
 129      global $database, $mainframe;
 130  
 131      // seperate contentids
 132      $cids = implode( ',', $cid );
 133      $mids = implode( ',', $mid );
 134  
 135      if ( $cids ) {
 136          // Content Items query
 137          // @RawSQLUse, trivial_implementation, SELECT
 138          $query =     "SELECT a.title AS name"
 139          . "\n FROM #__content AS a"
 140          . "\n WHERE ( a.id IN (". $cids .") )"
 141          . "\n ORDER BY a.title"
 142          ;
 143          $database->setQuery( $query );
 144          $items = $database->loadObjectList();
 145          $id = $cid;
 146          $type = "content";
 147      } else if ( $mids ) {
 148          // Content Items query
 149          // @RawSQLUse, trivial_implementation, SELECT
 150          $query =     "SELECT a.name"
 151          . "\n FROM #__menu AS a"
 152          . "\n WHERE ( a.id IN (". $mids .") )"
 153          . "\n ORDER BY a.name"
 154          ;
 155          $database->setQuery( $query );
 156          $items = $database->loadObjectList();
 157          $id = $mid;
 158          $type = "menu";
 159      }
 160  
 161      HTML_trash::showDelete( $option, $id, $items, $type );
 162  }
 163  
 164  
 165  /**
 166  * Permanently deletes the selected list of trash items
 167  */
 168  function deleteTrash( $cid, $option ) {
 169      global $database, $mainframe;
 170      $type = mosGetParam( $_POST, 'type', array(0) );
 171  
 172      $total = count( $cid );
 173  
 174      if ( $type == "content" ) {
 175          $obj = new mosContent( $database );
 176          $fp = new mosFrontPage( $database );
 177          foreach ( $cid as $id ) {
 178              $id = intval( $id );
 179              $obj->delete( $id );
 180              $fp->delete( $id );
 181          }
 182      } else if ( $type == "menu" ) {
 183          $obj = new mosMenu( $database );
 184          foreach ( $cid as $id ) {
 185              $id = intval( $id );
 186              $obj->delete( $id );
 187          }
 188      }
 189  
 190      $msg = sprintf(Tn_('%s Item successfully Deleted','%s Items successfully Deleted',$total), $total);
 191      mosRedirect( "index2.php?option=$option&mosmsg=". $msg ."" );
 192  }
 193  
 194  
 195  /**
 196  * Compiles a list of the items you have selected to permanently delte
 197  */
 198  function viewrestoreTrash( $cid, $mid, $option ) {
 199      global $database, $mainframe;
 200  
 201      // seperate contentids
 202      $cids = implode( ',', $cid );
 203      $mids = implode( ',', $mid );
 204  
 205      if ( $cids ) {
 206          // Content Items query
 207          // @RawSQLUse, trivial_implementation, SELECT
 208          $query =     "SELECT a.title AS name"
 209          . "\n FROM #__content AS a"
 210          . "\n WHERE ( a.id IN (". $cids .") )"
 211          . "\n ORDER BY a.title"
 212          ;
 213          $database->setQuery( $query );
 214          $items = $database->loadObjectList();
 215          $id = $cid;
 216          $type = "content";
 217      } else if ( $mids ) {
 218          // Content Items query
 219          // @RawSQLUse, trivial_implementation, SELECT
 220          $query =     "SELECT a.name"
 221          . "\n FROM #__menu AS a"
 222          . "\n WHERE ( a.id IN (". $mids .") )"
 223          . "\n ORDER BY a.name"
 224          ;
 225          $database->setQuery( $query );
 226          $items = $database->loadObjectList();
 227          $id = $mid;
 228          $type = "menu";
 229      }
 230  
 231      HTML_trash::showRestore( $option, $id, $items, $type );
 232  }
 233  
 234  
 235  /**
 236  * Restores items selected to normal - restores to an unpublished state
 237  */
 238  function restoreTrash( $cid, $option ) {
 239      global $database;
 240      $type = mosGetParam( $_POST, 'type', array(0) );
 241  
 242      $total = count( $cid );
 243  
 244      // restores to an unpublished state
 245      $state = "0";
 246      $ordering = '9999';
 247      //seperate contentids
 248      $cids = implode( ',', $cid );
 249  
 250      if ( $type == "content" ) {
 251          // @RawSQLUse, trivial_implementation, UPDATE
 252          $query =     "UPDATE #__content SET state = '". $state ."', ordering = '". $ordering ."'"
 253          . "\n WHERE id IN ( ". $cids ." )"
 254          ;
 255      } else if ( $type == "menu" ) {
 256          // @RawSQLUse, trivial_implementation, UPDATE
 257          $query =     "UPDATE #__menu SET published = '". $state ."', ordering = '9999'"
 258          . "\n WHERE id IN ( ". $cids ." )"
 259          ;
 260      }
 261  
 262      $database->setQuery( $query );
 263      if ( !$database->query() ) {
 264          echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 265          exit();
 266      }
 267  
 268      $msg = sprintf(Tn_('%s Item successfully Restored','%s Items successfully Restored',$total),$total);
 269      mosRedirect( "index2.php?option=$option&mosmsg=". $msg ."" );
 270  }
 271  
 272  
 273  ?>