__DIR__ was not replaced into scripts dir
This commit is contained in:
parent
f94b9e5a12
commit
a9b3748006
@ -22,10 +22,9 @@
|
|||||||
* \ingroup bank
|
* \ingroup bank
|
||||||
* \brief Script file to export bank receipts into Excel files
|
* \brief Script file to export bank receipts into Excel files
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test if batch mode
|
// Test if batch mode
|
||||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||||
@ -52,8 +51,6 @@ require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution
|
|||||||
$version = DOL_VERSION;
|
$version = DOL_VERSION;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -71,7 +68,6 @@ $num=$argv[2];
|
|||||||
$model = $argv[3];
|
$model = $argv[3];
|
||||||
$newlangid = 'en_EN'; // To force a new lang id
|
$newlangid = 'en_EN'; // To force a new lang id
|
||||||
|
|
||||||
|
|
||||||
$invoicestatic = new Facture($db);
|
$invoicestatic = new Facture($db);
|
||||||
$invoicesupplierstatic = new FactureFournisseur($db);
|
$invoicesupplierstatic = new FactureFournisseur($db);
|
||||||
$societestatic = new Societe($db);
|
$societestatic = new Societe($db);
|
||||||
@ -84,15 +80,12 @@ $paymentvatstatic=new Tva($db);
|
|||||||
$bankstatic = new Account($db);
|
$bankstatic = new Account($db);
|
||||||
$banklinestatic = new AccountLine($db);
|
$banklinestatic = new AccountLine($db);
|
||||||
|
|
||||||
|
|
||||||
// Parse parameters
|
// Parse parameters
|
||||||
foreach ($argv as $key => $value)
|
foreach ($argv as $key => $value) {
|
||||||
{
|
|
||||||
$found = false;
|
$found = false;
|
||||||
|
|
||||||
// Define options
|
// Define options
|
||||||
if (preg_match('/^lang=/i', $value))
|
if (preg_match('/^lang=/i', $value)) {
|
||||||
{
|
|
||||||
$found = true;
|
$found = true;
|
||||||
$valarray = explode('=', $value);
|
$valarray = explode('=', $value);
|
||||||
$newlangid = $valarray[1];
|
$newlangid = $valarray[1];
|
||||||
@ -100,10 +93,8 @@ foreach ($argv as $key => $value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$outputlangs = $langs;
|
$outputlangs = $langs;
|
||||||
if (! empty($newlangid))
|
if (! empty($newlangid)) {
|
||||||
{
|
if ($outputlangs->defaultlang != $newlangid) {
|
||||||
if ($outputlangs->defaultlang != $newlangid)
|
|
||||||
{
|
|
||||||
$outputlangs = new Translate("", $conf);
|
$outputlangs = new Translate("", $conf);
|
||||||
$outputlangs->setDefaultLang($newlangid);
|
$outputlangs->setDefaultLang($newlangid);
|
||||||
}
|
}
|
||||||
@ -114,70 +105,40 @@ $outputlangs->loadLangs(array("main", "companies", "bills", "banks", "members",
|
|||||||
|
|
||||||
$acct = new Account($db);
|
$acct = new Account($db);
|
||||||
$result = $acct->fetch('', $bankref);
|
$result = $acct->fetch('', $bankref);
|
||||||
if ($result <= 0)
|
if ($result <= 0) {
|
||||||
{
|
|
||||||
print "Failed to find bank account with ref " . $bankref . ".\n";
|
print "Failed to find bank account with ref " . $bankref . ".\n";
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
print "Export for bank account " . $acct->ref . " (" . $acct->label . ").\n";
|
print "Export for bank account " . $acct->ref . " (" . $acct->label . ").\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Creation de la classe d'export du model ExportXXX
|
// Creation de la classe d'export du model ExportXXX
|
||||||
$dir = DOL_DOCUMENT_ROOT . "/core/modules/export/";
|
$dir = DOL_DOCUMENT_ROOT . "/core/modules/export/";
|
||||||
$file = "export_" . $model . ".modules.php";
|
$file = "export_" . $model . ".modules.php";
|
||||||
$classname = "Export" . $model;
|
$classname = "Export" . $model;
|
||||||
if (! dol_is_file($dir.$file))
|
if (! dol_is_file($dir . $file)) {
|
||||||
{
|
|
||||||
print "No driver to export with format " . $model . "\n";
|
print "No driver to export with format " . $model . "\n";
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
require_once $dir . $file;
|
require_once $dir . $file;
|
||||||
$objmodel = new $classname($db);
|
$objmodel = new $classname($db);
|
||||||
|
|
||||||
|
|
||||||
// Define target path
|
// Define target path
|
||||||
$dirname = $conf->bank->dir_temp;
|
$dirname = $conf->bank->dir_temp;
|
||||||
$filename = 'export-bank-receipts-' . $bankref . '-' . $num . '.' . $objmodel->extension;
|
$filename = 'export-bank-receipts-' . $bankref . '-' . $num . '.' . $objmodel->extension;
|
||||||
|
|
||||||
|
$array_fields = array('bankreceipt' => $outputlangs->transnoentitiesnoconv("AccountStatementShort"),'bankaccount' => $outputlangs->transnoentitiesnoconv("BankAccount"),'dateop' => $outputlangs->transnoentitiesnoconv("DateOperationShort"),'dateval' => $outputlangs->transnoentitiesnoconv("DateValueShort"),'type' => $outputlangs->transnoentitiesnoconv("Type"),'description' => $outputlangs->transnoentitiesnoconv("Description"),'thirdparty' => $outputlangs->transnoentitiesnoconv("Tiers"),'accountelem' => $outputlangs->transnoentitiesnoconv("Piece"),'debit' => $outputlangs->transnoentitiesnoconv("Debit"),'credit' => $outputlangs->transnoentitiesnoconv("Credit"),'soldbefore' => $outputlangs->transnoentitiesnoconv("BankBalanceBefore"),'soldafter' => $outputlangs->transnoentitiesnoconv("BankBalanceAfter"),'comment' => $outputlangs->transnoentitiesnoconv("Comment"));
|
||||||
$array_fields=array(
|
$array_selected = array('bankreceipt' => 'bankreceipt','bankaccount' => 'bankaccount','dateop' => 'dateop','dateval' => 'dateval','type' => 'type','description' => 'description','thirdparty' => 'thirdparty','accountelem' => 'accountelem','debit' => 'debit','credit' => 'credit','soldbefore' => 'soldbefore','soldafter' => 'soldafter','comment' => 'comment');
|
||||||
'bankreceipt'=>$outputlangs->transnoentitiesnoconv("AccountStatementShort"), 'bankaccount'=>$outputlangs->transnoentitiesnoconv("BankAccount"),
|
$array_export_TypeFields = array('bankreceipt' => 'Text','bankaccount' => 'Text','dateop' => 'Date','dateval' => 'Date','type' => 'Text','description' => 'Text','thirdparty' => 'Text','accountelem' => 'Text','debit' => 'Number','credit' => 'Number','soldbefore' => 'Number','soldafter' => 'Number','comment' => 'Text');
|
||||||
'dateop'=>$outputlangs->transnoentitiesnoconv("DateOperationShort"),'dateval'=>$outputlangs->transnoentitiesnoconv("DateValueShort"),'type'=>$outputlangs->transnoentitiesnoconv("Type"),
|
|
||||||
'description'=>$outputlangs->transnoentitiesnoconv("Description"), 'thirdparty'=>$outputlangs->transnoentitiesnoconv("Tiers"), 'accountelem'=>$outputlangs->transnoentitiesnoconv("Piece"),
|
|
||||||
'debit'=>$outputlangs->transnoentitiesnoconv("Debit"), 'credit'=>$outputlangs->transnoentitiesnoconv("Credit"),
|
|
||||||
'soldbefore'=>$outputlangs->transnoentitiesnoconv("BankBalanceBefore"), 'soldafter'=>$outputlangs->transnoentitiesnoconv("BankBalanceAfter"),
|
|
||||||
'comment'=>$outputlangs->transnoentitiesnoconv("Comment")
|
|
||||||
);
|
|
||||||
$array_selected=array(
|
|
||||||
'bankreceipt'=>'bankreceipt', 'bankaccount'=>'bankaccount',
|
|
||||||
'dateop'=>'dateop','dateval'=>'dateval','type'=>'type',
|
|
||||||
'description'=>'description', 'thirdparty'=>'thirdparty', 'accountelem'=>'accountelem',
|
|
||||||
'debit'=>'debit', 'credit'=>'credit',
|
|
||||||
'soldbefore'=>'soldbefore','soldafter'=>'soldafter',
|
|
||||||
'comment'=>'comment'
|
|
||||||
);
|
|
||||||
$array_export_TypeFields=array(
|
|
||||||
'bankreceipt'=>'Text', 'bankaccount'=>'Text',
|
|
||||||
'dateop'=>'Date','dateval'=>'Date','type'=>'Text',
|
|
||||||
'description'=>'Text', 'thirdparty'=>'Text', 'accountelem'=>'Text',
|
|
||||||
'debit'=>'Number', 'credit'=>'Number',
|
|
||||||
'soldbefore'=>'Number','soldafter'=>'Number',
|
|
||||||
'comment'=>'Text'
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// Build request to find records for a bank account/receipt
|
// Build request to find records for a bank account/receipt
|
||||||
$listofnum = "";
|
$listofnum = "";
|
||||||
if (! empty($num) && $num != "all")
|
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 .= "'";
|
||||||
@ -188,28 +149,27 @@ $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) $sql.= " AND b.num_releve IN (".$listofnum.")";
|
if ($listofnum)
|
||||||
if (!isset($num)) $sql.= " OR b.num_releve is null";
|
$sql .= " AND b.num_releve IN (" . $listofnum . ")";
|
||||||
|
if (! isset($num))
|
||||||
|
$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;
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
|
||||||
$balancebefore = array();
|
$balancebefore = array();
|
||||||
|
|
||||||
$numrows = $db->num_rows($resql);
|
$numrows = $db->num_rows($resql);
|
||||||
|
|
||||||
if ($numrows > 0)
|
if ($numrows > 0) {
|
||||||
{
|
|
||||||
// Open file
|
// Open file
|
||||||
print 'Open file ' . $filename . ' into directory ' . $dirname . "\n";
|
print 'Open file ' . $filename . ' into directory ' . $dirname . "\n";
|
||||||
dol_mkdir($dirname);
|
dol_mkdir($dirname);
|
||||||
$result = $objmodel->open_file($dirname . "/" . $filename, $outputlangs);
|
$result = $objmodel->open_file($dirname . "/" . $filename, $outputlangs);
|
||||||
|
|
||||||
if ($result < 0)
|
if ($result < 0) {
|
||||||
{
|
|
||||||
print 'Failed to create file ' . $filename . ' into dir ' . $dirname . '.' . "\n";
|
print 'Failed to create file ' . $filename . ' into dir ' . $dirname . '.' . "\n";
|
||||||
return - 1;
|
return - 1;
|
||||||
}
|
}
|
||||||
@ -222,8 +182,7 @@ if ($resql)
|
|||||||
}
|
}
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
while ($i < $numrows)
|
while ($i < $numrows) {
|
||||||
{
|
|
||||||
$thirdparty = '';
|
$thirdparty = '';
|
||||||
$accountelem = '';
|
$accountelem = '';
|
||||||
$comment = '';
|
$comment = '';
|
||||||
@ -231,8 +190,7 @@ if ($resql)
|
|||||||
$objp = $db->fetch_object($resql);
|
$objp = $db->fetch_object($resql);
|
||||||
|
|
||||||
// Calculate start balance
|
// Calculate start balance
|
||||||
if (! isset($balancebefore[$objp->num_releve]))
|
if (! isset($balancebefore[$objp->num_releve])) {
|
||||||
{
|
|
||||||
print 'Calculate start balance for receipt ' . $objp->num_releve . "\n";
|
print 'Calculate start balance for receipt ' . $objp->num_releve . "\n";
|
||||||
|
|
||||||
$sql2 = "SELECT sum(b.amount) as amount";
|
$sql2 = "SELECT sum(b.amount) as amount";
|
||||||
@ -240,14 +198,11 @@ if ($resql)
|
|||||||
$sql2 .= " WHERE b.num_releve < '" . $db->escape($objp->num_releve) . "'";
|
$sql2 .= " WHERE b.num_releve < '" . $db->escape($objp->num_releve) . "'";
|
||||||
$sql2 .= " AND b.fk_account = " . $objp->bankid;
|
$sql2 .= " AND b.fk_account = " . $objp->bankid;
|
||||||
$resql2 = $db->query($sql2);
|
$resql2 = $db->query($sql2);
|
||||||
if ($resql2)
|
if ($resql2) {
|
||||||
{
|
|
||||||
$obj2 = $db->fetch_object($resql2);
|
$obj2 = $db->fetch_object($resql2);
|
||||||
$balancebefore[$objp->num_releve] = ($obj2->amount ? $obj2->amount : 0);
|
$balancebefore[$objp->num_releve] = ($obj2->amount ? $obj2->amount : 0);
|
||||||
$db->free($resql2);
|
$db->free($resql2);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
@ -258,8 +213,6 @@ if ($resql)
|
|||||||
$totalbefore = $total;
|
$totalbefore = $total;
|
||||||
$total = $total + $objp->amount;
|
$total = $total + $objp->amount;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Date operation
|
// Date operation
|
||||||
$dateop = $db->jdate($objp->do);
|
$dateop = $db->jdate($objp->do);
|
||||||
|
|
||||||
@ -272,61 +225,53 @@ 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]) $description=$langs->transnoentitiesnoconv($reg[1]);
|
if ($reg[1] && $langs->transnoentitiesnoconv($reg[1]) != $reg[1])
|
||||||
else $description=$objp->label;
|
$description = $langs->transnoentitiesnoconv($reg[1]);
|
||||||
|
else
|
||||||
|
$description = $objp->label;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ajout les liens (societe, company...)
|
* Ajout les liens (societe, company...)
|
||||||
*/
|
*/
|
||||||
$links = $acct->get_url($objp->rowid);
|
$links = $acct->get_url($objp->rowid);
|
||||||
foreach($links as $key=>$val)
|
foreach ($links as $key => $val) {
|
||||||
{
|
if ($links[$key]['type'] == 'payment') {
|
||||||
if ($links[$key]['type']=='payment')
|
|
||||||
{
|
|
||||||
$paymentstatic->fetch($links[$key]['url_id']);
|
$paymentstatic->fetch($links[$key]['url_id']);
|
||||||
$tmparray = $paymentstatic->getBillsArray('');
|
$tmparray = $paymentstatic->getBillsArray('');
|
||||||
if (is_array($tmparray))
|
if (is_array($tmparray)) {
|
||||||
{
|
foreach ($tmparray as $key => $val) {
|
||||||
foreach($tmparray as $key => $val)
|
|
||||||
{
|
|
||||||
$invoicestatic->fetch($val);
|
$invoicestatic->fetch($val);
|
||||||
if ($accountelem) $accountelem.= ', ';
|
if ($accountelem)
|
||||||
|
$accountelem .= ', ';
|
||||||
$accountelem .= $invoicestatic->ref;
|
$accountelem .= $invoicestatic->ref;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} elseif ($links[$key]['type'] == 'payment_supplier') {
|
||||||
elseif ($links[$key]['type']=='payment_supplier')
|
|
||||||
{
|
|
||||||
$paymentsupplierstatic->fetch($links[$key]['url_id']);
|
$paymentsupplierstatic->fetch($links[$key]['url_id']);
|
||||||
$tmparray = $paymentsupplierstatic->getBillsArray('');
|
$tmparray = $paymentsupplierstatic->getBillsArray('');
|
||||||
if (is_array($tmparray))
|
if (is_array($tmparray)) {
|
||||||
{
|
foreach ($tmparray as $key => $val) {
|
||||||
foreach($tmparray as $key => $val)
|
|
||||||
{
|
|
||||||
$invoicesupplierstatic->fetch($val);
|
$invoicesupplierstatic->fetch($val);
|
||||||
if ($accountelem) $accountelem.= ', ';
|
if ($accountelem)
|
||||||
|
$accountelem .= ', ';
|
||||||
$accountelem .= $invoicesupplierstatic->ref;
|
$accountelem .= $invoicesupplierstatic->ref;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} elseif ($links[$key]['type'] == 'payment_sc') {
|
||||||
elseif ($links[$key]['type']=='payment_sc')
|
|
||||||
{
|
|
||||||
$paymentsocialcontributionstatic->fetch($links[$key]['url_id']);
|
$paymentsocialcontributionstatic->fetch($links[$key]['url_id']);
|
||||||
if ($accountelem) $accountelem.= ', ';
|
if ($accountelem)
|
||||||
|
$accountelem .= ', ';
|
||||||
$accountelem .= $langs->transnoentitiesnoconv("SocialContribution") . ' ' . $paymentsocialcontributionstatic->ref;
|
$accountelem .= $langs->transnoentitiesnoconv("SocialContribution") . ' ' . $paymentsocialcontributionstatic->ref;
|
||||||
}
|
} elseif ($links[$key]['type'] == 'payment_vat') {
|
||||||
elseif ($links[$key]['type']=='payment_vat')
|
|
||||||
{
|
|
||||||
$paymentvatstatic->fetch($links[$key]['url_id']);
|
$paymentvatstatic->fetch($links[$key]['url_id']);
|
||||||
if ($accountelem) $accountelem.= ', ';
|
if ($accountelem)
|
||||||
|
$accountelem .= ', ';
|
||||||
$accountelem .= $langs->transnoentitiesnoconv("VATPayments") . ' ' . $paymentvatstatic->ref;
|
$accountelem .= $langs->transnoentitiesnoconv("VATPayments") . ' ' . $paymentvatstatic->ref;
|
||||||
}
|
} elseif ($links[$key]['type'] == 'banktransfert') {
|
||||||
elseif ($links[$key]['type']=='banktransfert')
|
|
||||||
{
|
|
||||||
$comment = $outputlangs->transnoentitiesnoconv("Transfer");
|
$comment = $outputlangs->transnoentitiesnoconv("Transfer");
|
||||||
if ($objp->amount > 0)
|
if ($objp->amount > 0) {
|
||||||
{
|
if ($comment)
|
||||||
if ($comment) $comment.= ' ';
|
$comment .= ' ';
|
||||||
$banklinestatic->fetch($links[$key]['url_id']);
|
$banklinestatic->fetch($links[$key]['url_id']);
|
||||||
$bankstatic->id = $banklinestatic->fk_account;
|
$bankstatic->id = $banklinestatic->fk_account;
|
||||||
$bankstatic->label = $banklinestatic->bank_account_label;
|
$bankstatic->label = $banklinestatic->bank_account_label;
|
||||||
@ -337,10 +282,9 @@ if ($resql)
|
|||||||
$bankstatic->label = $objp->bankref;
|
$bankstatic->label = $objp->bankref;
|
||||||
$comment .= $bankstatic->getNomUrl(1, '');
|
$comment .= $bankstatic->getNomUrl(1, '');
|
||||||
$comment .= ')';
|
$comment .= ')';
|
||||||
}
|
} else {
|
||||||
else
|
if ($comment)
|
||||||
{
|
$comment .= ' ';
|
||||||
if ($comment) $comment.= ' ';
|
|
||||||
$bankstatic->id = $objp->bankid;
|
$bankstatic->id = $objp->bankid;
|
||||||
$bankstatic->label = $objp->bankref;
|
$bankstatic->label = $objp->bankref;
|
||||||
$comment .= ' (' . $langs->transnoentitiesnoconv("from") . ' ';
|
$comment .= ' (' . $langs->transnoentitiesnoconv("from") . ' ';
|
||||||
@ -352,46 +296,43 @@ if ($resql)
|
|||||||
$comment .= $bankstatic->getNomUrl(1, 'transactions');
|
$comment .= $bankstatic->getNomUrl(1, 'transactions');
|
||||||
$comment .= ')';
|
$comment .= ')';
|
||||||
}
|
}
|
||||||
}
|
} elseif ($links[$key]['type'] == 'company') {
|
||||||
elseif ($links[$key]['type']=='company')
|
if ($thirdparty)
|
||||||
{
|
$thirdparty .= ', ';
|
||||||
if ($thirdparty) $thirdparty.= ', ';
|
|
||||||
$thirdparty .= dol_trunc($links[$key]['label'], 24);
|
$thirdparty .= dol_trunc($links[$key]['label'], 24);
|
||||||
$newline = 0;
|
$newline = 0;
|
||||||
}
|
} elseif ($links[$key]['type'] == 'member') {
|
||||||
elseif ($links[$key]['type']=='member')
|
if ($thirdparty)
|
||||||
{
|
$accountelem .= ', ';
|
||||||
if ($thirdparty) $accountelem.= ', ';
|
|
||||||
$thirdparty .= $links[$key]['label'];
|
$thirdparty .= $links[$key]['label'];
|
||||||
$newline = 0;
|
$newline = 0;
|
||||||
}
|
}
|
||||||
/*elseif ($links[$key]['type']=='sc')
|
/*
|
||||||
{
|
* elseif ($links[$key]['type']=='sc')
|
||||||
if ($accountelem) $accountelem.= ', ';
|
* {
|
||||||
//$accountelem.= '<a href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$links[$key]['url_id'].'">';
|
* if ($accountelem) $accountelem.= ', ';
|
||||||
//$accountelem.= img_object($langs->transnoentitiesnoconv('ShowBill'),'bill').' ';
|
* //$accountelem.= '<a href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$links[$key]['url_id'].'">';
|
||||||
$accountelem.= $langs->transnoentitiesnoconv("SocialContribution");
|
* //$accountelem.= img_object($langs->transnoentitiesnoconv('ShowBill'),'bill').' ';
|
||||||
//$accountelem.= '</a>';
|
* $accountelem.= $langs->transnoentitiesnoconv("SocialContribution");
|
||||||
$newline=0;
|
* //$accountelem.= '</a>';
|
||||||
}
|
* $newline=0;
|
||||||
else
|
* }
|
||||||
{
|
* else
|
||||||
if ($accountelem) $accountelem.= ', ';
|
* {
|
||||||
//$accountelem.= '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">';
|
* if ($accountelem) $accountelem.= ', ';
|
||||||
$accountelem.= $links[$key]['label'];
|
* //$accountelem.= '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">';
|
||||||
//$accountelem.= '</a>';
|
* $accountelem.= $links[$key]['label'];
|
||||||
$newline=0;
|
* //$accountelem.= '</a>';
|
||||||
}*/
|
* $newline=0;
|
||||||
|
* }
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
$debit = $credit = '';
|
$debit = $credit = '';
|
||||||
if ($objp->amount < 0)
|
if ($objp->amount < 0) {
|
||||||
{
|
|
||||||
$totald = $totald + abs($objp->amount);
|
$totald = $totald + abs($objp->amount);
|
||||||
$debit = price2num($objp->amount * - 1);
|
$debit = price2num($objp->amount * - 1);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$totalc = $totalc + abs($objp->amount);
|
$totalc = $totalc + abs($objp->amount);
|
||||||
$credit = price2num($objp->amount);
|
$credit = price2num($objp->amount);
|
||||||
}
|
}
|
||||||
@ -417,8 +358,7 @@ if ($resql)
|
|||||||
$objmodel->write_record($array_selected, $rec, $outputlangs, $array_export_TypeFields);
|
$objmodel->write_record($array_selected, $rec, $outputlangs, $array_export_TypeFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($numrows > 0)
|
if ($numrows > 0) {
|
||||||
{
|
|
||||||
print "Found " . $numrows . " records for receipt " . $num . "\n";
|
print "Found " . $numrows . " records for receipt " . $num . "\n";
|
||||||
|
|
||||||
// Genere en-tete
|
// Genere en-tete
|
||||||
@ -430,16 +370,12 @@ if ($resql)
|
|||||||
print 'File ' . $filename . ' was generated into dir ' . $dirname . '.' . "\n";
|
print 'File ' . $filename . ' was generated into dir ' . $dirname . '.' . "\n";
|
||||||
|
|
||||||
$ret = 0;
|
$ret = 0;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
print "No records found for receipt " . $num . "\n";
|
print "No records found for receipt " . $num . "\n";
|
||||||
|
|
||||||
$ret = 0;
|
$ret = 0;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
$ret = - 1;
|
$ret = - 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,10 +23,9 @@
|
|||||||
* \ingroup company
|
* \ingroup company
|
||||||
* \brief Script file to export contacts into an Excel file
|
* \brief Script file to export contacts into an Excel file
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test if batch mode
|
// Test if batch mode
|
||||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||||
@ -40,7 +39,6 @@ if (! isset($argv[1]) || ! $argv[1]) {
|
|||||||
}
|
}
|
||||||
$now = $argv[1];
|
$now = $argv[1];
|
||||||
|
|
||||||
|
|
||||||
require_once $path . "../../htdocs/master.inc.php";
|
require_once $path . "../../htdocs/master.inc.php";
|
||||||
// require_once PHP_WRITEEXCEL_PATH."/class.writeexcel_workbook.inc.php";
|
// require_once PHP_WRITEEXCEL_PATH."/class.writeexcel_workbook.inc.php";
|
||||||
// require_once PHP_WRITEEXCEL_PATH."/class.writeexcel_worksheet.inc.php";
|
// require_once PHP_WRITEEXCEL_PATH."/class.writeexcel_worksheet.inc.php";
|
||||||
@ -53,7 +51,6 @@ require_once PHPEXCEL_PATH."/PHPExcel/Writer/Excel5.php";
|
|||||||
$version = DOL_VERSION;
|
$version = DOL_VERSION;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -72,7 +69,6 @@ $objPHPExcel->getProperties()->setTitle("Test Document");
|
|||||||
$objPHPExcel->getProperties()->setSubject("Test Document");
|
$objPHPExcel->getProperties()->setSubject("Test Document");
|
||||||
$objPHPExcel->getProperties()->setDescription("Test document, generated using PHP classes.");
|
$objPHPExcel->getProperties()->setDescription("Test document, generated using PHP classes.");
|
||||||
|
|
||||||
|
|
||||||
// $page = &$objPHPExcel->addworksheet('Export Dolibarr');
|
// $page = &$objPHPExcel->addworksheet('Export Dolibarr');
|
||||||
$objPHPExcel->setActiveSheetIndex(0);
|
$objPHPExcel->setActiveSheetIndex(0);
|
||||||
$objPHPExcel->getActiveSheet()->setTitle('Contacts');
|
$objPHPExcel->getActiveSheet()->setTitle('Contacts');
|
||||||
@ -84,8 +80,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c";
|
|||||||
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s on s.rowid = c.fk_soc";
|
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s on s.rowid = c.fk_soc";
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
|
|
||||||
print "Lines " . $num . "\n";
|
print "Lines " . $num . "\n";
|
||||||
@ -98,8 +93,7 @@ if ($resql)
|
|||||||
$objPHPExcel->getActiveSheet()->SetCellValue('C1', $langs->trans("Email"));
|
$objPHPExcel->getActiveSheet()->SetCellValue('C1', $langs->trans("Email"));
|
||||||
$objPHPExcel->getActiveSheet()->SetCellValue('D1', $langs->trans("ThirdPart"));
|
$objPHPExcel->getActiveSheet()->SetCellValue('D1', $langs->trans("ThirdPart"));
|
||||||
|
|
||||||
while ($i < $num)
|
while ($i < $num) {
|
||||||
{
|
|
||||||
$obj = $db->fetch_object($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
|
|
||||||
$objPHPExcel->getActiveSheet()->SetCellValue('A' . ($i + 2), $obj->firstname);
|
$objPHPExcel->getActiveSheet()->SetCellValue('A' . ($i + 2), $obj->firstname);
|
||||||
@ -112,7 +106,6 @@ if ($resql)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
|
// $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
|
||||||
$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
|
$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
|
||||||
$objWriter->save($fname);
|
$objWriter->save($fname);
|
||||||
|
|||||||
@ -23,10 +23,9 @@
|
|||||||
* \ingroup ldap company
|
* \ingroup ldap company
|
||||||
* \brief Script to update all contacts from Dolibarr into a LDAP database
|
* \brief Script to update all contacts from Dolibarr into a LDAP database
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test if batch mode
|
// Test if batch mode
|
||||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||||
@ -34,7 +33,6 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
|
|||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
require_once $path . "../../htdocs/master.inc.php";
|
require_once $path . "../../htdocs/master.inc.php";
|
||||||
require_once DOL_DOCUMENT_ROOT . "/contact/class/contact.class.php";
|
require_once DOL_DOCUMENT_ROOT . "/contact/class/contact.class.php";
|
||||||
require_once DOL_DOCUMENT_ROOT . "/user/class/user.class.php";
|
require_once DOL_DOCUMENT_ROOT . "/user/class/user.class.php";
|
||||||
@ -45,7 +43,6 @@ $version=DOL_VERSION;
|
|||||||
$error = 0;
|
$error = 0;
|
||||||
$confirmed = 0;
|
$confirmed = 0;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -59,9 +56,9 @@ if (! isset($argv[1]) || ! $argv[1]) {
|
|||||||
exit(- 1);
|
exit(- 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];
|
||||||
@ -85,8 +82,7 @@ print "pass=".preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)."\n";
|
|||||||
print "DN target=" . $conf->global->LDAP_CONTACT_DN . "\n";
|
print "DN target=" . $conf->global->LDAP_CONTACT_DN . "\n";
|
||||||
print "\n";
|
print "\n";
|
||||||
|
|
||||||
if (! $confirmed)
|
if (! $confirmed) {
|
||||||
{
|
|
||||||
print "Press a key to confirm...\n";
|
print "Press a key to confirm...\n";
|
||||||
$input = trim(fgets(STDIN));
|
$input = trim(fgets(STDIN));
|
||||||
print "Warning, this operation may result in data loss if it failed.\n";
|
print "Warning, this operation may result in data loss if it failed.\n";
|
||||||
@ -96,27 +92,25 @@ if (! $confirmed)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (! $conf->global->LDAP_CONTACT_ACTIVE)
|
* if (! $conf->global->LDAP_CONTACT_ACTIVE)
|
||||||
{
|
* {
|
||||||
print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
* print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
||||||
exit(-1);
|
* exit(-1);
|
||||||
}
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sql = "SELECT rowid";
|
$sql = "SELECT rowid";
|
||||||
$sql .= " FROM " . MAIN_DB_PREFIX . "socpeople";
|
$sql .= " FROM " . MAIN_DB_PREFIX . "socpeople";
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
$ldap = new Ldap();
|
$ldap = new Ldap();
|
||||||
$ldap->connect_bind();
|
$ldap->connect_bind();
|
||||||
|
|
||||||
while ($i < $num)
|
while ($i < $num) {
|
||||||
{
|
|
||||||
$ldap->error = "";
|
$ldap->error = "";
|
||||||
|
|
||||||
$obj = $db->fetch_object($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
@ -137,12 +131,9 @@ if ($resql)
|
|||||||
|
|
||||||
$result = $ldap->add($dn, $info, $user); // Wil fail if already exists
|
$result = $ldap->add($dn, $info, $user); // Wil fail if already exists
|
||||||
$result = $ldap->update($dn, $info, $user, $olddn);
|
$result = $ldap->update($dn, $info, $user, $olddn);
|
||||||
if ($result > 0)
|
if ($result > 0) {
|
||||||
{
|
|
||||||
print " - " . $langs->trans("OK");
|
print " - " . $langs->trans("OK");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$error ++;
|
$error ++;
|
||||||
print " - " . $langs->trans("KO") . ' - ' . $ldap->error;
|
print " - " . $langs->trans("KO") . ' - ' . $ldap->error;
|
||||||
}
|
}
|
||||||
@ -153,9 +144,7 @@ if ($resql)
|
|||||||
|
|
||||||
$ldap->unbind();
|
$ldap->unbind();
|
||||||
$ldap->close();
|
$ldap->close();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,10 +24,9 @@
|
|||||||
* \ingroup facture
|
* \ingroup facture
|
||||||
* \brief Script to send a mail to customers with services to expire
|
* \brief Script to send a mail to customers with services to expire
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test si mode batch
|
// Test si mode batch
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
@ -36,8 +35,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
|
|||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1], array('test','confirm')) || ! in_array($argv[2], array('thirdparties','contacts')))
|
if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1], array('test','confirm')) || ! in_array($argv[2], array('thirdparties','contacts'))) {
|
||||||
{
|
|
||||||
print "Usage: $script_file (test|confirm) (thirdparties|contacts) [delay] [after]\n";
|
print "Usage: $script_file (test|confirm) (thirdparties|contacts) [delay] [after]\n";
|
||||||
print "\n";
|
print "\n";
|
||||||
print "Send an email to customers to remind all contracts services to expire or expired.\n";
|
print "Send an email to customers to remind all contracts services to expire or expired.\n";
|
||||||
@ -49,7 +47,6 @@ if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1], array('test','confir
|
|||||||
$mode = $argv[1];
|
$mode = $argv[1];
|
||||||
$targettype = $argv[2];
|
$targettype = $argv[2];
|
||||||
|
|
||||||
|
|
||||||
require $path . "../../htdocs/master.inc.php";
|
require $path . "../../htdocs/master.inc.php";
|
||||||
require_once DOL_DOCUMENT_ROOT . "/core/class/CMailFile.class.php";
|
require_once DOL_DOCUMENT_ROOT . "/core/class/CMailFile.class.php";
|
||||||
|
|
||||||
@ -59,7 +56,6 @@ $langs->loadLangs(array('main', 'contracts'));
|
|||||||
$version = DOL_VERSION;
|
$version = DOL_VERSION;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -75,66 +71,74 @@ $duration_value2=isset($argv[4])?$argv[4]:'none';
|
|||||||
$error = 0;
|
$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";
|
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') $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
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 = "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') $sql.= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail";
|
if ($targettype == 'contacts')
|
||||||
|
$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') $sql.= ", ".MAIN_DB_PREFIX."socpeople as sp";
|
if ($targettype == 'contacts')
|
||||||
|
$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)) $sql.= " AND cd.date_fin_validite >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'";
|
if (is_numeric($duration_value2))
|
||||||
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_value2, "d")) . "'";
|
||||||
if ($targettype == 'contacts') $sql.= " AND s.rowid = sp.fk_soc";
|
if (is_numeric($duration_value))
|
||||||
|
$sql .= " AND cd.date_fin_validite < '" . $db->idate(dol_time_plus_duree($now, $duration_value, "d")) . "'";
|
||||||
|
if ($targettype == 'contacts')
|
||||||
|
$sql .= " AND s.rowid = sp.fk_soc";
|
||||||
$sql .= " ORDER BY";
|
$sql .= " ORDER BY";
|
||||||
if ($targettype == 'contacts') $sql.= " sp.email, sp.rowid,";
|
if ($targettype == 'contacts')
|
||||||
|
$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;
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$oldemail = 'none'; $oldsid = 0; $oldcid = 0; $oldlang='';
|
$oldemail = 'none';
|
||||||
$total = 0; $foundtoprocess = 0;
|
$oldsid = 0;
|
||||||
|
$oldcid = 0;
|
||||||
|
$oldlang = '';
|
||||||
|
$total = 0;
|
||||||
|
$foundtoprocess = 0;
|
||||||
$trackthirdpartiessent = array();
|
$trackthirdpartiessent = array();
|
||||||
|
|
||||||
print "We found " . $num . " couples (services to expire-" . $targettype . ") qualified\n";
|
print "We found " . $num . " couples (services to expire-" . $targettype . ") qualified\n";
|
||||||
dol_syslog("We found " . $num . " couples (services to expire-" . $targettype . ") qualified");
|
dol_syslog("We found " . $num . " couples (services to expire-" . $targettype . ") qualified");
|
||||||
$message = '';
|
$message = '';
|
||||||
|
|
||||||
if ($num)
|
if ($num) {
|
||||||
{
|
while ($i < $num) {
|
||||||
while ($i < $num)
|
|
||||||
{
|
|
||||||
$obj = $db->fetch_object($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
|
|
||||||
$newemail = empty($obj->cemail) ? $obj->email : $obj->cemail;
|
$newemail = empty($obj->cemail) ? $obj->email : $obj->cemail;
|
||||||
|
|
||||||
// Check if this record is a break after previous one
|
// Check if this record is a break after previous one
|
||||||
$startbreak = false;
|
$startbreak = false;
|
||||||
if ($newemail <> $oldemail || $oldemail == 'none') $startbreak=true;
|
if ($newemail != $oldemail || $oldemail == 'none')
|
||||||
if ($obj->sid && $obj->sid <> $oldsid) $startbreak=true;
|
$startbreak = true;
|
||||||
if ($obj->cid && $obj->cid <> $oldcid) $startbreak=true;
|
if ($obj->sid && $obj->sid != $oldsid)
|
||||||
|
$startbreak = true;
|
||||||
|
if ($obj->cid && $obj->cid != $oldcid)
|
||||||
|
$startbreak = true;
|
||||||
|
|
||||||
if ($startbreak)
|
if ($startbreak) {
|
||||||
{
|
|
||||||
// Break onto sales representative (new email or cid)
|
// Break onto sales representative (new email or cid)
|
||||||
if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))
|
if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid . '|' . $oldemail])) {
|
||||||
{
|
|
||||||
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 {
|
||||||
|
if ($oldemail != 'none') {
|
||||||
|
if (empty($trackthirdpartiessent[$oldsid . '|' . $oldemail]))
|
||||||
|
print "- No email sent for '" . $oldtarget . "', total: " . $total . "\n";
|
||||||
else
|
else
|
||||||
{
|
print "- No email sent for '" . $oldtarget . "', total: " . $total . " (already sent to " . $trackthirdpartiessent[$oldsid . '|' . $oldemail] . ")\n";
|
||||||
if ($oldemail != 'none')
|
|
||||||
{
|
|
||||||
if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) 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";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$oldemail = $newemail;
|
$oldemail = $newemail;
|
||||||
@ -156,15 +160,16 @@ if ($resql)
|
|||||||
// Load translation files required by the page
|
// Load translation files required by the page
|
||||||
$outputlangs->loadLangs(array("main","contracts","bills","products"));
|
$outputlangs->loadLangs(array("main","contracts","bills","products"));
|
||||||
|
|
||||||
if (dol_strlen($newemail))
|
if (dol_strlen($newemail)) {
|
||||||
{
|
|
||||||
$message .= $outputlangs->trans("Contract") . " " . $obj->ref . ": " . $outputlangs->trans("Service") . " " . dol_concatdesc($obj->plabel, $obj->description) . " (" . price($obj->total_ttc, 0, $outputlangs, 0, 0, - 1, $conf->currency) . "), " . $outputlangs->trans("DateEndPlannedShort") . " " . dol_print_date($db->jdate($obj->date_fin_validite), 'day') . "\n\n";
|
$message .= $outputlangs->trans("Contract") . " " . $obj->ref . ": " . $outputlangs->trans("Service") . " " . dol_concatdesc($obj->plabel, $obj->description) . " (" . price($obj->total_ttc, 0, $outputlangs, 0, 0, - 1, $conf->currency) . "), " . $outputlangs->trans("DateEndPlannedShort") . " " . dol_print_date($db->jdate($obj->date_fin_validite), 'day') . "\n\n";
|
||||||
dol_syslog("email_expire_services_to_customers.php: " . $newemail . " " . $message);
|
dol_syslog("email_expire_services_to_customers.php: " . $newemail . " " . $message);
|
||||||
$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 . ", " . ($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 . ", " . ($obj->cid ? "contact id " . $obj->cid . " " . $obj->clastname . " " . $obj->cfirstname . ", " : "") . "email " . $newemail . ", lang " . $outputlangs->defaultlang . ": ";
|
||||||
if (dol_strlen($newemail)) print "qualified.";
|
if (dol_strlen($newemail))
|
||||||
else print "disqualified (no email).";
|
print "qualified.";
|
||||||
|
else
|
||||||
|
print "disqualified (no email).";
|
||||||
print "\n";
|
print "\n";
|
||||||
|
|
||||||
unset($outputlangs);
|
unset($outputlangs);
|
||||||
@ -175,68 +180,69 @@ 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 {
|
||||||
|
if ($oldemail != 'none') {
|
||||||
|
if (empty($trackthirdpartiessent[$oldsid . '|' . $oldemail]))
|
||||||
|
print "- No email sent for '" . $oldtarget . "', total: " . $total . "\n";
|
||||||
else
|
else
|
||||||
{
|
print "- No email sent for '" . $oldtarget . "', total: " . $total . " (already sent to " . $trackthirdpartiessent[$oldsid . '|' . $oldemail] . ")\n";
|
||||||
if ($oldemail != 'none')
|
|
||||||
{
|
|
||||||
if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) 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 {
|
||||||
else
|
|
||||||
{
|
|
||||||
print "No services to expire found\n";
|
print "No services to expire found\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
dol_syslog("email_expire_services_to_customers.php: Error");
|
dol_syslog("email_expire_services_to_customers.php: Error");
|
||||||
|
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send email
|
* Send email
|
||||||
*
|
*
|
||||||
* @param string $mode Mode (test | confirm)
|
* @param string $mode
|
||||||
* @param string $oldemail Target email
|
* Mode (test | confirm)
|
||||||
* @param string $message Message to send
|
* @param string $oldemail
|
||||||
* @param string $total Total amount of unpayed invoices
|
* Target email
|
||||||
* @param string $userlang Code lang to use for email output.
|
* @param string $message
|
||||||
* @param string $oldtarget Target name
|
* Message to send
|
||||||
* @param int $duration_value duration value
|
* @param string $total
|
||||||
|
* Total amount of unpayed invoices
|
||||||
|
* @param string $userlang
|
||||||
|
* Code lang to use for email output.
|
||||||
|
* @param string $oldtarget
|
||||||
|
* Target name
|
||||||
|
* @param int $duration_value
|
||||||
|
* duration value
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget, $duration_value)
|
function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget, $duration_value)
|
||||||
{
|
{
|
||||||
global $conf, $langs;
|
global $conf, $langs;
|
||||||
|
|
||||||
if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail=getenv('DOL_FORCE_EMAIL_TO');
|
if (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);
|
||||||
$newlangs->load("main");
|
$newlangs->load("main");
|
||||||
$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("ListOfServicesToExpireWithDurationNeg", $duration_value);
|
||||||
|
} else
|
||||||
$title = $newlangs->transnoentities("ListOfServicesToExpire");
|
$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);
|
||||||
@ -249,55 +255,38 @@ 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)) $usehtml+=1;
|
if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER))
|
||||||
if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) $usehtml+=1;
|
$usehtml += 1;
|
||||||
|
if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER))
|
||||||
|
$usehtml += 1;
|
||||||
|
|
||||||
$allmessage = '';
|
$allmessage = '';
|
||||||
if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER))
|
if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) {
|
||||||
{
|
|
||||||
$allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER;
|
$allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$allmessage .= "Dear customer" . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
|
$allmessage .= "Dear customer" . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
|
||||||
$allmessage .= "Please, find a summary of the services contracted by you that are about to expire." . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
|
$allmessage .= "Please, find a summary of the services contracted by you that are about to expire." . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
|
||||||
}
|
}
|
||||||
$allmessage .= $message . ($usehtml ? "<br>\n" : "\n");
|
$allmessage .= $message . ($usehtml ? "<br>\n" : "\n");
|
||||||
// $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)) $usehtml+=1;
|
if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER))
|
||||||
|
$usehtml += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$mail = new CMailFile(
|
$mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);
|
||||||
$subject,
|
|
||||||
$sendto,
|
|
||||||
$from,
|
|
||||||
$allmessage,
|
|
||||||
array(),
|
|
||||||
array(),
|
|
||||||
array(),
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
0,
|
|
||||||
$msgishtml
|
|
||||||
);
|
|
||||||
|
|
||||||
$mail->errors_to = $errorsto;
|
$mail->errors_to = $errorsto;
|
||||||
|
|
||||||
// Send or not email
|
// Send or not email
|
||||||
if ($mode == 'confirm')
|
if ($mode == 'confirm') {
|
||||||
{
|
|
||||||
$result = $mail->sendfile();
|
$result = $mail->sendfile();
|
||||||
if (! $result)
|
if (! $result) {
|
||||||
{
|
|
||||||
print "Error sending email " . $mail->error . "\n";
|
print "Error sending email " . $mail->error . "\n";
|
||||||
dol_syslog("Error sending email " . $mail->error . "\n");
|
dol_syslog("Error sending email " . $mail->error . "\n");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
print "No email sent (test mode)\n";
|
print "No email sent (test mode)\n";
|
||||||
dol_syslog("No email sent (test mode)");
|
dol_syslog("No email sent (test mode)");
|
||||||
$mail->dump_mail();
|
$mail->dump_mail();
|
||||||
@ -305,12 +294,9 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget, $
|
|||||||
}
|
}
|
||||||
|
|
||||||
unset($newlangs);
|
unset($newlangs);
|
||||||
if ($result)
|
if ($result) {
|
||||||
{
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return - 1;
|
return - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,10 +24,9 @@
|
|||||||
* \ingroup contracts
|
* \ingroup contracts
|
||||||
* \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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test si mode batch
|
// Test si mode batch
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
@ -36,8 +35,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
|
|||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1], array('test','confirm')))
|
if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1], array('test','confirm'))) {
|
||||||
{
|
|
||||||
print "Usage: $script_file (test|confirm) [delay]\n";
|
print "Usage: $script_file (test|confirm) [delay]\n";
|
||||||
print "\n";
|
print "\n";
|
||||||
print "Send an email to remind all contracts services to expire, to users that are sale representative for.\n";
|
print "Send an email to remind all contracts services to expire, to users that are sale representative for.\n";
|
||||||
@ -47,7 +45,6 @@ if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1], array('test','confir
|
|||||||
}
|
}
|
||||||
$mode = $argv[1];
|
$mode = $argv[1];
|
||||||
|
|
||||||
|
|
||||||
require $path . "../../htdocs/master.inc.php";
|
require $path . "../../htdocs/master.inc.php";
|
||||||
require_once DOL_DOCUMENT_ROOT . "/core/class/CMailFile.class.php";
|
require_once DOL_DOCUMENT_ROOT . "/core/class/CMailFile.class.php";
|
||||||
|
|
||||||
@ -57,7 +54,6 @@ $langs->loadLangs(array('main', 'contracts'));
|
|||||||
$version = DOL_VERSION;
|
$version = DOL_VERSION;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -71,45 +67,44 @@ $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";
|
print $script_file . " launched with mode " . $mode . " default lang=" . $langs->defaultlang . (is_numeric($duration_value) ? " delay=" . $duration_value : "") . "\n";
|
||||||
|
|
||||||
if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
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 = "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";
|
$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)) $sql .= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
|
if (is_numeric($duration_value))
|
||||||
|
$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
|
||||||
|
|
||||||
// print $sql;
|
// print $sql;
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$oldemail = 'none'; $olduid = 0; $oldlang='';
|
$oldemail = 'none';
|
||||||
$total = 0; $foundtoprocess = 0;
|
$olduid = 0;
|
||||||
|
$oldlang = '';
|
||||||
|
$total = 0;
|
||||||
|
$foundtoprocess = 0;
|
||||||
print "We found " . $num . " couples (services to expire - sale representative) qualified\n";
|
print "We found " . $num . " couples (services to expire - sale representative) qualified\n";
|
||||||
dol_syslog("We found " . $num . " couples (services to expire - sale representative) qualified");
|
dol_syslog("We found " . $num . " couples (services to expire - sale representative) qualified");
|
||||||
$message = '';
|
$message = '';
|
||||||
|
|
||||||
if ($num)
|
if ($num) {
|
||||||
{
|
while ($i < $num) {
|
||||||
while ($i < $num)
|
|
||||||
{
|
|
||||||
$obj = $db->fetch_object($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
|
|
||||||
if (($obj->email <> $oldemail || $obj->uid <> $olduid) || $oldemail == 'none')
|
if (($obj->email != $oldemail || $obj->uid != $olduid) || $oldemail == 'none') {
|
||||||
{
|
|
||||||
// Break onto sales representative (new email or uid)
|
// Break onto sales representative (new email or uid)
|
||||||
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')
|
||||||
{
|
print "- No email sent for " . $oldsalerepresentative . ", total: " . $total . "\n";
|
||||||
if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
|
|
||||||
}
|
}
|
||||||
$oldemail = $obj->email;
|
$oldemail = $obj->email;
|
||||||
$olduid = $obj->uid;
|
$olduid = $obj->uid;
|
||||||
@ -119,7 +114,8 @@ 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)) print "Warning: Sale representative ".$salerepresentative." has no email. Notice disabled.\n";
|
if (empty($obj->email))
|
||||||
|
print "Warning: Sale representative " . $salerepresentative . " has no email. Notice disabled.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define line content
|
// Define line content
|
||||||
@ -129,15 +125,16 @@ if ($resql)
|
|||||||
// Load translation files required by the page
|
// Load translation files required by the page
|
||||||
$outputlangs->loadLangs(array("main","contracts","bills","products"));
|
$outputlangs->loadLangs(array("main","contracts","bills","products"));
|
||||||
|
|
||||||
if (dol_strlen($obj->email))
|
if (dol_strlen($obj->email)) {
|
||||||
{
|
|
||||||
$message .= $outputlangs->trans("Contract") . " " . $obj->ref . ": " . $langs->trans("Service") . " " . dol_concatdesc($obj->plabel, $obj->description) . " (" . price($obj->total_ttc, 0, $outputlangs, 0, 0, - 1, $conf->currency) . ") " . $obj->name . ", " . $outputlangs->trans("DateEndPlannedShort") . " " . dol_print_date($db->jdate($obj->date_fin_validite), 'day') . "\n\n";
|
$message .= $outputlangs->trans("Contract") . " " . $obj->ref . ": " . $langs->trans("Service") . " " . dol_concatdesc($obj->plabel, $obj->description) . " (" . price($obj->total_ttc, 0, $outputlangs, 0, 0, - 1, $conf->currency) . ") " . $obj->name . ", " . $outputlangs->trans("DateEndPlannedShort") . " " . dol_print_date($db->jdate($obj->date_fin_validite), 'day') . "\n\n";
|
||||||
dol_syslog("email_expire_services_to_representatives.php: " . $obj->email);
|
dol_syslog("email_expire_services_to_representatives.php: " . $obj->email);
|
||||||
$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)) print "qualified.";
|
if (dol_strlen($obj->email))
|
||||||
else print "disqualified (no email).";
|
print "qualified.";
|
||||||
|
else
|
||||||
|
print "disqualified (no email).";
|
||||||
print "\n";
|
print "\n";
|
||||||
|
|
||||||
unset($outputlangs);
|
unset($outputlangs);
|
||||||
@ -147,63 +144,64 @@ 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')
|
||||||
{
|
print "- No email sent for " . $oldsalerepresentative . ", total: " . $total . "\n";
|
||||||
if ($oldemail != 'none') 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";
|
||||||
}
|
}
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
dol_syslog("email_expire_services_to_representatives.php: Error");
|
dol_syslog("email_expire_services_to_representatives.php: Error");
|
||||||
|
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send email
|
* Send email
|
||||||
*
|
*
|
||||||
* @param string $mode Mode (test | confirm)
|
* @param string $mode
|
||||||
* @param string $oldemail Old email
|
* Mode (test | confirm)
|
||||||
* @param string $message Message to send
|
* @param string $oldemail
|
||||||
* @param string $total Total amount of unpayed invoices
|
* Old email
|
||||||
* @param string $userlang Code lang to use for email output.
|
* @param string $message
|
||||||
* @param string $oldsalerepresentative Old sale representative
|
* Message to send
|
||||||
* @param int $duration_value duration value
|
* @param string $total
|
||||||
|
* Total amount of unpayed invoices
|
||||||
|
* @param string $userlang
|
||||||
|
* Code lang to use for email output.
|
||||||
|
* @param string $oldsalerepresentative
|
||||||
|
* Old sale representative
|
||||||
|
* @param int $duration_value
|
||||||
|
* duration value
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldsalerepresentative, $duration_value)
|
function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldsalerepresentative, $duration_value)
|
||||||
{
|
{
|
||||||
global $conf, $langs;
|
global $conf, $langs;
|
||||||
|
|
||||||
if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail=getenv('DOL_FORCE_EMAIL_TO');
|
if (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);
|
||||||
$newlangs->load("main");
|
$newlangs->load("main");
|
||||||
$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("ListOfServicesToExpireWithDurationNeg", $duration_value);
|
||||||
|
} else
|
||||||
$title = $newlangs->transnoentities("ListOfServicesToExpire");
|
$title = $newlangs->transnoentities("ListOfServicesToExpire");
|
||||||
|
|
||||||
$subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT) ? $title : $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT);
|
$subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT) ? $title : $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT);
|
||||||
@ -216,67 +214,47 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldsalerepre
|
|||||||
dol_syslog("email_expire_services_to_representatives.php: send mail to " . $oldemail);
|
dol_syslog("email_expire_services_to_representatives.php: send mail to " . $oldemail);
|
||||||
|
|
||||||
$usehtml = 0;
|
$usehtml = 0;
|
||||||
if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
|
if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER))
|
||||||
if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER)) $usehtml+=1;
|
$usehtml += 1;
|
||||||
|
if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER))
|
||||||
|
$usehtml += 1;
|
||||||
|
|
||||||
$allmessage = '';
|
$allmessage = '';
|
||||||
if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER))
|
if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER)) {
|
||||||
{
|
|
||||||
$allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER;
|
$allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$allmessage .= $title . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
|
$allmessage .= $title . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
|
||||||
$allmessage .= $newlangs->transnoentities("NoteListOfYourExpiredServices") . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
|
$allmessage .= $newlangs->transnoentities("NoteListOfYourExpiredServices") . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
|
||||||
}
|
}
|
||||||
$allmessage .= $message . ($usehtml ? "<br>\n" : "\n");
|
$allmessage .= $message . ($usehtml ? "<br>\n" : "\n");
|
||||||
$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)) $usehtml+=1;
|
if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER))
|
||||||
|
$usehtml += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$mail = new CMailFile(
|
$mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);
|
||||||
$subject,
|
|
||||||
$sendto,
|
|
||||||
$from,
|
|
||||||
$allmessage,
|
|
||||||
array(),
|
|
||||||
array(),
|
|
||||||
array(),
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
0,
|
|
||||||
$msgishtml
|
|
||||||
);
|
|
||||||
|
|
||||||
$mail->errors_to = $errorsto;
|
$mail->errors_to = $errorsto;
|
||||||
|
|
||||||
// Send or not email
|
// Send or not email
|
||||||
if ($mode == 'confirm')
|
if ($mode == 'confirm') {
|
||||||
{
|
|
||||||
$result = $mail->sendfile();
|
$result = $mail->sendfile();
|
||||||
if (! $result)
|
if (! $result) {
|
||||||
{
|
|
||||||
print "Error sending email " . $mail->error . "\n";
|
print "Error sending email " . $mail->error . "\n";
|
||||||
dol_syslog("Error sending email " . $mail->error . "\n");
|
dol_syslog("Error sending email " . $mail->error . "\n");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
print "No email sent (test mode)\n";
|
print "No email sent (test mode)\n";
|
||||||
dol_syslog("No email sent (test mode)");
|
dol_syslog("No email sent (test mode)");
|
||||||
$mail->dump_mail();
|
$mail->dump_mail();
|
||||||
$result = 1;
|
$result = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($result)
|
if ($result) {
|
||||||
{
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return - 1;
|
return - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env php
|
#!/usr/bin/env php
|
||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
|
/*
|
||||||
|
* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
|
||||||
* Copyright (C) 2013 Florian Henry <forian.henry@open-concept.pro
|
* Copyright (C) 2013 Florian Henry <forian.henry@open-concept.pro
|
||||||
* Copyright (C) 2013-2015 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2013-2015 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
@ -23,17 +24,21 @@
|
|||||||
* \ingroup cron
|
* \ingroup cron
|
||||||
* \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('NOREQUIREMENU'))
|
||||||
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
|
define('NOREQUIREMENU', '1');
|
||||||
if (! defined('NOLOGIN')) define('NOLOGIN', '1');
|
if (! defined('NOREQUIREHTML'))
|
||||||
|
define('NOREQUIREHTML', '1');
|
||||||
|
if (! defined('NOREQUIREAJAX'))
|
||||||
|
define('NOREQUIREAJAX', '1');
|
||||||
|
if (! defined('NOLOGIN'))
|
||||||
|
define('NOLOGIN', '1');
|
||||||
// if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
|
// if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
|
||||||
|
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Error if Web mode
|
// Error if Web mode
|
||||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||||
@ -59,13 +64,10 @@ if (! isset($argv[2]) || ! $argv[2]) {
|
|||||||
|
|
||||||
$userlogin = $argv[2];
|
$userlogin = $argv[2];
|
||||||
|
|
||||||
|
|
||||||
// Global variables
|
// Global variables
|
||||||
$version = DOL_VERSION;
|
$version = DOL_VERSION;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -79,56 +81,46 @@ $now=dol_now();
|
|||||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " ***** userlogin=" . $userlogin . " ***** " . dol_print_date($now, 'dayhourrfc') . " *****\n";
|
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " ***** userlogin=" . $userlogin . " ***** " . dol_print_date($now, 'dayhourrfc') . " *****\n";
|
||||||
|
|
||||||
// Check module cron is activated
|
// Check module cron is activated
|
||||||
if (empty($conf->cron->enabled))
|
if (empty($conf->cron->enabled)) {
|
||||||
{
|
|
||||||
print "Error: module Scheduled jobs (cron) not activated\n";
|
print "Error: module Scheduled jobs (cron) not activated\n";
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check module cron is activated
|
// Check module cron is activated
|
||||||
if (empty($conf->cron->enabled))
|
if (empty($conf->cron->enabled)) {
|
||||||
{
|
|
||||||
print "Error: module Scheduled jobs (cron) not activated\n";
|
print "Error: module Scheduled jobs (cron) not activated\n";
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check security key
|
// Check security key
|
||||||
if ($key != $conf->global->CRON_KEY)
|
if ($key != $conf->global->CRON_KEY) {
|
||||||
{
|
|
||||||
print "Error: securitykey is wrong\n";
|
print "Error: securitykey is wrong\n";
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If param userlogin is reserved word 'firstadmin'
|
// If param userlogin is reserved word 'firstadmin'
|
||||||
if ($userlogin == 'firstadmin')
|
if ($userlogin == 'firstadmin') {
|
||||||
{
|
|
||||||
$sql = 'SELECT login, entity from ' . MAIN_DB_PREFIX . 'user WHERE admin = 1 and statut = 1 ORDER BY entity LIMIT 1';
|
$sql = 'SELECT login, entity from ' . MAIN_DB_PREFIX . 'user WHERE admin = 1 and statut = 1 ORDER BY entity LIMIT 1';
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
|
||||||
$obj = $db->fetch_object($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
if ($obj)
|
if ($obj) {
|
||||||
{
|
|
||||||
$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
|
||||||
else dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check user login
|
// Check user login
|
||||||
$user = new User($db);
|
$user = new User($db);
|
||||||
$result = $user->fetch('', $userlogin);
|
$result = $user->fetch('', $userlogin);
|
||||||
if ($result < 0)
|
if ($result < 0) {
|
||||||
{
|
|
||||||
echo "User Error: " . $user->error;
|
echo "User Error: " . $user->error;
|
||||||
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 (empty($user->id)) {
|
||||||
{
|
|
||||||
if (empty($user->id))
|
|
||||||
{
|
|
||||||
echo "User login: " . $userlogin . " does not exists";
|
echo "User login: " . $userlogin . " does not exists";
|
||||||
dol_syslog("User login:" . $userlogin . " does not exists", LOG_ERR);
|
dol_syslog("User login:" . $userlogin . " does not exists", LOG_ERR);
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
@ -136,8 +128,7 @@ else
|
|||||||
}
|
}
|
||||||
$user->getrights();
|
$user->getrights();
|
||||||
|
|
||||||
if (isset($argv[3]) || $argv[3])
|
if (isset($argv[3]) || $argv[3]) {
|
||||||
{
|
|
||||||
$id = $argv[3];
|
$id = $argv[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,28 +137,25 @@ $object = new Cronjob($db);
|
|||||||
|
|
||||||
$filter = array();
|
$filter = array();
|
||||||
if (! empty($id)) {
|
if (! empty($id)) {
|
||||||
if (! is_numeric($id))
|
if (! is_numeric($id)) {
|
||||||
{
|
|
||||||
echo "Error: Bad value for parameter job id";
|
echo "Error: Bad value for parameter job id";
|
||||||
dol_syslog("cron_run_jobs.php Bad value for parameter job id", LOG_WARNING);
|
dol_syslog("cron_run_jobs.php Bad value for parameter job id", LOG_WARNING);
|
||||||
exit;
|
exit();
|
||||||
}
|
}
|
||||||
$filter['t.rowid'] = $id;
|
$filter['t.rowid'] = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $object->fetch_all('ASC,ASC,ASC', 't.priority,t.entity,t.rowid', 0, 0, 1, $filter, 0);
|
$result = $object->fetch_all('ASC,ASC,ASC', 't.priority,t.entity,t.rowid', 0, 0, 1, $filter, 0);
|
||||||
if ($result<0)
|
if ($result < 0) {
|
||||||
{
|
|
||||||
echo "Error: " . $object->error;
|
echo "Error: " . $object->error;
|
||||||
dol_syslog("cron_run_jobs.php:: fetch Error " . $object->error, LOG_ERR);
|
dol_syslog("cron_run_jobs.php:: fetch Error " . $object->error, LOG_ERR);
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,26 +165,22 @@ $nbofjobs=count($qualifiedjobs);
|
|||||||
$nbofjobslaunchedok = 0;
|
$nbofjobslaunchedok = 0;
|
||||||
$nbofjobslaunchedko = 0;
|
$nbofjobslaunchedko = 0;
|
||||||
|
|
||||||
if (is_array($qualifiedjobs) && (count($qualifiedjobs)>0))
|
if (is_array($qualifiedjobs) && (count($qualifiedjobs) > 0)) {
|
||||||
{
|
|
||||||
// Loop over job
|
// Loop over job
|
||||||
foreach($qualifiedjobs as $line)
|
foreach ($qualifiedjobs as $line) {
|
||||||
{
|
|
||||||
dol_syslog("cron_run_jobs.php cronjobid: " . $line->id . " priority=" . $line->priority . " entity=" . $line->entity . " label=" . $line->label, LOG_DEBUG);
|
dol_syslog("cron_run_jobs.php cronjobid: " . $line->id . " priority=" . $line->priority . " entity=" . $line->entity . " label=" . $line->label, LOG_DEBUG);
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
// 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
|
||||||
if (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now))
|
if (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now)) {
|
||||||
{
|
|
||||||
echo " - qualified";
|
echo " - qualified";
|
||||||
|
|
||||||
dol_syslog("cron_run_jobs.php line->datenextrun:" . dol_print_date($line->datenextrun, 'dayhourrfc') . " line->datestart:" . dol_print_date($line->datestart, 'dayhourrfc') . " line->dateend:" . dol_print_date($line->dateend, 'dayhourrfc') . " now:" . dol_print_date($now, 'dayhourrfc'));
|
dol_syslog("cron_run_jobs.php line->datenextrun:" . dol_print_date($line->datenextrun, 'dayhourrfc') . " line->datestart:" . dol_print_date($line->datestart, 'dayhourrfc') . " line->dateend:" . dol_print_date($line->dateend, 'dayhourrfc') . " now:" . dol_print_date($now, 'dayhourrfc'));
|
||||||
|
|
||||||
$cronjob = new Cronjob($db);
|
$cronjob = new Cronjob($db);
|
||||||
$result = $cronjob->fetch($line->id);
|
$result = $cronjob->fetch($line->id);
|
||||||
if ($result < 0)
|
if ($result < 0) {
|
||||||
{
|
|
||||||
echo "Error cronjobid: " . $line->id . " cronjob->fetch: " . $cronjob->error . "\n";
|
echo "Error cronjobid: " . $line->id . " cronjob->fetch: " . $cronjob->error . "\n";
|
||||||
echo "Failed to fetch job " . $line->id . "\n";
|
echo "Failed to fetch job " . $line->id . "\n";
|
||||||
dol_syslog("cron_run_jobs.php::fetch Error " . $cronjob->error, LOG_ERR);
|
dol_syslog("cron_run_jobs.php::fetch Error " . $cronjob->error, LOG_ERR);
|
||||||
@ -204,16 +188,13 @@ if (is_array($qualifiedjobs) && (count($qualifiedjobs)>0))
|
|||||||
}
|
}
|
||||||
// Execute job
|
// Execute job
|
||||||
$result = $cronjob->run_jobs($userlogin);
|
$result = $cronjob->run_jobs($userlogin);
|
||||||
if ($result < 0)
|
if ($result < 0) {
|
||||||
{
|
|
||||||
echo "Error cronjobid: " . $line->id . " cronjob->run_job: " . $cronjob->error . "\n";
|
echo "Error cronjobid: " . $line->id . " cronjob->run_job: " . $cronjob->error . "\n";
|
||||||
echo "At least one job failed. Go on menu Home-Setup-Admin tools to see result for each job.\n";
|
echo "At least one job failed. Go on menu Home-Setup-Admin tools to see result for each job.\n";
|
||||||
echo "You can also enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
|
echo "You can also enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
|
||||||
dol_syslog("cron_run_jobs.php::run_jobs Error " . $cronjob->error, LOG_ERR);
|
dol_syslog("cron_run_jobs.php::run_jobs Error " . $cronjob->error, LOG_ERR);
|
||||||
$nbofjobslaunchedko ++;
|
$nbofjobslaunchedko ++;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$nbofjobslaunchedok ++;
|
$nbofjobslaunchedok ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,8 +202,7 @@ if (is_array($qualifiedjobs) && (count($qualifiedjobs)>0))
|
|||||||
|
|
||||||
// we re-program the next execution and stores the last execution time for this job
|
// we re-program the next execution and stores the last execution time for this job
|
||||||
$result = $cronjob->reprogram_jobs($userlogin, $now);
|
$result = $cronjob->reprogram_jobs($userlogin, $now);
|
||||||
if ($result<0)
|
if ($result < 0) {
|
||||||
{
|
|
||||||
echo "Error cronjobid: " . $line->id . " cronjob->reprogram_job: " . $cronjob->error . "\n";
|
echo "Error cronjobid: " . $line->id . " cronjob->reprogram_job: " . $cronjob->error . "\n";
|
||||||
echo "Enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
|
echo "Enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
|
||||||
dol_syslog("cron_run_jobs.php::reprogram_jobs Error " . $cronjob->error, LOG_ERR);
|
dol_syslog("cron_run_jobs.php::reprogram_jobs Error " . $cronjob->error, LOG_ERR);
|
||||||
@ -230,32 +210,29 @@ if (is_array($qualifiedjobs) && (count($qualifiedjobs)>0))
|
|||||||
}
|
}
|
||||||
|
|
||||||
echo " - reprogrammed\n";
|
echo " - reprogrammed\n";
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
echo " - not qualified\n";
|
echo " - not qualified\n";
|
||||||
|
|
||||||
dol_syslog("cron_run_jobs.php job not qualified line->datenextrun:" . dol_print_date($line->datenextrun, 'dayhourrfc') . " line->datestart:" . dol_print_date($line->datestart, 'dayhourrfc') . " line->dateend:" . dol_print_date($line->dateend, 'dayhourrfc') . " now:" . dol_print_date($now, 'dayhourrfc'));
|
dol_syslog("cron_run_jobs.php job not qualified line->datenextrun:" . dol_print_date($line->datenextrun, 'dayhourrfc') . " line->datestart:" . dol_print_date($line->datestart, 'dayhourrfc') . " line->dateend:" . dol_print_date($line->dateend, 'dayhourrfc') . " now:" . dol_print_date($now, 'dayhourrfc'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
echo "cron_run_jobs.php no qualified job found\n";
|
echo "cron_run_jobs.php no qualified job found\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$db->close();
|
$db->close();
|
||||||
|
|
||||||
if ($nbofjobslaunchedko) exit(1);
|
if ($nbofjobslaunchedko)
|
||||||
|
exit(1);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* script cron usage
|
* script cron usage
|
||||||
*
|
*
|
||||||
* @param string $path path
|
* @param string $path
|
||||||
* @param string $script_file filename
|
* path
|
||||||
|
* @param string $script_file
|
||||||
|
* filename
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function usage($path, $script_file)
|
function usage($path, $script_file)
|
||||||
|
|||||||
@ -19,16 +19,14 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file scripts/emailings/mailing-send.php
|
* \file scripts/emailings/mailing-send.php
|
||||||
* \ingroup mailing
|
* \ingroup mailing
|
||||||
* \brief Script d'envoi d'un mailing prepare et valide
|
* \brief Script d'envoi d'un mailing prepare et valide
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test if batch mode
|
// Test if batch mode
|
||||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||||
@ -41,20 +39,19 @@ if (! isset($argv[1]) || ! $argv[1]) {
|
|||||||
exit(- 1);
|
exit(- 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 = '';
|
||||||
|
|
||||||
require_once $path . "../../htdocs/master.inc.php";
|
require_once $path . "../../htdocs/master.inc.php";
|
||||||
require_once DOL_DOCUMENT_ROOT . "/core/class/CMailFile.class.php";
|
require_once DOL_DOCUMENT_ROOT . "/core/class/CMailFile.class.php";
|
||||||
require_once DOL_DOCUMENT_ROOT . "/comm/mailing/class/mailing.class.php";
|
require_once DOL_DOCUMENT_ROOT . "/comm/mailing/class/mailing.class.php";
|
||||||
|
|
||||||
|
|
||||||
// Global variables
|
// Global variables
|
||||||
$version = DOL_VERSION;
|
$version = DOL_VERSION;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -62,34 +59,29 @@ $error=0;
|
|||||||
@set_time_limit(0);
|
@set_time_limit(0);
|
||||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\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)) $user->fetch('', $login);
|
if (! empty($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";
|
||||||
$sql .= " FROM " . MAIN_DB_PREFIX . "mailing as m";
|
$sql .= " FROM " . MAIN_DB_PREFIX . "mailing as m";
|
||||||
$sql .= " WHERE m.statut IN (1,2)";
|
$sql .= " WHERE m.statut IN (1,2)";
|
||||||
if ($id != 'all')
|
if ($id != 'all') {
|
||||||
{
|
|
||||||
$sql .= " AND m.rowid= " . $id;
|
$sql .= " AND m.rowid= " . $id;
|
||||||
$sql .= " LIMIT 1";
|
$sql .= " LIMIT 1";
|
||||||
}
|
}
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
$j = 0;
|
$j = 0;
|
||||||
|
|
||||||
if ($num)
|
if ($num) {
|
||||||
{
|
for ($j = 0; $j < $num; $j ++) {
|
||||||
for ($j=0; $j<$num; $j++)
|
|
||||||
{
|
|
||||||
$obj = $db->fetch_object($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
|
|
||||||
dol_syslog("Process mailing with id " . $obj->rowid);
|
dol_syslog("Process mailing with id " . $obj->rowid);
|
||||||
@ -106,44 +98,41 @@ 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)) $msgishtml=1;
|
if (preg_match('/[\s\t]*<html>/i', $message))
|
||||||
|
$msgishtml = 1;
|
||||||
|
|
||||||
$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)
|
||||||
$sql2 = "SELECT mc.rowid, mc.fk_mailing, mc.lastname, mc.firstname, mc.email, mc.other, mc.source_url, mc.source_id, mc.source_type, mc.tag";
|
$sql2 = "SELECT mc.rowid, mc.fk_mailing, mc.lastname, mc.firstname, mc.email, mc.other, mc.source_url, mc.source_id, mc.source_type, mc.tag";
|
||||||
$sql2 .= " FROM " . MAIN_DB_PREFIX . "mailing_cibles as mc";
|
$sql2 .= " FROM " . MAIN_DB_PREFIX . "mailing_cibles as mc";
|
||||||
$sql2 .= " WHERE mc.statut < 1 AND mc.fk_mailing = " . $id;
|
$sql2 .= " WHERE mc.statut < 1 AND mc.fk_mailing = " . $id;
|
||||||
if ($conf->global->MAILING_LIMIT_SENDBYCLI > 0)
|
if ($conf->global->MAILING_LIMIT_SENDBYCLI > 0) {
|
||||||
{
|
|
||||||
$sql2 .= " LIMIT " . $conf->global->MAILING_LIMIT_SENDBYCLI;
|
$sql2 .= " LIMIT " . $conf->global->MAILING_LIMIT_SENDBYCLI;
|
||||||
}
|
}
|
||||||
|
|
||||||
$resql2 = $db->query($sql2);
|
$resql2 = $db->query($sql2);
|
||||||
if ($resql2)
|
if ($resql2) {
|
||||||
{
|
|
||||||
$num2 = $db->num_rows($resql2);
|
$num2 = $db->num_rows($resql2);
|
||||||
dol_syslog("Nb of targets = " . $num2, LOG_DEBUG);
|
dol_syslog("Nb of targets = " . $num2, LOG_DEBUG);
|
||||||
print "Nb of targets = " . $num2 . "\n";
|
print "Nb of targets = " . $num2 . "\n";
|
||||||
|
|
||||||
if ($num2)
|
if ($num2) {
|
||||||
{
|
|
||||||
$now = dol_now();
|
$now = dol_now();
|
||||||
|
|
||||||
// Positionne date debut envoi
|
// Positionne date debut envoi
|
||||||
$sqlstartdate = "UPDATE " . MAIN_DB_PREFIX . "mailing SET date_envoi='" . $db->idate($now) . "' WHERE rowid=" . $id;
|
$sqlstartdate = "UPDATE " . MAIN_DB_PREFIX . "mailing SET date_envoi='" . $db->idate($now) . "' WHERE rowid=" . $id;
|
||||||
$resqlstartdate = $db->query($sqlstartdate);
|
$resqlstartdate = $db->query($sqlstartdate);
|
||||||
if (! $resqlstartdate)
|
if (! $resqlstartdate) {
|
||||||
{
|
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
$error ++;
|
$error ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look on each email and sent message
|
// Look on each email and sent message
|
||||||
$i = 0;
|
$i = 0;
|
||||||
while ($i < $num2)
|
while ($i < $num2) {
|
||||||
{
|
|
||||||
// Here code is common with same loop ino card.php
|
// Here code is common with same loop ino card.php
|
||||||
$res = 1;
|
$res = 1;
|
||||||
$now = dol_now();
|
$now = dol_now();
|
||||||
@ -155,11 +144,16 @@ if ($resql)
|
|||||||
|
|
||||||
// Make subtsitutions on topic and body
|
// Make subtsitutions on topic and body
|
||||||
$other = explode(';', $obj->other);
|
$other = explode(';', $obj->other);
|
||||||
$tmpfield=explode('=', $other[0], 2); $other1=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
|
$tmpfield = explode('=', $other[0], 2);
|
||||||
$tmpfield=explode('=', $other[1], 2); $other2=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
|
$other1 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
|
||||||
$tmpfield=explode('=', $other[2], 2); $other3=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
|
$tmpfield = explode('=', $other[1], 2);
|
||||||
$tmpfield=explode('=', $other[3], 2); $other4=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
|
$other2 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
|
||||||
$tmpfield=explode('=', $other[4], 2); $other5=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
|
$tmpfield = explode('=', $other[2], 2);
|
||||||
|
$other3 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
|
||||||
|
$tmpfield = explode('=', $other[3], 2);
|
||||||
|
$other4 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
|
||||||
|
$tmpfield = explode('=', $other[4], 2);
|
||||||
|
$other5 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
|
||||||
$signature = ((! empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $user->signature : '');
|
$signature = ((! empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $user->signature : '');
|
||||||
|
|
||||||
$object = null; // Not defined with mass emailing
|
$object = null; // Not defined with mass emailing
|
||||||
@ -183,21 +177,20 @@ 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)) $onlinepaymentenabled++;
|
if (! empty($conf->paypal->enabled))
|
||||||
if (! empty($conf->paybox->enabled)) $onlinepaymentenabled++;
|
$onlinepaymentenabled ++;
|
||||||
if (! empty($conf->stripe->enabled)) $onlinepaymentenabled++;
|
if (! empty($conf->paybox->enabled))
|
||||||
if ($onlinepaymentenabled && ! empty($conf->global->PAYMENT_SECURITY_TOKEN))
|
$onlinepaymentenabled ++;
|
||||||
{
|
if (! empty($conf->stripe->enabled))
|
||||||
|
$onlinepaymentenabled ++;
|
||||||
|
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)) {
|
||||||
{
|
|
||||||
$substitutionarray['__SECUREKEYPAYMENT_MEMBER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
|
$substitutionarray['__SECUREKEYPAYMENT_MEMBER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
|
||||||
$substitutionarray['__SECUREKEYPAYMENT_ORDER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
|
$substitutionarray['__SECUREKEYPAYMENT_ORDER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
|
||||||
$substitutionarray['__SECUREKEYPAYMENT_INVOICE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
|
$substitutionarray['__SECUREKEYPAYMENT_INVOICE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
|
||||||
$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
|
$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$substitutionarray['__SECUREKEYPAYMENT_MEMBER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
|
$substitutionarray['__SECUREKEYPAYMENT_MEMBER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
|
||||||
$substitutionarray['__SECUREKEYPAYMENT_ORDER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
|
$substitutionarray['__SECUREKEYPAYMENT_ORDER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
|
||||||
$substitutionarray['__SECUREKEYPAYMENT_INVOICE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
|
$substitutionarray['__SECUREKEYPAYMENT_INVOICE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
|
||||||
@ -205,21 +198,28 @@ if ($resql)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* For backward compatibility */
|
/* For backward compatibility */
|
||||||
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)) $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
|
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE))
|
||||||
else $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 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);
|
||||||
|
|
||||||
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
|
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE))
|
||||||
else $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'order' . $obj->source_id, 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);
|
||||||
|
|
||||||
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
|
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE))
|
||||||
else $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'invoice' . $obj->source_id, 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);
|
||||||
|
|
||||||
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
|
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE))
|
||||||
else $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'contractline' . $obj->source_id, 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
complete_substitutions_array($substitutionarray, $langs);
|
complete_substitutions_array($substitutionarray, $langs);
|
||||||
@ -230,43 +230,22 @@ if ($resql)
|
|||||||
|
|
||||||
// Fabrication du mail
|
// Fabrication du mail
|
||||||
$trackid = 'emailing-' . $obj->fk_mailing . '-' . $obj->rowid;
|
$trackid = 'emailing-' . $obj->fk_mailing . '-' . $obj->rowid;
|
||||||
$mail = new CMailFile(
|
$mail = new CMailFile($newsubject, $sendto, $from, $newmessage, array(), array(), array(), '', '', 0, $msgishtml, $errorsto, '', $trackid, '', 'emailing');
|
||||||
$newsubject,
|
|
||||||
$sendto,
|
|
||||||
$from,
|
|
||||||
$newmessage,
|
|
||||||
array(),
|
|
||||||
array(),
|
|
||||||
array(),
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
0,
|
|
||||||
$msgishtml,
|
|
||||||
$errorsto,
|
|
||||||
'',
|
|
||||||
$trackid,
|
|
||||||
'',
|
|
||||||
'emailing'
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($mail->error)
|
if ($mail->error) {
|
||||||
{
|
|
||||||
$res = 0;
|
$res = 0;
|
||||||
}
|
}
|
||||||
if (! $substitutionisok)
|
if (! $substitutionisok) {
|
||||||
{
|
|
||||||
$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 ++;
|
||||||
|
|
||||||
@ -276,39 +255,34 @@ if ($resql)
|
|||||||
// We must union table llx_mailing_taget for event tab OR enter 1 event with a special table link (id of email in event)
|
// We must union table llx_mailing_taget for event tab OR enter 1 event with a special table link (id of email in event)
|
||||||
// Run trigger
|
// Run trigger
|
||||||
/*
|
/*
|
||||||
if ($obj->source_type == 'contact')
|
* if ($obj->source_type == 'contact')
|
||||||
{
|
* {
|
||||||
$emailing->sendtoid = $obj->source_id;
|
* $emailing->sendtoid = $obj->source_id;
|
||||||
}
|
* }
|
||||||
if ($obj->source_type == 'thirdparty')
|
* if ($obj->source_type == 'thirdparty')
|
||||||
{
|
* {
|
||||||
$emailing->socid = $obj->source_id;
|
* $emailing->socid = $obj->source_id;
|
||||||
}
|
* }
|
||||||
// Call trigger
|
* // Call trigger
|
||||||
$result=$emailing->call_trigger('EMAILING_SENTBYMAIL',$user);
|
* $result=$emailing->call_trigger('EMAILING_SENTBYMAIL',$user);
|
||||||
if ($result < 0) $error++;
|
* if ($result < 0) $error++;
|
||||||
// End call triggers
|
* // End call triggers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sqlok = "UPDATE " . MAIN_DB_PREFIX . "mailing_cibles";
|
$sqlok = "UPDATE " . MAIN_DB_PREFIX . "mailing_cibles";
|
||||||
$sqlok .= " SET statut=1, date_envoi='" . $db->idate($now) . "' WHERE rowid=" . $obj->rowid;
|
$sqlok .= " SET statut=1, date_envoi='" . $db->idate($now) . "' WHERE rowid=" . $obj->rowid;
|
||||||
$resqlok = $db->query($sqlok);
|
$resqlok = $db->query($sqlok);
|
||||||
if (! $resqlok)
|
if (! $resqlok) {
|
||||||
{
|
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
$error ++;
|
$error ++;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// if cheack read is use then update prospect contact status
|
// if cheack read is use then update prospect contact status
|
||||||
if (strpos($message, '__CHECK_READ__') !== false)
|
if (strpos($message, '__CHECK_READ__') !== false) {
|
||||||
{
|
|
||||||
// Update status communication of thirdparty prospect
|
// Update status communication of thirdparty prospect
|
||||||
$sqlx = "UPDATE " . MAIN_DB_PREFIX . "societe SET fk_stcomm=2 WHERE rowid IN (SELECT source_id FROM " . MAIN_DB_PREFIX . "mailing_cibles WHERE rowid=" . $obj->rowid . ")";
|
$sqlx = "UPDATE " . MAIN_DB_PREFIX . "societe SET fk_stcomm=2 WHERE rowid IN (SELECT source_id FROM " . MAIN_DB_PREFIX . "mailing_cibles WHERE rowid=" . $obj->rowid . ")";
|
||||||
dol_syslog("card.php: set prospect thirdparty status", LOG_DEBUG);
|
dol_syslog("card.php: set prospect thirdparty status", LOG_DEBUG);
|
||||||
$resqlx = $db->query($sqlx);
|
$resqlx = $db->query($sqlx);
|
||||||
if (! $resqlx)
|
if (! $resqlx) {
|
||||||
{
|
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
$error ++;
|
$error ++;
|
||||||
}
|
}
|
||||||
@ -318,8 +292,7 @@ if ($resql)
|
|||||||
dol_syslog("card.php: set prospect contact status", LOG_DEBUG);
|
dol_syslog("card.php: set prospect contact status", LOG_DEBUG);
|
||||||
|
|
||||||
$resqlx = $db->query($sqlx);
|
$resqlx = $db->query($sqlx);
|
||||||
if (! $resqlx)
|
if (! $resqlx) {
|
||||||
{
|
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
$error ++;
|
$error ++;
|
||||||
}
|
}
|
||||||
@ -329,9 +302,7 @@ if ($resql)
|
|||||||
sleep($conf->global->MAILING_DELAY);
|
sleep($conf->global->MAILING_DELAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// Mail failed
|
// Mail failed
|
||||||
$nbko ++;
|
$nbko ++;
|
||||||
|
|
||||||
@ -340,8 +311,7 @@ if ($resql)
|
|||||||
$sqlerror = "UPDATE " . MAIN_DB_PREFIX . "mailing_cibles";
|
$sqlerror = "UPDATE " . MAIN_DB_PREFIX . "mailing_cibles";
|
||||||
$sqlerror .= " SET statut=-1, date_envoi=" . $db->idate($now) . " WHERE rowid=" . $obj->rowid;
|
$sqlerror .= " SET statut=-1, date_envoi=" . $db->idate($now) . " WHERE rowid=" . $obj->rowid;
|
||||||
$resqlerror = $db->query($sqlerror);
|
$resqlerror = $db->query($sqlerror);
|
||||||
if (! $resqlerror)
|
if (! $resqlerror) {
|
||||||
{
|
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
$error ++;
|
$error ++;
|
||||||
}
|
}
|
||||||
@ -349,9 +319,7 @@ if ($resql)
|
|||||||
|
|
||||||
$i ++;
|
$i ++;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$mesg = "Emailing id " . $id . " has no recipient to target";
|
$mesg = "Emailing id " . $id . " has no recipient to target";
|
||||||
print $mesg . "\n";
|
print $mesg . "\n";
|
||||||
dol_syslog($mesg, LOG_ERR);
|
dol_syslog($mesg, LOG_ERR);
|
||||||
@ -359,39 +327,32 @@ if ($resql)
|
|||||||
|
|
||||||
// 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;
|
||||||
|
|
||||||
$sqlenddate = "UPDATE " . MAIN_DB_PREFIX . "mailing SET statut=" . $statut . " WHERE rowid=" . $id;
|
$sqlenddate = "UPDATE " . MAIN_DB_PREFIX . "mailing SET statut=" . $statut . " WHERE rowid=" . $id;
|
||||||
|
|
||||||
dol_syslog("update global status", LOG_DEBUG);
|
dol_syslog("update global status", LOG_DEBUG);
|
||||||
print "Update status of emailing id " . $id . " to " . $statut . "\n";
|
print "Update status of emailing id " . $id . " to " . $statut . "\n";
|
||||||
$resqlenddate = $db->query($sqlenddate);
|
$resqlenddate = $db->query($sqlenddate);
|
||||||
if (! $resqlenddate)
|
if (! $resqlenddate) {
|
||||||
{
|
dol_print_error($db);
|
||||||
|
$error ++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
$error ++;
|
$error ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
dol_print_error($db);
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$mesg = "No validated emailing id to send found.";
|
$mesg = "No validated emailing id to send found.";
|
||||||
print $mesg . "\n";
|
print $mesg . "\n";
|
||||||
dol_syslog($mesg, LOG_ERR);
|
dol_syslog($mesg, LOG_ERR);
|
||||||
$error ++;
|
$error ++;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
$error ++;
|
$error ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
exit($error);
|
exit($error);
|
||||||
|
|||||||
@ -24,10 +24,9 @@
|
|||||||
* \ingroup facture
|
* \ingroup facture
|
||||||
* \brief Script to send a mail to customers with unpaid invoices
|
* \brief Script to send a mail to customers with unpaid invoices
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test si mode batch
|
// Test si mode batch
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
@ -36,8 +35,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
|
|||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isset($argv[2]) || ! $argv[2] || ! in_array($argv[1], array('test','confirm')) || ! in_array($argv[2], array('thirdparties','contacts')))
|
if (! isset($argv[2]) || ! $argv[2] || ! in_array($argv[1], array('test','confirm')) || ! in_array($argv[2], array('thirdparties','contacts'))) {
|
||||||
{
|
|
||||||
print "Usage: $script_file (test|confirm) (thirdparties|contacts) [delay] [after]\n";
|
print "Usage: $script_file (test|confirm) (thirdparties|contacts) [delay] [after]\n";
|
||||||
print "\n";
|
print "\n";
|
||||||
print "Send an email to customers to remind all unpaid customer invoices.\n";
|
print "Send an email to customers to remind all unpaid customer invoices.\n";
|
||||||
@ -49,7 +47,6 @@ if (! isset($argv[2]) || ! $argv[2] || ! in_array($argv[1], array('test','confir
|
|||||||
$mode = $argv[1];
|
$mode = $argv[1];
|
||||||
$targettype = $argv[2];
|
$targettype = $argv[2];
|
||||||
|
|
||||||
|
|
||||||
require $path . "../../htdocs/master.inc.php";
|
require $path . "../../htdocs/master.inc.php";
|
||||||
require_once DOL_DOCUMENT_ROOT . "/core/class/CMailFile.class.php";
|
require_once DOL_DOCUMENT_ROOT . "/core/class/CMailFile.class.php";
|
||||||
|
|
||||||
@ -59,8 +56,6 @@ $langs->load('main');
|
|||||||
$version = DOL_VERSION;
|
$version = DOL_VERSION;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -76,64 +71,72 @@ $duration_value2=isset($argv[4])?$argv[4]:'none';
|
|||||||
$error = 0;
|
$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";
|
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') $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
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 = "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') $sql.= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail";
|
if ($targettype == 'contacts')
|
||||||
|
$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') $sql.= ", ".MAIN_DB_PREFIX."socpeople as sp";
|
if ($targettype == 'contacts')
|
||||||
|
$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)) $sql.= " AND f.date_lim_reglement >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'";
|
if (is_numeric($duration_value2))
|
||||||
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_value2, "d")) . "'";
|
||||||
if ($targettype == 'contacts') $sql.= " AND s.rowid = sp.fk_soc";
|
if (is_numeric($duration_value))
|
||||||
|
$sql .= " AND f.date_lim_reglement < '" . $db->idate(dol_time_plus_duree($now, $duration_value, "d")) . "'";
|
||||||
|
if ($targettype == 'contacts')
|
||||||
|
$sql .= " AND s.rowid = sp.fk_soc";
|
||||||
$sql .= " ORDER BY";
|
$sql .= " ORDER BY";
|
||||||
if ($targettype == 'contacts') $sql.= " sp.email, sp.rowid,";
|
if ($targettype == 'contacts')
|
||||||
|
$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;
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$oldemail = 'none'; $oldsid = 0; $oldcid = 0; $oldlang='';
|
$oldemail = 'none';
|
||||||
$total = 0; $foundtoprocess = 0;
|
$oldsid = 0;
|
||||||
|
$oldcid = 0;
|
||||||
|
$oldlang = '';
|
||||||
|
$total = 0;
|
||||||
|
$foundtoprocess = 0;
|
||||||
$trackthirdpartiessent = array();
|
$trackthirdpartiessent = array();
|
||||||
|
|
||||||
print "We found " . $num . " couples (unpayed validated invoices-" . $targettype . ") qualified\n";
|
print "We found " . $num . " couples (unpayed validated invoices-" . $targettype . ") qualified\n";
|
||||||
dol_syslog("We found " . $num . " couples (unpayed validated invoices-" . $targettype . ") qualified");
|
dol_syslog("We found " . $num . " couples (unpayed validated invoices-" . $targettype . ") qualified");
|
||||||
$message = '';
|
$message = '';
|
||||||
|
|
||||||
if ($num)
|
if ($num) {
|
||||||
{
|
while ($i < $num) {
|
||||||
while ($i < $num)
|
|
||||||
{
|
|
||||||
$obj = $db->fetch_object($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
|
|
||||||
$newemail = empty($obj->cemail) ? $obj->email : $obj->cemail;
|
$newemail = empty($obj->cemail) ? $obj->email : $obj->cemail;
|
||||||
|
|
||||||
// Check if this record is a break after previous one
|
// Check if this record is a break after previous one
|
||||||
$startbreak = false;
|
$startbreak = false;
|
||||||
if ($newemail <> $oldemail || $oldemail == 'none') $startbreak=true;
|
if ($newemail != $oldemail || $oldemail == 'none')
|
||||||
if ($obj->sid && $obj->sid <> $oldsid) $startbreak=true;
|
$startbreak = true;
|
||||||
if ($obj->cid && $obj->cid <> $oldcid) $startbreak=true;
|
if ($obj->sid && $obj->sid != $oldsid)
|
||||||
|
$startbreak = true;
|
||||||
|
if ($obj->cid && $obj->cid != $oldcid)
|
||||||
|
$startbreak = true;
|
||||||
|
|
||||||
if ($startbreak)
|
if ($startbreak) {
|
||||||
{
|
|
||||||
// Break onto sales representative (new email or cid)
|
// Break onto sales representative (new email or cid)
|
||||||
if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))
|
if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid . '|' . $oldemail])) {
|
||||||
{
|
|
||||||
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 {
|
||||||
|
if ($oldemail != 'none') {
|
||||||
|
if (empty($trackthirdpartiessent[$oldsid . '|' . $oldemail]))
|
||||||
|
print "- No email sent for '" . $oldtarget . "', total: " . $total . "\n";
|
||||||
else
|
else
|
||||||
{
|
print "- No email sent for '" . $oldtarget . "', total: " . $total . " (already sent to " . $trackthirdpartiessent[$oldsid . '|' . $oldemail] . ")\n";
|
||||||
if ($oldemail != 'none')
|
|
||||||
{
|
|
||||||
if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) 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";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$oldemail = $newemail;
|
$oldemail = $newemail;
|
||||||
@ -155,15 +158,16 @@ if ($resql)
|
|||||||
// Load translation files required by the page
|
// Load translation files required by the page
|
||||||
$outputlangs->loadLangs(array("main","bills"));
|
$outputlangs->loadLangs(array("main","bills"));
|
||||||
|
|
||||||
if (dol_strlen($newemail))
|
if (dol_strlen($newemail)) {
|
||||||
{
|
|
||||||
$message .= $outputlangs->trans("Invoice") . " " . $obj->ref . " : " . price($obj->total_ttc, 0, $outputlangs, 0, 0, - 1, $conf->currency) . "\n";
|
$message .= $outputlangs->trans("Invoice") . " " . $obj->ref . " : " . price($obj->total_ttc, 0, $outputlangs, 0, 0, - 1, $conf->currency) . "\n";
|
||||||
dol_syslog("email_unpaid_invoices_to_customers.php: " . $newemail . " " . $message);
|
dol_syslog("email_unpaid_invoices_to_customers.php: " . $newemail . " " . $message);
|
||||||
$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 . ", " . ($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 . ", " . ($obj->cid ? "contact id " . $obj->cid . " " . $obj->clastname . " " . $obj->cfirstname . ", " : "") . "email " . $newemail . ", lang " . $outputlangs->defaultlang . ": ";
|
||||||
if (dol_strlen($newemail)) print "qualified.";
|
if (dol_strlen($newemail))
|
||||||
else print "disqualified (no email).";
|
print "qualified.";
|
||||||
|
else
|
||||||
|
print "disqualified (no email).";
|
||||||
print "\n";
|
print "\n";
|
||||||
|
|
||||||
unset($outputlangs);
|
unset($outputlangs);
|
||||||
@ -174,55 +178,55 @@ 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 {
|
||||||
|
if ($oldemail != 'none') {
|
||||||
|
if (empty($trackthirdpartiessent[$oldsid . '|' . $oldemail]))
|
||||||
|
print "- No email sent for '" . $oldtarget . "', total: " . $total . "\n";
|
||||||
else
|
else
|
||||||
{
|
print "- No email sent for '" . $oldtarget . "', total: " . $total . " (already sent to " . $trackthirdpartiessent[$oldsid . '|' . $oldemail] . ")\n";
|
||||||
if ($oldemail != 'none')
|
|
||||||
{
|
|
||||||
if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) 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 {
|
||||||
else
|
|
||||||
{
|
|
||||||
print "No unpaid invoices found\n";
|
print "No unpaid invoices found\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
dol_syslog("email_unpaid_invoices_to_customers.php: Error");
|
dol_syslog("email_unpaid_invoices_to_customers.php: Error");
|
||||||
|
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send email
|
* Send email
|
||||||
*
|
*
|
||||||
* @param string $mode Mode (test | confirm)
|
* @param string $mode
|
||||||
* @param string $oldemail Target email
|
* Mode (test | confirm)
|
||||||
* @param string $message Message to send
|
* @param string $oldemail
|
||||||
* @param string $total Total amount of unpayed invoices
|
* Target email
|
||||||
* @param string $userlang Code lang to use for email output.
|
* @param string $message
|
||||||
* @param string $oldtarget Target name
|
* Message to send
|
||||||
|
* @param string $total
|
||||||
|
* Total amount of unpayed invoices
|
||||||
|
* @param string $userlang
|
||||||
|
* Code lang to use for email output.
|
||||||
|
* @param string $oldtarget
|
||||||
|
* Target name
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget)
|
function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget)
|
||||||
{
|
{
|
||||||
global $conf, $langs;
|
global $conf, $langs;
|
||||||
|
|
||||||
if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail=getenv('DOL_FORCE_EMAIL_TO');
|
if (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,56 +243,39 @@ 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 (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) $usehtml+=1;
|
if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER))
|
||||||
if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER)) $usehtml+=1;
|
$usehtml += 1;
|
||||||
|
if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER))
|
||||||
|
$usehtml += 1;
|
||||||
|
|
||||||
$allmessage = '';
|
$allmessage = '';
|
||||||
if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER))
|
if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER)) {
|
||||||
{
|
|
||||||
$allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER;
|
$allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$allmessage .= "Dear customer" . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
|
$allmessage .= "Dear customer" . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
|
||||||
$allmessage .= "Please, find a summary of the bills with pending payments from you." . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
|
$allmessage .= "Please, find a summary of the bills with pending payments from you." . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
|
||||||
$allmessage .= "Note: This list contains only unpaid invoices." . ($usehtml ? "<br>\n" : "\n");
|
$allmessage .= "Note: This list contains only unpaid invoices." . ($usehtml ? "<br>\n" : "\n");
|
||||||
}
|
}
|
||||||
$allmessage .= $message . ($usehtml ? "<br>\n" : "\n");
|
$allmessage .= $message . ($usehtml ? "<br>\n" : "\n");
|
||||||
$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)) $usehtml+=1;
|
if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER))
|
||||||
|
$usehtml += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$mail = new CMailFile(
|
$mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);
|
||||||
$subject,
|
|
||||||
$sendto,
|
|
||||||
$from,
|
|
||||||
$allmessage,
|
|
||||||
array(),
|
|
||||||
array(),
|
|
||||||
array(),
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
0,
|
|
||||||
$msgishtml
|
|
||||||
);
|
|
||||||
|
|
||||||
$mail->errors_to = $errorsto;
|
$mail->errors_to = $errorsto;
|
||||||
|
|
||||||
// Send or not email
|
// Send or not email
|
||||||
if ($mode == 'confirm')
|
if ($mode == 'confirm') {
|
||||||
{
|
|
||||||
$result = $mail->sendfile();
|
$result = $mail->sendfile();
|
||||||
if (! $result)
|
if (! $result) {
|
||||||
{
|
|
||||||
print "Error sending email " . $mail->error . "\n";
|
print "Error sending email " . $mail->error . "\n";
|
||||||
dol_syslog("Error sending email " . $mail->error . "\n");
|
dol_syslog("Error sending email " . $mail->error . "\n");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
print "No email sent (test mode)\n";
|
print "No email sent (test mode)\n";
|
||||||
dol_syslog("No email sent (test mode)");
|
dol_syslog("No email sent (test mode)");
|
||||||
$mail->dump_mail();
|
$mail->dump_mail();
|
||||||
@ -296,12 +283,9 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget)
|
|||||||
}
|
}
|
||||||
|
|
||||||
unset($newlangs);
|
unset($newlangs);
|
||||||
if ($result)
|
if ($result) {
|
||||||
{
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return - 1;
|
return - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,10 +24,9 @@
|
|||||||
* \ingroup facture
|
* \ingroup facture
|
||||||
* \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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test si mode batch
|
// Test si mode batch
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
@ -36,8 +35,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
|
|||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1], array('test','confirm')))
|
if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1], array('test','confirm'))) {
|
||||||
{
|
|
||||||
print "Usage: $script_file (test|confirm) [delay]\n";
|
print "Usage: $script_file (test|confirm) [delay]\n";
|
||||||
print "\n";
|
print "\n";
|
||||||
print "Send an email to users to remind all unpaid customer invoices user is sale representative for.\n";
|
print "Send an email to users to remind all unpaid customer invoices user is sale representative for.\n";
|
||||||
@ -47,19 +45,15 @@ if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1], array('test','confir
|
|||||||
}
|
}
|
||||||
$mode = $argv[1];
|
$mode = $argv[1];
|
||||||
|
|
||||||
|
|
||||||
require $path . "../../htdocs/master.inc.php";
|
require $path . "../../htdocs/master.inc.php";
|
||||||
require_once DOL_DOCUMENT_ROOT . "/core/class/CMailFile.class.php";
|
require_once DOL_DOCUMENT_ROOT . "/core/class/CMailFile.class.php";
|
||||||
|
|
||||||
$langs->load('main');
|
$langs->load('main');
|
||||||
|
|
||||||
|
|
||||||
// Global variables
|
// Global variables
|
||||||
$version = DOL_VERSION;
|
$version = DOL_VERSION;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -73,7 +67,8 @@ $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";
|
print $script_file . " launched with mode " . $mode . " default lang=" . $langs->defaultlang . (is_numeric($duration_value) ? " delay=" . $duration_value : "") . "\n";
|
||||||
|
|
||||||
if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
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 = "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";
|
$sql .= " u.rowid as uid, u.lastname, u.firstname, u.email, u.lang";
|
||||||
@ -83,39 +78,37 @@ $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)) $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
|
if (is_numeric($duration_value))
|
||||||
|
$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
|
||||||
|
|
||||||
// print $sql;
|
// print $sql;
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$oldemail = 'none'; $olduid = 0; $oldlang='';
|
$oldemail = 'none';
|
||||||
$total = 0; $foundtoprocess = 0;
|
$olduid = 0;
|
||||||
|
$oldlang = '';
|
||||||
|
$total = 0;
|
||||||
|
$foundtoprocess = 0;
|
||||||
print "We found " . $num . " couples (unpayed validated invoice - sale representative) qualified\n";
|
print "We found " . $num . " couples (unpayed validated invoice - sale representative) qualified\n";
|
||||||
dol_syslog("We found " . $num . " couples (unpayed validated invoice - sale representative) qualified");
|
dol_syslog("We found " . $num . " couples (unpayed validated invoice - sale representative) qualified");
|
||||||
$message = '';
|
$message = '';
|
||||||
|
|
||||||
if ($num)
|
if ($num) {
|
||||||
{
|
while ($i < $num) {
|
||||||
while ($i < $num)
|
|
||||||
{
|
|
||||||
$obj = $db->fetch_object($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
|
|
||||||
if (($obj->email <> $oldemail || $obj->uid <> $olduid) || $oldemail == 'none')
|
if (($obj->email != $oldemail || $obj->uid != $olduid) || $oldemail == 'none') {
|
||||||
{
|
|
||||||
// Break onto sales representative (new email or uid)
|
// Break onto sales representative (new email or uid)
|
||||||
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')
|
||||||
{
|
print "- No email sent for " . $oldsalerepresentative . ", total: " . $total . "\n";
|
||||||
if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
|
|
||||||
}
|
}
|
||||||
$oldemail = $obj->email;
|
$oldemail = $obj->email;
|
||||||
$olduid = $obj->uid;
|
$olduid = $obj->uid;
|
||||||
@ -125,7 +118,8 @@ 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)) print "Warning: Sale representative ".$salerepresentative." has no email. Notice disabled.\n";
|
if (empty($obj->email))
|
||||||
|
print "Warning: Sale representative " . $salerepresentative . " has no email. Notice disabled.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define line content
|
// Define line content
|
||||||
@ -135,15 +129,16 @@ if ($resql)
|
|||||||
// Load translation files required by the page
|
// Load translation files required by the page
|
||||||
$outputlangs->loadLangs(array("main","bills"));
|
$outputlangs->loadLangs(array("main","bills"));
|
||||||
|
|
||||||
if (dol_strlen($obj->email))
|
if (dol_strlen($obj->email)) {
|
||||||
{
|
|
||||||
$message .= $outputlangs->trans("Invoice") . " " . $obj->ref . " : " . price($obj->total_ttc, 0, $outputlangs, 0, 0, - 1, $conf->currency) . " : " . $obj->name . "\n";
|
$message .= $outputlangs->trans("Invoice") . " " . $obj->ref . " : " . price($obj->total_ttc, 0, $outputlangs, 0, 0, - 1, $conf->currency) . " : " . $obj->name . "\n";
|
||||||
dol_syslog("email_unpaid_invoices_to_representatives.php: " . $obj->email);
|
dol_syslog("email_unpaid_invoices_to_representatives.php: " . $obj->email);
|
||||||
$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)) print "qualified.";
|
if (dol_strlen($obj->email))
|
||||||
else print "disqualified (no email).";
|
print "qualified.";
|
||||||
|
else
|
||||||
|
print "disqualified (no email).";
|
||||||
print "\n";
|
print "\n";
|
||||||
|
|
||||||
unset($outputlangs);
|
unset($outputlangs);
|
||||||
@ -153,50 +148,50 @@ 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')
|
||||||
{
|
print "- No email sent for " . $oldsalerepresentative . ", total: " . $total . "\n";
|
||||||
if ($oldemail != 'none') 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";
|
||||||
}
|
}
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
dol_syslog("email_unpaid_invoices_to_representatives.php: Error");
|
dol_syslog("email_unpaid_invoices_to_representatives.php: Error");
|
||||||
|
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send email
|
* Send email
|
||||||
*
|
*
|
||||||
* @param string $mode Mode (test | confirm)
|
* @param string $mode
|
||||||
* @param string $oldemail Old email
|
* Mode (test | confirm)
|
||||||
* @param string $message Message to send
|
* @param string $oldemail
|
||||||
* @param string $total Total amount of unpayed invoices
|
* Old email
|
||||||
* @param string $userlang Code lang to use for email output.
|
* @param string $message
|
||||||
* @param string $oldsalerepresentative Old sale representative
|
* Message to send
|
||||||
|
* @param string $total
|
||||||
|
* Total amount of unpayed invoices
|
||||||
|
* @param string $userlang
|
||||||
|
* Code lang to use for email output.
|
||||||
|
* @param string $oldsalerepresentative
|
||||||
|
* Old sale representative
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldsalerepresentative)
|
function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldsalerepresentative)
|
||||||
{
|
{
|
||||||
global $conf, $langs;
|
global $conf, $langs;
|
||||||
|
|
||||||
if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail=getenv('DOL_FORCE_EMAIL_TO');
|
if (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);
|
||||||
@ -213,67 +208,47 @@ 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 (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
|
if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER))
|
||||||
if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) $usehtml+=1;
|
$usehtml += 1;
|
||||||
|
if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER))
|
||||||
|
$usehtml += 1;
|
||||||
|
|
||||||
$allmessage = '';
|
$allmessage = '';
|
||||||
if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER))
|
if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) {
|
||||||
{
|
|
||||||
$allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER;
|
$allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$allmessage .= $newlangs->transnoentities("ListOfYourUnpaidInvoices") . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
|
$allmessage .= $newlangs->transnoentities("ListOfYourUnpaidInvoices") . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
|
||||||
$allmessage .= $newlangs->transnoentities("NoteListOfYourUnpaidInvoices") . ($usehtml ? "<br>\n" : "\n");
|
$allmessage .= $newlangs->transnoentities("NoteListOfYourUnpaidInvoices") . ($usehtml ? "<br>\n" : "\n");
|
||||||
}
|
}
|
||||||
$allmessage .= $message . ($usehtml ? "<br>\n" : "\n");
|
$allmessage .= $message . ($usehtml ? "<br>\n" : "\n");
|
||||||
$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)) $usehtml+=1;
|
if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER))
|
||||||
|
$usehtml += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$mail = new CMailFile(
|
$mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);
|
||||||
$subject,
|
|
||||||
$sendto,
|
|
||||||
$from,
|
|
||||||
$allmessage,
|
|
||||||
array(),
|
|
||||||
array(),
|
|
||||||
array(),
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
0,
|
|
||||||
$msgishtml
|
|
||||||
);
|
|
||||||
|
|
||||||
$mail->errors_to = $errorsto;
|
$mail->errors_to = $errorsto;
|
||||||
|
|
||||||
// Send or not email
|
// Send or not email
|
||||||
if ($mode == 'confirm')
|
if ($mode == 'confirm') {
|
||||||
{
|
|
||||||
$result = $mail->sendfile();
|
$result = $mail->sendfile();
|
||||||
if (! $result)
|
if (! $result) {
|
||||||
{
|
|
||||||
print "Error sending email " . $mail->error . "\n";
|
print "Error sending email " . $mail->error . "\n";
|
||||||
dol_syslog("Error sending email " . $mail->error . "\n");
|
dol_syslog("Error sending email " . $mail->error . "\n");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
print "No email sent (test mode)\n";
|
print "No email sent (test mode)\n";
|
||||||
dol_syslog("No email sent (test mode)");
|
dol_syslog("No email sent (test mode)");
|
||||||
$mail->dump_mail();
|
$mail->dump_mail();
|
||||||
$result = 1;
|
$result = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($result)
|
if ($result) {
|
||||||
{
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return - 1;
|
return - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,10 +22,9 @@
|
|||||||
* \ingroup facture
|
* \ingroup facture
|
||||||
* \brief Script to rebuild PDF and merge PDF files into one
|
* \brief Script to rebuild PDF and merge PDF files into one
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test if batch mode
|
// Test if batch mode
|
||||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||||
@ -41,7 +40,6 @@ require_once DOL_DOCUMENT_ROOT."/core/modules/facture/modules_facture.php";
|
|||||||
require_once DOL_DOCUMENT_ROOT . "/core/lib/date.lib.php";
|
require_once DOL_DOCUMENT_ROOT . "/core/lib/date.lib.php";
|
||||||
require_once DOL_DOCUMENT_ROOT . '/core/lib/invoice2.lib.php';
|
require_once DOL_DOCUMENT_ROOT . '/core/lib/invoice2.lib.php';
|
||||||
|
|
||||||
|
|
||||||
// Load main language strings
|
// Load main language strings
|
||||||
$langs->load("main");
|
$langs->load("main");
|
||||||
|
|
||||||
@ -49,8 +47,6 @@ $langs->load("main");
|
|||||||
$version = DOL_VERSION;
|
$version = DOL_VERSION;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -60,8 +56,7 @@ print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
|||||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||||
|
|
||||||
// Check parameters
|
// Check parameters
|
||||||
if (! isset($argv[1]))
|
if (! isset($argv[1])) {
|
||||||
{
|
|
||||||
usage();
|
usage();
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
@ -73,38 +68,32 @@ $regenerate=''; // Ask regenerate (contains name of model to use)
|
|||||||
$option = '';
|
$option = '';
|
||||||
$fileprefix = 'mergedpdf';
|
$fileprefix = 'mergedpdf';
|
||||||
|
|
||||||
foreach ($argv as $key => $value)
|
foreach ($argv as $key => $value) {
|
||||||
{
|
|
||||||
$found = false;
|
$found = false;
|
||||||
|
|
||||||
// Define options
|
// Define options
|
||||||
if (preg_match('/^lang=/i', $value))
|
if (preg_match('/^lang=/i', $value)) {
|
||||||
{
|
|
||||||
$found = true;
|
$found = true;
|
||||||
$valarray = explode('=', $value);
|
$valarray = explode('=', $value);
|
||||||
$newlangid = $valarray[1];
|
$newlangid = $valarray[1];
|
||||||
print 'Use language ' . $newlangid . ".\n";
|
print 'Use language ' . $newlangid . ".\n";
|
||||||
}
|
}
|
||||||
if (preg_match('/^prefix=/i', $value))
|
if (preg_match('/^prefix=/i', $value)) {
|
||||||
{
|
|
||||||
$found = true;
|
$found = true;
|
||||||
$valarray = explode('=', $value);
|
$valarray = explode('=', $value);
|
||||||
$fileprefix = $valarray[1];
|
$fileprefix = $valarray[1];
|
||||||
print 'Use prefix for filename ' . $fileprefix . ".\n";
|
print 'Use prefix for filename ' . $fileprefix . ".\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preg_match('/^regenerate=(.*)/i', $value, $reg))
|
if (preg_match('/^regenerate=(.*)/i', $value, $reg)) {
|
||||||
{
|
if (! in_array($reg[1], array('','0','no'))) {
|
||||||
if (! in_array($reg[1], array('','0','no')))
|
|
||||||
{
|
|
||||||
$found = true;
|
$found = true;
|
||||||
$regenerate = $reg[1];
|
$regenerate = $reg[1];
|
||||||
print 'Regeneration of PDF is requested with template ' . $regenerate . "\n";
|
print 'Regeneration of PDF is requested with template ' . $regenerate . "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($value == 'filter=all')
|
if ($value == 'filter=all') {
|
||||||
{
|
|
||||||
$found = true;
|
$found = true;
|
||||||
$option .= (empty($option) ? '' : '_') . 'all';
|
$option .= (empty($option) ? '' : '_') . 'all';
|
||||||
$filter[] = 'all';
|
$filter[] = 'all';
|
||||||
@ -112,8 +101,7 @@ foreach ($argv as $key => $value)
|
|||||||
print 'Rebuild PDF for all invoices' . "\n";
|
print 'Rebuild PDF for all invoices' . "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($value == 'filter=date')
|
if ($value == 'filter=date') {
|
||||||
{
|
|
||||||
$found = true;
|
$found = true;
|
||||||
$option .= (empty($option) ? '' : '_') . 'date_' . $argv[$key + 1] . '_' . $argv[$key + 2];
|
$option .= (empty($option) ? '' : '_') . 'date_' . $argv[$key + 1] . '_' . $argv[$key + 2];
|
||||||
$filter[] = 'date';
|
$filter[] = 'date';
|
||||||
@ -123,24 +111,21 @@ foreach ($argv as $key => $value)
|
|||||||
print 'Rebuild PDF for invoices validated between ' . dol_print_date($dateafterdate, 'day', 'gmt') . " and " . dol_print_date($datebeforedate, 'day', 'gmt') . ".\n";
|
print 'Rebuild PDF for invoices validated between ' . dol_print_date($dateafterdate, 'day', 'gmt') . " and " . dol_print_date($datebeforedate, 'day', 'gmt') . ".\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($value == 'filter=payments')
|
if ($value == 'filter=payments') {
|
||||||
{
|
|
||||||
$found = true;
|
$found = true;
|
||||||
$option .= (empty($option) ? '' : '_') . 'payments_' . $argv[$key + 1] . '_' . $argv[$key + 2];
|
$option .= (empty($option) ? '' : '_') . 'payments_' . $argv[$key + 1] . '_' . $argv[$key + 2];
|
||||||
$filter[] = 'payments';
|
$filter[] = 'payments';
|
||||||
|
|
||||||
$paymentdateafter = dol_stringtotime($argv[$key + 1] . '000000');
|
$paymentdateafter = dol_stringtotime($argv[$key + 1] . '000000');
|
||||||
$paymentdatebefore = dol_stringtotime($argv[$key + 2] . '235959');
|
$paymentdatebefore = dol_stringtotime($argv[$key + 2] . '235959');
|
||||||
if (empty($paymentdateafter) || empty($paymentdatebefore))
|
if (empty($paymentdateafter) || empty($paymentdatebefore)) {
|
||||||
{
|
|
||||||
print 'Error: Bad date format or value' . "\n";
|
print 'Error: Bad date format or value' . "\n";
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
print 'Rebuild PDF for invoices with at least one payment between ' . dol_print_date($paymentdateafter, 'day', 'gmt') . " and " . dol_print_date($paymentdatebefore, 'day', 'gmt') . ".\n";
|
print 'Rebuild PDF for invoices with at least one payment between ' . dol_print_date($paymentdateafter, 'day', 'gmt') . " and " . dol_print_date($paymentdatebefore, 'day', 'gmt') . ".\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($value == 'filter=nopayment')
|
if ($value == 'filter=nopayment') {
|
||||||
{
|
|
||||||
$found = true;
|
$found = true;
|
||||||
$option .= (empty($option) ? '' : '_') . 'nopayment';
|
$option .= (empty($option) ? '' : '_') . 'nopayment';
|
||||||
$filter[] = 'nopayment';
|
$filter[] = 'nopayment';
|
||||||
@ -148,8 +133,7 @@ foreach ($argv as $key => $value)
|
|||||||
print 'Rebuild PDF for invoices with no payment done yet.' . "\n";
|
print 'Rebuild PDF for invoices with no payment done yet.' . "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($value == 'filter=bank')
|
if ($value == 'filter=bank') {
|
||||||
{
|
|
||||||
$found = true;
|
$found = true;
|
||||||
$option .= (empty($option) ? '' : '_') . 'bank_' . $argv[$key + 1];
|
$option .= (empty($option) ? '' : '_') . 'bank_' . $argv[$key + 1];
|
||||||
$filter[] = 'bank';
|
$filter[] = 'bank';
|
||||||
@ -157,8 +141,7 @@ foreach ($argv as $key => $value)
|
|||||||
$paymentonbankref = $argv[$key + 1];
|
$paymentonbankref = $argv[$key + 1];
|
||||||
$bankaccount = new Account($db);
|
$bankaccount = new Account($db);
|
||||||
$result = $bankaccount->fetch(0, $paymentonbankref);
|
$result = $bankaccount->fetch(0, $paymentonbankref);
|
||||||
if ($result <= 0)
|
if ($result <= 0) {
|
||||||
{
|
|
||||||
print 'Error: Bank account with ref "' . $paymentonbankref . '" not found' . "\n";
|
print 'Error: Bank account with ref "' . $paymentonbankref . '" not found' . "\n";
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
@ -166,24 +149,21 @@ foreach ($argv as $key => $value)
|
|||||||
print 'Rebuild PDF for invoices with at least one payment on financial account ' . $bankaccount->ref . "\n";
|
print 'Rebuild PDF for invoices with at least one payment on financial account ' . $bankaccount->ref . "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($value == 'filter=nodeposit')
|
if ($value == 'filter=nodeposit') {
|
||||||
{
|
|
||||||
$found = true;
|
$found = true;
|
||||||
$option .= (empty($option) ? '' : '_') . 'nodeposit';
|
$option .= (empty($option) ? '' : '_') . 'nodeposit';
|
||||||
$filter[] = 'nodeposit';
|
$filter[] = 'nodeposit';
|
||||||
|
|
||||||
print 'Exclude deposit invoices' . "\n";
|
print 'Exclude deposit invoices' . "\n";
|
||||||
}
|
}
|
||||||
if ($value == 'filter=noreplacement')
|
if ($value == 'filter=noreplacement') {
|
||||||
{
|
|
||||||
$found = true;
|
$found = true;
|
||||||
$option .= (empty($option) ? '' : '_') . 'noreplacement';
|
$option .= (empty($option) ? '' : '_') . 'noreplacement';
|
||||||
$filter[] = 'noreplacement';
|
$filter[] = 'noreplacement';
|
||||||
|
|
||||||
print 'Exclude replacement invoices' . "\n";
|
print 'Exclude replacement invoices' . "\n";
|
||||||
}
|
}
|
||||||
if ($value == 'filter=nocreditnote')
|
if ($value == 'filter=nocreditnote') {
|
||||||
{
|
|
||||||
$found = true;
|
$found = true;
|
||||||
$option .= (empty($option) ? '' : '_') . 'nocreditnote';
|
$option .= (empty($option) ? '' : '_') . 'nocreditnote';
|
||||||
$filter[] = 'nocreditnote';
|
$filter[] = 'nocreditnote';
|
||||||
@ -191,8 +171,7 @@ foreach ($argv as $key => $value)
|
|||||||
print 'Exclude credit note invoices' . "\n";
|
print 'Exclude credit note invoices' . "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($value == 'filter=excludethirdparties')
|
if ($value == 'filter=excludethirdparties') {
|
||||||
{
|
|
||||||
$found = true;
|
$found = true;
|
||||||
$filter[] = 'excludethirdparties';
|
$filter[] = 'excludethirdparties';
|
||||||
|
|
||||||
@ -201,8 +180,7 @@ foreach ($argv as $key => $value)
|
|||||||
|
|
||||||
$option .= (empty($option) ? '' : '_') . 'excludethirdparties' . join('-', $thirdpartiesid);
|
$option .= (empty($option) ? '' : '_') . 'excludethirdparties' . join('-', $thirdpartiesid);
|
||||||
}
|
}
|
||||||
if ($value == 'filter=onlythirdparties')
|
if ($value == 'filter=onlythirdparties') {
|
||||||
{
|
|
||||||
$found = true;
|
$found = true;
|
||||||
$filter[] = 'onlythirdparties';
|
$filter[] = 'onlythirdparties';
|
||||||
|
|
||||||
@ -212,47 +190,37 @@ foreach ($argv as $key => $value)
|
|||||||
$option .= (empty($option) ? '' : '_') . 'onlythirdparty' . join('-', $thirdpartiesid);
|
$option .= (empty($option) ? '' : '_') . 'onlythirdparty' . join('-', $thirdpartiesid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $found && preg_match('/filter=/i', $value))
|
if (! $found && preg_match('/filter=/i', $value)) {
|
||||||
{
|
|
||||||
usage();
|
usage();
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if an option and a filter has been provided
|
// Check if an option and a filter has been provided
|
||||||
if (empty($option) && count($filter) <= 0)
|
if (empty($option) && count($filter) <= 0) {
|
||||||
{
|
|
||||||
usage();
|
usage();
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
// Check if there is no uncompatible choice
|
// Check if there is no uncompatible choice
|
||||||
if (in_array('payments', $filter) && in_array('nopayment', $filter))
|
if (in_array('payments', $filter) && in_array('nopayment', $filter)) {
|
||||||
{
|
|
||||||
usage();
|
usage();
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
if (in_array('bank', $filter) && in_array('nopayment', $filter))
|
if (in_array('bank', $filter) && in_array('nopayment', $filter)) {
|
||||||
{
|
|
||||||
usage();
|
usage();
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Define SQL and SQL request to select invoices
|
// Define SQL and SQL request to select invoices
|
||||||
// Use $filter, $dateafterdate, datebeforedate, $paymentdateafter, $paymentdatebefore
|
// Use $filter, $dateafterdate, datebeforedate, $paymentdateafter, $paymentdatebefore
|
||||||
$result = rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, 1, $regenerate, $option, $paymentonbankid, $thirdpartiesid, $fileprefix);
|
$result = rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, 1, $regenerate, $option, $paymentonbankid, $thirdpartiesid, $fileprefix);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -------------------- END OF YOUR CODE --------------------
|
// -------------------- END OF YOUR CODE --------------------
|
||||||
|
|
||||||
if ($result >= 0)
|
if ($result >= 0) {
|
||||||
{
|
|
||||||
$error = 0;
|
$error = 0;
|
||||||
print '--- end ok' . "\n";
|
print '--- end ok' . "\n";
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$error = $result;
|
$error = $result;
|
||||||
print '--- end error code=' . $error . "\n";
|
print '--- end error code=' . $error . "\n";
|
||||||
}
|
}
|
||||||
@ -261,8 +229,6 @@ $db->close();
|
|||||||
|
|
||||||
exit($error);
|
exit($error);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show usage of script
|
* Show usage of script
|
||||||
*
|
*
|
||||||
|
|||||||
@ -23,10 +23,9 @@
|
|||||||
* \ingroup ldap member
|
* \ingroup ldap member
|
||||||
* \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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test if batch mode
|
// Test if batch mode
|
||||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||||
@ -45,7 +44,6 @@ $version=DOL_VERSION;
|
|||||||
$error = 0;
|
$error = 0;
|
||||||
$confirmed = 0;
|
$confirmed = 0;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -59,9 +57,9 @@ if (! isset($argv[1]) || ! $argv[1]) {
|
|||||||
exit(- 1);
|
exit(- 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];
|
||||||
@ -85,8 +83,7 @@ print "pass=".preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)."\n";
|
|||||||
print "DN target=" . $conf->global->LDAP_MEMBER_DN . "\n";
|
print "DN target=" . $conf->global->LDAP_MEMBER_DN . "\n";
|
||||||
print "\n";
|
print "\n";
|
||||||
|
|
||||||
if (! $confirmed)
|
if (! $confirmed) {
|
||||||
{
|
|
||||||
print "Press a key to confirm...\n";
|
print "Press a key to confirm...\n";
|
||||||
$input = trim(fgets(STDIN));
|
$input = trim(fgets(STDIN));
|
||||||
print "Warning, this operation may result in data loss if it failed.\n";
|
print "Warning, this operation may result in data loss if it failed.\n";
|
||||||
@ -96,41 +93,37 @@ if (! $confirmed)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (! $conf->global->LDAP_MEMBER_ACTIVE)
|
* if (! $conf->global->LDAP_MEMBER_ACTIVE)
|
||||||
{
|
* {
|
||||||
print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
* print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
||||||
exit(-1);
|
* exit(-1);
|
||||||
}
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sql = "SELECT rowid";
|
$sql = "SELECT rowid";
|
||||||
$sql .= " FROM " . MAIN_DB_PREFIX . "adherent";
|
$sql .= " FROM " . MAIN_DB_PREFIX . "adherent";
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
$ldap = new Ldap();
|
$ldap = new Ldap();
|
||||||
$ldap->connect_bind();
|
$ldap->connect_bind();
|
||||||
|
|
||||||
while ($i < $num)
|
while ($i < $num) {
|
||||||
{
|
|
||||||
$ldap->error = "";
|
$ldap->error = "";
|
||||||
|
|
||||||
$obj = $db->fetch_object($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
|
|
||||||
$member = new Adherent($db);
|
$member = new Adherent($db);
|
||||||
$result = $member->fetch($obj->rowid);
|
$result = $member->fetch($obj->rowid);
|
||||||
if ($result < 0)
|
if ($result < 0) {
|
||||||
{
|
|
||||||
dol_print_error($db, $member->error);
|
dol_print_error($db, $member->error);
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
$result = $member->fetch_subscriptions();
|
$result = $member->fetch_subscriptions();
|
||||||
if ($result < 0)
|
if ($result < 0) {
|
||||||
{
|
|
||||||
dol_print_error($db, $member->error);
|
dol_print_error($db, $member->error);
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
@ -147,12 +140,9 @@ if ($resql)
|
|||||||
|
|
||||||
$result = $ldap->add($dn, $info, $user); // Wil fail if already exists
|
$result = $ldap->add($dn, $info, $user); // Wil fail if already exists
|
||||||
$result = $ldap->update($dn, $info, $user, $olddn);
|
$result = $ldap->update($dn, $info, $user, $olddn);
|
||||||
if ($result > 0)
|
if ($result > 0) {
|
||||||
{
|
|
||||||
print " - " . $langs->transnoentities("OK");
|
print " - " . $langs->transnoentities("OK");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$error ++;
|
$error ++;
|
||||||
print " - " . $langs->transnoentities("KO") . ' - ' . $ldap->error;
|
print " - " . $langs->transnoentities("KO") . ' - ' . $ldap->error;
|
||||||
}
|
}
|
||||||
@ -163,9 +153,7 @@ if ($resql)
|
|||||||
|
|
||||||
$ldap->unbind();
|
$ldap->unbind();
|
||||||
$ldap->close();
|
$ldap->close();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,10 +23,9 @@
|
|||||||
* \ingroup ldap member
|
* \ingroup ldap member
|
||||||
* \brief Script de mise a jour des adherents dans Dolibarr depuis LDAP
|
* \brief Script de mise a jour des adherents dans Dolibarr depuis LDAP
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test if batch mode
|
// Test if batch mode
|
||||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||||
@ -48,7 +47,6 @@ $error=0;
|
|||||||
$forcecommit = 0;
|
$forcecommit = 0;
|
||||||
$confirmed = 0;
|
$confirmed = 0;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -58,50 +56,26 @@ print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
|||||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||||
|
|
||||||
// List of fields to get from LDAP
|
// List of fields to get from LDAP
|
||||||
$required_fields = array(
|
$required_fields = array($conf->global->LDAP_KEY_MEMBERS,$conf->global->LDAP_FIELD_FULLNAME,$conf->global->LDAP_FIELD_LOGIN,$conf->global->LDAP_FIELD_LOGIN_SAMBA,$conf->global->LDAP_FIELD_PASSWORD,$conf->global->LDAP_FIELD_PASSWORD_CRYPTED,$conf->global->LDAP_FIELD_NAME,$conf->global->LDAP_FIELD_FIRSTNAME,$conf->global->LDAP_FIELD_MAIL,$conf->global->LDAP_FIELD_PHONE,$conf->global->LDAP_FIELD_PHONE_PERSO,$conf->global->LDAP_FIELD_MOBILE,$conf->global->LDAP_FIELD_FAX,$conf->global->LDAP_FIELD_ADDRESS,$conf->global->LDAP_FIELD_ZIP,$conf->global->LDAP_FIELD_TOWN,$conf->global->LDAP_FIELD_COUNTRY,$conf->global->LDAP_FIELD_DESCRIPTION,$conf->global->LDAP_FIELD_BIRTHDATE,$conf->global->LDAP_FIELD_MEMBER_STATUS,$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION,
|
||||||
$conf->global->LDAP_KEY_MEMBERS,
|
|
||||||
$conf->global->LDAP_FIELD_FULLNAME,
|
|
||||||
$conf->global->LDAP_FIELD_LOGIN,
|
|
||||||
$conf->global->LDAP_FIELD_LOGIN_SAMBA,
|
|
||||||
$conf->global->LDAP_FIELD_PASSWORD,
|
|
||||||
$conf->global->LDAP_FIELD_PASSWORD_CRYPTED,
|
|
||||||
$conf->global->LDAP_FIELD_NAME,
|
|
||||||
$conf->global->LDAP_FIELD_FIRSTNAME,
|
|
||||||
$conf->global->LDAP_FIELD_MAIL,
|
|
||||||
$conf->global->LDAP_FIELD_PHONE,
|
|
||||||
$conf->global->LDAP_FIELD_PHONE_PERSO,
|
|
||||||
$conf->global->LDAP_FIELD_MOBILE,
|
|
||||||
$conf->global->LDAP_FIELD_FAX,
|
|
||||||
$conf->global->LDAP_FIELD_ADDRESS,
|
|
||||||
$conf->global->LDAP_FIELD_ZIP,
|
|
||||||
$conf->global->LDAP_FIELD_TOWN,
|
|
||||||
$conf->global->LDAP_FIELD_COUNTRY,
|
|
||||||
$conf->global->LDAP_FIELD_DESCRIPTION,
|
|
||||||
$conf->global->LDAP_FIELD_BIRTHDATE,
|
|
||||||
$conf->global->LDAP_FIELD_MEMBER_STATUS,
|
|
||||||
$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION,
|
|
||||||
// Subscriptions
|
// Subscriptions
|
||||||
$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE,
|
$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE,$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT,$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE,$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT);
|
||||||
$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT,
|
|
||||||
$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE,
|
|
||||||
$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT
|
|
||||||
);
|
|
||||||
|
|
||||||
// Remove from required_fields all entries not configured in LDAP (empty) and duplicated
|
// Remove from required_fields all entries not configured in LDAP (empty) and duplicated
|
||||||
$required_fields = array_unique(array_values(array_filter($required_fields, "dolValidElement")));
|
$required_fields = array_unique(array_values(array_filter($required_fields, "dolValidElement")));
|
||||||
|
|
||||||
|
|
||||||
if (! isset($argv[2]) || ! is_numeric($argv[2])) {
|
if (! isset($argv[2]) || ! is_numeric($argv[2])) {
|
||||||
print "Usage: $script_file (nocommitiferror|commitiferror) id_member_type [--server=ldapserverhost] [-y]\n";
|
print "Usage: $script_file (nocommitiferror|commitiferror) id_member_type [--server=ldapserverhost] [-y]\n";
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$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)) $conf->global->LDAP_SERVER_HOST=$reg[1];
|
if (preg_match('/--server=([^\s]+)$/', $val, $reg))
|
||||||
if (preg_match('/-y$/', $val, $reg)) $confirmed=1;
|
$conf->global->LDAP_SERVER_HOST = $reg[1];
|
||||||
|
if (preg_match('/-y$/', $val, $reg))
|
||||||
|
$confirmed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
print "Mails sending disabled (useless in batch mode)\n";
|
print "Mails sending disabled (useless in batch mode)\n";
|
||||||
@ -113,8 +87,10 @@ 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)) print 'Filter=('.$conf->global->LDAP_MEMBER_FILTER.')'."\n"; // Note: filter is defined into function getRecords
|
if (! empty($conf->global->LDAP_MEMBER_FILTER))
|
||||||
else print 'Filter=('.$conf->global->LDAP_KEY_MEMBERS.'=*)'."\n";
|
print 'Filter=(' . $conf->global->LDAP_MEMBER_FILTER . ')' . "\n"; // Note: filter is defined into function getRecords
|
||||||
|
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";
|
||||||
@ -127,20 +103,16 @@ print "Mapped LDAP fields=".join(',', $required_fields)."\n";
|
|||||||
print "\n";
|
print "\n";
|
||||||
|
|
||||||
// Check parameters
|
// Check parameters
|
||||||
if (empty($conf->global->LDAP_MEMBER_DN))
|
if (empty($conf->global->LDAP_MEMBER_DN)) {
|
||||||
{
|
|
||||||
print $langs->trans("Error") . ': ' . $langs->trans("LDAP setup for members not defined inside Dolibarr") . "\n";
|
print $langs->trans("Error") . ': ' . $langs->trans("LDAP setup for members not defined inside Dolibarr") . "\n";
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
if ($typeid <= 0)
|
if ($typeid <= 0) {
|
||||||
{
|
|
||||||
print $langs->trans("Error") . ': Parameter id_member_type is not a valid ref of an existing member type' . "\n";
|
print $langs->trans("Error") . ': Parameter id_member_type is not a valid ref of an existing member type' . "\n";
|
||||||
exit(- 2);
|
exit(- 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! $confirmed) {
|
||||||
if (! $confirmed)
|
|
||||||
{
|
|
||||||
print "Hit Enter to continue or CTRL+C to stop...\n";
|
print "Hit Enter to continue or CTRL+C to stop...\n";
|
||||||
$input = trim(fgets(STDIN));
|
$input = trim(fgets(STDIN));
|
||||||
}
|
}
|
||||||
@ -153,17 +125,13 @@ $sql.= " FROM ".MAIN_DB_PREFIX."c_country";
|
|||||||
$sql .= " WHERE active = 1";
|
$sql .= " WHERE active = 1";
|
||||||
$sql .= " ORDER BY code ASC";
|
$sql .= " ORDER BY code ASC";
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
if ($num)
|
if ($num) {
|
||||||
{
|
while ($i < $num) {
|
||||||
while ($i < $num)
|
|
||||||
{
|
|
||||||
$obj = $db->fetch_object($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
if ($obj)
|
if ($obj) {
|
||||||
{
|
|
||||||
// print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n";
|
// print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n";
|
||||||
$hashlib2rowid[strtolower($obj->label)] = $obj->rowid;
|
$hashlib2rowid[strtolower($obj->label)] = $obj->rowid;
|
||||||
$countries[$obj->rowid] = array('rowid' => $obj->rowid,'label' => $obj->label,'code' => $obj->code);
|
$countries[$obj->rowid] = array('rowid' => $obj->rowid,'label' => $obj->label,'code' => $obj->code);
|
||||||
@ -171,33 +139,25 @@ if ($resql)
|
|||||||
$i ++;
|
$i ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$ldap = new Ldap();
|
$ldap = new Ldap();
|
||||||
$result = $ldap->connect_bind();
|
$result = $ldap->connect_bind();
|
||||||
if ($result >= 0)
|
if ($result >= 0) {
|
||||||
{
|
|
||||||
$justthese = array();
|
$justthese = array();
|
||||||
|
|
||||||
|
|
||||||
// We disable synchro Dolibarr-LDAP
|
// We disable synchro Dolibarr-LDAP
|
||||||
$conf->global->LDAP_MEMBER_ACTIVE = 0;
|
$conf->global->LDAP_MEMBER_ACTIVE = 0;
|
||||||
|
|
||||||
$ldaprecords = $ldap->getRecords('*', $conf->global->LDAP_MEMBER_DN, $conf->global->LDAP_KEY_MEMBERS, $required_fields, 'member'); // Fiter on 'member' filter param
|
$ldaprecords = $ldap->getRecords('*', $conf->global->LDAP_MEMBER_DN, $conf->global->LDAP_KEY_MEMBERS, $required_fields, 'member'); // Fiter on 'member' filter param
|
||||||
if (is_array($ldaprecords))
|
if (is_array($ldaprecords)) {
|
||||||
{
|
|
||||||
$db->begin();
|
$db->begin();
|
||||||
|
|
||||||
// Warning $ldapuser has a key in lowercase
|
// Warning $ldapuser has a key in lowercase
|
||||||
foreach ($ldaprecords as $key => $ldapuser)
|
foreach ($ldaprecords as $key => $ldapuser) {
|
||||||
{
|
|
||||||
$member = new Adherent($db);
|
$member = new Adherent($db);
|
||||||
|
|
||||||
// Propriete membre
|
// Propriete membre
|
||||||
@ -226,8 +186,7 @@ if ($result >= 0)
|
|||||||
$member->birth = dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_BIRTHDATE]);
|
$member->birth = dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_BIRTHDATE]);
|
||||||
|
|
||||||
$member->statut = - 1;
|
$member->statut = - 1;
|
||||||
if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS]))
|
if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS])) {
|
||||||
{
|
|
||||||
$member->datec = dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
|
$member->datec = dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
|
||||||
$member->datevalid = dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
|
$member->datevalid = dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
|
||||||
$member->statut = $ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS];
|
$member->statut = $ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS];
|
||||||
@ -243,12 +202,9 @@ if ($result >= 0)
|
|||||||
print $langs->transnoentities("MemberCreate") . ' # ' . $key . ': login=' . $member->login . ', fullname=' . $member->getFullName($langs);
|
print $langs->transnoentities("MemberCreate") . ' # ' . $key . ': login=' . $member->login . ', fullname=' . $member->getFullName($langs);
|
||||||
print ', datec=' . $member->datec;
|
print ', datec=' . $member->datec;
|
||||||
$member_id = $member->create($user);
|
$member_id = $member->create($user);
|
||||||
if ($member_id > 0)
|
if ($member_id > 0) {
|
||||||
{
|
|
||||||
print ' --> Created member id=' . $member_id . ' login=' . $member->login;
|
print ' --> Created member id=' . $member_id . ' login=' . $member->login;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$error ++;
|
$error ++;
|
||||||
print ' --> ' . $member->error;
|
print ' --> ' . $member->error;
|
||||||
}
|
}
|
||||||
@ -257,83 +213,70 @@ if ($result >= 0)
|
|||||||
// print_r($member);
|
// print_r($member);
|
||||||
|
|
||||||
$datefirst = '';
|
$datefirst = '';
|
||||||
if ($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE)
|
if ($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE) {
|
||||||
{
|
|
||||||
$datefirst = dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
|
$datefirst = dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
|
||||||
$pricefirst = price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT]);
|
$pricefirst = price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$datelast = '';
|
$datelast = '';
|
||||||
if ($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE)
|
if ($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE) {
|
||||||
{
|
|
||||||
$datelast = dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE]);
|
$datelast = dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE]);
|
||||||
$pricelast = price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]);
|
$pricelast = price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]);
|
||||||
}
|
} elseif ($conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION) {
|
||||||
elseif ($conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION)
|
|
||||||
{
|
|
||||||
$datelast = dol_time_plus_duree(dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION]), - 1, 'y') + 60 * 60 * 24;
|
$datelast = dol_time_plus_duree(dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION]), - 1, 'y') + 60 * 60 * 24;
|
||||||
$pricelast = price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]);
|
$pricelast = price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]);
|
||||||
|
|
||||||
// Cas special ou date derniere <= date premiere
|
// Cas special ou date derniere <= date premiere
|
||||||
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) $pricefirst = $pricelast;
|
if (! $pricefirst && $pricelast)
|
||||||
|
$pricefirst = $pricelast;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Insert first subscription
|
// Insert first subscription
|
||||||
if ($datefirst)
|
if ($datefirst) {
|
||||||
{
|
|
||||||
// Cree premiere cotisation et met a jour datefin dans adherent
|
// Cree premiere cotisation et met a jour datefin dans adherent
|
||||||
// print "xx".$datefirst."\n";
|
// print "xx".$datefirst."\n";
|
||||||
$crowid = $member->subscription($datefirst, $pricefirst, 0);
|
$crowid = $member->subscription($datefirst, $pricefirst, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert last subscription
|
// Insert last subscription
|
||||||
if ($datelast)
|
if ($datelast) {
|
||||||
{
|
|
||||||
// Cree derniere cotisation et met a jour datefin dans adherent
|
// Cree derniere cotisation et met a jour datefin dans adherent
|
||||||
// print "yy".dol_print_date($datelast)."\n";
|
// print "yy".dol_print_date($datelast)."\n";
|
||||||
$crowid = $member->subscription($datelast, $pricelast, 0);
|
$crowid = $member->subscription($datelast, $pricelast, 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";
|
|
||||||
$db->commit();
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
print $langs->transnoentities("ErrorButCommitIsDone") . "\n";
|
||||||
|
$db->commit();
|
||||||
|
} else {
|
||||||
print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error) . "\n";
|
print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error) . "\n";
|
||||||
$db->rollback();
|
$db->rollback();
|
||||||
}
|
}
|
||||||
print "\n";
|
print "\n";
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error('', $ldap->error);
|
dol_print_error('', $ldap->error);
|
||||||
$error ++;
|
$error ++;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error('', $ldap->error);
|
dol_print_error('', $ldap->error);
|
||||||
$error ++;
|
$error ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
exit($error);
|
exit($error);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to say if a value is empty or not
|
* Function to say if a value is empty or not
|
||||||
*
|
*
|
||||||
* @param string $element Value to test
|
* @param string $element
|
||||||
|
* Value to test
|
||||||
* @return boolean True of false
|
* @return boolean True of false
|
||||||
*/
|
*/
|
||||||
function dolValidElement($element)
|
function dolValidElement($element)
|
||||||
|
|||||||
@ -24,10 +24,9 @@
|
|||||||
* \ingroup ldap core
|
* \ingroup ldap core
|
||||||
* \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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test if batch mode
|
// Test if batch mode
|
||||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||||
@ -49,7 +48,6 @@ require_once DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php";
|
|||||||
$version = DOL_VERSION;
|
$version = DOL_VERSION;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -59,29 +57,26 @@ print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
|||||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
|
* if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
|
||||||
{
|
* {
|
||||||
print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
* print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
||||||
exit(-1);
|
* exit(-1);
|
||||||
}
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sql = "SELECT rowid";
|
$sql = "SELECT rowid";
|
||||||
$sql .= " FROM " . MAIN_DB_PREFIX . "adherent_type";
|
$sql .= " FROM " . MAIN_DB_PREFIX . "adherent_type";
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
$ldap = new Ldap();
|
$ldap = new Ldap();
|
||||||
$result = $ldap->connect_bind();
|
$result = $ldap->connect_bind();
|
||||||
|
|
||||||
if ($result > 0)
|
if ($result > 0) {
|
||||||
{
|
while ($i < $num) {
|
||||||
while ($i < $num)
|
|
||||||
{
|
|
||||||
$ldap->error = "";
|
$ldap->error = "";
|
||||||
|
|
||||||
$obj = $db->fetch_object($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
@ -102,12 +97,9 @@ if ($resql)
|
|||||||
|
|
||||||
$result = $ldap->add($dn, $info, $user); // Wil fail if already exists
|
$result = $ldap->add($dn, $info, $user); // Wil fail if already exists
|
||||||
$result = $ldap->update($dn, $info, $user, $olddn);
|
$result = $ldap->update($dn, $info, $user, $olddn);
|
||||||
if ($result > 0)
|
if ($result > 0) {
|
||||||
{
|
|
||||||
print " - " . $langs->trans("OK");
|
print " - " . $langs->trans("OK");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$error ++;
|
$error ++;
|
||||||
print " - " . $langs->trans("KO") . ' - ' . $ldap->error;
|
print " - " . $langs->trans("KO") . ' - ' . $ldap->error;
|
||||||
}
|
}
|
||||||
@ -118,13 +110,10 @@ if ($resql)
|
|||||||
|
|
||||||
$ldap->unbind();
|
$ldap->unbind();
|
||||||
$ldap->close();
|
$ldap->close();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
print $ldap->error;
|
print $ldap->error;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -25,10 +25,9 @@
|
|||||||
* \ingroup ldap member
|
* \ingroup ldap member
|
||||||
* \brief Script to update members types into Dolibarr from LDAP
|
* \brief Script to update members types into Dolibarr from LDAP
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test if batch mode
|
// Test if batch mode
|
||||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||||
@ -49,7 +48,6 @@ $error=0;
|
|||||||
$forcecommit = 0;
|
$forcecommit = 0;
|
||||||
$confirmed = 0;
|
$confirmed = 0;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -59,29 +57,26 @@ print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
|||||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||||
|
|
||||||
// List of fields to get from LDAP
|
// List of fields to get from LDAP
|
||||||
$required_fields = array(
|
$required_fields = array($conf->global->LDAP_KEY_MEMBERS_TYPES,$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME,$conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION,$conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS);
|
||||||
$conf->global->LDAP_KEY_MEMBERS_TYPES,
|
|
||||||
$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME,
|
|
||||||
$conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION,
|
|
||||||
$conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS
|
|
||||||
);
|
|
||||||
|
|
||||||
// Remove from required_fields all entries not configured in LDAP (empty) and duplicated
|
// Remove from required_fields all entries not configured in LDAP (empty) and duplicated
|
||||||
$required_fields = array_unique(array_values(array_filter($required_fields, "dolValidElementType")));
|
$required_fields = array_unique(array_values(array_filter($required_fields, "dolValidElementType")));
|
||||||
|
|
||||||
|
|
||||||
if (! isset($argv[1])) {
|
if (! isset($argv[1])) {
|
||||||
// print "Usage: $script_file (nocommitiferror|commitiferror) [id_group]\n";
|
// print "Usage: $script_file (nocommitiferror|commitiferror) [id_group]\n";
|
||||||
print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n";
|
print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n";
|
||||||
exit(- 1);
|
exit(- 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)) $conf->global->LDAP_SERVER_HOST=$reg[1];
|
if (preg_match('/--server=([^\s]+)$/', $val, $reg))
|
||||||
if (preg_match('/--excludeuser=([^\s]+)$/', $val, $reg)) $excludeuser=explode(',', $reg[1]);
|
$conf->global->LDAP_SERVER_HOST = $reg[1];
|
||||||
if (preg_match('/-y$/', $val, $reg)) $confirmed=1;
|
if (preg_match('/--excludeuser=([^\s]+)$/', $val, $reg))
|
||||||
|
$excludeuser = explode(',', $reg[1]);
|
||||||
|
if (preg_match('/-y$/', $val, $reg))
|
||||||
|
$confirmed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
print "Mails sending disabled (useless in batch mode)\n";
|
print "Mails sending disabled (useless in batch mode)\n";
|
||||||
@ -105,37 +100,30 @@ print "commitiferror=".$forcecommit."\n";
|
|||||||
print "Mapped LDAP fields=" . join(',', $required_fields) . "\n";
|
print "Mapped LDAP fields=" . join(',', $required_fields) . "\n";
|
||||||
print "\n";
|
print "\n";
|
||||||
|
|
||||||
if (! $confirmed)
|
if (! $confirmed) {
|
||||||
{
|
|
||||||
print "Hit Enter to continue or CTRL+C to stop...\n";
|
print "Hit Enter to continue or CTRL+C to stop...\n";
|
||||||
$input = trim(fgets(STDIN));
|
$input = trim(fgets(STDIN));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($conf->global->LDAP_MEMBER_TYPE_DN))
|
if (empty($conf->global->LDAP_MEMBER_TYPE_DN)) {
|
||||||
{
|
|
||||||
print $langs->trans("Error") . ': ' . $langs->trans("LDAP setup for members types not defined inside Dolibarr");
|
print $langs->trans("Error") . ': ' . $langs->trans("LDAP setup for members types not defined inside Dolibarr");
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$ldap = new Ldap();
|
$ldap = new Ldap();
|
||||||
$result = $ldap->connect_bind();
|
$result = $ldap->connect_bind();
|
||||||
if ($result >= 0)
|
if ($result >= 0) {
|
||||||
{
|
|
||||||
$justthese = array();
|
$justthese = array();
|
||||||
|
|
||||||
|
|
||||||
// We disable synchro Dolibarr-LDAP
|
// We disable synchro Dolibarr-LDAP
|
||||||
$conf->global->LDAP_MEMBER_TYPE_ACTIVE = 0;
|
$conf->global->LDAP_MEMBER_TYPE_ACTIVE = 0;
|
||||||
|
|
||||||
$ldaprecords = $ldap->getRecords('*', $conf->global->LDAP_MEMBER_TYPE_DN, $conf->global->LDAP_KEY_MEMBERS_TYPES, $required_fields, 0, array($conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS));
|
$ldaprecords = $ldap->getRecords('*', $conf->global->LDAP_MEMBER_TYPE_DN, $conf->global->LDAP_KEY_MEMBERS_TYPES, $required_fields, 0, array($conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS));
|
||||||
if (is_array($ldaprecords))
|
if (is_array($ldaprecords)) {
|
||||||
{
|
|
||||||
$db->begin();
|
$db->begin();
|
||||||
|
|
||||||
// Warning $ldapuser has a key in lowercase
|
// Warning $ldapuser has a key in lowercase
|
||||||
foreach ($ldaprecords as $key => $ldapgroup)
|
foreach ($ldaprecords as $key => $ldapgroup) {
|
||||||
{
|
|
||||||
$membertype = new AdherentType($db);
|
$membertype = new AdherentType($db);
|
||||||
$membertype->fetch('', $ldapgroup[$conf->global->LDAP_KEY_MEMBERS_TYPES]);
|
$membertype->fetch('', $ldapgroup[$conf->global->LDAP_KEY_MEMBERS_TYPES]);
|
||||||
$membertype->label = $ldapgroup[$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME];
|
$membertype->label = $ldapgroup[$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME];
|
||||||
@ -148,12 +136,9 @@ if ($result >= 0)
|
|||||||
print $langs->transnoentities("MemberTypeUpdate") . ' # ' . $key . ': name=' . $membertype->label;
|
print $langs->transnoentities("MemberTypeUpdate") . ' # ' . $key . ': name=' . $membertype->label;
|
||||||
$res = $membertype->update($user);
|
$res = $membertype->update($user);
|
||||||
|
|
||||||
if ($res > 0)
|
if ($res > 0) {
|
||||||
{
|
|
||||||
print ' --> Updated member type id=' . $membertype->id . ' name=' . $membertype->label;
|
print ' --> Updated member type id=' . $membertype->id . ' name=' . $membertype->label;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$error ++;
|
$error ++;
|
||||||
print ' --> ' . $res . ' ' . $membertype->error;
|
print ' --> ' . $res . ' ' . $membertype->error;
|
||||||
}
|
}
|
||||||
@ -162,12 +147,9 @@ if ($result >= 0)
|
|||||||
print $langs->transnoentities("MemberTypeCreate") . ' # ' . $key . ': name=' . $membertype->label;
|
print $langs->transnoentities("MemberTypeCreate") . ' # ' . $key . ': name=' . $membertype->label;
|
||||||
$res = $membertype->create($user);
|
$res = $membertype->create($user);
|
||||||
|
|
||||||
if ($res > 0)
|
if ($res > 0) {
|
||||||
{
|
|
||||||
print ' --> Created member type id=' . $membertype->id . ' name=' . $membertype->label;
|
print ' --> Created member type id=' . $membertype->id . ' name=' . $membertype->label;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$error ++;
|
$error ++;
|
||||||
print ' --> ' . $res . ' ' . $membertype->error;
|
print ' --> ' . $res . ' ' . $membertype->error;
|
||||||
}
|
}
|
||||||
@ -177,39 +159,33 @@ if ($result >= 0)
|
|||||||
// print_r($membertype);
|
// print_r($membertype);
|
||||||
}
|
}
|
||||||
|
|
||||||
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";
|
|
||||||
$db->commit();
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
print $langs->transnoentities("ErrorButCommitIsDone") . "\n";
|
||||||
|
$db->commit();
|
||||||
|
} else {
|
||||||
print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error) . "\n";
|
print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error) . "\n";
|
||||||
$db->rollback();
|
$db->rollback();
|
||||||
}
|
}
|
||||||
print "\n";
|
print "\n";
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error('', $ldap->error);
|
dol_print_error('', $ldap->error);
|
||||||
$error ++;
|
$error ++;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error('', $ldap->error);
|
dol_print_error('', $ldap->error);
|
||||||
$error ++;
|
$error ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
exit($error);
|
exit($error);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to say if a value is empty or not
|
* Function to say if a value is empty or not
|
||||||
*
|
*
|
||||||
* @param string $element Value to test
|
* @param string $element
|
||||||
|
* Value to test
|
||||||
* @return boolean True of false
|
* @return boolean True of false
|
||||||
*/
|
*/
|
||||||
function dolValidElementType($element)
|
function dolValidElementType($element)
|
||||||
|
|||||||
@ -17,21 +17,19 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file scripts/modulebuilder/builddoc.php
|
* \file scripts/modulebuilder/builddoc.php
|
||||||
* \ingroup modulebuilder
|
* \ingroup modulebuilder
|
||||||
* \brief Script to build a documentation from input files (.asciidoc or .md files). Use asciidoctor tool.
|
* \brief Script to build a documentation from input files (.asciidoc or .md files).
|
||||||
|
* Use asciidoctor tool.
|
||||||
*
|
*
|
||||||
* If file is a MD file, convert image links into asciidoc format.
|
* If file is a MD file, convert image links into asciidoc format.
|
||||||
* 
|
* 
|
||||||
* image:img/dolimed_screenshot_patientcard.png[Screenshot patient card]
|
* image:img/dolimed_screenshot_patientcard.png[Screenshot patient card]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test if batch mode
|
// Test if batch mode
|
||||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||||
@ -55,7 +53,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
|
|||||||
|
|
||||||
$langs->loadLangs(array("admin","modulebuilder","other","cron"));
|
$langs->loadLangs(array("admin","modulebuilder","other","cron"));
|
||||||
|
|
||||||
|
|
||||||
// Global variables
|
// Global variables
|
||||||
$version = DOL_VERSION;
|
$version = DOL_VERSION;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
@ -67,8 +64,7 @@ $dirread = $dirins;
|
|||||||
$forceddirread = 0;
|
$forceddirread = 0;
|
||||||
|
|
||||||
$tmpdir = explode('@', $module);
|
$tmpdir = explode('@', $module);
|
||||||
if (! empty($tmpdir[1]))
|
if (! empty($tmpdir[1])) {
|
||||||
{
|
|
||||||
$module = $tmpdir[0];
|
$module = $tmpdir[0];
|
||||||
$dirread = $tmpdir[1];
|
$dirread = $tmpdir[1];
|
||||||
$forceddirread = 1;
|
$forceddirread = 1;
|
||||||
@ -78,13 +74,13 @@ $FILEFLAG='modulebuilder.txt';
|
|||||||
|
|
||||||
$now = dol_now();
|
$now = dol_now();
|
||||||
$newmask = 0;
|
$newmask = 0;
|
||||||
if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
|
if (empty($newmask) && ! empty($conf->global->MAIN_UMASK))
|
||||||
|
$newmask = $conf->global->MAIN_UMASK;
|
||||||
if (empty($newmask)) // This should no happen
|
if (empty($newmask)) // This should no happen
|
||||||
{
|
{
|
||||||
$newmask = '0664';
|
$newmask = '0664';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -101,8 +97,7 @@ $outputfiledoc = $dirofmodule.'/'.$FILENAMEDOC;
|
|||||||
$util = new Utils($db);
|
$util = new Utils($db);
|
||||||
$result = $util->generateDoc($module);
|
$result = $util->generateDoc($module);
|
||||||
|
|
||||||
if ($result <= 0)
|
if ($result <= 0) {
|
||||||
{
|
|
||||||
print $util->errors;
|
print $util->errors;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,17 +17,14 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file scripts/modulebuilder/initmodule.php
|
* \file scripts/modulebuilder/initmodule.php
|
||||||
* \ingroup modulebuilder
|
* \ingroup modulebuilder
|
||||||
* \brief Script to initialize a module.
|
* \brief Script to initialize a module.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test if batch mode
|
// Test if batch mode
|
||||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||||
@ -50,7 +47,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
|
|||||||
|
|
||||||
$langs->loadLangs(array("admin","modulebuilder","other","cron"));
|
$langs->loadLangs(array("admin","modulebuilder","other","cron"));
|
||||||
|
|
||||||
|
|
||||||
// Global variables
|
// Global variables
|
||||||
$version = DOL_VERSION;
|
$version = DOL_VERSION;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
@ -62,8 +58,7 @@ $dirread = $dirins;
|
|||||||
$forceddirread = 0;
|
$forceddirread = 0;
|
||||||
|
|
||||||
$tmpdir = explode('@', $module);
|
$tmpdir = explode('@', $module);
|
||||||
if (! empty($tmpdir[1]))
|
if (! empty($tmpdir[1])) {
|
||||||
{
|
|
||||||
$module = $tmpdir[0];
|
$module = $tmpdir[0];
|
||||||
$dirread = $tmpdir[1];
|
$dirread = $tmpdir[1];
|
||||||
$forceddirread = 1;
|
$forceddirread = 1;
|
||||||
@ -73,13 +68,13 @@ $FILEFLAG='modulebuilder.txt';
|
|||||||
|
|
||||||
$now = dol_now();
|
$now = dol_now();
|
||||||
$newmask = 0;
|
$newmask = 0;
|
||||||
if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
|
if (empty($newmask) && ! empty($conf->global->MAIN_UMASK))
|
||||||
|
$newmask = $conf->global->MAIN_UMASK;
|
||||||
if (empty($newmask)) // This should no happen
|
if (empty($newmask)) // This should no happen
|
||||||
{
|
{
|
||||||
$newmask = '0664';
|
$newmask = '0664';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -89,35 +84,27 @@ print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
|||||||
print "modulename=" . $modulename . "\n";
|
print "modulename=" . $modulename . "\n";
|
||||||
print "dirins=" . $dirins . "\n";
|
print "dirins=" . $dirins . "\n";
|
||||||
|
|
||||||
if (preg_match('/[^a-z0-9_]/i', $modulename))
|
if (preg_match('/[^a-z0-9_]/i', $modulename)) {
|
||||||
{
|
|
||||||
$error ++;
|
$error ++;
|
||||||
print 'Error ' . $langs->trans("SpaceOrSpecialCharAreNotAllowed") . "\n";
|
print 'Error ' . $langs->trans("SpaceOrSpecialCharAreNotAllowed") . "\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error)
|
if (! $error) {
|
||||||
{
|
|
||||||
$srcdir = DOL_DOCUMENT_ROOT . '/modulebuilder/template';
|
$srcdir = DOL_DOCUMENT_ROOT . '/modulebuilder/template';
|
||||||
$destdir = $dirins . '/' . strtolower($modulename);
|
$destdir = $dirins . '/' . strtolower($modulename);
|
||||||
|
|
||||||
$arrayreplacement=array(
|
$arrayreplacement = array('mymodule' => strtolower($modulename),'MyModule' => $modulename);
|
||||||
'mymodule'=>strtolower($modulename),
|
|
||||||
'MyModule'=>$modulename
|
|
||||||
);
|
|
||||||
|
|
||||||
$result = dolCopyDir($srcdir, $destdir, 0, 0, $arrayreplacement);
|
$result = dolCopyDir($srcdir, $destdir, 0, 0, $arrayreplacement);
|
||||||
// dol_mkdir($destfile);
|
// dol_mkdir($destfile);
|
||||||
if ($result <= 0)
|
if ($result <= 0) {
|
||||||
{
|
if ($result < 0) {
|
||||||
if ($result < 0)
|
|
||||||
{
|
|
||||||
$error ++;
|
$error ++;
|
||||||
$langs->load("errors");
|
$langs->load("errors");
|
||||||
print $langs->trans("ErrorFailToCopyDir", $srcdir, $destdir) . "\n";
|
print $langs->trans("ErrorFailToCopyDir", $srcdir, $destdir) . "\n";
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
} else // $result == 0
|
||||||
else // $result == 0
|
|
||||||
{
|
{
|
||||||
print $langs->trans("AllFilesDidAlreadyExist", $srcdir, $destdir) . "\n";
|
print $langs->trans("AllFilesDidAlreadyExist", $srcdir, $destdir) . "\n";
|
||||||
}
|
}
|
||||||
@ -141,29 +128,15 @@ if (! $error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Edit PHP files
|
// Edit PHP files
|
||||||
if (! $error)
|
if (! $error) {
|
||||||
{
|
|
||||||
$listofphpfilestoedit = dol_dir_list($destdir, 'files', 1, '\.(php|MD|js|sql|txt|xml|lang)$', '', 'fullname', SORT_ASC, 0, 1);
|
$listofphpfilestoedit = dol_dir_list($destdir, 'files', 1, '\.(php|MD|js|sql|txt|xml|lang)$', '', 'fullname', SORT_ASC, 0, 1);
|
||||||
foreach($listofphpfilestoedit as $phpfileval)
|
foreach ($listofphpfilestoedit as $phpfileval) {
|
||||||
{
|
|
||||||
// var_dump($phpfileval['fullname']);
|
// var_dump($phpfileval['fullname']);
|
||||||
$arrayreplacement=array(
|
$arrayreplacement = array('mymodule' => strtolower($modulename),'MyModule' => $modulename,'MYMODULE' => strtoupper($modulename),'My module' => $modulename,'my module' => $modulename,'Mon module' => $modulename,'mon module' => $modulename,'htdocs/modulebuilder/template' => strtolower($modulename),'---Put here your own copyright and developer email---' => dol_print_date($now, '%Y') . ' ' . $user->getFullName($langs) . ($user->email ? ' <' . $user->email . '>' : ''));
|
||||||
'mymodule'=>strtolower($modulename),
|
|
||||||
'MyModule'=>$modulename,
|
|
||||||
'MYMODULE'=>strtoupper($modulename),
|
|
||||||
'My module'=>$modulename,
|
|
||||||
'my module'=>$modulename,
|
|
||||||
'Mon module'=>$modulename,
|
|
||||||
'mon module'=>$modulename,
|
|
||||||
'htdocs/modulebuilder/template'=>strtolower($modulename),
|
|
||||||
'---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email?' <'.$user->email.'>':'')
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
$result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
|
$result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
|
||||||
// var_dump($result);
|
// var_dump($result);
|
||||||
if ($result < 0)
|
if ($result < 0) {
|
||||||
{
|
|
||||||
print $langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']) . "\n";
|
print $langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']) . "\n";
|
||||||
exit(3);
|
exit(3);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env php
|
#!/usr/bin/env php
|
||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2007-2016 Laurent Destailleur <eldy@users.sourceforge.net>
|
/*
|
||||||
|
* Copyright (C) 2007-2016 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* Copyright (C) 2015 Jean Heimburger <http://tiaris.eu>
|
* Copyright (C) 2015 Jean Heimburger <http://tiaris.eu>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -22,10 +23,9 @@
|
|||||||
* \ingroup scripts
|
* \ingroup scripts
|
||||||
* \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+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test if batch mode
|
// Test if batch mode
|
||||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||||
@ -46,13 +46,11 @@ require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
|
|||||||
// $langs->setDefaultLang('en_US'); // To change default language of $langs
|
// $langs->setDefaultLang('en_US'); // To change default language of $langs
|
||||||
$langs->load("main"); // To load language file for default language
|
$langs->load("main"); // To load language file for default language
|
||||||
|
|
||||||
|
|
||||||
// Global variables
|
// Global variables
|
||||||
$version = DOL_VERSION;
|
$version = DOL_VERSION;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
$forcecommit = 0;
|
$forcecommit = 0;
|
||||||
|
|
||||||
|
|
||||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||||
|
|
||||||
@ -64,39 +62,32 @@ if (! isset($argv[1]) || $argv[1] != 'product') {
|
|||||||
print '--- start' . "\n";
|
print '--- start' . "\n";
|
||||||
|
|
||||||
// Case to migrate products path
|
// Case to migrate products path
|
||||||
if ($argv[1] == 'product')
|
if ($argv[1] == 'product') {
|
||||||
{
|
|
||||||
$product = new Product($db);
|
$product = new Product($db);
|
||||||
|
|
||||||
$sql = "SELECT rowid as pid from " . MAIN_DB_PREFIX . "product"; // Get list of all products
|
$sql = "SELECT rowid as pid from " . MAIN_DB_PREFIX . "product"; // Get list of all products
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
while ($obj = $db->fetch_object($resql)) {
|
||||||
while ($obj = $db->fetch_object($resql))
|
|
||||||
{
|
|
||||||
$product->fetch($obj->pid);
|
$product->fetch($obj->pid);
|
||||||
print " migrating product id=" . $product->id . " ref=" . $product->ref . "\n";
|
print " migrating product id=" . $product->id . " ref=" . $product->ref . "\n";
|
||||||
migrate_product_photospath($product);
|
migrate_product_photospath($product);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
print "\n sql error " . $sql;
|
print "\n sql error " . $sql;
|
||||||
exit;
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$db->close(); // Close $db database opened handler
|
$db->close(); // Close $db database opened handler
|
||||||
|
|
||||||
exit($error);
|
exit($error);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Migrate file from old path to new one for product $product
|
* Migrate file from old path to new one for product $product
|
||||||
*
|
*
|
||||||
* @param Product $product Object product
|
* @param Product $product
|
||||||
|
* Object product
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function migrate_product_photospath($product)
|
function migrate_product_photospath($product)
|
||||||
@ -114,30 +105,21 @@ function migrate_product_photospath($product)
|
|||||||
$destin_osencoded = dol_osencode($destin);
|
$destin_osencoded = dol_osencode($destin);
|
||||||
dol_mkdir($destin);
|
dol_mkdir($destin);
|
||||||
|
|
||||||
if (dol_is_dir($origin))
|
if (dol_is_dir($origin)) {
|
||||||
{
|
|
||||||
$handle = opendir($origin_osencoded);
|
$handle = opendir($origin_osencoded);
|
||||||
if (is_resource($handle))
|
if (is_resource($handle)) {
|
||||||
{
|
while (($file = readdir($handle)) !== false) {
|
||||||
while (($file = readdir($handle)) !== false)
|
if ($file != '.' && $file != '..' && is_dir($origin_osencoded . '/' . $file)) {
|
||||||
{
|
|
||||||
if ($file != '.' && $file != '..' && is_dir($origin_osencoded.'/'.$file))
|
|
||||||
{
|
|
||||||
$thumbs = opendir($origin_osencoded . '/' . $file);
|
$thumbs = opendir($origin_osencoded . '/' . $file);
|
||||||
if (is_resource($thumbs))
|
if (is_resource($thumbs)) {
|
||||||
{
|
|
||||||
dol_mkdir($destin . '/' . $file);
|
dol_mkdir($destin . '/' . $file);
|
||||||
while (($thumb = readdir($thumbs)) !== false)
|
while (($thumb = readdir($thumbs)) !== false) {
|
||||||
{
|
|
||||||
dol_move($origin . '/' . $file . '/' . $thumb, $destin . '/' . $file . '/' . $thumb);
|
dol_move($origin . '/' . $file . '/' . $thumb, $destin . '/' . $file . '/' . $thumb);
|
||||||
}
|
}
|
||||||
// dol_delete_dir($origin.'/'.$file);
|
// dol_delete_dir($origin.'/'.$file);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
if (dol_is_file($origin . '/' . $file)) {
|
||||||
{
|
|
||||||
if (dol_is_file($origin.'/'.$file) )
|
|
||||||
{
|
|
||||||
dol_move($origin . '/' . $file, $destin . '/' . $file);
|
dol_move($origin . '/' . $file, $destin . '/' . $file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env php
|
#!/usr/bin/env php
|
||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2007-2016 Laurent Destailleur <eldy@users.sourceforge.net>
|
/*
|
||||||
|
* Copyright (C) 2007-2016 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* Copyright (C) 2015 Jean Heimburger <http://tiaris.eu>
|
* Copyright (C) 2015 Jean Heimburger <http://tiaris.eu>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -22,10 +23,9 @@
|
|||||||
* \ingroup scripts
|
* \ingroup scripts
|
||||||
* \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+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test if batch mode
|
// Test if batch mode
|
||||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||||
@ -47,13 +47,11 @@ require_once DOL_DOCUMENT_ROOT."/core/lib/images.lib.php";
|
|||||||
// $langs->setDefaultLang('en_US'); // To change default language of $langs
|
// $langs->setDefaultLang('en_US'); // To change default language of $langs
|
||||||
$langs->load("main"); // To load language file for default language
|
$langs->load("main"); // To load language file for default language
|
||||||
|
|
||||||
|
|
||||||
// Global variables
|
// Global variables
|
||||||
$version = DOL_VERSION;
|
$version = DOL_VERSION;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
$forcecommit = 0;
|
$forcecommit = 0;
|
||||||
|
|
||||||
|
|
||||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||||
|
|
||||||
@ -67,13 +65,11 @@ print '--- start'."\n";
|
|||||||
|
|
||||||
$dir = DOL_DATA_ROOT;
|
$dir = DOL_DATA_ROOT;
|
||||||
$subdir = $argv[1];
|
$subdir = $argv[1];
|
||||||
if (empty($dir) || empty($subdir))
|
if (empty($dir) || empty($subdir)) {
|
||||||
{
|
|
||||||
dol_print_error('', 'dir not defined');
|
dol_print_error('', 'dir not defined');
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (! dol_is_dir($dir.'/'.$subdir))
|
if (! dol_is_dir($dir . '/' . $subdir)) {
|
||||||
{
|
|
||||||
print 'Directory ' . $dir . '/' . $subdir . ' not found.' . "\n";
|
print 'Directory ' . $dir . '/' . $subdir . ' not found.' . "\n";
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
@ -82,23 +78,23 @@ $filearray=dol_dir_list($dir.'/'.$subdir, "directories", 0, '', 'temp$');
|
|||||||
|
|
||||||
global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini;
|
global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini;
|
||||||
|
|
||||||
foreach($filearray as $keyf => $valf)
|
foreach ($filearray as $keyf => $valf) {
|
||||||
{
|
|
||||||
$ref = basename($valf['name']);
|
$ref = basename($valf['name']);
|
||||||
$filearrayimg = dol_dir_list($valf['fullname'], "files", 0, '(\.gif|\.png|\.jpg|\.jpeg|\.bmp)$', '(\.meta|_preview.*\.png)$');
|
$filearrayimg = dol_dir_list($valf['fullname'], "files", 0, '(\.gif|\.png|\.jpg|\.jpeg|\.bmp)$', '(\.meta|_preview.*\.png)$');
|
||||||
foreach($filearrayimg as $keyi => $vali)
|
foreach ($filearrayimg as $keyi => $vali) {
|
||||||
{
|
|
||||||
print 'Process image for ref ' . $ref . ' : ' . $vali['name'] . "\n";
|
print 'Process image for ref ' . $ref . ' : ' . $vali['name'] . "\n";
|
||||||
|
|
||||||
// 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)) print $imgThumbSmall."\n";
|
if (preg_match('/Error/', $imgThumbSmall))
|
||||||
|
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)) print $imgThumbMini."\n";
|
if (preg_match('/Error/', $imgThumbMini))
|
||||||
|
print $imgThumbMini . "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,10 +23,9 @@
|
|||||||
* \ingroup ldap core
|
* \ingroup ldap core
|
||||||
* \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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test if batch mode
|
// Test if batch mode
|
||||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||||
@ -48,7 +47,6 @@ require_once DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php";
|
|||||||
$version = DOL_VERSION;
|
$version = DOL_VERSION;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -58,27 +56,25 @@ print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
|||||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
|
* if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
|
||||||
{
|
* {
|
||||||
print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
* print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
||||||
exit(-1);
|
* exit(-1);
|
||||||
}
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sql = "SELECT rowid";
|
$sql = "SELECT rowid";
|
||||||
$sql .= " FROM " . MAIN_DB_PREFIX . "usergroup";
|
$sql .= " FROM " . MAIN_DB_PREFIX . "usergroup";
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
$ldap = new Ldap();
|
$ldap = new Ldap();
|
||||||
$ldap->connect_bind();
|
$ldap->connect_bind();
|
||||||
|
|
||||||
while ($i < $num)
|
while ($i < $num) {
|
||||||
{
|
|
||||||
$ldap->error = "";
|
$ldap->error = "";
|
||||||
|
|
||||||
$obj = $db->fetch_object($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
@ -99,12 +95,9 @@ if ($resql)
|
|||||||
|
|
||||||
$result = $ldap->add($dn, $info, $user); // Wil fail if already exists
|
$result = $ldap->add($dn, $info, $user); // Wil fail if already exists
|
||||||
$result = $ldap->update($dn, $info, $user, $olddn);
|
$result = $ldap->update($dn, $info, $user, $olddn);
|
||||||
if ($result > 0)
|
if ($result > 0) {
|
||||||
{
|
|
||||||
print " - " . $langs->trans("OK");
|
print " - " . $langs->trans("OK");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$error ++;
|
$error ++;
|
||||||
print " - " . $langs->trans("KO") . ' - ' . $ldap->error;
|
print " - " . $langs->trans("KO") . ' - ' . $ldap->error;
|
||||||
}
|
}
|
||||||
@ -115,9 +108,7 @@ if ($resql)
|
|||||||
|
|
||||||
$ldap->unbind();
|
$ldap->unbind();
|
||||||
$ldap->close();
|
$ldap->close();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,10 +24,9 @@
|
|||||||
* \ingroup ldap member
|
* \ingroup ldap member
|
||||||
* \brief Script to update groups into Dolibarr from LDAP
|
* \brief Script to update groups into Dolibarr from LDAP
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test if batch mode
|
// Test if batch mode
|
||||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||||
@ -49,7 +48,6 @@ $error=0;
|
|||||||
$forcecommit = 0;
|
$forcecommit = 0;
|
||||||
$confirmed = 0;
|
$confirmed = 0;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -59,29 +57,26 @@ print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
|||||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||||
|
|
||||||
// List of fields to get from LDAP
|
// List of fields to get from LDAP
|
||||||
$required_fields = array(
|
$required_fields = array($conf->global->LDAP_KEY_GROUPS,$conf->global->LDAP_GROUP_FIELD_FULLNAME,$conf->global->LDAP_GROUP_FIELD_DESCRIPTION,$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS);
|
||||||
$conf->global->LDAP_KEY_GROUPS,
|
|
||||||
$conf->global->LDAP_GROUP_FIELD_FULLNAME,
|
|
||||||
$conf->global->LDAP_GROUP_FIELD_DESCRIPTION,
|
|
||||||
$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS
|
|
||||||
);
|
|
||||||
|
|
||||||
// Remove from required_fields all entries not configured in LDAP (empty) and duplicated
|
// Remove from required_fields all entries not configured in LDAP (empty) and duplicated
|
||||||
$required_fields = array_unique(array_values(array_filter($required_fields, "dolValidElement")));
|
$required_fields = array_unique(array_values(array_filter($required_fields, "dolValidElement")));
|
||||||
|
|
||||||
|
|
||||||
if (! isset($argv[1])) {
|
if (! isset($argv[1])) {
|
||||||
// print "Usage: $script_file (nocommitiferror|commitiferror) [id_group]\n";
|
// print "Usage: $script_file (nocommitiferror|commitiferror) [id_group]\n";
|
||||||
print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n";
|
print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n";
|
||||||
exit(- 1);
|
exit(- 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)) $conf->global->LDAP_SERVER_HOST=$reg[1];
|
if (preg_match('/--server=([^\s]+)$/', $val, $reg))
|
||||||
if (preg_match('/--excludeuser=([^\s]+)$/', $val, $reg)) $excludeuser=explode(',', $reg[1]);
|
$conf->global->LDAP_SERVER_HOST = $reg[1];
|
||||||
if (preg_match('/-y$/', $val, $reg)) $confirmed=1;
|
if (preg_match('/--excludeuser=([^\s]+)$/', $val, $reg))
|
||||||
|
$excludeuser = explode(',', $reg[1]);
|
||||||
|
if (preg_match('/-y$/', $val, $reg))
|
||||||
|
$confirmed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
print "Mails sending disabled (useless in batch mode)\n";
|
print "Mails sending disabled (useless in batch mode)\n";
|
||||||
@ -105,37 +100,30 @@ print "commitiferror=".$forcecommit."\n";
|
|||||||
print "Mapped LDAP fields=" . join(',', $required_fields) . "\n";
|
print "Mapped LDAP fields=" . join(',', $required_fields) . "\n";
|
||||||
print "\n";
|
print "\n";
|
||||||
|
|
||||||
if (! $confirmed)
|
if (! $confirmed) {
|
||||||
{
|
|
||||||
print "Hit Enter to continue or CTRL+C to stop...\n";
|
print "Hit Enter to continue or CTRL+C to stop...\n";
|
||||||
$input = trim(fgets(STDIN));
|
$input = trim(fgets(STDIN));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($conf->global->LDAP_GROUP_DN))
|
if (empty($conf->global->LDAP_GROUP_DN)) {
|
||||||
{
|
|
||||||
print $langs->trans("Error") . ': ' . $langs->trans("LDAP setup for groups not defined inside Dolibarr");
|
print $langs->trans("Error") . ': ' . $langs->trans("LDAP setup for groups not defined inside Dolibarr");
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$ldap = new Ldap();
|
$ldap = new Ldap();
|
||||||
$result = $ldap->connect_bind();
|
$result = $ldap->connect_bind();
|
||||||
if ($result >= 0)
|
if ($result >= 0) {
|
||||||
{
|
|
||||||
$justthese = array();
|
$justthese = array();
|
||||||
|
|
||||||
|
|
||||||
// We disable synchro Dolibarr-LDAP
|
// We disable synchro Dolibarr-LDAP
|
||||||
$conf->global->LDAP_SYNCHRO_ACTIVE = 0;
|
$conf->global->LDAP_SYNCHRO_ACTIVE = 0;
|
||||||
|
|
||||||
$ldaprecords = $ldap->getRecords('*', $conf->global->LDAP_GROUP_DN, $conf->global->LDAP_KEY_GROUPS, $required_fields, 0, array($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS));
|
$ldaprecords = $ldap->getRecords('*', $conf->global->LDAP_GROUP_DN, $conf->global->LDAP_KEY_GROUPS, $required_fields, 0, array($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS));
|
||||||
if (is_array($ldaprecords))
|
if (is_array($ldaprecords)) {
|
||||||
{
|
|
||||||
$db->begin();
|
$db->begin();
|
||||||
|
|
||||||
// Warning $ldapuser has a key in lowercase
|
// Warning $ldapuser has a key in lowercase
|
||||||
foreach ($ldaprecords as $key => $ldapgroup)
|
foreach ($ldaprecords as $key => $ldapgroup) {
|
||||||
{
|
|
||||||
$group = new UserGroup($db);
|
$group = new UserGroup($db);
|
||||||
$group->fetch('', $ldapgroup[$conf->global->LDAP_KEY_GROUPS]);
|
$group->fetch('', $ldapgroup[$conf->global->LDAP_KEY_GROUPS]);
|
||||||
$group->name = $ldapgroup[$conf->global->LDAP_GROUP_FIELD_FULLNAME];
|
$group->name = $ldapgroup[$conf->global->LDAP_GROUP_FIELD_FULLNAME];
|
||||||
@ -149,12 +137,9 @@ if ($result >= 0)
|
|||||||
print $langs->transnoentities("GroupUpdate") . ' # ' . $key . ': name=' . $group->name;
|
print $langs->transnoentities("GroupUpdate") . ' # ' . $key . ': name=' . $group->name;
|
||||||
$res = $group->update();
|
$res = $group->update();
|
||||||
|
|
||||||
if ($res > 0)
|
if ($res > 0) {
|
||||||
{
|
|
||||||
print ' --> Updated group id=' . $group->id . ' name=' . $group->name;
|
print ' --> Updated group id=' . $group->id . ' name=' . $group->name;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$error ++;
|
$error ++;
|
||||||
print ' --> ' . $res . ' ' . $group->error;
|
print ' --> ' . $res . ' ' . $group->error;
|
||||||
}
|
}
|
||||||
@ -163,12 +148,9 @@ if ($result >= 0)
|
|||||||
print $langs->transnoentities("GroupCreate") . ' # ' . $key . ': name=' . $group->name;
|
print $langs->transnoentities("GroupCreate") . ' # ' . $key . ': name=' . $group->name;
|
||||||
$res = $group->create();
|
$res = $group->create();
|
||||||
|
|
||||||
if ($res > 0)
|
if ($res > 0) {
|
||||||
{
|
|
||||||
print ' --> Created group id=' . $group->id . ' name=' . $group->name;
|
print ' --> Created group id=' . $group->id . ' name=' . $group->name;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$error ++;
|
$error ++;
|
||||||
print ' --> ' . $res . ' ' . $group->error;
|
print ' --> ' . $res . ' ' . $group->error;
|
||||||
}
|
}
|
||||||
@ -182,7 +164,8 @@ 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') continue;
|
if ($key === 'count')
|
||||||
|
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') {
|
||||||
@ -191,7 +174,8 @@ 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)) continue;
|
if (! is_array($userKey))
|
||||||
|
continue;
|
||||||
|
|
||||||
$fuser = new User($db);
|
$fuser = new User($db);
|
||||||
|
|
||||||
@ -224,39 +208,33 @@ 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";
|
|
||||||
$db->commit();
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
print $langs->transnoentities("ErrorButCommitIsDone") . "\n";
|
||||||
|
$db->commit();
|
||||||
|
} else {
|
||||||
print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error) . "\n";
|
print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error) . "\n";
|
||||||
$db->rollback();
|
$db->rollback();
|
||||||
}
|
}
|
||||||
print "\n";
|
print "\n";
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error('', $ldap->error);
|
dol_print_error('', $ldap->error);
|
||||||
$error ++;
|
$error ++;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error('', $ldap->error);
|
dol_print_error('', $ldap->error);
|
||||||
$error ++;
|
$error ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
exit($error);
|
exit($error);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to say if a value is empty or not
|
* Function to say if a value is empty or not
|
||||||
*
|
*
|
||||||
* @param string $element Value to test
|
* @param string $element
|
||||||
|
* Value to test
|
||||||
* @return boolean True of false
|
* @return boolean True of false
|
||||||
*/
|
*/
|
||||||
function dolValidElement($element)
|
function dolValidElement($element)
|
||||||
|
|||||||
@ -23,10 +23,9 @@
|
|||||||
* \ingroup ldap core
|
* \ingroup ldap core
|
||||||
* \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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test if batch mode
|
// Test if batch mode
|
||||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||||
@ -48,7 +47,6 @@ require_once DOL_DOCUMENT_ROOT."/user/class/user.class.php";
|
|||||||
$version = DOL_VERSION;
|
$version = DOL_VERSION;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -58,27 +56,25 @@ print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
|||||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
|
* if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
|
||||||
{
|
* {
|
||||||
print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
* print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
||||||
exit(-1);
|
* exit(-1);
|
||||||
}
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sql = "SELECT rowid";
|
$sql = "SELECT rowid";
|
||||||
$sql .= " FROM " . MAIN_DB_PREFIX . "user";
|
$sql .= " FROM " . MAIN_DB_PREFIX . "user";
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
$ldap = new Ldap();
|
$ldap = new Ldap();
|
||||||
$ldap->connect_bind();
|
$ldap->connect_bind();
|
||||||
|
|
||||||
while ($i < $num)
|
while ($i < $num) {
|
||||||
{
|
|
||||||
$ldap->error = "";
|
$ldap->error = "";
|
||||||
|
|
||||||
$obj = $db->fetch_object($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
@ -98,12 +94,9 @@ if ($resql)
|
|||||||
|
|
||||||
$result = $ldap->add($dn, $info, $user); // Wil fail if already exists
|
$result = $ldap->add($dn, $info, $user); // Wil fail if already exists
|
||||||
$result = $ldap->update($dn, $info, $user, $olddn);
|
$result = $ldap->update($dn, $info, $user, $olddn);
|
||||||
if ($result > 0)
|
if ($result > 0) {
|
||||||
{
|
|
||||||
print " - " . $langs->trans("OK");
|
print " - " . $langs->trans("OK");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$error ++;
|
$error ++;
|
||||||
print " - " . $langs->trans("KO") . ' - ' . $ldap->error;
|
print " - " . $langs->trans("KO") . ' - ' . $ldap->error;
|
||||||
}
|
}
|
||||||
@ -114,9 +107,7 @@ if ($resql)
|
|||||||
|
|
||||||
$ldap->unbind();
|
$ldap->unbind();
|
||||||
$ldap->close();
|
$ldap->close();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,10 +23,9 @@
|
|||||||
* \ingroup ldap member
|
* \ingroup ldap member
|
||||||
* \brief Script to update users into Dolibarr from LDAP
|
* \brief Script to update users into Dolibarr from LDAP
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test if batch mode
|
// Test if batch mode
|
||||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||||
@ -57,27 +56,12 @@ print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
|||||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||||
|
|
||||||
// List of fields to get from LDAP
|
// List of fields to get from LDAP
|
||||||
$required_fields = array(
|
$required_fields = array($conf->global->LDAP_KEY_USERS,$conf->global->LDAP_FIELD_FULLNAME,$conf->global->LDAP_FIELD_NAME,$conf->global->LDAP_FIELD_FIRSTNAME,$conf->global->LDAP_FIELD_LOGIN,$conf->global->LDAP_FIELD_LOGIN_SAMBA,$conf->global->LDAP_FIELD_PASSWORD,$conf->global->LDAP_FIELD_PASSWORD_CRYPTED,$conf->global->LDAP_FIELD_PHONE,$conf->global->LDAP_FIELD_FAX,$conf->global->LDAP_FIELD_MOBILE,
|
||||||
$conf->global->LDAP_KEY_USERS,
|
|
||||||
$conf->global->LDAP_FIELD_FULLNAME,
|
|
||||||
$conf->global->LDAP_FIELD_NAME,
|
|
||||||
$conf->global->LDAP_FIELD_FIRSTNAME,
|
|
||||||
$conf->global->LDAP_FIELD_LOGIN,
|
|
||||||
$conf->global->LDAP_FIELD_LOGIN_SAMBA,
|
|
||||||
$conf->global->LDAP_FIELD_PASSWORD,
|
|
||||||
$conf->global->LDAP_FIELD_PASSWORD_CRYPTED,
|
|
||||||
$conf->global->LDAP_FIELD_PHONE,
|
|
||||||
$conf->global->LDAP_FIELD_FAX,
|
|
||||||
$conf->global->LDAP_FIELD_MOBILE,
|
|
||||||
// $conf->global->LDAP_FIELD_ADDRESS,
|
// $conf->global->LDAP_FIELD_ADDRESS,
|
||||||
// $conf->global->LDAP_FIELD_ZIP,
|
// $conf->global->LDAP_FIELD_ZIP,
|
||||||
// $conf->global->LDAP_FIELD_TOWN,
|
// $conf->global->LDAP_FIELD_TOWN,
|
||||||
// $conf->global->LDAP_FIELD_COUNTRY,
|
// $conf->global->LDAP_FIELD_COUNTRY,
|
||||||
$conf->global->LDAP_FIELD_MAIL,
|
$conf->global->LDAP_FIELD_MAIL,$conf->global->LDAP_FIELD_TITLE,$conf->global->LDAP_FIELD_DESCRIPTION,$conf->global->LDAP_FIELD_SID);
|
||||||
$conf->global->LDAP_FIELD_TITLE,
|
|
||||||
$conf->global->LDAP_FIELD_DESCRIPTION,
|
|
||||||
$conf->global->LDAP_FIELD_SID
|
|
||||||
);
|
|
||||||
|
|
||||||
// Remove from required_fields all entries not configured in LDAP (empty) and duplicated
|
// Remove from required_fields all entries not configured in LDAP (empty) and duplicated
|
||||||
$required_fields = array_unique(array_values(array_filter($required_fields, "dolValidElement")));
|
$required_fields = array_unique(array_values(array_filter($required_fields, "dolValidElement")));
|
||||||
@ -87,12 +71,15 @@ if (! isset($argv[1])) {
|
|||||||
exit(- 1);
|
exit(- 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)) $conf->global->LDAP_SERVER_HOST=$reg[1];
|
if (preg_match('/--server=([^\s]+)$/', $val, $reg))
|
||||||
if (preg_match('/--excludeuser=([^\s]+)$/', $val, $reg)) $excludeuser=explode(',', $reg[1]);
|
$conf->global->LDAP_SERVER_HOST = $reg[1];
|
||||||
if (preg_match('/-y$/', $val, $reg)) $confirmed=1;
|
if (preg_match('/--excludeuser=([^\s]+)$/', $val, $reg))
|
||||||
|
$excludeuser = explode(',', $reg[1]);
|
||||||
|
if (preg_match('/-y$/', $val, $reg))
|
||||||
|
$confirmed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
print "Mails sending disabled (useless in batch mode)\n";
|
print "Mails sending disabled (useless in batch mode)\n";
|
||||||
@ -104,8 +91,10 @@ 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_USER_DN . "\n";
|
print "DN to extract=" . $conf->global->LDAP_USER_DN . "\n";
|
||||||
if (! empty($conf->global->LDAP_FILTER_CONNECTION)) print 'Filter=('.$conf->global->LDAP_FILTER_CONNECTION.')'."\n"; // Note: filter is defined into function getRecords
|
if (! empty($conf->global->LDAP_FILTER_CONNECTION))
|
||||||
else print 'Filter=('.$conf->global->LDAP_KEY_USERS.'=*)'."\n";
|
print 'Filter=(' . $conf->global->LDAP_FILTER_CONNECTION . ')' . "\n"; // Note: filter is defined into function getRecords
|
||||||
|
else
|
||||||
|
print 'Filter=(' . $conf->global->LDAP_KEY_USERS . '=*)' . "\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";
|
||||||
@ -118,19 +107,16 @@ print "excludeuser=".join(',', $excludeuser)."\n";
|
|||||||
print "Mapped LDAP fields=" . join(',', $required_fields) . "\n";
|
print "Mapped LDAP fields=" . join(',', $required_fields) . "\n";
|
||||||
print "\n";
|
print "\n";
|
||||||
|
|
||||||
if (! $confirmed)
|
if (! $confirmed) {
|
||||||
{
|
|
||||||
print "Hit Enter to continue or CTRL+C to stop...\n";
|
print "Hit Enter to continue or CTRL+C to stop...\n";
|
||||||
$input = trim(fgets(STDIN));
|
$input = trim(fgets(STDIN));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($conf->global->LDAP_USER_DN))
|
if (empty($conf->global->LDAP_USER_DN)) {
|
||||||
{
|
|
||||||
print $langs->trans("Error") . ': ' . $langs->trans("LDAP setup for users not defined inside Dolibarr");
|
print $langs->trans("Error") . ': ' . $langs->trans("LDAP setup for users not defined inside Dolibarr");
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Load table of correspondence of countries
|
// Load table of correspondence of countries
|
||||||
$hashlib2rowid = array();
|
$hashlib2rowid = array();
|
||||||
$countries = array();
|
$countries = array();
|
||||||
@ -139,17 +125,13 @@ $sql.= " FROM ".MAIN_DB_PREFIX."c_country";
|
|||||||
$sql .= " WHERE active = 1";
|
$sql .= " WHERE active = 1";
|
||||||
$sql .= " ORDER BY code ASC";
|
$sql .= " ORDER BY code ASC";
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
if ($num)
|
if ($num) {
|
||||||
{
|
while ($i < $num) {
|
||||||
while ($i < $num)
|
|
||||||
{
|
|
||||||
$obj = $db->fetch_object($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
if ($obj)
|
if ($obj) {
|
||||||
{
|
|
||||||
// print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n";
|
// print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n";
|
||||||
$hashlib2rowid[strtolower($obj->label)] = $obj->rowid;
|
$hashlib2rowid[strtolower($obj->label)] = $obj->rowid;
|
||||||
$countries[$obj->rowid] = array('rowid' => $obj->rowid,'label' => $obj->label,'code' => $obj->code);
|
$countries[$obj->rowid] = array('rowid' => $obj->rowid,'label' => $obj->label,'code' => $obj->code);
|
||||||
@ -157,36 +139,27 @@ if ($resql)
|
|||||||
$i ++;
|
$i ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$ldap = new Ldap();
|
$ldap = new Ldap();
|
||||||
$result = $ldap->connect_bind();
|
$result = $ldap->connect_bind();
|
||||||
if ($result >= 0)
|
if ($result >= 0) {
|
||||||
{
|
|
||||||
$justthese = array();
|
$justthese = array();
|
||||||
|
|
||||||
|
|
||||||
// We disable synchro Dolibarr-LDAP
|
// We disable synchro Dolibarr-LDAP
|
||||||
$conf->global->LDAP_SYNCHRO_ACTIVE = 0;
|
$conf->global->LDAP_SYNCHRO_ACTIVE = 0;
|
||||||
|
|
||||||
$ldaprecords = $ldap->getRecords('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 'user'); // Fiter on 'user' filter param
|
$ldaprecords = $ldap->getRecords('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 'user'); // Fiter on 'user' filter param
|
||||||
if (is_array($ldaprecords))
|
if (is_array($ldaprecords)) {
|
||||||
{
|
|
||||||
$db->begin();
|
$db->begin();
|
||||||
|
|
||||||
// Warning $ldapuser has a key in lowercase
|
// Warning $ldapuser has a key in lowercase
|
||||||
foreach ($ldaprecords as $key => $ldapuser)
|
foreach ($ldaprecords as $key => $ldapuser) {
|
||||||
{
|
|
||||||
// If login into exclude list, we discard record
|
// If login into exclude list, we discard record
|
||||||
if (in_array($ldapuser[$conf->global->LDAP_FIELD_LOGIN], $excludeuser))
|
if (in_array($ldapuser[$conf->global->LDAP_FIELD_LOGIN], $excludeuser)) {
|
||||||
{
|
|
||||||
print $langs->transnoentities("UserDiscarded") . ' # ' . $key . ': login=' . $ldapuser[$conf->global->LDAP_FIELD_LOGIN] . ' --> Discarded' . "\n";
|
print $langs->transnoentities("UserDiscarded") . ' # ' . $key . ': login=' . $ldapuser[$conf->global->LDAP_FIELD_LOGIN] . ' --> Discarded' . "\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -208,12 +181,12 @@ if ($result >= 0)
|
|||||||
|
|
||||||
// $user->societe;
|
// $user->societe;
|
||||||
/*
|
/*
|
||||||
$fuser->address=$ldapuser[$conf->global->LDAP_FIELD_ADDRESS];
|
* $fuser->address=$ldapuser[$conf->global->LDAP_FIELD_ADDRESS];
|
||||||
$fuser->zip=$ldapuser[$conf->global->LDAP_FIELD_ZIP];
|
* $fuser->zip=$ldapuser[$conf->global->LDAP_FIELD_ZIP];
|
||||||
$fuser->town=$ldapuser[$conf->global->LDAP_FIELD_TOWN];
|
* $fuser->town=$ldapuser[$conf->global->LDAP_FIELD_TOWN];
|
||||||
$fuser->country=$ldapuser[$conf->global->LDAP_FIELD_COUNTRY];
|
* $fuser->country=$ldapuser[$conf->global->LDAP_FIELD_COUNTRY];
|
||||||
$fuser->country_id=$countries[$hashlib2rowid[strtolower($fuser->country)]]['rowid'];
|
* $fuser->country_id=$countries[$hashlib2rowid[strtolower($fuser->country)]]['rowid'];
|
||||||
$fuser->country_code=$countries[$hashlib2rowid[strtolower($fuser->country)]]['code'];
|
* $fuser->country_code=$countries[$hashlib2rowid[strtolower($fuser->country)]]['code'];
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$fuser->office_phone = $ldapuser[$conf->global->LDAP_FIELD_PHONE];
|
$fuser->office_phone = $ldapuser[$conf->global->LDAP_FIELD_PHONE];
|
||||||
@ -231,12 +204,14 @@ if ($result >= 0)
|
|||||||
|
|
||||||
$fuser->statut = 1;
|
$fuser->statut = 1;
|
||||||
// TODO : revoir la gestion du status
|
// TODO : revoir la gestion du status
|
||||||
/*if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS]))
|
/*
|
||||||
{
|
* if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS]))
|
||||||
$fuser->datec=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
|
* {
|
||||||
$fuser->datevalid=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
|
* $fuser->datec=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
|
||||||
$fuser->statut=$ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS];
|
* $fuser->datevalid=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
|
||||||
}*/
|
* $fuser->statut=$ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS];
|
||||||
|
* }
|
||||||
|
*/
|
||||||
// if ($fuser->statut > 1) $fuser->statut=1;
|
// if ($fuser->statut > 1) $fuser->statut=1;
|
||||||
|
|
||||||
// print_r($ldapuser);
|
// print_r($ldapuser);
|
||||||
@ -245,25 +220,19 @@ if ($result >= 0)
|
|||||||
print $langs->transnoentities("UserUpdate") . ' # ' . $key . ': login=' . $fuser->login . ', fullname=' . $fuser->getFullName($langs);
|
print $langs->transnoentities("UserUpdate") . ' # ' . $key . ': login=' . $fuser->login . ', fullname=' . $fuser->getFullName($langs);
|
||||||
$res = $fuser->update($user);
|
$res = $fuser->update($user);
|
||||||
|
|
||||||
if ($res < 0)
|
if ($res < 0) {
|
||||||
{
|
|
||||||
$error ++;
|
$error ++;
|
||||||
print ' --> ' . $res . ' ' . $fuser->error;
|
print ' --> ' . $res . ' ' . $fuser->error;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
print ' --> Updated user id=' . $fuser->id . ' login=' . $fuser->login;
|
print ' --> Updated user id=' . $fuser->id . ' login=' . $fuser->login;
|
||||||
}
|
}
|
||||||
} else { // User creation
|
} else { // User creation
|
||||||
print $langs->transnoentities("UserCreate") . ' # ' . $key . ': login=' . $fuser->login . ', fullname=' . $fuser->getFullName($langs);
|
print $langs->transnoentities("UserCreate") . ' # ' . $key . ': login=' . $fuser->login . ', fullname=' . $fuser->getFullName($langs);
|
||||||
$res = $fuser->create($user);
|
$res = $fuser->create($user);
|
||||||
|
|
||||||
if ($res > 0)
|
if ($res > 0) {
|
||||||
{
|
|
||||||
print ' --> Created user id=' . $fuser->id . ' login=' . $fuser->login;
|
print ' --> Created user id=' . $fuser->id . ' login=' . $fuser->login;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$error ++;
|
$error ++;
|
||||||
print ' --> ' . $res . ' ' . $fuser->error;
|
print ' --> ' . $res . ' ' . $fuser->error;
|
||||||
}
|
}
|
||||||
@ -273,46 +242,42 @@ if ($result >= 0)
|
|||||||
|
|
||||||
// Gestion des groupes
|
// Gestion des groupes
|
||||||
// TODO : revoir la gestion des groupes (ou script de sync groupes)
|
// TODO : revoir la gestion des groupes (ou script de sync groupes)
|
||||||
/*if(!$error) {
|
/*
|
||||||
foreach ($ldapuser[$conf->global->LDAP_FIELD_USERGROUPS] as $groupdn) {
|
* if(!$error) {
|
||||||
$groupdn;
|
* foreach ($ldapuser[$conf->global->LDAP_FIELD_USERGROUPS] as $groupdn) {
|
||||||
}
|
* $groupdn;
|
||||||
}*/
|
* }
|
||||||
|
* }
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
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";
|
|
||||||
$db->commit();
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
print $langs->transnoentities("ErrorButCommitIsDone") . "\n";
|
||||||
|
$db->commit();
|
||||||
|
} else {
|
||||||
print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error) . "\n";
|
print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error) . "\n";
|
||||||
$db->rollback();
|
$db->rollback();
|
||||||
}
|
}
|
||||||
print "\n";
|
print "\n";
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error('', $ldap->error);
|
dol_print_error('', $ldap->error);
|
||||||
$error ++;
|
$error ++;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error('', $ldap->error);
|
dol_print_error('', $ldap->error);
|
||||||
$error ++;
|
$error ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
exit($error);
|
exit($error);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to say if a value is empty or not
|
* Function to say if a value is empty or not
|
||||||
*
|
*
|
||||||
* @param string $element Value to test
|
* @param string $element
|
||||||
|
* Value to test
|
||||||
* @return boolean True of false
|
* @return boolean True of false
|
||||||
*/
|
*/
|
||||||
function dolValidElement($element)
|
function dolValidElement($element)
|
||||||
|
|||||||
@ -23,10 +23,9 @@
|
|||||||
* \ingroup prelevement
|
* \ingroup prelevement
|
||||||
* \brief Script de prelevement
|
* \brief Script de prelevement
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
$script_file = basename(__FILE__);
|
$script_file = basename(__FILE__);
|
||||||
$path=dirname(__FILE__).'/';
|
$path = __DIR__ . '/';
|
||||||
|
|
||||||
// Test if batch mode
|
// Test if batch mode
|
||||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||||
@ -44,7 +43,6 @@ require_once DOL_DOCUMENT_ROOT."/compta/paiement/class/paiement.class.php";
|
|||||||
$version = DOL_VERSION;
|
$version = DOL_VERSION;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -68,12 +66,10 @@ if (! isset($argv[1])) { // Check parameters
|
|||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$withdrawreceipt = new BonPrelevement($db);
|
$withdrawreceipt = new BonPrelevement($db);
|
||||||
// $conf->global->PRELEVEMENT_CODE_BANQUE and $conf->global->PRELEVEMENT_CODE_GUICHET should be empty
|
// $conf->global->PRELEVEMENT_CODE_BANQUE and $conf->global->PRELEVEMENT_CODE_GUICHET should be empty
|
||||||
$result = $withdrawreceipt->create($conf->global->PRELEVEMENT_CODE_BANQUE, $conf->global->PRELEVEMENT_CODE_GUICHET, $argv[1]);
|
$result = $withdrawreceipt->create($conf->global->PRELEVEMENT_CODE_BANQUE, $conf->global->PRELEVEMENT_CODE_GUICHET, $argv[1]);
|
||||||
|
|
||||||
|
|
||||||
$db->close();
|
$db->close();
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user