UsersProfilesController.php 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Support\Facades\Validator;
  6. use Illuminate\Support\Facades\Hash;
  7. use Illuminate\Support\Carbon;
  8. class UsersProfilesController extends Controller{
  9. private $responseController;
  10. private $encryptionController;
  11. private $functionsController;
  12. private $moduleCode = 'S002V01M02USPE';
  13. public function __construct(){
  14. $this->responseController = new ResponseController();
  15. $this->encryptionController = new EncryptionController();
  16. $this->functionsController = new FunctionsController();
  17. }
  18. public function getUsers($idUser, $line){
  19. DB::enableQueryLog();
  20. $idUser = $this->encryptionController->decrypt($idUser);
  21. if(!$idUser){
  22. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  23. }
  24. $usr = DB::table('S002V01TUSUA')->where([
  25. ['USUA_IDUS', '=', $idUser],
  26. ['USUA_NULI', '=', $line],
  27. ])->first();
  28. if(is_null($usr)){
  29. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 400);
  30. }
  31. $users = DB::table('S002V01TUSUA')->select([
  32. 'USUA_IDUS as IDUSUARIO',
  33. 'USUA_NOMB as NOMBRE',
  34. 'USUA_APPA as APEPAT',
  35. 'USUA_APMA as APEMAT',
  36. 'USUA_COEL as EMAIL',
  37. DB::raw("CONCAT(PERF_NOPE, ' (', PERF_IDPE, ')') AS PERFIL"),
  38. DB::raw("IF(ISNULL(PACO_IDPC), FALSE, TRUE) AS TIENE_PANEL"),
  39. DB::raw("IF(ISNULL(PACO_IDPC), '-', CONCAT(PACO_NPCO, ' (', PACO_IDPC, ')')) AS PANEL_CONTROL"),
  40. 'USUA_ESTA as ESTATUS',
  41. 'BIAC_FECO as ULCON',
  42. 'USUA_ORGA as ORGANIGRAMA',
  43. ])->join('S002V01TPERF', 'USUA_PERF', '=', 'PERF_IDPE')
  44. ->leftJoin('S002V01TBIAC', 'USUA_ULCO', '=', 'BIAC_IDCO')
  45. ->leftJoin('S002V01TPACO', 'USUA_PCRE', '=', 'PACO_IDPC')
  46. ->where('USUA_NULI', '=', $line)->get()->all();
  47. foreach($users as $key=>$user){
  48. $user->IDUSUARIO = $this->encryptionController->encrypt($user->IDUSUARIO);
  49. $user->TIENE_PANEL = $user->TIENE_PANEL == 1;
  50. if(is_null($user->ORGANIGRAMA)){
  51. $user->ORGANIGRAMA = '[]';
  52. }else{
  53. $organization = json_decode($user->ORGANIGRAMA, true);
  54. foreach($organization as $index=>$item){
  55. $idChiefEnc = $this->encryptionController->encrypt($item['id_chief']);
  56. $item['id_chief'] = $idChiefEnc;
  57. $organization[$index] = $item;
  58. }
  59. $user->ORGANIGRAMA = json_encode($organization);
  60. }
  61. $users[$key] = $user;
  62. }
  63. $now = $this->functionsController->now();
  64. $nowStr = $now->toDateTimeString();
  65. $actions = DB::getQueryLog();
  66. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  67. $idac = $this->functionsController->registerActivity(
  68. $line,
  69. $this->moduleCode,
  70. 'S002V01F01ADUS',
  71. 'S002V01P01COUS',
  72. 'Consulta',
  73. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los usuarios registrados.",
  74. $idUser,
  75. $nowStr,
  76. 'S002V01S01GEUS'
  77. );
  78. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  79. return $this->responseController->makeresponse(false, "EXITO", $users);
  80. }
  81. public function configureUserOrganization(Request $request){
  82. DB::enableQueryLog();
  83. $validator = Validator::make($request->all(), [
  84. 'id_user' => 'required|string',
  85. 'linea' => 'required|integer',
  86. 'organization' => 'required|json',
  87. 'configured_user' => 'required|string',
  88. ]);
  89. if($validator->fails()){
  90. return $this->responseController->makeResponse(
  91. true,
  92. "Se encontraron uno o más errores.",
  93. $this->responseController->makeErrors(
  94. $validator->errors()->messages()
  95. ),
  96. 401
  97. );
  98. }
  99. $form = $request->all();
  100. $idUser = $this->encryptionController->decrypt($form['id_user']);
  101. if(!$idUser){
  102. return $this->responseController->makeResponse(true, "El ID del usuario que realizó la solicitud no está encriptado correctamente.", [], 400);
  103. }
  104. $user = DB::table('S002V01TUSUA')->where([
  105. ['USUA_IDUS', '=', $idUser],
  106. ['USUA_NULI', '=', $form['linea']],
  107. ])->first();
  108. if(is_null($user)){
  109. return $this->responseController->makeResponse(true, 'El usuario usuario que realizó la solicitud no exise.', [], 404);
  110. }
  111. $idConfiguredUser = $this->encryptionController->decrypt($form['configured_user']);
  112. if(!$idConfiguredUser){
  113. return $this->responseController->makeResponse(true, "El ID del usuario que está configurando no fue encriptado correctamente.", [], 400);
  114. }else if($idUser == $idConfiguredUser){
  115. return $this->responseController->makeResponse(true, "El usuario no puede configurar su propio organigrama.", [], 400);
  116. }
  117. $configuredUser = DB::table('S002V01TUSUA')->where([
  118. ['USUA_IDUS', '=', $idConfiguredUser],
  119. ['USUA_NULI', '=', $form['linea']],
  120. ])->first();
  121. if(is_null($configuredUser)){
  122. return $this->responseController->makeResponse(true, 'El usuario usuario que desea configurar no exise.', [], 404);
  123. }else if($configuredUser->USUA_ESTA == 'Eliminado'){
  124. return $this->responseController->makeResponse(true, 'El usuario usuario que desea configurar esta eliminado.', [], 400);
  125. }
  126. $organization = json_decode($form['organization'], true);
  127. if(!is_array($organization)){
  128. return $this->responseController->makeResponse(true, 'La configuración del organigrama debe ser un arreglo.', [], 400);
  129. }else if(count($organization) < 1){
  130. return $this->responseController->makeResponse(true, 'El arreglo de configuración del organigrama debe contener al menos un elemento.', [], 400);
  131. }
  132. foreach($organization as $index=>$item){
  133. if(!is_array($item)){
  134. return $this->responseController->makeResponse(true, "El elemento en la posición $index del arreglo de configuración del organigrama no es un arreglo.", [], 400);
  135. }else if(!array_key_exists("level", $item) || !array_key_exists("id_chief", $item)){
  136. return $this->responseController->makeResponse(true, "El elemento en la posición $index del arreglo de configuración del organigrama tiene un formato inválido.", [], 400);
  137. }
  138. $idChiefDec = $this->encryptionController->decrypt($item['id_chief']);
  139. if(!$idChiefDec){
  140. return $this->responseController->makeResponse(true, "El ID del jefe del elemento en la posición $index del arreglo de configuración del organigrama no fue encriptado correctamente.", [], 400);
  141. }else if($idConfiguredUser == $idChiefDec){
  142. return $this->responseController->makeResponse(true, "El ID del jefe del elemento en la posición $index del arreglo de configuración del organigrama no puede ser igual al ID del usuario que está configurando.", [], 400);
  143. }
  144. $item['id_chief'] = $idChiefDec;
  145. $organization[$index] = $item;
  146. }
  147. $organizationStr = json_encode($organization);
  148. $now = $this->functionsController->now();
  149. $nowStr = $now->toDateTimeString();
  150. DB::table('S002V01TUSUA')->where([
  151. ['USUA_IDUS', '=', $idConfiguredUser],
  152. ['USUA_NULI', '=', $form['linea']]
  153. ])->update([
  154. 'USUA_ORGA' => $organizationStr,
  155. 'USUA_USMO' => $idUser,
  156. 'USUA_FEMO' => $nowStr
  157. ]);
  158. $actions = DB::getQueryLog();
  159. $name = $this->functionsController->joinName($user->USUA_NOMB, $user->USUA_APPA, $user->USUA_APMA);
  160. $nameMod = $this->functionsController->joinName($configuredUser->USUA_NOMB, $configuredUser->USUA_APPA, $configuredUser->USUA_APMA);
  161. $idac = $this->functionsController->registerActivity(
  162. $form['linea'],
  163. $this->moduleCode,
  164. 'S002V01F01ADUS',
  165. 'S002V01P02RAUS',
  166. 'Actualización',
  167. "El usuario $name (" . $user->USUA_IDUS . ") actualizó el organigrama del usuario $nameMod (" . $configuredUser->USUA_IDUS . ").",
  168. $idUser,
  169. $nowStr,
  170. 'S002V01S01GEUS'
  171. );
  172. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  173. return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
  174. }
  175. public function getUser($id, $idUser, $line){
  176. DB::enableQueryLog();
  177. $idUser = $this->encryptionController->decrypt($idUser);
  178. if(!$idUser){
  179. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no fue encriptado correctamente.', [], 400);
  180. }
  181. $usr = DB::table('S002V01TUSUA')->where([
  182. ['USUA_IDUS', '=', $idUser],
  183. ['USUA_NULI', '=', $line],
  184. ])->first();
  185. if(is_null($usr)){
  186. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe.', [], 400);
  187. }
  188. $id = $this->encryptionController->decrypt($id);
  189. if(!$id){
  190. return $this->responseController->makeResponse(true, "El ID del usuario consultado no está encriptado correctamente.", [], 400);
  191. }
  192. $user = DB::table('S002V01TUSUA')->select(
  193. 'USUA_IDUS AS IDUSUARIO',
  194. 'USUA_NOMB AS NOMBRE',
  195. 'USUA_APPA AS APEPAT',
  196. 'USUA_APMA AS APEMAT',
  197. 'USUA_COEL AS EMAIL',
  198. 'USUA_PERF AS PERFIL',
  199. 'PERF_NOPE AS PERFNOMB',
  200. 'USUA_ESTA AS ESTATUS',
  201. )->where([
  202. ['USUA_IDUS', '=', $id],
  203. ['USUA_NULI', '=', $line],
  204. ])->join('S002V01TPERF', 'PERF_IDPE', '=', 'USUA_PERF')->first();
  205. if(is_null($user)){
  206. return $this->responseController->makeResponse(true, "El usuario consultado no existe.", [], 404);
  207. }
  208. $user->IDUSUARIO = $this->encryptionController->encrypt($user->IDUSUARIO);
  209. $user->PERFIL = $this->encryptionController->encrypt($user->PERFIL);
  210. $now = $this->functionsController->now();
  211. $nowStr = $now->toDateTimeString();
  212. $actions = DB::getQueryLog();
  213. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  214. $nameCons = $this->functionsController->joinName($user->NOMBRE, $user->APEPAT, $user->APEMAT);
  215. $idac = $this->functionsController->registerActivity(
  216. $line,
  217. $this->moduleCode,
  218. 'S002V01F01ADUS',
  219. 'S002V01P01COUS',
  220. 'Consulta',
  221. "El usuario $name (" . $usr->USUA_IDUS . ") consultó al usuario $nameCons (" . $user->IDUSUARIO . ").",
  222. $idUser,
  223. $nowStr,
  224. 'S002V01S01GEUS'
  225. );
  226. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  227. return $this->responseController->makeresponse(false, "EXITO", $user);
  228. }
  229. public function getProfiles($idUser, $line){
  230. DB::enableQueryLog();
  231. $idUser = $this->encryptionController->decrypt($idUser);
  232. if(!$idUser){
  233. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  234. }
  235. $usr = DB::table('S002V01TUSUA')->where([
  236. ['USUA_IDUS', '=', $idUser],
  237. ['USUA_NULI', '=', $line]
  238. ])->first();
  239. if(is_null($usr)){
  240. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  241. }
  242. $profiles = DB::table('S002V01TPERF')->select(
  243. 'PERF_IDPE AS IDPERFIL',
  244. 'PERF_NOPE AS NOMBREPERFIL',
  245. 'PERF_PERM AS PERMISOS',
  246. 'PERF_ESTA AS ESTADO',
  247. 'PERF_USRE AS USRREG',
  248. 'PERF_FERE AS FECREG',
  249. 'PERF_USMO AS USRMOD',
  250. 'PERF_FEMO AS FECMOD',
  251. )->where('PERF_NULI', '=', $line)->orderBy('PERF_IDPE', 'desc')->get()->all();
  252. foreach($profiles as $key=>$profile){
  253. $relatedUsers = DB::table('S002V01TUSUA')->where([
  254. ['USUA_NULI', '=', $line],
  255. ['USUA_PERF', '=', $profile->IDPERFIL]
  256. ])->get()->all();
  257. $profile->IDPERFIL = $this->encryptionController->encrypt($profile->IDPERFIL);
  258. $profile->PERMISOS = $this->encryptionController->encrypt($profile->PERMISOS);
  259. $usrReg = DB::table('S002V01TUSUA')->where([
  260. ['USUA_NULI', '=', $line],
  261. ['USUA_IDUS', '=', $profile->USRREG]
  262. ])->first();
  263. $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
  264. $profile->USRREG = $usrRegName . " (" . $profile->USRREG . ")";
  265. if(!is_null($profile->USRMOD)){
  266. $usrMod = DB::table('S002V01TUSUA')->where([
  267. ['USUA_NULI', '=', $line],
  268. ['USUA_IDUS', '=', $profile->USRMOD]
  269. ])->first();
  270. $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
  271. $profile->USRMOD = $usrModName . " (" . $profile->USRMOD . ")";
  272. }
  273. $profile->USUARIOS_RELACIONADOS = count($relatedUsers);
  274. $profiles[$key] = $profile;
  275. }
  276. $now = $this->functionsController->now();
  277. $nowStr = $now->toDateTimeString();
  278. $actions = DB::getQueryLog();
  279. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  280. $idac = $this->functionsController->registerActivity(
  281. $line,
  282. $this->moduleCode,
  283. 'S002V01F01ADPE',
  284. 'S002V01P01COPE',
  285. 'Consulta',
  286. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los perfiles registrados.",
  287. $idUser,
  288. $nowStr,
  289. 'S002V01S02GEPE'
  290. );
  291. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  292. return $this->responseController->makeresponse(false, "EXITO", $profiles);
  293. }
  294. public function getProfile($idProfile, $idUser, $line){
  295. DB::enableQueryLog();
  296. $idUser = $this->encryptionController->decrypt($idUser);
  297. if(!$idUser){
  298. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  299. }
  300. $usr = DB::table('S002V01TUSUA')->where([
  301. ['USUA_IDUS', '=', $idUser],
  302. ['USUA_NULI', '=', $line],
  303. ])->first();
  304. if(is_null($usr)){
  305. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 400);
  306. }
  307. $idProfile = $this->encryptionController->decrypt($idProfile);
  308. if(!$idProfile){
  309. return $this->responseController->makeResponse(true, "El ID del perfil no está encriptado correctamente.", [], 401);
  310. }
  311. $profile = DB::table('S002V01TPERF')->select(
  312. 'PERF_IDPE AS IDPERFIL',
  313. 'PERF_NOPE AS NOMBREPERFIL',
  314. 'PERF_ESTA AS ESTATUS',
  315. 'PERF_PERM AS PERMISOS',
  316. )->where([
  317. ['PERF_IDPE', '=', $idProfile],
  318. ['PERF_NULI', '=', $line],
  319. ])->first();
  320. if(is_null($profile)){
  321. return $this->responseController->makeResponse(true, "El perfil consultado no existe.", [], 404);
  322. }
  323. $profile->IDPERFIL = $this->encryptionController->encrypt($profile->IDPERFIL);
  324. $profilePermissions = json_decode($profile->PERMISOS, true);
  325. $permissions = [];
  326. $modules = DB::table('S002V01TMODU')->where('MODU_NULI', '=', $line)->get()->all();
  327. $moduleIndex = 0;
  328. foreach($modules as $module){
  329. $submodules = DB::table('S002V01TSUBM')->where([
  330. ['SUBM_IDMO', '=', $module->MODU_IDMO],
  331. ['SUBM_NULI', '=', $line]
  332. ])->get()->all();
  333. $permissionsPerSubmodule = [];
  334. $submoduleIndex = 0;
  335. foreach($submodules as $submodule){
  336. $functions = DB::table('S002V01TFUNC')->where([
  337. ['FUNC_IDMO', '=', $module->MODU_IDMO],
  338. ['FUNC_IDSM', '=', $submodule->SUBM_IDSM],
  339. ['FUNC_NULI', '=', $line],
  340. ])->get()->all();
  341. $permissionsPerFunction = [];
  342. $functionIndex = 0;
  343. foreach($functions as $function){
  344. $screens = DB::table('S002V01TPANT')->where([
  345. ['PANT_IDFU', '=', $function->FUNC_IDFU],
  346. ['PANT_NULI', '=', $line],
  347. ])->get()->all();
  348. $permissionsPerScreen = [];
  349. $screenIndex = 0;
  350. foreach($screens as $screen){
  351. $screenAccess = 0;
  352. if(isset($profilePermissions['permissions'][$moduleIndex]['children'][$submoduleIndex]['children'][$functionIndex]['children'][$screenIndex]['access'])){
  353. $screenAccess = $profilePermissions['permissions'][$moduleIndex]['children'][$submoduleIndex]['children'][$functionIndex]['children'][$screenIndex]['access'];
  354. }
  355. $permissionsPerScreen[] = [
  356. 'id' => $this->encryptionController->encrypt($screen->PANT_IDPA),
  357. 'name' => $screen->PANT_NOMB,
  358. 'access' => $screenAccess
  359. ];
  360. $screenIndex++;
  361. }
  362. $functionAcces = 0;
  363. if(isset($profilePermissions['permissions'][$moduleIndex]['children'][$submoduleIndex]['children'][$functionIndex]['access'])){
  364. $functionAcces = $profilePermissions['permissions'][$moduleIndex]['children'][$submoduleIndex]['children'][$functionIndex]['access'];
  365. }
  366. $permissionsPerFunction[] = [
  367. 'id' => $this->encryptionController->encrypt($function->FUNC_IDFU),
  368. 'name' => $function->FUNC_NOMB,
  369. 'access' => $functionAcces,
  370. 'children' => $permissionsPerScreen,
  371. ];
  372. $functionIndex++;
  373. }
  374. $submoduleAccess = 0;
  375. if(isset($profilePermissions['permissions'][$moduleIndex]['children'][$submoduleIndex]['access'])){
  376. $submoduleAccess = $profilePermissions['permissions'][$moduleIndex]['children'][$submoduleIndex]['access'];
  377. }
  378. $permissionsPerSubmodule[] = [
  379. 'id' => $this->encryptionController->encrypt($submodule->SUBM_IDSM),
  380. 'name' => $submodule->SUBM_NOMB,
  381. 'access' => $submoduleAccess,
  382. 'children' => $permissionsPerFunction,
  383. ];
  384. $submoduleIndex++;
  385. }
  386. $functions = DB::table('S002V01TFUNC')->where([
  387. ['FUNC_IDMO', '=', $module->MODU_IDMO],
  388. ['FUNC_IDSM', '=', null],
  389. ['FUNC_NULI', '=', $line],
  390. ])->get()->all();
  391. $permissionsPerFunction = [];
  392. $functionIndex = 0;
  393. foreach($functions as $function){
  394. $screens = DB::table('S002V01TPANT')->where([
  395. ['PANT_IDFU', '=', $function->FUNC_IDFU],
  396. ['PANT_NULI', '=', $line],
  397. ])->get()->all();
  398. $permissionsPerScreen = [];
  399. $screenIndex = 0;
  400. foreach($screens as $screen){
  401. $screenAccess = 0;
  402. if(isset($profilePermissions['permissions'][$moduleIndex]['children'][$functionIndex]['children'][$screenIndex]['access'])){
  403. $screenAccess = $profilePermissions['permissions'][$moduleIndex]['children'][$functionIndex]['children'][$screenIndex]['access'];
  404. }
  405. $permissionsPerScreen[] = [
  406. 'id' => $this->encryptionController->encrypt($screen->PANT_IDPA),
  407. 'name' => $screen->PANT_NOMB,
  408. 'access' => $screenAccess
  409. ];
  410. $screenIndex++;
  411. }
  412. $functionAcces = 0;
  413. if(isset($profilePermissions['permissions'][$moduleIndex]['children'][$functionIndex]['access'])){
  414. $functionAcces = $profilePermissions['permissions'][$moduleIndex]['children'][$functionIndex]['access'];
  415. }
  416. $permissionsPerFunction[] = [
  417. 'id' => $this->encryptionController->encrypt($function->FUNC_IDFU),
  418. 'name' => $function->FUNC_NOMB,
  419. 'access' => $functionAcces,
  420. 'children' => $permissionsPerScreen,
  421. ];
  422. $functionIndex++;
  423. }
  424. $permissionsArr = [];
  425. foreach($permissionsPerSubmodule as $perm){ $permissionsArr[] = $perm; }
  426. foreach($permissionsPerFunction as $perm){ $permissionsArr[] = $perm; }
  427. $moduleAccess = $profilePermissions['permissions'][$moduleIndex]['access'];
  428. $permissions[] = [
  429. 'id' => $this->encryptionController->encrypt($module->MODU_IDMO),
  430. 'name' => $module->MODU_NOMO,
  431. 'access' => $moduleAccess,
  432. 'children' => $permissionsArr,
  433. 'enabled' => $module->MODU_ESTA == 'E'
  434. ];
  435. $moduleIndex++;
  436. }
  437. $now = $this->functionsController->now();
  438. $nowStr = $now->toDateTimeString();
  439. $profile->PERMISOS = ['permissions' => $permissions];
  440. $actions = DB::getQueryLog();
  441. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  442. $idac = $this->functionsController->registerActivity(
  443. $line,
  444. $this->moduleCode,
  445. 'S002V01F01ADPE',
  446. 'S002V01P01COPE',
  447. 'Consulta',
  448. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el perfil " . $profile->NOMBREPERFIL . " (" . $profile->IDPERFIL . ").",
  449. $idUser,
  450. $nowStr,
  451. 'S002V01S02GEPE'
  452. );
  453. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  454. return $this->responseController->makeresponse(false, "EXITO", $profile);
  455. }
  456. public function updateUser(Request $request){
  457. DB::enableQueryLog();
  458. $validator = Validator::make($request->all(), [
  459. 'id' => 'required|string',
  460. 'name' => 'required|string|max:50',
  461. 'fApe' => 'required|string|max:50',
  462. 'email' => 'required|string|email',
  463. 'perf' => 'required|string',
  464. 'id_user' => 'required|string',
  465. 'linea' => 'required|integer'
  466. ]);
  467. if($validator->fails()){
  468. return $this->responseController->makeResponse(
  469. true,
  470. "Se encontraron uno o más errores.",
  471. $this->responseController->makeErrors(
  472. $validator->errors()->messages()
  473. ),
  474. 401
  475. );
  476. }
  477. $user = $request->all();
  478. $idUser = $this->encryptionController->decrypt($user['id']);
  479. if(!$idUser){
  480. return $this->responseController->makeResponse(true, "El ID del usuario que desea modificar no está encriptado correctamente.", [], 400);
  481. }
  482. $usrMod = DB::table('S002V01TUSUA')->where([
  483. ['USUA_IDUS', '=', $idUser],
  484. ['USUA_NULI', '=', $user['linea']],
  485. ])->first();
  486. if(is_null($usrMod)){
  487. return $this->responseController->makeResponse(true, 'El usuario que desea modificar no exise.', [], 404);
  488. }
  489. $idUserMod = $this->encryptionController->decrypt($user['id_user']);
  490. if(!$idUserMod){
  491. return $this->responseController->makeResponse(true, "El ID del usuario que modifica no está encriptado correctamente.", [], 400);
  492. }
  493. $usr = DB::table('S002V01TUSUA')->where([
  494. ['USUA_IDUS', '=', $idUserMod],
  495. ['USUA_NULI', '=', $user['linea']],
  496. ])->first();
  497. if(is_null($usr)){
  498. return $this->responseController->makeResponse(true, 'El usuario que realiza la solicitud no existe', [], 404);
  499. }
  500. if($idUser == $idUserMod){
  501. return $this->responseController->makeResponse(true, "El usuario no puede modificar su propio registro.", [], 401);
  502. }
  503. $idProfile = $this->encryptionController->decrypt($user['perf']);
  504. if(!$idProfile){
  505. return $this->responseController->makeResponse(true, "El ID del perfil seleccionado no está encriptado correctamente.", [], 400);
  506. }
  507. $profile = DB::table('S002V01TPERF')->where([
  508. ['PERF_IDPE', '=', $idProfile],
  509. ['PERF_NULI', '=', $user['linea']]
  510. ])->first();
  511. if(is_null($profile)){
  512. return $this->responseController->makeResponse(true, 'El perfil seleccionado no existe.', [], 404);
  513. }else if($profile->PERF_ESTA == 'Eliminado'){
  514. return $this->responseController->makeResponse(true, 'El perfil seleccionado está eliminado.', [], 404);
  515. }
  516. $now = $this->functionsController->now();
  517. $nowStr = $now->toDateTimeString();
  518. $correos = DB::table('S002V01TUSUA')->where([
  519. ['USUA_COEL', '=', $user['email']],
  520. ['USUA_IDUS', '!=', $idUser]
  521. ])->get()->all();
  522. if(count($correos) > 0){
  523. return $this->responseController->makeResponse(true, "El nuevo correo electrónico ya está registrado en la base.", [], 401);
  524. }
  525. DB::table('S002V01TUSUA')->where([
  526. ['USUA_IDUS', '=', $idUser],
  527. ['USUA_NULI', '=', $user['linea']]
  528. ])->update([
  529. 'USUA_NOMB' => $user['name'],
  530. 'USUA_APPA' => $user['fApe'],
  531. 'USUA_APMA' => array_key_exists('sApe', $user) ? $user['sApe'] : null,
  532. 'USUA_COEL' => $user['email'],
  533. 'USUA_PERF' => $idProfile,
  534. 'USUA_USMO' => $idUserMod,
  535. 'USUA_FEMO' => $nowStr
  536. ]);
  537. $actions = DB::getQueryLog();
  538. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  539. $nameMod = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
  540. $idac = $this->functionsController->registerActivity(
  541. $user['linea'],
  542. $this->moduleCode,
  543. 'S002V01F01ADUS',
  544. 'S002V01P02RAUS',
  545. 'Actualización',
  546. "El usuario $name (" . $usr->USUA_IDUS . ") actualizó al usuario $nameMod (" . $usrMod->USUA_IDUS . ").",
  547. $idUser,
  548. $nowStr,
  549. 'S002V01S01GEUS'
  550. );
  551. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $user['linea']);
  552. return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
  553. }
  554. public function createUser(Request $request){
  555. DB::enableQueryLog();
  556. $validator = Validator::make($request->all(), [
  557. 'id_user' => 'required|string',
  558. 'linea' => 'required|integer',
  559. 'name' => 'required|string|max:50',
  560. 'fApe' => 'required|string|max:50',
  561. 'perf' => 'required|string',
  562. 'email' => 'required|string|email',
  563. 'password' => 'required|string|min:8|confirmed',
  564. ]);
  565. if($validator->fails()){
  566. return $this->responseController->makeResponse(
  567. true,
  568. "Se encontraron uno o más errores.",
  569. $this->responseController->makeErrors(
  570. $validator->errors()->messages()
  571. ),
  572. 401
  573. );
  574. }
  575. $user = $request->all();
  576. $idUsre = $this->encryptionController->decrypt($user['id_user']);
  577. if(!$idUsre){
  578. return $this->responseController->makeResponse(true, "El ID del usuario que registra no está encriptado correctamente.", [], 400);
  579. }
  580. $usr = DB::table('S002V01TUSUA')->where([
  581. ['USUA_IDUS', '=', $idUsre],
  582. ['USUA_NULI', '=', $user['linea']]
  583. ])->first();
  584. if(is_null($usr)){
  585. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  586. }else if($usr->USUA_ESTA == 'Eliminado'){
  587. return $this->responseController->makeResponse(true, "El usuario que realiza el registro está eliminado.", [], 401);
  588. }else if($usr->USUA_ESTA == 'Inactivo'){
  589. return $this->responseController->makeResponse(true, "El usuario que realiza el registro está boloqueado.", [], 401);
  590. }
  591. $idProfile = $this->encryptionController->decrypt($user['perf']);
  592. if(!$idProfile){
  593. return $this->responseController->makeResponse(true, "El ID del perfil seleccionado no está encriptado correctamente.", [], 400);
  594. }
  595. $profile = DB::table('S002V01TPERF')->where([
  596. ['PERF_IDPE', '=', $idProfile],
  597. ['PERF_NULI', '=', $user['linea']]
  598. ])->first();
  599. if(is_null($profile)){
  600. return $this->responseController->makeResponse(true, 'El perfil seleccionado no existe.', [], 404);
  601. }else if($usr->USUA_ESTA == 'Eliminado'){
  602. return $this->responseController->makeResponse(true, "El perfil seleccionado está eliminado.", [], 401);
  603. }
  604. $email = DB::table('S002V01TUSUA')->where([
  605. ['USUA_COEL', '=', $user['email']],
  606. ['USUA_NULI', '=', $user['linea']]
  607. ])->get()->first();
  608. if(!is_null($email)){
  609. return $this->responseController->makeResponse(true, "El correo electrónico ya se encuentra registrado.", [], 401);
  610. }
  611. $passEnc = Hash::make($user['password']);
  612. $apemat = isset($user['sApe']) ? $user['sApe'] : null;
  613. $now = $this->functionsController->now();
  614. $nowStr = $now->toDateTimeString();
  615. $idUser = DB::table('S002V01TUSUA')->insertGetId([
  616. 'USUA_NULI' => $user['linea'],
  617. 'USUA_NOMB' => $user['name'],
  618. 'USUA_APPA' => $user['fApe'],
  619. 'USUA_APMA' => $apemat,
  620. 'USUA_PERF' => $idProfile,
  621. 'USUA_PCRE' => 0,
  622. 'USUA_CONT' => $passEnc,
  623. 'USUA_COEL' => $user['email'],
  624. 'USUA_USRE' => $idUsre,
  625. 'USUA_FERE' => $nowStr,
  626. ]);
  627. $actions = DB::getQueryLog();
  628. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  629. $nameReg = $this->functionsController->joinName($user['name'], $user['fApe'], $apemat);
  630. $idac = $this->functionsController->registerActivity(
  631. $user['linea'],
  632. $this->moduleCode,
  633. 'S002V01F01ADUS',
  634. 'S002V01P02RAUS',
  635. 'Registro',
  636. "El usuario $name (" . $usr->USUA_IDUS . ") registró al usuario $nameReg ($idUser).",
  637. $idUsre,
  638. $nowStr,
  639. 'S002V01S01GEUS'
  640. );
  641. $this->functionsController->registerLog($actions, $idUsre, $nowStr, $idac, $user['linea']);
  642. return $this->responseController->makeResponse(false, "EXITO: Registro correcto.");
  643. }
  644. public function blockUser(Request $request){
  645. DB::enableQueryLog();
  646. $validator = Validator::make($request->all(), [
  647. 'id' => 'required|string',
  648. 'estatus' => 'required|in:Activo,Inactivo',
  649. 'id_user' => 'required|string',
  650. 'linea' => 'required|integer'
  651. ]);
  652. if($validator->fails()){
  653. return $this->responseController->makeResponse(
  654. true,
  655. "Se encontraron uno o más errores.",
  656. $this->responseController->makeErrors(
  657. $validator->errors()->messages()
  658. ),
  659. 401
  660. );
  661. }
  662. $user = $request->all();
  663. $idUser = $this->encryptionController->decrypt($user['id']);
  664. if(!$idUser){
  665. return $this->responseController->makeResponse(true, "El id del usuario que desea modificar no está encriptado correctamente.", [], 400);
  666. }
  667. $usr = DB::table('S002V01TUSUA')->where([
  668. ['USUA_IDUS', '=', $idUser],
  669. ['USUA_NULI', '=', $user['linea']],
  670. ])->first();
  671. if(is_null($usr)){
  672. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 400);
  673. }
  674. $idUserMod = $this->encryptionController->decrypt($user['id_user']);
  675. if(!$idUserMod){
  676. return $this->responseController->makeResponse(true, "El id del usuario que modifica no está encriptado correctamente.", [], 400);
  677. }
  678. if($idUser == $idUserMod){
  679. return $this->responseController->makeResponse(true, "El usuario no puede modificarse a sí mismo", [], 400);
  680. }
  681. $usrMod = DB::table('S002V01TUSUA')->where([
  682. ['USUA_IDUS', '=', $idUserMod],
  683. ['USUA_NULI', '=', $user['linea']],
  684. ])->first();
  685. if(is_null($usrMod)){
  686. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 400);
  687. }
  688. $now = $this->functionsController->now();
  689. $nowStr = $now->toDateTimeString();
  690. DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $idUserMod)->update([
  691. 'USUA_ESTA' => $user['estatus'],
  692. 'USUA_USMO' => $idUser,
  693. 'USUA_FEMO' => $nowStr
  694. ]);
  695. $actions = DB::getQueryLog();
  696. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  697. $nameMod = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
  698. $tipoAccion = $user['estatus'] == 'Activo' ? 'desbloqueó' : 'bloqueó';
  699. $idac = $this->functionsController->registerActivity(
  700. $user['linea'],
  701. $this->moduleCode,
  702. 'S002V01F02BDAC',
  703. '-',
  704. 'Actualización',
  705. "El usuario $name (" . $usr->USUA_IDUS . ") $tipoAccion al usuario $nameMod (" . $usrMod->USUA_IDUS . ").",
  706. $idUser,
  707. $nowStr,
  708. 'S002V01S01GEUS'
  709. );
  710. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $user['linea']);
  711. return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
  712. }
  713. public function updatePass(Request $request){
  714. DB::enableQueryLog();
  715. $validator = Validator::make($request->all(), [
  716. 'id' => 'required|string',
  717. 'password' => 'required|string|min:8|confirmed',
  718. 'id_user' => 'required|string',
  719. 'linea' => 'required|integer'
  720. ]);
  721. if($validator->fails()){
  722. return $this->responseController->makeResponse(
  723. true,
  724. "Se encontraron uno o más errores.",
  725. $this->responseController->makeErrors(
  726. $validator->errors()->messages()
  727. ),
  728. 401
  729. );
  730. }
  731. $user = $request->all();
  732. $idUser = $this->encryptionController->decrypt($user['id']);
  733. if(!$idUser){
  734. return $this->responseController->makeResponse(true, "El id del usuario que desea modificar no está encriptado correctamente.", [], 400);
  735. }
  736. $usrMod = DB::table('S002V01TUSUA')->where([
  737. ['USUA_IDUS', '=', $idUser],
  738. ['USUA_NULI', '=', $user['linea']],
  739. ])->first();
  740. if(is_null($usrMod)){
  741. return $this->responseController->makeResponse(true, 'El usuario que desea modificar no existe', [], 400);
  742. }
  743. $idUserMod = $this->encryptionController->decrypt($user['id_user']);
  744. if(!$idUserMod){
  745. return $this->responseController->makeResponse(true, "El id del usuario que modifica no está encriptado correctamente.", [], 400);
  746. }
  747. if($idUser == $idUserMod){
  748. return $this->responseController->makeResponse(true, "El usuario no puede modificarse a sí mismo.", [], 401);
  749. }
  750. $usr = DB::table('S002V01TUSUA')->where([
  751. ['USUA_IDUS', '=', $idUserMod],
  752. ['USUA_NULI', '=', $user['linea']],
  753. ])->first();
  754. if(is_null($usr)){
  755. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 400);
  756. }
  757. $lastPass = $usr->USUA_CONT;
  758. if(Hash::check($user['password'], $lastPass)){
  759. return $this->responseController->makeResponse(true, "La contraseña nueva es igual a la anterior.", [], 401);
  760. }
  761. $newPass = Hash::make($user['password']);
  762. $now = $this->functionsController->now();
  763. $nowStr = $now->toDateTimeString();
  764. DB::table('S002V01TUSUA')->where([
  765. ['USUA_IDUS', '=', $idUser],
  766. ['USUA_NULI', '=', $user['linea']],
  767. ])->update([
  768. 'USUA_CONT' => $newPass,
  769. 'USUA_USMO' => $idUserMod,
  770. 'USUA_FEMO' => $nowStr
  771. ]);
  772. $actions = DB::getQueryLog();
  773. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  774. $idac = $this->functionsController->registerActivity(
  775. $user['linea'],
  776. $this->moduleCode,
  777. 'S002V01F01ADUS',
  778. 'S002V01P01COUS',
  779. 'Consulta',
  780. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los usuarios registrados.",
  781. $idUser,
  782. $nowStr,
  783. 'S002V01S01GEUS'
  784. );
  785. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $user['linea']);
  786. return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
  787. }
  788. public function deleteUser(Request $request){
  789. DB::enableQueryLog();
  790. $validator = Validator::make($request->all(), [
  791. 'id' => 'required|string',
  792. 'id_user' => 'required|string',
  793. 'linea' => 'required|integer'
  794. ]);
  795. if($validator->fails()){
  796. return $this->responseController->makeResponse(
  797. true,
  798. "Se encontraron uno o más errores.",
  799. $this->responseController->makeErrors(
  800. $validator->errors()->messages()
  801. ),
  802. 401
  803. );
  804. }
  805. $user = $request->all();
  806. $idUser = $this->encryptionController->decrypt($user['id']);
  807. if(!$idUser){
  808. return $this->responseController->makeResponse(true, "El id del usuario que desea eliminar no está encriptado correctamente", [], 400);
  809. }
  810. $usr = DB::table('S002V01TUSUA')->where([
  811. ['USUA_IDUS', '=', $idUser],
  812. ['USUA_NULI', '=', $user['linea']]
  813. ])->first();
  814. if(is_null($usr)){
  815. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  816. }
  817. $idUserMod = $this->encryptionController->decrypt($user['id_user']);
  818. if(!$idUserMod){
  819. return $this->responseController->makeResponse(true, "El id del usuario que elimina no está encriptado correctamente", [], 400);
  820. }
  821. if($idUser == $idUserMod){
  822. return $this->responseController->makeResponse(true, "El usuario no puede eliminarse a sí mismo", [], 401);
  823. }
  824. $usrMod = DB::table('S002V01TUSUA')->where([
  825. ['USUA_IDUS', '=', $idUserMod],
  826. ['USUA_NULI', '=', $user['linea']]
  827. ])->first();
  828. if(is_null($usrMod)){
  829. return $this->responseController->makeResponse(true, 'El usuario que desea eliminar no está registrado', [], 404);
  830. }
  831. $now = $this->functionsController->now();
  832. $nowStr = $now->toDateTimeString();
  833. DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $idUser)->update([
  834. 'USUA_ESTA' => 'Eliminado',
  835. 'USUA_USMO' => $idUserMod,
  836. 'USUA_FEMO' => $nowStr
  837. ]);
  838. $actions = DB::getQueryLog();
  839. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  840. $nameMod = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
  841. $idac = $this->functionsController->registerActivity(
  842. $user['linea'],
  843. $this->moduleCode,
  844. 'S002V01F01ADUS',
  845. 'S002V01P02RAUS',
  846. 'Eliminación',
  847. "El usuario $name (" . $usr->USUA_IDUS . ") eliminó al usuario $nameMod (" . $usrMod->USUA_IDUS . ").",
  848. $idUser,
  849. $nowStr,
  850. 'S002V01S01GEUS'
  851. );
  852. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $user['linea']);
  853. return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
  854. }
  855. public function getModules($idUser, $line){
  856. DB::enableQueryLog();
  857. $idUser = $this->encryptionController->decrypt($idUser);
  858. if(!$idUser){
  859. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  860. }
  861. $usr = DB::table('S002V01TUSUA')->where([
  862. ['USUA_IDUS', '=', $idUser],
  863. ['USUA_NULI', '=', $line]
  864. ])->first();
  865. if(is_null($usr)){
  866. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  867. }
  868. $modules = DB::table('S002V01TMODU')->select(
  869. 'MODU_IDMO as ID_MODULO',
  870. 'MODU_NOMO as NOMBRE_MODULO',
  871. 'MODU_ICON as ICONO_MODULO',
  872. 'MODU_ESTA AS ESTADO_MODULO'
  873. )->where('MODU_NULI', '=', $line)->get()->all();
  874. foreach($modules as $key=>$module){
  875. $module->ID_MODULO = $this->encryptionController->encrypt($module->ID_MODULO);
  876. $module->ESTADO_MODULO = $module->ESTADO_MODULO == 'E';
  877. $modules[$key] = $module;
  878. }
  879. $now = $this->functionsController->now();
  880. $nowStr = $now->toDateTimeString();
  881. $actions = DB::getQueryLog();
  882. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  883. $idac = $this->functionsController->registerActivity(
  884. $line,
  885. '-',
  886. '-',
  887. '-',
  888. 'Consulta',
  889. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los módulos del sistema.",
  890. $idUser,
  891. $nowStr
  892. );
  893. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  894. return $this->responseController->makeresponse(false, "EXITO", $modules);
  895. }
  896. public function getMenu($idUser, $line){
  897. DB::enableQueryLog();
  898. $idUser = $this->encryptionController->decrypt($idUser);
  899. if(!$idUser){
  900. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  901. }
  902. $usr = DB::table('S002V01TUSUA')->where([
  903. ['USUA_IDUS', '=', $idUser],
  904. ['USUA_NULI', '=', $line]
  905. ])->first();
  906. if(is_null($usr)){
  907. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  908. }
  909. $modules = DB::table('S002V01TMODU')->select(
  910. 'MODU_IDMO AS ID_MODULO',
  911. 'MODU_NOMO AS NOMBRE_MODULO',
  912. 'MODU_ICON AS ICONO_MODULO',
  913. 'MODU_ICPE AS ICONO_PERSONALIZADO',
  914. 'MODU_AIPE AS ARCHIVO_ICONO_PERSONALIZADO',
  915. 'MODU_ESTA AS ESTADO'
  916. )->get()->all();
  917. $mods = [];
  918. foreach($modules as $module){
  919. $submodules = DB::table('S002V01TSUBM')->select(
  920. 'SUBM_IDSM as IDSUBMODULO',
  921. 'SUBM_NOMB as NOMBRESUBMODULO',
  922. 'SUBM_ICON AS ICONOSUBMODULO',
  923. 'SUBM_ICPE AS ICONO_PERSONALIZADO',
  924. 'SUBM_AIPE AS ARCHIVO_ICONO_PERSONALIZADO',
  925. )->where('SUBM_IDMO', '=', $module->ID_MODULO)->get()->all();
  926. $menusMod = DB::table('S002V01TFUNC')->select(
  927. 'FUNC_IDFU AS IDFUNCION',
  928. 'FUNC_NOMB AS NOMBREFUNCION',
  929. 'FUNC_ICON AS ICONOFUNCION',
  930. 'FUNC_ICPE AS ICONO_PERSONALIZADO',
  931. 'FUNC_AIPE AS ARCHIVO_ICONO_PERSONALIZADO',
  932. )->where([
  933. ['FUNC_IDMO', '=', $module->ID_MODULO],
  934. ['FUNC_IDSM', '=', null]
  935. ])->get()->all();
  936. $module->SUBMODULES = [];
  937. foreach($submodules as $submodule){
  938. $menus = DB::table('S002V01TFUNC')->select(
  939. 'FUNC_IDFU AS IDFUNCION',
  940. 'FUNC_NOMB AS NOMBREFUNCION',
  941. 'FUNC_ICON AS ICONOFUNCION',
  942. 'FUNC_ICPE AS ICONO_PERSONALIZADO',
  943. 'FUNC_AIPE AS ARCHIVO_ICONO_PERSONALIZADO',
  944. )->where([
  945. ['FUNC_IDMO', '=', $module->ID_MODULO],
  946. ['FUNC_IDSM', '=', $submodule->IDSUBMODULO]
  947. ])->get()->all();
  948. foreach($menus as $funcion){
  949. $pantallas = DB::table('S002V01TPANT')->select(
  950. 'PANT_IDPA AS IDPANTALLA',
  951. 'PANT_NOMB AS NOMBREPANTALLA'
  952. )->where([
  953. ['PANT_IDFU', '=', $funcion->IDFUNCION],
  954. ['PANT_NULI', '=', $line]
  955. ])->get()->all();
  956. foreach($pantallas as $key0=>$pantalla){
  957. $pantalla->IDPANTALLA = $this->encryptionController->encrypt($pantalla->IDPANTALLA);
  958. $pantallas[$key0] = $pantalla;
  959. }
  960. $funcion->IDFUNCION = $this->encryptionController->encrypt($funcion->IDFUNCION);
  961. $funcion->PANTALLAS = $pantallas;
  962. }
  963. $submodule->FUNCIONES = [];
  964. foreach($menus as $menu){
  965. $submodule->FUNCIONES[] = $menu;
  966. }
  967. $submodule->IDSUBMODULO = $this->encryptionController->encrypt($submodule->IDSUBMODULO);
  968. if(!is_null($submodule->ARCHIVO_ICONO_PERSONALIZADO)){
  969. $submodule->ARCHIVO_ICONO_PERSONALIZADO = $this->encryptionController->encrypt($submodule->ARCHIVO_ICONO_PERSONALIZADO);
  970. }
  971. $module->SUBMODULES[] = $submodule;
  972. }
  973. foreach($menusMod as $funcion){
  974. $pantallas = DB::table('S002V01TPANT')->select(
  975. 'PANT_IDPA AS IDPANTALLA',
  976. 'PANT_NOMB AS NOMBREPANTALLA'
  977. )->where([
  978. ['PANT_IDFU', '=', $funcion->IDFUNCION],
  979. ['PANT_NULI', '=', $line]
  980. ])->get()->all();
  981. foreach($pantallas as $key0=>$pantalla){
  982. $pantalla->IDPANTALLA = $this->encryptionController->encrypt($pantalla->IDPANTALLA);
  983. $pantallas[$key0] = $pantalla;
  984. }
  985. $funcion->IDFUNCION = $this->encryptionController->encrypt($funcion->IDFUNCION);
  986. $funcion->PANTALLAS = $pantallas;
  987. }
  988. $module->MENUS = $menusMod;
  989. $module->ID_MODULO = $this->encryptionController->encrypt($module->ID_MODULO);
  990. if(!is_null($module->ICONO_PERSONALIZADO)){
  991. $module->ICONO_PERSONALIZADO = $this->encryptionController->encrypt($module->ICONO_PERSONALIZADO);
  992. }
  993. if(!is_null($module->ARCHIVO_ICONO_PERSONALIZADO)){
  994. $module->ARCHIVO_ICONO_PERSONALIZADO = $this->encryptionController->encrypt($module->ARCHIVO_ICONO_PERSONALIZADO);
  995. }
  996. $mods[] = $module;
  997. }
  998. $now = $this->functionsController->now();
  999. $nowStr = $now->toDateTimeString();
  1000. $actions = DB::getQueryLog();
  1001. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1002. $idac = $this->functionsController->registerActivity(
  1003. $line,
  1004. '-',
  1005. '-',
  1006. '-',
  1007. 'Consulta',
  1008. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el menú del sistema.",
  1009. $idUser,
  1010. $nowStr
  1011. );
  1012. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  1013. return $this->responseController->makeResponse(false, "EXITO", $mods);
  1014. }
  1015. public function buildInitialPermissions($idUser, $line){
  1016. DB::enableQueryLog();
  1017. $idUser = $this->encryptionController->decrypt($idUser);
  1018. if(!$idUser){
  1019. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  1020. }
  1021. $usr = DB::table('S002V01TUSUA')->where([
  1022. ['USUA_IDUS', '=', $idUser],
  1023. ['USUA_NULI', '=', $line],
  1024. ])->first();
  1025. if(is_null($usr)){
  1026. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 400);
  1027. }
  1028. $permissions = [];
  1029. //Se obtienen todos los modulos
  1030. $modules = DB::table('S002V01TMODU')->where('MODU_NULI', '=', $line)->get()->all();
  1031. //se consultan los submodulos de cada modulo
  1032. foreach($modules as $module){
  1033. $submodules = DB::table('S002V01TSUBM')->where([
  1034. ['SUBM_IDMO', '=', $module->MODU_IDMO],
  1035. ['SUBM_NULI', '=', $line]
  1036. ])->get()->all();
  1037. $permissionsPerSubmodule = [];
  1038. $hasSubmodules = false;
  1039. foreach($submodules as $submodule){
  1040. //Se consultan las funciones
  1041. $functions = DB::table('S002V01TFUNC')->where([
  1042. ['FUNC_IDMO', '=', $module->MODU_IDMO],
  1043. ['FUNC_IDSM', '=', $submodule->SUBM_IDSM],
  1044. ['FUNC_NULI', '=', $line],
  1045. ])->get()->all();
  1046. $permissionsPerFunction = [];
  1047. foreach($functions as $function){
  1048. $screens = DB::table('S002V01TPANT')->where([
  1049. ['PANT_IDFU', '=', $function->FUNC_IDFU],
  1050. ['PANT_NULI', '=', $line],
  1051. ])->get()->all();
  1052. $permissionsPerScreen = [];
  1053. foreach($screens as $screen){
  1054. $permissionsPerScreen[] = [
  1055. 'id' => $screen->PANT_IDPA,
  1056. 'name' => $screen->PANT_NOMB,
  1057. 'access' => 0
  1058. ];
  1059. }
  1060. $permissionsPerFunction[] = [
  1061. 'id' => $function->FUNC_IDFU,
  1062. 'name' => $function->FUNC_NOMB,
  1063. 'access' => 0,
  1064. 'children' => $permissionsPerScreen,
  1065. ];
  1066. }
  1067. $permissionsPerSubmodule[] = [
  1068. 'id' => $submodule->SUBM_IDSM,
  1069. 'name' => $submodule->SUBM_NOMB,
  1070. 'access' => 0,
  1071. 'children' => $permissionsPerFunction,
  1072. ];
  1073. $hasSubmodules = true;
  1074. }
  1075. //Se consultan las funciones
  1076. $functions = DB::table('S002V01TFUNC')->where([
  1077. ['FUNC_IDMO', '=', $module->MODU_IDMO],
  1078. ['FUNC_IDSM', '=', null],
  1079. ['FUNC_NULI', '=', $line],
  1080. ])->get()->all();
  1081. $permissionsPerFunction = [];
  1082. foreach($functions as $function){
  1083. $screens = DB::table('S002V01TPANT')->where([
  1084. ['PANT_IDFU', '=', $function->FUNC_IDFU],
  1085. ['PANT_NULI', '=', $line],
  1086. ])->get()->all();
  1087. $permissionsPerScreen = [];
  1088. foreach($screens as $screen){
  1089. $permissionsPerScreen[] = [
  1090. 'id' => $screen->PANT_IDPA,
  1091. 'name' => $screen->PANT_NOMB,
  1092. 'access' => 0
  1093. ];
  1094. }
  1095. $permissionsPerFunction[] = [
  1096. 'id' => $function->FUNC_IDFU,
  1097. 'name' => $function->FUNC_NOMB,
  1098. 'access' => 0,
  1099. 'children' => $permissionsPerScreen,
  1100. ];
  1101. }
  1102. $permissionsArr = [];
  1103. foreach($permissionsPerSubmodule as $perm){ $permissionsArr[] = $perm; }
  1104. foreach($permissionsPerFunction as $perm){ $permissionsArr[] = $perm; }
  1105. $permissions[] = [
  1106. 'id' => $module->MODU_IDMO,
  1107. 'name' => $module->MODU_NOMO,
  1108. 'access' => 0,
  1109. 'children' => $permissionsArr,
  1110. ];
  1111. }
  1112. $now = $this->functionsController->now();
  1113. $nowStr = $now->toDateTimeString();
  1114. $actions = DB::getQueryLog();
  1115. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1116. $idac = $this->functionsController->registerActivity(
  1117. $line,
  1118. $this->moduleCode,
  1119. 'S002V01F01ADPE',
  1120. 'S002V01P02REPE',
  1121. 'Consulta',
  1122. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el arreglo de permisos iniciales.",
  1123. $idUser,
  1124. $nowStr,
  1125. 'S002V01S02GEPE'
  1126. );
  1127. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  1128. return $this->responseController->makeresponse(false, "EXITO", ['permissions' => $permissions]);
  1129. }
  1130. public function updateProfile(Request $request){
  1131. DB::enableQueryLog();
  1132. $validator = Validator::make($request->all(), [
  1133. 'id_user' => 'required|string',
  1134. 'linea' => 'required|integer',
  1135. 'id' => 'required|string',
  1136. 'name' => 'required|string|max:50',
  1137. 'permissions' => 'required|json',
  1138. ]);
  1139. if($validator->fails()){
  1140. return $this->responseController->makeResponse(
  1141. true,
  1142. "Se encontraron uno o más errores.",
  1143. $this->responseController->makeErrors(
  1144. $validator->errors()->messages()
  1145. ),
  1146. 401
  1147. );
  1148. }
  1149. $info = $request->all();
  1150. $idUser = $this->encryptionController->decrypt($info['id_user']);
  1151. if(!$idUser){
  1152. return $this->responseController->makeResponse(true, "El ID del usuario que realizó la solicitud no fue encriptado correctamente", [], 400);
  1153. }
  1154. $usr = DB::table('S002V01TUSUA')->where([
  1155. ['USUA_IDUS', '=', $idUser],
  1156. ['USUA_NULI', '=', $info['linea']],
  1157. ])->first();
  1158. if(is_null($usr)){
  1159. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 404);
  1160. }
  1161. $idPerf = $this->encryptionController->decrypt($info['id']);
  1162. if(!$idPerf){
  1163. return $this->responseController->makeResponse(true, "El ID del perfil solicitado no fue encriptado correctamente", [], 400);
  1164. }
  1165. $perf = DB::table('S002V01TPERF')->where([
  1166. ['PERF_IDPE', '=', $idPerf],
  1167. ['PERF_NULI', '=', $info['linea']],
  1168. ])->first();
  1169. if(is_null($perf)){
  1170. return $this->responseController->makeResponse(true, 'El perfil solicitado no existe', [], 400);
  1171. }
  1172. $now = $this->functionsController->now();
  1173. $nowStr = $now->toDateTimeString();
  1174. DB::table('S002V01TPERF')->where([
  1175. ['PERF_IDPE', '=', $idPerf],
  1176. ['PERF_NULI', '=', $info['linea']],
  1177. ])->update([
  1178. 'PERF_PERM' => $info['permissions'],
  1179. 'PERF_NOPE' => $info['name'],
  1180. 'PERF_USMO' => $idUser,
  1181. 'PERF_FEMO' => $nowStr
  1182. ]);
  1183. $actions = DB::getQueryLog();
  1184. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1185. $idac = $this->functionsController->registerActivity(
  1186. $info['linea'],
  1187. $this->moduleCode,
  1188. 'S002V01F01ADPE',
  1189. 'S002V01P02REPE',
  1190. 'Actualización',
  1191. "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el perfil " . $perf->PERF_NOPE . "(" . $perf->PERF_NOPE . ").",
  1192. $idUser,
  1193. $nowStr,
  1194. 'S002V01S02GEPE'
  1195. );
  1196. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $info['linea']);
  1197. return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
  1198. }
  1199. public function deleteProfile(Request $request){
  1200. DB::enableQueryLog();
  1201. $validator = Validator::make($request->all(), [
  1202. 'id' => 'required|string',
  1203. 'id_user' => 'required|string',
  1204. 'linea' => 'required|integer'
  1205. ]);
  1206. if($validator->fails()){
  1207. return $this->responseController->makeResponse(
  1208. true,
  1209. "Se encontraron uno o más errores.",
  1210. $this->responseController->makeErrors(
  1211. $validator->errors()->messages()
  1212. ),
  1213. 401
  1214. );
  1215. }
  1216. $profile = $request->all();
  1217. $idUser = $this->encryptionController->decrypt($profile['id_user']);
  1218. if(!$idUser){
  1219. return $this->responseController->makeResponse(true, "El ID del usuario que solicitó la acción no está encriptado correctamente", [], 401);
  1220. }
  1221. $usr = DB::table('S002V01TUSUA')->where([
  1222. ['USUA_IDUS', '=', $idUser],
  1223. ['USUA_NULI', '=', $profile['linea']],
  1224. ])->first();
  1225. if(is_null($usr)){
  1226. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 404);
  1227. }
  1228. $idProf = $this->encryptionController->decrypt($profile['id']);
  1229. if(!$idProf){
  1230. return $this->responseController->makeResponse(true, "El ID del perfil seleccionado no está encriptado correctamente", [], 401);
  1231. }
  1232. $perf = DB::table('S002V01TPERF')->where([
  1233. ['PERF_IDPE', '=', $idProf],
  1234. ['PERF_NULI', '=', $profile['linea']],
  1235. ])->first();
  1236. if(is_null($perf)){
  1237. return $this->responseController->makeResponse(true, 'El perfil solicitado no existe', [], 404);
  1238. }
  1239. $users = DB::table('S002V01TUSUA')->where([
  1240. ['USUA_PERF', '=', $idProf],
  1241. ['USUA_NULI', '=', $profile['linea']]
  1242. ])->get()->all();
  1243. if(count($users) > 0){
  1244. return $this->responseController->makeResponse(true, "El perfil seleccionado no se puede eliminar porque hay usuarios asociados a él.", [], 401);
  1245. }
  1246. $now = $this->functionsController->now();
  1247. $nowStr = $now->toDateTimeString();
  1248. DB::table('S002V01TPERF')->where([
  1249. ['PERF_IDPE', '=', $idProf],
  1250. ['PERF_NULI', '=', $profile['linea']],
  1251. ])->update([
  1252. 'PERF_ESTA' => 'Eliminado',
  1253. 'PERF_USMO' => $idUser,
  1254. 'PERF_FEMO' => $nowStr
  1255. ]);
  1256. $actions = DB::getQueryLog();
  1257. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1258. $idac = $this->functionsController->registerActivity(
  1259. $profile['linea'],
  1260. $this->moduleCode,
  1261. 'S002V01F01ADPE',
  1262. '-',
  1263. 'Eliminación',
  1264. "El usuario $name (" . $usr->USUA_IDUS . ") eliminó el perfil " . $perf->PERF_NOPE . "($idProf).",
  1265. $idUser,
  1266. $nowStr,
  1267. 'S002V01S02GEPE'
  1268. );
  1269. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $profile['linea']);
  1270. return $this->responseController->makeResponse(false, "EXITO: Eliminación correcta.");
  1271. }
  1272. public function createProfile(Request $request){
  1273. DB::enableQueryLog();
  1274. $validator = Validator::make($request->all(), [
  1275. 'id_user' => 'required|string',
  1276. 'linea' => 'required|integer',
  1277. 'name' => 'required|string|min:8|max:50',
  1278. 'permissions' => 'required|json'
  1279. ]);
  1280. if($validator->fails()){
  1281. return $this->responseController->makeResponse(
  1282. true,
  1283. "Se encontraron uno o más errores.",
  1284. $this->responseController->makeErrors(
  1285. $validator->errors()->messages()
  1286. ),
  1287. 401
  1288. );
  1289. }
  1290. $profile = $request->all();
  1291. $idUser = $this->encryptionController->decrypt($profile['id_user']);
  1292. if(!$idUser){
  1293. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente.', [], 400);
  1294. }
  1295. $usr = DB::table('S002V01TUSUA')->where([
  1296. ['USUA_IDUS', '=', $idUser],
  1297. ['USUA_NULI', '=', $profile['linea']]
  1298. ])->first();
  1299. if(is_null($usr)){
  1300. return $this->responseController->makeResponse(true, 'El usuario que realizó la solicitud no está registrado', [], 404);
  1301. }else if($usr->USUA_ESTA == 'Eliminado'){
  1302. return $this->responseController->makeResponse(true, "El usuario que realiza el registro está eliminado.", [], 401);
  1303. }else if($usr->USUA_ESTA == 'Inactivo'){
  1304. return $this->responseController->makeResponse(true, "El usuario que realiza el registro está boloqueado.", [], 401);
  1305. }
  1306. $now = $this->functionsController->now();
  1307. $nowStr = $now ->toDateTimeString();
  1308. $newPerf = DB::table('S002V01TPERF')->insertGetId([
  1309. 'PERF_NULI' => $profile['linea'],
  1310. 'PERF_NOPE' => $profile['name'],
  1311. 'PERF_PERM' => $profile['permissions'],
  1312. 'PERF_USRE' => $idUser,
  1313. 'PERF_FERE' => $nowStr
  1314. ]);
  1315. $actions = DB::getQueryLog();
  1316. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1317. $idac = $this->functionsController->registerActivity(
  1318. $profile['linea'],
  1319. $this->moduleCode,
  1320. 'S002V01F01ADPE',
  1321. 'S002V01P02REPE',
  1322. 'Registro',
  1323. "El usuario $name (" . $usr->USUA_IDUS . ") registró el perfil $profile[name] ($newPerf).",
  1324. $idUser,
  1325. $nowStr,
  1326. 'S002V01S02GEPE'
  1327. );
  1328. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $profile['linea']);
  1329. return $this->responseController->makeResponse(false, 'EXITO');
  1330. }
  1331. public function getModule($idMod, $idUser, $line){
  1332. DB::enableQueryLog();
  1333. $idUser = $this->encryptionController->decrypt($idUser);
  1334. if(!$idUser){
  1335. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  1336. }
  1337. $usr = DB::table('S002V01TUSUA')->where([
  1338. ['USUA_IDUS', '=', $idUser],
  1339. ['USUA_NULI', '=', $line]
  1340. ])->first();
  1341. if(is_null($usr)){
  1342. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  1343. }
  1344. $idMod = $this->encryptionController->decrypt($idMod);
  1345. if(!$idMod){
  1346. return $this->responseController->makeResponse(true, 'El módulo solicitado no fue encriptado correctamente', [], 400);
  1347. }
  1348. $module = DB::table('S002V01TMODU')->select(
  1349. 'MODU_IDMO as IDMODULO',
  1350. 'MODU_NOMO as NOMBREMODULO',
  1351. )->where([
  1352. ['MODU_NULI', '=', $line],
  1353. ['MODU_IDMO', '=', $idMod]
  1354. ])->first();
  1355. if(is_null($module)){
  1356. return $this->responseController->makeResponse(true, 'El módulo consultado no está registrado', [], 404);
  1357. }
  1358. $module->IDMODULO = $this->encryptionController->encrypt($module->IDMODULO);
  1359. $now = $this->functionsController->now();
  1360. $actions = DB::getQueryLog();
  1361. $nowStr = $now->toDateTimeString();
  1362. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1363. $idac = $this->functionsController->registerActivity(
  1364. $line,
  1365. '-',
  1366. '-',
  1367. '-',
  1368. 'Consulta',
  1369. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el módulo " . $idMod . " del sistema.",
  1370. $idUser,
  1371. $nowStr
  1372. );
  1373. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  1374. return $this->responseController->makeresponse(false, "EXITO", $module);
  1375. }
  1376. public function getSubmodules($idMod, $idUser, $line){
  1377. DB::enableQueryLog();
  1378. $idUser = $this->encryptionController->decrypt($idUser);
  1379. if(!$idUser){
  1380. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  1381. }
  1382. $usr = DB::table('S002V01TUSUA')->where([
  1383. ['USUA_IDUS', '=', $idUser],
  1384. ['USUA_NULI', '=', $line]
  1385. ])->first();
  1386. if(is_null($usr)){
  1387. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  1388. }
  1389. $idMod = $this->encryptionController->decrypt($idMod);
  1390. if(!$idMod){
  1391. return $this->responseController->makeResponse(true, 'El ID del módulo no fue encriptado correctamente', [], 400);
  1392. }
  1393. $mod = DB::table('S002V01TMODU')->where([
  1394. ['MODU_NULI', '=', $line],
  1395. ['MODU_IDMO', '=', $idMod]
  1396. ])->first();
  1397. if(is_null($mod)){
  1398. return $this->responseController->makeResponse(true, 'El módulo consultado no existe', [], 404);
  1399. }
  1400. $submodules = DB::table('S002V01TSUBM')->where([
  1401. ['SUBM_NULI', '=', $line],
  1402. ['SUBM_IDMO', '=', $idMod],
  1403. ])->select([
  1404. 'SUBM_IDSM AS IDSUBMODULO',
  1405. 'SUBM_NOMB AS NOMBRESUBMODULO',
  1406. 'SUBM_ICON AS ICONOSUBMODULO',
  1407. 'SUBM_IMAG AS IMAGENSUBMODULO',
  1408. ])->get()->all();
  1409. foreach($submodules as $key=>$submodule){
  1410. $submodule->IDSUBMODULO = $this->encryptionController->encrypt($submodule->IDSUBMODULO);
  1411. $submodules[$key] = $submodule;
  1412. }
  1413. $now = $this->functionsController->now();
  1414. $nowStr = $now->toDateTimeString();
  1415. $actions = DB::getQueryLog();
  1416. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1417. $idac = $this->functionsController->registerActivity(
  1418. $line,
  1419. '-',
  1420. '-',
  1421. '-',
  1422. 'Consulta',
  1423. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los submódulos del módulo '" . $mod->MODU_NOMO . "'.",
  1424. $idUser,
  1425. $nowStr
  1426. );
  1427. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  1428. return $this->responseController->makeResponse(false, 'EXITO', $submodules);
  1429. }
  1430. public function getSubmodule($idMod, $idSub, $idUser, $line){
  1431. DB::enableQueryLog();
  1432. $idUser = $this->encryptionController->decrypt($idUser);
  1433. if(!$idUser){
  1434. return $this->responseController->makeResponse(true, 'El ID del usuario que consulta no fue encriptado correctamente', [], 400);
  1435. }
  1436. $usr = DB::table('S002V01TUSUA')->where([
  1437. ['USUA_IDUS', '=', $idUser],
  1438. ['USUA_NULI', '=', $line]
  1439. ])->first();
  1440. if(is_null($usr)){
  1441. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 404);
  1442. }
  1443. $idMod = $this->encryptionController->decrypt($idMod);
  1444. if(!$idMod){
  1445. return $this->responseController->makeResponse(true, 'El módulo no fue encriptado correctamente', [], 400);
  1446. }
  1447. $module = DB::table('S002V01TMODU')->where([
  1448. ['MODU_NULI', '=', $line],
  1449. ['MODU_IDMO', '=', $idMod]
  1450. ])->first();
  1451. if(is_null($module)){
  1452. return $this->responseController->makeResponse(true, 'El módulo consultado no existe', [], 404);
  1453. }
  1454. $idSub = $this->encryptionController->decrypt($idSub);
  1455. if(!$idSub){
  1456. return $this->responseController->makeResponse(true, 'El submódulo no fue encriptado correctamente', [], 400);
  1457. }
  1458. $submodule = DB::table('S002V01TSUBM')->select(
  1459. 'SUBM_IDSM as IDSUBMODULO',
  1460. 'SUBM_NOMB as NOMBRESUBMODULO',
  1461. )->where([
  1462. ['SUBM_NULI', '=', $line],
  1463. ['SUBM_IDSM', '=', $idSub],
  1464. ['SUBM_IDMO', '=', $idMod],
  1465. ])->first();
  1466. if(is_null($submodule)){
  1467. return $this->responseController->makeResponse(true, 'El submódulo consultado no existe', [], 404);
  1468. }
  1469. $submodule->IDSUBMODULO = $this->encryptionController->encrypt($submodule->IDSUBMODULO);
  1470. $now = $this->functionsController->now();
  1471. $actions = DB::getQueryLog();
  1472. $nowStr = $now->toDateTimeString();
  1473. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1474. $idac = $this->functionsController->registerActivity(
  1475. $line,
  1476. '-',
  1477. '-',
  1478. '-',
  1479. 'Consulta',
  1480. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el submódulo " . $idSub . " del sistema.",
  1481. $idUser,
  1482. $nowStr
  1483. );
  1484. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  1485. return $this->responseController->makeresponse(false, "EXITO", $submodule);
  1486. }
  1487. public function getFunction($idMod, $idSub, $idFun, $idUser, $line){
  1488. DB::enableQueryLog();
  1489. $idMod = $this->encryptionController->decrypt($idMod);
  1490. if(!$idMod){
  1491. return $this->responseController->makeResponse(true, 'El módulo no fue encriptado correctamente', [], 400);
  1492. }
  1493. $idSub = $this->encryptionController->decrypt($idSub);
  1494. if(!$idSub){
  1495. return $this->responseController->makeResponse(true, 'El submódulo no fue encriptado correctamente', [], 400);
  1496. }
  1497. $idFun = $this->encryptionController->decrypt($idFun);
  1498. if(!$idFun){
  1499. return $this->responseController->makeResponse(true, 'La función no fue encriptada correctamente', [], 400);
  1500. }
  1501. $idUser = $this->encryptionController->decrypt($idUser);
  1502. if(!$idUser){
  1503. return $this->responseController->makeResponse(true, 'El id del usuario que consulta no fue encriptado correctamente', [], 400);
  1504. }
  1505. $usr = DB::table('S002V01TUSUA')->where([
  1506. ['USUA_IDUS', '=', $idUser],
  1507. ['USUA_NULI', '=', $line]
  1508. ])->first();
  1509. if(is_null($usr)){
  1510. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  1511. }
  1512. $function = DB::table('S002V01TFUNC')->select(
  1513. 'FUNC_IDFU as IDFUNCION',
  1514. 'FUNC_NOMB as NOMBREFUNCION',
  1515. )->where([
  1516. ['FUNC_NULI', '=', $line],
  1517. ['FUNC_IDFU', '=', $idFun],
  1518. ['FUNC_IDMO', '=', $idMod],
  1519. ['FUNC_IDSM', '=', $idSub],
  1520. ])->first();
  1521. $now = $this->functionsController->now();
  1522. $nowStr = $now->toDateTimeString();
  1523. $actions = DB::getQueryLog();
  1524. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1525. $idac = $this->functionsController->registerActivity(
  1526. $line,
  1527. '-',
  1528. '-',
  1529. '-',
  1530. 'Consulta',
  1531. "El usuario $name (" . $usr->USUA_IDUS . ") consultó la función " . $idFun . " del sistema.",
  1532. $idUser,
  1533. $nowStr
  1534. );
  1535. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  1536. return $this->responseController->makeresponse(false, "EXITO", [
  1537. 'NOMBREFUNCION' => is_null($function) ? '-' : $function->NOMBREFUNCION
  1538. ]);
  1539. }
  1540. public function getScreen($idFun, $idPan, $idUser, $line){
  1541. DB::enableQueryLog();
  1542. $idFun = $this->encryptionController->decrypt($idFun);
  1543. if(!$idFun){
  1544. return $this->responseController->makeResponse(true, 'La función no fue encriptada correctamente', [], 400);
  1545. }
  1546. $idPan = $this->encryptionController->decrypt($idPan);
  1547. if(!$idPan){
  1548. return $this->responseController->makeResponse(true, 'La pantalla no fue encriptada correctamente', [], 400);
  1549. }
  1550. $idUser = $this->encryptionController->decrypt($idUser);
  1551. if(!$idUser){
  1552. return $this->responseController->makeResponse(true, 'El id del usuario que consulta no fue encriptado correctamente', [], 400);
  1553. }
  1554. $usr = DB::table('S002V01TUSUA')->where([
  1555. ['USUA_IDUS', '=', $idUser],
  1556. ['USUA_NULI', '=', $line]
  1557. ])->first();
  1558. if(is_null($usr)){
  1559. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  1560. }
  1561. $screen = DB::table('S002V01TPANT')->select(
  1562. 'PANT_IDFU as IDPANTALLA',
  1563. 'PANT_NOMB as NOMBREPANTALLA',
  1564. )->where([
  1565. ['PANT_NULI', '=', $line],
  1566. ['PANT_IDPA', '=', $idPan],
  1567. ['PANT_IDFU', '=', $idFun],
  1568. ])->first();
  1569. $now = $this->functionsController->now();
  1570. $nowStr = $now->toDateTimeString();
  1571. $actions = DB::getQueryLog();
  1572. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1573. $idac = $this->functionsController->registerActivity(
  1574. $line,
  1575. '-',
  1576. '-',
  1577. '-',
  1578. 'Consulta',
  1579. "El usuario $name (" . $usr->USUA_IDUS . ") consultó la pantalla " . $idPan . " del sistema.",
  1580. $idUser,
  1581. $nowStr
  1582. );
  1583. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  1584. return $this->responseController->makeresponse(false, "EXITO", [
  1585. 'NOMBREPANTALLA' => is_null($screen) ? '-' : $screen->NOMBREPANTALLA
  1586. ]);
  1587. }
  1588. }