2006-12-02 04:36:16 +00:00
< ? php
/*
2008-12-29 16:11:02 +00:00
* e107 website system
*
2017-01-09 17:07:47 +00:00
* Copyright ( C ) 2008 - 2017 e107 Inc ( e107 . org )
2008-12-29 16:11:02 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* Administration Area - User classes
*
2006-12-02 04:36:16 +00:00
*/
2007-12-22 12:39:27 +00:00
2010-01-16 19:54:04 +00:00
require_once ( '../class2.php' );
2017-01-17 01:33:03 +01:00
2010-01-16 19:54:04 +00:00
if ( ! getperms ( '4' ))
2007-12-22 12:39:27 +00:00
{
2016-01-13 19:17:37 -08:00
e107 :: redirect ( 'admin' );
2007-12-22 12:39:27 +00:00
exit ;
2006-12-02 04:36:16 +00:00
}
2009-08-28 16:11:02 +00:00
2017-01-17 01:33:03 +01:00
e107 :: coreLan ( 'userclass2' , true );
2015-03-01 12:43:02 -08:00
class uclass_admin extends e_admin_dispatcher
{
protected $modes = array (
'main' => array (
'controller' => 'uclass_ui' ,
'path' => null ,
'ui' => 'uclass_ui_form' ,
'uipath' => null
),
);
protected $adminMenu = array (
'main/list' => array ( 'caption' => LAN_MANAGE , 'perm' => '4' ),
'main/create' => array ( 'caption' => LAN_CREATE , 'perm' => '4' ),
'main/initial' => array ( 'caption' => UCSLAN_38 , 'perm' => '4' ),
'main/options' => array ( 'caption' => LAN_OPTIONS , 'perm' => '4' ),
// 'main/custom' => array('caption'=> 'Custom Page', 'perm' => 'P')
);
protected $adminMenuAliases = array (
'main/edit' => 'main/list'
);
protected $menuTitle = ADLAN_38 ;
2017-02-01 18:25:32 -08:00
protected $adminMenuIcon = 'e-userclass-24' ;
2015-03-01 12:43:02 -08:00
}
class uclass_ui extends e_admin_ui
{
protected $pluginTitle = ADLAN_38 ;
protected $pluginName = 'core' ;
// protected $eventName = 'userclass';
protected $table = 'userclass_classes' ;
protected $pid = 'userclass_id' ;
protected $perPage = 10 ;
protected $batchDelete = true ;
2015-03-01 21:34:57 -08:00
protected $batchCopy = false ; // no way to generate the non-incrementing primary key at the moment
2015-05-15 13:07:26 -07:00
// protected $listOrder = 'userclass_id DESC'; //XXX Make more intuitive.
protected $listOrder = " CASE WHEN userclass_id = 250 THEN 1 WHEN userclass_id =254 THEN 2 WHEN userclass_id = 253 THEN 3 WHEN userclass_id < 250 THEN 4 END, userclass_id DESC " ;
2015-03-01 12:43:02 -08:00
// protected $sortField = 'somefield_order';
// protected $orderStep = 10;
2015-11-22 10:00:46 -08:00
protected $tabs = null ; // Use 'tab'=>0 OR 'tab'=>1 in the $fields below to enable.
2015-03-01 12:43:02 -08:00
// protected $listQry = "SELECT * FROM `#generic` WHERE gen_type='wmessage' "; // Example Custom Query. LEFT JOINS allowed. Should be without any Order or Limit.
// protected $listOrder = 'gen_id DESC';
protected $fields = array (
'checkboxes' => array ( 'title' => '' , 'type' => null , 'data' => null , 'width' => '5%' , 'thclass' => 'center' , 'forced' => '1' , 'class' => 'center' , 'toggle' => 'e-multiselect' , ),
'userclass_id' => array ( 'title' => LAN_ID , 'type' => 'hidden' , 'data' => 'int' , 'width' => '5%' , 'thclass' => 'left' ),
2017-01-09 17:07:47 +00:00
'userclass_icon' => array ( 'title' => LAN_ICON , 'type' => 'icon' , 'tab' => 0 , 'data' => 'str' , 'width' => '5%' , 'thclass' => 'left' , 'class' => 'center' ),
'userclass_name' => array ( 'title' => LAN_NAME , 'type' => 'text' , 'tab' => 0 , 'data' => 'str' , 'inline' => true , 'width' => 'auto' , 'thclass' => 'left' ),
'userclass_description' => array ( 'title' => LAN_DESCRIPTION , 'type' => 'text' , 'tab' => 0 , 'data' => 'str' , 'inline' => true , 'width' => 'auto' , 'thclass' => 'left' , 'writeParms' => array ( 'size' => 'xxlarge' )),
'userclass_type' => array ( 'title' => LAN_TYPE , 'type' => 'dropdown' , 'tab' => 0 , 'data' => 'int' , 'width' => '10%' , 'thclass' => 'left' , 'class' => 'left' ),
'userclass_editclass' => array ( 'title' => LAN_MANAGER , 'type' => 'userclass' , 'tab' => 0 , 'data' => 'int' , 'width' => 'auto' , 'thclass' => 'left' , 'writeParms' => array ( 'classlist' => 'nobody,public,main,admin,classes,matchclass,member, no-excludes' )),
2019-03-01 11:12:54 -08:00
'userclass_visibility' => array ( 'title' => LAN_VISIBILITY , 'type' => 'userclass' , 'tab' => 0 , 'data' => 'int' , 'width' => 'auto' , 'thclass' => 'left' , 'writeParms' => array ()),
2017-01-09 17:07:47 +00:00
'userclass_parent' => array ( 'title' => LAN_PARENT , 'type' => 'userclass' , 'tab' => 0 , 'data' => 'int' , 'width' => 'auto' , 'thclass' => 'left' , 'writeParms' => array ( 'classlist' => 'main,admin,nobody,public,classes,matchclass,member, no-excludes' )),
2019-03-01 11:12:54 -08:00
'userclass_perms' => array ( 'title' => " Perms " , 'type' => 'hidden' , 'tab' => 0 , 'data' => 'str' , 'width' => 'auto' , 'thclass' => 'left' , 'writeParms' => array ()),
2015-03-01 12:43:02 -08:00
'options' => array ( 'title' => LAN_OPTIONS , 'type' => 'method' , 'width' => '10%' , 'thclass' => 'center last' , 'forced' => TRUE , 'class' => 'right' , 'readParms' => array ( 'deleteClass' => e_UC_NOBODY ))
);
protected $fieldpref = array ( 'userclass_icon' , 'userclass_name' , 'userclass_description' );
/*
protected $prefs = array (
'wm_enclose' => array ( 'title' => WMLAN_05 , 'type' => 'boolean' , 'data' => 'int' , 'help' => WMLAN_06 ), ); */
public function init ()
{
2020-12-29 09:48:36 -08:00
if ( E107_DBG_BASIC && isset ( $_GET [ 'id' ]) && intval ( $_GET [ 'id' ]) === 254 ) // Experimental
2015-11-22 10:00:46 -08:00
{
e107 :: getMessage () -> addDebug ( " Experimental Feature active " );
$this -> tabs = array ( LAN_GENERAL , " Administrator Permissions " );
$this -> fields [ 'userclass_perms' ][ 'type' ] = 'method' ;
$this -> fields [ 'userclass_perms' ][ 'tab' ] = 1 ;
}
2015-03-01 12:43:02 -08:00
// Listen for submitted data.
$this -> initialPageSubmit ();
$this -> optionsPageSubmit ();
if ( $this -> getAction () == 'list' )
{
$this -> fields [ 'userclass_id' ][ 'type' ] = 'number' ;
}
// Set Defaults for when creating new records.
$this -> fields [ 'userclass_type' ][ 'writeParms' ] = array ( UC_TYPE_STD => UCSLAN_80 , UC_TYPE_GROUP => UCSLAN_81 );
$this -> fields [ 'userclass_editclass' ][ 'writeParms' ][ 'default' ] = e_UC_ADMIN ;
$this -> fields [ 'userclass_parent' ][ 'writeParms' ][ 'default' ] = e_UC_NOBODY ;
$this -> fields [ 'userclass_visibility' ][ 'writeParms' ][ 'default' ] = e_UC_ADMIN ;
$this -> fields [ 'userclass_id' ][ 'writeParms' ][ 'default' ] = $this -> getUserClassAdmin () -> findNewClassID ();
}
2017-01-21 11:13:14 -08:00
/**
* @ return Object
*/
2015-03-01 12:43:02 -08:00
public function getUserClassAdmin ()
{
return e107 :: getSingleton ( 'user_class_admin' );
}
2019-02-17 15:37:13 -08:00
public function beforeCreate ( $new_data , $old_data )
2015-03-01 12:43:02 -08:00
{
return $new_data ;
}
public function afterCreate ( $new_data , $old_data , $id )
{
2015-05-12 13:53:47 -07:00
e107 :: getUserClass () -> clearCache ();
2015-11-22 10:00:46 -08:00
$e_userclass = $this -> getUserClassAdmin ();
$e_userclass -> calc_tree ();
$e_userclass -> save_tree ();
2015-03-01 12:43:02 -08:00
}
public function beforeUpdate ( $new_data , $old_data , $id )
{
2015-11-22 10:00:46 -08:00
if ( ! empty ( $new_data [ 'perms' ]))
{
$new_data [ 'userclass_perms' ] = implode ( " . " , $new_data [ 'perms' ]);
}
e107 :: getMessage () -> addDebug ( print_a ( $new_data , true ));
2015-03-01 12:43:02 -08:00
return $new_data ;
}
public function afterUpdate ( $new_data , $old_data , $id )
{
2015-05-12 13:53:47 -07:00
e107 :: getUserClass () -> clearCache ();
2015-03-01 12:43:02 -08:00
}
2020-12-18 19:55:12 -08:00
public function afterDelete ( $deleted_data , $id , $deleted_check = false )
2015-05-12 13:53:47 -07:00
{
e107 :: getUserClass () -> clearCache ();
}
2015-03-01 12:43:02 -08:00
public function onCreateError ( $new_data , $old_data )
{
// do something
}
public function onUpdateError ( $new_data , $old_data , $id )
{
// do something
}
2015-04-09 11:13:26 -07:00
function renderHelp ()
{
$e_userclass = e107 :: getSingleton ( 'user_class_admin' ); // Admin functions - should just obliterate any previous object created in class2.php
$e_userclass -> calc_tree ();
$text = " <div id='userclass-tree-structure'> " . $e_userclass -> show_graphical_tree () . " </div> " ;
2017-01-22 10:19:26 +01:00
return array ( 'caption' => UCSLAN_91 , 'text' => $text );
2015-04-09 11:13:26 -07:00
// $text .= $e_userclass->show_graphical_tree();
}
2015-03-01 12:43:02 -08:00
public function optionsPage ()
{
$mes = e107 :: getMessage ();
$frm = e107 :: getForm ();
2017-01-09 17:07:47 +00:00
$mes -> addWarning ( LAN_OPTIONS . " <br /><br /> " . UCSLAN_53 );
2015-03-01 12:43:02 -08:00
$text = " <h4> " . LAN_PREFS . " </h4>
< form method = 'post' action = '".e_SELF."?mode=main&action=options' id = 'treesetForm' >
< table class = 'table adminform' >
< colgroup >
< col class = 'col-label' />
< col class = 'col-content' />
</ colgroup >
< tr >< td > " .UCSLAN_54. " < br />< span class = 'smalltext' > " .UCSLAN_57. " </ span >< br />
</ td >< td >
" . $frm->admin_button ('add_class_tree','no-value','delete', UCSLAN_58). "
</ td >
</ tr >
< tr >
< td > " .UCSLAN_55. " < br />< span class = 'smalltext' > " .UCSLAN_56. " </ span >< br />
</ td >< td >
" . $frm->admin_button ('flatten_class_tree','no-value','delete', UCSLAN_58). "
</ td >
</ tr > " ;
/*
if ( $params == '.xml' )
{
$text .= " <tr>
< td > " .'Create XML file of DB'. " < br />< span class = 'smalltext' > " .'Dev aid to set initial values'. " </ span >< br />
</ td >< td >
" . $frm->admin_button ('create_xml_db','no-value','create', 'Create'). "
</ td >
</ tr > " ;
}
*/
$text .= " </table></form> " ;
// $ns->tablerender(ADLAN_38.SEP.LAN_PREFS, $mes->render().$text);
$text .= "
< h4 > " .UCSLAN_71. " </ h4 >< form method = 'post' action = '".e_SELF."?options' id = 'maintainForm' >
< table class = 'table adminform' >
< colgroup >
< col class = 'col-label' />
< col class = 'col-content' />
</ colgroup >
< tr >
< td > " .UCSLAN_72. " < br />
< span class = 'smalltext' > " .UCSLAN_73. " </ span >
</ td >
< td >
" . $frm->admin_button ('rebuild_tree','no-value','delete', UCSLAN_58). "
</ td >
</ tr >
</ table >
</ form > " ;
// $ns->tablerender(UCSLAN_71, $text);
return $text ;
}
public function optionsPageSubmit ()
{
if ( ! check_class ( e_UC_MAINADMIN ))
{
return false ;
}
2017-01-21 11:13:14 -08:00
$message = '' ;
2015-03-01 12:43:02 -08:00
$sql = e107 :: getDb ();
$mes = e107 :: getMessage ();
$e_userclass = $this -> getUserClassAdmin ();
if ( isset ( $_POST [ 'add_class_tree' ])) // Create a default tree
{
$message = UCSLAN_62 ;
$e_userclass -> set_default_structure ();
$e_userclass -> calc_tree ();
$e_userclass -> save_tree ();
$e_userclass -> readTree ( TRUE ); // Need to re-read the tree to show correct info
$message .= UCSLAN_64 ;
}
if ( isset ( $_POST [ 'flatten_class_tree' ])) // Remove the default tree
{
$message = UCSLAN_65 ;
$sql -> update ( 'userclass_classes' , " userclass_parent='0' " );
$e_userclass -> calc_tree ();
$e_userclass -> save_tree ();
$e_userclass -> readTree ( TRUE ); // Need to re-read the tree to show correct info
$message .= UCSLAN_64 ;
}
if ( isset ( $_POST [ 'rebuild_tree' ]))
{
$message = UCSLAN_70 ;
$e_userclass -> calc_tree ();
$e_userclass -> save_tree ();
$message .= UCSLAN_64 ;
}
/*
if ( $params == 'xml' ) $params = '.xml' ; else $params = '' ;
if ( isset ( $_POST [ 'create_xml_db' ]) && ( $params == '.xml' ))
{
$message = $e_userclass -> makeXMLFile () ? 'XML file created' : 'Error creating XML file' ;
}
*/
if ( $message )
{
$mes -> addSuccess ( $message );
// $ns->tablerender('', "<div style='text-align:center'><b>".$message."</b></div>");
}
2017-01-21 11:13:14 -08:00
return null ;
2015-03-01 12:43:02 -08:00
}
public function initialPage ()
{
$pref = e107 :: pref ( 'core' );
$mes = e107 :: getMessage ();
2017-01-21 11:13:14 -08:00
2015-03-01 12:43:02 -08:00
$frm = e107 :: getForm ();
// $e_userclass = $this->getUserClassAdmin();
2017-01-21 11:13:14 -08:00
// $text = "";
2015-03-01 12:43:02 -08:00
$initial_classes = varset ( $pref [ 'initial_user_classes' ], '' );
$irc = explode ( ',' , $initial_classes );
$icn = array ();
foreach ( $irc as $i )
{
2015-05-12 13:53:47 -07:00
if ( trim ( $i )) $icn [] = e107 :: getUserClass () -> getName ( $i );
2015-03-01 12:43:02 -08:00
}
2015-06-02 14:25:39 -07:00
$class_text = $frm -> userclass ( 'init_classes' , $initial_classes , 'checkbox' , array ( 'options' => 'classes,force' ));
2015-03-01 12:43:02 -08:00
// $class_text = e107::getUserClass()->uc_checkboxes('init_classes', $initial_classes, 'classes, force', TRUE);
// $class_text = e107::getUserClass()->vetted_tree('init_classes',array($e_userclass,'checkbox_desc'), $initial_classes, 'classes, force, no-excludes');
$mes -> addInfo ( UCSLAN_49 );
2015-07-15 19:33:15 -07:00
$text = " <div>
2015-03-01 12:43:02 -08:00
< form method = 'post' action = '".e_SELF."?mode=main&action=initial' id = 'initialForm' >
< table class = 'table table-bordered adminform' >
< tr >< td > " .UCSLAN_43. " </ td >< td > " ;
2020-12-18 19:55:12 -08:00
if ( count ( $icn ) < 1 )
2015-03-01 12:43:02 -08:00
{
2017-01-09 17:07:47 +00:00
$text .= LAN_NONE ;
2015-03-01 12:43:02 -08:00
}
if ( $class_text )
{
$text .= $class_text . " </td></tr><tr><td> " ;
$sel_stage = varset ( $pref [ 'init_class_stage' ], 2 );
$initClassStages = array ( 1 => UCSLAN_47 , 2 => UCSLAN_48 );
$text .= UCSLAN_45 . " <br /> </td>
2017-01-21 11:13:14 -08:00
< td > " . $frm->select ('init_class_stage', $initClassStages , $sel_stage , 'size=xlarge'). " < span class = 'field-help' > " .UCSLAN_46. " </ span >
2015-03-01 12:43:02 -08:00
</ td ></ tr ></ table >
2017-01-11 08:45:00 +00:00
< div class = 'buttons-bar center' > " . $frm->admin_button ('set_initial_classes','no-value','create',LAN_UPDATE). " </ div > " ;
2015-03-01 12:43:02 -08:00
}
else
{
$text .= UCSLAN_39 ;
}
$text .= " </td></tr></table></form></div> " ;
return $mes -> render () . $text ;
// $ns->tablerender(ADLAN_38.SEP.UCSLAN_40, $mes->render() . $text);
}
/**
* @ return bool
*/
public function initialPageSubmit ()
{
if ( empty ( $_POST [ 'set_initial_classes' ]))
{
return false ;
}
$pref [ 'init_class_stage' ] = intval ( $_POST [ 'init_class_stage' ]);
$temp = array ();
foreach ( $_POST [ 'init_classes' ] as $ic )
{
$temp [] = intval ( $ic );
}
$newval = implode ( ',' , $temp );
$pref [ 'initial_user_classes' ] = $newval ;
e107 :: getConfig () -> setPref ( $pref ) -> save ( true , true , true );
2017-01-21 11:13:14 -08:00
return true ;
2015-03-01 12:43:02 -08:00
}
}
class uclass_ui_form extends e_admin_form_ui
{
function userclass_type ( $curVal , $mode )
{
$types = array (
UC_TYPE_STD => UCSLAN_80 ,
UC_TYPE_GROUP => UCSLAN_81
);
return varset ( $types [ $curVal ]);
}
function options ( $parms , $value , $id , $attributes )
{
2015-03-15 13:30:37 -07:00
2015-03-01 12:43:02 -08:00
$text = " " ;
2015-03-15 13:30:37 -07:00
$options = array ();
2015-03-01 12:43:02 -08:00
if ( $attributes [ 'mode' ] == 'read' )
{
$classID = $this -> getController () -> getListModel () -> get ( 'userclass_id' );
2017-01-21 11:13:14 -08:00
2015-03-01 12:43:02 -08:00
if ( ! $this -> getController () -> getUserClassAdmin () -> queryCanDeleteClass ( $classID ))
{
2015-03-15 13:30:37 -07:00
$options [ 'readParms' ][ 'deleteClass' ] = e_UC_NOBODY ;
}
if ( $classID == 0 )
{
$options [ 'readParms' ][ 'deleteClass' ] = e_UC_NOBODY ;
$options [ 'readParms' ][ 'editClass' ] = e_UC_NOBODY ;
2015-03-01 12:43:02 -08:00
}
$text .= $this -> renderValue ( 'options' , $value , $options , $id );
// if($parent != 0)
{
// $link = e_SELF."?searchquery=&filter_options=page_chapter__".$id."&mode=page&action=list";
// $text .= "<a href='".$link."' class='btn' title='View Pages in this chapter'>".E_32_CUST."</a>";
}
return $text ;
}
2015-11-22 10:00:46 -08:00
2017-01-21 11:13:14 -08:00
return '' ;
2015-03-01 12:43:02 -08:00
}
2015-11-22 10:00:46 -08:00
function userclass_perms ( $curVal , $mode )
{
2020-12-18 19:55:12 -08:00
// if($mode == 'read')
// {
2015-11-22 10:00:46 -08:00
// $uid = $this->getController()->getModel()->get('user_id');
// return e107::getUserPerms()->renderPerms($curVal,$uid);
2020-12-18 19:55:12 -08:00
// }
2015-11-22 10:00:46 -08:00
if ( $mode == 'write' )
{
$prm = e107 :: getUserPerms ();
return $prm -> renderPermTable ( 'tabs' , $curVal );
}
2017-01-21 11:13:14 -08:00
2020-12-18 19:55:12 -08:00
return null ;
2015-11-22 10:00:46 -08:00
}
2015-03-01 12:43:02 -08:00
}
2015-11-22 10:00:46 -08:00
2015-03-01 12:43:02 -08:00
new uclass_admin ();
require_once ( e_ADMIN . " auth.php " );
e107 :: getAdminUI () -> runPage ();
require_once ( e_ADMIN . " footer.php " );
exit ;
2017-01-22 10:19:26 +01:00
?>