| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744 |
- <?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'
- ])->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;
- $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 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,
- ];
- $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,
- 'S002V01F04ELUS',
- '-',
- 'Eliminación',
- "El usuario $name (" . $usr->USUA_IDUS . ") eleimnó 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 IDMODULO',
- 'MODU_NOMO as NOMBREMODULO',
- 'MODU_ICON as ICONOMODULO',
- )->where('MODU_NULI', '=', $line)->get()->all();
- foreach($modules as $key=>$module){
- $module->IDMODULO = $this->encryptionController->encrypt($module->IDMODULO);
- $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 IDMODULO',
- 'MODU_NOMO as NOMBREMODULO',
- 'MODU_ICON as ICONOMODULO',
- )->get()->all();
- $mods = [];
- foreach($modules as $module){
- $submodules = DB::table('S002V01TSUBM')->select(
- 'SUBM_IDSM as IDSUBMODULO',
- 'SUBM_NOMB as NOMBRESUBMODULO',
- 'SUBM_ICON AS ICONOSUBMODULO'
- )->where('SUBM_IDMO', '=', $module->IDMODULO)->get()->all();
- $menusMod = DB::table('S002V01TFUNC')->select(
- 'FUNC_IDFU AS IDFUNCION',
- 'FUNC_NOMB AS NOMBREFUNCION',
- 'FUNC_ICON AS ICONOFUNCION'
- )->where([
- ['FUNC_IDMO', '=', $module->IDMODULO],
- ['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'
- )->where([
- ['FUNC_IDMO', '=', $module->IDMODULO],
- ['FUNC_IDSM', '=', $submodule->IDSUBMODULO]
- ])->get()->all();
- $menuInd = 0;
- 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();
- $menus[$menuInd]->PANTALLAS = $pantallas;
- $menuInd++;
- }
- $submodule->FUNCIONES = [];
- foreach($menus as $menu){
- $submodule->FUNCIONES[] = $menu;
- }
- $module->SUBMODULES[] = $submodule;
- }
- $menModInd = 0;
- 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();
- $menusMod[$menModInd]->PANTALLAS = $pantallas;
- $menModInd++;
- }
- $module->MENUS = $menusMod;
- $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
- ]);
- }
- }
|