<?php 
include_once("/srv/www/protected/db_access.php");

require_once("top_page.php"); ?>
		  <h1>LEASING INQUIRY FORM </h1>
		  <?php
		  function quote_smart($value) 
		  { 
				   // Stripslashes 
				   if (get_magic_quotes_gpc()) { 
					   $value = stripslashes($value); 
				   } 
				   // Quote if not a number or a numeric string 
				 // $value = mysql_real_escape_string($value); 
					
				   return $value; 
		  }
		  
		  function connectdb()
			{
			   //$host = "localhost";          
			   //$user = "cItYpLeX"; 
			   //$pass = "bwvKrq9FV9pW9GFf";     
			   $db = "cityplex_db";
				 
			   // open connection 
			   //mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 
				connect_cityplex();
				 
			   // select database 
			   mysql_select_db($db) or die ("Unable to select database"); 
			   
			}
			
		  //GET VALUES
		  $name = quote_smart($_POST["name"]);
		  $title = quote_smart($_POST["title"]);
		  $company = quote_smart($_POST["company"]);
		  $address1 = quote_smart($_POST["address1"]);
		  $address2 = quote_smart($_POST["address2"]);
		  $city = quote_smart($_POST["city"]);
		  $state = quote_smart($_POST["state"]);
		  $zip = quote_smart($_POST["zip"]);
		  $phone = quote_smart($_POST["phone"]);
		  $email = quote_smart($_POST["email"]);
		  $extra = quote_smart($_POST["extra"]);
		  $a_action = quote_smart($_POST['a_action']);
		  $adddate = date('Y-m-d H:i:s');
		  
		  if ($a_action == 'yes')
		 {
			//CHECK ERROR AND DISPLAY ERROR
			echo '<div style=\'display: 8;  width:400;background: #fafafa; margin: 0px 0px 0px 0px;  border: 1px solid #d8dfea; padding: 5px 5px 5px 5px;\'>';
			echo '<ul>';
			
			if(empty($name))
			{
				echo '<li>';
				echo '<font color=#990000"><p>Please enter a name</p></font>'; 
				echo '</li>';
				$check_name = 1;
			}
			if(empty($company))
			{
				echo '<li>';
				echo '<font color=#990000"><p>Please enter a company</p></font>'; 
				echo '</li>';
				$check_company = 1;
			}
			if(empty($phone))
			{
				echo '<li>';
				echo '<font color=#990000"><p>Please enter a phone number</p></font>'; 
				echo '</li>';
				$check_phone = 1;
			}
			if(empty($email))
			{
				echo '<li>';
				echo '<font color=#990000"><p>Please enter an email address</p></font>'; 
				echo '</li>';
				$check_email = 1;
			}
			if(!$email == "" && (!strstr($email,"@") || !strstr($email,"."))) 
			{
				echo '<li>';
				echo '<font color=#990000"><p>Please enter a valid e-mail address</p></font>'; 
				echo '</li>';
				$check_emailv = 1;
			}
			if(empty($extra))
			{
				echo '<li>';
				echo '<font color=#990000"><p>Please enter a space requirements and other needs</p></font>'; 
				echo '</li>';
				$check_extra = 1;
			}
			
			if($check_name != 1 && $check_company != 1 && $check_phone != 1 && $check_email != 1 && $check_extra != 1)
			{
				//INSERT IN DATABASE
				/*
				connectdb();
				$query_1 = "INSERT INTO leasing_form (id,name,title,company,address1,address2,city,state,zip,phone,email,extra,adddate) 
				VALUES ('0','$name','$title','$company','$address1','$address2','$city','$state','$zip','$phone','$email','$extra','$adddate')"; 
				$result_1  = mysql_query($query_1) or die ("Error in query_1: $query_1  . ".mysql_error()); 
				*/

									//SENT OUT MESSAGE TO EMAIL
									$message = "========================================================================== \n";
									$message .= "LEASING INQUIRY FORM - CityPlex  \n";
									$message .= "========================================================================== \n";
									$message .= "Today's Date: ".date('F j, Y g:i: a')."\n";
									$message .= "Name : ".$name."\n";
									$message .= "Title : ".$title."\n";
									$message .= "Company : ".$company."\n";
									$message .= "Address : ".$address1." ".$address2."\n";
									$message .= "City : ".$city."\n";
									$message .= "State : ".$state."\n";
									$message .= "Zip : ".$state."\n";
									$message .= "\n";
									$message .= "Phone: ".$phone."\n";
									$message .= "Email: ".$email."\n";
									$message .= "Extra: ".$extra."\n";
									$message .= "\n";
									$message .= "========================================================================== \n";
								   
									$subject = 'Leasing Inquiry Form - CityPlex';

									$from = 'From: Web Form (CityPlex) <contact@tulsatrinity.com>'."\r\n";
									
									$email_ok='yes';
									if ((substr_count($name,'http')>0) ) {$email_ok='no';}
									if ((substr_count($title,'http')>0) ) {$email_ok='no';}
									if ((substr_count($company,'http')>0) ) {$email_ok='no';}
									if ((substr_count($address1,'http')>0) ) {$email_ok='no';}
									if ((substr_count($address2,'http')>0) ) {$email_ok='no';}
									if ((substr_count($city,'http')>0) ) {$email_ok='no';}
									if ((substr_count($state,'http')>0) ) {$email_ok='no';}
									if ((substr_count($zip,'http')>0) ) {$email_ok='no';}
									if ((substr_count($phone,'http')>0) ) {$email_ok='no';}
									if ((substr_count($email,'http')>0) ) {$email_ok='no';}
									//if ((substr_count($extra,'http')>0) && (substr_count($extra,'oru.edu')<1) ) {$email_ok='no';}

									if ($email_ok == 'yes')
									{
										mail('mike@corporaterea.com', $subject, $message, $from);
									}
				
									
									//RIDERECT TO THANK YOU PAGE ////////////////////////////////////
									echo '<META HTTP-EQUIV="Refresh" CONTENT="0; URL=thankyou.html">';
									exit();
				}
				else
				{
					echo '</ul>';
					echo '</div>';
				}
			}
			
		  ?>
		  <form name="form1" method="post" action="leasing_inquiry_form.php">
		  <table class="style5" width="100%"  border="0" cellspacing="0" cellpadding="5">
            <tr>
              <td width="26%">Name:</td>
              <td width="74%">
                <input name="name" type="text" id="name" size="25" maxlength="50" value="<?php echo $name; ?>">
                <span class="style13">required</span>
				<?php if ($check_name == 1){ echo '<br><font color="red">(Please enter a name)</font>';}?>
             </td>
            </tr>
            <tr>
              <td>Title:</td>
              <td><input name="title" type="text" id="title" size="25" maxlength="50" value="<?php echo $title; ?>"></td>
            </tr>
            <tr>
              <td>Company:</td>
              <td><input name="company" type="text" id="company" size="25" maxlength="50" value="<?php echo $company; ?>">
                <span class="style13">required</span><?php if ($check_company == 1){ echo '<br><font color="red">(Please enter a company)</font>';}?>
				</td>
            </tr>
            <tr>
              <td>Street Address: </td>
              <td><input name="address1" type="text" id="address1" size="35" maxlength="100" value="<?php echo $address1; ?>"></td>
            </tr>
            <tr>
              <td>Address (cont): </td>
              <td><input name="address2" type="text" id="address2" size="35" maxlength="50" value="<?php echo $address2; ?>"></td>
            </tr>
            <tr>
              <td>City:</td>
              <td><input name="city" type="text" id="city" size="25" maxlength="50" value="<?php echo $city; ?>"></td>
            </tr>
            <tr>
              <td>State:</td>
              <td><input name="state" type="text" id="state" size="25" maxlength="50" value="<?php echo $state; ?>"></td>
            </tr>
            <tr>
              <td>Zip:</td>
              <td><input name="zip" type="text" id="zip" size="10" maxlength="20" value="<?php echo $zip; ?>"></td>
            </tr>
            <tr>
              <td>Phone Number:</td>
              <td><input name="phone" type="text" id="phone" size="20" maxlength="20" value="<?php echo $phone; ?>">
                <span class="style13">required</span>
				<?php if ($check_phone == 1){ echo '<br><font color="red">(Please enter a phone number)</font>';}?>
				</td>
            </tr>
            <tr>
              <td>Email Address:</td>
              <td><input name="email" type="text" id="email" size="20" maxlength="100" value="<?php echo $email; ?>">
                <span class="style13">required</span>
				 <?php if ($check_email == 1){ echo '<br><font color="red">(Please enter an email address)</font>';}?>
				 <?php if ($check_emailv == 1){ echo '<br><font color="red">(Please enter a valid email address)</font>';}?>
				</td>
            </tr>
            <tr>
              <td colspan="2">Space Requirements and other needs <span class="style13">required</span>
			 
			  </td>
            </tr>
            <tr>
              <td colspan="2">
                <textarea name="extra" cols="45" rows="5" id="extra"><?php echo $extra; ?></textarea>
              <?php if ($check_extra == 1){ echo '<br><font color="red">(Please enter a space requirements and other needs)</font>';}?>
			 </td>
            </tr>
            <tr>
              <td colspan="2">
                <input type="submit" name="Submit" value="Submit">
				<input type="hidden" name="a_action" value="yes">
             </td>
            </tr>
          </table>
		   <br>
          </form>
<?php require_once("bottom_page.php"); ?>