<?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_php = $_SERVER['SCRIPT_NAME'];

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

	$cadena_get_comple = $_SERVER['QUERY_STRING'];
	$cadena_get = strstr($_SERVER['QUERY_STRING'],"msj=1&");
	$no_get = $cadena_get_comple == "" ? 1 : 0 ;
	$tabla_get = "tabla=".INGENIO;
	$campoid = "igID";
	$ig = $_GET;
	$in = $_POST;

if (isset($in["guardar"]))
{
	
	$tipo = $in["tipo"];
	$topic = entrada_gral_html($in["topic"]);
	$ayuda = entrada_sin_tags_html($in["ayuda"]);
	$grupo = entrada_sin_tags_html($in["grupo"]);
	$qs = "INSERT INTO ".INGENIO." (tipo,grupo,topic,ayuda) VALUES ('".$tipo."','".$grupo."','".$topic."','".$ayuda."')";
	myquery($qs,"[01]");
	$inid = myinsertid();
	
	Redir ($archivo_php."?".$campoid."=".$inid."&msj=1&".$in["listado_get"]);


}

if (isset($ig["igID"]) || isset($in["igID"]))
{
	// asignar ID gral
	$fileID_gral = isset($ig["igID"]) ? $ig["igID"] : $in["igID"];
	
	
	if (isset($in["actualizar"]))
	{
	
		// asignar el ID
		$inid = $fileID_gral;
		
		$tipo = $in["tipo"];
		$topic = $in["topic"];
		
		// tipos
		if ($tipo == 1)
		{
			$topic = is_numeric($topic) && $topic > 0 ? $topic : NULL ;
			
		} else if ($tipo == 3)
		{			
			$caracter = strrpos($topic,"#");
			$topic = strlen($topic) == 7 && $caracter == 0 && $caracter !== false ? $topic : NULL ;
			
		} else if ($tipo == 5)
		{
			$topic = $topic != "" ? entrada_gral_html($topic) : NULL ;
			
		} else if ($tipo == 6)
		{
			$topic = strpos($topic,"@") ? $topic : NULL ;
			
		} else if ($tipo == 9)
		{
			$topic = is_numeric($topic) && $topic > 0 ? $topic : NULL ;
			
		}
		
		// comprobar topic
		if ($topic == NULL)
		{
			Redir ($archivo_php."?igID=".$inid."&err=1&".$in["listado_get"]);
			
		} else {
		
		
		$ayuda = entrada_sin_tags_html($in["ayuda"]);
		$grupo = entrada_sin_tags_html($in["grupo"]);
		
		if ($tipo == 4) // pass
		{
			$topic = encode64($topic);
		
		}
		
		$qs = "UPDATE ".INGENIO." SET tipo='".$tipo."',grupo='".$grupo."',topic='".$topic."',ayuda='".$ayuda."' WHERE igID='".$fileID_gral."'";
		myquery($qs,"[04]");
		
		// general archivo de email
		$qtm = myquery("SELECT * FROM ".INGENIO." WHERE igID='12'","[06]");
		$rowtm = myfetch($qtm);
		generar_email ("../ftps/ingenio_cm.js",$rowtm["topic"],$rowtm["topic"]);
		
		Redir ($archivo_php."?".$campoid."=".$inid."&msj=1&".$in["listado_get"]);
		
		}

	}

	// extraer los datos de la base
	$qt = myquery("SELECT * FROM ".INGENIO." WHERE igID='".$fileID_gral."'","[05]");
	$row = myfetch($qt);


} else {


/***** NUEVO ******/

$row = array();
$row["igID"] = "";
$row["tipo"] = "";
$row["grupo"] = "";
$row["topic"] = "";
$row["ayuda"] = "";

}

?>
<!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.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">

<?php
	if (isset($ig[$campoid]) || isset($in["actualizar"]))
	{
?>
<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_editar.png" />
&nbsp;&nbsp;&nbsp;
<span class="rotulo_top_sec"><?php  echo LEN_ADMIN_146; ?></span>
</div>
<?php
	} else {
?>
<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_php.png" />
&nbsp;&nbsp;&nbsp;
<span class="rotulo_top_sec"><?php  echo LEN_ADMIN_10; ?></span>
</div>
<?php
	}
?>

