1.
<?php
2.
3.
/*
4.
5.
Formulaire d'édition pour la table : event.
6.
7.
07/03/2021 10:45
8.
9.
lvardon@laposte.net - 2021
10.
11.
Licence libre
12.
13.
*/
14.
15.
include_once "dbconnect.php";
16.
include_once "phpdb/class_event.php";
17.
include_once "phpdb/class_event_ext.php";
18.
19.
if (isset($_REQUEST['a_id_value'])) $id=$_REQUEST['a_id_value'];
20.
else
21.
if (isset($_REQUEST['id'])) $id=$_REQUEST['id'];
22.
else die("Erreur : _REQUEST['id'] est manquant.");
23.
24.
if (isset($_REQUEST['offset']))
25.
$offset=$_REQUEST['offset'];
26.
else
27.
$offset = '';
28.
29.
$userUiMessage="";
30.
31.
// Class instance
32.
$myevent = new event( $db );
33.
34.
35.
36.
$sqlError = false;
37.
38.
// Sauvegarde
39.
if(isset($_POST['submitSave']))
40.
{
41.
if ($id > 0) {
42.
$results = $myevent->update(
43.
$_REQUEST["a_id"],
44.
$_REQUEST["a_name"],
45.
$_REQUEST["a_description"],
46.
$_REQUEST["a_private"],
47.
$_REQUEST["a_date_begin"],
48.
$_REQUEST["a_date_begin_accurate"],
49.
$_REQUEST["a_notesearch"],
50.
$_REQUEST["a_datecreated"],
51.
$_REQUEST["a_person_1_id"],
52.
$_REQUEST["a_person_2_id"],
53.
$_REQUEST["a_person_3_id"],
54.
$_REQUEST["a_eventtype_id"],
55.
$_REQUEST["a_place_id"] );
56.
57.
if ($results === false) {
58.
$userUiMessage .= '<div class="editmessageError">Erreur sauvegarde (id='.$id.') :'.$myevent->lasterror.'</div>';
59.
$sqlError = true;
60.
}
61.
else
62.
$userUiMessage .= '<div class="editmessageInfo">Sauvegarde effectuée (id='.$id.')</div>';
63.
}
64.
else
65.
{
66.
$results = $myevent->insert(
67.
$_REQUEST["a_name"],
68.
$_REQUEST["a_description"],
69.
$_REQUEST["a_private"],
70.
$_REQUEST["a_date_begin"],
71.
$_REQUEST["a_date_begin_accurate"],
72.
$_REQUEST["a_notesearch"],
73.
$_REQUEST["a_datecreated"],
74.
$_REQUEST["a_person_1_id"],
75.
$_REQUEST["a_person_2_id"],
76.
$_REQUEST["a_person_3_id"],
77.
$_REQUEST["a_eventtype_id"],
78.
$_REQUEST["a_place_id"] );
79.
echo '<div class="editmessage">';
80.
if ($results === false) {
81.
$userUiMessage .= '<div class="editmessageError">Erreur de création :'.$myevent->lasterror.'</div>';
82.
$sqlError = true;
83.
}
84.
else {
85.
$id=$myevent->lastInsertId;
86.
$userUiMessage .= '<div class="editmessageInfo">Création effectuée (id='.$id.')</div>';
87.
}
88.
}
89.
}
90.
91.
// Suppression
92.
if(isset($_POST['submitDelete']))
93.
{
94.
if ($id > 0) {
95.
$results = $myevent->delete( $id );
96.
97.
if ($results === false) {
98.
$userUiMessage .= '<div class="editmessageError">Erreur Suppression (id='.$id.') :'.$myevent->lasterror.'</div>';
99.
$sqlError = true;
100.
}
101.
else {
102.
$userUiMessage .= '<div class="editmessageInfo">Suppression effectuée (id='.$id.')</div>';
103.
$id = -1;
104.
}
105.
106.
}
107.
}
108.
109.
// Select reccord by id :
110.
if ($sqlError === false ) {
111.
112.
if ( isset($_POST['submitSave']) || isset($_POST['submitDelete']) )
113.
$results = $myevent->select( $id );
114.
else {
115.
switch ($offset) {
116.
case '_PREV':
117.
$results = $myevent->selectPrev( $id );
118.
$id = $results[0]['a.id'];
119.
break;
120.
case '_NEXT':
121.
$results = $myevent->selectNext( $id );
122.
$id = $results[0]['a.id'];
123.
break;
124.
default:
125.
$results = $myevent->select( $id );
126.
break;
127.
}
128.
}
129.
130.
if ($results === false) {
131.
$userUiMessage .= '<div class="editmessageError">Erreur Sql : '.$myevent->lasterror.'</div>';
132.
$sqlError = true;
133.
}
134.
/*if ( empty($results) ) {
135.
$userUiMessage .= '<div class="editmessageInfo">Cet enregistrement n\'existe plus. id = '.$id.' </div>';
136.
$sqlError = true;
137.
}
138.
*/
139.
}
140.
else {
141.
$results[0]["a.id"] = $_REQUEST['a_id'];
142.
$results[0]["a.name"] = $_REQUEST['a_name'];
143.
$results[0]["a.description"] = $_REQUEST['a_description'];
144.
$results[0]["a.private"] = $_REQUEST['a_private'];
145.
$results[0]["a.date_begin"] = $_REQUEST['a_date_begin'];
146.
$results[0]["a.date_begin_accurate"] = $_REQUEST['a_date_begin_accurate'];
147.
$results[0]["a.notesearch"] = $_REQUEST['a_notesearch'];
148.
$results[0]["a.datecreated"] = $_REQUEST['a_datecreated'];
149.
$results[0]["a.person_1_id"] = $_REQUEST['a_person_1_id'];
150.
$results[0]["a.person_2_id"] = $_REQUEST['a_person_2_id'];
151.
$results[0]["a.person_3_id"] = $_REQUEST['a_person_3_id'];
152.
$results[0]["a.eventtype_id"] = $_REQUEST['a_eventtype_id'];
153.
$results[0]["a.place_id"] = $_REQUEST['a_place_id'];
154.
155.
}
156.
157.
$recordcount = $myevent->getCount();
158.
159.
echo '<div class="formtable">';
160.
161.
$protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https')
162.
=== FALSE ? 'http' : 'https';
163.
$host = $_SERVER['HTTP_HOST'];
164.
$script = $_SERVER['SCRIPT_NAME'];
165.
$params = $_SERVER['QUERY_STRING'];
166.
167.
$currentUrl = $protocol . '://' . $host . $script . '?' . $params;
168.
169.
// xxx fix enctype
170.
echo '<form id="editform" class="formedit pure-form pure-form-aligned" method="post" action="'.$currentUrl.'" enctype="multipart/form-data" >';
171.
172.
echo '<fieldset>';
173.
174.
echo '<legend style="display:inline-block" class="titleedit"><span title="Liste des évenements" class="titleedit">Evenement</span> #'.($id==-1?'?':$id).'/'.$recordcount['count'];
175.
176.
echo '<div style="font-size:80%; float:right; display:inline-block;">'.$userUiMessage.'</div>';
177.
178.
echo '</legend>';
179.
?>
180.
181.
<input type="hidden" readonly name="a.id.value" value="<?php echo $results[0]["a.id"]; ?>" >
182.
183.
<div class="pure-control-group"><label for="aligned-name">a_id</label>
184.
<input type="{{edithidden}}" readonly name="a.id" value="<?php echo $results[0]["a.id"]; ?>"
185.
style="width:12em;" ><span class="pure-form-message-inline"></span>
186.
</div>
187.
188.
<div class="pure-control-group"><label title="" for="aligned-name">a_name</label>
189.
190.
191.
192.
193.
<input type="text" class="" name="a.name" id="a_name"
194.
value="<?php if ( $results[0]["a.name"] !='') echo $results[0]["a.name"]; else echo ''; ?>"
195.
style="width:30em;"
196.
>
197.
<div style="display:inline-block; color:red">*</div>
198.
199.
200.
201.
<span class="pure-form-message-inline"></span>
202.
203.
</div>
204.
205.
<div class="pure-control-group"><label title="" for="aligned-name">a_description</label>
206.
207.
208.
209.
210.
<input type="text" class="" name="a.description" id="a_description"
211.
value="<?php if ( $results[0]["a.description"] !='') echo $results[0]["a.description"]; else echo ''; ?>"
212.
style="width:30em;"
213.
>
214.
<div style="display:inline-block; color:red"> </div>
215.
216.
217.
218.
<span class="pure-form-message-inline"></span>
219.
220.
</div>
221.
222.
<div class="pure-control-group"><label title="" for="aligned-name">a_private</label>
223.
224.
225.
226.
227.
<input type="checkbox" name="a.private"
228.
value="1"
229.
<?php echo ($results[0]["a.private"]==1?"checked='checked'":"") ?>
230.
>
231.
<div style="display:inline-block; color:red"> </div>
232.
233.
234.
<span class="pure-form-message-inline"></span>
235.
236.
</div>
237.
238.
<div class="pure-control-group"><label title="" for="aligned-name">a_date_begin</label>
239.
240.
241.
242.
243.
<input type="text" class="datepicker" name="a.date_begin" id="a_date_begin"
244.
value="<?php if ( $results[0]["a.date_begin"] !='') echo $results[0]["a.date_begin"]; else echo ''; ?>"
245.
style="width:9em;"
246.
>
247.
<div style="display:inline-block; color:red"> </div>
248.
249.
250.
251.
<span class="pure-form-message-inline"></span>
252.
253.
</div>
254.
255.
<div class="pure-control-group"><label title="" for="aligned-name">a_date_begin_accurate</label>
256.
257.
258.
259.
260.
<input type="text" class="" name="a.date_begin_accurate" id="a_date_begin_accurate"
261.
value="<?php if ( $results[0]["a.date_begin_accurate"] !='') echo $results[0]["a.date_begin_accurate"]; else echo ''; ?>"
262.
style="width:30em;"
263.
>
264.
<div style="display:inline-block; color:red"> </div>
265.
266.
267.
268.
<span class="pure-form-message-inline"></span>
269.
270.
</div>
271.
272.
<div class="pure-control-group"><label title="" for="aligned-name">a_notesearch</label>
273.
274.
275.
276.
277.
<input type="text" class="" name="a.notesearch" id="a_notesearch"
278.
value="<?php if ( $results[0]["a.notesearch"] !='') echo $results[0]["a.notesearch"]; else echo ''; ?>"
279.
style="width:30em;"
280.
>
281.
<div style="display:inline-block; color:red"> </div>
282.
283.
284.
285.
<span class="pure-form-message-inline"></span>
286.
287.
</div>
288.
289.
<div class="pure-control-group"><label title="" for="aligned-name">a_datecreated</label>
290.
291.
292.
293.
<span class="pure-form-message-inline"></span>
294.
295.
</div>
296.
297.
<div class="pure-control-group"><label title="" for="aligned-name">a_person_1_id</label>
298.
299.
300.
301.
302.
<input type="hidden" name="a.person_1_id" id="a_person_1_id"
303.
value="<?php echo $results[0]["a.person_1_id"]; ?>"
304.
style="width:20em;"
305.
>
306.
<input readonly type="text" style="width:{{fkeditlen}}em;" id="valback_a_person_1_id" value="<?php echo ($results[0]["b1.displayname"]) ;?>">
307.
<div style="display:inline-block; color:red">*</div>
308.
<a class="selectlist" valuetable="person" valuefield="id" valuebackfield="a_person_1_id" valuebackval="valback_a_person_1_id" href="#" >Select</a>
309.
310.
311.
<span class="pure-form-message-inline"></span>
312.
313.
</div>
314.
315.
<div class="pure-control-group"><label title="" for="aligned-name">a_person_2_id</label>
316.
317.
318.
319.
320.
<input type="hidden" name="a.person_2_id" id="a_person_2_id"
321.
value="<?php echo $results[0]["a.person_2_id"]; ?>"
322.
style="width:20em;"
323.
>
324.
<input readonly type="text" style="width:{{fkeditlen}}em;" id="valback_a_person_2_id" value="<?php echo ($results[0]["c2.displayname"]) ;?>">
325.
<div style="display:inline-block; color:red"> </div>
326.
<a class="selectlist" valuetable="person" valuefield="id" valuebackfield="a_person_2_id" valuebackval="valback_a_person_2_id" href="#" >Select</a>
327.
328.
329.
<span class="pure-form-message-inline"></span>
330.
331.
</div>
332.
333.
<div class="pure-control-group"><label title="" for="aligned-name">a_person_3_id</label>
334.
335.
336.
337.
338.
<input type="hidden" name="a.person_3_id" id="a_person_3_id"
339.
value="<?php echo $results[0]["a.person_3_id"]; ?>"
340.
style="width:20em;"
341.
>
342.
<input readonly type="text" style="width:{{fkeditlen}}em;" id="valback_a_person_3_id" value="<?php echo ($results[0]["d3.displayname"]) ;?>">
343.
<div style="display:inline-block; color:red"> </div>
344.
<a class="selectlist" valuetable="person" valuefield="id" valuebackfield="a_person_3_id" valuebackval="valback_a_person_3_id" href="#" >Select</a>
345.
346.
347.
<span class="pure-form-message-inline"></span>
348.
349.
</div>
350.
351.
<div class="pure-control-group"><label title="" for="aligned-name">a_eventtype_id</label>
352.
353.
354.
355.
356.
<input type="hidden" name="a.eventtype_id" id="a_eventtype_id"
357.
value="<?php echo $results[0]["a.eventtype_id"]; ?>"
358.
style="width:20em;"
359.
>
360.
<input readonly type="text" style="width:{{fkeditlen}}em;" id="valback_a_eventtype_id" value="<?php echo ($results[0]["e4.name"]) ;?>">
361.
<div style="display:inline-block; color:red">*</div>
362.
<a class="selectlist" valuetable="eventtype" valuefield="id" valuebackfield="a_eventtype_id" valuebackval="valback_a_eventtype_id" href="#" >Select</a>
363.
364.
365.
<span class="pure-form-message-inline"></span>
366.
367.
</div>
368.
369.
<div class="pure-control-group"><label title="" for="aligned-name">a_place_id</label>
370.
371.
372.
373.
374.
<input type="hidden" name="a.place_id" id="a_place_id"
375.
value="<?php echo $results[0]["a.place_id"]; ?>"
376.
style="width:20em;"
377.
>
378.
<input readonly type="text" style="width:{{fkeditlen}}em;" id="valback_a_place_id" value="<?php echo ($results[0]["f5.name"]) ;?>">
379.
<div style="display:inline-block; color:red"> </div>
380.
<a class="selectlist" valuetable="place" valuefield="id" valuebackfield="a_place_id" valuebackval="valback_a_place_id" href="#" >Select</a>
381.
382.
383.
<span class="pure-form-message-inline"></span>
384.
385.
</div>
386.
387.
<?
388.
389.
echo ' <div class="pure-controls">'."\n";
390.
echo '<button type="submit" name = "submitSave" class="formbutton xpure-button xpure-button-primary">Enregistrer</button>'."\n";
391.
$confirmBox = "onclick=\"return confirm('Etes vous sûr de vouloir supprimer cet article ?')\"";
392.
if ($id > 0)
393.
echo '<button type="submit" name = "submitDelete" class="formbutton xpure-button xpure-button-primary" '.$confirmBox.' >Supprimer</button>'."\n";
394.
395.
396.
parse_str($_SERVER['QUERY_STRING'], $query_string);
397.
398.
if ($id != -1 and $id > $recordcount['minid'] ) {
399.
$urlPrev='';
400.
$query_string['id'] = $id;
401.
$query_string['offset'] = '_PREV';
402.
$paramPrev = http_build_query($query_string);
403.
$urlPrev = $protocol . '://' . $host . $script . '?' . $paramPrev;
404.
echo "<a class='formbutton' href='$urlPrev'>Précédent</a>\n";
405.
}
406.
else echo "<a class='formbutton' style='color:gray; pointer-events: none' href=''>Précédent</a>\n";
407.
408.
if ($id != -1 and $id < $recordcount['maxid'] ) {
409.
$urlNext='';
410.
$query_string['id'] = $id;
411.
$query_string['offset'] = '_NEXT';
412.
$paramNext = http_build_query($query_string);
413.
$urlNext = $protocol . '://' . $host . $script . '?' . $paramNext;
414.
echo "<a class='formbutton' href='$urlNext'>Suivant</a>\n";
415.
}
416.
else echo "<a class='formbutton' style='color:gray; pointer-events: none' href=''>Suivant</a>\n";
417.
418.
419.
echo '</div>'."\n";
420.
echo '</fieldset>'."\n";
421.
echo '</form>'."\n";
422.
423.
echo '</div>';
424.
425.
?>
426.
427.
428.
<script type="text/javascript">
429.
430.
$(document).ready(function(){
431.
432.
$(".selectlist").on("click", function() {
433.
startModal('selectplaceholder');
434.
//alert("Id du champ à remplir au retour : [" + $(this).attr('valuebackval') + "]");
435.
var url = "phpui/select_" + $(this).attr('valuetable') + ".php?valuebackfield=" + $(this).attr('valuebackfield') + '&valuebackval=' + $(this).attr('valuebackval');
436.
437.
$('#selectplaceholder').load(url, function() {
438.
$('#selectplaceholder').css("background-color", "white");
439.
$('#selectplaceholder').css("border", "1px solid #034668");
440.
//box-shadow: 5px 10px 12px -4px rgba(0,0,0,0.75);
441.
//-webkit-box-shadow: 5px 10px 12px -4px rgba(0,0,0,0.75);
442.
//-moz-box-shadow: 5px 10px 12px -4px rgba(0,0,0,0.75);
443.
$('#selectplaceholder').css("box-shadow", "5px 10px 12px -4px rgba(0,0,0,0.75)");
444.
$('#selectplaceholder').css("border-radius", "7px");
445.
});
446.
447.
});
448.
});
449.
450.
function startModal(id) {
451.
$("body").prepend(
452.
"<div id='PopupMask' style='position:fixed;width:100%;height:100%;z-index:10;background-color:gray;'></div>"+
453.
"<div style='position: fixed;top: 50%;left: 50%; transform: translate(-50%, -50%);' "+
454.
"id='selectplaceholder'><img width='180' height='60' src='img/loading.gif'></div>");
455.
$("#PopupMask").css('opacity', 0.5);
456.
$("#"+id).data('saveZindex', $("#"+id).css( "z-index"));
457.
$("#"+id).data('savePosition', $("#"+id).css( "position"));
458.
$("#"+id).css( "z-index" , 11 );
459.
$("#"+id).css( "position" , "fixed" );
460.
}
461.
462.
</script>
463.
464.
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
465.
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
466.
467.
<script>
468.
469.
// Disable autofill
470.
$(".datepicker").prop("autocomplete", "off");
471.
472.
$( function() {
473.
474.
$.datepicker.regional['fr'] = {
475.
yearRange: '1:2099',
476.
changeMonth: true,
477.
changeYear: true,
478.
closeText: 'Fermer',
479.
prevText: '<Préc',
480.
nextText: 'Suiv>',
481.
currentText: 'Aujourd\'hui',
482.
monthNames: ['Janvier','Fevrier','Mars','Avril','Mai','Juin',
483.
'Juillet','Aout','Septembre','Octobre','Novembre','Decembre'],
484.
monthNamesShort: ['Jan','Fev','Mar','Avr','Mai','Jun',
485.
'Jul','Aou','Sep','Oct','Nov','Dec'],
486.
dayNames: ['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'],
487.
dayNamesShort: ['Dim','Lun','Mar','Mer','Jeu','Ven','Sam'],
488.
dayNamesMin: ['Di','Lu','Ma','Me','Je','Ve','Sa'],
489.
weekHeader: 'Sm',
490.
dateFormat: 'dd/mm/yy',
491.
firstDay: 1,
492.
/*isRTL: false,*/
493.
/*showMonthAfterYear: false,*/
494.
/*yearSuffix: '',*/
495.
/*minDate: 0,*/
496.
/*maxDate: '+12M +0D',*/
497.
numberOfMonths: 1,
498.
showButtonPanel: true
499.
};
500.
501.
$.datepicker.setDefaults($.datepicker.regional['fr']);
502.
503.
$(".datepicker" ).datepicker().on("show", function() {
504.
var formDate = $(this).val()
505.
$(this).val(formDate).datepicker('update');
506.
});
507.
508.
} );
509.
510.
$("#over").remove();
511.
512.
// Page quit confirmation
513.
var form = $('#editform'),
514.
original = form.serialize()
515.
516.
form.submit(function(){
517.
$('body').append('<div id="over" style="background:rgba(0,0,0, 0.05); position:fixed; top:0; left:0; width:100%; height:100%;"> <img style="position:absolute; top:0; left:0; right:0; bottom:0; margin:auto;" width="180" height="60" src="img/loading.gif"> </div> ');
518.
window.onbeforeunload = null
519.
})
520.
521.
window.onbeforeunload = function(){
522.
if (form.serialize() != original)
523.
return "Confirmez-vous l'abandon de vos modifications ?"
524.
}
525.
526.
</script>
527.
528.