Id()) {
// Saving a report that failed to load would insert a new row
ZM\Warning('Report '.$_REQUEST['id'].' not found');
$redirect = '?view=reports';
return;
}
if (!$report->Id() and !canEdit('Events')) {
ZM\Warning('You do not have permission to create a report');
$error_message .= 'You do not have permission to create a report.
';
return;
}
if ($report->Id() and !$report->canEdit()) {
ZM\Warning('You do not have permission to edit report '.$report->Id());
$error_message .= 'You do not have permission to edit this report.
';
return;
}
if ($action == 'save') {
$posted = isset($_REQUEST['Report']) && is_array($_REQUEST['Report']) ? $_REQUEST['Report'] : array();
if (isset($posted['Name'])) {
$posted['Name'] = is_string($posted['Name']) ? trim($posted['Name']) : '';
if ($posted['Name'] === '') {
$error_message .= 'Report Name is required
';
return;
}
}
$changes = $report->changes($posted);
if (!$report->Id()) {
$changes['CreatedBy'] = $user->Id();
}
if (count($changes)) {
if (!$report->save($changes)) {
$error_message .= "Error saving report: " . $report->get_last_error().'';
} else {
$redirect = '?view=report&id='.$report->Id();
}
}
} else if ($action == 'delete') {
if (!$report->delete()) {
$error_message .= 'Error deleting report: '.htmlspecialchars(dbLastError()).'
';
} else {
$redirect = '?view=reports';
}
} else {
ZM\Error("Unknown action $action in saving Report");
}
?>