[ Index ] |
PHP Cross Reference of osCMax 2.0.4 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 $Id: attributeManagerConfig.class.php,v 1.0 21/02/06 Sam West$ 4 5 osCommerce, Open Source E-Commerce Solutions 6 http://www.oscommerce.com 7 8 Released under the GNU General Public License 9 10 Copyright © 2006 Kangaroo Partners 11 http://kangaroopartners.com 12 [email protected] 13 */ 14 15 require_once('attributeManager/classes/amDB.class.php'); 16 require_once('attributeManager/includes/attributeManagerSessionFunctions.inc.php'); 17 18 if(file_exists('attributeManager/languages/'.$_SESSION['language'].'/attributeManager.php')) 19 include_once('attributeManager/languages/'.$_SESSION['language'].'/attributeManager.php'); 20 else 21 include_once('attributeManager/languages/'.'english'.'/attributeManager.php'); 22 23 class attributeManagerConfig { 24 25 var $arrConfig = array(); 26 27 function attributeManagerConfig() { 28 29 30 /** 31 * Default admin interface language id 32 */ 33 $this->add('AM_DEFAULT_LANGUAGE_ID',$GLOBALS['languages_id']); 34 35 /** 36 * Default admin interface template order 37 */ 38 $this->add('AM_DEFAULT_TEMPLATE_ORDER','123'); 39 40 /** 41 * Dont update the database untill the untill the end of the product addition process 42 */ 43 $this->add('AM_ATOMIC_PRODUCT_UPDATES', false); 44 45 46 /** 47 * Use attribute templates? 48 * 49 */ 50 $this->add('AM_USE_TEMPLATES',true); 51 52 53 /** 54 * Template Table names 55 */ 56 $this->add('AM_TABLE_TEMPLATES','am_templates'); 57 $this->add('AM_TABLE_ATTRIBUTES_TO_TEMPLATES','am_attributes_to_templates'); 58 59 60 $this->add('AM_USE_SORT_ORDER' , false); 61 $this->add('AM_USE_QT_PRO' , false); // DO NOT USE STILL IN DEV 62 63 /** 64 * Sort order tables 65 */ 66 $this->add('AM_FIELD_OPTION_SORT_ORDER','products_options_sort_order'); // Sort column on Products_options table 67 $this->add('AM_FIELD_OPTION_VALUE_SORT_ORDER','products_options_sort_order'); // Sort column on product_attributes table 68 69 70 /** 71 * How do sort the drop down lists in the admin - purly asthetic 72 * options 73 * 1 = alpha 74 * 2 = default - by id 75 */ 76 $this->add('AM_DEFAULT_SORT_ORDER',1); 77 78 /** 79 * Password for the session var - doesn't matter what it is. Mix it up if you fee like it :) 80 */ 81 $this->add('AM_VALID_INCLUDE_PASSWORD','asdfjkasdadfadsff'); 82 83 /** 84 * Variable names - Shouldn't need editing unless there are conflicts 85 */ 86 $this->add('AM_SESSION_VAR_NAME','am_session_var'); // main var for atomic 87 $this->add('AM_SESSION_CURRENT_LANG_VAR_NAME','am_current_lang_session_var'); // current interface lang 88 $this->add('AM_SESSION_CURRENT_TEMPLATE_ORDER','am_current_template_order'); // current template order 89 $this->add('AM_SESSION_VALID_INCLUDE','am_valid_include'); // variable set on categories.php to make sure attributeManager.php has been included 90 $this->add('AM_SESSION_SORT_ORDER_INSTALL_CHECKED','am_sort_order_checked'); 91 $this->add('AM_SESSION_TEMPLATES_INSTALL_CHECKED','am_templates_checked'); 92 $this->add('AM_ACTION_GET_VARIABLE', 'amAction'); // attribute manager get variable name 93 $this->add('AM_PAGE_ACTION_NAME','pageAction'); // attribute manager parent page action e.g. new_product 94 95 /** 96 * Install templates if not already done so 97 */ 98 $this->installTemplates(); 99 100 /** 101 * Install the sort order tables if they dont already exist 102 */ 103 104 $this->installSortOrder(); 105 } 106 107 function load() { 108 if(0 !== count($this->arrConfig)) 109 foreach($this->arrConfig as $key => $value) 110 define($key, $value); 111 } 112 113 function getValue($key) { 114 if(array_key_exists($key, $this->arrConfig)) 115 return $this->arrConfig[$key]; 116 return false; 117 } 118 119 function add($key, $value) { 120 $this->arrConfig[$key] = $value; 121 } 122 123 function installTemplates() { 124 if($this->getValue('AM_USE_TEMPLATES') && !amSessionIsRegistered($this->getValue('AM_SESSION_SORT_ORDER_INSTALL_CHECKED')) ) { 125 126 amDB::query("CREATE TABLE IF NOT EXISTS ".$this->getValue('AM_TABLE_TEMPLATES')." ( 127 `template_id` INT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , 128 `template_name` VARCHAR( 255 ) NOT NULL 129 )" 130 ); 131 amDB::query("CREATE TABLE IF NOT EXISTS ".$this->getValue('AM_TABLE_ATTRIBUTES_TO_TEMPLATES')." ( 132 `template_id` INT( 5 ) UNSIGNED NOT NULL , 133 `options_id` INT( 5 ) UNSIGNED NOT NULL , 134 `option_values_id` INT( 5 ) UNSIGNED NOT NULL , 135 `price_prefix` char(1) default '+', 136 `options_values_price` decimal(15,4) default 0, 137 `products_options_sort_order` int default 0, 138 INDEX ( `template_id` ) 139 )" 140 ); 141 // Check if the user is updating from the older version 142 $install_price_prefix=true; 143 $install_options_values_price=true; 144 $install_products_options_sort_order=true; 145 146 // Fetch database Fields 147 $attributeFields = amDB::query("SHOW COLUMNS FROM ". $this->getValue(AM_TABLE_ATTRIBUTES_TO_TEMPLATES)); 148 while($field = amDB::fetchArray($attributeFields)) 149 $fields[] = $field['Field']; 150 151 if( !in_array('price_prefix',$fields) ){ 152 amDB::query("ALTER TABLE ".$this->getValue('AM_TABLE_ATTRIBUTES_TO_TEMPLATES')." ADD(`price_prefix` char(1) default '+')"); 153 } 154 if( !in_array('options_values_price',$fields) ){ 155 amDB::query("ALTER TABLE ".$this->getValue('AM_TABLE_ATTRIBUTES_TO_TEMPLATES')." ADD(`options_values_price` decimal(15,4) default 0)"); 156 } 157 if( !in_array('products_options_sort_order',$fields) ){ 158 amDB::query("ALTER TABLE ".$this->getValue('AM_TABLE_ATTRIBUTES_TO_TEMPLATES')." ADD(`products_options_sort_order` int default 0)"); 159 } 160 161 // register the checked session so that this check is only done once per session 162 amSessionRegister('AM_SESSION_TEMPLATES_INSTALL_CHECKED',true); 163 164 165 } 166 } 167 168 function installSortOrder() { 169 170 171 if($this->getValue('AM_USE_SORT_ORDER') && !amSessionIsRegistered($this->getValue('AM_SESSION_SORT_ORDER_INSTALL_CHECKED'))) { 172 173 174 // check that the fields are in the attributes table 175 $attributeFields = amDB::query("SHOW COLUMNS FROM ". TABLE_PRODUCTS_ATTRIBUTES); 176 while($field = amDB::fetchArray($attributeFields)) 177 $attrfields[] = $field['Field']; 178 179 $attributeFields = amDB::query("SHOW COLUMNS FROM ". TABLE_PRODUCTS_OPTIONS); 180 while($field = amDB::fetchArray($attributeFields)) 181 $optionsFields[] = $field['Field']; 182 183 $attributeFields = amDB::query("SHOW COLUMNS FROM ". $this->getValue('AM_TABLE_ATTRIBUTES_TO_TEMPLATES')); 184 while($field = amDB::fetchArray($attributeFields)) 185 $soptionsFields[] = $field['Field']; 186 187 188 $oInstalled = in_array($this->getValue('AM_FIELD_OPTION_SORT_ORDER'),$optionsFields); 189 $ovInstalled = in_array($this->getValue('AM_FIELD_OPTION_VALUE_SORT_ORDER'),$attrfields); 190 $soInstalled = in_array($this->getValue('AM_FIELD_OPTION_SORT_ORDER'),$soptionsFields); 191 192 // if not add them 193 if( ! $oInstalled ) 194 amDB::query("ALTER TABLE ".TABLE_PRODUCTS_OPTIONS." ADD COLUMN ".$this->getValue('AM_FIELD_OPTION_SORT_ORDER')." INT UNSIGNED NOT NULL DEFAULT '0'"); 195 196 if(!$ovInstalled) 197 amDB::query("ALTER TABLE ".TABLE_PRODUCTS_ATTRIBUTES." ADD COLUMN ".$this->getValue('AM_FIELD_OPTION_VALUE_SORT_ORDER')." INT UNSIGNED NOT NULL DEFAULT '0'"); 198 199 if(!$soInstalled && $this->getValue('AM_USE_SORT_ORDER')) 200 amDB::query("ALTER TABLE ".$this->getValue('AM_TABLE_ATTRIBUTES_TO_TEMPLATES')." ADD COLUMN ".$this->getValue('AM_FIELD_OPTION_SORT_ORDER')." INT UNSIGNED NOT NULL DEFAULT '0'"); 201 202 // now reset all of the sort orders 203 if(!$oInstalled || !$ovInstalled) { 204 $allAttributes = amDB::getAll("select * from ".TABLE_PRODUCTS_ATTRIBUTES." order by products_id, options_id, options_values_id"); 205 206 $productId = $optionId = null; 207 $oCount = $ovCount = 1; 208 209 $updateValues = array(); 210 if(is_array($allAttributes)) { 211 foreach($allAttributes as $attrib) { 212 if($productId != $attrib['products_id']) { 213 $oCount = $ovCount = 0; 214 215 } 216 if($optionId != $attrib['options_id']) { 217 $oCount++; 218 $ovCount = 0; 219 } 220 221 /** for dev only 222 $updateValues[$attrib['products_attributes_id']]['prdoucts_id'] = $attrib['products_id']; 223 $updateValues[$attrib['products_attributes_id']]['options_id'] = $attrib['options_id']; 224 $updateValues[$attrib['products_attributes_id']]['options_values_id'] = $attrib['options_values_id']; 225 **/ 226 227 $updateValues[$attrib['products_attributes_id']]['option_sort'] = $oCount; 228 $updateValues[$attrib['products_attributes_id']]['option_value_sort'] = ++$ovCount; 229 230 231 $productId = $attrib['products_id']; 232 $optionId = $attrib['options_id']; 233 } 234 235 foreach($updateValues as $attributeId => $sorts) 236 amDB::query("update ".TABLE_PRODUCTS_ATTRIBUTES." set ".$this->getValue('AM_FIELD_OPTION_SORT_ORDER')." = '{$sorts['option_sort']}', ".$this->getValue('AM_FIELD_OPTION_VALUE_SORT_ORDER')." = '{$sorts['option_value_sort']}' where products_attributes_id = '$attributeId' limit 1"); 237 238 } 239 //echo '<pre style="text-align:left">'.print_r($updateValues,true); 240 } 241 242 // register the checked session so that this check is only done once per session 243 amSessionRegister($this->getValue('AM_SESSION_SORT_ORDER_INSTALL_CHECKED'), true); 244 245 } 246 247 } 248 } 249 250 $config = new attributeManagerConfig(); 251 $config->load(); 252 253 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Jan 1 13:43:16 2010 | Cross-referenced by PHPXref 0.7 |