Quick Search:

View

Revision:

Diff

Diff from 437 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/includes/classes/order_total.php

Annotated File View

hpdl
1
1 <?php
2 /*
hpdl
153
3   $Id: order_total.php 437 2006-02-16 10:41:13Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
404
8   Copyright (c) 2006 osCommerce
hpdl
1
9
10   Released under the GNU General Public License
11 */
12
hpdl
428
13   class osC_OrderTotal {
hpdl
434
14     var $_modules = array(),
15         $_group = 'order_total';
hpdl
1
16
17 // class constructor
hpdl
428
18     function osC_OrderTotal() {
19       global $osC_Database, $osC_Language;
hpdl
377
20
hpdl
435
21       if (isset($_SESSION['osC_OrderTotal_data']) === false) {
22         $_SESSION['osC_OrderTotal_data'] = array('cartID' => null,
23                                                  'output' => array());
24       }
25
26       $this->_data =& $_SESSION['osC_OrderTotal_data'];
27
hpdl
428
28       $Qmodules = $osC_Database->query('select code from :table_templates_boxes where modules_group = "order_total"');
29       $Qmodules->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
30       $Qmodules->setCache('modules-order_total');
31       $Qmodules->execute();
hpdl
1
32
hpdl
428
33       while ($Qmodules->next()) {
hpdl
434
34         $this->_modules[] = $Qmodules->value('code');
hpdl
428
35       }
hpdl
404
36
hpdl
428
37       $Qmodules->freeResult();
hpdl
1
38
hpdl
428
39       $osC_Language->load('modules-order_total');
40
hpdl
434
41       foreach ($this->_modules as $module) {
hpdl
428
42         include('includes/modules/order_total/' . $module . '.' . substr(basename(__FILE__), (strrpos(basename(__FILE__), '.')+1)));
43
44         $module_class = 'osC_OrderTotal_' . $module;
45
46         $GLOBALS[$module_class] = new $module_class();
hpdl
1
47       }
hpdl
437
48
49       usort($this->_modules, array('osC_OrderTotal', '_usortModules'));
hpdl
1
50     }
51
hpdl
432
52 // class methods
53     function getCode() {
54       return $this->_code;
55     }
56
57     function getTitle() {
58       return $this->_title;
59     }
60
61     function getDescription() {
62       return $this->_description;
63     }
64
65     function getStatus() {
66       return $this->_status;
67     }
68
69     function getSortOrder() {
70       return $this->_sort_order;
71     }
72
hpdl
433
73     function getResult() {
hpdl
435
74       global $osC_ShoppingCart;
hpdl
1
75
hpdl
435
76       if ($this->_data['cartID'] != $osC_ShoppingCart->getCartID()) {
77         $this->_data['cartID'] = $osC_ShoppingCart->getCartID();
hpdl
428
78
hpdl
435
79         $this->_data['output'] = array();
hpdl
428
80
hpdl
435
81         foreach ($this->_modules as $module) {
82           $module = 'osC_OrderTotal_' . $module;
83
84           if ($GLOBALS[$module]->getStatus() === true) {
85             $GLOBALS[$module]->process();
86
87             foreach ($GLOBALS[$module]->output as $output) {
88               if (tep_not_null($output['title']) && tep_not_null($output['text'])) {
89                 $this->_data['output'][] = array('code' => $GLOBALS[$module]->getCode(),
90                                                  'title' => $output['title'],
91                                                  'text' => $output['text'],
92                                                  'value' => $output['value'],
93                                                  'sort_order' => $GLOBALS[$module]->getSortOrder());
94               }
hpdl
1
95             }
96           }
97         }
98       }
99
hpdl
435
100       return $this->_data['output'];
hpdl
1
101     }
102
hpdl
431
103     function hasActive() {
104       static $has_active;
105
106       if (isset($has_active) === false) {
107         $has_active = false;
108
hpdl
434
109         foreach ($this->_modules as $module) {
hpdl
432
110           if ($GLOBALS['osC_OrderTotal_' . $module]->getStatus() === true) {
hpdl
431
111             $has_active = true;
112             break;
113           }
114         }
115       }
116
117       return $has_active;
118     }
119
hpdl
428
120     function hasKeys() {
121       static $has_keys;
122
123       if (isset($has_keys) === false) {
124         $has_keys = (sizeof($this->getKeys()) > 0) ? true : false;
125       }
126
127       return $has_keys;
128     }
129
130     function install() {
131       global $osC_Database, $osC_Language;
132
133       $Qinstall = $osC_Database->query('insert into :table_templates_boxes (title, code, author_name, author_www, modules_group) values (:title, :code, :author_name, :author_www, :modules_group)');
134       $Qinstall->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
135       $Qinstall->bindValue(':title', $this->_title);
136       $Qinstall->bindValue(':code', $this->_code);
137       $Qinstall->bindValue(':author_name', $this->_author_name);
138       $Qinstall->bindValue(':author_www', $this->_author_www);
139       $Qinstall->bindValue(':modules_group', $this->_group);
140       $Qinstall->execute();
141
142       foreach ($osC_Language->getAll() as $key => $value) {
143         if (file_exists(dirname(__FILE__) . '/../languages/' . $key . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) {
144           foreach ($osC_Language->extractDefinitions($key . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) {
145             $Qcheck = $osC_Database->query('select id from :table_languages_definitions where definition_key = :definition_key and content_group = :content_group and languages_id = :languages_id limit 1');
146             $Qcheck->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
147             $Qcheck->bindValue(':definition_key', $def['key']);
148             $Qcheck->bindValue(':content_group', $def['group']);
149             $Qcheck->bindInt(':languages_id', $value['id']);
150             $Qcheck->execute();
151
152             if ($Qcheck->numberOfRows() === 1) {
153               $Qdef = $osC_Database->query('update :table_languages_definitions set definition_value = :definition_value where definition_key = :definition_key and content_group = :content_group and languages_id = :languages_id');
154             } else {
155               $Qdef = $osC_Database->query('insert into :table_languages_definitions (languages_id, content_group, definition_key, definition_value) values (:languages_id, :content_group, :definition_key, :definition_value)');
156             }
157             $Qdef->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
158             $Qdef->bindInt(':languages_id', $value['id']);
159             $Qdef->bindValue(':content_group', $def['group']);
160             $Qdef->bindValue(':definition_key', $def['key']);
161             $Qdef->bindValue(':definition_value', $def['value']);
162             $Qdef->execute();
163           }
164         }
165       }
166
167       osC_Cache::clear('languages');
168     }
169
170     function remove() {
171       global $osC_Database, $osC_Language;
172
173       $Qdel = $osC_Database->query('delete from :table_templates_boxes where code = :code and modules_group = :modules_group');
174       $Qdel->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
175       $Qdel->bindValue(':code', $this->_code);
176       $Qdel->bindValue(':modules_group', $this->_group);
177       $Qdel->execute();
178
179       if ($this->hasKeys()) {
180         $Qdel = $osC_Database->query('delete from :table_configuration where configuration_key in (":configuration_key")');
181         $Qdel->bindTable(':table_configuration', TABLE_CONFIGURATION);
182         $Qdel->bindRaw(':configuration_key', implode('", "', $this->getKeys()));
183         $Qdel->execute();
184       }
185
186       if (file_exists(dirname(__FILE__) . '/../languages/' . $osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) {
187         foreach ($osC_Language->extractDefinitions($osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) {
188           $Qdel = $osC_Database->query('delete from :table_languages_definitions where definition_key = :definition_key and content_group = :content_group');
189           $Qdel->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
190           $Qdel->bindValue(':definition_key', $def['key']);
191           $Qdel->bindValue(':content_group', $def['group']);
192           $Qdel->execute();
193         }
194
195         osC_Cache::clear('languages');
196       }
197     }
198
199     function _usortModules($a, $b) {
hpdl
432
200       if ($GLOBALS['osC_OrderTotal_' . $a]->getSortOrder() == $GLOBALS['osC_OrderTotal_' . $b]->getSortOrder()) {
201         return strnatcasecmp($GLOBALS['osC_OrderTotal_' . $a]->getTitle(), $GLOBALS['osC_OrderTotal_' . $a]->getTitle());
hpdl
428
202       }
203
hpdl
432
204       return ($GLOBALS['osC_OrderTotal_' . $a]->getSortOrder() < $GLOBALS['osC_OrderTotal_' . $b]->getSortOrder()) ? -1 : 1;
hpdl
428
205     }
hpdl
1
206   }
hpdl
428
207 ?>