La mise à jour d'un POI est cassée, le proxy élévation est cassé
This commit is contained in:
@@ -56,7 +56,6 @@ switch ($controller->splitted_url[1]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$poi->parameters = json_encode($params, JSON_UNESCAPED_UNICODE);
|
$poi->parameters = json_encode($params, JSON_UNESCAPED_UNICODE);
|
||||||
|
|
||||||
if (!$poi->checkPermalink($_POST['permalink'], 1)) {
|
if (!$poi->checkPermalink($_POST['permalink'], 1)) {
|
||||||
@@ -125,9 +124,44 @@ switch ($controller->splitted_url[1]) {
|
|||||||
$poi->lat = $_POST['lat'];
|
$poi->lat = $_POST['lat'];
|
||||||
$poi->lon = $_POST['lon'];
|
$poi->lon = $_POST['lon'];
|
||||||
$poi->ele = $_POST['ele'];
|
$poi->ele = $_POST['ele'];
|
||||||
$poi->is_commentable = isset($_POST['is_commentable']) ? 't' : 'f';
|
|
||||||
$poi->author = $user->id;
|
$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();
|
$poi->update();
|
||||||
header('Location: '.$config['rel_root_folder']."poi/".$poi->permalink);
|
header('Location: '.$config['rel_root_folder']."poi/".$poi->permalink);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -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_access' => "🧭 Description de l'accès, des transports en commun, et d'éventuels passages délicats",
|
||||||
't_description' => "📝 Description sur le refuge et remarques",
|
't_description' => "📝 Description sur le refuge et remarques",
|
||||||
'b_usable' => "🚫 Refuge condamné, détruit ou fermé ?",
|
'b_usable' => "🚫 Refuge condamné, détruit ou fermé ?",
|
||||||
'n_bed' => "Places en période gardée ☀️ :",
|
'n_bed' => "☀️ Places en période gardée :",
|
||||||
'n_bed_winter' => "Places en période non gardée ❄️ :",
|
'n_bed_winter' => "❄️ Places en période non gardée :",
|
||||||
'n_mattress' => "🛌 Matelas en période non gardée :",
|
'n_mattress' => "🛌 Matelas en période non gardée :",
|
||||||
'b_cover' => "🧣 Couvertures disponibles ?",
|
'b_cover' => "🧣 Couvertures disponibles ?",
|
||||||
'b_water' => "💧 Possibilité de se ravitailler en eau ?",
|
'b_water' => "💧 Possibilité de se ravitailler en eau ?",
|
||||||
|
|||||||
@@ -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 ));
|
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
|
// 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_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
|
// 5) Add contributor
|
||||||
$query = "INSERT INTO content_contributors (content, contributor)
|
$query = "INSERT INTO content_contributors (content, contributor)
|
||||||
|
|||||||
@@ -548,7 +548,6 @@ form.form input[type="checkbox"]:checked + span:before {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.bool-row.labels {
|
.bool-row.labels {
|
||||||
font-weight: 600;
|
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,95 +36,150 @@
|
|||||||
|
|
||||||
<div class="flex_line" id="type_selector">
|
<div class="flex_line" id="type_selector">
|
||||||
<? foreach($poi_types as $type) { ?>
|
<? 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>
|
<label for="<?=$type[3]?>"><img src="<?=$config['views_url']?>img/<?=$type[3]?>.svg"><br><?=$type[0]?></label>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var unsaved = false;
|
<?php
|
||||||
|
$poi_params = $poi->parameters ?? new stdClass();
|
||||||
|
?>
|
||||||
|
|
||||||
// Used to store all the forms skeleton and abstracts
|
var poi_params = <?= json_encode($poi_params) ?>;
|
||||||
<? foreach($poi_types as $type) { ?>
|
var current_poi_type = "<?= $poi->poi_type ?>";
|
||||||
<?=$type[3]?>_abstract="<?=$type[4]?>";
|
|
||||||
<?=$type[3]?>_jsonform=<?=json_encode($type[5])?>;
|
|
||||||
<? } ?>
|
|
||||||
|
|
||||||
// Manages the three state checkbox feature
|
var unsaved = false;
|
||||||
function update3State(id) {
|
|
||||||
var input=$("input[name="+id+"]");
|
// Stocke les abstracts et les squelettes de formulaire
|
||||||
var label=$("label[for="+id+"]");
|
<? foreach($poi_types as $type) { ?>
|
||||||
switch(+input.val()) {
|
window["<?=$type[3]?>_abstract"] = "<?=$type[4]?>";
|
||||||
|
window["<?=$type[3]?>_jsonform"] = <?=json_encode($type[5])?>;
|
||||||
|
<? } ?>
|
||||||
|
|
||||||
|
// 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:
|
case 0:
|
||||||
input.val(1);
|
input.val(1);
|
||||||
label.toggleClass('uncheck intermediate')
|
label.toggleClass('uncheck intermediate');
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
input.val(2);
|
input.val(2);
|
||||||
label.toggleClass('intermediate check')
|
label.toggleClass('intermediate check');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
input.val(0);
|
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) {
|
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
|
var html_form = "";
|
||||||
$.each(this[type+'_jsonform'],function(index, value){
|
var jsonform = window[type + '_jsonform'];
|
||||||
switch(index.charAt(0)) {
|
|
||||||
|
$.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':
|
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;
|
break;
|
||||||
|
|
||||||
case 'n':
|
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;
|
break;
|
||||||
|
|
||||||
case 't':
|
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, "&")
|
||||||
|
.replace(/</g, "<")
|
||||||
|
.replace(/>/g, ">");
|
||||||
|
}
|
||||||
|
html_form += '</textarea>';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'l':
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.log("ERROR: "+index+"'s type is not known");
|
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;
|
unsaved = false;
|
||||||
$("#specific_form :input").change(function(){
|
$("#specific_form :input").change(function(){
|
||||||
unsaved = true;
|
unsaved = true;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function(){
|
||||||
|
// Au chargement : générer le formulaire du type actuel
|
||||||
|
if (current_poi_type) {
|
||||||
|
updateForm(current_poi_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
|
||||||
$('#type_selector label').click(function(){
|
$('#type_selector label').click(function(){
|
||||||
if(unsaved == true) {
|
|
||||||
if(confirm("Des changements ont été apportés et vont être supprimés, voulez-vous continuer ?")) {}
|
if (unsaved === true) {
|
||||||
else {
|
if (!confirm("Des changements ont été apportés et vont être supprimés, voulez-vous continuer ?")) {
|
||||||
return false; // Cancel radio switch action
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates the sub-form
|
const type = $(this).attr("for"); // robuste
|
||||||
updateForm($(this).prev().val());
|
current_poi_type = type;
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
updateForm(type);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
<p id="abstract"></p>
|
<p id="abstract"></p>
|
||||||
<div id="specific_form"></div>
|
<div id="specific_form"></div>
|
||||||
|
|
||||||
<label for="is_commentable">
|
<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>
|
<span>Autoriser les commentaires</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
@@ -154,7 +209,7 @@ $( "#name" ).change(function() {
|
|||||||
});
|
});
|
||||||
</script>
|
</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>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user