<?php 
$active = 'Buy Fuel';
$pageName = 'expert help';

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

include('hitCounter.php');

$obj9 = new DBClass();
$obj = new DBClass();

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

        $valid = validmess($_POST['commodity'], "Commodity"); if(isset($valid) && $valid != ''){ $error[] = $valid;}
        $valid = validmess($_POST['origin'], "Origin"); if(isset($valid) && $valid != ''){ $error[] = $valid;}
        $valid = validmess($_POST['gcv'], "Gross Calorifie Value"); if(isset($valid) && $valid != ''){ $error[] = $valid;}        
        $valid = validmess($_POST['supply_destination'], "Supply Destination"); if(isset($valid) && $valid != ''){ $error[] = $valid;}		
		$valid = checkName($_POST['name'], "Name"); if(isset($valid) && $valid != ''){ $error[] = $valid;}        
        $valid = validmess($_POST['contact'], "Mobile / Phone"); if(isset($valid) && $valid != ''){ $error[] = $valid;}
        $valid = checkEmail($_POST['email'], "Email Id"); if(isset($valid) && $valid != ''){ $error[] = $valid;}        
        $valid = validmess($_POST['address'], "Address"); if(isset($valid) && $valid != ''){ $error[] = $valid;}

		
     if(($_POST['port'] == 'other')) {            
          $valid = validmess($_POST['otherport'], "port"); if(isset($valid) && $valid != ''){ $mess[] = $valid;} 
          $port = $_POST['otherport'];
        }
        else {
          $port = $_POST['port'];
        }
        
     
     if(($_POST['commodity'] == 'other')) {            
          $valid = validmess($_POST['othercommudity'], "Commudity"); if(isset($valid) && $valid != ''){ $mess[] = $valid;} 
          $commodity = $_POST['othercommudity'];
        }
        else {
          $commodity = $_POST['commodity'];
        }
	 

	if($error == ''){
		
		if($_REQUEST['commodity'] =='Coal') {
			if($_REQUEST['origin'] =='Indian') {
				// COAL INDIAN
				$port = '';
				$_POST['noncoal_state'] = '';
				$_POST['noncoal_district'] = '';
				$_POST['noncoal_port'] = '';				
			}
			else {
				// COAL IMPORTED
				$_POST['area'] = '';
				$_POST['noncoal_state'] = '';
				$_POST['noncoal_district'] = '';
				$_POST['noncoal_port'] = '';
				$_POST['mines_name'] = '';
			}
		}
		else {
			if($_REQUEST['origin'] =='Indian') {
				// NON COAL INDIAN
				$_POST['area'] = '';
				$port = '';
				$_POST['noncoal_port'] = '';
				$_POST['mines_name'] = '';
			}
			else {
				// NON COAL IMPORTED
				$_POST['area'] = '';
				$port = '';
				$_POST['mines_name'] = '';
			}			
		}
        $sql5 = "INSERT INTO ".TBL_EXPERT." (name,organizaion,contact,address,email,commodity,origin,mines_name,area,port,noncoal_state,noncoal_district,noncoal_port,size, gcv,tm,ash,sulpher,supply_destination,comment) VALUES ('".trim($_POST['name'])."','".trim($_POST['organizaion'])."','".$_POST['contact']."','".trim($_POST['address'])."','".trim($_POST['email'])."','".trim($commodity)."','".trim($_POST['origin'])."','".trim($_POST['mines_name'])."','".trim($_POST['area'])."','".trim($port)."','".trim($_POST['noncoal_state'])."','".trim($_POST['noncoal_district'])."','".trim($_POST['noncoal_port'])."','".trim($_POST['size'])."','".trim($_POST['gcv'])."','".trim($_POST['tm'])."','".trim($_POST['ash'])."','".trim($_POST['sulpher'])."','".trim($_POST['supply_destination'])."','".trim($_POST['comment'])."') ";
    	
        $rs2 = $obj->executeQry($sql5,$link);
        
      	if($rs2){			
			// *********************** start  mail to admin *****************
			$to        	= 	'shrinetrainfotech@gmail.com';
			$subject	=	"Expert help require ".@$_POST['name'];
			$message	= 	"The Details are  :-               <br>".
			"--------------------------------------------------------------------------------<br>".
			"Name		: ".@$_POST['name']. "  		<br>".
			"Email Address 	: ".@$_POST['email']. "  	  <br>".		
			"Mobile / Phone		 	: ".@$_POST['contact']. "  	  <br>".		
			"Address		 	: ".@$_POST['address']. "  	  <br>".		
			"Organization 	: ".@$_POST['organizaion']. "  	  <br>".		
			"Message	: ".@$_POST['comment']. "  	<br>".
			"--------------------------------------------------------------------------------<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: '.$_POST['name'].'<'.$_POST['email'].'>' . "\r\n";
			@$sended=mail($to, $subject, $message, $headers);	
			
			@header('Location: expert.php?action=done');
			exit;
			
		}
	}
}

