Source for file admin.menumanager.php

Documentation is available at admin.menumanager.php

  1. <?php
  2. /**
  3. @package Mambo
  4. @subpackage Menus
  5. @copyright  Refer to copyright.php
  6. @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  7. @author Mambo Foundation Inc see README.php
  8. */ 
  9.  
  10. /** ensure this file is being included by a parent file */
  11. defined'_VALID_MOS' or die'Direct Access to this location is not allowed.' );
  12.  
  13. // ensure user has access to this function
  14. if (!$acl->acl_check'administration''manage''users'$my->usertype'components''com_menumanager' )) {
  15.     mosRedirect'index2.php'T_('You are not authorized to view this resource.') );
  16. }
  17.  
  18. require_once$mainframe->getPath'admin_html' ) );
  19.  
  20. $menu         mosGetParam$_GET'menu''' );
  21. $task         mosGetParam$_REQUEST'task'array(0) );
  22. $type         mosGetParam$_POST'type''' );
  23. $cid         mosGetParam$_POST'cid''' );
  24.  
  25. switch ($task{
  26.     case 'new':
  27.         editMenu$option'' );
  28.         break;
  29.  
  30.     case 'edit':
  31.         if !$menu {
  32.             $menu $cid[0];
  33.         }
  34.         editMenu$option$menu );
  35.         break;
  36.  
  37.     case 'savemenu':
  38.         saveMenu();
  39.         break;
  40.  
  41.     case 'deleteconfirm':
  42.         deleteconfirm$option$cid );
  43.         break;
  44.  
  45.     case 'deletemenu':
  46.         deleteMenu$option$cid$type );
  47.         break;
  48.  
  49.     case 'copyconfirm':
  50.         copyConfirm$option$cid[0);
  51.         break;
  52.  
  53.     case 'copymenu':
  54.         copyMenu$option$cid$type );
  55.         break;
  56.  
  57.     case 'cancel':
  58.         cancelMenu$option );
  59.         break;
  60.  
  61.     default:
  62.         showMenu$option );
  63.         break;
  64. }
  65.  
  66.  
  67. /**
  68. * Compiles a list of menumanager items
  69. */
  70. function showMenu$option {
  71.     global $database$mainframe$mosConfig_list_limit;
  72.  
  73.     $limit         $mainframe->getUserStateFromRequest"viewlistlimit"'limit'$mosConfig_list_limit );
  74.     $limitstart $mainframe->getUserStateFromRequest"view{"$option ."}limitstart"'limitstart');
  75.  
  76.     $menuTypes     mosAdminMenus::menutypes();                
  77.     $total        count$menuTypes );
  78.     $i            0;
  79.     foreach $menuTypes as $a {
  80.         $menus[$i]->type         $a;        
  81.         
  82.         // query to get number of modules for menutype
  83.         $query "SELECT count( id )"
  84.         . "\n FROM #__modules"
  85.         . "\n WHERE module = 'mod_mainmenu'"
  86.         . "\n AND params LIKE '%$a%'"
  87.         ;
  88.         $database->setQuery$query );
  89.         $modules $database->loadResult();        
  90.         
  91.         if !$modules {
  92.             $modules '-';
  93.         }
  94.         $menus[$i]->modules $modules;
  95.         
  96.         $i++;
  97.     }
  98.  
  99.     // Query to get published menu item counts
  100.     $query "SELECT a.menutype, count( a.menutype ) as num"
  101.     . "\n FROM #__menu AS a"
  102.     . "\n WHERE a.published = 1"
  103.     . "\n GROUP BY a.menutype"
  104.     . "\n ORDER BY a.menutype"
  105.     ;
  106.     $database->setQuery$query );
  107.     $published $database->loadObjectList();
  108.  
  109.     // Query to get unpublished menu item counts
  110.     $query "SELECT a.menutype, count( a.menutype ) as num"
  111.     . "\n FROM #__menu AS a"
  112.     . "\n WHERE a.published = 0"
  113.     . "\n GROUP BY a.menutype"
  114.     . "\n ORDER BY a.menutype"
  115.     ;
  116.     $database->setQuery$query );
  117.     $unpublished $database->loadObjectList();
  118.     if (!$unpublished$unpublished array();
  119.  
  120.     // Query to get trash menu item counts
  121.     $query "SELECT a.menutype, count( a.menutype ) as num"
  122.     . "\n FROM #__menu AS a"
  123.     . "\n WHERE a.published = -2"
  124.     . "\n GROUP BY a.menutype"
  125.     . "\n ORDER BY a.menutype"
  126.     ;
  127.     $database->setQuery$query );
  128.     $trash $database->loadObjectList();
  129.     if (!$trash$trash array();
  130.  
  131.     for$i 0$i $total$i++ {
  132.         // adds published count
  133.         foreach $published as $count {
  134.             if $menus[$i]->type == $count->menutype {
  135.                 $menus[$i]->published $count->num;
  136.             }
  137.         }
  138.         if @!$menus[$i]->published {
  139.             $menus[$i]->published '-';
  140.         }
  141.         // adds unpublished count
  142.         foreach $unpublished as $count {
  143.             if $menus[$i]->type == $count->menutype {
  144.                 $menus[$i]->unpublished $count->num;
  145.             }
  146.         }
  147.         if @!$menus[$i]->unpublished {
  148.             $menus[$i]->unpublished '-';
  149.         }
  150.         // adds trash count
  151.         foreach $trash as $count {
  152.             if $menus[$i]->type == $count->menutype {
  153.                 $menus[$i]->trash = $count->num;
  154.             }
  155.         }
  156.         if @!$menus[$i]->trash {
  157.             $menus[$i]->trash = '-';
  158.         }
  159.     }
  160.  
  161.     require_once$GLOBALS['mosConfig_absolute_path''/administrator/includes/pageNavigation.php' );
  162.     $pageNav new mosPageNav$total$limitstart$limit  );
  163.  
  164.     HTML_menumanager::show$option$menus$pageNav );
  165. }
  166.  
  167.  
  168. /**
  169. * Edits a mod_mainmenu module
  170. *
  171. @param option    options for the edit mode
  172. @param cid    menu id
  173. */
  174. function editMenu$option$menu {
  175.     global $database;
  176.     
  177.     if$menu {
  178.         $row->menutype     $menu;
  179.     else {
  180.         $row new mosModule$database );
  181.         // setting default values
  182.         $row->menutype     '';
  183.         $row->iscore     0;
  184.         $row->published 0;
  185.         $row->position     'left';
  186.         $row->module     'mod_mainmenu';
  187.     }
  188.  
  189.     HTML_menumanager::edit$row$option );
  190. }
  191.  
  192. /**
  193. * Creates a new mod_mainmenu module, which makes the menu visible
  194. * this is a workaround until a new dedicated table for menu management can be created
  195. */
  196. function saveMenu({
  197.     global $database;
  198.  
  199.     $menutype         mosGetParam$_POST'menutype''' );
  200.     $old_menutype     mosGetParam$_POST'old_menutype''' );
  201.     $new            mosGetParam$_POST'new');
  202.  
  203.     // block to stop renaming of 'mainmenu' menutype
  204.     if $old_menutype == 'منوی اصلی' {
  205.         if $menutype <> 'منوی اصلی' {
  206.             echo "<script> alert('".T_('You cannot rename the "mainmenu" Menu as this will disrupt the proper operation of Mambo')."'); window.history.go(-1); </script>\n";
  207.             exit;            
  208.         }
  209.     }
  210.     
  211.     // check for unique menutype for new menus
  212.     $query "SELECT params"
  213.     . "\n FROM #__modules"
  214.     . "\n WHERE module = 'mod_mainmenu'"
  215.     ;
  216.     $database->setQuery$query );
  217.     $menus $database->loadResultArray();    
  218.     foreach $menus as $menu {
  219.         $pparser new mosParameters($menu);
  220.         $params $pparser->getParams();
  221.         if $params->menutype == $menutype {
  222.             echo "<script> alert('".T_('A menu already exists with that name - you must enter a unique Menu Name')."'); window.history.go(-1); </script>\n";
  223.             exit;
  224.         }
  225.     }
  226.     
  227.     switch $new {
  228.         case 1:
  229.         // create a new module for the new menu
  230.             $row new mosModule$database );
  231.             $row->bind$_POST );
  232.         
  233.             $row->params 'menutype='$menutype;
  234.     
  235.             // check then store data in db    
  236.             if (!$row->check()) {
  237.                 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  238.                 exit();
  239.             }
  240.             if (!$row->store()) {
  241.                 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  242.                 exit();
  243.             }
  244.             
  245.             $row->checkin();
  246.             $row->updateOrder"position='"$row->position ."'" );
  247.             
  248.             // module assigned to show on All pages by default
  249.             // ToDO: Changed to become a mambo db-object
  250.             $query "INSERT INTO #__modules_menu VALUES ( $row->id, 0 )";
  251.             $database->setQuery$query );
  252.             if !$database->query() ) {
  253.                 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
  254.                 exit();
  255.             }
  256.             
  257.             $msg sprintf(T_('New Menu created [ %s ]')$menutype);            
  258.             break;
  259.     
  260.         default:
  261.         // change menutype being of all mod_mainmenu modules calling old menutype
  262.             $query "SELECT id"
  263.             . "\n FROM #__modules"
  264.             . "\n WHERE module = 'mod_mainmenu'"
  265.             . "\n AND params LIKE '%$old_menutype%'"                        
  266.             ;
  267.             $database->setQuery$query );
  268.             $modules $database->loadResultArray();
  269.             
  270.             foreach $modules as $module {
  271.                 $row new mosModule$database );
  272.                 $row->load$module );
  273.                 
  274.                 $save 0;
  275.                 $pparser new mosParameters($row->params);
  276.                 $params $pparser->getParams();
  277.                 if $params->menutype == $old_menutype {
  278.                     $params->menutype     $menutype;
  279.                     $save                 1;
  280.                 }
  281.                 
  282.                 // save changes to module 'menutype' param
  283.                 if $save {
  284.                     $txt array();
  285.                     foreach $params as $k=>$v{
  286.                         $txt["$k=$v";
  287.                     }
  288.                     $row->params implode"\n"$txt );
  289.                     
  290.                     // check then store data in db    
  291.                     if !$row->check() ) {
  292.                         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  293.                         exit();
  294.                     }
  295.                     if !$row->store() ) {
  296.                         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  297.                         exit();
  298.                     }
  299.                     
  300.                     $row->checkin();
  301.                 }                
  302.             }
  303.             
  304.         // change menutype of all menuitems using old menutype
  305.             if $menutype <> $old_menutype {
  306.                 $query "UPDATE #__menu SET menutype = '$menutype' WHERE menutype = '$old_menutype'";
  307.                 $database->setQuery$query );
  308.                 $database->query();
  309.             }
  310.             
  311.             $msg T_('Menu Items & Modules updated');
  312.             break;
  313.     }
  314.         
  315.     mosRedirect'index2.php?option=com_menumanager'$msg );
  316. }
  317.  
  318. /**
  319. * Compiles a list of the items you have selected to permanently delte
  320. */
  321. function deleteConfirm$option$types {
  322.     global $database;
  323.  
  324.     if in_array('منوی اصلی'$types )) {
  325.         $types array_diff($typesarray('منوی اصلی'));
  326.         echo "<script> alert('".T_('You cannot delete the "mainmenu" menu as it is a core menu')."'); </script>\n";
  327.     }
  328.  
  329.     $menus implode("','",$types);
  330.     // list of menu items to delete
  331.     $query =     "SELECT a.name, a.id"
  332.     . "\n FROM #__menu AS a"
  333.     . "\n WHERE ( a.menutype IN ( '$menus' ) )"
  334.     . "\n ORDER BY a.name"
  335.     ;
  336.     $database->setQuery$query );
  337.     $items $database->loadObjectList();
  338.  
  339.     foreach ($types as $type{
  340.         // list of modules to delete
  341.         $query "SELECT id"
  342.         . "\n FROM #__modules"
  343.         . "\n WHERE module = 'mod_mainmenu'"
  344.         . "\n AND params LIKE '%$type%'"                        
  345.         ;
  346.         $database->setQuery$query );
  347.         $mods $database->loadResultArray();
  348.         foreach $mods as $module {
  349.             $row new mosModule$database );
  350.             $row->load$module );
  351.             $pparser new mosParameters($row->params);
  352.             $params $pparser->getParams();
  353.             if $params->menutype == $type {
  354.                 $mid[$module;
  355.             }        
  356.         }
  357.     }
  358.  
  359.     @$mids implode','$mid );
  360.     $query "SELECT id, title"
  361.     . "\n FROM #__modules"
  362.     . "\n WHERE id IN ( $mids )"
  363.     ;
  364.     $database->setQuery$query );
  365.     @$modules $database->loadObjectList();
  366.  
  367.     HTML_menumanager::showDelete$option$type$items$modules );
  368. }
  369.  
  370. /**
  371. * Deletes menu items(s) you have selected
  372. */
  373. function deleteMenu$option$cid$type {
  374.     global $database;
  375.  
  376.     if $type == 'منوی اصلی' {
  377.         echo "<script> alert('".T_('You cannot delete the "mainmenu" menu as it is a core menu')."'); window.history.go(-1); </script>\n";
  378.         exit();        
  379.     }
  380.     
  381.  
  382.     $mids         mosGetParam$_POST'mids');    
  383.     if is_array$mids ) ) {
  384.         $mids implode','$mids );
  385.     }
  386.     // delete menu items
  387.     $query =     "DELETE FROM #__menu"
  388.     . "\n WHERE ( id IN ( $mids ) )"
  389.     ;
  390.     $database->setQuery$query );
  391.     if !$database->query() ) {
  392.         echo "<script> alert('"$database->getErrorMsg(."');</script>\n";
  393.         exit;
  394.     }
  395.  
  396.     if is_array$cid ) ) {
  397.         $cids implode','$cid );
  398.     else {
  399.         $cids $cid;
  400.     }
  401.     
  402.     // checks whether any modules to delete
  403.     if $cids {        
  404.         // delete modules
  405.         $database->setQuery"DELETE FROM #__modules WHERE id IN ( $cids ));
  406.         if !$database->query() ) {
  407.             echo "<script> alert('"$database->getErrorMsg(."'); window.history.go(-1); </script>\n";
  408.             exit;
  409.         }
  410.         // delete all module entires in mos_modules_menu
  411.         $database->setQuery"DELETE FROM #__modules_menu WHERE moduleid IN ( "$cids ." )" );
  412.         if !$database->query() ) {
  413.             echo "<script> alert('"$database->getErrorMsg(."');</script>\n";
  414.             exit;
  415.         }
  416.         
  417.         // reorder modules after deletion
  418.         $mod new mosModule$database );
  419.         $mod->ordering 0;
  420.         $mod->updateOrder"position='left'" );
  421.         $mod->updateOrder"position='right'" );
  422.     }
  423.  
  424.     $msg 'Menu Deleted';
  425.     mosRedirect'index2.php?option=' $option$msg );
  426. }
  427.  
  428.  
  429. /**
  430. * Compiles a list of the items you have selected to Copy
  431. */
  432. function copyConfirm$option$type {
  433.     global $database;
  434.  
  435.     // Content Items query
  436.     $query =     "SELECT a.name, a.id"
  437.     . "\n FROM #__menu AS a"
  438.     . "\n WHERE ( a.menutype IN ( '"$type ."' ) )"
  439.     . "\n ORDER BY a.name"
  440.     ;
  441.     $database->setQuery$query );
  442.     $items $database->loadObjectList();
  443.  
  444.     HTML_menumanager::showCopy$option$type$items );
  445. }
  446.  
  447.  
  448. /**
  449. * Copies a complete menu, all its items and creates a new module, using the name speified
  450. */
  451. function copyMenu$option$cid$type {
  452.     global $database;
  453.  
  454.     $menu_name         mosGetParam$_POST'menu_name''New Menu' );
  455.     $module_name     mosGetParam$_POST'module_name''New Module' );
  456.     
  457.     // check for unique menutype for new menu copy
  458.     $query "SELECT params"
  459.     . "\n FROM #__modules"
  460.     . "\n WHERE module = 'mod_mainmenu'"
  461.     ;
  462.     $database->setQuery$query );
  463.     $menus $database->loadResultArray();    
  464.     foreach $menus as $menu {
  465.         $pparser new mosParameters($menu);
  466.         $params $pparser->getParams();
  467.         if $params->menutype == $menu_name {
  468.             echo "<script> alert('".T_('A menu with that name already exists - you must enter a unique Menu Name')."'); window.history.go(-1); </script>\n";
  469.             exit;
  470.         }
  471.     }
  472.     
  473.     // copy the menu items
  474.     $mids         mosGetParam$_POST'mids''' );
  475.     $total         count$mids );
  476.     $copy         new mosMenu$database );
  477.     $original     new mosMenu$database );
  478.     sort$mids );
  479.     $a_ids         array();
  480.     
  481.     foreach$mids as $mid {
  482.         $original->load$mid );
  483.         $copy             $original;
  484.         $copy->id         NULL;
  485.         $copy->parent     $a_ids[$original->parent];        
  486.         $copy->menutype $menu_name;
  487.         
  488.         if !$copy->check() ) {
  489.             echo "<script> alert('".$copy->getError()."'); window.history.go(-1); </script>\n";
  490.             exit();
  491.         }
  492.         if !$copy->store() ) {
  493.             echo "<script> alert('".$copy->getError()."'); window.history.go(-1); </script>\n";
  494.             exit();
  495.         }
  496.         $a_ids[$original->id$copy->id;
  497.     }
  498.  
  499.     // create the module copy
  500.     $row new mosModule$database );
  501.     $row->load);
  502.     $row->title     $module_name;
  503.     $row->iscore     0;
  504.     $row->published 1;
  505.     $row->position     'left';
  506.     $row->module     'mod_mainmenu';
  507.     $row->params     'menutype='$menu_name;
  508.  
  509.     if (!$row->check()) {
  510.         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  511.         exit();
  512.     }
  513.     if (!$row->store()) {
  514.         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  515.         exit();
  516.     }
  517.     $row->checkin();
  518.     $row->updateOrder"position='"$row->position ."'" );
  519.     // module assigned to show on All pages by default
  520.     // ToDO: Changed to become a mambo db-object
  521.     $query "INSERT INTO #__modules_menu VALUES ( $row->id, 0 )";
  522.     $database->setQuery$query );
  523.     if !$database->query() ) {
  524.         echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
  525.         exit();
  526.     }
  527.  
  528.     $msg sprintf(Tn_('Copy of Menu `%s` created, consisting of %d item''Copy of Menu `%s` created, consisting of %d items'$total)$type$total);
  529.     mosRedirect'index2.php?option=' $option$msg );
  530. }
  531.  
  532. /**
  533. * Cancels an edit operation
  534. @param option    options for the operation
  535. */
  536. function cancelMenu$option {
  537.     mosRedirect'index2.php?option=' $option '&task=view' );
  538. }
  539. ?>

Documentation generated on Mon, 05 May 2008 16:15:33 +0400 by phpDocumentor 1.4.0