'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;
}
}
?>
";
}
}
}
}
closedir($handle);
}
//load bespoke apps in to the admin panel
if ($handle = @opendir('../../bespoke/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (file_exists('../../bespoke/' . $file . '/admin/index.php')) {
if (in_array($file, self::$ignore_panel_links) === false) {
$links['Bespoke Apps'][$file] = "" . ucwords(str_replace('-', ' ', $file)) . "";
}
}
}
}
closedir($handle);
}
//return the categories links
return $links;
}
}
?>
"Name",
2 => "Subject",
3 => "Message",
17 => "Phone Number",
4 => "Best Time To Call",
5 => "Order Number",
6 => "Account Number",
7 => "User Name",
8 => "Email Address",
9 => "How did you find us?",
10 => "Location",
11 => "House Name / Number",
12 => "Road Name",
13 => "City / Town",
14 => "Country",
15 => "Post Code",
16 => "Recommended By"
);
//==================================
//=== GET THE FIELDS THAT CAN BE SELECTED
//==================================
static public function get_selectable_fields_array() {
return self::$selectable_fields;
}
//==================================
//=== PRODUCE THE HTML FORM
//==================================
static public function get_form($layout = 'horizontal') {
$form_interface = new fg_class_create_form_interface($layout);
//produce the form
$sql = mysql_query("SELECT `type_id` FROM `application_contact_us_fields`;");
while ($row = mysql_fetch_object($sql)) {
//see if it needs a textarea or a textbox
if ($row->type_id == 3) {
$form_interface->add_field(array(
'display_name' => self::$selectable_fields[$row->type_id],
'type' => 'textarea',
'name' => 'contact_' . $row->type_id,
'id' => '',
'class' => '',
'style' => 'width:99%;height:50px;',
'override_value' => null,
'override_selected_value' => null,
'maxlength' => '',
'other' => '',
'select_options' => array()
));
continue;
}
$form_interface->add_field(array(
'display_name' => self::$selectable_fields[$row->type_id],
'type' => 'text',
'name' => 'contact_' . $row->type_id,
'id' => '',
'class' => '',
'style' => 'width:99%;',
'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' => '',
'type' => 'submit',
'name' => '',
'id' => '',
'class' => '',
'style' => 'width:100px;',
'override_value' => 'Send',
'override_selected_value' => null,
'maxlength' => '',
'other' => '',
'select_options' => array()
));
return $form_interface->get_interface();
}
//==================================
//=== SEND THE FORM
//==================================
static public function send($to, $subject) {
$error_messages = '';
$message = '';
foreach (self::$selectable_fields as $id=>$name) {
if (isset($_POST['contact_' . $id])) {
$message .= $name . ': ' . fg_string_decode($_POST['contact_' . $id]) . "\r\n";
}
}
//see if the form has been sent
if ($message != '') {
$message = nl2br($message);
if (@mail($to, $subject, $message, $headers = 'From: ' . $to . "\r\n" . 'Reply-To: ' . $to . "\r\n" . 'X-Mailer: PHP/' . phpversion())) {
$error_messages = fg_presentation_generate_message('Your email has been sent. Thank you for taking the time to contact us.');
} else {
$error_messages = fg_presentation_generate_message('Your email could not be sent. Please try again later or contact us via our alternative methods to the right of this page.', null, null, true);
}
}
return $error_messages;
}
}
?>email_address, 'Website - Call Us', $_POST['app_call_us_number'], 'From: ' . $details->email_address . "\r\n" . 'Reply-To: ' . $details->email_address . "\r\n" . 'X-Mailer: PHP/' . phpversion())) {
self::$called = true;
}
}
}
//==========================================================================
//=== PRODUCE THE TEXT BOX AND BUTTON
//==========================================================================
public static function get_form($default_text = 'Enter your phone number...', $confirm_text = 'Thank you. We will call you soon...', $button = '') {
if (self::$called) {
self::$called = false;
$default_text = $confirm_text;
}
print "
{$button}
";
}
}
?>" . "\r\n" .
'Content-type: text/html' . "\r\n" .
"Reply-To: $reply_to_address" . "\r\n" .
'X-Mailer: PHP/';
if (@mail($to, $subject, $content, $header)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
?> '');
}
//load vars
$filename = htmlspecialchars($_FILES[$input_name]['name'], ENT_QUOTES);
//test uploaded correctly (0 = uploaded correctly)
if ($_FILES[$input_name]['error'] == 1) {
return array('error_message' => $filename . ' -> The file size exceeds the max file size limit set by the PHP.INI file. Please try again after making the file smaller. (PS: Contact us if you see this message have not explicitly set this file limitation)');
}
if ($_FILES[$input_name]['error'] == 2) {
return array('error_message' => $filename . ' -> The file size exceeds the max file size limit set by the MAX_FILE_SIZE limit set in the hidden element of your HTML form. (PS: Contact us if you see this message as we do not use this element to limit file sizes!)');
}
if ($_FILES[$input_name]['error'] == 3) {
return array('error_message' => $filename . ' -> The file has only partially been uploaded! Please try uploading the file again. We are sorry for any inconvenience this has caused.');
}
if ($_FILES[$input_name]['error'] == 4) {
return array('not_uploaded' => '');
}
//test filesize ok (set by the function)
if ($_FILES[$input_name]['size'] > ($max_file_size * 1024)) {
return array('error_message' => $filename . ' -> The file size is to large! Please make sure the file is no larger than ' . $max_file_size . 'Kb where as your current file size is ' . (number_format($_FILES[$input_name]['size'] / 1024, 0)) . 'Kb');
}
//test file type is ok
$allow_type = false;
$allowed_extensions = ''; //loaded using the loop below
foreach ($file_types_allowed as $type) {
$type = strtolower(".$type"); //appends . to the start
if (substr(strtolower($filename), -2, 2) == $type) {
//allowed
$allow_type = true;
$file_extension = strtolower(substr($filename, -2, 2));
}
if (substr(strtolower($filename), -3, 3) == $type) {
//allowed
$allow_type = true;
$file_extension = strtolower(substr($filename, -3, 3));
}
if (substr(strtolower($filename), -4, 4) == $type) {
//allowed
$allow_type = true;
$file_extension = strtolower(substr($filename, -4, 4));
}
if (substr(strtolower($filename), -5, 5) == $type) {
//allowed
$allow_type = true;
$file_extension = strtolower(substr($filename, -5, 5));
}
if (substr(strtolower($filename), -6, 6) == $type) {
//allowed
$allow_type = true;
$file_extension = strtolower(substr($filename, -6, 6));
}
$allowed_extensions .= $type . ' '; // used incase an error occurs in that the file extension isn't allowed
}
if ($allow_type == false) {
//file extension not allowed
return array('error_message' => $filename . ' -> The file extension of the file you tried to upload is not allowed. It must be one of the following extensions: ' . $allowed_extensions);
}
//============= SWITCH FILE TO ONLINE =============
//generate random name
$hashed_filename = md5($filename . mt_rand(0, mt_getrandmax()) . mt_rand(0, mt_getrandmax())) . $file_extension;
$counter = 0;
while (file_exists($path . $hashed_filename)) {
$counter++;
//counts times its been passed and got the same name, and uses a different algorithm if looping to much, if a name that doesnt exist still cant be generated exit prematurely to stop script being killed.
if ($counter < 2500) {
$hashed_filename = md5($filename . mt_rand(0, mt_getrandmax()) . mt_rand(0, mt_getrandmax())) . $file_extension;
} else {
$hashed_filename = md5(mt_rand(0, mt_getrandmax()) . mt_rand(0, mt_getrandmax())) . $file_extension;
if ($counter > 5000) {
return array('error_message' => 'An internal error has occured where the server has run out of names to use in the current folder when trying to upload your file. Please contact us so we can resolve this issue by extending the name library. ');
}
}
}
//save to server folder
if ( ! @move_uploaded_file($_FILES[$input_name]['tmp_name'], $path . $hashed_filename)) {
return array('error_message' => 'An internal error has occured where your uploaded file could not be moved to an online folder. Please contact us so we can resolve this issue as soon as possible.');
} else {
return array('hashed_filename' => $hashed_filename);
}
}
?>
{$text}
";
}
/* ##################################################################
================================================================================================================
===== NAME: fg_image_size()
===== DESCRIPTION: Retruns total bytes of an image else returns false
===== NOTES: can include url's of images and files
================================================================================================================
################################################################## */
function fg_image_size($url){
$data = @file_get_contents($url);
if ($data != '') {
return strlen($data);
} else {
return false;
}
}
/* ##################################################################
================================================================================================================
===== NAME: fg_image_validate()
===== DESCRIPTION: checks evertying related to read only properties with the image (used on forms when uploading images)
===== NOTES: main purpose to check the image exists
================================================================================================================
################################################################## */
function fg_image_validate(
$image_url //location to the image (url or ../server path
) {
//checks that the file exists
if ( (@fopen($image_url, "r") == false) OR (substr($image_url, -1, 1 ) == '/')) {
return 'The file could not be found!';
}
//checks the image is actually an image and nothing else
if (@getimagesize($image_url) == false) {
return 'The file you are trying to upload is not of the right format. It must end in one of the following extensions: .png, .gif, .jpg, .jpeg, .bmp';
}
//the image must be one of these extensions!
if (substr(strtolower($image_url), -4, 4 ) == '.png') {
return true;
}
if (substr(strtolower($image_url), -4, 4 ) == '.gif') {
return true;
}
if (substr(strtolower($image_url), -4, 4 ) == '.jpg') {
return true;
}
if (substr(strtolower($image_url), -5, 5 ) == '.jpeg') {
return true;
}
if (substr(strtolower($image_url), -4, 4 ) == '.bmp') {
return true;
}
return 'The file you are trying to upload is not of the right format. It must end in one of the following extensions: .png, .gif, .jpg, .jpeg, .bmp';
}
/* ##################################################################
================================================================================================================
===== NAME: fg_image_load()
===== DESCRIPTION: loads an image into a tag set to your spec, else returns false for you to use a ghost image
===== NOTES: height='$max_height' has been removed for display purposes, yet the commented line below is the original code that contains the height property
================================================================================================================
################################################################## */
function fg_image_load(
$image_url, //location of the image (URL or ../server location)
$alt, //alternate text to be displayed on mouse over
$max_filesize_for_display, //if exceeds this filesize then will be displayed as a link
$max_height, //maximum height of the image
$max_width, //maximum width of the image
$stretch_to_fit = false, //regardless of the image dimentions will stretch to fit
$text_span = '' //span text around image
) {
//validate image
if (fg_image_validate($image_url) === true) {
//test if exceeds filesize (for display, so display as link)
$max_filesize_for_display = $max_filesize_for_display * 1024;
if (fg_image_size($image_url) > $max_filesize_for_display) {
//filesize is to large so return a link to the image
return "$image_url";
}
//text span image
if ($text_span == 'left') {
$text_span = 'float:left; margin:3px; margin-left:0px;';
} else {
if ($text_span == 'right') {
$text_span = 'float:right; margin:3px; margin-right:0px;';
} else {
$text_span = 'margin:3px;';
}
}
//if stretch to fit is true, then no need to check dimentions!
if ($stretch_to_fit) {
//returns image stretched to fit max height and max width
return "";
//return "";
}
//if dimentions exceed max allowed then shrink and make clickable
$image_details = getimagesize($image_url);
if ( ($max_width != 0) AND ($max_height != 0) ) {
//if both dimentions exceed size
if ( ($image_details[0] > $max_width) AND ($image_details[1] > $max_height) ) {
//returns image shrunk to max height and max width and made clickable
return "";
//return "";
}
}
if ($max_width != 0) {
//if width exceeds size
if ($image_details[0] > $max_width) {
//returns image shrunk to max width and made clickable
return "";
}
}
if ($max_height != 0) {
//if height exceeds size
if ($image_details[1] > $max_height) {
//returns image shrunk to max height and made clickable
return "";
//return "";
}
}
//if dimentions are ok, dont shrink and dont make clickable
return "";
} else {
return false;
}
}
?> 1) {
$last_2digits = substr($number, -2);
switch( $last_2digits ) {
case 11: $current_number = $number . "th"; break;
case 12: $current_number = $number . "th"; break;
case 13: $current_number = $number . "th"; break;
}
}
return $current_number;
}
?> ";
} else {
$bottom_spacing = '';
}
//detect what color for error or general message
if ($error) {
$color = 'border-color:red;background-color:#EEEEEE;color:red;border-width:3px;border-style:solid;';
} else {
$color = 'border-color:green;background-color:#EEEEEE;color:green;border-width:3px;border-style:solid;';
}
$width = '100%';
//display the message
$generated_message = '';
$generated_message .= "