<?php
/*
  ===============================================================

  inGenio X
  http://ingenio.area421.com

  Created by 
  Julian Moreno Hidalgo (Software developer)
  Jesus Moreno Hidalgo (Communication's tree)

  inGenio X is a free software licensed under CC-GNU GPL

  ===============================================================
*/

	// valor "1" en desarrollo y "0" en internet
	ini_set("display_errors", "0");

	// Attempt...
	define("IGNX", 1);

	// conex, config, login  global
	require("inc.global.php");

/******* CONFIGURACION  ***********/

$titulo = INGENIO_NOMBRE." ".INGENIO_VERSION;
$archivo="personalizar.php";

/******* CONFIGURACION FIN ********/

	$ig = $_GET;
	$in = $_POST;

if (isset($in["guardar"]))
{


		/* DATOS DE CONFIGURACION CON IDIOMAS */	
		// datos de configuracion
		$email = strpos($in["conf_12"],"@") ? $in["conf_12"] : NULL ;
		$email_pago = strpos($in["conf_77"],"@") ? $in["conf_77"] : NULL ;
			if ($email == NULL || $email_pago == NULL)
			{
				Redir ($archivo."?err_mail=1");
		
			}
		
		
		// comprobar si se cambia la contraseņa
		$qss = myquery("SELECT * FROM ".INGENIO." WHERE igID='9'","[07]");
		$rowss = myfetch($qss);
		if ($in["conf_9"] != $rowss["topic"])
		{
			// se cambia
			$lapass = encode64($in["conf_9"]);
		} else {
			// no se cambia
			$lapass = $in["conf_9"];	
		}

		// los ids y datos se ponen alineados
		/* 
			8 -> usuario
			9 -> pass
			12 -> email
			77 -> email pago
			78 -> modulo PAYPAL
			79 -> info adicional pago
			81 -> info adicional resumen
			82 -> idioma admin
		*/
		$ids_conf = array('8','9','12','77','78','79','81','82');		
		$datos_conf = array($in["conf_8"],$lapass,$in["conf_12"],$in["conf_77"],$in["conf_78"],$in["conf_79"],$in["conf_81"],$in["conf_82"]);	
		for ($i=0; $i<count($ids_conf); $i++)
		{
			myquery("UPDATE ".INGENIO." SET topic='".$datos_conf[$i]."' WHERE igID='".$ids_conf[$i]."'","[conf1]");
		}
		
		// generar archivo de email
		generar_email ("../ftps/ingenio_cm.js",$in["conf_12"],$in["conf_12"]);
	
		
		// datos de idiomas
		// los ids y datos se ponen alineados
		/* 
			163 -> informacion adicional sobre el pago
			209 -> informacion adicional sobre el resumen del pedido
		*/

		$ids_len = array('7','8','9','10','11','12','13','14','163','209');
		$update_idioma = "";
		for ($i=0; $i<count($ids_len); $i++)
		{
			//if ($ids_len[$i] <= 6) { $txt = "nom";  } else { $txt = "rot"; }
			$txt = "rot";
			if ($num_idiomas >= 1)
			{
				// idioma 1
				$update_idioma .= ",topic_1='".$in[$txt."1_".$ids_len[$i]]."'";
			}
			if ($num_idiomas >= 2)
			{				
					// idioma 2
				$update_idioma .= ",topic_2='".$in[$txt."2_".$ids_len[$i]]."'";
			}
			if ($num_idiomas >= 3)
			{
					// idioma 3
				$update_idioma .= ",topic_3='".$in[$txt."3_".$ids_len[$i]]."'";
			}
			if ($num_idiomas >= 4)
			{
					// idioma 4
				$update_idioma .= ",topic_4='".$in[$txt."4_".$ids_len[$i]]."'";
			}
			if ($num_idiomas >= 5)
			{
					// idioma 5
				$update_idioma .= ",topic_5='".$in[$txt."5_".$ids_len[$i]]."'";
			}
			myquery("UPDATE ".IDIOMAS." SET topic_0='".$in[$txt."0_".$ids_len[$i]]."'".$update_idioma." WHERE lenID='".$ids_len[$i]."'","[len1]");
		}
		/* FIN DATOS */
		
		Redir ($archivo."?msj=1");

}
?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<?php echo '<meta http-equiv="content-type" content="text/html; charset='.CONFIG_2.'" />'; ?>
<title><?php echo $titulo; ?></title>
<?php include("inc.head.php"); ?>

