File "arbo_test04.php"

Full Path: /home/analogde/www/Design/fileman/Fusion/arbo_test04.php
File size: 23.48 KB
MIME-type: text/x-php
Charset: utf-8

<?php

    session_start();

   

    echo " +++++++ "  .getcwd();
    echo "<br>";
    echo "<br>";
    echo "<br>";


   // echo 'Referrer is ' . $_SERVER['HTTP_REFERER'] . '<br>';
  
  /* function goback()
{
	header("Location: {$_SERVER['HTTP_REFERER']}");
	//exit;
}

goback();*/

    ///$_SERVER['HTTP_REFERER']
    // https://www.tutorialspoint.com/how-to-stop-browser-s-back-button-using-javascript
    // How to Disable Browser Back Button using JavaScript

    // https://stackoverflow.com/questions/50712560/how-to-prevent-a-php-page-from-browser-back-button

    $file = "pipo.html";
    $file = "GANTT";

    $file = $_SERVER['DOCUMENT_ROOT'] ."/Fusion/GANTT";
   if(is_dir($file)) {
  echo ("$file is a directory");
} else {
  echo ("$file is not a directory");
}

$file = $_SERVER['DOCUMENT_ROOT'] ."/Fusion/pipo.html";
if(is_file($file)) {
echo ("$file is a file");
} else {
echo ("$file is not a file");
}

    $root_path = $_SERVER['DOCUMENT_ROOT'];
    $dirReference = $root_path ."/Fusion";

/*    
	$file_path = $dirReference ."/" ."road-1072823_1280.jpg";
    $ext = strtolower(pathinfo($file_path, PATHINFO_EXTENSION));
    echo "<br>";
    echo $ext;
    echo "<br>";
    $mime_type = get_mime_type($file_path);
    echo  $mime_type;
    echo "<br>";

    $is_zip = false;
    $is_image = false;
    $is_audio = false;
    $is_video = false;
    $is_text = false;

    if (in_array($ext, get_image_exts()))
     {
        $is_image = true;
        $view_title = 'Image';
        echo $is_image ." " .$view_title;
    }
    if(in_array($ext, get_text_exts()) ) //|| substr($mime_type, 0, 4) == 'text' || in_array($mime_type, fm_get_text_mimes())) {
    {    $is_text = true;
        $content = file_get_contents($file_path);
    }    
   */ 
?>

<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;
}      

.noselected {
    background-color: #5555;
}    

.newRow
{
  color: #dd0000;
  background-color:#ffd700;
}

.blankcell {
    background: none!important; 
    border: none!important;
}
/*


header('Content-Type: image/gif');
$image= file_get_contents('http://localhost/no_img.gif');
echo $image;?>  

https://cyberzoide.developpez.com/php4/file/

        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

https://www.w3schools.com/jsref/coll_table_rows.asp

https://1bestcsharp.blogspot.com/2017/03/javascript-change-selected-html-table-row-background-color.html

https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_table_rows_index

https://www.dofactory.com/html/tr/style

https://stackoverflow.com/questions/17335496/alternate-row-colors-in-javascript

*/
    /* OK mais recouvre le mode hover et les selections */
    /*tr:nth-child(odd) { background-color: lightblue; }
      tr:nth-child(even) {background-color: lightgreen;}
    */  
   

</style>



<script type="text/javascript"> 


function disableBack()
{ window.history.forward(); }
//setTimeout("disableBack()", 0);
//window.onunload = function () { null };

  
        // 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; 
                   // document.getElementById("table_to_highlight").rows[i].style.background = selected;
                   // document.getElementById('t2').style.backgroundColor=color3;

                    //x[i].innerHTML = "NEW CONTENT";
                   
                }    
            } 

            
            selectedRow();
} 

function plouf(element)
{
    //alert("Bingo...");

    //var x = document.getElementById("table_to_highlight").rows[element].cells;
    //                x.className = "newRow";
    //                console.log(x);

    /*if(  element.style == "selected")
    {
        element.classList.toggle("noselected");
        alert("annule");
    }
    else 
    {
                     element.classList.toggle("selected");
                     alert("flash");
    }  */               

    element.classList.toggle("selected");
}


