mirror of
https://github.com/e107inc/e107.git
synced 2025-08-06 14:46:56 +02:00
Admin UI - work on types 'userclasses' and 'comma', related wit #9 as well. Work in progress.
This commit is contained in:
@@ -213,7 +213,7 @@ class users_admin_ui extends e_admin_ui
|
||||
'user_email' => array('title' => LAN_USER_08, 'type' => 'text', 'width' => 'auto'),
|
||||
'user_hideemail' => array('title' => LAN_USER_10, 'type' => 'boolean', 'width' => 'auto', 'thclass'=>'center', 'class'=>'center', 'filter'=>true, 'batch'=>true, 'readParms'=>'trueonly=1'),
|
||||
'user_xup' => array('title' => 'Xup', 'type' => 'text', 'width' => 'auto'),
|
||||
'user_class' => array('title' => LAN_USER_12, 'type' => 'method' , 'data' =>'comma', 'filter'=>true, 'batch'=>true),
|
||||
'user_class' => array('title' => LAN_USER_12, 'type' => 'userclasses' , 'writeParms' => 'classlist=classes', 'filter'=>true, 'batch'=>true),
|
||||
'user_join' => array('title' => LAN_USER_14, 'type' => 'datestamp', 'width' => 'auto', 'writeParms'=>'readonly=1'),
|
||||
'user_lastvisit' => array('title' => LAN_USER_15, 'type' => 'datestamp', 'width' => 'auto'),
|
||||
'user_currentvisit' => array('title' => LAN_USER_16, 'type' => 'datestamp', 'width' => 'auto'),
|
||||
@@ -225,6 +225,7 @@ class users_admin_ui extends e_admin_ui
|
||||
'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', 'width' => 'auto'),
|
||||
'user_pwchange' => array('title' => LAN_USER_24, 'type'=>'datestamp' , 'width' => 'auto'),
|
||||
//'commatest' => array('title' => 'TEST', 'type'=>'comma' , 'writeParms' => 'data=test1,test2,test3&addAll&clearAll', 'width' => 'auto', 'filter'=>true, 'batch'=>true),
|
||||
|
||||
);
|
||||
|
||||
@@ -266,6 +267,7 @@ class users_admin_ui extends e_admin_ui
|
||||
$this->fields[$field] = array('title' => $label,'width' => 'auto','type'=>'text', 'noedit'=>true);
|
||||
}
|
||||
}
|
||||
$this->fields['user_signature']['writeParms']['data'] = e107::getUserClass()->uc_required_class_list("classes");
|
||||
|
||||
$this->fields['user_signature'] = array('title' => LAN_USER_09, 'type' => 'bbarea', 'width' => 'auto');
|
||||
$this->fields['options'] = array('title'=> LAN_OPTIONS, 'type' => 'method', 'forced'=>TRUE, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center');
|
||||
@@ -1885,13 +1887,13 @@ class users_admin_form_ui extends e_admin_form_ui
|
||||
return vartrue($bo[$curval],' '); // ($curval == 1) ? ADMIN_TRUE_ICON : '';
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
function user_class($curval,$mode)
|
||||
{
|
||||
|
||||
$e_userclass = new user_class;
|
||||
$frm = e107::getForm();
|
||||
$list = $e_userclass->uc_required_class_list("classes");
|
||||
$list = $e_userclass->uc_required_class_list("classes");
|
||||
if($mode == 'filter')
|
||||
{
|
||||
@@ -1907,10 +1909,9 @@ class users_admin_form_ui extends e_admin_form_ui
|
||||
|
||||
//FIXME TODO - option to append userclass to existing value.
|
||||
if($mode == 'batch')
|
||||
{
|
||||
{
|
||||
//$list['#delete'] = "(clear userclass)"; // special
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
$tmp = explode(",",$curval);
|
||||
$text = array();
|
||||
@@ -1919,7 +1920,8 @@ class users_admin_form_ui extends e_admin_form_ui
|
||||
$text[] = $list[$v];
|
||||
}
|
||||
return implode("<br />",$text); // $list[$curval];
|
||||
|
||||
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
|
@@ -2718,8 +2718,15 @@ class e_admin_controller_ui extends e_admin_controller
|
||||
$multi_name = $this->getFieldAttr('checkboxes', 'toggle', 'multiselect');
|
||||
$selected = array_values($this->getPosted($multi_name, array()));
|
||||
|
||||
//if(empty($selected)) return $this; - allow empty (no selected) submit for custom batch handlers - e.g. Export CSV
|
||||
// requires writeParams['batchNoCheck'] == true!!!
|
||||
if(empty($selected))
|
||||
{
|
||||
$params = $this->getFieldAttr($field, 'writeParms', array());
|
||||
if(!is_array($params)) parse_str($params, $params);
|
||||
if(!vartrue($params['batchNoCheck']))
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
$selected = array_map('intval', $selected);
|
||||
$trigger = $tp->toDB(explode('__', $batch_trigger));
|
||||
@@ -2748,7 +2755,6 @@ class e_admin_controller_ui extends e_admin_controller
|
||||
if(method_exists($this, $method)) // callback handling
|
||||
{
|
||||
$this->$method($selected, $field, $value);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -2760,24 +2766,81 @@ class e_admin_controller_ui extends e_admin_controller
|
||||
if(method_exists($this, $method)) // callback handling
|
||||
{
|
||||
$this->$method($selected, $field);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'append':
|
||||
//TODO - append value to existing field value. eg. userclasses.
|
||||
// see commma, userclasses batch options
|
||||
case 'attach':
|
||||
case 'deattach':
|
||||
case 'addAll':
|
||||
case 'clearAll':
|
||||
$field = $trigger[1];
|
||||
$value = $trigger[2];
|
||||
|
||||
if($trigger[0] == 'addAll')
|
||||
{
|
||||
$parms = $this->getFieldAttr($field, 'writeParms', array());
|
||||
if(!is_array($parms)) parse_str($parms, $parms);
|
||||
|
||||
$value = isset($parms['data']) && !empty($parms['data']) ? $parms['data'] : array();
|
||||
if(empty($value)) return $this;
|
||||
if(!is_array($value)) $value = array_map('trim', explode(',', $value));
|
||||
}
|
||||
|
||||
if(method_exists($this, 'handleCommaBatch'))
|
||||
{
|
||||
$this->handleCommaBatch($selected, $field, $value, $trigger[0]);
|
||||
}
|
||||
break;
|
||||
|
||||
// append to userclass list
|
||||
case 'ucadd':
|
||||
case 'ucremove':
|
||||
//if(empty($selected)) return $this;
|
||||
$field = $trigger[1];
|
||||
$class = $trigger[2];
|
||||
$user = e107::getUser();
|
||||
$e_userclass = e107::getUserClass();
|
||||
|
||||
// check userclass manager class
|
||||
if (!isset($e_userclass->class_tree[$class]) || !$user->checkClass($e_userclass->class_tree[$class]))
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
if(method_exists($this, 'handleCommaBatch'))
|
||||
{
|
||||
$trigger[0] = $trigger[0] == 'ucadd' ? 'attach' : 'deattach';
|
||||
$this->handleCommaBatch($selected, $field, $class, $trigger[0]);
|
||||
}
|
||||
break;
|
||||
|
||||
// add all to userclass list
|
||||
// clear userclass list
|
||||
case 'ucaddall':
|
||||
case 'ucdelall':
|
||||
$field = $trigger[1];
|
||||
$user = e107::getUser();
|
||||
$e_userclass = e107::getUserClass();
|
||||
$parms = $this->getFieldAttr($field, 'writeParms', array());
|
||||
if(!is_array($parms)) parse_str($parms, $parms);
|
||||
if(!vartrue($parms['classlist'])) return $this;
|
||||
|
||||
$classes = $e_userclass->uc_required_class_list($parms['classlist']);
|
||||
foreach ($classes as $id => $label)
|
||||
{
|
||||
// check userclass manager class
|
||||
if (!isset($e_userclass->class_tree[$class]) || !$user->checkClass($e_userclass->class_tree[$class]))
|
||||
{
|
||||
unset($classes[$id]);
|
||||
}
|
||||
}
|
||||
$this->handleCommaBatch($selected, $field, $classes, $trigger[1] === 'ucdelall' ? 'clearAll' : 'addAll');
|
||||
break;
|
||||
|
||||
default:
|
||||
$field = $trigger[0];
|
||||
$value = $trigger[1];
|
||||
$params = $this->getFieldAttr($field, 'writeParms', array());
|
||||
if(!is_array($params)) parse_str($params, $params);
|
||||
|
||||
if(!vartrue($params['batchNoCheck']) && empty($selected))
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
//something like handleListUrlTypeBatch(); for custom handling of 'url_type' field name
|
||||
$method = 'handle'.$this->getRequest()->getActionName().$this->getRequest()->camelize($field).'Batch';
|
||||
@@ -3803,6 +3866,78 @@ class e_admin_ui extends e_admin_controller_ui
|
||||
$this->getTreeModel()->setMessages();
|
||||
}
|
||||
|
||||
public function handleCommaBatch($selected, $field, $value, $type)
|
||||
{
|
||||
$tree = $this->getTreeModel();
|
||||
$cnt = $rcnt = 0;
|
||||
$value = e107::getParser()->toDb($value);
|
||||
|
||||
switch ($type)
|
||||
{
|
||||
case 'attach':
|
||||
case 'deattach':
|
||||
$this->_setModel();
|
||||
foreach ($selected as $key => $id)
|
||||
{
|
||||
$node = $tree->getNode($id);
|
||||
if(!$node) continue;
|
||||
// quick fix, FIXME field ID name not set in the tree model, investigate
|
||||
if(!$node->getFieldIdName()) $node->setFieldIdName($this->pid);
|
||||
|
||||
$val = $node->get($field);
|
||||
|
||||
if(empty($val)) $val = array();
|
||||
elseif(!is_array($val)) $val = explode(',', $val);
|
||||
|
||||
if($type === 'deattach')
|
||||
{
|
||||
$search = array_search($value, $val);
|
||||
if(false === $search) continue;
|
||||
unset($val[$search]);
|
||||
$val = implode(',', $val);
|
||||
$node->set($field, $val);
|
||||
$check = $this->getModel()->setData($node->getData())->save(false, true);
|
||||
|
||||
if(false === $check) $this->getModel()->setMessages();
|
||||
else $rcnt++;
|
||||
}
|
||||
|
||||
// attach it
|
||||
if(false === in_array($value, $val))
|
||||
{
|
||||
$val[] = $value;
|
||||
$val = implode(',', array_unique($val));
|
||||
$node->set($field, $val);
|
||||
$check = $this->getModel()->setData($node->getData())->save(false, true);
|
||||
if(false === $check) $this->getModel()->setMessages();
|
||||
else $cnt++;
|
||||
}
|
||||
}
|
||||
$this->_model = null;
|
||||
break;
|
||||
|
||||
case 'addAll':
|
||||
if(is_array($value)) $value = implode(',', array_map('trim', $value));
|
||||
//$cnt = $this->getTreeModel()->update($field, $value, $selected, $value, false);
|
||||
break;
|
||||
|
||||
case 'clearAll':
|
||||
//$rcnt = $this->getTreeModel()->update($field, '', $selected, $value, false);
|
||||
break;
|
||||
}
|
||||
|
||||
if($cnt)
|
||||
{
|
||||
$vttl = $this->getUI()->renderValue($field, $value, $this->getFieldAttr($field));
|
||||
$this->getTreeModel()->addMessageSuccess(sprintf(LAN_UI_BATCH_UPDATE_SUCCESS, $vttl, $cnt))->setMessages();
|
||||
}
|
||||
elseif($rcnt)
|
||||
{
|
||||
$vttl = $this->getUI()->renderValue($field, $value, $this->getFieldAttr($field));
|
||||
$this->getTreeModel()->addMessageSuccess(sprintf(LAN_UI_BATCH_DEATTACH_SUCCESS, $vttl, $cnt))->setMessages();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Batch default (field) trigger
|
||||
* @param array $selected
|
||||
@@ -3832,7 +3967,7 @@ class e_admin_ui extends e_admin_controller_ui
|
||||
return;
|
||||
}
|
||||
|
||||
$cnt = $this->getTreeModel()->update($field, $val, $selected, $value, false);
|
||||
$cnt = $this->getTreeModel()->update($field, $val, $selected, true, false);
|
||||
if($cnt)
|
||||
{
|
||||
$vttl = $this->getUI()->renderValue($field, $value, $this->getFieldAttr($field));
|
||||
@@ -4231,15 +4366,15 @@ class e_admin_ui extends e_admin_controller_ui
|
||||
$this->dataFields = array();
|
||||
foreach ($this->fields as $key => $att)
|
||||
{
|
||||
if((false !== varset($att['data']) && null !== $att['type'] && !vartrue($att['noedit'])) || vartrue($att['forceSave']))
|
||||
if(($key !== 'options' && false !== varset($att['data']) && null !== $att['type'] && !vartrue($att['noedit'])) || vartrue($att['forceSave']))
|
||||
{
|
||||
$this->dataFields[$key] = vartrue($att['data'], 'str');
|
||||
}
|
||||
|
||||
if($att['data'] == 'comma') //XXX quick fix so it can be stored.
|
||||
{
|
||||
$this->dataFields[$key] = 'str';
|
||||
}
|
||||
// if($att['data'] == 'comma') //XXX quick fix so it can be stored.
|
||||
// {
|
||||
// $this->dataFields[$key] = 'str';
|
||||
// }
|
||||
}
|
||||
}
|
||||
// TODO - do it in one loop, or better - separate method(s) -> convertFields(validate), convertFields(data),...
|
||||
@@ -4707,6 +4842,27 @@ class e_admin_form_ui extends e_form
|
||||
}
|
||||
break;
|
||||
|
||||
case 'comma':
|
||||
// TODO lan
|
||||
$options = isset($parms['data']) && !empty($parms['data']) ? $parms['data'] : array();
|
||||
if(empty($options)) continue;
|
||||
if(!is_array($options)) $options = array_map('trim', explode(',', $options));
|
||||
|
||||
$_option = array();
|
||||
foreach ($options as $value)
|
||||
{
|
||||
$option['attach__'.$key.'__'.$value] = 'Add '.$value;
|
||||
$_option['deattach__'.$key.'__'.$value] = 'Remove '.$value;
|
||||
}
|
||||
if(isset($parms['addAll'])) $option['attach_all__'.$key] = vartrue($parms['addAll'], '(add all)');
|
||||
if(isset($parms['clearAll']))
|
||||
{
|
||||
$_option['deattach_all__'.$key] = vartrue($parms['clearAll'], '(clear all)');
|
||||
}
|
||||
$option = array_merge($option, $_option);
|
||||
unset($_option);
|
||||
break;
|
||||
|
||||
case 'templates':
|
||||
case 'layouts':
|
||||
$parms['raw'] = true;
|
||||
@@ -4768,13 +4924,25 @@ class e_admin_form_ui extends e_form
|
||||
break;
|
||||
|
||||
case 'userclass':
|
||||
case 'userclasses':
|
||||
$classes = e107::getUserClass()->uc_required_class_list(vartrue($parms['classlist'], 'public,nobody,guest,admin,main,classes'));
|
||||
foreach($classes as $k => $name)
|
||||
{
|
||||
$option[$key.'__'.$k] = $name;
|
||||
}
|
||||
break;
|
||||
case 'userclasses':
|
||||
$classes = e107::getUserClass()->uc_required_class_list(vartrue($parms['classlist'], 'public,nobody,guest,admin,main,classes'));
|
||||
$_option = array();
|
||||
foreach ($classes as $k => $v)
|
||||
{
|
||||
$option['ucadd__'.$key.'__'.$k] = 'Add '.$v;
|
||||
$_option['ucremove__'.$key.'__'.$k] = 'Remove '.$v;
|
||||
}
|
||||
$option['ucaddall__'.$key] = '(add all)';
|
||||
$_option['ucdelall__'.$key] = '(clear all)';
|
||||
$option = array_merge($option, $_option);
|
||||
unset($_option);
|
||||
break;
|
||||
|
||||
case 'method':
|
||||
$method = $key;
|
||||
|
@@ -360,6 +360,7 @@ define('LAN_UI_FORM_METHOD_ERROR', 'FATAL ERROR: The field name <strong>%1$s</st
|
||||
define('LAN_UI_BATCH_UPDATE_SUCCESS', '<strong>%1$s</strong> set for <strong>%2$d</strong> record(s).');
|
||||
define('LAN_UI_BATCH_REVERSED_SUCCESS', '<strong>%1$d</strong> records successfully reversed.');
|
||||
define('LAN_UI_BATCH_BOOL_SUCCESS', '<strong>%1$d</strong> records successfully updated.');
|
||||
define('LAN_UI_BATCH_DEATTACH_SUCCESS', '<strong>%1$s</strong> removed from <strong>%2$d</strong> record(s).');
|
||||
|
||||
define('LAN_UI_EDIT_LABEL', 'Update record #%1$s');
|
||||
define('LAN_UI_CREATE_LABEL', 'Create new record');
|
||||
|
Reference in New Issue
Block a user