[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/administrator/components/com_contact/ -> admin.contact.php (source)

   1  <?php
   2  /**
   3  * @version $Id: admin.contact.php 5076 2006-09-16 11:44:41Z friesengeist $
   4  * @package Joomla
   5  * @subpackage Contact
   6  * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
   7  * @license http://www.gnu.org/copyleft/gpl.html 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( '_VALID_MOS' ) or die( 'Restricted access' );
  17  
  18  // ensure user has access to this function
  19  if (!($acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'all' )
  20          | $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'com_contact' ))) {
  21      mosRedirect( 'index2.php', _NOT_AUTH );
  22  }
  23  
  24  require_once( $mainframe->getPath( 'admin_html' ) );
  25  require_once( $mainframe->getPath( 'class' ) );
  26  
  27  $cid = josGetArrayInts( 'cid' );
  28  
  29  switch ($task) {
  30  
  31      case 'new':
  32          editContact( '0', $option);
  33          break;
  34  
  35      case 'edit':
  36          editContact( intval( $cid[0] ), $option );
  37          break;
  38  
  39      case 'editA':
  40          editContact( $id, $option );
  41          break;
  42  
  43      case 'save':
  44          saveContact( $option );
  45          break;
  46  
  47      case 'remove':
  48          removeContacts( $cid, $option );
  49          break;
  50  
  51      case 'publish':
  52          changeContact( $cid, 1, $option );
  53          break;
  54  
  55      case 'unpublish':
  56          changeContact( $cid, 0, $option );
  57          break;
  58  
  59      case 'orderup':
  60          orderContacts( intval( $cid[0] ), -1, $option );
  61          break;
  62  
  63      case 'orderdown':
  64          orderContacts( intval( $cid[0] ), 1, $option );
  65          break;
  66  
  67      case 'cancel':
  68          cancelContact();
  69          break;
  70  
  71      default:
  72          showContacts( $option );
  73          break;
  74  }
  75  
  76  /**
  77  * List the records
  78  * @param string The current GET/POST option
  79  */
  80  function showContacts( $option ) {
  81      global $database, $mainframe, $mosConfig_list_limit;
  82  
  83      $catid         = intval( $mainframe->getUserStateFromRequest( "catid{$option}", 'catid', 0 ) );
  84      $limit         = intval( $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ) );
  85      $limitstart = intval( $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 ) );
  86      $search     = $mainframe->getUserStateFromRequest( "search{$option}", 'search', '' );
  87      if (get_magic_quotes_gpc()) {
  88          $search    = stripslashes( $search );
  89      }
  90  
  91      if ( $search ) {
  92          $where[] = "cd.name LIKE '%" . $database->getEscaped( trim( strtolower( $search ) ) ) . "%'";
  93      }
  94      if ( $catid ) {
  95          $where[] = "cd.catid = " . (int) $catid;
  96      }
  97      if ( isset( $where ) ) {
  98          $where = "\n WHERE ". implode( ' AND ', $where );
  99      } else {
 100          $where = '';
 101      }
 102  
 103      // get the total number of records
 104      $query = "SELECT COUNT(*)"
 105      . "\n FROM #__contact_details AS cd"
 106      . $where
 107      ;
 108      $database->setQuery( $query );
 109      $total = $database->loadResult();
 110  
 111      require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
 112      $pageNav = new mosPageNav( $total, $limitstart, $limit  );
 113  
 114      // get the subset (based on limits) of required records
 115      $query = "SELECT cd.*, cc.title AS category, u.name AS user, v.name as editor"
 116      . "\n FROM #__contact_details AS cd"
 117      . "\n LEFT JOIN #__categories AS cc ON cc.id = cd.catid"
 118      . "\n LEFT JOIN #__users AS u ON u.id = cd.user_id"
 119      . "\n LEFT JOIN #__users AS v ON v.id = cd.checked_out"
 120      . $where
 121      . "\n ORDER BY cd.catid, cd.ordering, cd.name ASC"
 122      ;
 123      $database->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
 124      $rows = $database->loadObjectList();
 125  
 126      // build list of categories
 127      $javascript = 'onchange="document.adminForm.submit();"';
 128      $lists['catid'] = mosAdminMenus::ComponentCategory( 'catid', 'com_contact_details', intval( $catid ), $javascript );
 129  
 130      HTML_contact::showcontacts( $rows, $pageNav, $search, $option, $lists );
 131  }
 132  
 133  /**
 134  * Creates a new or edits and existing user record
 135  * @param int The id of the record, 0 if a new entry
 136  * @param string The current GET/POST option
 137  */
 138  function editContact( $id, $option ) {
 139      global $database, $my;
 140      global $mosConfig_absolute_path;
 141  
 142      $row = new mosContact( $database );
 143      // load the row from the db table
 144      $row->load( (int)$id );
 145  
 146      if ($id) {
 147          // do stuff for existing records
 148          $row->checkout($my->id);
 149      } else {
 150          // do stuff for new records
 151          $row->imagepos = 'top';
 152          $row->ordering = 0;
 153          $row->published = 1;
 154      }
 155      $lists = array();
 156  
 157      // build the html select list for ordering
 158      $query = "SELECT ordering AS value, name AS text"
 159      . "\n FROM #__contact_details"
 160      . "\n WHERE published >= 0"
 161      . "\n AND catid = " . (int) $row->catid
 162      . "\n ORDER BY ordering"
 163      ;
 164      $lists['ordering']             = mosAdminMenus::SpecificOrdering( $row, $id, $query, 1 );
 165  
 166      // build list of users
 167      $lists['user_id']             = mosAdminMenus::UserSelect( 'user_id', $row->user_id, 1, NULL, 'name', 0 );
 168      // build list of categories
 169      $lists['catid']             = mosAdminMenus::ComponentCategory( 'catid', 'com_contact_details', intval( $row->catid ) );
 170      // build the html select list for images
 171      $lists['image']             = mosAdminMenus::Images( 'image', $row->image );
 172      // build the html select list for the group access
 173      $lists['access']             = mosAdminMenus::Access( $row );
 174      // build the html radio buttons for published
 175      $lists['published']         = mosHTML::yesnoradioList( 'published', '', $row->published );
 176      // build the html radio buttons for default
 177      $lists['default_con']         = mosHTML::yesnoradioList( 'default_con', '', $row->default_con );
 178  
 179      // get params definitions
 180      $file = $mosConfig_absolute_path .'/administrator/components/com_contact/contact_items.xml';
 181      $params = new mosParameters( $row->params, $file, 'component' );
 182  
 183      HTML_contact::editcontact( $row, $lists, $option, $params );
 184  }
 185  
 186  /**
 187  * Saves the record from an edit form submit
 188  * @param string The current GET/POST option
 189  */
 190  function saveContact( $option ) {
 191      global $database;
 192  
 193      $row = new mosContact( $database );
 194      if (!$row->bind( $_POST )) {
 195          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 196          exit();
 197      }
 198  
 199      // save params
 200      $params = mosGetParam( $_POST, 'params', '' );
 201      if (is_array( $params )) {
 202          $txt = array();
 203          foreach ( $params as $k=>$v) {
 204              $txt[] = "$k=$v";
 205          }
 206          $row->params = implode( "\n", $txt );
 207      }
 208  
 209      // pre-save checks
 210      if (!$row->check()) {
 211          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 212          exit();
 213      }
 214  
 215      // save the changes
 216      if (!$row->store()) {
 217          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 218          exit();
 219      }
 220      $row->checkin();
 221      $row->updateOrder();
 222      if ($row->default_con) {
 223          $query = "UPDATE #__contact_details"
 224          . "\n SET default_con = 0"
 225          . "\n WHERE id != " . (int) $row->id
 226          . "\n AND default_con = 1"
 227          ;
 228          $database->setQuery( $query );
 229          $database->query();
 230      }
 231  
 232      mosRedirect( "index2.php?option=$option" );
 233  }
 234  
 235  /**
 236  * Removes records
 237  * @param array An array of id keys to remove
 238  * @param string The current GET/POST option
 239  */
 240  function removeContacts( &$cid, $option ) {
 241      global $database;
 242  
 243      if (count( $cid )) {
 244          mosArrayToInts( $cid );
 245          $cids = 'id=' . implode( ' OR id=', $cid );
 246          $query = "DELETE FROM #__contact_details"
 247          . "\n WHERE ( $cids )"
 248          ;
 249          $database->setQuery( $query );
 250          if (!$database->query()) {
 251              echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 252          }
 253      }
 254  
 255      mosRedirect( "index2.php?option=$option" );
 256  }
 257  
 258  /**
 259  * Changes the state of one or more content pages
 260  * @param array An array of unique category id numbers
 261  * @param integer 0 if unpublishing, 1 if publishing
 262  * @param string The current option
 263  */
 264  function changeContact( $cid=null, $state=0, $option ) {
 265      global $database, $my;
 266  
 267      if (!is_array( $cid ) || count( $cid ) < 1) {
 268          $action = $publish ? 'publish' : 'unpublish';
 269          echo "<script> alert('Select an item to $action'); window.history.go(-1);</script>\n";
 270          exit();
 271      }
 272  
 273      mosArrayToInts( $cid );
 274      $cids = 'id=' . implode( ' OR id=', $cid );
 275  
 276      $query = "UPDATE #__contact_details"
 277      . "\n SET published = " . (int) $state
 278      . "\n WHERE ( $cids )"
 279      . "\n AND ( checked_out = 0 OR ( checked_out = " . (int) $my->id . ") )"
 280      ;
 281      $database->setQuery( $query );
 282      if (!$database->query()) {
 283          echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 284          exit();
 285      }
 286  
 287      if (count( $cid ) == 1) {
 288          $row = new mosContact( $database );
 289          $row->checkin( intval( $cid[0] ) );
 290      }
 291  
 292      mosRedirect( "index2.php?option=$option" );
 293  }
 294  
 295  /** JJC
 296  * Moves the order of a record
 297  * @param integer The increment to reorder by
 298  */
 299  function orderContacts( $uid, $inc, $option ) {
 300      global $database;
 301  
 302      $row = new mosContact( $database );
 303      $row->load( (int)$uid );
 304      $row->updateOrder();
 305      $row->move( $inc, "published >= 0" );
 306      $row->updateOrder();
 307  
 308      mosRedirect( "index2.php?option=$option" );
 309  }
 310  
 311  /** PT
 312  * Cancels editing and checks in the record
 313  */
 314  function cancelContact() {
 315      global $database;
 316  
 317      $row = new mosContact( $database );
 318      $row->bind( $_POST );
 319      $row->checkin();
 320      mosRedirect('index2.php?option=com_contact');
 321  }
 322  ?>


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics