4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Releases & Support) => Topic started by: IcEcReaM on February 16, 2006, 08:10:25 AM

Title: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: IcEcReaM 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
Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: Loda on February 16, 2006, 09:04:39 AM
wow! fantastic! thank you very much!  :D
Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: trez on February 16, 2006, 09:29:10 AM
Great! Fantastic MOD, i try it after a cup of hours :)
Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: V@no 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?
Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: TheOracle 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 ? ;)
Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: IcEcReaM 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.
Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: TheOracle 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.
Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: V@no 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]
Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: TheOracle 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";

Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: IcEcReaM 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:
Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: koolred 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
Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: mawenzi 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]);
  }
Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: koolred on March 31, 2007, 02:19:02 PM
Thanks a lot Mawenzi  :D  I'll do that..

Frank

Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: SoftDux 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?
Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: mawenzi 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 ...
Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: SoftDux on May 05, 2007, 06:03:25 PM
ok, cool. Sorry for the dumb question, I'm looking for a gallery script for a specific project, so instead of downloading each gallery on the net + install + learn + use + run into a deadend, I'd rather look around on the forums, and see which one will work for me :)

How would I be able to tell, if a user is older than 18 years old, that he / she has access to a certain group?
Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: mawenzi on May 05, 2007, 07:31:43 PM
... try this ...
... [MOD] Terms and Conditions for images v1.2.1 ...
... http://www.4homepages.de/forum/index.php?topic=7113.0 ...
Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: sigma. on May 13, 2007, 12:18:32 AM
Would it be possible to insted apply this per Image in the ACP?

Im looking for a way to add user rights per Image. Possibly with usergroups.
Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: Jan-Lukas on June 28, 2008, 09:21:44 PM
Hier der Einbau für Version 1.7.6

Step 1

 :flag-de:  öffne admin/categories.php
 :flag-en: Open admin/categories.php

 :flag-de: suche nach  :flag-en: search for

 
Code: [Select]
AUTH_ADMIN => $lang['userlevel_admin']
);

 :flag-de: füge darunter ein  :flag-en: 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 #######################


:flag-de: suche nach  :flag-en: 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);

 :flag-de: füge darunter ein  :flag-en: 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 #######################

:flag-de: suche nach  :flag-en: search for

Code: [Select]
foreach ($access_field_array as $key => $val) {
    show_access_select($lang[$key], $key, $cat_row[$key]);
  }

:flag-de: ersetze mit  :flag-en: replace with

Code: [Select]
foreach ($access_field_array as $key => $val) {
    show_access_select2($lang[$key], $key, $cat_row[$key]);
  }

:flag-de: suche nach  :flag-en: search for

Code: [Select]
show_form_footer($lang['save_changes'], $lang['reset'], 2, $lang['back']);
:flag-de: füge da drüber ein  :flag-en: insert above

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

Step 2

 :flag-de:  öffne lang/<your language>/admin.php
 :flag-en: Open lang/<your language>/admin.php

 :flag-de: suche nach  :flag-en: search for

Code: [Select]
//-----------------------------------------------------
//--- Images ------------------------------------------
//-----------------------------------------------------

:flag-de: füge da drüber ein  :flag-en: insert above

 :flag-de:
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.)";

 :flag-en:
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\" )";



Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: Sunny C. on June 28, 2008, 11:05:37 PM
Danke dir!!
Kann nützlich sein das Teil!

LG
Phisker

Ps.: Habs in der Liste mit aufgenommen!
Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: escbln on February 24, 2009, 06:14:12 PM
Lässt sich das auch für Usergruppen modifizieren? Sonst ist es ein super MOD.
Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: escbln on February 27, 2009, 03:14:55 PM
Ich habe den MOD für 1.7.6 so modifiziert, dass man Usergruppenweise die Rechte bei der Kategoriebearbeitung ändern kann.

Folgende Änderungen sind notwendig:

1. lang/deutsch/admin.php

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.)";

ersetzen durch

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

2. admin/categories.php

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 #######################

ersetzen durch

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=3 multiple>\n";

      $sql = "SELECT u.group_id, u.group_name, a.cat_id, a.".$type."
              FROM 4images_groups u
  LEFT JOIN 4images_groupaccess a ON (a.group_id = u.group_id) AND a.cat_id = ".$cat_id."
              WHERE u.group_type = '1'
              ORDER BY u.group_name ASC";

      $foo = $site_db->query($sql);

     while ($row = $site_db->fetch_array($foo)) {
echo $row['group_name'];
            if ($row[$type] == 1) {
               //$categorie_useraccess .= ", ".$row[$user_table_fields['user_name']]." (".$row['userid'].")";   // Check Usernames
               echo "<option value=\"".$row['group_id']."\" selected>".$row['group_name']."</option>\n";
            }
            else echo "<option value=\"".$row['group_id']."\">".$row['group_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 #######################

und

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 #######################

ersetzen durch

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 u.group_id, u.group_name, a.cat_id
              FROM 4images_groups u
  LEFT JOIN 4images_groupaccess a ON (a.group_id = u.group_id) AND a.cat_id = ".$cat_id."
              WHERE u.group_type = '1'
              ORDER BY u.group_name ASC";

      $foo = $site_db->query($sql);
      while ($row = $site_db->fetch_array($foo)) {

         $group_id = $row['group_id'];

//          if (!$row['group_id']) {
//               $row['group_id'] = update_single_usergroup($user_id, $row[$user_table_fields['user_name']]);
//           }
           
         foreach ($access_field_arrays as $key => $val) {
              ${$val."_sql"} = ((${$val."_rights"})) && (in_array ("$group_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 #######################

Viel Spass damit,

Erik
Title: Re: [MOD] Set User Rights per Category in ACP / User Rights Mod
Post by: henary on December 14, 2010, 04:23:14 PM
Hallo,

der ursprüngliche MOD wie auch die Änderung auf Usergruppen laufen beide unter 1.7.9 - danke für dieses feine MOD.

Bis später,
Henry