<?php
/**
  @licence GPL 2005-2010  The osCSS developers - osCSS Open Source E-commerce
  @portion code Copyright (c) 2002 osCommerce
  @package osCSS-2 <www http://www.oscss.org>
  @version 2.1.0
  @date  18/12/10, 11:21
  @author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
  @encode UTF-8
*/
  $saction = (isset($_GET['saction']) ? $_GET['saction'] : '');
  $tID = (isset($_GET['tID']) ? $_GET['tID'] : '');
  $trID = (isset($_GET['trID']) ? $_GET['trID'] : '');
  $page = (isset($page) ? $page : '1');
  $zpage = (isset($_GET['zpage']) ? $_GET['zpage'] : '1');


  switch ($saction) {
    case 'insert':
      $tax_zone_id = tep_db_prepare_input($_POST['tax_zone_id']);
      $tax_class_id = tep_db_prepare_input($_POST['tax_class_id']);
      $tax_rate = tep_db_prepare_input($_POST['tax_rate']);
      $tax_description = tep_db_prepare_input($_POST['tax_description']);
      $tax_priority = tep_db_prepare_input($_POST['tax_priority']);
      tep_db_query($sql="insert into " . TABLE_TAX_RATES . " (tax_zone_id, tax_class_id, tax_rate, tax_description, tax_priority, date_added) values ('" . (int)$tax_zone_id . "', '" . (int)$tax_class_id . "', '" . tep_db_input($tax_rate) . "', '" . tep_db_input($tax_description) . "', '" . tep_db_input($tax_priority) . "', now())");
      tep_redirect(tep_href_link(FILENAME_TAX_CLASSES, tep_get_all_get_params(array('saction'),false)));
      break;
    case 'save':
      $tax_rates_id = tep_db_prepare_input($_POST['tax_rates_id']);
      $tax_zone_id = tep_db_prepare_input($_POST['tax_zone_id']);
      $tax_class_id = tep_db_prepare_input($_POST['tax_class_id']);
      $tax_rate = tep_db_prepare_input($_POST['tax_rate']);
      $tax_description = tep_db_prepare_input($_POST['tax_description']);
      $tax_priority = tep_db_prepare_input($_POST['tax_priority']);

      tep_db_query($sql="update " . TABLE_TAX_RATES . " set tax_rates_id = '" . (int)$tax_rates_id . "', tax_zone_id = '" . (int)$tax_zone_id . "', tax_class_id = '" . (int)$tax_class_id . "', tax_rate = '" . tep_db_input($tax_rate) . "', tax_description = '" . tep_db_input($tax_description) . "', tax_priority = '" . tep_db_input($tax_priority) . "', last_modified = now() where tax_rates_id = '" . (int)$tax_rates_id . "'");

      tep_redirect(tep_href_link(FILENAME_TAX_CLASSES, tep_get_all_get_params(array('saction'),false). 'tax_class_id='.$tax_class_id));
    break;
    case 'deleteconfirm':
      $tax_rates_id = tep_db_prepare_input($trID);

      tep_db_query("delete from " . TABLE_TAX_RATES . " where tax_rates_id = '" . (int)$tax_rates_id . "'");

      tep_redirect(tep_href_link(FILENAME_TAX_CLASSES,  tep_get_all_get_params(array('saction','trID'),false)));
    break;
    default:
      $wh=(!empty($tID)? " and tc.tax_class_id = '".$tID."' " :"" );
      $rates_query_raw = "select r.tax_rates_id, z.geo_zone_id, z.geo_zone_name, tc.tax_class_title, tc.tax_class_id, r.tax_priority, r.tax_rate, r.tax_description, r.date_added, r.last_modified from " . TABLE_TAX_CLASS . " tc, " . TABLE_TAX_RATES . " r left join " . TABLE_GEO_ZONES . " z on r.tax_zone_id = z.geo_zone_id where r.tax_class_id = tc.tax_class_id ".$wh." ";
      $rates_split = new splitPageResults($page, MAX_DISPLAY_SEARCH_RESULTS, $rates_query_raw, $rates_query_numrows);
      $rates_query = tep_db_query($rates_query_raw);
      $list_c=array();
      while ($rates = tep_db_fetch_array($rates_query)) {
	if ( (isset($trID) && ($trID == $rates['tax_rates_id']))) {
	  $trInfo = new objectInfo($rates);
	}
	$list_c[]=$rates;
      }
  }



  switch ($action) {
    case 'insert':
      $tax_class_title = tep_db_prepare_input($_POST['tax_class_title']);
      $tax_class_description = tep_db_prepare_input($_POST['tax_class_description']);

      tep_db_query("insert into " . TABLE_TAX_CLASS . " (tax_class_title, tax_class_description, date_added) values ('" . tep_db_input($tax_class_title) . "', '" . tep_db_input($tax_class_description) . "', now())");

      tep_redirect(tep_href_link(FILENAME_TAX_CLASSES));
      break;
    case 'save':
      $tax_class_id = tep_db_prepare_input($_GET['tID']);
      $tax_class_title = tep_db_prepare_input($_POST['tax_class_title']);
      $tax_class_description = tep_db_prepare_input($_POST['tax_class_description']);

      tep_db_query("update " . TABLE_TAX_CLASS . " set tax_class_id = '" . (int)$tax_class_id . "', tax_class_title = '" . tep_db_input($tax_class_title) . "', tax_class_description = '" . tep_db_input($tax_class_description) . "', last_modified = now() where tax_class_id = '" . (int)$tax_class_id . "'");

      tep_redirect(tep_href_link(FILENAME_TAX_CLASSES, 'page=' . $_GET['page'] . '&tID=' . $tax_class_id));
      break;
    case 'deleteconfirm':
      $tax_class_id = tep_db_prepare_input($tID);

      tep_db_query("delete from " . TABLE_TAX_CLASS . " where tax_class_id = '" . (int)$tax_class_id . "'");

      tep_redirect(tep_href_link(FILENAME_TAX_CLASSES, 'page=' . $_GET['page']));
    break;
    case 'list':
    break;
    default:
      $classes_query_raw = "select tax_class_id, tax_class_title, tax_class_description, last_modified, date_added from " . TABLE_TAX_CLASS . " order by tax_class_title";
      $classes_split = new splitPageResults($_GET['page'], MAX_DISPLAY_SEARCH_RESULTS, $classes_query_raw, $classes_query_numrows);
      $classes_query = tep_db_query($classes_query_raw);
      $list_c=array();
      while ($classes = tep_db_fetch_array($classes_query)) {
	if ($tID == $classes['tax_class_id'])  $tcInfo = new objectInfo($classes);
	$list_c[]=$classes;
      }
  }

?>