| [ Index ] | PHP Cross Reference of Mambo 4.6.5 |
|
| [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Mambo 4 * @subpackage Mambots 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, 'mambots', 'all' ) 22 | $acl->acl_check( 'administration', 'install', 'users', $my->usertype, 'mambots', 'all' ))) { 23 mosRedirect( 'index2.php', T_('You are not authorized to view this resource.') ); 24 } 25 26 require_once( $mainframe->getPath( 'admin_html' ) ); 27 28 $client = mosGetParam( $_REQUEST, 'client', '' ); 29 $cid = mosGetParam( $_POST, 'cid', array(0) ); 30 if (!is_array( $cid )) { 31 $cid = array(0); 32 } 33 34 switch ( $task ) { 35 36 case 'new': 37 case 'edit': 38 editMambot( $option, $cid[0], $client ); 39 break; 40 41 case 'editA': 42 editMambot( $option, $id, $client ); 43 break; 44 45 case 'save': 46 case 'apply': 47 saveMambot( $option, $client, $task ); 48 break; 49 50 case 'remove': 51 removeMambot( $cid, $option, $client ); 52 break; 53 54 case 'cancel': 55 cancelMambot( $option, $client ); 56 break; 57 58 case 'publish': 59 case 'unpublish': 60 publishMambot( $cid, ($task == 'publish'), $option, $client ); 61 break; 62 63 case 'orderup': 64 case 'orderdown': 65 orderMambot( $cid[0], ($task == 'orderup' ? -1 : 1), $option, $client ); 66 break; 67 68 case 'accesspublic': 69 case 'accessregistered': 70 case 'accessspecial': 71 accessMenu( $cid[0], $task, $option, $client ); 72 break; 73 74 case 'saveorder': 75 saveOrder( $cid ); 76 break; 77 78 default: 79 viewMambots( $option, $client ); 80 break; 81 } 82 83 /** 84 * Compiles a list of installed or defined modules 85 */ 86 function viewMambots( $option, $client ) { 87 global $database, $mainframe, $mosConfig_list_limit; 88 global $mosConfig_absolute_path; 89 90 $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ); 91 $limitstart = $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 ); 92 $filter_type = $mainframe->getUserStateFromRequest( "filter_type{$option}{$client}", 'filter_type', 0 ); 93 $search = $mainframe->getUserStateFromRequest( "search{$option}{$client}", 'search', '' ); 94 $search = $database->getEscaped( trim( strtolower( $search ) ) ); 95 96 if ($client == 'admin') { 97 $where[] = "m.client_id = '1'"; 98 $client_id = 1; 99 } else { 100 $where[] = "m.client_id = '0'"; 101 $client_id = 0; 102 } 103 104 // used by filter 105 if ( $filter_type ) { 106 $where[] = "m.folder = '$filter_type'"; 107 } 108 if ( $search ) { 109 $where[] = "LOWER( m.name ) LIKE '%$search%'"; 110 } 111 112 // get the total number of records 113 $query = "SELECT count(*) FROM #__mambots As m ". ( count( $where ) ? "\n WHERE " . implode( ' AND ', $where ) : '' ); 114 $database->setQuery( $query ); 115 $total = $database->loadResult(); 116 117 require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' ); 118 $pageNav = new mosPageNav( $total, $limitstart, $limit ); 119 120 $query = "SELECT m.*, u.name AS editor, g.name AS groupname" 121 . "\n FROM #__mambots AS m" 122 . "\n LEFT JOIN #__users AS u ON u.id = m.checked_out" 123 . "\n LEFT JOIN #__groups AS g ON g.id = m.access" 124 . ( count( $where ) ? "\n WHERE " . implode( ' AND ', $where ) : '' ) 125 . "\n GROUP BY m.id" 126 . "\n ORDER BY m.folder ASC, m.ordering ASC, m.name ASC" 127 . "\n LIMIT $pageNav->limitstart,$pageNav->limit" 128 ; 129 $database->setQuery( $query ); 130 $rows = $database->loadObjectList(); 131 if ($database->getErrorNum()) { 132 echo $database->stderr(); 133 return false; 134 } 135 136 // get list of Positions for dropdown filter 137 // @RawSQLUse, trivial_implementation, SELECT 138 $query = "SELECT folder AS value, folder AS text" 139 . "\n FROM #__mambots" 140 . "\n WHERE client_id = '$client_id'" 141 . "\n GROUP BY folder" 142 . "\n ORDER BY folder" 143 ; 144 $types[] = mosHTML::makeOption( '0', T_('- All Types -') ); 145 $database->setQuery( $query ); 146 $types = array_merge( $types, $database->loadObjectList() ); 147 $lists['type'] = mosHTML::selectList( $types, 'filter_type', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', "$filter_type" ); 148 149 HTML_modules::showMambots( $rows, $client, $pageNav, $option, $lists, $search ); 150 } 151 152 /** 153 * Saves the module after an edit form submit 154 */ 155 function saveMambot( $option, $client, $task ) { 156 global $database; 157 158 $params = mosGetParam( $_POST, 'params', '' ); 159 if (is_array( $params )) { 160 $txt = array(); 161 foreach ($params as $k=>$v) { 162 $txt[] = "$k=$v"; 163 } 164 165 $_POST['params'] = mosParameters::textareaHandling( $txt ); 166 } 167 168 $row = new mosMambot( $database ); 169 if (!$row->bind( $_POST )) { 170 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 171 exit(); 172 } 173 if (!$row->check()) { 174 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 175 exit(); 176 } 177 if (!$row->store()) { 178 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 179 exit(); 180 } 181 $row->checkin(); 182 if ($client == 'admin') { 183 $where = "client_id='1'"; 184 } else { 185 $where = "client_id='0'"; 186 } 187 $row->updateOrder( "folder='$row->folder' AND ordering > -10000 AND ordering < 10000 AND ($where)" ); 188 189 switch ( $task ) { 190 case 'apply': 191 $msg = sprintf(T_('Successfully Saved changes to Mambot: %s'), $row->name); 192 mosRedirect( 'index2.php?option='. $option .'&client='. $client .'&task=editA&hidemainmenu=1&id='. $row->id, $msg ); 193 194 case 'save': 195 default: 196 $msg = sprintf(T_('Successfully Saved Mambot: %s'), $row->name); 197 mosRedirect( 'index2.php?option='. $option .'&client='. $client, $msg ); 198 break; 199 } 200 } 201 202 /** 203 * Compiles information to add or edit a module 204 * @param string The current GET/POST option 205 * @param integer The unique id of the record to edit 206 */ 207 function editMambot( $option, $uid, $client ) { 208 global $database, $my, $mainframe; 209 global $mosConfig_absolute_path; 210 211 $lists = array(); 212 $row = new mosMambot($database); 213 214 // load the row from the db table 215 $row->load( $uid ); 216 217 // fail if checked out not by 'me' 218 if ($row->checked_out && $row->checked_out <> $my->id) { 219 echo "<script>alert(".sprintf(T_('The module %s is currently being edited by another administrator'), $row->title)."); document.location.href='index2.php?option=$option'</script>\n"; 220 exit(0); 221 } 222 223 if ($client == 'admin') { 224 $where = "client_id='1'"; 225 } else { 226 $where = "client_id='0'"; 227 } 228 229 // get list of groups 230 if ($row->access == 99 || $row->client_id == 1) { 231 $lists['access'] = T_('Administrator').'<input type="hidden" name="access" value="99" />'; 232 } else { 233 // build the html select list for the group access 234 $lists['access'] = mosAdminMenus::Access( $row ); 235 } 236 237 if ($uid) { 238 $row->checkout( $my->id ); 239 240 if ( $row->ordering > -10000 && $row->ordering < 10000 ) { 241 // build the html select list for ordering 242 $query = "SELECT ordering AS value, name AS text" 243 . "\n FROM #__mambots" 244 . "\n WHERE folder='$row->folder'" 245 . "\n AND published > 0" 246 . "\n AND $where" 247 . "\n AND ordering > -10000" 248 . "\n AND ordering < 10000" 249 . "\n ORDER BY ordering" 250 ; 251 $order = mosGetOrderingList( $query ); 252 $lists['ordering'] = mosHTML::selectList( $order, 'ordering', 'class="inputbox" size="1"', 'value', 'text', intval( $row->ordering ) ); 253 } else { 254 $lists['ordering'] = '<input type="hidden" name="ordering" value="'. $row->ordering .'" />'.T_('This mambot cannot be reordered'); 255 } 256 $lists['folder'] = '<input type="hidden" name="folder" value="'. $row->folder .'" />'. $row->folder; 257 258 // xml file for module 259 $xmlfile = $mosConfig_absolute_path . '/mambots/' .$row->folder . '/' . $row->element .'.xml'; 260 $xmlparser =& new mosXMLDescription ($xmlfile); 261 $row->description = T_($xmlparser->getDescription('mambot')); 262 } else { 263 $row->folder = ''; 264 $row->ordering = 999; 265 $row->published = 1; 266 $row->description = ''; 267 268 $folders = mosReadDirectory( $mosConfig_absolute_path . '/mambots/' ); 269 $folders2 = array(); 270 foreach ($folders as $folder) { 271 if (is_dir( $mosConfig_absolute_path . '/mambots/' . $folder ) && ( $folder <> 'CVS' ) ) { 272 $folders2[] = mosHTML::makeOption( $folder ); 273 } 274 } 275 $lists['folder'] = mosHTML::selectList( $folders2, 'folder', 'class="inputbox" size="1"', 'value', 'text', null ); 276 $lists['ordering'] = '<input type="hidden" name="ordering" value="'. $row->ordering .'" />'.T_('New items default to the last place. Ordering can be changed after this item is saved.').''; 277 } 278 279 $lists['published'] = mosHTML::yesnoRadioList( 'published', 'class="inputbox"', $row->published ); 280 281 // get params definitions 282 $params =& new mosAdminParameters( $row->params, $mainframe->getPath( 'bot_xml', $row->folder.'/'.$row->element ), 'mambot' ); 283 284 HTML_modules::editMambot( $row, $lists, $params, $option ); 285 } 286 287 /** 288 * Deletes one or more mambots 289 * 290 * Also deletes associated entries in the #__mambots table. 291 * @param array An array of unique category id numbers 292 */ 293 function removeMambot( &$cid, $option, $client ) { 294 global $database, $my; 295 296 if (count( $cid ) < 1) { 297 echo "<script> alert(".T_('Select a module to delete')."); window.history.go(-1);</script>\n"; 298 exit; 299 } 300 301 mosRedirect( 'index2.php?option=com_installer&element=mambot&client='. $client .'&task=remove&cid[]='. $cid[0] ); 302 } 303 304 /** 305 * Publishes or Unpublishes one or more modules 306 * @param array An array of unique category id numbers 307 * @param integer 0 if unpublishing, 1 if publishing 308 */ 309 function publishMambot( $cid=null, $publish=1, $option, $client ) { 310 global $database, $my; 311 312 if (count( $cid ) < 1) { 313 $action = $publish ? T_('publish') : T_('unpublish'); 314 echo "<script> alert(".sprintf(T_('Select a mambot to %s'), $action)."); window.history.go(-1);</script>\n"; 315 exit; 316 } 317 318 $cids = implode( ',', $cid ); 319 320 $query = "UPDATE #__mambots SET published='$publish'" 321 . "\n WHERE id IN ($cids)" 322 . "\n AND (checked_out=0 OR (checked_out='$my->id'))" 323 ; 324 $database->setQuery( $query ); 325 if (!$database->query()) { 326 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 327 exit(); 328 } 329 330 if (count( $cid ) == 1) { 331 $row = new mosMambot( $database ); 332 $row->checkin( $cid[0] ); 333 } 334 335 mosRedirect( 'index2.php?option='. $option .'&client='. $client ); 336 } 337 338 /** 339 * Cancels an edit operation 340 */ 341 function cancelMambot( $option, $client ) { 342 global $database; 343 344 $row = new mosMambot( $database ); 345 $row->bind( $_POST ); 346 // sanitize 347 $row->id = intval($row->id); 348 $row->checkin(); 349 350 mosRedirect( 'index2.php?option='. $option .'&client='. $client ); 351 } 352 353 /** 354 * Moves the order of a record 355 * @param integer The unique id of record 356 * @param integer The increment to reorder by 357 */ 358 function orderMambot( $uid, $inc, $option, $client ) { 359 global $database; 360 361 // Currently Unsupported 362 if ($client == 'admin') { 363 $where = "client_id='1'"; 364 } else { 365 $where = "client_id='0'"; 366 } 367 $row = new mosMambot( $database ); 368 $row->load( $uid ); 369 $row->move( $inc, "folder='$row->folder' AND ordering > -10000 AND ordering < 10000 AND ($where)" ); 370 371 mosRedirect( 'index2.php?option='. $option ); 372 } 373 374 /** 375 * changes the access level of a record 376 * @param integer The increment to reorder by 377 */ 378 function accessMenu( $uid, $access, $option, $client ) { 379 global $database; 380 381 switch ( $access ) { 382 case 'accesspublic': 383 $access = 0; 384 break; 385 386 case 'accessregistered': 387 $access = 1; 388 break; 389 390 case 'accessspecial': 391 $access = 2; 392 break; 393 } 394 395 $row = new mosMambot( $database ); 396 $row->load( $uid ); 397 $row->access = $access; 398 399 if ( !$row->check() ) { 400 return $row->getError(); 401 } 402 if ( !$row->store() ) { 403 return $row->getError(); 404 } 405 406 mosRedirect( 'index2.php?option='. $option ); 407 } 408 409 function saveOrder( &$cid ) { 410 global $database; 411 $order = mosGetParam( $_POST, 'order', array(0) ); 412 $row = new mosMambot( $database ); 413 $folders = array(); 414 // update ordering values 415 foreach ($cid as $i=>$ciditem) { 416 $row->load( $ciditem ); 417 if ($row->ordering != $order[$i]) { 418 $row->ordering = $order[$i]; 419 if (!$row->store()) { 420 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 421 exit(); 422 } 423 // remember to updateOrder this group 424 $folders[$row->folder][$row->client_id] = $row->id; 425 } 426 } 427 // execute updateOrder for each group 428 foreach ($folders as $folder=>$clients) { 429 foreach ($clients as $client=>$rowid) { 430 $row->updateOrder("folder = '$folder' AND ordering > -10000 AND ordering < 10000 AND client_id = '$client'"); 431 } 432 } // foreach 433 434 $msg = T_('New ordering saved'); 435 mosRedirect( 'index2.php?option=com_mambots', $msg ); 436 } // saveOrder 437 438 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Feb 8 00:05:01 2012 | Cross-referenced by PHPXref 0.7 |
| Mambo API: Mambo is Free software released under the GNU/General Public License, Version 2 |