<?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.0.9
 *\date  16/06/10, 08:11
 *\author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
 *\encode UTF-8
 *\file redirect.php
 *\brief page de redirection
*/
  require('includes/application_top.php');

  $page->init(basename(__FILE__),$language);
  $page->post_init(false);
  //! Control origin demande
  if($_SERVER['SERVER_NAME'] == basename(HTTP_SERVER) && isset($_GET['action']))

  switch ($_GET['action']) {
    case 'banner':
      $banner_query = $DB->query("select banners_url from " . TABLE_BANNERS . " where banners_id = '" . (int)$_GET['goto'] . "'");
      if ($banner_query->__get('NumRows')>0) {
        $banner = $banner_query->fetchAssoc();
        banner::tep_update_banner_click_count($_GET['goto']);

        tep_redirect($banner['banners_url']);
      }
      break;

    case 'url':
      if (isset($_GET['goto']) && tep_not_null($_GET['goto'])) {
        $goto = tep_db_prepare_input($_GET['goto']);
        $product_query = $DB->query("select products_url from " . TABLE_PRODUCTS_DESCRIPTION . " where products_url = '" . tep_db_input($goto) . "'");
        if ($product_query->__get('NumRows')>0) {
         tep_redirect('http://' . $goto);
       } else {
         tep_redirect(tep_href_link(FILENAME_DEFAULT));
       }
      }
      break;

    case 'manufacturer':
      if (isset($_GET['manufacturers_id']) && tep_not_null($_GET['manufacturers_id'])) {
        $manufacturer_query = $DB->query("select manufacturers_url from " . TABLE_MANUFACTURERS_INFO . " where manufacturers_id = '" . (int)$_GET['manufacturers_id'] . "' and languages_id = '" . (int)$languages_id . "'");
        if ($manufacturer_query->__get('NumRows')>0) {
// url exists in selected language
          $manufacturer = tep_db_fetch_array($manufacturer_query);

          if (tep_not_null($manufacturer['manufacturers_url'])) {
            $DB->query("update " . TABLE_MANUFACTURERS_INFO . " set url_clicked = url_clicked+1, date_last_click = now() where manufacturers_id = '" . (int)$_GET['manufacturers_id'] . "' and languages_id = '" . (int)$languages_id . "'");

            tep_redirect($manufacturer['manufacturers_url']);
          }
        } else {
// no url exists for the selected language, lets use the default language then
          $manufacturer_query = $DB->query("select mi.languages_id, mi.manufacturers_url from " . TABLE_MANUFACTURERS_INFO . " mi, " . TABLE_LANGUAGES . " l where mi.manufacturers_id = '" . (int)$_GET['manufacturers_id'] . "' and mi.languages_id = l.languages_id and l.code = '" . DEFAULT_LANGUAGE . "'");
          if ($manufacturer_query->__get('NumRows')>0) {
            $manufacturer = $manufacturer_query->fectAssoc();

            if (tep_not_null($manufacturer['manufacturers_url'])) {
              $DB->query("update " . TABLE_MANUFACTURERS_INFO . " set url_clicked = url_clicked+1, date_last_click = now() where manufacturers_id = '" . (int)$_GET['manufacturers_id'] . "' and languages_id = '" . (int)$manufacturer['languages_id'] . "'");

              tep_redirect($manufacturer['manufacturers_url']);
            }
          }
        }
      }
      break;
  }

  tep_redirect(tep_href_link(FILENAME_DEFAULT));
?>