Files
@ c7d7e38b2269
Branch filter:
Location: hot67beta/administrator/components/com_contact/admin.contact.php
c7d7e38b2269
13.0 KiB
text/x-php
Initial import of the site.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | <?php
/**
* @version $Id: admin.contact.php 11299 2008-11-22 01:40:44Z ian $
* @package Joomla
* @subpackage Contact
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
/*
* Make sure the user is authorized to view this page
*/
$user = & JFactory::getUser();
if (!$user->authorize( 'com_contact', 'manage' )) {
$mainframe->redirect( 'index.php', JText::_('ALERTNOTAUTH') );
}
require_once( JApplicationHelper::getPath( 'admin_html' ) );
// Set the table directory
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_contact'.DS.'tables');
$task = JRequest::getCmd('task');
$id = JRequest::getVar('id', 0, 'get', 'int');
$cid = JRequest::getVar('cid', array(0), 'post', 'array');
JArrayHelper::toInteger($cid, array(0));
switch ($task)
{
case 'add' :
editContact(false );
break;
case 'edit':
editContact(true);
break;
case 'apply':
case 'save':
case 'save2new':
case 'save2copy':
saveContact( $task );
break;
case 'remove':
removeContacts( $cid );
break;
case 'publish':
changeContact( $cid, 1 );
break;
case 'unpublish':
changeContact( $cid, 0 );
break;
case 'orderup':
orderContacts( $cid[0], -1 );
break;
case 'orderdown':
orderContacts( $cid[0], 1 );
break;
case 'accesspublic':
changeAccess( $cid[0], 0 );
break;
case 'accessregistered':
changeAccess( $cid[0], 1 );
break;
case 'accessspecial':
changeAccess( $cid[0], 2 );
break;
case 'saveorder':
saveOrder( $cid );
break;
case 'cancel':
cancelContact();
break;
default:
showContacts( $option );
break;
}
/**
* List the records
* @param string The current GET/POST option
*/
function showContacts( $option )
{
global $mainframe;
$db =& JFactory::getDBO();
$filter_order = $mainframe->getUserStateFromRequest( $option.'filter_order', 'filter_order', 'cd.ordering', 'cmd' );
$filter_order_Dir = $mainframe->getUserStateFromRequest( $option.'filter_order_Dir', 'filter_order_Dir', '', 'word' );
$filter_state = $mainframe->getUserStateFromRequest( $option.'filter_state', 'filter_state', '', 'word' );
$filter_catid = $mainframe->getUserStateFromRequest( $option.'filter_catid', 'filter_catid', 0, 'int' );
$search = $mainframe->getUserStateFromRequest( $option.'search', 'search', '', 'string' );
$search = JString::strtolower( $search );
$limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
$limitstart = $mainframe->getUserStateFromRequest($option.'.limitstart', 'limitstart', 0, 'int');
$where = array();
if ( $search ) {
$where[] = 'cd.name LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
}
if ( $filter_catid ) {
$where[] = 'cd.catid = '.(int) $filter_catid;
}
if ( $filter_state ) {
if ( $filter_state == 'P' ) {
$where[] = 'cd.published = 1';
} else if ($filter_state == 'U' ) {
$where[] = 'cd.published = 0';
}
}
$where = ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' );
if ($filter_order == 'cd.ordering'){
$orderby = ' ORDER BY category, cd.ordering';
} else {
$orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', category, cd.ordering';
}
// get the total number of records
$query = 'SELECT COUNT(*)'
. ' FROM #__contact_details AS cd'
. $where
;
$db->setQuery( $query );
$total = $db->loadResult();
jimport('joomla.html.pagination');
$pageNav = new JPagination( $total, $limitstart, $limit );
// get the subset (based on limits) of required records
$query = 'SELECT cd.*, cc.title AS category, u.name AS user, v.name as editor, g.name AS groupname'
. ' FROM #__contact_details AS cd'
. ' LEFT JOIN #__groups AS g ON g.id = cd.access'
. ' LEFT JOIN #__categories AS cc ON cc.id = cd.catid'
. ' LEFT JOIN #__users AS u ON u.id = cd.user_id'
. ' LEFT JOIN #__users AS v ON v.id = cd.checked_out'
. $where
. $orderby
;
$db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
$rows = $db->loadObjectList();
// build list of categories
$javascript = 'onchange="document.adminForm.submit();"';
$lists['catid'] = JHTML::_('list.category', 'filter_catid', 'com_contact_details', intval( $filter_catid ), $javascript );
// state filter
$lists['state'] = JHTML::_('grid.state', $filter_state );
// table ordering
$lists['order_Dir'] = $filter_order_Dir;
$lists['order'] = $filter_order;
// search filter
$lists['search']= $search;
HTML_contact::showcontacts( $rows, $pageNav, $option, $lists );
}
/**
* Creates a new or edits and existing user record
* @param int The id of the record, 0 if a new entry
* @param string The current GET/POST option
*/
function editContact($edit )
{
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
$cid = JRequest::getVar('cid', array(0), '', 'array');
$option = JRequest::getCmd('option');
JArrayHelper::toInteger($cid, array(0));
$row =& JTable::getInstance('contact', 'Table');
// load the row from the db table
if($edit)
$row->load( $cid[0] );
if ($edit) {
// do stuff for existing records
$row->checkout($user->get('id'));
} else {
// do stuff for new records
$row->imagepos = 'top';
$row->ordering = 0;
$row->published = 1;
}
$lists = array();
// build the html select list for ordering
$query = 'SELECT ordering AS value, name AS text'
. ' FROM #__contact_details'
. ' WHERE published >= 0'
. ' AND catid = '.(int) $row->catid
. ' ORDER BY ordering'
;
if($edit)
$lists['ordering'] = JHTML::_('list.specificordering', $row, $cid[0], $query );
else
$lists['ordering'] = JHTML::_('list.specificordering', $row, '', $query );
// build list of users
$lists['user_id'] = JHTML::_('list.users', 'user_id', $row->user_id, 1, NULL, 'name', 0 );
// build list of categories
$lists['catid'] = JHTML::_('list.category', 'catid', 'com_contact_details', intval( $row->catid ) );
// build the html select list for images
$lists['image'] = JHTML::_('list.images', 'image', $row->image );
// build the html select list for the group access
$lists['access'] = JHTML::_('list.accesslevel', $row );
// build the html radio buttons for published
$lists['published'] = JHTML::_('select.booleanlist', 'published', '', $row->published );
// build the html radio buttons for default
$lists['default_con'] = JHTML::_('select.booleanlist', 'default_con', '', $row->default_con );
// get params definitions
$file = JPATH_ADMINISTRATOR .'/components/com_contact/contact_items.xml';
$params = new JParameter( $row->params, $file, 'component' );
HTML_contact::editcontact( $row, $lists, $option, $params );
}
/**
* Saves the record from an edit form submit
* @param string The current GET/POST option
*/
function saveContact( $task )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
// Initialize variables
$db =& JFactory::getDBO();
$row =& JTable::getInstance('contact', 'Table');
$post = JRequest::get( 'post' );
$post['misc'] = JRequest::getVar('misc', '', 'POST', 'string', JREQUEST_ALLOWHTML);
if (!$row->bind( $post )) {
JError::raiseError(500, $row->getError() );
}
// save params
$params = JRequest::getVar( 'params', array(), 'post', 'array' );
if (is_array( $params )) {
$txt = array();
foreach ( $params as $k=>$v) {
$txt[] = "$k=$v";
}
$row->params = implode( "\n", $txt );
}
// save to a copy, reset the primary key
if ($task == 'save2copy') {
$row->id = 0;
}
// pre-save checks
if (!$row->check()) {
JError::raiseError(500, $row->getError() );
}
// if new item, order last in appropriate group
if (!$row->id) {
$where = "catid = " . (int) $row->catid;
$row->ordering = $row->getNextOrder( $where );
}
// save the changes
if (!$row->store()) {
JError::raiseError(500, $row->getError() );
}
$row->checkin();
if ($row->default_con) {
$query = 'UPDATE #__contact_details'
. ' SET default_con = 0'
. ' WHERE id <> '. (int) $row->id
. ' AND default_con = 1'
;
$db->setQuery( $query );
$db->query();
}
switch ($task)
{
case 'apply':
case 'save2copy':
$msg = JText::sprintf( 'Changes to X saved', JText::_('Contact') );
$link = 'index.php?option=com_contact&task=edit&cid[]='. $row->id .'';
break;
case 'save2new':
$msg = JText::sprintf( 'Changes to X saved', JText::_('Contact') );
$link = 'index.php?option=com_contact&task=edit';
break;
case 'save':
default:
$msg = JText::_( 'Contact saved' );
$link = 'index.php?option=com_contact';
break;
}
$mainframe->redirect( $link, $msg );
}
/**
* Removes records
* @param array An array of id keys to remove
* @param string The current GET/POST option
*/
function removeContacts( &$cid )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
// Initialize variables
$db =& JFactory::getDBO();
JArrayHelper::toInteger($cid);
if (count( $cid )) {
$cids = implode( ',', $cid );
$query = 'DELETE FROM #__contact_details'
. ' WHERE id IN ( '. $cids .' )'
;
$db->setQuery( $query );
if (!$db->query()) {
echo "<script> alert('".$db->getErrorMsg(true)."'); window.history.go(-1); </script>\n";
}
}
$mainframe->redirect( "index.php?option=com_contact" );
}
/**
* Changes the state of one or more content pages
* @param array An array of unique category id numbers
* @param integer 0 if unpublishing, 1 if publishing
* @param string The current option
*/
function changeContact( $cid=null, $state=0 )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
// Initialize variables
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
JArrayHelper::toInteger($cid);
if (count( $cid ) < 1) {
$action = $state ? 'publish' : 'unpublish';
JError::raiseError(500, JText::_( 'Select an item to' .$action, true ) );
}
$cids = implode( ',', $cid );
$query = 'UPDATE #__contact_details'
. ' SET published = ' . (int) $state
. ' WHERE id IN ( '. $cids .' )'
. ' AND ( checked_out = 0 OR ( checked_out = '. (int) $user->get('id') .' ) )'
;
$db->setQuery( $query );
if (!$db->query()) {
JError::raiseError(500, $db->getErrorMsg() );
}
if (count( $cid ) == 1) {
$row =& JTable::getInstance('contact', 'Table');
$row->checkin( intval( $cid[0] ) );
}
$mainframe->redirect( 'index.php?option=com_contact' );
}
/** JJC
* Moves the order of a record
* @param integer The increment to reorder by
*/
function orderContacts( $uid, $inc )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
// Initialize variables
$db =& JFactory::getDBO();
$row =& JTable::getInstance('contact', 'Table');
$row->load( $uid );
$row->move( $inc, 'catid = '. (int) $row->catid .' AND published != 0' );
$mainframe->redirect( 'index.php?option=com_contact' );
}
/** PT
* Cancels editing and checks in the record
*/
function cancelContact()
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
// Initialize variables
$db =& JFactory::getDBO();
$row =& JTable::getInstance('contact', 'Table');
$row->bind( JRequest::get( 'post' ));
$row->checkin();
$mainframe->redirect('index.php?option=com_contact');
}
/**
* changes the access level of a record
* @param integer The increment to reorder by
*/
function changeAccess( $id, $access )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
// Initialize variables
$db =& JFactory::getDBO();
$row =& JTable::getInstance('contact', 'Table');
$row->load( $id );
$row->access = $access;
if ( !$row->check() ) {
return $row->getError();
}
if ( !$row->store() ) {
return $row->getError();
}
$mainframe->redirect( 'index.php?option=com_contact' );
}
function saveOrder( &$cid )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
// Initialize variables
$db =& JFactory::getDBO();
$total = count( $cid );
$order = JRequest::getVar( 'order', array(0), 'post', 'array' );
JArrayHelper::toInteger($order, array(0));
$row =& JTable::getInstance('contact', 'Table');
$groupings = array();
// update ordering values
for( $i=0; $i < $total; $i++ ) {
$row->load( (int) $cid[$i] );
// track categories
$groupings[] = $row->catid;
if ($row->ordering != $order[$i]) {
$row->ordering = $order[$i];
if (!$row->store()) {
JError::raiseError(500, $db->getErrorMsg() );
}
}
}
// execute updateOrder for each parent group
$groupings = array_unique( $groupings );
foreach ($groupings as $group){
$row->reorder('catid = '.(int) $group);
}
$msg = 'New ordering saved';
$mainframe->redirect( 'index.php?option=com_contact', $msg );
}
|