<?php
$pageName = 'sellcoal step2';

require_once('config/config.php');
require_once(CLASS_DIR.'dbClass.php');
require_once(INCLUDES_DIR.'header.php');

include('hitCounter.php');

$obj = new DBClass();
$obj1 = new DBClass();
$obj2 = new DBClass();
$obj3 = new DBClass();

if(isset($_REQUEST['email']) && $_REQUEST['email'] != ''){

	$sql = "SELECT * FROM ".TBL_TMPUSER." WHERE email = '".$_REQUEST['email']."' and hashcode = '".$_REQUEST['key']."'";
	$rs = $obj->executeQry($sql,$link);
	$row = $obj->fetchrow();
	$rownum = $obj->getRow();
	if($rownum < 1){
		@header("location:verify.php?action=invalid");
	}
	else {
	$row_package = mysql_fetch_array(mysql_query("SELECT * FROM ".TBL_CRN." WHERE crn_id = '".$row['crn']."'"));
	$sql_days = mysql_fetch_array(mysql_query("SELECT * FROM ".TBL_PACKAGE." WHERE id = '".$row_package['package_id']."'"));
	$days = $sql_days['package_days'];
		
	$expdate = mktime(0,0,0,date("m"),date("d")+$days,date("y"));
	$expdates = date("Y-m-d" , $expdate);
	
	
	$sql1 = "INSERT INTO ".TBL_USER." (email,password,company_name,crn,account_type_id,fname,lname,address1,country,city,state,zip,phone,fax,register_date,exp_date,profileID) VALUES ('".trim($row['email'])."','".trim($row['password'])."','".trim($row['company_name'])."','".trim($row['crn'])."','".trim($row_package['package_id'])."','".trim($row['fname'])."','".trim($row['lname'])."','".trim($row['address1'])."','".trim($row['country'])."','".trim($row['city'])."','".trim($row['state'])."','".trim($row['zip'])."','".trim($row['phone'])."','".trim($row['fax'])."','".date("Y-m-d")."','".$expdates."','".trim($row['profileID'])."')";
	$rs1 = $obj1->executeQry($sql1,$link);

		if($rs1){			
			$updt = 1;		
			$sql2 = "UPDATE ".TBL_CRN." SET status = '".$updt."', used_date = '".date("Y-m-d")."' WHERE crn_id = ".$row['crn'];
			$rs2 = $obj2->executeQry($sql2,$link);
					
			$sql3 = "DELETE FROM ".TBL_TMPUSER." WHERE id = '".$row['id']."' ";
			$rs3 = $obj3->executeQry($sql3,$link);
		} 
	}
}
?>


<!--workarea start------------------------->
<div class="workarea">
	<div class="workareatop">
		<img src="images/workareatopcorner_03.PNG" alt="" />
	</div>
	<!--workareamid start--------------------->
	<div class="workareamid">
		<div id="floatleft" style="width:590px; float:left;">
			<div class="welcomediv">

							<h2>Registration Confirm</h2>
								
								<?php 
									$rq = mysql_query("select * from user where email = '".$_REQUEST['email']."'");										  
									if(mysql_num_rows($rq)>0) {
										$rw = mysql_fetch_array($rq);
										$_SESSION['memberID'] = $rw['id'];
										$_SESSION['profileID'] = $rw['profileID'];
										$_SESSION['email'] = $rw['email'];
								 ?>
								 <div>Now your account has been activated,<br><br>Welcome to Coalbazaar.com, you can enjoy all the benefits of coalbazaar.com.</div>
								<?php } 
								
								
								if(isset($_GET['action']) && $_GET['action'] == 'invalid') { ?>
										<div>The url is either invalid or you already have activated your account.</div>
								<?php } ?>

						</div>
				</div>
				<?php require_once(INCLUDES_DIR.'left_bar.php');?>
                <!--floatright close-------------------->
                <div style="clear:both;"></div>
            </div>
            <!--workareamid close--------------------->
            <div class="workareabottom">
                <img src="images/workareabottomcorner_03.PNG" alt="" />
            </div>
        </div>
    <!--workarea close------------------------->
<?php require_once(INCLUDES_DIR.'footer.php');?>