ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilShopPurchaseGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once "./Services/Object/classes/class.ilObjectGUI.php";
5
16{
17 public $ctrl;
18 public $lng;
19 public $tpl;
20
21 public $object = null;
22 public $pobject = null;
23 public $cur_row_type = null;
24 public $price_obj = null;
25 public $sc_obj = null;
26
27 public function __construct($a_ref_id)
28 {
29 global $ilCtrl,$lng,$ilErr,$tpl,$ilTabs;
30
31 $this->ctrl = $ilCtrl;
32 $this->ctrl->saveParameter($this, array("ref_id"));
33
34 $this->ilErr = $ilErr;
35
36 $this->lng = $lng;
37 $this->lng->loadLanguageModule('payment');
38
39 $this->tpl = $tpl;
40
41 $this->ref_id = $a_ref_id;
42
43 $this->object = ilObjectFactory::getInstanceByRefId($this->ref_id, false);
44
45 $this->tpl->getStandardTemplate();
46
47 $ilTabs->clearTargets();
48 $ilTabs->addTarget('buy', $this->ctrl->getLinkTarget($this, 'showDetails').'&purchasetype=buy');
49 $ilTabs->addTarget('payment_demo', $this->ctrl->getLinkTarget($this, 'showDemoVersion').'&purchasetype=demo');
50
51 $this->ctrl->setParameter($this, 'purchasetype', ($_GET['purchasetype'] == 'demo' ? 'demo' : 'buy'));
52
53 }
54
58 public function executeCommand()
59 {
60 $cmd = $this->ctrl->getCmd();
61 switch($this->ctrl->getCmdClass())
62 {
63 case 'ilshoppagegui':
64 $this->__initPaymentObject();
65 include_once 'Services/Style/classes/class.ilObjStyleSheet.php';
66 include_once 'Services/Payment/classes/class.ilShopPageGUI.php';
67 $page_gui = new ilShopPageGUI($this->pobject->getPobjectId());
68 $this->ctrl->forwardCommand($page_gui);
69 return true;
70 break;
71 }
72
73
74 switch($cmd)
75 {
76 case 'addToShoppingCart':
77 break;
78
79 default:
80 if(!in_array($cmd, array('showDemoVersion', 'showDetails', 'addToShoppingCart')))
81 {
82 $cmd = ($_GET['purchasetype'] == 'demo' ? 'showDemoVersion' : 'showDetails');
83 }
84 break;
85 }
86 $this->$cmd();
87 return true;
88 }
89
90 public function showDemoVersion()
91 {
92 global $ilMainMenu, $ilTabs, $ilToolbar;
93
94 $this->__initPaymentObject();
95 $this->__initPricesObject();
97
98 $ilToolbar->addButton($this->lng->txt('payment_back_to_shop'),'ilias.php?baseClass=ilShopController');
99
100 $ilTabs->setTabActive('payment_demo');
101 $ilMainMenu->setActive('shop');
102 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.shop_abstract_details.html', 'Services/Payment');
103
104 $this->tpl->setVariable("DETAILS_FORMACTION",$this->ctrl->getFormAction($this));
105
106 if($this->object)
107 {
108 $icon = ilObject::_getIcon($this->object->getId());
109 $this->tpl->setVariable("TYPE_IMG", $icon);
110 $this->tpl->setVariable("ALT_IMG", $this->lng->txt('obj_'.$this->object->getType()));
111 $this->tpl->setVariable("TITLE", $this->object->getTitle());
112 }
113 else
114 {
115 $this->tpl->setVariable("TITLE",$this->lng->txt('object_not_found'));
116 }
117
118
119
120 // abstracts
121 if(($abstract_html = $this->__getAbstractHTML($this->pobject->getPobjectId())) != '')
122 {
123 $this->tpl->setCurrentBlock('abstract_block');
124 $this->tpl->setVariable('TXT_ABSTRACT', $this->lng->txt('pay_abstract'));
125 $this->tpl->setVariable('ABSTRACT_HTML', $abstract_html);
126 $this->tpl->parseCurrentBlock();
127 }
128
129 // public content ilias lm
130 global $ilObjDataCache;
131 if($ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($this->pobject->getRefId())) == 'lm')
132 {
133 include_once 'Modules/LearningModule/classes/class.ilShopPublicSectionSelector.php';
134 $exp = new ilShopPublicSectionSelector($this->ctrl->getLinkTarget($this, 'layout'),
135 ilObjectFactory::getInstanceByRefId($this->pobject->getRefId()), get_class($this));
136 $exp->setTargetGet('obj_id');
137 $exp->setOutput(0);
138 $output = $exp->getOutput();
139
140 if(trim($output) != '')
141 {
142
143 $this->tpl->setCurrentBlock('public_content_block');
144 $this->tpl->setVariable('TXT_CONTENT', $this->lng->txt('content'));
145 $this->tpl->setVariable('PUBLIC_CONTENT_HTML', $output);
146 $this->tpl->parseCurrentBlock();
147 }
148 }
149 else if($ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($this->pobject->getRefId())) == 'crs')
150 {
151 $oCourse = ilObjectFactory::getInstanceByRefId($this->pobject->getRefId());
152 $items = $oCourse->getSubItems();
153 $this->__getCourseItemsHTML($items);
154 }
155 }
156
157 private function getItemsByObjType($items, $type_group)
158 {
159 return is_array($items[$type_group]) ? $items[$type_group] : array();
160 }
161
162 private function __getCourseItemsHTML($container_items)
163 {
165
166 $output = false;
167
168 $tpl_sub_items = new ilTemplate('tpl.pay_purchase_demo_list_block.html', true, true, 'Services/Payment');
169
170 $objtype_groups = $objDefinition->getGroupedRepositoryObjectTypes(
171 array('cat', 'crs', 'grp', 'fold')
172 );
173
174 foreach($objtype_groups as $grp => $grpdata)
175 {
176// $title = $this->lng->txt('objs_'.$grp);
177 $items = $this->getItemsByObjType($container_items, $grp);
178
179 $item_html = array();
180 $rel_header = 'th_'.$grp;
181
182 if(count($items) > 0)
183 {
184 foreach($items as $item)
185 {
186 if($item['title'] != '')
187 {
188 $item_html[] = array(
189 'html' => $item['title'],
190 'item_ref_id' => $item['ref_id'],
191 'item_obj_id' => $item['obj_id']
192 );
193 }
194 }
195
196 // output block for resource type
197 if(count($item_html) > 0)
198 {
199 $output = true;
200
201 // add a header for each resource type
202 if($ilSetting->get('icon_position_in_lists') == 'item_rows')
203 {
204 $this->addHeaderRow($tpl_sub_items, $grp, false);
205 }
206 else
207 {
208 $this->addHeaderRow($tpl_sub_items, $grp);
209 }
210 $this->resetRowType();
211
212 // content row
213 foreach($item_html as $item)
214 {
215 if($ilSetting->get('icon_position_in_lists') == 'item_rows')
216 {
217 // BEGIN WebDAV: Use $item_list_gui to determine icon image type
218 $this->addStandardRow($tpl_sub_items, $item['html'], $item['item_obj_id'],
219 $item['item_icon_image_type'],
220 $rel_header);
221 // END WebDAV: Use $item_list_gui to determine icon image type
222 }
223 else
224 {
225 $this->addStandardRow($tpl_sub_items, $item['html'], $item['item_obj_id'], '', $rel_header);
226 }
227 }
228 }
229 }
230 }
231
232 if($output == true)
233 {
234 $this->tpl->setCurrentBlock('public_content_block');
235 $this->tpl->setVariable('TXT_CONTENT', $this->lng->txt('content'));
236 $this->tpl->setVariable('PUBLIC_CONTENT_HTML', $tpl_sub_items->get());
237 $this->tpl->parseCurrentBlock();
238 }
239 }
240
241 private function resetRowType()
242 {
243 $this->cur_row_type = "";
244 }
245
253 private function addHeaderRow($a_tpl, $a_type, $a_show_image = true)
254 {
255 $icon = ilObject::_getIcon($this->object->getId());
256 $title = $this->lng->txt("objs_".$a_type);
257 $header_id = "th_".$a_type;
258
259 if ($a_show_image)
260 {
261 $a_tpl->setCurrentBlock("container_header_row_image");
262 $a_tpl->setVariable("HEADER_IMG", $icon);
263 $a_tpl->setVariable("HEADER_ALT", $title);
264 }
265 else
266 {
267 $a_tpl->setCurrentBlock("container_header_row");
268 }
269
270 $a_tpl->setVariable("BLOCK_HEADER_CONTENT", $title);
271 $a_tpl->setVariable("BLOCK_HEADER_ID", $header_id);
272 $a_tpl->parseCurrentBlock();
273 $a_tpl->touchBlock("container_row");
274 }
275
283 private function addStandardRow(&$a_tpl, $a_html, $a_item_obj_id = "",
284 $a_image_type = "", $a_related_header = "")
285 {
286 global $ilSetting;
287
288 $this->cur_row_type = ($this->cur_row_type == "row_type_1")
289 ? "row_type_2"
290 : "row_type_1";
291 $a_tpl->touchBlock($this->cur_row_type);
292
293 if ($a_image_type != "")
294 {
295 if (!is_array($a_image_type) && !in_array($a_image_type, array("lm", "dbk", "htlm", "sahs")))
296 {
297 $icon = ilObject::_getIcon($this->object->getId());
298 $title = $this->lng->txt("obj_".$a_image_type);
299 }
300 else
301 {
302 $icon = ilObject::_getIcon($this->object->getId());
303 $title = $this->lng->txt("learning_resource");
304 }
305
306 // custom icon
307 if ($ilSetting->get("custom_icons") &&
308 in_array($a_image_type, array("cat","grp","crs")))
309 {
310 require_once("./Services/Container/classes/class.ilContainer.php");
311 if (($path = ilContainer::_lookupIconPath($a_item_obj_id, "small")) != "")
312 {
313 $icon = $path;
314 }
315 }
316
317 $a_tpl->setCurrentBlock("block_row_image");
318 $a_tpl->setVariable("ROW_IMG", $icon);
319 $a_tpl->setVariable("ROW_ALT", $title);
320 $a_tpl->parseCurrentBlock();
321 }
322 else
323 {
324 $a_tpl->setVariable("ROW_NBSP", "&nbsp;");
325 }
326 $a_tpl->setCurrentBlock("container_standard_row");
327 $a_tpl->setVariable("BLOCK_ROW_CONTENT", $a_html);
328 $rel_headers = ($a_related_header != "")
329 ? "th_selected_items ".$a_related_header
330 : "th_selected_items";
331 $a_tpl->setVariable("BLOCK_ROW_HEADERS", $rel_headers);
332 $a_tpl->parseCurrentBlock();
333 $a_tpl->touchBlock("container_row");
334 }
335
336 public function showDetails()
337 {
338 global $ilMainMenu, $ilTabs, $ilToolbar, $ilUser;
339
340 $this->__initPaymentObject();
341 $this->__initPricesObject();
343
344 $ilToolbar->addButton($this->lng->txt('payment_back_to_shop'),'ilias.php?baseClass=ilShopController');
345
346 $this->tpl->getStandardTemplate();
347 $ilTabs->setTabActive('buy');
348 $ilMainMenu->setActive('shop');
349
350 if($this->pobject->getStatus() == $this->pobject->STATUS_EXPIRES)
351 {
352 ilUtil::sendInfo($this->lng->txt('pay_expires_info'));
353 return false;
354 }
355
356 $extension_prices = array();
357
358 if($ilUser->getId() != ANONYMOUS_USER_ID)
359 {
360 include_once './Services/Payment/classes/class.ilPaymentBookings.php';
362 $ilUser->getId(), $this->pobject->getPobjectId());
363
364 if($has_extension_price)
365 {
366 $extension_prices = $this->price_obj->getExtensionPrices();
367 }
368 }
369
370 $org_prices = $this->price_obj->getPrices();
371 $tmp_prices = array_merge($org_prices, $extension_prices );
372
373 $prices = array();
374 foreach($tmp_prices as $price)
375 {
376 // expired prices must be filtered out
377 if($price['price_type'] == ilPaymentPrices::TYPE_DURATION_DATE && $price['duration_until'] < date('Y-m-d'))
378 {
379 //do nothing
380 }
381 else
382 {
383 $prices[] = $price;
384 }
385 }
386
387 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
388 $form = new ilPropertyFormGUI();
389 $form->setFormAction($this->ctrl->getFormAction($this));
390
391 $buyedObject = "";
392 if($this->sc_obj->isInShoppingCart($this->pobject->getPobjectId()))
393 {
394 $buyedObject = $this->sc_obj->getEntry($this->pobject->getPobjectId());
395 if (is_array($prices) &&
396 count($prices) > 1)
397 {
398 ilUtil::sendInfo($this->lng->txt('pay_item_already_in_sc_choose_another'));
399 }
400 else
401 {
402 ilUtil::sendInfo($this->lng->txt('pay_item_already_in_sc'));
403 }
404 }
405
406 $this->ctrl->setParameter($this, "ref_id", $this->pobject->getRefId());
407 $subtype = '';
408 if($this->object)
409 {
410 if($this->object->getType() == 'exc')
411 {
412 $subtype = ' ('.$this->lng->txt($this->pobject->getSubtype()).')';
413 }
414
415 $form->setTitle($this->object->getTitle().' '.$subtype);
416 $form->setTitleIcon(ilObject::_getIcon($this->object->getId()));
417 }
418 else
419 {
420 ilUtil::sendFailure($this->lng->txt('object_not_found'));
421 }
422 // payment infos
423 $info = new ilNonEditableValueGUI($this->lng->txt('info'));
424 $info->setValue($this->lng->txt('pay_info'));
425 $form->addItem($info);
426
427 if (is_array($buyedObject))
428 {
429 if (is_array($prices) && count($prices) > 1)
430 {
431 $button_txt = $this->lng->txt('pay_change_price');
432 }
433 else
434 {
435 $button_txt = $this->lng->txt('pay_add_to_shopping_cart');
436 }
437 }
438 else
439 {
440 $button_txt = $this->lng->txt('pay_add_to_shopping_cart');
441 }
442
443 $rg_prices = new ilRadioGroupInputGUI($this->lng->txt('prices'), 'price_id');
444
445 if (is_array($prices))
446 {
447 foreach($prices as $price)
448 {
449 if (is_array($buyedObject) && $buyedObject["price_id"] == $price['price_id'])
450 {
451 $rg_prices->setValue($price['price_id']);
452 }
453 else if (count($prices) == 1)
454 {
455 $rg_prices->setValue($price['price_id']);
456 }
457
458 switch($price['price_type'])
459 {
461 $txt_price = $price['duration'].' '.$this->lng->txt('paya_months').': ';
462 break;
464 $txt_price = ilDatePresentation::formatDate(new ilDate($price['duration_from'], IL_CAL_DATE))
465 .' - '.ilDatePresentation::formatDate(new ilDate($price['duration_until'], IL_CAL_DATE)).': ';
466 break;
468 $txt_price = $this->lng->txt('unlimited_duration').': ';
469 break;
470 }
471
472 $tmp_price = $price['price'];
473
474 $extension_txt = '';
475 if($price['extension'] == 1)
476 {
477 $extension_txt = '(' . $this->lng->txt('extension_price') . ')';
478 }
479
480 $price_row = new ilRadioOption($txt_price .' '. ilPaymentPrices::_formatPriceToString((float)$tmp_price).' '.$extension_txt, $price['price_id'] );
481 $price_row->setInfo($price['description']);
482
483 $rg_prices->addOption($price_row);
484 }
485 $form->addItem($rg_prices);
486 }
487
488 $form->addCommandButton('addToShoppingCart', $button_txt );
489 return $this->tpl->setContent($form->getHTML());
490 }
491
492 private function __getAbstractHTML($a_payment_object_id)
493 {
494 // page object
495 include_once 'Services/Payment/classes/class.ilShopPage.php';
496 include_once 'Services/Payment/classes/class.ilShopPageGUI.php';
497
498 // if page does not exist, return nothing
499 if(!ilShopPage::_exists('shop', $a_payment_object_id))
500 {
501 return '';
502 }
503
504 include_once 'Services/Style/classes/class.ilObjStyleSheet.php';
505 // get page object
506 $page_gui = new ilShopPageGUI($a_payment_object_id);
507
508 return $page_gui->showPage();
509 }
510
511 public function addToShoppingCart()
512 {
513 global $ilTabs;
514
515 $ilTabs->setTabActive('buy');
516
517 if(!isset($_POST['price_id']))
518 {
519 ilUtil::sendInfo($this->lng->txt('pay_select_price'));
520 $this->showDetails();
521
522 return true;
523 }
524 else
525 {
526 $this->__initPaymentObject();
527
529
530 $this->sc_obj->setSessionId(session_id());
531 $this->sc_obj->setPriceId((int) $_POST['price_id']);
532 $this->sc_obj->setPobjectId($this->pobject->getPobjectId());
533 $this->sc_obj->add();
534
535 ilUtil::redirect('ilias.php?baseClass=ilShopController&cmd=redirect&redirect_class=ilshopshoppingcartgui');
536
537 return true;
538 }
539 }
540
541 // PRIVATE
542 private function __initShoppingCartObject()
543 {
544 global $ilUser;
545 include_once './Services/Payment/classes/class.ilPaymentShoppingCart.php';
546 $this->sc_obj = new ilPaymentShoppingCart($ilUser);
547 return true;
548 }
549
550 private function __initPaymentObject()
551 {
552 global $ilUser;
553 $this->pobject = new ilPaymentObject($ilUser ,ilPaymentObject::_lookupPobjectId($this->ref_id));
554 return true;
555 }
556 private function __initPricesObject()
557 {
558 include_once './Services/Payment/classes/class.ilPaymentPrices.php';
559 $this->price_obj = new ilPaymentPrices($this->pobject->getPobjectId());
560 return true;
561 }
562
563}
564?>
$_GET["client_id"]
const IL_CAL_DATE
_lookupIconPath($a_id, $a_size="big")
lookup icon path
static formatDate(ilDateTime $date)
Format a date @access public.
Class for single dates.
This class represents a non editable value in a property form.
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
Class ilObjectGUI Basic methods of all Output classes.
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 _hasAccesstoExtensionPrice($a_user_id, $a_pobject_id)
static _lookupPobjectId($a_ref_id)
static _formatPriceToString($a_price)
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.
Shop page GUI class.
Class ilShopPurchaseGUI.
addStandardRow(&$a_tpl, $a_html, $a_item_obj_id="", $a_image_type="", $a_related_header="")
adds a standard row to a block template
__getCourseItemsHTML($container_items)
addHeaderRow($a_tpl, $a_type, $a_show_image=true)
adds a header row to a block template
executeCommand()
execute command
__getAbstractHTML($a_payment_object_id)
getItemsByObjType($items, $type_group)
special template class to simplify handling of ITX/PEAR
static redirect($a_script)
http redirect to other script
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$_POST['username']
Definition: cron.php:12
$info
Definition: example_052.php:80
global $ilCtrl
Definition: ilias.php:18
global $ilSetting
Definition: privfeed.php:40
$cmd
Definition: sahs_server.php:35
$path
Definition: index.php:22
global $ilUser
Definition: imgupload.php:15