Merge branch 'seeddms-5.1.x' into seeddms-6.0.x

This commit is contained in:
Uwe Steinmann 2020-07-27 15:33:40 +02:00
commit 096f9773dc
6 changed files with 116 additions and 11 deletions

View File

@ -161,7 +161,7 @@
- various minor improvements of indexer.php script
- minor fix for better behaviour of folder tree ('plus' signs appears if folder
has children)
- allow to import users from csv file
- allow to import users from and export users into csv file
- skip all fileѕ and directories starting with a '.' when creating an extension's
zip file
- add support for authentication of the rest api by a key

View File

@ -0,0 +1,56 @@
<?php
/**
* Implementation of UserListCsv controller
*
* @category DMS
* @package SeedDMS
* @license GPL 2
* @version @version@
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2010-2013 Uwe Steinmann
* @version Release: @package_version@
*/
/**
* Class which does the busines logic for export a list of all users as csv
*
* @category DMS
* @package SeedDMS
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2010-2013 Uwe Steinmann
* @version Release: @package_version@
*/
class SeedDMS_Controller_UserListCsv extends SeedDMS_Controller_Common {
public function run() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
$settings = $this->params['settings'];
$allUsers = $dms->getAllUsers($settings->_sortUsersInList);
$m = 0;
foreach($allUsers as $u) {
$m = max($m, count($u->getGroups()));
}
$fp = fopen("php://temp/maxmemory", 'r+');
$header = array('login', 'name', 'email', 'comment', 'role', 'quota', 'homefolder');
for($i=1; $i<=$m; $i++)
$header[] = 'group_'.$i;
fputcsv($fp, $header, ';');
foreach($allUsers as $u) {
$data = array($u->getLogin(), $u->getFullName(), $u->getEmail(), $u->getComment(), $u->isAdmin() ? 'admin' : ($u->isGuest() ? 'guest' : 'user'), $u->getQuota(), $u->getHomeFolder() ? $u->getHomeFolder() : '');
foreach($u->getGroups() as $g)
$data[] = $g->getName();
fputcsv($fp, $data, ';');
}
$efilename = 'userlist-'.date('Ymd-His').'.csv';
header("Content-Type: text/csv");
header("Content-Disposition: attachment; filename=\"" . $efilename . "\"; filename*=UTF-8''".$efilename);
// header("Content-Length: " . filesize($name));
fseek($fp, 0);
fpassthru($fp);
fclose($fp);
return true;
} /* }}} */
}

View File

@ -127,7 +127,7 @@ if (isset($_FILES['userdata']) && $_FILES['userdata']['error'] == 0) {
$newusers[] = $md;
}
}
// print_r($newusers);
// echo "<pre>";print_r($newusers);echo "</pre>";
$makeupdate = !empty($_POST['update']);
foreach($newusers as $u) {
if($eu = $dms->getUserByLogin($u['login'])) {
@ -141,28 +141,28 @@ if (isset($_FILES['userdata']) && $_FILES['userdata']['error'] == 0) {
if($makeupdate)
$eu->setEmail($u['email']);
}
if(isset($u['comment'])) {
if(isset($u['comment']) && $u['comment'] != $eu->getComment()) {
$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']) && $u['language'] != $eu->getLanguage()) {
$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['quota'])) {
if(isset($u['quota']) && $u['quota'] != $eu->getQuota()) {
$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(isset($u['homefolder']) && $u['homefolder']->getId() != $eu->getHomeFolder()) {
$log[] = array('id'=>$eu->getLogin(), 'type'=>'success', 'msg'=> "Homefolder of user updated. '".(is_object($u['homefolder']) ? $u['homefolder']->getId() : '')."' != '".($eu->getHomeFolder() ? $eu->getHomeFolder() : '')."'");
if($makeupdate)
$eu->setHomeFolder($u['homefolder']);
}
if(isset($u['groups'])) {
$func = function($o) {return $o->getID();};
$func = function($o) {return $o->getID();};
if(isset($u['groups']) && implode(',',array_map($func, $u['groups'])) != implode(',',array_map($func, $eu->getGroups()))) {
$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)
@ -171,7 +171,7 @@ if (isset($_FILES['userdata']) && $_FILES['userdata']['error'] == 0) {
$eu->joinGroup($g);
}
}
$log[] = array('id'=>$eu->getLogin(), 'type'=>'success', 'msg'=> "User '".$u['name']."' updated.");
// $log[] = array('id'=>$eu->getLogin(), 'type'=>'success', 'msg'=> "User '".$eu->getLogin()."' updated.");
} else {
if(!empty($_POST['addnew'])) {
if(!empty($u['login']) && !empty($u['name']) && !empty($u['email'])) {

48
op/op.UserListCsv.php Normal file
View File

@ -0,0 +1,48 @@
<?php
// MyDMS. Document Management System
// Copyright (C) 2002-2005 Markus Westphal
// Copyright (C) 2006-2008 Malcolm Cowe
// 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.
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.ClassController.php");
include("../inc/inc.Authentication.php");
if (!$user->isAdmin()) {
UI::exitError(getMLText("admin_tools"),getMLText("access_denied"));
}
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
$controller = Controller::factory($tmp[1], array('dms'=>$dms, 'user'=>$user));
if(!$controller->run()) {
if ($controller->getErrorMsg() != '')
$errormsg = $controller->getErrorMsg();
else
$errormsg = "error_userlistcsv";
UI::exitError(getMLText("admin_tools"), getMLText($errormsg));
}

View File

@ -87,7 +87,7 @@ class SeedDMS_View_ImportUsers extends SeedDMS_Bootstrap_Style {
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 "<tr class=\"".$class."\"><td>".$item['id']."</td><td>".htmlspecialchars($item['msg'])."</td></tr>\n";
}
echo "</table>";
}

View File

@ -131,6 +131,7 @@ class SeedDMS_View_UserList extends SeedDMS_Bootstrap_Style {
}
echo "</tbody></table>";
echo '<a class="btn btn-primary" href="../op/op.UserListCsv.php">'.getMLText('export_user_list_csv').'</a>';
$this->contentEnd();
$this->htmlEndPage();
} /* }}} */