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