Author Topic: [MOD] Set User Rights per Category in ACP / User Rights Mod  (Read 40520 times)

0 Members and 1 Guest are viewing this topic.

Offline IcEcReaM

  • Hero Member
  • *****
  • Posts: 714
    • View Profile
    • My little Testboard
[MOD] Set User Rights per Category in ACP / User Rights Mod
« on: February 16, 2006, 08:10:25 AM »
[ Introduction ]
With this mod you can now set the user rights per Category.
For example:
If you set categorie_view in an categorie to private,
you have to set the user rights (which user are allowed to view this category) for each user,
by searching the user, what takes some time and also is uncomfortable.
With this mod now you can set the user, which are allowed to view this category,
directly in the category editing page.

German:
Mit diesem Mod könnt ihr die User Rechte direkt per Kategorie setzen.
Bisher musste man, wenn man z.B. category view auf private gesetzt hat,
die User einzeln raussuchen, und dann bei jedem User einzeln die Erlaubnis setzen.
Mit diesem Mod könnt ihr direkt in der Kategorie Bearbeitungsseite die Rechte für die User setzen.

[ Changed Files ]
admin/categories.php
lang/<your language>/admin.php


[ Installation ]

First Backup your Files

Step 1
Open admin/categories.php

search for
Code: [Select]
  AUTH_ADMIN => $lang['userlevel_admin']
);
insert below
Code: [Select]
####################### User Rights per Cat MOD Start #######################

function update_single_usergroup($user_id, $user_name) {
    global $site_db, $user_table_fields;

    $group_name = $user_name;

    $sql = "SELECT group_id
            FROM ".GROUPS_TABLE."
            WHERE group_name = '".addslashes($group_name)."' AND group_type = ".GROUPTYPE_SINGLE;
    $row2 = $site_db->query_firstrow($sql);
    if (!$row2) {
        $sql = "INSERT INTO ".GROUPS_TABLE."
                (group_name, group_type)
                VALUES
                ('".addslashes($group_name)."', ".GROUPTYPE_SINGLE.")";
        $site_db->query($sql);
        $group_id = $site_db->get_insert_id();
  }
  else {
        $group_id = $row2['group_id'];
  }
  $sql = "SELECT group_id
          FROM ".GROUP_MATCH_TABLE."
          WHERE group_id = $group_id AND user_id = $user_id";
  if ($site_db->is_empty($sql)) {
    $sql = "INSERT INTO ".GROUP_MATCH_TABLE."
            (group_id, user_id, groupmatch_startdate, groupmatch_enddate)
            VALUES
            ($group_id, $user_id, 0, 0)";
    $site_db->query($sql);
  }
  return $group_id;
}

function show_access_select2($title = "", $type, $status) {
  global $access_array, $HTTP_POST_VARS, $site_db, $cat_id, $user_table_fields, $lang;
  if (isset($HTTP_POST_VARS[$type])) {
    $status = $HTTP_POST_VARS[$type];
  }
  echo "<tr class=\"".get_row_bg()."\" valign=\"top\">\n<td><p class=\"rowtitle\">".$title."</p></td>\n";
  echo "<td>\n<select name=\"".$type."\">\n";
  foreach ($access_array as $key => $val) {
    echo "<option value=\"".$key."\"";         //$key Nummer 0-9  Einstelloptionsmöglichkeiten
    if ($status == $key) {             // $status eingestellte Option
      echo " selected=\"selected\"";
    }
    echo ">".$val."</option>\n";      // $val = Einstelloptionsmöglichkeiten
  }
  echo "</select>";

  if ($status == AUTH_ACL)  {
     echo "<tr class=\"".get_row_bg()."\" valign=\"top\">\n<td> <div class=\"rowtitle\">".$lang['cat_user_rights']."</div> \n";
     echo $lang['cat_user_rights_users'].$title."</b></font> </td>\n";
     echo "<td>\n";
     echo "<select name=\"".$type."_rights[]\" size=5 multiple>\n";

      $sql = "SELECT ".get_user_table_field("u.", "user_id").", ".get_user_table_field("u.", "user_name").", a.cat_id, a.".$type."
              FROM ".USERS_TABLE." u
              LEFT JOIN ".GROUP_MATCH_TABLE." m ON (m.user_id = ".get_user_table_field("u.", "user_id").") AND groupmatch_startdate = '0'
              LEFT JOIN ".GROUP_ACCESS_TABLE." a ON (a.group_id = m.group_id) AND a.cat_id = ".$cat_id."
              WHERE ".get_user_table_field("u.", "user_id")." != ".GUEST."
              ORDER BY a.".$type." DESC , ".get_user_table_field("u.", "user_name")." ASC";
             
      $foo = $site_db->query($sql);
      while ($row = $site_db->fetch_array($foo)) {
            if ($row[$type] == 1) {
               //$categorie_useraccess .= ", ".$row[$user_table_fields['user_name']]." (".$row['userid'].")";   // Check Usernames
               echo "<option value=\"".$row[$user_table_fields['user_id']]."\" selected>".$row[$user_table_fields['user_name']]."</option>\n";
            }
            else echo "<option value=\"".$row[$user_table_fields['user_id']]."\">".$row[$user_table_fields['user_name']]."</option>\n";
       }
     echo "</select>";
     //echo "User: ".$categorie_useraccess;
     echo "<br>".$lang['cat_user_rights_select_tip']."</td></tr>";
   }
  echo "\n</td>\n</tr>\n";
}

