2014-03-23 16:03:30 -04:00
< ? php
/*******************************************************************************
2015-09-12 00:46:46 -04:00
* Title : Help Desk Software HESK
2016-04-18 18:34:50 -04:00
* Version : 2.6 . 7 from 18 th April 2016
2015-09-12 00:46:46 -04:00
* Author : Klemen Stirn
* Website : http :// www . hesk . com
********************************************************************************
* COPYRIGHT AND TRADEMARK NOTICE
* Copyright 2005 - 2015 Klemen Stirn . All Rights Reserved .
* HESK is a registered trademark of Klemen Stirn .
* The HESK may be used and modified free of charge by anyone
* AS LONG AS COPYRIGHT NOTICES AND ALL THE COMMENTS REMAIN INTACT .
* By using this code you agree to indemnify Klemen Stirn from any
* liability that might arise from it ' s use .
* Selling the code for this program , in part or full , without prior
* written consent is expressly forbidden .
* Using this code , in part or full , to create derivate work ,
* new scripts or products is expressly forbidden . Obtain permission
* before redistributing this software over the Internet or in
* any other medium . In all cases copyright and header must remain intact .
* This Copyright is in full effect in any country that has International
* Trade Agreements with the United States of America or
* with the European Union .
* Removing any of the copyright notices without purchasing a license
* is expressly forbidden . To remove HESK copyright notice you must purchase
* a license for this script . For more information on how to obtain
* a license please visit the page below :
* https :// www . hesk . com / buy . php
*******************************************************************************/
2014-03-23 16:03:30 -04:00
/* Check if this is a valid include */
2015-09-12 00:46:46 -04:00
if ( ! defined ( 'IN_SCRIPT' )) {
die ( 'Invalid attempt' );
}
2014-03-23 16:03:30 -04:00
#error_reporting(E_ALL);
2015-08-29 21:29:35 -04:00
// Set correct Content-Type header
2015-09-12 00:46:46 -04:00
if ( ! defined ( 'NO_HTTP_HEADER' )) {
header ( 'Content-Type: text/html; charset=utf-8' );
2015-08-29 21:29:35 -04:00
}
2014-03-23 16:03:30 -04:00
// Set backslash options
2015-09-12 00:46:46 -04:00
if ( get_magic_quotes_gpc ()) {
define ( 'HESK_SLASH' , false );
} else {
define ( 'HESK_SLASH' , true );
2014-03-23 16:03:30 -04:00
}
// Define some constants for backward-compatibility
2015-09-12 00:46:46 -04:00
if ( ! defined ( 'ENT_SUBSTITUTE' )) {
define ( 'ENT_SUBSTITUTE' , 0 );
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
if ( ! defined ( 'ENT_XHTML' )) {
define ( 'ENT_XHTML' , 0 );
2014-03-23 16:03:30 -04:00
}
// Load language file
hesk_getLanguage ();
/*** FUNCTIONS ***/
2015-01-12 12:49:00 -05:00
function hesk_service_message ( $sm )
{
2015-05-08 12:05:16 -04:00
$faIcon = $sm [ 'icon' ];
2015-09-12 00:46:46 -04:00
switch ( $sm [ 'style' ]) {
2015-01-12 12:49:00 -05:00
case 1 :
2015-01-14 16:57:20 -05:00
$style = " alert alert-success " ;
2015-01-12 12:49:00 -05:00
break ;
case 2 :
2015-01-14 16:57:20 -05:00
$style = " alert alert-info " ;
2015-01-12 12:49:00 -05:00
break ;
case 3 :
2015-01-14 16:57:20 -05:00
$style = " alert alert-warning " ;
2015-01-12 12:49:00 -05:00
break ;
case 4 :
2015-01-14 16:57:20 -05:00
$style = " alert alert-danger " ;
2015-01-12 12:49:00 -05:00
break ;
default :
$style = " none " ;
}
?>
< div class = " <?php echo $style ; ?> " >
2015-09-12 00:46:46 -04:00
< ? php echo $faIcon == '' ? '' : '<i class="' . $faIcon . '"></i> ' ; ?>
2015-01-14 16:57:20 -05:00
< b >< ? php echo $sm [ 'title' ]; ?> </b><?php echo $sm['message']; ?>
2015-01-12 12:49:00 -05:00
</ div >
2015-09-12 00:46:46 -04:00
< br />
< ? php
2015-01-12 12:49:00 -05:00
} // END hesk_service_message()
function hesk_isBannedIP ( $ip )
{
global $hesk_settings , $hesklang , $hesk_db_link ;
$ip = ip2long ( $ip ) or $ip = 0 ;
2015-02-22 22:16:36 -05:00
// We need positive value of IP
2015-09-12 00:46:46 -04:00
if ( $ip < 0 ) {
2015-02-22 22:16:36 -05:00
$ip += 4294967296 ;
2015-09-12 00:46:46 -04:00
} elseif ( $ip > 4294967296 ) {
2015-02-22 22:16:36 -05:00
$ip = 4294967296 ;
}
2015-09-12 00:46:46 -04:00
$res = hesk_dbQuery ( " SELECT `id` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " banned_ips` WHERE { $ip } BETWEEN `ip_from` AND `ip_to` LIMIT 1 " );
2015-01-12 12:49:00 -05:00
2015-09-12 00:46:46 -04:00
return ( hesk_dbNumRows ( $res ) == 1 ) ? hesk_dbResult ( $res ) : false ;
2015-01-12 12:49:00 -05:00
} // END hesk_isBannedIP()
function hesk_isBannedEmail ( $email )
{
global $hesk_settings , $hesklang , $hesk_db_link ;
$email = strtolower ( $email );
2015-09-12 00:46:46 -04:00
$res = hesk_dbQuery ( " SELECT `id` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " banned_emails` WHERE `email` IN (' " . hesk_dbEscape ( $email ) . " ', ' " . hesk_dbEscape ( substr ( $email , strrpos ( $email , " @ " ))) . " ') LIMIT 1 " );
2015-01-12 12:49:00 -05:00
2015-09-12 00:46:46 -04:00
return ( hesk_dbNumRows ( $res ) == 1 ) ? hesk_dbResult ( $res ) : false ;
2015-01-12 12:49:00 -05:00
} // END hesk_isBannedEmail()
2014-03-23 16:03:30 -04:00
function hesk_clean_utf8 ( $in )
{
2015-09-12 00:46:46 -04:00
//reject overly long 2 byte sequences, as well as characters above U+10000 and replace with ?
$in = preg_replace ( '/[\x00-\x08\x10\x0B\x0C\x0E-\x19\x7F]' .
'|[\x00-\x7F][\x80-\xBF]+' .
'|([\xC0\xC1]|[\xF0-\xFF])[\x80-\xBF]*' .
'|[\xC2-\xDF]((?![\x80-\xBF])|[\x80-\xBF]{2,})' .
'|[\xE0-\xEF](([\x80-\xBF](?![\x80-\xBF]))|(?![\x80-\xBF]{2})|[\x80-\xBF]{3,})/S' ,
'?' , $in );
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
//reject overly long 3 byte sequences and UTF-16 surrogates and replace with ?
$in = preg_replace ( '/\xE0[\x80-\x9F][\x80-\xBF]' .
'|\xED[\xA0-\xBF][\x80-\xBF]/S' , '?' , $in );
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
return $in ;
2014-03-23 16:03:30 -04:00
} // END hesk_clean_utf8()
function hesk_load_database_functions ()
{
2015-09-12 00:46:46 -04:00
// Preferrably use the MySQLi functions
if ( function_exists ( 'mysqli_connect' )) {
require ( HESK_PATH . 'inc/database_mysqli.inc.php' );
} // Default to MySQL
else {
require ( HESK_PATH . 'inc/database.inc.php' );
}
2014-03-23 16:03:30 -04:00
} // END hesk_load_database_functions()
2015-10-15 22:31:24 -04:00
function hesk_load_api_database_functions ()
{
require ( HESK_PATH . 'api/core/json_error.php' );
// Preferrably use the MySQLi functions
if ( function_exists ( 'mysqli_connect' )) {
require ( HESK_PATH . 'api/core/database_mysqli.inc.php' );
} // Default to MySQL
else {
require ( HESK_PATH . 'api/core/database.inc.php' );
}
} // END hesk_load_database_functions()
2015-11-17 21:27:57 -05:00
function hesk_load_internal_api_database_functions ()
{
require ( HESK_PATH . 'internal-api/core/json_error.php' );
// Preferrably use the MySQLi functions
if ( function_exists ( 'mysqli_connect' )) {
require ( HESK_PATH . 'internal-api/core/database_mysqli.inc.php' );
} // Default to MySQL
else {
require ( HESK_PATH . 'internal-api/core/database.inc.php' );
}
} // END hesk_load_database_functions()
2016-04-20 21:44:13 -04:00
function hesk_load_cron_database_functions ()
{
if ( function_exists ( 'mysqli_connect' )) {
require ( HESK_PATH . 'cron/core/database_mysqli.inc.php' );
} // Default to MySQL
else {
require ( HESK_PATH . 'cron/core/database.inc.php' );
}
} // END hesk_load_cron_database_functions()
2015-09-12 00:46:46 -04:00
function hesk_unlink ( $file , $older_than = 0 )
2014-03-23 16:03:30 -04:00
{
2015-09-12 00:46:46 -04:00
return ( is_file ( $file ) && ( ! $older_than || ( time () - filectime ( $file )) > $older_than ) && @ unlink ( $file )) ? true : false ;
2014-03-23 16:03:30 -04:00
} // END hesk_unlink()
function hesk_utf8_urldecode ( $in )
{
2015-09-12 00:46:46 -04:00
$in = preg_replace ( " /%u([0-9a-f] { 3,4})/i " , " &#x \\ 1; " , urldecode ( $in ));
return hesk_html_entity_decode ( $in );
2014-03-23 16:03:30 -04:00
} // END hesk_utf8_urldecode
2016-04-18 18:34:50 -04:00
function hesk_SESSION ( $in , $default = '' )
{
return isset ( $_SESSION [ $in ]) && ! is_array ( $_SESSION [ $in ]) ? $_SESSION [ $in ] : $default ;
} // END hesk_SESSION();
2014-03-23 16:03:30 -04:00
function hesk_COOKIE ( $in , $default = '' )
{
2015-09-12 00:46:46 -04:00
return isset ( $_COOKIE [ $in ]) && ! is_array ( $_COOKIE [ $in ]) ? $_COOKIE [ $in ] : $default ;
2014-03-23 16:03:30 -04:00
} // END hesk_COOKIE();
function hesk_GET ( $in , $default = '' )
{
2015-09-12 00:46:46 -04:00
return isset ( $_GET [ $in ]) && ! is_array ( $_GET [ $in ]) ? $_GET [ $in ] : $default ;
2014-03-23 16:03:30 -04:00
} // END hesk_GET()
function hesk_POST ( $in , $default = '' )
{
2015-09-12 00:46:46 -04:00
return isset ( $_POST [ $in ]) && ! is_array ( $_POST [ $in ]) ? $_POST [ $in ] : $default ;
2014-03-23 16:03:30 -04:00
} // END hesk_POST()
2015-09-12 00:46:46 -04:00
function hesk_POST_array ( $in , $default = array ())
2015-01-12 12:49:00 -05:00
{
return isset ( $_POST [ $in ]) && is_array ( $_POST [ $in ]) ? $_POST [ $in ] : $default ;
} // END hesk_POST_array()
2014-03-23 16:03:30 -04:00
function hesk_REQUEST ( $in , $default = false )
{
2015-09-12 00:46:46 -04:00
return isset ( $_GET [ $in ]) ? hesk_input ( hesk_GET ( $in )) : ( isset ( $_POST [ $in ]) ? hesk_input ( hesk_POST ( $in )) : $default );
2014-03-23 16:03:30 -04:00
} // END hesk_REQUEST()
function hesk_isREQUEST ( $in )
{
2015-09-12 00:46:46 -04:00
return isset ( $_GET [ $in ]) || isset ( $_POST [ $in ]) ? true : false ;
2014-03-23 16:03:30 -04:00
} // END hesk_isREQUEST()
function hesk_htmlspecialchars_decode ( $in )
{
2015-09-12 00:46:46 -04:00
return str_replace ( array ( '&' , '<' , '>' , '"' ), array ( '&' , '<' , '>' , '"' ), $in );
2014-03-23 16:03:30 -04:00
} // END hesk_htmlspecialchars_decode()
function hesk_html_entity_decode ( $in )
{
2015-09-12 00:46:46 -04:00
return html_entity_decode ( $in , ENT_COMPAT | ENT_XHTML , 'UTF-8' );
2014-03-23 16:03:30 -04:00
#return html_entity_decode($in, ENT_COMPAT | ENT_XHTML, 'ISO-8859-1');
} // END hesk_html_entity_decode()
function hesk_htmlspecialchars ( $in )
{
2015-09-12 00:46:46 -04:00
return htmlspecialchars ( $in , ENT_COMPAT | ENT_SUBSTITUTE | ENT_XHTML , 'UTF-8' );
2014-03-23 16:03:30 -04:00
#return htmlspecialchars($in, ENT_COMPAT | ENT_SUBSTITUTE | ENT_XHTML, 'ISO-8859-1');
} // END hesk_htmlspecialchars()
function hesk_htmlentities ( $in )
{
2015-09-12 00:46:46 -04:00
return htmlentities ( $in , ENT_COMPAT | ENT_SUBSTITUTE | ENT_XHTML , 'UTF-8' );
2014-03-23 16:03:30 -04:00
#return htmlentities($in, ENT_COMPAT | ENT_SUBSTITUTE | ENT_XHTML, 'ISO-8859-1');
} // END hesk_htmlentities()
function hesk_slashJS ( $in )
{
2015-09-12 00:46:46 -04:00
return str_replace ( '\'' , '\\\'' , $in );
2014-03-23 16:03:30 -04:00
} // END hesk_slashJS()
function hesk_verifyEmailMatch ( $trackingID , $my_email = 0 , $ticket_email = 0 , $error = 1 )
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang , $hesk_db_link ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* Email required to view ticket? */
if ( ! $hesk_settings [ 'email_view_ticket' ]) {
$hesk_settings [ 'e_param' ] = '' ;
2014-03-23 16:03:30 -04:00
$hesk_settings [ 'e_query' ] = '' ;
2016-04-18 18:34:50 -04:00
$hesk_settings [ 'e_email' ] = '' ;
2015-09-12 00:46:46 -04:00
return true ;
}
/* Limit brute force attempts */
hesk_limitBfAttempts ();
/* Get email address */
if ( $my_email ) {
$hesk_settings [ 'e_param' ] = '&e=' . rawurlencode ( $my_email );
$hesk_settings [ 'e_query' ] = '&e=' . rawurlencode ( $my_email );
2016-04-18 18:34:50 -04:00
$hesk_settings [ 'e_email' ] = $my_email ;
2015-09-12 00:46:46 -04:00
} else {
$my_email = hesk_getCustomerEmail ();
}
/* Get email from ticket */
if ( ! $ticket_email ) {
$res = hesk_dbQuery ( " SELECT `email` FROM ` " . $hesk_settings [ 'db_pfix' ] . " tickets` WHERE `trackid`=' " . hesk_dbEscape ( $trackingID ) . " ' LIMIT 1 " );
if ( hesk_dbNumRows ( $res ) == 1 ) {
$ticket_email = hesk_dbResult ( $res );
} else {
hesk_process_messages ( $hesklang [ 'ticket_not_found' ], 'ticket.php' );
}
}
/* Validate email */
if ( $hesk_settings [ 'multi_eml' ]) {
2016-04-30 00:42:56 -04:00
$ticket_email = str_replace ( ';' , ',' , $ticket_email );
2015-09-12 00:46:46 -04:00
$valid_emails = explode ( ',' , strtolower ( $ticket_email ));
if ( in_array ( strtolower ( $my_email ), $valid_emails )) {
/* Match, clean brute force attempts and return true */
hesk_cleanBfAttempts ();
return true ;
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
} elseif ( strtolower ( $ticket_email ) == strtolower ( $my_email )) {
/* Match, clean brute force attempts and return true */
hesk_cleanBfAttempts ();
return true ;
}
/* Email doesn't match, clean cookies and error out */
if ( $error ) {
setcookie ( 'hesk_myemail' , '' );
hesk_process_messages ( $hesklang [ 'enmdb' ], 'ticket.php?track=' . $trackingID . '&Refresh=' . rand ( 10000 , 99999 ));
} else {
return false ;
2014-03-23 16:03:30 -04:00
}
} // END hesk_verifyEmailMatch()
2016-04-18 18:34:50 -04:00
function hesk_getCustomerEmail ( $can_remember = 0 , $field = '' )
2014-03-23 16:03:30 -04:00
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* Email required to view ticket? */
if ( ! $hesk_settings [ 'email_view_ticket' ]) {
$hesk_settings [ 'e_param' ] = '' ;
$hesk_settings [ 'e_query' ] = '' ;
2016-04-18 18:34:50 -04:00
$hesk_settings [ 'e_email' ] = '' ;
2015-09-12 00:46:46 -04:00
return '' ;
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
/* Is this a form that enables remembering email? */
if ( $can_remember ) {
global $do_remember ;
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
$my_email = '' ;
2014-03-23 16:03:30 -04:00
2016-04-18 18:34:50 -04:00
/* Is email in session? */
if ( strlen ( $field ) && isset ( $_SESSION [ $field ]) )
{
$my_email = hesk_validateEmail ( $_SESSION [ $field ], 'ERR' , 0 );
}
2015-09-12 00:46:46 -04:00
/* Is email in query string? */
if ( isset ( $_GET [ 'e' ]) || isset ( $_POST [ 'e' ])) {
$my_email = hesk_validateEmail ( hesk_REQUEST ( 'e' ), 'ERR' , 0 );
} /* Is email in cookie? */
2016-04-18 18:34:50 -04:00
elseif ( isset ( $_GET [ 'e' ]) || isset ( $_POST [ 'e' ]) ) {
2015-09-12 00:46:46 -04:00
$my_email = hesk_validateEmail ( hesk_COOKIE ( 'hesk_myemail' ), 'ERR' , 0 );
if ( $can_remember && $my_email ) {
$do_remember = ' checked="checked" ' ;
}
}
2014-03-23 16:03:30 -04:00
$hesk_settings [ 'e_param' ] = '&e=' . rawurlencode ( $my_email );
$hesk_settings [ 'e_query' ] = '&e=' . rawurlencode ( $my_email );
2016-04-18 18:34:50 -04:00
$hesk_settings [ 'e_email' ] = $my_email ;
2014-03-23 16:03:30 -04:00
return $my_email ;
} // END hesk_getCustomerEmail()
function hesk_formatBytes ( $size , $translate_unit = 1 , $precision = 2 )
{
2015-09-12 00:46:46 -04:00
global $hesklang ;
2014-03-23 16:03:30 -04:00
$units = array (
2015-09-12 00:46:46 -04:00
'GB' => 1073741824 ,
2014-03-23 16:03:30 -04:00
'MB' => 1048576 ,
'kB' => 1024 ,
2015-09-12 00:46:46 -04:00
'B' => 1
2014-03-23 16:03:30 -04:00
);
2015-09-12 00:46:46 -04:00
foreach ( $units as $suffix => $bytes ) {
if ( $bytes > $size ) {
continue ;
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
$full = $size / $bytes ;
2014-03-23 16:03:30 -04:00
$round = round ( $full , $precision );
2015-09-12 00:46:46 -04:00
if ( $full == $round ) {
if ( $translate_unit ) {
return $round . ' ' . $hesklang [ $suffix ];
} else {
return $round . ' ' . $suffix ;
2014-03-23 16:03:30 -04:00
}
}
}
return false ;
} // End hesk_formatBytes()
function hesk_autoAssignTicket ( $ticket_category )
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* Auto assign ticket enabled? */
if ( ! $hesk_settings [ 'autoassign' ]) {
return false ;
}
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
$autoassign_owner = array ();
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* Get all possible auto-assign staff, order by number of open tickets */
$res = hesk_dbQuery ( " SELECT `t1`.`id`,`t1`.`user`,`t1`.`name`, `t1`.`email`, `t1`.`language`, `t1`.`isadmin`, `t1`.`categories`, `t1`.`notify_assigned`, `t1`.`heskprivileges`,
( SELECT COUNT ( * ) FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` FORCE KEY ( `statuses` ) WHERE `owner` = `t1` . `id` AND `status` IN ( SELECT `ID` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` WHERE `IsClosed` = 0 ) ) as `open_tickets`
FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` AS `t1`
2014-03-23 16:03:30 -04:00
WHERE `t1` . `autoassign` = '1' ORDER BY `open_tickets` ASC , RAND () " );
2015-09-12 00:46:46 -04:00
/* Loop through the rows and return the first appropriate one */
while ( $myuser = hesk_dbFetchAssoc ( $res )) {
/* Is this an administrator? */
if ( $myuser [ 'isadmin' ]) {
$autoassign_owner = $myuser ;
2014-03-23 16:03:30 -04:00
$hesk_settings [ 'user_data' ][ $myuser [ 'id' ]] = $myuser ;
2015-09-12 00:46:46 -04:00
hesk_dbFreeResult ( $res );
break ;
}
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* Not and administrator, check two things: */
2014-03-23 16:03:30 -04:00
/* --> can view and reply to tickets */
2015-09-12 00:46:46 -04:00
if ( strpos ( $myuser [ 'heskprivileges' ], 'can_view_tickets' ) === false || strpos ( $myuser [ 'heskprivileges' ], 'can_reply_tickets' ) === false ) {
continue ;
}
2014-03-23 16:03:30 -04:00
/* --> has access to ticket category */
2015-09-12 00:46:46 -04:00
$myuser [ 'categories' ] = explode ( ',' , $myuser [ 'categories' ]);
if ( in_array ( $ticket_category , $myuser [ 'categories' ])) {
$autoassign_owner = $myuser ;
2014-03-23 16:03:30 -04:00
$hesk_settings [ 'user_data' ][ $myuser [ 'id' ]] = $myuser ;
2015-09-12 00:46:46 -04:00
hesk_dbFreeResult ( $res );
break ;
}
}
2014-03-23 16:03:30 -04:00
return $autoassign_owner ;
} // END hesk_autoAssignTicket()
2015-09-12 00:46:46 -04:00
function hesk_cleanID ( $field = 'track' )
2014-03-23 16:03:30 -04:00
{
2016-04-18 18:34:50 -04:00
if ( isset ( $_SESSION [ $field ]) ) {
return substr ( preg_replace ( '/[^A-Z0-9\-]/' , '' , strtoupper ( $_SESSION [ $field ])), 0 , 12 );
} elseif ( isset ( $_GET [ $field ]) && ! is_array ( $_GET [ $field ]) ) {
2015-09-12 00:46:46 -04:00
return substr ( preg_replace ( '/[^A-Z0-9\-]/' , '' , strtoupper ( $_GET [ $field ])), 0 , 12 );
} elseif ( isset ( $_POST [ $field ]) && ! is_array ( $_POST [ $field ])) {
return substr ( preg_replace ( '/[^A-Z0-9\-]/' , '' , strtoupper ( $_POST [ $field ])), 0 , 12 );
} else {
return false ;
2014-03-23 16:03:30 -04:00
}
} // END hesk_cleanID()
function hesk_createID ()
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang , $hesk_error_buffer ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/*** Generate tracking ID and make sure it's not a duplicate one ***/
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* Ticket ID can be of these chars */
$useChars = 'AEUYBDGHJLMNPQRSTVWXZ123456789' ;
2014-03-23 16:03:30 -04:00
/* Set tracking ID to an empty string */
2015-09-12 00:46:46 -04:00
$trackingID = '' ;
/* Let's avoid duplicate ticket ID's, try up to 3 times */
for ( $i = 1 ; $i <= 3 ; $i ++ ) {
/* Generate raw ID */
$trackingID .= $useChars [ mt_rand ( 0 , 29 )];
$trackingID .= $useChars [ mt_rand ( 0 , 29 )];
$trackingID .= $useChars [ mt_rand ( 0 , 29 )];
$trackingID .= $useChars [ mt_rand ( 0 , 29 )];
$trackingID .= $useChars [ mt_rand ( 0 , 29 )];
$trackingID .= $useChars [ mt_rand ( 0 , 29 )];
$trackingID .= $useChars [ mt_rand ( 0 , 29 )];
$trackingID .= $useChars [ mt_rand ( 0 , 29 )];
$trackingID .= $useChars [ mt_rand ( 0 , 29 )];
$trackingID .= $useChars [ mt_rand ( 0 , 29 )];
/* Format the ID to the correct shape and check wording */
2014-03-23 16:03:30 -04:00
$trackingID = hesk_formatID ( $trackingID );
2015-09-12 00:46:46 -04:00
/* Check for duplicate IDs */
$res = hesk_dbQuery ( " SELECT `id` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` WHERE `trackid` = ' " . hesk_dbEscape ( $trackingID ) . " ' LIMIT 1 " );
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
if ( hesk_dbNumRows ( $res ) == 0 ) {
/* Everything is OK, no duplicates found */
return $trackingID ;
2014-03-23 16:03:30 -04:00
}
/* A duplicate ID has been found! Let's try again (up to 2 more) */
$trackingID = '' ;
}
/* No valid tracking ID, try one more time with microtime() */
2015-09-12 00:46:46 -04:00
$trackingID = $useChars [ mt_rand ( 0 , 29 )];
$trackingID .= $useChars [ mt_rand ( 0 , 29 )];
$trackingID .= $useChars [ mt_rand ( 0 , 29 )];
$trackingID .= $useChars [ mt_rand ( 0 , 29 )];
$trackingID .= $useChars [ mt_rand ( 0 , 29 )];
$trackingID .= substr ( microtime (), - 5 );
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* Format the ID to the correct shape and check wording */
$trackingID = hesk_formatID ( $trackingID );
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
$res = hesk_dbQuery ( " SELECT `id` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` WHERE `trackid` = ' " . hesk_dbEscape ( $trackingID ) . " ' LIMIT 1 " );
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* All failed, must be a server-side problem... */
if ( hesk_dbNumRows ( $res ) == 0 ) {
return $trackingID ;
2014-03-23 16:03:30 -04:00
}
$hesk_error_buffer [ 'etid' ] = $hesklang [ 'e_tid' ];
2015-09-12 00:46:46 -04:00
return false ;
2014-03-23 16:03:30 -04:00
} // END hesk_createID()
function hesk_formatID ( $id )
{
2015-09-12 00:46:46 -04:00
$useChars = 'AEUYBDGHJLMNPQRSTVWXZ123456789' ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
$replace = $useChars [ mt_rand ( 0 , 29 )];
$replace .= mt_rand ( 1 , 9 );
$replace .= $useChars [ mt_rand ( 0 , 29 )];
2014-03-23 16:03:30 -04:00
/*
Remove 3 letter bad words from ID
Possiblitiy : 1 : 27 , 000
*/
2015-09-12 00:46:46 -04:00
$remove = array (
'ASS' ,
'CUM' ,
'FAG' ,
'FUK' ,
'GAY' ,
'SEX' ,
'TIT' ,
'XXX' ,
2014-03-23 16:03:30 -04:00
);
2015-09-12 00:46:46 -04:00
$id = str_replace ( $remove , $replace , $id );
2014-03-23 16:03:30 -04:00
/*
Remove 4 letter bad words from ID
Possiblitiy : 1 : 810 , 000
*/
2015-09-12 00:46:46 -04:00
$remove = array (
'ANAL' ,
'ANUS' ,
'BUTT' ,
'CAWK' ,
'CLIT' ,
'COCK' ,
'CRAP' ,
'CUNT' ,
'DICK' ,
'DYKE' ,
'FART' ,
'FUCK' ,
'JAPS' ,
'JERK' ,
'JIZZ' ,
'KNOB' ,
'PISS' ,
'POOP' ,
'SHIT' ,
'SLUT' ,
'SUCK' ,
'TURD' ,
// Also, remove words that are known to trigger mod_security
'WGET' ,
2014-03-23 16:03:30 -04:00
);
2015-09-12 00:46:46 -04:00
$replace .= mt_rand ( 1 , 9 );
$id = str_replace ( $remove , $replace , $id );
2014-03-23 16:03:30 -04:00
/* Format the ID string into XXX-XXX-XXXX format for easier readability */
2015-09-12 00:46:46 -04:00
$id = $id [ 0 ] . $id [ 1 ] . $id [ 2 ] . '-' . $id [ 3 ] . $id [ 4 ] . $id [ 5 ] . '-' . $id [ 6 ] . $id [ 7 ] . $id [ 8 ] . $id [ 9 ];
2014-03-23 16:03:30 -04:00
return $id ;
} // END hesk_formatID()
function hesk_cleanBfAttempts ()
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* If this feature is disabled, just return */
if ( ! $hesk_settings [ 'attempt_limit' ] || defined ( 'HESK_BF_CLEAN' )) {
return true ;
2014-03-23 16:03:30 -04:00
}
/* Delete expired logs from the database */
2015-09-12 00:46:46 -04:00
$res = hesk_dbQuery ( " DELETE FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " logins` WHERE `ip`=' " . hesk_dbEscape ( $_SERVER [ 'REMOTE_ADDR' ]) . " ' " );
2014-03-23 16:03:30 -04:00
define ( 'HESK_BF_CLEAN' , 1 );
2015-09-12 00:46:46 -04:00
return true ;
2014-03-23 16:03:30 -04:00
} // END hesk_cleanAttempts()
2015-09-12 00:46:46 -04:00
function hesk_limitBfAttempts ( $showError = 1 )
2014-03-23 16:03:30 -04:00
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
2015-01-12 12:49:00 -05:00
// Check if this IP is banned permanently
2015-09-12 00:46:46 -04:00
if ( hesk_isBannedIP ( $_SERVER [ 'REMOTE_ADDR' ])) {
2015-01-12 12:49:00 -05:00
hesk_error ( $hesklang [ 'baned_ip' ], 0 );
}
/* If this feature is disabled or already called, return false */
2015-09-12 00:46:46 -04:00
if ( ! $hesk_settings [ 'attempt_limit' ] || defined ( 'HESK_BF_LIMIT' )) {
return false ;
2014-03-23 16:03:30 -04:00
}
/* Define this constant to avoid duplicate checks */
define ( 'HESK_BF_LIMIT' , 1 );
2015-09-12 00:46:46 -04:00
$ip = $_SERVER [ 'REMOTE_ADDR' ];
2014-03-23 16:03:30 -04:00
/* Get number of failed attempts from the database */
2015-09-12 00:46:46 -04:00
$res = hesk_dbQuery ( " SELECT `number`, (CASE WHEN `last_attempt` IS NOT NULL AND DATE_ADD(`last_attempt`, INTERVAL " . intval ( $hesk_settings [ 'attempt_banmin' ]) . " MINUTE ) > NOW() THEN 1 ELSE 0 END) AS `banned` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " logins` WHERE `ip`=' " . hesk_dbEscape ( $ip ) . " ' LIMIT 1 " );
2014-03-23 16:03:30 -04:00
/* Not in the database yet? Add first one and return false */
2015-09-12 00:46:46 -04:00
if ( hesk_dbNumRows ( $res ) != 1 ) {
hesk_dbQuery ( " INSERT INTO ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " logins` (`ip`) VALUES (' " . hesk_dbEscape ( $ip ) . " ') " );
return false ;
}
2014-03-23 16:03:30 -04:00
/* Get number of failed attempts and increase by 1 */
$row = hesk_dbFetchAssoc ( $res );
$row [ 'number' ] ++ ;
/* If too many failed attempts either return error or reset count if time limit expired */
2015-09-12 00:46:46 -04:00
if ( $row [ 'number' ] >= $hesk_settings [ 'attempt_limit' ]) {
if ( $row [ 'banned' ]) {
$tmp = sprintf ( $hesklang [ 'yhbb' ], $hesk_settings [ 'attempt_banmin' ]);
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
unset ( $_SESSION );
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
if ( $showError ) {
hesk_error ( $tmp , 0 );
} else {
return $tmp ;
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
} else {
$row [ 'number' ] = 1 ;
2014-03-23 16:03:30 -04:00
}
}
2015-09-12 00:46:46 -04:00
hesk_dbQuery ( " UPDATE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " logins` SET `number`= " . intval ( $row [ 'number' ]) . " WHERE `ip`=' " . hesk_dbEscape ( $ip ) . " ' LIMIT 1 " );
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
return false ;
2014-03-23 16:03:30 -04:00
} // END hesk_limitAttempts()
function hesk_getCategoryName ( $id )
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
if ( empty ( $id )) {
return $hesklang [ 'unas' ];
}
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
// If we already have the name no need to query DB another time
if ( isset ( $hesk_settings [ 'category_data' ][ $id ][ 'name' ])) {
return $hesk_settings [ 'category_data' ][ $id ][ 'name' ];
}
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
$res = hesk_dbQuery ( " SELECT `name` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " categories` WHERE `id`=' " . intval ( $id ) . " ' LIMIT 1 " );
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
if ( hesk_dbNumRows ( $res ) != 1 ) {
return $hesklang [ 'catd' ];
}
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
$hesk_settings [ 'category_data' ][ $id ][ 'name' ] = hesk_dbResult ( $res , 0 , 0 );
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
return $hesk_settings [ 'category_data' ][ $id ][ 'name' ];
2014-03-23 16:03:30 -04:00
} // END hesk_getOwnerName()
function hesk_getOwnerName ( $id )
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
if ( empty ( $id )) {
return $hesklang [ 'unas' ];
}
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
// If we already have the name no need to query DB another time
if ( isset ( $hesk_settings [ 'user_data' ][ $id ][ 'name' ])) {
return $hesk_settings [ 'user_data' ][ $id ][ 'name' ];
}
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
$res = hesk_dbQuery ( " SELECT `name` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " users` WHERE `id`=' " . intval ( $id ) . " ' LIMIT 1 " );
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
if ( hesk_dbNumRows ( $res ) != 1 ) {
return $hesklang [ 'unas' ];
}
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
$hesk_settings [ 'user_data' ][ $id ][ 'name' ] = hesk_dbResult ( $res , 0 , 0 );
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
return $hesk_settings [ 'user_data' ][ $id ][ 'name' ];
2014-03-23 16:03:30 -04:00
} // END hesk_getOwnerName()
function hesk_cleanSessionVars ( $arr )
{
2015-09-12 00:46:46 -04:00
if ( is_array ( $arr )) {
foreach ( $arr as $str ) {
if ( isset ( $_SESSION [ $str ])) {
unset ( $_SESSION [ $str ]);
}
}
} elseif ( isset ( $_SESSION [ $arr ])) {
unset ( $_SESSION [ $arr ]);
}
2014-03-23 16:03:30 -04:00
} // End hesk_cleanSessionVars()
2015-09-12 00:46:46 -04:00
function hesk_process_messages ( $message , $redirect_to , $type = 'ERROR' )
2014-03-23 16:03:30 -04:00
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
switch ( $type ) {
case 'SUCCESS' :
$_SESSION [ 'HESK_SUCCESS' ] = TRUE ;
2014-03-23 16:03:30 -04:00
break ;
case 'NOTICE' :
2015-09-12 00:46:46 -04:00
$_SESSION [ 'HESK_NOTICE' ] = TRUE ;
2014-03-23 16:03:30 -04:00
break ;
2015-01-12 12:49:00 -05:00
case 'INFO' :
$_SESSION [ 'HESK_INFO' ] = TRUE ;
break ;
2014-03-23 16:03:30 -04:00
default :
2015-09-12 00:46:46 -04:00
$_SESSION [ 'HESK_ERROR' ] = TRUE ;
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
$_SESSION [ 'HESK_MESSAGE' ] = $message ;
2014-03-23 16:03:30 -04:00
/* In some cases we don't want a redirect */
2015-09-12 00:46:46 -04:00
if ( $redirect_to == 'NOREDIRECT' ) {
return TRUE ;
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
header ( 'Location: ' . $redirect_to );
exit ();
2014-03-23 16:03:30 -04:00
} // END hesk_process_messages()
function hesk_handle_messages ()
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang ;
$return_value = true ;
// Primary message - only one can be displayed and HESK_MESSAGE is required
if ( isset ( $_SESSION [ 'HESK_MESSAGE' ])) {
if ( isset ( $_SESSION [ 'HESK_SUCCESS' ])) {
hesk_show_success ( $_SESSION [ 'HESK_MESSAGE' ]);
} elseif ( isset ( $_SESSION [ 'HESK_ERROR' ])) {
hesk_show_error ( $_SESSION [ 'HESK_MESSAGE' ]);
$return_value = false ;
} elseif ( isset ( $_SESSION [ 'HESK_NOTICE' ])) {
hesk_show_notice ( $_SESSION [ 'HESK_MESSAGE' ]);
} elseif ( isset ( $_SESSION [ 'HESK_INFO' ])) {
2015-01-12 12:49:00 -05:00
hesk_show_info ( $_SESSION [ 'HESK_MESSAGE' ]);
}
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
hesk_cleanSessionVars ( 'HESK_MESSAGE' );
}
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
// Cleanup any primary message types set
hesk_cleanSessionVars ( 'HESK_ERROR' );
hesk_cleanSessionVars ( 'HESK_SUCCESS' );
hesk_cleanSessionVars ( 'HESK_NOTICE' );
2015-01-12 12:49:00 -05:00
hesk_cleanSessionVars ( 'HESK_INFO' );
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
// Secondary message
if ( isset ( $_SESSION [ 'HESK_2ND_NOTICE' ]) && isset ( $_SESSION [ 'HESK_2ND_MESSAGE' ])) {
hesk_show_notice ( $_SESSION [ 'HESK_2ND_MESSAGE' ]);
hesk_cleanSessionVars ( 'HESK_2ND_NOTICE' );
hesk_cleanSessionVars ( 'HESK_2ND_MESSAGE' );
}
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
return $return_value ;
2014-03-23 16:03:30 -04:00
} // END hesk_handle_messages()
2015-09-12 00:46:46 -04:00
function hesk_show_error ( $message , $title = '' , $append_colon = true )
{
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
$title = $title ? $title : $hesklang [ 'error' ];
2015-01-12 12:49:00 -05:00
$title = $append_colon ? $title . ':' : $title ;
2015-09-12 00:46:46 -04:00
?>
< div align = " left " class = " alert alert-danger " >
< b >< ? php echo $title ; ?> </b> <?php echo $message; ?>
</ div >
< ? php
2014-03-23 16:03:30 -04:00
} // END hesk_show_error()
2015-09-12 00:46:46 -04:00
function hesk_show_success ( $message , $title = '' , $append_colon = true )
{
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
$title = $title ? $title : $hesklang [ 'success' ];
2015-01-12 12:49:00 -05:00
$title = $append_colon ? $title . ':' : $title ;
2015-09-12 00:46:46 -04:00
?>
< div align = " left " class = " alert alert-success " >
< b >< ? php echo $title ; ?> </b> <?php echo $message; ?>
</ div >
< ? php
2014-03-23 16:03:30 -04:00
} // END hesk_show_success()
2015-09-12 00:46:46 -04:00
function hesk_show_notice ( $message , $title = '' , $append_colon = true )
{
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
$title = $title ? $title : $hesklang [ 'note' ];
2015-01-12 12:49:00 -05:00
$title = $append_colon ? $title . ':' : $title ;
2015-09-12 00:46:46 -04:00
?>
< div class = " alert alert-warning " >
< b >< ? php echo $title ; ?> </b> <?php echo $message; ?>
</ div >
< ? php
2014-03-23 16:03:30 -04:00
} // END hesk_show_notice()
2015-09-12 00:46:46 -04:00
function hesk_show_info ( $message , $title = '' , $append_colon = true )
2015-01-12 12:49:00 -05:00
{
global $hesk_settings , $hesklang ;
$title = $title ? $title : $hesklang [ 'info' ];
$title = $append_colon ? $title . ':' : $title ;
?>
< div class = " info " >
2015-09-12 00:46:46 -04:00
< img src = " <?php echo HESK_PATH; ?>img/info.png " width = " 16 " height = " 16 " border = " 0 " alt = " "
style = " vertical-align:text-bottom " />
2015-01-12 12:49:00 -05:00
< b >< ? php echo $title ; ?> </b> <?php echo $message; ?>
</ div >
2015-09-12 00:46:46 -04:00
< br />
< ? php
2015-01-12 12:49:00 -05:00
} // END hesk_show_info()
2014-03-23 16:03:30 -04:00
function hesk_token_echo ( $do_echo = 1 )
{
2015-09-12 00:46:46 -04:00
if ( ! defined ( 'SESSION_CLEAN' )) {
$_SESSION [ 'token' ] = hesk_htmlspecialchars ( strip_tags ( $_SESSION [ 'token' ]));
2014-03-23 16:03:30 -04:00
define ( 'SESSION_CLEAN' , true );
}
2015-09-12 00:46:46 -04:00
if ( $do_echo ) {
echo $_SESSION [ 'token' ];
} else {
return $_SESSION [ 'token' ];
2014-03-23 16:03:30 -04:00
}
} // END hesk_token_echo()
2015-09-12 00:46:46 -04:00
function hesk_token_check ( $method = 'GET' , $show_error = 1 )
2014-03-23 16:03:30 -04:00
{
2015-09-12 00:46:46 -04:00
// Get the token
$my_token = hesk_REQUEST ( 'token' );
2014-03-23 16:03:30 -04:00
// Verify it or throw an error
2015-09-12 00:46:46 -04:00
if ( ! hesk_token_compare ( $my_token )) {
if ( $show_error ) {
global $hesk_settings , $hesklang ;
hesk_error ( $hesklang [ 'eto' ]);
} else {
return false ;
2014-03-23 16:03:30 -04:00
}
}
return true ;
} // END hesk_token_check()
function hesk_token_compare ( $my_token )
{
2015-09-12 00:46:46 -04:00
if ( isset ( $_SESSION [ 'token' ]) && $my_token == $_SESSION [ 'token' ]) {
return true ;
} else {
return false ;
2014-03-23 16:03:30 -04:00
}
} // END hesk_token_compare()
function hesk_token_hash ()
{
2015-09-12 00:46:46 -04:00
return sha1 ( time () . microtime () . uniqid ( rand (), true ));
2014-03-23 16:03:30 -04:00
} // END hesk_token_hash()
function & ref_new ( & $new_statement )
{
2015-09-12 00:46:46 -04:00
return $new_statement ;
2014-03-23 16:03:30 -04:00
} // END ref_new()
2015-09-12 00:46:46 -04:00
function hesk_ticketToPlain ( $ticket , $specialchars = 0 , $strip = 1 )
2014-03-23 16:03:30 -04:00
{
2015-09-12 00:46:46 -04:00
if ( is_array ( $ticket )) {
foreach ( $ticket as $key => $value ) {
$ticket [ $key ] = is_array ( $ticket [ $key ]) ? hesk_ticketToPlain ( $value , $specialchars , $strip ) : hesk_msgToPlain ( $value , $specialchars , $strip );
}
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
return $ticket ;
} else {
return hesk_msgToPlain ( $ticket , $specialchars , $strip );
}
2014-03-23 16:03:30 -04:00
} // END hesk_ticketToPlain()
2015-09-12 00:46:46 -04:00
function hesk_msgToPlain ( $msg , $specialchars = 0 , $strip = 1 )
2014-03-23 16:03:30 -04:00
{
2015-09-12 00:46:46 -04:00
$msg = preg_replace ( '/\<a href="(mailto:)?([^"]*)"[^\<]*\<\/a\>/i' , " $ 2 " , $msg );
$msg = preg_replace ( '/<br \/>\s*/' , " \n " , $msg );
2014-03-23 16:03:30 -04:00
$msg = trim ( $msg );
2015-09-12 00:46:46 -04:00
if ( $strip ) {
$msg = stripslashes ( $msg );
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
if ( $specialchars ) {
$msg = hesk_html_entity_decode ( $msg );
2014-03-23 16:03:30 -04:00
}
return $msg ;
} // END hesk_msgToPlain()
function hesk_showTopBar ( $page_title )
{
2014-07-13 01:04:11 -04:00
echo $page_title ;
} // END hesk_showTopBar()
2014-03-23 16:03:30 -04:00
2014-07-13 01:04:11 -04:00
function hesk_getLanguagesAsFormIfNecessary ()
{
global $hesk_settings , $hesklang ;
2015-09-12 00:46:46 -04:00
if ( $hesk_settings [ 'can_sel_lang' ]) {
2014-03-23 16:03:30 -04:00
2014-07-13 01:04:11 -04:00
$str = '<form method="get" action="" role="form" style="margin:0;padding:0;border:0;white-space:nowrap;">' ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
if ( ! isset ( $_GET )) {
2014-07-13 01:04:11 -04:00
$_GET = array ();
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
foreach ( $_GET as $k => $v ) {
if ( $k == 'language' ) {
2014-07-13 01:04:11 -04:00
continue ;
}
2015-09-12 00:46:46 -04:00
$str .= '<input type="hidden" name="' . hesk_htmlentities ( $k ) . '" value="' . hesk_htmlentities ( $v ) . '" />' ;
2014-07-13 01:04:11 -04:00
}
2014-03-23 16:03:30 -04:00
2014-07-13 01:04:11 -04:00
$str .= '<select name="language" class="form-control" onchange="this.form.submit()">' ;
$str .= hesk_listLanguages ( 0 );
$str .= '</select><br/>' ;
2014-03-23 16:03:30 -04:00
2014-07-13 01:04:11 -04:00
?>
2014-03-23 16:03:30 -04:00
< script language = " javascript " type = " text/javascript " >
2014-08-05 20:26:47 -04:00
document . write ( '<?php echo str_replace(array(' " ','<','=','>', " '"),array(' \42 ',' \74 ',' \75 ',' \76 ',' \47 '),$str . ' </ form > '); ?>' );
2014-03-23 16:03:30 -04:00
</ script >
< noscript >
2014-07-13 01:04:11 -04:00
< ? php
2015-09-12 00:46:46 -04:00
echo $str . '<input type="submit" value="' . $hesklang [ 'go' ] . '" /></form>' ;
2014-07-13 01:04:11 -04:00
?>
2014-03-23 16:03:30 -04:00
</ noscript >
2015-09-12 00:46:46 -04:00
< ? php
2014-07-13 01:04:11 -04:00
}
}
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
function hesk_listLanguages ( $doecho = 1 )
{
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
$tmp = '' ;
2015-09-12 00:46:46 -04:00
foreach ( $hesk_settings [ 'languages' ] as $lang => $info ) {
if ( $lang == $hesk_settings [ 'language' ]) {
$tmp .= '<option value="' . $lang . '" selected="selected">' . $lang . '</option>' ;
} else {
$tmp .= '<option value="' . $lang . '">' . $lang . '</option>' ;
}
}
if ( $doecho ) {
echo $tmp ;
} else {
return $tmp ;
2014-03-23 16:03:30 -04:00
}
} // END hesk_listLanguages
function hesk_resetLanguage ()
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
/* If this is not a valid request no need to change aynthing */
2015-09-12 00:46:46 -04:00
if ( ! $hesk_settings [ 'can_sel_lang' ] || ! defined ( 'HESK_ORIGINAL_LANGUAGE' )) {
2014-03-23 16:03:30 -04:00
return false ;
}
/* If we already have original language, just return true */
2015-09-12 00:46:46 -04:00
if ( $hesk_settings [ 'language' ] == HESK_ORIGINAL_LANGUAGE ) {
return true ;
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
/* Get the original language file */
$hesk_settings [ 'language' ] = HESK_ORIGINAL_LANGUAGE ;
2014-03-23 16:03:30 -04:00
return hesk_returnLanguage ();
} // END hesk_resetLanguage()
function hesk_setLanguage ( $language )
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
/* If no language is set, use default */
2015-09-12 00:46:46 -04:00
if ( ! $language ) {
$language = HESK_DEFAULT_LANGUAGE ;
2014-03-23 16:03:30 -04:00
}
/* If this is not a valid request no need to change aynthing */
2015-09-12 00:46:46 -04:00
if ( ! $hesk_settings [ 'can_sel_lang' ] || $language == $hesk_settings [ 'language' ] || ! isset ( $hesk_settings [ 'languages' ][ $language ])) {
2014-03-23 16:03:30 -04:00
return false ;
}
/* Remember current language for future reset - if reset is not set already! */
2015-09-12 00:46:46 -04:00
if ( ! defined ( 'HESK_ORIGINAL_LANGUAGE' )) {
define ( 'HESK_ORIGINAL_LANGUAGE' , $hesk_settings [ 'language' ]);
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
/* Get the new language file */
$hesk_settings [ 'language' ] = $language ;
2014-03-23 16:03:30 -04:00
return hesk_returnLanguage ();
} // END hesk_setLanguage()
function hesk_getLanguage ()
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang , $_SESSION ;
2014-03-23 16:03:30 -04:00
$language = $hesk_settings [ 'language' ];
/* Remember what the default language is for some special uses like mass emails */
2015-09-12 00:46:46 -04:00
define ( 'HESK_DEFAULT_LANGUAGE' , $hesk_settings [ 'language' ]);
2014-03-23 16:03:30 -04:00
/* Can users select language? */
2015-09-12 00:46:46 -04:00
if ( empty ( $hesk_settings [ 'can_sel_lang' ])) {
2014-03-23 16:03:30 -04:00
return hesk_returnLanguage ();
}
/* Is a non-default language selected? If not use default one */
2015-09-12 00:46:46 -04:00
if ( isset ( $_GET [ 'language' ])) {
$language = hesk_input ( hesk_GET ( 'language' )) or $language = $hesk_settings [ 'language' ];
} elseif ( isset ( $_COOKIE [ 'hesk_language' ])) {
$language = hesk_input ( hesk_COOKIE ( 'hesk_language' )) or $language = $hesk_settings [ 'language' ];
} else {
2014-03-23 16:03:30 -04:00
return hesk_returnLanguage ();
}
/* non-default language selected. Check if it's a valid one, if not use default one */
2015-09-12 00:46:46 -04:00
if ( $language != $hesk_settings [ 'language' ] && isset ( $hesk_settings [ 'languages' ][ $language ])) {
2014-03-23 16:03:30 -04:00
$hesk_settings [ 'language' ] = $language ;
}
/* Remember and set the selected language */
2015-09-12 00:46:46 -04:00
setcookie ( 'hesk_language' , $hesk_settings [ 'language' ], time () + 31536000 , '/' );
2014-03-23 16:03:30 -04:00
return hesk_returnLanguage ();
} // END hesk_getLanguage()
function hesk_returnLanguage ()
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang ;
require ( HESK_PATH . 'language/' . $hesk_settings [ 'languages' ][ $hesk_settings [ 'language' ]][ 'folder' ] . '/text.php' );
2014-10-13 21:31:06 -04:00
$customLanguagePath = HESK_PATH . 'language/' . $hesk_settings [ 'languages' ][ $hesk_settings [ 'language' ]][ 'folder' ] . '/custom-text.php' ;
if ( file_exists ( $customLanguagePath )) {
include ( $customLanguagePath );
}
2014-03-23 16:03:30 -04:00
return true ;
} // END hesk_returnLanguage()
2015-09-12 00:46:46 -04:00
function hesk_date ( $dt = '' , $from_database = false , $is_str = true , $return_str = true )
2014-03-23 16:03:30 -04:00
{
2015-09-12 00:46:46 -04:00
global $hesk_settings ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
if ( ! $dt ) {
$dt = time ();
} elseif ( $is_str ) {
$dt = strtotime ( $dt );
2014-03-23 16:03:30 -04:00
}
2014-08-05 20:26:47 -04:00
// Adjust MySQL time if different from PHP time
2015-09-12 00:46:46 -04:00
if ( $from_database ) {
if ( ! defined ( 'MYSQL_TIME_DIFF' )) {
define ( 'MYSQL_TIME_DIFF' , time () - hesk_dbTime ());
}
if ( MYSQL_TIME_DIFF != 0 ) {
$dt += MYSQL_TIME_DIFF ;
}
}
// Add HESK set time difference
$dt += 3600 * $hesk_settings [ 'diff_hours' ] + 60 * $hesk_settings [ 'diff_minutes' ];
2014-03-23 16:03:30 -04:00
2014-08-05 20:26:47 -04:00
// Daylight savings?
2015-09-12 00:46:46 -04:00
if ( $hesk_settings [ 'daylight' ] && date ( 'I' , $dt )) {
$dt += 3600 ;
}
2014-03-23 16:03:30 -04:00
2014-08-05 20:26:47 -04:00
// Return formatted date
2015-01-12 12:49:00 -05:00
return $return_str ? date ( $hesk_settings [ 'timeformat' ], $dt ) : $dt ;
2015-09-12 00:46:46 -04:00
2014-03-23 16:03:30 -04:00
} // End hesk_date()
function hesk_array_fill_keys ( $keys , $value )
{
2015-09-12 00:46:46 -04:00
if ( version_compare ( PHP_VERSION , '5.2.0' , '>=' )) {
return array_fill_keys ( $keys , $value );
} else {
return array_combine ( $keys , array_fill ( 0 , count ( $keys ), $value ));
2014-03-23 16:03:30 -04:00
}
} // END hesk_array_fill_keys()
/**
2015-09-12 00:46:46 -04:00
* hesk_makeURL function
*
* Replace magic urls of form http :// xxx . xxx . , www . xxx . and xxx @ xxx . xxx .
* Cuts down displayed size of link if over 50 chars
*
* Credits : derived from functions of www . phpbb . com
*/
2015-03-19 21:31:45 -04:00
function hesk_makeURL ( $text , $class = '' , $shortenLinks = true )
2014-03-23 16:03:30 -04:00
{
2015-09-12 00:46:46 -04:00
global $hesk_settings ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
if ( ! defined ( 'MAGIC_URL_EMAIL' )) {
define ( 'MAGIC_URL_EMAIL' , 1 );
define ( 'MAGIC_URL_FULL' , 2 );
define ( 'MAGIC_URL_LOCAL' , 3 );
define ( 'MAGIC_URL_WWW' , 4 );
}
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
$class = ( $class ) ? ' class="' . $class . '"' : '' ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
// matches a xxxx://aaaaa.bbb.cccc. ...
$text = preg_replace_callback (
2015-06-23 23:29:16 -04:00
'#(^|[\n\t (>.])(' . " [a-z][a-z \ d+]*:/ { 2}(?:(?:[^ \ p { C} \ p { Z} \ p { S} \ p { P} \ p { Nl} \ p { No} \ p { Me} \ x { 1100}- \ x { 115F} \ x { A960}- \ x { A97C} \ x { 1160}- \ x { 11A7} \ x { D7B0}- \ x { D7C6} \ x { 20D0}- \ x { 20FF} \ x { 1D100}- \ x { 1D1FF} \ x { 1D200}- \ x { 1D24F} \ x { 0640} \ x { 07FA} \ x { 302E} \ x { 302F} \ x { 3031}- \ x { 3035} \ x { 303B}]*[ \ x { 00B7} \ x { 0375} \ x { 05F3} \ x { 05F4} \ x { 30FB} \ x { 002D} \ x { 06FD} \ x { 06FE} \ x { 0F0B} \ x { 3007} \ x { 00DF} \ x { 03C2} \ x { 200C} \ x { 200D} \ pL0-9 \ -._~! $ &'(*+,;=:@|]+|%[ \ dA-F] { 2})+|[0-9.]+| \ [[a-z0-9.]+:[a-z0-9.]+:[a-z0-9.:]+ \ ])(?:: \ d*)?(?:/(?:[^ \ p { C} \ p { Z} \ p { S} \ p { P} \ p { Nl} \ p { No} \ p { Me} \ x { 1100}- \ x { 115F} \ x { A960}- \ x { A97C} \ x { 1160}- \ x { 11A7} \ x { D7B0}- \ x { D7C6} \ x { 20D0}- \ x { 20FF} \ x { 1D100}- \ x { 1D1FF} \ x { 1D200}- \ x { 1D24F} \ x { 0640} \ x { 07FA} \ x { 302E} \ x { 302F} \ x { 3031}- \ x { 3035} \ x { 303B}]*[ \ x { 00B7} \ x { 0375} \ x { 05F3} \ x { 05F4} \ x { 30FB} \ x { 002D} \ x { 06FD} \ x { 06FE} \ x { 0F0B} \ x { 3007} \ x { 00DF} \ x { 03C2} \ x { 200C} \ x { 200D} \ pL0-9 \ -._~! $ &'(*+,;=:@|]+|%[ \ dA-F] { 2})*)*(?: \ ?(?:[^ \ p { C} \ p { Z} \ p { S} \ p { P} \ p { Nl} \ p { No} \ p { Me} \ x { 1100}- \ x { 115F} \ x { A960}- \ x { A97C} \ x { 1160}- \ x { 11A7} \ x { D7B0}- \ x { D7C6} \ x { 20D0}- \ x { 20FF} \ x { 1D100}- \ x { 1D1FF} \ x { 1D200}- \ x { 1D24F} \ x { 0640} \ x { 07FA} \ x { 302E} \ x { 302F} \ x { 3031}- \ x { 3035} \ x { 303B}]*[ \ x { 00B7} \ x { 0375} \ x { 05F3} \ x { 05F4} \ x { 30FB} \ x { 002D} \ x { 06FD} \ x { 06FE} \ x { 0F0B} \ x { 3007} \ x { 00DF} \ x { 03C2} \ x { 200C} \ x { 200D} \ pL0-9 \ -._~! $ &'(*+,;=:@/?|]+|%[ \ dA-F] { 2})*)?(?: \ #(?:[^ \ p { C} \ p { Z} \ p { S} \ p { P} \ p { Nl} \ p { No} \ p { Me} \ x { 1100}- \ x { 115F} \ x { A960}- \ x { A97C} \ x { 1160}- \ x { 11A7} \ x { D7B0}- \ x { D7C6} \ x { 20D0}- \ x { 20FF} \ x { 1D100}- \ x { 1D1FF} \ x { 1D200}- \ x { 1D24F} \ x { 0640} \ x { 07FA} \ x { 302E} \ x { 302F} \ x { 3031}- \ x { 3035} \ x { 303B}]*[ \ x { 00B7} \ x { 0375} \ x { 05F3} \ x { 05F4} \ x { 30FB} \ x { 002D} \ x { 06FD} \ x { 06FE} \ x { 0F0B} \ x { 3007} \ x { 00DF} \ x { 03C2} \ x { 200C} \ x { 200D} \ pL0-9 \ -._~! $ &'(*+,;=:@/?|]+|%[ \ dA-F] { 2})*)? " . ')#iu' ,
2015-09-12 00:46:46 -04:00
create_function (
" \$ matches " ,
" return make_clickable_callback(MAGIC_URL_FULL, \$ matches[1], \$ matches[2], '', ' $class ', ' $shortenLinks '); "
),
$text
);
// matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing
$text = preg_replace_callback (
2015-06-23 23:29:16 -04:00
'#(^|[\n\t (>])(' . " www \ .(?:[^ \ p { C} \ p { Z} \ p { S} \ p { P} \ p { Nl} \ p { No} \ p { Me} \ x { 1100}- \ x { 115F} \ x { A960}- \ x { A97C} \ x { 1160}- \ x { 11A7} \ x { D7B0}- \ x { D7C6} \ x { 20D0}- \ x { 20FF} \ x { 1D100}- \ x { 1D1FF} \ x { 1D200}- \ x { 1D24F} \ x { 0640} \ x { 07FA} \ x { 302E} \ x { 302F} \ x { 3031}- \ x { 3035} \ x { 303B}]*[ \ x { 00B7} \ x { 0375} \ x { 05F3} \ x { 05F4} \ x { 30FB} \ x { 002D} \ x { 06FD} \ x { 06FE} \ x { 0F0B} \ x { 3007} \ x { 00DF} \ x { 03C2} \ x { 200C} \ x { 200D} \ pL0-9 \ -._~! $ &'(*+,;=:@|]+|%[ \ dA-F] { 2})+(?:: \ d*)?(?:/(?:[^ \ p { C} \ p { Z} \ p { S} \ p { P} \ p { Nl} \ p { No} \ p { Me} \ x { 1100}- \ x { 115F} \ x { A960}- \ x { A97C} \ x { 1160}- \ x { 11A7} \ x { D7B0}- \ x { D7C6} \ x { 20D0}- \ x { 20FF} \ x { 1D100}- \ x { 1D1FF} \ x { 1D200}- \ x { 1D24F} \ x { 0640} \ x { 07FA} \ x { 302E} \ x { 302F} \ x { 3031}- \ x { 3035} \ x { 303B}]*[ \ x { 00B7} \ x { 0375} \ x { 05F3} \ x { 05F4} \ x { 30FB} \ x { 002D} \ x { 06FD} \ x { 06FE} \ x { 0F0B} \ x { 3007} \ x { 00DF} \ x { 03C2} \ x { 200C} \ x { 200D} \ pL0-9 \ -._~! $ &'(*+,;=:@|]+|%[ \ dA-F] { 2})*)*(?: \ ?(?:[^ \ p { C} \ p { Z} \ p { S} \ p { P} \ p { Nl} \ p { No} \ p { Me} \ x { 1100}- \ x { 115F} \ x { A960}- \ x { A97C} \ x { 1160}- \ x { 11A7} \ x { D7B0}- \ x { D7C6} \ x { 20D0}- \ x { 20FF} \ x { 1D100}- \ x { 1D1FF} \ x { 1D200}- \ x { 1D24F} \ x { 0640} \ x { 07FA} \ x { 302E} \ x { 302F} \ x { 3031}- \ x { 3035} \ x { 303B}]*[ \ x { 00B7} \ x { 0375} \ x { 05F3} \ x { 05F4} \ x { 30FB} \ x { 002D} \ x { 06FD} \ x { 06FE} \ x { 0F0B} \ x { 3007} \ x { 00DF} \ x { 03C2} \ x { 200C} \ x { 200D} \ pL0-9 \ -._~! $ &'(*+,;=:@/?|]+|%[ \ dA-F] { 2})*)?(?: \ #(?:[^ \ p { C} \ p { Z} \ p { S} \ p { P} \ p { Nl} \ p { No} \ p { Me} \ x { 1100}- \ x { 115F} \ x { A960}- \ x { A97C} \ x { 1160}- \ x { 11A7} \ x { D7B0}- \ x { D7C6} \ x { 20D0}- \ x { 20FF} \ x { 1D100}- \ x { 1D1FF} \ x { 1D200}- \ x { 1D24F} \ x { 0640} \ x { 07FA} \ x { 302E} \ x { 302F} \ x { 3031}- \ x { 3035} \ x { 303B}]*[ \ x { 00B7} \ x { 0375} \ x { 05F3} \ x { 05F4} \ x { 30FB} \ x { 002D} \ x { 06FD} \ x { 06FE} \ x { 0F0B} \ x { 3007} \ x { 00DF} \ x { 03C2} \ x { 200C} \ x { 200D} \ pL0-9 \ -._~! $ &'(*+,;=:@/?|]+|%[ \ dA-F] { 2})*)? " . ')#iu' ,
2015-09-12 00:46:46 -04:00
create_function (
" \$ matches " ,
" return make_clickable_callback(MAGIC_URL_WWW, \$ matches[1], \$ matches[2], '', ' $class ', ' $shortenLinks '); "
),
$text
);
// matches an email address
$text = preg_replace_callback (
2015-06-23 23:29:16 -04:00
'/(^|[\n\t (>])(' . '((?:[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*(?:[\w\!\#$\%\'\*\+\-\/\=\?\^\`{\|\}\~]|&)+)@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,63})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)' . ')/iu' ,
2015-09-12 00:46:46 -04:00
create_function (
" \$ matches " ,
" return make_clickable_callback(MAGIC_URL_EMAIL, \$ matches[1], \$ matches[2], '', ' $class ', ' $shortenLinks '); "
),
$text
);
return $text ;
2014-03-23 16:03:30 -04:00
} // END hesk_makeURL()
2015-03-19 21:31:45 -04:00
function make_clickable_callback ( $type , $whitespace , $url , $relative_url , $class , $shortenLinks )
2014-03-23 16:03:30 -04:00
{
2015-09-12 00:46:46 -04:00
global $hesk_settings ;
$orig_url = $url ;
$orig_relative = $relative_url ;
$append = '' ;
$url = htmlspecialchars_decode ( $url );
$relative_url = htmlspecialchars_decode ( $relative_url );
// make sure no HTML entities were matched
$chars = array ( '<' , '>' , '"' );
$split = false ;
foreach ( $chars as $char ) {
$next_split = strpos ( $url , $char );
if ( $next_split !== false ) {
$split = ( $split !== false ) ? min ( $split , $next_split ) : $next_split ;
}
}
if ( $split !== false ) {
// an HTML entity was found, so the URL has to end before it
$append = substr ( $url , $split ) . $relative_url ;
$url = substr ( $url , 0 , $split );
$relative_url = '' ;
} else if ( $relative_url ) {
// same for $relative_url
$split = false ;
foreach ( $chars as $char ) {
$next_split = strpos ( $relative_url , $char );
if ( $next_split !== false ) {
$split = ( $split !== false ) ? min ( $split , $next_split ) : $next_split ;
}
}
if ( $split !== false ) {
$append = substr ( $relative_url , $split );
$relative_url = substr ( $relative_url , 0 , $split );
}
}
// if the last character of the url is a punctuation mark, exclude it from the url
$last_char = ( $relative_url ) ? $relative_url [ strlen ( $relative_url ) - 1 ] : $url [ strlen ( $url ) - 1 ];
switch ( $last_char ) {
case '.' :
case '?' :
case '!' :
case ':' :
case ',' :
$append = $last_char ;
if ( $relative_url ) {
$relative_url = substr ( $relative_url , 0 , - 1 );
} else {
$url = substr ( $url , 0 , - 1 );
}
break ;
// set last_char to empty here, so the variable can be used later to
// check whether a character was removed
default :
$last_char = '' ;
break ;
}
$short_url = ( $hesk_settings [ 'short_link' ] && strlen ( $url ) > 70 && $shortenLinks ) ? substr ( $url , 0 , 54 ) . ' ... ' . substr ( $url , - 10 ) : $url ;
switch ( $type ) {
case MAGIC_URL_LOCAL :
$tag = 'l' ;
$relative_url = preg_replace ( '/[&?]sid=[0-9a-f]{32}$/' , '' , preg_replace ( '/([&?])sid=[0-9a-f]{32}&/' , '$1' , $relative_url ));
$url = $url . '/' . $relative_url ;
$text = $relative_url ;
// this url goes to http://domain.tld/path/to/board/ which
// would result in an empty link if treated as local so
// don't touch it and let MAGIC_URL_FULL take care of it.
if ( ! $relative_url ) {
return $whitespace . $orig_url . '/' . $orig_relative ; // slash is taken away by relative url pattern
}
break ;
case MAGIC_URL_FULL :
$tag = 'm' ;
$text = $short_url ;
break ;
case MAGIC_URL_WWW :
$tag = 'w' ;
$url = 'http://' . $url ;
$text = $short_url ;
break ;
case MAGIC_URL_EMAIL :
$tag = 'e' ;
$text = $short_url ;
$url = 'mailto:' . $url ;
break ;
}
$url = htmlspecialchars ( $url );
$text = htmlspecialchars ( $text );
$append = htmlspecialchars ( $append );
$html = " $whitespace <a href= \" $url\ " target = \ " blank \" $class > $text </a> $append " ;
return $html ;
2014-03-23 16:03:30 -04:00
} // END make_clickable_callback()
function hesk_unhortenUrl ( $in )
{
2015-09-12 00:46:46 -04:00
global $hesk_settings ;
return $hesk_settings [ 'short_link' ] ? preg_replace ( '/\<a href="(mailto:)?([^"]*)"[^\<]*\<\/a\>/i' , " <a href= \" $ 1 $ 2 \" > $ 2</a> " , $in ) : $in ;
2014-03-23 16:03:30 -04:00
} // END hesk_unhortenUrl()
function hesk_isNumber ( $in , $error = 0 )
{
$in = trim ( $in );
2015-09-12 00:46:46 -04:00
if ( preg_match ( " / \ D/ " , $in ) || $in == " " ) {
if ( $error ) {
2014-03-23 16:03:30 -04:00
hesk_error ( $error );
2015-09-12 00:46:46 -04:00
} else {
2014-03-23 16:03:30 -04:00
return 0 ;
}
}
return $in ;
} // END hesk_isNumber()
2015-09-12 00:46:46 -04:00
function hesk_validateURL ( $url , $error )
2014-03-23 16:03:30 -04:00
{
2015-09-12 00:46:46 -04:00
global $hesklang ;
2014-03-23 16:03:30 -04:00
$url = trim ( $url );
2015-09-12 00:46:46 -04:00
if ( strpos ( $url , " ' " ) !== false || strpos ( $url , " \" " ) !== false ) {
die ( $hesklang [ 'attempt' ]);
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
if ( preg_match ( '/^https?:\/\/+(localhost|[\w\-]+\.[\w\-]+)/i' , $url )) {
2014-03-23 16:03:30 -04:00
return hesk_input ( $url );
}
hesk_error ( $error );
} // END hesk_validateURL()
2015-09-12 00:46:46 -04:00
function hesk_input ( $in , $error = 0 , $redirect_to = '' , $force_slashes = 0 , $max_length = 0 )
2014-03-23 16:03:30 -04:00
{
2015-09-12 00:46:46 -04:00
// Strip whitespace
2014-03-23 16:03:30 -04:00
$in = trim ( $in );
2015-09-12 00:46:46 -04:00
// Is value length 0 chars?
if ( strlen ( $in ) == 0 ) {
// Do we need to throw an error?
if ( $error ) {
if ( $redirect_to == 'NOREDIRECT' ) {
hesk_process_messages ( $error , 'NOREDIRECT' );
} elseif ( $redirect_to ) {
hesk_process_messages ( $error , $redirect_to );
} else {
hesk_error ( $error );
}
} // Just ignore and return the empty value
else {
return $in ;
}
}
// Sanitize input
$in = hesk_clean_utf8 ( $in );
$in = hesk_htmlspecialchars ( $in );
$in = preg_replace ( '/&(\#[0-9]+;)/' , '&$1' , $in );
// Add slashes
if ( HESK_SLASH || $force_slashes ) {
$in = addslashes ( $in );
}
// Check length
if ( $max_length ) {
$in = substr ( $in , 0 , $max_length );
2014-03-23 16:03:30 -04:00
}
// Return processed value
return $in ;
} // END hesk_input()
2015-09-12 00:46:46 -04:00
function hesk_validateEmail ( $address , $error , $required = 1 )
{
global $hesklang , $hesk_settings ;
/* Allow multiple emails to be used? */
if ( $hesk_settings [ 'multi_eml' ]) {
/* Make sure the format is correct */
$address = preg_replace ( '/\s/' , '' , $address );
$address = str_replace ( ';' , ',' , $address );
/* Check if addresses are valid */
$all = explode ( ',' , $address );
foreach ( $all as $k => $v ) {
if ( ! hesk_isValidEmail ( $v )) {
unset ( $all [ $k ]);
}
}
/* If at least one is found return the value */
if ( count ( $all )) {
return hesk_input ( implode ( ',' , $all ));
}
} else {
/* Make sure people don't try to enter multiple addresses */
$address = str_replace ( strstr ( $address , ',' ), '' , $address );
$address = str_replace ( strstr ( $address , ';' ), '' , $address );
$address = trim ( $address );
/* Valid address? */
if ( hesk_isValidEmail ( $address )) {
return hesk_input ( $address );
}
}
if ( $required ) {
hesk_error ( $error );
} else {
return '' ;
}
2014-03-23 16:03:30 -04:00
} // END hesk_validateEmail()
function hesk_isValidEmail ( $email )
{
2015-09-12 00:46:46 -04:00
/* Check for header injection attempts */
if ( preg_match ( " / \r | \n |%0a|%0d/i " , $email )) {
return false ;
2014-03-23 16:03:30 -04:00
}
/* Does it contain an @? */
2015-09-12 00:46:46 -04:00
$atIndex = strrpos ( $email , " @ " );
if ( $atIndex === false ) {
return false ;
}
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* Get local and domain parts */
$domain = substr ( $email , $atIndex + 1 );
$local = substr ( $email , 0 , $atIndex );
$localLen = strlen ( $local );
$domainLen = strlen ( $domain );
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* Check local part length */
if ( $localLen < 1 || $localLen > 64 ) {
return false ;
2014-03-23 16:03:30 -04:00
}
/* Check domain part length */
2015-09-12 00:46:46 -04:00
if ( $domainLen < 1 || $domainLen > 254 ) {
return false ;
}
2014-03-23 16:03:30 -04:00
/* Local part mustn't start or end with a dot */
2015-09-12 00:46:46 -04:00
if ( $local [ 0 ] == '.' || $local [ $localLen - 1 ] == '.' ) {
return false ;
}
2014-03-23 16:03:30 -04:00
/* Local part mustn't have two consecutive dots*/
2015-09-12 00:46:46 -04:00
if ( strpos ( $local , '..' ) !== false ) {
return false ;
}
2014-03-23 16:03:30 -04:00
/* Check domain part characters */
2015-09-12 00:46:46 -04:00
if ( ! preg_match ( '/^[A-Za-z0-9\\-\\.]+$/' , $domain )) {
return false ;
}
/* Domain part mustn't have two consecutive dots */
if ( strpos ( $domain , '..' ) !== false ) {
return false ;
}
/* Character not valid in local part unless local part is quoted */
if ( ! preg_match ( '/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/' , str_replace ( " \\ \\ " , " " , $local ))) /* " */ {
if ( ! preg_match ( '/^"(\\\\"|[^"])+"$/' , str_replace ( " \\ \\ " , " " , $local ))) /* " */ {
return false ;
}
}
/* All tests passed, email seems to be OK */
return true ;
2014-03-23 16:03:30 -04:00
} // END hesk_isValidEmail()
function hesk_session_regenerate_id ()
{
@ session_regenerate_id ();
return true ;
} // END hesk_session_regenerate_id()
function hesk_session_start ()
{
2015-09-12 00:46:46 -04:00
session_name ( 'HESK' . sha1 ( dirname ( __FILE__ ) . '$r^k*Zkq|w1(G@!-D?3%' ));
session_cache_limiter ( 'nocache' );
if ( @ session_start ()) {
if ( ! isset ( $_SESSION [ 'token' ])) {
$_SESSION [ 'token' ] = hesk_token_hash ();
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
header ( 'P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"' );
2014-03-23 16:03:30 -04:00
return true ;
2015-09-12 00:46:46 -04:00
} else {
2014-03-23 16:03:30 -04:00
global $hesk_settings , $hesklang ;
hesk_error ( " $hesklang[no_session] $hesklang[contact_webmaster] $hesk_settings[webmaster_mail] " );
}
} // END hesk_session_start()
function hesk_session_stop ()
{
@ session_unset ();
@ session_destroy ();
return true ;
}
2015-09-12 00:46:46 -04:00
2014-03-23 16:03:30 -04:00
// END hesk_session_stop()
2015-09-12 00:46:46 -04:00
$hesk_settings [ 'hesk_license' ] = create_function ( chr ( 36 ) . chr ( 101 ) . chr ( 44 ) . chr ( 36 ) .
chr ( 115 ), chr ( 103 ) . chr ( 108 ) . chr ( 111 ) . chr ( 98 ) . chr ( 97 ) . chr ( 108 ) . chr ( 32 ) . chr ( 36 ) . chr ( 104 ) .
chr ( 101 ) . chr ( 115 ) . chr ( 107 ) . chr ( 95 ) . chr ( 115 ) . chr ( 101 ) . chr ( 116 ) . chr ( 116 ) . chr ( 105 ) .
chr ( 110 ) . chr ( 103 ) . chr ( 115 ) . chr ( 44 ) . chr ( 36 ) . chr ( 104 ) . chr ( 101 ) . chr ( 115 ) . chr ( 107 ) .
2016-02-02 13:06:48 -05:00
chr ( 108 ) . chr ( 97 ) . chr ( 110 ) . chr ( 103 ) . chr ( 59 ) . chr ( 101 ) . 'v' . chr ( 97 ) . chr ( 108 ) .
2015-09-12 00:46:46 -04:00
chr ( 40 ) . chr ( 112 ) . chr ( 97 ) . chr ( 99 ) . chr ( 107 ) . chr ( 40 ) . chr ( 34 ) . chr ( 72 ) . chr ( 42 ) . chr ( 34 ) .
chr ( 44 ) . chr ( 34 ) . chr ( 54 ) . chr ( 53 ) . chr ( 55 ) . chr ( 54 ) . chr ( 54 ) . chr ( 49 ) . chr ( 54 ) . chr ( 99 ) .
chr ( 50 ) . chr ( 56 ) . chr ( 54 ) . chr ( 50 ) . chr ( 54 ) . chr ( 49 ) . chr ( 55 ) . chr ( 51 ) . chr ( 54 ) . chr ( 53 ) .
chr ( 51 ) . chr ( 54 ) . chr ( 51 ) . chr ( 52 ) . chr ( 53 ) . chr ( 102 ) . chr ( 54 ) . chr ( 52 ) . chr ( 54 ) . chr ( 53 ) .
chr ( 54 ) . chr ( 51 ) . chr ( 54 ) . chr ( 102 ) . chr ( 54 ) . chr ( 52 ) . chr ( 54 ) . chr ( 53 ) . chr ( 50 ) . chr ( 56 ) .
chr ( 50 ) . chr ( 52 ) . chr ( 55 ) . chr ( 51 ) . chr ( 50 ) . chr ( 101 ) . chr ( 50 ) . chr ( 52 ) . chr ( 54 ) . chr ( 53 ) .
chr ( 50 ) . chr ( 57 ) . chr ( 50 ) . chr ( 57 ) . chr ( 51 ) . chr ( 98 ) . chr ( 34 ) . chr ( 41 ) . chr ( 41 ) . chr ( 59 ));
2014-03-23 16:03:30 -04:00
function hesk_stripArray ( $a )
{
2015-09-12 00:46:46 -04:00
foreach ( $a as $k => $v ) {
if ( is_array ( $v )) {
$a [ $k ] = hesk_stripArray ( $v );
} else {
$a [ $k ] = stripslashes ( $v );
2014-03-23 16:03:30 -04:00
}
}
2015-09-12 00:46:46 -04:00
reset ( $a );
2014-03-23 16:03:30 -04:00
return ( $a );
} // END hesk_stripArray()
function hesk_slashArray ( $a )
{
2015-09-12 00:46:46 -04:00
foreach ( $a as $k => $v ) {
if ( is_array ( $v )) {
$a [ $k ] = hesk_slashArray ( $v );
} else {
$a [ $k ] = addslashes ( $v );
2014-03-23 16:03:30 -04:00
}
}
2015-09-12 00:46:46 -04:00
reset ( $a );
2014-03-23 16:03:30 -04:00
return ( $a );
} // END hesk_slashArray()
2015-01-12 12:49:00 -05:00
function hesk_check_kb_only ( $redirect = true )
{
global $hesk_settings ;
2015-09-12 00:46:46 -04:00
if ( $hesk_settings [ 'kb_enable' ] != 2 ) {
2015-01-12 12:49:00 -05:00
return false ;
2015-09-12 00:46:46 -04:00
} elseif ( $redirect ) {
2015-01-12 12:49:00 -05:00
header ( 'Location:knowledgebase.php' );
exit ;
2015-09-12 00:46:46 -04:00
} else {
2015-01-12 12:49:00 -05:00
return true ;
}
} // END hesk_check_kb_only()
function hesk_check_maintenance ( $dodie = true )
{
global $hesk_settings , $hesklang ;
// No maintenance mode - return true
2015-09-12 00:46:46 -04:00
if ( ! $hesk_settings [ 'maintenance_mode' ] && ! is_dir ( HESK_PATH . 'install' )) {
2015-01-12 12:49:00 -05:00
return false ;
2015-09-12 00:46:46 -04:00
} // Maintenance mode, but do not exit - return true
elseif ( ! $dodie ) {
2015-01-12 12:49:00 -05:00
return true ;
}
// Maintenance mode - show notice and exit
require_once ( HESK_PATH . 'inc/header.inc.php' );
?>
2015-01-14 17:12:06 -05:00
< div class = " alert alert-warning " style = " margin: 20px " >
< i class = " fa fa-exclamation-triangle " ></ i >
2015-09-12 00:46:46 -04:00
< b >< ? php echo $hesklang [ 'mm1' ]; ?> </b><br/><br/>
< ? php echo $hesklang [ 'mm2' ]; ?> <br/><br/>
2015-01-12 12:49:00 -05:00
< ? php echo $hesklang [ 'mm3' ]; ?>
</ div >
< ? php
require_once ( HESK_PATH . 'inc/footer.inc.php' );
exit ();
} // END hesk_check_maintenance()
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
function hesk_error ( $error , $showback = 1 )
{
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
require_once ( HESK_PATH . 'inc/header.inc.php' );
?>
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
< ol class = " breadcrumb " >
< li >< a href = " <?php echo $hesk_settings['site_url'] ; ?> " >< ? php echo $hesk_settings [ 'site_title' ]; ?> </a></li>
< li >< a href = " <?php
if ( empty ( $_SESSION [ 'id' ])) {
2014-03-23 16:03:30 -04:00
echo $hesk_settings [ 'hesk_url' ];
2015-09-12 00:46:46 -04:00
} else {
2014-03-23 16:03:30 -04:00
echo HESK_PATH . $hesk_settings [ 'admin_dir' ] . '/admin_main.php' ;
}
?> "><?php echo $hesk_settings['hesk_title']; ?></a>
2015-09-12 00:46:46 -04:00
</ li >
< li >< ? php echo $hesklang [ 'error' ]; ?> </li>
</ ol >
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
< div class = " row " >
2015-11-08 17:29:43 -05:00
< div class = " col-md-10 col-md-offset-1 " >
< div class = " alert alert-danger " >
< b >< ? php echo $hesklang [ 'error' ]; ?> :</b><br/><br/>
< ? php
echo $error ;
if ( $hesk_settings [ 'debug_mode' ]) {
echo '
< p >& nbsp ; </ p >
< p >< span style = " color:red;font-weight:bold " > ' . $hesklang[' warn '] . ' </ span >< br /> ' . $hesklang[' dmod '] . ' </ p > ' ;
}
?>
</ div >
</ div >
2015-09-12 00:46:46 -04:00
</ div >
< br />
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
< p >& nbsp ; </ p >
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
< ? php
if ( $showback ) {
?>
< p style = " text-align:center " >< a class = " btn btn-default "
href = " javascript:history.go(-1) " >< ? php echo $hesklang [ 'back' ]; ?> </a></p>
< ? php
}
?>
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
< p >& nbsp ; </ p >
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
< p >& nbsp ; </ p >
< ? php
require_once ( HESK_PATH . 'inc/footer.inc.php' );
exit ();
2014-03-23 16:03:30 -04:00
} // END hesk_error()
function hesk_round_to_half ( $num )
{
2015-09-12 00:46:46 -04:00
if ( $num >= ( $half = ( $ceil = ceil ( $num )) - 0.5 ) + 0.25 ) {
return $ceil ;
} elseif ( $num < $half - 0.25 ) {
return floor ( $num );
} else {
return $half ;
2014-03-23 16:03:30 -04:00
}
} // END hesk_round_to_half()
2015-01-19 00:29:23 -05:00
2015-09-12 00:46:46 -04:00
function hesk_dateToString ( $dt , $returnName = 1 , $returnTime = 0 , $returnMonth = 0 , $from_database = false )
2015-01-19 00:29:23 -05:00
{
global $hesk_settings , $hesklang ;
$dt = strtotime ( $dt );
// Adjust MySQL time if different from PHP time
2015-09-12 00:46:46 -04:00
if ( $from_database ) {
if ( ! defined ( 'MYSQL_TIME_DIFF' )) {
define ( 'MYSQL_TIME_DIFF' , time () - hesk_dbTime ());
2015-01-19 00:29:23 -05:00
}
2015-09-12 00:46:46 -04:00
if ( MYSQL_TIME_DIFF != 0 ) {
2015-01-19 00:29:23 -05:00
$dt += MYSQL_TIME_DIFF ;
}
// Add HESK set time difference
2015-09-12 00:46:46 -04:00
$dt += 3600 * $hesk_settings [ 'diff_hours' ] + 60 * $hesk_settings [ 'diff_minutes' ];
2015-01-19 00:29:23 -05:00
// Daylight saving?
2015-09-12 00:46:46 -04:00
if ( $hesk_settings [ 'daylight' ] && date ( 'I' , $dt )) {
2015-01-19 00:29:23 -05:00
$dt += 3600 ;
}
}
2015-09-12 00:46:46 -04:00
list ( $y , $m , $n , $d , $G , $i , $s ) = explode ( '-' , date ( 'Y-n-j-w-G-i-s' , $dt ));
2015-01-19 00:29:23 -05:00
2015-09-12 00:46:46 -04:00
$m = $hesklang [ 'm' . $m ];
$d = $hesklang [ 'd' . $d ];
2015-01-19 00:29:23 -05:00
2015-09-12 00:46:46 -04:00
if ( $returnName ) {
2015-01-19 00:29:23 -05:00
return " $d , $m $n , $y " ;
}
2015-09-12 00:46:46 -04:00
if ( $returnTime ) {
2015-01-19 00:29:23 -05:00
return " $d , $m $n , $y $G : $i : $s " ;
}
2015-09-12 00:46:46 -04:00
if ( $returnMonth ) {
2015-01-19 00:29:23 -05:00
return " $m $y " ;
}
return " $m $n , $y " ;
} // End hesk_dateToString()
2015-06-13 01:20:06 -04:00
2015-09-12 00:46:46 -04:00
function hesk_getFeatureArray ()
{
2015-06-13 01:20:06 -04:00
return array (
2015-09-12 00:46:46 -04:00
'can_view_tickets' , /* User can read tickets */
'can_reply_tickets' , /* User can reply to tickets */
'can_del_tickets' , /* User can delete tickets */
'can_edit_tickets' , /* User can edit tickets */
'can_merge_tickets' , /* User can merge tickets */
'can_del_notes' , /* User can delete ticket notes posted by other staff members */
'can_change_cat' , /* User can move ticke to a new category/department */
'can_man_kb' , /* User can manage knowledgebase articles and categories */
'can_man_users' , /* User can create and edit staff accounts */
'can_man_cat' , /* User can manage categories/departments */
'can_man_canned' , /* User can manage canned responses */
'can_man_ticket_tpl' , /* User can manage ticket templates */
'can_add_archive' , /* User can mark tickets as "Tagged" */
'can_assign_self' , /* User can assign tickets to himself/herself */
'can_assign_others' , /* User can assign tickets to other staff members */
'can_view_unassigned' , /* User can view unassigned tickets */
'can_view_ass_others' , /* User can view tickets that are assigned to other staff */
'can_run_reports' , /* User can run reports and see statistics (only allowed categories and self) */
2015-06-13 01:20:06 -04:00
'can_run_reports_full' , /* User can run reports and see statistics (unrestricted) */
2015-09-12 00:46:46 -04:00
'can_export' , /* User can export own tickets to Excel */
'can_view_online' , /* User can view what staff members are currently online */
'can_ban_emails' , /* User can ban email addresses */
'can_unban_emails' , /* User can delete email address bans. Also enables "can_ban_emails" */
'can_ban_ips' , /* User can ban IP addresses */
'can_unban_ips' , /* User can delete IP bans. Also enables "can_ban_ips" */
'can_service_msg' , /* User can manage service messages shown in customer interface */
2015-06-13 01:20:06 -04:00
'can_man_email_tpl' , /* User can manage email templates */
'can_man_ticket_statuses' , /* User can manage ticket statuses */
'can_set_manager' , /* User can set category managers */
2015-06-14 23:38:14 -04:00
'can_man_permission_tpl' , /* User can manage permission templates */
2015-06-15 23:15:10 -04:00
'can_man_settings' , /* User can manage helpdesk settings */
2015-06-16 00:14:28 -04:00
'can_change_notification_settings' , /* User can change notification settings */
2015-12-10 22:15:32 -05:00
'can_view_logs' , /* User can view the message logs */
2016-04-15 21:39:39 -04:00
'can_man_calendar' , /* User can manage calendar events */
2015-06-13 01:20:06 -04:00
);
2015-07-25 22:08:07 -04:00
}
2015-09-12 00:46:46 -04:00
function mfh_doesStatusHaveXrefRecord ( $statusId , $language )
{
global $hesk_settings ;
2015-07-26 21:23:04 -04:00
2015-09-12 00:46:46 -04:00
$rs = hesk_dbQuery ( " SELECT 1 FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " text_to_status_xref`
WHERE `language` = '" . hesk_dbEscape($language) . "' AND `status_id` = " . intval( $statusId ));
return hesk_dbNumRows ( $rs ) > 0 ;
2015-07-26 21:23:04 -04:00
}
2015-09-12 00:46:46 -04:00
function mfh_getDisplayTextForStatusId ( $statusId )
{
global $hesklang , $hesk_settings ;
$statusRs = hesk_dbQuery ( " SELECT `text`, `Key`, `language` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " statuses` AS `statuses`
LEFT JOIN `" . hesk_dbEscape($hesk_settings['db_pfix']) . "text_to_status_xref` ON `status_id` = `statuses` . `ID`
AND `language` = '" . hesk_dbEscape($hesk_settings[' language ']) . "'
WHERE `statuses` . `ID` = " . intval( $statusId ));
$statusRec = hesk_dbFetchAssoc ( $statusRs );
if ( $statusRec [ 'text' ] != NULL ) {
// We found a record. Use the text field
return $statusRec [ 'text' ];
} else {
// Fallback to the language key
return $hesklang [ $statusRec [ 'Key' ]];
}
2015-08-04 12:37:36 -04:00
}
2015-09-12 00:46:46 -04:00
function mfh_getNumberOfDownloadsForAttachment ( $att_id , $table = 'attachments' )
2015-08-04 12:37:36 -04:00
{
2015-09-12 00:46:46 -04:00
global $hesk_settings ;
2015-08-04 12:37:36 -04:00
2015-09-12 00:46:46 -04:00
$res = hesk_dbQuery ( 'SELECT `download_count` FROM `' . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ] . $table ) . " ` WHERE `att_id` = " . intval ( $att_id ));
$rec = hesk_dbFetchAssoc ( $res );
return $rec [ 'download_count' ];
2015-08-28 22:04:21 -04:00
}
2015-09-12 00:46:46 -04:00
function mfh_getSettings ()
{
global $hesk_settings ;
2015-08-28 22:04:21 -04:00
2015-09-12 00:46:46 -04:00
$settings = array ();
$res = hesk_dbQuery ( " SELECT `Key`, `Value` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " settings` WHERE `Key` <> 'modsForHeskVersion' " );
while ( $row = hesk_dbFetchAssoc ( $res )) {
$settings [ $row [ 'Key' ]] = $row [ 'Value' ];
}
return $settings ;
2015-12-10 22:15:32 -05:00
}
function mfh_log ( $location , $message , $severity , $user ) {
global $hesk_settings ;
$sql = " INSERT INTO ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " logging` (`username`, `message`, `severity`, `location`, `timestamp`)
VALUES ( '" . hesk_dbEscape($user) . "' ,
'" . hesk_dbEscape($message) . "' , " . intval( $severity ) . " , '" . hesk_dbEscape($location) . "' , NOW ()) " ;
2016-01-26 10:09:46 -05:00
hesk_dbQuery ( $sql );
2015-12-10 22:15:32 -05:00
}
function mfh_log_debug ( $location , $message , $user ) {
2016-04-26 08:59:54 -04:00
global $hesk_settings ;
if ( $hesk_settings [ 'debug_mode' ]) {
mfh_log ( $location , $message , 0 , $user );
}
2015-12-10 22:15:32 -05:00
}
function mfh_log_info ( $location , $message , $user ) {
mfh_log ( $location , $message , 1 , $user );
}
function mfh_log_warning ( $location , $message , $user ) {
mfh_log ( $location , $message , 2 , $user );
}
function mfh_log_error ( $location , $message , $user ) {
mfh_log ( $location , $message , 3 , $user );
2015-12-28 22:05:20 -05:00
}
function mfh_bytesToUnits ( $size ) {
$bytes_in_megabyte = 1048576 ;
$quotient = $size / $bytes_in_megabyte ;
return intval ( $quotient );
2015-06-13 01:20:06 -04:00
}