mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-05-16 14:41:39 +00:00
fix import of users, add groups
This commit is contained in:
parent
fef827a7db
commit
7a886b9693
|
@ -70,12 +70,17 @@ function renderFolderData($colname, $objdata) { /* {{{ */
|
||||||
|
|
||||||
function getGroupData($colname, $coldata, $objdata) { /* {{{ */
|
function getGroupData($colname, $coldata, $objdata) { /* {{{ */
|
||||||
global $dms;
|
global $dms;
|
||||||
|
$kk = explode('_', $colname);
|
||||||
|
if(count($kk) == 2)
|
||||||
|
$gn = $kk[1];
|
||||||
|
else
|
||||||
|
$gn = '1';
|
||||||
if(!isset($objdata['groups']))
|
if(!isset($objdata['groups']))
|
||||||
$objdata['groups'] = [];
|
$objdata['groups'] = [];
|
||||||
if($group = $dms->getGroupByName($coldata)) {
|
if($group = $dms->getGroupByName($coldata)) {
|
||||||
$objdata['groups'][] = $group;
|
$objdata['groups'][$gn] = $group;
|
||||||
} else {
|
} else {
|
||||||
$objdata['groups'] = [];
|
$objdata['groups'][$gn] = null;
|
||||||
$objdata['__logs__'][] = array('type'=>'error', 'msg'=> "No such group with name '".$coldata."'");
|
$objdata['__logs__'][] = array('type'=>'error', 'msg'=> "No such group with name '".$coldata."'");
|
||||||
}
|
}
|
||||||
return $objdata;
|
return $objdata;
|
||||||
|
@ -83,8 +88,13 @@ function getGroupData($colname, $coldata, $objdata) { /* {{{ */
|
||||||
|
|
||||||
function renderGroupData($colname, $objdata) { /* {{{ */
|
function renderGroupData($colname, $objdata) { /* {{{ */
|
||||||
$html = '';
|
$html = '';
|
||||||
foreach($objdata[$colname] as $g)
|
$kk = explode('_', $colname);
|
||||||
$html .= $g->getName().';';
|
if(count($kk) == 2)
|
||||||
|
$gn = $kk[1];
|
||||||
|
else
|
||||||
|
$gn = '1';
|
||||||
|
if($objdata['groups'][$gn])
|
||||||
|
$html .= $objdata['groups'][$gn]->getName();
|
||||||
return $html;
|
return $html;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
|
@ -127,6 +137,7 @@ if (isset($_FILES['userdata']) && $_FILES['userdata']['error'] == 0) {
|
||||||
|
|
||||||
$csvdelim = ';';
|
$csvdelim = ';';
|
||||||
$csvencl = '"';
|
$csvencl = '"';
|
||||||
|
$colmap = array();
|
||||||
if($fp = fopen($_FILES['userdata']['tmp_name'], 'r')) {
|
if($fp = fopen($_FILES['userdata']['tmp_name'], 'r')) {
|
||||||
/* First of all build up a column map, which contains for each columen
|
/* First of all build up a column map, which contains for each columen
|
||||||
* the column name
|
* 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
|
* Unknown columns will be skipped and the index in the column map will
|
||||||
* be left out.
|
* be left out.
|
||||||
*/
|
*/
|
||||||
$colmap = array();
|
|
||||||
if($csvheader = fgetcsv($fp, 0, $csvdelim, $csvencl)) {
|
if($csvheader = fgetcsv($fp, 0, $csvdelim, $csvencl)) {
|
||||||
foreach($csvheader as $i=>$colname) {
|
foreach($csvheader as $i=>$colname) {
|
||||||
$colname = trim($colname);
|
$colname = trim($colname);
|
||||||
|
@ -245,10 +255,14 @@ if (isset($_FILES['userdata']) && $_FILES['userdata']['error'] == 0) {
|
||||||
} else {
|
} else {
|
||||||
if(!empty($u['login']) && !empty($u['name']) && !empty($u['email'])) {
|
if(!empty($u['login']) && !empty($u['name']) && !empty($u['email'])) {
|
||||||
if(!empty($_POST['addnew'])) {
|
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']);
|
$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)
|
if($ret) {
|
||||||
$log[$uhash][] = array('id'=>$u['login'], 'type'=>'success', 'msg'=> "User '".$u['name']."' added.");
|
$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.");
|
$log[$uhash][] = array('id'=>$u['login'], 'type'=>'error', 'msg'=> "User '".$u['name']."' could not be added.");
|
||||||
} else {
|
} else {
|
||||||
// $log[$uhash][] = array('id'=>$u['login'], 'type'=>'success', 'msg'=> "User '".$u['name']."' can be added.");
|
// $log[$uhash][] = array('id'=>$u['login'], 'type'=>'success', 'msg'=> "User '".$u['name']."' can be added.");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user