[ Index ]

PHP Cross Reference of Mambo 4.6.5

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

title

Body

[close]

/administrator/components/com_newsfeeds/ -> admin.newsfeeds.php (source)

   1  <?php
   2  /**
   3  * @package Mambo
   4  * @subpackage Newsfeeds
   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', 'edit', 'users', $my->usertype, 'components', 'all' )
  22          | $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'com_newsfeeds' ))) {
  23      mosRedirect( 'index2.php', T_('You are not authorized to view this resource.') );
  24  }
  25  
  26  require_once( $mainframe->getPath( 'admin_html' ) );
  27  require_once( $mainframe->getPath( 'class' ) );
  28  
  29  $task     = mosGetParam( $_REQUEST, 'task', array(0) );
  30  $cid     = mosGetParam( $_POST, 'cid', array(0) );
  31  $id     = mosGetParam( $_GET, 'id', 0 );
  32  if (!is_array( $cid )) {
  33      $cid = array(0);
  34  }
  35  
  36  switch ($task) {
  37  
  38      case 'new':
  39          editNewsFeed( 0, $option );
  40          break;
  41  
  42      case 'edit':
  43          editNewsFeed( $cid[0], $option );
  44          break;
  45  
  46      case 'editA':
  47          editNewsFeed( $id, $option );
  48          break;
  49  
  50      case 'save':
  51          saveNewsFeed( $option );
  52          break;
  53  
  54      case 'publish':
  55          publishNewsFeeds( $cid, 1, $option );
  56          break;
  57  
  58      case 'unpublish':
  59          publishNewsFeeds( $cid, 0, $option );
  60          break;
  61  
  62      case 'remove':
  63          removeNewsFeeds( $cid, $option );
  64          break;
  65  
  66      case 'cancel':
  67          cancelNewsFeed( $option );
  68          break;
  69  
  70      case 'orderup':
  71          orderNewsFeed( $cid[0], -1, $option );
  72          break;
  73  
  74      case 'orderdown':
  75          orderNewsFeed( $cid[0], 1, $option );
  76          break;
  77  
  78      default:
  79          showNewsFeeds( $option );
  80          break;
  81  }
  82  
  83  /**
  84  * List the records
  85  * @param string The current GET/POST option
  86  */
  87  function showNewsFeeds( $option ) {
  88      global $database, $mainframe, $mosConfig_list_limit;
  89  
  90      $catid = $mainframe->getUserStateFromRequest( "catid{$option}", 'catid', 0 );
  91      $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit );
  92      $limitstart = $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 );
  93  
  94      // get the total number of records
  95      // @RawSQLUse, trivial_implementation, SELECT, CONCEPT
  96      $query = "SELECT count(*) FROM #__newsfeeds"
  97      . ( $catid ? "\n WHERE catid='$catid'" : '' )
  98      ;
  99      $database->setQuery( $query );
 100      $total = $database->loadResult();
 101  
 102      require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
 103      $pageNav = new mosPageNav( $total, $limitstart, $limit );
 104  
 105      // get the subset (based on limits) of required records
 106      $query = "SELECT a.*, c.name AS catname, u.name AS editor"
 107      . "\n FROM #__newsfeeds AS a"
 108      . "\n LEFT JOIN #__categories AS c ON c.id = a.catid"
 109      . "\n LEFT JOIN #__users AS u ON u.id = a.checked_out"
 110      . ( $catid ? "\n WHERE a.catid='$catid'" : '' )
 111      . "\n ORDER BY a.ordering"
 112      . "\n LIMIT $pageNav->limitstart,$pageNav->limit"
 113      ;
 114      $database->setQuery( $query );
 115  
 116      $rows = $database->loadObjectList();
 117      if ($database->getErrorNum()) {
 118          echo $database->stderr();
 119          return false;
 120      }
 121  
 122      // build list of categories
 123      $javascript = 'onchange="document.adminForm.submit();"';
 124      $lists['category']             = mosAdminMenus::ComponentCategory( 'catid', $option, $catid, $javascript ); 
 125  
 126      HTML_newsfeeds::showNewsFeeds( $rows, $lists, $pageNav, $option );
 127  }
 128  
 129  /**
 130  * Creates a new or edits and existing user record
 131  * @param int The id of the user, 0 if a new entry
 132  * @param string The current GET/POST option
 133  */
 134  function editNewsFeed( $id, $option ) {
 135      global $database, $my;
 136  
 137      $catid = intval( mosGetParam( $_REQUEST, 'catid', 0 ) );
 138  
 139      $row = new mosNewsFeed( $database );
 140      // load the row from the db table
 141      $row->load( $id );
 142  
 143      if ($id) {
 144          // do stuff for existing records
 145          $row->checkout( $my->id );
 146      } else {
 147          // do stuff for new records
 148          $row->ordering         = 0;
 149          $row->numarticles     = 5;
 150          $row->cache_time     = 3600;
 151          $row->published     = 1;
 152      }
 153  
 154      // build the html select list for ordering
 155      $query = "SELECT a.ordering AS value, a.name AS text"
 156      . "\n FROM #__newsfeeds AS a"
 157      . "\n ORDER BY a.ordering"
 158      ;
 159      $lists['ordering']             = mosAdminMenus::SpecificOrdering( $row, $id, $query, 1 ); 
 160  
 161      // build list of categories
 162      $lists['category']             = mosAdminMenus::ComponentCategory( 'catid', $option, intval( $row->catid ) ); 
 163      // build the html select list
 164      $lists['published']         = mosHTML::yesnoRadioList( 'published', 'class="inputbox"', $row->published );
 165  
 166      HTML_newsfeeds::editNewsFeed( $row, $lists, $option );
 167  }
 168  
 169  /**
 170  * Saves the record from an edit form submit
 171  * @param string The current GET/POST option
 172  */
 173  function saveNewsFeed( $option ) {
 174      global $database, $my;
 175  
 176      $row = new mosNewsFeed( $database );
 177      if (!$row->bind( $_POST )) {
 178          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 179          exit();
 180      }
 181  
 182      // pre-save checks
 183      if (!$row->check()) {
 184          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 185          exit();
 186      }
 187  
 188      // save the changes
 189      if (!$row->store()) {
 190          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 191          exit();
 192      }
 193      $row->checkin();
 194      $row->updateOrder();
 195  
 196      mosRedirect( 'index2.php?option='. $option );
 197  }
 198  
 199  /**
 200  * Publishes or Unpublishes one or more modules
 201  * @param array An array of unique category id numbers
 202  * @param integer 0 if unpublishing, 1 if publishing
 203  * @param string The current GET/POST option
 204  */
 205  function publishNewsFeeds( $cid, $publish, $option ) {
 206      global $database;
 207  
 208      if (count( $cid ) < 1) {
 209          $action = $publish ? T_('publish') : T_('unpublish');
 210          echo "<script> alert('".sprintf(T_('Select a module to %s'), $action)."'); window.history.go(-1);</script>\n";
 211          exit;
 212      }
 213  
 214      $cids = implode( ',', $cid );
 215  
 216      $query = "UPDATE #__newsfeeds SET published='$publish'"
 217      . "\n WHERE id IN ($cids)"
 218      . "\n AND ( checked_out=0 OR (checked_out='$my->id') )"
 219      ;
 220      $database->setQuery( $query );
 221      if (!$database->query()) {
 222          echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 223          exit();
 224      }
 225  
 226      if (count( $cid ) == 1) {
 227          $row = new mosNewsFeed( $database );
 228          $row->checkin( $cid[0] );
 229      }
 230  
 231      mosRedirect( 'index2.php?option='. $option );
 232  }
 233  
 234  /**
 235  * Removes records
 236  * @param array An array of id keys to remove
 237  * @param string The current GET/POST option
 238  */
 239  function removeNewsFeeds( &$cid, $option ) {
 240      global $database;
 241  
 242      if (!is_array( $cid ) || count( $cid ) < 1) {
 243          echo "<script> alert('".T_('Select an item to delete')."'); window.history.go(-1);</script>\n";
 244          exit;
 245      }
 246      if (count( $cid )) {
 247          $cids = implode( ',', $cid );
 248          $query = "DELETE FROM #__newsfeeds"
 249          . "\n WHERE id IN ($cids)"
 250          . "\n AND checked_out='0'"
 251          ;
 252          $database->setQuery( $query );
 253          if (!$database->query()) {
 254              echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 255          }
 256      }
 257  
 258      mosRedirect( 'index2.php?option='. $option );
 259  }
 260  
 261  /**
 262  * Cancels an edit operation
 263  * @param string The current GET/POST option
 264  */
 265  function cancelNewsFeed( $option ) {
 266      global $database;
 267  
 268      $row = new mosNewsFeed( $database );
 269      $row->bind( $_POST );
 270      // sanitize
 271      $row->id = intval($row->id);
 272      $row->checkin();
 273      mosRedirect( 'index2.php?option='. $option );
 274  }
 275  
 276  /**
 277  * Moves the order of a record
 278  * @param integer The id of the record to move
 279  * @param integer The direction to reorder, +1 down, -1 up
 280  * @param string The current GET/POST option
 281  */
 282  function orderNewsFeed( $id, $inc, $option ) {
 283      global $database;
 284  
 285      $limit = mosGetParam( $_REQUEST, 'limit', 0 );
 286      $limitstart = mosGetParam( $_REQUEST, 'limitstart', 0 );
 287      $catid = intval( mosGetParam( $_REQUEST, 'catid', 0 ) );
 288  
 289      $row = new mosNewsFeed( $database );
 290      $row->load( $id );
 291      $row->move( $inc );
 292  
 293      mosRedirect( 'index2.php?option='. $option );
 294  }
 295  ?>