Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00033 define ("PAY_METHOD_NOT_SPECIFIED", 0);
00034 define ("PAY_METHOD_BILL", 1);
00035 define ("PAY_METHOD_BMF", 2);
00036 define ("PAY_METHOD_PAYPAL", 3);
00037
00038 class ilPaymentObject
00039 {
00040 var $db = null;
00041 var $user_obj = null;
00042 var $pobject_id = null;
00043
00044 var $ref_id = null;
00045 var $status = null;
00046 var $pay_method = null;
00047 var $vendor_id = null;
00048
00049 function ilPaymentObject(&$user_obj,$a_pobject_id = null)
00050 {
00051 global $ilDB;
00052
00053 $this->db =& $ilDB;
00054 $this->user_obj =& $user_obj;
00055
00056 $this->STATUS_NOT_BUYABLE = 0;
00057 $this->STATUS_BUYABLE = 1;
00058 $this->STATUS_EXPIRES = 2;
00059
00060 $this->PAY_METHOD_NOT_SPECIFIED = PAY_METHOD_NOT_SPECIFIED;
00061 $this->PAY_METHOD_BILL = PAY_METHOD_BILL;
00062 $this->PAY_METHOD_BMF = PAY_METHOD_BMF;
00063 $this->PAY_METHOD_PAYPAL = PAY_METHOD_PAYPAL;
00064
00065 $this->pobject_id = $a_pobject_id;
00066 $this->__read();
00067 }
00068
00069
00070 function getPobjectId()
00071 {
00072 return $this->pobject_id;
00073 }
00074
00075 function setRefId($a_ref_id)
00076 {
00077 $this->ref_id = $a_ref_id;
00078 }
00079 function getRefId()
00080 {
00081 return $this->ref_id;
00082 }
00083 function setStatus($a_status)
00084 {
00085 $this->status = $a_status;
00086 }
00087 function getStatus()
00088 {
00089 return $this->status;
00090 }
00091 function setPayMethod($a_method)
00092 {
00093 $this->pay_method = $a_method;
00094 }
00095 function getPayMethod()
00096 {
00097 return $this->pay_method;
00098 }
00099 function setVendorId($a_vendor_id)
00100 {
00101 $this->vendor_id= $a_vendor_id;
00102 }
00103 function getVendorId()
00104 {
00105 return $this->vendor_id;
00106 }
00107
00108
00109
00110
00111 function add()
00112 {
00113 $query = "INSERT INTO payment_objects ".
00114 "VALUES('','".
00115 $this->getRefId()."','".
00116 $this->getStatus()."',' ".
00117 $this->getPayMethod()."',' ".
00118 $this->getVendorId()."')";
00119
00120 $this->db->query($query);
00121
00122 $query = "SELECT LAST_INSERT_ID() as new_id";
00123
00124 $res = $this->db->query($query);
00125 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00126 {
00127 return $row->new_id;
00128 }
00129 return false;
00130 }
00131 function delete()
00132 {
00133 if($this->getPobjectId())
00134 {
00135 $query = "DELETE FROM payment_objects ".
00136 "WHERE pobject_id = '".$this->getPobjectId()."'";
00137
00138 $this->db->query($query);
00139
00140 return true;
00141 }
00142 return false;
00143 }
00144
00145 function update()
00146 {
00147 $query = "UPDATE payment_objects ".
00148 "SET ref_id = '".$this->getRefId()."', ".
00149 "status = '".$this->getStatus()."', ".
00150 "pay_method = '".$this->getPayMethod()."', ".
00151 "vendor_id = '".$this->getVendorId()."' ".
00152 "WHERE pobject_id = '".$this->getPobjectId()."'";
00153
00154 $this->db->query($query);
00155
00156 return true;
00157 }
00158
00159 function _lookupPobjectId($a_ref_id)
00160 {
00161 global $ilDB;
00162
00163 $query = "SELECT * FROM payment_objects ".
00164 "WHERE ref_id = '".$a_ref_id."'";
00165
00166 $res = $ilDB->query($query);
00167 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00168 {
00169 return $row->pobject_id;
00170 }
00171 return 0;
00172 }
00173
00174 function _getCountObjectsByPayMethod($a_type)
00175 {
00176 global $ilDB;
00177
00178 switch($a_type)
00179 {
00180 case 'pm_bill':
00181 $pm = 1;
00182 break;
00183
00184 case 'pm_bmf':
00185 $pm = 2;
00186 break;
00187
00188 case 'pm_paypal':
00189 $pm = 3;
00190 break;
00191
00192 default:
00193 $pm = -1;
00194 }
00195
00196 $query = 'SELECT count(pay_method) as pm FROM payment_objects '.
00197 "WHERE pay_method = '".$pm."'";
00198
00199 $res = $ilDB->query($query);
00200
00201 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00202 {
00203 return $row->pm;
00204 }
00205 return 0;
00206 }
00207
00208 function _getObjectsData($a_user_id)
00209 {
00210 global $ilDB;
00211
00212
00213 include_once './payment/classes/class.ilPaymentTrustees.php';
00214 include_once './payment/classes/class.ilPaymentVendors.php';
00215
00216 $vendors = ilPaymentTrustees::_getVendorsForObjects($a_user_id);
00217
00218 if(ilPaymentVendors::_isVendor($a_user_id))
00219 {
00220 $vendors[] = $a_user_id;
00221 }
00222
00223 if(!count($vendors))
00224 {
00225 return array();
00226 }
00227 $in = " IN ('";
00228 $in .= implode("','",$vendors);
00229 $in .= "')";
00230
00231 $query = "SELECT * FROM payment_objects ".
00232 "WHERE vendor_id ".$in;
00233
00234 $res = $ilDB->query($query);
00235 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00236 {
00237 $objects[$row->pobject_id]['pobject_id'] = $row->pobject_id;
00238 $objects[$row->pobject_id]['ref_id'] = $row->ref_id;
00239 $objects[$row->pobject_id]['status'] = $row->status;
00240 $objects[$row->pobject_id]['pay_method'] = $row->pay_method;
00241 $objects[$row->pobject_id]['vendor_id'] = $row->vendor_id;
00242 }
00243 return $objects ? $objects : array();
00244 }
00245
00246 function _getAllObjectsData()
00247 {
00248 global $ilDB;
00249
00250 $query = "SELECT * FROM payment_objects ";
00251
00252 if ($_SESSION["pay_objects"]["title_value"] != "")
00253 {
00254 $query .= ", object_reference AS obr ";
00255 $query .= ", object_data AS od ";
00256 }
00257
00258 if ($_SESSION['pay_objects']['vendor'] != "")
00259 {
00260 $query .= ", usr_data AS ud ";
00261 }
00262
00263 $query .= " WHERE 1 ";
00264
00265 if ($_SESSION["pay_objects"]["title_value"])
00266 {
00267 $query .= " AND obr.ref_id = payment_objects.ref_id AND od.obj_id = obr.obj_id ";
00268
00269 $search_string = "";
00270
00271 $title_search = explode(" ", trim($_SESSION["pay_objects"]["title_value"]));
00272 for ($i = 0; $i < count($title_search); $i++)
00273 {
00274 $title_search[$i] = trim($title_search[$i]);
00275
00276 if ($title_search[$i] != "")
00277 {
00278 $search_string .= " od.title LIKE ".$ilDB->quote("%".$title_search[$i]."%")." ";
00279
00280 switch ($_SESSION["pay_objects"]["title_type"])
00281 {
00282 case "or" :
00283 if ($i < count($title_search) - 1) $search_string .= " OR ";
00284 break;
00285 case "and" :
00286 if ($i < count($title_search) - 1) $search_string .= " AND ";
00287 break;
00288 }
00289 }
00290 }
00291
00292 if ($search_string != "")
00293 {
00294 $query .= " AND (" . $search_string . ") ";
00295 }
00296 }
00297
00298 if ($_SESSION['pay_objects']['vendor'] != "")
00299 {
00300 $query .= " AND ud.usr_id = payment_objects.vendor_id AND login = ".$ilDB->quote($_SESSION["pay_objects"]["vendor"])." ";
00301 }
00302
00303
00304 if ($_SESSION["pay_objects"]["pay_method"] == "1" ||
00305 $_SESSION["pay_objects"]["pay_method"] == "2" ||
00306 $_SESSION["pay_objects"]["pay_method"] == "3")
00307 {
00308 $query .= " AND pay_method = '" . $_SESSION["pay_objects"]["pay_method"] . "' ";
00309 }
00310
00311 $res = $ilDB->query($query);
00312 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00313 {
00314 $objects[$row->pobject_id]['pobject_id'] = $row->pobject_id;
00315 $objects[$row->pobject_id]['ref_id'] = $row->ref_id;
00316 $objects[$row->pobject_id]['status'] = $row->status;
00317 $objects[$row->pobject_id]['pay_method'] = $row->pay_method;
00318 $objects[$row->pobject_id]['vendor_id'] = $row->vendor_id;
00319 }
00320 return $objects ? $objects : array();
00321 }
00322
00323 function _getObjectData($a_id)
00324 {
00325 global $ilDB;
00326
00327 $query = "SELECT * FROM payment_objects ".
00328 "WHERE pobject_id = '".$a_id."'";
00329
00330 $res = $ilDB->query($query);
00331
00332 if (is_object($res))
00333 {
00334 return $res->fetchRow(DB_FETCHMODE_ASSOC);
00335 }
00336
00337 return false;
00338 }
00339
00340 function _isPurchasable($a_ref_id, $a_vendor_id = 0)
00341 {
00342 global $ilDB;
00343
00344
00345 $query = "SELECT * FROM payment_objects ".
00346 "WHERE ref_id = '".$a_ref_id."' ";
00347 if ($a_vendor_id > 0)
00348 {
00349 $query .= "AND vendor_id = '".$a_vendor_id."' ";
00350 }
00351 #"AND status = '1' OR status = '3' ";
00352
00353 $res = $ilDB->query($query);
00354
00355 return $res->numRows() ? false : true;
00356 }
00357
00358
00359 function _hasAccess($a_ref_id)
00360 {
00361 include_once './payment/classes/class.ilPaymentBookings.php';
00362
00363 global $rbacsystem,$ilDB;
00364
00365
00366 if($rbacsystem->checkAccess('write',$a_ref_id))
00367 {
00368 return true;
00369 }
00370 $query = "SELECT * FROM payment_objects ".
00371 "WHERE ref_id = '".$a_ref_id."' ".
00372 "AND (status = '1' OR status = '2')";
00373
00374 $res = $ilDB->query($query);
00375 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00376 {
00377 if(!ilPaymentBookings::_hasAccess($row->pobject_id))
00378 {
00379 return false;
00380 }
00381 }
00382 return true;
00383 }
00384
00385 function _getActivation($a_ref_id)
00386 {
00387 include_once './payment/classes/class.ilPaymentBookings.php';
00388
00389 global $rbacsystem,$ilDB;
00390
00391 $query = "SELECT * FROM payment_objects ".
00392 "WHERE ref_id = '".$a_ref_id."' ".
00393 "AND (status = '1' OR status = '2')";
00394
00395 $res = $ilDB->query($query);
00396 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
00397 return ilPaymentBookings::_getActivation($row->pobject_id);
00398 }
00399 function _isBuyable($a_ref_id)
00400 {
00401 global $ilDB;
00402
00403 $query = "SELECT * FROM payment_objects ".
00404 "WHERE ref_id = '".$a_ref_id."' ".
00405 "AND (status = 1 or status = 2)";
00406
00407 $res = $ilDB->query($query);
00408 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00409 {
00410 return true;
00411 }
00412 return false;
00413 }
00414 function _isInCart($a_ref_id)
00415 {
00416 global $ilDB, $ilUser;
00417
00418 $query = "SELECT psc_id FROM payment_objects AS po, payment_shopping_cart AS psc ".
00419 "WHERE ref_id = '".$a_ref_id."' ".
00420 "AND customer_id = '".$ilUser->getId()."' ".
00421 "AND po.pobject_id = psc.pobject_id";
00422
00423 $res = $ilDB->query($query);
00424 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00425 {
00426 return true;
00427 }
00428 return false;
00429 }
00430
00431
00432 function __read()
00433 {
00434 if($this->getPobjectId())
00435 {
00436 $query = "SELECT * FROM payment_objects ".
00437 "WHERE pobject_id = '".$this->getPobjectId()."'";
00438
00439 $res = $this->db->query($query);
00440 while($row =& $res->fetchRow(DB_FETCHMODE_OBJECT))
00441 {
00442 $this->setRefId($row->ref_id);
00443 $this->setStatus($row->status);
00444 $this->setPayMethod($row->pay_method);
00445 $this->setVendorId($row->vendor_id);
00446
00447 return true;
00448 }
00449 }
00450 return false;
00451 }
00452
00453
00454 }
00455 ?>