Author Topic: [Mod] Create Sort Order for each category from Admin Panel  (Read 92659 times)

0 Members and 1 Guest are viewing this topic.

Offline Fugaziman

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
    • http://www.1024x768wallpapers.com
[Mod] Create Sort Order for each category from Admin Panel
« on: April 07, 2003, 04:39:23 AM »
This Mod will allow each category to have it's own Sort Order.

I created this so that some of my categories can be displayed in sequence using the image name but others I just want to display with the latest first ie. using date_order.

Two things to note:
1) It stops the default Sort order set using the Admin Panel - Settings Page.
2) The Mod in this forum for allowing users to select their own sort order will not work on the Categories page. However it will still work in the Search and New Images pages (same page really)

The Mod it quite easy to install but make sure you backup/make copy of your files first. Just in case  :D

Step 1.  :arrow:  Add 2 new fields to your categories table
sort_order  varchar(5)   Default "ASC"
sort_field    varchar(20) Default "image_name"

Thanks to V@no (Helps us unfortunate newbies all the time  :D )
Heres the link for the DB installer..
Category Sort Install
Just download the zip file, unzip it to your root directory and call it from your browser.
 
Step 2.  :arrow:  Backup ./global.php
   Edit ./global.php

4images v1.7
Search for ...
Code: [Select]
 $sql = "SELECT c.cat_id, c.cat_name, c.cat_description, c.cat_parent_id, c.cat_hits, c.cat_order, c.auth_viewcat, c.auth_viewimage, c.auth_download, c.auth_upload, c.auth_directupload, c.auth_vote, c.auth_sendpostcard, c.auth_readcomment, c.auth_postcomment, COUNT(i.image_id) AS new_images
          FROM ".CATEGORIES_TABLE." c
          LEFT JOIN ".IMAGES_TABLE." i ON (i.cat_id = c.cat_id AND i.image_date >= $new_cutoff AND i.image_active = 1)
          GROUP BY c.cat_id
          ORDER BY c.cat_order, c.cat_name ASC";

Replace with ...

Code: [Select]
 $sql = "SELECT c.cat_id, c.cat_name, c.cat_description, c.cat_parent_id, c.cat_hits, c.cat_order, c.auth_viewcat, c.auth_viewimage, c.auth_download, c.auth_upload, c.auth_directupload, c.auth_vote, c.auth_sendpostcard, c.auth_readcomment, c.auth_postcomment, c.sort_order, c.sort_field, COUNT(i.image_id) AS new_images
          FROM ".CATEGORIES_TABLE." c
          LEFT JOIN ".IMAGES_TABLE." i ON (i.cat_id = c.cat_id AND i.image_date >= $new_cutoff AND i.image_active = 1)
          GROUP BY c.cat_id
          ORDER BY c.cat_order, c.cat_name ASC";

4images v1.7.1

Search for ...
Code: [Select]
  $sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
Replace with ...
Code: [Select]
  $sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, sort_order, sort_field

Step 3.  :arrow:  Backup ./categories.php
   Edit ./categories.php
Search for sql line containing ...
Code: [Select]
ORDER BY
Replace Whole Line with...
Code: [Select]
       ORDER BY ".$cat_cache[$cat_id]['sort_field']." ".$cat_cache[$cat_id]['sort_order']."
Step 4.  :arrow:  Backup ./lang/yourlang/admin.php
   Edit ./lang/yourlang/admin.php
Insert just ABOVE
Code: [Select]
?> at end of page

Code: [Select]
//--------------Images Sort-------------------------
//---Used by Category Sort Option Mod            ---
//--------------------------------------------------
$lang['image_order'] = "Sort images by";
$image_order_optionlist = array(
  "image_name"      => "Name",
  "image_date"      => "Date",
  "image_downloads" => "Downloads",
  "image_votes"     => "Votes",
  "image_rating"    => "Rating",
  "image_hits"      => "Hits"
);
$lang['image_sort'] = "Ascending/Descending";
$image_sort_optionlist = array(
  "ASC"  => "Ascending",
  "DESC" => "Descending"
);
//--------------------------------------------------
//---End of Category Sort Option Mod             ---
//--------------------------------------------------

Step 5.  :arrow: Backup ./admin/categories.php
   Edit ./admin/categories.php

