logging, new unique ID and improve start case

This commit is contained in:
Fernando Ontiveros
2025-04-24 17:55:41 +00:00
parent 85020fbdbd
commit 66d2c7a6a4
5 changed files with 69 additions and 45 deletions

View File

@@ -2858,6 +2858,31 @@ class G
//return strtoupper(substr(uniqid(rand(0, 9), false),0,14));
}
/**
* Generate random number
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return int
*/
public static function generateUid($prefix = '')
{
// Ensure the prefix is exactly 3 alphabetical characters if not return default prefix
if (strlen($prefix) !== 3 || !ctype_alpha($prefix)) {
$prefix = "abc";
}
// Generate a unique ID based on the current time in microseconds
$uniqueId = uniqid('', true);
// Remove the prefix from the unique ID and ensure it's 29 characters long
$uniqueId = date('YmdH') . str_replace('.', '', $uniqueId); // Remove any dots
$uniqueId = substr($uniqueId, -29); // Trim to 29 characters
// Combine the prefix with the unique ID
return strtolower($prefix) . $uniqueId; // Convert prefix to uppercase
}
/**
* Generate a numeric or alphanumeric code
*
@@ -2873,19 +2898,23 @@ class G
if (($sType != 'NUMERIC') && ($sType != 'ALPHA') && ($sType != 'ALPHANUMERIC')) {
$sType = 'NUMERIC';
}
$aValidCharacters = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
// Define a character set excluding visually similar characters
$aValidCharacters = array(
'2', '3', '4', '5', '6', '7', '8', '9', // Numbers excluding 0 and 1
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'Q', 'R', 'T', 'U', 'V', 'W', 'X', 'Y' // Uppercase letters excluding O, I, L, S, Z
);
switch ($sType) {
case 'NUMERIC':
$iMin = 0;
$iMax = 9;
$iMax = 7;
break;
case 'ALPHA':
$iMin = 10;
$iMax = 35;
$iMin = 8;
$iMax = 28;
break;
case 'ALPHANUMERIC':
$iMin = 0;
$iMax = 35;
$iMax = 28;
break;
}
$sCode = '';