####################### User Rights per Cat MOD End #######################

Search for
Code: [Select]
    $sql = "UPDATE ".CATEGORIES_TABLE."
            SET cat_name = '$cat_name', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, 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";
    $result = $site_db->query($sql);

insert below
Code: [Select]
####################### User Rights per Cat MOD Start #######################

  $do_user_rights = (isset($HTTP_POST_VARS['do_user_rights']) && $HTTP_POST_VARS['do_user_rights']) ? 1 : 0;
  $do_user_rights_ok = 0;
  $array_merge_list = array();

  $access_field_arrays = array(1 =>'auth_viewcat','auth_viewimage','auth_download','auth_upload','auth_directupload','auth_vote','auth_sendpostcard','auth_readcomment','auth_postcomment');
    foreach ($access_field_arrays as $key => $val) {
         if (isset ($HTTP_POST_VARS[$val."_rights"])) {
             ${$val."_rights"} = $HTTP_POST_VARS[$val."_rights"];
             $array_merge_list = array_merge ($array_merge_list,${$val."_rights"});
             $do_user_rights_ok = 1;
         }
         else {
            ${$val."_rights"} = "";
         }
    }
  $array_merge_list = array_unique ($array_merge_list);
  $array_merge_user_sql = implode (",",$array_merge_list);

  if ($do_user_rights)  {

      $sql = "DELETE FROM ".GROUP_ACCESS_TABLE."
              WHERE cat_id = $cat_id";
      $site_db->query($sql);              // Delete old entries

      if ($array_merge_user_sql) {
      $sql = "SELECT ".get_user_table_field("u.",user_id).", ".get_user_table_field("u.",user_name).", g.group_id
              FROM ".USERS_TABLE." u
              LEFT JOIN ".GROUP_MATCH_TABLE." gm ON (gm.user_id = ".get_user_table_field("u.",user_id).") AND gm.groupmatch_startdate = 0
              LEFT JOIN ".GROUPS_TABLE." g ON (g.group_id = gm.group_id)
              WHERE ".get_user_table_field("u.",user_id)." IN (".$array_merge_user_sql.")
              ORDER BY ".get_user_table_field("u.",user_id)." ASC";

      $foo = $site_db->query($sql);
      while ($row = $site_db->fetch_array($foo)) {
         $user_id = $row[$user_table_fields['user_id']];
         
          if (!$row['group_id']) {
               $row['group_id'] = update_single_usergroup($user_id, $row[$user_table_fields['user_name']]);
           }
           
         $group_id = $row['group_id'];
   
         foreach ($access_field_arrays as $key => $val) {
              ${$val."_sql"} = ((${$val."_rights"})) && (in_array ("$user_id", ${$val."_rights"}) && $$val == AUTH_ACL) ? 1 : 0;
          }
         
         if (($auth_viewcat_sql || $auth_viewimage_sql || $auth_download_sql || $auth_upload_sql || $auth_directupload_sql || $auth_vote_sql || $auth_sendpostcard_sql || $auth_readcomment_sql || $auth_postcomment_sql) && $group_id) {
                 $sql = "INSERT INTO ".GROUP_ACCESS_TABLE."
                 (group_id, cat_id, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment)
                 VALUES
                 ($group_id, $cat_id, $auth_viewcat_sql, $auth_viewimage_sql, $auth_download_sql, $auth_upload_sql, $auth_directupload_sql, $auth_vote_sql, $auth_sendpostcard_sql, $auth_readcomment_sql, $auth_postcomment_sql)";
                 $site_db->query($sql);
         }
      }  // While
     }   
    }

