  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
3 | | - | $Id: template.php 333 2005-12-07 03:15:13Z hpdl $ |
| |
| 3 | + | $Id: template.php 351 2005-12-19 11:46:41Z hpdl $ |
|
4 | 4 | | |
| |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
|
|
 |
… |
|
23 | 23 | | * @access private |
| |
24 | 24 | | */ |
| |
25 | 25 | | |
  |
26 | | - | var $_template = 'default'; |
| |
| 26 | + | var $_template; |
|
27 | 27 | | |
| |
28 | 28 | | /** |
  |
| 29 | + | * Holds the template ID value |
| |
| 30 | + | * |
| |
| 31 | + | * @var int |
| |
| 32 | + | * @access private |
| |
| 33 | + | */ |
| |
| 34 | + | |
| |
| 35 | + | var $_template_id; |
| |
| 36 | + | |
| |
| 37 | + | /** |
|
29 | 38 | | * Holds the title of the page module |
| |
30 | 39 | | * |
| |
31 | 40 | | * @var string |
| |
|
|
 |
… |
|
144 | 153 | | } |
| |
145 | 154 | | |
| |
146 | 155 | | /** |
  |
| 156 | + | * Returns the template ID |
| |
| 157 | + | * |
| |
| 158 | + | * @access public |
| |
| 159 | + | * @return int |
| |
| 160 | + | */ |
| |
| 161 | + | |
| |
| 162 | + | function getID() { |
| |
| 163 | + | if (isset($this->_template) === false) { |
| |
| 164 | + | $this->setTemplate(); |
| |
| 165 | + | } |
| |
| 166 | + | |
| |
| 167 | + | return $this->_template_id; |
| |
| 168 | + | } |
| |
| 169 | + | |
| |
| 170 | + | /** |
|
147 | 171 | | * Returns the template name |
| |
148 | 172 | | * |
| |
149 | 173 | | * @access public |
| |
150 | 174 | | * @return string |
| |
151 | 175 | | */ |
| |
152 | 176 | | |
| |
153 | 177 | | function getTemplate() { |
  |
| 178 | + | if (isset($this->_template) === false) { |
| |
| 179 | + | $this->setTemplate(); |
| |
| 180 | + | } |
| |
| 181 | + | |
|
154 | 182 | | return $this->_template; |
| |
155 | 183 | | } |
| |
156 | 184 | | |
| |
|
|
 |
… |
|
311 | 339 | | } |
| |
312 | 340 | | |
| |
313 | 341 | | /** |
  |
314 | | - | * Sets the name of the template to use |
| |
| 342 | + | * Sets the template to use |
|
315 | 343 | | * |
  |
316 | | - | * @param string $template The name of the template to set |
|
317 | 344 | | * @access public |
| |
318 | 345 | | */ |
| |
319 | 346 | | |
  |
320 | | - | function setTemplate($template) { |
| |
321 | | - | $this->_template = $template; |
| |
| 347 | + | function setTemplate() { |
| |
| 348 | + | global $osC_Database; |
| |
| 349 | + | |
| |
| 350 | + | if ( (isset($_SESSION['template']) === false) || (isset($_GET['template']) && !empty($_GET['template'])) ) { |
| |
| 351 | + | $Qtemplates = $osC_Database->query('select id, code from :table_templates'); |
| |
| 352 | + | $Qtemplates->bindTable(':table_templates', TABLE_TEMPLATES); |
| |
| 353 | + | $Qtemplates->setCache('templates'); |
| |
| 354 | + | $Qtemplates->execute(); |
| |
| 355 | + | |
| |
| 356 | + | $template = (isset($_GET['template']) && !empty($_GET['template'])) ? $_GET['template'] : DEFAULT_TEMPLATE; |
| |
| 357 | + | |
| |
| 358 | + | $data = array(); |
| |
| 359 | + | $data_default = array(); |
| |
| 360 | + | |
| |
| 361 | + | while ($Qtemplates->next()) { |
| |
| 362 | + | if ($Qtemplates->value('code') == DEFAULT_TEMPLATE) { |
| |
| 363 | + | $data_default = array('id' => $Qtemplates->valueInt('id'), 'code' => $Qtemplates->value('code')); |
| |
| 364 | + | } elseif ($Qtemplates->value('code') == $template) { |
| |
| 365 | + | $data = array('id' => $Qtemplates->valueInt('id'), 'code' => $Qtemplates->value('code')); |
| |
| 366 | + | } |
| |
| 367 | + | } |
| |
| 368 | + | |
| |
| 369 | + | $Qtemplates->freeResult(); |
| |
| 370 | + | |
| |
| 371 | + | if (empty($data)) { |
| |
| 372 | + | $data =& $data_default; |
| |
| 373 | + | } |
| |
| 374 | + | |
| |
| 375 | + | $_SESSION['template'] =& $data; |
| |
| 376 | + | } |
| |
| 377 | + | |
| |
| 378 | + | $this->_template_id =& $_SESSION['template']['id']; |
| |
| 379 | + | $this->_template =& $_SESSION['template']['code']; |
  |
322 | 380 | | } |
| |
323 | 381 | | |
| |
324 | 382 | | /** |