[ 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
AUTH_ADMIN => $lang['userlevel_admin']
);
insert below
####################### 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
$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
####################### 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
foreach ($access_field_array as $key => $val) {
show_access_select($lang[$key], $key, $result[$key]);
}
and replace with
foreach ($access_field_array as $key => $val) {
show_access_select2($lang[$key], $key, $result[$key]);
}
Search for
show_form_footer($lang['save_changes'], $lang['reset'], 2, $lang['back']);
and insert above
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
//-----------------------------------------------------
//--- Images ------------------------------------------
//-----------------------------------------------------
and insert above
(choose your preferred language)
German:
$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:
$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