ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPaymentObjectGUI.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 include_once 'payment/classes/class.ilPaymentObject.php';
25 include_once 'payment/classes/class.ilPaymentBookings.php';
26 include_once 'Services/Payment/classes/class.ilFileDataShop.php';
27 
38 {
39  var $ctrl;
40  var $lng;
41  var $user_obj;
42  var $pobject = null;
43 
44  public function ilPaymentObjectGUI($user_obj)
45  {
47 
48  $this->user_obj = $user_obj;
49  $this->lng->loadLanguageModule('crs');
50  }
51 
52  protected function prepareOutput()
53  {
54  global $ilTabs;
55 
56  $this->setSection(6);
57 
59 
60  $ilTabs->setTabActive('paya_header');
61  $ilTabs->setSubTabActive('paya_object');
62  }
63 
64  public function executeCommand()
65  {
66  $cmd = $this->ctrl->getCmd();
67  switch($this->ctrl->getNextClass($this))
68  {
69  case 'ilpageobjectgui':
70  $this->prepareOutput();
71  $ret = $this->forwardToPageObject();
72  if($ret != '')
73  {
74  $this->tpl->setContent($ret);
75  }
76  break;
77 
78  default:
79  if(!$cmd = $this->ctrl->getCmd())
80  {
81  $cmd = 'showObjects';
82  }
83  $this->prepareOutput();
84  $this->$cmd();
85  break;
86  }
87  }
88 
89  public function forwardToPageObject()
90  {
91  global $ilTabs;
92 
93  if(!(int)$_GET['pobject_id'])
94  {
95  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
96  return $this->showObjects();
97  }
98  $this->ctrl->setParameter($this, 'pobject_id', (int)$_GET['pobject_id']);
99  $this->__initPaymentObject((int)$_GET['pobject_id']);
100 
101  $this->lng->loadLanguageModule('content');
102 
103  $ilTabs->clearTargets();
104  $ilTabs->clearSubTabs();
105  $ilTabs->setBackTarget($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'editDetails'), '_top');
106 
107  // page objec
108  include_once 'Services/COPage/classes/class.ilPageObject.php';
109  include_once 'Services/COPage/classes/class.ilPageObjectGUI.php';
110  include_once('./Services/Style/classes/class.ilObjStyleSheet.php');
111 
112  $this->tpl->setVariable('LOCATION_CONTENT_STYLESHEET', ilObjStyleSheet::getContentStylePath(0));
113 
114  if(!ilPageObject::_exists('shop', $this->pobject->getPobjectId()))
115  {
116  // doesn't exist -> create new one
117  $new_page_object = new ilPageObject('shop');
118  $new_page_object->setParentId(0);
119  $new_page_object->setId($this->pobject->getPobjectId());
120  $new_page_object->createFromXML();
121  }
122 
123  $this->ctrl->setReturnByClass('ilpageobjectgui', 'edit');
124 
125  $page_gui = new ilPageObjectGUI('shop', $this->pobject->getPobjectId());
126  $this->ctrl->setParameter($page_gui, 'pobject_id', (int)$_GET['pobject_id']);
127  $page_gui->setIntLinkHelpDefault('StructureObject', $this->pobject->getPobjectId());
128  $page_gui->setTemplateTargetVar('ADM_CONTENT');
129  $page_gui->setLinkXML('');
130  $page_gui->setFileDownloadLink($this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'downloadFile'));
131  $page_gui->setFullscreenLink($this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'displayMediaFullscreen'));
132  $page_gui->setSourcecodeDownloadScript($this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'download_paragraph'));
133  $page_gui->setPresentationTitle('');
134  $page_gui->setTemplateOutput(false);
135  $page_gui->setHeader('');
136  $page_gui->setEnabledRepositoryObjects(false);
137  $page_gui->setEnabledFileLists(true);
138  $page_gui->setEnabledMaps(true);
139  $page_gui->setEnabledPCTabs(true);
140 
141  return $this->ctrl->forwardCommand($page_gui);
142  }
143 
144  function showObjects()
145  {
146  $this->showButton('showObjectSelector', $this->lng->txt('paya_sell_object'));
147 
148  $this->tpl->addBlockfile('ADM_CONTENT', 'adm_content', 'tpl.paya_objects.html', 'payment');
149 
150  if(!count($objects = ilPaymentObject::_getObjectsData($this->user_obj->getId())))
151  {
152  ilUtil::sendInfo($this->lng->txt('paya_no_objects_assigned'));
153 
154  return true;
155  }
156 
157  $this->__initPaymentObject();
158 
159  $img_change = "<img src=\"".ilUtil::getImagePath("edit.gif")."\" alt=\"".
160  $this->lng->txt("edit")."\" title=\"".$this->lng->txt("edit").
161  "\" border=\"0\" vspace=\"0\"/>";
162 
163  $counter = 0;
164  foreach($objects as $data)
165  {
166  $tmp_obj =& ilObjectFactory::getInstanceByRefId($data['ref_id']);
167  $f_result[$counter][] = $tmp_obj->getTitle();
168 
169 
170  switch($data['status'])
171  {
172  case $this->pobject->STATUS_BUYABLE:
173  $f_result[$counter][] = $this->lng->txt('paya_buyable');
174  break;
175 
176  case $this->pobject->STATUS_NOT_BUYABLE:
177  $f_result[$counter][] = $this->lng->txt('paya_not_buyable');
178  break;
179 
180  case $this->pobject->STATUS_EXPIRES:
181  $f_result[$counter][] = $this->lng->txt('paya_expires');
182  break;
183  }
184  switch($data['pay_method'])
185  {
186  case $this->pobject->PAY_METHOD_NOT_SPECIFIED:
187  $f_result[$counter][] = $this->lng->txt('paya_pay_method_not_specified');
188  break;
189 
190  case $this->pobject->PAY_METHOD_BILL:
191  $f_result[$counter][] = $this->lng->txt('pays_bill');
192  break;
193 
194  case $this->pobject->PAY_METHOD_BMF:
195  $f_result[$counter][] = $this->lng->txt('pays_bmf');
196  break;
197 
198  case $this->pobject->PAY_METHOD_PAYPAL:
199  $f_result[$counter][] = $this->lng->txt('pays_paypal');
200  break;
201  }
202  $tmp_user =& ilObjectFactory::getInstanceByObjId($data['vendor_id']);
203  $f_result[$counter][] = $tmp_user->getFullname().' ['.$tmp_user->getLogin().']';
204 
205  // Get number of purchasers
206 
207  $f_result[$counter][] = ilPaymentBookings::_getCountBookingsByObject($data['pobject_id']);
208 
209 
210  // edit link
211  $this->ctrl->setParameter($this,"pobject_id",$data['pobject_id']);
212 # $link_change = "<a href=\"".$this->ctrl->getLinkTarget($this,"editDetails")."\"> ".
213 # $img_change."</a>";
214  $link_change = "<div class=\"il_ContainerItemCommands\"><a class=\"il_ContainerItemCommand\" href=\"".$this->ctrl->getLinkTarget($this,"editDetails")."\">".$this->lng->txt("edit")."</a></div>";
215 
216  $f_result[$counter][] = $link_change;
217  unset($tmp_user);
218  unset($tmp_obj);
219 
220  ++$counter;
221  }
222 
223  return $this->__showObjectsTable($f_result);
224  }
225 
226  function editDetails($a_show_confirm = false)
227  {
228  if(!(int)$_GET['pobject_id'])
229  {
230  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
231  return $this->showObjects();
232  }
233 
234  $this->__initPaymentObject((int)$_GET['pobject_id']);
235  $this->ctrl->setParameter($this,'pobject_id', (int)$_GET['pobject_id']);
236 
237  $this->showButton('editDetails', $this->lng->txt('paya_edit_details'));
238  $this->showButton('editPrices', $this->lng->txt('paya_edit_prices'));
239  // edit abstract
240  $this->tpl->setCurrentBlock('btn_cell');
241  $this->tpl->setVariable('BTN_LINK', $this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'edit'));
242  $this->tpl->setVariable('BTN_TXT', $this->lng->txt('pay_edit_abstract'));
243  $this->tpl->parseCurrentBlock();
244 
245  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.paya_edit.html','payment');
246 
247  if($a_show_confirm)
248  {
249  $this->tpl->setCurrentBlock("confirm_delete");
250  $this->tpl->setVariable("CONFIRM_FORMACTION",$this->ctrl->getFormAction($this));
251  $this->tpl->setVariable("TXT_CANCEL",$this->lng->txt('cancel'));
252  $this->tpl->setVariable("CONFIRM_CMD",'performDelete');
253  $this->tpl->setVariable("TXT_CONFIRM",$this->lng->txt('confirm'));
254  $this->tpl->parseCurrentBlock();
255  }
256 
257  $tmp_obj = ilObjectFactory::getInstanceByRefId($this->pobject->getRefId());
258 
259  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
260  $oForm = new ilPropertyFormGUI();
261  $oForm->setFormAction($this->ctrl->getFormAction($this, 'updateDetails'));
262  $oForm->setTitle($tmp_obj->getTitle());
263  $oForm->setTitleIcon(ilUtil::getImagePath('icon_'.$tmp_obj->getType().'_b.gif'));
264 
265  // repository path
266  $oPathGUI = new ilNonEditableValueGUI($this->lng->txt('path'));
267  $oPathGUI->setValue($this->__getHTMLPath($this->pobject->getRefId()));
268  $oForm->addItem($oPathGUI);
269 
270  // number of purchasers
271  $oPurchasersGUI = new ilNonEditableValueGUI($this->lng->txt('paya_count_purchaser'));
272  $oPurchasersGUI->setValue(ilPaymentBookings::_getCountBookingsByObject((int)$_GET['pobject_id']));
273  $oForm->addItem($oPurchasersGUI);
274 
275  // vendors
276  $oVendorsGUI = new ilSelectInputGUI($this->lng->txt('paya_vendor'), 'vendor');
277  $oVendorsGUI->setOptions($this->__getVendors());
278  $oVendorsGUI->setValue($this->pobject->getVendorId());
279  $oForm->addItem($oVendorsGUI);
280 
281  // status
282  $oStatusGUI = new ilSelectInputGUI($this->lng->txt('status'), 'status');
283  $oStatusGUI->setOptions($this->__getStatus());
284  $oStatusGUI->setValue($this->pobject->getStatus());
285  $oForm->addItem($oStatusGUI);
286 
287  // pay methods
288  $oPayMethodsGUI = new ilSelectInputGUI($this->lng->txt('paya_pay_method'), 'pay_method');
289  $oPayMethodsGUI->setOptions($this->__getPayMethods());
290  $oPayMethodsGUI->setValue($this->pobject->getPayMethod());
291  $oForm->addItem($oPayMethodsGUI);
292 
293  // topics
294  ilShopTopics::_getInstance()->read();
295  if(is_array($topics = ilShopTopics::_getInstance()->getTopics()) && count($topics))
296  {
297  $oTopicsGUI = new ilSelectInputGUI($this->lng->txt('topic'), 'topic_id');
298  include_once 'Services/Payment/classes/class.ilShopTopics.php';
299  ilShopTopics::_getInstance()->read();
300  $topic_options = array();
301  $topic_options[''] = $this->lng->txt('please_choose');
302 
303  foreach($topics as $oTopic)
304  {
305  $topic_options[$oTopic->getId()] = $oTopic->getTitle();
306  }
307 
308  $oTopicsGUI->setOptions($topic_options);
309  $oTopicsGUI->setValue($this->pobject->getTopicId());
310  $oForm->addItem($oTopicsGUI);
311  }
312 
313  $oThumbnail = new ilImageFileInputGUI($this->lng->txt('pay_thumbnail'), 'thumbnail');
314  $oFile = new ilFileDataShop($this->pobject->getPobjectId());
315  if(($webpath_file = $oFile->getCurrentImageWebPath()) !== false)
316  {
317  $oThumbnail->setImage($webpath_file);
318  }
319  $oForm->addItem($oThumbnail);
320 
321  // buttons
322  $oForm->addCommandButton('updateDetails', $this->lng->txt('save'));
323  $oForm->addCommandButton('deleteObject', $this->lng->txt('delete'));
324 
325  $this->tpl->setVariable('PAYMENT_OBJECT_FORM', $oForm->getHTML());
326  }
327 
328  function deleteObject()
329  {
330  include_once './payment/classes/class.ilPaymentBookings.php';
331 
332  if(!$_GET['pobject_id'])
333  {
334  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
335 
336  $this->showObjects();
337  return true;
338  }
339  if(ilPaymentBookings::_getCountBookingsByObject((int) $_GET['pobject_id']))
340  {
341  ilUtil::sendInfo($this->lng->txt('paya_bookings_available'));
342  $this->editDetails();
343 
344  return false;
345  }
346  else
347  {
348  ilUtil::sendInfo($this->lng->txt('paya_sure_delete_object'));
349  $this->editDetails(true);
350 
351  return true;
352  }
353  }
354 
355  function performDelete()
356  {
357  include_once './payment/classes/class.ilPaymentPrices.php';
358  include_once './payment/classes/class.ilPaymentBillVendor.php';
359 
360  if(!$_GET['pobject_id'])
361  {
362  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
363 
364  $this->showObjects();
365  return true;
366  }
367  $this->__initPaymentObject((int) $_GET['pobject_id']);
368 
369  // delete object data
370  $this->pobject->delete();
371 
372  // delete payment prices
373  $price_obj =& new ilPaymentPrices((int) $_GET['pobject_id']);
374  $price_obj->deleteAllPrices();
375  unset($price_obj);
376 
377  $bv =& new ilPaymentBillVendor((int) $_GET['pobject_id']);
378  $bv->delete();
379  unset($bv);
380 
381  // delete bill vendor data if exists
382  ilUtil::sendInfo($this->lng->txt('paya_deleted_object'));
383 
384  $this->showObjects();
385 
386  return true;
387  }
388 
389 
390 
391  function editPayMethod()
392  {
393  $this->__initPaymentObject((int) $_GET['pobject_id']);
394 
395  switch($this->pobject->getPayMethod())
396  {
397  case $this->pobject->PAY_METHOD_NOT_SPECIFIED:
398  ilUtil::sendInfo($this->lng->txt('paya_select_pay_method_first'));
399  $this->editDetails();
400 
401  return true;
402  case $this->pobject->PAY_METHOD_BMF:
403  ilUtil::sendInfo($this->lng->txt('paya_no_settings_necessary'));
404  $this->editDetails();
405 
406  return true;
407  case $this->pobject->PAY_METHOD_PAYPAL:
408  ilUtil::sendInfo($this->lng->txt('paya_no_settings_necessary'));
409  $this->editDetails();
410 
411  return true;
412  }
413 
414  $this->editDetails();
415 
416  return true;
417  }
418  function editPrices($a_show_delete = false)
419  {
420  include_once './payment/classes/class.ilPaymentPrices.php';
421  include_once './payment/classes/class.ilPaymentCurrency.php';
422  include_once "./Services/Table/classes/class.ilTableGUI.php";
423  include_once './payment/classes/class.ilGeneralSettings.php';
424 
425  $genSet = new ilGeneralSettings();
426 
427  $_SESSION['price_ids'] = $_SESSION['price_ids'] ? $_SESSION['price_ids'] : array();
428 
429  if(!$_GET['pobject_id'])
430  {
431  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
432 
433  $this->showObjects();
434  return true;
435  }
436  $this->ctrl->setParameter($this,'pobject_id',(int) $_GET['pobject_id']);
437 
438  $this->showButton('editDetails',$this->lng->txt('paya_edit_details'));
439  $this->showButton('editPrices',$this->lng->txt('paya_edit_prices'));
440  // edit abstract
441  $this->tpl->setCurrentBlock('btn_cell');
442  $this->tpl->setVariable('BTN_LINK', $this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'edit'));
443  $this->tpl->setVariable('BTN_TXT', $this->lng->txt('pay_edit_abstract'));
444  $this->tpl->parseCurrentBlock();
445 
446  $this->__initPaymentObject((int) $_GET['pobject_id']);
447 # $this->__showPayMethodLink();
448 
449  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.paya_edit_prices.html','payment');
450 
451  $price_obj =& new ilPaymentPrices((int) $_GET['pobject_id']);
452  $prices = $price_obj->getPrices();
453 
454  // No prices created
455  if(!count($prices))
456  {
457  ilUtil::sendInfo($this->lng->txt('paya_no_price_available'));
458 
459  $this->tpl->setCurrentBlock("price_info");
460  $this->tpl->setVariable("CONFIRM_FORMACTION",$this->ctrl->getFormAction($this));
461  $this->tpl->setVariable("CONFIRM_CMD",'addPrice');
462  $this->tpl->setVariable("TXT_CONFIRM",$this->lng->txt('paya_add_price'));
463  $this->tpl->parseCurrentBlock();
464 
465  return true;
466  }
467  // Show confirm delete
468  if($a_show_delete)
469  {
470  ilUtil::sendInfo($this->lng->txt('paya_sure_delete_selected_prices'));
471 
472  $this->tpl->setCurrentBlock("cancel");
473  $this->tpl->setVariable("CANCEL_CMD",'editPrices');
474  $this->tpl->setVariable("TXT_CANCEL",$this->lng->txt('cancel'));
475  $this->tpl->parseCurrentBlock();
476 
477  $this->tpl->setCurrentBlock("price_info");
478  $this->tpl->setVariable("CONFIRM_FORMACTION",$this->ctrl->getFormAction($this));
479  $this->tpl->setVariable("CONFIRM_CMD",'performDeletePrice');
480  $this->tpl->setVariable("TXT_CONFIRM",$this->lng->txt('paya_delete_price'));
481  $this->tpl->parseCurrentBlock();
482  }
483 
484  // Fill table cells
485  $tpl =& new ilTemplate('tpl.table.html',true,true);
486 
487  // set table header
488  $tpl->setCurrentBlock("tbl_form_header");
489 
490  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
491  $tpl->parseCurrentBlock();
492 
493  $tpl->addBlockfile("TBL_CONTENT", "tbl_content",'tpl.paya_edit_prices_row.html','payment');
494 
495  $counter = 0;
496  foreach($prices as $price)
497  {
498  $currency = ilPaymentCurrency::_getCurrency($price['currency']);
499 
500  $tpl->setCurrentBlock("tbl_content");
501  $tpl->setVariable("ROWCOL", ilUtil::switchColor($counter,"tblrow2","tblrow1"));
502 
503  $tpl->setVariable("CHECKBOX",ilUtil::formCheckBox(in_array($price['price_id'],$_SESSION['price_ids']) ? 1 : 0,
504  'price_ids[]',
505  $price['price_id']));
506  $tpl->setVariable("DURATION_NAME",'prices['.$price['price_id'].'][duration]');
507  $tpl->setVariable("DURATION",$price['duration']);
508  $tpl->setVariable("MONTH",$this->lng->txt('paya_months'));
509  $tpl->setVariable("UNIT_NAME",'prices['.$price['price_id'].'][unit_value]');
510  $tpl->setVariable("UNIT",$price['unit_value']);
511 # $tpl->setVariable("SHORTFORM",$this->lng->txt('currency_'.$currency['unit']));
512  $tpl->setVariable("SHORTFORM",$genSet->get("currency_unit"));
513 
514  $tpl->setVariable("SUB_UNIT_NAME",'prices['.$price['price_id'].'][sub_unit_value]');
515  $tpl->setVariable("SUB_UNIT",$price['sub_unit_value']);
516 # $tpl->setVariable("SUB_UNIT_TXT",$this->lng->txt('currency_'.$currency['sub_unit']));
517  $tpl->setVariable("SUB_UNIT_TXT",$genSet->get("currency_subunit"));
518  $tpl->parseCurrentBlock();
519 
520  ++$counter;
521  }
522 
523  // SET FOOTER
524  $tpl->setCurrentBlock("tbl_action_button");
525  $tpl->setVariable("BTN_NAME","deletePrice");
526  $tpl->setVariable("BTN_VALUE",$this->lng->txt("paya_delete_price"));
527  $tpl->parseCurrentBlock();
528 
529  $tpl->setCurrentBlock("plain_buttons");
530  $tpl->setVariable("PBTN_NAME","updatePrice");
531  $tpl->setVariable("PBTN_VALUE",$this->lng->txt("paya_update_price"));
532  $tpl->parseCurrentBlock();
533 
534  $tpl->setCurrentBlock("plain_buttons");
535  $tpl->setVariable("PBTN_NAME","addPrice");
536  $tpl->setVariable("PBTN_VALUE",$this->lng->txt("paya_add_price"));
537  $tpl->parseCurrentBlock();
538 
539 
540  $tpl->setCurrentBlock("tbl_action_row");
541  $tpl->setVariable("TPLPATH",$this->tpl->tplPath);
542  $tpl->setVariable("COLUMN_COUNTS",4);
543  $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
544  $tpl->parseCurrentBlock();
545 
546 
547  $tbl = new ilTableGUI();
548  $tbl->setTemplate($tpl);
549 
550  // title & header columns
551  $tbl->setStyle('table','std');
552 
553  $tmp_obj =& ilObjectFactory::getInstanceByRefId($this->pobject->getRefId());
554 
555  $tbl->setTitle($tmp_obj->getTitle(),
556  "icon_".$tmp_obj->getType()."_b.gif",
557  $this->lng->txt("objs_".$tmp_obj->getType()));
558  $tbl->setHeaderNames(array('',
559  $this->lng->txt('duration'),
560  $this->lng->txt('price_a'),
561  ''));
562  $tbl->setHeaderVars(array("",
563  "duration",
564  "price_unit",
565  "price_sub_unit"),
566  array("ref_id" => $this->cur_ref_id));
567 
568  // control
569  $tbl->setLimit($_GET["limit"]);
570  $tbl->setOffset($_GET["offset"]);
571  $tbl->setMaxCount(count($price_obj->getPrices()));
572 
573  $tbl->disable("sort");
574 
575  // render table
576  $tbl->render();
577 
578  $this->tpl->setVariable("PRICES_TABLE",$tpl->get());
579 
580  return true;
581  }
582 
583  function addPrice()
584  {
585  if(!$_GET['pobject_id'])
586  {
587  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
588 
589  $this->showObjects();
590  return true;
591  }
592 
593  include_once './payment/classes/class.ilGeneralSettings.php';
594 
595  $genSet = new ilGeneralSettings();
596 
597  $this->ctrl->setParameter($this,'pobject_id',(int) $_GET['pobject_id']);
598 
599  $this->__initPaymentObject((int) $_GET['pobject_id']);
600 
601  $this->showButton('editDetails',$this->lng->txt('paya_edit_details'));
602  $this->showButton('editPrices',$this->lng->txt('paya_edit_prices'));
603 # $this->__showPayMethodLink();
604 
605  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.paya_add_price.html','payment');
606 
607  $this->tpl->setVariable("ADD_FORMACTION",$this->ctrl->getFormAction($this));
608 
609  $tmp_obj =& ilObjectFactory::getInstanceByRefId($this->pobject->getRefId());
610  $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_'.$tmp_obj->getType().'_b.gif'));
611  $this->tpl->setVariable("ALT_IMG",$this->lng->txt('obj_'.$tmp_obj->getType()));
612  $this->tpl->setVariable("TITLE",$tmp_obj->getTitle());
613  $this->tpl->setVariable("DESCRIPTION",$this->lng->txt('paya_add_price_title'));
614 
615  // TODO show curency selector
616 # $this->tpl->setVariable("TXT_PRICE_A",$this->lng->txt('currency_euro'));
617 # $this->tpl->setVariable("TXT_PRICE_B",$this->lng->txt('currency_cent'));
618  $this->tpl->setVariable("TXT_PRICE_A",$genSet->get("currency_unit"));
619  $this->tpl->setVariable("TXT_PRICE_B",$genSet->get("currency_subunit"));
620 
621  $this->tpl->setVariable("MONTH",$this->lng->txt('paya_months'));
622  $this->tpl->setVariable("TXT_DURATION",$this->lng->txt('duration'));
623  $this->tpl->setVariable("TXT_PRICE",$this->lng->txt('price_a'));
624  $this->tpl->setVariable("CANCEL",$this->lng->txt('cancel'));
625  $this->tpl->setVariable("ADD",$this->lng->txt('paya_add_price'));
626 
627  $this->tpl->setVariable("DURATION",$_POST['duration']);
628  $this->tpl->setVariable("UNIT_VALUE",$_POST['unit']);
629  $this->tpl->setVariable("SUB_UNIT",$_POST['SUB_UNIT']);
630 
631  return true;
632  }
633 
634  function performAddPrice()
635  {
636  if(!$_GET['pobject_id'])
637  {
638  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
639 
640  $this->showObjects();
641  return true;
642  }
643 
644  include_once './payment/classes/class.ilPaymentPrices.php';
645  include_once './payment/classes/class.ilPaymentCurrency.php';
646 
648 
649  $prices =& new ilPaymentPrices((int) $_GET['pobject_id']);
650 
651  $prices->setDuration($_POST['duration']);
652  $prices->setUnitValue($_POST['unit']);
653  $prices->setSubUnitValue($_POST['sub_unit']);
654  $prices->setCurrency($currency[1]['currency_id']);
655 
656  if(!$prices->validate())
657  {
658  ilUtil::sendInfo($this->lng->txt('paya_price_not_valid'));
659  $this->addPrice();
660 
661  return true;
662  }
663  $prices->add();
664 
665  ilUtil::sendInfo($this->lng->txt('paya_added_new_price'));
666  $this->editPrices();
667 
668  return true;
669  }
670 
671 
672 
674  {
675  if(!$_GET['pobject_id'])
676  {
677  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
678 
679  $this->showObjects();
680  return true;
681  }
682 
683  if(!count($_SESSION['price_ids']))
684  {
685  ilUtil::sendInfo($this->lng->txt('paya_no_prices_selected'));
686 
687  $this->editPrices();
688  return true;
689  }
690  include_once './payment/classes/class.ilPaymentPrices.php';
691 
692  $prices =& new ilPaymentPrices((int) $_GET['pobject_id']);
693 
694  foreach($_SESSION['price_ids'] as $price_id)
695  {
696  $prices->delete($price_id);
697  }
698 
699  // check if it was last price otherwise set status to 'not_buyable'
700  if(!count($prices->getPrices()))
701  {
702  $this->__initPaymentObject((int) $_GET['pobject_id']);
703 
704  $this->pobject->setStatus($this->pobject->STATUS_NOT_BUYABLE);
705  $this->pobject->update();
706 
707  ilUtil::sendInfo($this->lng->txt('paya_deleted_last_price'));
708  }
709  unset($prices);
710  unset($_SESSION['price_ids']);
711 
712  return $this->editPrices();
713  }
714 
715 
716  function deletePrice()
717  {
718  if(!$_GET['pobject_id'])
719  {
720  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
721 
722  $this->showObjects();
723  return true;
724  }
725 
726  if(!count($_POST['price_ids']))
727  {
728  ilUtil::sendInfo($this->lng->txt('paya_no_prices_selected'));
729 
730  $this->editPrices();
731  return true;
732  }
733  $_SESSION['price_ids'] = $_POST['price_ids'];
734 
735  $this->editPrices(true);
736  return true;
737  }
738 
739  function updatePrice()
740  {
741  include_once './payment/classes/class.ilPaymentPrices.php';
742 
743  if(!$_GET['pobject_id'])
744  {
745  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
746 
747  $this->showObjects();
748  return true;
749  }
750  $po =& new ilPaymentPrices((int) $_GET['pobject_id']);
751 
752  $this->ctrl->setParameter($this,'pobject_id',(int) $_GET['pobject_id']);
753 
754  // validate
755  foreach($_POST['prices'] as $price_id => $price)
756  {
757  $old_price = $po->getPrice($price_id);
758 
759  $po->setDuration($price['duration']);
760  $po->setUnitValue($price['unit_value']);
761  $po->setSubUnitValue($price['sub_unit_value']);
762  $po->setCurrency($old_price['currency']);
763 
764  if(!$po->validate())
765  {
766  $error = true;
767  }
768  }
769  if($error)
770  {
771  ilUtil::sendInfo($this->lng->txt('paya_insert_only_numbers'));
772 
773  $this->editPrices();
774  return false;
775  }
776  foreach($_POST['prices'] as $price_id => $price)
777  {
778  $old_price = $po->getPrice($price_id);
779 
780  $po->setDuration($price['duration']);
781  $po->setUnitValue($price['unit_value']);
782  $po->setSubUnitValue($price['sub_unit_value']);
783  $po->setCurrency($old_price['currency']);
784 
785  $po->update($price_id);
786  }
787  ilUtil::sendInfo($this->lng->txt('paya_updated_prices'));
788  $this->editPrices();
789 
790  return true;
791  }
792 
793 
794  function updateDetails()
795  {
796  if(!$_GET['pobject_id'])
797  {
798  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
799 
800  $this->showObjects();
801  return true;
802  }
803  $this->__initPaymentObject((int)$_GET['pobject_id']);
804  $this->ctrl->setParameter($this, 'pobject_id', (int)$_GET['pobject_id']);
805 
806  // read old settings
807  $old_pay_method = $this->pobject->getPayMethod();
808  $old_status = $this->pobject->getStatus();
809 
810  // check status changed from not_buyable
811  if($old_status == $this->pobject->STATUS_NOT_BUYABLE and
812  (int) $_POST['status'] != $old_status)
813  {
814  // check pay_method edited
815  switch((int) $_POST['pay_method'])
816  {
817  case $this->pobject->PAY_METHOD_NOT_SPECIFIED:
818  ilUtil::sendInfo($this->lng->txt('paya_select_pay_method_first'));
819  $this->editDetails();
820 
821  return false;
822 
823  case $this->pobject->PAY_METHOD_BILL:
824  include_once './payment/classes/class.ilPaymentBillVendor.php';
825 
826  $bill_vendor =& new ilPaymentBillVendor((int) $_GET['pobject_id']);
827  if(!$bill_vendor->validate())
828  {
829  ilUtil::sendInfo($this->lng->txt('paya_select_pay_method_first'));
830  $this->editDetails();
831 
832  return false;
833  }
834  break;
835 
836  default:
837  ;
838  }
839  // check minimum one price
840  include_once './payment/classes/class.ilPaymentPrices.php';
841 
842  $prices_obj =& new ilPaymentPrices((int) $_GET['pobject_id']);
843  if(!count($prices_obj->getPrices()))
844  {
845  ilUtil::sendInfo($this->lng->txt('paya_edit_prices_first'));
846  $this->editDetails();
847 
848  return false;
849  }
850  }
851 
852  $this->pobject->setStatus((int)$_POST['status']);
853  $this->pobject->setVendorId((int)$_POST['vendor']);
854  $this->pobject->setPayMethod((int)$_POST['pay_method']);
855  $this->pobject->setTopicId((int)$_POST['topic_id']);
856 
857  if((int)$_POST['thumbnail_delete'])
858  {
859  $oFile = new ilFileDataShop($this->pobject->getPobjectId());
861  }
862  else if($_FILES['thumbnail']['tmp_name'] != '')
863  {
864  $this->lng->loadLanguageModule('form');
865  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
866  $oThumbnail = new ilImageFileInputGUI($this->lng->txt('pay_thumbnail'), 'thumbnail');
867  if($oThumbnail->checkInput())
868  {
869  $oFile = new ilFileDataShop($this->pobject->getPobjectId());
870  if(($oFile->storeUploadedFile($_FILES['thumbnail'])) !== false)
871  {
872  $oFile->assignFileToPaymentObject();
873  }
874  }
875  else
876  {
877  ilUtil::sendInfo($oThumbnail->getAlert());
878  return $this->editDetails();
879  }
880  }
881 
882  $this->pobject->update();
883 
884  ilUtil::sendInfo($this->lng->txt('paya_details_updated'));
885  $this->editDetails();
886 
887  return true;
888  }
889 
891  {
892  global $tree;
893 
894  include_once './payment/classes/class.ilPaymentObjectSelector.php';
895 
896  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.paya_object_selector.html",'payment');
897  $this->showButton('showObjects',$this->lng->txt('back'));
898 
899 
900  ilUtil::sendInfo($this->lng->txt("paya_select_object_to_sell"));
901 
902  $exp = new ilPaymentObjectSelector($this->ctrl->getLinkTarget($this,'showObjectSelector'), strtolower(get_class($this)));
903  $exp->setExpand($_GET["paya_link_expand"] ? $_GET["paya_link_expand"] : $tree->readRootId());
904  $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'showObjectSelector'));
905 
906  $exp->setOutput(0);
907 
908  $this->tpl->setVariable("EXPLORER",$exp->getOutput());
909 
910  return true;
911  }
912 
914  {
915  if(!(int)$_GET['sell_id'])
916  {
917  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
918  return $this->showObjectSelector();
919  }
920 
921  $this->showButton('showObjectSelector',$this->lng->txt('back'));
922 
923  // save ref_id of selected object
924  $this->ctrl->setParameter($this, 'sell_id', (int)$_GET['sell_id']);
925 
926  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
927  $oForm = new ilPropertyFormGUI();
928  $oForm->setFormAction($this->ctrl->getFormAction($this, 'updateDetails'));
929  $oForm->setTitle($this->lng->txt('details'));
930  $oForm->setTitleIcon(ilUtil::getImagePath('icon_pays.gif', false));
931 
932  $tmp_obj = ilObjectFactory::getInstanceByRefId($_GET['sell_id']);
933 
934  // title
935  $oTitleGUI = new ilNonEditableValueGUI($this->lng->txt('title'));
936  $oTitleGUI->setValue($tmp_obj->getTitle());
937  $oForm->addItem($oTitleGUI);
938 
939  // description
940  $oDescriptionGUI = new ilNonEditableValueGUI($this->lng->txt('description'));
941  $oDescriptionGUI->setValue($tmp_obj->getDescription());
942  $oForm->addItem($oDescriptionGUI);
943 
944  // owner
945  $oOwnerGUI = new ilNonEditableValueGUI($this->lng->txt('owner'));
946  $oOwnerGUI->setValue($tmp_obj->getOwnerName());
947  $oForm->addItem($oOwnerGUI);
948 
949  // path
950  $oPathGUI = new ilNonEditableValueGUI($this->lng->txt('paya_count_purchaser'));
951  $oPathGUI->setValue($this->__getHTMLPath((int)$_GET['sell_id']));
952  $oForm->addItem($oPathGUI);
953 
954  // vendors
955  $oVendorsGUI = new ilSelectInputGUI($this->lng->txt('paya_vendor'), 'vendor');
956  $oVendorsGUI->setOptions($this->__getVendors());
957  $oForm->addItem($oVendorsGUI);
958 
959  // buttons
960  $oForm->addCommandButton('addObject', $this->lng->txt('next'));
961  $oForm->addCommandButton('showObjects', $this->lng->txt('cancel'));
962 
963  $this->tpl->setVariable('ADM_CONTENT', $oForm->getHTML());
964  }
965 
966  function addObject()
967  {
968  if(!$_GET['sell_id'])
969  {
970  ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
971 
972  return $this->showObjectSelector();
973  }
974  if(!(int)$_POST['vendor'])
975  {
976  ilUtil::sendInfo($this->lng->txt('paya_no_vendor_selected'));
977 
978  return $this->showSelectedObject();
979  }
980  if(!ilPaymentObject::_isPurchasable($_GET['sell_id']))
981  {
982  ilUtil::sendInfo($this->lng->txt('paya_object_not_purchasable'));
983 
984  return $this->showObjectSelector();
985  }
986 
987  include_once 'payment/classes/class.ilPaymentObject.php';
988 
989  $p_obj = new ilPaymentObject($this->user_obj);
990 
991  $p_obj->setRefId((int)$_GET['sell_id']);
992  $p_obj->setStatus($p_obj->STATUS_NOT_BUYABLE);
993  $p_obj->setPayMethod($p_obj->PAY_METHOD_NOT_SPECIFIED);
994  $p_obj->setVendorId((int)$_POST['vendor']);
995  $p_obj->setTopicId((int)$_POST['topic_id']);
996 
997  if($new_id = $p_obj->add())
998  {
999  ilUtil::sendInfo($this->lng->txt('paya_added_new_object'));
1000  $_GET['pobject_id'] = $new_id;
1001  return $this->editDetails();
1002  }
1003  else
1004  {
1005  ilUtil::sendInfo($this->lng->txt('paya_err_adding_object'));
1006  return $this->showObjects();
1007  }
1008  }
1009 
1010  private function __getVendors()
1011  {
1012  include_once 'payment/classes/class.ilPaymentVendors.php';
1013 
1014  $options = array();
1015  $vendors = array();
1016  if(ilPaymentVendors::_isVendor($this->user_obj->getId()))
1017  {
1018  $vendors[] = $this->user_obj->getId();
1019  }
1020  if($vend = ilPaymentTrustees::_getVendorsForObjects($this->user_obj->getId()))
1021  {
1022  $vendors = array_merge($vendors, $vend);
1023  }
1024  foreach($vendors as $vendor)
1025  {
1026  $tmp_obj = ilObjectFactory::getInstanceByObjId($vendor, false);
1027  $options[$vendor] = $tmp_obj->getFullname().' ['.$tmp_obj->getLogin().']';
1028  }
1029 
1030  return $options;
1031  }
1032 
1033  private function __getStatus()
1034  {
1035  $option = array();
1036  $option[$this->pobject->STATUS_NOT_BUYABLE] = $this->lng->txt('paya_not_buyable');
1037  $option[$this->pobject->STATUS_BUYABLE] = $this->lng->txt('paya_buyable');
1038  $option[$this->pobject->STATUS_EXPIRES] = $this->lng->txt('paya_expires');
1039 
1040  return $option;
1041  }
1042 
1043  private function __getPayMethods()
1044  {
1045  include_once 'payment/classes/class.ilPayMethods.php';
1046 
1047  $options = array();
1048 
1049  $options[$this->pobject->PAY_METHOD_NOT_SPECIFIED] = $this->lng->txt('paya_pay_method_not_specified');
1050  if(ilPayMethods::_enabled('pm_bill'))
1051  {
1052  $options[$this->pobject->PAY_METHOD_BILL] = $this->lng->txt('pays_bill');
1053  }
1054  if(ilPayMethods::_enabled('pm_bmf'))
1055  {
1056  $options[$this->pobject->PAY_METHOD_BMF] = $this->lng->txt('pays_bmf');
1057  }
1058  if(ilPayMethods::_enabled('pm_paypal'))
1059  {
1060  $options[$this->pobject->PAY_METHOD_PAYPAL] = $this->lng->txt('pays_paypal');
1061  }
1062 
1063  return $options;
1064  }
1065 
1067  {
1068  switch($this->pobject->getPayMethod())
1069  {
1070  case $this->pobject->PAY_METHOD_NOT_SPECIFIED:
1071  $this->showButton('editPayMethod',$this->lng->txt('paya_edit_pay_method'));
1072  break;
1073 
1074  case $this->pobject->PAY_METHOD_BILL:
1075 
1076  $this->ctrl->setParameterByClass('ilpaymentbilladmingui','pobject_id',(int) $_GET['pobject_id']);
1077  $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
1078  $this->tpl->setCurrentBlock("btn_cell");
1079  $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTargetByClass('ilpaymentbilladmingui'));
1080  $this->tpl->setVariable("BTN_TXT",$this->lng->txt('paya_edit_pay_method'));
1081  $this->tpl->parseCurrentBlock();
1082  break;
1083 
1084  case $this->pobject->PAY_METHOD_BMF:
1085  $this->showButton('editPayMethod',$this->lng->txt('paya_edit_pay_method'));
1086  break;
1087 
1088  case $this->pobject->PAY_METHOD_PAYPAL:
1089  $this->showButton('editPayMethod',$this->lng->txt('paya_edit_pay_method'));
1090  break;
1091  }
1092  }
1093  function __showObjectsTable($a_result_set)
1094  {
1095  $tbl =& $this->initTableGUI();
1096  $tpl =& $tbl->getTemplateObject();
1097 
1098  // SET FORMAACTION
1099  $tpl->setCurrentBlock("tbl_form_header");
1100 
1101  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
1102  $tpl->parseCurrentBlock();
1103 
1104  /*
1105  $tpl->setCurrentBlock("tbl_action_row");
1106  $tpl->setCurrentBlock("plain_buttons");
1107  $tpl->parseCurrentBlock();
1108 
1109  $tpl->setVariable("COLUMN_COUNTS",6);
1110  $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
1111 
1112  $tpl->setCurrentBlock("tbl_action_button");
1113  $tpl->setVariable("BTN_NAME","deleteTrustee");
1114  $tpl->setVariable("BTN_VALUE",$this->lng->txt("delete"));
1115  $tpl->parseCurrentBlock();
1116  $tpl->setCurrentBlock("tbl_action_row");
1117  $tpl->setVariable("TPLPATH",$this->tpl->tplPath);
1118  $tpl->parseCurrentBlock();
1119  */
1120 
1121  $tbl->setTitle($this->lng->txt("objects"),"icon_pays.gif",$this->lng->txt("objects"));
1122  $tbl->setHeaderNames(array($this->lng->txt("title"),
1123  $this->lng->txt("status"),
1124  $this->lng->txt("paya_pay_method"),
1125  $this->lng->txt("paya_vendor"),
1126  $this->lng->txt("paya_count_purchaser"),
1127  ''));
1128  $header_params = $this->ctrl->getParameterArray($this,'');
1129  $tbl->setHeaderVars(array("title",
1130  "status",
1131  "pay_method",
1132  "vendor",
1133  "purchasers",
1134  "options"),$header_params);
1135  /*
1136  array("cmd" => "",
1137  "cmdClass" => "ilpaymentobjectgui",
1138  "cmdNode" => $_GET["cmdNode"]));
1139  */
1140  $tbl->setColumnWidth(array("15%","15%","15%","20%","20%"));
1141 
1142 # $this->setTableGUIBasicData($tbl,$a_result_set);
1143 
1144  $offset = $_GET["offset"];
1145  $order = $_GET["sort_by"];
1146  $direction = $_GET["sort_order"] ? $_GET['sort_order'] : 'desc';
1147 
1148  $tbl->setOrderColumn($order,'order_date');
1149  $tbl->setOrderDirection($direction);
1150  $tbl->setOffset($offset);
1151  $tbl->setLimit($_GET["limit"]);
1152  $tbl->setMaxCount(count($a_result_set));
1153  $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
1154  $tbl->setData($a_result_set);
1155 
1156  $tbl->render();
1157 
1158  $this->tpl->setVariable("OBJECTS_TABLE",$tbl->tpl->get());
1159 
1160  return true;
1161  }
1162 
1163 
1164  function __getHTMLPath($a_ref_id)
1165  {
1166  global $tree;
1167 
1168  $path = $tree->getPathFull($a_ref_id);
1169  unset($path[0]);
1170 
1171  foreach($path as $data)
1172  {
1173  $html .= $data['title'].' > ';
1174  }
1175  return substr($html,0,-2);
1176  }
1177 
1178  function __initPaymentObject($a_pobject_id = 0)
1179  {
1180  include_once './payment/classes/class.ilPaymentObject.php';
1181 
1182  $this->pobject =& new ilPaymentObject($this->user_obj,$a_pobject_id);
1183 
1184  return true;
1185  }
1186 }
1187 ?>