diff --git a/.gitignore b/.gitignore index 3317dca5..866d200a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,13 @@ admin/admin_suggest_articles.php admin/archive.php +admin/custom_statuses.php +admin/email_templates.php admin/generate_spam_question.php admin/priority.php admin/test_connection.php attachments/index.htm -docs/changelog.html -docs/docs_style.css -docs/index.html -docs/quick-guide.html -docs/step-by-step-guide.html +cache/ +docs/ file_limits.php footer.txt header.txt @@ -27,6 +26,7 @@ img/clip.png img/code.png img/code_off.png img/delete.png +img/delete_off.png img/delete_ticket.png img/edit.png img/error.png @@ -114,6 +114,7 @@ img/print.png img/private.png img/public.png img/reload.png +img/refresh.png img/roundcornersb.jpg img/roundcornerslb.jpg img/roundcornerslm.jpg @@ -156,10 +157,11 @@ inc/calendar/tcal.js inc/calendar/tcal.php inc/database.inc.php inc/database_mysqli.inc.php -inc/footer.inc.php inc/htmlpurifier inc/index.htm +inc/jscolor/ inc/mail/email_parser.php +inc/mail/hesk_imap.php inc/mail/hesk_pipe.php inc/mail/hesk_pop3.php inc/mail/index.htm @@ -184,6 +186,7 @@ inc/recaptcha/recaptchalib.php inc/reporting_functions.inc.php inc/secimg.inc.php inc/setup_functions.inc.php +inc/statuses.inc.php inc/tabs/index.htm inc/tabs/tabber-minimized.js inc/tabs/tabber.css diff --git a/admin/admin_main.php b/admin/admin_main.php index b5d53cdd..0d466735 100644 --- a/admin/admin_main.php +++ b/admin/admin_main.php @@ -51,6 +51,7 @@ hesk_isLoggedIn(); define('CALENDAR', 1); define('MAIN_PAGE', 1); define('PAGE_TITLE', 'ADMIN_HOME'); +define('AUTO_RELOAD', 1); /* Print header */ require_once(HESK_PATH . 'inc/headerAdmin.inc.php'); @@ -58,7 +59,7 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php'); /* Reset default settings? */ if (isset($_GET['reset']) && hesk_token_check()) { - $res = hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` SET `default_list`='' WHERE `id` = '" . intval($_SESSION['id']) . "' LIMIT 1"); + $res = hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` SET `default_list`='' WHERE `id` = '" . intval($_SESSION['id']) . "'"); $_SESSION['default_list'] = ''; } /* Get default settings */ else { @@ -81,6 +82,14 @@ else {
+
+ +
+
-
-
- -
-
+ /* Clean unneeded session variables */ + hesk_cleanSessionVars('hide'); + ?> If locked, keep it resolved if ($ticket['locked']) { $new_status = $lockedTicketStatus['ID']; @@ -248,7 +254,7 @@ if ($ticket['locked']) { $newStatusRs = hesk_dbQuery('SELECT `IsClosed`, `Key` FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'statuses` WHERE `ID` = ' . hesk_dbEscape($new_status)); $newStatus = hesk_dbFetchAssoc($newStatusRs); - if ($newStatus['IsClosed']) { + if ($newStatus['IsClosed'] && hesk_checkPermission('can_resolve', 0)) { $revision = sprintf($hesklang['thist3'], hesk_date(), $_SESSION['name'] . ' (' . $_SESSION['user'] . ')'); $sql_status = " , `closedat`=NOW(), `closedby`=" . intval($_SESSION['id']) . ", `history`=CONCAT(`history`,'" . hesk_dbEscape($revision) . "') "; @@ -257,7 +263,7 @@ if ($ticket['locked']) { $sql_status .= " , `locked`='1' "; } } else { - // Ticket isn't being closed, just add the history to the sql query + // Ticket isn't being closed, just add the history to the sql query (or tried to close but doesn't have permission) $revision = sprintf($hesklang['thist9'], hesk_date(), $hesklang[$newStatus['Key']], $_SESSION['name'] . ' (' . $_SESSION['user'] . ')'); $sql_status = " , `history`=CONCAT(`history`,'" . hesk_dbEscape($revision) . "') "; } @@ -310,12 +316,12 @@ $sql .= " , `replies`=`replies`+1 "; $sql .= $submit_as_customer ? '' : " , `staffreplies`=`staffreplies`+1 "; // End and execute the query -$sql .= " WHERE `id`='{$replyto}' LIMIT 1"; +$sql .= " WHERE `id`='{$replyto}'"; hesk_dbQuery($sql); unset($sql); /* Update number of replies in the users table */ -hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` SET `replies`=`replies`+1 WHERE `id`='" . intval($_SESSION['id']) . "' LIMIT 1"); +hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` SET `replies`=`replies`+1 WHERE `id`='" . intval($_SESSION['id']) . "'"); // --> Prepare reply message @@ -357,7 +363,7 @@ elseif (!isset($_POST['no_notify']) || intval(hesk_POST('no_notify')) != 1) { } // Delete any existing drafts from this owner for this ticket -hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "reply_drafts` WHERE `owner`=" . intval($_SESSION['id']) . " AND `ticket`=" . intval($ticket['id']) . " LIMIT 1"); +hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "reply_drafts` WHERE `owner`=" . intval($_SESSION['id']) . " AND `ticket`=" . intval($ticket['id'])); /* Set reply submitted message */ $_SESSION['HESK_SUCCESS'] = TRUE; diff --git a/admin/admin_settings.php b/admin/admin_settings.php index 6e337207..1f003357 100644 --- a/admin/admin_settings.php +++ b/admin/admin_settings.php @@ -56,6 +56,10 @@ hesk_isLoggedIn(); // Check permissions for this feature hesk_checkPermission('can_man_settings'); + +// Load custom fields +require_once(HESK_PATH . 'inc/custom_fields.inc.php'); + // Test languages function if (isset($_GET['test_languages'])) { hesk_testLanguage(0); @@ -89,6 +93,9 @@ if (defined('HESK_DEMO')) { $hesk_settings['pop3_password'] = $hesklang['hdemo']; $hesk_settings['recaptcha_public_key'] = $hesklang['hdemo']; $hesk_settings['recaptcha_private_key'] = $hesklang['hdemo']; + $hesk_settings['imap_host_name'] = $hesklang['hdemo']; + $hesk_settings['imap_user'] = $hesklang['hdemo']; + $hesk_settings['imap_password'] = $hesklang['hdemo']; } // Check file attachment limits @@ -214,89 +221,6 @@ $modsForHesk_settings = mfh_getSettings(); // MISC - // CUSTOM FIELDS - if (d.s_custom1_use.checked && d.s_custom1_name.value == '') { - alert(''); - return false; - } - if (d.s_custom2_use.checked && d.s_custom2_name.value == '') { - alert(''); - return false; - } - if (d.s_custom3_use.checked && d.s_custom3_name.value == '') { - alert(''); - return false; - } - if (d.s_custom4_use.checked && d.s_custom4_name.value == '') { - alert(''); - return false; - } - if (d.s_custom5_use.checked && d.s_custom5_name.value == '') { - alert(''); - return false; - } - if (d.s_custom6_use.checked && d.s_custom6_name.value == '') { - alert(''); - return false; - } - if (d.s_custom7_use.checked && d.s_custom7_name.value == '') { - alert(''); - return false; - } - if (d.s_custom8_use.checked && d.s_custom8_name.value == '') { - alert(''); - return false; - } - if (d.s_custom9_use.checked && d.s_custom9_name.value == '') { - alert(''); - return false; - } - if (d.s_custom10_use.checked && d.s_custom10_name.value == '') { - alert(''); - return false; - } - if (d.s_custom11_use.checked && d.s_custom11_name.value == '') { - alert(''); - return false; - } - if (d.s_custom12_use.checked && d.s_custom12_name.value == '') { - alert(''); - return false; - } - if (d.s_custom13_use.checked && d.s_custom13_name.value == '') { - alert(''); - return false; - } - if (d.s_custom14_use.checked && d.s_custom14_name.value == '') { - alert(''); - return false; - } - if (d.s_custom15_use.checked && d.s_custom15_name.value == '') { - alert(''); - return false; - } - if (d.s_custom16_use.checked && d.s_custom16_name.value == '') { - alert(''); - return false; - } - if (d.s_custom17_use.checked && d.s_custom17_name.value == '') { - alert(''); - return false; - } - if (d.s_custom18_use.checked && d.s_custom18_name.value == '') { - alert(''); - return false; - } - if (d.s_custom19_use.checked && d.s_custom19_name.value == '') { - alert(''); - return false; - } - if (d.s_custom20_use.checked && d.s_custom20_name.value == '') { - alert(''); - return false; - } - - // DISABLE SUBMIT BUTTON d.submitbutton.disabled = true; d.submitbutton.value = ''; @@ -304,21 +228,6 @@ $modsForHesk_settings = mfh_getSettings(); return true; } - function hesk_customOptions(cID, fID, fTYPE, maxlenID, oldTYPE) { - var t = document.getElementById(fTYPE).value; - if (t == oldTYPE) { - var d = document.getElementById(fID).value; - var m = document.getElementById(maxlenID).value; - } - else { - var d = ''; - var m = 255; - } - var myURL = "options.php?i=" + cID + "&q=" + encodeURIComponent(d) + "&t=" + t + "&m=" + m; - window.open(myURL, "Hesk_window", "height=400,width=500,menubar=0,location=0,toolbar=0,status=0,resizable=1,scrollbars=1"); - return false; - } - function hesk_toggleLayer(nr, setto) { if (document.all) document.all[nr].style.display = setto; @@ -380,6 +289,20 @@ $modsForHesk_settings = mfh_getSettings(); } return i; } + + function checkRequiredEmail(field) { + if (document.getElementById('s_require_email_0').checked && document.getElementById('s_email_view_ticket').checked) { + if (field == 's_require_email_0' && confirm('')) { + document.getElementById('s_email_view_ticket').checked = false; + return true; + } else if (field == 's_email_view_ticket' && confirm('')) { + document.getElementById('s_require_email_1').checked = true; + return true; + } + return false; + } + return true; + } //-->
@@ -542,6 +465,31 @@ $modsForHesk_settings = mfh_getSettings(); ?> + + + / + + + + ' . $hesklang['exists'] . ', '; + if ($attachmentsWritable) { + $enable_use_attachments = 1; + echo '' . $hesklang['writable'] . ''; + } else { + echo '' . $hesklang['not_writable'] . '
' . $hesklang['e_cdir']; + } + } else { + echo '' . $hesklang['no_exists'] . ', ' . $hesklang['not_writable'] . '
' . $hesklang['e_cdir']; + } + ?> + + @@ -875,6 +823,20 @@ $modsForHesk_settings = mfh_getSettings(); value=""/> +
+ + +
+ +
+
+
+ + +
+
    +
'; + ?> +
+ +
+ + +
+
    +
'; + ?> +
+ +
+ + +
+
    +
    +
'; + ?> +
+
+
+ + +
+
    +
    +
'; + ?> +
+
+
+ + +
+ + +
+
@@ -1516,12 +1561,48 @@ $modsForHesk_settings = mfh_getSettings();
+
+ + +
+
+ +
+
+
+
+ + +
+
+ + + + +
+
+
- -
-
-

- -

-
- -
-
-
-

- - -
- - -
-
- -
-
-
- - - - - - - - - - - - - - - - - - - - '; - } // End FOR - ?> -
- -
- -
-

-
-
- - - ' . $hesklang['opt'] . ' -
-
-
-
@@ -2696,6 +2664,202 @@ $modsForHesk_settings = mfh_getSettings();
+ +

+ +
+ + +
+
    +
'; + ?> + + + + + + +
+
+
+
+ + +
+ > +
+
+
+ + +
+ > +
+
+
+ + +
+ > +
+
+
+ + +
+
    +
    +
+ '; + ?> +
+
+
+ + +
+
    +
+ '; + ?> +
+ +
+ + +
+ autocomplete="off"> +
+
+
+ + +
+ autocomplete="off"> +
+
+
+
+ +
+
+ + + + + + + + +

-

+

Common Properties

+
+
+
+ + +
+ +
+
+
+
+ +

Customer View

@@ -3486,40 +3671,71 @@ $modsForHesk_settings = mfh_getSettings();
+
+
-
+

Admin Panel

-
+
-
@@ -3567,8 +3783,8 @@ $modsForHesk_settings = mfh_getSettings(); global $hesk_settings; // Do we have a cached version file? - if (file_exists(HESK_PATH . $hesk_settings['attach_dir'] . '/__latest.txt')) { - if (preg_match('/^(\d+)\|([\d.]+)+$/', @file_get_contents(HESK_PATH . $hesk_settings['attach_dir'] . '/__latest.txt'), $matches) && (time() - intval($matches[1])) < 3600) { + if (file_exists(HESK_PATH . $hesk_settings['cache_dir'] . '/__latest.txt')) { + if (preg_match('/^(\d+)\|([\d.]+)+$/', @file_get_contents(HESK_PATH . $hesk_settings['cache_dir'] . '/__latest.txt'), $matches) && (time() - intval($matches[1])) < 3600) { return $matches[2]; } } @@ -3601,7 +3817,7 @@ $modsForHesk_settings = mfh_getSettings(); { global $hesk_settings; - @file_put_contents(HESK_PATH . $hesk_settings['attach_dir'] . '/__latest.txt', time() . '|' . $latest); + @file_put_contents(HESK_PATH . $hesk_settings['cache_dir'] . '/__latest.txt', time() . '|' . $latest); return $latest; @@ -3627,8 +3843,8 @@ $modsForHesk_settings = mfh_getSettings(); global $hesk_settings; // Do we have a cached version file? - if (file_exists(HESK_PATH . $hesk_settings['attach_dir'] . '/__latest-mfh.txt')) { - if (preg_match('/^(\d+)\|([\d.]+)+$/', @file_get_contents(HESK_PATH . $hesk_settings['attach_dir'] . '/__latest-mfh.txt'), $matches) && (time() - intval($matches[1])) < 3600) { + if (file_exists(HESK_PATH . $hesk_settings['cache_dir'] . '/__latest-mfh.txt')) { + if (preg_match('/^(\d+)\|([\d.]+)+$/', @file_get_contents(HESK_PATH . $hesk_settings['cache_dir'] . '/__latest-mfh.txt'), $matches) && (time() - intval($matches[1])) < 3600) { return $matches[2]; } } @@ -3660,7 +3876,7 @@ $modsForHesk_settings = mfh_getSettings(); { global $hesk_settings; - @file_put_contents(HESK_PATH . $hesk_settings['attach_dir'] . '/__latest-mfh.txt', time() . '|' . $latest); + @file_put_contents(HESK_PATH . $hesk_settings['cache_dir'] . '/__latest-mfh.txt', time() . '|' . $latest); return $latest; @@ -3723,7 +3939,7 @@ $modsForHesk_settings = mfh_getSettings(); } /* Check if language file is for current version */ - if (strpos($tmp, '$hesklang[\'ms01\']') === false) { + if (strpos($tmp, '$hesklang[\'refresh_page\']') === false) { $err .= " |----> WRONG VERSION (not " . $hesk_settings['hesk_version'] . ")\n"; } diff --git a/admin/admin_settings_save.php b/admin/admin_settings_save.php index 4b9cb092..3661d17c 100644 --- a/admin/admin_settings_save.php +++ b/admin/admin_settings_save.php @@ -85,9 +85,6 @@ if (isset($lang[1]) && in_array($lang[1], hesk_getLanguagesArray(1))) { hesk_error($hesklang['err_lang']); } -/* --> Database settings */ -hesk_dbClose(); - if (hesk_testMySQL()) { // Database connection OK } elseif ($mysql_log) { @@ -125,6 +122,7 @@ if ( ! is_writable(HESK_PATH . $set['attach_dir']) ) } */ +$set['cache_dir'] = isset($_POST['s_cache_dir']) && ! is_array($_POST['s_cache_dir']) ? preg_replace('/[^a-zA-Z0-9_-]/', '', $_POST['s_cache_dir']) : 'cache'; $set['max_listings'] = hesk_checkMinMax(intval(hesk_POST('s_max_listings')), 1, 999, 10); $set['print_font_size'] = hesk_checkMinMax(intval(hesk_POST('s_print_font_size')), 1, 99, 12); $set['autoclose'] = hesk_checkMinMax(intval(hesk_POST('s_autoclose')), 0, 999, 7); @@ -135,6 +133,10 @@ $set['reply_top'] = empty($_POST['s_reply_top']) ? 0 : 1; /* --> Features */ $set['autologin'] = empty($_POST['s_autologin']) ? 0 : 1; $set['autoassign'] = empty($_POST['s_autoassign']) ? 0 : 1; +$set['require_email'] = empty($_POST['s_require_email']) ? 0 : 1; +$set['require_owner'] = empty($_POST['s_require_owner']) ? 0 : 1; +$set['require_subject'] = hesk_checkMinMax( intval( hesk_POST('s_require_subject') ) , -1, 1, 1); +$set['require_message'] = hesk_checkMinMax( intval( hesk_POST('s_require_message') ) , -1, 1, 1); $set['custclose'] = empty($_POST['s_custclose']) ? 0 : 1; $set['custopen'] = empty($_POST['s_custopen']) ? 0 : 1; $set['rating'] = empty($_POST['s_rating']) ? 0 : 1; @@ -147,6 +149,7 @@ $set['debug_mode'] = empty($_POST['s_debug_mode']) ? 0 : 1; $set['short_link'] = empty($_POST['s_short_link']) ? 0 : 1; $set['select_cat'] = empty($_POST['s_select_cat']) ? 0 : 1; $set['select_pri'] = empty($_POST['s_select_pri']) ? 0 : 1; +$set['cat_show_select'] = hesk_checkMinMax( intval( hesk_POST('s_cat_show_select') ) , 0, 999, 10); /* --> SPAM prevention */ $set['secimg_use'] = empty($_POST['s_secimg_use']) ? 0 : (hesk_POST('s_secimg_use') == 2 ? 2 : 1); @@ -168,7 +171,14 @@ if ($set['attempt_limit'] > 0) { } $set['attempt_banmin'] = hesk_checkMinMax(intval(hesk_POST('s_attempt_banmin')), 5, 99999, 60); $set['reset_pass'] = empty($_POST['s_reset_pass']) ? 0 : 1; -$set['email_view_ticket'] = empty($_POST['s_email_view_ticket']) ? 0 : 1; +$set['email_view_ticket'] = ($set['require_email'] == 0) ? 0 : (empty($_POST['s_email_view_ticket']) ? 0 : 1); +$set['x_frame_opt'] = empty($_POST['s_x_frame_opt']) ? 0 : 1; +$set['force_ssl'] = HESK_SSL && isset($_POST['s_force_ssl']) && $_POST['s_force_ssl'] == 1 ? 1 : 0; + +// Make sure help desk URL starts with https if forcing SSL +if ($set['force_ssl']) { + $set['hesk_url'] = preg_replace('/^http:/i', 'https:', $set['hesk_url']); +} /* --> Attachments */ $set['attachments']['use'] = empty($_POST['s_attach_use']) ? 0 : 1; @@ -246,7 +256,7 @@ if ($set['smtp']) { $set['smtp'] = 0; } } else { - $set['smtp_host_name'] = hesk_input(hesk_POST('tmp_smtp_host_name', 'mail.domain.com')); + $set['smtp_host_name'] = hesk_input(hesk_POST('tmp_smtp_host_name', 'mail.example.com')); $set['smtp_host_port'] = intval(hesk_POST('tmp_smtp_host_port', 25)); $set['smtp_timeout'] = intval(hesk_POST('tmp_smtp_timeout', 10)); $set['smtp_ssl'] = empty($_POST['tmp_smtp_ssl']) ? 0 : 1; @@ -279,7 +289,7 @@ if ($set['pop3']) { } } else { $set['pop3_job_wait'] = intval(hesk_POST('s_pop3_job_wait', 15)); - $set['pop3_host_name'] = hesk_input(hesk_POST('tmp_pop3_host_name', 'mail.domain.com')); + $set['pop3_host_name'] = hesk_input(hesk_POST('tmp_pop3_host_name', 'mail.example.com')); $set['pop3_host_port'] = intval(hesk_POST('tmp_pop3_host_port', 110)); $set['pop3_tls'] = empty($_POST['tmp_pop3_tls']) ? 0 : 1; $set['pop3_keep'] = empty($_POST['tmp_pop3_keep']) ? 0 : 1; @@ -287,6 +297,32 @@ if ($set['pop3']) { $set['pop3_password'] = hesk_input(hesk_POST('tmp_pop3_password')); } +/* --> IMAP fetching */ +$imap_OK = true; +$set['imap'] = empty($_POST['s_imap']) ? 0 : 1; + +if ($set['imap']) { + // Get IMAP fetching timeout + $set['imap_job_wait'] = hesk_checkMinMax( intval( hesk_POST('s_imap_job_wait') ) , 0, 1440, 15); + + // Test IMAP connection + $imap_OK = hesk_testIMAP(true); + + // If IMAP not working, disable it + if ( ! $imap_OK) { + $set['imap'] = 0; + } +} else { + $set['imap_job_wait'] = intval( hesk_POST('s_imap_job_wait', 15) ); + $set['imap_host_name'] = hesk_input( hesk_POST('tmp_imap_host_name', 'mail.example.com') ); + $set['imap_host_port'] = intval( hesk_POST('tmp_imap_host_port', 110) ); + $set['imap_enc'] = hesk_POST('tmp_imap_enc'); + $set['imap_enc'] = ($set['imap_enc'] == 'ssl' || $set['imap_enc'] == 'tls') ? $set['imap_enc'] : ''; + $set['imap_keep'] = empty($_POST['tmp_imap_keep']) ? 0 : 1; + $set['imap_user'] = hesk_input( hesk_POST('tmp_imap_user') ); + $set['imap_password'] = hesk_input( hesk_POST('tmp_imap_password') ); +} + /* --> Email loops */ $set['loop_hits'] = hesk_checkMinMax(intval(hesk_POST('s_loop_hits')), 0, 999, 5); $set['loop_time'] = hesk_checkMinMax(intval(hesk_POST('s_loop_time')), 1, 86400, 300); @@ -323,10 +359,10 @@ if (!empty($_POST['s_email_providers']) && !is_array($_POST['s_email_providers'] if (!$set['detect_typos'] || count($set['email_providers']) < 1) { $set['detect_typos'] = 0; - $set['email_providers'] = array('gmail.com', 'hotmail.com', 'hotmail.co.uk', 'yahoo.com', 'yahoo.co.uk', 'aol.com', 'aol.co.uk', 'msn.com', 'live.com', 'live.co.uk', 'mail.com', 'googlemail.com', 'btinternet.com', 'btopenworld.com'); + $set['email_providers']=array('aim.com','aol.co.uk','aol.com','att.net','bellsouth.net','blueyonder.co.uk','bt.com','btinternet.com','btopenworld.com','charter.net','comcast.net','cox.net','earthlink.net','email.com','facebook.com','fastmail.fm','free.fr','freeserve.co.uk','gmail.com','gmx.at','gmx.ch','gmx.com','gmx.de','gmx.fr','gmx.net','gmx.us','googlemail.com','hotmail.be','hotmail.co.uk','hotmail.com','hotmail.com.ar','hotmail.com.mx','hotmail.de','hotmail.es','hotmail.fr','hushmail.com','icloud.com','inbox.com','laposte.net','lavabit.com','list.ru','live.be','live.co.uk','live.com','live.com.ar','live.com.mx','live.de','live.fr','love.com','lycos.com','mac.com','mail.com','mail.ru','me.com','msn.com','nate.com','naver.com','neuf.fr','ntlworld.com','o2.co.uk','online.de','orange.fr','orange.net','outlook.com','pobox.com','prodigy.net.mx','qq.com','rambler.ru','rocketmail.com','safe-mail.net','sbcglobal.net','t-online.de','talktalk.co.uk','tiscali.co.uk','verizon.net','virgin.net','virginmedia.com','wanadoo.co.uk','wanadoo.fr','yahoo.co.id','yahoo.co.in','yahoo.co.jp','yahoo.co.kr','yahoo.co.uk','yahoo.com','yahoo.com.ar','yahoo.com.mx','yahoo.com.ph','yahoo.com.sg','yahoo.de','yahoo.fr','yandex.com','yandex.ru','ymail.com'); } -$set['email_providers'] = count($set['email_providers']) ? "'" . implode("','", $set['email_providers']) . "'" : ''; +$set['email_providers'] = count($set['email_providers']) ? "'" . implode("','", array_unique($set['email_providers'])) . "'" : ''; /* --> Notify customer when */ @@ -386,7 +422,8 @@ foreach ($hesk_settings['possible_ticket_list'] as $key => $title) { // We need at least one of these: id, trackid, subject if (!in_array('id', $set['ticket_list']) && !in_array('trackid', $set['ticket_list']) && !in_array('subject', $set['ticket_list'])) { - $set['ticket_list'][] = 'trackid'; + // None of the required fields are there, add "trackid" as the first one + array_unshift($set['ticket_list'], 'trackid'); } $set['ticket_list'] = count($set['ticket_list']) ? "'" . implode("','", $set['ticket_list']) . "'" : 'trackid'; @@ -419,49 +456,9 @@ $set['submit_notice'] = empty($_POST['s_submit_notice']) ? 0 : 1; $set['online'] = empty($_POST['s_online']) ? 0 : 1; $set['online_min'] = hesk_checkMinMax(intval(hesk_POST('s_online_min')), 1, 999, 10); $set['check_updates'] = empty($_POST['s_check_updates']) ? 0 : 1; - -/*** CUSTOM FIELDS ***/ - -for ($i = 1; $i <= 20; $i++) { - $this_field = 'custom' . $i; - $set['custom_fields'][$this_field]['use'] = !empty($_POST['s_custom' . $i . '_use']) ? 1 : 0; - - if ($set['custom_fields'][$this_field]['use']) { - $set['custom_fields'][$this_field]['place'] = empty($_POST['s_custom' . $i . '_place']) ? 0 : 1; - $set['custom_fields'][$this_field]['type'] = hesk_htmlspecialchars(hesk_POST('s_custom' . $i . '_type', 'text')); - $set['custom_fields'][$this_field]['req'] = !empty($_POST['s_custom' . $i . '_req']) ? 1 : 0; - $set['custom_fields'][$this_field]['name'] = hesk_input(hesk_POST('s_custom' . $i . '_name'), $hesklang['err_custname']); - $set['custom_fields'][$this_field]['maxlen'] = intval(hesk_POST('s_custom' . $i . '_maxlen', 255)); - $set['custom_fields'][$this_field]['value'] = hesk_input(hesk_POST('s_custom' . $i . '_val')); - - if ($set['custom_fields'][$this_field]['type'] == 'email' && $set['custom_fields'][$this_field]['value'] == '') { - // New custom field without any options set. Default to Cc - $set['custom_fields'][$this_field]['value'] = 'cc'; - } - - if (!in_array($set['custom_fields'][$this_field]['type'], array('text', 'textarea', 'select', 'radio', 'checkbox', 'date', 'multiselect', 'email', 'hidden', 'readonly'))) { - $set['custom_fields'][$this_field]['type'] = 'text'; - } - - // Try to detect if field type changed to anything except "select" - if ($set['custom_fields'][$this_field]['type'] != 'select') { - // If type is "radio" or "checkbox" remove "please select", keep other options - $set['custom_fields'][$this_field]['value'] = str_replace('{HESK_SELECT}', '', $set['custom_fields'][$this_field]['value']); - - // Field type changed to "text" or "textarea", clear default value if it contains "#HESK#" separator - if (in_array($set['custom_fields'][$this_field]['type'], array('text', 'textarea')) && !in_array($hesk_settings['custom_fields'][$this_field]['type'], array('text', 'textarea')) && strpos($set['custom_fields'][$this_field]['value'], '#HESK#') !== false) { - $set['custom_fields'][$this_field]['value'] = ''; - } - } - } else { - $set['custom_fields'][$this_field] = array('use' => 0, 'place' => 0, 'type' => 'text', 'req' => 0, 'name' => 'Custom field ' . $i, 'maxlen' => 255, 'value' => ''); - } -} - $set['hesk_version'] = $hesk_settings['hesk_version']; // Process quick help sections -hesk_dbConnect(); hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "quick_help_sections` SET `show` = '0'"); $postArray = hesk_POST_array('quick_help_sections'); foreach ($postArray as $value) { @@ -516,6 +513,7 @@ $set['dropdownItemTextColor'] = hesk_input(hesk_POST('dropdownItemTextColor')); $set['dropdownItemTextHoverColor'] = hesk_input(hesk_POST('dropdownItemTextHoverColor')); $set['questionMarkColor'] = hesk_input(hesk_POST('questionMarkColor')); $set['dropdownItemTextHoverBackgroundColor'] = hesk_input(hesk_POST('dropdownItemTextHoverBackgroundColor')); +$set['admin_color_scheme'] = hesk_input(hesk_POST('admin-color-scheme')); mfh_updateSetting('rtl', $set['rtl']); mfh_updateSetting('show_icons', $set['show-icons']); mfh_updateSetting('custom_field_setting', $set['custom-field-setting']); @@ -552,6 +550,7 @@ mfh_updateSetting('use_mailgun', $set['use_mailgun'], false); mfh_updateSetting('enable_calendar', $set['enable_calendar'], false); mfh_updateSetting('first_day_of_week', $set['first_day_of_week'], false); mfh_updateSetting('default_calendar_view', $set['default_view'], true); +mfh_updateSetting('admin_color_scheme', $set['admin_color_scheme'], true); // Prepare settings file and save it $settings_file_content = ' Features $hesk_settings[\'autologin\']=' . $set['autologin'] . '; $hesk_settings[\'autoassign\']=' . $set['autoassign'] . '; +$hesk_settings[\'require_email\']=' . $set['require_email'] . '; +$hesk_settings[\'require_owner\']=' . $set['require_owner'] . '; +$hesk_settings[\'require_subject\']=' . $set['require_subject'] . '; +$hesk_settings[\'require_message\']=' . $set['require_message'] . '; $hesk_settings[\'custclose\']=' . $set['custclose'] . '; $hesk_settings[\'custopen\']=' . $set['custopen'] . '; $hesk_settings[\'rating\']=' . $set['rating'] . '; @@ -610,6 +614,7 @@ $hesk_settings[\'debug_mode\']=' . $set['debug_mode'] . '; $hesk_settings[\'short_link\']=' . $set['short_link'] . '; $hesk_settings[\'select_cat\']=' . $set['select_cat'] . '; $hesk_settings[\'select_pri\']=' . $set['select_pri'] . '; +$hesk_settings[\'cat_show_select\']=' . $set['cat_show_select'] . '; // --> SPAM Prevention $hesk_settings[\'secimg_use\']=' . $set['secimg_use'] . '; @@ -626,6 +631,8 @@ $hesk_settings[\'attempt_limit\']=' . $set['attempt_limit'] . '; $hesk_settings[\'attempt_banmin\']=' . $set['attempt_banmin'] . '; $hesk_settings[\'reset_pass\']=' . $set['reset_pass'] . '; $hesk_settings[\'email_view_ticket\']=' . $set['email_view_ticket'] . '; +$hesk_settings[\'x_frame_opt\']=' . $set['x_frame_opt'] . '; +$hesk_settings[\'force_ssl\']=' . $set['force_ssl'] . '; // --> Attachments $hesk_settings[\'attachments\']=array ( @@ -635,6 +642,15 @@ $hesk_settings[\'attachments\']=array ( \'allowed_types\' => array(\'' . implode('\',\'', $set['attachments']['allowed_types']) . '\') ); +// --> IMAP Fetching +$hesk_settings[\'imap\']=' . $set['imap'] . '; +$hesk_settings[\'imap_job_wait\']=' . $set['imap_job_wait'] . '; +$hesk_settings[\'imap_host_name\']=\'' . $set['imap_host_name'] . '\'; +$hesk_settings[\'imap_host_port\']=' . $set['imap_host_port'] . '; +$hesk_settings[\'imap_enc\']=\'' . $set['imap_enc'] . '\'; +$hesk_settings[\'imap_keep\']=' . $set['imap_keep'] . '; +$hesk_settings[\'imap_user\']=\'' . $set['imap_user'] . '\'; +$hesk_settings[\'imap_password\']=\'' . $set['imap_password'] . '\'; // ==> KNOWLEDGEBASE @@ -731,22 +747,6 @@ $hesk_settings[\'online_min\']=' . $set['online_min'] . '; $hesk_settings[\'check_updates\']=' . $set['check_updates'] . '; -// ==> CUSTOM FIELDS - -$hesk_settings[\'custom_fields\']=array ( -'; - -for ($i = 1; $i <= 20; $i++) { - $settings_file_content .= '\'custom' . $i . '\'=>array(\'use\'=>' . $set['custom_fields']['custom' . $i]['use'] . ',\'place\'=>' . $set['custom_fields']['custom' . $i]['place'] . ',\'type\'=>\'' . $set['custom_fields']['custom' . $i]['type'] . '\',\'req\'=>' . $set['custom_fields']['custom' . $i]['req'] . ',\'name\'=>\'' . $set['custom_fields']['custom' . $i]['name'] . '\',\'maxlen\'=>' . $set['custom_fields']['custom' . $i]['maxlen'] . ',\'value\'=>\'' . $set['custom_fields']['custom' . $i]['value'] . '\')'; - if ($i != 20) { - $settings_file_content .= ', -'; - } -} - -$settings_file_content .= ' -); - ############################# # DO NOT EDIT BELOW # ############################# @@ -796,14 +796,6 @@ function mfh_updateSetting($key, $value, $isString = false) hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "settings` SET `Value` = " . $formattedValue . " WHERE `Key` = '" . $key . "'"); } -function hesk_checkMinMax($myint, $min, $max, $defval) -{ - if ($myint > $max || $myint < $min) { - return $defval; - } - return $myint; -} // END hesk_checkMinMax() - function hesk_getLanguagesArray($returnArray = 0) { @@ -847,7 +839,7 @@ function hesk_getLanguagesArray($returnArray = 0) $add = 0; } elseif (!preg_match('/\$hesklang\[\'EMAIL_HR\'\]\=\'(.*)\'\;/', $tmp, $hr)) { $add = 0; - } elseif (!preg_match('/\$hesklang\[\'ms01\'\]/', $tmp)) { + } elseif (!preg_match('/\$hesklang\[\'refresh_page\'\]/', $tmp)) { $add = 0; } } else { diff --git a/admin/admin_submit_ticket.php b/admin/admin_submit_ticket.php index d6241840..53386536 100644 --- a/admin/admin_submit_ticket.php +++ b/admin/admin_submit_ticket.php @@ -62,7 +62,22 @@ if ($hesk_settings['can_sel_lang']) { $tmpvar['language'] = hesk_POST('customerLanguage'); } $tmpvar['name'] = hesk_input(hesk_POST('name')) or $hesk_error_buffer['name'] = $hesklang['enter_your_name']; -$tmpvar['email'] = hesk_POST('email'); +$email_available = true; + +if ($hesk_settings['require_email']) { + $tmpvar['email'] = hesk_validateEmail( hesk_POST('email'), 'ERR', 0) or $hesk_error_buffer['email']=$hesklang['enter_valid_email']; +} else { + $tmpvar['email'] = hesk_validateEmail( hesk_POST('email'), 'ERR', 0); + + // Not required, but must be valid if it is entered + if ($tmpvar['email'] == '') { + $email_available = false; + + if (strlen(hesk_POST('email'))) { + $hesk_error_buffer['email'] = $hesklang['not_valid_email']; + } + } +} if ($hesk_settings['multi_eml']) { $tmpvar['email'] = str_replace(';',',', $tmpvar['email']); } @@ -80,11 +95,22 @@ if ($tmpvar['priority'] < 0 || $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['subject'] = hesk_input( hesk_POST('subject') ); +if ($hesk_settings['require_subject'] == 1 && $tmpvar['subject'] == '') { + $hesk_error_buffer['subject'] = $hesklang['enter_ticket_subject']; +} + +$tmpvar['message'] = hesk_input( hesk_POST('message') ); +if ($hesk_settings['require_message'] == 1 && $tmpvar['message'] == '') { + $hesk_error_buffer['message'] = $hesklang['enter_message']; +} // Is category a valid choice? if ($tmpvar['category']) { + if ( ! hesk_checkPermission('can_submit_any_cat', 0) && ! hesk_okCategory($tmpvar['category'], 0) ) { + hesk_process_messages($hesklang['noauth_submit'],'new_ticket.php'); + } + hesk_verifyCategory(1); // Is auto-assign of tickets disabled in this category? @@ -94,19 +120,69 @@ if ($tmpvar['category']) { } // Custom fields -foreach ($hesk_settings['custom_fields'] as $k => $v) { - if ($v['use'] && isset($_POST[$k])) { - // Date will be handled by the jQuery datepicker - if ($v['type'] == 'date' && $_POST[$k] != '') { - $tmpvar[$k] = strtotime($_POST[$k]); - } else if (is_array($_POST[$k])) { - $tmpvar[$k] = ''; - foreach ($_POST[$k] as $myCB) { - $tmpvar[$k] .= (is_array($myCB) ? '' : hesk_input($myCB)) . '
'; +foreach ($hesk_settings['custom_fields'] as $k=>$v) { + if ($v['use'] && hesk_is_custom_field_in_category($k, $tmpvar['category'])) { + if ($v['type'] == 'checkbox') { + $tmpvar[$k]=''; + + if (isset($_POST[$k]) && is_array($_POST[$k])) { + foreach ($_POST[$k] as $myCB) { + $tmpvar[$k] .= ( is_array($myCB) ? '' : hesk_input($myCB) ) . '
';; + } + $tmpvar[$k]=substr($tmpvar[$k],0,-6); + } else { + if ($v['req'] == 2) { + $hesk_error_buffer[$k]=$hesklang['fill_all'].': '.$v['name']; + } + $_POST[$k] = ''; + } + } elseif ($v['type'] == 'date') { + $tmpvar[$k] = hesk_POST($k); + $_SESSION["as_$k"] = ''; + if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $tmpvar[$k])) { + $date = strtotime($tmpvar[$k] . ' t00:00:00'); + $dmin = strlen($v['value']['dmin']) ? strtotime($v['value']['dmin'] . ' t00:00:00') : false; + $dmax = strlen($v['value']['dmax']) ? strtotime($v['value']['dmax'] . ' t00:00:00') : false; + + $_SESSION["as_$k"] = $tmpvar[$k]; + + if ($dmin && $dmin > $date) { + $hesk_error_buffer[$k] = sprintf($hesklang['d_emin'], $v['name'], hesk_custom_date_display_format($dmin, $v['value']['date_format'])); + } elseif ($dmax && $dmax < $date) { + $hesk_error_buffer[$k] = sprintf($hesklang['d_emax'], $v['name'], hesk_custom_date_display_format($dmax, $v['value']['date_format'])); + } else { + $tmpvar[$k] = $date; + } + } else { + $tmpvar[$k] = ''; + + if ($v['req'] == 2) { + $hesk_error_buffer[$k]=$hesklang['fill_all'].': '.$v['name']; + } + } + } elseif ($v['type'] == 'email') + { + $tmp = $hesk_settings['multi_eml']; + $hesk_settings['multi_eml'] = $v['value']['multiple']; + $tmpvar[$k] = hesk_validateEmail( hesk_POST($k), 'ERR', 0); + $hesk_settings['multi_eml'] = $tmp; + + if ($tmpvar[$k] != '') { + $_SESSION["as_$k"] = hesk_input($tmpvar[$k]); + } else { + $_SESSION["as_$k"] = ''; + + if ($v['req'] == 2) { + $hesk_error_buffer[$k] = $v['value']['multiple'] ? sprintf($hesklang['cf_noem'], $v['name']) : sprintf($hesklang['cf_noe'], $v['name']); + } + } + } elseif ($v['req'] == 2) { + $tmpvar[$k]=hesk_makeURL(nl2br(hesk_input( hesk_POST($k) ))); + if ($tmpvar[$k] == '') { + $hesk_error_buffer[$k]=$hesklang['fill_all'].': '.$v['name']; } - $tmpvar[$k] = substr($tmpvar[$k], 0, -6); } else { - $tmpvar[$k] = hesk_makeURL(nl2br(hesk_input($_POST[$k]))); + $tmpvar[$k]=hesk_makeURL(nl2br(hesk_input(hesk_POST($k)))); } } else { $tmpvar[$k] = ''; @@ -202,7 +278,6 @@ if (count($hesk_error_buffer) != 0) { $_SESSION['as_name'] = hesk_POST('name'); $_SESSION['as_email'] = hesk_POST('email'); - $_SESSION['as_category'] = hesk_POST('category'); $_SESSION['as_priority'] = $tmpvar['priority']; $_SESSION['as_subject'] = hesk_POST('subject'); $_SESSION['as_message'] = hesk_POST('message'); @@ -211,7 +286,7 @@ if (count($hesk_error_buffer) != 0) { $_SESSION['as_show'] = $show; foreach ($hesk_settings['custom_fields'] as $k => $v) { - if ($v['use']) { + if ($v['use'] && ! in_array($v['type'], array('date', 'email'))) { $_SESSION["as_$k"] = ($v['type'] == 'checkbox') ? hesk_POST_array($k) : hesk_POST($k); } } @@ -228,7 +303,7 @@ if (count($hesk_error_buffer) != 0) { } $hesk_error_buffer = $hesklang['pcer'] . '

    ' . $hesk_error_buffer . '
'; - hesk_process_messages($hesk_error_buffer, 'new_ticket.php'); + hesk_process_messages($hesk_error_buffer,'new_ticket.php?category='.$tmpvar['category']); } if ($hesk_settings['attachments']['use'] && !empty($attachments)) { @@ -258,7 +333,7 @@ $tmpvar['screen_resolution_width'] = "NULL"; $ticket = hesk_newTicket($tmpvar); // Notify the customer about the ticket? -if ($notify) { +if ($notify && $email_available) { hesk_notifyCustomer($modsForHesk_settings); } @@ -288,9 +363,7 @@ hesk_cleanSessionVars('as_owner'); hesk_cleanSessionVars('as_notify'); hesk_cleanSessionVars('as_show'); foreach ($hesk_settings['custom_fields'] as $k => $v) { - if ($v['use']) { - hesk_cleanSessionVars("as_$k"); - } + hesk_cleanSessionVars("as_$k"); } // If ticket has been assigned to the person submitting it lets show a message saying so @@ -304,5 +377,4 @@ if ($show) { hesk_process_messages($hesklang['new_ticket_submitted'], 'admin_ticket.php?track=' . $ticket['trackid'] . '&Refresh=' . mt_rand(10000, 99999), 'SUCCESS'); } else { hesk_process_messages($hesklang['new_ticket_submitted'] . '.
' . $hesklang['view_ticket'] . '', 'new_ticket.php', 'SUCCESS'); -} -?> +} \ No newline at end of file diff --git a/admin/admin_ticket.php b/admin/admin_ticket.php index fb6f0698..b14d1ed7 100644 --- a/admin/admin_ticket.php +++ b/admin/admin_ticket.php @@ -60,14 +60,22 @@ $can_archive = hesk_checkPermission('can_add_archive', 0); $can_assign_self = hesk_checkPermission('can_assign_self', 0); $can_view_unassigned = hesk_checkPermission('can_view_unassigned', 0); $can_change_cat = hesk_checkPermission('can_change_cat', 0); +$can_change_own_cat = hesk_checkPermission('can_change_own_cat',0); $can_ban_emails = hesk_checkPermission('can_ban_emails', 0); $can_unban_emails = hesk_checkPermission('can_unban_emails', 0); $can_ban_ips = hesk_checkPermission('can_ban_ips', 0); $can_unban_ips = hesk_checkPermission('can_unban_ips', 0); +$can_resolve = hesk_checkPermission('can_resolve', 0); // Get ticket ID $trackingID = hesk_cleanID() or print_form(); +// Load custom fields +require_once(HESK_PATH . 'inc/custom_fields.inc.php'); + +// Load statuses +//require_once(HESK_PATH . 'inc/statuses.inc.php'); + $_SERVER['PHP_SELF'] = 'admin_ticket.php?track=' . $trackingID . '&Refresh=' . mt_rand(10000, 99999); /* We will need timer function */ @@ -127,7 +135,20 @@ $managerRS = hesk_dbQuery('SELECT * FROM `' . hesk_dbEscape($hesk_settings['db_p $managerRow = hesk_dbFetchAssoc($managerRS); $isManager = $managerRow['id'] == $category['manager']; if ($isManager) { - $can_del_notes = $can_reply = $can_delete = $can_edit = $can_archive = $can_assign_self = $can_view_unassigned = $can_change_cat = true; + $can_del_notes = + $can_reply = + $can_delete = + $can_edit = + $can_archive = + $can_assign_self = + $can_view_unassigned = + $can_change_own_cat = + $can_change_cat = + $can_ban_emails = + $can_unban_emails = + $can_ban_ips = + $can_unban_ips = + $can_resolve = true; } /* Is this user allowed to view tickets inside this category? */ @@ -187,12 +208,12 @@ if (isset($_GET['delete_post']) && $can_delete && hesk_token_check()) { } /* Delete attachments info from the database */ - hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "attachments` WHERE `att_id`='" . intval($att_id) . "' LIMIT 1"); + hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "attachments` WHERE `att_id`='" . intval($att_id) . "'"); } } /* Delete this reply */ - hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "replies` WHERE `id`='" . intval($n) . "' AND `replyto`='" . intval($ticket['id']) . "' LIMIT 1"); + hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "replies` WHERE `id`='" . intval($n) . "' AND `replyto`='" . intval($ticket['id']) . "'"); /* Reply wasn't deleted */ if (hesk_dbAffectedRows() != 1) { @@ -239,7 +260,7 @@ if (isset($_GET['delete_post']) && $can_delete && hesk_token_check()) { } } - hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `lastchange`=NOW(), `lastreplier`='{$last_replier}', `replierid`='" . intval($replier_id) . "', `replies`=`replies`-1 $status_sql $closed_sql $staffreplies_sql WHERE `id`='" . intval($ticket['id']) . "' LIMIT 1"); + hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `lastchange`=NOW(), `lastreplier`='{$last_replier}', `replierid`='" . intval($replier_id) . "', `replies`=`replies`-1 $status_sql $closed_sql $staffreplies_sql WHERE `id`='" . intval($ticket['id']) . "'"); } else { // Update status, closedat and closedby columns as required if ($ticket['locked']) { @@ -250,7 +271,7 @@ if (isset($_GET['delete_post']) && $can_delete && hesk_token_check()) { $closed_sql = " , `closedat`=NULL, `closedby`=NULL "; } - hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `lastchange`=NOW(), `lastreplier`='0', `status`='$status', `replies`=0 $staffreplies_sql WHERE `id`='" . intval($ticket['id']) . "' LIMIT 1"); + hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `lastchange`=NOW(), `lastreplier`='0', `status`='$status', `replies`=0 $staffreplies_sql WHERE `id`='" . intval($ticket['id']) . "'"); } hesk_process_messages($hesklang['repl'], $_SERVER['PHP_SELF'], 'SUCCESS'); @@ -273,7 +294,7 @@ if (isset($_GET['delnote']) && hesk_token_check()) { // Permission to delete note? if ($can_del_notes || $note['who'] == $_SESSION['id']) { // Delete note - hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "notes` WHERE `id`='" . intval($n) . "' LIMIT 1"); + hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "notes` WHERE `id`='" . intval($n) . "'"); // Delete attachments if (strlen($note['attachments'])) { @@ -435,7 +456,7 @@ if ($hesk_settings['time_worked'] && ($can_reply || $can_edit) && isset($_POST[' /* Update database */ $revision = sprintf($hesklang['thist14'], hesk_date(), $time_worked, $_SESSION['name'] . ' (' . $_SESSION['user'] . ')'); - hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `time_worked`='" . hesk_dbEscape($time_worked) . "', `history`=CONCAT(`history`,'" . hesk_dbEscape($revision) . "') WHERE `trackid`='" . hesk_dbEscape($trackingID) . "' LIMIT 1"); + hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `time_worked`='" . hesk_dbEscape($time_worked) . "', `history`=CONCAT(`history`,'" . hesk_dbEscape($revision) . "') WHERE `trackid`='" . hesk_dbEscape($trackingID) . "'"); /* Show ticket */ hesk_process_messages($hesklang['twu'], 'admin_ticket.php?track=' . $trackingID . '&Refresh=' . mt_rand(10000, 99999), 'SUCCESS'); @@ -525,15 +546,14 @@ if (isset($_GET['delatt']) && hesk_token_check()) { /* Update ticket or reply in the database */ $revision = sprintf($hesklang['thist12'], hesk_date(), $att['real_name'], $_SESSION['name'] . ' (' . $_SESSION['user'] . ')'); if ($reply) { - hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "replies` SET `attachments`=REPLACE(`attachments`,'" . hesk_dbEscape($att_id . '#' . $att['real_name'] . '#' . $att['saved_name']) . ",','') WHERE `id`='" . intval($reply) . "' LIMIT 1"); - hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "replies` SET `attachments`=REPLACE(`attachments`,'" . hesk_dbEscape($att_id . '#' . $att['real_name']) . ",','') WHERE `id`='" . intval($reply) . "' LIMIT 1"); - hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `history`=CONCAT(`history`,'" . hesk_dbEscape($revision) . "') WHERE `id`='" . intval($ticket['id']) . "' LIMIT 1"); + hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "replies` SET `attachments`=REPLACE(`attachments`,'" . hesk_dbEscape($att_id . '#' . $att['real_name'] . '#' . $att['saved_name']) . ",','') WHERE `id`='" . intval($reply) . "'"); + hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `history`=CONCAT(`history`,'" . hesk_dbEscape($revision) . "') WHERE `id`='" . intval($ticket['id']) . "'"); } elseif ($note) { hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "notes` SET `attachments`=REPLACE(`attachments`,'" . hesk_dbEscape($att_id . '#' . $att['real_name'] . '#' . $att['saved_name']) . ",','') WHERE `id`={$note} LIMIT 1"); - hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "notes` SET `attachments`=REPLACE(`attachments`,'" . hesk_dbEscape($att_id . '#' . $att['real_name']) . ",','') WHERE `id`={$note} LIMIT 1"); + hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "notes` SET `attachments`=REPLACE(`attachments`,'" . hesk_dbEscape($att_id . '#' . $att['real_name']) . ",','') WHERE `id`={$note}"); } else { - hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `attachments`=REPLACE(`attachments`,'" . hesk_dbEscape($att_id . '#' . $att['real_name'] . '#' . $att['saved_name']) . ",','') WHERE `id`='" . intval($ticket['id']) . "' LIMIT 1"); - hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `attachments`=REPLACE(`attachments`,'" . hesk_dbEscape($att_id . '#' . $att['real_name']) . ",',''), `history`=CONCAT(`history`,'" . hesk_dbEscape($revision) . "') WHERE `id`='" . intval($ticket['id']) . "' LIMIT 1"); + hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `attachments`=REPLACE(`attachments`,'" . hesk_dbEscape($att_id . '#' . $att['real_name'] . '#' . $att['saved_name']) . ",','') WHERE `id`='" . intval($ticket['id']) . "'"); + hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `attachments`=REPLACE(`attachments`,'" . hesk_dbEscape($att_id . '#' . $att['real_name']) . ",',''), `history`=CONCAT(`history`,'" . hesk_dbEscape($revision) . "') WHERE `id`='" . intval($ticket['id']) . "'"); } hesk_process_messages($hesklang['kb_att_rem'], 'admin_ticket.php?track=' . $trackingID . '&Refresh=' . mt_rand(10000, 99999), 'SUCCESS'); @@ -553,7 +573,11 @@ require_once(HESK_PATH . 'inc/headerAdmin.inc.php'); /* List of categories */ $orderBy = $modsForHesk_settings['category_order_column']; -$result = hesk_dbQuery("SELECT `id`,`name` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "categories` WHERE `usage` <> 2 ORDER BY `" . $orderBy . "` ASC"); +if ($can_change_cat) { + $result = hesk_dbQuery("SELECT `id`,`name` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."categories` WHERE `usage` <> 2 ORDER BY `cat_order` ASC"); +} else { + $result = hesk_dbQuery("SELECT `id`,`name` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."categories` WHERE `usage` <> 2 AND ".hesk_myCategories('id')." ORDER BY `cat_order` ASC"); +} $categories_options = ''; while ($row = hesk_dbFetchAssoc($result)) { $selected = ''; @@ -633,6 +657,17 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php'); $v) { + if ($v['use'] && hesk_is_custom_field_in_category($k, $ticket['category']) ) { + switch ($v['type']) { + case 'date': + $ticket[$k] = hesk_custom_date_display_format($ticket[$k], $v['value']['date_format']); + break; + } + } + } ?>

@@ -1025,15 +1060,19 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php'); '; + if ( ! $ticket['owner']) + { + echo ''; + } + echo '

'; } else { echo '

'; echo isset($admins[$ticket['owner']]) ? $admins[$ticket['owner']] : - ($can_assign_self ? $hesklang['unas'] . ' [' . $hesklang['asss'] . ']' : $hesklang['unas']); + ($can_assign_self ? $hesklang['unas'] . ' [' . $hesklang['asss'] . ']' : $hesklang['unas']); echo '

'; } - echo '
'; echo '

' . $hesklang['category'] . '

'; - if ($can_change_cat) { + if (strlen($categories_options) && ($can_change_cat || $can_change_own_cat)) { echo '
@@ -1248,7 +1287,7 @@ require_once(HESK_PATH . 'inc/footer.inc.php'); function hesk_getAdminButtons($category_id) { - global $hesk_settings, $hesklang, $modsForHesk_settings, $ticket, $reply, $trackingID, $can_edit, $can_archive, $can_delete, $isManager; + global $hesk_settings, $hesklang, $modsForHesk_settings, $ticket, $reply, $trackingID, $can_edit, $can_archive, $can_delete, $can_resolve, $isManager; $options = ''; @@ -1330,7 +1369,7 @@ function hesk_getAdminButtons($category_id)
+$error\n"; + } + $hesk_error_buffer = $tmp; + + $hesk_error_buffer = $hesklang['rfm'].'

'; + hesk_process_messages($hesk_error_buffer,'custom_fields.php'); + } + + // Add custom field data into database + hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` SET + `use` = '{$cf['use']}', + `place` = '{$cf['place']}', + `type` = '{$cf['type']}', + `req` = '{$cf['req']}', + `category` = ".(count($cf['categories']) ? "'".json_encode($cf['categories'])."'" : 'NULL').", + `name` = '".hesk_dbEscape($cf['names'])."', + `value` = ".(strlen($cf['value']) ? "'".hesk_dbEscape($cf['value'])."'" : 'NULL')." + WHERE `id`={$id}"); + + // Clear cache + hesk_purge_cache('cf'); + + // Show success + $_SESSION['cford'] = $id; + hesk_process_messages($hesklang['cf_mdf'],'custom_fields.php','SUCCESS'); + +} // End save_cf() + + +function edit_cf() +{ + global $hesk_settings, $hesklang; + + // Get custom field ID + $id = intval( hesk_GET('id') ) or hesk_error($hesklang['cf_e_id']); + + // Get details from the database + $res = hesk_dbQuery("SELECT * FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` WHERE `id`={$id} LIMIT 1"); + if ( hesk_dbNumRows($res) != 1 ) + { + hesk_error($hesklang['cf_not_found']); + } + $cf = hesk_dbFetchAssoc($res); + + $cf['names'] = json_decode($cf['name'], true); + unset($cf['name']); + + if (strlen($cf['category'])) + { + $cf['categories'] = json_decode($cf['category'], true); + $cf['category'] = 1; + } + else + { + $cf['categories'] = array(); + $cf['category'] = 0; + } + + $_SESSION['new_cf'] = $cf; + $_SESSION['edit_cf'] = true; + +} // End edit_cf() + + +function order_cf() +{ + global $hesk_settings, $hesklang; + + // A security check + hesk_token_check(); + + // Get ID and move parameters + $id = intval( hesk_GET('id') ) or hesk_error($hesklang['cf_e_id']); + $move = intval( hesk_GET('move') ); + $_SESSION['cford'] = $id; + + // Update article details + hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` SET `order`=`order`+".intval($move)." WHERE `id`={$id}"); + + // Update order of all custom fields + update_cf_order(); + + // Clear cache + hesk_purge_cache('cf'); + + // Finish + header('Location: custom_fields.php'); + exit(); + +} // End order_cf() + + +function update_cf_order() +{ + global $hesk_settings, $hesklang; + + // Get list of current custom fields + $res = hesk_dbQuery("SELECT `id` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` WHERE `use` IN ('1','2') ORDER BY `place` ASC, `order` ASC"); + + // Update database + $i = 10; + while ( $cf = hesk_dbFetchAssoc($res) ) + { + hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` SET `order`=".intval($i)." WHERE `id`='".intval($cf['id'])."'"); + $i += 10; + } + + hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` SET `order`=1000 WHERE `use`='0'"); + + return true; + +} // END update_cf_order() + + +function remove_cf() +{ + global $hesk_settings, $hesklang; + + // A security check + hesk_token_check(); + + // Get ID + $id = intval( hesk_GET('id') ) or hesk_error($hesklang['cf_e_id']); + + // Reset the custom field + hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` SET `use`='0', `place`='0', `type`='text', `req`='0', `category`=NULL, `name`='', `value`=NULL, `order`=1000 WHERE `id`={$id}"); + + // Were we successful? + if ( hesk_dbAffectedRows() == 1 ) + { + // Update order + update_cf_order(); + + // Clear cache + hesk_purge_cache('cf'); + + // Delete custom field data from tickets + hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` SET `custom{$id}`=''"); + + // Show success message + hesk_process_messages($hesklang['cf_deleted'],'./custom_fields.php','SUCCESS'); + } + else + { + hesk_process_messages($hesklang['cf_not_found'],'./custom_fields.php'); + } + +} // End remove_cf() + + +function cf_validate() +{ + global $hesk_settings, $hesklang; + global $hesk_error_buffer; + + $hesk_error_buffer = array(); + + // Get names + $cf['names'] = hesk_POST_array('name'); + + // Make sure only valid names pass + foreach ($cf['names'] as $key => $name) + { + if ( ! isset($hesk_settings['languages'][$key])) + { + unset($cf['names'][$key]); + } + else + { + $name = is_array($name) ? '' : hesk_input($name, 0, 0, HESK_SLASH); + + if (strlen($name) < 1) + { + unset($cf['names'][$key]); + } + else + { + $cf['names'][$key] = stripslashes($name); + } + } + } + + // No name entered? + if ( ! count($cf['names'])) + { + $hesk_error_buffer[] = $hesklang['err_custname']; + } + + // Get type and values + $cf['type'] = hesk_POST('type'); + switch ($cf['type']) + { + case 'textarea': + $cf['rows'] = hesk_checkMinMax(intval(hesk_POST('rows')), 1, 100, 12); + $cf['cols'] = hesk_checkMinMax(intval(hesk_POST('cols')), 1, 500, 60); + $cf['value'] = array('rows' => $cf['rows'], 'cols' => $cf['cols']); + break; + + case 'radio': + $cf['radio_options'] = stripslashes(hesk_input(hesk_POST('radio_options'), 0, 0, HESK_SLASH)); + + $options = preg_split("/\\r\\n|\\r|\\n/", $cf['radio_options']); + + $no_default = hesk_POST('no_default') ? 1 : 0; + + $cf['value'] = array('radio_options' => $options, 'no_default' => $no_default); + + if (count($options) < 2) + { + $hesk_error_buffer[] = $hesklang['atl2']; + } + + break; + + case 'select': + $cf['select_options'] = stripslashes(hesk_input(hesk_POST('select_options'), 0, 0, HESK_SLASH)); + + $options = preg_split("/\\r\\n|\\r|\\n/", $cf['select_options']); + + $show_select = hesk_POST('show_select') ? 1 : 0; + + $cf['value'] = array('show_select' => $show_select, 'select_options' => $options); + + if (count($options) < 2) + { + $hesk_error_buffer[] = $hesklang['atl2']; + } + + break; + + case 'checkbox': + $cf['checkbox_options'] = stripslashes(hesk_input(hesk_POST('checkbox_options'), 0, 0, HESK_SLASH)); + + $options = preg_split("/\\r\\n|\\r|\\n/", $cf['checkbox_options']); + + $cf['value'] = array('checkbox_options' => $options); + + if ( ! isset($options[0]) || strlen($options[0]) < 1) + { + $hesk_error_buffer[] = $hesklang['atl1']; + } + + break; + + case 'date': + $cf['dmin'] = ''; + $cf['dmax'] = ''; + + // Minimum date + $dmin_rf = hesk_POST('dmin_rf'); + + if ($dmin_rf == 1) + { + $dmin = hesk_POST('dmin'); + + if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $dmin)) + { + $cf['dmin'] = $dmin; + } + } + elseif ($dmin_rf == 2) + { + $dmin_pm = hesk_POST('dmin_pm') == '+' ? '+' : '-'; + $dmin_num = intval(hesk_POST('dmin_num', 0)); + $dmin_type = hesk_POST('dmin_type'); + if ( ! in_array($dmin_type, array('day', 'week', 'month', 'year'))) + { + $dmin_type = 'day'; + } + + $cf['dmin'] = $dmin_pm . $dmin_num . ' ' . $dmin_type; + } + + // Maximum date + $dmax_rf = hesk_POST('dmax_rf'); + + if ($dmax_rf == 1) + { + $dmax = hesk_POST('dmax'); + + if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $dmax)) + { + $cf['dmax'] = $dmax; + } + } + elseif ($dmax_rf == 2) + { + $dmax_pm = hesk_POST('dmax_pm') == '+' ? '+' : '-'; + $dmax_num = intval(hesk_POST('dmax_num', 0)); + $dmax_type = hesk_POST('dmax_type'); + if ( ! in_array($dmax_type, array('day', 'week', 'month', 'year'))) + { + $dmax_type = 'day'; + } + + $cf['dmax'] = $dmax_pm . $dmax_num . ' ' . $dmax_type; + } + + // Minimum date should not be higher than maximum date + if (strlen($cf['dmin']) && strlen($cf['dmax'])) + { + if (strtotime($cf['dmin']) > strtotime($cf['dmax'])) + { + $hesk_error_buffer[] = $hesklang['d_mm']; + } + } + + // Date format + $date_format = hesk_POST('date_format'); + if ($date_format == 'custom') + { + $date_format = hesk_POST('date_format_custom'); + } + + $cf['date_format'] = preg_replace('/[^a-zA-Z0-9 \/\.\_+\-,;:#(){}\[\]\'@*]/', '', $date_format); + + $cf['value'] = array('dmin' => $cf['dmin'], 'dmax' => $cf['dmax'], 'date_format' => $cf['date_format']); + + break; + + case 'email': + $cf['email_multi'] = hesk_POST('email_multi') ? 1 : 0; + $cf['email_type'] = hesk_POST('email_type', 'none'); + $cf['value'] = array('multiple' => $cf['email_multi'], 'email_type' => $cf['email_type']); + break; + + case 'hidden': + $cf['hidden_max_length'] = hesk_checkMinMax(intval(hesk_POST('hidden_max_length')), 1, 10000, 255); + $cf['hidden_default_value'] = stripslashes(hesk_input(hesk_POST('hidden_default_value'), 0, 0, HESK_SLASH)); + $cf['value'] = array('max_length' => $cf['hidden_max_length'], 'default_value' => $cf['hidden_default_value']); + break; + + case 'readonly': + $max_length = hesk_POST('max_length'); + $value = hesk_POST('default_value'); + $cf['value'] = array('default_value' => $value, 'max_length' => $max_length); + break; + + default: + $cf['type'] = 'text'; + $cf['max_length'] = hesk_checkMinMax(intval(hesk_POST('max_length')), 1, 10000, 255); + $cf['default_value'] = stripslashes(hesk_input(hesk_POST('default_value'), 0, 0, HESK_SLASH)); + $cf['value'] = array('max_length' => $cf['max_length'], 'default_value' => $cf['default_value']); + + } + + // Enable + $cf['use'] = hesk_POST('use') == 2 ? 2 : 1; + + // req + $cf['req'] = hesk_POST('req'); + $cf['req'] = $cf['req'] == 2 ? 2 : ($cf['req'] == 1 ? 1 : 0); + + // Private fields cannot be req for customers + if ($cf['use'] == 2 && $cf['req'] == 1) + { + $cf['req'] = 0; + } + + // Located above or below "Message"? + $cf['place'] = hesk_POST('place') ? 1 : 0; + + // Get allowed categories + if (hesk_POST('category')) + { + $cf['category'] = 1; + $cf['categories'] = hesk_POST_array('categories'); + + foreach ($cf['categories'] as $key => $cat_id) + { + if ( ! isset($hesk_settings['categories'][$cat_id]) ) + { + unset($cf['categories'][$key]); + } + } + + if ( ! count($cf['categories'])) + { + $hesk_error_buffer[] = $hesklang['cf_nocat']; + } + } + else + { + $cf['category'] = 0; + $cf['categories'] = array(); + } + + // Any errors? + if (count($hesk_error_buffer)) + { + $_SESSION['new_cf'] = $cf; + return false; + } + + $cf['names'] = addslashes(json_encode($cf['names'])); + $cf['value'] = $cf['type'] == 'date' ? json_encode($cf['value']) : addslashes(json_encode($cf['value'])); + + return $cf; +} // END cf_validate() + + +function new_cf() +{ + global $hesk_settings, $hesklang; + global $hesk_error_buffer; + + // A security check + # hesk_token_check('POST'); + + // Validate inputs + if (($cf = cf_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_fields.php'); + } + + // Get the lowest available custom field ID + $res = hesk_dbQuery("SELECT `id` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` WHERE `use`='0' ORDER BY `id` ASC LIMIT 1"); + $row = hesk_dbFetchRow($res); + $_SESSION['cford'] = intval($row[0]); + + // Insert custom field into database + hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` SET + `use` = '{$cf['use']}', + `place` = '{$cf['place']}', + `type` = '{$cf['type']}', + `req` = '{$cf['req']}', + `category` = ".(count($cf['categories']) ? "'".json_encode($cf['categories'])."'" : 'NULL').", + `name` = '".hesk_dbEscape($cf['names'])."', + `value` = ".(strlen($cf['value']) ? "'".hesk_dbEscape($cf['value'])."'" : 'NULL').", + `order` = 990 + WHERE `id`={$_SESSION['cford']}"); + + // Update order + update_cf_order(); + + // Clear cache + hesk_purge_cache('cf'); + + // Show success + hesk_process_messages($hesklang['cf_added'],'custom_fields.php','SUCCESS'); + +} // End new_cf() diff --git a/admin/delete_tickets.php b/admin/delete_tickets.php index 4880d4cb..b6b8d014 100644 --- a/admin/delete_tickets.php +++ b/admin/delete_tickets.php @@ -131,7 +131,7 @@ if (array_key_exists($_POST['a'], $priorities)) { hesk_okCategory($ticket['category']); $revision = sprintf($hesklang['thist8'], hesk_date(), $priority['formatted'], $_SESSION['name'] . ' (' . $_SESSION['user'] . ')'); - hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `priority`='{$priority['value']}', `history`=CONCAT(`history`,'" . hesk_dbEscape($revision) . "') WHERE `id`={$this_id} LIMIT 1"); + hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `priority`='{$priority['value']}', `history`=CONCAT(`history`,'" . hesk_dbEscape($revision) . "') WHERE `id`={$this_id}"); $i++; } @@ -223,7 +223,7 @@ elseif ($_POST['a'] == 'tag' || $_POST['a'] == 'untag') { hesk_okCategory($ticket['category']); - hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `archive`='$archived' WHERE `id`='" . intval($this_id) . "' LIMIT 1"); + hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `archive`='$archived' WHERE `id`='" . intval($this_id) . "'"); $i++; } @@ -233,6 +233,7 @@ else { /* Check permissions for this feature */ hesk_checkPermission('can_view_tickets'); hesk_checkPermission('can_reply_tickets'); + hesk_checkPermission('can_resolve'); /* A security check */ hesk_token_check('POST'); @@ -255,7 +256,7 @@ else { $closedStatusRS = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` WHERE `IsStaffClosedOption` = 1"); $closedStatus = hesk_dbFetchAssoc($closedStatusRS); - hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `status`='" . $closedStatus['ID'] . "', `closedat`=NOW(), `closedby`=" . intval($_SESSION['id']) . ", `history`=CONCAT(`history`,'" . hesk_dbEscape($revision) . "') WHERE `id`='" . intval($this_id) . "' LIMIT 1"); + hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `status`='" . $closedStatus['ID'] . "', `closedat`=NOW(), `closedby`=" . intval($_SESSION['id']) . ", `history`=CONCAT(`history`,'" . hesk_dbEscape($revision) . "') WHERE `id`='" . intval($this_id) . "'"); $i++; // Notify customer of closed ticket? diff --git a/admin/edit_post.php b/admin/edit_post.php index 7e0f36a0..779c8400 100644 --- a/admin/edit_post.php +++ b/admin/edit_post.php @@ -31,12 +31,14 @@ define('IN_SCRIPT', 1); define('HESK_PATH', '../'); define('WYSIWYG', 1); +define('VALIDATOR', 1); /* Get all the required files and functions */ require(HESK_PATH . 'hesk_settings.inc.php'); require(HESK_PATH . 'inc/common.inc.php'); require(HESK_PATH . 'inc/admin_functions.inc.php'); require(HESK_PATH . 'inc/mail_functions.inc.php'); +require(HESK_PATH . 'inc/custom_fields.inc.php'); hesk_load_database_functions(); hesk_session_start(); @@ -56,6 +58,10 @@ $trackingID = hesk_cleanID() or die($hesklang['int_error'] . ': ' . $hesklang['n $is_reply = 0; $tmpvar = array(); +if (!isset($_SESSION['iserror'])) { + $_SESSION['iserror'] = array(); +} + /* Get ticket info */ $result = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` WHERE `trackid`='" . hesk_dbEscape($trackingID) . "' LIMIT 1"); if (hesk_dbNumRows($result) != 1) { @@ -111,13 +117,29 @@ if (isset($_POST['save'])) { $tmpvar['html'] = hesk_POST('html'); - hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "replies` SET `html`='" . $tmpvar['html'] . "', `message`='" . hesk_dbEscape($tmpvar['message']) . "' WHERE `id`='" . intval($tmpvar['id']) . "' AND `replyto`='" . intval($ticket['id']) . "' LIMIT 1"); + hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "replies` SET `html`='" . $tmpvar['html'] . "', `message`='" . hesk_dbEscape($tmpvar['message']) . "' WHERE `id`='" . intval($tmpvar['id']) . "' AND `replyto`='" . intval($ticket['id']) . "'"); } else { $tmpvar['language'] = hesk_POST('customerLanguage'); $tmpvar['name'] = hesk_input(hesk_POST('name')) or $hesk_error_buffer[] = $hesklang['enter_your_name']; - $tmpvar['email'] = hesk_validateEmail(hesk_POST('email'), 'ERR', 0); + + if ($hesk_settings['require_email']) { + $tmpvar['email'] = hesk_validateEmail( hesk_POST('email'), 'ERR', 0) or $hesk_error_buffer['email']=$hesklang['enter_valid_email']; + } else { + $tmpvar['email'] = hesk_validateEmail( hesk_POST('email'), 'ERR', 0); + + // Not required, but must be valid if it is entered + if ($tmpvar['email'] == '') { + if (strlen(hesk_POST('email'))) { + $hesk_error_buffer['email'] = $hesklang['not_valid_email']; + } + } + } + $tmpvar['subject'] = hesk_input(hesk_POST('subject')) or $hesk_error_buffer[] = $hesklang['enter_ticket_subject']; - $tmpvar['message'] = hesk_input(hesk_POST('message')) or $hesk_error_buffer[] = $hesklang['enter_message']; + $tmpvar['message'] = hesk_input( hesk_POST('message') ); + if ($hesk_settings['require_message'] == 1 && $tmpvar['message'] == '') { + $hesk_error_buffer[] = $hesklang['enter_message']; + } $tmpvar['html'] = hesk_POST('html'); // Demo mode @@ -125,6 +147,82 @@ if (isset($_POST['save'])) { $tmpvar['email'] = 'hidden@demo.com'; } + // Custom fields + foreach ($hesk_settings['custom_fields'] as $k=>$v) { + if ($v['use'] && hesk_is_custom_field_in_category($k, $ticket['category'])) { + if ($v['req'] == 2) { + $v['req'] = '*'; + $required_attribute = 'data-error="' . $hesklang['this_field_is_required'] . '" required'; + } else { + $v['req'] = ''; + $required_attribute = ''; + } + + if ($v['type'] == 'checkbox') { + $tmpvar[$k]=''; + + if (isset($_POST[$k]) && is_array($_POST[$k])) { + foreach ($_POST[$k] as $myCB) { + $tmpvar[$k] .= ( is_array($myCB) ? '' : hesk_input($myCB) ) . '
    '; + } + $tmpvar[$k]=substr($tmpvar[$k],0,-6); + } else { + if ($v['req'] == 2) { + $hesk_error_buffer[$k]=$hesklang['fill_all'].': '.$v['name']; + } + $_POST[$k] = ''; + } + } elseif ($v['type'] == 'date') { + $tmpvar[$k] = hesk_POST($k); + $_SESSION["as_$k"] = ''; + + if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $tmpvar[$k])) { + $date = strtotime($tmpvar[$k] . ' t00:00:00'); + $dmin = strlen($v['value']['dmin']) ? strtotime($v['value']['dmin'] . ' t00:00:00') : false; + $dmax = strlen($v['value']['dmax']) ? strtotime($v['value']['dmax'] . ' t00:00:00') : false; + + $_SESSION["as_$k"] = $tmpvar[$k]; + + if ($dmin && $dmin > $date) { + $hesk_error_buffer[$k] = sprintf($hesklang['d_emin'], $v['name'], hesk_custom_date_display_format($dmin, $v['value']['date_format'])); + } elseif ($dmax && $dmax < $date) { + $hesk_error_buffer[$k] = sprintf($hesklang['d_emax'], $v['name'], hesk_custom_date_display_format($dmax, $v['value']['date_format'])); + } else { + $tmpvar[$k] = $date; + } + } else { + if ($v['req'] == 2) { + $hesk_error_buffer[$k]=$hesklang['fill_all'].': '.$v['name']; + } + } + } elseif ($v['type'] == 'email') { + $tmp = $hesk_settings['multi_eml']; + $hesk_settings['multi_eml'] = $v['value']['multiple']; + $tmpvar[$k] = hesk_validateEmail( hesk_POST($k), 'ERR', 0); + $hesk_settings['multi_eml'] = $tmp; + + if ($tmpvar[$k] != '') { + $_SESSION["as_$k"] = hesk_input($tmpvar[$k]); + } else { + $_SESSION["as_$k"] = ''; + + if ($v['req'] == 2) { + $hesk_error_buffer[$k] = $v['value']['multiple'] ? sprintf($hesklang['cf_noem'], $v['name']) : sprintf($hesklang['cf_noe'], $v['name']); + } + } + } elseif ($v['req'] == 2) { + $tmpvar[$k]=hesk_makeURL(nl2br(hesk_input( hesk_POST($k) ))); + if ($tmpvar[$k] == '') { + $hesk_error_buffer[$k]=$hesklang['fill_all'].': '.$v['name']; + } + } else { + $tmpvar[$k]=hesk_makeURL(nl2br(hesk_input(hesk_POST($k)))); + } + } else { + $tmpvar[$k] = ''; + } + } + if (count($hesk_error_buffer)) { $myerror = '