File "editer.php"

Full Path: /home/analogde/www/Bookmarks/CHESS_ON/editer.php
File size: 6.28 KB
MIME-type: text/html
Charset: utf-8


<style>
 div.bloc {
   display: inline-block;
   width: 100px;
   border: 1px solid #000;
   margin:5px;
 }
</style>

<!--<div class="bloc" id="bloc1">Bloc 1</div>
Name: <input type="text" id="myText" value="Mickey">
-->

<!-- ce qu'il faut faire -->
<input type="hidden" id="msg" name="msg" value="rien" style="display:none"/>


<script type="text/javascript">

function getXhr()
{
			var xhr = null; 
			if(window.XMLHttpRequest) // Firefox et autres
			   xhr = new XMLHttpRequest(); 
			else if(window.ActiveXObject)
			{ // Internet Explorer 
			   try 
			   {
					xhr = new ActiveXObject("Msxml2.XMLHTTP");
			   } 
			   catch (e) 
			   {
					xhr = new ActiveXObject("Microsoft.XMLHTTP");
			   }
			}
			else 
			{ 
				// XMLHttpRequest non supporté par le navigateur 
				alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
				xhr = false; 
			} 

			return xhr;
}

function sauve_fichier()
{
					
			var xhr = getXhr();
								
			xhr.onreadystatechange = function()
			{
				if(xhr.readyState == 4 && xhr.status == 200)
				{
							retour = xhr.responseText;
							
							//alert(retour);
							
							 response.innerHTML = retour;
							
				}
			}

					
			xhr.open("POST","sauve_fichier.php",true);
					
			xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
					
			filename = document.getElementById('filename').value;
			data = document.getElementById('data').value;
			
			

			//xhr.send("J1="+J1+"&J2="+J2+"&jour="+jour+"&mois="+mois+"&annee="+annee+"&selection_date="+selection_date+"&selection_score="+selection_score);
			xhr.send("filename="+filename+"&data="+data);
					
			//alert(J1 + " " + J2 + " " + jour + " " + mois + " " + annee + " " + selection_score);
	
}


/*
function save()
{

	//var test = document.getElementById("msg").value ;
//
//	alert(test);
	
	
	var xxx = document.getElementById("blase").value ;

	alert(xxx);
	
	
	//var pipo = document.getElementById("myText").value ;

	//alert(pipo);
	
  // var ele = document.getElementById("myText").value = "Johnny Bravo";


	//const p = document.getElementById('message').value;

//	alert(ele);
	
	var number=document.getElementById("number").value;  

	var response=document.getElementById("response");
	var data = 'data='+document.getElementById("data").value;
	
	// var div=document.getElementById("bloc1").value;
	
	//	alert(div);
	
	//var filecopy = 'filecopy='+document.getElementById("filecopy").value;
	
	//alert(filecopy);
	
	var xmlhttp = new XMLHttpRequest();
	
	xmlhttp.onreadystatechange=function()
	{
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	  {
	    response.innerHTML='<a href="files/'+xmlhttp.responseText+'.txt">'+xmlhttp.responseText+'.txt</a>';
	  }
	}

	xmlhttp.open("POST","sauve_fichier.php",true);
    //Must add this request header to XMLHttpRequest request for POST
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	
	
	alert(data);
	
	
	//var params = 'data='+data+'&field2='+xxx;
	
	xmlhttp.send(data);
	
	//xmlhttp.send(params);
	
	
}
*/

/*
function sauver()
{
		
			
			var xhr = getXhr();
						
			xhr.onreadystatechange = function()
			{
				// on a tout reçu et le serveur est ok
				if(xhr.readyState == 4 && xhr.status == 200)
				{
					document.getElementById("message_patience").style.display='none';			
					$(function()
					{
									$( "#message_generation" ).dialog({
									modal: true,
									title: "Infos",
									buttons: {
												Ok: function()
												{
													$( this ).dialog( "close" );
													
												}
											 }
										});
					});
						
				}
			}

			xhr.open("POST","traitement_edition_DB.php",true);
			xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			
			contenu = document.getElementById('datas').value;
			
			//xhr.send("J1="+J1+"&J2="+J2+"&jour="+jour+"&mois="+mois+"&annee="+annee+"&selection_date="+selection_date+"&selection_score="+selection_score);
			xhr.send("datas="+contenu);
	
}
*/
</script>

<?php

	echo '<a href="' .$_SERVER['HTTP_REFERER'] .'">retour ...</a>';  
	echo "<br><br>";
/*
	//backup_auto-19-06-2022-07_55_00.txt
	
	$destination = getcwd() .'/insertion/' .$_GET['filename'];
	
	//echo "<br><br>";
	//echo "Destination " .$destination;
	
	chdir("backup");
	copy($_GET['filename'], $destination) ;
	chdir("..");
	
//	echo "<br><br>";
//	echo " --- " .getcwd(); 
//	echo "<br><br>";
	chdir("insertion");
//	echo "<br><br>";
//	echo " --- " .getcwd(); 
//	echo "<br><br>";
	
	$new_filename = $_GET['filename'];
	$pos = strpos($_GET['filename'], "auto");
	$str_len = strlen($_GET['filename']);
	$renamefile = "mofification_" .substr($_GET['filename'], $pos+5, $str_len); // auto- =5
	
//	echo " --- " .$renamefile;
	
	// fichier existe, on le supprime
	if (file_exists($renamefile)) 
	{
		unlink($renamefile);
	}
	rename($_GET['filename'], $renamefile);
	
	echo "Edition du fichier : " .$_GET['filename'];
	echo "<br><br>";
	echo "La modification est faite dans un fichier copie du backup : "  .$renamefile;
	echo "<br><br>";
	
	//echo " --- " .getcwd(); 
	//echo "<br><br>";
	//chdir("insertion");
	
	$f = fopen($renamefile, 'r');
	if ($f) 
	{
		$contents = fread($f, filesize($renamefile));
		fclose($f);
		//echo nl2br($contents);
	}
*/

	chdir("insertion");

	$f = fopen($_GET['filename'], 'r');
	if ($f) 
	{
		$contents = fread($f, filesize($_GET['filename']));
		fclose($f);
		//echo nl2br($contents);
	}

	$filename = $_GET['filename'];
	

	echo "<br><br>";
	
	echo "<input type='hidden' id='filename' name='filename' value='$filename' />";
	
	echo  '<textarea id="data" style="width:600;height:200;resize:none" >' .$contents .'</textarea>';
	
	/*echo "<br><br>";
	
	echo '<textarea id="data">Enter some content here you want to save as a file</textarea>';
	
	echo "<br><br>";*/
	
	//echo '<input id="sauve" name="sauve" type="submit" value="Enregistrer"   onclick="sauver()" />'; 
	
	echo "<br><br>";
	
	echo '<button id="Enregistrer" onclick="sauve_fichier();return false;">Save</button>';

	echo '<div id="response"></div>';
	
	///  http://techslides.com/save-file-with-ajax-and-php

	
?>