ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPaymentPurchaseGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
35 require_once "./classes/class.ilObjectGUI.php";
36 
38 {
39  var $ctrl;
40  var $ilias;
41  var $lng;
42  var $tpl;
43 
44  var $object = null;
45 
46  function ilPaymentPurchaseGUI($a_ref_id)
47  {
49 
50  $this->ctrl =& $ilCtrl;
51  $this->ctrl->saveParameter($this,array("ref_id"));
52 
53  $this->ilErr =& $ilErr;
54  $this->ilias =& $ilias;
55 
56  $this->lng =& $lng;
57  $this->lng->loadLanguageModule('payment');
58 
59  $this->tpl =& $tpl;
60 
61  $this->ref_id = $a_ref_id;
62 
63  $this->object =& ilObjectFactory::getInstanceByRefId($this->ref_id, false);
64  }
65 
69  function &executeCommand()
70  {
71  $cmd = $this->ctrl->getCmd();
72 
73  if (!$cmd = $this->ctrl->getCmd())
74  {
75  $cmd = "showDetails";
76  }
77 
78  $this->__buildHeader();
79 
80  $this->$cmd();
81  }
82 
83  function showDetails()
84  {
85  if($this->object)
86  {
87  if($this->object->getType() == 'crs' && $this->object->isSubscriptionMembershipLimited())
88  {
89  $this->object->initCourseMemberObject();
90 
91  if($this->object->getSubscriptionMaxMembers() <= $this->object->members_obj->getCountMembers())
92  {
93  ilUtil::sendInfo($this->lng->txt('pay_crs_max_members_exceeded'));
94  return false;
95  }
96  }
97  }
98  else
99  {
100  ilUtil::sendInfo($this->lng->txt('object_not_found'));
101  }
102  $this->__initPaymentObject();
103  $this->__initPricesObject();
104  $this->__initShoppingCartObject();
105 
106  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.pay_purchase_details.html','payment');
107 
108  if($this->pobject->getStatus() == $this->pobject->STATUS_EXPIRES)
109  {
110  ilUtil::sendInfo($this->lng->txt('pay_expires_info'));
111 
112  return false;
113  }
114 
115  $prices = $this->price_obj->getPrices();
116  $buyedObject = "";
117  if($this->sc_obj->isInShoppingCart($this->pobject->getPobjectId()))
118  {
119  $buyedObject = $this->sc_obj->getEntry($this->pobject->getPobjectId());
120  if (is_array($prices) &&
121  count($prices) > 1)
122  {
123  ilUtil::sendInfo($this->lng->txt('pay_item_already_in_sc_choose_another'));
124  }
125  else
126  {
127  ilUtil::sendInfo($this->lng->txt('pay_item_already_in_sc'));
128  }
129 
130  $this->tpl->setCurrentBlock("shopping_cart");
131  $this->tpl->setVariable("LINK_GOTO_SHOPPING_CART", "ilias.php?cmdClass=ilpaymentgui&baseClass=ilPersonalDesktopGUI&cmd=showShoppingCart");
132  $this->tpl->setVariable("TXT_GOTO_SHOPPING_CART", $this->lng->txt('pay_goto_shopping_cart'));
133 # $this->tpl->setVariable("TXT_BUY", $this->lng->txt('pay_click_to_buy'));
134  $this->tpl->parseCurrentBlock("shopping_cart");
135  }
136 
137  $this->ctrl->setParameter($this, "ref_id", $this->pobject->getRefId());
138 
139 # if (!is_array($buyedObject) ||
140 # (is_array($buyedObject) && is_array($prices) && count($prices) > 1))
141 # {
142  $this->tpl->setVariable("DETAILS_FORMACTION",$this->ctrl->getFormAction($this));
143  if($this->object)
144  {
145  $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_'.$this->object->getType().'_b.gif'));
146  $this->tpl->setVariable("ALT_IMG",$this->lng->txt('obj_'.$this->object->getType()));
147  $this->tpl->setVariable("TITLE",$this->object->getTitle());
148  }
149  else
150  {
151  $this->tpl->setVariable("TITLE",$this->lng->txt('object_not_found'));
152  }
153  // payment infos
154  $this->tpl->setVariable("TXT_INFO",$this->lng->txt('info'));
155  switch($this->pobject->getPayMethod())
156  {
157 /* case $this->pobject->PAY_METHOD_BILL:
158  $this->tpl->setVariable("INFO_PAY",$this->lng->txt('pay_bill'));
159  $this->tpl->setVariable("INPUT_CMD",'getBill');
160  $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_get_bill'));
161  break;
162 */
163  case $this->pobject->PAY_METHOD_BILL:
164  $this->tpl->setVariable("INFO_PAY",$this->lng->txt('pay_info'));
165  if (is_array($buyedObject))
166  {
167  if (is_array($prices) && count($prices) > 1)
168  {
169  $this->tpl->setVariable("INPUT_CMD",'addToShoppingCart');
170  $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_change_price'));
171  }
172  }
173  else
174  {
175  $this->tpl->setVariable("INPUT_CMD",'addToShoppingCart');
176  $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_add_to_shopping_cart'));
177  }
178  break;
179 
180  case $this->pobject->PAY_METHOD_BMF:
181  $this->tpl->setVariable("INFO_PAY",$this->lng->txt('pay_info'));
182  if (is_array($buyedObject))
183  {
184  if (is_array($prices) && count($prices) > 1)
185  {
186  $this->tpl->setVariable("INPUT_CMD",'addToShoppingCart');
187  $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_change_price'));
188  }
189  }
190  else
191  {
192  $this->tpl->setVariable("INPUT_CMD",'addToShoppingCart');
193  $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_add_to_shopping_cart'));
194  }
195  break;
196 
197  case $this->pobject->PAY_METHOD_PAYPAL:
198  $this->tpl->setVariable("INFO_PAY",$this->lng->txt('pay_info'));
199  if (is_array($buyedObject))
200  {
201  if (is_array($prices) && count($prices) > 1)
202  {
203  $this->tpl->setVariable("INPUT_CMD",'addToShoppingCart');
204  $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_change_price'));
205  }
206  }
207  else
208  {
209  $this->tpl->setVariable("INPUT_CMD",'addToShoppingCart');
210  $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_add_to_shopping_cart'));
211  }
212  break;
213 
214  case $this->pobject->PAY_METHOD_EPAY:
215  $this->tpl->setVariable("INFO_PAY",$this->lng->txt('pay_info'));
216  if (is_array($buyedObject))
217  {
218  if (is_array($prices) && count($prices) > 1)
219  {
220  $this->tpl->setVariable("INPUT_CMD",'addToShoppingCart');
221  $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_change_price'));
222  }
223  }
224  else
225  {
226  $this->tpl->setVariable("INPUT_CMD",'addToShoppingCart');
227  $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_add_to_shopping_cart'));
228  }
229  break;
230  }
231 
232  $this->tpl->setVariable("ROWSPAN",count($prices));
233  $this->tpl->setVariable("TXT_PRICES",$this->lng->txt('prices'));
234 # }
235 
236  if (is_array($prices))
237  {
238 # if (count($prices) > 1)
239 # {
240  $counter = 0;
241  foreach($prices as $price)
242  {
243  if ($counter == 0)
244  {
245  $placeholderCheckbox = "CHECKBOX";
246  $placeholderDuration = "DURATION";
247  $placeholderPrice = "PRICE";
248  }
249  else
250  {
251  $placeholderCheckbox = "ROW_CHECKBOX";
252  $placeholderDuration = "ROW_DURATION";
253  $placeholderPrice = "ROW_PRICE";
254  }
255  $this->tpl->setCurrentBlock("price_row");
256  if ($buyedObject["price_id"] == $price['price_id'])
257  {
258  $this->tpl->setVariable($placeholderCheckbox,ilUtil::formRadioButton(1,'price_id',$price['price_id']));
259  }
260  else
261  {
262  $this->tpl->setVariable($placeholderCheckbox,ilUtil::formRadioButton(0,'price_id',$price['price_id']));
263  }
264  $this->tpl->setVariable($placeholderDuration,$price['duration'].' '.$this->lng->txt('paya_months'));
265  $this->tpl->setVariable($placeholderPrice,ilPaymentPrices::_getPriceString($price['price_id']));
266  $this->tpl->parseCurrentBlock();
267  $counter++;
268  }
269 # }
270 # else if (!is_array($buyedObject))
271 # {
272 # foreach($prices as $price)
273 # {
274 # $this->tpl->setVariable("CHECKBOX",ilUtil::formRadioButton(0,'price_id',$price['price_id']));
275 # $this->tpl->setVariable("DURATION",$price['duration'].' '.$this->lng->txt('paya_months'));
276 # $this->tpl->setVariable("PRICE",ilPaymentPrices::_getPriceString($price['price_id']));
277 # }
278 # }
279  }
280 
281  }
282 
283  function addToShoppingCart()
284  {
285  if($this->object->getType() == 'crs' && $this->object->isSubscriptionMembershipLimited())
286  {
287  $this->object->initCourseMemberObject();
288 
289  if($this->object->getSubscriptionMaxMembers() <= $this->object->members_obj->getCountMembers())
290  {
291  ilUtil::sendInfo($this->lng->txt('pay_crs_max_members_exceeded'));
292  return false;
293  }
294  }
295 
296  if(!isset($_POST['price_id']))
297  {
298  ilUtil::sendInfo($this->lng->txt('pay_select_price'));
299  $this->showDetails();
300 
301  return true;
302  }
303  else
304  {
305  $this->__initPaymentObject();
306  $this->__initShoppingCartObject();
307 
308 
309  $this->sc_obj->setPriceId((int) $_POST['price_id']);
310  $this->sc_obj->setPobjectId($this->pobject->getPobjectId());
311  $this->sc_obj->add();
312 
313 # $tmp_obj =& ilObjectFactory::getInstanceByRefId($this->pobject->getRefId());
314 
315  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.pay_purchase_details.html','payment');
316  $this->tpl->setCurrentBlock("shopping_cart");
317  $this->tpl->setVariable("LINK_GOTO_SHOPPING_CART", "ilias.php?cmdClass=ilpaymentgui&baseClass=ilPersonalDesktopGUI&cmd=showShoppingCart");
318  $this->tpl->setVariable("TXT_GOTO_SHOPPING_CART", $this->lng->txt('pay_goto_shopping_cart'));
319 # $this->tpl->setVariable("TXT_BUY", $this->lng->txt('pay_click_to_buy'));
320  $this->tpl->parseCurrentBlock("shopping_cart");
321 
322  ilUtil::sendInfo($this->lng->txt('pay_added_to_shopping_cart'));
323 
324  return true;
325  }
326  }
327 
328  // PRIVATE
330  {
331  include_once './payment/classes/class.ilPaymentShoppingCart.php';
332 
333  $this->sc_obj =& new ilPaymentShoppingCart($this->ilias->account);
334 
335  return true;
336  }
337 
339  {
340  include_once './payment/classes/class.ilPaymentObject.php';
341 
342  $this->pobject =& new ilPaymentObject($this->ilias->account,ilPaymentObject::_lookupPobjectId($this->ref_id));
343 
344  return true;
345  }
347  {
348  include_once './payment/classes/class.ilPaymentPrices.php';
349 
350  $this->price_obj =& new ilPaymentPrices($this->pobject->getPobjectId());
351 
352  return true;
353  }
354 
355  function __buildHeader()
356  {
357  $this->tpl->addBlockFile("CONTENT", "content", "tpl.payb_content.html");
358 
359  $this->tpl->setVariable("HEADER",$this->object->getTitle());
360  $this->tpl->setVariable("DESCRIPTION",$this->object->getDescription());
361 
362 # $this->__buildStylesheet();
363 # $this->__buildStatusline();
364  }
365 
366  function __buildStatusline()
367  {
368  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
369  $this->__buildLocator();
370  }
371 
372  function __buildLocator()
373  {
374  $this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html", "Services/Locator");
375  $this->tpl->setVariable("TXT_LOCATOR",$this->lng->txt("locator"));
376 
377  $this->tpl->setCurrentBlock("locator_item");
378  $this->tpl->setVariable("ITEM", $this->lng->txt("repository"));
379  $this->tpl->setVariable("LINK_ITEM", "../repository.php?getlast=true");
380  $this->tpl->parseCurrentBlock();
381 
382  // CHECK for new mail and info
384 
385  return true;
386  }
387 
388  function __buildStylesheet()
389  {
390  $this->tpl->setVariable("LOCATION_STYLESHEET",ilUtil::getStyleSheetLocation());
391  }
392 
393 
394 
395 }
396 ?>