• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

payment/classes/class.ilPaymentBookings.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
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          * id of vendor, admin or trustee
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          * admin_view = true reads all statistic data (only_used in administration)
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         // SET GET
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         // STATIC
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                         default:
00453                                 return 0;
00454                 }
00455         }
00456 
00457 
00458         // PRIVATE
00459         function __read()
00460         {
00461                 $query = 'SELECT * FROM payment_statistic as ps, payment_objects as po';
00462                 if ($_SESSION["pay_statistics"]["customer"] or $_SESSION['pay_statistics']['vendor'])
00463                 {
00464                         $query .= ', usr_data as ud';
00465                 }
00466                 $query .= " WHERE ps.pobject_id = po.pobject_id ";
00467 
00468                 if ($_SESSION["pay_statistics"]["transaction_value"] != "")
00469                 {
00470                         if ($_SESSION["pay_statistics"]["transaction_type"] == 0)
00471                         {
00472                                 $query .= "AND transaction_extern LIKE '" . $_SESSION["pay_statistics"]["transaction_value"] . "%' ";
00473                         }
00474                         else if ($_SESSION["pay_statistics"]["transaction_type"] == 1)
00475                         {
00476                                 $query .= "AND transaction_extern LIKE '%" . $_SESSION["pay_statistics"]["transaction_value"] . "' ";
00477                         }
00478                 }
00479                 if ($_SESSION["pay_statistics"]["customer"] != "")
00480                 {
00481                         $query .= "AND ud.login LIKE '%" . $_SESSION["pay_statistics"]["customer"] . "%' " .
00482                                           "AND ud.usr_id = ps.customer_id ";
00483                 }
00484                 if ($_SESSION["pay_statistics"]["from"]["day"] != "" &&
00485                         $_SESSION["pay_statistics"]["from"]["month"] != "" &&
00486                         $_SESSION["pay_statistics"]["from"]["year"] != "")
00487                 {
00488                         $from = mktime(0, 0, 0, $_SESSION["pay_statistics"]["from"]["month"], 
00489                                                    $_SESSION["pay_statistics"]["from"]["day"], $_SESSION["pay_statistics"]["from"]["year"]);
00490                         $query .= "AND order_date >= '" . $from . "' ";
00491                 }
00492                 if ($_SESSION["pay_statistics"]["til"]["day"] != "" &&
00493                         $_SESSION["pay_statistics"]["til"]["month"] != "" &&
00494                         $_SESSION["pay_statistics"]["til"]["year"] != "")
00495                 {
00496                         $til = mktime(23, 59, 59, $_SESSION["pay_statistics"]["til"]["month"], 
00497                                                   $_SESSION["pay_statistics"]["til"]["day"], $_SESSION["pay_statistics"]["til"]["year"]);
00498                         $query .= "AND order_date <= '" . $til . "' ";
00499                 }
00500                 if ($_SESSION["pay_statistics"]["payed"] == "0" ||
00501                         $_SESSION["pay_statistics"]["payed"] == "1")
00502                 {
00503                         $query .= "AND payed = '" . $_SESSION["pay_statistics"]["payed"] . "' ";
00504                 }
00505                 if ($_SESSION["pay_statistics"]["access"] == "0" ||
00506                         $_SESSION["pay_statistics"]["access"] == "1")
00507                 {
00508                         $query .= "AND access = '" . $_SESSION["pay_statistics"]["access"] . "' ";
00509                 }
00510                 
00511                 if(!$this->admin_view)
00512                 {
00513                         $vendors = $this->__getVendorIds();
00514                         if (is_array($vendors) &&
00515                                 count($vendors) > 0)
00516                         {
00517                                 $in = 'ps.b_vendor_id IN (';
00518                                 $in .= implode(',',$vendors);
00519                                 $in .= ')';
00520                                 
00521                                 $query .= "AND ".$in." ";
00522                         }
00523                 }
00524                 else
00525                 {
00526                         if($_SESSION['pay_statistics']['vendor'])
00527                         {
00528                                 $query .= "AND ud.login LIKE '%" . $_SESSION["pay_statistics"]["vendor"] . "%' " .
00529                                         "AND ud.usr_id = ps.b_vendor_id ";
00530                         }
00531                 }
00532                 $query .= "ORDER BY order_date DESC";
00533 
00534                 $res = $this->db->query($query);
00535                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00536                 {
00537                         $this->bookings[$row->booking_id]['booking_id'] = $row->booking_id;
00538                         $this->bookings[$row->booking_id]['transaction'] = $row->transaction;
00539                         $this->bookings[$row->booking_id]['pobject_id'] = $row->pobject_id;
00540                         $this->bookings[$row->booking_id]['customer_id'] = $row->customer_id;
00541                         $this->bookings[$row->booking_id]['order_date'] = $row->order_date;
00542                         $this->bookings[$row->booking_id]['duration'] = $row->duration;
00543                         $this->bookings[$row->booking_id]['price'] = $row->price;
00544                         $this->bookings[$row->booking_id]['payed'] = $row->payed;
00545                         $this->bookings[$row->booking_id]['access'] = $row->access;
00546                         $this->bookings[$row->booking_id]['ref_id'] = $row->ref_id;
00547                         $this->bookings[$row->booking_id]['status'] = $row->status;
00548                         $this->bookings[$row->booking_id]['pay_method'] = $row->pay_method;
00549                         $this->bookings[$row->booking_id]['vendor_id'] = $row->vendor_id;
00550                         $this->bookings[$row->booking_id]['b_vendor_id'] = $row->b_vendor_id;
00551                         $this->bookings[$row->booking_id]['b_pay_method'] = $row->b_pay_method;
00552                         $this->bookings[$row->booking_id]['voucher'] = $row->voucher;
00553                         $this->bookings[$row->booking_id]['transaction_extern'] = $row->transaction_extern;
00554                         
00555                 }
00556 
00557         }
00558 
00559         function __getVendorIds()
00560         {
00561                 if(ilPaymentVendors::_isVendor($this->user_id))
00562                 {
00563                         $vendors[] = $this->user_id;
00564                 }
00565                 if($vend = ilPaymentTrustees::_getVendorsForObjects($this->user_id))
00566                 {
00567                         foreach($vend as $v)
00568                         {
00569                                 if(ilPaymentTrustees::_hasStatisticPermissionByVendor($this->user_id,$v))
00570                                 {
00571                                         $vendors[] = $v;
00572                                         #vendors = array_merge($vendors,$v);
00573                                 }
00574                         }
00575                 }
00576                 return $vendors ? $vendors : array();
00577         }
00578                 
00579                 
00580 }
00581 ?>

Generated on Fri Dec 13 2013 09:06:37 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1