<?php include("inc.editor_tinymce.php"); ?>

<?php include("inc.formjs.php"); ?>

</head>

<body>

<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr><td valign="top">

<?php include("inc.menu.php"); ?>

</td><td valign="top" width="100%">

<?php include("inc.copy.php"); ?>

<div class="contenido">

<div class="div_rotulo_top_sec">
<img class="img_icon_pag" src="../skins_admin/<?php echo substr($row_comp['skin_admin'],0,-4); ?>/imgs/icon_personalizar.png" />
&nbsp;&nbsp;&nbsp;
<span class="rotulo_top_sec"><?php  echo LEN_ADMIN_198; ?></span>
</div>

<form enctype="multipart/form-data" action="<?php echo $archivo; ?>" onsubmit="return validar_ingreso(this);" method="post" name="principal">

<div class="rotulo"><?php  echo LEN_ADMIN_36; ?></div>

<?php
	
	if (isset($ig["err_mail"]))
	{
		echo '<span class="mensaje">'.LEN_ADMIN_29.'</span><br /><br />';
	
	}
	if (isset($ig["msj"]))
	{
		echo '<span class="mensaje">'.LEN_ADMIN_58.'</span><br /><br />';
	
	}
?>

<div class="div_destacar_grupos">
<?php
		// email, id, pass
		// rellenar ids
		$ids_add = array('12','8','9');
			for ($a=0; $a<count($ids_add); $a++)
			{
				$qid = myquery("SELECT * FROM ".INGENIO." WHERE igID='".$ids_add[$a]."'","[id3]");
				$row4 = myfetch($qid);
				echo '<strong>'.salida_sin_tags_html_br($row4["ayuda"]).'</strong><br /><br />';
				// email
				if ($row4["igID"] == 12) { $css_plus = ""; } else { $css_plus = " tmini"; }
				// pass
				if ($row4["igID"] == 9) { $input_plus = "password"; } else { $input_plus = "text"; }
				echo '<input name="conf_'.$row4["igID"].'" value="'.salida_editar_form($row4['topic']).'" type="'.$input_plus.'" class="input_text'.$css_plus.'">';	
				echo '<br /><br />';
			
			}
?>
</div>

