Location: PHPKode > projects > JobAppr > Jobappr-1.4/complete.php
<?php
session_start();
require_once('includes/functions.php');
$error=null;

if (isset($_GET['id'])) {
	$id = $_GET['id'];
} else {
	header('Location: post.php');
}

# validate id is still in need of purchasing
if ($id && !isset($_POST['submit'])) {	
	$select = "SELECT * FROM ".TB_JOBS." WHERE form_id='".clean($id)."' AND preview IS NOT NULL AND completed IS NULL";
	$result = mysql_query($select);
	$count = mysql_num_rows($result);
	# check to verify it was already previewed, but not yet completed
	if($count == 1) {
		$row = mysql_fetch_assoc($result);
	} else {
		$error.= 'That job ID does not exist';
		header('Location: post.php');
	}
}


require_once('paypal/paypal.class.php'); 
$paypal = new paypal_class;
$paypal->paypal_url = 'https://www.paypal.com/cgi-bin/webscr';     // paypal url
	switch ($_GET['action']) { 
    case 'success':      // Order was successful...
      $success = "The PayPal transaction completed successfully";
			$pagebody = '<h3>Congratulations!</h3><p>Your job purchase has completed successfully. Please <a href="mailto:'.meta('paypal_email').'">contact us</a> if there are any questions.</p>';
			
			# update database to replace completed flag with timestamp, then redirect to completed/receipt page
			mysql_query("UPDATE ". TB_JOBS ."	SET completed='".clean(date("D M j G:i:s T Y"))."' WHERE form_id='".$id."'");
			if (mysql_error()) { $error .= "Database entry failed: ". mysql_error(); };
		break;
      
    case 'cancel':       // Order was canceled...
      $error = "The PayPal transaction was canceled";
      $pagebody = '<h3>Transaction Cancelled</h3><p>If you want to create a new job ad, you can <a href="post.php">restart the process here</a>.</p>';
			
			# delete job ad since it was cancelled
			#mysql_query("DELETE FROM ".TB_JOBS." WHERE form_id='".clean($id)."' AND preview is NOT NULL AND completed IS NULL");
			#if (mysql_error()) { $error .= "Database entry failed: ". mysql_error(); };
		break;
      
   	case 'ipn':          // Paypal is calling page for IPN validation...
   	  if ($paypal->validate_ipn()) {		  
				//creating message for sending
				$headers  = "MIME-Version: 1.0\n";
				$headers .= "Content-type: text/html; charset=utf-8\n";
				$headers .= "From: '".meta('site_name')."' <".meta('paypal_email')."> \n";
				$subject = "New Payment Received";
				$message =  "New payment was successfully recieved through paypal payment terminal \n";
		    $message .= "from ".$paypal->pp_data['payer_email']." on ".date('m/d/Y');
		    $message .= " at ".date('g:i A');	
				mail($admin_email,$subject,$message,$headers);
      }
      break;
 }     

?>
<?php get_template('header', 'Transaction Complete'); ?>

	<div id="main">
		<!-- main content data -->
		<?php echo $pagebody; ?>
	</div>
	
	<div id="sidebar">
		<!--
		<div class="inner">
			<h2>Hint</h2>
			Lorem Ipsum
		</div> 
		-->
	</div>


<?php get_template('footer'); ?>
Return current item: JobAppr