seeddms-code/controllers/class.UserListCsv.php

62 lines
2.0 KiB
PHP
Raw Permalink Normal View History

2020-07-27 12:17:11 +00:00
<?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'];
2020-09-23 09:39:19 +00:00
$group = $this->params['group'];
2020-07-27 12:17:11 +00:00
2020-09-23 09:39:19 +00:00
if($group) {
$allUsers = $group->getUsers();
} else {
$allUsers = $dms->getAllUsers($settings->_sortUsersInList);
}
2020-07-27 12:17:11 +00:00
$m = 0;
foreach($allUsers as $u) {
$m = max($m, count($u->getGroups()));
}
$fp = fopen("php://temp/maxmemory", 'r+');
2020-08-27 06:52:35 +00:00
$header = array('login', 'passenc', 'name', 'email', 'comment', 'role', 'quota', 'homefolder', 'hidden', 'disabled');
2020-07-27 12:17:11 +00:00
for($i=1; $i<=$m; $i++)
$header[] = 'group_'.$i;
2020-07-27 13:30:30 +00:00
fputcsv($fp, $header, ';');
2020-07-27 12:17:11 +00:00
foreach($allUsers as $u) {
2020-08-27 06:52:35 +00:00
$data = array($u->getLogin(), $u->getPwd(), $u->getFullName(), $u->getEmail(), $u->getComment(), $u->isAdmin() ? 'admin' : ($u->isGuest() ? 'guest' : 'user'), $u->getQuota(), $u->getHomeFolder() ? $u->getHomeFolder() : '', $u->isHidden() ? '1' : 0, $u->isDisabled() ? '1' : '0');
2020-07-27 12:17:11 +00:00
foreach($u->getGroups() as $g)
$data[] = $g->getName();
2020-07-27 13:30:30 +00:00
fputcsv($fp, $data, ';');
2020-07-27 12:17:11 +00:00
}
$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;
} /* }}} */
}