  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
3 | | - | $Id: reviews.php 151 2005-08-02 14:33:25Z mattice $ |
| |
| 3 | + | $Id: reviews.php 368 2005-12-22 16:27:23Z hpdl $ |
|
4 | 4 | | |
| |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
|
|
 |
… |
|
13 | 13 | | class osC_Reviews { |
| |
14 | 14 | | var $is_enabled = false, |
| |
15 | 15 | | $is_moderated = false; |
  |
16 | | - | |
| |
| 16 | + | |
|
17 | 17 | | // class constructor |
| |
18 | 18 | | function osC_Reviews() { |
  |
19 | | - | |
| |
| 19 | + | |
|
20 | 20 | | $this->enableReviews(); |
| |
21 | 21 | | $this->enableModeration(); |
| |
22 | 22 | | } |
| |
|
|
 |
… |
|
29 | 29 | | $this->is_enabled = true; |
| |
30 | 30 | | break; |
| |
31 | 31 | | case 1: |
  |
32 | | - | if ($osC_Customer->isLoggedOn() == true) { |
| |
| 32 | + | if ($osC_Customer->isLoggedOn()) { |
|
33 | 33 | | $this->is_enabled = true; |
| |
34 | 34 | | } else { |
| |
35 | 35 | | $this->is_enabled = false; |
| |
|
|
 |
… |
|
47 | 47 | | break; |
| |
48 | 48 | | } |
| |
49 | 49 | | } |
  |
50 | | - | |
| |
| 50 | + | |
|
51 | 51 | | function hasPurchased() { |
| |
52 | 52 | | global $osC_Database, $osC_Customer; |
  |
53 | | - | |
| |
| 53 | + | |
|
54 | 54 | | $Qhaspurchased = $osC_Database->query('select count(*) as total from :table_orders o, :table_orders_products op, :table_products p where o.customers_id = :customers_id and o.orders_id = op.orders_id and op.products_id = p.products_id and op.products_id = :products_id'); |
| |
55 | 55 | | $Qhaspurchased->bindRaw(':table_orders', TABLE_ORDERS); |
| |
56 | 56 | | $Qhaspurchased->bindRaw(':table_orders_products', TABLE_ORDERS_PRODUCTS); |
| |
57 | 57 | | $Qhaspurchased->bindRaw(':table_products', TABLE_PRODUCTS); |
  |
58 | | - | $Qhaspurchased->bindInt(':customers_id', $osC_Customer->id); |
| |
| 58 | + | $Qhaspurchased->bindInt(':customers_id', $osC_Customer->getID()); |
|
59 | 59 | | $Qhaspurchased->bindInt(':products_id', $_GET['products_id']); |
| |
60 | 60 | | $Qhaspurchased->execute(); |
| |
61 | 61 | | |
| |
|
|
 |
… |
|
65 | 65 | | return false; |
| |
66 | 66 | | } |
| |
67 | 67 | | } |
  |
