ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjPaymentSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
19 require_once './Services/Object/classes/class.ilObjectGUI.php';
20 include_once './Services/Payment/classes/class.ilShopVatsList.php';
21 include_once './Services/Payment/classes/class.ilPaymentPrices.php';
22 include_once './Services/Payment/classes/class.ilPaymentObject.php';
23 include_once './Services/Payment/classes/class.ilFileDataShop.php';
24 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
25 include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
26 include_once './Services/Payment/classes/class.ilPaymentBookings.php';
27 include_once './Services/Payment/classes/class.ilPaymentSettings.php';
28 include_once './Services/Payment/classes/class.ilPaymentCurrency.php';
29 include_once './Services/Payment/classes/class.ilShopTableGUI.php';
30 include_once './Services/Payment/classes/class.ilInvoiceNumberPlaceholdersPropertyGUI.php';
31 include_once './Services/Payment/classes/class.ilUserDefinedInvoiceNumber.php';
32 include_once './Services/Search/classes/class.ilRepositorySearchGUI.php';
33 
35 {
36  const CONDITIONS_EDITOR_PAGE_ID = 99999997;
37 
40  public $user_obj = null;
41 
43  public $pobject = null;
47  public $genSetData = null;
48 
50 
51  public $error = false;
53  public $booking_obj = null;
54  public $form = null;
55 
56  public $ilErr = null;
60  public $vendors_obj = null;
61 
65  public $ctrl = null;
66 
70  public $tabs_gui = null;
71 
76  public function __construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output = true)
77  {
78  global $ilErr, $ilUser;
79 
80  $this->user_obj = $ilUser;
81  $this->ilErr = $ilErr;
82 
83  $this->pobject = new ilPaymentObject($this->user_obj);
84 
85  $this->genSetData = ilPaymentSettings::_getInstance();
86  $this->vendors_obj = ilPaymentVendors::getInstance();
87 
88  $this->type = 'pays';
89  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference,$a_prepare_output);
90 
91  $this->lng->loadLanguageModule('payment');
92  }
93 
94  public function checkShopActivationObject()
95  {
96 // check general settings
97  $check = $this->genSetData->get('currency_unit');
98  if($check == null)
99  {
100  ilUtil::sendInfo($this->lng->txt('please_enter_currency'));
101  return $this->generalSettingsObject();
102  }
103 
104  $check = $this->genSetData->get('address');
105  if($check == null)
106  {
107  ilUtil::sendInfo($this->lng->txt('please_enter_address'));
108  return $this->generalSettingsObject();
109  }
110 
111  $check = $this->genSetData->get('bank_data');
112  if($check == null)
113  {
114  ilUtil::sendInfo($this->lng->txt('please_enter_bank_data'));
115  return $this->generalSettingsObject();
116  }
117 
118  $check = $this->genSetData->get('pdf_path');
119  if($check == null)
120  {
121  ilUtil::sendInfo($this->lng->txt('please_enter_pdf_path'));
122  return $this->generalSettingsObject();
123  }
124 
125 // check paymethods
126  $pm_array = ilPaymethods::_getActivePaymethods();
127 
128  if(count($pm_array) == 0)
129  {
130  ilUtil::sendInfo($this->lng->txt('please_activate_one_paymethod'));
131  $this->payMethodsObject();
132  return false;
133  }
134 
135  foreach($pm_array as $paymethod)
136  {
137  switch($paymethod['pm_title'])
138  {
139  case 'bmf':
140  $check = unserialize($this->genSetData->get('bmf'));
141  if ($check['mandantNr'] == '' ||
142  $check['bewirtschafterNr'] == '' ||
143  $check['haushaltsstelle'] == '' ||
144  $check['objektNr'] == '' ||
145  $check['kennzeichenMahnverfahren'] == '' ||
146  $check['waehrungskennzeichen'] == '' ||
147  $check['ePaymentServer'] == '' ||
148  $check['clientCertificate'] == '' ||
149  $check['caCertificate'] == '' ||
150  $check['timeOut'] == '')
151  {
152  ilUtil::sendInfo($this->lng->txt('please_enter_bmf_data'));
153  $this->bmfSettingsObject();
154  return false;
155 
156  }
157  break;
158  case 'paypal':
159  $check = unserialize($this->genSetData->get('paypal'));
160  if ($check['server_host'] == '' ||
161  $check['server_path'] == '' ||
162  $check['vendor'] == '' ||
163  $check['auth_token'] == '')
164  {
165  ilUtil::sendInfo($this->lng->txt('please_enter_paypal_data'));
166  $this->paypalSettingsObject();
167  return false;
168  }
169  break;
170  case 'epay':
171 // $check = unserialize($this->genSetData->get('epay'));
172 // if ($check['server_host'] == '' ||
173 // $check['server_path'] == '' ||
174 // $check['merchant_number'] == '' ||
175 // $check['auth_token'] == '' ||
176 // $check['auth_email'] == '')
177 // {
178 // ilUtil::sendInfo($this->lng->txt('please_enter_epay_data'));
179 // $this->paypalSettingsObject();
180 // return true;
181 // }
182  break;
183  case 'erp':
184  break;
185  }
186  }
187 // check vats
188  include_once './Services/Payment/classes/class.ilShopVats.php';
189  $check= ilShopVats::_readAllVats();
190  if(count($check) == 0)
191  {
192  ilUtil::sendInfo($this->lng->txt('please_enter_vats'));
193  $this->vatsObject();
194  return false;
195  }
196 // check vendors
197  $vendors = $this->vendors_obj->getVendors();
198 
199  if(count($vendors) == 0)
200  {
201  ilUtil::sendInfo($this->lng->txt('please_create_vendor'));
202  $this->vendorsObject();
203  return false;
204  }
205 
206 // everything ok
207  ilUtil::sendInfo($this->lng->txt('shop_activation_ok'));
208  $this->generalSettingsObject();
209  return true;
210 
211  }
212 
213  public function executeCommand()
214  {
215  $next_class = $this->ctrl->getNextClass($this);
216  $cmd = $this->ctrl->getCmd();
217  $this->prepareOutput();
218 
219 /*
220  * shop activation guide
221  */
222 
227  global $ilToolbar;
228  $ilToolbar->addButton($this->lng->txt('check_shop_activation'),$this->ctrl->getLinkTarget($this,'checkShopActivation'));
229 
230  $this->getTabs($this->tabs_gui);
231 
232  switch($next_class)
233  {
234  case 'ilrepositorysearchgui':
235  include_once('./Services/Search/classes/class.ilRepositorySearchGUI.php');
236  $rep_search =& new ilRepositorySearchGUI();
237 
238  $rep_search->setCallback($this,
239  'addVendorObject', array()
240  );
241 
242  $this->ctrl->setReturn($this,'vendors');
243  $ret =& $this->ctrl->forwardCommand($rep_search);
244  break;
245 
246  case 'ilpermissiongui':
247  include_once('Services/AccessControl/classes/class.ilPermissionGUI.php');
248  $perm_gui = new ilPermissionGUI($this);
249  $ret = $this->ctrl->forwardCommand($perm_gui);
250  break;
251 
252  case 'ilshoppagegui':
253  if($cmd == 'TermsConditions')
254  {
255  $ret = $this->forwardToDocumentsPageObject(self::CONDITIONS_EDITOR_PAGE_ID);
256  $this->prepareOutput();
257  }
258  else
259  {
260  $ret = $this->forwardToPageObject();
261  }
262  if($ret != '')
263  {
264  $this->tpl->setContent($ret);
265  }
266  break;
267 
268  case 'ilshoptopicsgui':
269  include_once './Services/Payment/classes/class.ilShopTopicsGUI.php';
270  $topics_gui = new ilShopTopicsGUI($this);
271  $ret = $this->ctrl->forwardCommand($topics_gui);
272  break;
273 
274  default:
275  if ($cmd == '' || $cmd == 'view')
276  {
277  $cmd = 'generalSettings';
278  }
279  switch ($cmd)
280  {
281  // only needed for subtabs
282  case 'saveGeneralSettings' :
283  case 'generalSettings' :
284  $this->tabs_gui->setTabActive('settings');
285  $this->getSubTabs('settings', 'generalSettings');
286  break;
287  case 'payMethods':
288  case 'savePayMethods':
289  $this->tabs_gui->setTabActive('pay_methods');
290  $this->getSubTabs('payMethods', 'payMethods');
291  break;
292  case 'saveBmfSettings' :
293  case 'bmfSettings' : $this->tabs_gui->setTabActive('pay_methods');
294  $this->getSubTabs('payMethods', 'bmfSettings');
295  break;
296  case 'savePaypalSettings' :
297  case 'paypalSettings' :
298  $this->tabs_gui->setTabActive('pay_methods');
299  $this->getSubTabs('payMethods', 'paypalSettings');
300  break;
301  case 'saveEPaySettings' :
302  case 'epaySettings' :
303 // $this->tabs_gui->setTabActive('pay_methods');
304 // $this->getSubTabs('payMethods', 'epaySettings');
305  break;
306  case 'saveERPsettings' :
307  case 'delERPpreview':
308  case 'testERPsettings' :
309  case 'erpSettings' :
310 // $this->tabs_gui->setTabActive('payMethods');
311 // $this->getSubTabs('payMethods', 'erpSettings');
312  break;
313  case 'deleteVat' :
314  case 'newVat':
315  case 'insertVat':
316 
317  case 'updateVat':
318  case 'performDeleteVat':
319  case 'confirmDeleteVat':
320  case 'createVat':
321  case 'saveVat':
322  case 'editVat':
323  case 'vats' : $this->tabs_gui->setTabActive('vats');
324  break;
325 
326 
327 #TODO: CURRENCY not finished yet
328  case 'addCurrency':
329  case 'currencies':
330  # case 'performDeleteCurrency':
331  case 'updateCurrency':
332  # if($_POST['action'] == 'editCurrency' || $_POST['action'] == 'deleteCurrency')
333  # $cmd = $_POST['action'];
334  $this->tabs_gui->setTabActive('currencies');
335  break;
336 
337  case 'StatutoryRegulations':
338  case 'saveStatutoryRegulations':
339  $this->active_sub_tab = 'statutory_regulations';
340  $this->tabs_gui->setTabActive('documents');
341  $this->getSubTabs('documents', 'statutory_regulations');
342  break;
343  case 'TermsConditions':
344  case 'documents':
345  $this->active_sub_tab = 'terms_conditions';
346  $this->tabs_gui->setTabActive('documents');
347  $this->getSubTabs('documents', 'terms_conditions');
348 
349  $cmd = 'TermsConditions';
350  break;
351  case 'BillingMail':
352  case 'saveBillingMail':
353  $this->active_sub_tab = 'billing_mail';
354  $this->tabs_gui->setTabActive('documents');
355  $this->getSubTabs('documents', 'billing_mail');
356 
357  # $cmd = 'BillingMail';
358  break;
359  case 'InvoiceNumber':
360  case 'saveInvoiceNumber':
361  $this->active_sub_tab = 'invoice_number';
362  $this->tabs_gui->setTabActive('documents');
363  $this->getSubTabs('documents', 'invoice_number');
364 
365  #$cmd = 'InvoiceNumber';
366  break;
367  case 'checkShopActivation':
368  break;
369  }
370  $cmd .= 'Object';
371 
372  $this->$cmd();
373 
374  break;
375  }
376  return true;
377  }
378 
379  public function forwardToPageObject()
380  {
384  global $ilTabs;
385 
386  if(isset($_GET['pobject_id']) && $_GET['pobject_id'] > 0)
387  {
388  $this->ctrl->setParameter($this, 'pobject_id', (int)$_GET['pobject_id']);
389  $this->__initPaymentObject((int)$_GET['pobject_id']);
390  $this->lng->loadLanguageModule('content');
391 
392  $ilTabs->clearTargets();
393  $ilTabs->clearSubTabs();
394  $ilTabs->setBackTarget($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'editDetails'));
395 
396  include_once 'Services/Payment/classes/class.ilShopPage.php';
397  include_once 'Services/Payment/classes/class.ilShopPageGUI.php';
398  include_once('./Services/Style/classes/class.ilObjStyleSheet.php');
399 
400  $this->tpl->setVariable('LOCATION_CONTENT_STYLESHEET', ilObjStyleSheet::getContentStylePath(0));
401 
402  if(!ilShopPage::_exists('shop', (int)$this->pobject->getPobjectId()))
403  {
404  // doesn't exist -> create new one
405  $new_page_object = new ilShopPage();
406  $new_page_object->setParentId(0);
407  $new_page_object->setId($this->pobject->getPobjectId());
408  $new_page_object->createFromXML();
409  }
410 
411  $this->ctrl->setReturnByClass('ilshoppagegui', 'edit');
412 
413  if(!(int)$_GET['pobject_id'])
414  {
415  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
416  return $this->objectsObject();
417  }
418  $this->ctrl->setParameter($this, 'pobject_id', (int)$_GET['pobject_id']);
419  $this->__initPaymentObject((int)$_GET['pobject_id']);
420 
421  $page_gui = new ilShopPageGUI((int)$this->pobject->getPobjectId());
422  $this->ctrl->setParameter($page_gui, 'pobject_id', (int)$_GET['pobject_id']);
423  }
424  else
425  {
430  global $lng, $ilCtrl;
431 
432  $ilTabs->clearTargets();
433  $ilTabs->setBackTarget($lng->txt('back'), $this->ctrl->getLinkTarget($this), '_top');
434 
435  // page object
436  include_once 'Services/Payment/classes/class.ilShopPage.php';
437  include_once 'Services/Payment/classes/class.ilShopPageGUI.php';
438 
439  $lng->loadLanguageModule('content');
440 
441  include_once('./Services/Style/classes/class.ilObjStyleSheet.php');
442  $this->tpl->setVariable('LOCATION_CONTENT_STYLESHEET', ilObjStyleSheet::getContentStylePath(0));
443 
444  if(!ilShopPage::_exists('shop', self::CONDITIONS_EDITOR_PAGE_ID))
445  {
446  // doesn't exist -> create new one
447  $new_page_object = new ilShopPage();
448  $new_page_object->setParentId(0);
449  $new_page_object->setId(self::CONDITIONS_EDITOR_PAGE_ID);
450  $new_page_object->createFromXML();
451  }
452 
453  $this->ctrl->setReturnByClass('ilshoppagegui', 'edit');
454 
455  $page_gui = new ilShopPageGUI(self::CONDITIONS_EDITOR_PAGE_ID);
456  }
457 
458  return $this->ctrl->forwardCommand($page_gui);
459  }
460 
461  public function saveBmfSettingsObject()
462  {
466  global $rbacsystem;
467 
468  // MINIMUM ACCESS LEVEL = 'read'
469  if(!$rbacsystem->checkAccess('read', $this->object->getRefId()))
470  {
471  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$this->ilErr->MESSAGE);
472  }
473 
474  include_once './Services/Payment/classes/class.ilBMFSettings.php';
475 
476  $this->error = '';
480  $bmfSetObj = ilBMFSettings::getInstance();
481 
482  $bmfSetObj->setClientId(ilUtil::stripSlashes($_POST['mandantNr']));
483  $bmfSetObj->setBewirtschafterNr(ilUtil::stripSlashes($_POST['bewirtschafterNr']));
484  $bmfSetObj->setHaushaltsstelle(ilUtil::stripSlashes($_POST['haushaltsstelle']));
485  $bmfSetObj->setObjectId(ilUtil::stripSlashes($_POST['objektNr']));
486  $bmfSetObj->setKennzeichenMahnverfahren(ilUtil::stripSlashes($_POST['kennzeichenMahnverfahren']));
487  $bmfSetObj->setWaehrungsKennzeichen(ilUtil::stripSlashes($_POST['waehrungskennzeichen']));
488  $bmfSetObj->setEpaymentServer(ilUtil::stripSlashes($_POST['ePaymentServer']));
489  $bmfSetObj->setClientCertificate(ilUtil::stripSlashes($_POST['clientCertificate']));
490  $bmfSetObj->setCaCertificate(ilUtil::stripSlashes($_POST['caCertificate']));
491  $bmfSetObj->setTimeout(ilUtil::stripSlashes($_POST['timeOut']));
492 
493  if ($_POST['mandantNr'] == '' ||
494  $_POST['bewirtschafterNr'] == '' ||
495  $_POST['haushaltsstelle'] == '' ||
496  $_POST['objektNr'] == '' ||
497  $_POST['kennzeichenMahnverfahren'] == '' ||
498  $_POST['waehrungskennzeichen'] == '' ||
499  $_POST['ePaymentServer'] == '' ||
500  $_POST['clientCertificate'] == '' ||
501  $_POST['caCertificate'] == '' ||
502  $_POST['timeOut'] == '')
503  {
504  $this->error = $this->lng->txt('pays_bmf_settings_not_valid');
505  ilUtil::sendFailure($this->error);
506  $this->bmfSettingsObject();
507  return true;
508  }
509 
510  $bmfSetObj->save();
511 
512  $this->bmfSettingsObject();
513 
514  ilUtil::sendSuccess($this->lng->txt('pays_updated_bmf_settings'));
515 
516  return true;
517  }
518 
519  public function bmfSettingsObject()
520  {
524  global $rbacsystem;
525 
526  // MINIMUM ACCESS LEVEL = 'read'
527  if(!$rbacsystem->checkAccess('read', $this->object->getRefId()))
528  {
529  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$this->ilErr->MESSAGE);
530  }
531  include_once './Services/Payment/classes/class.ilBMFSettings.php';
532 
533 
534  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.main_view.html','Services/Payment');
535 
539  $bmfSetObj = ilBMFSettings::getInstance();
540 
541  $form = new ilPropertyFormGUI();
542  $form->setFormAction($this->ctrl->getFormAction($this, 'saveBmfSettings'));
543  $form->setTitle($this->lng->txt('pays_bmf_settings'));
544 
545  $form->addCommandButton('saveBmfSettings',$this->lng->txt('save'));
546 
547  $formItem = new ilTextInputGUI($this->lng->txt('pays_bmf_client_id'), 'mandantNr');
548  $formItem->setValue($bmfSetObj->getClientId());
549  $form->addItem($formItem);
550 
551  $formItem = new ilTextInputGUI($this->lng->txt('pays_bmf_bewirtschafter_nr'), 'bewirtschafterNr');
552  $formItem->setValue($bmfSetObj->getBewirtschafterNr());
553  $form->addItem($formItem);
554 
555  $formItem = new ilTextInputGUI($this->lng->txt('pays_bmf_haushaltsstelle'), 'haushaltsstelle');
556  $formItem->setValue($bmfSetObj->getHaushaltsstelle());
557  $form->addItem($formItem);
558 
559  $formItem = new ilTextInputGUI($this->lng->txt('pays_bmf_object_id'), 'objektNr');
560  $formItem->setValue($bmfSetObj->getObjectId());
561  $form->addItem($formItem);
562 
563  $formItem = new ilTextInputGUI($this->lng->txt('pays_bmf_kennzeichen_mahnverfahren'), 'kennzeichenMahnverfahren');
564  $formItem->setValue($bmfSetObj->getKennzeichenMahnverfahren());
565  $form->addItem($formItem);
566 
567  $formItem = new ilTextInputGUI($this->lng->txt('pays_bmf_waehrungskennzeichen'), 'waehrungskennzeichen');
568  $formItem->setValue($bmfSetObj->getWaehrungsKennzeichen());
569  $form->addItem($formItem);
570 
571  $formItem = new ilTextInputGUI($this->lng->txt('pays_bmf_epayment_server'), 'ePaymentServer');
572  $formItem->setValue($bmfSetObj->getEpaymentServer());
573  $form->addItem($formItem);
574 
575  $formItem = new ilTextInputGUI($this->lng->txt('pays_bmf_client_certificate'), 'clientCertificate');
576  $formItem->setValue($bmfSetObj->getClientCertificate());
577  $form->addItem($formItem);
578 
579  $formItem = new ilTextInputGUI($this->lng->txt('pays_bmf_ca_certificate'), 'caCertificate');
580  $formItem->setValue($bmfSetObj->getCaCertificate());
581  $form->addItem($formItem);
582 
583  $formItem = new ilTextInputGUI($this->lng->txt('pays_bmf_timeout'), 'timeOut');
584  $formItem->setValue($bmfSetObj->getTimeOut());
585  $form->addItem($formItem);
586 
587  $this->tpl->setVariable('FORM',$form->getHTML());
588  return true;
589  }
590 
591 
592  public function updateDetailsObject()
593  {
594  if(!$_GET['pobject_id'])
595  {
596  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
597 
598  $this->objectObjects();
599  return true;
600  }
601 
602  $this->__initPaymentObject((int) $_GET['pobject_id']);
603  $this->ctrl->setParameter($this,'pobject_id',(int) $_GET['pobject_id']);
604 
605  // read old settings
606  $old_status = $this->pobject->getStatus();
607 
608  // check status changed from not_buyable
609  if($old_status == $this->pobject->STATUS_NOT_BUYABLE and
610  (int) $_POST['status'] != $old_status)
611  {
612  // check pay_method edited
613  switch((int) $_POST['pay_method'])
614  {
615  case $this->pobject->PAY_METHOD_NOT_SPECIFIED:
616  ilUtil::sendInfo($this->lng->txt('paya_select_pay_method_first'));
617  $this->editDetailsObject();
618 
619  return false;
620  default:
621  ;
622  }
623  // check minimum one price
624  $prices_obj = new ilPaymentPrices((int) $_GET['pobject_id']);
625  $standard_prices = array();
626  $standard_prices = $prices_obj->getPrices();
627 
628  if(!count($standard_prices))
629  {
630  ilUtil::sendInfo($this->lng->txt('paya_edit_prices_first'));
631  $this->editDetailsObject();
632 
633  return false;
634  }
635  }
636 
637  $this->pobject->setStatus((int) $_POST['status']);
638  $this->pobject->setVendorId((int) $_POST['vendor']);
639  $this->pobject->setPayMethod((int) $_POST['pay_method']);
640  $this->pobject->setTopicId((int) $_POST['topic_id']);
641  $this->pobject->setVatId((int) $_POST['vat_id']);
642 
643  $this->pobject->update();
644 
645  ilUtil::sendInfo($this->lng->txt('paya_details_updated'));
646  $this->editDetailsObject();
647 
648  return true;
649  }
650 
651  public function editPricesObject($a_show_delete = false)
652  {
656  global $ilToolbar;
657 
658  if($a_show_delete == false) unset($_SESSION['price_ids']);
659 
660  $_SESSION['price_ids'] = $_SESSION['price_ids'] ? $_SESSION['price_ids'] : array();
661 
662  if(!$_GET['pobject_id'])
663  {
664  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
665 
666  $this->objectsObject();
667  return true;
668  }
669  $this->ctrl->setParameter($this,'pobject_id',(int) $_GET['pobject_id']);
670 
671  $ilToolbar->addButton($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'objects'));
672  $ilToolbar->addButton($this->lng->txt('paya_edit_details'), $this->ctrl->getLinkTarget($this, 'editDetails'));
673  $ilToolbar->addButton($this->lng->txt('paya_edit_prices'), $this->ctrl->getLinkTarget($this, 'editPrices'));
674  $ilToolbar->addButton($this->lng->txt('pay_edit_abstract'), $this->ctrl->getLinkTargetByClass(array('ilshoppagegui'), 'edit'));
675 
676  $this->__initPaymentObject((int) $_GET['pobject_id']);
677 
678  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
679 
680  $price_obj = new ilPaymentPrices((int) $_GET['pobject_id']);
681  $standard_prices = array();
682  $extension_prices = array();
683  $standard_prices = $price_obj->getPrices();
684  $extension_prices = $price_obj->getExtensionPrices();
685 
686  $prices = array_merge($standard_prices, $extension_prices );
687 
688 
689  // No prices created
690  if(!count($prices))
691  {
692  ilUtil::sendInfo($this->lng->txt('paya_no_price_available'));
693  $ilToolbar->addButton($this->lng->txt('paya_add_price'), $this->ctrl->getLinkTarget($this, 'addPrice'));
694 
695  return true;
696  }
697  // Show confirm delete
698  if($a_show_delete)
699  {
700  $oConfirmationGUI = new ilConfirmationGUI();
701 
702  // set confirm/cancel commands
703  $oConfirmationGUI->setFormAction($this->ctrl->getFormAction($this,"performDeletePrice"));
704  $oConfirmationGUI->setHeaderText($this->lng->txt("paya_sure_delete_selected_prices"));
705  $oConfirmationGUI->setCancel($this->lng->txt("cancel"), "editPrices");
706  $oConfirmationGUI->setConfirm($this->lng->txt("confirm"), "performDeletePrice");
707 
708  foreach($prices as $price)
709  {
710  $delete_row = '';
711  $tmp_price = '';
712 
713  if(in_array($price['price_id'],$_SESSION['price_ids']))
714  {
715  switch($price['price_type'])
716  {
718  include_once './Services/Calendar/classes/class.ilDatePresentation.php';
719  $tmp_price = ilDatePresentation::formatDate(new ilDate($price['duration_from'], IL_CAL_DATE))
720  .' - '.ilDatePresentation::formatDate(new ilDate($price['duration_until'], IL_CAL_DATE));
721  break;
722 
724  $tmp_price = $price['duration'].' '.$this->lng->txt('paya_months');
725  break;
726 
728  $tmp_price = $this->lng->txt('unlimited_duration');
729  break;
730  }
731 
732  $delete_row .= ''.$tmp_price.' -> '.
733  ilFormat::_getLocalMoneyFormat($price['price']).' '.
734  $this->genSetData->get('currency_unit');
735 
736  $oConfirmationGUI->addItem('',$delete_row, $delete_row);
737  }
738  }
739 
740  $this->tpl->setVariable('CONFIRMATION', $oConfirmationGUI->getHTML());
741 
742  return true;
743  }
744 
745  // Fill table cells
749  $tpl = new ilTemplate('tpl.table.html',true,true);
750 
751  // set table header
752  $tpl->setCurrentBlock('tbl_form_header');
753 
754  $tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this));
755  $tpl->parseCurrentBlock();
756 
757  $counter = 0;
758  $data = array();
759  foreach($prices as $price)
760  {
761  $data[$counter]['price_id'] = ilUtil::formCheckBox(in_array($price['price_id'],$_SESSION['price_ids']) ? 1 : 0,
762  'price_ids[]', $price['price_id']);
763 
764  switch($price['price_type'])
765  {
767  $data[$counter]['duration'] = $price['duration'].' '.$this->lng->txt('paya_months');
768  break;
770 
771  $data[$counter]['duration'] = ilDatePresentation::formatDate(new ilDate($price['duration_from'], IL_CAL_DATE))
772  .' - '.ilDatePresentation::formatDate(new ilDate($price['duration_until'],IL_CAL_DATE));
773  break;
775  $data[$counter]['duration'] = $this->lng->txt('unlimited_duration');
776  break;
777  }
778  $data[$counter]['price'] = ilFormat::_getLocalMoneyFormat($price['price']);
779  $data[$counter]['currency_unit'] = $this->genSetData->get('currency_unit');
780  $data[$counter]['extension'] = ilUtil::formCheckBox($price['extension'] ? 1 : 0,
781  'extension_ids[]', (int)$price['price_id'], true);
782 
783  $this->ctrl->setParameter($this,"price_id",$price['price_id']);
784  $data[$counter]['edit'] =
785  "<div class=\"il_ContainerItemCommands\"><a class=\"il_ContainerItemCommand\" href=\"".$this->ctrl->getLinkTarget($this,"editPrice")."\">".$this->lng->txt("edit")."</a></div>";
786 
787  ++$counter;
788  }
789  $this->__editPricesTable($data);
790 
791  return true;
792  }
793 
794  private function __editPricesTable($a_result_set)
795  {
796  $this->ctrl->setParameter($this, 'cmd', 'editprices');
797  $tbl = new ilShopTableGUI($this);
798 
799  $tmp_obj = ilObjectFactory::getInstanceByRefId($this->pobject->getRefId(), false);
800  if($tmp_obj)
801  {
802  $tbl->setTitle($tmp_obj->getTitle());
803  }
804  else
805  {
806  $tbl->setTitle($this->lng->txt('object_not_found'));
807  }
808 
809  $tbl->setId('tbl_bookings');
810  $tbl->setRowTemplate("tpl.shop_prices_row.html", "Services/Payment");
811 
812  $tbl->addColumn(' ', 'price_id', '5%');
813  $tbl->addColumn($this->lng->txt('duration'), 'duration', '40%');
814  $tbl->addColumn($this->lng->txt('price_a'), 'price', '1%');
815  $tbl->addColumn($this->lng->txt('currency'), 'currency_unit', '10%');
816  $tbl->addColumn($this->lng->txt('extension_price'), 'extension', '10%');
817  $tbl->addColumn('', 'edit', '30%' );
818 
819  $tbl->setSelectAllCheckbox('price_id');
820  $tbl->addCommandButton('addPrice',$this->lng->txt('paya_add_price'));
821 
822  $tbl->addMultiCommand("deletePrice", $this->lng->txt("paya_delete_price"));
823  $tbl->fillFooter();
824 
825  $tbl->setData($a_result_set);
826 
827  $this->tpl->setVariable('TABLE', $tbl->getHTML());
828 
829  return true;
830  }
831 
832  public function addPriceObject()
833  {
837  global $ilToolbar;
838 
839  if(!$_GET['pobject_id'])
840  {
841  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
842 
843  $this->objectsObject();
844  return true;
845  }
850 
851  $this->ctrl->setParameter($this,'pobject_id',(int) $_GET['pobject_id']);
852 
853  $this->__initPaymentObject((int) $_GET['pobject_id']);
854 
855  $ilToolbar->addButton($this->lng->txt('paya_edit_details'), $this->ctrl->getLinkTarget($this, 'editDetails'));
856  $ilToolbar->addButton($this->lng->txt('paya_edit_prices'), $this->ctrl->getLinkTarget($this, 'editPrices'));
857  $ilToolbar->addButton($this->lng->txt('pay_edit_abstract'), $this->ctrl->getLinkTargetByClass(array('ilshoppagegui'), 'edit'));
858 
859  $tmp_obj = ilObjectFactory::getInstanceByRefId($this->pobject->getRefId(), false);
860  if(is_object($tmp_obj))
861  {
862  $tmp_object['title'] = $tmp_obj->getTitle();
863  }
864  else
865  {
866  $tmp_object['title'] = $this->lng->txt('object_not_found');
867  }
868  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
869 
870  $form = new ilPropertyFormGUI();
871  $form->setFormAction($this->ctrl->getFormAction($this));
872  $form->setTitle($this->lng->txt('paya_add_price_title'));
873 
874  // object_title
875  $oTitle = new ilNonEditableValueGUI($this->lng->txt('title'));
876 
877  $oTitle->setValue($tmp_object['title']);
878  $form->addItem($oTitle);
879 
880  //price_type
881 
882  $radio_group = new ilRadioGroupInputGUI('','price_type');
883  $radio_group->setTitle($this->lng->txt('duration'));
884  $radio_group->setRequired(true);
885  $radio_group->setValue($_POST['price_type']);
886  $radio_group->setPostVar('price_type');
887 
888  $radio_option_1 = new ilRadioOption($this->lng->txt('duration_month'), 'duration_month');
889 
890  // duration month
891  $oDuration = new ilNumberInputGUI();
892  $oDuration->setTitle($this->lng->txt('paya_months'));
893  $oDuration->setSize('30%');
894  $oDuration->setValue($_POST['duration_month']);
895  $oDuration->setPostVar('duration_month');
896  $radio_option_1->addSubItem($oDuration);
897 
898  $radio_group->addOption($radio_option_1);
899 
900  $radio_option_3 = new ilRadioOption($this->lng->txt('duration_date'), 'duration_date');
901 
902  // duration_date from
903  $o_date_from = new ilDateTimeInputGUI();
904  $o_date_from->setTitle($this->lng->txt('cal_from'));
905  $o_date_from->setPostVar('duration_date_from');
906  $radio_option_3->addSubItem($o_date_from);
907 
908  // duration_date until
909  $o_date_until = new ilDateTimeInputGUI();
910  $o_date_until->setTitle($this->lng->txt('cal_until'));
911  $o_date_until->setPostVar('duration_date_until');
912  $radio_option_3->addSubItem($o_date_until);
913 
914  $radio_group->addOption($radio_option_3);
915 
916  $radio_option_2 = new ilRadioOption($this->lng->txt('unlimited_duration'), 'unlimited_duration');
917  $radio_group->addOption($radio_option_2);
918 
919  $form->addItem($radio_group);
920 
921  // description
922  $oDescription = new ilTextAreaInputGUI($this->lng->txt('description'), 'description');
923  $oDescription->setRows(4);
924  $oDescription->setCols(35);
925  $oDescription->setValue($_POST['description']);
926  $form->addItem($oDescription);
927 
928  // price
929  $oPrice = new ilNumberInputGUI();
930  $oPrice->setTitle($this->lng->txt('price_a'));
931  $oPrice->setValue($_POST['price']);
932  $oPrice->setPostVar('price');
933  $oPrice->setRequired(true);
934  $oPrice->allowDecimals(true);
935  $form->addItem($oPrice);
936 
937  // currency
938  // TODO show curency selector
939 
940 #TODO: CURRENCY not finished yet
941 /* $objCurrency = new ilPaymentCurrency();
942  $currencies = $objCurrency->_getAvailableCurrencies();
943 
944  foreach($currencies as $currency)
945  {
946  $currency_options[$currency['currency_id']] = $currency['unit'];
947  }
948 
949 
950  $oCurrency = new ilSelectInputGUI($this->lng->txt('currency'), 'currency_id');
951  $oCurrency->setOptions($currency_options);
952 
953  $oCurrency->setValue($_SESSION['pay_objects']['currency_value']);
954  $oCurrency->setPostVar('currency_id');
955  /**/
956  $currency_options = $genSet->get('currency_unit');
957  $oCurrency = new ilNonEditableValueGUI($this->lng->txt('currency'));
958  $oCurrency->setValue($currency_options);
959  $form->addItem($oCurrency);
960 
961 
962  //extension
963  $oExtension = new ilCheckboxInputGUI($this->lng->txt('extension_price'), 'extension');
964  $oExtension->setChecked((int)$_POST['extension']);
965 
966  $form->addItem($oExtension);
967 
968  $form->addCommandButton('performAddPrice',$this->lng->txt('paya_add_price'));
969  $form->addCommandButton('editPrices', $this->lng->txt('cancel'));
970  $this->tpl->setVariable('FORM',$form->getHTML());
971 
972  return true;
973  }
974 
975  public function performAddPriceObject()
976  {
977  $po = new ilPaymentPrices((int)$_GET['pobject_id']);
978 
979  switch($_POST['price_type'])
980  {
981  case 'unlimited_duration':
983  $po->setDuration(0);
984  $po->setDurationFrom(NULL);
985  $po->setDurationUntil(NULL);
986  $po->setUnlimitedDuration(1);
987 
988  break;
989 
990  case 'duration_date':
991 
993  $po->setDuration(NULL);
994  $po->setDurationFrom(ilUtil::stripSlashes(
995  $_POST['duration_date_from']['date']['y'].'-'.
996  $_POST['duration_date_from']['date']['m'].'-'.
997  $_POST['duration_date_from']['date']['d']));
998  $po->setDurationUntil(ilUtil::stripSlashes(
999  $_POST['duration_date_until']['date']['y'].'-'.
1000  $_POST['duration_date_until']['date']['m'].'-'.
1001  $_POST['duration_date_until']['date']['d']));
1002  break;
1003 
1004  default:
1005  case 'duration_month':
1007  $po->setDuration($_POST['duration_month']);
1008  $po->setDurationFrom(NULL);
1009  $po->setDurationUntil(NULL);
1010  break;
1011  }
1012 
1013  $po->setDescription($_POST['description'] ? ilUtil::stripSlashes($_POST['description']) : NULL);
1014  $po->setPrice(ilUtil::stripSlashes($_POST['price']));
1015 // $po->setCurrency($currency[1]['currency_id']);
1016 
1017  if($_POST['extension_price'])
1018  {
1019  $po->setExtension(1);
1020  }
1021  else
1022  {
1023  $po->setExtension(0);
1024  }
1025 
1026  try
1027  {
1028  $po->validate();
1029  $po->add();
1030  ilUtil::sendInfo($this->lng->txt('paya_added_new_price'));
1031  return $this->editPricesObject();
1032  }
1033  catch(ilShopException $e)
1034  {
1035  ilUtil::sendInfo($e->getMessage());
1036  return $this->addPriceObject();
1037  }
1038  }
1039 
1040  public function performDeletePriceObject()
1041  {
1042  if(!$_GET['pobject_id'])
1043  {
1044  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
1045 
1046  $this->objectsObject();
1047  return true;
1048  }
1049 
1050  if(!count($_SESSION['price_ids']))
1051  {
1052  ilUtil::sendInfo($this->lng->txt('paya_no_prices_selected'));
1053 
1054  $this->editPriceObject();
1055  return true;
1056  }
1057 
1058  $prices = new ilPaymentPrices((int) $_GET['pobject_id']);
1059 
1060  foreach($_SESSION['price_ids'] as $price_id)
1061  {
1062  if($prices->delete($price_id))
1063  ilUtil::sendInfo($this->lng->txt('paya_deleted_selected_prices'));
1064 
1065  }
1066 
1067  // check if it was last price otherwise set status to 'not_buyable'
1068  if(!count($prices->getPrices()))
1069  {
1070  $this->__initPaymentObject((int) $_GET['pobject_id']);
1071 
1072  $this->pobject->setStatus($this->pobject->STATUS_NOT_BUYABLE);
1073  $this->pobject->update();
1074 
1075  ilUtil::sendInfo($this->lng->txt('paya_deleted_last_price'));
1076  }
1077  unset($prices);
1078  unset($_SESSION['price_ids']);
1079 
1080  return $this->editPricesObject();
1081  }
1082 
1083  public function deletePriceObject()
1084  {
1085  if(!$_GET['pobject_id'])
1086  {
1087  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
1088 
1089  $this->objectsObject();
1090  return true;
1091  }
1092 
1093  if(!count($_POST['price_ids']))
1094  {
1095  ilUtil::sendInfo($this->lng->txt('paya_no_prices_selected'));
1096 
1097  $this->editPricesObject();
1098  return true;
1099  }
1100  $_SESSION['price_ids'] = $_POST['price_ids'];
1101 
1102  $this->editPricesObject(true);
1103  return true;
1104  }
1105 
1106  public function updatePriceObject()
1107  {
1108  if(!$_GET['pobject_id'] && !$_POST['pobject_id'])
1109  {
1110  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
1111 
1112  $this->objectsObject();
1113  return true;
1114  }
1115  if(isset($_GET['pobject_id']))
1116  {
1117  $pobject_id = (int)$_GET['pobject_id'];
1118  }
1119  else
1120  {
1121  $pobject_id = (int)$_POST['pobject_id'];
1122  }
1123 
1124  if(!(int)$_GET['price_id'] && !$_POST['price_id'])
1125  {
1126  ilUtil::sendInfo($this->lng->txt('payment_no_price_selected'));
1127  return $this->editPricesObject();
1128  }
1129  if(isset($_GET['price_id']))
1130  {
1131  $price_id = (int)$_GET['price_id'];
1132  }
1133  else
1134  {
1135  $price_id = (int)$_POST['price_id'];
1136  }
1137 
1138  $po = new ilPaymentPrices((int)$pobject_id);
1139  switch($_POST['price_type'])
1140  {
1143  $po->setDuration(NULL);
1144  $po->setDurationFrom(NULL);
1145  $po->setDurationUntil(NULL);
1146  $po->setUnlimitedDuration(1);
1147 
1148  break;
1149 
1152  $po->setDuration(NULL);
1153  $po->setDurationFrom(ilUtil::stripSlashes(
1154  $_POST['duration_date_from']['date']['y'].'-'.
1155  $_POST['duration_date_from']['date']['m'].'-'.
1156  $_POST['duration_date_from']['date']['d']));
1157  $po->setDurationUntil(ilUtil::stripSlashes(
1158  $_POST['duration_date_until']['date']['y'].'-'.
1159  $_POST['duration_date_until']['date']['m'].'-'.
1160  $_POST['duration_date_until']['date']['d']));
1161  break;
1162 
1163  default:
1166  $po->setDuration($_POST['duration_month']);
1167  $po->setDurationFrom(NULL);
1168  $po->setDurationUntil(NULL);
1169  break;
1170  }
1171 
1172  $po->setDescription($_POST['description'] ? ilUtil::stripSlashes($_POST['description']) : NULL);
1173  $po->setPrice(ilUtil::stripSlashes($_POST['price']));
1174  $po->setCurrency(ilUtil::stripSlashes($_POST['currency']));
1175  if($_POST['extension_price'])
1176  {
1177  $po->setExtension(1);
1178  }
1179  else
1180  {
1181  $po->setExtension(0);
1182  }
1183  try
1184  {
1185  $po->validate();
1186  $po->update($price_id);
1187  ilUtil::sendInfo($this->lng->txt('paya_updated_price'));
1188  return $this->editPricesObject();
1189  }
1190  catch(ilShopException $e)
1191  {
1192  ilUtil::sendInfo($e->getMessage());
1193  $this->editPriceObject();
1194  return true;
1195  }
1196  }
1197 
1198  public function editDetailsObject($a_show_confirm = false)
1199  {
1200  global $ilToolbar;
1201 
1202  if(!(int)$_GET['pobject_id'])
1203  {
1204  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
1205  return $this->objectsObject();
1206  }
1207 
1208  $this->__initPaymentObject((int)$_GET['pobject_id']);
1209 
1210  $this->ctrl->setParameter($this,'pobject_id', (int)$_GET['pobject_id']);
1211 
1212  $ilToolbar->addButton($this->lng->txt('paya_edit_details'), $this->ctrl->getLinkTarget($this, 'editDetails'));
1213  $ilToolbar->addButton($this->lng->txt('paya_edit_prices'), $this->ctrl->getLinkTarget($this, 'editPrices'));
1214  $ilToolbar->addButton($this->lng->txt('pay_edit_abstract'), $this->ctrl->getLinkTargetByClass(array('ilshoppagegui'), 'edit'));
1215 
1216  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
1217 
1218  $tmp_obj = ilObjectFactory::getInstanceByRefId($this->pobject->getRefId(),false);
1219  if($tmp_obj)
1220  {
1221  $tmp_object['title'] = $tmp_obj->getTitle();
1222  $tmp_object['type'] = $tmp_obj->getType();
1223  }
1224  else
1225  {
1226  $tmp_object['title'] = $this->lng->txt('object_not_found');
1227  $tmp_object['type'] = '';
1228 
1229  }
1230  if($a_show_confirm)
1231  {
1232  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
1233  $oConfirmationGUI = new ilConfirmationGUI();
1234 
1235  // set confirm/cancel commands
1236  $oConfirmationGUI->setFormAction($this->ctrl->getFormAction($this,"performObjectDelete"));
1237  $oConfirmationGUI->setHeaderText($this->lng->txt("paya_sure_delete_object"));
1238  $oConfirmationGUI->setCancel($this->lng->txt("cancel"), "objects");
1239  $oConfirmationGUI->setConfirm($this->lng->txt("confirm"), "performObjectDelete");
1240 
1241  $oConfirmationGUI->addItem('', $tmp_object['title'], $tmp_object['title']);
1242  $this->tpl->setVariable('CONFIRMATION',$oConfirmationGUI->getHTML());
1243 
1244  return true;
1245  }
1246 
1247  $oForm = new ilPropertyFormGUI();
1248  $oForm->setFormAction($this->ctrl->getFormAction($this, 'updateDetails'));
1249  $oForm->setTitle($tmp_object['title']);
1250  $oForm->setTitleIcon(ilUtil::getImagePath('icon_'.$tmp_object['type'].'_b.png'));
1251 
1252  // repository path
1253  $oPathGUI = new ilNonEditableValueGUI($this->lng->txt('path'));
1254  $oPathGUI->setValue($this->__getHTMLPath($this->pobject->getRefId()));
1255  $oForm->addItem($oPathGUI);
1256 
1257  // number of purchasers
1258  $oPurchasersGUI = new ilNonEditableValueGUI($this->lng->txt('paya_count_purchaser'));
1259  $oPurchasersGUI->setValue(ilPaymentBookings::_getCountBookingsByObject((int)$_GET['pobject_id']));
1260  $oForm->addItem($oPurchasersGUI);
1261 
1262  // vendors
1263  $oVendorsGUI = new ilSelectInputGUI($this->lng->txt('paya_vendor'), 'vendor');
1264  $oVendorsGUI->setOptions($this->__getVendors());
1265  $oVendorsGUI->setValue($this->pobject->getVendorId());
1266  $oForm->addItem($oVendorsGUI);
1267 
1268  // status
1269  $oStatusGUI = new ilSelectInputGUI($this->lng->txt('status'), 'status');
1270  $oStatusGUI->setOptions($this->__getStatus());
1271  $oStatusGUI->setValue($this->pobject->getStatus());
1272  $oForm->addItem($oStatusGUI);
1273 
1274  // pay methods
1275  $oPayMethodsGUI = new ilSelectInputGUI($this->lng->txt('paya_pay_method'), 'pay_method');
1276  $oPayMethodsGUI->setOptions(ilPayMethods::getPayMethodsOptions('not_specified'));
1277 
1278  $oPayMethodsGUI->setValue($this->pobject->getPayMethod());
1279  $oForm->addItem($oPayMethodsGUI);
1280 
1281  // topics
1282  include_once './Services/Payment/classes/class.ilShopTopics.php';
1283  ilShopTopics::_getInstance()->read();
1284  if(is_array($topics = ilShopTopics::_getInstance()->getTopics()) && count($topics))
1285  {
1286  $oTopicsGUI = new ilSelectInputGUI($this->lng->txt('topic'), 'topic_id');
1287 
1288  ilShopTopics::_getInstance()->read();
1289  $topic_options = array();
1290  $topic_options[''] = $this->lng->txt('please_choose');
1291 
1292  foreach($topics as $oTopic)
1293  {
1294  $topic_options[$oTopic->getId()] = $oTopic->getTitle();
1295  }
1296 
1297  $oTopicsGUI->setOptions($topic_options);
1298  $oTopicsGUI->setValue($this->pobject->getTopicId());
1299  $oForm->addItem($oTopicsGUI);
1300  }
1301 
1302  // vats
1303  $oShopVatsList = new ilShopVatsList();
1304  $oShopVatsList->read();
1305  if($oShopVatsList->hasItems())
1306  {
1307  $oVatsGUI = new ilSelectInputGUI($this->lng->txt('vat_rate'), 'vat_id');
1308 
1309  $vats_options = array();
1310  foreach($oShopVatsList as $oVAT)
1311  {
1312  $vats_options[$oVAT->getId()] = ilShopUtils::_formatVAT($oVAT->getRate()).' -> '.$oVAT->getTitle();
1313  }
1314 
1315  $oVatsGUI->setOptions($vats_options);
1316  $oVatsGUI->setValue($this->pobject->getVatId());
1317  $oForm->addItem($oVatsGUI);
1318  }
1319  else
1320  {
1321  $oVatsGUI = new ilNonEditableValueGUI($this->lng->txt('vat_rate'));
1322  $oVatsGUI->setValue($this->lng->txt('paya_no_vats_assigned'));
1323  $oForm->addItem($oVatsGUI);
1324  }
1325 
1326  $oThumbnail = new ilImageFileInputGUI($this->lng->txt('pay_thumbnail'), 'thumbnail');
1327  $oFile = new ilFileDataShop($this->pobject->getPobjectId());
1328  if(($webpath_file = $oFile->getCurrentImageWebPath()) !== false)
1329  {
1330  $oThumbnail->setImage($webpath_file);
1331  }
1332  $oForm->addItem($oThumbnail);
1333 
1334  // buttons
1335  $oForm->addCommandButton('updateDetails', $this->lng->txt('save'));
1336  $oForm->addCommandButton('deleteObject', $this->lng->txt('delete'));
1337 
1338  $this->tpl->setVariable('FORM', $oForm->getHTML());
1339  return true;
1340 
1341  }
1342 
1343  public function deleteObjectObject()
1344  {
1345  //include_once './Services/Payment/classes/class.ilPaymentBookings.php';
1346 
1347  if(!$_GET['pobject_id'])
1348  {
1349  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
1350 
1351  $this->editDetailsObject();
1352  return true;
1353  }
1354  if(ilPaymentBookings::_getCountBookingsByObject((int) $_GET['pobject_id']))
1355  {
1356  ilUtil::sendInfo($this->lng->txt('paya_bookings_available'));
1357  $this->editDetailsObject();
1358 
1359  return false;
1360  }
1361  else
1362  {
1363  ilUtil::sendQuestion($this->lng->txt('paya_sure_delete_object'));
1364  $this->editDetailsObject(true);
1365 
1366  return true;
1367  }
1368  }
1369 
1370  public function performObjectDeleteObject()
1371  {
1372 
1373  if(!$_GET['pobject_id'])
1374  {
1375  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
1376 
1377  $this->objectsObject();
1378  return true;
1379  }
1380  $this->__initPaymentObject((int) $_GET['pobject_id']);
1381 
1382  // delete object data
1383  $this->pobject->delete();
1384 
1385  // delete payment prices
1386  $price_obj = new ilPaymentPrices((int) $_GET['pobject_id']);
1387  $price_obj->deleteAllPrices();
1388  unset($price_obj);
1389 
1390  ilUtil::sendInfo($this->lng->txt('paya_deleted_object'));
1391 
1392  $this->objectsObject();
1393 
1394  return true;
1395  }
1396 
1397  private function __getHTMLPath($a_ref_id)
1398  {
1399  global $tree;
1400 
1401  $path = $tree->getPathFull($a_ref_id);
1402 
1403  unset($path[0]);
1404  $html = '';
1405  if(is_array($path))
1406  {
1407  foreach($path as $data)
1408  {
1409  $html .= $data['title'].' > ';
1410  }
1411  }
1412  return substr($html,0,-2);
1413  }
1414 
1415  private function __getVendors()
1416  {
1417  $options = array();
1418  $vendors = array();
1419 
1420  $all_vendors = $this->vendors_obj->getVendors();
1421  if (is_array($all_vendors))
1422  {
1423  foreach ($all_vendors as $vendor)
1424  {
1425  $vendors[] = $vendor['vendor_id'];
1426  }
1427  }
1428 
1429  foreach($vendors as $vendor)
1430  {
1431  if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($vendor, false))
1432  {
1433  continue;
1434  }
1435 
1436  $options[$vendor] = $tmp_obj->getFullname().' ['.$tmp_obj->getLogin().']';
1437  }
1438  return $options;
1439  }
1440 
1441  private function __getStatus()
1442  {
1443  $option = array();
1444  $option[$this->pobject->STATUS_NOT_BUYABLE] = $this->lng->txt('paya_not_buyable');
1445  $option[$this->pobject->STATUS_BUYABLE] = $this->lng->txt('paya_buyable');
1446  $option[$this->pobject->STATUS_EXPIRES] = $this->lng->txt('paya_expires');
1447 
1448  return $option;
1449  }
1450 
1451  public function resetObjectFilterObject()
1452  {
1453  unset($_SESSION['pay_statistics']);
1454  unset($_POST['title_type']);
1455  unset($_POST['title_value']);
1456  unset($_POST['vendor']);
1457  unset($_POST['pay_method']);
1458 
1459  ilUtil::sendInfo($this->lng->txt('paya_filter_reseted'));
1460 
1461  return $this->objectsObject();
1462  }
1463 
1464  public function objectsObject()
1465  {
1466  global $rbacsystem;
1467 
1468  // MINIMUM ACCESS LEVEL = 'read'
1469  if(!$rbacsystem->checkAccess('read', $this->object->getRefId()))
1470  {
1471  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$this->ilErr->MESSAGE);
1472  }
1473 
1474  if ($_POST['updateView'] == 1)
1475  {
1476  $_SESSION['pay_objects']['title_type'] = $_POST['title_type'];
1477  $_SESSION['pay_objects']['title_value'] = $_POST['title_value'];
1478  $_SESSION['pay_objects']['pay_method'] = $_POST['pay_method'];
1479  $_SESSION['pay_objects']['vendor'] = $_POST['vendor'];
1480  }
1481 
1482  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
1483 
1484  $this->__initPaymentObject();
1485  $this->lng->loadLanguageModule('search');
1486 
1487  $filter_form = new ilPropertyFormGUI();
1488  $filter_form->setFormAction($this->ctrl->getFormAction($this));
1489  $filter_form->setTitle($this->lng->txt('pay_filter'));
1490  $filter_form->setId('filter_form');
1491  $filter_form->setTableWidth('100 %');
1492 
1493  //hide_filter
1494  $o_hide_check = new ilCheckBoxInputGUI($this->lng->txt('show_filter'),'show_filter');
1495  $o_hide_check->setValue(1);
1496  $o_hide_check->setChecked($_POST['show_filter'] ? 1 : 0);
1497 
1498  $o_hidden = new ilHiddenInputGUI('updateView');
1499  $o_hidden->setValue(1);
1500  $o_hidden->setPostVar('updateView');
1501  $o_hide_check->addSubItem($o_hidden);
1502 
1503  //title
1504  $radio_group = new ilRadioGroupInputGUI($this->lng->txt('search_in_title'), 'title_type');
1505  $radio_option = new ilRadioOption($this->lng->txt('search_any_word'), 'or');
1506  $radio_group->addOption($radio_option);
1507  $radio_option = new ilRadioOption($this->lng->txt('search_all_words'), 'and');
1508  $radio_group->addOption($radio_option);
1509 
1510  $radio_group->setRequired(false);
1511  $radio_group->setValue('or');
1512  $radio_group->setPostVar('title_type');
1513 
1514  $o_title = new ilTextInputGUI();
1515  $o_title->setValue($_SESSION['pay_objects']['title_value']);
1516  $o_title->setPostVar('title_value');
1517  $o_title->setTitle($this->lng->txt('title'));
1518 
1519  $o_hide_check->addSubItem($radio_group);
1520  $o_hide_check->addSubItem($o_title);
1521 
1522  //vendor
1523  $o_vendor = new ilTextInputGUI();
1524  $o_vendor->setTitle($this->lng->txt('paya_vendor'));
1525  $o_vendor->setValue($_SESSION['pay_objects']['vendor']);
1526  $o_vendor->setPostVar('vendor');
1527  $o_hide_check->addSubItem($o_vendor);
1528 
1529  // paymethod
1530  $o_paymethod = new ilSelectInputGUI();
1531  $o_paymethod->setTitle($this->lng->txt('payment_system'));
1532  $o_paymethod->setOptions(ilPaymethods::getPayMethodsOptions('all'));
1533  $o_paymethod->setValue($_SESSION['pay_objects']['pay_method']);
1534  $o_paymethod->setPostVar('pay_method');
1535  $o_hide_check->addSubItem($o_paymethod);
1536 
1537  $filter_form->addCommandButton('objects', $this->lng->txt('pay_update_view'));
1538  $filter_form->addCommandButton('resetObjectFilter', $this->lng->txt('pay_reset_filter'));
1539 
1540  $filter_form->addItem($o_hide_check);
1541  if(!count($objects = ilPaymentObject::_getAllObjectsData()))
1542  {
1543  ilUtil::sendInfo($this->lng->txt('paya_no_objects_assigned'));
1544 
1545  return true;
1546  }
1547  $this->tpl->setVariable('FORM', $filter_form->getHTML());
1548 
1549  $counter = 0;
1550  foreach($objects as $data)
1551  {
1552  $tmp_obj = ilObjectFactory::getInstanceByRefId($data['ref_id'], false);
1553  if($tmp_obj)
1554  {
1555  $f_result[$counter]['title'] = $tmp_obj->getTitle();
1556  }
1557  else
1558  {
1559  $f_result[$counter]['title'] = $this->lng->txt('object_not_found');
1560  }
1561 
1562  switch($data['status'])
1563  {
1564  case $this->pobject->STATUS_BUYABLE:
1565  $f_result[$counter]['status'] = $this->lng->txt('paya_buyable');
1566  break;
1567 
1568  case $this->pobject->STATUS_NOT_BUYABLE:
1569  $f_result[$counter]['status'] = $this->lng->txt('paya_not_buyable');
1570  break;
1571 
1572  case $this->pobject->STATUS_EXPIRES:
1573  $f_result[$counter]['status'] = $this->lng->txt('paya_expires');
1574  break;
1575  }
1576 
1577  include_once './Services/Payment/classes/class.ilPayMethods.php';
1578  $str_paymethod = ilPayMethods::getStringByPaymethod($data['pay_method']);
1579  $f_result[$counter]['pay_method'] = $str_paymethod;
1580 
1581  if($data['vat_id'] <= 0)
1582  {
1583  $vat_rate = $this->lng->txt('payment_vat_has_to_be_defined_by_administration_short');
1584  }
1585  else
1586  {
1587  try
1588  {
1589  $oVAT = new ilShopVats((int)$data['vat_id']);
1590  $vat_rate = ilShopUtils::_formatVAT((float)$oVAT->getRate());
1591  }
1592  catch(ilShopException $e)
1593  {
1594  $vat_rate = $this->lng->txt('payment_vat_has_to_be_defined_by_administration_short');
1595  }
1596  }
1597 
1598  $f_result[$counter]['vat_rate'] = $vat_rate;
1599 
1600  $tmp_user = ilObjectFactory::getInstanceByObjId($data['vendor_id'], false);
1601  if($tmp_user )
1602  {
1603  $f_result[$counter]['vendor'] = $tmp_user->getFullname().' ['.$tmp_user->getLogin().']';
1604  }
1605  else
1606  {
1607  $f_result[$counter]['vendor'] = $this->lng->txt('user_not_found');
1608  }
1609 
1610  // Get number of purchasers
1611  $f_result[$counter]['purchasers'] = ilPaymentBookings::_getCountBookingsByObject($data['pobject_id']);
1612 
1613  // edit link
1614  $this->ctrl->setParameter($this,'pobject_id',$data['pobject_id']);
1615  $link_change = "<div class=\"il_ContainerItemCommands\"><a class=\"il_ContainerItemCommand\" href=\"".$this->ctrl->getLinkTarget($this,"editDetails")."\">".$this->lng->txt("edit")."</a></div>";
1616 
1617  $f_result[$counter]['options'] = $link_change;
1618  unset($tmp_user);
1619  unset($tmp_obj);
1620 
1621  ++$counter;
1622  }
1623 
1624  return $this->__showObjectsTable($f_result);
1625 
1626  //return true;
1627  }
1628 
1629  private function __showObjectsTable($a_result_set)
1630  {
1631  $this->ctrl->setParameter($this, 'cmd', 'objects');
1632 
1633  $tbl = new ilShopTableGUI($this);
1634  $tbl->setTitle($this->lng->txt('objects'));
1635 
1636  $tbl->setId('tbl_show_objects');
1637  $tbl->setRowTemplate("tpl.shop_objects_row.html", "Services/Payment");
1638 
1639  $tbl->addColumn($this->lng->txt('title'), 'title', '10%');
1640  $tbl->addColumn($this->lng->txt('status'), 'status', '10%');
1641  $tbl->addColumn($this->lng->txt('paya_pay_method'),'pay_method','10%');
1642  $tbl->addColumn($this->lng->txt('vat_rate'), 'vat_rate', '15%');
1643  $tbl->addColumn($this->lng->txt('paya_vendor'), 'vendor', '10%');
1644  $tbl->addColumn($this->lng->txt('paya_count_purchaser'), 'purchasers', '10%');
1645  $tbl->addColumn('','options','10%');
1646 
1647  $tbl->setData($a_result_set);
1648 
1649  $this->tpl->setVariable('TABLE', $tbl->getHTML());
1650 
1651  return true;
1652  }
1653 
1654  private function __initPaymentObject($a_pobject_id = 0)
1655  {
1656  $this->pobject = new ilPaymentObject($this->user_obj,$a_pobject_id);
1657  return true;
1658  }
1659 
1660  public function gatewayObject()
1661  {
1662  switch($_POST['action'])
1663  {
1664  case 'deleteVendorsObject':
1665  $this->deleteVendors();
1666  break;
1667 
1668  case 'editVendorObject':
1669  $this->editVendor();
1670  break;
1671 
1672  case 'performEditVendorObject':
1673  $this->performEditVendorObject();
1674  break;
1675 
1676  default:
1677  $this->vendorsObject();
1678  break;
1679  }
1680  return true;
1681  }
1682 
1683  public function resetFilterObject()
1684  {
1685  unset($_SESSION['pay_statistics']);
1686  unset($_POST['transaction_type']);
1687  unset($_POST['transaction_value']);
1688  unset($_POST['from']);
1689  unset($_POST['til']);
1690  unset($_POST['payed']);
1691  unset($_POST['access']);
1692  unset($_POST['customer']);
1693  unset($_POST['pay_method']);
1694  unset($_POST['updateView']);
1695  unset($_POST["adm_filter_title_id"]);
1696  ilUtil::sendInfo($this->lng->txt('paya_filter_reseted'));
1697 
1698  return $this->statisticObject();
1699  }
1700 
1701  public function statisticObject()
1702  {
1703  global $rbacsystem, $ilToolbar,$ilObjDataCache;
1704 
1705  include_once './Services/Payment/classes/class.ilPayMethods.php';
1706 
1707  // MINIMUM ACCESS LEVEL = 'read'
1708  if(!$rbacsystem->checkAccess('read', $this->object->getRefId()))
1709  {
1710  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$this->ilErr->MESSAGE);
1711  }
1712 
1713  $ilToolbar->addButton($this->lng->txt('paya_add_customer'), $this->ctrl->getLinkTarget($this, 'showObjectSelector'));
1714 
1715  if ($_POST['updateView'] == 1)
1716  {
1717  $_SESSION['pay_statistics']['show_filter']= $_POST['show_filter'];
1718  $_SESSION['pay_statistics']['updateView'] = true;
1719  $_SESSION['pay_statistics']['until_check'] = $_POST['until_check'];
1720  $_SESSION['pay_statistics']['from_check'] = $_POST['from_check'];
1721  $_SESSION['pay_statistics']['transaction_type'] = isset($_POST['transaction_type']) ? $_POST['transaction_type'] : '' ;
1722  $_SESSION['pay_statistics']['transaction_value'] = isset($_POST['transaction_value']) ? $_POST['transaction_value'] : '';
1723  $_SESSION['pay_statistics']['adm_filter_title_id'] = (int)$_POST['adm_filter_title_id'];
1724 
1725  if($_SESSION['pay_statistics']['from_check'] == '1')
1726  {
1727  $_SESSION['pay_statistics']['from']['date']['d'] = $_POST['from']['date']['d'];
1728  $_SESSION['pay_statistics']['from']['date']['m'] = $_POST['from']['date']['m'];
1729  $_SESSION['pay_statistics']['from']['date']['y'] = $_POST['from']['date']['y'];
1730  }
1731  else
1732  {
1733  $_SESSION['pay_statistics']['from']['date']['d'] = '';
1734  $_SESSION['pay_statistics']['from']['date']['m'] = '';
1735  $_SESSION['pay_statistics']['from']['date']['y'] = '';
1736  }
1737 
1738  if($_SESSION['pay_statistics']['until_check']== '1')
1739  {
1740  $_SESSION['pay_statistics']['til']['date']['d'] = $_POST['til']['date']['d'];
1741  $_SESSION['pay_statistics']['til']['date']['m'] = $_POST['til']['date']['m'];
1742  $_SESSION['pay_statistics']['til']['date']['y'] = $_POST['til']['date']['y'];
1743  }
1744  else
1745  {
1746  $_SESSION['pay_statistics']['til']['date']['d'] = '';
1747  $_SESSION['pay_statistics']['til']['date']['m'] = '';
1748  $_SESSION['pay_statistics']['til']['date']['y'] = '';
1749  }
1750 
1751  $_SESSION['pay_statistics']['payed'] = $_POST['payed'];
1752  $_SESSION['pay_statistics']['access'] = $_POST['access'];
1753  $_SESSION['pay_statistics']['pay_method'] = $_POST['pay_method'];
1754  $_SESSION['pay_statistics']['customer'] = isset ($_POST['customer']) ? $_POST['customer'] : '';
1755  $_SESSION['pay_statistics']['vendor'] = isset ($_POST['vendor']) ? $_POST['vendor']: '';
1756 
1757  }
1758 
1759  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
1760 
1761  $filter_form = new ilPropertyFormGUI();
1762  $filter_form->setFormAction($this->ctrl->getFormAction($this));
1763  $filter_form->setTitle($this->lng->txt('pay_filter'));
1764  $filter_form->setId('formular');
1765  $filter_form->setTableWidth('100 %');
1766  //filter
1767  $o_hide_check = new ilCheckBoxInputGUI($this->lng->txt('show_filter'),'show_filter');
1768  $o_hide_check->setValue(1);
1769  $o_hide_check->setChecked($_POST['show_filter'] ? 1 : 0);
1770 
1771  $o_hidden = new ilHiddenInputGUI('updateView');
1772  $o_hidden->setValue(1);
1773  $o_hidden->setPostVar('updateView');
1774  $o_hide_check->addSubItem($o_hidden);
1775 
1776  $o_transaction_type = new ilSelectInputGUI();
1777  $trans_option = array($this->lng->txt('pay_starting'),$this->lng->txt('pay_ending'));
1778  $trans_value = array('0','1');
1779  $o_transaction_type->setTitle($this->lng->txt('paya_transaction'));
1780  $o_transaction_type->setOptions($trans_option);
1781  $o_transaction_type->setValue($_SESSION['pay_statistics']['transaction_type']);
1782  $o_transaction_type->setPostVar('transaction_type');
1783  $o_hide_check->addSubItem($o_transaction_type);
1784 
1785  $o_transaction_val = new ilTextInputGUI();
1786  $o_transaction_val->setValue($_SESSION['pay_statistics']['transaction_value']);
1787  $o_transaction_val->setPostVar('transaction_value');
1788  $o_hide_check->addSubItem($o_transaction_val);
1789 
1790  $o_customer = new ilTextInputGUI();
1791  $o_customer->setTitle($this->lng->txt('paya_customer'));
1792  $o_customer->setValue($_SESSION['pay_statistics']['customer']);
1793  $o_customer->setPostVar('customer');
1794  $o_hide_check->addSubItem($o_customer);
1795 
1796  $o_vendor = new ilTextInputGUI();
1797  $o_vendor->setTitle($this->lng->txt('paya_vendor'));
1798  $o_vendor->setValue($_SESSION['pay_statistics']['vendor']);
1799  $o_vendor->setPostVar('vendor');
1800  $o_hide_check->addSubItem($o_vendor);
1801 
1802  $o_from_check = new ilCheckBoxInputGUI($this->lng->txt('pay_order_date_from'),'from_check');
1803  $o_from_check->setValue(1);
1804  $o_from_check->setChecked($_SESSION['pay_statistics']['from_check'] ? 1 : 0);
1805 
1806  $o_date_from = new ilDateTimeInputGUI();
1807  $o_date_from->setPostVar('from');
1808 
1809  if($_SESSION['pay_statistics']['from_check'] == '1')
1810  {
1811  $o_date_from->setValueByArray($_SESSION['pay_statistics']['from']);
1812  $o_date_from->checkInput();
1813  }
1814 
1815  $o_from_check->addSubItem($o_date_from);
1816  $o_hide_check->addSubItem($o_from_check);
1817 
1818  $o_until_check = new ilCheckBoxInputGUI($this->lng->txt('pay_order_date_til'), 'until_check');
1819  $o_until_check->setValue(1);
1820  $o_until_check->setChecked($_SESSION['pay_statistics']['until_check'] ? 1 : 0);
1821 
1822  $o_date_until = new ilDateTimeInputGUI();
1823  $o_date_until->setPostVar('til');
1824 
1825  if($_SESSION['pay_statistics']['until_check'] == '1')
1826  {
1827  $o_date_until->setValueByArray($_SESSION['pay_statistics']['til']);
1828  $o_date_until->checkInput();
1829  }
1830 
1831  $o_until_check->addSubItem($o_date_until);
1832  $o_hide_check->addSubItem($o_until_check);
1833 
1834  // title filter
1835  $this->__initBookingObject();
1836  $title_options['all']=$this->lng->txt('pay_all');
1837  $unique_titles = $this->booking_obj->getUniqueTitles();
1838 
1839  if(is_array($unique_titles) && count($unique_titles))
1840  {
1841  foreach($unique_titles as $ref_id)
1842  {
1843  $title_options[$ref_id] = $ilObjDataCache->lookupTitle($ilObjDataCache->lookupObjId($ref_id));
1844  }
1845  }
1846 
1847  $o_object_title = new ilSelectInputGUI();
1848  $o_object_title->setTitle($this->lng->txt('title'));
1849  $o_object_title->setOptions($title_options);
1850  $o_object_title->setValue($_SESSION["pay_statistics"]["adm_filter_title_id"]);
1851  $o_object_title->setPostVar('adm_filter_title_id');
1852  $o_hide_check->addSubItem($o_object_title);
1853 
1854  $o_payed = new ilSelectInputGUI();
1855  $payed_option = array('all'=>$this->lng->txt('pay_all'),'1'=>$this->lng->txt('yes'),'0'=>$this->lng->txt('no'));
1856 
1857  $o_payed->setTitle($this->lng->txt('paya_payed'));
1858  $o_payed->setOptions($payed_option);
1859  $o_payed->setValue($_SESSION['pay_statistics']['payed']);
1860  $o_payed->setPostVar('payed');
1861 
1862  $o_hide_check->addSubItem($o_payed);
1863 
1864  $o_access = new ilSelectInputGUI();
1865  $access_option = array('all'=>$this->lng->txt('pay_all'),'1'=>$this->lng->txt('yes'),'0'=>$this->lng->txt('no'));
1866 
1867  $o_access->setTitle($this->lng->txt('paya_access'));
1868  $o_access->setOptions($access_option);
1869  $o_access->setValue($_SESSION['pay_statistics']['access']);
1870  $o_access->setPostVar('access');
1871  $o_hide_check->addSubItem($o_access);
1872 
1873  $o_paymethod = new ilSelectInputGUI();
1874  $o_paymethod->setTitle($this->lng->txt('payment_system'));
1875  $o_paymethod->setOptions(ilPaymethods::getPayMethodsOptions('all'));
1876  $o_paymethod->setValue($_SESSION['pay_statistics']['pay_method']);
1877  $o_paymethod->setPostVar('pay_method');
1878  $o_hide_check->addSubItem($o_paymethod);
1879 
1880  $filter_form->addCommandButton('statistic', $this->lng->txt('pay_update_view'));
1881  $filter_form->addCommandButton('resetFilter', $this->lng->txt('pay_reset_filter'));
1882 
1883  $filter_form->addItem($o_hide_check);
1884 
1885  $this->tpl->setVariable('FORM', $filter_form->getHTML());
1886  //else $filter_form->checkInput();
1887 
1888  // STATISTICS TABLE
1889  $this->__initBookingObject();
1890 
1891  if(!count($bookings = $this->booking_obj->getBookings()))
1892  {
1893  ilUtil::sendInfo($this->lng->txt('paya_no_bookings'));
1894 
1895  return true;
1896  }
1897 # else
1898 # {
1899 # $this->__showButton('exportVendors',$this->lng->txt('excel_export'));
1900 # }
1901 
1902  include_once 'Services/User/classes/class.ilObjUser.php';
1903  $object_title_cache = array();
1904  $user_title_cache = array();
1905 
1906  $counter = 0;
1907  foreach($bookings as $booking)
1908  {
1909  if(array_key_exists($booking['ref_id'], $object_title_cache))
1910  {
1911  $tmp_obj = $object_title_cache[$booking['ref_id']];
1912  }
1913  else
1914  {
1915  $tmp_obj = ilObject::_lookupTitle(ilObject::_lookupObjId($booking['ref_id']));
1916  $object_title_cache[$booking['ref_id']] = $tmp_obj;
1917  }
1918 
1919 
1920  if(array_key_exists($booking['b_vendor_id'], $user_title_cache))
1921  {
1922  $tmp_vendor = $user_title_cache[$booking['b_vendor_id']];
1923  }
1924  else
1925  {
1926  $tmp_vendor = ilObjUser::_lookupLogin($booking['b_vendor_id']);
1927  $user_title_cache[$booking['b_vendor_id']] = $tmp_vendor;
1928  }
1929  if(array_key_exists($booking['customer_id'], $user_title_cache))
1930  {
1931  $tmp_purchaser = $user_title_cache[$booking['customer_id']];
1932  }
1933  else
1934  {
1935  if(ANONYMOUS_USER_ID == $booking['customer_id'])
1936  {
1937  $tmp_purchaser = ilObjUser::_lookupLogin($booking['customer_id']);
1938  $purchaser_name = $booking['name_extern'];
1939  $tmp_purchaser_email = $booking['email_extern'];
1940  }
1941  else
1942  {
1943  $tmp_purchaser = ilObjUser::_lookupLogin($booking['customer_id']);
1944  $tmp_purchaser_name = ilObjUser::_lookupName($booking['customer_id']);
1945  $purchaser_name = $tmp_purchaser_name['firstname'].' '.$tmp_purchaser_name['lastname'];
1946  $tmp_purchaser_email = ilObjUser::_lookupEmail($booking['customer_id']);
1947  }
1948  $user_title_cache[$booking['customer_id']] = $tmp_purchaser;
1949  }
1950 
1951  $transaction = $booking['transaction_extern'];
1952  $str_paymethod = ilPayMethods::getStringByPaymethod($booking['b_pay_method']);
1953  $transaction .= $booking['transaction']."<br> (" . $str_paymethod . ")";
1954 
1955  $f_result[$counter]['transaction'] = $transaction;
1956  $f_result[$counter]['object_title'] = ($tmp_obj != '' ? $tmp_obj : $this->lng->txt('object_deleted'));
1957  $f_result[$counter]['vendor'] = ($tmp_vendor != '' ? '['.$tmp_vendor.']' : $this->lng->txt('user_deleted'));
1958  $f_result[$counter]['customer'] = ($tmp_purchaser != '' ?
1959  $purchaser_name. ' ['.$tmp_purchaser.']<br>'
1960  .$tmp_purchaser_email
1961  : $this->lng->txt('user_deleted'));
1962  $f_result[$counter]['order_date'] = ilDatePresentation::formatDate(new ilDate($booking['order_date'], IL_CAL_UNIX));
1963 
1964 
1965  if($booking['duration'] == 0 && $booking['access_enddate'] == NULL)
1966  {
1967  $f_result[$counter]['duration'] = $this->lng->txt("unlimited_duration");
1968  }
1969  else
1970  {
1971 // if($booking['duration'] > 0 )
1972 // {
1973 // $f_result[$counter]['duration'] = $booking['duration'].' '.$this->lng->txt('paya_months').' / </br>';
1974 // }
1975  $f_result[$counter]['duration'] .= ilDatePresentation::formatDate(new ilDate($booking['access_startdate'], IL_CAL_DATETIME))
1976  .' - '.ilDatePresentation::formatDate(new ilDate($booking['access_enddate'], IL_CAL_DATETIME));
1977  }
1978 
1979  $f_result[$counter]['price'] = $booking['price'].' '.$booking['currency_unit'];
1980  $f_result[$counter]['discount'] = ($booking['discount'] != '' ? ($booking['discount'].' '.$booking['currency_unit']) : '&nbsp;');
1981 
1982  $payed_access = $booking['payed'] ?
1983  $this->lng->txt('yes') :
1984  $this->lng->txt('no');
1985 
1986  $payed_access .= '/';
1987  $payed_access .= $booking['access_granted'] ?
1988  $this->lng->txt('yes') :
1989  $this->lng->txt('no');
1990 
1991  $f_result[$counter]['payed_access'] = $payed_access;
1992 
1993  $this->ctrl->setParameter($this,"booking_id",$booking['booking_id']);
1994  $link_change = "<div class=\"il_ContainerItemCommands\"><a class=\"il_ContainerItemCommand\" href=\"".$this->ctrl->getLinkTarget($this,"editStatistic")."\">".$this->lng->txt("edit")."</a></div>";
1995 
1996  $f_result[$counter]['edit'] = $link_change;
1997 
1998  unset($tmp_obj);
1999  unset($tmp_vendor);
2000  unset($tmp_purchaser);
2001 
2002  ++$counter;
2003  }
2004  return $this->__showStatisticTable($f_result);
2005  }
2006 
2007  public function editStatisticObject($a_show_confirm_delete = false)
2008  {
2009  global $ilToolbar;
2010 
2011  include_once './Services/Payment/classes/class.ilPayMethods.php';
2012 
2013  if(!isset($_GET['booking_id']))
2014  {
2015  ilUtil::sendInfo($this->lng->txt('paya_no_booking_id_given'));
2016  $this->showStatistics();
2017 
2018  return true;
2019  }
2020 
2021  $ilToolbar->addButton($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'statistic'));
2022 
2023  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
2024  $this->ctrl->setParameter($this,'booking_id',(int) $_GET['booking_id']);
2025 
2026  // confirm delete
2027  if($a_show_confirm_delete)
2028  {
2029  $oConfirmationGUI = new ilConfirmationGUI();
2030 
2031  // set confirm/cancel commands
2032  $oConfirmationGUI->setFormAction($this->ctrl->getFormAction($this,"performDelete"));
2033  $oConfirmationGUI->setHeaderText($this->lng->txt("paya_sure_delete_stat"));
2034  $oConfirmationGUI->setCancel($this->lng->txt("cancel"), "statistic");
2035  $oConfirmationGUI->setConfirm($this->lng->txt("confirm"), "performDelete");
2036 
2037  $this->tpl->setVariable('CONFIRMATION', $oConfirmationGUI->getHTML());
2038  return true;
2039  }
2040 
2041 
2042  $this->__initBookingObject();
2043  $bookings = $this->booking_obj->getBookings();
2044  $booking = $bookings[(int) $_GET['booking_id']];
2045 
2046  // get customer_obj
2047  $tmp_user = ilObjectFactory::getInstanceByObjId($booking['customer_id'], false);
2048 
2049  $oForm = new ilPropertyFormGUI();
2050  $oForm->setFormAction($this->ctrl->getFormAction($this));
2051  $oForm->setId('stat_form');
2052  $oForm->setTableWidth('50 %');
2053  $oForm->setTitleIcon(ilUtil::getImagePath('icon_usr.png'));
2054  if(is_object($tmp_user))
2055  {
2056  $frm_user = $tmp_user->getFullname().' ['.$tmp_user->getLogin().']';
2057  }
2058  else
2059  {
2060  $frm_user = $this->lng->txt('user_deleted');
2061  }
2062  $oForm->setTitle($frm_user);
2063 
2064  $pObj = new ilPaymentObject($this->user_obj, $booking['pobject_id']);
2065  $tmp_obj = ilObject::_lookupTitle(ilObject::_lookupObjId($pObj->getRefId()));
2066 
2067  // object_title
2068  $oTitleGUI = new ilNonEditableValueGUI($this->lng->txt('title'));
2069  $oTitleGUI->setValue($tmp_obj != '' ? $tmp_obj : $this->lng->txt('object_deleted'));
2070  $oForm->addItem($oTitleGUI);
2071 
2072  // transaction
2073  $oTransactionGUI = new ilNonEditableValueGUI($this->lng->txt('paya_transaction'));
2074  $oTransactionGUI->setValue($booking['transaction']);
2075  $oForm->addItem($oTransactionGUI);
2076 
2077  //vendor
2078  $oVendorGUI = new ilNonEditableValueGUI($this->lng->txt('paya_vendor'));
2079  $tmp_vendor = ilObjectFactory::getInstanceByObjId($booking['b_vendor_id'], false);
2080  if(is_object($tmp_vendor))
2081  {
2082  $frm_vendor = $tmp_vendor->getFullname().' ['.$tmp_vendor->getLogin().']';
2083  }
2084  else
2085  {
2086  $frm_vendor = $this->lng->txt('user_deleted');
2087  }
2088  $oVendorGUI->setValue($frm_vendor);
2089  $oForm->addItem($oVendorGUI);
2090 
2091  // paymethod
2092  $oPaymethodGUI = new ilNonEditableValueGUI($this->lng->txt('paya_pay_method'));
2093  $oPaymethodGUI->setValue(ilPayMethods::getStringByPaymethod($booking['b_pay_method']));
2094  $oForm->addItem($oPaymethodGUI);
2095 
2096  // order_date
2097  $oOrderdateGUI = new ilNonEditableValueGUI($this->lng->txt('paya_order_date'));
2098  $oOrderdateGUI->setValue(ilDatePresentation::formatDate(new ilDate($booking['order_date'], IL_CAL_UNIX)));
2099  $oForm->addItem($oOrderdateGUI);
2100 
2101  // duration
2102  $oDurationGUI = new ilNonEditableValueGUI($this->lng->txt('duration'));
2103  if($booking['duration'] == 0 && $booking['access_enddate'] == NULL)
2104  {
2105  $frm_duration = $this->lng->txt("unlimited_duration");
2106 
2107  }
2108  else
2109  {
2110  if($booking['duration'] > 0)
2111  {
2112  $frm_duration = $booking['duration'].' '.$this->lng->txt('paya_months').'</br>';
2113  }
2114  $frm_duration .= ilDatePresentation::formatDate(new ilDate($booking['access_startdate'], IL_CAL_DATETIME))
2115  .' - '.ilDatePresentation::formatDate(new ilDate($booking['access_enddate'], IL_CAL_DATETIME));
2116 
2117  }
2118  $oDurationGUI->setValue($frm_duration);
2119  $oForm->addItem($oDurationGUI);
2120 
2121  // price
2122  $oPriceGUI = new ilNonEditableValueGUI($this->lng->txt('price_a'));
2123  $oPriceGUI->setValue($booking['price'].' '.$booking['currency_unit']);
2124  $oForm->addItem($oPriceGUI);
2125 
2126  //discount
2127  $oDiscountGUI = new ilNonEditableValueGUI($this->lng->txt('paya_coupons_coupon'));
2128  $oDiscountGUI->setValue($booking['discount'].' '.$booking['currency_unit']);
2129  $oForm->addItem($oDiscountGUI);
2130 
2131  // payed
2132  $oPayedGUI = new ilSelectInputGUI();
2133  $payed_option = array(0 => $this->lng->txt('no'),1 => $this->lng->txt('yes'));
2134 
2135  $oPayedGUI->setTitle($this->lng->txt('paya_payed'));
2136  $oPayedGUI->setOptions($payed_option);
2137  $oPayedGUI->setValue($booking['payed']);
2138  $oPayedGUI->setPostVar('payed');
2139  $oForm->addItem($oPayedGUI);
2140 
2141  // access
2142  $oAccessGUI = new ilSelectInputGUI();
2143  $access_option = array(0 => $this->lng->txt('no'),1 => $this->lng->txt('yes'));
2144 
2145  $oAccessGUI->setTitle($this->lng->txt('paya_access'));
2146  $oAccessGUI->setOptions($access_option);
2147  $oAccessGUI->setValue($booking['access_granted']);
2148  $oAccessGUI->setPostVar('access');
2149  $oForm->addItem($oAccessGUI);
2150 
2151  $oForm->addCommandButton('updateStatistic',$this->lng->txt('save'));
2152  $oForm->addCommandButton('deleteStatistic',$this->lng->txt('delete'));
2153 
2154  // show CUSTOMER_DATA if isset -> setting: save_user_address
2155  if(ilPayMethods::_PMEnabled($booking['b_pay_method']))
2156  {
2157  $oForm2 = new ilPropertyFormGUI();
2158  $oForm2->setId('cust_form');
2159  $oForm2->setTableWidth('50%');
2160  $oForm2->setTitle($frm_user);
2161 
2162  // email
2163  $oEmailGUI = new ilNonEditableValueGUI($this->lng->txt('email'));
2164  $email = (!$tmp_user) ? $this->lng->txt('user_deleted') : $tmp_user->getEmail();
2165  $oEmailGUI->setValue($email);
2166  $oForm2->addItem($oEmailGUI);
2167 
2168  // street
2169  $oStreetGUI = new ilNonEditableValueGUI($this->lng->txt('street'));
2170  $oStreetGUI->setValue($booking['street']);
2171  $oForm2->addItem($oStreetGUI);
2172 
2173  // pobox
2174  $oPoBoxGUI = new ilNonEditableValueGUI($this->lng->txt('pay_bmf_po_box'));
2175  $oPoBoxGUI->setValue($booking['po_box']);
2176  $oForm2->addItem($oPoBoxGUI);
2177 
2178  // zipcode
2179  $oPoBoxGUI = new ilNonEditableValueGUI($this->lng->txt('zipcode'));
2180  $oPoBoxGUI->setValue($booking['zipcode']);
2181  $oForm2->addItem($oPoBoxGUI);
2182 
2183  // city
2184  $oCityGUI = new ilNonEditableValueGUI($this->lng->txt('city'));
2185  $oCityGUI->setValue($booking['city']);
2186  $oForm2->addItem($oCityGUI);
2187 
2188  // country
2189  $oCountryGUI = new ilNonEditableValueGUI($this->lng->txt('country'));
2190  $oCountryGUI->setValue($booking['country']);
2191  $oForm2->addItem($oCountryGUI);
2192  }
2193 
2194  $this->tpl->setVariable('FORM',$oForm->getHTML());
2195  $this->tpl->setVariable('FORM_2',$oForm2->getHTML());
2196  return true;
2197 
2198  }
2199  public function updateStatisticObject()
2200  {
2201  if(!isset($_GET['booking_id']))
2202  {
2203  ilUtil::sendInfo($this->lng->txt('paya_no_booking_id_given'));
2204  $this->statisticObject();
2205 
2206  return true;
2207  }
2208  $this->__initBookingObject();
2209 
2210  $this->booking_obj->setBookingId((int) $_GET['booking_id']);
2211  $this->booking_obj->setAccess((int) $_POST['access']);
2212  $this->booking_obj->setPayed((int) $_POST['payed']);
2213 
2214  if($this->booking_obj->update())
2215  {
2216  ilUtil::sendSuccess($this->lng->txt('paya_updated_booking'));
2217 
2218  $this->statisticObject();
2219  return true;
2220  }
2221  else
2222  {
2223  ilUtil::sendInfo($this->lng->txt('paya_error_update_booking'));
2224  $this->statisticObject();
2225 
2226  return true;
2227  }
2228  }
2229 
2230  public function deleteStatisticObject()
2231  {
2232  if(!isset($_GET['booking_id']))
2233  {
2234  ilUtil::sendInfo($this->lng->txt('paya_no_booking_id_given'));
2235  $this->statisticObject();
2236 
2237  return true;
2238  }
2239  ilUtil::sendQuestion($this->lng->txt('paya_sure_delete_stat'));
2240 
2241  $this->editStatisticObject(true);
2242 
2243  return true;
2244  }
2245  public function performDeleteObject()
2246  {
2247  if(!isset($_GET['booking_id']))
2248  {
2249  ilUtil::sendInfo($this->lng->txt('paya_no_booking_id_given'));
2250  $this->statisticObject();
2251 
2252  return true;
2253  }
2254 
2255  $this->__initBookingObject();
2256  $this->booking_obj->setBookingId((int) $_GET['booking_id']);
2257  if(!$this->booking_obj->delete())
2258  {
2259  die('Error deleting booking');
2260  }
2261  ilUtil::sendInfo($this->lng->txt('pay_deleted_booking'));
2262 
2263  $this->statisticObject();
2264 
2265  return true;
2266  }
2267 
2273  public function getTabs($tabs_gui)
2274  {
2275  global $rbacsystem, $ilHelp;
2276 
2277  $tabs_gui->clearTargets();
2278  $ilHelp->setScreenIdComponent("pays");
2279  if ($rbacsystem->checkAccess('visible,read',$this->object->getRefId()))
2280  {
2281  // Settings
2282  $tabs_gui->addTarget('settings', $this->ctrl->getLinkTarget($this, 'generalSettings'),
2283  array('saveGeneralSettings','generalSettings ','saveBmfSettings','savePaypalSettings','paypalSettings',
2284 // 'saveEPaySettings','epaySettings','saveERPsettings','delERPpreview','','testERPsettings','erpSettings',
2285  '','view'), '', '');
2286 
2287  // Bookings
2288  $tabs_gui->addTarget('bookings', $this->ctrl->getLinkTarget($this, 'statistic'),
2289  array( 'statistic','editStatistic','updateStatistic','deleteStatistic','performDelete',
2290  'resetFilter','exportVendors','addCustomer', 'saveCustomer','showObjectSelector',
2291  'searchUserSP','performSearchSP'), '', '');
2292  // Objects
2293  $tabs_gui->addTarget('objects', $this->ctrl->getLinkTarget($this, 'objects'),
2294  array('updateObjectDetails','deleteObject','performObjectDelete','objects',
2295  'editPrices','addPrice','editDetails','resetObjectFilter'), '', '');
2296  // Vendors
2297  $tabs_gui->addTarget('vendors', $this->ctrl->getLinkTarget($this, 'vendors'),
2298  array('vendors','searchUser','search','performSearch','addVendor','addUser','exportVendors','deleteVendors','performDeleteVendors',
2299  'cancelDeleteVendors','editVendor','performEditVendor'), '', '');
2300 
2301 #TODO: CURRENCY not finished yet
2302 /*
2303  // Currencies
2304  $tabs_gui->addTarget('currencies',
2305  $this->ctrl->getLinkTarget($this, 'currencies'),
2306  array('currencies','editCurrency','deleteCurrency','performDeleteCurrency','updateCurrency','updateDefaultCurrency'), '','');
2307 /**/
2308  // Paymethods
2309  $tabs_gui->addTarget('pay_methods', $this->ctrl->getLinkTarget($this, 'payMethods'),
2310  #array('payMethods','savePayMethods'), '', '');
2311  array('payMethods','savePayMethods ','saveBmfSettings','savePaypalSettings','paypalSettings',
2312 // 'saveEPaySettings','epaySettings','saveERPsettings','delERPpreview','','testERPsettings','erpSettings',
2313  '','view'), '', '');
2314 
2315  // Topics
2316  $tabs_gui->addTarget('topics',
2317  $this->ctrl->getLinkTargetByClass('ilshoptopicsgui', ''), 'payment_topics', '', '');
2318 
2319  // Vats
2320  $tabs_gui->addTarget('vats',
2321  $this->ctrl->getLinkTarget($this, 'vats'), 'vats', '', '');
2322 
2323  // Documents
2324  $tabs_gui->addTarget('documents', $this->ctrl->getLinkTarget($this, 'documents'),
2325  array('documents','TermsConditions','saveTermsConditions','BillingMail',
2326  'saveBillingMail','InvoiceNumber','saveInvoiceNumber','StatutoryRegulations', 'saveStatutoryRegulations'), '', '');
2327  }
2328 
2329  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
2330  {
2331  // Permissions
2332  $tabs_gui->addTarget('perm_settings',
2333  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), 'perm'), array('perm','info','owner'), 'ilpermissiongui');
2334  }
2335  }
2336 
2337  private function getSubTabs($a_tab, $a_sub_tab = null)
2338  {
2339  switch($a_tab)
2340  {
2341  case 'bookings':
2342  break;
2343  case 'objects':
2344  break;
2345  case 'vendors':
2346  break;
2347  case 'payMethods':
2348 
2349  if(!$a_sub_tab) $a_sub_tab = 'payMethods';
2350  $this->tabs_gui->addSubTabTarget('settings',
2351  $this->ctrl->getLinkTargetByClass('ilobjpaymentsettingsgui', 'payMethods'),
2352  '','', '',$a_sub_tab == 'payMethods' ? true : false);
2353 
2354  $this->tabs_gui->addSubTabTarget('pays_bmf',
2355  $this->ctrl->getLinkTargetByClass('ilobjpaymentsettingsgui', 'bmfSettings'),
2356  '','', '',$a_sub_tab == 'bmfSettings' ? true : false);
2357 
2358  $this->tabs_gui->addSubTabTarget('pays_paypal',
2359  $this->ctrl->getLinkTargetByClass('ilobjpaymentsettingsgui', 'paypalSettings'),
2360  '','', '',$a_sub_tab == 'paypalSettings' ? true : false);
2361 
2362 // $this->tabs_gui->addSubTabTarget('pays_epay',
2363 // $this->ctrl->getLinkTargetByClass('ilobjpaymentsettingsgui', 'epaySettings'),
2364 // '','', '',$a_sub_tab == 'epaySettings' ? true : false);
2365 //
2366 // $this->tabs_gui->addSubTabTarget('pays_erp',
2367 // $this->ctrl->getLinkTargetByClass('ilobjpaymentsettingsgui', 'erpSettings'),
2368 // '','', '',$a_sub_tab == 'erpSettings' ? true : false);
2369  break;
2370  case 'currencies':
2371  break;
2372  case 'vats':
2373  break;
2374  case 'topics':
2375  break;
2376  case 'documents':
2377  if(!$a_sub_tab) $a_sub_tab = 'terms_conditions';
2378  $this->tabs_gui->addSubTabTarget('terms_conditions',
2379  $this->ctrl->getLinkTargetByClass('ilobjpaymentsettingsgui', 'TermsConditions'),
2380  '','', '',$a_sub_tab == 'terms_conditions' ? true : false);
2381 
2382  $this->tabs_gui->addSubTabTarget('billing_mail',
2383  $this->ctrl->getLinkTargetByClass('ilobjpaymentsettingsgui', 'BillingMail'),
2384  '','', '',$a_sub_tab == 'billing_mail' ? true : false);
2385  $this->tabs_gui->addSubTabTarget('invoice_number',
2386  $this->ctrl->getLinkTargetByClass('ilobjpaymentsettingsgui', 'InvoiceNumber'),
2387  '','', '',$a_sub_tab == 'invoice_number' ? true : false);
2388  $this->tabs_gui->addSubTabTarget('statutory_regulations',
2389  $this->ctrl->getLinkTargetByClass('ilobjpaymentsettingsgui', 'StatutoryRegulations'),
2390  '','', '',$a_sub_tab == 'statutory_regulations' ? true : false);
2391  break;
2392 
2393  default:
2394  case 'settings':
2395  if (($_GET['cmd'] == '') || ($_GET['cmd'] == 'view') || ($a_sub_tab == 'generalSettings'))
2396  $a_sub_tab = 'generalSettings';
2397  break;
2398  }
2399  }
2400 
2401  public function generalSettingsObject()
2402  {
2403  global $rbacsystem, $ilSetting;
2404 
2408  // MINIMUM ACCESS LEVEL = 'read'
2409  if(!$rbacsystem->checkAccess('read', $this->object->getRefId()))
2410  {
2411  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$this->ilErr->MESSAGE);
2412  }
2413 
2414  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.main_view.html','Services/Payment');
2415 
2416  $genSet = ilPaymentSettings::_getInstance();
2417  $genSetData = $genSet->getAll();
2418 
2419  $form = new ilPropertyFormGUI();
2420  $form->setFormAction($this->ctrl->getFormAction($this, 'saveGeneralSettings'));
2421  $form->setTitle($this->lng->txt('pays_general_settings'));
2422 
2423  $form->addCommandButton('saveGeneralSettings',$this->lng->txt('save'));
2424 
2425  // enable webshop
2426  $formItem = new ilCheckboxInputGUI($this->lng->txt('pay_enable_shop'), 'shop_enabled');
2427  $formItem->setChecked((int)$genSetData['shop_enabled']);
2428  $formItem->setInfo($this->lng->txt('pay_enable_shop_info'));
2429  $form->addItem($formItem);
2430 
2431  $formItem = new ilTextInputGUI($this->lng->txt('pays_currency_unit'), 'currency_unit');
2432  $formItem->setSize(5);
2433  $formItem->setValue($this->error != '' && isset($_POST['currency_unit'])
2434  ? ilUtil::prepareFormOutput($_POST['currency_unit'],true)
2435  : ilUtil::prepareFormOutput($genSetData['currency_unit'],true));
2436  $formItem->setRequired(true);
2437  $form->addItem($formItem);
2438 
2439  $formItem = new ilTextAreaInputGUI($this->lng->txt('pays_address'), 'address');
2440  $formItem->setRows(7);
2441  $formItem->setCols(35);
2442  $formItem->setRequired(true);
2443  $formItem->setValue($this->error != '' && isset($_POST['address'])
2444  ? ilUtil::prepareFormOutput($_POST['address'],true)
2445  : $genSetData['address']);
2446  $form->addItem($formItem);
2447 
2448  $formItem = new ilTextAreaInputGUI($this->lng->txt('pays_bank_data'), 'bank_data');
2449  $formItem->setRows(7);
2450  $formItem->setCols(35);
2451  $formItem->setRequired(true);
2452  $formItem->setValue($this->error != '' && isset($_POST['bank_data'])
2453  ? ilUtil::prepareFormOutput($_POST['bank_data'],true)
2454  : $genSetData['bank_data']);
2455  $form->addItem($formItem);
2456 
2457  $formItem = new ilTextAreaInputGUI($this->lng->txt('pays_add_info'), 'add_info');
2458  $formItem->setRows(7);
2459  $formItem->setCols(35);
2460  $formItem->setValue($this->error != '' && isset($_POST['add_info'])
2461  ? ilUtil::prepareFormOutput($_POST['add_info'],true)
2462  : $genSetData['add_info']);
2463  $form->addItem($formItem);
2464 
2465  $formItem = new ilTextInputGUI($this->lng->txt('pays_pdf_path'), 'pdf_path');
2466  $formItem->setValue($this->error != "" && isset($_POST['pdf_path'])
2467  ? ilUtil::prepareFormOutput($_POST['pdf_path'],true)
2468  : ilUtil::prepareFormOutput($genSetData['pdf_path'],true));
2469  $formItem->setRequired(true);
2470  $form->addItem($formItem);
2471 
2472  // default sorting type
2473  $formItem = new ilSelectInputGUI($this->lng->txt('pay_topics_default_sorting_type'), 'topics_sorting_type');
2474  $formItem->setValue($genSetData['topics_sorting_type']);
2475  $options = array(
2476  1 => $this->lng->txt('pay_topics_sort_by_title'),
2477  2 => $this->lng->txt('pay_topics_sort_by_date'),
2478  3 => $this->lng->txt('pay_topics_sort_manually')
2479  );
2480  $formItem->setOptions($options);
2481  $form->addItem($formItem);
2482 
2483  // default sorting direction
2484  $formItem = new ilSelectInputGUI($this->lng->txt('pay_topics_default_sorting_direction'), 'topics_sorting_direction');
2485  $formItem->setValue($genSetData['topics_sorting_direction']);
2486  $options = array(
2487  'asc' => $this->lng->txt('sort_asc'),
2488  'desc' => $this->lng->txt('sort_desc'),
2489  );
2490  $formItem->setOptions($options);
2491  $form->addItem($formItem);
2492 
2493  // topics custom sorting
2494  $formItem = new ilCheckboxInputGUI($this->lng->txt('pay_topics_allow_custom_sorting'), 'topics_allow_custom_sorting');
2495  $formItem->setChecked((int)$genSetData['topics_allow_custom_sorting']);
2496  $formItem->setInfo($this->lng->txt('pay_topics_allow_custom_sorting_info'));
2497  $form->addItem($formItem);
2498 
2499  // objects custom sorting
2500 /* $formItem = new ilCheckboxInputGUI($this->lng->txt('pay_hide_filtering'), 'objects_allow_custom_sorting');
2501  $formItem->setChecked((int)$genSetData['objects_allow_custom_sorting']);
2502  $formItem->setInfo($this->lng->txt('pay_hide_filtering_info'));
2503  $form->addItem($formItem);
2504 */
2505  // max hits
2506  $formItem = new ilSelectInputGUI($this->lng->txt('pay_max_hits'), 'max_hits');
2507  $formItem->setValue($genSetData['max_hits']);
2508  $options = array();
2509  for($i = 10; $i <= 100; $i += 10)
2510  {
2511  $options[$i] = $i;
2512  }
2513  $formItem->setOptions($options);
2514  $formItem->setInfo($this->lng->txt('pay_max_hits_info'));
2515  $form->addItem($formItem);
2516 
2517  // hide advanced search
2518  $formItem = new ilCheckboxInputGUI($this->lng->txt('pay_hide_advanced_search'), 'hide_advanced_search');
2519  $formItem->setChecked((int)$genSetData['hide_advanced_search']);
2520  $formItem->setInfo($this->lng->txt('pay_hide_advanced_search_info'));
2521  $form->addItem($formItem);
2522 
2523  // hide shop news
2524  $formItem = new ilCheckboxInputGUI($this->lng->txt('pay_hide_news'), 'hide_news');
2525  $formItem->setChecked((int)$genSetData['hide_news']);
2526  $formItem->setInfo($this->lng->txt('pay_hide_news_info'));
2527  $form->addItem($formItem);
2528 
2529  // Hide coupons
2530  $formItem = new ilCheckboxInputGUI($this->lng->txt('pay_hide_coupons'), 'hide_coupons');
2531  $formItem->setChecked((int)$genSetData['hide_coupons']);
2532  $formItem->setInfo($this->lng->txt('pay_hide_coupons'));
2533  $form->addItem($formItem);
2534 
2535  // hide shop news
2536  $formItem = new ilCheckboxInputGUI($this->lng->txt('pay_hide_shop_info'), 'hide_shop_info');
2537  $formItem->setChecked((int)$genSetData['hide_shop_info']);
2538  $formItem->setInfo($this->lng->txt('pay_hide_shop_info_info'));
2539  $form->addItem($formItem);
2540 
2541  // use shop specials
2542  $formItem = new ilCheckboxInputGUI($this->lng->txt('use_shop_specials'), 'use_shop_specials');
2543  $formItem->setChecked((int)$genSetData['use_shop_specials']);
2544  $formItem->setInfo($this->lng->txt('use_shop_specials_info'));
2545  $form->addItem($formItem);
2546 
2547  // show general filter
2548  $formItem = new ilCheckboxInputGUI($this->lng->txt('show_general_filter'), 'show_general_filter');
2549  $formItem->setChecked((int)$genSetData['show_general_filter']);
2550  $formItem->setInfo($this->lng->txt('show_general_filter_info'));
2551  $form->addItem($formItem);
2552 
2553  // show topics filter
2554  $formItem = new ilCheckboxInputGUI($this->lng->txt('show_topics_filter'), 'show_topics_filter');
2555  $formItem->setChecked((int)$genSetData['show_topics_filter']);
2556  $formItem->setInfo($this->lng->txt('show_topics_filter_info'));
2557  $form->addItem($formItem);
2558 
2559  // show shop explorer
2560  $formItem = new ilCheckboxInputGUI($this->lng->txt('show_shop_explorer'), 'show_shop_explorer');
2561  $formItem->setChecked((int)$genSetData['show_shop_explorer']);
2562  $formItem->setInfo($this->lng->txt('show_shop_explorer_info'));
2563  $form->addItem($formItem);
2564 
2565 
2566  // Enable payment notifications
2567  $payment_noti = new ilCheckboxInputGUI($this->lng->txt("payment_notification"), "payment_notification");
2568  $payment_noti->setValue(1);
2569  $payment_noti->setChecked((int)$ilSetting->get('payment_notification', 0) == 1);
2570  $payment_noti->setInfo($this->lng->txt('payment_notification_desc'));
2571 
2572  $num_days = new ilNumberInputGUI($this->lng->txt('payment_notification_days'),'payment_notification_days');
2573  $num_days->setSize(3);
2574  $num_days->setMinValue(0);
2575  $num_days->setMaxValue(120);
2576  $num_days->setRequired(true);
2577  $num_days->setValue($ilSetting->get('payment_notification_days'));
2578  $num_days->setInfo($this->lng->txt('payment_notification_days_desc'));
2579 
2580  $payment_noti->addSubItem($num_days);
2581  $form->addItem($payment_noti);
2582 
2583 
2584  $this->tpl->setVariable('FORM',$form->getHTML());
2585  return true;
2586  }
2587 
2588  public function saveGeneralSettingsObject()
2589  {
2590  global $rbacsystem, $ilSetting;
2591 
2592  // MINIMUM ACCESS LEVEL = 'read'
2593  if(!$rbacsystem->checkAccess('read', $this->object->getRefId()))
2594  {
2595  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$this->ilErr->MESSAGE);
2596  }
2597 
2601  $genSet = ilPaymentSettings::_getInstance();
2602 
2603  if ($_POST['currency_unit'] == '' ||
2604  $_POST['address'] == '' ||
2605  $_POST['bank_data'] == '' ||
2606  $_POST['pdf_path'] == '')
2607  {
2608  $this->error = $this->lng->txt('pays_general_settings_not_valid');
2609  ilUtil::sendFailure($this->error);
2610  return $this->generalSettingsObject();
2611 
2612  }
2613 
2614  $genSet->set('currency_unit', $_POST['currency_unit'], 'currencies');
2615  $genSet->set('address', $_POST['address'], 'invoice');
2616  $genSet->set('bank_data', $_POST['bank_data'], 'invoice');
2617  $genSet->set('add_info', $_POST['add_info'], 'invoice');
2618  $genSet->set('pdf_path', $_POST['pdf_path'], 'invoice');
2619 
2620  $genSet->set('topics_allow_custom_sorting', $_POST['topics_allow_custom_sorting'], 'gui');
2621  $genSet->set('topics_sorting_type', $_POST['topics_sorting_type'], 'gui');
2622  $genSet->set('topics_sorting_direction', $_POST['topics_sorting_direction'], 'gui');
2623  $genSet->set('max_hits', $_POST['max_hits'], 'gui');
2624 
2625  $genSet->set('hide_advanced_search', $_POST['hide_advanced_search'], 'gui');
2626  #$genSet->set('hide_filtering', $_POST['hide_filtering'], 'gui');
2627  $genSet->set('objects_allow_custom_sorting', $_POST['objects_allow_custom_sorting'], 'gui');
2628  $genSet->set('hide_coupons', $_POST['hide_coupons'], 'gui');
2629  $genSet->set('hide_news', $_POST['hide_news'], 'gui');
2630 
2631  if( (int)$_POST['hide_news'] == 0 )
2632  {
2633  if( (int)$ilSetting->get('payment_news_archive_period') == 0)
2634  {
2635  $ilSetting->set('payment_news_archive_period', '5');
2636  }
2637  }
2638 
2639  $genSet->set('hide_shop_info', $_POST['hide_shop_info'], 'gui');
2640  $genSet->set('use_shop_specials', $_POST['use_shop_specials'], 'gui');
2641  $genSet->set('show_general_filter', $_POST['show_general_filter'], 'gui');
2642  $genSet->set('show_topics_filter', $_POST['show_topics_filter'], 'gui');
2643  $genSet->set('show_shop_explorer', $_POST['show_shop_explorer'], 'gui');
2644 
2645  // payment notification
2646  $ilSetting->set('payment_notification', $_POST['payment_notification'] ? 1 : 0);
2647  $ilSetting->set('payment_notification_days', $_POST['payment_notification_days']);
2648 
2649  $check = $this->checkShopActivationObject();
2650  if($check == true && (int)$_POST['shop_enabled'])
2651  {
2652  $genSet->set('shop_enabled', 1, 'common');
2653  }
2654  else
2655  {
2656  $genSet->set('shop_enabled', 0, 'common');
2657  }
2658  ilUtil::sendSuccess($this->lng->txt('pays_updated_general_settings'));
2659 
2660  $this->generalSettingsObject();
2661  return true;
2662  }
2663 
2664  public function paypalSettingsObject()
2665  {
2670  global $rbacsystem;
2671 
2672  // MINIMUM ACCESS LEVEL = 'read'
2673  if(!$rbacsystem->checkAccess('read', $this->object->getRefId()))
2674  {
2675  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$this->ilErr->MESSAGE);
2676  }
2677 
2678  include_once './Services/Payment/classes/class.ilPaypalSettings.php';
2679 
2680  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.main_view.html','Services/Payment');
2681 
2682  $ppSet = ilPaypalSettings::getInstance();
2683 
2684  $form = new ilPropertyFormGUI();
2685  $form->setFormAction($this->ctrl->getFormAction($this, 'savePaypalSettings'));
2686  $form->setTitle($this->lng->txt('pays_paypal_settings'));
2687 
2688  $form->addCommandButton('savePaypalSettings',$this->lng->txt('save'));
2689 
2690  $formItem = new ilTextInputGUI($this->lng->txt('pays_server_host'), 'server_host');
2691  $formItem->setValue($ppSet->getServerHost());
2692  $form->addItem($formItem);
2693 
2694  $formItem = new ilTextInputGUI($this->lng->txt('pays_server_path'), 'server_path');
2695  $formItem->setValue($ppSet->getServerPath());
2696  $form->addItem($formItem);
2697 
2698  $formItem = new ilTextInputGUI($this->lng->txt('pays_email_vendor'), 'vendor');
2699  $formItem->setValue($ppSet->getVendor());
2700  $form->addItem($formItem);
2701 
2702 // $formItem = new ilPasswordInputGUI($this->lng->txt('password'), 'vendor_password');
2703 // $formItem->setRetype(false);
2704 // $formItem->setValue($ppSet->getVendorPassword());
2705 // $form->addItem($formItem);
2706 
2707  $formItem = new ilTextInputGUI($this->lng->txt('pays_auth_token'), 'auth_token');
2708  $formItem->setValue($ppSet->getAuthToken());
2709  $form->addItem($formItem);
2710 
2711  $formItem = new ilTextInputGUI($this->lng->txt('pays_page_style'), 'page_style');
2712  $formItem->setValue($ppSet->getPageStyle());
2713  $form->addItem($formItem);
2714 
2715  $this->tpl->setVariable('FORM',$form->getHTML());
2716  }
2717 
2718  public function savePaypalSettingsObject()
2719  {
2720  include_once './Services/Payment/classes/class.ilPaypalSettings.php';
2721 
2722  global $rbacsystem;
2723 
2724  // MINIMUM ACCESS LEVEL = 'read'
2725  if(!$rbacsystem->checkAccess('read', $this->object->getRefId()))
2726  {
2727  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$this->ilErr->MESSAGE);
2728  }
2729 
2730  $ppSet = ilPaypalSettings::getInstance();
2731 
2732  $ppSet->setServerHost(ilUtil::stripSlashes($_POST['server_host']));
2733  $ppSet->setServerPath(ilUtil::stripSlashes($_POST['server_path']));
2734  $ppSet->setVendor(ilUtil::stripSlashes($_POST['vendor']));
2735 // $ppSet->setVendorPassword(ilUtil::stripSlashes($_POST['vendor_password']));
2736  $ppSet->setAuthToken(ilUtil::stripSlashes($_POST['auth_token']));
2737  $ppSet->setPageStyle(ilUtil::stripSlashes($_POST['page_style']));
2738  $ppSet->setSsl(ilUtil::stripSlashes($_POST['ssl']));
2739 
2740  if ($_POST['server_host'] == '' ||
2741  $_POST['server_path'] == '' ||
2742  $_POST['vendor'] == '' ||
2743 // $_POST['vendor_password'] == '' ||
2744  $_POST['auth_token'] == '')
2745  {
2746  $this->error = $this->lng->txt('pays_paypal_settings_not_valid');
2747  ilUtil::sendFailure($this->error);
2748  $this->paypalSettingsObject();
2749  return true;
2750 
2751  }
2752 
2753  $ppSet->save();
2754 
2755  $this->paypalSettingsObject();
2756 
2757  ilUtil::sendSuccess($this->lng->txt('pays_updated_paypal_settings'));
2758 
2759  return true;
2760  }
2761 
2762  //function vendorsObject($a_show_confirm = false)
2763  public function vendorsObject($a_show_confirm = false)
2764  {
2765  // include_once './Services/Payment/classes/class.ilPaymentBookings.php';
2766  #include_once './Services/Table/classes/class.ilTable2GUI.php';
2767 
2768  global $rbacsystem, $ilToolbar;
2769 
2770  // MINIMUM ACCESS LEVEL = 'read'
2771  if(!$rbacsystem->checkAccess('read', $this->object->getRefId()))
2772  {
2773  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$this->ilErr->MESSAGE);
2774  }
2775 
2776  $_SESSION['pays_vendor'] = is_array($_SESSION['pays_vendor']) ? $_SESSION['pays_vendor'] : array();
2777 
2778  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.main_view.html','Services/Payment');
2779 
2780  // add vendors
2782  $this,
2783  $ilToolbar,
2784  array(
2785  'auto_complete_name' => $this->lng->txt('user'),
2786  'user_type' => null,
2787  'submit_name' => $this->lng->txt('add')
2788  ));
2789 
2790  if(!count($vendors = $this->vendors_obj->getVendors()))
2791  {
2792  ilUtil::sendInfo($this->lng->txt('pay_no_vendors_created'));
2793  }
2794 
2795  if($a_show_confirm)
2796  {
2797  $oConfirmationGUI = new ilConfirmationGUI();
2798 
2799  // set confirm/cancel commands
2800  $oConfirmationGUI->setFormAction($this->ctrl->getFormAction($this,"performDeleteVendors"));
2801  $oConfirmationGUI->setHeaderText($this->lng->txt("pays_sure_delete_selected_vendors"));
2802  $oConfirmationGUI->setCancel($this->lng->txt("cancel"), "vendors");
2803  $oConfirmationGUI->setConfirm($this->lng->txt("confirm"), "performDeleteVendors");
2804 
2805  foreach($vendors as $vendor)
2806  {
2807  if(in_array($vendor['vendor_id'],$_SESSION['pays_vendor']))
2808  {
2809  // GET USER OBJ
2810  if($tmp_obj = ilObjectFactory::getInstanceByObjId($vendor['vendor_id'],false))
2811  {
2812  $delete_row = '';
2813  $delete_row = $tmp_obj->getLogin().' '.
2814  $vendor['cost_center'].' '.
2815  ilPaymentBookings::_getCountBookingsByVendor($vendor['vendor_id']);
2816  $oConfirmationGUI->addItem('',$delete_row, $delete_row);
2817  unset($tmp_obj);
2818  }
2819  }
2820  } // END VENDORS TABLE
2821 
2822  if(count($vendors) == count($_SESSION['pays_vendor']))
2823  {
2824  ilUtil::sendInfo($this->lng->txt('shop_disabled_no_vendors'));
2825  $_SESSION['disable_shop'] = true;
2826  }
2827  $this->tpl->setVariable('CONFIRMATION', $oConfirmationGUI->getHTML()); #
2828  return true;
2829  }
2830 
2831  $counter = 0;
2832  $f_result = array();
2833  foreach($vendors as $vendor)
2834  {
2835  // GET USER OBJ
2836  if($tmp_obj = ilObjectFactory::getInstanceByObjId($vendor['vendor_id'],false))
2837  {
2838  $f_result[$counter]['vendor_id'] = ilUtil::formCheckbox(in_array($vendor['vendor_id'],
2839  $_SESSION['pays_vendor']) ? 1 : 0, "vendor[]", $vendor['vendor_id']);
2840  $f_result[$counter]['login'] = $tmp_obj->getLogin();
2841  $f_result[$counter]['cost_center'] = $vendor['cost_center'];
2842  $f_result[$counter]['number_bookings'] = ilPaymentBookings::_getCountBookingsByVendor($vendor['vendor_id']);
2843 
2844  unset($tmp_obj);
2845  ++$counter;
2846  }
2847  } // END VENDORS TABLE
2848  $this->__showVendorsTable($f_result);
2849 
2850  return true;
2851  }
2852 
2853  public function exportVendorsObject()
2854  {
2855  include_once './Services/Payment/classes/class.ilPaymentExcelWriterAdapter.php';
2856 
2857  $pewa = new ilPaymentExcelWriterAdapter('payment_vendors.xls');
2858 
2859  // add/fill worksheet
2860  $this->addVendorWorksheet($pewa);
2861  $this->addStatisticWorksheet($pewa);
2862 
2863  // HEADER SENT
2864 
2865  $workbook = $pewa->getWorkbook();
2866  @$workbook->close();
2867  }
2868 
2869  public function addStatisticWorksheet(&$pewa)
2870  {
2871  include_once './Services/Excel/classes/class.ilExcelUtils.php';
2872  include_once './Services/Payment/classes/class.ilPaymentVendors.php';
2873 
2874  $this->__initBookingObject();
2875 
2876  $workbook = $pewa->getWorkbook();
2877  $worksheet = $workbook->addWorksheet(utf8_decode($this->lng->txt('bookings')));
2878 
2879  $worksheet->mergeCells(0,0,0,3);
2880  $worksheet->setColumn(0,0,16);
2881  $worksheet->setColumn(0,1,32);
2882  $worksheet->setColumn(0,2,32);
2883  $worksheet->setColumn(0,3,16);
2884  $worksheet->setColumn(0,4,16);
2885  $worksheet->setColumn(0,5,16);
2886  $worksheet->setColumn(0,6,24);
2887  $worksheet->setColumn(0,7,8);
2888  $worksheet->setColumn(0,8,12);
2889  $worksheet->setColumn(0,9,16);
2890 
2891  $title = $this->lng->txt('bookings');
2892  $title .= ' '.$this->lng->txt('as_of').' ';
2893  $title .= strftime('%Y-%m-%d %R',time());
2894 
2895  $worksheet->writeString(0,0,$title,$pewa->getFormatTitle());
2896 
2897  $worksheet->writeString(1,0,$this->lng->txt('payment_system'),$pewa->getFormatHeader());
2898  $worksheet->writeString(1,1,$this->lng->txt('paya_transaction'),$pewa->getFormatHeader());
2899  $worksheet->writeString(1,2,$this->lng->txt('title'),$pewa->getFormatHeader());
2900  $worksheet->writeString(1,3,$this->lng->txt('paya_vendor'),$pewa->getFormatHeader());
2901  $worksheet->writeString(1,4,$this->lng->txt('pays_cost_center'),$pewa->getFormatHeader());
2902  $worksheet->writeString(1,5,$this->lng->txt('paya_customer'),$pewa->getFormatHeader());
2903  $worksheet->writeString(1,6,$this->lng->txt('email'),$pewa->getFormatHeader());
2904  $worksheet->writeString(1,7,$this->lng->txt('paya_order_date'),$pewa->getFormatHeader());
2905  $worksheet->writeString(1,8,$this->lng->txt('duration'),$pewa->getFormatHeader());
2906  $worksheet->writeString(1,9,$this->lng->txt('price_a'),$pewa->getFormatHeader());
2907  $worksheet->writeString(1,10,$this->lng->txt('paya_payed_access'),$pewa->getFormatHeader());
2908 
2909  $worksheet->writeString(1,11,$this->lng->txt('street'),$pewa->getFormatHeader());
2910  $worksheet->writeString(1,12,$this->lng->txt('pay_bmf_po_box'),$pewa->getFormatHeader());
2911  $worksheet->writeString(1,13,$this->lng->txt('zipcode'),$pewa->getFormatHeader());
2912  $worksheet->writeString(1,14,$this->lng->txt('city'),$pewa->getFormatHeader());
2913  $worksheet->writeString(1,15,$this->lng->txt('country'),$pewa->getFormatHeader());
2914 
2915  if(!count($bookings = $this->booking_obj->getBookings()))
2916  {
2917  return false;
2918  }
2919 
2920  include_once 'Services/User/classes/class.ilObjUser.php';
2921  $object_title_cache = array();
2922  $user_title_cache = array();
2923 
2924  $counter = 2;
2925  foreach($bookings as $booking)
2926  {
2927  if(array_key_exists($booking['ref_id'], $object_title_cache))
2928  {
2929  $tmp_obj = $object_title_cache[$booking['ref_id']];
2930  }
2931  else
2932  {
2933  $tmp_obj = ilObject::_lookupTitle(ilObject::_lookupObjId($booking['ref_id']));
2934  $object_title_cache[$booking['ref_id']] = $tmp_obj;
2935  }
2936  if(array_key_exists($booking['b_vendor_id'], $user_title_cache))
2937  {
2938  $tmp_vendor = $user_title_cache[$booking['b_vendor_id']];
2939  }
2940  else
2941  {
2942  $tmp_vendor = ilObjUser::_lookupLogin($booking['b_vendor_id']);
2943  $user_title_cache[$booking['b_vendor_id']] = $tmp_vendor;
2944  }
2945  if(array_key_exists($booking['customer_id'], $user_title_cache))
2946  {
2947  $tmp_purchaser = $user_title_cache[$booking['customer_id']];
2948  }
2949  else
2950  {
2951  $tmp_purchaser_name = ilObjUser::_lookupName($booking['customer_id']);
2952  $tmp_purchaser_login = ilObjUser::_lookupLogin($booking['customer_id']);
2953  $tmp_purchaser_email = ilObjUser::_lookupEmail($booking['customer_id']);
2954  $tmp_purchaser = ''.$tmp_purchaser_name['firstname'].' '.$tmp_purchaser_name['lastname'].' ['.$tmp_purchaser_login.']';
2955  $user_title_cache[$booking['customer_id']] = $tmp_purchaser;
2956  }
2957 
2958  include_once './Services/Payment/classes/class.ilPayMethods.php';
2959  $str_paymethod = ilPayMethods::getStringByPaymethod($booking['b_pay_method']);
2960 
2961  $worksheet->writeString($counter,0,$str_paymethod);
2962  $worksheet->writeString($counter,1,$booking['transaction']);
2963  $worksheet->writeString($counter,2,($tmp_obj != '' ? $tmp_obj : $this->lng->txt('object_deleted')));
2964  $worksheet->writeString($counter,3,($tmp_vendor != '' ? $tmp_vendor : $this->lng->txt('user_deleted')));
2965  $worksheet->writeString($counter,4,ilPaymentVendors::_getCostCenter($booking['b_vendor_id']));
2966  $worksheet->writeString($counter,5,($tmp_purchaser != '' ? $tmp_purchaser : $this->lng->txt('user_deleted')));
2967  $worksheet->writeString($counter,6,$tmp_purchaser_email);
2968  $worksheet->writeString($counter,7,strftime('%Y-%m-%d %R',$booking['order_date']));
2969  $worksheet->writeString($counter,8,$booking['duration']);
2970  $worksheet->writeString($counter,9,$booking['price']);
2971 
2972  $payed_access = $booking['payed'] ?
2973  $this->lng->txt('yes') :
2974  $this->lng->txt('no');
2975 
2976  $payed_access .= '/';
2977  $payed_access .= $booking['access_granted'] ?
2978  $this->lng->txt('yes') :
2979  $this->lng->txt('no');
2980 
2981  $worksheet->writeString($counter,10,$payed_access);
2982 
2983  $worksheet->writeString($counter,11,$booking['street']);
2984  $worksheet->writeString($counter,12,$booking['po_box']);
2985  $worksheet->writeString($counter,13,$booking['zipcode']);
2986  $worksheet->writeString($counter,14,$booking['city']);
2987  $worksheet->writeString($counter,15,$booking['country']);
2988 
2989  unset($tmp_obj);
2990  unset($tmp_vendor);
2991  unset($tmp_purchaser);
2992 
2993  ++$counter;
2994  }
2995  return true;
2996  }
2997 
2998  public function addVendorWorksheet($pewa)
2999  {
3000  include_once './Services/Excel/classes/class.ilExcelUtils.php';
3001 
3002  $workbook = $pewa->getWorkbook();
3003  $worksheet = $workbook->addWorksheet($this->lng->txt('pays_vendor'));
3004 
3005  // SHOW HEADER
3006  $worksheet->mergeCells(0,0,0,2);
3007  $worksheet->setColumn(1,0,32);
3008  $worksheet->setColumn(1,1,32);
3009  $worksheet->setColumn(1,2,32);
3010 
3011  $title = $this->lng->txt('pays_vendor');
3012  $title .= ' '.$this->lng->txt('as_of').' ';
3013  $title .= strftime('%Y-%m-%d %R',time());
3014 
3015  $worksheet->writeString(0,0,$title,$pewa->getFormatTitle());
3016 
3017  $worksheet->writeString(1,0,$this->lng->txt('login'),$pewa->getFormatHeader());
3018  $worksheet->writeString(1,1,$this->lng->txt('fullname'),$pewa->getFormatHeader());
3019  $worksheet->writeString(1,2,$this->lng->txt('pays_cost_center'),$pewa->getFormatHeader());
3020 
3021  if(!count($vendors = $this->vendors_obj->getVendors()))
3022  {
3023  return false;
3024  }
3025 
3026  $counter = 2;
3027  foreach($vendors as $vendor)
3028  {
3029  // GET USER OBJ
3030  if($tmp_obj = ilObjectFactory::getInstanceByObjId($vendor['vendor_id'],false))
3031  {
3032  $worksheet->writeString($counter,0,$tmp_obj->getLogin());
3033  $worksheet->writeString($counter,1,$tmp_obj->getFullname());
3034  $worksheet->writeString($counter,2,$vendor['cost_center']);
3035  }
3036  unset($tmp_obj);
3037  ++$counter;
3038  }
3039  return true;
3040  }
3041 
3042  public function payMethodsObject($askForDeletingAddresses = array())
3043  {
3044  include_once './Services/Payment/classes/class.ilPayMethods.php';
3045 
3046  global $rbacsystem, $ilCtrl;
3047 
3048  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.main_view.html','Services/Payment');
3049 
3050  if(!$rbacsystem->checkAccess('read', $this->object->getRefId()))
3051  {
3052  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$this->ilErr->MESSAGE);
3053  }
3054 
3055  if(count($askForDeletingAddresses))
3056  {
3057  $oConfirmationGUI = new ilConfirmationGUI();
3058 
3059  // set confirm/cancel commands
3060  $oConfirmationGUI->setFormAction($ilCtrl->getFormAction($this, "deleteAddressesForPaymethods"));
3061  $oConfirmationGUI->setHeaderText($this->lng->txt("info_delete_sure"));
3062  $oConfirmationGUI->setCancel($this->lng->txt("cancel"), "payMethods");
3063  $oConfirmationGUI->setConfirm($this->lng->txt("confirm"), "deleteAddressesForPaymethods");
3064 
3065  foreach($askForDeletingAddresses as $pm_id)
3066  {
3067  $pm_obj = new ilPayMethods($pm_id);
3068  $oConfirmationGUI->additem('paymethod['.$pm_obj->getPmId().']',$pm_obj->getPmId(), $this->lng->txt('delete_addresses_bill').' -> '.ilPayMethods::getStringByPaymethod($pm_obj->getPmTitle()));
3069  }
3070 
3071  $this->tpl->setVariable('CONFIRMATION', $oConfirmationGUI->getHtml());
3072  return true;
3073  }
3074 
3075  $obj_paymethods = new ilPayMethods();
3076  $paymethods = $obj_paymethods->readAll();
3077 
3078  $result = array();
3079  $counter = 0;
3080  foreach($paymethods as $paymethod)
3081  {
3082  if($paymethod['pm_title'] != 'epay')
3083  {
3084  $result[$counter]['pm_title'] = ilPayMethods::getStringByPaymethod($paymethod['pm_title']);
3085  $result[$counter]['pm_enabled'] = ilUtil::formCheckbox($paymethod['pm_enabled'] ? 1 : 0,'pm_enabled['.$paymethod['pm_id'].']',1);
3086  $result[$counter]['save_usr_adr'] = ilUtil::formCheckbox($paymethod['save_usr_adr'] ? 1 : 0,'save_usr_adr['.$paymethod['pm_id'].']',1);
3087  $this->ctrl->clearParameters($this);
3088  $counter++;
3089  }
3090  }
3091 
3092  $this->ctrl->setParameter($this, 'cmd', 'savePayMethods');
3093  $tbl = new ilShopTableGUI($this);
3094  $tbl->setTitle($this->lng->txt('pays_pay_methods'));
3095 
3096  $tbl->setId('tbl_paymethods');
3097  $tbl->setRowTemplate("tpl.shop_paymethods_row.html", "Services/Payment");
3098 
3099  $tbl->addColumn($this->lng->txt('title'), 'pm_title', '10%');
3100  $tbl->addColumn($this->lng->txt('enabled'), 'pm_enabled', '10%');
3101  $tbl->addColumn($this->lng->txt('save_customer_address'),'save_usr_adr','10%');
3102  $tbl->addCommandButton('savePayMethods', $this->lng->txt('save'));
3103 
3104  $tbl->disable('sort');
3105  $tbl->setData($result);
3106 
3107  $this->tpl->setVariable('TABLE', $tbl->getHTML());
3108 
3109  return true;
3110  }
3111 
3112  public function savePayMethodsObject()
3113  {
3114  include_once './Services/Payment/classes/class.ilPayMethods.php';
3115 
3116  global $rbacsystem;
3117 
3118  if(!$rbacsystem->checkAccess('read', $this->object->getRefId()))
3119  {
3120  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$this->ilErr->MESSAGE);
3121  }
3122 
3123  $obj_paymethods = new ilPayMethods();
3124  $paymethods = $obj_paymethods->readAll();
3125 
3126  $askForDeletingAddresses = array();
3127 
3128  $pm_enabled = (array)$_POST['pm_enabled'];
3129  $pm_addr = (array)$_POST['save_usr_adr'];
3130 
3131  if(!$pm_enabled)
3132  {
3133  ilUtil::sendInfo($this->lng->txt('shop_disabled_no_paymethods'));
3134  $this->genSetData->set('shop_enabled', 0, 'common');
3135  $_SESSION['disable_shop'] = false;
3136  }
3137 
3138  $info_msg = array();
3139  foreach($paymethods as $paymethod)
3140  {
3141  if(
3142  (!isset($pm_enabled[$paymethod['pm_id']]) || !$pm_enabled[$paymethod['pm_id']]) &&
3143  $paymethod['pm_enabled']
3144  )
3145  {
3146  if(ilPaymentObject::_getCountObjectsByPayMethod($paymethod['pm_id']))
3147  {
3148  $info_msg[] = $this->lng->txt('pays_objects_'.$paymethod['pm_title'].'_exist');
3149  }
3150  }
3151  }
3152  if($info_msg)
3153  {
3154  ilUtil::sendInfo(implode('<br />', $info_msg));
3155  $this->payMethodsObject();
3156  return;
3157  }
3158 
3159  $num_changed = 0;
3160  foreach($paymethods as $paymethod)
3161  {
3162  if(
3163  (!isset($pm_enabled[$paymethod['pm_id']]) || !$pm_enabled[$paymethod['pm_id']]) &&
3164  $paymethod['pm_enabled']
3165  )
3166  {
3167  ilPayMethods::_PMdisable($paymethod['pm_id']);
3168  ++$num_changed;
3169  }
3170  else if(isset($pm_enabled[$paymethod['pm_id']]) && $pm_enabled[$paymethod['pm_id']] && !$paymethod['pm_enabled'])
3171  {
3172  ilPayMethods::_PMenable($paymethod['pm_id']);
3173  ++$num_changed;
3174  }
3175 
3176  if(
3177  (!isset($pm_addr[$paymethod['pm_id']]) || !$pm_addr[$paymethod['pm_id']]) &&
3178  $paymethod['save_usr_adr'])
3179  {
3180  $askForDeletingAddresses[] = $paymethod['pm_id'];
3181  }
3182  else if(
3183  (!isset($pm_addr[$paymethod['pm_id']]) || !$pm_addr[$paymethod['pm_id']]) &&
3184  !$paymethod['save_usr_adr']
3185  )
3186  {
3187  continue;
3188  }
3189  else
3190  {
3191  ilPayMethods::_enableSaveUserAddress($paymethod['pm_id']);
3192  ++$num_changed;
3193  }
3194  }
3195  if($num_changed && !$askForDeletingAddresses)
3196  {
3197  ilUtil::sendSuccess($this->lng->txt('pays_updated_pay_method'));
3198  }
3199  $this->payMethodsObject($askForDeletingAddresses);
3200 
3201  return true;
3202  }
3203 
3204  public function cancelDeleteVendorsObject()
3205  {
3206  unset($_SESSION['pays_vendor']);
3207  $_SESSION['disable_shop'] = false;
3208  $this->vendorsObject();
3209 
3210  return true;
3211  }
3212 
3213  public function deleteVendorsObject()
3214  {
3215  //include_once './Services/Payment/classes/class.ilPaymentBookings.php';
3216 
3217  if(!count($_POST['vendor']))
3218  {
3219  ilUtil::sendFailure($this->lng->txt('pays_no_vendor_selected'));
3220  $this->vendorsObject();
3221 
3222  return true;
3223  }
3224  // CHECK BOOKINGS
3225  foreach($_POST['vendor'] as $vendor)
3226  {
3228  {
3229  ilUtil::sendInfo($this->lng->txt('pays_active_bookings'));
3230  $this->vendorsObject();
3231 
3232  return true;
3233  }
3234  }
3235 
3236  $_SESSION['pays_vendor'] = $_POST['vendor'];
3237  ilUtil::sendQuestion($this->lng->txt('pays_sure_delete_selected_vendors'));
3238  $this->vendorsObject(true);
3239 
3240  return true;
3241  }
3242 
3243  public function performDeleteVendorsObject()
3244  {
3245  include_once './Services/Payment/classes/class.ilPaymentTrustees.php';
3246 
3247  global $rbacsystem;
3248 
3249  // MINIMUM ACCESS LEVEL = 'read'
3250  if(!$rbacsystem->checkAccess('write', $this->object->getRefId()))
3251  {
3252  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_write'),$this->ilErr->MESSAGE);
3253  }
3254 
3255  foreach($_SESSION['pays_vendor'] as $vendor)
3256  {
3257  $this->vendors_obj->delete($vendor);
3259  }
3260 
3261  ilUtil::sendInfo($this->lng->txt('pays_deleted_number_vendors').' '.count($_SESSION['pays_vendor']));
3262  unset($_SESSION['pays_vendor']);
3263  if($_SESSION['disable_shop'] == true)
3264  {
3265  $this->genSetData->set('shop_enabled', 0, 'common');
3266  $_SESSION['disable_shop'] = false;
3267  }
3268 
3269  $this->vendorsObject();
3270 
3271  return true;
3272  }
3273 
3274  public function editVendorObject()
3275  {
3276  global $rbacsystem;
3277 
3278  // MINIMUM ACCESS LEVEL = 'read'
3279  if(!$rbacsystem->checkAccess("write", $this->object->getRefId()))
3280  {
3281  $this->ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilErr->MESSAGE);
3282  }
3283 
3284  if(!count($_POST['vendor']))
3285  {
3286  ilUtil::sendInfo($this->lng->txt('pays_no_vendor_selected'));
3287  $this->vendorsObject();
3288 
3289  return true;
3290  }
3291  if(count($_POST['vendor']) > 1)
3292  {
3293  ilUtil::sendInfo($this->lng->txt('pays_too_many_vendors_selected'));
3294  $this->vendorsObject();
3295 
3296  return true;
3297  }
3298 
3299  $_SESSION['pays_vendor'] = $_POST['vendor'][0];
3300 
3301  if (!is_array($this->vendors_obj->vendors[$_SESSION['pays_vendor']]))
3302  {
3303  $this->vendorsObject();
3304 
3305  return true;
3306  }
3307 
3308  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
3309 
3310  $form_gui = new ilPropertyFormGUI();
3311  $form_gui->setFormAction($this->ctrl->getFormAction($this, 'performEditVendor'));
3312  $form_gui->setTitle($this->lng->txt('pays_vendor'));
3313 
3314  $oVendorGUI = new ilNonEditableValueGUI($this->lng->txt('pays_vendor'));
3315  $oVendorGUI->setValue(ilObjUser::getLoginByUserId($this->vendors_obj->vendors[$_SESSION['pays_vendor']]['vendor_id']), true);
3316  $form_gui->addItem($oVendorGUI);
3317 
3318  $oCostcenterGUI = new ilTextInputGUI($this->lng->txt('pays_cost_center'),'cost_center');
3319  $oCostcenterGUI->setValue($this->error != '' && isset($_POST['cost_center'])
3320  ? ilUtil::prepareFormOutput($_POST['cost_center'],true)
3321  : ilUtil::prepareFormOutput($this->vendors_obj->vendors[$_SESSION['pays_vendor']]['cost_center'],true));
3322  $form_gui->addItem($oCostcenterGUI);
3323 
3324  $form_gui->addCommandButton('performEditVendor',$this->lng->txt('save'));
3325  $this->tpl->setVariable('FORM', $form_gui->getHTML());
3326  return true;
3327  }
3328 
3329  public function performEditVendorObject()
3330  {
3331  global $rbacsystem;
3332 
3333  // MINIMUM ACCESS LEVEL = 'read'
3334  if(!$rbacsystem->checkAccess('write', $this->object->getRefId()))
3335  {
3336  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_write'),$this->ilErr->MESSAGE);
3337  }
3338 
3339  if(!count($_SESSION['pays_vendor']))
3340  {
3341  ilUtil::sendInfo($this->lng->txt('pays_no_vendor_selected'));
3342  $this->vendorsObject();
3343 
3344  return true;
3345  }
3346  if(count($_SESSION['pays_vendor']) > 1)
3347  {
3348  ilUtil::sendInfo($this->lng->txt('pays_too_many_vendors_selected'));
3349  $this->vendorsObject();
3350 
3351  return true;
3352  }
3353 
3354  if (!is_array($this->vendors_obj->vendors[$_SESSION['pays_vendor']]))
3355  {
3356  $this->vendorsObject();
3357  return true;
3358  }
3359 
3360  if ($_POST['cost_center'] == '')
3361  {
3362  $this->error = $this->lng->txt('pays_cost_center_not_valid');
3363  ilUtil::sendFailure($this->error);
3364  $_POST['vendor'] = array($_SESSION['pays_vendor']);
3365  return $this->editVendor();
3366 
3367  }
3368 
3369  $this->vendors_obj->update($_SESSION['pays_vendor'], $_POST['cost_center']);
3370 
3371  unset($_SESSION['pays_vendor']);
3372 
3373  $this->vendorsObject();
3374 
3375  return true;
3376  }
3377 
3378  public function showObjectSelectorObject()
3379  {
3380  global $rbacsystem, $tree, $ilToolbar;
3381 
3382  // MINIMUM ACCESS LEVEL = 'read'
3383  if(!$rbacsystem->checkAccess('read', $this->object->getRefId()))
3384  {
3385  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$this->ilErr->MESSAGE);
3386  }
3387 
3388  include_once './Services/Payment/classes/class.ilPaymentObjectSelector.php';
3389 
3390  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.paya_object_selector.html','Services/Payment');
3391 
3392  $ilToolbar->addButton($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'statistic'));
3393 
3394  ilUtil::sendInfo($this->lng->txt('paya_select_object_to_sell'));
3395 
3396  $exp = new ilPaymentObjectSelector($this->ctrl->getLinkTarget($this,'showObjectSelector'), (string)strtolower(get_class($this)));
3397  $exp->setExpand($_GET['paya_link_expand'] ? $_GET['paya_link_expand'] : $tree->readRootId());
3398  $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'showObjectSelector'));
3399 
3400  $exp->setOutput(0);
3401 
3402  $this->tpl->setVariable('EXPLORER',$exp->getOutput());
3403 
3404  return true;
3405  }
3406 
3407  public function searchUserObject()
3408  {
3409 /* global $rbacsystem, $ilToolbar;
3410 
3411  // MINIMUM ACCESS LEVEL = 'read'
3412  if(!$rbacsystem->checkAccess('read', $this->object->getRefId()))
3413  {
3414  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$this->ilErr->MESSAGE);
3415  }
3416 
3417  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
3418 
3419  $ilToolbar->addButton($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'vendors'));
3420 
3421  $this->lng->loadLanguageModule('search');
3422 
3423  $form_gui = new ilPropertyFormGUI();
3424  $form_gui->setFormAction($this->ctrl->getFormAction($this));
3425  $form_gui->setTitle($this->lng->txt('crs_search_members'));
3426  $form_gui->setId('search_form');
3427 
3428  $oTitle = new ilTextInputGUI($this->lng->txt('search_search_term'), 'search_str');
3429  $oTitle->setMaxLength(255);
3430  $oTitle->setSize(40);
3431  $oTitle->setValue($_POST['search_str']); // $_SESSION['pays_search_str']
3432  $form_gui->addItem($oTitle);
3433 
3434  // buttons
3435  $form_gui->addCommandButton('search', $this->lng->txt('search'));
3436  $form_gui->addCommandButton('vendors', $this->lng->txt('cancel')); //??vendors
3437 
3438  $this->tpl->setVariable('FORM',$form_gui->getHTML());
3439  return true;*/
3440  }
3441 
3442  public function searchObject()
3443  {
3444  global $rbacsystem;
3445 
3446  if(!$rbacsystem->checkAccess('read', $this->object->getRefId()))
3447  {
3448  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$this->ilErr->MESSAGE);
3449  }
3450 
3451  $_SESSION['pays_search_str'] = $_POST['search_str'] = $_POST['search_str'] ? $_POST['search_str'] : $_SESSION['pays_search_str'];
3452 
3453  if(!isset($_POST['search_str']))
3454  {
3455  ilUtil::sendInfo($this->lng->txt('crs_search_enter_search_string'));
3456  $this->searchUserObject();
3457 
3458  return false;
3459  }
3460  if(!count($result = $this->__search(ilUtil::stripSlashes($_POST['search_str']))))
3461  {
3462  ilUtil::sendInfo($this->lng->txt('crs_no_results_found'));
3463  $this->searchUserObject();
3464 
3465  return false;
3466  }
3467 
3468  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.main_view.html','Services/Payment');
3469 
3470  $counter = 0;
3471  $f_result = array();
3472  foreach($result as $user)
3473  {
3474  if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($user['id'],false))
3475  {
3476  continue;
3477  }
3478  $f_result[$counter]['vendor_id'] = ilUtil::formCheckbox(0,'user[]',$user['id']);
3479  $f_result[$counter]['login'] = $tmp_obj->getLogin();
3480  $f_result[$counter]['lastname'] = $tmp_obj->getLastname();
3481  $f_result[$counter]['firstname'] = $tmp_obj->getFirstname();
3482 
3483  unset($tmp_obj);
3484  ++$counter;
3485  }
3486  $this->__showSearchUserTable($f_result);
3487 
3488  return true;
3489  }
3490 
3491  function addVendorObject()
3492  {
3493  global $rbacsystem;
3494 
3495  // MINIMUM ACCESS LEVEL = 'administrate'
3496  if(!$rbacsystem->checkAccess('write', $this->object->getRefId()))
3497  {
3498  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_write'),$this->ilErr->MESSAGE);
3499  }
3500  if(!$_POST['user_login'])
3501  {
3502  ilUtil::sendFailure($this->lng->txt('pays_no_username_given'));
3503  $this->vendorsObject();
3504 
3505  return true;
3506  }
3507  if(!($usr_id = ilObjUser::getUserIdByLogin(ilUtil::stripSlashes($_POST['user_login']))))
3508  {
3509  ilUtil::sendFailure($this->lng->txt('pays_no_valid_username_given'));
3510  $this->vendorsObject();
3511 
3512  return true;
3513  }
3514 
3515  if($this->vendors_obj->isAssigned($usr_id))
3516  {
3517  ilUtil::sendFailure($this->lng->txt('pays_user_already_assigned'));
3518  $this->vendorsObject();
3519 
3520  return true;
3521  }
3522  $this->vendors_obj->add($usr_id);
3523 
3524  ilUtil::sendSuccess($this->lng->txt('pays_added_vendor'));
3525  $this->vendorsObject();
3526 
3527  return true;
3528  }
3529 
3530  public function addUserObject()
3531  {
3532  global $rbacsystem;
3533 
3534  // MINIMUM ACCESS LEVEL = 'administrate'
3535  if(!$rbacsystem->checkAccess('write', $this->object->getRefId()))
3536  {
3537  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_write'),$this->ilErr->MESSAGE);
3538  }
3539 
3540  $this->lng->loadLanguageModule('crs');
3541  if(!is_array($_POST['user']))
3542  {
3543  ilUtil::sendFailure($this->lng->txt('crs_no_users_selected'));
3544  $this->searchObject();
3545 
3546  return false;
3547  }
3548 
3549  $already_assigned = $assigned = 0;
3550  foreach($_POST['user'] as $usr_id)
3551  {
3552  if($this->vendors_obj->isAssigned($usr_id))
3553  {
3554  ++$already_assigned;
3555  continue;
3556  }
3557  $this->vendors_obj->add($usr_id);
3558  ++$assigned;
3559 
3560  // TODO: SEND NOTIFICATION
3561  }
3562  $message = '';
3563  if($assigned)
3564  {
3565  $message .= $this->lng->txt('pays_assigned_vendors').' '.$assigned;
3566  }
3567  if($already_assigned)
3568  {
3569  $message .= '<br />'.$this->lng->txt('pays_already_assigned_vendors').' '.$already_assigned;
3570  }
3571 
3572  ilUtil::sendInfo($message);
3573  $this->vendorsObject();
3574 
3575  return true;
3576  }
3577 
3578  public function searchUserSPObject()
3579  {
3580  global $ilToolbar;
3581 
3582  if(!isset($_GET['sell_id']))
3583  {
3584  ilUtil::sendFailiure($this->lng->txt('paya_no_booking_id_given'));
3585  $this->showObjectSelectorObject();
3586 
3587  return false;
3588  }
3589 
3590  $ilToolbar->addButton($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'showObjectSelector'));
3591  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
3592 
3593  $this->lng->loadLanguageModule('search');
3594  $this->ctrl->setParameter($this, 'sell_id', $_GET['sell_id']);
3595 
3596  $form_gui = new ilPropertyFormGUI();
3597  $form_gui->setFormAction($this->ctrl->getFormAction($this));
3598  $form_gui->setTitle($this->lng->txt('search_user'));
3599  $form_gui->setId('search_form');
3600 
3601  $oTitle = new ilTextInputGUI($this->lng->txt('search_search_term'), 'search_str');
3602  $oTitle->setMaxLength(255);
3603  $oTitle->setSize(40);
3604  $oTitle->setValue($_POST['search_str']);
3605  $form_gui->addItem($oTitle);
3606 
3607  // buttons
3608  $form_gui->addCommandButton('performSearchSP', $this->lng->txt('search'));
3609  $form_gui->addCommandButton('bookings', $this->lng->txt('cancel'));
3610 
3611  $this->tpl->setVariable('FORM',$form_gui->getHTML());
3612  return true;
3613  }
3614 
3615  public function performSearchSPObject()
3616  {
3617  global $ilToolbar;
3618  // SAVE it to allow sort in tables
3619  $_SESSION['paya_search_str_user_sp'] = $_POST['search_str'] = $_POST['search_str'] ? $_POST['search_str'] : $_SESSION['paya_search_str_user_sp'];
3620 
3621  if(!trim($_POST['search_str']))
3622  {
3623  ilUtil::sendFailure($this->lng->txt('search_no_search_term'));
3624  $this->statistics();
3625 
3626  return false;
3627  }
3628  if(!count($result = $this->__search(ilUtil::stripSlashes($_POST['search_str']))))
3629  {
3630  ilUtil::sendInfo($this->lng->txt('search_no_match'));
3631  $this->searchUserSPObject();
3632 
3633  return false;
3634  }
3635 
3636  if(!isset($_GET['sell_id']))
3637  {
3638  ilUtil::sendInfo($this->lng->txt('paya_no_booking_id_given'));
3639  $this->showObjectSelectorObject();
3640 
3641  return false;
3642  }
3643 
3644  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.main_view.html','Services/Payment');
3645  $this->ctrl->setParameter($this, 'sell_id', $_GET['sell_id']);
3646 
3647  $ilToolbar->addButton($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'searchUserSP'));
3648 
3649  $counter = 0;
3650  $f_result = array();
3651  foreach($result as $user)
3652  {
3653  if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($user['id'],false))
3654  {
3655  continue;
3656  }
3657  $f_result[$counter]['user_id'] = $user['id'];
3658  $f_result[$counter]['login'] = $tmp_obj->getLogin();
3659  $f_result[$counter]['firstname'] = $tmp_obj->getFirstname();
3660  $f_result[$counter]['lastname'] = $tmp_obj->getLastname();
3661 
3662  unset($tmp_obj);
3663  ++$counter;
3664  }
3665  return $this->__showSearchUserSPTable($f_result);
3666  }
3667 
3668  public function addCustomerObject()
3669  {
3670  global $ilToolbar;
3671 
3672  if ($_POST['sell_id'] != '') $_GET['sell_id'] = $_POST['sell_id'];
3673  if ($_GET['user_id'] != '') $_POST['user_id'] = $_GET['user_id'];
3674 
3675  if(!isset($_GET['sell_id']))
3676  {
3677  ilUtil::sendInfo($this->lng->txt('paya_no_booking_id_given'));
3678  $this->showObjectSelectorObject();
3679 
3680  return true;
3681  }
3682 
3683  if(!isset($_POST['user_id']))
3684  {
3685  ilUtil::sendInfo($this->lng->txt('paya_no_user_id_given'));
3686  $this->searchUserSPObject();
3687 
3688  return true;
3689  }
3690  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.main_view.html','Services/Payment');
3691  $this->ctrl->setParameter($this, 'sell_id', $_GET['sell_id']);
3692 
3693  $ilToolbar->addButton($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'searchUserSP'));
3694 
3695  $this->ctrl->setParameter($this, 'user_id', $_POST['user_id']);
3696 
3697  $pObjectId = ilPaymentObject::_lookupPobjectId($_GET['sell_id']);
3698  $obj = new ilPaymentObject($this->user_obj, $pObjectId);
3699 
3700  // get obj
3701  $tmp_obj = ilObjectFactory::getInstanceByRefId($_GET['sell_id'], false);
3702  if($tmp_obj)
3703  {
3704  $tmp_object['title'] = $tmp_obj->getTitle();
3705  }
3706  else
3707  {
3708  $tmp_object['title'] = $this->lng->txt('object_not_found');
3709  }
3710  // get customer_obj
3711  $tmp_user = ilObjectFactory::getInstanceByObjId($_POST['user_id']);
3712  // get vendor_obj
3713  $tmp_vendor = ilObjectFactory::getInstanceByObjId($obj->getVendorId());
3714 
3715  $oForm = new ilPropertyFormGUI();
3716  $oForm->setFormAction($this->ctrl->getFormAction($this, 'saveCustomer'));
3717  $oForm->setTitle($this->lng->txt($tmp_user->getFullname().' ['.$tmp_user->getLogin().']'));
3718 
3719  //transaction
3720  $oTransaction = new ilTextInputGUI();
3721  $oTransaction->setTitle($this->lng->txt('paya_transaction'));
3722  //$oTransaction->setValue(ilUtil::prepareFormOutut($_POST['transaction'], true));
3723  $oTransaction->setValue($_POST['transaction']);
3724  $oTransaction->setPostVar('transaction');
3725  $oForm->addItem($oTransaction);
3726 
3727  //object
3728  $oObject = new ilNonEditableValueGUI($this->lng->txt('title'));
3729  $oObject->setValue($tmp_obj->getTitle());
3730  $oForm->addItem($oObject);
3731 
3732  //vendor
3733  $oVendor = new ilNonEditableValueGUI($this->lng->txt('paya_vendor'));
3734  $oVendor->setValue($tmp_vendor->getFullname().' ['.$tmp_vendor->getLogin().']');
3735  $oForm->addItem($oVendor);
3736 
3737  // pay methods
3738  $oPayMethods = new ilSelectInputGUI($this->lng->txt('paya_pay_method'), 'pay_method');
3739  $payOptions = ilPaymethods::getPayMethodsOptions(false);
3740  $oPayMethods->setOptions($payOptions);
3741  $oPayMethods->setValue($_POST['pay_method']);
3742  $oPayMethods->setPostVar('pay_method');
3743  $oForm->addItem($oPayMethods);
3744 
3745  //duration
3746  $duration_options = array();
3747  $price_obj = new ilPaymentPrices($pObjectId);
3748 
3749  $standard_prices = array();
3750  $extension_prices = array();
3751  $standard_prices = $price_obj->getPrices();
3752  $extension_prices = $price_obj->getExtensionPrices();
3753 
3754  $prices = array_merge($standard_prices, $extension_prices );
3755 
3756  if (is_array($prices))
3757  {
3758  $genSet = ilPaymentSettings::_getInstance();
3759  $currency_unit = $genSet->get('currency_unit');
3760 
3761  foreach($prices as $price)
3762  {
3763  switch($price['price_type'])
3764  {
3766  $txt_duration =
3767  $price['duration'].' '.$this->lng->txt('paya_months').' -> '.$price['price'].' '. $currency_unit;
3768  break;
3769 
3771  include_once './Services/Calendar/classes/class.ilDatePresentation.php';
3772  $txt_duration = ilDatePresentation::formatDate(new ilDate($price['duration_from'], IL_CAL_DATE))
3773  .' - '.ilDatePresentation::formatDate(new ilDate($price['duration_until'], IL_CAL_DATE))
3774  ." -> ".ilPaymentPrices::_getPriceString($price["price_id"]) .' '.$currency_unit;
3775  break;
3776 
3778  $txt_duration = $this->lng->txt('unlimited_duration').' -> '.$price['price'].' '. $currency_unit;
3779  break;
3780  }
3781  $txt_extension = '';
3782  if($price['extension'] == 1)
3783  {
3784  $txt_extension = ' ('.$this->lng->txt('extension_price').') ';
3785  }
3786  $duration_options[$price['price_id']] .= $txt_duration.''.$txt_extension;
3787  }
3788  }
3789 
3790  $oDuration = new ilSelectInputGUI($this->lng->txt('duration'), 'price_id');
3791  $oDuration->setOptions($duration_options);
3792  $oDuration->setValue($_POST['price_id']);
3793  $oForm->addItem($oDuration);
3794 
3795  //payed
3796  $o_payed = new ilSelectInputGUI();
3797  $payed_option = array('1'=>$this->lng->txt('yes'),'0'=>$this->lng->txt('no'));
3798 
3799  $o_payed->setTitle($this->lng->txt('paya_payed'));
3800  $o_payed->setOptions($payed_option);
3801  $o_payed->setValue($_POST['payed']);
3802  $o_payed->setPostVar('payed');
3803  $oForm->addItem($o_payed);
3804 
3805 
3806  $o_access = new ilSelectInputGUI();
3807  $access_option = array('1'=>$this->lng->txt('yes'),'0'=>$this->lng->txt('no'));
3808 
3809  $o_access->setTitle($this->lng->txt('paya_access'));
3810  $o_access->setOptions($access_option);
3811  $o_access->setValue($_POST['access']);
3812  $o_access->setPostVar('access');
3813 
3814  $oForm->addItem($o_access);
3815 
3816  $oForm->addCommandButton('saveCustomer',$this->lng->txt('save'));
3817  $oForm->addCommandButton('bookings', $this->lng->txt('cancel'));
3818 
3819  $this->tpl->setVariable('FORM',$oForm->getHTML());
3820  return true;
3821  }
3822 
3823  public function saveCustomerObject()
3824  {
3825  global $ilUser,$ilObjDataCache;
3826 
3827  if(!isset($_GET['sell_id']))
3828  {
3829  ilUtil::sendInfo($this->lng->txt('paya_error_no_object_id_given'));
3830  $this->showObjectSelectorObject();
3831 
3832  return true;
3833  }
3834 
3835  if(!isset($_GET['user_id']))
3836  {
3837  ilUtil::sendInfo($this->lng->txt('paya_error_no_user_id_given'));
3838  $this->searchUserSPObject();
3839 
3840  return true;
3841  }
3842 
3843  if ($_POST['pay_method'] == '' ||
3844  $_POST['price_id'] == '')
3845  {
3846  ilUtil::sendInfo($this->lng->txt('paya_error_mandatory_fields'));
3847  $this->addCustomerObject();
3848 
3849  return true;
3850  }
3851 
3852  $pObjectId = ilPaymentObject::_lookupPobjectId($_GET['sell_id']);
3853  $obj = new ilPaymentObject($this->user_obj, $pObjectId);
3854 
3855  $this->__initBookingObject();
3856 
3857  $transaction = ilInvoiceNumberPlaceholdersPropertyGUI::_generateInvoiceNumber($ilUser->getId());
3858 
3859  $this->booking_obj->setTransaction($transaction);
3860  $this->booking_obj->setTransactionExtern($_POST['transaction']);
3861  $this->booking_obj->setPobjectId($pObjectId);
3862  $this->booking_obj->setCustomerId($_GET['user_id']);
3863  $this->booking_obj->setVendorId($obj->getVendorId());
3864 
3865  $this->booking_obj->setPayMethod($_POST['pay_method']);
3866  $this->booking_obj->setOrderDate(time());
3867 
3868  $price = ilPaymentPrices::_getPrice($_POST['price_id']);
3869 // $currency = ilPaymentCurrency::_getUnit($price['currency']);
3870 
3871 #@todo check this.
3872  switch($price['price_type'])
3873  {
3875  $this->booking_obj->setDuration($price['duration']);
3876  break;
3877 
3879  $this->booking_obj->setDuration(0);
3880  $this->booking_obj->setAccessStartdate($price['duration_from']);
3881  $this->booking_obj->setAccessEnddate($price['duration_until']);
3882  break;
3884  $this->booking_obj->setDuration(0);
3885  $this->booking_obj->setAccessEnddate(NULL);
3886  break;
3887  }
3888 
3889  $this->booking_obj->setPriceType($price['price_type']);
3890  $this->booking_obj->setPrice($price['price']);
3891 
3892  $this->booking_obj->setAccess((int) $_POST['access']);
3893  $this->booking_obj->setPayed((int) $_POST['payed']);
3894  $this->booking_obj->setVoucher('');
3895 
3896  $obj_id = $ilObjDataCache->lookupObjId($obj->getRefId());
3897  $obj_type = $ilObjDataCache->lookupType($obj_id);
3898  $obj_title = $ilObjDataCache->lookupTitle($obj_id);
3899 
3900  // include_once 'Services/Payment/classes/class.ilShopVatsList.php';
3901  $oVAT = new ilShopVats((int)$obj->getVatId());
3902  $obj_vat_rate = $oVAT->getRate();
3903  $obj_vat_unit = $obj->getVat($this->booking_obj->getPrice());
3904 
3905  $this->booking_obj->setObjectTitle($obj_title);
3906  $this->booking_obj->setVatRate($obj_vat_rate);
3907  $this->booking_obj->setVatUnit($obj_vat_unit);
3908 
3910  $this->booking_obj->setCurrencyUnit( $genSet->get('currency_unit'));
3911 
3912  include_once './Services/Payment/classes/class.ilPayMethods.php';
3913 
3914  $save_user_address_enabled = ilPayMethods::_EnabledSaveUserAddress($this->booking_obj->getPayMethod());
3915  if($save_user_address_enabled == 1)
3916  {
3917  global $ilObjUser;
3918  $user_id[] = $_GET["user_id"];
3919 
3920  $cust_obj = ilObjUser::_readUsersProfileData($user_id);
3921 
3922  $this->booking_obj->setStreet($cust_obj[$_GET["user_id"]]['street'],'');
3923 
3924  $this->booking_obj->setZipcode($cust_obj[$_GET["user_id"]]['zipcode']);
3925  $this->booking_obj->setCity($cust_obj[$_GET["user_id"]]['city']);
3926  $this->booking_obj->setCountry($cust_obj[$_GET["user_id"]]['country']);
3927  }
3928 
3929  if($this->booking_obj->add())
3930  {
3931  // add purchased item to desktop
3932  ilShopUtils::_addPurchasedObjToDesktop($obj, $this->booking_obj->getCustomerId());
3933 
3934  // autosubscribe user if purchased object is a course
3935  if($obj_type == 'crs')
3936  {
3937  ilShopUtils::_assignPurchasedCourseMemberRole($obj, $this->booking_obj->getCustomerId());
3938  }
3939 
3940  ilUtil::sendInfo($this->lng->txt('paya_customer_added_successfully'));
3941  $this->statisticObject();
3942  }
3943  else
3944  {
3945  ilUtil::sendInfo($this->lng->txt('paya_error_adding_customer'));
3946  $this->addCustomerObject();
3947  }
3948  return true;
3949  }
3950 
3951  // PRIVATE
3952  private function __showStatisticTable($a_result_set)
3953  {
3954  $this->ctrl->setParameter($this, 'cmd', 'statistic');
3955 
3956  $tbl = new ilShopTableGUI($this);
3957  $tbl->setTitle($this->lng->txt("bookings"));
3958  $tbl->setId('tbl_show_statistics');
3959  $tbl->setRowTemplate("tpl.shop_statistics_row.html", "Services/Payment");
3960 
3961  $tbl->addColumn($this->lng->txt('paya_transaction'), 'transaction', '10%');
3962  $tbl->addColumn($this->lng->txt('title'), 'object_title', '10%');
3963  $tbl->addColumn($this->lng->txt('paya_vendor'), 'vendor', '10%');
3964  $tbl->addColumn($this->lng->txt('paya_customer'), 'customer', '10%');
3965  $tbl->addColumn($this->lng->txt('paya_order_date'), 'order_date', '10%');
3966  $tbl->addColumn($this->lng->txt('duration'), 'duration', '20%');
3967  $tbl->addColumn($this->lng->txt('price_a'), 'price', '5%');
3968  $tbl->addColumn($this->lng->txt('paya_coupons_coupon'), 'discount', '5%');
3969  $tbl->addColumn($this->lng->txt('paya_payed_access'), 'payed_access', '1%');
3970  $tbl->addColumn('','edit', '5%');
3971 
3972  $tbl->addCommandButton('exportVendors',$this->lng->txt('excel_export'));
3973  $tbl->setData($a_result_set);
3974 
3975  $this->tpl->setVariable('TABLE', $tbl->getHTML());
3976 
3977  return true;
3978  }
3979 
3980  private function __initBookingObject()
3981  {
3982  include_once './Services/Payment/classes/class.ilPaymentBookings.php';
3983 
3984  $this->booking_obj = new ilPaymentBookings($this->user_obj->getId(),true);
3985  }
3986 
3987  private function __showVendorsTable($a_result_set)
3988  {
3989  $this->ctrl->setParameter($this, 'cmd', 'vendors');
3990 
3991  $tbl = new ilShopTableGUI($this);
3992  $tbl->setTitle($this->lng->txt("vendors"));
3993  $tbl->setId('tbl_show_vendors');
3994  $tbl->setRowTemplate("tpl.shop_users_row.html", "Services/Payment");
3995 
3996  $tbl->addColumn('', 'vendor_id', '1%');
3997  $tbl->addColumn($this->lng->txt('paya_vendor'), 'login', '10%');
3998  $tbl->addColumn($this->lng->txt('pays_cost_center'), 'cost_center', '10%');
3999  $tbl->addColumn($this->lng->txt('pays_number_bookings'), 'number_bookings', '10%');
4000 
4001  $tbl->addMultiCommand("editVendor", $this->lng->txt('pays_edit_vendor'));
4002  $tbl->addMultiCommand("deleteVendors", $this->lng->txt('pays_delete_vendor'));
4003 
4004  $tbl->addCommandButton('exportVendors',$this->lng->txt('excel_export'));
4005 
4006  $tbl->setData($a_result_set);
4007  $this->tpl->setVariable('TABLE', $tbl->getHTML());
4008 
4009  return true;
4010  }
4011 
4012  private function __showSearchUserTable($a_result_set)
4013  {
4014  $tbl = new ilShopTableGUI($this);
4015 
4016  $tbl->setTitle($this->lng->txt("pays_header_select_vendor"));
4017  $tbl->setId('tbl_search_user_vendor');
4018  $tbl->setRowTemplate("tpl.shop_users_row.html", "Services/Payment");
4019 
4020  $tbl->addColumn(' ', 'vendor_id', '3%', true);
4021  $tbl->addColumn($this->lng->txt('login'), 'login', '32%');
4022  $tbl->addColumn($this->lng->txt('firstname'),'firstname','32%');
4023  $tbl->addColumn($this->lng->txt('lastname'), 'lastname', '32%');
4024 
4025  $tbl->setSelectAllCheckbox('vendor_id');
4026  $tbl->addMultiCommand("addUser", $this->lng->txt("add"));
4027  $tbl->addCommandButton('vendors',$this->lng->txt('cancel'));
4028 
4029  $tbl->fillFooter();
4030  $tbl->setData($a_result_set);
4031  $this->tpl->setVariable('TABLE', $tbl->getHTML());
4032 
4033  return true;
4034  }
4035 
4036  private function __search($a_search_string)
4037  {
4038  include_once('./Services/Search/classes/class.ilSearch.php');
4039 
4040  $this->lng->loadLanguageModule('content');
4041 
4042  $search = new ilSearch($_SESSION['AccountId']);
4043  $search->setPerformUpdate(false);
4044  $search->setSearchString(ilUtil::stripSlashes($a_search_string));
4045  $search->setCombination('and');
4046  $search->setSearchFor(array(0 => 'usr'));
4047  $search->setSearchType('new');
4048 
4049  if($search->validate($message))
4050  {
4051  $search->performSearch();
4052  }
4053  else
4054  {
4055  ilUtil::sendInfo($message,true);
4056  $this->ctrl->redirect($this,'searchUser');
4057  }
4058  return $search->getResultByType('usr');
4059  }
4060 
4061  private function __searchSP($a_search_string)
4062  {
4063  include_once('./Services/Search/classes/class.ilSearch.php');
4064 
4065  $this->lng->loadLanguageModule('content');
4066 
4067  $search = new ilSearch($this->user_obj->getId());
4068  $search->setPerformUpdate(false);
4069  $search->setSearchString(ilUtil::stripSlashes($a_search_string));
4070  $search->setCombination('and');
4071  $search->setSearchFor(array(0 => 'usr'));
4072  $search->setSearchType('new');
4073 
4074  if($search->validate($message))
4075  {
4076  $search->performSearchSPObject();
4077  }
4078  else
4079  {
4080  ilUtil::sendInfo($message,true);
4081  $this->ctrl->redirect($this,'searchUserSP');
4082  }
4083  return $search->getResultByType('usr');
4084  }
4085  private function __showSearchUserSPTable($a_result_set)
4086  {
4087  $this->ctrl->setParameter($this, 'sell_id', $_GET['sell_id']);
4088  $tbl = new ilShopTableGUI($this);
4089 
4090  $tbl->setTitle($this->lng->txt('users'));
4091  $tbl->setId('tbl_search_user_vendor');
4092  $tbl->setRowTemplate("tpl.shop_users_row.html", "Services/Payment");
4093 
4094  $tbl->addColumn(' ', 'user_id', '3%', true);
4095  $tbl->addColumn($this->lng->txt('login'), 'login', '32%');
4096  $tbl->addColumn($this->lng->txt('firstname'),'firstname','32%');
4097  $tbl->addColumn($this->lng->txt('lastname'), 'lastname', '32%');
4098 
4099 
4100  $tbl->addMultiCommand("addCustomer", $this->lng->txt("add"));
4101  $tbl->addCommandButton('statistic',$this->lng->txt('cancel'));
4102 
4103  $tbl->fillFooter();
4104  $tbl->setData($a_result_set);
4105  $this->tpl->setVariable('TABLE', $tbl->getHTML());
4106  return true;
4107  }
4108 
4109  public function vatsObject()
4110  {
4111  global $ilAccess;
4112 
4113  if(!$ilAccess->checkAccess('read', '', $this->object->getRefId()))
4114  {
4115  $this->ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $this->ilErr->MESSAGE);
4116  }
4117 
4118  include_once 'Services/Table/classes/class.ilTable2GUI.php';
4119  $tbl = new ilTable2GUI($this, 'vats');
4120  $tbl->setId('pay_vats_tbl');
4121  $tbl->setFormAction($this->ctrl->getFormAction($this), 'createVat');
4122  $tbl->setTitle($this->lng->txt('payment_tax_rates'));
4123  $tbl->setRowTemplate('tpl.shop_vats_list_row.html', 'Services/Payment');
4124 
4125  $tbl->setDefaultOrderField('title');
4126 
4127  $tbl->addColumn('', 'check', '1%');
4128  $tbl->addColumn($this->lng->txt('vat_title'), 'vat_title', '33%');
4129  $tbl->addColumn($this->lng->txt('vat_rate'), 'vat_rate', '33%');
4130  $tbl->addColumn('', 'commands', '33%');
4131 
4132  $oShopVatsList = new ilShopVatsList();
4133  $oShopVatsList->read();
4134 
4135  $result = array();
4136 
4137  $_SESSION['count_vats'] = $oShopVatsList->getNumItems();
4138 
4139  if($oShopVatsList->hasItems())
4140  {
4141  $tbl->enable('select_all');
4142  $tbl->setSelectAllCheckbox('vat_id');
4143 
4144  $counter = 0;
4145  foreach($oShopVatsList as $oVAT)
4146  {
4147  $result[$counter]['check'] = ilUtil::formCheckbox(0, 'vat_id[]', $oVAT->getId());
4148  $result[$counter]['vat_title'] = $oVAT->getTitle();
4149  $result[$counter]['vat_rate'] = ilShopUtils::_formatVAT((float)$oVAT->getRate());
4150  $this->ctrl->setParameter($this, 'vat_id', $oVAT->getId());
4151  $result[$counter]['edit_text'] = $this->lng->txt('edit');
4152  $result[$counter]['edit_url'] = $this->ctrl->getLinkTarget($this, 'editVat');
4153  $result[$counter]['delete_text'] = $this->lng->txt('delete');
4154  $result[$counter]['delete_url'] = $this->ctrl->getLinkTarget($this, 'confirmDeleteVat');
4155  $this->ctrl->clearParameters($this);
4156  ++$counter;
4157  }
4158 
4159  $tbl->addMultiCommand('confirmDeleteVat', $this->lng->txt('delete'));
4160  }
4161  else
4162  {
4163  $tbl->disable('header');
4164  $tbl->disable('footer');
4165 
4166  $tbl->setNoEntriesText($this->lng->txt('paya_no_vats_assigned'));
4167  }
4168 
4169  $tbl->setData($result);
4170 
4171  $tbl->addCommandButton('createVat', $this->lng->txt('paya_insert_vats'));
4172 
4173  $this->tpl->setContent($tbl->getHTML());
4174 
4175  return true;
4176  }
4177 
4178  public function confirmDeleteVatObject()
4179  {
4180  if((int)$_GET['vat_id'] && !isset($_POST['vat_id']))
4181  {
4182  $_POST['vat_id'][] = $_GET['vat_id'];
4183  }
4184 
4185  if($_SESSION['count_vats'] == count($_POST['vat_id']))
4186  {
4187  ilUtil::sendInfo($this->lng->txt('shop_disabled_no_vats'));
4188  $_SESSION['disable_shop'] = true;
4189  }
4190 
4191  $c_gui = new ilConfirmationGUI();
4192  $c_gui->setFormAction($this->ctrl->getFormAction($this, 'performDeleteVat'));
4193  $c_gui->setHeaderText($this->lng->txt('paya_sure_delete_vats'));
4194  $c_gui->setCancel($this->lng->txt('cancel'), 'vats');
4195  $c_gui->setConfirm($this->lng->txt('confirm'), 'performDeleteVat');
4196 
4197  $counter = 0;
4198  foreach((array)$_POST['vat_id'] as $vat_id)
4199  {
4200  try
4201  {
4202  $oVAT = new ilShopVats((int)$vat_id);
4203  $c_gui->addItem('vat_id[]', $oVAT->getId(), $oVAT->getTitle());
4204  ++$counter;
4205  }
4206  catch(ilShopException $e)
4207  {
4208  ilUtil::sendInfo($e->getMessage());
4209  return $this->vatsObject();
4210  }
4211  }
4212 
4213  if($counter)
4214  {
4215  $this->tpl->setContent($c_gui->getHTML());
4216  return true;
4217  }
4218  else
4219  {
4220  $this->vatsObject();
4221  return true;
4222  }
4223  }
4224 
4225  public function performDeleteVatObject()
4226  {
4227  if(!is_array($_POST['vat_id']))
4228  {
4229  return $this->vatsObject();
4230  }
4231 
4232  foreach($_POST['vat_id'] as $vat_id)
4233  {
4234  try
4235  {
4236  $oVAT = new ilShopVats((int)$vat_id);
4237  $oVAT->delete();
4238 
4239  }
4240  catch(ilShopException $e)
4241  {
4242  ilUtil::sendInfo($e->getMessage());
4243  $_SESSION['disable_shop'] = false;
4244  return $this->vatsObject();
4245  }
4246  }
4247 
4248  if($_SESSION['disable_shop'] == true)
4249  {
4250  $this->genSetData->set('shop_enabled', 0, 'common');
4251  $_SESSION['disable_shop'] = false;
4252  }
4253  ilUtil::sendSuccess($this->lng->txt('payment_vat_deleted_successfully'));
4254  return $this->vatsObject();
4255  }
4256  public function createVatObject()
4257  {
4258  $this->initVatForm('create');
4259  $this->tpl->setContent($this->form->getHtml());
4260  }
4261 
4262  public function editVatObject()
4263  {
4264  $this->initVatForm('edit');
4265  $this->fillVATDataIntoVATForm();
4266  $this->tpl->setContent($this->form->getHtml());
4267  }
4268 
4269  private function initVatForm($a_type = 'create')
4270  {
4271  $this->form = new ilPropertyFormGUI();
4272  if($a_type == 'edit')
4273  {
4274  $this->ctrl->setParameter($this, 'vat_id', $_GET['vat_id']);
4275  $this->form->setFormAction($this->ctrl->getFormAction($this, 'updateVat'));
4276  $this->form->setTitle($this->lng->txt('payment_edit_vat'));
4277  }
4278  else
4279  {
4280  $this->form->setFormAction($this->ctrl->getFormAction($this, 'saveVat'));
4281  $this->form->setTitle($this->lng->txt('payment_add_vat'));
4282  }
4283 
4284  $oTitle = new ilTextInputGUI($this->lng->txt('title'), 'vat_title');
4285  $oTitle->setMaxLength(255);
4286  $oTitle->setSize(40);
4287  $oTitle->setRequired(true);
4288  $oTitle->setInfo($this->lng->txt('payment_vat_title_info'));
4289  $this->form->addItem($oTitle);
4290 
4291  $oRate = new ilTextInputGUI($this->lng->txt('vat_rate'), 'vat_rate');
4292  $oRate->setMaxLength(5);
4293  $oRate->setSize(5);
4294  $oRate->setRequired(true);
4295  $oRate->setInfo($this->lng->txt('payment_vat_rate_info'));
4296  $this->form->addItem($oRate);
4297 
4298  if($a_type == 'edit')
4299  {
4300  $this->form->addCommandButton('updateVat', $this->lng->txt('save'));
4301  }
4302  else
4303  {
4304  $this->form->addCommandButton('saveVat', $this->lng->txt('save'));
4305  }
4306 
4307  $this->form->addCommandButton('vats', $this->lng->txt('cancel'));
4308  }
4309 
4310  private function fillVATDataIntoVATForm()
4311  {
4312  $oVAT = new ilShopVats((int)$_GET['vat_id']);
4313  $this->form->setValuesByArray(array(
4314  'vat_title' => $oVAT->getTitle(),
4315  'vat_rate' => $oVAT->getRate()
4316  ));
4317  }
4318 
4319  public function updateVatObject()
4320  {
4321  $this->initVatForm('edit');
4322  if(!$this->form->checkInput())
4323  {
4324  $this->form->setValuesByPost();
4325  $this->tpl->setContent($this->form->getHtml());
4326  return true;
4327  }
4328 
4329  if(!ilShopUtils::_checkVATRate($this->form->getInput('vat_rate')))
4330  {
4331  $this->form->getItemByPostVar('vat_rate')->setAlert($this->lng->txt('payment_vat_input_invalid'));
4332  $this->form->setValuesByPost();
4333  $this->tpl->setContent($this->form->getHtml());
4334  return true;
4335  }
4336 
4337  try
4338  {
4339  $oVAT = new ilShopVats((int)$_GET['vat_id']);
4340  $oVAT->setTitle($this->form->getInput('vat_title'));
4341  $oVAT->setRate((float)str_replace(',', '.', $this->form->getInput('vat_rate')));
4342  $oVAT->update();
4343  }
4344  catch(ilShopException $e)
4345  {
4346  ilUtil::sendInfo($e->getMessage());
4347  $this->form->setValuesByPost();
4348  $this->tpl->setContent($this->form->getHtml());
4349  return true;
4350  }
4351 
4352  ilUtil::sendInfo($this->lng->txt('saved_successfully'));
4353  return $this->vatsObject();
4354  }
4355 
4356  public function saveVatObject()
4357  {
4358  $this->initVatForm('create');
4359  if(!$this->form->checkInput())
4360  {
4361  $this->form->setValuesByPost();
4362  $this->tpl->setContent($this->form->getHtml());
4363  return true;
4364  }
4365 
4366  if(!ilShopUtils::_checkVATRate($this->form->getInput('vat_rate')))
4367  {
4368  $this->form->getItemByPostVar('vat_rate')->setAlert($this->lng->txt('payment_vat_input_invalid'));
4369  $this->form->setValuesByPost();
4370  $this->tpl->setContent($this->form->getHtml());
4371  return true;
4372  }
4373 
4374  try
4375  {
4376  $oVAT = new ilShopVats();
4377  $oVAT->setTitle($this->form->getInput('vat_title'));
4378  $oVAT->setRate((float)str_replace(',', '.', $this->form->getInput('vat_rate')));
4379  $oVAT->save();
4380  }
4381  catch(ilShopException $e)
4382  {
4383  ilUtil::sendInfo($e->getMessage());
4384  $this->form->setValuesByPost();
4385  $this->tpl->setContent($this->form->getHtml());
4386  return true;
4387 
4388  }
4389 
4390  ilUtil::sendInfo($this->lng->txt('saved'));
4391  $this->vatsObject();
4392  return true;
4393 
4394  }
4395 
4397  {
4398  // delete addresses here
4399  include_once './Services/Payment/classes/class.ilPayMethods.php';
4400  $this->__initBookingObject();
4401 
4402  foreach($_POST['paymethod'] as $pay_method)
4403  {
4405  $del_bookings = $this->booking_obj->deleteAddressesByPaymethod((int)$pay_method);
4406  }
4407  ilUtil::sendSuccess($this->lng->txt('pays_updated_pay_method'));
4408  return $this->payMethodsObject();
4409  }
4410 
4411  // show currencies
4412  public function currenciesObject()
4413  {
4414  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
4416  // currency table
4417  $counter = 0;
4418  foreach($currency_res as $cur)
4419  {
4420  $f_result[$counter]['currency_id'] = ilUtil::formRadioButton(0,'currency_id',$cur['currency_id']);
4421  $f_result[$counter]['is_default'] = $cur['is_default'] == 1 ? $this->lng->txt('yes') : $this->lng->txt('no');
4422 
4423  $f_result[$counter]['currency_unit'] = $cur['unit'];
4424  $f_result[$counter]['iso_code'] = $cur['iso_code'];
4425  $f_result[$counter]['currency_symbol'] = $cur['symbol'];
4426  $f_result[$counter]['conversion_rate'] = $cur['conversion_rate'];
4427 
4428  $counter++;
4429  }
4430 
4431  $tbl = new ilShopTableGUI($this);
4432 
4433  $tbl->setTitle($this->lng->txt("currencies"));
4434  $tbl->setId('tbl_show_currencies');
4435  $tbl->setRowTemplate("tpl.shop_currencies_row.html", "Services/Payment");
4436 
4437  $tbl->addColumn(' ', 'currency_id', '1%', true);
4438  $tbl->addColumn($this->lng->txt('is_default'), 'is_default', '5%');
4439  $tbl->addColumn($this->lng->txt('currency_unit'), 'currency_unit', '10%');
4440  $tbl->addColumn($this->lng->txt('iso_code'),'iso_code','20%');
4441  $tbl->addColumn($this->lng->txt('currency_symbol'), 'currency_symbol', '20%');
4442  $tbl->addColumn($this->lng->txt('conversion_rate'), 'conversion_rate', '15%');
4443  $tbl->addColumn('', 'options', '5%');
4444 
4445  $this->ctrl->setParameter($this, 'cmd', 'currencies');
4446 
4447  $tbl->addMultiCommand('updateDefaultCurrency', $this->lng->txt('paya_set_default_currency'));
4448  $tbl->addMultiCommand("editCurrency",$this->lng->txt('edit'));
4449  $tbl->addMultiCommand("deleteCurrency", $this->lng->txt('delete'));
4450 
4451  $tbl->addCommandButton('addCurrency',$this->lng->txt('add_currency'));
4452  $tbl->setData($f_result);
4453  $this->tpl->setVariable('TABLE', $tbl->getHTML());
4454  return true;
4455  }
4457  {
4458  if(isset($_POST['currency_id'] ))
4459  {
4460  ilPaymentCurrency::_updateIsDefault($_POST['currency_id']);
4461  }
4462  else ilUtil::sendFailure($this->lng->txt('please_select_currency'));
4463 
4464  $this->currenciesObject();
4465  }
4466 
4467  public function addCurrencyObject()
4468  {
4469  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
4470  $form = new ilPropertyFormGUI();
4471  $form->setFormAction($this->ctrl->getFormAction($this));
4472  $form->setTitle($this->lng->txt('paya_add_currency'));
4473 
4474  $o_Unit = new ilTextInputGUI($this->lng->txt('paya_currency_unit'),'currency_unit');
4475  $o_Unit->setValue($_POST['currency_unit']);
4476  $o_Unit->setPostVar('currency_unit');
4477  $o_Unit->setRequired(true);
4478 
4479  $o_Isocode = new ilTextInputGUI($this->lng->txt('iso_code'),'iso_code');
4480  $o_Isocode->setValue($_POST['iso_code']);
4481  $o_Isocode->setPostVar('iso_code');
4482  $o_Isocode->setRequired(true);
4483 
4484  $o_Symbol = new ilTextInputGUI($this->lng->txt('symbol'), 'symbol');
4485  $o_Symbol->setValue($_POST['symbol']);
4486  $o_Symbol->setPostVar('symbol');
4487  $o_Symbol->setRequired(true);
4488 
4489  $o_Conversionrate = new IlTextInputGUI($this->lng->txt('conversion_rate'), 'conversion_rate');
4490  $o_Conversionrate->setValue($_POST['conversion_rate']);
4491  $o_Conversionrate->setPostVar('conversion_rate');
4492  $o_Conversionrate->setRequired(true);
4493 
4494  $form->addItem($o_Unit);
4495  $form->addItem($o_Isocode);
4496  $form->addItem($o_Symbol);
4497  $form->addItem($o_Conversionrate);
4498 
4499  $form->addCommandButton('saveCurrency', $this->lng->txt('save'));
4500  $form->addCommandButton('currencies', $this->lng->txt('cancel'));
4501 
4502  $this->tpl->setVariable('FORM', $form->getHTML());
4503  }
4504 
4505  public function saveCurrencyObject()
4506  {
4507  $obj_currency = new ilPaymentCurrency();
4508  $obj_currency->setUnit($_POST['currency_unit']);
4509  $obj_currency->setIsoCode($_POST['iso_code']);
4510  $obj_currency->setSymbol($_POST['symbol']);
4511  $obj_currency->setConversionRate($_POST['conversion_rate']);
4512  $obj_currency->addCurrency();
4513  $this->currenciesObject();
4514  }
4515 
4516  public function editCurrencyObject()
4517  {
4518  $currency_id = $_POST['currency_id'];
4519  $obj_currency = ilPaymentCurrency::_getCurrency($currency_id);
4520 
4521  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
4522  $form = new ilPropertyFormGUI();
4523  $form->setFormAction($this->ctrl->getFormAction($this));
4524  $form->setTitle($this->lng->txt('paya_edit_currency'));
4525 
4526  $o_Unit = new ilTextInputGUI($this->lng->txt('paya_currency_unit'),'currency_unit');
4527  $o_Unit->setValue($obj_currency[$currency_id]['unit']);
4528  $o_Unit->setPostVar('currency_unit');
4529  $o_Unit->setRequired(true);
4530 
4531  $o_Isocode = new ilTextInputGUI($this->lng->txt('iso_code'),'iso_code');
4532  $o_Isocode->setValue($obj_currency[$currency_id]['iso_code']);
4533  $o_Isocode->setPostVar('iso_code');
4534  $o_Isocode->setRequired(true);
4535 
4536  $o_Symbol = new ilTextInputGUI($this->lng->txt('symbol'), 'symbol');
4537  $o_Symbol->setValue($obj_currency[$currency_id]['symbol']);
4538  $o_Symbol->setPostVar('symbol');
4539  $o_Symbol->setRequired(true);
4540 
4541  $o_Conversionrate = new IlTextInputGUI($this->lng->txt('conversion_rate'), 'conversion_rate');
4542  $o_Conversionrate->setValue($obj_currency[$currency_id]['conversion_rate']);
4543  $o_Conversionrate->setPostVar('conversion_rate');
4544  $o_Conversionrate->setRequired(true);
4545 
4546  $o_hidden = new ilHiddenInputGUI('currency_id');
4547  $o_hidden->setValue($obj_currency[$currency_id]['currency_id']);
4548  $o_hidden->setPostVar('currency_id');
4549  $form->addItem($o_hidden);
4550 
4551  $form->addItem($o_Unit);
4552  $form->addItem($o_Isocode);
4553  $form->addItem($o_Symbol);
4554  $form->addItem($o_Conversionrate);
4555 
4556  $form->addCommandButton('updateCurrency', $this->lng->txt('save'));
4557  $form->addCommandButton('currencies', $this->lng->txt('cancel'));
4558 
4559  $this->tpl->setVariable('FORM', $form->getHTML());
4560  }
4561 
4562  public function deleteCurrencyObject()
4563  {
4564 
4565  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
4566  if(ilPaymentCurrency::_isDefault($_POST['currency_id'])) return false;
4567  $_SESSION['currency_id'] = $_POST['currency_id'];
4568 
4569  $oConfirmationGUI = new ilConfirmationGUI();
4570  $this->ctrl->setParameter($this,'currency_id',(int) $_POST['currency_id']);
4571  // set confirm/cancel commands
4572  $oConfirmationGUI->setFormAction($this->ctrl->getFormAction($this,"performDeleteCurrency"));
4573 
4574  $oConfirmationGUI->setHeaderText($this->lng->txt("paya_sure_delete_selected_currency"));
4575  $oConfirmationGUI->setCancel($this->lng->txt("cancel"), "currencies");
4576  $oConfirmationGUI->setConfirm($this->lng->txt("confirm"), "performDeleteCurrency");
4577 
4578  $oConfirmationGUI->addItem('currency_id','', ilPaymentCurrency::_getUnit($_POST['currency_id']),'' );
4579 
4580  $this->tpl->setVariable('CONFIRMATION', $oConfirmationGUI->getHtml());
4581  return true;
4582  }
4583 
4585  {
4586  if(!$_SESSION['currency_id']) return false;
4587 
4588  $obj_currency = new ilPaymentCurrency((int)$_SESSION['currency_id']);
4589  $obj_currency->deleteCurrency();
4590 
4591  return $this->currenciesObject();
4592  }
4593  public function updateCurrencyObject()
4594  {
4595  if(!$_POST['currency_id']) return false;
4596 
4597  $obj_currency = new ilPaymentCurrency($_POST['currency_id']);
4598  $obj_currency->setUnit($_POST['currency_unit']);
4599  $obj_currency->setIsoCode($_POST['iso_code']);
4600  $obj_currency->setSymbol($_POST['symbol']);
4601  $obj_currency->setConversionRate($_POST['conversion_rate']);
4602 
4603  $obj_currency->updateCurrency();
4604 
4605  $this->currenciesObject();
4606 
4607  return true;
4608  }
4609 
4610  public function TermsConditionsObject()
4611  {
4612  global $ilToolbar;
4613 
4614  $ilToolbar->addButton($this->lng->txt('edit_page'), $this->ctrl->getLinkTargetByClass(array('ilshoppagegui'), 'edit'));
4615 
4616  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
4617  $this->tpl->setVariable('FORM', $this->getDocumentsPageHTML(self::CONDITIONS_EDITOR_PAGE_ID));
4618 
4619  return true;
4620  }
4621 
4622  public function BillingMailObject()
4623  {
4624  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
4625 
4626  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
4627  $this->tpl->addJavaScript('Services/Mail/js/ilMailComposeFunctions.js');
4628 
4629  $form_gui = new ilPropertyFormGUI();
4630  $form_gui->setFormAction($this->ctrl->getFormAction($this, 'savebillingmail'));
4631  $form_gui->setTitle($this->lng->txt('billing_mail'));
4632 
4633 
4634  // MESSAGE
4635  $inp = new ilTextAreaInputGUI($this->lng->txt('message_content'), 'm_message');
4636 
4638  $inp->setRequired(false);
4639  $inp->setCols(60);
4640  $inp->setRows(10);
4641 
4642  // PLACEHOLDERS
4643  $chb = new ilCheckboxInputGUI($this->lng->txt('activate_placeholders'), 'use_placeholders');
4644  $chb->setOptionTitle($this->lng->txt('activate_placeholders'));
4645  $chb->setValue(1);
4646  $chb->setChecked(ilPaymentSettings::getMailUsePlaceholders());
4647  $form_gui->addItem($inp);
4648 
4649  include_once 'Services/Payment/classes/class.ilBillingMailPlaceholdersPropertyGUI.php';
4651 
4652  $chb->addSubItem($prop);
4653  $chb->setChecked(true);
4654 
4655  $form_gui->addItem($chb);
4656 
4657  $form_gui->addCommandButton('saveBillingMail', $this->lng->txt('save'));
4658  $this->tpl->setVariable('FORM', $form_gui->getHTML());
4659 
4660  return true;
4661  }
4662 
4663  public function saveBillingMailObject()
4664  {
4665  if($_POST['m_message'])
4666  {
4667  ilPaymentSettings::setMailBillingText($_POST['m_message']);
4668  }
4669 
4670  $_POST['use_placeholders'] ? $placeholders = 1: $placeholders = 0;
4672 
4673  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
4674  $this->BillingMailObject();
4675  }
4676 
4677  public function getDocumentsPageHTML($a_editor_page_id)
4678  {
4679 
4680  // page object
4681 
4682  include_once 'Services/Payment/classes/class.ilShopPage.php';
4683  include_once 'Services/Payment/classes/class.ilShopPageGUI.php';
4684 
4685  // if page does not exist, return nothing
4686  if(!ilShopPage::_exists('shop', $a_editor_page_id))
4687  {
4688  return '';
4689  }
4690 
4691  include_once 'Services/Style/classes/class.ilObjStyleSheet.php';
4692  $this->tpl->setVariable('LOCATION_CONTENT_STYLESHEET', ilObjStyleSheet::getContentStylePath(0));
4693 
4694  // get page object
4695  $page_gui = new ilShopPageGUI($a_editor_page_id);
4696 
4697  return $page_gui->showPage();
4698  }
4699 
4700  public function forwardToDocumentsPageObject($a_editor_page_id)
4701  {
4702  global $ilTabs;
4703 
4704  $ilTabs->clearTargets();
4705  $ilTabs->setBackTarget($this->lng->txt('back'), $this->ctrl->getLinkTarget($this,'documents'), '_self');
4706 
4707  include_once 'Services/Payment/classes/class.ilShopPage.php';
4708  include_once 'Services/Payment/classes/class.ilShopPageGUI.php';
4709  include_once('./Services/Style/classes/class.ilObjStyleSheet.php');
4710 
4711  $this->tpl->setVariable('LOCATION_CONTENT_STYLESHEET', ilObjStyleSheet::getContentStylePath(0));
4712 
4713  if(!ilShopPage::_exists('shop', $a_editor_page_id))
4714  {
4715  // doesn't exist -> create new one
4716  $new_page_object = new ilShopPage();
4717  $new_page_object->setParentId(0);
4718  $new_page_object->setId($a_editor_page_id);
4719  $new_page_object->createFromXML();
4720  }
4721 
4722  $this->ctrl->setReturnByClass('ilshoppagegui', 'edit');
4723 
4724  $page_gui = new ilShopPageGUI(self::CONDITIONS_EDITOR_PAGE_ID);
4725 
4726  return $this->ctrl->forwardCommand($page_gui);
4727  }
4728 
4729  public function InvoiceNumberObject()
4730  {
4731  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
4732 
4733  $invObj = new ilUserDefinedInvoiceNumber();
4734 
4735  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
4736  $this->tpl->addJavaScript('Services/Mail/js/ilMailComposeFunctions.js');
4737 
4738  $form_gui = new ilPropertyFormGUI();
4739  $form_gui->setFormAction($this->ctrl->getFormAction($this, 'saveInvoiceNumber'));
4740  $form_gui->setTitle($this->lng->txt('invoice_number_setting'));
4741 
4742  // invoice_type
4743  $radio_group = new ilRadioGroupInputGUI($this->lng->txt('invoice_number'), 'ud_invoice_number');
4744  $radio_option_1 = new ilRadioOption($this->lng->txt('ilias_invoice_number'), '0');
4745  $radio_group->addOption($radio_option_1);
4746  $radio_option_2 = new ilRadioOption($this->lng->txt('userdefined_invoice_number'), '1');
4747  $radio_group->addOption($radio_option_2);
4748  $radio_group->setRequired(true);
4749  $radio_group->setValue($invObj->getUDInvoiceNumberActive(),'0');
4750  $radio_group->setPostVar('ud_invoice_number');
4751  $form_gui->addItem($radio_group);
4752 
4753  // incremental current value
4754  $cur_num = new ilNonEditableValueGUI($this->lng->txt('incremental_current_value'), 'inc_current_value');
4756  $radio_option_2->addSubItem($cur_num);
4757 
4758  // incremental start value
4759  $inc_num = new ilNumberInputGUI($this->lng->txt('incremental_start_value'), 'inc_start_value');
4760  $inc_num->setValue($this->error != "" && isset($_POST['incremental_start_value'])
4761  ? ilUtil::prepareFormOutput($_POST['incremental_start_value'],true)
4762  : ilUtil::prepareFormOutput($invObj->getIncStartValue(),true));
4763  $inc_num->setInfo($this->lng->txt('incremental_start_value_info'));
4764  $radio_option_2->addSubItem($inc_num);
4765 
4766  // reset period of current value
4767  $sel_reset = new ilSelectInputGUI($this->lng->txt('invoice_number_reset_period'), 'inc_reset_period');
4768  $sel_reset->setValue($this->error != "" && isset($_POST['inc_reset_period'])
4769  ? $_POST['inc_reset_period']
4770  : $invObj->getIncResetPeriod());
4771 
4772  $reset_options = array(
4773  1 => $this->lng->txt('yearly'),
4774  2 => $this->lng->txt('monthly'));
4775  $sel_reset->setOptions($reset_options);
4776 
4777  $radio_option_2->addSubItem($sel_reset);
4778 
4779  // invoice_number_text
4780  $inp = new ilTextAreaInputGUI($this->lng->txt('invoice_number_text'), 'invoice_number_text');
4781  $inp->setValue( $this->error != "" && isset($_POST['invoice_number_text'])
4782  ? ilUtil::prepareFormOutput($_POST['invoice_number_text'],true)
4783  : ilUtil::prepareFormOutput($invObj->getInvoiceNumberText(),true));
4784 
4785 
4786  $inp->setRequired(false);
4787  $inp->setCols(60);
4788  $inp->setRows(3);
4789  $radio_option_2->addSubItem($inp);
4790 
4791  // PLACEHOLDERS
4792 
4794  $radio_option_2->addSubItem($prop);
4795 
4796  $form_gui->addCommandButton('saveInvoiceNumber', $this->lng->txt('save'));
4797  $this->tpl->setVariable('FORM', $form_gui->getHTML());
4798  }
4799 
4800  public function saveInvoiceNumberObject()
4801  {
4802  // check conditions
4803  if($_POST['ud_invoice_number'] == 1)
4804  {
4805  if($_POST['inc_start_value'] <= 0 || $_POST['inc_start_value'] == NULL)
4806  {
4807  $this->error = $this->lng->txt('start_value_cannot_be_null');
4808  ilUtil::sendFailure($this->error);
4810  return $this->InvoiceNumberObject();
4811  }
4812 
4813  if($_POST['invoice_number_text'] !== NULL)
4814  {
4815  $check_text = $_POST['invoice_number_text'];
4816 
4817  if(strpos($check_text, '[INCREMENTAL_NUMBER]') === FALSE)
4818  {
4819  $this->error = $this->lng->txt('invoice_number_must_contain_incremental_number');
4820  ilUtil::sendFailure($this->error);
4821  $this->InvoiceNumberObject();
4822  return true;
4823  }
4824  else
4825  {
4826  if($_POST['inc_reset_period'] == 1) // yearly
4827  {
4828  if(strpos($check_text, '[YEAR]') === FALSE && strpos($check_text, '[CURRENT_TIMESTAMP]') === FALSE)
4829  {
4830  $this->error = $this->lng->txt('invoice_number_must_contain_year_ct');
4831  ilUtil::sendFailure($this->error);
4832  $this->InvoiceNumberObject();
4833  return true;
4834  }
4835  }
4836  else if($_POST['inc_reset_period'] == 2) // monthly
4837  {
4838  if((strpos($check_text, '[YEAR]') === FALSE || strpos($check_text, '[MONTH]') === FALSE )
4839  && (strpos($check_text, '[CURRENT_TIMESTAMP]') === FALSE))
4840  {
4841  $this->error = $this->lng->txt('invoice_number_must_contain_year_month_ct');
4842  ilUtil::sendFailure($this->error);
4843  $this->InvoiceNumberObject();
4844  return true;
4845  }
4846  }
4847  }
4848  }
4849  else
4850  {
4851  ilUtil::sendFailure($this->lng->txt('invoice_number_text_cannot_be_null'));
4852  $this->InvoiceNumberObject();
4853  return true;
4854  }
4855  }
4856  // everythink ok .... update settings
4857  $invObj = new ilUserDefinedInvoiceNumber();
4858  $invObj->setUDInvoiceNumberActive($_POST['ud_invoice_number']);
4859  $invObj->setIncStartValue($_POST['inc_start_value']);
4860  $invObj->setIncResetPeriod($_POST['inc_reset_period']);
4861  $invObj->setInvoiceNumberText($_POST['invoice_number_text']);
4862  $invObj->update();
4863 
4864  $this->InvoiceNumberObject();
4865  ilUtil::sendSuccess($this->lng->txt('pays_updated_general_settings'));
4866 
4867  return true;
4868  }
4869 
4870  public function StatutoryRegulationsObject()
4871  {
4872  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
4873  $form = new ilPropertyFormGUI();
4874  $form->setFormAction($this->ctrl->getFormAction($this, 'saveStatutoryRegulations'));
4875  $form->setTitle($this->lng->txt('statutory_regulations'));
4876  $form->setTableWidth('100%');
4877  // message
4878  $post_gui = new ilTextAreaInputGUI($this->lng->txt('content'), 'statutory_regulations');
4879  $post_gui->setCols(50);
4880  $post_gui->setRows(15);
4881  $post_gui->setUseRte(true);
4882  $post_gui->addPlugin('latex');
4883  $post_gui->addButton('latex');
4884  $post_gui->addButton('pastelatex');
4885  $post_gui->addPlugin('ilimgupload');
4886  $post_gui->addButton('ilimgupload');
4887  $post_gui->removePlugin('advlink');
4888  $post_gui->removePlugin(ilRTE::ILIAS_IMG_MANAGER_PLUGIN);
4889  $post_gui->removePlugin('image');
4890  $post_gui->usePurifier(true);
4891  $post_gui->setRTERootBlockElement('');
4892  $post_gui->setRTESupport(ilObject::_lookupObjId($this->ref_id), 'pays~', 'frm_post', 'tpl.tinymce_frm_post.html', false, '3.4.7');
4893  $post_gui->disableButtons(array(
4894  'charmap',
4895  'undo',
4896  'redo',
4897  'justifyleft',
4898  'justifycenter',
4899  'justifyright',
4900  'justifyfull',
4901  'anchor',
4902  'fullscreen',
4903  'cut',
4904  'copy',
4905  'paste',
4906  'pastetext',
4907  'formatselect',
4908  'image'
4909  ));
4910  // purifier
4911  require_once 'Services/Html/classes/class.ilHtmlPurifierFactory.php';
4912  require_once 'Services/RTE/classes/class.ilRTE.php';
4913  $post_gui->setPurifier(ilHtmlPurifierFactory::_getInstanceByType('frm_post'));
4914  $post_gui->setValue(ilRTE::_replaceMediaObjectImageSrc($this->genSetData->get('statutory_regulations'),1));
4915  $form->addItem($post_gui);
4916 
4917  // show staturaltyio regulations in shoppingcart
4918  $cb_showShoppingCart = new ilCheckboxInputGUI($this->lng->txt('show_sr_shoppingcart'), 'show_sr_shoppingcart');
4919  $cb_showShoppingCart->setInfo($this->lng->txt('show_sr_shoppingcart_info'));
4920  $cb_showShoppingCart->setValue(1);
4921  $cb_showShoppingCart->setChecked($this->genSetData->get('show_sr_shoppingcart'));
4922  $form->addItem($cb_showShoppingCart);
4923 
4924  // attach staturaltyio regulations at invoice
4925  $cb_attachInvoice = new ilCheckboxInputGUI($this->lng->txt('attach_sr_invoice'), 'attach_sr_invoice');
4926  $cb_attachInvoice->setInfo($this->lng->txt('attach_sr_invoice_info'));
4927  $cb_attachInvoice->setValue(1);
4928  $cb_attachInvoice->setChecked($this->genSetData->get('attach_sr_invoice'));
4929  $form->addItem($cb_attachInvoice);
4930 
4931  $form->addCommandButton('saveStatutoryRegulations', $this->lng->txt('save'));
4932  $this->tpl->setVariable('FORM', $form->getHTML());
4933 
4934  }
4935 
4937  {
4938  require_once 'Services/RTE/classes/class.ilRTE.php';
4939 
4940  if(isset($_POST['statutory_regulations']) && $_POST['statutory_regulations'] != NULL)
4941  {
4942  $this->genSetData->set('statutory_regulations', ilRTE::_replaceMediaObjectImageSrc($_POST['statutory_regulations'], 0), 'regulations');
4943 
4944  // copy temporary media objects (frm~)
4945  include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
4946  $mediaObjects = ilRTE::_getMediaObjects($_POST['statutory_regulations'], 0);
4947  $myMediaObjects = ilObjMediaObject::_getMobsOfObject('pays~:html', ilObject::_lookupObjId($this->ref_id));
4948  foreach($mediaObjects as $mob)
4949  {
4950  foreach($myMediaObjects as $myMob)
4951  {
4952  if($mob == $myMob)
4953  {
4954  // change usage
4955  ilObjMediaObject::_removeUsage($mob, 'pays~:html', ilObject::_lookupObjId($this->ref_id));
4956  break;
4957  }
4958  }
4959  ilObjMediaObject::_saveUsage($mob, 'pays~:html',ilObject::_lookupObjId($this->ref_id));
4960  }
4961  }
4962  else
4963  {
4964  $this->genSetData->set('statutory_regulations', NULL, 'regulations');
4965  }
4966 
4967  // remove usage of deleted media objects
4968  include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
4969  $oldMediaObjects = ilObjMediaObject::_getMobsOfObject('pays~:html', ilObject::_lookupObjId($this->ref_id));
4970  $curMediaObjects = ilRTE::_getMediaObjects($_POST['statutory_regulations'], 0);
4971  foreach($oldMediaObjects as $oldMob)
4972  {
4973  $found = false;
4974  foreach($curMediaObjects as $curMob)
4975  {
4976  if($oldMob == $curMob)
4977  {
4978  $found = true;
4979  break;
4980  }
4981  }
4982  if(!$found)
4983  {
4984  if(ilObjMediaObject::_exists($oldMob))
4985  {
4986  ilObjMediaObject::_removeUsage($oldMob, 'pays~:html', ilObject::_lookupObjId($this->ref_id));
4987  $mob_obj = new ilObjMediaObject($oldMob);
4988  $mob_obj->delete();
4989  }
4990  }
4991  }
4992 
4993  $this->genSetData->set('show_sr_shoppingcart', isset($_POST['show_sr_shoppingcart']) ? 1 : 0, 'regulations');
4994  $this->genSetData->set('attach_sr_invoice', isset($_POST['attach_sr_invoice']) ? 1 : 0, 'regulations');
4995 
4996  $this->StatutoryRegulationsObject();
4997  ilUtil::sendSuccess($this->lng->txt('pays_updated_general_settings'));
4998  return true;
4999  }
5000 
5001  public function editPriceObject()
5002  {
5003  $this->tpl->addBlockfile('ADM_CONTENT', 'adm_content', 'tpl.main_view.html', 'Services/Payment');
5004 
5005  $price_id = $_GET['price_id']?$_GET['price_id']: $_POST['price_id'];
5006  $price= ilPaymentPrices::_getPrice($price_id);
5007  $this->ctrl->setParameter($this,'pobject_id',(int) $_GET['pobject_id']);
5008  $tmp_pobject = ilPaymentObject::_getObjectData($_GET['pobject_id']);
5009  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
5010  $form = new ilPropertyFormGUI();
5011  $form->setFormAction($this->ctrl->getFormAction($this));
5012 
5013  $tmp_obj = ilObjectFactory::getInstanceByRefId($tmp_pobject['ref_id'], false);
5014 
5015  if($tmp_obj)
5016  {
5017  $form->setTitle($tmp_obj->getTitle());
5018  }
5019  else
5020  {
5021  $form->setTitle($this->lng->txt('object_not_found'));
5022  }
5023 
5024  //price_type
5025  $radio_group = new ilRadioGroupInputGUI('','price_type');
5026  $radio_group->setTitle($this->lng->txt('duration'));
5027  $radio_group->setRequired(true);
5028  $radio_group->setValue($price['price_type']);
5029  $radio_group->setPostVar('price_type');
5030 
5031  $radio_option_1 = new ilRadioOption($this->lng->txt('duration_month'), ilPaymentPrices::TYPE_DURATION_MONTH);
5032 
5033  // duration month
5034  $oDuration = new ilNumberInputGUI();
5035  $oDuration->setTitle($this->lng->txt('paya_months'));
5036  $oDuration->setSize('20%');
5037  $oDuration->setValue($price['duration']);
5038  $oDuration->setPostVar('duration_month');
5039  $radio_option_1->addSubItem($oDuration);
5040 
5041  $radio_group->addOption($radio_option_1);
5042 
5043  $radio_option_3 = new ilRadioOption($this->lng->txt('duration_date'), ilPaymentPrices::TYPE_DURATION_DATE);
5044 
5045  // duration_date from
5046  $o_date_from = new ilDateTimeInputGUI();
5047  $o_date_from->setTitle($this->lng->txt('cal_from'));
5048  $o_date_from->setDate(new ilDate($price['duration_from'],IL_CAL_DATE));
5049  $o_date_from->setPostVar('duration_date_from');
5050  $radio_option_3->addSubItem($o_date_from);
5051 
5052  // duration_date until
5053  $o_date_until = new ilDateTimeInputGUI();
5054  $o_date_until->setTitle($this->lng->txt('cal_until'));
5055  $o_date_until->setDate(new ilDate($price['duration_until'],IL_CAL_DATE));
5056  $o_date_until->setPostVar('duration_date_until');
5057  $radio_option_3->addSubItem($o_date_until);
5058 
5059  $radio_group->addOption($radio_option_3);
5060 
5061  $radio_option_2 = new ilRadioOption($this->lng->txt('unlimited_duration'), ilPaymentPrices::TYPE_UNLIMITED_DURATION);
5062  $radio_group->addOption($radio_option_2);
5063 
5064  $form->addItem($radio_group);
5065 
5066  // description
5067  $oDescription = new ilTextAreaInputGUI($this->lng->txt('description'), 'description');
5068  $oDescription->setRows(4);
5069  $oDescription->setCols(35);
5070  $oDescription->setValue($price['description']);
5071  $form->addItem($oDescription);
5072 
5073  // price
5074  $oPrice = new ilNumberInputGUI();
5075  $oPrice->setTitle($this->lng->txt('price_a'));
5076  $oPrice->setSize('20%');
5077  $oPrice->setRequired(true);
5078  $oPrice->setValue($price['price']);
5079  include_once './Services/Payment/classes/class.ilPaymentSettings.php';
5080  $genSet = ilPaymentSettings::_getInstance();
5081  $oPrice->setInfo($genSet->get('currency_unit'));
5082  $oPrice->setPostVar('price');
5083  $oPrice->allowDecimals(true);
5084  $form->addItem($oPrice);
5085 
5086  //extension
5087  $oExtension = new ilCheckboxInputGUI($this->lng->txt('extension_price'), 'extension');
5088 
5089  $oExtension->setChecked($price['extension']);
5090 
5091  $form->addItem($oExtension);
5092 
5093  $o_hidden_1 = new ilHiddenInputGUI('pobject_id');
5094  $o_hidden_1->setValue( (int)$_GET['pobject_id']);
5095  $o_hidden_1->setPostVar('pobject_id');
5096 
5097  $o_hidden_2 = new ilHiddenInputGUI('price_id');
5098  $o_hidden_2->setValue( (int)$_GET['price_id']);
5099  $o_hidden_2->setPostVar('price_id');
5100 
5101  $form->addItem($o_hidden_1);
5102  $form->addItem($o_hidden_2);
5103 
5104  $form->addCommandButton('updatePrice',$this->lng->txt('save'));
5105  $form->addCommandButton('editPrices', $this->lng->txt('cancel'));
5106 
5107  $this->tpl->setVariable('FORM',$form->getHTML());
5108  }
5109 
5110 } // END class.ilObjPaymentSettingsGUI
5111 ?>