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/dev-telemedicina.teky.com.co/app/Http/Controllers/UserController.php
<?php

namespace Telemedicina\Http\Controllers;

use Illuminate\Http\Request;
use Telemedicina\User;
use Telemedicina\Rol;
use Telemedicina\MedicalCenter;
use Telemedicina\IdentificationType;
use Illuminate\Support\Facades\Input;
use Session;
use Redirect;
use Telemedicina\Specialty;
use Illuminate\Support\Facades\Auth;


class UserController extends Controller
{
    /**
    * Display a listing of the resource.
    *
    * @return \Illuminate\Http\Response
    */
    public function index()
    {
        $obj = User::select('id', 'name', 'last_name','document', 'phone', 'email', 'rol_id', 'center_id', 'active')
        ->with('rol')
        ->with('centro')
        ->orderBy('name')
        ->orderBy('active')
        ->get();

        $objHospitales = MedicalCenter::where('active', true)->orderBy('name')->get();
        if(Auth::user()->rol->id == 10 || Auth::user()->rol->id == 11 || Auth::user()->rol->id == 4){
            $objRols = Rol::where('id',9)->get();
        }else{
            $objRols = Rol::orderBy('name')->get();
        }
        $specialties = Specialty::where('active', true)->get();
        $document_types = IdentificationType::where('active', true)->get();

        return view('users.main')
                ->with('users', $obj)
                ->with('rols', $objRols)
                ->with('centers', $objHospitales)
                ->with('specialties', $specialties)
                ->with('document_types', $document_types);
    }

    /**
    * Show the form for creating a new resource.
    *
    * @return \Illuminate\Http\Response
    */
    public function create()
    {
        //
    }

    /**
    * Store a newly created resource in storage.
    *
    * @param  \Illuminate\Http\Request  $request
    * @return \Illuminate\Http\Response
    */
    public function store(Request $request)
    {
        if(!$request->rol_id){
            Session::flash('data', array('type' => 'danger', 'message' => __('messages.user.valid_rol')));
            return redirect()->back()->withInput(Input::all());
        }

        if(!$request->center_id){
            Session::flash('data', array('type' => 'danger', 'message' => __('messages.user.valid_hospital')));
            return redirect()->back()->withInput(Input::all());
        }

        $r= User::where('document',$request->document)->orWhere('email',$request->email)->get()->first();
        if($r){
            Session::flash('data', array('type' => 'danger', 'message' => __('messages.user.document_exist')));
            return redirect()->back()->withInput(Input::all());
        }

        $obj = new User;
        $obj->name = $request->name;
        $obj->last_name = $request->last_name;
        $obj->document = $request->document;
        $obj->phone = $request->phone;
        $obj->rol_id = $request->rol_id;
        $obj->specialty_id = $request->specialty_id;
        $obj->center_id = $request->center_id;
        $obj->dating_duration = $request->dating_duration;
        $obj->identification_type_id = $request->document_type_id;
        $obj->email = $request->email;
        $obj->medic_code = $request->medic_code;
        $obj->password = \Hash::make($request->password);

        $obj->save();

        Session::flash('data', array('type' => 'success', 'message' => __('messages.user.ok_create')));
        return Redirect::to('users');

    }

    /**
    * Display the specified resource.
    *
    * @param  int  $id
    * @return \Illuminate\Http\Response
    */
    public function show($id)
    {
        //
    }

    /**
    * Show the form for editing the specified resource.
    *
    * @param  int  $id
    * @return \Illuminate\Http\Response
    */
    public function edit($id)
    {
        $user = User::find($id);
        $objHospitales = MedicalCenter::where('active', true)->orderBy('name')->get();
        $objRols = Rol::orderBy('name')->get();
        $specialties = Specialty::where('active', true)->get();
        $document_types = IdentificationType::where('active', true)->get();

        return view('users.edit')
                ->with('obj', $user)
                ->with('rols', $objRols)
                ->with('centers', $objHospitales)
                ->with('specialties', $specialties)
                ->with('document_types', $document_types);
    }

    /**
    * Update the specified resource in storage.
    *
    * @param  \Illuminate\Http\Request  $request
    * @param  int  $id
    * @return \Illuminate\Http\Response
    */
    public function update(Request $request, $id)
    {
        if(!$request->rol_id){
            Session::flash('data', array('type' => 'danger', 'message' => __('messages.user.valid_rol')));
            return redirect()->back()->withInput(Input::all());
        }

        if(!$request->center_id){
            Session::flash('data', array('type' => 'danger', 'message' => __('messages.user.valid_hospital')));
            return redirect()->back()->withInput(Input::all());
        }

        $obj = User::find($id);

        $obj->name = $request->name;
        $obj->last_name = $request->last_name;
        $obj->phone = $request->phone;
        $obj->rol_id = $request->rol_id;
        $obj->specialty_id = $request->specialty_id;
        $obj->center_id = $request->center_id;
        $obj->dating_duration = $request->dating_duration;
        $obj->medic_code = $request->medic_code;
        $obj->email = $request->email;

        if($request->password){
            $obj->password = \Hash::make($request->password);
            $obj->initial = true;
        }

        $obj->update();

        Session::flash('data', array('type' => 'success', 'message' => __('messages.user.ok_update')));
        return Redirect::to('users');
    }

    /**
    * Remove the specified resource from storage.
    *
    * @param  int  $id
    * @return \Illuminate\Http\Response
    */
    public function destroy($id)
    {
        //
    }

    public function filter($id){
        if($id!="todos"){
            $obj =User::where('center_id',$id)
            ->with('rol')
            ->with('centro')->get();

            $objHospitales = MedicalCenter::orderBy('name')->get();
            $objRols = Rol::orderBy('name')->get();

            return view('users.main')
                    ->with('users', $obj)
                    ->with('rols', $objRols)
                    ->with('centers', $objHospitales)
                    ->with('selectHospital',$id);

        }else{
            $obj = User::select('id', 'name', 'last_name','document', 'phone', 'email', 'rol_id', 'center_id','active')
        ->with('rol')
        ->with('centro')
        ->get();

        $objHospitales = MedicalCenter::orderBy('name')->get();
        $objRols = Rol::orderBy('name')->get();

        return view('users.main')
                ->with('users', $obj)
                ->with('rols', $objRols)
                ->with('centers', $objHospitales);
        }

    }


    public function active(Request $request){

        $id= $request['id'];
        $estado=  $request['estado'];
        $user = User::where('id', '=',$id)->first();
        $user->active = $estado;
        $user->update();

        $res[] = array('respuesta' => true);
        $dres = json_encode($res);
        return json_decode($dres, true);

      }

      public function updatePassword(Request $request){

        $user = User::where('id', '=',$request["id"])->first();
        $user->initial = false;
        $user->password = \Hash::make($request["password"]);
        $user->update();

        $res[] = array('respuesta' => true);
        $dres = json_encode($res);
        return json_decode($dres, true);
      }


}