Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Add more User Levels  (Read 1062 times)

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Add more User Levels
« on: October 05, 2010, 06:44:51 PM »

Recently, I had a request from one of my clients who wanted to have more control over what each individual Super Editor and Editor would have access to in the Main Administration panels. The client wanted to be able to limit Super Editors and Editors to add, edit or delete just one or all content types - categories, articles, pages or extras.

Since sNewsMU 1.6.3 was first released, a few sNews members have asked if it is possible to add more User Levels.
The response to that has usually been that it does not seem practical to have more since the existing four do the job, and that was the end of the discussion.

The default sNewsMU 1.6.3 package provides 4 User Levels (account types as follows:
   - Admin (level 1) - the site owner, full privileges (all admin panels),
   - Super Editor (level 2) - content Management panel only, Can View, Edit or Delete any site content,
   - Editor (level 3) - Content Management panl only, can add, view, edit own content only by default.
   - User - level 4 - no admin access.

So... I tested the modifications required to add up to 5 additional User levels with success, whic is the subject of this thread.

Having done that, I determined that it was far more practical to add Access Privilege Options for all Editors and Super Editors.
This lets the Admin (site owner) select each of the administration panels for each User account individually when creating the account, or editing them after the account is created... using the account's Profile Privilege Settings panel.
In other words, any Super Editor or Editor account can be limited to posting one or all content types... making the need for additional User levels redundant.

However, I wanted to document the steps required to add up to 5 additional User Levels (account types) to the default sNewsMU 1.6.3 package so they are available for anyone else who wishes to explore adding User Levels further. These modifications would apply to any variant of the sNewsMU 1.6.3 package as well.

Important Back-up Notes:
1.  Before starting modifications, make a copy of your current snews.php file and keep it in a safe place so you have a fresh working file if you need it.

2.  Using phpMyAdmin, back up the users table in your existing database and save the .sql file as users_backup.sql in an SQL folder where you keep all your project's .sql files... in case you need or want to refresh the table back to what it was before modding.

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

STEP 1: Users Table (database) changes

We can make all the changes in snews.php for adding additional User levels but they will not work until we make a couple of changes to the users database table.
The 'level' column in the users table script (SQL) uses enum which only permits the use of values 1 to 4, and sets the default value as '4'. (reference)
   level enum('1','2','3','4') NOT NULL default '4',

To use values 1 to 9, we need to replace that string in the table script with this one:
   level enum('1','2','3','4','5','6','7','8','9') NOT NULL default '9',
... which adds 5 to 9 to the permitted values list... and sets the default value as '9' (instead of 4) to be used for the 'User' level.

Making the Changes:
1)   Open the users_backup.sql file you created earlier and save it in the same SQL folder as users_levels_1-9.sql.
2)   Replace the level enum string with the new one.
3)   Add this string - DROP TABLE IF EXISTS users; - above the CREATE TABLE users string, and save your changes.
4)   Import your new file into your database using phpMyAdmin.
      This will over-write the existing users table without affecting the rest of your database.

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

STEP 2:  Modifications to snews.php

1.  Language Variable Values:
    Search your snews.php file for $l['mu_level_supereditor'] and add these new strings under it:
   # User Levels 5-9 mod
   $l['mu_level_4'] = 'Level 4';
   $l['mu_level_5'] = 'Level 5';
   $l['mu_level_6'] = 'Level 6';
   $l['mu_level_7'] = 'Level 7';
   $l['mu_level_8'] = 'Level 8';


2.  Changing User Level '4' to '9':
    a) Search your snews.php file for seven instances of: 'level') < '4') and change the '4' to '9'
    b) Search again for 1 instance of: 'level') == '4') and change the '4' to '9'


3.  Within function register()
    Search for this query string and change the second last value in it from '4' to '9':

Code: [Select]
<?php

$sql 
mysql_query("INSERT INTO ".db('prefix')."users (username, username_real, password, email, website, level, ipaddy) VALUES ('$md5_name', '$name', '$md5_pass', '$mail', '$url', '4', '$ip')");

?>



4.  Within function bulk_users()
    Search for this string (should be 15 lines down in the function):
   echo '<option value="4">'.l('mu_level_user').'</option></select>';
    and (excluding the php-tags) replace it with:

Code: [Select]
<?php

# User Levels 5-9 mod
echo '<option value="4">'.l('mu_level_4').'</option>';
echo '<option value="5">'.l('mu_level_5').'</option>';
echo '<option value="6">'.l('mu_level_6').'</option>';
echo '<option value="7">'.l('mu_level_7').'</option>';
echo '<option value="8">'.l('mu_level_8').'</option>';
echo '<option value="9" selected="selected">'.l('mu_level_user').'</option></select>';

?>



5.  Within function profile()
    Search for this string:
   echo '<option value="4"'.($level == '4' ? ' selected="selected"' : '').'>'.l('mu_level_user').'</option></select>';
    and (excluding the php-tags) replace it with:

Code: [Select]
<?php

# User Levels 5-9 mod
echo '<option value="4"'.($level == '4' ' selected="selected"' '').'>'.l('mu_level_4').'</option>';
echo '<option value="5"'.($level == '5' ' selected="selected"' '').'>'.l('mu_level_5').'</option>';
echo '<option value="6"'.($level == '6' ' selected="selected"' '').'>'.l('mu_level_6').'</option>';
echo '<option value="7"'.($level == '7' ' selected="selected"' '').'>'.l('mu_level_7').'</option>';
echo '<option value="8"'.($level == '8' ' selected="selected"' '').'>'.l('mu_level_8').'</option>';
echo '<option value="9"'.($level == '9' ' selected="selected"' '').'>'.l('mu_level_user').'</option>';
echo '</select>';

?>



6.  Within function get_identity($var, $column='', $check='')
    Search for (5 lines up from the bottom of the function):
   case ('4'): $user = l('mu_level_user'); break;
    and (excluding the php-tags) replace it with:

Code: [Select]
<?php

# User Levels 5-9 mod
case ('4'): $user l('mu_level_4'); break;
case ('5'): $user l('mu_level_5'); break;
case ('6'): $user l('mu_level_6'); break;
case ('7'): $user l('mu_level_7'); break;
case ('8'): $user l('mu_level_8'); break;
case ('9'): $user l('mu_level_user'); break;


?>



Customizing the new Level Names:
You can customize the new level names in the Level drop-downs - Level 4, Level 5, Level 6, Level 7, Level 8 - to whatever text you want by changing their values within the 5 language variable strings you pasted into your snews.php file in STEP 2 (above).
« Last Edit: October 05, 2010, 07:16:02 PM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU