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