= 100; // Did we reach the custom statuses limit? if ($reached_status_limit && $action !== 'edit_status') { hesk_show_info($hesklang['status_limit']); } ?>

$status) { $status['span'] = isset($status['class']) ? '' : ''; $status['color'] = isset($status['class']) ? $status['span'] . '.' . $status['class'] . '' : $status['span'] . $status['color'] . ''; $status['tickets'] = isset($tickets_all[$tmp_id]) ? $tickets_all[$tmp_id] : 0; $status['can_customers_change'] = ! isset($status['can_customers_change']) ? '' : ($status['can_customers_change'] == 1 ? $hesklang['yes'] : $hesklang['no']); if (!$is_custom && $tmp_id > 5) { $is_custom = true; echo ' '; } $table_row = ''; if (isset($_SESSION['statusord']) && $_SESSION['statusord'] == $tmp_id) { $table_row = 'class="ticket-new"'; unset($_SESSION['statusord']); } ?> >
' . $hesklang['status_custom'] . '

0): ?>

>

'; hesk_handle_messages(); echo '
'; } $names = hesk_SESSION(array('new_status','names')); $errors = hesk_SESSION(array('new_status','errors')); $errors = is_array($errors) ? $errors : array(); if ($hesk_settings['can_sel_lang'] && count($hesk_settings['languages']) > 1) { echo '

' . $hesklang['status'] . '

'; foreach ($hesk_settings['languages'] as $lang => $info) { ?>
$error\n"; } $hesk_error_buffer = $tmp; $hesk_error_buffer = $hesklang['rfm'].'

