ILIAS  Release_4_2_x_branch Revision 61807
 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 {
22  public $ctrl;
23  public $lng;
24  public $user_obj;
25  public $pobject = null;
26 
27  public function ilPaymentObjectGUI($user_obj)
28  {
30 
31  $this->user_obj = $user_obj;
32  $this->lng->loadLanguageModule('crs');
33  }
34 
35  protected function prepareOutput()
36  {
37  global $ilTabs;
38 
39  $this->setSection(6);
40 
42 
43  $ilTabs->setTabActive('paya_header');
44  $ilTabs->setSubTabActive('paya_object');
45  }
46 
47  public function executeCommand()
48  {
49  $cmd = $this->ctrl->getCmd();
50  switch($this->ctrl->getNextClass($this))
51  {
52  case 'ilpageobjectgui':
53  $this->prepareOutput();
54  $ret = $this->forwardToPageObject();
55  if($ret != '')
56  {
57  $this->tpl->setContent($ret);
58  }
59  break;
60 
61  default:
62  if(!$cmd = $this->ctrl->getCmd())
63  {
64  $cmd = 'showObjects';
65  }
66  $this->prepareOutput();
67  $this->$cmd();
68  break;
69  }
70  }
71 
72  public function forwardToPageObject()
73  {
74  global $ilTabs;
75 
76  if(!(int)$_GET['pobject_id'])
77  {
78  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
79  return $this->showObjects();
80  }
81  $this->ctrl->setParameter($this, 'pobject_id', (int)$_GET['pobject_id']);
82  $this->__initPaymentObject((int)$_GET['pobject_id']);
83 
84  $this->lng->loadLanguageModule('content');
85 
86  $ilTabs->clearTargets();
87  $ilTabs->clearSubTabs();
88  $ilTabs->setBackTarget($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'editDetails'), '_top');
89 
90  // page objec
91  include_once 'Services/COPage/classes/class.ilPageObject.php';
92  include_once 'Services/COPage/classes/class.ilPageObjectGUI.php';
93  include_once('./Services/Style/classes/class.ilObjStyleSheet.php');
94 
95  $this->tpl->setVariable('LOCATION_CONTENT_STYLESHEET', ilObjStyleSheet::getContentStylePath(0));
96 
97  if(!ilPageObject::_exists('shop', $this->pobject->getPobjectId()))
98  {
99  // doesn't exist -> create new one
100  $new_page_object = new ilPageObject('shop');
101  $new_page_object->setParentId(0);
102  $new_page_object->setId($this->pobject->getPobjectId());
103  $new_page_object->createFromXML();
104  }
105 
106  $this->ctrl->setReturnByClass('ilpageobjectgui', 'edit');
107 
108  $page_gui = new ilPageObjectGUI('shop', $this->pobject->getPobjectId());
109  $this->ctrl->setParameter($page_gui, 'pobject_id', (int)$_GET['pobject_id']);
110  $page_gui->setIntLinkHelpDefault('StructureObject', $this->pobject->getPobjectId());
111  $page_gui->setTemplateTargetVar('ADM_CONTENT');
112  $page_gui->setLinkXML('');
113  $page_gui->setFileDownloadLink($this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'downloadFile'));
114  $page_gui->setFullscreenLink($this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'displayMediaFullscreen'));
115  $page_gui->setSourcecodeDownloadScript($this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'download_paragraph'));
116  $page_gui->setPresentationTitle('');
117  $page_gui->setTemplateOutput(false);
118  $page_gui->setHeader('');
119  $page_gui->setEnabledRepositoryObjects(false);
120  $page_gui->setEnabledFileLists(true);
121  $page_gui->setEnabledMaps(true);
122  $page_gui->setEnabledPCTabs(true);
123 
124  return $this->ctrl->forwardCommand($page_gui);
125  }
126 
127  public function resetObjectFilter()
128  {
129  unset($_SESSION['pay_objects']);
130  unset($_POST['title_type']);
131  unset($_POST['title_value']);
132  unset($_POST['vendor']);
133  unset($_POST['pay_method']);
134  unset($_POST['updateView']);
135  unset($_POST['show_filter']);
136 
137  ilUtil::sendInfo($this->lng->txt('paya_filter_reseted'));
138 
139  return $this->showObjects();
140  }
141 
142  public function showObjects()
143  {
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  $img_change = "<img src=\"".ilUtil::getImagePath("edit.gif")."\" alt=\"".
233  $this->lng->txt("edit")."\" title=\"".$this->lng->txt("edit").
234  "\" border=\"0\" vspace=\"0\"/>";
235 
236  $counter = 0;
237  foreach($objects as $data)
238  {
239 
240  $tmp_obj = ilObjectFactory::getInstanceByRefId($data['ref_id'], false);
241  if($tmp_obj)
242  {
243  $f_result[$counter]['title'] = $tmp_obj->getTitle();
244  }
245  else
246  {
247  $f_result[$counter]['title'] = $this->lng->txt('object_not_found');
248  }
249 
250 
251  switch($data['status'])
252  {
253  case $this->pobject->STATUS_BUYABLE:
254  $f_result[$counter]['status'] = $this->lng->txt('paya_buyable');
255  break;
256 
257  case $this->pobject->STATUS_NOT_BUYABLE:
258  $f_result[$counter]['status'] = $this->lng->txt('paya_not_buyable');
259  break;
260 
261  case $this->pobject->STATUS_EXPIRES:
262  $f_result[$counter]['status'] = $this->lng->txt('paya_expires');
263  break;
264  }
265  $str_paymethod = ilPayMethods::getStringByPaymethod($data['pay_method']);
266  $f_result[$counter]['pay_method'] = $str_paymethod;
267 
268  if($data['vat_id'] <= 0)
269  {
270  $vat_rate = $this->lng->txt('payment_vat_has_to_be_defined_by_administration_short');
271  }
272  else
273  {
274  try
275  {
276  $oVAT = new ilShopVats((int)$data['vat_id']);
277  $vat_rate = ilShopUtils::_formatVAT((float)$oVAT->getRate());
278  }
279  catch(ilShopException $e)
280  {
281  $vat_rate = $this->lng->txt('payment_vat_has_to_be_defined_by_administration_short');
282  }
283  }
284  $f_result[$counter]['vat_rate'] = $vat_rate;
285 
286  $tmp_user = ilObjectFactory::getInstanceByObjId($data['vendor_id']);
287  $f_result[$counter]['vendor'] = $tmp_user->getFullname().' ['.$tmp_user->getLogin().']';
288 
289  // Get number of purchasers
290  $f_result[$counter]['purchasers'] = ilPaymentBookings::_getCountBookingsByObject($data['pobject_id']);
291 
292  // edit link
293  $this->ctrl->setParameter($this,'pobject_id',$data['pobject_id']);
294  $link_change = "<div class=\"il_ContainerItemCommands\"><a class=\"il_ContainerItemCommand\" href=\"".$this->ctrl->getLinkTarget($this,"editDetails")."\">".$this->lng->txt("edit")."</a></div>";
295 
296  $f_result[$counter]['options'] = $link_change;
297  unset($tmp_user);
298  unset($tmp_obj);
299 
300  ++$counter;
301  }
302 
303  return $this->__showObjectsTable($f_result);
304  }
305 
306  public function editDetails($a_show_confirm = false)
307  {
308  global $ilToolbar;
309 
310  include_once './Services/Payment/classes/class.ilPaymentSettings.php';
312 
313  if(!(int)$_GET['pobject_id'])
314  {
315  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
316  return $this->showObjects();
317  }
318 
319  $this->__initPaymentObject((int)$_GET['pobject_id']);
320 
321  $this->ctrl->setParameter($this,'pobject_id', (int)$_GET['pobject_id']);
322 
323  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.main_view.html', 'Services/Payment');
324  $tmp_obj = ilObjectFactory::getInstanceByRefId($this->pobject->getRefId(), false);
325  if(is_object($tmp_obj))
326  {
327  $trash = '';
328  if(ilObject::_isInTrash($this->pobject->getRefId()))
329  {
330  $trash = ' ('.$this->lng->txt('object_deleted').')';
331  }
332  $tmp_object['title'] = $tmp_obj->getTitle().''.$trash;
333  $tmp_object['type'] = $tmp_obj->getType();
334  }
335  else
336  {
337  $tmp_object['title'] = $this->lng->txt('object_not_found');
338  $tmp_object['type'] = false;
339  }
340 
341  if($a_show_confirm)
342  {
343  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
344  $oConfirmationGUI = new ilConfirmationGUI();
345 
346  // set confirm/cancel commands
347  $oConfirmationGUI->setFormAction($this->ctrl->getFormAction($this,"performDelete"));
348  $oConfirmationGUI->setHeaderText($this->lng->txt("paya_sure_delete_object"));
349  $oConfirmationGUI->setCancel($this->lng->txt("cancel"), "editDetails");
350  $oConfirmationGUI->setConfirm($this->lng->txt("confirm"), "performDelete");
351 
352  $oConfirmationGUI->addItem('', $tmp_object['title'], $tmp_object['title']);
353  $this->tpl->setVariable('CONFIRMATION',$oConfirmationGUI->getHTML());
354 
355  return true;
356  }
357 
358  $ilToolbar->addButton($this->lng->txt('paya_edit_details'), $this->ctrl->getLinkTarget($this, 'editDetails'));
359  $ilToolbar->addButton($this->lng->txt('paya_edit_prices'), $this->ctrl->getLinkTarget($this, 'editPrices'));
360  $ilToolbar->addButton($this->lng->txt('pay_edit_abstract'), $this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'edit'));
361 
362  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
363  $oForm = new ilPropertyFormGUI();
364  $oForm->setFormAction($this->ctrl->getFormAction($this, 'updateDetails'));
365  $oForm->setTitle($tmp_object['title']);
366  if($tmp_object['type'])
367  $oForm->setTitleIcon(ilUtil::getImagePath('icon_'.$tmp_object['type'] .'_b.gif'));
368 
369  // repository path
370  $oPathGUI = new ilNonEditableValueGUI($this->lng->txt('path'));
371  $oPathGUI->setValue($this->__getHTMLPath($this->pobject->getRefId()));
372  $oForm->addItem($oPathGUI);
373 
374  switch ($tmp_object['type'])
375  {
376  case 'exc':
377  $exc_subtype_option = array();
378  $check_subtypes = ilPaymentObject::_checkExcSubtype($this->pobject->getRefId());
379 
380  if(!in_array('download', $check_subtypes) || $this->pobject->getSubtype() == 'download')
381  $exc_subtype_option['download'] = $this->lng->txt('download');
382  if(!in_array('upload', $check_subtypes) || $this->pobject->getSubtype() == 'upload')
383  $exc_subtype_option['upload'] = $this->lng->txt('upload');
384 
385  $oExcSubtype = new ilSelectInputGUI($this->lng->txt('select_subtype'), 'exc_subtype');
386  $oExcSubtype->setOptions($exc_subtype_option);
387  $oExcSubtype->setValue($this->pobject->getSubtype());
388  $oForm->addItem($oExcSubtype);
389 
390  break;
391  default: break;
392  }
393  // number of purchasers
394  $oPurchasersGUI = new ilNonEditableValueGUI($this->lng->txt('paya_count_purchaser'));
395  $oPurchasersGUI->setValue(ilPaymentBookings::_getCountBookingsByObject((int)$_GET['pobject_id']));
396  $oForm->addItem($oPurchasersGUI);
397 
398  // vendors
399  $oVendorsGUI = new ilSelectInputGUI($this->lng->txt('paya_vendor'), 'vendor');
400  $oVendorsGUI->setOptions($this->__getVendors());
401  $oVendorsGUI->setValue($this->pobject->getVendorId());
402  $oForm->addItem($oVendorsGUI);
403 
404  // status
405  $oStatusGUI = new ilSelectInputGUI($this->lng->txt('status'), 'status');
406  $oStatusGUI->setOptions($this->__getStatus());
407  $oStatusGUI->setValue($this->pobject->getStatus());
408  $oForm->addItem($oStatusGUI);
409 
410  // pay methods
411  $oPayMethodsGUI = new ilSelectInputGUI($this->lng->txt('paya_pay_method'), 'pay_method');
412  $PMoptions = ilPaymethods::getPayMethodsOptions('not_specified');
413  $oPayMethodsGUI->setOptions($PMoptions);
414  $oPayMethodsGUI->setValue($this->pobject->getPayMethod());
415  $oForm->addItem($oPayMethodsGUI);
416 
417  // topics
418  ilShopTopics::_getInstance()->read();
419  if(is_array($topics = ilShopTopics::_getInstance()->getTopics()) && count($topics))
420  {
421  $oTopicsGUI = new ilSelectInputGUI($this->lng->txt('topic'), 'topic_id');
422  include_once 'Services/Payment/classes/class.ilShopTopics.php';
423  ilShopTopics::_getInstance()->read();
424  $topic_options = array();
425  $topic_options[''] = $this->lng->txt('please_choose');
426 
427  foreach($topics as $oTopic)
428  {
429  $topic_options[$oTopic->getId()] = $oTopic->getTitle();
430  }
431 
432  $oTopicsGUI->setOptions($topic_options);
433  $oTopicsGUI->setValue($this->pobject->getTopicId());
434  $oForm->addItem($oTopicsGUI);
435  }
436 
437  // vats
438  $oShopVatsList = new ilShopVatsList();
439  $oShopVatsList->read();
440  if($oShopVatsList->hasItems())
441  {
442  $oVatsGUI = new ilSelectInputGUI($this->lng->txt('vat_rate'), 'vat_id');
443 
444  $vats_options = array();
445  foreach($oShopVatsList as $oVAT)
446  {
447  $vats_options[$oVAT->getId()] = ilShopUtils::_formatVAT($oVAT->getRate()).' -> '.$oVAT->getTitle();
448  }
449 
450  $oVatsGUI->setOptions($vats_options);
451  $oVatsGUI->setValue($this->pobject->getVatId());
452  $oForm->addItem($oVatsGUI);
453  }
454  else
455  {
456  $oVatsGUI = new ilNonEditableValueGUI($this->lng->txt('vat_rate'));
457  $oVatsGUI->setValue($this->lng->txt('paya_no_vats_assigned'));
458  $oForm->addItem($oVatsGUI);
459  }
460 
461  $oThumbnail = new ilImageFileInputGUI($this->lng->txt('pay_thumbnail'), 'thumbnail');
462  $oFile = new ilFileDataShop($this->pobject->getPobjectId());
463  if(($webpath_file = $oFile->getCurrentImageWebPath()) !== false)
464  {
465  $oThumbnail->setImage($webpath_file);
466  }
467  $oForm->addItem($oThumbnail);
468 
469  if($genSet->get('use_shop_specials'))
470  {
471  // special object
472  $oSpecial = new ilCheckboxInputGUI($this->lng->txt('special'), 'is_special');
473  $oSpecial->setChecked((int)$this->pobject->getSpecial());
474  $oSpecial->setInfo($this->lng->txt('special_info'));
475  $oForm->addItem($oSpecial);
476  }
477  // buttons
478  $oForm->addCommandButton('updateDetails', $this->lng->txt('save'));
479  $oForm->addCommandButton('deleteObject', $this->lng->txt('delete'));
480 
481  $this->tpl->setVariable('FORM', $oForm->getHTML());
482  }
483 
484  public function deleteObject()
485  {
486  include_once './Services/Payment/classes/class.ilPaymentBookings.php';
487 
488  if(!$_GET['pobject_id'])
489  {
490  ilUtil::sendFailure($this->lng->txt('paya_no_object_selected'));
491 
492  $this->showObjects();
493  return true;
494  }
495  if(ilPaymentBookings::_getCountBookingsByObject((int) $_GET['pobject_id']))
496  {
497  ilUtil::sendInfo($this->lng->txt('paya_bookings_available'));
498  $this->editDetails();
499 
500  return false;
501  }
502  else
503  {
504 
505  $this->editDetails(true);
506 
507  return true;
508  }
509  }
510 
511  public function performDelete()
512  {
513  include_once './Services/Payment/classes/class.ilPaymentPrices.php';
514 
515  if(!$_GET['pobject_id'])
516  {
517  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
518 
519  $this->showObjects();
520  return true;
521  }
522  $this->__initPaymentObject((int) $_GET['pobject_id']);
523 
524  // delete object data
525  $this->pobject->delete();
526 
527  // delete payment prices
528  $price_obj = new ilPaymentPrices((int) $_GET['pobject_id']);
529  $price_obj->deleteAllPrices();
530  unset($price_obj);
531 
532  ilUtil::sendInfo($this->lng->txt('paya_deleted_object'));
533 
534  $this->showObjects();
535 
536  return true;
537  }
538 
539  public function editPayMethod()
540  {
541  $this->__initPaymentObject((int) $_GET['pobject_id']);
542 
543  switch($this->pobject->getPayMethod())
544  {
545  case $this->pobject->PAY_METHOD_NOT_SPECIFIED:
546  ilUtil::sendFailure($this->lng->txt('paya_select_pay_method_first'));
547  $this->editDetails();
548  return true;
549 
550  default:
551  ilUtil::sendInfo($this->lng->txt('paya_no_settings_necessary'));
552  $this->editDetails();
553  return true;
554  }
555  $this->editDetails();
556 
557  return true;
558  }
559 
560  public function editPrices($a_show_delete = false, $oConfirmationGUI = '')
561  {
562  global $ilToolbar;
563  include_once './Services/Payment/classes/class.ilPaymentPrices.php';
564  include_once './Services/Payment/classes/class.ilPaymentCurrency.php';
565  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
566  include_once './Services/Payment/classes/class.ilPaymentSettings.php';
568 
569  if($a_show_delete == false) unset($_SESSION['price_ids']);
570 
571  $_SESSION['price_ids'] = $_SESSION['price_ids'] ? $_SESSION['price_ids'] : array();
572 
573  if(!$_GET['pobject_id'])
574  {
575  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
576 
577  $this->objectsObject();
578  return true;
579  }
580  $this->ctrl->setParameter($this,'pobject_id',(int) $_GET['pobject_id']);
581  $this->__initPaymentObject((int) $_GET['pobject_id']);
582 
583  $this->tpl->addBlockfile("ADM_CONTENT", "adm_content",'tpl.main_view.html','Services/Payment');
584 
585  $price_obj = new ilPaymentPrices((int) $_GET['pobject_id']);
586 
587  $standard_prices = array();
588  $extension_prices = array();
589  $standard_prices = $price_obj->getPrices();
590  $extension_prices = $price_obj->getExtensionPrices();
591 
592  $prices = array_merge($standard_prices, $extension_prices );
593 
594  // No prices created
595  if(!count($prices))
596  {
597  ilUtil::sendInfo($this->lng->txt('paya_no_price_available'));
598  $ilToolbar->addButton($this->lng->txt('paya_add_price'), $this->ctrl->getLinkTarget($this, 'addPrice'));
599 
600  return true;
601  }
602  else if(!count($standard_prices))
603  {
604  //set pobject status to "not buyable" if there is no standard_price defined
605  $this->pobject->setStatus(0);
606  $this->pobject->update();
607  ilUtil::sendInfo($this->lng->txt('paya_no_price_available'));
608  }
609 
610  // Show confirm delete
611  if($a_show_delete)
612  {
613  $oConfirmationGUI = new ilConfirmationGUI();
614 
615  // set confirm/cancel commands
616  $oConfirmationGUI->setFormAction($this->ctrl->getFormAction($this,"performDeletePrice"));
617  $oConfirmationGUI->setHeaderText($this->lng->txt("paya_sure_delete_selected_prices"));
618  $oConfirmationGUI->setCancel($this->lng->txt("cancel"), "editPrices");
619  $oConfirmationGUI->setConfirm($this->lng->txt("confirm"), "performDeletePrice");
620 
621  $counter = 0;
622 
623  foreach($prices as $price)
624  {
625  $currency = $genSet->get('currency_unit');
626  if(in_array($price['price_id'],$_SESSION['price_ids']))
627  {
628 
629  if ($price['unlimited_duration'] == '1')
630  {
631  $tmp_price = $this->lng->txt('unlimited_duration');
632  }
633  else
634  {
635  $tmp_price = $price['duration'].' '.$this->lng->txt('paya_months');
636  }
637  $delete_row = ''.$tmp_price.' : '.
638  ilFormat::_getLocalMoneyFormat($price['price']).' '.
639  $currency;
640 
641  $oConfirmationGUI->addItem('',$delete_row, $delete_row);
642  $delete_row = '';
643  }
644  $counter++;
645  }
646 
647  $this->tpl->setVariable('CONFIRMATION', $oConfirmationGUI->getHTML());
648 
649  return true;
650  }
651 
652  $ilToolbar->addButton($this->lng->txt('paya_edit_details'), $this->ctrl->getLinkTarget($this, 'editDetails'));
653  $ilToolbar->addButton($this->lng->txt('paya_edit_prices'), $this->ctrl->getLinkTarget($this, 'editPrices'));
654  $ilToolbar->addButton($this->lng->txt('pay_edit_abstract'), $this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'edit'));
655 
656  // Fill table cells
657  $tpl = new ilTemplate('tpl.table.html',true,true);
658 
659  // set table header
660  $tpl->setCurrentBlock('tbl_form_header');
661 
662  $tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this));
663  $tpl->parseCurrentBlock();
664 
665  $counter = 0;
666  foreach($prices as $price)
667  {
668  $currency = ilPaymentCurrency::_getCurrency($price['currency']);
669  if($a_show_delete == true )
670  {
671  $this->ctrl->setParameter($this, 'show_delete', 'true');
672 
673  if(in_array($price['price_id'],$_SESSION['price_ids']))
674  {
675  $data[$counter]['price_id'] = ilUtil::formCheckBox(0,
676  'price_ids[]', (int)$price['price_id']);
677  //$data[$counter]['price_id'] = '';
678  $data[$counter]['duration'] =$price['duration'] ;
679  $data[$counter]['month'] = $this->lng->txt('paya_months');
680 
681  $data[$counter]['unlimited_duration'] = ilUtil::formCheckBox($price['unlimited_duration'] ? 1 : 0,
682  'duration_ids[]', (int)$price['price_id']);
683 
684  $data[$counter]['price'] = ilFormat::_getLocalMoneyFormat($price['price']);
685  $data[$counter]['currency_unit'] = $genSet->get('currency_unit');
686  $data[$counter]['extension'] = ilUtil::formCheckBox($price['extension'] ? 1 : 0,
687  'extension_ids[]', (int)$price['price_id']);
688  //TODO: later $data[$counter]['currency_unit'] = $currency['unit'];
689  }
690  }
691  else
692  {
693  $data[$counter]['price_id'] = ilUtil::formCheckBox(in_array($price['price_id'],$_SESSION['price_ids']) ? 1 : 0,
694  'price_ids[]', $price['price_id']);
695 
696  $data[$counter]['duration'] = ilUtil::formInput('prices['.$price['price_id'].'][duration]',$price['duration']);
697  $data[$counter]['month'] = $this->lng->txt('paya_months');
698 
699  $data[$counter]['unlimited_duration'] = ilUtil::formCheckBox($price['unlimited_duration'] ? 1 : 0,
700  'duration_ids[]', (int)$price['price_id']);
701 
702  $data[$counter]['price'] = ilUtil::formInput('prices['.$price['price_id'].'][price]', ilFormat::_getLocalMoneyFormat($price['price']));
703  $data[$counter]['currency_unit'] = $genSet->get('currency_unit');
704  $data[$counter]['extension'] = ilUtil::formCheckBox($price['extension'] ? 1 : 0,
705  'extension_ids[]', (int)$price['price_id']);
706 /* TODO: later -> use currency table
707  * $data[$counter]['price'] = ilUtil::formInput('prices['.$price['price_id'].'][price]', ilFormat::_getLocalMoneyFormat($price['price']));
708 
709  $default_currency = ilPaymentCurrency::_getDefaultCurrency();
710 
711  $all_currencies = ilPaymentCurrency::_getAvailableCurrencies();
712  $currency_options = array();
713 
714  foreach($all_currencies as $cur)
715  {
716  $currency_options[$cur['currency_id']] = $cur['unit'];
717  }
718 
719  $data[$counter]['currency_unit'] = ilUtil::formSelect($price['currency'], 'prices['.$price['price_id'].'][currency]',
720  $currency_options,false,true);
721 
722  */
723  }
724  ++$counter;
725  }
726  $this->__editPricesTable($data);
727 
728  return true;
729  }
730 
731  private function __editPricesTable($a_result_set)
732  {
733  $tbl = new ilShopTableGUI($this);
734 
735  $tmp_obj = ilObjectFactory::getInstanceByRefId($this->pobject->getRefId(), false);
736  if($tmp_obj)
737  {
738  $tbl->setTitle($tmp_obj->getTitle());
739  }
740  else
741  {
742  $tbl->setTitle($this->lng->txt('object_not_found'));
743  }
744 
745  $tbl->setId('tbl_bookings');
746  $tbl->setRowTemplate("tpl.shop_prices_row.html", "Services/Payment");
747 
748  $tbl->addColumn(' ', 'price_id', '5%');
749  $tbl->addColumn($this->lng->txt('duration'), 'duration', '10%');
750  $tbl->addColumn('','month','10%');
751  $tbl->addColumn($this->lng->txt('unlimited_duration'), 'unlimitied_duration', '15%');
752  $tbl->addColumn($this->lng->txt('price_a'), 'price', '10%');
753  $tbl->addColumn($this->lng->txt('currency'), 'currency_unit', '10%');
754  $tbl->addColumn($this->lng->txt('extension_price'), 'extension', '40%');
755 
756  $tbl->setSelectAllCheckbox('price_id');
757  $tbl->addCommandButton('updatePrice',$this->lng->txt('paya_update_price'));
758  $tbl->addCommandButton('addPrice',$this->lng->txt('paya_add_price'));
759 
760  $tbl->addMultiCommand("deletePrice", $this->lng->txt("paya_delete_price"));
761  $tbl->fillFooter();
762 
763  $tbl->setData($a_result_set);
764 
765  $this->tpl->setVariable('TABLE', $tbl->getHTML());
766 
767  return true;
768  }
769 
770  public function addPrice()
771  {
772  global $ilToolbar;
773 
774  if(!$_GET['pobject_id'])
775  {
776  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
777 
778  $this->showObjects();
779  return true;
780  }
781 
782  include_once './Services/Payment/classes/class.ilPaymentSettings.php';
783 
785 
786 
787  $this->ctrl->setParameter($this,'pobject_id',(int) $_GET['pobject_id']);
788 
789  $this->__initPaymentObject((int) $_GET['pobject_id']);
790 
791  $ilToolbar->addButton($this->lng->txt('paya_edit_details'), $this->ctrl->getLinkTarget($this, 'editDetails'));
792  $ilToolbar->addButton($this->lng->txt('paya_edit_prices'), $this->ctrl->getLinkTarget($this, 'editPrices'));
793 
794  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
795 
796  $form = new ilPropertyFormGUI();
797  $form->setFormAction($this->ctrl->getFormAction($this));
798  $form->setTitle($this->lng->txt('paya_add_price_title'));
799 
800  // object_title
801  $oTitle = new ilNonEditableValueGUI($this->lng->txt('title'));
802  $tmp_obj = ilObjectFactory::getInstanceByRefId($this->pobject->getRefId(), false);
803  if(is_object($tmp_obj))
804  {
805  $oTitle->setValue($tmp_obj->getTitle());
806  }
807  else
808  {
809  $oTitle->setValue($this->lng->txt('object_not_found'));
810  }
811  $form->addItem($oTitle);
812 
813  // duration
814  $oDuration = new ilTextInputGUI();
815  $oDuration->setTitle($this->lng->txt('duration'));
816  $oDuration->setValue($_POST['duration']);
817  $oDuration->setInfo($this->lng->txt('paya_months'));
818  $oDuration->setPostVar('duration');
819  $form->addItem($oDuration);
820  // unlimited duration
821  $oUnlimitedDuration = new ilCheckboxInputGUI($this->lng->txt('unlimited_duration'), 'unlimited_duration');
822  $oUnlimitedDuration->setChecked($_POST['unlimited_duration'] == 1);
823 
824  $form->addItem($oUnlimitedDuration);
825 
826  // price
827  $oPrice = new ilTextInputGUI();
828  $oPrice->setTitle($this->lng->txt('price_a'));
829  $oPrice->setValue($_POST['price']);
830  $oPrice->setPostVar('price');
831  $oPrice->setRequired(true);
832  $form->addItem($oPrice);
833 
834  // currency
835  $this->tpl->setVariable('TXT_PRICE_A',$genSet->get('currency_unit'));
836 
837  //extension
838  $oExtension = new ilCheckboxInputGUI($this->lng->txt('extension_price'), 'extension');
839  isset($_POST['extension']) ? $ext_value = 1 : $ext_value = 0;
840  $oExtension->setChecked($ext_value);
841 
842  $form->addItem($oExtension);
843 
844 /*
845  // TODO: show currency selector
846 
847  // currency
848  include_once './Services/Payment/classes/class.ilPaymentCurrency.php';
849  $objCurrency = new ilPaymentCurrency();
850  $currencies = $objCurrency->_getAvailableCurrencies();
851 
852  foreach($currencies as $currency)
853  {
854  $currency_options[$currency['currency_id']] = $currency['unit'];
855  }
856 
857  $oCurrency = new ilSelectInputGUI($this->lng->txt('currency'), 'currency_id');
858  $oCurrency->setOptions($currency_options);
859 
860  $oCurrency->setValue($_SESSION['pay_objects']['currency_value']);
861  $oCurrency->setPostVar('currency_id');
862 
863  $form->addItem($oCurrency);
864 
865  */
866  $form->addCommandButton('performAddPrice',$this->lng->txt('paya_add_price'));
867  $form->addCommandButton('editPrices', $this->lng->txt('cancel'));
868  $this->tpl->setVariable('FORM',$form->getHTML());
869 
870  return true;
871  }
872 
873  public function performAddPrice()
874  {
875 
876  if(!$_GET['pobject_id'])
877  {
878  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
879 
880  $this->showObjects();
881  return true;
882  }
883 
884  include_once './Services/Payment/classes/class.ilPaymentPrices.php';
885  include_once './Services/Payment/classes/class.ilPaymentCurrency.php';
886 
888 
889  $prices = new ilPaymentPrices((int) $_GET['pobject_id']);
890 
891  $prices->setDuration($_POST['duration']);
892  $prices->setUnlimitedDuration($_POST['unlimited_duration']);
893  if($_POST['unlimited_duration'] == '1')
894  {
895  $prices->setUnlimitedDuration(1);
896  }
897 
898  $prices->setPrice((float)$_POST['price']);
899  $prices->setCurrency($currency[1]['currency_id']);
900  if($_POST['extension'] == '1')
901  {
902  $prices->setExtension(1);
903  }
904  else
905  $prices->setExtension(0);
906  //$prices->setCurrency($_POST['currency_id']);
907 
908  if(!$prices->validate())
909  {
910  ilUtil::sendInfo($this->lng->txt('paya_price_not_valid'));
911  $this->addPrice();
912 
913  return true;
914  }
915  $prices->add();
916 
917  ilUtil::sendSuccess($this->lng->txt('paya_added_new_price'));
918  $this->editPrices();
919 
920  return true;
921  }
922 
923  public function performDeletePrice()
924  {
925  if(!$_GET['pobject_id'])
926  {
927  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
928 
929  $this->showObjects();
930  return true;
931  }
932 
933  if(!count($_SESSION['price_ids']))
934  {
935  ilUtil::sendInfo($this->lng->txt('paya_no_prices_selected'));
936 
937  $this->editPrices();
938  return true;
939  }
940  include_once './Services/Payment/classes/class.ilPaymentPrices.php';
941 
942  $prices = new ilPaymentPrices((int) $_GET['pobject_id']);
943 
944  foreach($_SESSION['price_ids'] as $price_id)
945  {
946  $prices->delete($price_id);
947  }
948 
949  // check if it was last price otherwise set status to 'not_buyable'
950  if(!count($prices->getPrices()))
951  {
952  $this->__initPaymentObject((int) $_GET['pobject_id']);
953 
954  $this->pobject->setStatus($this->pobject->STATUS_NOT_BUYABLE);
955  $this->pobject->update();
956 
957  ilUtil::sendInfo($this->lng->txt('paya_deleted_last_price'));
958  }
959  unset($prices);
960  unset($_SESSION['price_ids']);
961 
962  return $this->editPrices();
963  }
964 
965 
966  public function deletePrice()
967  {
968  if(!$_GET['pobject_id'])
969  {
970  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
971 
972  $this->showObjects();
973  return true;
974  }
975 
976  if(!count($_POST['price_ids']))
977  {
978  ilUtil::sendInfo($this->lng->txt('paya_no_prices_selected'));
979 
980  $this->editPrices();
981  return true;
982  }
983  $_SESSION['price_ids'] = $_POST['price_ids'];
984 
985  $this->editPrices(true);
986  return true;
987  }
988 
989  public function updatePrice()
990  {
991  include_once './Services/Payment/classes/class.ilPaymentPrices.php';
992 
993  if(!$_GET['pobject_id'])
994  {
995  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
996 
997  $this->showObjects();
998  return true;
999  }
1000  $po = new ilPaymentPrices((int) $_GET['pobject_id']);
1001 
1002  $this->ctrl->setParameter($this,'pobject_id',(int) $_GET['pobject_id']);
1003 
1004  // validate
1005  foreach($_POST['prices'] as $price_id => $price)
1006  {
1007  $old_price = $po->getPrice($price_id);
1008 
1009  $po->setDuration($price['duration']);
1010  $po->setUnlimitedDuration($price['unlimited_duration']);
1011  $po->setPrice($price['price']);
1012  $po->setCurrency($old_price['currency']);
1013  $po->setExtension($price['extension']);
1014 //$po->setCurrency($price['currency']);
1015  if(!$po->validate())
1016  {
1017  $error = true;
1018  }
1019  }
1020  if($error)
1021  {
1022  ilUtil::sendInfo($this->lng->txt('paya_insert_only_numbers'));
1023 
1024  $this->editPrices();
1025  return false;
1026  }
1027 
1028  foreach($_POST['prices'] as $price_id => $price)
1029  {
1030  $old_price = $po->getPrice($price_id);
1031  if(isset($_POST['duration_ids']))
1032  {
1033  $search = in_array((string)$price_id, $_POST['duration_ids']);
1034 
1035  if($_POST['duration_ids'] == NULL)
1036  {
1037  $po->setUnlimitedDuration(0);
1038  $po->setDuration($price['duration']);
1039  }
1040 
1041  else if( $search = in_array((string)$price_id, $_POST['duration_ids']))
1042  {
1043  $po->setUnlimitedDuration(1);
1044  $po->setDuration(0);
1045  }
1046  else
1047  {
1048  $po->setUnlimitedDuration(0);
1049  }
1050  }
1051 
1052  if(isset($_POST['extension_ids']))
1053  {
1054  $search = in_array((string)$price_id, $_POST['extension_ids']);
1055 
1056  if( $search = in_array((string)$price_id, $_POST['extension_ids']))
1057  {
1058  $po->setExtension(1);
1059  }
1060  else
1061  {
1062  $po->setExtension(0);
1063  }
1064  }
1065 
1066 
1067  $po->setDuration($price['duration']);
1068 
1069  $po->setPrice($price['price']);
1070  $po->setCurrency($old_price['currency']);
1071 //$po->setCurrency($price['currency']);
1072  $po->update($price_id);
1073  }
1074  ilUtil::sendInfo($this->lng->txt('paya_updated_prices'));
1075  $this->editPrices();
1076 
1077  return true;
1078  }
1079 
1080 
1081  public function updateDetails()
1082  {
1083  if(!$_GET['pobject_id'])
1084  {
1085  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
1086 
1087  $this->showObjects();
1088  return true;
1089  }
1090  $this->__initPaymentObject((int)$_GET['pobject_id']);
1091  $this->ctrl->setParameter($this, 'pobject_id', (int)$_GET['pobject_id']);
1092 
1093  // read old settings
1094  $old_pay_method = $this->pobject->getPayMethod();
1095  $old_status = $this->pobject->getStatus();
1096 
1097  // check status changed from not_buyable
1098  if($old_status == $this->pobject->STATUS_NOT_BUYABLE and
1099  (int) $_POST['status'] != $old_status)
1100  {
1101  // check pay_method edited
1102  switch((int) $_POST['pay_method'])
1103  {
1104  case $this->pobject->PAY_METHOD_NOT_SPECIFIED:
1105  ilUtil::sendInfo($this->lng->txt('paya_select_pay_method_first'));
1106  $this->editDetails();
1107 
1108  return false;
1109 
1110  default:
1111  ;
1112  }
1113  // check minimum one price
1114  include_once './Services/Payment/classes/class.ilPaymentPrices.php';
1115 
1116  $prices_obj = new ilPaymentPrices((int) $_GET['pobject_id']);
1117  if(!count($prices_obj->getPrices()))
1118  {
1119  ilUtil::sendInfo($this->lng->txt('paya_edit_prices_first'));
1120  $this->editDetails();
1121 
1122  return false;
1123  }
1124  }
1125 
1126  if((int)$_POST['status'] == 0)
1127  {
1128  // Status: not buyable -> delete depending shoppingcart entries
1129  include_once './Services/Payment/classes/class.ilPaymentShoppingCart.php';
1130  ilPaymentShoppingCart::_deleteShoppingCartEntries($this->pobject->getPobjectId());
1131  }
1132 
1133  $this->pobject->setStatus((int)$_POST['status']);
1134  $this->pobject->setVendorId((int)$_POST['vendor']);
1135  $this->pobject->setPayMethod((int)$_POST['pay_method']);
1136  $this->pobject->setTopicId((int)$_POST['topic_id']);
1137  $this->pobject->setVatId((int)$_POST['vat_id']);
1138  $this->pobject->setSubtype((string)$_POST['exc_subtype']);
1139  $this->pobject->setSpecial((int)$_POST['is_special']);
1140 
1141  if((int)$_POST['thumbnail_delete'])
1142  {
1143  $oFile = new ilFileDataShop($this->pobject->getPobjectId());
1145  }
1146  else if($_FILES['thumbnail']['tmp_name'] != '')
1147  {
1148  $this->lng->loadLanguageModule('form');
1149  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
1150  $oThumbnail = new ilImageFileInputGUI($this->lng->txt('pay_thumbnail'), 'thumbnail');
1151  if($oThumbnail->checkInput())
1152  {
1153  $oFile = new ilFileDataShop($this->pobject->getPobjectId());
1154  if(($oFile->storeUploadedFile($_FILES['thumbnail'])) !== false)
1155  {
1156  $oFile->assignFileToPaymentObject();
1157  }
1158  }
1159  else
1160  {
1161  ilUtil::sendInfo($oThumbnail->getAlert());
1162  return $this->editDetails();
1163  }
1164  }
1165 
1166  $this->pobject->update();
1167 
1168  ilUtil::sendInfo($this->lng->txt('paya_details_updated'));
1169  $this->showObjects();
1170 
1171  return true;
1172  }
1173 
1174  public function showObjectSelector()
1175  {
1176  global $tree, $ilToolbar;
1177 
1178  include_once './Services/Payment/classes/class.ilPaymentObjectSelector.php';
1179 
1180  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.paya_object_selector.html','Services/Payment');
1181  $ilToolbar->addButton($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'showObjects'));
1182 
1183 
1184  ilUtil::sendInfo($this->lng->txt('paya_select_object_to_sell'));
1185 
1186  $exp = new ilPaymentObjectSelector($this->ctrl->getLinkTarget($this,'showObjectSelector'), strtolower(get_class($this)));
1187  $exp->setExpand($_GET['paya_link_expand'] ? $_GET['paya_link_expand'] : $tree->readRootId());
1188  $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'showObjectSelector'));
1189 
1190  $exp->setOutput(0);
1191 
1192  $this->tpl->setVariable("EXPLORER",$exp->getOutput());
1193 
1194  return true;
1195  }
1196 
1197  public function showSelectedObject()
1198  {
1199  global $ilToolbar;
1200 
1201  if(!(int)$_GET['sell_id'])
1202  {
1203  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
1204  return $this->showObjectSelector();
1205  }
1206 
1207  $ilToolbar->addButton($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'showObjectSelector'));
1208 
1209  // save ref_id of selected object
1210  $this->ctrl->setParameter($this, 'sell_id', (int)$_GET['sell_id']);
1211 
1212  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
1213  $oForm = new ilPropertyFormGUI();
1214  $oForm->setFormAction($this->ctrl->getFormAction($this, 'updateDetails'));
1215  $oForm->setTitle($this->lng->txt('details'));
1216  $oForm->setTitleIcon(ilUtil::getImagePath('icon_pays.gif', false));
1217 
1218  $tmp_obj = ilObjectFactory::getInstanceByRefId($_GET['sell_id'], false);
1219  if(is_object($tmp_obj))
1220  {
1221  $tmp_object['title'] = $tmp_obj->getTitle();
1222  $tmp_object['description'] = $tmp_obj->getDescription();
1223  $tmp_object['owner'] = $tmp_obj->getOwnerName();
1224  $tmp_object['path'] = $this->__getHTMLPath((int)$_GET['sell_id']);
1225  }
1226  else
1227  {
1228  $tmp_object['title'] = $this->lng->txt('object_not_found');
1229  $tmp_object['description'] = '';
1230  $tmp_object['owner'] = '';
1231  $tmp_object['path'] = '';
1232  }
1233 
1234  // title
1235  $oTitleGUI = new ilNonEditableValueGUI($this->lng->txt('title'));
1236  $oTitleGUI->setValue($tmp_object['title']);
1237  $oForm->addItem($oTitleGUI);
1238 
1239  // description
1240  $oDescriptionGUI = new ilNonEditableValueGUI($this->lng->txt('description'));
1241  $oDescriptionGUI->setValue($tmp_object['description']);
1242  $oForm->addItem($oDescriptionGUI);
1243 
1244  // owner
1245  $oOwnerGUI = new ilNonEditableValueGUI($this->lng->txt('owner'));
1246  $oOwnerGUI->setValue($tmp_object['owner']);
1247  $oForm->addItem($oOwnerGUI);
1248 
1249  // repository path
1250  $oPathGUI = new ilNonEditableValueGUI($this->lng->txt('path'));
1251  $oPathGUI->setValue($tmp_object['path']);
1252  $oForm->addItem($oPathGUI);
1253 
1254  // vendors
1255  $oVendorsGUI = new ilSelectInputGUI($this->lng->txt('paya_vendor'), 'vendor');
1256  $oVendorsGUI->setOptions($this->__getVendors());
1257  $oForm->addItem($oVendorsGUI);
1258 
1259  // buttons
1260  $oForm->addCommandButton('addObject', $this->lng->txt('next'));
1261  $oForm->addCommandButton('showObjects', $this->lng->txt('cancel'));
1262 
1263  $this->tpl->setVariable('ADM_CONTENT', $oForm->getHTML());
1264  }
1265 
1266  public function addObject()
1267  {
1268  if(!$_GET['sell_id'])
1269  {
1270  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
1271 
1272  return $this->showObjectSelector();
1273  }
1274  if(!(int)$_POST['vendor'])
1275  {
1276  ilUtil::sendInfo($this->lng->txt('paya_no_vendor_selected'));
1277 
1278  return $this->showSelectedObject();
1279  }
1280 
1281  include_once 'Services/Payment/classes/class.ilPaymentObject.php';
1282  $p_obj = new ilPaymentObject($this->user_obj);
1283 
1284  if($check_subtypes= ilPaymentObject::_checkExcSubtype($_GET['sell_id']))
1285 {
1286  if(!in_array('download',$check_subtypes))
1287  $p_obj->setSubtype('download');
1288  else
1289  if(!in_array('upload',$check_subtypes))
1290  $p_obj->setSubtype('upload');
1291 
1292 
1293  }
1294  else
1295  if(ilPaymentObject::_isPurchasable($_GET['sell_id']))
1296  {
1297  // means that current object already exits in payment_objects _table ...
1298  ilUtil::sendInfo($this->lng->txt('paya_object_not_purchasable'));
1299 
1300  return $this->showObjectSelector();
1301  }
1302 
1303  $p_obj->setRefId((int)$_GET['sell_id']);
1304  $p_obj->setStatus($p_obj->STATUS_NOT_BUYABLE);
1305  $p_obj->setPayMethod($p_obj->PAY_METHOD_NOT_SPECIFIED);
1306  $p_obj->setVendorId((int)$_POST['vendor']);
1307  $p_obj->setTopicId((int)$_POST['topic_id']);
1308  $p_obj->setVatId((int)$_POST['vat_id']);
1309 
1310  $new_id = $p_obj->add();
1311  if($new_id)
1312  {
1313  ilUtil::sendInfo($this->lng->txt('paya_added_new_object'));
1314  $_GET['pobject_id'] = $new_id;
1315  return $this->editDetails();
1316  }
1317  else
1318  {
1319  ilUtil::sendInfo($this->lng->txt('paya_err_adding_object'));
1320  return $this->showObjects();
1321  }
1322  }
1323 
1324  private function __getVendors()
1325  {
1326  include_once 'Services/Payment/classes/class.ilPaymentVendors.php';
1327 
1328  $options = array();
1329  $vendors = array();
1330  if(ilPaymentVendors::_isVendor($this->user_obj->getId()))
1331  {
1332  $vendors[] = $this->user_obj->getId();
1333  }
1334  if($vend = ilPaymentTrustees::_getVendorsForObjects($this->user_obj->getId()))
1335  {
1336  $vendors = array_merge($vendors, $vend);
1337  }
1338  foreach($vendors as $vendor)
1339  {
1340  $tmp_obj = ilObjectFactory::getInstanceByObjId($vendor, false);
1341  $options[$vendor] = $tmp_obj->getFullname().' ['.$tmp_obj->getLogin().']';
1342  }
1343 
1344  return $options;
1345  }
1346 
1347 
1348  private function __getStatus()
1349  {
1350  $option = array();
1351  $option[$this->pobject->STATUS_NOT_BUYABLE] = $this->lng->txt('paya_not_buyable');
1352  $option[$this->pobject->STATUS_BUYABLE] = $this->lng->txt('paya_buyable');
1353  $option[$this->pobject->STATUS_EXPIRES] = $this->lng->txt('paya_expires');
1354 
1355  return $option;
1356  }
1357 
1358  private function __showObjectsTable($a_result_set)
1359  {
1360  $tbl = new ilShopTableGUI($this);
1361  $tbl->setTitle($this->lng->txt('objects'));
1362 
1363  $tbl->setId('tbl_objects');
1364  $tbl->setRowTemplate("tpl.shop_objects_row.html", "Services/Payment");
1365 
1366  $tbl->addColumn($this->lng->txt('title'), 'title', '10%');
1367  $tbl->addColumn($this->lng->txt('status'), 'status', '10%');
1368  $tbl->addColumn($this->lng->txt('paya_pay_method'),'pay_method','10%');
1369  $tbl->addColumn($this->lng->txt('vat_rate'), 'vat_rate', '15%');
1370  $tbl->addColumn($this->lng->txt('paya_vendor'), 'vendor', '10%');
1371  $tbl->addColumn($this->lng->txt('paya_count_purchaser'), 'purchasers', '10%');
1372  $tbl->addColumn('','options','10%');
1373 
1374  $tbl->setData($a_result_set);
1375 
1376  $this->tpl->setVariable('TABLE', $tbl->getHTML());
1377 
1378  return true;
1379  }
1380 
1381 
1382  private function __getHTMLPath($a_ref_id)
1383  {
1384  global $tree;
1385 
1386  $path = $tree->getPathFull($a_ref_id);
1387  unset($path[0]);
1388 
1389  foreach($path as $data)
1390  {
1391  $html .= $data['title'].' > ';
1392  }
1393  return substr($html,0,-2);
1394  }
1395 
1396  private function __initPaymentObject($a_pobject_id = 0)
1397  {
1398  include_once './Services/Payment/classes/class.ilPaymentObject.php';
1399 
1400  $this->pobject = new ilPaymentObject($this->user_obj,$a_pobject_id);
1401 
1402  return true;
1403  }
1404 }
1405 ?>