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