Search for ...
Code: [Select]
if ($action == "savecat") {
  $error = array();
  $cat_name = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_name']));
  $cat_description = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_description']));
  $cat_parent_id = intval($HTTP_POST_VARS['cat_parent_id']);
  $cat_order = (isset($HTTP_POST_VARS['cat_order'])) ? intval($HTTP_POST_VARS['cat_order']) : 0;
 
Immediatley After INSERT these 2 lines...
Code: [Select]
 $sort_order = trim($HTTP_POST_VARS['imagesradio']);
  $sort_field = trim($HTTP_POST_VARS['imagesorder']);

Search for ...
Code: [Select]
   $sql = "INSERT INTO ".CATEGORIES_TABLE."
            (cat_name, cat_description, cat_parent_id, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment)
            VALUES
            ('$cat_name', '$cat_description', $cat_parent_id, $cat_order, $auth_viewcat, $auth_viewimage, $auth_download, $auth_upload, $auth_directupload, $auth_vote, $auth_sendpostcard, $auth_readcomment, $auth_postcomment)";

Replace with ...
Code: [Select]
   $sql = "INSERT INTO ".CATEGORIES_TABLE."
            (cat_name, cat_description, cat_parent_id, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, sort_order, sort_field)
            VALUES
            ('$cat_name', '$cat_description', $cat_parent_id, $cat_order, $auth_viewcat, $auth_viewimage, $auth_download, $auth_upload, $auth_directupload, $auth_vote, $auth_sendpostcard, $auth_readcomment, $auth_postcomment, '$sort_order', '$sort_field')";

Search for ...
Code: [Select]
 show_textarea_row($lang['field_description_ext'], "cat_description", "", $textarea_size);  
Immediatley After, INSERT this...
Code: [Select]
 $imgsort_dropdown="\n<select name=\"imagesorder\" class=\"setperpageselect\">\n";
  foreach ($image_order_optionlist as $key => $val) {
    $imgsort_dropdown .= "<option value=\"$key\"";
    if ($config['image_order'] == $key) {
      $imgsort_dropdown .= " selected=\"selected\"";
    }
    $imgsort_dropdown .= ">".$val."</option>\n";
  }
  $imgsort_dropdown .= "</select>\n";
  
  foreach ($image_sort_optionlist as $key => $val) {
  $imgsort_radio .= "<INPUT type=\"radio\" name=\"imagesradio\" value=\"$key\"";
  if ($config['image_sort'] == $key) {
      $imgsort_radio .= " checked";
  }
  $imgsort_radio .= ">".$val."\n";
  }
  show_custom_row($lang['image_order'], $imgsort_dropdown);
  show_custom_row($lang['image_sort'], $imgsort_radio);

Search for ...
Code: [Select]
if ($action == "savecat") {
  $error = array();
  $cat_name = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_name']));
  $cat_description = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_description']));
  $cat_parent_id = intval($HTTP_POST_VARS['cat_parent_id']);
  $cat_order = (isset($HTTP_POST_VARS['cat_order'])) ? intval($HTTP_POST_VARS['cat_order']) : 0;

Immediatley After, INSERT this...
Code: [Select]
 $sort_order = trim($HTTP_POST_VARS['imagesradio']);
  $sort_field = trim($HTTP_POST_VARS['imagesorder']);

Search for ...
Code: [Select]
if ($action == "updatecat") {
  $error = array();
  $cat_id = (isset($HTTP_POST_VARS['cat_id'])) ? intval($HTTP_POST_VARS['cat_id']) : intval($HTTP_GET_VARS['cat_id']);
  $cat_parent_id = intval($HTTP_POST_VARS['cat_parent_id']);
  $cat_name = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_name']));
  $cat_description = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_description']));
  $cat_hits = intval(trim($HTTP_POST_VARS['cat_hits']));
  $cat_order = (isset($HTTP_POST_VARS['cat_order'])) ? intval($HTTP_POST_VARS['cat_order']) : 0;
 
Immediatley After, INSERT this...
Code: [Select]
 $sort_order = trim($HTTP_POST_VARS['imagesradio']);
  $sort_field = trim($HTTP_POST_VARS['imagesorder']);
 
Search for ...
Code: [Select]
   $sql = "UPDATE ".CATEGORIES_TABLE."
            SET cat_name = '$cat_name', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, cat_order = $cat_order, cat_hits = $cat_hits, auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcomment
            WHERE cat_id = $cat_id";
           
Replace with ...
Code: [Select]
   $sql = "UPDATE ".CATEGORIES_TABLE."
            SET cat_name = '$cat_name', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, cat_order = $cat_order, cat_hits = $cat_hits, auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcomment, sort_order = '$sort_order', sort_field = '$sort_field'
            WHERE cat_id = $cat_id";
           
Search for ...
Code: [Select]
 $sql = "SELECT cat_name, cat_description, cat_parent_id, cat_order, cat_hits, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
          FROM ".CATEGORIES_TABLE."
          WHERE cat_id = $cat_id";
         
Replace with ...
Code: [Select]
 $sql = "SELECT cat_name, cat_description, cat_parent_id, cat_order, cat_hits, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, sort_order, sort_field
          FROM ".CATEGORIES_TABLE."
          WHERE cat_id = $cat_id";
         
Search for ...
Code: [Select]
 show_textarea_row($lang['field_description_ext'], "cat_description", $cat_row['cat_description'], $textarea_size);
Immediatley After INSERT this ...
Code: [Select]
 $imgsort_dropdown="\n<select name=\"imagesorder\" class=\"setperpageselect\">\n";
  foreach ($image_order_optionlist as $key => $val) {
    $imgsort_dropdown .= "<option value=\"$key\"";
    if ($cat_row['sort_field'] == $key) {
      $imgsort_dropdown .= " selected=\"selected\"";
    }
    $imgsort_dropdown .= ">".$val."</option>\n";
  }
  $imgsort_dropdown .= "</select>\n";
  
  foreach ($image_sort_optionlist as $key => $val) {
  $imgsort_radio .= "<INPUT type=\"radio\" name=\"imagesradio\" value=\"$key\"";
  if ($cat_row['sort_order'] == $key) {
      $imgsort_radio .= " checked";
  }
  $imgsort_radio .= ">".$val."\n";
  }
  show_custom_row($lang['image_order'], $imgsort_dropdown);
  show_custom_row($lang['image_sort'], $imgsort_radio);
 
Search for ...
Code: [Select]
if ($action == "modifycats") {
  if ($msg != "") {
    printf("<b>%s</b>\n<p>", $msg);
  }
  $sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
          FROM ".CATEGORIES_TABLE."
          ORDER BY cat_order, cat_name ASC";
  $result = $site_db->query($sql);

Replace with ....
Code: [Select]
if ($action == "modifycats") {
  if ($msg != "") {
    printf("<b>%s</b>\n<p>", $msg);
  }
  $sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, sort_order, sort_field
          FROM ".CATEGORIES_TABLE."
          ORDER BY cat_order, cat_name ASC";
  $result = $site_db->query($sql);

THAT'S IT PEOPLE.
Now just go into your Admin Panel - Edit Categories and set your sort orders. If you created the 2 extra table fields above the default sort order for all existing categories will be image_name ASC.

Good luck  8)
Fugaziman
« Last Edit: August 15, 2005, 02:13:53 PM by V@no »
Please take time to visit us at ...
http://www.1024x768wallpapers.com
And don't forget to leave a comment or message.

Offline toto1

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
    • http://www.gifanimer.com
[Mod] Create Sort Order for each category from Admin Panel
« Reply #1 on: May 08, 2003, 02:31:33 PM »
excellent thk :D  :D

Offline lakeside

  • Full Member
  • ***
  • Posts: 123
    • View Profile
[Mod] Create Sort Order for each category from Admin Panel
« Reply #2 on: May 11, 2003, 12:00:46 AM »
Have a problem
When I run install_cat_sort.php I get the following error:
Code: [Select]
DB Error: Bad SQL Query: ALTER TABLE 4imagesg_categories ADD `sort_order` VARCHAR( 5 ) DEFAULT 'ASC' NOT NULL , ADD `sort_field` VARCHAR( 20 ) DEFAULT 'image_name' NOT NULL ;
You have an error in your SQL syntax near '; ' at line 1


What has caused this please?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Create Sort Order for each category from Admin Panel
« Reply #3 on: May 11, 2003, 12:43:09 AM »
Quote from: lakeside
Have a problem
When I run install_cat_sort.php

try to delete semicolon:
Quote
NOT NULL ;
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline helluvaguy

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
[Mod] Create Sort Order for each category from Admin Panel
« Reply #4 on: May 11, 2003, 11:14:54 AM »
This is a really fine mod, thx.

I was just wondering, if this one "bug" is happening only to my or if others experience the same thing.

When I'm changing the sortorder for a category in the ACP, this categorie "jumps" to the 1st place on this level, eventhough it was last in the list before.

Can anyone tell me something about that.

Offline helluvaguy

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
[Mod] Create Sort Order for each category from Admin Panel
« Reply #5 on: May 11, 2003, 01:51:47 PM »
By the way is ths mod compatible with v@nos [Mod] Let visitors to chose how to sort images(date,name,..) ?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Create Sort Order for each category from Admin Panel
« Reply #6 on: May 11, 2003, 02:49:55 PM »
yes, its working in a different way ;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline helluvaguy

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
[Mod] Create Sort Order for each category from Admin Panel
« Reply #7 on: May 11, 2003, 06:27:46 PM »
Quote from: V@no
yes, its working in a different way ;)

Meaning :?:

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Create Sort Order for each category from Admin Panel
« Reply #8 on: May 11, 2003, 07:09:53 PM »
meaning "just dont worry" hehe :lol: ;)
sereously those two mods are do compleately different things, and can not affect each other.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline jarano

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: [Mod] Create Sort Order for each category from Admin Panel
« Reply #9 on: May 04, 2005, 05:19:37 PM »
Hola!!
Se me cayó el cielo! No puedo entrar al Panel de Control y mi web está llena de mensajes de errores....como este:

Warning: mysql_fetch_array(): 7 is not a valid MySQL result resource in /home/celeper/public_html/galeria/includes/db_mysql.php on line 92

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/celeper/public_html/galeria/includes/db_mysql.php:92) in /home/celeper/public_html/galeria/includes/sessions.php on line 84

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/celeper/public_html/galeria/includes/db_mysql.php:92) in /home/celeper/public_html/galeria/includes/sessions.php on line 84

