Close #3 (add export/reports feature)
This commit is contained in:
parent
21f39a326f
commit
c5724b658e
@ -183,6 +183,10 @@ switch ($VARS['action']) {
|
||||
}
|
||||
$data = $database->select('permissions', ['permcode (name)', 'perminfo (info)'], ["OR" => ['permcode[~]' => $VARS['q'], 'perminfo[~]' => $VARS['q']], "LIMIT" => 10]);
|
||||
exit(json_encode($data));
|
||||
case "export":
|
||||
require_once __DIR__ . "/lib/reports.php";
|
||||
generateReport($VARS['type'], $VARS['format']);
|
||||
break;
|
||||
case "signout":
|
||||
session_destroy();
|
||||
header('Location: index.php');
|
||||
|
@ -4,7 +4,9 @@
|
||||
"type": "project",
|
||||
"require": {
|
||||
"catfan/medoo": "^1.2",
|
||||
"guzzlehttp/guzzle": "^6.2"
|
||||
"guzzlehttp/guzzle": "^6.2",
|
||||
"league/csv": "^9.0",
|
||||
"lapinator/ods-php-generator": "^0.0.3"
|
||||
},
|
||||
"license": "OTHER",
|
||||
"authors": [
|
||||
|
120
composer.lock
generated
120
composer.lock
generated
@ -4,7 +4,8 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "1c8b61c5d506ae016285b99b20040cf0",
|
||||
"hash": "8acc7eb83a673740764833bbd7a269b4",
|
||||
"content-hash": "023698ff1ab38962a9834e363ebe460c",
|
||||
"packages": [
|
||||
{
|
||||
"name": "catfan/medoo",
|
||||
@ -63,7 +64,7 @@
|
||||
"sql",
|
||||
"sqlite"
|
||||
],
|
||||
"time": "2017-05-22T04:39:48+00:00"
|
||||
"time": "2017-05-22 04:39:48"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/guzzle",
|
||||
@ -125,7 +126,7 @@
|
||||
"rest",
|
||||
"web service"
|
||||
],
|
||||
"time": "2017-02-28T22:50:30+00:00"
|
||||
"time": "2017-02-28 22:50:30"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/promises",
|
||||
@ -176,7 +177,7 @@
|
||||
"keywords": [
|
||||
"promise"
|
||||
],
|
||||
"time": "2016-12-20T10:07:11+00:00"
|
||||
"time": "2016-12-20 10:07:11"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/psr7",
|
||||
@ -241,7 +242,114 @@
|
||||
"uri",
|
||||
"url"
|
||||
],
|
||||
"time": "2017-03-20T17:10:46+00:00"
|
||||
"time": "2017-03-20 17:10:46"
|
||||
},
|
||||
{
|
||||
"name": "lapinator/ods-php-generator",
|
||||
"version": "v0.0.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Lapinator/odsPhpGenerator.git",
|
||||
"reference": "575314c003c2ec3032813bedcc1d27032b7b7ab2"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Lapinator/odsPhpGenerator/zipball/575314c003c2ec3032813bedcc1d27032b7b7ab2",
|
||||
"reference": "575314c003c2ec3032813bedcc1d27032b7b7ab2",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"src/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"LGPL-3.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Laurent VUIBERT",
|
||||
"email": "lapinator@gmx.fr",
|
||||
"homepage": "http://lapinator.net",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Open Document Spreadsheet (.ods) generator ",
|
||||
"homepage": "https://odsphpgenerator.lapinator.net/",
|
||||
"keywords": [
|
||||
"LibreOffice",
|
||||
"ods"
|
||||
],
|
||||
"time": "2016-04-14 21:51:27"
|
||||
},
|
||||
{
|
||||
"name": "league/csv",
|
||||
"version": "9.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/thephpleague/csv.git",
|
||||
"reference": "5dc305e7958190bcab0cc2778888a4f658d29aa1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/thephpleague/csv/zipball/5dc305e7958190bcab0cc2778888a4f658d29aa1",
|
||||
"reference": "5dc305e7958190bcab0cc2778888a4f658d29aa1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-mbstring": "*",
|
||||
"php": ">=7.0.10"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-curl": "*",
|
||||
"friendsofphp/php-cs-fixer": "^2.0",
|
||||
"phpunit/phpunit": "^6.0"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-iconv": "Needed to ease transcoding CSV using iconv stream filters"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "9.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"League\\Csv\\": "src"
|
||||
},
|
||||
"files": [
|
||||
"src/functions_include.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ignace Nyamagana Butera",
|
||||
"email": "nyamsprod@gmail.com",
|
||||
"homepage": "https://github.com/nyamsprod/",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Csv data manipulation made easy in PHP",
|
||||
"homepage": "http://csv.thephpleague.com",
|
||||
"keywords": [
|
||||
"csv",
|
||||
"export",
|
||||
"filter",
|
||||
"import",
|
||||
"read",
|
||||
"write"
|
||||
],
|
||||
"time": "2017-08-21 13:42:10"
|
||||
},
|
||||
{
|
||||
"name": "psr/http-message",
|
||||
@ -291,7 +399,7 @@
|
||||
"request",
|
||||
"response"
|
||||
],
|
||||
"time": "2016-08-06T14:39:51+00:00"
|
||||
"time": "2016-08-06 14:39:51"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
|
@ -93,5 +93,18 @@ define("STRINGS", [
|
||||
"type to add a person" => "Type to add a person",
|
||||
"employees" => "Employees",
|
||||
"type to select a manager" => "Type to select a manager",
|
||||
"select a manager to view or edit employees" => "Select a manager to view or edit the assigned employees."
|
||||
"select a manager to view or edit employees" => "Select a manager to view or edit the assigned employees.",
|
||||
"report export" => "Reports/Export",
|
||||
"report type" => "Report type",
|
||||
"format" => "Format",
|
||||
"generate report" => "Generate report",
|
||||
"choose an option" => "Choose an option",
|
||||
"csv file" => "CSV text file",
|
||||
"ods file" => "ODS spreadsheet",
|
||||
"uid" => "User ID",
|
||||
"manager name" => "Manager",
|
||||
"manager username" => "Mgr. Username",
|
||||
"employee name" => "Employee",
|
||||
"employee username" => "Emp. Username",
|
||||
"permission id" => "Perm. ID"
|
||||
]);
|
192
lib/reports.php
Normal file
192
lib/reports.php
Normal file
@ -0,0 +1,192 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . "/../required.php";
|
||||
|
||||
use League\Csv\Writer;
|
||||
use odsPhpGenerator\ods;
|
||||
use odsPhpGenerator\odsTable;
|
||||
use odsPhpGenerator\odsTableRow;
|
||||
use odsPhpGenerator\odsTableColumn;
|
||||
use odsPhpGenerator\odsTableCellString;
|
||||
use odsPhpGenerator\odsStyleTableColumn;
|
||||
use odsPhpGenerator\odsStyleTableCell;
|
||||
|
||||
dieifnotloggedin();
|
||||
|
||||
function getUserReport() {
|
||||
global $database;
|
||||
$users = $database->select(
|
||||
"accounts", [
|
||||
"[>]acctstatus" => ["acctstatus" => "statusid"],
|
||||
"[>]accttypes" => ["accttype" => "typeid"]
|
||||
], [
|
||||
"uid", "username", "realname", "email", "statuscode", "typecode", "authsecret"
|
||||
]
|
||||
);
|
||||
$header = [lang("uid", false), lang("username", false), lang("name", false), lang("email", false), lang("status", false), lang("type", false), lang("2fa", false)];
|
||||
$out = [$header];
|
||||
for ($i = 0; $i < count($users); $i++) {
|
||||
$out[] = [
|
||||
$users[$i]["uid"],
|
||||
$users[$i]["username"],
|
||||
$users[$i]["realname"],
|
||||
$users[$i]["email"],
|
||||
$users[$i]["statuscode"],
|
||||
$users[$i]["typecode"],
|
||||
is_null($users[$i]["authsecret"]) ? "0" : "1"
|
||||
];
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
function getManagerReport() {
|
||||
global $database;
|
||||
$managers = $database->select('managers', [
|
||||
"[>]accounts (manager)" => ['managerid' => 'uid'],
|
||||
"[>]accounts (employee)" => ['employeeid' => 'uid']
|
||||
], [
|
||||
'managerid',
|
||||
'employeeid',
|
||||
'manager.username (manageruser)',
|
||||
'employee.username (employeeuser)',
|
||||
'manager.realname (managername)',
|
||||
'employee.realname (employeename)',
|
||||
]);
|
||||
$header = [lang("manager name", false), lang("manager username", false), lang("employee name", false), lang("employee username", false)];
|
||||
$out = [$header];
|
||||
for ($i = 0; $i < count($managers); $i++) {
|
||||
$out[] = [
|
||||
$managers[$i]["managername"],
|
||||
$managers[$i]["manageruser"],
|
||||
$managers[$i]["employeename"],
|
||||
$managers[$i]["employeeuser"]
|
||||
];
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
function getPermissionReport() {
|
||||
global $database;
|
||||
$permissions = $database->select('assigned_permissions', [
|
||||
"[>]accounts" => ['uid' => 'uid'],
|
||||
"[>]permissions" => ['permid' => 'permid']
|
||||
], [
|
||||
'username',
|
||||
'realname',
|
||||
'assigned_permissions.uid',
|
||||
'permissions.permid',
|
||||
'permcode'
|
||||
]);
|
||||
$header = [lang("uid", false), lang("username", false), lang("name", false), lang("permission", false), lang("permission id", false)];
|
||||
$out = [$header];
|
||||
for ($i = 0; $i < count($permissions); $i++) {
|
||||
$out[] = [
|
||||
$permissions[$i]["uid"],
|
||||
$permissions[$i]["username"],
|
||||
$permissions[$i]["realname"],
|
||||
$permissions[$i]["permcode"],
|
||||
$permissions[$i]["permid"],
|
||||
];
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
function getSecurityReport() {
|
||||
global $database;
|
||||
$log = $database->select('authlog', [
|
||||
"[>]logtypes" => ['logtype'],
|
||||
"[>]accounts" => ['uid']
|
||||
], [
|
||||
'logtime',
|
||||
'typename',
|
||||
'uid',
|
||||
'username',
|
||||
'realname',
|
||||
'ip',
|
||||
'otherdata'
|
||||
]);
|
||||
$header = [lang("logtime", false), lang("logtype", false), lang("ip address", false), lang("uid", false), lang("username", false), lang("name", false), lang("other data", false)];
|
||||
$out = [$header];
|
||||
for ($i = 0; $i < count($log); $i++) {
|
||||
$out[] = [
|
||||
$log[$i]["logtime"],
|
||||
$log[$i]["typename"],
|
||||
$log[$i]["ip"],
|
||||
$log[$i]["uid"],
|
||||
$log[$i]["username"],
|
||||
$log[$i]["realname"],
|
||||
$log[$i]["otherdata"]
|
||||
];
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
function getReportData($type) {
|
||||
switch ($type) {
|
||||
case "users":
|
||||
return getUserReport();
|
||||
break;
|
||||
case "managers":
|
||||
return getManagerReport();
|
||||
break;
|
||||
case "permissions":
|
||||
return getPermissionReport();
|
||||
break;
|
||||
case "security":
|
||||
return getSecurityReport();
|
||||
break;
|
||||
default:
|
||||
return [["error"]];
|
||||
}
|
||||
}
|
||||
|
||||
function dataToCSV($data, $name = "report") {
|
||||
$csv = Writer::createFromString('');
|
||||
$csv->insertAll($data);
|
||||
header('Content-type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="' . $name . "_" . date("Y-m-d_Hm") . ".csv" . '"');
|
||||
echo $csv;
|
||||
die();
|
||||
}
|
||||
|
||||
function dataToODS($data, $name = "report") {
|
||||
$ods = new ods();
|
||||
$styleColumn = new odsStyleTableColumn();
|
||||
$styleColumn->setUseOptimalColumnWidth(true);
|
||||
$headerstyle = new odsStyleTableCell();
|
||||
$headerstyle->setFontWeight("bold");
|
||||
$table = new odsTable($name);
|
||||
|
||||
for ($i = 0; $i < count($data[0]); $i++) {
|
||||
$table->addTableColumn(new odsTableColumn($styleColumn));
|
||||
}
|
||||
|
||||
$rowid = 0;
|
||||
foreach ($data as $datarow) {
|
||||
$row = new odsTableRow();
|
||||
foreach ($datarow as $cell) {
|
||||
if ($rowid == 0) {
|
||||
$row->addCell(new odsTableCellString($cell, $headerstyle));
|
||||
} else {
|
||||
$row->addCell(new odsTableCellString($cell));
|
||||
}
|
||||
}
|
||||
$table->addRow($row);
|
||||
$rowid++;
|
||||
}
|
||||
$ods->addTable($table);
|
||||
$ods->downloadOdsFile($name . "_" . date("Y-m-d_Hm") . ".ods");
|
||||
}
|
||||
|
||||
function generateReport($type, $format) {
|
||||
$data = getReportData($type);
|
||||
switch ($format) {
|
||||
case "ods":
|
||||
dataToODS($data, $type);
|
||||
break;
|
||||
case "csv":
|
||||
default:
|
||||
echo dataToCSV($data, $type);
|
||||
break;
|
||||
}
|
||||
}
|
@ -88,6 +88,11 @@ define("PAGES", [
|
||||
"title" => "delete permission",
|
||||
"navbar" => false
|
||||
],
|
||||
"export" => [
|
||||
"title" => "report export",
|
||||
"navbar" => true,
|
||||
"icon" => "download"
|
||||
],
|
||||
"404" => [
|
||||
"title" => "404 error"
|
||||
]
|
||||
|
32
pages/export.php
Normal file
32
pages/export.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../required.php';
|
||||
|
||||
redirectifnotloggedin();
|
||||
?>
|
||||
|
||||
<form action="action.php" method="POST" target="_BLANK">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-6">
|
||||
<label for="type"><?php lang("report type"); ?></label>
|
||||
<select name="type" class="form-control" required>
|
||||
<option selected><?php lang("choose an option") ?></option>
|
||||
<option value="users"><?php lang("users") ?></option>
|
||||
<option value="managers"><?php lang("managers") ?></option>
|
||||
<option value="permissions"><?php lang("permissions") ?></option>
|
||||
<option value="security"><?php lang("security log") ?></option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-6">
|
||||
<label for="type"><?php lang("format"); ?></label>
|
||||
<select name="format" class="form-control" required>
|
||||
<option value="csv"><?php lang("csv file") ?></option>
|
||||
<option value="ods"><?php lang("ods file") ?></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
<input type="hidden" name="action" value="export" />
|
||||
<input type="hidden" name="source" value="export" />
|
||||
|
||||
<button type="submit" class="btn btn-success"><i class="fa fa-download"></i> <?php lang("generate report"); ?></button>
|
||||
</form>
|
Loading…
x
Reference in New Issue
Block a user