La mise à jour d'un POI est cassée, le proxy élévation est cassé

This commit is contained in:
leosw
2026-01-18 20:07:49 +01:00
parent 0f502d6536
commit 454ccb7a65
5 changed files with 171 additions and 83 deletions

View File

@@ -56,7 +56,6 @@ switch ($controller->splitted_url[1]) {
}
}
$poi->parameters = json_encode($params, JSON_UNESCAPED_UNICODE);
if (!$poi->checkPermalink($_POST['permalink'], 1)) {
@@ -125,9 +124,44 @@ switch ($controller->splitted_url[1]) {
$poi->lat = $_POST['lat'];
$poi->lon = $_POST['lon'];
$poi->ele = $_POST['ele'];
$poi->is_commentable = isset($_POST['is_commentable']) ? 't' : 'f';
$poi->author = $user->id;
// $poi->parameters = ... // à remplir si tu veux éditer les champs dynamiques
$poi->source = "kab";
$poi->is_commentable = isset($_POST['is_commentable']) ? 't' : 'f';
$definition = $poi_types[$poi->poi_type][5];
$params = [];
foreach ($definition as $key => $label) {
if (isset($_POST[$key])) {
$value = $_POST[$key];
if (str_starts_with($key, 'b_')) {
// 3 états : 1 = oui, 0 = non, -1 = non renseigné
$params[$key] = ($value === "1" ? 1 :
($value === "0" ? 0 : -1));
}
elseif (str_starts_with($key, 'n_')) {
$params[$key] = is_numeric($value) ? (0 + $value) : null;
}
elseif (str_starts_with($key, 't_') || str_starts_with($key, 'l_')) {
$params[$key] = trim($value);
}
else {
$params[$key] = $value;
}
} else {
// Champ absent → booléen = -1 (non renseigné)
if (str_starts_with($key, 'b_')) {
$params[$key] = -1;
} else {
$params[$key] = null;
}
}
}
$poi->parameters = json_encode($params, JSON_UNESCAPED_UNICODE);
$poi->update();
header('Location: '.$config['rel_root_folder']."poi/".$poi->permalink);
} else {

View File

@@ -39,8 +39,8 @@ $poi_types = array(
't_access' => "🧭 Description de l'accès, des transports en commun, et d'éventuels passages délicats",
't_description' => "📝 Description sur le refuge et remarques",
'b_usable' => "🚫 Refuge condamné, détruit ou fermé ?",
'n_bed' => "Places en période gardée ☀️ :",
'n_bed_winter' => "Places en période non gardée ❄️ :",
'n_bed' => "☀️ Places en période gardée :",
'n_bed_winter' => "❄️ Places en période non gardée :",
'n_mattress' => "🛌 Matelas en période non gardée :",
'b_cover' => "🧣 Couvertures disponibles ?",
'b_water' => "💧 Possibilité de se ravitailler en eau ?",

View File

@@ -250,9 +250,9 @@ class Poi
pg_execute($con, "poi_insert_specs_update", array( $this->version_id, $this->lon, $this->lat, $this->ele, $this->source, $this->remote_source_id ));
// 4) Update is_commentable
$query = "UPDATE contents SET is_commentable = $1 WHERE id = $2";
$query = "UPDATE contents SET is_commentable = $1, poi_type = $2 WHERE id = $3";
pg_prepare($con, "poi_update_commentable", $query);
pg_execute($con, "poi_update_commentable", array( $this->is_commentable ? 't' : 'f', $this->content_id));
pg_execute($con, "poi_update_commentable", array( $this->is_commentable ? 't' : 'f', $this->poi_type, $this->content_id));
// 5) Add contributor
$query = "INSERT INTO content_contributors (content, contributor)

View File

@@ -548,7 +548,6 @@ form.form input[type="checkbox"]:checked + span:before {
}
.bool-row.labels {
font-weight: 600;
font-size: 16px;
}

View File

@@ -36,95 +36,150 @@
<div class="flex_line" id="type_selector">
<? foreach($poi_types as $type) { ?>
<input type="radio" name="poi_type" value="<?=$type[3]?>" id="<?=$type[3]?>" required>
<input type="radio" name="poi_type" value="<?=$type[3]?>" id="<?=$type[3]?>" required
<?=$poi->poi_type == $type[3] ? 'checked' : ''?>>
<label for="<?=$type[3]?>"><img src="<?=$config['views_url']?>img/<?=$type[3]?>.svg"><br><?=$type[0]?></label>
<? } ?>
</div>
<script type="text/javascript">
<?php
$poi_params = $poi->parameters ?? new stdClass();
?>
var poi_params = <?= json_encode($poi_params) ?>;
var current_poi_type = "<?= $poi->poi_type ?>";
var unsaved = false;
// Used to store all the forms skeleton and abstracts
// Stocke les abstracts et les squelettes de formulaire
<? foreach($poi_types as $type) { ?>
<?=$type[3]?>_abstract="<?=$type[4]?>";
<?=$type[3]?>_jsonform=<?=json_encode($type[5])?>;
window["<?=$type[3]?>_abstract"] = "<?=$type[4]?>";
window["<?=$type[3]?>_jsonform"] = <?=json_encode($type[5])?>;
<? } ?>
// Manages the three state checkbox feature
// 3 états : 0 = non, 1 = intermédiaire, 2 = oui
function update3State(id) {
var input = $("input[name="+id+"]");
var label = $("label[for="+id+"]");
switch (+input.val()) {
case 0:
input.val(1);
label.toggleClass('uncheck intermediate')
label.toggleClass('uncheck intermediate');
break;
case 1:
input.val(2);
label.toggleClass('intermediate check')
label.toggleClass('intermediate check');
break;
default:
input.val(0);
label.toggleClass('check uncheck')
label.toggleClass('check uncheck');
}
unsaved = true; // The form values changed
unsaved = true;
}
// Updates the specific form section when changing poi type
// Génère / met à jour le sous-formulaire selon le type
function updateForm(type) {
$("#abstract").html(this[type+'_abstract']); // Changes the abstract legend
$("#abstract").html(window[type + '_abstract']);
var html_form = "";
// Generates HTML for the sub-form
$.each(this[type+'_jsonform'],function(index, value){
switch(index.charAt(0)) {
var jsonform = window[type + '_jsonform'];
$.each(jsonform, function(index, value) {
var prefix = index.charAt(0);
var existing = (poi_params && typeof poi_params[index] !== 'undefined')
? poi_params[index]
: null;
switch (prefix) {
case 'b':
html_form+='<label class="threecb intermediate" for="'+index+'" onclick="update3State(\''+index+'\')">'+value+'</label><input value="1" type="hidden" name="'+index+'" id="'+index+'"><br>'
var cls = 'intermediate';
var val = 1;
if (existing === 0 || existing === "0") {
cls = 'uncheck';
val = 0;
} else if (existing === 2 || existing === "2") {
cls = 'check';
val = 2;
}
html_form +=
'<label class="threecb ' + cls + '" for="' + index + '" onclick="update3State(\'' + index + '\')">' +
value +
'</label>' +
'<input value="' + val + '" type="hidden" name="' + index + '" id="' + index + '"><br>';
break;
case 'n':
html_form+='<div class="flex_line"><label for="'+index+'">'+value+'</label><input min="0" type="number" name="'+index+'" id="'+index+'"></div>'
html_form +=
'<div class="flex_line">' +
'<label for="' + index + '">' + value + '</label>' +
'<input min="0" type="number" name="' + index + '" id="' + index + '" ' +
(existing !== null ? 'value="' + existing + '"' : '') +
'>' +
'</div>';
break;
case 't':
html_form+='<textarea name="'+index+'" id="'+index+'" placeholder="'+value+'"></textarea>'
html_form +=
'<textarea name="' + index + '" id="' + index + '" placeholder="' + value + '">';
if (existing !== null) {
html_form += String(existing)
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;");
}
html_form += '</textarea>';
break;
case 'l':
html_form+='<div class="flex_line"><label for="'+index+'">'+value+'</label><input placeholder="https://" type="url" name="'+index+'" id="'+index+'"></div>'
html_form +=
'<div class="flex_line">' +
'<label for="' + index + '">' + value + '</label>' +
'<input placeholder="https://" type="url" name="' + index + '" id="' + index + '" ' +
(existing ? 'value="' + existing + '"' : '') +
'>' +
'</div>';
break;
default:
console.log("ERROR: " + index + "'s type is not known");
}
});
$("#specific_form").html(html_form); // Updates HTML
// Display an alert if the poi type is changed before reseting the form
$("#specific_form").html(html_form);
unsaved = false;
$("#specific_form :input").change(function(){
unsaved = true;
});
}
// Handle click on type selector
$(document).ready(function(){
// First check if there is changes in the sub-form and if the user is OK to reset the form
// Au chargement : générer le formulaire du type actuel
if (current_poi_type) {
updateForm(current_poi_type);
}
$('#type_selector label').click(function(){
if(unsaved == true) {
if(confirm("Des changements ont été apportés et vont être supprimés, voulez-vous continuer ?")) {}
else {
return false; // Cancel radio switch action
if (unsaved === true) {
if (!confirm("Des changements ont été apportés et vont être supprimés, voulez-vous continuer ?")) {
return false;
}
}
// Updates the sub-form
updateForm($(this).prev().val());
const type = $(this).attr("for"); // robuste
current_poi_type = type;
updateForm(type);
});
});
</script>
<p id="abstract"></p>
<div id="specific_form"></div>
<label for="is_commentable">
<input type="checkbox" name="is_commentable" id="is_commentable" />
<input type="checkbox" name="is_commentable" id="is_commentable" <?=$poi->is_commentable ? 'checked' : ''?> />
<span>Autoriser les commentaires</span>
</label>
@@ -154,7 +209,7 @@ $( "#name" ).change(function() {
});
</script>
<input name="submit" id="submit" type="submit" value="Ajouter l'hébergement">
<input name="submit" id="submit" type="submit" value="<?= isset($new) && $new == 1 ? "Ajouter l'hébergement" : "Mettre à jour l'hébergement" ?>">
</form>
</section>