}
} else {
    $res = hesk_dbQuery("SELECT `priority` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "categories` WHERE `id`=" . intval($tmpvar['category']));
    if (hesk_dbNumRows($res) == 1) {
        $tmpvar['priority'] = intval(hesk_dbResult($res));
    } else {
        $tmpvar['priority'] = 3;
    }
}
$tmpvar['subject'] = hesk_input(hesk_POST('subject')) or $hesk_error_buffer['subject'] = $hesklang['enter_ticket_subject'];
$tmpvar['message'] = hesk_input(hesk_POST('message')) or $hesk_error_buffer['message'] = $hesklang['enter_message'];
$tmpvar['contract_ticket_id'] = hesk_input(hesk_POST('contract_name'));
$tmpvar['company_ticket_id'] = hesk_input(hesk_POST('company_name'));
// Is category a valid choice?
if ($tmpvar['category']) {
    hesk_verifyCategory();
    // Is auto-assign of tickets disabled in this category?
    if (empty($hesk_settings['category_data'][$tmpvar['category']]['autoassign'])) {
        $hesk_settings['autoassign'] = false;
    }
}
// Custom fields
foreach ($hesk_settings['custom_fields'] as $k => $v) {
    if ($v['use']) {
        if ($v['type'] == 'checkbox') {
            $tmpvar[$k] = '';
            if (isset($_POST[$k])) {
                if (is_array($_POST[$k])) {
                    foreach ($_POST[$k] as $myCB) {
                        $tmpvar[$k] .= (is_array($myCB) ? '' : hesk_input($myCB)) . '<br />';
                    }
$tmpvar['priority'] = hesk_POST('priority');
$tmpvar['priority'] = strlen($tmpvar['priority']) ? intval($tmpvar['priority']) : -1;
if ($tmpvar['priority'] < 0 || $tmpvar['priority'] > 3) {
    // If we are showing "Click to select" priority needs to be selected
    if ($hesk_settings['select_pri']) {
        $tmpvar['priority'] = -1;
        $hesk_error_buffer['priority'] = $hesklang['select_priority'];
    } else {
        $tmpvar['priority'] = 3;
    }
}
$tmpvar['subject'] = hesk_input(hesk_POST('subject')) or $hesk_error_buffer['subject'] = $hesklang['enter_ticket_subject'];
$tmpvar['message'] = hesk_input(hesk_POST('message')) or $hesk_error_buffer['message'] = $hesklang['enter_message'];
// Is category a valid choice?
if ($tmpvar['category']) {
    hesk_verifyCategory(1);
    // Is auto-assign of tickets disabled in this category?
    if (empty($hesk_settings['category_data'][$tmpvar['category']]['autoassign'])) {
        $hesk_settings['autoassign'] = false;
    }
}
// Custom fields
foreach ($hesk_settings['custom_fields'] as $k => $v) {
    if ($v['use'] && isset($_POST[$k])) {
        if (is_array($_POST[$k])) {
            $tmpvar[$k] = '';
            foreach ($_POST[$k] as $myCB) {
                $tmpvar[$k] .= (is_array($myCB) ? '' : hesk_input($myCB)) . '<br />';
            }
            $tmpvar[$k] = substr($tmpvar[$k], 0, -6);
        } else {