hpdl
|
1
|
1
|
<?php
|
|
2
|
/*
|
hpdl
|
153
|
3
|
$Id: reviews.php 556 2006-04-30 23:57:23Z hpdl $
|
hpdl
|
1
|
4
|
|
|
5
|
osCommerce, Open Source E-Commerce Solutions
|
|
6
|
http://www.oscommerce.com
|
|
7
|
|
hpdl
|
555
|
8
|
Copyright (c) 2006 osCommerce
|
hpdl
|
1
|
9
|
|
|
10
|
Released under the GNU General Public License
|
|
11
|
*/
|
|
12
|
|
|
13
|
class osC_Reviews {
|
|
14
|
var $is_enabled = false,
|
|
15
|
$is_moderated = false;
|
hpdl
|
246
|
16
|
|
hpdl
|
1
|
17
|
// class constructor
|
|
18
|
function osC_Reviews() {
|
hpdl
|
246
|
19
|
|
hpdl
|
1
|
20
|
$this->enableReviews();
|
|
21
|
$this->enableModeration();
|
|
22
|
}
|
|
23
|
|
|
24
|
function enableReviews() {
|
|
25
|
global $osC_Database, $osC_Customer;
|
|
26
|
|
|
27
|
switch (SERVICE_REVIEW_ENABLE_REVIEWS) {
|
|
28
|
case 0:
|
|
29
|
$this->is_enabled = true;
|
|
30
|
break;
|
|
31
|
case 1:
|
hpdl
|
184
|
32
|
if ($osC_Customer->isLoggedOn()) {
|
hpdl
|
1
|
33
|
$this->is_enabled = true;
|
|
34
|
} else {
|
|
35
|
$this->is_enabled = false;
|
|
36
|
}
|
|
37
|
break;
|
|
38
|
case 2:
|
|
39
|
if ($this->hasPurchased() == true) {
|
|
40
|
$this->is_enabled = true;
|
|
41
|
} else {
|
|
42
|
$this->is_enabled = false;
|
|
43
|
}
|
|
44
|
break;
|
|
45
|
default:
|
|
46
|
$this->is_enabled = false;
|
|
47
|
break;
|
|
48
|
}
|
|
49
|
}
|
hpdl
|
246
|
50
|
|
hpdl
|
1
|
51
|
function hasPurchased() {
|
|
52
|
global $osC_Database, $osC_Customer;
|
hpdl
|
246
|
53
|
|
hpdl
|
1
|
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
|
$Qhaspurchased->bindRaw(':table_orders', TABLE_ORDERS);
|
|
56
|
$Qhaspurchased->bindRaw(':table_orders_products', TABLE_ORDERS_PRODUCTS);
|
|
57
|
$Qhaspurchased->bindRaw(':table_products', TABLE_PRODUCTS);
|
hpdl
|
184
|
58
|
$Qhaspurchased->bindInt(':customers_id', $osC_Customer->getID());
|
hpdl
|
1
|
59
|
$Qhaspurchased->bindInt(':products_id', $_GET['products_id']);
|
|
60
|
$Qhaspurchased->execute();
|
|
61
|
|
|
62
|
if ($Qhaspurchased->valueInt('total') >= '1') {
|
|
63
|
return true;
|
|
64
|
} else {
|
|
65
|
return false;
|
|
66
|
}
|
|
67
|
}
|
hpdl
|
246
|
68
|
|
hpdl
|
1
|
69
|
function enableModeration() {
|
|
70
|
global $osC_Database, $osC_Customer;
|
|
71
|
|
|
72
|
switch (SERVICE_REVIEW_ENABLE_MODERATION) {
|
|
73
|
case -1:
|
|
74
|
$this->is_moderated = false;
|
|
75
|
break;
|
|
76
|
case 0:
|
hpdl
|
184
|
77
|
if ($osC_Customer->isLoggedOn()) {
|
hpdl
|
1
|
78
|
$this->is_moderated = false;
|
|
79
|
} else {
|
|
80
|
$this->is_moderated = true;
|
|
81
|
}
|
|
82
|
break;
|
|
83
|
case 1:
|
|
84
|
$this->is_moderated = true;
|
|
85
|
break;
|
|
86
|
default:
|
|
87
|
$this->is_moderated = true;
|
|
88
|
break;
|
|
89
|
}
|
|
90
|
}
|
hpdl
|
210
|
91
|
|
|
92
|
function getTotal($id) {
|
hpdl
|
377
|
93
|
global $osC_Database, $osC_Language;
|
hpdl
|
210
|
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);
|
hpdl
|
377
|
98
|
$Qcheck->bindInt(':languages_id', $osC_Language->getID());
|
hpdl
|
210
|
99
|
$Qcheck->execute();
|
|
100
|
|
|
101
|
return $Qcheck->valueInt('total');
|
|
102
|
}
|
|
103
|
|
hpdl
|
213
|
104
|
function exists($id = null, $groupped = false) {
|
hpdl
|
377
|
105
|
global $osC_Database, $osC_Language;
|
hpdl
|
210
|
106
|
|
hpdl
|
212
|
107
|
$Qcheck = $osC_Database->query('select reviews_id from :table_reviews where');
|
|
108
|
|
|
109
|
if (is_numeric($id)) {
|
hpdl
|
213
|
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
|
}
|
hpdl
|
212
|
117
|
}
|
|
118
|
|
|
119
|
$Qcheck->appendQuery('languages_id = :languages_id and reviews_status = 1 limit 1');
|
hpdl
|
210
|
120
|
$Qcheck->bindTable(':table_reviews', TABLE_REVIEWS);
|
hpdl
|
377
|
121
|
$Qcheck->bindInt(':languages_id', $osC_Language->getID());
|
hpdl
|
210
|
122
|
$Qcheck->execute();
|
|
123
|
|
|
124
|
if ($Qcheck->numberOfRows() === 1) {
|
|
125
|
return true;
|
|
126
|
}
|
|
127
|
|
|
128
|
return false;
|
|
129
|
}
|
hpdl
|
212
|
130
|
|
hpdl
|
213
|
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
|
|
hpdl
|
212
|
142
|
function &getListing($id = null) {
|
hpdl
|
555
|
143
|
global $osC_Database, $osC_Language, $osC_Image;
|
hpdl
|
212
|
144
|
|
hpdl
|
213
|
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);
|
hpdl
|
377
|
148
|
$Qreviews->bindInt(':languages_id', $osC_Language->getID());
|
hpdl
|
213
|
149
|
} else {
|
hpdl
|
556
|
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_price, p.products_tax_class_id, pd.products_name, pd.products_keyword, i.image from :table_reviews r, :table_products p left join :table_products_images i on (p.products_id = i.products_id and i.products_images_groups_id = :products_images_groups_id), :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');
|
hpdl
|
213
|
151
|
$Qreviews->bindTable(':table_products', TABLE_PRODUCTS);
|
hpdl
|
556
|
152
|
$Qreviews->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
|
hpdl
|
213
|
153
|
$Qreviews->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
|
hpdl
|
556
|
154
|
$Qreviews->bindTable(':products_images_groups_id', $osC_Image->getID('default'));
|
hpdl
|
377
|
155
|
$Qreviews->bindInt(':languages_id', $osC_Language->getID());
|
|
156
|
$Qreviews->bindInt(':language_id', $osC_Language->getID());
|
hpdl
|
213
|
157
|
}
|
hpdl
|
212
|
158
|
$Qreviews->bindTable(':table_reviews', TABLE_REVIEWS);
|
|
159
|
$Qreviews->setBatchLimit((isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1), MAX_DISPLAY_NEW_REVIEWS);
|
|
160
|
$Qreviews->execute();
|
|
161
|
|
|
162
|
return $Qreviews;
|
|
163
|
}
|
hpdl
|
213
|
164
|
|
|
165
|
function &getEntry($id) {
|
hpdl
|
377
|
166
|
global $osC_Database, $osC_Language;
|
hpdl
|
213
|
167
|
|
|
168
|
$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');
|
|
169
|
$Qreviews->bindTable(':table_reviews', TABLE_REVIEWS);
|
|
170
|
$Qreviews->bindInt(':reviews_id', $id);
|
hpdl
|
377
|
171
|
$Qreviews->bindInt(':languages_id', $osC_Language->getID());
|
hpdl
|
213
|
172
|
$Qreviews->execute();
|
|
173
|
|
|
174
|
return $Qreviews;
|
|
175
|
}
|
hpdl
|
215
|
176
|
|
|
177
|
function saveEntry($data) {
|
hpdl
|
377
|
178
|
global $osC_Database, $osC_Language;
|
hpdl
|
215
|
179
|
|
|
180
|
$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())');
|
|
181
|
$Qreview->bindTable(':table_reviews', TABLE_REVIEWS);
|
|
182
|
$Qreview->bindInt(':products_id', $data['products_id']);
|
|
183
|
$Qreview->bindInt(':customers_id', $data['customer_id']);
|
|
184
|
$Qreview->bindValue(':customers_name', $data['customer_name']);
|
|
185
|
$Qreview->bindValue(':reviews_rating', $data['rating']);
|
hpdl
|
377
|
186
|
$Qreview->bindInt(':languages_id', $osC_Language->getID());
|
hpdl
|
215
|
187
|
$Qreview->bindValue(':reviews_text', $data['review']);
|
|
188
|
$Qreview->bindInt(':reviews_status', $data['status']);
|
|
189
|
$Qreview->execute();
|
|
190
|
}
|
hpdl
|
246
|
191
|
}
|
hpdl
|
213
|
192
|
?>
|