Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2024-01-29 11:41:22 +01:00
commit fd0495e1c7
49 changed files with 1721 additions and 99 deletions

View file

@ -14,6 +14,17 @@ jobs:
- name: Install required tools
run: sudo apt-get update && sudo apt-get install cppcheck
if: false
# The next uses the git API because there is no clone yet.
# This is faster for a big repo.
- name: Get all changed php files (if PR)
id: changed-php
uses: tj-actions/changed-files@v42
if: github.event_name == 'pull_request'
with:
files: |
**.php
# Checkout git sources to analyze
- uses: actions/checkout@v4
# Action setup-python needs a requirements.txt or pyproject.toml
@ -42,6 +53,32 @@ jobs:
set -o pipefail
pre-commit gc
pre-commit run --show-diff-on-failure --color=always --all-files | tee ${RAW_LOG}
# The next uses git, which is slow for a bit repo.
# - name: Get all changed php files (if PR)
# id: changed-php
# uses: tj-actions/changed-files@v42
# if: github.event_name == 'pull_request'
# with:
# files: |
# **.php
- name: Setup PHPCS
uses: shivammathur/setup-php@v2
if: steps.changed-php.outputs.any_changed == 'true'
with:
php-version: 8.1
coverage: none # disable xdebug, pcov
tools: phpcs
- name: Run some pre-commit hooks on selected changed files only
if: steps.changed-php.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-php.outputs.all_changed_files }}
run: |
set -o pipefail
pre-commit run php-cs --files ${ALL_CHANGED_FILES} | tee -a ${RAW_LOG}
# If error, we convert log in the checkstyle format
- name: Convert Raw Log to CheckStyle format
if: ${{ failure() }}

View file

@ -3,7 +3,7 @@ exclude: (?x)^( htdocs/includes/ckeditor/.* )
repos:
# Several miscellaneous checks and fix (on yaml files, end of files fix)
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: no-commit-to-branch
args: [--branch, develop, --pattern, \d+.0]
@ -87,7 +87,7 @@ repos:
# Check format of yaml files
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.32.0
rev: v1.33.0
hooks:
- id: yamllint
args:
@ -97,7 +97,7 @@ repos:
# Execute codespell to fix typo errors (setup of codespell into dev/tools/codespell/)
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
rev: v2.2.6
hooks:
- id: codespell
# Due to a current limitation of configuration files,
@ -142,7 +142,7 @@ repos:
# Check some shell scripts
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.5
rev: v0.9.0.6
hooks:
- id: shellcheck
args: [-W, '100']

View file

