2006-12-02 04:36:16 +00:00
< ? php
/*
2009-11-17 10:46:35 +00:00
* e107 website system
*
2017-01-09 17:07:47 +00:00
* Copyright ( C ) 2008 - 2017 e107 Inc ( e107 . org )
2009-11-17 10:46:35 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
2010-01-11 21:09:52 +00:00
* User class functions
2009-11-17 10:46:35 +00:00
*
*/
2007-12-22 12:39:27 +00:00
2010-01-11 21:09:52 +00:00
/**
2010-03-11 11:56:23 +00:00
*
2010-01-11 21:09:52 +00:00
* @ package e107
* @ subpackage e107_handlers
*
* This class handles all user - related user class functions . Admin functions inherit from it .
*/
2007-12-22 12:39:27 +00:00
2006-12-02 04:36:16 +00:00
if ( ! defined ( 'e107_INIT' )) { exit ; }
2008-11-29 21:16:54 +00:00
2017-01-23 09:41:23 -08:00
e107 :: includeLan ( e_LANGUAGEDIR . e_LANGUAGE . '/lan_userclass.php' );
2006-12-02 04:36:16 +00:00
2007-12-22 12:39:27 +00:00
/*
2009-12-07 20:43:37 +00:00
Fixed classes occupy a numeric block from e_UC_SPECIAL_BASE to e_UC_SPECIAL_END , plus zero = e_UC_PUBLIC
2012-01-20 18:08:31 +00:00
( Note that in 0.7 / 1.0 , class numbers stopped at 255. Now they can be up to 65535 ) .
2007-12-22 12:39:27 +00:00
For info :
define ( " e_UC_PUBLIC " , 0 );
define ( " e_UC_MAINADMIN " , 250 );
define ( " e_UC_READONLY " , 251 );
define ( " e_UC_GUEST " , 252 );
define ( " e_UC_MEMBER " , 253 );
define ( " e_UC_ADMIN " , 254 );
define ( " e_UC_NOBODY " , 255 );
2006-12-02 04:36:16 +00:00
*/
2012-12-30 22:42:17 +00:00
define ( 'e_UC_ADMINMOD' , 249 ); // Admins (includes main admins)
define ( 'e_UC_MODS' , 248 ); // Moderators (who aren't admins)
define ( 'e_UC_NEWUSER' , 247 ); // Users in 'probationary' period
define ( 'e_UC_BOTS' , 246 ); // Reserved to identify search bots
2011-12-28 22:38:18 +00:00
// 243..245 reserved for future predefined user classes
2012-06-20 01:12:33 +00:00
define ( 'e_UC_SPECIAL_BASE' , 243 ); // Assign class IDs 243 and above for fixed/special purposes
2013-01-01 10:39:30 +00:00
define ( 'e_UC_SPECIAL_END' , 255 ); // Highest 'special' class
2007-12-22 12:39:27 +00:00
2012-06-20 01:12:33 +00:00
define ( 'UC_ICON_DIR' , e_IMAGE_ABS . 'generic/' ); // Directory for the icons used in the admin tree displays
2007-12-22 12:39:27 +00:00
2013-02-05 21:46:18 +00:00
define ( 'e_UC_BLANK' , '-32767' ); // Code for internal use - needs to be large to avoid confusion with 'not a member of...'
2012-12-30 22:42:17 +00:00
define ( 'UC_TYPE_STD' , '0' ); // User class is 'normal'
define ( 'UC_TYPE_GROUP' , '1' ); // User class is a group or list of subsidiary classes
2007-12-22 12:39:27 +00:00
2008-11-29 21:16:54 +00:00
define ( 'UC_CACHE_TAG' , 'nomd5_classtree' );
2010-03-11 21:55:45 +00:00
2007-12-22 12:39:27 +00:00
class user_class
{
2010-03-11 21:55:45 +00:00
public $class_tree ; // Simple array, filled with current tree. Additional field class_children is an array of child user classes (by ID)
protected $class_parents ; // Array of class IDs of 'parent' (i.e. top level) classes
2009-01-15 15:42:24 +00:00
2010-03-11 21:55:45 +00:00
public $fixed_classes = array (); // The 'predefined' core classes (constants beginning 'e_UC_') (would be nice to have this R/O outside)
public $text_class_link = array (); // List of 'core' user classes and the related constants
2009-01-15 15:42:24 +00:00
2010-03-11 21:55:45 +00:00
protected $sql_r ; // We'll use our own DB to avoid interactions
protected $isAdmin ; // Set true if we're an instance of user_class_admin
2009-01-15 15:42:24 +00:00
2009-12-07 20:43:37 +00:00
2007-12-22 12:39:27 +00:00
// Constructor
2009-12-07 20:43:37 +00:00
public function __construct ()
2007-12-22 12:39:27 +00:00
{
2009-12-07 20:43:37 +00:00
$this -> sql_r = e107 :: getDb ( 'sql_r' );
$this -> isAdmin = FALSE ;
2009-01-15 15:42:24 +00:00
2012-01-20 18:08:31 +00:00
$this -> fixed_classes = array (
e_UC_PUBLIC => UC_LAN_0 ,
2007-12-22 12:39:27 +00:00
e_UC_GUEST => UC_LAN_1 ,
e_UC_NOBODY => UC_LAN_2 ,
e_UC_MEMBER => UC_LAN_3 ,
e_UC_ADMIN => UC_LAN_5 ,
e_UC_MAINADMIN => UC_LAN_6 ,
2008-12-21 11:07:58 +00:00
e_UC_READONLY => UC_LAN_4 ,
2009-11-01 17:19:27 +00:00
e_UC_NEWUSER => UC_LAN_9 ,
e_UC_BOTS => UC_LAN_10
2007-12-22 12:39:27 +00:00
);
2012-06-20 01:12:33 +00:00
2009-01-15 15:42:24 +00:00
2009-12-07 20:43:37 +00:00
$this -> text_class_link = array ( 'public' => e_UC_PUBLIC , 'guest' => e_UC_GUEST , 'nobody' => e_UC_NOBODY , 'member' => e_UC_MEMBER ,
2011-12-28 22:38:18 +00:00
'admin' => e_UC_ADMIN , 'main' => e_UC_MAINADMIN , 'new' => e_UC_NEWUSER , 'mods' => e_UC_MODS ,
2009-11-01 17:19:27 +00:00
'bots' => e_UC_BOTS , 'readonly' => e_UC_READONLY );
2012-06-20 01:12:33 +00:00
2007-12-22 12:39:27 +00:00
2009-12-07 20:43:37 +00:00
$this -> readTree ( TRUE ); // Initialise the classes on entry
2006-12-02 04:36:16 +00:00
}
2015-04-14 11:59:46 -07:00
2016-03-26 15:17:11 -07:00
public function getFixedClassDescription ( $id )
{
if ( isset ( $this -> fixed_classes [ $id ]))
{
return $this -> fixed_classes [ $id ];
}
return false ;
}
2015-04-14 11:59:46 -07:00
/**
* Take a key value such as 'member' and return it ' s numerical value .
* @ param $text
* @ return bool
*/
public function getClassFromKey ( $text )
{
if ( isset ( $this -> text_class_link [ $text ]))
{
return $this -> text_class_link [ $text ];
}
return false ;
}
2010-03-17 23:59:52 +00:00
/**
* Return value of isAdmin
*/
public function isAdmin ()
{
return $this -> isAdmin ;
}
2007-12-22 12:39:27 +00:00
2009-12-07 20:43:37 +00:00
/**
2010-01-11 21:09:52 +00:00
* Ensure the tree of userclass data is stored in our object ( $this -> class_tree ) .
* Only read if its either not present , or the $force flag is set .
* Data is cached if enabled
*
* @ param boolean $force - set to TRUE to force a re - read of the info regardless .
* @ return none
2007-12-22 12:39:27 +00:00
*/
2010-05-17 14:13:50 +00:00
public function readTree ( $force = FALSE )
2009-12-07 20:43:37 +00:00
{
if ( isset ( $this -> class_tree ) && count ( $this -> class_tree ) && ! $force ) return ;
2009-01-15 15:42:24 +00:00
2009-12-07 20:43:37 +00:00
$e107 = e107 :: getInstance ();
2007-12-22 12:39:27 +00:00
2009-12-07 20:43:37 +00:00
$this -> class_tree = array ();
$this -> class_parents = array ();
2008-11-29 21:16:54 +00:00
2013-02-26 19:53:49 -08:00
2009-12-07 20:43:37 +00:00
if ( $temp = $e107 -> ecache -> retrieve_sys ( UC_CACHE_TAG ))
2008-11-29 21:16:54 +00:00
{
2016-03-22 16:52:54 -07:00
$this -> class_tree = e107 :: unserialize ( $temp );
2009-12-07 20:43:37 +00:00
unset ( $temp );
2008-11-29 21:16:54 +00:00
}
2009-12-07 20:43:37 +00:00
else
{
2016-03-22 16:52:54 -07:00
if ( $this -> sql_r -> field ( 'userclass_classes' , 'userclass_parent' ) && $this -> sql_r -> select ( 'userclass_classes' , '*' , 'ORDER BY userclass_parent,userclass_name' , 'nowhere' )) // The order statement should give a consistent return
2009-12-07 20:43:37 +00:00
{
2016-02-14 12:15:55 -08:00
while ( $row = $this -> sql_r -> fetch ())
2015-08-24 17:39:28 -07:00
{
$this -> class_tree [ $row [ 'userclass_id' ]] = $row ;
$this -> class_tree [ $row [ 'userclass_id' ]][ 'class_children' ] = array (); // Create the child array in case needed
}
2009-12-07 20:43:37 +00:00
}
2008-11-29 21:16:54 +00:00
2012-12-30 22:42:17 +00:00
// Add in any fixed classes that aren't already defined (they historically didn't have a DB entry, although now its facilitated (and necessary for tree structure)
2009-12-07 20:43:37 +00:00
foreach ( $this -> fixed_classes as $c => $d )
2008-11-29 21:16:54 +00:00
{
2009-12-07 20:43:37 +00:00
if ( ! isset ( $this -> class_tree [ $c ]))
2008-12-21 11:07:58 +00:00
{
2009-12-07 20:43:37 +00:00
switch ( $c )
{
case e_UC_ADMIN :
case e_UC_MAINADMIN :
$this -> class_tree [ $c ][ 'userclass_parent' ] = e_UC_NOBODY ;
break ;
case e_UC_NEWUSER :
$this -> class_tree [ $c ][ 'userclass_parent' ] = e_UC_MEMBER ;
break ;
default :
$this -> class_tree [ $c ][ 'userclass_parent' ] = e_UC_PUBLIC ;
}
$this -> class_tree [ $c ][ 'userclass_id' ] = $c ;
$this -> class_tree [ $c ][ 'userclass_name' ] = $d ;
$this -> class_tree [ $c ][ 'userclass_description' ] = 'Fixed class' ;
$this -> class_tree [ $c ][ 'userclass_visibility' ] = e_UC_PUBLIC ;
$this -> class_tree [ $c ][ 'userclass_editclass' ] = e_UC_MAINADMIN ;
$this -> class_tree [ $c ][ 'userclass_accum' ] = $c ;
$this -> class_tree [ $c ][ 'userclass_type' ] = UC_TYPE_STD ;
2008-12-21 11:07:58 +00:00
}
2008-11-29 21:16:54 +00:00
}
2013-03-31 05:55:08 -07:00
$userCache = e107 :: serialize ( $this -> class_tree , FALSE );
2009-12-07 20:43:37 +00:00
$e107 -> ecache -> set_sys ( UC_CACHE_TAG , $userCache );
unset ( $userCache );
}
2008-03-23 10:11:17 +00:00
2009-12-07 20:43:37 +00:00
// Now build the tree.
// There are just two top-level classes - 'Everybody' and 'Nobody'
$this -> class_parents [ e_UC_PUBLIC ] = e_UC_PUBLIC ;
$this -> class_parents [ e_UC_NOBODY ] = e_UC_NOBODY ;
foreach ( $this -> class_tree as $uc )
2008-11-29 21:16:54 +00:00
{
2009-12-07 20:43:37 +00:00
if (( $uc [ 'userclass_id' ] != e_UC_PUBLIC ) && ( $uc [ 'userclass_id' ] != e_UC_NOBODY ))
2008-11-29 21:16:54 +00:00
{
2009-12-07 20:43:37 +00:00
if ( ! isset ( $this -> class_tree [ $uc [ 'userclass_parent' ]]))
{
echo " Orphaned class record: ID= " . $uc [ 'userclass_id' ] . " Name= " . $uc [ 'userclass_name' ] . " Parent= " . $uc [ 'userclass_parent' ] . " <br /> " ;
}
else
{ // Add to array
$this -> class_tree [ $uc [ 'userclass_parent' ]][ 'class_children' ][] = $uc [ 'userclass_id' ];
}
2008-11-29 21:16:54 +00:00
}
2007-12-22 12:39:27 +00:00
}
2009-01-15 15:42:24 +00:00
}
2007-12-22 12:39:27 +00:00
2012-12-30 22:42:17 +00:00
/**
* Given the list of 'base' classes a user belongs to , returns a comma separated list including ancestors . Duplicates stripped
2009-12-07 20:43:37 +00:00
*
* @ param string $startList - comma - separated list of classes user belongs to
* @ param boolean $asArray - if TRUE , result returned as array ; otherwise result returned as string
* @ return string | array of user classes ; format determined by $asArray
*/
public function get_all_user_classes ( $startList , $asArray = FALSE )
2008-12-28 22:37:43 +00:00
{
$is = array ();
2009-12-07 20:43:37 +00:00
$start_array = explode ( ',' , $startList );
2016-03-22 16:52:54 -07:00
2008-12-28 22:37:43 +00:00
foreach ( $start_array as $sa )
{ // Merge in latest values - should eliminate duplicates as it goes
2011-06-27 09:46:16 +00:00
$is [] = $sa ; // add parent to the flat list first
2008-12-28 22:37:43 +00:00
if ( isset ( $this -> class_tree [ $sa ]))
{
2011-06-27 09:46:16 +00:00
if ( $this -> class_tree [ $sa ][ 'userclass_accum' ])
{
$is = array_merge ( $is , explode ( ',' , $this -> class_tree [ $sa ][ 'userclass_accum' ]));
}
2008-12-28 22:37:43 +00:00
}
}
2009-12-07 20:43:37 +00:00
if ( $asArray )
{
return array_unique ( $is );
}
2008-12-28 22:37:43 +00:00
return implode ( ',' , array_unique ( $is ));
2006-12-02 04:36:16 +00:00
}
2007-12-22 12:39:27 +00:00
2009-12-07 20:43:37 +00:00
2012-12-30 22:42:17 +00:00
/**
* Returns a list of user classes which can be edited by the specified classlist
2009-12-07 20:43:37 +00:00
*
* @ param string $classList - comma - separated list of classes to consider - default current user ' s class list
* @ param boolean $asArray - if TRUE , result returned as array ; otherwise result returned as string
* @ return string | array of user classes ; format determined by $asArray
*/
public function get_editable_classes ( $classList = USERCLASS_LIST , $asArray = FALSE )
2008-01-07 22:30:29 +00:00
{
2008-12-28 22:37:43 +00:00
$ret = array ();
2009-11-01 17:19:27 +00:00
$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 , e_UC_BOTS => 1 );
2009-12-07 20:43:37 +00:00
$possibles = array_flip ( explode ( ',' , $classList ));
2008-12-28 22:37:43 +00:00
unset ( $possibles [ e_UC_READONLY ]);
2019-05-01 17:08:33 -07:00
2008-12-28 22:37:43 +00:00
foreach ( $this -> class_tree as $uc => $uv )
2008-01-08 22:24:22 +00:00
{
2008-12-28 22:37:43 +00:00
if ( ! isset ( $blockers [ $uc ]))
{
$ec = $uv [ 'userclass_editclass' ];
2019-05-01 17:08:33 -07:00
// $ec = $uv['userclass_visibility'];
2008-12-28 22:37:43 +00:00
if ( isset ( $possibles [ $ec ]))
{
$ret [] = $uc ;
}
}
2008-01-08 22:24:22 +00:00
}
2008-12-28 22:37:43 +00:00
if ( $asArray ) { return $ret ; }
return implode ( ',' , $ret );
}
2009-01-15 15:42:24 +00:00
2010-03-11 11:56:23 +00:00
/**
2010-01-11 21:09:52 +00:00
* Combines the selected editable classes into the main class list for a user .
2012-12-30 22:42:17 +00:00
*
2009-12-07 20:43:37 +00:00
* @ param array | string $combined - the complete list of current class memberships
* @ param array | string $possible - the classes which are being edited
* @ param array | string $actual - the actual membership of the editable classes
* @ param boolean $asArray - if TRUE , result returned as array ; otherwise result returned as string
* @ return string | array of user classes ; format determined by $asArray
*/
2009-08-19 21:33:20 +00:00
public function mergeClassLists ( $combined , $possible , $actual , $asArray = FALSE )
2008-12-28 22:37:43 +00:00
{
if ( ! is_array ( $combined )) { $combined = explode ( ',' , $combined ); }
if ( ! is_array ( $possible )) { $possible = explode ( ',' , $possible ); }
if ( ! is_array ( $actual )) { $actual = explode ( ',' , $actual ); }
$combined = array_flip ( $combined );
foreach ( $possible as $p )
{
if ( in_array ( $p , $actual ))
{ // Class must be in final array
$combined [ $p ] = 1 ;
}
else
{
unset ( $combined [ $p ]);
}
}
$combined = array_keys ( $combined );
if ( $asArray ) { return $combined ; }
return implode ( ',' , $combined );
}
2009-12-07 20:43:37 +00:00
2012-12-30 22:42:17 +00:00
/**
* Remove the fixed classes from a class list
2009-12-07 20:43:37 +00:00
* Removes all classes in the reserved block , as well as e_UC_PUBLIC
* @ param array | string $inClasses - the complete list of current class memberships
* @ return string | array of user classes ; format is the same as $inClasses
*/
2009-08-19 21:33:20 +00:00
public function stripFixedClasses ( $inClasses )
2008-12-28 22:37:43 +00:00
{
$asArray = TRUE ;
if ( ! is_array ( $inClasses ))
{
$asArray = FALSE ;
$inClasses = explode ( ',' , $inClasses );
}
2009-12-07 20:43:37 +00:00
/*
2008-12-28 22:37:43 +00:00
$inClasses = array_flip ( $inClasses );
foreach ( $this -> fixed_classes as $k => $v )
{
if ( isset ( $inClasses [ $k ])) { unset ( $inClasses [ $k ]); }
}
$inClasses = array_keys ( $inClasses );
2009-12-07 20:43:37 +00:00
*/
foreach ( $inClasses as $k => $uc )
{
if ((( $uc >= e_UC_SPECIAL_BASE ) && ( $uc <= e_UC_SPECIAL_END )) || ( $uc == e_UC_PUBLIC ))
{
unset ( $inClasses [ $k ]);
}
}
2008-12-28 22:37:43 +00:00
if ( $asArray ) { return ( $inClasses ); }
return implode ( ',' , $inClasses );
2008-01-07 22:30:29 +00:00
}
2007-12-22 12:39:27 +00:00
2009-12-07 20:43:37 +00:00
2012-01-20 18:08:31 +00:00
/**
* 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 )
2009-12-07 20:43:37 +00:00
* Requires the class tree to have been initialised
2012-01-20 18:08:31 +00:00
*
2009-12-07 20:43:37 +00:00
* @ param array | string $classList - the complete list of current class memberships
2012-01-20 18:08:31 +00:00
*
* @ return string | array of user classes ; format is the same as $classList
2009-12-07 20:43:37 +00:00
*/
public function normalise_classes ( $classList )
{
2012-01-20 18:08:31 +00:00
if ( is_array ( $classList ))
{
$asArray = TRUE ;
$oldClasses = $classList ;
}
else
2007-12-22 12:39:27 +00:00
{
2009-12-07 20:43:37 +00:00
$asArray = FALSE ;
$oldClasses = explode ( ',' , $classList );
}
$dropClasses = array ();
foreach ( $oldClasses as $c )
{ // Look at our parents (which are in 'userclass_accum') - if any of them are contained in oldClasses, we can drop them.
$tc = array_flip ( explode ( ',' , $this -> class_tree [ $c ][ 'userclass_accum' ]));
unset ( $tc [ $c ]); // Current class should be in $tc anyway
foreach ( $tc as $tc_c => $v )
{
if ( in_array ( $tc_c , $oldClasses ))
{
$dropClasses [] = $tc_c ;
}
}
2007-12-22 12:39:27 +00:00
}
2009-12-07 20:43:37 +00:00
$newClasses = array_diff ( $oldClasses , $dropClasses );
if ( $asArray ) { return $newClasses ; }
return implode ( ',' , $newClasses );
2006-12-02 04:36:16 +00:00
}
2007-12-22 12:39:27 +00:00
2009-01-15 15:42:24 +00:00
2016-04-01 19:59:51 -07:00
/**
* @ param string $optlist - comma - separated list of classes / class types to be included in the list
It allows selection of the classes to be shown in the dropdown . All or none can be included , separated by comma . Valid options are :
public
guest
nobody
member
readonly
admin
main - main admin
new - new users
bots - search bot class
classes - shows all classes
matchclass - if 'classes' is set , this option will only show the classes that the user is a member of
* @ return array
*/
public function getClassList ( $optlist )
{
return $this -> uc_required_class_list ( $optlist );
}
2009-01-15 15:42:24 +00:00
2007-12-22 12:39:27 +00:00
2012-01-20 18:08:31 +00:00
/**
* Generate a dropdown list of user classes from which to select - virtually as the deprecated r_userclass () function did
2009-12-07 20:43:37 +00:00
* [ $mode parameter of r_userclass () removed - $optlist is more flexible ) ]
2012-01-20 18:08:31 +00:00
*
2009-12-07 20:43:37 +00:00
* @ param string $fieldname - name of select list
* @ param mixed $curval - current selected value ( empty string if no current value )
* @ param string $optlist - comma - separated list of classes / class types to be included in the list
It allows selection of the classes to be shown in the dropdown . All or none can be included , separated by comma . Valid options are :
2007-12-22 12:39:27 +00:00
public
guest
nobody
member
readonly
admin
main - main admin
2008-12-21 11:07:58 +00:00
new - new users
2009-11-01 17:19:27 +00:00
bots - search bot class
2007-12-22 12:39:27 +00:00
classes - shows all classes
matchclass - if 'classes' is set , this option will only show the classes that the user is a member of
2008-04-05 16:30:18 +00:00
blank - puts an empty option at the top of select dropdowns
2007-12-22 12:39:27 +00:00
2013-01-01 10:39:30 +00:00
filter - only show those classes where member is in a class permitted to view them - e . g . as the new 'visible to' field - added for 2.0
2012-01-20 18:08:31 +00:00
force - show all classes ( subject to the other options , including matchclass ) - added for 2.0
2012-12-18 21:21:05 +00:00
all - alias for 'force'
2007-12-22 12:39:27 +00:00
2009-12-07 20:43:37 +00:00
no - excludes - if present , doesn 't show the ' not member of ' list
2012-12-18 21:21:05 +00:00
is - checkbox - if present , suppresses the < optgroup ...> construct round the 'not member of' list
2009-01-15 15:42:24 +00:00
2009-12-07 20:43:37 +00:00
editable - can only appear on its own - returns list of those classes the user can edit ( manage )
2007-12-22 12:39:27 +00:00
2009-12-07 20:43:37 +00:00
* @ param string $extra_js - can add JS handlers ( e . g . 'onclick' , 'onchange' ) if required
*/
public function uc_dropdown ( $fieldname , $curval = 0 , $optlist = '' , $extra_js = '' )
{
$show_classes = self :: uc_required_class_list ( $optlist ); // Get list of classes which meet criteria
2007-12-22 12:39:27 +00:00
2009-08-19 21:33:20 +00:00
$text = '' ;
foreach ( $show_classes as $k => $v )
2008-04-05 16:30:18 +00:00
{
2009-08-19 21:33:20 +00:00
if ( $k == e_UC_BLANK )
{
2009-12-07 20:43:37 +00:00
$text .= " <option value=''> </option> \n " ;
2009-08-19 21:33:20 +00:00
}
else
{
2009-12-07 20:43:37 +00:00
$s = ( $curval == $k && $curval !== '' ) ? " selected='selected' " : '' ;
$text .= " <option class='uc-select' value=' " . $k . " ' " . $s . " > " . $v . " </option> \n " ;
2009-08-19 21:33:20 +00:00
}
2008-04-05 16:30:18 +00:00
}
2009-08-19 21:33:20 +00:00
2015-06-02 14:25:39 -07:00
if ( is_array ( $extra_js ))
{
$options = $extra_js ;
unset ( $extra_js );
}
$class = " tbox form-control " ;
if ( ! empty ( $options [ 'class' ]))
{
$class .= " " . $options [ 'class' ];
}
2009-08-19 21:33:20 +00:00
// Inverted Classes
2012-12-18 21:29:53 +00:00
if ( strpos ( $optlist , 'no-excludes' ) === FALSE )
2008-04-05 16:30:18 +00:00
{
2012-12-18 21:21:05 +00:00
if ( strpos ( $optlist , 'is-checkbox' ) !== FALSE )
{
$text .= " \n " . UC_LAN_INVERTLABEL . " <br /> \n " ;
}
else
{
2018-09-04 15:15:50 -07:00
$text .= " \n " ;
$text .= '<optgroup label=\'' . UC_LAN_INVERTLABEL . '\'>' ;
$text .= " \n " ;
2012-12-18 21:21:05 +00:00
}
2009-08-19 21:33:20 +00:00
foreach ( $show_classes as $k => $v )
{
2009-12-07 20:43:37 +00:00
if ( $k != e_UC_PUBLIC && $k != e_UC_NOBODY && $k != e_UC_READONLY ) // remove everyone, nobody and readonly from list.
2009-08-19 21:33:20 +00:00
{
2009-12-07 20:43:37 +00:00
$s = ( $curval == ( '-' . $k ) && $curval !== '' ) ? " selected='selected' " : '' ;
2017-11-07 06:59:11 -08:00
$text .= " <option class='uc-select-inverted' value='- " . $k . " ' " . $s . " > " . str_replace ( " [x] " , $v , UC_LAN_INVERT ) . " </option> \n " ;
2009-08-19 21:33:20 +00:00
}
}
$text .= " </optgroup> \n " ;
2008-04-05 16:30:18 +00:00
}
2007-12-22 12:39:27 +00:00
2009-08-19 21:33:20 +00:00
// Only return the select box if we've ended up with some options
2015-06-02 14:25:39 -07:00
if ( $text ) $text = " \n <select class=' " . $class . " ' name=' { $fieldname } ' id=' { $fieldname } ' { $extra_js } > \n " . $text . " </select> \n " ;
2009-12-07 20:43:37 +00:00
return $text ;
2006-12-02 04:36:16 +00:00
}
2007-12-22 12:39:27 +00:00
2010-03-11 11:56:23 +00:00
/**
2010-01-11 21:09:52 +00:00
* Generate an ordered array classid => classname - used for dropdown and check box lists
*
2009-12-07 20:43:37 +00:00
* @ param string $optlist - comma - separated list of classes / class types to include ( see uc_dropdown for details )
* @ param boolean $just_ids - if TRUE , each returned array value is '1' ; otherwise it is the class name
* @ return array of user classes ; ky is numeric class id , value is '1' or class name according to $just_ids
*/
2009-08-19 21:33:20 +00:00
public function uc_required_class_list ( $optlist = '' , $just_ids = FALSE )
2006-12-02 04:36:16 +00:00
{
2009-12-07 20:43:37 +00:00
$ret = array ();
2012-12-18 21:21:05 +00:00
$opt_arr = array ();
if ( $optlist )
{
2016-01-04 02:30:59 +02:00
$opt_arr = array_map ( 'trim' , explode ( ',' , $optlist ));
2012-12-18 21:21:05 +00:00
}
2016-01-04 02:30:59 +02:00
2012-12-18 21:21:05 +00:00
$opt_arr = array_flip ( $opt_arr ); // This also eliminates duplicates which could arise from applying the other options, although shouldn't matter
2009-12-07 20:43:37 +00:00
2012-12-18 21:21:05 +00:00
if ( isset ( $opt_arr [ 'no-excludes' ])) unset ( $opt_arr [ 'no-excludes' ]);
if ( isset ( $opt_arr [ 'is-checkbox' ])) unset ( $opt_arr [ 'is-checkbox' ]);
if ( count ( $opt_arr ) == 0 )
{
2016-04-25 19:06:37 -07:00
$opt_arr = array ( 'public' => 1 , 'guest' => 1 , 'nobody' => 1 , 'member' => 1 , 'classes' => 1 );
2012-12-18 21:21:05 +00:00
}
if ( isset ( $opt_arr [ 'all' ]))
{
unset ( $opt_arr [ 'all' ]);
$opt_arr [ 'force' ] = 1 ;
}
if ( isset ( $opt_arr [ 'editable' ]))
2009-12-07 20:43:37 +00:00
{
$temp = array_flip ( explode ( ',' , $this -> get_editable_classes ()));
if ( $just_ids ) return $temp ;
foreach ( $temp as $c => $t )
2006-12-02 04:36:16 +00:00
{
2009-12-07 20:43:37 +00:00
$temp [ $c ] = $this -> class_tree [ $c ][ 'userclass_name' ];
2006-12-02 04:36:16 +00:00
}
2009-12-07 20:43:37 +00:00
return $temp ;
2006-12-02 04:36:16 +00:00
}
2007-12-22 12:39:27 +00:00
2009-12-07 20:43:37 +00:00
if ( isset ( $opt_arr [ 'force' ])) unset ( $opt_arr [ 'filter' ]);
if ( isset ( $opt_arr [ 'blank' ]))
{
$ret [ e_UC_BLANK ] = 1 ;
}
// Do the 'fixed' classes next
foreach ( $this -> text_class_link as $k => $v )
{
// if (isset($opt_arr[$k]) || isset($opt_arr['force']))
if ( isset ( $opt_arr [ $k ]))
{
$ret [ $v ] = $just_ids ? '1' : $this -> fixed_classes [ $v ];
}
}
// Now do the user-defined classes
if ( isset ( $opt_arr [ 'classes' ]) || isset ( $opt_arr [ 'force' ]))
{ // Display those classes the user is allowed to:
// Main admin always sees the lot
// a) Mask the 'fixed' user classes which have already been processed
// b) Apply the visibility option field ('userclass_visibility')
// c) Apply the matchclass option if appropriate
foreach ( $this -> class_tree as $uc_id => $row )
{
if ( ! array_key_exists ( $uc_id , $this -> fixed_classes )
&& ( getperms ( '0' )
|| (
2016-01-04 02:30:59 +02:00
( ! isset ( $opt_arr [ 'matchclass' ]) || check_class ( $uc_id ))
&&
( ! isset ( $opt_arr [ 'filter' ]) || check_class ( $row [ 'userclass_visibility' ]))
2009-12-07 20:43:37 +00:00
)
)
)
{
2012-12-18 21:21:05 +00:00
$ret [ $uc_id ] = $just_ids ? '1' : $this -> class_tree [ $uc_id ][ 'userclass_name' ];
2009-12-07 20:43:37 +00:00
}
}
}
/* Above loop slightly changes the display order of earlier code versions .
If readonly must be last , delete it from the $text_class_link array , and uncomment the following code
if ( isset ( $opt_arr [ 'readonly' ]))
{
$ret [ e_UC_READONLY ] = $this -> class_tree [ e_UC_READONLY ][ 'userclass_description' ];
}
*/
2012-06-20 01:12:33 +00:00
2008-12-21 11:07:58 +00:00
return $ret ;
2006-12-02 04:36:16 +00:00
}
2009-01-15 15:42:24 +00:00
2009-12-07 20:43:37 +00:00
/**
2015-02-15 02:37:36 -08:00
* Very similar to self :: uc_dropdown , but returns a list of check boxes . Doesn ' t encapsulate it .
2010-01-11 21:09:52 +00:00
*
2015-02-15 02:37:36 -08:00
* @ param string $fieldname is the name for the array of checkboxes
* @ param string $curval is a comma separated list of class IDs for boxes which are checked .
* @ param string $optlist as for uc_dropdown
* @ param boolean $showdescription - if TRUE , appends the class description in brackets
* @ param boolean $asArray - if TRUE , result returned as array ; otherwise result returned as string
2010-01-11 21:09:52 +00:00
*
2015-02-15 02:37:36 -08:00
* return string | array according to $asArray
* @ return array | string
2009-12-07 20:43:37 +00:00
*/
public function uc_checkboxes ( $fieldname , $curval = '' , $optlist = '' , $showdescription = FALSE , $asArray = FALSE )
2007-12-22 12:39:27 +00:00
{
2009-08-19 21:33:20 +00:00
$show_classes = $this -> uc_required_class_list ( $optlist );
2014-01-06 01:03:58 -08:00
$frm = e107 :: getForm ();
2007-12-22 12:39:27 +00:00
2009-12-07 20:43:37 +00:00
$curArray = explode ( ',' , $curval ); // Array of current values
$ret = array ();
2006-12-02 04:36:16 +00:00
2009-08-19 21:33:20 +00:00
foreach ( $show_classes as $k => $v )
2008-04-05 16:30:18 +00:00
{
2009-08-19 21:33:20 +00:00
if ( $k != e_UC_BLANK )
{
2014-01-06 01:03:58 -08:00
// $c = (in_array($k,$curArray)) ? " checked='checked'" : '';
$c = ( in_array ( $k , $curArray )) ? true : false ;
2009-12-07 20:43:37 +00:00
if ( $showdescription ) $v .= ' (' . $this -> uc_get_classdescription ( $k ) . ')' ;
2014-01-06 01:03:58 -08:00
//$ret[] = "<div class='field-spacer'><input type='checkbox' class='checkbox' name='{$fieldname}[{$k}]' id='{$fieldname}-{$k}' value='{$k}'{$c} /><label for='{$fieldname}-{$k}'>".$v."</label></div>\n";
2015-03-01 12:43:02 -08:00
$name = $fieldname . '[' . $k . ']' ;
$ret [] = $frm -> checkbox ( $name , $k , $c , $v );
2014-01-06 01:03:58 -08:00
//$ret[] = "<div class='field-spacer'><input type='checkbox' class='checkbox' name='{$fieldname}[{$k}]' id='{$fieldname}-{$k}' value='{$k}'{$c} /><label for='{$fieldname}-{$k}'>".$v."</label></div>\n";
2009-08-19 21:33:20 +00:00
}
2008-04-05 16:30:18 +00:00
}
2009-12-07 20:43:37 +00:00
if ( $asArray ) return $ret ;
return implode ( '' , $ret );
2006-12-02 04:36:16 +00:00
}
2009-12-07 20:43:37 +00:00
/**
2010-01-11 21:09:52 +00:00
* Used by @ see { vetted_tree ()} to generate lower levels of tree
2012-12-18 21:21:05 +00:00
*
* @ param string $listnum - class number of the parent . Is negative if the class is 'Everyone except...' ( Must be a string because 0 == - 0 )
* @ param integer $nest_level - indicates our level in the tree - 0 is the top level ; increases as we descend the tree . Positive value .
* @ param string $current_value - comma - separated list of integers indicating classes selected . ( Spaces not permitted )
* @ param array $perms - list of classes we are allowed to display
* @ param string $opt_options - passed to callback function ; not otherwise used
2009-12-07 20:43:37 +00:00
*/
2012-12-18 21:21:05 +00:00
protected function vetted_sub_tree ( $treename , $callback , $listnum , $nest_level , $current_value , $perms , $opt_options )
2006-12-03 02:10:58 +00:00
{
2008-12-21 11:07:58 +00:00
$ret = '' ;
$nest_level ++ ;
2012-12-18 21:21:05 +00:00
$listIndex = abs ( $listnum );
$classSign = ( substr ( $listnum , 0 , 1 ) == '-' ) ? '-' : '+' ;
//echo "Subtree: {$listnum}, {$nest_level}, {$current_value}, {$classSign}:{$listIndex}<br />";
if ( isset ( $this -> class_tree [ $listIndex ][ 'class_children' ]))
2008-12-21 11:07:58 +00:00
{
2012-12-18 21:21:05 +00:00
foreach ( $this -> class_tree [ $listIndex ][ 'class_children' ] as $p )
2008-12-21 11:07:58 +00:00
{
2012-12-18 21:21:05 +00:00
$classValue = $classSign . $p ;
2009-07-08 06:58:00 +00:00
// Looks like we don't need to differentiate between function and class calls
if ( isset ( $perms [ $p ]))
{
2012-12-18 21:21:05 +00:00
$ret .= call_user_func ( $callback , $treename , $classValue , $current_value , $nest_level , $opt_options );
2009-07-08 06:58:00 +00:00
}
2012-12-18 21:21:05 +00:00
$ret .= $this -> vetted_sub_tree ( $treename , $callback , $classValue , $nest_level , $current_value , $perms , $opt_options );
2012-06-20 01:12:33 +00:00
}
2008-12-21 11:07:58 +00:00
}
return $ret ;
2006-12-03 02:10:58 +00:00
}
2007-12-22 12:39:27 +00:00
2009-12-07 20:43:37 +00:00
/**
* create an indented tree - for example within a select box or a list of check boxes .
* For each displayed element , the callback routine is called
* @ param string $treename is the name given to the elements where required
* @ param function | object $callback is a routine used to generate each element ; there are three implemented within this class :
* select ( the default ) - generates the option list . Text requires to be encapsulated in a < select ......./ select > tag set
* - can also be used with multi - select boxes
* checkbox - generates a set of checkboxes
* checkbox_desc - generates a set of checkboxes with the class description in brackets
* Alternative callbacks can be used to achieve different layouts / styles
* @ param integer | string $current_value - single class number for single - select dropdown ; comma separated array of class numbers for checkbox list or multi - select
* @ param string $optlist works the same as for @ see uc_dropdown ()
2012-12-18 21:21:05 +00:00
* @ param string $opt_options - passed to callback function ; not otherwise used
2009-12-07 20:43:37 +00:00
* @ return string - formatted HTML for tree
*/
2012-12-18 21:21:05 +00:00
public function vetted_tree ( $treename , $callback = '' , $current_value = '' , $optlist = '' , $opt_options = '' )
2008-04-05 16:30:18 +00:00
{
2008-12-21 11:07:58 +00:00
$ret = '' ;
if ( ! $callback ) $callback = array ( $this , 'select' );
$current_value = str_replace ( ' ' , '' , $current_value ); // Simplifies parameter passing for the tidy-minded
2012-12-30 22:42:17 +00:00
$notCheckbox = ( strpos ( $optlist , 'is-checkbox' ) === FALSE );
2008-12-21 11:07:58 +00:00
$perms = $this -> uc_required_class_list ( $optlist , TRUE ); // List of classes which we can display
if ( isset ( $perms [ e_UC_BLANK ]))
{
2012-12-18 21:21:05 +00:00
$ret .= call_user_func ( $callback , $treename , e_UC_BLANK , $current_value , 0 , $opt_options );
2008-12-21 11:07:58 +00:00
}
foreach ( $this -> class_parents as $p )
{
if ( isset ( $perms [ $p ]))
{
2012-12-18 21:21:05 +00:00
$ret .= call_user_func ( $callback , $treename , $p , $current_value , 0 , $opt_options );
2008-12-21 11:07:58 +00:00
}
2012-12-18 21:21:05 +00:00
$ret .= $this -> vetted_sub_tree ( $treename , $callback , $p , 0 , $current_value , $perms , $opt_options );
2008-12-21 11:07:58 +00:00
}
2012-12-18 21:21:05 +00:00
2012-12-18 21:29:53 +00:00
2012-06-20 01:12:33 +00:00
// Inverted classes. (negative values for exclusion).
2012-12-18 21:29:53 +00:00
if ( strpos ( $optlist , 'no-excludes' ) === FALSE )
2012-12-18 21:21:05 +00:00
{
2012-12-30 22:42:17 +00:00
if ( $notCheckbox )
2012-12-18 21:21:05 +00:00
{
2018-09-04 15:15:50 -07:00
$ret .= " \n " ;
$ret .= '<optgroup label=\'' . UC_LAN_INVERTLABEL . '\'>' ;
$ret .= " \n " ;
2012-12-18 21:21:05 +00:00
}
else
{
2012-12-30 22:42:17 +00:00
$ret .= " \n " . UC_LAN_INVERTLABEL . " <br /> \n " ;
2012-12-18 21:21:05 +00:00
}
foreach ( $this -> class_parents as $k => $p ) // Currently key and data are the same
{
//echo "Class parent: {$k}:{$p}<br />";
if ( $k != e_UC_PUBLIC && $k != e_UC_NOBODY && $k != e_UC_READONLY ) // remove everyone, nobody and readonly from list.
{
if ( isset ( $perms [ $p ]))
{
$ret .= call_user_func ( $callback , $treename , '-' . $p , $current_value , 0 , $opt_options );
}
}
$ret .= $this -> vetted_sub_tree ( $treename , $callback , '-' . $p , 0 , $current_value , $perms , $opt_options );
}
2012-12-30 22:42:17 +00:00
if ( $notCheckbox )
{
$ret .= " </optgroup> \n " ;
}
2012-12-18 21:21:05 +00:00
}
2008-12-21 11:07:58 +00:00
return $ret ;
2006-12-02 04:36:16 +00:00
}
2007-12-22 12:39:27 +00:00
2009-12-07 20:43:37 +00:00
/**
* Callback for vetted_tree - Creates the option list for a selection box
* It is the caller ' s responsibility to enclose this list in a < select ...../ select > structure
* Can be used as a basis for similar functions
*
* @ param string $treename - name of tree elements ( not used with select ; used with checkboxes , for example )
2012-12-18 21:21:05 +00:00
* @ param string $classnum - user class being displayed . This may be negative to indicate 'everyone but...'
* - special numeric part e_UC_BLANK adds a blank option in the list .
2009-12-07 20:43:37 +00:00
* @ param integer | string $current_value - single class number for single - select dropdown ; comma separated array of class numbers for checkbox list or multi - select
* @ param integer $nest_level - 'depth' of this item in the tree . Zero is base level . May be used to indent or highlight dependent on level
2012-12-18 21:21:05 +00:00
* @ param string $opt_options - passed to callback function ; not otherwise used
*
2009-12-07 20:43:37 +00:00
* @ return string - option list
*/
2012-12-18 21:21:05 +00:00
public function select ( $treename , $classnum , $current_value , $nest_level , $opt_options = '' )
2007-12-22 12:39:27 +00:00
{
2012-12-18 21:21:05 +00:00
$classIndex = abs ( $classnum ); // Handle negative class values
$classSign = ( substr ( $classnum , 0 , 1 ) == '-' ) ? '-' : '' ;
if ( $classIndex == e_UC_BLANK ) return " <option value=''> </option> \n " ;
2009-08-19 21:33:20 +00:00
$tmp = explode ( ',' , $current_value );
2012-12-18 21:21:05 +00:00
$sel = in_array ( $classnum , $tmp ) ? " selected='selected' " : '' ;
2009-08-19 21:33:20 +00:00
if ( $nest_level == 0 )
{
$prefix = '' ;
$style = " style='font-weight:bold; font-style: italic;' " ;
}
elseif ( $nest_level == 1 )
{
$prefix = ' ' ;
$style = " style='font-weight:bold' " ;
}
else
{
$prefix = ' ' . str_repeat ( '--' , $nest_level - 1 ) . '>' ;
$style = '' ;
}
2013-02-05 21:46:18 +00:00
$ucString = $this -> class_tree [ $classIndex ][ 'userclass_name' ];
if ( $classSign == '-' )
{
2017-11-07 06:59:11 -08:00
$ucString = str_replace ( '[x]' , $ucString , UC_LAN_INVERT );
2013-02-05 21:46:18 +00:00
}
return " <option value=' { $classSign } { $classIndex } ' { $sel } { $style } > " . $prefix . $ucString . " </option> \n " ;
2007-12-22 12:39:27 +00:00
}
2006-12-02 04:36:16 +00:00
2009-12-07 20:43:37 +00:00
/**
* Callback for vetted_tree - displays indented checkboxes with class name only
* See @ link select for parameter details
*/
2012-12-18 21:21:05 +00:00
public function checkbox ( $treename , $classnum , $current_value , $nest_level , $opt_options = '' )
2006-12-02 04:36:16 +00:00
{
2013-04-16 18:03:34 -07:00
$frm = e107 :: getForm ();
$classIndex = abs ( $classnum ); // Handle negative class values
$classSign = ( substr ( $classnum , 0 , 1 ) == '-' ) ? '-' : '' ;
2012-12-18 21:21:05 +00:00
if ( $classIndex == e_UC_BLANK ) return '' ;
2013-04-16 18:03:34 -07:00
$tmp = explode ( ',' , $current_value );
$chk = in_array ( $classnum , $tmp ) ? " checked='checked' " : '' ;
$style = " " ;
2009-08-19 21:33:20 +00:00
if ( $nest_level == 0 )
{
$style = " style='font-weight:bold' " ;
}
2013-04-16 18:03:34 -07:00
elseif ( $nest_level > 1 )
2009-08-19 21:33:20 +00:00
{
2013-04-16 18:03:34 -07:00
$style = " style='text-indent: " . ( 1.2 * $nest_level ) . " em' " ;
2009-08-19 21:33:20 +00:00
}
2013-04-16 18:03:34 -07:00
2013-02-05 21:46:18 +00:00
$ucString = $this -> class_tree [ $classIndex ][ 'userclass_name' ];
2013-04-16 18:03:34 -07:00
2013-02-05 21:46:18 +00:00
if ( $classSign == '-' )
{
2017-11-07 06:59:11 -08:00
$ucString = str_replace ( '[x]' , $ucString , UC_LAN_INVERT );
2013-02-05 21:46:18 +00:00
}
2013-04-16 18:03:34 -07:00
$checked = in_array ( $classnum , $tmp ) ? true : false ;
return " <div { $style } > " . $frm -> checkbox ( $treename . '[]' , $classSign . $classIndex , $checked , array ( 'label' => $ucString )) . " </div> \n " ;
2013-02-05 21:46:18 +00:00
return " <div { $style } ><input type='checkbox' class='checkbox' name=' { $treename } []' id=' { $treename } _ { $classSign } { $classIndex } ' value=' { $classSign } { $classIndex } ' { $chk } /> " . $ucString . " </div> \n " ;
2007-12-22 12:39:27 +00:00
}
2006-12-02 04:36:16 +00:00
2009-12-07 20:43:37 +00:00
/**
* Callback for vetted_tree - displays indented checkboxes with class name , and description in brackets
* See @ link select for parameter details
*/
2012-12-18 21:21:05 +00:00
public function checkbox_desc ( $treename , $classnum , $current_value , $nest_level , $opt_options = '' )
2006-12-02 04:36:16 +00:00
{
2012-12-18 21:21:05 +00:00
$classIndex = abs ( $classnum ); // Handle negative class values
$classSign = ( substr ( $classnum , 0 , 1 ) == '-' ) ? '-' : '' ;
2013-05-07 20:30:20 -07:00
2012-12-18 21:21:05 +00:00
if ( $classIndex == e_UC_BLANK ) return '' ;
2013-05-07 20:30:20 -07:00
2009-08-19 21:33:20 +00:00
$tmp = explode ( ',' , $current_value );
$chk = in_array ( $classnum , $tmp ) ? " checked='checked' " : '' ;
2013-05-07 20:30:20 -07:00
2009-08-19 21:33:20 +00:00
if ( $nest_level == 0 )
{
$style = " style='font-weight:bold' " ;
}
else
{
2013-05-07 20:30:20 -07:00
$style = " style='text-indent: " . ( 0.3 * $nest_level ) . " em' " ;
2009-08-19 21:33:20 +00:00
}
2012-12-12 18:46:34 -08:00
$id = " { $treename } _ { $classnum } " ;
2013-02-05 21:46:18 +00:00
$ucString = $this -> class_tree [ $classIndex ][ 'userclass_name' ];
2013-05-07 20:30:20 -07:00
2013-02-05 21:46:18 +00:00
if ( $classSign == '-' )
{
2017-11-07 06:59:11 -08:00
$ucString = str_replace ( '[x]' , $ucString , UC_LAN_INVERT );
2013-02-05 21:46:18 +00:00
}
2013-05-07 20:30:20 -07:00
$description = $ucString . ' (' . $this -> class_tree [ $classIndex ][ 'userclass_description' ] . " ) " ;
$id = " { $treename } _ { $classSign } { $classnum } " ;
return " <div class='checkbox' { $style } > " . e107 :: getForm () -> checkbox ( $treename . '[]' , $classnum , $chk , array ( " id " => $id , 'label' => $description )) . " </div> \n " ;
2012-12-12 18:46:34 -08:00
2013-05-07 20:30:20 -07:00
// return "<div {$style}><input type='checkbox' class='checkbox' name='{$treename}[]' id='{$treename}_{$classSign}{$classnum}' value='{$classSign}{$classnum}'{$chk} />".$this->class_tree[$classIndex]['userclass_name'].' ('.$this->class_tree[$classIndex]['userclass_description'].")</div>\n";
2007-12-22 12:39:27 +00:00
}
2006-12-02 04:36:16 +00:00
2007-12-22 12:39:27 +00:00
2009-01-15 15:42:24 +00:00
2009-12-07 20:43:37 +00:00
/**
* Return array of all classes , limited according to membership of the userclass_visibility field if $filter is set .
* @ param string | integer $filter - user class or class list in format acceptable to check_class ()
* @ return array of class elements , each itself an array :
* Index field - userclass_id
* Data fields - userclass_name , userclass_description , userclass_editclass
*/
2009-08-19 21:33:20 +00:00
public function uc_get_classlist ( $filter = FALSE )
2006-12-02 04:36:16 +00:00
{
2009-08-19 21:33:20 +00:00
$ret = array ();
$this -> readTree ( FALSE ); // Make sure we have data
foreach ( $this -> class_tree as $k => $v )
2006-12-02 04:36:16 +00:00
{
2009-08-19 21:33:20 +00:00
if ( ! $filter || check_class ( $filter ))
{
$ret [ $k ] = array ( 'userclass_name' => $v , 'userclass_description' => $v [ 'userclass_description' ], 'userclass_editclass' => $v [ 'userclass_editclass' ]);
}
2006-12-02 04:36:16 +00:00
}
2009-08-19 21:33:20 +00:00
return $ret ;
2007-12-22 12:39:27 +00:00
}
2009-01-15 15:42:24 +00:00
2009-12-07 20:43:37 +00:00
/**
* Return class name for given class ID
* Handles 'not a member of...' construct by replacing '--CLASS--' in UC_LAN_INVERT with the class name
* @ param integer $id - class number . A negative number indicates 'not a member of...'
* @ return string class name
*/
2015-05-12 13:53:47 -07:00
public function getName ( $id )
2007-12-22 12:39:27 +00:00
{
2020-11-27 17:00:32 +01:00
$id = ( int ) $id ;
2013-02-03 18:29:11 +00:00
$cn = abs ( $id );
2013-02-05 21:46:18 +00:00
$ucString = 'Class:' . $id ; // Debugging aid - this should be overridden
2013-02-03 18:29:11 +00:00
if ( isset ( $this -> class_tree [ $cn ]))
2009-08-19 21:33:20 +00:00
{
2013-02-03 18:29:11 +00:00
$ucString = $this -> class_tree [ $cn ][ 'userclass_name' ];
2009-08-19 21:33:20 +00:00
}
2013-02-03 18:29:11 +00:00
elseif ( isset ( $this -> fixed_classes [ $cn ]))
2009-08-19 21:33:20 +00:00
{
2013-02-03 18:29:11 +00:00
$ucString = $this -> fixed_classes [ $cn ];
2009-08-19 21:33:20 +00:00
}
2009-08-04 15:04:18 +00:00
2009-08-19 21:33:20 +00:00
if ( $id < 0 )
{
2013-02-03 18:29:11 +00:00
//$val = abs($id);
//$name = isset($this->class_tree[$val]['userclass_name']) ? $this->class_tree[$val]['userclass_name'] : $this->fixed_classes[$val];
2017-11-07 06:59:11 -08:00
$ucString = str_replace ( '[x]' , $ucString , UC_LAN_INVERT );
2009-08-19 21:33:20 +00:00
}
2013-02-03 18:29:11 +00:00
return $ucString ;
2007-12-22 12:39:27 +00:00
}
2009-01-15 15:42:24 +00:00
2009-12-07 20:43:37 +00:00
2016-08-30 14:22:47 -07:00
/**
* Return a key - name identifier for given class ID
* @ param integer $id - class number . A negative number indicates 'not a member of...'
* @ return string class name ke
*/
public function getIdentifier ( $id )
{
$cn = abs ( $id );
$ucString = '' ;
$fixedClasses = array_flip ( $this -> text_class_link );
if ( isset ( $fixedClasses [ $cn ]))
{
return $fixedClasses [ $cn ];
}
if ( isset ( $this -> class_tree [ $cn ]))
{
return e107 :: getForm () -> name2id ( $this -> class_tree [ $cn ][ 'userclass_name' ]);
}
return $ucString ;
}
2015-05-12 13:53:47 -07:00
2009-12-07 20:43:37 +00:00
/**
* Return class description for given class ID
* @ param integer $id - class number . Must be >= 0
* @ return string class description
*/
2015-05-12 13:53:47 -07:00
public function getDescription ( $id )
2007-12-22 12:39:27 +00:00
{
2015-05-12 13:53:47 -07:00
$id = intval ( $id );
if ( isset ( $this -> class_tree [ $id ]))
2009-08-19 21:33:20 +00:00
{
return $this -> class_tree [ $id ][ 'userclass_description' ];
}
if ( isset ( $this -> fixed_classes [ $id ]))
{
return $this -> fixed_classes [ $id ]; // Name and description the same for fixed classes
}
return '' ;
2006-12-02 04:36:16 +00:00
}
2009-08-19 21:33:20 +00:00
2009-12-07 20:43:37 +00:00
2015-05-12 13:53:47 -07:00
/**
* BC Alias . of getName ();
* @ deprecated
* @ param $id
* @ return string
*/
public function uc_get_classname ( $id )
{
return $this -> getName ( $id );
}
/**
* BC Alias of getDescription
* @ deprecated
* @ param $id
* @ return mixed
*/
public function uc_get_classdescription ( $id )
{
return $this -> getDescription ( $id );
}
2009-12-07 20:43:37 +00:00
/**
* Return class icon for given class ID
* @ param integer $id - class number . Must be >= 0
* @ return string class icon if defined , otherwise empty string
*/
2009-08-19 21:33:20 +00:00
public function uc_get_classicon ( $id )
2007-12-22 12:39:27 +00:00
{
2009-08-19 21:33:20 +00:00
if ( isset ( $this -> class_tree [ $id ]))
{
return $this -> class_tree [ $id ][ 'userclass_icon' ];
}
return '' ;
2006-12-02 04:36:16 +00:00
}
2009-01-15 15:42:24 +00:00
2009-08-19 21:33:20 +00:00
2009-12-07 20:43:37 +00:00
2015-06-11 13:10:04 -07:00
2009-12-07 20:43:37 +00:00
/**
* Look up class ID for a given class name
* @ param string $name - class name
* @ return integer | boolean FALSE if not found , else user class ID
*/
2015-06-11 13:10:04 -07:00
public function getID ( $name )
2008-11-29 21:16:54 +00:00
{
$this -> readTree ();
// We have all the info - can just search the array
foreach ( $this -> class_tree as $uc => $info )
{
if ( $info [ 'userclass_name' ] == $name )
{
return $uc ;
}
}
return FALSE ; // not found
}
2009-01-15 15:42:24 +00:00
2008-12-21 11:07:58 +00:00
2009-12-07 20:43:37 +00:00
2015-06-11 13:10:04 -07:00
/**
* BC Alias of getID ();
* @ param $name
* @ return mixed
*/
public function ucGetClassIDFromName ( $name )
{
2019-02-22 14:56:47 -08:00
return $this -> getID ( $name );
2015-06-11 13:10:04 -07:00
}
2009-12-07 20:43:37 +00:00
/**
* Utility to remove a specified class ID from the default comma - separated list
* Optional conversion to array of classes
* @ param integer $classID - class number . Must be >= 0
* @ param string $from - comma separated list of class numbers
* @ param boolean $asArray - if TRUE , result returned as array ; otherwise result returned as string
* @ return string class description
*/
2009-08-19 21:33:20 +00:00
public function ucRemove ( $classID , $from , $asArray = FALSE )
2008-12-21 11:07:58 +00:00
{
$tmp = array_flip ( explode ( ',' , $from ));
if ( isset ( $tmp [ $classID ]))
{
unset ( $tmp [ $classID ]);
}
$tmp = array_keys ( $tmp );
if ( $asArray ) { return $tmp ; }
2008-12-29 22:30:16 +00:00
if ( count ( $tmp ) == 0 ) { return '' ; }
2008-12-21 11:07:58 +00:00
return implode ( ',' , $tmp );
}
2009-01-15 15:42:24 +00:00
2009-12-07 20:43:37 +00:00
/**
* Utility to add a specified class ID to the default comma - separated list
* Optional conversion to array of classes
* @ param integer $classID - class number . Must be >= 0
* @ param string $to - comma separated list of class numbers
* @ param boolean $asArray - if TRUE , result returned as array ; otherwise result returned as string
* @ return string class description
*/
2009-08-19 21:33:20 +00:00
public function ucAdd ( $classID , $to , $asArray = FALSE )
2008-12-29 09:31:36 +00:00
{
$tmp = array_flip ( explode ( ',' , $to ));
$tmp [ $classID ] = 1 ;
$tmp = array_keys ( $tmp );
if ( $asArray ) { return $tmp ; }
return implode ( ',' , $tmp );
}
2009-01-15 15:42:24 +00:00
2009-12-07 20:43:37 +00:00
/**
* See if a class can be edited ( in the sense of the class ID not being fixed )
* @ param integer $classID - class number . Must be >= 0
* @ return boolean - TRUE if class can be edited
*/
2009-08-19 21:33:20 +00:00
public function isEditableClass ( $classID )
{
if (( $classID >= e_UC_SPECIAL_BASE ) && ( $classID <= e_UC_SPECIAL_END )) return FALSE ; // Don't allow deletion of fixed classes
2012-12-18 22:43:10 +00:00
if ( isset ( $this -> fixed_classes [ $classID ])) return FALSE ; // This picks up classes such as e_UC_PUBLIC outside the main range which can't be deleted
2009-08-19 21:33:20 +00:00
return TRUE ;
}
2019-04-18 10:24:30 -07:00
/**
* @ deprecated Alias of getUsersInClass ()
* @ param $classes
* @ param string $fieldList
* @ param bool $includeAncestors
* @ param string $orderBy
* @ return array
*/
public function get_users_in_class ( $classes , $fieldList = 'user_name, user_loginname' , $includeAncestors = FALSE , $orderBy = 'user_id' )
{
return $this -> getUsersInClass ( $classes , $fieldList , $includeAncestors , $orderBy );
}
2009-12-07 20:43:37 +00:00
/**
* Return all users in a particular class or set of classes .
*
2019-04-18 10:24:30 -07:00
* Could potentially be verrrrryyyy slow - has to scan the whole user database at present .
* @ param string $$classes - comma separated list of classes
2020-01-23 14:59:01 -08:00
* @ param string $fields - comma separated list of fields to be returned . `user_id` is always returned as the key of the array entry , prefix with 'ue.' to retrieve extended user fields .
2009-12-07 20:43:37 +00:00
* @ param boolean $includeAncestors - if TRUE , also looks for classes in the hierarchy ; otherwise checks exactly the classes passed
* @ param string $orderBy - optional field name to define the order of entries in the results array
* @ return array indexed by user_id , each element is an array ( database row ) containing the requested fields
*/
2019-04-18 10:24:30 -07:00
public function getUsersInClass ( $classes , $fields = 'user_name, user_loginname' , $includeAncestors = false , $orderBy = 'user_id' )
2006-12-03 02:10:58 +00:00
{
2019-04-18 10:24:30 -07:00
$classes = str_replace ( ' ' , '' , $classes ); // clean up white spaces
$classList = explode ( " , " , $classes );
if ( empty ( $classList ))
{
return array ();
}
if ( $includeAncestors === true )
{
2019-05-28 11:26:32 -07:00
$classList = $this -> get_all_user_classes ( $classes , true );
2019-04-18 10:24:30 -07:00
}
$classList = array_flip ( $classList );
$qry = array ();
if ( isset ( $classList [ e_UC_MEMBER ]))
{
$qry [] = " user_ban = 0 " ;
unset ( $classList [ e_UC_MEMBER ]);
}
if ( isset ( $classList [ e_UC_ADMIN ]))
{
$qry [] = " user_admin = 1 " ;
unset ( $classList [ e_UC_ADMIN ]);
}
if ( isset ( $classList [ e_UC_MAINADMIN ]))
{
$qry [] = " user_perms = '0' OR user_perms = '0.' " ;
unset ( $classList [ e_UC_MAINADMIN ]);
}
if ( ! empty ( $classList ))
{
$class_regex = implode ( '|' , array_flip ( $classList ));
$regex = " (^|,)( " . e107 :: getParser () -> toDB ( $class_regex ) . " )(,| $ ) " ;
2019-05-01 17:08:33 -07:00
$qry [] = " user_class REGEXP ' { $regex } ' " ;
2019-04-18 10:24:30 -07:00
}
if ( empty ( $qry ))
{
return array ();
}
$sql = e107 :: getDb ( 'sql_r' );
2009-08-19 21:33:20 +00:00
$ret = array ();
2019-04-18 10:24:30 -07:00
2020-01-23 14:59:01 -08:00
$lj = strpos ( $fields , 'ue.' ) !== false ? " LEFT JOIN `#user_extended` AS ue ON user_id = ue.user_extended_id " : " " ;
$query = " SELECT user_id, { $fields } FROM `#user` " . $lj . " WHERE " . implode ( " OR " , $qry ) . " ORDER BY " . $orderBy ;
2019-04-18 10:24:30 -07:00
if ( $sql -> gen ( $query ))
2007-12-22 12:39:27 +00:00
{
2019-04-18 10:24:30 -07:00
while ( $row = $sql -> fetch ())
2009-08-19 21:33:20 +00:00
{
2020-01-22 12:04:59 -08:00
$row [ 'user_id' ] = ( int ) $row [ 'user_id' ];
2009-08-19 21:33:20 +00:00
$ret [ $row [ 'user_id' ]] = $row ;
}
2020-01-23 14:59:01 -08:00
2007-12-22 12:39:27 +00:00
}
2019-04-18 10:24:30 -07:00
2009-08-19 21:33:20 +00:00
return $ret ;
2006-12-03 02:10:58 +00:00
}
2015-05-12 13:53:47 -07:00
/**
* Clear user class cache
2019-04-18 10:24:30 -07:00
* @ return void
2015-05-12 13:53:47 -07:00
*/
public function clearCache ()
{
e107 :: getCache () -> clear_sys ( UC_CACHE_TAG );
}
2006-12-02 04:36:16 +00:00
}
2007-12-22 12:39:27 +00:00
2013-01-01 10:39:30 +00:00
/**========================================================================
* Functions from previous userclass_class handler
* ========================================================================
* Implemented for backwards compatibility / convenience .
2007-12-22 12:39:27 +00:00
2013-01-01 10:39:30 +00:00
* ************** DEPRECATED - use new class - based functions **************
*
* Functionality should be sufficiently similar to the original functions to not notice ( and will
* be more consistent with the preferred class - based functions ) .
*
* Refer to the corresponding class - based functions for full details
*
* Consistent interface :
*
* @ param string $fieldname - name to use for the element
* @ param mixed $curval - current value of field - as CSV if multiple values
* @ param string $mode = ( off | admin ... ) - affects display -
* @ param string $optlist - comma - separated list which specifies the classes to be shown :
* public
* guest
* nobody
* member
* readonly
* admin
* main - main admin
* classes - shows all classes
* matchclass - if 'classes' is set , this option will only show the classes that the user is a member of
*
* filter - only show those classes where member is in a class permitted to view them - i . e . as the new 'visible to' field
* force - show all classes ( subject to the other options , including matchclass )
*
* $mode = 'off' turns off listing of admin / main admin classes unless enabled in $optlist ( can probably be deprecated - barely used )
*
*/
2007-12-22 12:39:27 +00:00
2009-01-15 15:42:24 +00:00
function r_userclass ( $fieldname , $curval = 0 , $mode = " off " , $optlist = " " )
2007-12-22 12:39:27 +00:00
{
2013-01-01 10:39:30 +00:00
// echo "Call r_userclass{$fieldname}, CV: {$curval} opts: {$optlist}<br />";
global $e_userclass ;
if ( $mode != 'off' )
{ // Handle legacy code
if ( $optlist ) $optlist .= ',' ;
$optlist .= 'admin,main' ;
if ( $mode != 'admin' ) $optlist .= ',readonly' ;
}
if ( ! is_object ( $e_userclass )) $e_userclass = new user_class ;
return $e_userclass -> uc_dropdown ( $fieldname , $curval , $optlist );
2007-12-22 12:39:27 +00:00
}
// Very similar to r_userclass, but returns a list of check boxes. (currently only used in newspost.php)
// $curval is a comma separated list of class IDs for boxes which are checked.
function r_userclass_check ( $fieldname , $curval = '' , $optlist = " " )
{
2013-01-01 10:39:30 +00:00
// echo "Call r_userclass_check: {$curval}<br />";
global $e_userclass ;
if ( ! is_object ( $e_userclass )) $e_userclass = new user_class ;
$ret = $e_userclass -> uc_checkboxes ( $fieldname , $curval , $optlist );
if ( $ret ) $ret = " <div class='check-block'> " . $ret . " </div> " ;
return $ret ;
2007-12-22 12:39:27 +00:00
}
2006-12-02 04:36:16 +00:00
function get_userclass_list ()
{
2007-12-22 12:39:27 +00:00
// echo "Call get_userclass_list<br />";
2013-01-01 10:39:30 +00:00
global $e_userclass ;
if ( ! is_object ( $e_userclass )) $e_userclass = new user_class ;
return $e_userclass -> uc_get_classlist ();
2007-12-22 12:39:27 +00:00
}
2009-01-15 15:42:24 +00:00
function r_userclass_name ( $id )
2007-12-22 12:39:27 +00:00
{
// echo "Call r_userclass_name<br />";
2013-01-01 10:39:30 +00:00
global $e_userclass ;
if ( ! is_object ( $e_userclass )) $e_userclass = new user_class ;
return $e_userclass -> uc_get_classname ( $id );
2007-12-22 12:39:27 +00:00
}
// Deprecated functions to hopefully be removed
function r_userclass_radio ( $fieldname , $curval = '' )
{
2013-01-01 10:39:30 +00:00
echo " Deprecated function r_userclass_radio not used in core - mutter if you'd like it implemented<br /> " ;
2007-12-22 12:39:27 +00:00
}
//========================================================================
// Admin Class handler - could go into separate file later
//========================================================================
class user_class_admin extends user_class
{
2009-12-07 20:43:37 +00:00
protected $field_list = array ( 'userclass_name' => " varchar(100) NOT NULL default '' " ,
2009-01-15 15:42:24 +00:00
'userclass_description' => " varchar(250) NOT NULL default '' " ,
2008-12-29 22:30:16 +00:00
'userclass_editclass' => " tinyint(3) unsigned NOT NULL default '0' " ,
'userclass_parent' => " tinyint(3) unsigned NOT NULL default '0' " ,
2009-01-15 15:42:24 +00:00
'userclass_accum' => " varchar(250) NOT NULL default '' " ,
2008-12-29 22:30:16 +00:00
'userclass_visibility' => " tinyint(3) unsigned NOT NULL default '0' " ,
'userclass_type' => " tinyint(1) unsigned NOT NULL default '0' " ,
'userclass_icon' => " varchar(250) NOT NULL default '' "
); // Note - 'userclass_id' intentionally not in this list
2009-12-07 20:43:37 +00:00
protected $graph_debug = FALSE ; // Shows extra info on graphical tree when TRUE
2008-12-29 22:30:16 +00:00
// Icons to use for graphical tree display
// First index - no children, children
// Second index - not last item, last item
// Third index - closed tree, open tree
2009-12-07 20:43:37 +00:00
protected $tree_icons = array (
2007-12-22 12:39:27 +00:00
FALSE => array ( // No children
FALSE => array ( // Not last item
FALSE => '' , // Closed tree - don't display
TRUE => 'branch.gif'
)
,
TRUE => array ( // Last item
FALSE => '' , // Closed tree - don't display
TRUE => 'branchbottom.gif'
)
),
TRUE => array ( // children
FALSE => array ( // Not last item
FALSE => 'plus.gif' , // Closed tree - option to expand
TRUE => 'minus.gif'
)
,
TRUE => array ( // Last item
FALSE => 'plusbottom.gif' , // Closed tree - option to expand
TRUE => 'minusbottom.gif'
))
);
2009-12-07 20:43:37 +00:00
2013-04-30 01:28:44 -07:00
protected $top_icon = null ;
2009-12-07 20:43:37 +00:00
/**
* Constructor
*/
public function __construct ()
{
parent :: __construct ();
2012-12-19 22:27:48 +00:00
if ( ! ( getperms ( '4' ) || getperms ( '0' ))) return ;
$this -> isAdmin = TRUE ; // We have full class management rights
2013-04-30 01:28:44 -07:00
$pref = e107 :: getPref ();
$style = ( $pref [ 'admincss' ] == 'admin_dark.css' ) ? ' icon-white' : '' ;
$this -> top_icon = " <i class='icon-user { $style } '></i> " ;
2008-12-29 22:30:16 +00:00
}
2007-12-22 12:39:27 +00:00
2009-01-15 15:42:24 +00:00
2007-12-22 12:39:27 +00:00
2009-12-07 20:43:37 +00:00
/**
* Next three routines are used to update the database after adding / deleting a class
* calc_tree is the public interface
* @ return none
2007-12-22 12:39:27 +00:00
*/
2009-08-19 21:33:20 +00:00
public function calc_tree ()
2006-12-02 04:36:16 +00:00
{
2012-12-19 22:27:48 +00:00
$this -> readTree ( TRUE ); // Make sure we have accurate data
2008-12-29 22:30:16 +00:00
foreach ( $this -> class_parents as $cp )
{
$rights = array ();
$this -> rebuild_tree ( $cp , $rights ); // increasing rights going down the tree
}
2006-12-02 04:36:16 +00:00
}
2009-01-15 15:42:24 +00:00
2007-12-22 12:39:27 +00:00
2015-03-01 12:43:02 -08:00
2010-03-11 11:56:23 +00:00
/*
2009-12-07 20:43:37 +00:00
* Internal function , called recursively to rebuild the permissions tree where rights increase going down the tree
* If the permissions change , sets the 'change_flag' to force rewrite to DB ( by other code )
* @ param integer $parent is the class number being processed .
* @ param array $rights is the array of rights accumulated so far in the walk down the tree
*/
2009-08-19 21:33:20 +00:00
protected function rebuild_tree ( $parent , $rights )
2008-11-27 22:07:36 +00:00
{
2019-04-18 10:24:30 -07:00
if ( $this -> class_tree [ $parent ][ 'userclass_parent' ] == e_UC_NOBODY )
2008-12-29 22:30:16 +00:00
{
$this -> topdown_tree ( $parent );
2019-04-18 10:24:30 -07:00
return null ;
2008-12-29 22:30:16 +00:00
}
2019-04-18 10:24:30 -07:00
if ( $this -> class_tree [ $parent ][ 'userclass_type' ] == UC_TYPE_GROUP )
2008-12-29 22:30:16 +00:00
{
2019-04-18 10:24:30 -07:00
return null ; // Probably just stop here for a group class
2008-12-29 22:30:16 +00:00
}
2019-04-18 10:24:30 -07:00
$rights [] = $parent ;
$imp_rights = implode ( ',' , $rights );
if ( $this -> class_tree [ $parent ][ 'userclass_accum' ] != $imp_rights )
2008-12-29 22:30:16 +00:00
{
$this -> class_tree [ $parent ][ 'userclass_accum' ] = $imp_rights ;
2019-04-18 10:24:30 -07:00
if ( ! isset ( $this -> class_tree [ $parent ][ 'change_flag' ]))
{
$this -> class_tree [ $parent ][ 'change_flag' ] = 'UPDATE' ;
}
2008-12-29 22:30:16 +00:00
}
2015-04-09 11:13:26 -07:00
if ( ! empty ( $this -> class_tree [ $parent ][ 'class_children' ]))
2008-12-29 22:30:16 +00:00
{
2015-04-09 11:13:26 -07:00
foreach ( $this -> class_tree [ $parent ][ 'class_children' ] as $cc )
{
$this -> rebuild_tree ( $cc , $rights ); // Recursive call
}
2008-12-29 22:30:16 +00:00
}
2009-01-15 15:42:24 +00:00
}
2007-12-22 12:39:27 +00:00
2006-12-02 04:36:16 +00:00
2009-12-07 20:43:37 +00:00
/*
* Internal function , called recursively to rebuild the permissions tree where rights increase going up the tree
* @ param integer $our_class - ID of class being processed
* @ return array of class permissions
*/
2009-08-19 21:33:20 +00:00
protected function topdown_tree ( $our_class )
{
$rights = array ( $our_class ); // Accumulator always has rights to its own class
2008-11-27 22:07:36 +00:00
2009-08-19 21:33:20 +00:00
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
2008-11-27 22:07:36 +00:00
2009-08-19 21:33:20 +00:00
foreach ( $this -> class_tree [ $our_class ][ 'class_children' ] as $cc )
{
$rights = array_merge ( $rights , $this -> topdown_tree ( $cc )); // Recursive call
}
$rights = array_unique ( $rights );
$imp_rights = implode ( ',' , $rights );
if ( $this -> class_tree [ $our_class ][ 'userclass_accum' ] != $imp_rights )
{
$this -> class_tree [ $our_class ][ 'userclass_accum' ] = $imp_rights ;
$this -> class_tree [ $our_class ][ 'change_flag' ] = 'UPDATE' ;
}
return $rights ;
2008-03-23 10:11:17 +00:00
}
2009-12-07 20:43:37 +00:00
/**
* Called after recalculating the tree to save changed records to the database
* @ return none
*/
2009-08-19 21:33:20 +00:00
public function save_tree ()
2007-12-22 12:39:27 +00:00
{
2009-08-19 21:33:20 +00:00
foreach ( $this -> class_tree as $tree )
2006-12-02 04:36:16 +00:00
{
2009-08-19 21:33:20 +00:00
if ( isset ( $tree [ 'change_flag' ]))
{
switch ( $tree [ 'change_flag' ])
{
case 'INSERT' :
$this -> add_new_class ( $tree );
break ;
case 'UPDATE' :
$this -> save_edited_class ( $tree );
break ;
2019-02-07 17:12:23 -08:00
2009-08-19 21:33:20 +00:00
}
}
2007-12-22 12:39:27 +00:00
}
}
2009-01-15 15:42:24 +00:00
2007-12-22 12:39:27 +00:00
2009-12-07 20:43:37 +00:00
/**
* Next two routines show a text - based tree with markers to indicate the hierarchy .
* Intended primarily for debugging
*/
2009-08-19 21:33:20 +00:00
protected function show_sub_tree ( $listnum , $marker , $add_class = FALSE )
2007-12-22 12:39:27 +00:00
{
2009-08-19 21:33:20 +00:00
$ret = '' ;
$marker = '--' . $marker ;
foreach ( $this -> class_tree [ $listnum ][ 'class_children' ] as $p )
{
2009-12-07 20:43:37 +00:00
$ret .= $marker . $this -> class_tree [ $p ][ 'userclass_id' ] . ':' . $this -> class_tree [ $p ][ 'userclass_name' ];
if ( $add_class ) $ret .= " ( " . $this -> class_tree [ $p ][ 'userclass_accum' ] . " ) " ;
$ret .= " Children: " . count ( $this -> class_tree [ $p ][ 'class_children' ]);
$ret .= " <br /> " ;
$ret .= $this -> show_sub_tree ( $p , $marker , $add_class );
2009-08-19 21:33:20 +00:00
}
return $ret ;
2007-12-22 12:39:27 +00:00
}
2009-01-15 15:42:24 +00:00
2009-12-07 20:43:37 +00:00
/**
* Show a text - based sub - tree , optionally with helpful debug info
* @ param boolean $add_class - TRUE includes a list of accumulated rights in each line
* @ return string text for display
*/
2009-08-19 21:33:20 +00:00
public function show_tree ( $add_class = FALSE )
2007-12-22 12:39:27 +00:00
{
2009-08-19 21:33:20 +00:00
$ret = '' ;
foreach ( $this -> class_parents as $p )
{
$ret .= $this -> class_tree [ $p ][ 'userclass_id' ] . ':' . $this -> class_tree [ $p ][ 'userclass_name' ];
if ( $add_class ) $ret .= " ( " . $this -> class_tree [ $p ][ 'userclass_accum' ] . " ) " ;
$ret .= " Children: " . count ( $this -> class_tree [ $p ][ 'class_children' ]);
$ret .= " <br /> " ;
$ret .= $this -> show_sub_tree ( $p , '>' , $add_class );
}
return $ret ;
2007-12-22 12:39:27 +00:00
}
/*
2012-12-19 22:27:48 +00:00
* Next two routines generate a graphical tree , including option to open / close branches
*
* function show_graphical subtree () is for internal use , called from function show_graphical_tree
*
* @ param int $listnum - class number of first element to display , along with its children
* @ param array $indent_images - array of images with which to start each line
* @ param boolean $is_last - TRUE if this is the last element on the current branch of the tree
*/
2009-08-19 21:33:20 +00:00
protected function show_graphical_subtree ( $listnum , $indent_images , $is_last = FALSE )
{
2019-02-17 15:37:13 -08:00
$tree = vartrue ( $this -> class_tree [ $listnum ][ 'class_children' ], array ());
$num_children = count ( $tree );
2009-08-19 21:33:20 +00:00
$is_open = TRUE ;
$tag_name = 'uclass_tree_' . $listnum ;
2007-12-22 12:39:27 +00:00
2013-03-03 23:42:37 -08:00
$ret = " <div class='uclass_tree' > \n " ;
2009-01-15 15:42:24 +00:00
2009-08-19 21:33:20 +00:00
foreach ( $indent_images as $im )
{
$ret .= " <img src=' " . UC_ICON_DIR . $im . " ' alt='class icon' /> " ;
}
// If this link has children, wrap the next image in a link and an expand/hide option
if ( $num_children )
{
$ret .= " <span onclick= \" javascript: expandit(' { $tag_name } '); expandit(' { $tag_name } _p'); expandit(' { $tag_name } _m') \" ><img src=' " . UC_ICON_DIR . $this -> tree_icons [ TRUE ][ $is_last ][ TRUE ] . " ' alt='class icon' id=' { $tag_name } _m' /> " ;
$ret .= " <img src=' " . UC_ICON_DIR . $this -> tree_icons [ TRUE ][ $is_last ][ FALSE ] . " ' style='display:none' id=' { $tag_name } _p' alt='class icon' /></span> \n " ;
}
else
{
$ret .= " <img src=' " . UC_ICON_DIR . $this -> tree_icons [ FALSE ][ $is_last ][ $is_open ] . " ' alt='class icon' /> \n " ;
}
$name_line = '' ;
if ( $this -> graph_debug ) { $name_line = $this -> class_tree [ $listnum ][ 'userclass_id' ] . " : " ; }
// if ($this->graph_debug) { $name_line = varset($this->class_tree[$listnum]['userclass_id'], 'XXX').":"; }
if ( $this -> class_tree [ $listnum ][ 'userclass_type' ] == UC_TYPE_GROUP )
{
2017-01-09 17:07:47 +00:00
$name_line .= '<b>' . $this -> class_tree [ $listnum ][ 'userclass_name' ] . '</b> (' . UCSLAN_81 . ').' ; // Highlight groups
2009-08-19 21:33:20 +00:00
}
else
{
$name_line .= $this -> class_tree [ $listnum ][ 'userclass_name' ];
}
if ( $this -> graph_debug ) $name_line .= " [vis: " . $this -> class_tree [ $listnum ][ 'userclass_visibility' ] . " , edit: " . $this -> class_tree [ $listnum ][ 'userclass_editclass' ] . " ] = " . $this -> class_tree [ $listnum ][ 'userclass_accum' ] . " Children: " . implode ( ',' , $this -> class_tree [ $listnum ][ 'class_children' ]);
// Next (commented out) line gives a 'conventional' link
2010-02-07 19:42:07 +00:00
//$ret .= "<img src='".UC_ICON_DIR."topicon.png' alt='class icon' /><a style='text-decoration: none' class='userclass_edit' href='".e_ADMIN_ABS."userclass2.php?config.edit.{$this->class_tree[$listnum]['userclass_id']}'>".$name_line."</a></div>";
2012-12-19 22:27:48 +00:00
if ( $this -> queryCanEditClass ( $this -> class_tree [ $listnum ][ 'userclass_id' ]))
2010-03-11 11:56:23 +00:00
{
2017-02-07 07:08:58 -08:00
$url = e_SELF . '?mode=main&action=edit&id=' . $this -> class_tree [ $listnum ][ 'userclass_id' ];
2010-03-11 11:56:23 +00:00
$onc = '' ;
}
else
{
$url = '#' ;
$onc = " onclick= \" alert(' " . str_replace ( " ' " , " \\ ' " , ( stripslashes ( UCSLAN_90 ))) . " '); return false; \" " ;
}
2013-04-30 01:28:44 -07:00
$ret .= $this -> top_icon . " <a style='text-decoration: none' class='userclass_edit' { $onc } href=' { $url } '> " . $name_line . " </a></div> " ;
2009-08-19 21:33:20 +00:00
//$ret .= "<img src='".UC_ICON_DIR."topicon.png' alt='class icon' />
//<span style='cursor:pointer; vertical-align: bottom' onclick=\"javascript: document.location.href='".e_ADMIN."userclass2.php?config.edit.{$this->class_tree[$listnum]['userclass_id']}'\">".$name_line."</span></div>";
// vertical-align: middle doesn't work! Nor does text-top
2008-11-27 22:07:36 +00:00
2007-12-22 12:39:27 +00:00
if ( $num_children )
2009-08-19 21:33:20 +00:00
{
$ret .= " <div class='uclass_tree' id=' { $tag_name } '> \n " ;
$image_level = count ( $indent_images );
if ( $is_last )
{
$indent_images [] = 'linebottom.gif' ;
}
else
{
$indent_images [] = 'line.gif' ;
}
2012-12-19 22:27:48 +00:00
if ( isset ( $this -> class_tree [ $listnum ][ 'class_children' ])) foreach ( $this -> class_tree [ $listnum ][ 'class_children' ] as $p )
2009-08-19 21:33:20 +00:00
{
$num_children -- ;
if ( $num_children )
{ // Use icon indicating more below
2012-12-19 22:27:48 +00:00
$ret .= $this -> show_graphical_subtree ( $p , $indent_images , FALSE );
2009-08-19 21:33:20 +00:00
}
else
{ // else last entry on this tree
2012-12-19 22:27:48 +00:00
$ret .= $this -> show_graphical_subtree ( $p , $indent_images , TRUE );
2009-08-19 21:33:20 +00:00
}
}
$ret .= " </div> " ;
2006-12-02 04:36:16 +00:00
}
2009-08-19 21:33:20 +00:00
return $ret ;
2007-12-22 12:39:27 +00:00
}
2009-01-15 15:42:24 +00:00
2007-12-22 12:39:27 +00:00
2008-03-23 10:11:17 +00:00
2010-03-11 11:56:23 +00:00
/**
* Create graphical class tree , including clickable links to expand / contract branches .
2012-12-19 22:27:48 +00:00
*
2010-03-11 11:56:23 +00:00
* @ param boolean $show_debug - TRUE to display additional information against each class
* @ return string - text for display
2009-12-07 20:43:37 +00:00
*/
2009-08-19 21:33:20 +00:00
public function show_graphical_tree ( $show_debug = FALSE )
2007-12-22 12:39:27 +00:00
{
2009-02-01 15:18:30 +00:00
$this -> graph_debug = $show_debug ;
$indent_images = array ();
2010-03-11 11:56:23 +00:00
$ret = "
< div class = 'uclass_tree' style = 'height:16px' >
2013-04-30 01:28:44 -07:00
" . $this->top_icon . "
2009-02-01 15:18:30 +00:00
< span style = 'top:3px' ></ span >
</ div > " ; // Just a generic icon here to provide a visual anchor
$num_parents = count ( $this -> class_parents );
foreach ( $this -> class_parents as $p )
{
$num_parents -- ;
$ret .= $this -> show_graphical_subtree ( $p , $indent_images , ( $num_parents == 0 ));
}
return $ret ;
2007-12-22 12:39:27 +00:00
}
2009-12-07 20:43:37 +00:00
/**
* Creates an array which contains only DB fields ( i . e . strips any added status )
* Copies only those valid fields which are found in the source array
* @ param array $classrec - array of class - related information
* @ param boolean $inc_id - TRUE to include the class id field ( if present in the original )
* @ return array of class info suitable for writing to DB
*/
2009-08-19 21:33:20 +00:00
protected function copy_rec ( $classrec , $inc_id = FALSE )
2007-12-22 12:39:27 +00:00
{
2009-08-19 21:33:20 +00:00
$ret = array ();
if ( $inc_id && isset ( $classrec [ 'userclass_id' ])) $ret [ 'userclass_id' ] = $classrec [ 'userclass_id' ];
foreach ( $this -> field_list as $fl => $val )
{
2012-12-19 22:27:48 +00:00
if ( isset ( $classrec [ $fl ])) $ret [ $fl ] = $classrec [ $fl ];
2009-08-19 21:33:20 +00:00
}
return $ret ;
2007-12-22 12:39:27 +00:00
}
2008-11-29 21:16:54 +00:00
2009-12-07 20:43:37 +00:00
/**
* Return an unused class ID . Misses the predefined classes .
* Initially tries to find an unused class ID less than e_UC_SPECIAL_BASE
* Then attempts to find a gap in the lower numbered classes
* Finally allocates a class number above e_UC_SPECIAL_END
* @ return integer | boolean - class ID if available ; otherwise FALSE
*/
2009-08-19 21:43:46 +00:00
public function findNewClassID ()
2008-11-29 21:16:54 +00:00
{
$i = 1 ;
// Start by allocating a new class with a number higher than any previously allocated
foreach ( $this -> class_tree as $id => $r )
{
if ( $id < e_UC_SPECIAL_BASE )
{
$i = max ( $i , $id );
}
}
$i ++ ;
if ( $i < e_UC_SPECIAL_BASE ) return $i ;
2009-01-15 15:42:24 +00:00
2008-11-29 21:16:54 +00:00
// Looks like we've had a lot of activity in classes - try and find a gap.
for ( $i = 1 ; ( $i < e_UC_SPECIAL_BASE ); $i ++ )
{
if ( ! isset ( $this -> class_tree [ $i ])) return $i ;
}
2013-01-01 10:39:30 +00:00
// Big system!! Assign a class in the 2.0-only block above 255
2009-06-29 21:26:58 +00:00
for ( $i = e_UC_SPECIAL_END + 1 ; ( $i < 32767 ); $i ++ )
{
if ( ! isset ( $this -> class_tree [ $i ])) return $i ;
}
2008-11-29 21:16:54 +00:00
return FALSE ; // Just in case all classes assigned!
}
2009-12-07 20:43:37 +00:00
/**
* Add new class . Class ID must be in the passed record .
* @ param array $classrec - user class data
* @ return boolean TRUE on success , FALSE on failure
*/
2009-08-19 21:33:20 +00:00
public function add_new_class ( $classrec )
2008-12-29 22:30:16 +00:00
{
if ( ! isset ( $classrec [ 'userclass_id' ]))
{
return FALSE ;
}
if ( $classrec [ 'userclass_type' ] == UC_TYPE_GROUP )
{ // Need to make sure our ID is in the accumulation array
$temp = explode ( ',' , $classrec [ 'userclass_accum' ]);
if ( ! in_array ( $classrec [ 'userclass_id' ], $temp ))
{
$temp [] = $classrec [ 'userclass_id' ];
$classrec [ 'userclass_accum' ] = implode ( ',' , $temp );
}
}
2020-12-14 16:21:48 -08:00
if ( $this -> sql_r -> insert ( 'userclass_classes' , $this -> copy_rec ( $classrec , TRUE )) === FALSE )
2008-12-07 16:37:37 +00:00
{
2008-12-29 22:30:16 +00:00
return FALSE ;
2008-12-07 16:37:37 +00:00
}
2015-07-20 16:55:01 -03:00
//findNewClassID() always returns an unused ID.
//if a plugin.xml adds more than one <class ...> within <userClasses..> tag
//it will add 1 class only because class_tree never updates itself after adding classes and will return the same unnused ID
$this -> class_tree [ $classrec [ 'userclass_id' ]] = $classrec ;
2008-12-29 22:30:16 +00:00
$this -> clearCache ();
return TRUE ;
2008-12-07 16:37:37 +00:00
}
2009-01-15 15:42:24 +00:00
2009-12-07 20:43:37 +00:00
/**
* Save class data after editing
2013-01-01 10:39:30 +00:00
*
2009-12-07 20:43:37 +00:00
* @ param array $classrec - class data
* @ return boolean TRUE on success , FALSE on failure
2012-12-19 22:27:48 +00:00
*
* Note - only updates those fields which are present in the passed array , and ignores unexpected fields .
2009-12-07 20:43:37 +00:00
*/
2009-08-19 21:33:20 +00:00
public function save_edited_class ( $classrec )
2007-12-22 12:39:27 +00:00
{
2009-01-15 15:42:24 +00:00
if ( ! $classrec [ 'userclass_id' ])
2008-12-29 22:30:16 +00:00
{
2015-03-01 12:43:02 -08:00
e107 :: getMessage () -> addDebug ( 'Programming bungle on save - no ID field' );
// echo 'Programming bungle on save - no ID field<br />';
2008-12-29 22:30:16 +00:00
return FALSE ;
}
$qry = '' ;
$spacer = '' ;
2012-12-19 22:27:48 +00:00
if ( isset ( $classrec [ 'userclass_type' ]) && ( $classrec [ 'userclass_type' ] == UC_TYPE_GROUP ))
2008-12-29 22:30:16 +00:00
{ // Need to make sure our ID is in the accumulation array
$temp = explode ( ',' , $classrec [ 'userclass_accum' ]);
if ( ! in_array ( $classrec [ 'userclass_id' ], $temp ))
{
$temp [] = $classrec [ 'userclass_id' ];
$classrec [ 'userclass_accum' ] = implode ( ',' , $temp );
}
}
2009-01-15 15:42:24 +00:00
2008-12-29 22:30:16 +00:00
foreach ( $this -> field_list as $fl => $val )
2008-12-07 16:37:37 +00:00
{
2008-12-29 22:30:16 +00:00
if ( isset ( $classrec [ $fl ]))
{
$qry .= $spacer . " ` " . $fl . " ` = ' " . $classrec [ $fl ] . " ' " ;
$spacer = " , " ;
}
2008-12-07 16:37:37 +00:00
}
2020-12-14 16:21:48 -08:00
if ( $this -> sql_r -> update ( 'userclass_classes' , $qry . " WHERE `userclass_id`=' { $classrec [ 'userclass_id' ] } ' " ) === FALSE )
2008-12-29 22:30:16 +00:00
{
return FALSE ;
}
$this -> clearCache ();
return TRUE ;
2008-12-07 16:37:37 +00:00
}
2009-01-15 15:42:24 +00:00
2008-12-29 22:30:16 +00:00
2012-12-19 22:27:48 +00:00
/**
* Check if a user may edit a user class .
* @ param integer $classID > 0
* @ param string $classList - comma - separated list of class IDs ; defaults to those of current user
*
* @ return integer :
* 0 - if editing not allowed at all
* 1 - if restricted editing allowed ( usually because its a fixed class )
* 2 - All editing rights allowed
*/
public function queryCanEditClass ( $classID , $classList = USERCLASS_LIST )
{
if ( ! isset ( $this -> class_tree [ $classID ])) return 0 ; // Class doesn't exist - no hope of editing!
$blockers = array ( e_UC_PUBLIC => 1 , e_UC_READONLY => 1 , e_UC_NOBODY => 1 , e_UC_GUEST => 1 );
if ( isset ( $blockers [ $classID ])) return 0 ; // Don't allow edit of some fixed classes
$canEdit = $this -> isAdmin ;
$possibles = array_flip ( explode ( ',' , $classList ));
if ( isset ( $possibles [ $this -> class_tree [ $classID ][ 'userclass_editclass' ]])) $canEdit = TRUE ;
if ( ! $canEdit ) return 0 ;
if (( $classID >= e_UC_SPECIAL_BASE ) && ( $classID <= e_UC_SPECIAL_END )) return 1 ; // Restricted edit of fixed classes
if ( isset ( $this -> fixed_classes [ $classID ])) return 1 ; // This picks up fixed classes such as e_UC_PUBLIC outside the main range
return 2 ; // Full edit rights - a 'normal' class
}
2009-08-19 21:33:20 +00:00
2009-12-07 20:43:37 +00:00
/**
* Check if a class may be deleted . ( Fixed classes , classes with descendants cannot be deleted )
* @ param integer $classID > 0
* @ return boolean TRUE if deletion permissible ; false otherwise
*/
2009-08-19 21:33:20 +00:00
public function queryCanDeleteClass ( $classID )
2007-12-22 12:39:27 +00:00
{
2009-08-19 21:33:20 +00:00
if (( $classID >= e_UC_SPECIAL_BASE ) && ( $classID <= e_UC_SPECIAL_END )) return FALSE ; // Don't allow deletion of fixed classes
2012-12-19 22:27:48 +00:00
if ( isset ( $this -> fixed_classes [ $classID ])) return FALSE ; // This picks up fixed classes such as e_UC_PUBLIC outside the main range which can't be deleted
2010-03-11 21:55:45 +00:00
if ( ! isset ( $this -> class_tree [ $classID ])) return FALSE ;
if ( count ( $this -> class_tree [ $classID ][ 'class_children' ])) return FALSE ; // Can't delete class with descendants
2008-12-29 22:30:16 +00:00
foreach ( $this -> class_tree as $c )
{
2012-12-19 22:27:48 +00:00
if ( $c [ 'userclass_editclass' ] == $classID ) return FALSE ; // Class specified as managing or using another class
2009-12-07 20:43:37 +00:00
if ( $c [ 'userclass_visibility' ] == $classID ) return FALSE ;
2008-12-29 22:30:16 +00:00
}
2009-08-19 21:33:20 +00:00
return TRUE ;
}
2009-12-07 20:43:37 +00:00
/**
* Delete a class
* @ param integer $classID > 0
* @ return boolean TRUE on success , FALSE on error
*/
2009-08-19 21:33:20 +00:00
public function delete_class ( $classID )
{
if ( self :: queryCanDeleteClass ( $classID ) === FALSE ) return FALSE ;
2020-12-14 16:21:48 -08:00
if ( $this -> sql_r -> delete ( 'userclass_classes' , " `userclass_id`=' { $classID } ' " ) === FALSE ) return FALSE ;
2008-12-29 22:30:16 +00:00
$this -> clearCache ();
$this -> readTree ( TRUE ); // Re-read the class tree
return TRUE ;
2007-12-22 12:39:27 +00:00
}
2008-12-29 22:30:16 +00:00
2009-12-07 20:43:37 +00:00
/**
2013-01-01 10:39:30 +00:00
* Delete a class , and update class membership for all users who are members of that class .
2009-12-07 20:43:37 +00:00
* @ param integer $classID > 0
* @ return boolean TRUE on success , FALSE on error
*/
2009-08-19 21:33:20 +00:00
public function deleteClassAndUsers ( $classID )
2008-01-13 17:47:35 +00:00
{
2009-08-19 21:33:20 +00:00
if ( self :: delete_class ( $classID ) === TRUE )
2008-12-29 22:30:16 +00:00
{
2019-02-22 11:10:05 -08:00
if ( $this -> sql_r -> select ( 'user' , 'user_id, user_class' , " user_class REGEXP '(^|,) { $classID } (,| $ )' " ))
2008-12-29 22:30:16 +00:00
{
2013-01-01 10:39:30 +00:00
$sql2 = e107 :: getDb ( 'sql2' );
2019-02-22 11:10:05 -08:00
while ( $row = $this -> sql_r -> fetch ())
2008-12-29 22:30:16 +00:00
{
2013-01-01 10:39:30 +00:00
$newClass = self :: ucRemove ( $classID , $row [ 'user_class' ]);
2019-02-22 11:10:05 -08:00
$sql2 -> update ( 'user' , " user_class = ' { $newClass } ' WHERE user_id = { $row [ 'user_id' ] } LIMIT 1 " );
2008-12-29 22:30:16 +00:00
}
}
2009-08-19 21:33:20 +00:00
return TRUE ;
2008-12-29 22:30:16 +00:00
}
2009-08-19 21:33:20 +00:00
return FALSE ;
2008-01-13 17:47:35 +00:00
}
2008-12-29 22:30:16 +00:00
2007-12-22 12:39:27 +00:00
2009-12-07 20:43:37 +00:00
/**
* Adds all users in list to a specified user class
* ( Moved in from e_userclass class )
* @ param integer $cid - user class ID
* @ param $uinfoArray is array ( uid => user_class ) - list of affected users
* @ return none
*/
2009-08-22 21:27:34 +00:00
public function class_add ( $cid , $uinfoArray )
{
$e107 = e107 :: getInstance ();
$uc_sql = new db ;
foreach ( $uinfoArray as $uid => $curclass )
{
if ( $curclass )
{
$newarray = array_unique ( array_merge ( explode ( ',' , $curclass ), array ( $cid )));
$new_userclass = implode ( ',' , $newarray );
}
else
{
$new_userclass = $cid ;
}
2019-02-22 11:10:05 -08:00
$uc_sql -> update ( 'user' , " user_class=' " . e107 :: getParser () -> toDB ( $new_userclass , true ) . " ' WHERE user_id= " . intval ( $uid ) . " LIMIT 1 " );
2009-08-22 21:27:34 +00:00
}
}
2009-12-07 20:43:37 +00:00
/**
2013-01-01 10:39:30 +00:00
* Removes all users in list from a specified user class
2009-12-07 20:43:37 +00:00
* ( Moved in from e_userclass class )
* @ param integer $cid - user class ID
* @ param $uinfoArray is array ( uid => user_class ) - list of affected users
* @ return none
*/
2009-08-22 21:27:34 +00:00
public function class_remove ( $cid , $uinfoArray )
{
2019-02-22 11:10:05 -08:00
$uc_sql = e107 :: getDb ();
2009-08-22 21:27:34 +00:00
foreach ( $uinfoArray as $uid => $curclass )
{
$newarray = array_diff ( explode ( ',' , $curclass ), array ( '' , $cid ));
$new_userclass = implode ( ',' , $newarray );
2019-02-22 11:10:05 -08:00
$uc_sql -> update ( 'user' , " user_class=' " . e107 :: getParser () -> toDB ( $new_userclass , true ) . " ' WHERE user_id= " . intval ( $uid ) . " LIMIT 1 " );
2009-08-22 21:27:34 +00:00
}
}
2007-12-22 12:39:27 +00:00
2009-12-07 20:43:37 +00:00
/**
* Check class data record for a fixed class - certain fields have constraints on their values .
* updates any values which are unacceptable .
* @ param array $data - user class record ( passed by reference )
* @ param integer $id - class id
* @ return boolean Returns TRUE if nothing changed , FALSE if changes made
*/
2009-08-19 21:33:20 +00:00
public function checkAdminInfo ( & $data , $id )
2007-12-22 12:39:27 +00:00
{
2008-11-29 21:16:54 +00:00
$ret = TRUE ;
2009-06-29 21:26:58 +00:00
if (( $id < e_UC_SPECIAL_BASE ) || ( $id > e_UC_SPECIAL_END )) return TRUE ;
2008-11-29 21:16:54 +00:00
if ( isset ( $data [ 'userclass_parent' ]))
{
2009-06-29 21:26:58 +00:00
if (( $data [ 'userclass_parent' ] < e_UC_SPECIAL_BASE ) || ( $data [ 'userclass_parent' ] > e_UC_SPECIAL_END ))
2008-11-29 21:16:54 +00:00
{
$data [ 'userclass_parent' ] = e_UC_NOBODY ;
$ret = FALSE ;
}
}
if ( isset ( $data [ 'userclass_editclass' ]))
{
if ( $id == e_UC_MAINADMIN )
{
if ( $data [ 'userclass_editclass' ] < e_UC_MAINADMIN )
{
$data [ 'userclass_editclass' ] = e_UC_MAINADMIN ;
$ret = FALSE ;
}
}
2009-06-29 21:26:58 +00:00
elseif (( $data [ 'userclass_editclass' ] < e_UC_SPECIAL_BASE ) || ( $data [ 'userclass_editclass' ] > e_UC_SPECIAL_END ))
2008-11-29 21:16:54 +00:00
{
$data [ 'userclass_editclass' ] = e_UC_MAINADMIN ;
$ret = FALSE ;
}
}
return $ret ;
2006-12-02 04:36:16 +00:00
}
2007-12-22 12:39:27 +00:00
2009-12-07 20:43:37 +00:00
/**
* Set a simple default tree structure of classes
* @ return none
*/
2009-08-19 21:33:20 +00:00
public function set_default_structure ()
2007-12-22 12:39:27 +00:00
{
2009-08-19 21:33:20 +00:00
// If they don't exist, we need to create class records for the 'standard' user classes
$init_list = array (
array ( 'userclass_id' => e_UC_MEMBER , 'userclass_name' => UC_LAN_3 ,
'userclass_description' => UCSLAN_75 ,
'userclass_editclass' => e_UC_MAINADMIN ,
'userclass_parent' => e_UC_PUBLIC ,
'userclass_visibility' => e_UC_MEMBER
),
array ( 'userclass_id' => e_UC_ADMINMOD , 'userclass_name' => UC_LAN_8 ,
'userclass_description' => UCSLAN_74 ,
'userclass_editclass' => e_UC_MAINADMIN ,
'userclass_parent' => e_UC_MAINADMIN ,
'userclass_visibility' => e_UC_MEMBER
),
array ( 'userclass_id' => e_UC_ADMIN , 'userclass_name' => UC_LAN_5 ,
'userclass_description' => UCSLAN_76 ,
'userclass_editclass' => e_UC_MAINADMIN ,
'userclass_parent' => e_UC_ADMINMOD ,
'userclass_visibility' => e_UC_MEMBER
),
array ( 'userclass_id' => e_UC_MAINADMIN , 'userclass_name' => UC_LAN_6 ,
'userclass_description' => UCSLAN_77 ,
'userclass_editclass' => e_UC_MAINADMIN ,
'userclass_parent' => e_UC_NOBODY ,
'userclass_visibility' => e_UC_MEMBER
),
array ( 'userclass_id' => e_UC_MODS , 'userclass_name' => UC_LAN_7 ,
'userclass_description' => UCSLAN_78 ,
'userclass_editclass' => e_UC_MAINADMIN ,
'userclass_parent' => e_UC_ADMINMOD ,
'userclass_visibility' => e_UC_MEMBER
),
array ( 'userclass_id' => e_UC_NEWUSER , 'userclass_name' => UC_LAN_9 ,
'userclass_description' => UCSLAN_87 ,
'userclass_editclass' => e_UC_MAINADMIN ,
'userclass_parent' => e_UC_MEMBER ,
'userclass_visibility' => e_UC_ADMIN
2009-11-01 17:19:27 +00:00
),
2016-01-21 16:22:57 -08:00
array ( 'userclass_id' => e_UC_BOTS , 'userclass_name' => UC_LAN_10 ,
2009-11-01 17:19:27 +00:00
'userclass_description' => UCSLAN_88 ,
'userclass_editclass' => e_UC_MAINADMIN ,
'userclass_parent' => e_UC_PUBLIC ,
'userclass_visibility' => e_UC_ADMIN
2009-08-19 21:33:20 +00:00
)
);
foreach ( $init_list as $entry )
{
2015-03-01 12:43:02 -08:00
if ( $this -> sql_r -> select ( 'userclass_classes' , '*' , " userclass_id=' " . $entry [ 'userclass_id' ] . " ' " ))
2009-08-19 21:33:20 +00:00
{
2015-03-01 12:43:02 -08:00
$this -> sql_r -> update ( 'userclass_classes' , " userclass_parent=' " . $entry [ 'userclass_parent' ] . " ', userclass_visibility=' " . $entry [ 'userclass_visibility' ] . " ' WHERE userclass_id=' " . $entry [ 'userclass_id' ] . " ' " );
2009-08-19 21:33:20 +00:00
}
else
{
$this -> add_new_class ( $entry );
}
}
2007-12-22 12:39:27 +00:00
}
2009-01-15 15:42:24 +00:00
2009-08-19 21:33:20 +00:00
2012-12-29 12:12:51 +00:00
/**
* Write the current userclass tree to the file e_TEMP . 'userclasses.xml'
*
* @ return TRUE on success , FALSE on fail .
*/
public function makeXMLFile ()
{
$xml = " <dbTable name= \" userclass_classes \" > \n " ;
foreach ( $this -> class_tree as $uc => $d )
{
$xml .= " \t <item> \n " ;
$xml .= " \t \t <field name= \" userclass_id \" > { $uc } </field> \n " ;
foreach ( $this -> field_list as $f => $v )
{
$xml .= " \t \t <field name= \" { $f } \" > { $d [ $f ] } </field> \n " ;
}
$xml .= " \t </item> \n " ;
}
$xml .= " </dbTable> \n " ;
return ( file_put_contents ( e_TEMP . 'userclasses.xml' , $xml ) === FALSE ) ? FALSE : TRUE ;
}
2009-12-07 20:43:37 +00:00
/**
* Clear user class cache
* @ return none
*/
2009-08-19 21:33:20 +00:00
public function clearCache ()
2008-11-29 21:16:54 +00:00
{
2015-05-12 13:53:47 -07:00
e107 :: getCache () -> clear_sys ( UC_CACHE_TAG );
2008-11-29 21:16:54 +00:00
}
2006-12-02 04:36:16 +00:00
}
2007-12-22 12:39:27 +00:00
2020-06-05 11:34:17 -07:00