00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00032 include_once './payment/classes/class.ilPaymentObject.php';
00033
00034 class ilPaymentStatisticGUI extends ilPaymentBaseGUI
00035 {
00036 var $ctrl;
00037
00038 var $lng;
00039 var $user_obj;
00040 var $pobject = null;
00041
00042 function ilPaymentStatisticGUI(&$user_obj)
00043 {
00044 global $ilCtrl;
00045
00046 $this->ctrl =& $ilCtrl;
00047 $this->ctrl->saveParameter($this, "baseClass");
00048
00049 $this->ilPaymentBaseGUI();
00050
00051 $this->user_obj =& $user_obj;
00052
00053 $this->pobject =& new ilPaymentObject($this->user_obj);
00054
00055 }
00059 function &executeCommand()
00060 {
00061 global $tree;
00062
00063 $cmd = $this->ctrl->getCmd();
00064 switch ($this->ctrl->getNextClass($this))
00065 {
00066 default:
00067 if(!$cmd = $this->ctrl->getCmd())
00068 {
00069 $cmd = 'showStatistics';
00070 }
00071 $this->$cmd();
00072 break;
00073 }
00074 }
00075
00076 function resetFilter()
00077 {
00078 unset($_SESSION["pay_statistics"]);
00079 unset($_POST["transaction_type"]);
00080 unset($_POST["transaction_value"]);
00081 unset($_POST["from"]["day"]);
00082 unset($_POST["from"]["month"]);
00083 unset($_POST["from"]["year"]);
00084 unset($_POST["til"]["day"]);
00085 unset($_POST["til"]["month"]);
00086 unset($_POST["til"]["year"]);
00087 unset($_POST["payed"]);
00088 unset($_POST["access"]);
00089 unset($_POST["customer"]);
00090 unset($_POST["pay_method"]);
00091 $this->showStatistics();
00092 }
00093
00094 function showStatistics()
00095 {
00096 $this->showButton('showObjectSelector',$this->lng->txt('paya_add_customer'));
00097
00098 if ($_POST["updateView"] == 1)
00099 {
00100 $_SESSION["pay_statistics"]["transaction_type"] = $_POST["transaction_type"];
00101 $_SESSION["pay_statistics"]["transaction_value"] = $_POST["transaction_value"];
00102 $_SESSION["pay_statistics"]["from"]["day"] = $_POST["from"]["day"];
00103 $_SESSION["pay_statistics"]["from"]["month"] = $_POST["from"]["month"];
00104 $_SESSION["pay_statistics"]["from"]["year"] = $_POST["from"]["year"];
00105 $_SESSION["pay_statistics"]["til"]["day"] = $_POST["til"]["day"];
00106 $_SESSION["pay_statistics"]["til"]["month"] = $_POST["til"]["month"];
00107 $_SESSION["pay_statistics"]["til"]["year"] = $_POST["til"]["year"];
00108 $_SESSION["pay_statistics"]["payed"] = $_POST["payed"];
00109 $_SESSION["pay_statistics"]["access"] = $_POST["access"];
00110 $_SESSION["pay_statistics"]["customer"] = $_POST["customer"];
00111 $_SESSION["pay_statistics"]["pay_method"] = $_POST["pay_method"];
00112 }
00113
00114 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.paya_statistic.html','payment');
00115
00116 $this->tpl->setVariable("TXT_FILTER",$this->lng->txt('pay_filter'));
00117 $this->tpl->setVariable("FORM_ACTION",$this->ctrl->getFormAction($this));
00118 $this->tpl->setVariable("TXT_TRANSACTION",$this->lng->txt('paya_transaction'));
00119 $this->tpl->setVariable("TXT_STARTING",$this->lng->txt('pay_starting'));
00120 $this->tpl->setVariable("TXT_ENDING",$this->lng->txt('pay_ending'));
00121 $this->tpl->setVariable("TXT_PAYED",$this->lng->txt('paya_payed'));
00122 $this->tpl->setVariable("TXT_ALL",$this->lng->txt('pay_all'));
00123 $this->tpl->setVariable("TXT_YES",$this->lng->txt('yes'));
00124 $this->tpl->setVariable("TXT_NO",$this->lng->txt('no'));
00125 $this->tpl->setVariable("TXT_BILL",$this->lng->txt('pays_bill'));
00126 $this->tpl->setVariable("TXT_BMF",$this->lng->txt('pays_bmf'));
00127 $this->tpl->setVariable("TXT_PAYPAL",$this->lng->txt('pays_paypal'));
00128 $this->tpl->setVariable("TXT_CUSTOMER",$this->lng->txt('paya_customer'));
00129 $this->tpl->setVariable("TXT_ACCESS",$this->lng->txt('paya_access'));
00130 $this->tpl->setVariable("TXT_PAYMENT",$this->lng->txt('payment_system'));
00131 $this->tpl->setVariable("TXT_ORDER_DATE_FROM",$this->lng->txt('pay_order_date_from'));
00132 $this->tpl->setVariable("TXT_ORDER_DATE_TIL",$this->lng->txt('pay_order_date_til'));
00133 $this->tpl->setVariable("TXT_UPDATE_VIEW",$this->lng->txt('pay_update_view'));
00134 $this->tpl->setVariable("TXT_RESET_FILTER",$this->lng->txt('pay_reset_filter'));
00135
00136 $this->tpl->setVariable("TRANSACTION_TYPE_" . $_SESSION["pay_statistics"]["transaction_type"], " selected");
00137 $this->tpl->setVariable("TRANSACTION_VALUE", ilUtil::prepareFormOutput($_SESSION["pay_statistics"]["transaction_value"], true));
00138 $this->tpl->setVariable("PAYED_" . $_SESSION["pay_statistics"]["payed"], " selected");
00139 $this->tpl->setVariable("ACCESS_" . $_SESSION["pay_statistics"]["access"], " selected");
00140 $this->tpl->setVariable("PAYMENT_" . $_SESSION["pay_statistics"]["pay_method"], " selected");
00141 $this->tpl->setVariable("CUSTOMER", ilUtil::prepareFormOutput($_SESSION["pay_statistics"]["customer"], true));
00142 for ($i = 1; $i <= 31; $i++)
00143 {
00144 $this->tpl->setCurrentBlock("loop_from_day");
00145 $this->tpl->setVariable("LOOP_FROM_DAY", $i < 10 ? "0" . $i : $i);
00146 if ($_SESSION["pay_statistics"]["from"]["day"] == $i)
00147 {
00148 $this->tpl->setVariable("LOOP_FROM_DAY_SELECTED", " selected");
00149 }
00150 $this->tpl->parseCurrentBlock("loop_from_day");
00151 $this->tpl->setCurrentBlock("loop_til_day");
00152 $this->tpl->setVariable("LOOP_TIL_DAY", $i < 10 ? "0" . $i : $i);
00153 if ($_SESSION["pay_statistics"]["til"]["day"] == $i)
00154 {
00155 $this->tpl->setVariable("LOOP_TIL_DAY_SELECTED", " selected");
00156 }
00157 $this->tpl->parseCurrentBlock("loop_til_day");
00158 }
00159 for ($i = 1; $i <= 12; $i++)
00160 {
00161 $this->tpl->setCurrentBlock("loop_from_month");
00162 $this->tpl->setVariable("LOOP_FROM_MONTH", $i < 10 ? "0" . $i : $i);
00163 if ($_SESSION["pay_statistics"]["from"]["month"] == $i)
00164 {
00165 $this->tpl->setVariable("LOOP_FROM_MONTH_SELECTED", " selected");
00166 }
00167 $this->tpl->parseCurrentBlock("loop_from_month");
00168 $this->tpl->setCurrentBlock("loop_til_month");
00169 $this->tpl->setVariable("LOOP_TIL_MONTH", $i < 10 ? "0" . $i : $i);
00170 if ($_SESSION["pay_statistics"]["til"]["month"] == $i)
00171 {
00172 $this->tpl->setVariable("LOOP_TIL_MONTH_SELECTED", " selected");
00173 }
00174 $this->tpl->parseCurrentBlock("loop_til_month");
00175 }
00176 for ($i = 2004; $i <= date("Y"); $i++)
00177 {
00178 $this->tpl->setCurrentBlock("loop_from_year");
00179 $this->tpl->setVariable("LOOP_FROM_YEAR", $i);
00180 if ($_SESSION["pay_statistics"]["from"]["year"] == $i)
00181 {
00182 $this->tpl->setVariable("LOOP_FROM_YEAR_SELECTED", " selected");
00183 }
00184 $this->tpl->parseCurrentBlock("loop_from_year");
00185 $this->tpl->setCurrentBlock("loop_til_year");
00186 $this->tpl->setVariable("LOOP_TIL_YEAR", $i);
00187 if ($_SESSION["pay_statistics"]["til"]["year"] == $i)
00188 {
00189 $this->tpl->setVariable("LOOP_TIL_YEAR_SELECTED", " selected");
00190 }
00191 $this->tpl->parseCurrentBlock("loop_til_year");
00192 }
00193
00194 $this->__initBookingObject();
00195
00196 if(!count($bookings = $this->booking_obj->getBookings()))
00197 {
00198 sendInfo($this->lng->txt('paya_no_bookings'));
00199
00200 return true;
00201 }
00202 # $this->__showButton('excelExport',$this->lng->txt('excel_export'));
00203
00204 $img_change = "<img src=\"".ilUtil::getImagePath("edit.gif")."\" alt=\"".
00205 $this->lng->txt("edit")."\" title=\"".$this->lng->txt("edit").
00206 "\" border=\"0\" vspace=\"0\"/>";
00207
00208 $counter = 0;
00209 foreach($bookings as $booking)
00210 {
00211 $tmp_obj =& ilObjectFactory::getInstanceByRefId($booking['ref_id']);
00212 $tmp_vendor =& ilObjectFactory::getInstanceByObjId($booking['b_vendor_id']);
00213 $tmp_purchaser =& ilObjectFactory::getInstanceByObjId($booking['customer_id']);
00214
00215 $transaction = $booking['transaction_extern'];
00216 switch ($booking['b_pay_method'])
00217 {
00218 case $this->pobject->PAY_METHOD_BILL :
00219 $transaction .= " (" . $this->lng->txt("pays_bill") . ")";
00220 break;
00221 case $this->pobject->PAY_METHOD_BMF :
00222 $transaction .= " (" . $this->lng->txt("pays_bmf") . ")";
00223 break;
00224 case $this->pobject->PAY_METHOD_PAYPAL :
00225 $transaction .= " (" . $this->lng->txt("pays_paypal") . ")";
00226 break;
00227 }
00228 $f_result[$counter][] = $transaction;
00229 $f_result[$counter][] = $tmp_obj->getTitle();
00230 $f_result[$counter][] = '['.$tmp_vendor->getLogin().']';
00231 $f_result[$counter][] = '['.$tmp_purchaser->getLogin().']';
00232 $f_result[$counter][] = date('Y m d H:i:s',$booking['order_date']);
00233 $f_result[$counter][] = $booking['duration'];
00234 $f_result[$counter][] = $booking['price'];
00235
00236 $payed_access = $booking['payed'] ?
00237 $this->lng->txt('yes') :
00238 $this->lng->txt('no');
00239
00240 $payed_access .= '/';
00241 $payed_access .= $booking['access'] ?
00242 $this->lng->txt('yes') :
00243 $this->lng->txt('no');
00244
00245 $f_result[$counter][] = $payed_access;
00246
00247 $this->ctrl->setParameter($this,"booking_id",$booking['booking_id']);
00248 # $link_change = "<a href=\"".$this->ctrl->getLinkTarget($this,"editStatistic")."\"> ".
00249 # $img_change."</a>";
00250 $link_change = "<div class=\"il_ContainerItemCommands\"><a class=\"il_ContainerItemCommand\" href=\"".$this->ctrl->getLinkTarget($this,"editStatistic")."\">".$this->lng->txt("edit")."</a></div>";
00251
00252 $f_result[$counter][] = $link_change;
00253
00254 unset($tmp_obj);
00255 unset($tmp_vendor);
00256 unset($tmp_purchaser);
00257
00258 ++$counter;
00259 }
00260 return $this->__showStatisticTable($f_result);
00261
00262 }
00263
00264 function excelExport()
00265 {
00266 include_once './payment/classes/class.ilPaymentExcelWriterAdapter.php';
00267
00268 $pewa =& new ilPaymentExcelWriterAdapter('payment_vendors.xls');
00269
00270
00271 $this->addStatisticWorksheet($pewa);
00272
00273
00274
00275 $workbook =& $pewa->getWorkbook();
00276 $workbook->close();
00277 }
00278
00279 function addStatisticWorksheet(&$pewa)
00280 {
00281 include_once './payment/classes/class.ilPaymentVendors.php';
00282
00283 $this->__initBookingObject();
00284
00285 if(!count($bookings = $this->booking_obj->getBookings()))
00286 {
00287 return false;
00288 }
00289
00290 $workbook =& $pewa->getWorkbook();
00291 $worksheet =& $workbook->addWorksheet($this->lng->txt('paya_statistic'));
00292
00293 $worksheet->mergeCells(0,0,0,8);
00294 $worksheet->setColumn(0,0,16);
00295 $worksheet->setColumn(0,1,32);
00296 $worksheet->setColumn(0,2,32);
00297 $worksheet->setColumn(0,3,16);
00298 $worksheet->setColumn(0,4,16);
00299 $worksheet->setColumn(0,5,16);
00300 $worksheet->setColumn(0,6,24);
00301 $worksheet->setColumn(0,7,8);
00302 $worksheet->setColumn(0,8,12);
00303 $worksheet->setColumn(0,9,16);
00304
00305 $title = $this->lng->txt('paya_statistic');
00306 $title .= ' '.$this->lng->txt('as_of');
00307 $title .= strftime('%Y-%m-%d %R',time());
00308
00309 $worksheet->writeString(0,0,$title,$pewa->getFormatTitle());
00310
00311 $worksheet->writeString(1,0,$this->lng->txt('payment_system'),$pewa->getFormatHeader());
00312 $worksheet->writeString(1,1,$this->lng->txt('paya_transaction'),$pewa->getFormatHeader());
00313 $worksheet->writeString(1,2,$this->lng->txt('title'),$pewa->getFormatHeader());
00314 $worksheet->writeString(1,3,$this->lng->txt('paya_vendor'),$pewa->getFormatHeader());
00315 $worksheet->writeString(1,4,$this->lng->txt('pays_cost_center'),$pewa->getFormatHeader());
00316 $worksheet->writeString(1,5,$this->lng->txt('paya_customer'),$pewa->getFormatHeader());
00317 $worksheet->writeString(1,6,$this->lng->txt('paya_order_date'),$pewa->getFormatHeader());
00318 $worksheet->writeString(1,7,$this->lng->txt('duration'),$pewa->getFormatHeader());
00319 $worksheet->writeString(1,8,$this->lng->txt('price_a'),$pewa->getFormatHeader());
00320 $worksheet->writeString(1,9,$this->lng->txt('paya_payed_access'),$pewa->getFormatHeader());
00321
00322 $counter = 2;
00323 foreach($bookings as $booking)
00324 {
00325 $tmp_obj =& ilObjectFactory::getInstanceByRefId($booking['ref_id']);
00326 $tmp_vendor =& ilObjectFactory::getInstanceByObjId($booking['b_vendor_id']);
00327 $tmp_purchaser =& ilObjectFactory::getInstanceByObjId($booking['customer_id']);
00328
00329 switch ($booking['b_pay_method'])
00330 {
00331 case $this->pobject->PAY_METHOD_BILL :
00332 $pay_method = $this->lng->txt("pays_bill");
00333 break;
00334 case $this->pobject->PAY_METHOD_BMF :
00335 $pay_method = $this->lng->txt("pays_bmf");
00336 break;
00337 case $this->pobject->PAY_METHOD_PAYPAL :
00338 $pay_method = $this->lng->txt("pays_paypal");
00339 break;
00340 }
00341 $worksheet->writeString($counter,0,$pay_method);
00342 $worksheet->writeString($counter,1,$booking['transaction_extern']);
00343 $worksheet->writeString($counter,2,$tmp_obj->getTitle());
00344 $worksheet->writeString($counter,3,$tmp_vendor->getLogin());
00345 $worksheet->writeString($counter,4,ilPaymentVendors::_getCostCenter($tmp_vendor->getId()));
00346 $worksheet->writeString($counter,5,$tmp_purchaser->getLogin());
00347 $worksheet->writeString($counter,6,strftime('%Y-%m-%d %R',$booking['order_date']));
00348
00349
00350
00351
00352
00353
00354
00355
00356 $worksheet->writeString($counter,7,$booking['duration']);
00357 $worksheet->writeString($counter,8,$booking['price']);
00358
00359 $payed_access = $booking['payed'] ?
00360 $this->lng->txt('yes') :
00361 $this->lng->txt('no');
00362
00363 $payed_access .= '/';
00364 $payed_access .= $booking['access'] ?
00365 $this->lng->txt('yes') :
00366 $this->lng->txt('no');
00367
00368 $worksheet->writeString($counter,9,$payed_access);
00369
00370 unset($tmp_obj);
00371 unset($tmp_vendor);
00372 unset($tmp_purchaser);
00373
00374 ++$counter;
00375 }
00376 }
00377
00378 function editStatistic($a_show_confirm_delete = false)
00379 {
00380 if(!isset($_GET['booking_id']))
00381 {
00382 sendInfo($this->lng->txt('paya_no_booking_id_given'));
00383 $this->showStatistics();
00384
00385 return true;
00386 }
00387
00388 $this->showButton('showStatistics',$this->lng->txt('back'));
00389
00390 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.paya_edit_statistic.html','payment');
00391 $this->ctrl->setParameter($this,'booking_id',(int) $_GET['booking_id']);
00392
00393
00394 if($a_show_confirm_delete)
00395 {
00396 $this->tpl->setCurrentBlock("confirm_delete");
00397 $this->tpl->setVariable("CONFIRM_FORMACTION",$this->ctrl->getFormAction($this));
00398 $this->tpl->setVariable("TXT_CANCEL",$this->lng->txt('cancel'));
00399 $this->tpl->setVariable("CONFIRM_CMD",'performDelete');
00400 $this->tpl->setVariable("TXT_CONFIRM",$this->lng->txt('confirm'));
00401 $this->tpl->parseCurrentBlock();
00402 }
00403
00404
00405 $this->__initBookingObject();
00406 $bookings = $this->booking_obj->getBookings();
00407 $booking = $bookings[(int) $_GET['booking_id']];
00408
00409
00410 $tmp_user =& ilObjectFactory::getInstanceByObjId($booking['customer_id']);
00411
00412
00413
00414 $this->tpl->setVariable("STAT_FORMACTION",$this->ctrl->getFormAction($this));
00415 $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_usr.gif'));
00416 $this->tpl->setVariable("ALT_IMG",$this->lng->txt('obj_usr'));
00417 $this->tpl->setVariable("TITLE",$tmp_user->getFullname().' ['.$tmp_user->getLogin().']');
00418
00419
00420 $pObj =& new ilPaymentObject($this->user_obj, $booking["pobject_id"]);
00421 $tmp_obj =& ilObjectFactory::getInstanceByRefId($pObj->getRefId());
00422
00423 $this->tpl->setVariable("TXT_OBJECT",$this->lng->txt('title'));
00424 $this->tpl->setVariable("OBJECT",$tmp_obj->getTitle());
00425
00426 $this->tpl->setVariable("TXT_TRANSACTION",$this->lng->txt('paya_transaction'));
00427 $this->tpl->setVariable("TXT_VENDOR",$this->lng->txt('paya_vendor'));
00428 $this->tpl->setVariable("TXT_PAY_METHOD",$this->lng->txt('paya_pay_method'));
00429 $this->tpl->setVariable("TXT_ORDER_DATE",$this->lng->txt('paya_order_date'));
00430 $this->tpl->setVariable("TXT_DURATION",$this->lng->txt('duration'));
00431 $this->tpl->setVariable("TXT_PRICE",$this->lng->txt('price_a'));
00432 $this->tpl->setVariable("TXT_PAYED",$this->lng->txt('paya_payed'));
00433 $this->tpl->setVariable("TXT_ACCESS",$this->lng->txt('paya_access'));
00434
00435 $this->tpl->setVariable("TRANSACTION",$booking['transaction']);
00436
00437 $tmp_vendor =& ilObjectFactory::getInstanceByObjId($booking['b_vendor_id']);
00438
00439 $this->tpl->setVariable("VENDOR",$tmp_vendor->getFullname().' ['.$tmp_vendor->getLogin().']');
00440
00441 switch($booking['b_pay_method'])
00442 {
00443 case $this->pobject->PAY_METHOD_BILL:
00444 $this->tpl->setVariable("PAY_METHOD",$this->lng->txt('pays_bill'));
00445 break;
00446
00447 case $this->pobject->PAY_METHOD_BMF:
00448 $this->tpl->setVariable("PAY_METHOD",$this->lng->txt('pays_bmf'));
00449 break;
00450
00451 case $this->pobject->PAY_METHOD_PAYPAL:
00452 $this->tpl->setVariable("PAY_METHOD",$this->lng->txt('pays_paypal'));
00453 break;
00454
00455 default:
00456 $this->tpl->setVariable("PAY_METHOD",$this->lng->txt('paya_pay_method_not_specified'));
00457 break;
00458 }
00459 $this->tpl->setVariable("ORDER_DATE",date('Y m d H:i:s',$booking['order_date']));
00460 $this->tpl->setVariable("DURATION",$booking['duration'].' '.$this->lng->txt('paya_months'));
00461 $this->tpl->setVariable("PRICE",$booking['price']);
00462
00463 $yes_no = array(0 => $this->lng->txt('no'),1 => $this->lng->txt('yes'));
00464
00465 $this->tpl->setVariable("PAYED",ilUtil::formSelect((int) $booking['payed'],'payed',$yes_no,false,true));
00466 $this->tpl->setVariable("ACCESS",ilUtil::formSelect((int) $booking['access'],'access',$yes_no,false,true));
00467
00468
00469 $this->tpl->setVariable("INPUT_CMD",'updateStatistic');
00470 $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('save'));
00471
00472 $this->tpl->setVariable("DELETE_CMD",'deleteStatistic');
00473 $this->tpl->setVariable("DELETE_VALUE",$this->lng->txt('delete'));
00474 }
00475
00476 function updateStatistic()
00477 {
00478 if(!isset($_GET['booking_id']))
00479 {
00480 sendInfo($this->lng->txt('paya_no_booking_id_given'));
00481 $this->showStatistics();
00482
00483 return true;
00484 }
00485 $this->__initBookingObject();
00486
00487 $this->booking_obj->setBookingId((int) $_GET['booking_id']);
00488 $this->booking_obj->setAccess((int) $_POST['access']);
00489 $this->booking_obj->setPayed((int) $_POST['payed']);
00490
00491 if($this->booking_obj->update())
00492 {
00493 sendInfo($this->lng->txt('paya_updated_booking'));
00494
00495 $this->showStatistics();
00496 return true;
00497 }
00498 else
00499 {
00500 sendInfo($this->lng->txt('paya_error_update_booking'));
00501 $this->showStatistics();
00502
00503 return true;
00504 }
00505 }
00506
00507 function deleteStatistic()
00508 {
00509 if(!isset($_GET['booking_id']))
00510 {
00511 sendInfo($this->lng->txt('paya_no_booking_id_given'));
00512 $this->showStatistics();
00513
00514 return true;
00515 }
00516 sendInfo($this->lng->txt('paya_sure_delete_stat'));
00517
00518 $this->editStatistic(true);
00519
00520 return true;
00521 }
00522
00523 function performDelete()
00524 {
00525 if(!isset($_GET['booking_id']))
00526 {
00527 sendInfo($this->lng->txt('paya_no_booking_id_given'));
00528 $this->showStatistics();
00529
00530 return true;
00531 }
00532
00533 $this->__initBookingObject();
00534 $this->booking_obj->setBookingId((int) $_GET['booking_id']);
00535 if(!$this->booking_obj->delete())
00536 {
00537 die('Error deleting booking');
00538 }
00539 sendInfo($this->lng->txt('pay_deleted_booking'));
00540
00541 $this->showStatistics();
00542
00543 return true;
00544 }
00545
00546 function showObjectSelector()
00547 {
00548 global $tree;
00549
00550 include_once './payment/classes/class.ilPaymentObjectSelector.php';
00551
00552 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.paya_object_selector.html",'payment');
00553 $this->showButton('showStatistics',$this->lng->txt('back'));
00554
00555 sendInfo($this->lng->txt("paya_select_object_to_sell"));
00556
00557 $exp = new ilPaymentObjectSelector($this->ctrl->getLinkTarget($this,'showObjectSelector'), strtolower(get_class($this)));
00558 $exp->setExpand($_GET["paya_link_expand"] ? $_GET["paya_link_expand"] : $tree->readRootId());
00559 $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'showObjectSelector'));
00560
00561 $exp->setOutput(0);
00562
00563 $this->tpl->setVariable("EXPLORER",$exp->getOutput());
00564
00565 return true;
00566 }
00567
00568 function searchUser()
00569 {
00570 if(!isset($_GET['sell_id']))
00571 {
00572 sendInfo($this->lng->txt('paya_no_booking_id_given'));
00573 $this->showObjectSelector();
00574
00575 return false;
00576 }
00577
00578 $this->tpl->addBlockFile("ADM_CONTENT","adm_content","tpl.paya_user_search.html",'payment');
00579 $this->showButton('showObjectSelector',$this->lng->txt('back'));
00580
00581 $this->lng->loadLanguageModule('search');
00582
00583 $this->ctrl->setParameter($this, "sell_id", $_GET["sell_id"]);
00584 $this->tpl->setVariable("F_ACTION",$this->ctrl->getFormAction($this));
00585 $this->tpl->setVariable("SEARCH_ASSIGN_USR",$this->lng->txt("search_user"));
00586 $this->tpl->setVariable("SEARCH_SEARCH_TERM",$this->lng->txt("search_search_term"));
00587 $this->tpl->setVariable("SEARCH_VALUE",$_SESSION["pays_search_str_user_sp"] ? $_SESSION["pays_search_str_user_sp"] : "");
00588 $this->tpl->setVariable("BTN2_VALUE",$this->lng->txt("cancel"));
00589 $this->tpl->setVariable("BTN1_VALUE",$this->lng->txt("search"));
00590 $this->tpl->setVariable("SEARCH","performSearch");
00591 $this->tpl->setVariable("CANCEL","showStatistics");
00592
00593 return true;
00594 }
00595
00596 function performSearch()
00597 {
00598
00599 $_SESSION["pays_search_str_user_sp"] = $_POST["search_str"] = $_POST["search_str"] ? $_POST["search_str"] : $_SESSION["pays_search_str_user_sp"];
00600
00601
00602 if(!trim($_POST["search_str"]))
00603 {
00604 sendInfo($this->lng->txt("search_no_search_term"));
00605 $this->showStatistics();
00606
00607 return false;
00608 }
00609 if(!count($result = $this->__search(ilUtil::stripSlashes($_POST["search_str"]))))
00610 {
00611 sendInfo($this->lng->txt("search_no_match"));
00612 $this->searchUser();
00613
00614 return false;
00615 }
00616
00617 if(!isset($_GET['sell_id']))
00618 {
00619 sendInfo($this->lng->txt('paya_no_booking_id_given'));
00620 $this->showObjectSelector();
00621
00622 return false;
00623 }
00624
00625 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.paya_usr_selection.html",'payment');
00626 $this->ctrl->setParameter($this, "sell_id", $_GET["sell_id"]);
00627 $this->showButton("searchUser",$this->lng->txt("back"));
00628
00629 $counter = 0;
00630 $f_result = array();
00631 foreach($result as $user)
00632 {
00633 if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($user["id"],false))
00634 {
00635 continue;
00636 }
00637 $f_result[$counter][] = ilUtil::formRadiobutton(0,"user_id",$user["id"]);
00638 $f_result[$counter][] = $tmp_obj->getLogin();
00639 $f_result[$counter][] = $tmp_obj->getFirstname();
00640 $f_result[$counter][] = $tmp_obj->getLastname();
00641
00642 unset($tmp_obj);
00643 ++$counter;
00644 }
00645 $this->__showSearchUserTable($f_result);
00646 }
00647
00648 function addCustomer()
00649 {
00650 if ($_POST["sell_id"] != "") $_GET["sell_id"] = $_POST["sell_id"];
00651 if ($_GET["user_id"] != "") $_POST["user_id"] = $_GET["user_id"];
00652
00653 if(!isset($_GET['sell_id']))
00654 {
00655 sendInfo($this->lng->txt('paya_no_booking_id_given'));
00656 $this->showObjectSelector();
00657
00658 return true;
00659 }
00660
00661 if(!isset($_POST['user_id']))
00662 {
00663 sendInfo($this->lng->txt('paya_no_user_id_given'));
00664 $this->searchUser();
00665
00666 return true;
00667 }
00668
00669 $this->ctrl->setParameter($this, "sell_id", $_GET["sell_id"]);
00670 $this->showButton('searchUser',$this->lng->txt('back'));
00671
00672 $this->ctrl->setParameter($this, "user_id", $_POST["user_id"]);
00673
00674 $pObjectId = ilPaymentObject::_lookupPobjectId($_GET["sell_id"]);
00675 $obj =& new ilPaymentObject($this->user_obj, $pObjectId);
00676
00677
00678 $tmp_obj =& ilObjectFactory::getInstanceByRefId($_GET["sell_id"]);
00679
00680 $tmp_user =& ilObjectFactory::getInstanceByObjId($_POST["user_id"]);
00681
00682 $tmp_vendor =& ilObjectFactory::getInstanceByObjId($obj->getVendorId());
00683
00684 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.paya_add_customer.html','payment');
00685
00686 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00687
00688 $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_usr.gif'));
00689 $this->tpl->setVariable("ALT_IMG",$this->lng->txt('obj_usr'));
00690 $this->tpl->setVariable("TITLE",$tmp_user->getFullname().' ['.$tmp_user->getLogin().']');
00691
00692
00693 $this->tpl->setVariable("TXT_TRANSACTION",$this->lng->txt('paya_transaction'));
00694 $this->tpl->setVariable("TRANSACTION",ilUtil::prepareFormOutput($_POST["transaction"], true));
00695
00696 $this->tpl->setVariable("TXT_OBJECT",$this->lng->txt('title'));
00697 $this->tpl->setVariable("OBJECT",$tmp_obj->getTitle());
00698
00699 $this->tpl->setVariable("TXT_VENDOR",$this->lng->txt('paya_vendor'));
00700 $this->tpl->setVariable("VENDOR",$tmp_vendor->getFullname().' ['.$tmp_vendor->getLogin().']');
00701
00702 $this->tpl->setVariable("TXT_PAY_METHOD",$this->lng->txt('paya_pay_method'));
00703 $this->tpl->setVariable("TXT_PAY_METHOD_BILL",$this->lng->txt('pays_bill'));
00704 $this->tpl->setVariable("TXT_PAY_METHOD_BMF",$this->lng->txt('pays_bmf'));
00705 $this->tpl->setVariable("TXT_PAY_METHOD_PAYPAL",$this->lng->txt('pays_paypal'));
00706 $this->tpl->setVariable("PAY_METHOD_".$_POST["pay_method"], " selected");
00707
00708 $this->tpl->setVariable("TXT_ORDER_DATE",$this->lng->txt('paya_order_date'));
00709 $this->tpl->setVariable("ORDER_DATE",ilFormat::formatUnixTime(time(), true));
00710
00711 $this->tpl->setVariable("TXT_DURATION",$this->lng->txt('duration'));
00712 include_once './payment/classes/class.ilPaymentPrices.php';
00713 $prices_obj =& new ilPaymentPrices($pObjectId);
00714 if (is_array($prices = $prices_obj->getPrices()))
00715 {
00716 foreach($prices as $price)
00717 {
00718 $this->tpl->setCurrentBlock("duration_loop");
00719 if ($_POST["duration"] == $price["price_id"]) $this->tpl->setVariable("DURATION_LOOP_SELECTED", " selected");
00720 $this->tpl->setVariable("DURATION_LOOP_ID", $price["price_id"]);
00721 $this->tpl->setVariable("DURATION_LOOP_NAME", $price["duration"]." ".$this->lng->txt("paya_months").", ".ilPaymentPrices::_getPriceString($price["price_id"]));
00722 $this->tpl->parseCurrentBlock();
00723 }
00724 }
00725
00726 $this->tpl->setVariable("TXT_PAYED",$this->lng->txt('paya_payed'));
00727 if ($_POST["payed"] == 1) $this->tpl->setVariable("PAYED_1", " selected");
00728 $this->tpl->setVariable("TXT_ACCESS",$this->lng->txt('paya_access'));
00729 if ($_POST["access"] == 1) $this->tpl->setVariable("ACCESS_1", " selected");
00730
00731 $this->tpl->setVariable("TXT_NO",$this->lng->txt('no'));
00732 $this->tpl->setVariable("TXT_YES",$this->lng->txt('yes'));
00733 $this->tpl->setVariable("TXT_SAVE",$this->lng->txt('save'));
00734 $this->tpl->setVariable("TXT_CANCEL",$this->lng->txt('cancel'));
00735 $this->tpl->setVariable("STATISTICS","showStatistics");
00736
00737 }
00738
00739 function saveCustomer()
00740 {
00741 global $ilias;
00742
00743 if(!isset($_GET['sell_id']))
00744 {
00745 sendInfo($this->lng->txt('paya_error_no_object_id_given'));
00746 $this->showObjectSelector();
00747
00748 return true;
00749 }
00750
00751 if(!isset($_GET['user_id']))
00752 {
00753 sendInfo($this->lng->txt('paya_error_no_user_id_given'));
00754 $this->searchUser();
00755
00756 return true;
00757 }
00758
00759 if ($_POST["pay_method"] == "" ||
00760 $_POST["duration"] == "")
00761 {
00762 sendInfo($this->lng->txt('paya_error_mandatory_fields'));
00763 $this->addCustomer();
00764
00765 return true;
00766 }
00767
00768 $pObjectId = ilPaymentObject::_lookupPobjectId($_GET["sell_id"]);
00769 $obj =& new ilPaymentObject($this->user_obj, $pObjectId);
00770
00771 $this->__initBookingObject();
00772
00773 $inst_id_time = $ilias->getSetting('inst_id').'_'.$this->user_obj->getId().'_'.substr((string) time(),-3);
00774 $transaction = $inst_id_time.substr(md5(uniqid(rand(), true)), 0, 4);
00775 $this->booking_obj->setTransaction($transaction);
00776 $this->booking_obj->setTransactionExtern($_POST["transaction"]);
00777 $this->booking_obj->setPobjectId($pObjectId);
00778 $this->booking_obj->setCustomerId($_GET["user_id"]);
00779 $this->booking_obj->setVendorId($obj->getVendorId());
00780 $this->booking_obj->setPayMethod((int) $_POST["pay_method"]);
00781 $this->booking_obj->setOrderDate(time());
00782 $price = ilPaymentPrices::_getPrice($_POST["duration"]);
00783 $this->booking_obj->setDuration($price["duration"]);
00784 $this->booking_obj->setPrice(ilPaymentPrices::_getPriceString($_POST["duration"]));
00785 $this->booking_obj->setAccess((int) $_POST['access']);
00786 $this->booking_obj->setPayed((int) $_POST['payed']);
00787 $this->booking_obj->setVoucher('');
00788
00789 if($this->booking_obj->add())
00790 {
00791 sendInfo($this->lng->txt('paya_customer_added_successfully'));
00792 $this->showStatistics();
00793 }
00794 else
00795 {
00796 sendInfo($this->lng->txt('paya_error_adding_customer'));
00797 $this->addCustomer();
00798 }
00799
00800 return true;
00801 }
00802
00803
00804 function __showStatisticTable($a_result_set)
00805 {
00806 $tbl =& $this->initTableGUI();
00807 $tpl =& $tbl->getTemplateObject();
00808
00809
00810 $tpl->setCurrentBlock("tbl_form_header");
00811
00812 $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00813 $tpl->parseCurrentBlock();
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832 $tbl->setTitle($this->lng->txt("paya_statistic"),"icon_pays.gif",$this->lng->txt("paya_statistic"));
00833 $tbl->setHeaderNames(array($this->lng->txt("paya_transaction"),
00834 $this->lng->txt("title"),
00835 $this->lng->txt("paya_vendor"),
00836 $this->lng->txt("paya_customer"),
00837 $this->lng->txt("paya_order_date"),
00838 $this->lng->txt("duration"),
00839 $this->lng->txt("price_a"),
00840 $this->lng->txt("paya_payed_access"),
00841 ''));
00842 $header_params = $this->ctrl->getParameterArray($this,'');
00843 $tbl->setHeaderVars(array("transaction",
00844 "title",
00845 "vendor",
00846 "customer",
00847 "order_date",
00848 "duration",
00849 "price",
00850 "payed_access",
00851 "options"),$header_params);
00852
00853
00854
00855
00856
00857
00858
00859 $offset = $_GET["offset"];
00860 $order = $_GET["sort_by"];
00861 $direction = $_GET["sort_order"] ? $_GET['sort_order'] : 'desc';
00862
00863 $tbl->setOrderColumn($order,'order_date');
00864 $tbl->setOrderDirection($direction);
00865 $tbl->setOffset($offset);
00866 $tbl->setLimit($_GET["limit"]);
00867 $tbl->setMaxCount(count($a_result_set));
00868 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
00869 $tbl->setData($a_result_set);
00870
00871 $tpl->setVariable("COLUMN_COUNTS",9);
00872 $tpl->setCurrentBlock("plain_buttons");
00873 $tpl->setVariable("PBTN_NAME","excelExport");
00874 $tpl->setVariable("PBTN_VALUE",$this->lng->txt("excel_export"));
00875 $tpl->parseCurrentBlock();
00876
00877 $tbl->render();
00878
00879 $this->tpl->setVariable("STATISTIC_TABLE",$tbl->tpl->get());
00880
00881 return true;
00882 }
00883
00884 function __initBookingObject()
00885 {
00886 include_once './payment/classes/class.ilPaymentBookings.php';
00887
00888 $this->booking_obj =& new ilPaymentBookings($this->user_obj->getId());
00889 }
00890
00891 function __showButton($a_cmd,$a_text,$a_target = '')
00892 {
00893 $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
00894
00895
00896 $this->tpl->setCurrentBlock("btn_cell");
00897 $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTarget($this,$a_cmd));
00898 $this->tpl->setVariable("BTN_TXT",$a_text);
00899 if($a_target)
00900 {
00901 $this->tpl->setVariable("BTN_TARGET",$a_target);
00902 }
00903
00904 $this->tpl->parseCurrentBlock();
00905 }
00906
00907 function __search($a_search_string)
00908 {
00909 include_once("./classes/class.ilSearch.php");
00910
00911 $this->lng->loadLanguageModule("content");
00912
00913 $search =& new ilSearch($this->user_obj->getId());
00914 $search->setPerformUpdate(false);
00915 $search->setSearchString(ilUtil::stripSlashes($a_search_string));
00916 $search->setCombination("and");
00917 $search->setSearchFor(array(0 => 'usr'));
00918 $search->setSearchType('new');
00919
00920 if($search->validate($message))
00921 {
00922 $search->performSearch();
00923 }
00924 else
00925 {
00926 sendInfo($message,true);
00927 $this->ctrl->redirect($this,"searchUser");
00928 }
00929 return $search->getResultByType('usr');
00930 }
00931 function __showSearchUserTable($a_result_set)
00932 {
00933 $tbl =& $this->initTableGUI();
00934 $tpl =& $tbl->getTemplateObject();
00935
00936
00937
00938 $tpl->setCurrentBlock("tbl_form_header");
00939 $this->ctrl->setParameter($this, "sell_id", $_GET["sell_id"]);
00940 $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00941 $tpl->parseCurrentBlock();
00942
00943 $tpl->setCurrentBlock("tbl_action_btn");
00944 $tpl->setVariable("BTN_NAME","addCustomer");
00945 $tpl->setVariable("BTN_VALUE",$this->lng->txt("add"));
00946 $tpl->parseCurrentBlock();
00947
00948 $tpl->setCurrentBlock("tbl_action_btn");
00949 $tpl->setVariable("BTN_NAME","showStatistics");
00950 $tpl->setVariable("BTN_VALUE",$this->lng->txt("cancel"));
00951 $tpl->parseCurrentBlock();
00952
00953 $tpl->setCurrentBlock("tbl_action_row");
00954 $tpl->setVariable("COLUMN_COUNTS",5);
00955 $tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
00956 $tpl->parseCurrentBlock();
00957
00958 $tbl->setTitle($this->lng->txt("users"),"icon_usr.gif",$this->lng->txt("crs_header_edit_members"));
00959 $tbl->setHeaderNames(array("",
00960 $this->lng->txt("login"),
00961 $this->lng->txt("firstname"),
00962 $this->lng->txt("lastname")));
00963 $this->ctrl->setParameter($this, "cmd", "addCustomer");
00964 $header_params = $this->ctrl->getParameterArray($this,'');
00965 $tbl->setHeaderVars(array("",
00966 "login",
00967 "firstname",
00968 "lastname"), $header_params);
00969
00970
00971
00972
00973
00974
00975 $tbl->setColumnWidth(array("3%","32%","32%","32%"));
00976
00977 $this->setTableGUIBasicData($tbl,$a_result_set);
00978 $tbl->render();
00979
00980 $this->tpl->setVariable("SEARCH_RESULT_TABLE",$tbl->tpl->get());
00981
00982 return true;
00983 }
00984 }
00985 ?>