<?
////////////////////////////////////////////////////
// Conciliación: gestión de conciliación de activos
// Version: 1.0
//
// Copyright (C) 2014  Eustotem Multimedia, S.L.
//
// License: MIT, see LICENSE
////////////////////////////////////////////////////


session_start();
include("../conf/preferences.php");
include("../conf/langs/".$langs[$_SESSION['userlang']][0]."/MAIN.php");
include("../conf/langs/".$langs[$_SESSION['userlang']][0]."/myAccount.php");
include("../conf/connections.php");
include("../phplib/auth.php");
require_once("../phplib/utils.php");
require_once("../core/plugins.php");
$respuesta='';
if($_SERVER['REQUEST_METHOD']=='POST'){
	$f=$_POST;
	if($f['nombre']=='') $errores['nombre']=ADDON_PHP_NAME_REQUIRED;
	if($f['apellidos']=='') $errores['apellidos']=ADDON_PHP_SURNAME_REQUIRED;
	if($f['email']=='') $errores['email']=ADDON_PHP_EMAIL_REQUIRED;
	if($f['user']=='') $errores['user']=ADDON_PHP_NICK_REQUIRED;
	if(!isset($f['keep_password'])){
		if($f['password']=='') $errores['password']=ADDON_PHP_PASS_NOT_EMPTY;
	}
	if(!isset($errores)){
		$nombre=mysql_real_escape_string($f['nombre']);
		$apellidos=mysql_real_escape_string($f['apellidos']);
		$email=mysql_real_escape_string($f['email']);
		$tel=mysql_real_escape_string($f['tel']);
		$user=mysql_real_escape_string($f['user']);
		if(!isset($f['keep_password'])){
			$password=", password='" . sha1($f['password']) . "'";
		}else{
			$password='';
		}
		
		$cadena="UPDATE " . SYS_USERS_TABLE . " SET nombre='$nombre', apellidos='$apellidos', email='$email', tel='$tel', user='$user' $password WHERE id=" . $_SESSION['user']['id'];
		$q=mysql_query($cadena);
		$respuesta='ok';
	}else{
		$respuesta='ko';
	}
}else{
	$q=mysql_query("SELECT * FROM " . SYS_USERS_TABLE . " WHERE id=" . $_SESSION['user']['id']);
	$f=mysql_fetch_array($q);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><? echo $_SESSION['application']['title'] ?></title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link href="../resources/themes/default/main.css" rel="stylesheet" type="text/css" />
	<link href="../resources/themes/default/form_screen.css" rel="stylesheet" type="text/css" />
</head>

<body bgcolor="#FFFFFF" style="background-image:none;">
<div id="pageBar">
	<h1><? echo ADDON_HTML_MY_ACCOUNT ?></h1>
</div>
<table width="100%" cellpadding="0" cellspacing="0" style="">
<tr>
<td id="panel_central" valign="top">
<? if($respuesta=='ok'){ ?>
<div class="validacion" style="border:1px solid #999999; margin:10px auto 0 auto; text-align:center">
<? echo ADDON_HTML_OK ?>
</div>
<? }else{ ?>
<form action="myAccount.php" method="post" name="dataform" id="dataform" enctype="multipart/form-data">
<? echo ADDON_HTML_DESCRIPTION ?>
<br />
<br />
<table width="600" border="0" cellspacing="0" cellpadding="2" style="border:1px solid #333333" align="center">
	<thead>
	<tr>
		<td colspan="2" class="barra_recuento"><? echo ADDON_HTML_USER_DATA ?></td>
	</tr>
	</thead>
	
	<tbody id="table_body">
	<tr class="<? echo $clase ?>" style="border-bottom:1px solid #999999;">
		<td width="179"><? echo ADDON_HTML_NAME ?></td>
		<td align="left"><input type='text' name='nombre' id='nombre' class='txt_default' value='<? echo $f['nombre'] ?>' /></td>
		</tr>
	<tr class="<? echo $clase ?>" style="border-bottom:1px solid #999999;">
		<td><? echo ADDON_HTML_SURNAME ?></td>
		<td align="left"><input type='text' name='apellidos' id='apellidos' class='txt_default' value='<? echo $f['apellidos'] ?>' /></td>
	</tr>
	<tr class="<? echo $clase ?>" style="border-bottom:1px solid #999999;">
		<td><? echo ADDON_HTML_EMAIL ?></td>
		<td align="left"><input type='text' name='email' id='email' class='txt_default' value='<? echo $f['email'] ?>' /></td>
	</tr>
	<tr class="<? echo $clase ?>" style="border-bottom:1px solid #999999;">
		<td><? echo ADDON_HTML_TEL ?></td>
		<td align="left"><input type='text' name='tel' id='tel' class='txt_default' value='<? echo $f['tel'] ?>' /></td>
	</tr>
	<tr class="<? echo $clase ?>" style="border-bottom:1px solid #999999;">
		<td><? echo ADDON_HTML_NICK ?></td>
		<td align="left"><input type='text' name='user' id='user' class='txt_default' value='<? echo $f['user'] ?>' /></td>
	</tr>
	<tr class="<? echo $clase ?>" style="border-bottom:1px solid #999999;">
		<td><? echo ADDON_HTML_PASS ?></td>
		<td align="left">
			<input type='password' name='password' id='password' class='txt_default' value='' maxlength="15" />
			<input type="checkbox" name="keep_password" id="keep_password" value="1" checked="checked" />&nbsp;<? echo ADDON_HTML_KEEP_PASS ?>
		</td>
	</tr>
	<? if($respuesta=='ko'){ ?>
	<tr class="<? echo $clase ?>" style="border-bottom:1px solid #999999;">
		<td class="validacion" colspan="2">
			<?
			$cadena='';
			foreach($errores as $key=>$value){
				$cadena.=$value . '<br />';
			}
			echo $cadena;
			?>
		</td>
	</tr>
	<? } ?>
	</tbody>
	
	<tfoot id="table_foot">
	<tr>
		<td>
			<input type="submit" name="ya" id="ya" value="<? echo ADDON_HTML_SEND ?>" class="but_default" />
		</td>
		<td align="right">&nbsp;</td>
		</tr>
	</tfoot>
</table>
</form>
<? } ?>
</td>
</tr>
</table>
</body>
</html>
