| 1 | <?php |
|---|
| 2 | // $Id: partners.php,v 1.2 2005/03/18 12:52:49 onokazu Exp $ |
|---|
| 3 | // ------------------------------------------------------------------------ // |
|---|
| 4 | // XOOPS - PHP Content Management System // |
|---|
| 5 | // Copyright (c) 2000 XOOPS.org // |
|---|
| 6 | // <http://www.xoops.org/> // |
|---|
| 7 | // ------------------------------------------------------------------------ // |
|---|
| 8 | // This program is free software; you can redistribute it and/or modify // |
|---|
| 9 | // it under the terms of the GNU General Public License as published by // |
|---|
| 10 | // the Free Software Foundation; either version 2 of the License, or // |
|---|
| 11 | // (at your option) any later version. // |
|---|
| 12 | // // |
|---|
| 13 | // You may not change or alter any portion of this comment or credits // |
|---|
| 14 | // of supporting developers from this source code or any supporting // |
|---|
| 15 | // source code which is considered copyrighted (c) material of the // |
|---|
| 16 | // original comment or credit authors. // |
|---|
| 17 | // // |
|---|
| 18 | // This program is distributed in the hope that it will be useful, // |
|---|
| 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|---|
| 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|---|
| 21 | // GNU General Public License for more details. // |
|---|
| 22 | // // |
|---|
| 23 | // You should have received a copy of the GNU General Public License // |
|---|
| 24 | // along with this program; if not, write to the Free Software // |
|---|
| 25 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
|---|
| 26 | // ------------------------------------------------------------------------ // |
|---|
| 27 | // Author: Raul Recio (AKA UNFOR) // |
|---|
| 28 | // Project: The XOOPS Project // |
|---|
| 29 | // ------------------------------------------------------------------------- // |
|---|
| 30 | |
|---|
| 31 | include_once XOOPS_ROOT_PATH."/class/xoopsobject.php"; |
|---|
| 32 | |
|---|
| 33 | class PartnerSystem extends XoopsObject |
|---|
| 34 | { |
|---|
| 35 | var $db; |
|---|
| 36 | |
|---|
| 37 | // constructor |
|---|
| 38 | function PartnerSystem($id=null) |
|---|
| 39 | { |
|---|
| 40 | $this->db =& Database::getInstance(); |
|---|
| 41 | $this->initVar("id", XOBJ_DTYPE_INT, null, false); |
|---|
| 42 | $this->initVar("weight", XOBJ_DTYPE_INT, null, false, 10); |
|---|
| 43 | $this->initVar("hits", XOBJ_DTYPE_INT, null, true, 10); |
|---|
| 44 | $this->initVar("url", XOBJ_DTYPE_TXTBOX, null, true); |
|---|
| 45 | $this->initVar("image", XOBJ_DTYPE_TXTBOX, null, true); |
|---|
| 46 | $this->initVar("title", XOBJ_DTYPE_TXTBOX, null, false); |
|---|
| 47 | $this->initVar("description", XOBJ_DTYPE_TXTBOX, null, true); |
|---|
| 48 | if ( !empty($id) ) { |
|---|
| 49 | if ( is_array($id) ) { |
|---|
| 50 | $this->assignVars($id); |
|---|
| 51 | } else { |
|---|
| 52 | $this->load(intval($id)); |
|---|
| 53 | } |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | function load($id) |
|---|
| 58 | { |
|---|
| 59 | $sql = "SELECT * FROM ".$this->db->prefix("partners")." WHERE id=$id and status=1"; |
|---|
| 60 | $myrow = $this->db->fetchArray($this->db->query($sql)); |
|---|
| 61 | $this->assignVars($myrow); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | function getAllPartners($criteria=array(), $asobject=false, $sort="hits", $order="DESC", $limit=0, $start=0) |
|---|
| 65 | { |
|---|
| 66 | $db =& Database::getInstance(); |
|---|
| 67 | $ret = array(); |
|---|
| 68 | $where_query = ""; |
|---|
| 69 | if ( is_array($criteria) && count($criteria) > 0 ) { |
|---|
| 70 | $where_query = " WHERE"; |
|---|
| 71 | foreach ( $criteria as $c ) { |
|---|
| 72 | $where_query .= " $c AND"; |
|---|
| 73 | } |
|---|
| 74 | $where_query = substr($where_query, 0, -4); |
|---|
| 75 | } elseif ( !is_array($criteria) ) { |
|---|
| 76 | $where_query = " WHERE ".$criteria; |
|---|
| 77 | } |
|---|
| 78 | if ( !$asobject ) { |
|---|
| 79 | $sql = "SELECT id FROM ".$db->prefix("partners")."$where_query ORDER BY $sort $order"; |
|---|
| 80 | $result = $db->query($sql,$limit,$start); |
|---|
| 81 | while ( $myrow = $db->fetchArray($result) ) { |
|---|
| 82 | $ret[] = $myrow['id']; |
|---|
| 83 | } |
|---|
| 84 | } else { |
|---|
| 85 | $sql = "SELECT * FROM ".$db->prefix("partners")."".$where_query." ORDER BY $sort $order"; |
|---|
| 86 | $result = $db->query($sql,$limit,$start); |
|---|
| 87 | while ( $myrow = $db->fetchArray($result) ) { |
|---|
| 88 | $ret[] = new PartnerSystem($myrow); |
|---|
| 89 | } |
|---|
| 90 | } |
|---|
| 91 | return $ret; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | function setHits($id) |
|---|
| 95 | { |
|---|
| 96 | $db =& Database::getInstance(); |
|---|
| 97 | $db->queryF("UPDATE ".$db->prefix("partners")." SET hits=hits+1 WHERE id=$id"); |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | ?> |
|---|