All pastes #2053906 Raw Edit

Anonymous

public text v1 · immutable
#2053906 ·published 2011-05-04 17:44 UTC
rendered paste body
<?php
function ppms_job_form_alter(&$form, $form_state, $form_id)
{
   if ($form_id == 'job_application_node_form')
   {
   
      $form['buttons']['submit']['#value'] = t("Submit");
	  $form['#validate'][] = 'ppms_job_validate'; //Be sure not to use 'form' for the 'functionName' part as it will confuse drupal.  Use a descriptive name.
      $form['#submit'][] = 'ppms_job_submit';  //Be sure not to use 'form' for the 'functionName' part as it will confuse drupal.  Use a descriptive name.
   }
}

function getPage($url, $referer, $timeout){
 if(!isset($timeout))
 $timeout=30;
 $curl = curl_init();
 if(strstr($referer,"://")){
 curl_setopt ($curl, CURLOPT_REFERER, $referer);
 }
 curl_setopt ($curl, CURLOPT_URL, $url);
 curl_setopt ($curl, CURLOPT_TIMEOUT, $timeout);
 curl_setopt ($curl, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5)));
 curl_setopt ($curl, CURLOPT_HEADER, (int)$header);
 curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
 $html = curl_exec ($curl);
 curl_close ($curl);
 return $html;
 }

