function amSessionRegister($strSessionVar, $value = '') { if (!amSessionIsRegistered($strSessionVar)) { vam_session_register($strSessionVar); $GLOBALS[$strSessionVar] = $value; } }
/** * Checks the session var * @static checkAuthorisation() * @access public * @author Sam West aka Nimmit - osc@kangaroopartners.com * @param $sessionVar string session variable name * @return void */ function checkAuthorisation($sessionVar) { if (!amSessionIsRegistered($sessionVar)) { exit("Session not registered - You cant access this page directly"); } if ($GLOBALS[$sessionVar] != stopDirectAccess::makeSessionId()) { exit("Session ids don't match - You cant access this page directly"); } }
function installMoreProductWeight() { if ($this->getValue('AM_USE_MPW') && !amSessionIsRegistered($this->getValue('AM_SESSION_MORE_PRODUCT_WEIGHT_INSTALL_CHECKED'))) { // check that the fields are in the weights table $weightFields = amDB::query("SHOW COLUMNS FROM " . TABLE_PRODUCTS_ATTRIBUTES); while ($field = amDB::fetchArray($weightFields)) { $pa_fields[] = $field['Field']; } $weightFields = amDB::query("SHOW COLUMNS FROM " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES); while ($field = amDB::fetchArray($weightFields)) { $opa_Fields[] = $field['Field']; } $weightFields = amDB::query("SHOW COLUMNS FROM " . $this->getValue('AM_TABLE_ATTRIBUTES_TO_TEMPLATES')); while ($field = amDB::fetchArray($weightFields)) { $tmpl_Fields[] = $field['Field']; } $p_Type = ''; $weightFields = amDB::query("SHOW COLUMNS FROM " . TABLE_PRODUCTS); while ($field = amDB::fetchArray($weightFields)) { if ($field['Field'] == 'products_weight') { $p_Type = $field['Type']; break; } } // if not add them if (!in_array('weight_prefix', $pa_fields)) { amDB::query("ALTER TABLE " . TABLE_PRODUCTS_ATTRIBUTES . " ADD COLUMN `weight_prefix` CHAR (1) NOT NULL"); } if (!in_array('attributes_stock', $pa_fields)) { amDB::query("ALTER TABLE " . TABLE_PRODUCTS_ATTRIBUTES . " ADD COLUMN `attributes_stock` int(5) DEFAULT 0"); } if (!in_array('options_values_weight', $pa_fields)) { amDB::query("ALTER TABLE " . TABLE_PRODUCTS_ATTRIBUTES . " ADD COLUMN `options_values_weight` DECIMAL (6,3) DEFAULT '0.000' NOT NULL"); } if (!in_array('weight_prefix', $opa_Fields)) { amDB::query("ALTER TABLE " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " ADD COLUMN `weight_prefix` CHAR (1) NOT NULL"); } if (!in_array('options_values_weight', $opa_Fields)) { amDB::query("ALTER TABLE " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " ADD COLUMN `options_values_weight` DECIMAL (6,3) DEFAULT '0.000' NOT NULL"); } if (!in_array('attributes_stock', $tmpl_Fields) && $this->getValue('AM_USE_SORT_ORDER')) { amDB::query("ALTER TABLE " . $this->getValue('AM_TABLE_ATTRIBUTES_TO_TEMPLATES') . " ADD COLUMN `attributes_stock` int(5) DEFAULT 0"); } if (!in_array('weight_prefix', $tmpl_Fields) && $this->getValue('AM_USE_SORT_ORDER')) { amDB::query("ALTER TABLE " . $this->getValue('AM_TABLE_ATTRIBUTES_TO_TEMPLATES') . " ADD COLUMN `weight_prefix` CHAR (1) NOT NULL default '+'"); } if (!in_array('options_values_weight', $tmpl_Fields) && $this->getValue('AM_USE_SORT_ORDER')) { amDB::query("ALTER TABLE " . $this->getValue('AM_TABLE_ATTRIBUTES_TO_TEMPLATES') . " ADD COLUMN `options_values_weight` DECIMAL (6,3) DEFAULT '0.000' NOT NULL"); } // change field size of product weight if ($p_Type != '' && $p_Type != strtoupper('DECIMAL(6,3)')) { amDB::query("ALTER TABLE " . TABLE_PRODUCTS . " CHANGE `products_weight` `products_weight` DECIMAL(6,3) DEFAULT '0.000' NOT NULL"); } // register the checked session so that this check is only done once per session amSessionRegister($this->getValue('AM_SESSION_MORE_PRODUCT_WEIGHT_INSTALL_CHECKED'), true); } }
function installSortOrder() { if ($this->getValue('AM_USE_SORT_ORDER') && !amSessionIsRegistered($this->getValue('AM_SESSION_SORT_ORDER_INSTALL_CHECKED'))) { // register the checked session so that this check is only done once per session amSessionRegister($this->getValue('AM_SESSION_SORT_ORDER_INSTALL_CHECKED'), true); // check that the fields are in the attributes table $attributeFields = amDB::query("SHOW COLUMNS FROM " . TABLE_PRODUCTS_ATTRIBUTES); while ($field = amDB::fetchArray($attributeFields)) { $fields[] = $field['Field']; } $oInstalled = in_array($this->getValue('AM_FIELD_OPTION_SORT_ORDER'), $fields); $ovInstalled = in_array($this->getValue('AM_FIELD_OPTION_VALUE_SORT_ORDER'), $fields); // if not add them if (!$oInstalled) { amDB::query("ALTER TABLE " . TABLE_PRODUCTS_ATTRIBUTES . " ADD COLUMN " . $this->getValue('AM_FIELD_OPTION_SORT_ORDER') . " INT UNSIGNED NOT NULL DEFAULT '0'"); } if (!$ovInstalled) { amDB::query("ALTER TABLE " . TABLE_PRODUCTS_ATTRIBUTES . " ADD COLUMN " . $this->getValue('AM_FIELD_OPTION_VALUE_SORT_ORDER') . " INT UNSIGNED NOT NULL DEFAULT '0'"); } // now reset all of the sort orders if (!$oInstalled || !$ovInstalled) { $allAttributes = amDB::getAll("select * from " . TABLE_PRODUCTS_ATTRIBUTES . " order by products_id, options_id, options_values_id"); $productId = $optionId = null; $oCount = $ovCount = 1; $updateValues = array(); if (is_array($allAttributes)) { foreach ($allAttributes as $attrib) { if ($productId != $attrib['products_id']) { $oCount = $ovCount = 0; } if ($optionId != $attrib['options_id']) { $oCount++; $ovCount = 0; } /** for dev only $updateValues[$attrib['products_attributes_id']]['prdoucts_id'] = $attrib['products_id']; $updateValues[$attrib['products_attributes_id']]['options_id'] = $attrib['options_id']; $updateValues[$attrib['products_attributes_id']]['options_values_id'] = $attrib['options_values_id']; **/ $updateValues[$attrib['products_attributes_id']]['option_sort'] = $oCount; $updateValues[$attrib['products_attributes_id']]['option_value_sort'] = ++$ovCount; $productId = $attrib['products_id']; $optionId = $attrib['options_id']; } foreach ($updateValues as $attributeId => $sorts) { 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"); } } //echo '<pre style="text-align:left">'.print_r($updateValues,true); } } }