new parameter '$use_smtp' to disable email notification if needed

bug correction on email notification (using '$dsondage->titre' in adminstuds.php)
This commit is contained in:
Bob Le Bricodeur 2014-11-12 17:49:52 +01:00
parent e53043b232
commit eb5677e451
6 changed files with 83 additions and 60 deletions

View File

@ -76,21 +76,25 @@ if (!$sondage || $sondage->RecordCount() != 1){
$dsujet=$sujets->FetchObject(false);
$dsondage=$sondage->FetchObject(false);
// Send email (only once during the session) to alert admin of the change he made
// Send email (only once during the session) to alert admin of the change he made. ==> two modifications (comment, title, description, ...) on differents polls in the same session will generate only one mail.
$email_admin = $dsondage->mail_admin;
$poll_title = $dsondage->titre;
function send_mail_admin() {
global $email_admin;
global $poll_title;
global $numsondageadmin;
if(config_get('use_smtp')==true){
if(!isset($_SESSION["mail_admin_sent"])) {
Utils::sendEmail( $email_admin,
_("[ADMINISTRATOR] New settings for your poll") . ' ' . stripslashes( $poll_title ),
_("You have changed the settings of your poll. \nYou can modify this poll with this link") .
" :\n\n" . Utils::getUrlSondage($numsondageadmin, true) . "\n\n" .
_("Thanks for your confidence.") . "\n" . NOMAPPLICATION
);
$_SESSION["mail_admin_sent"]=true;
}
}
if(!isset($_SESSION["mail_admin_sent"])) {
Utils::sendEmail( $email_admin,
_("[ADMINISTRATOR] New settings for your poll") . ' ' . stripslashes( $dsondage->titre ),
_("You have changed the settings of your poll. \nYou can modify this poll with this link") .
" :\n\n" . Utils::getUrlSondage($numsondageadmin, true) . "\n\n" .
_("Thanks for your confidence.") . "\n" . NOMAPPLICATION
);
$_SESSION["mail_admin_sent"]=true;
}
}
//si la valeur du nouveau titre est valide et que le bouton est activé
@ -105,8 +109,10 @@ if (isset($_POST["boutonnouveautitre"])) {
//Email sent to the admin
if ($connect->Execute($sql, array($nouveautitre, $numsondage))) {
send_mail_admin();
}
//if(config_get('use_smtp')==true){
send_mail_admin();
//}
}
}
}

View File

@ -21,8 +21,8 @@
* general configuration
*/
//is a smtp server is configured to send e-mail ?
//$use_smtp = true;
//use email for polls creation/modification/responses notification
$use_smtp = true;
//if only one language is allowed in constants.php, $ALLOWED_LANGUAGES, the language selection bar is useless
$show_language_bar_selection = true;
@ -44,7 +44,7 @@
* choix_autre.php
*/
//default values for the new poll duration (number of days).
$default_poll_duration = 10;
$default_poll_duration = 30;
//user can add link or URL when creating his poll.
$user_can_add_link_or_url = false;

View File

