Quick Search:

View

Revision:

Diff

Diff from 297 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
297
27       global $osC_Product;
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') {
34         $this->setCategory();
35       }
36
37       if (SERVICE_RECENTLY_VISITED_SHOW_SEARCHES == 'True') {
38         $this->setSearchQuery();
39       }
hpdl
290
40     }
41
42     function getContentModule() {
43       return 'recently_visited.php';
44     }
45
hpdl
228
46    function setProduct($id) {
47      foreach ($this->visits['products'] as $key => $value) {
48       if ($this->visits['products'][$key]['products_id'] == $id) {
49        unset($this->visits['products'][$key]);
50        break;
51       }
52      }
53
54      if (sizeof($this->visits['products']) >= MAX_RECENTLY_VISITED_PRODUCTS+3) {
55       $keys = array_keys($this->visits['products']);
56       unset($this->visits['products'][$keys[0]]);
hpdl
290
57       $this->debug[] = 'unsetted ' . $keys[0];
hpdl
228
58      }
59
60      if (SERVICE_RECENTLY_VISITED_ORIGINAL_PAGE == 'True') {
61       $this->visits['products'][] = array('products_id' => $id,
62                                           'page_name' => basename($_SERVER['PHP_SELF']),
63                                           'get_params' => tep_array_to_string($_GET, array($osC_Session->name, 'action', 'products_id'))
64                                          );
65      } else {
66       $this->visits['products'][] = array('products_id' => $id);
67      }
68    }
69
70    function setCategory() {
71     if (!empty($_GET['cPath'])) {
72
73      $cpath = $_GET['cPath'];
74
75      foreach ($this->visits['categories'] as $key => $value) {
76       if ($this->visits['categories'][$key]['cpath'] == $cpath) {
77        unset($this->visits['categories'][$key]);
78        break;
79       }
80      }
81
82      if (sizeof($this->visits['categories']) >= MAX_RECENTLY_VISITED_CATEGORIES+3) {
83       $keys = array_keys($this->visits['categories']);
84       unset($this->visits['categories'][$keys[0]]);
85      }
86
87       $this->visits['categories'][] = array('cpath' => $cpath);
88
89     }
90    }
91
92    function setSearchQuery() {
93     if (!empty($_GET['keywords'])) {
94
95      $keywords = $_GET['keywords'];
96
97      foreach ($this->visits['searches'] as $key => $value) {
98       if ($this->visits['searches'][$key]['keywords'] == $keywords) {
99        unset($this->visits['searches'][$key]);
100        break;
101       }
102      }
103
104      if (sizeof($this->visits['searches']) >= MAX_RECENTLY_VISITED_SEARCHES+3) {
105       $keys = array_keys($this->visits['searches']);
106       unset($this->visits['searches'][$keys[0]]);
107      }
108      $this->visits['searches'][] = array('keywords' => $keywords,
109                                          'get_params' => tep_array_to_string($_GET, array($osC_Session->name, 'keywords')));
110     }
111    }
112
hpdl
297
113    function hasCategories() {
114      if (isset($this->visits['categories']) && (empty($this->visits['categories']) === false)) {
115        return true;
116      }
117
118      return false;
119    }
120
121    function getCategories() {
122      global $osC_Database;
123
124      $history = array();
125
126      if (isset($this->visits['categories']) && (empty($this->visits['categories']) === false)) {
127        foreach ($this->visits['categories'] as $k => $v) {
128          $parts = explode("_", $this->visits['categories'][$k]['cpath']);
129
130          if (sizeof($parts) > 1) {
131            $Qpcategory = $osC_Database->query('select categories_name, categories_id from :table_categories_description where categories_id = :categories_id and  language_id = :language_id');
132            $Qpcategory->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION);
133            $Qpcategory->bindInt(':categories_id', $parts[0]);
134            $Qpcategory->bindInt(':language_id', $_SESSION['languages_id']);
135            $Qpcategory->execute();
136
137            $Qcategory = $osC_Database->query('select categories_name from :table_categories_description where categories_id = :categories_id and  language_id = :language_id');
138            $Qcategory->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION);
139            $Qcategory->bindInt(':categories_id', $parts[sizeof($parts)-1]);
140            $Qcategory->bindInt(':language_id', $_SESSION['languages_id']);
141            $Qcategory->execute();
142          } else {
143            $Qpcategory = false;
144
145            $Qcategory = $osC_Database->query('select categories_name from :table_categories_description where categories_id = :categories_id and  language_id = :language_id');
146            $Qcategory->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION);
147            $Qcategory->bindInt(':categories_id', $parts[0]);
148            $Qcategory->bindInt(':language_id', $_SESSION['languages_id']);
149            $Qcategory->execute();
150          }
151
152          $history[]  = array('parents_name' => ($Qpcategory) ? $Qpcategory->value('categories_name') : '',
153                              'parents_id' => ($Qpcategory) ? $Qpcategory->value('categories_id') : '',
154                              'category_name' => $Qcategory->value('categories_name'),
155                              'category_id' => $this->visits['categories'][$k]['cpath']
156                             );
157        }
158
159        if (empty($history) === false) {
160          krsort($history);
161          $history = array_slice($history, 0, MAX_RECENTLY_VISITED_CATEGORIES);
162        }
163      }
164
165      return $history;
166    }
167
168    function hasProducts() {
169      if (isset($this->visits['products']) && (empty($this->visits['products']) === false)) {
170        return true;
171      }
172
173      return false;
174    }
175
176    function getProducts() {
177      global $osC_Database, $osC_Services, $osC_Currencies, $osC_Specials;
178
179      $history = array();
180
181      if (isset($this->visits['products']) && (empty($this->visits['products']) === false)) {
182        foreach ($this->visits['products'] as $k => $v) {
183          $cpath = tep_get_product_path($this->visits['products'][$k]['products_id']);
184          $parts = explode("_", $cpath);
185          $cat_id =  $parts[sizeof($parts)-1];
186
187          $Qcategory = $osC_Database->query('select categories_name from :table_categories_description where categories_id = :categories_id and  language_id = :language_id');
188          $Qcategory->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION);
189          $Qcategory->bindInt(':categories_id', $cat_id);
190          $Qcategory->bindInt(':language_id', $_SESSION['languages_id']);
191          $Qcategory->execute();
192
193          $products_name = tep_get_products_name($this->visits['products'][$k]['products_id']);
194
195          if ( (SERVICE_RECENTLY_VISITED_SHOW_IMAGE == 'True') or (SERVICE_RECENTLY_VISITED_SHOW_PRICE == 'True') ) {
196            $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');
197            $Qproduct->bindTable(':table_products', TABLE_PRODUCTS);
198            $Qproduct->bindInt(':products_id', $this->visits['products'][$k]['products_id']);
199            $Qproduct->execute();
200
201            if (SERVICE_RECENTLY_VISITED_SHOW_PRICE == 'True') {
202              if ( ($osC_Services->isStarted('specials')) && ($new_price = $osC_Specials->getPrice($this->visits['products'][$k]['products_id'])) ) {
203                $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>';
204              } else {
205                $products_price = $osC_Currencies->displayPrice($Qproduct->value('products_price'), $Qproduct->valueInt('products_tax_class_id'));
206              }
207            }
208          }
209
210          $history[] = array('name' => $products_name,
211                             'page' => ($this->visits['products'][$k]['page_name']) ? $this->visits['products'][$k]['page_name'] : FILENAME_DEFAULT,
212                             'id' => $this->visits['products'][$k]['products_id'],
213                             'get_params' => $this->visits['products'][$k]['get_params'],
214                             'price' => (SERVICE_RECENTLY_VISITED_SHOW_PRICE == 'True') ? $products_price : '',
215                             'image' => (SERVICE_RECENTLY_VISITED_SHOW_IMAGE == 'True') ? $Qproduct->value('products_image') : '',
216                             'category_name' =>  $Qcategory->value('categories_name'),
217                             'category_path' => $cpath
218                            );
219        }
220
221        if (empty($history) === false) {
222          krsort($history);
223          $history = array_slice($history, 0, MAX_RECENTLY_VISITED_PRODUCTS);
224        }
225      }
226
227      return $history;
228    }
229
230    function hasSearches() {
231      if (isset($this->visits['searches']) && (empty($this->visits['searches']) === false)) {
232        return true;
233      }
234
235      return false;
236    }
237
238    function getSearches() {
239      $history = array();
240
241      if (isset($this->visits['searches']) && (empty($this->visits['searches']) === false)) {
242        foreach ($this->visits['searches'] as $k => $v) {
243          $history[]  = array('keywords' => $this->visits['searches'][$k]['keywords'],                                             'parents_id' => ($Qpcategory) ? $Qpcategory->value('categories_id') : '',
244                              'get_params' => $this->visits['searches'][$k]['get_params']
245                             );
246        }
247
248        if (empty($history) === false) {
249          krsort($history);
250          $history = array_slice($history, 0, MAX_RECENTLY_VISITED_SEARCHES);
251        }
252      }
253
254      return $history;
255    }
hpdl
228
256  }
hpdl
297
257 ?>