Warning: Cannot modify header information - headers already sent by (output started at /home/celeper/public_html/galeria/includes/db_mysql.php:92) in /home/celeper/public_html/galeria/includes/sessions.php on line 92

Warning: Cannot modify header information - headers already sent by (output started at /home/celeper/public_html/galeria/includes/db_mysql.php:92) in /home/celeper/public_html/galeria/includes/sessions.php on line 92

Warning: Cannot modify header information - headers already sent by (output started at /home/celeper/public_html/galeria/includes/db_mysql.php:92) in /home/celeper/public_html/galeria/includes/sessions.php on line 92

no puedo desinstalar el install_cat_xx que puse en la base de datos. Como puedo desinstalarlo o que debo corregir? Please...mi web es una desgracia...mirenla...http://www.celebridadesperuanas.com/galeria
Help...glu...glu...glugggg.....

Offline Josef Florian

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: [Mod] Create Sort Order for each category from Admin Panel
« Reply #10 on: May 18, 2005, 09:00:10 AM »
When i try STEP 1 to search for

Code: [Select]
...c.cat_id, c.cat_name, c.cat_description, c.cat_parent_id, c.cat_hits...
i can't find this string!


Since a few days, i know that in version 1.7.1 is a modification of this c.cat_id

What should i do, to install that mod on version 1.7.1?

