<?php 

// https://www.fusioncharts.com/dev/chart-attributes/realtimestackedcolumn

// https://www.fusioncharts.com/charts/line-area-charts/line-chart-with-multiple-series?framework=php

// https://www.fusioncharts.com/dev/chart-guide/standard-charts/multi-series-charts

// https://www.fusioncharts.com/fusiontime/examples/plotting-multiple-series-on-time-axis?framework=javascript

	// sur l'axe des y : les tâches
	// sur l'axe des x : la durée pour la réalisation d'une tâche

	// https://www.geeksforgeeks.org/overview-of-burndown-chart-in-agile/
	
	// php diagramme d'avancement d'un projet
	
	// etat d'avancement
	
	// planification de projet
	
	// https://siocours.lycees.nouvelle-aquitaine.pro/doku.php/si7/si7.3
	
	// http://lyc-vaucanson-tours.tice.ac-orleans-tours.fr/php5/Accueil/index.php/gestion-de-projet/927-planifier-un-projet-avec-ganttproject
	
	//https://code.daypilot.org/93862/html5-gantt-chart
	
	// https://github.com/th0liveira/GanttChartPHP
	
	//  php time tracking open source
	
	// https://sourceforge.net/directory/time-tracking/php/
	
	// timeline
	
	// https://hotexamples.com/examples/-/TimeLine/-/php-timeline-class-examples.html
	
	//https://www.techieclues.com/blogs/converting-html-table-to-array-in-php

// php scheduled task

	date_default_timezone_set('Europe/Paris');

	include("fusioncharts.php");

	$temps_debut = "2024-01-11";
	$temps_fin = "2024-01-25";
	
	
	if (isset($_POST['Submit']))
	{
		echo "Bingo...";
		
		
	}
	//blabla($temps_debut, $temps_fin);
	
?>

<html>
   <head>
      <title>FusionCharts | Multi-Series Chart using PHP and MySQL</title>
	  <!--
        <script src="http://static.fusioncharts.com/code/latest/fusioncharts.js"></script>
        <script src="http://static.fusioncharts.com/code/latest/fusioncharts.charts.js"></script>
        <script src="http://static.fusioncharts.com/code/latest/themes/fusioncharts.theme.fint.js"></script>
	-->	
	
        <script src="js/js/fusioncharts.js"></script>
        <script src="js/js/fusioncharts.charts.js"></script>
        <script src="js/js/themes/fusioncharts.theme.fint.js"></script>
		
	
   </head>
   <body>
   
<?php

