Author Topic: [MOD] Add Multiple Categories/Subcategories, one time with single Click!  (Read 29781 times)

0 Members and 1 Guest are viewing this topic.

Offline byrev

  • Pre-Newbie
  • Posts: 4
    • View Profile
With this modification you can add in "ACP -> Add Categories " several categories with one single click !


if i have 400 category i must lose days with simple procedure ... ;)
modify function for multiple category/subcategory one time, one click !!!

========= This is my modification code for this job ===========
Code: [Select]
  if (empty($error)) {
$cat_name_array = explode('|', $cat_name);
$cat_name_count = count($cat_name_array);
    for ($i=0;$i<$cat_name_count;$i++)
    {     
    $cat_name = $cat_name_array[$i];   
/** Start ADD **/
    if (!$cat_order) {         
      $sql = "SELECT cat_order
              FROM ".CATEGORIES_TABLE."
              WHERE cat_parent_id = $cat_parent_id
              ORDER BY cat_order DESC
              LIMIT 1";
      $catorder = $site_db->query_firstrow($sql);
      $cat_order = $catorder['cat_order'] + 10;
      $do_update_cat_order = 0;
    }
    else {
      $do_update_cat_order = 1;
    }
         
     $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)";
     $result = $site_db->query($sql);
     $cat_id = $site_db->get_insert_id();

     if ($result && $cat_id) {
      if ($do_update_cat_order) {
        update_cat_order($cat_parent_id);
      }
      $msg = $lang['cat_add_success'];
      create_cat_folder(MEDIA_PATH."/".$cat_id, CHMOD_DIRS);
      create_cat_folder(THUMB_PATH."/".$cat_id, CHMOD_DIRS);
     }
     else {
      $msg = $lang['cat_add_error'];
     }
     /** End ADD **/
     // echo $cat_name.' , ';
    } // end FOR!
    forward_to_modify($msg);   
  }

modification in: admin/categories.php
position: in body "savecat" action: if ($action == "savecat") {

so....
now you can enter categories like this example:
Animals|Cars|Bussines|Nature|Musical|Sports|Abstract|Art|People|Objects|Musical|Food|Education
and .. done ... 13 categories with only 1 click !!! ;)

This modification works here : http://www.findavatar.com

Edited by mawenzi :
- how to add the modification : here
- how to add APC description extension : here
« Last Edit: January 31, 2007, 04:24:25 PM by mawenzi »

Offline alemao59

  • Pre-Newbie
  • Posts: 3
    • View Profile
Re: Multiple Category/Subcategory, one time with single Clik!
« Reply #1 on: January 13, 2007, 08:21:00 PM »
hi,
where do i have tto add this code? do i need to replace anything? thanks

Offline byrev

  • Pre-Newbie
  • Posts: 4
    • View Profile
Re: Multiple Category/Subcategory, one time with single Clik!
« Reply #2 on: January 14, 2007, 11:05:22 AM »
in file: categories.php from admin folder  ( ./admin/categories.php )
find first aparence: if (empty($error)) {
for me i find this at line 502.
now form 502 to 537 you have this code:
Quote
  if (empty($error)) {
    if (!$cat_order) {
      $sql = "SELECT cat_order
              FROM ".CATEGORIES_TABLE."
              WHERE cat_parent_id = $cat_parent_id
              ORDER BY cat_order DESC
              LIMIT 1";
      $catorder = $site_db->query_firstrow($sql);
      $cat_order = $catorder['cat_order'] + 10;
      $do_update_cat_order = 0;
    }
    else {
      $do_update_cat_order = 1;
    }

    $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)";
    $result = $site_db->query($sql);
    $cat_id = $site_db->get_insert_id();

    if ($result && $cat_id) {
      if ($do_update_cat_order) {
        update_cat_order($cat_parent_id);
      }
      $msg = $lang['cat_add_success'];
      create_cat_folder(MEDIA_PATH."/".$cat_id, CHMOD_DIRS);
      create_cat_folder(THUMB_PATH."/".$cat_id, CHMOD_DIRS);
    }
    else {
      $msg = $lang['cat_add_error'];
    }
    //$action = "modifycats";
    forward_to_modify($msg);
  }

