mirror of
https://github.com/e107inc/e107.git
synced 2025-07-31 20:00:37 +02:00
Tidy up some userclass stuff
This commit is contained in:
@@ -10,9 +10,9 @@
|
||||
* Administration Area - Users
|
||||
*
|
||||
* $Source: /cvs_backup/e107_0.8/e107_admin/users.php,v $
|
||||
* $Revision: 1.52 $
|
||||
* $Date: 2009-08-14 23:22:36 $
|
||||
* $Author: bugrain $
|
||||
* $Revision: 1.53 $
|
||||
* $Date: 2009-08-19 21:33:19 $
|
||||
* $Author: e107steved $
|
||||
*
|
||||
*/
|
||||
require_once ('../class2.php');
|
||||
@@ -1111,12 +1111,14 @@ class users
|
||||
|
||||
function show_batch_options()
|
||||
{
|
||||
$e107 = e107::getInstance();
|
||||
$classObj = $e107->getUserClass();
|
||||
$frm = new e_form();
|
||||
$classes = get_userclass_list();
|
||||
$classes = $classObj->uc_get_classlist();
|
||||
$assignClasses = array(); // Userclass list of userclasses that can be assigned
|
||||
foreach ($classes as $key => $val)
|
||||
{
|
||||
if ($key < 240 && $key!=0)
|
||||
if ($classObj->isEditableClass($key))
|
||||
{
|
||||
$assignClasses[$key] = $classes[$key];
|
||||
}
|
||||
|
@@ -11,9 +11,9 @@
|
||||
| GNU General Public License (http://gnu.org).
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/e107_handlers/userclass_class.php,v $
|
||||
| $Revision: 1.38 $
|
||||
| $Date: 2009-08-04 15:04:18 $
|
||||
| $Author: e107coders $
|
||||
| $Revision: 1.39 $
|
||||
| $Date: 2009-08-19 21:33:20 $
|
||||
| $Author: e107steved $
|
||||
+----------------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
@@ -93,7 +93,7 @@ class user_class
|
||||
Ensure the tree of userclass data is stored in our object.
|
||||
Only read if its either not present, or the $force flag is set
|
||||
*/
|
||||
function readTree($force = FALSE)
|
||||
protected function readTree($force = FALSE)
|
||||
{
|
||||
if (isset($this->class_tree) && count($this->class_tree) && !$force) return $this->class_tree;
|
||||
|
||||
@@ -183,7 +183,7 @@ class user_class
|
||||
|
||||
|
||||
// Given the list of 'base' classes a user belongs to, returns a comma separated list including ancestors. Duplicates stripped
|
||||
function get_all_user_classes($start_list)
|
||||
public function get_all_user_classes($start_list)
|
||||
{
|
||||
$is = array();
|
||||
$start_array = explode(',', $start_list);
|
||||
@@ -199,7 +199,7 @@ class user_class
|
||||
|
||||
|
||||
// Returns a list of user classes which can be edited by the specified classlist (defaults to current user's classes)
|
||||
function get_editable_classes($class_list = USERCLASS_LIST, $asArray = FALSE)
|
||||
public function get_editable_classes($class_list = USERCLASS_LIST, $asArray = FALSE)
|
||||
{
|
||||
$ret = array();
|
||||
$blockers = array(e_UC_PUBLIC => 1, e_UC_READONLY => 1, e_UC_MEMBER => 1, e_UC_NOBODY => 1, e_UC_GUEST => 1, e_UC_NEWUSER => 1);
|
||||
@@ -228,7 +228,7 @@ class user_class
|
||||
// $possible - the classes which are being edited
|
||||
// $actual - the actual membership of the editable classes
|
||||
// All classes may be passed as comma-separated lists or arrays
|
||||
function mergeClassLists($combined, $possible, $actual, $asArray = FALSE)
|
||||
public function mergeClassLists($combined, $possible, $actual, $asArray = FALSE)
|
||||
{
|
||||
if (!is_array($combined)) { $combined = explode(',',$combined); }
|
||||
if (!is_array($possible)) { $possible = explode(',',$possible); }
|
||||
@@ -251,7 +251,7 @@ class user_class
|
||||
}
|
||||
|
||||
|
||||
function stripFixedClasses($inClasses)
|
||||
public function stripFixedClasses($inClasses)
|
||||
{
|
||||
$asArray = TRUE;
|
||||
if (!is_array($inClasses))
|
||||
@@ -272,7 +272,7 @@ class user_class
|
||||
|
||||
// Given a comma separated list, returns the minimum number of class memberships required to achieve this (i.e. strips classes 'above' another in the tree)
|
||||
// Requires the class tree to have been initialised
|
||||
function normalise_classes($class_list)
|
||||
public function normalise_classes($class_list)
|
||||
{
|
||||
$drop_classes = array();
|
||||
$old_classes = explode(',',$class_list);
|
||||
@@ -317,11 +317,11 @@ class user_class
|
||||
|
||||
[ $mode parameter of r_userclass() removed - $optlist is more flexible) ]
|
||||
*/
|
||||
function uc_dropdown($fieldname, $curval = 0, $optlist = "", $extra_js = '')
|
||||
public function uc_dropdown($fieldname, $curval = 0, $optlist = "", $extra_js = '')
|
||||
{
|
||||
global $pref;
|
||||
|
||||
$show_classes = $this->uc_required_class_list($optlist);
|
||||
$show_classes = self::uc_required_class_list($optlist);
|
||||
|
||||
$text = '';
|
||||
foreach ($show_classes as $k => $v)
|
||||
@@ -375,7 +375,7 @@ class user_class
|
||||
Generate an ordered array classid=>classname - used for dropdown and check box lists
|
||||
If $just_ids is TRUE, array value is just '1'
|
||||
*/
|
||||
function uc_required_class_list($optlist = '', $just_ids = FALSE)
|
||||
public function uc_required_class_list($optlist = '', $just_ids = FALSE)
|
||||
{
|
||||
$ret = array();
|
||||
if (!$optlist) $optlist = 'public,guest,nobody,member,classes'; // Set defaults to simplify ongoing processing
|
||||
@@ -458,7 +458,7 @@ class user_class
|
||||
$optlist as for uc_dropdown
|
||||
if $showdescription is TRUE, appends the class description in brackets
|
||||
*/
|
||||
function uc_checkboxes($fieldname, $curval='', $optlist = '', $showdescription = FALSE)
|
||||
public function uc_checkboxes($fieldname, $curval='', $optlist = '', $showdescription = FALSE)
|
||||
{
|
||||
global $pref;
|
||||
$show_classes = $this->uc_required_class_list($optlist);
|
||||
@@ -505,7 +505,7 @@ class user_class
|
||||
$current_value is a single class number for single-select dropdown; comma separated array of class numbers for checkbox list or multi-select
|
||||
$optlist works the same as for other class displays
|
||||
*/
|
||||
function vetted_sub_tree($treename, $callback,$listnum,$nest_level,$current_value, $perms, $opt_options)
|
||||
protected function vetted_sub_tree($treename, $callback,$listnum,$nest_level,$current_value, $perms, $opt_options)
|
||||
{
|
||||
$ret = '';
|
||||
$nest_level++;
|
||||
@@ -525,7 +525,7 @@ class user_class
|
||||
}
|
||||
|
||||
|
||||
function vetted_tree($treename, $callback='', $current_value='', $optlist = '',$opt_options = '')
|
||||
public function vetted_tree($treename, $callback='', $current_value='', $optlist = '',$opt_options = '')
|
||||
{
|
||||
$ret = '';
|
||||
if (!$callback) $callback=array($this,'select');
|
||||
@@ -549,7 +549,7 @@ class user_class
|
||||
|
||||
|
||||
// Callback for vetted_tree - Creates the option list for a selection box
|
||||
function select($treename, $classnum, $current_value, $nest_level)
|
||||
public function select($treename, $classnum, $current_value, $nest_level)
|
||||
{
|
||||
if ($classnum == e_UC_BLANK) return "<option value=''> </option>\n";
|
||||
// echo "Display: {$classnum}, {$current_value}, {$nest_level}<br />";
|
||||
@@ -575,7 +575,7 @@ class user_class
|
||||
|
||||
|
||||
// Callback for vetted_tree - displays indented checkboxes with class name only
|
||||
function checkbox($treename, $classnum, $current_value, $nest_level)
|
||||
public function checkbox($treename, $classnum, $current_value, $nest_level)
|
||||
{
|
||||
if ($classnum == e_UC_BLANK) return '';
|
||||
$tmp = explode(',',$current_value);
|
||||
@@ -593,7 +593,7 @@ class user_class
|
||||
|
||||
|
||||
// Callback for vetted_tree - displays indented checkboxes with class name, and description in brackets
|
||||
function checkbox_desc($treename, $classnum, $current_value, $nest_level)
|
||||
public function checkbox_desc($treename, $classnum, $current_value, $nest_level)
|
||||
{
|
||||
if ($classnum == e_UC_BLANK) return '';
|
||||
$tmp = explode(',',$current_value);
|
||||
@@ -617,7 +617,7 @@ class user_class
|
||||
Index field - userclass_id
|
||||
Data fields - userclass_name, userclass_description, userclass_editclass
|
||||
*/
|
||||
function uc_get_classlist($filter = FALSE)
|
||||
public function uc_get_classlist($filter = FALSE)
|
||||
{
|
||||
$ret = array();
|
||||
$this->readTree(FALSE); // Make sure we have data
|
||||
@@ -632,7 +632,8 @@ class user_class
|
||||
}
|
||||
|
||||
|
||||
function uc_get_classname($id)
|
||||
// Return class name for given class ID
|
||||
public function uc_get_classname($id)
|
||||
{
|
||||
if (isset($this->class_tree[$id]))
|
||||
{
|
||||
@@ -653,7 +654,7 @@ class user_class
|
||||
}
|
||||
|
||||
|
||||
function uc_get_classdescription($id)
|
||||
public function uc_get_classdescription($id)
|
||||
{
|
||||
if (isset($this->class_tree[$id]))
|
||||
{
|
||||
@@ -666,7 +667,8 @@ class user_class
|
||||
return '';
|
||||
}
|
||||
|
||||
function uc_get_classicon($id)
|
||||
|
||||
public function uc_get_classicon($id)
|
||||
{
|
||||
if (isset($this->class_tree[$id]))
|
||||
{
|
||||
@@ -675,7 +677,9 @@ class user_class
|
||||
return '';
|
||||
}
|
||||
|
||||
function ucGetClassIDFromName($name)
|
||||
|
||||
// Given a class name, look up the ID. Return FALSE if not found
|
||||
public function ucGetClassIDFromName($name)
|
||||
{
|
||||
$this->readTree();
|
||||
// We have all the info - can just search the array
|
||||
@@ -691,7 +695,7 @@ class user_class
|
||||
|
||||
|
||||
// Utility to remove a specified class ID from the default comma-separated list
|
||||
function ucRemove($classID, $from, $asArray = FALSE)
|
||||
public function ucRemove($classID, $from, $asArray = FALSE)
|
||||
{
|
||||
$tmp = array_flip(explode(',',$from));
|
||||
if (isset($tmp[$classID]))
|
||||
@@ -706,7 +710,7 @@ class user_class
|
||||
|
||||
|
||||
// Utility to add a specified class ID to the default comma-separated list
|
||||
function ucAdd($classID, $to, $asArray = FALSE)
|
||||
public function ucAdd($classID, $to, $asArray = FALSE)
|
||||
{
|
||||
$tmp = array_flip(explode(',',$to));
|
||||
$tmp[$classID] = 1;
|
||||
@@ -716,6 +720,15 @@ class user_class
|
||||
}
|
||||
|
||||
|
||||
// See if a class can be edited (in the sense of the class ID not being fixed) - return TRUE if permitted.
|
||||
public function isEditableClass($classID)
|
||||
{
|
||||
if (($classID >= e_UC_SPECIAL_BASE) && ($classID <= e_UC_SPECIAL_END)) return FALSE; // Don't allow deletion of fixed classes
|
||||
if (isset($this->fixed_classes[$class_id])) return FALSE; // This picks up classes such as e_UC_PUBLIC outside the main range which can't be deleted
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Return all users in a particular class or set of classes.
|
||||
$classlist is a comma separated list of classes - if the 'predefined' classes are required, they must be included. No spaces allowed
|
||||
@@ -727,7 +740,7 @@ class user_class
|
||||
|
||||
***** NOT SURE WHETHER THIS IS REALLY A USER OR A USER CLASS FUNCTION *****
|
||||
*/
|
||||
function get_users_in_class($classlist, $field_list = 'user_name, user_loginname', $include_ancestors = FALSE, $order_by = 'user_id')
|
||||
public function get_users_in_class($classlist, $field_list = 'user_name, user_loginname', $include_ancestors = FALSE, $order_by = 'user_id')
|
||||
{
|
||||
$ret = array();
|
||||
if ($include_ancestors) $classlist = $this->get_all_user_classes($classlist);
|
||||
@@ -748,7 +761,9 @@ class user_class
|
||||
//========================================================================
|
||||
// Functions from previous userclass_class handler
|
||||
//========================================================================
|
||||
// Implemented for backwards compatibility/convenience
|
||||
// Implemented for backwards compatibility/convenience.
|
||||
|
||||
// ************** DEPRECATED - use new class-based functions
|
||||
|
||||
/*
|
||||
With $optlist you can now specify which classes are shown in the dropdown.
|
||||
@@ -857,7 +872,7 @@ class user_class_admin extends user_class
|
||||
|
||||
function user_class_admin()
|
||||
{
|
||||
$this->user_class(); // Call constructor from ancestor class
|
||||
parent::user_class(); // Call constructor from ancestor class
|
||||
$this->isAdmin = TRUE;
|
||||
|
||||
// Have to initialise the images this way - PHP4 won't take a nested array assignment in the variable list
|
||||
@@ -891,7 +906,7 @@ class user_class_admin extends user_class
|
||||
/*
|
||||
Next three routines are used to update the database after adding/deleting a class
|
||||
*/
|
||||
function calc_tree()
|
||||
public function calc_tree()
|
||||
{
|
||||
// echo "Calc Tree<br />";
|
||||
$this->readTree(TRUE); // Make sure we have accurate data
|
||||
@@ -906,7 +921,7 @@ class user_class_admin extends user_class
|
||||
// Internal function, called recursively to rebuild the permissions tree where rights increase going down the tree
|
||||
// $parent is the class number being processed.
|
||||
// $rights is the array of rights accumulated so far in the walk down the tree
|
||||
function rebuild_tree($parent, $rights)
|
||||
protected function rebuild_tree($parent, $rights)
|
||||
{
|
||||
if ($this->class_tree[$parent]['userclass_parent'] == e_UC_NOBODY)
|
||||
{
|
||||
@@ -935,9 +950,8 @@ class user_class_admin extends user_class
|
||||
|
||||
// Internal function, called recursively to rebuild the permissions tree where rights increase going up the tree
|
||||
// Returns an array
|
||||
function topdown_tree($our_class)
|
||||
protected function topdown_tree($our_class)
|
||||
{
|
||||
// echo "Top down: {$our_class}, Children: ".implode(',',$this->class_tree[$our_class]['class_children'])."<br />";
|
||||
$rights = array($our_class); // Accumulator always has rights to its own class
|
||||
|
||||
if ($this->class_tree[$our_class]['userclass_type'] == UC_TYPE_GROUP) return array_merge($rights, explode(',',$this->class_tree[$our_class]['userclass_accum'])); // Stop rights accumulation at a group
|
||||
@@ -958,9 +972,8 @@ class user_class_admin extends user_class
|
||||
}
|
||||
|
||||
|
||||
function save_tree()
|
||||
public function save_tree()
|
||||
{
|
||||
// echo "Save Tree<br />";
|
||||
foreach ($this->class_tree as $tree)
|
||||
{
|
||||
if (isset($tree['change_flag']))
|
||||
@@ -985,7 +998,7 @@ class user_class_admin extends user_class
|
||||
/*
|
||||
Next two routines show a text-based tree with markers to indicate the hierarchy.
|
||||
*/
|
||||
function show_sub_tree($listnum,$marker, $add_class = FALSE)
|
||||
protected function show_sub_tree($listnum,$marker, $add_class = FALSE)
|
||||
{
|
||||
$ret = '';
|
||||
$marker = '--'.$marker;
|
||||
@@ -1000,7 +1013,7 @@ class user_class_admin extends user_class
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function show_tree($add_class = FALSE)
|
||||
public function show_tree($add_class = FALSE)
|
||||
{
|
||||
$ret = '';
|
||||
foreach ($this->class_parents as $p)
|
||||
@@ -1020,7 +1033,7 @@ class user_class_admin extends user_class
|
||||
/*
|
||||
Next two routines generate a graphical tree, including option to open/close branches
|
||||
*/
|
||||
function show_graphical_subtree($listnum, $indent_images, $is_last = FALSE)
|
||||
protected function show_graphical_subtree($listnum, $indent_images, $is_last = FALSE)
|
||||
{
|
||||
$num_children = count($this->class_tree[$listnum]['class_children']);
|
||||
$is_open = TRUE;
|
||||
@@ -1093,7 +1106,7 @@ class user_class_admin extends user_class
|
||||
|
||||
|
||||
|
||||
function show_graphical_tree($show_debug=FALSE)
|
||||
public function show_graphical_tree($show_debug=FALSE)
|
||||
{
|
||||
$this->graph_debug = $show_debug;
|
||||
$indent_images = array();
|
||||
@@ -1115,7 +1128,7 @@ class user_class_admin extends user_class
|
||||
|
||||
|
||||
// Creates an array which contains only DB fields (i.e. strips the added status)
|
||||
function copy_rec($classrec, $inc_id = FALSE)
|
||||
protected function copy_rec($classrec, $inc_id = FALSE)
|
||||
{
|
||||
$ret = array();
|
||||
if ($inc_id && isset($classrec['userclass_id'])) $ret['userclass_id'] = $classrec['userclass_id'];
|
||||
@@ -1127,8 +1140,8 @@ class user_class_admin extends user_class
|
||||
}
|
||||
|
||||
|
||||
// Return an unused class ID - FALSE if none spare. Misses the predefined classes.
|
||||
function findNewClassID()
|
||||
// Return an unused class ID - FALSE if none spare. Misses the predefined classes. **** May need to be public rather than protected
|
||||
protected function findNewClassID()
|
||||
{
|
||||
$i = 1;
|
||||
// Start by allocating a new class with a number higher than any previously allocated
|
||||
@@ -1159,9 +1172,8 @@ class user_class_admin extends user_class
|
||||
|
||||
// Add new class. Class ID must be in the passed record.
|
||||
// Return TRUE on success, FALSE on failure
|
||||
function add_new_class($classrec)
|
||||
public function add_new_class($classrec)
|
||||
{
|
||||
// echo "Add new class<br />";
|
||||
if (!isset($classrec['userclass_id']))
|
||||
{
|
||||
return FALSE;
|
||||
@@ -1184,9 +1196,8 @@ class user_class_admin extends user_class
|
||||
}
|
||||
|
||||
|
||||
function save_edited_class($classrec)
|
||||
public function save_edited_class($classrec)
|
||||
{
|
||||
// echo "Save edited class: ".implode(',', $classrec)."<br />";
|
||||
if (!$classrec['userclass_id'])
|
||||
{
|
||||
echo "Programming bungle on save<br />";
|
||||
@@ -1222,38 +1233,54 @@ class user_class_admin extends user_class
|
||||
|
||||
|
||||
|
||||
function delete_class($class_id)
|
||||
|
||||
public function queryCanDeleteClass($classID)
|
||||
{
|
||||
if (isset($this->fixed_classes[$class_id])) return FALSE; // Some classes can't be deleted
|
||||
// echo "Delete class {$class_id}<br />";
|
||||
if (($classID >= e_UC_SPECIAL_BASE) && ($classID <= e_UC_SPECIAL_END)) return FALSE; // Don't allow deletion of fixed classes
|
||||
if (isset($this->fixed_classes[$class_id])) return FALSE; // This picks up classes such as e_UC_PUBLIC outside the main range which can't be deleted
|
||||
if (!isset($this->class_tree[$class_id])) return FALSE;
|
||||
if (count($this->class_tree[$class_id]['class_children'])) return FALSE; // Can't delete class with descendants
|
||||
foreach ($this->class_tree as $c)
|
||||
{
|
||||
if ($c['userclass_editclass'] == $class_id) return FALSE;
|
||||
if ($c['userclass_visibility'] == $class_id) return FALSE;
|
||||
if ($c['userclass_editclass'] == $classID) return FALSE;
|
||||
if ($c['userclass_visibility'] == $classID) return FALSE;
|
||||
}
|
||||
if ($this->sql_r->db_Delete('userclass_classes', "`userclass_id`='{$class_id}'") === FALSE) return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Delete a class
|
||||
// Return TRUE on success, FALSE on error
|
||||
public function delete_class($classID)
|
||||
{
|
||||
if (self::queryCanDeleteClass($classID) === FALSE) return FALSE;
|
||||
|
||||
if ($this->sql_r->db_Delete('userclass_classes', "`userclass_id`='{$classID}'") === FALSE) return FALSE;
|
||||
$this->clearCache();
|
||||
$this->readTree(TRUE); // Re-read the class tree
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
function deleteClassAndUsers($classID)
|
||||
// Delete a class, and all users who are members of that class.
|
||||
// Return TRUE on success, FALSE on error
|
||||
public function deleteClassAndUsers($classID)
|
||||
{
|
||||
if ($this->delete_class($classID))
|
||||
if (self::delete_class($classID) === TRUE)
|
||||
{
|
||||
if ($this->sql_r->db_Select('user', 'user_id, user_class', "user_class REGEXP '(^|,){$classID}(,|$)'"))
|
||||
{
|
||||
$sql2 = new db;
|
||||
while ($row = $this->sql_r->db_Fetch())
|
||||
{
|
||||
$newClass = $this->ucRemove($classID,$row['user_class']);
|
||||
$newClass = self::ucRemove($classID,$row['user_class']);
|
||||
$sql2->db_Update('user', "user_class = '{$newClass}' WHERE user_id = {$row['user_id']}");
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -1261,7 +1288,7 @@ class user_class_admin extends user_class
|
||||
// Certain fields on admin records have constraints on their values.
|
||||
// Checks the passed array, and updates any values which are unacceptable.
|
||||
// Returns TRUE if nothing changed, FALSE if changes made
|
||||
function checkAdminInfo(&$data, $id)
|
||||
public function checkAdminInfo(&$data, $id)
|
||||
{
|
||||
$ret = TRUE;
|
||||
if (($id < e_UC_SPECIAL_BASE) || ($id > e_UC_SPECIAL_END)) return TRUE;
|
||||
@@ -1294,7 +1321,7 @@ class user_class_admin extends user_class
|
||||
|
||||
|
||||
// Set default tree structure
|
||||
function set_default_structure()
|
||||
public function set_default_structure()
|
||||
{
|
||||
// If they don't exist, we need to create class records for the 'standard' user classes
|
||||
$init_list = array(
|
||||
@@ -1349,9 +1376,10 @@ class user_class_admin extends user_class
|
||||
}
|
||||
}
|
||||
|
||||
function clearCache()
|
||||
|
||||
public function clearCache()
|
||||
{
|
||||
global $e107;
|
||||
$e107 = e107::getInstance();
|
||||
$e107->ecache->clear_sys(UC_CACHE_TAG);
|
||||
}
|
||||
}
|
||||
@@ -1364,8 +1392,8 @@ class user_class_admin extends user_class
|
||||
// Legacy Admin Class handler - maybe add to admin class
|
||||
//========================================================================
|
||||
|
||||
// class_add() - called only from userclass2.php
|
||||
// class_remove() - called only from userclass2.php
|
||||
// class_add() - called only from userclass2.php - adds a list of users to a class
|
||||
// class_remove() - called only from userclass2.php - removes a list of users from a class
|
||||
// class_create() - called only from forum update routines - could probably go
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user