184 lines
6.5 KiB
PHP
184 lines
6.5 KiB
PHP
<?
|
|
date_default_timezone_set('Europe/Berlin');
|
|
|
|
$messages = array();
|
|
$error = FALSE;
|
|
|
|
|
|
if (isset($custom_action)) {
|
|
$action = $custom_action;
|
|
} else {
|
|
$action = $_REQUEST["action"];
|
|
}
|
|
|
|
switch ($action) {
|
|
case 'close_process':
|
|
require_once("process_listform.inc.php");
|
|
break;
|
|
case 'load_process':
|
|
require_once("process_listform.inc.php");
|
|
break;
|
|
case 'new_process' :
|
|
require_once("process_cardform.inc.php");
|
|
break;
|
|
case 'edit':
|
|
edit_process();
|
|
break;
|
|
case 'delete_process':
|
|
delete_process();
|
|
break;
|
|
case 'save_process':
|
|
save_process();
|
|
break;
|
|
default:
|
|
require_once("process_listform.inc.php");
|
|
break;
|
|
}
|
|
|
|
function edit_process($_id = "") {
|
|
if ((int)$_id > 0) {
|
|
$process_id = $_id;
|
|
} else {
|
|
$process_id = $_REQUEST["input_process_id"];
|
|
}
|
|
if ($process_id <> '') {
|
|
$query = "SELECT * FROM main_tickets_process WHERE id = '" . $process_id . "' LIMIT 1";
|
|
$result = @mysqli_query($GLOBALS['mysql_con'], $query);
|
|
|
|
if (@mysqli_num_rows($result) == 1) {
|
|
$input_process = @mysqli_fetch_array($result);
|
|
require_once("process_cardform.inc.php");
|
|
}
|
|
} else {
|
|
require_once("process_cardform.inc.php");
|
|
}
|
|
}
|
|
|
|
function save_process() {
|
|
$translation = \DynCom\mysyde\common\classes\Registry::get("translation");
|
|
$inserted = FALSE;
|
|
$messages = array();
|
|
|
|
// var_dump($_POST["input_process_id"] );
|
|
// die();
|
|
|
|
if ($_POST["input_process_id"] != '') {
|
|
$query = "UPDATE main_tickets_process SET
|
|
description = '" . mysqli_real_escape_string($GLOBALS['mysql_con'], $_REQUEST["input_description"]) . "'
|
|
WHERE id = '" . $_REQUEST["input_process_id"] . "' LIMIT 1";
|
|
|
|
|
|
$inserted = TRUE;
|
|
} else {
|
|
|
|
|
|
// $sorting = @mysqli_fetch_array(@mysqli_query($GLOBALS['mysql_con'], "SELECT MAX(sorting)+1 AS 'newsorting' FROM main_tickets_process"));
|
|
// $sorting = ($sorting["newsorting"] <> "") ? $sorting = $sorting["newsorting"] : $sorting = 1;
|
|
$query = "INSERT INTO main_tickets_process (description) VALUES ('" . $_REQUEST["input_description"] . "')";
|
|
|
|
$inserted = TRUE;
|
|
|
|
}
|
|
|
|
@mysqli_query($GLOBALS['mysql_con'], $query);
|
|
|
|
if ($inserted == TRUE) {
|
|
$input_id = mysqli_insert_id($GLOBALS['mysql_con']);
|
|
// If it's an update, use the existing ID
|
|
$process_id = $_REQUEST["input_process_id"] != '' ? $_REQUEST["input_process_id"] : $input_id;
|
|
|
|
// Save process statuses
|
|
save_process_statuses($process_id);
|
|
|
|
$messages[] = '<div class="successbox">' . $translation->get("msg_success") . '</div>';
|
|
} else {
|
|
$messages[] = '<div class="successbox">' . $translation->get("msg_error") . '</div>';
|
|
}
|
|
|
|
if ($_REQUEST['save_and_close'] == 1) {
|
|
require_once("process_listform.inc.php");
|
|
} else {
|
|
edit_process($input_id);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Save process statuses
|
|
*
|
|
* This function saves selected statuses for a process. Statuses 0, 1, 2, 3 are
|
|
* always included with sorting values 0, 1, 2, 999 respectively. User-selected
|
|
* statuses have sorting values between 3 and 998.
|
|
*
|
|
* @param int $process_id The ID of the process
|
|
* @return bool True on success, false on failure
|
|
*/
|
|
function save_process_statuses($process_id) {
|
|
if (empty($process_id)) {
|
|
return false;
|
|
}
|
|
|
|
// Delete existing process status associations
|
|
$delete_query = "DELETE FROM main_tickets_process_status WHERE main_tickets_process_id = '" .
|
|
mysqli_real_escape_string($GLOBALS['mysql_con'], $process_id) . "'";
|
|
mysqli_query($GLOBALS['mysql_con'], $delete_query);
|
|
|
|
// Add mandatory statuses with fixed sorting values
|
|
$mandatory_statuses = [
|
|
['id' => 0, 'sorting' => 0],
|
|
['id' => 1, 'sorting' => 1],
|
|
['id' => 2, 'sorting' => 2],
|
|
['id' => 3, 'sorting' => 999]
|
|
];
|
|
|
|
foreach ($mandatory_statuses as $status) {
|
|
$insert_query = "INSERT INTO main_tickets_process_status
|
|
(main_tickets_process_id, main_tickets_status_id, sorting)
|
|
VALUES (
|
|
'" . mysqli_real_escape_string($GLOBALS['mysql_con'], $process_id) . "',
|
|
'" . mysqli_real_escape_string($GLOBALS['mysql_con'], $status['id']) . "',
|
|
'" . mysqli_real_escape_string($GLOBALS['mysql_con'], $status['sorting']) . "'
|
|
)";
|
|
mysqli_query($GLOBALS['mysql_con'], $insert_query);
|
|
}
|
|
|
|
// Process user-selected statuses
|
|
if (isset($_REQUEST['selected_statuses']) && !empty($_REQUEST['selected_statuses'])) {
|
|
$selected_statuses = json_decode($_REQUEST['selected_statuses'], true);
|
|
|
|
if (is_array($selected_statuses) && count($selected_statuses) > 0) {
|
|
// Start sorting from 3
|
|
$sort_offset = 3;
|
|
|
|
foreach ($selected_statuses as $index => $status) {
|
|
// Skip mandatory statuses if they somehow got included
|
|
if (in_array($status['id'], [0, 1, 2, 3])) {
|
|
continue;
|
|
}
|
|
|
|
// Calculate sorting (between 3 and 998)
|
|
$sorting = min(998, $sort_offset + $index);
|
|
|
|
$insert_query = "INSERT INTO main_tickets_process_status
|
|
(main_tickets_process_id, main_tickets_status_id, sorting)
|
|
VALUES (
|
|
'" . mysqli_real_escape_string($GLOBALS['mysql_con'], $process_id) . "',
|
|
'" . mysqli_real_escape_string($GLOBALS['mysql_con'], $status['id']) . "',
|
|
'" . mysqli_real_escape_string($GLOBALS['mysql_con'], $sorting) . "'
|
|
)";
|
|
mysqli_query($GLOBALS['mysql_con'], $insert_query);
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
function delete_process() {
|
|
if ($_REQUEST["input_process_id"] <> '') {
|
|
$query = "DELETE FROM main_tickets_process WHERE id = '" . $_REQUEST["input_process_id"]."'";
|
|
@mysqli_query($GLOBALS['mysql_con'], $query);
|
|
}
|
|
require_once("process_listform.inc.php");
|
|
}
|
|
|