mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-05-13 21:21:27 +00:00
import users from csv file
This commit is contained in:
parent
a15c968d72
commit
514002f877
|
@ -4,6 +4,8 @@
|
||||||
- various minor improvements of indexer.php script
|
- various minor improvements of indexer.php script
|
||||||
- minor fix for better behaviour of folder tree ('plus' signs appears if folder
|
- minor fix for better behaviour of folder tree ('plus' signs appears if folder
|
||||||
has children)
|
has children)
|
||||||
|
- allow to import users from csv file
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
Changes in version 5.1.17
|
Changes in version 5.1.17
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
134
op/op.ImportUsers.php
Normal file
134
op/op.ImportUsers.php
Normal file
|
@ -0,0 +1,134 @@
|
||||||
|
<?php
|
||||||
|
// SeedDMS. Document Management System
|
||||||
|
// Copyright (C) 2010-2016 Uwe Steinmann
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation; either version 2 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
|
include("../inc/inc.Settings.php");
|
||||||
|
include("../inc/inc.LogInit.php");
|
||||||
|
include("../inc/inc.Utils.php");
|
||||||
|
include("../inc/inc.Language.php");
|
||||||
|
include("../inc/inc.Init.php");
|
||||||
|
include("../inc/inc.Extension.php");
|
||||||
|
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 getGroupData($colname, $coldata, $objdata) { /* {{{ */
|
||||||
|
global $dms;
|
||||||
|
if($group = $dms->getGroupByName($coldata)) {
|
||||||
|
$objdata['groups'][] = $group;
|
||||||
|
}
|
||||||
|
return $objdata;
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
|
function getRoleData($colname, $coldata, $objdata) { /* {{{ */
|
||||||
|
switch($coldata) {
|
||||||
|
case 'admin':
|
||||||
|
$role = 1;
|
||||||
|
break;
|
||||||
|
case 'guest':
|
||||||
|
$role = 2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$role = 0;
|
||||||
|
}
|
||||||
|
$objdata['role'] = $role;
|
||||||
|
return $objdata;
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
|
$csvdelim = ';';
|
||||||
|
$csvencl = '"';
|
||||||
|
if($fp = fopen($_FILES['userdata']['tmp_name'], 'r')) {
|
||||||
|
$colmap = array();
|
||||||
|
if($header = fgetcsv($fp, 0, $csvdelim, $csvencl)) {
|
||||||
|
foreach($header as $i=>$colname) {
|
||||||
|
$colname = trim($colname);
|
||||||
|
if(substr($colname, 0, 5) == 'group') {
|
||||||
|
$colmap[$i] = array("getGroupData", $colname);
|
||||||
|
} elseif(in_array($colname, array('role'))) {
|
||||||
|
$colmap[$i] = array("getRoleData", $colname);
|
||||||
|
} elseif(in_array($colname, array('login', 'name', 'email', 'comment', 'group'))) {
|
||||||
|
$colmap[$i] = array("getBaseData", $colname);
|
||||||
|
} elseif(substr($colname, 0, 5) == 'attr:') {
|
||||||
|
$kk = explode(':', $colname, 2);
|
||||||
|
if(($attrdef = $dms->getAttributeDefinitionByName($kk[1])) || ($attrdef = $dms->getAttributeDefinition((int) $kk[1]))) {
|
||||||
|
$colmap[$i] = array("getAttributeData", $attrdef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// echo "<pre>";print_r($colmap);echo "</pre>";
|
||||||
|
if(count($colmap) > 1) {
|
||||||
|
$allusers = $dms->getAllUsers();
|
||||||
|
$userids = array();
|
||||||
|
foreach($allusers as $muser)
|
||||||
|
$userids[$muser->getLogin()] = $muser;
|
||||||
|
$newusers = array();
|
||||||
|
while(!feof($fp)) {
|
||||||
|
if($data = fgetcsv($fp, 0, $csvdelim, $csvencl)) {
|
||||||
|
$md = array();
|
||||||
|
foreach($data as $i=>$coldata) {
|
||||||
|
if(isset($colmap[$i])) {
|
||||||
|
$md = call_user_func($colmap[$i][0], $colmap[$i][1], $coldata, $md);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($md)
|
||||||
|
$newusers[] = $md;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// print_r($newusers);
|
||||||
|
foreach($newusers as $u) {
|
||||||
|
if($eu = $dms->getUserByLogin($u['login'])) {
|
||||||
|
if(!empty($_POST['update'])) {
|
||||||
|
if(isset($u['name']))
|
||||||
|
$eu->setFullName($u['name']);
|
||||||
|
if(isset($u['email']))
|
||||||
|
$eu->setEmail($u['email']);
|
||||||
|
if(isset($u['comment']))
|
||||||
|
$eu->setComment($u['comment']);
|
||||||
|
if(isset($u['language']))
|
||||||
|
$eu->setLanguage($u['language']);
|
||||||
|
if(isset($u['groups'])) {
|
||||||
|
foreach($eu->getGroups() as $g)
|
||||||
|
$eu->leaveGroup($g);
|
||||||
|
foreach($u['groups'] as $g)
|
||||||
|
$eu->joinGroup($g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//header("Location:../out/out.ViewFolder.php?folderid=".$newfolder->getID());
|
40
out/out.ImportUsers.php
Normal file
40
out/out.ImportUsers.php
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
// MyDMS. Document Management System
|
||||||
|
// Copyright (C) 2010 Matteo Lucarelli
|
||||||
|
// Copyright (C) 2010-2016 Uwe Steinmann
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation; either version 2 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
|
if(!isset($settings))
|
||||||
|
require_once("../inc/inc.Settings.php");
|
||||||
|
require_once("inc/inc.LogInit.php");
|
||||||
|
require_once("inc/inc.Utils.php");
|
||||||
|
require_once("inc/inc.Language.php");
|
||||||
|
require_once("inc/inc.Init.php");
|
||||||
|
require_once("inc/inc.Extension.php");
|
||||||
|
require_once("inc/inc.DBInit.php");
|
||||||
|
require_once("inc/inc.ClassUI.php");
|
||||||
|
require_once("inc/inc.Authentication.php");
|
||||||
|
|
||||||
|
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
|
||||||
|
$view = UI::factory($theme, $tmp[1], array('dms'=>$dms, 'user'=>$user));
|
||||||
|
if (!$user->isAdmin()) {
|
||||||
|
UI::exitError(getMLText("admin_tools"),getMLText("access_denied"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if($view) {
|
||||||
|
$view($_GET);
|
||||||
|
exit;
|
||||||
|
}
|
|
@ -721,6 +721,7 @@ background-image: linear-gradient(to bottom, #882222, #111111);;
|
||||||
|
|
||||||
$menuitems['misc'] = array('link'=>"#", 'label'=>'misc');
|
$menuitems['misc'] = array('link'=>"#", 'label'=>'misc');
|
||||||
$menuitems['misc']['children']['import_fs'] = array('link'=>"../out/out.ImportFS.php", 'label'=>'import_fs');
|
$menuitems['misc']['children']['import_fs'] = array('link'=>"../out/out.ImportFS.php", 'label'=>'import_fs');
|
||||||
|
$menuitems['misc']['children']['import_users'] = array('link'=>"../out/out.ImportUsers.php", 'label'=>'import_users');
|
||||||
$menuitems['misc']['children']['folders_and_documents_statistic'] = array('link'=>"../out/out.Statistic.php", 'label'=>'folders_and_documents_statistic');
|
$menuitems['misc']['children']['folders_and_documents_statistic'] = array('link'=>"../out/out.Statistic.php", 'label'=>'folders_and_documents_statistic');
|
||||||
$menuitems['misc']['children']['charts'] = array('link'=>"../out/out.Charts.php", 'label'=>'charts');
|
$menuitems['misc']['children']['charts'] = array('link'=>"../out/out.Charts.php", 'label'=>'charts');
|
||||||
$menuitems['misc']['children']['timeline'] = array('link'=>"../out/out.Timeline.php", 'label'=>'timeline');
|
$menuitems['misc']['children']['timeline'] = array('link'=>"../out/out.Timeline.php", 'label'=>'timeline');
|
||||||
|
|
74
views/bootstrap/class.ImportUsers.php
Normal file
74
views/bootstrap/class.ImportUsers.php
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Implementation of ImportUsers view
|
||||||
|
*
|
||||||
|
* @category DMS
|
||||||
|
* @package SeedDMS
|
||||||
|
* @license GPL 2
|
||||||
|
* @version @version@
|
||||||
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
||||||
|
* @copyright Copyright (C) 2002-2005 Markus Westphal,
|
||||||
|
* 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli,
|
||||||
|
* 2010-2012 Uwe Steinmann
|
||||||
|
* @version Release: @package_version@
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Include parent class
|
||||||
|
*/
|
||||||
|
require_once("class.Bootstrap.php");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class which outputs the html page for ImportUsers view
|
||||||
|
*
|
||||||
|
* @category DMS
|
||||||
|
* @package SeedDMS
|
||||||
|
* @author Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx>
|
||||||
|
* @copyright Copyright (C) 2002-2005 Markus Westphal,
|
||||||
|
* 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli,
|
||||||
|
* 2010-2012 Uwe Steinmann
|
||||||
|
* @version Release: @package_version@
|
||||||
|
*/
|
||||||
|
class SeedDMS_View_ImportUsers extends SeedDMS_Bootstrap_Style {
|
||||||
|
|
||||||
|
function js() { /* {{{ */
|
||||||
|
$this->printFileChooserJs();
|
||||||
|
header('Content-Type: application/javascript');
|
||||||
|
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
|
function show() { /* {{{ */
|
||||||
|
$dms = $this->params['dms'];
|
||||||
|
$user = $this->params['user'];
|
||||||
|
|
||||||
|
$this->htmlStartPage(getMLText("import_users"));
|
||||||
|
$this->globalNavigation();
|
||||||
|
$this->contentStart();
|
||||||
|
$this->pageNavigation(getMLText("admin_tools"), "admin_tools");
|
||||||
|
|
||||||
|
$this->contentHeading(getMLText("import_users"));
|
||||||
|
|
||||||
|
$this->contentContainerStart();
|
||||||
|
print "<form class=\"form-horizontal\" action=\"../op/op.ImportUsers.php\" name=\"form1\" enctype=\"multipart/form-data\" method=\"post\">";
|
||||||
|
$this->formField(
|
||||||
|
getMLText("userdata_file"),
|
||||||
|
$this->getFileChooserHtml('userdata', false)
|
||||||
|
);
|
||||||
|
$this->formField(
|
||||||
|
getMLText("import_users_update"),
|
||||||
|
array(
|
||||||
|
'element'=>'input',
|
||||||
|
'type'=>'checkbox',
|
||||||
|
'name'=>'update',
|
||||||
|
'value'=>'1'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->formSubmit("<i class=\"icon-save\"></i> ".getMLText('import'));
|
||||||
|
print "</form>\n";
|
||||||
|
$this->contentContainerEnd();
|
||||||
|
|
||||||
|
$this->contentEnd();
|
||||||
|
$this->htmlEndPage();
|
||||||
|
} /* }}} */
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user