<?php
###########################################
# add_categories.php3                     #
# ajout de catégories                     #
###########################################

include("../config.php3");
include($BIB."bib_generic.php3");
include($BIB."bib_constants.php3");
include($BIB."bib_admin.php3");


function get_unix_date_simple($date) {
  $year = intval(strtok($date, "- :"));
  $month = intval(strtok("- :"));
  $day = intval(strtok("- :"));
  return mktime(0, 0, 1, $month, $day, $year);
}

function get_unix_date($date) {
  $year = intval(strtok($date, "- :"));
  $month = intval(strtok("- :"));
  $day = intval(strtok("- :"));
  $hour = intval(strtok("- :"));
  $minute = intval(strtok("- :"));
  $second = intval(strtok("- :"));
  return mktime($hour, $minute, $second, $month, $day, $year);

}


# constants
$ADD_CATEGORIES_PAGE = $ADMIN_URL. "add_categories.php3";
$GERER_QUESTIONS_PAGE = $ADMIN_URL. "gerer_questions.php3";
$CHECK_QUESTIONS_PAGE = $ADMIN_URL. "check_questions.php3";

?>

<html>
<head></head>
<link rel="stylesheet" href="admin.css">
<body rightmargin=0>
<div align=center class=trTitle>Liste des questions</div>
<br>



<?php


$categories = main_db_query ("SELECT * FROM QCategories ORDER BY ShowTime ASC");
while ($categorie = db_fetch_array($categories))
{
//	$date_format2 = date("d/m/Y ", get_unix_date($categorie['ShowTime']));
	$date_fin = date_mysql($categorie[EndTime])." à ".time_mysql($categorie[EndTime]);
	$date_debut = date_mysql($categorie[ShowTime])." à ".time_mysql($categorie[ShowTime]);
	
//	echo $date_format2." : ";
	echo "<hr>Du ".$date_debut." jusqu'au ".$date_fin." : ";
	
	$questions = main_db_query("SELECT * FROM QMotions WHERE Category='".$categorie[CategoryId]."'");
	$compte = db_num_rows($questions);
	if ($compte <= 0)
		echo "pas de questions";
	else
		echo $compte." questions";

	echo "<br>";
	while ($question = db_fetch_array($questions))
	{
		echo $question['Title']."<br>";
		$reponses = main_db_query("SELECT * FROM QMotionTypesAnswers WHERE MotionId = '".$question['MotionId']."'");
		$totalSondage = db_fetch_array(main_db_query("SELECT SUM(Extra) AS total FROM QMotionTypesAnswers WHERE MotionId = '".$question['MotionId']."'"));
		//echo "SELECT SUM(Extra) AS total FROM QMotionTypesAnswers WHERE MotionId = '".$question['MotionId']."'";
		$nbReponses = 0;
		while ($reponse = db_fetch_array($reponses))
		{
			$pourcent = intval($reponse['Extra'] / max(1, $totalSondage['total']) * 100);
			//if ($reponse['Price'] > 0)
				//echo "*";
			echo $pourcent."% ";
			echo $reponse['Answer']."<br>";
			$nbReponses += $reponse['Extra'];
		}
		echo $nbReponses." réponses";
	}
}

?>

</body>
</html>