LieGrü
Josef Florian
    • running v1.7.6 with MOD: SortImageAsYouLike / Cooliris Slideshow
    • with © removal
    • i have problems with:
actually no[/list]

Offline Sopur

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
    • Bilder des Harassenlaufs in Basel
Re: [Mod] Create Sort Order for each category from Admin Panel
« Reply #11 on: May 25, 2005, 05:01:23 PM »
Hello!
I can't find the database installer. Can I do the mod anyway?
Regards
Sopur

Offline tobiasth

  • Pre-Newbie
  • Posts: 7
    • View Profile
Re: [Mod] Create Sort Order for each category from Admin Panel
« Reply #12 on: June 20, 2005, 10:18:33 PM »
What should i do, to install that mod on version 1.7.1?

are there any solutions? would be great if this is working with v1.7.1! plz, we need your help :wink:

thx!

Offline marod0er

  • Full Member
  • ***
  • Posts: 199
    • View Profile
Re: [Mod] Create Sort Order for each category from Admin Panel
« Reply #13 on: June 24, 2005, 08:46:11 PM »
Great MOD, thanks!
Greetz: Lasse

Offline tobiasth

  • Pre-Newbie
  • Posts: 7
    • View Profile
Re: [Mod] Create Sort Order for each category from Admin Panel
« Reply #14 on: June 27, 2005, 11:39:50 PM »
hey guys!

this is not working with v1.7.1, can anyone fix it ? many thx!

cya,
tobi