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