fixes #1604 moved activity download API method to activity php file

This commit is contained in:
Matthieu Leproux 2022-02-02 14:42:06 +01:00
parent 0c3ef1d521
commit 1e8b4c747f
3 changed files with 59 additions and 61 deletions

View file

@ -25,6 +25,64 @@ check_status(ACCESS_ADMINISTRATOR);
$page['tab'] = 'user_activity';
include(PHPWG_ROOT_PATH.'admin/include/user_tabs.inc.php');
if (isset($_GET['type']) && 'download_logs' == $_GET['type']) {
global $conf;
$output_lines = array();
$query = '
SELECT
activity_id,
performed_by,
object,
object_id,
action,
ip_address,
occured_on,
details,
'.$conf['user_fields']['username'].' AS username
FROM '.ACTIVITY_TABLE.'
JOIN '.USERS_TABLE.' AS u ON performed_by = u.'.$conf['user_fields']['id'].'
ORDER BY activity_id DESC
;';
$result = pwg_query($query);
array_push($output_lines, ['User', 'ID_User', 'Object', 'Object_ID', 'Action', 'Date', 'Hour', 'IP_Address', 'Details']);
while ($row = pwg_db_fetch_assoc($result))
{
$row['details'] = str_replace('`groups`', 'groups', $row['details']);
$row['details'] = str_replace('`rank`', 'rank', $row['details']);
list($date, $hour) = explode(' ', $row['occured_on']);
$output_lines[] = array(
'username' => $row['username'],
'user_id' => $row['performed_by'],
'object' => $row['object'],
'object_id' => $row['object_id'],
'action' => $row['action'],
'date' => $date,
'hour' => $hour,
'ip_address' => $row['ip_address'],
'details' => $row['details'],
);
}
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.date('YmdGis').'piwigo_activity_log.csv');
header("Content-Transfer-Encoding: UTF-8");
$f = fopen('php://output', 'w');
foreach ($output_lines as $line) {
fputcsv($f, $line, ";");
}
fclose($f);
exit();
}
// +-----------------------------------------------------------------------+
// | template initialization |
// +-----------------------------------------------------------------------+