Quick Search:

View

Revision:

Diff

Diff from 298 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/includes/modules/content/recently_visited.php

Annotated File View

hpdl
228
1 <?php
2 /*
3
4   osCommerce, Open Source E-Commerce Solutions
5   http://www.oscommerce.com
6
hpdl
296
7   Copyright (c) 2005 osCommerce
hpdl
228
8
9   Released under the GNU General Public License
10 */
11
hpdl
297
12   class osC_RecentlyVisited {
hpdl
228
13
hpdl
290
14     var $visits = array();
hpdl
228
15
16 /* Class constructor */
17
hpdl
297
18     function osC_RecentlyVisited() {
hpdl
296
19       if (isset($_SESSION['osC_RecentlyVisited_data']) === false) {
20         $_SESSION['osC_RecentlyVisited_data'] = array();
21       }
22
23       $this->visits =& $_SESSION['osC_RecentlyVisited_data'];
hpdl
290
24     }
hpdl
228
25
hpdl
290
26     function contentModuleInitialize() {
hpdl
298
27       global $osC_Product, $osC_Category, $osC_Search;
hpdl
228
28
hpdl
297
29       if (isset($osC_Product) && is_a($osC_Product, 'osC_Product')) {
30         $this->setProduct($osC_Product->getID());
hpdl
290
31       }
hpdl
297
32
33       if (SERVICE_RECENTLY_VISITED_SHOW_CATEGORIES == 'True') {
hpdl
298
34         if (isset($osC_Category) && is_a($osC_Category, 'osC_Category')) {
35           $this->setCategory($osC_Category->getID());
36         }
hpdl
297
37       }
38
39       if (SERVICE_RECENTLY_VISITED_SHOW_SEARCHES == 'True') {
hpdl
298
40         if (isset($osC_Search) && is_a($osC_Search, 'osC_Search')) {
41           if ($osC_Search->hasKeywords()) {
42             $this->setSearchQuery($osC_Search->getKeywords());
43           }
44         }
hpdl
297
45       }
hpdl
290
46     }
47
48     function getContentModule() {
49       return 'recently_visited.php';
50     }
51
hpdl
298
52     function setProduct($id) {
53       if (isset($this->visits['products'])) {
54         foreach ($this->visits['products'] as $key => $value) {
55           if ($value['id'] == $id) {
56             unset($this->visits['products'][$key]);
57             break;
58           }
59         }
60
61         if (sizeof($this->visits['products']) > (MAX_RECENTLY_VISITED_PRODUCTS * 2)) {
62           array_pop($this->visits['products']);
63         }
64       } else {
65         $this->visits['products'] = array();
hpdl
228
66       }
67
hpdl
298
68       array_unshift($this->visits['products'], array('id' => $id));
69     }
hpdl
228
70
hpdl
298
71     function setCategory($id) {
72       if (isset($this->visits['categories'])) {
73         foreach ($this->visits['categories'] as $key => $value) {
74           if ($value['id'] == $id) {
75             unset($this->visits['categories'][$key]);
76             break;
77           }
78         }
hpdl
228
79
hpdl
298
80         if (sizeof($this->visits['categories']) > (MAX_RECENTLY_VISITED_CATEGORIES * 2)) {
81           array_pop($this->visits['categories']);
82         }
83       } else {
84         $this->visits['categories'] = array();
85       }
hpdl
228
86
hpdl
298
87       array_unshift($this->visits['categories'], array('id' => $id));
88     }
hpdl
228
89
hpdl
298
90     function setSearchQuery($keywords) {
91       global $osC_Search;
hpdl
228
92
hpdl
298
93       if (isset($this->visits['searches'])) {
94         foreach ($this->visits['searches'] as $key => $value) {
95           if ($value['keywords'] == $keywords) {
96             unset($this->visits['searches'][$key]);
97             break;
98           }
99         }
hpdl
228
100
hpdl
298
101         if (sizeof($this->visits['searches']) > (MAX_RECENTLY_VISITED_SEARCHES * 2)) {
102           array_pop($this->visits['searches']);
103         }
104       } else {
105         $this->visits['searches'] = array();
106       }
hpdl
228
107
hpdl
298
108       array_unshift($this->visits['searches'], array('keywords' => $keywords,
109                                                      'results' => $osC_Search->getNumberOfResults()
110                                                     ));
hpdl
228
111     }
112
hpdl
298
113     function hasHistory() {
114       if ($this->hasProducts() || $this->hasCategories() || $this->hasSearches()) {
115         return true;
116       }
hpdl
228
117
hpdl
298
118       return false;
119     }
hpdl
228
120
hpdl
298
121     function hasProducts() {
122       if (isset($this->visits['products']) && (empty($this->visits['products']) === false)) {
123         return true;
hpdl
228
124       }
125
hpdl
298
126       return false;
hpdl
228
127     }
128
hpdl
298
129     function getProducts() {
130       global $osC_Database, $osC_Services, $osC_Currencies, $osC_Specials;
hpdl
297
131
hpdl
298
132       $history = array();
hpdl
297
133
hpdl
298
134       if (isset($this->visits['products']) && (empty($this->visits['products']) === false)) {
135         $counter = 0;
hpdl
297
136
hpdl
298
137         foreach ($this->visits['products'] as $k => $v) {
138           $counter++;
hpdl
297
139
hpdl
298
140           $cpath = tep_get_product_path($this->visits['products'][$k]['id']);
141           $parts = explode("_", $cpath);
142           $cat_id =  $parts[sizeof($parts)-1];
hpdl
297
143
hpdl
298
144           $Qcategory = $osC_Database->query('select categories_name from :table_categories_description where categories_id = :categories_id and  language_id = :language_id');
145           $Qcategory->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION);
146           $Qcategory->bindInt(':categories_id', $cat_id);
147           $Qcategory->bindInt(':language_id', $_SESSION['languages_id']);
148           $Qcategory->execute();
hpdl
297
149
hpdl
298
150           $products_name = tep_get_products_name($this->visits['products'][$k]['id']);
hpdl
297
151
hpdl
298
152           if ( (SERVICE_RECENTLY_VISITED_SHOW_IMAGE == 'True') or (SERVICE_RECENTLY_VISITED_SHOW_PRICE == 'True') ) {
153             $Qproduct = $osC_Database->query('select products_price, products_tax_class_id, products_image from :table_products where products_status = 1 and products_id = :products_id');
154             $Qproduct->bindTable(':table_products', TABLE_PRODUCTS);
155             $Qproduct->bindInt(':products_id', $this->visits['products'][$k]['id']);
156             $Qproduct->execute();
hpdl
297
157
hpdl
298
158             if (SERVICE_RECENTLY_VISITED_SHOW_PRICE == 'True') {
159               if ( ($osC_Services->isStarted('specials')) && ($new_price = $osC_Specials->getPrice($this->visits['products'][$k]['id'])) ) {
160                 $products_price = '<s>' . $osC_Currencies->displayPrice($Qproduct->value('products_price'), $Qproduct->valueInt('products_tax_class_id')) . '</s> <span class="productSpecialPrice">' . $osC_Currencies->displayPrice($new_price, $Qproduct->valueInt('products_tax_class_id')) . '</span>';
161               } else {
162                 $products_price = $osC_Currencies->displayPrice($Qproduct->value('products_price'), $Qproduct->valueInt('products_tax_class_id'));
163               }
164             }
165           }
166
167           $history[] = array('name' => $products_name,
168                              'page' => ($this->visits['products'][$k]['page_name']) ? $this->visits['products'][$k]['page_name'] : FILENAME_DEFAULT,
169                              'id' => $this->visits['products'][$k]['id'],
170                              'get_params' => $this->visits['products'][$k]['get_params'],
171                              'price' => (SERVICE_RECENTLY_VISITED_SHOW_PRICE == 'True') ? $products_price : '',
172                              'image' => (SERVICE_RECENTLY_VISITED_SHOW_IMAGE == 'True') ? $Qproduct->value('products_image') : '',
173                              'category_name' =>  $Qcategory->value('categories_name'),
174                              'category_path' => $cpath
hpdl
297
175                             );
176
hpdl
298
177           if ($counter == MAX_RECENTLY_VISITED_PRODUCTS) {
178             break;
179           }
180         }
181       }
hpdl
297
182
hpdl
298
183       return $history;
184     }
hpdl
297
185
hpdl
298
186     function hasCategories() {
187       if (isset($this->visits['categories']) && (empty($this->visits['categories']) === false)) {
188         return true;
189       }
hpdl
297
190
hpdl
298
191       return false;
192     }
hpdl
297
193
hpdl
298
194     function getCategories() {
195       global $osC_Database;
hpdl
297
196
hpdl
298
197       $history = array();
hpdl
297
198
hpdl
298
199       if (isset($this->visits['categories']) && (empty($this->visits['categories']) === false)) {
200         $osC_CategoryTree = new osC_CategoryTree();
hpdl
297
201
hpdl
298
202         $counter = 0;
hpdl
297
203
hpdl
298
204         foreach ($this->visits['categories'] as $k => $v) {
205           $counter++;
hpdl
297
206
hpdl
298
207           $cpath = $osC_CategoryTree->buildBreadcrumb($this->visits['categories'][$k]['id']);
208           $parts = explode("_", $cpath);
hpdl
297
209
hpdl
298
210           if (sizeof($parts) > 1) {
211             $Qpcategory = $osC_Database->query('select categories_name, categories_id from :table_categories_description where categories_id = :categories_id and  language_id = :language_id');
212             $Qpcategory->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION);
213             $Qpcategory->bindInt(':categories_id', $parts[0]);
214             $Qpcategory->bindInt(':language_id', $_SESSION['languages_id']);
215             $Qpcategory->execute();
hpdl
297
216
hpdl
298
217             $Qcategory = $osC_Database->query('select categories_name from :table_categories_description where categories_id = :categories_id and  language_id = :language_id');
218             $Qcategory->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION);
219             $Qcategory->bindInt(':categories_id', $parts[sizeof($parts)-1]);
220             $Qcategory->bindInt(':language_id', $_SESSION['languages_id']);
221             $Qcategory->execute();
222           } else {
223             $Qpcategory = false;
hpdl
297
224
hpdl
298
225             $Qcategory = $osC_Database->query('select categories_name from :table_categories_description where categories_id = :categories_id and  language_id = :language_id');
226             $Qcategory->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION);
227             $Qcategory->bindInt(':categories_id', $parts[0]);
228             $Qcategory->bindInt(':language_id', $_SESSION['languages_id']);
229             $Qcategory->execute();
230           }
hpdl
297
231
hpdl
298
232           $history[]  = array('parents_name' => ($Qpcategory) ? $Qpcategory->value('categories_name') : '',
233                               'parents_id' => ($Qpcategory) ? $Qpcategory->value('categories_id') : '',
234                               'category_name' => $Qcategory->value('categories_name'),
235                               'category_id' => $cpath
236                              );
hpdl
297
237
hpdl
298
238           if ($counter == MAX_RECENTLY_VISITED_CATEGORIES) {
239             break;
240           }
241         }
242       }
hpdl
297
243
hpdl
298
244       return $history;
245     }
hpdl
297
246
hpdl
298
247     function hasSearches() {
248       if (isset($this->visits['searches']) && (empty($this->visits['searches']) === false)) {
249         return true;
250       }
hpdl
297
251
hpdl
298
252       return false;
253     }
hpdl
297
254
hpdl
298
255     function getSearches() {
256       $history = array();
hpdl
297
257
hpdl
298
258       if (isset($this->visits['searches']) && (empty($this->visits['searches']) === false)) {
259         $counter = 0;
260
261         foreach ($this->visits['searches'] as $k => $v) {
262           $counter++;
263
264           $history[]  = array('keywords' => $this->visits['searches'][$k]['keywords'],
265                               'results' => $this->visits['searches'][$k]['results']
266                              );
267
268           if ($counter == MAX_RECENTLY_VISITED_SEARCHES) {
269             break;
270           }
271         }
272       }
273
274       return $history;
275     }
276   }
hpdl
297
277 ?>