function ppms_job_validate($form, &$form_state)
{	
	$category=$form['field_jobs_category']['tids']['hierarchical_select']['selects'][1];
	$cat=$form['field_jobs_category']['tids']['hierarchical_select']['selects'][1]['#options']['label_1'];
	//print $cat;
	
	//
	
	$firstname= $form['field_firstname'][0]['value']['#value'];
	$pin=$form['field_pin_number'][0]['value']['#value'];
	
	$send_pin=$form['#value']['field_pin_number'][0]['value'];
	$request_headers = array('Content-Type' => 'application/x-www-form-urlencoded');
	$request_method = 'POST';
	$request_retry = 1;
	$data = '';
	$embed_url = 	"http://www.etranzact.net:8080/WebConnect/queryPayoutletTransaction.jsp?TERMINAL_ID=0690000132&CONFIRMATION_NO=".$pin;
  
	
			
			$result = file_get_contents($embed_url);
			  
   // $result=fopen("http://www.etranzact.net:8080/WebConnect/queryPayoutletTransaction.jsp?TERMINAL_ID=0690000132&CONFIRMATION_NO=".$pin, "r");
		//print $result;
   
		if (strpos($http_response_header[0], "200")) { 
			if(isset($result)){
				if ($result == -1){
				//print $cat;
     				form_set_error('field_pin_number',	t("$firstname, $pin is an invalid pin number."));
				}
				if($result != -1){
						$temp= $form['field_jobs_category']['tids']['hierarchical_select']['selects'][1]['#value']; 
						$cat = $form['field_jobs_category']['tids']['hierarchical_select']['selects'][1]['#options'][$temp];
						$my_result = ltrim(trim($result));
						foreach (explode('&', $my_result) as $each_set)
						{
							$tmp_data = explode('=', $each_set);
							$package[$tmp_data[0]] = $tmp_data[1];
						}
						$count = 0;
                		$status = '0';
						
					 	$customer_id = isset($package['CUSTOMER_ID'])?$package['CUSTOMER_ID']:'';
						$fullname = isset($package['CUSTOMER_NAME'])?$package['CUSTOMER_NAME']:'';
						$receipt_no = isset($package['RECEIPT_NO'])?$package['RECEIPT_NO']:'';
						$confirm_code = isset($package['PAYMENT_CODE'])?$package['PAYMENT_CODE']:'';
						$descr = isset($package['TRANS_DESCR'])?$package['TRANS_DESCR']:'';
						$bankcode = isset($package['BANK_CODE'])?$package['BANK_CODE']:'';
						$branchcode = isset($package['BRANCH_CODE'])?$package['BRANCH_CODE']:'';
						$trans_amount = isset($package['TRANS_AMOUNT'])?$package['TRANS_AMOUNT']:'';
						
						
						//form_set_error('field_jobs_category',	t("customer id $customer_id, fullname $fullname, Receipt No $receipt_no  confirm_code $confirm_code 
						//descr $descr  bankcode $bankcode branchcode $branchcode trans_amount $trans_amount$pin is an invalid pin number."));
						
						
						
						$CategoryA = array('Personnel Manager','Personnel Officers','Admin Manager','Public Relation Manager','Chief Accountant','IT Managers','Public Relation Officers');
						$CategoryB = array('Civil Enforcement Supervisors','Civil Enforcement Officers','Civil Enforcement Assistants', 'Accountants','Account Officers','Human Resource Officers','Database Administrators','Desktop Support Officers','Mobile and Desktop Support','Desktop Support Officers','Web Administrators','Legal Officers','Marketing Executives','Admin Officers','Secretaries','Front Desk Officers','Receptionists');
						$CategoryC=array('Towing Vehicle Drivers','Clamping Vehicle Drivers','Drivers/Mechanics','Cashiers','Office Assistants');
	 

						
						//Check if amount paid by applicant  corresponds to chosen job category
						//print($trans_amount);
						//print($cat);
								if ($trans_amount =="3000.0"){
									
									if (in_array(trim($cat), $CategoryA)){
										//ignore and move on
									}
									else{
										form_set_error('field_jobs_category',	t("Amount does not cover applying for the position $cat, Please <a href='http://ppmslimited.com/contact'> send us an email</a> if this problem persits"));
									}
							}
								if ($trans_amount =="2500.0"){
									
									if (in_array(trim($cat), $CategoryB)){
									
									}
									else{
										form_set_error('field_jobs_category',	t("Amount does not cover applying for the position $cat, Please <a href='http://ppmslimited.com/contact'> send us an email</a> if this problem persits"));
									}
							}
								if ($trans_amount =="2000.0"){
									
									if (in_array(trim($cat), $CategoryC)){
									}
									else{
										form_set_error('field_jobs_category',	t("Amount does not cover applying for the position $cat, Please <a href='http://ppmslimited.com/contact'> send us an email</a> if this problem persits"));
									}
								}
							
							$trans_arr = array('2000.0','2500.0','3000.0');
							if (in_array(trim($trans_amount), $trans_arr)){
									//drupal_set_message(t("$trans_amount"));
									}
									else{
										//if the amount does not match the category chosen
											if(in_array(($cat),$CategoryA)){
												$amt_to_pay="N3,000.0";
											}
											if(in_array(($cat),$CategoryB)){
												$amt_to_pay="N2,500.0";
											}
											if(in_array(($cat),$CategoryC)){
												$amt_to_pay="N2,000.0";
											}
									form_set_error('field_jobs_category',	t("Amount paid not in range for position $cat, Please <a href='http://ppmslimited.com/contact'> send us an email</a> if this problem persits"));
									}
							
						
					
						
						

						
						
						
						 $result = db_query("select count(customer_id) from {pin_data} where customer_id='$customer_id' and confirm_code= '$confirm_code'");
						
						
						$count = db_result($result);
						//print($count);
						
						if($count>0){
								// Record already exist
								drupal_set_message(t("$firstname your card status: Used"));
								form_set_error('field_pin_number',t("Please check the PIN provided, it may not have been entered correctly"));
								
						}   
				}
		
			}
			
			}
			 
			 else { 
			
			  form_set_error('field_pin_number',t("$cat  Currently no response from verification server, please try agian much later or contact <a href ='http://ppmslimited.com/contact'>admin</a>"));
			}

			
			
	}


