mirror of
https://github.com/itflow-org/itflow
synced 2026-11-20 19:37:24 +00:00
Vendor templates stage 1: Admin > Vendor Templates rebuilt on the standard list with Active and Archived tabs, support line, hours and SLA, how many clients have a vendor from each, last used and changed by, sortable and searchable including by support line; new template page with what a vendor starts with, the clients with it and their account numbers, the license templates that use it, made and changed by, and history; shared New/Edit window on the vendor window's tabs with per-field push to the vendors made from it, each logged on the vendor; copy, archive, restore and delete with vendors and license templates unlinked on delete; Make a template from a client's vendor, linking the vendor to it, and the vendor page linking its template for admins; Delete offered to every admin role, not only the built-in Administrator; the admin handler no longer includes the agent vendor handler; database 3.3.4 adds vendor_template_created_by and vendor_template_updated_by, backfilled from the audit log
This commit is contained in:
79
admin/post/app_log.php
Normal file
79
admin/post/app_log.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - POST handler for the app logs: exporting them to CSV or PDF, and
|
||||
* clearing them, with the filters the export and clear windows post - the
|
||||
* same ones the list uses (appLogFiltersSql(), functions/app_log.php). Both
|
||||
* are in the audit log.
|
||||
*/
|
||||
|
||||
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
|
||||
|
||||
if (isExportRequest('export_app_logs')) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceAdminPermission();
|
||||
|
||||
$format = resolveExportFormat($_POST['export_app_logs']);
|
||||
|
||||
$filter_summary = [];
|
||||
$where = appLogFiltersSql($_POST, $filter_summary);
|
||||
|
||||
$num_rows = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM app_logs WHERE $where"))[0]);
|
||||
|
||||
if ($num_rows > 0) {
|
||||
|
||||
guardExportPdfRowCount($format, $num_rows);
|
||||
|
||||
$export = beginExport('app_logs', $format, "$session_company_name-App-Logs", 'App Logs', summarizeExportFilters($filter_summary));
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT app_log_id, app_log_category, app_log_type, app_log_details, app_log_created_at FROM app_logs
|
||||
WHERE $where
|
||||
ORDER BY app_log_created_at DESC, app_log_id DESC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$row['app_log_type'] = appLogLevels()[appLogLevel($row['app_log_type'])]['one'];
|
||||
addExportRow($export, $row);
|
||||
}
|
||||
|
||||
finishExport($export);
|
||||
|
||||
logAudit("App Log", "Export", "$session_name exported $num_rows app log " . ($num_rows === 1 ? 'entry' : 'entries') . " to a " . strtoupper($format) . " file");
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
flashAlert('No app log entries match - nothing to export.', 'error');
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['clear_app_logs'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceAdminPermission();
|
||||
|
||||
// The ones shown, with the list's filters - or every one
|
||||
$all = ($_POST['scope'] ?? '') !== 'shown';
|
||||
$summary = [];
|
||||
$where = $all ? '1 = 1' : appLogFiltersSql($_POST, $summary);
|
||||
if (!$all && !$summary) {
|
||||
$all = true;
|
||||
}
|
||||
|
||||
mysqli_query($mysqli, "DELETE FROM app_logs WHERE $where");
|
||||
$cleared = mysqli_affected_rows($mysqli);
|
||||
|
||||
if ($cleared > 0) {
|
||||
$what = lcfirst(appLogFiltersText($summary));
|
||||
logAudit("App Log", "Delete", "$session_name cleared $cleared app log " . ($cleared === 1 ? 'entry' : 'entries') . ($all ? ' - all of them' : ' - ' . escapeSql($what)));
|
||||
flashAlert("Cleared $cleared app log " . ($cleared === 1 ? 'entry' : 'entries'));
|
||||
} else {
|
||||
flashAlert('There was nothing to clear.', 'error');
|
||||
}
|
||||
|
||||
redirect('app_logs.php');
|
||||
|
||||
}
|
||||
119
admin/post/settings_logs.php
Normal file
119
admin/post/settings_logs.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - POST handler for Admin > Settings > Logs: how long each log is
|
||||
* kept, and sending entries on to a syslog server or SIEM. Save and send a
|
||||
* test saves first, then sends one test message with what was saved
|
||||
* (logForwardTest(), functions/log_forward.php). What changed is in the audit
|
||||
* log.
|
||||
*/
|
||||
|
||||
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
|
||||
|
||||
if (isset($_POST['edit_log_settings']) || isset($_POST['test_log_forward'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
// Days, or 0 for keep forever
|
||||
$days = function ($name, $forever) {
|
||||
if (!empty($_POST[$forever])) {
|
||||
return 0;
|
||||
}
|
||||
return min(36500, max(1, intval($_POST[$name] ?? 90)));
|
||||
};
|
||||
$audit_days = $days('config_log_retention', 'audit_forever');
|
||||
$app_days = $days('config_app_log_retention', 'app_forever');
|
||||
|
||||
$was_retention = appLogRetention();
|
||||
$was = logForwardSettings();
|
||||
$posted_host = is_string($_POST['config_log_forward_host'] ?? null) ? trim($_POST['config_log_forward_host']) : '';
|
||||
$forward = logForwardTidy([
|
||||
'enabled' => $_POST['config_log_forward_enabled'] ?? 0,
|
||||
'host' => $posted_host,
|
||||
'port' => $_POST['config_log_forward_port'] ?? 514,
|
||||
'protocol' => $_POST['config_log_forward_protocol'] ?? 'udp',
|
||||
'format' => $_POST['config_log_forward_format'] ?? 'json',
|
||||
'audit' => $_POST['config_log_forward_audit'] ?? 0,
|
||||
'app_level' => $_POST['config_log_forward_app_level'] ?? '',
|
||||
// Only asked over TLS - kept as it was otherwise
|
||||
'tls_verify' => ($_POST['config_log_forward_protocol'] ?? '') === 'tls' ? ($_POST['config_log_forward_tls_verify'] ?? 0) : $was['tls_verify'],
|
||||
]);
|
||||
|
||||
// Nowhere to send to - saved, but off
|
||||
$warning = '';
|
||||
if ($posted_host !== '' && $forward['host'] === '') {
|
||||
$warning = "That isn't a server name or address, so sending stays off.";
|
||||
$forward['enabled'] = 0;
|
||||
} elseif ($forward['enabled'] && $forward['host'] === '') {
|
||||
$warning = 'Sending stays off until there is a server to send to.';
|
||||
$forward['enabled'] = 0;
|
||||
}
|
||||
|
||||
$host_sql = $forward['host'] !== '' ? "'" . escapeSql($forward['host']) . "'" : 'NULL';
|
||||
mysqli_query($mysqli, "UPDATE settings SET config_log_retention = $audit_days, config_app_log_retention = $app_days,
|
||||
config_log_forward_enabled = {$forward['enabled']}, config_log_forward_host = $host_sql, config_log_forward_port = {$forward['port']},
|
||||
config_log_forward_protocol = '{$forward['protocol']}', config_log_forward_format = '{$forward['format']}', config_log_forward_audit = {$forward['audit']},
|
||||
config_log_forward_app_level = '{$forward['app_level']}', config_log_forward_tls_verify = {$forward['tls_verify']}
|
||||
WHERE company_id = 1");
|
||||
|
||||
// What changed, in words
|
||||
$changes = [];
|
||||
if ($audit_days !== $was_retention['audit']) {
|
||||
$changes[] = 'the audit log kept ' . strtolower(appLogRetentionText($audit_days)) . ' (was ' . strtolower(appLogRetentionText($was_retention['audit'])) . ')';
|
||||
}
|
||||
if ($app_days !== $was_retention['app']) {
|
||||
$changes[] = 'app logs kept ' . strtolower(appLogRetentionText($app_days)) . ' (was ' . strtolower(appLogRetentionText($was_retention['app'])) . ')';
|
||||
}
|
||||
$target = function ($settings) {
|
||||
return logForwardTarget($settings) . ($settings['protocol'] === 'tls' && !$settings['tls_verify'] ? ' (certificate not checked)' : '');
|
||||
};
|
||||
$what = function ($settings) {
|
||||
return implode(' and ', array_filter([$settings['audit'] ? 'the audit log' : '', $settings['app_level'] !== '' ? 'app ' . strtolower(logForwardAppLevels()[$settings['app_level']]) : ''])) ?: 'nothing';
|
||||
};
|
||||
$on = logForwardOn($forward);
|
||||
$was_on = logForwardOn($was);
|
||||
if ($on && !$was_on) {
|
||||
$changes[] = 'sending logs to ' . $target($forward) . ' as ' . LOG_FORWARD_FORMATS[$forward['format']] . ' - ' . $what($forward);
|
||||
} elseif (!$on && $was_on) {
|
||||
$changes[] = 'stopped sending logs (was to ' . $target($was) . ')';
|
||||
} elseif ($on) {
|
||||
if ($target($forward) !== $target($was)) {
|
||||
$changes[] = 'sending logs to ' . $target($forward) . ' (was ' . $target($was) . ')';
|
||||
}
|
||||
if ($forward['format'] !== $was['format']) {
|
||||
$changes[] = 'sent as ' . LOG_FORWARD_FORMATS[$forward['format']] . ' (was ' . LOG_FORWARD_FORMATS[$was['format']] . ')';
|
||||
}
|
||||
if ($what($forward) !== $what($was)) {
|
||||
$changes[] = 'sending ' . $what($forward) . ' (was ' . $what($was) . ')';
|
||||
}
|
||||
}
|
||||
|
||||
// Read again, so what is logged from here on goes where it now should
|
||||
logForwardSettings(true);
|
||||
|
||||
if ($changes) {
|
||||
logAudit("Settings", "Edit", "$session_name edited log settings - " . escapeSql(implode('; ', $changes)));
|
||||
}
|
||||
|
||||
if (isset($_POST['test_log_forward'])) {
|
||||
if ($forward['host'] === '') {
|
||||
flashAlert($warning !== '' ? $warning : 'Give the server to send to first.', 'error');
|
||||
redirect();
|
||||
}
|
||||
$test = logForwardTest($forward, stripslashes($session_name));
|
||||
$target = logForwardTarget($forward);
|
||||
if ($test['ok']) {
|
||||
flashAlert(($forward['protocol'] === 'udp'
|
||||
? "Saved, and a test message went to $target. UDP doesn't say whether it arrived - check the server for it."
|
||||
: "Saved, and $target took the test message.") . ($forward['enabled'] ? '' : ' Sending is still off - switch it on to send entries.'));
|
||||
} else {
|
||||
flashAlert("Saved, but the test message couldn't be sent to $target - " . $test['error'] . '.', 'error');
|
||||
}
|
||||
redirect();
|
||||
}
|
||||
|
||||
flashAlert($warning !== '' ? "Log settings saved. $warning" : 'Log settings saved', $warning !== '' ? 'warning' : 'success');
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
@@ -10,7 +10,6 @@ if (isset($_POST['edit_security_settings'])) {
|
||||
$config_login_key_required = intval($_POST['config_login_key_required'] ?? 0);
|
||||
$config_login_key_secret = escapeSql($_POST['config_login_key_secret']);
|
||||
$config_login_remember_me_expire = intval($_POST['config_login_remember_me_expire']);
|
||||
$config_log_retention = intval($_POST['config_log_retention']);
|
||||
|
||||
// Shared links (functions/share.php) - only the lengths the share window offers
|
||||
$config_share_max_hours = intval($_POST['config_share_max_hours'] ?? 720);
|
||||
@@ -30,7 +29,7 @@ if (isset($_POST['edit_security_settings'])) {
|
||||
$config_login_key_required = 0;
|
||||
}
|
||||
|
||||
mysqli_query($mysqli,"UPDATE settings SET config_login_message = '$config_login_message', config_login_key_required = '$config_login_key_required', config_login_key_secret = '$config_login_key_secret', config_login_remember_me_expire = $config_login_remember_me_expire, config_log_retention = $config_log_retention, config_share_max_hours = $config_share_max_hours, config_share_require_protection = $config_share_require_protection, config_login_alert_failures = $config_login_alert_failures WHERE company_id = 1");
|
||||
mysqli_query($mysqli,"UPDATE settings SET config_login_message = '$config_login_message', config_login_key_required = '$config_login_key_required', config_login_key_secret = '$config_login_key_secret', config_login_remember_me_expire = $config_login_remember_me_expire, config_share_max_hours = $config_share_max_hours, config_share_require_protection = $config_share_require_protection, config_login_alert_failures = $config_login_alert_failures WHERE company_id = 1");
|
||||
|
||||
logAudit("Settings", "Edit", "$session_name edited security settings");
|
||||
|
||||
|
||||
@@ -1,146 +1,108 @@
|
||||
<?php
|
||||
|
||||
// Vendor Templates
|
||||
/*
|
||||
* Vendor templates (Admin > Vendor Templates) - making, changing (and the
|
||||
* fields ticked on the vendors made from it too), copying, archiving,
|
||||
* restoring and deleting them. The work is in functions/vendor_template.php;
|
||||
* a vendor is made from one by add_vendor, add_vendor_from_template and
|
||||
* add_vendor_template_to_clients (agent/post/vendor.php).
|
||||
*/
|
||||
|
||||
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
|
||||
|
||||
// Import shared code from user-side vendor management as we reuse functions
|
||||
require_once '../agent/post/vendor.php';
|
||||
/* The template a request is for - or back to the list, saying it is gone. */
|
||||
function vendorTemplateForRequest($vendor_template_id) {
|
||||
$row = vendorTemplateInfo($vendor_template_id);
|
||||
if (!$row) {
|
||||
flashAlert('That vendor template no longer exists.', 'error');
|
||||
redirect('vendor_templates.php');
|
||||
}
|
||||
return $row;
|
||||
}
|
||||
|
||||
if (isset($_POST['add_vendor_template'])) {
|
||||
if (isset($_POST['add_vendor_template']) || isset($_POST['edit_vendor_template'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$name = escapeSql($_POST['name']);
|
||||
$description = escapeSql($_POST['description']);
|
||||
$account_number = escapeSql($_POST['account_number']);
|
||||
$contact_name = escapeSql($_POST['contact_name']);
|
||||
$phone_country_code = preg_replace("/[^0-9]/", '', $_POST['phone_country_code']);
|
||||
$phone = preg_replace("/[^0-9]/", '', $_POST['phone']);
|
||||
$extension = preg_replace("/[^0-9]/", '', $_POST['extension']);
|
||||
$email = escapeSql($_POST['email']);
|
||||
$website = preg_replace("(^https?://)", "", escapeSql($_POST['website']));
|
||||
$hours = escapeSql($_POST['hours']);
|
||||
$sla = escapeSql($_POST['sla']);
|
||||
$code = escapeSql($_POST['code']);
|
||||
$notes = escapeSql($_POST['notes']);
|
||||
$editing = isset($_POST['edit_vendor_template']);
|
||||
$before = $editing ? vendorTemplateForRequest($_POST['vendor_template_id'] ?? 0) : null;
|
||||
$vendor_template_id = $before ? intval($before['vendor_template_id']) : 0;
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO vendor_templates SET vendor_template_name = '$name', vendor_template_description = '$description', vendor_template_contact_name = '$contact_name', vendor_template_phone_country_code = '$phone_country_code', vendor_template_phone = '$phone', vendor_template_extension = '$extension', vendor_template_email = '$email', vendor_template_website = '$website', vendor_template_hours = '$hours', vendor_template_sla = '$sla', vendor_template_code = '$code', vendor_template_account_number = '$account_number', vendor_template_notes = '$notes'");
|
||||
$fields = vendorTemplateFields($_POST, $error);
|
||||
if (!$fields) {
|
||||
flashAlert(escapeHtml($error), 'error');
|
||||
redirect();
|
||||
}
|
||||
$vendor_template_id = vendorTemplateSave($vendor_template_id, $fields);
|
||||
$name = $fields['name'];
|
||||
|
||||
$vendor_template_id = mysqli_insert_id($mysqli);
|
||||
if ($editing) {
|
||||
$changed = vendorTemplateChanged(vendorTemplateRowFields($before), $fields);
|
||||
$renamed = $before['vendor_template_name'] !== $name ? ' (was ' . $before['vendor_template_name'] . ')' : '';
|
||||
logAudit("Vendor Template", "Edit", "$session_name edited vendor template " . escapeSql($name . $renamed) . ($changed ? ' - ' . escapeSql(mb_strtolower(implode(', ', $changed))) : ''), 0, $vendor_template_id);
|
||||
|
||||
logAudit("Vendor Template", "Create", "$session_name created vendor template $name", 0, $vendor_template_id);
|
||||
// The fields ticked, on every vendor made from it too
|
||||
$labels = array_map(function ($field) {
|
||||
return $field['label'];
|
||||
}, vendorTemplateFieldLabels());
|
||||
$push = array_values(array_intersect(array_keys($labels), array_map('strval', array_filter((array) ($_POST['push'] ?? []), 'is_scalar'))));
|
||||
$pushed = $push ? vendorTemplatePush($vendor_template_id, $push) : [];
|
||||
$what = mb_strtolower(implode(', ', array_intersect_key($labels, array_flip($push))));
|
||||
foreach ($pushed as $vendor_id => $vendor) {
|
||||
logAudit("Vendor", "Edit", "$session_name updated vendor " . escapeSql($vendor['name']) . " from template " . escapeSql($name) . " - " . escapeSql($what), $vendor['client_id'], $vendor_id);
|
||||
}
|
||||
|
||||
flashAlert("Vendor template <strong>" . stripslashes($name) . "</strong> created");
|
||||
flashAlert("Vendor template <strong>" . escapeHtml($name) . "</strong> saved" . ($pushed ? ", and " . escapeHtml($what) . " changed on " . count($pushed) . " vendor" . (count($pushed) === 1 ? '' : 's') . " made from it" : ''));
|
||||
|
||||
redirect();
|
||||
redirect();
|
||||
}
|
||||
|
||||
// Made from one of a client's vendors - that vendor is now made from it
|
||||
$from_vendor = vendorRow($_POST['from_vendor'] ?? 0);
|
||||
if ($from_vendor) {
|
||||
mysqli_query($mysqli, "UPDATE vendors SET vendor_template_id = $vendor_template_id, vendor_updated_at = vendor_updated_at WHERE vendor_id = " . intval($from_vendor['vendor_id']));
|
||||
}
|
||||
|
||||
logAudit("Vendor Template", "Create", "$session_name created vendor template " . escapeSql($name) . ($from_vendor ? " from vendor " . escapeSql($from_vendor['vendor_name']) . ($from_vendor['client_name'] !== null ? " of " . escapeSql($from_vendor['client_name']) : '') : ''), 0, $vendor_template_id);
|
||||
|
||||
flashAlert("Vendor template <strong>" . escapeHtml($name) . "</strong> created");
|
||||
|
||||
// A new one opens on its page
|
||||
redirect("vendor_template.php?vendor_template_id=$vendor_template_id");
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['edit_vendor_template'])) {
|
||||
if (isset($_GET['copy_vendor_template'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$vendor_template_id = intval($_POST['vendor_template_id']);
|
||||
$name = escapeSql($_POST['name']);
|
||||
$description = escapeSql($_POST['description']);
|
||||
$account_number = escapeSql($_POST['account_number']);
|
||||
$contact_name = escapeSql($_POST['contact_name']);
|
||||
$phone_country_code = preg_replace("/[^0-9]/", '', $_POST['phone_country_code']);
|
||||
$phone = preg_replace("/[^0-9]/", '', $_POST['phone']);
|
||||
$extension = preg_replace("/[^0-9]/", '', $_POST['extension']);
|
||||
$email = escapeSql($_POST['email']);
|
||||
$website = preg_replace("(^https?://)", "", escapeSql($_POST['website']));
|
||||
$hours = escapeSql($_POST['hours']);
|
||||
$sla = escapeSql($_POST['sla']);
|
||||
$code = escapeSql($_POST['code']);
|
||||
$notes = escapeSql($_POST['notes']);
|
||||
$row = vendorTemplateForRequest($_GET['copy_vendor_template']);
|
||||
$new_id = vendorTemplateCopy($row['vendor_template_id']);
|
||||
$new_name = (string) vendorTemplateInfo($new_id)['vendor_template_name'];
|
||||
|
||||
if ($_POST['global_update_vendor_name'] == 1 ?? 0) {
|
||||
$sql_global_update_vendor_name = ", vendor_name = '$name'";
|
||||
} else {
|
||||
$sql_global_update_vendor_name = "";
|
||||
}
|
||||
logAudit("Vendor Template", "Create", "$session_name copied vendor template " . escapeSql($row['vendor_template_name']) . " as " . escapeSql($new_name), 0, $new_id);
|
||||
|
||||
if ($_POST['global_update_vendor_description'] == 1) {
|
||||
$sql_global_update_vendor_description = ", vendor_description = '$description'";
|
||||
} else {
|
||||
$sql_global_update_vendor_description = "";
|
||||
}
|
||||
flashAlert("Vendor template <strong>" . escapeHtml($row['vendor_template_name']) . "</strong> copied as <strong>" . escapeHtml($new_name) . "</strong>");
|
||||
|
||||
if ($_POST['global_update_vendor_account_number'] == 1) {
|
||||
$sql_global_update_vendor_account_number = ", vendor_account_number = '$account_number'";
|
||||
} else {
|
||||
$sql_global_update_vendor_account_number = "";
|
||||
}
|
||||
redirect("vendor_template.php?vendor_template_id=$new_id");
|
||||
|
||||
if ($_POST['global_update_vendor_contact_name'] == 1) {
|
||||
$sql_global_update_vendor_contact_name = ", vendor_contact_name = '$contact_name'";
|
||||
} else {
|
||||
$sql_global_update_vendor_contact_name = "";
|
||||
}
|
||||
}
|
||||
|
||||
if ($_POST['global_update_vendor_phone'] == 1) {
|
||||
$sql_global_update_vendor_phone = ", vendor_phone_country_code = '$phone_country_code', vendor_phone = '$phone', vendor_extension = '$extension'";
|
||||
} else {
|
||||
$sql_global_update_vendor_phone = "";
|
||||
}
|
||||
if (isset($_GET['archive_vendor_template']) || isset($_GET['restore_vendor_template'])) {
|
||||
|
||||
if ($_POST['global_update_vendor_hours'] == 1) {
|
||||
$sql_global_update_vendor_hours = ", vendor_hours = '$hours'";
|
||||
} else {
|
||||
$sql_global_update_vendor_hours = "";
|
||||
}
|
||||
validateCSRFToken();
|
||||
|
||||
if ($_POST['global_update_vendor_email'] == 1) {
|
||||
$sql_global_update_vendor_email = ", vendor_email = '$email'";
|
||||
} else {
|
||||
$sql_global_update_vendor_email = "";
|
||||
}
|
||||
$archive = isset($_GET['archive_vendor_template']);
|
||||
$row = vendorTemplateForRequest($archive ? $_GET['archive_vendor_template'] : $_GET['restore_vendor_template']);
|
||||
$vendor_template_id = intval($row['vendor_template_id']);
|
||||
|
||||
if ($_POST['global_update_vendor_website'] == 1) {
|
||||
$sql_global_update_vendor_website = ", vendor_website = '$website'";
|
||||
} else {
|
||||
$sql_global_update_vendor_website = "";
|
||||
}
|
||||
// Archived, it isn't offered for new vendors; the ones made from it stay
|
||||
mysqli_query($mysqli, "UPDATE vendor_templates SET vendor_template_archived_at = " . ($archive ? 'NOW()' : 'NULL') . ", vendor_template_updated_at = vendor_template_updated_at
|
||||
WHERE vendor_template_id = $vendor_template_id");
|
||||
|
||||
if ($_POST['global_update_vendor_sla'] == 1) {
|
||||
$sql_global_update_vendor_sla = ", vendor_sla = '$sla'";
|
||||
} else {
|
||||
$sql_global_update_vendor_sla = "";
|
||||
}
|
||||
logAudit("Vendor Template", $archive ? "Archive" : "Restore", "$session_name " . ($archive ? 'archived' : 'restored') . " vendor template " . escapeSql($row['vendor_template_name']), 0, $vendor_template_id);
|
||||
|
||||
if ($_POST['global_update_vendor_code'] == 1) {
|
||||
$sql_global_update_vendor_code = ", vendor_code = '$code'";
|
||||
} else {
|
||||
$sql_global_update_vendor_code = "";
|
||||
}
|
||||
|
||||
if ($_POST['global_update_vendor_notes'] == 1) {
|
||||
$sql_global_update_vendor_notes = ", vendor_notes = '$notes'";
|
||||
} else {
|
||||
$sql_global_update_vendor_notes = "";
|
||||
}
|
||||
|
||||
// Update just the template
|
||||
mysqli_query($mysqli,"UPDATE vendor_templates SET vendor_template_name = '$name', vendor_template_description = '$description', vendor_template_contact_name = '$contact_name', vendor_template_phone_country_code = '$phone_country_code', vendor_template_phone = '$phone', vendor_template_extension = '$extension', vendor_template_email = '$email', vendor_template_website = '$website', vendor_template_hours = '$hours', vendor_template_sla = '$sla', vendor_template_code = '$code', vendor_template_account_number = '$account_number', vendor_template_notes = '$notes' WHERE vendor_template_id = $vendor_template_id");
|
||||
|
||||
if ($_POST['update_base_vendors'] == 1) {
|
||||
// Update client related vendors if anything is checked
|
||||
$sql = "$sql_global_update_vendor_name $sql_global_update_vendor_description $sql_global_update_vendor_account_number $sql_global_update_vendor_contact_name $sql_global_update_vendor_phone $sql_global_update_vendor_hours $sql_global_update_vendor_email $sql_global_update_vendor_website $sql_global_update_vendor_sla $sql_global_update_vendor_code $sql_global_update_vendor_notes";
|
||||
|
||||
// Remove the first comma to prevent MySQL error
|
||||
$sql = preg_replace('/,/', '', $sql, 1);
|
||||
|
||||
// Nothing ticked to push - nothing to update, rather than an empty SET
|
||||
if (trim($sql) !== '') {
|
||||
mysqli_query($mysqli,"UPDATE vendors SET $sql WHERE vendor_template_id = $vendor_template_id");
|
||||
}
|
||||
}
|
||||
|
||||
logAudit("Vendor Template", "Edit", "$session_name edited vendor template $name", 0, $vendor_template_id);
|
||||
|
||||
flashAlert("Vendor template <strong>" . stripslashes($name) . "</strong> saved");
|
||||
flashAlert("Vendor template <strong>" . escapeHtml($row['vendor_template_name']) . "</strong> " . ($archive ? 'archived' : 'restored'), $archive ? 'error' : 'success');
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -150,22 +112,16 @@ if (isset($_GET['delete_vendor_template'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$vendor_template_id = intval($_GET['delete_vendor_template']);
|
||||
$row = vendorTemplateForRequest($_GET['delete_vendor_template']);
|
||||
|
||||
$vendor_template_name = escapeSql(getFieldById('vendor_templates', $vendor_template_id, 'vendor_template_name'));
|
||||
// The vendors made from it stay, no longer linked to it
|
||||
vendorTemplateDelete($row['vendor_template_id']);
|
||||
|
||||
// If its a template reset all vendors based off this template to no template base
|
||||
mysqli_query($mysqli,"UPDATE vendors SET vendor_template_id = 0 WHERE vendor_template_id = $vendor_template_id");
|
||||
logAudit("Vendor Template", "Delete", "$session_name deleted vendor template " . escapeSql($row['vendor_template_name']), 0, intval($row['vendor_template_id']));
|
||||
|
||||
// License templates that took their vendor from it no longer have one
|
||||
mysqli_query($mysqli, "UPDATE software_templates SET software_template_vendor_template_id = 0, software_template_updated_at = software_template_updated_at WHERE software_template_vendor_template_id = $vendor_template_id");
|
||||
flashAlert("Vendor template <strong>" . escapeHtml($row['vendor_template_name']) . "</strong> deleted", 'error');
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM vendor_templates WHERE vendor_template_id = $vendor_template_id");
|
||||
|
||||
logAudit("Vendor Template", "Delete", "$session_name deleted vendor template $vendor_template_name");
|
||||
|
||||
flashAlert("Vendor template <strong>" . stripslashes($vendor_template_name) . "</strong> deleted", 'error');
|
||||
|
||||
redirect();
|
||||
// From its own page, back to the list
|
||||
redirect(!empty($_GET['from_page']) ? 'vendor_templates.php' : null);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user