Skip to content

Commit

Permalink
ajout : quota sur les réservations par formulaire
Browse files Browse the repository at this point in the history
  • Loading branch information
ynaessens committed May 7, 2020
1 parent 651b07a commit 0144685
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 106 deletions.
37 changes: 25 additions & 12 deletions admin/admin_config1.php
Expand Up @@ -3,7 +3,7 @@
* admin_config1.php
* Interface permettant à l'administrateur la configuration de certains paramètres généraux
* Ce script fait partie de l'application GRR.
* Dernière modification : $Date: 2020-03-27 18:50$
* Dernière modification : $Date: 2020-05-07 10:13$
* @author Laurent Delineau & JeromeB & Bouteillier Nicolas & Yan Naessens
* @copyright Copyright 2003-2020 Team DEVOME - JeromeB
* @link http://www.gnu.org/licenses/licenses.html
Expand Down Expand Up @@ -184,10 +184,10 @@
die();
}
}
// display_beneficicaire
if (isset($_POST['display_beneficicaire'])) {
if (!Settings::set('display_beneficicaire', $_POST['display_beneficicaire'])) {
echo "Erreur lors de l'enregistrement de display_beneficicaire !<br />";
// display_beneficiaire
if (isset($_POST['display_beneficiaire'])) {
if (!Settings::set('display_beneficiaire', $_POST['display_beneficiaire'])) {
echo "Erreur lors de l'enregistrement de display_beneficiaire !<br />";
die();
}
}
Expand Down Expand Up @@ -277,11 +277,18 @@
}

if (isset($_POST['mail_etat_destinataire'])) {
if (!Settings::set('mail_etat_destinataire', $_POST['mail_etat_destinataire'])) {
if (!Settings::set('mail_etat_destinataire', clean_input($_POST['mail_etat_destinataire']))) {
echo "Erreur lors de l'enregistrement de mail_etat_destinataire !<br />";
die();
}
}

if (isset($_POST['nb_max_resa_form'])){
if (!Settings::set('nb_max_resa_form', clean_input($_POST['nb_max_resa_form']))) {
echo "Erreur lors de l'enregistrement de nb_max_resa_form !<br />";
die();
}
}
// gestion_lien_aide
if (isset($_POST['gestion_lien_aide'])) {
if (($_POST['gestion_lien_aide'] == 'perso') && (trim($_POST['lien_aide']) == '')) {
Expand Down Expand Up @@ -1008,8 +1015,9 @@ function modifier_liste_ressources(action){
echo '</td>'.PHP_EOL;
echo '</tr>'.PHP_EOL;
echo '</table>'.PHP_EOL;
#mail_destinataire = 0 //Le formulaire de contact est désactivé (0 par défaut)
#mail_destinataire = 1 //Le formulaire de contact est activé
#mail_etat_destinataire = 0 //Le formulaire de contact est désactivé (0 par défaut)
#mail_etat_destinataire = 1 //Le formulaire de contact est activé
#mail_etat_destinataire = 2 //Le formulaire de contact est activé uniquement pour les visiteurs connectés
echo '<hr />'.PHP_EOL;
echo '<h3>'.get_vocab('display_mail_etat_destinataire').'</h3>'.PHP_EOL;
echo '<p>'.get_vocab('display_mail_etat_destinataire_1').'</p>'.PHP_EOL;
Expand Down Expand Up @@ -1051,6 +1059,11 @@ function modifier_liste_ressources(action){
echo '<input class="form-control" type="text" id="mail_destinataire" name="mail_destinataire" value="'.Settings::get('mail_destinataire').'" size="30">'.PHP_EOL;
echo '</td>'.PHP_EOL;
echo '</tr>'.PHP_EOL;
echo '<tr><td>'.PHP_EOL;
echo get_vocab('nb_max_resa_form');
echo '</td><td>'.PHP_EOL;
echo '<input type="number" name="nb_max_resa_form" value="'.Settings::get('nb_max_resa_form').'" size="5" min="-1" />'.PHP_EOL;
echo '</td></tr>'.PHP_EOL;
echo '</table>'.PHP_EOL;
// modification du formulaire de choix, reste à internationaliser
echo '<section id="display_planning_resa">';
Expand All @@ -1064,11 +1077,11 @@ function modifier_liste_ressources(action){
echo ' <tbody>';
echo ' <tr>';
echo ' <td>'.get_vocab('sum_by_creator').'</td>';
echo ' <td><input type="radio" name="display_beneficicaire" value="0"';
if (Settings::get('display_beneficicaire') == '0') echo 'checked="checked"';
echo ' <td><input type="radio" name="display_beneficiaire" value="0"';
if (Settings::get('display_beneficiaire') == '0') echo 'checked="checked"';
echo ' /></td>';
echo ' <td><input type="radio" name="display_beneficicaire" value="1"';
if (Settings::get('display_beneficicaire') == '1') echo 'checked="checked"';
echo ' <td><input type="radio" name="display_beneficiaire" value="1"';
if (Settings::get('display_beneficiaire') == '1') echo 'checked="checked"';
echo ' /></td>';
echo ' </tr>';
echo ' <tr>';
Expand Down
9 changes: 7 additions & 2 deletions contactFormulaire.php
Expand Up @@ -3,7 +3,7 @@
* contactFormulaire.php
* Formulaire d'envoi de mail demandant une réservation
* Ce script fait partie de l'application GRR
* Dernière modification : $Date: 2020-05-06 18:35$
* Dernière modification : $Date: 2020-05-07 11:25$
* @author JeromeB & Yan Naessens
* @copyright Copyright 2003-2020 Team DEVOME - JeromeB
* @link http://www.gnu.org/licenses/licenses.html
Expand Down Expand Up @@ -33,7 +33,12 @@

// pour le traitement des modules
include "./include/hook.class.php";

// contrôle d'accès pour limiter les demandes
if (!acces_formulaire_reservation()){
begin_page('','','','no_session');
showAccessDenied(page_accueil());
die();
}
// code HTML
header('Content-Type: text/html; charset=utf-8');
if (!isset($_COOKIE['open']))
Expand Down
25 changes: 21 additions & 4 deletions include/functions.inc.php
Expand Up @@ -2,7 +2,7 @@
/**
* include/functions.inc.php
* fichier Bibliothèque de fonctions de GRR
* Dernière modification : $Date: 2020-05-05 18:37$
* Dernière modification : $Date: 2020-05-07 11:00$
* @author JeromeB & Laurent Delineau & Marc-Henri PAMISEUX & Yan Naessens
* @copyright Copyright 2003-2020 Team DEVOME - JeromeB
* @link http://www.gnu.org/licenses/licenses.html
Expand Down Expand Up @@ -4570,7 +4570,7 @@ function affichage_resa_planning_complet($vue, $resa, $heures)
$affichage .= "<br>".$resa[15];

// Bénéficiaire
if (Settings::get("display_beneficicaire") == 1)
if (Settings::get("display_beneficiaire") == 1)
$affichage .= "<br>".affiche_nom_prenom_email($resa[4], $resa[12], "nomail");

// Type
Expand Down Expand Up @@ -5603,9 +5603,8 @@ function pageHeader2($day = '', $month = '', $year = '', $type_session = 'with_s
//Mail réservation
$sql = "SELECT value FROM ".TABLE_PREFIX."_setting WHERE name='mail_etat_destinataire'";
$res = grr_sql_query1($sql);
grr_sql_free($res);

if ( ( $res == 1 && $type_session == "no_session" ) || ( ( $res == 1 || $res == 2) && $type_session == "with_session" && (authGetUserLevel(getUserName(), -1, 'area')) == 1 ) )
if ((( $res == 1 && $type_session == "no_session" ) || ( ( $res == 1 || $res == 2) && $type_session == "with_session" && (authGetUserLevel(getUserName(), -1, 'area')) == 1 ) )&& acces_formulaire_reservation())
{
echo '<div class="contactformulaire">',PHP_EOL,'<input class="btn btn-default" type="submit" rel="popup_name" value="Réserver" onClick="javascript:location.href=\'contactFormulaire.php?day=',$day,'&amp;month=',$month,'&amp;year=',$year,'\'" >',PHP_EOL,'</div>',PHP_EOL;
}
Expand Down Expand Up @@ -5824,6 +5823,24 @@ function clean_input($data){
$data = htmlspecialchars($data);
return $data;
}

/* fonction acces_formulaire_reservation
* détermine si le quota de réservations par formulaire non modérées est atteint
* rend TRUE ou FALSE (y compris si l'accès à la base est impossible)
*/
function acces_formulaire_reservation(){
if (!Settings::get('nb_max_resa_form'))
return FALSE;
else {
$quota = grr_sql_query1("SELECT COUNT(*) FROM ".TABLE_PREFIX."_entry WHERE (entry_type = -1 AND moderate = 1)");
// echo $quota;
if ($quota == -1)
return FALSE;
else
return ((Settings::get('nb_max_resa_form') - $quota) > 0);
}
}

// Les lignes suivantes permettent la compatibilité de GRR avec la variable register_global à off
unset($day);
if (isset($_GET["day"]))
Expand Down
3 changes: 2 additions & 1 deletion language/lang.de
@@ -1,7 +1,7 @@
<?php
# GRR: Translations provided by: Karsten Schinkel, Jean-Yves Migeon - jeanyves.migeon@free.fr
# GRR : fichier de langue allemande
# Last modification : 2020-05-05
# Last modification : 2020-05-07
# Charset (jeu de caractères) utilisé dans l'en-tête des pages HTML
$charset_html = "utf-8";
$vocab = array();
Expand Down Expand Up @@ -1073,4 +1073,5 @@ $vocab["no_restricted_room"] = "No restricted room has been defined";
$vocab["no_room_selected"] = "No room has been selected";
$vocab['user_can_book'] = "can book the restricted rooms:";
$vocab['cycle_cplt'] = "Check to select all the days in the cycle";
$vocab['nb_max_resa_form'] = "Max. number of pending reservations via contact form (-1 if no restriction) :";
?>
3 changes: 2 additions & 1 deletion language/lang.en
@@ -1,7 +1,7 @@
<?php
# GRR: Translations provided by: Patricia Gaubert-Dubois et Yan Naessens
# GRR : fichier de langue anglaise
# Last modification : 2020-05-05
# Last modification : 2020-05-07
# Charset (jeu de caractères) utilisé dans l'en-tête des pages HTML
$charset_html = "utf-8";
$vocab = array();
Expand Down Expand Up @@ -1084,4 +1084,5 @@ $vocab["no_restricted_room"] = "No restricted room has been defined";
$vocab["no_room_selected"] = "No room has been selected";
$vocab['user_can_book'] = "can book the restricted rooms:";
$vocab['cycle_cplt'] = "Check to select all the days in the cycle";
$vocab['nb_max_resa_form'] = "Max. number of pending reservations via contact form (-1 if no restriction) :";
?>
3 changes: 2 additions & 1 deletion language/lang.es
@@ -1,6 +1,6 @@
<?php
# GRR : fichier de langue espagnole
# Last modification : 2020-05-05
# Last modification : 2020-05-07
# Charset (jeu de caractères) utilisé dans l'en-tête des pages HTML
$charset_html = "utf-8";
$vocab = array();
Expand Down Expand Up @@ -1068,4 +1068,5 @@ $vocab["no_restricted_room"] = "No restricted room has been defined";
$vocab["no_room_selected"] = "No room has been selected";
$vocab['user_can_book'] = "can book the restricted rooms:";
$vocab['cycle_cplt'] = "Check to select all the days in the cycle";
$vocab['nb_max_resa_form'] = "Max. number of pending reservations via contact form (-1 if no restriction) :";
?>
3 changes: 2 additions & 1 deletion language/lang.fr
@@ -1,6 +1,6 @@
<?php
# GRR : fichier de langue française
# Last modification : 2020-05-05
# Last modification : 2020-05-06
# Charset (jeu de caractères) utilisé dans l'en-tête des pages HTML
$charset_html = "utf-8";
$vocab = array();
Expand Down Expand Up @@ -1086,4 +1086,5 @@ $vocab["no_restricted_room"] = "Aucune ressource restreinte n'a été définie";
$vocab["no_room_selected"] = "Aucune ressource n'a été sélectionnée";
$vocab['user_can_book'] = "peut réserver les ressources restreintes :";
$vocab['cycle_cplt'] = "Sélectionner tous les jours du cycle";
$vocab['nb_max_resa_form'] = "Nombre maximum de réservations par formulaire en attente (-1 si pas de restriction) :";
?>
3 changes: 2 additions & 1 deletion language/lang.it
@@ -1,7 +1,7 @@
<?php
# GRR: Translations provided by: Marc HENNETIER and Antony AUDOUARD
# GRR : fichier de langue italienne
# Last modification : 2020-05-05
# Last modification : 2020-05-07
# Charset (jeu de caractères) utilisé dans l'en-tête des pages HTML
$charset_html = "utf-8";
$vocab = array();
Expand Down Expand Up @@ -1065,4 +1065,5 @@ $vocab["no_restricted_room"] = "No restricted room has been defined";
$vocab["no_room_selected"] = "No room has been selected";
$vocab['user_can_book'] = "can book the restricted rooms:";
$vocab['cycle_cplt'] = "Check to select all the days in the cycle";
$vocab['nb_max_resa_form'] = "Max. number of pending reservations via contact form (-1 if no restriction) :";
?>
95 changes: 12 additions & 83 deletions traitementcontact.php
Expand Up @@ -3,7 +3,7 @@
* traitementcontact.php
* envoie l'email suite au formulaire
* Ce script fait partie de l'application GRR
* Dernière modification : $Date: 2020-05-06 18:41$
* Dernière modification : $Date: 2020-05-07 11:24$
* @author Laurent Delineau & JeromeB & Yan Naessens
* @copyright Copyright 2003-2020 Team DEVOME - JeromeB
* @link http://www.gnu.org/licenses/licenses.html
Expand Down Expand Up @@ -31,6 +31,12 @@
if (!Settings::load())
die("Erreur chargement settings");
// $link = page_accueil();
// contrôle d'accès
if (!acces_formulaire_reservation()){
start_page_w_header('','','','no_session');
showAccessDenied(page_accueil());
die();
}
// vérification des paramètres
$msg_erreur = "Erreur. Les champs suivants doivent être obligatoirement remplis : \\n \\n ";
$msg_ok = "Votre demande a bien été prise en compte.";
Expand Down Expand Up @@ -74,11 +80,11 @@
}
else
fatal_error(0,"ne devrait pas être atteint");
echo $input['room'],'/',strftime("%c",$starttime),'/',strftime("%c",$endtime);
//echo $input['room'],'/',strftime("%c",$starttime),'/',strftime("%c",$endtime);
$plage_libre = mrbsCheckFree($input['room'],$starttime,$endtime,0,0);
echo '<br>'.$plage_libre ;
//echo '<br>'.$plage_libre ;
if ($plage_libre == ""){// la plage est libre, on pose une réservation modérée et on envoie un courrier
$entry_id = mrbsCreateSingleEntry($starttime, $endtime, 0, 0, $input['room'], '', '', $input['nom'].' '.$input['prenom'], $input['nom'].' '.$input['prenom'], 'A', $input['sujet'], -1,array(), 1, 0, '-', 0, 0);
$entry_id = mrbsCreateSingleEntry($starttime, $endtime, -1, 0, $input['room'], '', '', $input['nom'].' '.$input['prenom'].'|'.$input['email'], $input['nom'].' '.$input['prenom'], 'A', $input['sujet'], -1,array(), 1, 0, '-', 0, 0);
if ($entry_id != 0){ // l'insertion a réussi
$message = "réservation posée sous réserve";
// on envoie un message pour averir de la demande
Expand Down Expand Up @@ -108,7 +114,7 @@
while (($a = grr_sql_row($pnres, $i++)))
{ $periods_name[$i] = $a[0];}
}
print_r($periods_name);
//print_r($periods_name);
$start_period = isset($periods_name[$input['start']])? $periods_name[$input['start']] :"";
$mail_corps .= "Premier créneau : ". $start_period." \n";
$mail_corps .= "Durée de la réservation : ".$input['dureemin']." créneau(x) \n";
Expand All @@ -131,7 +137,7 @@
else
$message = "au moins une partie de la plage demandée est occupée";
}

// une page toute simple pour revenir au planning si on a suivi le chemin normal
echo '<!DOCTYPE html>
<html><body>
<script>
Expand All @@ -140,81 +146,4 @@
</script>
</body></html>';
die();

// recherche si la plage demandée est libre
$room_id = protect_data_sql($_POST['room']);
$starttime = mktime($_POST['heure'],$_POST['minutes'],0,$_POST['start_month'],$_POST['start_day'],$_POST['start_year']);
$endtime = $starttime + $_POST['duree']*3600 + $_POST['dureemin']*60;
$plage_libre = mrbsCheckFree($room_id,$starttime,$endtime,0,0);
if ($plage_libre != "") // la plage n'est pas libre
{
// echo "la plage est au moins partiellement occupée";
start_page_w_header('','','','no_session');
echo "<script type=\"text/javascript\">";
echo "<!--\n";
echo " alert(\"la plage est au moins partiellement occupée\");";
echo "window.location.assign('$link');";
echo "//-->";
echo "</script>";
end_page();
die();
}
else
{ // la plage est libre, on préréserve le créneau sous forme d'une réservation à modérer, à compléter
$id_resa = grr_sql_insert_id(); // récupère l'id de la résa juste créée -> mail au modérateur
echo "plage libre";
die();
}
// traitement des erreurs
$message = "ok?";
//if ($message != "")
//{
$message = $msg_erreur.$message;
echo "<br />".$message;
affiche_pop_up($message);
//die();
//}

foreach ($_POST as $index => $valeur)
$index = stripslashes(trim($valeur));
// $mail_entete n'est plus utilisé, phpmailer s'en charge
/* $mail_entete = "MIME-Version: 1.0\r\n";
$mail_entete .= "From: {$_POST['nom']} "
."<{$_POST['email']}>\r\n";
$mail_entete .= 'Reply-To: '.$_POST['email']."\r\n";
$mail_entete .= 'Content-Type: text/plain; charset="iso-8859-1"';
$mail_entete .= "\r\nContent-Transfer-Encoding: 8bit\r\n";
$mail_entete .= 'X-Mailer:PHP/' . phpversion()."\r\n"; */

$DE = $_POST['email']; // a été filtrée

$mail_corps = "<html><head></head><body> Message de :" .$_POST['prenom']." " .$_POST['nom'] . "<br/>";
$mail_corps .= "Email : ".$_POST['email']. "<br/>";
$mail_corps .= "Téléphone : ".$_POST['telephone']. "<br/><br/>";
$mail_corps .= "<b> Sujet de la réservation :".$_POST['sujet']. "</b><br/><br/>";

$id = $_POST['area'] ;
$sql_areaName = "SELECT area_name FROM ".TABLE_PREFIX."_area where id = \"$id\" ";
$res_areaName = grr_sql_query1($sql_areaName);
$mail_corps .= "Domaine : ".$res_areaName. "<br/> ";
$mail_corps .= "Salle : ".$_POST['room']. "<br/><br/>";
$mail_corps .= "Date :".$_POST['start_day']."/".$_POST['start_month']."/".$_POST['start_year']. " <br/>";
$mail_corps .= "Heure réservation : ".$_POST['heure']. "h ".$_POST['minutes']. "min<br/>";
$mail_corps .= "Durée de la réservation : ".$_POST['duree'];
$mail_corps .= " h ".$_POST['dureemin']. " min \n";
// ici insérer un lien de validation, cf functions.inc.php, ligne 2964
if (isset($id_resa)){
$mail_corps .="";
}
$mail_corps .= "</body></html>";
$sujet ="Réservation d'une salle";
$destinataire = Settings::get("mail_destinataire");

require_once 'phpmailer/PHPMailerAutoload.php';
require_once 'include/mail.class.php';

Email::Envois($destinataire, $sujet, $mail_corps, $DE, '', '');

// retour vers la page d'accueil
header('Location: '.$link);
?>

0 comments on commit 0144685

Please sign in to comment.