<?php
/**************************************************************************/
/* Module Gbook MX v2.0 Copyright (c) 2004 by Víctor Simental             */
/* $Revision 14/02/2004 - $Id save.php - v4.2.0    EPX $                  */ 
/* @URI: http://www.phpwebmasters.com                                     */ 
/* ============================================                           */
/* Based in Gbook MX v4.1.0 Copyright (c) 2003 by                         */
/* Víctor Simental - http://gbookmx.sourceforge.net                       */
/* ============================================                           */
/* GbookMX is Based in the Gbook v1.0 for PHP Nuke Copyright (c) 2003 by  */
/* http://www.PHP-Mania.com.ar                                            */
/* Programed and Design By Víctor Simental and German Cúevas              */
/* vicmx@phpwebmasters.com                                                */
/*                                                                        */
/* This program is free software. You can redistribute it and/or modify   */
/* it under the terms of the GNU General Public License as published by   */
/* the Free Software Foundation; either version 2 of the License.         */
/**************************************************************************/

if (!eregi("modules.php", $_SERVER['PHP_SELF'])) {   
 die ("You can't access this file directly...");
}
if(!@file_exists("modules/$module_name/copyright.php"))
	  die("<h1>Your Gbook MX its an copy ilegal<br> <b>DO NOT REMOVE THE COPYRIGHT. YOU'RE NOT ALLOWED TO REMOVE NOR EDIT THIS.!!!!</b></h1>");
$gbook_user= $_POST['gbook_user'];
require_once("modules/$module_name/common.php");

function comprobar($gbook_user){
global $mysql, $prefix;
$res = $mysql->sql_query("SELECT * FROM ".$prefix."_users WHERE username='$gbook_user'");
if($mysql->sql_num_rows($res)>0){
$ok = 0;
} 
else{
$ok = 1;
}
return $ok;
}

$nombre = $_POST[nombre];
$genero = $_POST[genero];
$bandera = $_POST[bandera];
$ciudad = $_POST[ciudad];
$email = $_POST[email];
$icq = $_POST[icq];
$msn = $_POST[msn];
$yim = $_POST[yim];
$url = $_POST[url];
$firma = nl2br($_POST[firma]);
$aim = $_POST[aim];
$userrec = $_POST[userrec];

$comprobacion = comprobar($nombre);
if ($gbook_user == 1 OR $comprobacion == 1){
	require("modules/$module_name/includes/class.navegador.php");
	$agent = new Navegador;
	include_once("modules/$module_name/includes/settings.php");
	//Flood Check!!!
	if(!$check){
	  $firma = nl2br($firma);
	  $nombre = trim($nombre);
	  $ciudad = trim($ciudad);
	  $ip=realip();
	  $fecha = date("Y-m-d H:i");
	  $subjectadmin=""._ADMINMESSAGE."";
	  $subjectuser=""._USERMESSAGE."";
	  $messageadmin="".$writemailadmin."";
	  $messageuser="".$writemailuser."";
	  $useragent = $agent->navegador;
	  
	if(!ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $email)){
	include("header.php");
	Table();
	echo "<center><b>"._INVALIDEMAIL."</b><br>\n<input type=\"button\" name=\"back\" value=\""._BACK."\" onclick=\"javascript:history.go(-1)\"></center>";
	EndTable();
	include("footer.php");
	}
	else
	{
	setcookie("check","flood",time()+300);
	
	if($mailadmin=="yes"){
	mail($adminmail,$subjectadmin,$messageadmin,"From: $adminmail\nX-Mailer: PHP/" . phpversion());
	}
	if($mailuser=="yes"){
	mail($email,$subjectuser,$messageuser,"From: $adminmail\nX-Mailer: PHP/" . phpversion());
	}
	$mysql->sql_query("INSERT INTO ".$prefix."_gbook (id, nombre, email, genero, bandera, firma, url, ciudad, ip, fecha, user, icq, msn, yim, aim, useragent) VALUES ('0', '$nombre', '$email', '$genero', '$bandera', '$firma', '$url', '$ciudad', '$ip', '$fecha', '$userrec', '$icq', '$msn', '$yim', '$aim', '$useragent')");
	header("Location: modules.php?name=$module_name");
	//Se puede cambiar por un mensaje de agradecimiento para el usuario
	}
	}
	else
	{
	echo "<script> window.alert(\""._SCRIPTALERTFLOODCHECK."\"); location.href=\"modules.php?name=$module_name\"; </script>";
}
        }
		else{
include ('header.php');
    OpenTable();
	 echo ""._ERRORGBOOKNICKNAME."<br>\n"
	 ."<META HTTP-EQUIV=Refresh CONTENT=\"3; URL=modules.php?name=$module_name&op=Add_Sign\">\n";
    CloseTable();
include ('footer.php');
	
	}
?>