####################### User Rights per Cat MOD End #######################


Search for
Code: [Select]
  foreach ($access_field_array as $key => $val) {
    show_access_select($lang[$key], $key, $result[$key]);
  }
and replace with
Code: [Select]
  foreach ($access_field_array as $key => $val) {
    show_access_select2($lang[$key], $key, $result[$key]);
  }

Search for
Code: [Select]
  show_form_footer($lang['save_changes'], $lang['reset'], 2, $lang['back']);and insert above
Code: [Select]
  show_radio_row($lang['save_user_rights'],  "do_user_rights", 0);   // pre setting 1-yes / 0-no

Step 2
Open lang/<your language>/admin.php
Search for
Code: [Select]
//-----------------------------------------------------
//--- Images ------------------------------------------
//-----------------------------------------------------
and insert above
(choose your preferred language)

German:
Code: [Select]
$lang['cat_user_rights'] = "Einzelrechte - User:";
$lang['save_user_rights'] = "Einstellungen speichern für Userrechte";
$lang['cat_user_rights_users'] = "Welche User dürfen: ";
$lang['cat_user_rights_select_tip'] = "(Mehrfache Markierungen sind bei vielen Browsern durch gleichzeitiges Drücken von \"Ctrl/Strg\" möglich.)";

English:
Code: [Select]
$lang['save_user_rights'] = "Save changes of User Rights";
$lang['cat_user_rights'] = "User Rights:";
$lang['cat_user_rights_users'] = "Which Users are allowed to: ";
$lang['cat_user_rights_select_tip'] = "(To select multiple user by pushing  \"Ctrl/Strg\" )";

Finished!

I've tested the mod on a fresh & clean 4images installation.

Note:
This options only appears if a category permission is set to private.

17.02 Fixed multlanguage support
« Last Edit: February 17, 2006, 09:58:09 AM by IcEcReaM »
Coding is a everlasting competition between programmers who tries to write larger, better and idiot-safe programs and the universe producing larger and stupider idiots...
...so far the universe won
bump

Offline Loda

  • Sr. Member
  • ****
  • Posts: 353
    • View Profile
    • Fotosucht Schweiz
Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
« Reply #1 on: February 16, 2006, 09:04:39 AM »
wow! fantastic! thank you very much!  :D

Offline trez

  • Hero Member
  • *****
  • Posts: 613
    • View Profile
    • blog / photography
Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
« Reply #2 on: February 16, 2006, 09:29:10 AM »
Great! Fantastic MOD, i try it after a cup of hours :)

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] Set User Rights per Category in ACP / User Rights Mod
« Reply #3 on: February 16, 2006, 03:12:01 PM »
Very nice and good idea!

I have a question though, ones you saved the category settings, it will NOT show which members were previously added...so, I guess, its not a big deal, but you can not use this form to remove specific users access permission, correct?
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 TheOracle

  • Hero Member
  • *****
  • Posts: 875
    • View Profile
Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
« Reply #4 on: February 16, 2006, 03:44:27 PM »
I have a question myself for this interesting MOD. Doesn't it also require additional modifications to the check_permission module ? Since it is for grouping with the add / edit users page rather than simply the cat page ? ;)

Offline IcEcReaM

  • Hero Member
  • *****
  • Posts: 714
    • View Profile
    • My little Testboard
Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
« Reply #5 on: February 16, 2006, 03:54:28 PM »
I don't know what you exactly mean.

This mod shows, when a category is set to private,
and already some users have the rights to view the category,
in the form as "preselected" users.

