| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: controller.php 18162 2010-07-16 07:00:47Z ian $ 4 * @package Joomla 5 * @subpackage Menus 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 to the 9 * GNU General Public License, and as distributed it includes or is derivative 10 * of works licensed under the GNU General Public License or other free or open 11 * source software licenses. See COPYRIGHT.php for copyright notices and 12 * details. 13 */ 14 15 // Check to ensure this file is included in Joomla! 16 defined('_JEXEC') or die( 'Restricted access' ); 17 18 jimport('joomla.application.component.controller'); 19 20 /** 21 * @package Joomla 22 * @subpackage Menus 23 */ 24 class MenusController extends JController 25 { 26 /** 27 * New menu item wizard 28 */ 29 30 function newItem() 31 { 32 JRequest::setVar( 'edit', false ); 33 $model =& $this->getModel( 'Item' ); 34 $view =& $this->getView( 'Item' ); 35 $view->setModel( $model, true ); 36 37 // Set the layout and display 38 $view->setLayout('type'); 39 $view->type(); 40 } 41 /** 42 * Edit menu item wizard 43 */ 44 45 function type() 46 { 47 JRequest::setVar( 'edit', true ); 48 $model =& $this->getModel( 'Item' ); 49 $view =& $this->getView( 'Item' ); 50 $view->setModel( $model, true ); 51 52 // Set the layout and display 53 $view->setLayout('type'); 54 $view->type(); 55 } 56 57 /** 58 * Edits a menu item 59 */ 60 function edit() 61 { 62 JRequest::setVar( 'edit', true ); 63 $model =& $this->getModel( 'Item' ); 64 $model->checkout(); 65 66 $view =& $this->getView( 'Item' ); 67 $view->setModel( $model, true ); 68 // Set the layout and display 69 $view->setLayout('form'); 70 $view->edit(); 71 } 72 73 /** 74 * Saves a menu item 75 */ 76 function save() 77 { 78 // Check for request forgeries 79 JRequest::checkToken() or jexit( 'Invalid Token' ); 80 81 $model =& $this->getModel( 'Item' ); 82 $post = JRequest::get('post'); 83 // allow name only to contain html 84 $post['name'] = JRequest::getVar( 'name', '', 'post', 'string', JREQUEST_ALLOWHTML ); 85 $model->setState( 'request', $post ); 86 87 if ($model->store()) { 88 $msg = JText::_( 'Menu item Saved' ); 89 } else { 90 $msg = JText::_( 'Error Saving Menu item' ); 91 } 92 93 $item =& $model->getItem(); 94 switch ( $this->_task ) { 95 case 'apply': 96 $this->setRedirect( 97 'index.php?option=com_menus&menutype=' . $item->menutype 98 . '&task=edit&cid[]=' . $item->id, 99 $msg 100 ); 101 break; 102 103 case 'save': 104 default: 105 $this->setRedirect( 106 'index.php?option=com_menus&task=view&menutype=' . $item->menutype, 107 $msg 108 ); 109 break; 110 } 111 } 112 113 /** 114 * Cancels an edit operation 115 */ 116 function cancelItem() 117 { 118 global $mainframe; 119 120 JRequest::checkToken() or jexit( 'Invalid Token' ); 121 122 $menutype = $mainframe->getUserStateFromRequest( 'com_menus.menutype', 'menutype', 'mainmenu', 'menutype' ); 123 124 $model = $this->getModel('item'); 125 $model->checkin(); 126 127 $this->setRedirect('index.php?option=com_menus&task=view&menutype=' . $menutype); 128 } 129 130 /** 131 * Cancels an edit operation 132 */ 133 function cancel() 134 { 135 $this->setRedirect( 'index.php?option=com_menus'); 136 } 137 138 /** 139 * Form for copying item(s) to a specific menu 140 */ 141 function copy() 142 { 143 $model =& $this->getModel( 'List' ); 144 $view =& $this->getView( 'List' ); 145 $view->setModel( $model, true ); 146 $view->copyForm(); 147 } 148 149 /** 150 * Save the item(s) to the menu selected 151 */ 152 function doCopy() 153 { 154 global $mainframe; 155 156 // Check for request forgeries 157 JRequest::checkToken() or jexit( 'Invalid Token' ); 158 159 // Get some variables from the request 160 $menu = JRequest::getVar('menu', '', 'post', 'menutype'); 161 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 162 JArrayHelper::toInteger($cid); 163 164 //Check to see of a menu was selected to copy the items too 165 if (empty($menu)) 166 { 167 $msg = JText::_('Please select a menu from the list'); 168 $mainframe->enqueueMessage($msg, 'message'); 169 return $this->execute('copy'); 170 } 171 172 $model =& $this->getModel( 'List' ); 173 174 if ($model->copy($cid, $menu)) { 175 $msg = JText::sprintf( 'Menu Items Copied to', count( $cid ), $menu ); 176 } else { 177 $msg = $model->getError(); 178 } 179 $this->setRedirect('index.php?option=com_menus&task=view&menutype=' . $menu, $msg); 180 } 181 182 /** 183 * Form for moving item(s) to a specific menu 184 */ 185 function move() 186 { 187 $model =& $this->getModel( 'List'); 188 $view =& $this->getView( 'List' ); 189 $view->setModel( $model, true ); 190 $view->moveForm(); 191 } 192 193 /** 194 * Save the item(s) to the menu selected 195 */ 196 function doMove() 197 { 198 global $mainframe; 199 200 // Check for request forgeries 201 JRequest::checkToken() or jexit( 'Invalid Token' ); 202 203 // Get some variables from the request 204 $menu = JRequest::getVar( 'menu', '', 'post', 'menutype' ); 205 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 206 JArrayHelper::toInteger($cid); 207 208 //Check to see if a menu was selected to copy the items too 209 if (empty($menu)) 210 { 211 $msg = JText::_('Please select a menu from the list'); 212 $mainframe->enqueueMessage($msg, 'message'); 213 return $this->execute('move'); 214 } 215 216 $model =& $this->getModel( 'List' ); 217 218 if ($model->move($cid, $menu)) { 219 $msg = JText::sprintf( 'Menu Items Moved to', count( $cid ), $menu ); 220 } else { 221 $msg = $model->getError(); 222 } 223 $this->setRedirect('index.php?option=com_menus&task=view&menutype=' . $menu, $msg); 224 } 225 226 /** 227 * Save the item(s) to the menu selected 228 */ 229 function publish() 230 { 231 // Check for request forgeries 232 JRequest::checkToken() or jexit( 'Invalid Token' ); 233 234 // Get some variables from the request 235 $menutype = JRequest::getVar('menutype', '', 'post', 'menutype'); 236 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 237 JArrayHelper::toInteger($cid); 238 239 $model =& $this->getModel( 'List' ); 240 if ($model->setItemState($cid, 1)) { 241 $msg = JText::sprintf( 'Menu Items Published', count( $cid ) ); 242 } else { 243 $msg = $model->getError(); 244 } 245 $this->setRedirect('index.php?option=com_menus&task=view&menutype=' . $menutype, $msg); 246 } 247 248 /** 249 * Save the item(s) to the menu selected 250 */ 251 function unpublish() 252 { 253 // Check for request forgeries 254 JRequest::checkToken() or jexit( 'Invalid Token' ); 255 256 // Get some variables from the request 257 $menutype = JRequest::getVar('menutype', '', 'post', 'menutype'); 258 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 259 JArrayHelper::toInteger($cid); 260 261 $model =& $this->getModel( 'List' ); 262 if ($model->setItemState($cid, 0)) { 263 $msg = JText::sprintf( 'Menu Items Unpublished', count( $cid ) ); 264 } else { 265 $msg = $model->getError(); 266 } 267 $this->setRedirect('index.php?option=com_menus&task=view&menutype=' . $menutype, $msg); 268 } 269 270 /** 271 * Save the item(s) to the menu selected 272 */ 273 function orderup() 274 { 275 // Check for request forgeries 276 JRequest::checkToken() or jexit( 'Invalid Token' ); 277 278 $menutype = JRequest::getVar('menutype', '', 'post', 'menutype'); 279 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 280 JArrayHelper::toInteger($cid); 281 282 if (isset($cid[0]) && $cid[0]) { 283 $id = $cid[0]; 284 } else { 285 $this->setRedirect( 286 'index.php?option=com_menus&task=view&menutype=' . $menutype, 287 JText::_('No Items Selected') 288 ); 289 return false; 290 } 291 292 $model =& $this->getModel( 'List' ); 293 if ($model->orderItem($id, -1)) { 294 $msg = JText::_( 'Menu Item Moved Up' ); 295 } else { 296 $msg = $model->getError(); 297 } 298 $this->setRedirect('index.php?option=com_menus&task=view&menutype=' . $menutype, $msg); 299 } 300 301 /** 302 * Save the item(s) to the menu selected 303 */ 304 function orderdown() 305 { 306 // Check for request forgeries 307 JRequest::checkToken() or jexit( 'Invalid Token' ); 308 309 $menutype = JRequest::getVar('menutype', '', 'post', 'menutype'); 310 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 311 JArrayHelper::toInteger($cid); 312 313 if (isset($cid[0]) && $cid[0]) { 314 $id = $cid[0]; 315 } else { 316 $this->setRedirect( 317 'index.php?option=com_menus&task=view&menutype=' . $menutype, 318 JText::_('No Items Selected') 319 ); 320 return false; 321 } 322 323 $model =& $this->getModel( 'List' ); 324 if ($model->orderItem($id, 1)) { 325 $msg = JText::_( 'Menu Item Moved Down' ); 326 } else { 327 $msg = $model->getError(); 328 } 329 $this->setRedirect('index.php?option=com_menus&task=view&menutype=' . $menutype, $msg); 330 } 331 332 /** 333 * Save the item(s) to the menu selected 334 */ 335 function saveorder() 336 { 337 // Check for request forgeries 338 JRequest::checkToken() or jexit( 'Invalid Token' ); 339 340 $menutype = JRequest::getVar('menutype', '', 'post', 'menutype'); 341 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 342 JArrayHelper::toInteger($cid); 343 344 $model =& $this->getModel( 'List' ); 345 if ($model->setOrder($cid, $menutype)) { 346 $msg = JText::_( 'New ordering saved' ); 347 } else { 348 $msg = $model->getError(); 349 } 350 $this->setRedirect('index.php?option=com_menus&task=view&menutype='. $menutype, $msg); 351 } 352 353 /** 354 * Save the item(s) to the menu selected 355 */ 356 function accesspublic() 357 { 358 // Check for request forgeries 359 JRequest::checkToken() or jexit( 'Invalid Token' ); 360 361 // Get some variables from the request 362 $menutype = JRequest::getVar('menutype', '', 'post', 'menutype'); 363 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 364 JArrayHelper::toInteger($cid); 365 366 $model =& $this->getModel( 'List' ); 367 if ($model->setAccess($cid, 0)) { 368 $msg = JText::sprintf( 'Menu Items Set Public', count( $cid ) ); 369 } else { 370 $msg = $model->getError(); 371 } 372 $this->setRedirect('index.php?option=com_menus&task=view&menutype=' . $menutype, $msg); 373 } 374 375 /** 376 * Save the item(s) to the menu selected 377 */ 378 function accessregistered() 379 { 380 // Check for request forgeries 381 JRequest::checkToken() or jexit( 'Invalid Token' ); 382 383 // Get some variables from the request 384 $menutype = JRequest::getVar('menutype', '', 'post', 'menutype'); 385 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 386 JArrayHelper::toInteger($cid); 387 388 $model =& $this->getModel( 'List' ); 389 if ($model->setAccess($cid, 1)) { 390 $msg = JText::sprintf( 'Menu Items Set Registered', count( $cid ) ); 391 } else { 392 $msg = $model->getError(); 393 } 394 $this->setRedirect('index.php?option=com_menus&task=view&menutype=' . $menutype, $msg); 395 } 396 397 /** 398 * Save the item(s) to the menu selected 399 */ 400 function accessspecial() 401 { 402 // Check for request forgeries 403 JRequest::checkToken() or jexit( 'Invalid Token' ); 404 405 // Get some variables from the request 406 $menutype = JRequest::getVar('menutype', '', 'post', 'menutype'); 407 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 408 JArrayHelper::toInteger($cid); 409 410 $model =& $this->getModel( 'List' ); 411 if ($model->setAccess($cid, 2)) { 412 $msg = JText::sprintf( 'Menu Items Set Special', count( $cid ) ); 413 } else { 414 $msg = $model->getError(); 415 } 416 $this->setRedirect('index.php?option=com_menus&task=view&menutype=' . $menutype, $msg); 417 } 418 419 /** 420 * Save the item(s) to the menu selected 421 */ 422 function setdefault() 423 { 424 // Check for request forgeries 425 JRequest::checkToken() or jexit( 'Invalid Token' ); 426 427 // Get some variables from the request 428 $menutype = JRequest::getVar('menutype', '', 'post', 'menutype'); 429 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 430 JArrayHelper::toInteger($cid); 431 432 if (isset($cid[0]) && $cid[0]) { 433 $id = $cid[0]; 434 } else { 435 $this->setRedirect( 436 'index.php?option=com_menus&task=view&menutype=' . $menutype, 437 JText::_('No Items Selected') 438 ); 439 return false; 440 } 441 442 $item =& JTable::getInstance( 'menu' ); 443 $item->load($id); 444 if(!$item->get('published')) { 445 $this->setRedirect( 446 'index.php?option=com_menus&task=view&menutype=' . $menutype, 447 JText::_('The Default Menu Item Must Be Published') 448 ); 449 return false; 450 } 451 452 $model =& $this->getModel( 'List' ); 453 if ($model->setHome($id)) { 454 $msg = JText::_( 'Default Menu Item Set' ); 455 } else { 456 $msg = $model->getError(); 457 } 458 $this->setRedirect( 459 'index.php?option=com_menus&task=view&menutype=' . $menutype, 460 $msg 461 ); 462 } 463 464 function remove() 465 { 466 // Check for request forgeries 467 JRequest::checkToken() or jexit( 'Invalid Token' ); 468 469 // Get some variables from the request 470 $menutype = JRequest::getVar('menutype', '', 'post', 'menutype'); 471 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 472 JArrayHelper::toInteger($cid); 473 474 if (!count($cid)) { 475 $this->setRedirect( 476 'index.php?option=com_menus&task=view&menutype=' . $menutype, 477 JText::_('No Items Selected') 478 ); 479 return false; 480 } 481 482 $model =& $this->getModel( 'List' ); 483 if ($n = $model->toTrash($cid)) { 484 $msg = JText::sprintf( 'Item(s) sent to the Trash', $n ); 485 } else { 486 $msg = $model->getError(); 487 } 488 $this->setRedirect( 489 'index.php?option=com_menus&task=view&menutype=' . $menutype, 490 $msg 491 ); 492 } 493 494 /** 495 * Save the item(s) to the menu selected 496 */ 497 function view() 498 { 499 $model =& $this->getModel( 'List' ); 500 $view =& $this->getView( 'List' ); 501 $view->setModel( $model, true ); 502 $view->display(); 503 } 504 505 506 /** 507 * Controller for view listing menu types and related statical info 508 * @param string The URL option 509 */ 510 function viewMenus() 511 { 512 513 $view =& $this->getView( 'Menus'); 514 $model =& $this->getModel( 'Menutype' ); 515 $view->setModel( $model, true ); 516 $view->display(); 517 } 518 519 520 /** 521 * Controller for view to edit a menu type 522 */ 523 function editMenu() 524 { 525 $view =& $this->getView( 'Menus' ); 526 $model =& $this->getModel( 'Menutype' ); 527 $view->setModel( $model, true ); 528 $view->editForm(true,null); 529 530 } 531 532 /** 533 * Controller for view to create a menu type 534 */ 535 function addMenu() 536 { 537 $view =& $this->getView( 'Menus' ); 538 $model =& $this->getModel( 'Menutype' ); 539 $view->setModel( $model, true ); 540 $view->editForm(false,null); 541 } 542 543 /** 544 * Controller for saving a menu type 545 */ 546 function saveMenu() 547 { 548 global $mainframe; 549 550 // Check for request forgeries 551 JRequest::checkToken() or jexit( 'Invalid Token' ); 552 553 $db =& JFactory::getDBO(); 554 $id = JRequest::getVar( 'id', 0, 'post', 'int' ); 555 556 $oldType =& JTable::getInstance('menutypes' ); 557 $oldType->load( $id ); 558 559 $menuType =& JTable::getInstance('menutypes'); 560 $menuType->bind( JRequest::get( 'post' ) ); 561 562 $isNew = ($menuType->id == 0); 563 $isChanged = ($oldType->menutype != $menuType->menutype); 564 565 if (!$menuType->check()) { 566 JError::raiseWarning( 500, $menuType->getError() ); 567 $this->setRedirect( 'index.php?option=com_menus&task=editMenu', 'Please check your menu settings' ); 568 return false; 569 } 570 571 if (!$menuType->store()) { 572 JError::raiseWarning( 500, $menuType->getError() ); 573 $this->setRedirect( 'index.php?option=com_menus&task=editMenu', 'Please check your menu settings' ); 574 return false; 575 } 576 577 if ($isNew) 578 { 579 if ($title = JRequest::getVar( 'module_title', $menuType->menutype, 'post', 'string' )) 580 { 581 $module =& JTable::getInstance( 'module'); 582 $module->title = $title; 583 $module->position = 'left'; 584 $module->module = 'mod_mainmenu'; 585 $module->published = 0; 586 $module->iscore = 0; 587 $module->params = 'menutype='. $menuType->menutype; 588 589 // check then store data in db 590 if (!$module->check()) { 591 return JError::raiseWarning( 500, $module->getError() ); 592 } 593 if (!$module->store()) { 594 return JError::raiseWarning( 500, $module->getError() ); 595 } 596 $module->checkin(); 597 $module->reorder( 'position='.$db->Quote($module->position) ); 598 599 // module assigned to show on All pages by default 600 // Clean up possible garbage first 601 $query = 'DELETE FROM #__modules_menu WHERE moduleid = '.(int) $module->id; 602 $db->setQuery( $query ); 603 if (!$db->query()) { 604 return JError::raiseWarning( 500, $db->getError() ); 605 } 606 607 // ToDO: Changed to become a Joomla! db-object 608 $query = 'INSERT INTO #__modules_menu VALUES ( '.(int) $module->id.', 0 )'; 609 $db->setQuery( $query ); 610 if (!$db->query()) { 611 return JError::raiseWarning( 500, $db->getError() ); 612 } 613 } 614 615 $msg = JText::sprintf( 'New Menu created', $menuType->menutype ); 616 } 617 else if ($isChanged) 618 { 619 $oldTerm = $oldType->menutype; 620 $newTerm = $menuType->menutype; 621 622 // change menutype being of all mod_mainmenu modules calling old menutype 623 $query = 'SELECT id' 624 . ' FROM #__modules' 625 . ' WHERE module = "mod_mainmenu"' 626 . ' AND params LIKE "%menutype='.$db->getEscaped($oldTerm).'%"' 627 ; 628 $db->setQuery( $query ); 629 $modules = $db->loadResultArray(); 630 631 foreach ($modules as $id) 632 { 633 $row =& JTable::getInstance('module'); 634 $row->load( $id ); 635 636 $row->params = str_replace( $oldTerm, $newTerm, $row->params ); 637 638 // check then store data in db 639 if ( !$row->check() ) { 640 return JError::raiseWarning( 500, $db->getError() ); 641 } 642 if ( !$row->store() ) { 643 return JError::raiseWarning( 500, $db->getError() ); 644 } 645 $row->checkin(); 646 } 647 648 // change menutype of all menuitems using old menutype 649 $query = 'UPDATE #__menu' 650 . ' SET menutype = '.$db->Quote($newTerm) 651 . ' WHERE menutype = '.$db->Quote($oldTerm) 652 ; 653 $db->setQuery( $query ); 654 $db->query(); 655 656 $msg = JText::_( 'Menu Items & Modules updated' ); 657 } 658 659 $this->setRedirect( 'index.php?option=com_menus', $msg ); 660 } 661 662 /** 663 * Controller for a view to confirm the deletion of a menu type 664 */ 665 function deleteMenu() 666 { 667 $view =& $this->getView( 'Menus' ); 668 $model =& $this->getModel( 'Menutype' ); 669 $view->setModel( $model, true ); 670 $view->deleteForm(); 671 } 672 673 /** 674 * Delete a menu 675 */ 676 function doDeleteMenu() 677 { 678 // Check for request forgeries 679 JRequest::checkToken() or jexit( 'Invalid Token' ); 680 681 $id = JRequest::getVar( 'id', 0, '', 'int' ); 682 if ($id <= 0) { 683 JError::raiseWarning( 500, JText::_( 'Invalid ID provided' ) ); 684 $this->setRedirect( 'index.php?option=com_menus' ); 685 return false; 686 } 687 688 $model =& $this->getModel( 'Menutype' ); 689 if (!$model->canDelete()) { 690 JError::raiseWarning( 500, $model->getError() ); 691 $this->setRedirect( 'index.php?option=com_menus' ); 692 return false; 693 } 694 $err = null; 695 if (!$model->delete()) { 696 $err = $model->getError(); 697 } 698 $this->setRedirect( 'index.php?option=com_menus', $err ); 699 } 700 701 /** 702 * Compiles a list of the articles you have selected to Copy 703 */ 704 function copyMenu() 705 { 706 $view =& $this->getView( 'Menus' ); 707 $model =& $this->getModel( 'Menutype' ); 708 $view->setModel( $model, true ); 709 $view->copyForm(); 710 } 711 712 /** 713 * Copies a complete menu, all its items and creates a new module, using the name speified 714 */ 715 function doCopyMenu() 716 { 717 global $mainframe; 718 719 // Check for request forgeries 720 JRequest::checkToken() or jexit( 'Invalid Token' ); 721 722 $db =& JFactory::getDBO(); 723 $type = JRequest::getVar( 'type', '', 'post', 'string' ); 724 $menu_name = JRequest::getVar( 'menu_name', 'New Menu', 'post', 'menutype' ); 725 $module_name = JRequest::getVar( 'module_name', 'New Module', 'post', 'string' ); 726 727 // check for unique menutype for new menu copy 728 $query = 'SELECT params' . 729 ' FROM #__modules' . 730 ' WHERE module = "mod_mainmenu"'; 731 $db->setQuery( $query ); 732 $menus = $db->loadResultArray(); 733 734 foreach ( $menus as $menu ) 735 { 736 $params = new JParameter( $menu ); 737 if ( $params->get('menutype') == $menu_name ) { 738 JError::raiseWarning( 500, JText::_( 'ERRORMENUNAMEEXISTS' ) ); 739 $this->setRedirect( 'index.php?option=com_menus' ); 740 return; 741 } 742 } 743 744 // copy the menu items 745 $mids = JRequest::getVar( 'mids', array(), 'post', 'array' ); 746 JArrayHelper::toInteger($mids); 747 $total = count( $mids ); 748 $copy =& JTable::getInstance('menu'); 749 $original =& JTable::getInstance('menu'); 750 sort( $mids ); 751 $a_ids = array(); 752 753 foreach( $mids as $mid ) 754 { 755 $original->load( $mid ); 756 $parent = $original->parent; 757 $id = $original->id; 758 $copy = $original; 759 $copy->id = NULL; 760 $copy->parent = $a_ids[$parent]; 761 $copy->menutype = $menu_name; 762 $copy->home = 0; 763 764 if ( !$copy->check() ) { 765 JError::raiseWarning( 500, $copy->getError() ); 766 $this->setRedirect( 'index.php?option=com_menus' ); 767 return; 768 } 769 if ( !$copy->store() ) { 770 JError::raiseWarning( 500, $copy->getError() ); 771 $this->setRedirect( 'index.php?option=com_menus' ); 772 return; 773 } 774 $a_ids[$id] = $copy->id; 775 } 776 777 // create the module copy 778 $row =& JTable::getInstance('module'); 779 $row->load( 0 ); 780 $row->title = $module_name; 781 $row->iscore = 0; 782 $row->published = 1; 783 $row->position = 'left'; 784 $row->module = 'mod_mainmenu'; 785 $row->params = 'menutype='. $menu_name; 786 787 if (!$row->check()) { 788 JError::raiseWarning( 500, $db->getError() ); 789 $this->setRedirect( 'index.php?option=com_menus' ); 790 return; 791 } 792 if (!$row->store()) { 793 JError::raiseWarning( 500, $db->getError() ); 794 $this->setRedirect( 'index.php?option=com_menus' ); 795 return; 796 } 797 $row->checkin(); 798 $row->reorder( 'position='.$db->Quote($row->position) ); 799 // module assigned to show on All pages by default 800 // ToDO: Changed to become a Joomla! db-object 801 $query = 'INSERT INTO #__modules_menu' . 802 ' VALUES ( '.(int) $row->id.', 0 )'; 803 $db->setQuery( $query ); 804 if ( !$db->query() ) { 805 JError::raiseWarning( 500, $db->getErrorMsg(true) ); 806 $this->setRedirect( 'index.php?option=com_menus' ); 807 return; 808 //echo "<script> alert('".$db->getErrorMsg(true)."'); window.history.go(-1); </script>\n"; 809 //$mainframe->close(); 810 } 811 812 // Insert the menu type 813 $query = 'INSERT INTO `#__menu_types` ( `menutype` , `title` , `description` ) ' . 814 ' VALUES ( '.$db->Quote($menu_name).', '.$db->Quote($menu_name).', "")'; 815 $db->setQuery( $query ); 816 if ( !$db->query() ) { 817 JError::raiseWarning( 500, $db->getErrorMsg(true) ); 818 $this->setRedirect( 'index.php?option=com_menus' ); 819 return; 820 //echo "<script> alert('".$db->getErrorMsg(true)."'); window.history.go(-1); </script>\n"; 821 //$mainframe->close(); 822 } 823 824 $msg = JText::sprintf( 'Copy of Menu created', $type, $total ); 825 $mainframe->redirect( 'index.php?option=com_menus', $msg ); 826 } 827 }
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 |