| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904 |
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Validator;
- use Illuminate\Support\Facades\Hash;
- use Illuminate\Support\Carbon;
- class UsersProfilesController extends Controller{
- private $responseController;
- private $encryptionController;
- private $functionsController;
- private $moduleCode = 'S002V01M02USPE';
- public function __construct(){
- $this->responseController = new ResponseController();
- $this->encryptionController = new EncryptionController();
- $this->functionsController = new FunctionsController();
- }
-
- public function getUsers($idUser, $line){
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 400);
- }
-
- $users = DB::table('S002V01TUSUA')->select([
- 'USUA_IDUS as IDUSUARIO',
- 'USUA_NOMB as NOMBRE',
- 'USUA_APPA as APEPAT',
- 'USUA_APMA as APEMAT',
- 'USUA_COEL as EMAIL',
- DB::raw("CONCAT(PERF_NOPE, ' (', PERF_IDPE, ')') AS PERFIL"),
- DB::raw("IF(ISNULL(PACO_IDPC), FALSE, TRUE) AS TIENE_PANEL"),
- DB::raw("IF(ISNULL(PACO_IDPC), '-', CONCAT(PACO_NPCO, ' (', PACO_IDPC, ')')) AS PANEL_CONTROL"),
- 'USUA_ESTA as ESTATUS',
- 'BIAC_FECO as ULCON',
- 'USUA_ORGA as ORGANIGRAMA',
- ])->join('S002V01TPERF', 'USUA_PERF', '=', 'PERF_IDPE')
- ->leftJoin('S002V01TBIAC', 'USUA_ULCO', '=', 'BIAC_IDCO')
- ->leftJoin('S002V01TPACO', 'USUA_PCRE', '=', 'PACO_IDPC')
- ->where('USUA_NULI', '=', $line)->get()->all();
- foreach($users as $key=>$user){
- $user->IDUSUARIO = $this->encryptionController->encrypt($user->IDUSUARIO);
- $user->TIENE_PANEL = $user->TIENE_PANEL == 1;
- if(is_null($user->ORGANIGRAMA)){
- $user->ORGANIGRAMA = '[]';
- }else{
- $organization = json_decode($user->ORGANIGRAMA, true);
- foreach($organization as $index=>$item){
- $idChiefEnc = $this->encryptionController->encrypt($item['id_chief']);
- $item['id_chief'] = $idChiefEnc;
- $organization[$index] = $item;
- }
- $user->ORGANIGRAMA = json_encode($organization);
- }
- $users[$key] = $user;
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $idac = $this->functionsController->registerActivity(
- $line,
- $this->moduleCode,
- 'S002V01F01ADUS',
- 'S002V01P01COUS',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los usuarios registrados.",
- $idUser,
- $nowStr,
- 'S002V01S01GEUS'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeresponse(false, "EXITO", $users);
- }
- public function configureUserOrganization(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'organization' => 'required|json',
- 'configured_user' => 'required|string',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, "El ID del usuario que realizó la solicitud no está encriptado correctamente.", [], 400);
- }
- $user = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']],
- ])->first();
- if(is_null($user)){
- return $this->responseController->makeResponse(true, 'El usuario usuario que realizó la solicitud no exise.', [], 404);
- }
- $idConfiguredUser = $this->encryptionController->decrypt($form['configured_user']);
- if(!$idConfiguredUser){
- return $this->responseController->makeResponse(true, "El ID del usuario que está configurando no fue encriptado correctamente.", [], 400);
- }else if($idUser == $idConfiguredUser){
- return $this->responseController->makeResponse(true, "El usuario no puede configurar su propio organigrama.", [], 400);
- }
- $configuredUser = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idConfiguredUser],
- ['USUA_NULI', '=', $form['linea']],
- ])->first();
- if(is_null($configuredUser)){
- return $this->responseController->makeResponse(true, 'El usuario usuario que desea configurar no exise.', [], 404);
- }else if($configuredUser->USUA_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'El usuario usuario que desea configurar esta eliminado.', [], 400);
- }
- $organization = json_decode($form['organization'], true);
- if(!is_array($organization)){
- return $this->responseController->makeResponse(true, 'La configuración del organigrama debe ser un arreglo.', [], 400);
- }else if(count($organization) < 1){
- return $this->responseController->makeResponse(true, 'El arreglo de configuración del organigrama debe contener al menos un elemento.', [], 400);
- }
- foreach($organization as $index=>$item){
- if(!is_array($item)){
- return $this->responseController->makeResponse(true, "El elemento en la posición $index del arreglo de configuración del organigrama no es un arreglo.", [], 400);
- }else if(!array_key_exists("level", $item) || !array_key_exists("id_chief", $item)){
- 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);
- }
- $idChiefDec = $this->encryptionController->decrypt($item['id_chief']);
- if(!$idChiefDec){
- 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);
- }else if($idConfiguredUser == $idChiefDec){
- 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);
- }
- $item['id_chief'] = $idChiefDec;
- $organization[$index] = $item;
- }
- $organizationStr = json_encode($organization);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idConfiguredUser],
- ['USUA_NULI', '=', $form['linea']]
- ])->update([
- 'USUA_ORGA' => $organizationStr,
- 'USUA_USMO' => $idUser,
- 'USUA_FEMO' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($user->USUA_NOMB, $user->USUA_APPA, $user->USUA_APMA);
- $nameMod = $this->functionsController->joinName($configuredUser->USUA_NOMB, $configuredUser->USUA_APPA, $configuredUser->USUA_APMA);
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- $this->moduleCode,
- 'S002V01F01ADUS',
- 'S002V01P02RAUS',
- 'Actualización',
- "El usuario $name (" . $user->USUA_IDUS . ") actualizó el organigrama del usuario $nameMod (" . $configuredUser->USUA_IDUS . ").",
- $idUser,
- $nowStr,
- 'S002V01S01GEUS'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
- }
- public function getUser($id, $idUser, $line){
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe.', [], 400);
- }
- $id = $this->encryptionController->decrypt($id);
- if(!$id){
- return $this->responseController->makeResponse(true, "El ID del usuario consultado no está encriptado correctamente.", [], 400);
- }
- $user = DB::table('S002V01TUSUA')->select(
- 'USUA_IDUS AS IDUSUARIO',
- 'USUA_NOMB AS NOMBRE',
- 'USUA_APPA AS APEPAT',
- 'USUA_APMA AS APEMAT',
- 'USUA_COEL AS EMAIL',
- 'USUA_PERF AS PERFIL',
- 'PERF_NOPE AS PERFNOMB',
- 'USUA_ESTA AS ESTATUS',
- )->where([
- ['USUA_IDUS', '=', $id],
- ['USUA_NULI', '=', $line],
- ])->join('S002V01TPERF', 'PERF_IDPE', '=', 'USUA_PERF')->first();
- if(is_null($user)){
- return $this->responseController->makeResponse(true, "El usuario consultado no existe.", [], 404);
- }
- $user->IDUSUARIO = $this->encryptionController->encrypt($user->IDUSUARIO);
- $user->PERFIL = $this->encryptionController->encrypt($user->PERFIL);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $nameCons = $this->functionsController->joinName($user->NOMBRE, $user->APEPAT, $user->APEMAT);
- $idac = $this->functionsController->registerActivity(
- $line,
- $this->moduleCode,
- 'S002V01F01ADUS',
- 'S002V01P01COUS',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó al usuario $nameCons (" . $user->IDUSUARIO . ").",
- $idUser,
- $nowStr,
- 'S002V01S01GEUS'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeresponse(false, "EXITO", $user);
- }
- public function getProfiles($idUser, $line){
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
-
- $profiles = DB::table('S002V01TPERF')->select(
- 'PERF_IDPE AS IDPERFIL',
- 'PERF_NOPE AS NOMBREPERFIL',
- 'PERF_PERM AS PERMISOS',
- 'PERF_ESTA AS ESTADO',
- 'PERF_USRE AS USRREG',
- 'PERF_FERE AS FECREG',
- 'PERF_USMO AS USRMOD',
- 'PERF_FEMO AS FECMOD',
- )->where('PERF_NULI', '=', $line)->orderBy('PERF_IDPE', 'desc')->get()->all();
- foreach($profiles as $key=>$profile){
- $relatedUsers = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_PERF', '=', $profile->IDPERFIL]
- ])->get()->all();
- $profile->IDPERFIL = $this->encryptionController->encrypt($profile->IDPERFIL);
- $profile->PERMISOS = $this->encryptionController->encrypt($profile->PERMISOS);
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $profile->USRREG]
- ])->first();
- $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $profile->USRREG = $usrRegName . " (" . $profile->USRREG . ")";
- if(!is_null($profile->USRMOD)){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $profile->USRMOD]
- ])->first();
- $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $profile->USRMOD = $usrModName . " (" . $profile->USRMOD . ")";
- }
- $profile->USUARIOS_RELACIONADOS = count($relatedUsers);
- $profiles[$key] = $profile;
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $idac = $this->functionsController->registerActivity(
- $line,
- $this->moduleCode,
- 'S002V01F01ADPE',
- 'S002V01P01COPE',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los perfiles registrados.",
- $idUser,
- $nowStr,
- 'S002V01S02GEPE'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeresponse(false, "EXITO", $profiles);
- }
- public function getProfile($idProfile, $idUser, $line){
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 400);
- }
- $idProfile = $this->encryptionController->decrypt($idProfile);
- if(!$idProfile){
- return $this->responseController->makeResponse(true, "El ID del perfil no está encriptado correctamente.", [], 401);
- }
- $profile = DB::table('S002V01TPERF')->select(
- 'PERF_IDPE AS IDPERFIL',
- 'PERF_NOPE AS NOMBREPERFIL',
- 'PERF_ESTA AS ESTATUS',
- 'PERF_PERM AS PERMISOS',
- )->where([
- ['PERF_IDPE', '=', $idProfile],
- ['PERF_NULI', '=', $line],
- ])->first();
- if(is_null($profile)){
- return $this->responseController->makeResponse(true, "El perfil consultado no existe.", [], 404);
- }
- $profile->IDPERFIL = $this->encryptionController->encrypt($profile->IDPERFIL);
- $profilePermissions = json_decode($profile->PERMISOS, true);
- $permissions = [];
- $modules = DB::table('S002V01TMODU')->where('MODU_NULI', '=', $line)->get()->all();
- $moduleIndex = 0;
- foreach($modules as $module){
- $submodules = DB::table('S002V01TSUBM')->where([
- ['SUBM_IDMO', '=', $module->MODU_IDMO],
- ['SUBM_NULI', '=', $line]
- ])->get()->all();
-
- $permissionsPerSubmodule = [];
- $submoduleIndex = 0;
- foreach($submodules as $submodule){
- $functions = DB::table('S002V01TFUNC')->where([
- ['FUNC_IDMO', '=', $module->MODU_IDMO],
- ['FUNC_IDSM', '=', $submodule->SUBM_IDSM],
- ['FUNC_NULI', '=', $line],
- ])->get()->all();
- $permissionsPerFunction = [];
- $functionIndex = 0;
- foreach($functions as $function){
- $screens = DB::table('S002V01TPANT')->where([
- ['PANT_IDFU', '=', $function->FUNC_IDFU],
- ['PANT_NULI', '=', $line],
- ])->get()->all();
- $permissionsPerScreen = [];
- $screenIndex = 0;
- foreach($screens as $screen){
- $screenAccess = 0;
- if(isset($profilePermissions['permissions'][$moduleIndex]['children'][$submoduleIndex]['children'][$functionIndex]['children'][$screenIndex]['access'])){
- $screenAccess = $profilePermissions['permissions'][$moduleIndex]['children'][$submoduleIndex]['children'][$functionIndex]['children'][$screenIndex]['access'];
- }
-
- $permissionsPerScreen[] = [
- 'id' => $this->encryptionController->encrypt($screen->PANT_IDPA),
- 'name' => $screen->PANT_NOMB,
- 'access' => $screenAccess
- ];
-
- $screenIndex++;
- }
- $functionAcces = 0;
- if(isset($profilePermissions['permissions'][$moduleIndex]['children'][$submoduleIndex]['children'][$functionIndex]['access'])){
- $functionAcces = $profilePermissions['permissions'][$moduleIndex]['children'][$submoduleIndex]['children'][$functionIndex]['access'];
- }
- $permissionsPerFunction[] = [
- 'id' => $this->encryptionController->encrypt($function->FUNC_IDFU),
- 'name' => $function->FUNC_NOMB,
- 'access' => $functionAcces,
- 'children' => $permissionsPerScreen,
- ];
- $functionIndex++;
- }
- $submoduleAccess = 0;
- if(isset($profilePermissions['permissions'][$moduleIndex]['children'][$submoduleIndex]['access'])){
- $submoduleAccess = $profilePermissions['permissions'][$moduleIndex]['children'][$submoduleIndex]['access'];
- }
- $permissionsPerSubmodule[] = [
- 'id' => $this->encryptionController->encrypt($submodule->SUBM_IDSM),
- 'name' => $submodule->SUBM_NOMB,
- 'access' => $submoduleAccess,
- 'children' => $permissionsPerFunction,
- ];
- $submoduleIndex++;
- }
-
- $functions = DB::table('S002V01TFUNC')->where([
- ['FUNC_IDMO', '=', $module->MODU_IDMO],
- ['FUNC_IDSM', '=', null],
- ['FUNC_NULI', '=', $line],
- ])->get()->all();
-
- $permissionsPerFunction = [];
- $functionIndex = 0;
- foreach($functions as $function){
- $screens = DB::table('S002V01TPANT')->where([
- ['PANT_IDFU', '=', $function->FUNC_IDFU],
- ['PANT_NULI', '=', $line],
- ])->get()->all();
- $permissionsPerScreen = [];
- $screenIndex = 0;
- foreach($screens as $screen){
- $screenAccess = 0;
- if(isset($profilePermissions['permissions'][$moduleIndex]['children'][$functionIndex]['children'][$screenIndex]['access'])){
- $screenAccess = $profilePermissions['permissions'][$moduleIndex]['children'][$functionIndex]['children'][$screenIndex]['access'];
- }
- $permissionsPerScreen[] = [
- 'id' => $this->encryptionController->encrypt($screen->PANT_IDPA),
- 'name' => $screen->PANT_NOMB,
- 'access' => $screenAccess
- ];
- $screenIndex++;
- }
- $functionAcces = 0;
- if(isset($profilePermissions['permissions'][$moduleIndex]['children'][$functionIndex]['access'])){
- $functionAcces = $profilePermissions['permissions'][$moduleIndex]['children'][$functionIndex]['access'];
- }
- $permissionsPerFunction[] = [
- 'id' => $this->encryptionController->encrypt($function->FUNC_IDFU),
- 'name' => $function->FUNC_NOMB,
- 'access' => $functionAcces,
- 'children' => $permissionsPerScreen,
- ];
- $functionIndex++;
- }
- $permissionsArr = [];
- foreach($permissionsPerSubmodule as $perm){ $permissionsArr[] = $perm; }
- foreach($permissionsPerFunction as $perm){ $permissionsArr[] = $perm; }
- $moduleAccess = $profilePermissions['permissions'][$moduleIndex]['access'];
- $permissions[] = [
- 'id' => $this->encryptionController->encrypt($module->MODU_IDMO),
- 'name' => $module->MODU_NOMO,
- 'access' => $moduleAccess,
- 'children' => $permissionsArr,
- 'enabled' => $module->MODU_ESTA == 'E'
- ];
- $moduleIndex++;
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $profile->PERMISOS = ['permissions' => $permissions];
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $idac = $this->functionsController->registerActivity(
- $line,
- $this->moduleCode,
- 'S002V01F01ADPE',
- 'S002V01P01COPE',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el perfil " . $profile->NOMBREPERFIL . " (" . $profile->IDPERFIL . ").",
- $idUser,
- $nowStr,
- 'S002V01S02GEPE'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeresponse(false, "EXITO", $profile);
- }
- public function updateUser(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id' => 'required|string',
- 'name' => 'required|string|max:50',
- 'fApe' => 'required|string|max:50',
- 'email' => 'required|string|email',
- 'perf' => 'required|string',
- 'id_user' => 'required|string',
- 'linea' => 'required|integer'
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $user = $request->all();
- $idUser = $this->encryptionController->decrypt($user['id']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, "El ID del usuario que desea modificar no está encriptado correctamente.", [], 400);
- }
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $user['linea']],
- ])->first();
- if(is_null($usrMod)){
- return $this->responseController->makeResponse(true, 'El usuario que desea modificar no exise.', [], 404);
- }
- $idUserMod = $this->encryptionController->decrypt($user['id_user']);
- if(!$idUserMod){
- return $this->responseController->makeResponse(true, "El ID del usuario que modifica no está encriptado correctamente.", [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUserMod],
- ['USUA_NULI', '=', $user['linea']],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realiza la solicitud no existe', [], 404);
- }
- if($idUser == $idUserMod){
- return $this->responseController->makeResponse(true, "El usuario no puede modificar su propio registro.", [], 401);
- }
- $idProfile = $this->encryptionController->decrypt($user['perf']);
- if(!$idProfile){
- return $this->responseController->makeResponse(true, "El ID del perfil seleccionado no está encriptado correctamente.", [], 400);
- }
- $profile = DB::table('S002V01TPERF')->where([
- ['PERF_IDPE', '=', $idProfile],
- ['PERF_NULI', '=', $user['linea']]
- ])->first();
- if(is_null($profile)){
- return $this->responseController->makeResponse(true, 'El perfil seleccionado no existe.', [], 404);
- }else if($profile->PERF_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'El perfil seleccionado está eliminado.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $correos = DB::table('S002V01TUSUA')->where([
- ['USUA_COEL', '=', $user['email']],
- ['USUA_IDUS', '!=', $idUser]
- ])->get()->all();
- if(count($correos) > 0){
- return $this->responseController->makeResponse(true, "El nuevo correo electrónico ya está registrado en la base.", [], 401);
- }
- DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $user['linea']]
- ])->update([
- 'USUA_NOMB' => $user['name'],
- 'USUA_APPA' => $user['fApe'],
- 'USUA_APMA' => array_key_exists('sApe', $user) ? $user['sApe'] : null,
- 'USUA_COEL' => $user['email'],
- 'USUA_PERF' => $idProfile,
- 'USUA_USMO' => $idUserMod,
- 'USUA_FEMO' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $nameMod = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $idac = $this->functionsController->registerActivity(
- $user['linea'],
- $this->moduleCode,
- 'S002V01F01ADUS',
- 'S002V01P02RAUS',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó al usuario $nameMod (" . $usrMod->USUA_IDUS . ").",
- $idUser,
- $nowStr,
- 'S002V01S01GEUS'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $user['linea']);
- return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
- }
- public function createUser(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'name' => 'required|string|max:50',
- 'fApe' => 'required|string|max:50',
- 'perf' => 'required|string',
- 'email' => 'required|string|email',
- 'password' => 'required|string|min:8|confirmed',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $user = $request->all();
- $idUsre = $this->encryptionController->decrypt($user['id_user']);
- if(!$idUsre){
- return $this->responseController->makeResponse(true, "El ID del usuario que registra no está encriptado correctamente.", [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUsre],
- ['USUA_NULI', '=', $user['linea']]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }else if($usr->USUA_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El usuario que realiza el registro está eliminado.", [], 401);
- }else if($usr->USUA_ESTA == 'Inactivo'){
- return $this->responseController->makeResponse(true, "El usuario que realiza el registro está boloqueado.", [], 401);
- }
- $idProfile = $this->encryptionController->decrypt($user['perf']);
- if(!$idProfile){
- return $this->responseController->makeResponse(true, "El ID del perfil seleccionado no está encriptado correctamente.", [], 400);
- }
-
- $profile = DB::table('S002V01TPERF')->where([
- ['PERF_IDPE', '=', $idProfile],
- ['PERF_NULI', '=', $user['linea']]
- ])->first();
- if(is_null($profile)){
- return $this->responseController->makeResponse(true, 'El perfil seleccionado no existe.', [], 404);
- }else if($usr->USUA_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El perfil seleccionado está eliminado.", [], 401);
- }
- $email = DB::table('S002V01TUSUA')->where([
- ['USUA_COEL', '=', $user['email']],
- ['USUA_NULI', '=', $user['linea']]
- ])->get()->first();
-
- if(!is_null($email)){
- return $this->responseController->makeResponse(true, "El correo electrónico ya se encuentra registrado.", [], 401);
- }
- $passEnc = Hash::make($user['password']);
- $apemat = isset($user['sApe']) ? $user['sApe'] : null;
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $idUser = DB::table('S002V01TUSUA')->insertGetId([
- 'USUA_NULI' => $user['linea'],
- 'USUA_NOMB' => $user['name'],
- 'USUA_APPA' => $user['fApe'],
- 'USUA_APMA' => $apemat,
- 'USUA_PERF' => $idProfile,
- 'USUA_PCRE' => 0,
- 'USUA_CONT' => $passEnc,
- 'USUA_COEL' => $user['email'],
- 'USUA_USRE' => $idUsre,
- 'USUA_FERE' => $nowStr,
- ]);
-
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $nameReg = $this->functionsController->joinName($user['name'], $user['fApe'], $apemat);
- $idac = $this->functionsController->registerActivity(
- $user['linea'],
- $this->moduleCode,
- 'S002V01F01ADUS',
- 'S002V01P02RAUS',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró al usuario $nameReg ($idUser).",
- $idUsre,
- $nowStr,
- 'S002V01S01GEUS'
- );
- $this->functionsController->registerLog($actions, $idUsre, $nowStr, $idac, $user['linea']);
- return $this->responseController->makeResponse(false, "EXITO: Registro correcto.");
- }
- public function blockUser(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id' => 'required|string',
- 'estatus' => 'required|in:Activo,Inactivo',
- 'id_user' => 'required|string',
- 'linea' => 'required|integer'
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $user = $request->all();
- $idUser = $this->encryptionController->decrypt($user['id']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, "El id del usuario que desea modificar no está encriptado correctamente.", [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $user['linea']],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 400);
- }
- $idUserMod = $this->encryptionController->decrypt($user['id_user']);
- if(!$idUserMod){
- return $this->responseController->makeResponse(true, "El id del usuario que modifica no está encriptado correctamente.", [], 400);
- }
- if($idUser == $idUserMod){
- return $this->responseController->makeResponse(true, "El usuario no puede modificarse a sí mismo", [], 400);
- }
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUserMod],
- ['USUA_NULI', '=', $user['linea']],
- ])->first();
- if(is_null($usrMod)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $idUserMod)->update([
- 'USUA_ESTA' => $user['estatus'],
- 'USUA_USMO' => $idUser,
- 'USUA_FEMO' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $nameMod = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $tipoAccion = $user['estatus'] == 'Activo' ? 'desbloqueó' : 'bloqueó';
- $idac = $this->functionsController->registerActivity(
- $user['linea'],
- $this->moduleCode,
- 'S002V01F02BDAC',
- '-',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") $tipoAccion al usuario $nameMod (" . $usrMod->USUA_IDUS . ").",
- $idUser,
- $nowStr,
- 'S002V01S01GEUS'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $user['linea']);
- return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
- }
- public function updatePass(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id' => 'required|string',
- 'password' => 'required|string|min:8|confirmed',
- 'id_user' => 'required|string',
- 'linea' => 'required|integer'
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $user = $request->all();
- $idUser = $this->encryptionController->decrypt($user['id']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, "El id del usuario que desea modificar no está encriptado correctamente.", [], 400);
- }
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $user['linea']],
- ])->first();
- if(is_null($usrMod)){
- return $this->responseController->makeResponse(true, 'El usuario que desea modificar no existe', [], 400);
- }
- $idUserMod = $this->encryptionController->decrypt($user['id_user']);
- if(!$idUserMod){
- return $this->responseController->makeResponse(true, "El id del usuario que modifica no está encriptado correctamente.", [], 400);
- }
- if($idUser == $idUserMod){
- return $this->responseController->makeResponse(true, "El usuario no puede modificarse a sí mismo.", [], 401);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUserMod],
- ['USUA_NULI', '=', $user['linea']],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 400);
- }
- $lastPass = $usr->USUA_CONT;
- if(Hash::check($user['password'], $lastPass)){
- return $this->responseController->makeResponse(true, "La contraseña nueva es igual a la anterior.", [], 401);
- }
- $newPass = Hash::make($user['password']);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $user['linea']],
- ])->update([
- 'USUA_CONT' => $newPass,
- 'USUA_USMO' => $idUserMod,
- 'USUA_FEMO' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $idac = $this->functionsController->registerActivity(
- $user['linea'],
- $this->moduleCode,
- 'S002V01F01ADUS',
- 'S002V01P01COUS',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los usuarios registrados.",
- $idUser,
- $nowStr,
- 'S002V01S01GEUS'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $user['linea']);
- return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
- }
- public function deleteUser(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id' => 'required|string',
- 'id_user' => 'required|string',
- 'linea' => 'required|integer'
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $user = $request->all();
- $idUser = $this->encryptionController->decrypt($user['id']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, "El id del usuario que desea eliminar no está encriptado correctamente", [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $user['linea']]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $idUserMod = $this->encryptionController->decrypt($user['id_user']);
- if(!$idUserMod){
- return $this->responseController->makeResponse(true, "El id del usuario que elimina no está encriptado correctamente", [], 400);
- }
- if($idUser == $idUserMod){
- return $this->responseController->makeResponse(true, "El usuario no puede eliminarse a sí mismo", [], 401);
- }
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUserMod],
- ['USUA_NULI', '=', $user['linea']]
- ])->first();
- if(is_null($usrMod)){
- return $this->responseController->makeResponse(true, 'El usuario que desea eliminar no está registrado', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $idUser)->update([
- 'USUA_ESTA' => 'Eliminado',
- 'USUA_USMO' => $idUserMod,
- 'USUA_FEMO' => $nowStr
- ]);
-
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $nameMod = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $idac = $this->functionsController->registerActivity(
- $user['linea'],
- $this->moduleCode,
- 'S002V01F01ADUS',
- 'S002V01P02RAUS',
- 'Eliminación',
- "El usuario $name (" . $usr->USUA_IDUS . ") eliminó al usuario $nameMod (" . $usrMod->USUA_IDUS . ").",
- $idUser,
- $nowStr,
- 'S002V01S01GEUS'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $user['linea']);
-
- return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
- }
- public function getModules($idUser, $line){
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
-
- $modules = DB::table('S002V01TMODU')->select(
- 'MODU_IDMO as ID_MODULO',
- 'MODU_NOMO as NOMBRE_MODULO',
- 'MODU_ICON as ICONO_MODULO',
- 'MODU_ESTA AS ESTADO_MODULO'
- )->where('MODU_NULI', '=', $line)->get()->all();
- foreach($modules as $key=>$module){
- $module->ID_MODULO = $this->encryptionController->encrypt($module->ID_MODULO);
- $module->ESTADO_MODULO = $module->ESTADO_MODULO == 'E';
- $modules[$key] = $module;
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- '-',
- '-',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los módulos del sistema.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeresponse(false, "EXITO", $modules);
- }
- public function getMenu($idUser, $line){
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $modules = DB::table('S002V01TMODU')->select(
- 'MODU_IDMO AS ID_MODULO',
- 'MODU_NOMO AS NOMBRE_MODULO',
- 'MODU_ICON AS ICONO_MODULO',
- 'MODU_ICPE AS ICONO_PERSONALIZADO',
- 'MODU_AIPE AS ARCHIVO_ICONO_PERSONALIZADO',
- 'MODU_ESTA AS ESTADO'
- )->get()->all();
- $mods = [];
- foreach($modules as $module){
- $submodules = DB::table('S002V01TSUBM')->select(
- 'SUBM_IDSM as IDSUBMODULO',
- 'SUBM_NOMB as NOMBRESUBMODULO',
- 'SUBM_ICON AS ICONOSUBMODULO',
- 'SUBM_ICPE AS ICONO_PERSONALIZADO',
- 'SUBM_AIPE AS ARCHIVO_ICONO_PERSONALIZADO',
- )->where('SUBM_IDMO', '=', $module->ID_MODULO)->get()->all();
- $menusMod = DB::table('S002V01TFUNC')->select(
- 'FUNC_IDFU AS IDFUNCION',
- 'FUNC_NOMB AS NOMBREFUNCION',
- 'FUNC_ICON AS ICONOFUNCION',
- 'FUNC_ICPE AS ICONO_PERSONALIZADO',
- 'FUNC_AIPE AS ARCHIVO_ICONO_PERSONALIZADO',
- )->where([
- ['FUNC_IDMO', '=', $module->ID_MODULO],
- ['FUNC_IDSM', '=', null]
- ])->get()->all();
- $module->SUBMODULES = [];
- foreach($submodules as $submodule){
- $menus = DB::table('S002V01TFUNC')->select(
- 'FUNC_IDFU AS IDFUNCION',
- 'FUNC_NOMB AS NOMBREFUNCION',
- 'FUNC_ICON AS ICONOFUNCION',
- 'FUNC_ICPE AS ICONO_PERSONALIZADO',
- 'FUNC_AIPE AS ARCHIVO_ICONO_PERSONALIZADO',
- )->where([
- ['FUNC_IDMO', '=', $module->ID_MODULO],
- ['FUNC_IDSM', '=', $submodule->IDSUBMODULO]
- ])->get()->all();
- foreach($menus as $funcion){
- $pantallas = DB::table('S002V01TPANT')->select(
- 'PANT_IDPA AS IDPANTALLA',
- 'PANT_NOMB AS NOMBREPANTALLA'
- )->where([
- ['PANT_IDFU', '=', $funcion->IDFUNCION],
- ['PANT_NULI', '=', $line]
- ])->get()->all();
- foreach($pantallas as $key0=>$pantalla){
- $pantalla->IDPANTALLA = $this->encryptionController->encrypt($pantalla->IDPANTALLA);
- $pantallas[$key0] = $pantalla;
- }
- $funcion->IDFUNCION = $this->encryptionController->encrypt($funcion->IDFUNCION);
- $funcion->PANTALLAS = $pantallas;
- }
- $submodule->FUNCIONES = [];
- foreach($menus as $menu){
- $submodule->FUNCIONES[] = $menu;
- }
- $submodule->IDSUBMODULO = $this->encryptionController->encrypt($submodule->IDSUBMODULO);
- if(!is_null($submodule->ARCHIVO_ICONO_PERSONALIZADO)){
- $submodule->ARCHIVO_ICONO_PERSONALIZADO = $this->encryptionController->encrypt($submodule->ARCHIVO_ICONO_PERSONALIZADO);
- }
- $module->SUBMODULES[] = $submodule;
- }
- foreach($menusMod as $funcion){
- $pantallas = DB::table('S002V01TPANT')->select(
- 'PANT_IDPA AS IDPANTALLA',
- 'PANT_NOMB AS NOMBREPANTALLA'
- )->where([
- ['PANT_IDFU', '=', $funcion->IDFUNCION],
- ['PANT_NULI', '=', $line]
- ])->get()->all();
- foreach($pantallas as $key0=>$pantalla){
- $pantalla->IDPANTALLA = $this->encryptionController->encrypt($pantalla->IDPANTALLA);
- $pantallas[$key0] = $pantalla;
- }
- $funcion->IDFUNCION = $this->encryptionController->encrypt($funcion->IDFUNCION);
- $funcion->PANTALLAS = $pantallas;
- }
- $module->MENUS = $menusMod;
- $module->ID_MODULO = $this->encryptionController->encrypt($module->ID_MODULO);
-
- if(!is_null($module->ICONO_PERSONALIZADO)){
- $module->ICONO_PERSONALIZADO = $this->encryptionController->encrypt($module->ICONO_PERSONALIZADO);
- }
-
- if(!is_null($module->ARCHIVO_ICONO_PERSONALIZADO)){
- $module->ARCHIVO_ICONO_PERSONALIZADO = $this->encryptionController->encrypt($module->ARCHIVO_ICONO_PERSONALIZADO);
- }
- $mods[] = $module;
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- '-',
- '-',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el menú del sistema.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, "EXITO", $mods);
- }
- public function buildInitialPermissions($idUser, $line){
- DB::enableQueryLog();
-
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 400);
- }
- $permissions = [];
- //Se obtienen todos los modulos
- $modules = DB::table('S002V01TMODU')->where('MODU_NULI', '=', $line)->get()->all();
- //se consultan los submodulos de cada modulo
- foreach($modules as $module){
- $submodules = DB::table('S002V01TSUBM')->where([
- ['SUBM_IDMO', '=', $module->MODU_IDMO],
- ['SUBM_NULI', '=', $line]
- ])->get()->all();
-
- $permissionsPerSubmodule = [];
- $hasSubmodules = false;
- foreach($submodules as $submodule){
- //Se consultan las funciones
- $functions = DB::table('S002V01TFUNC')->where([
- ['FUNC_IDMO', '=', $module->MODU_IDMO],
- ['FUNC_IDSM', '=', $submodule->SUBM_IDSM],
- ['FUNC_NULI', '=', $line],
- ])->get()->all();
- $permissionsPerFunction = [];
- foreach($functions as $function){
- $screens = DB::table('S002V01TPANT')->where([
- ['PANT_IDFU', '=', $function->FUNC_IDFU],
- ['PANT_NULI', '=', $line],
- ])->get()->all();
- $permissionsPerScreen = [];
- foreach($screens as $screen){
- $permissionsPerScreen[] = [
- 'id' => $screen->PANT_IDPA,
- 'name' => $screen->PANT_NOMB,
- 'access' => 0
- ];
- }
- $permissionsPerFunction[] = [
- 'id' => $function->FUNC_IDFU,
- 'name' => $function->FUNC_NOMB,
- 'access' => 0,
- 'children' => $permissionsPerScreen,
- ];
- }
- $permissionsPerSubmodule[] = [
- 'id' => $submodule->SUBM_IDSM,
- 'name' => $submodule->SUBM_NOMB,
- 'access' => 0,
- 'children' => $permissionsPerFunction,
- ];
- $hasSubmodules = true;
- }
-
- //Se consultan las funciones
- $functions = DB::table('S002V01TFUNC')->where([
- ['FUNC_IDMO', '=', $module->MODU_IDMO],
- ['FUNC_IDSM', '=', null],
- ['FUNC_NULI', '=', $line],
- ])->get()->all();
-
- $permissionsPerFunction = [];
- foreach($functions as $function){
- $screens = DB::table('S002V01TPANT')->where([
- ['PANT_IDFU', '=', $function->FUNC_IDFU],
- ['PANT_NULI', '=', $line],
- ])->get()->all();
- $permissionsPerScreen = [];
- foreach($screens as $screen){
- $permissionsPerScreen[] = [
- 'id' => $screen->PANT_IDPA,
- 'name' => $screen->PANT_NOMB,
- 'access' => 0
- ];
- }
- $permissionsPerFunction[] = [
- 'id' => $function->FUNC_IDFU,
- 'name' => $function->FUNC_NOMB,
- 'access' => 0,
- 'children' => $permissionsPerScreen,
- ];
- }
- $permissionsArr = [];
- foreach($permissionsPerSubmodule as $perm){ $permissionsArr[] = $perm; }
- foreach($permissionsPerFunction as $perm){ $permissionsArr[] = $perm; }
- $permissions[] = [
- 'id' => $module->MODU_IDMO,
- 'name' => $module->MODU_NOMO,
- 'access' => 0,
- 'children' => $permissionsArr,
- ];
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $idac = $this->functionsController->registerActivity(
- $line,
- $this->moduleCode,
- 'S002V01F01ADPE',
- 'S002V01P02REPE',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el arreglo de permisos iniciales.",
- $idUser,
- $nowStr,
- 'S002V01S02GEPE'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeresponse(false, "EXITO", ['permissions' => $permissions]);
- }
- public function updateProfile(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id' => 'required|string',
- 'name' => 'required|string|max:50',
- 'permissions' => 'required|json',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $info = $request->all();
- $idUser = $this->encryptionController->decrypt($info['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, "El ID del usuario que realizó la solicitud no fue encriptado correctamente", [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $info['linea']],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 404);
- }
- $idPerf = $this->encryptionController->decrypt($info['id']);
- if(!$idPerf){
- return $this->responseController->makeResponse(true, "El ID del perfil solicitado no fue encriptado correctamente", [], 400);
- }
- $perf = DB::table('S002V01TPERF')->where([
- ['PERF_IDPE', '=', $idPerf],
- ['PERF_NULI', '=', $info['linea']],
- ])->first();
- if(is_null($perf)){
- return $this->responseController->makeResponse(true, 'El perfil solicitado no existe', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TPERF')->where([
- ['PERF_IDPE', '=', $idPerf],
- ['PERF_NULI', '=', $info['linea']],
- ])->update([
- 'PERF_PERM' => $info['permissions'],
- 'PERF_NOPE' => $info['name'],
- 'PERF_USMO' => $idUser,
- 'PERF_FEMO' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $idac = $this->functionsController->registerActivity(
- $info['linea'],
- $this->moduleCode,
- 'S002V01F01ADPE',
- 'S002V01P02REPE',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el perfil " . $perf->PERF_NOPE . "(" . $perf->PERF_NOPE . ").",
- $idUser,
- $nowStr,
- 'S002V01S02GEPE'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $info['linea']);
- return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
- }
- public function deleteProfile(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id' => 'required|string',
- 'id_user' => 'required|string',
- 'linea' => 'required|integer'
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $profile = $request->all();
- $idUser = $this->encryptionController->decrypt($profile['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, "El ID del usuario que solicitó la acción no está encriptado correctamente", [], 401);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $profile['linea']],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 404);
- }
-
- $idProf = $this->encryptionController->decrypt($profile['id']);
- if(!$idProf){
- return $this->responseController->makeResponse(true, "El ID del perfil seleccionado no está encriptado correctamente", [], 401);
- }
- $perf = DB::table('S002V01TPERF')->where([
- ['PERF_IDPE', '=', $idProf],
- ['PERF_NULI', '=', $profile['linea']],
- ])->first();
- if(is_null($perf)){
- return $this->responseController->makeResponse(true, 'El perfil solicitado no existe', [], 404);
- }
- $users = DB::table('S002V01TUSUA')->where([
- ['USUA_PERF', '=', $idProf],
- ['USUA_NULI', '=', $profile['linea']]
- ])->get()->all();
- if(count($users) > 0){
- return $this->responseController->makeResponse(true, "El perfil seleccionado no se puede eliminar porque hay usuarios asociados a él.", [], 401);
- }
-
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TPERF')->where([
- ['PERF_IDPE', '=', $idProf],
- ['PERF_NULI', '=', $profile['linea']],
- ])->update([
- 'PERF_ESTA' => 'Eliminado',
- 'PERF_USMO' => $idUser,
- 'PERF_FEMO' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $idac = $this->functionsController->registerActivity(
- $profile['linea'],
- $this->moduleCode,
- 'S002V01F01ADPE',
- '-',
- 'Eliminación',
- "El usuario $name (" . $usr->USUA_IDUS . ") eliminó el perfil " . $perf->PERF_NOPE . "($idProf).",
- $idUser,
- $nowStr,
- 'S002V01S02GEPE'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $profile['linea']);
- return $this->responseController->makeResponse(false, "EXITO: Eliminación correcta.");
- }
- public function createProfile(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'name' => 'required|string|min:8|max:50',
- 'permissions' => 'required|json'
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $profile = $request->all();
- $idUser = $this->encryptionController->decrypt($profile['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $profile['linea']]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la solicitud no está registrado', [], 404);
- }else if($usr->USUA_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El usuario que realiza el registro está eliminado.", [], 401);
- }else if($usr->USUA_ESTA == 'Inactivo'){
- return $this->responseController->makeResponse(true, "El usuario que realiza el registro está boloqueado.", [], 401);
- }
- $now = $this->functionsController->now();
- $nowStr = $now ->toDateTimeString();
- $newPerf = DB::table('S002V01TPERF')->insertGetId([
- 'PERF_NULI' => $profile['linea'],
- 'PERF_NOPE' => $profile['name'],
- 'PERF_PERM' => $profile['permissions'],
- 'PERF_USRE' => $idUser,
- 'PERF_FERE' => $nowStr
- ]);
-
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $idac = $this->functionsController->registerActivity(
- $profile['linea'],
- $this->moduleCode,
- 'S002V01F01ADPE',
- 'S002V01P02REPE',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró el perfil $profile[name] ($newPerf).",
- $idUser,
- $nowStr,
- 'S002V01S02GEPE'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $profile['linea']);
- return $this->responseController->makeResponse(false, 'EXITO');
- }
- public function getModule($idMod, $idUser, $line){
- DB::enableQueryLog();
-
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $idMod = $this->encryptionController->decrypt($idMod);
- if(!$idMod){
- return $this->responseController->makeResponse(true, 'El módulo solicitado no fue encriptado correctamente', [], 400);
- }
- $module = DB::table('S002V01TMODU')->select(
- 'MODU_IDMO as IDMODULO',
- 'MODU_NOMO as NOMBREMODULO',
- )->where([
- ['MODU_NULI', '=', $line],
- ['MODU_IDMO', '=', $idMod]
- ])->first();
- if(is_null($module)){
- return $this->responseController->makeResponse(true, 'El módulo consultado no está registrado', [], 404);
- }
- $module->IDMODULO = $this->encryptionController->encrypt($module->IDMODULO);
- $now = $this->functionsController->now();
- $actions = DB::getQueryLog();
- $nowStr = $now->toDateTimeString();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- '-',
- '-',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el módulo " . $idMod . " del sistema.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeresponse(false, "EXITO", $module);
- }
- public function getSubmodules($idMod, $idUser, $line){
- DB::enableQueryLog();
-
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
-
- $idMod = $this->encryptionController->decrypt($idMod);
- if(!$idMod){
- return $this->responseController->makeResponse(true, 'El ID del módulo no fue encriptado correctamente', [], 400);
- }
- $mod = DB::table('S002V01TMODU')->where([
- ['MODU_NULI', '=', $line],
- ['MODU_IDMO', '=', $idMod]
- ])->first();
- if(is_null($mod)){
- return $this->responseController->makeResponse(true, 'El módulo consultado no existe', [], 404);
- }
- $submodules = DB::table('S002V01TSUBM')->where([
- ['SUBM_NULI', '=', $line],
- ['SUBM_IDMO', '=', $idMod],
- ])->select([
- 'SUBM_IDSM AS IDSUBMODULO',
- 'SUBM_NOMB AS NOMBRESUBMODULO',
- 'SUBM_ICON AS ICONOSUBMODULO',
- 'SUBM_IMAG AS IMAGENSUBMODULO',
- ])->get()->all();
- foreach($submodules as $key=>$submodule){
- $submodule->IDSUBMODULO = $this->encryptionController->encrypt($submodule->IDSUBMODULO);
- $submodules[$key] = $submodule;
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- '-',
- '-',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los submódulos del módulo '" . $mod->MODU_NOMO . "'.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $submodules);
- }
- public function getSubmodule($idMod, $idSub, $idUser, $line){
- DB::enableQueryLog();
-
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que consulta no fue encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 404);
- }
-
- $idMod = $this->encryptionController->decrypt($idMod);
- if(!$idMod){
- return $this->responseController->makeResponse(true, 'El módulo no fue encriptado correctamente', [], 400);
- }
- $module = DB::table('S002V01TMODU')->where([
- ['MODU_NULI', '=', $line],
- ['MODU_IDMO', '=', $idMod]
- ])->first();
- if(is_null($module)){
- return $this->responseController->makeResponse(true, 'El módulo consultado no existe', [], 404);
- }
-
- $idSub = $this->encryptionController->decrypt($idSub);
- if(!$idSub){
- return $this->responseController->makeResponse(true, 'El submódulo no fue encriptado correctamente', [], 400);
- }
- $submodule = DB::table('S002V01TSUBM')->select(
- 'SUBM_IDSM as IDSUBMODULO',
- 'SUBM_NOMB as NOMBRESUBMODULO',
- )->where([
- ['SUBM_NULI', '=', $line],
- ['SUBM_IDSM', '=', $idSub],
- ['SUBM_IDMO', '=', $idMod],
- ])->first();
- if(is_null($submodule)){
- return $this->responseController->makeResponse(true, 'El submódulo consultado no existe', [], 404);
- }
- $submodule->IDSUBMODULO = $this->encryptionController->encrypt($submodule->IDSUBMODULO);
- $now = $this->functionsController->now();
- $actions = DB::getQueryLog();
- $nowStr = $now->toDateTimeString();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- '-',
- '-',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el submódulo " . $idSub . " del sistema.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeresponse(false, "EXITO", $submodule);
- }
- public function getFunction($idMod, $idSub, $idFun, $idUser, $line){
- DB::enableQueryLog();
-
- $idMod = $this->encryptionController->decrypt($idMod);
- if(!$idMod){
- return $this->responseController->makeResponse(true, 'El módulo no fue encriptado correctamente', [], 400);
- }
-
- $idSub = $this->encryptionController->decrypt($idSub);
- if(!$idSub){
- return $this->responseController->makeResponse(true, 'El submódulo no fue encriptado correctamente', [], 400);
- }
- $idFun = $this->encryptionController->decrypt($idFun);
- if(!$idFun){
- return $this->responseController->makeResponse(true, 'La función no fue encriptada correctamente', [], 400);
- }
-
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El id del usuario que consulta no fue encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $function = DB::table('S002V01TFUNC')->select(
- 'FUNC_IDFU as IDFUNCION',
- 'FUNC_NOMB as NOMBREFUNCION',
- )->where([
- ['FUNC_NULI', '=', $line],
- ['FUNC_IDFU', '=', $idFun],
- ['FUNC_IDMO', '=', $idMod],
- ['FUNC_IDSM', '=', $idSub],
- ])->first();
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- '-',
- '-',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó la función " . $idFun . " del sistema.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeresponse(false, "EXITO", [
- 'NOMBREFUNCION' => is_null($function) ? '-' : $function->NOMBREFUNCION
- ]);
- }
- public function getScreen($idFun, $idPan, $idUser, $line){
- DB::enableQueryLog();
- $idFun = $this->encryptionController->decrypt($idFun);
- if(!$idFun){
- return $this->responseController->makeResponse(true, 'La función no fue encriptada correctamente', [], 400);
- }
- $idPan = $this->encryptionController->decrypt($idPan);
- if(!$idPan){
- return $this->responseController->makeResponse(true, 'La pantalla no fue encriptada correctamente', [], 400);
- }
-
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El id del usuario que consulta no fue encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $screen = DB::table('S002V01TPANT')->select(
- 'PANT_IDFU as IDPANTALLA',
- 'PANT_NOMB as NOMBREPANTALLA',
- )->where([
- ['PANT_NULI', '=', $line],
- ['PANT_IDPA', '=', $idPan],
- ['PANT_IDFU', '=', $idFun],
- ])->first();
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- '-',
- '-',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó la pantalla " . $idPan . " del sistema.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeresponse(false, "EXITO", [
- 'NOMBREPANTALLA' => is_null($screen) ? '-' : $screen->NOMBREPANTALLA
- ]);
- }
- }
|