ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPurchaseBaseGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 include_once './Services/Payment/classes/class.ilPaymentShoppingCart.php';
14 include_once './Services/Payment/classes/class.ilShopShoppingCartGUI.php';
15 include_once './Services/Payment/classes/class.ilPaymentCoupons.php';
16 include_once './Services/Payment/classes/class.ilShopVatsList.php';
17 include_once './Services/Payment/classes/class.ilPayMethods.php';
18 
20 {
21  public $ctrl;
22  public $tpl;
23 
24  public $psc_obj = null;
25  public $user_obj = null;
26 
27  public $coupon_obj = null;
28  public $error;
29 
30  public $pmethod_obj = null;
31  private $pm_id = 0;
32  private $totalVat = 0;
33  private $session_var = null;
34 
36  {
37  global $ilias, $lng, $tpl, $rbacsystem, $ilCtrl, $ilTabs;
38 
39  $this->ilias = $ilias;
40  $this->lng = $lng;
41  $this->ctrl = $ilCtrl;
42  $this->tpl = $tpl;
43  $this->user_obj = $user_obj;
44 
45  $this->pmethod_obj = new ilPayMethods($pay_method);
46  $this->session_var = $this->pmethod_obj->getPmTitle();
47 
48  $this->pm_id = $pay_method;
49 
50  $this->psc_obj = new ilPaymentShoppingCart($this->user_obj);
51 
52  $this->coupon_obj = new ilPaymentCoupons($this->user_obj);
53 
54  if (!is_array($_SESSION[$this->session_var]['personal_data']))
55  {
56  $_SESSION[$this->session_var]['personal_data']['firstname'] = $this->user_obj->getFirstname();
57  $_SESSION[$this->session_var]['personal_data']['lastname'] = $this->user_obj->getLastname();
58  if (strpos('_' . $this->user_obj->getStreet(), ' ') > 0)
59  {
60  $houseNo = substr($this->user_obj->getStreet(), strrpos($this->user_obj->getStreet(), ' ')+1);
61  $street = substr($this->user_obj->getStreet(), 0, strlen($this->user_obj->getStreet())-(strlen($houseNo)+1));
62  $_SESSION[$this->session_var]['personal_data']['street'] = $street;
63  $_SESSION[$this->session_var]['personal_data']['house_number'] = $houseNo;
64  }
65  else
66  {
67  $_SESSION[$this->session_var]['personal_data']['street'] = $this->user_obj->getStreet();
68  $_SESSION[$this->session_var]['personal_data']['house_number'] = '';
69  }
70  $_SESSION[$this->session_var]['personal_data']['po_box'] = '';
71  $_SESSION[$this->session_var]['personal_data']['zipcode'] = $this->user_obj->getZipcode();
72  $_SESSION[$this->session_var]['personal_data']['city'] = $this->user_obj->getCity();
73  $_SESSION[$this->session_var]['personal_data']['country'] = $this->__getCountryCode($this->user_obj->getCountry());
74  $_SESSION[$this->session_var]['personal_data']['email'] = $this->user_obj->getEmail();
75  $_SESSION[$this->session_var]['personal_data']['language'] = $this->user_obj->getLanguage();
76  }
77 
78  if (!is_array($_SESSION['coupons'][$this->session_var]))
79  {
80  $_SESSION['coupons'][$this->session_var] = array();
81  }
82 
83  $this->__loadTemplate();
84  $this->error = '';
85  $this->lng->loadLanguageModule('payment');
86 
87  $ilTabs->clearTargets();
88  $ilTabs->clearSubTabs();
89  }
90 
91  public function cancel()
92  {
93  ilUtil::redirect('./payment.php');
94  }
95 
96  public function showPersonalData()
97  {
98  $this->psc_obj = new ilPaymentShoppingCart($this->user_obj);
99 
100  if(!count($items = $this->psc_obj->getEntries($this->pm_id)))
101  {
102  $this->tpl->setVariable('HEADER',$this->lng->txt('pay_bmf_your_order'));
103  $this->tpl->touchBlock('stop_floating');
104  ilUtil::sendInfo($this->lng->txt('pay_shopping_cart_empty'));
105  }
106  else
107  {
108  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
109 
110  $oForm = new ilPropertyFormGUI();
111  $oForm->setFormAction($this->ctrl->getFormAction($this, 'getPersonalData'));
112  $oForm->setTitle($this->lng->txt('pay_bmf_personal_data'));
113 
114  $oFirstname = new ilNonEditableValueGUI($this->lng->txt('firstname'));
115  $oFirstname->setValue($this->user_obj->getFirstname());
116  $oForm->addItem($oFirstname);
117 
118  $oLastname = new ilNonEditableValueGUI($this->lng->txt('lastname'));
119  $oLastname->setValue($this->user_obj->getLastname());
120  $oForm->addItem($oLastname);
121 
122  $oStreet = new ilTextInputGUI($this->lng->txt('street'),'street');
123  $oStreet->setValue($this->error != '' && isset($_POST['street'])
124  ? ilUtil::prepareFormOutput($_POST['street'],true)
125  : ilUtil::prepareFormOutput($_SESSION[$this->session_var]['personal_data']['street'],true));
126  $oForm->addItem($oStreet);
127 
128  $oHouseNumber = new ilTextInputGUI($this->lng->txt('pay_bmf_house_number'), 'house_number');
129  $oHouseNumber->setValue($this->error != '' && isset($_POST['house_number'])
130  ? ilUtil::prepareFormOutput($_POST['house_number'],true)
131  : ilUtil::prepareFormOutput($_SESSION[$this->session_var]['personal_data']['house_number'],true));
132  $oForm->addItem($oHouseNumber);
133 
134  $oPoBox = new ilTextInputGUI($this->lng->txt('pay_bmf_or').' '.$this->lng->txt('pay_bmf_po_box'), 'po_box');
135  $oPoBox->setValue($this->error != '' && isset($_POST['po_box'])
136  ? ilUtil::prepareFormOutput($_POST['po_box'],true)
137  : ilUtil::prepareFormOutput($_SESSION[$this->session_var]['personal_data']['po_box'],true));
138  $oForm->addItem($oPoBox);
139 
140  $oZipCode = new ilTextInputGUI($this->lng->txt('zipcode'), 'zipcode');
141  $oZipCode->setValue($this->error != '' && isset($_POST['zipcode'])
142  ? ilUtil::prepareFormOutput($_POST['zipcode'],true)
143  : ilUtil::prepareFormOutput($_SESSION[$this->session_var]['personal_data']['zipcode'],true));
144  $oForm->addItem($oZipCode);
145 
146  $oCity = new ilTextInputGUI($this->lng->txt('city'), 'city');
147  $oCity->setValue($this->error != '' && isset($_POST['city'])
148  ? ilUtil::prepareFormOutput($_POST['city'],true)
149  : ilUtil::prepareFormOutput($_SESSION[$this->session_var]['personal_data']['city'],true));
150  $oForm->addItem($oCity);
151 
152  $oCountry = new ilSelectInputGUI($this->lng->txt('country'), 'country');
153  $oCountry->setOptions($this->__getCountries());
154  $oCountry->setValue($this->error != '' && isset($_POST['country']) ? $_POST['country']
155  : $_SESSION[$this->session_var]['personal_data']['country']);
156  $oForm->addItem($oCountry);
157 
158  $oEmail = new ilNonEditableValueGUI($this->lng->txt('email'));
159  $oEmail->setValue($this->user_obj->getEmail());
160  $oForm->addItem($oEmail);
161 
162  $oForm->addcommandButton('getPersonalData',ucfirst($this->lng->txt('next')));
163 
164  $this->tpl->setVariable('FORM', $oForm->getHTML());
165  }
166  }
167 
168  public function getPersonalData()
169  {
170 
171  if ($_SESSION[$this->session_var]['personal_data']['firstname'] == '' ||
172  $_SESSION[$this->session_var]['personal_data']['lastname'] == '' ||
173  $_POST['zipcode'] == '' ||
174  $_POST['city'] == '' ||
175  $_POST['country'] == '' ||
176  $_SESSION[$this->session_var]['personal_data']['email'] == '')
177  {
178 
179  $this->error = $this->lng->txt('pay_bmf_personal_data_not_valid');
180  ilUtil::sendInfo($this->error);
181  $this->showPersonalData();
182  return;
183  }
184 
185  if (($_POST['street'] == '' && $_POST['house_number'] == '' && $_POST['po_box'] == '') ||
186  (($_POST['street'] != '' || $_POST['house_number'] != '') && $_POST['po_box'] != '') ||
187  ($_POST['street'] != '' && $_POST['house_number'] == '') ||
188  ($_POST['street'] == '' && $_POST['house_number'] != ''))
189  {
190  $this->error = $this->lng->txt('pay_bmf_street_or_pobox');
191  ilUtil::sendInfo($this->error);
192  $this->showPersonalData();
193  return;
194  }
195 
196  $_SESSION[$this->session_var]['personal_data']['firstname'] = $this->user_obj->getFirstname();
197  $_SESSION[$this->session_var]['personal_data']['lastname'] = $this->user_obj->getLastname();
198  $_SESSION[$this->session_var]['personal_data']['street'] = $_POST['street'];
199  $_SESSION[$this->session_var]['personal_data']['house_number'] = $_POST['house_number'];
200  $_SESSION[$this->session_var]['personal_data']['po_box'] = $_POST['po_box'];
201  $_SESSION[$this->session_var]['personal_data']['zipcode'] = $_POST['zipcode'];
202  $_SESSION[$this->session_var]['personal_data']['city'] = $_POST['city'];
203  $_SESSION[$this->session_var]['personal_data']['country'] = $_POST['country'];
204 
205  $_SESSION[$this->session_var]['personal_data']['email'] = $this->user_obj->getEmail();
206  $_SESSION[$this->session_var]['personal_data']['language'] = $this->user_obj->getLanguage();
207 
208  $this->error = '';
209  $this->showBillConfirm();
210 
211  }
212 
213  public function showBillConfirm()
214  {
215  $this->psc_obj = new ilPaymentShoppingCart($this->user_obj);
216 
217  if(!count($items = $this->psc_obj->getEntries($this->pm_id)))
218  {
219  $this->tpl->setVariable('HEADER',$this->lng->txt('pay_bmf_your_order'));
220  $this->tpl->touchBlock('stop_floating');
221  ilUtil::sendInfo($this->lng->txt('pay_shopping_cart_empty'));
222  }
223  else
224  {
225  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.pay_bill_confirm.html','Services/Payment');
226 
227  $this->__showShoppingCart();
228 
229  $this->tpl->setVariable('BILL_CONFIRM_FORMACTION',$this->ctrl->getFormAction($this));
230 
231  // set table header
232  $this->tpl->setVariable('TYPE_IMG',ilUtil::getImagePath('icon_pays_b.gif'));
233  $this->tpl->setVariable('ALT_IMG',$this->lng->txt('obj_usr'));
234  $this->tpl->touchBlock('stop_floating');
235  $this->tpl->setVariable('TXT_CLOSE_WINDOW',$this->lng->txt('close_window'));
236 
237  // set plain text variables
238  $this->tpl->setVariable('TXT_TERMS_CONDITIONS',$this->lng->txt('pay_bmf_terms_conditions'));
239  $this->tpl->setVariable('TXT_TERMS_CONDITIONS_READ',$this->lng->txt('pay_bmf_terms_conditions_read'));
240  $this->tpl->setVariable('TXT_TERMS_CONDITIONS_SHOW',$this->lng->txt('pay_bmf_terms_conditions_show'));
241  $this->tpl->setVariable('LINK_TERMS_CONDITIONS','./payment.php?view=conditions');
242  $this->tpl->setVariable('TXT_PASSWORD',$this->lng->txt('password'));
243  $this->tpl->setVariable('TXT_CONFIRM_ORDER',$this->lng->txt('pay_confirm_order'));
244 
245  $this->tpl->setVariable('INPUT_VALUE',$this->lng->txt('pay_send_order'));
246  $this->tpl->setVariable('CANCEL',$this->lng->txt('cancel'));
247  if ($this->error != '' &&
248  isset($_POST['terms_conditions']))
249  {
250  $this->tpl->setVariable('TERMS_CONDITIONS_' . strtoupper($_POST['terms_conditions']), ' checked') ;
251  }
252  if ($this->error != '' &&
253  isset($_POST['password']))
254  {
255  $this->tpl->setVariable('PASSWORD', ilUtil::prepareFormOutput($_POST['password'],true));
256  }
257 
258  // Button
259  $this->tpl->addBlockfile('BUTTONS', 'buttons', 'tpl.buttons.html');
260  $this->tpl->setCurrentBlock('btn_cell');
261  $this->tpl->setVariable('BTN_LINK', $this->ctrl->getLinkTarget($this, 'showPersonalData'));
262  $this->tpl->setVariable('BTN_TXT', $this->lng->txt('pay_bmf_back'));
263  $this->tpl->parseCurrentBlock('btn_cell');
264  }
265  }
266 
270  function executeCommand()
271  {
272  global $tree;
273 
274  $cmd = $this->ctrl->getCmd();
275 
276  switch ($this->ctrl->getNextClass($this))
277  {
278  default:
279  if(!$cmd = $this->ctrl->getCmd())
280  {
281  $cmd = 'showPersonalData';
282  }
283  $this->$cmd();
284  break;
285  }
286  }
287 
288  public function __addBookings($external_data = null)
289  {
290  global //$ilias,
291  $ilObjDataCache;
292 
293  //$this->psc_obj = new ilPaymentShoppingCart($this->user_obj);
294 
295  $sc = $this->psc_obj->getShoppingCart($this->pm_id);
296 
297  $this->psc_obj->clearCouponItemsSession();
298 
299  if (is_array($sc) && count($sc) > 0)
300  {
301  include_once './Services/Payment/classes/class.ilPaymentBookings.php';
302  $book_obj = new ilPaymentBookings($this->usr_obj);
303 
304  for ($i = 0; $i < count($sc); $i++)
305  {
306  if (!empty($_SESSION['coupons'][$this->session_var]))
307  {
308  $sc[$i]['math_price'] = (float) $sc[$i]['price'];
309 
310  $tmp_pobject = new ilPaymentObject($this->user_obj, $sc[$i]['pobject_id']);
311 
312  foreach ($_SESSION['coupons'][$this->session_var] as $key => $coupon)
313  {
314  $this->coupon_obj->setId($coupon['pc_pk']);
315  $this->coupon_obj->setCurrentCoupon($coupon);
316 
317  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
318  {
319  $_SESSION['coupons'][$this->session_var][$key]['total_objects_coupon_price'] += (float) $sc[$i]['price'];
320  $_SESSION['coupons'][$this->session_var][$key]['items'][] = $sc[$i];
321  }
322  }
323 
324  unset($tmp_pobject);
325  }
326  }
327 
328  $coupon_discount_items = $this->psc_obj->calcDiscountPrices($_SESSION['coupons'][$this->session_var]);
329 
330  $inst_id_time = $this->ilias->getSetting('inst_id').'_'.$this->user_obj->getId().'_'.substr((string) time(),-3);
331  $transaction = $inst_id_time.substr(md5(uniqid(rand(), true)), 0, 4);
332 
333  for ($i = 0; $i < count($sc); $i++)
334  {
335  $pobjectData = ilPaymentObject::_getObjectData($sc[$i]['pobject_id']);
336  $pobject = new ilPaymentObject($this->user_obj,$sc[$i]['pobject_id']);
337 
338  $price = $sc[$i]['price'];
339  $bonus = 0.0;
340 
341  if (array_key_exists($sc[$i]['pobject_id'], $coupon_discount_items))
342  {
343  $bonus = $coupon_discount_items[$sc[$i]['pobject_id']]['math_price'] - $coupon_discount_items[$sc[$i]['pobject_id']]['discount_price'];
344  }
345 
346  $book_obj->setTransaction($transaction);
347  $book_obj->setPobjectId($sc[$i]['pobject_id']);
348  $book_obj->setCustomerId($this->user_obj->getId());
349  $book_obj->setVendorId($pobjectData['vendor_id']);
350  $book_obj->setPayMethod($pobjectData['pay_method']);
351  $book_obj->setOrderDate(time());
352  $book_obj->setDuration($sc[$i]['duration']);
353  $book_obj->setUnlimitedDuration($sc[i]['unlimited_duration']);
354  $book_obj->setPrice($sc[$i]['price_string']);
355  //$book_obj->setDiscount($bonus > 0 ? ilPaymentPrices::_getPriceStringFromAmount($bonus * (-1)) : '');
356  $book_obj->setDiscount($bonus > 0 ? (round($bonus, 2)* (-1)) : 0);
357  $book_obj->setPayed(1);
358  $book_obj->setAccess(1);
359 
360  $book_obj->setVoucher(''); // bmf
361  $book_obj->setTransactionExtern(''); // bmf , paypal
362 
363  $book_obj->setVatRate($sc[$i]['vat_rate']);
364  $book_obj->setVatUnit($sc[$i]['vat_unit']);
365  $book_obj->setObjectTitle(strip_tags($sc[$i]['object_title']));
366 
367  if($external_data)
368  {
369  $book_obj->setVoucher($external_data['voucher']); // bmf
370  $book_obj->setTransactionExtern($external_data['transaction_extern']); // bmf, paypal
371  $book_obj->setStreet($external_data['street'],'');
372  $book_obj->setZipcode($external_data['zipcode']);
373  $book_obj->setCity($external_data['city']);
374  $book_obj->setCountry($external_data['country']);
375  }
376  else
377  if(isset($_SESSION[$this->session_var]['personal_data']))
378  {
379  $book_obj->setStreet($_SESSION[$this->session_var]['personal_data']['street'], $_SESSION[$this->session_var]['personal_data']['house_number']);
380  $book_obj->setPoBox($_SESSION[$this->session_var]['personal_data']['po_box']);
381  $book_obj->setZipcode($_SESSION[$this->session_var]['personal_data']['zipcode']);
382  $book_obj->setCity($_SESSION[$this->session_var]['personal_data']['city']);
383  $book_obj->setCountry($_SESSION[$this->session_var]['personal_data']['country']);
384  }
385  else
386  {
387  $book_obj->setStreet($this->user_obj->getStreet(), '');
388  $book_obj->setPoBox($this->user_obj->getPoBox());
389  $book_obj->setZipcode($this->user_obj->getZipCode());
390  $book_obj->setCity($this->user_obj->getCity());
391  $book_obj->setCountry($this->user_obj->getCountry());
392  }
393 
394  $booking_id = $book_obj->add();
395 
396  if (!empty($_SESSION['coupons'][$this->session_var]) && $booking_id)
397  {
398  foreach ($_SESSION['coupons'][$this->session_var] as $coupon)
399  {
400  $this->coupon_obj->setId($coupon['pc_pk']);
401  $this->coupon_obj->setCurrentCoupon($coupon);
402 
403  if ($this->coupon_obj->isObjectAssignedToCoupon($pobject->getRefId()))
404  {
405  $this->coupon_obj->addCouponForBookingId($booking_id);
406  }
407  }
408  }
409 
410  $obj_id = $ilObjDataCache->lookupObjId($pobjectData['ref_id']);
411  $obj_type = $ilObjDataCache->lookupType($obj_id);
412  $obj_title = $ilObjDataCache->lookupTitle($obj_id);
413 
414  $bookings['list'][] = array(
415  'pobject_id' => $sc[$i]['pobject_id'],
416  'type' => $obj_type,
417  'title' => '['.$obj_id.']: ' . $obj_title,
418  'duration' => $sc[$i]['duration'],
419  'vat_rate' => $sc[$i]['vat_rate'],
420  'vat_unit' => $sc[$i]['vat_unit'],
421  'price_string' => $sc[$i]['price_string'],
422  'price' => $sc[$i]['price'],
423  'bonus'=> $bonus
424  );
425 
426  $total += $sc[$i]['price'];
427  $total_vat += $sc[$i]['vat_unit'];
428 
429  if ($sc[$i]['psc_id']) $this->psc_obj->delete($sc[$i]['psc_id']);
430  }
431 
432  if (!empty($_SESSION['coupons'][$this->session_var]))
433  {
434  foreach ($_SESSION['coupons'][$this->session_var] as $coupon)
435  {
436  $this->coupon_obj->setId($coupon['pc_pk']);
437  $this->coupon_obj->setCurrentCoupon($coupon);
438  $this->coupon_obj->addTracking();
439  }
440  }
441  }
442 
443  $bookings['total'] = $total;
444  $bookings['total_vat'] = $total_vat;
445  $bookings['transaction'] = $transaction;
446  $bookings['street'] = $book_obj->getStreet();
447  $bookings['zipcode'] = $book_obj->getZipCode();
448  $bookings['city'] = $book_obj->getCity();
449  $bookings['country'] = $book_obj->getCountry();
450  $bookings['transaction_extern'] = $book_obj->getTransactionExtern();
451 
452  $this->__sendBill($bookings);
453  }
454 
455  public function __sendBill($bookings)
456  {
457 
458  global //$ilUser,$ilias,
459  $tpl;
460 
461  include_once './classes/class.ilTemplate.php';
462  include_once './Services/Utilities/classes/class.ilUtil.php';
463  include_once './Services/Payment/classes/class.ilGeneralSettings.php';
464  include_once './Services/Payment/classes/class.ilPaymentShoppingCart.php';
465  include_once 'Services/Mail/classes/class.ilMimeMail.php';
466 
467  $psc_obj = new ilPaymentShoppingCart($this->user_obj);
468  $genSet = new ilGeneralSettings();
469  $currency = $genSet->get('currency_unit');
470 
471  $tpl = new ilTemplate('./Services/Payment/templates/default/tpl.pay_bill.html', true, true, true);
472 
473  $tpl->setVariable('VENDOR_ADDRESS', nl2br(utf8_decode($genSet->get('address'))));
474  $tpl->setVariable('VENDOR_ADD_INFO', nl2br(utf8_decode($genSet->get('add_info'))));
475  $tpl->setVariable('VENDOR_BANK_DATA', nl2br(utf8_decode($genSet->get('bank_data'))));
476  $tpl->setVariable('TXT_BANK_DATA', utf8_decode($this->lng->txt('pay_bank_data')));
477 
478 
479  $tpl->setVariable('CUSTOMER_FIRSTNAME', $this->user_obj->getFirstname());
480  $tpl->setVariable('CUSTOMER_LASTNAME', $this->user_obj->getLastname());
481  if($bookings['po_box']== '')
482  {
483  $tpl->setVariable('CUSTOMER_STREET', $bookings['street']); // contains also housenumber
484  }
485  else
486  {
487  $tpl->setVariable('CUSTOMER_STREET', $bookings['po_box']);
488  }
489  $tpl->setVariable('CUSTOMER_ZIPCODE', $bookings['zipcode']);
490  $tpl->setVariable('CUSTOMER_CITY', $bookings['city']);
491  $tpl->setVariable('CUSTOMER_COUNTRY', $bookings['country']);
492 
493  $tpl->setVariable('BILL_NO', $bookings['transaction']);
494  $tpl->setVariable('DATE', date('d.m.Y'));
495 
496  $tpl->setVariable('TXT_BILL', utf8_decode($this->lng->txt('pays_bill')));
497  $tpl->setVariable('TXT_BILL_NO', utf8_decode($this->lng->txt('pay_bill_no')));
498  $tpl->setVariable('TXT_DATE', utf8_decode($this->lng->txt('date')));
499 
500  $tpl->setVariable('TXT_ARTICLE', utf8_decode($this->lng->txt('pay_article')));
501  $tpl->setVariable('TXT_VAT_RATE', utf8_decode($this->lng->txt('vat_rate')));
502  $tpl->setVariable('TXT_VAT_UNIT', utf8_decode($this->lng->txt('vat_unit')));
503  $tpl->setVariable('TXT_PRICE', utf8_decode($this->lng->txt('price_a')));
504 
505  for ($i = 0; $i < count($bookings['list']); $i++)
506  {
507  $tmp_pobject = new ilPaymentObject($this->user_obj, $bookings['list'][$i]['pobject_id']);
508 
509  $assigned_coupons = '';
510  if (!empty($_SESSION['coupons'][$this->session_var]))
511  {
512  foreach ($_SESSION['coupons'][$this->session_var] as $coupon)
513  {
514  $this->coupon_obj->setId($coupon['pc_pk']);
515  $this->coupon_obj->setCurrentCoupon($coupon);
516 
517  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
518  {
519  $assigned_coupons .= '<br />' . $this->lng->txt('paya_coupons_coupon') . ': ' . $coupon['pcc_code'];
520  }
521  }
522  }
523 
524  $tpl->setCurrentBlock('loop');
525  $tpl->setVariable('LOOP_OBJ_TYPE', utf8_decode($this->lng->txt($bookings['list'][$i]['type'])));
526  $tpl->setVariable('LOOP_TITLE',$tmp = utf8_decode($bookings['list'][$i]['title']));
527  $tpl->setVariable('LOOP_COUPON', utf8_decode( $assigned_coupons));
528  $tpl->setVariable('LOOP_TXT_ENTITLED_RETRIEVE', utf8_decode($this->lng->txt('pay_entitled_retrieve')));
529 
530  if( $bookings['list'][$i]['duration'] == 0)
531  {
532  $tpl->setVariable('LOOP_DURATION', utf8_decode($this->lng->txt('unlimited_duration')));
533  }
534  else
535  $tpl->setVariable('LOOP_DURATION', $bookings['list'][$i]['duration'] . ' ' . utf8_decode($this->lng->txt('paya_months')));
536 
537  #$currency = $bookings['list'][$i]['currency_unit'];
538  $tpl->setVariable('LOOP_VAT_RATE', $bookings['list'][$i]['vat_rate'].' %');
539  $tpl->setVariable('LOOP_VAT_UNIT', $bookings['list'][$i]['vat_unit'].' '.$currency);
540  $tpl->setVariable('LOOP_PRICE', $bookings['list'][$i]['price'].' '.$currency);
541  $tpl->parseCurrentBlock('loop');
542 
543  unset($tmp_pobject);
544  }
545 
546  if (!empty($_SESSION['coupons'][$this->session_var]))
547  {
548  if (count($items = $bookings['list']))
549  {
550  $sub_total_amount = $bookings['total'];
551 
552  foreach ($_SESSION['coupons'][$this->session_var] as $coupon)
553  {
554  $this->coupon_obj->setId($coupon['pc_pk']);
555  $this->coupon_obj->setCurrentCoupon($coupon);
556 
557  $total_object_price = 0.0;
558  $current_coupon_bonus = 0.0;
559 
560  foreach ($bookings['list'] as $item)
561  {
562  $tmp_pobject =& new ilPaymentObject($this->user_obj, $item['pobject_id']);
563 
564  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
565  {
566  $total_object_price += $item['price'];
567  }
568  unset($tmp_pobject);
569  }
570 
571  $current_coupon_bonus = $this->coupon_obj->getCouponBonus($total_object_price);
572  $bonus += $current_coupon_bonus * (-1);
573 
574  $tpl->setCurrentBlock('cloop');
575  $tpl->setVariable('TXT_COUPON', utf8_decode($this->lng->txt('paya_coupons_coupon') . ' ' . $coupon['pcc_code']));
576  $tpl->setVariable('BONUS', number_format($bonus, 2, ',', '.') . ' ' .$currency);
577 
578  $tpl->parseCurrentBlock();
579  }
580 
581  $tpl->setVariable('TXT_SUBTOTAL_AMOUNT', utf8_decode($this->lng->txt('pay_bmf_subtotal_amount')));
582  $tpl->setVariable('SUBTOTAL_AMOUNT', number_format($sub_total_amount, 2, ',', '.') . ' ' .$currency);
583  }
584  }
585 
586  if ($bookings['total'] < 0)
587  {
588  $bookings['total'] = 0.0;
590  }
591 
592  $tpl->setVariable('TXT_TOTAL_AMOUNT', utf8_decode($this->lng->txt('pay_bmf_total_amount')));
593  $tpl->setVariable('TOTAL_AMOUNT', number_format($bookings['total']-$current_coupon_bonus, 2, ',', '.') . ' ' . $currency);
594  if ($bookings['total_vat'] > 0)
595  {
596  $tpl->setVariable('TOTAL_VAT', $bookings['total_vat']. ' ' .$currency);
597  $tpl->setVariable('TXT_TOTAL_VAT', utf8_decode($this->lng->txt('pay_bmf_vat_included')));
598  }
599 
600  $tpl->setVariable('TXT_PAYMENT_TYPE', utf8_decode($this->lng->txt('pay_payed_bill')));
601 
602  if (!@file_exists($genSet->get('pdf_path')))
603  {
604 
605  ilUtil::makeDir($genSet->get('pdf_path'));
606  }
607 
608  if (@file_exists($genSet->get('pdf_path')))
609  {
610  ilUtil::html2pdf($tpl->get(), $genSet->get('pdf_path') . '/' . $bookings['transaction'] . '.pdf');
611  }
612 
613  if (@file_exists($genSet->get('pdf_path') . '/' . $bookings['transaction'] . '.pdf') &&
614  $this->user_obj->getEmail() != '' &&
615  $this->ilias->getSetting('admin_email') != '')
616  {
617  $m= new ilMimeMail; // create the mail
618  $m->From( $this->ilias->getSetting('admin_email') );
619  $m->To( $this->user_obj->getEmail() );
620  $m->Subject( $this->lng->txt('pay_message_subject') );
621  $message = $this->lng->txt('pay_message_hello') . ' ' . $this->user_obj->getFirstname() . ' ' . $this->user_obj->getLastname() . ",\n\n";
622  $message .= $this->lng->txt('pay_message_thanks') . "\n\n";
623  $message .= $this->lng->txt('pay_message_attachment') . "\n\n";
624  $message .= $this->lng->txt('pay_message_regards') . "\n\n";
625  $message .= strip_tags($genSet->get('address'));
626  $m->Body( $message ); // set the body
627  $m->Attach( $genSet->get('pdf_path') . '/' . $bookings['transaction'] . '.pdf', 'application/pdf' ) ; // attach a file of type image/gif
628  $m->Send(); // send the mail
629  }
630 
631  @unlink($genSet->get('pdf_path') . '/' . $bookings['transaction'] . '.html');
632  @unlink($genSet->get('pdf_path') . '/' . $bookings['transaction'] . '.pdf');
633 
634  unset($current_booking_id);
635  unset($pobject);
636  unset($_SESSION['coupons'][$this->session_var]);
637  }
638 
640  {
641  include_once './Services/Payment/classes/class.ilPaymentShoppingCart.php';
642 
643  $sc_obj =& new ilPaymentShoppingCart($this->user_obj);
644 
645  return $sc_obj->emptyShoppingCart();
646  }
647 
648  function __clearSession()
649  {
650  $_SESSION['coupons'][$this->session_var] = '';
652  }
653 
654  function __loadTemplate()
655  {
656  $this->tpl->addBlockFile('CONTENT', 'content', 'tpl.payb_content.html');
657 
658  $this->__buildStylesheet();
659  $this->__buildStatusline();
660  }
661 
662  function __buildStatusline()
663  {
664  $this->tpl->addBlockFile('STATUSLINE', 'statusline', 'tpl.statusline.html');
665 # $this->__buildLocator();
666  }
667 
668  function __buildLocator()
669  {
670  $this->tpl->addBlockFile('LOCATOR', 'locator', 'tpl.locator.html');
671  $this->tpl->setVariable('TXT_LOCATOR',$this->lng->txt('locator'));
672 
673  $this->tpl->setCurrentBlock('locator_item');
674  $this->tpl->setVariable('ITEM', $this->lng->txt('personal_desktop'));
675  $this->tpl->setVariable('LINK_ITEM','../ilias.php?baseClass=ilPersonalDesktopGUI');
676  $this->tpl->parseCurrentBlock();
677 
678  $this->tpl->setCurrentBlock('locator_item');
679  $this->tpl->setVariable('PREFIX','>&nbsp;');
680  $this->tpl->setVariable('ITEM', 'Payment');
681  $this->tpl->setVariable('LINK_ITEM', './payment.php');
682  $this->tpl->parseCurrentBlock();
683 
684  // CHECK for new mail and info
686 
687  return true;
688  }
689 
690  function __buildStylesheet()
691  {
692  $this->tpl->setVariable('LOCATION_STYLESHEET',ilUtil::getStyleSheetLocation());
693  }
694 
698  public function __getCountries()
699  {
700  global $lng;
701 
702  $lng->loadLanguageModule('meta');
703 
704  $cntcodes = array ('DE','ES','FR','GB','AT','CH','AF','AL','DZ','AS','AD','AO',
705  'AI','AQ','AG','AR','AM','AW','AU','AT','AZ','BS','BH','BD','BB','BY',
706  'BE','BZ','BJ','BM','BT','BO','BA','BW','BV','BR','IO','BN','BG','BF',
707  'BI','KH','CM','CA','CV','KY','CF','TD','CL','CN','CX','CC','CO','KM',
708  'CG','CK','CR','CI','HR','CU','CY','CZ','DK','DJ','DM','DO','TP','EC',
709  'EG','SV','GQ','ER','EE','ET','FK','FO','FJ','FI','FR','FX','GF','PF',
710  'TF','GA','GM','GE','DE','GH','GI','GR','GL','GD','GP','GU','GT','GN',
711  'GW','GY','HT','HM','HN','HU','IS','IN','ID','IR','IQ','IE','IL','IT',
712  'JM','JP','JO','KZ','KE','KI','KP','KR','KW','KG','LA','LV','LB','LS',
713  'LR','LY','LI','LT','LU','MO','MK','MG','MW','MY','MV','ML','MT','MH',
714  'MQ','MR','MU','YT','MX','FM','MD','MC','MN','MS','MA','MZ','MM','NA',
715  'NR','NP','NL','AN','NC','NZ','NI','NE','NG','NU','NF','MP','NO','OM',
716  'PK','PW','PA','PG','PY','PE','PH','PN','PL','PT','PR','QA','RE','RO',
717  'RU','RW','KN','LC','VC','WS','SM','ST','SA','CH','SN','SC','SL','SG',
718  'SK','SI','SB','SO','ZA','GS','ES','LK','SH','PM','SD','SR','SJ','SZ',
719  'SE','SY','TW','TJ','TZ','TH','TG','TK','TO','TT','TN','TR','TM','TC',
720  'TV','UG','UA','AE','GB','UY','US','UM','UZ','VU','VA','VE','VN','VG',
721  'VI','WF','EH','YE','ZR','ZM','ZW');
722  $cntrs = array();
723  foreach($cntcodes as $cntcode)
724  {
725  $cntrs[$cntcode] = $lng->txt('meta_c_'.$cntcode);
726  }
727  asort($cntrs);
728  return $cntrs;
729  }
730 
731  public function __getCountryCode($value = '')
732  {
733  $countries = $this->__getCountries();
734  foreach($countries as $code => $text)
735  {
736  if ($text == $value)
737  {
738  return $code;
739  }
740  }
741  return;
742  }
743 
744  public function __getCountryName($value = '')
745  {
746  $countries = $this->__getCountries();
747  return $countries[$value];
748  }
749 
750  function __getShoppingCart()
751  {
752  $this->psc_obj = new ilPaymentShoppingCart($this->user_obj);
753 
754  if(!count($items = $this->psc_obj->getEntries($this->pm_id)))
755  {
756  return 0;
757  }
758 
759  $counter = 0;
760  foreach($items as $item)
761  {
762  $tmp_pobject =& new ilPaymentObject($this->user_obj,$item['pobject_id']);
763 
764  $tmp_obj =& ilObjectFactory::getInstanceByRefId($tmp_pobject->getRefId(), false);
765  if($tmp_obj)
766  {
767  $f_result[$counter]["object_title"] = $tmp_obj->getTitle();
768  }
769  else
770  {
771  $f_result[$counter]["object_title"] = $this->lng->txt('object_not_found');
772  }
773 
774  $price_arr = ilPaymentPrices::_getPrice($item['price_id']);
775 
776  $price = (float) $price_arr['price'];
777  $f_result[$counter]['price'] = $price * 1.0;
778  unset($tmp_obj);
779  unset($tmp_pobject);
780 
781  ++$counter;
782  }
783 
784  return $f_result;
785  }
786 
787  function __getTotalAmount()
788  {
789  $amount = 0;
790 
791  if (is_array($result = $this->__getShoppingCart()))
792  {
793  for ($i = 0; $i < count($result); $i++)
794  {
795  $amount += $result[$i]['price'];
796  }
797  }
798  return $amount;
799  }
800 
801  // if ok, a transaction-id will be generated and the customer gets a bill
802  function getBill()
803  {
804  if ($_POST['terms_conditions'] != 1)
805  {
806  $this->error = $this->lng->txt('pay_bmf_check_terms_conditions');
807  ilUtil::sendInfo($this->error);
808  $this->getPersonalData();
809  return;
810  }
811  if ($_POST['password'] == '' ||
812  md5($_POST['password']) != $this->user_obj->getPasswd())
813  {
814  $this->error = $this->lng->txt('pay_bmf_password_not_valid');
815  ilUtil::sendInfo($this->error);
816  $this->getPersonalData();
817  return;
818  }
819  $this->error = '';
820  ilUtil::sendInfo($this->lng->txt('pay_message_thanks'));
821 
822  $this->__addBookings();
823 
824  }
825 
827  {
828  include_once './Services/Payment/classes/class.ilGeneralSettings.php';
829 
830  $genSet = new ilGeneralSettings();
831 
832  $this->psc_obj = new ilPaymentShoppingCart($this->user_obj);
833 
834  if(!count($items = $this->psc_obj->getEntries($this->pm_id)))
835  {
836  ilUtil::sendInfo($this->lng->txt('pay_shopping_cart_empty'));
837  }
838 
839  $counter = 0;
840  foreach($items as $item)
841  {
842  $tmp_pobject = new ilPaymentObject($this->user_obj,$item['pobject_id']);
843 
844  $tmp_obj = ilObjectFactory::getInstanceByRefId($tmp_pobject->getRefId(), false);
845 
846  $price_arr = ilPaymentPrices::_getPrice($item['price_id']);
847 
848  $assigned_coupons = '';
849  if (!empty($_SESSION['coupons'][$this->session_var]))
850  {
851  foreach ($_SESSION['coupons'][$this->session_var] as $key => $coupon)
852  {
853  $this->coupon_obj->setId($coupon['pc_pk']);
854  $this->coupon_obj->setCurrentCoupon($coupon);
855 
856  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
857  {
858  $assigned_coupons .= '<br />' . $this->lng->txt('paya_coupons_coupon') . ': ' . $coupon['pcc_code'];
859  }
860  }
861  }
862  $f_result[$counter]['item'] = '';
863  if($tmp_obj)
864  {
865  $f_result[$counter]['title'] = $tmp_obj->getTitle();
866  }
867  else
868  {
869  $f_result[$counter]['title'] = $this->lng->txt('object_not_found');
870  }
871  if ($assigned_coupons != '') $f_result[$counter][count($f_result[$counter]) - 1] .= $assigned_coupons;
872 
873  if($price_arr['duration'] == 0)
874  {
875  $f_result[$counter]['duration'] = $this->lng->txt('unlimited_duration');
876  }
877  else
878  {
879  $f_result[$counter]['duration'] = $price_arr['duration'] . ' ' . $this->lng->txt('paya_months');
880  }
881 
882  $oVAT = new ilShopVats((int)$tmp_pobject->getVatId());
883  $f_result[$counter]['vat_rate'] = ilShopUtils::_formatVAT($oVAT->getRate());
884 
885  $float_price = $price_arr['price'];
886 
887  $currency = ilPaymentCurrency::_getUnit($price_arr['currency']);
888  $f_result[$counter]['vat_unit'] = $tmp_pobject->getVat($float_price, 'GUI').' '.$genSet->get('currency_unit');
889  $this->totalVat = $this->totalVat + $tmp_pobject->getVat($float_price);
890 
891  $f_result[$counter]['price'] = number_format(ilPaymentPrices::_getPriceString($item['price_id']), 2, ',', '.') .' '.$genSet->get('currency_unit');
892 
893  unset($tmp_obj);
894  unset($tmp_pobject);
895 
896  ++$counter;
897  }
898 
899  return $this->__showItemsTable($f_result);
900  }
901 
902  function __showItemsTable($a_result_set)
903  {
904  include_once './Services/Payment/classes/class.ilGeneralSettings.php';
905 
906  $genSet = new ilGeneralSettings();
907  include_once './Services/Payment/classes/class.ilShoppingCartTableGUI.php';
908 
909  $tbl = new ilShoppingCartTableGUI($this);
910  $tbl->setId('tbl_id_'.$this->session_var);
911  $tbl->setTitle($this->lng->txt('paya_shopping_cart'));
912  /*
913  " (".$this->lng->txt('payment_system').": ".
914  ilPayMethods::getStringByPaymethod($a_pay_method['pm_title']) .")");
915  */
916  $tbl->setRowTemplate("tpl.shop_shoppingcart_row.html", "Services/Payment");
917  $tbl->addColumn('','item','1%');
918  $tbl->addColumn($this->lng->txt('title'), 'title', '30%');
919  $tbl->addColumn($this->lng->txt('duration'),'duration', '30%');
920  $tbl->addColumn($this->lng->txt('vat_rate'), 'vat_rate', '15%');
921  $tbl->addColumn($this->lng->txt('vat_unit'), 'vat_unit', '15%');
922  $tbl->addColumn($this->lng->txt('price_a'), 'price', '10%');
923  $tbl->disable('sort');
924 
925  #$tbl->setPrefix("table". $a_pay_method['pm_title']."_");
926 
927  // show total amount of costs
928  $sc_obj = new ilPaymentShoppingCart($this->user_obj);
929  $totalAmount = $sc_obj->getTotalAmount();
930 
931  if (!empty($_SESSION['coupons'][$this->session_var]))
932  {
933  if (count($items = $sc_obj->getEntries($this->pm_id)))
934  {
935  $tbl->setTotalData('TXT_SUB_TOTAL', $this->lng->txt('pay_bmf_subtotal_amount') . ": ");
936  $tbl->setTotalData('VAL_SUB_TOTAL', number_format($totalAmount[$this->pm_id], 2, ',', '.') . " " . $genSet->get('currency_unit'));
937  #$tbl->setTotalData('VAL_SUB_TOTAL',ilPaymentPrices::_formatPriceToString($totalAmount[$a_pay_method['pm_id']], (int)$this->default_currency['currency_id'] ));
938 
939  foreach ($_SESSION['coupons'][$this->session_var] as $coupon)
940  {
941  $this->coupon_obj->setId($coupon['pc_pk']);
942  $this->coupon_obj->setCurrentCoupon($coupon);
943 
944  $total_object_price = 0.0;
945  $current_coupon_bonus = 0.0;
946 
947  foreach ($items as $item)
948  {
949  $tmp_pobject = new ilPaymentObject($this->user_obj, $item['pobject_id']);
950 
951  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
952  {
953  $price_data = ilPaymentPrices::_getPrice($item['price_id']);
954  $price = (float) $price_data['price'];
955 
956  $total_object_price += $price;
957  }
958  unset($tmp_pobject);
959  }
960 
961  $current_coupon_bonus = $this->coupon_obj->getCouponBonus($total_object_price);
962  $totalAmount[$current_coupon_bonus] += $current_coupon_bonus * (-1);
963  $tbl->setTotalData('TXT_COUPON_BONUS', $this->lng->txt('paya_coupons_coupon') . " " . $coupon['pcc_code'] . ": ");
964  $tbl->setTotalData('VAL_COUPON_BONUS', number_format($current_coupon_bonus * (-1), 2, ',', '.') . " " . $genSet->get('currency_unit'));
965  }
966 
967  if ($totalAmount[$this->pm_id] < 0)
968  {
969  $totalAmount[$this->pm_id] = 0;
970  $this->totalVat = 0;
971  }
972  }
973  }
974 
975  $this->totalAmount[$this->pm_id] = $totalAmount[$this->pm_id]-$current_coupon_bonus;
976  $tbl->setTotalData('TXT_TOTAL_AMOUNT', $this->lng->txt('pay_bmf_total_amount').": ");
977  $tbl->setTotalData('VAL_TOTAL_AMOUNT', number_format($this->totalAmount[$this->pm_id] , 2, ',', '.') . " " . $genSet->get('currency_unit')); #.$item['currency']);
978 
979  // TODO: CURRENCY
980  #$currency_conversion_totalvat = (float)$_SESSION['currency_conversion'][$a_pay_method['pm_title']]['total_vat'];
981  #if($currency_conversion_totalvat > 0) $this->totalVat = $currency_conversion_totalvat;
982 
983  if ($this->totalVat > 0)
984  {
985  $tbl->setTotalData('TXT_TOTAL_VAT', $this->lng->txt('pay_bmf_vat_included') . ": ");
986  $tbl->setTotalData('VAL_TOTAL_VAT', number_format($this->totalVat , 2, ',', '.') . " " . $genSet->get('currency_unit'));
987  }
988 
989  $tbl->setData($a_result_set);
990  $this->tpl->setVariable('ITEMS_TABLE',$tbl->getCartHTML());
991 
992  return true;
993  }
994 }
995 ?>