<?php
//_________________________________________________________________________________
//Récupère fichier
if(!isset($_GET['element']))
redirect('index.php');
$fileName = encrypt_decrypt("decrypt", rawurldecode($_GET['element']), $key_user, $iv_user);
$filePath = dirname(__FILE__, 2) .'/'. $_SESSION['current_application_folder_system'] .'/'. $fileName;
if(!file_exists($filePath)) {
//Test du chemin URI
$filePath = dirname(__FILE__, 3) .'/'. $fileName;
if(!file_exists($filePath)) {
itsLog(array('log_table' => "editor.php",
'log_operation' => "Ce fichier n'existe pas",
'log_request' => json_encode($fileName),
'log_response' => json_encode($filePath),
'log_color' => "danger",
'log_display' => 1,
'log_timeout' => 5000,
'user_id' => $user -> getUserId()
));
//Refresh
redirect('index.php');
}
}
//_________________________________________________________________________________
//_________________________________________________________________________________
//Modifie code du fichier fonction
if(isset($_POST['code'])) {
$content = $_POST['code'];
/*
//Suppression du fichier fonction actuelle (si existant)
$pathFile = $pathFolder . $filename;
$flag = unlink($pathFile);
//Création d'un nouveau fichier
$file = fopen($pathFolder . $filename, 'x');
fwrite($file, $content);
fclose($file);
*/
file_put_contents( $filePath, $content );
//Refresh
redirect($_SERVER['REQUEST_URI']);
}
//_________________________________________________________________________________
?>
<div class="content d-flex flex-column flex-column-fluid" id="kt_content">
<!--begin::Container-->
<div class="container-xxl" id="kt_content_container">
<div class="row">
<div class="col-8">
<!--begin::Card-->
<div class="card mb-6 mb-xl-9">
<form method="post" action="">
<!--begin::Card header-->
<div class="card-header mt-6">
<!--begin::Card title-->
<div class="card-title flex-column">
<h2 class="mb-1">Edition d'un fichier </h2>
<div class="fs-6 fw-bold text-muted">Editez le fichier <?= $fileName?></div>
</div>
<!--end::Card title-->
</div>
<!--end::Card header-->
<!--begin::Content-->
<div id="editor_container" class="collapse show">
<!--begin::Card body-->
<div class="card-body border-top px-9 py-9" style="height:850px;">
<!--begin::Editor-->
<?php
$content = htmlspecialchars(file_get_contents($filePath));
?>
<pre id="editor"><?= $content?></pre>
<!--end::Editor-->
</div>
<!--end::Card body-->
<!--begin::Card footer-->
<div class="card-footer d-flex justify-content-end py-6 px-9">
<button class="btn btn-primary px-6" type="button" id="update-function">Enregistrer</button>
</div>
<!--end::Card footer-->
</div>
<!--end::Content-->
</form>
</div>
<!--end::Card-->
</div>
<div class="col-4">
<!--begin::Card-->
<div class="card mb-6 mb-xl-9">
<form method="post" action="">
<!--begin::Card header-->
<div class="card-header mt-6">
<!--begin::Card title-->
<div class="card-title flex-column">
<h2 class="mb-1">Conseils et liens</h2>
<div class="fs-6 fw-bold text-muted">Liens vers des ressources utiles pour l'édition de fichier</div>
</div>
<!--end::Card title-->
</div>
<!--end::Card header-->
<!--begin::Content-->
<div class="card-body">
<ul>
<li>Mettre en forme du JSON <a href="https://jsonformatter.org" target="_blank">Editeur JSON en ligne</a></li>
<li>Icônes Bootstrap <a href="https://icons.getbootstrap.com" target="_blank">Librairie Bootstrap Icons</a></li>
</ul>
</div>
<!--end::Content-->
</form>
</div>
<!--end::Card-->
</div>
</div>
</div>
<!--end::Container-->
</div>