mirror of
https://github.com/itflow-org/itflow
synced 2026-02-28 19:04:52 +00:00
Migrated Vendor Templates to its own table, lots of code modifications here
This commit is contained in:
@@ -9,14 +9,26 @@ require_once 'post/user/vendor.php';
|
||||
|
||||
if (isset($_POST['add_vendor_template'])) {
|
||||
|
||||
require_once 'post/user/vendor_model.php';
|
||||
$name = sanitizeInput($_POST['name']);
|
||||
$description = sanitizeInput($_POST['description']);
|
||||
$account_number = sanitizeInput($_POST['account_number']);
|
||||
$contact_name = sanitizeInput($_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 = sanitizeInput($_POST['email']);
|
||||
$website = preg_replace("(^https?://)", "", sanitizeInput($_POST['website']));
|
||||
$hours = sanitizeInput($_POST['hours']);
|
||||
$sla = sanitizeInput($_POST['sla']);
|
||||
$code = sanitizeInput($_POST['code']);
|
||||
$notes = sanitizeInput($_POST['notes']);
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO vendors SET vendor_name = '$name', vendor_description = '$description', vendor_contact_name = '$contact_name', vendor_phone = '$phone', vendor_extension = '$extension', vendor_email = '$email', vendor_website = '$website', vendor_hours = '$hours', vendor_sla = '$sla', vendor_code = '$code', vendor_account_number = '$account_number', vendor_notes = '$notes', vendor_template = 1, vendor_client_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 = '$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'");
|
||||
|
||||
$vendor_id = mysqli_insert_id($mysqli);
|
||||
$vendor_template_id = mysqli_insert_id($mysqli);
|
||||
|
||||
// Logging
|
||||
logAction("Vendor Template", "Create", "$session_name created vendor template $name", 0, $vendor_id);
|
||||
logAction("Vendor Template", "Create", "$session_name created vendor template $name", 0, $vendor_template_id);
|
||||
|
||||
$_SESSION['alert_message'] = "Vendor template <strong>$name</strong> created";
|
||||
|
||||
@@ -25,10 +37,20 @@ if (isset($_POST['add_vendor_template'])) {
|
||||
|
||||
if (isset($_POST['edit_vendor_template'])) {
|
||||
|
||||
require_once 'post/user/vendor_model.php';
|
||||
|
||||
$vendor_id = intval($_POST['vendor_id']);
|
||||
$vendor_template_id = intval($_POST['vendor_template_id']);
|
||||
$name = sanitizeInput($_POST['name']);
|
||||
$description = sanitizeInput($_POST['description']);
|
||||
$account_number = sanitizeInput($_POST['account_number']);
|
||||
$contact_name = sanitizeInput($_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 = sanitizeInput($_POST['email']);
|
||||
$website = preg_replace("(^https?://)", "", sanitizeInput($_POST['website']));
|
||||
$hours = sanitizeInput($_POST['hours']);
|
||||
$sla = sanitizeInput($_POST['sla']);
|
||||
$code = sanitizeInput($_POST['code']);
|
||||
$notes = sanitizeInput($_POST['notes']);
|
||||
|
||||
if ($_POST['global_update_vendor_name'] == 1) {
|
||||
$sql_global_update_vendor_name = ", vendor_name = '$name'";
|
||||
@@ -97,7 +119,7 @@ if (isset($_POST['edit_vendor_template'])) {
|
||||
}
|
||||
|
||||
// Update just the template
|
||||
mysqli_query($mysqli,"UPDATE vendors SET vendor_name = '$name', vendor_description = '$description', vendor_contact_name = '$contact_name', vendor_phone = '$phone', vendor_extension = '$extension', vendor_email = '$email', vendor_website = '$website', vendor_hours = '$hours', vendor_sla = '$sla', vendor_code = '$code', vendor_account_number = '$account_number', vendor_notes = '$notes' WHERE vendor_id = $vendor_id");
|
||||
mysqli_query($mysqli,"UPDATE vendor_templates SET vendor_template_name = '$name', vendor_template_description = '$description', vendor_template_contact_name = '$contact_name', 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
|
||||
@@ -106,7 +128,7 @@ if (isset($_POST['edit_vendor_template'])) {
|
||||
// Remove the first comma to prevent MySQL error
|
||||
$sql = preg_replace('/,/', '', $sql, 1);
|
||||
|
||||
mysqli_query($mysqli,"UPDATE vendors SET $sql WHERE vendor_template_id = $vendor_id");
|
||||
mysqli_query($mysqli,"UPDATE vendors SET $sql WHERE vendor_template_id = $vendor_template_id");
|
||||
}
|
||||
|
||||
// Logging
|
||||
@@ -116,3 +138,25 @@ if (isset($_POST['edit_vendor_template'])) {
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
}
|
||||
|
||||
if (isset($_GET['delete_vendor_template'])) {
|
||||
$vendor_template_id = intval($_GET['delete_vendor_template']);
|
||||
|
||||
//Get Vendor Template Name
|
||||
$sql = mysqli_query($mysqli,"SELECT vendor_template_name FROM vendor_templates WHERE vendor_template_id = $vendor_template_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$vendor_template_name = sanitizeInput($row['vendor_template_name']);
|
||||
|
||||
// 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");
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM vendor_templates WHERE vendor_template_id = $vendor_template_id");
|
||||
|
||||
// Logging
|
||||
logAction("Vendor Template", "Delete", "$session_name deleted vendor template $vendor_template_name");
|
||||
|
||||
$_SESSION['alert_type'] = "error";
|
||||
$_SESSION['alert_message'] = "Vendor Template <strong>$vendor_template_name</strong> deleted";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user