<form enctype="multipart/form-data" action="<?php echo $archivo_php; ?>" onsubmit="return validar_ingreso(this);" method="post" name="principal">
<?php
	if (isset($ig["igID"]) || isset($in["actualizar"]))
	{

		if ($cadena_get)
		{
			$listado_get = substr($cadena_get,6);
			
		} else {
			
			if (isset($ig["err"]))
			{
			
				$listado_get = str_replace($campoid."=".$fileID_gral."&err=1&","", $cadena_get_comple);
				
			} else {
			
				// si se entra desde la web
				if ($cadena_get_comple == $campoid."=".$fileID_gral)
				{
					$listado_get = str_replace($campoid."=".$fileID_gral, $tabla_get, $cadena_get_comple);
						
				} else {
			
					$listado_get = str_replace($campoid."=".$fileID_gral."&","", $cadena_get_comple);
				}
			}

		}
		
		echo '<div class="rotulo">'.LEN_ADMIN_48.'</div>';
		
		// gestionar
		echo '&nbsp;&nbsp;<a title="'.salida_popups(LEN_ADMIN_9).'"';
		echo ' href="listados.php?'.$listado_get.'"';
		echo ' class="conex_tip">';
		echo '<img class="img_icon_ini" src="../skins_admin/'.substr($row_comp['skin_admin'],0,-4).'/imgs/icon_configuracion.png" />';
		echo '</a>';
		echo '&nbsp;&nbsp;(#'.$fileID_gral.')';


	} else {
		echo '<div class="rotulo">'.LEN_ADMIN_48.'</div>';	
		
		// gestionar
		echo '<a title="'.salida_popups(LEN_ADMIN_9).'"';
		echo ' href="listados.php?'.$tabla_get.'"';
		echo ' class="conex_tip">';
		echo '<img class="img_icon_ini" src="../skins_admin/'.substr($row_comp['skin_admin'],0,-4).'/imgs/icon_configuracion.png" />';
		echo '</a>';
	}

	if (isset($ig["msj"]))
	{
		echo '<br /><br /><span class="mensaje">'.LEN_ADMIN_22.'</span>&nbsp;&nbsp;';
	
	}

	if (isset($ig["err"]))
	{
		echo '<br /><br /><span class="mensaje">'.LEN_ADMIN_32.'</span>&nbsp;&nbsp;';
	
	}
?>

<br /><br /><br />
<div class="div_destacar_grupos">
<?php  echo LEN_ADMIN_87; ?><br /><br />
<textarea name="ayuda" class="input_editor_otro" rows="6"><?php echo $row["ayuda"]; ?></textarea>
</div>