@ -28,7 +28,7 @@ if (file_exists('bandeaux_local.php')) {
}
// Step 1/3 : error if $_SESSION from info_sondage are not valid
if (Utils::issetAndNoEmpty('titre', $_SESSION) === false || Utils::issetAndNoEmpty('nom', $_SESSION) === false || Utils::issetAndNoEmpty('adresse', $_SESSION) === false) {
if (Utils::issetAndNoEmpty('titre', $_SESSION) === false || Utils::issetAndNoEmpty('nom', $_SESSION) === false || ((config_get('use_smtp')) ? Utils::issetAndNoEmpty('adresse', $_SESSION) === false : false)) {
Utils::print_header ( _("Error!") );
bandeau_titre(_("Error!"));

View File

@ -68,22 +68,23 @@ function ajouter_sondage()
$sql = $connect->Prepare($sql);
$connect->Execute($sql, array($sondage, $_SESSION['toutchoix']));
$message = _("This is the message you have to send to the people you want to poll. \nNow, you have to send this message to everyone you want to poll.");
$message .= "\n\n";
$message .= stripslashes(html_entity_decode($_SESSION["nom"],ENT_QUOTES,"UTF-8"))." " . _("hast just created a poll called") . " : \"".stripslashes(htmlspecialchars_decode($_SESSION["titre"],ENT_QUOTES))."\".\n";
$message .= _("Thanks for filling the poll at the link above") . " :\n\n%s\n\n" . _("Thanks for your confidence.") . "\n".NOMAPPLICATION;
if(config_get('use_smtp')==true){
$message = _("This is the message you have to send to the people you want to poll. \nNow, you have to send this message to everyone you want to poll.");
$message .= "\n\n";
$message .= stripslashes(html_entity_decode($_SESSION["nom"],ENT_QUOTES,"UTF-8"))." " . _("hast just created a poll called") . " : \"".stripslashes(htmlspecialchars_decode($_SESSION["titre"],ENT_QUOTES))."\".\n";
$message .= _("Thanks for filling the poll at the link above") . " :\n\n%s\n\n" . _("Thanks for your confidence.") . "\n".NOMAPPLICATION;
$message_admin = _("This message should NOT be sent to the polled people. It is private for the poll's creator.\n\nYou can now modify it at the link above");
$message_admin .= " :\n\n"."%s \n\n" . _("Thanks for your confidence.") . "\n".NOMAPPLICATION;
$message_admin = _("This message should NOT be sent to the polled people. It is private for the poll's creator.\n\nYou can now modify it at the link above");
$message_admin .= " :\n\n"."%s \n\n" . _("Thanks for your confidence.") . "\n".NOMAPPLICATION;
$message = sprintf($message, Utils::getUrlSondage($sondage));
$message_admin = sprintf($message_admin, Utils::getUrlSondage($sondage_admin, true));
if (Utils::isValidEmail($_SESSION['adresse'])) {
Utils::sendEmail( "$_SESSION[adresse]", "[".NOMAPPLICATION."][" . _("Author's message") . "] " . _("Poll") . " : ".stripslashes(htmlspecialchars_decode($_SESSION["titre"],ENT_QUOTES)), $message_admin, $_SESSION['adresse'] );
Utils::sendEmail( "$_SESSION[adresse]", "[".NOMAPPLICATION."][" . _("For sending to the polled users") . "] " . _("Poll") . " : ".stripslashes(htmlspecialchars_decode($_SESSION["titre"],ENT_QUOTES)), $message, $_SESSION['adresse'] );
}
$message = sprintf($message, Utils::getUrlSondage($sondage));
$message_admin = sprintf($message_admin, Utils::getUrlSondage($sondage_admin, true));
if (Utils::isValidEmail($_SESSION['adresse'])) {
Utils::sendEmail( "$_SESSION[adresse]", "[".NOMAPPLICATION."][" . _("Author's message") . "] " . _("Poll") . " : ".stripslashes(htmlspecialchars_decode($_SESSION["titre"],ENT_QUOTES)), $message_admin, $_SESSION['adresse'] );
Utils::sendEmail( "$_SESSION[adresse]", "[".NOMAPPLICATION."][" . _("For sending to the polled users") . "] " . _("Poll") . " : ".stripslashes(htmlspecialchars_decode($_SESSION["titre"],ENT_QUOTES)), $message, $_SESSION['adresse'] );
}
}
error_log(date('H:i:s d/m/Y:') . ' CREATION: '.$sondage."\t".$_SESSION[formatsondage]."\t".$_SESSION[nom]."\t".$_SESSION[adresse]."\t \t".$_SESSION[toutchoix]."\n", 3, 'admin/logs_studs.txt');
Utils::cleaning_polls($connect, 'admin/logs_studs.txt');

View File

@ -77,9 +77,11 @@ if (Utils::issetAndNoEmpty("poursuivre")){
unset($_SESSION["mailsonde"]);
$_SESSION["mailsonde"] = ($mailsonde !== null) ? true : false;
if (Utils::isValidEmail($adresse) === false) {
$erreur_adresse = true;
}
if (config_get('use_smtp')==true){
if (Utils::isValidEmail($adresse) === false) {
$erreur_adresse = true;
}
}
if (preg_match(';<|>|";',$titre)) {
$erreur_injection_titre = true;
@ -94,7 +96,14 @@ if (Utils::issetAndNoEmpty("poursuivre")){
}
// Si pas d'erreur dans l'adresse alors on change de page vers date ou autre
if ($titre && $nom && $adresse && !$erreur_adresse && ! $erreur_injection_titre && ! $erreur_injection_commentaires && ! $erreur_injection_nom) {
if(config_get('use_smtp')==true){
$email_OK = $adresse && !$erreur_adresse;
}
else{
$email_OK = true;
}
if ($titre && $nom && $email_OK && ! $erreur_injection_titre && ! $erreur_injection_commentaires && ! $erreur_injection_nom) {
if ( $poursuivre == "creation_sondage_date" ) {
header("Location:choix_date.php");
@ -242,16 +251,19 @@ echo '
'.$input_name.'
</div>
</div>
'.$errors['name']['msg'].'
<div class="form-group'.$errors['email']['class'].'">
<label for="email" class="col-sm-4 control-label">'. _("Your email address") .' *</label>
<div class="col-sm-8">
'.$input_email.'
</div>
</div>
'.$errors['email']['msg'].'
'.$errors['name']['msg'];
if(config_get('use_smtp')==true){
echo '
<div class="form-group'.$errors['email']['class'].'">
<label for="email" class="col-sm-4 control-label">'. _("Your email address") .' *</label>
<div class="col-sm-8">
'.$input_email.'
</div>
</div>
'.$errors['email']['msg'];
}
<div class="form-group">
echo '<div class="form-group">
<div class="col-sm-offset-1 col-sm-11">
<div class="checkbox">
<label>
@ -259,18 +271,20 @@ echo '
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-1 col-sm-11">
<div class="checkbox">
<label>
<input type=checkbox name=mailsonde '.$cochemail.' id="mailsonde">'. _("To receive an email for each new vote.") .'
</label>
</div>
</div>
</div>
</div>';
if(config_get('use_smtp')==true){
echo '<div class="form-group">
<div class="col-sm-offset-1 col-sm-11">
<div class="checkbox">
<label>
<input type=checkbox name=mailsonde '.$cochemail.' id="mailsonde">'. _("To receive an email for each new vote.") .'
</label>
</div>
</div>
</div>';
}
<p class="text-right">
echo '<p class="text-right">
<input type="hidden" name="choix_sondage" value="'. $choix_sondage .'"/>
<button name="poursuivre" value="'. $choix_sondage .'" type="submit" class="btn btn-success" title="'. _('Go to step 2') . '">'. _('Next') . '</button>
</p>

View File

@ -173,13 +173,15 @@ if (!Utils::is_error(NO_POLL) && (isset($_POST["boutonp"]))) {
$connect->Execute($sql, array($nom, $numsondage, $nouveauchoix));
if ($dsondage->mailsonde || /* compatibility for non boolean DB */ $dsondage->mailsonde=="yes" || $dsondage->mailsonde=="true") {
Utils::sendEmail( "$dsondage->mail_admin",
"[".NOMAPPLICATION."] "._("Poll's participation")." : ".html_entity_decode($dsondage->titre, ENT_QUOTES, 'UTF-8')."",
html_entity_decode("\"$nom\" ", ENT_QUOTES, 'UTF-8').
_("has filled a line.\nYou can find your poll at the link") . " :\n\n".
Utils::getUrlSondage($numsondage) . " \n\n" .
_("Thanks for your confidence.") . "\n". NOMAPPLICATION );
}
if(config_get('use_smtp')==true){
Utils::sendEmail( "$dsondage->mail_admin",
"[".NOMAPPLICATION."] "._("Poll's participation")." : ".html_entity_decode($dsondage->titre, ENT_QUOTES, 'UTF-8')."",
html_entity_decode("\"$nom\" ", ENT_QUOTES, 'UTF-8').
_("has filled a line.\nYou can find your poll at the link") . " :\n\n".
Utils::getUrlSondage($numsondage) . " \n\n" .
_("Thanks for your confidence.") . "\n". NOMAPPLICATION );
}
}
}
} else {
$err |= NAME_EMPTY;