HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/comfama.sports-crowd.com/app/Http/Controllers/Controller.php
<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use App\Http\Controllers\LogController;
use Illuminate\Http\Request;
use App\UserInformation;
use App\Parameter;
use App\Module;
use App\ModuleRol;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Str;
use DB;
use Stichoza\GoogleTranslate\TranslateClient;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public $__SUPERADMIN_ROL = 1;
    public $__ADMIN_ROL = 2;
    public $__MESSENGER_ROL = 3;
    public $__CLIENT_ROL = 4;
    public $__TECHNICAL_ROL = 6;                   // ROL TECNICOS
    public $__EXTERNAL_OPERATOR_ROL = 7;           // ROL GANA
    public $__TICKET_OFFICE_ROL = 8;               // ROL BOLETERIA
    public $__LOGISTICS_ROL = 14;                  // ROL LOGISTICA/ENTRENADOR/USUARIO-ESTADIO
    public $__TICKET_OFFICE_ROL_INTERNAL = 15;     // ROL BOLETERIA INTERNA
    public $__TREASURY_TEAM = 16;                  // ROL TESORERIA
    public $__ADMIN_TEAM = 17;                     // ROL ADMIN EQUIPO
    public $__ADMIN_2_TEAM = 22;                   // ROL ADMIN EQUIPO

    public function __construct()
    {
        ini_set('memory_limit', config('cache.memory_limit'));
    }

    public function registerLog($user_id, $description, $data_operation, $task, $module)
    {
        $module_id = $module;
        if (!is_numeric($module)) {
            $module_id = $this->getIdModuleByName($module);
        }
        $c = new LogController;
        $c->logRegister($user_id, $description, $data_operation, $task, $module_id);
    }

    public function getIdModuleByName($name)
    {
        $module_id = 1;
        if ($name && $name != '') {
            $module = Module::select('id')->where('name', 'LIKE', '%' . $name . '%')->first();
            if ($module) {
                $module_id = $module->id;
            }
        }
        return $module_id;
    }

    public function changeDbDefault(Request $request)
    {
        if (!$request->is('api/*')) {
            $userOld = UserInformation::where('user_id', Auth::user()->id)->first();
            Config::set('database.default', $userOld->current_db);
            DB::reconnect($userOld->current_db);
            $userI = UserInformation::where('user_id', Auth::user()->id)->first();
            $parameters = Parameter::select('db_name')->first();
            $userI->current_db = $parameters->db_name;
            $userI->update();
        }
    }

    // retorna codigo para el evento
    public function codeOrder()
    {
        return (string) Str::uuid();
    }

    public function gen_uid($l = 10)
    {
        return strtoupper(substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyz"), 0, $l));
    }

    // funcion para retornar el valor de una celda en la importacion de archivos excel de la libreria Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
    public function getValueRow($cells, $index = false)
    {
        if ($index !== false) {
            return $cells[$index]->getValue();
        }
        return $cells->getValue();
    }

    public function translate($text, $originLanguage = 'en', $targetLanguage = 'es')
    {
        $tr = new TranslateClient($originLanguage, $targetLanguage);
        return $tr->translate(strval($text));
    }

    public function requestLanguage(Request $request)
    {
        $language = 'es';
        // REVISAR CON MAS DETALLE PORQUE NO RECUPERA IDIOMA DE LOS DISPOSITVOS
        /*$headerLanguage = $request->header('accept-language');
        if (str_contains($headerLanguage, 'en-US')) {
            $language = 'en';
        } else if (str_contains($headerLanguage, 'pt-BR')) {
            $language = 'pt';
        }*/
        return $language;
    }

    public function getModule(Request $request)
    {
        $path = $request->getPathInfo();
        $paths = explode("/", $path);
        if (count($paths) > 1)
            $route = $paths[1];
        else
            $route = $paths[0];

        $module = Module::where('route', $route)->latest('id')->first();
        if (!$module)
            $module = Module::where('route', 'LIKE', '%' . $route . '%')->first();
        if (!$module) {
            $module = $this->getSpecialRoutes($route);
        }
        $module = $this->validateConditionalRoutes($route, $module);
        return $module->id;
    }

    public function validateRouteEnabledUser($module)
    {
        if (Auth::user()) {
            $rol = Auth::user()->rol->id;
            if (in_array($rol, [$this->__CLIENT_ROL])) {
                Auth::logout();
                return redirect('/password/recover-success')->send();
            } elseif (in_array($rol, [$this->__SUPERADMIN_ROL])) {
                return true;
            } else {
                $moduleRol = ModuleRol::where([['rol_id', $rol], ['module_id', $module]])->first();
                return !!$moduleRol;
            }
        }
        return false;
    }

    public function getRouteEnabled()
    {
        if (Auth::user()) {
            $route = Auth::user()->rol->route;
            if ($route)
                return $route;
            else {
                $rol = Auth::user()->rol->id;
                $moduleRol = ModuleRol::where([['rol_id', $rol]])->with('module')->first();
                $moduleFirst = $this->getFirstRouteEnabled($moduleRol->module);
                return ('/' . $moduleFirst->route);
            }
        }
        return false;
    }

    public function validateRolePermissions($module, $roleType, $rol = null)
    {
        if (!$rol)
            $rol = Auth::user()->rol->id;

        switch ($module) {
            case 'ticketing':
                switch ($roleType) {
                    case 'administrator':
                        if (in_array($rol, [$this->__SUPERADMIN_ROL, $this->__ADMIN_ROL]))
                            return true;
                        break;
                    case 'supervisor':
                        if (in_array($rol, [$this->__TICKET_OFFICE_ROL, $this->__TECHNICAL_ROL, $this->__ADMIN_TEAM]))
                            return true;
                        break;
                    case 'seller':
                        if (in_array($rol, [$this->__EXTERNAL_OPERATOR_ROL, $this->__TICKET_OFFICE_ROL_INTERNAL]))
                            return true;
                        break;
                }
                break;

            case 'academy':
            case 'experience':
                switch ($roleType) {
                    case 'administrator':
                        if (in_array($rol, [$this->__SUPERADMIN_ROL, $this->__ADMIN_ROL]))
                            return true;
                        break;
                    case 'supervisor':
                        if (in_array($rol, [$this->__TREASURY_TEAM, $this->__ADMIN_TEAM]))
                            return true;
                        break;
                    case 'assistant':
                        if (in_array($rol, [$this->__LOGISTICS_ROL]))
                            return true;
                        break;
                }
                break;

            case 'user':
                switch ($roleType) {
                    case 'administrator':
                        if (in_array($rol, [$this->__SUPERADMIN_ROL, $this->__ADMIN_ROL]))
                            return true;
                        break;
                    case 'supervisor':
                        if (in_array($rol, [$this->__TICKET_OFFICE_ROL, $this->__TECHNICAL_ROL, $this->__TREASURY_TEAM, $this->__ADMIN_TEAM, $this->__ADMIN_2_TEAM]))
                            return true;
                        break;
                }
                break;
        }

        return false;
    }

    public function extension($mimeType)
    {
        $mimes = new \Mimey\MimeTypes;
        return $mimes->getExtension($mimeType);
    }

    private function getFirstRouteEnabled($module)
    {
        $moduleChild = Module::where('module_id', $module->id)->first();
        if ($moduleChild)
            return $this->getFirstRouteEnabled($moduleChild);
        else
            return $module;
    }

    private function getSpecialRoutes($route)
    {
        $module = null;
        switch ($route) {
                // RUTAS ESPECIALES ACADEMIA
            case 'academy_user_payment':
            case 'validatePayments':
                $module = Module::where('route', 'academy_user')->latest('id')->first();
                break;
            case 'academy_locations/get':
                $module = Module::where('route', 'academy_schedules')->latest('id')->first();
                break;


                // RUTAS ESPECIALES BOLETERIA
            case 'seasons':
            case 'season':
            case 'events':
            case 'event':
            case 'event_prices':
            case 'blocks':
            case 'matchEventStages':
                $module = Module::where('route', 'tournaments')->latest('id')->first();
                break;

            case 'symbolic_tickets_price':
            case 'symbolic_tickets_user':
                $module = Module::where('route', 'symbolic_tickets')->latest('id')->first();
                break;

                // RUTAS ESPECIALES TIENDA
            case 'productAttributes':
                $module = Module::where('route', 'products')->latest('id')->first();
                break;

                // RUTAS ESPECIALES ENCUESTA
            case 'form_fields':
                $module = Module::where('route', 'forms')->latest('id')->first();
                break;

                // RUTAS ESPECIALES EXPERIENCIA
            case 'experience_plans':
            case 'experience_plan_prices':
                $module = Module::where('route', 'experience_settings')->latest('id')->first();
                break;
        }
        return $module;
    }

    private function validateConditionalRoutes($route, $module)
    {
        switch ($route) {
                // RUTAS ESPECIALES BOLETERIA
            case 'tickets':
            case 'flash_ticket':
                $module = Module::where('route', 'ticket-office')->latest('id')->first();
                break;
        }
        return $module;
    }
}