@php

    use App\Libraries\ejLib;
    $var = ejLib::getInstance();
    $soapclient = $var->getWs();
    $wsClave = $var->get_wsClave();

    function recuperaCadena($cadena_entrante){       
        $cadena = $cadena_entrante;
        $cadena = utf8_decode($cadena);
        $cadena = str_replace('.*-*.br .*-*.', '<br>', $cadena);
        $cadena = str_replace('.*-*.b .*-*.', '<b>', $cadena);
        return trim(utf8_decode($cadena));
    }

    function cifrar($string, $key) {
	   $result = '';
	   for($i=0; $i<strlen($string); $i++) {
	      $char = substr($string, $i, 1);
	      $keychar = substr($key, ($i % strlen($key))-1, 1);
	      $char = chr(ord($char)+ord($keychar));
	      $result.=$char;
	   }
	   return base64_encode($result);
	}


    $data = $soapclient->ConsultaExterna_getDetalleCita_Agenda($_GET['id_cita'], $_GET['centro_sal'], $wsClave);
    $data = utf8_encode($data);
    $data = str_replace('<br />', '.*-*.br .*-*.', $data);
    $data = str_replace('<br/>', '.*-*.br .*-*.', $data);
    $data = str_replace('<br>', '.*-*.br .*-*.', $data);

    $data = str_replace('<b>', '.*-*.b .*-*.', $data);

    $data = str_replace('<----', '----', $data);
    $data = str_replace('---->', '----', $data);
    $data = str_replace('<INSPECCION GENERAL>', 'INSPECCION GENERAL', $data);
    

    $data = new SimpleXMLElement($data);
    $nota = $data->respuesta;
    //print_r($nota);
    $ordfecha = explode('/',$nota->ordfecha);

    $firma = cifrar( $nota->id_cita.','.$nota->centrosaludagenda.','.$nota->paciente , $var->getKeySession());


  if(isset($_GET['referencia']))$referencia = $_GET['referencia']; if(isset($_POST['referencia']))$referencia = $_POST['referencia'];
  if ($referencia == '1'){
    $hidden ='hidden'; 
  } else{ $hidden= '';
  }
    
@endphp

<link rel="stylesheet" href="css/bootstrap.css">
<script src="js/jquery-3.1.0.min.js"></script>
<script src="js/notify.js"></script>

<style type="text/css">
	.page-headerL { font-size: 1.1em; font-weight: bold; border-bottom: 1px solid #3c8cbc; width: 100%; text-align: left;}

	.margenSuperior { margin-top: 5px; }
	.input-group{ margin-top: 5px; }

	.td{ border: 1px solid; border-color: #d2d6de; height: 30px; padding: 5px 10px; line-height: 1.3;}
	    
</style>
		<div class="box box-primary">

			<div class="box-body" id="espAgenda" name="espAgenda" style="width: 95%; margin: 0px auto; margin-top: 40px;">
				<div class="row alinear_centrado">
                    <div class="page-headerL" id="espacioAgenda" name="espacioAgenda">Espacio Agendado</div>
                    <div class="row margenSuperior">

                      <div class="row">
                        <div class="col-sm-4">                                                    	
                          	<table width="100%" {{ $hidden }}>                         		
                          		<tr><td class="input-group-addon" style="background: #eee;">UMED de agenda</td><td class="td">{{$nota->desc_centr}}</td></tr>                          		
                          	</table>

                          	<table width="100%">
                          	<tr>
                          		<td class="input-group-addon" style="background: #eee;">Urgente</td><td class="td" style="width: 50px;">{{$nota->es_urgente}}</td>
                          		<td class="input-group-addon" style="background: #eee;">Consultorio</td><td class="td" style="width: 50px;">{{$nota->consultorio}}</td>
                          		<td class="input-group-addon" style="background: #eee;">Modulo</td><td class="td" style="width: 50px;"><?php if($nota->no_modulo!='') echo $nota->no_modulo; else echo 'N/D'; ?></td>
                          		<td class="input-group-addon" style="background: #eee;">Consulta</td><td class="td">{{$nota->tipodeconsulta}}</td>
                          	</tr></table>

                          	<table width="100%">
                          	<tr>
                          		<td class="input-group-addon" style="background: #eee; width: 25%;">Especialidad</td><td class="td"><?= utf8_decode(utf8_decode($nota->especialidad)) ?></td>
                          		<td class="input-group-addon" style="background: #eee; width: 25%;">Fecha y hora</td><td class="td">{!! $nota->fecha_cita !!}</td>

                          	</tr></table>

                          	<table width="100%">
                          		<tr><td class="input-group-addon" style="background: #eee;">Paciente</td><td class="td"><?= utf8_decode(utf8_decode($nota->paciente)) ?></td></tr>
                          		<tr><td class="input-group-addon" style="background: #eee;">M{{'é'}}dico</td><td class="td"><?= utf8_decode(utf8_decode($nota->medico)) ?></td></tr>
                          	</table>


                        </div>
                      </div>

                      <div style="width: 97%;">
                        <div style="position: relative; text-align: right; font-weight: 600; margin-top: 5px;">{{ date("d") . "/" . date("m") . "/" . date("Y"). ' ' . date("H") . ':' . date("i") }}</div>                          
                      </div>
                      <div style="width: 97%;">
                      	<div style="position: relative; text-align: center; margin-top: 5px;">{{$firma}}</div>
                      </div>

                      

                    </div>
                </div>
            </div>
		</div>

