'a97z', 'dev' => '' ); /* ################################################################## ================================================================================================================ ===== NAME: JavaScript Includes ===== DESCRIPTION: ===== NOTES: ================================================================================================================ ################################################################## */ $ENGINE_SETTINGS['javascript_framework'] = array( 'live' => " ", 'dev' => " " ); ?>$value) { if (is_array($value)) { if (isset($value['live']) && isset($value['dev'])) { if ($ENGINE_SETTINGS['live_server']) { $ENGINE_SETTINGS[$key] = $value['live']; } else { $ENGINE_SETTINGS[$key] = $value['dev']; } } } } ?>$value1) { //level 2 array found if (is_array($value1)) { foreach($value1 as $name2=>$value2) { //level 3 array found - so destroy! if (is_array($value2)) { $_GET[$name1][$name2] = ''; } } } } foreach($_POST as $name1=>$value1) { //level 2 array found if (is_array($value1)) { foreach($value1 as $name2=>$value2) { //level 3 array found - so destroy! if (is_array($value2)) { $_POST[$name1][$name2] = ''; } } } } foreach($_COOKIE as $name1=>$value1) { //level 2 array found if (is_array($value1)) { foreach($value1 as $name2=>$value2) { //level 3 array found - so destroy! if (is_array($value2)) { $_COOKIE[$name1][$name2] = ''; } } } } /* ======================================================================================== */ //scans through array levels 1 and 2 and executes function on each entry function run_function_on_all_of_array($function_start, $function_end) { //$_GET foreach($_GET as $name1=>$value1) { //level 2 array found if (is_array($value1)) { foreach($value1 as $name2=>$value2) { eval("\$_GET[\$name1][\$name2] = {$function_start}\$value2{$function_end};"); } } else { eval("\$_GET[\$name1] = {$function_start}\$value1{$function_end};"); } } //$_POST foreach($_POST as $name1=>$value1) { //level 2 array found if (is_array($value1)) { foreach($value1 as $name2=>$value2) { @eval("\$_POST[\$name1][\$name2] = {$function_start}\$value2{$function_end};"); } } else { eval("\$_POST[\$name1] = {$function_start}\$value1{$function_end};"); } } //$_COOKIE foreach($_COOKIE as $name1=>$value1) { //level 2 array found if (is_array($value1)) { foreach($value1 as $name2=>$value2) { eval("\$_COOKIE[\$name1][\$name2] = {$function_start}\$value2{$function_end};"); } } else { eval("\$_COOKIE[\$name1] = {$function_start}\$value1{$function_end};"); } } } //Remove any magic quotes if (get_magic_quotes_gpc()) { run_function_on_all_of_array('stripslashes(', ')'); } //trim whitespace HTML run_function_on_all_of_array('trim(', ')'); //escape HTML run_function_on_all_of_array('htmlspecialchars(', ', ENT_QUOTES)'); //Escape % and _ for use in mysql queries that use LIKE alogn with new lines run_function_on_all_of_array('str_replace(\'\\\\\', \'\\', ', ')'); run_function_on_all_of_array('str_replace(\'\n\', \'\n\', ', ')'); run_function_on_all_of_array('str_replace(\'\r\', \'\r\', ', ')'); //Make DB Safe if (@mysql_real_escape_string('g')) { run_function_on_all_of_array('mysql_real_escape_string(', ')'); } else { die('Error escaping database information!'); } ?>get_sql_limit()); print $pagination->get_pagination(); */ //============================================================= //=== Class: pagination //=== Description: takes care of the hard work when creating pagination and can carry across variables between pages in the pages URL. Multiple instances of pagination can be used on a single page. //============================================================= class fg_class_pagination { //============================================================= //=== GLOBAL PROPERTIES //============================================================= private $instance = 'page'; private $total_per_page = 1; private $total_items = 1; private $total_pages = 1; private $current_page = 1; private $query_string = ''; //does not include a ? character //============================================================= //=== SET THE MAIN PROPERTIES //============================================================= function __construct($total_per_page, $total_items, $instance = 'page') { //Add some basic vars to the object $this->total_per_page = $total_per_page; $this->total_items = $total_items; $this->instance = $instance; //calculate some more basic vars $this->total_pages = ceil($total_items / $total_per_page); $this->current_page = isset($_GET[$this->instance]) ? intval($_GET[$this->instance]) : 1; //generate the query string $this->query_string = $this->get_query_string(); } //============================================================= //=== GET THE LIMIT NEEDED FOR SQL DATABASES //============================================================= function get_sql_limit() { return (($this->current_page-1) * $this->total_per_page) . ',' . $this->total_per_page; } //============================================================= //=== GENERATE THE HTML PAGINATION FOR PEOPLE TO CLICK //============================================================= function get_pagination() { //store the generated html $pages = ''; //generate the html for the pagination for ($counter = 1; $counter <= $this->total_pages; $counter++) { //see if this page is currently selected $selected_style = ($this->current_page == $counter ? ' style="font-weight:bold;color:green;"' : ''); //put together the html for this page number if ($counter == $this->total_pages) { //last page number $pages .= "query_string}{$this->instance}={$counter}'{$selected_style}>{$counter}"; } else { //more pages to come... $pages .= "query_string}{$this->instance}={$counter}'{$selected_style}>{$counter}, "; } } //return the generated html for the pagination return $pages; } //============================================================= //=== GETS THE QUERY STRING WITHOUT THE PAGINATION VARS //============================================================= private function get_query_string() { //get all the params $query_string = ''; foreach ($_GET as $key=>$value) { if ($key != $this->instance) { $query_string .= "{$key}={$value}&"; } } return $query_string; } } ?>convert_to_sandbox(); //verify the IPN $this->verify_ipn(); //record the transaction $this->log_transaction(); //make sure the basic vars exist in the IPN etc if ($this->ok_to_process_error == '') { //don't need to test because already found an error! $this->basic_ipn_authentication(); } //check it's from the web & not direct payment from within someones paypal account if ($this->ok_to_process_error == '') { //don't need to test because already found an error! $this->check_source(); } //check the currency was correct that the merchant accepted in to his account if ($this->ok_to_process_error == '') { //don't need to test because already found an error! $this->check_currency_is_accepted(); } //kill script execution and send the error to the error log so you go and check the error if ($this->ok_to_process_error != '') { //update the transaction log to reflect the error mysql_query("UPDATE `orders` SET `status` = 'discarded' WHERE `entry_id` = '{$this->transaction_id}' LIMIT 1;"); trigger_error($this->ok_to_process_error, E_USER_WARNING); //don't need to do anything else! die(); } } //============================================================= //=== CHECK THE IPN RECEIVED WAS FROM PAYPAL //============================================================= function verify_ipn() { //produce the body to post back to paypal $post_data = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $post_data .= "&" . fg_string_decode($key) . "=" . fg_string_decode($value); } //open the connection to the paypal server $fp = @fsockopen($this->paypal_postback_validation_url, 80, $errno, $errstr, 30); if ( ! $fp) { $this->ok_to_process_error = "Couldn't connect to the PayPal website to validate the IPN. Socket Error: {$errno}:{$errstr}"; return false; } //post back to the paypal system to validate fputs($fp, "POST /cgi-bin/webscr HTTP/1.1\r\n"); fputs($fp, "Host: {$this->paypal_postback_validation_url}\r\n"); fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-Length: " . strlen($post_data) . "\r\n"); fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, "{$post_data}\r\n\r\n"); //send the verification check to paypal and save the result $response = ''; while ( ! feof($fp)) { $response .= fgets($fp, 1024); } fclose($fp); //check the result to see if it was a valid IPN if (strtoupper(trim(substr($response, -8))) == "VERIFIED") { return true; } $this->ok_to_process_error = "The IPN request was invalid. It could have been spoofed. The transaction has been logged."; return false; } //============================================================= //=== CHECK SPECIFIC VARS EXIST IN THE IPN IN ORDER TO PROCESS IT //============================================================= function basic_ipn_authentication() { global $ENGINE_SETTINGS; //make sure the required vars exists in the IPN foreach ($ENGINE_SETTINGS['paypal_ipn_required_fields'] as $field) { if (isset($_POST[$field]) == false) { $this->ok_to_process_error = 'Some required fields did not exist in the IPN and the payment has not been processed, the request has been discarded!'; return false; } } //detect which settings to test against if ($this->sandbox_mode_enabled == true) { //check that the money was sent to the correct person if (fg_string_decode($_POST['receiver_email']) != $ENGINE_SETTINGS['paypal_ipn_sandbox_merchant_primary_email_address']) { $this->ok_to_process_error = 'The money was not sent to you. Check your primary address matches the address in the IPN page!'; return false; } } else { //check that the money was sent to the correct person if (fg_string_decode($_POST['receiver_email']) != $ENGINE_SETTINGS['paypal_ipn_real_merchant_primary_email_address']) { $this->ok_to_process_error = 'The money was not sent to you. Check your primary address matches the address in the IPN page!'; return false; } } return true; } //============================================================= //=== LOGS THE IPN DATA TO A FILE FOR SAFE KEEPING AND REFERENCING //============================================================= function log_transaction() { global $ENGINE_SETTINGS; $data = ''; foreach($_POST as $name=>$value) { $data .= "{$name} = {$value}\r\n"; } $order_id = @$_POST['item_number']; $customer_name = @$_POST['first_name'] . ' ' . @$_POST['last_name']; $total = @$_POST['mc_gross']; $total_items = intval(mysql_result(mysql_query("SELECT COUNT('visitor_id') FROM `shopping_basket` WHERE `visitor_id` = '{$order_id}' LIMIT 1;"), 0)); //record the transaction to the correct log file if ($this->sandbox_mode_enabled == true) { $sandbox = 'y'; } else { $sandbox = 'n'; } //log transaction $timestamp = time(); mysql_query("INSERT INTO `orders` ( `entry_id` , `timestamp` , `sandbox_ipn` , `order_id` , `status` , `customer_name` , `total_price` , `total_items` , `details` , `ipn_dump` ) VALUES ( '' , '{$timestamp}' , '{$sandbox}', '{$order_id}', 'new', '{$customer_name}', '{$total}', '{$total_items}', '', '{$data}' );"); $this->transaction_id = mysql_insert_id(); } //============================================================= //=== CHECK THAT THE REQUEST CAME FROM THE WEBSITE & NOT A DIRECT PAYMENT ETC //============================================================= function check_source() { //no txn_type is set, and so it could be a transaction related to a web_accept payment if (@$_POST['txn_type'] == false) { //see if it has a parent transaction if (isset($_POST['parent_txn_id']) == false) { //it doesnt $this->ok_to_process_error = "No transaction type was specified, and no parent id was given and so we have no idea where this transaction originated from (web, paypal, auction, etc)"; return false; } //it does $this->payment_source_type = 'parent'; return true; } //it's a parent transaction - so only allow web_accept meaning it came from the website if (fg_string_decode($_POST['txn_type']) != 'web_accept') { $this->ok_to_process_error = "An IPN was received that was not initiated from your website. A direct payment could be a payment sent from the 'Send Money' tab within a paypal account."; return false; } //pretty sure it came from the web $this->payment_source_type = 'web'; return true; } //============================================================= //=== DETECTS SANDBOX MODE OR LIVE MODE AND CONVERTS VARS AS NEEDED //============================================================= function convert_to_sandbox() { global $ENGINE_SETTINGS; //detect if in sandbox mode if (isset($_POST['test_ipn'])) { if ($_POST['test_ipn'] == 1) { $this->sandbox_mode_enabled = true; } } //set the correct url to post to if ($this->sandbox_mode_enabled) { $this->paypal_postback_validation_url = 'www.sandbox.paypal.com'; } else { $this->paypal_postback_validation_url = 'www.paypal.com'; } } //============================================================= //=== SETTLED PAYMENT AMOUNT IN THE CURRENCY SET FOR THIS PAYPAL CLASS //============================================================= function check_currency_is_accepted() { global $ENGINE_SETTINGS; if (strtolower(substr($_POST['mc_currency'], 0, 3)) != strtolower($ENGINE_SETTINGS['paypal_ipn_currency'])) { $this->ok_to_process_error = 'A currency was accepted in to your account that was not allowed for payments taken on this website. It has not been processed.'; return false; } return true; } /* ################################################################## ================================================================================================================ ===== PROCESSING FUNCTIONS - USED TO HELP WHEN PROCESSING A PRODUCT IN THE DATABASE ================================================================================================================ ################################################################## */ //============================================================= //=== GET THE PAYMENT SOURCE: WEB or PARENT (meaning you need to lookup the source with its parent) //============================================================= function get_payment_source() { return $this->payment_source_type; } //============================================================= //=== DETECT IF THE IPN IS A SANDBOX IPN OR A PROPER IPN //============================================================= function is_ipn_from_sandbox() { return $this->sandbox_mode_enabled; } //============================================================= //=== GET THE STATUS OF THE TRANSACTION (pending, completed or failed) //============================================================= function get_payment_status() { //completed if (strtolower($_POST['payment_status']) == 'completed') { return 'completed'; } //failed if ( strtolower($_POST['payment_status']) == 'denied' || strtolower($_POST['payment_status']) == 'expired' || strtolower($_POST['payment_status']) == 'failed' || strtolower($_POST['payment_status']) == 'refunded' || strtolower($_POST['payment_status']) == 'reversed' || strtolower($_POST['payment_status']) == 'voided' ) { return 'failed'; } //everything else is pending - pending, processed, cancelled_reversal return 'pending'; } //============================================================= //=== GETS MORE INFORMATION ABOUT THE CURRENT STATUS OF THE TRANSACTION //============================================================= function get_payment_status_information() { switch (strtolower($_POST['payment_status'])) { case 'completed': return 'The payment has completed and is in your account.'; break; case 'pending': switch (strtolower($_POST['pending_reason'])) { case 'address': return 'The payment is pending because your customer did not include a confirmed shipping address and your Payment Receiving Preferences is set to allow you to manually accept or deny each of these payments. To change your preference, go to the Preferences section of your Profile.'; break; case 'authorization': return htmlspecialchars('You set Authorization on SetExpressCheckoutRequest and have not yet captured funds.', ENT_QUOTES); break; case 'echeck': return 'The payment is pending because it was made by an eCheck that has not yet cleared.'; break; case 'intl': return 'The payment is pending because you hold a non-U.S. account and do not have a withdrawal mechanism. You must manually accept or deny this payment from your Account Overview.'; break; case 'multi-currency': return 'You do not have a balance in the currency sent, and you do not have your Payment Receiving Preferences set to automatically convert and accept this payment. You must manually accept or deny this payment.'; break; case 'unilateral': return 'The payment is pending because it was made to an email address that is not yet registered or confirmed.'; break; case 'upgrade': return 'The payment is pending because it was made via credit card and you must upgrade your account to Business or Premier status in order to receive the funds. upgrade can also mean that you have reached the monthly limit for transactions on your account.'; break; case 'verify': return 'The payment is pending because you are not yet verified. You must verify your account before you can accept this payment.'; break; case 'other': return 'The payment is pending for a reason other than those listed above. For more information, contact PayPal Customer Service.'; break; } return 'The payment is pending, but we dont no why?'; break; case 'processed': return 'A payment has been accepted.'; break; case 'denied': return 'You denied a pending payment.'; break; case 'expired': return 'The payment is too old to have anything else done to it such as refunds.'; break; case 'failed': return 'The payment has failed when being funded from the clients bank account.'; break; case 'canceled_reversal': switch (strtolower($_POST['reason_code'])) { case 'chargeback': return 'A reversal has occurred on this transaction due to a chargeback by your customer.'; break; case 'guarantee': return 'A reversal has occurred on this transaction due to your customer triggering a money-back guarantee.'; break; case 'buyer-complaint': return 'A reversal has occurred on this transaction due to a complaint about the transaction from your customer.'; break; case 'refund': return 'A reversal has occurred on this transaction because you have given the customer a refund.'; break; case 'other': return 'A reversal has occurred on this transaction due to a reason not listed by paypal.'; break; } return 'A reversal has been canceled. For example, you won the dispute with the customer, and the funds for the transaction that was reversed have been returned to you.'; break; case 'refunded': switch (strtolower($_POST['reason_code'])) { case 'chargeback': return 'A reversal has occurred on this transaction due to a chargeback by your customer.'; break; case 'guarantee': return 'A reversal has occurred on this transaction due to your customer triggering a money-back guarantee.'; break; case 'buyer-complaint': return 'A reversal has occurred on this transaction due to a complaint about the transaction from your customer.'; break; case 'refund': return 'A reversal has occurred on this transaction because you have given the customer a refund.'; break; case 'other': return 'A reversal has occurred on this transaction due to a reason not listed by paypal.'; break; } return 'You refunded the payment back to the customer.'; break; case 'reversed': switch (strtolower($_POST['reason_code'])) { case 'chargeback': return 'A reversal has occurred on this transaction due to a chargeback by your customer.'; break; case 'guarantee': return 'A reversal has occurred on this transaction due to your customer triggering a money-back guarantee.'; break; case 'buyer-complaint': return 'A reversal has occurred on this transaction due to a complaint about the transaction from your customer.'; break; case 'refund': return 'A reversal has occurred on this transaction because you have given the customer a refund.'; break; case 'other': return 'A reversal has occurred on this transaction due to a reason not listed by paypal.'; break; } return 'The payment was reversed for some reason that is unknown?'; break; case 'voided': return 'The payment is too old to have anything else done to it such as refunds.'; break; } } } ?>add_field(array( 'display_name' => 'Name', 'type' => 'text', 'name' => 'name', 'id' => 'name', 'class' => '', 'style' => 'width:100%;', 'override_value' => null, 'override_selected_value' => null, //for checkboxes, select boxes, and radio boxes 'maxlength' => '50', 'other' => '', 'select_options' => array() )); $form_interface->add_field(array( 'display_name' => 'Details', 'type' => 'textarea', 'name' => 'details', 'id' => '', 'class' => '', 'style' => 'width:100%;height:100px;', 'override_value' => null, 'override_selected_value' => null, 'maxlength' => '', 'other' => '', 'select_options' => array() )); $form_interface->add_field(array( 'display_name' => 'Details Type', 'type' => 'select', 'name' => 'details_type', 'id' => '', 'class' => '', 'style' => 'width:200px;', 'override_value' => null, 'override_selected_value' => null, //for checkboxes, select boxes, and radio boxes 'maxlength' => '', 'other' => '', 'select_options' => array( array( 'checkbox_name' => '', 'display_name' => 'Age', 'value' => '123' ), array( 'checkbox_name' => '', 'display_name' => 'Gender', 'value' => 'male' ), array( 'checkbox_name' => '', 'display_name' => 'Weight', 'value' => '12 Stone' ), array( 'checkbox_name' => '', 'display_name' => 'DoB', 'value' => '12th June' ), ) )); $form_interface->add_field(array( 'display_name' => 'Details Type', 'type' => 'radio', 'name' => 'details_radioboxes', 'id' => '', 'class' => '', 'style' => '', 'override_value' => null, 'override_selected_value' => null, //for checkboxes, select boxes, and radio boxes 'maxlength' => '', 'other' => '', 'select_options' => array( array( 'checkbox_name' => '', 'display_name' => 'Age', 'value' => '123' ), array( 'checkbox_name' => '', 'display_name' => 'Gender', 'value' => 'male' ), array( 'checkbox_name' => '', 'display_name' => 'Weight', 'value' => '12 Stone' ), array( 'checkbox_name' => '', 'display_name' => 'DoB', 'value' => '12th June' ), ) )); $form_interface->add_field(array( 'display_name' => 'Details Type', 'type' => 'checkbox', 'name' => 'details_radioboxes', 'id' => '', 'class' => '', 'style' => '', 'override_value' => null, 'override_selected_value' => null, //for checkboxes, select boxes, and radio boxes 'maxlength' => '', 'other' => '', 'select_options' => array( array( 'checkbox_name' => 'age', 'display_name' => 'Age', 'value' => '123' ), array( 'checkbox_name' => 'gender', 'display_name' => 'Gender', 'value' => 'male' ), array( 'checkbox_name' => 'weight', 'display_name' => 'Weight', 'value' => '12 Stone' ), array( 'checkbox_name' => 'dob', 'display_name' => 'DoB', 'value' => '12th June' ), ) )); $form_interface->add_field(array( 'display_name' => 'Image', 'type' => 'file', 'name' => 'image', 'id' => '', 'class' => '', 'style' => '', 'override_value' => null, 'override_selected_value' => null, //for checkboxes, select boxes, and radio boxes 'maxlength' => '', 'other' => 'size="70"', 'select_options' => array() )); $form_interface->add_field(array( 'display_name' => '', 'type' => 'submit', 'name' => '', 'id' => '', 'class' => '', 'style' => 'width:100px;', 'override_value' => 'Send', 'override_selected_value' => null, 'maxlength' => '', 'other' => '', 'select_options' => array() )); print $form_interface->get_interface(); */ /* ################################################################## ================================================================================================================ ===== NAME: Create Form Interface ===== DESCRIPTION: creates a form interface already formated and ready to use ===== NOTES: can use two styles... horizontal and verticle ===== WARNINGS: needs "upload" field adding ================================================================================================================ ################################################################## */ class fg_class_create_form_interface { var $layout = ''; var $fields = array(); var $width = ''; //========================================================================== //=== SET WHAT LAYOUT YOU WANT FOR THE FORM WHEN CREATING THE CLASS //========================================================================== function fg_class_create_form_interface( $layout = 'vertical', //can be horizontal or vertical $width = '20%' ) { $this->layout = $layout; $this->width = $width; } //========================================================================== //=== ADD NEW FIELDS TO THE FORM //========================================================================== function add_field( $field = array( 'display_name' => '', 'type' => '', 'name' => '', 'id' => '', 'class' => '', 'style' => '', 'override_value' => null, //use a string to over ride it with, null simply means don't over ride the value 'override_selected_value' => null, //for checkboxes, select boxes, and radio boxes 'maxlength' => '', 'other' => '', 'select_options' => array( array( 'checkbox_name' => '', 'display_name' => '', 'value' => '' ), array( 'checkbox_name' => '', 'display_name' => '', 'value' => '' ), array( 'checkbox_name' => '', 'display_name' => '', 'value' => '' ) ) )) { $this->fields[] = $field; } //========================================================================== //=== GENERATES THE FORM //========================================================================== function get_interface() { $form_interface = ''; foreach ($this->fields as $field) { switch ($field['type']) { case 'text': $value = ''; if (isset($_POST[$field['name']])) { $value = fg_form_enter_previous_details($field['name'], 'POST'); } if ($field['override_value'] !== null) { $value = $field['override_value']; } switch ($this->layout) { case 'vertical': $form_interface .= " {$field['display_name']} "; break; case 'horizontal': $form_interface .= " {$field['display_name']} "; break; } break; case 'submit': switch ($this->layout) { case 'vertical': $form_interface .= " {$field['display_name']} "; break; case 'horizontal': $form_interface .= " {$field['display_name']} "; break; } break; case 'button': switch ($this->layout) { case 'vertical': $form_interface .= " {$field['display_name']} "; break; case 'horizontal': $form_interface .= " {$field['display_name']} "; break; } break; case 'file': switch ($this->layout) { case 'vertical': $form_interface .= " {$field['display_name']} "; break; case 'horizontal': $form_interface .= " {$field['display_name']} "; break; } break; case 'textarea': $value = ''; if (isset($_POST[$field['name']])) { $value = fg_form_enter_previous_details($field['name'], 'POST'); } if ($field['override_value'] !== null) { $value = $field['override_value']; } switch ($this->layout) { case 'vertical': $form_interface .= " {$field['display_name']} "; break; case 'horizontal': $form_interface .= " {$field['display_name']} "; break; } break; case 'select': $options = ''; foreach ($field['select_options'] as $option) { $checked = ''; if (isset($_POST[$field['name']])) { $checked = fg_form_select_previous_details($field['name'], $option['value'], $_POST[$field['name']]); } if ($field['override_selected_value'] !== null) { if ($option['value'] == $field['override_selected_value']) { $checked = " selected='selected'"; } } $options .= ""; } switch ($this->layout) { case 'vertical': $form_interface .= " {$field['display_name']} "; break; case 'horizontal': $form_interface .= " {$field['display_name']} "; break; } break; case 'radio': $options = ''; foreach ($field['select_options'] as $option) { $checked = ''; if (isset($_POST[$field['name']])) { $checked = fg_form_select_checked_details($field['name'], $option['value'], $_POST[$field['name']]); } if ($field['override_selected_value'] !== null) { if ($option['value'] == $field['override_selected_value']) { $checked = " checked='checked'"; } } $options .= "{$option['display_name']}"; } switch ($this->layout) { case 'vertical': $form_interface .= " {$field['display_name']} {$options} "; break; case 'horizontal': $form_interface .= " {$field['display_name']} {$options} "; break; } break; case 'checkbox': $options = ''; foreach ($field['select_options'] as $option) { $checked = ''; if (isset($_POST[$option['checkbox_name']])) { $checked = 'checked="checked"'; } $options .= "{$option['display_name']}"; } switch ($this->layout) { case 'vertical': $form_interface .= " {$field['display_name']} {$options} "; break; case 'horizontal': $form_interface .= " {$field['display_name']} {$options} "; break; } break; } } return $form_interface; } } ?>add_item(14, 3, 2.49); $delivery_cost->add_item(14, 3, 2.49); $delivery_cost->add_item(14, 3, 2.49); $delivery_cost->add_item(14, 3, 2.49); $delivery_cost->add_item(14, 3, 2.49); print $delivery_cost->get_delivery_cost(); */ //============================================================= //=== Class: delivery costings //=== Description: Works out a delivery cost. This class works it out using the following algorithm: ceil($data['quantity'] / $data['volume_max']) * $data['volume_price']; //=== This means that if you order say 5 products... it will cost you £10, but £10 is added on when they are 5 or more... so 3 items = £10, 5 items = £10, 7 items = £20, 10 items = £20, etc //============================================================= class fg_class_delivery_costings { private $items_data = array(); private $template = array('quantity' => 1, 'volume_max' => 0, 'volume_price' => 0); public function add_item($item_id, $volume_max, $volume_price) { if (isset($this->items_data[$item_id])) { $this->items_data[$item_id]['quantity']++; } else { $this->items_data[$item_id] = $this->template; $this->items_data[$item_id]['volume_max'] = $volume_max; $this->items_data[$item_id]['volume_price'] = $volume_price; } } public function get_delivery_cost() { $cost = 0; //calculate cost foreach ($this->items_data as $item_id=>$data) { $cost += ceil($data['quantity'] / $data['volume_max']) * $data['volume_price']; } return $cost; } } ?>