?>
<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>
<script type="text/javascript" src="citySelection.js"></script>


<script type="text/javascript">
function change_port(val){
    if(val=='other') {
		document.getElementById('otherport').style.display='';
	}
	else {
		document.getElementById('otherport').style.display='none';	
	}
}

function changeCommudity(val){
    if(val=='other') {
		document.getElementById('othercommudity').style.display='';
	}
	else {
		document.getElementById('othercommudity').style.display='none';	
	}
	
	if(val=='Coal') {
		document.getElementById('coalselection').style.display='';
		document.getElementById('coalselection1').style.display='';		
	}
	else {
		document.getElementById('coalselection').style.display='none';	
		document.getElementById('coalselection1').style.display='none';
	}
	
	if(val!='Coal') {
		document.getElementById('othercoal').style.display='';
		document.getElementById('othercoal1').style.display='';
		document.getElementById('othercoal2').style.display='';
	}
	else {
		document.getElementById('othercoal').style.display='none';	
		document.getElementById('othercoal1').style.display='none';
		document.getElementById('othercoal2').style.display='none';			
	}
}


function change_origin1(val) {
	if(val=='Indian') {
		document.getElementById('area').style.display='';
		document.getElementById('port').style.display='none';
        document.getElementById('area1').style.display='';
		document.getElementById('area3').style.display='';
		document.getElementById('port1').style.display='none';
		document.getElementById('noncoal').style.display='none';
		document.getElementById('noncoal1').style.display='none';		
        document.getElementById('area2').style.display='';
	}
	else {
		document.getElementById('area').style.display='none';
		document.getElementById('port').style.display='';
        document.getElementById('area1').style.display='none';
        document.getElementById('area3').style.display='none';		
		document.getElementById('port1').style.display='';	
        document.getElementById('area2').style.display='none';
		document.getElementById('noncoal').style.display='';
		document.getElementById('noncoal1').style.display='';			
	}
}
</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>Expert Help</h2>
						
<?php 
if(isset($_GET['action'] ) && $_GET['action'] == "done")  {
?>
<div>Your Requirement has been registered , <br /> <br /> We will reply you soon..</div>
<?php  } else { ?>
<div id="preloader" style="margin-top:120px;"><img src="ajax-loader.gif"  style="border:none;"/></div>	



		<form name="contact" method="POST" action="">
				<table>
						<tr>
								<td colspan="2"><h3>Send your requirement</h3><hr /></td>
						</tr>
						<tr>
								<td colspan="2" height="8"><div class="err_msg"><?php ShowError($error); ShowInfo($info);?></div></td>
						</tr>
					    <tr>
						        <td>Commodity<span class="style1">*</span></td>
							    <td>
										<select name="commodity" class="txt_box2" onchange="changeCommudity(this.value)">
											<option value="">-- Select Commodity --</option>
												<?php 
												$obj1 = new DBClass();
												$sql2 = "SELECT * FROM ".TBL_OPTIONS." where `option`='Commodity' 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['commodity'] == $row2['value']) echo 'selected'; ?>><?php echo $row2['value'];?></option>
												<?php } ?>
											<option value="other">Other</option>
									</select>
								</td>
				    </tr>
					 <tr id="othercommudity" <?php if(($_POST['commodity']=='') || ($_POST['commodity'] != 'other')) { ?>style="display:none"<?php } ?>>
								<td class="formtxt">Other Commodity Name</td>
								<td><input  type="text" class="txt_box2" name="othercommudity" value="<?php echo $_POST['othercommudity']; ?>" /></td>
					</tr>
				    <tr>
        					<td class="formtxt">Origin<span class="style1">*</span></td>
        					<td>
									<select name="origin" onchange="change_origin1(this.value)" class="txt_box2">
											<option value="">-- Select Origin --</option>
												<?php 
													$sql2 = "SELECT * FROM ".TBL_OPTIONS." where `option`='origin' 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['origin'] == $row2['value']) echo 'selected'; ?>><?php echo $row2['value'];?></option>