function selectedRow(){
                
                var index,
                table = document.getElementById("table_to_highlight");
            
                for(var i = 1; i < table.rows.length; i++)
                {
                    //table.rows[i].onclick = function()
                    //{
                         // remove the background from the previous selected row
                        //if(typeof index !== "undefined"){
                        //   table.rows[index].classList.toggle("selected");
                        //}
                        //console.log(typeof index);
                        // get the selected row index
                        var index = this.rowIndex;
                        // add class selected to the row
                        //console.log("message....");
                        //this.classList.toggle("selected");
                        //console.log(typeof index);

                        table.rows[i].classList.toggle("selected");
                     //};
                }
                
            }
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'])) 
    {

        // que contient  $_GET['pipo'] ?

          

        if ($_GET['pipo'] != "..")
        {
            $dirPath =  $_SESSION['dirpath'] ."/" .$_GET['pipo'];

            if( is_dir($dirPath))
            {
                echo "<br>";
                echo " Folder >>>> " . $dirPath;
                echo "<br>";

                $_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
            {
                //is_file($dirPath)
                $file_path =  $_SESSION['dirpath'] ."/" .$_GET['pipo'];
                echo "<br>";
                echo " File ------->>>> " . $file_path;
                echo "<br>";

                analyse($file_path);
                
            }    
        }

        else
        {
            //if(is_dir($_GET['pipo'])) 
            //{
              
                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;
                }
            //}
            //else
            //{
            //    echo "Il s'agit d'un fichier !!!!";
            //    echo "<br>";
            //}    

        }

       // 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);

  

    /********************************/

    // $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);

    echo "<br>";
    echo "<br>";

    echo "<table id='table_to_highlight' border=1 cellpadding=5 cellspacing=0 class=whitelinks>";
    // la classe bloque les highlight sur la ligne des titres (header)
    echo "<tr class='blankcell'>";
    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 onclick='plouf(this)'>";

        echo "<td>";
        echo "<input type='checkbox'  id='$champ' value = '$blase'  >";
        // onclick='abc()'
        echo "</td>";

        $typeFile = $tableau_concatenate[$index]->getType();

        echo "<td>";
        echo "<a href=\"arbo_test04.php?pipo=$blase&typefile=$typeFile\">$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'>";

function listing()   
{
    $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;
}

function analyse($file_path)
{

    $ext = strtolower(pathinfo($file_path, PATHINFO_EXTENSION));
    echo "<br>";
    echo $ext;
    echo "<br>";
    $mime_type = get_mime_type($file_path);
    echo  $mime_type;
    echo "<br>";

    $is_zip = false;
    $is_image = false;
    $is_audio = false;
    $is_video = false;
    $is_text = false;

    if (in_array($ext, get_image_exts()))
     {
        $is_image = true;
        $view_title = 'Image';
        echo $is_image ." " .$view_title;

        //$image = 'http://www.google.com/doodle4google/images/d4g_logo_global.jpg';
        $imageData = base64_encode(file_get_contents($file_path));
        echo '<img src="data:image/jpeg;base64,'.$imageData.'">';

        // header('Content-type: image/jpeg');
        //echo file_get_contents($file_path);

        //header('Content-Type: image/jpeg');
        //readfile($file_path);

    }
    if(in_array($ext, get_text_exts()) ) //|| substr($mime_type, 0, 4) == 'text' || in_array($mime_type, fm_get_text_mimes())) {
    {    $is_text = true;
         $content = file_get_contents($file_path);

       echo '<textarea class="numbered" readonly style="resize:none;" rows="4" cols="50" width="400px" height="400px">' . htmlspecialchars($content). '</textarea>';

    }    

echo " ================ ";
/*
    //if($ext == "pdf")
    //{
        echo "Bingo .......................";
        
        $file_path = "/home/analogde/www/Fusion/dmPDF.pdf";

        header('Content-type: application/pdf'); 
  
        header('Content-Disposition: inline; filename="' . $file_path . '"'); 
  
        header('Content-Transfer-Encoding: binary'); 
  
        header('Accept-Ranges: bytes'); 
  
        // Read the file 
        @readfile($file_path); 
    //}
*/
}

function get_mime_type($file_path)
{
    if (function_exists('finfo_open')) 
    {
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        $mime = finfo_file($finfo, $file_path);
        finfo_close($finfo);
        return $mime;
    } 
    elseif (function_exists('mime_content_type')) 
    {
        return mime_content_type($file_path);
    } 
    elseif (!stristr(ini_get('disable_functions'), 'shell_exec')) 
    {
        $file = escapeshellarg($file_path);
        $mime = shell_exec('file -bi ' . $file);
        return $mime;
    } 
    else 
    {
        return '--';
    }
}

function get_image_exts()
{
    return array('ico', 'gif', 'jpg', 'jpeg', 'jpc', 'jp2', 'jpx', 'xbm', 'wbmp', 'png', 'bmp', 'tif', 'tiff', 'psd');
}

function get_text_exts()
{
    return array(
        'txt', 'css', 'ini', 'conf', 'log', 'htaccess', 'passwd', 'ftpquota', 'sql', 'js', 'json', 'sh', 'config',
        'php', 'php4', 'php5', 'phps', 'phtml', 'htm', 'html', 'shtml', 'xhtml', 'xml', 'xsl', 'm3u', 'm3u8', 'pls', 'cue',
        'eml', 'msg', 'csv', 'bat', 'twig', 'tpl', 'md', 'gitignore', 'less', 'sass', 'scss', 'c', 'cpp', 'cs', 'py',
        'map', 'lock', 'dtd', 'svg',
    );
}

?>