ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPaymentObjectGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once 'Services/Payment/classes/class.ilPaymentObject.php';
5 include_once 'Services/Payment/classes/class.ilPaymentBookings.php';
6 include_once 'Services/Payment/classes/class.ilFileDataShop.php';
7 include_once 'Services/Payment/classes/class.ilShopVatsList.php';
8 include_once './Services/Payment/classes/class.ilShopTableGUI.php';
9 
10 
21 {
23  public $ctrl;
25  public $lng;
27  public $user_obj;
29  public $pobject = null;
30 
31  public function __construct($user_obj)
32  {
34 
35  $this->user_obj = $user_obj;
36  $this->lng->loadLanguageModule('crs');
38  }
39 
40  protected function prepareOutput()
41  {
45  global $ilTabs;
46 
47  $this->setSection(6);
48 
50 
51  $ilTabs->setTabActive('paya_header');
52  $ilTabs->setSubTabActive('paya_object');
53  }
54 
55  public function executeCommand()
56  {
57  $cmd = $this->ctrl->getCmd();
58  switch($this->ctrl->getNextClass($this))
59  {
60  case 'ilshoppagegui':
61  $this->prepareOutput();
62  $ret = $this->forwardToPageObject();
63  if($ret != '')
64  {
65  $this->tpl->setContent($ret);
66  }
67  break;
68 
69  default:
70  if(!$cmd)
71  {
72  $cmd = 'showObjects';
73  }
74  $this->prepareOutput();
75  $this->$cmd();
76  break;
77  }
78  }
79 
80  public function forwardToPageObject()
81  {
85  global $ilTabs;
86 
87  if(!(int)$_GET['pobject_id'])
88  {
89  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
90  return $this->showObjects();
91  }
92  $this->ctrl->setParameter($this, 'pobject_id', (int)$_GET['pobject_id']);
93  $this->__initPaymentObject((int)$_GET['pobject_id']);
94 
95  $this->lng->loadLanguageModule('content');
96 
97  $ilTabs->clearTargets();
98  $ilTabs->clearSubTabs();
99  $ilTabs->setBackTarget($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'editDetails'), '_top');
100 
101  // page objec
102  include_once 'Services/Payment/classes/class.ilShopPage.php';
103  include_once 'Services/Payment/classes/class.ilShopPageGUI.php';
104  include_once('./Services/Style/classes/class.ilObjStyleSheet.php');
105 
106  $this->tpl->setVariable('LOCATION_CONTENT_STYLESHEET', ilObjStyleSheet::getContentStylePath(0));
107 
108  if(!ilShopPage::_exists('shop', $this->pobject->getPobjectId()))
109  {
110  // doesn't exist -> create new one
111  $new_page_object = new ilShopPage();
112  $new_page_object->setParentId(0);
113  $new_page_object->setId($this->pobject->getPobjectId());
114  $new_page_object->createFromXML();
115  }
116 
117  $this->ctrl->setReturnByClass('ilshoppagegui', 'edit');
118 
119  $page_gui = new ilShopPageGUI($this->pobject->getPobjectId());
120  $this->ctrl->setParameter($page_gui, 'pobject_id', (int)$_GET['pobject_id']);
121 
122  return $this->ctrl->forwardCommand($page_gui);
123  }
124 
125  public function resetObjectFilter()
126  {
127  unset($_SESSION['pay_objects']);
128  unset($_POST['title_type']);
129  unset($_POST['title_value']);
130  unset($_POST['vendor']);
131  unset($_POST['pay_method']);
132  unset($_POST['updateView']);
133  unset($_POST['show_filter']);
134 
135  ilUtil::sendInfo($this->lng->txt('paya_filter_reseted'));
136 
137  return $this->showObjects();
138  }
139 
140  public function showObjects()
141  {
144  global $ilToolbar;
145 
146  include_once './Services/Payment/classes/class.ilPayMethods.php';
147 
148  $ilToolbar->addButton($this->lng->txt('paya_sell_object'), $this->ctrl->getLinkTarget($this, 'showObjectSelector'));
149 
150  if(!$_POST['show_filter'] && $_POST['updateView'] == '1')
151  {
152  $this->resetObjectFilter();
153  }
154  else
155  if($_POST['updateView'] == 1)
156  {
157  $_SESSION['pay_objects']['updateView'] = $_POST['updateView'];
158  $_SESSION['pay_objects']['show_filter'] = $_POST['show_filter'];
159  $_SESSION['pay_objects']['title_type'] = $_POST['title_type'];
160  $_SESSION['pay_objects']['title_value'] = $_POST['title_value'];
161  $_SESSION['pay_objects']['pay_method'] = $_POST['pay_method'];
162  $_SESSION['pay_objects']['vendor'] = $_POST['vendor'];
163  }
164 
165  $this->tpl->addBlockfile('ADM_CONTENT', 'adm_content', 'tpl.main_view.html', 'Services/Payment');
166 
167  $this->__initPaymentObject();
168  $this->lng->loadLanguageModule('search');
169 
170  $filter_form = new ilPropertyFormGUI();
171  $filter_form->setFormAction($this->ctrl->getFormAction($this));
172  $filter_form->setTitle($this->lng->txt('pay_filter'));
173  $filter_form->setId('filter_form');
174  $filter_form->setTableWidth('100 %');
175 
176  //hide_filter
177  $o_hide_check = new ilCheckBoxInputGUI($this->lng->txt('show_filter'), 'show_filter');
178  $o_hide_check->setValue(1);
179  $o_hide_check->setChecked($_SESSION['pay_objects']['show_filter'] ? 1 : 0);
180 
181  $o_hidden = new ilHiddenInputGUI('updateView');
182  $o_hidden->setValue(1);
183  $o_hidden->setPostVar('updateView');
184  $o_hide_check->addSubItem($o_hidden);
185 
186  //title
187  $radio_group = new ilRadioGroupInputGUI($this->lng->txt('search_in_title'), 'title_type');
188  $radio_option = new ilRadioOption($this->lng->txt('search_any_word'), 'or');
189  $radio_group->addOption($radio_option);
190  $radio_option = new ilRadioOption($this->lng->txt('search_all_words'), 'and');
191  $radio_group->addOption($radio_option);
192 
193  $radio_group->setRequired(false);
194  $radio_group->setValue('or');
195  $radio_group->setPostVar('title_type');
196 
197  $o_title = new ilTextInputGUI();
198  $o_title->setValue($_SESSION['pay_objects']['title_value']);
199  $o_title->setPostVar('title_value');
200  $o_title->setTitle($this->lng->txt('title'));
201 
202  $o_hide_check->addSubItem($radio_group);
203  $o_hide_check->addSubItem($o_title);
204 
205  //vendor
206  $o_vendor = new ilTextInputGUI();
207  $o_vendor->setTitle($this->lng->txt('paya_vendor'));
208  $o_vendor->setValue($_SESSION['pay_objects']['vendor']);
209  $o_vendor->setPostVar('vendor');
210  $o_hide_check->addSubItem($o_vendor);
211 
212  // paymethod
213  $o_paymethod = new ilSelectInputGUI();
214  $o_paymethod->setTitle($this->lng->txt('payment_system'));
215  $o_paymethod->setOptions(ilPaymethods::getPayMethodsOptions('all'));
216  $o_paymethod->setValue($_SESSION['pay_objects']['pay_method']);
217  $o_paymethod->setPostVar('pay_method');
218  $o_hide_check->addSubItem($o_paymethod);
219 
220  $filter_form->addCommandButton('showObjects', $this->lng->txt('pay_update_view'));
221  $filter_form->addCommandButton('resetObjectFilter', $this->lng->txt('pay_reset_filter'));
222 
223  $filter_form->addItem($o_hide_check);
224  if(!count($objects = ilPaymentObject::_getObjectsData($this->user_obj->getId())))
225  {
226  ilUtil::sendInfo($this->lng->txt('paya_no_objects_assigned'));
227 
228  return true;
229  }
230  $this->tpl->setVariable('FORM', $filter_form->getHTML());
231 
232  $counter = 0;
233  foreach($objects as $data)
234  {
236  $tmp_obj = ilObjectFactory::getInstanceByRefId($data['ref_id'], false);
237  if($tmp_obj)
238  {
239  $f_result[$counter]['title'] = $tmp_obj->getTitle();
240  }
241  else
242  {
243  $f_result[$counter]['title'] = $this->lng->txt('object_not_found');
244  }
245 
246 
247  switch($data['status'])
248  {
249  case $this->pobject->STATUS_BUYABLE:
250  $f_result[$counter]['status'] = $this->lng->txt('paya_buyable');
251  break;
252 
253  case $this->pobject->STATUS_NOT_BUYABLE:
254  $f_result[$counter]['status'] = $this->lng->txt('paya_not_buyable');
255  break;
256 
257  case $this->pobject->STATUS_EXPIRES:
258  $f_result[$counter]['status'] = $this->lng->txt('paya_expires');
259  break;
260  }
261  $str_paymethod = ilPayMethods::getStringByPaymethod($data['pay_method']);
262  $f_result[$counter]['pay_method'] = $str_paymethod;
263 
264  if($data['vat_id'] <= 0)
265  {
266  $vat_rate = $this->lng->txt('payment_vat_has_to_be_defined_by_administration_short');
267  }
268  else
269  {
270  try
271  {
272  $oVAT = new ilShopVats((int)$data['vat_id']);
273  $vat_rate = ilShopUtils::_formatVAT((float)$oVAT->getRate());
274  }
275  catch(ilShopException $e)
276  {
277  $vat_rate = $this->lng->txt('payment_vat_has_to_be_defined_by_administration_short');
278  }
279  }
280  $f_result[$counter]['vat_rate'] = $vat_rate;
281 
283  $tmp_user = ilObjectFactory::getInstanceByObjId($data['vendor_id']);
284  $f_result[$counter]['vendor'] = $tmp_user->getFullname() . ' [' . $tmp_user->getLogin() . ']';
285 
286  // Get number of purchasers
287  $f_result[$counter]['purchasers'] = ilPaymentBookings::_getCountBookingsByObject($data['pobject_id']);
288 
289  // edit link
290  $this->ctrl->setParameter($this, 'pobject_id', $data['pobject_id']);
291  $link_change = "<div class=\"il_ContainerItemCommands\"><a class=\"il_ContainerItemCommand\" href=\"" . $this->ctrl->getLinkTarget($this, "editDetails") . "\">" . $this->lng->txt("edit") . "</a></div>";
292 
293  $f_result[$counter]['options'] = $link_change;
294  unset($tmp_user);
295  unset($tmp_obj);
296 
297  ++$counter;
298  }
299 
300  return $this->__showObjectsTable($f_result);
301  }
302 
303  public function editDetails($a_show_confirm = false)
304  {
308  global $ilToolbar;
309 
310  include_once './Services/Payment/classes/class.ilPaymentSettings.php';
313 
314  if(!(int)$_GET['pobject_id'])
315  {
316  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
317  return $this->showObjects();
318  }
319 
320  $this->__initPaymentObject((int)$_GET['pobject_id']);
321 
322  $this->ctrl->setParameter($this, 'pobject_id', (int)$_GET['pobject_id']);
323 
324  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.main_view.html', 'Services/Payment');
326  $tmp_obj = ilObjectFactory::getInstanceByRefId($this->pobject->getRefId(), false);
327  if(is_object($tmp_obj))
328  {
329  $trash = '';
330  if(ilObject::_isInTrash($this->pobject->getRefId()))
331  {
332  $trash = ' (' . $this->lng->txt('object_deleted') . ')';
333  }
334  $tmp_object['title'] = $tmp_obj->getTitle() . '' . $trash;
335  $tmp_object['type'] = $tmp_obj->getType();
336  }
337  else
338  {
339  $tmp_object['title'] = $this->lng->txt('object_not_found');
340  $tmp_object['type'] = false;
341  }
342 
343  if($a_show_confirm)
344  {
345  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
346  $oConfirmationGUI = new ilConfirmationGUI();
347 
348  // set confirm/cancel commands
349  $oConfirmationGUI->setFormAction($this->ctrl->getFormAction($this, "performDelete"));
350  $oConfirmationGUI->setHeaderText($this->lng->txt("paya_sure_delete_object"));
351  $oConfirmationGUI->setCancel($this->lng->txt("cancel"), "editDetails");
352  $oConfirmationGUI->setConfirm($this->lng->txt("confirm"), "performDelete");
353 
354  $oConfirmationGUI->addItem('', $tmp_object['title'], $tmp_object['title']);
355  $this->tpl->setVariable('CONFIRMATION', $oConfirmationGUI->getHTML());
356 
357  return true;
358  }
359 
360  $ilToolbar->addButton($this->lng->txt('paya_edit_details'), $this->ctrl->getLinkTarget($this, 'editDetails'));
361  $ilToolbar->addButton($this->lng->txt('paya_edit_prices'), $this->ctrl->getLinkTarget($this, 'editPrices'));
362  $ilToolbar->addButton($this->lng->txt('pay_edit_abstract'), $this->ctrl->getLinkTargetByClass(array('ilshoppagegui'), 'edit'));
363 
364  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
365  $oForm = new ilPropertyFormGUI();
366  $oForm->setFormAction($this->ctrl->getFormAction($this, 'updateDetails'));
367  $oForm->setTitle($tmp_object['title']);
368  if($tmp_object['type'])
369  $oForm->setTitleIcon(ilUtil::getImagePath('icon_' . $tmp_object['type'] . '_b.png'));
370 
371  // repository path
372  $oPathGUI = new ilNonEditableValueGUI($this->lng->txt('path'));
373  $oPathGUI->setValue($this->__getHTMLPath($this->pobject->getRefId()));
374  $oForm->addItem($oPathGUI);
375 
376  switch($tmp_object['type'])
377  {
378  case 'exc':
379  $exc_subtype_option = array();
380  $check_subtypes = ilPaymentObject::_checkExcSubtype($this->pobject->getRefId());
381 
382  if(!in_array('download', $check_subtypes) || $this->pobject->getSubtype() == 'download')
383  $exc_subtype_option['download'] = $this->lng->txt('download');
384  if(!in_array('upload', $check_subtypes) || $this->pobject->getSubtype() == 'upload')
385  $exc_subtype_option['upload'] = $this->lng->txt('upload');
386 
387  $oExcSubtype = new ilSelectInputGUI($this->lng->txt('select_subtype'), 'exc_subtype');
388  $oExcSubtype->setOptions($exc_subtype_option);
389  $oExcSubtype->setValue($this->pobject->getSubtype());
390  $oForm->addItem($oExcSubtype);
391 
392  break;
393  default:
394  break;
395  }
396  // number of purchasers
397  $oPurchasersGUI = new ilNonEditableValueGUI($this->lng->txt('paya_count_purchaser'));
398  $oPurchasersGUI->setValue(ilPaymentBookings::_getCountBookingsByObject((int)$_GET['pobject_id']));
399  $oForm->addItem($oPurchasersGUI);
400 
401  // vendors
402  $oVendorsGUI = new ilSelectInputGUI($this->lng->txt('paya_vendor'), 'vendor');
403  $oVendorsGUI->setOptions($this->__getVendors());
404  $oVendorsGUI->setValue($this->pobject->getVendorId());
405  $oForm->addItem($oVendorsGUI);
406 
407  // status
408  $oStatusGUI = new ilSelectInputGUI($this->lng->txt('status'), 'status');
409  $oStatusGUI->setOptions($this->__getStatus());
410  $oStatusGUI->setValue($this->pobject->getStatus());
411  $oForm->addItem($oStatusGUI);
412 
413  // pay methods
414  $oPayMethodsGUI = new ilSelectInputGUI($this->lng->txt('paya_pay_method'), 'pay_method');
415  $PMoptions = ilPaymethods::getPayMethodsOptions('not_specified');
416  $oPayMethodsGUI->setOptions($PMoptions);
417  $oPayMethodsGUI->setValue($this->pobject->getPayMethod());
418  $oForm->addItem($oPayMethodsGUI);
419 
420  // topics
422  $shopTopicsObj = ilShopTopics::_getInstance();
423  $shopTopicsObj->read();
424  if(is_array($topics = $shopTopicsObj->getTopics()) && count($topics))
425  {
426  $oTopicsGUI = new ilSelectInputGUI($this->lng->txt('topic'), 'topic_id');
427  include_once 'Services/Payment/classes/class.ilShopTopics.php';
429  $shopTopicsObj = ilShopTopics::_getInstance();
430  $shopTopicsObj->read();
431  $topic_options = array();
432  $topic_options[''] = $this->lng->txt('please_choose');
433 
435  foreach($topics as $oTopic)
436  {
437  $topic_options[$oTopic->getId()] = $oTopic->getTitle();
438  }
439 
440  $oTopicsGUI->setOptions($topic_options);
441  $oTopicsGUI->setValue($this->pobject->getTopicId());
442  $oForm->addItem($oTopicsGUI);
443  }
444 
445  // vats
446  $oShopVatsList = new ilShopVatsList();
447  $oShopVatsList->read();
448  if($oShopVatsList->hasItems())
449  {
450  $oVatsGUI = new ilSelectInputGUI($this->lng->txt('vat_rate'), 'vat_id');
451 
452  $vats_options = array();
454  foreach($oShopVatsList as $oVAT)
455  {
456  $vats_options[$oVAT->getId()] = ilShopUtils::_formatVAT($oVAT->getRate()) . ' -> ' . $oVAT->getTitle();
457  }
458 
459  $oVatsGUI->setOptions($vats_options);
460  $oVatsGUI->setValue($this->pobject->getVatId());
461  $oForm->addItem($oVatsGUI);
462  }
463  else
464  {
465  $oVatsGUI = new ilNonEditableValueGUI($this->lng->txt('vat_rate'));
466  $oVatsGUI->setValue($this->lng->txt('paya_no_vats_assigned'));
467  $oForm->addItem($oVatsGUI);
468  }
469 
470  $oThumbnail = new ilImageFileInputGUI($this->lng->txt('pay_thumbnail'), 'thumbnail');
471  $oFile = new ilFileDataShop($this->pobject->getPobjectId());
472  if(($webpath_file = $oFile->getCurrentImageWebPath()) !== false)
473  {
474  $oThumbnail->setImage($webpath_file);
475  }
476  $oForm->addItem($oThumbnail);
477 
478  if($genSet->get('use_shop_specials'))
479  {
480  // special object
481  $oSpecial = new ilCheckboxInputGUI($this->lng->txt('special'), 'is_special');
482  $oSpecial->setChecked((int)$this->pobject->getSpecial());
483  $oSpecial->setInfo($this->lng->txt('special_info'));
484  $oForm->addItem($oSpecial);
485  }
486  // buttons
487  $oForm->addCommandButton('updateDetails', $this->lng->txt('save'));
488  $oForm->addCommandButton('deleteObject', $this->lng->txt('delete'));
489 
490  $this->tpl->setVariable('FORM', $oForm->getHTML());
491  return true;
492  }
493 
494  public function deleteObject()
495  {
496  include_once './Services/Payment/classes/class.ilPaymentBookings.php';
497 
498  if(!$_GET['pobject_id'])
499  {
500  ilUtil::sendFailure($this->lng->txt('paya_no_object_selected'));
501 
502  $this->showObjects();
503  return true;
504  }
505  if(ilPaymentBookings::_getCountBookingsByObject((int)$_GET['pobject_id']))
506  {
507  ilUtil::sendInfo($this->lng->txt('paya_bookings_available'));
508  $this->editDetails();
509 
510  return false;
511  }
512  else
513  {
514 
515  $this->editDetails(true);
516 
517  return true;
518  }
519  }
520 
521  public function performDelete()
522  {
523  include_once './Services/Payment/classes/class.ilPaymentPrices.php';
524 
525  if(!$_GET['pobject_id'])
526  {
527  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
528 
529  $this->showObjects();
530  return true;
531  }
532  $this->__initPaymentObject((int)$_GET['pobject_id']);
533 
534  // delete object data
535  $this->pobject->delete();
536 
537  // delete payment prices
538  $price_obj = new ilPaymentPrices((int)$_GET['pobject_id']);
539  $price_obj->deleteAllPrices();
540  unset($price_obj);
541 
542  ilUtil::sendInfo($this->lng->txt('paya_deleted_object'));
543 
544  $this->showObjects();
545 
546  return true;
547  }
548 
549  public function editPayMethod()
550  {
551  $this->__initPaymentObject((int)$_GET['pobject_id']);
552 
553  switch($this->pobject->getPayMethod())
554  {
555  case $this->pobject->PAY_METHOD_NOT_SPECIFIED:
556  ilUtil::sendFailure($this->lng->txt('paya_select_pay_method_first'));
557  $this->editDetails();
558  return true;
559 
560  default:
561  ilUtil::sendInfo($this->lng->txt('paya_no_settings_necessary'));
562  $this->editDetails();
563  return true;
564  }
565  }
566 
567  public function editPrices($a_show_delete = false)
568  {
572  global $ilToolbar;
573 
574  include_once './Services/Payment/classes/class.ilPaymentPrices.php';
575  include_once './Services/Payment/classes/class.ilPaymentCurrency.php';
576  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
577  include_once './Services/Payment/classes/class.ilPaymentSettings.php';
580 
581  if($a_show_delete == false) unset($_SESSION['price_ids']);
582 
583  $_SESSION['price_ids'] = $_SESSION['price_ids'] ? $_SESSION['price_ids'] : array();
584 
585  if(!$_GET['pobject_id'] && !$_POST['pobject_id'])
586  {
587  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
588 
589  $this->showObjects();
590  return true;
591  }
592 
593  if(isset($_GET['pobject_id']))
594  {
595  $pobject_id = (int)$_GET['pobject_id'];
596  }
597  else
598  {
599  $pobject_id = (int)$_POST['pobject_id'];
600  }
601 
602  $this->ctrl->setParameter($this, 'pobject_id', $pobject_id);
603  $this->__initPaymentObject((int)$_GET['pobject_id']);
604 
605  $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", 'tpl.main_view.html', 'Services/Payment');
606 
607  $price_obj = new ilPaymentPrices($pobject_id);
608 
609  $standard_prices = array();
610  $extension_prices = array();
611  $standard_prices = $price_obj->getPrices();
612  $extension_prices = $price_obj->getExtensionPrices();
613 
614  $prices = array_merge($standard_prices, $extension_prices);
615 
616  // No prices created
617  if(!count($prices))
618  {
619  ilUtil::sendInfo($this->lng->txt('paya_no_price_available'));
620  $ilToolbar->addButton($this->lng->txt('paya_add_price'), $this->ctrl->getLinkTarget($this, 'addPrice'));
621 
622  return true;
623  }
624  else if(!count($standard_prices))
625  {
626  //set pobject status to "not buyable" if there is no standard_price defined
627  $this->pobject->setStatus(0);
628  $this->pobject->update();
629  ilUtil::sendInfo($this->lng->txt('paya_no_price_available'));
630  }
631 
632  // Show confirm delete
633  if($a_show_delete)
634  {
635  $oConfirmationGUI = new ilConfirmationGUI();
636 
637  // set confirm/cancel commands
638  $oConfirmationGUI->setFormAction($this->ctrl->getFormAction($this, "performDeletePrice"));
639  $oConfirmationGUI->setHeaderText($this->lng->txt("paya_sure_delete_selected_prices"));
640  $oConfirmationGUI->setCancel($this->lng->txt("cancel"), "editPrices");
641  $oConfirmationGUI->setConfirm($this->lng->txt("confirm"), "performDeletePrice");
642 
643  $counter = 0;
644 
645  foreach($prices as $price)
646  {
647  $currency = $genSet->get('currency_unit');
648  if(in_array($price['price_id'], $_SESSION['price_ids']))
649  {
650 
651  if($price['unlimited_duration'] == '1')
652  {
653  $tmp_price = $this->lng->txt('unlimited_duration');
654  }
655  else
656  {
657  $tmp_price = $price['duration'] . ' ' . $this->lng->txt('paya_months');
658  }
659  $delete_row = '' . $tmp_price . ' : ' .
660  ilFormat::_getLocalMoneyFormat($price['price']) . ' ' .
661  $currency;
662 
663  $oConfirmationGUI->addItem('', $delete_row, $delete_row);
664  $delete_row = '';
665  }
666  $counter++;
667  }
668 
669  $this->tpl->setVariable('CONFIRMATION', $oConfirmationGUI->getHTML());
670 
671  return true;
672  }
673 
674  $ilToolbar->addButton($this->lng->txt('paya_edit_details'), $this->ctrl->getLinkTarget($this, 'editDetails'));
675  $ilToolbar->addButton($this->lng->txt('paya_edit_prices'), $this->ctrl->getLinkTarget($this, 'editPrices'));
676  $ilToolbar->addButton($this->lng->txt('pay_edit_abstract'), $this->ctrl->getLinkTargetByClass(array('ilshoppagegui'), 'edit'));
677 
678  // Fill table cells
680  $tpl = new ilTemplate('tpl.table.html', true, true);
681 
682  // set table header
683  $tpl->setCurrentBlock('tbl_form_header');
684 
685  $tpl->setVariable('FORMACTION', $this->ctrl->getFormAction($this));
686  $tpl->parseCurrentBlock();
687 
688  $counter = 0;
689  include_once './Services/Calendar/classes/class.ilDatePresentation.php';
690  foreach($prices as $price)
691  {
692  $data[$counter]['price_id'] = ilUtil::formCheckBox(in_array($price['price_id'], $_SESSION['price_ids']) ? 1 : 0,
693  'price_ids[]', $price['price_id']);
694 
695  switch($price['price_type'])
696  {
698  $data[$counter]['duration'] = $price['duration'] . ' ' . $this->lng->txt('paya_months');
699  break;
701 
702  $data[$counter]['duration'] = ilDatePresentation::formatDate(new ilDate($price['duration_from'], IL_CAL_DATE))
703  . ' - ' . ilDatePresentation::formatDate(new ilDate($price['duration_until'], IL_CAL_DATE));
704  break;
706  $data[$counter]['duration'] = $this->lng->txt('unlimited_duration');
707  break;
708  }
709  $data[$counter]['price'] = ilFormat::_getLocalMoneyFormat($price['price']);
710  $data[$counter]['currency_unit'] = $genSet->get('currency_unit');
711  $data[$counter]['extension'] = ilUtil::formCheckBox($price['extension'] ? 1 : 0,
712  'extension_ids[]', (int)$price['price_id'], true);
713 
714  $this->ctrl->setParameter($this, "price_id", $price['price_id']);
715  $data[$counter]['edit'] =
716  "<div class=\"il_ContainerItemCommands\"><a class=\"il_ContainerItemCommand\" href=\"" . $this->ctrl->getLinkTarget($this, "editPrice") . "\">" . $this->lng->txt("edit") . "</a></div>";
717 
718  ++$counter;
719  }
720  $this->__editPricesTable($data);
721 
722  return true;
723  }
724 
725  private function __editPricesTable($a_result_set)
726  {
727  $tbl = new ilShopTableGUI($this);
728 
730  $tmp_obj = ilObjectFactory::getInstanceByRefId($this->pobject->getRefId(), false);
731  if($tmp_obj)
732  {
733  $tbl->setTitle($tmp_obj->getTitle());
734  }
735  else
736  {
737  $tbl->setTitle($this->lng->txt('object_not_found'));
738  }
739 
740  $tbl->setId('tbl_bookings');
741  $tbl->setRowTemplate("tpl.shop_prices_row.html", "Services/Payment");
742 
743  $tbl->addColumn(' ', 'price_id', '5%');
744  $tbl->addColumn($this->lng->txt('duration'), 'duration', '40%');
745  $tbl->addColumn($this->lng->txt('price_a'), 'price', '1%');
746  $tbl->addColumn($this->lng->txt('currency'), 'currency_unit', '10%');
747  $tbl->addColumn($this->lng->txt('extension_price'), 'extension', '10%');
748  $tbl->addColumn('', 'edit', '30%');
749 
750  $tbl->setSelectAllCheckbox('price_id');
751  $tbl->addCommandButton('addPrice', $this->lng->txt('paya_add_price'));
752 
753  $tbl->addMultiCommand("deletePrice", $this->lng->txt("paya_delete_price"));
754  $tbl->fillFooter();
755 
756  $tbl->setData($a_result_set);
757 
758  $this->tpl->setVariable('TABLE', $tbl->getHTML());
759 
760  return true;
761  }
762 
763  public function addPrice()
764  {
768  global $ilToolbar;
769 
770  if(!$_GET['pobject_id'])
771  {
772  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
773 
774  $this->showObjects();
775  return true;
776  }
777 
778  include_once './Services/Payment/classes/class.ilPaymentSettings.php';
781 
782  $this->ctrl->setParameter($this, 'pobject_id', (int)$_GET['pobject_id']);
783 
784  $this->__initPaymentObject((int)$_GET['pobject_id']);
785 
786  $ilToolbar->addButton($this->lng->txt('paya_edit_details'), $this->ctrl->getLinkTarget($this, 'editDetails'));
787  $ilToolbar->addButton($this->lng->txt('paya_edit_prices'), $this->ctrl->getLinkTarget($this, 'editPrices'));
788 
789  $this->tpl->addBlockfile('ADM_CONTENT', 'adm_content', 'tpl.main_view.html', 'Services/Payment');
790 
791  $form = new ilPropertyFormGUI();
792  $form->setFormAction($this->ctrl->getFormAction($this));
793  $form->setTitle($this->lng->txt('paya_add_price_title'));
794 
795  // object_title
796  $oTitle = new ilNonEditableValueGUI($this->lng->txt('title'));
798  $tmp_obj = ilObjectFactory::getInstanceByRefId($this->pobject->getRefId(), false);
799  if(is_object($tmp_obj))
800  {
801  $oTitle->setValue($tmp_obj->getTitle());
802  }
803  else
804  {
805  $oTitle->setValue($this->lng->txt('object_not_found'));
806  }
807  $form->addItem($oTitle);
808 
809  //price_type
810 
811  $radio_group = new ilRadioGroupInputGUI('', 'price_type');
812  $radio_group->setTitle($this->lng->txt('duration'));
813  $radio_group->setRequired(true);
814  $radio_group->setValue($_POST['price_type']);
815  $radio_group->setPostVar('price_type');
816 
817  $radio_option_1 = new ilRadioOption($this->lng->txt('duration_month'), 'duration_month');
818 
819  // duration month
820  $oDuration = new ilNumberInputGUI();
821  $oDuration->setTitle($this->lng->txt('paya_months'));
822  $oDuration->setSize('30%');
823  $oDuration->setValue($_POST['duration_month']);
824 
825  $oDuration->setPostVar('duration_month');
826  $radio_option_1->addSubItem($oDuration);
827 
828  $radio_group->addOption($radio_option_1);
829 
830  $radio_option_3 = new ilRadioOption($this->lng->txt('duration_date'), 'duration_date');
831 
832  // duration_date from
833  $o_date_from = new ilDateTimeInputGUI();
834  $o_date_from->setTitle($this->lng->txt('from'));
835  $o_date_from->setPostVar('duration_date_from');
836  $radio_option_3->addSubItem($o_date_from);
837 
838  // duration_date until
839  $o_date_until = new ilDateTimeInputGUI();
840  $o_date_until->setTitle($this->lng->txt('until'));
841  $o_date_until->setPostVar('duration_date_until');
842  $radio_option_3->addSubItem($o_date_until);
843 
844  $radio_group->addOption($radio_option_3);
845 
846  $radio_option_2 = new ilRadioOption($this->lng->txt('unlimited_duration'), 'unlimited_duration');
847  $radio_group->addOption($radio_option_2);
848 
849  $form->addItem($radio_group);
850  // description
851  $oDescription = new ilTextAreaInputGUI($this->lng->txt('description'), 'description');
852  $oDescription->setRows(4);
853  $oDescription->setCols(35);
854  $oDescription->setValue($_POST['description']);
855  $form->addItem($oDescription);
856 
857  // price
858  $oPrice = new ilNumberInputGUI();
859  $oPrice->setTitle($this->lng->txt('price_a'));
860  $oPrice->setValue($_POST['price']);
861  $oPrice->setPostVar('price');
862  $oPrice->setRequired(true);
863  $oPrice->allowDecimals(true);
864  $form->addItem($oPrice);
865 
866  // currency
867  $this->tpl->setVariable('TXT_PRICE_A', $genSet->get('currency_unit'));
868 
869  //extension
870  $oExtension = new ilCheckboxInputGUI($this->lng->txt('extension_price'), 'extension');
871  isset($_POST['extension']) ? $ext_value = 1 : $ext_value = 0;
872  $oExtension->setChecked($ext_value);
873 
874  $form->addItem($oExtension);
875 
876  $form->addCommandButton('performAddPrice', $this->lng->txt('paya_add_price'));
877  $form->addCommandButton('editPrices', $this->lng->txt('cancel'));
878  $this->tpl->setVariable('FORM', $form->getHTML());
879 
880  return true;
881  }
882 
883  public function performAddPrice()
884  {
885  if(!(int)$_GET['pobject_id'])
886  {
887  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
888 
889  $this->showObjects();
890  return true;
891  }
892 
893  include_once './Services/Payment/classes/class.ilPaymentPrices.php';
894  include_once './Services/Payment/classes/class.ilPaymentCurrency.php';
895 
897 
898  $po = new ilPaymentPrices((int)$_GET['pobject_id']);
899 
900  switch($_POST['price_type'])
901  {
902  case 'unlimited_duration':
903  $po->setPriceType(ilPaymentPrices::TYPE_UNLIMITED_DURATION);
904  $po->setDuration(0);
905  $po->setDurationFrom(NULL);
906  $po->setDurationUntil(NULL);
907  $po->setUnlimitedDuration(1);
908 
909  break;
910 
911  case 'duration_date':
912 
913  $po->setPriceType(ilPaymentPrices::TYPE_DURATION_DATE);
914  $po->setDuration(NULL);
915  $po->setDurationFrom(ilUtil::stripSlashes(
916  $_POST['duration_date_from']['date']['y'] . '-' .
917  $_POST['duration_date_from']['date']['m'] . '-' .
918  $_POST['duration_date_from']['date']['d']));
919  $po->setDurationUntil(ilUtil::stripSlashes(
920  $_POST['duration_date_until']['date']['y'] . '-' .
921  $_POST['duration_date_until']['date']['m'] . '-' .
922  $_POST['duration_date_until']['date']['d']));
923  break;
924 
925  default:
926  case 'duration_month':
927  $po->setPriceType(ilPaymentPrices::TYPE_DURATION_MONTH);
928  $po->setDuration($_POST['duration_month']);
929  $po->setDurationFrom(NULL);
930  $po->setDurationUntil(NULL);
931  break;
932  }
933 
934  $po->setDescription($_POST['description'] ? ilUtil::stripSlashes($_POST['description']) : NULL);
935  $po->setPrice(ilUtil::stripSlashes($_POST['price']));
936  $po->setCurrency($currency[1]['currency_id']);
937 
938  if($_POST['extension_price'])
939  {
940  $po->setExtension(1);
941  }
942  else
943  {
944  $po->setExtension(0);
945  }
946 
947  try
948  {
949  $po->validate();
950  $po->add();
951  ilUtil::sendInfo($this->lng->txt('paya_added_new_price'));
952 
953  return $this->editPrices();
954 
955  }
956  catch(ilShopException $e)
957  {
958  ilUtil::sendInfo($e->getMessage());
959  return $this->addPrice();
960  }
961 
962  }
963 
964  public function performDeletePrice()
965  {
966  if(!$_GET['pobject_id'])
967  {
968  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
969 
970  $this->showObjects();
971  return true;
972  }
973 
974  if(!count($_SESSION['price_ids']))
975  {
976  ilUtil::sendInfo($this->lng->txt('paya_no_prices_selected'));
977 
978  $this->editPrices();
979  return true;
980  }
981  include_once './Services/Payment/classes/class.ilPaymentPrices.php';
982 
983  $prices = new ilPaymentPrices((int)$_GET['pobject_id']);
984 
985  foreach($_SESSION['price_ids'] as $price_id)
986  {
987  $prices->delete($price_id);
988  }
989 
990  // check if it was last price otherwise set status to 'not_buyable'
991  if(!count($prices->getPrices()))
992  {
993  $this->__initPaymentObject((int)$_GET['pobject_id']);
994 
995  $this->pobject->setStatus($this->pobject->STATUS_NOT_BUYABLE);
996  $this->pobject->update();
997 
998  ilUtil::sendInfo($this->lng->txt('paya_deleted_last_price'));
999  }
1000  unset($prices);
1001  unset($_SESSION['price_ids']);
1002 
1003  return $this->editPrices();
1004  }
1005 
1006 
1007  public function deletePrice()
1008  {
1009  if(!$_GET['pobject_id'])
1010  {
1011  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
1012 
1013  $this->showObjects();
1014  return true;
1015  }
1016 
1017  if(!count($_POST['price_ids']))
1018  {
1019  ilUtil::sendInfo($this->lng->txt('paya_no_prices_selected'));
1020 
1021  $this->editPrices();
1022  return true;
1023  }
1024  $_SESSION['price_ids'] = $_POST['price_ids'];
1025 
1026  $this->editPrices(true);
1027  return true;
1028  }
1029 
1030  public function ORg_updatePrice()
1031  {
1032  include_once './Services/Payment/classes/class.ilPaymentPrices.php';
1033 
1034  if(!$_GET['pobject_id'] && !$_POST['pobject_id'])
1035  {
1036  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
1037 
1038  $this->showObjects();
1039  return true;
1040  }
1041  if(isset($_GET['pobject_id']))
1042  {
1043  $pobject_id = (int)$_GET['pobject_id'];
1044  }
1045  else
1046  {
1047  $pobject_id = (int)$_POST['pobject_id'];
1048  }
1049  $po = new ilPaymentPrices($pobject_id);
1050 
1051  $this->ctrl->setParameter($this, 'pobject_id', $pobject_id);
1052 
1053  $price_id = (int)$_POST['price_id'];
1054 
1055  // validate
1056  $old_price = $po->getPrice($price_id);
1057 
1058 
1059  $po->setDuration((int)$_POST['duration']);
1060  $po->setUnlimitedDuration($_POST['unlimited_duration']);
1061  $po->setPrice($_POST['price']);
1062  $po->setPriceType($_POST['price_type']);
1063  $po->setCurrency($old_price['currency']);
1064  $po->setExtension((int)$_POST['extension']);
1065 
1066  if(!$po->validate())
1067  {
1068  $error = true;
1069  }
1070  if($error)
1071  {
1072  ilUtil::sendInfo($this->lng->txt('paya_insert_only_numbers'));
1073 
1074  $this->editPrices();
1075  return false;
1076  }
1077 
1078  foreach($_POST['prices'] as $price_id => $price)
1079  {
1080  $old_price = $po->getPrice($price_id);
1081  if(isset($_POST['duration_ids']))
1082  {
1083 // $search = in_array((string)$price_id, $_POST['duration_ids']);
1084  if($_POST['duration_ids'] == NULL)
1085  {
1086  $po->setUnlimitedDuration(0);
1087  $po->setDuration($price['duration']);
1088  }
1089 
1090  else if($search = in_array((string)$price_id, $_POST['duration_ids']))
1091  {
1092  $po->setUnlimitedDuration(1);
1093  $po->setDuration(0);
1094  }
1095  else
1096  {
1097  $po->setUnlimitedDuration(0);
1098  }
1099  }
1100 
1101  if(isset($_POST['extension_ids']))
1102  {
1103 // $search = in_array((string)$price_id, $_POST['extension_ids']);
1104  if($search = in_array((string)$price_id, $_POST['extension_ids']))
1105  {
1106  $po->setExtension(1);
1107  }
1108  else
1109  {
1110  $po->setExtension(0);
1111  }
1112  }
1113 
1114  $po->setDuration($price['duration']);
1115 
1116  $po->setPrice($price['price']);
1117  $po->setCurrency($old_price['currency']);
1118  $po->update($price_id);
1119  }
1120  ilUtil::sendInfo($this->lng->txt('paya_updated_prices'));
1121  $this->editPrices();
1122 
1123  return true;
1124  }
1125 
1126  public function updateDetails()
1127  {
1128  if(!$_GET['pobject_id'])
1129  {
1130  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
1131 
1132  $this->showObjects();
1133  return true;
1134  }
1135  $this->__initPaymentObject((int)$_GET['pobject_id']);
1136  $this->ctrl->setParameter($this, 'pobject_id', (int)$_GET['pobject_id']);
1137 
1138  // read old settings
1139  $old_status = $this->pobject->getStatus();
1140 
1141  // check status changed from not_buyable
1142  if($old_status == $this->pobject->STATUS_NOT_BUYABLE and
1143  (int)$_POST['status'] != $old_status
1144  )
1145  {
1146  // check pay_method edited
1147  switch((int)$_POST['pay_method'])
1148  {
1149  case $this->pobject->PAY_METHOD_NOT_SPECIFIED:
1150  ilUtil::sendInfo($this->lng->txt('paya_select_pay_method_first'));
1151  $this->editDetails();
1152 
1153  return false;
1154 
1155  default:
1156  ;
1157  }
1158  // check minimum one price
1159  include_once './Services/Payment/classes/class.ilPaymentPrices.php';
1160 
1161  $prices_obj = new ilPaymentPrices((int)$_GET['pobject_id']);
1162  if(!count($prices_obj->getPrices()))
1163  {
1164  ilUtil::sendInfo($this->lng->txt('paya_edit_prices_first'));
1165  $this->editDetails();
1166 
1167  return false;
1168  }
1169  }
1170 
1171  if((int)$_POST['status'] == 0)
1172  {
1173  // Status: not buyable -> delete depending shoppingcart entries
1174  include_once './Services/Payment/classes/class.ilPaymentShoppingCart.php';
1175  ilPaymentShoppingCart::_deleteShoppingCartEntries($this->pobject->getPobjectId());
1176  }
1177 
1178  $this->pobject->setStatus((int)$_POST['status']);
1179  $this->pobject->setVendorId((int)$_POST['vendor']);
1180  $this->pobject->setPayMethod((int)$_POST['pay_method']);
1181  $this->pobject->setTopicId((int)$_POST['topic_id']);
1182  $this->pobject->setVatId((int)$_POST['vat_id']);
1183  $this->pobject->setSubtype((string)$_POST['exc_subtype']);
1184  $this->pobject->setSpecial((int)$_POST['is_special']);
1185 
1186  if((int)$_POST['thumbnail_delete'])
1187  {
1188  $oFile = new ilFileDataShop($this->pobject->getPobjectId());
1189  $oFile->deassignFileFromPaymentObject();
1190  }
1191  else if($_FILES['thumbnail']['tmp_name'] != '')
1192  {
1193  $this->lng->loadLanguageModule('form');
1194  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
1195  $oThumbnail = new ilImageFileInputGUI($this->lng->txt('pay_thumbnail'), 'thumbnail');
1196  if($oThumbnail->checkInput())
1197  {
1198  $oFile = new ilFileDataShop($this->pobject->getPobjectId());
1199  if(($oFile->storeUploadedFile($_FILES['thumbnail'])) !== false)
1200  {
1201  $oFile->assignFileToPaymentObject();
1202  }
1203  }
1204  else
1205  {
1206  ilUtil::sendInfo($oThumbnail->getAlert());
1207  return $this->editDetails();
1208  }
1209  }
1210 
1211  $this->pobject->update();
1212 
1213  ilUtil::sendInfo($this->lng->txt('paya_details_updated'));
1214  $this->showObjects();
1215 
1216  return true;
1217  }
1218 
1219  public function showObjectSelector()
1220  {
1224  global $tree, $ilToolbar;
1225 
1226  include_once './Services/Payment/classes/class.ilPaymentObjectSelector.php';
1227 
1228  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.paya_object_selector.html', 'Services/Payment');
1229  $ilToolbar->addButton($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'showObjects'));
1230 
1231 
1232  ilUtil::sendInfo($this->lng->txt('paya_select_object_to_sell'));
1233 
1234  $exp = new ilPaymentObjectSelector($this->ctrl->getLinkTarget($this, 'showObjectSelector'), (string)strtolower(get_class($this)));
1235  $exp->setExpand($_GET['paya_link_expand'] ? $_GET['paya_link_expand'] : $tree->readRootId());
1236  $exp->setExpandTarget($this->ctrl->getLinkTarget($this, 'showObjectSelector'));
1237 
1238  $exp->setOutput(0);
1239 
1240  $this->tpl->setVariable("EXPLORER", $exp->getOutput());
1241 
1242  return true;
1243  }
1244 
1245  public function showSelectedObject()
1246  {
1247  global $ilToolbar;
1248 
1249  if(!(int)$_GET['sell_id'])
1250  {
1251  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
1252  return $this->showObjectSelector();
1253  }
1254 
1255  $ilToolbar->addButton($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'showObjectSelector'));
1256 
1257  // save ref_id of selected object
1258  $this->ctrl->setParameter($this, 'sell_id', (int)$_GET['sell_id']);
1259 
1260  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
1261  $oForm = new ilPropertyFormGUI();
1262  $oForm->setFormAction($this->ctrl->getFormAction($this, 'updateDetails'));
1263  $oForm->setTitle($this->lng->txt('details'));
1264  $oForm->setTitleIcon(ilUtil::getImagePath('icon_pays.png', false));
1265 
1266  $tmp_obj = ilObjectFactory::getInstanceByRefId($_GET['sell_id'], false);
1267  if(is_object($tmp_obj))
1268  {
1269  $tmp_object['title'] = $tmp_obj->getTitle();
1270  $tmp_object['description'] = $tmp_obj->getDescription();
1271  $tmp_object['owner'] = $tmp_obj->getOwnerName();
1272  $tmp_object['path'] = $this->__getHTMLPath((int)$_GET['sell_id']);
1273  }
1274  else
1275  {
1276  $tmp_object['title'] = $this->lng->txt('object_not_found');
1277  $tmp_object['description'] = '';
1278  $tmp_object['owner'] = '';
1279  $tmp_object['path'] = '';
1280  }
1281 
1282  // title
1283  $oTitleGUI = new ilNonEditableValueGUI($this->lng->txt('title'));
1284  $oTitleGUI->setValue($tmp_object['title']);
1285  $oForm->addItem($oTitleGUI);
1286 
1287  // description
1288  $oDescriptionGUI = new ilNonEditableValueGUI($this->lng->txt('description'));
1289  $oDescriptionGUI->setValue($tmp_object['description']);
1290  $oForm->addItem($oDescriptionGUI);
1291 
1292  // owner
1293  $oOwnerGUI = new ilNonEditableValueGUI($this->lng->txt('owner'));
1294  $oOwnerGUI->setValue($tmp_object['owner']);
1295  $oForm->addItem($oOwnerGUI);
1296 
1297  // repository path
1298  $oPathGUI = new ilNonEditableValueGUI($this->lng->txt('path'));
1299  $oPathGUI->setValue($tmp_object['path']);
1300  $oForm->addItem($oPathGUI);
1301 
1302  // vendors
1303  $oVendorsGUI = new ilSelectInputGUI($this->lng->txt('paya_vendor'), 'vendor');
1304  $oVendorsGUI->setOptions($this->__getVendors());
1305  $oForm->addItem($oVendorsGUI);
1306 
1307  // buttons
1308  $oForm->addCommandButton('addObject', $this->lng->txt('next'));
1309  $oForm->addCommandButton('showObjects', $this->lng->txt('cancel'));
1310 
1311  $this->tpl->setVariable('ADM_CONTENT', $oForm->getHTML());
1312  return true;
1313  }
1314 
1315  public function addObject()
1316  {
1317  if(!$_GET['sell_id'])
1318  {
1319  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
1320 
1321  return $this->showObjectSelector();
1322  }
1323  if(!(int)$_POST['vendor'])
1324  {
1325  ilUtil::sendInfo($this->lng->txt('paya_no_vendor_selected'));
1326 
1327  return $this->showSelectedObject();
1328  }
1329 
1330  include_once 'Services/Payment/classes/class.ilPaymentObject.php';
1331  $p_obj = new ilPaymentObject($this->user_obj);
1332 
1333  if($check_subtypes = ilPaymentObject::_checkExcSubtype($_GET['sell_id']))
1334  {
1335  if(!in_array('download', $check_subtypes))
1336  $p_obj->setSubtype('download');
1337  else
1338  if(!in_array('upload', $check_subtypes))
1339  $p_obj->setSubtype('upload');
1340 
1341 
1342  }
1343  else
1344  if(ilPaymentObject::_isPurchasable($_GET['sell_id']))
1345  {
1346  // means that current object already exits in payment_objects _table ...
1347  ilUtil::sendInfo($this->lng->txt('paya_object_not_purchasable'));
1348 
1349  return $this->showObjectSelector();
1350  }
1351 
1352  $p_obj->setRefId((int)$_GET['sell_id']);
1353  $p_obj->setStatus($p_obj->STATUS_NOT_BUYABLE);
1354  $p_obj->setPayMethod($p_obj->PAY_METHOD_NOT_SPECIFIED);
1355  $p_obj->setVendorId((int)$_POST['vendor']);
1356  $p_obj->setTopicId((int)$_POST['topic_id']);
1357  $p_obj->setVatId((int)$_POST['vat_id']);
1358 
1359  $new_id = $p_obj->add();
1360  if($new_id)
1361  {
1362  ilUtil::sendInfo($this->lng->txt('paya_added_new_object'));
1363  $_GET['pobject_id'] = $new_id;
1364  $this->editPrices();
1365  return true;
1366  }
1367  else
1368  {
1369  ilUtil::sendInfo($this->lng->txt('paya_err_adding_object'));
1370  return $this->showObjects();
1371  }
1372  }
1373 
1374  private function __getVendors()
1375  {
1376  include_once 'Services/Payment/classes/class.ilPaymentVendors.php';
1377 
1378  $options = array();
1379  $vendors = array();
1380  if(ilPaymentVendors::_isVendor($this->user_obj->getId()))
1381  {
1382  $vendors[] = $this->user_obj->getId();
1383  }
1384  if($vend = ilPaymentTrustees::_getVendorsForObjects($this->user_obj->getId()))
1385  {
1386  $vendors = array_merge($vendors, $vend);
1387  }
1388 
1389  foreach($vendors as $vendor)
1390  {
1392  $tmp_obj = ilObjectFactory::getInstanceByObjId($vendor, false);
1393  $options[$vendor] = $tmp_obj->getFullname() . ' [' . $tmp_obj->getLogin() . ']';
1394  }
1395 
1396  return $options;
1397  }
1398 
1399 
1400  private function __getStatus()
1401  {
1402  $option = array();
1403  $option[$this->pobject->STATUS_NOT_BUYABLE] = $this->lng->txt('paya_not_buyable');
1404  $option[$this->pobject->STATUS_BUYABLE] = $this->lng->txt('paya_buyable');
1405  $option[$this->pobject->STATUS_EXPIRES] = $this->lng->txt('paya_expires');
1406 
1407  return $option;
1408  }
1409 
1410  private function __showObjectsTable($a_result_set)
1411  {
1412  $tbl = new ilShopTableGUI($this);
1413  $tbl->setTitle($this->lng->txt('objects'));
1414 
1415  $tbl->setId('tbl_objects');
1416  $tbl->setRowTemplate("tpl.shop_objects_row.html", "Services/Payment");
1417 
1418  $tbl->addColumn($this->lng->txt('title'), 'title', '10%');
1419  $tbl->addColumn($this->lng->txt('status'), 'status', '10%');
1420  $tbl->addColumn($this->lng->txt('paya_pay_method'), 'pay_method', '10%');
1421  $tbl->addColumn($this->lng->txt('vat_rate'), 'vat_rate', '15%');
1422  $tbl->addColumn($this->lng->txt('paya_vendor'), 'vendor', '10%');
1423  $tbl->addColumn($this->lng->txt('paya_count_purchaser'), 'purchasers', '10%');
1424  $tbl->addColumn('', 'options', '10%');
1425 
1426  $tbl->setData($a_result_set);
1427 
1428  $this->tpl->setVariable('TABLE', $tbl->getHTML());
1429 
1430  return true;
1431  }
1432 
1433 
1434  private function __getHTMLPath($a_ref_id)
1435  {
1438  global $tree;
1439 
1440  $path = $tree->getPathFull($a_ref_id);
1441  unset($path[0]);
1442 
1443  $html = '';
1444  foreach($path as $data)
1445  {
1446  $html .= $data['title'] . ' > ';
1447  }
1448  return substr($html, 0, -2);
1449  }
1450 
1451  private function __initPaymentObject($a_pobject_id = 0)
1452  {
1453  include_once './Services/Payment/classes/class.ilPaymentObject.php';
1454 
1455  $this->pobject = new ilPaymentObject($this->user_obj, $a_pobject_id);
1456 
1457  return true;
1458  }
1459 
1460  public function editPrice()
1461  {
1462  $this->tpl->addBlockfile('ADM_CONTENT', 'adm_content', 'tpl.main_view.html', 'Services/Payment');
1463 
1464  $price_id = $_GET['price_id'] ? $_GET['price_id'] : $_POST['price_id'];
1465  $price = ilPaymentPrices::_getPrice($price_id);
1466 
1467 
1468  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
1469  $form = new ilPropertyFormGUI();
1470  $form->setFormAction($this->ctrl->getFormAction($this));
1471 
1472  //price_type
1473  $radio_group = new ilRadioGroupInputGUI('', 'price_type');
1474  $radio_group->setTitle($this->lng->txt('duration'));
1475  $radio_group->setRequired(true);
1476  $radio_group->setValue($price['price_type']);
1477  $radio_group->setPostVar('price_type');
1478 
1479  $radio_option_1 = new ilRadioOption($this->lng->txt('duration_month'), ilPaymentPrices::TYPE_DURATION_MONTH);
1480 
1481  // duration month
1482  $oDuration = new ilNumberInputGUI();
1483  $oDuration->setTitle($this->lng->txt('paya_months'));
1484  $oDuration->setSize('20%');
1485  $oDuration->setValue($price['duration']);
1486  $oDuration->setPostVar('duration_month');
1487  $radio_option_1->addSubItem($oDuration);
1488 
1489  $radio_group->addOption($radio_option_1);
1490 
1491  $radio_option_3 = new ilRadioOption($this->lng->txt('duration_date'), ilPaymentPrices::TYPE_DURATION_DATE);
1492 
1493  $now_date = date('Y-m-d');
1494 
1495  // duration_date from
1496  $o_date_from = new ilDateTimeInputGUI();
1497  $o_date_from->setTitle($this->lng->txt('from'));
1498 
1499  $o_date_from->setDate(new ilDate($price['duration_from'] == NULL ? $now_date : $price['duration_from'], IL_CAL_DATE));
1500  $o_date_from->setPostVar('duration_date_from');
1501  $radio_option_3->addSubItem($o_date_from);
1502 
1503  // duration_date until
1504  $o_date_until = new ilDateTimeInputGUI();
1505  $o_date_until->setTitle($this->lng->txt('until'));
1506  $o_date_until->setDate(new ilDate($price['duration_until'] == NULL ? $now_date : $price['duration_until'], IL_CAL_DATE));
1507  $o_date_until->setPostVar('duration_date_until');
1508  $radio_option_3->addSubItem($o_date_until);
1509 
1510  $radio_group->addOption($radio_option_3);
1511 
1512  $radio_option_2 = new ilRadioOption($this->lng->txt('unlimited_duration'), ilPaymentPrices::TYPE_UNLIMITED_DURATION);
1513  $radio_group->addOption($radio_option_2);
1514 
1515  $form->addItem($radio_group);
1516 
1517  // description
1518  $oDescription = new ilTextAreaInputGUI($this->lng->txt('description'), 'description');
1519  $oDescription->setRows(4);
1520  $oDescription->setCols(35);
1521  $oDescription->setValue($price['description']);
1522  $form->addItem($oDescription);
1523 
1524  // price
1525  $oPrice = new ilNumberInputGUI();
1526  $oPrice->setTitle($this->lng->txt('price_a'));
1527  $oPrice->allowDecimals(true);
1528  $oPrice->setRequired(true);
1529  $oPrice->setSize('20%');
1530  $oPrice->setValue($price['price']);
1531  include_once './Services/Payment/classes/class.ilPaymentSettings.php';
1533  $genSet = ilPaymentSettings::_getInstance();
1534  $oPrice->setInfo($genSet->get('currency_unit'));
1535  $oPrice->setPostVar('price');
1536  $oPrice->allowDecimals(true);
1537  $form->addItem($oPrice);
1538 
1539  //extension
1540  $oExtension = new ilCheckboxInputGUI($this->lng->txt('extension_price'), 'extension');
1541  $oExtension->setChecked((int)$price['extension']);
1542  $form->addItem($oExtension);
1543 
1544  $o_hidden_1 = new ilHiddenInputGUI('pobject_id');
1545  $o_hidden_1->setValue((int)$_GET['pobject_id']);
1546  $o_hidden_1->setPostVar('pobject_id');
1547 
1548  $o_hidden_2 = new ilHiddenInputGUI('price_id');
1549  $o_hidden_2->setValue((int)$_GET['price_id']);
1550  $o_hidden_2->setPostVar('price_id');
1551 
1552  $form->addItem($o_hidden_1);
1553  $form->addItem($o_hidden_2);
1554 
1555  $form->addCommandButton('updatePrice', $this->lng->txt('save'));
1556  $form->addCommandButton('editPrices', $this->lng->txt('cancel'));
1557 
1558  $this->tpl->setVariable('FORM', $form->getHTML());
1559  }
1560 
1561  public function updatePrice()
1562  {
1563  include_once './Services/Payment/classes/class.ilPaymentPrices.php';
1564 
1565  if(!$_GET['pobject_id'] && !$_POST['pobject_id'])
1566  {
1567  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
1568 
1569  $this->showObjects();
1570  return true;
1571  }
1572  if(isset($_GET['pobject_id']))
1573  {
1574  $pobject_id = (int)$_GET['pobject_id'];
1575  }
1576  else
1577  {
1578  $pobject_id = (int)$_POST['pobject_id'];
1579  }
1580 
1581  if(!(int)$_GET['price_id'] && !$_POST['price_id'])
1582  {
1583  ilUtil::sendInfo($this->lng->txt('payment_no_price_selected'));
1584  return $this->editPrices();
1585  }
1586  if(isset($_GET['price_id']))
1587  {
1588  $price_id = (int)$_GET['price_id'];
1589  }
1590  else
1591  {
1592  $price_id = (int)$_POST['price_id'];
1593  }
1594 
1595  $po = new ilPaymentPrices((int)$pobject_id);
1596  switch($_POST['price_type'])
1597  {
1599  $po->setPriceType(ilPaymentPrices::TYPE_UNLIMITED_DURATION);
1600  $po->setDuration(NULL);
1601  $po->setDurationFrom(NULL);
1602  $po->setDurationUntil(NULL);
1603  $po->setUnlimitedDuration(1);
1604 
1605  break;
1606 
1608 
1609  $po->setPriceType(ilPaymentPrices::TYPE_DURATION_DATE);
1610  $po->setDuration(NULL);
1611  $po->setDurationFrom(ilUtil::stripSlashes(
1612  $_POST['duration_date_from']['date']['y'] . '-' .
1613  $_POST['duration_date_from']['date']['m'] . '-' .
1614  $_POST['duration_date_from']['date']['d']));
1615  $po->setDurationUntil(ilUtil::stripSlashes(
1616  $_POST['duration_date_until']['date']['y'] . '-' .
1617  $_POST['duration_date_until']['date']['m'] . '-' .
1618  $_POST['duration_date_until']['date']['d']));
1619  break;
1620 
1621  default:
1623  $po->setPriceType(ilPaymentPrices::TYPE_DURATION_MONTH);
1624  $po->setDuration($_POST['duration_month']);
1625  $po->setDurationFrom(NULL);
1626  $po->setDurationUntil(NULL);
1627  break;
1628  }
1629 
1630  $po->setDescription($_POST['description'] ? ilUtil::stripSlashes($_POST['description']) : NULL);
1631  $po->setPrice(ilUtil::stripSlashes($_POST['price']));
1632  $po->setCurrency(ilUtil::stripSlashes($_POST['currency']));
1633  if($_POST['extension'])
1634  {
1635  $po->setExtension(1);
1636  }
1637  else
1638  {
1639  $po->setExtension(0);
1640  }
1641  try
1642  {
1643  $po->validate();
1644  $po->update($price_id);
1645  ilUtil::sendInfo($this->lng->txt('paya_updated_price'));
1646  return $this->editPrices();
1647  }
1648  catch(ilShopException $e)
1649  {
1650  ilUtil::sendInfo($e->getMessage());
1651  return $this->editPrices();
1652  }
1653  }
1654 }