[ Index ]

PHP Cross Reference of Mambo 4.6.5

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

title

Body

[close]

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

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