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