Index: branches/5.3.x/units/orders/orders_item.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/orders/orders_item.php (.../orders_item.php) (revision 15492) +++ branches/5.3.x/units/orders/orders_item.php (.../orders_item.php) (revision 15695) @@ -1,6 +1,6 @@ Application->getUnitOption('pt', 'TableName'); + $pt_table = $this->Application->getUnitConfig('pt')->getTableName(); $sql = 'SELECT GatewayId FROM %s @@ -71,8 +71,8 @@ $ret = $this->Conn->GetRow(sprintf($sql, TABLE_PREFIX . 'Gateways', $gw_id)); // get Gateway parameters based on payment type - $gwf_table = $this->Application->getUnitOption('gwf', 'TableName'); - $gwfv_table = $this->Application->getUnitOption('gwfv', 'TableName'); + $gwf_table = $this->Application->getUnitConfig('gwf')->getTableName(); + $gwfv_table = $this->Application->getUnitConfig('gwfv')->getTableName(); $sql = 'SELECT gwfv.Value, gwf.SystemFieldName FROM %s gwf @@ -130,8 +130,8 @@ $tax = false; $sql = 'SELECT tx.* - FROM '.$this->Application->getUnitOption('tax', 'TableName').' tx - LEFT JOIN '.$this->Application->getUnitOption('taxdst', 'TableName').' txd ON tx.TaxZoneId = txd.TaxZoneId + FROM '.$this->Application->getUnitConfig('tax')->getTableName().' tx + LEFT JOIN '.$this->Application->getUnitConfig('taxdst')->getTableName().' txd ON tx.TaxZoneId = txd.TaxZoneId WHERE ( txd.StdDestId IN ('.$shipping_country_id.','.$shipping_state_id.') AND @@ -250,7 +250,7 @@ function requireCreditCard() { $sql = 'SELECT RequireCCFields - FROM ' . $this->Application->getUnitOption('pt', 'TableName') . ' pt + FROM ' . $this->Application->getUnitConfig('pt')->getTableName() . ' pt LEFT JOIN '.TABLE_PREFIX.'Gateways gw ON gw.GatewayId = pt.GatewayId WHERE pt.PaymentTypeId = ' . $this->GetDBField('PaymentType'); Index: branches/5.3.x/units/affiliate_plans_items/affiliate_plans_items_tag_processor.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/affiliate_plans_items/affiliate_plans_items_tag_processor.php (.../affiliate_plans_items_tag_processor.php) (revision 15492) +++ branches/5.3.x/units/affiliate_plans_items/affiliate_plans_items_tag_processor.php (.../affiliate_plans_items_tag_processor.php) (revision 15695) @@ -1,6 +1,6 @@ Application->getUnitOption($this->Prefix, 'TableName'); + $table_name = $this->getUnitConfig()->getTableName(); - if ($this->Application->IsTempMode($this->Prefix)) { + if ( $this->Application->IsTempMode($this->Prefix) ) { $table_name = $this->Application->GetTempName($table_name, 'prefix:' . $this->Prefix); } $sql = 'SELECT COUNT(*) FROM ' . $table_name . ' WHERE (ItemType = 0) AND (AffiliatePlanId = ' . $this->Application->GetVar('ap_id') . ')'; + return $this->Conn->GetOne($sql); } Index: branches/5.3.x/units/taxes/taxes_tag_processor.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/taxes/taxes_tag_processor.php (.../taxes_tag_processor.php) (revision 15492) +++ branches/5.3.x/units/taxes/taxes_tag_processor.php (.../taxes_tag_processor.php) (revision 15695) @@ -1,6 +1,6 @@ Application->GetVar('CountrySelector'); $name_field = 'l' . $this->Application->GetVar('m_lang') . '_Name'; - $id_field = $this->Application->getUnitOption('country-state', 'IDField'); - $table_name = $this->Application->getUnitOption('country-state', 'TableName'); + $country_config = $this->Application->getUnitConfig('country-state'); + $id_field = $country_config->getIDField(); + $table_name = $country_config->getTableName(); + switch ($params['show']) { case 'current': // selected countries in current zone @@ -132,9 +134,11 @@ $destination_table = $this->getDestinationsTable($params); $name_field = 'l' . $this->Application->GetVar('m_lang') . '_Name'; - $id_field = $this->Application->getUnitOption('country-state', 'IDField'); - $table_name = $this->Application->getUnitOption('country-state', 'TableName'); + $country_config = $this->Application->getUnitConfig('country-state'); + $id_field = $country_config->getIDField(); + $table_name = $country_config->getTableName(); + $country_id = $this->Application->GetVar('CountrySelector'); switch ($params['show']) { @@ -217,7 +221,7 @@ $selected_zips = $this->Conn->qstrArray($selected_zips); $sql = 'SELECT DISTINCT DestValue - FROM ' . $this->Application->getUnitOption('taxdst', 'TableName') . ' + FROM ' . $this->Application->getUnitConfig('taxdst')->getTableName() . ' WHERE COALESCE(DestValue, "") <> "" AND TaxZoneId <> ' . $object->GetID() . ' AND @@ -261,7 +265,7 @@ $object = $this->getObject($params); /* @var $object kDBItem */ - $table_name = $this->Application->getUnitOption('taxdst', 'TableName'); + $table_name = $this->Application->getUnitConfig('taxdst')->getTableName(); if ($object->IsTempTable()) { $table_name = $this->Application->GetTempName($table_name, 'prefix:' . $this->Prefix); Index: branches/5.3.x/units/product_option_combinations/product_option_combinations_event_handler.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/product_option_combinations/product_option_combinations_event_handler.php (.../product_option_combinations_event_handler.php) (revision 15492) +++ branches/5.3.x/units/product_option_combinations/product_option_combinations_event_handler.php (.../product_option_combinations_event_handler.php) (revision 15695) @@ -1,6 +1,6 @@ setSelectSQL($sql); // 2. loads if allowed - $auto_load = $this->Application->getUnitOption($event->Prefix, 'AutoLoad'); + $auto_load = $event->getUnitConfig()->getAutoLoad(); $skip_autoload = $event->getEventParam('skip_autoload'); if ( $auto_load && !$skip_autoload ) { @@ -370,14 +370,14 @@ // check if product inventory management is via options and then proceed $id = $event->getEventParam('id'); - $products_table = $this->Application->getUnitOption('p', 'TableName'); - $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); - $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); + $products_table = $this->Application->getUnitConfig('p')->getTableName(); + $config = $event->getUnitConfig();; + $sql = 'SELECT p.InventoryStatus FROM ' . $products_table . ' p - LEFT JOIN ' . $table_name . ' poc ON poc.ProductId = p.ProductId - WHERE poc.' . $id_field . ' = ' . $id; + LEFT JOIN ' . $config->getTableName() . ' poc ON poc.ProductId = p.ProductId + WHERE poc.' . $config->getIDField() . ' = ' . $id; $inventory_status = $this->Conn->GetOne($sql); if ( $inventory_status == ProductInventory::BY_OPTIONS ) { Index: branches/5.3.x/units/shipping_quote_engines/usps.php =================================================================== diff -u -r15671 -r15695 --- branches/5.3.x/units/shipping_quote_engines/usps.php (.../usps.php) (revision 15671) +++ branches/5.3.x/units/shipping_quote_engines/usps.php (.../usps.php) (revision 15695) @@ -1,6 +1,6 @@ $order ) { // try to track order if ( $order['ShippingTracking'] != '' && $this->TrackOrder($order['ShippingTracking']) ) { + $config = $this->Application->getUnitConfig('ord'); + $update_order = sprintf("UPDATE %s SET `Delivered` = 1 WHERE %s = %s", TABLE_PREFIX.'Orders', - $this->Application->getUnitOption('ord', 'IDField'), - $order[$this->Application->getUnitOption('ord', 'IDField')] + $config->getIDField(), + $order[$config->getIDField()] ); $this->Application->Conn->Query($update_order); } @@ -1190,7 +1192,7 @@ function LoadParams() { - $sql = 'SELECT Properties FROM '.$this->Application->getUnitOption('sqe', 'TableName').' + $sql = 'SELECT Properties FROM '.$this->Application->getUnitConfig('sqe')->getTableName().' WHERE ClassName="USPS"'; $params = $this->Conn->GetOne($sql); Index: branches/5.3.x/units/discount_items/discount_items_event_handler.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/discount_items/discount_items_event_handler.php (.../discount_items_event_handler.php) (revision 15492) +++ branches/5.3.x/units/discount_items/discount_items_event_handler.php (.../discount_items_event_handler.php) (revision 15695) @@ -1,6 +1,6 @@ getObject( Array('skip_autoload' => true) ); + $object = $event->getObject(Array ('skip_autoload' => true)); + /* @var $object kDBItem */ + $selected_ids = $this->Application->GetVar('selected_ids'); - if ($selected_ids['c'] == $this->Application->GetVar('m_cat_id')) { + if ( $selected_ids['c'] == $this->Application->GetVar('m_cat_id') ) { // no categories were selected, so selector returned current in catalog. This is not needed here $selected_ids['c'] = ''; } $table_data = $object->getLinkedInfo(); // in selectors we could select category & item together - $prefixes = Array('c', 'p'); + $prefixes = Array ('c', 'p'); foreach ($prefixes as $prefix) { - $item_ids = $selected_ids[$prefix] ? explode(',', $selected_ids[$prefix]) : Array(); - if (!$item_ids) continue; + $item_ids = $selected_ids[$prefix] ? explode(',', $selected_ids[$prefix]) : Array (); - if ($prefix == 'c') { + if ( !$item_ids ) { + continue; + } + + if ( $prefix == 'c' ) { // select all products from selected categories and their subcategories $sql = 'SELECT DISTINCT p.ResourceId - FROM '.TABLE_PREFIX.'Categories c - LEFT JOIN '.TABLE_PREFIX.'CategoryItems ci ON c.CategoryId = ci.CategoryId - LEFT JOIN '.TABLE_PREFIX.'Products p ON p.ResourceId = ci.ItemResourceId - WHERE (p.ProductId IS NOT NULL) AND (c.ParentPath LIKE "%|'.implode('|%" OR c.ParentPath LIKE "%|', $item_ids).'|%")'; + FROM ' . TABLE_PREFIX . 'Categories c + LEFT JOIN ' . TABLE_PREFIX . 'CategoryItems ci ON c.CategoryId = ci.CategoryId + LEFT JOIN ' . TABLE_PREFIX . 'Products p ON p.ResourceId = ci.ItemResourceId + WHERE (p.ProductId IS NOT NULL) AND (c.ParentPath LIKE "%|' . implode('|%" OR c.ParentPath LIKE "%|', $item_ids) . '|%")'; $resource_ids = $this->Conn->GetCol($sql); } else { - // select selected prodcts + // select selected products + $config = $this->Application->getUnitConfig($prefix); + $sql = 'SELECT ResourceId - FROM '.$this->Application->getUnitOption($prefix, 'TableName').' - WHERE '.$this->Application->getUnitOption($prefix, 'IDField').' IN ('.implode(',', $item_ids).')'; + FROM ' . $config->getTableName() . ' + WHERE ' . $config->getIDField() . ' IN (' . implode(',', $item_ids) . ')'; $resource_ids = $this->Conn->GetCol($sql); } - if (!$resource_ids) continue; + if ( !$resource_ids ) { + continue; + } $sql = 'SELECT ItemResourceId - FROM '.$object->TableName.' - WHERE ('.$table_data['ForeignKey'].' = '.$table_data['ParentId'].') AND (ItemResourceId IN ('.implode(',', $resource_ids).'))'; + FROM ' . $object->TableName . ' + WHERE (' . $table_data['ForeignKey'] . ' = ' . $table_data['ParentId'] . ') AND (ItemResourceId IN (' . implode(',', $resource_ids) . '))'; // 1. don't insert items, that are already in $skip_resource_ids = $this->Conn->GetCol($sql); @@ -132,10 +141,10 @@ function OnDeleteDiscountedItem($event) { $main_object = $event->MasterEvent->getObject(); - $resource_id = $main_object->GetDBField('ResourceId'); + /* @var $main_object kDBItem */ - $table = $this->Application->getUnitOption($event->Prefix,'TableName'); - $sql = 'DELETE FROM '.$table.' WHERE ItemResourceId = '.$resource_id; + $sql = 'DELETE FROM ' . $event->getUnitConfig()->getTableName() . ' + WHERE ItemResourceId = ' . $main_object->GetDBField('ResourceId'); $this->Conn->Query($sql); } @@ -150,12 +159,11 @@ { parent::OnAfterConfigRead($event); - $calculated_fields = $this->Application->getUnitOption($event->Prefix, 'CalculatedFields'); - $language_id = $this->Application->GetVar('m_lang'); $primary_language_id = $this->Application->GetDefaultLanguageId(); - $calculated_fields['']['ItemName'] = 'COALESCE(p.l' . $language_id . '_Name, p.l' . $primary_language_id . '_Name)'; - $this->Application->setUnitOption($event->Prefix, 'CalculatedFields', $calculated_fields); + $event->getUnitConfig()->addCalculatedFieldsBySpecial('', Array ( + 'ItemName' => 'COALESCE(p.l' . $language_id . '_Name, p.l' . $primary_language_id . '_Name)' + )); } } \ No newline at end of file Index: branches/5.3.x/units/products/products_event_handler.php =================================================================== diff -u -r15671 -r15695 --- branches/5.3.x/units/products/products_event_handler.php (.../products_event_handler.php) (revision 15671) +++ branches/5.3.x/units/products/products_event_handler.php (.../products_event_handler.php) (revision 15695) @@ -1,6 +1,6 @@ GetDBField('InventoryStatus') == 2)) { // if combination id present and inventory by combinations - $poc_idfield = $this->Application->getUnitOption('poc', 'IDField'); - $poc_tablename = $this->Application->getUnitOption('poc', 'TableName'); + $poc_config = $this->Application->getUnitConfig('poc'); + $sql = 'SELECT QtyInStock - FROM '.$poc_tablename.' - WHERE '.$poc_idfield.' = '.$combination_id; + FROM '. $poc_config->getTableName() .' + WHERE '. $poc_config->getIDField() .' = '.$combination_id; $stock_qty = $this->Conn->GetOne($sql); } else { @@ -620,13 +620,13 @@ // my favorite products: begin if ( in_array('wish_list', $types) || in_array('wish_list', $except_types) ) { $sql = 'SELECT ResourceId - FROM ' . $this->Application->getUnitOption('fav', 'TableName') . ' + FROM ' . $this->Application->getUnitConfig('fav')->getTableName() . ' WHERE PortalUserId = ' . (int)$this->Application->RecallVar('user_id'); - $wishlist_ids = $this->Conn->GetCol($sql); + $wish_list_ids = $this->Conn->GetCol($sql); - if ( $wishlist_ids ) { - $type_clauses['wish_list']['include'] = '%1$s.ResourceId IN (' . implode(',', $wishlist_ids) . ') AND PrimaryCat = 1'; - $type_clauses['wish_list']['except'] = '%1$s.ResourceId NOT IN (' . implode(',', $wishlist_ids) . ') AND PrimaryCat = 1'; + if ( $wish_list_ids ) { + $type_clauses['wish_list']['include'] = '%1$s.ResourceId IN (' . implode(',', $wish_list_ids) . ') AND PrimaryCat = 1'; + $type_clauses['wish_list']['except'] = '%1$s.ResourceId NOT IN (' . implode(',', $wish_list_ids) . ') AND PrimaryCat = 1'; } else { $type_clauses['wish_list']['include'] = '0'; @@ -893,9 +893,11 @@ return false; } + $orders_config = $this->Application->getUnitConfig('ord'); + $sql = 'SELECT PortalUserId - FROM ' . $this->Application->getUnitOption('ord', 'TableName') . ' - WHERE ' . $this->Application->getUnitOption('ord', 'IDField') . ' = ' . $field_values['OrderId']; + FROM ' . $orders_config->getTableName() . ' + WHERE ' . $orders_config->getIDField() . ' = ' . $field_values['OrderId']; $user_id = $this->Conn->GetOne($sql); $group_id = $item_data['PortalGroupId']; @@ -935,19 +937,18 @@ $sub_order->SetDBField('NextCharge_time', $expire); } - function OnDownloadableApprove($event) + function OnDownloadableApprove(kEvent $event) { $field_values = $event->getEventParam('field_values'); $product_id = $field_values['ProductId']; - $sql = 'SELECT PortalUserId FROM '.$this->Application->getUnitOption('ord', 'TableName').' + $sql = 'SELECT PortalUserId FROM '.$this->Application->getUnitConfig('ord')->getTableName().' WHERE OrderId = '.$field_values['OrderId']; $user_id = $this->Conn->GetOne($sql); $sql = 'INSERT INTO '.TABLE_PREFIX.'UserFileAccess VALUES("", '.$product_id.', '.$user_id.')'; $this->Conn->Query($sql); } - protected function OnPackageApprove(kEvent $event) - { + function OnPackageApprove(kEvent $event){ $field_values = $event->getEventParam('field_values'); $item_data = unserialize($field_values['ItemData']); $package_content_ids = $item_data['PackageContent']; @@ -956,9 +957,9 @@ /* @var $object_item ProductsItem */ foreach ($package_content_ids as $package_item_id) { - $object_field_values = array (); + $object_field_values = array(); - // query processing data from product and run approve event + // query processing data from product and run approve event $sql = 'SELECT ProcessingData FROM ' . TABLE_PREFIX . 'Products WHERE ProductId = ' . $package_item_id; @@ -1456,9 +1457,11 @@ ORDER BY MinQty LIMIT 0,1'; - $calculated_fields = $this->Application->getUnitOption($event->Prefix, 'CalculatedFields'); - $calculated_fields['']['Price'] = 'IFNULL((' . $sub_select . '), ' . $calculated_fields['']['Price'] . ')'; - $this->Application->setUnitOption($event->Prefix, 'CalculatedFields', $calculated_fields); + $config = $event->getUnitConfig(); + + $calculated_fields = $config->getCalculatedFieldsBySpecial(''); + $calculated_fields['Price'] = 'IFNULL((' . $sub_select . '), ' . $calculated_fields['Price'] . ')'; + $config->setCalculatedFieldsBySpecial('', $calculated_fields); } /** @@ -1482,9 +1485,9 @@ */ function OnModifyPaidListingConfig($event) { - $edit_tab_presets = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'EditTabPresets'); - $edit_tab_presets['Default']['shopping_cart'] = Array ('title' => 'la_tab_ShopCartEntry', 't' => 'in-commerce/paid_listings/paid_listing_type_shopcart', 'priority' => 2); - $this->Application->setUnitOption($event->MasterEvent->Prefix, 'EditTabPresets', $edit_tab_presets); + $event->MasterEvent->getUnitConfig()->addEditTabPresetTabs('Default', Array ( + 'shopping_cart' => Array ('title' => 'la_tab_ShopCartEntry', 't' => 'in-commerce/paid_listings/paid_listing_type_shopcart', 'priority' => 2), + )); } /** @@ -1499,17 +1502,18 @@ parent::OnCloneSubItem($event); if ( $event->MasterEvent->Prefix == 'rev' ) { - $clones = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'Clones'); - $subitem_prefix = $event->Prefix . '-' . $event->MasterEvent->Prefix; + $sub_item_prefix = $event->Prefix . '-' . $event->MasterEvent->Prefix; - $clones[$subitem_prefix]['ConfigMapping'] = Array ( + $event->MasterEvent->getUnitConfig()->addClones(Array ( + $sub_item_prefix => Array ( + 'ConfigMapping' => Array ( 'PerPage' => 'Comm_Perpage_Reviews', 'ReviewDelayInterval' => 'product_ReviewDelay_Value', 'ReviewDelayValue' => 'product_ReviewDelay_Interval', - ); - - $this->Application->setUnitOption($event->MasterEvent->Prefix, 'Clones', $clones); + ), + ), + )); } } Index: branches/5.3.x/units/affiliates/affiliates_event_handler.php =================================================================== diff -u -r15671 -r15695 --- branches/5.3.x/units/affiliates/affiliates_event_handler.php (.../affiliates_event_handler.php) (revision 15671) +++ branches/5.3.x/units/affiliates/affiliates_event_handler.php (.../affiliates_event_handler.php) (revision 15695) @@ -1,6 +1,6 @@ Special == 'user' ) { + $config = $event->getUnitConfig(); $event->setEventParam('raise_warnings', 0); - $sql = 'SELECT ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . ' - FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + $sql = 'SELECT ' . $config->getIDField() . ' + FROM ' . $config->getTableName() . ' WHERE PortalUserId = ' . (int)$this->Application->RecallVar('user_id'); $id = $this->Conn->GetOne($sql); @@ -92,22 +93,24 @@ '31'=>'4','32'=>'5','33'=>'6','34'=>'7','35'=>'8','36'=>'9'); $ret = ''; - for($i=1; $i<=$number_length; $i++) - { + for ($i = 1; $i <= $number_length; $i++) { mt_srand((double)microtime() * 1000000); $num = mt_rand(1,36); $ret .= $num_chars[$num]; } + $ret = strtoupper($ret); - $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); - $table = $this->Application->getUnitOption($event->Prefix, 'TableName'); + $config = $event->getUnitConfig(); + $id_field = $config->getIDField(); + $table = $config->getTableName(); - $sql = 'SELECT %s FROM %s WHERE AffiliateCode = %s'; + $sql = 'SELECT %s + FROM %s + WHERE AffiliateCode = %s'; $code_found = $this->Conn->GetOne( sprintf($sql, $id_field, $table, $this->Conn->qstr($ret) ) ); - if($code_found) return $this->generateAffiliateCode($event); - return $ret; + return $code_found ? $this->generateAffiliateCode($event) : $ret; } /** @@ -244,7 +247,7 @@ if ( $affiliate_plan->isLoaded() ) { $sql = 'SELECT SUM(Quantity) FROM %s WHERE OrderId = %s'; - $orderitems_table = $this->Application->getUnitOption('orditems', 'TableName'); + $orderitems_table = $this->Application->getUnitConfig('orditems')->getTableName(); $items_sold = $this->Conn->GetOne(sprintf($sql, $orderitems_table, $order->GetID())); $object->SetDBField('AccumulatedAmount', $object->GetDBField('AccumulatedAmount') + $order->GetDBField('TotalAmount')); @@ -260,7 +263,7 @@ break; } - $apb_table = $this->Application->getUnitOption('apbrackets', 'TableName'); + $apb_table = $this->Application->getUnitConfig('apbrackets')->getTableName(); $sql = 'SELECT Percent FROM %1$s WHERE (%2$s >= FromAmount) AND ( (%2$s <= ToAmount) OR (ToAmount = -1) ) AND (AffiliatePlanId = %3$s)'; $commission_percent = $this->Conn->GetOne(sprintf($sql, $apb_table, $this->Conn->qstr($value), $affiliate_plan->GetID())); @@ -360,7 +363,7 @@ protected function _getPrimaryAffiliatePlan() { $sql = 'SELECT AffiliatePlanId - FROM ' . $this->Application->getUnitOption('ap', 'TableName') . ' + FROM ' . $this->Application->getUnitConfig('ap')->getTableName() . ' WHERE IsPrimary = 1'; return (int)$this->Conn->GetOne($sql); @@ -432,7 +435,7 @@ /* @var $payment_object kDBItem */ $id = $event->getEventParam('id'); - $ap_table = $this->Application->getUnitOption('apayments', 'TableName'); + $ap_table = $this->Application->getUnitConfig('apayments')->getTableName(); $sql = 'SELECT AffiliatePaymentId FROM ' . $ap_table . ' @@ -462,7 +465,7 @@ } $sql = 'SELECT Status - FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + FROM ' . $event->getUnitConfig()->getTableName() . ' WHERE ' . $object->IDField . ' = ' . $object->GetID(); $old_status = $this->Conn->GetOne($sql); @@ -486,8 +489,8 @@ $intervals = Array (86400 => 'la_day', 604800 => 'la_week', 2628000 => 'la_month', 7884000 => 'la_quartely', 31536000 => 'la_year'); - $affiliates_table = $this->Application->getUnitOption($event->Prefix, 'TableName'); - $affiliate_plan_table = $this->Application->getUnitOption('ap', 'TableName'); + $affiliates_table = $event->getUnitConfig()->getTableName(); + $affiliate_plan_table = $this->Application->getUnitConfig('ap')->getTableName(); $base_time = adodb_mktime(); $where_clause = Array (); @@ -582,6 +585,7 @@ { if ( $this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1) ) { $event->status = kEvent::erFAIL; + return; } @@ -591,7 +595,7 @@ $ids = $this->StoreSelectedIDs($event); if ( $ids ) { - $status_field = $object->getStatusField(); + $status_field = $event->getUnitConfig()->getStatusField(true); foreach ($ids as $id) { $object->Load($id); Index: branches/5.3.x/units/reports/reports_event_handler.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/reports/reports_event_handler.php (.../reports_event_handler.php) (revision 15492) +++ branches/5.3.x/units/reports/reports_event_handler.php (.../reports_event_handler.php) (revision 15695) @@ -1,6 +1,6 @@ Application->StoreVar('report_options', serialize($field_values)); } - function OnUpdateConfig($event) + function OnUpdateConfig(kEvent $event) { $report = $this->Application->RecallVar('report_options'); - if (!$report) { - return ; + + if ( !$report ) { + return; } $field_values = unserialize($report); - $rep_options = $this->Application->getUnitOptions('rep'); - $new_options = Array (); + $config = $event->getUnitConfig('rep'); + $config->setTableName($field_values['table_name']); - $new_options['TableName'] = $field_values['table_name']; - - $new_options['Fields'] = Array ( + $config->addFields(Array ( 'Qty' => Array ('type' => 'float', 'formatter' => 'kFormatter', 'format' => '%d', 'default' => 0, 'totals' => 'sum'), 'Cost' => Array ('type' => 'float', 'formatter' => 'kFormatter', 'format' => '%.2f', 'default' => 0, 'totals' => 'sum'), 'Amount' => Array ('type' => 'float', 'formatter' => 'kFormatter', 'format' => '%.2f', 'default' => 0, 'totals' => 'sum'), 'Tax' => Array ('type' => 'float', 'formatter' => 'kFormatter', 'format' => '%.2f', 'default' => 0, 'totals' => 'sum'), 'Shipping' => Array ('type' => 'float', 'formatter' => 'kFormatter', 'format' => '%.2f', 'default' => 0, 'totals' => 'sum'), 'Processing' => Array ('type' => 'float', 'formatter' => 'kFormatter', 'format' => '%.2f', 'default' => 0, 'totals' => 'sum'), 'Profit' => Array ('type' => 'float', 'formatter' => 'kFormatter', 'format' => '%.2f', 'default' => 0, 'totals' => 'sum'), - ); + )); if ( $this->Application->isModuleEnabled('in-auction') ) { - if ( in_Array ($field_values['ReportType'], Array (1, 5)) ) { - $new_options['Fields'] += Array ( + if ( in_array($field_values['ReportType'], Array (1, 5)) ) { + $config->addFields(Array ( 'StoreQty' => Array ('type' => 'int', 'formatter' => 'kFormatter', 'format' => '%d', 'default' => 0, 'totals' => 'sum'), 'StoreAmount' => Array ('type' => 'float', 'formatter' => 'kFormatter', 'format' => '%.2f', 'default' => 0, 'totals' => 'sum'), 'StoreProfit' => Array ('type' => 'float', 'formatter' => 'kFormatter', 'format' => '%.2f', 'default' => 0, 'totals' => 'sum'), 'eBayQty' => Array ('type' => 'int', 'formatter' => 'kFormatter', 'format' => '%d', 'default' => 0, 'totals' => 'sum'), 'eBayAmount' => Array ('type' => 'float', 'formatter' => 'kFormatter', 'format' => '%.2f', 'default' => 0, 'totals' => 'sum'), 'eBayProfit' => Array ('type' => 'float', 'formatter' => 'kFormatter', 'format' => '%.2f', 'default' => 0, 'totals' => 'sum'), - ); + )); } } - if ($field_values['ReportType'] == 1) { // by Category + if ( $field_values['ReportType'] == 1 ) { // by Category + $config->setListSQLsBySpecial('', ' SELECT %1$s.* %2$s + FROM %1$s + LEFT JOIN ' . TABLE_PREFIX . 'Categories AS c ON c.CategoryId = %1$s.CategoryId'); - $new_options['ListSQLs'][''] = - 'SELECT %1$s.* %2$s FROM %1$s - LEFT JOIN '.TABLE_PREFIX.'Categories AS c - ON c.CategoryId = %1$s.CategoryId'; - $new_options['Grids']['Default'] = Array ( - 'Icons' => Array ( - 'default' => 'icon16_item.png', - 'module' => 'core', - ), - 'Fields' => Array ( - 'CategoryName' => Array ('title' => 'la_col_CategoryName', 'filter_block' => 'grid_like_filter'), - 'Qty' => Array ('td_style' => 'text-align: center', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), - 'StoreQty' => Array ('title' => 'la_col_StoreQty', 'td_style' => 'text-align: center', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), - 'eBayQty' => Array ('title' => 'la_col_eBayQty', 'td_style' => 'text-align: center', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), - 'Cost' => Array ('td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), - 'Amount' => Array ('title' => 'la_col_GMV', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), - 'StoreAmount' => Array ('title' => 'la_col_StoreGMV', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), - 'eBayAmount' => Array ('title' => 'la_col_eBayGMV', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), - 'Tax' => Array ('title' => 'la_col_Tax', 'td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), - 'Shipping' => Array ('title' => 'la_col_Shipping', 'td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), - 'Processing' => Array ('title' => 'la_col_Processing', 'td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), - 'Profit' => Array ('title' => 'la_col_Profit', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), - 'StoreProfit' => Array ('title' => 'la_col_StoreProfit', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), - 'eBayProfit' => Array ('title' => 'la_col_eBayProfit', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), - ), - - ); - - if (!$this->Application->isModuleEnabled('in-auction')) { - $a_fields =& $new_options['Grids']['Default']['Fields']; - unset($a_fields['StoreQty']); - unset($a_fields['eBayQty']); - unset($a_fields['StoreAmount']); - unset($a_fields['eBayAmount']); - unset($a_fields['StoreProfit']); - unset($a_fields['eBayProfit']); + if ( $this->Application->isModuleEnabled('in-auction') ) { + $config->addGrids(Array ( + 'Icons' => Array ('default' => 'icon16_item.png', 'module' => 'core'), + 'Fields' => Array ( + 'CategoryName' => Array ('title' => 'la_col_CategoryName', 'filter_block' => 'grid_like_filter'), + 'Qty' => Array ('td_style' => 'text-align: center', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + 'StoreQty' => Array ('title' => 'la_col_StoreQty', 'td_style' => 'text-align: center', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + 'eBayQty' => Array ('title' => 'la_col_eBayQty', 'td_style' => 'text-align: center', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + 'Cost' => Array ('td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), + 'Amount' => Array ('title' => 'la_col_GMV', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + 'StoreAmount' => Array ('title' => 'la_col_StoreGMV', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + 'eBayAmount' => Array ('title' => 'la_col_eBayGMV', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + 'Tax' => Array ('title' => 'la_col_Tax', 'td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), + 'Shipping' => Array ('title' => 'la_col_Shipping', 'td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), + 'Processing' => Array ('title' => 'la_col_Processing', 'td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), + 'Profit' => Array ('title' => 'la_col_Profit', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + 'StoreProfit' => Array ('title' => 'la_col_StoreProfit', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + 'eBayProfit' => Array ('title' => 'la_col_eBayProfit', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + ), + ), 'Default'); } + else { + $config->addGrids(Array ( + 'Icons' => Array ('default' => 'icon16_item.png', 'module' => 'core'), + 'Fields' => Array ( + 'CategoryName' => Array ('title' => 'la_col_CategoryName', 'filter_block' => 'grid_like_filter'), + 'Qty' => Array ('td_style' => 'text-align: center', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + 'Cost' => Array ('td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), + 'Amount' => Array ('title' => 'la_col_GMV', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + 'Tax' => Array ('title' => 'la_col_Tax', 'td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), + 'Shipping' => Array ('title' => 'la_col_Shipping', 'td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), + 'Processing' => Array ('title' => 'la_col_Processing', 'td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), + 'Profit' => Array ('title' => 'la_col_Profit', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + ), + ), 'Default'); + } - $new_options['VirtualFields'] = array_merge($rep_options['VirtualFields'], Array ( + $config->addVirtualFields(Array ( 'CategoryName' => Array ('type' => 'string', 'default' => ''), - 'Metric' => Array ( - 'type' => 'int', - 'formatter' => 'kOptionsFormatter', - 'options' => $this->GetMetricOptions($new_options, 'CategoryName'), - 'use_phrases' => 1, - 'default' => 0, - ), + 'Metric' => Array ( + 'type' => 'int', + 'formatter' => 'kOptionsFormatter', + 'options' => $this->GetMetricOptions($config, 'CategoryName'), + 'use_phrases' => 1, + 'default' => 0, + ), )); $lang = $this->Application->GetVar('m_lang'); // products root category $products_category_id = $this->Application->findModule('Name', 'In-Commerce', 'RootCat'); + // get root category name $sql = 'SELECT LENGTH(l' . $lang . '_CachedNavbar) FROM ' . TABLE_PREFIX . 'Categories WHERE CategoryId = '.$products_category_id; $root_length = $this->Conn->GetOne($sql) + 4; - $new_options['CalculatedFields'][''] = array( - 'CategoryName' => 'REPLACE(SUBSTR(c.l'.$lang.'_CachedNavbar, '.$root_length.'), "&|&", " > ")', - ); + $config->addCalculatedFieldsBySpecial('', 'REPLACE(SUBSTR(c.l'.$lang.'_CachedNavbar, '.$root_length.'), "&|&", " > ")', 'CategoryName'); } elseif ($field_values['ReportType'] == 2) { // by User - $new_options['ListSQLs'][''] = - 'SELECT %1$s.* %2$s FROM %1$s - LEFT JOIN '.TABLE_PREFIX.'Users AS u - ON u.PortalUserId = %1$s.PortalUserId'; + $config->setListSQLsBySpecial('', ' SELECT %1$s.* %2$s + FROM %1$s + LEFT JOIN ' . TABLE_PREFIX . 'Users AS u ON u.PortalUserId = %1$s.PortalUserId'); - $new_options['Grids']['Default'] = Array ( - 'Icons' => Array ( - 'default' => 'icon16_item.png', - 'module' => 'core', - ), + $config->addGrids(Array ( + 'Icons' => Array ('default' => 'icon16_item.png', 'module' => 'core'), 'Fields' => Array ( 'Login' => Array ('filter_block' => 'grid_like_filter'), 'FirstName' => Array ('filter_block' => 'grid_like_filter'), @@ -455,100 +451,89 @@ 'Processing' => Array ('title' => 'la_col_Processing', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), 'Profit' => Array ('title' => 'la_col_Profit', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), ), - ); + ), 'Default'); - $new_options['VirtualFields'] = array_merge($rep_options['VirtualFields'], Array ( + $config->addVirtualFields(Array ( 'Login' => Array ('type' => 'string', 'default' => ''), 'FirstName' => Array ('type' => 'string', 'default' => ''), 'LastName' => Array ('type' => 'string', 'default' => ''), )); - $new_options['CalculatedFields'][''] = Array ( + $config->addCalculatedFieldsBySpecial('', Array ( 'Login' => 'u.Username', 'FirstName' => 'u.FirstName', 'LastName' => 'u.LastName', - ); + )); } elseif ($field_values['ReportType'] == 5) { // by Product + $config->setListSQLsBySpecial('', ' SELECT %1$s.* %2$s + FROM %1$s + LEFT JOIN '.TABLE_PREFIX.'Products AS p ON p.ProductId = %1$s.ProductId'); - $new_options['ListSQLs'][''] = - 'SELECT %1$s.* %2$s FROM %1$s - LEFT JOIN '.TABLE_PREFIX.'Products AS p - ON p.ProductId = %1$s.ProductId'; - - $new_options['Grids']['Default'] = Array ( - 'Icons' => Array ( - 'default' => 'icon16_item.png', - 'module' => 'core', + if ( $this->Application->isModuleEnabled('in-auction') ) { + $config->addGrids(Array ( + 'Icons' => Array ('default' => 'icon16_item.png', 'module' => 'core'), + 'Fields' => Array ( + 'ProductName' => Array ('title' => 'la_col_ProductName', 'filter_block' => 'grid_like_filter'), + 'Qty' => Array ('td_style' => 'text-align: center', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + 'StoreQty' => Array ('title' => 'la_col_StoreQty', 'td_style' => 'text-align: center', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + 'eBayQty' => Array ('title' => 'la_col_eBayQty', 'td_style' => 'text-align: center', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + 'Cost' => Array ('td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), + 'Amount' => Array ('title' => 'la_col_GMV', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + 'StoreAmount' => Array ('title' => 'la_col_StoreGMV', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + 'eBayAmount' => Array ('title' => 'la_col_eBayGMV', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + 'Tax' => Array ('title' => 'la_col_Tax', 'td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), + 'Shipping' => Array ('title' => 'la_col_Shipping', 'td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), + 'Processing' => Array ('title' => 'la_col_Processing', 'td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), + 'Profit' => Array ('title' => 'la_col_Profit', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + 'StoreProfit' => Array ('title' => 'la_col_StoreProfit', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + 'eBayProfit' => Array ('title' => 'la_col_eBayProfit', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), ), - 'Fields' => Array ( - 'ProductName' => Array ('title' => 'la_col_ProductName', 'filter_block' => 'grid_like_filter'), - 'Qty' => Array ('td_style' => 'text-align: center', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), - 'StoreQty' => Array ('title' => 'la_col_StoreQty', 'td_style' => 'text-align: center', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), - 'eBayQty' => Array ('title' => 'la_col_eBayQty', 'td_style' => 'text-align: center', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), - 'Cost' => Array ('td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), - 'Amount' => Array ('title' => 'la_col_GMV', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), - 'StoreAmount' => Array ('title' => 'la_col_StoreGMV', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), - 'eBayAmount' => Array ('title' => 'la_col_eBayGMV', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), - 'Tax' => Array ('title' => 'la_col_Tax', 'td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), - 'Shipping' => Array ('title' => 'la_col_Shipping', 'td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), - 'Processing' => Array ('title' => 'la_col_Processing', 'td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), - 'Profit' => Array ('title' => 'la_col_Profit', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), - 'StoreProfit' => Array ('title' => 'la_col_StoreProfit', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), - 'eBayProfit' => Array ('title' => 'la_col_eBayProfit', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), - ), - - ); - - if (!$this->Application->isModuleEnabled('in-auction')) - { - $a_fields =& $new_options['Grids']['Default']['Fields']; - unset($a_fields['StoreQty']); - unset($a_fields['eBayQty']); - unset($a_fields['StoreAmount']); - unset($a_fields['eBayAmount']); - unset($a_fields['StoreProfit']); - unset($a_fields['eBayProfit']); + ), 'Default'); } + else { + $config->addGrids(Array ( + 'Icons' => Array ('default' => 'icon16_item.png', 'module' => 'core'), + 'Fields' => Array ( + 'ProductName' => Array ('title' => 'la_col_ProductName', 'filter_block' => 'grid_like_filter'), + 'Qty' => Array ('td_style' => 'text-align: center', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + 'Cost' => Array ('td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), + 'Amount' => Array ('title' => 'la_col_GMV', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + 'Tax' => Array ('title' => 'la_col_Tax', 'td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), + 'Shipping' => Array ('title' => 'la_col_Shipping', 'td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), + 'Processing' => Array ('title' => 'la_col_Processing', 'td_style' => 'text-align: right', 'total' => 'sum', 'hidden' => 1, 'filter_block' => 'grid_range_filter'), + 'Profit' => Array ('title' => 'la_col_Profit', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), + ), + ), 'Default'); + } - - $new_options['VirtualFields'] = array_merge($rep_options['VirtualFields'], Array ( + $config->addVirtualFields(Array ( 'ProductName' => Array ('type' => 'string', 'default' => ''), - 'Metric' => Array ( - 'type' => 'int', - 'formatter' => 'kOptionsFormatter', - 'options' => $this->GetMetricOptions($new_options, 'ProductName'), - 'use_phrases' => 1, - 'default' => 0 - ), + 'Metric' => Array ( + 'type' => 'int', + 'formatter' => 'kOptionsFormatter', + 'options' => $this->GetMetricOptions($config, 'ProductName'), + 'use_phrases' => 1, + 'default' => 0 + ) )); $lang = $this->Application->GetVar('m_lang'); - - $new_options['CalculatedFields'][''] = Array ( - 'ProductName' => 'p.l'.$lang.'_Name', - ); + $config->addCalculatedFieldsBySpecial('', 'p.l' . $lang . '_Name', 'ProductName'); } elseif ($field_values['ReportType'] == 12) { // Overall + $config->setListSQLsBySpecial('', 'SELECT %1$s.* %2$s FROM %1$s'); - $new_options['ListSQLs'][''] = - 'SELECT %1$s.* %2$s FROM %1$s'; + $config->addFields(Array ( + 'Marketplace' => Array ( + 'formatter' => 'kOptionsFormatter', + 'options' => Array (1 => 'la_OnlineStore', 2 => 'la_eBayMarketplace'), 'use_phrases' => 1, + 'default' => 1 + ) + )); - $new_options['Fields']['Marketplace'] = Array ( - 'formatter' => 'kOptionsFormatter', - 'options' => Array ( - 1 => 'la_OnlineStore', - 2 => 'la_eBayMarketplace', - ), - 'use_phrases' => 1, - 'default' => 1 - ); - - $new_options['Grids']['Default'] = Array( - 'Icons' => Array( - 'default' => 'icon16_item.png', - 'module' => 'core', - ), + $config->addGrids(Array( + 'Icons' => Array('default' => 'icon16_item.png', 'module' => 'core'), 'Fields' => Array( 'Marketplace' => Array ('title' => 'la_col_Marketplace', 'filter_block' => 'grid_options_filter'), 'Qty' => Array ('td_style' => 'text-align: center', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), @@ -559,33 +544,20 @@ 'Processing' => Array ('title' => 'la_col_Processing', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), 'Profit' => Array ('title' => 'la_col_Profit', 'td_style' => 'text-align: right', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), ), + ), 'Default'); - ); - - - $new_options['VirtualFields'] = array_merge($rep_options['VirtualFields'], array( - 'Metric' => Array ( - 'type' => 'int', - 'formatter' => 'kOptionsFormatter', - 'options' => $this->GetMetricOptions($new_options, 'Marketplace'), - 'use_phrases' => 1, - 'default' => 0 - ), - )); - - $lang = $this->Application->GetVar('m_lang'); - + $config->addVirtualFields(Array ( + 'type' => 'int', + 'formatter' => 'kOptionsFormatter', + 'options' => $this->GetMetricOptions($config, 'Marketplace'), + 'use_phrases' => 1, + 'default' => 0 + ), 'Metric'); } - $new_options['ListSortings'] = Array( - '' => Array( - 'Sorting' => Array('Amount' => 'desc'), - ) - ); - - foreach ($new_options as $key => $val) { - $this->Application->setUnitOption('rep', $key, $val); - } + $config->setListSortingsBySpecial('', Array( + 'Sorting' => Array('Amount' => 'desc'), + )); } /** @@ -628,21 +600,24 @@ /** * Generate Metric Field Options * - * @param array $a_config_options + * @param kUnitConfig $config * @param string $exclude_field + * @return Array */ - function GetMetricOptions(&$a_config_options, $exclude_field) + function GetMetricOptions(kUnitConfig $config, $exclude_field) { - $a_ret = Array(); - foreach ($a_config_options['Grids']['Default']['Fields'] AS $field => $a_options) - { - if ($field == $exclude_field) - { + $grid = $config->getGridByName('Default'); + + $ret = Array (); + foreach ($grid['Fields'] as $field => $field_options) { + if ( $field == $exclude_field ) { continue; } - $a_ret[$field] = $a_options['title']; + + $ret[$field] = $field_options['title']; } - return $a_ret; + + return $ret; } function OnChangeStatistics($event) @@ -755,8 +730,8 @@ $ReportItem = $this->Application->recallObject('rep.item', 'rep', Array('skip_autoload' => true)); /* @var $ReportItem kDBItem*/ - $a_grids = $this->Application->getUnitOption('rep', 'Grids'); - $a_fields = $a_grids['Default']['Fields']; + $grid = $this->Application->getUnitConfig('rep')->getGridByName('Default'); + $a_fields = $grid['Fields']; $ret = ''; foreach ($a_fields AS $field => $a_props) Index: branches/5.3.x/gw_notify.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/gw_notify.php (.../gw_notify.php) (revision 15492) +++ branches/5.3.x/gw_notify.php (.../gw_notify.php) (revision 15695) @@ -1,6 +1,6 @@ GetADODBConnection(); - $application->setUnitOption('ord','AutoLoad',false); + $application->getUnitConfig('ord')->setAutoLoad(false); $order = $application->recallObject('ord'); $order_id = $application->GetVar('order_id'); Index: branches/5.3.x/units/addresses/addresses_event_handler.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/addresses/addresses_event_handler.php (.../addresses_event_handler.php) (revision 15492) +++ branches/5.3.x/units/addresses/addresses_event_handler.php (.../addresses_event_handler.php) (revision 15695) @@ -1,6 +1,6 @@ Application->recallObject('SiteHelper'); /* @var $site_helper SiteHelper */ - $fields = $this->Application->getUnitOption($event->Prefix, 'Fields'); + $config = $this->Application->getUnitConfig($event->Prefix); + + $fields = $config->getFields(); $fields['Country']['default'] = $site_helper->getDefaultCountry('Shipping'); - $this->Application->setUnitOption($event->Prefix, 'Fields', $fields); + $config->setFields($fields); } /** @@ -431,28 +433,26 @@ */ function OnModifyUsersConfig($event) { - $title_presets = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'TitlePresets'); + $config = $this->Application->getUnitConfig($event->MasterEvent->Prefix); - $title_presets['user_edit_addresses'] = Array ( - 'prefixes' => Array ('u', $event->Prefix . '_List'), - 'format' => "#u_status# '#u_titlefield#' - !la_title_Addresses! (#" . $event->Prefix . "_recordcount#)" - ); + $config->addTitlePresets(Array ( + 'user_edit_addresses' => Array ( + 'prefixes' => Array ('u', $event->Prefix . '_List'), + 'format' => "#u_status# '#u_titlefield#' - !la_title_Addresses! (#" . $event->Prefix . "_recordcount#)" + ), + 'user_address_edit' => Array ( + 'prefixes' => Array ('u', $event->Prefix), + 'new_status_labels' => Array ($event->Prefix => '!la_title_AddingAddress!'), + 'edit_status_labels' => Array ($event->Prefix => '!la_title_EditingAddress!'), + 'new_titlefield' => Array ($event->Prefix => '!la_title_NewAddress!'), + 'format' => "#u_status# '#u_titlefield#' - #{$event->Prefix}_status#" + ) + )); - $title_presets['user_address_edit'] = Array ( - 'prefixes' => Array ('u', $event->Prefix), - 'new_status_labels' => Array ($event->Prefix => '!la_title_AddingAddress!'), - 'edit_status_labels' => Array ($event->Prefix => '!la_title_EditingAddress!'), - 'new_titlefield' => Array ($event->Prefix => '!la_title_NewAddress!'), - 'format' => "#u_status# '#u_titlefield#' - #{$event->Prefix}_status#" - ); - $this->Application->setUnitOption($event->MasterEvent->Prefix, 'TitlePresets', $title_presets); - - $edit_tab_presets = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'EditTabPresets'); - - $edit_tab_presets['Default'][] = Array ( - 'title' => 'la_tab_Addresses', 't' => 'in-commerce/users/user_edit_addresses', 'priority' => 6 - ); - - $this->Application->setUnitOption($event->MasterEvent->Prefix, 'EditTabPresets', $edit_tab_presets); + $config->addEditTabPresetTabs('Default', Array ( + 'addresses' => Array ( + 'title' => 'la_tab_Addresses', 't' => 'in-commerce/users/user_edit_addresses', 'priority' => 6 + ) + )); } } \ No newline at end of file Index: branches/5.3.x/units/reports/reports_tag_processor.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/reports/reports_tag_processor.php (.../reports_tag_processor.php) (revision 15492) +++ branches/5.3.x/units/reports/reports_tag_processor.php (.../reports_tag_processor.php) (revision 15695) @@ -1,6 +1,6 @@ Application->getUnitOption('rep', 'VirtualFields'); + $a_virtual_fields = $this->Application->getUnitConfig('rep')->getVirtualFields(); + foreach ($a_virtual_fields['Metric']['options'] AS $field => $label) { $metric = $field; Index: branches/5.3.x/units/discount_items/discount_items_tag_processor.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/discount_items/discount_items_tag_processor.php (.../discount_items_tag_processor.php) (revision 15492) +++ branches/5.3.x/units/discount_items/discount_items_tag_processor.php (.../discount_items_tag_processor.php) (revision 15695) @@ -1,6 +1,6 @@ Application->getUnitOption($this->Prefix, 'TableName'); + $table_name = $this->getUnitConfig()->getTableName(); - if ($this->Application->IsTempMode($this->Prefix)) { + if ( $this->Application->IsTempMode($this->Prefix) ) { $table_name = $this->Application->GetTempName($table_name, 'prefix:' . $this->Prefix); } $sql = 'SELECT COUNT(*) FROM ' . $table_name . ' WHERE (ItemType = 0) AND (DiscountId = ' . $this->Application->GetVar('d_id') . ')'; + return $this->Conn->GetOne($sql); } Index: branches/5.3.x/units/gateways/gw_classes/paypal_direct.php =================================================================== diff -u -r15671 -r15695 --- branches/5.3.x/units/gateways/gw_classes/paypal_direct.php (.../paypal_direct.php) (revision 15671) +++ branches/5.3.x/units/gateways/gw_classes/paypal_direct.php (.../paypal_direct.php) (revision 15695) @@ -1,6 +1,6 @@ Conn->GetOne(' SELECT Email FROM '.$this->Application->getUnitOption('u', 'TableName').' - WHERE PortalUserId = '.$this->Application->RecallVar('user_id')); + $billing_email = $this->_getUserEmail(); } $post_fields['x_email'] = $billing_email; $post_fields['x_phone'] = $item_data['BillingPhone']; Index: branches/5.3.x/units/products/products_tag_processor.php =================================================================== diff -u -r15671 -r15695 --- branches/5.3.x/units/products/products_tag_processor.php (.../products_tag_processor.php) (revision 15671) +++ branches/5.3.x/units/products/products_tag_processor.php (.../products_tag_processor.php) (revision 15695) @@ -1,6 +1,6 @@ Application->ConfigValue('Comm_Enable_Backordering'); if ( $object->GetDBField('InventoryStatus') == 2 ) { - $poc_table = $this->Application->getUnitOption('poc', 'TableName'); + $poc_table = $this->Application->getUnitConfig('poc')->getTableName(); + $sql = 'SELECT SUM(IF(QtyInStock > ' . $object->GetDBField('QtyInStockMin') . ', 1, 0)) FROM ' . $poc_table . ' WHERE (ProductId = ' . $object->GetID() . ') AND (Availability = 1)'; @@ -553,8 +554,10 @@ function HasFiles($params) { - $sql = 'SELECT COUNT(FileId) FROM '.$this->Application->getUnitOption('file', 'TableName').' + $sql = 'SELECT COUNT(FileId) + FROM '.$this->Application->getUnitConfig('file')->getTableName().' WHERE ProductId = '.$this->Application->GetVar('p_id').' AND Status = 1'; + return $this->Conn->GetOne($sql) ? 1 : 0; } @@ -570,15 +573,13 @@ { $file_id = $this->Application->GetVar('file.downl_id'); $product_id = $file_id ? $this->Conn->GetOne('SELECT ProductId - FROM '.$this->Application->getUnitOption('file', 'TableName').' + FROM '.$this->Application->getUnitConfig('file')->getTableName().' WHERE FileId = '.$file_id) : $this->Application->GetVar($this->getPrefixSpecial().'_id'); - $download_helper_class = $this->Application->getUnitOption($this->Prefix, 'DownloadHelperClass'); + $download_helper_class = $this->getUnitConfig()->getDownloadHelperClass('DownloadHelper'); - if (!$download_helper_class) { - $download_helper_class = 'DownloadHelper'; - } + $download_helper = $this->Application->recallObject($download_helper_class); if (!$download_helper->CheckAccess($file_id, $product_id)) { $this->Application->ApplicationDie('File Access permission check failed!'); @@ -730,8 +731,8 @@ */ function ModifyUnitConfig($params) { - $edit_tab_presets = $this->Application->getUnitOption($this->Prefix, 'EditTabPresets'); - $edit_tab_preset = $edit_tab_presets['Default']; + $config = $this->getUnitConfig(); + $edit_tab_preset = $config->getEditTabPresetByName('Default'); $object = $this->getObject($params); /* @var $object kDBItem */ @@ -764,8 +765,7 @@ unset($edit_tab_preset['package_content']); } - $edit_tab_presets['Default'] = $edit_tab_preset; - $this->Application->setUnitOption($this->Prefix, 'EditTabPresets', $edit_tab_presets); + $config->addEditTabPresets($edit_tab_preset, 'Default'); } /** Index: branches/5.3.x/units/orders/order_manager.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/orders/order_manager.php (.../order_manager.php) (revision 15492) +++ branches/5.3.x/units/orders/order_manager.php (.../order_manager.php) (revision 15695) @@ -1,6 +1,6 @@ Application->getUnitOption($prefix, 'TableName'); + $table_name = $this->Application->getUnitConfig($prefix)->getTableName(); if ( $this->order->IsTempTable() ) { return $this->Application->GetTempName($table_name, 'prefix:' . $this->order->Prefix); Index: branches/5.3.x/units/downloads/download_helper.php =================================================================== diff -u -r15671 -r15695 --- branches/5.3.x/units/downloads/download_helper.php (.../download_helper.php) (revision 15671) +++ branches/5.3.x/units/downloads/download_helper.php (.../download_helper.php) (revision 15695) @@ -1,6 +1,6 @@ Application->recallObject('file', null, Array('skip_autoload' => true)); /* @var $file_object kDBItem */ - $sql = $file_id ? - 'SELECT FileId, FilePath, RealPath, MIMEType FROM '.$this->Application->getUnitOption('file', 'TableName').' - WHERE FileId = '.$file_id : - 'SELECT FileId, FilePath, RealPath, MIMEType FROM '.$this->Application->getUnitOption('file', 'TableName').' - WHERE ProductId = '.$product_id.' AND IsPrimary = 1'; + if ( $file_id ) { + $sql = 'SELECT FileId, FilePath, RealPath, MIMEType + FROM ' . $this->Application->getUnitConfig('file')->getTableName() . ' + WHERE FileId = ' . $file_id; + } + else { + $sql = 'SELECT FileId, FilePath, RealPath, MIMEType + FROM ' . $this->Application->getUnitConfig('file')->getTableName() . ' + WHERE ProductId = ' . $product_id . ' AND IsPrimary = 1'; + } + $file_info = $this->Conn->GetRow($sql); $field_options = $file_object->GetFieldOptions('RealPath'); Index: branches/5.3.x/units/gateways/gw_classes/atosorigin.php =================================================================== diff -u -r15671 -r15695 --- branches/5.3.x/units/gateways/gw_classes/atosorigin.php (.../atosorigin.php) (revision 15671) +++ branches/5.3.x/units/gateways/gw_classes/atosorigin.php (.../atosorigin.php) (revision 15695) @@ -1,6 +1,6 @@ Conn->GetOne(' SELECT Email FROM '.$this->Application->getUnitOption('u', 'TableName').' - WHERE PortalUserId = '.$this->Application->RecallVar('user_id')); + $billing_email = $this->_getUserEmail(); } $params['customer_email'] = $billing_email; Index: branches/5.3.x/units/gateways/gw_classes/gw_base.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/gateways/gw_classes/gw_base.php (.../gw_base.php) (revision 15492) +++ branches/5.3.x/units/gateways/gw_classes/gw_base.php (.../gw_base.php) (revision 15695) @@ -1,6 +1,6 @@ Application->getUnitConfig('u')->getTableName() . ' + WHERE PortalUserId = ' . $this->Application->RecallVar('user_id'); + + return $this->Conn->GetOne($sql); + } } \ No newline at end of file Index: branches/5.3.x/units/shipping_quote_engines/shipping_quote_collector.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/shipping_quote_engines/shipping_quote_collector.php (.../shipping_quote_collector.php) (revision 15492) +++ branches/5.3.x/units/shipping_quote_engines/shipping_quote_collector.php (.../shipping_quote_collector.php) (revision 15695) @@ -1,6 +1,6 @@ Application->getUnitOption('sqe', 'TableName') . ' + FROM ' . $this->Application->getUnitConfig('sqe')->getTableName() . ' WHERE Status = ' . STATUS_ACTIVE; $classes = $this->Conn->GetCol($sql); Index: branches/5.3.x/units/zones/zones_tag_processor.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/zones/zones_tag_processor.php (.../zones_tag_processor.php) (revision 15492) +++ branches/5.3.x/units/zones/zones_tag_processor.php (.../zones_tag_processor.php) (revision 15695) @@ -1,6 +1,6 @@ Application->GetVar('CountrySelector'); $name_field = 'l' . $this->Application->GetVar('m_lang') . '_Name'; - $id_field = $this->Application->getUnitOption('country-state', 'IDField'); - $table_name = $this->Application->getUnitOption('country-state', 'TableName'); + $countries_config = $this->Application->getUnitConfig('country-state'); + $id_field = $countries_config->getIDField(); + $table_name = $countries_config->getTableName(); + switch ($params['show']) { case 'current': // selected countries in current zone @@ -131,9 +133,11 @@ $destination_table = $this->getDestinationsTable($params); $name_field = 'l' . $this->Application->GetVar('m_lang') . '_Name'; - $id_field = $this->Application->getUnitOption('country-state', 'IDField'); - $table_name = $this->Application->getUnitOption('country-state', 'TableName'); + $countries_config = $this->Application->getUnitConfig('country-state'); + $id_field = $countries_config->getIDField(); + $table_name = $countries_config->getTableName(); + $country_id = $this->Application->GetVar('CountrySelector'); switch ($params['show']) { @@ -216,7 +220,7 @@ $selected_zips = $this->Conn->qstrArray($selected_zips); $sql = 'SELECT DISTINCT DestValue - FROM ' . $this->Application->getUnitOption('dst', 'TableName') . ' + FROM ' . $this->Application->getUnitConfig('dst')->getTableName() . ' WHERE COALESCE(DestValue, "") <> "" AND ShippingZoneID <> ' . $object->GetID() . ' AND @@ -260,7 +264,7 @@ $object = $this->getObject($params); /* @var $object kDBItem */ - $table_name = $this->Application->getUnitOption('dst', 'TableName'); + $table_name = $this->Application->getUnitConfig('dst')->getTableName(); if ($object->IsTempTable()) { $table_name = $this->Application->GetTempName($table_name, 'prefix:' . $this->Prefix); Index: branches/5.3.x/units/gateways/gw_classes/multicards.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/gateways/gw_classes/multicards.php (.../multicards.php) (revision 15492) +++ branches/5.3.x/units/gateways/gw_classes/multicards.php (.../multicards.php) (revision 15695) @@ -1,6 +1,6 @@ Conn->GetOne(' SELECT Email FROM '.$this->Application->getUnitOption('u', 'TableName').' + $billing_email = $this->Conn->GetOne(' SELECT Email FROM '.$this->Application->getUnitConfig('u')->getTableName().' WHERE PortalUserId = '.$this->Application->RecallVar('user_id')); } $ret['cust_email'] = $billing_email; Index: branches/5.3.x/units/products/products_item.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/products/products_item.php (.../products_item.php) (revision 15492) +++ branches/5.3.x/units/products/products_item.php (.../products_item.php) (revision 15695) @@ -1,6 +1,6 @@ Application->getUnitOption('pr', 'TableName'); + $pr_table = $this->Application->getUnitConfig('pr')->getTableName(); if ($this->IsTempTable()) { $pr_table = $this->Application->GetTempName($pr_table, 'prefix:' . $this->Prefix); Index: branches/5.3.x/units/shipping_quote_engines/shipping_quote_engine.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/shipping_quote_engines/shipping_quote_engine.php (.../shipping_quote_engine.php) (revision 15492) +++ branches/5.3.x/units/shipping_quote_engines/shipping_quote_engine.php (.../shipping_quote_engine.php) (revision 15695) @@ -1,6 +1,6 @@ Application->getUnitOption('sqe', 'TableName') . ' + FROM ' . $this->Application->getUnitConfig('sqe')->getTableName() . ' WHERE LOWER(ClassName) = ' . $this->Conn->qstr( strtolower( get_class($this) ) ); $data = $this->Conn->GetRow($sql); Index: branches/5.3.x/units/affiliate_payment_types/affiliate_payment_types_event_handler.php =================================================================== diff -u -r15671 -r15695 --- branches/5.3.x/units/affiliate_payment_types/affiliate_payment_types_event_handler.php (.../affiliate_payment_types_event_handler.php) (revision 15671) +++ branches/5.3.x/units/affiliate_payment_types/affiliate_payment_types_event_handler.php (.../affiliate_payment_types_event_handler.php) (revision 15695) @@ -1,6 +1,6 @@ GetDBField('IsPrimary') && $object->Validate() ) { - $sql = 'UPDATE ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + $config = $event->getUnitConfig(); + + $sql = 'UPDATE ' . $config->getTableName() . ' SET IsPrimary = 0'; $this->Conn->Query($sql); - $object->SetDBField($object->getStatusField(), 1); + $object->SetDBField($config->getStatusField(true), 1); } } @@ -108,10 +110,11 @@ protected function customProcessing(kEvent $event, $type) { if ( $event->Name == 'OnMassDelete' && $type == 'before' ) { + $config = $event->getUnitConfig(); $ids = $event->getEventParam('ids'); - $sql = 'SELECT ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . ' - FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + $sql = 'SELECT ' . $config->getIDField() . ' + FROM ' . $config->getTableName() . ' WHERE IsPrimary = 1'; $primary_id = $this->Conn->GetOne($sql); Index: branches/5.3.x/units/gateways/gw_classes/verisign_pflink.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/gateways/gw_classes/verisign_pflink.php (.../verisign_pflink.php) (revision 15492) +++ branches/5.3.x/units/gateways/gw_classes/verisign_pflink.php (.../verisign_pflink.php) (revision 15695) @@ -1,6 +1,6 @@ Conn->GetOne(' SELECT Email FROM '.$this->Application->getUnitOption('u', 'TableName').' + $billing_email = $this->Conn->GetOne(' SELECT Email FROM '.$this->Application->getUnitConfig('u')->getTableName().' WHERE PortalUserId = '.$this->Application->RecallVar('user_id')); } Index: branches/5.3.x/units/coupon_items/coupon_items_event_handler.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/coupon_items/coupon_items_event_handler.php (.../coupon_items_event_handler.php) (revision 15492) +++ branches/5.3.x/units/coupon_items/coupon_items_event_handler.php (.../coupon_items_event_handler.php) (revision 15695) @@ -1,6 +1,6 @@ MasterEvent->getObject(); - $resource_id = $main_object->GetDBField('ResourceId'); + /* @var $main_object kDBItem */ - $table = $this->Application->getUnitOption($event->Prefix,'TableName'); - $sql = 'DELETE FROM '.$table.' WHERE ItemResourceId = '.$resource_id; + $sql = 'DELETE FROM ' . $event->getUnitConfig()->getTableName() . ' + WHERE ItemResourceId = ' . $main_object->GetDBField('ResourceId'); $this->Conn->Query($sql); } @@ -100,12 +100,11 @@ { parent::OnAfterConfigRead($event); - $calculated_fields = $this->Application->getUnitOption($event->Prefix, 'CalculatedFields'); - $language_id = $this->Application->GetVar('m_lang'); $primary_language_id = $this->Application->GetDefaultLanguageId(); - $calculated_fields['']['ItemName'] = 'COALESCE(p.l' . $language_id . '_Name, p.l' . $primary_language_id . '_Name)'; - $this->Application->setUnitOption($event->Prefix, 'CalculatedFields', $calculated_fields); + $event->getUnitConfig()->addCalculatedFieldsBySpecial('', Array ( + 'ItemName' => 'COALESCE(p.l' . $language_id . '_Name, p.l' . $primary_language_id . '_Name)' + )); } } \ No newline at end of file Index: branches/5.3.x/units/order_items/order_items_event_handler.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/order_items/order_items_event_handler.php (.../order_items_event_handler.php) (revision 15492) +++ branches/5.3.x/units/order_items/order_items_event_handler.php (.../order_items_event_handler.php) (revision 15695) @@ -1,6 +1,6 @@ Load($product_id); $sql = 'SELECT COUNT(*) - FROM ' . $this->Application->getUnitOption('po', 'TableName') . ' + FROM ' . $this->Application->getUnitConfig('po')->getTableName() . ' WHERE (Required = 1) AND (ProductId = ' . $product_id . ')'; if ( $this->Conn->GetOne($sql) ) { @@ -278,13 +278,11 @@ { parent::OnAfterClone($event); - $id = $event->getEventParam('id'); - $table = $this->Application->getUnitOption($event->Prefix, 'TableName'); - $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); + $config = $event->getUnitConfig(); - $sql = 'UPDATE ' . $table . ' + $sql = 'UPDATE ' . $config->getTableName() . ' SET QuantityReserved = NULL - WHERE ' . $id_field . ' = ' . $id; + WHERE ' . $config->getIDField() . ' = ' . $event->getEventParam('id'); $this->Conn->Query($sql); } Index: branches/5.3.x/units/payment_type/payment_type_event_handler.php =================================================================== diff -u -r15671 -r15695 --- branches/5.3.x/units/payment_type/payment_type_event_handler.php (.../payment_type_event_handler.php) (revision 15671) +++ branches/5.3.x/units/payment_type/payment_type_event_handler.php (.../payment_type_event_handler.php) (revision 15695) @@ -1,6 +1,6 @@ SetRedirectParam('opener', 's'); } - function OnMassDecline($event) + function OnMassDecline(kEvent $event) { $object = $event->getObject(Array ('skip_autoload' => true)); /* @var $object kDBItem */ @@ -84,7 +84,7 @@ $ids = $this->getSelectedIDs($event); if ( $ids ) { - $status_field = $object->getStatusField(); + $status_field = $event->getUnitConfig()->getStatusField(true); foreach ($ids as $id) { $object->Load($id); @@ -120,7 +120,7 @@ $object = $event->getObject(); /* @var $object kDBItem */ - $status_field = $object->getStatusField(); + $status_field = $event->getUnitConfig()->getStatusField(true); if ( $object->GetDBField('IsPrimary') == 1 && $object->GetDBField($status_field) == 0 ) { $object->SetDBField($status_field, 1); @@ -201,11 +201,12 @@ { parent::OnAfterConfigRead($event); + $config = $event->getUnitConfig(); $default_group = $this->Application->ConfigValue('User_LoggedInGroup'); - $fields = $this->Application->getUnitOption($event->Prefix, 'Fields'); + $fields = $config->getFields(); $fields['PortalGroups']['default'] = ','.$default_group.','; - $this->Application->setUnitOption($event->Prefix, 'Fields', $fields); + $config->setFields($fields); } /** Index: branches/5.3.x/units/orders/orders_event_handler.php =================================================================== diff -u -r15671 -r15695 --- branches/5.3.x/units/orders/orders_event_handler.php (.../orders_event_handler.php) (revision 15671) +++ branches/5.3.x/units/orders/orders_event_handler.php (.../orders_event_handler.php) (revision 15695) @@ -1,6 +1,6 @@ getStatusField(); + $status_field = $event->getUnitConfig()->getStatusField(true); if ( isset($field_values[$status_field]) && $order_dummy->GetDBField($status_field) != $field_values[$status_field] ) { // user can't change status by himself @@ -318,11 +318,9 @@ $fields_hash['AffiliateId'] = $affiliate_id; } - $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); - $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); + $config = $event->getUnitConfig(); + $this->Conn->doUpdate($fields_hash, $config->getTableName(), $config->getIDField() . ' = ' . $order_id); - $this->Conn->doUpdate($fields_hash, $table_name, $id_field . ' = ' . $order_id); - $object = $event->getObject(); /* @var $object kDBItem */ @@ -374,7 +372,7 @@ $billing_email = $order->GetDBField('BillingEmail'); $sql = 'SELECT Email - FROM ' . $this->Application->getUnitOption('u', 'TableName') . ' + FROM ' . $this->Application->getUnitConfig('u')->getTableName() . ' WHERE PortalUserId = ' . $order->GetDBField('PortalUserId'); $user_email = $this->Conn->GetOne($sql); @@ -514,13 +512,14 @@ // $event->CallSubEvent('OnSave'); } - $order_id = $order->GetId(); - $order_idfield = $this->Application->getUnitOption('ord','IDField'); - $order_table = $this->Application->getUnitOption('ord','TableName'); + $order_id = $order->GetID(); + $config = $event->getUnitConfig(); + $original_amount = $order->GetDBField('SubTotal') + $order->GetDBField('ShippingCost') + $order->GetDBField('VAT') + $order->GetDBField('ProcessingFee') + $order->GetDBField('InsuranceFee') - $order->GetDBField('GiftCertificateDiscount'); - $sql = 'UPDATE '.$order_table.' + + $sql = 'UPDATE '. $config->getTableName() .' SET OriginalAmount = '.$original_amount.' - WHERE '.$order_idfield.' = '.$order_id; + WHERE '. $config->getIDField() .' = '.$order_id; $this->Conn->Query($sql); $this->Application->StoreVar('front_order_id', $order_id); @@ -1038,8 +1037,10 @@ // 2. check for option combinations in stock $comb_salt = $this->OptionsSalt($options, true); if ($comb_salt) { + $poc_config = $this->Application->getUnitConfig('poc'); + // such option combination is defined explicitly - $poc_table = $this->Application->getUnitOption('poc', 'TableName'); + $poc_table = $poc_config->getTableName(); $sql = 'SELECT Availability FROM '.$poc_table.' WHERE CombinationCRC = '.$comb_salt; @@ -1049,8 +1050,8 @@ if ($comb_availble == 1) { // 2.2. check for quantity in stock $table = Array(); - $table['poc'] = $this->Application->getUnitOption('poc', 'TableName'); - $table['p'] = $this->Application->getUnitOption('p', 'TableName'); + $table['poc'] = $poc_config->getTableName(); + $table['p'] = $this->Application->getUnitConfig('p')->getTableName(); $table['oi'] = $this->TablePrefix($event).'OrderItems'; $object = $event->getObject(); @@ -1140,23 +1141,29 @@ function BuildSubscriptionItemData($item_id, $item_data) { - $products_table = $this->Application->getUnitOption('p', 'TableName'); - $products_idfield = $this->Application->getUnitOption('p', 'IDField'); - $sql = 'SELECT AccessGroupId FROM %s WHERE %s = %s'; - $item_data['PortalGroupId'] = $this->Conn->GetOne( sprintf($sql, $products_table, $products_idfield, $item_id) ); + $products_config = $this->Application->getUnitConfig('p'); - $pricing_table = $this->Application->getUnitOption('pr', 'TableName'); - $pricing_idfield = $this->Application->getUnitOption('pr', 'IDField'); + $sql = 'SELECT AccessGroupId + FROM ' . $products_config->getTableName() . ' + WHERE ' . $products_config->getIDField() . ' = ' . $item_id; + $item_data['PortalGroupId'] = $this->Conn->GetOne($sql); /* TODO check on implementation - $sql = 'SELECT AccessDuration, AccessUnit, DurationType, AccessExpiration FROM %s WHERE %s = %s'; + $sql = 'SELECT AccessDuration, AccessUnit, DurationType, AccessExpiration + FROM %s + WHERE %s = %s'; */ - $sql = 'SELECT * FROM %s WHERE %s = %s'; + $pricing_config = $this->Application->getUnitConfig('pr'); $pricing_id = $this->GetPricingId($item_id, $item_data); + + $sql = 'SELECT * + FROM ' . $pricing_config->getTableName() . ' + WHERE ' . $pricing_config->getIDField() . ' = ' . $pricing_id; + $pricing_info = $this->Conn->GetRow($sql); + $item_data['PricingId'] = $pricing_id; - $pricing_info = $this->Conn->GetRow( sprintf($sql, $pricing_table, $pricing_idfield, $pricing_id ) ); $unit_secs = Array(1 => 1, 2 => 60, 3 => 3600, 4 => 86400, 5 => 604800, 6 => 2592000, 7 => 31536000); /* TODO check on implementation (code from customization healtheconomics.org) @@ -1226,7 +1233,7 @@ $coupon->Update(); - $this->Application->setUnitOption('ord', 'AutoLoad', true); + $this->Application->getUnitConfig('ord')->setAutoLoad(true); $order = $this->Application->recallObject('ord'); /* @var $order OrdersItem */ @@ -1296,15 +1303,15 @@ else { $link_id = $this->Application->GetVar('l_id'); - $sql = 'SELECT ResourceId FROM '.$this->Application->getUnitOption('l', 'TableName').' + $sql = 'SELECT ResourceId FROM '.$this->Application->getUnitConfig('l')->getTableName().' WHERE LinkId = '.$link_id; - $sql = 'SELECT ListingTypeId FROM '.$this->Application->getUnitOption('ls', 'TableName').' + $sql = 'SELECT ListingTypeId FROM '.$this->Application->getUnitConfig('ls')->getTableName().' WHERE ItemResourceId = '.$this->Conn->GetOne($sql); $item_data['LinkId'] = $link_id; $item_data['ListingTypeId'] = $this->Conn->GetOne($sql); } - $sql = 'SELECT VirtualProductId FROM '.$this->Application->getUnitOption('lst', 'TableName').' + $sql = 'SELECT VirtualProductId FROM '.$this->Application->getUnitConfig('lst')->getTableName().' WHERE ListingTypeId = '.$item_data['ListingTypeId']; $item_id = $this->Conn->GetOne($sql); @@ -1799,7 +1806,8 @@ */ function ReadyToProcess($ord_id) { - $poc_table = $this->Application->getUnitOption('poc', 'TableName'); + $poc_table = $this->Application->getUnitConfig('poc')->getTableName(); + $query = ' SELECT SUM(IF( IF('.TABLE_PREFIX.'Products.InventoryStatus = 2, '.$poc_table.'.QtyInStock, '.TABLE_PREFIX.'Products.QtyInStock) - '.TABLE_PREFIX.'Products.QtyInStockMin >= ('.TABLE_PREFIX.'OrderItems.Quantity - '.TABLE_PREFIX.'OrderItems.QuantityReserved), 0, 1)) FROM '.TABLE_PREFIX.'OrderItems LEFT JOIN '.TABLE_PREFIX.'Products ON '.TABLE_PREFIX.'Products.ProductId = '.TABLE_PREFIX.'OrderItems.ProductId @@ -1835,7 +1843,8 @@ if ($combinations) { // 2. query data about combinations - $poc_table = $this->Application->getUnitOption('poc', 'TableName'); + $poc_table = $this->Application->getUnitConfig('poc')->getTableName(); + $sql = 'SELECT CONCAT(poc.ProductId, "_", poc.CombinationCRC) AS CombinationKey, poc.* FROM '.$poc_table.' poc WHERE ('.implode(') OR (', $combinations).')'; @@ -2100,26 +2109,26 @@ } $product_object->Load($product_item['ProductId']); $hits = floor( $product_object->GetDBField('Hits') ) + 1; - $sql = 'SELECT MAX(Hits) FROM '.$this->Application->getUnitOption('p', 'TableName').' + $sql = 'SELECT MAX(Hits) FROM '.$this->Application->getUnitConfig('p')->getTableName().' WHERE FLOOR(Hits) = '.$hits; $hits = ( $res = $this->Conn->GetOne($sql) ) ? $res + 0.000001 : $hits; $product_object->SetDBField('Hits', $hits); $product_object->Update(); - /*$sql = 'UPDATE '.$this->Application->getUnitOption('p', 'TableName').' - SET Hits = Hits + '.$product_item['Quantity'].' - WHERE ProductId = '.$product_item['ProductId']; + /*$sql = 'UPDATE ' . $this->Application->getUnitConfig('p')->getTableName() . ' + SET Hits = Hits + ' . $product_item['Quantity'] . ' + WHERE ProductId = ' . $product_item['ProductId']; $this->Conn->Query($sql);*/ } $this->PrepareCoupons($event, $object); $this->SplitOrder($event, $object); - if ( $object->GetDBField('IsRecurringBilling') != 1 ) { + if ($object->GetDBField('IsRecurringBilling') != 1) { $this->Application->emailUser('ORDER.APPROVE', null, $email_params); // Mask credit card with XXXX - if ( $this->Application->ConfigValue('Comm_MaskProcessedCreditCards') ) { + if ($this->Application->ConfigValue('Comm_MaskProcessedCreditCards')) { $this->maskCreditCard($object, 'PaymentAccount'); $set_new_status = 1; } @@ -2138,15 +2147,15 @@ $this->raiseProductEvent('Deny', $product_item['ProductId'], $product_item); } - if ( ($original_order_status != ORDER_STATUS_INCOMPLETE) && ($event->Name == 'OnMassOrderDeny' || $event->Name == 'OnOrderDeny') ) { + if ( ($original_order_status != ORDER_STATUS_INCOMPLETE ) && ($event->Name == 'OnMassOrderDeny' || $event->Name == 'OnOrderDeny') ) { $this->Application->emailUser('ORDER.DENY', null, $email_params); // inform payment gateway that order was declined $gw_data = $object->getGatewayData(); if ( $gw_data ) { - $this->Application->registerClass($gw_data['ClassName'], GW_CLASS_PATH . '/' . $gw_data['ClassFile']); - $gateway_object = $this->Application->recallObject($gw_data['ClassName']); + $this->Application->registerClass( $gw_data['ClassName'], GW_CLASS_PATH . '/' . $gw_data['ClassFile'] ); + $gateway_object = $this->Application->recallObject( $gw_data['ClassName'] ); $gateway_object->OrderDeclined($object->GetFieldValues(), $gw_data['gw_params']); } @@ -2188,7 +2197,7 @@ if ( !array_key_exists('error_number', $ret) ) { $set_new_status = $this->approveOrder($order_items); -// $set_new_status = $this->shipOrder($order_items); + // $set_new_status = $this->shipOrder($order_items); $object->SetDBField('ShippingDate', adodb_mktime()); $object->UpdateFormattersSubFields(); @@ -2199,8 +2208,8 @@ // inform payment gateway that order was shipped $gw_data = $object->getGatewayData(); - $this->Application->registerClass($gw_data['ClassName'], GW_CLASS_PATH . '/' . $gw_data['ClassFile']); - $gateway_object = $this->Application->recallObject($gw_data['ClassName']); + $this->Application->registerClass( $gw_data['ClassName'], GW_CLASS_PATH.'/'.$gw_data['ClassFile'] ); + $gateway_object = $this->Application->recallObject( $gw_data['ClassName'] ); $gateway_object->OrderShipped($object->GetFieldValues(), $gw_data['gw_params']); } @@ -2215,7 +2224,7 @@ case 'OnMassOrderProcess': case 'OnOrderProcess': - if ( $this->ReadyToProcess($object->GetID()) ) { + if ($this->ReadyToProcess($object->GetID())) { $event->CallSubEvent('OnReserveItems'); if ( $event->status == kEvent::erSUCCESS ) { @@ -2230,7 +2239,7 @@ break; } - if ( $set_new_status ) { + if ($set_new_status) { $object->Update(); } } @@ -2312,13 +2321,12 @@ parent::OnAfterClone($event); $id = $event->getEventParam('id'); - $table = $this->Application->getUnitOption($event->Prefix, 'TableName'); - $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); + $config = $event->getUnitConfig(); // set cloned order status to Incomplete - $sql = 'UPDATE ' . $table . ' + $sql = 'UPDATE ' . $config->getTableName() . ' SET Status = 0 - WHERE ' . $id_field . ' = ' . $id; + WHERE ' . $config->getIDField() . ' = ' . $id; $this->Conn->Query($sql); } @@ -2634,7 +2642,7 @@ $ord_id = $order->GetId(); // TABLE_PREFIX and $table_prefix are NOT the same !!! - $poc_table = $this->Application->getUnitOption('poc', 'TableName'); + $poc_table = $this->Application->getUnitConfig('poc')->getTableName(); $query = ' SELECT BackOrderFlag, '. $table_prefix.'OrderItems.OrderItemId, '. @@ -2695,8 +2703,8 @@ } else { // inventory = 2 -> by product option combinations - $poc_idfield = $this->Application->getUnitOption('poc', 'IDField'); - $poc_table = $this->Application->getUnitOption('poc', 'TableName'); + $poc_table = $this->Application->getUnitConfig('poc')->getTableName(); + $query = ' UPDATE '.$poc_table.' SET '.$update_clause.' WHERE (ProductId = '.$an_item['ProductId'].') AND (CombinationCRC = '.$an_item['CombinationCRC'].')'; @@ -2734,8 +2742,8 @@ } else { // inventory by option combinations - $poc_idfield = $this->Application->getUnitOption('poc', 'IDField'); - $poc_table = $this->Application->getUnitOption('poc', 'TableName'); + $poc_table = $this->Application->getUnitConfig('poc')->getTableName(); + $query = ' UPDATE '.$poc_table.' SET '.$update_clause.' WHERE (ProductId = '.$an_item['ProductId'].') AND (CombinationCRC = '.$an_item['CombinationCRC'].')'; @@ -3338,7 +3346,12 @@ if ($object->GetDBField('Status') > ORDER_STATUS_PENDING) return; //no changes for orders other than incomple or pending $pt = $object->GetDBField('PaymentType'); - $processing_fee = $this->Conn->GetOne('SELECT ProcessingFee FROM '.$this->Application->getUnitOption('pt', 'TableName').' WHERE PaymentTypeId = '.$pt); + + $sql = 'SELECT ProcessingFee + FROM ' . $this->Application->getUnitConfig('pt')->getTableName() . ' + WHERE PaymentTypeId = ' . $pt; + $processing_fee = $this->Conn->GetOne($sql); + $object->SetDBField( 'ProcessingFee', $processing_fee ); $this->UpdateTotals($event); } @@ -3361,12 +3374,12 @@ return false; } - $sql = 'SELECT Price * Quantity AS Amount, ProductId FROM '.$this->Application->getUnitOption('orditems', 'TableName').' + $sql = 'SELECT Price * Quantity AS Amount, ProductId FROM '.$this->Application->getUnitConfig('orditems')->getTableName().' WHERE OrderId = '.$object->GetDBField('OrderId'); $orditems = $this->Conn->GetCol($sql, 'ProductId'); - $sql = 'SELECT coupi.ItemType, p.ProductId FROM '.$this->Application->getUnitOption('coupi', 'TableName').' coupi - LEFT JOIN '.$this->Application->getUnitOption('p', 'TableName').' p + $sql = 'SELECT coupi.ItemType, p.ProductId FROM '.$this->Application->getUnitConfig('coupi')->getTableName().' coupi + LEFT JOIN '.$this->Application->getUnitConfig('p')->getTableName().' p ON coupi.ItemResourceId = p.ResourceId WHERE CouponId = '.$object->GetDBField('CouponId'); $discounts = $this->Conn->GetCol($sql, 'ProductId'); @@ -3404,13 +3417,14 @@ { $id = current($this->StoreSelectedIDs($event)); - $id_field = $this->Application->getUnitOption($event->Prefix,'IDField'); - $table = $this->Application->getUnitOption($event->Prefix,'TableName'); + $config = $event->getUnitConfig(); + $id_field = $config->getIDField(); - $sql = 'SELECT Status FROM %s WHERE %s = %s'; + $sql = 'SELECT Status + FROM ' . $config->getTableName() . ' + WHERE ' . $id_field . ' = ' . $id; + $order_status = $this->Conn->GetOne($sql); - $order_status = $this->Conn->GetOne( sprintf($sql, $table, $id_field, $id) ); - $prefix_special = $event->Prefix.'.'.$this->getSpecialByType($order_status); $orders_list = $this->Application->recallObject($prefix_special, $event->Prefix.'_List', Array('per_page'=>-1) ); @@ -3480,14 +3494,14 @@ */ function getRecurringOrders($pre_expiration) { - $ord_table = $this->Application->getUnitOption('ord', 'TableName'); - $ord_idfield = $this->Application->getUnitOption('ord', 'IDField'); + $config = $this->Application->getUnitConfig('ord'); + $ord_id_field = $config->getIDField(); $processing_allowed = Array(ORDER_STATUS_PROCESSED, ORDER_STATUS_ARCHIVED); - $sql = 'SELECT '.$ord_idfield.', PortalUserId, GroupId, NextCharge - FROM '.$ord_table.' + $sql = 'SELECT '.$ord_id_field.', PortalUserId, GroupId, NextCharge + FROM '. $config->getTableName() .' WHERE (IsRecurringBilling = 1) AND (NextCharge < '.$pre_expiration.') AND Status IN ('.implode(',', $processing_allowed).')'; - return $this->Conn->Query($sql, $ord_idfield); + return $this->Conn->Query($sql, $ord_id_field); } /** @@ -3498,11 +3512,9 @@ function OnCheckRecurringOrders($event) { $skip_clause = Array(); - $ord_table = $this->Application->getUnitOption($event->Prefix, 'TableName'); - $ord_idfield = $this->Application->getUnitOption($event->Prefix, 'IDField'); - $pre_expiration = adodb_mktime() + $this->Application->ConfigValue('Comm_RecurringChargeInverval') * 3600 * 24; $to_charge = $this->getRecurringOrders($pre_expiration); + if ($to_charge) { $order_ids = Array(); foreach ($to_charge as $order_id => $record) { @@ -3537,9 +3549,11 @@ } // remove recurring flag from all orders found, not to select them next time script runs - $sql = 'UPDATE '.$ord_table.' + $config = $event->getUnitConfig(); + + $sql = 'UPDATE '. $config->getTableName() .' SET IsRecurringBilling = 0 - WHERE '.$ord_idfield.' IN ('.implode(',', array_keys($to_charge)).')'; + WHERE '. $config->getIDField() .' IN ('.implode(',', array_keys($to_charge)).')'; $this->Conn->Query($sql); } @@ -3658,14 +3672,16 @@ $order_number = (int)$this->Application->ConfigValue('Comm_Order_Number_Format_P'); $order_sub_number = (int)$this->Application->ConfigValue('Comm_Order_Number_Format_S'); - $calc_fields = $this->Application->getUnitOption($event->Prefix, 'CalculatedFields'); + $config = $event->getUnitConfig(); + $calc_fields = $config->getSetting('CalculatedFields'); + foreach ($calc_fields as $special => $fields) { $calc_fields[$special]['OrderNumber'] = str_replace('6', $order_number, $calc_fields[$special]['OrderNumber']); $calc_fields[$special]['OrderNumber'] = str_replace('3', $order_sub_number, $calc_fields[$special]['OrderNumber']); } - $this->Application->setUnitOption($event->Prefix, 'CalculatedFields', $calc_fields); + $config->setSetting('CalculatedFields', $calc_fields); - $fields = $this->Application->getUnitOption($event->Prefix, 'Fields'); + $fields = $config->getFields(); $fields['Number']['format'] = str_replace('%06d', '%0'.$order_number.'d', $fields['Number']['format']); $fields['SubNumber']['format'] = str_replace('%03d', '%0'.$order_sub_number.'d', $fields['SubNumber']['format']); @@ -3702,13 +3718,13 @@ ); } - $this->Application->setUnitOption($event->Prefix, 'Fields', $fields); + $config->setFields($fields); - $user_forms = $this->Application->getUnitOption('u', 'Forms'); + $user_default_form = $this->Application->getUnitConfig('u')->getFieldByName('default'); - $virtual_fields = $this->Application->getUnitOption($event->Prefix, 'VirtualFields'); - $virtual_fields['UserPassword']['hashing_method'] = $user_forms['default']['Fields']['PasswordHashingMethod']['default']; - $this->Application->setUnitOption($event->Prefix, 'VirtualFields', $virtual_fields); + $virtual_fields = $config->getVirtualFields(); + $virtual_fields['UserPassword']['hashing_method'] = $user_default_form['Fields']['PasswordHashingMethod']['default']; + $config->setVirtualFields($virtual_fields); } /** Index: branches/5.3.x/units/currencies/currencies_event_handler.php =================================================================== diff -u -r15583 -r15695 --- branches/5.3.x/units/currencies/currencies_event_handler.php (.../currencies_event_handler.php) (revision 15583) +++ branches/5.3.x/units/currencies/currencies_event_handler.php (.../currencies_event_handler.php) (revision 15695) @@ -1,6 +1,6 @@ GetDBField('IsPrimary') && $object->Validate() ) { - $sql = 'UPDATE ' . $this->Application->getUnitOption($this->Prefix, 'TableName') . ' + $sql = 'UPDATE ' . $event->getUnitConfig()->getTableName() . ' SET IsPrimary = 0 WHERE CurrencyId <> ' . $object->GetDBField('CurrencyId'); $this->Conn->Query($sql); @@ -106,7 +106,7 @@ $object->SetDBField('Modified_time', adodb_mktime()); if ( $object->GetDBField('Status') == 0 ) { - $sql = 'DELETE FROM ' . $this->Application->getUnitOption('ptc', 'TableName') . ' + $sql = 'DELETE FROM ' . $this->Application->getUnitConfig('ptc')->getTableName() . ' WHERE CurrencyId = ' . $object->GetDBField('CurrencyId'); $this->Conn->Query($sql); } @@ -178,7 +178,7 @@ $unused_ids = $this->Application->GetVar('unused_ids'); if ( $unused_ids ) { - $sql = 'UPDATE ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + $sql = 'UPDATE ' . $event->getUnitConfig()->getTableName() . ' SET Status = 0 WHERE CurrencyId IN(' . $unused_ids . ') AND IsPrimary <> 1'; $this->Conn->Query($sql); Index: branches/5.3.x/units/shipping_quote_engines/intershipper.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/shipping_quote_engines/intershipper.php (.../intershipper.php) (revision 15492) +++ branches/5.3.x/units/shipping_quote_engines/intershipper.php (.../intershipper.php) (revision 15695) @@ -1,6 +1,6 @@ Application->getUnitOption('sqe', 'TableName').' + $sql = 'SELECT Properties, FlatSurcharge, PercentSurcharge FROM '.$this->Application->getUnitConfig('sqe')->getTableName().' WHERE Name="Intershipper.com"'; $data = $this->Conn->GetRow($sql); Index: branches/5.3.x/install/upgrades.php =================================================================== diff -u -r15671 -r15695 --- branches/5.3.x/install/upgrades.php (.../upgrades.php) (revision 15671) +++ branches/5.3.x/install/upgrades.php (.../upgrades.php) (revision 15695) @@ -1,6 +1,6 @@ Application->getUnitConfig('c'); $root_category = $this->Application->findModule('Name', 'In-Commerce', 'RootCat'); - $sql = 'UPDATE ' . $this->Application->getUnitOption('c', 'TableName') . ' + $sql = 'UPDATE ' . $categories_config->getTableName() . ' SET UseMenuIconUrl = 1, MenuIconUrl = "in-commerce/img/menu_products.gif" - WHERE ' . $this->Application->getUnitOption('c', 'IDField') . ' = ' . $root_category; + WHERE ' . $categories_config->getIDField() . ' = ' . $root_category; $this->Conn->Query($sql); $this->_updateDetailTemplate('p', 'in-commerce/product/details', 'in-commerce/designs/detail'); @@ -156,7 +157,7 @@ return; } - $table_name = $this->Application->getUnitOption('pt', 'TableName'); + $table_name = $this->Application->getUnitConfig('pt')->getTableName(); $table_structure = $this->Conn->Query('DESCRIBE ' . $table_name, 'Field'); if ( isset($table_structure['Description']) ) { Index: branches/5.3.x/units/gateways/gw_classes/authorizenet.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/gateways/gw_classes/authorizenet.php (.../authorizenet.php) (revision 15492) +++ branches/5.3.x/units/gateways/gw_classes/authorizenet.php (.../authorizenet.php) (revision 15695) @@ -1,6 +1,6 @@ Conn->GetOne(' SELECT Email FROM '.$this->Application->getUnitOption('u', 'TableName').' - WHERE PortalUserId = '.$this->Application->RecallVar('user_id')); + $billing_email = $this->_getUserEmail(); } + $post_fields['x_email'] = $billing_email; $post_fields['x_phone'] = $item_data['BillingPhone']; Index: branches/5.3.x/units/orders/order_calculator.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/orders/order_calculator.php (.../order_calculator.php) (revision 15492) +++ branches/5.3.x/units/orders/order_calculator.php (.../order_calculator.php) (revision 15695) @@ -1,6 +1,6 @@ Application->getUnitOption('poc', 'TableName'); + $poc_table = $this->Application->getUnitConfig('poc')->getTableName(); $query = ' SELECT oi.ProductId, oi.OptionsSalt, oi.ItemData, oi.Quantity, IF(p.InventoryStatus = ' . ProductInventory::BY_OPTIONS . ', poc.QtyInStock, p.QtyInStock) AS QtyInStock, Index: branches/5.3.x/units/orders/orders_tag_processor.php =================================================================== diff -u -r15671 -r15695 --- branches/5.3.x/units/orders/orders_tag_processor.php (.../orders_tag_processor.php) (revision 15671) +++ branches/5.3.x/units/orders/orders_tag_processor.php (.../orders_tag_processor.php) (revision 15695) @@ -1,6 +1,6 @@ GetID(); - $oi_table = $this->Application->getUnitOption('orditems', 'TableName'); + $oi_table = $this->Application->getUnitConfig('orditems')->getTableName(); if ( $object->IsTempTable() ) { $oi_table = $this->Application->GetTempName($oi_table, 'prefix:' . $object->Prefix); @@ -532,7 +532,7 @@ $object->SetDBField('PaymentType', $pt); } - $pt_table = $this->Application->getUnitOption('pt','TableName'); + $pt_table = $this->Application->getUnitConfig('pt')->getTableName(); $sql = 'SELECT GatewayId FROM %s WHERE PaymentTypeId = %s'; $gw_id = $this->Conn->GetOne( sprintf( $sql, $pt_table, $pt ) ); @@ -614,8 +614,9 @@ */ function OrderEditable($params) { - $id_field = $this->Application->getUnitOption($this->Prefix, 'IDField'); - $table_name = $this->Application->getUnitOption($this->Prefix, 'TableName'); + $config = $this->getUnitConfig(); + $id_field = $config->getIDField(); + $table_name = $config->getTableName(); if ($this->Application->IsTempMode($this->Prefix, $this->Special)) { $table_name = $this->Application->GetTempName($table_name, 'prefix:' . $this->Prefix); @@ -640,9 +641,11 @@ case ORDER_STATUS_PENDING: case ORDER_STATUS_BACKORDERS: + $config = $this->Application->getUnitConfig('pt'); + $sql = 'SELECT PlacedOrdersEdit - FROM ' . $this->Application->getUnitOption('pt', 'TableName') . ' - WHERE ' . $this->Application->getUnitOption('pt', 'IDField') . ' = ' . $order_data['PaymentType']; + FROM ' . $config->getTableName() . ' + WHERE ' . $config->getIDField() . ' = ' . $order_data['PaymentType']; $ret = $this->Conn->GetOne($sql); break; @@ -1402,9 +1405,12 @@ function UserHasPendingOrders($params) { - $sql = 'SELECT OrderId FROM '.$this->Application->getUnitOption($this->Prefix, 'TableName').' - WHERE PortalUserId = '.$this->Application->RecallVar('user_id').' - AND Status = '.ORDER_STATUS_PENDING; + $user_id = $this->Application->RecallVar('user_id'); + + $sql = 'SELECT OrderId + FROM '.$this->getUnitConfig()->getTableName().' + WHERE PortalUserId = '. $user_id .' AND Status = '.ORDER_STATUS_PENDING; + return $this->Conn->GetOne($sql) ? 1 : 0; } Index: branches/5.3.x/units/currencies/currencies_tag_processor.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/currencies/currencies_tag_processor.php (.../currencies_tag_processor.php) (revision 15492) +++ branches/5.3.x/units/currencies/currencies_tag_processor.php (.../currencies_tag_processor.php) (revision 15695) @@ -1,6 +1,6 @@ Application->RecallVar('saved_curr_ids'); // when saving currency(-ies) - $check_all = $this->Application->RecallVar('check_unused_currencies'); // when saving payment type $ret = ''; - if($saved_ids || $check_all) - { - $sql = 'SELECT DISTINCT CurrencyId FROM '.$this->Application->getUnitOption('ptc', 'TableName'); + $saved_ids = $this->Application->RecallVar('saved_curr_ids'); // when saving currency(-ies) + $check_all = $this->Application->RecallVar('check_unused_currencies'); // when saving payment type + + $config = $this->getUnitConfig(); + + if ( $saved_ids || $check_all ) { + $sql = 'SELECT DISTINCT CurrencyId + FROM ' . $this->Application->getUnitConfig('ptc')->getTableName(); $used_ids = $this->Conn->GetCol($sql); - if($check_all) - { - $sql = 'SELECT DISTINCT CurrencyId FROM '.$this->Application->getUnitOption('curr', 'TableName'); + + if ( $check_all ) { + $sql = 'SELECT DISTINCT CurrencyId + FROM ' . $config->getTableName(); $all_ids = $this->Conn->GetCol($sql); - $unused_ids = implode(',', array_diff($all_ids, $used_ids) ); + + $unused_ids = implode(',', array_diff($all_ids, $used_ids)); $this->Application->RemoveVar('check_unused_currencies'); } - else - { + else { $saved_ids = explode(',', $saved_ids); - $unused_ids = implode(',', array_diff($saved_ids, $used_ids) ); + $unused_ids = implode(',', array_diff($saved_ids, $used_ids)); $this->Application->RemoveVar('saved_curr_ids'); } if ( $unused_ids ) { $this->Application->SetVar('unused_ids', $unused_ids); + $sql = 'SELECT ISO - FROM '.$this->Application->getUnitOption($this->Prefix, 'TableName').' - WHERE CurrencyId IN('.$unused_ids.') AND Status = 1'; + FROM ' . $config->getTableName() . ' + WHERE CurrencyId IN(' . $unused_ids . ') AND Status = 1'; $params['unused_iso'] = implode(', ', $this->Conn->GetCol($sql)); if ( $params['unused_iso'] ) { @@ -52,6 +57,7 @@ } } } + return $ret; } @@ -82,7 +88,7 @@ function PrimaryCurrencyISO($params) { $sql = 'SELECT ISO - FROM ' . $this->Application->getUnitOption($this->Prefix, 'TableName') . ' + FROM ' . $this->getUnitConfig()->getTableName() . ' WHERE IsPrimary = 1'; return $this->Conn->GetOne($sql); @@ -91,7 +97,7 @@ function PrimaryCurrencyName($params) { $sql = 'SELECT Name - FROM ' . $this->Application->getUnitOption($this->Prefix, 'TableName') . ' + FROM ' . $this->getUnitConfig()->getTableName() . ' WHERE IsPrimary = 1'; return $this->Application->Phrase( $this->Conn->GetOne($sql) ); Index: branches/5.3.x/units/coupon_items/coupon_items_tag_processor.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/coupon_items/coupon_items_tag_processor.php (.../coupon_items_tag_processor.php) (revision 15492) +++ branches/5.3.x/units/coupon_items/coupon_items_tag_processor.php (.../coupon_items_tag_processor.php) (revision 15695) @@ -1,6 +1,6 @@ Application->getUnitOption($this->Prefix, 'TableName'); + $table_name = $this->getUnitConfig()->getTableName(); - if ($this->Application->IsTempMode($this->Prefix)) { + if ( $this->Application->IsTempMode($this->Prefix) ) { $table_name = $this->Application->GetTempName($table_name, 'prefix:' . $this->Prefix); } $sql = 'SELECT COUNT(*) FROM ' . $table_name . ' WHERE (ItemType = 0) AND (CouponId = ' . $this->Application->GetVar('coup_id') . ')'; + return $this->Conn->GetOne($sql); } @@ -34,12 +35,16 @@ $object = $this->getObject($params); /* @var $object kDBList */ - if ($object->GetDBField('ItemType') == 2) { + if ( $object->GetDBField('ItemType') == 2 ) { $cat_object = $this->Application->recallObject('c'); - $cat_object->Load( $object->GetDBField('CategoryId') ); + /* @var $cat_object CategoriesItem */ + + $cat_object->Load($object->GetDBField('CategoryId')); + $cat_tag_processor = $this->Application->recallObject('c_TagProcessor'); + /* @var $cat_tag_processor CategoriesTagProcessor */ - return $cat_tag_processor->ItemIcon(); + return $cat_tag_processor->ItemIcon($params); } return parent::ItemIcon($params); Index: branches/5.3.x/units/order_items/order_items_tag_processor.php =================================================================== diff -u -r15671 -r15695 --- branches/5.3.x/units/order_items/order_items_tag_processor.php (.../order_items_tag_processor.php) (revision 15671) +++ branches/5.3.x/units/order_items/order_items_tag_processor.php (.../order_items_tag_processor.php) (revision 15695) @@ -1,6 +1,6 @@ GetDBField('InventoryStatus') == 2) { - $poc_table = $this->Application->getUnitOption('poc', 'TableName'); + $poc_table = $this->Application->getUnitConfig('poc')->getTableName(); $sql = 'SELECT QtyInStock FROM '.$poc_table.' WHERE (ProductId = '.$object->GetDBField('ProductId').') AND (Availability = 1) AND (CombinationCRC = '.$object->GetDBField('OptionsSalt').')'; @@ -209,7 +209,7 @@ function PrintList($params) { $list =& $this->GetList($params); - $id_field = $this->Application->getUnitOption($this->Prefix, 'IDField'); + $id_field = $this->getUnitConfig()->getIDField(); $list->Query(); $o = ''; Index: branches/5.3.x/units/helpers/currency_rates.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/helpers/currency_rates.php (.../currency_rates.php) (revision 15492) +++ branches/5.3.x/units/helpers/currency_rates.php (.../currency_rates.php) (revision 15695) @@ -1,6 +1,6 @@ Application->getCache($cache_key); $primary = $this->Application->GetPrimaryCurrency(); - if ($rates === false) { + if ( $rates === false ) { $this->Conn->nextQueryCachable = true; $sql = 'SELECT ISO, RateToPrimary - FROM ' . $this->Application->getUnitOption('curr', 'TableName') . ' + FROM ' . $this->Application->getUnitConfig('curr')->getTableName() . ' WHERE Status = ' . STATUS_ACTIVE; $rates = $this->Conn->Query($sql); @@ -55,24 +55,23 @@ { $source_cur = ($source_cur == 'PRIMARY') ? $this->Application->GetPrimaryCurrency() : $source_cur; $target_cur = ($target_cur == 'PRIMARY') ? $this->Application->GetPrimaryCurrency() : $target_cur; - if($source_cur == $target_cur) - { + + if ( $source_cur == $target_cur ) { return 1; } - if($this->ExchangeRates[$target_cur]['TARGET'] == $source_cur) - { - $rate = ($this->ExchangeRates[$target_cur]['RATE'] == 0) ? false : 1 / $this->ExchangeRates[$target_cur]['RATE']; + if ( $this->ExchangeRates[$target_cur]['TARGET'] == $source_cur ) { + $rate = ($this->ExchangeRates[$target_cur]['RATE'] == 0) ? false : 1 / $this->ExchangeRates[$target_cur]['RATE']; } - elseif($this->ExchangeRates[$source_cur]['TARGET'] == $target_cur) - { + elseif ( $this->ExchangeRates[$source_cur]['TARGET'] == $target_cur ) { $rate = $this->ExchangeRates[$source_cur]['RATE']; } - else - { + else { $rate = ($this->ExchangeRates[$target_cur]['RATE'] == 0) ? false : $this->ExchangeRates[$source_cur]['RATE'] / $this->ExchangeRates[$target_cur]['RATE']; } + $rate *= $units; + return $rate; } @@ -93,7 +92,7 @@ $symbol_sql = 'IF(COALESCE(Symbol, "") = "", CONCAT(ISO, " "), Symbol)'; $sql = 'SELECT IF(SymbolPosition = 0, CONCAT(' . $symbol_sql . ', "%s"), CONCAT("%s", ' . $symbol_sql . ')), LOWER(ISO) AS ISO - FROM ' . $this->Application->getUnitOption('curr', 'TableName') . ' + FROM ' . $this->Application->getUnitConfig('curr')->getTableName() . ' WHERE Status = ' . STATUS_ACTIVE; $iso_masks = $this->Conn->GetCol($sql, 'ISO'); $this->Application->setCache($cache_key, $iso_masks); Index: branches/5.3.x/units/sections/section_eh.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/sections/section_eh.php (.../section_eh.php) (revision 15492) +++ branches/5.3.x/units/sections/section_eh.php (.../section_eh.php) (revision 15695) @@ -1,6 +1,6 @@ Application->getUnitOption($event->MasterEvent->Prefix, 'EditTabPresets'); - $edit_tab_presets['Default']['in-commerce'] = Array ( - 'title' => 'la_title_In-Commerce', 't' => 'in-commerce/site_domains/site_domain_edit', 'priority' => 2.1 - ); - $this->Application->setUnitOption($event->MasterEvent->Prefix, 'EditTabPresets', $edit_tab_presets); + $master_config = $event->MasterEvent->getUnitConfig(); - $title_presets = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'TitlePresets'); - $title_presets['site_domain_edit_in_commerce'] = Array ( - 'prefixes' => Array ('site-domain'), 'format' => "#site-domain_status# '#site-domain_titlefield#' - !la_title_In-Commerce!", - 'toolbar_buttons' => Array ('select', 'cancel', 'reset_edit', 'prev', 'next'), - ); - $this->Application->setUnitOption($event->MasterEvent->Prefix, 'TitlePresets', $title_presets); + $master_config->addEditTabPresetTabs('Default', Array ( + 'in-commerce' => Array ( + 'title' => 'la_title_In-Commerce', 't' => 'in-commerce/site_domains/site_domain_edit', 'priority' => 2.1 + ), + )); + + $master_config->addTitlePresets(Array ( + 'site_domain_edit_in_commerce' => Array ( + 'prefixes' => Array ('site-domain'), 'format' => "#site-domain_status# '#site-domain_titlefield#' - !la_title_In-Commerce!", + 'toolbar_buttons' => Array ('select', 'cancel', 'reset_edit', 'prev', 'next'), + ), + )); + + $new_fields = Array ( 'BillingCountry' => Array ( 'type' => 'string', 'max_len' => 3, @@ -78,20 +82,19 @@ ), ); - $fields = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'Fields'); - $this->Application->setUnitOption($event->MasterEvent->Prefix, 'Fields', array_merge($fields, $new_fields)); + $master_config->addFields($new_fields); + $new_columns = Array ( 'BillingCountry' => Array ('filter_block' => 'grid_options_filter', 'width' => 250, ), 'ShippingCountry' => Array ('filter_block' => 'grid_options_filter', 'width' => 250, ), 'PrimaryCurrencyId' => Array ('title' => 'column:la_fld_Currency', 'filter_block' => 'grid_options_filter', 'width' => 250, ), 'PrimaryPaymentTypeId' => Array ('title' => 'column:la_fld_PaymentType', 'filter_block' => 'grid_options_filter', 'width' => 250, ), ); - $grids = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'Grids'); - $grids['Default']['Fields'] = array_merge($grids['Default']['Fields'], $new_columns); - $this->Application->setUnitOption($event->MasterEvent->Prefix, 'Grids', $grids); + $master_config->addGridFields('Default', $new_columns); + if (!$this->Application->isAdmin && is_object($this->Application->siteDomain)) { // re-configure object, because it's recalled before kUnitConfigReader::AfterConfigRead is called $this->Application->siteDomain->Configure(); Index: branches/5.3.x/units/gateways/gw_tag_processor.php =================================================================== diff -u -r15671 -r15695 --- branches/5.3.x/units/gateways/gw_tag_processor.php (.../gw_tag_processor.php) (revision 15671) +++ branches/5.3.x/units/gateways/gw_tag_processor.php (.../gw_tag_processor.php) (revision 15695) @@ -1,6 +1,6 @@ Application->recallObject( $this->getPrefixSpecial(), $this->Prefix.'_List', $params); - $id_field = $this->Application->getUnitOption($this->Prefix,'IDField'); + $id_field = $this->getUnitConfig()->getIDField(); $list->Query(); $list->GoFirst(); Index: branches/5.3.x/units/affiliate_plans/affiliate_plans_event_handler.php =================================================================== diff -u -r15671 -r15695 --- branches/5.3.x/units/affiliate_plans/affiliate_plans_event_handler.php (.../affiliate_plans_event_handler.php) (revision 15671) +++ branches/5.3.x/units/affiliate_plans/affiliate_plans_event_handler.php (.../affiliate_plans_event_handler.php) (revision 15695) @@ -1,6 +1,6 @@ getObject(); /* @var $object kDBItem */ - $live_table = $this->Application->getUnitOption($event->Prefix, 'TableName'); + $config = $event->getUnitConfig(); + + $live_table = $config->getTableName(); $plans_count = $this->Conn->GetOne('SELECT COUNT(*) FROM ' . $live_table); + if ( !$plans_count ) { $object->SetDBField('IsPrimary', 1); } if ( $object->GetDBField('IsPrimary') && $object->Validate() ) { - $sql = 'UPDATE ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + $sql = 'UPDATE ' . $config->getTableName() . ' SET IsPrimary = 0'; $this->Conn->Query($sql); - $object->SetDBField($object->getStatusField(), 1); + $object->SetDBField($config->getStatusField(true), 1); } } @@ -111,10 +114,11 @@ protected function customProcessing(kEvent $event, $type) { if ( $event->Name == 'OnMassDelete' && $type == 'before' ) { + $config = $event->getUnitConfig(); $ids = $event->getEventParam('ids'); - $sql = 'SELECT ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . ' - FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + $sql = 'SELECT ' . $config->getIDField() . ' + FROM ' . $config->getTableName() . ' WHERE IsPrimary = 1'; $primary_id = $this->Conn->GetOne($sql); Index: branches/5.3.x/units/gateways/gw_classes/paybox.php =================================================================== diff -u -r15671 -r15695 --- branches/5.3.x/units/gateways/gw_classes/paybox.php (.../paybox.php) (revision 15671) +++ branches/5.3.x/units/gateways/gw_classes/paybox.php (.../paybox.php) (revision 15695) @@ -1,6 +1,6 @@ Conn->GetOne(' SELECT Email FROM '.$this->Application->getUnitOption('u', 'TableName').' + $billing_email = $this->Conn->GetOne(' SELECT Email FROM '.$this->Application->getUnitConfig('u')->getTableName().' WHERE PortalUserId = '.$this->Application->RecallVar('user_id')); } $params['PBX_PORTEUR'] = $billing_email; Index: branches/5.3.x/units/affiliate_plans_items/affiliate_plans_items_event_handler.php =================================================================== diff -u -r15492 -r15695 --- branches/5.3.x/units/affiliate_plans_items/affiliate_plans_items_event_handler.php (.../affiliate_plans_items_event_handler.php) (revision 15492) +++ branches/5.3.x/units/affiliate_plans_items/affiliate_plans_items_event_handler.php (.../affiliate_plans_items_event_handler.php) (revision 15695) @@ -1,6 +1,6 @@ MasterEvent->getObject(); - $resource_id = $main_object->GetDBField('ResourceId'); + /* @var $main_object kDBItem */ - $table = $this->Application->getUnitOption($event->Prefix,'TableName'); - $sql = 'DELETE FROM '.$table.' WHERE ItemResourceId = '.$resource_id; + $sql = 'DELETE FROM ' . $event->getUnitConfig()->getTableName() . ' + WHERE ItemResourceId = ' . $main_object->GetDBField('ResourceId'); $this->Conn->Query($sql); } @@ -83,12 +83,11 @@ { parent::OnAfterConfigRead($event); - $calculated_fields = $this->Application->getUnitOption($event->Prefix, 'CalculatedFields'); - $language_id = $this->Application->GetVar('m_lang'); $primary_language_id = $this->Application->GetDefaultLanguageId(); - $calculated_fields['']['ItemName'] = 'COALESCE(p.l' . $language_id . '_Name, p.l' . $primary_language_id . '_Name)'; - $this->Application->setUnitOption($event->Prefix, 'CalculatedFields', $calculated_fields); + $event->getUnitConfig()->addCalculatedFieldsBySpecial('', Array ( + 'ItemName' => 'COALESCE(p.l' . $language_id . '_Name, p.l' . $primary_language_id . '_Name)', + )); } } \ No newline at end of file