From 821ef72d482c4669d2d3c3e286551cb9d8a9063b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 2 Jan 2021 17:43:02 +0100 Subject: [PATCH] Fix warnings --- .../email_expire_services_to_customers.php | 24 +++++++++----- ...ail_expire_services_to_representatives.php | 23 ++++++++----- .../email_unpaid_invoices_to_customers.php | 32 ++++++++++++------- ...ail_unpaid_invoices_to_representatives.php | 11 ++++--- 4 files changed, 57 insertions(+), 33 deletions(-) diff --git a/scripts/contracts/email_expire_services_to_customers.php b/scripts/contracts/email_expire_services_to_customers.php index 5c98dc2913b..596a5794d70 100755 --- a/scripts/contracts/email_expire_services_to_customers.php +++ b/scripts/contracts/email_expire_services_to_customers.php @@ -74,8 +74,9 @@ $duration_value2 = isset($argv[4]) ? $argv[4] : 'none'; $error = 0; print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value) ? " delay=".$duration_value : "").(is_numeric($duration_value2) ? " after=".$duration_value2 : "")."\n"; -if ($mode != 'confirm') +if ($mode != 'confirm') { $conf->global->MAIN_DISABLE_ALL_MAILS = 1; +} $sql = "SELECT c.ref, cd.date_fin_validite, cd.total_ttc, cd.description as description, p.label as plabel,"; $sql .= " s.rowid as sid, s.nom as name, s.email, s.default_lang"; @@ -115,6 +116,7 @@ if ($resql) { print "We found ".$num." couples (services to expire-".$targettype.") qualified\n"; dol_syslog("We found ".$num." couples (services to expire-".$targettype.") qualified"); $message = ''; + $oldtarget = ''; if ($num) { while ($i < $num) { @@ -124,12 +126,17 @@ if ($resql) { // Check if this record is a break after previous one $startbreak = false; - if ($newemail != $oldemail || $oldemail == 'none') + if ($newemail != $oldemail || $oldemail == 'none') { $startbreak = true; - if ($obj->sid && $obj->sid != $oldsid) - $startbreak = true; - if ($obj->cid && $obj->cid != $oldcid) + } + if ($obj->sid && $obj->sid != $oldsid) { $startbreak = true; + } + if ($targettype == 'contacts') { + if ($obj->cid && $obj->cid != $oldcid) { + $startbreak = true; + } + } if ($startbreak) { // Break onto sales representative (new email or cid) @@ -145,13 +152,14 @@ if ($resql) { } $oldemail = $newemail; $oldsid = $obj->sid; - $oldcid = $obj->cid; + if ($targettype == 'contacts') { + $oldcid = $obj->cid; + } $oldlang = $obj->lang; $oldtarget = (empty($obj->cfirstname) && empty($obj->clastname)) ? $obj->name : ($obj->clastname." ".$obj->cfirstname); $message = ''; $total = 0; $foundtoprocess = 0; - $target = (empty($obj->cfirstname) && empty($obj->clastname)) ? $obj->name : ($obj->clastname." ".$obj->cfirstname); // if (empty($newemail)) print "Warning: Customer ".$target." has no email. Notice disabled.\n"; } @@ -167,7 +175,7 @@ if ($resql) { dol_syslog("email_expire_services_to_customers.php: ".$newemail." ".$message); $foundtoprocess++; } - print "Service to expire ".$obj->ref.", label ".dol_concatdesc($obj->plabel, $obj->description).", due date ".dol_print_date($db->jdate($obj->date_fin_validite), 'day').", customer id ".$obj->sid." ".$obj->name.", ".($obj->cid ? "contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", " : "")."email ".$newemail.", lang ".$outputlangs->defaultlang.": "; + print "Service to expire ".$obj->ref.", label ".dol_concatdesc($obj->plabel, $obj->description).", due date ".dol_print_date($db->jdate($obj->date_fin_validite), 'day').", customer id ".$obj->sid." ".$obj->name.", ".(isset($obj->cid) ? "contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", " : "")."email ".$newemail.", lang ".$outputlangs->defaultlang.": "; if (dol_strlen($newemail)) print "qualified."; else print "disqualified (no email)."; diff --git a/scripts/contracts/email_expire_services_to_representatives.php b/scripts/contracts/email_expire_services_to_representatives.php index eec151376ee..2c8429b6256 100755 --- a/scripts/contracts/email_expire_services_to_representatives.php +++ b/scripts/contracts/email_expire_services_to_representatives.php @@ -70,8 +70,9 @@ $duration_value = isset($argv[2]) ? $argv[2] : 'none'; print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value) ? " delay=".$duration_value : "")."\n"; -if ($mode != 'confirm') +if ($mode != 'confirm') { $conf->global->MAIN_DISABLE_ALL_MAILS = 1; +} $sql = "SELECT DISTINCT c.ref, c.fk_soc, cd.date_fin_validite, cd.total_ttc, cd.description as description, p.label as plabel, s.rowid, s.nom as name, s.email, s.default_lang,"; $sql .= " u.rowid as uid, u.lastname, u.firstname, u.email, u.lang"; @@ -192,25 +193,31 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldsalerepre $newlangs->load("contracts"); if ($duration_value) { - if ($duration_value > 0) + if ($duration_value > 0) { $title = $newlangs->transnoentities("ListOfServicesToExpireWithDuration", $duration_value); - else $title = $newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg", $duration_value); - } else $title = $newlangs->transnoentities("ListOfServicesToExpire"); + } else { + $title = $newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg", $duration_value); + } + } else { + $title = $newlangs->transnoentities("ListOfServicesToExpire"); + } $subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT) ? $title : $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT); $sendto = $oldemail; - $from = $conf->global->MAIN_MAIL_EMAIL_FROM; - $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO; + $from = empty($conf->global->MAIN_MAIL_EMAIL_FROM) ? '' : $conf->global->MAIN_MAIL_EMAIL_FROM; + $errorsto = empty($conf->global->MAIN_MAIL_ERRORS_TO) ? '' : $conf->global->MAIN_MAIL_ERRORS_TO; $msgishtml = - 1; print "- Send email for ".$oldsalerepresentative." (".$oldemail."), total: ".$total."\n"; dol_syslog("email_expire_services_to_representatives.php: send mail to ".$oldemail); $usehtml = 0; - if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) + if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER) && dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) { $usehtml += 1; - if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER)) + } + if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER) && dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER)) { $usehtml += 1; + } $allmessage = ''; if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER)) { diff --git a/scripts/invoices/email_unpaid_invoices_to_customers.php b/scripts/invoices/email_unpaid_invoices_to_customers.php index 9b59fcab6f7..a569a34d0fa 100755 --- a/scripts/invoices/email_unpaid_invoices_to_customers.php +++ b/scripts/invoices/email_unpaid_invoices_to_customers.php @@ -74,8 +74,9 @@ $duration_value2 = isset($argv[4]) ? $argv[4] : 'none'; $error = 0; print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value) ? " delay=".$duration_value : "").(is_numeric($duration_value2) ? " after=".$duration_value2 : "")."\n"; -if ($mode != 'confirm') +if ($mode != 'confirm') { $conf->global->MAIN_DISABLE_ALL_MAILS = 1; +} $sql = "SELECT f.ref, f.total_ttc, f.date_lim_reglement as due_date,"; $sql .= " s.rowid as sid, s.nom as name, s.email, s.default_lang"; @@ -113,6 +114,7 @@ if ($resql) { print "We found ".$num." couples (unpayed validated invoices-".$targettype.") qualified\n"; dol_syslog("We found ".$num." couples (unpayed validated invoices-".$targettype.") qualified"); $message = ''; + $oldtarget = ''; if ($num) { while ($i < $num) { @@ -122,12 +124,17 @@ if ($resql) { // Check if this record is a break after previous one $startbreak = false; - if ($newemail != $oldemail || $oldemail == 'none') + if ($newemail != $oldemail || $oldemail == 'none') { $startbreak = true; - if ($obj->sid && $obj->sid != $oldsid) - $startbreak = true; - if ($obj->cid && $obj->cid != $oldcid) + } + if ($obj->sid && $obj->sid != $oldsid) { $startbreak = true; + } + if ($targettype == 'contacts') { + if ($obj->cid && $obj->cid != $oldcid) { + $startbreak = true; + } + } if ($startbreak) { // Break onto sales representative (new email or cid) @@ -143,13 +150,14 @@ if ($resql) { } $oldemail = $newemail; $oldsid = $obj->sid; - $oldcid = $obj->cid; + if ($targettype == 'contacts') { + $oldcid = $obj->cid; + } $oldlang = $obj->lang; $oldtarget = (empty($obj->cfirstname) && empty($obj->clastname)) ? $obj->name : ($obj->clastname." ".$obj->cfirstname); $message = ''; $total = 0; $foundtoprocess = 0; - $target = (empty($obj->cfirstname) && empty($obj->clastname)) ? $obj->name : ($obj->clastname." ".$obj->cfirstname); // if (empty($newemail)) print "Warning: Customer ".$target." has no email. Notice disabled.\n"; } @@ -165,7 +173,7 @@ if ($resql) { dol_syslog("email_unpaid_invoices_to_customers.php: ".$newemail." ".$message); $foundtoprocess++; } - print "Unpaid invoice ".$obj->ref.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date), 'day').", customer id ".$obj->sid." ".$obj->name.", ".($obj->cid ? "contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", " : "")."email ".$newemail.", lang ".$outputlangs->defaultlang.": "; + print "Unpaid invoice ".$obj->ref.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date), 'day').", customer id ".$obj->sid." ".$obj->name.", ".(isset($obj->cid) ? "contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", " : "")."email ".$newemail.", lang ".$outputlangs->defaultlang.": "; if (dol_strlen($newemail)) print "qualified."; else print "disqualified (no email)."; @@ -229,17 +237,17 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget) $subject = (empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_SUBJECT) ? $newlangs->trans("ListOfYourUnpaidInvoices") : $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_SUBJECT); $sendto = $oldemail; - $from = $conf->global->MAIN_MAIL_EMAIL_FROM; - $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO; + $from = empty($conf->global->MAIN_MAIL_EMAIL_FROM) ? '' : $conf->global->MAIN_MAIL_EMAIL_FROM; + $errorsto = empty($conf->global->MAIN_MAIL_ERRORS_TO) ? '' : $conf->global->MAIN_MAIL_ERRORS_TO; $msgishtml = - 1; print "- Send email to '".$oldtarget."' (".$oldemail."), total: ".$total."\n"; dol_syslog("email_unpaid_invoices_to_customers.php: send mail to ".$oldemail); $usehtml = 0; - if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) + if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER) && dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) $usehtml += 1; - if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER)) + if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER) && dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER)) $usehtml += 1; $allmessage = ''; diff --git a/scripts/invoices/email_unpaid_invoices_to_representatives.php b/scripts/invoices/email_unpaid_invoices_to_representatives.php index d401894363d..d5c71c70565 100755 --- a/scripts/invoices/email_unpaid_invoices_to_representatives.php +++ b/scripts/invoices/email_unpaid_invoices_to_representatives.php @@ -70,8 +70,9 @@ $duration_value = isset($argv[2]) ? $argv[2] : 'none'; print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value) ? " delay=".$duration_value : "")."\n"; -if ($mode != 'confirm') +if ($mode != 'confirm') { $conf->global->MAIN_DISABLE_ALL_MAILS = 1; +} $sql = "SELECT f.ref, f.total_ttc, f.date_lim_reglement as due_date, s.nom as name, s.email, s.default_lang,"; $sql .= " u.rowid as uid, u.lastname, u.firstname, u.email, u.lang"; @@ -196,17 +197,17 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldsalerepre $subject = (empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT) ? $newlangs->trans("ListOfYourUnpaidInvoices") : $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT); $sendto = $oldemail; - $from = $conf->global->MAIN_MAIL_EMAIL_FROM; - $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO; + $from = empty($conf->global->MAIN_MAIL_EMAIL_FROM) ? '' : $conf->global->MAIN_MAIL_EMAIL_FROM; + $errorsto = empty($conf->global->MAIN_MAIL_ERRORS_TO) ? '' : $conf->global->MAIN_MAIL_ERRORS_TO; $msgishtml = - 1; print "- Send email for ".$oldsalerepresentative." (".$oldemail."), total: ".$total."\n"; dol_syslog("email_unpaid_invoices_to_representatives.php: send mail to ".$oldemail); $usehtml = 0; - if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) + if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER) && dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) $usehtml += 1; - if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) + if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER) && dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) $usehtml += 1; $allmessage = '';