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

