<?php
$options = array('welcome', 'contact', 'T3sT');
if(!isset($_POST['DATA_pages']))
$_POST['DATA_pages'] = $options[0];
if(!in_array($_POST['DATA_pages'], $options))
$_POST['DATA_pages'] = $options[0];
$filename = 'Pages/' . $_POST['DATA_pages'] . '.php';
if (isset($_POST['BUTTON_save'])) {
if(file_exists($filename))
{
file_put_contents($filename, $_POST['DATA_websiteContent']); // only works, if other user (www-data) has rw (6) rights
echo "<p>Changes saved successfully!</p>";
}
}
?>
<form method="POST" id="form-web-page-contents">
<label for="sel-pages">Please select a page to edit:</label>
<select name="DATA_pages" id="sel-pages" onchange="document.getElementById('form-web-page-contents').submit();">
<?php
foreach($options as $option){
echo '<option';
if($_POST['DATA_pages'] == $option)
{
echo ' selected="selected"';
}
echo '>' . $option . '</option>';
}
?>
</select>
<?php
/* echo "<pre>" . print_r($_POST, true) . "</pre>"; */
if (file_exists($filename)) {
$websiteContent = file_get_contents($filename);
?>
<br>
<textarea name="DATA_websiteContent" rows="20" cols="70"><?= $websiteContent ?></textarea>
<br>
<button type="submit" name="BUTTON_save">Save</button>
<?php
} else {
echo "<br>Sorry, the file $page does not exist on the server.";
}
?>
</form>