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