<?php


// @todo: delete me

/*
function translate_template($template, $values) {
	foreach($values as $key => $value){
		$template->set( $key, $value );
	}
	
	return $template->output();
}
*/

// @todo: re-think about me...and me smart!
/**
 * hide and disable a given menu by name.
 * 
 * @param string $menu_name name used to identify a unic menu
 * @param object $template template used for theming the menu
 * 
 * @return boolean true if successful
 * 
 * @link http://www.oldauntie.org
 * @author Maggie Marple <oldauntie@oldauntie.org>
 * @version 1.0
 */
function empty_themed_menu($menu_name, $template){
	$con = new Connection();
	
	$sSQL = "SELECT DISTINCT(item) FROM menu 
					WHERE NAME = '".$menu_name."'";
	
	$rs = $con->execute($sSQL);
					
	if( empty($rs) == false && is_array($rs) ){
		
		foreach($rs as $row){
			$key 			= 'menu-'.$menu_name.'-item-'.$row['item'];
			$template->set( $key, '' );
			$template->set($key.'-style', 'display: none;' );
			$template->set($key.'-url', '#' );
		}
		
		return true;
	}
	
	return false;
}




/**
 * Given a template menu file create a translated menu according to user role id (rid).
 * 
 * @param string $menu_name name used to identify a unic menu
 * @param int $rid role id of user
 * @param object $template template used for theming the menu
 * @param object $translation array of translated menu item
 * 
 * @return object $template return a themed template
 * 
 * @link http://www.oldauntie.org
 * @author Maggie Marple <oldauntie@oldauntie.org>
 * @version 1.0
 */
function build_themed_menu ( $menu_name, $rid, $template ){
	empty_themed_menu($menu_name, $template);
	
	
	$con = new Connection();
	
	$sql = "SELECT * FROM menu 
					WHERE NAME = '".$menu_name."' 
					AND RID >= '".$rid."' 
					ORDER BY WEIGHT ASC";

	$rs = $con->execute( $sql );
	

	if ( empty( $rs ) == false && is_array( $rs ) ){
		foreach( $rs as $row ){
			$key = 'menu-'.$menu_name.'-item-'.$row['item'];
			$template->set( $key, _($row['item']) );
			$template->set($key.'-url', $row['url'] );
			$template->set($key.'-style', 'display: block;' );
		}
	}
	return $template;
}


function template_common_header() {
	$sRV = '
		<!DOCTYPE html>
		<html>
		<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
		<meta name="description" content="">
		<meta name="author" content="">
		<link rel="icon" href="../../favicon.ico">
		
		<title>Ozzy Template for Ababu</title>
		
		<!-- CSS files order determines the override -->
		<!-- Bootstrap core CSS -->
		<link href="assets/css/bootstrap.min.css" rel="stylesheet">
		<link href="assets/css/jquery.dataTables.min.css" rel="stylesheet">
		<link href="assets/css/bootstrap-datepicker3.css" rel="stylesheet">
		<link href="' . _DEFAULT_THEME_PATH . _DEFAULT_THEME . '/styles.css" rel="stylesheet">

		
		<script type="text/javascript" src="assets/js/jquery-2.2.3.min.js"></script>
		<script type="text/javascript" src="assets/js/bootstrap.min.js"></script>
		<script type="text/javascript" src="assets/js/jquery.dataTables.min.js"></script>
		<script type="text/javascript" src="assets/js/bootstrap-snippets.js"></script>
		<script type="text/javascript" src="assets/js/bootbox.min.js"></script>
		<script type="text/javascript" src="assets/js/typeahead.bundle.js"></script>
		<script type="text/javascript" src="assets/js/bootstrap-datepicker.js"></script>
		<script type="text/javascript" src="assets/js/parsley/parsley.js"></script>
		<script type="text/javascript" src="assets/js/common.logic.js"></script>
		</head>';
	return $sRV;
}
function template_common_footer() {
	$sRV = '</html>';
	return $sRV;
}
