function saveOrder(&$cid, $client)
{
    global $database;
    josSpoofCheck();
    $total = count($cid);
    $order = josGetArrayInts('order');
    $row = new mosModule($database);
    $conditions = array();
    // update ordering values
    for ($i = 0; $i < $total; $i++) {
        $row->load((int) $cid[$i]);
        if ($row->ordering != $order[$i]) {
            $row->ordering = $order[$i];
            if (!$row->store()) {
                echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
                exit;
            }
            // if
            // remember to updateOrder this group
            $condition = "position = " . $database->Quote($row->position) . " AND client_id = " . (int) $row->client_id;
            $found = false;
            foreach ($conditions as $cond) {
                if ($cond[1] == $condition) {
                    $found = true;
                    break;
                }
            }
            // if
            if (!$found) {
                $conditions[] = array($row->id, $condition);
            }
        }
        // if
    }
    // for
    // execute updateOrder for each group
    foreach ($conditions as $cond) {
        $row->load($cond[0]);
        $row->updateOrder($cond[1]);
    }
    // foreach
    mosCache::cleanCache('com_content');
    $msg = 'New ordering saved';
    mosRedirect('index2.php?option=com_modules&client=' . $client, $msg);
}
Exemple #2
0
function saveOrder(&$cid, $client)
{
    global $database;
    $order = mosGetParam($_POST, 'order', array(0));
    $row = new mosModule($database);
    $positions = array();
    // update ordering values
    foreach ($cid as $i => $ciditem) {
        $row->load($ciditem);
        if ($row->ordering != $order[$i]) {
            $row->ordering = $order[$i];
            if (!$row->store()) {
                echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
                exit;
            }
            // remember to updateOrder this group
            $positions[$row->position][$row->client_id] = $row->id;
        }
    }
    // execute updateOrder for each group
    foreach ($positions as $position => $clients) {
        foreach ($clients as $client => $rowid) {
            $row->updateOrder("position = '{$position}' AND client_id = '{$client}'");
        }
    }
    // foreach
    $msg = T_('New ordering saved');
    mosRedirect('index2.php?option=com_modules&client=' . $client, $msg);
}
Exemple #3
0
/**
* Copies a complete menu, all its items and creates a new module, using the name speified
*/
function copyMenu($option, $cid, $menu_name, $type)
{
    global $database, $adminLanguage;
    $mids = mosGetParam($_POST, 'mids', '');
    // create the module copy
    foreach ($cid as $id) {
        $row = new mosModule($database);
        $row->load($id);
        $row->title = $menu_name;
        $row->iscore = 0;
        $row->published = 0;
        $row->position = "left";
        $row->module = "mod_mainmenu";
        $row->params = "menutype=" . $menu_name . "";
        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 . "'");
    }
    $total = count($mids);
    $copy = new mosMenu($database);
    $original = new mosMenu($database);
    foreach ($mids as $mid) {
        $original->load($mid);
        $copy = $original;
        $copy->id = NULL;
        $copy->menutype = $menu_name;
        if (!$copy->check()) {
            echo "<script> alert('" . $copy->getError() . "'); window.history.go(-1); </script>\n";
            exit;
        }
        if (!$copy->store()) {
            echo "<script> alert('" . $copy->getError() . "'); window.history.go(-1); </script>\n";
            exit;
        }
    }
    $msg = $adminLanguage->A_COMP_MENU_COPY_OF . " `" . $type . "` " . $adminLanguage->A_COMP_MENU_CONSIST . " " . $total . " " . $adminLanguage->A_COMP_ITEMS;
    mosRedirect("index2.php?option=com_menumanager&mosmsg=" . $msg . "");
}
Exemple #4
0
/**
* Deletes one or more modules
*
* Also deletes associated entries in the #__module_menu table.
* @param array An array of unique category id numbers
*/
function removeModule(&$cid, $option, $client)
{
    global $database, $my, $adminLanguage;
    if (count($cid) < 1) {
        echo "<script> alert(\"" . $adminLanguage->A_COMP_MAMB_DEL . "\"); window.history.go(-1);</script>\n";
        exit;
    }
    $cids = implode(',', $cid);
    $database->setQuery("SELECT id, module, title, iscore FROM #__modules WHERE id IN ({$cids})");
    if (!($rows = $database->loadObjectList())) {
        echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
    }
    $err = array();
    $cid = array();
    foreach ($rows as $row) {
        if ($row->module == '' || $row->iscore == 0) {
            $cid[] = $row->id;
        } else {
            $err[] = $row->title;
        }
    }
    if (count($cid)) {
        $cids = implode(',', $cid);
        $database->setQuery("DELETE FROM #__modules WHERE id IN ({$cids})");
        if (!$database->query()) {
            echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
            exit;
        }
        $database->setQuery("DELETE from #__modules_menu WHERE moduleid IN ({$cids})");
        if (!$database->query()) {
            echo "<script> alert('" . $database->getErrorMsg() . "');</script>\n";
            exit;
        }
        $mod = new mosModule($database);
        $mod->ordering = 0;
        $mod->updateOrder("position='left'");
        $mod->updateOrder("position='right'");
    }
    if (count($err)) {
        $cids = addslashes(implode("', '", $err));
        echo "<script>alert(\"" . $adminLanguage->A_COMP_MOD_MODULES . ": '" . $cids . "' " . $adminLanguage->A_COMP_MOD_CANNOT . "\");</script>\n";
    }
    mosRedirect('index2.php?option=' . $option . '&client=' . $client);
}
/**
* Copies a complete menu, all its items and creates a new module, using the name speified
*/
function copyMenu($option, $cid, $type)
{
    global $database;
    josSpoofCheck();
    $menu_name = stripslashes(strval(mosGetParam($_POST, 'menu_name', 'New Menu')));
    $module_name = stripslashes(strval(mosGetParam($_POST, 'module_name', 'New Module')));
    // check for unique menutype for new menu copy
    $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 == $menu_name) {
            echo "<script> alert('A menu already exists with that name - you must enter a unique Menu Name'); window.history.go(-1); </script>\n";
            exit;
        }
    }
    // copy the menu items
    $mids = josGetArrayInts('mids');
    $total = count($mids);
    $copy = new mosMenu($database);
    $original = new mosMenu($database);
    sort($mids);
    $a_ids = array();
    foreach ($mids as $mid) {
        $original->load($mid);
        $copy = $original;
        $copy->id = NULL;
        $copy->parent = $a_ids[$original->parent];
        $copy->menutype = $menu_name;
        if (!$copy->check()) {
            echo "<script> alert('" . $copy->getError() . "'); window.history.go(-1); </script>\n";
            exit;
        }
        if (!$copy->store()) {
            echo "<script> alert('" . $copy->getError() . "'); window.history.go(-1); </script>\n";
            exit;
        }
        $a_ids[$original->id] = $copy->id;
    }
    // create the module copy
    $row = new mosModule($database);
    $row->load(0);
    $row->title = $module_name;
    $row->iscore = 0;
    $row->published = 1;
    $row->position = 'left';
    $row->module = 'mod_mainmenu';
    $row->params = 'menutype=' . $menu_name;
    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;
    }
    // clean any existing cache files
    mosCache::cleanCache('com_content');
    $msg = 'Copy of Menu `' . $type . '` created, consisting of ' . $total . ' items';
    mosRedirect('index2.php?option=' . $option, $msg);
}
/**
* Copies a complete menu, all its items and creates a new module, using the name speified
*/
function copyMenu($option, $cid, $type)
{
    global $database;
    $menu_name = mosGetParam($_POST, 'menu_name', 'New Menu');
    $module_name = mosGetParam($_POST, 'module_name', 'New Module');
    // check for unique menutype for new menu copy
    $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 == $menu_name) {
            echo "<script> alert('" . T_('A menu with that name already exists - you must enter a unique Menu Name') . "'); window.history.go(-1); </script>\n";
            exit;
        }
    }
    // copy the menu items
    $mids = mosGetParam($_POST, 'mids', '');
    $total = count($mids);
    $copy = new mosMenu($database);
    $original = new mosMenu($database);
    sort($mids);
    $a_ids = array();
    foreach ($mids as $mid) {
        $original->load($mid);
        $copy = $original;
        $copy->id = NULL;
        $copy->parent = $a_ids[$original->parent];
        $copy->menutype = $menu_name;
        if (!$copy->check()) {
            echo "<script> alert('" . $copy->getError() . "'); window.history.go(-1); </script>\n";
            exit;
        }
        if (!$copy->store()) {
            echo "<script> alert('" . $copy->getError() . "'); window.history.go(-1); </script>\n";
            exit;
        }
        $a_ids[$original->id] = $copy->id;
    }
    // create the module copy
    $row = new mosModule($database);
    $row->load(0);
    $row->title = $module_name;
    $row->iscore = 0;
    $row->published = 1;
    $row->position = 'left';
    $row->module = 'mod_mainmenu';
    $row->params = 'menutype=' . $menu_name;
    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(Tn_('Copy of Menu `%s` created, consisting of %d item', 'Copy of Menu `%s` created, consisting of %d items', $total), $type, $total);
    mosRedirect('index2.php?option=' . $option, $msg);
}