<!-- https://www.journaldunet.fr/developpeur/developpement/1202649-comment-passer-une-variable-de-php-a-javascript/ --> <!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); } <!-- https://saturncloud.io/blog/how-to-pass-variables-and-data-from-php-to-javascript/#:~:text=The%20simplest%20way%20to%20pass,it%20to%20a%20JavaScript%20variable. --> function submitFormDataxxxxx() { //var x = "<?php echo"$name"?>"; //alert(x); //var variable = document.getElementByName("email").value; var x = document.getElementsByName("email").value; //alert(variableRecuperee); //var variableRecuperee = <?php echo json_encode($variableAPasser); ?>; //alert(variableRecuperee); //const phpecho="<?php echo $variableRecuperee; ?>"; //var name = '$variableRecuperee'; console.log("Hello world!"); console.log(x); //console.log(variable); alert(x); } function submitFormData() { // OK //var element = "col1-row1"; //champ = document.getElementById(element).value; //alert("plouf " + champ ); var javaScriptVar = "<?php echo $nb_semaines ; ?>"; alert(javaScriptVar); console.log(javaScriptVar); // OK //var indice = "col2" + "-" + "row1" ; //var titi = document.getElementById(indice).value; //console.log(titi); var toto = document.getElementById("id_element").value; console.log("mlklm " + toto); let text = ""; var tableau = new Array(); //for (let i = 0; i < 3; i++) //{ var array_col = new Array(7); for (let j = 0; j < 7; j++) { var col = 2; //i + 1; var row = j + 1; var indice = "col" + col + "-" + "row" + row; champ_valeur = document.getElementById(indice).value; text += champ_valeur + "<br>"; array_col[j] = champ_valeur; // OK pour déterminer si le champ est vide if (typeof champ_valeur === "string" && champ_valeur.length === 0) { console.log(indice + " The string is empty"); } else if (champ_valeur === null) { console.log(indice + " The string is null"); } else { console.log(indice + " The string is not empty or null"); } /*if (champ_valeur === null) { console.log(indice + " " + champ_valeur ); }*/ //text += indice + "<br>"; } //tableau[i] = array_col; //tableau[0] = array_col; //} //document.getElementById("display_text").innerHTML = text; //document.getElementById("display_text").innerHTML = "Voici le tableau au format string " + tableau.toString(); document.getElementById("display_text").innerHTML = "Voici le tableau au format string " + array_col.toString(); if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } var JsonString = JSON.stringify(array_col); xmlhttp.onreadystatechange = respond; xmlhttp.open("POST", "envoi_json.php", true); xmlhttp.send(JsonString); } function respond() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById('result').innerHTML = xmlhttp.responseText; } } function testResults (form) { var inputValue = form.input.value; alert ("You typed: " + inputValue); } </script> </body> <p id="display_text"></p> <div id="result"></div> </br> </br> </br> <html> <?php $variableRecuperee = "Zorro"; $variableAPasser = "Zoulou"; $name = "Hello World"; ?> <?php $currentDate = date('d-m-Y'); echo $currentDate; echo " +++++ " .strtotime($currentDate); //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"; $date_debut = "02-02-2024"; $date_fin = "10-05-2024"; 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 "<br>"; echo "<pre>"; print_r($etalement); 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 = structuration_dates($listing_jours, $date_debut, $date_fin); echo "<pre>"; print_r($allDates); echo "</pre>"; // table_horizontale($allDates); // table_verticale($allDates); // $semaines_details = array(); $semaines_details = traitement($allDates); /* echo "<pre>"; print_r($semaines_details); echo "</pre>"; */ affiche_horizontale_table_semaine($semaines_details); /**********************************************************************************/ function structuration_dates($listing_jours, $date_debut, $date_fin) { $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]; } } } } return $allDates; } /**********************************************************************************/ function traitement($allDates) { //echo "GO ............................................."; //echo "<br>"; $semaines_details = array(); for( $i=0; $i < count($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 affiche_horizontale_table_semaine($semaines_details) { $nb_semaines = count($semaines_details); $array_val = array(" WEEK ", " Valeur "); ?> <form action="javascript:void(0);" id="frmdata" onsubmit="submitFormData()"> <!-- <form name="myForm" action="#" method="post" onsubmit="submitFormData()" > <!-- <form action="" id="frmdata" onsubmit="submitFormData()"> --> <!-- <input type="hidden" name="email" value="riri"> <input type="text" name="input" value="<?php echo $variableAPasser; ?>"> --> <input type="hidden" id="id_element" value="<?php echo $nb_semaines; ?>"> <!-- <input type="button" name="button" value="Click" onClick="testResults(this.form)"> --> <!-- <input type=hidden id=variableAPasser value=<?php echo $variableAPasser; ?>/> --> <?php 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]; // get month from date setlocale(LC_TIME, "fr_FR"); $month = date('M', strtotime($date_debut)); if( $month == "Jan") $month = "Janvier"; if( $month == "Feb") $month = "Fevrier"; if( $month == "Mar") $month = "Mars"; if( $month == "Apr") $month = "Avril"; if( $month == "May") $month = "Mai"; if( $month == "Jun") $month = "Juin"; if( $month == "Jul") $month = "Juillet"; if( $month == "Aug") $month = "Aout"; if( $month == "Sep") $month = "Septembre"; if( $month == "Oct") $month = "Octobre"; if( $month == "Nov") $month = "Novembre"; if( $month == "Dec") $month = "Decembre"; $str = $month ." " .$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>'; ?> <button type="submit">Submit</button> </form> <?php } /**********************************************************/ /* 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> ';*/ ?> <td><input type="text" name = "<?php echo $indice; ?>" id="<?php echo $indice; ?>" onblur="blabla(this.id)" /></td> <?php } echo '</tr>'; } echo '</table>'; } /**********************************************************/ function table_verticale($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> ';*/ ?> <td width="400px" ><input type="text" name = "<?php echo $indice; ?>" id="<?php echo $indice; ?>" onblur="blabla(this.id)" /></td> <?php } } 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 generation($tab_annee) { $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); } 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 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')"; } */ /**********************************************************/ ?>