ILIAS  Release_3_10_x_branch Revision 61812
 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);
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->getType() == 'crs' && $this->object->isSubscriptionMembershipLimited())
86  {
87  $this->object->initCourseMemberObject();
88 
89  if($this->object->getSubscriptionMaxMembers() <= $this->object->members_obj->getCountMembers())
90  {
91  ilUtil::sendInfo($this->lng->txt('pay_crs_max_members_exceeded'));
92  return false;
93  }
94  }
95 
96  $this->__initPaymentObject();
97  $this->__initPricesObject();
98  $this->__initShoppingCartObject();
99 
100  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.pay_purchase_details.html','payment');
101 
102  if($this->pobject->getStatus() == $this->pobject->STATUS_EXPIRES)
103  {
104  ilUtil::sendInfo($this->lng->txt('pay_expires_info'));
105 
106  return false;
107  }
108 
109  $prices = $this->price_obj->getPrices();
110  $buyedObject = "";
111  if($this->sc_obj->isInShoppingCart($this->pobject->getPobjectId()))
112  {
113  $buyedObject = $this->sc_obj->getEntry($this->pobject->getPobjectId());
114  if (is_array($prices) &&
115  count($prices) > 1)
116  {
117  ilUtil::sendInfo($this->lng->txt('pay_item_already_in_sc_choose_another'));
118  }
119  else
120  {
121  ilUtil::sendInfo($this->lng->txt('pay_item_already_in_sc'));
122  }
123 
124  $this->tpl->setCurrentBlock("shopping_cart");
125  $this->tpl->setVariable("LINK_GOTO_SHOPPING_CART", "ilias.php?cmdClass=ilpaymentgui&baseClass=ilPersonalDesktopGUI&cmd=showShoppingCart");
126  $this->tpl->setVariable("TXT_GOTO_SHOPPING_CART", $this->lng->txt('pay_goto_shopping_cart'));
127 # $this->tpl->setVariable("TXT_BUY", $this->lng->txt('pay_click_to_buy'));
128  $this->tpl->parseCurrentBlock("shopping_cart");
129  }
130 
131  $this->ctrl->setParameter($this, "ref_id", $this->pobject->getRefId());
132 
133 # if (!is_array($buyedObject) ||
134 # (is_array($buyedObject) && is_array($prices) && count($prices) > 1))
135 # {
136  $this->tpl->setVariable("DETAILS_FORMACTION",$this->ctrl->getFormAction($this));
137  $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_'.$this->object->getType().'_b.gif'));
138  $this->tpl->setVariable("ALT_IMG",$this->lng->txt('obj_'.$this->object->getType()));
139  $this->tpl->setVariable("TITLE",$this->object->getTitle());
140 
141  // payment infos
142  $this->tpl->setVariable("TXT_INFO",$this->lng->txt('info'));
143  switch($this->pobject->getPayMethod())
144  {
145  case $this->pobject->PAY_METHOD_BILL:
146  $this->tpl->setVariable("INFO_PAY",$this->lng->txt('pay_bill'));
147  $this->tpl->setVariable("INPUT_CMD",'getBill');
148  $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_get_bill'));
149  break;
150 
151  case $this->pobject->PAY_METHOD_BMF:
152  $this->tpl->setVariable("INFO_PAY",$this->lng->txt('pay_info'));
153  if (is_array($buyedObject))
154  {
155  if (is_array($prices) && count($prices) > 1)
156  {
157  $this->tpl->setVariable("INPUT_CMD",'addToShoppingCart');
158  $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_change_price'));
159  }
160  }
161  else
162  {
163  $this->tpl->setVariable("INPUT_CMD",'addToShoppingCart');
164  $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_add_to_shopping_cart'));
165  }
166  break;
167 
168  case $this->pobject->PAY_METHOD_PAYPAL:
169  $this->tpl->setVariable("INFO_PAY",$this->lng->txt('pay_info'));
170  if (is_array($buyedObject))
171  {
172  if (is_array($prices) && count($prices) > 1)
173  {
174  $this->tpl->setVariable("INPUT_CMD",'addToShoppingCart');
175  $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_change_price'));
176  }
177  }
178  else
179  {
180  $this->tpl->setVariable("INPUT_CMD",'addToShoppingCart');
181  $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_add_to_shopping_cart'));
182  }
183  break;
184  }
185 
186  $this->tpl->setVariable("ROWSPAN",count($prices));
187  $this->tpl->setVariable("TXT_PRICES",$this->lng->txt('prices'));
188 # }
189 
190  if (is_array($prices))
191  {
192 # if (count($prices) > 1)
193 # {
194  $counter = 0;
195  foreach($prices as $price)
196  {
197  if ($counter == 0)
198  {
199  $placeholderCheckbox = "CHECKBOX";
200  $placeholderDuration = "DURATION";
201  $placeholderPrice = "PRICE";
202  }
203  else
204  {
205  $placeholderCheckbox = "ROW_CHECKBOX";
206  $placeholderDuration = "ROW_DURATION";
207  $placeholderPrice = "ROW_PRICE";
208  }
209  $this->tpl->setCurrentBlock("price_row");
210  if ($buyedObject["price_id"] == $price['price_id'])
211  {
212  $this->tpl->setVariable($placeholderCheckbox,ilUtil::formRadioButton(1,'price_id',$price['price_id']));
213  }
214  else
215  {
216  $this->tpl->setVariable($placeholderCheckbox,ilUtil::formRadioButton(0,'price_id',$price['price_id']));
217  }
218  $this->tpl->setVariable($placeholderDuration,$price['duration'].' '.$this->lng->txt('paya_months'));
219  $this->tpl->setVariable($placeholderPrice,ilPaymentPrices::_getPriceString($price['price_id']));
220  $this->tpl->parseCurrentBlock();
221  $counter++;
222  }
223 # }
224 # else if (!is_array($buyedObject))
225 # {
226 # foreach($prices as $price)
227 # {
228 # $this->tpl->setVariable("CHECKBOX",ilUtil::formRadioButton(0,'price_id',$price['price_id']));
229 # $this->tpl->setVariable("DURATION",$price['duration'].' '.$this->lng->txt('paya_months'));
230 # $this->tpl->setVariable("PRICE",ilPaymentPrices::_getPriceString($price['price_id']));
231 # }
232 # }
233  }
234 
235  }
236 
237  function addToShoppingCart()
238  {
239  if($this->object->getType() == 'crs' && $this->object->isSubscriptionMembershipLimited())
240  {
241  $this->object->initCourseMemberObject();
242 
243  if($this->object->getSubscriptionMaxMembers() <= $this->object->members_obj->getCountMembers())
244  {
245  ilUtil::sendInfo($this->lng->txt('pay_crs_max_members_exceeded'));
246  return false;
247  }
248  }
249 
250  if(!isset($_POST['price_id']))
251  {
252  ilUtil::sendInfo($this->lng->txt('pay_select_price'));
253  $this->showDetails();
254 
255  return true;
256  }
257  else
258  {
259  $this->__initPaymentObject();
260  $this->__initShoppingCartObject();
261 
262 
263  $this->sc_obj->setPriceId((int) $_POST['price_id']);
264  $this->sc_obj->setPobjectId($this->pobject->getPobjectId());
265  $this->sc_obj->add();
266 
267 # $tmp_obj =& ilObjectFactory::getInstanceByRefId($this->pobject->getRefId());
268 
269  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.pay_purchase_details.html','payment');
270  $this->tpl->setCurrentBlock("shopping_cart");
271  $this->tpl->setVariable("LINK_GOTO_SHOPPING_CART", "ilias.php?cmdClass=ilpaymentgui&baseClass=ilPersonalDesktopGUI&cmd=showShoppingCart");
272  $this->tpl->setVariable("TXT_GOTO_SHOPPING_CART", $this->lng->txt('pay_goto_shopping_cart'));
273 # $this->tpl->setVariable("TXT_BUY", $this->lng->txt('pay_click_to_buy'));
274  $this->tpl->parseCurrentBlock("shopping_cart");
275 
276  ilUtil::sendInfo($this->lng->txt('pay_added_to_shopping_cart'));
277 
278  return true;
279  }
280  }
281 
282  // PRIVATE
284  {
285  include_once './payment/classes/class.ilPaymentShoppingCart.php';
286 
287  $this->sc_obj =& new ilPaymentShoppingCart($this->ilias->account);
288 
289  return true;
290  }
291 
293  {
294  include_once './payment/classes/class.ilPaymentObject.php';
295 
296  $this->pobject =& new ilPaymentObject($this->ilias->account,ilPaymentObject::_lookupPobjectId($this->ref_id));
297 
298  return true;
299  }
301  {
302  include_once './payment/classes/class.ilPaymentPrices.php';
303 
304  $this->price_obj =& new ilPaymentPrices($this->pobject->getPobjectId());
305 
306  return true;
307  }
308 
309  function __buildHeader()
310  {
311  $this->tpl->addBlockFile("CONTENT", "content", "tpl.payb_content.html");
312 
313  $this->tpl->setVariable("HEADER",$this->object->getTitle());
314  $this->tpl->setVariable("DESCRIPTION",$this->object->getDescription());
315 
316 # $this->__buildStylesheet();
317 # $this->__buildStatusline();
318  }
319 
320  function __buildStatusline()
321  {
322  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
323  $this->__buildLocator();
324  }
325 
326  function __buildLocator()
327  {
328  $this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html");
329  $this->tpl->setVariable("TXT_LOCATOR",$this->lng->txt("locator"));
330 
331  $this->tpl->setCurrentBlock("locator_item");
332  $this->tpl->setVariable("ITEM", $this->lng->txt("repository"));
333  $this->tpl->setVariable("LINK_ITEM", "../repository.php?getlast=true");
334  $this->tpl->parseCurrentBlock();
335 
336  // CHECK for new mail and info
338 
339  return true;
340  }
341 
342  function __buildStylesheet()
343  {
344  $this->tpl->setVariable("LOCATION_STYLESHEET",ilUtil::getStyleSheetLocation());
345  }
346 
347 
348 
349 }
350 ?>