Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
paypal_payment_button_edit_fns.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/page/page_edit_fns.inc';
19 
32 {
33 
38  function __construct()
39  {
40  parent::__construct();
41  $this->static_screens['details']['force_unlock'] = FALSE;
42 
43  }//end constructor
44 
45 
56  function paintItemName(&$asset, &$o, $prefix)
57  {
58  if ($asset->attr('button_type') == '_view_cart') return TRUE;
59 
60  if ($asset->attr('button_type') == '_donations') {
61  $field_name = 'Organization name/service';
62  $note = 'The name of your organization or the purpose for the donation. Global keywords can be used here.';
63  } else {
64  $field_name = 'Item name';
65  $note = 'The name of the item or service that you wish to sell. Global keywords can be used here.';
66  }
67 
68  $o->openField($field_name, '', $note);
69 
70  $item_name = $asset->attr('item_name');
71  if ($asset->writeAccess('attributes')) {
72  text_box($prefix.'_item_name', $item_name, 60);
73  } else {
74  echo htmlspecialchars($item_name);
75  }
76 
77  return TRUE;
78 
79  }//end paintItemName()
80 
81 
92  function processItemName(&$asset, &$o, $prefix)
93  {
94  if (!$asset->writeAccess('attributes')) return FALSE;
95  if ($asset->attr('button_type') == '_view_cart') return FALSE;
96  if (!isset($_POST[$prefix.'_item_name'])) return FALSE;
97 
98  $item_name = $_POST[$prefix.'_item_name'];
99 
100  return $asset->setAttrValue('item_name', $item_name);
101 
102  }//end processItemName()
103 
104 
115  function paintItemID(&$asset, &$o, $prefix)
116  {
117  if ($asset->attr('button_type') == '_view_cart') return TRUE;
118 
119  if ($asset->attr('button_type') == '_donations') {
120  $field_name = 'Donation ID';
121  $note = 'A value to help identify different kinds of contribution payments, for example, the name of your current fund-raising campaign';
122  } else {
123  $field_name = 'Item ID';
124  $note = 'Pass-through variable that will return to Matrix after Paypal finishes processing. This value is usually an asset ID and can be viewed by customers. Thus, it should not be used if the asset ID is secret to customers.';
125  }
126 
127  $o->openField($field_name, '', $note);
128 
129  $item_id = $asset->attr('item_id');
130  if ($asset->writeAccess('attributes')) {
131  text_box($prefix.'_item_id', $item_id, 60);
132  } else {
133  echo htmlspecialchars($item_id);
134  }
135 
136  return TRUE;
137 
138  }//end paintItemID()
139 
140 
151  function processItemID(&$asset, &$o, $prefix)
152  {
153  if (!$asset->writeAccess('attributes')) return FALSE;
154  if ($asset->attr('button_type') == '_view_cart') return FALSE;
155  if (!isset($_POST[$prefix.'_item_id'])) return FALSE;
156 
157  $item_id = $_POST[$prefix.'_item_id'];
158 
159  return $asset->setAttrValue('item_id', $item_id);
160 
161  }//end processItemID()
162 
163 
174  function paintPrice(&$asset, &$o, $prefix)
175  {
176  if ($asset->attr('button_type') == '_view_cart') return TRUE;
177 
178  if ($asset->attr('button_type') == '_donations') {
179  $field_name = 'Amount';
180  $note = 'The fixed contribution amount. If you leave the field blank, donors enter their own contribution amount after they click the Donate button. Global keywords can be used here.';
181  } else {
182  $field_name = 'Price';
183  $note = 'The fixed price for your item. If you leave the field blank, buyers "name their own price" after they click the Buy Now button. Global keywords can be used here.';
184  }
185 
186  $o->openField($field_name, '', $note);
187 
188  $price = $asset->attr('price');
189  if ($asset->writeAccess('attributes')) {
190  text_box($prefix.'_price', $price, 40);
191  } else {
192  echo htmlspecialchars($price);
193  }
194 
195  return TRUE;
196 
197  }//end paintPrice()
198 
199 
210  function processPrice(&$asset, &$o, $prefix)
211  {
212  if (!$asset->writeAccess('attributes')) return FALSE;
213  if ($asset->attr('button_type') == '_view_cart') return FALSE;
214  if (!isset($_POST[$prefix.'_price'])) return FALSE;
215 
216  $price = $_POST[$prefix.'_price'];
217 
218  return $asset->setAttrValue('price', $price);
219 
220  }//end processPrice()
221 
222 
233  function paintCurrency(&$asset, &$o, $prefix)
234  {
235  if ($asset->attr('button_type') == '_view_cart') return TRUE;
236 
237  $field_name = 'Currency';
238  $note = 'The currency of the price.';
239 
240  $o->openField($field_name, '', $note);
241 
242  $attr = $asset->getAttribute('currency');
243 
244  $attr->paint($prefix.'_'.$attr->id, !$asset->writeAccess('attributes'));
245 
246  return TRUE;
247 
248  }//end paintCurrency()
249 
250 
261  function processCurrency(&$asset, &$o, $prefix)
262  {
263  if (!$asset->writeAccess('attributes')) return FALSE;
264  if ($asset->attr('button_type') == '_view_cart') return FALSE;
265 
266  $attr = $asset->getAttribute('currency');
267 
268  $attr->process($prefix.'_'.$attr->id);
269 
270  return ($attr->processed && $asset->setAttrValue($attr->name, $attr->value));
271 
272  }//end processCurrency()
273 
274 
285  function paintUndefinedQuantity(&$asset, &$o, $prefix)
286  {
287  if ($asset->attr('button_type') != '_xclick') return TRUE;
288 
289  $field_name = 'Undefined quantity?';
290  $note = 'Yes, if buyers can update the item quantity in payment process.';
291 
292  $o->openField($field_name, '', $note);
293 
294  $options = Array(
295  '1' => 'Yes',
296  '0' => 'No',
297  );
298 
299  $undefined_quantity = $asset->attr('undefined_quantity');
300  if ($asset->writeAccess('attributes')) {
301  combo_box($prefix.'_undefined_quantity', $options, FALSE, $undefined_quantity);
302  } else {
303  echo $options[$undefined_quantity];
304  }
305 
306  return TRUE;
307 
308  }//end paintUndefinedQuantity()
309 
310 
321  function processUndefinedQuantity(&$asset, &$o, $prefix)
322  {
323  if (!$asset->writeAccess('attributes')) return FALSE;
324  if ($asset->attr('button_type') != '_xclick') return FALSE;
325  if (!isset($_POST[$prefix.'_undefined_quantity'])) return FALSE;
326 
327  $undefined_quantity = $_POST[$prefix.'_undefined_quantity'];
328 
329  return $asset->setAttrValue('undefined_quantity', $undefined_quantity);
330 
331  }//end processUndefinedQuantity()
332 
333 
344  function paintCustomVar(&$asset, &$o, $prefix)
345  {
346  if ($asset->attr('button_type') == '_view_cart') return TRUE;
347 
348  $field_name = 'Custom variable';
349  $note = 'Pass-through variable that will return to Matrix after Paypal finishes processing. This value can be any extra information that Paypal will send back after a customer purchases an item. This value is never presented to customers so it can be used to send secret data under the format var1=value1,var2=value2. These values can be extracted by an IPN Receiver asset later. Globals keywords like %globals_user_assetid% can be used.';
350 
351 
352  if ($asset->attr('button_type') == '_cart') {
353  $note .= ' You should use the same value for this field in all <b>Add to Cart</b> buttons because the last clicked button\'s custom variable is returned and you will not know what it is.';
354  }
355 
356  $o->openField($field_name, '', $note);
357 
358  $custom_var = $asset->attr('custom_var');
359  if ($asset->writeAccess('attributes')) {
360  text_box($prefix.'_custom_var', $custom_var, 60);
361  } else {
362  echo htmlspecialchars($custom_var);
363  }
364 
365  return TRUE;
366 
367  }//end paintCustomVar()
368 
369 
380  function processCustomVar(&$asset, &$o, $prefix)
381  {
382  if (!$asset->writeAccess('attributes')) return FALSE;
383  if ($asset->attr('button_type') == '_view_cart') return FALSE;
384  if (!isset($_POST[$prefix.'_custom_var'])) return FALSE;
385 
386  $custom_var = $_POST[$prefix.'_custom_var'];
387 
388  return $asset->setAttrValue('custom_var', $custom_var);
389 
390  }//end processCustomVar()
391 
392 
403  function paintNotifyUrl(&$asset, &$o, $prefix)
404  {
405  if ($asset->attr('button_type') == '_view_cart') return TRUE;
406 
407  $field_name = 'Notify URL';
408  $note = 'This is the URL that Paypal will POST an Instant Payment Notification (IPN) to. It must be the URL of an IPN Receiver asset.';
409 
410 
411  if ($asset->attr('button_type') == '_cart') {
412  $note .= ' You should use the same value for this field in all <b>Add to Cart</b> buttons because the last clicked button\'s notify URL is used by Paypal and you will not know what it is.';
413  }
414 
415  $o->openField($field_name, '', $note);
416 
417  $notify_url = $asset->attr('notify_url');
418  if ($asset->writeAccess('attributes')) {
419  text_box($prefix.'_notify_url', $notify_url, 60);
420  } else {
421  echo htmlspecialchars($notify_url);
422  }
423 
424  return TRUE;
425 
426  }//end paintNotifyUrl()
427 
428 
439  function processNotifyUrl(&$asset, &$o, $prefix)
440  {
441  if (!$asset->writeAccess('attributes')) return FALSE;
442  if ($asset->attr('button_type') == '_view_cart') return FALSE;
443  if (!isset($_POST[$prefix.'_notify_url'])) return FALSE;
444 
445  $notify_url = $_POST[$prefix.'_notify_url'];
446 
447  return $asset->setAttrValue('notify_url', $notify_url);
448 
449  }//end processNotifyUrl()
450 
451 
462  function paintReturnUrl(&$asset, &$o, $prefix)
463  {
464  if ($asset->attr('button_type') == '_view_cart') return TRUE;
465 
466  $field_name = 'Return URL';
467  $note = 'The URL of the page that the user will be returned after completing a payment.';
468 
469 
470  if ($asset->attr('button_type') == '_cart') {
471  $note .= ' You should use the same value for this field in all <b>Add to Cart</b> buttons because the last clicked button\'s return URL is used by Paypal and you will not know what it is.';
472  }
473 
474  $o->openField($field_name, '', $note);
475 
476  $return_url = $asset->attr('return_url');
477  if ($asset->writeAccess('attributes')) {
478  text_box($prefix.'_return_url', $return_url, 60);
479  } else {
480  echo htmlspecialchars($return_url);
481  }
482 
483  return TRUE;
484 
485  }//end paintReturnUrl()
486 
487 
498  function processReturnUrl(&$asset, &$o, $prefix)
499  {
500  if (!$asset->writeAccess('attributes')) return FALSE;
501  if ($asset->attr('button_type') == '_view_cart') return FALSE;
502  if (!isset($_POST[$prefix.'_return_url'])) return FALSE;
503 
504  $return_url = $_POST[$prefix.'_return_url'];
505 
506  return $asset->setAttrValue('return_url', $return_url);
507 
508  }//end processReturnUrl()
509 
510 
521  function paintCancelUrl(&$asset, &$o, $prefix)
522  {
523  if ($asset->attr('button_type') == '_view_cart') return TRUE;
524 
525  $field_name = 'Cancel URL';
526  $note = 'The URL of the page that the user will be returned if a payment is cancelled.';
527 
528 
529  if ($asset->attr('button_type') == '_cart') {
530  $note .= ' You should use the same value for this field in all <b>Add to Cart</b> buttons because the last clicked button\'s cancel URL is used by Paypal and you will not know what it is.';
531  }
532 
533  $o->openField($field_name, '', $note);
534 
535  $cancel_url = $asset->attr('cancel_return_url');
536  if ($asset->writeAccess('attributes')) {
537  text_box($prefix.'_cancel_return_url', $cancel_url, 60);
538  } else {
539  echo htmlspecialchars($cancel_url);
540  }
541 
542  return TRUE;
543 
544  }//end paintCancelUrl()
545 
546 
557  function processCancelUrl(&$asset, &$o, $prefix)
558  {
559  if (!$asset->writeAccess('attributes')) return FALSE;
560  if ($asset->attr('button_type') == '_view_cart') return FALSE;
561  if (!isset($_POST[$prefix.'_cancel_return_url'])) return FALSE;
562 
563  $cancel_url = $_POST[$prefix.'_cancel_return_url'];
564 
565  return $asset->setAttrValue('cancel_return_url', $cancel_url);
566 
567  }//end processCancelUrl()
568 
569 
580  function paintCartTargetWindow(&$asset, &$o, $prefix)
581  {
582  if (($asset->attr('button_type') != '_cart') && ($asset->attr('button_type') != '_view_cart')) return TRUE;
583 
584  $field_name = 'Paypal Shopping Cart opens in';
585  $note = 'This field specifies that the Paypal Shopping Cart will be opened in a separate browser window or opened in the same browser window that displays your website.';
586 
587  $o->openField($field_name, '', $note);
588 
589  $attr = $asset->getAttribute('cart_target_window');
590 
591  $attr->paint($prefix.'_'.$attr->id, !$asset->writeAccess('attributes'));
592 
593  return TRUE;
594 
595  }//end paintCartTargetWindow()
596 
597 
608  function processCartTargetWindow(&$asset, &$o, $prefix)
609  {
610  if (!$asset->writeAccess('attributes')) return FALSE;
611  if (($asset->attr('button_type') != '_cart') && ($asset->attr('button_type') != '_view_cart')) return FALSE;
612 
613  $attr = $asset->getAttribute('cart_target_window');
614 
615  $attr->process($prefix.'_'.$attr->id);
616 
617  return ($attr->processed && $asset->setAttrValue($attr->name, $attr->value));
618 
619  }//end processCartTargetWindow()
620 
621 
632  function paintShoppingURL(&$asset, &$o, $prefix)
633  {
634  if (($asset->attr('button_type') != '_cart') && ($asset->attr('button_type') != '_view_cart')) return TRUE;
635 
636  $field_name = 'Shopping URL';
637  $note = 'This field specifies which page PayPal returns buyers to when they click the <b>Continue Shopping</b> button.';
638 
639  $o->openField($field_name, '', $note);
640 
641  $shopping_url = $asset->attr('shopping_url');
642  if ($asset->writeAccess('attributes')) {
643  text_box($prefix.'_shopping_url', $shopping_url, 60);
644  } else {
645  echo htmlspecialchars($shopping_url);
646  }
647 
648  return TRUE;
649 
650  }//end paintShoppingURL()
651 
652 
663  function processShoppingURL(&$asset, &$o, $prefix)
664  {
665  if (!$asset->writeAccess('attributes')) return FALSE;
666  if (($asset->attr('button_type') != '_cart') && ($asset->attr('button_type') != '_view_cart')) return FALSE;
667  if (!isset($_POST[$prefix.'_shopping_url'])) return FALSE;
668 
669  $shopping_url = $_POST[$prefix.'_shopping_url'];
670 
671  return $asset->setAttrValue('shopping_url', $shopping_url);
672 
673  }//end processShoppingURL()
674 
675 
686  function paintExtraVars(&$asset, &$o, $prefix)
687  {
688  $current_vars = $asset->attr('extra_vars');
689 
690  if ($asset->writeAccess('attributes')) {
691  text_area($prefix.'_extra_vars', $current_vars, 80, 30);
692  } else {
693  if ($current_vars == '') {
694  echo '<b>[Empty]</b>';
695  } else {
696  echo '<b>'.str_replace("\n", '<br />', $current_vars).'</b>';
697  }
698  }
699 
700  return TRUE;
701 
702  }//end paintExtraVars()
703 
704 
715  function processExtraVars(&$asset, &$o, $prefix)
716  {
717  if (!$asset->writeAccess('attributes')) return FALSE;
718  if (!isset($_POST[$prefix.'_extra_vars'])) return FALSE;
719 
720  $extra_vars = $_POST[$prefix.'_extra_vars'];
721  $extra_vars = trim($extra_vars);
722  //replace Windows newline character with Unix newline character because Paypal decryption only accept the Unix format
723  $extra_vars = str_replace("\r\n", "\n", $extra_vars);
724 
725  return $asset->setAttrValue('extra_vars', $extra_vars);
726 
727  }//end processExtraVars()
728 
729 
730 }//end class
731 ?>