17 require_once SQ_PACKAGES_PATH.
'/cms/form/form_email/form_email.inc';
18 require_once SQ_FUDGE_PATH.
'/general/www.inc';
19 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
20 require_once SQ_PACKAGES_PATH.
'/ecommerce/orders/order/order.inc';
44 var $confirm_view =
'confirmation';
50 var $process_view =
'process';
56 var $receipt_view =
'receipt';
62 var $_bodycopies = Array(
'Form',
'Confirmation',
'Receipt');
102 foreach ($this->_bodycopies as $bodycopy) {
121 $order_links = parent::_getAllowedLinks();
122 $order_links[SQ_LINK_TYPE_2][
'folder'] = Array(
'card' =>
'M');
139 case(
'form_question_type_numeric'):
140 case(
'form_question_type_select'):
141 case(
'form_question_type_option_list'):
142 case(
'form_question_type_tickbox_list'):
143 case(
'form_question_type_tickbox_table'):
164 case(
'form_question_type_text'):
165 case(
'form_question_type_numeric'):
166 case(
'form_question_type_email_address'):
167 case(
'form_question_type_select'):
168 case(
'form_question_type_option_list'):
169 case(
'form_question_type_tickbox_list'):
170 case(
'form_question_type_tickbox_table'):
171 case(
'form_question_type_country'):
192 $e_questions = $this->
attr(
'rules');
193 $result = array_get_index($e_questions, $name, FALSE);
210 $rules = $this->
attr(
'rules');
212 if (!isset($rules[$name]))
return FALSE;
214 $rules[$name] = $value;
234 if (isset($_SESSION[$this->
getPrefix()][
'order'])) {
235 $order =& $_SESSION[$this->
getPrefix()][
'order'];
240 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
243 $action = array_get_index($_REQUEST, $this->
getPrefix().
'_action');
244 if (isset($_REQUEST[$this->
getPrefix().
'_submit'])) {
248 for (reset($questions); $question =& $questions[key($questions)]; next($questions)) {
250 $question->saveValue($this);
251 $this->current_answers[$question->id] = $question->getValue();
252 $this->extra_data[$question->id] = $question->getExtraData();
254 if (method_exists($question,
'onSubmitForm')) {
255 $question->onSubmitForm($this);
256 $this->extra_data[$question->id] = $question->getExtraData();
257 if (!empty($question->failed_rules)) {
258 if (!is_array($this->submission_errors)) $this->submission_errors = Array();
259 $this->submission_errors = array_merge($this->submission_errors, $question->failed_rules);
265 if(empty($this->submission_errors))
266 $action = $this->confirm_view;
268 }
else if (!empty($order)) {
272 $this->current_answers = $order[
'submission'];
273 $this->extra_data = $order[
'submission_extra_data'];
277 $request_var_name = $this->
attr(
'item_req_var');
278 if (empty($action) && isset($_REQUEST[$request_var_name])) {
279 $action =
'add_to_cart';
284 case (
'add_to_cart'):
286 if ($request_var_name ==
'')
break;
288 $assetid = @$_REQUEST[$request_var_name];
289 if (is_null($assetid))
break;
291 $quantity = @$_REQUEST[$this->
attr(
'item_quantity_req_var')];
294 trigger_error(
'This item cannot be purchased', E_USER_NOTICE);
298 $promo_code_var_name = $this->
attr(
'item_promo_code_req_var');
299 if (($promo_code_var_name !=
'') && isset($_REQUEST[$promo_code_var_name])) {
305 header(
'Location: '.$this->
getUrl());
315 header(
'Location: '.$this->
getUrl());
323 case ($this->confirm_view):
332 $order = $_SESSION[$this->
getPrefix()][
'order'];
333 $action_name = $this->
getPrefix().
'_action';
335 $_SESSION[
'SQ_ECOM_SUCCESS_URL'] = $this->
getURL().
'?'.$action_name.
'='.$this->receipt_view;
336 $_SESSION[
'SQ_ECOM_CANCEL_URL'] = $this->
getURL().
'?'.$action_name.
'='.$this->confirm_view;
337 $_SESSION[
'SQ_ECOM_REF_NO'] = md5(session_id().time());
341 if (!empty($pass_through_vars)) {
342 $_SESSION[
'SQ_ECOM_PASS_THROUGH_VARS'] = $pass_through_vars;
347 $new_reference_id = $this->
attr(
'custom_reference_id');
348 if (!empty($new_reference_id)) {
349 $new_reference_replacements = Array();
350 $new_reference_keywords = extract_keywords($new_reference_id);
351 foreach ($new_reference_keywords as $keyword) {
355 $new_reference_replacements[
'session_id'] = session_id();
356 $new_reference_replacements[
'current_time'] = time();
358 replace_keywords($new_reference_id, $new_reference_replacements);
360 $_SESSION[
'SQ_ECOM_REF_NO'] = $new_reference_id;
363 $_SESSION[
'SQ_ECOM_AMOUNT'] = $order[
'total'];
372 $gateway = $this->
attr(
'gateway_assetid');
373 if (empty($gateway)) {
374 trigger_error(
'Payment Gateway not configured. Cannot proceed.', E_USER_NOTICE);
379 $gateway = $this->
attr(
'gateway_assetid');
380 $gateway_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($gateway);
381 $gateway_asset_url = $gateway_asset->getURL();
383 header(
'Location: '.$gateway_asset_url);
391 case ($this->receipt_view):
393 $response = array_get_index($_SESSION,
'SQ_ECOM_RESPONSE', FALSE);
398 header(
'Location: '.$this->
getUrl());
404 unset($_SESSION[
'SQ_ECOM_RESPONSE']);
405 $this->_tmp[
'GATEWAY_RESPONSE'] = $response;
412 $this->current_answers = $order[
'submission'];
413 $this->extra_data = $order[
'submission_extra_data'];
425 $order_asset = $this->order;
428 foreach ($file_uploads as $assetid => $file_upload) {
429 $extra_data = $file_upload->getExtraData();
431 $create_location = $file_upload->attr(
'create_location');
432 if (empty($create_location)) {
433 if (!empty($extra_data[
'temp_filesystem_path'])) {
434 $filename = $file_upload->getValue();
435 $perm_path = $order_asset->data_path.
'/attachments/'.str_replace(
':',
'_', $file_upload->id);
438 create_directory($perm_path);
439 move_file($extra_data[
'temp_filesystem_path'], $perm_path.
'/'.$filename);
441 'filesystem_path' => $perm_path.
'/'.$filename,
444 $file_upload->setExtraData($extra_data);
450 $uploaded_assetid = array_get_index($extra_data,
'existing_file_assetid', array_get_index($extra_data,
'new_file_assetid', NULL));
451 if (!empty($uploaded_assetid)) {
452 $uploaded_file = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($uploaded_assetid);
454 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
455 $order_asset->createLink($uploaded_file, SQ_LINK_NOTICE,
'file_submission');
456 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
460 $file_upload->cleanUp($this);
466 if ($this->
attr(
'log_to_file')) {
480 $_SESSION[$this->
getPrefix()][
'items'] = Array();
481 $_SESSION[$this->
getPrefix()][
'order'] = Array();
508 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
510 $asset_item_format = $this->
attr(
'log_asset_item_format');
511 $question_item_format = $this->
attr(
'log_question_item_format');
512 $item_block_format = $this->
attr(
'log_item_block_format');
513 $log_entry_format = $this->
attr(
'log_entry_format');
517 $asset_list = @$_SESSION[$this->
getPrefix()][
'order'][
'ecom_assets'];
518 if (empty($asset_list)) $asset_list = Array();
519 foreach ($asset_list as $id => $item) {
520 $asset = $am->getAsset($id);
521 $item_string = $asset->replaceKeywordsInString($asset_item_format);
522 $replacements[
'item_name'] = $item[
'name'];
523 $replacements[
'item_price'] = $item[
'price'];
524 $replacements[
'item_id'] = $item[
'id'];
525 replace_keywords($item_string, $replacements);
528 $asset_item_list = ob_get_clean();
529 $item_block_replacements[
'asset_item_list'] = $asset_item_list;
532 $question_list = @$_SESSION[$this->
getPrefix()][
'order'][
'ecom_questions'];
533 if (empty($question_list)) $question_list = Array();
534 foreach ($question_list as $id => $item) {
535 $item_string = $question_item_format;
536 $replacements[
'item_name'] = $item[
'name'];
537 $replacements[
'item_price'] = $item[
'price'];
538 $replacements[
'item_id'] = $item[
'id'];
539 replace_keywords($item_string, $replacements);
542 $question_item_list = ob_get_clean();
543 $item_block_replacements[
'question_item_list'] = $question_item_list;
546 if (!empty($question_item_list) || !empty($asset_item_list)) {
547 $item_block = $item_block_format;
548 replace_keywords($item_block, $item_block_replacements);
551 $log_entry_string = $log_entry_format;
552 $log_entry_keywords = extract_keywords($log_entry_format);
553 foreach ($log_entry_keywords as $keyword) {
554 if ($keyword ==
'form_summary') {
555 $keyword2 = $keyword.
'_text';
562 $log_entry_replacements[
'item_block'] = $item_block;
564 replace_keywords($log_entry_string, $log_entry_replacements);
566 replace_global_keywords($log_entry_string);
569 $this->
_log($log_entry_string);
597 $clientside = ($this->
attr(
'use_client_side')) ?
'onsubmit="return beforeSubmit_'.$prefix.
'(this);"' :
'';
599 $form_action = $_SERVER[
'PHP_SELF'];
603 if (!empty($_SERVER[
'QUERY_STRING'])) {
604 $form_action .=
'?'.htmlentities($_SERVER[
'QUERY_STRING']);
608 if ($this->
attr(
'use_client_side')) {
609 ?><script
type=
"text/javascript">
610 function beforeSubmit_<?php echo $prefix; ?>(form) {
611 var submission_errors =
new Array();
614 if (submission_errors.length > 0) {
615 var errors_list =
"<?php echo translate('cms_form_submission_errors'); ?>\n";
616 for(x in submission_errors) {
617 errors_list += submission_errors[x] +
"\n";
627 $javascript = ob_get_clean();
631 if (is_null($bodycopy))
return '';
633 $replacements = Array();
634 $keyword_list = $bodycopy->getKeywords();
635 if (!empty($keyword_list)) {
636 foreach ($keyword_list as $keyword) {
637 if (isset($replacements[$keyword]))
continue;
642 $bodycopy->setKeywordReplacements($replacements);
645 echo
'<form id="'.$prefix.
'" enctype="multipart/form-data" action="'.$form_action.
'" method="post" '.$clientside.
'>';
647 echo hidden_field(
'SQ_FORM_'.$this->
id.
'_PAGE', 1);;
648 $bodycopy->printBody();
665 $unreplaced_value =
'%'.$keyword.
'%';
667 $keyword_parts = explode(
'_', $keyword);
668 if (empty($keyword_parts))
return $unreplaced_value;
670 $keyword_category = $keyword_parts[0];
672 if ($keyword_category ==
'question') {
678 if (count($keyword_parts) != 4) {
679 return $unreplaced_value;
682 $question_id = $keyword_parts[2].
':'.$keyword_parts[3];
685 return $unreplaced_value;
688 $q_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($question_id);
690 switch ($keyword_parts[1]) {
692 $value =
'q'.$keyword_parts[2].
'_'.$keyword_parts[3];
696 $value = $q_asset->getHtmlLabel();
700 $value = $q_asset->getHtmlField();
704 $value = $q_asset->attr(
'note');
708 $value = $q_asset->getSummary();
712 $value = $q_asset->attr(
'name');
716 $value = $unreplaced_value;
719 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($q_asset);
723 }
else if ($keyword_category ==
'response') {
724 if (count($keyword_parts) != 3) {
725 return $unreplaced_value;
728 $question_id = $keyword_parts[1].
':'.$keyword_parts[2];
730 return $unreplaced_value;
733 $q_asset =& $GLOBALS[
'SQ_SYSTEM']->am->getAsset($question_id);
734 $value = $q_asset->getSummary();
737 }
else if ($keyword_category ==
'section') {
741 if (count($keyword_parts) != 3) {
742 return $unreplaced_value;
745 if ($keyword_parts[1] ==
'title') {
746 $section_id = $keyword_parts[2];
747 $section_asset =& $GLOBALS[
'SQ_SYSTEM']->am->getAsset($section_id);
748 $value = $section_asset->attr(
'name');
749 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($section_asset);
755 return parent::getKeywordReplacement($keyword);
773 return isset($all_questions[$question_id]);
788 if (is_null(@$this->_tmp[
'all_questions'])) {
792 $questions =& $this->_tmp[
'all_questions'];
813 foreach ($questions as $q_id => $question) {
814 $q_asset =& $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->
id.
':q'.$q_id);
815 $q_name = $q_asset->attr(
'name');
816 $replacements[
'question_field_'.$this->id.
'_q'.$q_id] = $q_asset->getHtmlField();
817 $replacements[
'question_id_'.$this->id.
'_q'.$q_id] =
'q'.$this->id.
'_q'.$q_id;
818 $replacements[
'question_note_'.$this->id.
'_q'.$q_id] = $q_asset->attr(
'note');
819 $replacements[
'question_label_'.$this->id.
'_q'.$q_id] = $q_asset->getHtmlLabel();
822 foreach ($sections as $section) {
823 $replacements[
'section_title_'.$section->id] = $section->attr(
'name');
824 $questions = $section->getQuestions();
825 foreach ($questions as $q_id => $question) {
826 $q_asset =& $GLOBALS[
'SQ_SYSTEM']->am->getAsset($section->id.
':q'.$q_id);
827 $q_name = $section->attr(
'name').
': '.$q_asset->attr(
'name');
828 $replacements[
'question_field_'.$section->id.
'_q'.$q_id] = $q_asset->getHtmlField();
829 $replacements[
'question_id_'.$section->id.
'_q'.$q_id] =
'q'.$section->id.
'_q'.$q_id;
830 $replacements[
'question_note_'.$section->id.
'_q'.$q_id] = $q_asset->attr(
'note');
831 $replacements[
'question_label_'.$section->id.
'_q'.$q_id] = $q_asset->getHtmlLabel();
835 return $replacements;
850 if ($bodycopy ==
'Page Contents') {
852 }
else if ($bodycopy ==
'Thank You') {
853 $bodycopy =
'Confirmation';
856 $bodycopy_asset =& parent::getBodycopy($bodycopy);
858 return $bodycopy_asset;
928 $response = array_get_index($this->_tmp,
'GATEWAY_RESPONSE', FALSE);
929 if (!$response)
return $header;
932 $date = date(
'F j, Y, g:i a');
936 <table class="ecom_header_table">
938 <td colspan="2"><h2>Receipt</h2></td>
941 <td>'.translate(
'ecom_form_transaction_number:').
'</td>
942 <td>'.$response[
'TRANSACTION'].
'</td>
945 <td>'.translate(
'ecom_form_transaction_status:').
'</td>
946 <td>'.$response[
'STATUS'].
'</td>
949 <td>'.translate(
'ecom_form_credit_card:').
'</td>
950 <td>'.$response[
'CARDNO'].
'</td>
953 <td>'.translate(
'ecom_form_date:').
'</td>
960 $header .= translate(
'ecom_form_transaction_number:').
' '.$response[
'TRANSACTION'].
"\n";
961 $header .= translate(
'ecom_form_transaction_status:').
' '.$response[
'STATUS'].
"\n";
962 $header .= translate(
'ecom_form_date:').
' '.$date.
"\n";
989 parent::printSummary($as_html);
1002 return parent::processPage(1);
1018 if (is_null($order)) $order =& $this->
createOrder();
1021 $this->order =& $order;
1022 $this->submission_asset =& $order;
1025 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1027 for (reset($questions); $question =& $questions[key($questions)]; next($questions)) {
1028 $question->saveValue($this);
1031 if ($question->attr(
'sticky')) {
1032 $question->stickValue($question->getValue());
1037 for (reset($questions); $question =& $questions[key($questions)]; next($questions)) {
1038 $order->setAnswer(key($questions), $question->getValue());
1039 $order->setSummary(key($questions), $question->attr(
'name'), $question->getSummary());
1040 $order->setExtraData(key($questions), $question->getExtraData());
1043 $order->setIP($_SERVER[
'REMOTE_ADDR']);
1044 $order->setAttrValue(
'complete', TRUE);
1045 $order->setAttrValue(
'xml', $this->
getXML());
1047 $order->setAttrValue(
'transaction_id', array_get_index($this->_tmp[
'GATEWAY_RESPONSE'],
'TRANSACTION',
''));
1048 $order->setAttrValue(
'billing_name', array_get_index($this->_tmp[
'GATEWAY_RESPONSE'],
'BILLING_NAME',
''));
1049 $order->setAttrValue(
'billing_addr', array_get_index($this->_tmp[
'GATEWAY_RESPONSE'],
'BILLING_ADDR',
''));
1050 $order->setAttrValue(
'delivery_name', array_get_index($this->_tmp[
'GATEWAY_RESPONSE'],
'DELIVERY_NAME',
''));
1051 $order->setAttrValue(
'delivery_addr', array_get_index($this->_tmp[
'GATEWAY_RESPONSE'],
'DELIVERY_ADDR',
''));
1053 $order->saveAttributes();
1055 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1068 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
1070 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1071 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1074 $folder_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE,
'orders_folder');
1075 if (empty($folder_link)) {
1078 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'folder');
1080 $folder->setAttrValue(
'name',
'Orders');
1082 $folder_link = Array(
'asset' => &$this,
'link_type' => SQ_LINK_TYPE_2,
'value' =>
'orders_folder',
'is_dependant' => 0,
'is_exclusive' => 1);
1085 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
1086 $success = $folder->create($folder_link);
1087 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
1089 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1090 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1095 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
1096 $success = $GLOBALS[
'SQ_SYSTEM']->am->setPermission($folder->id, $GLOBALS[
'SQ_SYSTEM']->am->getSystemAssetid(
'public_user'), SQ_PERMISSION_READ, 0, TRUE, TRUE);
1097 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
1099 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1100 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1106 $folder = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($folder_link[
'minorid'], $folder_link[
'minor_type_code']);
1110 if (is_null($folder)) {
1111 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1112 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1117 $order =
new Order();
1118 $copy_link = Array(
'asset' => &$folder,
'link_type' => SQ_LINK_TYPE_2,
'is_dependant' => 1,
'is_exclusive' => 1);
1120 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
1121 $success = $order->create($copy_link);
1122 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
1126 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1127 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1130 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1131 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1148 $order = $_SESSION[$this->
getPrefix()][
'order'];
1149 if (empty($order))
return FALSE;
1151 $curr_sign = $this->
attr(
'currency_sign');
1153 $receipt_fmt =
'<hr /><table class="sq_ecomTable">%s%s%s</table><hr />';
1154 $order_row_fmt =
'<tr class="sq_ecomTableItemRow"><td class="sq_ecomTableItemName">%s</td><td class="sq_ecomTableItemValue" align="right">%01.2f</td></tr>';
1155 $divider_row =
'<tr class="sq_ecomTableItemRow"><td class="sq_ecomTableItemName"> </td><td class="sq_ecomTableItemValue" align="right"><hr /></td></tr>';
1156 $total_discount_row_fmt =
'<tr class="sq_ecomTableTotalDiscountRow"><td class="sq_ecomTableTotalDiscountName" align="right">%s</td><td class="sq_ecomTableTotalDiscountValue" align="right">'.$curr_sign.
'%01.2f</td></tr>';
1157 $total_row_fmt =
'<tr class="sq_ecomTableTotalRow"><td class="sq_ecomTableTotalName" align="right">%s</td><td class="sq_ecomTableTotalValue" align="right">'.$curr_sign.
'%01.2f</td></tr>';
1159 $receipt_fmt = strtoupper(translate(
'ecom_form_receipt:')).
"\n############################\n%s\n%s\n%s\n############################";
1160 $order_row_fmt =
"%s: %01.2f\n";
1161 $divider_row =
"----------------------------\n";
1162 $total_discount_row_fmt =
"*** %s $curr_sign%01.2f ***\n";
1163 $total_row_fmt =
"*** %s $curr_sign%01.2f ***\n";
1167 foreach ($order[
'items'] as $item) {
1168 $rows .= sprintf($order_row_fmt, $item[
'name'], $item[
'price']);
1171 $rows .= $divider_row;
1173 $total_discount =
'';
1174 if ($order[
'total_discount'] > 0) {
1175 $total_discount = sprintf($total_discount_row_fmt, translate(
'ecom_form_total_discount:'), $order[
'total_discount']);
1176 $total_discount .= $divider_row;
1179 $total = sprintf($total_row_fmt, translate(
'ecom_form_total:'), $order[
'total']);
1180 $receipt = sprintf($receipt_fmt, $rows, $total_discount, $total);
1197 $total_discount = 0;
1200 $ecom_items = Array();
1201 $taxable_items = Array();
1202 $ecom_assets = Array();
1203 $ecom_questions = Array();
1206 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
1209 foreach ($assets_in_cart as $asset_id => $count) {
1210 $ecom_item[
'taxable'] = FALSE;
1211 $asset = $am->getAsset($asset_id);
1217 if (isset($promo_codes_in_cart[$asset_id])) {
1222 $name = $count.
' x '.$name.
' @'.$price;
1223 $price = $price * $count;
1226 $ecom_item[
'name'] = $name;
1227 $ecom_item[
'quantity'] = $count;
1228 $ecom_item[
'price'] = $price;
1229 $ecom_item[
'discount'] = $discount;
1230 $ecom_item[
'id'] = $asset_id;
1235 $taxable_items[$asset_id] = $ecom_item;
1236 $taxable_total += $ecom_item[
'price'];
1237 $ecom_item[
'taxable'] = TRUE;
1239 $ecom_assets[$asset_id] = $ecom_item;
1240 $ecom_items[$asset_id] = $ecom_item;
1241 $total += $ecom_item[
'price'];
1242 $total_discount += $ecom_item[
'discount'];
1243 $am->forgetAsset($asset);
1247 $taxable_rules = $this->
attr(
'taxable_rules');
1249 foreach ($questions as $q_id => $question) {
1251 $ecom_item[
'taxable'] = FALSE;
1252 $question_title = $question->attr(
'name');
1257 $ecom_item[
'name'] =
'';
1258 $ecom_item[
'price'] =
'';
1259 if ($question->isSelection()) {
1260 foreach ($rule as $option_id => $price) {
1262 if ($question->isSelected($option_id) && (!($question instanceof Form_question_type_select) || !$question->isEmptyOption($option_id))) {
1263 if (isset($ecom_item[
'name']) && !empty($ecom_item[
'name'])) {
1264 $ecom_item[
'name'] .=
', '.$question->getOptionName($option_id);
1266 $ecom_item[
'name'] = $question_title.
': '.$question->getOptionName($option_id);
1268 if (!isset($ecom_item[
'price']) && !empty($ecom_item[
'price'])) {
1269 $ecom_item[
'price'] = $price;
1271 $ecom_item[
'price'] += $price;
1274 $ecom_item[
'id'] = $q_id;
1276 if (array_get_index($taxable_rules, $q_id, FALSE)) {
1277 $taxable_items[$q_id] = $ecom_item;
1278 $taxable_total += $price;
1279 $ecom_item[
'taxable'] = TRUE;
1281 $ecom_items[$q_id] = $ecom_item;
1282 $ecom_questions[$q_id] = $ecom_item;
1290 $ecom_item[
'name'] = $question_title;
1291 $ecom_item[
'price'] = $this->current_answers[$q_id];
1292 $ecom_item[
'id'] = $q_id;
1294 if (array_get_index($taxable_rules, $q_id, FALSE)) {
1295 $taxable_items[$q_id] = $ecom_item;
1296 $taxable_total += $ecom_item[
'price'];
1297 $ecom_item[
'taxable'] = TRUE;
1299 $ecom_items[$q_id] = $ecom_item;
1300 $ecom_questions[$q_id] = $ecom_item;
1301 $total += $ecom_item[
'price'];
1308 $order[
'items'] = $ecom_items;
1309 $order[
'ecom_assets'] = $ecom_assets;
1310 $order[
'ecom_questions'] = $ecom_questions;
1311 $order[
'taxable_items'] = $taxable_items;
1312 $order[
'taxable_total'] = $taxable_total;
1313 $order[
'total'] = $total - $total_discount;
1314 $order[
'total_discount'] = $total_discount;
1315 $order[
'submission'] = $this->current_answers;
1316 $order[
'submission_extra_data'] = $this->extra_data;
1318 $_SESSION[$this->
getPrefix()][
'order'] = $order;
1334 $order = $_SESSION[$this->
getPrefix()][
'order'];
1335 $order_contents = serialize($order);
1336 return string_to_file($order_contents, $filename);
1350 $order = file_to_string($filename);
1351 if (!$order)
return FALSE;
1352 $_SESSION[$this->
getPrefix()][
'order'] = unserialize($order);
1353 return $_SESSION[$this->
getPrefix()][
'order'];
1387 $order_path = $this->data_path.
'/tmp_orders';
1389 if (!is_dir($order_path)) {
1391 chmod($order_path, 0700);
1394 if (!$order_no) $order_no = session_id();
1396 return $order_path.
'/'.$order_no.
'.tmp';
1411 $keyword_list = $body->getKeywords();
1412 $replacements = Array();
1413 foreach ($keyword_list as $keyword) {
1417 $body->setKeywordReplacements($replacements);
1432 $replacements = Array();
1434 $keyword_list = $body->getKeywords();
1435 foreach ($keyword_list as $keyword) {
1439 $body->setKeywordReplacements($replacements);
1453 $parent_page_assetid = array_get_index($this->_tmp,
'parent_form_page_assetid');
1455 if (is_null($parent_page_assetid)) {
1456 $parents = array_keys($GLOBALS[
'SQ_SYSTEM']->am->getParents($this->id,
'page_custom_form_ecommerce', FALSE));
1457 $parent_page_assetid = array_pop($parents);
1458 $this->_tmp[
'parent_form_page_assetid'] =& $parent_page_assetid;
1461 return $parent_page_assetid;
1474 if (!isset($this->_tmp[
'parent_form_page_asset'])) {
1476 $this->_tmp[
'parent_form_page_asset'] =& $parent_page;
1478 $parent_page =& $this->_tmp[
'parent_form_page_asset'];
1481 return $parent_page;
1496 $url = array_get_index($this->_tmp,
'current_url');
1498 if (is_null($url)) {
1500 $url = $parent->getURL();
1502 $this->_tmp[
'current_url'] = $url;
1521 $keywords = parent::_getThankYouBodycopyKeywords();
1523 $keywords[
'confirm_text'] =
'Confirm and pay button text';
1524 $keywords[
'cancel_text'] =
'Text Used on "Cancel" button';
1526 $keywords[
'confirm_url'] =
'URL to Confirmation Screen';
1527 $keywords[
'cancel_url'] =
'URL to Cancel Screen';
1529 $keywords[
'order_item_count'] =
'Count of items being purchased';
1530 $keywords[
'order_total'] =
'Total';
1531 $keywords[
'order_total_excluding_tax'] =
'Total minus tax';
1532 $keywords[
'order_total_tax'] =
'Total tax';
1533 $keywords[
'order_taxable_total'] =
'Taxable total';
1534 $keywords[
'order_taxable_item_count'] =
'Count of taxable items being purchased';
1535 $keywords[
'order_item_list'] =
'List of items being purchased';
1536 $keywords[
'order_total_discount'] =
'Total discount';
1537 $keywords[
'order_total_before_discount'] =
'Total before discount';
1539 $keywords[
'tax_rate'] =
'Tax Rate';
1540 $keywords[
'tax_name'] =
'Tax Name';
1542 $keywords[
'taxable_item_string'] =
'String appended to the taxable items';
1560 return $this->
attr(
'confirm_button_name');
1573 return $this->
attr(
'cancel_button_name');
1586 $confrim_url = $this->
getUrl();
1587 $confrim_url .=
'?'.$this->getPrefix().
'_action=process';
1589 return $confrim_url;
1602 $cancel_url = $this->
getUrl();
1619 if (isset($_SESSION[$this->
getPrefix()][
'order'][
'items'])) {
1620 $item_count = count($_SESSION[$this->
getPrefix()][
'order'][
'items']);
1655 return $total_discount;
1670 $total_before_discount = $total + $total_discount;
1673 return $total_before_discount;
1690 $total_no_tax = $total - $tax;
1693 return $total_no_tax;
1723 return $taxable_total;
1738 if (isset($_SESSION[$this->
getPrefix()][
'order'][
'taxable_items'])) {
1739 $taxable_count = count($_SESSION[$this->
getPrefix()][
'order'][
'taxable_items']);
1741 return $taxable_count;
1767 return $this->
attr(
'tax_name');
1780 $item_format = $this->
attr(
'item_format');
1781 $keywords = extract_keywords($item_format);
1785 $item_line = $item_format;
1787 $item_name = array_get_index($item,
'name',
'--UNKNOWN ITEM NAME--');
1788 $item_price = array_get_index($item,
'price', 0);
1789 $item_id = array_get_index($item,
'id');
1790 $is_taxable = array_get_index($item,
'taxable', FALSE);
1792 $replacements[
'item_name'] = $item_name;
1794 $replacements[
'currency_sign'] = $this->
attr(
'currency_sign');
1795 $replacements[
'item_taxable_string'] =
'';
1797 $replacements[
'taxable_item_string'] = $this->
attr(
'item_taxable_string');
1799 replace_keywords($item_line, $replacements);
1804 return ob_get_clean();
1817 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
1820 $item_format = $this->
attr(
'form_asset_format');
1823 foreach ($assets_in_cart as $asset_id => $count) {
1824 $asset =& $am->getAsset($asset_id);
1831 $name = $count.
' x '.$name.
' @'.$price;
1832 $price = $price * $count;
1835 $replacements[
'item_name'] = $name;
1837 $replacements[
'currency_sign'] = $this->
attr(
'currency_sign');
1838 $replacements[
'item_taxable_string'] =
'';
1840 $replacements[
'taxable_item_string'] = $this->
attr(
'item_taxable_string');
1844 $item_line = $asset->replaceKeywordsInString($item_format);
1846 replace_keywords($item_line, $replacements);
1851 return ob_get_clean();
1865 if (empty($item_printout)) {
1866 return $this->
attr(
'form_assets_empty_str');
1869 $form_assets_format = $this->
attr(
'form_asset_list_format');
1870 $keywords[
'item_format'] = $item_printout;
1871 replace_keywords($form_assets_format, $keywords);
1873 return $form_assets_format;
1886 return $this->
attr(
'item_taxable_string');
1899 return $this->
attr(
'currency_sign');
1912 return array_get_index($this->_tmp[
'GATEWAY_RESPONSE'],
'TRANSACTION',
'');
1925 return array_get_index($this->_tmp[
'GATEWAY_RESPONSE'],
'STATUS',
'');
1938 return array_get_index($this->_tmp[
'GATEWAY_RESPONSE'],
'TYPE',
'');
1951 return array_get_index($this->_tmp[
'GATEWAY_RESPONSE'],
'TIME',
'');
1964 $amount = array_get_index($this->_tmp[
'GATEWAY_RESPONSE'],
'AMOUNT',
'');
1978 return array_get_index($this->_tmp[
'GATEWAY_RESPONSE'],
'CARDNO',
'');
1991 return array_get_index($this->_tmp[
'GATEWAY_RESPONSE'],
'BILLING_NAME',
'');
2004 return array_get_index($this->_tmp[
'GATEWAY_RESPONSE'],
'BILLING_ADDR',
'');
2017 return array_get_index($this->_tmp[
'GATEWAY_RESPONSE'],
'DELIVERY_NAME',
'');
2030 return array_get_index($this->_tmp[
'GATEWAY_RESPONSE'],
'DELIVERY_ADDR',
'');
2044 if (is_null($order))
return;
2059 if (!empty($this->order)) {
2060 $order =& $this->order;
2064 $order_id = @$_SESSION[$this->
getPrefix()][
'order_id'];
2065 if (empty($order_id)) {
2070 $this->order =& $GLOBALS[
'SQ_SYSTEM']->am->getAsset($order_id);
2071 $order =& $this->order;
2085 $assets_in_cart = @$_SESSION[$this->
getPrefix()][
'assets'];
2086 if (is_null($assets_in_cart)) {
2087 $assets_in_cart = Array();
2089 return $assets_in_cart;
2102 $_SESSION[$this->
getPrefix()][
'assets'] = Array();
2118 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
2119 if (is_null($asset))
return FALSE;
2122 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
2128 if (!is_numeric($quantity) || $quantity <= 0) {
2135 $_SESSION[$this->
getPrefix()][
'assets'] = Array();
2136 $_SESSION[$this->
getPrefix()][
'assets'][$assetid] = $quantity;
2138 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
2153 $promo_codes_in_cart = @$_SESSION[$this->
getPrefix()][
'promo_code_assets'];
2154 if (is_null($promo_codes_in_cart)) {
2155 $promo_codes_in_cart = Array();
2158 return $promo_codes_in_cart;
2171 $_SESSION[$this->
getPrefix()][
'promo_code_assets'] = Array();
2187 if (trim($promo_code) ==
'')
return;
2189 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
2190 if (is_null($asset))
return;
2193 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
2199 if (!is_null($promo_code_asset)){
2203 $_SESSION[$this->
getPrefix()][
'promo_code_assets'] = Array();
2204 $_SESSION[$this->
getPrefix()][
'promo_code_assets'][$assetid] = $promo_code_asset->id;
2205 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($promo_code_asset);
2208 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
2225 $promo_code_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($promo_code_assetid);
2226 $asset_data = Array(
'price' => $price,
'quantity' => $quantity);
2228 $promo_code_asset->process($asset_data);
2230 return $asset_data[
'discount'];
2245 if (isset($_SESSION[$this->
getPrefix()][
'order'][
'total'])) {
2246 $total = $_SESSION[$this->
getPrefix()][
'order'][
'total'];
2261 $total_discount = 0;
2263 if (isset($_SESSION[$this->
getPrefix()][
'order'][
'total_discount'])) {
2264 $total_discount = $_SESSION[$this->
getPrefix()][
'order'][
'total_discount'];
2267 return $total_discount;
2284 if (isset($_SESSION[$this->
getPrefix()][
'order'][
'taxable_total'])) {
2285 $taxable_total = $_SESSION[$this->
getPrefix()][
'order'][
'taxable_total'];
2287 return $taxable_total;
2300 return $this->
attr(
'tax_value');
2316 $total_tax = $taxable_total * $tax_rate/(100 + $tax_rate);
2332 $items = @$_SESSION[$this->
getPrefix()][
'order'][
'items'];
2333 if (is_null($items) || !is_array($items)) {
2352 $price_string = $this->
attr(
'asset_price_source');
2353 $price = $asset->replaceKeywordsInString($price_string);
2355 if (!is_numeric($price)) $price = 0;
2372 $name_string = $this->
attr(
'asset_name_source');
2373 $name = $asset->replaceKeywordsInString($name_string);
2376 $name = $asset->replaceKeywordsInString(
'%asset_name%');
2392 $key_val_arr = Array();
2393 $var_rules = $this->
attr(
'key_val_rules');
2394 if (empty($var_rules)) {
2395 return $key_val_arr;
2399 foreach ($questions as $q_id => $question) {
2400 if (key_exists($q_id, $var_rules)) {
2401 $var_rule = $var_rules[$q_id];
2402 $key = array_get_index($var_rule,
'key',
'');
2403 if (trim($key) ==
'') {
2409 $options = array_get_index($var_rule,
'value', Array());
2410 foreach ($options as $option_id => $option_val) {
2412 if ($question->isSelected($option_id) && (!($question instanceof Form_question_type_select) || !$question->isEmptyOption($option_id))) {
2418 $val = $this->current_answers[$q_id];
2421 $key_val_arr[$key] = $val;
2425 return $key_val_arr;
2440 $price_string = $this->
attr(
'asset_price_source');
2441 $price = $asset->replaceKeywordsInString($price_string);
2443 return is_numeric($price);
2458 $tax_source_string = $this->
attr(
'asset_taxable_source');
2459 $tax_check_string = $asset->replaceKeywordsInString($tax_source_string);
2461 return $tax_check_string !==
'';
2476 $multiple_source_string = $this->
attr(
'asset_multiple_source');
2477 $check_string = $asset->replaceKeywordsInString($multiple_source_string);
2479 return $check_string !==
'';
2494 $promotable_source_string = $this->
attr(
'asset_promotable_source');
2495 $check_string = $asset->replaceKeywordsInString($promotable_source_string);
2497 return (
boolean) $check_string;
2513 $am = $GLOBALS[
'SQ_SYSTEM']->am;
2514 $links = $am->getLinks($asset->id, SQ_LINK_NOTICE,
'promotional_code', TRUE,
'minor', $promo_code);
2516 foreach ($links as $link) {
2517 $promo_code_asset = $am->getAsset($link[
'majorid']);
2518 if (!is_null($promo_code_asset) && ($promo_code_asset->status == SQ_STATUS_LIVE)) {
2519 return $promo_code_asset;
2538 return sprintf(
'%01.2f', $amount);
2554 $taxable = @$_SESSION[$this->
getPrefix()][
'order'][
'taxable_items'][$item_id];
2555 return !is_null($taxable);
2598 if (!$file_pointer = fopen($file,
'a'))
return FALSE;
2600 $sucess = fputs($file_pointer, $string);
2601 fclose($file_pointer);
2602 if ($sucess === FALSE) {
2603 trigger_error(
'Unable to write '.$file, E_USER_WARNING);