@ -187,15 +187,8 @@ NEW: updating for display Help title when try to delete Don (issue #25314)
NEW: Upgrade in module builder in menu section
NEW: use account address in sepa mandate (#23642)
NEW: VAT rate - Add entity
<<<<<<< HEAD
NEW: webportal site account
NEW: When an user unset the batch management of products, transformation of each batch stock movement in global stock movement
FIX: #25828 wrong odt style naming
=======
NEW: When an user unset the batch management of products, transformation of each batch stock mouvement in global stock mouvement
NEW: PDF Generation for each Human Resource Evaluations.
>>>>>>> branch '19.0' of git@github.com:Dolibarr/dolibarr.git
SEC: #25512 applicative anti bruteforce - security on too many login attempts (#25520)
SEC: Add action confirm_... as sensitive to need a CSRF token

View file

@ -2069,6 +2069,14 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
// Show online payment link
$useonlinepayment = (isModEnabled('paypal') || isModEnabled('stripe') || isModEnabled('paybox'));
$parameters = array();
$reshook = $hookmanager->executeHooks('doShowOnlinePaymentUrl', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
} else {
$useonlinepayment = $reshook;
}
if ($useonlinepayment) {
print '<br>';
if (empty($amount)) { // Take the maximum amount among what the member is supposed to pay / has paid in the past

View file

@ -825,6 +825,14 @@ if (($action != 'addsubscription' && $action != 'create_thirdparty')) {
// Shon online payment link
$useonlinepayment = (isModEnabled('paypal') || isModEnabled('stripe') || isModEnabled('paybox'));
$parameters = array();
$reshook = $hookmanager->executeHooks('doShowOnlinePaymentUrl', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) {
if (isset($hookmanager->resArray['showonlinepaymenturl'])) {
$useonlinepayment = $hookmanager->resArray['showonlinepaymenturl'];
}
}
if ($useonlinepayment) {
print '<br>';

View file

@ -476,12 +476,12 @@ if (getDolGlobalInt('TICKET_ENABLE_PUBLIC_INTERFACE')) {
// Url public interface
$url_interface = getDolGlobalString("TICKET_URL_PUBLIC_INTERFACE");
print '<tr><td>'.$langs->trans("TicketUrlPublicInterfaceLabelAdmin").'</label>';
print '<tr><td>'.$langs->trans("UrlPublicInterfaceLabelAdmin").'</label>';
print '</td><td>';
print '<input type="text" class="minwidth500" name="TICKET_URL_PUBLIC_INTERFACE" value="'.$url_interface.'"></td>';
print '<input type="text" class="minwidth500" name="TICKET_URL_PUBLIC_INTERFACE" value="'.$url_interface.'" placeholder="https://..."></td>';
print '</td>';
print '<td class="center">';
print $form->textwithpicto('', $langs->trans("TicketUrlPublicInterfaceHelpAdmin"), 1, 'help');
print $form->textwithpicto('', $langs->trans("UrlPublicInterfaceHelpAdmin"), 1, 'help');
print '</td></tr>';
print '</table>';

View file

@ -61,7 +61,7 @@ $formSetup = new FormSetup($db);
$arrayofia = array('chatgpt');
foreach($arrayofia as $ia) {
foreach ($arrayofia as $ia) {
// Setup conf AI_PUBLIC_INTERFACE_TOPIC
$item = $formSetup->newItem('AI_KEY_API_'.strtoupper($ia));
$item->defaultFieldValue = '';

View file

@ -3090,6 +3090,15 @@ if ($action == 'create' && $usercancreate) {
// Show online payment link
$useonlinepayment = (isModEnabled('paypal') || isModEnabled('stripe') || isModEnabled('paybox'));
$parameters = array();
$reshook = $hookmanager->executeHooks('doShowOnlinePaymentUrl', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) {
if (isset($hookmanager->resArray['showonlinepaymenturl'])) {
$useonlinepayment = $hookmanager->resArray['showonlinepaymenturl'];
}
}
if (getDolGlobalString('ORDER_HIDE_ONLINE_PAYMENT_ON_ORDER')) {
$useonlinepayment = 0;
}

View file

@ -5993,6 +5993,14 @@ if ($action == 'create') {
// Show online payment link
$useonlinepayment = (isModEnabled('paypal') || isModEnabled('stripe') || isModEnabled('paybox'));
$parameters = array();
$reshook = $hookmanager->executeHooks('doShowOnlinePaymentUrl', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) {
if (isset($hookmanager->resArray['showonlinepaymenturl'])) {
$useonlinepayment = $hookmanager->resArray['showonlinepaymenturl'];
}
}
if ($object->status != Facture::STATUS_DRAFT && $useonlinepayment) {
print '<br><!-- Link to pay -->'."\n";
require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';

View file

@ -616,6 +616,9 @@ abstract class CommonDocGenerator
$resarray[$array_key.'_bank_label'] = (empty($bank_account) ? '' : $bank_account->label);
$resarray[$array_key.'_bank_number'] = (empty($bank_account) ? '' : $bank_account->number);
$resarray[$array_key.'_bank_proprio'] =(empty($bank_account) ? '' : $bank_account->proprio);
$resarray[$array_key.'_bank_address'] =(empty($bank_account) ? '' : $bank_account->address);
$resarray[$array_key.'_bank_state'] =(empty($bank_account) ? '' : $bank_account->state);
$resarray[$array_key.'_bank_country'] =(empty($bank_account) ? '' : $bank_account->country);
}
if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
@ -808,10 +811,11 @@ abstract class CommonDocGenerator
} else {
// Set unused placeholders as blank
$extrafields->fetch_name_optionals_label("product");
$extralabels = $extrafields->attributes["product"]['label'];
foreach ($extralabels as $key => $label) {
$resarray['line_product_options_'.$key] = '';
if ($extrafields->attributes["product"]['count'] > 0) {
$extralabels = $extrafields->attributes["product"]['label'];
foreach ($extralabels as $key => $label) {
$resarray['line_product_options_'.$key] = '';
}
}
}
@ -946,7 +950,7 @@ abstract class CommonDocGenerator
// phpcs:enable
global $conf;
if (is_array($extrafields->attributes[$object->table_element]['label'])) {
if ($extrafields->attributes[$object->table_element]['count'] > 0) {
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
$formatedarrayoption = $object->array_options;

View file

@ -889,7 +889,7 @@ class FormMail extends Form
//input prompt AI
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
if (isModEnabled('ai') && getDolGlobalConst('AI_CHATGPT_API_KEY')) {
if (isModEnabled('ai') && getDolGlobalString('AI_CHATGPT_API_KEY')) {
$out .= $this->getHtmlForInstruction();
}
// Message

View file

@ -1502,7 +1502,7 @@ class FormTicket
}
print '<tr class="email_line"><td>'.$langs->trans('Subject').'</td>';
if (empty($topic)) {
print '<td><input type="text" class="text minwidth500" name="subject" value="['.getDolGlobalString('MAIN_INFO_SOCIETE_NOM').' - '.$langs->trans("Ticket").' '.$ticketstat->ref.'] '.$langs->trans('TicketNewMessage').'" />';
print '<td><input type="text" class="text minwidth500" name="subject" value="['.getDolGlobalString('MAIN_INFO_SOCIETE_NOM').' - '.$langs->trans("Ticket").' '.$ticketstat->ref.'] '. $ticketstat->subject .'" />';
} else {
print '<td><input type="text" class="text minwidth500" name="subject" value="['.getDolGlobalString('MAIN_INFO_SOCIETE_NOM').' - '.$langs->trans("Ticket").' '.$ticketstat->ref.'] '.$topic.'" />';
}

View file

@ -497,8 +497,8 @@ class Menubase
$this->module = 'specimen';
$this->type = 'top';
$this->mainmenu = '';
$this->fk_menu = '0';
$this->position = '';
$this->fk_menu = 0;
$this->position = 0;
$this->url = 'http://dummy';
$this->target = '';
$this->title = 'Specimen menu';
@ -506,8 +506,8 @@ class Menubase
$this->leftmenu = '';
$this->perms = '';
$this->enabled = '';
$this->user = '';
$this->tms = '';
$this->user = 0;
$this->tms = dol_now();
}

View file

@ -647,7 +647,7 @@ function dol_get_last_hour($date, $gm = 'tzserver')
* @param int $date Date GMT
* @param mixed $gm False or 0 or 'tzserver' = Return date to compare with server TZ,
* 'gmt' to compare with GMT date.
* @return int Date for last hour of a given date
* @return int Date for first hour of a given date
*/
function dol_get_first_hour($date, $gm = 'tzserver')
{

View file

@ -2194,9 +2194,8 @@ function dol_convert_file($fileinput, $ext = 'png', $fileoutput = '', $page = ''
*/
function dol_compress_file($inputfile, $outputfile, $mode = "gz", &$errorstring = null)
{
global $conf;
$foundhandler = 0;
//var_dump(basename($inputfile)); exit;
try {
dol_syslog("dol_compress_file mode=".$mode." inputfile=".$inputfile." outputfile=".$outputfile);
@ -2265,6 +2264,7 @@ function dol_compress_file($inputfile, $outputfile, $mode = "gz", &$errorstring
include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php';
$archive = new PclZip($outputfile);
$result = $archive->add($inputfile, PCLZIP_OPT_REMOVE_PATH, dirname($inputfile));
if ($result === 0) {
@ -2439,7 +2439,7 @@ function dol_uncompress($inputfile, $outputdir)
* @param string $inputdir Source dir name
* @param string $outputfile Target file name (output directory must exists and be writable)
* @param string $mode 'zip'
* @param string $excludefiles A regex pattern. For example: '/\.log$|\/temp\//'
* @param string $excludefiles A regex pattern to exclude files. For example: '/\.log$|\/temp\//'
* @param string $rootdirinzip Add a root dir level in zip file
* @param string $newmask Mask for new file (0 by default means $conf->global->MAIN_UMASK). Example: '0666'
* @return int Return integer <0 if KO, >0 if OK
@ -2447,8 +2447,6 @@ function dol_uncompress($inputfile, $outputdir)
*/
function dol_compress_dir($inputdir, $outputfile, $mode = "zip", $excludefiles = '', $rootdirinzip = '', $newmask = 0)
{
global $conf;
$foundhandler = 0;
dol_syslog("Try to zip dir ".$inputdir." into ".$outputfile." mode=".$mode);

View file

@ -966,6 +966,7 @@ function GETPOSTINT($paramname, $method = 0)
* @param string $paramname Name of the $_GET or $_POST parameter
* @param string|int $rounding Type of rounding ('', 'MU', 'MT, 'MS', 'CU', 'CT', integer) {@see price2num()}
* @return float Value converted into float
* @since Dolibarr V20
*/
function GETPOSTFLOAT($paramname, $rounding = '')
{
@ -8174,6 +8175,10 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null,
'__MYCOMPANY_PROFID4__' => $mysoc->idprof4,
'__MYCOMPANY_PROFID5__' => $mysoc->idprof5,
'__MYCOMPANY_PROFID6__' => $mysoc->idprof6,
'__MYCOMPANY_PROFID7__' => $mysoc->idprof7,
'__MYCOMPANY_PROFID8__' => $mysoc->idprof8,
'__MYCOMPANY_PROFID9__' => $mysoc->idprof9,
'__MYCOMPANY_PROFID10__' => $mysoc->idprof10,
'__MYCOMPANY_CAPITAL__' => $mysoc->capital,
'__MYCOMPANY_FULLADDRESS__' => (method_exists($mysoc, 'getFullAddress') ? $mysoc->getFullAddress(1, ', ') : ''), // $mysoc may be stdClass
'__MYCOMPANY_ADDRESS__' => $mysoc->address,
@ -8216,6 +8221,10 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null,
$substitutionarray['__THIRDPARTY_IDPROF4__'] = '__THIRDPARTY_IDPROF4__';
$substitutionarray['__THIRDPARTY_IDPROF5__'] = '__THIRDPARTY_IDPROF5__';
$substitutionarray['__THIRDPARTY_IDPROF6__'] = '__THIRDPARTY_IDPROF6__';
$substitutionarray['__MYCOMPANY_PROFID7__'] = '__MYCOMPANY_PROFID7__';
$substitutionarray['__MYCOMPANY_PROFID8__'] = '__MYCOMPANY_PROFID8__';
$substitutionarray['__MYCOMPANY_PROFID9__'] = '__MYCOMPANY_PROFID9__';
$substitutionarray['__MYCOMPANY_PROFID10__'] = '__MYCOMPANY_PROFID10__';
$substitutionarray['__THIRDPARTY_TVAINTRA__'] = '__THIRDPARTY_TVAINTRA__';
$substitutionarray['__THIRDPARTY_NOTE_PUBLIC__'] = '__THIRDPARTY_NOTE_PUBLIC__';
$substitutionarray['__THIRDPARTY_NOTE_PRIVATE__'] = '__THIRDPARTY_NOTE_PRIVATE__';

View file

@ -155,7 +155,7 @@ function isValidTinForBE($str)
$str = trim($str);
$str = preg_replace('/(\s)/', '', $str);
if (preg_match('/(^[0-9]{4}\.[0-9]{3}\.[0-9]{3}$)/', $str)) {
if (preg_match('/(^[0-1]{1}[0-9]{3}\.[0-9]{3}\.[0-9]{3}$)/', $str)) {
return true;
} else {
return false;
@ -165,12 +165,12 @@ function isValidTinForBE($str)
/**
* Check the syntax validity of a Spanish (ES) Tax Identification Number (TIN), where:
* - NIF = Número de Identificación Fiscal
* - CIF = Código de Identificación Fiscal
* - NIF = Número de Identificación Fiscal (used for residents only before 2008. Used for both residents and companies since 2008.)
* - CIF = Código de Identificación Fiscal (used for companies only before 2008. Replaced by NIF since 2008.)
* - NIE = Número de Identidad de Extranjero
*
* @param string $str TIN to check
* @return int 1 if NIF ok, 2 if CIF ok, 3 if NIE ok, -1 if NIF bad, -2 if CIF bad, -3 if NIE bad, 0 if unexpected bad
* @return int 1 if NIF ok, 2 if CIF ok, 3 if NIE ok, -1 if NIF bad, -2 if CIF bad, -3 if NIE bad, -4 if unexpected bad
* @since Dolibarr V20
*/
function isValidTinForES($str)

View file

@ -1548,6 +1548,7 @@ function get_left_menu_billing($mainmenu, &$newmenu, $usemenuhider = 1, $leftmen
if ($usemenuhider || empty($leftmenu) || $leftmenu == "donations") {
$newmenu->add("/don/card.php?leftmenu=donations&amp;action=create", $langs->trans("NewDonation"), 1, $user->hasRight('don', 'creer'));
$newmenu->add("/don/list.php?leftmenu=donations", $langs->trans("List"), 1, $user->hasRight('don', 'lire'));
$newmenu->add("/don/paiement/list.php?leftmenu=donations", $langs->trans("Payments"), 1, $user->hasRight('don', 'lire'));
}
// if ($leftmenu=="donations") $newmenu->add("/don/stats/index.php",$langs->trans("Statistics"), 1, $user->hasRight('don', 'lire'));
}

View file

@ -1111,7 +1111,7 @@ class pdf_crabe extends ModelePDFFactures
protected function _tableau_info(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
{
// phpcs:enable
global $conf, $mysoc;
global $conf, $mysoc, $hookmanager;
$default_font_size = pdf_getPDFFontSize($outputlangs);
@ -1238,6 +1238,14 @@ class pdf_crabe extends ModelePDFFactures
if (isModEnabled('paybox')) {
$useonlinepayment++;
}
$parameters = array();
$action = '';
$reshook = $hookmanager->executeHooks('doShowOnlinePaymentUrl', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) {
if (isset($hookmanager->resArray['showonlinepaymenturl'])) {
$useonlinepayment += $hookmanager->resArray['showonlinepaymenturl'];
}
}
}
if ($object->statut != Facture::STATUS_DRAFT && $useonlinepayment) {

View file

@ -1204,7 +1204,7 @@ class pdf_sponge extends ModelePDFFactures
*/
protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
{
global $conf, $mysoc;
global $conf, $mysoc, $hookmanager;
$default_font_size = pdf_getPDFFontSize($outputlangs);
@ -1333,6 +1333,14 @@ class pdf_sponge extends ModelePDFFactures
if (isModEnabled('paybox')) {
$useonlinepayment++;
}
$parameters = array();
$action = '';
$reshook = $hookmanager->executeHooks('doShowOnlinePaymentUrl', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) {
if (isset($hookmanager->resArray['showonlinepaymenturl'])) {
$useonlinepayment += $hookmanager->resArray['showonlinepaymenturl'];
}
}
}

View file

@ -280,6 +280,7 @@ class modWebPortal extends DolibarrModules
$this->menu = array();
$r = 0;
// Add here entries to declare new menus
/*
$this->menu[$r++] = array(
'fk_menu' => '', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'type' => 'top', // This is a Top menu entry
@ -295,6 +296,7 @@ class modWebPortal extends DolibarrModules
'target' => '',
'user' => 2, // 0=Menu for internal users, 1=external users, 2=both
);
*/
/*$this->menu[$r++]=array(
'fk_menu'=>'fk_mainmenu=webportal', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'type'=>'left', // This is a Left menu entry

View file

@ -482,7 +482,7 @@ if (($action == "create") || ($action == "edit")) {
} else {
$input .= ' />';
}
$input .= "<label for=\"frequency_month\">".$langs->trans('Monthly')."</label>";
$input .= "<label for=\"frequency_month\">".$langs->trans('Months')."</label>";
print $input;
print "</td>";

View file

@ -184,6 +184,11 @@ class Cronjob extends CommonObject
*/
public $autodelete;
/**
* @var array Cronjob
*/
public $lines;
const STATUS_DISABLED = 0;
const STATUS_ENABLED = 1;
@ -512,7 +517,6 @@ class Cronjob extends CommonObject
/**
* Load list of cron jobs in a memory array from the database
* @TODO Use object CronJob and not CronJobLine.
*
* @param string $sortorder sort order
* @param string $sortfield sort field

View file

@ -115,9 +115,9 @@ class ActionsDatapolicy extends CommonHookActions
$object->fax = '';
$object->state = '';
$object->country = '';
$object->state_id = '';
$object->state_id = 0;
$object->socialnetworks = '';
$object->country_id = '';
$object->country_id = 0;
$object->note_private = dol_concatdesc($object->note_private, $langs->trans('ANONYMISER_AT', dol_print_date(dol_now())));
if ($object->update($object->id, $user, 0)) {

View file

@ -102,7 +102,7 @@ if ($action == 'add') {
$object->note = GETPOST("note", 'restricthtml');
$object->note_private = GETPOST("note", 'restricthtml');
$object->commande_id = GETPOST("commande_id", 'int');
$object->fk_incoterms = GETPOST('incoterm_id', 'int');
$object->fk_incoterms = GETPOSTINT('incoterm_id');
/* ->entrepot_id seems to not exists
if (!getDolGlobalInt('MAIN_SUBMODULE_EXPEDITION') && isModEnabled('stock')) {

View file

@ -185,19 +185,19 @@ if (empty($reshook)) {
if (!$error) {
$object->fetch($id);
$object->firstname = (string) GETPOST("firstname", 'alpha');
$object->lastname = (string) GETPOST("lastname", 'alpha');
$object->societe = (string) GETPOST("societe", 'alpha');
$object->address = (string) GETPOST("address", 'alpha');
$object->amount = price2num(GETPOST("amount", 'alpha'), '', 2);
$object->town = (string) GETPOST("town", 'alpha');
$object->zip = (string) GETPOST("zipcode", 'alpha');
$object->country_id = (int) GETPOST('country_id', 'int');
$object->email = (string) GETPOST("email", 'alpha');
$object->firstname = GETPOST("firstname", 'alpha');
$object->lastname = GETPOST("lastname", 'alpha');
$object->societe = GETPOST("societe", 'alpha');
$object->address = GETPOST("address", 'alpha');
$object->amount = GETPOSTFLOAT("amount");
$object->town = GETPOST("town", 'alpha');
$object->zip = GETPOST("zipcode", 'alpha');
$object->country_id = GETPOSTINT('country_id');
$object->email = GETPOST("email", 'alpha');
$object->date = $donation_date;
$object->public = $public_donation;
$object->fk_project = (int) GETPOST("fk_project", 'int');
$object->modepaymentid = (int) GETPOST('modepayment', 'int');
$object->fk_project = GETPOSTINT("fk_project");
$object->modepaymentid = GETPOSTINT('modepayment');
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
@ -974,6 +974,14 @@ if (!empty($id) && $action != 'edit') {
// Show online payment link
$useonlinepayment = (isModEnabled('paypal') || isModEnabled('stripe') || isModEnabled('paybox'));
$parameters = array();
$reshook = $hookmanager->executeHooks('doShowOnlinePaymentUrl', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) {
if (isset($hookmanager->resArray['showonlinepaymenturl'])) {
$useonlinepayment += $hookmanager->resArray['showonlinepaymenturl'];
}
}
if ($useonlinepayment) { //$object->statut != Facture::STATUS_DRAFT &&
print '<br><!-- Link to pay -->'."\n";
require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';

View file

@ -0,0 +1,656 @@
<?php
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.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 <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/don/list.php
* \ingroup donations
* \brief List of donations
*/
// Load Dolibarr environment
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
// Load translation files required by the page
$langs->loadLangs(array('companies', 'donations'));
$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'create'/'add', 'edit'/'update', 'view', ...
$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'sclist';
$paiementid = GETPOST('paiementid', 'int');
$search_ref = GETPOST("search_ref", "alpha");
$search_date_startday = GETPOST('search_date_startday', 'int');
$search_date_startmonth = GETPOST('search_date_startmonth', 'int');
$search_date_startyear = GETPOST('search_date_startyear', 'int');
$search_date_endday = GETPOST('search_date_endday', 'int');
$search_date_endmonth = GETPOST('search_date_endmonth', 'int');
$search_date_endyear = GETPOST('search_date_endyear', 'int');
$search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear);
$search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
$search_company = GETPOST("search_company", 'alpha');
$search_paymenttype = GETPOST("search_paymenttype");
$search_account = GETPOST("search_account", "int");
$search_payment_num = GETPOST('search_payment_num', 'alpha');
$search_amount = GETPOST("search_amount", 'alpha');
$search_status = GETPOST('search_status', 'intcomma');
$search_sale = GETPOST('search_sale', 'int');
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
$type = GETPOST('type', 'aZ');
$mode = GETPOST('mode', 'alpha');
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "pd.rowid";
}
$search_all = trim(GETPOSTISSET("search_all") ? GETPOST("search_all", 'alpha') : GETPOST('sall'));
// List of fields to search into when doing a "search in all"
$fieldstosearchall = array(
'pd.rowid'=>"RefPayment",
's.nom'=>"ThirdParty",
'pd.num_paiement'=>"Numero",
'pd.amount'=>"Amount",
);
$arrayfields = array(
'pd.rowid' => array('label'=>"RefPayment", 'checked'=>1, 'position'=>10),
'pd.datep' => array('label'=>"Date", 'checked'=>1, 'position'=>20),
's.nom' => array('label'=>"ThirdParty", 'checked'=>1, 'position'=>30),
'c.code' => array('label'=>"Type", 'checked'=>1, 'position'=>40),
'pd.num_paiement' => array('label'=>"Numero", 'checked'=>1, 'position'=>50, 'tooltip'=>"ChequeOrTransferNumber"),
'transaction' => array('label'=>"BankTransactionLine", 'checked'=>1, 'position'=>60, 'enabled'=>(isModEnabled("banque"))),
'ba.label' => array('label'=>"Account", 'checked'=>1, 'position'=>70, 'enabled'=>(isModEnabled("banque"))),
'pd.amount' => array('label'=>"Amount", 'checked'=>1, 'position'=>80),
);
$arrayfields = dol_sort_array($arrayfields, 'position');
$optioncss = GETPOST('optioncss', 'alpha');
$moreforfilter = GETPOST('moreforfilter', 'alpha');
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('donationlist'));
// Security check
$result = restrictedArea($user, 'don');
$permissiontoread = $user->hasRight('don', 'read');
$permissiontoadd = $user->hasRight('don', 'write');
$permissiontodelete = $user->hasRight('don', 'delete');
/*
* Actions
*/
$parameters = array('socid'=>$paiementid);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook)) {
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
// All tests are required to be compatible with all browsers
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
$search_ref = '';
$search_date_startday = '';
$search_date_startmonth = '';
$search_date_startyear = '';
$search_date_endday = '';
$search_date_endmonth = '';
$search_date_endyear = '';
$search_date_start = '';
$search_date_end = '';
$search_account = '';
$search_amount = '';
$search_paymenttype = '';
$search_payment_num = '';
$search_company = '';
$option = '';
$toselect = array();
$search_array_options = array();
}
}
/*
* View
*/
$form = new Form($db);
$donationstatic = new Don($db);
$companystatic = new Societe($db);
$bankline = new AccountLine($db);
$accountstatic = new Account($db);
$title = $langs->trans("Donations");
$help_url = 'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones|DE:Modul_Spenden';
// Build and execute select
// --------------------------------------------------------------------
$sql = "SELECT pd.rowid as payment_id, pd.amount, pd.datep, pd.fk_typepayment, pd.num_payment, pd.amount, pd.fk_bank, ";
$sql .= ' s.rowid as soc_id, s.nom, ';
$sql .= ' d.societe, ';
$sql .= ' c.code as paiement_code, ';
$sql .= ' d.rowid, ba.rowid as bid, ba.ref as bref, ba.label as blabel, ba.number, ba.account_number as account_number, ba.iban_prefix, ba.bic, ba.currency_code, ba.fk_accountancy_journal as accountancy_journal ';
// Add fields from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
$sqlfields = $sql; // $sql fields to remove for count total
$sql .= " FROM ".MAIN_DB_PREFIX."payment_donation as pd";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."don as d ON (d.rowid = pd.fk_donation)";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON (b.rowid = pd.fk_bank)";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON (ba.rowid = b.fk_account)";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON (s.rowid = d.fk_soc)";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON (c.id = pd.fk_typepayment)";
$sql .= " WHERE d.entity IN (".getEntity('donation').")";
if ($search_ref) {
$sql .= natural_search('pd.rowid', $search_ref);
}
if ($search_date_start) {
$sql .= " AND pd.datep >= '" . $db->idate($search_date_start) . "'";
}
if ($search_date_end) {
$sql .= " AND pd.datep <= '" . $db->idate($search_date_end) . "'";
}
if ($search_account > 0) {
$sql .= " AND b.fk_account=".((int) $search_account);
}
if ($search_paymenttype != '') {
$sql .= " AND c.code='".$db->escape($search_paymenttype)."'";
}
if ($search_payment_num != '') {
$sql .= natural_search('pd.num_payment', $search_payment_num);
}
if ($search_amount) {
$sql .= natural_search('pd.amount', $search_amount, 1);
}
if ($search_company) {
$sql .= natural_search('s.nom', $search_company);
}
if ($search_all) {
$sql .= natural_search(array_keys($fieldstosearchall), $search_all);
}
// Add where from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
// Count total nb of records
$nbtotalofrecords = '';
if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
/* The fast and low memory method to get and count full list converts the sql into a sql count */
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
$resql = $db->query($sqlforcount);
if ($resql) {
$objforcount = $db->fetch_object($resql);
$nbtotalofrecords = $objforcount->nbtotalofrecords;
} else {
dol_print_error($db);
}
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
$db->free($resql);
}
$sql .= $db->order($sortfield, $sortorder);
// Complete request and execute it with limit
if ($limit) {
$sql .= $db->plimit($limit + 1, $offset);
}
$resql = $db->query($sql);
if (!$resql) {
dol_print_error($db);
exit;
}
$num = $db->num_rows($resql);
// Output page
// --------------------------------------------------------------------
llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist'); // Can use also classforhorizontalscrolloftabs instead of bodyforlist for no horizontal scroll
$param = '';
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
$param .= '&contextpage='.urlencode($contextpage);
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.((int) $limit);
}
if ($search_ref) {
$param .= '&search_ref='.urlencode($search_ref);
}
if ($search_date_startday) {
$param .= '&search_date_startday='.urlencode($search_date_startday);
}
if ($search_date_startmonth) {
$param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
}
if ($search_date_startyear) {
$param .= '&search_date_startyear='.urlencode($search_date_startyear);
}
if ($search_date_endday) {
$param .= '&search_date_endday='.urlencode($search_date_endday);
}
if ($search_date_endmonth) {
$param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
}
if ($search_date_endyear) {
$param .= '&search_date_endyear='.urlencode($search_date_endyear);
}
if ($search_company) {
$param .= '&search_company='.urlencode($search_company);
}
if ($search_amount != '') {
$param .= '&search_amount='.urlencode($search_amount);
}
if ($search_paymenttype) {
$param .= '&search_paymenttype='.urlencode($search_paymenttype);
}
if ($search_account) {
$param .= '&search_account='.urlencode($search_account);
}
if ($search_payment_num) {
$param .= '&search_payment_num='.urlencode($search_payment_num);
}
if ($optioncss != '') {
$param .= '&optioncss='.urlencode($optioncss);
}
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="list">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
print_barre_liste($langs->trans("DonationsReglement"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'bill', 0, '', '', $limit, 0, 0, 1);
if ($search_all) {
foreach ($fieldstosearchall as $key => $val) {
$fieldstosearchall[$key] = $langs->trans($val);
}
print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
}
$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
$massactionbutton = '';
if ($massactionbutton) {
$selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
}
$moreforfilter = '';
print '<div class="div-table-responsive">';
print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : '').'">';
// Fields title search
// --------------------------------------------------------------------
print '<tr class="liste_titre_filter">';
// Action column
if (getDolGlobalInt('MAIN_CHECKBOX_LEFT_COLUMN')) {
print '<td class="liste_titre center maxwidthsearch">';
$searchpicto = $form->showFilterButtons('left');
print $searchpicto;
print '</td>';
}
if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER_IN_LIST')) {
print '<td class="liste_titre">';
print '</td>';
}
if (!empty($arrayfields['pd.rowid']['checked'])) {
print '<td class="liste_titre left">';
print '<input class="flat" type="text" size="4" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
print '</td>';
}
// Filter: Date
if (!empty($arrayfields['pd.datep']['checked'])) {
print '<td class="liste_titre">';
print '<div class="nowrapfordate">';
print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
print '</div>';
print '<div class="nowrapfordate">';
print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
print '</div>';
print '</td>';
}
// Filter: Thirdparty
if (!empty($arrayfields['s.nom']['checked'])) {
print '<td class="liste_titre">';
print '<input class="flat" type="text" size="6" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
print '</td>';
}
// Filter: Payment type
if (!empty($arrayfields['c.code']['checked'])) {
print '<td class="liste_titre">';
print $form->select_types_paiements($search_paymenttype, 'search_paymenttype', '', 2, 1, 1, 0, 1, 'maxwidth100', 1);
print '</td>';
}
// Filter: Bank transaction number
if (!empty($arrayfields['transaction']['checked'])) {
print '<td class="liste_titre">';
print '<input class="flat" type="text" size="4" name="search_payment_num" value="'.dol_escape_htmltag($search_payment_num).'">';
print '</td>';
}
// Filter: Cheque number (fund transfer)
if (!empty($arrayfields['pd.num_paiement']['checked'])) {
print '<td class="liste_titre">';
print '</td>';
}
// Filter: Bank account
if (!empty($arrayfields['ba.label']['checked'])) {
print '<td class="liste_titre">';
$form->select_comptes($search_account, 'search_account', 0, '', 1);
print '</td>';
}
// Filter: Amount
if (!empty($arrayfields['pd.amount']['checked'])) {
print '<td class="liste_titre">';
print '<input class="flat" type="text" size="6" name="search_amount" value="'.dol_escape_htmltag($search_amount).'">';
print '</td>';
}
// Fields from hook
$parameters = array('arrayfields'=>$arrayfields);
$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
// Action column
if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
print '<td class="liste_titre center maxwidthsearch">';
$searchpicto = $form->showFilterButtons();
print $searchpicto;
print '</td>';
}
print '</tr>'."\n";
$totalarray = array();
$totalarray['nbfield'] = 0;
// Fields title label
// --------------------------------------------------------------------
print '<tr class="liste_titre">';
// Action column
if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
$totalarray['nbfield']++;
}
if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER_IN_LIST')) {
print_liste_field_titre('#', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
$totalarray['nbfield']++;
}
if (!empty($arrayfields['pd.rowid']['checked'])) {
print_liste_field_titre($arrayfields['pd.rowid']['label'], $_SERVER["PHP_SELF"], "pd.rowid", '', $param, '', $sortfield, $sortorder);
$totalarray['nbfield']++;
}
if (!empty($arrayfields['pd.datep']['checked'])) {
print_liste_field_titre($arrayfields['pd.datep']['label'], $_SERVER["PHP_SELF"], "pd.datep", '', $param, '', $sortfield, $sortorder);
$totalarray['nbfield']++;
}
if (!empty($arrayfields['s.nom']['checked'])) {
print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder);
$totalarray['nbfield']++;
}
if (!empty($arrayfields['c.code']['checked'])) {
print_liste_field_titre($arrayfields['c.code']['label'], $_SERVER["PHP_SELF"], "c.code", '', $param, '', $sortfield, $sortorder);
$totalarray['nbfield']++;
}
if (!empty($arrayfields['pd.num_paiement']['checked'])) {
print_liste_field_titre($arrayfields['pd.num_paiement']['label'], $_SERVER["PHP_SELF"], "pd.num_payment", '', $param, '', $sortfield, $sortorder, '', $arrayfields['p.num_paiement']['tooltip']);
$totalarray['nbfield']++;
}
if (!empty($arrayfields['transaction']['checked'])) {
print_liste_field_titre($arrayfields['transaction']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
$totalarray['nbfield']++;
}
if (!empty($arrayfields['ba.label']['checked'])) {
print_liste_field_titre($arrayfields['ba.label']['label'], $_SERVER["PHP_SELF"], "ba.label", '', $param, '', $sortfield, $sortorder);
$totalarray['nbfield']++;
}
if (!empty($arrayfields['pd.amount']['checked'])) {
print_liste_field_titre($arrayfields['pd.amount']['label'], $_SERVER["PHP_SELF"], "pd.amount", '', $param, '', $sortfield, $sortorder);
$totalarray['nbfield']++;
}
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
// Hook fields
$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;
// Action column
if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
$totalarray['nbfield']++;
}
print '</tr>'."\n";
// Detect if we need a fetch on each output line
$needToFetchEachLine = 0;
if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
if (!is_null($val) && preg_match('/\$object/', $val)) {
$needToFetchEachLine++; // There is at least one compute field that use $object
}
}
}
// Loop on record
// --------------------------------------------------------------------
$i = 0;
$savnbfield = $totalarray['nbfield'];
$totalarray = array();
$totalarray['nbfield'] = 0;
$imaxinloop = ($limit ? min($num, $limit) : $num);
while ($i < $imaxinloop) {
$obj = $db->fetch_object($resql);
$companystatic->id = $obj->soc_id;
$companystatic->name = $obj->nom;
$company = new Societe($db);
$result = $company->fetch($obj->socid);
print '<tr class="oddeven">';
if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
print '<td class="nowrap center">';
if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
$selected = 0;
if (in_array($obj->id_paiement, $arrayofselected)) {
$selected = 1;
}
print '<input id="cb'.$obj->id_paiement.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id_paiement.'"'.($selected ? ' checked="checked"' : '').'>';
}
print '</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
// Ref
if (!empty($arrayfields['pd.rowid']['checked'])) {
print '<td><a href="' . DOL_URL_ROOT . '/don/payment/card.php?id=' . $obj->payment_id . '">' . img_object($langs->trans("Payment"), "payment") . ' ' . $obj->payment_id . '</a></td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
// Date
if (!empty($arrayfields['pd.datep']['checked'])) {
$dateformatforpayment = 'dayhour';
print '<td class="nowraponall">'.dol_print_date($db->jdate($obj->datep), $dateformatforpayment, 'tzuser').'</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
// Thirdparty
if (!empty($arrayfields['s.nom']['checked'])) {
print '<td class="nowraponall">';
if ($obj->soc_id > 0) {
print $companystatic->getNomUrl(1, '', 24);
} else {
print $donationstatic->societe = $obj->societe;
}
print '</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
// Payment type
if (!empty($arrayfields['c.code']['checked'])) {
print '<td>'.$langs->trans("PaymentTypeShort".$obj->paiement_code).'</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
// Filter: Cheque number (fund transfer)
if (!empty($arrayfields['pd.num_paiement']['checked'])) {
print '<td>'.$obj->num_payment.'</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
// Bank transaction
if (!empty($arrayfields['transaction']['checked'])) {
print '<td class="tdoverflowmax125">';
if ($obj->fk_bank > 0) {
$test = $bankline->fetch($obj->fk_bank);
print $bankline->getNomUrl(1, 0);
}
print '</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
// Bank account
if (!empty($arrayfields['ba.label']['checked'])) {
print '<td>';
if ($obj->bid > 0) {
$accountstatic->id = $obj->bid;
$accountstatic->ref = $obj->bref;
$accountstatic->label = $obj->blabel;
$accountstatic->number = $obj->number;
$accountstatic->account_number = $obj->account_number;
$accountingjournal = new AccountingJournal($db);
$accountingjournal->fetch($obj->accountancy_journal);
$accountstatic->accountancy_journal = $accountingjournal->code;
print $accountstatic->getNomUrl(1);
}
if (!$i) {
$totalarray['nbfield']++;
}
}
// Amount
if (!empty($arrayfields['pd.amount']['checked'])) {
print '<td ><span class="amount">' . price($obj->amount) . '</span></td>';
if (!$i) {
$totalarray['nbfield']++;
$totalarray['pos'][$totalarray['nbfield']] = 'amount';
}
if (empty($totalarray['val']['amount'])) {
$totalarray['val']['amount'] = $obj->amount;
} else {
$totalarray['val']['amount'] += $obj->amount;
}
}
$i++;
}
// Show total line
include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
// If no record found
if ($num == 0) {
$colspan = 1;
foreach ($arrayfields as $key => $val) {
if (!empty($val['checked'])) {
$colspan++;
}
}
print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
}
$db->free($resql);
$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
print '</table>'."\n";
print '</div>'."\n";
print '</form>'."\n";
llxFooter();
$db->close();

View file

@ -1104,11 +1104,11 @@ class CommandeFournisseur extends CommonOrder
/**
* Returns the following order reference not used depending on the numbering model activated
* defined within COMMANDE_SUPPLIER_ADDON_NUMBER
* Returns the next order reference not used, based on the
* numbering model defined within COMMANDE_SUPPLIER_ADDON_NUMBER
*
* @param Societe $soc company object
* @return string free reference for the invoice
* @return string|int free reference for the invoice. '', -1 or -2 if error.
*/
public function getNextNumRef($soc)
{
@ -1864,13 +1864,13 @@ class CommandeFournisseur extends CommonOrder
// Clear fields
$this->user_author_id = $user->id;
$this->user_validation_id = 0;
$this->date_creation = '';
$this->date_validation = '';
$this->ref_supplier = null;
$this->user_approve_id = '';
$this->user_approve_id2 = '';
$this->date_approve = '';
$this->date_approve2 = '';
$this->date_creation = 0;
$this->date_validation = 0;
$this->ref_supplier = '';
$this->user_approve_id = 0;
$this->user_approve_id2 = 0;
$this->date_approve = 0;
$this->date_approve2 = 0;
// Create clone
$this->context['createfromclone'] = 'createfromclone';
@ -2923,7 +2923,7 @@ class CommandeFournisseur extends CommonOrder
$remise_percent = 0;
}
$remise_percent = price2num($remise_percent);
$remise_percent = (float) price2num($remise_percent);
$qty = price2num($qty);
if (!$qty) {
$qty = 1;

View file

@ -12,7 +12,7 @@
* Copyright (C) 2017 Josep Lluís Amador <joseplluis@lliuretic.cat>
* Copyright (C) 2018-2022 Charlene Benke <charlene@patas-monkey.com>
* Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2019-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2019-2023 Alexandre Spangaro <aspangaro@easya.solutions>
* Copyright (C) 2023 Nick Fragoulis
*
* This program is free software; you can redistribute it and/or modify
@ -88,7 +88,7 @@ $search_paymentcond = GETPOST('search_paymentcond', 'int');
$search_town = GETPOST('search_town', 'alpha');
$search_zip = GETPOST('search_zip', 'alpha');
$search_state = GETPOST("search_state");
$search_country = GETPOST("search_country", 'int');
$search_country = GETPOST("search_country", 'alpha');
$search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
$search_user = GETPOST('search_user', 'int');
$search_sale = GETPOST('search_sale', 'int');
@ -530,8 +530,26 @@ if ($search_zip) {
if ($search_state) {
$sql .= natural_search("state.nom", $search_state);
}
if ($search_country) {
$sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
if (strlen(trim($search_country))) {
$arrayofcode = getCountriesInEEC();
$country_code_in_EEC = $country_code_in_EEC_without_me = '';
foreach ($arrayofcode as $key => $value) {
$country_code_in_EEC .= ($country_code_in_EEC ? "," : "")."'".$value."'";
if ($value != $mysoc->country_code) {
$country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ? "," : "")."'".$value."'";
}
}
if ($search_country == 'special_allnotme') {
$sql .= " AND country.code <> '".$db->escape($mysoc->country_code)."'";
} elseif ($search_country == 'special_eec') {
$sql .= " AND country.code IN (".$db->sanitize($country_code_in_EEC, 1).")";
} elseif ($search_country == 'special_eecnotme') {
$sql .= " AND country.code IN (".$db->sanitize($country_code_in_EEC_without_me, 1).")";
} elseif ($search_country == 'special_noteec') {
$sql .= " AND country.code NOT IN (".$db->sanitize($country_code_in_EEC, 1).")";
} else {
$sql .= natural_search("country.code", $search_country);
}
}
if ($search_type_thirdparty != '' && $search_type_thirdparty >= 0) {
$sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')';
@ -1138,7 +1156,7 @@ if (!empty($arrayfields['state.nom']['checked'])) {
// Country
if (!empty($arrayfields['country.code_iso']['checked'])) {
print '<td class="liste_titre center">';
print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
print $form->select_country($search_country, 'search_country', '', 0, 'minwidth150imp maxwidth150', 'code2', 1, 0, 1, null, 1);
print '</td>';
}
// Company type

View file

@ -173,7 +173,7 @@ if (empty($reshook)) {
$date_fin_gmt = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'), 1);
$starthalfday = GETPOST('starthalfday');
$endhalfday = GETPOST('endhalfday');
$type = GETPOST('type');
$type = GETPOSTINT('type');
$halfday = 0;
if ($starthalfday == 'afternoon' && $endhalfday == 'morning') {

View file

@ -166,7 +166,8 @@ if (empty($reshook)) {
$object->fetch($id);
$skillRequire = $object->getSkillRankForJob($originalId);
if ($object->id > 0) {
$object->id = $object->ref = null;
$object->id = 0;
$object->ref = '';
if (GETPOST('clone_label', 'alphanohtml')) {
$object->label = GETPOST('clone_label', 'alphanohtml');

View file

@ -208,3 +208,6 @@ ALTER TABLE llx_categorie ADD COLUMN position integer DEFAULT 0 AFTER color;
ALTER TABLE llx_product DROP COLUMN onportal;
ALTER TABLE llx_knowledgemanagement_knowledgerecord MODIFY COLUMN answer longtext;
-- Rename const to add customer categories on not customer/prospect third-party if enabled
UPDATE llx_const SET name = 'THIRDPARTY_CAN_HAVE_CUSTOMER_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT' WHERE name = 'THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER';

View file

@ -2437,3 +2437,5 @@ ParametersForTestEnvironment=Parameters for test environment
TryToKeepOnly=Try to keep only %s
RecommendedForProduction=Recommended for Production
RecommendedForDebug=Recommended for Debug
UrlPublicInterfaceLabelAdmin=Alternative URL for public interface
UrlPublicInterfaceHelpAdmin=It is possible to define an alias to the web server and thus make available the public interface with another URL (the virtual host server must act as a proxy on the standard URL)

View file

@ -107,8 +107,6 @@ TicketsShowProgressionHelp=Enable this option to hide the progress of the ticket
TicketCreateThirdPartyWithContactIfNotExist=Ask name and company name for unknown emails.
TicketCreateThirdPartyWithContactIfNotExistHelp=Check if a third party or a contact exists for the email entered. If not, ask a name and a company name to create a third party with contact.
PublicInterface=Public interface
TicketUrlPublicInterfaceLabelAdmin=Alternative URL for public interface
TicketUrlPublicInterfaceHelpAdmin=It is possible to define an alias to the web server and thus make available the public interface with another URL (the server must act as a proxy on this new URL)
TicketPublicInterfaceTextHomeLabelAdmin=Welcome text of the public interface
TicketPublicInterfaceTextHome=You can create a support ticket or view existing from its identifier tracking ticket.
TicketPublicInterfaceTextHomeHelpAdmin=The text defined here will appear on the home page of the public interface.

View file

@ -174,8 +174,6 @@ WebPortalSetup = WebPortal setup
WebPortalCSS=Web portal CSS
Settings = Settings
WebPortalSetupPage = WebPortal setup page
WEBPORTAL_ROOT_URL = Alternative virtual host URL
WebPortalRootUrlHelp = Public access url (http or https) if you have a virtual host or keep empty
WEBPORTAL_TITLE = Brand name on header of public page
UserAccountForWebPortalAreInThirdPartyTabHelp = Users accounts for WebPortal can be set on each third party card in Website accounts tab
WebPortalAccessHidden = Hidden
@ -234,3 +232,4 @@ WebPortalErrorFetchLoggedUser = Error when loading user (Id : %s)
WebPortalErrorFetchLoggedThirdParty = Error when loading third-party (Id : %s)
WebPortalErrorFetchLoggedMember = Error when loading member (Id : %s)
WebPortalErrorFetchLoggedPartnership = Error when loading partnership (Third-party Id : %s, Member Id : %s)
ExportIntoGIT=Export into sources

View file

@ -2440,3 +2440,4 @@ ParametersForTestEnvironment=Paramètres pour l'environnement de test
TryToKeepOnly=Essayez de ne conserver que %s
RecommendedForProduction=Recommandé pour la production
RecommendedForDebug=Recommandé pour le débogage
UrlPublicInterfaceHelpAdmin=Il est possible de définir un alias vers le serveur et de rendre ainsi l'interface publique accessible avec une autre URL (le serveur doit agir comme un proxy sur cette nouvelle URL)

View file

@ -32,5 +32,9 @@ DONATION_ART238=Afficher article 238 du CGI si vous êtes concernés
DONATION_ART978=Afficher article 978 du CGI si vous êtes concernés
DonationPayment=Paiement du don
DonationValidated=Don %s validé
DonationsReglement= Règlements reçus pour les dons
DonationUseThirdparties=Utiliser un tiers existant comme coordonnées du donateur
DonationsStatistics=Statistiques des dons

View file

@ -108,7 +108,6 @@ TicketCreateThirdPartyWithContactIfNotExist=Demandez le nom et le nom de l'entre
TicketCreateThirdPartyWithContactIfNotExistHelp=Vérifiez s'il existe un tiers ou un contact pour l'e-mail saisi. Sinon, demandez un nom et un nom société pour créer un tiers avec contact.
PublicInterface=Interface publique
TicketUrlPublicInterfaceLabelAdmin=URL alternative pour l'interface publique
TicketUrlPublicInterfaceHelpAdmin=Il est possible de définir un alias vers le serveur et de rendre ainsi l'interface publique accessible avec une autre URL (le serveur doit agir comme un proxy sur cette nouvelle URL)
TicketPublicInterfaceTextHomeLabelAdmin=Texte de bienvenue dans l'interface publique
TicketPublicInterfaceTextHome=Vous pouvez créer un ticket ou consulter à partir d'un ID de ticket existant.
TicketPublicInterfaceTextHomeHelpAdmin=Le texte défini ici apparaîtra sur la page d'accueil de l'interface publique.

View file

@ -2358,7 +2358,7 @@ class Product extends CommonObject
$price_min_ttc = 0;
}
} else {
$price = price2num($newprice, 'MU');
$price = (float) price2num($newprice, 'MU');
$price_ttc = ($newnpr != 1) ? (float) price2num($newprice) * (1 + ($newvat / 100)) : $price;
$price_ttc = price2num($price_ttc, 'MU');
@ -2905,8 +2905,8 @@ class Product extends CommonObject
if ($price_result >= 0) {
$this->price = $price_result;
// Calculate the VAT
$this->price_ttc = price2num($this->price) * (1 + ($this->tva_tx / 100));
$this->price_ttc = price2num($this->price_ttc, 'MU');
$this->price_ttc = (float) price2num($this->price) * (1 + ($this->tva_tx / 100));
$this->price_ttc = (float) price2num($this->price_ttc, 'MU');
}
}
@ -5062,7 +5062,7 @@ class Product extends CommonObject
/**
* Return if loaded product is a variant
*
* @return int
* @return bool|int Return true if the product is a variant, false if not, -1 if error
*/
public function isVariant()
{
@ -5587,7 +5587,7 @@ class Product extends CommonObject
/**
* Retour label of nature of product
*
* @return string Label
* @return string|int Return label or ''. -1 if error
*/
public function getLibFinished()
{

View file

@ -469,6 +469,30 @@ class Societe extends CommonObject
*/
public $idprof6;
/**
* Professional ID 7
* @var string
*/
public $idprof7;
/**
* Professional ID 8
* @var string
*/
public $idprof8;
/**
* Professional ID 9
* @var string
*/
public $idprof9;
/**
* Professional ID 10
* @var string
*/
public $idprof10;
/**
* Social object of the company
* @var string

View file

@ -2659,7 +2659,7 @@ class Ticket extends CommonObject
if (!empty($sendto)) {
$appli = getDolGlobalString('MAIN_APPLICATION_TITLE', $mysoc->name);
$subject = '['.$appli.'- ticket #'.$object->track_id.'] '.$langs->trans('TicketNewMessage');
$subject = '['.$appli.'- ticket #'.$object->track_id.'] '.$this->subject;
// Message send
$message = $langs->trans('TicketMessageMailIntroText');

View file

@ -3,7 +3,7 @@ Module Web Portal
This is a module to provide a ready to use Web Portal for your customers, suppliers, partners or members of the mebership module.
Accounts (login and pass) to acces this portal can be created for any thirdparty (from the tab "Web site accounts").
Accounts (login and pass) to access this portal can be created for any thirdparty (from the tab "Web site accounts").
It is better to have a standalone web server with its own virtual host and domain name to use this module, so using the web portal does not
reaveal the domain and url of your backoffice installation.
@ -15,8 +15,8 @@ If the Thirdparty module is enabled:
* Read/modify Name, phone, email, addresses of thirdparty
If the Patnership module is enabled:
* Read properties (status, stard date, end date) of its partnership.
* Read properties (status, start date, end date) of its partnership.
If the Proposal module is enabled:
* Read its orders
@ -42,4 +42,3 @@ Documentation
[Module Web Portal](https://wiki.dolibarr.org/index.php/Module_Web_Portal)

View file

@ -29,7 +29,7 @@ require_once DOL_DOCUMENT_ROOT . "/core/lib/admin.lib.php";
require_once DOL_DOCUMENT_ROOT . "/webportal/lib/webportal.lib.php";
// Translations
$langs->loadLangs(array("admin", "hrm", "other"));
$langs->loadLangs(array("admin", "hrm", "other", "website"));
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('webportalsetup', 'globalsetup'));

View file

@ -57,15 +57,15 @@ $useFormSetup = 1;
if (!class_exists('FormSetup')) {
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formsetup.class.php';
}
$formSetup = new FormSetup($db);
// root url
$item = $formSetup->newItem('WEBPORTAL_ROOT_URL')->setAsString();
$item->nameText = $langs->transnoentities('UrlPublicInterfaceLabelAdmin');
$item->fieldAttr = array('placeholder' => 'https://');
$item->helpText = $langs->transnoentities('WebPortalRootUrlHelp');
$item->helpText = $langs->transnoentities('UrlPublicInterfaceHelpAdmin');
require_once __DIR__ . '/../class/context.class.php';
$context = Context::getInstance();
//$context = Context::getInstance();
//$item->fieldOutputOverride = '<a target="_blank" href="'.Context::getRootConfigUrl().'" >'.img_picto('', 'globe', 'class="pictofixedwidth"').Context::getRootConfigUrl().'</a>';
@ -270,7 +270,7 @@ print ajax_autoselect('publicurlmember');
// Setup page goes here
print info_admin($langs->trans("UserAccountForWebPortalAreInThirdPartyTabHelp"));
print '<br>';
print '<br><br>';
if ($action == 'edit') {
print $formSetup->generateOutput(true);

View file

@ -28,7 +28,7 @@ require_once DOL_DOCUMENT_ROOT . "/core/lib/admin.lib.php";
require_once DOL_DOCUMENT_ROOT . "/webportal/lib/webportal.lib.php";
// Translations
$langs->loadLangs(array("admin", "webportal"));
$langs->loadLangs(array("admin", "webportal", "website"));
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('webportalthemesetup', 'globalsetup'));

View file

@ -140,6 +140,10 @@ class Website extends CommonObject
*/
public $lines;
/**
* @var string name of template
*/
public $name_template;
const STATUS_DRAFT = 0;
const STATUS_VALIDATED = 1;
@ -330,7 +334,8 @@ class Website extends CommonObject
$sql .= " t.fk_user_creat,";
$sql .= " t.fk_user_modif,";
$sql .= " t.date_creation,";
$sql .= " t.tms as date_modification";
$sql .= " t.tms as date_modification,";
$sql .= " t.name_template";
$sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
$sql .= " WHERE t.entity IN (".getEntity('website').")";
if (!empty($ref)) {
@ -361,6 +366,7 @@ class Website extends CommonObject
$this->fk_user_modif = $obj->fk_user_modif;
$this->date_creation = $this->db->jdate($obj->date_creation);
$this->date_modification = $this->db->jdate($obj->date_modification);
$this->name_template = $obj->name_template;
}
$this->db->free($resql);
@ -952,7 +958,6 @@ class Website extends CommonObject
}
$destdir = $conf->website->dir_temp.'/'.$website->ref;
dol_syslog("Clear temp dir ".$destdir);
$count = 0;
$countreallydeleted = 0;
@ -1149,7 +1154,8 @@ class Website extends CommonObject
$filename = $conf->website->dir_temp.'/'.$website->ref.'/website_'.$website->ref.'-'.dol_print_date(dol_now(), 'dayhourlog').'-V'.((float) DOL_VERSION).'.zip';
dol_delete_file($fileglob, 0);
$result = dol_compress_file($filedir, $filename, 'zip');
$result = dol_compress_dir($filedir, $filename, 'zip');
if ($result > 0) {
return $filename;
@ -1174,7 +1180,6 @@ class Website extends CommonObject
$error = 0;
$pathtofile = dol_sanitizePathName($pathtofile);
$object = $this;
if (empty($object->ref)) {
$this->error = 'Function importWebSite called on object not loaded (object->ref is empty)';
@ -1310,7 +1315,7 @@ class Website extends CommonObject
// Regenerate index page to point to the new index page
$pathofwebsite = $conf->website->dir_output.'/'.$object->ref;
dolSaveIndexPage($pathofwebsite, $pathofwebsite.'/index.php', $pathofwebsite.'/page'.$object->fk_default_home.'.tpl.php', $pathofwebsite.'/wrapper.php', $object);
$this->initFilesStatus($pathofwebsite);
if ($error) {
$this->db->rollback();
return -1;
@ -1602,4 +1607,514 @@ class Website extends CommonObject
return $out;
}
/**
* Overite template by copying all files
*
* @return int Return integer <0 if KO, >0 if OK
*/
public function overwriteTemplate()
{
global $conf;
$website = $this;
if (empty($website->id) || empty($website->ref)) {
setEventMessages("Website id or ref is not defined", null, 'errors');
return -1;
}
if (empty($website->name_template)) {
setEventMessages("To export the website template into the GIT sources directory, the name of the directory/template must be know. For this website, the variable 'name_template' is unknown, so export in GIT sources is not possible.", null, 'errors');
return -1;
}
if (!is_writable($conf->website->dir_temp)) {
setEventMessages("Temporary dir ".$conf->website->dir_temp." is not writable", null, 'errors');
return -1;
}
$sourcedir = $conf->website->dir_output."/".$website->ref;
$fichierEtat = $sourcedir . '/filelist-lastwrite-doctemplates.txt';
// Get array with hash of files
$etatPrecedent = $this->checkPreviousState($fichierEtat);
// Get list of all source files of the website
$arraySourcedir = dol_dir_list($sourcedir);
// Get list of modified files
$modifications = [];
foreach ($arraySourcedir as $file) {
if (substr($file['name'], -4) === '.old') {
continue;
}
$hashActuel = hash_file('md5', $file['fullname']);
// Check whether the file is new or has been modified
if (!isset($etatPrecedent[$file['name']]) || $etatPrecedent[$file['name']] !== $hashActuel) {
$modifications[] = $file;
}
$etatPrecedent[$file['name']] = $hashActuel; // we store he new hash to record it later on disk.
}
// Replace modified files into the doctemplates directory.
$destdirrel = 'install/doctemplates/websites/'.$website->name_template;
$destdir = DOL_DOCUMENT_ROOT.'/'.$destdirrel;
$arraydestdir = dol_dir_list($destdir, "all", 1);
$differences = [];
$names = array_column($arraydestdir, 'name');
$namesSource = array_column($arraySourcedir, 'name');
if (count($modifications) > 1) {
foreach ($modifications as $fichierModifie) {
$nomFichierModifie = $fichierModifie['name'];
if ($nomFichierModifie == basename($fichierEtat)) {
continue;
}
$success = 0;
//check if it is a new file
if ((!preg_match('/^page\d+\.tpl\.php$/', $nomFichierModifie)) && (!in_array($nomFichierModifie, $names))) {
if (file_exists($fichierModifie['fullname']) && dol_is_dir($destdir.'/containers')) {
$cp = dol_copy($fichierModifie['fullname'], $destdir.'/containers/'.$nomFichierModifie, '0664');
if ($cp > 0) {
if (file_exists($destdir.'/containers/'.$nomFichierModifie)) {
$tabnumpage = array();
foreach ($arraydestdir as $fileDest) {
if ($this->extractNumberFromFilename($fileDest['name']) !== -1) {
$tabnumpage[] = $this->extractNumberFromFilename($fileDest['name']);
}
}
$getContentSource = file_get_contents($destdir.'/containers/'.$nomFichierModifie);
$nextpage = max($tabnumpage) + 1;
$chaineModifiee = preg_replace('/page\d+\.tpl\.php/', 'page' . $nextpage . '.tpl.php', $getContentSource);
$write = file_put_contents($destdir.'/containers/'.$nomFichierModifie, $chaineModifiee);
if ($write !== false) {
if (!touch($destdir.'/containers/'."page" . $nextpage . ".tpl.php")) {
setEventMessages("Please check permission to create <b>page" . $nextpage . ".tpl.php</b> in template <b>".$website->name_template."</b>", null, 'errors');
}
$fileFounded = '';
foreach ($arraySourcedir as $file) {
if ($file['name'] == $nomFichierModifie) {
$fileContent = file_get_contents($file['fullname']);
if (preg_match("/page\d+\.tpl\.php/", $fileContent, $matches)) {
$fileFounded = $matches[0];
break;
}
}
}
foreach ($arraySourcedir as $file) {
if ($file['name'] == $fileFounded) {
if (!is_writable($file['fullname'])) {
dolChmod($file['fullname'], '0664');
}
$diff = $this->showDifferences(file_get_contents($destdir.'/containers/'."page" . $nextpage . ".tpl.php"), file_get_contents($file['fullname']), array($nextpage,$this->extractNumberFromFilename($file['name'])));
if ($diff != -1) {
$replace = $this->replaceLineUsingNum($destdir.'/containers/'."page" . $nextpage . ".tpl.php", $diff);
if ($replace !== false) {
setEventMessages("Copy file <b>page".$nextpage.".tpl.php</b> in template <b>".$this->name_template."</b> with success", null, 'warnings');
}
}
}
}
}
}
$this->saveState($etatPrecedent, $fichierEtat);
setEventMessages("file <b>".$nomFichierModifie."</b> was created in template <b>".$website->name_template."</b>", null, 'warnings');
header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website->ref);
exit();
}
}
}
// Find the corresponding file in the destination folder
if (in_array($nomFichierModifie, $namesSource)) {
foreach ($arraydestdir as $destFile) {
if ($destFile['name'] == $nomFichierModifie) {
$sourceContent = file_get_contents($fichierModifie['fullname']);
$destContent = file_get_contents($destFile['fullname']);
if ($sourceContent !== $destContent) {
$differences[$nomFichierModifie] = $this->showDifferences($destContent, $sourceContent);
if (count($differences[$nomFichierModifie]) > 0) {
$result = $this->replaceLineUsingNum($destFile['fullname'], $differences[$nomFichierModifie]);
if ($result !== false) {
if ($result == -2) {
setEventMessages("No permissions to write into file <b>".$destdirrel.'/'.$nomFichierModifie."</b> from the current website <b>".$website->name_template."</b>", null, 'errors');
header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website->ref);
exit();
}
setEventMessages("file <b>".$nomFichierModifie."</b> was modified in template <b>".$website->name_template."</b>", null, 'warnings');
} else {
setEventMessages("file ".$nomFichierModifie." was not modified", null, 'errors');
}
}
}
}
if (preg_match('/page(\d+)\.tpl\.php/', $nomFichierModifie)) {
$differences[$nomFichierModifie] = $this->compareFichierModifie($sourcedir, $destdir, $fichierModifie);
if (count($differences[$nomFichierModifie]) > 0) {
$result = $this->replaceLineUsingNum($differences[$nomFichierModifie]['file_destination']['fullname'], $differences[$nomFichierModifie]);
if ($result !== false) {
if ($result == -2) {
setEventMessages("No permissions to write into file <b>".$destdirrel.'/'.$differences[$nomFichierModifie]['file_destination']['name']."</b> from the current website <b>".$website->name_template."</b>", null, 'errors');
header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website->ref);
exit();
}
$success++;
}
}
}
}
}
}
if ($success > 0) {
// Save the state file filelist.txt
$this->saveState($etatPrecedent, $fichierEtat);
setEventMessages("file <b>".$differences[$nomFichierModifie]['file_destination']['name']."</b> was modified in template <b>".$website->name_template."</b>", null, 'warnings');
header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website->ref);
exit();
}
} else {
setEventMessages("No file has been modified", null, 'errors');
}
// save state file
$this->saveState($etatPrecedent, $fichierEtat);
header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website->ref);
exit();
}
/**
* extract num of page
* @param string $filename name of file
* @return int 1 if OK, -1 if KO
*/
protected function extractNumberFromFilename($filename)
{
$matches = [];
if (preg_match('/page(\d+)\.tpl\.php/', $filename, $matches)) {
return (int) $matches[1];
}
return -1;
}
/**
* update name_template in table after import template
* @param string $name_template name of template
* @return int 1 if OK, -1 if KO
*/
public function setTemplateName($name_template)
{
$sql = "UPDATE ".$this->db->prefix()."website SET";
$sql .= " name_template = '".$this->db->escape($name_template)."'";
$sql .= " WHERE rowid = ".(int) $this->id;
$result = $this->db->query($sql);
if ($result) {
$this->db->commit();
return 1;
} else {
$this->db->rollback();
return -1;
}
}
/**
* check previous state for file
* @param string $pathname path of file
* @return array|mixed
*/
public function checkPreviousState($pathname)
{
if (!file_exists($pathname)) {
if (touch($pathname)) {
dolChmod($pathname, '0664');
}
return [];
}
return unserialize(file_get_contents($pathname));
}
/**
* Save state for File
* @param mixed $etat state
* @param mixed $pathname path of file
* @return int|false
*/
public function saveState($etat, $pathname)
{
return file_put_contents($pathname, serialize($etat));
}
/**
* create file for save state of all files in folder
* @param string $sourcedir path of folder
* @return void
*/
public function initFilesStatus($sourcedir)
{
$fichierEtat = $sourcedir . '/filelist-lastwrite-doctemplates.txt';
$etatPrecedent = $this->checkPreviousState($fichierEtat);
// for first save state when create file
if (empty($etatPrecedent)) {
$arraySourcedir = dol_dir_list($sourcedir, "files");
$etatFichiers = [];
foreach ($arraySourcedir as $file) {
// Ignore .old files and the status file itself
if (substr($file['name'], -4) === '.old' || $file['name'] === basename($fichierEtat)) {
continue;
}
$hashActuel = hash_file('md5', $file['fullname']);
$etatFichiers[$file['name']] = $hashActuel;
}
$this->saveState($etatFichiers, $fichierEtat);
}
}
/**
* Compare two files has not same name but same content
* @param string $dossierSource filepath of folder source
* @param string $dossierDestination filepath of folder dest
* @param mixed $fichierModifie files modified
* @return array empty if KO, array if OK
*/
public function compareFichierModifie($dossierSource, $dossierDestination, $fichierModifie)
{
$fichiersSource = [];
$fichiersDestination = [];
$fichierWithNoPage = [];
$fichierWithNoPageInDest = [];
// filter files source
foreach (dol_dir_list($dossierSource, "files") as $file) {
if (preg_match('/^page\d+/', $file['name']) && !str_contains($file['name'], '.old')) {
$fichiersSource[] = $file;
} else {
$fichierWithNoPage[] = $file;
}
}
// filter files destination
foreach (dol_dir_list($dossierDestination, "all", 1) as $file) {
if (preg_match('/^page\d+/', $file['name']) && !str_contains($file['name'], '.old')) {
$fichiersDestination[] = $file;
} else {
$fichierWithNoPageInDest[] = $file;
}
}
// find index source and search it in folder destination
$numOfPageSource = 0;
foreach ($fichiersSource as $index => $file) {
if ($file['name'] == basename($fichierModifie['fullname'])) {
$numOfPageSource = $this->extractNumberFromFilename($file['name']);
break;
}
}
//search numPage where was declared
$fileFounded = array();
foreach ($fichierWithNoPage as $filesource) {
$fileContent = file_get_contents($filesource['fullname']);
if (strpos($fileContent, "require './page".$numOfPageSource.".tpl.php'") !== false) {
$fileFounded = $filesource;
break;
}
}
// find file with same name and extract num page in destination folder
$numPageFounded = '';
foreach ($fichierWithNoPageInDest as $filedest) {
if ($filedest['name'] === $fileFounded['name']) {
$fileContent = file_get_contents($filedest['fullname']);
if (preg_match("/page\d+\.tpl\.php/", $fileContent, $matches)) {
$numPageFounded = $matches[0];
break;
}
}
}
//search file with the number of page founded
$fileNeeded = array();
foreach ($fichiersDestination as $index => $file) {
if ($file['name'] == $numPageFounded) {
$fileNeeded = $file;
break;
}
}
if (isset($fileNeeded)) {
$sourceContent = file_get_contents($fichierModifie['fullname']);
if (file_exists($fileNeeded['fullname'])) {
$destContent = file_get_contents($fileNeeded['fullname']);
$numOfPageDest = $this->extractNumberFromFilename($fileNeeded['name']);
$differences = $this->showDifferences($destContent, $sourceContent, array($numOfPageDest,$numOfPageSource));
$differences['file_destination'] = $fileNeeded;
}
return $differences;
}
return array();
}
/**
* remove espace in string
* @param string $str string
* @return string
*/
private function normalizeString($str)
{
$str = str_replace("\r\n", "\n", $str);
$str = str_replace("\r", "\n", $str);
return $str;
}
/**
* show difference between to string
* @param string $str1 first string
* @param string $str2 seconde string
* @param array $exceptNumPge num of page files we don't want to change
* @return array|int -1 if KO, array if OK
*/
protected function showDifferences($str1, $str2, $exceptNumPge = array())
{
$diff = array();
$str1 = $this->normalizeString($str1);
$str2 = $this->normalizeString($str2);
$lines1 = explode("\n", $str1);
$lines2 = explode("\n", $str2);
$linesShouldnChange = array();
$linesShouldnNotChange = array();
$linefound = array();
$countNumPage = count($exceptNumPge);
for ($i = 0;$i< $countNumPage; $i++) {
$linefound[$i]['meta'] = '/content="' . preg_quote($exceptNumPge[$i], '/') . '" \/>/';
$linefound[$i]['output'] = '/dolWebsiteOutput\(\$tmp, "html", ' . preg_quote($exceptNumPge[$i], '/') . '\);/';
}
$maxLines = max(count($lines1), count($lines2));
for ($lineNum = 0; $lineNum < $maxLines; $lineNum++) {
$lineContent1 = $lines1[$lineNum] ?? '';
$lineContent2 = $lines2[$lineNum] ?? '';
if (preg_match($linefound[0]['output'], $lineContent1)) {
$linesShouldnChange[] = $lineContent1;
}
if (preg_match($linefound[0]['meta'], $lineContent1)) {
$linesShouldnChange[] = $lineContent1;
}
if (preg_match($linefound[1]['output'], $lineContent2)) {
$linesShouldnNotChange[] = $lineContent2;
}
if (preg_match($linefound[1]['meta'], $lineContent2)) {
$linesShouldnNotChange[] = $lineContent2;
}
if ($lineContent1 !== $lineContent2) {
if (isset($lines1[$lineNum]) && !isset($lines2[$lineNum])) {
// Ligne deleted de la source
$diff["Supprimée à la ligne " . ($lineNum + 1)] = $lineContent1;
} elseif (!isset($lines1[$lineNum]) && isset($lines2[$lineNum])) {
// Nouvelle ligne added dans la destination
$diff["Ajoutée à la ligne " . ($lineNum + 1)] = $lineContent2;
} else {
// Différence found it
$diff["Modifiée à la ligne " . ($lineNum + 1)] = $lineContent2;
}
}
}
if (empty($linesShouldnChange)) {
$linesShouldnChange[0] = '<meta name="dolibarr:pageid" content="'.$exceptNumPge[0].'" />';
$linesShouldnChange[1] = '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "html", '.$exceptNumPge[0].');';
}
$pairesRemplacement = array();
if (!empty($linesShouldnNotChange)) {
$i =0;
foreach ($linesShouldnNotChange as $numLigne => $ligneRemplacement) {
if (isset($linesShouldnChange[$numLigne])) {
$pairesRemplacement[$ligneRemplacement] = $linesShouldnChange[$numLigne];
} else {
$pairesRemplacement[$ligneRemplacement] = $linesShouldnChange[$i];
}
$i++;
}
$diff['lignes_dont_change'] = $pairesRemplacement;
}
// search path of image and replace it with the correcte path
$pattern = '/medias\/image\/'.$this->ref.'\/([^\'"\s]+)/';
foreach ($diff as $key => $value) {
// Assurez-vous que la valeur est une chaîne
if (is_string($value)) {
if (preg_match($pattern, $value)) {
$newValue = preg_replace($pattern, 'medias/image/'.$this->name_template.'/$1', $value);
$diff[$key] = $newValue;
}
}
}
return $diff;
}
/**
* Replace line by line in file using num of line
* @param string $desfFile path of file dest
* @param array $differences array of differences between files
* @return false|int false if we can't replace
*/
protected function replaceLineUsingNum($desfFile, $differences)
{
$userId = fileowner($desfFile);
if ($userId !== false) {
// Obtain user information from the ID
if (function_exists('posix_getpwuid')&& function_exists('posix_getpwuid')) {
$uid = posix_geteuid();
$userInfoM = posix_getpwuid($uid);
$userInfo = posix_getpwuid($userId);
if ($userInfo['uid'] !== $userInfoM['uid']) {
return -2;
}
}
}
if (file_exists($desfFile)) {
dolChmod($desfFile, '0664');
}
unset($differences['file_destination']);
$contentDest = file($desfFile, FILE_IGNORE_NEW_LINES);
foreach ($differences as $key => $ligneSource) {
if (preg_match('/(Ajoutée|Modifiée) à la ligne (\d+)/', $key, $matches)) {
$typeModification = $matches[1];
$numLigne = (int) $matches[2] - 1;
if ($typeModification === 'Ajoutée') {
array_splice($contentDest, $numLigne, 0, $ligneSource);
} elseif ($typeModification === 'Modifiée') {
$contentDest[$numLigne] = $ligneSource;
}
} elseif (preg_match('/Supprimée à la ligne (\d+)/', $key, $matches)) {
$numLigne = (int) $matches[1] - 1;
unset($contentDest[$numLigne]);
}
}
// Reindex the table keys
$contentDest = array_values($contentDest);
$stringreplacement = implode("\n", $contentDest);
file_put_contents($desfFile, $stringreplacement);
foreach ($differences['lignes_dont_change'] as $linechanged => $line) {
if (in_array($linechanged, $contentDest)) {
dolReplaceInFile($desfFile, array($linechanged => $line));
}
}
}
}

View file

@ -2405,7 +2405,6 @@ if ($action == 'exportsite' && $user->hasRight('website', 'export')) {
if ($fileofzip) {
$file_name = basename($fileofzip);
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=".$file_name);
header("Content-Length: ".filesize($fileofzip));
@ -2418,6 +2417,12 @@ if ($action == 'exportsite' && $user->hasRight('website', 'export')) {
}
}
// Overwrite site
if ($action == 'overwritesite' && $user->hasRight('website', 'export')) {
if (getDolGlobalString('WEBSITE_ALLOW_OVERWRITE_GIT_SOURCE')) {
$fileofzip = $object->overwriteTemplate();
}
}
// Regenerate site
if ($action == 'regeneratesite' && $usercanedit) {
// Check symlink to medias and restore it if ko. Recreate also dir of website if not found.
@ -2518,6 +2523,9 @@ if ($action == 'importsiteconfirm' && $usercanedit) {
}
if (!$error && GETPOSTISSET('templateuserfile')) {
$templatewithoutzip = preg_replace('/\.zip$/i', '', GETPOST('templateuserfile'));
$object->setTemplateName($templatewithoutzip);
$result = $object->importWebSite($fileofzip);
if ($result < 0) {
@ -3014,6 +3022,11 @@ if (!GETPOST('hide_websitemenu')) {
// Export web site
print '<input type="submit" class="button bordertransp"'.$disabledexport.' value="'.dol_escape_htmltag($exportlabel).'" name="exportsite">';
if (getDolGlobalString('WEBSITE_ALLOW_OVERWRITE_GIT_SOURCE')) {
// Overwrite template in sources
print '<a href="'.$_SERVER["PHP_SELF"].'?action=overwritesite&website='.urlencode($website->ref).'" class="button bordertransp">'.dol_escape_htmltag($langs->trans("ExportIntoGIT")).'</a>';
}
// Clone web site
print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("CloneSite")).'" name="createfromclone">';

View file

@ -99,6 +99,8 @@ class AllTests
$suite->addTestSuite('FunctionsLibTest');
require_once dirname(__FILE__).'/Functions2LibTest.php';
$suite->addTestSuite('Functions2LibTest');
require_once dirname(__FILE__).'/ProfidLibTest.php';
$suite->addTestSuite('ProfidLibTest');
require_once dirname(__FILE__).'/XCalLibTest.php';
$suite->addTestSuite('XCalLibTest');

View file

@ -0,0 +1,283 @@
<?php
/* Copyright (C) 2010-2023 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 <https://www.gnu.org/licenses/>.
* or see https://www.gnu.org/
*/
/**
* \file test/phpunit/ProfidLibTest.php
* \ingroup test
* \brief PHPUnit test
* \remarks To run this script as CLI: phpunit filename.php
*/
global $conf,$user,$langs,$db,$mysoc;
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
//require_once 'PHPUnit/Autoload.php';
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
require_once dirname(__FILE__).'/../../htdocs/core/lib/profid.lib.php';
if (! defined('NOREQUIREUSER')) {
define('NOREQUIREUSER', '1');
}
if (! defined('NOREQUIREDB')) {
define('NOREQUIREDB', '1');
}
if (! defined('NOREQUIRESOC')) {
define('NOREQUIRESOC', '1');
}
if (! defined('NOREQUIRETRAN')) {
define('NOREQUIRETRAN', '1');
}
if (! defined('NOCSRFCHECK')) {
define('NOCSRFCHECK', '1');
}
if (! defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', '1');
}
if (! defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '1'); // If there is no menu to show
}
if (! defined('NOREQUIREHTML')) {
define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
}
if (! defined('NOREQUIREAJAX')) {
define('NOREQUIREAJAX', '1');
}
if (! defined("NOLOGIN")) {
define("NOLOGIN", '1'); // If this page is public (can be called outside logged session)
}
/**
* Class for PHPUnit tests
*
* @backupGlobals disabled
* @backupStaticAttributes enabled
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
*/
class ProfidLibTest extends PHPUnit\Framework\TestCase
{
protected $savconf;
protected $savuser;
protected $savlangs;
protected $savdb;
/**
* Constructor
* We save global variables into local variables
*
* @param string $name Name
* @return CoreTest
*/
public function __construct($name = '')
{
parent::__construct($name);
//$this->sharedFixture
global $conf,$user,$langs,$db;
$this->savconf=$conf;
$this->savuser=$user;
$this->savlangs=$langs;
$this->savdb=$db;
print __METHOD__." db->type=".$db->type." user->id=".$user->id;
//print " - db ".$db->db;
print "\n";
}
/**
* setUpBeforeClass
*
* @return void
*/
public static function setUpBeforeClass(): void
{
global $conf,$user,$langs,$db;
//$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
print __METHOD__."\n";
}
/**
* tearDownAfterClass
*
* @return void
*/
public static function tearDownAfterClass(): void
{
global $conf,$user,$langs,$db;
//$db->rollback();
print __METHOD__."\n";
}
/**
* Init phpunit tests. Restore variables before each test.
*
* @return void
*/
protected function setUp(): void
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
//$db=$this->savdb;
print __METHOD__."\n";
}
/**
* End phpunit tests
*
* @return void
*/
protected function tearDown(): void
{
print __METHOD__."\n";
}
/**
* testIsValidLuhn
*
* @return void
*/
public function testIsValidLuhn()
{
// Tests OK
$this->assertTrue(isValidLuhn(972487086)); // int
$this->assertTrue(isValidLuhn("972487086")); // string
// Tests KO
$this->assertFalse(isValidLuhn(123456789)); // int
$this->assertFalse(isValidLuhn("123456789")); // string
}
/**
* testIsValidSiren
*
* @return void
*/
public function testIsValidSiren()
{
// Tests OK
$this->assertTrue(isValidSiren("732829320"));
$this->assertTrue(isValidSiren(" 732 829 320 ")); // formatted with spaces
// Tests NOK
$this->assertFalse(isValidSiren("123456ABC")); // not numeric
$this->assertFalse(isValidSiren("43336767")); // Luhn test OK but length != 9
$this->assertFalse(isValidSiren("123456789")); // 9 digits but Luhn test KO
}
/**
* testIsValidSiret
*
* @return void
*/
public function testIsValidSiret()
{
// Tests OK
$this->assertTrue(isValidSiret("73282932000074"));
$this->assertTrue(isValidSiret(" 732 829 320 00074 ")); // formatted with spaces
$this->assertTrue(isValidSiret("35600000049837")); // Specific cases of "La Poste" companies
// Tests NOK
$this->assertFalse(isValidSiret("123456ABC12345")); // not numeric
$this->assertFalse(isValidSiret("3624679471379")); // Luhn test OK but length != 14
$this->assertFalse(isValidSiret("12345678912345")); // 14 digits but Luhn test KO
}
/**
* testIsValidTinForPT
*
* @return void
*/
public function testIsValidTinForPT()
{
// Tests OK
$this->assertTrue(isValidTinForPT("123456789"));
$this->assertTrue(isValidTinForPT(" 123 456 789 ")); // formatted with spaces
// Tests NOK
$this->assertFalse(isValidTinForPT("123456ABC")); // not numeric
$this->assertFalse(isValidTinForPT("12345678")); // length != 9
}
/**
* testIsValidTinForDZ
*
* @return void
*/
public function testIsValidTinForDZ()
{
// Tests OK
$this->assertTrue(isValidTinForDZ("123456789123456"));
$this->assertTrue(isValidTinForDZ(" 12345 67891 23456 ")); // formatted with spaces
// Tests NOK
$this->assertFalse(isValidTinForDZ("123456789123ABC")); // not numeric
$this->assertFalse(isValidTinForDZ("123456789123")); // length != 15
}
/**
* testIsValidTinForBE
*
* @return void
*/
public function testIsValidTinForBE()
{
// Tests OK
$this->assertTrue(isValidTinForBE("0123.123.123"));
$this->assertTrue(isValidTinForBE("1234.123.123"));
// Tests NOK
$this->assertFalse(isValidTinForBE("2345.123.123")); // First digit shall be 0 or 1
$this->assertFalse(isValidTinForBE("1234 123 123")); // formatted with spaces instead of dots
$this->assertFalse(isValidTinForBE("1234123123")); // without dots formatting
$this->assertFalse(isValidTinForBE("ABCD.123.123")); // not digits only
}
// TODO
/**
* testIsValidTinForES
*
* @return void
*/
/*
public function testIsValidTinForES()
{
// Tests for NIF
$this->assertEquals(1, isValidTinForES("")); // valid NIF
$this->assertEquals(-1, isValidTinForES("")); // valid regex, but invalid control key
// Tests for CIF
$this->assertEquals(2, isValidTinForES("")); // valid CIF
$this->assertEquals(-2, isValidTinForES("")); // valid regex, but invalid control key
// Tests for NIE
$this->assertEquals(3, isValidTinForES("")); // valid NIE
$this->assertEquals(-3, isValidTinForES("")); // valid regex, but invalid control key
// Tests for unknown error
$this->assertEquals(-4, isValidTinForES("")); // invalid regex for both NIF, CIF and NIE
}
*/
}