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