add new rule

This commit is contained in:
Frédéric FRANCE 2021-03-01 00:22:36 +01:00
parent 1b046f25cf
commit 63dad7f25c
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1
23 changed files with 354 additions and 192 deletions

View File

@ -25,7 +25,9 @@
* \brief Page to detect empty accounting account * \brief Page to detect empty accounting account
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$path = __DIR__.'/'; $path = __DIR__.'/';
@ -36,8 +38,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
$langs->loadLangs(array("companies", "compta", "main", "accountancy")); $langs->loadLangs(array("companies", "compta", "main", "accountancy"));
// Security check // Security check
if (!$user->admin) if (!$user->admin) {
accessforbidden(); accessforbidden();
}
// Date range // Date range
$year = GETPOST("year"); $year = GETPOST("year");
@ -54,8 +57,7 @@ $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_starty
$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear); $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
// Quarter // Quarter
if (empty($date_start) || empty($date_end)) // We define date_start and date_end if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
{
$q = GETPOST("q") ? GETPOST("q") : 0; $q = GETPOST("q") ? GETPOST("q") : 0;
if ($q == 0) { if ($q == 0) {
// We define date_start and date_end // We define date_start and date_end
@ -67,10 +69,14 @@ if (empty($date_start) || empty($date_end)) // We define date_start and date_end
$year_end--; $year_end--;
} }
$month_end = $month_start - 1; $month_end = $month_start - 1;
if ($month_end < 1) if ($month_end < 1) {
$month_end = 12; $month_end = 12;
else $year_end++; } else {
} else $month_end = $month_start; $year_end++;
}
} else {
$month_end = $month_start;
}
$date_start = dol_get_first_day($year_start, $month_start, false); $date_start = dol_get_first_day($year_start, $month_start, false);
$date_end = dol_get_last_day($year_end, $month_end, false); $date_end = dol_get_last_day($year_end, $month_end, false);
} }
@ -128,11 +134,13 @@ $sql .= ", ".MAIN_DB_PREFIX."facture as f";
$sql .= ", ".MAIN_DB_PREFIX."c_country as cp"; $sql .= ", ".MAIN_DB_PREFIX."c_country as cp";
$sql .= " WHERE f.fk_soc = s.rowid"; $sql .= " WHERE f.fk_soc = s.rowid";
$sql .= " AND s.fk_pays = cp.rowid"; $sql .= " AND s.fk_pays = cp.rowid";
if (!empty($date_start) && !empty($date_end)) if (!empty($date_start) && !empty($date_end)) {
$sql .= " AND f.datec >= '".$db->idate($date_start)."' AND f.datec <= '".$db->idate($date_end)."'"; $sql .= " AND f.datec >= '".$db->idate($date_start)."' AND f.datec <= '".$db->idate($date_end)."'";
}
$sql .= " AND f.entity IN (".getEntity('invoice', 0).")"; $sql .= " AND f.entity IN (".getEntity('invoice', 0).")";
if ($socid) if ($socid) {
$sql .= " AND f.fk_soc = ".$socid; $sql .= " AND f.fk_soc = ".$socid;
}
$sql .= " GROUP BY name"; $sql .= " GROUP BY name";
$sql .= ")"; $sql .= ")";
$sql .= "UNION (SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, s.code_compta_fournisseur as compta , "; $sql .= "UNION (SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, s.code_compta_fournisseur as compta , ";
@ -142,11 +150,13 @@ $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as ff";
$sql .= ", ".MAIN_DB_PREFIX."c_country as cp"; $sql .= ", ".MAIN_DB_PREFIX."c_country as cp";
$sql .= " WHERE ff.fk_soc = s.rowid"; $sql .= " WHERE ff.fk_soc = s.rowid";
$sql .= " AND s.fk_pays = cp.rowid"; $sql .= " AND s.fk_pays = cp.rowid";
if (!empty($date_start) && !empty($date_end)) if (!empty($date_start) && !empty($date_end)) {
$sql .= " AND ff.datec >= '".$db->idate($date_start)."' AND ff.datec <= '".$db->idate($date_end)."'"; $sql .= " AND ff.datec >= '".$db->idate($date_start)."' AND ff.datec <= '".$db->idate($date_end)."'";
}
$sql .= " AND ff.entity = ".$conf->entity; $sql .= " AND ff.entity = ".$conf->entity;
if ($socid) if ($socid) {
$sql .= " AND f.fk_soc = ".$socid; $sql .= " AND f.fk_soc = ".$socid;
}
$sql .= " GROUP BY name"; $sql .= " GROUP BY name";
$sql .= ")"; $sql .= ")";
@ -200,8 +210,7 @@ if ($resql) {
print '<td class="left">'.$langs->trans("Phone").'</td>'; print '<td class="left">'.$langs->trans("Phone").'</td>';
print '<td class="left">'.$langs->trans("Fax").'</td></tr>'; print '<td class="left">'.$langs->trans("Fax").'</td></tr>';
while ($obj = $db->fetch_object($resql)) while ($obj = $db->fetch_object($resql)) {
{
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td>'; print '<td>';
$thirdpartystatic->id = $obj->rowid; $thirdpartystatic->id = $obj->rowid;

View File

@ -23,7 +23,9 @@
* \brief Script file to export bank receipts into Excel files * \brief Script file to export bank receipts into Excel files
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);
@ -154,8 +156,9 @@ if (!empty($num) && $num != "all") {
$listofnum .= "'"; $listofnum .= "'";
$arraynum = explode(',', $num); $arraynum = explode(',', $num);
foreach ($arraynum as $val) { foreach ($arraynum as $val) {
if ($listofnum != "'") if ($listofnum != "'") {
$listofnum .= "','"; $listofnum .= "','";
}
$listofnum .= $val; $listofnum .= $val;
} }
$listofnum .= "'"; $listofnum .= "'";
@ -166,10 +169,12 @@ $sql .= " ba.rowid as bankid, ba.ref as bankref, ba.label as banklabel";
$sql .= " FROM ".MAIN_DB_PREFIX."bank_account as ba"; $sql .= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
$sql .= ", ".MAIN_DB_PREFIX."bank as b"; $sql .= ", ".MAIN_DB_PREFIX."bank as b";
$sql .= " WHERE b.fk_account = ".$acct->id; $sql .= " WHERE b.fk_account = ".$acct->id;
if ($listofnum) if ($listofnum) {
$sql .= " AND b.num_releve IN (".$listofnum.")"; $sql .= " AND b.num_releve IN (".$listofnum.")";
if (!isset($num)) }
if (!isset($num)) {
$sql .= " OR b.num_releve is null"; $sql .= " OR b.num_releve is null";
}
$sql .= " AND b.fk_account = ba.rowid"; $sql .= " AND b.fk_account = ba.rowid";
$sql .= $db->order("b.num_releve, b.datev, b.datec", "ASC"); // We add date of creation to have correct order when everything is done the same day $sql .= $db->order("b.num_releve, b.datev, b.datec", "ASC"); // We add date of creation to have correct order when everything is done the same day
// print $sql; // print $sql;
@ -242,9 +247,11 @@ if ($resql) {
// Libelle // Libelle
$reg = array(); $reg = array();
preg_match('/\((.+)\)/i', $objp->label, $reg); // Si texte entoure de parenthese on tente recherche de traduction preg_match('/\((.+)\)/i', $objp->label, $reg); // Si texte entoure de parenthese on tente recherche de traduction
if ($reg[1] && $langs->transnoentitiesnoconv($reg[1]) != $reg[1]) if ($reg[1] && $langs->transnoentitiesnoconv($reg[1]) != $reg[1]) {
$description = $langs->transnoentitiesnoconv($reg[1]); $description = $langs->transnoentitiesnoconv($reg[1]);
else $description = $objp->label; } else {
$description = $objp->label;
}
/* /*
* Ajout les liens (societe, company...) * Ajout les liens (societe, company...)

View File

@ -24,7 +24,9 @@
* \brief Script to update all contacts from Dolibarr into a LDAP database * \brief Script to update all contacts from Dolibarr into a LDAP database
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);
@ -60,8 +62,9 @@ if (!isset($argv[1]) || !$argv[1]) {
} }
foreach ($argv as $key => $val) { foreach ($argv as $key => $val) {
if (preg_match('/-y$/', $val, $reg)) if (preg_match('/-y$/', $val, $reg)) {
$confirmed = 1; $confirmed = 1;
}
} }
$now = $argv[1]; $now = $argv[1];

View File

@ -25,7 +25,9 @@
* \brief Script to send a mail to customers with services to expire * \brief Script to send a mail to customers with services to expire
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);
@ -80,24 +82,30 @@ if ($mode != 'confirm') {
$sql = "SELECT c.ref, cd.date_fin_validite, cd.total_ttc, cd.description as description, p.label as plabel,"; $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"; $sql .= " s.rowid as sid, s.nom as name, s.email, s.default_lang";
if ($targettype == 'contacts') if ($targettype == 'contacts') {
$sql .= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail"; $sql .= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail";
}
$sql .= " FROM ".MAIN_DB_PREFIX."societe AS s"; $sql .= " FROM ".MAIN_DB_PREFIX."societe AS s";
if ($targettype == 'contacts') if ($targettype == 'contacts') {
$sql .= ", ".MAIN_DB_PREFIX."socpeople as sp"; $sql .= ", ".MAIN_DB_PREFIX."socpeople as sp";
}
$sql .= ", ".MAIN_DB_PREFIX."contrat AS c"; $sql .= ", ".MAIN_DB_PREFIX."contrat AS c";
$sql .= ", ".MAIN_DB_PREFIX."contratdet AS cd"; $sql .= ", ".MAIN_DB_PREFIX."contratdet AS cd";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product AS p ON p.rowid = cd.fk_product"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product AS p ON p.rowid = cd.fk_product";
$sql .= " WHERE s.rowid = c.fk_soc AND c.rowid = cd.fk_contrat AND c.statut > 0 AND cd.statut < 5"; $sql .= " WHERE s.rowid = c.fk_soc AND c.rowid = cd.fk_contrat AND c.statut > 0 AND cd.statut < 5";
if (is_numeric($duration_value2)) if (is_numeric($duration_value2)) {
$sql .= " AND cd.date_fin_validite >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'"; $sql .= " AND cd.date_fin_validite >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'";
if (is_numeric($duration_value)) }
if (is_numeric($duration_value)) {
$sql .= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'"; $sql .= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
if ($targettype == 'contacts') }
if ($targettype == 'contacts') {
$sql .= " AND s.rowid = sp.fk_soc"; $sql .= " AND s.rowid = sp.fk_soc";
}
$sql .= " ORDER BY"; $sql .= " ORDER BY";
if ($targettype == 'contacts') if ($targettype == 'contacts') {
$sql .= " sp.email, sp.rowid,"; $sql .= " sp.email, sp.rowid,";
}
$sql .= " s.email ASC, s.rowid ASC, cd.date_fin_validite ASC"; // Order by email to allow one message per email $sql .= " s.email ASC, s.rowid ASC, cd.date_fin_validite ASC"; // Order by email to allow one message per email
// print $sql; // print $sql;
@ -145,9 +153,11 @@ if ($resql) {
$trackthirdpartiessent[$oldsid.'|'.$oldemail] = 'contact id '.$oldcid; $trackthirdpartiessent[$oldsid.'|'.$oldemail] = 'contact id '.$oldcid;
} else { } else {
if ($oldemail != 'none') { if ($oldemail != 'none') {
if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) {
print "- No email sent for '".$oldtarget."', total: ".$total."\n"; print "- No email sent for '".$oldtarget."', total: ".$total."\n";
else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n"; } else {
print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
}
} }
} }
$oldemail = $newemail; $oldemail = $newemail;
@ -176,9 +186,11 @@ if ($resql) {
$foundtoprocess++; $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.", ".(isset($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)) if (dol_strlen($newemail)) {
print "qualified."; print "qualified.";
else print "disqualified (no email)."; } else {
print "disqualified (no email).";
}
print "\n"; print "\n";
unset($outputlangs); unset($outputlangs);
@ -190,15 +202,16 @@ if ($resql) {
// Si il reste des envois en buffer // Si il reste des envois en buffer
if ($foundtoprocess) { if ($foundtoprocess) {
if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) // Break onto email (new email) if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) { // Break onto email (new email)
{
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldtarget, $duration_value); envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldtarget, $duration_value);
$trackthirdpartiessent[$oldsid.'|'.$oldemail] = 'contact id '.$oldcid; $trackthirdpartiessent[$oldsid.'|'.$oldemail] = 'contact id '.$oldcid;
} else { } else {
if ($oldemail != 'none') { if ($oldemail != 'none') {
if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) {
print "- No email sent for '".$oldtarget."', total: ".$total."\n"; print "- No email sent for '".$oldtarget."', total: ".$total."\n";
else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n"; } else {
print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
}
} }
} }
} }
@ -230,8 +243,9 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget, $
{ {
global $conf, $langs; global $conf, $langs;
if (getenv('DOL_FORCE_EMAIL_TO')) if (getenv('DOL_FORCE_EMAIL_TO')) {
$oldemail = getenv('DOL_FORCE_EMAIL_TO'); $oldemail = getenv('DOL_FORCE_EMAIL_TO');
}
$newlangs = new Translate('', $conf); $newlangs = new Translate('', $conf);
$newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang); $newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang);
@ -239,10 +253,14 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget, $
$newlangs->load("contracts"); $newlangs->load("contracts");
if ($duration_value) { if ($duration_value) {
if ($duration_value > 0) if ($duration_value > 0) {
$title = $newlangs->transnoentities("ListOfServicesToExpireWithDuration", $duration_value); $title = $newlangs->transnoentities("ListOfServicesToExpireWithDuration", $duration_value);
else $title = $newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg", $duration_value); } else {
} else $title = $newlangs->transnoentities("ListOfServicesToExpire"); $title = $newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg", $duration_value);
}
} else {
$title = $newlangs->transnoentities("ListOfServicesToExpire");
}
$subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT) ? $title : $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT); $subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT) ? $title : $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT);
$sendto = $oldemail; $sendto = $oldemail;
@ -254,10 +272,12 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget, $
dol_syslog("email_expire_services_to_customers.php: send mail to ".$oldemail); dol_syslog("email_expire_services_to_customers.php: send mail to ".$oldemail);
$usehtml = 0; $usehtml = 0;
if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) {
$usehtml += 1; $usehtml += 1;
if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) }
if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) {
$usehtml += 1; $usehtml += 1;
}
$allmessage = ''; $allmessage = '';
if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) { if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) {
@ -270,9 +290,10 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget, $
// $allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n"); // $allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");
if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) { if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) {
$allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER; $allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER;
if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) {
$usehtml += 1; $usehtml += 1;
} }
}
$mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml); $mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);

View File

@ -25,7 +25,9 @@
* \brief Script to send a mail to dolibarr users linked to companies with services to expire * \brief Script to send a mail to dolibarr users linked to companies with services to expire
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);
@ -79,8 +81,9 @@ $sql .= " u.rowid as uid, u.lastname, u.firstname, u.email, u.lang";
$sql .= " FROM ".MAIN_DB_PREFIX."societe AS s, ".MAIN_DB_PREFIX."contrat AS c, ".MAIN_DB_PREFIX."contratdet AS cd"; $sql .= " FROM ".MAIN_DB_PREFIX."societe AS s, ".MAIN_DB_PREFIX."contrat AS c, ".MAIN_DB_PREFIX."contratdet AS cd";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product AS p ON p.rowid = cd.fk_product, ".MAIN_DB_PREFIX."societe_commerciaux AS sc, ".MAIN_DB_PREFIX."user AS u"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product AS p ON p.rowid = cd.fk_product, ".MAIN_DB_PREFIX."societe_commerciaux AS sc, ".MAIN_DB_PREFIX."user AS u";
$sql .= " WHERE s.rowid = c.fk_soc AND c.rowid = cd.fk_contrat AND c.statut > 0 AND cd.statut<5"; $sql .= " WHERE s.rowid = c.fk_soc AND c.rowid = cd.fk_contrat AND c.statut > 0 AND cd.statut<5";
if (is_numeric($duration_value)) if (is_numeric($duration_value)) {
$sql .= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'"; $sql .= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
}
$sql .= " AND sc.fk_soc = s.rowid AND sc.fk_user = u.rowid"; $sql .= " AND sc.fk_soc = s.rowid AND sc.fk_user = u.rowid";
$sql .= " ORDER BY u.email ASC, s.rowid ASC, c.ref ASC"; // Order by email to allow one message per email $sql .= " ORDER BY u.email ASC, s.rowid ASC, c.ref ASC"; // Order by email to allow one message per email
@ -107,9 +110,10 @@ if ($resql) {
if (dol_strlen($oldemail) && $oldemail != 'none') { if (dol_strlen($oldemail) && $oldemail != 'none') {
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative, $duration_value); envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative, $duration_value);
} else { } else {
if ($oldemail != 'none') if ($oldemail != 'none') {
print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n"; print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
} }
}
$oldemail = $obj->email; $oldemail = $obj->email;
$olduid = $obj->uid; $olduid = $obj->uid;
$oldlang = $obj->lang; $oldlang = $obj->lang;
@ -118,9 +122,10 @@ if ($resql) {
$total = 0; $total = 0;
$foundtoprocess = 0; $foundtoprocess = 0;
$salerepresentative = dolGetFirstLastname($obj->firstname, $obj->lastname); $salerepresentative = dolGetFirstLastname($obj->firstname, $obj->lastname);
if (empty($obj->email)) if (empty($obj->email)) {
print "Warning: Sale representative ".$salerepresentative." has no email. Notice disabled.\n"; print "Warning: Sale representative ".$salerepresentative." has no email. Notice disabled.\n";
} }
}
// Define line content // Define line content
$outputlangs = new Translate('', $conf); $outputlangs = new Translate('', $conf);
@ -135,9 +140,11 @@ if ($resql) {
$foundtoprocess++; $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')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email."): "; 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')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email."): ";
if (dol_strlen($obj->email)) if (dol_strlen($obj->email)) {
print "qualified."; print "qualified.";
else print "disqualified (no email)."; } else {
print "disqualified (no email).";
}
print "\n"; print "\n";
unset($outputlangs); unset($outputlangs);
@ -148,14 +155,14 @@ if ($resql) {
// Si il reste des envois en buffer // Si il reste des envois en buffer
if ($foundtoprocess) { if ($foundtoprocess) {
if (dol_strlen($oldemail) && $oldemail != 'none') // Break onto email (new email) if (dol_strlen($oldemail) && $oldemail != 'none') { // Break onto email (new email)
{
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative, $duration_value); envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative, $duration_value);
} else { } else {
if ($oldemail != 'none') if ($oldemail != 'none') {
print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n"; print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
} }
} }
}
} else { } else {
print "No services to expire (for companies linked to a particular commercial dolibarr user) found\n"; print "No services to expire (for companies linked to a particular commercial dolibarr user) found\n";
} }
@ -184,8 +191,9 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldsalerepre
{ {
global $conf, $langs; global $conf, $langs;
if (getenv('DOL_FORCE_EMAIL_TO')) if (getenv('DOL_FORCE_EMAIL_TO')) {
$oldemail = getenv('DOL_FORCE_EMAIL_TO'); $oldemail = getenv('DOL_FORCE_EMAIL_TO');
}
$newlangs = new Translate('', $conf); $newlangs = new Translate('', $conf);
$newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang); $newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang);
@ -230,9 +238,10 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldsalerepre
$allmessage .= $langs->trans("Total")." = ".price($total, 0, $userlang, 0, 0, - 1, $conf->currency).($usehtml ? "<br>\n" : "\n"); $allmessage .= $langs->trans("Total")." = ".price($total, 0, $userlang, 0, 0, - 1, $conf->currency).($usehtml ? "<br>\n" : "\n");
if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) { if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) {
$allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER; $allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER;
if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) {
$usehtml += 1; $usehtml += 1;
} }
}
$mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml); $mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);

View File

@ -25,12 +25,24 @@
* \brief Execute pendings jobs * \brief Execute pendings jobs
*/ */
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Disables token renewal if (!defined('NOTOKENRENEWAL')) {
if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); define('NOTOKENRENEWAL', '1'); // Disables token renewal
if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); }
if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); if (!defined('NOREQUIREMENU')) {
if (!defined('NOLOGIN')) define('NOLOGIN', '1'); define('NOREQUIREMENU', '1');
if (!defined('NOSESSION')) define('NOSESSION', '1'); }
if (!defined('NOREQUIREHTML')) {
define('NOREQUIREHTML', '1');
}
if (!defined('NOREQUIREAJAX')) {
define('NOREQUIREAJAX', '1');
}
if (!defined('NOLOGIN')) {
define('NOLOGIN', '1');
}
if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);
@ -106,7 +118,9 @@ if ($userlogin == 'firstadmin') {
$userlogin = $obj->login; $userlogin = $obj->login;
echo "First admin user found is login '".$userlogin."', entity ".$obj->entity."\n"; echo "First admin user found is login '".$userlogin."', entity ".$obj->entity."\n";
} }
} else dol_print_error($db); } else {
dol_print_error($db);
}
} }
// Check user login // Check user login
@ -151,8 +165,7 @@ if ($result < 0) {
$qualifiedjobs = array(); $qualifiedjobs = array();
foreach ($object->lines as $val) { foreach ($object->lines as $val) {
if (!verifCond($val->test)) if (!verifCond($val->test)) {
{
continue; continue;
} }
$qualifiedjobs[] = $val; $qualifiedjobs[] = $val;
@ -173,8 +186,7 @@ if (is_array($qualifiedjobs) && (count($qualifiedjobs) > 0)) {
echo "cron_run_jobs.php cronjobid: ".$line->id." priority=".$line->priority." entity=".$line->entity." label=".$line->label; echo "cron_run_jobs.php cronjobid: ".$line->id." priority=".$line->priority." entity=".$line->entity." label=".$line->label;
// Force reload of setup for the current entity // Force reload of setup for the current entity
if ((empty($line->entity) ? 1 : $line->entity) != $conf->entity) if ((empty($line->entity) ? 1 : $line->entity) != $conf->entity) {
{
dol_syslog("cron_run_jobs.php we work on another entity conf than ".$conf->entity." so we reload mysoc, langs, user and conf", LOG_DEBUG); dol_syslog("cron_run_jobs.php we work on another entity conf than ".$conf->entity." so we reload mysoc, langs, user and conf", LOG_DEBUG);
echo " -> we change entity so we reload mysoc, langs, user and conf"; echo " -> we change entity so we reload mysoc, langs, user and conf";
@ -183,17 +195,14 @@ if (is_array($qualifiedjobs) && (count($qualifiedjobs) > 0)) {
$mysoc->setMysoc($conf); $mysoc->setMysoc($conf);
// Force recheck that user is ok for the entity to process and reload permission for entity // Force recheck that user is ok for the entity to process and reload permission for entity
if ($conf->entity != $user->entity && $user->entity != 0) if ($conf->entity != $user->entity && $user->entity != 0) {
{
$result = $user->fetch('', $userlogin, '', 0, $conf->entity); $result = $user->fetch('', $userlogin, '', 0, $conf->entity);
if ($result < 0) if ($result < 0) {
{
echo "\nUser Error: ".$user->error."\n"; echo "\nUser Error: ".$user->error."\n";
dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_ERR); dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
exit(-1); exit(-1);
} else { } else {
if ($result == 0) if ($result == 0) {
{
echo "\nUser login: ".$userlogin." does not exists for entity ".$conf->entity."\n"; echo "\nUser login: ".$userlogin." does not exists for entity ".$conf->entity."\n";
dol_syslog("User login:".$userlogin." does not exists", LOG_ERR); dol_syslog("User login:".$userlogin." does not exists", LOG_ERR);
exit(-1); exit(-1);
@ -204,8 +213,12 @@ if (is_array($qualifiedjobs) && (count($qualifiedjobs) > 0)) {
// Reload langs // Reload langs
$langcode = (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT); $langcode = (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT);
if (!empty($user->conf->MAIN_LANG_DEFAULT)) $langcode = $user->conf->MAIN_LANG_DEFAULT; if (!empty($user->conf->MAIN_LANG_DEFAULT)) {
if ($langs->getDefaultLang() != $langcode) $langs->setDefaultLang($langcode); $langcode = $user->conf->MAIN_LANG_DEFAULT;
}
if ($langs->getDefaultLang() != $langcode) {
$langs->setDefaultLang($langcode);
}
} }
//If date_next_jobs is less of current date, execute the program, and store the execution time of the next execution in database //If date_next_jobs is less of current date, execute the program, and store the execution time of the next execution in database
@ -262,8 +275,9 @@ if (is_array($qualifiedjobs) && (count($qualifiedjobs) > 0)) {
$db->close(); $db->close();
if ($nbofjobslaunchedko) if ($nbofjobslaunchedko) {
exit(1); exit(1);
}
exit(0); exit(0);
/** /**

View File

@ -26,7 +26,9 @@
* \brief Script to send a prepared and validated emaling from command line * \brief Script to send a prepared and validated emaling from command line
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);
@ -45,12 +47,17 @@ if (!isset($argv[1]) || !$argv[1]) {
$id = $argv[1]; $id = $argv[1];
if (isset($argv[2]) || !empty($argv[2])) $login = $argv[2]; if (isset($argv[2]) || !empty($argv[2])) {
else $login = ''; $login = $argv[2];
} else {
$login = '';
}
$max = 0; $max = 0;
if (isset($argv[3]) || !empty($argv[3])) $max = $argv[3]; if (isset($argv[3]) || !empty($argv[3])) {
$max = $argv[3];
}
require_once $path."../../htdocs/master.inc.php"; require_once $path."../../htdocs/master.inc.php";
@ -61,8 +68,7 @@ require_once DOL_DOCUMENT_ROOT."/comm/mailing/class/mailing.class.php";
$version = DOL_VERSION; $version = DOL_VERSION;
$error = 0; $error = 0;
if (empty($conf->global->MAILING_LIMIT_SENDBYCLI)) if (empty($conf->global->MAILING_LIMIT_SENDBYCLI)) {
{
$conf->global->MAILING_LIMIT_SENDBYCLI = 0; $conf->global->MAILING_LIMIT_SENDBYCLI = 0;
} }
@ -78,12 +84,14 @@ if (!empty($conf->global->MAILING_DELAY)) {
print 'A delay of '.((float) $conf->global->MAILING_DELAY * 1000000).' millisecond has been set between each email'."\n"; print 'A delay of '.((float) $conf->global->MAILING_DELAY * 1000000).' millisecond has been set between each email'."\n";
} }
if ($conf->global->MAILING_LIMIT_SENDBYCLI == '-1') {} if ($conf->global->MAILING_LIMIT_SENDBYCLI == '-1') {
}
$user = new User($db); $user = new User($db);
// for signature, we use user send as parameter // for signature, we use user send as parameter
if (!empty($login)) if (!empty($login)) {
$user->fetch('', $login); $user->fetch('', $login);
}
// We get list of emailing id to process // We get list of emailing id to process
$sql = "SELECT m.rowid"; $sql = "SELECT m.rowid";
@ -119,8 +127,9 @@ if ($resql) {
$errorsto = $emailing->email_errorsto; $errorsto = $emailing->email_errorsto;
// Le message est-il en html // Le message est-il en html
$msgishtml = - 1; // Unknown by default $msgishtml = - 1; // Unknown by default
if (preg_match('/[\s\t]*<html>/i', $message)) if (preg_match('/[\s\t]*<html>/i', $message)) {
$msgishtml = 1; $msgishtml = 1;
}
$nbok = 0; $nbok = 0;
$nbko = 0; $nbko = 0;
@ -202,12 +211,15 @@ if ($resql) {
$substitutionarray['__UNSUBSCRIBE__'] = '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj->tag.'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>'; $substitutionarray['__UNSUBSCRIBE__'] = '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj->tag.'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>';
$onlinepaymentenabled = 0; $onlinepaymentenabled = 0;
if (!empty($conf->paypal->enabled)) if (!empty($conf->paypal->enabled)) {
$onlinepaymentenabled++; $onlinepaymentenabled++;
if (!empty($conf->paybox->enabled)) }
if (!empty($conf->paybox->enabled)) {
$onlinepaymentenabled++; $onlinepaymentenabled++;
if (!empty($conf->stripe->enabled)) }
if (!empty($conf->stripe->enabled)) {
$onlinepaymentenabled++; $onlinepaymentenabled++;
}
if ($onlinepaymentenabled && !empty($conf->global->PAYMENT_SECURITY_TOKEN)) { if ($onlinepaymentenabled && !empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
$substitutionarray['__SECUREKEYPAYMENT__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2); $substitutionarray['__SECUREKEYPAYMENT__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
@ -226,21 +238,29 @@ if ($resql) {
if (!empty($conf->paypal->enabled) && !empty($conf->global->PAYPAL_SECURITY_TOKEN)) { if (!empty($conf->paypal->enabled) && !empty($conf->global->PAYPAL_SECURITY_TOKEN)) {
$substitutionarray['__SECUREKEYPAYPAL__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2); $substitutionarray['__SECUREKEYPAYPAL__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
$substitutionarray['__SECUREKEYPAYPAL_MEMBER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2); $substitutionarray['__SECUREKEYPAYPAL_MEMBER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
else $substitutionarray['__SECUREKEYPAYPAL_MEMBER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.'membersubscription'.$obj->source_id, 2); } else {
$substitutionarray['__SECUREKEYPAYPAL_MEMBER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.'membersubscription'.$obj->source_id, 2);
}
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
$substitutionarray['__SECUREKEYPAYPAL_ORDER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2); $substitutionarray['__SECUREKEYPAYPAL_ORDER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
else $substitutionarray['__SECUREKEYPAYPAL_ORDER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.'order'.$obj->source_id, 2); } else {
$substitutionarray['__SECUREKEYPAYPAL_ORDER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.'order'.$obj->source_id, 2);
}
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
$substitutionarray['__SECUREKEYPAYPAL_INVOICE__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2); $substitutionarray['__SECUREKEYPAYPAL_INVOICE__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
else $substitutionarray['__SECUREKEYPAYPAL_INVOICE__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.'invoice'.$obj->source_id, 2); } else {
$substitutionarray['__SECUREKEYPAYPAL_INVOICE__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.'invoice'.$obj->source_id, 2);
}
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
$substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2); $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
else $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.'contractline'.$obj->source_id, 2); } else {
$substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.'contractline'.$obj->source_id, 2);
}
} }
complete_substitutions_array($substitutionarray, $langs); complete_substitutions_array($substitutionarray, $langs);
@ -256,10 +276,8 @@ if ($resql) {
$listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0); $listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0);
if (count($listofpaths)) if (count($listofpaths)) {
{ foreach ($listofpaths as $key => $val) {
foreach ($listofpaths as $key => $val)
{
$arr_file[] = $listofpaths[$key]['fullname']; $arr_file[] = $listofpaths[$key]['fullname'];
$arr_mime[] = dol_mimetype($listofpaths[$key]['name']); $arr_mime[] = dol_mimetype($listofpaths[$key]['name']);
$arr_name[] = $listofpaths[$key]['name']; $arr_name[] = $listofpaths[$key]['name'];
@ -364,8 +382,9 @@ if ($resql) {
// Loop finished, set global statut of mail // Loop finished, set global statut of mail
$statut = 2; $statut = 2;
if (!$nbko) if (!$nbko) {
$statut = 3; $statut = 3;
}
$sqlenddate = "UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$id; $sqlenddate = "UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$id;

View File

@ -22,8 +22,12 @@
* \brief Script to reset (set email to empty) from a list of email * \brief Script to reset (set email to empty) from a list of email
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
if (!defined('MAXEMAILS')) define('MAXEMAILS', 100); define('NOSESSION', '1');
}
if (!defined('MAXEMAILS')) {
define('MAXEMAILS', 100);
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);
@ -71,8 +75,7 @@ $db->begin();
$myfile = fopen($fileofinvalidemail, "r"); $myfile = fopen($fileofinvalidemail, "r");
if (!$myfile) if (!$myfile) {
{
echo "Failed to open file"; echo "Failed to open file";
exit(-1); exit(-1);
} }
@ -81,14 +84,11 @@ $tmp = 1;
$counter = 1; $counter = 1;
$numerasedtotal = 0; $numerasedtotal = 0;
while ($tmp != null) while ($tmp != null) {
{
$groupofemails = array(); $groupofemails = array();
for ($i = 0; $i < MAXEMAILS; $i++) for ($i = 0; $i < MAXEMAILS; $i++) {
{
$tmp = fgets($myfile); $tmp = fgets($myfile);
if ($tmp == null) if ($tmp == null) {
{
break; break;
} }
$groupofemails[$i] = trim($tmp, "\n"); $groupofemails[$i] = trim($tmp, "\n");
@ -109,8 +109,7 @@ while ($tmp != null)
$sql_base = "UPDATE ".MAIN_DB_PREFIX; $sql_base = "UPDATE ".MAIN_DB_PREFIX;
if ($type == 'all' || $type == 'users') if ($type == 'all' || $type == 'users') {
{
// Loop on each record and update the email to null if email into $groupofemails // Loop on each record and update the email to null if email into $groupofemails
$sql = $sql_base."user as u SET u.email = NULL WHERE u.email IN (".$emailsin.");"; $sql = $sql_base."user as u SET u.email = NULL WHERE u.email IN (".$emailsin.");";
print "Try to update users, "; print "Try to update users, ";
@ -121,8 +120,7 @@ while ($tmp != null)
$numerased += $db->affected_rows($resql); $numerased += $db->affected_rows($resql);
} }
if ($type == 'all' || $type == 'thirdparties') if ($type == 'all' || $type == 'thirdparties') {
{
// Loop on each record and update the email to null if email into $groupofemails // Loop on each record and update the email to null if email into $groupofemails
$sql = $sql_base."societe as s SET s.email = NULL WHERE s.email IN (".$emailsin.");"; $sql = $sql_base."societe as s SET s.email = NULL WHERE s.email IN (".$emailsin.");";
print "Try to update thirdparties, "; print "Try to update thirdparties, ";
@ -133,8 +131,7 @@ while ($tmp != null)
$numerased += $db->affected_rows($resql); $numerased += $db->affected_rows($resql);
} }
if ($type == 'all' || $type == 'contacts') if ($type == 'all' || $type == 'contacts') {
{
// Loop on each record and update the email to null if email into $groupofemails // Loop on each record and update the email to null if email into $groupofemails
$sql = $sql_base."socpeople as s SET s.email = NULL WHERE s.email IN (".$emailsin.");"; $sql = $sql_base."socpeople as s SET s.email = NULL WHERE s.email IN (".$emailsin.");";
@ -146,8 +143,7 @@ while ($tmp != null)
$numerased += $db->affected_rows($resql); $numerased += $db->affected_rows($resql);
} }
if ($type == 'all' || $type == 'members') if ($type == 'all' || $type == 'members') {
{
// Loop on each record and update the email to null if email into $groupofemails // Loop on each record and update the email to null if email into $groupofemails
$sql = $sql_base."adherent as a SET a.email = NULL WHERE a.email IN (".$emailsin.");"; $sql = $sql_base."adherent as a SET a.email = NULL WHERE a.email IN (".$emailsin.");";

View File

@ -25,7 +25,9 @@
* \brief Script to send a mail to customers with unpaid invoices * \brief Script to send a mail to customers with unpaid invoices
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);
@ -80,22 +82,28 @@ if ($mode != 'confirm') {
$sql = "SELECT f.ref, f.total_ttc, f.date_lim_reglement as due_date,"; $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"; $sql .= " s.rowid as sid, s.nom as name, s.email, s.default_lang";
if ($targettype == 'contacts') if ($targettype == 'contacts') {
$sql .= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail"; $sql .= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail";
}
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s"; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
if ($targettype == 'contacts') if ($targettype == 'contacts') {
$sql .= ", ".MAIN_DB_PREFIX."socpeople as sp"; $sql .= ", ".MAIN_DB_PREFIX."socpeople as sp";
}
$sql .= " WHERE f.fk_statut = 1 AND f.paye = 0"; $sql .= " WHERE f.fk_statut = 1 AND f.paye = 0";
$sql .= " AND f.fk_soc = s.rowid"; $sql .= " AND f.fk_soc = s.rowid";
if (is_numeric($duration_value2)) if (is_numeric($duration_value2)) {
$sql .= " AND f.date_lim_reglement >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'"; $sql .= " AND f.date_lim_reglement >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'";
if (is_numeric($duration_value)) }
if (is_numeric($duration_value)) {
$sql .= " AND f.date_lim_reglement < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'"; $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
if ($targettype == 'contacts') }
if ($targettype == 'contacts') {
$sql .= " AND s.rowid = sp.fk_soc"; $sql .= " AND s.rowid = sp.fk_soc";
}
$sql .= " ORDER BY"; $sql .= " ORDER BY";
if ($targettype == 'contacts') if ($targettype == 'contacts') {
$sql .= " sp.email, sp.rowid,"; $sql .= " sp.email, sp.rowid,";
}
$sql .= " s.email ASC, s.rowid ASC, f.ref ASC"; // Order by email to allow one message per email $sql .= " s.email ASC, s.rowid ASC, f.ref ASC"; // Order by email to allow one message per email
// print $sql; // print $sql;
@ -143,9 +151,11 @@ if ($resql) {
$trackthirdpartiessent[$oldsid.'|'.$oldemail] = 'contact id '.$oldcid; $trackthirdpartiessent[$oldsid.'|'.$oldemail] = 'contact id '.$oldcid;
} else { } else {
if ($oldemail != 'none') { if ($oldemail != 'none') {
if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) {
print "- No email sent for '".$oldtarget."', total: ".$total."\n"; print "- No email sent for '".$oldtarget."', total: ".$total."\n";
else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n"; } else {
print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
}
} }
} }
$oldemail = $newemail; $oldemail = $newemail;
@ -174,9 +184,11 @@ if ($resql) {
$foundtoprocess++; $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.", ".(isset($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)) if (dol_strlen($newemail)) {
print "qualified."; print "qualified.";
else print "disqualified (no email)."; } else {
print "disqualified (no email).";
}
print "\n"; print "\n";
unset($outputlangs); unset($outputlangs);
@ -188,15 +200,16 @@ if ($resql) {
// Si il reste des envois en buffer // Si il reste des envois en buffer
if ($foundtoprocess) { if ($foundtoprocess) {
if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) // Break onto email (new email) if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) { // Break onto email (new email)
{
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldtarget); envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldtarget);
$trackthirdpartiessent[$oldsid.'|'.$oldemail] = 'contact id '.$oldcid; $trackthirdpartiessent[$oldsid.'|'.$oldemail] = 'contact id '.$oldcid;
} else { } else {
if ($oldemail != 'none') { if ($oldemail != 'none') {
if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) {
print "- No email sent for '".$oldtarget."', total: ".$total."\n"; print "- No email sent for '".$oldtarget."', total: ".$total."\n";
else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n"; } else {
print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
}
} }
} }
} }
@ -227,8 +240,9 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget)
{ {
global $conf, $langs; global $conf, $langs;
if (getenv('DOL_FORCE_EMAIL_TO')) if (getenv('DOL_FORCE_EMAIL_TO')) {
$oldemail = getenv('DOL_FORCE_EMAIL_TO'); $oldemail = getenv('DOL_FORCE_EMAIL_TO');
}
$newlangs = new Translate('', $conf); $newlangs = new Translate('', $conf);
$newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang); $newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang);
@ -245,10 +259,12 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget)
dol_syslog("email_unpaid_invoices_to_customers.php: send mail to ".$oldemail); dol_syslog("email_unpaid_invoices_to_customers.php: send mail to ".$oldemail);
$usehtml = 0; $usehtml = 0;
if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER) && 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; $usehtml += 1;
if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER) && 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; $usehtml += 1;
}
$allmessage = ''; $allmessage = '';
if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER)) { if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER)) {
@ -262,9 +278,10 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget)
$allmessage .= $langs->trans("Total")." = ".price($total, 0, $userlang, 0, 0, - 1, $conf->currency).($usehtml ? "<br>\n" : "\n"); $allmessage .= $langs->trans("Total")." = ".price($total, 0, $userlang, 0, 0, - 1, $conf->currency).($usehtml ? "<br>\n" : "\n");
if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) { if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) {
$allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER; $allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER;
if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) {
$usehtml += 1; $usehtml += 1;
} }
}
$mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml); $mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);

View File

@ -25,7 +25,9 @@
* \brief Script to send a mail to dolibarr users linked to companies with unpaid invoices * \brief Script to send a mail to dolibarr users linked to companies with unpaid invoices
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);
@ -82,8 +84,9 @@ $sql .= " , ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql .= " , ".MAIN_DB_PREFIX."user as u"; $sql .= " , ".MAIN_DB_PREFIX."user as u";
$sql .= " WHERE f.fk_statut = 1 AND f.paye = 0"; $sql .= " WHERE f.fk_statut = 1 AND f.paye = 0";
$sql .= " AND f.fk_soc = s.rowid"; $sql .= " AND f.fk_soc = s.rowid";
if (is_numeric($duration_value)) if (is_numeric($duration_value)) {
$sql .= " AND f.date_lim_reglement < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'"; $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
}
$sql .= " AND sc.fk_soc = s.rowid"; $sql .= " AND sc.fk_soc = s.rowid";
$sql .= " AND sc.fk_user = u.rowid"; $sql .= " AND sc.fk_user = u.rowid";
$sql .= " ORDER BY u.email ASC, s.rowid ASC, f.ref ASC"; // Order by email to allow one message per email $sql .= " ORDER BY u.email ASC, s.rowid ASC, f.ref ASC"; // Order by email to allow one message per email
@ -111,9 +114,10 @@ if ($resql) {
if (dol_strlen($oldemail) && $oldemail != 'none') { if (dol_strlen($oldemail) && $oldemail != 'none') {
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative); envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative);
} else { } else {
if ($oldemail != 'none') if ($oldemail != 'none') {
print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n"; print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
} }
}
$oldemail = $obj->email; $oldemail = $obj->email;
$olduid = $obj->uid; $olduid = $obj->uid;
$oldlang = $obj->lang; $oldlang = $obj->lang;
@ -122,9 +126,10 @@ if ($resql) {
$total = 0; $total = 0;
$foundtoprocess = 0; $foundtoprocess = 0;
$salerepresentative = dolGetFirstLastname($obj->firstname, $obj->lastname); $salerepresentative = dolGetFirstLastname($obj->firstname, $obj->lastname);
if (empty($obj->email)) if (empty($obj->email)) {
print "Warning: Sale representative ".$salerepresentative." has no email. Notice disabled.\n"; print "Warning: Sale representative ".$salerepresentative." has no email. Notice disabled.\n";
} }
}
// Define line content // Define line content
$outputlangs = new Translate('', $conf); $outputlangs = new Translate('', $conf);
@ -139,9 +144,11 @@ if ($resql) {
$foundtoprocess++; $foundtoprocess++;
} }
print "Unpaid invoice ".$obj->ref.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date), 'day')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email.", lang ".$outputlangs->defaultlang."): "; print "Unpaid invoice ".$obj->ref.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date), 'day')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email.", lang ".$outputlangs->defaultlang."): ";
if (dol_strlen($obj->email)) if (dol_strlen($obj->email)) {
print "qualified."; print "qualified.";
else print "disqualified (no email)."; } else {
print "disqualified (no email).";
}
print "\n"; print "\n";
unset($outputlangs); unset($outputlangs);
@ -152,14 +159,14 @@ if ($resql) {
// Si il reste des envois en buffer // Si il reste des envois en buffer
if ($foundtoprocess) { if ($foundtoprocess) {
if (dol_strlen($oldemail) && $oldemail != 'none') // Break onto email (new email) if (dol_strlen($oldemail) && $oldemail != 'none') { // Break onto email (new email)
{
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative); envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative);
} else { } else {
if ($oldemail != 'none') if ($oldemail != 'none') {
print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n"; print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
} }
} }
}
} else { } else {
print "No unpaid invoices (for companies linked to a particular commercial dolibarr user) found\n"; print "No unpaid invoices (for companies linked to a particular commercial dolibarr user) found\n";
} }
@ -187,8 +194,9 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldsalerepre
{ {
global $conf, $langs; global $conf, $langs;
if (getenv('DOL_FORCE_EMAIL_TO')) if (getenv('DOL_FORCE_EMAIL_TO')) {
$oldemail = getenv('DOL_FORCE_EMAIL_TO'); $oldemail = getenv('DOL_FORCE_EMAIL_TO');
}
$newlangs = new Translate('', $conf); $newlangs = new Translate('', $conf);
$newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang); $newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang);
@ -205,10 +213,12 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldsalerepre
dol_syslog("email_unpaid_invoices_to_representatives.php: send mail to ".$oldemail); dol_syslog("email_unpaid_invoices_to_representatives.php: send mail to ".$oldemail);
$usehtml = 0; $usehtml = 0;
if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER) && 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; $usehtml += 1;
if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER) && 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; $usehtml += 1;
}
$allmessage = ''; $allmessage = '';
if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) { if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) {
@ -221,9 +231,10 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldsalerepre
$allmessage .= $langs->trans("Total")." = ".price($total, 0, $newlangs, 0, 0, - 1, $conf->currency).($usehtml ? "<br>\n" : "\n"); $allmessage .= $langs->trans("Total")." = ".price($total, 0, $newlangs, 0, 0, - 1, $conf->currency).($usehtml ? "<br>\n" : "\n");
if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) { if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) {
$allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER; $allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER;
if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) {
$usehtml += 1; $usehtml += 1;
} }
}
$mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml); $mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);

View File

@ -23,7 +23,9 @@
* \brief Script to rebuild PDF and merge PDF files into one * \brief Script to rebuild PDF and merge PDF files into one
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);

View File

@ -24,7 +24,9 @@
* \brief Script de mise a jour des adherents dans LDAP depuis base Dolibarr * \brief Script de mise a jour des adherents dans LDAP depuis base Dolibarr
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);
@ -61,8 +63,9 @@ if (!isset($argv[1]) || !$argv[1]) {
} }
foreach ($argv as $key => $val) { foreach ($argv as $key => $val) {
if (preg_match('/-y$/', $val, $reg)) if (preg_match('/-y$/', $val, $reg)) {
$confirmed = 1; $confirmed = 1;
}
} }
$now = $argv[1]; $now = $argv[1];

View File

@ -24,7 +24,9 @@
* \brief Script de mise a jour des adherents dans Dolibarr depuis LDAP * \brief Script de mise a jour des adherents dans Dolibarr depuis LDAP
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);
@ -98,12 +100,15 @@ if (!isset($argv[2]) || !is_numeric($argv[2])) {
$typeid = $argv[2]; $typeid = $argv[2];
foreach ($argv as $key => $val) { foreach ($argv as $key => $val) {
if ($val == 'commitiferror') if ($val == 'commitiferror') {
$forcecommit = 1; $forcecommit = 1;
if (preg_match('/--server=([^\s]+)$/', $val, $reg)) }
if (preg_match('/--server=([^\s]+)$/', $val, $reg)) {
$conf->global->LDAP_SERVER_HOST = $reg[1]; $conf->global->LDAP_SERVER_HOST = $reg[1];
if (preg_match('/-y$/', $val, $reg)) }
if (preg_match('/-y$/', $val, $reg)) {
$confirmed = 1; $confirmed = 1;
}
} }
print "Mails sending disabled (useless in batch mode)\n"; print "Mails sending disabled (useless in batch mode)\n";
@ -115,9 +120,11 @@ print "port=".$conf->global->LDAP_SERVER_PORT."\n";
print "login=".$conf->global->LDAP_ADMIN_DN."\n"; print "login=".$conf->global->LDAP_ADMIN_DN."\n";
print "pass=".preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)."\n"; print "pass=".preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)."\n";
print "DN to extract=".$conf->global->LDAP_MEMBER_DN."\n"; print "DN to extract=".$conf->global->LDAP_MEMBER_DN."\n";
if (!empty($conf->global->LDAP_MEMBER_FILTER)) if (!empty($conf->global->LDAP_MEMBER_FILTER)) {
print 'Filter=('.$conf->global->LDAP_MEMBER_FILTER.')'."\n"; // Note: filter is defined into function getRecords print 'Filter=('.$conf->global->LDAP_MEMBER_FILTER.')'."\n"; // Note: filter is defined into function getRecords
else print 'Filter=('.$conf->global->LDAP_KEY_MEMBERS.'=*)'."\n"; } else {
print 'Filter=('.$conf->global->LDAP_KEY_MEMBERS.'=*)'."\n";
}
print "----- To Dolibarr database:\n"; print "----- To Dolibarr database:\n";
print "type=".$conf->db->type."\n"; print "type=".$conf->db->type."\n";
print "host=".$conf->db->host."\n"; print "host=".$conf->db->host."\n";
@ -257,10 +264,11 @@ if ($result >= 0) {
if ($datefirst && $datelast && $datelast <= $datefirst) { if ($datefirst && $datelast && $datelast <= $datefirst) {
// On ne va inserer que la premiere // On ne va inserer que la premiere
$datelast = 0; $datelast = 0;
if (!$pricefirst && $pricelast) if (!$pricefirst && $pricelast) {
$pricefirst = $pricelast; $pricefirst = $pricelast;
} }
} }
}
// Insert first subscription // Insert first subscription
if ($datefirst) { if ($datefirst) {
@ -278,9 +286,11 @@ if ($result >= 0) {
} }
if (!$error || $forcecommit) { if (!$error || $forcecommit) {
if (!$error) if (!$error) {
print $langs->transnoentities("NoErrorCommitIsDone")."\n"; print $langs->transnoentities("NoErrorCommitIsDone")."\n";
else print $langs->transnoentities("ErrorButCommitIsDone")."\n"; } else {
print $langs->transnoentities("ErrorButCommitIsDone")."\n";
}
$db->commit(); $db->commit();
} else { } else {
print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error)."\n"; print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error)."\n";

View File

@ -25,7 +25,9 @@
* \brief Script de mise a jour des types de membres dans LDAP depuis base Dolibarr * \brief Script de mise a jour des types de membres dans LDAP depuis base Dolibarr
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);

View File

@ -26,7 +26,9 @@
* \brief Script to update members types into Dolibarr from LDAP * \brief Script to update members types into Dolibarr from LDAP
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);
@ -72,14 +74,18 @@ if (!isset($argv[1])) {
} }
foreach ($argv as $key => $val) { foreach ($argv as $key => $val) {
if ($val == 'commitiferror') if ($val == 'commitiferror') {
$forcecommit = 1; $forcecommit = 1;
if (preg_match('/--server=([^\s]+)$/', $val, $reg)) }
if (preg_match('/--server=([^\s]+)$/', $val, $reg)) {
$conf->global->LDAP_SERVER_HOST = $reg[1]; $conf->global->LDAP_SERVER_HOST = $reg[1];
if (preg_match('/--excludeuser=([^\s]+)$/', $val, $reg)) }
if (preg_match('/--excludeuser=([^\s]+)$/', $val, $reg)) {
$excludeuser = explode(',', $reg[1]); $excludeuser = explode(',', $reg[1]);
if (preg_match('/-y$/', $val, $reg)) }
if (preg_match('/-y$/', $val, $reg)) {
$confirmed = 1; $confirmed = 1;
}
} }
print "Mails sending disabled (useless in batch mode)\n"; print "Mails sending disabled (useless in batch mode)\n";
@ -163,9 +169,11 @@ if ($result >= 0) {
} }
if (!$error || $forcecommit) { if (!$error || $forcecommit) {
if (!$error) if (!$error) {
print $langs->transnoentities("NoErrorCommitIsDone")."\n"; print $langs->transnoentities("NoErrorCommitIsDone")."\n";
else print $langs->transnoentities("ErrorButCommitIsDone")."\n"; } else {
print $langs->transnoentities("ErrorButCommitIsDone")."\n";
}
$db->commit(); $db->commit();
} else { } else {
print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error)."\n"; print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error)."\n";

View File

@ -24,7 +24,9 @@
* \brief Migrate pictures from old system prior to 3.7 to new path for 3.7+ * \brief Migrate pictures from old system prior to 3.7 to new path for 3.7+
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);

View File

@ -24,7 +24,9 @@
* \brief Migrate pictures from old system prior to 3.7 to new path for 3.7+ * \brief Migrate pictures from old system prior to 3.7 to new path for 3.7+
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);
@ -90,15 +92,17 @@ foreach ($filearray as $keyf => $valf) {
// Create small thumbs for image // Create small thumbs for image
// Used on logon for example // Used on logon for example
$imgThumbSmall = vignette($vali['fullname'], $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs"); $imgThumbSmall = vignette($vali['fullname'], $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs");
if (preg_match('/Error/', $imgThumbSmall)) if (preg_match('/Error/', $imgThumbSmall)) {
print $imgThumbSmall."\n"; print $imgThumbSmall."\n";
}
// Create mini thumbs for image (Ratio is near 16/9) // Create mini thumbs for image (Ratio is near 16/9)
// Used on menu or for setup page for example // Used on menu or for setup page for example
$imgThumbMini = vignette($vali['fullname'], $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs"); $imgThumbMini = vignette($vali['fullname'], $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs");
if (preg_match('/Error/', $imgThumbMini)) if (preg_match('/Error/', $imgThumbMini)) {
print $imgThumbMini."\n"; print $imgThumbMini."\n";
} }
}
} }
$db->close(); // Close $db database opened handler $db->close(); // Close $db database opened handler

View File

@ -24,7 +24,9 @@
* \brief Script de mise a jour des groupes dans LDAP depuis base Dolibarr * \brief Script de mise a jour des groupes dans LDAP depuis base Dolibarr
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);

View File

@ -25,7 +25,9 @@
* \brief Script to update groups into Dolibarr from LDAP * \brief Script to update groups into Dolibarr from LDAP
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);
@ -72,14 +74,18 @@ if (!isset($argv[1])) {
} }
foreach ($argv as $key => $val) { foreach ($argv as $key => $val) {
if ($val == 'commitiferror') if ($val == 'commitiferror') {
$forcecommit = 1; $forcecommit = 1;
if (preg_match('/--server=([^\s]+)$/', $val, $reg)) }
if (preg_match('/--server=([^\s]+)$/', $val, $reg)) {
$conf->global->LDAP_SERVER_HOST = $reg[1]; $conf->global->LDAP_SERVER_HOST = $reg[1];
if (preg_match('/--excludeuser=([^\s]+)$/', $val, $reg)) }
if (preg_match('/--excludeuser=([^\s]+)$/', $val, $reg)) {
$excludeuser = explode(',', $reg[1]); $excludeuser = explode(',', $reg[1]);
if (preg_match('/-y$/', $val, $reg)) }
if (preg_match('/-y$/', $val, $reg)) {
$confirmed = 1; $confirmed = 1;
}
} }
print "Mails sending disabled (useless in batch mode)\n"; print "Mails sending disabled (useless in batch mode)\n";
@ -167,8 +173,9 @@ if ($result >= 0) {
$userList = array(); $userList = array();
$userIdList = array(); $userIdList = array();
foreach ($ldapgroup[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] as $key => $userdn) { foreach ($ldapgroup[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] as $key => $userdn) {
if ($key === 'count') if ($key === 'count') {
continue; continue;
}
if (empty($userList[$userdn])) { // Récupération de l'utilisateur if (empty($userList[$userdn])) { // Récupération de l'utilisateur
// Schéma rfc2307: les membres sont listés dans l'attribut memberUid sous form de login uniquement // Schéma rfc2307: les membres sont listés dans l'attribut memberUid sous form de login uniquement
if ($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS === 'memberUid') { if ($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS === 'memberUid') {
@ -177,8 +184,9 @@ if ($result >= 0) {
$userFilter = explode(',', $userdn); $userFilter = explode(',', $userdn);
$userKey = $ldap->getAttributeValues('('.$userFilter[0].')', $conf->global->LDAP_KEY_USERS); $userKey = $ldap->getAttributeValues('('.$userFilter[0].')', $conf->global->LDAP_KEY_USERS);
} }
if (!is_array($userKey)) if (!is_array($userKey)) {
continue; continue;
}
$fuser = new User($db); $fuser = new User($db);
@ -212,9 +220,11 @@ if ($result >= 0) {
} }
if (!$error || $forcecommit) { if (!$error || $forcecommit) {
if (!$error) if (!$error) {
print $langs->transnoentities("NoErrorCommitIsDone")."\n"; print $langs->transnoentities("NoErrorCommitIsDone")."\n";
else print $langs->transnoentities("ErrorButCommitIsDone")."\n"; } else {
print $langs->transnoentities("ErrorButCommitIsDone")."\n";
}
$db->commit(); $db->commit();
} else { } else {
print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error)."\n"; print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error)."\n";

View File

@ -24,7 +24,9 @@
* \brief Script de mise a jour des users dans LDAP depuis base Dolibarr * \brief Script de mise a jour des users dans LDAP depuis base Dolibarr
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);

View File

@ -22,7 +22,9 @@
* \brief Migrate news from a Joomla databse into a Dolibarr website * \brief Migrate news from a Joomla databse into a Dolibarr website
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);
@ -82,8 +84,7 @@ $websiteid = $website->id;
$importid = dol_print_date(dol_now(), 'dayhourlog'); $importid = dol_print_date(dol_now(), 'dayhourlog');
$dbjoomla = getDoliDBInstance('mysqli', $joomlahost, $joomlalogin, $joomlapass, $joomladatabase, $joomlaport); $dbjoomla = getDoliDBInstance('mysqli', $joomlahost, $joomlalogin, $joomlapass, $joomladatabase, $joomlaport);
if ($dbjoomla->error) if ($dbjoomla->error) {
{
dol_print_error($dbjoomla, "host=".$joomlahost.", port=".$joomlaport.", user=".$joomlalogin.", databasename=".$joomladatabase.", ".$dbjoomla->error); dol_print_error($dbjoomla, "host=".$joomlahost.", port=".$joomlaport.", user=".$joomlalogin.", databasename=".$joomladatabase.", ".$dbjoomla->error);
exit(-1); exit(-1);
} }
@ -124,10 +125,14 @@ while ($obj = $dbjoomla->fetch_object($resql)) {
$title = $obj->title; $title = $obj->title;
//$description = dol_string_nohtmltag($obj->introtext); //$description = dol_string_nohtmltag($obj->introtext);
$description = trim(dol_trunc(dol_string_nohtmltag($obj->metadesc), 250)); $description = trim(dol_trunc(dol_string_nohtmltag($obj->metadesc), 250));
if (empty($description)) $description = trim(dol_trunc(dol_string_nohtmltag($obj->introtext), 250)); if (empty($description)) {
$description = trim(dol_trunc(dol_string_nohtmltag($obj->introtext), 250));
}
$htmltext = ""; $htmltext = "";
if ($blogpostheader) $htmltext .= $blogpostheader."\n"; if ($blogpostheader) {
$htmltext .= $blogpostheader."\n";
}
$htmltext .= '<section id="mysectionnewsintro" contenteditable="true">'."\n"; $htmltext .= '<section id="mysectionnewsintro" contenteditable="true">'."\n";
$htmltext .= $obj->introtext; $htmltext .= $obj->introtext;
$htmltext .= '</section>'."\n"; $htmltext .= '</section>'."\n";
@ -137,7 +142,9 @@ while ($obj = $dbjoomla->fetch_object($resql)) {
$htmltext .= $obj->fulltext; $htmltext .= $obj->fulltext;
$htmltext .= "</section>"; $htmltext .= "</section>";
} }
if ($blogpostfooter) $htmltext .= "\n".$blogpostfooter; if ($blogpostfooter) {
$htmltext .= "\n".$blogpostfooter;
}
$language = ($forcelang ? $forcelang : ($obj->language && $obj->language != '*' ? $obj->language : 'en')); $language = ($forcelang ? $forcelang : ($obj->language && $obj->language != '*' ? $obj->language : 'en'));
$keywords = $obj->metakey; $keywords = $obj->metakey;

View File

@ -22,7 +22,9 @@
* \brief Regenerate all pages of a web site * \brief Regenerate all pages of a web site
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);

View File

@ -24,7 +24,9 @@
* \brief Script de prelevement * \brief Script de prelevement
*/ */
if (!defined('NOSESSION')) define('NOSESSION', '1'); if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);