mirror of
https://github.com/e107inc/e107.git
synced 2025-07-28 18:30:53 +02:00
Update userclass management on plugin install/uninstall
This commit is contained in:
@@ -11,8 +11,8 @@
|
|||||||
| GNU General Public License (http://gnu.org).
|
| GNU General Public License (http://gnu.org).
|
||||||
|
|
|
|
||||||
| $Source: /cvs_backup/e107_0.8/e107_handlers/plugin_class.php,v $
|
| $Source: /cvs_backup/e107_0.8/e107_handlers/plugin_class.php,v $
|
||||||
| $Revision: 1.61 $
|
| $Revision: 1.62 $
|
||||||
| $Date: 2008-12-29 20:55:27 $
|
| $Date: 2008-12-29 22:30:16 $
|
||||||
| $Author: e107steved $
|
| $Author: e107steved $
|
||||||
+----------------------------------------------------------------------------+
|
+----------------------------------------------------------------------------+
|
||||||
*/
|
*/
|
||||||
@@ -304,19 +304,19 @@ class e107plugin
|
|||||||
function manage_userclass($action, $class_name, $class_description)
|
function manage_userclass($action, $class_name, $class_description)
|
||||||
{
|
{
|
||||||
global $sql, $tp, $e107;
|
global $sql, $tp, $e107;
|
||||||
|
if (!$e107->user_class->isAdmin)
|
||||||
|
{
|
||||||
|
$e107->user_class = new user_class_admin; // We need the extra methods of the admin extension
|
||||||
|
}
|
||||||
|
$class_name = strip_tags(strtoupper($class_name));
|
||||||
if ($action == 'add')
|
if ($action == 'add')
|
||||||
{
|
{
|
||||||
$class_name = strip_tags(strtoupper($class_name));
|
|
||||||
if ($e107->user_class->ucGetClassIDFromName($class_name) !== FALSE)
|
if ($e107->user_class->ucGetClassIDFromName($class_name) !== FALSE)
|
||||||
{ // Class already exists.
|
{ // Class already exists.
|
||||||
return TRUE; // That's probably OK
|
return TRUE; // That's probably OK
|
||||||
}
|
}
|
||||||
$i = 1;
|
$i = $e107->user_class->findNewClassID();
|
||||||
while (isset($e107->user_class->class_tree[$i]))
|
if ($i !== FALSE)
|
||||||
{
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
if ($i < e_UC_SPECIAL_BASE)
|
|
||||||
{
|
{
|
||||||
$tmp = array();
|
$tmp = array();
|
||||||
$tmp['userclass_id'] = $i;
|
$tmp['userclass_id'] = $i;
|
||||||
@@ -330,7 +330,7 @@ class e107plugin
|
|||||||
$tmp['_FIELD_TYPES']['userclass_visibility'] = 'int';
|
$tmp['_FIELD_TYPES']['userclass_visibility'] = 'int';
|
||||||
$tmp['_FIELD_TYPES']['userclass_id'] = 'int';
|
$tmp['_FIELD_TYPES']['userclass_id'] = 'int';
|
||||||
$tmp['_FIELD_TYPES']['_DEFAULT'] = 'todb';
|
$tmp['_FIELD_TYPES']['_DEFAULT'] = 'todb';
|
||||||
return $sql->db_Insert('userclass_classes', $tmp);
|
return $e107->user_class->add_new_class($tmp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -339,31 +339,16 @@ class e107plugin
|
|||||||
}
|
}
|
||||||
if ($action == 'remove')
|
if ($action == 'remove')
|
||||||
{
|
{
|
||||||
if ($sql->db_Select('userclass_classes', 'userclass_id', "userclass_name = '{$class_name}'"))
|
$classID = $e107->user_class->ucGetClassIDFromName($class_name);
|
||||||
|
echo "Class ID: {$classID}, name: {$class_name}<br />";
|
||||||
|
if (($classID !== FALSE)
|
||||||
|
&& ($e107->user_class->deleteClassAndUsers($classID) === TRUE))
|
||||||
{
|
{
|
||||||
$row = $sql->db_Fetch();
|
return TRUE;
|
||||||
$class_id = $row['userclass_id'];
|
|
||||||
if ($sql->db_Delete('userclass_classes', "userclass_id = {$class_id}"))
|
|
||||||
{
|
|
||||||
if ($sql->db_Select('user', 'user_id, user_class', "user_class REGEXP('^{$class_id}\.') OR user_class REGEXP('\.{$class_id}\.') OR user_class REGEXP('\.{$class_id}$')"))
|
|
||||||
{
|
|
||||||
$sql2 = new db;
|
|
||||||
while ($row = $sql->db_Fetch())
|
|
||||||
{
|
|
||||||
$classes = explode(".", $row['user_class']);
|
|
||||||
unset($classes[$class_id]);
|
|
||||||
foreach($classes as $k => $v)
|
|
||||||
{
|
|
||||||
if ($v = '')
|
|
||||||
{
|
|
||||||
unset($classes[$k]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$newclass = '.'.implode('.', $classes).'.';
|
|
||||||
$sql2->db_Update('user', "user_class = '{$newclass}' WHERE user_id = {$row['user_id']}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1003,26 +988,27 @@ class e107plugin
|
|||||||
$attrib = $uclass['@attributes'];
|
$attrib = $uclass['@attributes'];
|
||||||
switch($function)
|
switch($function)
|
||||||
{
|
{
|
||||||
case 'install':
|
case 'install' :
|
||||||
case 'upgrade':
|
case 'upgrade' :
|
||||||
// Add all active userclasses
|
case 'refresh' :
|
||||||
|
// Add all active userclasses (code checks for already installed)
|
||||||
if(!isset($attrib['active']) || $attrib['active'] == 'true')
|
if(!isset($attrib['active']) || $attrib['active'] == 'true')
|
||||||
{
|
{
|
||||||
$txt .= "Adding userclass ".$attrib['name']."<br />";
|
$txt .= 'Adding userclass '.$attrib['name'].'<br />';
|
||||||
$this->manage_userclass('add', $attrib['name'], $attrib['description']);
|
$this->manage_userclass('add', $attrib['name'], $attrib['description']);
|
||||||
}
|
}
|
||||||
|
|
||||||
//If upgrading, removing any inactive userclass
|
//If upgrading, removing any inactive userclass
|
||||||
if($function == 'upgrade' && isset($attrib['active']) && $attrib['active'] == 'false')
|
if($function == 'upgrade' && isset($attrib['active']) && $attrib['active'] == 'false')
|
||||||
{
|
{
|
||||||
$txt .= "Removing userclass ".$attrib['name']."<br />";
|
$txt .= 'Removing userclass '.$attrib['name'].'<br />';
|
||||||
$this->manage_userclass('remove', $attrib['name'], $attrib['description']);
|
$this->manage_userclass('remove', $attrib['name'], $attrib['description']);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//If uninstalling, remove all userclasses (active or inactive)
|
//If uninstalling, remove all userclasses (active or inactive)
|
||||||
case 'uninstall':
|
case 'uninstall':
|
||||||
$txt .= "Removing userclass ".$attrib['name']."<br />";
|
$txt .= 'Removing userclass '.$attrib['name'].'<br />';
|
||||||
$this->manage_userclass('remove', $attrib['name'], $attrib['description']);
|
$this->manage_userclass('remove', $attrib['name'], $attrib['description']);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -11,8 +11,8 @@
|
|||||||
| GNU General Public License (http://gnu.org).
|
| GNU General Public License (http://gnu.org).
|
||||||
|
|
|
|
||||||
| $Source: /cvs_backup/e107_0.8/e107_handlers/userclass_class.php,v $
|
| $Source: /cvs_backup/e107_0.8/e107_handlers/userclass_class.php,v $
|
||||||
| $Revision: 1.26 $
|
| $Revision: 1.27 $
|
||||||
| $Date: 2008-12-29 09:31:36 $
|
| $Date: 2008-12-29 22:30:16 $
|
||||||
| $Author: e107steved $
|
| $Author: e107steved $
|
||||||
+----------------------------------------------------------------------------+
|
+----------------------------------------------------------------------------+
|
||||||
*/
|
*/
|
||||||
@@ -62,6 +62,7 @@ class user_class
|
|||||||
var $text_class_link = array(); // List of 'core' user classes and the related constants
|
var $text_class_link = array(); // List of 'core' user classes and the related constants
|
||||||
|
|
||||||
var $sql_r; // We'll use our own DB to avoid interactions
|
var $sql_r; // We'll use our own DB to avoid interactions
|
||||||
|
var $isAdmin; // Set true if we're an instance of user_class_admin
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
function user_class()
|
function user_class()
|
||||||
@@ -69,6 +70,7 @@ class user_class
|
|||||||
global $imode;
|
global $imode;
|
||||||
|
|
||||||
$this->sql_r = new db;
|
$this->sql_r = new db;
|
||||||
|
$this->isAdmin = FALSE;
|
||||||
|
|
||||||
$this->fixed_classes = array(e_UC_PUBLIC => UC_LAN_0,
|
$this->fixed_classes = array(e_UC_PUBLIC => UC_LAN_0,
|
||||||
e_UC_GUEST => UC_LAN_1,
|
e_UC_GUEST => UC_LAN_1,
|
||||||
@@ -665,6 +667,7 @@ class user_class
|
|||||||
}
|
}
|
||||||
$tmp = array_keys($tmp);
|
$tmp = array_keys($tmp);
|
||||||
if ($asArray) { return $tmp; }
|
if ($asArray) { return $tmp; }
|
||||||
|
if (count($tmp) == 0) { return ''; }
|
||||||
return implode(',',$tmp);
|
return implode(',',$tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -822,6 +825,7 @@ class user_class_admin extends user_class
|
|||||||
function user_class_admin()
|
function user_class_admin()
|
||||||
{
|
{
|
||||||
$this->user_class(); // Call constructor from ancestor class
|
$this->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
|
// Have to initialise the images this way - PHP4 won't take a nested array assignment in the variable list
|
||||||
$this->tree_icons = array(
|
$this->tree_icons = array(
|
||||||
@@ -878,7 +882,7 @@ class user_class_admin extends user_class
|
|||||||
}
|
}
|
||||||
if ($this->class_tree[$parent]['userclass_type'] == UC_TYPE_GROUP)
|
if ($this->class_tree[$parent]['userclass_type'] == UC_TYPE_GROUP)
|
||||||
{
|
{
|
||||||
echo "Bottom up - skip: {$parent}<br />";
|
// echo "Bottom up - skip: {$parent}<br />";
|
||||||
return; // Probably just stop here for a group class
|
return; // Probably just stop here for a group class
|
||||||
}
|
}
|
||||||
$rights[] = $parent;
|
$rights[] = $parent;
|
||||||
@@ -1109,10 +1113,15 @@ 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)
|
function add_new_class($classrec)
|
||||||
{
|
{
|
||||||
// echo "Add new class<br />";
|
// echo "Add new class<br />";
|
||||||
|
if (!isset($classrec['userclass_id']))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
if ($classrec['userclass_type'] == UC_TYPE_GROUP)
|
if ($classrec['userclass_type'] == UC_TYPE_GROUP)
|
||||||
{ // Need to make sure our ID is in the accumulation array
|
{ // Need to make sure our ID is in the accumulation array
|
||||||
$temp = explode(',',$classrec['userclass_accum']);
|
$temp = explode(',',$classrec['userclass_accum']);
|
||||||
@@ -1122,8 +1131,12 @@ class user_class_admin extends user_class
|
|||||||
$classrec['userclass_accum'] = implode(',',$temp);
|
$classrec['userclass_accum'] = implode(',',$temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->sql_r->db_Insert('userclass_classes',$this->copy_rec($classrec, TRUE));
|
if ($this->sql_r->db_Insert('userclass_classes',$this->copy_rec($classrec, TRUE)) === FALSE)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
$this->clearCache();
|
$this->clearCache();
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1133,7 +1146,7 @@ class user_class_admin extends user_class
|
|||||||
if (!$classrec['userclass_id'])
|
if (!$classrec['userclass_id'])
|
||||||
{
|
{
|
||||||
echo "Programming bungle on save<br />";
|
echo "Programming bungle on save<br />";
|
||||||
return;
|
return FALSE;
|
||||||
}
|
}
|
||||||
$qry = '';
|
$qry = '';
|
||||||
$spacer = '';
|
$spacer = '';
|
||||||
@@ -1155,14 +1168,20 @@ class user_class_admin extends user_class
|
|||||||
$spacer = ", ";
|
$spacer = ", ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->sql_r->db_Update('userclass_classes', $qry." WHERE `userclass_id`='{$classrec['userclass_id']}'");
|
if ($this->sql_r->db_Update('userclass_classes', $qry." WHERE `userclass_id`='{$classrec['userclass_id']}'") === FALSE)
|
||||||
$this->clearCache();
|
{
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
$this->clearCache();
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function delete_class($class_id)
|
function delete_class($class_id)
|
||||||
{
|
{
|
||||||
if (isset($this->fixed_classes[$class_id])) return FALSE; // Some classes can't be deleted
|
if (isset($this->fixed_classes[$class_id])) return FALSE; // Some classes can't be deleted
|
||||||
|
// echo "Delete class {$class_id}<br />";
|
||||||
if (!isset($this->class_tree[$class_id])) return FALSE;
|
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
|
if (count($this->class_tree[$class_id]['class_children'])) return FALSE; // Can't delete class with descendants
|
||||||
foreach ($this->class_tree as $c)
|
foreach ($this->class_tree as $c)
|
||||||
@@ -1170,13 +1189,31 @@ class user_class_admin extends user_class
|
|||||||
if ($c['userclass_editclass'] == $class_id) return FALSE;
|
if ($c['userclass_editclass'] == $class_id) return FALSE;
|
||||||
if ($c['userclass_visibility'] == $class_id) return FALSE;
|
if ($c['userclass_visibility'] == $class_id) return FALSE;
|
||||||
}
|
}
|
||||||
if (!$this->sql_r->db_Delete('userclass_classes', "`userclass_id`='{$class_id}'")) return FALSE;
|
if ($this->sql_r->db_Delete('userclass_classes', "`userclass_id`='{$class_id}'") === FALSE) return FALSE;
|
||||||
$this->clearCache();
|
$this->clearCache();
|
||||||
$this->readTree(TRUE); // Re-read the class tree
|
$this->readTree(TRUE); // Re-read the class tree
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function deleteClassAndUsers($classID)
|
||||||
|
{
|
||||||
|
if ($this->delete_class($classID))
|
||||||
|
{
|
||||||
|
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']);
|
||||||
|
$sql2->db_Update('user', "user_class = '{$newClass}' WHERE user_id = {$row['user_id']}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Certain fields on admin records have constraints on their values.
|
// Certain fields on admin records have constraints on their values.
|
||||||
// Checks the passed array, and updates any values which are unacceptable.
|
// Checks the passed array, and updates any values which are unacceptable.
|
||||||
// Returns TRUE if nothing changed, FALSE if changes made
|
// Returns TRUE if nothing changed, FALSE if changes made
|
||||||
|
Reference in New Issue
Block a user