• [MOD] Apply permission to sub-categories from their parent category 5 0 5 1
Currently:  

Author Topic: [MOD] Apply permission to sub-categories from their parent category  (Read 84780 times)

0 Members and 1 Guest are viewing this topic.

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
With this mod you will be able apply category permissions including it's sub-categories.

----------- [ Installation ] ---------------
Step 1
Open admin/categories.php
Find:
Code: [Select]
  $auth_postcomment = $HTTP_POST_VARS['auth_postcomment'];Insert below:
Code: [Select]
/*
  MOD SUBCAT PERM FROM PARENT
  BEGIN INSERT
*/
  $subcats = (isset($HTTP_POST_VARS['subcats']) && $HTTP_POST_VARS['subcats']) ? 1 : 0;
/*
  MOD SUBCAT PERM FROM PARENT
  END INSERT
*/


Step 1.1
Find:
Code: [Select]
    $msg = ($result) ? $lang['cat_edit_success'] : $lang['cat_edit_error'];Insert above:
(for 4images v1.7/1.7.1 only!)
Code: [Select]
/*
  MOD SUBCAT PERM FROM PARENT
  BEGIN INSERT
*/
    if ($subcats)
    {
      function get_subcategories_id($cat_id = 0)
      {
        global $subcat_ids, $cat_parent_cache;
     
        if (!isset($cat_parent_cache[$cat_id]))
        {
          return false;
        }
        foreach ($cat_parent_cache[$cat_id] as $key => $val)
        {
          $subcat_ids[] = $val;
          get_subcategories_id($val);
        }
        return $subcat_ids;
      }
      $subcat_ids = array();
      $subcat_ids = get_subcategories_id($cat_id);
      if (!empty($subcat_ids))
      {
        $sql = "UPDATE ".CATEGORIES_TABLE."
                SET 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 IN (".implode($subcat_ids, ",").")";
        $result = $site_db->query($sql);
      }
    }
/*
  MOD SUBCAT PERM FROM PARENT
  END INSERT
*/

(for 4images v1.7.2 and newer)
Code: [Select]
/*
  MOD SUBCAT PERM FROM PARENT
  BEGIN INSERT
*/
    if ($subcats)
    {
      $subcat_ids = array();
      $subcat_ids = get_subcategories_id($cat_id);
      if (!empty($subcat_ids))
      {
        $sql = "UPDATE ".CATEGORIES_TABLE."
                SET 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 IN (".implode($subcat_ids, ",").")";
        $result = $site_db->query($sql);
      }
    }
/*
  MOD SUBCAT PERM FROM PARENT
  END INSERT
*/

Step 1.2
Find:
Code: [Select]
  show_form_footer($lang['save_changes'], $lang['reset'], 2, $lang['back']);Insert above:
Code: [Select]
/*
  MOD SUBCAT PERM FROM PARENT
  BEGIN INSERT
*/
  show_radio_row("Apply to all subcategories", "subcats", $subcats);
/*
  MOD SUBCAT PERM FROM PARENT
  END INSERT
*/



That's all.
Now when you edit category permissions, you should see a new option Apply to all subcategories
« Last Edit: August 25, 2006, 04:47:05 AM by V@no »
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 suprdave71

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Heroic Images!
Re: [MOD] Apply permission to sub-categories from their parent category
« Reply #1 on: April 27, 2005, 05:18:32 AM »
Fantastic! I can't wait to try this.

Offline om6acw

  • Full Member
  • ***
  • Posts: 187
    • View Profile
    • My Animal's World
Re: [MOD] Apply permission to sub-categories from their parent category
« Reply #2 on: April 27, 2005, 06:00:50 AM »
Super Vano :!:  :D

Offline suprdave71

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Heroic Images!
Re: [MOD] Apply permission to sub-categories from their parent category
« Reply #3 on: April 27, 2005, 06:11:30 AM »
Well, shoot. I got a Bad SQL Query right off the bat. I do have a shared database with phpBB2 -- could that be the reason?

Quote
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ' auth_terms = WHERE cat_id IN (293,4,5,307,14,
Error editing category

I have no idea what this means! I'm using version 1.7 of 4images if that means anything also.

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
Re: [MOD] Apply permission to sub-categories from their parent category
« Reply #4 on: April 27, 2005, 06:14:40 AM »
my bad, forgot remove some extra fields I have in my code... its fixed now, redo Step 1.1
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 suprdave71

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Heroic Images!
Re: [MOD] Apply permission to sub-categories from their parent category
« Reply #5 on: April 27, 2005, 06:24:04 AM »
my bad, forgot remove some extra fields I have in my code... its fixed now, redo Step 1.1

Beauty. What a time saver! Thanks for the quick fix, dude. You rock as usual.

Dave

Offline Candace

  • Newbie
  • *
  • Posts: 38
    • View Profile
I get the option now, but my save changes button has now vanished?

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
I get the option now, but my save changes button has now vanished?
restore backups and try again.
I have no idea what possible could cause your "save" button to dissapier...
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 Candace

  • Newbie
  • *
  • Posts: 38
    • View Profile
I did it wrong, It works now, thanks

Offline udaman

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: [MOD] Apply permission to sub-categories from their parent category
« Reply #9 on: August 29, 2005, 12:27:09 AM »
Code: [Select]
  $auth_postcomment = $HTTP_POST_VARS['auth_postcomment'];
I have the above code in two differnet places in my admin/categories.php

Should I use the following code in both places?

Code: [Select]
/*
  MOD SUBCAT PERM FROM PARENT
  BEGIN INSERT
*/
  $subcats = (isset($HTTP_POST_VARS['subcats']) && $HTTP_POST_VARS['subcats']) ? 1 : 0;
/*
  MOD SUBCAT PERM FROM PARENT
  END INSERT
*/

Any help will be greatly appreciated. Thanks.

Offline Xyu BAM

  • Full Member
  • ***
  • Posts: 145
    • View Profile
Re: [MOD] Apply permission to sub-categories from their parent category
« Reply #10 on: August 29, 2005, 05:20:39 AM »
probably only below
Code: [Select]
if ($action == "updatecat") { (second item)

Offline udaman

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: [MOD] Apply permission to sub-categories from their parent category
« Reply #11 on: August 29, 2005, 08:32:13 AM »
Works! Thank you for your help.

Offline bibabobu

  • Sr. Member
  • ****
  • Posts: 311
  • Technische und künstlerische Gravuren
    • View Profile
    • Technische und künstlerische Gravuren für die gesamte Metall-, Kunststoff- und Papierindustrie
Re: [MOD] Apply permission to sub-categories from their parent category
« Reply #12 on: November 07, 2005, 05:27:13 PM »
Really thanks for that MOD!

WORKS PERFECT WITHOUT HAVING TROUBLE!!!

 :D

Offline garett

  • Pre-Newbie
  • Posts: 9
    • View Profile
    • Dragon Family
Re: [MOD] Apply permission to sub-categories from their parent category
« Reply #13 on: November 13, 2005, 03:48:53 PM »
Is there a mod that allow to do almost the same thing with users group on categories.

I explain myself :

on my site, I have about 12 main categories with for some of it 30 subcategories (on several levels). When I create a new group, I apply the same permissions than main categories to their subcategories. It should be really optimized if there was somme "apply to subcategories" actions (for the groupe) on this page.

Have you seen a mod like that somewhere?

Offline Maniac

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: [MOD] Apply permission to sub-categories from their parent category
« Reply #14 on: December 29, 2005, 04:13:13 AM »
THANK YOU - Exactly what I was looking for... :D