<?php
/**
 * Showing the page
 */

//Defining the template
$template	= new Template( $page );

//Defining the meta
$meta		= ( defined( 'METADATA_HOME' ) ) ? METADATA_HOME : null;

//Including the template's variables
require( BASE_DIR . '/include/variables.php' );

//Product's category
try{

	//Defining
	$records	= ListController::orderly( 'product-category', 'name' );

	//Checking
	if( !is_null( $records ) )
		//Listing
		foreach( $records as $record ){

			//Defining the object to template
			$template->OBJ_PRODUCT_CATEGORY	= $record;

			//Defining the products
			$products						= ListController::byCategoryOrderly( 'product', $record->id );

			//Checking
			if( !is_null( $products ) )
				//Listring
				foreach( $products as $product ){

					//Defining the object to template
					$template->OBJ_PRODUCT_WITH_CATEGORY	= $product;

					//Showing the block
					$template->block( 'PRODUCT_WITH_CATEGORY' );

				}

			//Showing the block
			$template->block( 'PRODUCT_CATEGORY' );

		}

	//Defining
	$records	= ListController::orderly( 'service', 'name' );

	//Checking
	if( !is_null( $records ) )
		//Listing
		foreach( $records as $record ){

			//Defining the object to template
			$template->OBJ_SERVICE_SELECT	= $record;

			//Showing the block
			$template->block( 'SERVICE_SELECT' );

		}

}catch( Exception $e ){}

//Banner
try{

	//Defining
	$records	= ListController::orderly( 'banner', 'sequence' );

	//Listing
	foreach( $records as $record ){

		//Defining the object to template
		$template->OBJ_BANNER	= $record;

		//Showing the block
		$template->block( 'BANNER' );

	}

}catch( Exception $e ){}

//Product
try{

	//Defining
	$records	= ListController::orderlyByQuantity( 'product', 'random' );

	//Listing
	foreach( $records as $record ){

		//Defining the object to template
		$template->OBJ_PRODUCT					= $record;

		//Defining the small description to template
		$template->PRODUCT_SMALL_DESCRIPTION	= Util::defineDescription( $record->small_description, 17 );

		//Showing the block
		$template->block( 'PRODUCT' );

	}

}catch( Exception $e ){}

//Service
try{

	//Defining
	$records	= ListController::orderlyByQuantity( 'service', 'random' );

	//Listing
	foreach( $records as $record ){

		//Defining the object to template
		$template->OBJ_SERVICE					= $record;

		//Defining the small description to template
		$template->SERVICE_SMALL_DESCRIPTION	= Util::defineDescription( $record->small_description, 20 );

		//Showing the block
		$template->block( 'SERVICE' );

	}

}catch( Exception $e ){}

//Defining some variables
$template->BASE_URL_REPOSITORY	= BASE_URL_REPOSITORY;
$template->SOURCE_SITE_HOME		= SOURCE_SITE_HOME;

//Showing the page
$template->show();