4images Modifications / Modifikationen > Mods & Plugins (Releases & Support)

[MOD] Sort Categories in ACP by Number

(1/3) > >>

IcEcReaM:
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

--- Code: ---$lang['cat_sort'] = "Kategorien sortieren";
$lang['cat_sort_success'] = "Kategorien erfolgreich sortiert";
--- End code ---

or in english

--- Code: ---$lang['cat_sort'] = "Sort Categories";
$lang['cat_sort_success'] = "Categories sucessfully sorted";
--- End code ---



admin/categories.php

Above
######################

--- Code: ---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'].")&nbsp;&nbsp;&nbsp;&nbsp;";
--- End code ---
######################
insert:
######################

--- Code: ---    /** 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>&nbsp;&nbsp;\n";
    /** Cat Order By Number Mod **/
--- End code ---
######################

---------------------------------------------------------------------------------

Above
######################

--- Code: ---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";
--- End code ---
######################
insert:
######################

--- Code: ---  echo "<form action=\"".$PHP_SELF."\" name=\"sort_cat_form\"> \n";
  echo "<input type=\"hidden\" name=\"action\" value=\"sort_cat\" /> \n";
--- End code ---
######################
---------------------------------------------------------------------------------

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:
######################

--- Code: ---  echo " <input type=\"submit\" value=\"".$lang['cat_sort']."\" class=\"button\" />";
  echo "</form>";
--- End code ---
######################
---------------------------------------------------------------------------------
Above:
######################

--- Code: ---if ($action == "modifycats") {
--- End code ---
######################
insert:
######################

--- Code: ---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";
}
--- End code ---
######################

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.

TheOracle:
Well, isn't that a nice MOD ? :D

It has been requested for sometime now. Thanks for posting this.

However, not that it really matters but :


--- Quote ---
<a href=\"".$site_sess->url(ROOT_PATH."categories.php?cat_id=".$cats['cat_id'])."\" target=\"_blank\">


--- End quote ---

could also be stated as :


--- Quote ---
<a href=\"".$site_sess->url(ROOT_PATH."categories.php?&amp;".URL_CAT_ID)."\" target=\"_blank\">


--- End quote ---

Excellent codings. ;)

mawenzi:
@IcEcReaM,

... tolle Erweiterung dieser ACP-MOD ... gleich in der Kategorien-Übersicht ... für den Totalumbau der Galerie ...  :wink:
... die einzelnen Kategorien ließen sich ja schon komfortabel mit der Erweiterung von Jan verschieben ...
... habe wegen der Eindeutigkeit die Überschrift geändert ( ... in ACP ... ) ...

danke ... mawenzi

Edit :
... habe den MOD soweit installiert, doch nach der Betätigung des Buttons "Kategorien sortieren" passiert rein garnichts ...  :?
... $action == "sort_cat" wird durch das "Form" nicht aktiviert ...
... bitte nochmals die Installationsanweisung nachvollziehen (Inhalt, Reihenfolge, Above, After) ... und ggf. berichtigen ...
... der language-Eintrag ist event. in der lang/your_language/admin.php besser aufgehoben ...
... danke ...

Loda:
hallo!
zuerst ging bei mir auch nix.. bitte nehme den untersten eintrag des show_table_footer();, bei mir ging es danach.
in der Kategorien-Einstellung im ACP muss es auf "manuell" stehen.

IcEcReaM:
@TheOracle:
This piece of code is the original code from 4images.
i didn't changed that.

@mawenzi:
Habs sicherheitshalber nochmal selbst in nem frisch installierten Board getestet nach der geposteten Anleitung.
Bei mir klappts soweit einwandfrei.

Evtl. kannst du mal versuchen diese Zeile


--- Code: ---echo "<form action=\"".$PHP_SELF."\" name=\"sort_cat_form\"> \n";
--- End code ---
durch das zu ersetzen:


--- Code: ---echo "<form method=\"post\" action=\"".$PHP_SELF."\" name=\"sort_cat_form\"> \n";
--- End code ---
sollte aber eigentlich nicht daran liegen.


P.S.: Hab den Post oben editiert wegen der Language Files...klenie Verwechslung..^^



Edit:

Modified the description in the first post.
I forgot that the code "show_table_footer();" can be find just more than one time.

Navigation

[0] Message Index

[#] Next page

Go to full version