1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-30 11:20:25 +02:00

Admin -> users area now has a tab for extended fields. TODO: field-type detection for extended fields.

This commit is contained in:
Cameron
2014-08-21 14:21:49 -07:00
parent d6dc4aa716
commit 361c471bc7

View File

@@ -176,7 +176,7 @@ class users_admin_ui extends e_admin_ui
// protected $listQry = "SELECT SQL_CALC_FOUND_ROWS * FROM #users"; // without any Order or Limit.
protected $listQry = "SELECT SQL_CALC_FOUND_ROWS u.*,ue.* from #user AS u left join #user_extended AS ue ON u.user_id = ue.user_extended_id "; // without any Order or Limit.
//protected $editQry = "SELECT * FROM #users WHERE comment_id = {ID}";
protected $editQry = "SELECT u.*,ue.* FROM #user AS u left join #user_extended AS ue ON u.user_id = ue.user_extended_id WHERE user_id = {ID}";
protected $pid = "user_id";
protected $perPage = 10;
@@ -199,37 +199,38 @@ class users_admin_ui extends e_admin_ui
*/
protected $disallow = array('create');
protected $tabs = array('Basic', 'Extended');
//TODO - finish 'user' type, set 'data' to all editable fields, set 'noedit' for all non-editable fields
protected $fields = array(
'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
'user_id' => array('title' => LAN_ID, 'type' =>'integer', 'width' => '5%','forced' => true),
'user_id' => array('title' => LAN_ID, 'tab'=>0, 'type' =>'integer', 'width' => '5%','forced' => true),
// 'user_status' => array('title' => LAN_STATUS, 'type' => 'method', 'alias'=>'user_status', 'width' => 'auto','forced' => true, 'nosort'=>TRUE),
'user_ban' => array('title' => LAN_STATUS, 'type' => 'method', 'width' => 'auto', 'filter'=>true, 'batch'=>true,'thclass'=>'center', 'class'=>'center'),
'user_ban' => array('title' => LAN_STATUS, 'tab'=>0, 'type' => 'method', 'width' => 'auto', 'filter'=>true, 'batch'=>true,'thclass'=>'center', 'class'=>'center'),
'user_name' => array('title' => LAN_USER_01, 'type' => 'text', 'data'=>'str', 'width' => 'auto','thclass' => 'left first'), // Display name
'user_loginname' => array('title' => LAN_USER_02, 'type' => 'text', 'data'=>'str', 'width' => 'auto'), // User name
'user_login' => array('title' => LAN_USER_03, 'type' => 'text', 'data'=>'str', 'width' => 'auto'), // Real name (no real vetting)
'user_customtitle' => array('title' => LAN_USER_04, 'type' => 'text', 'data'=>'str', 'width' => 'auto'), // No real vetting
'user_password' => array('title' => LAN_USER_05, 'type' => 'method', 'data'=>'str', 'width' => 'auto'), //TODO add md5 option to form handler?
'user_sess' => array('title' => 'Session', 'noedit'=>true, 'type' => 'text', 'width' => 'auto'), // Photo
'user_image' => array('title' => LAN_USER_07, 'type' => 'dropdown', 'data'=>'str', 'width' => 'auto'), // Avatar
'user_email' => array('title' => LAN_EMAIL, 'type' => 'text', 'inline'=>true, 'data'=>'str', 'width' => 'auto'),
'user_hideemail' => array('title' => LAN_USER_10, 'type' => 'boolean', 'data'=>'int', 'width' => 'auto', 'thclass'=>'center', 'class'=>'center', 'filter'=>true, 'batch'=>true, 'readParms'=>'trueonly=1'),
'user_xup' => array('title' => 'Xup', 'noedit'=>true, 'type' => 'text', 'width' => 'auto'),
'user_class' => array('title' => LAN_USER_12, 'type' => 'userclasses' , 'inline'=>true, 'writeParms' => 'classlist=classes', 'inline'=>true, 'filter'=>true, 'batch'=>true),
'user_join' => array('title' => LAN_USER_14, 'noedit'=>true, 'type' => 'datestamp', 'width' => 'auto', 'writeParms'=>'readonly=1'),
'user_lastvisit' => array('title' => LAN_USER_15, 'noedit'=>true, 'type' => 'datestamp', 'width' => 'auto'),
'user_currentvisit' => array('title' => LAN_USER_16, 'noedit'=>true, 'type' => 'datestamp', 'width' => 'auto'),
'user_comments' => array('title' => LAN_USER_17, 'noedit'=>true, 'type' => 'int', 'width' => 'auto','thclass'=>'right','class'=>'right'),
'user_lastpost' => array('title' => 'Last Post', 'noedit'=>true, 'type' => 'datestamp', 'width' => 'auto'),
'user_ip' => array('title' => LAN_USER_18, 'noedit'=>true, 'type' => 'ip', 'width' => 'auto'),
'user_name' => array('title' => LAN_USER_01, 'tab'=>0, 'type' => 'text', 'data'=>'str', 'width' => 'auto','thclass' => 'left first'), // Display name
'user_loginname' => array('title' => LAN_USER_02, 'tab'=>0, 'type' => 'text', 'data'=>'str', 'width' => 'auto'), // User name
'user_login' => array('title' => LAN_USER_03, 'tab'=>0, 'type' => 'text', 'data'=>'str', 'width' => 'auto'), // Real name (no real vetting)
'user_customtitle' => array('title' => LAN_USER_04, 'tab'=>0, 'type' => 'text', 'data'=>'str', 'width' => 'auto'), // No real vetting
'user_password' => array('title' => LAN_USER_05, 'tab'=>0, 'type' => 'method', 'data'=>'str', 'width' => 'auto'), //TODO add md5 option to form handler?
'user_sess' => array('title' => 'Session', 'tab'=>0, 'noedit'=>true, 'type' => 'text', 'width' => 'auto'), // Photo
'user_image' => array('title' => LAN_USER_07, 'tab'=>0, 'type' => 'dropdown', 'data'=>'str', 'width' => 'auto'), // Avatar
'user_email' => array('title' => LAN_EMAIL, 'tab'=>0, 'type' => 'text', 'inline'=>true, 'data'=>'str', 'width' => 'auto'),
'user_hideemail' => array('title' => LAN_USER_10, 'tab'=>0, 'type' => 'boolean', 'data'=>'int', 'width' => 'auto', 'thclass'=>'center', 'class'=>'center', 'filter'=>true, 'batch'=>true, 'readParms'=>'trueonly=1'),
'user_xup' => array('title' => 'Xup', 'tab'=>0, 'noedit'=>true, 'type' => 'text', 'width' => 'auto'),
'user_class' => array('title' => LAN_USER_12, 'tab'=>0, 'type' => 'userclasses' , 'inline'=>true, 'writeParms' => 'classlist=classes', 'inline'=>true, 'filter'=>true, 'batch'=>true),
'user_join' => array('title' => LAN_USER_14, 'tab'=>0, 'noedit'=>true, 'type' => 'datestamp', 'width' => 'auto', 'writeParms'=>'readonly=1'),
'user_lastvisit' => array('title' => LAN_USER_15, 'tab'=>0, 'noedit'=>true, 'type' => 'datestamp', 'width' => 'auto'),
'user_currentvisit' => array('title' => LAN_USER_16, 'tab'=>0, 'noedit'=>true, 'type' => 'datestamp', 'width' => 'auto'),
'user_comments' => array('title' => LAN_USER_17, 'tab'=>0, 'noedit'=>true, 'type' => 'int', 'width' => 'auto','thclass'=>'right','class'=>'right'),
'user_lastpost' => array('title' => 'Last Post', 'tab'=>0, 'noedit'=>true, 'type' => 'datestamp', 'width' => 'auto'),
'user_ip' => array('title' => LAN_USER_18, 'tab'=>0, 'noedit'=>true, 'type' => 'ip', 'width' => 'auto'),
// 'user_prefs' => array('title' => LAN_USER_20, 'type' => 'text', 'width' => 'auto'),
'user_visits' => array('title' => LAN_USER_21, 'noedit'=>true, 'type' => 'int', 'width' => 'auto','thclass'=>'right','class'=>'right'),
'user_admin' => array('title' => LAN_USER_22, 'type' => 'boolean', 'width' => 'auto', 'thclass'=>'center', 'class'=>'center', 'filter'=>true, 'batch'=>true, 'readParms'=>'trueonly=1'),
'user_perms' => array('title' => LAN_USER_23, 'type' => 'method', 'data'=>'str', 'width' => 'auto'),
'user_pwchange' => array('title' => LAN_USER_24, 'noedit'=>true, 'type'=>'datestamp' , 'width' => 'auto'),
'user_visits' => array('title' => LAN_USER_21, 'tab'=>0, 'noedit'=>true, 'type' => 'int', 'width' => 'auto','thclass'=>'right','class'=>'right'),
'user_admin' => array('title' => LAN_USER_22, 'tab'=>0, 'type' => 'boolean', 'width' => 'auto', 'thclass'=>'center', 'class'=>'center', 'filter'=>true, 'batch'=>true, 'readParms'=>'trueonly=1'),
'user_perms' => array('title' => LAN_USER_23, 'tab'=>0, 'type' => 'method', 'data'=>'str', 'width' => 'auto'),
'user_pwchange' => array('title' => LAN_USER_24, 'tab'=>0, 'noedit'=>true, 'type'=>'datestamp' , 'width' => 'auto'),
);
@@ -251,6 +252,8 @@ class users_admin_ui extends e_admin_ui
'user_new_period' => array('title' => USRLAN_190, 'type' => 'number', 'writeParms' => array('maxlength' => 3, 'post' => LANDT_04s), 'help' => USRLAN_191, 'data' => 'int',),
);
protected $extended = array();
function init()
{
@@ -262,12 +265,11 @@ class users_admin_ui extends e_admin_ui
$this->fields['user_class']['noedit'] = true;
}
// Extended fields - FIXME - better field types
if($sql->db_Select('user_extended_struct', 'user_extended_struct_name,user_extended_struct_text', "user_extended_struct_type > 0 AND user_extended_struct_text != '_system_' ORDER BY user_extended_struct_parent ASC"))
if($sql->select('user_extended_struct', 'user_extended_struct_name,user_extended_struct_text', "user_extended_struct_type > 0 AND user_extended_struct_text != '_system_' ORDER BY user_extended_struct_parent ASC"))
{
// FIXME use the handler to build fields and field attributes
// TODO FIXME use the handler to build fields and field attributes
// FIXME a way to load 3rd party language files for extended user fields
e107::coreLan('user_extended');
while ($row = $sql->fetch())
@@ -275,7 +277,9 @@ class users_admin_ui extends e_admin_ui
$field = "user_".$row['user_extended_struct_name'];
$title = ucfirst(str_replace("user_","",$field));
$label = $tp->toHtml($row['user_extended_struct_text'],false,'defs');
$this->fields[$field] = array('title' => $label,'width' => 'auto','type'=>'text', 'noedit'=>true);
$this->fields[$field] = array('title' => $label,'width' => 'auto', 'data'=>false,'type'=>'text', 'tab'=>1, 'noedit'=>false);
$this->extended[] = $field;
}
}
$this->fields['user_signature']['writeParms']['data'] = e107::getUserClass()->uc_required_class_list("classes");
@@ -289,7 +293,24 @@ class users_admin_ui extends e_admin_ui
unset($this->fields['checkboxes']);
unset($this->fields['options']);
}
$this->fields['user_image']['writeParms'] = $this->getAvatarList();
//FIXME - handle user extended search...
//$this->_alias_parsed = false;
//$this->parseAliases();
// if(isset ($_POST['adduser']))
// {
// addUser();
// }
}
protected function getAvatarList()
{
$avs = array(''=>LAN_NONE);
$upload = array();
$sys = array();
@@ -307,28 +328,16 @@ class users_admin_ui extends e_admin_ui
}
$avs['uploaded'] = $upload;
$avs['system'] = $sys;
$avs['system'] = $sys;
// $avs = array_merge($uploaded,$system);
// print_a($uploaded);
// print_a($avs);
$this->fields['user_image']['writeParms'] = $avs;
//FIXME - handle user extended search...
//$this->_alias_parsed = false;
//$this->parseAliases();
// if(isset ($_POST['adduser']))
// {
// addUser();
// }
return $avs;
}
public function beforeUpdate($new_data, $old_data, $id)
{
$tp = e107::getParser();
if(empty($new_data['user_password']))
{
$new_data['user_password'] = $old_data['user_password'];
@@ -343,8 +352,51 @@ class users_admin_ui extends e_admin_ui
$new_data['user_perms'] = implode(".",$new_data['perms']);
}
// Handle the Extended Fields.
$update = array();
foreach($this->extended as $key) // Grab Extended field data.
{
$update[$key] = ($new_data[$key]);
}
if(!empty($update))
{
if(!e107::getDb()->count('user_extended', '(user_extended_id)', "user_extended_id=".intval($new_data['submit_value'])))
{
$update['user_extended_id'] = intval($new_data['submit_value']);
if(e107::getDb()->insert('user_extended', $update))
{
e107::getMessage()->addSuccess('Extended Fields Updated'); //TODO Replace with Generic or existing LAN.
}
else
{
e107::getMessage()->addError('Extended Fields Update Failed'); //TODO Replace with Generic or existing LAN.
e107::getMessage()->addDebug(print_a($update,true));
}
}
else
{
$update['WHERE'] = 'user_extended_id='. intval($new_data['submit_value']);
if(e107::getDb()->update('user_extended',$update))
{
e107::getMessage()->addSuccess('Extended Fields Updated'); //TODO Replace with Generic or existing LAN.
}
else
{
e107::getMessage()->addError('Extended Fields Update Failed'); //TODO Replace with Generic or existing LAN.
e107::getMessage()->addDebug(print_a($update,true));
}
}
}
return $new_data;
}
/**
* Unban user trigger