Replace code from line 502 to 537, with the next code:
Quote
  if (empty($error)) {
   $cat_name_array = explode('|', $cat_name);
   $cat_name_count = count($cat_name_array);
    for ($i=0;$i<$cat_name_count;$i++)
    {     
    $cat_name = $cat_name_array[$i];   
   /** Start ADD **/
    if (!$cat_order) {         
      $sql = "SELECT cat_order
              FROM ".CATEGORIES_TABLE."
              WHERE cat_parent_id = $cat_parent_id
              ORDER BY cat_order DESC
              LIMIT 1";
      $catorder = $site_db->query_firstrow($sql);
      $cat_order = $catorder['cat_order'] + 10;
      $do_update_cat_order = 0;
    }
    else {
      $do_update_cat_order = 1;
    }
         
     $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)";
     $result = $site_db->query($sql);
     $cat_id = $site_db->get_insert_id();

     if ($result && $cat_id) {
      if ($do_update_cat_order) {
        update_cat_order($cat_parent_id);
      }
      $msg = $lang['cat_add_success'];
      create_cat_folder(MEDIA_PATH."/".$cat_id, CHMOD_DIRS);
      create_cat_folder(THUMB_PATH."/".$cat_id, CHMOD_DIRS);
     }
     else {
      $msg = $lang['cat_add_error'];
     }
     /** End ADD **/
     // echo $cat_name.' , ';
    } // end FOR!
    forward_to_modify($msg);   
  }

Done... must be ok now !!!

Offline byrev

  • Pre-Newbie
  • Posts: 4
    • View Profile
Re: Multiple Category/Subcategory, one time with single Clik!
« Reply #3 on: January 14, 2007, 11:12:58 AM »
i see many scripts: cms, forum, blogs, gallery... no one have this modification... wtf, i am to smart for this job !!!
i made similar modification to wordpress, runcms, Jupiter CMS and ... other scripts !!! works all time :)

Offline trez

  • Hero Member
  • *****
  • Posts: 613
    • View Profile
    • blog / photography
Re: Multiple Category/Subcategory, one time with single Clik!
« Reply #4 on: January 31, 2007, 09:22:37 AM »
i see many scripts: cms, forum, blogs, gallery... no one have this modification... wtf, i am to smart for this job !!!
i made similar modification to wordpress, runcms, Jupiter CMS and ... other scripts !!! works all time :)

Oh, how good you bless us too with that modification  8)
At least can you tell a little bit more what this is about? I get a little confused.
It's a "multiple category maker" ? If yes, great job ;)

Offline mawenzi

  • Moderator
  • 4images Guru
  • *****
  • Posts: 4.500
    • View Profile
Re: Multiple Category/Subcategory, one time with single Clik!
« Reply #5 on: January 31, 2007, 03:07:09 PM »
@ byrev

... I've just tested your modification in ACP -> Add Categories ...
... it works great ...  :!:
... but we should add some description in ACP "Add Categories" ...
... so that in ACP everyone can read how to add multiple categories ...
Your first three "must do" before you ask a question ! ( © by V@no )
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

You are on search for top 4images MOD's ?
- then please search here ... Mawenzi's Top 100+ MOD List (unsorted sorted) ...

Offline mawenzi

  • Moderator
  • 4images Guru
  • *****
  • Posts: 4.500
    • View Profile
Re: [MOD] Multiple Category/Subcategory, one time with single Clik!
« Reply #6 on: January 31, 2007, 03:54:02 PM »
... my little description extension in APC, to know / to read how to add multiple categories ...  :wink:

