I'll add the code, maybe I didn't change something correctly in the functions?
Code: Select all
function hesk_createID()
{
global $hesk_settings, $hesklang, $hesk_error_buffer;
/*** Generate tracking ID and make sure it's not a duplicate one ***/
/* Ticket ID can be of these chars */
$useChars = '123456789';
/* Set tracking ID to an empty string */
$trackingID = '';
/* Let's avoid duplicate ticket ID's, try up to 3 times */
for ($i=1;$i<=3;$i++)
{
/* Generate raw ID */
$trackingID .= 'P';
$trackingID .= 'S';
$trackingID .= 'K';
$trackingID .= '-';
$trackingID .= $useChars[mt_rand(0,9)];
$trackingID .= $useChars[mt_rand(0,9)];
$trackingID .= $useChars[mt_rand(0,9)];
$trackingID .= $useChars[mt_rand(0,9)];
$trackingID .= $useChars[mt_rand(0,9)];
$trackingID .= $useChars[mt_rand(0,9)];
/* Format the ID to the correct shape and check wording */
$trackingID = hesk_formatID($trackingID);
/* Check for duplicate IDs */
$res = hesk_dbQuery("SELECT `id` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` WHERE `trackid` = '".hesk_dbEscape($trackingID)."' LIMIT 1");
if (hesk_dbNumRows($res) == 0)
{
/* Everything is OK, no duplicates found */
return $trackingID;
}
/* 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() */
$trackingID = $useChars[mt_rand(0,9)];
$trackingID .= $useChars[mt_rand(0,9)];
$trackingID .= $useChars[mt_rand(0,9)];
$trackingID .= $useChars[mt_rand(0,9)];
$trackingID .= $useChars[mt_rand(0,9)];
$trackingID .= substr(microtime(), -5);
/* Format the ID to the correct shape and check wording */
$trackingID = hesk_formatID($trackingID);
$res = hesk_dbQuery("SELECT `id` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` WHERE `trackid` = '".hesk_dbEscape($trackingID)."' LIMIT 1");
/* All failed, must be a server-side problem... */
if (hesk_dbNumRows($res) == 0)
{
return $trackingID;
}
$hesk_error_buffer['etid'] = $hesklang['e_tid'];
return false;
} // END hesk_createID()
function hesk_formatID($id)
{
$useChars = '123456789';
$replace = $useChars[mt_rand(0,9)];
$replace .= mt_rand(1,9);
$replace .= $useChars[mt_rand(0,9)];
/*
Remove 3 letter bad words from ID
Possiblitiy: 1:27,000
*/
$remove = array(
'ASS',
'CUM',
'FAG',
'FUK',
'GAY',
'SEX',
'TIT',
'XXX',
);
$id = str_replace($remove,$replace,$id);
/*
Remove 4 letter bad words from ID
Possiblitiy: 1:810,000
*/
$remove = array(
'ANAL',
'ANUS',
'BUTT',
'CAWK',
'CLIT',
'COCK',
'CRAP',
'CUNT',
'DICK',
'DYKE',
'FART',
'f***',
'JAPS',
'JERK',
'JIZZ',
'KNOB',
'PISS',
'POOP',
'SHIT',
'SLUT',
'SUCK',
'TURD',
// Also, remove words that are known to trigger mod_security
'WGET',
);
$replace .= mt_rand(1,9);
$id = str_replace($remove,$replace,$id);
/* Format the ID string into XXX-XXX-XXXX format for easier readability */
$id = $id[0].$id[1].$id[2].$id[3].$id[4].$id[5].$id[6].$id[7].$id[8].$id[9];
return $id;
} // END hesk_formatID()
I noticed that on the hesk demo, if you enter TrackingID not entirely, then it will not find anything either. Is there a rule somewhere that there must be a 100% match of TrackingID in search for the ticket to be found?