Merge branch 'develop' into clean_10_beta
This commit is contained in:
commit
c1ec7454a1
@ -1,7 +1,8 @@
|
||||
# EditorConfig is awesome: http://EditorConfig.org
|
||||
# EditorConfig is awesome: https://editorconfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# Unix-style newlines with a newline ending every file
|
||||
[*]
|
||||
charset = utf-8
|
||||
@ -11,9 +12,10 @@ insert_final_newline = true
|
||||
# PHP PSR-2 Coding Standards
|
||||
# http://www.php-fig.org/psr/psr-2/
|
||||
[*.php]
|
||||
indent_style = space
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
[*.js]
|
||||
indent_style = tab
|
||||
[*.css]
|
||||
|
||||
14
build/phpstan/bootstrap.php
Normal file
14
build/phpstan/bootstrap.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
// Example to use PHPStan
|
||||
// cd git/dolibarr
|
||||
// /usr/bin/php7.2 ../phpstan.phar -l1 analyze htdocs/societe/website.php --memory-limit 2G
|
||||
|
||||
// Defined some constants and load Dolibarr env to reduce PHPStan bootstrap that fails to load a lot of things.
|
||||
define('DOL_DOCUMENT_ROOT', __DIR__ . '/../../htdocs');
|
||||
define('DOL_DATA_ROOT', __DIR__ . '/../../documents');
|
||||
define('DOL_URL_ROOT', '/');
|
||||
|
||||
// Load the main.inc.php file to have finctions llx_Header and llx_Footer defined
|
||||
if (! defined("NOLOGIN")) define("NOLOGIN", '1');
|
||||
global $conf, $langs, $user, $db;
|
||||
include_once __DIR__ . '/../../htdocs/main.inc.php';
|
||||
@ -4656,6 +4656,14 @@ elseif ($id > 0 || ! empty($ref))
|
||||
}
|
||||
}
|
||||
|
||||
// POS Ticket
|
||||
if (! empty($conf->takepos->enabled) && $object->module_source == 'takepos')
|
||||
{
|
||||
$langs->load("cashdesk");
|
||||
$receipt_url=DOL_URL_ROOT."/takepos/receipt.php";
|
||||
print '<div class="inline-block divButAction"><a target="_blank" class="butAction" href="' . $receipt_url . '?facid=' . $object->id.'">' . $langs->trans('POSTicket') .'</a></div>';
|
||||
}
|
||||
|
||||
// Create payment
|
||||
if ($object->type != Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $usercanissuepayment) {
|
||||
if ($objectidnext) {
|
||||
@ -4700,13 +4708,6 @@ elseif ($id > 0 || ! empty($ref))
|
||||
}
|
||||
}
|
||||
|
||||
// POS Ticket
|
||||
if (! empty($conf->takepos->enabled) && $object->module_source != '')
|
||||
{
|
||||
$receipt_url=DOL_URL_ROOT."/takepos/receipt.php";
|
||||
print '<div class="inline-block divButAction"><a target="_blank" class="butAction" href="' . $receipt_url . '?facid=' . $object->id.'">' . $langs->trans('POSTicket') .'</a></div>';
|
||||
}
|
||||
|
||||
// Classify paid
|
||||
if ($object->statut == 1 && $object->paye == 0 && $usercanissuepayment && (($object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT && $resteapayer <= 0) || ($object->type == Facture::TYPE_CREDIT_NOTE && $resteapayer >= 0))
|
||||
|| ($object->type == Facture::TYPE_DEPOSIT && $object->paye == 0 && $object->total_ttc > 0 && $resteapayer == 0 && $usercanissuepayment && empty($discount->id))
|
||||
|
||||
@ -222,19 +222,26 @@ if (empty($reshook))
|
||||
if ($socid > 0) $thirdparty->fetch($socid);
|
||||
|
||||
// Clean parameters amount if payment is for a credit note
|
||||
if (GETPOST('type') == Facture::TYPE_CREDIT_NOTE)
|
||||
foreach ($amounts as $key => $value) // How payment is dispatched
|
||||
{
|
||||
foreach ($amounts as $key => $value) // How payment is dispatch
|
||||
{
|
||||
$newvalue = price2num($value, 'MT');
|
||||
$amounts[$key] = -$newvalue;
|
||||
}
|
||||
$tmpinvoice = new Facture($db);
|
||||
$tmpinvoice->fetch($key);
|
||||
if ($tmpinvoice->type == Facture::TYPE_CREDIT_NOTE)
|
||||
{
|
||||
$newvalue = price2num($value, 'MT');
|
||||
$amounts[$key] = - abs($newvalue);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($multicurrency_amounts as $key => $value) // How payment is dispatch
|
||||
{
|
||||
$newvalue = price2num($value, 'MT');
|
||||
$multicurrency_amounts[$key] = -$newvalue;
|
||||
}
|
||||
foreach ($multicurrency_amounts as $key => $value) // How payment is dispatched
|
||||
{
|
||||
$tmpinvoice = new Facture($db);
|
||||
$tmpinvoice->fetch($key);
|
||||
if ($tmpinvoice->type == Facture::TYPE_CREDIT_NOTE)
|
||||
{
|
||||
$newvalue = price2num($value, 'MT');
|
||||
$multicurrency_amounts[$key] = - abs($newvalue);
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($conf->banque->enabled))
|
||||
@ -544,7 +551,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
||||
}
|
||||
$sql.= ') AND f.paye = 0';
|
||||
$sql.= ' AND f.fk_statut = 1'; // Statut=0 => not validated, Statut=2 => canceled
|
||||
if ($facture->type != 2)
|
||||
if ($facture->type != Facture::TYPE_CREDIT_NOTE)
|
||||
{
|
||||
$sql .= ' AND type IN (0,1,3,5)'; // Standard invoice, replacement, deposit, situation
|
||||
}
|
||||
@ -552,7 +559,6 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
||||
{
|
||||
$sql .= ' AND type = 2'; // If paying back a credit note, we show all credit notes
|
||||
}
|
||||
|
||||
// Sort invoices by date and serial number: the older one comes first
|
||||
$sql.=' ORDER BY f.datef ASC, f.ref ASC';
|
||||
|
||||
@ -562,9 +568,6 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
||||
$num = $db->num_rows($resql);
|
||||
if ($num > 0)
|
||||
{
|
||||
$sign=1;
|
||||
if ($facture->type == 2) $sign=-1;
|
||||
|
||||
$arraytitle=$langs->trans('Invoice');
|
||||
if ($facture->type == 2) $arraytitle=$langs->trans("CreditNotes");
|
||||
$alreadypayedlabel=$langs->trans('Received');
|
||||
@ -606,6 +609,9 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
||||
{
|
||||
$objp = $db->fetch_object($resql);
|
||||
|
||||
$sign=1;
|
||||
if ($facture->type == Facture::TYPE_CREDIT_NOTE) $sign=-1;
|
||||
|
||||
$soc = new Societe($db);
|
||||
$soc->fetch($objp->socid);
|
||||
|
||||
@ -631,7 +637,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
||||
|
||||
print '<td>';
|
||||
print $invoice->getNomUrl(1, '');
|
||||
if($objp->socid != $facture->thirdparty->id) print ' - '.$soc->getNomUrl(1).' ';
|
||||
if ($objp->socid != $facture->thirdparty->id) print ' - '.$soc->getNomUrl(1).' ';
|
||||
print "</td>\n";
|
||||
|
||||
// Date
|
||||
|
||||
@ -50,15 +50,15 @@ $search_name=GETPOST('search_name', 'alpha');
|
||||
$search_email=GETPOST('search_email', 'alpha');
|
||||
$search_town=GETPOST('search_town', 'alpha');
|
||||
$search_zip=GETPOST('search_zip', 'alpha');
|
||||
$search_state=trim(GETPOST("search_state"));
|
||||
$search_state=trim(GETPOST("search_state", 'alpha'));
|
||||
$search_country=GETPOST("search_country", 'int');
|
||||
$search_type_thirdparty=GETPOST("search_type_thirdparty", 'int');
|
||||
$search_contract=GETPOST('search_contract');
|
||||
$search_contract=GETPOST('search_contract', 'alpha');
|
||||
$search_ref_customer=GETPOST('search_ref_customer', 'alpha');
|
||||
$search_ref_supplier=GETPOST('search_ref_supplier', 'alpha');
|
||||
$sall=trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml'));
|
||||
$search_status=GETPOST('search_status');
|
||||
$socid=GETPOST('socid');
|
||||
$search_status=GETPOST('search_status', 'alpha');
|
||||
$socid=GETPOST('socid', 'int');
|
||||
$search_user=GETPOST('search_user', 'int');
|
||||
$search_sale=GETPOST('search_sale', 'int');
|
||||
$search_product_category=GETPOST('search_product_category', 'int');
|
||||
|
||||
@ -91,7 +91,7 @@ class DolGraph
|
||||
public function __construct($library = 'jflot')
|
||||
{
|
||||
global $conf;
|
||||
global $theme_bordercolor, $theme_datacolor, $theme_bgcolor, $theme_bgcoloronglet;
|
||||
global $theme_bordercolor, $theme_datacolor, $theme_bgcolor;
|
||||
|
||||
// To use old feature
|
||||
if ($library == 'artichow')
|
||||
@ -883,7 +883,6 @@ class DolGraph
|
||||
private function draw_jflot($file, $fileurl)
|
||||
{
|
||||
// phpcs:enable
|
||||
global $artichow_defaultfont;
|
||||
|
||||
dol_syslog(get_class($this)."::draw_jflot this->type=".join(',', $this->type)." this->MaxValue=".$this->MaxValue);
|
||||
|
||||
|
||||
@ -660,16 +660,19 @@ function dol_buildpath($path, $type = 0, $returnemptyifnotfound = 0)
|
||||
if (empty($type)) // For a filesystem path
|
||||
{
|
||||
$res = DOL_DOCUMENT_ROOT.'/'.$path; // Standard default path
|
||||
foreach ($conf->file->dol_document_root as $key => $dirroot) // ex: array(["main"]=>"/home/main/htdocs", ["alt0"]=>"/home/dirmod/htdocs", ...)
|
||||
if (is_array($conf->file->dol_document_root))
|
||||
{
|
||||
if ($key == 'main')
|
||||
foreach ($conf->file->dol_document_root as $key => $dirroot) // ex: array("main"=>"/home/main/htdocs", "alt0"=>"/home/dirmod/htdocs", ...)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (file_exists($dirroot.'/'.$path))
|
||||
{
|
||||
$res=$dirroot.'/'.$path;
|
||||
return $res;
|
||||
if ($key == 'main')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (file_exists($dirroot.'/'.$path))
|
||||
{
|
||||
$res=$dirroot.'/'.$path;
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($returnemptyifnotfound) // Not found into alternate dir
|
||||
@ -6582,7 +6585,7 @@ function dol_htmloutput_errors($mesgstring = '', $mesgarray = array(), $keepembe
|
||||
* or descending output and uses optionally natural case insensitive sorting (which
|
||||
* can be optionally case sensitive as well).
|
||||
*
|
||||
* @param array $array Array to sort (array of array('key','otherkey1','otherkey2'...))
|
||||
* @param array $array Array to sort (array of array('key1'=>val1,'key2'=>val2,'key3'...) or array of objects)
|
||||
* @param string $index Key in array to use for sorting criteria
|
||||
* @param int $order Sort order ('asc' or 'desc')
|
||||
* @param int $natsort 1=use "natural" sort (natsort), 0=use "standard" sort (asort)
|
||||
@ -6601,7 +6604,17 @@ function dol_sort_array(&$array, $index, $order = 'asc', $natsort = 0, $case_sen
|
||||
if ($sizearray>0)
|
||||
{
|
||||
$temp = array();
|
||||
foreach(array_keys($array) as $key) $temp[$key]=$array[$key][$index];
|
||||
foreach(array_keys($array) as $key)
|
||||
{
|
||||
if (is_object($array[$key]))
|
||||
{
|
||||
$temp[$key]=$array[$key]->$index;
|
||||
}
|
||||
else
|
||||
{
|
||||
$temp[$key]=$array[$key][$index];
|
||||
}
|
||||
}
|
||||
|
||||
if (! $natsort) {
|
||||
($order=='asc') ? asort($temp) : arsort($temp);
|
||||
|
||||
@ -243,11 +243,12 @@ class modAccounting extends DolibarrModules
|
||||
$this->export_icon[$r]='Accounting';
|
||||
$this->export_permission[$r]=array(array("accounting","chartofaccount"));
|
||||
$this->export_fields_array[$r]=array('ac.rowid'=>'ChartofaccountsId','ac.pcg_version'=>'Chartofaccounts','aa.rowid'=>'Id','aa.account_number'=>"AccountAccounting",'aa.label'=>"Label",'aa.account_parent'=>"Accountparent",'aa.pcg_type'=>"Pcgtype",'aa.pcg_subtype'=>'Pcgsubtype','aa.active'=>'Status');
|
||||
$this->export_TypeFields_array[$r]=array('ac.rowid'=>'List:accounting_system:pcg_version','aa.account_number'=>"Text",'aa.label'=>"Text",'aa.pcg_type'=>'Text','aa.pcg_subtype'=>'Text','aa.active'=>'Status');
|
||||
$this->export_TypeFields_array[$r]=array('ac.rowid'=>'List:accounting_system:pcg_version','aa.account_number'=>"Text",'aa.label'=>"Text",'aa.account_parent'=>"Text",'aa.pcg_type'=>'Text','aa.pcg_subtype'=>'Text','aa.active'=>'Status');
|
||||
$this->export_entities_array[$r]=array('ac.rowid'=>"Accounting",'ac.pcg_version'=>"Accounting",'aa.rowid'=>'Accounting','aa.account_number'=>"Accounting",'aa.label'=>"Accounting",'aa.accountparent'=>"Accounting",'aa.pcg_type'=>"Accounting",'aa.pcgsubtype'=>"Accounting",'aa_active'=>"Accounting");
|
||||
|
||||
$this->export_sql_start[$r]='SELECT DISTINCT ';
|
||||
$this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'accounting_account as aa, '.MAIN_DB_PREFIX.'accounting_system as ac';
|
||||
$this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'accounting_account as aa';
|
||||
$this->export_sql_end[$r] .=' ,'.MAIN_DB_PREFIX.'accounting_system as ac';
|
||||
$this->export_sql_end[$r] .=' WHERE ac.pcg_version = aa.fk_pcg_version AND aa.entity IN ('.getEntity('accounting').') ';
|
||||
|
||||
|
||||
|
||||
@ -169,6 +169,7 @@ class modProduct extends DolibarrModules
|
||||
$this->export_permission[$r]=array(array("produit","export"));
|
||||
$this->export_fields_array[$r]=array(
|
||||
'p.rowid'=>"Id",'p.ref'=>"Ref",'p.label'=>"Label",'p.description'=>"Description",'p.url'=>"PublicUrl",'p.accountancy_code_sell'=>"ProductAccountancySellCode",
|
||||
'p.accountancy_code_sell_intra'=>"ProductAccountancySellIntraCode", 'p.accountancy_code_sell_export'=>"ProductAccountancySellExportCode",
|
||||
'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",'p.length'=>"Length",'p.width'=>"Width",'p.height'=>"Height",'p.surface'=>"Surface",
|
||||
'p.volume'=>"Volume",'p.weight'=>"Weight",'p.customcode'=>'CustomCode','p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC",
|
||||
'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell",'p.tobuy'=>"OnBuy",'p.datec'=>'DateCreation','p.tms'=>'DateModification'
|
||||
@ -184,7 +185,8 @@ class modProduct extends DolibarrModules
|
||||
if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r], array('l.lang'=>'Language', 'l.label'=>'TranslatedLabel','l.description'=>'TranslatedDescription','l.note'=>'TranslatedNote'));
|
||||
if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->export_fields_array[$r]['p.fk_unit'] = 'Unit';
|
||||
$this->export_TypeFields_array[$r]=array(
|
||||
'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
|
||||
'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",
|
||||
'p.accountancy_code_sell_intra'=>"Text",'p.accountancy_code_sell_export'=>"Text",'p.accountancy_code_buy'=>"Text",
|
||||
'p.note'=>"Text",'p.length'=>"Numeric",'p.width'=>"Numeric",'p.height'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",
|
||||
'p.customcode'=>'Text','p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",
|
||||
'p.tobuy'=>"Boolean",'p.datec'=>'Date','p.tms'=>'Date'
|
||||
@ -289,7 +291,8 @@ class modProduct extends DolibarrModules
|
||||
$this->export_permission[$r]=array(array("produit","export"));
|
||||
$this->export_fields_array[$r]=array(
|
||||
'p.rowid'=>"Id",'p.ref'=>"Ref",'p.label'=>"Label",'p.description'=>"Description",'p.url'=>"PublicUrl",
|
||||
'p.accountancy_code_sell'=>"ProductAccountancySellCode",'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",
|
||||
'p.accountancy_code_sell'=>"ProductAccountancySellCode",'p.accountancy_code_sell_intra'=>"ProductAccountancySellIntraCode",
|
||||
'p.accountancy_code_sell_export'=>"ProductAccountancySellExportCode",'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",
|
||||
'p.length'=>"Length",'p.surface'=>"Surface",'p.volume'=>"Volume",'p.weight'=>"Weight",'p.customcode'=>'CustomCode',
|
||||
'p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC",'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell",
|
||||
'p.tobuy'=>"OnBuy",'p.datec'=>'DateCreation','p.tms'=>'DateModification'
|
||||
@ -298,7 +301,8 @@ class modProduct extends DolibarrModules
|
||||
if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r], array('p.barcode'=>'BarCode'));
|
||||
$this->export_fields_array[$r]=array_merge($this->export_fields_array[$r], array('pa.qty'=>'Qty','pa.incdec'=>'ComposedProductIncDecStock'));
|
||||
$this->export_TypeFields_array[$r]=array(
|
||||
'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
|
||||
'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",
|
||||
'p.accountancy_code_sell_intra'=>"Text",'p.accountancy_code_sell_export'=>"Text",'p.accountancy_code_buy'=>"Text",
|
||||
'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text',
|
||||
'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",
|
||||
'p.datec'=>'Date','p.tms'=>'Date'
|
||||
@ -308,7 +312,8 @@ class modProduct extends DolibarrModules
|
||||
$this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r], array('pa.qty'=>'Numeric'));
|
||||
$this->export_entities_array[$r]=array(
|
||||
'p.rowid'=>"virtualproduct",'p.ref'=>"virtualproduct",'p.label'=>"virtualproduct",'p.description'=>"virtualproduct",'p.url'=>"virtualproduct",
|
||||
'p.accountancy_code_sell'=>'virtualproduct','p.accountancy_code_buy'=>'virtualproduct','p.note'=>"virtualproduct",'p.length'=>"virtualproduct",
|
||||
'p.accountancy_code_sell'=>'virtualproduct','p.accountancy_code_sell_intra'=>'virtualproduct','p.accountancy_code_sell_export'=>'virtualproduct',
|
||||
'p.accountancy_code_buy'=>'virtualproduct','p.note'=>"virtualproduct",'p.length'=>"virtualproduct",
|
||||
'p.surface'=>"virtualproduct",'p.volume'=>"virtualproduct",'p.weight'=>"virtualproduct",'p.customcode'=>'virtualproduct',
|
||||
'p.price_base_type'=>"virtualproduct",'p.price'=>"virtualproduct",'p.price_ttc'=>"virtualproduct",'p.tva_tx'=>"virtualproduct",
|
||||
'p.tosell'=>"virtualproduct",'p.tobuy'=>"virtualproduct",'p.datec'=>"virtualproduct",'p.tms'=>"virtualproduct"
|
||||
@ -492,6 +497,8 @@ class modProduct extends DolibarrModules
|
||||
'p.duration' => "eg. 365d/12m/1y",
|
||||
'p.url' => 'link to product (no https)',
|
||||
'p.accountancy_code_sell' => "",
|
||||
'p.accountancy_code_sell_intra' => "",
|
||||
'p.accountancy_code_sell_export' => "",
|
||||
'p.accountancy_code_buy' => "",
|
||||
'p.weight' => "",
|
||||
'p.weight_units' => 'use a unit of measure from the dictionary. g/Kg/T etc....matches field "Short Label" for unit type "weight" in table "' . MAIN_DB_PREFIX . 'c_units',
|
||||
|
||||
@ -251,21 +251,32 @@ if (empty($reshook))
|
||||
$datepaye = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
|
||||
|
||||
// Clean parameters amount if payment is for a credit note
|
||||
if (GETPOST('type', 'int') == FactureFournisseur::TYPE_CREDIT_NOTE)
|
||||
foreach ($amounts as $key => $value) // How payment is dispatched
|
||||
{
|
||||
foreach ($amounts as $key => $value) // How payment is dispatch
|
||||
$tmpinvoice = new FactureFournisseur($db);
|
||||
$tmpinvoice->fetch($key);
|
||||
if ($tmpinvoice->type == FactureFournisseur::TYPE_CREDIT_NOTE)
|
||||
{
|
||||
$newvalue = price2num($value, 'MT');
|
||||
$amounts[$key] = -$newvalue;
|
||||
}
|
||||
|
||||
foreach ($multicurrency_amounts as $key => $value) // How payment is dispatch
|
||||
{
|
||||
$newvalue = price2num($value, 'MT');
|
||||
$multicurrency_amounts[$key] = -$newvalue;
|
||||
$amounts[$key] = - abs($newvalue);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($multicurrency_amounts as $key => $value) // How payment is dispatched
|
||||
{
|
||||
$tmpinvoice = new FactureFournisseur($db);
|
||||
$tmpinvoice->fetch($key);
|
||||
if ($tmpinvoice->type == FactureFournisseur::TYPE_CREDIT_NOTE)
|
||||
{
|
||||
$newvalue = price2num($value, 'MT');
|
||||
$multicurrency_amounts[$key] = - abs($newvalue);
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($amounts);
|
||||
//var_dump($multicurrency_amounts);
|
||||
//exit;
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$db->begin();
|
||||
@ -491,26 +502,35 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
||||
if (empty($reshook))
|
||||
{
|
||||
/*
|
||||
* Autres factures impayees
|
||||
* All unpayed supplier invoices
|
||||
*/
|
||||
$sql = 'SELECT f.rowid as facid, f.ref, f.ref_supplier, f.total_ht, f.total_ttc, f.multicurrency_total_ttc, f.datef as df,';
|
||||
$sql.= ' SUM(pf.amount) as am, SUM(pf.multicurrency_amount) as multicurrency_am, f.date_lim_reglement as dlr';
|
||||
$sql = 'SELECT f.rowid as facid, f.ref, f.ref_supplier, f.type, f.total_ht, f.total_ttc, f.multicurrency_total_ttc, f.datef as df, f.date_lim_reglement as dlr,';
|
||||
$sql.= ' SUM(pf.amount) as am, SUM(pf.multicurrency_amount) as multicurrency_am';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
|
||||
$sql.= " WHERE f.entity = ".$conf->entity;
|
||||
$sql.= ' AND f.fk_soc = '.$object->socid;
|
||||
$sql.= ' AND f.paye = 0';
|
||||
$sql.= ' AND f.fk_statut = 1'; // Statut=0 => non validee, Statut=2 => annulee
|
||||
$sql.= ' GROUP BY f.rowid, f.ref, f.ref_supplier, f.total_ht, f.total_ttc, f.multicurrency_total_ttc, f.datef, f.date_lim_reglement';
|
||||
if ($object->type != FactureFournisseur::TYPE_CREDIT_NOTE)
|
||||
{
|
||||
$sql .= ' AND f.type IN (0,1,3,5)'; // Standard invoice, replacement, deposit, situation
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql .= ' AND f.type = 2'; // If paying back a credit note, we show all credit notes
|
||||
}
|
||||
// Group by because we have a total
|
||||
$sql.= ' GROUP BY f.datef, f.ref, f.ref_supplier, f.rowid, f.type, f.total_ht, f.total_ttc, f.multicurrency_total_ttc, f.datef, f.date_lim_reglement';
|
||||
// Sort invoices by date and serial number: the older one comes first
|
||||
$sql.= ' ORDER BY f.datef ASC, f.ref ASC';
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
if ($num > 0)
|
||||
{
|
||||
$sign=1;
|
||||
if ($object->type == 2) $sign=-1;
|
||||
|
||||
$i = 0;
|
||||
print '<br>';
|
||||
|
||||
@ -551,8 +571,15 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
||||
{
|
||||
$objp = $db->fetch_object($resql);
|
||||
|
||||
$sign=1;
|
||||
if ($objp->type == FactureFournisseur::TYPE_CREDIT_NOTE) $sign=-1;
|
||||
|
||||
$invoice=new FactureFournisseur($db);
|
||||
$invoice->fetch($objp->facid);
|
||||
|
||||
$invoicesupplierstatic->ref=$objp->ref;
|
||||
$invoicesupplierstatic->id=$objp->facid;
|
||||
|
||||
$paiement = $invoice->getSommePaiement();
|
||||
$creditnotes=$invoice->getSumCreditNotesUsed();
|
||||
$deposits=$invoice->getSumDepositsUsed();
|
||||
@ -572,9 +599,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
||||
print '<tr class="oddeven">';
|
||||
|
||||
// Ref
|
||||
print '<td>';
|
||||
$invoicesupplierstatic->ref=$objp->ref;
|
||||
$invoicesupplierstatic->id=$objp->facid;
|
||||
print '<td class="nowraponall">';
|
||||
print $invoicesupplierstatic->getNomUrl(1);
|
||||
print '</td>';
|
||||
|
||||
@ -582,7 +607,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
||||
print '<td>'.$objp->ref_supplier.'</td>';
|
||||
|
||||
// Date
|
||||
if ($objp->df > 0 )
|
||||
if ($objp->df > 0)
|
||||
{
|
||||
print '<td class="center">';
|
||||
print dol_print_date($db->jdate($objp->df), 'day').'</td>';
|
||||
@ -593,7 +618,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
||||
}
|
||||
|
||||
// Date Max Payment
|
||||
if ($objp->dlr > 0 )
|
||||
if ($objp->dlr > 0)
|
||||
{
|
||||
print '<td class="center">';
|
||||
print dol_print_date($db->jdate($objp->dlr), 'day');
|
||||
@ -648,7 +673,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
||||
print '<td class="right">'.price($sign * $remaintopay).'</td>';
|
||||
|
||||
// Amount
|
||||
print '<td class="center">';
|
||||
print '<td class="center nowraponall">';
|
||||
|
||||
$namef = 'amount_'.$objp->facid;
|
||||
$nameRemain = 'remain_'.$objp->facid;
|
||||
@ -711,12 +736,12 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
||||
if (!empty($conf->multicurrency->enabled)) print '<td> </td>';
|
||||
if (!empty($conf->multicurrency->enabled)) print '<td> </td>';
|
||||
if (!empty($conf->multicurrency->enabled)) print '<td> </td>';
|
||||
print '<td class="right"><b>'.price($total_ttc).'</b></td>';
|
||||
print '<td class="right"><b>'.price($totalrecu);
|
||||
print '<td class="right"><b>'.price($sign * $total_ttc).'</b></td>';
|
||||
print '<td class="right"><b>'.price($sign * $totalrecu);
|
||||
if ($totalrecucreditnote) print '+'.price($totalrecucreditnote);
|
||||
if ($totalrecudeposits) print '+'.price($totalrecudeposits);
|
||||
print '</b></td>';
|
||||
print '<td class="right"><b>'.price(price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits, 'MT')).'</b></td>';
|
||||
print '<td class="right"><b>'.price($sign * price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits, 'MT')).'</b></td>';
|
||||
print '<td class="center" id="result" style="font-weight: bold;"></td>'; // Autofilled
|
||||
if (!empty($conf->multicurrency->enabled)) print '<td class="right" id="multicurrency_result" style="font-weight: bold;"></td>';
|
||||
print "</tr>\n";
|
||||
@ -936,11 +961,11 @@ if (empty($action) || $action == 'list')
|
||||
print_liste_field_titre("Account", $_SERVER["PHP_SELF"], 'ba.label', '', $param, '', $sortfield, $sortorder);
|
||||
}
|
||||
print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], 'p.amount', '', $param, '', $sortfield, $sortorder, 'right ');
|
||||
|
||||
|
||||
$parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
|
||||
$reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
|
||||
print $hookmanager->resPrint;
|
||||
|
||||
|
||||
print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch ');
|
||||
print "</tr>\n";
|
||||
|
||||
@ -955,29 +980,29 @@ if (empty($action) || $action == 'list')
|
||||
// Ref payment
|
||||
print '<td class="nowrap"><a href="'.DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$objp->pid.'">'.img_object($langs->trans('ShowPayment'), 'payment').' '.$objp->pid.'</a></td>';
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
|
||||
|
||||
// Date
|
||||
$dateformatforpayment = 'day';
|
||||
if (! empty($conf->global->INVOICE_USE_HOURS_FOR_PAYMENT)) $dateformatforpayment='dayhour';
|
||||
print '<td class="nowrap center">'.dol_print_date($db->jdate($objp->dp), $dateformatforpayment)."</td>\n";
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
|
||||
|
||||
// Thirdparty
|
||||
print '<td>';
|
||||
if ($objp->socid) print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$objp->socid.'">'.img_object($langs->trans('ShowCompany'), 'company').' '.dol_trunc($objp->name, 32).'</a>';
|
||||
else print ' ';
|
||||
print '</td>';
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
|
||||
|
||||
// Type
|
||||
$payment_type = $langs->trans("PaymentType".$objp->paiement_type)!=("PaymentType".$objp->paiement_type)?$langs->trans("PaymentType".$objp->paiement_type):$objp->paiement_libelle;
|
||||
print '<td>'.$payment_type.' '.dol_trunc($objp->num_paiement, 32)."</td>\n";
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
|
||||
|
||||
// Payment number
|
||||
print '<td>'.$objp->num_paiement.'</td>';
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
|
||||
|
||||
// Account
|
||||
if (! empty($conf->banque->enabled))
|
||||
{
|
||||
@ -987,13 +1012,13 @@ if (empty($action) || $action == 'list')
|
||||
print '</td>';
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
}
|
||||
|
||||
|
||||
// Amount
|
||||
print '<td class="right">'.price($objp->pamount).'</td>';
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
$totalarray['pos'][7]='amount';
|
||||
$totalarray['val']['amount'] += $objp->pamount;
|
||||
|
||||
|
||||
// Ref invoice
|
||||
/*$invoicesupplierstatic->ref=$objp->ref_supplier;
|
||||
$invoicesupplierstatic->id=$objp->facid;
|
||||
@ -1003,11 +1028,11 @@ if (empty($action) || $action == 'list')
|
||||
|
||||
print '<td></td>';
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
|
||||
|
||||
print '</tr>';
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
// Show total line
|
||||
if (isset($totalarray['pos']))
|
||||
{
|
||||
@ -1029,7 +1054,7 @@ if (empty($action) || $action == 'list')
|
||||
}
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
|
||||
print "</table>";
|
||||
print "</div>";
|
||||
print "</form>\n";
|
||||
|
||||
@ -61,6 +61,8 @@ CREATE TABLE llx_pos_cash_fence(
|
||||
-- For 10.0
|
||||
|
||||
DROP TABLE llx_cotisation;
|
||||
ALTER TABLE llx_accounting_bookkeeping DROP COLUMN validated;
|
||||
ALTER TABLE llx_accounting_bookkeeping_tmp DROP COLUMN validated;
|
||||
|
||||
ALTER TABLE llx_loan ADD COLUMN insurance_amount double(24,8) DEFAULT 0;
|
||||
|
||||
|
||||
@ -49,8 +49,7 @@ CREATE TABLE llx_accounting_bookkeeping
|
||||
code_journal varchar(32) NOT NULL, -- FEC:JournalCode
|
||||
journal_label varchar(255), -- FEC:JournalLib
|
||||
piece_num integer NOT NULL, -- FEC:EcritureNum | accounting source document
|
||||
validated tinyint DEFAULT 0 NOT NULL, -- | 0 line not validated / 1 line validated (No deleting / No modification)
|
||||
date_validated datetime, -- FEC:ValidDate
|
||||
date_validated datetime, -- FEC:ValidDate | if empty: movement not validated / if not empty: movement validated (No deleting / No modification)
|
||||
import_key varchar(14),
|
||||
extraparams varchar(255) -- for other parameters with json format
|
||||
) ENGINE=innodb;
|
||||
|
||||
@ -49,8 +49,7 @@ CREATE TABLE llx_accounting_bookkeeping_tmp
|
||||
code_journal varchar(32) NOT NULL, -- FEC:JournalCode
|
||||
journal_label varchar(255), -- FEC:JournalLib
|
||||
piece_num integer NOT NULL, -- FEC:EcritureNum
|
||||
validated tinyint DEFAULT 0 NOT NULL, -- | 0 line not validated / 1 line validated (No deleting / No modification)
|
||||
date_validated datetime, -- FEC:ValidDate
|
||||
date_validated datetime, -- FEC:ValidDate | if empty: movement not validated / if not empty: movement validated (No deleting / No modification)
|
||||
import_key varchar(14),
|
||||
extraparams varchar(255) -- for other parameters with json format
|
||||
) ENGINE=innodb;
|
||||
|
||||
@ -156,11 +156,11 @@ CheckRejectedAndInvoicesReopened=Check returned and invoices reopened
|
||||
BankAccountModelModule=Document templates for bank accounts
|
||||
DocumentModelSepaMandate=Template of SEPA mandate. Useful for European countries in EEC only.
|
||||
DocumentModelBan=Template to print a page with BAN information.
|
||||
NewVariousPayment=New miscellaneous payments
|
||||
VariousPayment=Miscellaneous payments
|
||||
NewVariousPayment=New miscellaneous payment
|
||||
VariousPayment=Miscellaneous payment
|
||||
VariousPayments=Miscellaneous payments
|
||||
ShowVariousPayment=Show miscellaneous payments
|
||||
AddVariousPayment=Add miscellaneous payments
|
||||
ShowVariousPayment=Show miscellaneous payment
|
||||
AddVariousPayment=Add miscellaneous payment
|
||||
SEPAMandate=SEPA mandate
|
||||
YourSEPAMandate=Your SEPA mandate
|
||||
FindYourSEPAMandate=This is your SEPA mandate to authorize our company to make direct debit order to your bank. Return it signed (scan of the signed document) or send it by mail to
|
||||
|
||||
@ -66,4 +66,5 @@ History=History
|
||||
ValidateAndClose=Validate and close
|
||||
Terminal=Terminal
|
||||
NumberOfTerminals=Number of Terminals
|
||||
TerminalSelect=Select terminal you want to use:
|
||||
TerminalSelect=Select terminal you want to use:
|
||||
POSTicket=POS Ticket
|
||||
@ -1152,7 +1152,7 @@ function top_httphead($contenttype = 'text/html', $forcenocache = 0)
|
||||
$contentsecuritypolicy = $conf->global->MAIN_HTTP_CONTENT_SECURITY_POLICY;
|
||||
|
||||
if (! is_object($hookmanager)) $hookmanager = new HookManager($db);
|
||||
$hookmanager->initHooks("main");
|
||||
$hookmanager->initHooks(array("main"));
|
||||
|
||||
$parameters=array('contentsecuritypolicy'=>$contentsecuritypolicy);
|
||||
$result=$hookmanager->executeHooks('setContentSecurityPolicy', $parameters); // Note that $action and $object may have been modified by some hooks
|
||||
@ -1212,7 +1212,7 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr
|
||||
if (empty($disablehead))
|
||||
{
|
||||
if (! is_object($hookmanager)) $hookmanager = new HookManager($db);
|
||||
$hookmanager->initHooks("main");
|
||||
$hookmanager->initHooks(array("main"));
|
||||
|
||||
$ext='layout='.$conf->browser->layout.'&version='.urlencode(DOL_VERSION);
|
||||
|
||||
|
||||
@ -346,7 +346,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
print '<table class="border centpercent">'."\n";
|
||||
|
||||
// Common attributes
|
||||
//$keyforbreak='fieldkeytoswithonsecondcolumn';
|
||||
//$keyforbreak='fieldkeytoswitchonsecondcolumn';
|
||||
include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
|
||||
|
||||
// Other attributes
|
||||
|
||||
@ -673,9 +673,11 @@ SCRIPT;
|
||||
print '<tr><td>'.$langs->trans("SupplierReputation").'</td><td>';
|
||||
echo $form->selectarray('supplier_reputation', $object->reputations, $supplier_reputation?$supplier_reputation:$object->supplier_reputation);
|
||||
print '</td></tr>';
|
||||
if(!empty($conf->barcode->enabled)) {
|
||||
|
||||
// Option to define a transport cost on supplier price
|
||||
// Barcode
|
||||
if (! empty($conf->barcode->enabled))
|
||||
{
|
||||
// Option to define a transport cost on supplier price
|
||||
print '<tr>';
|
||||
print '<td>' . $langs->trans('BarcodeValue') . '</td>';
|
||||
print '<td><input class="flat" name="barcode" value="'.($rowid ? $object->fourn_barcode : '').'"></td>';
|
||||
@ -690,6 +692,7 @@ SCRIPT;
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
// Option to define a transport cost on supplier price
|
||||
if ($conf->global->PRODUCT_CHARGES)
|
||||
{
|
||||
@ -775,7 +778,7 @@ SCRIPT;
|
||||
$num = count($product_fourn_list);
|
||||
if (($num + ($offset * $limit)) < $nbtotalofrecords) $num++;
|
||||
|
||||
print_barre_liste($langs->trans('SupplierPrices'), $page, $_SERVEUR ['PHP_SELF'], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy.png', 0, '', '', $limit, 1);
|
||||
print_barre_liste($langs->trans('SupplierPrices'), $page, $_SERVER ['PHP_SELF'], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy.png', 0, '', '', $limit, 1);
|
||||
|
||||
// Suppliers list title
|
||||
print '<div class="div-table-responsive">';
|
||||
@ -819,7 +822,7 @@ SCRIPT;
|
||||
print '<tr class="oddeven">';
|
||||
|
||||
// Date from
|
||||
print '<td>'.dol_print_date($productfourn->date_creation, 'dayhour').'</td>';
|
||||
print '<td>'.dol_print_date(($productfourn->fourn_date_creation ? $productfourn->fourn_date_creation: $productfourn->date_creation), 'dayhour').'</td>';
|
||||
|
||||
// Supplier
|
||||
print '<td>'.$productfourn->getSocNomUrl(1, 'supplier').'</td>';
|
||||
@ -907,7 +910,6 @@ SCRIPT;
|
||||
|
||||
// Barcode type
|
||||
print '<td align="center">';
|
||||
|
||||
$productfourn->barcode_type = !empty($productfourn->fk_barcode_type) ? $productfourn->fk_barcode_type:0;
|
||||
$productfourn->fetch_barcode();
|
||||
print $productfourn->barcode_type_label?$productfourn->barcode_type_label:($productfourn->barcode?'<div class="warning">'.$langs->trans("SetDefaultBarcodeType").'<div>':'');
|
||||
@ -916,7 +918,7 @@ SCRIPT;
|
||||
|
||||
// Date
|
||||
print '<td align="right">';
|
||||
print dol_print_date($productfourn->date_modification, "dayhour");
|
||||
print dol_print_date(($productfourn->fourn_date_modification ? $productfourn->fourn_date_modification : $productfourn->date_modification), "dayhour");
|
||||
print '</td>';
|
||||
|
||||
if (is_object($hookmanager))
|
||||
|
||||
@ -1851,7 +1851,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES))
|
||||
|
||||
$backbutton='<a class="justalink" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '">' . $langs->trans("Back") . '</a>';
|
||||
|
||||
print_barre_liste($title, $page, $_SERVEUR['PHP_SELF'], $option, $sortfield, $sortorder, $backbutton, count($prodcustprice->lines), $nbtotalofrecords, 'title_accountancy.png');
|
||||
print_barre_liste($title, $page, $_SERVER['PHP_SELF'], $option, $sortfield, $sortorder, $backbutton, count($prodcustprice->lines), $nbtotalofrecords, 'title_accountancy.png');
|
||||
|
||||
if (count($prodcustprice->lines) > 0)
|
||||
{
|
||||
@ -1973,7 +1973,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES))
|
||||
|
||||
$option = '&search_soc=' . $search_soc . '&id=' . $object->id;
|
||||
|
||||
print_barre_liste($langs->trans('PriceByCustomer'), $page, $_SERVEUR ['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords, 'title_accountancy.png');
|
||||
print_barre_liste($langs->trans('PriceByCustomer'), $page, $_SERVER ['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords, 'title_accountancy.png');
|
||||
|
||||
print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="POST">';
|
||||
print '<input type="hidden" name="id" value="' . $object->id . '">';
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file class/societeaccount.class.php
|
||||
* \file societe/class/societeaccount.class.php
|
||||
* \ingroup societe
|
||||
* \brief This file is a CRUD class file for SocieteAccount (Create/Read/Update/Delete)
|
||||
*/
|
||||
|
||||
@ -428,7 +428,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
|
||||
|
||||
$option = '&socid=' . GETPOST('socid', 'int') . '&prodid=' . GETPOST('prodid', 'int');
|
||||
|
||||
print_barre_liste($langs->trans('PriceByCustomerLog'), $page, $_SERVEUR ['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords);
|
||||
print_barre_liste($langs->trans('PriceByCustomerLog'), $page, $_SERVER ['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords);
|
||||
|
||||
if (count($prodcustprice->lines) > 0) {
|
||||
|
||||
@ -519,7 +519,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
|
||||
|
||||
print '<!-- view specific price for each product -->'."\n";
|
||||
|
||||
print_barre_liste($langs->trans('PriceForEachProduct'), $page, $_SERVEUR['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords, '');
|
||||
print_barre_liste($langs->trans('PriceForEachProduct'), $page, $_SERVER['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords, '');
|
||||
|
||||
print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="POST">';
|
||||
print '<input type="hidden" name="id" value="' . $object->id . '">';
|
||||
@ -603,7 +603,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
|
||||
{
|
||||
$colspan=9;
|
||||
if ($user->rights->produit->supprimer || $user->rights->service->supprimer) $colspan+=1;
|
||||
print '<tr ' . $bc[false] . '><td colspan="'.$colspan.'">' . $langs->trans('None') . '</td></tr>';
|
||||
print '<tr class="oddeven"><td colspan="'.$colspan.'">' . $langs->trans('None') . '</td></tr>';
|
||||
}
|
||||
|
||||
print "</table>";
|
||||
|
||||
@ -37,6 +37,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
|
||||
|
||||
$langs->loadLangs(array("companies","website"));
|
||||
|
||||
$action = GETPOST('action', 'aZ09')?GETPOST('action', 'aZ09'):'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
|
||||
$show_files = GETPOST('show_files', 'int');
|
||||
$contextpage= GETPOST('contextpage', 'aZ')?GETPOST('contextpage', 'aZ'):'myobjectlist'; // To manage different context of search
|
||||
$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
|
||||
$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
|
||||
|
||||
$search_status=GETPOST('search_status');
|
||||
|
||||
// Security check
|
||||
@ -340,14 +346,14 @@ $objecttmp=new SocieteAccount($db);
|
||||
$trackid='thi'.$object->id;
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
|
||||
|
||||
if ($sall)
|
||||
/*if ($sall)
|
||||
{
|
||||
foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
|
||||
print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall) . join(', ', $fieldstosearchall).'</div>';
|
||||
}
|
||||
}*/
|
||||
|
||||
/*$moreforfilter = '';
|
||||
$moreforfilter.='<div class="divsearchfield">';
|
||||
$moreforfilter = '';
|
||||
/*$moreforfilter.='<div class="divsearchfield">';
|
||||
$moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
|
||||
$moreforfilter.= '</div>';*/
|
||||
|
||||
|
||||
@ -861,7 +861,7 @@ select.selectarrowonleft option {
|
||||
input, input[type=text], input[type=password], select, textarea {
|
||||
min-width: 20px;
|
||||
}
|
||||
input[type=text], input[type=password] {
|
||||
.trinputlogin input[type=text], input[type=password] {
|
||||
max-width: 180px;
|
||||
}
|
||||
.vmenu .searchform input {
|
||||
|
||||
118
phpstan.neon
Normal file
118
phpstan.neon
Normal file
@ -0,0 +1,118 @@
|
||||
parameters:
|
||||
bootstrap: %currentWorkingDirectory%/build/phpstan/bootstrap.php
|
||||
excludes_analyse:
|
||||
- %currentWorkingDirectory%/htdocs/includes/restler/framework/Luracast/Restler/AutoLoader.php
|
||||
- %currentWorkingDirectory%/htdocs/includes/*
|
||||
- %currentWorkingDirectory%/htdocs/*/class/api_*
|
||||
autoload_directories:
|
||||
- %currentWorkingDirectory%/htdocs/accountancy/class
|
||||
- %currentWorkingDirectory%/htdocs/adherents/class
|
||||
- %currentWorkingDirectory%/htdocs/api/class
|
||||
- %currentWorkingDirectory%/htdocs/asset/class
|
||||
- %currentWorkingDirectory%/htdocs/blockedlog/class
|
||||
- %currentWorkingDirectory%/htdocs/bom/class
|
||||
- %currentWorkingDirectory%/htdocs/bookmarks/class
|
||||
- %currentWorkingDirectory%/htdocs/cashdesk/class
|
||||
- %currentWorkingDirectory%/htdocs/categories/class
|
||||
- %currentWorkingDirectory%/htdocs/comm/action/class
|
||||
- %currentWorkingDirectory%/htdocs/comm/propal/class
|
||||
- %currentWorkingDirectory%/htdocs/commande/class
|
||||
- %currentWorkingDirectory%/htdocs/compta/bank/class
|
||||
- %currentWorkingDirectory%/htdocs/compta/cashcontrol/class
|
||||
- %currentWorkingDirectory%/htdocs/compta/deplacement/class
|
||||
- %currentWorkingDirectory%/htdocs/compta/facture/class
|
||||
- %currentWorkingDirectory%/htdocs/compta/localtax/class
|
||||
- %currentWorkingDirectory%/htdocs/compta/paiement/class
|
||||
- %currentWorkingDirectory%/htdocs/conf
|
||||
- %currentWorkingDirectory%/htdocs/contact/class
|
||||
- %currentWorkingDirectory%/htdocs/contrat/class
|
||||
- %currentWorkingDirectory%/htdocs/core/class
|
||||
- %currentWorkingDirectory%/htdocs/product/class
|
||||
- %currentWorkingDirectory%/htdocs/societe/class
|
||||
- %currentWorkingDirectory%/htdocs/user/class
|
||||
autoload_files: []
|
||||
featureToggles:
|
||||
subtractableTypes: false
|
||||
validateParameters: false
|
||||
fileExtensions:
|
||||
- php
|
||||
checkAlwaysTrueCheckTypeFunctionCall: false
|
||||
checkAlwaysTrueInstanceof: false
|
||||
checkAlwaysTrueStrictComparison: false
|
||||
checkClassCaseSensitivity: false
|
||||
checkFunctionArgumentTypes: false
|
||||
checkFunctionNameCase: false
|
||||
checkArgumentsPassedByReference: false
|
||||
checkMaybeUndefinedVariables: false
|
||||
checkNullables: false
|
||||
checkThisOnly: true
|
||||
checkUnionTypes: false
|
||||
checkExplicitMixedMissingReturn: false
|
||||
checkPhpDocMissingReturn: false
|
||||
reportMaybes: false
|
||||
reportMaybesInMethodSignatures: false
|
||||
reportStaticMethodSignatures: false
|
||||
polluteScopeWithLoopInitialAssignments: true
|
||||
polluteScopeWithAlwaysIterableForeach: true
|
||||
polluteCatchScopeWithTryAssignments: false
|
||||
reportMagicMethods: false
|
||||
reportMagicProperties: false
|
||||
ignoreErrors:
|
||||
-
|
||||
message: '#Call to an undefined method abcdef#'
|
||||
path: %currentWorkingDirectory%/dirtoignoreerror/*
|
||||
- '#Undefined variable: \$langs#'
|
||||
- '#Undefined variable: \$user#'
|
||||
- '#Undefined variable: \$db#'
|
||||
- '#Undefined variable: \$conf#'
|
||||
- '#Undefined variable: \$hookmanager#'
|
||||
internalErrorsCountLimit: 50
|
||||
cache:
|
||||
nodesByFileCountMax: 512
|
||||
nodesByStringCountMax: 512
|
||||
reportUnmatchedIgnoredErrors: true
|
||||
scopeClass: PHPStan\Analyser\Scope
|
||||
universalObjectCratesClasses:
|
||||
- stdClass
|
||||
- SimpleXMLElement
|
||||
earlyTerminatingMethodCalls: []
|
||||
memoryLimitFile: %tmpDir%/.memory_limit
|
||||
benchmarkFile: null
|
||||
dynamicConstantNames:
|
||||
- ICONV_IMPL
|
||||
- PHP_VERSION
|
||||
- PHP_MAJOR_VERSION
|
||||
- PHP_MINOR_VERSION
|
||||
- PHP_RELEASE_VERSION
|
||||
- PHP_VERSION_ID
|
||||
- PHP_EXTRA_VERSION
|
||||
- PHP_ZTS
|
||||
- PHP_DEBUG
|
||||
- PHP_MAXPATHLEN
|
||||
- PHP_OS
|
||||
- PHP_OS_FAMILY
|
||||
- PHP_SAPI
|
||||
- PHP_EOL
|
||||
- PHP_INT_MAX
|
||||
- PHP_INT_MIN
|
||||
- PHP_INT_SIZE
|
||||
- PHP_FLOAT_DIG
|
||||
- PHP_FLOAT_EPSILON
|
||||
- PHP_FLOAT_MIN
|
||||
- PHP_FLOAT_MAX
|
||||
- DEFAULT_INCLUDE_PATH
|
||||
- PEAR_INSTALL_DIR
|
||||
- PEAR_EXTENSION_DIR
|
||||
- PHP_EXTENSION_DIR
|
||||
- PHP_PREFIX
|
||||
- PHP_BINDIR
|
||||
- PHP_BINARY
|
||||
- PHP_MANDIR
|
||||
- PHP_LIBDIR
|
||||
- PHP_DATADIR
|
||||
- PHP_SYSCONFDIR
|
||||
- PHP_LOCALSTATEDIR
|
||||
- PHP_CONFIG_FILE_PATH
|
||||
- PHP_CONFIG_FILE_SCAN_DIR
|
||||
- PHP_SHLIB_SUFFIX
|
||||
- PHP_FD_SETSIZE
|
||||
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -10,7 +10,7 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
@ -18,200 +18,160 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/bank/export-bank-receipts.php
|
||||
* \ingroup bank
|
||||
* \brief Script file to export bank receipts into Excel files
|
||||
* \file scripts/bank/export-bank-receipts.php
|
||||
* \ingroup bank
|
||||
* \brief Script file to export bank receipts into Excel files
|
||||
*/
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Test if batch mode
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
require_once $path."../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
|
||||
require_once $path . "../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/core/lib/bank.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/compta/sociales/class/chargesociales.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/compta/tva/class/tva.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/fourn/class/paiementfourn.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/compta/tva/class/tva.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/compta/sociales/class/paymentsocialcontribution.class.php';
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
|
||||
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',', $argv));
|
||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||
|
||||
if (! isset($argv[3]) || ! $argv[3]) {
|
||||
print "Usage: ".$script_file." bank_ref [bank_receipt_number|all] (csv|tsv|excel|excel2007) [lang=xx_XX]\n";
|
||||
exit(-1);
|
||||
print "Usage: " . $script_file . " bank_ref [bank_receipt_number|all] (csv|tsv|excel|excel2007) [lang=xx_XX]\n";
|
||||
exit(- 1);
|
||||
}
|
||||
$bankref=$argv[1];
|
||||
$num=$argv[2];
|
||||
$model=$argv[3];
|
||||
$newlangid='en_EN'; // To force a new lang id
|
||||
|
||||
|
||||
$invoicestatic=new Facture($db);
|
||||
$invoicesupplierstatic=new FactureFournisseur($db);
|
||||
$societestatic=new Societe($db);
|
||||
$chargestatic=new ChargeSociales($db);
|
||||
$memberstatic=new Adherent($db);
|
||||
$paymentstatic=new Paiement($db);
|
||||
$paymentsupplierstatic=new PaiementFourn($db);
|
||||
$paymentsocialcontributionstatic=new PaymentSocialContribution($db);
|
||||
$paymentvatstatic=new Tva($db);
|
||||
$bankstatic=new Account($db);
|
||||
$banklinestatic=new AccountLine($db);
|
||||
$bankref = $argv[1];
|
||||
$num = $argv[2];
|
||||
$model = $argv[3];
|
||||
$newlangid = 'en_EN'; // To force a new lang id
|
||||
|
||||
$invoicestatic = new Facture($db);
|
||||
$invoicesupplierstatic = new FactureFournisseur($db);
|
||||
$societestatic = new Societe($db);
|
||||
$chargestatic = new ChargeSociales($db);
|
||||
$memberstatic = new Adherent($db);
|
||||
$paymentstatic = new Paiement($db);
|
||||
$paymentsupplierstatic = new PaiementFourn($db);
|
||||
$paymentsocialcontributionstatic = new PaymentSocialContribution($db);
|
||||
$paymentvatstatic = new Tva($db);
|
||||
$bankstatic = new Account($db);
|
||||
$banklinestatic = new AccountLine($db);
|
||||
|
||||
// Parse parameters
|
||||
foreach ($argv as $key => $value)
|
||||
{
|
||||
$found=false;
|
||||
foreach ($argv as $key => $value) {
|
||||
$found = false;
|
||||
|
||||
// Define options
|
||||
if (preg_match('/^lang=/i', $value))
|
||||
{
|
||||
$found=true;
|
||||
$valarray=explode('=', $value);
|
||||
$newlangid=$valarray[1];
|
||||
print 'Use language '.$newlangid.".\n";
|
||||
if (preg_match('/^lang=/i', $value)) {
|
||||
$found = true;
|
||||
$valarray = explode('=', $value);
|
||||
$newlangid = $valarray[1];
|
||||
print 'Use language ' . $newlangid . ".\n";
|
||||
}
|
||||
}
|
||||
$outputlangs = $langs;
|
||||
if (! empty($newlangid))
|
||||
{
|
||||
if ($outputlangs->defaultlang != $newlangid)
|
||||
{
|
||||
if (! empty($newlangid)) {
|
||||
if ($outputlangs->defaultlang != $newlangid) {
|
||||
$outputlangs = new Translate("", $conf);
|
||||
$outputlangs->setDefaultLang($newlangid);
|
||||
}
|
||||
}
|
||||
|
||||
// Load translation files required by the page
|
||||
$outputlangs->loadLangs(array("main", "companies", "bills", "banks", "members", "compta"));
|
||||
$outputlangs->loadLangs(array("main","companies","bills","banks","members","compta"));
|
||||
|
||||
$acct=new Account($db);
|
||||
$result=$acct->fetch('', $bankref);
|
||||
if ($result <= 0)
|
||||
{
|
||||
print "Failed to find bank account with ref ".$bankref.".\n";
|
||||
exit(-1);
|
||||
$acct = new Account($db);
|
||||
$result = $acct->fetch('', $bankref);
|
||||
if ($result <= 0) {
|
||||
print "Failed to find bank account with ref " . $bankref . ".\n";
|
||||
exit(- 1);
|
||||
} else {
|
||||
print "Export for bank account " . $acct->ref . " (" . $acct->label . ").\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print "Export for bank account ".$acct->ref." (".$acct->label.").\n";
|
||||
}
|
||||
|
||||
|
||||
// Creation de la classe d'export du model ExportXXX
|
||||
$dir = DOL_DOCUMENT_ROOT . "/core/modules/export/";
|
||||
$file = "export_".$model.".modules.php";
|
||||
$classname = "Export".$model;
|
||||
if (! dol_is_file($dir.$file))
|
||||
{
|
||||
print "No driver to export with format ".$model."\n";
|
||||
exit(-1);
|
||||
$file = "export_" . $model . ".modules.php";
|
||||
$classname = "Export" . $model;
|
||||
if (! dol_is_file($dir . $file)) {
|
||||
print "No driver to export with format " . $model . "\n";
|
||||
exit(- 1);
|
||||
}
|
||||
require_once $dir.$file;
|
||||
require_once $dir . $file;
|
||||
$objmodel = new $classname($db);
|
||||
|
||||
|
||||
// Define target path
|
||||
$dirname = $conf->bank->dir_temp;
|
||||
$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_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'
|
||||
);
|
||||
$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_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
|
||||
$listofnum="";
|
||||
if (! empty($num) && $num != "all")
|
||||
{
|
||||
$listofnum.="'";
|
||||
$arraynum=explode(',', $num);
|
||||
foreach($arraynum as $val)
|
||||
{
|
||||
if ($listofnum != "'") $listofnum.="','";
|
||||
$listofnum.=$val;
|
||||
$listofnum = "";
|
||||
if (! empty($num) && $num != "all") {
|
||||
$listofnum .= "'";
|
||||
$arraynum = explode(',', $num);
|
||||
foreach ($arraynum as $val) {
|
||||
if ($listofnum != "'")
|
||||
$listofnum .= "','";
|
||||
$listofnum .= $val;
|
||||
}
|
||||
$listofnum.="'";
|
||||
$listofnum .= "'";
|
||||
}
|
||||
$sql = "SELECT b.rowid, b.dateo as do, b.datev as dv,";
|
||||
$sql.= " b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,";
|
||||
$sql.= " ba.rowid as bankid, ba.ref as bankref, ba.label as banklabel";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."bank as b";
|
||||
$sql.= " WHERE b.fk_account = ".$acct->id;
|
||||
if ($listofnum) $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.= $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;
|
||||
$sql .= " b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,";
|
||||
$sql .= " ba.rowid as bankid, ba.ref as bankref, ba.label as banklabel";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "bank_account as ba";
|
||||
$sql .= ", " . MAIN_DB_PREFIX . "bank as b";
|
||||
$sql .= " WHERE b.fk_account = " . $acct->id;
|
||||
if ($listofnum)
|
||||
$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 .= $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;
|
||||
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$balancebefore=array();
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$balancebefore = array();
|
||||
|
||||
$numrows = $db->num_rows($resql);
|
||||
|
||||
if ($numrows > 0)
|
||||
{
|
||||
if ($numrows > 0) {
|
||||
// Open file
|
||||
print 'Open file '.$filename.' into directory '.$dirname."\n";
|
||||
print 'Open file ' . $filename . ' into directory ' . $dirname . "\n";
|
||||
dol_mkdir($dirname);
|
||||
$result=$objmodel->open_file($dirname."/".$filename, $outputlangs);
|
||||
$result = $objmodel->open_file($dirname . "/" . $filename, $outputlangs);
|
||||
|
||||
if ($result < 0)
|
||||
{
|
||||
print 'Failed to create file '.$filename.' into dir '.$dirname.'.'."\n";
|
||||
return -1;
|
||||
if ($result < 0) {
|
||||
print 'Failed to create file ' . $filename . ' into dir ' . $dirname . '.' . "\n";
|
||||
return - 1;
|
||||
}
|
||||
|
||||
// Genere en-tete
|
||||
@ -221,35 +181,30 @@ if ($resql)
|
||||
$objmodel->write_title($array_fields, $array_selected, $outputlangs, $array_export_TypeFields);
|
||||
}
|
||||
|
||||
$i=0;
|
||||
while ($i < $numrows)
|
||||
{
|
||||
$thirdparty='';
|
||||
$accountelem='';
|
||||
$comment='';
|
||||
$i = 0;
|
||||
while ($i < $numrows) {
|
||||
$thirdparty = '';
|
||||
$accountelem = '';
|
||||
$comment = '';
|
||||
|
||||
$objp = $db->fetch_object($resql);
|
||||
|
||||
// Calculate start balance
|
||||
if (! isset($balancebefore[$objp->num_releve]))
|
||||
{
|
||||
print 'Calculate start balance for receipt '.$objp->num_releve."\n";
|
||||
if (! isset($balancebefore[$objp->num_releve])) {
|
||||
print 'Calculate start balance for receipt ' . $objp->num_releve . "\n";
|
||||
|
||||
$sql2 = "SELECT sum(b.amount) as amount";
|
||||
$sql2.= " FROM ".MAIN_DB_PREFIX."bank as b";
|
||||
$sql2.= " WHERE b.num_releve < '".$db->escape($objp->num_releve)."'";
|
||||
$sql2.= " AND b.fk_account = ".$objp->bankid;
|
||||
$resql2=$db->query($sql2);
|
||||
if ($resql2)
|
||||
{
|
||||
$obj2=$db->fetch_object($resql2);
|
||||
$balancebefore[$objp->num_releve] = ($obj2->amount?$obj2->amount:0);
|
||||
$sql2 .= " FROM " . MAIN_DB_PREFIX . "bank as b";
|
||||
$sql2 .= " WHERE b.num_releve < '" . $db->escape($objp->num_releve) . "'";
|
||||
$sql2 .= " AND b.fk_account = " . $objp->bankid;
|
||||
$resql2 = $db->query($sql2);
|
||||
if ($resql2) {
|
||||
$obj2 = $db->fetch_object($resql2);
|
||||
$balancebefore[$objp->num_releve] = ($obj2->amount ? $obj2->amount : 0);
|
||||
$db->free($resql2);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
$total = $balancebefore[$objp->num_releve];
|
||||
@ -258,168 +213,153 @@ if ($resql)
|
||||
$totalbefore = $total;
|
||||
$total = $total + $objp->amount;
|
||||
|
||||
|
||||
|
||||
// Date operation
|
||||
$dateop=$db->jdate($objp->do);
|
||||
$dateop = $db->jdate($objp->do);
|
||||
|
||||
// Date de valeur
|
||||
$datevalue=$db->jdate($objp->dv);
|
||||
$datevalue = $db->jdate($objp->dv);
|
||||
|
||||
// Num cheque
|
||||
$numchq=($objp->num_chq?$objp->num_chq:'');
|
||||
$numchq = ($objp->num_chq ? $objp->num_chq : '');
|
||||
|
||||
// Libelle
|
||||
$reg=array();
|
||||
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]);
|
||||
else $description=$objp->label;
|
||||
$reg = array();
|
||||
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]);
|
||||
else
|
||||
$description = $objp->label;
|
||||
|
||||
/*
|
||||
* Ajout les liens (societe, company...)
|
||||
*/
|
||||
$links = $acct->get_url($objp->rowid);
|
||||
foreach($links as $key=>$val)
|
||||
{
|
||||
if ($links[$key]['type']=='payment')
|
||||
{
|
||||
foreach ($links as $key => $val) {
|
||||
if ($links[$key]['type'] == 'payment') {
|
||||
$paymentstatic->fetch($links[$key]['url_id']);
|
||||
$tmparray=$paymentstatic->getBillsArray('');
|
||||
if (is_array($tmparray))
|
||||
{
|
||||
foreach($tmparray as $key => $val)
|
||||
{
|
||||
$tmparray = $paymentstatic->getBillsArray('');
|
||||
if (is_array($tmparray)) {
|
||||
foreach ($tmparray as $key => $val) {
|
||||
$invoicestatic->fetch($val);
|
||||
if ($accountelem) $accountelem.= ', ';
|
||||
$accountelem.=$invoicestatic->ref;
|
||||
if ($accountelem)
|
||||
$accountelem .= ', ';
|
||||
$accountelem .= $invoicestatic->ref;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ($links[$key]['type']=='payment_supplier')
|
||||
{
|
||||
} elseif ($links[$key]['type'] == 'payment_supplier') {
|
||||
$paymentsupplierstatic->fetch($links[$key]['url_id']);
|
||||
$tmparray=$paymentsupplierstatic->getBillsArray('');
|
||||
if (is_array($tmparray))
|
||||
{
|
||||
foreach($tmparray as $key => $val)
|
||||
{
|
||||
$tmparray = $paymentsupplierstatic->getBillsArray('');
|
||||
if (is_array($tmparray)) {
|
||||
foreach ($tmparray as $key => $val) {
|
||||
$invoicesupplierstatic->fetch($val);
|
||||
if ($accountelem) $accountelem.= ', ';
|
||||
$accountelem.=$invoicesupplierstatic->ref;
|
||||
if ($accountelem)
|
||||
$accountelem .= ', ';
|
||||
$accountelem .= $invoicesupplierstatic->ref;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ($links[$key]['type']=='payment_sc')
|
||||
{
|
||||
} elseif ($links[$key]['type'] == 'payment_sc') {
|
||||
$paymentsocialcontributionstatic->fetch($links[$key]['url_id']);
|
||||
if ($accountelem) $accountelem.= ', ';
|
||||
$accountelem.=$langs->transnoentitiesnoconv("SocialContribution").' '.$paymentsocialcontributionstatic->ref;
|
||||
}
|
||||
elseif ($links[$key]['type']=='payment_vat')
|
||||
{
|
||||
if ($accountelem)
|
||||
$accountelem .= ', ';
|
||||
$accountelem .= $langs->transnoentitiesnoconv("SocialContribution") . ' ' . $paymentsocialcontributionstatic->ref;
|
||||
} elseif ($links[$key]['type'] == 'payment_vat') {
|
||||
$paymentvatstatic->fetch($links[$key]['url_id']);
|
||||
if ($accountelem) $accountelem.= ', ';
|
||||
$accountelem.=$langs->transnoentitiesnoconv("VATPayments").' '.$paymentvatstatic->ref;
|
||||
}
|
||||
elseif ($links[$key]['type']=='banktransfert')
|
||||
{
|
||||
$comment=$outputlangs->transnoentitiesnoconv("Transfer");
|
||||
if ($objp->amount > 0)
|
||||
{
|
||||
if ($comment) $comment.= ' ';
|
||||
if ($accountelem)
|
||||
$accountelem .= ', ';
|
||||
$accountelem .= $langs->transnoentitiesnoconv("VATPayments") . ' ' . $paymentvatstatic->ref;
|
||||
} elseif ($links[$key]['type'] == 'banktransfert') {
|
||||
$comment = $outputlangs->transnoentitiesnoconv("Transfer");
|
||||
if ($objp->amount > 0) {
|
||||
if ($comment)
|
||||
$comment .= ' ';
|
||||
$banklinestatic->fetch($links[$key]['url_id']);
|
||||
$bankstatic->id=$banklinestatic->fk_account;
|
||||
$bankstatic->label=$banklinestatic->bank_account_label;
|
||||
$comment.= ' ('.$langs->transnoentitiesnoconv("from").' ';
|
||||
$comment.= $bankstatic->getNomUrl(1, 'transactions');
|
||||
$comment.= ' '.$langs->transnoentitiesnoconv("toward").' ';
|
||||
$bankstatic->id=$objp->bankid;
|
||||
$bankstatic->label=$objp->bankref;
|
||||
$comment.= $bankstatic->getNomUrl(1, '');
|
||||
$comment.= ')';
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($comment) $comment.= ' ';
|
||||
$bankstatic->id=$objp->bankid;
|
||||
$bankstatic->label=$objp->bankref;
|
||||
$comment.= ' ('.$langs->transnoentitiesnoconv("from").' ';
|
||||
$comment.= $bankstatic->getNomUrl(1, '');
|
||||
$comment.= ' '.$langs->transnoentitiesnoconv("toward").' ';
|
||||
$bankstatic->id = $banklinestatic->fk_account;
|
||||
$bankstatic->label = $banklinestatic->bank_account_label;
|
||||
$comment .= ' (' . $langs->transnoentitiesnoconv("from") . ' ';
|
||||
$comment .= $bankstatic->getNomUrl(1, 'transactions');
|
||||
$comment .= ' ' . $langs->transnoentitiesnoconv("toward") . ' ';
|
||||
$bankstatic->id = $objp->bankid;
|
||||
$bankstatic->label = $objp->bankref;
|
||||
$comment .= $bankstatic->getNomUrl(1, '');
|
||||
$comment .= ')';
|
||||
} else {
|
||||
if ($comment)
|
||||
$comment .= ' ';
|
||||
$bankstatic->id = $objp->bankid;
|
||||
$bankstatic->label = $objp->bankref;
|
||||
$comment .= ' (' . $langs->transnoentitiesnoconv("from") . ' ';
|
||||
$comment .= $bankstatic->getNomUrl(1, '');
|
||||
$comment .= ' ' . $langs->transnoentitiesnoconv("toward") . ' ';
|
||||
$banklinestatic->fetch($links[$key]['url_id']);
|
||||
$bankstatic->id=$banklinestatic->fk_account;
|
||||
$bankstatic->label=$banklinestatic->bank_account_label;
|
||||
$comment.= $bankstatic->getNomUrl(1, 'transactions');
|
||||
$comment.= ')';
|
||||
$bankstatic->id = $banklinestatic->fk_account;
|
||||
$bankstatic->label = $banklinestatic->bank_account_label;
|
||||
$comment .= $bankstatic->getNomUrl(1, 'transactions');
|
||||
$comment .= ')';
|
||||
}
|
||||
} elseif ($links[$key]['type'] == 'company') {
|
||||
if ($thirdparty)
|
||||
$thirdparty .= ', ';
|
||||
$thirdparty .= dol_trunc($links[$key]['label'], 24);
|
||||
$newline = 0;
|
||||
} elseif ($links[$key]['type'] == 'member') {
|
||||
if ($thirdparty)
|
||||
$accountelem .= ', ';
|
||||
$thirdparty .= $links[$key]['label'];
|
||||
$newline = 0;
|
||||
}
|
||||
elseif ($links[$key]['type']=='company')
|
||||
{
|
||||
if ($thirdparty) $thirdparty.= ', ';
|
||||
$thirdparty.= dol_trunc($links[$key]['label'], 24);
|
||||
$newline=0;
|
||||
}
|
||||
elseif ($links[$key]['type']=='member')
|
||||
{
|
||||
if ($thirdparty) $accountelem.= ', ';
|
||||
$thirdparty.= $links[$key]['label'];
|
||||
$newline=0;
|
||||
}
|
||||
/*elseif ($links[$key]['type']=='sc')
|
||||
{
|
||||
if ($accountelem) $accountelem.= ', ';
|
||||
//$accountelem.= '<a href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$links[$key]['url_id'].'">';
|
||||
//$accountelem.= img_object($langs->transnoentitiesnoconv('ShowBill'),'bill').' ';
|
||||
$accountelem.= $langs->transnoentitiesnoconv("SocialContribution");
|
||||
//$accountelem.= '</a>';
|
||||
$newline=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($accountelem) $accountelem.= ', ';
|
||||
//$accountelem.= '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">';
|
||||
$accountelem.= $links[$key]['label'];
|
||||
//$accountelem.= '</a>';
|
||||
$newline=0;
|
||||
}*/
|
||||
/*
|
||||
* elseif ($links[$key]['type']=='sc')
|
||||
* {
|
||||
* if ($accountelem) $accountelem.= ', ';
|
||||
* //$accountelem.= '<a href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$links[$key]['url_id'].'">';
|
||||
* //$accountelem.= img_object($langs->transnoentitiesnoconv('ShowBill'),'bill').' ';
|
||||
* $accountelem.= $langs->transnoentitiesnoconv("SocialContribution");
|
||||
* //$accountelem.= '</a>';
|
||||
* $newline=0;
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* if ($accountelem) $accountelem.= ', ';
|
||||
* //$accountelem.= '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">';
|
||||
* $accountelem.= $links[$key]['label'];
|
||||
* //$accountelem.= '</a>';
|
||||
* $newline=0;
|
||||
* }
|
||||
*/
|
||||
}
|
||||
|
||||
$debit=$credit='';
|
||||
if ($objp->amount < 0)
|
||||
{
|
||||
$debit = $credit = '';
|
||||
if ($objp->amount < 0) {
|
||||
$totald = $totald + abs($objp->amount);
|
||||
$debit=price2num($objp->amount * -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
$debit = price2num($objp->amount * - 1);
|
||||
} else {
|
||||
$totalc = $totalc + abs($objp->amount);
|
||||
$credit=price2num($objp->amount);
|
||||
$credit = price2num($objp->amount);
|
||||
}
|
||||
|
||||
$i++;
|
||||
$i ++;
|
||||
|
||||
$rec=new stdClass();
|
||||
$rec->bankreceipt=$objp->num_releve;
|
||||
$rec->bankaccount=$objp->banklabel;
|
||||
$rec->dateop=dol_print_date($dateop, 'dayrfc');
|
||||
$rec->dateval=dol_print_date($datevalue, 'dayrfc');
|
||||
$rec->type=$objp->fk_type.' '.($objp->num_chq?$objp->num_chq:'');
|
||||
$rec->description=$description;
|
||||
$rec->thirdparty=$thirdparty;
|
||||
$rec->accountelem=$accountelem;
|
||||
$rec->debit=$debit;
|
||||
$rec->credit=$credit;
|
||||
$rec->comment=$comment;
|
||||
$rec->soldbefore=price2num($totalbefore);
|
||||
$rec->soldafter=price2num($total);
|
||||
$rec = new stdClass();
|
||||
$rec->bankreceipt = $objp->num_releve;
|
||||
$rec->bankaccount = $objp->banklabel;
|
||||
$rec->dateop = dol_print_date($dateop, 'dayrfc');
|
||||
$rec->dateval = dol_print_date($datevalue, 'dayrfc');
|
||||
$rec->type = $objp->fk_type . ' ' . ($objp->num_chq ? $objp->num_chq : '');
|
||||
$rec->description = $description;
|
||||
$rec->thirdparty = $thirdparty;
|
||||
$rec->accountelem = $accountelem;
|
||||
$rec->debit = $debit;
|
||||
$rec->credit = $credit;
|
||||
$rec->comment = $comment;
|
||||
$rec->soldbefore = price2num($totalbefore);
|
||||
$rec->soldafter = price2num($total);
|
||||
|
||||
// end of special operation processing
|
||||
$objmodel->write_record($array_selected, $rec, $outputlangs, $array_export_TypeFields);
|
||||
}
|
||||
|
||||
if ($numrows > 0)
|
||||
{
|
||||
print "Found ".$numrows." records for receipt ".$num."\n";
|
||||
if ($numrows > 0) {
|
||||
print "Found " . $numrows . " records for receipt " . $num . "\n";
|
||||
|
||||
// Genere en-tete
|
||||
$objmodel->write_footer($outputlangs);
|
||||
@ -427,21 +367,17 @@ if ($resql)
|
||||
// Close file
|
||||
$objmodel->close_file();
|
||||
|
||||
print 'File '.$filename.' was generated into dir '.$dirname.'.'."\n";
|
||||
print 'File ' . $filename . ' was generated into dir ' . $dirname . '.' . "\n";
|
||||
|
||||
$ret=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
print "No records found for receipt ".$num."\n";
|
||||
$ret = 0;
|
||||
} else {
|
||||
print "No records found for receipt " . $num . "\n";
|
||||
|
||||
$ret=0;
|
||||
$ret = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
$ret=-1;
|
||||
$ret = - 1;
|
||||
}
|
||||
|
||||
$db->close();
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2009-2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2009-2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -11,7 +11,7 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
@ -19,52 +19,49 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/company/export-contacts-xls-example.php
|
||||
* \ingroup company
|
||||
* \brief Script file to export contacts into an Excel file
|
||||
* \file scripts/company/export-contacts-xls-example.php
|
||||
* \ingroup company
|
||||
* \brief Script file to export contacts into an Excel file
|
||||
*/
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Test if batch mode
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
if (! isset($argv[1]) || ! $argv[1]) {
|
||||
print "Usage: $script_file now\n";
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
$now=$argv[1];
|
||||
$now = $argv[1];
|
||||
|
||||
require_once $path . "../../htdocs/master.inc.php";
|
||||
// require_once PHP_WRITEEXCEL_PATH."/class.writeexcel_workbook.inc.php";
|
||||
// require_once PHP_WRITEEXCEL_PATH."/class.writeexcel_worksheet.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_worksheet.inc.php";
|
||||
|
||||
require_once PHPEXCEL_PATH."/PHPExcel.php";
|
||||
//require_once PHPEXCEL_PATH."/PHPExcel/Writer/Excel2007.php";
|
||||
require_once PHPEXCEL_PATH."/PHPExcel/Writer/Excel5.php";
|
||||
require_once PHPEXCEL_PATH . "/PHPExcel.php";
|
||||
// require_once PHPEXCEL_PATH."/PHPExcel/Writer/Excel2007.php";
|
||||
require_once PHPEXCEL_PATH . "/PHPExcel/Writer/Excel5.php";
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',', $argv));
|
||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||
|
||||
$fname = DOL_DATA_ROOT.'/export-contacts.xls';
|
||||
$fname = DOL_DATA_ROOT . '/export-contacts.xls';
|
||||
|
||||
//$objPHPExcel = new writeexcel_workbook($fname);
|
||||
// $objPHPExcel = new writeexcel_workbook($fname);
|
||||
$objPHPExcel = new PHPExcel();
|
||||
$objPHPExcel->getProperties()->setCreator("Dolibarr script");
|
||||
$objPHPExcel->getProperties()->setLastModifiedBy("Dolibarr script");
|
||||
@ -72,23 +69,21 @@ $objPHPExcel->getProperties()->setTitle("Test Document");
|
||||
$objPHPExcel->getProperties()->setSubject("Test Document");
|
||||
$objPHPExcel->getProperties()->setDescription("Test document, generated using PHP classes.");
|
||||
|
||||
|
||||
//$page = &$objPHPExcel->addworksheet('Export Dolibarr');
|
||||
// $page = &$objPHPExcel->addworksheet('Export Dolibarr');
|
||||
$objPHPExcel->setActiveSheetIndex(0);
|
||||
$objPHPExcel->getActiveSheet()->setTitle('Contacts');
|
||||
|
||||
//$page->set_column(0,4,18); // A
|
||||
// $page->set_column(0,4,18); // A
|
||||
|
||||
$sql = "SELECT distinct c.lastname, c.firstname, c.email, s.nom as name";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on s.rowid = c.fk_soc";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "socpeople as c";
|
||||
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s on s.rowid = c.fk_soc";
|
||||
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
|
||||
print "Lines ".$num."\n";
|
||||
print "Lines " . $num . "\n";
|
||||
|
||||
$i = 0;
|
||||
$j = 1;
|
||||
@ -98,27 +93,25 @@ if ($resql)
|
||||
$objPHPExcel->getActiveSheet()->SetCellValue('C1', $langs->trans("Email"));
|
||||
$objPHPExcel->getActiveSheet()->SetCellValue('D1', $langs->trans("ThirdPart"));
|
||||
|
||||
while ($i < $num)
|
||||
{
|
||||
while ($i < $num) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->SetCellValue('A'.($i+2), $obj->firstname);
|
||||
$objPHPExcel->getActiveSheet()->SetCellValue('B'.($i+2), $obj->lastname);
|
||||
$objPHPExcel->getActiveSheet()->SetCellValue('C'.($i+2), $obj->email);
|
||||
$objPHPExcel->getActiveSheet()->SetCellValue('D'.($i+2), $obj->name);
|
||||
$objPHPExcel->getActiveSheet()->SetCellValue('A' . ($i + 2), $obj->firstname);
|
||||
$objPHPExcel->getActiveSheet()->SetCellValue('B' . ($i + 2), $obj->lastname);
|
||||
$objPHPExcel->getActiveSheet()->SetCellValue('C' . ($i + 2), $obj->email);
|
||||
$objPHPExcel->getActiveSheet()->SetCellValue('D' . ($i + 2), $obj->name);
|
||||
|
||||
$j++;
|
||||
$i++;
|
||||
$j ++;
|
||||
$i ++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
|
||||
// $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
|
||||
$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
|
||||
$objWriter->save($fname);
|
||||
|
||||
//$objPHPExcel->close();
|
||||
// $objPHPExcel->close();
|
||||
|
||||
print 'File '.$fname.' was generated.'."\n";
|
||||
print 'File ' . $fname . ' was generated.' . "\n";
|
||||
|
||||
exit(0);
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006-2009 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006-2009 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -11,7 +11,7 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
@ -19,74 +19,70 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/company/sync_contacts_dolibarr2ldap.php
|
||||
* \ingroup ldap company
|
||||
* \brief Script to update all contacts from Dolibarr into a LDAP database
|
||||
* \file scripts/company/sync_contacts_dolibarr2ldap.php
|
||||
* \ingroup ldap company
|
||||
* \brief Script to update all contacts from Dolibarr into a LDAP database
|
||||
*/
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Test if batch mode
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
|
||||
require_once $path."../../htdocs/master.inc.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."/core/class/ldap.class.php";
|
||||
require_once $path . "../../htdocs/master.inc.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 . "/core/class/ldap.class.php";
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
$confirmed=0;
|
||||
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
$confirmed = 0;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',', $argv));
|
||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||
|
||||
if (! isset($argv[1]) || ! $argv[1]) {
|
||||
print "Usage: $script_file now [-y]\n";
|
||||
exit(-1);
|
||||
print "Usage: $script_file now [-y]\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
foreach($argv as $key => $val)
|
||||
{
|
||||
if (preg_match('/-y$/', $val, $reg)) $confirmed=1;
|
||||
foreach ($argv as $key => $val) {
|
||||
if (preg_match('/-y$/', $val, $reg))
|
||||
$confirmed = 1;
|
||||
}
|
||||
|
||||
$now=$argv[1];
|
||||
$now = $argv[1];
|
||||
|
||||
print "Mails sending disabled (useless in batch mode)\n";
|
||||
$conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails
|
||||
$conf->global->MAIN_DISABLE_ALL_MAILS = 1; // On bloque les mails
|
||||
print "\n";
|
||||
print "----- Synchronize all records from Dolibarr database:\n";
|
||||
print "type=".$conf->db->type."\n";
|
||||
print "host=".$conf->db->host."\n";
|
||||
print "port=".$conf->db->port."\n";
|
||||
print "login=".$conf->db->user."\n";
|
||||
//print "pass=".preg_replace('/./i','*',$conf->db->password)."\n"; // Not defined for security reasons
|
||||
print "database=".$conf->db->name."\n";
|
||||
print "type=" . $conf->db->type . "\n";
|
||||
print "host=" . $conf->db->host . "\n";
|
||||
print "port=" . $conf->db->port . "\n";
|
||||
print "login=" . $conf->db->user . "\n";
|
||||
// print "pass=".preg_replace('/./i','*',$conf->db->password)."\n"; // Not defined for security reasons
|
||||
print "database=" . $conf->db->name . "\n";
|
||||
print "\n";
|
||||
print "----- To LDAP database:\n";
|
||||
print "host=".$conf->global->LDAP_SERVER_HOST."\n";
|
||||
print "port=".$conf->global->LDAP_SERVER_PORT."\n";
|
||||
print "login=".$conf->global->LDAP_ADMIN_DN."\n";
|
||||
print "pass=".preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)."\n";
|
||||
print "DN target=".$conf->global->LDAP_CONTACT_DN."\n";
|
||||
print "host=" . $conf->global->LDAP_SERVER_HOST . "\n";
|
||||
print "port=" . $conf->global->LDAP_SERVER_PORT . "\n";
|
||||
print "login=" . $conf->global->LDAP_ADMIN_DN . "\n";
|
||||
print "pass=" . preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS) . "\n";
|
||||
print "DN target=" . $conf->global->LDAP_CONTACT_DN . "\n";
|
||||
print "\n";
|
||||
|
||||
if (! $confirmed)
|
||||
{
|
||||
if (! $confirmed) {
|
||||
print "Press a key to confirm...\n";
|
||||
$input = trim(fgets(STDIN));
|
||||
print "Warning, this operation may result in data loss if it failed.\n";
|
||||
@ -96,28 +92,26 @@ if (! $confirmed)
|
||||
}
|
||||
|
||||
/*
|
||||
if (! $conf->global->LDAP_CONTACT_ACTIVE)
|
||||
{
|
||||
print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
||||
exit(-1);
|
||||
}
|
||||
*/
|
||||
* if (! $conf->global->LDAP_CONTACT_ACTIVE)
|
||||
* {
|
||||
* print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
||||
* exit(-1);
|
||||
* }
|
||||
*/
|
||||
|
||||
$sql = "SELECT rowid";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."socpeople";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "socpeople";
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
|
||||
$ldap=new Ldap();
|
||||
$ldap = new Ldap();
|
||||
$ldap->connect_bind();
|
||||
|
||||
while ($i < $num)
|
||||
{
|
||||
$ldap->error="";
|
||||
while ($i < $num) {
|
||||
$ldap->error = "";
|
||||
|
||||
$obj = $db->fetch_object($resql);
|
||||
|
||||
@ -125,37 +119,32 @@ if ($resql)
|
||||
$contact->id = $obj->rowid;
|
||||
$contact->fetch($contact->id);
|
||||
|
||||
print $langs->trans("UpdateContact")." rowid=".$contact->id." ".$contact->getFullName($langs);
|
||||
print $langs->trans("UpdateContact") . " rowid=" . $contact->id . " " . $contact->getFullName($langs);
|
||||
|
||||
$oldobject=$contact;
|
||||
$oldobject = $contact;
|
||||
|
||||
$oldinfo=$oldobject->_load_ldap_info();
|
||||
$olddn=$oldobject->_load_ldap_dn($oldinfo);
|
||||
$oldinfo = $oldobject->_load_ldap_info();
|
||||
$olddn = $oldobject->_load_ldap_dn($oldinfo);
|
||||
|
||||
$info=$contact->_load_ldap_info();
|
||||
$dn=$contact->_load_ldap_dn($info);
|
||||
$info = $contact->_load_ldap_info();
|
||||
$dn = $contact->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->add($dn, $info, $user); // Wil fail if already exists
|
||||
$result=$ldap->update($dn, $info, $user, $olddn);
|
||||
if ($result > 0)
|
||||
{
|
||||
print " - ".$langs->trans("OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
print " - ".$langs->trans("KO").' - '.$ldap->error;
|
||||
$result = $ldap->add($dn, $info, $user); // Wil fail if already exists
|
||||
$result = $ldap->update($dn, $info, $user, $olddn);
|
||||
if ($result > 0) {
|
||||
print " - " . $langs->trans("OK");
|
||||
} else {
|
||||
$error ++;
|
||||
print " - " . $langs->trans("KO") . ' - ' . $ldap->error;
|
||||
}
|
||||
print "\n";
|
||||
|
||||
$i++;
|
||||
$i ++;
|
||||
}
|
||||
|
||||
$ldap->unbind();
|
||||
$ldap->close();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -12,7 +12,7 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
@ -20,297 +20,276 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/contracts/email_expire_services_to_customers.php
|
||||
* \ingroup facture
|
||||
* \brief Script to send a mail to customers with services to expire
|
||||
* \file scripts/contracts/email_expire_services_to_customers.php
|
||||
* \ingroup facture
|
||||
* \brief Script to send a mail to customers with services to expire
|
||||
*/
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Test si mode batch
|
||||
$sapi_type = php_sapi_name();
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
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 "\n";
|
||||
print "Send an email to customers to remind all contracts services to expire or expired.\n";
|
||||
print "If you choose 'test' mode, no emails are sent.\n";
|
||||
print "If you add param delay (nb of days), only services with expired date < today + delay are included.\n";
|
||||
print "If you add param after (nb of days), only services with expired date >= today + delay are included.\n";
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
$mode=$argv[1];
|
||||
$targettype=$argv[2];
|
||||
$mode = $argv[1];
|
||||
$targettype = $argv[2];
|
||||
|
||||
require $path . "../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/core/class/CMailFile.class.php";
|
||||
|
||||
require $path."../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php";
|
||||
|
||||
$langs->loadLangs(array('main', 'contracts'));
|
||||
$langs->loadLangs(array('main','contracts'));
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',', $argv));
|
||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||
|
||||
$now=dol_now('tzserver');
|
||||
$duration_value=isset($argv[3])?$argv[3]:'none';
|
||||
$duration_value2=isset($argv[4])?$argv[4]:'none';
|
||||
$now = dol_now('tzserver');
|
||||
$duration_value = isset($argv[3]) ? $argv[3] : 'none';
|
||||
$duration_value2 = isset($argv[4]) ? $argv[4] : 'none';
|
||||
|
||||
$error = 0;
|
||||
print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value)?" delay=".$duration_value:"").(is_numeric($duration_value2)?" after=".$duration_value2:"")."\n";
|
||||
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.= " 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";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe AS s";
|
||||
if ($targettype == 'contacts') $sql.= ", ".MAIN_DB_PREFIX."socpeople as sp";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."contrat AS c";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."contratdet AS cd";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product AS p ON p.rowid = cd.fk_product";
|
||||
$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";
|
||||
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";
|
||||
if ($targettype == 'contacts')
|
||||
$sql .= ", " . MAIN_DB_PREFIX . "socpeople as sp";
|
||||
$sql .= ", " . MAIN_DB_PREFIX . "contrat AS c";
|
||||
$sql .= ", " . MAIN_DB_PREFIX . "contratdet AS cd";
|
||||
$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";
|
||||
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_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";
|
||||
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
|
||||
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_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";
|
||||
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
|
||||
|
||||
//print $sql;
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
$oldemail = 'none'; $oldsid = 0; $oldcid = 0; $oldlang='';
|
||||
$total = 0; $foundtoprocess = 0;
|
||||
$trackthirdpartiessent = array();
|
||||
// print $sql;
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
$oldemail = 'none';
|
||||
$oldsid = 0;
|
||||
$oldcid = 0;
|
||||
$oldlang = '';
|
||||
$total = 0;
|
||||
$foundtoprocess = 0;
|
||||
$trackthirdpartiessent = array();
|
||||
|
||||
print "We found ".$num." couples (services to expire-".$targettype.") qualified\n";
|
||||
dol_syslog("We found ".$num." couples (services to expire-".$targettype.") qualified");
|
||||
$message='';
|
||||
print "We found " . $num . " couples (services to expire-" . $targettype . ") qualified\n";
|
||||
dol_syslog("We found " . $num . " couples (services to expire-" . $targettype . ") qualified");
|
||||
$message = '';
|
||||
|
||||
if ($num)
|
||||
{
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
if ($num) {
|
||||
while ($i < $num) {
|
||||
$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
|
||||
$startbreak=false;
|
||||
if ($newemail <> $oldemail || $oldemail == 'none') $startbreak=true;
|
||||
if ($obj->sid && $obj->sid <> $oldsid) $startbreak=true;
|
||||
if ($obj->cid && $obj->cid <> $oldcid) $startbreak=true;
|
||||
// Check if this record is a break after previous one
|
||||
$startbreak = false;
|
||||
if ($newemail != $oldemail || $oldemail == 'none')
|
||||
$startbreak = true;
|
||||
if ($obj->sid && $obj->sid != $oldsid)
|
||||
$startbreak = true;
|
||||
if ($obj->cid && $obj->cid != $oldcid)
|
||||
$startbreak = true;
|
||||
|
||||
if ($startbreak)
|
||||
{
|
||||
// Break onto sales representative (new email or cid)
|
||||
if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))
|
||||
{
|
||||
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldtarget, $duration_value);
|
||||
$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 print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
|
||||
}
|
||||
}
|
||||
$oldemail = $newemail;
|
||||
$oldsid = $obj->sid;
|
||||
$oldcid = $obj->cid;
|
||||
$oldlang = $obj->lang;
|
||||
$oldtarget=(empty($obj->cfirstname) && empty($obj->clastname))?$obj->name:($obj->clastname." ".$obj->cfirstname);
|
||||
$message = '';
|
||||
$total = 0;
|
||||
$foundtoprocess = 0;
|
||||
$target=(empty($obj->cfirstname) && empty($obj->clastname))?$obj->name:($obj->clastname." ".$obj->cfirstname);
|
||||
//if (empty($newemail)) print "Warning: Customer ".$target." has no email. Notice disabled.\n";
|
||||
}
|
||||
if ($startbreak) {
|
||||
// Break onto sales representative (new email or cid)
|
||||
if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid . '|' . $oldemail])) {
|
||||
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldtarget, $duration_value);
|
||||
$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
|
||||
print "- No email sent for '" . $oldtarget . "', total: " . $total . " (already sent to " . $trackthirdpartiessent[$oldsid . '|' . $oldemail] . ")\n";
|
||||
}
|
||||
}
|
||||
$oldemail = $newemail;
|
||||
$oldsid = $obj->sid;
|
||||
$oldcid = $obj->cid;
|
||||
$oldlang = $obj->lang;
|
||||
$oldtarget = (empty($obj->cfirstname) && empty($obj->clastname)) ? $obj->name : ($obj->clastname . " " . $obj->cfirstname);
|
||||
$message = '';
|
||||
$total = 0;
|
||||
$foundtoprocess = 0;
|
||||
$target = (empty($obj->cfirstname) && empty($obj->clastname)) ? $obj->name : ($obj->clastname . " " . $obj->cfirstname);
|
||||
// if (empty($newemail)) print "Warning: Customer ".$target." has no email. Notice disabled.\n";
|
||||
}
|
||||
|
||||
// Define line content
|
||||
$outputlangs=new Translate('', $conf);
|
||||
$outputlangs->setDefaultLang(empty($obj->default_lang)?$langs->defaultlang:$obj->default_lang); // By default language of customer
|
||||
// Define line content
|
||||
$outputlangs = new Translate('', $conf);
|
||||
$outputlangs->setDefaultLang(empty($obj->default_lang) ? $langs->defaultlang : $obj->default_lang); // By default language of customer
|
||||
|
||||
// Load translation files required by the page
|
||||
$outputlangs->loadLangs(array("main", "contracts", "bills", "products"));
|
||||
// Load translation files required by the page
|
||||
$outputlangs->loadLangs(array("main","contracts","bills","products"));
|
||||
|
||||
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";
|
||||
dol_syslog("email_expire_services_to_customers.php: ".$newemail." ".$message);
|
||||
$foundtoprocess++;
|
||||
}
|
||||
print "Service to expire ".$obj->ref.", label ".dol_concatdesc($obj->plabel, $obj->description).", due date ".dol_print_date($db->jdate($obj->date_fin_validite), 'day').", customer id ".$obj->sid." ".$obj->name.", ".($obj->cid?"contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", ":"")."email ".$newemail.", lang ".$outputlangs->defaultlang.": ";
|
||||
if (dol_strlen($newemail)) print "qualified.";
|
||||
else print "disqualified (no email).";
|
||||
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";
|
||||
dol_syslog("email_expire_services_to_customers.php: " . $newemail . " " . $message);
|
||||
$foundtoprocess ++;
|
||||
}
|
||||
print "Service to expire " . $obj->ref . ", label " . dol_concatdesc($obj->plabel, $obj->description) . ", due date " . dol_print_date($db->jdate($obj->date_fin_validite), 'day') . ", customer id " . $obj->sid . " " . $obj->name . ", " . ($obj->cid ? "contact id " . $obj->cid . " " . $obj->clastname . " " . $obj->cfirstname . ", " : "") . "email " . $newemail . ", lang " . $outputlangs->defaultlang . ": ";
|
||||
if (dol_strlen($newemail))
|
||||
print "qualified.";
|
||||
else
|
||||
print "disqualified (no email).";
|
||||
print "\n";
|
||||
|
||||
unset($outputlangs);
|
||||
unset($outputlangs);
|
||||
|
||||
$total += $obj->total_ttc;
|
||||
$total += $obj->total_ttc;
|
||||
|
||||
$i++;
|
||||
}
|
||||
$i ++;
|
||||
}
|
||||
|
||||
// Si il reste des envois en buffer
|
||||
if ($foundtoprocess)
|
||||
{
|
||||
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);
|
||||
$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
|
||||
}
|
||||
else
|
||||
// Si il reste des envois en buffer
|
||||
if ($foundtoprocess) {
|
||||
if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid . '|' . $oldemail])) // Break onto email (new email)
|
||||
{
|
||||
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
|
||||
{
|
||||
print "No services to expire found\n";
|
||||
}
|
||||
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldtarget, $duration_value);
|
||||
$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
|
||||
print "- No email sent for '" . $oldtarget . "', total: " . $total . " (already sent to " . $trackthirdpartiessent[$oldsid . '|' . $oldemail] . ")\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print "No services to expire found\n";
|
||||
}
|
||||
|
||||
exit(0);
|
||||
exit(0);
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
dol_syslog("email_expire_services_to_customers.php: Error");
|
||||
|
||||
exit(- 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
dol_syslog("email_expire_services_to_customers.php: Error");
|
||||
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send email
|
||||
* Send email
|
||||
*
|
||||
* @param string $mode Mode (test | confirm)
|
||||
* @param string $oldemail Target email
|
||||
* @param string $message 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
|
||||
* @param int $duration_value duration value
|
||||
* @return int <0 if KO, >0 if OK
|
||||
* @param string $mode Mode (test | confirm)
|
||||
* @param string $oldemail Target email
|
||||
* @param string $message 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
|
||||
* @param int $duration_value duration value
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
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->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang);
|
||||
$newlangs->load("main");
|
||||
$newlangs->load("contracts");
|
||||
$newlangs = new Translate('', $conf);
|
||||
$newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang);
|
||||
$newlangs->load("main");
|
||||
$newlangs->load("contracts");
|
||||
|
||||
if ($duration_value)
|
||||
{
|
||||
if ($duration_value > 0) $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration", $duration_value);
|
||||
else $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg", $duration_value);
|
||||
}
|
||||
else
|
||||
$title= $newlangs->transnoentities("ListOfServicesToExpire");
|
||||
if ($duration_value) {
|
||||
if ($duration_value > 0)
|
||||
$title = $newlangs->transnoentities("ListOfServicesToExpireWithDuration", $duration_value);
|
||||
else
|
||||
$title = $newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg", $duration_value);
|
||||
} else
|
||||
$title = $newlangs->transnoentities("ListOfServicesToExpire");
|
||||
|
||||
$subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT)?$title:$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT);
|
||||
$sendto = $oldemail;
|
||||
$from = $conf->global->MAIN_MAIL_EMAIL_FROM;
|
||||
$errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
|
||||
$msgishtml = -1;
|
||||
$subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT) ? $title : $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT);
|
||||
$sendto = $oldemail;
|
||||
$from = $conf->global->MAIN_MAIL_EMAIL_FROM;
|
||||
$errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
|
||||
$msgishtml = - 1;
|
||||
|
||||
print "- Send email to '".$oldtarget."' (".$oldemail."), total: ".$total."\n";
|
||||
dol_syslog("email_expire_services_to_customers.php: send mail to ".$oldemail);
|
||||
print "- Send email to '" . $oldtarget . "' (" . $oldemail . "), total: " . $total . "\n";
|
||||
dol_syslog("email_expire_services_to_customers.php: send mail to " . $oldemail);
|
||||
|
||||
$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_HEADER)) $usehtml+=1;
|
||||
$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_HEADER))
|
||||
$usehtml += 1;
|
||||
|
||||
$allmessage='';
|
||||
if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER))
|
||||
{
|
||||
$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER;
|
||||
}
|
||||
else
|
||||
{
|
||||
$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.= $message.($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))
|
||||
{
|
||||
$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER;
|
||||
if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) $usehtml+=1;
|
||||
}
|
||||
$allmessage = '';
|
||||
if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) {
|
||||
$allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER;
|
||||
} else {
|
||||
$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 .= $message . ($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)) {
|
||||
$allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER;
|
||||
if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER))
|
||||
$usehtml += 1;
|
||||
}
|
||||
|
||||
$mail = new CMailFile(
|
||||
$subject,
|
||||
$sendto,
|
||||
$from,
|
||||
$allmessage,
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
'',
|
||||
'',
|
||||
0,
|
||||
$msgishtml
|
||||
);
|
||||
$mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);
|
||||
|
||||
$mail->errors_to = $errorsto;
|
||||
$mail->errors_to = $errorsto;
|
||||
|
||||
// Send or not email
|
||||
if ($mode == 'confirm')
|
||||
{
|
||||
$result=$mail->sendfile();
|
||||
if (! $result)
|
||||
{
|
||||
print "Error sending email ".$mail->error."\n";
|
||||
dol_syslog("Error sending email ".$mail->error."\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "No email sent (test mode)\n";
|
||||
dol_syslog("No email sent (test mode)");
|
||||
$mail->dump_mail();
|
||||
$result=1;
|
||||
}
|
||||
// Send or not email
|
||||
if ($mode == 'confirm') {
|
||||
$result = $mail->sendfile();
|
||||
if (! $result) {
|
||||
print "Error sending email " . $mail->error . "\n";
|
||||
dol_syslog("Error sending email " . $mail->error . "\n");
|
||||
}
|
||||
} else {
|
||||
print "No email sent (test mode)\n";
|
||||
dol_syslog("No email sent (test mode)");
|
||||
$mail->dump_mail();
|
||||
$result = 1;
|
||||
}
|
||||
|
||||
unset($newlangs);
|
||||
if ($result)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
unset($newlangs);
|
||||
if ($result) {
|
||||
return 1;
|
||||
} else {
|
||||
return - 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -12,7 +12,7 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
@ -20,263 +20,234 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/contracts/email_expire_services_to_representatives.php
|
||||
* \ingroup contracts
|
||||
* \brief Script to send a mail to dolibarr users linked to companies with services to expire
|
||||
* \file scripts/contracts/email_expire_services_to_representatives.php
|
||||
* \ingroup contracts
|
||||
* \brief Script to send a mail to dolibarr users linked to companies with services to expire
|
||||
*/
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Test si mode batch
|
||||
$sapi_type = php_sapi_name();
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
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 "\n";
|
||||
print "Send an email to remind all contracts services to expire, to users that are sale representative for.\n";
|
||||
print "If you choose 'test' mode, no emails are sent.\n";
|
||||
print "If you add a delay (nb of days), only services with expired date < today + delay are included.\n";
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
$mode=$argv[1];
|
||||
$mode = $argv[1];
|
||||
|
||||
require $path . "../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/core/class/CMailFile.class.php";
|
||||
|
||||
require $path."../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php";
|
||||
|
||||
$langs->loadLangs(array('main', 'contracts'));
|
||||
$langs->loadLangs(array('main','contracts'));
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',', $argv));
|
||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||
|
||||
$now=dol_now('tzserver');
|
||||
$duration_value=isset($argv[2])?$argv[2]:'none';
|
||||
$now = dol_now('tzserver');
|
||||
$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.= " 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.= " 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";
|
||||
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 .= " ORDER BY u.email ASC, s.rowid ASC, c.ref ASC"; // Order by email to allow one message per email
|
||||
$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 .= " 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 .= " 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")) . "'";
|
||||
$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
|
||||
|
||||
//print $sql;
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
$oldemail = 'none'; $olduid = 0; $oldlang='';
|
||||
$total = 0; $foundtoprocess = 0;
|
||||
print "We found ".$num." couples (services to expire - sale representative) qualified\n";
|
||||
dol_syslog("We found ".$num." couples (services to expire - sale representative) qualified");
|
||||
$message='';
|
||||
// print $sql;
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
$oldemail = 'none';
|
||||
$olduid = 0;
|
||||
$oldlang = '';
|
||||
$total = 0;
|
||||
$foundtoprocess = 0;
|
||||
print "We found " . $num . " couples (services to expire - sale representative) qualified\n";
|
||||
dol_syslog("We found " . $num . " couples (services to expire - sale representative) qualified");
|
||||
$message = '';
|
||||
|
||||
if ($num)
|
||||
{
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
if ($num) {
|
||||
while ($i < $num) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
|
||||
if (($obj->email <> $oldemail || $obj->uid <> $olduid) || $oldemail == 'none')
|
||||
{
|
||||
// Break onto sales representative (new email or uid)
|
||||
if (dol_strlen($oldemail) && $oldemail != 'none')
|
||||
{
|
||||
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative, $duration_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
|
||||
}
|
||||
$oldemail = $obj->email;
|
||||
$olduid = $obj->uid;
|
||||
$oldlang = $obj->lang;
|
||||
$oldsalerepresentative=dolGetFirstLastname($obj->firstname, $obj->lastname);
|
||||
$message = '';
|
||||
$total = 0;
|
||||
$foundtoprocess = 0;
|
||||
$salerepresentative=dolGetFirstLastname($obj->firstname, $obj->lastname);
|
||||
if (empty($obj->email)) print "Warning: Sale representative ".$salerepresentative." has no email. Notice disabled.\n";
|
||||
}
|
||||
if (($obj->email != $oldemail || $obj->uid != $olduid) || $oldemail == 'none') {
|
||||
// Break onto sales representative (new email or uid)
|
||||
if (dol_strlen($oldemail) && $oldemail != 'none') {
|
||||
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative, $duration_value);
|
||||
} else {
|
||||
if ($oldemail != 'none')
|
||||
print "- No email sent for " . $oldsalerepresentative . ", total: " . $total . "\n";
|
||||
}
|
||||
$oldemail = $obj->email;
|
||||
$olduid = $obj->uid;
|
||||
$oldlang = $obj->lang;
|
||||
$oldsalerepresentative = dolGetFirstLastname($obj->firstname, $obj->lastname);
|
||||
$message = '';
|
||||
$total = 0;
|
||||
$foundtoprocess = 0;
|
||||
$salerepresentative = dolGetFirstLastname($obj->firstname, $obj->lastname);
|
||||
if (empty($obj->email))
|
||||
print "Warning: Sale representative " . $salerepresentative . " has no email. Notice disabled.\n";
|
||||
}
|
||||
|
||||
// Define line content
|
||||
$outputlangs=new Translate('', $conf);
|
||||
$outputlangs->setDefaultLang(empty($obj->lang)?$langs->defaultlang:$obj->lang); // By default language of sale representative
|
||||
// Define line content
|
||||
$outputlangs = new Translate('', $conf);
|
||||
$outputlangs->setDefaultLang(empty($obj->lang) ? $langs->defaultlang : $obj->lang); // By default language of sale representative
|
||||
|
||||
// Load translation files required by the page
|
||||
$outputlangs->loadLangs(array("main", "contracts", "bills", "products"));
|
||||
// Load translation files required by the page
|
||||
$outputlangs->loadLangs(array("main","contracts","bills","products"));
|
||||
|
||||
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";
|
||||
dol_syslog("email_expire_services_to_representatives.php: ".$obj->email);
|
||||
$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."): ";
|
||||
if (dol_strlen($obj->email)) print "qualified.";
|
||||
else print "disqualified (no 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";
|
||||
dol_syslog("email_expire_services_to_representatives.php: " . $obj->email);
|
||||
$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 . "): ";
|
||||
if (dol_strlen($obj->email))
|
||||
print "qualified.";
|
||||
else
|
||||
print "disqualified (no email).";
|
||||
print "\n";
|
||||
|
||||
unset($outputlangs);
|
||||
|
||||
$total += $obj->total_ttc;
|
||||
$i++;
|
||||
}
|
||||
$i ++;
|
||||
}
|
||||
|
||||
// Si il reste des envois en buffer
|
||||
if ($foundtoprocess)
|
||||
{
|
||||
if (dol_strlen($oldemail) && $oldemail != 'none') // Break onto email (new email)
|
||||
{
|
||||
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative, $duration_value);
|
||||
}
|
||||
else
|
||||
// Si il reste des envois en buffer
|
||||
if ($foundtoprocess) {
|
||||
if (dol_strlen($oldemail) && $oldemail != 'none') // Break onto email (new email)
|
||||
{
|
||||
if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "No services to expire (for companies linked to a particular commercial dolibarr user) found\n";
|
||||
}
|
||||
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative, $duration_value);
|
||||
} else {
|
||||
if ($oldemail != 'none')
|
||||
print "- No email sent for " . $oldsalerepresentative . ", total: " . $total . "\n";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print "No services to expire (for companies linked to a particular commercial dolibarr user) found\n";
|
||||
}
|
||||
|
||||
exit(0);
|
||||
exit(0);
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
dol_syslog("email_expire_services_to_representatives.php: Error");
|
||||
|
||||
exit(- 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
dol_syslog("email_expire_services_to_representatives.php: Error");
|
||||
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send email
|
||||
* Send email
|
||||
*
|
||||
* @param string $mode Mode (test | confirm)
|
||||
* @param string $oldemail Old email
|
||||
* @param string $message 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
|
||||
* @param int $duration_value duration value
|
||||
* @return int <0 if KO, >0 if OK
|
||||
* @param string $mode Mode (test | confirm)
|
||||
* @param string $oldemail Old email
|
||||
* @param string $message 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
|
||||
* @param int $duration_value Duration value
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
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->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang);
|
||||
$newlangs->load("main");
|
||||
$newlangs->load("contracts");
|
||||
$newlangs = new Translate('', $conf);
|
||||
$newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang);
|
||||
$newlangs->load("main");
|
||||
$newlangs->load("contracts");
|
||||
|
||||
if ($duration_value)
|
||||
{
|
||||
if ($duration_value > 0) $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration", $duration_value);
|
||||
else $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg", $duration_value);
|
||||
}
|
||||
else
|
||||
$title= $newlangs->transnoentities("ListOfServicesToExpire");
|
||||
if ($duration_value) {
|
||||
if ($duration_value > 0)
|
||||
$title = $newlangs->transnoentities("ListOfServicesToExpireWithDuration", $duration_value);
|
||||
else
|
||||
$title = $newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg", $duration_value);
|
||||
} else
|
||||
$title = $newlangs->transnoentities("ListOfServicesToExpire");
|
||||
|
||||
$subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT)?$title:$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT);
|
||||
$sendto = $oldemail;
|
||||
$from = $conf->global->MAIN_MAIL_EMAIL_FROM;
|
||||
$errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
|
||||
$msgishtml = -1;
|
||||
$subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT) ? $title : $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT);
|
||||
$sendto = $oldemail;
|
||||
$from = $conf->global->MAIN_MAIL_EMAIL_FROM;
|
||||
$errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
|
||||
$msgishtml = - 1;
|
||||
|
||||
print "- Send email for ".$oldsalerepresentative." (".$oldemail."), total: ".$total."\n";
|
||||
dol_syslog("email_expire_services_to_representatives.php: send mail to ".$oldemail);
|
||||
print "- Send email for " . $oldsalerepresentative . " (" . $oldemail . "), total: " . $total . "\n";
|
||||
dol_syslog("email_expire_services_to_representatives.php: send mail to " . $oldemail);
|
||||
|
||||
$usehtml=0;
|
||||
if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
|
||||
if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER)) $usehtml+=1;
|
||||
$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_HEADER))
|
||||
$usehtml += 1;
|
||||
|
||||
$allmessage='';
|
||||
if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER))
|
||||
{
|
||||
$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER;
|
||||
}
|
||||
else
|
||||
{
|
||||
$allmessage.= $title.($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.= $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))
|
||||
{
|
||||
$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER;
|
||||
if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
|
||||
}
|
||||
$allmessage = '';
|
||||
if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER)) {
|
||||
$allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER;
|
||||
} else {
|
||||
$allmessage .= $title . ($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 .= $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)) {
|
||||
$allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER;
|
||||
if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER))
|
||||
$usehtml += 1;
|
||||
}
|
||||
|
||||
$mail = new CMailFile(
|
||||
$subject,
|
||||
$sendto,
|
||||
$from,
|
||||
$allmessage,
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
'',
|
||||
'',
|
||||
0,
|
||||
$msgishtml
|
||||
);
|
||||
$mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);
|
||||
|
||||
$mail->errors_to = $errorsto;
|
||||
$mail->errors_to = $errorsto;
|
||||
|
||||
// Send or not email
|
||||
if ($mode == 'confirm')
|
||||
{
|
||||
$result=$mail->sendfile();
|
||||
if (! $result)
|
||||
{
|
||||
print "Error sending email ".$mail->error."\n";
|
||||
dol_syslog("Error sending email ".$mail->error."\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "No email sent (test mode)\n";
|
||||
dol_syslog("No email sent (test mode)");
|
||||
$mail->dump_mail();
|
||||
$result=1;
|
||||
}
|
||||
// Send or not email
|
||||
if ($mode == 'confirm') {
|
||||
$result = $mail->sendfile();
|
||||
if (! $result) {
|
||||
print "Error sending email " . $mail->error . "\n";
|
||||
dol_syslog("Error sending email " . $mail->error . "\n");
|
||||
}
|
||||
} else {
|
||||
print "No email sent (test mode)\n";
|
||||
dol_syslog("No email sent (test mode)");
|
||||
$mail->dump_mail();
|
||||
$result = 1;
|
||||
}
|
||||
|
||||
if ($result)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if ($result) {
|
||||
return 1;
|
||||
} else {
|
||||
return - 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
|
||||
* Copyright (C) 2013 Florian Henry <forian.henry@open-concept.pro
|
||||
/*
|
||||
* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
|
||||
* Copyright (C) 2013 Florian Henry <forian.henry@open-concept.pro
|
||||
* Copyright (C) 2013-2015 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -11,7 +12,7 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
@ -19,255 +20,227 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/cron/cron_run_jobs.php
|
||||
* \ingroup cron
|
||||
* \brief Execute pendings jobs
|
||||
* \file scripts/cron/cron_run_jobs.php
|
||||
* \ingroup cron
|
||||
* \brief Execute pendings jobs
|
||||
*/
|
||||
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Disables token renewal
|
||||
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '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('NOTOKENRENEWAL'))
|
||||
define('NOTOKENRENEWAL', '1'); // Disables token renewal
|
||||
if (! defined('NOREQUIREMENU'))
|
||||
define('NOREQUIREMENU', '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');
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Error if Web mode
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
require_once $path."../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/cron/class/cronjob.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
|
||||
require_once $path . "../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/cron/class/cronjob.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php';
|
||||
|
||||
// Check parameters
|
||||
if (! isset($argv[1]) || ! $argv[1]) {
|
||||
usage($path, $script_file);
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
$key=$argv[1];
|
||||
$key = $argv[1];
|
||||
|
||||
if (! isset($argv[2]) || ! $argv[2]) {
|
||||
usage($path, $script_file);
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
$userlogin=$argv[2];
|
||||
|
||||
$userlogin = $argv[2];
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
|
||||
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
$langs->loadLangs(array('main', 'dict'));
|
||||
$langs->loadLangs(array('main','dict'));
|
||||
|
||||
// current date
|
||||
$now=dol_now();
|
||||
$now = dol_now();
|
||||
|
||||
@set_time_limit(0);
|
||||
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
|
||||
if (empty($conf->cron->enabled))
|
||||
{
|
||||
if (empty($conf->cron->enabled)) {
|
||||
print "Error: module Scheduled jobs (cron) not activated\n";
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
// Check module cron is activated
|
||||
if (empty($conf->cron->enabled))
|
||||
{
|
||||
if (empty($conf->cron->enabled)) {
|
||||
print "Error: module Scheduled jobs (cron) not activated\n";
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
// Check security key
|
||||
if ($key != $conf->global->CRON_KEY)
|
||||
{
|
||||
if ($key != $conf->global->CRON_KEY) {
|
||||
print "Error: securitykey is wrong\n";
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
// If param userlogin is reserved word 'firstadmin'
|
||||
if ($userlogin == 'firstadmin')
|
||||
{
|
||||
$sql='SELECT login, entity from '.MAIN_DB_PREFIX.'user WHERE admin = 1 and statut = 1 ORDER BY entity LIMIT 1';
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$obj=$db->fetch_object($resql);
|
||||
if ($obj)
|
||||
{
|
||||
$userlogin = $obj->login;
|
||||
echo "First admin user found is login '".$userlogin."', entity ".$obj->entity."\n";
|
||||
}
|
||||
}
|
||||
else dol_print_error($db);
|
||||
if ($userlogin == 'firstadmin') {
|
||||
$sql = 'SELECT login, entity from ' . MAIN_DB_PREFIX . 'user WHERE admin = 1 and statut = 1 ORDER BY entity LIMIT 1';
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
if ($obj) {
|
||||
$userlogin = $obj->login;
|
||||
echo "First admin user found is login '" . $userlogin . "', entity " . $obj->entity . "\n";
|
||||
}
|
||||
} else
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
// Check user login
|
||||
$user=new User($db);
|
||||
$result=$user->fetch('', $userlogin);
|
||||
if ($result < 0)
|
||||
{
|
||||
echo "User Error: ".$user->error;
|
||||
dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
|
||||
exit(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (empty($user->id))
|
||||
{
|
||||
echo "User login: ".$userlogin." does not exists";
|
||||
dol_syslog("User login:".$userlogin." does not exists", LOG_ERR);
|
||||
exit(-1);
|
||||
$user = new User($db);
|
||||
$result = $user->fetch('', $userlogin);
|
||||
if ($result < 0) {
|
||||
echo "User Error: " . $user->error;
|
||||
dol_syslog("cron_run_jobs.php:: User Error:" . $user->error, LOG_ERR);
|
||||
exit(- 1);
|
||||
} else {
|
||||
if (empty($user->id)) {
|
||||
echo "User login: " . $userlogin . " does not exists";
|
||||
dol_syslog("User login:" . $userlogin . " does not exists", LOG_ERR);
|
||||
exit(- 1);
|
||||
}
|
||||
}
|
||||
$user->getrights();
|
||||
|
||||
if (isset($argv[3]) || $argv[3])
|
||||
{
|
||||
if (isset($argv[3]) || $argv[3]) {
|
||||
$id = $argv[3];
|
||||
}
|
||||
|
||||
// create a jobs object
|
||||
$object = new Cronjob($db);
|
||||
|
||||
$filter=array();
|
||||
$filter = array();
|
||||
if (! empty($id)) {
|
||||
if (! is_numeric($id))
|
||||
{
|
||||
if (! is_numeric($id)) {
|
||||
echo "Error: Bad value for parameter job id";
|
||||
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);
|
||||
if ($result<0)
|
||||
{
|
||||
echo "Error: ".$object->error;
|
||||
dol_syslog("cron_run_jobs.php:: fetch Error ".$object->error, LOG_ERR);
|
||||
exit(-1);
|
||||
if ($result < 0) {
|
||||
echo "Error: " . $object->error;
|
||||
dol_syslog("cron_run_jobs.php:: fetch Error " . $object->error, LOG_ERR);
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
|
||||
$qualifiedjobs = array();
|
||||
foreach($object->lines as $val)
|
||||
{
|
||||
if (! verifCond($val->test)) continue;
|
||||
foreach ($object->lines as $val) {
|
||||
if (! verifCond($val->test))
|
||||
continue;
|
||||
$qualifiedjobs[] = $val;
|
||||
}
|
||||
|
||||
// TODO Duplicate. This sequence of code must be shared with code into public/cron/cron_run_jobs.php php page.
|
||||
|
||||
$nbofjobs=count($qualifiedjobs);
|
||||
$nbofjobslaunchedok=0;
|
||||
$nbofjobslaunchedko=0;
|
||||
$nbofjobs = count($qualifiedjobs);
|
||||
$nbofjobslaunchedok = 0;
|
||||
$nbofjobslaunchedko = 0;
|
||||
|
||||
if (is_array($qualifiedjobs) && (count($qualifiedjobs)>0))
|
||||
{
|
||||
if (is_array($qualifiedjobs) && (count($qualifiedjobs) > 0)) {
|
||||
// Loop over job
|
||||
foreach($qualifiedjobs as $line)
|
||||
{
|
||||
dol_syslog("cron_run_jobs.php cronjobid: ".$line->id." priority=".$line->priority." entity=".$line->entity." label=".$line->label, LOG_DEBUG);
|
||||
foreach ($qualifiedjobs as $line) {
|
||||
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 (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now))
|
||||
{
|
||||
// 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)) {
|
||||
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);
|
||||
$result=$cronjob->fetch($line->id);
|
||||
if ($result < 0)
|
||||
{
|
||||
echo "Error cronjobid: ".$line->id." cronjob->fetch: ".$cronjob->error."\n";
|
||||
echo "Failed to fetch job ".$line->id."\n";
|
||||
dol_syslog("cron_run_jobs.php::fetch Error ".$cronjob->error, LOG_ERR);
|
||||
exit(-1);
|
||||
$cronjob = new Cronjob($db);
|
||||
$result = $cronjob->fetch($line->id);
|
||||
if ($result < 0) {
|
||||
echo "Error cronjobid: " . $line->id . " cronjob->fetch: " . $cronjob->error . "\n";
|
||||
echo "Failed to fetch job " . $line->id . "\n";
|
||||
dol_syslog("cron_run_jobs.php::fetch Error " . $cronjob->error, LOG_ERR);
|
||||
exit(- 1);
|
||||
}
|
||||
// Execute job
|
||||
$result=$cronjob->run_jobs($userlogin);
|
||||
if ($result < 0)
|
||||
{
|
||||
echo "Error cronjobid: ".$line->id." cronjob->run_job: ".$cronjob->error."\n";
|
||||
$result = $cronjob->run_jobs($userlogin);
|
||||
if ($result < 0) {
|
||||
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 "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);
|
||||
$nbofjobslaunchedko++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$nbofjobslaunchedok++;
|
||||
dol_syslog("cron_run_jobs.php::run_jobs Error " . $cronjob->error, LOG_ERR);
|
||||
$nbofjobslaunchedko ++;
|
||||
} else {
|
||||
$nbofjobslaunchedok ++;
|
||||
}
|
||||
|
||||
echo " - result of run_jobs = ".$result;
|
||||
echo " - result of run_jobs = " . $result;
|
||||
|
||||
// we re-program the next execution and stores the last execution time for this job
|
||||
$result=$cronjob->reprogram_jobs($userlogin, $now);
|
||||
if ($result<0)
|
||||
{
|
||||
echo "Error cronjobid: ".$line->id." cronjob->reprogram_job: ".$cronjob->error."\n";
|
||||
$result = $cronjob->reprogram_jobs($userlogin, $now);
|
||||
if ($result < 0) {
|
||||
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";
|
||||
dol_syslog("cron_run_jobs.php::reprogram_jobs Error ".$cronjob->error, LOG_ERR);
|
||||
exit(-1);
|
||||
dol_syslog("cron_run_jobs.php::reprogram_jobs Error " . $cronjob->error, LOG_ERR);
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
echo " - reprogrammed\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
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";
|
||||
}
|
||||
|
||||
$db->close();
|
||||
|
||||
if ($nbofjobslaunchedko) exit(1);
|
||||
if ($nbofjobslaunchedko)
|
||||
exit(1);
|
||||
exit(0);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* script cron usage
|
||||
*
|
||||
* @param string $path path
|
||||
* @param string $script_file filename
|
||||
* @param string $path Path
|
||||
* @param string $script_file Filename
|
||||
* @return void
|
||||
*/
|
||||
function usage($path, $script_file)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
print "Usage: ".$script_file." securitykey userlogin|'firstadmin' [cronjobid]\n";
|
||||
print "Usage: " . $script_file . " securitykey userlogin|'firstadmin' [cronjobid]\n";
|
||||
print "The script return 0 when everything worked successfully.\n";
|
||||
print "\n";
|
||||
print "On Linux system, you can have cron jobs ran automatically by adding an entry into cron.\n";
|
||||
print "For example, to run pending tasks each day at 3:30, you can add this line:\n";
|
||||
print "30 3 * * * ".$path.$script_file." securitykey userlogin > ".DOL_DATA_ROOT."/".$script_file.".log\n";
|
||||
print "30 3 * * * " . $path . $script_file . " securitykey userlogin > " . DOL_DATA_ROOT . "/" . $script_file . ".log\n";
|
||||
print "For example, to run pending tasks every 5mn, you can add this line:\n";
|
||||
print "*/5 * * * * ".$path.$script_file." securitykey userlogin > ".DOL_DATA_ROOT."/".$script_file.".log\n";
|
||||
print "*/5 * * * * " . $path . $script_file . " securitykey userlogin > " . DOL_DATA_ROOT . "/" . $script_file . ".log\n";
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005-2016 Regis Houssin <regis.houssin@inodbox.com>
|
||||
* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005-2016 Regis Houssin <regis.houssin@inodbox.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -12,386 +12,347 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* \file scripts/emailings/mailing-send.php
|
||||
* \ingroup mailing
|
||||
* \brief Script d'envoi d'un mailing prepare et valide
|
||||
* \file scripts/emailings/mailing-send.php
|
||||
* \ingroup mailing
|
||||
* \brief Script d'envoi d'un mailing prepare et valide
|
||||
*/
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Test if batch mode
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
if (! isset($argv[1]) || ! $argv[1]) {
|
||||
print "Usage: ".$script_file." (ID_MAILING|all)\n";
|
||||
exit(-1);
|
||||
print "Usage: " . $script_file . " (ID_MAILING|all)\n";
|
||||
exit(- 1);
|
||||
}
|
||||
$id=$argv[1];
|
||||
if (isset($argv[2]) || !empty($argv[2])) $login = $argv[2];
|
||||
else $login = '';
|
||||
|
||||
require_once $path."../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/comm/mailing/class/mailing.class.php";
|
||||
$id = $argv[1];
|
||||
if (isset($argv[2]) || ! empty($argv[2]))
|
||||
$login = $argv[2];
|
||||
else
|
||||
$login = '';
|
||||
|
||||
require_once $path . "../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/core/class/CMailFile.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/comm/mailing/class/mailing.class.php";
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
|
||||
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@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);
|
||||
// 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
|
||||
$sql = "SELECT m.rowid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."mailing as m";
|
||||
$sql.= " WHERE m.statut IN (1,2)";
|
||||
if ($id != 'all')
|
||||
{
|
||||
$sql.= " AND m.rowid= ".$id;
|
||||
$sql.= " LIMIT 1";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "mailing as m";
|
||||
$sql .= " WHERE m.statut IN (1,2)";
|
||||
if ($id != 'all') {
|
||||
$sql .= " AND m.rowid= " . $id;
|
||||
$sql .= " LIMIT 1";
|
||||
}
|
||||
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
$j = 0;
|
||||
|
||||
if ($num)
|
||||
{
|
||||
for ($j=0; $j<$num; $j++)
|
||||
{
|
||||
if ($num) {
|
||||
for ($j = 0; $j < $num; $j ++) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
|
||||
dol_syslog("Process mailing with id ".$obj->rowid);
|
||||
print "Process mailing with id ".$obj->rowid."\n";
|
||||
dol_syslog("Process mailing with id " . $obj->rowid);
|
||||
print "Process mailing with id " . $obj->rowid . "\n";
|
||||
|
||||
$emailing = new Mailing($db);
|
||||
$emailing->fetch($obj->rowid);
|
||||
|
||||
$id = $emailing->id;
|
||||
$subject = $emailing->sujet;
|
||||
$message = $emailing->body;
|
||||
$from = $emailing->email_from;
|
||||
$replyto = $emailing->email_replyto;
|
||||
$id = $emailing->id;
|
||||
$subject = $emailing->sujet;
|
||||
$message = $emailing->body;
|
||||
$from = $emailing->email_from;
|
||||
$replyto = $emailing->email_replyto;
|
||||
$errorsto = $emailing->email_errorsto;
|
||||
// Le message est-il en html
|
||||
$msgishtml=-1; // Unknown by default
|
||||
if (preg_match('/[\s\t]*<html>/i', $message)) $msgishtml=1;
|
||||
$msgishtml = - 1; // Unknown by default
|
||||
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)
|
||||
// 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.= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
|
||||
$sql2.= " WHERE mc.statut < 1 AND mc.fk_mailing = ".$id;
|
||||
if ($conf->global->MAILING_LIMIT_SENDBYCLI > 0)
|
||||
{
|
||||
$sql2.= " LIMIT ".$conf->global->MAILING_LIMIT_SENDBYCLI;
|
||||
$sql2 .= " FROM " . MAIN_DB_PREFIX . "mailing_cibles as mc";
|
||||
$sql2 .= " WHERE mc.statut < 1 AND mc.fk_mailing = " . $id;
|
||||
if ($conf->global->MAILING_LIMIT_SENDBYCLI > 0) {
|
||||
$sql2 .= " LIMIT " . $conf->global->MAILING_LIMIT_SENDBYCLI;
|
||||
}
|
||||
|
||||
$resql2=$db->query($sql2);
|
||||
if ($resql2)
|
||||
{
|
||||
$resql2 = $db->query($sql2);
|
||||
if ($resql2) {
|
||||
$num2 = $db->num_rows($resql2);
|
||||
dol_syslog("Nb of targets = ".$num2, LOG_DEBUG);
|
||||
print "Nb of targets = ".$num2."\n";
|
||||
dol_syslog("Nb of targets = " . $num2, LOG_DEBUG);
|
||||
print "Nb of targets = " . $num2 . "\n";
|
||||
|
||||
if ($num2)
|
||||
{
|
||||
$now=dol_now();
|
||||
if ($num2) {
|
||||
$now = dol_now();
|
||||
|
||||
// Positionne date debut envoi
|
||||
$sqlstartdate="UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi='".$db->idate($now)."' WHERE rowid=".$id;
|
||||
$resqlstartdate=$db->query($sqlstartdate);
|
||||
if (! $resqlstartdate)
|
||||
{
|
||||
$sqlstartdate = "UPDATE " . MAIN_DB_PREFIX . "mailing SET date_envoi='" . $db->idate($now) . "' WHERE rowid=" . $id;
|
||||
$resqlstartdate = $db->query($sqlstartdate);
|
||||
if (! $resqlstartdate) {
|
||||
dol_print_error($db);
|
||||
$error++;
|
||||
$error ++;
|
||||
}
|
||||
|
||||
// Look on each email and sent message
|
||||
$i = 0;
|
||||
while ($i < $num2)
|
||||
{
|
||||
while ($i < $num2) {
|
||||
// Here code is common with same loop ino card.php
|
||||
$res=1;
|
||||
$now=dol_now();
|
||||
$res = 1;
|
||||
$now = dol_now();
|
||||
|
||||
$obj = $db->fetch_object($resql2);
|
||||
|
||||
// sendto en RFC2822
|
||||
$sendto = str_replace(',', ' ', dolGetFirstLastname($obj->firstname, $obj->lastname) ." <".$obj->email.">");
|
||||
$sendto = str_replace(',', ' ', dolGetFirstLastname($obj->firstname, $obj->lastname) . " <" . $obj->email . ">");
|
||||
|
||||
// Make subtsitutions on topic and body
|
||||
$other=explode(';', $obj->other);
|
||||
$tmpfield=explode('=', $other[0], 2); $other1=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
|
||||
$tmpfield=explode('=', $other[1], 2); $other2=(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:'');
|
||||
$other = explode(';', $obj->other);
|
||||
$tmpfield = explode('=', $other[0], 2);
|
||||
$other1 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
|
||||
$tmpfield = explode('=', $other[1], 2);
|
||||
$other2 = (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 : '');
|
||||
|
||||
$object = null; // Not defined with mass emailing
|
||||
$parameters=array('mode'=>'emailing');
|
||||
$substitutionarray=getCommonSubstitutionArray($langs, 0, array('object','objectamount'), $object); // Note: On mass emailing, this is null because we don't know object
|
||||
$object = null; // Not defined with mass emailing
|
||||
$parameters = array('mode' => 'emailing');
|
||||
$substitutionarray = getCommonSubstitutionArray($langs, 0, array('object','objectamount'), $object); // Note: On mass emailing, this is null because we don't know object
|
||||
|
||||
// Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
|
||||
$substitutionarray['__ID__'] = $obj->source_id;
|
||||
$substitutionarray['__EMAIL__'] = $obj->email;
|
||||
$substitutionarray['__LASTNAME__'] = $obj->lastname;
|
||||
$substitutionarray['__FIRSTNAME__'] = $obj->firstname;
|
||||
$substitutionarray['__MAILTOEMAIL__'] = '<a href="mailto:'.$obj->email.'">'.$obj->email.'</a>';
|
||||
$substitutionarray['__MAILTOEMAIL__'] = '<a href="mailto:' . $obj->email . '">' . $obj->email . '</a>';
|
||||
$substitutionarray['__OTHER1__'] = $other1;
|
||||
$substitutionarray['__OTHER2__'] = $other2;
|
||||
$substitutionarray['__OTHER3__'] = $other3;
|
||||
$substitutionarray['__OTHER4__'] = $other4;
|
||||
$substitutionarray['__OTHER5__'] = $other5;
|
||||
$substitutionarray['__USER_SIGNATURE__'] = $signature; // Signature is empty when ran from command line or taken from user in parameter)
|
||||
$substitutionarray['__SIGNATURE__'] = $signature; // For backward compatibility
|
||||
$substitutionarray['__CHECK_READ__'] = '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$obj->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
|
||||
$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['__USER_SIGNATURE__'] = $signature; // Signature is empty when ran from command line or taken from user in parameter)
|
||||
$substitutionarray['__SIGNATURE__'] = $signature; // For backward compatibility
|
||||
$substitutionarray['__CHECK_READ__'] = '<img src="' . DOL_MAIN_URL_ROOT . '/public/emailing/mailing-read.php?tag=' . $obj->tag . '&securitykey=' . urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY) . '" width="1" height="1" style="width:1px;height:1px" border="0"/>';
|
||||
$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;
|
||||
if (! empty($conf->paypal->enabled)) $onlinepaymentenabled++;
|
||||
if (! empty($conf->paybox->enabled)) $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);
|
||||
if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
|
||||
{
|
||||
$substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=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_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
$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_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
|
||||
$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
|
||||
if (! empty($conf->paypal->enabled))
|
||||
$onlinepaymentenabled ++;
|
||||
if (! empty($conf->paybox->enabled))
|
||||
$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);
|
||||
if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
|
||||
$substitutionarray['__SECUREKEYPAYMENT_MEMBER__'] = 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_CONTRACTLINE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
|
||||
} else {
|
||||
$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_INVOICE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
|
||||
$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
|
||||
}
|
||||
}
|
||||
/* For backward compatibility */
|
||||
if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN))
|
||||
{
|
||||
$substitutionarray['__SECUREKEYPAYPAL__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
|
||||
if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN)) {
|
||||
$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);
|
||||
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_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);
|
||||
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_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);
|
||||
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_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);
|
||||
else $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
|
||||
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE))
|
||||
$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);
|
||||
$newsubject=make_substitutions($subject, $substitutionarray);
|
||||
$newmessage=make_substitutions($message, $substitutionarray);
|
||||
$newsubject = make_substitutions($subject, $substitutionarray);
|
||||
$newmessage = make_substitutions($message, $substitutionarray);
|
||||
|
||||
$substitutionisok=true;
|
||||
$substitutionisok = true;
|
||||
|
||||
// Fabrication du mail
|
||||
$trackid='emailing-'.$obj->fk_mailing.'-'.$obj->rowid;
|
||||
$mail = new CMailFile(
|
||||
$newsubject,
|
||||
$sendto,
|
||||
$from,
|
||||
$newmessage,
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
'',
|
||||
'',
|
||||
0,
|
||||
$msgishtml,
|
||||
$errorsto,
|
||||
'',
|
||||
$trackid,
|
||||
'',
|
||||
'emailing'
|
||||
);
|
||||
$trackid = 'emailing-' . $obj->fk_mailing . '-' . $obj->rowid;
|
||||
$mail = new CMailFile($newsubject, $sendto, $from, $newmessage, array(), array(), array(), '', '', 0, $msgishtml, $errorsto, '', $trackid, '', 'emailing');
|
||||
|
||||
if ($mail->error)
|
||||
{
|
||||
$res=0;
|
||||
if ($mail->error) {
|
||||
$res = 0;
|
||||
}
|
||||
if (! $substitutionisok)
|
||||
{
|
||||
$mail->error='Some substitution failed';
|
||||
$res=0;
|
||||
if (! $substitutionisok) {
|
||||
$mail->error = 'Some substitution failed';
|
||||
$res = 0;
|
||||
}
|
||||
|
||||
// Send Email
|
||||
if ($res)
|
||||
{
|
||||
$res=$mail->sendfile();
|
||||
if ($res) {
|
||||
$res = $mail->sendfile();
|
||||
}
|
||||
|
||||
if ($res)
|
||||
{
|
||||
if ($res) {
|
||||
// Mail successful
|
||||
$nbok++;
|
||||
$nbok ++;
|
||||
|
||||
dol_syslog("ok for emailing id ".$id." #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
|
||||
dol_syslog("ok for emailing id " . $id . " #" . $i . ($mail->error ? ' - ' . $mail->error : ''), LOG_DEBUG);
|
||||
|
||||
// Note: If emailing is 100 000 targets, 100 000 entries are added, so we don't enter events for each target here
|
||||
// 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
|
||||
/*
|
||||
if ($obj->source_type == 'contact')
|
||||
{
|
||||
$emailing->sendtoid = $obj->source_id;
|
||||
}
|
||||
if ($obj->source_type == 'thirdparty')
|
||||
{
|
||||
$emailing->socid = $obj->source_id;
|
||||
}
|
||||
// Call trigger
|
||||
$result=$emailing->call_trigger('EMAILING_SENTBYMAIL',$user);
|
||||
if ($result < 0) $error++;
|
||||
// End call triggers
|
||||
*/
|
||||
* if ($obj->source_type == 'contact')
|
||||
* {
|
||||
* $emailing->sendtoid = $obj->source_id;
|
||||
* }
|
||||
* if ($obj->source_type == 'thirdparty')
|
||||
* {
|
||||
* $emailing->socid = $obj->source_id;
|
||||
* }
|
||||
* // Call trigger
|
||||
* $result=$emailing->call_trigger('EMAILING_SENTBYMAIL',$user);
|
||||
* if ($result < 0) $error++;
|
||||
* // End call triggers
|
||||
*/
|
||||
|
||||
$sqlok ="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
|
||||
$sqlok.=" SET statut=1, date_envoi='".$db->idate($now)."' WHERE rowid=".$obj->rowid;
|
||||
$resqlok=$db->query($sqlok);
|
||||
if (! $resqlok)
|
||||
{
|
||||
$sqlok = "UPDATE " . MAIN_DB_PREFIX . "mailing_cibles";
|
||||
$sqlok .= " SET statut=1, date_envoi='" . $db->idate($now) . "' WHERE rowid=" . $obj->rowid;
|
||||
$resqlok = $db->query($sqlok);
|
||||
if (! $resqlok) {
|
||||
dol_print_error($db);
|
||||
$error++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//if cheack read is use then update prospect contact status
|
||||
if (strpos($message, '__CHECK_READ__') !== false)
|
||||
{
|
||||
//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.")";
|
||||
$error ++;
|
||||
} else {
|
||||
// if cheack read is use then update prospect contact status
|
||||
if (strpos($message, '__CHECK_READ__') !== false) {
|
||||
// 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 . ")";
|
||||
dol_syslog("card.php: set prospect thirdparty status", LOG_DEBUG);
|
||||
$resqlx=$db->query($sqlx);
|
||||
if (! $resqlx)
|
||||
{
|
||||
$resqlx = $db->query($sqlx);
|
||||
if (! $resqlx) {
|
||||
dol_print_error($db);
|
||||
$error++;
|
||||
$error ++;
|
||||
}
|
||||
|
||||
//Update status communication of contact prospect
|
||||
$sqlx = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."socpeople AS sc INNER JOIN ".MAIN_DB_PREFIX."mailing_cibles AS mc ON mc.rowid=".$obj->rowid." AND mc.source_type = 'contact' AND mc.source_id = sc.rowid)";
|
||||
// Update status communication of contact prospect
|
||||
$sqlx = "UPDATE " . MAIN_DB_PREFIX . "societe SET fk_stcomm=2 WHERE rowid IN (SELECT sc.fk_soc FROM " . MAIN_DB_PREFIX . "socpeople AS sc INNER JOIN " . MAIN_DB_PREFIX . "mailing_cibles AS mc ON mc.rowid=" . $obj->rowid . " AND mc.source_type = 'contact' AND mc.source_id = sc.rowid)";
|
||||
dol_syslog("card.php: set prospect contact status", LOG_DEBUG);
|
||||
|
||||
$resqlx=$db->query($sqlx);
|
||||
if (! $resqlx)
|
||||
{
|
||||
$resqlx = $db->query($sqlx);
|
||||
if (! $resqlx) {
|
||||
dol_print_error($db);
|
||||
$error++;
|
||||
$error ++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($conf->global->MAILING_DELAY)) {
|
||||
if (! empty($conf->global->MAILING_DELAY)) {
|
||||
sleep($conf->global->MAILING_DELAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Mail failed
|
||||
$nbko++;
|
||||
$nbko ++;
|
||||
|
||||
dol_syslog("error for emailing id ".$id." #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
|
||||
dol_syslog("error for emailing id " . $id . " #" . $i . ($mail->error ? ' - ' . $mail->error : ''), LOG_DEBUG);
|
||||
|
||||
$sqlerror="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
|
||||
$sqlerror.=" SET statut=-1, date_envoi=".$db->idate($now)." WHERE rowid=".$obj->rowid;
|
||||
$resqlerror=$db->query($sqlerror);
|
||||
if (! $resqlerror)
|
||||
{
|
||||
$sqlerror = "UPDATE " . MAIN_DB_PREFIX . "mailing_cibles";
|
||||
$sqlerror .= " SET statut=-1, date_envoi=" . $db->idate($now) . " WHERE rowid=" . $obj->rowid;
|
||||
$resqlerror = $db->query($sqlerror);
|
||||
if (! $resqlerror) {
|
||||
dol_print_error($db);
|
||||
$error++;
|
||||
$error ++;
|
||||
}
|
||||
}
|
||||
|
||||
$i++;
|
||||
$i ++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg="Emailing id ".$id." has no recipient to target";
|
||||
print $mesg."\n";
|
||||
} else {
|
||||
$mesg = "Emailing id " . $id . " has no recipient to target";
|
||||
print $mesg . "\n";
|
||||
dol_syslog($mesg, LOG_ERR);
|
||||
}
|
||||
|
||||
// Loop finished, set global statut of mail
|
||||
$statut=2;
|
||||
if (! $nbko) $statut=3;
|
||||
$statut = 2;
|
||||
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);
|
||||
print "Update status of emailing id ".$id." to ".$statut."\n";
|
||||
$resqlenddate=$db->query($sqlenddate);
|
||||
if (! $resqlenddate)
|
||||
{
|
||||
print "Update status of emailing id " . $id . " to " . $statut . "\n";
|
||||
$resqlenddate = $db->query($sqlenddate);
|
||||
if (! $resqlenddate) {
|
||||
dol_print_error($db);
|
||||
$error++;
|
||||
$error ++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
$error++;
|
||||
$error ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg="No validated emailing id to send found.";
|
||||
print $mesg."\n";
|
||||
} else {
|
||||
$mesg = "No validated emailing id to send found.";
|
||||
print $mesg . "\n";
|
||||
dol_syslog($mesg, LOG_ERR);
|
||||
$error++;
|
||||
$error ++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
$error++;
|
||||
$error ++;
|
||||
}
|
||||
|
||||
|
||||
exit($error);
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -12,7 +12,7 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
@ -20,288 +20,266 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/invoices/email_unpaid_invoices_to_customers.php
|
||||
* \ingroup facture
|
||||
* \brief Script to send a mail to customers with unpaid invoices
|
||||
* \file scripts/invoices/email_unpaid_invoices_to_customers.php
|
||||
* \ingroup facture
|
||||
* \brief Script to send a mail to customers with unpaid invoices
|
||||
*/
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Test si mode batch
|
||||
$sapi_type = php_sapi_name();
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
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 "\n";
|
||||
print "Send an email to customers to remind all unpaid customer invoices.\n";
|
||||
print "If you choose 'test' mode, no emails are sent.\n";
|
||||
print "If you add param delay (nb of days), only invoice with due date < today + delay are included.\n";
|
||||
print "If you add param after (nb of days), only invoice with due date >= today + delay are included.\n";
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
$mode=$argv[1];
|
||||
$targettype=$argv[2];
|
||||
$mode = $argv[1];
|
||||
$targettype = $argv[2];
|
||||
|
||||
|
||||
require $path."../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php";
|
||||
require $path . "../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/core/class/CMailFile.class.php";
|
||||
|
||||
$langs->load('main');
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
|
||||
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',', $argv));
|
||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||
|
||||
$now=dol_now('tzserver');
|
||||
$duration_value=isset($argv[3])?$argv[3]:'none';
|
||||
$duration_value2=isset($argv[4])?$argv[4]:'none';
|
||||
$now = dol_now('tzserver');
|
||||
$duration_value = isset($argv[3]) ? $argv[3] : 'none';
|
||||
$duration_value2 = isset($argv[4]) ? $argv[4] : 'none';
|
||||
|
||||
$error = 0;
|
||||
print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value)?" delay=".$duration_value:"").(is_numeric($duration_value2)?" after=".$duration_value2:"")."\n";
|
||||
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.= " 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";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
|
||||
if ($targettype == 'contacts') $sql.= ", ".MAIN_DB_PREFIX."socpeople as sp";
|
||||
$sql.= " WHERE f.fk_statut = 1 AND f.paye = 0";
|
||||
$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_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";
|
||||
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.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";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "facture as f, " . MAIN_DB_PREFIX . "societe as s";
|
||||
if ($targettype == 'contacts')
|
||||
$sql .= ", " . MAIN_DB_PREFIX . "socpeople as sp";
|
||||
$sql .= " WHERE f.fk_statut = 1 AND f.paye = 0";
|
||||
$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_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";
|
||||
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
|
||||
|
||||
//print $sql;
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
$oldemail = 'none'; $oldsid = 0; $oldcid = 0; $oldlang='';
|
||||
$total = 0; $foundtoprocess = 0;
|
||||
$trackthirdpartiessent = array();
|
||||
// print $sql;
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
$oldemail = 'none';
|
||||
$oldsid = 0;
|
||||
$oldcid = 0;
|
||||
$oldlang = '';
|
||||
$total = 0;
|
||||
$foundtoprocess = 0;
|
||||
$trackthirdpartiessent = array();
|
||||
|
||||
print "We found ".$num." couples (unpayed validated invoices-".$targettype.") qualified\n";
|
||||
dol_syslog("We found ".$num." couples (unpayed validated invoices-".$targettype.") qualified");
|
||||
$message='';
|
||||
print "We found " . $num . " couples (unpayed validated invoices-" . $targettype . ") qualified\n";
|
||||
dol_syslog("We found " . $num . " couples (unpayed validated invoices-" . $targettype . ") qualified");
|
||||
$message = '';
|
||||
|
||||
if ($num)
|
||||
{
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
if ($num) {
|
||||
while ($i < $num) {
|
||||
$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
|
||||
$startbreak=false;
|
||||
if ($newemail <> $oldemail || $oldemail == 'none') $startbreak=true;
|
||||
if ($obj->sid && $obj->sid <> $oldsid) $startbreak=true;
|
||||
if ($obj->cid && $obj->cid <> $oldcid) $startbreak=true;
|
||||
// Check if this record is a break after previous one
|
||||
$startbreak = false;
|
||||
if ($newemail != $oldemail || $oldemail == 'none')
|
||||
$startbreak = true;
|
||||
if ($obj->sid && $obj->sid != $oldsid)
|
||||
$startbreak = true;
|
||||
if ($obj->cid && $obj->cid != $oldcid)
|
||||
$startbreak = true;
|
||||
|
||||
if ($startbreak)
|
||||
{
|
||||
// Break onto sales representative (new email or cid)
|
||||
if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))
|
||||
{
|
||||
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldtarget);
|
||||
$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 print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
|
||||
}
|
||||
}
|
||||
$oldemail = $newemail;
|
||||
$oldsid = $obj->sid;
|
||||
$oldcid = $obj->cid;
|
||||
$oldlang = $obj->lang;
|
||||
$oldtarget=(empty($obj->cfirstname) && empty($obj->clastname))?$obj->name:($obj->clastname." ".$obj->cfirstname);
|
||||
$message = '';
|
||||
$total = 0;
|
||||
$foundtoprocess = 0;
|
||||
$target=(empty($obj->cfirstname) && empty($obj->clastname))?$obj->name:($obj->clastname." ".$obj->cfirstname);
|
||||
//if (empty($newemail)) print "Warning: Customer ".$target." has no email. Notice disabled.\n";
|
||||
}
|
||||
if ($startbreak) {
|
||||
// Break onto sales representative (new email or cid)
|
||||
if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid . '|' . $oldemail])) {
|
||||
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldtarget);
|
||||
$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
|
||||
print "- No email sent for '" . $oldtarget . "', total: " . $total . " (already sent to " . $trackthirdpartiessent[$oldsid . '|' . $oldemail] . ")\n";
|
||||
}
|
||||
}
|
||||
$oldemail = $newemail;
|
||||
$oldsid = $obj->sid;
|
||||
$oldcid = $obj->cid;
|
||||
$oldlang = $obj->lang;
|
||||
$oldtarget = (empty($obj->cfirstname) && empty($obj->clastname)) ? $obj->name : ($obj->clastname . " " . $obj->cfirstname);
|
||||
$message = '';
|
||||
$total = 0;
|
||||
$foundtoprocess = 0;
|
||||
$target = (empty($obj->cfirstname) && empty($obj->clastname)) ? $obj->name : ($obj->clastname . " " . $obj->cfirstname);
|
||||
// if (empty($newemail)) print "Warning: Customer ".$target." has no email. Notice disabled.\n";
|
||||
}
|
||||
|
||||
// Define line content
|
||||
$outputlangs=new Translate('', $conf);
|
||||
$outputlangs->setDefaultLang(empty($obj->default_lang)?$langs->defaultlang:$obj->default_lang); // By default language of customer
|
||||
// Define line content
|
||||
$outputlangs = new Translate('', $conf);
|
||||
$outputlangs->setDefaultLang(empty($obj->default_lang) ? $langs->defaultlang : $obj->default_lang); // By default language of customer
|
||||
|
||||
// Load translation files required by the page
|
||||
$outputlangs->loadLangs(array("main", "bills"));
|
||||
// Load translation files required by the page
|
||||
$outputlangs->loadLangs(array("main","bills"));
|
||||
|
||||
if (dol_strlen($newemail))
|
||||
{
|
||||
$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);
|
||||
$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.": ";
|
||||
if (dol_strlen($newemail)) print "qualified.";
|
||||
else print "disqualified (no email).";
|
||||
print "\n";
|
||||
if (dol_strlen($newemail)) {
|
||||
$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);
|
||||
$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 . ": ";
|
||||
if (dol_strlen($newemail))
|
||||
print "qualified.";
|
||||
else
|
||||
print "disqualified (no email).";
|
||||
print "\n";
|
||||
|
||||
unset($outputlangs);
|
||||
unset($outputlangs);
|
||||
|
||||
$total += $obj->total_ttc;
|
||||
$total += $obj->total_ttc;
|
||||
|
||||
$i++;
|
||||
}
|
||||
$i ++;
|
||||
}
|
||||
|
||||
// Si il reste des envois en buffer
|
||||
if ($foundtoprocess)
|
||||
{
|
||||
if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) // Break onto email (new email)
|
||||
{
|
||||
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldtarget);
|
||||
$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
|
||||
}
|
||||
else
|
||||
// Si il reste des envois en buffer
|
||||
if ($foundtoprocess) {
|
||||
if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid . '|' . $oldemail])) // Break onto email (new email)
|
||||
{
|
||||
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
|
||||
{
|
||||
print "No unpaid invoices found\n";
|
||||
}
|
||||
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldtarget);
|
||||
$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
|
||||
print "- No email sent for '" . $oldtarget . "', total: " . $total . " (already sent to " . $trackthirdpartiessent[$oldsid . '|' . $oldemail] . ")\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print "No unpaid invoices found\n";
|
||||
}
|
||||
|
||||
exit(0);
|
||||
exit(0);
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
dol_syslog("email_unpaid_invoices_to_customers.php: Error");
|
||||
|
||||
exit(- 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
dol_syslog("email_unpaid_invoices_to_customers.php: Error");
|
||||
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send email
|
||||
* Send email
|
||||
*
|
||||
* @param string $mode Mode (test | confirm)
|
||||
* @param string $oldemail Target email
|
||||
* @param string $message 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
|
||||
* @param string $mode Mode (test | confirm)
|
||||
* @param string $oldemail Target email
|
||||
* @param string $message 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
|
||||
*/
|
||||
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->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang);
|
||||
$newlangs->load("main");
|
||||
$newlangs->load("bills");
|
||||
$newlangs = new Translate('', $conf);
|
||||
$newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang);
|
||||
$newlangs->load("main");
|
||||
$newlangs->load("bills");
|
||||
|
||||
$subject = (empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_SUBJECT)?$newlangs->trans("ListOfYourUnpaidInvoices"):$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_SUBJECT);
|
||||
$sendto = $oldemail;
|
||||
$from = $conf->global->MAIN_MAIL_EMAIL_FROM;
|
||||
$errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
|
||||
$msgishtml = -1;
|
||||
$subject = (empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_SUBJECT) ? $newlangs->trans("ListOfYourUnpaidInvoices") : $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_SUBJECT);
|
||||
$sendto = $oldemail;
|
||||
$from = $conf->global->MAIN_MAIL_EMAIL_FROM;
|
||||
$errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
|
||||
$msgishtml = - 1;
|
||||
|
||||
print "- Send email to '".$oldtarget."' (".$oldemail."), total: ".$total."\n";
|
||||
dol_syslog("email_unpaid_invoices_to_customers.php: send mail to ".$oldemail);
|
||||
print "- Send email to '" . $oldtarget . "' (" . $oldemail . "), total: " . $total . "\n";
|
||||
dol_syslog("email_unpaid_invoices_to_customers.php: send mail to " . $oldemail);
|
||||
|
||||
$usehtml=0;
|
||||
if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) $usehtml+=1;
|
||||
if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER)) $usehtml+=1;
|
||||
$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_HEADER))
|
||||
$usehtml += 1;
|
||||
|
||||
$allmessage='';
|
||||
if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER))
|
||||
{
|
||||
$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER;
|
||||
}
|
||||
else
|
||||
{
|
||||
$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.= "Note: This list contains only unpaid invoices.".($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");
|
||||
if (! empty($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;
|
||||
}
|
||||
$allmessage = '';
|
||||
if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER)) {
|
||||
$allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER;
|
||||
} else {
|
||||
$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 .= "Note: This list contains only unpaid invoices." . ($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");
|
||||
if (! empty($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;
|
||||
}
|
||||
|
||||
$mail = new CMailFile(
|
||||
$subject,
|
||||
$sendto,
|
||||
$from,
|
||||
$allmessage,
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
'',
|
||||
'',
|
||||
0,
|
||||
$msgishtml
|
||||
);
|
||||
$mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);
|
||||
|
||||
$mail->errors_to = $errorsto;
|
||||
$mail->errors_to = $errorsto;
|
||||
|
||||
// Send or not email
|
||||
if ($mode == 'confirm')
|
||||
{
|
||||
$result=$mail->sendfile();
|
||||
if (! $result)
|
||||
{
|
||||
print "Error sending email ".$mail->error."\n";
|
||||
dol_syslog("Error sending email ".$mail->error."\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "No email sent (test mode)\n";
|
||||
dol_syslog("No email sent (test mode)");
|
||||
$mail->dump_mail();
|
||||
$result=1;
|
||||
}
|
||||
// Send or not email
|
||||
if ($mode == 'confirm') {
|
||||
$result = $mail->sendfile();
|
||||
if (! $result) {
|
||||
print "Error sending email " . $mail->error . "\n";
|
||||
dol_syslog("Error sending email " . $mail->error . "\n");
|
||||
}
|
||||
} else {
|
||||
print "No email sent (test mode)\n";
|
||||
dol_syslog("No email sent (test mode)");
|
||||
$mail->dump_mail();
|
||||
$result = 1;
|
||||
}
|
||||
|
||||
unset($newlangs);
|
||||
if ($result)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
unset($newlangs);
|
||||
if ($result) {
|
||||
return 1;
|
||||
} else {
|
||||
return - 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -12,7 +12,7 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
@ -20,260 +20,229 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/invoices/email_unpaid_invoices_to_representatives.php
|
||||
* \ingroup facture
|
||||
* \brief Script to send a mail to dolibarr users linked to companies with unpaid invoices
|
||||
* \file scripts/invoices/email_unpaid_invoices_to_representatives.php
|
||||
* \ingroup facture
|
||||
* \brief Script to send a mail to dolibarr users linked to companies with unpaid invoices
|
||||
*/
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Test si mode batch
|
||||
$sapi_type = php_sapi_name();
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
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 "\n";
|
||||
print "Send an email to users to remind all unpaid customer invoices user is sale representative for.\n";
|
||||
print "If you choose 'test' mode, no emails are sent.\n";
|
||||
print "If you add a delay (nb of days), only invoice with due date < today + delay are included.\n";
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
$mode=$argv[1];
|
||||
$mode = $argv[1];
|
||||
|
||||
|
||||
require $path."../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php";
|
||||
require $path . "../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/core/class/CMailFile.class.php";
|
||||
|
||||
$langs->load('main');
|
||||
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
|
||||
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',', $argv));
|
||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||
|
||||
$now=dol_now('tzserver');
|
||||
$duration_value=isset($argv[2])?$argv[2]:'none';
|
||||
$now = dol_now('tzserver');
|
||||
$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.= " u.rowid as uid, u.lastname, u.firstname, u.email, u.lang";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
|
||||
$sql .= " , ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql .= " , ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql .= " , ".MAIN_DB_PREFIX."user as u";
|
||||
$sql .= " u.rowid as uid, u.lastname, u.firstname, u.email, u.lang";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "facture as f";
|
||||
$sql .= " , " . MAIN_DB_PREFIX . "societe as s";
|
||||
$sql .= " , " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
|
||||
$sql .= " , " . MAIN_DB_PREFIX . "user as u";
|
||||
$sql .= " WHERE f.fk_statut = 1 AND f.paye = 0";
|
||||
$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_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;
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
$oldemail = 'none'; $olduid = 0; $oldlang='';
|
||||
$total = 0; $foundtoprocess = 0;
|
||||
print "We found ".$num." couples (unpayed validated invoice - sale representative) qualified\n";
|
||||
dol_syslog("We found ".$num." couples (unpayed validated invoice - sale representative) qualified");
|
||||
$message='';
|
||||
// print $sql;
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
$oldemail = 'none';
|
||||
$olduid = 0;
|
||||
$oldlang = '';
|
||||
$total = 0;
|
||||
$foundtoprocess = 0;
|
||||
print "We found " . $num . " couples (unpayed validated invoice - sale representative) qualified\n";
|
||||
dol_syslog("We found " . $num . " couples (unpayed validated invoice - sale representative) qualified");
|
||||
$message = '';
|
||||
|
||||
if ($num)
|
||||
{
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
if ($num) {
|
||||
while ($i < $num) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
|
||||
if (($obj->email <> $oldemail || $obj->uid <> $olduid) || $oldemail == 'none')
|
||||
{
|
||||
// Break onto sales representative (new email or uid)
|
||||
if (dol_strlen($oldemail) && $oldemail != 'none')
|
||||
{
|
||||
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
|
||||
}
|
||||
$oldemail = $obj->email;
|
||||
$olduid = $obj->uid;
|
||||
$oldlang = $obj->lang;
|
||||
$oldsalerepresentative=dolGetFirstLastname($obj->firstname, $obj->lastname);
|
||||
$message = '';
|
||||
$total = 0;
|
||||
$foundtoprocess = 0;
|
||||
$salerepresentative=dolGetFirstLastname($obj->firstname, $obj->lastname);
|
||||
if (empty($obj->email)) print "Warning: Sale representative ".$salerepresentative." has no email. Notice disabled.\n";
|
||||
}
|
||||
if (($obj->email != $oldemail || $obj->uid != $olduid) || $oldemail == 'none') {
|
||||
// Break onto sales representative (new email or uid)
|
||||
if (dol_strlen($oldemail) && $oldemail != 'none') {
|
||||
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative);
|
||||
} else {
|
||||
if ($oldemail != 'none')
|
||||
print "- No email sent for " . $oldsalerepresentative . ", total: " . $total . "\n";
|
||||
}
|
||||
$oldemail = $obj->email;
|
||||
$olduid = $obj->uid;
|
||||
$oldlang = $obj->lang;
|
||||
$oldsalerepresentative = dolGetFirstLastname($obj->firstname, $obj->lastname);
|
||||
$message = '';
|
||||
$total = 0;
|
||||
$foundtoprocess = 0;
|
||||
$salerepresentative = dolGetFirstLastname($obj->firstname, $obj->lastname);
|
||||
if (empty($obj->email))
|
||||
print "Warning: Sale representative " . $salerepresentative . " has no email. Notice disabled.\n";
|
||||
}
|
||||
|
||||
// Define line content
|
||||
$outputlangs=new Translate('', $conf);
|
||||
$outputlangs->setDefaultLang(empty($obj->lang)?$langs->defaultlang:$obj->lang); // By default language of sale representative
|
||||
// Define line content
|
||||
$outputlangs = new Translate('', $conf);
|
||||
$outputlangs->setDefaultLang(empty($obj->lang) ? $langs->defaultlang : $obj->lang); // By default language of sale representative
|
||||
|
||||
// Load translation files required by the page
|
||||
$outputlangs->loadLangs(array("main", "bills"));
|
||||
// Load translation files required by the page
|
||||
$outputlangs->loadLangs(array("main","bills"));
|
||||
|
||||
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";
|
||||
dol_syslog("email_unpaid_invoices_to_representatives.php: ".$obj->email);
|
||||
$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."): ";
|
||||
if (dol_strlen($obj->email)) print "qualified.";
|
||||
else print "disqualified (no 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";
|
||||
dol_syslog("email_unpaid_invoices_to_representatives.php: " . $obj->email);
|
||||
$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 . "): ";
|
||||
if (dol_strlen($obj->email))
|
||||
print "qualified.";
|
||||
else
|
||||
print "disqualified (no email).";
|
||||
print "\n";
|
||||
|
||||
unset($outputlangs);
|
||||
|
||||
$total += $obj->total_ttc;
|
||||
$i++;
|
||||
}
|
||||
$total += $obj->total_ttc;
|
||||
$i ++;
|
||||
}
|
||||
|
||||
// Si il reste des envois en buffer
|
||||
if ($foundtoprocess)
|
||||
{
|
||||
if (dol_strlen($oldemail) && $oldemail != 'none') // Break onto email (new email)
|
||||
{
|
||||
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative);
|
||||
}
|
||||
else
|
||||
// Si il reste des envois en buffer
|
||||
if ($foundtoprocess) {
|
||||
if (dol_strlen($oldemail) && $oldemail != 'none') // Break onto email (new email)
|
||||
{
|
||||
if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "No unpaid invoices (for companies linked to a particular commercial dolibarr user) found\n";
|
||||
}
|
||||
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative);
|
||||
} else {
|
||||
if ($oldemail != 'none')
|
||||
print "- No email sent for " . $oldsalerepresentative . ", total: " . $total . "\n";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print "No unpaid invoices (for companies linked to a particular commercial dolibarr user) found\n";
|
||||
}
|
||||
|
||||
exit(0);
|
||||
exit(0);
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
dol_syslog("email_unpaid_invoices_to_representatives.php: Error");
|
||||
|
||||
exit(- 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
dol_syslog("email_unpaid_invoices_to_representatives.php: Error");
|
||||
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send email
|
||||
* Send email
|
||||
*
|
||||
* @param string $mode Mode (test | confirm)
|
||||
* @param string $oldemail Old email
|
||||
* @param string $message 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
|
||||
* @param string $mode Mode (test | confirm)
|
||||
* @param string $oldemail Old email
|
||||
* @param string $message 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
|
||||
*/
|
||||
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->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang);
|
||||
$newlangs->load("main");
|
||||
$newlangs->load("bills");
|
||||
$newlangs = new Translate('', $conf);
|
||||
$newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang);
|
||||
$newlangs->load("main");
|
||||
$newlangs->load("bills");
|
||||
|
||||
$subject = (empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT)?$newlangs->trans("ListOfYourUnpaidInvoices"):$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT);
|
||||
$sendto = $oldemail;
|
||||
$from = $conf->global->MAIN_MAIL_EMAIL_FROM;
|
||||
$errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
|
||||
$msgishtml = -1;
|
||||
$subject = (empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT) ? $newlangs->trans("ListOfYourUnpaidInvoices") : $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT);
|
||||
$sendto = $oldemail;
|
||||
$from = $conf->global->MAIN_MAIL_EMAIL_FROM;
|
||||
$errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
|
||||
$msgishtml = - 1;
|
||||
|
||||
print "- Send email for ".$oldsalerepresentative." (".$oldemail."), total: ".$total."\n";
|
||||
dol_syslog("email_unpaid_invoices_to_representatives.php: send mail to ".$oldemail);
|
||||
print "- Send email for " . $oldsalerepresentative . " (" . $oldemail . "), total: " . $total . "\n";
|
||||
dol_syslog("email_unpaid_invoices_to_representatives.php: send mail to " . $oldemail);
|
||||
|
||||
$usehtml=0;
|
||||
if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
|
||||
if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) $usehtml+=1;
|
||||
$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_HEADER))
|
||||
$usehtml += 1;
|
||||
|
||||
$allmessage='';
|
||||
if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER))
|
||||
{
|
||||
$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER;
|
||||
}
|
||||
else
|
||||
{
|
||||
$allmessage.= $newlangs->transnoentities("ListOfYourUnpaidInvoices").($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
|
||||
$allmessage.= $newlangs->transnoentities("NoteListOfYourUnpaidInvoices").($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");
|
||||
if (! empty($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;
|
||||
}
|
||||
$allmessage = '';
|
||||
if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) {
|
||||
$allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER;
|
||||
} else {
|
||||
$allmessage .= $newlangs->transnoentities("ListOfYourUnpaidInvoices") . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
|
||||
$allmessage .= $newlangs->transnoentities("NoteListOfYourUnpaidInvoices") . ($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");
|
||||
if (! empty($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;
|
||||
}
|
||||
|
||||
$mail = new CMailFile(
|
||||
$subject,
|
||||
$sendto,
|
||||
$from,
|
||||
$allmessage,
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
'',
|
||||
'',
|
||||
0,
|
||||
$msgishtml
|
||||
);
|
||||
$mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);
|
||||
|
||||
$mail->errors_to = $errorsto;
|
||||
$mail->errors_to = $errorsto;
|
||||
|
||||
// Send or not email
|
||||
if ($mode == 'confirm')
|
||||
{
|
||||
$result=$mail->sendfile();
|
||||
if (! $result)
|
||||
{
|
||||
print "Error sending email ".$mail->error."\n";
|
||||
dol_syslog("Error sending email ".$mail->error."\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "No email sent (test mode)\n";
|
||||
dol_syslog("No email sent (test mode)");
|
||||
$mail->dump_mail();
|
||||
$result=1;
|
||||
}
|
||||
// Send or not email
|
||||
if ($mode == 'confirm') {
|
||||
$result = $mail->sendfile();
|
||||
if (! $result) {
|
||||
print "Error sending email " . $mail->error . "\n";
|
||||
dol_syslog("Error sending email " . $mail->error . "\n");
|
||||
}
|
||||
} else {
|
||||
print "No email sent (test mode)\n";
|
||||
dol_syslog("No email sent (test mode)");
|
||||
$mail->dump_mail();
|
||||
$result = 1;
|
||||
}
|
||||
|
||||
if ($result)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if ($result) {
|
||||
return 1;
|
||||
} else {
|
||||
return - 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2009-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2009-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -10,7 +10,7 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
@ -18,251 +18,217 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/invoices/rebuild_merge_pdf.php
|
||||
* \ingroup facture
|
||||
* \brief Script to rebuild PDF and merge PDF files into one
|
||||
* \file scripts/invoices/rebuild_merge_pdf.php
|
||||
* \ingroup facture
|
||||
* \brief Script to rebuild PDF and merge PDF files into one
|
||||
*/
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Test if batch mode
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
// Include Dolibarr environment
|
||||
require_once $path."../../htdocs/master.inc.php";
|
||||
require_once $path . "../../htdocs/master.inc.php";
|
||||
// After this $db is an opened handler to database. We close it at end of file.
|
||||
require_once DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php";
|
||||
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/invoice2.lib.php';
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT . "/compta/facture/class/facture.class.php";
|
||||
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/invoice2.lib.php';
|
||||
|
||||
// Load main language strings
|
||||
$langs->load("main");
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
|
||||
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',', $argv));
|
||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||
|
||||
// Check parameters
|
||||
if (! isset($argv[1]))
|
||||
{
|
||||
if (! isset($argv[1])) {
|
||||
usage();
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
$diroutputpdf=$conf->facture->dir_output . '/temp';
|
||||
$newlangid='en_EN'; // To force a new lang id
|
||||
$filter=array();
|
||||
$regenerate=''; // Ask regenerate (contains name of model to use)
|
||||
$option='';
|
||||
$fileprefix='mergedpdf';
|
||||
$diroutputpdf = $conf->facture->dir_output . '/temp';
|
||||
$newlangid = 'en_EN'; // To force a new lang id
|
||||
$filter = array();
|
||||
$regenerate = ''; // Ask regenerate (contains name of model to use)
|
||||
$option = '';
|
||||
$fileprefix = 'mergedpdf';
|
||||
|
||||
foreach ($argv as $key => $value)
|
||||
{
|
||||
$found=false;
|
||||
foreach ($argv as $key => $value) {
|
||||
$found = false;
|
||||
|
||||
// Define options
|
||||
if (preg_match('/^lang=/i', $value))
|
||||
{
|
||||
$found=true;
|
||||
$valarray=explode('=', $value);
|
||||
$newlangid=$valarray[1];
|
||||
print 'Use language '.$newlangid.".\n";
|
||||
if (preg_match('/^lang=/i', $value)) {
|
||||
$found = true;
|
||||
$valarray = explode('=', $value);
|
||||
$newlangid = $valarray[1];
|
||||
print 'Use language ' . $newlangid . ".\n";
|
||||
}
|
||||
if (preg_match('/^prefix=/i', $value))
|
||||
{
|
||||
$found=true;
|
||||
$valarray=explode('=', $value);
|
||||
$fileprefix=$valarray[1];
|
||||
print 'Use prefix for filename '.$fileprefix.".\n";
|
||||
if (preg_match('/^prefix=/i', $value)) {
|
||||
$found = true;
|
||||
$valarray = explode('=', $value);
|
||||
$fileprefix = $valarray[1];
|
||||
print 'Use prefix for filename ' . $fileprefix . ".\n";
|
||||
}
|
||||
|
||||
if (preg_match('/^regenerate=(.*)/i', $value, $reg))
|
||||
{
|
||||
if (! in_array($reg[1], array('','0','no')))
|
||||
{
|
||||
$found=true;
|
||||
$regenerate=$reg[1];
|
||||
print 'Regeneration of PDF is requested with template '.$regenerate."\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ($value == 'filter=all')
|
||||
{
|
||||
$found=true;
|
||||
$option.=(empty($option)?'':'_').'all';
|
||||
$filter[]='all';
|
||||
|
||||
print 'Rebuild PDF for all invoices'."\n";
|
||||
}
|
||||
|
||||
if ($value == 'filter=date')
|
||||
{
|
||||
$found=true;
|
||||
$option.=(empty($option)?'':'_').'date_'.$argv[$key+1].'_'.$argv[$key+2];
|
||||
$filter[]='date';
|
||||
|
||||
$dateafterdate=dol_stringtotime($argv[$key+1]);
|
||||
$datebeforedate=dol_stringtotime($argv[$key+2]);
|
||||
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')
|
||||
{
|
||||
$found=true;
|
||||
$option.=(empty($option)?'':'_').'payments_'.$argv[$key+1].'_'.$argv[$key+2];
|
||||
$filter[]='payments';
|
||||
|
||||
$paymentdateafter=dol_stringtotime($argv[$key+1].'000000');
|
||||
$paymentdatebefore=dol_stringtotime($argv[$key+2].'235959');
|
||||
if (empty($paymentdateafter) || empty($paymentdatebefore))
|
||||
{
|
||||
print 'Error: Bad date format or value'."\n";
|
||||
exit(-1);
|
||||
if (preg_match('/^regenerate=(.*)/i', $value, $reg)) {
|
||||
if (! in_array($reg[1], array('','0','no'))) {
|
||||
$found = true;
|
||||
$regenerate = $reg[1];
|
||||
print 'Regeneration of PDF is requested with template ' . $regenerate . "\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')
|
||||
{
|
||||
$found=true;
|
||||
$option.=(empty($option)?'':'_').'nopayment';
|
||||
$filter[]='nopayment';
|
||||
if ($value == 'filter=all') {
|
||||
$found = true;
|
||||
$option .= (empty($option) ? '' : '_') . 'all';
|
||||
$filter[] = 'all';
|
||||
|
||||
print 'Rebuild PDF for invoices with no payment done yet.'."\n";
|
||||
print 'Rebuild PDF for all invoices' . "\n";
|
||||
}
|
||||
|
||||
if ($value == 'filter=bank')
|
||||
{
|
||||
$found=true;
|
||||
$option.=(empty($option)?'':'_').'bank_'.$argv[$key+1];
|
||||
$filter[]='bank';
|
||||
if ($value == 'filter=date') {
|
||||
$found = true;
|
||||
$option .= (empty($option) ? '' : '_') . 'date_' . $argv[$key + 1] . '_' . $argv[$key + 2];
|
||||
$filter[] = 'date';
|
||||
|
||||
$paymentonbankref=$argv[$key+1];
|
||||
$bankaccount=new Account($db);
|
||||
$result=$bankaccount->fetch(0, $paymentonbankref);
|
||||
if ($result <= 0)
|
||||
{
|
||||
print 'Error: Bank account with ref "'.$paymentonbankref.'" not found'."\n";
|
||||
exit(-1);
|
||||
$dateafterdate = dol_stringtotime($argv[$key + 1]);
|
||||
$datebeforedate = dol_stringtotime($argv[$key + 2]);
|
||||
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') {
|
||||
$found = true;
|
||||
$option .= (empty($option) ? '' : '_') . 'payments_' . $argv[$key + 1] . '_' . $argv[$key + 2];
|
||||
$filter[] = 'payments';
|
||||
|
||||
$paymentdateafter = dol_stringtotime($argv[$key + 1] . '000000');
|
||||
$paymentdatebefore = dol_stringtotime($argv[$key + 2] . '235959');
|
||||
if (empty($paymentdateafter) || empty($paymentdatebefore)) {
|
||||
print 'Error: Bad date format or value' . "\n";
|
||||
exit(- 1);
|
||||
}
|
||||
$paymentonbankid=$bankaccount->id;
|
||||
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 between ' . dol_print_date($paymentdateafter, 'day', 'gmt') . " and " . dol_print_date($paymentdatebefore, 'day', 'gmt') . ".\n";
|
||||
}
|
||||
|
||||
if ($value == 'filter=nodeposit')
|
||||
{
|
||||
$found=true;
|
||||
$option.=(empty($option)?'':'_').'nodeposit';
|
||||
$filter[]='nodeposit';
|
||||
if ($value == 'filter=nopayment') {
|
||||
$found = true;
|
||||
$option .= (empty($option) ? '' : '_') . 'nopayment';
|
||||
$filter[] = 'nopayment';
|
||||
|
||||
print 'Exclude deposit invoices'."\n";
|
||||
}
|
||||
if ($value == 'filter=noreplacement')
|
||||
{
|
||||
$found=true;
|
||||
$option.=(empty($option)?'':'_').'noreplacement';
|
||||
$filter[]='noreplacement';
|
||||
print 'Rebuild PDF for invoices with no payment done yet.' . "\n";
|
||||
}
|
||||
|
||||
print 'Exclude replacement invoices'."\n";
|
||||
}
|
||||
if ($value == 'filter=nocreditnote')
|
||||
{
|
||||
$found=true;
|
||||
$option.=(empty($option)?'':'_').'nocreditnote';
|
||||
$filter[]='nocreditnote';
|
||||
if ($value == 'filter=bank') {
|
||||
$found = true;
|
||||
$option .= (empty($option) ? '' : '_') . 'bank_' . $argv[$key + 1];
|
||||
$filter[] = 'bank';
|
||||
|
||||
print 'Exclude credit note invoices'."\n";
|
||||
}
|
||||
$paymentonbankref = $argv[$key + 1];
|
||||
$bankaccount = new Account($db);
|
||||
$result = $bankaccount->fetch(0, $paymentonbankref);
|
||||
if ($result <= 0) {
|
||||
print 'Error: Bank account with ref "' . $paymentonbankref . '" not found' . "\n";
|
||||
exit(- 1);
|
||||
}
|
||||
$paymentonbankid = $bankaccount->id;
|
||||
print 'Rebuild PDF for invoices with at least one payment on financial account ' . $bankaccount->ref . "\n";
|
||||
}
|
||||
|
||||
if ($value == 'filter=excludethirdparties')
|
||||
{
|
||||
$found=true;
|
||||
$filter[]='excludethirdparties';
|
||||
if ($value == 'filter=nodeposit') {
|
||||
$found = true;
|
||||
$option .= (empty($option) ? '' : '_') . 'nodeposit';
|
||||
$filter[] = 'nodeposit';
|
||||
|
||||
$thirdpartiesid=explode(',', $argv[$key+1]);
|
||||
print 'Exclude thirdparties with id in list ('.join(',', $thirdpartiesid).").\n";
|
||||
print 'Exclude deposit invoices' . "\n";
|
||||
}
|
||||
if ($value == 'filter=noreplacement') {
|
||||
$found = true;
|
||||
$option .= (empty($option) ? '' : '_') . 'noreplacement';
|
||||
$filter[] = 'noreplacement';
|
||||
|
||||
$option.=(empty($option)?'':'_').'excludethirdparties'.join('-', $thirdpartiesid);
|
||||
}
|
||||
if ($value == 'filter=onlythirdparties')
|
||||
{
|
||||
$found=true;
|
||||
$filter[]='onlythirdparties';
|
||||
print 'Exclude replacement invoices' . "\n";
|
||||
}
|
||||
if ($value == 'filter=nocreditnote') {
|
||||
$found = true;
|
||||
$option .= (empty($option) ? '' : '_') . 'nocreditnote';
|
||||
$filter[] = 'nocreditnote';
|
||||
|
||||
$thirdpartiesid=explode(',', $argv[$key+1]);
|
||||
print 'Only thirdparties with id in list ('.join(',', $thirdpartiesid).").\n";
|
||||
print 'Exclude credit note invoices' . "\n";
|
||||
}
|
||||
|
||||
$option.=(empty($option)?'':'_').'onlythirdparty'.join('-', $thirdpartiesid);
|
||||
}
|
||||
if ($value == 'filter=excludethirdparties') {
|
||||
$found = true;
|
||||
$filter[] = 'excludethirdparties';
|
||||
|
||||
if (! $found && preg_match('/filter=/i', $value))
|
||||
{
|
||||
$thirdpartiesid = explode(',', $argv[$key + 1]);
|
||||
print 'Exclude thirdparties with id in list (' . join(',', $thirdpartiesid) . ").\n";
|
||||
|
||||
$option .= (empty($option) ? '' : '_') . 'excludethirdparties' . join('-', $thirdpartiesid);
|
||||
}
|
||||
if ($value == 'filter=onlythirdparties') {
|
||||
$found = true;
|
||||
$filter[] = 'onlythirdparties';
|
||||
|
||||
$thirdpartiesid = explode(',', $argv[$key + 1]);
|
||||
print 'Only thirdparties with id in list (' . join(',', $thirdpartiesid) . ").\n";
|
||||
|
||||
$option .= (empty($option) ? '' : '_') . 'onlythirdparty' . join('-', $thirdpartiesid);
|
||||
}
|
||||
|
||||
if (! $found && preg_match('/filter=/i', $value)) {
|
||||
usage();
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if an option and a filter has been provided
|
||||
if (empty($option) && count($filter) <= 0)
|
||||
{
|
||||
if (empty($option) && count($filter) <= 0) {
|
||||
usage();
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
// 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();
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
if (in_array('bank', $filter) && in_array('nopayment', $filter))
|
||||
{
|
||||
if (in_array('bank', $filter) && in_array('nopayment', $filter)) {
|
||||
usage();
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
|
||||
// Define SQL and SQL request to select invoices
|
||||
// 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 --------------------
|
||||
|
||||
if ($result >= 0)
|
||||
{
|
||||
$error=0;
|
||||
print '--- end ok'."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$error=$result;
|
||||
print '--- end error code='.$error."\n";
|
||||
if ($result >= 0) {
|
||||
$error = 0;
|
||||
print '--- end ok' . "\n";
|
||||
} else {
|
||||
$error = $result;
|
||||
print '--- end error code=' . $error . "\n";
|
||||
}
|
||||
|
||||
$db->close();
|
||||
|
||||
exit($error);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Show usage of script
|
||||
*
|
||||
@ -272,29 +238,29 @@ function usage()
|
||||
{
|
||||
global $script_file;
|
||||
|
||||
print "Rebuild PDF files for some invoices and merge PDF files into one.\n";
|
||||
print "Rebuild PDF files for some invoices and merge PDF files into one.\n";
|
||||
print "\n";
|
||||
print "To build/merge PDF for invoices in a date range:\n";
|
||||
print "Usage: ".$script_file." filter=date dateafter datebefore\n";
|
||||
print "Usage: " . $script_file . " filter=date dateafter datebefore\n";
|
||||
print "To build/merge PDF for invoices with at least one payment in a date range:\n";
|
||||
print "Usage: ".$script_file." filter=payments dateafter datebefore\n";
|
||||
print "Usage: " . $script_file . " filter=payments dateafter datebefore\n";
|
||||
print "To build/merge PDF for invoices with at least one payment onto a bank account:\n";
|
||||
print "Usage: ".$script_file." filter=bank bankref\n";
|
||||
print "Usage: " . $script_file . " filter=bank bankref\n";
|
||||
print "To build/merge PDF for all invoices, use filter=all\n";
|
||||
print "Usage: ".$script_file." filter=all\n";
|
||||
print "Usage: " . $script_file . " filter=all\n";
|
||||
print "To build/merge PDF for invoices with no payments, use filter=nopayment\n";
|
||||
print "Usage: ".$script_file." filter=nopayment\n";
|
||||
print "To exclude credit notes, use filter=nocreditnote\n";
|
||||
print "To exclude replacement invoices, use filter=noreplacement\n";
|
||||
print "To exclude deposit invoices, use filter=nodeposit\n";
|
||||
print "To exclude some thirdparties, use filter=excludethirdparties id1,id2...\n";
|
||||
print "To limit to some thirdparties, use filter=onlythirdparties id1,id2...\n";
|
||||
print "To regenerate existing PDF, use regenerate=templatename\n";
|
||||
print "To generate invoices in a language, use lang=xx_XX\n";
|
||||
print "To set prefix of generated file name, use prefix=myfileprefix\n";
|
||||
print "\n";
|
||||
print "Example: ".$script_file." filter=payments 20080101 20081231 lang=fr_FR regenerate=crabe\n";
|
||||
print "Example: ".$script_file." filter=all lang=en_US\n";
|
||||
print "Usage: " . $script_file . " filter=nopayment\n";
|
||||
print "To exclude credit notes, use filter=nocreditnote\n";
|
||||
print "To exclude replacement invoices, use filter=noreplacement\n";
|
||||
print "To exclude deposit invoices, use filter=nodeposit\n";
|
||||
print "To exclude some thirdparties, use filter=excludethirdparties id1,id2...\n";
|
||||
print "To limit to some thirdparties, use filter=onlythirdparties id1,id2...\n";
|
||||
print "To regenerate existing PDF, use regenerate=templatename\n";
|
||||
print "To generate invoices in a language, use lang=xx_XX\n";
|
||||
print "To set prefix of generated file name, use prefix=myfileprefix\n";
|
||||
print "\n";
|
||||
print "Example: " . $script_file . " filter=payments 20080101 20081231 lang=fr_FR regenerate=crabe\n";
|
||||
print "Example: " . $script_file . " filter=all lang=en_US\n";
|
||||
print "\n";
|
||||
print "Note that some filters can be cumulated.\n";
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -11,7 +11,7 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
@ -19,74 +19,71 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/members/sync_members_dolibarr2ldap.php
|
||||
* \ingroup ldap member
|
||||
* \brief Script de mise a jour des adherents dans LDAP depuis base Dolibarr
|
||||
* \file scripts/members/sync_members_dolibarr2ldap.php
|
||||
* \ingroup ldap member
|
||||
* \brief Script de mise a jour des adherents dans LDAP depuis base Dolibarr
|
||||
*/
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Test if batch mode
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
require_once $path."../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php";
|
||||
require_once $path . "../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/core/class/ldap.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/adherents/class/adherent.class.php";
|
||||
|
||||
$langs->load("main");
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
$confirmed=0;
|
||||
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
$confirmed = 0;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',', $argv));
|
||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||
|
||||
if (! isset($argv[1]) || ! $argv[1]) {
|
||||
print "Usage: $script_file now [-y]\n";
|
||||
exit(-1);
|
||||
print "Usage: $script_file now [-y]\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
foreach($argv as $key => $val)
|
||||
{
|
||||
if (preg_match('/-y$/', $val, $reg)) $confirmed=1;
|
||||
foreach ($argv as $key => $val) {
|
||||
if (preg_match('/-y$/', $val, $reg))
|
||||
$confirmed = 1;
|
||||
}
|
||||
|
||||
$now=$argv[1];
|
||||
$now = $argv[1];
|
||||
|
||||
print "Mails sending disabled (useless in batch mode)\n";
|
||||
$conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails
|
||||
$conf->global->MAIN_DISABLE_ALL_MAILS = 1; // On bloque les mails
|
||||
print "\n";
|
||||
print "----- Synchronize all records from Dolibarr database:\n";
|
||||
print "type=".$conf->db->type."\n";
|
||||
print "host=".$conf->db->host."\n";
|
||||
print "port=".$conf->db->port."\n";
|
||||
print "login=".$conf->db->user."\n";
|
||||
//print "pass=".preg_replace('/./i','*',$conf->db->password)."\n"; // Not defined for security reasons
|
||||
print "database=".$conf->db->name."\n";
|
||||
print "type=" . $conf->db->type . "\n";
|
||||
print "host=" . $conf->db->host . "\n";
|
||||
print "port=" . $conf->db->port . "\n";
|
||||
print "login=" . $conf->db->user . "\n";
|
||||
// print "pass=".preg_replace('/./i','*',$conf->db->password)."\n"; // Not defined for security reasons
|
||||
print "database=" . $conf->db->name . "\n";
|
||||
print "\n";
|
||||
print "----- To LDAP database:\n";
|
||||
print "host=".$conf->global->LDAP_SERVER_HOST."\n";
|
||||
print "port=".$conf->global->LDAP_SERVER_PORT."\n";
|
||||
print "login=".$conf->global->LDAP_ADMIN_DN."\n";
|
||||
print "pass=".preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)."\n";
|
||||
print "DN target=".$conf->global->LDAP_MEMBER_DN."\n";
|
||||
print "host=" . $conf->global->LDAP_SERVER_HOST . "\n";
|
||||
print "port=" . $conf->global->LDAP_SERVER_PORT . "\n";
|
||||
print "login=" . $conf->global->LDAP_ADMIN_DN . "\n";
|
||||
print "pass=" . preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS) . "\n";
|
||||
print "DN target=" . $conf->global->LDAP_MEMBER_DN . "\n";
|
||||
print "\n";
|
||||
|
||||
if (! $confirmed)
|
||||
{
|
||||
if (! $confirmed) {
|
||||
print "Press a key to confirm...\n";
|
||||
$input = trim(fgets(STDIN));
|
||||
print "Warning, this operation may result in data loss if it failed.\n";
|
||||
@ -96,76 +93,67 @@ if (! $confirmed)
|
||||
}
|
||||
|
||||
/*
|
||||
if (! $conf->global->LDAP_MEMBER_ACTIVE)
|
||||
{
|
||||
print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
||||
exit(-1);
|
||||
}
|
||||
*/
|
||||
* if (! $conf->global->LDAP_MEMBER_ACTIVE)
|
||||
* {
|
||||
* print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
||||
* exit(-1);
|
||||
* }
|
||||
*/
|
||||
|
||||
$sql = "SELECT rowid";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."adherent";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "adherent";
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
|
||||
$ldap=new Ldap();
|
||||
$ldap = new Ldap();
|
||||
$ldap->connect_bind();
|
||||
|
||||
while ($i < $num)
|
||||
{
|
||||
$ldap->error="";
|
||||
while ($i < $num) {
|
||||
$ldap->error = "";
|
||||
|
||||
$obj = $db->fetch_object($resql);
|
||||
|
||||
$member = new Adherent($db);
|
||||
$result=$member->fetch($obj->rowid);
|
||||
if ($result < 0)
|
||||
{
|
||||
$result = $member->fetch($obj->rowid);
|
||||
if ($result < 0) {
|
||||
dol_print_error($db, $member->error);
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
$result=$member->fetch_subscriptions();
|
||||
if ($result < 0)
|
||||
{
|
||||
$result = $member->fetch_subscriptions();
|
||||
if ($result < 0) {
|
||||
dol_print_error($db, $member->error);
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
print $langs->transnoentities("UpdateMember")." rowid=".$member->id." ".$member->getFullName($langs);
|
||||
print $langs->transnoentities("UpdateMember") . " rowid=" . $member->id . " " . $member->getFullName($langs);
|
||||
|
||||
$oldobject=$member;
|
||||
$oldobject = $member;
|
||||
|
||||
$oldinfo=$oldobject->_load_ldap_info();
|
||||
$olddn=$oldobject->_load_ldap_dn($oldinfo);
|
||||
$oldinfo = $oldobject->_load_ldap_info();
|
||||
$olddn = $oldobject->_load_ldap_dn($oldinfo);
|
||||
|
||||
$info=$member->_load_ldap_info();
|
||||
$dn=$member->_load_ldap_dn($info);
|
||||
$info = $member->_load_ldap_info();
|
||||
$dn = $member->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->add($dn, $info, $user); // Wil fail if already exists
|
||||
$result=$ldap->update($dn, $info, $user, $olddn);
|
||||
if ($result > 0)
|
||||
{
|
||||
print " - ".$langs->transnoentities("OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
print " - ".$langs->transnoentities("KO").' - '.$ldap->error;
|
||||
$result = $ldap->add($dn, $info, $user); // Wil fail if already exists
|
||||
$result = $ldap->update($dn, $info, $user, $olddn);
|
||||
if ($result > 0) {
|
||||
print " - " . $langs->transnoentities("OK");
|
||||
} else {
|
||||
$error ++;
|
||||
print " - " . $langs->transnoentities("KO") . ' - ' . $ldap->error;
|
||||
}
|
||||
print "\n";
|
||||
|
||||
$i++;
|
||||
$i ++;
|
||||
}
|
||||
|
||||
$ldap->unbind();
|
||||
$ldap->close();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006-2015 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006-2015 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -11,7 +11,7 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
@ -19,322 +19,265 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/members/sync_members_ldap2dolibarr.php
|
||||
* \ingroup ldap member
|
||||
* \brief Script de mise a jour des adherents dans Dolibarr depuis LDAP
|
||||
* \file scripts/members/sync_members_ldap2dolibarr.php
|
||||
* \ingroup ldap member
|
||||
* \brief Script de mise a jour des adherents dans Dolibarr depuis LDAP
|
||||
*/
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Test if batch mode
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
require_once $path."../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/adherents/class/subscription.class.php";
|
||||
require_once $path . "../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/core/lib/date.lib.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/core/class/ldap.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/adherents/class/adherent.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/adherents/class/subscription.class.php";
|
||||
|
||||
$langs->loadLangs(array("main", "errors"));
|
||||
$langs->loadLangs(array("main","errors"));
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
$forcecommit=0;
|
||||
$confirmed=0;
|
||||
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
$forcecommit = 0;
|
||||
$confirmed = 0;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',', $argv));
|
||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||
|
||||
// List of fields to get from LDAP
|
||||
$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,
|
||||
$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,
|
||||
// Subscriptions
|
||||
$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_DATE,$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
|
||||
$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])) {
|
||||
print "Usage: $script_file (nocommitiferror|commitiferror) id_member_type [--server=ldapserverhost] [-y]\n";
|
||||
exit(-1);
|
||||
print "Usage: $script_file (nocommitiferror|commitiferror) id_member_type [--server=ldapserverhost] [-y]\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
$typeid=$argv[2];
|
||||
foreach($argv as $key => $val)
|
||||
{
|
||||
if ($val == 'commitiferror') $forcecommit=1;
|
||||
if (preg_match('/--server=([^\s]+)$/', $val, $reg)) $conf->global->LDAP_SERVER_HOST=$reg[1];
|
||||
if (preg_match('/-y$/', $val, $reg)) $confirmed=1;
|
||||
$typeid = $argv[2];
|
||||
foreach ($argv as $key => $val) {
|
||||
if ($val == 'commitiferror')
|
||||
$forcecommit = 1;
|
||||
if (preg_match('/--server=([^\s]+)$/', $val, $reg))
|
||||
$conf->global->LDAP_SERVER_HOST = $reg[1];
|
||||
if (preg_match('/-y$/', $val, $reg))
|
||||
$confirmed = 1;
|
||||
}
|
||||
|
||||
print "Mails sending disabled (useless in batch mode)\n";
|
||||
$conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails
|
||||
$conf->global->MAIN_DISABLE_ALL_MAILS = 1; // On bloque les mails
|
||||
print "\n";
|
||||
print "----- Synchronize all records from LDAP database:\n";
|
||||
print "host=".$conf->global->LDAP_SERVER_HOST."\n";
|
||||
print "port=".$conf->global->LDAP_SERVER_PORT."\n";
|
||||
print "login=".$conf->global->LDAP_ADMIN_DN."\n";
|
||||
print "pass=".preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)."\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
|
||||
else print 'Filter=('.$conf->global->LDAP_KEY_MEMBERS.'=*)'."\n";
|
||||
print "host=" . $conf->global->LDAP_SERVER_HOST . "\n";
|
||||
print "port=" . $conf->global->LDAP_SERVER_PORT . "\n";
|
||||
print "login=" . $conf->global->LDAP_ADMIN_DN . "\n";
|
||||
print "pass=" . preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS) . "\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
|
||||
else
|
||||
print 'Filter=(' . $conf->global->LDAP_KEY_MEMBERS . '=*)' . "\n";
|
||||
print "----- To Dolibarr database:\n";
|
||||
print "type=".$conf->db->type."\n";
|
||||
print "host=".$conf->db->host."\n";
|
||||
print "port=".$conf->db->port."\n";
|
||||
print "login=".$conf->db->user."\n";
|
||||
print "database=".$conf->db->name."\n";
|
||||
print "type=" . $conf->db->type . "\n";
|
||||
print "host=" . $conf->db->host . "\n";
|
||||
print "port=" . $conf->db->port . "\n";
|
||||
print "login=" . $conf->db->user . "\n";
|
||||
print "database=" . $conf->db->name . "\n";
|
||||
print "----- Options:\n";
|
||||
print "commitiferror=".$forcecommit."\n";
|
||||
print "Mapped LDAP fields=".join(',', $required_fields)."\n";
|
||||
print "commitiferror=" . $forcecommit . "\n";
|
||||
print "Mapped LDAP fields=" . join(',', $required_fields) . "\n";
|
||||
print "\n";
|
||||
|
||||
// Check parameters
|
||||
if (empty($conf->global->LDAP_MEMBER_DN))
|
||||
{
|
||||
print $langs->trans("Error").': '.$langs->trans("LDAP setup for members not defined inside Dolibarr")."\n";
|
||||
exit(-1);
|
||||
if (empty($conf->global->LDAP_MEMBER_DN)) {
|
||||
print $langs->trans("Error") . ': ' . $langs->trans("LDAP setup for members not defined inside Dolibarr") . "\n";
|
||||
exit(- 1);
|
||||
}
|
||||
if ($typeid <= 0)
|
||||
{
|
||||
print $langs->trans("Error").': Parameter id_member_type is not a valid ref of an existing member type'."\n";
|
||||
exit(-2);
|
||||
if ($typeid <= 0) {
|
||||
print $langs->trans("Error") . ': Parameter id_member_type is not a valid ref of an existing member type' . "\n";
|
||||
exit(- 2);
|
||||
}
|
||||
|
||||
|
||||
if (! $confirmed)
|
||||
{
|
||||
if (! $confirmed) {
|
||||
print "Hit Enter to continue or CTRL+C to stop...\n";
|
||||
$input = trim(fgets(STDIN));
|
||||
}
|
||||
|
||||
// Load table of correspondence of countries
|
||||
$hashlib2rowid=array();
|
||||
$countries=array();
|
||||
$hashlib2rowid = array();
|
||||
$countries = array();
|
||||
$sql = "SELECT rowid, code, label, active";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."c_country";
|
||||
$sql.= " WHERE active = 1";
|
||||
$sql.= " ORDER BY code ASC";
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "c_country";
|
||||
$sql .= " WHERE active = 1";
|
||||
$sql .= " ORDER BY code ASC";
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
if ($num)
|
||||
{
|
||||
while ($i < $num)
|
||||
{
|
||||
if ($num) {
|
||||
while ($i < $num) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
if ($obj)
|
||||
{
|
||||
//print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n";
|
||||
$hashlib2rowid[strtolower($obj->label)]=$obj->rowid;
|
||||
$countries[$obj->rowid]=array('rowid' => $obj->rowid, 'label' => $obj->label, 'code' => $obj->code);
|
||||
if ($obj) {
|
||||
// print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n";
|
||||
$hashlib2rowid[strtolower($obj->label)] = $obj->rowid;
|
||||
$countries[$obj->rowid] = array('rowid' => $obj->rowid,'label' => $obj->label,'code' => $obj->code);
|
||||
}
|
||||
$i++;
|
||||
$i ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$ldap = new Ldap();
|
||||
$result = $ldap->connect_bind();
|
||||
if ($result >= 0)
|
||||
{
|
||||
$justthese=array();
|
||||
|
||||
if ($result >= 0) {
|
||||
$justthese = array();
|
||||
|
||||
// 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
|
||||
if (is_array($ldaprecords))
|
||||
{
|
||||
$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)) {
|
||||
$db->begin();
|
||||
|
||||
// Warning $ldapuser has a key in lowercase
|
||||
foreach ($ldaprecords as $key => $ldapuser)
|
||||
{
|
||||
foreach ($ldaprecords as $key => $ldapuser) {
|
||||
$member = new Adherent($db);
|
||||
|
||||
// Propriete membre
|
||||
$member->firstname=$ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME];
|
||||
$member->lastname=$ldapuser[$conf->global->LDAP_FIELD_NAME];
|
||||
$member->login=$ldapuser[$conf->global->LDAP_FIELD_LOGIN];
|
||||
$member->pass=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD];
|
||||
$member->firstname = $ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME];
|
||||
$member->lastname = $ldapuser[$conf->global->LDAP_FIELD_NAME];
|
||||
$member->login = $ldapuser[$conf->global->LDAP_FIELD_LOGIN];
|
||||
$member->pass = $ldapuser[$conf->global->LDAP_FIELD_PASSWORD];
|
||||
|
||||
//$member->societe;
|
||||
$member->address=$ldapuser[$conf->global->LDAP_FIELD_ADDRESS];
|
||||
$member->zip=$ldapuser[$conf->global->LDAP_FIELD_ZIP];
|
||||
$member->town=$ldapuser[$conf->global->LDAP_FIELD_TOWN];
|
||||
$member->country=$ldapuser[$conf->global->LDAP_FIELD_COUNTRY];
|
||||
$member->country_id=$countries[$hashlib2rowid[strtolower($member->country)]]['rowid'];
|
||||
$member->country_code=$countries[$hashlib2rowid[strtolower($member->country)]]['code'];
|
||||
// $member->societe;
|
||||
$member->address = $ldapuser[$conf->global->LDAP_FIELD_ADDRESS];
|
||||
$member->zip = $ldapuser[$conf->global->LDAP_FIELD_ZIP];
|
||||
$member->town = $ldapuser[$conf->global->LDAP_FIELD_TOWN];
|
||||
$member->country = $ldapuser[$conf->global->LDAP_FIELD_COUNTRY];
|
||||
$member->country_id = $countries[$hashlib2rowid[strtolower($member->country)]]['rowid'];
|
||||
$member->country_code = $countries[$hashlib2rowid[strtolower($member->country)]]['code'];
|
||||
|
||||
$member->phone=$ldapuser[$conf->global->LDAP_FIELD_PHONE];
|
||||
$member->phone_perso=$ldapuser[$conf->global->LDAP_FIELD_PHONE_PERSO];
|
||||
$member->phone_mobile=$ldapuser[$conf->global->LDAP_FIELD_MOBILE];
|
||||
$member->email=$ldapuser[$conf->global->LDAP_FIELD_MAIL];
|
||||
$member->phone = $ldapuser[$conf->global->LDAP_FIELD_PHONE];
|
||||
$member->phone_perso = $ldapuser[$conf->global->LDAP_FIELD_PHONE_PERSO];
|
||||
$member->phone_mobile = $ldapuser[$conf->global->LDAP_FIELD_MOBILE];
|
||||
$member->email = $ldapuser[$conf->global->LDAP_FIELD_MAIL];
|
||||
|
||||
$member->note=$ldapuser[$conf->global->LDAP_FIELD_DESCRIPTION];
|
||||
$member->morphy='phy';
|
||||
$member->photo='';
|
||||
$member->public=1;
|
||||
$member->birth=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_BIRTHDATE]);
|
||||
$member->note = $ldapuser[$conf->global->LDAP_FIELD_DESCRIPTION];
|
||||
$member->morphy = 'phy';
|
||||
$member->photo = '';
|
||||
$member->public = 1;
|
||||
$member->birth = dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_BIRTHDATE]);
|
||||
|
||||
$member->statut=-1;
|
||||
if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS]))
|
||||
{
|
||||
$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->statut=$ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS];
|
||||
$member->statut = - 1;
|
||||
if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS])) {
|
||||
$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->statut = $ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS];
|
||||
}
|
||||
//if ($member->statut > 1) $member->statut=1;
|
||||
// if ($member->statut > 1) $member->statut=1;
|
||||
|
||||
//print_r($ldapuser);
|
||||
// print_r($ldapuser);
|
||||
|
||||
// Propriete type membre
|
||||
$member->typeid=$typeid;
|
||||
$member->typeid = $typeid;
|
||||
|
||||
// Creation membre
|
||||
print $langs->transnoentities("MemberCreate").' # '.$key.': login='.$member->login.', fullname='.$member->getFullName($langs);
|
||||
print ', datec='.$member->datec;
|
||||
$member_id=$member->create($user);
|
||||
if ($member_id > 0)
|
||||
{
|
||||
print ' --> Created member id='.$member_id.' login='.$member->login;
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
print ' --> '.$member->error;
|
||||
print $langs->transnoentities("MemberCreate") . ' # ' . $key . ': login=' . $member->login . ', fullname=' . $member->getFullName($langs);
|
||||
print ', datec=' . $member->datec;
|
||||
$member_id = $member->create($user);
|
||||
if ($member_id > 0) {
|
||||
print ' --> Created member id=' . $member_id . ' login=' . $member->login;
|
||||
} else {
|
||||
$error ++;
|
||||
print ' --> ' . $member->error;
|
||||
}
|
||||
print "\n";
|
||||
|
||||
//print_r($member);
|
||||
// print_r($member);
|
||||
|
||||
$datefirst='';
|
||||
if ($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]);
|
||||
$datefirst = '';
|
||||
if ($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]);
|
||||
}
|
||||
|
||||
$datelast='';
|
||||
if ($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]);
|
||||
}
|
||||
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;
|
||||
$pricelast=price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]);
|
||||
$datelast = '';
|
||||
if ($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]);
|
||||
} 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;
|
||||
$pricelast = price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]);
|
||||
|
||||
// Cas special ou date derniere <= date premiere
|
||||
if ($datefirst && $datelast && $datelast <= $datefirst)
|
||||
{
|
||||
if ($datefirst && $datelast && $datelast <= $datefirst) {
|
||||
// On ne va inserer que la premiere
|
||||
$datelast=0;
|
||||
if (! $pricefirst && $pricelast) $pricefirst = $pricelast;
|
||||
$datelast = 0;
|
||||
if (! $pricefirst && $pricelast)
|
||||
$pricefirst = $pricelast;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Insert first subscription
|
||||
if ($datefirst)
|
||||
{
|
||||
if ($datefirst) {
|
||||
// Cree premiere cotisation et met a jour datefin dans adherent
|
||||
//print "xx".$datefirst."\n";
|
||||
$crowid=$member->subscription($datefirst, $pricefirst, 0);
|
||||
// print "xx".$datefirst."\n";
|
||||
$crowid = $member->subscription($datefirst, $pricefirst, 0);
|
||||
}
|
||||
|
||||
// Insert last subscription
|
||||
if ($datelast)
|
||||
{
|
||||
if ($datelast) {
|
||||
// Cree derniere cotisation et met a jour datefin dans adherent
|
||||
//print "yy".dol_print_date($datelast)."\n";
|
||||
$crowid=$member->subscription($datelast, $pricelast, 0);
|
||||
// print "yy".dol_print_date($datelast)."\n";
|
||||
$crowid = $member->subscription($datelast, $pricelast, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error || $forcecommit)
|
||||
{
|
||||
if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n";
|
||||
else print $langs->transnoentities("ErrorButCommitIsDone")."\n";
|
||||
if (! $error || $forcecommit) {
|
||||
if (! $error)
|
||||
print $langs->transnoentities("NoErrorCommitIsDone") . "\n";
|
||||
else
|
||||
print $langs->transnoentities("ErrorButCommitIsDone") . "\n";
|
||||
$db->commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error)."\n";
|
||||
} else {
|
||||
print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error) . "\n";
|
||||
$db->rollback();
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dol_print_error('', $ldap->error);
|
||||
$error++;
|
||||
$error ++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dol_print_error('', $ldap->error);
|
||||
$error++;
|
||||
$error ++;
|
||||
}
|
||||
|
||||
|
||||
exit($error);
|
||||
|
||||
|
||||
/**
|
||||
* Function to say if a value is empty or not
|
||||
*
|
||||
* @param string $element Value to test
|
||||
* @return boolean True of false
|
||||
* @param string $element Value to test
|
||||
* @return boolean True of false
|
||||
*/
|
||||
function dolValidElement($element)
|
||||
{
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2017 Regis Houssin <regis.houssin@inodbox.com>
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2017 Regis Houssin <regis.houssin@inodbox.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -12,7 +12,7 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
@ -20,69 +20,64 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/user/sync_members_types_dolibarr2ldap.php
|
||||
* \ingroup ldap core
|
||||
* \brief Script de mise a jour des types de membres dans LDAP depuis base Dolibarr
|
||||
* \file scripts/user/sync_members_types_dolibarr2ldap.php
|
||||
* \ingroup ldap core
|
||||
* \brief Script de mise a jour des types de membres dans LDAP depuis base Dolibarr
|
||||
*/
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Test if batch mode
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
if (! isset($argv[1]) || ! $argv[1]) {
|
||||
print "Usage: ".$script_file." now\n";
|
||||
exit(-1);
|
||||
print "Usage: " . $script_file . " now\n";
|
||||
exit(- 1);
|
||||
}
|
||||
$now=$argv[1];
|
||||
$now = $argv[1];
|
||||
|
||||
require_once $path."../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php";
|
||||
require_once $path . "../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/core/class/ldap.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/adherents/class/adherent_type.class.php";
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',', $argv));
|
||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||
|
||||
/*
|
||||
if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
|
||||
{
|
||||
print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
||||
exit(-1);
|
||||
}
|
||||
*/
|
||||
* if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
|
||||
* {
|
||||
* print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
||||
* exit(-1);
|
||||
* }
|
||||
*/
|
||||
|
||||
$sql = "SELECT rowid";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."adherent_type";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "adherent_type";
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
|
||||
$ldap=new Ldap();
|
||||
$result=$ldap->connect_bind();
|
||||
$ldap = new Ldap();
|
||||
$result = $ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
while ($i < $num)
|
||||
{
|
||||
$ldap->error="";
|
||||
if ($result > 0) {
|
||||
while ($i < $num) {
|
||||
$ldap->error = "";
|
||||
|
||||
$obj = $db->fetch_object($resql);
|
||||
|
||||
@ -90,41 +85,35 @@ if ($resql)
|
||||
$membertype->id = $obj->rowid;
|
||||
$membertype->fetch($membertype->id);
|
||||
|
||||
print $langs->trans("UpdateMemberType")." rowid=".$membertype->id." ".$membertype-label;
|
||||
print $langs->trans("UpdateMemberType") . " rowid=" . $membertype->id . " " . $membertype - label;
|
||||
|
||||
$oldobject=$membertype;
|
||||
$oldobject = $membertype;
|
||||
|
||||
$oldinfo=$membertype->_load_ldap_info();
|
||||
$olddn=$membertype->_load_ldap_dn($oldinfo);
|
||||
$oldinfo = $membertype->_load_ldap_info();
|
||||
$olddn = $membertype->_load_ldap_dn($oldinfo);
|
||||
|
||||
$info=$membertype->_load_ldap_info();
|
||||
$dn=$membertype->_load_ldap_dn($info);
|
||||
$info = $membertype->_load_ldap_info();
|
||||
$dn = $membertype->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->add($dn, $info, $user); // Wil fail if already exists
|
||||
$result=$ldap->update($dn, $info, $user, $olddn);
|
||||
if ($result > 0)
|
||||
{
|
||||
print " - ".$langs->trans("OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
print " - ".$langs->trans("KO").' - '.$ldap->error;
|
||||
$result = $ldap->add($dn, $info, $user); // Wil fail if already exists
|
||||
$result = $ldap->update($dn, $info, $user, $olddn);
|
||||
if ($result > 0) {
|
||||
print " - " . $langs->trans("OK");
|
||||
} else {
|
||||
$error ++;
|
||||
print " - " . $langs->trans("KO") . ' - ' . $ldap->error;
|
||||
}
|
||||
print "\n";
|
||||
|
||||
$i++;
|
||||
$i ++;
|
||||
}
|
||||
|
||||
$ldap->unbind();
|
||||
$ldap->close();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
print $ldap->error;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2013 Maxime Kohlhaas <maxime@atm-consulting.fr>
|
||||
* Copyright (C) 2017 Regis Houssin <regis.houssin@inodbox.com>
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2013 Maxime Kohlhaas <maxime@atm-consulting.fr>
|
||||
* Copyright (C) 2017 Regis Houssin <regis.houssin@inodbox.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -13,7 +13,7 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
@ -21,196 +21,172 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/user/sync_members_types_ldap2dolibarr.php
|
||||
* \ingroup ldap member
|
||||
* \brief Script to update members types into Dolibarr from LDAP
|
||||
* \file scripts/user/sync_members_types_ldap2dolibarr.php
|
||||
* \ingroup ldap member
|
||||
* \brief Script to update members types into Dolibarr from LDAP
|
||||
*/
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Test if batch mode
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
require_once $path."../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php";
|
||||
require_once $path . "../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/core/lib/date.lib.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/core/class/ldap.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/adherents/class/adherent_type.class.php";
|
||||
|
||||
$langs->loadLangs(array("main", "errors"));
|
||||
$langs->loadLangs(array("main","errors"));
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
$forcecommit=0;
|
||||
$confirmed=0;
|
||||
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
$forcecommit = 0;
|
||||
$confirmed = 0;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',', $argv));
|
||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||
|
||||
// List of fields to get from LDAP
|
||||
$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
|
||||
);
|
||||
$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);
|
||||
|
||||
// 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])) {
|
||||
//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";
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
foreach($argv as $key => $val)
|
||||
{
|
||||
if ($val == 'commitiferror') $forcecommit=1;
|
||||
if (preg_match('/--server=([^\s]+)$/', $val, $reg)) $conf->global->LDAP_SERVER_HOST=$reg[1];
|
||||
if (preg_match('/--excludeuser=([^\s]+)$/', $val, $reg)) $excludeuser=explode(',', $reg[1]);
|
||||
if (preg_match('/-y$/', $val, $reg)) $confirmed=1;
|
||||
foreach ($argv as $key => $val) {
|
||||
if ($val == 'commitiferror')
|
||||
$forcecommit = 1;
|
||||
if (preg_match('/--server=([^\s]+)$/', $val, $reg))
|
||||
$conf->global->LDAP_SERVER_HOST = $reg[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";
|
||||
$conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails
|
||||
$conf->global->MAIN_DISABLE_ALL_MAILS = 1; // On bloque les mails
|
||||
print "\n";
|
||||
print "----- Synchronize all records from LDAP database:\n";
|
||||
print "host=".$conf->global->LDAP_SERVER_HOST."\n";
|
||||
print "port=".$conf->global->LDAP_SERVER_PORT."\n";
|
||||
print "login=".$conf->global->LDAP_ADMIN_DN."\n";
|
||||
print "pass=".preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)."\n";
|
||||
print "DN to extract=".$conf->global->LDAP_MEMBER_TYPE_DN."\n";
|
||||
print 'Filter=('.$conf->global->LDAP_KEY_MEMBERS_TYPES.'=*)'."\n";
|
||||
print "host=" . $conf->global->LDAP_SERVER_HOST . "\n";
|
||||
print "port=" . $conf->global->LDAP_SERVER_PORT . "\n";
|
||||
print "login=" . $conf->global->LDAP_ADMIN_DN . "\n";
|
||||
print "pass=" . preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS) . "\n";
|
||||
print "DN to extract=" . $conf->global->LDAP_MEMBER_TYPE_DN . "\n";
|
||||
print 'Filter=(' . $conf->global->LDAP_KEY_MEMBERS_TYPES . '=*)' . "\n";
|
||||
print "----- To Dolibarr database:\n";
|
||||
print "type=".$conf->db->type."\n";
|
||||
print "host=".$conf->db->host."\n";
|
||||
print "port=".$conf->db->port."\n";
|
||||
print "login=".$conf->db->user."\n";
|
||||
print "database=".$conf->db->name."\n";
|
||||
print "type=" . $conf->db->type . "\n";
|
||||
print "host=" . $conf->db->host . "\n";
|
||||
print "port=" . $conf->db->port . "\n";
|
||||
print "login=" . $conf->db->user . "\n";
|
||||
print "database=" . $conf->db->name . "\n";
|
||||
print "----- Options:\n";
|
||||
print "commitiferror=".$forcecommit."\n";
|
||||
print "Mapped LDAP fields=".join(',', $required_fields)."\n";
|
||||
print "commitiferror=" . $forcecommit . "\n";
|
||||
print "Mapped LDAP fields=" . join(',', $required_fields) . "\n";
|
||||
print "\n";
|
||||
|
||||
if (! $confirmed)
|
||||
{
|
||||
if (! $confirmed) {
|
||||
print "Hit Enter to continue or CTRL+C to stop...\n";
|
||||
$input = trim(fgets(STDIN));
|
||||
}
|
||||
|
||||
if (empty($conf->global->LDAP_MEMBER_TYPE_DN))
|
||||
{
|
||||
print $langs->trans("Error").': '.$langs->trans("LDAP setup for members types not defined inside Dolibarr");
|
||||
exit(-1);
|
||||
if (empty($conf->global->LDAP_MEMBER_TYPE_DN)) {
|
||||
print $langs->trans("Error") . ': ' . $langs->trans("LDAP setup for members types not defined inside Dolibarr");
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
|
||||
$ldap = new Ldap();
|
||||
$result = $ldap->connect_bind();
|
||||
if ($result >= 0)
|
||||
{
|
||||
$justthese=array();
|
||||
|
||||
if ($result >= 0) {
|
||||
$justthese = array();
|
||||
|
||||
// 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));
|
||||
if (is_array($ldaprecords))
|
||||
{
|
||||
if (is_array($ldaprecords)) {
|
||||
$db->begin();
|
||||
|
||||
// Warning $ldapuser has a key in lowercase
|
||||
foreach ($ldaprecords as $key => $ldapgroup)
|
||||
{
|
||||
foreach ($ldaprecords as $key => $ldapgroup) {
|
||||
$membertype = new AdherentType($db);
|
||||
$membertype->fetch('', $ldapgroup[$conf->global->LDAP_KEY_MEMBERS_TYPES]);
|
||||
$membertype->label = $ldapgroup[$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME];
|
||||
$membertype->description = $ldapgroup[$conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION];
|
||||
$membertype->entity = $conf->entity;
|
||||
|
||||
//print_r($ldapgroup);
|
||||
// print_r($ldapgroup);
|
||||
|
||||
if ($membertype->id > 0) { // Member type update
|
||||
print $langs->transnoentities("MemberTypeUpdate").' # '.$key.': name='.$membertype->label;
|
||||
$res=$membertype->update($user);
|
||||
print $langs->transnoentities("MemberTypeUpdate") . ' # ' . $key . ': name=' . $membertype->label;
|
||||
$res = $membertype->update($user);
|
||||
|
||||
if ($res > 0)
|
||||
{
|
||||
print ' --> Updated member type id='.$membertype->id.' name='.$membertype->label;
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
print ' --> '.$res.' '.$membertype->error;
|
||||
if ($res > 0) {
|
||||
print ' --> Updated member type id=' . $membertype->id . ' name=' . $membertype->label;
|
||||
} else {
|
||||
$error ++;
|
||||
print ' --> ' . $res . ' ' . $membertype->error;
|
||||
}
|
||||
print "\n";
|
||||
} else { // Member type creation
|
||||
print $langs->transnoentities("MemberTypeCreate").' # '.$key.': name='.$membertype->label;
|
||||
$res=$membertype->create($user);
|
||||
print $langs->transnoentities("MemberTypeCreate") . ' # ' . $key . ': name=' . $membertype->label;
|
||||
$res = $membertype->create($user);
|
||||
|
||||
if ($res > 0)
|
||||
{
|
||||
print ' --> Created member type id='.$membertype->id.' name='.$membertype->label;
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
print ' --> '.$res.' '.$membertype->error;
|
||||
if ($res > 0) {
|
||||
print ' --> Created member type id=' . $membertype->id . ' name=' . $membertype->label;
|
||||
} else {
|
||||
$error ++;
|
||||
print ' --> ' . $res . ' ' . $membertype->error;
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
|
||||
//print_r($membertype);
|
||||
// print_r($membertype);
|
||||
}
|
||||
|
||||
if (! $error || $forcecommit)
|
||||
{
|
||||
if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n";
|
||||
else print $langs->transnoentities("ErrorButCommitIsDone")."\n";
|
||||
if (! $error || $forcecommit) {
|
||||
if (! $error)
|
||||
print $langs->transnoentities("NoErrorCommitIsDone") . "\n";
|
||||
else
|
||||
print $langs->transnoentities("ErrorButCommitIsDone") . "\n";
|
||||
$db->commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error)."\n";
|
||||
} else {
|
||||
print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error) . "\n";
|
||||
$db->rollback();
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dol_print_error('', $ldap->error);
|
||||
$error++;
|
||||
$error ++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dol_print_error('', $ldap->error);
|
||||
$error++;
|
||||
$error ++;
|
||||
}
|
||||
|
||||
|
||||
exit($error);
|
||||
|
||||
|
||||
/**
|
||||
* Function to say if a value is empty or not
|
||||
*
|
||||
* @param string $element Value to test
|
||||
* @return boolean True of false
|
||||
* @param string $element Value to test
|
||||
* @return boolean True of false
|
||||
*/
|
||||
function dolValidElementType($element)
|
||||
{
|
||||
|
||||
@ -1,111 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* \file scripts/modulebuilder/builddoc.php
|
||||
* \ingroup modulebuilder
|
||||
* \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.
|
||||
* 
|
||||
* image:img/dolimed_screenshot_patientcard.png[Screenshot patient card]
|
||||
*/
|
||||
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
|
||||
// Test if batch mode
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (! isset($argv[1]) || ! $argv[1]) {
|
||||
print "Usage: ".$script_file." ModuleName\n";
|
||||
exit(-1);
|
||||
}
|
||||
$modulename=$argv[1];
|
||||
|
||||
require_once $path."../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/modulebuilder.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
|
||||
|
||||
$langs->loadLangs(array("admin", "modulebuilder", "other", "cron"));
|
||||
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
|
||||
// Dir for custom dirs
|
||||
$tmp=explode(',', $dolibarr_main_document_root_alt);
|
||||
$dirins = $tmp[0];
|
||||
$dirread = $dirins;
|
||||
$forceddirread = 0;
|
||||
|
||||
$tmpdir = explode('@', $module);
|
||||
if (! empty($tmpdir[1]))
|
||||
{
|
||||
$module=$tmpdir[0];
|
||||
$dirread=$tmpdir[1];
|
||||
$forceddirread=1;
|
||||
}
|
||||
|
||||
$FILEFLAG='modulebuilder.txt';
|
||||
|
||||
$now=dol_now();
|
||||
$newmask = 0;
|
||||
if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
|
||||
if (empty($newmask)) // This should no happen
|
||||
{
|
||||
$newmask='0664';
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
print "modulename=".$modulename."\n";
|
||||
print "dirins=".$dirins."\n";
|
||||
|
||||
$FILENAMEDOC=strtolower($module).'.html'; // TODO Use/text PDF
|
||||
$dirofmodule = dol_buildpath(strtolower($module), 0).'/doc';
|
||||
$outputfiledoc = $dirofmodule.'/'.$FILENAMEDOC;
|
||||
|
||||
$util = new Utils($db);
|
||||
$result = $util->generateDoc($module);
|
||||
|
||||
if ($result <= 0)
|
||||
{
|
||||
print $util->errors;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
print $langs->trans("DocFileGeneratedInto", $outputfiledoc);
|
||||
exit(0);
|
||||
@ -1,174 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* \file scripts/modulebuilder/initmodule.php
|
||||
* \ingroup modulebuilder
|
||||
* \brief Script to initialize a module.
|
||||
*/
|
||||
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
|
||||
// Test if batch mode
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (! isset($argv[1]) || ! $argv[1]) {
|
||||
print "Usage: ".$script_file." ModuleName\n";
|
||||
exit(-1);
|
||||
}
|
||||
$modulename=$argv[1];
|
||||
|
||||
require_once $path."../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/modulebuilder.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
|
||||
|
||||
$langs->loadLangs(array("admin", "modulebuilder", "other", "cron"));
|
||||
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
|
||||
// Dir for custom dirs
|
||||
$tmp=explode(',', $dolibarr_main_document_root_alt);
|
||||
$dirins = $tmp[0];
|
||||
$dirread = $dirins;
|
||||
$forceddirread = 0;
|
||||
|
||||
$tmpdir = explode('@', $module);
|
||||
if (! empty($tmpdir[1]))
|
||||
{
|
||||
$module=$tmpdir[0];
|
||||
$dirread=$tmpdir[1];
|
||||
$forceddirread=1;
|
||||
}
|
||||
|
||||
$FILEFLAG='modulebuilder.txt';
|
||||
|
||||
$now=dol_now();
|
||||
$newmask = 0;
|
||||
if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
|
||||
if (empty($newmask)) // This should no happen
|
||||
{
|
||||
$newmask='0664';
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
print "modulename=".$modulename."\n";
|
||||
print "dirins=".$dirins."\n";
|
||||
|
||||
if (preg_match('/[^a-z0-9_]/i', $modulename))
|
||||
{
|
||||
$error++;
|
||||
print 'Error '.$langs->trans("SpaceOrSpecialCharAreNotAllowed")."\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
|
||||
$destdir = $dirins.'/'.strtolower($modulename);
|
||||
|
||||
$arrayreplacement=array(
|
||||
'mymodule'=>strtolower($modulename),
|
||||
'MyModule'=>$modulename
|
||||
);
|
||||
|
||||
$result = dolCopyDir($srcdir, $destdir, 0, 0, $arrayreplacement);
|
||||
//dol_mkdir($destfile);
|
||||
if ($result <= 0)
|
||||
{
|
||||
if ($result < 0)
|
||||
{
|
||||
$error++;
|
||||
$langs->load("errors");
|
||||
print $langs->trans("ErrorFailToCopyDir", $srcdir, $destdir)."\n";
|
||||
exit(2);
|
||||
}
|
||||
else // $result == 0
|
||||
{
|
||||
print $langs->trans("AllFilesDidAlreadyExist", $srcdir, $destdir)."\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Delete some files
|
||||
dol_delete_file($destdir.'/myobject_card.php');
|
||||
dol_delete_file($destdir.'/myobject_note.php');
|
||||
dol_delete_file($destdir.'/myobject_document.php');
|
||||
dol_delete_file($destdir.'/myobject_agenda.php');
|
||||
dol_delete_file($destdir.'/myobject_list.php');
|
||||
dol_delete_file($destdir.'/lib/myobject.lib.php');
|
||||
dol_delete_file($destdir.'/test/phpunit/MyObjectTest.php');
|
||||
dol_delete_file($destdir.'/sql/llx_mymodule_myobject.sql');
|
||||
dol_delete_file($destdir.'/sql/llx_mymodule_myobject_extrafields.sql');
|
||||
dol_delete_file($destdir.'/sql/llx_mymodule_myobject.key.sql');
|
||||
dol_delete_file($destdir.'/scripts/myobject.php');
|
||||
dol_delete_file($destdir.'/img/object_myobject.png');
|
||||
dol_delete_file($destdir.'/class/myobject.class.php');
|
||||
dol_delete_file($destdir.'/class/api_mymodule.class.php');
|
||||
}
|
||||
|
||||
// Edit PHP files
|
||||
if (! $error)
|
||||
{
|
||||
$listofphpfilestoedit = dol_dir_list($destdir, 'files', 1, '\.(php|MD|js|sql|txt|xml|lang)$', '', 'fullname', SORT_ASC, 0, 1);
|
||||
foreach($listofphpfilestoedit as $phpfileval)
|
||||
{
|
||||
//var_dump($phpfileval['fullname']);
|
||||
$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.'>':'')
|
||||
);
|
||||
|
||||
|
||||
$result=dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
|
||||
//var_dump($result);
|
||||
if ($result < 0)
|
||||
{
|
||||
print $langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname'])."\n";
|
||||
exit(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print 'Module initialized'."\n";
|
||||
exit(0);
|
||||
@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/* Copyright (C) 2007-2016 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2015 Jean Heimburger <http://tiaris.eu>
|
||||
/*
|
||||
* Copyright (C) 2007-2016 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2015 Jean Heimburger <http://tiaris.eu>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -10,7 +11,7 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
@ -18,86 +19,75 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/product/migrate_picture_path.php
|
||||
* \ingroup scripts
|
||||
* \brief Migrate pictures from old system prior to 3.7 to new path for 3.7+
|
||||
* \file scripts/product/migrate_picture_path.php
|
||||
* \ingroup scripts
|
||||
* \brief Migrate pictures from old system prior to 3.7 to new path for 3.7+
|
||||
*/
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Test if batch mode
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
@set_time_limit(0); // No timeout for this script
|
||||
define('EVEN_IF_ONLY_LOGIN_ALLOWED', 1); // Set this define to 0 if you want to lock your script when dolibarr setup is "locked to admin user only".
|
||||
@set_time_limit(0); // No timeout for this script
|
||||
define('EVEN_IF_ONLY_LOGIN_ALLOWED', 1); // Set this define to 0 if you want to lock your script when dolibarr setup is "locked to admin user only".
|
||||
|
||||
// Include and load Dolibarr environment variables
|
||||
require_once $path."../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
|
||||
require_once $path . "../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/product/class/product.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/core/lib/files.lib.php";
|
||||
// After this $db, $mysoc, $langs, $conf and $hookmanager are defined (Opened $db handler to database will be closed at end of file).
|
||||
// $user is created but empty.
|
||||
|
||||
//$langs->setDefaultLang('en_US'); // To change default language of $langs
|
||||
$langs->load("main"); // To load language file for default language
|
||||
|
||||
// $langs->setDefaultLang('en_US'); // To change default language of $langs
|
||||
$langs->load("main"); // To load language file for default language
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
$forcecommit=0;
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
$forcecommit = 0;
|
||||
|
||||
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',', $argv));
|
||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||
|
||||
if (! isset($argv[1]) || $argv[1] != 'product') {
|
||||
print "Usage: $script_file product\n";
|
||||
exit(-1);
|
||||
print "Usage: $script_file product\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
print '--- start'."\n";
|
||||
print '--- start' . "\n";
|
||||
|
||||
// Case to migrate products path
|
||||
if ($argv[1] == 'product')
|
||||
{
|
||||
if ($argv[1] == 'product') {
|
||||
$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);
|
||||
if ($resql)
|
||||
{
|
||||
while ($obj = $db->fetch_object($resql))
|
||||
{
|
||||
if ($resql) {
|
||||
while ($obj = $db->fetch_object($resql)) {
|
||||
$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);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "\n sql error ".$sql;
|
||||
exit;
|
||||
} else {
|
||||
print "\n sql error " . $sql;
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$db->close(); // Close $db database opened handler
|
||||
$db->close(); // Close $db database opened handler
|
||||
|
||||
exit($error);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Migrate file from old path to new one for product $product
|
||||
*
|
||||
* @param Product $product Object product
|
||||
* @return void
|
||||
* @param Product $product Object product
|
||||
* @return void
|
||||
*/
|
||||
function migrate_product_photospath($product)
|
||||
{
|
||||
@ -105,43 +95,34 @@ function migrate_product_photospath($product)
|
||||
|
||||
$dir = $conf->product->multidir_output[$product->entity];
|
||||
$conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO = 1;
|
||||
$origin = $dir .'/'. get_exdir($product->id, 2, 0, 0, $product, 'product') . $product->id ."/photos";
|
||||
$destin = $dir.'/'.dol_sanitizeFileName($product->ref);
|
||||
$origin = $dir . '/' . get_exdir($product->id, 2, 0, 0, $product, 'product') . $product->id . "/photos";
|
||||
$destin = $dir . '/' . dol_sanitizeFileName($product->ref);
|
||||
|
||||
$error = 0;
|
||||
|
||||
$origin_osencoded=dol_osencode($origin);
|
||||
$destin_osencoded=dol_osencode($destin);
|
||||
$origin_osencoded = dol_osencode($origin);
|
||||
$destin_osencoded = dol_osencode($destin);
|
||||
dol_mkdir($destin);
|
||||
|
||||
if (dol_is_dir($origin))
|
||||
{
|
||||
$handle=opendir($origin_osencoded);
|
||||
if (is_resource($handle))
|
||||
{
|
||||
while (($file = readdir($handle)) !== false)
|
||||
{
|
||||
if ($file != '.' && $file != '..' && is_dir($origin_osencoded.'/'.$file))
|
||||
{
|
||||
$thumbs = opendir($origin_osencoded.'/'.$file);
|
||||
if (is_resource($thumbs))
|
||||
{
|
||||
dol_mkdir($destin.'/'.$file);
|
||||
while (($thumb = readdir($thumbs)) !== false)
|
||||
{
|
||||
dol_move($origin.'/'.$file.'/'.$thumb, $destin.'/'.$file.'/'.$thumb);
|
||||
}
|
||||
// dol_delete_dir($origin.'/'.$file);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dol_is_file($origin.'/'.$file) )
|
||||
{
|
||||
dol_move($origin.'/'.$file, $destin.'/'.$file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dol_is_dir($origin)) {
|
||||
$handle = opendir($origin_osencoded);
|
||||
if (is_resource($handle)) {
|
||||
while (($file = readdir($handle)) !== false) {
|
||||
if ($file != '.' && $file != '..' && is_dir($origin_osencoded . '/' . $file)) {
|
||||
$thumbs = opendir($origin_osencoded . '/' . $file);
|
||||
if (is_resource($thumbs)) {
|
||||
dol_mkdir($destin . '/' . $file);
|
||||
while (($thumb = readdir($thumbs)) !== false) {
|
||||
dol_move($origin . '/' . $file . '/' . $thumb, $destin . '/' . $file . '/' . $thumb);
|
||||
}
|
||||
// dol_delete_dir($origin.'/'.$file);
|
||||
}
|
||||
} else {
|
||||
if (dol_is_file($origin . '/' . $file)) {
|
||||
dol_move($origin . '/' . $file, $destin . '/' . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/* Copyright (C) 2007-2016 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2015 Jean Heimburger <http://tiaris.eu>
|
||||
/*
|
||||
* Copyright (C) 2007-2016 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2015 Jean Heimburger <http://tiaris.eu>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -10,7 +11,7 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
@ -18,90 +19,85 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/product/migrate_picture_path.php
|
||||
* \ingroup scripts
|
||||
* \brief Migrate pictures from old system prior to 3.7 to new path for 3.7+
|
||||
* \file scripts/product/migrate_picture_path.php
|
||||
* \ingroup scripts
|
||||
* \brief Migrate pictures from old system prior to 3.7 to new path for 3.7+
|
||||
*/
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Test if batch mode
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
@set_time_limit(0); // No timeout for this script
|
||||
define('EVEN_IF_ONLY_LOGIN_ALLOWED', 1); // Set this define to 0 if you want to lock your script when dolibarr setup is "locked to admin user only".
|
||||
@set_time_limit(0); // No timeout for this script
|
||||
define('EVEN_IF_ONLY_LOGIN_ALLOWED', 1); // Set this define to 0 if you want to lock your script when dolibarr setup is "locked to admin user only".
|
||||
|
||||
// Include and load Dolibarr environment variables
|
||||
require_once $path."../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/lib/images.lib.php";
|
||||
require_once $path . "../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/product/class/product.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/core/lib/files.lib.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/core/lib/images.lib.php";
|
||||
// After this $db, $mysoc, $langs, $conf and $hookmanager are defined (Opened $db handler to database will be closed at end of file).
|
||||
// $user is created but empty.
|
||||
|
||||
//$langs->setDefaultLang('en_US'); // To change default language of $langs
|
||||
$langs->load("main"); // To load language file for default language
|
||||
|
||||
// $langs->setDefaultLang('en_US'); // To change default language of $langs
|
||||
$langs->load("main"); // To load language file for default language
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
$forcecommit=0;
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
$forcecommit = 0;
|
||||
|
||||
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',', $argv));
|
||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||
|
||||
if (empty($argv[1])) {
|
||||
print "Usage: $script_file subdirtoscan\n";
|
||||
print "Example: $script_file produit\n";
|
||||
exit(-1);
|
||||
print "Usage: $script_file subdirtoscan\n";
|
||||
print "Example: $script_file produit\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
print '--- start'."\n";
|
||||
print '--- start' . "\n";
|
||||
|
||||
$dir = DOL_DATA_ROOT;
|
||||
$subdir=$argv[1];
|
||||
if (empty($dir) || empty($subdir))
|
||||
{
|
||||
$subdir = $argv[1];
|
||||
if (empty($dir) || empty($subdir)) {
|
||||
dol_print_error('', 'dir not defined');
|
||||
exit(1);
|
||||
}
|
||||
if (! dol_is_dir($dir.'/'.$subdir))
|
||||
{
|
||||
print 'Directory '.$dir.'/'.$subdir.' not found.'."\n";
|
||||
if (! dol_is_dir($dir . '/' . $subdir)) {
|
||||
print 'Directory ' . $dir . '/' . $subdir . ' not found.' . "\n";
|
||||
exit(2);
|
||||
}
|
||||
|
||||
$filearray=dol_dir_list($dir.'/'.$subdir, "directories", 0, '', 'temp$');
|
||||
$filearray = dol_dir_list($dir . '/' . $subdir, "directories", 0, '', 'temp$');
|
||||
|
||||
global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini;
|
||||
|
||||
foreach($filearray as $keyf => $valf)
|
||||
{
|
||||
$ref=basename($valf['name']);
|
||||
$filearrayimg=dol_dir_list($valf['fullname'], "files", 0, '(\.gif|\.png|\.jpg|\.jpeg|\.bmp)$', '(\.meta|_preview.*\.png)$');
|
||||
foreach($filearrayimg as $keyi => $vali)
|
||||
{
|
||||
print 'Process image for ref '.$ref.' : '.$vali['name']."\n";
|
||||
foreach ($filearray as $keyf => $valf) {
|
||||
$ref = basename($valf['name']);
|
||||
$filearrayimg = dol_dir_list($valf['fullname'], "files", 0, '(\.gif|\.png|\.jpg|\.jpeg|\.bmp)$', '(\.meta|_preview.*\.png)$');
|
||||
foreach ($filearrayimg as $keyi => $vali) {
|
||||
print 'Process image for ref ' . $ref . ' : ' . $vali['name'] . "\n";
|
||||
|
||||
// Create small thumbs for image
|
||||
// Used on logon for example
|
||||
$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)
|
||||
// Used on menu or for setup page for example
|
||||
$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";
|
||||
}
|
||||
}
|
||||
|
||||
$db->close(); // Close $db database opened handler
|
||||
$db->close(); // Close $db database opened handler
|
||||
|
||||
exit($error);
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -11,7 +11,7 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
@ -19,67 +19,63 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/user/sync_groups_dolibarr2ldap.php
|
||||
* \ingroup ldap core
|
||||
* \brief Script de mise a jour des groupes dans LDAP depuis base Dolibarr
|
||||
* \file scripts/user/sync_groups_dolibarr2ldap.php
|
||||
* \ingroup ldap core
|
||||
* \brief Script de mise a jour des groupes dans LDAP depuis base Dolibarr
|
||||
*/
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Test if batch mode
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
if (! isset($argv[1]) || ! $argv[1]) {
|
||||
print "Usage: ".$script_file." now\n";
|
||||
exit(-1);
|
||||
print "Usage: " . $script_file . " now\n";
|
||||
exit(- 1);
|
||||
}
|
||||
$now=$argv[1];
|
||||
$now = $argv[1];
|
||||
|
||||
require_once $path."../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php";
|
||||
require_once $path . "../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/core/class/ldap.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/user/class/usergroup.class.php";
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',', $argv));
|
||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||
|
||||
/*
|
||||
if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
|
||||
{
|
||||
print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
||||
exit(-1);
|
||||
}
|
||||
*/
|
||||
* if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
|
||||
* {
|
||||
* print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
||||
* exit(-1);
|
||||
* }
|
||||
*/
|
||||
|
||||
$sql = "SELECT rowid";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."usergroup";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "usergroup";
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
|
||||
$ldap=new Ldap();
|
||||
$ldap = new Ldap();
|
||||
$ldap->connect_bind();
|
||||
|
||||
while ($i < $num)
|
||||
{
|
||||
$ldap->error="";
|
||||
while ($i < $num) {
|
||||
$ldap->error = "";
|
||||
|
||||
$obj = $db->fetch_object($resql);
|
||||
|
||||
@ -87,37 +83,32 @@ if ($resql)
|
||||
$fgroup->id = $obj->rowid;
|
||||
$fgroup->fetch($fgroup->id);
|
||||
|
||||
print $langs->trans("UpdateGroup")." rowid=".$fgroup->id." ".$fgroup->name;
|
||||
print $langs->trans("UpdateGroup") . " rowid=" . $fgroup->id . " " . $fgroup->name;
|
||||
|
||||
$oldobject=$fgroup;
|
||||
$oldobject = $fgroup;
|
||||
|
||||
$oldinfo=$oldobject->_load_ldap_info();
|
||||
$olddn=$oldobject->_load_ldap_dn($oldinfo);
|
||||
$oldinfo = $oldobject->_load_ldap_info();
|
||||
$olddn = $oldobject->_load_ldap_dn($oldinfo);
|
||||
|
||||
$info=$fgroup->_load_ldap_info();
|
||||
$dn=$fgroup->_load_ldap_dn($info);
|
||||
$info = $fgroup->_load_ldap_info();
|
||||
$dn = $fgroup->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->add($dn, $info, $user); // Wil fail if already exists
|
||||
$result=$ldap->update($dn, $info, $user, $olddn);
|
||||
if ($result > 0)
|
||||
{
|
||||
print " - ".$langs->trans("OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
print " - ".$langs->trans("KO").' - '.$ldap->error;
|
||||
$result = $ldap->add($dn, $info, $user); // Wil fail if already exists
|
||||
$result = $ldap->update($dn, $info, $user, $olddn);
|
||||
if ($result > 0) {
|
||||
print " - " . $langs->trans("OK");
|
||||
} else {
|
||||
$error ++;
|
||||
print " - " . $langs->trans("KO") . ' - ' . $ldap->error;
|
||||
}
|
||||
print "\n";
|
||||
|
||||
$i++;
|
||||
$i ++;
|
||||
}
|
||||
|
||||
$ldap->unbind();
|
||||
$ldap->close();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2013 Maxime Kohlhaas <maxime@atm-consulting.fr>
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2013 Maxime Kohlhaas <maxime@atm-consulting.fr>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -12,7 +12,7 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
@ -20,182 +20,166 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/user/sync_groups_ldap2dolibarr.php
|
||||
* \ingroup ldap member
|
||||
* \brief Script to update groups into Dolibarr from LDAP
|
||||
* \file scripts/user/sync_groups_ldap2dolibarr.php
|
||||
* \ingroup ldap member
|
||||
* \brief Script to update groups into Dolibarr from LDAP
|
||||
*/
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Test if batch mode
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
require_once $path."../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/user/class/user.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php";
|
||||
require_once $path . "../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/core/lib/date.lib.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/core/class/ldap.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/user/class/user.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/user/class/usergroup.class.php";
|
||||
|
||||
$langs->loadLangs(array("main", "errors"));
|
||||
$langs->loadLangs(array("main","errors"));
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
$forcecommit=0;
|
||||
$confirmed=0;
|
||||
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
$forcecommit = 0;
|
||||
$confirmed = 0;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',', $argv));
|
||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||
|
||||
// List of fields to get from LDAP
|
||||
$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
|
||||
);
|
||||
$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);
|
||||
|
||||
// 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])) {
|
||||
//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";
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
foreach($argv as $key => $val)
|
||||
{
|
||||
if ($val == 'commitiferror') $forcecommit=1;
|
||||
if (preg_match('/--server=([^\s]+)$/', $val, $reg)) $conf->global->LDAP_SERVER_HOST=$reg[1];
|
||||
if (preg_match('/--excludeuser=([^\s]+)$/', $val, $reg)) $excludeuser=explode(',', $reg[1]);
|
||||
if (preg_match('/-y$/', $val, $reg)) $confirmed=1;
|
||||
foreach ($argv as $key => $val) {
|
||||
if ($val == 'commitiferror')
|
||||
$forcecommit = 1;
|
||||
if (preg_match('/--server=([^\s]+)$/', $val, $reg))
|
||||
$conf->global->LDAP_SERVER_HOST = $reg[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";
|
||||
$conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails
|
||||
$conf->global->MAIN_DISABLE_ALL_MAILS = 1; // On bloque les mails
|
||||
print "\n";
|
||||
print "----- Synchronize all records from LDAP database:\n";
|
||||
print "host=".$conf->global->LDAP_SERVER_HOST."\n";
|
||||
print "port=".$conf->global->LDAP_SERVER_PORT."\n";
|
||||
print "login=".$conf->global->LDAP_ADMIN_DN."\n";
|
||||
print "pass=".preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)."\n";
|
||||
print "DN to extract=".$conf->global->LDAP_GROUP_DN."\n";
|
||||
print 'Filter=('.$conf->global->LDAP_KEY_GROUPS.'=*)'."\n";
|
||||
print "host=" . $conf->global->LDAP_SERVER_HOST . "\n";
|
||||
print "port=" . $conf->global->LDAP_SERVER_PORT . "\n";
|
||||
print "login=" . $conf->global->LDAP_ADMIN_DN . "\n";
|
||||
print "pass=" . preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS) . "\n";
|
||||
print "DN to extract=" . $conf->global->LDAP_GROUP_DN . "\n";
|
||||
print 'Filter=(' . $conf->global->LDAP_KEY_GROUPS . '=*)' . "\n";
|
||||
print "----- To Dolibarr database:\n";
|
||||
print "type=".$conf->db->type."\n";
|
||||
print "host=".$conf->db->host."\n";
|
||||
print "port=".$conf->db->port."\n";
|
||||
print "login=".$conf->db->user."\n";
|
||||
print "database=".$conf->db->name."\n";
|
||||
print "type=" . $conf->db->type . "\n";
|
||||
print "host=" . $conf->db->host . "\n";
|
||||
print "port=" . $conf->db->port . "\n";
|
||||
print "login=" . $conf->db->user . "\n";
|
||||
print "database=" . $conf->db->name . "\n";
|
||||
print "----- Options:\n";
|
||||
print "commitiferror=".$forcecommit."\n";
|
||||
print "Mapped LDAP fields=".join(',', $required_fields)."\n";
|
||||
print "commitiferror=" . $forcecommit . "\n";
|
||||
print "Mapped LDAP fields=" . join(',', $required_fields) . "\n";
|
||||
print "\n";
|
||||
|
||||
if (! $confirmed)
|
||||
{
|
||||
if (! $confirmed) {
|
||||
print "Hit Enter to continue or CTRL+C to stop...\n";
|
||||
$input = trim(fgets(STDIN));
|
||||
}
|
||||
|
||||
if (empty($conf->global->LDAP_GROUP_DN))
|
||||
{
|
||||
print $langs->trans("Error").': '.$langs->trans("LDAP setup for groups not defined inside Dolibarr");
|
||||
exit(-1);
|
||||
if (empty($conf->global->LDAP_GROUP_DN)) {
|
||||
print $langs->trans("Error") . ': ' . $langs->trans("LDAP setup for groups not defined inside Dolibarr");
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
|
||||
$ldap = new Ldap();
|
||||
$result = $ldap->connect_bind();
|
||||
if ($result >= 0)
|
||||
{
|
||||
$justthese=array();
|
||||
|
||||
if ($result >= 0) {
|
||||
$justthese = array();
|
||||
|
||||
// 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));
|
||||
if (is_array($ldaprecords))
|
||||
{
|
||||
if (is_array($ldaprecords)) {
|
||||
$db->begin();
|
||||
|
||||
// Warning $ldapuser has a key in lowercase
|
||||
foreach ($ldaprecords as $key => $ldapgroup)
|
||||
{
|
||||
foreach ($ldaprecords as $key => $ldapgroup) {
|
||||
$group = new UserGroup($db);
|
||||
$group->fetch('', $ldapgroup[$conf->global->LDAP_KEY_GROUPS]);
|
||||
$group->name = $ldapgroup[$conf->global->LDAP_GROUP_FIELD_FULLNAME];
|
||||
$group->nom = $group->name; // For backward compatibility
|
||||
$group->nom = $group->name; // For backward compatibility
|
||||
$group->note = $ldapgroup[$conf->global->LDAP_GROUP_FIELD_DESCRIPTION];
|
||||
$group->entity = $conf->entity;
|
||||
|
||||
//print_r($ldapgroup);
|
||||
// print_r($ldapgroup);
|
||||
|
||||
if($group->id > 0) { // Group update
|
||||
print $langs->transnoentities("GroupUpdate").' # '.$key.': name='.$group->name;
|
||||
$res=$group->update();
|
||||
if ($group->id > 0) { // Group update
|
||||
print $langs->transnoentities("GroupUpdate") . ' # ' . $key . ': name=' . $group->name;
|
||||
$res = $group->update();
|
||||
|
||||
if ($res > 0)
|
||||
{
|
||||
print ' --> Updated group id='.$group->id.' name='.$group->name;
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
print ' --> '.$res.' '.$group->error;
|
||||
if ($res > 0) {
|
||||
print ' --> Updated group id=' . $group->id . ' name=' . $group->name;
|
||||
} else {
|
||||
$error ++;
|
||||
print ' --> ' . $res . ' ' . $group->error;
|
||||
}
|
||||
print "\n";
|
||||
} else { // Group creation
|
||||
print $langs->transnoentities("GroupCreate").' # '.$key.': name='.$group->name;
|
||||
$res=$group->create();
|
||||
print $langs->transnoentities("GroupCreate") . ' # ' . $key . ': name=' . $group->name;
|
||||
$res = $group->create();
|
||||
|
||||
if ($res > 0)
|
||||
{
|
||||
print ' --> Created group id='.$group->id.' name='.$group->name;
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
print ' --> '.$res.' '.$group->error;
|
||||
if ($res > 0) {
|
||||
print ' --> Created group id=' . $group->id . ' name=' . $group->name;
|
||||
} else {
|
||||
$error ++;
|
||||
print ' --> ' . $res . ' ' . $group->error;
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
|
||||
//print_r($group);
|
||||
// print_r($group);
|
||||
|
||||
// Gestion des utilisateurs associés au groupe
|
||||
// 1 - Association des utilisateurs du groupe LDAP au groupe Dolibarr
|
||||
$userList = array();
|
||||
$userIdList = array();
|
||||
foreach($ldapgroup[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] as $key => $userdn) {
|
||||
if($key === 'count') continue;
|
||||
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
|
||||
if ($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS === 'memberUid'){
|
||||
foreach ($ldapgroup[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] as $key => $userdn) {
|
||||
if ($key === 'count')
|
||||
continue;
|
||||
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
|
||||
if ($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS === 'memberUid') {
|
||||
$userKey = array($userdn);
|
||||
} else { // Pour les autres schémas, les membres sont listés sous forme de DN complets
|
||||
$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);
|
||||
|
||||
if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) {
|
||||
if ($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) {
|
||||
$fuser->fetch('', '', $userKey[0]); // Chargement du user concerné par le SID
|
||||
} elseif ($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) {
|
||||
$fuser->fetch('', $userKey[0]); // Chargement du user concerné par le login
|
||||
@ -209,55 +193,49 @@ if ($result >= 0)
|
||||
$userIdList[$userdn] = $fuser->id;
|
||||
|
||||
// Ajout de l'utilisateur dans le groupe
|
||||
if(!in_array($fuser->id, array_keys($group->members))) {
|
||||
if (! in_array($fuser->id, array_keys($group->members))) {
|
||||
$fuser->SetInGroup($group->id, $group->entity);
|
||||
echo $fuser->login.' added'."\n";
|
||||
echo $fuser->login . ' added' . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// 2 - Suppression des utilisateurs du groupe Dolibarr qui ne sont plus dans le groupe LDAP
|
||||
foreach ($group->members as $guser) {
|
||||
if(!in_array($guser->id, $userIdList)) {
|
||||
if (! in_array($guser->id, $userIdList)) {
|
||||
$guser->RemoveFromGroup($group->id, $group->entity);
|
||||
echo $guser->login.' removed'."\n";
|
||||
echo $guser->login . ' removed' . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error || $forcecommit)
|
||||
{
|
||||
if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n";
|
||||
else print $langs->transnoentities("ErrorButCommitIsDone")."\n";
|
||||
if (! $error || $forcecommit) {
|
||||
if (! $error)
|
||||
print $langs->transnoentities("NoErrorCommitIsDone") . "\n";
|
||||
else
|
||||
print $langs->transnoentities("ErrorButCommitIsDone") . "\n";
|
||||
$db->commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error)."\n";
|
||||
} else {
|
||||
print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error) . "\n";
|
||||
$db->rollback();
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dol_print_error('', $ldap->error);
|
||||
$error++;
|
||||
$error ++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dol_print_error('', $ldap->error);
|
||||
$error++;
|
||||
$error ++;
|
||||
}
|
||||
|
||||
|
||||
exit($error);
|
||||
|
||||
|
||||
/**
|
||||
* Function to say if a value is empty or not
|
||||
*
|
||||
* @param string $element Value to test
|
||||
* @return boolean True of false
|
||||
* @param string $element Value to test
|
||||
* @return boolean True of false
|
||||
*/
|
||||
function dolValidElement($element)
|
||||
{
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -11,7 +11,7 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
@ -19,104 +19,95 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/user/sync_users_dolibarr2ldap.php
|
||||
* \ingroup ldap core
|
||||
* \brief Script de mise a jour des users dans LDAP depuis base Dolibarr
|
||||
* \file scripts/user/sync_users_dolibarr2ldap.php
|
||||
* \ingroup ldap core
|
||||
* \brief Script de mise a jour des users dans LDAP depuis base Dolibarr
|
||||
*/
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Test if batch mode
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
if (! isset($argv[1]) || ! $argv[1]) {
|
||||
print "Usage: $script_file now\n";
|
||||
exit(-1);
|
||||
print "Usage: $script_file now\n";
|
||||
exit(- 1);
|
||||
}
|
||||
$now=$argv[1];
|
||||
$now = $argv[1];
|
||||
|
||||
require_once $path."../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/user/class/user.class.php";
|
||||
require_once $path . "../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/core/class/ldap.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/user/class/user.class.php";
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',', $argv));
|
||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||
|
||||
/*
|
||||
if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
|
||||
{
|
||||
print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
||||
exit(-1);
|
||||
}
|
||||
*/
|
||||
* if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
|
||||
* {
|
||||
* print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
||||
* exit(-1);
|
||||
* }
|
||||
*/
|
||||
|
||||
$sql = "SELECT rowid";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."user";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "user";
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
|
||||
$ldap=new Ldap();
|
||||
$ldap = new Ldap();
|
||||
$ldap->connect_bind();
|
||||
|
||||
while ($i < $num)
|
||||
{
|
||||
$ldap->error="";
|
||||
while ($i < $num) {
|
||||
$ldap->error = "";
|
||||
|
||||
$obj = $db->fetch_object($resql);
|
||||
|
||||
$fuser = new User($db);
|
||||
$fuser->fetch($obj->rowid);
|
||||
|
||||
print $langs->trans("UpdateUser")." rowid=".$fuser->id." ".$fuser->getFullName($langs);
|
||||
print $langs->trans("UpdateUser") . " rowid=" . $fuser->id . " " . $fuser->getFullName($langs);
|
||||
|
||||
$oldobject=$fuser;
|
||||
$oldobject = $fuser;
|
||||
|
||||
$oldinfo=$oldobject->_load_ldap_info();
|
||||
$olddn=$oldobject->_load_ldap_dn($oldinfo);
|
||||
$oldinfo = $oldobject->_load_ldap_info();
|
||||
$olddn = $oldobject->_load_ldap_dn($oldinfo);
|
||||
|
||||
$info=$fuser->_load_ldap_info();
|
||||
$dn=$fuser->_load_ldap_dn($info);
|
||||
$info = $fuser->_load_ldap_info();
|
||||
$dn = $fuser->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->add($dn, $info, $user); // Wil fail if already exists
|
||||
$result=$ldap->update($dn, $info, $user, $olddn);
|
||||
if ($result > 0)
|
||||
{
|
||||
print " - ".$langs->trans("OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
print " - ".$langs->trans("KO").' - '.$ldap->error;
|
||||
$result = $ldap->add($dn, $info, $user); // Wil fail if already exists
|
||||
$result = $ldap->update($dn, $info, $user, $olddn);
|
||||
if ($result > 0) {
|
||||
print " - " . $langs->trans("OK");
|
||||
} else {
|
||||
$error ++;
|
||||
print " - " . $langs->trans("KO") . ' - ' . $ldap->error;
|
||||
}
|
||||
print "\n";
|
||||
|
||||
$i++;
|
||||
$i ++;
|
||||
}
|
||||
|
||||
$ldap->unbind();
|
||||
$ldap->close();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -11,7 +11,7 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
@ -19,301 +19,266 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/user/sync_users_ldap2dolibarr.php
|
||||
* \ingroup ldap member
|
||||
* \brief Script to update users into Dolibarr from LDAP
|
||||
* \file scripts/user/sync_users_ldap2dolibarr.php
|
||||
* \ingroup ldap member
|
||||
* \brief Script to update users into Dolibarr from LDAP
|
||||
*/
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Test if batch mode
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
require_once $path."../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/user/class/user.class.php";
|
||||
require_once $path . "../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/core/lib/date.lib.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/core/class/ldap.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/user/class/user.class.php";
|
||||
|
||||
$langs->loadLangs(array("main", "errors"));
|
||||
$langs->loadLangs(array("main","errors"));
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
$forcecommit=0;
|
||||
$excludeuser=array();
|
||||
$confirmed=0;
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
$forcecommit = 0;
|
||||
$excludeuser = array();
|
||||
$confirmed = 0;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',', $argv));
|
||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||
|
||||
// List of fields to get from LDAP
|
||||
$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_FIELD_ADDRESS,
|
||||
//$conf->global->LDAP_FIELD_ZIP,
|
||||
//$conf->global->LDAP_FIELD_TOWN,
|
||||
//$conf->global->LDAP_FIELD_COUNTRY,
|
||||
$conf->global->LDAP_FIELD_MAIL,
|
||||
$conf->global->LDAP_FIELD_TITLE,
|
||||
$conf->global->LDAP_FIELD_DESCRIPTION,
|
||||
$conf->global->LDAP_FIELD_SID
|
||||
);
|
||||
$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_FIELD_ADDRESS,
|
||||
// $conf->global->LDAP_FIELD_ZIP,
|
||||
// $conf->global->LDAP_FIELD_TOWN,
|
||||
// $conf->global->LDAP_FIELD_COUNTRY,
|
||||
$conf->global->LDAP_FIELD_MAIL,$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
|
||||
$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])) {
|
||||
print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n";
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
foreach($argv as $key => $val)
|
||||
{
|
||||
if ($val == 'commitiferror') $forcecommit=1;
|
||||
if (preg_match('/--server=([^\s]+)$/', $val, $reg)) $conf->global->LDAP_SERVER_HOST=$reg[1];
|
||||
if (preg_match('/--excludeuser=([^\s]+)$/', $val, $reg)) $excludeuser=explode(',', $reg[1]);
|
||||
if (preg_match('/-y$/', $val, $reg)) $confirmed=1;
|
||||
foreach ($argv as $key => $val) {
|
||||
if ($val == 'commitiferror')
|
||||
$forcecommit = 1;
|
||||
if (preg_match('/--server=([^\s]+)$/', $val, $reg))
|
||||
$conf->global->LDAP_SERVER_HOST = $reg[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";
|
||||
$conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails
|
||||
$conf->global->MAIN_DISABLE_ALL_MAILS = 1; // On bloque les mails
|
||||
print "\n";
|
||||
print "----- Synchronize all records from LDAP database:\n";
|
||||
print "host=".$conf->global->LDAP_SERVER_HOST."\n";
|
||||
print "port=".$conf->global->LDAP_SERVER_PORT."\n";
|
||||
print "login=".$conf->global->LDAP_ADMIN_DN."\n";
|
||||
print "pass=".preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)."\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
|
||||
else print 'Filter=('.$conf->global->LDAP_KEY_USERS.'=*)'."\n";
|
||||
print "host=" . $conf->global->LDAP_SERVER_HOST . "\n";
|
||||
print "port=" . $conf->global->LDAP_SERVER_PORT . "\n";
|
||||
print "login=" . $conf->global->LDAP_ADMIN_DN . "\n";
|
||||
print "pass=" . preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS) . "\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
|
||||
else
|
||||
print 'Filter=(' . $conf->global->LDAP_KEY_USERS . '=*)' . "\n";
|
||||
print "----- To Dolibarr database:\n";
|
||||
print "type=".$conf->db->type."\n";
|
||||
print "host=".$conf->db->host."\n";
|
||||
print "port=".$conf->db->port."\n";
|
||||
print "login=".$conf->db->user."\n";
|
||||
print "database=".$conf->db->name."\n";
|
||||
print "type=" . $conf->db->type . "\n";
|
||||
print "host=" . $conf->db->host . "\n";
|
||||
print "port=" . $conf->db->port . "\n";
|
||||
print "login=" . $conf->db->user . "\n";
|
||||
print "database=" . $conf->db->name . "\n";
|
||||
print "----- Options:\n";
|
||||
print "commitiferror=".$forcecommit."\n";
|
||||
print "excludeuser=".join(',', $excludeuser)."\n";
|
||||
print "Mapped LDAP fields=".join(',', $required_fields)."\n";
|
||||
print "commitiferror=" . $forcecommit . "\n";
|
||||
print "excludeuser=" . join(',', $excludeuser) . "\n";
|
||||
print "Mapped LDAP fields=" . join(',', $required_fields) . "\n";
|
||||
print "\n";
|
||||
|
||||
if (! $confirmed)
|
||||
{
|
||||
if (! $confirmed) {
|
||||
print "Hit Enter to continue or CTRL+C to stop...\n";
|
||||
$input = trim(fgets(STDIN));
|
||||
}
|
||||
|
||||
if (empty($conf->global->LDAP_USER_DN))
|
||||
{
|
||||
print $langs->trans("Error").': '.$langs->trans("LDAP setup for users not defined inside Dolibarr");
|
||||
exit(-1);
|
||||
if (empty($conf->global->LDAP_USER_DN)) {
|
||||
print $langs->trans("Error") . ': ' . $langs->trans("LDAP setup for users not defined inside Dolibarr");
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
|
||||
// Load table of correspondence of countries
|
||||
$hashlib2rowid=array();
|
||||
$countries=array();
|
||||
$hashlib2rowid = array();
|
||||
$countries = array();
|
||||
$sql = "SELECT rowid, code, label, active";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."c_country";
|
||||
$sql.= " WHERE active = 1";
|
||||
$sql.= " ORDER BY code ASC";
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "c_country";
|
||||
$sql .= " WHERE active = 1";
|
||||
$sql .= " ORDER BY code ASC";
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
if ($num)
|
||||
{
|
||||
while ($i < $num)
|
||||
{
|
||||
if ($num) {
|
||||
while ($i < $num) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
if ($obj)
|
||||
{
|
||||
//print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n";
|
||||
$hashlib2rowid[strtolower($obj->label)]=$obj->rowid;
|
||||
$countries[$obj->rowid]=array('rowid' => $obj->rowid, 'label' => $obj->label, 'code' => $obj->code);
|
||||
if ($obj) {
|
||||
// print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n";
|
||||
$hashlib2rowid[strtolower($obj->label)] = $obj->rowid;
|
||||
$countries[$obj->rowid] = array('rowid' => $obj->rowid,'label' => $obj->label,'code' => $obj->code);
|
||||
}
|
||||
$i++;
|
||||
$i ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
exit(-1);
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$ldap = new Ldap();
|
||||
$result = $ldap->connect_bind();
|
||||
if ($result >= 0)
|
||||
{
|
||||
$justthese=array();
|
||||
|
||||
if ($result >= 0) {
|
||||
$justthese = array();
|
||||
|
||||
// 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
|
||||
if (is_array($ldaprecords))
|
||||
{
|
||||
$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)) {
|
||||
$db->begin();
|
||||
|
||||
// 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 (in_array($ldapuser[$conf->global->LDAP_FIELD_LOGIN], $excludeuser))
|
||||
{
|
||||
print $langs->transnoentities("UserDiscarded").' # '.$key.': login='.$ldapuser[$conf->global->LDAP_FIELD_LOGIN].' --> Discarded'."\n";
|
||||
if (in_array($ldapuser[$conf->global->LDAP_FIELD_LOGIN], $excludeuser)) {
|
||||
print $langs->transnoentities("UserDiscarded") . ' # ' . $key . ': login=' . $ldapuser[$conf->global->LDAP_FIELD_LOGIN] . ' --> Discarded' . "\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$fuser = new User($db);
|
||||
|
||||
if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) {
|
||||
if ($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) {
|
||||
$fuser->fetch('', '', $ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le SID
|
||||
} elseif ($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) {
|
||||
$fuser->fetch('', $ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le login
|
||||
}
|
||||
|
||||
// Propriete membre
|
||||
$fuser->firstname=$ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME];
|
||||
$fuser->lastname=$ldapuser[$conf->global->LDAP_FIELD_NAME];
|
||||
$fuser->login=$ldapuser[$conf->global->LDAP_FIELD_LOGIN];
|
||||
$fuser->pass=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD];
|
||||
$fuser->pass_indatabase_crypted=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED];
|
||||
$fuser->firstname = $ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME];
|
||||
$fuser->lastname = $ldapuser[$conf->global->LDAP_FIELD_NAME];
|
||||
$fuser->login = $ldapuser[$conf->global->LDAP_FIELD_LOGIN];
|
||||
$fuser->pass = $ldapuser[$conf->global->LDAP_FIELD_PASSWORD];
|
||||
$fuser->pass_indatabase_crypted = $ldapuser[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED];
|
||||
|
||||
//$user->societe;
|
||||
// $user->societe;
|
||||
/*
|
||||
$fuser->address=$ldapuser[$conf->global->LDAP_FIELD_ADDRESS];
|
||||
$fuser->zip=$ldapuser[$conf->global->LDAP_FIELD_ZIP];
|
||||
$fuser->town=$ldapuser[$conf->global->LDAP_FIELD_TOWN];
|
||||
$fuser->country=$ldapuser[$conf->global->LDAP_FIELD_COUNTRY];
|
||||
$fuser->country_id=$countries[$hashlib2rowid[strtolower($fuser->country)]]['rowid'];
|
||||
$fuser->country_code=$countries[$hashlib2rowid[strtolower($fuser->country)]]['code'];
|
||||
*/
|
||||
* $fuser->address=$ldapuser[$conf->global->LDAP_FIELD_ADDRESS];
|
||||
* $fuser->zip=$ldapuser[$conf->global->LDAP_FIELD_ZIP];
|
||||
* $fuser->town=$ldapuser[$conf->global->LDAP_FIELD_TOWN];
|
||||
* $fuser->country=$ldapuser[$conf->global->LDAP_FIELD_COUNTRY];
|
||||
* $fuser->country_id=$countries[$hashlib2rowid[strtolower($fuser->country)]]['rowid'];
|
||||
* $fuser->country_code=$countries[$hashlib2rowid[strtolower($fuser->country)]]['code'];
|
||||
*/
|
||||
|
||||
$fuser->office_phone=$ldapuser[$conf->global->LDAP_FIELD_PHONE];
|
||||
$fuser->user_mobile=$ldapuser[$conf->global->LDAP_FIELD_MOBILE];
|
||||
$fuser->office_fax=$ldapuser[$conf->global->LDAP_FIELD_FAX];
|
||||
$fuser->email=$ldapuser[$conf->global->LDAP_FIELD_MAIL];
|
||||
$fuser->ldap_sid=$ldapuser[$conf->global->LDAP_FIELD_SID];
|
||||
$fuser->office_phone = $ldapuser[$conf->global->LDAP_FIELD_PHONE];
|
||||
$fuser->user_mobile = $ldapuser[$conf->global->LDAP_FIELD_MOBILE];
|
||||
$fuser->office_fax = $ldapuser[$conf->global->LDAP_FIELD_FAX];
|
||||
$fuser->email = $ldapuser[$conf->global->LDAP_FIELD_MAIL];
|
||||
$fuser->ldap_sid = $ldapuser[$conf->global->LDAP_FIELD_SID];
|
||||
|
||||
$fuser->job=$ldapuser[$conf->global->LDAP_FIELD_TITLE];
|
||||
$fuser->note=$ldapuser[$conf->global->LDAP_FIELD_DESCRIPTION];
|
||||
$fuser->admin=0;
|
||||
$fuser->societe_id=0;
|
||||
$fuser->contact_id=0;
|
||||
$fuser->fk_member=0;
|
||||
$fuser->job = $ldapuser[$conf->global->LDAP_FIELD_TITLE];
|
||||
$fuser->note = $ldapuser[$conf->global->LDAP_FIELD_DESCRIPTION];
|
||||
$fuser->admin = 0;
|
||||
$fuser->societe_id = 0;
|
||||
$fuser->contact_id = 0;
|
||||
$fuser->fk_member = 0;
|
||||
|
||||
$fuser->statut=1;
|
||||
$fuser->statut = 1;
|
||||
// TODO : revoir la gestion du 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->statut=$ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS];
|
||||
}*/
|
||||
//if ($fuser->statut > 1) $fuser->statut=1;
|
||||
/*
|
||||
* 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->statut=$ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS];
|
||||
* }
|
||||
*/
|
||||
// if ($fuser->statut > 1) $fuser->statut=1;
|
||||
|
||||
//print_r($ldapuser);
|
||||
// print_r($ldapuser);
|
||||
|
||||
if($fuser->id > 0) { // User update
|
||||
print $langs->transnoentities("UserUpdate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs);
|
||||
$res=$fuser->update($user);
|
||||
if ($fuser->id > 0) { // User update
|
||||
print $langs->transnoentities("UserUpdate") . ' # ' . $key . ': login=' . $fuser->login . ', fullname=' . $fuser->getFullName($langs);
|
||||
$res = $fuser->update($user);
|
||||
|
||||
if ($res < 0)
|
||||
{
|
||||
$error++;
|
||||
print ' --> '.$res.' '.$fuser->error;
|
||||
}
|
||||
else
|
||||
{
|
||||
print ' --> Updated user id='.$fuser->id.' login='.$fuser->login;
|
||||
if ($res < 0) {
|
||||
$error ++;
|
||||
print ' --> ' . $res . ' ' . $fuser->error;
|
||||
} else {
|
||||
print ' --> Updated user id=' . $fuser->id . ' login=' . $fuser->login;
|
||||
}
|
||||
} else { // User creation
|
||||
print $langs->transnoentities("UserCreate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs);
|
||||
$res=$fuser->create($user);
|
||||
print $langs->transnoentities("UserCreate") . ' # ' . $key . ': login=' . $fuser->login . ', fullname=' . $fuser->getFullName($langs);
|
||||
$res = $fuser->create($user);
|
||||
|
||||
if ($res > 0)
|
||||
{
|
||||
print ' --> Created user id='.$fuser->id.' login='.$fuser->login;
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
print ' --> '.$res.' '.$fuser->error;
|
||||
if ($res > 0) {
|
||||
print ' --> Created user id=' . $fuser->id . ' login=' . $fuser->login;
|
||||
} else {
|
||||
$error ++;
|
||||
print ' --> ' . $res . ' ' . $fuser->error;
|
||||
}
|
||||
}
|
||||
print "\n";
|
||||
//print_r($fuser);
|
||||
// print_r($fuser);
|
||||
|
||||
// Gestion des groupes
|
||||
// TODO : revoir la gestion des groupes (ou script de sync groupes)
|
||||
/*if(!$error) {
|
||||
foreach ($ldapuser[$conf->global->LDAP_FIELD_USERGROUPS] as $groupdn) {
|
||||
$groupdn;
|
||||
}
|
||||
}*/
|
||||
/*
|
||||
* if(!$error) {
|
||||
* foreach ($ldapuser[$conf->global->LDAP_FIELD_USERGROUPS] as $groupdn) {
|
||||
* $groupdn;
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
}
|
||||
|
||||
if (! $error || $forcecommit)
|
||||
{
|
||||
if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n";
|
||||
else print $langs->transnoentities("ErrorButCommitIsDone")."\n";
|
||||
if (! $error || $forcecommit) {
|
||||
if (! $error)
|
||||
print $langs->transnoentities("NoErrorCommitIsDone") . "\n";
|
||||
else
|
||||
print $langs->transnoentities("ErrorButCommitIsDone") . "\n";
|
||||
$db->commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error)."\n";
|
||||
} else {
|
||||
print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error) . "\n";
|
||||
$db->rollback();
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dol_print_error('', $ldap->error);
|
||||
$error++;
|
||||
$error ++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dol_print_error('', $ldap->error);
|
||||
$error++;
|
||||
$error ++;
|
||||
}
|
||||
|
||||
|
||||
exit($error);
|
||||
|
||||
|
||||
/**
|
||||
* Function to say if a value is empty or not
|
||||
*
|
||||
* @param string $element Value to test
|
||||
* @return boolean True of false
|
||||
* @param string $element Value to test
|
||||
* @return boolean True of false
|
||||
*/
|
||||
function dolValidElement($element)
|
||||
{
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -11,7 +11,7 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
@ -19,39 +19,37 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/withdrawals/build_withdrawal_file.php
|
||||
* \ingroup prelevement
|
||||
* \brief Script de prelevement
|
||||
* \file scripts/withdrawals/build_withdrawal_file.php
|
||||
* \ingroup prelevement
|
||||
* \brief Script de prelevement
|
||||
*/
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
$path=dirname(__FILE__).'/';
|
||||
$path = __DIR__ . '/';
|
||||
|
||||
// Test if batch mode
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
require_once $path."../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/compta/prelevement/class/bonprelevement.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/societe/class/societe.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/compta/paiement/class/paiement.class.php";
|
||||
require_once $path . "../../htdocs/master.inc.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/compta/prelevement/class/bonprelevement.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/compta/facture/class/facture.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/societe/class/societe.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT . "/compta/paiement/class/paiement.class.php";
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',', $argv));
|
||||
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
|
||||
dol_syslog($script_file . " launched with arg " . join(',', $argv));
|
||||
|
||||
$datetimeprev = dol_now();
|
||||
|
||||
@ -61,18 +59,16 @@ $year = strftime("%Y", $datetimeprev);
|
||||
$user = new user($db);
|
||||
$user->fetch($conf->global->PRELEVEMENT_USER);
|
||||
|
||||
if (! isset($argv[1])) { // Check parameters
|
||||
print "This script check invoices with a withdrawal request and\n";
|
||||
print "then create payment and build a withdraw file.\n";
|
||||
print "Usage: ".$script_file." simu|real\n";
|
||||
exit(-1);
|
||||
if (! isset($argv[1])) { // Check parameters
|
||||
print "This script check invoices with a withdrawal request and\n";
|
||||
print "then create payment and build a withdraw file.\n";
|
||||
print "Usage: " . $script_file . " simu|real\n";
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
|
||||
$withdrawreceipt=new BonPrelevement($db);
|
||||
$withdrawreceipt = new BonPrelevement($db);
|
||||
// $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();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user