/**
* Cancels an edit operation
*/
function cancelModule($option, $client)
{
    global $database;
    josSpoofCheck();
    $row = new mosModule($database);
    // ignore array elements
    $row->bind($_POST, 'selections params');
    $row->checkin();
    mosRedirect('index2.php?option=' . $option . '&client=' . $client);
}
/**
* Creates a new mod_mainmenu module, which makes the menu visible
* this is a workaround until a new dedicated table for menu management can be created
*/
function saveMenu()
{
    global $database;
    josSpoofCheck();
    $menutype = stripslashes(strval(mosGetParam($_POST, 'menutype', '')));
    $old_menutype = stripslashes(strval(mosGetParam($_POST, 'old_menutype', '')));
    $new = intval(mosGetParam($_POST, 'new', 1));
    // block to stop renaming of 'mainmenu' menutype
    if ($old_menutype == 'mainmenu') {
        if ($menutype != 'mainmenu') {
            echo "<script> alert('You cannot rename the \\'mainmenu\\' Menu as this will disrupt the proper operation of Joomla'); window.history.go(-1); </script>\n";
            exit;
        }
    }
    // check for ' in menu name
    if (strstr($menutype, '\'')) {
        echo "<script> alert('The menu name cannot contain a \\''); window.history.go(-1); </script>\n";
        exit;
    }
    // check for unique menutype for new menus
    $query = "SELECT params" . "\n FROM #__modules" . "\n WHERE module = 'mod_mainmenu'";
    $database->setQuery($query);
    $menus = $database->loadResultArray();
    foreach ($menus as $menu) {
        $params = mosParseParams($menu);
        if ($params->menutype == $menutype) {
            echo "<script> alert('A menu already exists with that name - you must enter a unique Menu Name'); window.history.go(-1); </script>\n";
            exit;
        }
    }
    switch ($new) {
        case 1:
            // create a new module for the new menu
            $row = new mosModule($database);
            $row->bind($_POST);
            $row->params = 'menutype=' . $menutype;
            // check then store data in db
            if (!$row->check()) {
                echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
                exit;
            }
            if (!$row->store()) {
                echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
                exit;
            }
            $row->checkin();
            $row->updateOrder("position=" . $database->Quote($row->position));
            // module assigned to show on All pages by default
            // ToDO: Changed to become a Joomla! db-object
            $query = "INSERT INTO #__modules_menu VALUES ( " . (int) $row->id . ", 0 )";
            $database->setQuery($query);
            if (!$database->query()) {
                echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
                exit;
            }
            $msg = 'New Menu created [ ' . $menutype . ' ]';
            break;
        default:
            // change menutype being of all mod_mainmenu modules calling old menutype
            $query = "SELECT id" . "\n FROM #__modules" . "\n WHERE module = 'mod_mainmenu'" . "\n AND params LIKE '%" . $database->getEscaped($old_menutype) . "%'";
            $database->setQuery($query);
            $modules = $database->loadResultArray();
            foreach ($modules as $module) {
                $row = new mosModule($database);
                $row->load($module);
                $save = 0;
                $params = mosParseParams($row->params);
                if ($params->menutype == $old_menutype) {
                    $params->menutype = $menutype;
                    $save = 1;
                }
                // save changes to module 'menutype' param
                if ($save) {
                    $txt = array();
                    foreach ($params as $k => $v) {
                        $txt[] = "{$k}={$v}";
                    }
                    $row->params = implode("\n", $txt);
                    // check then store data in db
                    if (!$row->check()) {
                        echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
                        exit;
                    }
                    if (!$row->store()) {
                        echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
                        exit;
                    }
                    $row->checkin();
                }
            }
            // change menutype of all menuitems using old menutype
            if ($menutype != $old_menutype) {
                $query = "UPDATE #__menu" . "\n SET menutype = " . $database->Quote($menutype) . "\n WHERE menutype = " . $database->Quote($old_menutype);
                $database->setQuery($query);
                $database->query();
            }
            $msg = 'Menu Items & Modules updated';
            break;
    }
    mosRedirect('index2.php?option=com_menumanager', $msg);
}
Exemple #3
0
/**
* Creates a new mod_mainmenu module, which makes the menu visible
* this is a workaround until a new dedicated table for menu management can be created
*/
function saveMenu($option)
{
    global $database;
    global $adminLanguage;
    ## create the new module
    $row = new mosModule($database);
    $row->bind($_POST);
    // change display
    $row->params = "menutype=" . $row->params;
    $newMenu = false;
    if (!isset($row->id) || $row->id == '') {
        $newMenu = true;
    }
    if (!$row->check()) {
        echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
        exit;
    }
    if (!$row->store()) {
        echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
        exit;
    }
    $row->checkin();
    $row->updateOrder("position='" . $row->position . "'");
    if ($newMenu) {
        ## module assigned to show on All pages by default
        ## ToDO: Changed to become a mambo db-object
        $query = "INSERT INTO #__modules_menu VALUES" . "\n ( " . $row->id . ", 0 )";
        $database->setQuery($query);
        if (!$database->query()) {
            echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
            exit;
        }
        $msg = $adminLanguage->A_COMP_MENU_CREATED . " (id={$row->id})";
    } else {
        $msg = $adminLanguage->A_COMP_MENU_UPDATED;
    }
    mosRedirect("index2.php?option=com_menumanager&mosmsg=" . $msg . "");
}
/**
* Creates a new mod_mainmenu module, which makes the menu visible
* this is a workaround until a new dedicated table for menu management can be created
*/
function saveMenu()
{
    global $database;
    $menutype = mosGetParam($_POST, 'menutype', '');
    $old_menutype = mosGetParam($_POST, 'old_menutype', '');
    $new = mosGetParam($_POST, 'new', 1);
    // block to stop renaming of 'mainmenu' menutype
    if ($old_menutype == 'mainmenu') {
        if ($menutype != 'mainmenu') {
            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";
            exit;
        }
    }
    // check for unique menutype for new menus
    $query = "SELECT params" . "\n FROM #__modules" . "\n WHERE module = 'mod_mainmenu'";
    $database->setQuery($query);
    $menus = $database->loadResultArray();
    foreach ($menus as $menu) {
        $pparser = new mosParameters($menu);
        $params = $pparser->getParams();
        if ($params->menutype == $menutype) {
            echo "<script> alert('" . T_('A menu already exists with that name - you must enter a unique Menu Name') . "'); window.history.go(-1); </script>\n";
            exit;
        }
    }
    switch ($new) {
        case 1:
            // create a new module for the new menu
            $row = new mosModule($database);
            $row->bind($_POST);
            $row->params = 'menutype=' . $menutype;
            // check then store data in db
            if (!$row->check()) {
                echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
                exit;
            }
            if (!$row->store()) {
                echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
                exit;
            }
            $row->checkin();
            $row->updateOrder("position='" . $row->position . "'");
            // module assigned to show on All pages by default
            // ToDO: Changed to become a mambo db-object
            $query = "INSERT INTO #__modules_menu VALUES ( {$row->id}, 0 )";
            $database->setQuery($query);
            if (!$database->query()) {
                echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
                exit;
            }
            $msg = sprintf(T_('New Menu created [ %s ]'), $menutype);
            break;
        default:
            // change menutype being of all mod_mainmenu modules calling old menutype
            $query = "SELECT id" . "\n FROM #__modules" . "\n WHERE module = 'mod_mainmenu'" . "\n AND params LIKE '%{$old_menutype}%'";
            $database->setQuery($query);
            $modules = $database->loadResultArray();
            foreach ($modules as $module) {
                $row = new mosModule($database);
                $row->load($module);
                $save = 0;
                $pparser = new mosParameters($row->params);
                $params = $pparser->getParams();
                if ($params->menutype == $old_menutype) {
                    $params->menutype = $menutype;
                    $save = 1;
                }
                // save changes to module 'menutype' param
                if ($save) {
                    $txt = array();
                    foreach ($params as $k => $v) {
                        $txt[] = "{$k}={$v}";
                    }
                    $row->params = implode("\n", $txt);
                    // check then store data in db
                    if (!$row->check()) {
                        echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
                        exit;
                    }
                    if (!$row->store()) {
                        echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
                        exit;
                    }
                    $row->checkin();
                }
            }
            // change menutype of all menuitems using old menutype
            if ($menutype != $old_menutype) {
                $query = "UPDATE #__menu SET menutype = '{$menutype}' WHERE menutype = '{$old_menutype}'";
                $database->setQuery($query);
                $database->query();
            }
            $msg = T_('Menu Items & Modules updated');
            break;
    }
    mosRedirect('index2.php?option=com_menumanager', $msg);
}