<?php
// Reporting E_NOTICE to report uninitialized
// variables or catch variable name misspellings ...
//error_reporting (E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

require 'inc/lang.php';
require 'inc/db.php';
require_once 'inc/http_build_query.php';

// session_start();

initiateLang($_GET['lang']);

if (is_int($_GET['entry'])) {
	$entry = $_GET['entry'];
}

if ($_POST['action'] == "addComment") {

	$httpQuery = $_GET;
	$httpQuery['msg'] = urlencode("It worked!");
	header('location:' . addLang($_SERVER['PHP_SELF'] . "?" . http_build_query($httpQuery)));
	exit;
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>

<HEAD>

<link rel="stylesheet" title="Base stylesheet" href="base.css">
<TITLE><?= translate("Welcome to Francis Provencher's homepage", "Bienvenu chez Francis Provencher")?></TITLE>
<link rel="shortcut icon" href="/favicon.png" type="image/png">

</HEAD>

<BODY STYLE="background:#FF9933">


<!-- Main title -->

<table ALIGN="LEFT">
<tr>
<TD valign="top">

<!-- Left section -->

<table align="left">
<tr>
<td HEIGHT="80" valign="top">
<h2><?= translate("Welcome to Darkfox's mansion", "Bienvenue dans l'antre du renard de l'ombre!") ?></h2>
<i><?= translate("Francis Provencher's homepage", "La page de Francis Provencher") ?></i>
</TD>
</TR>

<tr>
<td valign="top">

<!-- Main -->
<?php
if ($_GET['msg']) {
	?>
	<h3><?= htmlspecialchars($_GET['msg'])?></h3>	
	<?php
}
if ($entry) {
	?>
	<h4><a href="<?= addLang("index.php") ?>"><?= translate("Back to top", "Retour a la page principale") ?></a></h4>
	<?php
}

// Performing SQL query
$query = "SELECT id, title_$lang as title, text_$lang as blogtext, postdate FROM blog";
$query .= " WHERE NOT isNull(title_$lang) ";
if ($entry) {
	$sqlEntry = mysql_escape_string($entry);
	$query .= " AND id = $sqlEntry ";
}
$query .= " ORDER BY postdate desc";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

while ($row = mysql_fetch_assoc($result)) {
	?>

	<!-- News item -->
	<h3><a name="entry<?= $row["id"] ?>"></a><?= $row["title"] ?></h3>
	<div class="subtitled">
	<a href="mailto:francis@TZoNE.org" class="subtitled">francis@TZoNE.org</a> - <?= $row["postdate"] ?> EST
	</div>
	<?= $row["blogtext"] ?>
	<div class="feedback">
	<?php 
	if (!$entry) {
		$queryComments = "SELECT count(commentId) as countId FROM blogComment WHERE commentEnable='y' AND blogId = '".$row["id"]."' GROUP BY blogId ";
		$resultComments = mysql_query($queryComments) or die('Query failed: ' . mysql_error());
		$rowComments = mysql_fetch_assoc($resultComments);
		if ($rowComments) {
			$rowCount = $rowComments["countId"];
		} else {
			$rowCount = 0;
		}
		?>
		<a href="<?= addLang("index.php?entry=" . $row["id"]) ?>" class="feedback"><?= translate("Comments", "Commentaires"). " ($rowCount)" ?></a>
		<?php
	}
	?>
	</div>
	<!-- End of News item -->

	<?php
	if ($entry) {
		//session_start();
		?>
		<table align="left" border="0">	
		<tr>
		<td>
		<!--
		<h3><?= translate("Comments:", "Commentaires:") ?></h3>
		<div class="subtitled"><a href="#add"><?= translate("Add a comment", "Ajoutez un commentaire") ?></a></div>
		-->
		</td>
		</tr>

		<?php
		$queryComments = "SELECT * FROM blogComment WHERE commentEnable='y' AND blogId = '".$row["id"]."' ORDER BY commentDate DESC ";
		$resultComments = mysql_query($queryComments) or die('Query failed: ' . mysql_error());
		while ($rowComments = mysql_fetch_assoc($resultComments)) {
			?>
			
			<tr>
			<td>
			<h4><?= $rowComments["commentTitle"] ?></h3>
			<div class="subtitled">
			<?= $rowComments["fromName"] . " - " . $rowComments["commentDate"] ?> EST
			</div>
			<?= $rowComments["commentText"] ?>
			<div class="feedback"></div>
			</td>
			</tr>
			<?php
		}
		?>
		<tr>
		<td>
		<!-- Comment form -->
	
		<!-- <form action="<?= addLang($_SERVER['PHP_SELF'] . "?" . http_build_query($_GET)) ?>" method="post"> -->
		<!--
		<form action="do.php" method="post"> 
		<input type="hidden" name="action" value="addComment" />
		<input type="hidden" name="lang" value="<?= $lang ?>" />
		<input type="hidden" name="entry" value="<?= $entry ?>" />
		<a name="add"></a>
		<table border="0">

		<tr>
		<td colspan="2">
		<h4><?= translate("Add a comment", "Ajouter un commentaire") ?></h4>
		<div class="subtitled"><?= translate("All fields are required, but the email will not be showed.", "Tous les champs sont requis, mais le courriel ne sera pas affiche.") ?></div> 
		</td>
		</tr>


		<tr>
		<td>
		<?= translate("Name", "Nom") ?>: 
		</td>
		<td>
		<input type="text" name="name" size="50" value="<?= $_SESSION['name'] ?>" />
		</td>
		</tr>

		<tr>
		<td>
		<?= translate("Email", "Courriel") ?>: 
		</td>
		<td>
		<input type="text" name="email" size="50" value="<?= $_SESSION['email'] ?>" />
		</td>
		</tr>

		<tr>
		<td>
		<?= translate("Title", "Titre") ?>: 
		</td>
		<td>
		<input type="text" name="title" size="50" value="<?= $_SESSION['title'] ?>" />
		</td>
		</tr>

		<tr>
		<td colspan ="2">
		<?= translate("Comment", "Commentaire") ?>: 
		</td>
		</tr>
		<tr>
		<td colspan="2">
		<textarea name="comment" rows="12" cols="70"><?= $_SESSION['comment'] ?></textarea>
		</td>
		</tr>

		<tr>
		<td colspan="2" align="right">
		<input type="submit" name="Submit" value="<?= translate("Add comment", "Ajouter le commentaire") ?>" >
		</td>
		</tr>

		</table>
		</form>
		-->
		<!-- End of Comment form -->
		</td>
		</tr>
		</table>
		<?php
	}
}

?>

<!-- End of Main -->

</TD>
</TR>
</table>	

<!-- End of Left section -->

</TD>
<TD WIDTH="200" HEIGHT="100%" VALIGN="TOP">

<!-- Right section -->

<table align="right">
<tr>
<td HEIGHT="80" align="right" valign="top">

<!-- Lang -->

<?= switchLang() ?>

</TD>
</TR>

<tr>
<td align="left" valign="top">

<!-- About me -->
<h4><?= translate("About me:", "A propos de moi:")?></h4>
<?= translate(
"My name is Francis Provencher. I am from Montreal, Quebec, Canada, and I just came back from Miyazaki, Japan. I live with my wife, Julie and my two sons, Alexis and Mat&eacute;o.<br>
I graduated in computer science at Sherbrooke University. I am now working at <a href='http://www.newbreedvfx.com/'>Newbreed Visual Effects</a> and It rocks!",
"Mon nom est Francis Provencher. je suis originaire de Montr&eacute;al, Quebec, Canada. Je reviens d'un s&eacute;jour d'un an &agrave; Miyazaki au Japon. J'habite avec ma femme, Julie et mes deux fils Alexis et Mat&eacute;o.<br>
J'ai gradue en informatique &agrave; l'Universit&eacute; de Sherbrooke. Je travaille pr&eacute;sentement &agrave; <a href='http://www.newbreedvfx.com/'>Newbreed Visual Effects</a> et c'est super!")?>
<!-- End of About me -->


</TD>
</TR>

<tr>
<td align="left" valign="top">

<!-- Photos -->

<h4><?= translate("My GPG key:", "Ma cl&eacute; GPG:")?></h4>
<A HREF="francis.key">F9357C13</A><br>

<!-- End of Photos -->

</TD>
</TR>

<tr>
<td align="left" valign="top">

<!-- Photos -->

<h4><?= translate("My photo albums:", "Mes albums photo:")?></h4>
<A HREF="https://www.tzone.org/gallery/darkfox"><?= translate("New album", "Nouvel album") ?></A><br>
<A HREF="/~darkfox/cgi-bin/album/album.cgi"><?= translate("Old album", "Ancien album") ?></A>

<!-- End of Photos -->

</TD>
</TR>

<tr>
<td align="left" valign="top">

<!-- Read -->
<!--
<h4><?= translate("I am now reading:", "Je lis presentement:")?></h4>
<?
$queryRead = "SELECT * FROM blogRead WHERE active='y' ORDER BY readDate DESC ";
$resultRead = mysql_query($queryRead) or die('Query failed: ' . mysql_error());
while ($rowRead = mysql_fetch_assoc($resultRead)) {
	?>
	<A HREF="<?= $rowRead['link'] ?>" target="_NEW"><?= $rowRead['title'] ?></A> <?= translate("by", "par") . " " . $rowRead['author'] ?><br>
	<?
}
?>
-->
<!-- End of Read -->

</TD>
</TR>

<tr>
<td align="left" valign="top">

<!-- Links -->

<h4><?= translate("Useful links:", "Liens utiles:") ?></h4>
<a href="http://slashdot.org/"><img src="img/slashbutton.gif" width="88" border="0" alt="slashdot.org"></a>
<a href="http://freshmeat.net/"><img src="img/freshmeat_link_button_2.gif" width="88" border="0" alt="freshmeat.net"></a>
<br>
<a href="http://www.perl.com"><img src="img/rectangle_power_perl.gif" width="88" height="31" alt="Perl" border="0"></a>
<a href="http://perl.apache.org"><img src="img/powered_by_modperl.gif" width="88" height="31" alt="Powered by ModPerl and Apache" border="0"></a>
<br>
<!-- 
<a href="http://www.spreadfirefox.com/?q=affiliates&amp;id=0&amp;t=70"><img border="0" alt="Get Firefox!" title="Get Firefox!" src="http://sfx-images.mozilla.org/affiliates/Buttons/88x31/get.gif"/></a>
-->
<a href="http://www.spreadfirefox.com/?q=affiliates&amp;id=0&amp;t=71"><img border="0" alt="Get Firefox!" title="Get Firefox!" src="http://sfx-images.mozilla.org/affiliates/Buttons/88x31/safer.gif"></a>
<a href="http://www.spreadfirefox.com/?q=affiliates&amp;id=0&amp;t=182"><img border="0" alt="Get Thunderbird!" title="Get Thunderbird!" src="http://sfx-images.mozilla.org/affiliates/thunderbird/thunderbird_88x31.png"></a>
<!-- End of Links -->

</TD>
</TR>

<tr>
<td align="left" valign="top">

<!-- Powered by -->

<h4><?= translate("Powered by:", "Ce site utilise:") ?></h4>
<a href="http://www.debian.org/"><img src="img/debian_button-k2.png" width="88" height="30" border="0" alt="www.debian.org"></a>
<a href="http://www.php.net/"><img src="img/php.png" width="88" height="31" border="0" alt="www.php.net"></a>
<!-- <br>
<br>
<a href="http://www.apache-asp.org/"><img src="img/powered_by_apache_asp.jpg" width="88" height="31" alt="Powered by Apache::ASP" border="0"></a>

<br>
-->
<br>
<a href="http://www.mysql.com"><img src="img/powered-by-mysql-88x31.png" width="88" height="31" alt="Powered by MySQL" border="0"></a>

<!-- End of Powered by -->

</TD>
</TR>

<tr>
<td align="left" valign="top">

<!-- Misc -->

<h4><?= translate("Misc:", "Misc:") ?></h4>
<a href="http://www.nosoftwarepatents.com"><img src="img/nopatent_button_2.jpg" alt="No Software Patents" border="0"></a>
<a href="http://validator.w3.org/check/referer"><img border="0"
src="http://www.w3.org/Icons/valid-html401"
alt="Valid HTML 4.01!" height="31" width="88"></a>
<br>

<ADDRESS>
<FONT SIZE=-2>
<?= translate("Last modified: ", "Derniere modification le ") . date ("Y/m/d.", getlastmod()) ?> 
<BR>
Contact: Francis Provencher &lt;<A HREF="mailto:francis@TZoNE.ORG">francis@TZoNE.ORG</A>&gt;
</FONT>
</ADDRESS>

<!-- End of Misc -->

</TD>
</TR>
</table>	
<!-- End of Right section -->

</TD>
</tr>
</table>
</BODY>

</HTML>
