mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-03-12 00:45:34 +00:00
135 lines
4.4 KiB
PHP
135 lines
4.4 KiB
PHP
![]() |
<?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());
|