<?php
@session_start();
class Xado extends MX_Controller{
	public function __construct(){
		if(!isset($_SESSION["app.gxc_sesion_id"]) || $_SESSION["app.gxc_sesion_id"]==0){
 			header('Location: '.base_url().'main/no_conectado');
 		}
		parent::__construct();
		$this->load->model('movimientos/xado_model');
		$this->load->model('seguridad/xppo_model');
		date_default_timezone_set('America/Lima');
	}

	public function insertar_listar_cart(){
		$cod 	= $this->input->post('d2');
		$desc 	= $this->input->post('d3');
		if($cod!='0')
			$_SESSION['app.gxc_sesion_xado'][$cod] 	= array('cod' => $cod, 'desc' => $desc);
		$array 	= $_SESSION['app.gxc_sesion_xado'];
		$html 	= '';
		foreach ($array as $row) {
			$html.= '
				<tr>
					<td>'.$row['cod'].'</td>
					<td>'.$row['desc'].'</td>
					<td>
						<a href="javascript:fn_xado_eliminar(\''.$row['cod'].'\',\''.$row['cod'].'\',\''.$row['desc'].'\');" class="btn btn-danger btn-xs">
							<span class="glyphicon glyphicon-trash"></span> <b>Eliminar</b>
						</a>
					</td>
				</tr>
			';
		}
		echo json_encode(array($html));
	}

	public function insertar_listar(){
		$xan 	= $this->input->post('d1');
		$xdo 	= $this->input->post('d2');
		/*$data 	= array('diag_codigo' 	=> $xdo,
						'ate_id'		=> $xan);*/
		if($xdo!='0')
			$this->xado_model->insertar($xdo, $xan);
		$ds 	= $this->xado_model->listar($xan);
		$html 	= '';
		foreach ($ds->result() as $row) {
			$html.= '
				<tr>
					<td>'.$row->diag_codigo.'</td>
					<td>'.$row->diag_descripcion.'</td>
					<td>
						<a href="javascript:fn_xado_eliminar(\''.$row->atdx_id.'\',\''.$row->diag_codigo.'\',\''.$row->diag_descripcion.'\');" class="btn btn-danger btn-xs">
							<span class="glyphicon glyphicon-trash"></span> <b>Eliminar</b>
						</a>
					</td>
				</tr>
			';
		}
		echo json_encode(array($html));
	}



	/**/

	public function listar_cart(){
		$cod 	= $this->input->post('d2');
		$desc 	= $this->input->post('d3');
		if($cod!=0)
			$_SESSION['app.gxc_sesion_xado'][$cod] 	= array('cod' => $cod, 'desc' => $desc);
		$array 	= $_SESSION['app.gxc_sesion_xado'];
		$html 	= '';
		foreach ($array as $row) {
			$html.= '
				<tr>
					<td>'.$row['cod'].'</td>
					<td>'.$row['desc'].'</td>
					<td>
						<a href="javascript:fn_xado_eliminar(\''.$row['cod'].'\',\''.$row['cod'].'\',\''.$row['desc'].'\');" class="btn btn-danger btn-xs">
							<span class="glyphicon glyphicon-trash"></span> <b>Eliminar</b>
						</a>
					</td>
				</tr>
			';
		}
		echo json_encode(array($html));
	}

	public function listar(){
		$xan 	= $this->input->post('d1');
		$ds 	= $this->xado_model->listar($xan);
		$html 	= '';
		foreach ($ds->result() as $row) {
			$html.= '
				<tr>
					<td>'.$row->diag_codigo.'</td>
					<td>'.$row->diag_descripcion.'</td>
					<td>
						<a href="javascript:fn_xado_eliminar(\''.$row->atdx_id.'\',\''.$row->diag_codigo.'\',\''.$row->diag_descripcion.'\');" class="btn btn-danger btn-xs">
							<span class="glyphicon glyphicon-trash"></span> <b>Eliminar</b>
						</a>
					</td>
				</tr>
			';
		}
		echo json_encode(array($html));
	}

	public function insertar_cart(){
		$cod 	= $this->input->post('d1');
		$desc 	= $this->input->post('d3');
		$_SESSION['app.gxc_sesion_xado'][$cod] 	= array('cod' => $cod, 'desc' => $desc);
		echo 	0;
	}

	public function insertar(){
		$xdo 	= $this->input->post('d1');
		$xan 	= $this->input->post('d2');
		/*$data 	= array('diag_codigo' 	=> $xdo,
						'ate_id'		=> $xan);*/
		$this->xado_model->insertar($xdo, $xan);
		echo 	0;
	}

	public function eliminar_cart(){
		$cod 	= $this->input->post('d1');
		unset($_SESSION['app.gxc_sesion_xado'][$cod]);
		echo 	0;
	}

	public function eliminar(){
		$id 	= $this->input->post('d1');
		$this->xado_model->eliminar($id);
		echo 	0;
	}
}