Reffering to
to this Topic,
i made a litte Mod.
Now it's possible to order the Categories by Numbers in one step instead of Using Moving Up/Down each Categorie.
For Users with many Categories this might be a useful help.
Because i use 4images just a week, i hope there is no critical error in this script.
In German:
Dieses kleine Addon ermöglicht es die Kategorien nun nicht mehr nur mit nach oben und unten Pfeilen der Reihenfolge nach zu sortireren, sonderen alles auf einmal, indem man kleine DropDowns hat und sie einfach per Nummer sortiert.
Just 2 Files to edit:
lang/your language/admin.php
After
//--- Categories --------------------------------------
insert
$lang['cat_sort'] = "Kategorien sortieren";
$lang['cat_sort_success'] = "Kategorien erfolgreich sortiert";
or in english
$lang['cat_sort'] = "Sort Categories";
$lang['cat_sort_success'] = "Categories sucessfully sorted";
admin/categories.php
Above
######################
echo "<img src=\"".ROOT_PATH."admin/images/folder.gif\" alt=\"\"><b><a
href=\"".$site_sess->url(ROOT_PATH."categories.php?cat_id=".$cats['cat_id'])."\"
target=\"_blank\">".$cats['cat_name']."</a>\n</b> (ID: ".$cats['cat_id'].") ";
######################
insert:
######################
/** Cat Order By Number Mod **/
echo "<select name=\"catorder[".$cats['cat_id']."]\">\n";
for($i = 1; $i <= count ($category_cache[$cid]); $i++) { // Options erstellen
$selected = "";
if ($i == ($cats['cat_order']/10)) $selected = " selected";
echo "<option value=\"".($i*10)."\"$selected>$i</option>\n";
}
echo " </select> \n";
/** Cat Order By Number Mod **/
######################
---------------------------------------------------------------------------------
Above
######################
echo "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\" align=\"center\"><tr><td class=\"tableborder\">\n<table cellpadding=\"3\" cellspacing=\"1\" border=\"0\" width=\"100%\">\n";
######################
insert:
######################
echo "<form action=\"".$PHP_SELF."\" name=\"sort_cat_form\"> \n";
echo "<input type=\"hidden\" name=\"action\" value=\"sort_cat\" /> \n";
######################
---------------------------------------------------------------------------------
After: the last one you find
Because show_table_footer(); can be find more than one time.
( in the section of : $action == "modifycats")
######################
show_table_footer();
######################
insert:
######################
echo " <input type=\"submit\" value=\"".$lang['cat_sort']."\" class=\"button\" />";
echo "</form>";
######################
---------------------------------------------------------------------------------
Above:
######################
if ($action == "modifycats") {
######################
insert:
######################
if ($action == "sort_cat") {
$catorder = (isset($HTTP_POST_VARS['catorder'])) ? $HTTP_POST_VARS['catorder'] : $HTTP_GET_VARS['catorder'];
reset($catorder);
while(list($key,$val)=each($catorder)) {
$sql = "UPDATE ".CATEGORIES_TABLE."
SET cat_order = '$val'
WHERE cat_id = '$key'";
$result = $site_db->query($sql);
}
//Nachfolgender Code überprüft falsch einträge
$tmp_cat_parent_id ="";
$sql2 = "SELECT cat_parent_id
FROM ".CATEGORIES_TABLE."
ORDER BY cat_parent_id ASC";
$result2 = $site_db->query($sql2);
while ($row2 = $site_db->fetch_array($result2)) {
if ($tmp_cat_parent_id != $row2['cat_parent_id']) {
update_cat_order($row2['cat_parent_id']); // hier die Update Funktion
}
$tmp_cat_parent_id = $row2['cat_parent_id'];
}
$msg = ($result) ? $lang['cat_sort_success'] : $lang['cat_edit_error'];
$action = "modifycats";
}
######################
Thats all.
If a User makes a mistake and e.g. gives two categories the same number,
the script will correct this automaticlly and will also sort the following categories correct the right cat_order.
Would be nice if the pro coders here could give some comments
if the code is well enough or maybe could be optimized.