4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Releases & Support) => Topic started by: IcEcReaM on January 20, 2006, 04:44:13 PM

Title: [MOD] Sort Categories in ACP by Number
Post by: IcEcReaM on January 20, 2006, 04:44:13 PM
Reffering to to this  Topic (http://www.4homepages.de/forum/index.php?topic=1531.0),
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: [Select]
$lang['cat_sort'] = "Kategorien sortieren";
$lang['cat_sort_success'] = "Kategorien erfolgreich sortiert";

or in english
Code: [Select]
$lang['cat_sort'] = "Sort Categories";
$lang['cat_sort_success'] = "Categories sucessfully sorted";



admin/categories.php

Above
######################
Code: [Select]
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;";
######################
insert:
######################
Code: [Select]
    /** 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 **/
######################

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

Above
######################
Code: [Select]
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:
######################
Code: [Select]
  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:
######################
Code: [Select]
  echo " <input type=\"submit\" value=\"".$lang['cat_sort']."\" class=\"button\" />";
  echo "</form>";
######################
---------------------------------------------------------------------------------
Above:
######################
Code: [Select]
if ($action == "modifycats") {######################
insert:
######################
Code: [Select]
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.

Title: Re: [MOD] Sort Categories by Number
Post by: TheOracle on January 20, 2006, 04:55:45 PM
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\">


could also be stated as :

Quote

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


Excellent codings. ;)
Title: Re: [MOD] Sort Categories in ACP by Number
Post by: mawenzi on January 20, 2006, 06:20:34 PM
@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 ...
Title: Re: [MOD] Sort Categories in ACP by Number
Post by: Loda on January 20, 2006, 07:55:08 PM
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.
Title: Re: [MOD] Sort Categories in ACP by Number
Post by: IcEcReaM on January 20, 2006, 07:58:49 PM
@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: [Select]
echo "<form action=\"".$PHP_SELF."\" name=\"sort_cat_form\"> \n";durch das zu ersetzen:

Code: [Select]
echo "<form method=\"post\" action=\"".$PHP_SELF."\" name=\"sort_cat_form\"> \n";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.

Title: Re: [MOD] Sort Categories in ACP by Number
Post by: TheOracle on January 20, 2006, 08:06:31 PM
Quote

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


Would you look at that ? How rude ! :oops: :D

Quote

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


Correct. ;)
Title: Re: [MOD] Sort Categories in ACP by Number
Post by: mawenzi on January 20, 2006, 11:59:43 PM
@IcEcReaM

...
Evtl. kannst du mal versuchen diese Zeile
Code: [Select]
echo "<form action=\"".$PHP_SELF."\" name=\"sort_cat_form\"> \n";durch das zu ersetzen:
Code: [Select]
echo "<form method=\"post\" action=\"".$PHP_SELF."\" name=\"sort_cat_form\"> \n";sollte aber eigentlich nicht daran liegen.
...

... und genau daran hat es gelegen ... mit nur dieser Änderung hat es sofort funktioniert ... bestens ... :D
... ich denke diese Änderung solltest du noch in die MOD-Beschreibung übernehmen ...

nochmals danke für diesen MOD ... mawenzi

@Loda
... hatte eigentlich schon alles richtig platziert ... incl. ACP-Kateorie -Einstellung  ...
... Änderung s.o. war bei mir noch notwendig ...

danke Loda
Title: Re: [MOD] Sort Categories in ACP by Number
Post by: V@no on January 21, 2006, 05:59:22 AM
Interesting mod :)
I have a question though. As I understand the administrator will be able manualy reorder the categories by selecting the order number from the dropdown options, correct? Now, the question: is there any "security" against possible conflict in the order? for example if more then one category gets same order option?
Title: Re: [MOD] Sort Categories in ACP by Number
Post by: IcEcReaM on January 21, 2006, 06:09:27 AM
Jep, there is.
May be i explained it in my first post not well.

This was the main problem.
The solution is that when two categories get the same order_option,
the script will correct this automaticlly by giving one of these categories a higher order_option,
and correct the following ones too by setting the following one step higher.
Using the reorder per cat_parent_id.
Title: Re: [MOD] Sort Categories in ACP by Number
Post by: JensF on January 22, 2006, 08:39:30 PM
hhmm,

ich muss wohl mal irgendwas anderes zum sortieren eingebaut haben :) Egal wie ich sortiere, es ist immer in alphabetischer Reihenfolge zu sehen. Im ACP wird das ganze zwar sortiert wie ich es haben will aber in den Kategorien bzw. auf der Startseite ist alles von a-z geordnet...

*EDIT*

OK, man sollte in den Einstellungen auch "manuell" anwählen :)
Title: Re: [MOD] Sort Categories in ACP by Number
Post by: cpuswe on March 01, 2006, 10:00:22 PM
Realy nice coding there!

But it does not work for me. Probably not because of the code, but limitations at my hosting company.

I get:

Request-URI Too Large
The requested URL's length exceeds the capacity limit for this server.

request failed: URI too long


I have to 590 categories. Although i dont know what happens in the script i can imagine that the server thinks "to much" when submitting that.

Is it possible to tweak the code in some way? Split category list on more than one page?

Thanks!

/Thomas

http://www.cpuphotolibrary.com