<?php

	define('IN_HUGLO', true);
	require_once('./common.php');
	require_once(ROOT_PATH . 'includes/menu_actualites.php');

	$actualites = array();

	$category_id = isset($_GET['category_id']) ? (is_numeric($_GET['category_id']) ? $_GET['category_id'] : 0) : 0;
	$actualites_id = isset($_GET['actualites_id']) ? (is_numeric($_GET['actualites_id']) ? $_GET['actualites_id'] : 0) : 0;
	
	if($category_id == 0) {
		$sql = 'SELECT category_id FROM ' . CATEGORY_TABLE . ' WHERE category_is = 0 AND category_parent_id IN (5,30) ORDER BY category_sort ASC';
		$result = mysql_query($sql);
		$row = mysql_fetch_assoc($result);
		mysql_free_result($result);
		$category_id = $row['category_id'];
	}

	$sql = 'SELECT c2.category_id, c2.category_parent_id, c1.category_name_fr , c2.category_name_fr AS category_s_name_fr, c1.category_name_en , c2.category_name_en AS category_s_name_en, c2.category_bg_img, c2.category_bg_color FROM ' . CATEGORY_TABLE . ' c1 LEFT JOIN ' . CATEGORY_TABLE . ' c2 ON c2.category_parent_id = c1.category_id WHERE c2.category_id = ' . $category_id;
	$result = mysql_query($sql);
	$category = mysql_fetch_assoc($result);
	mysql_free_result($result);

	$sql = 'SELECT * FROM ' . ACTUALITES_TABLE . ' WHERE category_id = ' . $category_id . ' ORDER BY actualites_datetime DESC';
	$result = mysql_query($sql);
	while($row = mysql_fetch_assoc($result)) {
		$actualites[$row['actualites_id']] = array(
			'category_id'			=>	$row['category_id'],
			'actualites_datetime'	=>	$row['actualites_datetime'],
			'actualites_title_fr'	=>	$row['actualites_title_fr'],
			'actualites_title_en'	=>	$row['actualites_title_en'],
			'actualites_text_fr'	=>	$row['actualites_text_fr'],
			'actualites_text_en'	=>	$row['actualites_text_en'],
			'actualites_flv'		=>	$row['actualites_flv']
		);
	}
	mysql_free_result($result);
	
	foreach($actualites as $key => $value) {
		$template->assign_block_vars('acturow', array(
			'U_LINK'		=>	BASE_PATH . '/actualites.php?category_id=' . $value['category_id'] . '&amp;actualites_id=' . $key,
			'T_TITLE'		=>	$value['actualites_title_' . $l],
			'V_SELECTED'	=>	($actualites_id == $key) ? true : false
		));
	}

	$template->assign_vars(array(
		'T_ACTU'			=>	isset($actualites[$actualites_id]) ? $actualites[$actualites_id]['actualites_text_' . $l] : '',
		'V_NFLV'			=>	isset($actualites[$actualites_id]) ? (($actualites[$actualites_id]['actualites_flv']) ? true : false) : false,
		'T_FLV'				=>	isset($actualites[$actualites_id]) ? $actualites[$actualites_id]['actualites_flv'] : '',

		'T_ACTU_NAME'		=>	$category['category_name_' . $l] . ' - ' . $category['category_s_name_' . $l],
		'T_NAME_PAGE'		=>	$category['category_s_name_' . $l] . ' - ' . $category['category_name_' . $l],
		'V_C_NAME'			=>	$category['category_name_' . $l],
		'V_BG'				=>	true,
		'V_BG_IMG'			=>	$category['category_bg_img'],
		'V_BG_COLOR'		=>	$category['category_bg_color'],
	));

	$template->set_filenames(array('body' => 'view_actualites.html'));
	$template->display('body');

	unset($actualites);
	$db->sql_close();

?>
