<?php

ini_set('display_errors', '0');

if(!isset($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] != "on")
{
    header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"], true, 301);
    exit;
}

set_include_path('.' . PATH_SEPARATOR . './library' . PATH_SEPARATOR 
   . PATH_SEPARATOR . './application/models/'
   . PATH_SEPARATOR . get_include_path());

include "Zend/Loader.php";
require_once('tcpdf/tcpdf.php');
require_once('PHPMailer-master/class.phpmailer.php');    //dodanie klasy phpmailer
require_once('PHPMailer-master/class.smtp.php');    //dodanie klasy smtp


Zend_Loader::loadClass('Zend_Controller_Front');
Zend_Loader::loadClass('Zend_Controller_Router_Route');
Zend_Loader::loadClass('Zend_Controller_Router_Route_Regex');
Zend_Loader::loadClass('Zend_Controller_Router_Route_Static');
Zend_Loader::loadClass('Zend_Config_Ini');
Zend_Loader::loadClass('Zend_Registry');
Zend_Loader::loadClass('Zend_Session');
Zend_Loader::loadClass('Zend_Db');
Zend_Loader::loadClass('Zend_Db_Table');
Zend_Loader::loadClass('Zend_Form');
Zend_Loader::loadClass('Zend_Auth');
Zend_Loader::loadClass('Zend_Auth_Adapter_Interface');
Zend_Loader::loadClass('Zend_Auth_Adapter_DbTable');
Zend_Loader::loadClass('Zend_Acl');
Zend_Loader::loadClass('Zend_Form_Element_Text');
Zend_Loader::loadClass('Zend_Date');
Zend_Loader::loadClass('Zend_View');
Zend_Loader::loadClass('Zend_Debug');
Zend_Loader::loadClass('Zend_Pdf');
Zend_Loader::loadClass('Zend_File_Transfer_Adapter_Http');
Zend_Loader::loadClass('Zend_Mail');
Zend_Loader::loadClass('Zend_Json');
Zend_Loader::loadClass('Zend_Controller_Request_Http');
Zend_Loader::loadClass('Zend_Db_Adapter_Abstract');

// walidatory
Zend_Loader::loadClass('Zend_Validate');
Zend_Loader::loadClass('Zend_Validate_StringLength');
Zend_Loader::loadClass('Zend_Validate_Alpha');
Zend_Loader::loadClass('Zend_Validate_Alnum');
Zend_Loader::loadClass('Zend_Validate_EmailAddress');

Zend_Session::start();

Zend_Loader::loadFile('Admin.php');
Zend_Loader::loadFile('HistoryLog.php');
Zend_Loader::loadFile('Lang.php');
Zend_Loader::loadFile('Category.php');
Zend_Loader::loadFile('Product.php');
Zend_Loader::loadFile('ProductElement.php');
Zend_Loader::loadFile('ProductFieldname.php');
Zend_Loader::loadFile('ProductWidth.php');
Zend_Loader::loadFile('ProductDepth.php');
Zend_Loader::loadFile('ProductHeight.php');
Zend_Loader::loadFile('ProductShelfamount.php');
Zend_Loader::loadFile('ProductWysszerA.php');
Zend_Loader::loadFile('ProductWysszerB.php');
Zend_Loader::loadFile('ProductWysszerC.php');
Zend_Loader::loadFile('ProductWysszerD.php');
Zend_Loader::loadFile('ProductWysszerE.php');
Zend_Loader::loadFile('ProductBody.php');
Zend_Loader::loadFile('ProductFront.php');
Zend_Loader::loadFile('ProductType.php');
Zend_Loader::loadFile('ProductType2.php');
Zend_Loader::loadFile('ProductAccessories.php');
Zend_Loader::loadFile('ProductLegs.php');
Zend_Loader::loadFile('ProductHandles.php');
Zend_Loader::loadFile('ProductOptions.php');
Zend_Loader::loadFile('ProductLinked.php');
Zend_Loader::loadFile('Client.php');
Zend_Loader::loadFile('HistoryClientLog.php');
Zend_Loader::loadFile('Opinion.php');
Zend_Loader::loadFile('Order.php');
Zend_Loader::loadFile('OrderLog.php');
Zend_Loader::loadFile('OrderFile.php');
Zend_Loader::loadFile('OrderProduct.php');
Zend_Loader::loadFile('OrderProductLog.php');
Zend_Loader::loadFile('Content.php');
Zend_Loader::loadFile('Color.php');
Zend_Loader::loadFile('Newsletter.php');
Zend_Loader::loadFile('ColorSchema.php');
Zend_Loader::loadFile('ColorSchemaProductFront.php');
Zend_Loader::loadFile('ColorSchemaProductBody.php');
Zend_Loader::loadFile('ColorSchemaProductAccessories.php');
Zend_Loader::loadFile('ColorSchemaProductHandles.php');
Zend_Loader::loadFile('ColorSchemaProductType.php');
Zend_Loader::loadFile('ColorSchemaProductType2.php');
Zend_Loader::loadFile('SchemaProduct.php');
Zend_Loader::loadFile('SchemaProductAccessories.php');
Zend_Loader::loadFile('SchemaProductHandles.php');
Zend_Loader::loadFile('PayRaport.php');
Zend_Loader::loadFile('TypePack.php');
Zend_Loader::loadFile('TypeTransport.php');
Zend_Loader::loadFile('TypeLeadTime.php');
Zend_Loader::loadFile('Voucher.php');
Zend_Loader::loadFile('Config.php');

Zend_Loader::loadFile('MapFiltrBody.php');
Zend_Loader::loadFile('MapFiltrFront.php');

Zend_Loader::loadClass('Lib_Lang');
Zend_Loader::loadClass('Lib_Page');
Zend_Loader::loadClass('Lib_Date');
Zend_Loader::loadClass('Lib_Permission');
Zend_Loader::loadClass('Lib_Category');
Zend_Loader::loadClass('Lib_Color');
Zend_Loader::loadClass('Lib_Code');
Zend_Loader::loadClass('Lib_Link');
Zend_Loader::loadClass('Lib_Basket');
Zend_Loader::loadClass('Lib_Equation');
Zend_Loader::loadClass('Lib_Product');
Zend_Loader::loadClass('Lib_Export');
/*
if( $_GET['test'] == true ) $_SESSION['test'] = true;
if( $_SESSION['test'] != true ) Zend_Loader::loadClass('Lib_SumOrder');
*/
// load configuration [general]
$config = new Zend_Config_Ini('./application/config/config.ini.php','general');
$registry = Zend_Registry::getInstance();
$registry->set('config', $config);
$registry->set('last_ref', time());
$registry->set('users_ip',$_SERVER['REMOTE_ADDR']);
$registry->set('users_host',gethostbyaddr($_SERVER['REMOTE_ADDR']));

define('WWW_PATH', $config->app->wwwpath);
define('VERSION', $config->app->version);
define('LANGDEF', $config->app->lang);

define('PAY_pos_id', $config->pay->pos_id);
define('PAY_key', $config->pay->key);
define('PAY_key2', $config->pay->key2);
define('PAY_pos_auth_key', $config->pay->pos_auth_key);


define('MAIL_EMAIL', $config->mail->email);
define('MAIL_EMAILNAME', $config->mail->emailname);
define('MAIL_LOGIN', $config->mail->login);
define('MAIL_PASS', $config->mail->pass);
define('MAIL_HOST', $config->mail->host);

// setup database
$db = Zend_Db::factory( $config->db->adapter, $config->db->config->toArray() );
$registry->set('db', $db);
Zend_Db_Table::setDefaultAdapter($db);
try {
	$db->query('SET NAMES \'utf8\'');
} catch (Exception $e) {
	echo $e->getMessage();
}

Lib_Lang::Lang();

$frontController = Zend_Controller_Front::getInstance();
$frontController->setControllerDirectory('./application/controllers');

$router = $frontController->getRouter(); 

$route = new Zend_Controller_Router_Route_Regex(
    '([0-9]+),([-a-z0-9]+).html',
    array('controller' => 'product', 'action' => 'index'),
    array(1=>'id',2=>'productname'),
    '%s,%s.html'
);
$router->addRoute('product',$route); 


$frontController->dispatch();


