register_api_key($postdata); /****Start error checking*****/ //check if empty response from api response with service unavailable message if(empty($post_response)){ echo '

Sorry, Service Unavailable.'; echo ' Please try again later

'; die(); } //if not empty response try whether it is xml, if not response with service unavailable message try{ $xml = @new SimpleXMLElement($post_response); //check if there is status code, if not it is probably 404 or 503 apache html response if(empty($xml->status['code'])){ echo '

Sorry, Service Unavailable.'; echo ' Please try again later

'; die(); } } catch(Exception $e) { //xml error message of unable to parse string as xml //$message = $e->getMessage(); //response with service unavailable message echo '

Sorry, Service Unavailable.'; echo ' Please try again later

'; die(); } /*********end error checking************/ //get status code 400 error 200 ok $status_code = $xml->status['code']; if($status_code == '500'){//server internal error //echo error message echo "
"; echo "

Sorry, registration was not successful. Please try again later.

"; echo "
"; }//end foreach if($status_code == '400'){// error //parse error message response and show to user $status_message = "

The following needs your attention!

    "; foreach ($xml->status->messages->message as $mess){ $status_message .= "
  1. ".$mess."
  2. "; } $status_message .= "
"; echo $status_message; }//end foreach if($status_code == '200'){// success $response_api_key = $xml->id; $response_username = $xml->login; //cast xml object into array $response_api_key_array = (array)$response_api_key; //assign index [0] which is the api key to updated into option $update_in_option_apikey = $response_api_key_array[0]; $response_username_array = (array)$response_username; $update_in_option_username = $response_username_array[0]; update_option('agent_apikey',$update_in_option_apikey); update_option('agent_username',$update_in_option_username); //echo script to hide admin warning echo""; $admin_setting_url = admin_url()."options-general.php?page=agentrank_option"; //echo success message in header! echo "
"; echo "

Your registration was successful! Please click here to setup remaining options.

"; echo "
"; }//end foreach }//end if(isset($_POST['process_register_form'])== 'yes_process') /**process API reminder form!*********************/ if(isset($_POST['process_reminder_form'])== 'yes_process'){ $nonce_value = $_POST['_wpnonce']; if (!wp_verify_nonce($nonce_value, 'agent_ajax_nonce') ) die('Failed Security check'); $email = $_POST['email']; global $agapi; $xml = $agapi->get_username_reminder($email); //check if empty response from api response with service unavailable message if(empty($xml)){ echo '

Sorry, Service Unavailable.'; echo ' Please try again later

'; die(); } //get status code $status_code = $xml->status['code']; if($status_code == '500'){//server internal error //echo error message echo "
"; echo "

Sorry, Service Unavailable. 3 Please try again later.

"; echo "
"; }//end foreach if($status_code == '400'){// error //parse error message response and show to user $status_message = "

The following needs your attention!

    "; foreach ($xml->status->messages->message as $mess){ $status_message .= "
  1. ".$mess."
  2. "; } $status_message .= "
"; echo $status_message; }//end foreach if($status_code == '404'){// error //parse error message response and show to user $status_message = "

The following needs your attention!

    "; foreach ($xml->status->messages->message as $mess){ $status_message .= "
  1. ".$mess."
  2. "; } $status_message .= "
"; echo $status_message; }//end foreach if($status_code == '200'){// success $message = $xml->status->messages->message; //echo success message in header! echo "
"; echo "

$message, Please click here to setup remaining options.

"; echo "
"; }//end foreach }//end if(isset($_POST['process_reminder_form'])== 'yes_process') ?>