[ Index ]

PHP Cross Reference of Mambo 4.6.5

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

title

Body

[close]

/administrator/components/com_weblinks/ -> admin.weblinks.php (source)

   1  <?php
   2  /**
   3  * @package Mambo
   4  * @subpackage Weblinks
   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_weblinks' ))) {
  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  $cid = mosGetParam( $_POST, 'cid', array(0) );
  30  
  31  switch ($task) {
  32      case 'new':
  33          editWeblink( $option, 0 );
  34          break;
  35  
  36      case 'edit':
  37          editWeblink( $option, $cid[0] );
  38          break;
  39  
  40      case 'editA':
  41          editWeblink( $option, $id );
  42          break;
  43  
  44      case 'save':
  45          saveWeblink( $option );
  46          break;
  47  
  48      case 'remove':
  49          removeWeblinks( $cid, $option );
  50          break;
  51  
  52      case 'publish':
  53          publishWeblinks( $cid, 1, $option );
  54          break;
  55  
  56      case 'unpublish':
  57          publishWeblinks( $cid, 0, $option );
  58          break;
  59  
  60      case 'approve':
  61          break;
  62  
  63      case 'cancel':
  64          cancelWeblink( $option );
  65          break;
  66  
  67      case 'orderup':
  68          orderWeblinks( $cid[0], -1, $option );
  69          break;
  70  
  71      case 'orderdown':
  72          orderWeblinks( $cid[0], 1, $option );
  73          break;
  74  
  75      default:
  76          showWeblinks( $option );
  77          break;
  78  }
  79  
  80  /**
  81  * Compiles a list of records
  82  * @param database A database connector object
  83  */
  84  function showWeblinks( $option ) {
  85      global $database, $mainframe, $mosConfig_list_limit;
  86  
  87      $catid = $mainframe->getUserStateFromRequest( "catid{$option}", 'catid', 0 );
  88      $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit );
  89      $limitstart = $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 );
  90      $search = $mainframe->getUserStateFromRequest( "search{$option}", 'search', '' );
  91      $search = $database->getEscaped( trim( strtolower( $search ) ) );
  92  
  93      $where = array();
  94  
  95      if ($catid > 0) {
  96          $where[] = "a.catid='$catid'";
  97      }
  98      if ($search) {
  99          $where[] = "LOWER(a.title) LIKE '%$search%'";
 100      }
 101  
 102      // get the total number of records
 103      $database->setQuery( "SELECT count(*) FROM #__weblinks AS a"
 104          . (count( $where ) ? "\nWHERE " . implode( ' AND ', $where ) : "")
 105      );
 106      $total = $database->loadResult();
 107  
 108      require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
 109      $pageNav = new mosPageNav( $total, $limitstart, $limit  );
 110  
 111      $query = "SELECT a.*, cc.name AS category, u.name AS editor"
 112      . "\n FROM #__weblinks AS a"
 113      . "\n LEFT JOIN #__categories AS cc ON cc.id = a.catid"
 114      . "\n LEFT JOIN #__users AS u ON u.id = a.checked_out"
 115      . ( count( $where ) ? "\n WHERE " . implode( ' AND ', $where ) : "")
 116      . "\n ORDER BY a.catid, a.ordering"
 117      . "\n LIMIT $pageNav->limitstart, $pageNav->limit"
 118      ;
 119      $database->setQuery( $query );
 120  
 121      $rows = $database->loadObjectList();
 122      if ($database->getErrorNum()) {
 123          echo $database->stderr();
 124          return false;
 125      }
 126  
 127      // build list of categories
 128      $javascript = 'onchange="document.adminForm.submit();"';
 129      $lists['catid'] = mosAdminMenus::ComponentCategory( 'catid', $option, intval( $catid ), $javascript );
 130  
 131      HTML_weblinks::showWeblinks( $option, $rows, $lists, $search, $pageNav );
 132  }
 133  
 134  /**
 135  * Compiles information to add or edit
 136  * @param integer The unique id of the record to edit (0 if new)
 137  */
 138  function editWeblink( $option, $id ) {
 139      global $database, $my, $mosConfig_absolute_path, $mosConfig_live_site;
 140  
 141      $lists = array();
 142  
 143      $row = new mosWeblink( $database );
 144      // load the row from the db table
 145      $row->load( $id );
 146  
 147      // fail if checked out not by 'me'
 148      if ($row->checked_out && $row->checked_out <> $my->id) {
 149          mosRedirect( 'index2.php?option='. $option, sprintf(T_('The module %s is currently being edited by another administrator.'), $row->title) );
 150      }
 151  
 152      if ($id) {
 153          $row->checkout( $my->id );
 154      } else {
 155          // initialise new record
 156          $row->published         = 1;
 157          $row->approved         = 1;
 158          $row->order             = 0;
 159          $row->catid = mosGetParam( $_POST, 'catid', 0 );
 160      }
 161  
 162      // build the html select list for ordering
 163      $query = "SELECT ordering AS value, title AS text"
 164      . "\n FROM #__weblinks"
 165      . "\n WHERE catid='$row->catid'"
 166      . "\n ORDER BY ordering"
 167      ;
 168      $lists['ordering']             = mosAdminMenus::SpecificOrdering( $row, $id, $query, 1 );
 169  
 170      // build list of categories
 171      $lists['catid']             = mosAdminMenus::ComponentCategory( 'catid', $option, intval( $row->catid ) );
 172      // build the html select list
 173      $lists['approved']             = mosHTML::yesnoRadioList( 'approved', 'class="inputbox"', $row->approved );
 174      // build the html select list
 175      $lists['published']         = mosHTML::yesnoRadioList( 'published', 'class="inputbox"', $row->published );
 176  
 177      $file = $mosConfig_absolute_path .'/administrator/components/com_weblinks/weblinks_item.xml';
 178      $params =& new mosAdminParameters( $row->params, $file, 'component' );
 179  
 180      HTML_weblinks::editWeblink( $row, $lists, $params, $option );
 181  }
 182  
 183  /**
 184  * Saves the record on an edit form submit
 185  * @param database A database connector object
 186  */
 187  function saveWeblink( $option ) {
 188      global $database, $my;
 189  
 190      $row = new mosWeblink( $database );
 191      if (!$row->bind( $_POST )) {
 192          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 193          exit();
 194      }
 195      // save params
 196      $params = mosGetParam( $_POST, 'params', '' );
 197      if (is_array( $params )) {
 198          $txt = array();
 199          foreach ( $params as $k=>$v) {
 200              $txt[] = "$k=$v";
 201          }
 202          $row->params = implode( "\n", $txt );
 203      }
 204  
 205      $row->date = date( "Y-m-d H:i:s" );
 206      if (!$row->check()) {
 207          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 208          exit();
 209      }
 210      if (!$row->store()) {
 211          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 212          exit();
 213      }
 214      $row->checkin();
 215      $row->updateOrder( "catid='$row->catid'" );
 216  
 217      mosRedirect( "index2.php?option=$option" );
 218  }
 219  
 220  /**
 221  * Deletes one or more records
 222  * @param array An array of unique category id numbers
 223  * @param string The current url option
 224  */
 225  function removeWeblinks( $cid, $option ) {
 226      global $database;
 227  
 228      if (!is_array( $cid ) || count( $cid ) < 1) {
 229          echo "<script> alert('".T_('Select an item to delete')."'); window.history.go(-1);</script>\n";
 230          exit;
 231      }
 232      if (count( $cid )) {
 233          $cids = implode( ',', $cid );
 234          // @RawSQLUse, trivial_implementation, DELETE
 235          $database->setQuery( "DELETE FROM #__weblinks WHERE id IN ($cids)" );
 236          if (!$database->query()) {
 237              echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 238          }
 239      }
 240  
 241      mosRedirect( "index2.php?option=$option" );
 242  }
 243  
 244  /**
 245  * Publishes or Unpublishes one or more records
 246  * @param array An array of unique category id numbers
 247  * @param integer 0 if unpublishing, 1 if publishing
 248  * @param string The current url option
 249  */
 250  function publishWeblinks( $cid=null, $publish=1,  $option ) {
 251      global $database, $my;
 252  
 253      $catid = mosGetParam( $_POST, 'catid', array(0) );
 254  
 255      if (!is_array( $cid ) || count( $cid ) < 1) {
 256          $action = $publish ? T_('publish') : T_('unpublish');
 257          echo "<script> alert('".sprintf(T_('Select an item to %s'), $action)."'); window.history.go(-1);</script>\n";
 258          exit;
 259      }
 260  
 261      $cids = implode( ',', $cid );
 262  
 263      $database->setQuery( "UPDATE #__weblinks SET published='$publish'"
 264          . "\nWHERE id IN ($cids) AND (checked_out=0 OR (checked_out='$my->id'))"
 265      );
 266      if (!$database->query()) {
 267          echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 268          exit();
 269      }
 270  
 271      if (count( $cid ) == 1) {
 272          $row = new mosWeblink( $database );
 273          $row->checkin( $cid[0] );
 274      }
 275      mosRedirect( "index2.php?option=$option" );
 276  }
 277  /**
 278  * Moves the order of a record
 279  * @param integer The increment to reorder by
 280  */
 281  function orderWeblinks( $uid, $inc, $option ) {
 282      global $database;
 283      $row = new mosWeblink( $database );
 284      $row->load( $uid );
 285      $row->move( $inc, "published >= 0" );
 286  
 287      mosRedirect( "index2.php?option=$option" );
 288  }
 289  
 290  /**
 291  * Cancels an edit operation
 292  * @param string The current url option
 293  */
 294  function cancelWeblink( $option ) {
 295      global $database;
 296      $row = new mosWeblink( $database );
 297      $row->bind( $_POST );
 298      // sanitize
 299      $row->id = intval($row->id);
 300      $row->checkin();
 301      mosRedirect( "index2.php?option=$option" );
 302  }
 303  ?>