From 35c094e0bbb5010e2ad2b9ce96fd92b3790b5765 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 11 Apr 2024 10:38:22 +0200 Subject: [PATCH 01/14] css --- htdocs/theme/eldy/global.inc.php | 4 ++++ htdocs/theme/md/style.css.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index 6e860b8a37c..621daa785f3 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -770,6 +770,10 @@ div.floatright { display:block; } +.inline +{ + display:inline; +} .inline-block { display:inline-block; diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index 67783785de5..6538364a278 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -957,6 +957,10 @@ div.floatright { display:block; } +.inline +{ + display:inline; +} .inline-block { display:inline-block; From beda30c493138996750607c39ba592d1934b65a7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 11 Apr 2024 10:55:42 +0200 Subject: [PATCH 02/14] Debug v20 --- htdocs/admin/webhook.php | 5 +++-- htdocs/langs/en_US/admin.lang | 3 ++- htdocs/webhook/class/target.class.php | 10 ++++++---- htdocs/webhook/target_list.php | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/htdocs/admin/webhook.php b/htdocs/admin/webhook.php index a0ef3ee897c..cdd26c933c8 100644 --- a/htdocs/admin/webhook.php +++ b/htdocs/admin/webhook.php @@ -159,7 +159,7 @@ $head = webhookAdminPrepareHead(); print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "webhook"); // Setup page goes here -echo ''.$langs->trans("WebhookSetupPage").'

'; +echo ''.$langs->trans("WebhookSetupPage", $langs->transnoentitiesnoconv("Targets")).'

'; if ($action == 'edit') { @@ -339,10 +339,11 @@ if ($action == 'edit') { } } - +/* if (empty($setupnotempty)) { print '
'.$langs->trans("NothingToSetup"); } +*/ // Page end print dol_get_fiche_end(); diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index d216a035a50..691b55e52b5 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1814,6 +1814,7 @@ DetailRight=Condition to display unauthorized gray menus DetailLangs=Lang file name for label code translation DetailUser=Intern / Extern / All Target=Target +Targets=Targets DetailTarget=Target for links (_blank top opens a new window) DetailLevel=Level (-1:top menu, 0:header menu, >0 menu and sub menu) ModifMenu=Menu change @@ -2335,7 +2336,7 @@ ExportUseLowMemoryModeHelp=Use the low memory mode to generate the dump file (co ModuleWebhookName = Webhook ModuleWebhookDesc = Interface to catch dolibarr triggers and send data of the event to an URL WebhookSetup = Webhook setup -WebhookSetupPage = Webhook setup page +WebhookSetupPage = Webhook setup page. To activate a webhook, go on the %s tab and create targets ShowQuickAddLink=Show a button to quickly add an element in top right menu ShowSearchAreaInTopMenu=Show the search area in the top menu HashForPing=Hash used for ping diff --git a/htdocs/webhook/class/target.class.php b/htdocs/webhook/class/target.class.php index 24e1b7c1a37..a0c43455874 100644 --- a/htdocs/webhook/class/target.class.php +++ b/htdocs/webhook/class/target.class.php @@ -106,9 +106,9 @@ class Target extends CommonObject public $fields = array( 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id"), 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 20, 'notnull' => 1, 'visible' => 4, 'noteditable' => 1, 'index' => 1, 'searchall' => 1, 'validate' => 1, 'comment' => "Reference of object"), - 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 30, 'notnull' => 0, 'visible' => 1, 'searchall' => 1, 'css' => 'minwidth300', 'cssview' => 'wordbreak', 'help' => "Help text", 'showoncombobox' => 2, 'validate' => 1,), - 'url' => array('type' => 'varchar(255)', 'label' => 'Url', 'enabled' => 1, 'position' => 50, 'notnull' => 1, 'visible' => 1,), - 'trigger_codes' => array('type' => 'text', 'label' => 'TriggerCodes', 'enabled' => 1, 'position' => 55, 'notnull' => 1, 'visible' => 1, 'help' => "TriggerCodeInfo",), + 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 30, 'notnull' => 0, 'visible' => 1, 'searchall' => 1, 'css' => 'minwidth300', 'cssview' => 'wordbreak', 'csslist'=>'tdoverflowmax150', 'showoncombobox' => 2, 'validate' => 1,), + 'trigger_codes' => array('type' => 'text', 'label' => 'TriggerCodes', 'enabled' => 1, 'position' => 50, 'notnull' => 1, 'visible' => 1, 'help' => "TriggerCodeInfo", 'tdcss'=>'titlefieldmiddle'), + 'url' => array('type' => 'varchar(255)', 'label' => 'Url', 'enabled' => 1, 'position' => 55, 'notnull' => 1, 'visible' => 1,), 'description' => array('type' => 'text', 'label' => 'Description', 'enabled' => 1, 'position' => 60, 'notnull' => 0, 'visible' => 3, 'validate' => 1,), 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 61, 'notnull' => 0, 'visible' => 0, 'cssview' => 'wordbreak', 'validate' => 1,), 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 62, 'notnull' => 0, 'visible' => 0, 'cssview' => 'wordbreak', 'validate' => 1,), @@ -805,7 +805,9 @@ class Target extends CommonObject } $statusType = 'status'.$status; - //if ($status == self::STATUS_VALIDATED) $statusType = 'status1'; + if ($status == self::STATUS_VALIDATED) { + $statusType = 'status4'; + } if ($status == self::STATUS_CANCELED) { $statusType = 'status6'; } diff --git a/htdocs/webhook/target_list.php b/htdocs/webhook/target_list.php index 2a119373a51..cfc69b02d01 100644 --- a/htdocs/webhook/target_list.php +++ b/htdocs/webhook/target_list.php @@ -218,7 +218,7 @@ $form = new Form($db); $now = dol_now(); //$help_url = "EN:Module_Target|FR:Module_Target_FR|ES:Módulo_Target"; $help_url = ''; -$title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("Targets")); +$title = $langs->trans("Targets"); $morejs = array(); $morecss = array(); From a63614593bbad3d2a9e4668e32ada1279d30a850 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 11 Apr 2024 11:04:42 +0200 Subject: [PATCH 03/14] Removed deprecated line --- htdocs/install/mysql/migration/19.0.0-20.0.0.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/install/mysql/migration/19.0.0-20.0.0.sql b/htdocs/install/mysql/migration/19.0.0-20.0.0.sql index 65cd026efb5..11c972958fb 100644 --- a/htdocs/install/mysql/migration/19.0.0-20.0.0.sql +++ b/htdocs/install/mysql/migration/19.0.0-20.0.0.sql @@ -301,3 +301,5 @@ ALTER TABLE llx_bookcal_calendar ADD COLUMN entity integer DEFAULT 1 NOT NULL AF ALTER TABLE llx_rights_def ADD COLUMN module_origin varchar(64) AFTER module; ALTER TABLE llx_rights_def ADD COLUMN enabled text NULL AFTER bydefault; + +DELETE FROM llx_c_action_trigger WHERE code = 'BILLREC_AUTOCREATEBILL'; From 84db53ef63d2d72e133cdc2a3b6f8ee9a0d6945a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 11 Apr 2024 12:10:38 +0200 Subject: [PATCH 04/14] Fix link to image in RSS --- htdocs/website/samples/wrapper.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/website/samples/wrapper.php b/htdocs/website/samples/wrapper.php index 4e39f2bbbaa..500501eb61c 100644 --- a/htdocs/website/samples/wrapper.php +++ b/htdocs/website/samples/wrapper.php @@ -116,6 +116,8 @@ if ($rss) { if (is_array($arrayofblogs)) { foreach ($arrayofblogs as $blog) { $blog->fullpageurl = $website->virtualhost.'/'.$blog->pageurl.'.php'; + $blog->image = preg_replace('/__WEBSITE_KEY__/', $websitekey, $blog->image); + $eventarray[] = $blog; } } From bf92611e18915bd906d3a67fe5979c837bf2145f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 11 Apr 2024 12:26:02 +0200 Subject: [PATCH 05/14] Fix warning --- htdocs/user/list.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/user/list.php b/htdocs/user/list.php index b9234625794..a896b80e444 100644 --- a/htdocs/user/list.php +++ b/htdocs/user/list.php @@ -686,8 +686,10 @@ if (!empty($catid)) { } if ($search_all) { + $setupstring = ''; foreach ($fieldstosearchall as $key => $val) { $fieldstosearchall[$key] = $langs->trans($val); + $setupstring .= $key."=".$val.";"; } print ''."\n"; print '
'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'
'; From a1e25601e73451d4f9ff82d83d30d5af812c902e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 11 Apr 2024 12:29:52 +0200 Subject: [PATCH 06/14] Fix search_all must not force the status to enabled --- htdocs/user/list.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/user/list.php b/htdocs/user/list.php index a896b80e444..fa327939a70 100644 --- a/htdocs/user/list.php +++ b/htdocs/user/list.php @@ -172,7 +172,7 @@ $search_thirdparty = GETPOST('search_thirdparty', 'alpha'); $search_job = GETPOST('search_job', 'alpha'); $search_warehouse = GETPOST('search_warehouse', 'alpha'); $search_supervisor = GETPOST('search_supervisor', 'intcomma'); -$search_categ = GETPOSTINT("search_categ"); +$search_categ = GETPOST("search_categ", 'intcomma'); $searchCategoryUserOperator = 0; if (GETPOSTISSET('formfilteraction')) { $searchCategoryUserOperator = GETPOSTINT('search_category_user_operator'); @@ -190,7 +190,7 @@ if (!empty($catid) && empty($search_categ)) { } // Default search -if ($search_status == '') { +if ($search_status == '' && empty($search_all)) { $search_status = '1'; } if ($contextpage == 'employeelist' && !GETPOSTISSET('search_employee')) { From c12a9a9d50e2358c9a6625d3520b5116beeda512 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 11 Apr 2024 12:29:54 +0200 Subject: [PATCH 07/14] Fix search_all must not force the status to enabled From d86f5c83f02eff7aa141bb1c387e15926caad331 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 11 Apr 2024 14:32:02 +0200 Subject: [PATCH 08/14] FIX Oauth login --- htdocs/core/login/functions_googleoauth.php | 1 + htdocs/core/modules/oauth/google_oauthcallback.php | 2 +- htdocs/core/tpl/login.tpl.php | 5 ++++- htdocs/main.inc.php | 11 ++++++++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/htdocs/core/login/functions_googleoauth.php b/htdocs/core/login/functions_googleoauth.php index 0e61541192c..c0a77655f29 100644 --- a/htdocs/core/login/functions_googleoauth.php +++ b/htdocs/core/login/functions_googleoauth.php @@ -115,6 +115,7 @@ function check_user_password_googleoauth($usertotest, $passwordtotest, $entityto // If googleoauth_login has been set (by google_oauthcallback after a successful OAUTH2 request on openid scope if (!empty($_SESSION['googleoauth_receivedlogin']) && dol_verifyHash($conf->file->instance_unique_id.$usertotest, $_SESSION['googleoauth_receivedlogin'], '0')) { + dol_syslog("Login received by Google OAuth was validated by callback page and saved crypted into session. This login is ".$usertotest); unset($_SESSION['googleoauth_receivedlogin']); $login = $usertotest; } diff --git a/htdocs/core/modules/oauth/google_oauthcallback.php b/htdocs/core/modules/oauth/google_oauthcallback.php index 4f38e884481..165fb44c61e 100644 --- a/htdocs/core/modules/oauth/google_oauthcallback.php +++ b/htdocs/core/modules/oauth/google_oauthcallback.php @@ -152,7 +152,7 @@ if ($action == 'delete') { } if (!GETPOST('code')) { - dol_syslog("Page is called without code parameter defined"); + dol_syslog("Page is called without the 'code' parameter defined"); // If we enter this page without 'code' parameter, it means we click on the link from login page and we want to get the redirect // to the OAuth provider login page. diff --git a/htdocs/core/tpl/login.tpl.php b/htdocs/core/tpl/login.tpl.php index e7eea603e18..f271a2ed385 100644 --- a/htdocs/core/tpl/login.tpl.php +++ b/htdocs/core/tpl/login.tpl.php @@ -74,10 +74,13 @@ if (preg_match('/'.preg_quote('core/modules/oauth', '/').'/', $php_self)) { $php_self = DOL_URL_ROOT.'/index.php?mainmenu=home'; } $php_self = preg_replace('/(\?|&|&)action=[^&]+/', '\1', $php_self); +$php_self = preg_replace('/(\?|&|&)actionlogin=[^&]+/', '\1', $php_self); +$php_self = preg_replace('/(\?|&|&)afteroauthloginreturn=[^&]+/', '\1', $php_self); $php_self = preg_replace('/(\?|&|&)username=[^&]*/', '\1', $php_self); $php_self = preg_replace('/(\?|&|&)entity=\d+/', '\1', $php_self); $php_self = preg_replace('/(\?|&|&)massaction=[^&]+/', '\1', $php_self); $php_self = preg_replace('/(\?|&|&)token=[^&]+/', '\1', $php_self); +$php_self = preg_replace('/(&)+/', '&', $php_self); // Javascript code on logon page only to detect user tz, dst_observed, dst_first, dst_second $arrayofjs = array( @@ -374,7 +377,7 @@ if (isset($conf->file->main_authentication) && preg_match('/google/', $conf->fil */ print ''; - print ''; + print ''; print '
'; print img_picto('', 'google', 'class="pictofixedwidth"'); print $langs->trans("LoginWith", "Google"); diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 67886881b32..2e937c9b543 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -876,9 +876,13 @@ if (!defined('NOLOGIN')) { // $authmode is an array for example: array('0'=>'dolibarr', '1'=>'googleoauth'); $oauthmodetotestarray = array('google'); foreach ($oauthmodetotestarray as $oauthmodetotest) { - if (in_array($oauthmodetotest.'oauth', $authmode) && GETPOST('beforeoauthloginredirect') != $oauthmodetotest) { - // If we did not click on the link to use OAuth authentication, we do not try it. - dol_syslog("User did not click on link for OAuth so we disable check using googleoauth"); + if (in_array($oauthmodetotest.'oauth', $authmode)) { // This is an authmode that is currently qualified. Do we have to remove it ? + // If we click on the link to use OAuth authentication or if we goes after callback return, we do nothing + if (GETPOST('beforeoauthloginredirect') == $oauthmodetotest || GETPOST('afteroauthloginreturn')) { + // TODO Use: if (GETPOST('beforeoauthloginredirect') == $oauthmodetotest || GETPOST('afteroauthloginreturn') == $oauthmodetotest) { + continue; + } + dol_syslog("User did not click on link for OAuth or is not on the OAuth return, so we disable check using ".$oauthmodetotest); foreach ($authmode as $tmpkey => $tmpval) { if ($tmpval == $oauthmodetotest.'oauth') { unset($authmode[$tmpkey]); @@ -888,6 +892,7 @@ if (!defined('NOLOGIN')) { } } + // Check login for all qualified modes in array $authmode. $login = checkLoginPassEntity($usertotest, $passwordtotest, $entitytotest, $authmode); if ($login === '--bad-login-validity--') { $login = ''; From 5ccbca4009a482474802c6aa21236be4a337c491 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 11 Apr 2024 14:40:02 +0200 Subject: [PATCH 09/14] Trans --- htdocs/admin/oauthlogintokens.php | 46 +++++++++++++++++-------------- htdocs/langs/en_US/admin.lang | 1 + 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/htdocs/admin/oauthlogintokens.php b/htdocs/admin/oauthlogintokens.php index da17f3e3e9d..90130e78505 100644 --- a/htdocs/admin/oauthlogintokens.php +++ b/htdocs/admin/oauthlogintokens.php @@ -315,31 +315,37 @@ if ($mode == 'setup' && $user->admin) { print $langs->trans("IsTokenGenerated"); print ''; print ''; - if (is_object($tokenobj)) { - print $form->textwithpicto(yn(1), $langs->trans("HasAccessToken").' : '.dol_print_date($storage->date_modification, 'dayhour').' state='.dol_escape_htmltag($storage->state)); + if ($keyforprovider != 'Login') { + if (is_object($tokenobj)) { + print $form->textwithpicto(yn(1), $langs->trans("HasAccessToken").' : '.dol_print_date($storage->date_modification, 'dayhour').' state='.dol_escape_htmltag($storage->state)); + } else { + print ''.$langs->trans("NoAccessToken").''; + } } else { - print ''.$langs->trans("NoAccessToken").''; + print ''.$langs->trans("TokenNotRequiredForOAuthLogin").''; } print ''; print ''; - // Links to delete/checks token - if (is_object($tokenobj)) { - //test on $storage->hasAccessToken($OAUTH_SERVICENAME) ? - if ($urltodelete) { - print ''.$langs->trans('DeleteAccess').'
'; - } else { - print ''.$langs->trans('GoOnTokenProviderToDeleteToken').'
'; + if ($keyforprovider != 'Login') { + // Links to delete/checks token + if (is_object($tokenobj)) { + //test on $storage->hasAccessToken($OAUTH_SERVICENAME) ? + if ($urltodelete) { + print ''.$langs->trans('DeleteAccess').'
'; + } else { + print ''.$langs->trans('GoOnTokenProviderToDeleteToken').'
'; + } + } + // Request remote token + if ($urltorenew) { + print ''.$langs->trans('GetAccess').''; + print $form->textwithpicto('', $langs->trans('RequestAccess')); + print '
'; + } + // Check remote access + if ($urltocheckperms) { + print '
'.$langs->trans("ToCheckDeleteTokenOnProvider", $OAUTH_SERVICENAME).': '.$urltocheckperms.''; } - } - // Request remote token - if ($urltorenew) { - print ''.$langs->trans('GetAccess').''; - print $form->textwithpicto('', $langs->trans('RequestAccess')); - print '
'; - } - // Check remote access - if ($urltocheckperms) { - print '
'.$langs->trans("ToCheckDeleteTokenOnProvider", $OAUTH_SERVICENAME).': '.$urltocheckperms.''; } print ''; print ''; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 691b55e52b5..29603bc54db 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -2135,6 +2135,7 @@ oauthToken=OAuth2 token accessType=Access type oauthService=Oauth service TokenMustHaveBeenCreated=Module OAuth2 must be enabled and an oauth2 token must have been created with the correct permissions (for example scope "gmail_full" with OAuth for Gmail). +TokenNotRequiredForOAuthLogin=Token unnecessary for OAuth entry used for Login ImapEncryption = IMAP encryption method ImapEncryptionHelp = Example: none, ssl, tls, notls NoRSH = Use the NoRSH configuration From feae114088d5997bbcb1d5869fe98503bffb3273 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 11 Apr 2024 19:07:05 +0200 Subject: [PATCH 10/14] Rename email files --- ...icket.txt => source_email_ticket_2_a_answer_from_ticket.txt} | 0 ...ailer.txt => source_email_ticket_2_b_answer_from_mailer.txt} | 0 ...rce_email_ticket_3_after_2_answer_of_answer_from_mailer.txt} | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename dev/examples/mail/{source_email_ticket_2_answer_from_ticket.txt => source_email_ticket_2_a_answer_from_ticket.txt} (100%) rename dev/examples/mail/{source_email_ticket_3_answer_from_mailer.txt => source_email_ticket_2_b_answer_from_mailer.txt} (100%) rename dev/examples/mail/{source_email_ticket_4_answer_of_answer_from_mailer.txt => source_email_ticket_3_after_2_answer_of_answer_from_mailer.txt} (99%) diff --git a/dev/examples/mail/source_email_ticket_2_answer_from_ticket.txt b/dev/examples/mail/source_email_ticket_2_a_answer_from_ticket.txt similarity index 100% rename from dev/examples/mail/source_email_ticket_2_answer_from_ticket.txt rename to dev/examples/mail/source_email_ticket_2_a_answer_from_ticket.txt diff --git a/dev/examples/mail/source_email_ticket_3_answer_from_mailer.txt b/dev/examples/mail/source_email_ticket_2_b_answer_from_mailer.txt similarity index 100% rename from dev/examples/mail/source_email_ticket_3_answer_from_mailer.txt rename to dev/examples/mail/source_email_ticket_2_b_answer_from_mailer.txt diff --git a/dev/examples/mail/source_email_ticket_4_answer_of_answer_from_mailer.txt b/dev/examples/mail/source_email_ticket_3_after_2_answer_of_answer_from_mailer.txt similarity index 99% rename from dev/examples/mail/source_email_ticket_4_answer_of_answer_from_mailer.txt rename to dev/examples/mail/source_email_ticket_3_after_2_answer_of_answer_from_mailer.txt index 314e9cda20f..69c22775b19 100644 --- a/dev/examples/mail/source_email_ticket_4_answer_of_answer_from_mailer.txt +++ b/dev/examples/mail/source_email_ticket_3_after_2_answer_of_answer_from_mailer.txt @@ -131,4 +131,4 @@ tter.com/eldy10
ps://www.twitter.com/eldy10" target=3D"_blank">https://www.twitter.com/eldy= 10 ---000000000000cd54be05ad51fe67-- \ No newline at end of file +--000000000000cd54be05ad51fe67-- From 2655cd156b65daa97e4fb4d945786fb13719af00 Mon Sep 17 00:00:00 2001 From: Lucas Marcouiller <45882981+Hystepik@users.noreply.github.com> Date: Thu, 11 Apr 2024 19:14:10 +0200 Subject: [PATCH 11/14] New api call counter (#29323) Co-authored-by: Hystepik --- htdocs/api/index.php | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/htdocs/api/index.php b/htdocs/api/index.php index 31e8dcf47c7..4dfbc3c7dcb 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -441,6 +441,52 @@ if (Luracast\Restler\Defaults::$returnResponse) { echo $result; } +if (getDolGlobalInt("API_ENABLE_COUNT_CALLS") && $api->r->responseCode == 200) { + $error = 0; + $db->begin(); + $userid = DolibarrApiAccess::$user->id; + + $sql = "SELECT up.value"; + $sql .= " FROM ".MAIN_DB_PREFIX."user_param as up"; + $sql .= " WHERE up.param = 'API_COUNT_CALL'"; + $sql .= " AND up.fk_user = ".((int) $userid); + $sql .= " AND up.entity = ".((int) $conf->entity); + + $result = $db->query($sql); + if ($result) { + $updateapi = false; + $nbrows = $db->num_rows($result); + if ($nbrows == 0) { + $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."user_param"; + $sql2 .= " (fk_user, entity, param, value)"; + $sql2 .= " VALUES (".((int) $userid).", ".((int) $conf->entity).", 'API_COUNT_CALL', 1)"; + } else { + $updateapi = true; + $sql2 = "UPDATE ".MAIN_DB_PREFIX."user_param as up"; + $sql2 .= " SET up.value = up.value + 1"; + $sql2 .= " WHERE up.param = 'API_COUNT_CALL'"; + $sql2 .= " AND up.fk_user = ".((int) $userid); + $sql2 .= " AND up.entity = ".((int) $conf->entity); + } + + $result2 = $db->query($sql2); + if (!$result2) { + $modeapicall = $updateapi ? 'updating' : 'inserting'; + dol_syslog('Error while '.$modeapicall. ' API_COUNT_CALL for user '.$userid, LOG_ERR); + $error++; + } + } else { + dol_syslog('Error on select API_COUNT_CALL for user '.$userid, LOG_ERR); + $error++; + } + + if ($error) { + $db->rollback(); + } else { + $db->commit(); + } +} + // Call API termination method $apiMethodInfo = &$api->r->apiMethodInfo; $terminateCall = '_terminate_' . $apiMethodInfo->methodName . '_' . $api->r->responseFormat->getExtension(); From e171e8e7efd92529651de55d1992af0c6244d9f5 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 11 Apr 2024 19:14:46 +0200 Subject: [PATCH 12/14] Qual: Fix all active phan notices in html.form.class.php (#29316) --- dev/tools/phan/baseline.txt | 1 - htdocs/core/class/html.form.class.php | 27 +++++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/dev/tools/phan/baseline.txt b/dev/tools/phan/baseline.txt index 37202d6187c..4dee052f83f 100644 --- a/dev/tools/phan/baseline.txt +++ b/dev/tools/phan/baseline.txt @@ -542,7 +542,6 @@ return [ 'htdocs/core/class/fiscalyear.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanPossiblyUndeclaredVariable'], 'htdocs/core/class/google.class.php' => ['PhanPluginUnknownPropertyType'], 'htdocs/core/class/hookmanager.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownObjectMethodCall', 'PhanTypeInvalidDimOffset', 'PhanUndeclaredProperty'], - 'htdocs/core/class/html.form.class.php' => ['PhanTypeConversionFromArray', 'PhanTypeInvalidDimOffset', 'PhanTypePossiblyInvalidDimOffset', 'PhanUndeclaredProperty', 'PhanPluginUnknownObjectMethodCall'], 'htdocs/core/class/html.formaccounting.class.php' => ['PhanPluginDuplicateExpressionAssignmentOperation', 'PhanPossiblyUndeclaredVariable'], 'htdocs/core/class/html.formadmin.class.php' => ['PhanPluginUnknownArrayMethodParamType'], 'htdocs/core/class/html.formbarcode.class.php' => ['PhanPluginUnknownArrayMethodParamType'], diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 79895728c3d..885611dc197 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5210,7 +5210,7 @@ class Form * @param string $title Title * @param string $question Question * @param string $action Action - * @param array $formquestion An array with complementary inputs to add into forms: array(array('label'=> ,'type'=> , 'size'=>, 'morecss'=>, 'moreattr'=>'autofocus' or 'style=...')) + * @param array{text:string}|array $formquestion An array with complementary inputs to add into forms: array(array('label'=> ,'type'=> , 'size'=>, 'morecss'=>, 'moreattr'=>'autofocus' or 'style=...')) * @param string $selectedchoice "" or "no" or "yes" * @param int|string $useajax 0=No, 1=Yes use Ajax to show the popup, 2=Yes and also submit page with &confirm=no if choice is No, 'xxx'=Yes and preoutput confirm box with div id=dialog-confirm-xxx * @param int $height Force height of box @@ -5244,8 +5244,8 @@ class Form * @param array}>|string|null $formquestion An array with complementary inputs to add into forms: array(array('label'=> ,'type'=> , 'size'=>, 'morecss'=>, 'moreattr'=>'autofocus' or 'style=...')) * 'type' can be 'text', 'password', 'checkbox', 'radio', 'date', 'datetime', 'select', 'multiselect', 'morecss', * 'other', 'onecolumn' or 'hidden'... - * @param int|string $selectedchoice '' or 'no', or 'yes' or '1', 1, '0' or 0 - * @param int|string $useajax 0=No, 1=Yes use Ajax to show the popup, 2=Yes and also submit page with &confirm=no if choice is No, 'xxx'=Yes and preoutput confirm box with div id=dialog-confirm-xxx + * @param int<0,1>|''|'no'|'yes'|'1'|'0' $selectedchoice '' or 'no', or 'yes' or '1', 1, '0' or 0 + * @param int<0,2>|string $useajax 0=No, 1=Yes use Ajax to show the popup, 2=Yes and also submit page with &confirm=no if choice is No, 'xxx'=Yes and preoutput confirm box with div id=dialog-confirm-xxx * @param int|string $height Force height of box (0 = auto) * @param int $width Force width of box ('999' or '90%'). Ignored and forced to 90% on smartphones. * @param int $disableformtag 1=Disable form tag. Can be used if we are already inside a
section. @@ -5450,8 +5450,8 @@ class Form array_push($inputok, $input['name']); } } - // Add name of fields to propagate with the GET when submitting the form with button KO. - if (isset($input['inputko']) && $input['inputko'] == 1 && isset($input['name'])) { + // Add name of fields to propagate with the GET when submitting the form with button KO. @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset + if (array_key_exists('inputko', $input) && $input['inputko'] == 1 && isset($input['name'])) { array_push($inputko, $input['name']); } } @@ -5459,7 +5459,7 @@ class Form // Show JQuery confirm box. $formconfirm .= '