validated_invoices) return 0; return count($this->validated_invoices); } function path($invoices) { return "http://api.assetstore.unity3d.com/publisher/v1/invoice/verify.json?key=".get_option("as_pub_key")."&invoice=$invoices" ; } function validate_invoices($invoices) { $this->validated_invoices = Array(); $path = $this->path($invoices); $unity_data = file_get_contents( $path ); $data = json_decode($unity_data); foreach($data as $key => $val) $this->validate_entry($key, $val); } function validate_entry($key, $val) { if ( is_array( $val ) ) { if ( count($val) > 0 ) foreach($val as $sub_entry) { $this->validate_entry($key, $sub_entry); } } else { $entry = new unity_invoice_data(); $entry->date = $val->date; $entry->refunded = !($val->refunded == "No"); $entry->invoice = $val->invoice; $entry->package = $val->package; $this->validated_invoices[] = $entry; } } function is_validated($invoice_no) { if ($invoice_no == "" || $this->validated_invoices == null) return false; foreach($this->validated_invoices as $invoice) if ($invoice->invoice == $invoice_no) return true; return false; } } function as_validate_form($invoice, $name, $email, $subject, &$message) { if (empty($name)) return "Name is required"; if (empty($subject)) return "Subject is required"; if (empty($message)) return "Message is required"; if (!is_email($email)) return "Email address is not valid"; $message = "
Product support request from $name [ $email ]:
$message
"; if (isset($_POST['skip'])) return ""; if (empty($invoice)) return "Please supply a valid invoice number(s) for the product(s) you require assistance with"; $invoice = str_replace(' ','',$invoice); $invoice = str_replace(',,',',',$invoice); // $invoice_count = count ( explode(',',$invoice) ); $invoices = new unity_invoices(); $invoices->validate_invoices($invoice); // if ($invoices->validated_invoices_count() != $invoice_count) return "One or more invoices were incorrect"; foreach($invoices->validated_invoices as $valid_invoice) if ($valid_invoice->refunded) return "Invoice {$valid_invoice->invoice} was refunded!"; $message .= "";
foreach($invoices->validated_invoices as $valid_invoice)
{
$message .= "$valid_invoice->invoice: ";
$message .= $valid_invoice->package . "
";
}
$message .= "
Contact form successfully sent
$error