mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-03-11 16:35:38 +00:00
a script for export users as csv
This commit is contained in:
parent
9239a12787
commit
076535bf7d
56
controllers/class.UserListCsv.php
Normal file
56
controllers/class.UserListCsv.php
Normal 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;
|
||||
} /* }}} */
|
||||
|
||||
}
|
48
op/op.UserListCsv.php
Normal file
48
op/op.UserListCsv.php
Normal 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));
|
||||
}
|
||||
|
||||
|
|
@ -123,6 +123,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();
|
||||
} /* }}} */
|
||||
|
|
Loading…
Reference in New Issue
Block a user