<?php
/**
 @licence GPL 2005-2009  The osCSS developers - osCSS Open Source E-commerce
  @package oscss-2 <www http://www.oscss.org>
  @version Rc-3
  @date  08/04/10, 22:41
  @author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
   @encode UTF-8
*/

   $rID=(isset($_GET['rID'])) ? $_GET['rID'] : '';
   $cID=(isset($_GET['cID'])) ? $_GET['cID'] : '';

  $saction=(isset($_GET['saction'])) ? $_GET['saction'] : '';


    switch ($action) {
      case 'insert':
        $countries_name = tep_db_prepare_input($_POST['countries_name']);
		$countries_localname = tep_db_prepare_input($_POST['countries_localname']);
        $countries_iso_code_2 = tep_db_prepare_input($_POST['countries_iso_code_2']);
        $countries_iso_code_3 = tep_db_prepare_input($_POST['countries_iso_code_3']);
        $address_format_id = tep_db_prepare_input($_POST['address_format_id']);
		$country_visible = tep_db_prepare_input($_POST['country_visible']);

        tep_db_query("insert into " . TABLE_COUNTRIES . " (countries_name, countries_localname, countries_iso_code_2, countries_iso_code_3, address_format_id, country_visible) values ('" . tep_db_input($countries_name) . "', '" . tep_db_input($countries_localname) . "', '" . tep_db_input($countries_iso_code_2) . "', '" . tep_db_input($countries_iso_code_3) . "', '" . (int)$address_format_id . "', '" . (int)$country_visible . "')");

        tep_redirect(tep_href_link(FILENAME_COUNTRIES));
        break;

	case 'update':
        $countries_id = tep_db_prepare_input($_GET['cID']);
		$country_visible = tep_db_prepare_input($_GET['country_visible']);

        tep_db_query("update " . TABLE_COUNTRIES . " set country_visible = '" . (int)$country_visible . "' where countries_id = '" . (int)$countries_id . "'");

        tep_redirect(tep_href_link(FILENAME_COUNTRIES, 'page=' . $_GET['page'] . '&cID=' . $countries_id.'&row_by_page='.$row_by_page));
        break;


      case 'save':
        $countries_id = tep_db_prepare_input($_GET['cID']);
        $countries_name = tep_db_prepare_input($_POST['countries_name']);
		$countries_localname = tep_db_prepare_input($_POST['countries_localname']);
        $countries_iso_code_2 = tep_db_prepare_input($_POST['countries_iso_code_2']);
        $countries_iso_code_3 = tep_db_prepare_input($_POST['countries_iso_code_3']);
        $address_format_id = tep_db_prepare_input($_POST['address_format_id']);
		$country_visible = tep_db_prepare_input($_POST['country_visible']);

        tep_db_query("update " . TABLE_COUNTRIES . " set countries_name = '" . tep_db_input($countries_name) . "', countries_localname = '" . tep_db_input($countries_localname) . "', countries_iso_code_2 = '" . tep_db_input($countries_iso_code_2) . "', countries_iso_code_3 = '" . tep_db_input($countries_iso_code_3) . "', address_format_id = '" . (int)$address_format_id . "', country_visible = '" . (int)$country_visible . "' where countries_id = '" . (int)$countries_id . "'");

        tep_redirect(tep_href_link(FILENAME_COUNTRIES, 'page=' . $_GET['page'] . '&cID=' . $countries_id.'&row_by_page='.$row_by_page));
        break;
      case 'deleteconfirm':
        $countries_id = tep_db_prepare_input($_GET['cID']);

        tep_db_query("delete from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$countries_id . "'");

        tep_redirect(tep_href_link(FILENAME_COUNTRIES, 'page=' . $_GET['page'].'&row_by_page='.$row_by_page));
      break;
      case 'list':
      break;
      default:

	$countries_query_raw = "select countries_id, countries_name, countries_localname, countries_iso_code_2, countries_iso_code_3, address_format_id, country_visible from " . TABLE_COUNTRIES . " order by ".((isset($_GET['sort_by'])) ? $_GET['sort_by'] : 'countries_name ASC, country_visible DESC');
	$countries_split = new splitPageResults($page, MAX_DISPLAY_ROW_BY_PAGE, $countries_query_raw, $countries_query_numrows);
	$countries_query = tep_db_query($countries_query_raw);
	$list_c=array();
	while ($countries = tep_db_fetch_array($countries_query)) {
	  if ($cID == $countries['countries_id']) $cInfo = new objectInfo($countries);
	  $list_c[]=$countries;
	}

}

    switch ($saction) {
      case 'insert':
        $zone_country_id = tep_db_prepare_input($_POST['zone_country_id']);
        $zone_code = tep_db_prepare_input($_POST['zone_code']);
        $zone_name = tep_db_prepare_input($_POST['zone_name']);

        tep_db_query("insert into " . TABLE_ZONES . " (zone_country_id, zone_code, zone_name) values ('" . (int)$zone_country_id . "', '" . tep_db_input($zone_code) . "', '" . tep_db_input($zone_name) . "')");

        tep_redirect(tep_href_link(FILENAME_ZONES, 'page=' . $_GET['page'].'&row_by_page='.$row_by_page));
        break;
      case 'save':
        $zone_id = tep_db_prepare_input($_GET['cID']);
        $zone_country_id = tep_db_prepare_input($_POST['zone_country_id']);
        $zone_code = tep_db_prepare_input($_POST['zone_code']);
        $zone_name = tep_db_prepare_input($_POST['zone_name']);

        tep_db_query("update " . TABLE_ZONES . " set zone_country_id = '" . (int)$zone_country_id . "', zone_code = '" . tep_db_input($zone_code) . "', zone_name = '" . tep_db_input($zone_name) . "' where zone_id = '" . (int)$zone_id . "'");

        tep_redirect(tep_href_link(FILENAME_ZONES, 'page=' . $_GET['page'] . '&cID=' . $zone_id.'&row_by_page='.$row_by_page));
        break;
      case 'deleteconfirm':
        $zone_id = tep_db_prepare_input($_GET['cID']);

        tep_db_query("delete from " . TABLE_ZONES . " where zone_id = '" . (int)$zone_id . "'");

        tep_redirect(tep_href_link(FILENAME_ZONES, 'page=' . $_GET['page'].'&row_by_page='.$row_by_page));
      break;
      default:
	  $wh=(tep_not_null($cID)? " and z.zone_country_id = '".$cID."' ":'');
          $zones_query_raw = "select z.zone_id, c.countries_id, c.countries_name, z.zone_name, z.zone_code, z.zone_country_id from " . TABLE_ZONES . " z, " . TABLE_COUNTRIES . " c where z.zone_country_id = c.countries_id ".$wh."  order by ".((isset($_GET['sort_by'])) ? $_GET['sort_by'] : 'c.countries_name, z.zone_name ASC');
          $zones_split = new splitPageResults($page, MAX_DISPLAY_ROW_BY_PAGE, $zones_query_raw, $zones_query_numrows);
          $zones_query = tep_db_query($zones_query_raw);
          $list_z=array();
          while ($zones = tep_db_fetch_array($zones_query)) {
            if ($rID == $zones['zone_id']) $cInfo = new objectInfo($zones);
            $list_z[]=$zones;
          }
//       break;
    }

?>