So with this one is also possible to kick out just one user,
by deselecting him, and let the others selected.

I hope that was what you asked for.  :roll:


Edit:
No it doesn't need any other modfications,
cause mainly it does the same thing as you would all users step by step and setting their rights,
just a little bit comfortabler.
Coding is a everlasting competition between programmers who tries to write larger, better and idiot-safe programs and the universe producing larger and stupider idiots...
...so far the universe won
bump

Offline TheOracle

  • Hero Member
  • *****
  • Posts: 875
    • View Profile
Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
« Reply #6 on: February 16, 2006, 04:23:29 PM »
Quote

This mod shows, when a category is set to private,
and already some users have the rights to view the category,
in the form as "preselected" users.


Thanks for the info.

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] Set User Rights per Category in ACP / User Rights Mod
« Reply #7 on: February 17, 2006, 03:03:57 AM »
Never mind my question...the mod works great.

One little thing though, since this mod supports multi language, I guess you forgot to add multi-lang support in last item of Step 1:[qcode]show_radio_row("Save changes of User Rights", "do_user_rights", 0);   // pre setting 1-yes / 0-no[/qcode]
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 TheOracle

  • Hero Member
  • *****
  • Posts: 875
    • View Profile
Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
« Reply #8 on: February 17, 2006, 03:11:30 AM »
In fact, this line :

Quote

show_radio_row("Save changes of User Rights", "do_user_rights", 0);   // pre setting 1-yes / 0-no


could be done like this :

Code: [Select]

show_radio_row($lang['save_user_rights'], "do_user_rights", 0);   // pre setting 1-yes / 0-no


Then, in your lang/english/admin.php file,

add above the '?>' tag :

Code: [Select]

$lang['save_user_rights'] = "Save changes of User Rights";


Offline IcEcReaM

  • Hero Member
  • *****
  • Posts: 714
    • View Profile
    • My little Testboard
Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
« Reply #9 on: February 17, 2006, 10:00:27 AM »
One little thing though, since this mod supports multi language, I guess you forgot to add multi-lang support in last item of Step

thx for the hint.
Fixed it in the first post.

Man this multilanuage support drives me crazy  :mrgreen:
Coding is a everlasting competition between programmers who tries to write larger, better and idiot-safe programs and the universe producing larger and stupider idiots...
...so far the universe won
bump

Offline koolred

  • Pre-Newbie
  • Posts: 4
    • View Profile
Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
« Reply #10 on: March 23, 2007, 03:36:26 PM »
Hi, I just started to install this mod of yours but at the third replacement I found out that

foreach ($access_field_array as $key => $val) {
    show_access_select($lang[$key], $key, $result[$key]);
  }

cannot be found in the categories.php of admin of version 1.74 What should I do to go on. Am I stuck then? Is this compatible?

Thanks for your help  :D

Frank

Offline mawenzi

  • Moderator
  • 4images Guru
  • *****
  • Posts: 4.500
    • View Profile
Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
« Reply #11 on: March 23, 2007, 04:23:32 PM »
@ koolred

... search instead for ...

Code: [Select]
  foreach ($access_field_array as $key => $val) {
    show_access_select2($lang[$key], $key, $cat_row[$key]);
  }
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 koolred

  • Pre-Newbie
  • Posts: 4
    • View Profile
Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
« Reply #12 on: March 31, 2007, 02:19:02 PM »
Thanks a lot Mawenzi  :D  I'll do that..

Frank


Offline SoftDux

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • SoftDux - The Leaders in Software & Networking
Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
« Reply #13 on: May 05, 2007, 04:52:49 PM »
Would I be able to use this MOD to create adult related categories (for a public gallery, which requires registration), and then only allow users who has specified thei're older than 18, to view the adult related categories?
Visit these Website:  SA WebHosting Talk || SoftDux

Offline mawenzi

  • Moderator
  • 4images Guru
  • *****
  • Posts: 4.500
    • View Profile
Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
« Reply #14 on: May 05, 2007, 05:10:18 PM »
@SoftDux
... yes ...
... but ...
... you can also create usergroups, and give them the permission for certain categories ...
... then only you need to add the new user to the appropriate usergroup ...
... and this function is already in the standard version of 4images ...
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) ...