PageRenderTime 83ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/basket/helpers/basket.php

https://github.com/mihalyf/gallery3-contrib
PHP | 164 lines | 124 code | 22 blank | 18 comment | 2 complexity | 8ab82eab1da995c7b35fe760a4e763dd MD5 | raw file
  1. <?php
  2. /**
  3. * Gallery - a web based photo album viewer and editor
  4. * Copyright (C) 2000-2010 Bharat Mediratta
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. class basket_Core {
  21. static $currencies = array(
  22. "AUD" => "Australian Dollars",
  23. "CAD" => "Canadian Dollars",
  24. "EUR" => "Euros",
  25. "GBP" => "Pounds Sterling",
  26. "JPY" => "Yen",
  27. "USD" => "U.S. Dollars",
  28. "NZD" => "New Zealand Dollar",
  29. "CHF" => "Swiss Franc",
  30. "HKD" => "Hong Kong Dollar",
  31. "SGD" => "Singapore Dollar",
  32. "SEK" => "Swedish Krona",
  33. "DKK" => "Danish Krone",
  34. "PLN" => "Polish Zloty",
  35. "NOK" => "Norwegian Krone",
  36. "HUF" => "Hungarian Forint",
  37. "CZK" => "Czech Koruna",
  38. "ILS" => "Israeli Shekel",
  39. "MXN" => "Mexican Peso");
  40. static $format= array(
  41. "AUD" => "$",
  42. "CAD" => "$",
  43. "EUR" => "&euro;",
  44. "GBP" => "&pound;",
  45. "JPY" => "&yen;",
  46. "USD" => "$",
  47. "NZD" => "$",
  48. "CHF" => "",
  49. "HKD" => "$",
  50. "SGD" => "$",
  51. "SEK" => "",
  52. "DKK" => "",
  53. "PLN" => "",
  54. "NOK" => "",
  55. "HUF" => "",
  56. "CZK" => "",
  57. "ILS" => "",
  58. "MXN" => "");
  59. static function get_configure_form() {
  60. $form = new Forge("admin/configure", "", "post", array("id" => "g-configure-form"));
  61. $group = $form->group("configure")->label(t("Configure Basket"));
  62. $group->input("email")->label(t("Offline Paying Email Address"))->id("g-order-email-address");
  63. $group->dropdown("currency")
  64. ->label(t("Currency"))
  65. ->options(self::$currencies);
  66. $group->checkbox("paypal")->label(t("Use Paypal"))->id("g-paypal");
  67. $group->input("paypal_account")->label(t("Paypal E-Mail Address"))->id("g-paypal-address");
  68. $group->submit("")->value(t("Save"));
  69. return $form;
  70. }
  71. static function populateForm($form){
  72. $form->configure->email->value(basket::getEmailAddress());
  73. $form->configure->paypal->checked(basket::isPaypal());
  74. $form->configure->paypal_account->value(basket::getPaypalAccount());
  75. $form->configure->currency->selected(basket::getCurrency());
  76. }
  77. static function extractForm($form){
  78. $email = $form->configure->email->value;
  79. $isPaypal = $form->configure->paypal->value;
  80. $paypal_account = $form->configure->paypal_account->value;
  81. $currency = $form->configure->currency->selected;
  82. basket::setEmailAddress($email);
  83. basket::setPaypal($isPaypal);
  84. basket::setPaypalAccount($paypal_account);
  85. basket::setCurrency($currency);
  86. }
  87. static function getEmailAddress(){
  88. return module::get_var("basket","email");
  89. }
  90. static function isPaypal(){
  91. return module::get_var("basket","paypal");
  92. }
  93. static function getPaypalAccount(){
  94. return module::get_var("basket","paypal_account");
  95. }
  96. static function getCurrency(){
  97. $cur = module::get_var("basket","currency");
  98. if (!isset($cur))
  99. {
  100. $cur = "USD";
  101. }
  102. return $cur;
  103. }
  104. static function formatMoney($money){
  105. return self::$format[self::getCurrency()].number_format($money,2);
  106. }
  107. static function setEmailAddress($email){
  108. module::set_var("basket","email",$email);
  109. }
  110. static function setPaypal($paypal){
  111. module::set_var("basket","paypal",$paypal);
  112. }
  113. static function setPaypalAccount($paypal_account){
  114. module::set_var("basket","paypal_account",$paypal_account);
  115. }
  116. static function setCurrency($currency){
  117. module::set_var("basket","currency",$currency);
  118. }
  119. static function generatePaypalForm($session_basket){
  120. $form = "
  121. <form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\" name=\"paypal_form\">
  122. <input type=\"hidden\" name=\"cmd\" value=\"_cart\"/>
  123. <input type=\"hidden\" name=\"upload\" value=\"1\"/>
  124. <input type=\"hidden\" name=\"currency_code\" value=\"".self::getCurrency()."\">
  125. <input type=\"hidden\" name=\"business\" value=\"".self::getPaypalAccount()."\"/>";
  126. $postage = $session_basket->postage_cost();
  127. if ($postage > 0) {
  128. $form = $form."
  129. <input type=\"hidden\" name=\"shipping_1\" value=\"".$postage."\">";
  130. }
  131. $id = 1;
  132. foreach ($session_basket->contents as $key => $basket_item){
  133. $form = $form."
  134. <input type=\"hidden\" name=\"item_name_$id\" value=\"".$basket_item->getCode()."\"/>
  135. <input type=\"hidden\" name=\"amount_$id\" value=\"$basket_item->cost_per\"/>
  136. <input type=\"hidden\" name=\"quantity_$id\" value=\"$basket_item->quantity\"/>";
  137. $id++;
  138. }
  139. $form = $form."</form>";
  140. return $form;
  141. }
  142. }