<?php } ?>
									</select>
							</td>
				    </tr>
	
					<!-- State -->
					<tr id="othercoal" <?php if(($_POST['commodity'] == 'Coal') || ($_POST['commodity'] == '')) { ?> style="display:none"<?php } ?>>
							<td>State</td>
							<td>
									<select name="noncoal_state" class="txt_box2" id="state">
        									<option value="">--Select State--</option>
											<?php 
												$obj1 = new DBClass();
												$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['noncoal_state'] == $row2['State']) echo 'selected'; ?>><?php echo $row2['State'];?></option>
										<?php } ?>
								    </select>
							</td>
				</tr>
	
				<!-- District-->
				<tr id="othercoal1" <?php if(($_POST['commodity'] == 'Coal') || ($_POST['commodity'] == '')) { ?> style="display:none"<?php } ?>>
							<td>District</td>
							<td>
									<select id="city"  name="noncoal_district" class="txt_box2">
											<option value="">--Select District--</option>
											<?php
											$obj1 = new DBClass();
											$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['noncoal_district'] == $row2['city']) echo 'selected'; ?>><?php echo $row2['city'];?></option>
											<?php } ?>
							 		 </select> 
							</td>
				</tr>
				<!-- Port -->
				<tr id="othercoal2" <?php if(($_POST['commodity'] == 'Coal') || ($_POST['commodity'] == '') || ($_POST['origin'] == 'Indian')) { ?> style="display:none"<?php } ?>>
							<td id="noncoal">Enter Port name</td>
							<td id="noncoal1"><input class="txt_box2"  type="text" name="noncoal_port" value="<?php echo $_POST['noncoal_port']; ?>" /></td>
				</tr>
	
    			<tr id="coalselection" <?php if($_POST['commodity'] != 'Coal') { ?> style="display:none"<?php } ?>>
        					<td class="formtxt">
									<span id="area1" <?php if($_POST['origin']=='Imported') { ?> style="display:none"<?php } ?>>Area/Mines</span>
									<span id="port1" <?php if($_POST['origin']!='Imported') { ?> style="display:none"<?php } ?>>Port</span>
							</td>
       						 <td>
									<span id="area" <?php if($_POST['origin']=='Imported') { ?> style="display:none"<?php } ?>>
											<select name="area" class="txt_box2">
													<option value="">Area/Mines</option>
															<?php 
															$sql2 = "SELECT * FROM ".TBL_OPTIONS." where `option`='area' 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['area'] == $row2['value']) echo 'selected'; ?>><?php echo $row2['value'];?></option>
													<?php } ?>

											</select>
									</span>
									
									<span id="port" <?php if($_POST['origin']!='Imported') { ?> style="display:none"<?php } ?>>
											<select name="port" onchange="change_port(this.value)" class="txt_box2">
													<option value="">Ports</option>
													<?php 
														$sql2 = "SELECT * FROM ".TBL_OPTIONS." where `option`='Port' 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['port'] == $row2['value']) echo 'selected'; ?>><?php echo $row2['value'];?></option>
													<?php } ?>
													<option value="other">Other</option>
											</select>
									</span>
								</td>
				    </tr>
    				<tr id="otherport" <?php if(($_REQUEST['port']=='') || ($_REQUEST['port'] != 'other') || ($_REQUEST['origin']) != 'Imported') { ?> style="display:none" <?php } ?>>
        						<td class="formtxt">Other Port Name</td>
						        <td><input  type="text" class="txt_box2" name="otherport" value="<?php echo $_POST['otherport']; ?>" /></td>
				    </tr>
   
    				<tr id="coalselection1" <?php if($_POST['commodity'] != 'Coal') { ?> style="display:none"<?php } ?>>
        						<td id="area2" class="formtxt">Mines Name</td>
						        <td  id="area3" ><input class="txt_box2" type="text" name="mines_name" value="<?php echo $_POST['mines_name']; ?>" /></td>
				    </tr>
				    <tr>
					        <td class="formtxt">Size</td>
					        <td>
									<select name="size" class="txt_box2">
										<option value="">-- Select -- </option>
											<?php 
											$sql2 = "SELECT * FROM ".TBL_OPTIONS." where `option`='size' 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['size'] == $row2['value']) echo 'selected'; ?>><?php echo $row2['value'];?></option>
											<?php } ?>
									</select>
							</td>
				   </tr>
					<tr>
							  <td>GCV (A.D.Basis)<span class="style1">*</span></td>
							  <td><input class="txt_box2"  type="text" name="gcv" value="<?php echo $_POST['gcv']; ?>" /></td>
				   </tr>
				   <tr>
							  <td>TM (A.R.Basis)</td>
							   <td><input class="txt_box2"  type="text" name="tm" value="<?php echo $_POST['tm']; ?>" /></td>
					</tr>
					<tr>
							<td>ASH(A.D.Basis)</td>
							<td><input class="txt_box2" type="text" name="ash" value="<?php echo $_POST['ash']; ?>" /></td>
					</tr>
					<tr>
							<td>Sulphur</td>
							<td ><input class="txt_box2" type="text" name="sulpher" value="<?php echo $_POST['sulpher']; ?>" /></td>
							 
					</tr>
					<tr>
							<td>Supply Destination<span class="style1">*</span></td>
							<td><input class="txt_box2" type="text" name="supply_destination" value="<?php echo $_POST['supply_destination']; ?>" /></td>
					</tr>
					<tr>
							<td colspan="2" height="5"></td>
					</tr>
					<tr>
							<td colspan="2"><h3>Personal details</h3><hr /></td>
					</tr>
					<tr>
							<td colspan="2" height="8"></td>
					</tr>
					 <tr>
							<td>Name<span class="style1">*</span></td>
							<td ><input class="txt_box2" type="text" name="name" value="<?php echo $_POST['name']; ?>" /></td>
							 
					</tr>
					 <tr>
							<td>Organization</td>
							<td ><input class="txt_box2" type="text" name="organizaion" value="<?php echo $_POST['organizaion']; ?>" /></td>
					</tr>
					 <tr>
							<td>Mobile / Phone No.<span class="style1">*</span></td>
							<td ><input class="txt_box2" type="text" name="contact" value="<?php echo $_POST['contact']; ?>" /></td>
					</tr>
					 <tr>
							<td>Email ID<span class="style1">*</span></td>
							<td ><input class="txt_box2" type="text" name="email" value="<?php echo $_POST['email']; ?>" /></td>
					</tr>
					 <tr>
							<td>Address<span class="style1">*</span></td>
							<td ><input class="txt_box2" type="text" name="address" value="<?php echo $_POST['address']; ?>" /></td>
					</tr>
					 <tr>
							<td valign="top">Requirement Details<span class="style1">*</span></td>
							<td ><textarea class="txt_box2" cols="30" rows="3" name="comment"><?php echo $_POST['comment'];?></textarea></td>
					</tr>
					<tr>
							<td colspan="2" height="5"></td>
					</tr>
					<tr>
							<td><input type="submit" name="submit" class="login_btn" value="Send" /></td>
							<td>&nbsp;</td>
					</tr>
			</table>
		</form>

<?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');?>