<br /><br />
<div class="div_destacar_grupos">
<?php 
		// datos
		// rellenar ids
		$ids_add = array('14','7','13','8','9','10','11','12');
			for ($a=0; $a<count($ids_add); $a++)
			{
				$qid = myquery("SELECT * FROM ".IDIOMAS." WHERE lenID='".$ids_add[$a]."'","[id1]");
				$row2 = myfetch($qid);
				
				echo '<strong>'.salida_sin_tags_html_br($row2["ayuda"]).'</strong><br /><br />';
				// idioma principal
				echo LEN_ADMIN_90;
				if ($row2["lenID"] == 14)
				{
					echo '&nbsp;&nbsp;<input type="button" class="boton" onclick="toggleEditor(\'rot0_'.$row2["lenID"].'\');" value="'.LEN_ADMIN_78.'"><br /><br />';
					echo '<textarea id="rot0_'.$row2["lenID"].'" name="rot0_'.$row2["lenID"].'" rows="6" class="input_editor">'.$row2['topic_0'].'</textarea>';
				} else {
					echo '&nbsp;&nbsp;<input name="rot0_'.$row2["lenID"].'" value="'.salida_editar_form($row2['topic_0']).'" type="text" class="input_text">';
				}
				
				if ($num_idiomas >= 1)
				{
					// idioma 1
					echo '<br /><br />';
					echo LEN_ADMIN_91.' (1)';
					if ($row2["lenID"] == 14)
					{
						echo '&nbsp;&nbsp;<input type="button" class="boton" onclick="toggleEditor(\'rot1_'.$row2["lenID"].'\');" value="'.LEN_ADMIN_78.'"><br /><br />';
						echo '<textarea id="rot1_'.$row2["lenID"].'" name="rot1_'.$row2["lenID"].'" rows="6" class="input_editor">'.$row2['topic_1'].'</textarea>';
					} else {
						echo '&nbsp;&nbsp;<input name="rot1_'.$row2["lenID"].'" value="'.salida_editar_form($row2['topic_1']).'" type="text" class="input_text">';
					}

				}
				if ($num_idiomas >= 2)
				{				
					// idioma 2
					echo '<br /><br />';
					echo LEN_ADMIN_91.' (2)';
					if ($row2["lenID"] == 14)
					{
						echo '&nbsp;&nbsp;<input type="button" class="boton" onclick="toggleEditor(\'rot2_'.$row2["lenID"].'\');" value="'.LEN_ADMIN_78.'"><br /><br />';
						echo '<textarea id="rot2_'.$row2["lenID"].'" name="rot2_'.$row2["lenID"].'" rows="6" class="input_editor">'.$row2['topic_2'].'</textarea>';
					} else {
						echo '&nbsp;&nbsp;<input name="rot2_'.$row2["lenID"].'" value="'.salida_editar_form($row2['topic_2']).'" type="text" class="input_text">';
					}
				}
				if ($num_idiomas >= 3)
				{
					// idioma 3
					echo '<br /><br />';
					echo LEN_ADMIN_91.' (3)';
					if ($row2["lenID"] == 14)
					{
						echo '&nbsp;&nbsp;<input type="button" class="boton" onclick="toggleEditor(\'rot3_'.$row2["lenID"].'\');" value="'.LEN_ADMIN_78.'"><br /><br />';
						echo '<textarea id="rot3_'.$row2["lenID"].'" name="rot3_'.$row2["lenID"].'" rows="6" class="input_editor">'.$row2['topic_3'].'</textarea>';
					} else {
						echo '&nbsp;&nbsp;<input name="rot3_'.$row2["lenID"].'" value="'.salida_editar_form($row2['topic_3']).'" type="text" class="input_text">';
					}
				}
				if ($num_idiomas >= 4)
				{
					// idioma 4
					echo '<br /><br />';
					echo LEN_ADMIN_91.' (4)';
					if ($row2["lenID"] == 14)
					{
						echo '&nbsp;&nbsp;<input type="button" class="boton" onclick="toggleEditor(\'rot4_'.$row2["lenID"].'\');" value="'.LEN_ADMIN_78.'"><br /><br />';
						echo '<textarea id="rot4_'.$row2["lenID"].'" name="rot4_'.$row2["lenID"].'" rows="6" class="input_editor">'.$row2['topic_4'].'</textarea>';
					} else {
						echo '&nbsp;&nbsp;<input name="rot4_'.$row2["lenID"].'" value="'.salida_editar_form($row2['topic_4']).'" type="text" class="input_text">';
					}
				}
				if ($num_idiomas >= 5)
				{
					// idioma 5
					echo '<br /><br />';
					echo LEN_ADMIN_91.' (5)';
					if ($row2["lenID"] == 14)
					{
						echo '&nbsp;&nbsp;<input type="button" class="boton" onclick="toggleEditor(\'rot5_'.$row2["lenID"].'\');" value="'.LEN_ADMIN_78.'"><br /><br />';
						echo '<textarea id="rot5_'.$row2["lenID"].'" name="rot5_'.$row2["lenID"].'" rows="6" class="input_editor">'.$row2['topic_5'].'</textarea>';
					} else {
						echo '&nbsp;&nbsp;<input name="rot5_'.$row2["lenID"].'" value="'.salida_editar_form($row2['topic_5']).'" type="text" class="input_text">';
					}
				}
				echo '<br /><br />';
			
			}

?>
</div>

