Annotation of /mambo/branches/4.6/administrator/components/com_modules/admin.modules.php
Parent Directory
|
Revision Log
Revision 129 - (view) (download)
| 1 : | root | 1 | <?php |
| 2 : | /** | ||
| 3 : | * @version $Id: admin.modules.php,v 1.1 2005/07/22 01:53:20 eddieajau Exp $ | ||
| 4 : | * @package Mambo | ||
| 5 : | * @subpackage Modules | ||
| 6 : | * @copyright (C) 2000 - 2005 Miro International Pty Ltd | ||
| 7 : | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL | ||
| 8 : | * Mambo is Free Software | ||
| 9 : | */ | ||
| 10 : | |||
| 11 : | /** ensure this file is being included by a parent file */ | ||
| 12 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 13 : | |||
| 14 : | // ensure user has access to this function | ||
| 15 : | if (!($acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'modules', 'all' ) | $acl->acl_check( 'administration', 'install', 'users', $my->usertype, 'modules', 'all' ))) { | ||
| 16 : | mosRedirect( 'index2.php', _NOT_AUTH ); | ||
| 17 : | } | ||
| 18 : | |||
| 19 : | require_once( $mainframe->getPath( 'admin_html' ) ); | ||
| 20 : | |||
| 21 : | $client = mosGetParam( $_REQUEST, 'client', '' ); | ||
| 22 : | $cid = mosGetParam( $_POST, 'cid', array(0) ); | ||
| 23 : | $moduleid = mosGetParam( $_REQUEST, 'moduleid', null ); | ||
| 24 : | if ($cid[0] == 0 && isset($moduleid) ) { | ||
| 25 : | $cid[0] = $moduleid; | ||
| 26 : | } | ||
| 27 : | |||
| 28 : | switch ( $task ) { | ||
| 29 : | case 'copy': | ||
| 30 : | copyModule( $option, intval( $cid[0] ), $client ); | ||
| 31 : | break; | ||
| 32 : | |||
| 33 : | case 'new': | ||
| 34 : | editModule( $option, 0, $client ); | ||
| 35 : | break; | ||
| 36 : | |||
| 37 : | case 'edit': | ||
| 38 : | editModule( $option, $cid[0], $client ); | ||
| 39 : | break; | ||
| 40 : | |||
| 41 : | case 'editA': | ||
| 42 : | editModule( $option, $id, $client ); | ||
| 43 : | break; | ||
| 44 : | |||
| 45 : | case 'save': | ||
| 46 : | case 'apply': | ||
| 47 : | mosCache::cleanCache( 'com_content' ); | ||
| 48 : | saveModule( $option, $client, $task ); | ||
| 49 : | break; | ||
| 50 : | |||
| 51 : | case 'remove': | ||
| 52 : | removeModule( $cid, $option, $client ); | ||
| 53 : | break; | ||
| 54 : | |||
| 55 : | case 'cancel': | ||
| 56 : | cancelModule( $option, $client ); | ||
| 57 : | break; | ||
| 58 : | |||
| 59 : | case 'publish': | ||
| 60 : | case 'unpublish': | ||
| 61 : | mosCache::cleanCache( 'com_content' ); | ||
| 62 : | publishModule( $cid, ($task == 'publish'), $option, $client ); | ||
| 63 : | break; | ||
| 64 : | |||
| 65 : | case 'orderup': | ||
| 66 : | case 'orderdown': | ||
| 67 : | orderModule( $cid[0], ($task == 'orderup' ? -1 : 1), $option, $client ); | ||
| 68 : | break; | ||
| 69 : | |||
| 70 : | case 'accesspublic': | ||
| 71 : | case 'accessregistered': | ||
| 72 : | case 'accessspecial': | ||
| 73 : | accessMenu( $cid[0], $task, $option, $client ); | ||
| 74 : | break; | ||
| 75 : | |||
| 76 : | case 'saveorder': | ||
| 77 : | saveOrder( $cid, $client ); | ||
| 78 : | break; | ||
| 79 : | |||
| 80 : | default: | ||
| 81 : | viewModules( $option, $client ); | ||
| 82 : | break; | ||
| 83 : | } | ||
| 84 : | |||
| 85 : | /** | ||
| 86 : | * Compiles a list of installed or defined modules | ||
| 87 : | */ | ||
| 88 : | function viewModules( $option, $client ) { | ||
| 89 : | global $database, $my, $mainframe, $mosConfig_list_limit, $mosConfig_absolute_path; | ||
| 90 : | |||
| 91 : | $filter_position = $mainframe->getUserStateFromRequest( "filter_position{$option}{$client}", 'filter_position', 0 ); | ||
| 92 : | $filter_type = $mainframe->getUserStateFromRequest( "filter_type{$option}{$client}", 'filter_type', 0 ); | ||
| 93 : | $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ); | ||
| 94 : | $limitstart = $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 ); | ||
| 95 : | $search = $mainframe->getUserStateFromRequest( "search{$option}{$client}", 'search', '' ); | ||
| 96 : | $search = $database->getEscaped( trim( strtolower( $search ) ) ); | ||
| 97 : | |||
| 98 : | if ($client == 'admin') { | ||
| 99 : | $where[] = "m.client_id = '1'"; | ||
| 100 : | $client_id = 1; | ||
| 101 : | } else { | ||
| 102 : | $where[] = "m.client_id = '0'"; | ||
| 103 : | $client_id = 0; | ||
| 104 : | } | ||
| 105 : | |||
| 106 : | // used by filter | ||
| 107 : | if ( $filter_position ) { | ||
| 108 : | $where[] = "m.position = '$filter_position'"; | ||
| 109 : | } | ||
| 110 : | if ( $filter_type ) { | ||
| 111 : | $where[] = "m.module = '$filter_type'"; | ||
| 112 : | } | ||
| 113 : | if ( $search ) { | ||
| 114 : | $where[] = "LOWER( m.title ) LIKE '%$search%'"; | ||
| 115 : | } | ||
| 116 : | |||
| 117 : | // get the total number of records | ||
| 118 : | $query = "SELECT COUNT(*) FROM #__modules AS m ". ( count( $where ) ? "\n WHERE " . implode( ' AND ', $where ) : '' ); | ||
| 119 : | $database->setQuery( $query ); | ||
| 120 : | $total = $database->loadResult(); | ||
| 121 : | |||
| 122 : | require_once( $mosConfig_absolute_path . '/administrator/includes/pageNavigation.php' ); | ||
| 123 : | $pageNav = new mosPageNav( $total, $limitstart, $limit ); | ||
| 124 : | |||
| 125 : | $database->setQuery( "SELECT m.*, u.name AS editor, g.name AS groupname, MIN(mm.menuid) AS pages" | ||
| 126 : | . "\n FROM #__modules AS m" | ||
| 127 : | . "\n LEFT JOIN #__users AS u ON u.id = m.checked_out" | ||
| 128 : | . "\n LEFT JOIN #__groups AS g ON g.id = m.access" | ||
| 129 : | . "\n LEFT JOIN #__modules_menu AS mm ON mm.moduleid=m.id" | ||
| 130 : | . ( count( $where ) ? "\n WHERE " . implode( ' AND ', $where ) : '' ) | ||
| 131 : | . "\n GROUP BY m.id" | ||
| 132 : | . "\n ORDER BY position ASC, ordering ASC" | ||
| 133 : | . "\n LIMIT $pageNav->limitstart,$pageNav->limit" | ||
| 134 : | ); | ||
| 135 : | $rows = $database->loadObjectList(); | ||
| 136 : | if ($database->getErrorNum()) { | ||
| 137 : | echo $database->stderr(); | ||
| 138 : | return false; | ||
| 139 : | } | ||
| 140 : | |||
| 141 : | // get list of Positions for dropdown filter | ||
| 142 : | $query = "SELECT t.position AS value, t.position AS text" | ||
| 143 : | . "\n FROM #__template_positions as t" | ||
| 144 : | . "\n LEFT JOIN #__modules AS m ON m.position = t.position" | ||
| 145 : | . "\n WHERE m.client_id = '$client_id'" | ||
| 146 : | . "\n GROUP BY t.position" | ||
| 147 : | . "\n ORDER BY t.position" | ||
| 148 : | ; | ||
| 149 : | $positions[] = mosHTML::makeOption( '0', _SEL_POSITION ); | ||
| 150 : | $database->setQuery( $query ); | ||
| 151 : | $positions = array_merge( $positions, $database->loadObjectList() ); | ||
| 152 : | $lists['position'] = mosHTML::selectList( $positions, 'filter_position', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', "$filter_position" ); | ||
| 153 : | |||
| 154 : | // get list of Positions for dropdown filter | ||
| 155 : | $query = "SELECT module AS value, module AS text" | ||
| 156 : | . "\n FROM #__modules" | ||
| 157 : | . "\n WHERE client_id = '$client_id'" | ||
| 158 : | . "\n GROUP BY module" | ||
| 159 : | . "\n ORDER BY module" | ||
| 160 : | ; | ||
| 161 : | $types[] = mosHTML::makeOption( '0', _SEL_TYPE ); | ||
| 162 : | $database->setQuery( $query ); | ||
| 163 : | $types = array_merge( $types, $database->loadObjectList() ); | ||
| 164 : | $lists['type'] = mosHTML::selectList( $types, 'filter_type', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', "$filter_type" ); | ||
| 165 : | |||
| 166 : | HTML_modules::showModules( $rows, $my->id, $client, $pageNav, $option, $lists, $search ); | ||
| 167 : | } | ||
| 168 : | |||
| 169 : | /** | ||
| 170 : | * Compiles information to add or edit a module | ||
| 171 : | * @param string The current GET/POST option | ||
| 172 : | * @param integer The unique id of the record to edit | ||
| 173 : | */ | ||
| 174 : | function copyModule( $option, $uid, $client ) { | ||
| 175 : | global $database, $my; | ||
| 176 : | |||
| 177 : | $row = new mosModule( $database ); | ||
| 178 : | // load the row from the db table | ||
| 179 : | $row->load( $uid ); | ||
| 180 : | $row->title = 'Copy of '.$row->title; | ||
| 181 : | $row->id = 0; | ||
| 182 : | $row->iscore = 0; | ||
| 183 : | $row->published = 0; | ||
| 184 : | |||
| 185 : | if (!$row->check()) { | ||
| 186 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 187 : | exit(); | ||
| 188 : | } | ||
| 189 : | if (!$row->store()) { | ||
| 190 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 191 : | exit(); | ||
| 192 : | } | ||
| 193 : | $row->checkin(); | ||
| 194 : | if ($client == 'admin') { | ||
| 195 : | $where = "client_id='1'"; | ||
| 196 : | } else { | ||
| 197 : | $where = "client_id='0'"; | ||
| 198 : | } | ||
| 199 : | $row->updateOrder( "position='$row->position' AND ($where)" ); | ||
| 200 : | |||
| 201 : | $database->setQuery( "SELECT menuid FROM #__modules_menu WHERE moduleid='$uid'" ); | ||
| 202 : | $rows = $database->loadResultArray(); | ||
| 203 : | |||
| 204 : | foreach($rows as $menuid) { | ||
| 205 : | $database->setQuery( "INSERT INTO #__modules_menu" | ||
| 206 : | . "\nSET moduleid='$row->id', menuid='$menuid'" | ||
| 207 : | ); | ||
| 208 : | $database->query(); | ||
| 209 : | } | ||
| 210 : | |||
| 211 : | $msg = 'Module Copied ['. $row->title .']'; | ||
| 212 : | mosRedirect( 'index2.php?option='. $option .'&client='. $client, $msg ); | ||
| 213 : | } | ||
| 214 : | |||
| 215 : | /** | ||
| 216 : | * Saves the module after an edit form submit | ||
| 217 : | */ | ||
| 218 : | function saveModule( $option, $client, $task ) { | ||
| 219 : | global $database; | ||
| 220 : | |||
| 221 : | $params = mosGetParam( $_POST, 'params', '' ); | ||
| 222 : | if (is_array( $params )) { | ||
| 223 : | $txt = array(); | ||
| 224 : | foreach ($params as $k=>$v) { | ||
| 225 : | $txt[] = "$k=$v"; | ||
| 226 : | } | ||
| 227 : | $_POST['params'] = mosParameters::textareaHandling( $txt ); | ||
| 228 : | } | ||
| 229 : | |||
| 230 : | $row = new mosModule( $database ); | ||
| 231 : | if (!$row->bind( $_POST, 'selections' )) { | ||
| 232 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 233 : | exit(); | ||
| 234 : | } | ||
| 235 : | if (!$row->check()) { | ||
| 236 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 237 : | exit(); | ||
| 238 : | } | ||
| 239 : | if (!$row->store()) { | ||
| 240 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 241 : | exit(); | ||
| 242 : | } | ||
| 243 : | $row->checkin(); | ||
| 244 : | if ($client == 'admin') { | ||
| 245 : | $where = "client_id='1'"; | ||
| 246 : | } else { | ||
| 247 : | $where = "client_id='0'"; | ||
| 248 : | } | ||
| 249 : | $row->updateOrder( "position='$row->position' AND ($where)" ); | ||
| 250 : | |||
| 251 : | $menus = mosGetParam( $_POST, 'selections', array() ); | ||
| 252 : | |||
| 253 : | $database->setQuery( "DELETE FROM #__modules_menu WHERE moduleid='$row->id'" ); | ||
| 254 : | $database->query(); | ||
| 255 : | |||
| 256 : | foreach ($menus as $menuid){ | ||
| 257 : | // this check for the blank spaces in the select box that have been added for cosmetic reasons | ||
| 258 : | if ( $menuid <> "-999" ) { | ||
| 259 : | $query = "INSERT INTO #__modules_menu SET moduleid='$row->id', menuid='$menuid'"; | ||
| 260 : | $database->setQuery( $query ); | ||
| 261 : | $database->query(); | ||
| 262 : | } | ||
| 263 : | } | ||
| 264 : | |||
| 265 : | |||
| 266 : | switch ( $task ) { | ||
| 267 : | case 'apply': | ||
| 268 : | $msg = 'Successfully Saved changes to Module: '. $row->title; | ||
| 269 : | mosRedirect( 'index2.php?option='. $option .'&client='. $client .'&task=editA&hidemainmenu=1&id='. $row->id, $msg ); | ||
| 270 : | break; | ||
| 271 : | |||
| 272 : | case 'save': | ||
| 273 : | default: | ||
| 274 : | $msg = 'Successfully Saved Module: '. $row->title; | ||
| 275 : | mosRedirect( 'index2.php?option='. $option .'&client='. $client, $msg ); | ||
| 276 : | break; | ||
| 277 : | } | ||
| 278 : | } | ||
| 279 : | |||
| 280 : | /** | ||
| 281 : | * Compiles information to add or edit a module | ||
| 282 : | * @param string The current GET/POST option | ||
| 283 : | * @param integer The unique id of the record to edit | ||
| 284 : | */ | ||
| 285 : | function editModule( $option, $uid, $client ) { | ||
| 286 : | global $database, $my, $mainframe; | ||
| 287 : | global $mosConfig_absolute_path; | ||
| 288 : | |||
| 289 : | $lists = array(); | ||
| 290 : | $row = new mosModule( $database ); | ||
| 291 : | // load the row from the db table | ||
| 292 : | $row->load( $uid ); | ||
| 293 : | // fail if checked out not by 'me' | ||
| 294 : | if ( $row->checked_out && $row->checked_out <> $my->id ) { | ||
| 295 : | echo "<script>alert('The module $row->title is currently being edited by another administrator'); document.location.href='index2.php?option=$option'</script>\n"; | ||
| 296 : | exit(0); | ||
| 297 : | } | ||
| 298 : | |||
| 299 : | $row->content = htmlspecialchars( str_replace( '&', '&', $row->content ) ); | ||
| 300 : | |||
| 301 : | if ( $uid ) { | ||
| 302 : | $row->checkout( $my->id ); | ||
| 303 : | } | ||
| 304 : | // if a new record we must still prime the mosModule object with a default | ||
| 305 : | // position and the order; also add an extra item to the order list to | ||
| 306 : | // place the 'new' record in last position if desired | ||
| 307 : | if ($uid == 0) { | ||
| 308 : | $row->position = 'left'; | ||
| 309 : | $row->showtitle = true; | ||
| 310 : | //$row->ordering = $l; | ||
| 311 : | $row->published = 1; | ||
| 312 : | } | ||
| 313 : | |||
| 314 : | |||
| 315 : | if ( $client == 'admin' ) { | ||
| 316 : | $where = "client_id='1'"; | ||
| 317 : | $lists['client_id'] = 1; | ||
| 318 : | $path = 'mod1_xml'; | ||
| 319 : | } else { | ||
| 320 : | $where = "client_id='0'"; | ||
| 321 : | $lists['client_id'] = 0; | ||
| 322 : | $path = 'mod0_xml'; | ||
| 323 : | } | ||
| 324 : | $query = "SELECT position, ordering, showtitle, title" | ||
| 325 : | . "\n FROM #__modules" | ||
| 326 : | . "\n WHERE ". $where | ||
| 327 : | . "\n ORDER BY ordering" | ||
| 328 : | ; | ||
| 329 : | $database->setQuery( $query ); | ||
| 330 : | if ( !($orders = $database->loadObjectList()) ) { | ||
| 331 : | echo $database->stderr(); | ||
| 332 : | return false; | ||
| 333 : | } | ||
| 334 : | |||
| 335 : | $query = "SELECT position, description" | ||
| 336 : | . "\n FROM #__template_positions" | ||
| 337 : | . "\n WHERE position <> ''" | ||
| 338 : | ; | ||
| 339 : | $database->setQuery( $query ); | ||
| 340 : | // hard code options for now | ||
| 341 : | $positions = $database->loadObjectList(); | ||
| 342 : | |||
| 343 : | $orders2 = array(); | ||
| 344 : | $pos = array(); | ||
| 345 : | foreach ($positions as $position) { | ||
| 346 : | $orders2[$position->position] = array(); | ||
| 347 : | $pos[] = mosHTML::makeOption( $position->position, $position->description ); | ||
| 348 : | } | ||
| 349 : | |||
| 350 : | $l = 0; | ||
| 351 : | $r = 0; | ||
| 352 : | for ($i=0, $n=count( $orders ); $i < $n; $i++) { | ||
| 353 : | $ord = 0; | ||
| 354 : | if (array_key_exists( $orders[$i]->position, $orders2 )) { | ||
| 355 : | $ord =count( array_keys( $orders2[$orders[$i]->position] ) ) + 1; | ||
| 356 : | } | ||
| 357 : | |||
| 358 : | $orders2[$orders[$i]->position][] = mosHTML::makeOption( $ord, $ord.'::'.addslashes( $orders[$i]->title ) ); | ||
| 359 : | } | ||
| 360 : | |||
| 361 : | // build the html select list | ||
| 362 : | $pos_select = 'onchange="changeDynaList(\'ordering\',orders,document.adminForm.position.options[document.adminForm.position.selectedIndex].value, originalPos, originalOrder)"'; | ||
| 363 : | $active = ( $row->position ? $row->position : 'left' ); | ||
| 364 : | $lists['position'] = mosHTML::selectList( $pos, 'position', 'class="inputbox" size="1" '. $pos_select, 'value', 'text', $active ); | ||
| 365 : | |||
| 366 : | // get selected pages for $lists['selections'] | ||
| 367 : | if ( $uid ) { | ||
| 368 : | $query = 'SELECT menuid AS value FROM #__modules_menu WHERE moduleid='. $row->id; | ||
| 369 : | $database->setQuery( $query ); | ||
| 370 : | $lookup = $database->loadObjectList(); | ||
| 371 : | } else { | ||
| 372 : | $lookup = array( mosHTML::makeOption( 0, 'All' ) ); | ||
| 373 : | } | ||
| 374 : | |||
| 375 : | if ( $row->access == 99 || $row->client_id == 1 || $lists['client_id'] ) { | ||
| 376 : | $lists['access'] = 'Administrator<input type="hidden" name="access" value="99" />'; | ||
| 377 : | $lists['showtitle'] = 'N/A <input type="hidden" name="showtitle" value="1" />'; | ||
| 378 : | $lists['selections'] = 'N/A'; | ||
| 379 : | } else { | ||
| 380 : | if ( $client == 'admin' ) { | ||
| 381 : | $lists['access'] = 'N/A'; | ||
| 382 : | $lists['selections'] = 'N/A'; | ||
| 383 : | } else { | ||
| 384 : | $lists['access'] = mosAdminMenus::Access( $row ); | ||
| 385 : | $lists['selections'] = mosAdminMenus::MenuLinks( $lookup, 1, 1 ); | ||
| 386 : | } | ||
| 387 : | $lists['showtitle'] = mosHTML::yesnoRadioList( 'showtitle', 'class="inputbox"', $row->showtitle ); | ||
| 388 : | } | ||
| 389 : | |||
| 390 : | // build the html select list for published | ||
| 391 : | $lists['published'] = mosAdminMenus::Published( $row ); | ||
| 392 : | |||
| 393 : | // xml file for module | ||
| 394 : | $xmlfile = $mainframe->getPath( $path, $row->module ); | ||
| 395 : | csouza | 129 | $xmlparser =& new mosXMLDescription ($xmlfile); |
| 396 : | $row->description = $xmlparser->getDescription('module'); | ||
| 397 : | root | 1 | |
| 398 : | // get params definitions | ||
| 399 : | $params =& new mosParameters( $row->params, $xmlfile, 'module' ); | ||
| 400 : | |||
| 401 : | HTML_modules::editModule( $row, $orders2, $lists, $params, $option ); | ||
| 402 : | } | ||
| 403 : | |||
| 404 : | /** | ||
| 405 : | * Deletes one or more modules | ||
| 406 : | * | ||
| 407 : | * Also deletes associated entries in the #__module_menu table. | ||
| 408 : | * @param array An array of unique category id numbers | ||
| 409 : | */ | ||
| 410 : | function removeModule( &$cid, $option, $client ) { | ||
| 411 : | global $database, $my; | ||
| 412 : | |||
| 413 : | if (count( $cid ) < 1) { | ||
| 414 : | echo "<script> alert('Select a module to delete'); window.history.go(-1);</script>\n"; | ||
| 415 : | exit; | ||
| 416 : | } | ||
| 417 : | |||
| 418 : | $cids = implode( ',', $cid ); | ||
| 419 : | |||
| 420 : | $database->setQuery( "SELECT id, module, title, iscore, params FROM #__modules WHERE id IN ($cids)" ); | ||
| 421 : | if (!($rows = $database->loadObjectList())) { | ||
| 422 : | echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 423 : | exit; | ||
| 424 : | } | ||
| 425 : | |||
| 426 : | $err = array(); | ||
| 427 : | $cid = array(); | ||
| 428 : | foreach ($rows as $row) { | ||
| 429 : | if ($row->module == '' || $row->iscore == 0) { | ||
| 430 : | $cid[] = $row->id; | ||
| 431 : | } else { | ||
| 432 : | $err[] = $row->title; | ||
| 433 : | } | ||
| 434 : | // mod_mainmenu modules only deletable via Menu Manager | ||
| 435 : | if ( $row->module == 'mod_mainmenu' ) { | ||
| 436 : | if ( strstr( $row->params, 'mainmenu' ) ) { | ||
| 437 : | echo "<script> alert('You cannot delete mod_mainmenu module that displays the \'mainmenu\' as it is a core Menu'); window.history.go(-1); </script>\n"; | ||
| 438 : | exit; | ||
| 439 : | } | ||
| 440 : | } | ||
| 441 : | } | ||
| 442 : | |||
| 443 : | if (count( $cid )) { | ||
| 444 : | $cids = implode( ',', $cid ); | ||
| 445 : | $database->setQuery( "DELETE FROM #__modules WHERE id IN ($cids)" ); | ||
| 446 : | if (!$database->query()) { | ||
| 447 : | echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 448 : | exit; | ||
| 449 : | } | ||
| 450 : | $database->setQuery( "DELETE from #__modules_menu WHERE moduleid IN ($cids)" ); | ||
| 451 : | if (!$database->query()) { | ||
| 452 : | echo "<script> alert('".$database->getErrorMsg()."');</script>\n"; | ||
| 453 : | exit; | ||
| 454 : | } | ||
| 455 : | $mod = new mosModule( $database ); | ||
| 456 : | $mod->ordering = 0; | ||
| 457 : | $mod->updateOrder( "position='left'" ); | ||
| 458 : | $mod->updateOrder( "position='right'" ); | ||
| 459 : | } | ||
| 460 : | |||
| 461 : | if (count( $err )) { | ||
| 462 : | $cids = addslashes( implode( "', '", $err ) ); | ||
| 463 : | echo "<script>alert('Module(s): \'$cids\' cannot be deleted they can only be un-installed as they are Mambo modules.');</script>\n"; | ||
| 464 : | } | ||
| 465 : | |||
| 466 : | mosRedirect( 'index2.php?option='. $option .'&client='. $client ); | ||
| 467 : | } | ||
| 468 : | |||
| 469 : | /** | ||
| 470 : | * Publishes or Unpublishes one or more modules | ||
| 471 : | * @param array An array of unique record id numbers | ||
| 472 : | * @param integer 0 if unpublishing, 1 if publishing | ||
| 473 : | */ | ||
| 474 : | function publishModule( $cid=null, $publish=1, $option, $client ) { | ||
| 475 : | global $database, $my; | ||
| 476 : | |||
| 477 : | if (count( $cid ) < 1) { | ||
| 478 : | $action = $publish ? 'publish' : 'unpublish'; | ||
| 479 : | echo "<script> alert('Select a module to $action'); window.history.go(-1);</script>\n"; | ||
| 480 : | exit; | ||
| 481 : | } | ||
| 482 : | |||
| 483 : | $cids = implode( ',', $cid ); | ||
| 484 : | |||
| 485 : | $query = "UPDATE #__modules SET published='$publish'" | ||
| 486 : | . "\n WHERE id IN ($cids)" | ||
| 487 : | . "\n AND (checked_out=0 OR (checked_out='$my->id'))" | ||
| 488 : | ; | ||
| 489 : | $database->setQuery( $query ); | ||
| 490 : | if (!$database->query()) { | ||
| 491 : | echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 492 : | exit(); | ||
| 493 : | } | ||
| 494 : | |||
| 495 : | if (count( $cid ) == 1) { | ||
| 496 : | $row = new mosModule( $database ); | ||
| 497 : | $row->checkin( $cid[0] ); | ||
| 498 : | } | ||
| 499 : | |||
| 500 : | mosRedirect( 'index2.php?option='. $option .'&client='. $client ); | ||
| 501 : | } | ||
| 502 : | |||
| 503 : | /** | ||
| 504 : | * Cancels an edit operation | ||
| 505 : | */ | ||
| 506 : | function cancelModule( $option, $client ) { | ||
| 507 : | global $database; | ||
| 508 : | |||
| 509 : | $row = new mosModule( $database ); | ||
| 510 : | // ignore array elements | ||
| 511 : | $row->bind( $_POST, 'selections params' ); | ||
| 512 : | $row->checkin(); | ||
| 513 : | |||
| 514 : | mosRedirect( 'index2.php?option='. $option .'&client='. $client ); | ||
| 515 : | } | ||
| 516 : | |||
| 517 : | /** | ||
| 518 : | * Moves the order of a record | ||
| 519 : | * @param integer The unique id of record | ||
| 520 : | * @param integer The increment to reorder by | ||
| 521 : | */ | ||
| 522 : | function orderModule( $uid, $inc, $option ) { | ||
| 523 : | global $database; | ||
| 524 : | |||
| 525 : | $client = mosGetParam( $_POST, 'client', '' ); | ||
| 526 : | |||
| 527 : | $row = new mosModule( $database ); | ||
| 528 : | $row->load( $uid ); | ||
| 529 : | if ($client == 'admin') { | ||
| 530 : | $where = "client_id='1'"; | ||
| 531 : | } else { | ||
| 532 : | $where = "client_id='0'"; | ||
| 533 : | } | ||
| 534 : | |||
| 535 : | $row->move( $inc, "position='$row->position' AND ($where)" ); | ||
| 536 : | if ( $client ) { | ||
| 537 : | $client = '&client=admin' ; | ||
| 538 : | } else { | ||
| 539 : | $client = ''; | ||
| 540 : | } | ||
| 541 : | |||
| 542 : | mosRedirect( 'index2.php?option='. $option .'&client='. $client ); | ||
| 543 : | } | ||
| 544 : | |||
| 545 : | /** | ||
| 546 : | * changes the access level of a record | ||
| 547 : | * @param integer The increment to reorder by | ||
| 548 : | */ | ||
| 549 : | function accessMenu( $uid, $access, $option, $client ) { | ||
| 550 : | global $database; | ||
| 551 : | |||
| 552 : | switch ( $access ) { | ||
| 553 : | case 'accesspublic': | ||
| 554 : | $access = 0; | ||
| 555 : | break; | ||
| 556 : | |||
| 557 : | case 'accessregistered': | ||
| 558 : | $access = 1; | ||
| 559 : | break; | ||
| 560 : | |||
| 561 : | case 'accessspecial': | ||
| 562 : | $access = 2; | ||
| 563 : | break; | ||
| 564 : | } | ||
| 565 : | |||
| 566 : | $row = new mosModule( $database ); | ||
| 567 : | $row->load( $uid ); | ||
| 568 : | $row->access = $access; | ||
| 569 : | |||
| 570 : | if ( !$row->check() ) { | ||
| 571 : | return $row->getError(); | ||
| 572 : | } | ||
| 573 : | if ( !$row->store() ) { | ||
| 574 : | return $row->getError(); | ||
| 575 : | } | ||
| 576 : | |||
| 577 : | mosRedirect( 'index2.php?option='. $option .'&client='. $client ); | ||
| 578 : | } | ||
| 579 : | |||
| 580 : | function saveOrder( &$cid, $client ) { | ||
| 581 : | global $database; | ||
| 582 : | |||
| 583 : | $total = count( $cid ); | ||
| 584 : | $order = mosGetParam( $_POST, 'order', array(0) ); | ||
| 585 : | $row = new mosModule( $database ); | ||
| 586 : | $conditions = array(); | ||
| 587 : | |||
| 588 : | // update ordering values | ||
| 589 : | for( $i=0; $i < $total; $i++ ) { | ||
| 590 : | $row->load( $cid[$i] ); | ||
| 591 : | if ($row->ordering != $order[$i]) { | ||
| 592 : | $row->ordering = $order[$i]; | ||
| 593 : | if (!$row->store()) { | ||
| 594 : | echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 595 : | exit(); | ||
| 596 : | } // if | ||
| 597 : | // remember to updateOrder this group | ||
| 598 : | $condition = "position='$row->position' AND client_id='$row->client_id'"; | ||
| 599 : | $found = false; | ||
| 600 : | foreach ( $conditions as $cond ) | ||
| 601 : | if ($cond[1]==$condition) { | ||
| 602 : | $found = true; | ||
| 603 : | break; | ||
| 604 : | } // if | ||
| 605 : | if (!$found) $conditions[] = array($row->id, $condition); | ||
| 606 : | } // if | ||
| 607 : | } // for | ||
| 608 : | |||
| 609 : | // execute updateOrder for each group | ||
| 610 : | foreach ( $conditions as $cond ) { | ||
| 611 : | $row->load( $cond[0] ); | ||
| 612 : | $row->updateOrder( $cond[1] ); | ||
| 613 : | } // foreach | ||
| 614 : | |||
| 615 : | $msg = 'New ordering saved'; | ||
| 616 : | mosRedirect( 'index2.php?option=com_modules&client='. $client, $msg ); | ||
| 617 : | } // saveOrder | ||
| 618 : | csouza | 129 | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

