mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-05-11 12:11:19 +00:00
better import of users
This commit is contained in:
parent
b19db06572
commit
837f697d3b
|
@ -26,19 +26,28 @@ include("../inc/inc.DBInit.php");
|
|||
include("../inc/inc.ClassUI.php");
|
||||
include("../inc/inc.Authentication.php");
|
||||
|
||||
if (isset($_FILES['userdata']) && $_FILES['userdata']['error'] == 0) {
|
||||
if(!is_uploaded_file($_FILES["userdata"]["tmp_name"]))
|
||||
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_occured"));
|
||||
|
||||
if($_FILES["userdata"]["size"] == 0)
|
||||
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("uploading_zerosize"));
|
||||
}
|
||||
|
||||
function getBaseData($colname, $coldata, $objdata) { /* {{{ */
|
||||
$objdata[$colname] = $coldata;
|
||||
return $objdata;
|
||||
} /* }}} */
|
||||
|
||||
function getQuotaData($colname, $coldata, $objdata) { /* {{{ */
|
||||
$objdata[$colname] = SeedDMS_Core_File::parse_filesize($coldata);
|
||||
return $objdata;
|
||||
} /* }}} */
|
||||
|
||||
function getFolderData($colname, $coldata, $objdata) { /* {{{ */
|
||||
global $dms;
|
||||
if($coldata) {
|
||||
if($folder = $dms->getFolder((int)$coldata)) {
|
||||
$objdata['homefolder'] = $folder;
|
||||
}
|
||||
} else {
|
||||
$objdata['homefolder'] = null;
|
||||
}
|
||||
return $objdata;
|
||||
} /* }}} */
|
||||
|
||||
function getGroupData($colname, $coldata, $objdata) { /* {{{ */
|
||||
global $dms;
|
||||
if($group = $dms->getGroupByName($coldata)) {
|
||||
|
@ -62,6 +71,18 @@ function getRoleData($colname, $coldata, $objdata) { /* {{{ */
|
|||
return $objdata;
|
||||
} /* }}} */
|
||||
|
||||
if (!$user->isAdmin()) {
|
||||
UI::exitError(getMLText("admin_tools"),getMLText("access_denied"));
|
||||
}
|
||||
|
||||
$log = array();
|
||||
if (isset($_FILES['userdata']) && $_FILES['userdata']['error'] == 0) {
|
||||
if(!is_uploaded_file($_FILES["userdata"]["tmp_name"]))
|
||||
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_occured"));
|
||||
|
||||
if($_FILES["userdata"]["size"] == 0)
|
||||
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("uploading_zerosize"));
|
||||
|
||||
$csvdelim = ';';
|
||||
$csvencl = '"';
|
||||
if($fp = fopen($_FILES['userdata']['tmp_name'], 'r')) {
|
||||
|
@ -73,6 +94,10 @@ function getRoleData($colname, $coldata, $objdata) { /* {{{ */
|
|||
$colmap[$i] = array("getGroupData", $colname);
|
||||
} elseif(in_array($colname, array('role'))) {
|
||||
$colmap[$i] = array("getRoleData", $colname);
|
||||
} elseif(in_array($colname, array('homefolder'))) {
|
||||
$colmap[$i] = array("getFolderData", $colname);
|
||||
} elseif(in_array($colname, array('quota'))) {
|
||||
$colmap[$i] = array("getQuotaData", $colname);
|
||||
} elseif(in_array($colname, array('login', 'name', 'email', 'comment', 'group'))) {
|
||||
$colmap[$i] = array("getBaseData", $colname);
|
||||
} elseif(substr($colname, 0, 5) == 'attr:') {
|
||||
|
@ -103,32 +128,69 @@ function getRoleData($colname, $coldata, $objdata) { /* {{{ */
|
|||
}
|
||||
}
|
||||
// print_r($newusers);
|
||||
$makeupdate = !empty($_POST['update']);
|
||||
foreach($newusers as $u) {
|
||||
if($eu = $dms->getUserByLogin($u['login'])) {
|
||||
if(!empty($_POST['update'])) {
|
||||
if(isset($u['name']))
|
||||
if(isset($u['name']) && $u['name'] != $eu->getFullName()) {
|
||||
$log[] = array('id'=>$eu->getLogin(), 'type'=>'success', 'msg'=> "Name of user updated. '".$u['name']."' != '".$eu->getFullName()."'");
|
||||
if($makeupdate)
|
||||
$eu->setFullName($u['name']);
|
||||
if(isset($u['email']))
|
||||
}
|
||||
if(isset($u['email']) && $u['email'] != $eu->getEmail()) {
|
||||
$log[] = array('id'=>$eu->getLogin(), 'type'=>'success', 'msg'=> "Email of user updated. '".$u['email']."' != '".$eu->getEmail()."'");
|
||||
if($makeupdate)
|
||||
$eu->setEmail($u['email']);
|
||||
if(isset($u['comment']))
|
||||
}
|
||||
if(isset($u['comment'])) {
|
||||
$log[] = array('id'=>$eu->getLogin(), 'type'=>'success', 'msg'=> "Comment of user updated. '".$u['comment']."' != '".$eu->getComment()."'");
|
||||
if($makeupdate)
|
||||
$eu->setComment($u['comment']);
|
||||
if(isset($u['language']))
|
||||
}
|
||||
if(isset($u['language'])) {
|
||||
$log[] = array('id'=>$eu->getLogin(), 'type'=>'success', 'msg'=> "Language of user updated. '".$u['language']."' != '".$eu->getLanguage()."'");
|
||||
if($makeupdate)
|
||||
$eu->setLanguage($u['language']);
|
||||
if(isset($u['groups'])) {
|
||||
}
|
||||
if(isset($u['quota'])) {
|
||||
$log[] = array('id'=>$eu->getLogin(), 'type'=>'success', 'msg'=> "Quota of user updated. '".$u['quota']."' != '".$eu->getQuota()."'");
|
||||
if($makeupdate)
|
||||
$eu->setQuota($u['language']);
|
||||
}
|
||||
if(isset($u['homefolder'])) {
|
||||
$log[] = array('id'=>$eu->getLogin(), 'type'=>'success', 'msg'=> "Homefolder of user updated. '".($u['homefolder'] ? $u['homefolder']->getId() : '')."' != '".($eu->getHomeFolder() ? $eu->getHomeFolder()->getId() : '')."'");
|
||||
if($makeupdate)
|
||||
$eu->setHomeFolder($u['homefolder']);
|
||||
}
|
||||
if(isset($u['groups'])) {
|
||||
$func = function($o) {return $o->getID();};
|
||||
$log[] = array('id'=>$eu->getLogin(), 'type'=>'success', 'msg'=> "Groups of user updated. '".implode(',',array_map($func, $u['groups']))."' != '".implode(',',array_map($func, $eu->getGroups()))."'");
|
||||
if($makeupdate) {
|
||||
foreach($eu->getGroups() as $g)
|
||||
$eu->leaveGroup($g);
|
||||
foreach($u['groups'] as $g)
|
||||
$eu->joinGroup($g);
|
||||
}
|
||||
}
|
||||
$log[] = array('id'=>$eu->getLogin(), 'type'=>'success', 'msg'=> "User '".$u['name']."' updated.");
|
||||
} else {
|
||||
if(!empty($u['login']) && !empty($u['name']) && !empty($u['email'])) {
|
||||
$ret = $dms->addUser($u['login'], '', $u['name'], $u['email'], !empty($u['language']) ? $u['language'] : 'en_GB', 'bootstrap', !empty($u['comment']) ? $u['comment'] : '', $u['role']);
|
||||
var_dump($ret);
|
||||
if(!empty($_POST['addnew'])) {
|
||||
if(!empty($u['login']) && !empty($u['name']) && !empty($u['email'])) {
|
||||
$ret = $dms->addUser($u['login'], '', $u['name'], $u['email'], !empty($u['language']) ? $u['language'] : 'en_GB', 'bootstrap', !empty($u['comment']) ? $u['comment'] : '', $u['role']);
|
||||
var_dump($ret);
|
||||
}
|
||||
}
|
||||
$log[] = array('id'=>$u['login'], 'type'=>'success', 'msg'=> "User '".$u['name']."' added.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
|
||||
$view = UI::factory($theme, $tmp[1], array('dms'=>$dms, 'user'=>$user));
|
||||
if($view) {
|
||||
$view->setParam('log', $log);
|
||||
$view($_GET);
|
||||
exit;
|
||||
}
|
||||
|
||||
//header("Location:../out/out.ViewFolder.php?folderid=".$newfolder->getID());
|
||||
|
|
|
@ -40,6 +40,7 @@ class SeedDMS_View_ImportUsers extends SeedDMS_Bootstrap_Style {
|
|||
function show() { /* {{{ */
|
||||
$dms = $this->params['dms'];
|
||||
$user = $this->params['user'];
|
||||
$log = $this->params['log'];
|
||||
|
||||
$this->htmlStartPage(getMLText("import_users"));
|
||||
$this->globalNavigation();
|
||||
|
@ -48,6 +49,8 @@ class SeedDMS_View_ImportUsers extends SeedDMS_Bootstrap_Style {
|
|||
|
||||
$this->contentHeading(getMLText("import_users"));
|
||||
|
||||
echo "<div class=\"row-fluid\">\n";
|
||||
echo "<div class=\"span4\">\n";
|
||||
$this->contentContainerStart();
|
||||
print "<form class=\"form-horizontal\" action=\"../op/op.ImportUsers.php\" name=\"form1\" enctype=\"multipart/form-data\" method=\"post\">";
|
||||
$this->formField(
|
||||
|
@ -63,10 +66,33 @@ class SeedDMS_View_ImportUsers extends SeedDMS_Bootstrap_Style {
|
|||
'value'=>'1'
|
||||
)
|
||||
);
|
||||
$this->formField(
|
||||
getMLText("import_users_addnew"),
|
||||
array(
|
||||
'element'=>'input',
|
||||
'type'=>'checkbox',
|
||||
'name'=>'addnew',
|
||||
'value'=>'1'
|
||||
)
|
||||
);
|
||||
$this->formSubmit("<i class=\"icon-save\"></i> ".getMLText('import'));
|
||||
print "</form>\n";
|
||||
$this->contentContainerEnd();
|
||||
|
||||
echo "</div>\n";
|
||||
echo "<div class=\"span8\">\n";
|
||||
if($log) {
|
||||
echo "<table class=\"table table-condensed\">\n";
|
||||
echo "<tr><th>".getMLText('id')."</th>\n";
|
||||
echo "<th>".getMLText('message')."</th></tr>\n";
|
||||
foreach($log as $item) {
|
||||
$class = $item['type'] == 'success' ? 'success' : 'error';
|
||||
echo "<tr class=\"".$class."\"><td>".$item['id']."</td><td>".$item['msg']."</td></tr>\n";
|
||||
}
|
||||
echo "</table>";
|
||||
}
|
||||
echo "</div>\n";
|
||||
echo "</div>\n";
|
||||
$this->contentEnd();
|
||||
$this->htmlEndPage();
|
||||
} /* }}} */
|
||||
|
|
Loading…
Reference in New Issue
Block a user