<br /><br />
<div class="div_destacar_grupos">
<?php
	if (isset($ig["igID"]) || isset($in["actualizar"]))
	{

		 // programacion
		 if (CONFIG_53 == 1)
		 {
		 	// seleccionar tipo 
		 	$sel_1 = $row['tipo'] == 1 ? " selected" : "" ;
		 	$sel_2 = $row['tipo'] == 2 ? " selected" : "" ;
		 	$sel_3 = $row['tipo'] == 3 ? " selected" : "" ;
		 	$sel_4 = $row['tipo'] == 4 ? " selected" : "" ;
		 	$sel_5 = $row['tipo'] == 5 ? " selected" : "" ;
		 	$sel_6 = $row['tipo'] == 6 ? " selected" : "" ;
		 	$sel_7 = $row['tipo'] == 7 ? " selected" : "" ;
		 	$sel_8 = $row['tipo'] == 8 ? " selected" : "" ;
		 	$sel_9 = $row['tipo'] == 9 ? " selected" : "" ;

		 	echo LEN_ADMIN_96.' <b>'.$row['tipo'].'</b>';
			echo '&nbsp;&nbsp;&nbsp;<select name="tipo">';
			echo '<option value="1"'.$sel_1.'>int</option>';
			echo '<option value="2"'.$sel_2.'>0|1</option>';
			echo '<option value="3"'.$sel_3.'>#000000</option>';
			echo '<option value="4"'.$sel_4.'>pass</option>';
			echo '<option value="5"'.$sel_5.'>str</option>';
			echo '<option value="6"'.$sel_6.'>email</option>';
			echo '<option value="7"'.$sel_7.'>0|1|2|3|4|5</option>';
			echo '<option value="8"'.$sel_8.'>textarea</option>';
			echo '<option value="9"'.$sel_9.'>cols</option>';
			echo '</select>';
		
		 } else {
		
		 	// no cambio de tipo
		 	echo LEN_ADMIN_96.' <b>'.$row['tipo'].'</b>';
			echo '<input type="hidden" name="tipo" value="'.$row['tipo'].'">';
		 }
		 	echo '<br /><br />';
		 
		 if ($row['tipo'] == 2) { // SI|NO

		 	$sel_0 = $row['topic'] == 0 ? " selected" : "" ;
		 	$sel_1 = $row['topic'] == 1 ? " selected" : "" ;
		 	
			// grupo
			echo LEN_ADMIN_327;
			echo '&nbsp;<input name="grupo" maxlength="255" value="'.salida_editar_form($row["grupo"]).'" type="text" class="input_text tmini">';
		 	// config
		 	echo '<br /><br />';
		 	echo '* <strong>'.LEN_ADMIN_97.'</strong>';
		 	echo '&nbsp;&nbsp;<select name="topic">';
		 	echo '<option value="0"'.$sel_0.'>'.LEN_ADMIN_60.'</option>';
		 	echo '<option value="1"'.$sel_1.'>'.LEN_ADMIN_59.'</option>';
		 	echo '</select>';
		 	
		 } else if ($row['tipo'] == 7) { // idiomas
		 
		 	$sel_0 = $row['topic'] == 0 ? " selected" : "" ;
		 	$sel_1 = $row['topic'] == 1 ? " selected" : "" ;
		 	$sel_2 = $row['topic'] == 2 ? " selected" : "" ;
		 	$sel_3 = $row['topic'] == 3 ? " selected" : "" ;
		 	$sel_4 = $row['topic'] == 4 ? " selected" : "" ;
		 	$sel_5 = $row['topic'] == 5 ? " selected" : "" ;

			// grupo
			echo LEN_ADMIN_327;
			echo '&nbsp;<input name="grupo" maxlength="255" value="'.salida_editar_form($row["grupo"]).'" type="text" class="input_text tmini">';
		 	// config
		 	echo '<br /><br />';
		 	echo '* <strong>'.LEN_ADMIN_97.'</strong>';
		 	echo '&nbsp;&nbsp;<select name="topic">';
		 	echo '<option value="0"'.$sel_0.'>0</option>';
		 	echo '<option value="1"'.$sel_1.'>1</option>';
		 	echo '<option value="2"'.$sel_2.'>2</option>';
		 	echo '<option value="3"'.$sel_3.'>3</option>';
		 	echo '<option value="4"'.$sel_4.'>4</option>';
		 	echo '<option value="5"'.$sel_5.'>5</option>';
		 	echo '</select>';	 
		 
		 } else if ($row['tipo'] == 8) { // textarea
		 
			// grupo
			echo LEN_ADMIN_327;
			echo '&nbsp;<input name="grupo" maxlength="255" value="'.salida_editar_form($row["grupo"]).'" type="text" class="input_text tmini">';
			// config
		 	echo '<br /><br />';
		 	echo '* <strong>'.LEN_ADMIN_97.'</strong>';
		 	echo '<br /><br />';
			echo '<textarea name="topic" rows="12" class="input_editor">'.$row['topic'].'</textarea>';			
	
		 } else if ($row['tipo'] == 9) { // cols
		 

			// grupo
			echo LEN_ADMIN_327;
			echo '&nbsp;<input name="grupo" maxlength="255" value="'.salida_editar_form($row["grupo"]).'" type="text" class="input_text tmini">';
		 	// config
		 	echo '<br /><br />';
		 	echo '* <strong>'.LEN_ADMIN_97.'</strong>';
		 	echo '&nbsp;&nbsp;<input name="topic" maxlength="2" value="'.salida_editar_form($row["topic"]).'" type="text" class="input_text tchar">';		 

		 
		 } else if ($row['tipo'] == 4) { // pass

			// grupo
			echo LEN_ADMIN_327;
			echo '&nbsp;<input name="grupo" maxlength="255" value="'.salida_editar_form($row["grupo"]).'" type="text" class="input_text tmini">';
		 	// config
		 	echo '<br /><br />';
		 	echo '* <strong>'.LEN_ADMIN_97.'</strong>';
		 	echo '&nbsp;&nbsp;<input name="topic" value="'.decode64($row["topic"]).'" type="password" class="input_text">';		 
		 		 
		 } else {
		 
			// grupo
			echo LEN_ADMIN_327;
			echo '&nbsp;<input name="grupo" maxlength="255" value="'.salida_editar_form($row["grupo"]).'" type="text" class="input_text tmini">';
		 	// config
		 	echo '<br /><br />';
		 	echo '* <strong>'.LEN_ADMIN_97.'</strong>';
		 	echo '&nbsp;&nbsp;<input name="topic" value="'.salida_editar_form($row["topic"]).'" type="text" class="input_text">';		 
		 
		 }
	
	
	} else {
?>
* <?php  echo LEN_ADMIN_96; ?>
&nbsp;<select name="tipo">
<option value="1">int</option>
<option value="2">0|1</option>
<option value="3">#000000</option>
<option value="4">pass</option>
<option value="5">str</option>
<option value="6">email</option>
<option value="7">0|1|2|3|4|5</option>
<option value="8">textarea</option>
<option value="9">cols</option>
</select>

<br /><br />
<?php  echo LEN_ADMIN_327; ?>
&nbsp;<input name="grupo" maxlength="255" value="<?php echo salida_editar_form($row['grupo']); ?>" type="text" class="input_text tmini">

<br /><br />
* <strong><?php  echo LEN_ADMIN_97; ?></strong>
&nbsp;&nbsp;<input name="topic" maxlength="255" value="<?php echo salida_editar_form($row['topic']); ?>" type="text" class="input_text">
<?php
	} // del if
?>
</div>

<div style="text-align:center;margin:20px 0px 20px 0px;">
<?php
	if (isset($ig["igID"]) || isset($in["actualizar"]))
	{
?>
<input type="submit" value="<?php echo LEN_ADMIN_17;?>" class="boton">
<input type="hidden" name="<?php echo $campoid; ?>" value="<?php echo $fileID_gral; ?>">
<input type="hidden" name="actualizar" value="1">
<input type="hidden" name="listado_get" value="<?php echo $listado_get; ?>">
<?php
	} else {
?>
<input type="submit" value="<?php echo LEN_ADMIN_16;?>" class="boton">
<input type="hidden" name="guardar" value="1">
<input type="hidden" name="listado_get" value="<?php echo $tabla_get; ?>">
&nbsp;&nbsp;&nbsp;<input type="reset" value="<?php echo LEN_ADMIN_18;?>" class="boton">
<?php
	}
?>
</div>

</form>
</div>

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

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