File "create_table05.php"
Full Path: /home/analogde/www/Outlook/Debug/create_table05.php
File size: 18.33 KB
MIME-type: text/html
Charset: utf-8
<!DOCTYPE html>
<html>
<style>
<!--
table, th, td {
border:1px solid black;
}
-->
table {
<!-- margin-left: auto;
margin-right: auto;
-->
font-size: 20px;
height: 100%;
table-layout: fixed;
}
td {
border: 1px solid black;
text-align: center;
padding: 1px;
}
tr:nth-child(even) {
background-color: #00cf45;
}
</style>
<body>
<script>
function blabla(val)
{
alert(val);
}
</script>
</body>
<html>
<?php
//ISO week number
// https://jqueryui.com/datepicker/#date-range
// https://makitweb.com/jquery-datepicker-to-filter-records-with-php-mysql/
// https://cdynamicprogramming.blogspot.com/p/blog-page_96.html
include("calendrier_generation02.php");
//30-12-2024 LUN
//31-12-2024 MAR
// ++++++++++++ a voir
//https://phpsources.net/code/php/date-heure/929_numero-de-semaine-iso
// https://blog.hubspot.com/website/php-date-time-functions
$ts = strtotime("30-12-2024");
echo ">>>>> " .idate('W', $ts);
echo "<br>";
echo ">>>>> " .strftime('%-V', $ts);
echo "<br>";
$ddate = "2024-12-30";
$date = new DateTime($ddate);
$week = $date->format("W");
echo "Week Number: $week";
echo "<br>";
echo ISOweek (2024, 12, 29);
echo "<br>";
echo ISOweek (2024, 12, 30);
echo "<br>";
echo ISOweek (2024, 12, 31);
echo "<br>";
echo ISOweek (2024, 01, 01);
echo "<br>";
$site = $_SERVER["SERVER_NAME"];
if( ($site == "localhost") || ($site == "127.0.0.1") )
{
echo "Mode local";
echo "<br>";
$hostdb = "localhost";
$userdb = "root";
$passdb = "";
$namedb = "task_manager";
}
else
{
echo "Hebergeur";
echo "<br>";
$hostdb = "analogdepat.mysql.db";
$userdb = "analogdepat";
$passdb = "Un92pac007";
$namedb = "analogdepat";
}
// connexion
$conn = new mysqli($hostdb, $userdb, $passdb, $namedb);
// gestion erreur de connexion
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
// définir la date de début et de fin
$date_debut = "02-04-2024";
$date_fin = "18-12-2026";
echo "Plage " .$date_debut ." " .$date_fin;
echo "<br>";
//
$pieces = explode("-", $date_debut);
$annee_debut = $pieces[2];
unset($pieces);
$pieces = explode("-", $date_fin);
$annee_fin = $pieces[2];
unset($pieces);
echo " >>>> " .$annee_debut . " " .$annee_fin ;
echo "<br>";
// etalement du planning
$etalement = array();
if( $annee_debut == $annee_fin)
{
$etalement[] = $annee_debut;
echo "Sur la meme annee";
echo "<br>";
}
else
{
// 2025 - 2024 = 1 sur 2 ans
// 2026 - 2024 = 2 sur 3 ans
//$etalement = ($annee_fin - $annee_debut) + 1;
for( $i=$annee_debut; $i <= $annee_fin ; $i++)
{
$etalement[] = $i;
}
echo "Sur plusieurs annees";
echo "<br>";
echo "<pre>";
print_r($etalement);
echo "</pre>";
}
/*
$AlldatesRange = getBetweenDates($date_debut, $date_fin);
echo "<pre>";
print_r($AlldatesRange);
echo "</pre>";
*/
echo "<br>";
echo "---------------------------------------------------";
echo "<br>";
$listing_jours = array();
$listing_jours = generation_bis($etalement);
echo "<pre>";
print_r($listing_jours);
echo "</pre>";
echo "<br>";
echo "------------------ +++++ ---------------------------------";
echo "<br>";
$allDates = array();
$flag = false;
for( $i=0; $i <= count($listing_jours) ; $i++)
{
//echo "<pre>";
//print_r($listing_jours[$i]);
//echo "</pre>";
$annee = $listing_jours[$i];
for( $j=0; $j < count($annee) ; $j++)
{
/*echo "<pre>";
print_r($annee[$j]);
echo "</pre>";*/
$mois = $annee[$j];
for( $k=0; $k < count($mois) ; $k++)
{
$string = $mois[$k];
$pieces = explode( "_", $string);
echo " ++++ " .$pieces[0] . " " .$date_debut ." " .gettype($pieces[0]) . " " .gettype($date_debut);
echo "<br>";
if( $pieces[0] == $date_debut )
{
$flag = true;
echo " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ";
echo "<br>";
}
if( $pieces[0] == $date_fin )
{
$flag = false;
$allDates[] = $mois[$k];
echo " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ";
echo "<br>";
}
if($flag)
{
$allDates[] = $mois[$k];
}
}
}
}
echo " &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ";
echo "<br>";
echo "<pre>";
print_r($allDates);
echo "</pre>";
table_horizontale($allDates);
zzz($allDates);
echo "Zoulou .....";
echo " concatener ";
echo "<br>";
echo "<br>";
$semaines_details = array();
$semaines_details = traitement($allDates);
/*
$semaines_details = array();
for( $i=0; $i < count($allDates) ; $i++)
{
//$pieces = explode( "_", $allDates[$i]);
if( $i != 0 )
{
$element_courant = explode( "_", $allDates[$i]);
$element_precedent = explode( "_", $allDates[$i-1]);
$week_courant = $element_courant[3];
$week_precedent = $element_precedent[3];
if( $week_courant != $week_precedent)
{
$p++;
$start = $i - $p;
$end = $start + $p - 1;
$element_debut = explode( "_", $allDates[$i-$p]);
$element_fin = explode( "_", $allDates[$i-1]);
echo ">>>>> " .$start ." " .$end ." " .$p ." " .$week_precedent ." " .$element_debut[0] ." " .$element_fin[0] ."<br>";
// construire le tableau coorespondant
$semaines_details[] = $start ."_" .$end ."_" .$p ."_" .$week_precedent ."_" .$element_debut[0] ."_" .$element_fin[0];
$p = 0;
}
else
{
$p++;
}
}
if( $i == count($allDates) - 1)
{
//$p++;
$start = $end + 1;;
$end = $i;
$element_debut = explode( "_", $allDates[$start]);
$element_fin = explode( "_", $allDates[$end]);
$ecart = ($end - $start)+1;
echo "<< FIN >> " .$start ." " .$end ." " .$ecart ." " .$element_debut[3] ." " .$element_debut[0] ." " . $element_fin[0] ."<br>";
$semaines_details[] = $start ."_" .$end ."_" .$ecart ."_" .$element_debut[3] ."_" .$element_debut[0] ."_" .$element_fin[0];
}
//echo " ///// " .$week_courant . " " .$week_precedent;
//echo "<br>";
}
*/
//zzz($allDates);
echo "Tout ...";
echo "<pre>";
print_r($semaines_details);
echo "</pre>";
abc($semaines_details);
/**********************************************************************************/
function traitement($allDates)
{
echo "GO .............................................";
echo "<br>";
$semaines_details = array();
for( $i=0; $i < count($allDates) ; $i++)
{
//$pieces = explode( "_", $allDates[$i]);
if( $i != 0 )
{
$element_courant = explode( "_", $allDates[$i]);
$element_precedent = explode( "_", $allDates[$i-1]);
$week_courant = $element_courant[3];
$week_precedent = $element_precedent[3];
if( $week_courant != $week_precedent)
{
$p++;
$start = $i - $p;
$end = $start + $p - 1;
$element_debut = explode( "_", $allDates[$i-$p]);
$element_fin = explode( "_", $allDates[$i-1]);
echo ">>>>> " .$start ." " .$end ." " .$p ." " .$week_precedent ." " .$element_debut[0] ." " .$element_fin[0] ."<br>";
// construire le tableau coorespondant
$semaines_details[] = $start ."_" .$end ."_" .$p ."_" .$week_precedent ."_" .$element_debut[0] ."_" .$element_fin[0];
$p = 0;
}
else
{
$p++;
}
}
if( $i == count($allDates) - 1)
{
//$p++;
$start = $end + 1;;
$end = $i;
$element_debut = explode( "_", $allDates[$start]);
$element_fin = explode( "_", $allDates[$end]);
$ecart = ($end - $start)+1;
echo "<< FIN >> " .$start ." " .$end ." " .$ecart ." " .$element_debut[3] ." " .$element_debut[0] ." " . $element_fin[0] ."<br>";
$semaines_details[] = $start ."_" .$end ."_" .$ecart ."_" .$element_debut[3] ."_" .$element_debut[0] ."_" .$element_fin[0];
}
}
return $semaines_details;
}
/**********************************************************************************/
function abc($semaines_details)
{
$array_val = array(" WEEK ", "C");
echo "
<table border='1px' >
<tr style='color:white;
background-color:black;' >";
for ($i = 0; $i < 2; $i++)
{
echo "<th> ".$array_val[$i] ."</th>";
}
echo '</tr>';
echo '<tr>';
for($row=0;$row< count($semaines_details) ;$row++)
{
echo '<tr>';
for($col=0;$col < 2 ;$col++)
{
$indice_row = $row+1;
$indice_col = $col+1;
$indice = "col".$indice_col ."-" ."row".$indice_row ;
if( $col == 0 )
{
$pieces = explode( "_", $semaines_details[$row]);
$week = $pieces[3];
$date_debut = $pieces[4];
$date_fin = $pieces[5];
$str = $week ." (" .$date_debut ." * " .$date_fin .")";
echo "<td width='400px' >$str</td>";
}
else
{
/*echo '
<td width="400px" ><input type="text" name = "<?php echo $indice; ?>" id="<?php echo $indice; ?>" onblur="blabla(this.id)" /></td>
';*/
?>
<td><input type="text" name = "<?php echo $indice; ?>" id="<?php echo $indice; ?>" onblur="blabla(this.id)" /></td>
<?php
}
}
echo '</tr>';
}
echo '</table>';
}
/*
// nom de la table
$table = "pipo";
$listing_jours = aaa();
echo " Toute l'annee ";
echo "<br>";
echo "<pre>";
print_r($listing_jours);
echo "</pre>";
// on prends le 3 mois
echo " On prends le 3ieme mois ";
echo "<br>";
echo "<pre>";
print_r($listing_jours[2]);
echo "</pre>";
//
$nb_elements = count($listing_jours[2]);
$DateArray = array();
for( $i=0; $i < $nb_elements ; $i++)
{
$pieces = explode("_", $listing_jours[2][$i]);
//echo " ++++ " .gettype($pieces[0]);
//echo "<br>";
////str_replace("-","_",$pieces[0]);
//$DateArray[] =
//$titi = str_replace("-","/", $listing_jours[0][$i]);
//echo " >>>> " .$titi;
//echo "<br>";
$DateArray[] = $pieces[2];
//$startdate = strtotime("03/11/2024");
//str_replace("-","", $listing_jours[0][$i] );
//$DateArray[] = strtotime($pieces[0]);
}
echo "Liste des dates" ."<br>";
echo "<pre>";
print_r($DateArray);
echo "</pre>";
$RandomNumber = array();
for( $i=0; $i < $nb_elements ; $i++)
{
$RandomNumber[] = rand(10,250);
}
echo "Liste des valeurs (aléatoire)" ."<br>";
echo "<pre>";
print_r($RandomNumber);
echo "</pre>";
$table = "chart_table";
//create_table($conn,$table);
//insertion($conn,$table,$DateArray,$RandomNumber);
function getBetweenDates($startDate, $endDate)
{
$rangArray = [];
$startDate = strtotime($startDate);
$endDate = strtotime($endDate);
for ($currentDate = $startDate; $currentDate <= $endDate; $currentDate += (86400))
{
$date = date('d-m-Y', $currentDate);
$rangArray[] = $date;
}
return $rangArray;
}
*/
/**********************************************************/
/*
function ISOWeek($y , $m , $d){
$week=strftime("%W", mktime(0, 0, 0, $m, $d, $y));
$dow0101=getdate(mktime(0, 0, 0, 1, 1, $y));
if ($dow0101["wday"]>1 &&
$dow0101["wday"]<5)
$week++;
elseif ($week==0)
$week=53;
return(substr("00" . $week, -2));
}
*/
/**********************************************************/
function table_horizontale($AllDates)
{
echo "
<table border='2px' >
<tr>";
for ($i = 0; $i < count($AllDates); $i++)
{
$pieces = explode("_", $AllDates[$i]);
$indice = $i + 1;
$jour = substr($pieces[1], 0, 3);
$jour = ucfirst($jour);
echo '<th>' .$pieces[0] ." " .$jour ." " .$indice .'</th>';
}
echo '</tr>';
echo '<tr>';
for($row=0;$row<7;$row++)
{
echo '<tr>';
for($col=0;$col < count($AllDates);$col++)
{
$indice_row = $row+1;
$indice_col = $col+1;
$indice = "col".$indice_col ."-" ."row".$indice_row ;
echo '
<td><input type="text" name = "<?php echo $indice; ?>" id="<?php echo $indice; ?>" onblur="blabla(this.id)" /></td>
';
}
echo '</tr>';
}
echo '</table>';
}
/**********************************************************/
function zzz($AllDates)
{
$array_val = array(" DATE ", " JOUR ", "SEMAINE" , "C");
echo "
<table border='1px' >
<tr style='color:white;
background-color:black;' >";
for ($i = 0; $i < 4; $i++)
{
echo "<th> ".$array_val[$i] ."</th>";
}
echo '</tr>';
echo '<tr>';
for($row=0;$row< count($AllDates) ;$row++)
{
echo '<tr>';
for($col=0;$col < 4 ;$col++)
{
$indice_row = $row+1;
$indice_col = $col+1;
$indice = "col".$indice_col ."-" ."row".$indice_row ;
if( $col == 0 )
{
$pieces = explode("_", $AllDates[$row]);
echo "<td width='400px' >$pieces[0]</td>";
}
else if( $col == 1)
{
$pieces = explode("_", $AllDates[$row]);
$indice = $i + 1;
$jour = substr($pieces[1], 0, 3);
$jour = ucfirst($jour);
echo "<td width='400px'>$jour</td>";
}
else if( $col == 2)
{
//$week = getWeek($pieces[0]);
$date_split = explode("-", $pieces[0] );
$week = ISOweek ($date_split[2], $date_split[1], $date_split[0]);
//echo ISOweek (2024, 12, 29);
echo "<td width='400px'> $week </td>";
}
else
{
echo '
<td width="400px" ><input type="text" name = "<?php echo $indice; ?>" id="<?php echo $indice; ?>" onblur="blabla(this.id)" /></td>
';
}
}
echo '</tr>';
}
echo '</table>';
}
/**********************************************************/
function zzz_bis($AllDates)
{
//$array_val = array(" DATE ", " JOUR ", "SEMAINE" , "C");
$array_val = array(" Semaine ", " Valeur");
echo "
<table border='1px' >
<tr style='color:white;
background-color:black;' >";
for ($i = 0; $i < 2; $i++)
{
echo "<th> ".$array_val[$i] ."</th>";
}
echo '</tr>';
echo '<tr>';
for($row=0;$row< count($AllDates) ;$row++)
{
echo '<tr>';
for($col=0;$col < 2 ;$col++)
{
$indice_row = $row+1;
$indice_col = $col+1;
$indice = "col".$indice_col ."-" ."row".$indice_row ;
if( $col == 0 )
{
$pieces = explode("_", $AllDates[$row]);
echo "<td width='400px' >$pieces[3]</td>";
}
/*else if( $col == 1)
{
$pieces = explode("_", $AllDates[$row]);
$indice = $i + 1;
$jour = substr($pieces[1], 0, 3);
$jour = ucfirst($jour);
echo "<td width='400px'>$jour</td>";
} */
/*else if( $col == 2)
{
//$week = getWeek($pieces[0]);
$date_split = explode("-", $pieces[0] );
$week = ISOweek ($date_split[2], $date_split[1], $date_split[0]);
//echo ISOweek (2024, 12, 29);
echo "<td width='400px'> $week </td>";
}*/
else
{
echo '
<td width="400px" ><input type="text" name = "<?php echo $indice; ?>" id="<?php echo $indice; ?>" onblur="blabla(this.id)" /></td>
';
}
}
echo '</tr>';
}
echo '</table>';
}
/**********************************************************/
function xxx($AllDates)
{
for($row=0;$row< count($AllDates) ;$row++)
{
}
//18-12-2026_vendredi_1797548400
}
/**********************************************************/
function generation($tab_annee)
{
//echo "plouf...aaaa";
//print_r($tab_annee);
//$liste_annee = array("2024");
$allDates = array();
for( $i=0; $i < count($tab_annee) ; $i++)
{
echo " <<<< >>>> " .$tab_annee[$i];
echo "<br>";
//blabla_calendrier($tab_annee[$i]);
$listing_jours = calendrier($tab_annee[$i]);
$allDates[] = $listing_jours;
unset($listing_jours);
}
//echo "<pre>";
//print_r($allDates);
//echo "</pre>";
return $allDates;
}
/**********************************************************/
function generation_bis($tab_annee)
{
$allDates = array();
for( $i=0; $i < count($tab_annee) ; $i++)
{
echo " <<<< >>>> " .$tab_annee[$i];
echo "<br>";
$listing_jours = calendrier_bis($tab_annee[$i]);
$allDates[] = $listing_jours;
unset($listing_jours);
}
return $allDates;
}
/**********************************************************/
/*function blabla_calendrier($aaaa)
{
echo "++++++ " .$aaaa;
echo "<br>";
/*$listing_jours = calendrier($annee);
echo "<pre>";
print_r($listing_jours);
echo "</pre>";*/
/*
}*/
/**********************************************************/
function convert_date_to_timestamp()
{
}
/**********************************************************/
function create_table($conn,$table)
{
$result = $conn->query("SHOW TABLES LIKE '$table'");
if ($result->num_rows > 0)
{
echo ">>>>> Table : " .$table ." exists !!!!";
}
else
{
echo "Table does not exist.";
$sql = "CREATE TABLE $table (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
champ_date VARCHAR(30) NOT NULL,
champ_valeur VARCHAR(30) NOT NULL
)";
if ($conn->query($sql) === TRUE)
{
echo "Table was created successfully";
}
else
{
echo "Error creating table: " . $conn->error;
}
}
}
/**********************************************************/
function insertion($conn,$table,$DateArray,$RandomNumber)
{
for( $i=0; $i < count($DateArray) ; $i++)
{
$sql = "INSERT INTO $table (champ_date, champ_valeur)
VALUES ( $DateArray[$i], $RandomNumber[$i] )";
//echo " ++++ " .$sql;
//echo "<br>";
if ($conn->query($sql) === TRUE)
{
//echo "New record created successfully";
$ok = True;
echo "Insert OK : " . $sql . "<br>" ;
} else
{
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
//$sql = "INSERT INTO $table (firstname, lastname, email)
//VALUES ('John', 'Doe', 'john@example.com')";
}
/**********************************************************/
?>