<br /><br />
<div class="div_destacar_grupos">
<?php
		// email, modulos
		// rellenar ids
		$ids_add = array('77','78');
			for ($a=0; $a<count($ids_add); $a++)
			{
				$qid = myquery("SELECT * FROM ".INGENIO." WHERE igID='".$ids_add[$a]."'","[id5]");
				$row4 = myfetch($qid);
				echo '<strong>'.salida_sin_tags_html_br($row4["ayuda"]).'</strong><br /><br />';
				// email pago
				if ($row4["igID"] == 77)
				{
					$input_plus = "text"; $css_plus = "";
					echo '<input name="conf_'.$row4["igID"].'" value="'.salida_editar_form($row4['topic']).'" type="'.$input_plus.'" class="input_text'.$css_plus.'">';	
				}
				// modulos //
				// PAYPAL
				if ($row4["igID"] == 78)
				{
		 			$sel_0 = $row4['topic'] == 0 ? " selected" : "" ;
		 			$sel_1 = $row4['topic'] == 1 ? " selected" : "" ;

		 			echo '<select name="conf_'.$row4["igID"].'">';
		 			echo '<option value="0"'.$sel_0.'>'.LEN_ADMIN_60.'</option>';
		 			echo '<option value="1"'.$sel_1.'>'.LEN_ADMIN_59.'</option>';
		 			echo '</select>';
				}
				// FIN modulos //
				echo '<br /><br />';
			
			}
?>
</div>

<br /><br />
<div class="div_destacar_grupos">
<?php

		// instalar info adicional
		$qid = myquery("SELECT * FROM ".INGENIO." WHERE igID='79'","[id7]");
		$row4 = myfetch($qid);
		
		$sel_info_0 = $row4["topic"] == 0 ? ' selected' : '';
		$sel_info_1 = $row4["topic"] == 1 ? ' selected' : '';
		
		echo '<strong>'.salida_sin_tags_html_br($row4["ayuda"]).'</strong><br /><br />';
		echo '<select name="conf_79">';
		echo '<option value="0"'.$sel_info_0.'>'.LEN_ADMIN_60.'</option>';
		echo '<option value="1"'.$sel_info_1.'>'.LEN_ADMIN_59.'</option>';
		echo '</select>';
		echo '<br /><br /><br />';

		// datos
		/* 
			163 -> informacion adicional sobre el pago
		*/
		// rellenar ids
		$ids_add = array('163');
			for ($a=0; $a<count($ids_add); $a++)
			{
				$qid = myquery("SELECT * FROM ".IDIOMAS." WHERE lenID='".$ids_add[$a]."'","[id6]");
				$row2 = myfetch($qid);
				
				echo '<strong>'.salida_sin_tags_html_br($row2["ayuda"]).'</strong><br /><br />';
				// idioma principal
				echo LEN_ADMIN_90;
				echo '&nbsp;&nbsp;<input type="button" class="boton" onclick="toggleEditor(\'rot0_'.$row2["lenID"].'\');" value="'.LEN_ADMIN_78.'"><br /><br />';
				echo '<textarea id="rot0_'.$row2["lenID"].'" name="rot0_'.$row2["lenID"].'" rows="6" class="input_editor">'.$row2['topic_0'].'</textarea>';
				
				if ($num_idiomas >= 1)
				{
					// idioma 1
					echo '<br /><br />';
					echo LEN_ADMIN_91.' (1)';
						echo '&nbsp;&nbsp;<input type="button" class="boton" onclick="toggleEditor(\'rot1_'.$row2["lenID"].'\');" value="'.LEN_ADMIN_78.'"><br /><br />';
						echo '<textarea id="rot1_'.$row2["lenID"].'" name="rot1_'.$row2["lenID"].'" rows="6" class="input_editor">'.$row2['topic_1'].'</textarea>';

				}
				if ($num_idiomas >= 2)
				{				
					// idioma 2
					echo '<br /><br />';
					echo LEN_ADMIN_91.' (2)';
						echo '&nbsp;&nbsp;<input type="button" class="boton" onclick="toggleEditor(\'rot2_'.$row2["lenID"].'\');" value="'.LEN_ADMIN_78.'"><br /><br />';
						echo '<textarea id="rot2_'.$row2["lenID"].'" name="rot2_'.$row2["lenID"].'" rows="6" class="input_editor">'.$row2['topic_2'].'</textarea>';
				}
				if ($num_idiomas >= 3)
				{
					// idioma 3
					echo '<br /><br />';
					echo LEN_ADMIN_91.' (3)';
						echo '&nbsp;&nbsp;<input type="button" class="boton" onclick="toggleEditor(\'rot3_'.$row2["lenID"].'\');" value="'.LEN_ADMIN_78.'"><br /><br />';
						echo '<textarea id="rot3_'.$row2["lenID"].'" name="rot3_'.$row2["lenID"].'" rows="6" class="input_editor">'.$row2['topic_3'].'</textarea>';
				}
				if ($num_idiomas >= 4)
				{
					// idioma 4
					echo '<br /><br />';
					echo LEN_ADMIN_91.' (4)';
						echo '&nbsp;&nbsp;<input type="button" class="boton" onclick="toggleEditor(\'rot4_'.$row2["lenID"].'\');" value="'.LEN_ADMIN_78.'"><br /><br />';
						echo '<textarea id="rot4_'.$row2["lenID"].'" name="rot4_'.$row2["lenID"].'" rows="6" class="input_editor">'.$row2['topic_4'].'</textarea>';
				}
				if ($num_idiomas >= 5)
				{
					// idioma 5
					echo '<br /><br />';
					echo LEN_ADMIN_91.' (5)';
						echo '&nbsp;&nbsp;<input type="button" class="boton" onclick="toggleEditor(\'rot5_'.$row2["lenID"].'\');" value="'.LEN_ADMIN_78.'"><br /><br />';
						echo '<textarea id="rot5_'.$row2["lenID"].'" name="rot5_'.$row2["lenID"].'" rows="6" class="input_editor">'.$row2['topic_5'].'</textarea>';
				}
				echo '<br /><br />';
			
			}