1. Step
find in /admin/categories.php the following ...
Code: [Select]
show_input_row($lang['field_category_name'], "cat_name", "", $textinput_size);
and replace with ...
Code: [Select]
show_input_row($lang['field_category_name_ext'], "cat_name", "", $textinput_size);

2. Step - Deutsch
find in /lang/deutsch/admin.php in section //---Fields --- the following ...
Code: [Select]
$lang['field_category_name'] = "Kategorie Name";
and add after ...
Code: [Select]
$lang['field_category_name_ext'] = "Kategorie Name<br /><span class=\"smalltext\">Es können mehrere Kategorien hinzugefügt werden.<br>Dann sind die Kategorie-Namen durch | zu trennen. z.B. Test1|Test2|Test3</span>";

2. Step - English (only my insignificant English)
find in /lang/english/admin.php in section //---Fields --- the following ...
Code: [Select]
$lang['field_category_name'] = "Category name";
and add after ...
Code: [Select]
$lang['field_category_name_ext'] = "Category name<br /><span class=\"smalltext\">You can add several categories.<br>Then you must separate category names through | . e.g. Test1|Test2|Test3</span>";

... btw ... nice modification ...  :D

PS.
@  Acidgod ... dieser Topic kann nach Mods & Plugins verschoben werden ... Danke !
Your first three "must do" before you ask a question ! ( © by V@no )
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

You are on search for top 4images MOD's ?
- then please search here ... Mawenzi's Top 100+ MOD List (unsorted sorted) ...

Offline Acidgod

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 2.421
  • It's me?
    • View Profile
    • Flash-Webdesign
Re: [MOD] Multiple Category/Subcategory, one time with single Clik!
« Reply #7 on: January 31, 2007, 03:56:31 PM »
Gesagt getan... (o:

Offline Tiburon

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
    • http://www.hintergrundbilder.de
hm, it does not work in 1.7.4  :cry:
----------------------------------

Have a nice Day

Offline mawenzi

  • Moderator
  • 4images Guru
  • *****
  • Posts: 4.500
    • View Profile
... tested also on a version 1.7.4 ... and it works great ... ;)
Your first three "must do" before you ask a question ! ( © by V@no )
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

You are on search for top 4images MOD's ?
- then please search here ... Mawenzi's Top 100+ MOD List (unsorted sorted) ...

Offline Jenn

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Worked Beautifully on 1.7.4 as well :)

Thanks for this. Helps out alot.

Offline 4ella

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
    • http://www.dancersrecruit.com/pictures/
Great modification , works good in 1.7.6 too

http://www.dancersrecruit.com/pictures/
4IMAGES 1.7.6 version/default theme
Apache version   2.2.11 (Unix)
PHP version   5.2.9
MySQL version   5.0.75-community-log
Architecture   x86_64
Operating system   Linux

Offline truecolor

  • Pre-Newbie
  • Posts: 1
    • View Profile
simulation credit auto
This worked really well. Many thanks  8)

Offline khansahib

  • Full Member
  • ***
  • Posts: 100
    • View Profile
Re: [MOD] Add Multiple Categories/Subcategories, one time with single Click!
« Reply #13 on: December 28, 2010, 12:11:57 PM »
Amazing, You saved alot of my Time....
just a thought can same be done with adding description to the categories..

Like

cat1|cat2|cat3
desc1|desc2|desc3

Thanks :)

Offline Bodzio

  • Newbie
  • *
  • Posts: 36
  • BJ Fan
    • View Profile
    • Always - Bon Jovi Portal Gallery
Re: [MOD] Add Multiple Categories/Subcategories, one time with single Click!
« Reply #14 on: November 11, 2012, 10:08:24 PM »
Can anyone help?

The categories are not placed in order, when I add Test1|Test2 etc. it goes randomly after adding.

Can anyone help with thesame thing with adding many descriptions at once?
---
Best regards / Pozdrawiam serdecznie

Artur "Bodzio" Bogdański