Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
form_ecommerce_edit_fns.inc
1 <?php
18 require_once SQ_PACKAGES_PATH.'/cms/form/form_email/form_email_edit_fns.inc';
19 
20 require_once SQ_FUDGE_PATH.'/datetime_field/datetime_field.inc';
21 require_once SQ_FUDGE_PATH.'/general/datetime.inc';
22 
36 {
37 
38 
49  function paintBodycopyList(&$asset, &$o, $prefix)
50  {
51  $o->openRaw();
52 
53  $bodycopies = $asset->_bodycopies;
54  foreach ($bodycopies as $one_bodycopy) {
55  $bodycopy_asset = $asset->getBodycopy($one_bodycopy);
56  echo '<div style="padding:1ex;">';
57  echo get_asset_tag_line($bodycopy_asset->id, 'contents');
58  echo '</div>';
59  }
60 
61  $o->closeRaw();
62 
63  }//end paintBodycopyList()
64 
65 
76  function processUseBodycopy(&$asset, &$o, $prefix)
77  {
78  return TRUE;
79 
80  }//end processUseBodycopy()
81 
82 
93  function paintEcommerceQuestionLinks(&$asset, &$o, $prefix)
94  {
95  $am =& $GLOBALS['SQ_SYSTEM']->am;
96  $write_access = $asset->writeAccess('attributes');
97 
98  $o->openRaw();
99 
100  echo '<table class="sq-backend-table">';
101  echo '<tr>';
102  echo '<th>Question Name</th>';
103  echo '<th>Ecom Enabled?</th>';
104  echo '<th>Is Taxable?</th>';
105  echo '<th>Options</th>';
106  echo '</tr>';
107 
108  $all_form_questions = $asset->getAllQuestions();
109  $taxable_rules = $asset->attr('taxable_rules');
110 
111  foreach ($all_form_questions as $q_id => $question_data) {
112  if (!$asset->_isAllowedQuestionType($question_data['question_type_code'])) {
113  continue;
114  }
115 
116  $rule = $asset->_getEcommerceRule($q_id);
117  $ecom_enabled = ($rule !== FALSE);
118 
119  echo '<tr>';
120  echo '<td>';
121  echo $question_data['attributes']['name'];
122  echo '</td>';
123  echo '<td>';
124  $ecom_enabled_prefix = $prefix.'_ecom_enabled['.$q_id.']';
125  if ($write_access) {
126  check_box($ecom_enabled_prefix, $q_id, $ecom_enabled);
127  } else {
128  echo '<img src="'.sq_web_path('lib').'/web/images/'.($ecom_enabled ? 'tick' : 'cross').'.gif" />';
129  }
130  echo '</td>';
131  echo '<td>';
132  $taxable = array_get_index($taxable_rules, $q_id, FALSE);
133  $taxable_prefix = $prefix.'_taxable['.$q_id.']';
134  if ($write_access) {
135  check_box($taxable_prefix, $q_id, $taxable);
136  } else {
137  echo '<img src="'.sq_web_path('lib').'/web/images/'.($taxable ? 'tick' : 'cross').'.gif" />';
138  }
139  echo '</td>';
140  echo '<td>';
141  if ($ecom_enabled) {
142  $question = $am->getAsset($q_id);
143  if ($question->isSelection()) {
144  echo '<table class="sq-backend-table">';
145  $options = $question->getOptions();
146  $local_prefix = $prefix.'_ecom_rule['.$q_id.']';
147  foreach ($options as $key => $option_text) {
148  // if this option is not --leave empty--, print out the rule change table
149  if (!($question instanceof Form_question_type_select) || !$question->isEmptyOption($key)){
150  echo '<tr>';
151  $rule_value = array_get_index($rule, $key, 0);
152  echo '<td class="sq-backend-table-header" nowrap="nowrap">';
153  echo $option_text;
154  echo '</td>';
155  echo '<td class="sq-backend-table-cell" width="100%">';
156  text_box($local_prefix.'['.$key.']', $rule_value, 5);
157  echo '</td>';
158  echo '</tr>';
159  }
160  }
161  echo '</table>';
162  } else {
163  echo translate('ecom_form_numeric_field');
164  }
165 
166  $am->forgetAsset($question);
167  } else {
168  echo '<em style="color: grey;">E-commerce support for this question is not enabled</em>';
169  }
170  echo '</td>';
171  echo '</tr>';
172  }//end foreach
173 
174  echo '</table>';
175 
176  $o->closeRaw();
177 
178  return $write_access;
179 
180  }//end paintEcommerceQuestionLinks()
181 
182 
193  function processEcommerceQuestionLinks(&$asset, &$o, $prefix)
194  {
195  // process the new rule list
196  $rule_list_name = $prefix.'_ecom_enabled';
197  $rule_list = array_get_index($_REQUEST, $rule_list_name);
198 
199  $new_rule_list = Array();
200  if (!empty($rule_list) && is_array($rule_list)) {
201  foreach ($rule_list as $id) {
202  $rule = $asset->_getEcommerceRule($id);
203  // if new rule is in the current list, just copy it to the new one
204  if ($rule) {
205  $new_rule = $rule;
206  // otherwise, create an empty rule
207  } else {
208  $new_rule = Array();
209  }
210  // add the rule to the new list
211  $new_rule_list[$id] = $new_rule;
212  }
213  }
214 
215  $asset->setAttrValue('rules', $new_rule_list);
216 
217  $rule_settings = array_get_index($_REQUEST, $prefix.'_ecom_rule', Array());
218 
219  foreach ($rule_settings as $q_id => $rule) {
220  $asset->_setEcommerceRule($q_id, $rule);
221  }
222 
223  $taxable = array_get_index($_REQUEST, $prefix.'_taxable', Array());
224  $asset->setAttrValue('taxable_rules', $taxable);
225 
226  return TRUE;
227 
228  }//end processEcommerceQuestionLinks()
229 
230 
241  function paintPassthroughVarQuestionLinks(&$asset, &$o, $prefix)
242  {
243  $am =& $GLOBALS['SQ_SYSTEM']->am;
244  $write_access = $asset->writeAccess('attributes');
245 
246  $o->openRaw();
247 
248  echo '<table class="sq-backend-table">';
249  echo '<tr>';
250  echo '<th>Question Name</th>';
251  echo '<th>Enabled?</th>';
252  echo '<th>Key</th>';
253  echo '<th>Value Options</th>';
254  echo '</tr>';
255 
256  $all_form_questions = $asset->getAllQuestions();
257  $var_rules = $asset->attr('key_val_rules');
258 
259  foreach ($all_form_questions as $q_id => $question_data) {
260  if (!$asset->_isAllowedPassThroughQuestionType($question_data['question_type_code'])) {
261  continue;
262  }
263 
264  $var_enabled = isset($var_rules[$q_id]);
265 
266  echo '<tr>';
267  echo '<td>';
268  echo $question_data['attributes']['name'];
269  echo '</td>';
270  echo '<td>';
271  $var_enabled_name = $prefix.'_var_enabled['.$q_id.']';
272  if ($write_access) {
273  check_box($var_enabled_name, $q_id, $var_enabled);
274  } else {
275  echo '<img src="'.sq_web_path('lib').'/web/images/'.($var_enabled ? 'tick' : 'cross').'.gif" />';
276  }
277  echo '</td>';
278  echo '<td>';
279  $pass_through_key_name = $prefix.'_pass_through_key['.$q_id.']';
280  if ($write_access) {
281  if ($var_enabled) {
282  text_box($pass_through_key_name, array_get_index($var_rules[$q_id], 'key', ''));
283  } else {
284  echo '<em style="color: grey;">None</em>';
285  }
286  } else {
287  if ($var_enabled) {
288  echo array_get_index($var_rules[$q_id], 'key', '');
289  } else {
290  echo '<em style="color: grey;">None</em>';
291  }
292  }
293  echo '</td>';
294  echo '<td>';
295  if ($var_enabled) {
296  $question = $am->getAsset($q_id);
297  if (!($question instanceof Form_Question_Type_Country) && $question->isSelection()) {
298  echo '<table class="sq-backend-table">';
299  $options = $question->getOptions();
300  $var_value = array_get_index($var_rules[$q_id], 'value', Array());
301  $local_prefix = $prefix.'_pass_through_value['.$q_id.']';
302  foreach ($options as $key => $option_text) {
303  // if this option is not --leave empty--, print out the rule change table
304  if (!($question instanceof Form_question_type_select) || !$question->isEmptyOption($key)){
305  echo '<tr>';
306  $rule_value = array_get_index($var_value, $key, '');
307  echo '<td class="sq-backend-table-header" nowrap="nowrap">';
308  echo $option_text;
309  echo '</td>';
310  echo '<td class="sq-backend-table-cell" width="100%">';
311  text_box($local_prefix.'['.$key.']', $rule_value);
312  echo '</td>';
313  echo '</tr>';
314  }
315  }
316  echo '</table>';
317  } else {
318  echo 'The value supplied by the user will be passed through to the Payment Gateway.';
319  }
320 
321  $am->forgetAsset($question);
322  } else {
323  echo '<em style="color: grey;">Pass through variable is not enabled for this question</em>';
324  }
325  echo '</td>';
326  echo '</tr>';
327  }//end foreach
328 
329  echo '</table>';
330 
331  $o->closeRaw();
332 
333  return $write_access;
334 
335  }//end paintPassthroughVarQuestionLinks()
336 
337 
348  function processPassthroughVarQuestionLinks(&$asset, &$o, $prefix)
349  {
350  // process the new pass through variable rule list
351  $var_list = array_get_index($_REQUEST, $prefix.'_var_enabled', Array());
352 
353  $new_var_list = Array();
354  if (!empty($var_list)) {
355  $key_list = array_get_index($_REQUEST, $prefix.'_pass_through_key', Array());
356  $value_list = array_get_index($_REQUEST, $prefix.'_pass_through_value', Array());
357  foreach ($var_list as $id) {
358  // add the empty var to the new list
359  $new_var_list[$id] = Array(
360  'key' => array_get_index($key_list, $id, ''),
361  'value' => array_get_index($value_list, $id, Array()));
362  }
363  }
364 
365  $asset->setAttrValue('key_val_rules', $new_var_list);
366 
367  return TRUE;
368 
369  }//end processPassthroughVarQuestionLinks()
370 
371 
382  function paintExport(&$asset, &$o, $prefix)
383  {
384  if (!$asset->writeAccess('attributes')) return FALSE;
385  if (array_get_index($_POST, $prefix.'_export_switch', 0) == 1) {
386  $this->processExport($asset, $o, $prefix);
387  }
388 
389  // paint option goes here
390  echo hidden_field($prefix.'_export_switch', '0');
391 
392  echo normal_button($prefix.'_export', translate('download_file'), 'this.form.'.$prefix.'_export_switch.value = 1; this.form.submit(); SQ_FORM_SUBMITTED = false; this.form.'.$prefix.'_export_switch.value = 0; return true;');
393 
394  return TRUE;
395 
396  }//end paintExport()
397 
398 
409  function processExport(&$asset, &$o, $prefix)
410  {
411  if (!$_POST[$prefix.'_export_switch']) return TRUE;
412 
413  // begin and populate order object
414  header('Content-Type: application/xml');
415 
416  // defining the file as attachment forces most browsers to offer it for download
417  header('Content-Disposition: attachment; filename=order-summary-'.$asset->id.'.xml;');
418 
419  echo '<orders>'."\n";
420 
421  // get each order
422  $children_id = $GLOBALS['SQ_SYSTEM']->am->getChildren($asset->id, 'order', FALSE);
423 
424  foreach ($children_id as $child_id => $assettype) {
425  // retrieve asset with this id
426  echo "\t".'<order id="'.$child_id.'">'."\n";
427 
428  // get this orders children
429  $order_lines = $GLOBALS['SQ_SYSTEM']->am->getChildren($child_id, 'order_line', FALSE);
430 
431  foreach ($order_lines as $line_id => $assettype) {
432 
433  $child =& $GLOBALS['SQ_SYSTEM']->am->getAsset($line_id);
434 
435  // extract name quantity price etc
436  ?>
437  <order_line id="<?php echo $child_id ?>">
438  <product id="<?php echo $child->attr('product_assetid'); ?>"></product>
439  <quantity><?php echo $child->attr('quantity'); ?></quantity>
440  <price><?php echo $child->attr('price'); ?></price>
441  </order_line>
442  <?php
443  }
444 
445  echo "\t".'</order>'."\n";
446 
447  }
448 
449  echo '</orders>'."\n";
450  exit(0);
451 
452  return TRUE;
453 
454  }//end processExport()
455 
456 
467  function paintLogFileInfo(&$asset, &$o, $prefix)
468  {
469  $log_file = $asset->_getLogFilePath();
470  if (is_readable($log_file)) {
471  $last_modified = filemtime($log_file);
472  $file_size = filesize($log_file);
473  echo 'Filename: <strong>'.$log_file.'</strong>';
474  echo '<br />';
475  echo 'Last Modified: <strong>'.date('r', $last_modified).'</strong>';
476  echo '<br />';
477  echo 'Size: <strong>'.$file_size.'</strong>B';
478  } else {
479  echo 'Log file does not exist';
480  echo '<br />';
481  echo 'Filename: '.$log_file;
482  }
483 
484  }//end paintLogFileInfo()
485 
486 
496  public function paintNewAction(Form_Email $asset, Backend_Outputter $o, $prefix)
497  {
498  $write_access = $asset->writeAccess('attributes');
499 
500  // Currently we only have this action available in eCommerce
501  // We may need to create a new ecom_submission_action sub class in the feature
502  $types = Array('form_action_soap_call');
503 
504  $names = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($types, 'name');
505 
506 
507 
508  $o->openField('');
509  if ($write_access) {
510  ?><p><?php
511  check_box($prefix.'_new', '1', FALSE, 'this.form.'.$prefix.'_new_type.disabled = !this.checked; return true;');
512  ?><label for="<?php echo $prefix ?>_new">Create a new action of type:</label> <?php
513  $names = Array('' => 'Select action type...') + $names;
514  combo_box($prefix.'_new_type', $names, FALSE, '', 0, 'disabled="disabled"');
515  ?></p><?php
516  } else {
517  ?><p>This screen must be locked before you can create a new action.</p><?php
518  }
519 
520  // If we have a new action, are we
521  $o->closeField();
522 
523  $o->sectionNote('If you create a new action, the new action will be displayed immediately for you to edit. If you already have an action open to edit, the changes to that action will be saved when you commit before the new action is created.');
524 
525  return $write_access;
526 
527  }//end paintNewAction()
528 
529 }//end class
530 ?>