<?php
include("postget.php");
include_once("common.php");

if(!$_SESSION['newclientid']) {go2('signup.php');}

if($_POST['send']!="send") {

	$query="SELECT clientid,first,last,email,password,preflang FROM hd_clients WHERE clientid=".$_SESSION['newclientid']."";
	$result=mysql_query($query,$db_link);
	$clients=mysql_fetch_array($result) or die(mysql_error());

	$subject = lang('_WELCOME',$clients['preflang']);

	include("head_template_guest.php");


	print("<br><br>");
	echo '
<div class="container">
	<div class="row">


<table class="table">
		<tr>
		<td align="center">
';
	print($subject);
echo '
		</td>
		</tr>
';
echo '
			<tr valign="top">
				<td>

';


	print("
	<table class='table'>
		<tr>
			<td>");

	$body="<table border='0' cellspacing='1' width='100%'>";

	$body.="<tr>";
	$body.="<td>";

	$body.= texto('WELCOME_MESSAGE_BY_REGISTERING',$clients['preflang']);

	$body.="</td>";
	$body.="</tr>";
	$body.="</table>";

	$body=str_replace('%FIRSTNAME%',$clients[first],$body);
	$body=str_replace('%LASTNAME%',$clients[last],$body);
	$body=str_replace('%EMAIL%',$clients[email],$body);
	$body=str_replace('%USER%',$clients[clientid],$body);
	$body=str_replace('%PASS%',decrypt($clients[password]),$body);
	$body=str_replace('%COMPANY%',$config[0][1],$body);

	print($body);

	print("
		</td>
			</tr>
			<tr>
				<td align='center'>");
	print("
				<form method='POST'>
					<input type='hidden' name='subject' value='".base64_encode($subject)."'>
					<input type='hidden' name='body' value='".base64_encode($body)."'>
				");

	if ($_REQUEST['step']=='2') {
	}else{
		print("
				<input type='hidden' name='send' value='send'>
				<input type='submit' name='sendmessage' value='"._SEND." "._TO." ".$clients[email]."'>");
	}

	print("
			</form>
			</td>
			</tr>
	</table>
	");

echo '
		</td>
		</tr>
		</table>
</div>
</div>
';

	include("foot_template.php");

}else{
	$query="SELECT clientid,first,last,email,password,preflang FROM hd_clients WHERE clientid=".$_SESSION['newclientid']."";
	$result=mysql_query($query,$db_link);
	$clients=mysql_fetch_array($result) or die(mysql_error());

	if(mail2client(stripslashes(base64_decode($_POST['subject'])),stripslashes(base64_decode($_POST['body'])),'admin',$clients[email],1))	{
		logevent(""._MESSAGE_SENT.": ".base64_decode($_POST['subject'])."",$_SESSION['newclientid'],"SYSTEM");
		messagetop(_MESSAGE_SENT." "._TO." ".$clients[first]." ".$clients[last],"","index.php",1);
	}else{
		messagetop(_ERROR,_MESSAGE_COULD_NOT_BE_SENT." "._TO." ".$clients[first]." ".$clients[last],'welcome.php',0);
	}

}
?>