function blabla($temps_debut, $temps_fin)
{

	// générer les timestamps sur un période donnée
	
	//$start_date = new DateTime("2024-01-11");
	//$end_date = new DateTime("2024-01-25");
	
	$start_date = new DateTime($temps_debut);
	$end_date = new DateTime($temps_fin);
 
	echo $start_date->getTimestamp();
	echo "<BR>";
	echo $end_date->getTimestamp();
	echo "<BR>";
	
	//$plouf = $start_date->modify('+1 day');
	//echo $plouf->getTimestamp();
	
	$nombreSecondParJour = 3600 * 24; 
	
	//$date = new DateTime();
	//$date->setTimestamp($start_date);

	//echo $date->format('Y-m-d');
	
	$timestamp_start = $start_date->getTimestamp();
	
	$timestamp = $timestamp_start ;
	
	$pipo = array();
	
	for ($x = 1; $x <= 10; $x++) 
	{
		$timestamp = $timestamp + $nombreSecondParJour;
		$dateTime = date('d-m-Y ', $timestamp );
		
		//echo gettype($dateTime);
		//echo "<br>";
		
		$item = (string)$x;
		//echo gettype($item);
		//echo "<br>";
		
		echo $item ." " .$dateTime;
		echo "<br>";
		
		$pipo[] = $dateTime;
		
		//$s = $dateTime + " titi";
		//echo $s;
		//echo "<br>";
		
		
		
		//echo $item + " 64644 ";
		
		//$result = $dateTime->format('Y-m-d H:i:s');
		
		//echo $item + $dateTime;
		
	}

	print_r($pipo);
	
	echo count($pipo);

	//$s1 = "John";
	//echo "<br>";
	//$sql = "INSERT INTO MyGuests (firstname, lastname, email) VALUES ( '$s1', 'Doe', 'john@example.com')";

	$site = $_SERVER["SERVER_NAME"];
	if( ($site == "localhost") || ($site == "127.0.0.1") ) 
	{
		echo "Mode local";
		echo "<br>";
		$hostdb = "localhost";  // MySQl host
		$userdb = "root";  // MySQL username
		$passdb = "";  // MySQL password
		$namedb = "task_manager";  // MySQL database name
	}
	else
	{	
		echo "Hebergeur";
		echo "<br>";
		$hostdb = "analogdepat.mysql.db";
		$userdb = "analogdepat";
		$passdb = "Un92pac007";
		$namedb = "analogdepat";
	}




	$dbhandle = new mysqli($hostdb, $userdb, $passdb, $namedb);

	if ($dbhandle->connect_error) 
	{
		exit("There was an error with your connection: ".$dbhandle->connect_error);
	}

	

	$val1 = array(250, 220, 200, 180, 160, 135,120, 100, 82, 70);
	$val2 = array(220, 200, 100, 100, 50, 220, 200, 100, 100, 50 );
/*
CREATE TABLE IF NOT EXISTS `graph02` (
  `id` int(11) DEFAULT NULL,
  `jour` varchar(255) NOT NULL,
  `val1` int(11) DEFAULT NULL,
  `val2` int(11) DEFAULT NULL,
  PRIMARY KEY (`jour`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
*/

	echo "<br>";
/*
	for ($i = 1; $i <= count($pipo); $i++)
	{
		$indice = $i - 1;
		
		$sql = "INSERT INTO graph02 (id, jour, val1, val2) VALUES ( '$i', '$pipo[$indice]', '$val1[$indice]', '$val2[$indice]' )";
		//echo $sql;
		//echo "<br>";
		
		//$result = $dbhandle->query($sql) or exit("Error code ({$dbhandle->errno}): {$dbhandle->error}");
		
	}		
*/	
	$strQuery = "SELECT * FROM graph02; ";

	$result = $dbhandle->query($strQuery) or exit("Error code ({$dbhandle->errno}): {$dbhandle->error}");



	if ($result)
	{

		// https://www.fusioncharts.com/dev/chart-attributes/scrollline2d

		$arrData = array(
        "chart" => array(
        	  "caption"=> "blabla",
            "xAxisname"=> "XXX",
            "yAxisName"=> "YYY",
            "numberPrefix"=> "",
            "plotFillAlpha"=> "80",
        	  "showValues"=> "1",
        	  "placeValuesInside"=> "1",
        	  "usePlotGradientColor"=> "0",
        	  "rotateValues"=> "1",
        	  "valueFontColor"=> "#FFFFFF",
        	  "showHoverEffect"=> "1",
            "rotateValues"=> "1",
			
			"flatScrollBars"=> "1",
			"numVisiblePlot"=> "3",
			
            "showXAxisLine"=> "1",
			"rotateLabels"=> "1",
            "xAxisLineThickness"=> "1",
            "xAxisLineColor"=> "#999999",
            "showAlternateHGridColor"=> "0",
            "legendBgAlpha"=> "0",
            "legendBorderAlpha"=> "0",
            "legendShadow"=> "0",
            "legendItemFontSize"=> "10",
            "legendItemFontColor"=> "#666666",
            "theme"=> "fint"
          	)
         	);

		$categoryArray=array();
		$dataseries1=array();
		$dataseries2=array();
        	
		while($row = mysqli_fetch_array($result)) 
		{				
			array_push($categoryArray, array( "label" => $row["jour"])	);

			array_push($dataseries1, array(	"value" => $row["val1"]) );
				
			array_push($dataseries2, array(	"value" => $row["val2"])	);

		}
	
		$arrData["categories"]=array(array("category"=>$categoryArray));
	
		$arrData["dataset"] = array(array("seriesName"=> "Prévision", "data"=>$dataseries1), array("seriesName"=> "Avancement", "data"=>$dataseries2));
		
		//echo "<pre>";
		//print_r($arrData["dataset"]);
		//echo "</pre>";
		
		echo "<pre>";
		print_r($arrData);
		echo "</pre>";
		

		$jsonEncodedData = json_encode($arrData);
            			
		// chart object
		//scrollline2d
		//$burndown = new FusionCharts("msline", "chart1" , "100%", "400", "contenu", "json", $jsonEncodedData);
		$burndown = new FusionCharts("scrollline2d", "chart1" , "70%", "1800", "contenu", "json", $jsonEncodedData);
		
		
		//scrollline2d
		
		$burndown->render();
		$dbhandle->close();
		
		echo "Fin";
		echo "<br>";
		echo "<br>";
		echo "<br>";

	}
}
?>   
   
<?php
  

	
	blabla($temps_debut, $temps_fin);
 
?>

<center>

 
 
 <div id="contenu"> 3 Chart will render here!</div>
 
</center>

<style>
.wrapper {
  overflow-x: scroll;
}

.wrapper table {
  white-space: nowrap;
}

/** Only for demo */
table,
td,
th {
  border-collapse: collapse;
  border: 1px solid #777;
}

input {
            margin: 1px;
            padding: 2px
        }

th {
  padding: 5px;
  background: #ddd;
}

td {
  padding: 5px 10px;
}

</style>

<!--
 https://stackoverflow.com/questions/62532819/html-input-inside-table-cell

https://stackoverflow.com/questions/62532819/html-input-inside-table-cell

https://www.phpzag.com/create-dynamic-bootstrap-tabs-with-php-mysql/ ++++++

https://coderszine.com/editable-html-table-with-jquery-php-mysql/

https://www.phpflow.com/html5/simple-example-of-editable-table-in-html5/

-->






</body>
   
   
</html>


