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