<?php
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
// brain  : Cristian Fernandez O.
// e-mail : cristian.fernandez@factobyte.cl
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
// requiere sesion : Si
   session_start();
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
// ruta a la raiz del sistema:
   $ruta_raiz = "";
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
// asociacion de archivos externos a la pagina:
   include("soul/inc_soul.php");
//***********************************************************************************************
//***********************************************************************************************

tagHead($ruta_raiz, "Nuevo programa");
tagBody();

//cabecera del sitio
generaCabeceraSistema($ruta_raiz);

if (!validaInicioSesion()){
	//acceso no autorizado
	redireccionaAccesoNoAutorizado($ruta_raiz);
}
elseif (!validaPrivilegiosAcceso("sis_programas_nuevo")){
	//no tiene privilegios de acceso
	redireccionaSinPrivilegiosAcceso($ruta_raiz);
}
else {
	//banner de sistema
	generaCabeceraSistemaBanner($ruta_raiz, 0, "ADMINISTRACI&Oacute;N");

	?>

	<div id="contenidos">
		<div id="contenidos-content">

			<h1>NUEVO PROGRAMA</h1>
			<hr class="linea_titulo">
			<br>
			
			<?
			//------------------------------------------
			// se reciben datos enviados
			//------------------------------------------
			$req_imglast = $_REQUEST["txt_imglast"];
			$req_img1 = $_REQUEST["txt_img1"];
			$req_img2 = $_REQUEST["txt_img2"];
			$req_img3 = $_REQUEST["txt_img3"];
			$req_img4 = $_REQUEST["txt_img4"];
			$req_img5 = $_REQUEST["txt_img5"];
			$req_img6 = $_REQUEST["txt_img6"];
			$req_img7 = $_REQUEST["txt_img7"];
			$req_img8 = $_REQUEST["txt_img8"];
			$req_img9 = $_REQUEST["txt_img9"];
			$req_img10 = $_REQUEST["txt_img10"];
			
			if ((!empty($_REQUEST["a"])) || (empty($_REQUEST["txt_nombre"])) || (!empty($_FILES["file_img1"]["tmp_name"])) || (!empty($_FILES["file_img2"]["tmp_name"])) || (!empty($_FILES["file_img3"]["tmp_name"])) || (!empty($_FILES["file_img4"]["tmp_name"])) || (!empty($_FILES["file_img5"]["tmp_name"])) || (!empty($_FILES["file_img6"]["tmp_name"])) || (!empty($_FILES["file_img7"]["tmp_name"])) || (!empty($_FILES["file_img8"]["tmp_name"])) || (!empty($_FILES["file_img9"]["tmp_name"])) || (!empty($_FILES["file_img10"]["tmp_name"]))) {
				//------------------------------------------
				// se desplega formulario
				//------------------------------------------
				if (!empty($_REQUEST["codmensaje"])){
					//mensaje de sistema
					switch ($_REQUEST["codmensaje"]){
				    case 1:
				    	//faltan datos requeridos
			        echo "<h6>&iexcl; DEBE INGRESAR TODOS LOS DATOS REQUERIDOS !</h6>";
							echo "<p class=\"contenidos-texto-centrado\">Inténtalo nuevamente</p>";
			        break;

				    case 2:
				    	//error en cantidad de dias-noches
			        echo "<h6>&iexcl; LA CANTIDAD DE NOCHES NO PUEDE SER SUPERIOR A LOS DÍAS !</h6>";
							echo "<p class=\"contenidos-texto-centrado\">Inténtalo nuevamente</p>";
			        break;

					}
					echo "<br>";
				}
				
				//se procesan posibles datos traspasados y acciones solicitadas
				
				//clave del programa
				$cod_programa = generaClavePrimariaNumerica();
				if (!empty($_REQUEST["coditem"]))
					$cod_programa = $_REQUEST["coditem"];

				//conexion a bdd
				$id_conexion = abreConeccionBdd();

				if (!empty($_REQUEST["a"])){
					if ($_REQUEST["a"] == "i"){
						//se solicita insertar
						
						if ($_REQUEST["q"] == "menu"){
							//construccion del script
							$script = "INSERT INTO fb_programa_menu VALUES(".$cod_programa.", ".$_REQUEST["id"].")";

							//ejecucion del script
							mysql_query($script, $id_conexion);
						}
					}
					elseif ($_REQUEST["a"] == "d"){
						//se solicita eliminar
						
						if ($_REQUEST["q"] == "menu"){
							//construccion del script
							$script = "DELETE FROM fb_programa_menu WHERE (promen_codigo_programa = ".$cod_programa.") AND (promen_codigo_menu = ".$_REQUEST["id"].")";

							//ejecucion del script
							mysql_query($script, $id_conexion);
						}
					}
				}

				//cierre conexion a bdd
				cierraConeccionBdd($id_conexion);
				
				?>
				<h3>INGRESE LOS SIGUIENTES DATOS PARA CREAR UN NUEVO PROGRAMA</h3>
				<p class="contenidos-texto-centrado">Dato (requerido) no es opcional</p>
				<br>

				<div id="contenidos-formulario">
					<form id="form" method="post" enctype="multipart/form-data">
					<input type="hidden" name="coditem" value="<?= $cod_programa ?>">
					<input type="hidden" name="a" id="a" value="">
					<input type="hidden" name="q" id="q" value="">
					<input type="hidden" name="id" id="id" value="">

					<h2>IMAGENES PROGRAMA</h2>
					<?

					//imagenes de galeria
					$img_tmp1 = asignaImgPrograma(procesaImgsPrograma(1), $req_img1);
					$img_tmp2 = asignaImgPrograma(procesaImgsPrograma(2), $req_img2);
					$img_tmp3 = asignaImgPrograma(procesaImgsPrograma(3), $req_img3);
					$img_tmp4 = asignaImgPrograma(procesaImgsPrograma(4), $req_img4);
					$img_tmp5 = asignaImgPrograma(procesaImgsPrograma(5), $req_img5);
					$img_tmp6 = asignaImgPrograma(procesaImgsPrograma(6), $req_img6);
					$img_tmp7 = asignaImgPrograma(procesaImgsPrograma(7), $req_img7);
					$img_tmp8 = asignaImgPrograma(procesaImgsPrograma(8), $req_img8);
					$img_tmp9 = asignaImgPrograma(procesaImgsPrograma(9), $req_img9);
					$img_tmp10 = asignaImgPrograma(procesaImgsPrograma(10), $req_img10);
					
					//ultima imagen cargada
					$img_last = "soul/imgs/progrs/default.jpg";
					if (!empty($req_imglast)){
						switch ($req_imglast){
					    case 1:
									$img_last = $img_tmp1;
					        break;
					    case 2:
									$img_last = $img_tmp2;
					        break;
					    case 3:
									$img_last = $img_tmp3;
					        break;
					    case 4:
									$img_last = $img_tmp4;
					        break;
					    case 5:
									$img_last = $img_tmp5;
					        break;
					    case 6:
									$img_last = $img_tmp6;
					        break;
					    case 7:
									$img_last = $img_tmp7;
					        break;
					    case 8:
									$img_last = $img_tmp8;
					        break;
					    case 9:
									$img_last = $img_tmp9;
					        break;
					    case 10:
									$img_last = $img_tmp10;
					        break;
						}		
					}
					?>

					<p class="contenidos-texto-centrado">Opcional. Debe ser m&iacute;nimo de 1.200 pxls. de ancho o 500 pxls. de alto<?= consultaValorMaxUploadFileSize() ?>, en formato .jpg</p>
					<h3>Galer&iacute;a de im&aacute;genes asociada al programa:</h3>
					<div class="programas-imgprog"><img src="<?= $img_last ?>" alt="programa" id="programas-imgprogpreview"></div>
					<input type="hidden" name="txt_imglast" id="txt_imglast" value="">
					
					<div id="programas-divimgsprog">
						<div class="programas-divimgprog">
							<center><img src="<?= $img_tmp1 ?>" id="programas-imgpreview1" class="programas-imgthumbprog" onclick="document.getElementById('programas-imgprogpreview').src='<?= $img_tmp1 ?>'"></center>
							<input type="hidden" name="txt_img1" id="txt_img1" value="<?= $img_tmp1 ?>">
							<label class="form-file-img-prog">
						    IMG1
						    <input type="file" name="file_img1" id="file_img1" accept="image/jpeg, image/jpg">
							</label>
							<center><button type="button" class="boton_imgquitar" onclick="imgGaleriaProQuitar(1)" title="Quitar esta imagen">[x]</button></center>
						</div>
						<div class="programas-divimgprog">
							<center><img src="<?= $img_tmp2 ?>" id="programas-imgpreview2" class="programas-imgthumbprog" onclick="document.getElementById('programas-imgprogpreview').src='<?= $img_tmp2 ?>'"></center>
							<input type="hidden" name="txt_img2" id="txt_img2" value="<?= $img_tmp2 ?>">
							<label class="form-file-img-prog">
						    IMG2
						    <input type="file" name="file_img2" id="file_img2" accept="image/jpeg, image/jpg">
							</label>
							<center><button type="button" class="boton_imgquitar" onclick="imgGaleriaProQuitar(2)" title="Quitar esta imagen">[x]</button></center>
						</div>
						<div class="programas-divimgprog">
							<center><img src="<?= $img_tmp3 ?>" id="programas-imgpreview3" class="programas-imgthumbprog" onclick="document.getElementById('programas-imgprogpreview').src='<?= $img_tmp3 ?>'"></center>
							<input type="hidden" name="txt_img3" id="txt_img3" value="<?= $img_tmp3 ?>">
							<label class="form-file-img-prog">
						    IMG3
						    <input type="file" name="file_img3" id="file_img3" accept="image/jpeg, image/jpg">
							</label>
							<center><button type="button" class="boton_imgquitar" onclick="imgGaleriaProQuitar(3)" title="Quitar esta imagen">[x]</button></center>
						</div>
						<div class="programas-divimgprog">
							<center><img src="<?= $img_tmp4 ?>" id="programas-imgpreview4" class="programas-imgthumbprog" onclick="document.getElementById('programas-imgprogpreview').src='<?= $img_tmp4 ?>'"></center>
							<input type="hidden" name="txt_img4" id="txt_img4" value="<?= $img_tmp4 ?>">
							<label class="form-file-img-prog">
						    IMG4
						    <input type="file" name="file_img4" id="file_img4" accept="image/jpeg, image/jpg">
							</label>
							<center><button type="button" class="boton_imgquitar" onclick="imgGaleriaProQuitar(4)" title="Quitar esta imagen">[x]</button></center>
						</div>
						<div class="programas-divimgprog">
							<center><img src="<?= $img_tmp5 ?>" id="programas-imgpreview5" class="programas-imgthumbprog" onclick="document.getElementById('programas-imgprogpreview').src='<?= $img_tmp5 ?>'"></center>
							<input type="hidden" name="txt_img5" id="txt_img5" value="<?= $img_tmp5 ?>">
							<label class="form-file-img-prog">
						    IMG5
						    <input type="file" name="file_img5" id="file_img5" accept="image/jpeg, image/jpg">
							</label>
							<center><button type="button" class="boton_imgquitar" onclick="imgGaleriaProQuitar(5)" title="Quitar esta imagen">[x]</button></center>
						</div>
						<div class="programas-divimgprog">
							<center><img src="<?= $img_tmp6 ?>" id="programas-imgpreview6" class="programas-imgthumbprog" onclick="document.getElementById('programas-imgprogpreview').src='<?= $img_tmp6 ?>'"></center>
							<input type="hidden" name="txt_img6" id="txt_img6" value="<?= $img_tmp6 ?>">
							<label class="form-file-img-prog">
						    IMG6
						    <input type="file" name="file_img6" id="file_img6" accept="image/jpeg, image/jpg">
							</label>
							<center><button type="button" class="boton_imgquitar" onclick="imgGaleriaProQuitar(6)" title="Quitar esta imagen">[x]</button></center>
						</div>
						<div class="programas-divimgprog">
							<center><img src="<?= $img_tmp7 ?>" id="programas-imgpreview7" class="programas-imgthumbprog" onclick="document.getElementById('programas-imgprogpreview').src='<?= $img_tmp7 ?>'"></center>
							<input type="hidden" name="txt_img7" id="txt_img7" value="<?= $img_tmp7 ?>">
							<label class="form-file-img-prog">
						    IMG7
						    <input type="file" name="file_img7" id="file_img7" accept="image/jpeg, image/jpg">
							</label>
							<center><button type="button" class="boton_imgquitar" onclick="imgGaleriaProQuitar(7)" title="Quitar esta imagen">[x]</button></center>
						</div>
						<div class="programas-divimgprog">
							<center><img src="<?= $img_tmp8 ?>" id="programas-imgpreview8" class="programas-imgthumbprog" onclick="document.getElementById('programas-imgprogpreview').src='<?= $img_tmp8 ?>'"></center>
							<input type="hidden" name="txt_img8" id="txt_img8" value="<?= $img_tmp8 ?>">
							<label class="form-file-img-prog">
						    IMG8
						    <input type="file" name="file_img8" id="file_img8" accept="image/jpeg, image/jpg">
							</label>
							<center><button type="button" class="boton_imgquitar" onclick="imgGaleriaProQuitar(8)" title="Quitar esta imagen">[x]</button></center>
						</div>
						<div class="programas-divimgprog">
							<center><img src="<?= $img_tmp9 ?>" id="programas-imgpreview9" class="programas-imgthumbprog" onclick="document.getElementById('programas-imgprogpreview').src='<?= $img_tmp9 ?>'"></center>
							<input type="hidden" name="txt_img9" id="txt_img9" value="<?= $img_tmp9 ?>">
							<label class="form-file-img-prog">
						    IMG9
						    <input type="file" name="file_img9" id="file_img9" accept="image/jpeg, image/jpg">
							</label>
							<center><button type="button" class="boton_imgquitar" onclick="imgGaleriaProQuitar(9)" title="Quitar esta imagen">[x]</button></center>
						</div>
						<div class="programas-divimgprog">
							<center><img src="<?= $img_tmp10 ?>" id="programas-imgpreview10" class="programas-imgthumbprog" onclick="document.getElementById('programas-imgprogpreview').src='<?= $img_tmp10 ?>'"></center>
							<input type="hidden" name="txt_img10" id="txt_img10" value="<?= $img_tmp10 ?>">
							<label class="form-file-img-prog">
						    IMG10
						    <input type="file" name="file_img10" id="file_img10" accept="image/jpeg, image/jpg">
							</label>
							<center><button type="button" class="boton_imgquitar" onclick="imgGaleriaProQuitar(10)" title="Quitar esta imagen">[x]</button></center>
						</div>
						<div id="anula-float"></div>
					</div>
					<div id="anula-float"></div>
					<br>

					<h2>DATOS PROGRAMA</h2>
					<p>Sección de menú (requerido):</p>
					<? generaComboMenuOpciones("cmb_menu", "cmb_menu", -1, true, "", "", false, "", false, false) ?>

					<div class="contenidos-programa-info">
						<p><b>Estos son los men&uacute; seleccionados por t&iacute;</b>. (Presiona "<b>X</b>" para eliminar un &iacute;tem)</p>
					</div>
					<?
					//conexion a bdd
					$id_conexion = abreConeccionBdd();
				
					//construccion del script
					$script = "SELECT promen_codigo_menu, mensub_codigo_submenu, mensub_descripcion FROM fb_programa_menu, fb_menu_sub WHERE (promen_codigo_menu = mensub_codigo_submenu) AND (promen_codigo_programa = ".$cod_programa.") ORDER BY UPPER(mensub_descripcion)";

					//ejecucion del script
					$resultado_script = mysql_query($script, $id_conexion);
					
					if (mysql_num_rows($resultado_script) == 0){
						//no existen resultados
						?>
						<div class="contenidos-scort-tagservicio"><p>&nbsp;* NO TIENES MEN&Uacute;S ASOCIADOS *&nbsp;</p></div>
						<?
					}
					else {
						//se muestran resultados
						while ($row = mysql_fetch_array($resultado_script)){
							?>
							<div class="contenidos-programa-menu"><p>&nbsp;<?= $row['mensub_descripcion'] ?>&nbsp;</p> <button type="button" class="contenidos-boton-quitar-menu" value="<?= $row['mensub_codigo_submenu'] ?>" title="Eliminar">X</button> </div>
							<?
						}
					}
					
					//cierre conexion a bdd
					cierraConeccionBdd($id_conexion);	
					?>
					<div id="anula-float"></div>
					<hr class="linea_separacion_gris">
					<br>
							
					<?
					$request_value = "";
					if (!empty($_REQUEST["txt_nombre"]))
						$request_value = $_REQUEST["txt_nombre"];
					?>
					<p>Nombre programa (requerido):</p>
					<input type="text" name="txt_nombre" id="txt_nombre" class="txt_programa" maxlength="200" placeholder="Nombre" value="<?= $request_value ?>" required />
					
					<?
					$request_value = "";
					if (!empty($_REQUEST["txt_descripcion"]))
						$request_value = $_REQUEST["txt_descripcion"];
					?>
					<p>Descripción programa (requerido):</p>
					<textarea name="txt_descripcion" id="txt_descripcion" class="txt_descripcion_long" placeholder="Descripción" required><?= $request_value ?></textarea>
					
					<p>Programa descargable en archivo PDF (opcional):</p>
					<div id="contenidos-programa-pdf"></div>
					<label class="form-file">
				    SELECCIONAR&nbsp;PDF
				    <input type="file" name="file_pdf" id="file_pdf" accept="application/pdf">
					</label>
					<br>
			    
					<?
					$request_value = "";
					if (!empty($_REQUEST["txt_mapa"]))
						$request_value = $_REQUEST["txt_mapa"];
					?>
					<p>Mapa de ubicación de Google Maps (Opcional. Debe copiar url desde maps.google.com opción COMPARTIR > Insertar un mapa > COPIAR HTML, y pegar acá. Si pega código erróneo arrojará error):</p>
					<textarea name="txt_mapa" id="txt_mapa" class="" placeholder="URL mapa Google Maps"><?= $request_value ?></textarea>
					
					<?
					$request_value = "";
					if (!empty($_REQUEST["txt_cant_dias"]))
						$request_value = $_REQUEST["txt_cant_dias"];
					?>
					<p>Cantidad de días (requerido):</p>
					<input type="number" name="txt_cant_dias" id="txt_cant_dias" maxlength="3" min="0" max="999" pattern="[0-9]{1,3}" title="Solo se permiten números. Mínimo 1 dígito. Máximo 3 dígitos" placeholder="Días" value="<?= $request_value ?>" required />
					
					<?
					$request_value = "";
					if (!empty($_REQUEST["txt_cant_noches"]))
						$request_value = $_REQUEST["txt_cant_noches"];
					?>
					<p>Cantidad de noches (requerido):</p>
					<input type="number" name="txt_cant_noches" id="txt_cant_noches" maxlength="3" min="0" max="999" pattern="[0-9]{1,3}" title="Solo se permiten números. Mínimo 1 dígito. Máximo 3 dígitos" placeholder="Noches" value="<?= $request_value ?>" required />

					<?
					$request_value = -1;
					if (!empty($_REQUEST["cmb_incvuelo"]))
						$request_value = $_REQUEST["cmb_incvuelo"];
					?>
					<p>&iquest; Incluye vuelo ? (requerido):</p>
					<? generaComboIncluyeVuelo("cmb_incvuelo", "cmb_incvuelo", $request_value, true, "", "", false, "", true, false) ?>

					<?
					$request_value = -1;
					if (!empty($_REQUEST["cmb_inctraslado"]))
						$request_value = $_REQUEST["cmb_inctraslado"];
					?>
					<p>&iquest; Incluye traslado ? (requerido):</p>
					<? generaComboIncluyeTraslado("cmb_inctraslado", "cmb_inctraslado", $request_value, true, "", "", false, "", true, false) ?>

					<?
					$request_value = -1;
					if (!empty($_REQUEST["cmb_inchotel"]))
						$request_value = $_REQUEST["cmb_inchotel"];
					?>
					<p>&iquest; Incluye hotel ? (requerido):</p>
					<? generaComboIncluyeHotel("cmb_inchotel", "cmb_inchotel", $request_value, true, "", "", false, "", true, false) ?>

					<?
					$request_value = -1;
					if (!empty($_REQUEST["cmb_incalimentacion"]))
						$request_value = $_REQUEST["cmb_incalimentacion"];
					?>
					<p>&iquest; Incluye alimentación ? (requerido):</p>
					<? generaComboIncluyeAlimentacion("cmb_incalimentacion", "cmb_incalimentacion", $request_value, true, "", "", false, "", true, false) ?>

					<?
					$request_value = -1;
					if (!empty($_REQUEST["cmb_incseguroviaje"]))
						$request_value = $_REQUEST["cmb_incseguroviaje"];
					?>
					<p>&iquest; Incluye seguro de viaje ? (requerido):</p>
					<? generaComboIncluyeSeguroViaje("cmb_incseguroviaje", "cmb_incseguroviaje", $request_value, true, "", "", false, "", true, false) ?>

					<?
					$request_value = -1;
					if (!empty($_REQUEST["cmb_incexcursiones"]))
						$request_value = $_REQUEST["cmb_incexcursiones"];
					?>
					<p>&iquest; Incluye excursiones ? (requerido):</p>
					<? generaComboIncluyeExcursiones("cmb_incexcursiones", "cmb_incexcursiones", $request_value, true, "", "", false, "", true, false) ?>

					<?
					$request_value = -1;
					if (!empty($_REQUEST["cmb_inccrucero"]))
						$request_value = $_REQUEST["cmb_inccrucero"];
					?>
					<p>&iquest; Incluye crucero ? (requerido):</p>
					<? generaComboIncluyeCrucero("cmb_inccrucero", "cmb_inccrucero", $request_value, true, "", "", false, "", true, false) ?>

					<p>Moneda asociada (requerido):</p>
					<? generaComboDivisasPrograma("cmb_moneda", "cmb_moneda", -1, true, "", "", false, "", true, false) ?>
					<div id="anula-float"></div>

					<p>Valor del programa (requerido):</p>
					<div id="programa-valor-mnsj">
						<p><b>* Seleccione moneda asociada</b><br><br></p>
					</div>
					<div id="programa-valor-clp">
						<input type="number" name="txt_precio_clp" id="txt_precio_clp" value="0" maxlength="9" min="0" max="999999999" step="1" pattern="[0-9]{1,9}" title="Solo se permiten números. Mínimo 1 dígito. Máximo 9 dígitos" placeholder="Valor en CLP" value="<?= $request_value ?>" required />
					</div>
					<div id="programa-valor-usd">
						<input type="number" name="txt_precio_usd" id="txt_precio_usd" value="0" maxlength="9" min="0" max="999999999" step="any" pattern="[0-9]{1,}" placeholder="Valor en USD" value="<?= $request_value ?>" required />
					</div>
					
					<?
					$request_value = -1;
					if (!empty($_REQUEST["cmb_modalidad_pago"]))
						$request_value = $_REQUEST["cmb_modalidad_pago"];
					?>
					<p>Modalidad valor (requerido):</p>
					<? generaComboProgramaModalidadPago("cmb_modalidad_pago", "cmb_modalidad_pago", $request_value, true, "", "", false, "", true, false) ?>
					<div id="anula-float"></div>
					
					<?
					$request_value = -1;
					if (!empty($_REQUEST["cmb_condiciones"]))
						$request_value = $_REQUEST["cmb_condiciones"];
					?>
					<p>Condiciones (opcional):</p>
					<? generaComboCondicionesPrograma("cmb_condiciones", "cmb_condiciones", $request_value, true, "", "", false, "", false, false) ?>
					
					<?
					$request_value = -1;
					if (!empty($_REQUEST["cmb_destacado"]))
						$request_value = $_REQUEST["cmb_destacado"];
					?>
					<p>&iquest; Clasificar como destacado ? (requerido):</p>
					<? generaComboProgramaDestacado("cmb_destacado", "cmb_destacado", $request_value, true, "", "", false, "", true, false) ?>

					<!--
					<p>&iquest; Clasificar como oferta ? (requerido):</p>
					<? generaComboProgramaOferta("cmb_oferta", "cmb_oferta", -1, true, "", "", false, "", true, false) ?>
					-->

					<button type="submit" class="boton_principal">CREAR &raquo;</button>
					</form>
					<div id="anula-float"></div>
				</div>
				<?
			}
			else {
				//------------------------------------------
				// se procesan datos recibidos
				//------------------------------------------
				//$req_menu = $_REQUEST["cmb_menu"];
				$req_nombre = mb_strtoupper(trim($_REQUEST["txt_nombre"]));
				$req_descripcion = trim($_REQUEST["txt_descripcion"]);
				$req_mapa = trim($_REQUEST["txt_mapa"]);
				$req_cant_dias = trim($_REQUEST["txt_cant_dias"]);
				$req_cant_noches = trim($_REQUEST["txt_cant_noches"]);
				$req_incvuelo = $_REQUEST["cmb_incvuelo"];
				$req_inctraslado = $_REQUEST["cmb_inctraslado"];
				$req_inchotel = $_REQUEST["cmb_inchotel"];
				$req_incalimentacion = $_REQUEST["cmb_incalimentacion"];
				$req_incseguroviaje = $_REQUEST["cmb_incseguroviaje"];
				$req_incexcursiones = $_REQUEST["cmb_incexcursiones"];
				$req_inccrucero = $_REQUEST["cmb_inccrucero"];
				$req_moneda = $_REQUEST["cmb_moneda"];
				$req_precio_clp = trim($_REQUEST["txt_precio_clp"]);
				$req_precio_usd = trim($_REQUEST["txt_precio_usd"]);
				$req_modalidad_pago = $_REQUEST["cmb_modalidad_pago"];
				$req_condiciones = $_REQUEST["cmb_condiciones"];
				$req_destacado = $_REQUEST["cmb_destacado"];
				//$req_oferta = $_REQUEST["cmb_oferta"];

				//ajuste cantidad dias-noches para que pase validacion con valor 0
				if ($req_cant_dias == 0)
					$req_cant_dias = -1;
				if ($req_cant_noches == 0)
					$req_cant_noches = -1;
				
				//ajuste valor programa para que pase validacion con valor 0
				if ($req_precio_clp == 0)
					$req_precio_clp = -1;
				if ($req_precio_usd == 0)
					$req_precio_usd = -1;

				//if ((empty($req_menu)) || (empty($req_nombre)) || (empty($req_descripcion)) || (empty($req_cant_dias)) || (empty($req_cant_noches)) || (empty($req_incvuelo)) || (empty($req_inctraslado)) || (empty($req_inchotel)) || (empty($req_incalimentacion)) || (empty($req_incseguroviaje)) || (empty($req_incexcursiones)) || (empty($req_inccrucero)) || (empty($req_moneda)) || ((empty($req_precio_clp)) && (empty($req_precio_usd))) || (empty($req_modalidad_pago)) || (empty($req_destacado)) || (empty($req_oferta))){
				//if ((empty($req_menu)) || (empty($req_nombre)) || (empty($req_descripcion)) || (empty($req_cant_dias)) || (empty($req_cant_noches)) || (empty($req_incvuelo)) || (empty($req_inctraslado)) || (empty($req_inchotel)) || (empty($req_incalimentacion)) || (empty($req_incseguroviaje)) || (empty($req_incexcursiones)) || (empty($req_inccrucero)) || (empty($req_moneda)) || ((empty($req_precio_clp)) && (empty($req_precio_usd))) || (empty($req_modalidad_pago)) || (empty($req_destacado))){
				if ((empty($req_nombre)) || (empty($req_descripcion)) || (empty($req_cant_dias)) || (empty($req_cant_noches)) || (empty($req_incvuelo)) || (empty($req_inctraslado)) || (empty($req_inchotel)) || (empty($req_incalimentacion)) || (empty($req_incseguroviaje)) || (empty($req_incexcursiones)) || (empty($req_inccrucero)) || (empty($req_moneda)) || ((empty($req_precio_clp)) && (empty($req_precio_usd))) || (empty($req_modalidad_pago)) || (empty($req_destacado))){
					//faltan datos requeridos
					?>
					<form method="post" name="form">
						<input type="hidden" name="codmensaje" value="1">
					</form>
					<script>document.form.submit()</script>
					<?
				}
				elseif (($req_cant_dias != -1) && ($req_cant_noches > $req_cant_dias)){
					//error en cantidad de dias-noches
					?>
					<form method="post" name="form">
						<input type="hidden" name="codmensaje" value="2">
					</form>
					<script>document.form.submit()</script>
					<?
				}
				else {
					//todo ok, se guarda registro

					//conexion a bdd
					$id_conexion = abreConeccionBdd();
				
					//fecha y hora de sistema
					$fecha_actual = date("Y-m-d");
					$hora_actual = date("H:i:s");
					
					//programa en pdf
					$url_file = "";
					if (is_uploaded_file($_FILES["file_pdf"]["tmp_name"])){
						$url_file = "soul/docs/progs/".generaClavePrimaria().".pdf";
						move_uploaded_file($_FILES["file_pdf"]["tmp_name"], $url_file);
					}
					
					//mapa de google maps
					if (!empty($req_mapa))
						$req_mapa = modificaAnchoAltoMapaGoogleMaps($req_mapa);
					
					if ($req_condiciones == "NO")
						$req_condiciones = 0;
						
					//valor programa
					if ($req_precio_clp == -1)
						$req_precio_clp = 0;
					if ($req_precio_usd == -1)
						$req_precio_usd = 0;

					//construccion del script
					$script = "INSERT 
					INTO fb_programa 
					VALUES(NULL, 
					'".$req_nombre."', 
					\"".$req_descripcion."\", 
					'".$req_mapa."', 
					'".$url_file."', 
					".$req_cant_dias.", 
					".$req_cant_noches.", 
					".$req_precio_clp.", 
					".$req_precio_usd.", 
					'', 
					".$req_incvuelo.", 
					".$req_inctraslado.", 
					".$req_inchotel.", 
					".$req_incalimentacion.", 
					".$req_incseguroviaje.", 
					".$req_incexcursiones.", 
					".$req_inccrucero.", 
					".$req_moneda.", 
					".$req_modalidad_pago.", 
					".$req_condiciones.", 
					".$req_destacado.", 
					14, 
					1, '".$fecha_actual."', '".$hora_actual."', ".$_SESSION["per_codigo_persona"].", '".$fecha_actual."', '".$hora_actual."', ".$_SESSION["per_codigo_persona"].")";

					//ejecucion del script
					mysql_query($script, $id_conexion);
					
					//cierre conexion a bdd
					cierraConeccionBdd($id_conexion);
					
					//imagenes asociadas
					$galeria = false;
					$codigo_programa = consultaCodigoUltPrograma();

					$img_guardada = guardaImgGaleriaPro($codigo_programa, $req_img1);
					if (($img_guardada == true) && (!$galeria))
						$galeria = true;

					$img_guardada = guardaImgGaleriaPro($codigo_programa, $req_img2);
					if (($img_guardada == true) && (!$galeria))
						$galeria = true;

					$img_guardada = guardaImgGaleriaPro($codigo_programa, $req_img3);
					if (($img_guardada == true) && (!$galeria))
						$galeria = true;

					$img_guardada = guardaImgGaleriaPro($codigo_programa, $req_img4);
					if (($img_guardada == true) && (!$galeria))
						$galeria = true;

					$img_guardada = guardaImgGaleriaPro($codigo_programa, $req_img5);
					if (($img_guardada == true) && (!$galeria))
						$galeria = true;

					$img_guardada = guardaImgGaleriaPro($codigo_programa, $req_img6);
					if (($img_guardada == true) && (!$galeria))
						$galeria = true;

					$img_guardada = guardaImgGaleriaPro($codigo_programa, $req_img7);
					if (($img_guardada == true) && (!$galeria))
						$galeria = true;

					$img_guardada = guardaImgGaleriaPro($codigo_programa, $req_img8);
					if (($img_guardada == true) && (!$galeria))
						$galeria = true;

					$img_guardada = guardaImgGaleriaPro($codigo_programa, $req_img9);
					if (($img_guardada == true) && (!$galeria))
						$galeria = true;

					$img_guardada = guardaImgGaleriaPro($codigo_programa, $req_img10);
					if (($img_guardada == true) && (!$galeria))
						$galeria = true;
					
					if (!$galeria){
						//no se cargaron imgs, se asocia img default

						//conexion a bdd
						$id_conexion = abreConeccionBdd();
					
						//fecha y hora de sistema
						$fecha_actual = date("Y-m-d");
						$hora_actual = date("H:i:s");
						
						//construccion del script
						$script = "INSERT 
						INTO fb_programa_img 
						VALUES(NULL, 
						'soul/imgs/progrs/default.jpg', 
						".$codigo_programa.", 
						1, '".$fecha_actual."', '".$hora_actual."', ".$_SESSION["per_codigo_persona"].", '".$fecha_actual."', '".$hora_actual."', ".$_SESSION["per_codigo_persona"].")";
				
						//ejecucion del script
						mysql_query($script, $id_conexion);
						
						//cierre conexion a bdd
						cierraConeccionBdd($id_conexion);
					}

					?>
					<h5>&iexcl; EL PROGRAMA HA SIDO CORRECTAMENTE CREADO !</h5>
					<p class="contenidos-texto-centrado">Ahora aparecerá en su listado de programas</p>
					<br>
					<button type="button" class="boton_principal" onclick="window.location='sis_programas.php'">IR&nbsp;A&nbsp;PROGRAMAS&nbsp;&raquo;</button>
					<?
				}
			}
			?>
			
			<div id="anula-float"></div>
		</div>
	</div>
	
	<div id="contenidos-theater">
	</div>

	<?
}

//pie del sitio
generaPieSistema($ruta_raiz);

tagFoot();
?>