?>
</div>

<br /><br />
<div class="div_destacar_grupos">
<?php

		// instalar info adicional del resumen del pedido
		$qid = myquery("SELECT * FROM ".INGENIO." WHERE igID='81'","[id7]");
		$row4 = myfetch($qid);
		
		$sel_info_0 = $row4["topic"] == 0 ? ' selected' : '';
		$sel_info_1 = $row4["topic"] == 1 ? ' selected' : '';
		
		echo '<strong>'.salida_sin_tags_html_br($row4["ayuda"]).'</strong><br /><br />';
		echo '<select name="conf_81">';
		echo '<option value="0"'.$sel_info_0.'>'.LEN_ADMIN_60.'</option>';
		echo '<option value="1"'.$sel_info_1.'>'.LEN_ADMIN_59.'</option>';
		echo '</select>';
		echo '<br /><br /><br />';

		// datos
		/* 
			209 -> informacion adicional sobre el resumen del pedido
		*/
		// rellenar ids
		$ids_add = array('209');
			for ($a=0; $a<count($ids_add); $a++)
			{
				$qid = myquery("SELECT * FROM ".IDIOMAS." WHERE lenID='".$ids_add[$a]."'","[id6]");
				$row2 = myfetch($qid);
				
				echo '<strong>'.salida_sin_tags_html_br($row2["ayuda"]).'</strong><br /><br />';
				// idioma principal
				echo LEN_ADMIN_90;
				echo '&nbsp;&nbsp;<input type="button" class="boton" onclick="toggleEditor(\'rot0_'.$row2["lenID"].'\');" value="'.LEN_ADMIN_78.'"><br /><br />';
				echo '<textarea id="rot0_'.$row2["lenID"].'" name="rot0_'.$row2["lenID"].'" rows="6" class="input_editor">'.$row2['topic_0'].'</textarea>';
				
				if ($num_idiomas >= 1)
				{
					// idioma 1
					echo '<br /><br />';
					echo LEN_ADMIN_91.' (1)';
						echo '&nbsp;&nbsp;<input type="button" class="boton" onclick="toggleEditor(\'rot1_'.$row2["lenID"].'\');" value="'.LEN_ADMIN_78.'"><br /><br />';
						echo '<textarea id="rot1_'.$row2["lenID"].'" name="rot1_'.$row2["lenID"].'" rows="6" class="input_editor">'.$row2['topic_1'].'</textarea>';

				}
				if ($num_idiomas >= 2)
				{				
					// idioma 2
					echo '<br /><br />';
					echo LEN_ADMIN_91.' (2)';
						echo '&nbsp;&nbsp;<input type="button" class="boton" onclick="toggleEditor(\'rot2_'.$row2["lenID"].'\');" value="'.LEN_ADMIN_78.'"><br /><br />';
						echo '<textarea id="rot2_'.$row2["lenID"].'" name="rot2_'.$row2["lenID"].'" rows="6" class="input_editor">'.$row2['topic_2'].'</textarea>';
				}
				if ($num_idiomas >= 3)
				{
					// idioma 3
					echo '<br /><br />';
					echo LEN_ADMIN_91.' (3)';
						echo '&nbsp;&nbsp;<input type="button" class="boton" onclick="toggleEditor(\'rot3_'.$row2["lenID"].'\');" value="'.LEN_ADMIN_78.'"><br /><br />';
						echo '<textarea id="rot3_'.$row2["lenID"].'" name="rot3_'.$row2["lenID"].'" rows="6" class="input_editor">'.$row2['topic_3'].'</textarea>';
				}
				if ($num_idiomas >= 4)
				{
					// idioma 4
					echo '<br /><br />';
					echo LEN_ADMIN_91.' (4)';
						echo '&nbsp;&nbsp;<input type="button" class="boton" onclick="toggleEditor(\'rot4_'.$row2["lenID"].'\');" value="'.LEN_ADMIN_78.'"><br /><br />';
						echo '<textarea id="rot4_'.$row2["lenID"].'" name="rot4_'.$row2["lenID"].'" rows="6" class="input_editor">'.$row2['topic_4'].'</textarea>';
				}
				if ($num_idiomas >= 5)
				{
					// idioma 5
					echo '<br /><br />';
					echo LEN_ADMIN_91.' (5)';
						echo '&nbsp;&nbsp;<input type="button" class="boton" onclick="toggleEditor(\'rot5_'.$row2["lenID"].'\');" value="'.LEN_ADMIN_78.'"><br /><br />';
						echo '<textarea id="rot5_'.$row2["lenID"].'" name="rot5_'.$row2["lenID"].'" rows="6" class="input_editor">'.$row2['topic_5'].'</textarea>';
				}
				echo '<br /><br />';
			
			}

