From ed743c9dbba86afb2d9daa68b8e1791efa350871 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 2 Sep 2020 21:39:22 +0200 Subject: [PATCH] Fix phpcs More secured sendEmailsReminder() --- htdocs/comm/action/class/actioncomm.class.php | 110 +++++++++--------- htdocs/core/class/html.form.class.php | 1 + htdocs/theme/md/badges.inc.php | 4 +- 3 files changed, 60 insertions(+), 55 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index fd41a9eadf4..6b5f19fa64c 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1965,6 +1965,8 @@ class ActionComm extends CommonObject $error = 0; $this->output = ''; $this->error = ''; + $nbMailSend = 0; + $errorsMsg = array(); if (empty($conf->agenda->enabled)) // Should not happen. If module disabled, cron job should not be visible. { @@ -2005,68 +2007,68 @@ class ActionComm extends CommonObject if (!$error) { - //Select email template - $arraymessage = $formmail->getEMailTemplate($this->db, 'actioncomm_send', $user, $langs, (!empty($actionCommReminder->fk_email_template)) ? $actionCommReminder->fk_email_template : -1, 1); + //Select email template + $arraymessage = $formmail->getEMailTemplate($this->db, 'actioncomm_send', $user, $langs, (!empty($actionCommReminder->fk_email_template)) ? $actionCommReminder->fk_email_template : -1, 1); - // Load event - $res = $this->fetch($actionCommReminder->fk_actioncomm); - if ($res > 0) - { - // PREPARE EMAIL + // Load event + $res = $this->fetch($actionCommReminder->fk_actioncomm); + if ($res > 0) + { + // PREPARE EMAIL - // Make substitution in email content - $substitutionarray = getCommonSubstitutionArray($langs, 0, '', $this); + // Make substitution in email content + $substitutionarray = getCommonSubstitutionArray($langs, 0, '', $this); - complete_substitutions_array($substitutionarray, $langs, $this); + complete_substitutions_array($substitutionarray, $langs, $this); - // Content - $sendContent = make_substitutions($langs->trans($arraymessage->content), $substitutionarray); + // Content + $sendContent = make_substitutions($langs->trans($arraymessage->content), $substitutionarray); - //Topic - $sendTopic = (!empty($arraymessage->topic)) ? $arraymessage->topic : html_entity_decode($langs->trans('EventReminder')); + //Topic + $sendTopic = (!empty($arraymessage->topic)) ? $arraymessage->topic : html_entity_decode($langs->trans('EventReminder')); - // Recipient - $recipient = new User($this->db); - $res = $recipient->fetch($actionCommReminder->fk_user); - if ($res > 0 && !empty($recipient->email)) $to = $recipient->email; - else { - $errorsMsg[] = "Failed to load recipient"; - $error++; - } + // Recipient + $recipient = new User($this->db); + $res = $recipient->fetch($actionCommReminder->fk_user); + if ($res > 0 && !empty($recipient->email)) $to = $recipient->email; + else { + $errorsMsg[] = "Failed to load recipient"; + $error++; + } - // Sender - $from = $conf->global->MAIN_MAIL_EMAIL_FROM; - if (empty($from)) { - $errorsMsg[] = "Failed to load recipient"; - $error++; - } + // Sender + $from = $conf->global->MAIN_MAIL_EMAIL_FROM; + if (empty($from)) { + $errorsMsg[] = "Failed to load recipient"; + $error++; + } - // Errors Recipient - $errors_to = $conf->global->MAIN_MAIL_ERRORS_TO; + // Errors Recipient + $errors_to = $conf->global->MAIN_MAIL_ERRORS_TO; - // Mail Creation - $cMailFile = new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(), '', "", 0, 1, $errors_to, '', '', '', '', ''); + // Mail Creation + $cMailFile = new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(), '', "", 0, 1, $errors_to, '', '', '', '', ''); - // Sending Mail - if ($cMailFile->sendfile()) - { - $actionCommReminder->status = $actionCommReminder::STATUS_DONE; - $res = $actionCommReminder->update($user); - if ($res < 0) - { - $errorsMsg[] = "Failed to update status of ActionComm Reminder"; - $error++; - } - else $nbMailSend++; - } - else { - $errorsMsg[] = $cMailFile->error.' : '.$to; - $error++; - } - } - else { - $error++; - } + // Sending Mail + if ($cMailFile->sendfile()) + { + $actionCommReminder->status = $actionCommReminder::STATUS_DONE; + $res = $actionCommReminder->update($user); + if ($res < 0) + { + $errorsMsg[] = "Failed to update status of ActionComm Reminder"; + //$error++; Do not add error here. + break; // This is to avoid to have this error on all the selected email. If we fails here for one record, it may fails for others. We must solve first. + } else { + $nbMailSend++; + } + } else { + $errorsMsg[] = $cMailFile->error.' : '.$to; + $error++; + } + } else { + $error++; + } } } } else { @@ -2087,12 +2089,14 @@ class ActionComm extends CommonObject } if (!$error) { + $this->output = 'Nb of emails sent : '.$nbMailSend; $this->db->commit(); return 0; } else { $this->db->rollback(); - return (!empty($errorsMsg)) ? end($errorsMsg) : $error; + $this->error = (!empty($errorsMsg)) ? join(', ', $errorsMsg) : $error; + return $error; } } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 996fcc52912..a913a878251 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -7977,6 +7977,7 @@ class Form * * @param string $prefix Prefix * @param string $modelType Model type + * @param int $default 1=Show also Default mail template * @return string HTML select string */ public function selectModelMail($prefix, $modelType = '', $default = 0) diff --git a/htdocs/theme/md/badges.inc.php b/htdocs/theme/md/badges.inc.php index 55bec9ce8f6..1ce2d912669 100644 --- a/htdocs/theme/md/badges.inc.php +++ b/htdocs/theme/md/badges.inc.php @@ -215,7 +215,7 @@ function _createStatusBadgeCss($statusName, $statusVarNamePrefix = '', $commentL if (!empty(${$statusVarNamePrefix.'badgeStatus'.$statusName})) { print "\n/* ".strtoupper($commentLabel)." */\n"; - + $thisBadgeBackgroundColor = $thisBadgeBorderColor = ${$statusVarNamePrefix.'badgeStatus'.$statusName}; @@ -233,7 +233,7 @@ function _createStatusBadgeCss($statusName, $statusVarNamePrefix = '', $commentL if (in_array((string) $statusName, array('0', '5', '9'))) $thisBadgeTextColor = '#999999'; if (in_array((string) $statusName, array('6'))) $thisBadgeTextColor = '#777777'; - + print $cssPrefix.".badge-status".$statusName." {\n"; print " color: ".$thisBadgeTextColor." !important;\n"; if (in_array((string) $statusName, $TBadgeBorderOnly)) {