function ppms_job_submit($form, &$form_state)
{
	 $firstname= $form['field_firstname'][0]['value']['#value'];
	$pin=$form['field_pin_number'][0]['value']['#value'];
	$send_pin=$form['#value']['field_pin_number'][0]['value'];
	
	
	$request_headers = array('Content-Type' => 'application/x-www-form-urlencoded');
	$request_method = 'POST';
	$request_retry = 1;
	$data = '';
	$embed_url = 	"http://www.etranzact.net:8080/WebConnect/queryPayoutletTransaction.jsp?TERMINAL_ID=0690000132&CONFIRMATION_NO=".$pin;
  
	
			
			$result = file_get_contents($embed_url);
									    //$result=fopen("http://www.etranzact.net:8080/WebConnect/queryPayoutletTransaction.jsp?TERMINAL_ID=0690000132&CONFIRMATION_NO=".$pin, "r");
		//print $result;
		if (strpos($http_response_header[0], "200")) { 
			if(isset($result)){
				if ($result == -1){
     				form_set_error('field_pin_number',	t("selected $category,   $firstname Your Pin Number $pin has either been used or you may have not entered it correctly. Please check agian"));
				}
				if($result != -1){
						$my_result = ltrim(trim($result));
						foreach (explode('&', $my_result) as $each_set)
						{
							$tmp_data = explode('=', $each_set);
							$package[$tmp_data[0]] = $tmp_data[1];
						}
						$count = 0;
                		$status = '0';
						
					 	$customer_id =str_replace("%20"," ",isset($package['CUSTOMER_ID'])?$package['CUSTOMER_ID']:'');
						$fullname = str_replace("%20"," ",isset($package['CUSTOMER_NAME'])?$package['CUSTOMER_NAME']:'');
						$receipt_no = str_replace("%20"," ",isset($package['RECEIPT_NO'])?$package['RECEIPT_NO']:'');
						$confirm_code = str_replace("%20"," ",isset($package['PAYMENT_CODE'])?$package['PAYMENT_CODE']:'');
						$descr = str_replace("%20"," ",isset($package['TRANS_DESCR'])?$package['TRANS_DESCR']:'');
						$bankcode = str_replace("%20"," ",isset($package['BANK_CODE'])?$package['BANK_CODE']:'');
						$branchcode =str_replace("%20"," ", isset($package['BRANCH_CODE'])?$package['BRANCH_CODE']:'');
						$trans_amount = str_replace("%20"," ",isset($package['TRANS_AMOUNT'])?$package['TRANS_AMOUNT']:'');
						
						
						
						$CategoryA = array('Personnel Manager','Personnel Officers','Admin Manager','Public Relation Manager','Chief Accountant','IT Managers','Public Relation Officers');
						$CategoryB = array('Civil Enforcement Supervisors','Civil Enforcement Officers','Civil Enforcement Assistants','Accountants','Account Officers','Human Resource Officers','Data Base Administrator','Desktop Support Officers','Mobile and Desktop Support','Desktop Support Officer','Web Administrators','Legal Officers','Marketing Executives','Admin Officers','Secretaries','Front Desk Officers','Receptionists');
						$CategoryC=array('Towing Vehicle Drivers','Clamping Vehicle Drivers','Drivers/Mechanics','Cashiers','Office Assistants');
	 
 					
					$result = db_query("select count(customer_id) from {pin_data} where customer_id='$customer_id' and confirm_code= '$confirm_code'"); 
					
					 
						 $count = db_result($result);
							 
							if($count>0){
								form_set_error('field_pin_number',t("Please check the PIN, it may not have been entered correctly"));
								
							}
							else{
                        		//print($count);
								 $insert_sql = db_query("insert into {pin_data}(customer_id,fullname,receipt_no,confirm_code,description,amount,bankcode,branchcode,status) values('$customer_id','$fullname','$receipt_no','$confirm_code','$descr',$trans_amount,'$bankcode','$branchcode',0)");   
								if(db_affected_rows() > 0){
										drupal_set_message(t("Congrats %firstname, your application has been successfully submitted, ",array('%firstname' => $firstname)));
								}
								else{
											drupal_set_message(t('Hi $firstname, your application has not been submitted please try agin or <a href="http://www.ppmslimited.com/contact" title="Send us a message">send us a message</a>'));
											form_set_error('field_jobs_category',	t(""));
										}
								}
							}
		
			}
			
			}
			 
			 else { 
			  form_set_error('field_pin_number',t('Currently no response from verification server, please try again much later or contact <a href ="http://www.ppmslimited.com/contact">admin</a>'));
			}

			
			
	}