'; hesk_process_messages($hesk_error_buffer,'custom_statuses.php'); } // Remove # from color $color = str_replace('#', '', $status['color']); // Add custom status data into database hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_statuses` SET `name` = '".hesk_dbEscape($status['names'])."', `color` = '{$color}', `can_customers_change` = '{$status['can_customers_change']}' WHERE `id`={$id}"); // Clear cache hesk_purge_cache('status'); // Show success $_SESSION['statusord'] = $id; hesk_process_messages($hesklang['status_mdf'],'custom_statuses.php','SUCCESS'); } // End save_status() function edit_status() { global $hesk_settings, $hesklang; // Get custom status ID $id = intval( hesk_GET('id') ) or hesk_error($hesklang['status_e_id']); // Get details from the database $res = hesk_dbQuery("SELECT * FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_statuses` WHERE `id`={$id} LIMIT 1"); if ( hesk_dbNumRows($res) != 1 ) { hesk_error($hesklang['status_not_found']); } $status = hesk_dbFetchAssoc($res); $status['names'] = json_decode($status['name'], true); unset($status['name']); $status['color'] = '#'.$status['color']; $_SESSION['new_status'] = $status; $_SESSION['edit_status'] = true; } // End edit_status() function update_status_order() { global $hesk_settings, $hesklang; // Get list of current custom statuses $res = hesk_dbQuery("SELECT `id` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_statuses` ORDER BY `order` ASC"); // Update database $i = 10; while ( $status = hesk_dbFetchAssoc($res) ) { hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_statuses` SET `order`=".intval($i)." WHERE `id`='".intval($status['id'])."'"); $i += 10; } return true; } // END update_status_order() function remove_status() { global $hesk_settings, $hesklang; // A security check hesk_token_check(); // Get ID $id = intval( hesk_GET('id') ) or hesk_error($hesklang['status_e_id']); // Any tickets with this status? $res = hesk_dbQuery("SELECT COUNT(*) AS `cnt`, `status` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` WHERE `status` = {$id}"); if (hesk_dbResult($res) > 0) { hesk_process_messages($hesklang['status_not_empty'],'./custom_statuses.php'); } // Reset the custom status hesk_dbQuery("DELETE FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_statuses` WHERE `id`={$id}"); // Were we successful? if ( hesk_dbAffectedRows() == 1 ) { // Update order update_status_order(); // Clear cache hesk_purge_cache('status'); // Delete custom status data from tickets hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` SET `custom{$id}`=''"); // Show success message hesk_process_messages($hesklang['status_deleted'],'./custom_statuses.php','SUCCESS'); } else { hesk_process_messages($hesklang['status_not_found'],'./custom_statuses.php'); } } // End remove_status() function status_validate() { global $hesk_settings, $hesklang; global $hesk_error_buffer; $hesk_error_buffer = array(); // Get names $status['names'] = hesk_POST_array('name'); // Make sure only valid names pass foreach ($status['names'] as $key => $name) { if ( ! isset($hesk_settings['languages'][$key])) { unset($status['names'][$key]); } else { $name = is_array($name) ? '' : hesk_input($name, 0, 0, HESK_SLASH); if (strlen($name) < 1) { unset($status['names'][$key]); } else { $status['names'][$key] = stripslashes($name); } } } // No name entered? $errors = array(); if ( ! count($status['names'])) { $hesk_error_buffer[] = $hesklang['err_status']; $errors[] = 'names'; } // Color $status['color'] = hesk_validate_color_hex(hesk_POST('color')); // Can customers change it? $status['can_customers_change'] = hesk_POST('can_customers_change') ? 1 : 0; // Any errors? if (count($hesk_error_buffer)) { $_SESSION['new_status'] = $status; $_SESSION['new_status']['errors'] = $errors; return false; } $status['names'] = addslashes(json_encode($status['names'])); return $status; } // END status_validate() function new_status() { global $hesk_settings, $hesklang; global $hesk_error_buffer; // A security check # hesk_token_check('POST'); // Validate inputs if (($status = status_validate()) == false) { $tmp = ''; foreach ($hesk_error_buffer as $error) { $tmp .= "
  • $error
  • \n"; } $hesk_error_buffer = $tmp; $hesk_error_buffer = $hesklang['rfm'].'

    '; hesk_process_messages($hesk_error_buffer,'custom_statuses.php'); } // Did we reach status limit? if (count($hesk_settings['statuses']) >= 100) { hesk_process_messages($hesklang['status_limit'],'custom_statuses.php'); } // Lowest available ID for custom statuses is 6 $next_id = 6; // Any existing statuses? if (count($hesk_settings['statuses']) > 6) { // The lowest currently used ID $res = hesk_dbQuery("SELECT `id` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_statuses` ORDER BY `id` ASC LIMIT 1"); $lowest_id = hesk_dbResult($res); if ($lowest_id > 6) { $next_id = 6; } else { // Minimum next ID $res = hesk_dbQuery(" SELECT MIN(`t1`.`id` + 1) FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_statuses` AS `t1` LEFT JOIN `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_statuses` AS `t2` ON `t1`.`id` + 1 = `t2`.`id` WHERE `t2`.`id` IS NULL" ); $next_id = hesk_dbResult($res); } } // Remove # from color $color = str_replace('#', '', $status['color']); // Insert custom status into database hesk_dbQuery("INSERT INTO `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_statuses` (`id`, `name`, `color`, `can_customers_change`, `order`) VALUES (".intval($next_id).", '".hesk_dbEscape($status['names'])."', '{$color}', '{$status['can_customers_change']}', 990)"); // Update order update_status_order(); // Clear cache hesk_purge_cache('status'); $_SESSION['statusord'] = $next_id; // Show success hesk_process_messages($hesklang['status_added'],'custom_statuses.php','SUCCESS'); } // End new_status() function hesk_validate_color_hex($hex, $def = '#000000') { $hex = strtolower($hex); return preg_match('/^\#[a-f0-9]{6}$/', $hex) ? $hex : $def; } // END hesk_validate_color_hex() function hesk_get_text_color($bg_color) { // Get RGB values list($r, $g, $b) = sscanf($bg_color, "#%02x%02x%02x"); // Is Black a good text color? if (hesk_color_diff($r, $g, $b, 0, 0, 0) >= 500) { return '#000000'; } // Use white instead return '#ffffff'; } // END hesk_get_text_color() function hesk_color_diff($R1,$G1,$B1,$R2,$G2,$B2) { return max($R1,$R2) - min($R1,$R2) + max($G1,$G2) - min($G1,$G2) + max($B1,$B2) - min($B1,$B2); } // END hesk_color_diff()