00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00031 include_once './payment/classes/class.ilPaymentVendors.php';
00032 include_once './payment/classes/class.ilPaymentTrustees.php';
00033
00034
00035 class ilPaymentBookings
00036 {
00037
00038
00039
00040 var $user_id = null;
00041 var $db = null;
00042
00043 var $bookings = array();
00044
00045 var $booking_id = null;
00046 var $payed = null;
00047 var $access = null;
00048 var $admin_view = false;
00049
00050
00051
00052
00053 function ilPaymentBookings($a_user_id = '',$a_admin_view = false)
00054 {
00055 global $ilDB;
00056
00057 $this->admin_view = $a_admin_view;
00058 $this->user_id = $a_user_id;
00059 $this->db =& $ilDB;
00060
00061 if($a_user_id)
00062 {
00063 $this->__read();
00064 }
00065 }
00066
00067
00068 function setBookingId($a_booking_id)
00069 {
00070 return $this->booking_id = $a_booking_id;
00071 }
00072 function getBookingId()
00073 {
00074 return $this->booking_id;
00075 }
00076 function setTransaction($a_transaction)
00077 {
00078 $this->transaction = $a_transaction;
00079 }
00080 function getTransaction()
00081 {
00082 return $this->transaction;
00083 }
00084 function setPobjectId($a_pobject_id)
00085 {
00086 $this->pobject_id = $a_pobject_id;
00087 }
00088 function getPobjectId()
00089 {
00090 return $this->pobject_id;
00091 }
00092 function setCustomerId($a_customer_id)
00093 {
00094 $this->customer_id = $a_customer_id;
00095 }
00096 function getCustomerId()
00097 {
00098 return $this->customer_id;
00099 }
00100 function setVendorId($a_vendor_id)
00101 {
00102 $this->vendor_id = $a_vendor_id;
00103 }
00104 function getVendorId()
00105 {
00106 return $this->vendor_id;
00107 }
00108 function setPayMethod($a_pay_method)
00109 {
00110 $this->pay_method = $a_pay_method;
00111 }
00112 function getPayMethod()
00113 {
00114 return $this->pay_method;
00115 }
00116 function setOrderDate($a_order_date)
00117 {
00118 $this->order_date = $a_order_date;
00119 }
00120 function getOrderDate()
00121 {
00122 return $this->order_date;
00123 }
00124 function setDuration($a_duration)
00125 {
00126 $this->duration = $a_duration;
00127 }
00128 function getDuration()
00129 {
00130 return $this->duration;
00131 }
00132 function setPrice($a_price)
00133 {
00134 $this->price = $a_price;
00135 }
00136 function getPrice()
00137 {
00138 return $this->price;
00139 }
00140 function setPayed($a_payed)
00141 {
00142 $this->payed = $a_payed;
00143 }
00144 function getPayedStatus()
00145 {
00146 return $this->payed;
00147 }
00148 function setAccess($a_access)
00149 {
00150 $this->access = $a_access;
00151 }
00152 function getAccessStatus()
00153 {
00154 return $this->access;
00155 }
00156 function setVoucher($a_voucher)
00157 {
00158 $this->voucher = $a_voucher;
00159 }
00160 function getVoucher()
00161 {
00162 return $this->voucher;
00163 }
00164 function setTransactionExtern($a_transaction_extern)
00165 {
00166 $this->transaction_extern = $a_transaction_extern;
00167 }
00168 function getTransactionExtern()
00169 {
00170 return $this->transaction_extern;
00171 }
00172
00173 function add()
00174 {
00175 $query = sprintf("INSERT INTO payment_statistic VALUES('',".
00176 "'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
00177 $this->getTransaction(),
00178 $this->getPobjectId(),
00179 $this->getCustomerId(),
00180 $this->getVendorId(),
00181 $this->getPayMethod(),
00182 $this->getOrderDate(),
00183 $this->getDuration(),
00184 $this->getPrice(),
00185 $this->getPayedStatus(),
00186 $this->getAccessStatus(),
00187 $this->getVoucher(),
00188 $this->getTransactionExtern());
00189
00190 $this->db->query($query);
00191
00192 return true;
00193 }
00194
00195 function update()
00196 {
00197 if($this->getBookingId())
00198 {
00199 $query = "UPDATE payment_statistic ".
00200 "SET payed = '".(int) $this->getPayedStatus()."', ".
00201 "access = '".(int) $this->getAccessStatus()."' ".
00202 "WHERE booking_id = '".$this->getBookingId()."'";
00203 $this->db->query($query);
00204
00205 return true;
00206 }
00207 return false;
00208 }
00209
00210 function delete()
00211 {
00212 if($this->getBookingId())
00213 {
00214 $query = "DELETE FROM payment_statistic ".
00215 "WHERE booking_id = '".$this->getBookingId()."'";
00216
00217 $this->db->query($query);
00218
00219 return true;
00220 }
00221 return false;
00222 }
00223
00224 function getBookingsOfCustomer($a_usr_id)
00225 {
00226 $query = 'SELECT * FROM payment_statistic as ps, payment_objects as po '.
00227 "WHERE ps.pobject_id = po.pobject_id ".
00228 "AND customer_id = '".$a_usr_id."' ".
00229 "ORDER BY order_date DESC";
00230
00231 $res = $this->db->query($query);
00232 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00233 {
00234 $booking[$row->booking_id]['booking_id'] = $row->booking_id;
00235 $booking[$row->booking_id]['transaction'] = $row->transaction;
00236 $booking[$row->booking_id]['pobject_id'] = $row->pobject_id;
00237 $booking[$row->booking_id]['customer_id'] = $row->customer_id;
00238 $booking[$row->booking_id]['order_date'] = $row->order_date;
00239 $booking[$row->booking_id]['duration'] = $row->duration;
00240 $booking[$row->booking_id]['price'] = $row->price;
00241 $booking[$row->booking_id]['payed'] = $row->payed;
00242 $booking[$row->booking_id]['access'] = $row->access;
00243 $booking[$row->booking_id]['ref_id'] = $row->ref_id;
00244 $booking[$row->booking_id]['status'] = $row->status;
00245 $booking[$row->booking_id]['pay_method'] = $row->pay_method;
00246 $booking[$row->booking_id]['vendor_id'] = $row->vendor_id;
00247 $booking[$row->booking_id]['b_vendor_id'] = $row->b_vendor_id;
00248 $booking[$row->booking_id]['b_pay_method'] = $row->b_pay_method;
00249 $booking[$row->booking_id]['voucher'] = $row->voucher;
00250 $booking[$row->booking_id]['transaction_extern'] = $row->transaction_extern;
00251 }
00252 return $booking ? $booking : array();
00253 }
00254
00255 function getBookings()
00256 {
00257 return $this->bookings ? $this->bookings : array();
00258 }
00259
00260 function getBooking($a_booking_id)
00261 {
00262 $query = 'SELECT * FROM payment_statistic as ps, payment_objects as po '.
00263 "WHERE ps.pobject_id = po.pobject_id ".
00264 "AND booking_id = '".$a_booking_id."'";
00265
00266 $res = $this->db->query($query);
00267 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00268 {
00269 $booking['booking_id'] = $row->booking_id;
00270 $booking['transaction'] = $row->transaction;
00271 $booking['pobject_id'] = $row->pobject_id;
00272 $booking['customer_id'] = $row->customer_id;
00273 $booking['order_date'] = $row->order_date;
00274 $booking['duration'] = $row->duration;
00275 $booking['price'] = $row->price;
00276 $booking['payed'] = $row->payed;
00277 $booking['access'] = $row->access;
00278 $booking['ref_id'] = $row->ref_id;
00279 $booking['status'] = $row->status;
00280 $booking['pay_method'] = $row->pay_method;
00281 $booking['vendor_id'] = $row->vendor_id;
00282 $booking['b_vendor_id'] = $row->b_vendor_id;
00283 $booking['b_pay_method'] = $row->b_pay_method;
00284 $booking['voucher'] = $row->voucher;
00285 $booking['transaction_extern'] = $row->transaction_extern;
00286 }
00287 return $booking ? $booking : array();
00288 }
00289
00290
00291
00292 function _getCountBookingsByVendor($a_vendor_id)
00293 {
00294 global $ilDB;
00295
00296 $query = "SELECT COUNT(booking_id) AS bid FROM payment_statistic ".
00297 "WHERE b_vendor_id = '".$a_vendor_id."'";
00298
00299 $res = $ilDB->query($query);
00300 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00301 {
00302 return $row->bid;
00303 }
00304 return 0;
00305 }
00306
00307 function _getCountBookingsByCustomer($a_vendor_id)
00308 {
00309 global $ilDB;
00310
00311 $query = "SELECT COUNT(booking_id) AS bid FROM payment_statistic ".
00312 "WHERE customer_id = '".$a_vendor_id."'";
00313
00314 $res = $ilDB->query($query);
00315 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00316 {
00317 return $row->bid;
00318 }
00319 return 0;
00320 }
00321 function _getCountBookingsByObject($a_pobject_id)
00322 {
00323 global $ilDB;
00324
00325 $query = "SELECT COUNT(booking_id) AS bid FROM payment_statistic ".
00326 "WHERE pobject_id = '".$a_pobject_id."'";
00327
00328 $res = $ilDB->query($query);
00329 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00330 {
00331 return $row->bid;
00332 }
00333 return 0;
00334 }
00335
00336 function _hasAccess($a_pobject_id,$a_user_id = 0)
00337 {
00338 global $ilDB,$ilias;
00339
00340 $usr_id = $a_user_id ? $a_user_id : $ilias->account->getId();
00341
00342 $query = "SELECT * FROM payment_statistic ".
00343 "WHERE pobject_id = '".$a_pobject_id."' ".
00344 "AND customer_id = '".$usr_id."' ".
00345 "AND payed = '1' ".
00346 "AND access = '1'";
00347
00348 $res = $ilDB->query($query);
00349 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00350 {
00351 $orderDateYear = date("Y", $row->order_date);
00352 $orderDateMonth = date("m", $row->order_date);
00353 $orderDateDay = date("d", $row->order_date);
00354 $orderDateHour = date("H", $row->order_date);
00355 $orderDateMinute = date("i", $row->order_date);
00356 $orderDateSecond = date("s", $row->order_date);
00357 if (($orderDateMonth + $row->duration) > 12)
00358 {
00359 $years = floor(($orderDateMonth + $row->duration) / 12);
00360 $months = ($orderDateMonth + $row->duration) - (12 * $years);
00361 $orderDateYear += $years;
00362 $orderDateMonth = $months;
00363 }
00364 else
00365 {
00366 $orderDateMonth += $row->duration;
00367 }
00368 $startDate = date("Y-m-d H:i:s", $row->order_date);
00369 $endDate = date("Y-m-d H:i:s", mktime($orderDateHour, $orderDateMinute, $orderDateSecond, $orderDateMonth, $orderDateDay, $orderDateYear));
00370 if (date("Y-m-d H:i:s") >= $startDate &&
00371 date("Y-m-d H:i:s") <= $endDate)
00372 {
00373 return true;
00374 }
00375 }
00376 return false;
00377 }
00378
00379 function _getActivation($a_pobject_id,$a_user_id = 0)
00380 {
00381 global $ilDB,$ilias;
00382
00383 $usr_id = $a_user_id ? $a_user_id : $ilias->account->getId();
00384
00385 $query = "SELECT * FROM payment_statistic ".
00386 "WHERE pobject_id = '".$a_pobject_id."' ".
00387 "AND customer_id = '".$usr_id."' ".
00388 "AND payed = '1' ".
00389 "AND access = '1'";
00390
00391 $res = $ilDB->query($query);
00392 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00393 {
00394 $orderDateYear = date("Y", $row->order_date);
00395 $orderDateMonth = date("m", $row->order_date);
00396 $orderDateDay = date("d", $row->order_date);
00397 $orderDateHour = date("H", $row->order_date);
00398 $orderDateMinute = date("i", $row->order_date);
00399 $orderDateSecond = date("s", $row->order_date);
00400 if (($orderDateMonth + $row->duration) > 12)
00401 {
00402 $years = floor(($orderDateMonth + $row->duration) / 12);
00403 $months = ($orderDateMonth + $row->duration) - (12 * $years);
00404 $orderDateYear += $years;
00405 $orderDateMonth = $months;
00406 }
00407 else
00408 {
00409 $orderDateMonth += $row->duration;
00410 }
00411 $startDate = date("Y-m-d H:i:s", $row->order_date);
00412 $endDate = date("Y-m-d H:i:s", mktime($orderDateHour, $orderDateMinute, $orderDateSecond, $orderDateMonth, $orderDateDay, $orderDateYear));
00413 if (date("Y-m-d H:i:s") >= $startDate &&
00414 date("Y-m-d H:i:s") <= $endDate)
00415 {
00416 $activation = array(
00417 "activation_start" => $row->order_date,
00418 "activation_end" => mktime($orderDateHour, $orderDateMinute, $orderDateSecond, $orderDateMonth, $orderDateDay, $orderDateYear)
00419 );
00420 return $activation;
00421 }
00422 }
00423 return false;
00424 }
00425
00426 function _getCountBookingsByPayMethod($a_pm)
00427 {
00428 switch($a_pm)
00429 {
00430 case 'pm_bill':
00431 $query = "SELECT COUNT(booking_id) AS bid FROM payment_statistic ".
00432 "WHERE pay_method = '1'";
00433
00434 $res = $ilDB->query($query);
00435 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00436 {
00437 return $row->bid;
00438 }
00439 return 0;
00440
00441 case 'pm_bmf':
00442 $query = "SELECT COUNT(booking_id) AS bid FROM payment_statistic ".
00443 "WHERE pay_method = '2'";
00444
00445 $res = $ilDB->query($query);
00446 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00447 {
00448 return $row->bid;
00449 }
00450 return 0;
00451
00452 case 'pm_paypal':
00453 $query = "SELECT COUNT(booking_id) AS bid FROM payment_statistic ".
00454 "WHERE pay_method = '3'";
00455
00456 $res = $ilDB->query($query);
00457 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00458 {
00459 return $row->bid;
00460 }
00461 return 0;
00462
00463 default:
00464 return 0;
00465 }
00466 }
00467
00468
00469
00470 function __read()
00471 {
00472 $query = 'SELECT * FROM payment_statistic as ps, payment_objects as po';
00473 if ($_SESSION["pay_statistics"]["customer"] or $_SESSION['pay_statistics']['vendor'])
00474 {
00475 $query .= ', usr_data as ud';
00476 }
00477 $query .= " WHERE ps.pobject_id = po.pobject_id ";
00478
00479 if ($_SESSION["pay_statistics"]["transaction_value"] != "")
00480 {
00481 if ($_SESSION["pay_statistics"]["transaction_type"] == 0)
00482 {
00483 $query .= "AND transaction_extern LIKE '" . $_SESSION["pay_statistics"]["transaction_value"] . "%' ";
00484 }
00485 else if ($_SESSION["pay_statistics"]["transaction_type"] == 1)
00486 {
00487 $query .= "AND transaction_extern LIKE '%" . $_SESSION["pay_statistics"]["transaction_value"] . "' ";
00488 }
00489 }
00490 if ($_SESSION["pay_statistics"]["customer"] != "")
00491 {
00492 $query .= "AND ud.login LIKE '%" . $_SESSION["pay_statistics"]["customer"] . "%' " .
00493 "AND ud.usr_id = ps.customer_id ";
00494 }
00495 if ($_SESSION["pay_statistics"]["from"]["day"] != "" &&
00496 $_SESSION["pay_statistics"]["from"]["month"] != "" &&
00497 $_SESSION["pay_statistics"]["from"]["year"] != "")
00498 {
00499 $from = mktime(0, 0, 0, $_SESSION["pay_statistics"]["from"]["month"],
00500 $_SESSION["pay_statistics"]["from"]["day"], $_SESSION["pay_statistics"]["from"]["year"]);
00501 $query .= "AND order_date >= '" . $from . "' ";
00502 }
00503 if ($_SESSION["pay_statistics"]["til"]["day"] != "" &&
00504 $_SESSION["pay_statistics"]["til"]["month"] != "" &&
00505 $_SESSION["pay_statistics"]["til"]["year"] != "")
00506 {
00507 $til = mktime(23, 59, 59, $_SESSION["pay_statistics"]["til"]["month"],
00508 $_SESSION["pay_statistics"]["til"]["day"], $_SESSION["pay_statistics"]["til"]["year"]);
00509 $query .= "AND order_date <= '" . $til . "' ";
00510 }
00511 if ($_SESSION["pay_statistics"]["payed"] == "0" ||
00512 $_SESSION["pay_statistics"]["payed"] == "1")
00513 {
00514 $query .= "AND payed = '" . $_SESSION["pay_statistics"]["payed"] . "' ";
00515 }
00516 if ($_SESSION["pay_statistics"]["access"] == "0" ||
00517 $_SESSION["pay_statistics"]["access"] == "1")
00518 {
00519 $query .= "AND access = '" . $_SESSION["pay_statistics"]["access"] . "' ";
00520 }
00521 if ($_SESSION["pay_statistics"]["pay_method"] == "1" ||
00522 $_SESSION["pay_statistics"]["pay_method"] == "2" ||
00523 $_SESSION["pay_statistics"]["pay_method"] == "3")
00524 {
00525 $query .= "AND b_pay_method = '" . $_SESSION["pay_statistics"]["pay_method"] . "' ";
00526 }
00527
00528 if(!$this->admin_view)
00529 {
00530 $vendors = $this->__getVendorIds();
00531 if (is_array($vendors) &&
00532 count($vendors) > 0)
00533 {
00534 $in = 'ps.b_vendor_id IN (';
00535 $in .= implode(',',$vendors);
00536 $in .= ')';
00537
00538 $query .= "AND ".$in." ";
00539 }
00540 }
00541 else
00542 {
00543 if($_SESSION['pay_statistics']['vendor'])
00544 {
00545 $query .= "AND ud.login LIKE '%" . $_SESSION["pay_statistics"]["vendor"] . "%' " .
00546 "AND ud.usr_id = ps.b_vendor_id ";
00547 }
00548 }
00549 $query .= "ORDER BY order_date DESC";
00550
00551 $res = $this->db->query($query);
00552 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00553 {
00554 $this->bookings[$row->booking_id]['booking_id'] = $row->booking_id;
00555 $this->bookings[$row->booking_id]['transaction'] = $row->transaction;
00556 $this->bookings[$row->booking_id]['pobject_id'] = $row->pobject_id;
00557 $this->bookings[$row->booking_id]['customer_id'] = $row->customer_id;
00558 $this->bookings[$row->booking_id]['order_date'] = $row->order_date;
00559 $this->bookings[$row->booking_id]['duration'] = $row->duration;
00560 $this->bookings[$row->booking_id]['price'] = $row->price;
00561 $this->bookings[$row->booking_id]['payed'] = $row->payed;
00562 $this->bookings[$row->booking_id]['access'] = $row->access;
00563 $this->bookings[$row->booking_id]['ref_id'] = $row->ref_id;
00564 $this->bookings[$row->booking_id]['status'] = $row->status;
00565 $this->bookings[$row->booking_id]['pay_method'] = $row->pay_method;
00566 $this->bookings[$row->booking_id]['vendor_id'] = $row->vendor_id;
00567 $this->bookings[$row->booking_id]['b_vendor_id'] = $row->b_vendor_id;
00568 $this->bookings[$row->booking_id]['b_pay_method'] = $row->b_pay_method;
00569 $this->bookings[$row->booking_id]['voucher'] = $row->voucher;
00570 $this->bookings[$row->booking_id]['transaction_extern'] = $row->transaction_extern;
00571
00572 }
00573
00574 }
00575
00576 function __getVendorIds()
00577 {
00578 if(ilPaymentVendors::_isVendor($this->user_id))
00579 {
00580 $vendors[] = $this->user_id;
00581 }
00582 if($vend = ilPaymentTrustees::_getVendorsForObjects($this->user_id))
00583 {
00584 foreach($vend as $v)
00585 {
00586 if(ilPaymentTrustees::_hasStatisticPermissionByVendor($this->user_id,$v))
00587 {
00588 $vendors[] = $v;
00589 #vendors = array_merge($vendors,$v);
00590 }
00591 }
00592 }
00593 return $vendors ? $vendors : array();
00594 }
00595
00596
00597 }
00598 ?>