1
0
This repository has been archived on 2023-11-30. You can view files and clone it, but cannot push or open issues or pull requests.
dtux__serveur-vote-lalis/include/fonctions.inc.php

150 lines
4.2 KiB
PHP
Raw Normal View History

2021-10-14 17:58:21 +02:00
<?php
require_once 'log.php';
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
{
return;
}
}
// 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;
}
function getLang( $lang, $gestion=false )
{
$dico = array();
if ( empty($lang) )
{
$lang="en";
}
$langPath ='lang/'.$lang;
if ($gestion)
$langPath = "../" . $langPath;
if (($fh = fopen($langPath, 'r') ))
{
$str = fgets($fh);
fclose($fh);
$dico = json_decode($str, true);
return $dico;
}else
{
return false;
}
}
function choixVotation($path, $methode=2) //2 = toutes les votations 1 = votations en cours 0 = votations cloturées
{
global $db, $base_url, $action;
$query = "SELECT * FROM liste_votations";
if ($methode != 2)
{
$query .= " where status=" . $methode;
}
$result = $db->query($query);
$votations = $db->result->fetch_all(MYSQLI_ASSOC);
print ('<form method="get" action="gestionsite/modifVotation.php">');
print "<pre>";
if ($db->result->num_rows == 1)
{
$redirect = '<META HTTP-EQUIV=Refresh CONTENT="0; URL=' . $base_url . $path . '?id=' . $votations["0"]["id"];
if( !empty($action))
{
$redirect .= '&action=' . $action;
}
$redirect .= '">';
echo $redirect;
//header( 'Location: ' . $base_url . '/gestionsite/modifVotation.php?action=modif&id=' . $votations["0"]["id"]);
}
foreach($votations as $key => $value )
{
print '<input type="radio" name="id" value="' . $value["id"] . '"> ' . $value["titre"] . '&nbsp;:' . $value["libelle"] . '<br>';
}
print '</pre><br>
<div>
<input type="submit" value="Voter">
</div>
</form>';
}
function envoiMail($destinataire, $sujet, $text, $html=false, $cc='', $bcc='')
{
require_once 'swiftmailer/autoload.php';
//require_once 'include/swiftmailer/swiftmailer/lib/swift_init.php';
$transport = (new Swift_SmtpTransport('mail.gandi.net', 465, 'ssl'))
->setUsername('contact@lalis.fr')
->setPassword('Gu>V$fiM{bQ^!x+FAHF+R.}bl');
$mailer = new Swift_Mailer($transport);
$message = (new Swift_Message($sujet))
->setFrom(["contact@lalis.fr"])
->setTo([$destinataire])
->setCharset('utf-8');
$type = $message->getHeaders()->get('Content-Type');
if ($html)
{
// setParameters() takes an associative array
$type->setValue('text/html');
$type->setParameter('charset', 'utf-8');
$str = nl2br($text);
$text = "<html><head></head>\n<body>" . $str . "</body></html>";
log_write(__FILE__ . EOL . __LINE__ . EOL . wordwrap($text, 1000, "\r\n"), INFO);
}else
{
$type->setValue('text/plain');
$type->setParameter('charset', 'utf-8');
$text = str_replace("\n","\r\n", $text);
}
$message->setBody($text);
//add date header
$headers = $message->getHeaders();
$headers->addDateHeader('Your-Header', new DateTimeImmutable('3 days ago'));
if (!$mailer->send($message, $failures))
{
echo "Failures:";
print_r($failures);
log_write(__FILE__ . EOL . __LINE__ . EOL . "Le courriel n'est pas parti:" . $destinataire . EOL . $sujet . EOL . print_r($failure, true) . EOL . wordwrap($text, 1000 , "\r\n"), ERROR);
return false;
}
return true;
}
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 );
}
?>