ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPurchasePaypal.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
31 include_once './payment/classes/class.ilPaymentObject.php';
32 include_once './payment/classes/class.ilPaymentShoppingCart.php';
33 include_once './payment/classes/class.ilPaypalSettings.php';
34 include_once './payment/classes/class.ilPaymentCoupons.php';
35 include_once 'Services/Payment/classes/class.ilShopVatsList.php';
36 
37 define('SUCCESS', 0);
38 define('ERROR_OPENSOCKET', 1);
39 define('ERROR_WRONG_CUSTOMER', 2);
40 define('ERROR_NOT_COMPLETED', 3);
41 define('ERROR_PREV_TRANS_ID', 4);
42 define('ERROR_WRONG_VENDOR', 5);
43 define('ERROR_WRONG_ITEMS', 6);
44 define('ERROR_FAIL', 7);
45 
47 {
48  /*
49  * id of vendor, admin or trustee
50  */
51  var $psc_obj = null;
52  var $user_obj = null;
53  var $db = null;
54 
56 
57  private $totalVat = 0;
58 
60  {
61  global $ilDB, $lng;
62 
63  $this->user_obj =& $user_obj;
64  $this->db =& $ilDB;
65  $this->lng =& $lng;
66 
67  $this->coupon_obj = new ilPaymentCoupons($this->user_obj);
68 
69  $this->__initShoppingCartObject();
70 
72  $this->paypalConfig = $ppSet->getAll();
73 
74  $this->lng->loadLanguageModule("payment");
75 
76  if (!is_array($_SESSION["coupons"]["paypal"]))
77  {
78  $_SESSION["coupons"]["paypal"] = array();
79  }
80  }
81 
82  function openSocket()
83  {
84  // post back to PayPal system to validate
85  $fp = @fsockopen ($path = $this->paypalConfig["server_host"], 80, $errno, $errstr, 30);
86  return $fp;
87  }
88 
89  function checkData($fp)
90  {
91  global $ilUser;
92 
93  // read the post from PayPal system and add 'cmd'
94  $req = 'cmd=_notify-synch';
95 
96  $tx_token = $_REQUEST['tx'];
97 
98  $auth_token = $this->paypalConfig["auth_token"];
99 
100  $req .= "&tx=$tx_token&at=$auth_token";
101  $header .= "POST " . $this->paypalConfig["server_path"] . " HTTP/1.0\r\n";
102  $header .= "Host:".$this->paypalConfig["server_host"]."\r\n";
103  $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
104  $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
105 
106  fputs ($fp, $header . $req);
107  // read the body data
108  $res = '';
109  $headerdone = false;
110  while (!feof($fp))
111  {
112  $line = fgets ($fp, 1024);
113  if (strcmp($line, "\r\n") == 0)
114  {
115  // read the header
116  $headerdone = true;
117  }
118  else if ($headerdone)
119  {
120  // header has been read. now read the contents
121  $res .= $line;
122  }
123  }
124 
125  // parse the data
126  $lines = explode("\n", $res);
127  $keyarray = array();
128  if (strcmp ($lines[0], "SUCCESS") == 0)
129  {
130  for ($i=1; $i<count($lines);$i++)
131  {
132  list($key,$val) = explode("=", $lines[$i]);
133  $keyarray[urldecode($key)] = urldecode($val);
134  }
135 // check customer
136  if ($ilUser->getId() != $keyarray["custom"])
137  {
138 #echo "Wrong customer";
139  return ERROR_WRONG_CUSTOMER;
140  }
141 
142 // check the payment_status is Completed
143  if (!in_array($keyarray["payment_status"], array("Completed", "In-Progress", "Pending", "Processed")))
144  {
145 #echo "Not completed";
146  return ERROR_NOT_COMPLETED;
147  }
148 
149 // check that txn_id has not been previously processed
150  if ($this->__checkTransactionId($keyarray["txn_id"]))
151  {
152 #echo "Prev. processed trans. id";
153  return ERROR_PREV_TRANS_ID;
154  }
155 
156 // check that receiver_email is your Primary PayPal email
157  if ($keyarray["receiver_email"] != $this->paypalConfig["vendor"])
158  {
159 #echo "Wrong vendor";
160  return ERROR_WRONG_VENDOR;
161  }
162 
163 // check that payment_amount/payment_currency are correct
164  if (!$this->__checkItems($keyarray))
165  {
166 #echo "Wrong items";
167  return ERROR_WRONG_ITEMS;
168  }
169 
170  $bookings = $this->__saveTransaction($keyarray["txn_id"]);
171  $this->__sendBill($bookings, $keyarray);
172  $_SESSION["coupons"]["paypal"] = array();
173 
174  return SUCCESS;
175  }
176  else if (strcmp ($lines[0], "FAIL") == 0)
177  {
178  return ERROR_FAIL;
179  }
180  else
181  return ERROR_FAIL;
182  }
183 
184  function __checkTransactionId($a_id)
185  {
186  global $ilDB;
187 
188  $res = $this->db->query('SELECT * FROM payment_statistic WHERE transaction_extern = '.$ilDB->quote($a_id, 'integer'));
189 
190  return $res->numRows() ? true : false;
191  }
192 
193  function __checkItems($a_array)
194  {
195  $genSet = new ilGeneralSettings();
196 
197  include_once './payment/classes/class.ilPayMethods.php';
198 
199 // Wrong currency
200  if ($a_array["mc_currency"] != $genSet->get("currency_unit"))
201  {
202  return false;
203  }
204 
205  $sc = $this->psc_obj->getShoppingCart(PAY_METHOD_PAYPAL);
206  $this->psc_obj->clearCouponItemsSession();
207 
208  if (is_array($sc) &&
209  count($sc) > 0)
210  {
211  for ($i = 0; $i < count($sc); $i++)
212  {
213  $items[$i] = array(
214  "name" => $a_array["item_name".($i+1)],
215  "amount" => $a_array["mc_gross_".($i+1)]
216  );
217 
218  if (!empty($_SESSION["coupons"]["paypal"]))
219  {
220  $sc[$i]["math_price"] = (float) $sc[$i]["betrag"];
221 
222  $tmp_pobject =& new ilPaymentObject($this->user_obj, $sc[$i]['pobject_id']);
223 
224  foreach ($_SESSION["coupons"]["paypal"] as $key => $coupon)
225  {
226  $this->coupon_obj->setId($coupon["pc_pk"]);
227  $this->coupon_obj->setCurrentCoupon($coupon);
228 
229  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
230  {
231  $_SESSION["coupons"]["paypal"][$key]["total_objects_coupon_price"] += (float) $sc[$i]["betrag"];
232  $_SESSION["coupons"]["paypal"][$key]["items"][] = $sc[$i];
233  }
234  }
235 
236  unset($tmp_pobject);
237  }
238  }
239 
240  $coupon_discount_items = $this->psc_obj->calcDiscountPrices($_SESSION["coupons"]["paypal"]);
241 
242  $found = 0;
243  $total = 0;
244  for ($i = 0; $i < count($sc); $i++)
245  {
246  if (array_key_exists($sc[$i]["pobject_id"], $coupon_discount_items))
247  {
248  $sc[$i]["betrag"] = round($coupon_discount_items[$sc[$i]["pobject_id"]]["discount_price"], 2);
249  if ($sc[$i]["betrag"] < 0) $sc[$i]["betrag"] = 0.0;
250  }
251 
252  for ($j = 0; $j < count($items); $j++)
253  {
254  if (substr($items[$j]["name"], 0, strlen($sc[$i]["obj_id"])+2) == "[".$sc[$i]["obj_id"]."]" &&
255  $items[$j]["amount"] == $sc[$i]["betrag"])
256  {
257  $total += $items[$j]["amount"];
258  $found++;
259  }
260  }
261  }
262 
263 // The number of items, the items themselves and their amounts and the total amount correct
264  if (number_format($total, 2, ".", "") == $a_array["mc_gross"] &&
265  $found == count($sc))
266  {
267  return true;
268  }
269  }
270 
271  return false;
272  }
273 
274  function __saveTransaction($a_id)
275  {
276  global $ilias, $ilUser, $ilObjDataCache;
277 
278  $sc = $this->psc_obj->getShoppingCart(PAY_METHOD_PAYPAL);
279  $this->psc_obj->clearCouponItemsSession();
280 
281  if (is_array($sc) &&
282  count($sc) > 0)
283  {
284  include_once './payment/classes/class.ilPaymentBookings.php';
285  $book_obj =& new ilPaymentBookings($this->usr_obj);
286 
287  for ($i = 0; $i < count($sc); $i++)
288  {
289  if (!empty($_SESSION["coupons"]["paypal"]))
290  {
291  $sc[$i]["math_price"] = (float) $sc[$i]["betrag"];
292 
293  $tmp_pobject =& new ilPaymentObject($this->user_obj, $sc[$i]['pobject_id']);
294 
295  foreach ($_SESSION["coupons"]["paypal"] as $key => $coupon)
296  {
297  $this->coupon_obj->setId($coupon["pc_pk"]);
298  $this->coupon_obj->setCurrentCoupon($coupon);
299 
300  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
301  {
302  $_SESSION["coupons"]["paypal"][$key]["total_objects_coupon_price"] += (float) $sc[$i]["betrag"];
303  $_SESSION["coupons"]["paypal"][$key]["items"][] = $sc[$i];
304  }
305  }
306 
307  unset($tmp_pobject);
308  }
309  }
310 
311  $coupon_discount_items = $this->psc_obj->calcDiscountPrices($_SESSION["coupons"]["paypal"]);
312 
313  for ($i = 0; $i < count($sc); $i++)
314  {
315  $pobjectData = ilPaymentObject::_getObjectData($sc[$i]["pobject_id"]);
316  $pobject =& new ilPaymentObject($this->user_obj,$sc[$i]['pobject_id']);
317 
318  $inst_id_time = $ilias->getSetting('inst_id').'_'.$ilUser->getId().'_'.substr((string) time(),-3);
319 
320  $price = $sc[$i]["betrag"];
321  $bonus = 0.0;
322 
323  if (array_key_exists($sc[$i]["pobject_id"], $coupon_discount_items))
324  {
325  $bonus = $coupon_discount_items[$sc[$i]["pobject_id"]]["math_price"] - $coupon_discount_items[$sc[$i]["pobject_id"]]["discount_price"];
326  }
327  $inst_id_time = $ilias->getSetting('inst_id').'_'.$ilUser->getId().'_'.substr((string) time(),-3);
328  $transaction = $inst_id_time.substr(md5(uniqid(rand(), true)), 0, 4);
329 
330  $book_obj->setTransaction($inst_id_time.substr(md5(uniqid(rand(), true)), 0, 4));
331  $book_obj->setPobjectId($sc[$i]["pobject_id"]);
332  $book_obj->setCustomerId($ilUser->getId());
333  $book_obj->setVendorId($pobjectData["vendor_id"]);
334  $book_obj->setPayMethod($pobjectData["pay_method"]);
335  $book_obj->setOrderDate(time());
336  $book_obj->setDuration($sc[$i]["dauer"]);
337  $book_obj->setPrice($sc[$i]["betrag_string"]);
338  $book_obj->setDiscount($bonus > 0 ? ilPaymentPrices::_getPriceStringFromAmount($bonus * (-1)) : 0);
339  $book_obj->setPayed(1);
340  $book_obj->setAccess(1);
341  $book_obj->setVoucher('');
342  $book_obj->setTransactionExtern($a_id);
343 
344  $book_obj->setObjectTitle($sc[$i]['buchungstext']);
345  $book_obj->setVatRate($sc[$i]['vat_rate']);
346  $book_obj->setVatUnit($sc[$i]['vat_unit']);
347 
348  include_once './payment/classes/class.ilPayMethods.php';
349  $save_user_adr_bill = (int) ilPayMethods::_enabled('save_user_adr_paypal') ? 1 : 0;
350 
351  if($save_user_adr_bill == '1')
352  {
353  $book_obj->setStreet($_SESSION['paypal']['personal_data']['street'], $_SESSION['bill']['personal_data']['house_number']);
354  $book_obj->setPoBox($_SESSION['paypal']['personal_data']['po_box']);
355  $book_obj->setZipcode($_SESSION['paypal']['personal_data']['zipcode']);
356  $book_obj->setCity($_SESSION['paypal']['personal_data']['city']);
357  $book_obj->setCountry($_SESSION['paypal']['personal_data']['country']);
358  }
359 
360  $booking_id = $book_obj->add();
361 
362  if (!empty($_SESSION["coupons"]["paypal"]) && $booking_id)
363  {
364  foreach ($_SESSION["coupons"]["paypal"] as $coupon)
365  {
366  $this->coupon_obj->setId($coupon["pc_pk"]);
367  $this->coupon_obj->setCurrentCoupon($coupon);
368 
369  if ($this->coupon_obj->isObjectAssignedToCoupon($pobject->getRefId()))
370  {
371  $this->coupon_obj->addCouponForBookingId($booking_id);
372  }
373  }
374  }
375 
376  unset($booking_id);
377  unset($pobject);
378 
379  $obj_id = $ilObjDataCache->lookupObjId($pobjectData["ref_id"]);
380  $obj_type = $ilObjDataCache->lookupType($obj_id);
381  $obj_title = $ilObjDataCache->lookupTitle($obj_id);
382 
383  $bookings["list"][] = array(
384  "type" => $obj_type,
385  "title" => "[".$obj_id."]: " . $obj_title,
386  "duration" => $sc[$i]["dauer"],
387  "vat_rate" => $sc[$i]["vat_rate"],
388  "vat_unit" => $sc[$i]["vat_unit"],
389  "price" => $sc[$i]["betrag_string"],
390  "betrag" => $sc[$i]["betrag"]
391  );
392 
393  $total += $sc[$i]["betrag"];
394  $total_vat += $sc[$i]['vat_unit'];
395 
396  if ($sc[$i]["psc_id"]) $this->psc_obj->delete($sc[$i]["psc_id"]);
397  }
398 
399  if (!empty($_SESSION["coupons"]["paypal"]))
400  {
401  foreach ($_SESSION["coupons"]["paypal"] as $coupon)
402  {
403  $this->coupon_obj->setId($coupon["pc_pk"]);
404  $this->coupon_obj->setCurrentCoupon($coupon);
405  $this->coupon_obj->addTracking();
406  }
407  }
408  }
409 
410  $bookings["total"] = $total;
411  $bookings['total_vat'] = $total_vat;
412 
413  return $bookings;
414  }
415 
416  function __sendBill($bookings, $a_array)
417  {
418  global $ilUser, $ilias;
419 
420  $transaction = $a_array["txn_id"];
421 
422  include_once './classes/class.ilTemplate.php';
423  include_once './Services/Utilities/classes/class.ilUtil.php';
424  include_once './payment/classes/class.ilGeneralSettings.php';
425  include_once './payment/classes/class.ilPaymentShoppingCart.php';
426  include_once 'Services/Mail/classes/class.ilMimeMail.php';
427 
428  $genSet = new ilGeneralSettings();
429 
430  $tpl = new ilTemplate("./payment/templates/default/tpl.pay_paypal_bill.html", true, true, true);
431 
432  $tpl->setVariable("VENDOR_ADDRESS", nl2br(utf8_decode($genSet->get("address"))));
433  $tpl->setVariable("VENDOR_ADD_INFO", nl2br(utf8_decode($genSet->get("add_info"))));
434  $tpl->setVariable("VENDOR_BANK_DATA", nl2br(utf8_decode($genSet->get("bank_data"))));
435  $tpl->setVariable("TXT_BANK_DATA", utf8_decode($this->lng->txt("pay_bank_data")));
436 
437  $tpl->setVariable("CUSTOMER_FIRSTNAME", $a_array["first_name"]);
438  $tpl->setVariable("CUSTOMER_LASTNAME", $a_array["last_name"]);
439  $tpl->setVariable("CUSTOMER_STREET", $a_array["address_street"]);
440  $tpl->setVariable("CUSTOMER_ZIPCODE", $a_array["address_zip"]);
441  $tpl->setVariable("CUSTOMER_CITY", $a_array["address_city"]);
442  $tpl->setVariable("CUSTOMER_COUNTRY", $a_array["address_country"]);
443 
444  $tpl->setVariable("BILL_NO", $transaction);
445  $tpl->setVariable("DATE", date("d.m.Y"));
446 
447  $tpl->setVariable("TXT_BILL", utf8_decode($this->lng->txt("pays_bill")));
448  $tpl->setVariable("TXT_BILL_NO", utf8_decode($this->lng->txt("pay_bill_no")));
449  $tpl->setVariable("TXT_DATE", utf8_decode($this->lng->txt("date")));
450 
451  $tpl->setVariable("TXT_ARTICLE", utf8_decode($this->lng->txt("pay_article")));
452  $tpl->setVariable('TXT_VAT_RATE', utf8_decode($this->lng->txt('vat_rate')));
453  $tpl->setVariable('TXT_VAT_UNIT', utf8_decode($this->lng->txt('vat_unit')));
454  $tpl->setVariable("TXT_PRICE", utf8_decode($this->lng->txt("price_a")));
455 
456  for ($i = 0; $i < count($bookings["list"]); $i++)
457  {
458  $tmp_pobject =& new ilPaymentObject($this->user_obj, $bookings["list"][$i]['pobject_id']);
459 
460  $assigned_coupons = '';
461  if (!empty($_SESSION["coupons"]["paypal"]))
462  {
463  foreach ($_SESSION["coupons"]["paypal"] as $key => $coupon)
464  {
465  $this->coupon_obj->setId($coupon["pc_pk"]);
466  $this->coupon_obj->setCurrentCoupon($coupon);
467 
468  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
469  {
470  $assigned_coupons .= '<br />' . $this->lng->txt('paya_coupons_coupon') . ': ' . $coupon["pcc_code"];
471  }
472  }
473  }
474 
475  $tpl->setCurrentBlock("loop");
476  $tpl->setVariable("LOOP_OBJ_TYPE", utf8_decode($this->lng->txt($bookings["list"][$i]["type"])));
477  $tpl->setVariable("LOOP_TITLE", utf8_decode($bookings["list"][$i]["title"]) . $assigned_coupons);
478  $tpl->setVariable("LOOP_TXT_ENTITLED_RETRIEVE", utf8_decode($this->lng->txt("pay_entitled_retrieve")));
479  $tpl->setVariable("LOOP_DURATION", $bookings["list"][$i]["duration"] . " " . utf8_decode($this->lng->txt("paya_months")));
480  $tpl->setVariable("LOOP_VAT_RATE", ilShopUtils::_formatVAT($bookings["list"][$i]["vat_rate"]));
481  $tpl->setVariable('LOOP_VAT_UNIT', ilShopUtils::_formatFloat($bookings['list'][$i]['vat_unit']).' '.$genSet->get('currency_unit'));
482  $tpl->setVariable("LOOP_PRICE", $bookings["list"][$i]["price"]);
483  $tpl->parseCurrentBlock("loop");
484 
485  unset($tmp_pobject);
486  }
487 
488  if (!empty($_SESSION["coupons"]["paypal"]))
489  {
490  if (count($items = $bookings["list"]))
491  {
492  $sub_total_amount = $bookings["total"];
493 
494  foreach ($_SESSION["coupons"]["paypal"] as $coupon)
495  {
496  $this->coupon_obj->setId($coupon["pc_pk"]);
497  $this->coupon_obj->setCurrentCoupon($coupon);
498 
499  $total_object_price = 0.0;
500  $current_coupon_bonus = 0.0;
501 
502  foreach ($bookings["list"] as $item)
503  {
504  $tmp_pobject =& new ilPaymentObject($this->user_obj, $item['pobject_id']);
505 
506  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
507  {
508  $total_object_price += $item["betrag"];
509  }
510 
511  unset($tmp_pobject);
512  }
513 
514  $current_coupon_bonus = $this->coupon_obj->getCouponBonus($total_object_price);
515 
516  $bookings["total"] += $current_coupon_bonus * (-1);
517 
518  $tpl->setCurrentBlock("cloop");
519  $tpl->setVariable("TXT_COUPON", utf8_decode($this->lng->txt("paya_coupons_coupon") . " " . $coupon["pcc_code"]));
520  $tpl->setVariable("BONUS", number_format($current_coupon_bonus * (-1), 2, ',', '.') . " " . $genSet->get("currency_unit"));
521  $tpl->parseCurrentBlock();
522  }
523 
524  $tpl->setVariable("TXT_SUBTOTAL_AMOUNT", utf8_decode($this->lng->txt("pay_bmf_subtotal_amount")));
525  $tpl->setVariable("SUBTOTAL_AMOUNT", number_format($sub_total_amount, 2, ",", ".") . " " . $genSet->get("currency_unit"));
526  }
527  }
528 
529  if ($bookings["total"] < 0)
530  {
531  $bookings["total"] = 0.0;
532  $bookings["total_vat"] = 0.0;
533  }
534 
535  $tpl->setVariable("TXT_TOTAL_AMOUNT", utf8_decode($this->lng->txt("pay_bmf_total_amount")));
536  $tpl->setVariable("TOTAL_AMOUNT", number_format($bookings["total"], 2, ",", ".") . " " . $genSet->get("currency_unit"));
537  if ($bookings["total_vat"] > 0)
538  {
539  $tpl->setVariable("TOTAL_VAT", ilShopUtils::_formatFloat($bookings["total_vat"]). " " . $genSet->get("currency_unit"));
540  $tpl->setVariable("TXT_TOTAL_VAT", utf8_decode($this->lng->txt("pay_bmf_vat_included")));
541  }
542 
543  $tpl->setVariable("TXT_PAYMENT_TYPE", utf8_decode($this->lng->txt("pay_payed_paypal")));
544 
545  if (!@file_exists($genSet->get("pdf_path")))
546  {
547  ilUtil::makeDir($genSet->get("pdf_path"));
548  }
549 
550  if (@file_exists($genSet->get("pdf_path")))
551  {
552  ilUtil::html2pdf($tpl->get(), $genSet->get("pdf_path") . "/" . $transaction . ".pdf");
553  }
554 
555  if (@file_exists($genSet->get("pdf_path") . "/" . $transaction . ".pdf") &&
556  $ilUser->getEmail() != "" &&
557  $ilias->getSetting("admin_email") != "")
558  {
559  $m= new ilMimeMail; // create the mail
560  $m->From( $ilias->getSetting("admin_email") );
561  $m->To( $ilUser->getEmail() );
562  $m->Subject( $this->lng->txt("pay_message_subject") );
563  $message = $this->lng->txt("pay_message_hello") . " " . $ilUser->getFirstname() . " " . $ilUser->getLastname() . ",\n\n";
564  $message .= $this->lng->txt("pay_message_thanks") . "\n\n";
565  $message .= $this->lng->txt("pay_message_attachment") . "\n\n";
566  $message .= $this->lng->txt("pay_message_regards") . "\n\n";
567  $message .= strip_tags($genSet->get("address"));
568  $m->Body( $message ); // set the body
569  $m->Attach( $genSet->get("pdf_path") . "/" . $transaction . ".pdf", "application/pdf" ) ; // attach a file of type image/gif
570  $m->Send(); // send the mail
571  }
572 
573  @unlink($genSet->get("pdf_path") . "/" . $transaction . ".html");
574  @unlink($genSet->get("pdf_path") . "/" . $transaction . ".pdf");
575 
576  }
577 
579  {
580  $this->psc_obj =& new ilPaymentShoppingCart($this->user_obj);
581  }
582 
583  function __getCountries()
584  {
585  global $lng;
586 
587  $lng->loadLanguageModule("meta");
588 
589  $cntcodes = array ("DE","ES","FR","GB","AT","CH","AF","AL","DZ","AS","AD","AO",
590  "AI","AQ","AG","AR","AM","AW","AU","AT","AZ","BS","BH","BD","BB","BY",
591  "BE","BZ","BJ","BM","BT","BO","BA","BW","BV","BR","IO","BN","BG","BF",
592  "BI","KH","CM","CA","CV","KY","CF","TD","CL","CN","CX","CC","CO","KM",
593  "CG","CK","CR","CI","HR","CU","CY","CZ","DK","DJ","DM","DO","TP","EC",
594  "EG","SV","GQ","ER","EE","ET","FK","FO","FJ","FI","FR","FX","GF","PF",
595  "TF","GA","GM","GE","DE","GH","GI","GR","GL","GD","GP","GU","GT","GN",
596  "GW","GY","HT","HM","HN","HU","IS","IN","ID","IR","IQ","IE","IL","IT",
597  "JM","JP","JO","KZ","KE","KI","KP","KR","KW","KG","LA","LV","LB","LS",
598  "LR","LY","LI","LT","LU","MO","MK","MG","MW","MY","MV","ML","MT","MH",
599  "MQ","MR","MU","YT","MX","FM","MD","MC","MN","MS","MA","MZ","MM","NA",
600  "NR","NP","NL","AN","NC","NZ","NI","NE","NG","NU","NF","MP","NO","OM",
601  "PK","PW","PA","PG","PY","PE","PH","PN","PL","PT","PR","QA","RE","RO",
602  "RU","RW","KN","LC","VC","WS","SM","ST","SA","CH","SN","SC","SL","SG",
603  "SK","SI","SB","SO","ZA","GS","ES","LK","SH","PM","SD","SR","SJ","SZ",
604  "SE","SY","TW","TJ","TZ","TH","TG","TK","TO","TT","TN","TR","TM","TC",
605  "TV","UG","UA","AE","GB","UY","US","UM","UZ","VU","VA","VE","VN","VG",
606  "VI","WF","EH","YE","ZR","ZM","ZW");
607  $cntrs = array();
608  foreach($cntcodes as $cntcode)
609  {
610  $cntrs[$cntcode] = $lng->txt("meta_c_".$cntcode);
611  }
612  asort($cntrs);
613  return $cntrs;
614  }
615 
616  function __getCountryCode($value = "")
617  {
618  $countries = $this->__getCountries();
619  foreach($countries as $code => $text)
620  {
621  if ($text == $value)
622  {
623  return $code;
624  }
625  }
626  return;
627  }
628 
629  function __getCountryName($value = "")
630  {
631  $countries = $this->__getCountries();
632  return $countries[$value];
633  }
634 
635 }
636 ?>