fix import of users, add groups

This commit is contained in:
Uwe Steinmann 2020-09-03 14:17:40 +02:00
parent fef827a7db
commit 7a886b9693

View File

@ -70,12 +70,17 @@ function renderFolderData($colname, $objdata) { /* {{{ */
function getGroupData($colname, $coldata, $objdata) { /* {{{ */
global $dms;
$kk = explode('_', $colname);
if(count($kk) == 2)
$gn = $kk[1];
else
$gn = '1';
if(!isset($objdata['groups']))
$objdata['groups'] = [];
if($group = $dms->getGroupByName($coldata)) {
$objdata['groups'][] = $group;
$objdata['groups'][$gn] = $group;
} else {
$objdata['groups'] = [];
$objdata['groups'][$gn] = null;
$objdata['__logs__'][] = array('type'=>'error', 'msg'=> "No such group with name '".$coldata."'");
}
return $objdata;
@ -83,8 +88,13 @@ function getGroupData($colname, $coldata, $objdata) { /* {{{ */
function renderGroupData($colname, $objdata) { /* {{{ */
$html = '';
foreach($objdata[$colname] as $g)
$html .= $g->getName().';';
$kk = explode('_', $colname);
if(count($kk) == 2)
$gn = $kk[1];
else
$gn = '1';
if($objdata['groups'][$gn])
$html .= $objdata['groups'][$gn]->getName();
return $html;
} /* }}} */
@ -127,6 +137,7 @@ if (isset($_FILES['userdata']) && $_FILES['userdata']['error'] == 0) {
$csvdelim = ';';
$csvencl = '"';
$colmap = array();
if($fp = fopen($_FILES['userdata']['tmp_name'], 'r')) {
/* First of all build up a column map, which contains for each columen
* the column name
@ -138,7 +149,6 @@ if (isset($_FILES['userdata']) && $_FILES['userdata']['error'] == 0) {
* Unknown columns will be skipped and the index in the column map will
* be left out.
*/
$colmap = array();
if($csvheader = fgetcsv($fp, 0, $csvdelim, $csvencl)) {
foreach($csvheader as $i=>$colname) {
$colname = trim($colname);
@ -245,10 +255,14 @@ if (isset($_FILES['userdata']) && $_FILES['userdata']['error'] == 0) {
} else {
if(!empty($u['login']) && !empty($u['name']) && !empty($u['email'])) {
if(!empty($_POST['addnew'])) {
$ret = $dms->addUser($u['login'], '', $u['name'], $u['email'], !empty($u['language']) ? $u['language'] : 'en_GB', 'bootstrap', !empty($u['comment']) ? $u['comment'] : '', $u['role']);
if($ret)
$ret = $dms->addUser($u['login'], !empty($u['passenc']) ? $u['passenc'] : '', $u['name'], $u['email'], !empty($u['language']) ? $u['language'] : 'en_GB', 'bootstrap', !empty($u['comment']) ? $u['comment'] : '', $u['role']);
if($ret) {
$log[$uhash][] = array('id'=>$u['login'], 'type'=>'success', 'msg'=> "User '".$u['name']."' added.");
else
foreach($u['groups'] as $g) {
if($g)
$ret->joinGroup($g);
}
} else
$log[$uhash][] = array('id'=>$u['login'], 'type'=>'error', 'msg'=> "User '".$u['name']."' could not be added.");
} else {
// $log[$uhash][] = array('id'=>$u['login'], 'type'=>'success', 'msg'=> "User '".$u['name']."' can be added.");