Index: branches/5.1.x/units/taxes/taxes_tag_processor.php
===================================================================
diff -u -N -r13147 -r13465
--- branches/5.1.x/units/taxes/taxes_tag_processor.php (.../taxes_tag_processor.php) (revision 13147)
+++ branches/5.1.x/units/taxes/taxes_tag_processor.php (.../taxes_tag_processor.php) (revision 13465)
@@ -1,6 +1,6 @@
Application->recallObject('tax');
- $zone->SetDBField('TaxZoneId', $zone->ID);
- $destination =& $this->Application->recallObject('taxdst');
+ $object =& $this->getObject($params);
+ /* @var $object kDBItem */
- if(!$this->Application->GetVar('loaded'))
- {
- if ($zone->GetID() == 0)
- {
- $this->Application->DeleteVar('taxdst');
- }
- else
- {
- $sql = 'SELECT * FROM '.$destination->TableName.' WHERE TaxZoneId='.$zone->GetID();
- $res = $this->Conn->Query($sql);
- if (is_array($res)) foreach ($res as $dest_record)
- {
- $temp[$dest_record['TaxZoneDestId']]['TaxZoneDestId'] = $dest_record['TaxZoneDestId'];
- $temp[$dest_record['TaxZoneDestId']]['StdDestId'] = $dest_record['StdDestId'];
- $temp[$dest_record['TaxZoneDestId']]['DestValue'] = $dest_record['DestValue'];
- }
- $this->Application->SetVar('taxdst', $temp);
- }
- }
- $destination =& $this->Application->recallObject('taxdst');
+ $destination_table = $this->getDestinationsTable($params);
+ $selected_country_id = (int)$this->Application->GetVar('CountrySelector');
- $hidden_clause = '';
+ $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');
- switch ( $zone->GetDBField('Type') )
- {
- case 1:
+ switch ($params['show']) {
+ case 'current':
+ // selected countries in current zone
+ $sql = 'SELECT cs.' . $name_field . ', cs.' . $id_field . '
+ FROM ' . $table_name . ' cs
+ LEFT JOIN ' . $destination_table . ' zd ON zd.StdDestId = cs.' . $id_field . '
+ WHERE cs.Type = ' . DESTINATION_TYPE_COUNTRY . ' AND zd.TaxZoneId = ' . $object->GetID() . '
+ ORDER BY cs.' . $name_field;
+ break;
- $sql = 'SELECT * FROM '.TABLE_PREFIX.'StdDestinations WHERE DestType=1';
- $res = $this->Conn->Query($sql, 'DestId');
-
- $dropdown = ''."\n";
-
- $form_params = Array();
- $form_params['dropdown'] = $dropdown;
- $form_params['block'] = $param['block'];
- $form_params['res'] = $res;
- $ret = $this->ShowDestionationForm($form_params);
+ case 'available':
+ // available countries in current zone
+ $sql = 'SELECT cs.' . $name_field . ', cs.' . $id_field . '
+ FROM ' . $table_name . ' cs
+ LEFT JOIN ' . $destination_table . ' zd ON zd.StdDestId = cs.' . $id_field . '
+ WHERE cs.Type = ' . DESTINATION_TYPE_COUNTRY . ' AND zd.TaxZoneId IS NULL
+ ORDER BY cs.' . $name_field;
break;
- case 2:
- $country_sql = 'SELECT d1.* FROM '.TABLE_PREFIX.'StdDestinations d1,
- '.TABLE_PREFIX.'StdDestinations d2
- WHERE d1.DestType=1 AND d1.DestId=d2.DestParentId
- GROUP BY d1.DestId';
- if( !($current_country = $this->Application->GetVar('StatesCountry')) )
- {
- $current_country_sql = 'SELECT sd.DestParentId FROM '.TABLE_PREFIX.'StdDestinations sd
- LEFT JOIN '.$destination->TableName.' zd
- ON zd.StdDestId = sd.DestId
- WHERE sd.DestType=2 AND zd.TaxZoneId='.$zone->GetDBField('TaxZoneId');
- if($zone->GetDBField('TaxZoneId'))
- {
- $current_country = $this->Conn->GetOne($current_country_sql);
- }
+ case 'all':
+ // always preselect 1st country, when user haven't selected any
+ if (!$selected_country_id) {
+ $sql = 'SELECT StdDestId
+ FROM ' . $destination_table . '
+ WHERE TaxZoneId = ' . $object->GetID();
+ $selected_country_id = $this->Conn->GetOne($sql);
- if(!$current_country)
- {
- $current_country_sql = 'SELECT DestId FROM '.TABLE_PREFIX.'StdDestinations WHERE DestType=1';
- $current_country = $this->Conn->GetOne($current_country_sql);
+ if ($selected_country_id) {
+ $this->Application->SetVar('CountrySelector', $selected_country_id);
}
}
- $states_sql = 'SELECT * FROM '.TABLE_PREFIX.'StdDestinations WHERE DestType=2 AND DestParentId='.$current_country;
- $countries = $this->Conn->Query($country_sql, 'DestId');
- $states = $this->Conn->Query($states_sql, 'DestId');
- if($countries)
- {
- $countries_dropdown = ''."\n";
- }
-
- if($states)
- {
- $states_dropdown = ''."\n";
- }
-
- $form_params = Array();
- $table = '
| ';
- $ret .= '';
-
- $ret .= ' | ';
- $ret .= $hidden;
- $ret .= " |
";
- }else{
-
- }
+ $ret .= $this->Application->ParseBlock($block_params);
}
-//