ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPaymentStatisticGUI.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 */
32 include_once './payment/classes/class.ilPaymentObject.php';
33 
35 {
36  private $pobject = null;
37 
38  public function ilPaymentStatisticGUI($user_obj)
39  {
41 
42  $this->ctrl->saveParameter($this, 'baseClass');
43 
44  $this->user_obj = $user_obj;
45  $this->pobject = new ilPaymentObject($this->user_obj);
46  }
47 
48  protected function prepareOutput()
49  {
50  global $ilTabs;
51 
52  $this->setSection(6);
53 
55 
56  $ilTabs->setTabActive('paya_header');
57  $ilTabs->setSubTabActive('bookings');
58  }
59 
60  public function executeCommand()
61  {
62  $cmd = $this->ctrl->getCmd();
63 
64  switch ($this->ctrl->getNextClass($this))
65  {
66  default:
67  if(!$cmd = $this->ctrl->getCmd())
68  {
69  $cmd = 'showStatistics';
70  }
71  $this->prepareOutput();
72  $this->$cmd();
73  break;
74  }
75  }
76 
77  function resetFilter()
78  {
79  unset($_SESSION["pay_statistics"]);
80  unset($_POST["transaction_type"]);
81  unset($_POST["transaction_value"]);
82  unset($_POST["from"]["day"]);
83  unset($_POST["from"]["month"]);
84  unset($_POST["from"]["year"]);
85  unset($_POST["til"]["day"]);
86  unset($_POST["til"]["month"]);
87  unset($_POST["til"]["year"]);
88  unset($_POST["payed"]);
89  unset($_POST["access"]);
90  unset($_POST["customer"]);
91  unset($_POST["pay_method"]);
92  unset($_POST["updateView"]);
93  $this->showStatistics();
94  }
95 
96  function showStatistics()
97  {
98  $this->showButton('showObjectSelector',$this->lng->txt('paya_add_customer'));
99 
100  if ($_POST["updateView"] == 1)
101  {
102  $_SESSION["pay_statistics"]["updateView"] = true;
103  $_SESSION["pay_statistics"]["transaction_type"] = $_POST["transaction_type"];
104  $_SESSION["pay_statistics"]["transaction_value"] = $_POST["transaction_value"];
105  $_SESSION["pay_statistics"]["from"]["day"] = $_POST["from"]["day"];
106  $_SESSION["pay_statistics"]["from"]["month"] = $_POST["from"]["month"];
107  $_SESSION["pay_statistics"]["from"]["year"] = $_POST["from"]["year"];
108  $_SESSION["pay_statistics"]["til"]["day"] = $_POST["til"]["day"];
109  $_SESSION["pay_statistics"]["til"]["month"] = $_POST["til"]["month"];
110  $_SESSION["pay_statistics"]["til"]["year"] = $_POST["til"]["year"];
111  $_SESSION["pay_statistics"]["payed"] = $_POST["payed"];
112  $_SESSION["pay_statistics"]["access"] = $_POST["access"];
113  $_SESSION["pay_statistics"]["customer"] = $_POST["customer"];
114  $_SESSION["pay_statistics"]["pay_method"] = $_POST["pay_method"];
115  }
116 
117  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.paya_statistic.html','payment');
118 
119  $this->tpl->setVariable("TXT_FILTER",$this->lng->txt('pay_filter'));
120  $this->tpl->setVariable("FORM_ACTION",$this->ctrl->getFormAction($this));
121  $this->tpl->setVariable("TXT_TRANSACTION",$this->lng->txt('paya_transaction'));
122  $this->tpl->setVariable("TXT_STARTING",$this->lng->txt('pay_starting'));
123  $this->tpl->setVariable("TXT_ENDING",$this->lng->txt('pay_ending'));
124  $this->tpl->setVariable("TXT_PAYED",$this->lng->txt('paya_payed'));
125  $this->tpl->setVariable("TXT_ALL",$this->lng->txt('pay_all'));
126  $this->tpl->setVariable("TXT_YES",$this->lng->txt('yes'));
127  $this->tpl->setVariable("TXT_NO",$this->lng->txt('no'));
128  $this->tpl->setVariable("TXT_BILL",$this->lng->txt('pays_bill'));
129  $this->tpl->setVariable("TXT_BMF",$this->lng->txt('pays_bmf'));
130  $this->tpl->setVariable("TXT_PAYPAL",$this->lng->txt('pays_paypal'));
131  $this->tpl->setVariable("TXT_CUSTOMER",$this->lng->txt('paya_customer'));
132  $this->tpl->setVariable("TXT_ACCESS",$this->lng->txt('paya_access'));
133  $this->tpl->setVariable("TXT_PAYMENT",$this->lng->txt('payment_system'));
134  $this->tpl->setVariable("TXT_ORDER_DATE_FROM",$this->lng->txt('pay_order_date_from'));
135  $this->tpl->setVariable("TXT_ORDER_DATE_TIL",$this->lng->txt('pay_order_date_til'));
136  $this->tpl->setVariable("TXT_UPDATE_VIEW",$this->lng->txt('pay_update_view'));
137  $this->tpl->setVariable("TXT_RESET_FILTER",$this->lng->txt('pay_reset_filter'));
138 
139  $this->tpl->setVariable("TRANSACTION_TYPE_" . $_SESSION["pay_statistics"]["transaction_type"], " selected");
140  $this->tpl->setVariable("TRANSACTION_VALUE", ilUtil::prepareFormOutput($_SESSION["pay_statistics"]["transaction_value"], true));
141  $this->tpl->setVariable("PAYED_" . $_SESSION["pay_statistics"]["payed"], " selected");
142  $this->tpl->setVariable("ACCESS_" . $_SESSION["pay_statistics"]["access"], " selected");
143  $this->tpl->setVariable("PAYMENT_" . $_SESSION["pay_statistics"]["pay_method"], " selected");
144  $this->tpl->setVariable("CUSTOMER", ilUtil::prepareFormOutput($_SESSION["pay_statistics"]["customer"], true));
145  for ($i = 1; $i <= 31; $i++)
146  {
147  $this->tpl->setCurrentBlock("loop_from_day");
148  $this->tpl->setVariable("LOOP_FROM_DAY", $i < 10 ? "0" . $i : $i);
149  if ($_SESSION["pay_statistics"]["from"]["day"] == $i)
150  {
151  $this->tpl->setVariable("LOOP_FROM_DAY_SELECTED", " selected");
152  }
153  $this->tpl->parseCurrentBlock("loop_from_day");
154  $this->tpl->setCurrentBlock("loop_til_day");
155  $this->tpl->setVariable("LOOP_TIL_DAY", $i < 10 ? "0" . $i : $i);
156  if ($_SESSION["pay_statistics"]["til"]["day"] == $i)
157  {
158  $this->tpl->setVariable("LOOP_TIL_DAY_SELECTED", " selected");
159  }
160  $this->tpl->parseCurrentBlock("loop_til_day");
161  }
162  for ($i = 1; $i <= 12; $i++)
163  {
164  $this->tpl->setCurrentBlock("loop_from_month");
165  $this->tpl->setVariable("LOOP_FROM_MONTH", $i < 10 ? "0" . $i : $i);
166  if ($_SESSION["pay_statistics"]["from"]["month"] == $i)
167  {
168  $this->tpl->setVariable("LOOP_FROM_MONTH_SELECTED", " selected");
169  }
170  $this->tpl->parseCurrentBlock("loop_from_month");
171  $this->tpl->setCurrentBlock("loop_til_month");
172  $this->tpl->setVariable("LOOP_TIL_MONTH", $i < 10 ? "0" . $i : $i);
173  if ($_SESSION["pay_statistics"]["til"]["month"] == $i)
174  {
175  $this->tpl->setVariable("LOOP_TIL_MONTH_SELECTED", " selected");
176  }
177  $this->tpl->parseCurrentBlock("loop_til_month");
178  }
179  for ($i = 2004; $i <= date("Y"); $i++)
180  {
181  $this->tpl->setCurrentBlock("loop_from_year");
182  $this->tpl->setVariable("LOOP_FROM_YEAR", $i);
183  if ($_SESSION["pay_statistics"]["from"]["year"] == $i)
184  {
185  $this->tpl->setVariable("LOOP_FROM_YEAR_SELECTED", " selected");
186  }
187  $this->tpl->parseCurrentBlock("loop_from_year");
188  $this->tpl->setCurrentBlock("loop_til_year");
189  $this->tpl->setVariable("LOOP_TIL_YEAR", $i);
190  if ($_SESSION["pay_statistics"]["til"]["year"] == $i)
191  {
192  $this->tpl->setVariable("LOOP_TIL_YEAR_SELECTED", " selected");
193  }
194  $this->tpl->parseCurrentBlock("loop_til_year");
195  }
196 
197  if(!$_SESSION['pay_statistics']['updateView'])
198  {
199  $this->tpl->setVariable('FILTER_MESSAGE', $this->lng->txt('statistics_filter_advice'));
200  return true;
201  }
202 
203  $this->__initBookingObject();
204 
205  if(!count($bookings = $this->booking_obj->getBookings()))
206  {
207  ilUtil::sendInfo($this->lng->txt('paya_no_bookings'));
208 
209  return true;
210  }
211 # $this->__showButton('excelExport',$this->lng->txt('excel_export'));
212 
213  $img_change = "<img src=\"".ilUtil::getImagePath("edit.gif")."\" alt=\"".
214  $this->lng->txt("edit")."\" title=\"".$this->lng->txt("edit").
215  "\" border=\"0\" vspace=\"0\"/>";
216 
217  include_once 'Services/User/classes/class.ilObjUser.php';
218  $object_title_cache = array();
219  $user_title_cache = array();
220 
221  $counter = 0;
222  foreach($bookings as $booking)
223  {
224  if(array_key_exists($booking['ref_id'], $object_title_cache))
225  {
226  $tmp_obj = $object_title_cache[$booking['ref_id']];
227  }
228  else
229  {
230  $tmp_obj = ilObject::_lookupTitle(ilObject::_lookupObjId($booking['ref_id']));
231  $object_title_cache[$booking['ref_id']] = $tmp_obj;
232  }
233  if(array_key_exists($booking['b_vendor_id'], $user_title_cache))
234  {
235  $tmp_vendor = $user_title_cache[$booking['b_vendor_id']];
236  }
237  else
238  {
239  $tmp_vendor = ilObjUser::_lookupLogin($booking['b_vendor_id']);
240  $user_title_cache[$booking['b_vendor_id']] = $tmp_vendor;
241  }
242  if(array_key_exists($booking['customer_id'], $user_title_cache))
243  {
244  $tmp_purchaser = $user_title_cache[$booking['customer_id']];
245  }
246  else
247  {
248  $tmp_purchaser = ilObjUser::_lookupLogin($booking['customer_id']);
249  $user_title_cache[$booking['customer_id']] = $tmp_purchaser;
250  }
251 
252  $transaction = $booking['transaction_extern'];
253  switch ($booking['b_pay_method'])
254  {
255  case $this->pobject->PAY_METHOD_BILL :
256  $transaction .= " (" . $this->lng->txt("pays_bill") . ")";
257  break;
258  case $this->pobject->PAY_METHOD_BMF :
259  $transaction .= " (" . $this->lng->txt("pays_bmf") . ")";
260  break;
261  case $this->pobject->PAY_METHOD_PAYPAL :
262  $transaction .= " (" . $this->lng->txt("pays_paypal") . ")";
263  break;
264  }
265  $f_result[$counter][] = $transaction;
266  $f_result[$counter][] = ($tmp_obj != '' ? $tmp_obj : $this->lng->txt('object_deleted'));
267  $f_result[$counter][] = ($tmp_vendor != '' ? '['.$tmp_vendor.']' : $this->lng->txt('user_deleted'));
268  $f_result[$counter][] = ($tmp_purchaser != '' ? '['.$tmp_purchaser.']' : $this->lng->txt('user_deleted'));
269  $f_result[$counter][] = date('Y-m-d H:i:s', $booking['order_date']);
270 
271  if($booking['duration'] == 0)
272  {
273  $booking['duration'] = $this->lng->txt('unlimited_duration');
274  }
275 
276  $f_result[$counter][] = $booking['duration'];
277  $f_result[$counter][] = ilFormat::_getLocalMoneyFormat($booking['price']);
278  $f_result[$counter][] = $booking['discount'];
279 
280  $payed_access = $booking['payed'] ?
281  $this->lng->txt('yes') :
282  $this->lng->txt('no');
283 
284  $payed_access .= '/';
285  $payed_access .= $booking['access'] ?
286  $this->lng->txt('yes') :
287  $this->lng->txt('no');
288 
289  $f_result[$counter][] = $payed_access;
290 
291  $this->ctrl->setParameter($this,"booking_id",$booking['booking_id']);
292 # $link_change = "<a href=\"".$this->ctrl->getLinkTarget($this,"editStatistic")."\"> ".
293 # $img_change."</a>";
294  $link_change = "<div class=\"il_ContainerItemCommands\"><a class=\"il_ContainerItemCommand\" href=\"".$this->ctrl->getLinkTarget($this,"editStatistic")."\">".$this->lng->txt("edit")."</a></div>";
295 
296  $f_result[$counter][] = $link_change;
297 
298  unset($tmp_obj);
299  unset($tmp_vendor);
300  unset($tmp_purchaser);
301 
302  ++$counter;
303  }
304  return $this->__showStatisticTable($f_result);
305  }
306 
307  function excelExport()
308  {
309  include_once './payment/classes/class.ilPaymentExcelWriterAdapter.php';
310 
311  $pewa =& new ilPaymentExcelWriterAdapter('payment_vendors.xls');
312 
313  // add/fill worksheet
314  $this->addStatisticWorksheet($pewa);
315 
316  // HEADER SENT
317 
318  $workbook =& $pewa->getWorkbook();
319  @$workbook->close();
320  }
321 
322  function addStatisticWorksheet(&$pewa)
323  {
324  include_once './payment/classes/class.ilPaymentVendors.php';
325 
326  $this->__initBookingObject();
327 
328  $workbook =& $pewa->getWorkbook();
329  $worksheet =& $workbook->addWorksheet($this->lng->txt('bookings'));
330 
331  $worksheet->mergeCells(0,0,0,8);
332  $worksheet->setColumn(0,0,16);
333  $worksheet->setColumn(0,1,32);
334  $worksheet->setColumn(0,2,32);
335  $worksheet->setColumn(0,3,16);
336  $worksheet->setColumn(0,4,16);
337  $worksheet->setColumn(0,5,16);
338  $worksheet->setColumn(0,6,24);
339  $worksheet->setColumn(0,7,8);
340  $worksheet->setColumn(0,8,12);
341  $worksheet->setColumn(0,9,16);
342 
343  //$title = $this->lng->txt('paya_statistic');
344  $title = $this->lng->txt('bookings');
345  $title .= ' '.$this->lng->txt('as_of');
346  $title .= strftime('%Y-%m-%d %R',time());
347 
348  $worksheet->writeString(0,0,$title,$pewa->getFormatTitle());
349 
350  $worksheet->writeString(1,0,$this->lng->txt('payment_system'),$pewa->getFormatHeader());
351  $worksheet->writeString(1,1,$this->lng->txt('paya_transaction'),$pewa->getFormatHeader());
352  $worksheet->writeString(1,2,$this->lng->txt('title'),$pewa->getFormatHeader());
353  $worksheet->writeString(1,3,$this->lng->txt('paya_vendor'),$pewa->getFormatHeader());
354  $worksheet->writeString(1,4,$this->lng->txt('pays_cost_center'),$pewa->getFormatHeader());
355  $worksheet->writeString(1,5,$this->lng->txt('paya_customer'),$pewa->getFormatHeader());
356  $worksheet->writeString(1,6,$this->lng->txt('paya_order_date'),$pewa->getFormatHeader());
357  $worksheet->writeString(1,7,$this->lng->txt('duration'),$pewa->getFormatHeader());
358  $worksheet->writeString(1,8,$this->lng->txt('price_a'),$pewa->getFormatHeader());
359  $worksheet->writeString(1,9,$this->lng->txt('paya_payed_access'),$pewa->getFormatHeader());
360 
361  if(!count($bookings = $this->booking_obj->getBookings()))
362  {
363  return false;
364  }
365 
366  include_once 'Services/User/classes/class.ilObjUser.php';
367  $object_title_cache = array();
368  $user_title_cache = array();
369 
370  $counter = 2;
371  foreach($bookings as $booking)
372  {
373  if(array_key_exists($booking['ref_id'], $object_title_cache))
374  {
375  $tmp_obj = $object_title_cache[$booking['ref_id']];
376  }
377  else
378  {
379  $tmp_obj = ilObject::_lookupTitle(ilObject::_lookupObjId($booking['ref_id']));
380  $object_title_cache[$booking['ref_id']] = $tmp_obj;
381  }
382  if(array_key_exists($booking['b_vendor_id'], $user_title_cache))
383  {
384  $tmp_vendor = $user_title_cache[$booking['b_vendor_id']];
385  }
386  else
387  {
388  $tmp_vendor = ilObjUser::_lookupLogin($booking['b_vendor_id']);
389  $user_title_cache[$booking['b_vendor_id']] = $tmp_vendor;
390  }
391  if(array_key_exists($booking['customer_id'], $user_title_cache))
392  {
393  $tmp_purchaser = $user_title_cache[$booking['customer_id']];
394  }
395  else
396  {
397  $tmp_purchaser = ilObjUser::_lookupLogin($booking['customer_id']);
398  $user_title_cache[$booking['customer_id']] = $tmp_purchaser;
399  }
400 
401  switch ($booking['b_pay_method'])
402  {
403  case $this->pobject->PAY_METHOD_BILL :
404  $pay_method = $this->lng->txt("pays_bill");
405  break;
406  case $this->pobject->PAY_METHOD_BMF :
407  $pay_method = $this->lng->txt("pays_bmf");
408  break;
409  case $this->pobject->PAY_METHOD_PAYPAL :
410  $pay_method = $this->lng->txt("pays_paypal");
411  break;
412  }
413  $worksheet->writeString($counter,0,$pay_method);
414  $worksheet->writeString($counter,1,$booking['transaction_extern']);
415  $worksheet->writeString($counter,2,($tmp_obj != '' ? $tmp_obj : $this->lng->txt('object_deleted')));
416  $worksheet->writeString($counter,3,($tmp_vendor != '' ? $tmp_vendor : $this->lng->txt('user_deleted')));
417  $worksheet->writeString($counter,4,ilPaymentVendors::_getCostCenter($booking['b_vendor_id']));
418  $worksheet->writeString($counter,5,($tmp_purchaser != '' ? $tmp_purchaser : $this->lng->txt('user_deleted')));
419  $worksheet->writeString($counter,6,strftime('%Y-%m-%d %R',$booking['order_date']));
420  /*
421  $worksheet->write($counter,5,ilUtil::excelTime(date('Y',$booking['order_date']),
422  date('m',$booking['order_date']),
423  date('d',$booking['order_date']),
424  date('H',$booking['order_date']),
425  date('i',$booking['order_date']),
426  date('s',$booking['order_date'])),$pewa->getFormatDate());
427  */
428  $worksheet->writeString($counter,7,$booking['duration']);
429  $worksheet->writeString($counter,8,$booking['price']);
430 
431  $payed_access = $booking['payed'] ?
432  $this->lng->txt('yes') :
433  $this->lng->txt('no');
434 
435  $payed_access .= '/';
436  $payed_access .= $booking['access'] ?
437  $this->lng->txt('yes') :
438  $this->lng->txt('no');
439 
440  $worksheet->writeString($counter,9,$payed_access);
441 
442  unset($tmp_obj);
443  unset($tmp_vendor);
444  unset($tmp_purchaser);
445 
446  ++$counter;
447  }
448  }
449 
450  function editStatistic($a_show_confirm_delete = false)
451  {
452  if(!isset($_GET['booking_id']))
453  {
454  ilUtil::sendInfo($this->lng->txt('paya_no_booking_id_given'));
455  $this->showStatistics();
456 
457  return true;
458  }
459 
460  $this->showButton('showStatistics',$this->lng->txt('back'));
461 
462  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.paya_edit_statistic.html','payment');
463  $this->ctrl->setParameter($this,'booking_id',(int) $_GET['booking_id']);
464 
465  // confirm delete
466  if($a_show_confirm_delete)
467  {
468  $this->tpl->setCurrentBlock("confirm_delete");
469  $this->tpl->setVariable("CONFIRM_FORMACTION",$this->ctrl->getFormAction($this));
470  $this->tpl->setVariable("TXT_CANCEL",$this->lng->txt('cancel'));
471  $this->tpl->setVariable("CONFIRM_CMD",'performDelete');
472  $this->tpl->setVariable("TXT_CONFIRM",$this->lng->txt('confirm'));
473  $this->tpl->parseCurrentBlock();
474  }
475 
476 
477  $this->__initBookingObject();
478  $bookings = $this->booking_obj->getBookings();
479  $booking = $bookings[(int) $_GET['booking_id']];
480 
481  // get customer_obj
482  $tmp_user = ilObjectFactory::getInstanceByObjId($booking['customer_id'], false);
483 
484 
485 
486  $this->tpl->setVariable("STAT_FORMACTION",$this->ctrl->getFormAction($this));
487  $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_usr.gif'));
488  $this->tpl->setVariable("ALT_IMG",$this->lng->txt('obj_usr'));
489  if(is_object($tmp_user))
490  {
491  $this->tpl->setVariable('TITLE', $tmp_user->getFullname().' ['.$tmp_user->getLogin().']');
492  }
493  else
494  {
495  $this->tpl->setVariable('TITLE', $this->lng->txt('user_deleted'));
496  }
497 
498  // TXT
499  $pObj = new ilPaymentObject($this->user_obj, $booking["pobject_id"]);
500  $tmp_obj = ilObject::_lookupTitle(ilObject::_lookupObjId($pObj->getRefId()));
501 
502  $this->tpl->setVariable("TXT_OBJECT",$this->lng->txt('title'));
503  $this->tpl->setVariable("OBJECT", ($tmp_obj != '' ? $tmp_obj : $this->lng->txt('object_deleted')));
504 
505  $this->tpl->setVariable("TXT_TRANSACTION",$this->lng->txt('paya_transaction'));
506  $this->tpl->setVariable("TXT_VENDOR",$this->lng->txt('paya_vendor'));
507  $this->tpl->setVariable("TXT_PAY_METHOD",$this->lng->txt('paya_pay_method'));
508  $this->tpl->setVariable("TXT_ORDER_DATE",$this->lng->txt('paya_order_date'));
509  $this->tpl->setVariable("TXT_DURATION",$this->lng->txt('duration'));
510  $this->tpl->setVariable("TXT_PRICE",$this->lng->txt('price_a'));
511  $this->tpl->setVariable("TXT_PAYED",$this->lng->txt('paya_payed'));
512  $this->tpl->setVariable("TXT_ACCESS",$this->lng->txt('paya_access'));
513 
514  $this->tpl->setVariable("TRANSACTION",$booking['transaction']);
515 
516  $tmp_vendor = ilObjectFactory::getInstanceByObjId($booking['b_vendor_id'], false);
517  if(is_object($tmp_vendor))
518  {
519  $this->tpl->setVariable('VENDOR', $tmp_vendor->getFullname().' ['.$tmp_vendor->getLogin().']');
520  }
521  else
522  {
523  $this->tpl->setVariable('VENDOR', $this->lng->txt('user_deleted'));
524  }
525 
526  switch($booking['b_pay_method'])
527  {
528  case $this->pobject->PAY_METHOD_BILL:
529  $this->tpl->setVariable("PAY_METHOD",$this->lng->txt('pays_bill'));
530  break;
531 
532  case $this->pobject->PAY_METHOD_BMF:
533  $this->tpl->setVariable("PAY_METHOD",$this->lng->txt('pays_bmf'));
534  break;
535 
536  case $this->pobject->PAY_METHOD_PAYPAL:
537  $this->tpl->setVariable("PAY_METHOD",$this->lng->txt('pays_paypal'));
538  break;
539 
540  default:
541  $this->tpl->setVariable("PAY_METHOD",$this->lng->txt('paya_pay_method_not_specified'));
542  break;
543  }
544  $this->tpl->setVariable("ORDER_DATE",date('Y m d H:i:s',$booking['order_date']));
545 
546  if($booking['duration'] != 0)
547  {
548  $this->tpl->setVariable("DURATION",$booking['duration'].' '.$this->lng->txt('paya_months'));
549  }
550  else
551  {
552  $this->tpl->setVariable("DURATION",$this->lng->txt("unlimited_duration"));
553 
554  }
555 
556  $this->tpl->setVariable("PRICE",ilFormat::_getLocalMoneyFormat($booking['price']));
557 
558  $yes_no = array(0 => $this->lng->txt('no'),1 => $this->lng->txt('yes'));
559 
560  $this->tpl->setVariable("PAYED",ilUtil::formSelect((int) $booking['payed'],'payed',$yes_no,false,true));
561  $this->tpl->setVariable("ACCESS",ilUtil::formSelect((int) $booking['access'],'access',$yes_no,false,true));
562 
563  // buttons
564  $this->tpl->setVariable("INPUT_CMD",'updateStatistic');
565  $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('save'));
566 
567  $this->tpl->setVariable("DELETE_CMD",'deleteStatistic');
568  $this->tpl->setVariable("DELETE_VALUE",$this->lng->txt('delete'));
569  }
570 
571  function updateStatistic()
572  {
573  if(!isset($_GET['booking_id']))
574  {
575  ilUtil::sendInfo($this->lng->txt('paya_no_booking_id_given'));
576  $this->showStatistics();
577 
578  return true;
579  }
580  $this->__initBookingObject();
581 
582  $this->booking_obj->setBookingId((int) $_GET['booking_id']);
583  $this->booking_obj->setAccess((int) $_POST['access']);
584  $this->booking_obj->setPayed((int) $_POST['payed']);
585 
586  if($this->booking_obj->update())
587  {
588  ilUtil::sendInfo($this->lng->txt('paya_updated_booking'));
589 
590  $this->showStatistics();
591  return true;
592  }
593  else
594  {
595  ilUtil::sendInfo($this->lng->txt('paya_error_update_booking'));
596  $this->showStatistics();
597 
598  return true;
599  }
600  }
601 
602  function deleteStatistic()
603  {
604  if(!isset($_GET['booking_id']))
605  {
606  ilUtil::sendInfo($this->lng->txt('paya_no_booking_id_given'));
607  $this->showStatistics();
608 
609  return true;
610  }
611  ilUtil::sendInfo($this->lng->txt('paya_sure_delete_stat'));
612 
613  $this->editStatistic(true);
614 
615  return true;
616  }
617 
618  function performDelete()
619  {
620  if(!isset($_GET['booking_id']))
621  {
622  ilUtil::sendInfo($this->lng->txt('paya_no_booking_id_given'));
623  $this->showStatistics();
624 
625  return true;
626  }
627 
628  $this->__initBookingObject();
629  $this->booking_obj->setBookingId((int) $_GET['booking_id']);
630  if(!$this->booking_obj->delete())
631  {
632  die('Error deleting booking');
633  }
634  ilUtil::sendInfo($this->lng->txt('pay_deleted_booking'));
635 
636  $this->showStatistics();
637 
638  return true;
639  }
640 
642  {
643  global $tree;
644 
645  include_once './payment/classes/class.ilPaymentObjectSelector.php';
646 
647  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.paya_object_selector.html",'payment');
648  $this->showButton('showStatistics',$this->lng->txt('back'));
649 
650  ilUtil::sendInfo($this->lng->txt("paya_select_object_to_sell"));
651 
652  $exp = new ilPaymentObjectSelector($this->ctrl->getLinkTarget($this,'showObjectSelector'), strtolower(get_class($this)));
653  $exp->setExpand($_GET["paya_link_expand"] ? $_GET["paya_link_expand"] : $tree->readRootId());
654  $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'showObjectSelector'));
655 
656  $exp->setOutput(0);
657 
658  $this->tpl->setVariable("EXPLORER",$exp->getOutput());
659 
660  return true;
661  }
662 
663  function searchUser()
664  {
665  if(!isset($_GET['sell_id']))
666  {
667  ilUtil::sendInfo($this->lng->txt('paya_no_booking_id_given'));
668  $this->showObjectSelector();
669 
670  return false;
671  }
672 
673  $this->tpl->addBlockFile("ADM_CONTENT","adm_content","tpl.paya_user_search.html",'payment');
674  $this->showButton('showObjectSelector',$this->lng->txt('back'));
675 
676  $this->lng->loadLanguageModule('search');
677 
678  $this->ctrl->setParameter($this, "sell_id", $_GET["sell_id"]);
679  $this->tpl->setVariable("F_ACTION",$this->ctrl->getFormAction($this));
680  $this->tpl->setVariable("SEARCH_ASSIGN_USR",$this->lng->txt("search_user"));
681  $this->tpl->setVariable("SEARCH_SEARCH_TERM",$this->lng->txt("search_search_term"));
682  $this->tpl->setVariable("SEARCH_VALUE",$_SESSION["pays_search_str_user_sp"] ? $_SESSION["pays_search_str_user_sp"] : "");
683  $this->tpl->setVariable("BTN2_VALUE",$this->lng->txt("cancel"));
684  $this->tpl->setVariable("BTN1_VALUE",$this->lng->txt("search"));
685  $this->tpl->setVariable("SEARCH","performSearch");
686  $this->tpl->setVariable("CANCEL","showStatistics");
687 
688  return true;
689  }
690 
691  function performSearch()
692  {
693  // SAVE it to allow sort in tables
694  $_SESSION["pays_search_str_user_sp"] = $_POST["search_str"] = $_POST["search_str"] ? $_POST["search_str"] : $_SESSION["pays_search_str_user_sp"];
695 
696 
697  if(!trim($_POST["search_str"]))
698  {
699  ilUtil::sendInfo($this->lng->txt("search_no_search_term"));
700  $this->showStatistics();
701 
702  return false;
703  }
704  if(!count($result = $this->__search(ilUtil::stripSlashes($_POST["search_str"]))))
705  {
706  ilUtil::sendInfo($this->lng->txt("search_no_match"));
707  $this->searchUser();
708 
709  return false;
710  }
711 
712  if(!isset($_GET['sell_id']))
713  {
714  ilUtil::sendInfo($this->lng->txt('paya_no_booking_id_given'));
715  $this->showObjectSelector();
716 
717  return false;
718  }
719 
720  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.paya_usr_selection.html",'payment');
721  $this->ctrl->setParameter($this, "sell_id", $_GET["sell_id"]);
722  $this->showButton("searchUser",$this->lng->txt("back"));
723 
724  $counter = 0;
725  $f_result = array();
726  foreach($result as $user)
727  {
728  if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($user["id"],false))
729  {
730  continue;
731  }
732  $f_result[$counter][] = ilUtil::formRadiobutton(0,"user_id",$user["id"]);
733  $f_result[$counter][] = $tmp_obj->getLogin();
734  $f_result[$counter][] = $tmp_obj->getFirstname();
735  $f_result[$counter][] = $tmp_obj->getLastname();
736 
737  unset($tmp_obj);
738  ++$counter;
739  }
740  $this->__showSearchUserTable($f_result);
741  }
742 
743  function addCustomer()
744  {
745  if ($_POST["sell_id"] != "") $_GET["sell_id"] = $_POST["sell_id"];
746  if ($_GET["user_id"] != "") $_POST["user_id"] = $_GET["user_id"];
747 
748  if(!isset($_GET['sell_id']))
749  {
750  ilUtil::sendInfo($this->lng->txt('paya_no_booking_id_given'));
751  $this->showObjectSelector();
752 
753  return true;
754  }
755 
756  if(!isset($_POST['user_id']))
757  {
758  ilUtil::sendInfo($this->lng->txt('paya_no_user_id_given'));
759  $this->searchUser();
760 
761  return true;
762  }
763 
764  $this->ctrl->setParameter($this, "sell_id", $_GET["sell_id"]);
765  $this->showButton('searchUser',$this->lng->txt('back'));
766 
767  $this->ctrl->setParameter($this, "user_id", $_POST["user_id"]);
768 
769  $pObjectId = ilPaymentObject::_lookupPobjectId($_GET["sell_id"]);
770  $obj =& new ilPaymentObject($this->user_obj, $pObjectId);
771 
772  // get obj
773  $tmp_obj =& ilObjectFactory::getInstanceByRefId($_GET["sell_id"], false);
774  // get customer_obj
775  $tmp_user =& ilObjectFactory::getInstanceByObjId($_POST["user_id"]);
776  // get vendor_obj
777  $tmp_vendor =& ilObjectFactory::getInstanceByObjId($obj->getVendorId());
778 
779  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.paya_add_customer.html','payment');
780 
781  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
782 
783  $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_usr.gif'));
784  $this->tpl->setVariable("ALT_IMG",$this->lng->txt('obj_usr'));
785  $this->tpl->setVariable("TITLE",$tmp_user->getFullname().' ['.$tmp_user->getLogin().']');
786 
787  // TXT
788  $this->tpl->setVariable("TXT_TRANSACTION",$this->lng->txt('paya_transaction'));
789  $this->tpl->setVariable("TRANSACTION",ilUtil::prepareFormOutput($_POST["transaction"], true));
790 
791  $this->tpl->setVariable("TXT_OBJECT",$this->lng->txt('title'));
792  if($tmp_obj)
793  {
794  $this->tpl->setVariable("OBJECT",$tmp_obj->getTitle());
795  }
796  else
797  {
798  $this->tpl->setVariable("OBJECT",$this->lng->txt('object_not_found'));
799  }
800  $this->tpl->setVariable("TXT_VENDOR",$this->lng->txt('paya_vendor'));
801  $this->tpl->setVariable("VENDOR",$tmp_vendor->getFullname().' ['.$tmp_vendor->getLogin().']');
802 
803  $this->tpl->setVariable("TXT_PAY_METHOD",$this->lng->txt('paya_pay_method'));
804  $this->tpl->setVariable("TXT_PAY_METHOD_BILL",$this->lng->txt('pays_bill'));
805  $this->tpl->setVariable("TXT_PAY_METHOD_BMF",$this->lng->txt('pays_bmf'));
806  $this->tpl->setVariable("TXT_PAY_METHOD_PAYPAL",$this->lng->txt('pays_paypal'));
807  $this->tpl->setVariable("PAY_METHOD_".$_POST["pay_method"], " selected");
808 
809  $this->tpl->setVariable("TXT_ORDER_DATE",$this->lng->txt('paya_order_date'));
810  $this->tpl->setVariable('ORDER_DATE',ilDatePresentation::formatDate(new ilDateTime(time(),IL_CAL_UNIX)));
811 
812  $this->tpl->setVariable("TXT_DURATION",$this->lng->txt('duration'));
813  include_once './payment/classes/class.ilPaymentPrices.php';
814  $prices_obj =& new ilPaymentPrices($pObjectId);
815  if (is_array($prices = $prices_obj->getPrices()))
816  {
817  foreach($prices as $price)
818  {
819  $this->tpl->setCurrentBlock("duration_loop");
820  if ($_POST["duration"] == $price["price_id"]) $this->tpl->setVariable("DURATION_LOOP_SELECTED", " selected");
821  $this->tpl->setVariable("DURATION_LOOP_ID", $price["price_id"]);
822  $this->tpl->setVariable("DURATION_LOOP_NAME", $price["duration"]." ".$this->lng->txt("paya_months").", ".ilPaymentPrices::_getPriceString($price["price_id"]));
823  $this->tpl->parseCurrentBlock();
824  }
825  }
826 
827  $this->tpl->setVariable("TXT_PAYED",$this->lng->txt('paya_payed'));
828  if ($_POST["payed"] == 1) $this->tpl->setVariable("PAYED_1", " selected");
829  $this->tpl->setVariable("TXT_ACCESS",$this->lng->txt('paya_access'));
830  if ($_POST["access"] == 1) $this->tpl->setVariable("ACCESS_1", " selected");
831 
832  $this->tpl->setVariable("TXT_NO",$this->lng->txt('no'));
833  $this->tpl->setVariable("TXT_YES",$this->lng->txt('yes'));
834  $this->tpl->setVariable("TXT_SAVE",$this->lng->txt('save'));
835  $this->tpl->setVariable("TXT_CANCEL",$this->lng->txt('cancel'));
836  $this->tpl->setVariable("STATISTICS","showStatistics");
837 
838  }
839 
840  function saveCustomer()
841  {
842  global $ilias,$ilObjDataCache, $ilUser;
843 
844 
845  if(!isset($_GET['sell_id']))
846  {
847  ilUtil::sendInfo($this->lng->txt('paya_error_no_object_id_given'));
848  $this->showObjectSelector();
849 
850  return true;
851  }
852 
853  if(!isset($_GET['user_id']))
854  {
855  ilUtil::sendInfo($this->lng->txt('paya_error_no_user_id_given'));
856  $this->searchUser();
857 
858  return true;
859  }
860 
861  if ($_POST["pay_method"] == "" ||
862  $_POST["duration"] == "")
863  {
864  ilUtil::sendInfo($this->lng->txt('paya_error_mandatory_fields'));
865  $this->addCustomer();
866 
867  return true;
868  }
869 
870  $pObjectId = ilPaymentObject::_lookupPobjectId($_GET["sell_id"]);
871  $obj =& new ilPaymentObject($this->user_obj, $pObjectId);
872 
873  $this->__initBookingObject();
874 
875  $inst_id_time = $ilias->getSetting('inst_id').'_'.$this->user_obj->getId().'_'.substr((string) time(),-3);
876  $transaction = $inst_id_time.substr(md5(uniqid(rand(), true)), 0, 4);
877  $this->booking_obj->setTransaction($transaction);
878  $this->booking_obj->setTransactionExtern($_POST["transaction"]);
879  $this->booking_obj->setPobjectId($pObjectId);
880  $this->booking_obj->setCustomerId($_GET["user_id"]);
881  $this->booking_obj->setVendorId($obj->getVendorId());
882  $this->booking_obj->setPayMethod((int) $_POST["pay_method"]);
883  $this->booking_obj->setOrderDate(time());
884  $price = ilPaymentPrices::_getPrice($_POST["duration"]);
885 
886  $this->booking_obj->setDuration($price["duration"]);
887  $this->booking_obj->setPrice(ilPaymentPrices::_getPriceString($_POST["duration"]));
888  $this->booking_obj->setAccess((int) $_POST['access']);
889  $this->booking_obj->setPayed((int) $_POST['payed']);
890  $this->booking_obj->setVoucher('');
891 
892  $obj_id = $ilObjDataCache->lookupObjId($obj->getRefId());
893  $obj_type = $ilObjDataCache->lookupType($obj_id);
894  $obj_title = $ilObjDataCache->lookupTitle($obj_id);
895 
896  include_once 'Services/Payment/classes/class.ilShopVatsList.php';
897  $oVAT = new ilShopVats((int)$obj->getVatId());
898  $obj_vat_rate = $oVAT->getRate();
899  $obj_vat_unit = $obj->getVat($this->booking_obj->getPrice());
900 
901  $this->booking_obj->setObjectTitle($obj_title);
902  $this->booking_obj->setVatRate($obj_vat_rate);
903  $this->booking_obj->setVatUnit($obj_vat_unit);
904 
905  include_once './payment/classes/class.ilPayMethods.php';
906  $save_user_adr_bill = (int) ilPayMethods::_enabled('save_user_adr_bill') ? 1 : 0;
907  $save_user_adr_bmf = (int) ilPayMethods::_enabled('save_user_adr_bmf') ? 1 : 0;
908  $save_user_adr_paypal =(int) ilPayMethods::_enabled('save_user_adr_paypal') ? 1 : 0;
909  $save_user_adr_epay =(int) ilPayMethods::_enabled('save_user_adr_epay') ? 1 : 0;
910 
911  if($save_user_adr_bill == 1 || $save_user_adr_bmf == 1
912  || $save_user_adr_paypal == 1 || $save_user_adr_epay == 1)
913  {
914  global $ilObjUser;
915  $user_id[] = $_GET["user_id"];
916 
917  $cust_obj = ilObjUser::_readUsersProfileData($user_id);
918 
919  $this->booking_obj->setStreet($cust_obj[$_GET["user_id"]]['street'],'');
920 
921  $this->booking_obj->setZipcode($cust_obj[$_GET["user_id"]]['zipcode']);
922  $this->booking_obj->setCity($cust_obj[$_GET["user_id"]]['city']);
923  $this->booking_obj->setCountry($cust_obj[$_GET["user_id"]]['country']);
924  }
925 
926  if($this->booking_obj->add())
927  {
928  ilUtil::sendInfo($this->lng->txt('paya_customer_added_successfully'));
929  $this->showStatistics();
930  }
931  else
932  {
933  ilUtil::sendInfo($this->lng->txt('paya_error_adding_customer'));
934  $this->addCustomer();
935  }
936 
937  return true;
938  }
939 
940  // PRIVATE
941  function __showStatisticTable($a_result_set)
942  {
943  $tbl =& $this->initTableGUI();
944  $tpl =& $tbl->getTemplateObject();
945 
946  // SET FORMAACTION
947  $tpl->setCurrentBlock("tbl_form_header");
948 
949  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
950  $tpl->parseCurrentBlock();
951 
952  $tbl->setTitle($this->lng->txt("bookings"),"icon_pays.gif",$this->lng->txt("bookings"));
953  $tbl->setHeaderNames(array($this->lng->txt("paya_transaction"),
954  $this->lng->txt("title"),
955  $this->lng->txt("paya_vendor"),
956  $this->lng->txt("paya_customer"),
957  $this->lng->txt("paya_order_date"),
958  $this->lng->txt("duration"),
959  $this->lng->txt("price_a"),
960  $this->lng->txt("paya_coupons_coupons"),
961  $this->lng->txt("paya_payed_access"),
962  ''));
963  $header_params = $this->ctrl->getParameterArray($this,'');
964  $tbl->setHeaderVars(array("transaction",
965  "title",
966  "vendor",
967  "customer",
968  "order_date",
969  "duration",
970  "price",
971  "discount",
972  "payed_access",
973  "options"),$header_params);
974 
975  $offset = $_GET["offset"];
976  $order = $_GET["sort_by"];
977  $direction = $_GET["sort_order"] ? $_GET['sort_order'] : 'desc';
978 
979  $tbl->setOrderColumn($order,'order_date');
980  $tbl->setOrderDirection($direction);
981  $tbl->setOffset($offset);
982  $tbl->setLimit($_GET["limit"]);
983  $tbl->setMaxCount(count($a_result_set));
984  $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
985  $tbl->setData($a_result_set);
986 
987  $tpl->setVariable("COLUMN_COUNTS",10);
988  $tpl->setCurrentBlock("plain_buttons");
989  $tpl->setVariable("PBTN_NAME","excelExport");
990  $tpl->setVariable("PBTN_VALUE",$this->lng->txt("excel_export"));
991  $tpl->parseCurrentBlock();
992 
993  $tbl->render();
994 
995  $this->tpl->setVariable("STATISTIC_TABLE",$tbl->tpl->get());
996 
997  return true;
998  }
999 
1001  {
1002  include_once './payment/classes/class.ilPaymentBookings.php';
1003 
1004  $this->booking_obj =& new ilPaymentBookings($this->user_obj->getId());
1005  }
1006 
1007  function __showButton($a_cmd,$a_text,$a_target = '')
1008  {
1009  $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
1010 
1011  // display button
1012  $this->tpl->setCurrentBlock("btn_cell");
1013  $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTarget($this,$a_cmd));
1014  $this->tpl->setVariable("BTN_TXT",$a_text);
1015  if($a_target)
1016  {
1017  $this->tpl->setVariable("BTN_TARGET",$a_target);
1018  }
1019 
1020  $this->tpl->parseCurrentBlock();
1021  }
1022 
1023  function __search($a_search_string)
1024  {
1025  include_once("./classes/class.ilSearch.php");
1026 
1027  $this->lng->loadLanguageModule("content");
1028 
1029  $search =& new ilSearch($this->user_obj->getId());
1030  $search->setPerformUpdate(false);
1031  $search->setSearchString(ilUtil::stripSlashes($a_search_string));
1032  $search->setCombination("and");
1033  $search->setSearchFor(array(0 => 'usr'));
1034  $search->setSearchType('new');
1035 
1036  if($search->validate($message))
1037  {
1038  $search->performSearch();
1039  }
1040  else
1041  {
1042  ilUtil::sendInfo($message,true);
1043  $this->ctrl->redirect($this,"searchUser");
1044  }
1045  return $search->getResultByType('usr');
1046  }
1047  function __showSearchUserTable($a_result_set)
1048  {
1049  $tbl =& $this->initTableGUI();
1050  $tpl =& $tbl->getTemplateObject();
1051 
1052 
1053  // SET FORMACTION
1054  $tpl->setCurrentBlock("tbl_form_header");
1055  $this->ctrl->setParameter($this, "sell_id", $_GET["sell_id"]);
1056  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
1057  $tpl->parseCurrentBlock();
1058 
1059  $tpl->setCurrentBlock("tbl_action_btn");
1060  $tpl->setVariable("BTN_NAME","addCustomer");
1061  $tpl->setVariable("BTN_VALUE",$this->lng->txt("add"));
1062  $tpl->parseCurrentBlock();
1063 
1064  $tpl->setCurrentBlock("tbl_action_btn");
1065  $tpl->setVariable("BTN_NAME","showStatistics");
1066  $tpl->setVariable("BTN_VALUE",$this->lng->txt("cancel"));
1067  $tpl->parseCurrentBlock();
1068 
1069  $tpl->setCurrentBlock("tbl_action_row");
1070  $tpl->setVariable("COLUMN_COUNTS",5);
1071  $tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
1072  $tpl->parseCurrentBlock();
1073 
1074  $tbl->setTitle($this->lng->txt("users"),"icon_usr.gif",$this->lng->txt("crs_header_edit_members"));
1075  $tbl->setHeaderNames(array("",
1076  $this->lng->txt("login"),
1077  $this->lng->txt("firstname"),
1078  $this->lng->txt("lastname")));
1079  $this->ctrl->setParameter($this, "cmd", "addCustomer");
1080  $header_params = $this->ctrl->getParameterArray($this,'');
1081  $tbl->setHeaderVars(array("",
1082  "login",
1083  "firstname",
1084  "lastname"), $header_params);
1085 
1086  $tbl->setColumnWidth(array("3%","32%","32%","32%"));
1087 
1088  $this->setTableGUIBasicData($tbl,$a_result_set);
1089  $tbl->render();
1090 
1091  $this->tpl->setVariable("SEARCH_RESULT_TABLE",$tbl->tpl->get());
1092 
1093  return true;
1094  }
1095 }
1096 ?>