68 | | - | |
| |
| 68 | + | |
|
69 | 69 | | function enableModeration() { |
| |
70 | 70 | | global $osC_Database, $osC_Customer; |
| |
71 | 71 | | |
| |
|
|
 |
… |
|
74 | 74 | | $this->is_moderated = false; |
| |
75 | 75 | | break; |
| |
76 | 76 | | case 0: |
  |
77 | | - | if ($osC_Customer->isLoggedOn() === true) { |
| |
| 77 | + | if ($osC_Customer->isLoggedOn()) { |
|
78 | 78 | | $this->is_moderated = false; |
| |
79 | 79 | | } else { |
| |
80 | 80 | | $this->is_moderated = true; |
| |
|
|
 |
… |
|
88 | 88 | | break; |
| |
89 | 89 | | } |
| |
90 | 90 | | } |
  |
91 | | - | } |
| |
92 | | - | ?> |
| |
| 91 | + | |
| |
| 92 | + | function getTotal($id) { |
| |
| 93 | + | global $osC_Database; |
| |
| 94 | + | |
| |
| 95 | + | $Qcheck = $osC_Database->query('select count(*) as total from :table_reviews where products_id = :products_id and languages_id = :languages_id and reviews_status = 1 limit 1'); |
| |
| 96 | + | $Qcheck->bindTable(':table_reviews', TABLE_REVIEWS); |
| |
| 97 | + | $Qcheck->bindInt(':products_id', $id); |
| |
| 98 | + | $Qcheck->bindInt(':languages_id', $_SESSION['languages_id']); |
| |
| 99 | + | $Qcheck->execute(); |
| |
| 100 | + | |
| |
| 101 | + | return $Qcheck->valueInt('total'); |
| |
| 102 | + | } |
| |
| 103 | + | |
| |
| 104 | + | function exists($id = null, $groupped = false) { |
| |
| 105 | + | global $osC_Database; |
| |
| 106 | + | |
| |
| 107 | + | $Qcheck = $osC_Database->query('select reviews_id from :table_reviews where'); |
| |
| 108 | + | |
| |
| 109 | + | if (is_numeric($id)) { |
| |
| 110 | + | if ($groupped === false) { |
| |
| 111 | + | $Qcheck->appendQuery('reviews_id = :reviews_id and'); |
| |
| 112 | + | $Qcheck->bindInt(':reviews_id', $id); |
| |
| 113 | + | } else { |
| |
| 114 | + | $Qcheck->appendQuery('products_id = :products_id and'); |
| |
| 115 | + | $Qcheck->bindInt(':products_id', $id); |
| |
| 116 | + | } |
| |
| 117 | + | } |
| |
| 118 | + | |
| |
| 119 | + | $Qcheck->appendQuery('languages_id = :languages_id and reviews_status = 1 limit 1'); |
| |
| 120 | + | $Qcheck->bindTable(':table_reviews', TABLE_REVIEWS); |
| |
| 121 | + | $Qcheck->bindInt(':languages_id', $_SESSION['languages_id']); |
| |
| 122 | + | $Qcheck->execute(); |
| |
| 123 | + | |
| |
| 124 | + | if ($Qcheck->numberOfRows() === 1) { |
| |
| 125 | + | return true; |
| |
| 126 | + | } |
| |
| 127 | + | |
| |
| 128 | + | return false; |
| |
| 129 | + | } |
| |
| 130 | + | |
| |
| 131 | + | function getProductID($id) { |
| |
| 132 | + | global $osC_Database; |
| |
| 133 | + | |
| |
| 134 | + | $Qreview = $osC_Database->query('select products_id from :table_reviews where reviews_id = :reviews_id'); |
| |
| 135 | + | $Qreview->bindTable(':table_reviews', TABLE_REVIEWS); |
| |
| 136 | + | $Qreview->bindInt(':reviews_id', $id); |
| |
| 137 | + | $Qreview->execute(); |
| |
| 138 | + | |
| |
| 139 | + | return $Qreview->valueInt('products_id'); |
| |
| 140 | + | } |
| |
| 141 | + | |
| |
| 142 | + | function &getListing($id = null) { |
| |
| 143 | + | global $osC_Database; |
| |
| 144 | + | |
| |
| 145 | + | if (is_numeric($id)) { |
| |
| 146 | + | $Qreviews = $osC_Database->query('select reviews_id, reviews_text, reviews_rating, date_added, customers_name from :table_reviews where products_id = :products_id and languages_id = :languages_id and reviews_status = 1 order by reviews_id desc'); |
| |
| 147 | + | $Qreviews->bindInt(':products_id', $id); |
| |
| 148 | + | $Qreviews->bindInt(':languages_id', $_SESSION['languages_id']); |
| |
| 149 | + | } else { |
| |
| 150 | + | $Qreviews = $osC_Database->query('select r.reviews_id, left(r.reviews_text, 100) as reviews_text, r.reviews_rating, r.date_added, r.customers_name, p.products_id, p.products_image, p.products_price, p.products_tax_class_id, pd.products_name, pd.products_keyword from :table_reviews r, :table_products p, :table_products_description pd where r.reviews_status = 1 and r.languages_id = :languages_id and r.products_id = p.products_id and p.products_status = 1 and p.products_id = pd.products_id and pd.language_id = :language_id order by r.reviews_id desc'); |
| |
| 151 | + | $Qreviews->bindTable(':table_products', TABLE_PRODUCTS); |
| |
| 152 | + | $Qreviews->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION); |
| |
| 153 | + | $Qreviews->bindInt(':languages_id', $_SESSION['languages_id']); |
| |
| 154 | + | $Qreviews->bindInt(':language_id', $_SESSION['languages_id']); |
| |
| 155 | + | } |
| |
| 156 | + | $Qreviews->bindTable(':table_reviews', TABLE_REVIEWS); |
| |
| 157 | + | $Qreviews->setBatchLimit((isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1), MAX_DISPLAY_NEW_REVIEWS); |
| |
| 158 | + | $Qreviews->execute(); |
| |
| 159 | + | |
| |
| 160 | + | return $Qreviews; |
| |
| 161 | + | } |
| |
| 162 | + | |
| |
| 163 | + | function &getEntry($id) { |
| |
| 164 | + | global $osC_Database; |
| |
| 165 | + | |
| |
| 166 | + | $Qreviews = $osC_Database->query('select reviews_id, reviews_text, reviews_rating, date_added, customers_name from :table_reviews where reviews_id = :reviews_id and languages_id = :languages_id and reviews_status = 1'); |
| |
| 167 | + | $Qreviews->bindTable(':table_reviews', TABLE_REVIEWS); |
| |
| 168 | + | $Qreviews->bindInt(':reviews_id', $id); |
| |
| 169 | + | $Qreviews->bindInt(':languages_id', $_SESSION['languages_id']); |
| |
| 170 | + | $Qreviews->execute(); |
| |
| 171 | + | |
| |
| 172 | + | return $Qreviews; |
| |
| 173 | + | } |
| |
| 174 | + | |
| |
| 175 | + | function saveEntry($data) { |
| |
| 176 | + | global $osC_Database; |
| |
| 177 | + | |
| |
| 178 | + | $Qreview = $osC_Database->query('insert into :table_reviews (products_id, customers_id, customers_name, reviews_rating, languages_id, reviews_text, reviews_status, date_added) values (:products_id, :customers_id, :customers_name, :reviews_rating, :languages_id, :reviews_text, :reviews_status, now())'); |
| |
| 179 | + | $Qreview->bindTable(':table_reviews', TABLE_REVIEWS); |
| |
| 180 | + | $Qreview->bindInt(':products_id', $data['products_id']); |
| |
| 181 | + | $Qreview->bindInt(':customers_id', $data['customer_id']); |
| |
| 182 | + | $Qreview->bindValue(':customers_name', $data['customer_name']); |
| |
| 183 | + | $Qreview->bindValue(':reviews_rating', $data['rating']); |
| |
| 184 | + | $Qreview->bindInt(':languages_id', $_SESSION['languages_id']); |
| |
| 185 | + | $Qreview->bindValue(':reviews_text', $data['review']); |
| |
| 186 | + | $Qreview->bindInt(':reviews_status', $data['status']); |
| |
| 187 | + | $Qreview->execute(); |
| |
| 188 | + | } |
| |
| 189 | + | } |
| |
| 190 | + | ?> |