?>
</div>

<br /><br />
<div class="div_destacar_grupos">
<?php
		// idioma admin
		$qid = myquery("SELECT * FROM ".INGENIO." WHERE igID='82'","[id8]");
		$row5 = myfetch($qid);
	
		$qid2 = myquery("SELECT * FROM ".IDIOMA_ADMIN." WHERE lenID='1'","[id9]");
		$rowid = myfetch($qid2);			
		
		$sel_lan_0 = $row5["topic"] == 0 ? ' selected' : '';
		$sel_lan_1 = $row5["topic"] == 1 ? ' selected' : '';
		$sel_lan_2 = $row5["topic"] == 2 ? ' selected' : '';
		$sel_lan_3 = $row5["topic"] == 3 ? ' selected' : '';
		$sel_lan_4 = $row5["topic"] == 4 ? ' selected' : '';
		$sel_lan_5 = $row5["topic"] == 5 ? ' selected' : '';
		
		echo '<strong>'.salida_sin_tags_html_br($row5["ayuda"]).'</strong><br /><br />';
		echo '<select name="conf_82">';
		echo '<option value="0"'.$sel_lan_0.'>[0] '.$rowid["topic_pre"].'</option>';
		echo '<option value="1"'.$sel_lan_1.'>[1] '.$rowid["topic_pre_1"].'</option>';
		echo '<option value="2"'.$sel_lan_2.'>[2] '.$rowid["topic_pre_2"].'</option>';
		echo '<option value="3"'.$sel_lan_3.'>[3] '.$rowid["topic_pre_3"].'</option>';
		echo '<option value="4"'.$sel_lan_4.'>[4] '.$rowid["topic_pre_4"].'</option>';
		echo '<option value="5"'.$sel_lan_5.'>[5] '.$rowid["topic_pre_5"].'</option>';
		echo '</select>';

?>
</div>

<div style="text-align:center;margin:20px 0px 20px 0px;">
<input type="submit" value="<?php echo LEN_ADMIN_16;?>" class="boton">
<input type="hidden" name="guardar" value="1">
&nbsp;&nbsp;&nbsp;<input type="reset" value="<?php echo LEN_ADMIN_18;?>" class="boton">
</div>

</form>
</div>

</td></tr></table>

</body>
</html>
<?php
	include("inc.fin.php");
?>