2021-10-14 17:58:21 +02:00
< ? php
2021-10-22 20:12:02 +02:00
2021-10-14 17:58:21 +02:00
require_once 'log.php' ;
2021-10-22 20:12:02 +02:00
require 'PHPMailer/Exception.php' ;
require 'PHPMailer/PHPMailer.php' ;
require 'PHPMailer/SMTP.php' ;
use PHPMailer\PHPMailer\PHPMailer ;
use PHPMailer\PHPMailer\SMTP ;
use PHPMailer\PHPMailer\Exception ;
2021-10-14 17:58:21 +02:00
if ( ! isset ( $site ) )
{
require_once ( " config.inc.php " );
header ( 'Location: ' . $accueil );
}
// $var clef à rechercher dans $_POST, $_GET, et $_SESSION (si $session=true)
// $default valeur retournée si aucune valeur n'est trouvée
// $session: si true, rechercher aussi dans $_SESSION
function getpost ( $var )
{
//echo '$var =>' . $var . "<br />";
if ( isset ( $_GET [ $var ]) )
{
//echo '$_get -> $var =>' . $var . "<br />";
return $_GET [ $var ];
}
elseif ( isset ( $_POST [ $var ]) )
{
//echo '$_POST -> $var =>' . $var . "<br />";
return $_POST [ $var ];
} else
{
2022-09-15 18:34:18 +02:00
return null ;
2021-10-14 17:58:21 +02:00
}
}
// MET LA PREMIÈRE LETTRE D'UN MOT EN MAJUSCULE ( utf8 compliant )
function mb_ucfirst ( $str )
{
$char = mb_substr ( $str , 0 , 1 , " UTF8 " );
$str = mb_substr ( $str , 1 , NULL , " UTF8 " );
$char = mb_strtoupper ( $char , " UTF8 " );
return $char . $str ;
}
2022-09-25 23:06:35 +02:00
function choixVote ( $path , $idVotation , $confirm = false )
{
$db = new db ();
$query = " SELECT * FROM liste_votes WHERE idVotation= " . $idVotation ;
$result = $db -> query ( $query );
$votes = $db -> result -> fetch_all ( MYSQLI_ASSOC );
print ( '<form method="get" action="' . $path . '">' );
print " <pre> " ;
print '<input type="hidden" name="idVotation" value="' . $idVotation . '"/>' ;
foreach ( $votes as $key => $value )
{
2022-09-25 23:21:14 +02:00
print '<input type="radio" name="idVote" value="' . $value [ " id " ] . '"/> ' . $value [ " libelle " ] . '<br>' ;
2022-09-25 23:06:35 +02:00
}
// TODO confirmation du choix par javascript si $confirm = true
print ' </ pre >< br >
< div >
< input type = " submit " value = " Envoyer " />
< input type = " submit " formaction = " index.php " value = " ' . _( " Annuler " ) . ' " />
</ div >
</ form > ' ;
$db -> close ();
}
2022-09-19 12:59:40 +02:00
function choixVotation ( $path , $methode = 2 , $confirm = true ) //2 = toutes les votations 0 = votations en cours 1 = votations cloturées
2021-10-14 17:58:21 +02:00
{
2022-09-19 12:04:33 +02:00
$db = new db ();
2021-10-14 17:58:21 +02:00
$query = " SELECT * FROM liste_votations " ;
if ( $methode != 2 )
{
$query .= " where status= " . $methode ;
}
$result = $db -> query ( $query );
$votations = $db -> result -> fetch_all ( MYSQLI_ASSOC );
2022-09-14 14:09:04 +02:00
2023-03-16 15:23:41 +01:00
//print ('<form method="get" action="' . $path . '">');
//print "<pre>";
2021-10-14 17:58:21 +02:00
foreach ( $votations as $key => $value )
{
2023-03-16 15:23:41 +01:00
//print '<input type="radio" name="id" value="' . $value["id"] . '"/> ' . $value["titre"] . ' :' . $value["libelle"] . '<br>';
2023-03-16 16:24:09 +01:00
print '<a href="' . $path . '?id=' . $value [ " id " ] . '">' . $value [ " libelle " ] . '</a><br>' ;
2021-10-14 17:58:21 +02:00
}
2022-09-15 18:34:18 +02:00
// TODO confirmation du choix par javascript si $confirm = true
2023-03-16 15:23:41 +01:00
/* print ' </ pre >< br >
2022-09-19 12:54:22 +02:00
< div >
< input type = " submit " value = " Envoyer " />
< input type = " submit " formaction = " index.php " value = " ' . _( " Annuler " ) . ' " />
</ div >
</ form > ' ;
2023-03-16 15:23:41 +01:00
*/
2022-09-19 12:13:09 +02:00
$db -> close ();
2021-10-14 17:58:21 +02:00
}
2022-09-19 12:13:09 +02:00
function votationForm ( $path , $titre = " " , $libelle = " " , $dateDebut = " " , $dateFin = " " , $status = 0 )
2021-10-14 17:58:21 +02:00
{
2022-09-15 11:44:34 +02:00
//TODO vérification du formulaire en javascript
print ( '<form method="get" action="' . $path . '">' );
2022-09-19 12:13:09 +02:00
print ( '<input type="hidden" name="status" value="' . $status . '">' );
2022-09-19 10:39:13 +02:00
print ( '<label for="titre">' . _ ( " Titre " ) . '</label><br><input type="text" id="titre" name="titre" value="' . $titre . '"/>' ) . EOLH ;
print ( '<label for="libelle">' . _ ( " Description " ) . '</label><br><input type="text" id="libelle" name="libelle" value="' . $libelle . '"/>' ) . EOLH ;
print ( '<label for="dateDebut">' . _ ( " Date de début de la période de vote " ) . '</label><br><input type="date" id="dateDebut" name="dateDebut" value="' . $dateDebut . '"/>' ) . EOLH ;
print ( '<label for="dateFin">' . _ ( " Date de fin de la période de vote " ) . '</label><br><input type="date" id="dateFin" name="dateFin" value="' . $dateFin . '"/>' ) . EOLH ;
print ( '<input type="submit" formaction="index.php" value="' . _ ( " Annuler " ) . '"/>' ) . EOLH ;
print ( '<input type="submit" value="' . _ ( " Envoyer " ) . '"/>' ) . EOLH ;
2022-09-15 18:34:18 +02:00
}
function votesForm ( $path , $libelle = " " , $method = 0 )
{
$db = new db ();
2022-09-15 20:23:56 +02:00
$query = " SELECT * FROM methods " ; // clotûre
2022-09-15 18:34:18 +02:00
$db -> query ( $query );
2022-09-15 18:43:24 +02:00
$methods = $db -> result -> fetch_all ( MYSQLI_ASSOC );
2022-09-15 18:34:18 +02:00
if ( ! ( array_key_exists ( $method , $methods )))
{
print ( _ ( " L'ID de la méthode demandée n'est pas bonne " . __file__ . __LINE__ ));
log_error ( _ ( " L'ID de la méthode demandée n'est pas bonne " . __file__ . __LINE__ ), true , true );
}
2022-09-15 20:49:16 +02:00
2022-09-15 18:34:18 +02:00
//TODO vérification du formulaire en javascript
2022-09-15 21:20:49 +02:00
print ( '<form method="get" action="' . $path . '">' . EOL );
2022-09-19 10:39:13 +02:00
print ( '<label for="libelle">' . _ ( " Libellé du vote " ) . '</label><br><input type="text" id="libelle" name="libelle" value="' . $libelle . '"/>' ) . EOLH ;
2022-09-15 18:34:18 +02:00
print ( '<label for="method">' . _ ( " Méthode de vote " ) . ' </ label >< br >
2022-09-19 10:28:44 +02:00
< select id = " method " name = " method " value = " '. $method . ' " > ' ) . EOL ;
2022-09-15 18:34:18 +02:00
if ( $method == 0 )
{
2022-09-19 11:06:53 +02:00
print ( '<option value ="">' . _ ( " Choisissez une option " ) . '</option>' ) . EOL ;
2022-09-15 18:34:18 +02:00
}
2022-09-15 20:49:16 +02:00
foreach ( $methods as $value )
2022-09-15 18:34:18 +02:00
{
2022-09-15 20:49:16 +02:00
$id = $value [ " id " ];
2022-09-21 21:05:44 +02:00
if ( $id == $method )
2022-09-15 18:34:18 +02:00
{
2022-09-19 10:31:45 +02:00
print ( '<option value ="' . $id . '" selected>' . $value [ " libelle " ] . '</option>' . EOL );
2022-09-15 18:34:18 +02:00
} else
{
2022-09-19 10:31:45 +02:00
print ( '<option value ="' . $id . '">' . $value [ " libelle " ] . '</option>' . EOL );
2022-09-15 18:34:18 +02:00
}
}
2022-09-19 10:31:45 +02:00
print ( " </select> " ) . EOLH ;
2022-09-19 10:39:13 +02:00
print ( '<input type="submit" formaction="index.php" value="' . _ ( " Annuler " ) . '"/>' ) . EOL ;
print ( '<input type="submit" value="' . _ ( " Envoyer " ) . '"/>' ) . EOL ;
2022-09-19 10:17:07 +02:00
print ( '</form>' ) . EOL ;
2022-09-19 12:04:33 +02:00
$db -> close ();
2022-09-15 11:44:34 +02:00
}
2021-10-22 20:12:02 +02:00
2022-09-26 10:45:12 +02:00
function candidatsForm ( $path , $idVotation , $idVote )
{
//TODO vérification du formulaire en javascript
print ( '<form method="get" action="' . $path . '">' );
print ( '<input type="hidden" name="idVotation" value="' . $idVotation . '">' );
print ( '<input type="hidden" name="idVote" value="' . $idVote . '">' );
print ( '<label for="candidat">' . _ ( " Candidat " ) . '</label><br><input type="text" id="candidat" name="candidat" value=""/>' ) . EOLH ;
2022-09-26 11:39:41 +02:00
print ( '<label for="libelle">' . _ ( " Libellé " ) . '</label><br><input type="text" id="libelle" name="libelle" value=""/>' ) . EOLH ;
2022-09-26 10:45:12 +02:00
print ( '<input type="submit" formaction="index.php" value="' . _ ( " Annuler " ) . '"/>' ) . EOLH ;
print ( '<input type="submit" value="' . _ ( " Envoyer " ) . '"/>' ) . EOLH ;
}
2021-10-22 20:12:02 +02:00
function envoiMail ( $destinataire , $sujet , $text , $html = false , $cc = '' , $bcc = '' )
{
//require 'vendor/autoload.php';
$mail = new PHPMailer ( true );
try {
if ( $html )
{
// setParameters() takes an associative array
$str = nl2br ( $text );
$text = " <html><head></head> \n <body> " . $str . " </body></html> " ;
log_write ( __FILE__ . EOL . __LINE__ . EOL . wordwrap ( $text , 1000 , " \r \n " ), INFO );
$mail -> isHTML ( true );
$mail -> AltBody = 'Ceci est un messssage HTML' ;
} else
{
//$mail->isHTML(false);
$text = str_replace ( " \n " , " \r \n " , $text );
}
//Server settings
//$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail -> isSMTP (); //Send using SMTP
$mail -> Host = 'mail.gandi.net' ; //Set the SMTP server to send through
$mail -> SMTPAuth = true ; //Enable SMTP authentication
$mail -> Username = 'contact@lalis.fr' ; //SMTP username
$mail -> Password = 'Gu>V$fiM{bQ^!x+FAHF+R.}bl' ; //SMTP password
$mail -> SMTPSecure = PHPMailer :: ENCRYPTION_SMTPS ; //Enable implicit ssl encryption
$mail -> Port = 465 ; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
$mail -> MessageDate = '' ;
$mail -> SMTPKeepAlive = true ;
//Recipients
$mail -> setFrom ( 'contact@lalis.fr' );
$mail -> addAddress ( $destinataire ); //Add a recipient
//$mail->addReplyTo('info@example.com', 'Information');
$mail -> CharSet = PHPMailer :: CHARSET_UTF8 ;
$mail -> Body = $text ;
//Attachments
//$mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name
//Content
//Set email format to HTML
$mail -> Subject = $sujet ;
$mail -> send ();
echo 'Message has been sent' ;
log_write ( __FILE__ . EOL . __LINE__ . EOL . " Le courriel est parti: " . $destinataire . EOL . $sujet . EOL , INFO );
} catch ( Exception $e ) {
echo " Message could not be sent. Mailer Error: { $mail -> ErrorInfo } " ;
log_error ( __FILE__ . EOL . __LINE__ . EOL . " Le courriel n'est pas parti: " . $destinataire . EOL . $sujet . EOL . print_r ( $mail -> ErrorInfo , true ) . EOL . wordwrap ( $text , 1000 , " \r \n " ));
$mail -> getSMTPInstance () -> reset ();
return false ;
}
return true ;
2021-10-14 17:58:21 +02:00
}
function formatteDate ( $locale , $date , $tz )
{
$formatter = new IntlDateFormatter ( $locale , IntlDateFormatter :: LONG , IntlDateFormatter :: NONE , $tz , IntlDateFormatter :: GREGORIAN );
$datetime = new DateTime ();
$datetime -> setTimestamp ( $date );
if ( $formatter == null )
{
log_write ( __FILE__ . EOLH . __LINE__ . EOLH . " Formatter error : locale = " . $locale . " tz = " . $tz . " Formatter = " . print_r ( $formatter , true ) . InvalidConfigException ( intl_get_error_message ()), ERROR );
}
return $formatter -> format ( $datetime );
}
2021-10-22 20:12:02 +02:00
function listeAdherents ()
{
$dolibarr = new dbDolibarr ();
$query = 'SELECT login, firstname, lastname FROM llx_adherent' ;
$dolibarr -> query ( $query );
while ( $adherent = $dolibarr -> result -> fetch_array ())
{
$listeAdherents [ $adherent [ 'login' ]] = $adherent [ 'firstname' ] . ' ' . $adherent [ 'lastname' ];
}
$dolibarr -> close ();
return $listeAdherents ;
}
function listeVotants ( $idVotation , $idVote , $listeAdherents )
{
2021-10-23 01:27:50 +02:00
$nv = 0 ;
$text = '' ;
2022-10-19 15:51:41 +02:00
$db = new db ();
2022-09-19 12:04:33 +02:00
$db -> open ();
2021-10-22 20:12:02 +02:00
$query = " SELECT DISTINCT idVotant FROM votes WHERE idVotation= " . $idVotation . ' AND idVote=' . $idVote ;
$result = $db -> query ( $query );
2021-10-23 01:27:50 +02:00
2021-10-22 20:12:02 +02:00
while ( $idVotants = $db -> result -> fetch_assoc ())
{
2021-10-23 01:27:50 +02:00
$nv ++ ;
$text .= $listeAdherents [ $idVotants [ 'idVotant' ]] . EOLH ;
2021-10-22 20:12:02 +02:00
}
2021-10-23 01:27:50 +02:00
print ( 'Nombre de votants : ' . $nv . EOLH . '<div id="listeVotants' . $idVote . '" style="display: none; line-height: 0.8;">' . $text . '</div>' );
print ( '<button id="button' . $idVote . '" onclick="show(\'listeVotants\',\'' . $idVote . '\')">Voir la liste des votants</button>' . EOLH );
2022-09-19 12:04:33 +02:00
$db -> close ();
2021-10-22 20:12:02 +02:00
}
2022-09-29 11:32:23 +02:00
function printLine ( $path , $request , $libelle , $modif = true , $delete = false )
{
print ( '<a href="' . $vote_url . $path . $request . '>' . $libelle . '</a>' );
if ( $modif ) print ( '<a href=""' );
}
2021-10-14 17:58:21 +02:00
?>