14 require_once SQ_PACKAGES_PATH.
'/ecommerce/delivery_methods/ecommerce_delivery_method/ecommerce_delivery_method.inc';
15 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
16 require_once SQ_LIB_PATH.
'/xml_array/xml_array.inc';
17 require_once SQ_FUDGE_PATH.
'/general/www.inc';
18 require_once SQ_PACKAGES_PATH.
'/ecommerce/lib/ecommerce_cart_processor.inc';
37 $this->_ser_attrs = TRUE;
53 if (!parent::_createAdditional($link))
return FALSE;
57 'type_code' =>
'simple_form',
58 'name' =>
'Form Contents',
59 'link_type' => SQ_LINK_TYPE_2,
62 'bodycopies' => Array(
63 'type_code' =>
'folder',
64 'name' =>
'Bodycopies',
65 'link_type' => SQ_LINK_TYPE_2,
71 $bodycopy_folder = NULL;
72 foreach ($sub_assets as $link_value => $sub_asset) {
73 $asset_type = $sub_asset[
'type_code'];
74 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($asset_type);
76 $asset =
new $asset_type();
79 'value' => $link_value,
80 'link_type' => $sub_asset[
'link_type'],
82 'is_exclusive' => $sub_asset[
'exclusive'],
85 $asset->setAttrValue(
'name', $sub_asset[
'name']);
86 $success = $asset->create($copy_link);
88 if ($link_value ==
'bodycopies') {
89 $bodycopy_folder = $asset;
92 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
100 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'bodycopy');
105 'asset' => &$bodycopy_folder,
106 'value' => $link_value,
107 'link_type' => SQ_LINK_TYPE_2,
112 $asset->setAttrValue(
'name', $bodycopy_name);
114 $success = $asset->create($copy_link);
116 if (!$success)
break;
136 $form_values = unserialize($_SESSION[
'order_extra_information']);
139 $keyword_remplacements = Array();
142 $confirmation_keywords = $bodycopy->getKeywords();
145 foreach ($confirmation_keywords as $keyword) {
146 $key_parts = explode(
'_', $keyword);
147 if ((count($key_parts) == 2 ) && ($key_parts[0] ==
'form')) {
149 $keyword_remplacements[$keyword] = $form_values[$key_parts[1]];
152 $bodycopy->setKeywordReplacements($keyword_remplacements);
155 $bodycopy->printBody();
156 $contents = ob_get_contents();
177 if (!is_array($vars[
'keywords'])) {
178 $vars[
'keywords'] = Array();
181 $bodycopy_folder_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE,
'bodycopies');
183 if (empty($bodycopy_folder_link)) {
186 $bodycopy_folder_id = $bodycopy_folder_link[
'minorid'];
189 $broadcaster_parents = $GLOBALS[
'SQ_SYSTEM']->am->getParents($broadcaster->id,
'bodycopy', TRUE);
190 $content_bodycopy_value = NULL;
191 foreach (array_keys($broadcaster_parents) as $bodycopy_id) {
192 $content_bodycopy_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkByAsset($bodycopy_folder_id, $bodycopy_id);
193 if (!empty($content_bodycopy_link) && !empty($content_bodycopy_link[
'value'])) {
194 $bodycopy_context = $content_bodycopy_link[
'value'];
201 if (empty($bodycopy_context) || !isset($contexts[$bodycopy_context])) {
205 require_once SQ_FUDGE_PATH.
'/general/text.inc';
207 $context_kw_fn =
'_get'.ucwords_no_space($bodycopy_context).
'BodycopyKeywords';
208 if (method_exists($this, $context_kw_fn)) {
209 $vars[
'keywords'] = array_merge($vars[
'keywords'], $this->$context_kw_fn());
226 $question_values = $form->getQuestions();
227 foreach ($question_values as $key => $value) {
228 $key_parts = explode(
':', $key);
229 $keywords[
'form_'.$key_parts[1]] = $value[
'name'].
' ('.$key_parts[1].
')';
247 $question_values = $form->getQuestions();
248 foreach ($question_values as $key => $value) {
249 $key_parts = explode(
':', $key);
250 $keywords[
'form_'.$key_parts[1]] = $value[
'name'].
' ('.$key_parts[1].
')';
268 $question_values = $form->getQuestions();
269 foreach ($question_values as $key => $value) {
270 $key_parts = explode(
':', $key);
271 $keywords[
'form_'.$key_parts[1]] = $value[
'name'].
' ('.$key_parts[1].
')';
286 $links = parent::_getAllowedLinks();
287 $links[SQ_LINK_TYPE_2] = Array(
288 'simple_form' => Array(
290 'exclusive' => FALSE,
314 case(
'form_question_type_text'):
315 case(
'form_question_type_numeric'):
316 case(
'form_question_type_email_address'):
317 case(
'form_question_type_select'):
318 case(
'form_question_type_option_list'):
319 case(
'form_question_type_tickbox_list'):
320 case(
'form_question_type_tickbox_table'):
321 case(
'form_question_type_country'):
342 $questions = $form->getQuestions();
343 $answers = unserialize($_SESSION[
'order_extra_information']);
345 foreach ($questions as $q_id => $question_data) {
346 $id_parts = explode(
':', $q_id);
347 $answer = array_get_index($answers, $id_parts[1],
'');
349 $xml_str .= <<<HEREDOC
352 <
id><![CDATA[$q_id]]></
id>
353 <name><![CDATA[{$question_data[
'name']}]]></name>
354 <answer><![CDATA[$answer]]></answer>
359 $xml_str = <<<HEREDOC
382 if ($html) echo
'<pre><ul>';
385 $question_values = $form->getQuestions();
386 $answers = unserialize($_SESSION[
'order_extra_information']);
387 foreach ($question_values as $key => $value) {
388 $key_parts = explode(
':', $key);
390 echo
'<li>'.$value[
'name'].
' ('.$key_parts[1].
') : '.$answers[$key_parts[1]].
'</li>';
392 echo $value[
'name'].
' ('.$key_parts[1].
') : '.$answers[$key_parts[1]].
"\n";
396 if ($html) echo
'</ul></pre>';
398 $receipt = ob_get_contents();
420 if (!empty($this->state[
'transaction_id'])) {
421 $tmp_order = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->state[
'transaction_id']);
422 $transaction_id = $this->state[
'transaction_id'];
424 $keywords = $bodycopy->getKeywords();
425 $form_values = $tmp_order->attr(
'order_form_value');
426 $keyword_replacements = Array();
427 foreach ($keywords as $keyword) {
428 $key_parts = explode(
'_', $keyword);
429 if ((count($key_parts) == 2) && ($key_parts[0] ==
'form')) {
430 $keyword_replacements[$keyword] = $form_values[$key_parts[1]];
433 $bodycopy->setKeywordReplacements($keyword_replacements);
439 if (!empty($transaction_id)) {
440 echo
'<p id="order_id"><span id="order_id_title">Order ID:</span> '.$transaction_id.
'</p>';
442 $bodycopy->printBody();
443 $contents = ob_get_contents();
474 'success' =>
'Success',
475 'failure' =>
'Failure',
476 'confirmation' =>
'Confirmation',
490 $interface = parent::getInputInterface();
495 $form->printBody(FALSE, FALSE);
496 $contents = ob_get_contents();
515 $ok = $form->process();
518 $question_values = $form->getQuestions();
519 $answers = $form->getAnswers();
520 $order_extra_info = Array();
521 foreach ($question_values as $key => $value) {
523 if (!empty($answers[$key][
'summary'])) {
524 $tmp_value = $answers[$key][
'summary'];
525 }
else if (!empty($answers[$key][
'value'])) {
526 $tmp_value = $answers[$key][
'value'];
528 $key_parts = explode(
':', $key);
529 $order_extra_info[$key_parts[1]] = $tmp_value;
531 if ($answers[$key][
'type_code'] ==
'form_question_type_country') {
532 $order_extra_info[$key] = $answers[$key][
'value'];
536 $_SESSION[
'order_extra_information'] = serialize($order_extra_info);
556 return $form->getErrors();
569 if (empty($this->_tmp[
'form'])) {
570 $this->_tmp[
'form'] = NULL;
572 $form_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'simple_form', TRUE,
'form');
574 $this->_tmp[
'form'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($form_link[
'minorid'],
'simple_form');
578 return $this->_tmp[
'form'];
597 return 'Sent to mail server';
634 $bodycopy->printBody();
635 $contents = ob_get_contents();
654 if (!$name)
return $null;
655 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
657 $folder_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE,
'bodycopies');
658 if (empty($folder_link))
return $null;
660 $folder = $am->getAsset($folder_link[
'minorid'], $folder_link[
'minor_type_code']);
661 if (is_null($folder))
return $null;
663 $bodycopy_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($folder->id, SQ_LINK_TYPE_2,
'bodycopy', TRUE, $name);
664 if (empty($bodycopy_link))
return $null;
666 $bodycopy = $am->getAsset($bodycopy_link[
'minorid'], $bodycopy_link[
'minor_type_code']);
668 if (!empty($bodycopy))
return $bodycopy;
692 function processDelivery(&$order, &$contents_bodycopy, &$format_bodycopy, $currency_symbol=
'$', $float_precision=2, $taxation_name=
'GST', $taxation_rate=0.0, $flat_charges=Array(), $neg_quantity_list=
'', $neg_quantity_message=
'')
694 $this->state[
'transaction_id'] = $order->id;
696 $order->setOrderStatus(SQ_ECOM_ORDER_STATUS_PROCESSING,
'Pending');
698 if ($this->
attr(
'send_emails')) {
699 $email_receipt_attr = $this->
getAttribute(
'receipt_emails_format');
700 $email_recipient_attr = $this->
getAttribute(
'recipient_emails_format');
702 $receipt_value = @unserialize($email_receipt_attr->value);
703 $recipient_value = @unserialize($email_recipient_attr->value);
706 $keywords_replacements = Array();
707 $keywords_to_replace = Array();
710 $keywords_to_replace[] =
'order_id';
711 $keywords_replacements[] = $this->state[
'transaction_id'];
714 $keywords_to_replace[] =
'transaction_id';
715 $keywords_replacements[] = $order->attr(
'transaction_id');
718 $keywords_to_replace[] =
'merchant_transaction_id';
719 $keywords_replacements[] = $order->attr(
'ecom_ref_no');
722 $keywords_to_replace[] =
'order_receipt';
726 $cart->setCartContainer($_SESSION[
'sq_local_cart_contents'][
'cart_contents']);
727 $tmp_order_receipt_cart =
'<pre>';
728 $tmp_order_receipt_cart_text =
'';
730 echo
'Order ID: '.$this->state[
'transaction_id'].
"\n\n";
732 $remove_tax = isset($_SESSION[
'sq_region_specific'][
'remove_tax']) ? $_SESSION[
'sq_region_specific'][
'remove_tax'] : FALSE;
733 $cart->printReceipt($taxation_name, $taxation_rate, $flat_charges, $remove_tax, $currency_symbol, $float_precision);
735 $tmp_order_receipt_cart_text .= ob_get_contents();
737 $tmp_order_receipt_cart .= $tmp_order_receipt_cart_text.
'</pre>';
740 $tmp_order_receipt_form =
'<pre>'.$this->getReceipt(TRUE).
'</pre>';
741 $keywords_replacements[] = $tmp_order_receipt_cart.$tmp_order_receipt_form;
744 $keywords_to_replace[] =
'cart_summary';
745 $keywords_replacements[] = $tmp_order_receipt_cart;
747 $keywords_to_replace[] =
'cart_summary_text';
748 $keywords_replacements[] = $tmp_order_receipt_cart_text;
751 if (!is_null($contents_bodycopy) && !is_null($format_bodycopy)) {
752 $keywords_to_replace[] =
'customised_receipt';
753 $keywords_replacements[] = $cart->printCustomisedReceipt($contents_bodycopy, $format_bodycopy, $taxation_name, $taxation_rate, $flat_charges, $remove_tax, $currency_symbol, $float_precision);
757 $keywords_to_replace[] =
'form_summary';
758 $keywords_replacements[] = $tmp_order_receipt_form;
760 $keywords_to_replace[] =
'form_summary_text';
761 $keywords_replacements[] = $this->
getReceipt(FALSE);
765 $keywords_to_replace[] =
'negative_quantity_product_list';
766 $keywords_replacements[] = $neg_quantity_list;
767 $keywords_to_replace[] =
'negative_quantity_message';
768 $keywords_replacements[] = $neg_quantity_message;
771 $form_values = unserialize($_SESSION[
'order_extra_information']);
773 $tmp_questions = $tmp_form->getQuestions();
774 foreach ($tmp_questions as $key => $value) {
775 $key_parts = explode(
':', $key);
776 $keywords_to_replace[] =
'response_'.$key_parts[1].
'';
777 if (!empty($form_values[$key_parts[1]])) {
778 $keywords_replacements[] = $form_values[$key_parts[1]];
780 $keywords_replacements[] =
'';
785 $send_mail_replacements = Array();
786 for ($i = 0; $i < count($keywords_to_replace); $i++) {
787 $send_mail_replacements = array_merge($send_mail_replacements, Array($keywords_to_replace[$i] => $keywords_replacements[$i]));
791 $email_recipient_attr->sendMail($send_mail_replacements);
792 $email_receipt_attr->sendMail($send_mail_replacements);
798 $order->setOrderStatus(SQ_ECOM_ORDER_STATUS_SUCCESS);
800 $order->setOrderStatus(SQ_ECOM_ORDER_STATUS_FAILED);
802 $order->setAttrValue(
'order_form_value', unserialize($_SESSION[
'order_extra_information']));
820 $gateway_asset =& $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->
attr(
'payment_gateway'));
821 $gateway_asset_url = $gateway_asset->getURL();
823 $_SESSION[
'SQ_ECOM_AMOUNT'] = $total_cost;
825 $checkout_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_NOTICE,
'ecommerce_checkout', TRUE,
'delivery_method',
'minor');
826 $checkout_url = $GLOBALS[
'SQ_SYSTEM']->am->getAssetURL($checkout_link[
'majorid']);
827 $checkout =& $GLOBALS[
'SQ_SYSTEM']->am->getAsset($checkout_link[
'majorid']);
829 $_SESSION[
'SQ_ECOM_SUCCESS_URL'] = $checkout_url.
'?'.$checkout->getPrefix().
'_action=payment_gateway_successful';
830 $_SESSION[
'SQ_ECOM_CANCEL_URL'] = $checkout_url.
'?'.$checkout->getPrefix().
'_action=return_to_checkout';
831 $_SESSION[
'SQ_ECOM_REF_NO'] = md5(session_id().time());
835 if (!empty($pass_through_vars)) {
836 $_SESSION[
'SQ_ECOM_PASS_THROUGH_VARS'] = $pass_through_vars;
839 $pending_order_id = array_get_index($_SESSION[
'sq_local_cart_contents'],
'pending_order_id', NULL);
840 $pending_order = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($_SESSION[
'sq_local_cart_contents'][
'pending_order_id']);
842 $pending_order->setAttrValue(
'ecom_ref_no', $_SESSION[
'SQ_ECOM_REF_NO']);
843 $pending_order->appendAuditLog(translate(
'ecom_ref_num_recorded_before_processing'));
845 header(
'Location: '.$gateway_asset_url);
858 $key_val_arr = Array();
859 $var_rules = $this->
attr(
'key_val_rules');
860 if (empty($var_rules)) {
865 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
868 $current_answers = unserialize($_SESSION[
'order_extra_information']);
871 $questions = $form->getQuestions();
872 foreach ($questions as $q_id => $question_data) {
873 if (key_exists($q_id, $var_rules)) {
874 $var_rule = $var_rules[$q_id];
875 $key = array_get_index($var_rule,
'key',
'');
876 if (trim($key) ==
'') {
881 $question = $am->getAsset($q_id);
883 $val = $current_answers[$q_id];
884 }
else if ($question->isSelection()) {
885 $options = array_get_index($var_rule,
'value', Array());
886 foreach ($options as $option_id => $option_val) {
888 if ($question->isSelected($option_id) && (!($question instanceof Form_question_type_select) || !$question->isEmptyOption($option_id))) {
894 $key_parts = explode(
':', $q_id);
895 if (!empty($current_answers[$key_parts[1]])) {
896 $val = $current_answers[$key_parts[1]];
900 $key_val_arr[$key] = $val;