ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
4 require_once "./classes/class.ilObjectGUI.php";
5 
16 {
17  var $ctrl;
18  var $ilias;
19  var $lng;
20  var $tpl;
21 
22  var $object = null;
23 
24  public function __construct($a_ref_id)
25  {
27 
28  $this->ctrl = $ilCtrl;
29  $this->ctrl->saveParameter($this, array("ref_id"));
30 
31  $this->ilErr = $ilErr;
32  $this->ilias = $ilias;
33 
34  $this->lng = $lng;
35  $this->lng->loadLanguageModule('payment');
36 
37  $this->tpl = $tpl;
38 
39  $this->ref_id = $a_ref_id;
40 
41  $this->object = ilObjectFactory::getInstanceByRefId($this->ref_id, false);
42 
43  global $ilTabs;
44 
45  $ilTabs->clearTargets();
46  $ilTabs->addTarget('buy', $this->ctrl->getLinkTarget($this, 'showDetails').'&purchasetype=buy');
47  $ilTabs->addTarget('payment_demo', $this->ctrl->getLinkTarget($this, 'showDemoVersion').'&purchasetype=demo');
48 
49  $this->ctrl->setParameter($this, 'purchasetype', ($_GET['purchasetype'] == 'demo' ? 'demo' : 'buy'));
50  }
51 
55  public function executeCommand()
56  {
57  $cmd = $this->ctrl->getCmd();
58  switch($this->ctrl->getCmdClass())
59  {
60  case 'ilpageobjectgui':
61  $this->__initPaymentObject();
62  include_once 'Services/Style/classes/class.ilObjStyleSheet.php';
63  include_once 'Services/COPage/classes/class.ilPageObjectGUI.php';
64  $page_gui = new ilPageObjectGUI('shop', $this->pobject->getPobjectId());
65  $this->ctrl->forwardCommand($page_gui);
66  return;
67  break;
68  }
69 
70  $this->__buildHeader();
71 
72  switch($cmd)
73  {
74  case 'addToShoppingCart':
75  break;
76 
77  default:
78  if(!in_array($cmd, array('showDemoVersion', 'showDetails', 'addToShoppingCart')))
79  {
80  $cmd = ($_GET['purchasetype'] == 'demo' ? 'showDemoVersion' : 'showDetails');
81  }
82  break;
83  }
84  $this->$cmd();
85  return true;
86  }
87 
88  public function showDemoVersion()
89  {
90  global $ilMainMenu, $ilTabs, $tpl, $ilToolbar;
91 
92  $this->__initPaymentObject();
93  $this->__initPricesObject();
94  $this->__initShoppingCartObject();
95 
96  $ilToolbar->addButton($this->lng->txt('payment_back_to_shop'),'ilias.php?baseClass=ilShopController');
97 
98  $ilTabs->setTabActive('payment_demo');
99  $ilMainMenu->setActive('shop');
100  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.shop_abstract_details.html', 'Services/Payment');
101 
102  $this->tpl->setVariable("DETAILS_FORMACTION",$this->ctrl->getFormAction($this));
103  $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_'.$this->object->getType().'_b.gif'));
104  $this->tpl->setVariable("ALT_IMG",$this->lng->txt('obj_'.$this->object->getType()));
105  $this->tpl->setVariable("TITLE",$this->object->getTitle());
106 
107  // abstracts
108  if(($abstract_html = $this->__getAbstractHTML($this->pobject->getPobjectId())) != '')
109  {
110  $this->tpl->setCurrentBlock('abstract_block');
111  $this->tpl->setVariable('TXT_ABSTRACT', $this->lng->txt('pay_abstract'));
112  $this->tpl->setVariable('ABSTRACT_HTML', $abstract_html.$output);
113  $this->tpl->parseCurrentBlock();
114  }
115 
116  // public content ilias lm
117  global $ilObjDataCache;
118  if($ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($this->pobject->getRefId())) == 'lm')
119  {
120  include_once 'Modules/LearningModule/classes/class.ilShopPublicSectionSelector.php';
121  $exp = new ilShopPublicSectionSelector($this->ctrl->getLinkTarget($this, 'layout'),
122  ilObjectFactory::getInstanceByRefId($this->pobject->getRefId()), get_class($this));
123  $exp->setTargetGet('obj_id');
124  $exp->setOutput(0);
125  $output = $exp->getOutput();
126 
127  if(trim($output) != '')
128  {
129 
130  $this->tpl->setCurrentBlock('public_content_block');
131  $this->tpl->setVariable('TXT_CONTENT', $this->lng->txt('content'));
132  $this->tpl->setVariable('PUBLIC_CONTENT_HTML', $output);
133  $this->tpl->parseCurrentBlock();
134  }
135  }
136  else if($ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($this->pobject->getRefId())) == 'crs')
137  {
138  $oCourse = ilObjectFactory::getInstanceByRefId($this->pobject->getRefId());
139  $items = $oCourse->getSubItems();
140  $this->__getCourseItemsHTML($items);
141  }
142  }
143 
144  private function getItemsByObjType($items, $type_group)
145  {
146  return is_array($items[$type_group]) ? $items[$type_group] : array();
147  }
148 
149  private function __getCourseItemsHTML($container_items)
150  {
151  global $ilUser, $rbacsystem, $objDefinition, $ilSetting, $ilObjDataCache;
152 
153  $output = false;
154 
155  $tpl_sub_items = new ilTemplate('tpl.pay_purchase_demo_list_block.html', true, true, 'Services/Payment');
156 
157  $objtype_groups = $objDefinition->getGroupedRepositoryObjectTypes(
158  array('cat', 'crs', 'grp', 'fold')
159  );
160 
161  foreach($objtype_groups as $grp => $grpdata)
162  {
163  $title = $this->lng->txt('objs_'.$grp);
164  $items = $this->getItemsByObjType($container_items, $grp);
165 
166  $item_html = array();
167  $rel_header = 'th_'.$grp;
168 
169  if(count($items) > 0)
170  {
171  foreach($items as $item)
172  {
173  if($item['title'] != '')
174  {
175  $item_html[] = array(
176  'html' => $item['title'],
177  'item_ref_id' => $item['ref_id'],
178  'item_obj_id' => $item['obj_id']
179  );
180  }
181  }
182 
183  // output block for resource type
184  if(count($item_html) > 0)
185  {
186  $output = true;
187 
188  // add a header for each resource type
189  if($ilSetting->get('icon_position_in_lists') == 'item_rows')
190  {
191  $this->addHeaderRow($tpl_sub_items, $grp, false);
192  }
193  else
194  {
195  $this->addHeaderRow($tpl_sub_items, $grp);
196  }
197  $this->resetRowType();
198 
199  // content row
200  foreach($item_html as $item)
201  {
202  if($ilSetting->get('icon_position_in_lists') == 'item_rows')
203  {
204  // BEGIN WebDAV: Use $item_list_gui to determine icon image type
205  $this->addStandardRow($tpl_sub_items, $item['html'], $item['item_ref_id'], $item['item_obj_id'],
206  $item['item_icon_image_type'],
207  $rel_header);
208  // END WebDAV: Use $item_list_gui to determine icon image type
209  }
210  else
211  {
212  $this->addStandardRow($tpl_sub_items, $item['html'], $item['item_ref_id'], $item['item_obj_id'], '', $rel_header);
213  }
214  }
215  }
216  }
217  }
218 
219  if($output == true)
220  {
221  $this->tpl->setCurrentBlock('public_content_block');
222  $this->tpl->setVariable('TXT_CONTENT', $this->lng->txt('content'));
223  $this->tpl->setVariable('PUBLIC_CONTENT_HTML', $tpl_sub_items->get());
224  $this->tpl->parseCurrentBlock();
225  }
226  }
227 
228  private function resetRowType()
229  {
230  $this->cur_row_type = "";
231  }
232 
240  private function addHeaderRow($a_tpl, $a_type, $a_show_image = true)
241  {
242  $icon = ilUtil::getImagePath("icon_".$a_type.".gif");
243  $title = $this->lng->txt("objs_".$a_type);
244  $header_id = "th_".$a_type;
245 
246  if ($a_show_image)
247  {
248  $a_tpl->setCurrentBlock("container_header_row_image");
249  $a_tpl->setVariable("HEADER_IMG", $icon);
250  $a_tpl->setVariable("HEADER_ALT", $title);
251  }
252  else
253  {
254  $a_tpl->setCurrentBlock("container_header_row");
255  }
256 
257  $a_tpl->setVariable("BLOCK_HEADER_CONTENT", $title);
258  $a_tpl->setVariable("BLOCK_HEADER_ID", $header_id);
259  $a_tpl->parseCurrentBlock();
260  $a_tpl->touchBlock("container_row");
261  }
262 
270  private function addStandardRow(&$a_tpl, $a_html, $a_item_ref_id = "", $a_item_obj_id = "",
271  $a_image_type = "", $a_related_header = "")
272  {
273  global $ilSetting;
274 
275  $this->cur_row_type = ($this->cur_row_type == "row_type_1")
276  ? "row_type_2"
277  : "row_type_1";
278  $a_tpl->touchBlock($this->cur_row_type);
279 
280  if ($a_image_type != "")
281  {
282  if (!is_array($a_image_type) && !in_array($a_image_type, array("lm", "dbk", "htlm", "sahs")))
283  {
284  $icon = ilUtil::getImagePath("icon_".$a_image_type.".gif");
285  $title = $this->lng->txt("obj_".$a_image_type);
286  }
287  else
288  {
289  $icon = ilUtil::getImagePath("icon_lm.gif");
290  $title = $this->lng->txt("learning_resource");
291  }
292 
293  // custom icon
294  if ($ilSetting->get("custom_icons") &&
295  in_array($a_image_type, array("cat","grp","crs")))
296  {
297  require_once("./Services/Container/classes/class.ilContainer.php");
298  if (($path = ilContainer::_lookupIconPath($a_item_obj_id, "small")) != "")
299  {
300  $icon = $path;
301  }
302  }
303 
304  $a_tpl->setCurrentBlock("block_row_image");
305  $a_tpl->setVariable("ROW_IMG", $icon);
306  $a_tpl->setVariable("ROW_ALT", $title);
307  $a_tpl->parseCurrentBlock();
308  }
309  else
310  {
311  $a_tpl->setVariable("ROW_NBSP", "&nbsp;");
312  }
313  $a_tpl->setCurrentBlock("container_standard_row");
314  $a_tpl->setVariable("BLOCK_ROW_CONTENT", $a_html);
315  $rel_headers = ($a_related_header != "")
316  ? "th_selected_items ".$a_related_header
317  : "th_selected_items";
318  $a_tpl->setVariable("BLOCK_ROW_HEADERS", $rel_headers);
319  $a_tpl->parseCurrentBlock();
320  $a_tpl->touchBlock("container_row");
321  }
322 
323  public function showDetails()
324  {
325  global $ilMainMenu, $ilTabs, $ilToolbar;
326 
327  $ilTabs->setTabActive('buy');
328 
329  $ilMainMenu->setActive('shop');
330 
331  $this->__initPaymentObject();
332  $this->__initPricesObject();
333  $this->__initShoppingCartObject();
334 
335  $ilToolbar->addButton($this->lng->txt('payment_back_to_shop'),'ilias.php?baseClass=ilShopController');
336 
337  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.pay_purchase_details.html', 'Services/Payment');
338 
339  if($this->pobject->getStatus() == $this->pobject->STATUS_EXPIRES)
340  {
341  ilUtil::sendInfo($this->lng->txt('pay_expires_info'));
342 
343  return false;
344  }
345 
346  $prices = $this->price_obj->getPrices();
347  $buyedObject = "";
348  if($this->sc_obj->isInShoppingCart($this->pobject->getPobjectId()))
349  {
350  $buyedObject = $this->sc_obj->getEntry($this->pobject->getPobjectId());
351  if (is_array($prices) &&
352  count($prices) > 1)
353  {
354  ilUtil::sendInfo($this->lng->txt('pay_item_already_in_sc_choose_another'));
355  }
356  else
357  {
358  ilUtil::sendInfo($this->lng->txt('pay_item_already_in_sc'));
359  }
360 
361  $this->tpl->setCurrentBlock("shopping_cart");
362 
363 
364  $this->tpl->setVariable("LINK_GOTO_SHOPPING_CART",'ilias.php?baseClass=ilShopController&cmd=redirect&redirect_class=ilShopShoppingCartGUI');
365  $this->tpl->setVariable("TXT_GOTO_SHOPPING_CART", $this->lng->txt('pay_goto_shopping_cart'));
366  $this->tpl->parseCurrentBlock("shopping_cart");
367  }
368 
369  $this->ctrl->setParameter($this, "ref_id", $this->pobject->getRefId());
370  if($this->object)
371  {
372  $this->tpl->setVariable("DETAILS_FORMACTION",$this->ctrl->getFormAction($this));
373  $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_'.$this->object->getType().'_b.gif'));
374  $this->tpl->setVariable("ALT_IMG",$this->lng->txt('obj_'.$this->object->getType()));
375  $this->tpl->setVariable("TITLE",$this->object->getTitle().' '.$subtype);
376  }
377  else
378  {
379  $this->tpl->setVariable("DETAILS_FORMACTION",$this->ctrl->getFormAction($this));
380  $this->tpl->setVariable("TITLE",$this->lng->txt('object_not_found'));
381  }
382  // payment infos
383  $this->tpl->setVariable("TXT_INFO",$this->lng->txt('info'));
384 
385  $this->tpl->setVariable("INFO_PAY",$this->lng->txt('pay_info'));
386  if (is_array($buyedObject))
387  {
388  if (is_array($prices) && count($prices) > 1)
389  {
390  $this->tpl->setVariable("INPUT_CMD",'addToShoppingCart');
391  $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_change_price'));
392  }
393  }
394  else
395  {
396  $this->tpl->setVariable("INPUT_CMD",'addToShoppingCart');
397  $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_add_to_shopping_cart'));
398  }
399 
400  $this->tpl->setVariable("ROWSPAN",count($prices));
401  $this->tpl->setVariable("TXT_PRICES",$this->lng->txt('prices'));
402 
403  if (is_array($prices))
404  {
405  $counter = 0;
406  foreach($prices as $price)
407  {
408  if ($counter == 0)
409  {
410  $placeholderCheckbox = "CHECKBOX";
411  $placeholderDuration = "DURATION";
412  $placeholderPrice = "PRICE";
413  }
414  else
415  {
416  $placeholderCheckbox = "ROW_CHECKBOX";
417  $placeholderDuration = "ROW_DURATION";
418  $placeholderPrice = "ROW_PRICE";
419  }
420  $this->tpl->setCurrentBlock("price_row");
421  if ($buyedObject["price_id"] == $price['price_id'])
422  {
423  $this->tpl->setVariable($placeholderCheckbox,ilUtil::formRadioButton(1,'price_id',$price['price_id']));
424  }
425  else if (count($prices) == 1)
426  {
427  $this->tpl->setVariable($placeholderCheckbox,ilUtil::formRadioButton(1,'price_id',$price['price_id']));
428  }
429  else
430  {
431  $this->tpl->setVariable($placeholderCheckbox,ilUtil::formRadioButton(0,'price_id',$price['price_id']));
432  }
433 
434  if($price['unlimited_duration'] == '1')
435  {
436 
437  $this->tpl->setVariable($placeholderDuration, ''. $this->lng->txt('unlimited_duration'). ': ');
438  }
439  else
440  $this->tpl->setVariable($placeholderDuration,$price['duration'].' '.$this->lng->txt('paya_months'). ': ');
441 
442  $tmp_price = ilPaymentPrices::_getPriceString($price['price_id']);
443  $this->tpl->setVariable($placeholderPrice,ilPaymentPrices::_formatPriceToString($tmp_price));
444 
445  $this->tpl->parseCurrentBlock();
446  $counter++;
447  }
448  }
449  }
450 
451  private function __getAbstractHTML($a_payment_object_id)
452  {
453  // page object
454  include_once 'Services/COPage/classes/class.ilPageObject.php';
455  include_once 'Services/COPage/classes/class.ilPageObjectGUI.php';
456 
457  // if page does not exist, return nothing
458  if(!ilPageObject::_exists('shop', $a_payment_object_id))
459  {
460  return '';
461  }
462 
463  include_once 'Services/Style/classes/class.ilObjStyleSheet.php';
464  // get page object
465  $page_gui = new ilPageObjectGUI('shop', $a_payment_object_id);
466  $page_gui->setIntLinkHelpDefault('StructureObject', $a_payment_object_id);
467  $page_gui->setLinkXML('');
468  $page_gui->setFileDownloadLink($this->ctrl->getLinkTargetByClass('ilPageObjectGUI', 'downloadFile'));
469  $page_gui->setFullscreenLink($this->ctrl->getLinkTargetByClass('ilPageObjectGUI', 'displayMediaFullscreen'));
470  $page_gui->setSourcecodeDownloadScript($this->ctrl->getLinkTargetByClass('ilPageObjectGUI', 'download_paragraph'));
471  $page_gui->setPresentationTitle('');
472  $page_gui->setTemplateOutput(false);
473  $page_gui->setHeader('');
474  $page_gui->setEnabledRepositoryObjects(false);
475  $page_gui->setEnabledFileLists(false);
476  $page_gui->setEnabledPCTabs(true);
477  $page_gui->setEnabledMaps(true);
478 
479  return $page_gui->showPage();
480  }
481 
482  public function addToShoppingCart()
483  {
484  global $ilTabs;
485 
486  $ilTabs->setTabActive('buy');
487 
488  if(!isset($_POST['price_id']))
489  {
490  ilUtil::sendInfo($this->lng->txt('pay_select_price'));
491  $this->showDetails();
492 
493  return true;
494  }
495  else
496  {
497  $this->__initPaymentObject();
498 
499  $this->__initShoppingCartObject();
500 
501  $this->sc_obj->setSessionId(session_id());
502  $this->sc_obj->setPriceId((int) $_POST['price_id']);
503  $this->sc_obj->setPobjectId($this->pobject->getPobjectId());
504  $this->sc_obj->add();
505 
506  ilUtil::redirect('ilias.php?baseClass=ilShopController&cmd=redirect&redirect_class=ilshopshoppingcartgui');
507 
508  return true;
509  }
510  }
511 
512  // PRIVATE
514  {
515  include_once './Services/Payment/classes/class.ilPaymentShoppingCart.php';
516  $this->sc_obj = new ilPaymentShoppingCart($this->ilias->account);
517  return true;
518  }
519 
521  {
522  include_once './Services/Payment/classes/class.ilPaymentObject.php';
523  $this->pobject = new ilPaymentObject($this->ilias->account,ilPaymentObject::_lookupPobjectId($this->ref_id));
524  return true;
525  }
527  {
528  include_once './Services/Payment/classes/class.ilPaymentPrices.php';
529  $this->price_obj = new ilPaymentPrices($this->pobject->getPobjectId());
530  return true;
531  }
532 
533  function __buildHeader()
534  {
535  $this->tpl->addBlockFile("CONTENT", "content", "tpl.payb_content.html");
536  $this->tpl->setVariable("HEADER",$this->object->getTitle());
537  $this->tpl->setVariable("DESCRIPTION",$this->object->getDescription());
538  }
539 
540  function __buildStatusline()
541  {
542  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
543  $this->__buildLocator();
544  }
545 
546  function __buildLocator()
547  {
548  $this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html", "Services/Locator");
549  $this->tpl->setVariable("TXT_LOCATOR",$this->lng->txt("locator"));
550 
551  $this->tpl->setCurrentBlock("locator_item");
552  $this->tpl->setVariable("ITEM", $this->lng->txt("repository"));
553  $this->tpl->setVariable("LINK_ITEM", "../repository.php?getlast=true");
554  $this->tpl->parseCurrentBlock();
555 
556  // CHECK for new mail and info
558 
559  return true;
560  }
561 
562  function __buildStylesheet()
563  {
564  $this->tpl->setVariable("LOCATION_STYLESHEET",ilUtil::getStyleSheetLocation());
565  }
566 }
567 ?>