ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilShopShoppingCartGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/Payment/classes/class.ilPurchasePaypal.php';
5 
6 include_once './Services/Payment/classes/class.ilShopBaseGUI.php';
7 include_once './Services/Payment/classes/class.ilPaypalSettings.php';
8 include_once './Services/Payment/classes/class.ilEPaySettings.php';
9 include_once './Services/Payment/classes/class.ilPaymentCoupons.php';
10 include_once './Services/Payment/classes/class.ilShopVatsList.php';
11 include_once './Services/Payment/classes/class.ilPaymentShoppingCart.php';
12 include_once './Services/Payment/classes/class.ilPayMethods.php';
13 
14 include_once './Services/Payment/classes/class.ilPaymentCurrency.php';
15 include_once './Services/Payment/classes/class.ilShopBoughtObjectsGUI.php';
16 
27 {
28  private $user_obj;
29  private $psc_obj = null;
30  private $paypal_obj = null;
31 
32  private $totalAmount = array();
33  private $totalVat = 0;
34  private $epSet;
35 
36  #private $default_currency = 1;
37  private $session_id;
38 
39  public function __construct($user_obj)
40  {
42 
43  $this->user_obj = $user_obj;
44  $this->session_id = session_id();
45 
46  $this->coupon_obj = new ilPaymentCoupons($this->user_obj);
47 
49  $this->paypalConfig = $ppSet->getAll();
50 
51  $this->epSet = ilEPaySettings::getInstance();
52  $this->epayConfig = $this->epSet->getAll();
53 
55 
56  #$this->default_currency = ilPaymentCurrency::_getDefaultCurrency();
57  }
58 
62  public function executeCommand()
63  {
64  global $ilUser;
65 
66  $cmd = $this->ctrl->getCmd();
67  switch ($this->ctrl->getNextClass($this))
68  {
69  default:
70  $this->prepareOutput();
71  if (!$cmd = $this->ctrl->getCmd())
72  {
73  $cmd = 'showItems';
74  }
75  $this->$cmd();
76  break;
77  }
78 
79  return true;
80  }
81 
82  protected function prepareOutput()
83  {
84  global $ilTabs;
85 
87 
88  $ilTabs->setTabActive('paya_shopping_cart');
89  }
91  {
92  $this->addBookings(PAY_METHOD_BILL, 'bill');
93  $_SESSION['coupons']['bill'] = '';
94 
95  ilUtil::sendInfo($this->lng->txt('pay_bmf_thanks'), true);
96 
97  $this->ctrl->redirectByClass('ilShopBoughtObjectsGUI', '');
98 
99  return true;
100  }
101 
103  {
104  $this->addBookings(PAY_METHOD_BMF, 'bmf');
105 
106  $_SESSION['coupons']['bmf'] = '';
107  $_SESSION['bmf']['payment_type'] = '';
108  $_SESSION['bmf']['debit_entry'] = array();
109  $_SESSION['bmf']['credit_card'] = array();
110 
111  ilUtil::sendInfo($this->lng->txt('pay_bmf_thanks'), true);
112 
113  $this->ctrl->redirectByClass('ilShopBoughtObjectsGUI', '');
114 
115  return true;
116  }
117 
119  {
120  global $ilUser;
121  $this->addBookings(PAY_METHOD_PAYPAL, 'paypal');
122 
123  $_SESSION['coupons']['paypal'] = array();
124 
125  ilUtil::sendSuccess($this->lng->txt('pay_paypal_success'), true);
126 
127  if(ANONYMOUS_USER_ID == $ilUser->getId() || isset($_SESSION['user_name']))
128  {
129  $this->ctrl->redirectByClass('ilShopShoppingCartGUI', '');
130  }
131  else
132  {
133  $this->ctrl->redirectByClass('ilShopBoughtObjectsGUI', '');
134  }
135  return true;
136  }
137 
138  private function addBookings($pay_method, $coupon_session)
139  {
140  global $ilias, $ilUser, $ilObjDataCache;
141 
142  include_once './Services/Payment/classes/class.ilPaymentBookings.php';
143  include_once './Services/Payment/classes/class.ilPaymentObject.php';
144  include_once './Services/Payment/classes/class.ilPaymentPrices.php';
145 
146  $booking_obj = new ilPaymentBookings();
147  $sc_obj = new ilPaymentShoppingCart($this->user_obj);
148  $items = $sc_obj->getEntries($pay_method);
149  $sc_obj->clearCouponItemsSession();
150 
151  foreach($items as $entry)
152  {
153  $pobject = new ilPaymentObject($this->user_obj, $entry['pobject_id']);
154  $price = ilPaymentPrices::_getPrice($entry['price_id']);
155 
156  if (!empty($_SESSION['coupons'][$coupon_session]))
157  {
158  $entry['math_price'] = $entry['price']; // (float) ilPaymentPrices::_getPriceFromArray($price);
159  foreach ($_SESSION['coupons'][$coupon_session] as $key => $coupon)
160  {
161  $this->coupon_obj->setId($coupon['pc_pk']);
162  $this->coupon_obj->setCurrentCoupon($coupon);
163 
164  if ($this->coupon_obj->isObjectAssignedToCoupon($pobject->getRefId()))
165  {
166  $_SESSION['coupons'][$coupon_session][$key]['total_objects_coupon_price'] += $entry['price']; //(float) ilPaymentPrices::_getPriceFromArray($price);
167  $_SESSION['coupons'][$coupon_session][$key]['items'][] = $entry;
168  }
169  }
170  }
171  unset($pobject);
172  }
173 
174  $coupon_discount_items = $sc_obj->calcDiscountPrices($_SESSION['coupons'][$coupon_session]);
175 
176  $i = 0;
177  foreach($items as $entry)
178  {
179  $pobject = new ilPaymentObject($this->user_obj, $entry['pobject_id']);
180 
181  $price = ilPaymentPrices::_getPrice($entry['price_id']);
182 
183  if (array_key_exists($entry['pobject_id'], $coupon_discount_items))
184  {
185  $bonus = $coupon_discount_items[$entry['pobject_id']]['math_price'] - $coupon_discount_items[$entry['pobject_id']]['discount_price'];
186  }
187 
188  $booking_obj->setPobjectId($entry['pobject_id']);
189 
190  $booking_obj->setCustomerId($this->user_obj->getId());
191  $booking_obj->setVendorId($pobject->getVendorId());
192  $booking_obj->setPayMethod($pobject->getPayMethod());
193  $booking_obj->setOrderDate(time());
194  $booking_obj->setDuration($price['duration']);
195  $booking_obj->setPrice(ilPaymentPrices::_getPriceString($entry['price_id']));
196  $booking_obj->setDiscount($bonus > 0 ? ((-1) * $bonus) : 0);
197  $booking_obj->setPayed(1);
198  $booking_obj->setAccess(1);
199 
200  $obj_id = $ilObjDataCache->lookupObjId($pobject->getRefId());
201  $obj_type = $ilObjDataCache->lookupType($obj_id);
202  $obj_title = $ilObjDataCache->lookupTitle($obj_id);
203 
204  $oVAT = new ilShopVats((int)$pobject->getVatId());
205  $obj_vat_rate = $oVAT->getRate();
206 
207  if($bonus > 0)
208  {
209  $tmp_price = $booking_obj->getPrice()-$bonus;
210  $obj_vat_unit = $pobject->getVat($tmp_price);
211  }else
212  $obj_vat_unit = $pobject->getVat($booking_obj->getPrice());
213 
214  $booking_obj->setObjectTitle($obj_title);
215  $booking_obj->setVatRate($obj_vat_rate);
216  $booking_obj->setVatUnit($obj_vat_unit);
217 
218  if(ilPaymethods::_EnabledSaveUserAddress($booking_obj->getPayMethod()))
219  {
220  $booking_obj->setStreet($ilUser->getStreet(), $ilUser->getHouseNumber);
221  $booking_obj->setZipcode($ilUser->getZipcode());
222  $booking_obj->setCity($ilUser->getCity());
223  $booking_obj->setCountry($ilUser->getCountry());
224  }
225 
226  $current_booking_id = $booking_obj->add();
227 
228  if ($current_booking_id)
229  {
230  $sc_obj->delete($entry['psc_id']);
231 
232  if (!empty($_SESSION['coupons'][$coupon_session]))
233  {
234  foreach ($_SESSION['coupons'][$coupon_session] as $coupon)
235  {
236  $this->coupon_obj->setId($coupon['pc_pk']);
237  $this->coupon_obj->setCurrentCoupon($coupon);
238 
239  if ($this->coupon_obj->isObjectAssignedToCoupon($pobject->getRefId()))
240  {
241  $this->coupon_obj->addCouponForBookingId($current_booking_id);
242  }
243  }
244  }
245  }
246 
247  unset($current_booking_id);
248  unset($pobject);
249  }
250 
251  if (!empty($_SESSION['coupons'][$coupon_session]))
252  {
253  foreach ($_SESSION['coupons'][$coupon_session] as $coupon)
254  {
255  $this->coupon_obj->setId($coupon['pc_pk']);
256  $this->coupon_obj->setCurrentCoupon($coupon);
257  $this->coupon_obj->addTracking();
258  }
259  }
260  }
261 
262  public function checkCouponsOfShoppingCart()
263  {
264  $objPM = new ilPayMethods();
265  $get_paymethods = $objPM->readAll();
266 
267  foreach($get_paymethods as $pm)
268  {
269  $pay_methods[$pm['pm_id']]['pm_title'] = $pm['pm_title'];
270  $pay_methods[$pm['pm_id']]['pm_id'] = $pm['pm_id'];
271  }
272 
273  if (is_array($pay_methods))
274  {
275  foreach($pay_methods as $pay_method)
276  {
277  $coupon_session_id = $pay_method['pm_title'];
278 
279  if (!is_array($_SESSION['coupons'][$coupon_session_id]))
280  {
281  $_SESSION['coupons'][$coupon_session_id] = array();
282  }
283  else // check if coupons are valid anymore
284  {
285  foreach ($_SESSION['coupons'][$coupon_session_id] as $coupon_id => $session_coupon)
286  {
287  $coupon = $this->coupon_obj->getCouponByCode($session_coupon['pcc_code']);
288 
289  if ($this->coupon_obj->checkCouponValidity() == 0)
290  {
291  $assignedItems = 0;
292  $this->psc_obj = new ilPaymentShoppingCart($this->user_obj);
293 
294  if (count($items = $this->psc_obj->getEntries($pay_method['pm_id'])))
295  {
296  foreach($items as $item)
297  {
298  $tmp_pobject = new ilPaymentObject($this->user_obj, $item['pobject_id']);
299 
300  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
301  {
302  ++$assignedItems;
303  }
304  }
305  }
306  if (!$assignedItems)
307  {
308  unset($_SESSION['coupons'][$coupon_session_id][$coupon_id]);
309  }
310  }
311  else
312  {
313  unset($_SESSION['coupons'][$coupon_session_id][$coupon_id]);
314  }
315  }
316  }
317  }
318  }
319  }
320 
326  public function finishEPay()
327  {
328  global $ilias, $ilUser;
329  require_once './Services/Payment/classes/class.ilPurchase.php';
330 
331  try
332  {
333  $pm_id = ilPayMethods::_getIdByTitle('epay');
334  $buy = new ilPurchase( $ilUser->getId(), $pm_id );
335  $buy->purchase($_REQUEST['tid'] );
336  }
337  catch (ilERPException $e)
338  {
339  $msg = $e->getMessage();
340  if (DEVMODE) $msg .= " " . print_r($_REQUEST, true);
341  ilUtil::sendFailure($msg);
342  }
343  ilUtil::sendSuccess($this->lng->txt('pay_epay_success'));
344  $this->ctrl->redirectByClass('ilShopBoughtObjectsGUI', '');
345  }
346 
347  public function finishPaypal()
348  {
349  global $ilUser;
350  $this->initPaypalObject();
351 
352  if (!($fp = $this->paypal_obj->openSocket()))
353  {
354  ilUtil::sendFailure($this->lng->txt('pay_paypal_failed').'<br />'.$this->lng->txt('pay_paypal_unreachable').'<br />'.$this->lng->txt('pay_paypal_error_info'));
355  $this->showItems();
356  }
357  else
358  {
359 
360  $res = $this->paypal_obj->checkData($fp);
361 
362 
363  if ($res == SUCCESS)
364  {
365  ilUtil::sendSuccess($this->lng->txt('pay_paypal_success'), true);
366  if($ilUser->getId() == ANONYMOUS_USER_ID || $_SESSION['is_crs_object'] || $_SESSION['is_lm_object'] || $_SESSION['is_file_object'])
367  {
368 
369  $this->ctrl->redirectByClass('ilShopShoppingCartGUI', '');
370  }
371  else
372  {
373  # $this->ctrl->redirectByClass('ilShopBoughtObjectsGUI', '');
374  $this->ctrl->redirectByClass('ilShopShoppingCartGUI', '');
375  }
376  }
377  else
378  {
379  switch ($res)
380  {
381  case ERROR_WRONG_CUSTOMER : ilUtil::sendFailure($this->lng->txt('pay_paypal_failed').'<br />'.$this->lng->txt('pay_paypal_error_wrong_customer').'<br />'.$this->lng->txt('pay_paypal_error_info'));
382  break;
383  case ERROR_NOT_COMPLETED : ilUtil::sendFailure($this->lng->txt('pay_paypal_failed').'<br />'.$this->lng->txt('pay_paypal_error_not_completed').'<br />'.$this->lng->txt('pay_paypal_error_info'));
384  break;
385  case ERROR_PREV_TRANS_ID : ilUtil::sendFailure($this->lng->txt('pay_paypal_failed').'<br />'.$this->lng->txt('pay_paypal_error_prev_trans_id').'<br />'.$this->lng->txt('pay_paypal_error_info'));
386  break;
387  case ERROR_WRONG_VENDOR : ilUtil::sendFailure($this->lng->txt('pay_paypal_failed').'<br />'.$this->lng->txt('pay_paypal_error_wrong_vendor').'<br />'.$this->lng->txt('pay_paypal_error_info'));
388  break;
389  case ERROR_WRONG_ITEMS : ilUtil::sendFailure($this->lng->txt('pay_paypal_failed').'<br />'.$this->lng->txt('pay_paypal_error_wrong_items').'<br />'.$this->lng->txt('pay_paypal_error_info'));
390  break;
391  case ERROR_FAIL : ilUtil::sendFailure($this->lng->txt('pay_paypal_failed').'<br />'.$this->lng->txt('pay_paypal_error_fails').'<br />'.$this->lng->txt('pay_paypal_error_info'));
392  break;
393  }
394  $this->showItems();
395  }
396  fclose($fp);
397  }
398  }
399 
400 
401  public function cancelEPay()
402  {
403  ilUtil::sendInfo($this->lng->txt('pay_epay_canceled'));
404  $this->showItems();
405  }
406 
407  public function cancelPaypal()
408  {
409  ilUtil::sendInfo($this->lng->txt('pay_paypal_canceled'));
410  $this->showItems();
411  }
412 
413  private function _getPayMethods( $limitToEnabled = false )
414  {
415  $objPM = new ilPayMethods();
416  $get_paymethods = $objPM->readAll();
417 
418  if(!$limitToEnabled)
419  {
420  foreach($get_paymethods as $pm)
421  {
422  $pay_methods[$pm['pm_id']]['pm_title'] = $pm['pm_title'];
423  $pay_methods[$pm['pm_id']]['pm_id'] = $pm['pm_id'];
424  $pay_methods[$pm['pm_id']]['pm_enabled'] = $pm['pm_enabled'];
425  $pay_methods[$pm['pm_id']]['save_usr_adr'] = $pm['save_usr_adr'];
426  }
427  }
428  else
429  {
430  foreach($get_paymethods as $pm)
431  {
432  if($pm['pm_enabled'] == 1)
433  {
434  $pay_methods[$pm['pm_id']]['pm_title'] = $pm['pm_title'];
435  $pay_methods[$pm['pm_id']]['pm_id'] = $pm['pm_id'];
436  $pay_methods[$pm['pm_id']]['pm_enabled'] = $pm['pm_enabled'];
437  $pay_methods[$pm['pm_id']]['save_usr_adr'] = $pm['save_usr_adr'];
438  }
439  }
440  }
441  return $pay_methods;
442  }
443 
444  /*
445  *
446  */
447  private function _getTemplateFilename( $a_pm_title )
448  {
449  // use payment_paymethods -> pm_title
450  $base = "./Services/Payment/templates/default/tpl.pay_shopping_cart_";
451  $suffix = ".html";
452 
453  return $base . $a_pm_title . $suffix;
454  }
455 
456  public function cartNotEmpty()
457  {
458  $pay_methods = $this->_getPayMethods( true);
459  if (is_array($pay_methods))
460  for ($p = 0; $p < count($pay_methods); $p++)
461  {
462  if (count($items = $this->psc_obj->getEntries($pay_methods['pm_id'])))
463  {
464  foreach ($items as $item)
465  {
466  return true;
467  }
468  }
469  }
470  return false;
471  }
472 
473  public function showItems()
474  {
475  global $ilObjDataCache, $ilUser;
476 
477  include_once './Services/Payment/classes/class.ilPaymentPrices.php';
478  include_once './Services/Payment/classes/class.ilPaymentCurrency.php';
479 
480  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.pay_shopping_cart.html','Services/Payment');
481  $this->initShoppingCartObject();
482 
483  include_once './Services/Payment/classes/class.ilGeneralSettings.php';
484  $genSet = new ilGeneralSettings();
485  $pay_methods = $this->_getPayMethods( true );
486  $num_items = 0;
487  $desc = array();
488  $is_crs_object = false;
489  $crs_obj_ids = array();
490 
491  $is_file_object = false;
492 
493  $is_lm_object = false;
494  $lm_obj_ids = array();
495 
496  $force_user_login = false;
497 
498  foreach($pay_methods as $pay_method)
499  {
500  $this->totalVat = 0;
501  $tpl = new ilTemplate( $this->_getTemplateFilename( $pay_method['pm_title'] ), true,'Services/Payment');
502  $coupon_session_id = $pay_method['pm_title'];
503 
504  if (count($items = $this->psc_obj->getEntries( $pay_method['pm_id'])))
505  {
506  $counter = 0;
507  $paypal_counter = 0;
508  $total_price = 0;
509 
510  $total_price_in_default_currency = 0;
511  $total_vat_in_default_currency = 0;
512  foreach ($items as $item)
513  {
514  $tmp_pobject = new ilPaymentObject($this->user_obj,$item['pobject_id']);
515 
516  $obj_id = $ilObjDataCache->lookupObjId($tmp_pobject->getRefId());
517  $obj_type = $ilObjDataCache->lookupType($obj_id);
518  $obj_title = $ilObjDataCache->lookupTitle($obj_id);
519  $desc[] = "[" . $obj_type . "] " . $obj_title;
520  $price_arr = ilPaymentPrices::_getPrice($item['price_id']);
521 
522 // TODO: CURRENCY
523  /* $is_default_currency = ((int)$price_arr['currency'] == (int)$this->default_currency['currency_id'] ? true : false);
524  $is_default_currency
525  ? $item_conversion_rate = (float)$this->default_currency['conversion_rate']
526  : $item_conversion_rate = ilPaymentCurrency::_getConversionRate($price_arr['currency']);
527  */
528  # checks object_type: needed for purchasing file or crs objects without login
529  switch ($obj_type)
530  {
531  case 'crs':
532  // if is_crs there an user-aacount will be autogenerated
533  $is_crs_object = true;
534  $_SESSION['is_crs_object'] = true;
535  $crs_obj_ids[] = $obj_id;
536  $_SESSION['crs_obj_ids'] = $crs_obj_ids;
537  break;
538  case 'lm':
539  case 'sahs':
540  case 'htlm':
541  case 'tst':
542  $is_lm_object = true;
543  $_SESSION['is_lm_object'] = true;
544  $lm_obj_ids[] = $obj_id;
545  $_SESSION['lm_obj_ids'] = $lm_obj_ids;
546  break;
547 
548  case 'file':
549  $is_file_object = true;
550  break;
551  default:
552  $force_user_login = true;
553  break;
554  }
555 
556  $direct_paypal_info_output = true;
557 
558  $assigned_coupons = '';
559  if (!empty($_SESSION['coupons'][$coupon_session_id]))
560  {
561  $price = $price_arr['price'];
562  $item['math_price'] = (float) $price;
563 
564  foreach ($_SESSION['coupons'][$coupon_session_id] as $key => $coupon)
565  {
566  $this->coupon_obj->setId($coupon['pc_pk']);
567  $this->coupon_obj->setCurrentCoupon($coupon);
568 
569  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
570  {
571  $assigned_coupons .= $this->lng->txt('paya_coupons_coupon') . ': ' . $coupon['pcc_code'];
572 
573  $_SESSION['coupons'][$coupon_session_id][$key]['total_objects_coupon_price'] += (float) $price;
574  $_SESSION['coupons'][$coupon_session_id][$key]['items'][] = $item;
575  $direct_paypal_info_output = false;
576  }
577  }
578  }
579 
580  $f_result[$counter]['item'] = ilUtil::formCheckBox(0,'item[]',$item['psc_id']);
581  $f_result[$counter]['title'] = "<a href=\"goto.php?target=".$obj_type."_".$tmp_pobject->getRefId() . "\">".$obj_title."</a>";
582  if ($assigned_coupons != '')
583  {
584  // !!! $f_result[$counter][count($f_result[$counter]) - 1] .= $assigned_coupons;
585  $f_result[$counter]['assigned_coupons'] .= $assigned_coupons;
586  }
587 
588  if($price_arr['duration'] == 0)
589  {
590  $f_result[$counter]['duration'] = $this->lng->txt('unlimited_duration');
591  }
592  else
593  $f_result[$counter]['duration'] = $price_arr['duration'].' '.$this->lng->txt('paya_months');
594 
595  $float_price = $price_arr['price'];
596  $total_price += $float_price;
597 
598  $oVAT = new ilShopVats((int)$tmp_pobject->getVatId());
599  $f_result[$counter]['vat_rate'] = ilShopUtils::_formatVAT($oVAT->getRate());
600 //TODO CURRENCY
601 /*
602  $current_vat = $tmp_pobject->getVat($float_price);
603 
604  $current_vat_in_default_currency = $current_vat * $item_conversion_rate;
605  $current_price_in_default_currency = $float_price * $item_conversion_rate;
606 
607  $item_current_vat = ilPaymentPrices::_formatPriceToString($current_vat, $price_arr['currency']);
608  if(!$is_default_currency)
609  $item_current_vat .= ' '.$this->lng->txt('equivalent').' ('.ilPaymentCurrency::_formatPriceToString((float)$current_vat_in_default_currency,$this->default_currency['symbol']).' )';
610 
611  $f_result[$counter]['vat_unit'] = $item_current_vat;
612 
613  $this->totalVat = $this->totalVat + $tmp_pobject->getVat($float_price);
614 
615  $total_price_in_default_currency += $current_price_in_default_currency;
616  $total_vat_in_default_currency += $current_vat_in_default_currency;
617 
618  $_SESSION['currency_conversion'][$pay_method['pm_title']][$counter]['price'] = $current_price_in_default_currency;
619  $_SESSION['currency_conversion'][$pay_method['pm_title']][$counter]['vat'] = $current_vat_in_default_currency;
620 
621  $_SESSION['currency_conversion'][$pay_method['pm_title']]['total_vat'] = $total_vat_in_default_currency;
622  $_SESSION['currency_conversion'][$pay_method['pm_title']]['total_price'] = $total_price_in_default_currency;
623 
624  $item_current_price = ilPaymentPrices::_formatPriceToString($price_arr['price'],$price_arr['currency']);
625  if(!$is_default_currency)
626  $item_current_price .= ' '.$this->lng->txt('equivalent').' ('.ilPaymentCurrency::_formatPriceToString($current_price_in_default_currency,$this->default_currency['symbol']).' )';
627 
628  $f_result[$counter]['price'] = $item_current_price;
629  **/
630  //* old one without currency-conversion
631  $f_result[$counter]['vat_unit'] = $tmp_pobject->getVat($float_price, 'GUI').' '.$genSet->get('currency_unit');
632  $this->totalVat = $this->totalVat + $tmp_pobject->getVat($float_price);
633 
634  $f_result[$counter]['price'] = number_format(ilPaymentPrices::_getPriceString($item['price_id']), 2, ',', '.') .' '.$genSet->get('currency_unit');
635 /*****/
636  if ($pay_method['pm_title'] == 'paypal')
637  {
638  if ($direct_paypal_info_output == true) // Paypal information in hidden fields
639  {
640  $tpl->setCurrentBlock('loop_items');
641  $tpl->setVariable('LOOP_ITEMS_NO', (++$paypal_counter));
642  $tpl->setVariable('LOOP_ITEMS_NAME', "[".$obj_id."]: ".$obj_title);
643  $tpl->setVariable('LOOP_ITEMS_AMOUNT', $float_price);
644 // TODO : CURRENCY $tpl->setVariable('LOOP_ITEMS_AMOUNT',ilPaymentPrices::_formatPriceToString($price_arr['price'],$price_arr['currency']));
645  $tpl->parseCurrentBlock('loop_items');
646  }
647  }
648 
649  ++$counter;
650  unset($tmp_pobject);
651  } // foreach
652 
653  $this->showItemsTable($tpl, $f_result, $pay_method);
654 
655  if (!(bool)$genSet->get('hide_coupons'))
656  {
657  $tpl->setVariable('COUPON_TABLE', $this->showCouponInput($pay_method['pm_title']));
658  }
659  $tpl->setCurrentBlock('buy_link');
660 
661  switch($pay_method['pm_title'])
662  {
663  case 'bill':
664  if ($this->totalAmount[$pay_method['pm_id']] == 0)
665  {
666  $tpl->setVariable('TXT_UNLOCK', $this->lng->txt('pay_click_to_buy'));
667  $tpl->setVariable('LINK_UNLOCK', $this->ctrl->getLinkTarget($this, 'unlockBillObjectsInShoppingCart'));
668  }
669  else
670  {
671  # Anonymous user has to login
672  if(ANONYMOUS_USER_ID == $ilUser->getId())
673 
674  {
675  $tpl->setVariable('TXT_BUY', $this->lng->txt('pay_click_to_buy'));
676  $tpl->setVariable('SCRIPT_LINK','login.php?cmd=force_login&login_to_purchase_object=1&forceShoppingCartRedirect=1');
677  }
678  else
679  {
680  $tpl->setVariable('TXT_BUY', $this->lng->txt('pay_click_to_buy'));
681  $tpl->setVariable('SCRIPT_LINK', $this->ctrl->getLinkTargetByClass('ilPurchaseBillGUI', ''));
682  }
683  }
684  break;
685 
686  case 'bmf':
687  #$tpl->setVariable("SCRIPT_LINK", './payment.php?view=start_bmf');
688  if ($this->totalAmount[$pay_method['pm_id']] == 0)
689  {
690  $tpl->setVariable('TXT_UNLOCK', $this->lng->txt('pay_click_to_buy'));
691  $tpl->setVariable('LINK_UNLOCK', $this->ctrl->getLinkTarget($this, 'unlockBMFObjectsInShoppingCart'));
692  }
693  else
694  {
695  # Anonymous user has to login
696  if(ANONYMOUS_USER_ID == $ilUser->getId())
697  {
698  $tpl->setVariable('TXT_BUY', $this->lng->txt('pay_click_to_buy'));
699  $tpl->setVariable('SCRIPT_LINK','login.php?cmd=force_login&login_to_purchase_object=1&forceShoppingCartRedirect=1');
700  }
701  else
702  {
703  $tpl->setVariable('TXT_BUY', $this->lng->txt('pay_click_to_buy'));
704  $tpl->setVariable('SCRIPT_LINK', $this->ctrl->getLinkTargetByClass('ilPurchaseBMFGUI', ''));
705  }
706  }
707  break;
708 
709  case 'epay':
710  # Anonymous user has to login
711  if(ANONYMOUS_USER_ID == $ilUser->getId())
712  {
713  $tpl->setVariable('TXT_BUY', $this->lng->txt('pay_click_to_buy'));
714  $tpl->setVariable('SCRIPT_LINK','login.php?cmd=force_login&login_to_purchase_object=1&forceShoppingCartRedirect=1');
715  }
716  else
717  {
719  $tpl->setVariable('TXT_BUY', $this->lng->txt('pay_click_to_buy'));
720  $tpl->setVariable('SCRIPT_LINK', 'https://'.$this->epayConfig['server_host'].$this->epayConfig['server_path']);
721  $tpl->setVariable('MERCHANT_NUMBER', $this->epayConfig['merchant_number']);
722  $tpl->setVariable('AMOUNT', $total_price * 100);
723  $tpl->setVariable('CURRENCY', "208");
724  $tpl->setVariable('ORDERID', $ilUser->getId()."_".uniqid());
725  $tpl->setVariable('ACCEPT_URL', ILIAS_HTTP_PATH . "/" . $this->ctrl->getLinkTarget($this, 'finishEPay'));
726  $tpl->setVariable('DECLINE_URL', ILIAS_HTTP_PATH . "/" . $this->ctrl->getLinkTarget($this, 'cancelEPay'));
727  $tpl->setVariable('INSTANT_CAPTURE', $this->epayConfig['instant_capture'] ? "1" : "0");
728  $tpl->setVariable('ADDFEE', 1);
729  $tpl->setVariable('LANGUAGE', 1);
730  $tpl->setVariable('GROUP', "");
731  $tpl->setVariable('CARDTYPE', "");
732  $tpl->setVariable("CALLBACK_URL", ILIAS_HTTP_PATH . "/Services/Payment/classes/class.ilCallback.php?ilUser=" .$ilUser->getId() . "&pay_method=". PAY_METHOD_EPAY);
733 
734  $tpl->setVariable('DESCRIPTION', $ilUser->getFullName() . " (" . $ilUser->getEmail() . ") #" . $ilUser->getId() . " " . implode(",", $desc));
735  $tpl->setVariable('AUTH_MAIL', $this->epayConfig['auth_email']);
736  $tpl->setVariable('MD5KEY', $this->epSet->generateKeyForEpay(208, $total_price*100, $ilUser->getId()."_".uniqid()));
737  }
738  break;
739 
740  case 'paypal':
741  if ($this->totalAmount[$pay_method['pm_id']] == 0)
742  {
743  $tpl->setVariable('TXT_BUY', $this->lng->txt('pay_click_to_buy'));
744  $tpl->setVariable('SCRIPT_LINK', $this->ctrl->getLinkTarget($this, 'unlockPAYPALObjectsInShoppingCart'));
745  }
746  else
747  {
748  if(ANONYMOUS_USER_ID == $ilUser->getId() && $force_user_login == true)
749 
750  {
751  $tpl->setVariable('TXT_BUY', $this->lng->txt('pay_click_to_buy'));
752  $tpl->setVariable('SCRIPT_LINK','login.php?cmd=force_login&login_to_purchase_object=1&forceShoppingCartRedirect=1');
753  }
754  else
755  {
756  $tpl->setVariable('TXT_BUY', $this->lng->txt('pay_click_to_buy'));
757  $tpl->setVariable('SCRIPT_LINK', 'https://'.$this->paypalConfig['server_host'].$this->paypalConfig['server_path']);
758  }
759  }
760 
761  $tpl->setVariable('POPUP_BLOCKER', $this->lng->txt('popup_blocker'));
762  $tpl->setVariable('VENDOR', $this->paypalConfig['vendor']);
763  $tpl->setVariable('RETURN', ILIAS_HTTP_PATH . "/" . $this->ctrl->getLinkTarget($this, 'finishPaypal'));
764  $tpl->setVariable('CANCEL_RETURN', ILIAS_HTTP_PATH . "/" . $this->ctrl->getLinkTarget($this, 'cancelPaypal'));
765  $tpl->setVariable('CUSTOM', $ilUser->getId());
766  $tpl->setVariable('CURRENCY', $genSet->get('currency_unit'));
767 // TODO CURRENCY $tpl->setVariable('CURRENCY', $currency);
768  $tpl->setVariable('PAGE_STYLE', $this->paypalConfig['page_style']);
769 
770  if (!empty($_SESSION['coupons'][$coupon_session_id]))
771  {
772  $coupon_discount_items = $this->psc_obj->calcDiscountPrices($_SESSION['coupons'][$coupon_session_id]);
773 
774  if (is_array($coupon_discount_items) && !empty($coupon_discount_items))
775  {
776  foreach ($coupon_discount_items as $item)
777  {
778  $tmp_pobject = new ilPaymentObject($this->user_obj, $item['pobject_id']);
779 
780  $obj_id = $ilObjDataCache->lookupObjId($tmp_pobject->getRefId());
781  $obj_title = $ilObjDataCache->lookupTitle($obj_id);
782 
783  $tpl->setCurrentBlock('loop_items');
784  $tpl->setVariable('LOOP_ITEMS_NO', (++$paypal_counter));
785  $tpl->setVariable('LOOP_ITEMS_NAME', "[".$obj_id."]: ".$obj_title);
786  $tpl->setVariable('LOOP_ITEMS_AMOUNT', round($item['discount_price'], 2));
787 // TODO CURRENCY $tpl->setVariable('LOOP_ITEMS_AMOUNT', round($item['discount_price'], 2).' '.$currency);
788  $tpl->parseCurrentBlock('loop_items');
789 
790  unset($tmp_pobject);
791  }
792  }
793  }
794  break;
795 # $buttonParams["upload"] = 1;
796 # $buttonParams["charset"] = "utf-8";
797 # $buttonParams["business"] = $this->paypalConfig["vendor"];
798 # $buttonParams["currency_code"] = "EUR";
799 # $buttonParams["return"] = "http://www.databay.de/user/jens/paypal.php";
800 # $buttonParams["rm"] = 2;
801 # $buttonParams["cancel_return"] = "http://www.databay.de/user/jens/paypal.php";
802 # $buttonParams["custom"] = "HALLO";
803 # $buttonParams["invoice"] = "0987654321";
804 # if ($enc_data = $this->__encryptButton($buttonParams))
805 # {
806 # $tpl->setVariable("ENCDATA", $enc_data);
807 # }
808  }
809 
810  if ($pay_method['pm_title'] == 'paypal')
811  {
812  $tpl->setVariable('PAYPAL_HINT', $this->lng->txt('pay_hint_paypal'));
813  $tpl->setVariable('PAYPAL_INFO', $this->lng->txt('pay_info_paypal'));
814  }
815  else if ($pay_method['pm_title'] == 'epay')
816  {
817  $tpl->setVariable('EPAY_HINT', $this->lng->txt('pay_hint_epay'));
818  $tpl->setVariable('EPAY_INFO', $this->lng->txt('pay_info_epay'));
819  }
820 
821  $tpl->parseCurrentBlock('buy_link');
822 
823  $tpl->setCurrentBlock('loop');
824  unset($f_result);
825 
826  $tpl->parseCurrentBlock('loop');
827 
828  $this->tpl->setVariable(''.strtoupper($pay_method['pm_title']).'', $tpl->get());
829 
830  $num_items += $counter;
831  }
832  }
833  #}
834 
835  if($_SESSION['tmp_user_account'])
836  {
837  $question = $this->lng->txt('have_existing_account');
838  if($_SESSION['tmp_user_account'])
839  {
840  $question .= sprintf($this->lng->txt('have_no_existing_account'), $_SESSION['tmp_user_account']['login'],$_SESSION['tmp_user_account']['passwd'][0]);
841  }
842  $question .= $this->lng->txt('please_use_account');
843 
844  ilUtil::sendQuestion($question);
845 
846  if($_SESSION['tmp_transaction'] || ANONYMOUS_USER_ID == $ilUser->getId())
847  {
848  $this->newUserForm();
849  }
850  }
851  if(isset($_SESSION['download_links']))
852  {
853  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
854  $form = new ilPropertyFormGUI();
855  $form->setTitle($this->lng->txt('download'));
856 
857  foreach ($_SESSION['download_links'] as $link)
858  {
859  $form_item = new ilNonEditableValueGUI();
860  $form_item->setValue('<a href='.$link.'>'.$link.'</a>');
861  $form->addItem($form_item);
862  $this->tpl->setVariable('FORM', $form->getHTML());
863  }
864  $_SESSION['download_links'] = array();
865  }
866 /***/
867  if ($num_items == 0)
868  {
869  ilUtil::sendInfo($this->lng->txt('pay_shopping_cart_empty'));
870  return false;
871  }
872 /* else
873  {
874  //$_SESSION['currency_conversion']=null;
875  return true;
876  }
877  */
878 
879  }
880 
881  /* not used ?! */
882  public function setCoupon()
883  {
884  if ($_POST['coupon_code'] != '')
885  {
886  $coupon = $this->coupon_obj->getCouponByCode($_POST['coupon_code']);
887 
888  switch ($this->coupon_obj->checkCouponValidity())
889  {
890  case 1:
891  case 2:
892  ilUtil::sendInfo($this->lng->txt('paya_coupons_not_valid'));
893  $this->showItems();
894  return true;
895 
896  case 3:
897  ilUtil::sendInfo($this->lng->txt('paya_coupons_coupon_not_found'));
898  $this->showItems();
899  return true;
900  }
901 
902  $assignedItems = 0;
903  $this->psc_obj = new ilPaymentShoppingCart($this->user_obj);
904  if (count($items = $this->psc_obj->getEntries(isset($_POST['payment_type']) ? $_POST['payment_type'] : 'bmf')))
905  {
906  foreach($items as $item)
907  {
908  $tmp_pobject = new ilPaymentObject($this->user_obj,$item['pobject_id']);
909 
910  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
911  {
912  ++$assignedItems;
913  }
914  }
915  }
916  if (!$assignedItems)
917  {
918  ilUtil::sendInfo($this->lng->txt('paya_coupons_no_object_assigned'));
919  $this->showItems();
920  return true;
921  }
922 
923  $coupon_session_id = $_POST['payment_type'];
924 
925  if (!array_key_exists($coupon['pc_pk'], $_SESSION['coupons'][$coupon_session_id]))
926  {
927  if (is_array($_SESSION['coupons']))
928  {
929  foreach ($_SESSION['coupons'] as $key => $val)
930  {
931  unset($_SESSION['coupons'][$key][$coupon['pc_pk']]);
932  }
933  }
934  ilUtil::sendInfo($this->lng->txt('paya_coupons_coupon_added'));
935  $_SESSION['coupons'][$coupon_session_id][$coupon['pc_pk']] = $coupon;
936  }
937  else
938  {
939  ilUtil::sendInfo($this->lng->txt('paya_coupons_already_in_use'));
940  }
941 
942  $this->showItems();
943  return true;
944  }
945 
946  $this->showItems();
947  return true;
948  }
949 
950  public function removeCoupon()
951  {
952  if (is_array($_SESSION['coupons']))
953  {
954  foreach ($_SESSION['coupons'] as $key => $val)
955  {
956  unset($_SESSION['coupons'][$key][$_GET['coupon_id']]);
957  }
958  }
959 
960  $this->showItems();
961  return true;
962  }
963 /*
964  *
965  * @param string $payment_type pm_title
966  *
967  */
968  private function showCouponInput($payment_type = '')
969  {
970  include_once './Services/Payment/classes/class.ilGeneralSettings.php';
971  $genSet = new ilGeneralSettings();
972 
973  $tpl = new ilTemplate('tpl.pay_shopping_cart_coupons.html', true, true, 'Services/Payment');
974 
975  $tpl->setVariable('COUPON_FORMACTION', $this->ctrl->getFormAction($this));
976  $tpl->setVariable('TITLE', $this->lng->txt('paya_coupons_coupons'));
977  $tpl->setVariable('TYPE_IMG', ilUtil::getImagePath('icon_pays_b.gif'));
978  $tpl->setVariable('ALT_IMG', $this->lng->txt('obj_usr'));
979 
980  $tpl->setVariable('TXT_CODE', $this->lng->txt('paya_coupons_code'));
981  $tpl->setVariable('CMD_VALUE', $this->lng->txt('send'));
982 
983  $tpl->setVariable('PAYMENT_TYPE', $payment_type);
984 
985  $coupon_session = $payment_type;
986 
987  if (!empty($_SESSION['coupons'][$coupon_session]))
988  {
989  $i = 0;
990  foreach ($_SESSION['coupons'][$coupon_session] as $coupon)
991  {
992  $tpl->setCurrentBlock('loop');
993  $tpl->setVariable('LOOP_ROW', ilUtil::switchColor($i++, '1', '2'));
994  $tpl->setVariable('LOOP_TXT_COUPON', $this->lng->txt('paya_coupons_coupon'));
995  $tpl->setVariable('LOOP_CODE', $coupon['pcc_code']);
996  $this->ctrl->setParameter($this, 'coupon_id', $coupon['pc_pk']);
997  $this->ctrl->setParameter($this, 'payment_type', $_SESSION['bmf']['payment_type']);
998  $tpl->setVariable('LOOP_TITLE', $coupon['pc_title']);
999  if ($coupon['pc_description'] != '') $tpl->setVariable('LOOP_DESCRIPTION', nl2br($coupon['pc_description']));
1000  $tpl->setVariable("LOOP_TYPE", sprintf($this->lng->txt('paya_coupons_'.($coupon['pc_type'] == "fix" ? 'fix' : 'percentaged').'_'.(count($coupon['objects']) == 0 ? 'all' : 'selected').'_objects'),
1001  ($coupon['pc_value'] / round($coupon['pc_value'], 0) == 1 && $coupon['pc_type'] == "percent" ? round($coupon['pc_value'], 0) : number_format($coupon['pc_value'], 2, ',', '.')),
1002  ($coupon['pc_type'] == "percent" ? "%" :$genSet->get('currency_unit'))));
1003  $tpl->setVariable("LOOP_REMOVE", "<div class=\"il_ContainerItemCommands\" style=\"float: right;\"><a class=\"il_ContainerItemCommand\" href=\"".$this->ctrl->getLinkTarget($this, 'removeCoupon')."\">".$this->lng->txt('remove')."</a></div>");
1004 
1005  $tpl->parseCurrentBlock();
1006  }
1007  }
1008 
1009  return $tpl->get();
1010  }
1011 /*
1012  *
1013  * @param array $a_pay_method
1014  *
1015  */
1016  private function showItemsTable(&$a_tpl, $a_result_set, $a_pay_method = 0)
1017  {
1018  include_once './Services/Payment/classes/class.ilGeneralSettings.php';
1019  $genSet = new ilGeneralSettings();
1020 
1021  include_once './Services/Payment/classes/class.ilShoppingCartTableGUI.php';
1022 
1023  $tbl = new ilShoppingCartTableGUI($this);
1024  $tbl->setId('tbl_id_'.$a_pay_method);
1025  $tbl->setTitle($this->lng->txt('paya_shopping_cart').
1026  " (".$this->lng->txt('payment_system').": ".
1027  ilPayMethods::getStringByPaymethod($a_pay_method['pm_title']) .")");
1028 
1029  $coupon_session = $a_pay_method['pm_title'];
1030 
1031  $tbl->setRowTemplate("tpl.shop_shoppingcart_row.html", "Services/Payment");
1032  $tbl->addColumn('', 'item', '1%', true);
1033  $tbl->addColumn($this->lng->txt('title'), "table". $a_pay_method['pm_title']."_title", '30%');
1034  $tbl->addColumn($this->lng->txt('duration'), "table". $a_pay_method['pm_title']."_duration", '30%');
1035  $tbl->addColumn($this->lng->txt('vat_rate'), "table". $a_pay_method['pm_title']."_vat_rate", '15%');
1036  $tbl->addColumn($this->lng->txt('vat_unit'), "table". $a_pay_method['pm_title']."_vat_unit", '15%');
1037  $tbl->addColumn($this->lng->txt('price_a'), "table". $a_pay_method['pm_title']."_price", '10%');
1038 
1039  $tbl->setPrefix("table". $a_pay_method['pm_title']."_");
1040  $tbl->addMultiCommand('deleteItem', $this->lng->txt('delete'));
1041 
1042  // show total amount of costs
1043  $sc_obj = new ilPaymentShoppingCart($this->user_obj);
1044  $totalAmount = $sc_obj->getTotalAmount();
1045 
1046  if (!empty($_SESSION['coupons'][$coupon_session]))
1047  {
1048  if (count($items = $sc_obj->getEntries($a_pay_method['pm_id'])))
1049  {
1050  $tbl->setTotalData('TXT_SUB_TOTAL', $this->lng->txt('pay_bmf_subtotal_amount') . ": ");
1051  $tbl->setTotalData('VAL_SUB_TOTAL', number_format($totalAmount[$a_pay_method['pm_id']], 2, ',', '.') . " " . $genSet->get('currency_unit'));
1052 //TODO: CURRENCY #$tbl->setTotalData('VAL_SUB_TOTAL',ilPaymentPrices::_formatPriceToString($totalAmount[$a_pay_method['pm_id']], (int)$this->default_currency['currency_id'] ));
1053 
1054  foreach ($_SESSION['coupons'][$coupon_session] as $coupon)
1055  {
1056  $this->coupon_obj->setId($coupon['pc_pk']);
1057  $this->coupon_obj->setCurrentCoupon($coupon);
1058 
1059  $total_object_price = 0.0;
1060  $current_coupon_bonus = 0.0;
1061 
1062  foreach ($items as $item)
1063  {
1064  $tmp_pobject = new ilPaymentObject($this->user_obj, $item['pobject_id']);
1065 
1066  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
1067  {
1068  $price_data = ilPaymentPrices::_getPrice($item['price_id']);
1069  $price = (float) $price_data['price'];
1070 
1071  $total_object_price += $price;
1072  }
1073  unset($tmp_pobject);
1074  }
1075 
1076  $current_coupon_bonus = $this->coupon_obj->getCouponBonus($total_object_price);
1077  $totalAmount[$current_coupon_bonus] += $current_coupon_bonus * (-1);
1078  $tbl->setTotalData('TXT_COUPON_BONUS', $this->lng->txt('paya_coupons_coupon') . " " . $coupon['pcc_code'] . ": ");
1079  $tbl->setTotalData('VAL_COUPON_BONUS', number_format($current_coupon_bonus * (-1), 2, ',', '.') . " " . $genSet->get('currency_unit'));
1080  }
1081 
1082  if ($totalAmount[$a_pay_method['pm_id']] < 0)
1083  {
1084  $totalAmount[$a_pay_method['pm_id']] = 0;
1085  $this->totalVat = 0;
1086  }
1087  }
1088  }
1089 
1090  $this->totalAmount[$a_pay_method['pm_id']] = $totalAmount[$a_pay_method['pm_id']]-$current_coupon_bonus;
1091  $tbl->setTotalData('TXT_TOTAL_AMOUNT', $this->lng->txt('pay_bmf_total_amount').": ");
1092  $tbl->setTotalData('VAL_TOTAL_AMOUNT', number_format($this->totalAmount[$a_pay_method['pm_id']] , 2, ',', '.') . " " . $genSet->get('currency_unit')); #.$item['currency']);
1093 
1094  // TODO: CURRENCY
1095  #$currency_conversion_totalvat = (float)$_SESSION['currency_conversion'][$a_pay_method['pm_title']]['total_vat'];
1096  #if($currency_conversion_totalvat > 0) $this->totalVat = $currency_conversion_totalvat;
1097 
1098  if ($this->totalVat > 0)
1099  {
1100  $tbl->setTotalData('TXT_TOTAL_VAT', $this->lng->txt('pay_bmf_vat_included') . ": ");
1101  $tbl->setTotalData('VAL_TOTAL_VAT', number_format($this->totalVat , 2, ',', '.') . " " . $genSet->get('currency_unit'));
1102  }
1103 
1104  $tbl->setData($a_result_set);
1105  $a_tpl->setVariable('ITEMS_TABLE',$tbl->getCartHTML());
1106 
1107  return true;
1108  }
1109 
1110  public function deleteItem()
1111  {
1112  if(!count($_POST['item']))
1113  {
1114  ilUtil::sendInfo($this->lng->txt('pay_select_one_item'));
1115 
1116  $this->showItems();
1117  return true;
1118  }
1119  $this->initShoppingCartObject();
1120 
1121  foreach($_POST['item'] as $id)
1122  {
1123  $this->psc_obj->delete($id);
1124  $this->checkCouponsOfShoppingCart();
1125  }
1126  ilUtil::sendInfo($this->lng->txt('pay_deleted_items'));
1127  $this->showItems();
1128 
1129  return true;
1130  }
1131 
1132  private function initShoppingCartObject()
1133  {
1134  $this->psc_obj = new ilPaymentShoppingCart($this->user_obj);
1135  $this->psc_obj->clearCouponItemsSession();
1136  }
1137 
1138  private function initPaypalObject()
1139  {
1140  $this->paypal_obj = new ilPurchasePaypal($this->user_obj);
1141  }
1142 
1149  private function encryptButton($buttonParams)
1150  {
1151  $merchant_cert = $this->paypalConfig["vendor_cert"];
1152  $merchant_key = $this->paypalConfig["vendor_key"];
1153  $end_cert = $this->paypalConfig["enc_cert"];
1154 
1155  $tmpin_file = tempnam('/tmp', 'paypal_');
1156  $tmpout_file = tempnam('/tmp', 'paypal_');
1157  $tmpfinal_file = tempnam('/tmp', 'paypal_');
1158 
1159  $rawdata = array();
1160  $buttonParams['cert_id'] = $this->paypalConfig["cert_id"];
1161  foreach ($buttonParams as $name => $value) {
1162  $rawdata[] = "$name=$value";
1163  }
1164  $rawdata = implode("\n", $rawdata);
1165 
1166  $fp = fopen($tmpin_file, 'w');
1167  if (!$fp) {
1168  echo "Could not open temporary file '$tmpin_file')";
1169  return false;
1170 # return PayPal::raiseError("Could not open temporary file '$tmpin_file')");
1171  }
1172  fwrite($fp, $rawdata);
1173  fclose($fp);
1174 
1175  if (!@openssl_pkcs7_sign($tmpin_file, $tmpout_file, $merchant_cert,
1176  array($merchant_key, $this->paypalConfig["private_key_password"]),
1177  array(), PKCS7_BINARY)) {
1178  echo "Could not sign encrypted data: " . openssl_error_string();
1179  return false;
1180 # return PayPal::raiseError("Could not sign encrypted data: " . openssl_error_string());
1181  }
1182 
1183  $data = file_get_contents($tmpout_file);
1184  $data = explode("\n\n", $data);
1185  $data = $data[1];
1186  $data = base64_decode($data);
1187  $fp = fopen($tmpout_file, 'w');
1188  if (!$fp) {
1189  echo "Could not open temporary file '$tmpin_file')";
1190  return false;
1191 # return PayPal::raiseError("Could not open temporary file '$tmpin_file')");
1192  }
1193  fwrite($fp, $data);
1194  fclose($fp);
1195 
1196  if (!@openssl_pkcs7_encrypt($tmpout_file, $tmpfinal_file, $end_cert, array(), PKCS7_BINARY)) {
1197  echo "Could not encrypt data:" . openssl_error_string();
1198  return false;
1199 # return PayPal::raiseError("Could not encrypt data:" . openssl_error_string());
1200  }
1201 
1202  $encdata = @file_get_contents($tmpfinal_file, false);
1203  if (!$encdata) {
1204  echo "Encryption and signature of data failed.";
1205  return false;
1206 # return PayPal::raiseError("Encryption and signature of data failed.");
1207  }
1208 
1209  $encdata = explode("\n\n", $encdata);
1210  $encdata = trim(str_replace("\n", '', $encdata[1]));
1211  $encdata = "-----BEGIN PKCS7-----$encdata-----END PKCS7-----";
1212 
1213  @unlink($tmpfinal_file);
1214  @unlink($tmpin_file);
1215  @unlink($tmpout_file);
1216 
1217  return $encdata;
1218  }
1219 
1220  public function newUserForm()
1221  {
1222  global $tpl, $lng, $ilCtrl;
1223 
1224  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
1225 
1226  $form_2 = new ilPropertyFormGUI();
1227  $form_2->setFormAction($ilCtrl->getFormAction($this, 'validateNewUser'));
1228  $form_2->setTitle($lng->txt('login'));
1229  $form_2->setId('user_frm');
1230 
1231  $form_2->addCommandButton('validateNewUser',$lng->txt('save'));
1232 
1233  $formName = new ilTextInputGUI($lng->txt('login'), 'user_name');
1234  $formName->setValue($_SESSION['user_name']);
1235  $form_2->addItem($formName);
1236 
1237  $formPass = new ilPasswordInputGUI($lng->txt('password'), 'user_pass');
1238  $formPass->setRetype(false);
1239  $formPass->setValue($_SESSION['user_pass']);
1240  $form_2->addItem($formPass);
1241 
1242  $tpl->setVariable('USER_FORM',$form_2->getHTML());
1243  }
1244 
1245  public function validateNewUser()
1246  {
1247  global $tpl, $lng, $ilUser, $ilias;
1248 
1249  require_once 'Services/User/classes/class.ilObjUser.php';
1250  include_once './Services/Payment/classes/class.ilShopUtils.php';
1251 
1252  $obj_user = new ilObjUser();
1253  $user_id = ilObjUser::_lookupId($_POST['user_name']);
1254 
1255  $old_user_id = $_SESSION['tmp_transaction']['usr_id'];
1256  $transaction_extern = $_SESSION['tmp_transaction']['tx_id'];
1257 
1258  if($user_id != ANONYMOUS_USER_ID && $user_id != $old_user_id && $user_id != NULL)
1259  {
1260  $obj_user = new ilObjUser($user_id);
1261 
1262  if($obj_user->getPasswd() == md5($_POST["user_pass"]))
1263  {
1264  ilShopUtils::_assignTransactionToCustomerId($old_user_id, $user_id, $transaction_extern);
1265 
1266  // assign new_user_id to crs
1267  if($_SESSION['is_crs_object'] == true)
1268  {
1269  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
1270  foreach ($_SESSION['crs_obj_ids'] as $obj_id)
1271  {
1272  $members_obj = ilCourseParticipants::_getInstanceByObjId($obj_id);
1273  $members_obj->add($user_id,IL_CRS_MEMBER);
1274  }
1275  }
1276  //delete tmp_shop_user account
1277  if($obj =& $ilias->obj_factory->getInstanceByObjId($old_user_id))
1278  $obj->delete();
1279 
1280  $ilUser = new ilObjUser(ANONYMOUS_USER_ID);
1281  ilUtil::sendInfo(sprintf($lng->txt('user_name_accepted'),$_SESSION['tmp_user_account']['login']), true);
1282  unset($_SESSION['tmp_user_account']);
1283  }
1284  $this->showItems();
1285  return true;
1286  }
1287  else
1288  {
1289  ilUtil::sendFailure($lng->txt('pays_no_valid_username_given'));
1290  $this->showItems();
1291 
1292  return true;
1293  }
1294  }
1295 }
1296 ?>