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