Checkstyle

This commit is contained in:
Laurent Destailleur 2012-07-04 12:01:45 +02:00
parent 59bd8ada73
commit df42899ecd
2 changed files with 57 additions and 57 deletions

View File

@ -32,8 +32,8 @@ $path=dirname(__FILE__).'/';
// Test if batch mode // Test if batch mode
if (substr($sapi_type, 0, 3) == 'cgi') { if (substr($sapi_type, 0, 3) == 'cgi') {
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
exit; exit;
} }
require_once ($path."../../htdocs/master.inc.php"); require_once ($path."../../htdocs/master.inc.php");
@ -60,9 +60,9 @@ if ($resql)
for ($i=0;$i<$num;$i++) for ($i=0;$i<$num;$i++)
{ {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
dol_syslog("mailing ".$obj->rowid); dol_syslog("mailing ".$obj->rowid);
$id = $obj->rowid; $id = $obj->rowid;
$subject = $obj->sujet; $subject = $obj->sujet;
$message = $obj->body; $message = $obj->body;
@ -72,7 +72,7 @@ if ($resql)
// 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)) $msgishtml=1; if (preg_match('/[\s\t]*<html>/i',$message)) $msgishtml=1;
// Set statut 9 (in progress) to avoid duplication // Set statut 9 (in progress) to avoid duplication
$sql="UPDATE ".MAIN_DB_PREFIX."mailing"; $sql="UPDATE ".MAIN_DB_PREFIX."mailing";
$sql.=" SET statut=9 WHERE rowid=".$id; $sql.=" SET statut=9 WHERE rowid=".$id;
@ -81,47 +81,47 @@ if ($resql)
{ {
dol_print_error($db); dol_print_error($db);
} }
$nbok=0; $nbko=0; $nbok=0; $nbko=0;
// On choisit les mails non deja envoyes pour ce mailing (statut=0) // On choisit les mails non deja envoyes pour ce mailing (statut=0)
// ou envoyes en erreur (statut=-1) // ou envoyes en erreur (statut=-1)
$sql = "SELECT mc.rowid, mc.nom as lastname, mc.prenom as firstname, mc.email, mc.other, mc.source_url, mc.source_id, mc.source_type, mc.tag"; $sql = "SELECT mc.rowid, mc.nom as lastname, mc.prenom as firstname, mc.email, mc.other, mc.source_url, mc.source_id, mc.source_type, mc.tag";
$sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc"; $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
$sql .= " WHERE mc.statut < 1 AND mc.fk_mailing = ".$id; $sql .= " WHERE mc.statut < 1 AND mc.fk_mailing = ".$id;
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)
{ {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
if ($num) if ($num)
{ {
dol_syslog("nb of targets = ".$num, LOG_DEBUG); dol_syslog("nb of targets = ".$num, LOG_DEBUG);
$now=dol_now(); $now=dol_now();
// Positionne date debut envoi // Positionne date debut envoi
$sql="UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi='".$db->idate($now)."' WHERE rowid=".$id; $sql="UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi='".$db->idate($now)."' WHERE rowid=".$id;
$resql2=$db->query($sql); $resql2=$db->query($sql);
if (! $resql2) if (! $resql2)
{ {
dol_print_error($db); dol_print_error($db);
} }
// Look on each email and sent message // Look on each email and sent message
$i = 0; $i = 0;
while ($i < $num) while ($i < $num)
{ {
$res=1; $res=1;
$now=dol_now(); $now=dol_now();
$obj2 = $db->fetch_object($resql); $obj2 = $db->fetch_object($resql);
// sendto en RFC2822 // sendto en RFC2822
$sendto = str_replace(',',' ',$obj2->firstname." ".$obj2->lastname) ." <".$obj2->email.">"; $sendto = str_replace(',',' ',$obj2->firstname." ".$obj2->lastname) ." <".$obj2->email.">";
// Make subtsitutions on topic and body // Make subtsitutions on topic and body
$other=explode(';',$obj2->other); $other=explode(';',$obj2->other);
$other1=$other[0]; $other1=$other[0];
@ -130,42 +130,42 @@ if ($resql)
$other4=$other[3]; $other4=$other[3];
$other5=$other[4]; $other5=$other[4];
$substitutionarray=array( $substitutionarray=array(
'__ID__' => $obj2->source_id, '__ID__' => $obj2->source_id,
'__EMAIL__' => $obj2->email, '__EMAIL__' => $obj2->email,
'__CHECK_READ__' => '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$obj2->tag.'" width="1" height="1" style="width:1px;height:1px" border="0"/>', '__CHECK_READ__' => '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$obj2->tag.'" width="1" height="1" style="width:1px;height:1px" border="0"/>',
'__UNSUSCRIBE__' => '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj2->tag.'&unsuscrib=1" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>', '__UNSUSCRIBE__' => '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj2->tag.'&unsuscrib=1" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>',
'__MAILTOEMAIL__' => '<a href="mailto:'.$obj2->email.'">'.$obj2->email.'</a>', '__MAILTOEMAIL__' => '<a href="mailto:'.$obj2->email.'">'.$obj2->email.'</a>',
'__LASTNAME__' => $obj2->lastname, '__LASTNAME__' => $obj2->lastname,
'__FIRSTNAME__' => $obj2->firstname, '__FIRSTNAME__' => $obj2->firstname,
'__OTHER1__' => $other1, '__OTHER1__' => $other1,
'__OTHER2__' => $other2, '__OTHER2__' => $other2,
'__OTHER3__' => $other3, '__OTHER3__' => $other3,
'__OTHER4__' => $other4, '__OTHER4__' => $other4,
'__OTHER5__' => $other5 '__OTHER5__' => $other5
); );
complete_substitutions_array($substitutionarray,$langs); complete_substitutions_array($substitutionarray,$langs);
$newsubject=make_substitutions($subject,$substitutionarray); $newsubject=make_substitutions($subject,$substitutionarray);
$newmessage=make_substitutions($message,$substitutionarray); $newmessage=make_substitutions($message,$substitutionarray);
$substitutionisok=true; $substitutionisok=true;
// Fabrication du mail // Fabrication du mail
$mail = new CMailFile( $mail = new CMailFile(
$newsubject, $newsubject,
$sendto, $sendto,
$from, $from,
$newmessage, $newmessage,
array(), array(),
array(), array(),
array(), array(),
'', '',
'', '',
0, 0,
$msgishtml, $msgishtml,
$errorsto $errorsto
); );
if ($mail->error) if ($mail->error)
{ {
$res=0; $res=0;
@ -175,20 +175,20 @@ if ($resql)
$mail->error='Some substitution failed'; $mail->error='Some substitution failed';
$res=0; $res=0;
} }
// Send Email // Send Email
if ($res) if ($res)
{ {
$res=$mail->sendfile(); $res=$mail->sendfile();
} }
if ($res) if ($res)
{ {
// Mail successful // Mail successful
$nbok++; $nbok++;
dol_syslog("ok for #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG); dol_syslog("ok for #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
$sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles"; $sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
$sql.=" SET statut=1, date_envoi=".$db->idate($now)." WHERE rowid=".$obj2->rowid; $sql.=" SET statut=1, date_envoi=".$db->idate($now)." WHERE rowid=".$obj2->rowid;
$resql2=$db->query($sql); $resql2=$db->query($sql);
@ -209,11 +209,11 @@ if ($resql)
{ {
dol_print_error($db); dol_print_error($db);
} }
//Update status communication of contact prospect //Update status communication of contact prospect
$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."socpeople AS sc INNER JOIN ".MAIN_DB_PREFIX."mailing_cibles AS mc ON mc.rowid=".$obj2->rowid." AND mc.source_type = 'contact' AND mc.source_id = sc.rowid)"; $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."socpeople AS sc INNER JOIN ".MAIN_DB_PREFIX."mailing_cibles AS mc ON mc.rowid=".$obj2->rowid." AND mc.source_type = 'contact' AND mc.source_id = sc.rowid)";
dol_syslog("fiche.php: set prospect contact status sql=".$sql, LOG_DEBUG); dol_syslog("fiche.php: set prospect contact status sql=".$sql, LOG_DEBUG);
$resql2=$db->query($sql); $resql2=$db->query($sql);
if (! $resql2) if (! $resql2)
{ {
@ -226,9 +226,9 @@ if ($resql)
{ {
// Mail failed // Mail failed
$nbko++; $nbko++;
dol_syslog("error for #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG); dol_syslog("error for #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
$sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles"; $sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
$sql.=" SET statut=-1, date_envoi=".$db->idate($now)." WHERE rowid=".$obj2->rowid; $sql.=" SET statut=-1, date_envoi=".$db->idate($now)." WHERE rowid=".$obj2->rowid;
$resql2=$db->query($sql); $resql2=$db->query($sql);
@ -237,15 +237,15 @@ if ($resql)
dol_print_error($db); dol_print_error($db);
} }
} }
$i++; $i++;
} }
} }
// Loop finished, set global statut of mail // Loop finished, set global statut of mail
$statut=2; $statut=2;
if (! $nbko) $statut=3; if (! $nbko) $statut=3;
$sql="UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$id; $sql="UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$id;
dol_syslog("update global status sql=".$sql, LOG_DEBUG); dol_syslog("update global status sql=".$sql, LOG_DEBUG);
$resql2=$db->query($sql); $resql2=$db->query($sql);

View File

@ -166,8 +166,8 @@ if ($resql)
array(), array(),
array(), array(),
array(), array(),
'', '',
'', '',
0, 0,
$msgishtml, $msgishtml,
$errorsto $errorsto