<?php 
$pageName = 'Registration';

require_once('config/config.php');
require_once('recaptchalib.php');

$publickey = "6Lf3v-YSAAAAABVsHbP_zvgWIbaJxQg8aS7OIHit";
$privatekey = "6Lf3v-YSAAAAADnNWJCPqptbQYzwpNHXTV4rCQ6_";
		?>
<link rel="stylesheet" href="css/main.css" type="text/css">
<?php
require_once(CLASS_DIR.'dbClass.php');
require_once(INCLUDES_DIR.'header.php');

include('hitCounter.php');

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

if(isset($_POST['submit']) && $_POST['submit'] == 'Register'){

		// email id check
		$sql2 = "SELECT * FROM ".TBL_USER." WHERE email = '".$_POST['email']."'";		
		$rs2 = $obj1->executeQry($sql2,$link);		
		$row2 = $obj1->fetchrow();	 
		if($row2['email'] == $_POST['email'] && ($_POST['email']!= '')){  $error[] = "This email is already registered."; }
		
		// CRN Check	
		/*if(isset($_POST['radiobtn']) && ($_POST['radiobtn'] !='1') ){
			$sql3 = "SELECT * FROM ".TBL_CRN." WHERE `status`=0 and crn_id = '".$_POST['crn']."'";
			$rs2 = $obj3->executeQry($sql3,$link);
			$row3 = $obj3->fetchrow();
			if($row3['crn_id'] != $_POST['crn'] && ($_POST['crn']!= '')){ $error[] = "This CRN is Not Valid.";	}
		} */
		$valid = validmess($_POST['fname'], "First Name"); if(isset($valid) && $valid != ''){ $mess[] = $valid;}	
		$valid = validmess($_POST['lname'], "Last Name"); if(isset($valid) && $valid != ''){ $mess[] = $valid;}	
		$valid = checkEmail($_POST['email'], "Email"); if(isset($valid) && $valid != ''){ $mess[] = $valid;}	
		$valid = validmess($_POST['password'], "Password"); if(isset($valid) && $valid != ''){ $mess[] = $valid;}			
		$valid = validmess($_POST['crn'], "Customer receipt number"); if(isset($valid) && $valid != ''){ $mess[] = $valid;}			
		$valid = validmess($_POST['company_name'], "Company name"); if(isset($valid) && $valid != ''){ $mess[] = $valid;}	
		$valid = validmess($_POST['cpassword'], "Confirm Password"); if(isset($valid) && $valid != ''){ $mess[] = $valid;}	
		$valid = validmess($_POST['address1'], "Address"); if(isset($valid) && $valid != ''){ $mess[] = $valid;}			
		$valid = validmess($_POST['country'], "Country"); if(isset($valid) && $valid != ''){ $mess[] = $valid;}	
		$valid = validmess($_POST['city'], "City"); if(isset($valid) && $valid != ''){ $mess[] = $valid;}	
		$valid = validmess($_POST['state'], "State"); if(isset($valid) && $valid != ''){ $mess[] = $valid;}	
		$valid = validmess($_POST['zip'], "Zip"); if(isset($valid) && $valid != ''){ $mess[] = $valid;}

		if($_POST['terms'] == ''){ $error[] = 'First read all terms and conditions';	}
        
    
		if(($_POST['country'] == 'other')) {			
		  $valid = validmess($_POST['othercountry'], "Country"); if(isset($valid) && $valid != ''){ $mess[] = $valid;} 
		  $country = $_POST['othercountry'];
		}
		else {
		  $country = $_POST['country'];
		}
        
        if(($_POST['state'] == 'other')) {            
          $valid = validmess($_POST['otherstate'], "State"); if(isset($valid) && $valid != ''){ $mess[] = $valid;} 
          $state = $_POST['otherstate'];
        }
        else {
          $state = $_POST['state'];
        }
        
        if(($_POST['city'] == 'other')) {            
          $valid = validmess($_POST['othercity'], "City"); if(isset($valid) && $valid != ''){ $mess[] = $valid;} 
          $city = $_POST['othercity'];
        }
        else {
          $city = $_POST['city'];
        }
		
		
		if($_POST['password'] != $_POST['cpassword']){ $error[] = 'Password and confirm password should be same...!';}

	    if($mess != '') { $error[] = 'Please fill all required fields with correct values.';}
		
		if (isset($_POST["recaptcha_response_field"])) {
		$resp = recaptcha_check_answer($privatekey,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"],$_POST["recaptcha_response_field"]);
		if ($resp->is_valid) {
		if($error == ''){
			//if(isset($_POST['radiobtn']) && ($_POST['radiobtn'] =='1') ){
			$sql1 = "INSERT INTO ".TBL_CRN." (crn_id,name,service,package_id,issue_date) VALUES ('".trim($_POST['crn'])."','".trim($_POST['company_name'])."','Free Members','1','".date("Y-m-d")."')";
			$rs5 = $obj4->executeQry($sql1,$link);
			//}
			$key = md5(uniqid(rand(0,1000), true)); // Generate random 32 character hash and assign it to a local variable.
				
			$profileID = strtoupper(substr($_POST['fname'],0,2).substr($_POST['lname'],0,2).date("d-m-Y"));
			
			$sql = "INSERT INTO ".TBL_TMPUSER." (email,password,company_name,crn,fname,lname,address1,country,city,state,zip,phone,fax,register_date,profileID,hashcode) VALUES ('".trim($_POST['email'])."','".trim($_POST['password'])."','".trim($_POST['company_name'])."','".trim($_POST['crn'])."','".trim($_POST['fname'])."','".trim($_POST['lname'])."','".trim($_POST['address1'])."','".trim($country)."','".trim(strtoupper($city))."','".trim($state)."','".trim($_POST['zip'])."','".trim($_POST['phone'])."','".trim($_POST['fax'])."','".date("Y-m-d")."','".trim($profileID)."','".trim($key)."')";
			$rs = $obj->executeQry($sql,$link);
				
			if($rs){
				// *********************** start  mail to admin *****************
				$to        	= 	$_POST['email'];
				$subject	=	"Email Verification Mail From Coalbazaar.com";
				$message	= 	"Dear Customer,  <br><br>".
				
				"Thanks for Registring with coalbazaar.com family<br><br>".
				"Your account has been created, you can login with your user id(Email id) and Password after you have activated your account by pressing the url given below.<br><br>".
				"Please click this link to activate your account:<br><br>".				
				"http://www.coalbazaar.com/verify.php?email=".$_POST['email']."&key=".$key				
				
				."<br><br><strong style='font-size:18px;'>Thanks and Regards</strong><br><strong>Shrinetra Infotech</strong><br>62, Sch. No. 114, Part 1<br>Near ICICI Bank ATM,<br>Indore, (M.P) 452010<br><br><strong>Phone &nbsp;&nbsp;:</strong> 0731-2012323<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+91-9993299974-78 (sales)<br><strong>Fax &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: </strong> 0731-4032323<br><strong>Email Id:</strong> shrinetrainfotech@gmail.com<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;info@coalbazaar.com<br><strong>Website:</strong><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;www.coalbazaar.com<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;www.coalmandi.com<br>";
				
				// To send HTML mail, the Content-type header must be set
				$headers  = 'MIME-Version: 1.0' . "\r\n";
				$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
				// Additional headers
				//$headers .= 'To: ' "\r\n";
				$headers .= "From: admin@coalbazaar.com \r\n";				

				$sended=@mail($to, $subject, $message, $headers);
				$to        	= 	"shrinetrainfotech@gmail.com";
				$subject	=	"New User register with us";
				$message	= 	"Dear Admin,  <br><br>".
				
				"New user is registered with coalbazaar.com<br><br>".
				"Please login into admin panel and look it<br><br>".
				"Please click this link to activate your account:<br><br>".				
				
				"<br><br><strong style='font-size:18px;'>Thanks and Regards</strong><br><strong>Shrinetra Infotech</strong>";
				
				// To send HTML mail, the Content-type header must be set
				$headers  = 'MIME-Version: 1.0' . "\r\n";
				$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
				// Additional headers
				//$headers .= 'To: ' "\r\n";
				$headers .= "From: admin@coalbazaar.com \r\n";				

				$sended=@mail($to, $subject, $message, $headers);
					if($sended!='')	{
						@header('Location: registration.php?action=done');	
						exit;
					}
			}
		}
	} else {
		$error[] = 'Please fill correct code.';
	}
	}
}



?>
<script type="text/javascript" src="citySelection.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="JqueryLoader.js" type="text/javascript"></script>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.5/mootools-yui-compressed.js"></script>


<style type="text/css">
<!--
.style5 {color: #0000FF}
-->
</style>

<script>
var RecaptchaOptions = {
   theme : 'clean',
   lang : 'en',
   tabindex : 2
};
</script>

<!--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><?php if(isset($_GET['action'])){ echo "Registration Done"; } else { echo "Registration Form";(isset($_POST['radiobtn']))?"Registration Form":"Select Package"; } ?></h2>

<div class="err_msg"><?php ShowError($error); ShowInfo($info);?></div>				

<?php if(isset($_GET['action']) && $_GET['action'] == 'done') { ?>
		<div>Your account has been registered , <br /> <br /> Please verify it by clicking the activation link that has been send to your email.</div>
<?php // }  elseif(isset($_POST['radiobtn']) && ($_POST['radiobtn'] !='')){ 
} else { ?>
<div id="preloader"><img src="ajax-loader.gif" style="border:none;"/></div>
<form action=""  method="post" >
		<input type="hidden" name="radiobtn" value="<?=$_POST['radiobtn']?>" />
		<table width="100%">
				<tr>
						<td colspan="2" class="heading"> All mandatory fields are marked with <span class="style1">*</span></td>
				</tr>
				<tr>	
					<td height="8"></td>
				</tr>
				<tr>
						<td align="left" class="formtxt" style="width: 230px;">First Name<span class="style1">*</span></td>
						<td align="left" class="form_field"><input type="text" name="fname" id="fname" class="txt_box2" value="<?php echo $_POST['fname']; ?>" /></td>
				</tr>
				<tr>
						<td align="left" class="formtxt">Last Name<span class="style1">*</span></td>
						<td align="left" class="form_field"><input type="text" name="lname" id="lname" class="txt_box2" value="<?php echo $_POST['lname']; ?>" /></td>
				</tr>
				<tr>
						<td align="left" class="formtxt">Email<span class="style1">*</span></td>
						<td align="left" class="form_field"><input type="text" name="email" id="email" class="txt_box2" value="<?php echo $_POST['email']; ?>"/></td>
				</tr>
				<tr>
						<td align="left" class="formtxt">Password<span class="style1">*</span></td>
						<td align="left" class="form_field"><input type="password" name="password" id="password" class="txt_box2" value="<?php echo $_POST['password']; ?>" /></td>
				</tr>
				<tr>
						<td align="left" class="formtxt">Confirm Password<span class="style1">*</span></td>
						<td align="left" class="form_field"><input type="password" name="cpassword" id="cpassword" class="txt_box2" value="<?php echo $_POST['cpassword']; ?>" /></td>
				</tr>
				<tr>
						<td align="left" class="formtxt">Company Name<span class="style1">*</span></td>
						<td align="left" class="form_field"><input type="text" name="company_name" id="company_name" class="txt_box2" value="<?php echo $_POST['company_name']; ?>" /></td>
				</tr>
				<?php // if(isset($_POST['radiobtn']) && ($_POST['radiobtn'] !='1') ){ ?>
				<!--<tr>
						<td align="left" class="formtxt">Customer Receipt number<span class="style1">*</span></td>
						<td align="left" class="form_field"><input type="text" name="crn" id="crn" class="txt_box2" value="<?php echo $_POST['crn']; ?>"></td>
				</tr>
				<tr>
						<td colspan="2" align="right" id="checkcrn" style="margin-right:35px;"></td>
	 			<tr>-->
				<?php // } else { 
				$newcrn = date("y").date("m").date("d").rand(000,999);
				?>
				<tr>
						<td align="left" class="formtxt">Customer Receipt number<span class="style1">*</span></td>
						<td align="left" class="form_field"><input type="text" name="crn" class="txt_box2" value="<?php echo $newcrn; ?>" readonly="readonly"></td>
				</tr>
				<?php // } ?>
				<tr>
						<td align="left" class="formtxt">Address<span class="style1">*</span></td>
						<td align="left" class="form_field"><input type="text" name="address1" id="address1" class="txt_box2" value="<?php echo $_POST['address1']; ?>" /></td>
				</tr>
				<tr>
						<td align="left" class="formtxt">Country <span class="style1">*</span></td>
						<td align="left" class="form_field">
							<select id="country" name="country" class="txt_box2" onblur="change_country1(this.value)">
							<option value="">--Select Country--</option>
								<?php                    
									$obj1 = new DBClass();
									$sql2 = "SELECT * FROM ".TBL_OPTIONS." where `option`='Country' and `value`!='' and `status`=0 ORDER BY value ASC";
									$rs2 = $obj1->executeQry($sql2,$link);
									while($row2 = $obj1->fetchrow()){                 
								?>
									<option value="<?php echo $row2['value'];?>" <?php if($_POST['country'] == $row2['value']) echo 'selected'; ?>><?php echo $row2['value'];?></option>
							    <?php } ?>
								<option value="other">other</option>
							</select>
						</td>
				</tr>
				<tr id="othercountry" <?php if($_POST['country']!='other') { ?> style="display:none"<?php } ?>>
						<td align="left" class="formtxt">Country Name <span class="style1">*</span></td>
						<td align="left" class="form_field"><input type="text" name="othercountry"  class="txt_box2" value="<?php echo $_POST['othercountry']; ?>" /></td>
				</tr>
				<tr>
						<td align="left" class="formtxt">State<span class="style1">*</span></td>
						<td align="left" class="form_field">
								<select id="state" name="state" class="txt_box2" onblur="change_state(this.value)">
										<option selected="selected">--Select State--</option>
										<?php
											$sql2 = "SELECT DISTINCT(State) as State FROM ".TBL_STATE." where  State != '' ORDER BY State ASC";
											$rs2 = $obj1->executeQry($sql2,$link);
											while($row2 = $obj1->fetchrow()){
										?>
										<option value="<?php echo $row2['State'];?>" <?php if($_POST['state'] == $row2['State']) echo 'selected'; ?>><?php echo $row2['State'];?></option>
<?php } ?>
									    <option value="other">other</option>
								</select>
						</td>
				</tr>
				<tr id="otherstate" <?php if($_POST['state']!='other') { ?> style="display:none"<?php } ?>>
						<td align="left" class="formtxt">State Name <span class="style1">*</span></td>
						<td align="left" class="form_field"><input type="text" name="otherstate"  class="txt_box2" /></td>
				</tr>
				<tr>
						<td align="left" class="formtxt">District<span class="style1">*</span></td>
						<td align="left" class="form_field">
								<select id="city" name="city" class="txt_box2" onblur="change_city(this.value)">
										<option selected="selected">--Select District--</option>
										<?php
											$sql2 = "SELECT * FROM ".TBL_STATE." ORDER BY city ASC";
											$rs2 = $obj1->executeQry($sql2,$link);
											while($row2 = $obj1->fetchrow()){
										?>
										<option value="<?php echo $row2['city'];?>" <?php if($_POST['city'] == $row2['city']) echo 'selected'; ?>><?php echo $row2['city'];?></option>
										<?php } ?>
			                    		<option value="other">other</option>
								</select>
						</td>
				</tr>
				<tr id="othercity" <?php if($_POST['city']!='other') { ?> style="display:none"<?php } ?>>
						<td align="left" class="formtxt">Distirct Name <span class="style1">*</span></td>
						<td align="left" class="form_field"><input type="text" name="othercity"  class="txt_box2"/></td>
				</tr>
				<tr>
						<td align="left" class="formtxt">Zip/Pin Code<span class="style1">*</span></td>
						<td align="left" class="form_field"><input type="text" name="zip" id="zip" class="txt_box2" value="<?php echo $_POST['zip']; ?>" /></td>
				</tr>
				<tr>
						<td align="left" class="formtxt">Phone / Mobile No.<span class="style1">*</span></td>
						<td align="left" class="form_field"><input type="text" name="phone" id="phone" class="txt_box2" value="<?php echo $_POST['phone']; ?>" /></td>
				</tr>
				<tr>
						<td align="left" class="formtxt">Fax No.</td>
						<td align="left" class="form_field"><input type="text" name="fax" id="fax" class="txt_box2" value="<?php echo $_POST['fax']; ?>" /></td>
				</tr>
				<tr>
						<td colspan="2">&nbsp;</td>
				</tr>
			</table>
			<?php echo recaptcha_get_html($publickey); ?>
			<table>
				<tr>
						<td colspan="2">&nbsp;</td>
				</tr>
				<tr>
			  			<td colspan="2">
							<div align="justify"><input type="checkbox" name="terms" id="terms" checked="checked"/><span class="form_field" style="text-align:justify;">I accept all the terms and conditions mentioned in <a href="page.php?page=Public%20Disclosures" target="_blank" style="font-size:14px;color:blue;">public discloser</a>.</span>
							</div>
						</td>
				</tr>
				<tr>
						<td colspan="2">&nbsp;</td>
				</tr>
				<tr>
						<td align="left" style="margin-left:5px;"><input type="submit" class="login_btn" name="submit" id="submit" value="Register" /></td>
				</tr>
		</table>
</form>
<?php }  //} else { ?>
<!--<form action="" method="post">
<div class="row" style="margin-left:35px;margin-bottom: 46px;">
					
					<?php
					$sql2 = "SELECT * FROM ".TBL_PACKAGE." WHERE status = 0 ";		
					$rs2 = $obj1->executeQry($sql2,$link);		
					while($row2 = $obj1->fetchrow()){;	
					 ?>
						<div class="span4 pricing-table" style="width:225px;margin-top:30px;">
							<ul>
								<li class="pricing-header-row-1">
									<div class="package-title">
										<div class="title"><?php echo $row2['package_name']; ?></div>
										<h3 class="no-bold"  style="text-align:center"><?php echo $row2['package_type']; ?></h3>
									</div>
								</li>
								<li class="pricing-header-row-2">
									<div class="package-price">
										<h1 class="no-bold">Rs.<span><?php echo $row2['package_amount']; ?></span> <!-- span class="cents"><TMPL_VAR currency_code></span </h1>
										<p class="cents" style="text-align:center">Rs.<?php echo $row2['package_amount']; ?>/ <?php echo $row2['package_days']; ?> days</p>
										
									</div>
								</li>
								<li class="pricing-header-row-2">
									<div class="package-price">
										<p class="cents" style="text-align:center;word-wrap: break-word;padding-left:5px;padding-right:5px;"><?php echo $row2['package_desc']; ?></p>
									</div>
								</li>
								<li class="pricing-footer" style="font-size:11px;"><input type="radio" name="radiobtn" value="<?php echo $row2['id']; ?>" /></li>
							</ul>
						</div>
					<?php } ?>
						
				
					</div> <!--row
<input type="submit" name="submit" value="Next >>" style="margin-top: -41px;padding: 10px 10px 10px 10px;width: 100px;font-size: 16px;float: left;margin-left: 424px;"/>	
</form>
-->
<?php // } ?>

						</div>
						<div style="text-align:center"> <br />
OR<br />

<a href="/facebook/index.php?login&amp;oauth_provider=facebook" title="Coalbazaar facebook login"><img src="images/fbsignup.gif" style="margin-left: 220px;
margin-bottom: 20px;background: none;border: none;margin-top: 20px;float: left;" title="Coalbazaar facebook login" alt="Coalbazaar facebook login"></a></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');?>