</div>
  <div class="modal-body">
 	<!-- Evaluar politicas de cancelación -->
 	<?php 
    $Glaformulacion = HistorialFormulacion::model()->findAll("paciente_id = {$model->id}");
    foreach ($Glaformulacion as $Gla_formulacion) {
        echo "<b>Fecha: </b><span class='label label-info'>" . Yii::app()->dateformatter->format("yyyy-MM-dd", $Gla_formulacion->fecha) . "</span>";
        ?>
 		<table class="table table-striped">
			<tr>
				<th>Formula</th>
				<th>Formulación</th>
			</tr>
		
		<?php 
        $GlasFormulas = HistorialFormulacionDetalle::model()->findAll("historial_formulacion_id = {$Gla_formulacion->id}");
        foreach ($GlasFormulas as $Glas_formulas) {
            ?>
				<tr>
					<?php 
            if ($Glas_formulas->formulacion_id != "") {
                ?>
					<td><?php 
                echo $Glas_formulas->laformulacion->nombre;
                ?>
</td>
						<?php 
            } else {
                ?>
					<td><?php 
                echo $Glas_formulas->otra_formulacion;
<?php

//Detalles
$numFormulacion = $_GET['id'];
$laFormulacion = HistorialFormulacion::model()->findByPk($numFormulacion);
$detalleFormulacion = HistorialFormulacionDetalle::model()->findAll("historial_formulacion_id = {$numFormulacion}");
?>

			<style type="text/css">
				#parrafo{
					padding: 0px 50px 0px 0px 
				}
				#cuerpo{
				   font-size: 70%;
				}
			
			</style>

<div id="cuerpo" style="background-image: url(images/m_horizontal_presupuesto.jpg); background-repeat: no-repeat; height:100%; width:100%; padding:0px 0px 0px 50px;">			
<!-- <div style="height:175px"></div> -->
<div style="padding:150px 0px 0px 0px;">
<h4>Formulaciones</h4>

<p id="parrafo">Paciente: <?php 
echo "<b>" . $laFormulacion->paciente->nombreCompleto . "</b>";
?>
</p>
<p id="parrafo">Medico: <?php 
echo "<b>" . $laFormulacion->personal->nombreCompleto . "</b>";
?>
</p>
<?php

/* @var $this HistorialFormulacionController */
/* @var $model HistorialFormulacion */
/* @var $form CActiveForm */
?>

<?php 
$elPaciente = $model->paciente_id;
$paciente = Paciente::model()->find("id={$elPaciente}");
$formulaciones = Formulacion::model()->findAll(array("condition" => "id > 0", 'order' => 'nombre asc'));
$registros = HistorialFormulacionDetalle::model()->findAll("historial_formulacion_id = {$model->id}");
?>
<div class="row">
		<h4 class="text-center">Datos de Paciente</h4>
		<div class="span1"></div>
		<div class="span5">
			<?php 
$this->widget('zii.widgets.CDetailView', array('data' => $paciente, 'attributes' => array('nombreCompleto', 'n_identificacion', 'edad')));
?>
		</div>
		<div class="span5">
			<?php 
$this->widget('zii.widgets.CDetailView', array('data' => $paciente, 'attributes' => array('email', 'telefono1', 'celular')));
?>
		</div>
		<div class="span1"></div>
	</div>

<div class="row text-center">
	<div class="span12">
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return HistorialFormulacionDetalle the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = HistorialFormulacionDetalle::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 public function actionActualizarFormulacion()
 {
     $model = HistorialFormulacion::model()->findByPk($_GET['id']);
     if (isset($_GET['idCita'])) {
         $idCita = $_GET['idCita'];
     } else {
         $idCita = null;
     }
     $model->paciente_id = $_GET['idPaciente'];
     $model->personal_id = Yii::app()->user->usuarioId;
     $model->cita_id = $idCita;
     $model->fecha = date("Y-m-d");
     if ($model->save()) {
         $detalleP = HistorialFormulacionDetalle::model()->findAll("historial_formulacion_id = {$model->id}");
         foreach ($detalleP as $detalle_P) {
             $detalle_P->delete();
         }
         $eltotal = 0;
         for ($i = 0; $i <= $_POST['variable']; $i++) {
             //$x = $i+1;
             //
             if (isset($_POST['formula_' . $i])) {
                 $detalleP = new HistorialFormulacionDetalle();
                 $detalleP->historial_formulacion_id = $model->id;
                 $detalleP->otra_formulacion = $_POST['otra_' . $i];
                 $detalleP->formulacion_id = $_POST['formula_' . $i];
                 $detalleP->formulacion = $_POST['formulacion_' . $i];
                 $detalleP->save();
             }
         }
         $this->redirect(array('view', 'id' => $model->id));
     }
     //}
     // $this->render('create',array(
     // 	'model'=>$model,
     // ));
 }