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