FunctionsController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\Validator;
  5. use Illuminate\Support\Facades\DB;
  6. use Illuminate\Support\Facades\Hash;
  7. use Illuminate\Support\Carbon;
  8. class FunctionsController extends Controller{
  9. public function __construct(){}
  10. public static function uuidv5($namespace, $name) {
  11. if(!self::is_valid($namespace)) return false;
  12. // Get hexadecimal components of namespace
  13. $nhex = str_replace(array('-','{','}'), '', $namespace);
  14. // Binary Value
  15. $nstr = '';
  16. // Convert Namespace UUID to bits
  17. for($i = 0; $i < strlen($nhex); $i+=2) {
  18. $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1]));
  19. }
  20. // Calculate hash value
  21. $hash = sha1($nstr . $name);
  22. return sprintf('%08s-%04s-%04x-%04x-%12s',
  23. // 32 bits for "time_low"
  24. substr($hash, 0, 8),
  25. // 16 bits for "time_mid"
  26. substr($hash, 8, 4),
  27. // 16 bits for "time_hi_and_version",
  28. // four most significant bits holds version number 5
  29. (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000,
  30. // 16 bits, 8 bits for "clk_seq_hi_res",
  31. // 8 bits for "clk_seq_low",
  32. // two most significant bits holds zero and one for variant DCE1.1
  33. (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
  34. // 48 bits for "node"
  35. substr($hash, 20, 12)
  36. );
  37. }
  38. public static function is_valid($uuid) {
  39. return preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?'.
  40. '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/i', $uuid) === 1;
  41. }
  42. public function generateID($seed, $timestamp){
  43. $string = str_replace(" ", "", $seed) . $timestamp;
  44. $array = [];
  45. for($i = 0; $i < strlen($string); $i++){
  46. $array[] = $string[$i];
  47. }
  48. shuffle($array);
  49. $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  50. $ID = '';
  51. foreach($array as $char){
  52. $ascii = ord($char);
  53. $s = $ascii / 100;
  54. if($s >= 1) continue;
  55. $s = $s * strlen($chars);
  56. $s = intval($s);
  57. $l = $chars[$s];
  58. if(strlen($ID) < 20) $ID .= $l;
  59. }
  60. if(strlen($ID) < 20){
  61. for($i = strlen($ID); $i < 20; $i++){
  62. $s = rand(0, strlen($chars) - 1);
  63. $l = $chars[$s];
  64. $ID .= $l;
  65. }
  66. }
  67. return $ID;
  68. }
  69. public function getType($type){
  70. switch($type){
  71. case "insert":
  72. return "CREATE";
  73. break;
  74. case "update":
  75. return strtoupper($type);
  76. break;
  77. case "select":
  78. return "READ";
  79. break;
  80. case "delete":
  81. return strtoupper($type);
  82. break;
  83. default:
  84. return "UNKNOWN";
  85. break;
  86. }
  87. }
  88. public function registerLog($querys, $user, $date, $idac, $line){
  89. foreach($querys as $query){
  90. $script = $query['query'];
  91. $params = json_encode($query['bindings']);
  92. DB::table('S002V01TLOMY')->insert([
  93. 'LOMY_NULI' => $line,
  94. 'LOMY_IDAC' => $idac,
  95. 'LOMY_QUER' => $script,
  96. 'LOMY_PARA' => $params,
  97. 'LOMY_FECH' => $date,
  98. 'LOMY_IDUS' => $user,
  99. ]);
  100. }
  101. }
  102. public function registerActivity($line, $module, $function, $screen, $action, $description, $user, $date, $submodule = null){
  103. $id = DB::table('S002V01TACCI')->insertGetId([
  104. 'ACCI_NULI' => $line,
  105. 'ACCI_IDMO' => $module,
  106. 'ACCI_IDSM' => $submodule,
  107. 'ACCI_IDFU' => $function,
  108. 'ACCI_IDPA' => $screen,
  109. 'ACCI_TIAC' => $action,
  110. 'ACCI_DESC' => $description,
  111. 'ACCI_IDUS' => $user,
  112. 'ACCI_FEAC' => $date
  113. ]);
  114. DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $user)->update([
  115. 'USUA_ULAC' => $id
  116. ]);
  117. return $id;
  118. }
  119. public function joinName($name, $fApe, $sApe = null){
  120. $fullName = "$name $fApe";
  121. if(!is_null($sApe)){
  122. $fullName = "$fullName $sApe";
  123. }
  124. return $fullName;
  125. }
  126. public function checkFileSize($ext, $size){
  127. $availableFiles = [
  128. 250=> ["zip", "tar", "rar", "7z", "mp3", "mpeg", "wav", "ogg", "opus", "jpg", "png", "gif", "bmp", "tiff", "svg",
  129. "txt", "webm", "mp4", "3gp", "mov", "avi", "wmv", "flv", "dwg", "dxf", "3ds", "ai", "psd"],
  130. 50 => ["doc", "docx", "vsd", "vsdx", "pdf"],
  131. 75 => ["xls", "xlsx"],
  132. 100=> ["ppt", "pptx"],
  133. ];
  134. $maxFileSizeMB = 0;
  135. foreach($availableFiles as $k=>$v){
  136. if(in_array($ext, $v)) $maxFileSizeMB = $k;
  137. }
  138. if($maxFileSizeMB == 0) return false;
  139. $maxFileSize = $maxFileSizeMB * 1048576;
  140. return $size < $maxFileSize;
  141. }
  142. }