File "arbo_test03.php"
Full Path: /home/analogde/www/makefont/table_selection/arbo_test03.php
File size: 16.75 KB
MIME-type: text/x-php
Charset: utf-8
<?php
session_start();
echo "plouf";
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<style type="text/css">
.tbl {width: 640px;}
.tbl tr {background-color: Blue; height: 24px}
.tbl tr:hover {background-color: Red;}
</style>
<style>
tr:hover {
background-color: #ffff99;
}
.selected {
background-color: #E30B5C;
}
.newRow
{
color: #dd0000;
background-color:#ffd700;
}
/*
https://stackoverflow.com/questions/16045668/highlight-table-row-when-check-box-is-checked
https://breakingpar.com/bkp/home.nsf/0/87256B280015193F87256D6900079C14
https://jsfiddle.net/s5Gzd/6
https://www.aspsnippets.com/Articles/2659/Get-selected-checked-CheckBox-Row-values-of-HTML-Table-using-JavaScript/
https://shivrajan.medium.com/javascript-function-to-highlight-a-table-row-when-its-clicked-1967a483e3c3
https://www.reddit.com/r/learnjavascript/comments/11hv2ar/highlight_only_one_row_in_html_table/?onetap_auto=true&one_tap=true
https://www.tutorialspoint.com/how-to-access-tr-element-from-table-using-javascript
https://stackoverflow.com/questions/41485807/pure-javascript-select-table-row-as-object-when-click
*/
</style>
<script type="text/javascript">
// JavaScript Code to Highlight any
// row in the given table.
document.getElementById('table_to_highlight')
.addEventListener('click', function (item) {
// To get tr tag
// In the row where we click
var row = item.path[1];
var row_value = "";
for (var j = 0; j < row.cells.length; j++) {
row_value += row.cells[j].innerHTML;
row_value += " | ";
}
alert(row_value);
// Toggle the highlight
if (row.classList.contains('highlight'))
row.classList.remove('highlight');
else
row.classList.add('highlight');
});
</script>
<script>
function toggle(source)
{
let checkboxes = document.querySelectorAll('input[type="checkbox"]');
for (let i = 1; i < checkboxes.length; i++)
{
if (checkboxes[i] != source)
{
checkboxes[i].checked = source.checked;
var x = document.getElementById("table_to_highlight").rows[i].cells;
x.className = "newRow";
console.log(x);
// document.getElementById("table_to_highlight").rows[i].style.background = selected;
// document.getElementById('t2').style.backgroundColor=color3;
//x[i].innerHTML = "NEW CONTENT";
}
}
}
function test_checkbox()
{
console.log(" Au total : " + document.querySelectorAll('input[type="checkbox"]').length);
let checkboxes = document.querySelectorAll('input[type="checkbox"]');
console.log(checkboxes);
for(var i=0, n=checkboxes.length;i<n;i++)
{
//checkboxes[i].checked = source.checked;
if (checkboxes[i].checked == true)
{
console.log( i + " " + checkboxes[i] + " OK " );
}
else
{
console.log( i + " " + checkboxes[i] + " No " );
}
}
const checked = document.querySelectorAll('input[type="checkbox"]:checked')
let selected = [];
selected = Array.from(checked).map(x => x.value)
console.log(" +++++ " + selected);
/*var item = document.getElementById("ck1");
if (item.checked == true)
{
console.log(" +++++ " + document.getElementById("ck1").value);
} */
}
function tutu()
{
let checkboxes = document.querySelectorAll('input[type="checkbox"]');
//let nb = checkboxes.length;
selection_elements = [];
for(var i=1 ; i<checkboxes.length ;i++)
{
let numerotation = "CK" + i;
console.log(" ***** " + numerotation);
var obj = document.getElementById(numerotation);
if (obj.checked == true )
{
var contenu = document.getElementById(numerotation).value;
console.log(" Selection ---->>>> " + contenu);
selection_elements.push(contenu);
//console.log("\n");
}
}
/* const jsonContent = JSON.stringify(selection_elements);
const fs = require("fs");
fs.writeFile("./alphabet.json", jsonContent, 'utf8', function (err)
{
if (err)
{
return console.log(err);
}
console.log("The file was saved!");
}); */
/*$.ajax({
url: "titi.php",
type: "POST",
dataType: 'json',
data: JSON.stringify(selection_elements),
success: function(response){}
});
*/
var tab1 = new Array();
tab1.push("champ_date");
tab1.push("champ_valeur");
xmlhttp = new XMLHttpRequest();
var JsonString = JSON.stringify(tab1);
var aze = "+";
//xmlhttp.onreadystatechange = respond;
xmlhttp.open("POST", "titi.php", true);
xmlhttp.send(JsonString);
}
</script>
<?php
$tableau_fichiers = array();
$tableau_repertoires = array();
$root_path = $_SERVER['DOCUMENT_ROOT'];
//$path = getcwd();
//echo " +++ " .$path ."<br>";
//$aaa = removeLastDir($path, 1);
//echo " +++ " .$aaa ."<br>";
$dirReference = $root_path ."/Fusion";
echo "Reference " .$dirReference ."<br>";
if (isset($_GET['pipo']))
{
if ($_GET['pipo'] != "..")
{
$dirPath = $_SESSION['dirpath'] ."/" .$_GET['pipo'];
$_SESSION['dirpath'] = $dirPath;
if( $dirReference != $dirPath )
{
echo "==> " .$_SESSION['dirpath'] ."<br>";
// on doit rajouter le double point ( retour en arriére)
$obj = new fileObject();
$obj->setName("..");
$obj->setType('folder');
$tableau_repertoires[] = $obj;
}
}
else
{
echo "Zoulou " .$_SESSION['dirpath'] ."<br>";
//echo " <== " .$dirPath ."<br>";
$chunks = explode('/', $_SESSION['dirpath']);
//echo "<pre>";
//print_r($chunks);
//echo "</pre>";
//$toto = array_shift($chunks);
for($i=0; $i< count($chunks)-1 ; $i++)
{
$dirPath .= "/" .$chunks[$i];
}
$dirPath = substr($dirPath, 1);
$_SESSION['dirpath'] = $dirPath;
echo "<== " .$_SESSION['dirpath'] ."<br>";
//echo " <== " .$_SESSION['dirpath'] ."<br>";
if( $dirReference != $dirPath )
{
//echo "<== " .$_SESSION['dirpath'] ."<br>";
// on doit rajouter le double point ( retour en arriére)
$obj = new fileObject();
$obj->setName("..");
$obj->setType('folder');
$tableau_repertoires[] = $obj;
}
}
// echo dirname($path,2)
//chdir('/var/www/');
//echo realpath('./../../etc/passwd') . PHP_EOL;
// dirname
// basename
}
else
{
// initialisation
$dirPath = $root_path ."/Fusion";
$_SESSION['dirpath'] = $dirPath;
echo "Current start " .$_SESSION['dirpath'] ."<br>";
}
//echo " TRACE " .$dirPath ."<br>";
class fileObject
{
public $name;
public $type;
public $size;
// Methodes
function setName($name)
{
$this->name = $name;
}
function getName()
{
return $this->name;
}
function setType($type)
{
$this->type = $type;
}
function getType()
{
return $this->type;
}
function setSize($size)
{
$this->size = $size;
}
function getSize()
{
return $this->size;
}
}
/*
$tableau = array();
$myCar = new fileObject();
$myCar->setName('red');
$myCar->setType('Xfile');
$tableau[] = $myCar;
$myCar = new fileObject();
$myCar->setName('Vert');
$myCar->setType('plfolder');
$tableau[] = $myCar;
foreach ($tableau as $element) {
echo ' ------ ' . $element->color . ' ' . $element->type . "\n";
}
*/
// $root_path = $_SERVER['DOCUMENT_ROOT'];
// echo $root_path;
// $dirPath = $root_path ."/Fusion";
// $scan = scandir($dirPath);
/*
$tab_folders = array();
$tab_files = array();
$tableau_content = array();
foreach ($scan as $element)
{
$obj = new fileObject();
$obj->setName($element);
if( is_dir($element) )
{
//$tab_folders[] = $element;
$obj->setType('folder');
//$tableau[] = $obj;
}
if( is_file($element) )
{
//$tab_files[] = $element;
$obj->setType('file');
// $tableau[] = $obj;
}
$tableau_content[] = $obj;
}
*/
$tableau_content = array();
echo "Search ....... " .$dirPath ."<br>";
$dir = $dirPath;
$directories = array();
$files_list = array();
$files = scandir($dir);
foreach($files as $file)
{
if(($file != '.') && ($file != '..'))
{
$obj = new fileObject();
$obj->setName($file);
if(is_dir($dir.'/'.$file))
{
$directories[] = $file;
$obj->setType('folder');
$tableau_repertoires[] = $obj;
//echo " ---- " .$file . " folder" ."<br>";
}
else
{
$files_list[] = $file;
$obj->setType('file');
$tableau_fichiers[] = $obj;
$obj->setSize( get_filesize(filesize( $dirPath ."/" .$file)) );
//echo " ---- " .$file . " file " .filesize($file) ."<br>";
}
$tableau_content[] = $obj;
}
}
$tableau_concatenate = array_merge( $tableau_repertoires, $tableau_fichiers);
// echo "<pre>";
// var_dump($tableau_concatenate);
// echo "<pre>";
foreach($files as $element)
{
if(($element != '.') && ($element != '..'))
{
/* $obj = new fileObject();
$obj->setName($element);
if(is_dir($dir.'/'.$file))
{
//$directories[] = $file;
$obj->setType('folder');
echo " ---- " .$element . " folder" ."<br>";
}
else
{
//$files_list[] = $file;
$obj->setType('file');
echo " ++++ " .$element . " file" ."<br>";
}
$tableau_content[] = $obj;*/
}
}
// echo "<pre>";
// var_dump($tableau_content);
// echo "<pre>";
/********************************/
// $filesize = fm_get_filesize($filesize_raw);
/*
$root_path = $_SERVER['DOCUMENT_ROOT'];
echo $root_path;
$dirPath = $root_path ."/Fusion";
$scan = scandir($dirPath);
$tab_folders = array();
$tab_files = array();
foreach ($scan as $element)
{
if( is_dir($element) )
{
$tab_folders[] = $element;
}
if( is_file($element) )
{
$tab_files[] = $element;
}
}
echo "<pre>";
print_r($tab_folders);
echo "</pre>";
echo "<pre>";
print_r($tab_files);
echo "</pre>";
*/
/*$arrFiles = array();
$files = scandir($dirPath);
foreach ($files as $file)
{
$filePath = $dirPath . '/' . $file;
if (is_file($filePath))
{
echo $file . "<br>";
}
}*/
// open this directory
$myDirectory = opendir($dirPath);
// get each entry
while($entryName = readdir($myDirectory))
{
$dirArray[] = $entryName;
}
// close directory
closedir($myDirectory);
// count elements in array
//$indexCount = count($dirArray);
//Print ("$indexCount files<br>\n");
// sort 'em
sort($dirArray);
/*for ($i = 0; $i < count($dirArray); $i++)
{
echo $dirArray[$i] ."<br>";
}*/
/*if (file_exists($filename)) {
echo "The file $filename exists";
}*/
// print 'em
/*
print("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks>\n");
print("<TR><TH>Filename</TH><th>Filetype</th><th>Filesize</th></TR>\n");
// loop through the array of files and print them all
for($index=0; $index < $indexCount; $index++) {
if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files
//print("<TR><TD><a href=\"$dirArray[$index]\">$dirArray[$index]</a></td>");
// il faut faire la différence entre un répertoire et un fichier !!!
print("<TR><TD><a href=\"arbo_test.php?pipo=$dirArray[$index]\">$dirArray[$index]</a></td>");
print("<td>");
print(filetype($dirArray[$index]));
print("</td>");
print("<td>");
print(filesize($dirArray[$index]));
print("</td>");
print("</TR>\n");
}
}
print("</TABLE>\n");
*/
echo "<br>";
echo "<br>";
echo "<table id='table_to_highlight' border=1 cellpadding=5 cellspacing=0 class=whitelinks>";
echo "<tr>";
echo "<th><input type='checkbox' onclick='toggle(this);'></th>";
echo "<th>Filename</th>";
echo "<th>Filetype</th><th>Filesize</th>";
echo "</tr>";
for($index=0; $index < count($tableau_concatenate); $index++)
{
//if (substr("$dirArray[$index]", 0, 1) != ".")
//{ // don't list hidden files
//print("<TR><TD><a href=\"$dirArray[$index]\">$dirArray[$index]</a></td>");
// il faut faire la différence entre un répertoire et un fichier !!!
$numerotation = $index + 1;
$champ = "CK" .$numerotation;
$blase = $tableau_concatenate[$index]->getName();
//$blase = $blase . " +++ ";
echo "<tr>";
echo "<td>";
echo "<input type='checkbox' id='$champ' value = '$blase' >";
// onclick='abc()'
echo "</td>";
echo "<td>";
echo "<a href=\"arbo_test.php?pipo=$blase\">$blase</a>";
echo "</td>";
echo "<td>";
echo $tableau_concatenate[$index]->getType();
echo "</td>";
if( $tableau_concatenate[$index]->getName() != "..")
{
print("<td>");
echo $tableau_concatenate[$index]->getSize();
print("</td>");
}
else
{
echo "<td>";
echo "";
echo "</td>";
}
echo "</tr>";
//}
}
echo "</table>\n";
echo "<br>";
echo "<br>";
echo "<input type='button' id='btn_selection' onclick='test_checkbox()' value='Validation'>";
echo "<br>";
echo "<br>";
echo "<input type='button' id='test' onclick='tutu()' value='Check'>";
$dir = $dirPath;
$directories = array();
$files_list = array();
$files = scandir($dir);
foreach($files as $file){
if(($file != '.') && ($file != '..')){
if(is_dir($dir.'/'.$file)){
$directories[] = $file;
}else{
$files_list[] = $file;
}
}
}
foreach($directories as $directory)
{
echo '<li class="folder">'.$directory.'</li>';
}
echo "<br>";
echo "<br>";
echo "<br>";
foreach($files_list as $file_list)
{
echo '<li class="file">'.$file_list.'</li>';
}
function get_filesize($size)
{
if ($size < 1000) {
return sprintf('%s B', $size);
} elseif (($size / 1024) < 1000) {
return sprintf('%s KiB', round(($size / 1024), 2));
} elseif (($size / 1024 / 1024) < 1000) {
return sprintf('%s MiB', round(($size / 1024 / 1024), 2));
} elseif (($size / 1024 / 1024 / 1024) < 1000) {
return sprintf('%s GiB', round(($size / 1024 / 1024 / 1024), 2));
} else {
return sprintf('%s TiB', round(($size / 1024 / 1024 / 1024 / 1024), 2));
}
}
function removeLastDir($path, $level)
{
if (is_int($level) && $level > 0) {
$path = preg_replace('#\/[^/]*$#', '', $path);
return $this->removeLastDir($path, (int)$level - 1);
}
return $path;
}
?>