From 496973996d2f8542773766ef3c7599866dc15897 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 9 Oct 2022 15:52:37 +0200 Subject: [PATCH 01/19] NEW Can remove a website template --- htdocs/core/lib/website2.lib.php | 11 +++++++++-- htdocs/website/index.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/website2.lib.php b/htdocs/core/lib/website2.lib.php index 17021ab25db..0b836399f43 100644 --- a/htdocs/core/lib/website2.lib.php +++ b/htdocs/core/lib/website2.lib.php @@ -563,7 +563,7 @@ function dolSaveLicense($file, $content) */ function showWebsiteTemplates(Website $website) { - global $conf, $langs, $db, $form; + global $conf, $langs, $db, $form, $user; $dirthemes = array('/doctemplates/websites'); if (!empty($conf->modules_parts['websitetemplates'])) { // Using this feature slow down application @@ -582,11 +582,15 @@ function showWebsiteTemplates(Website $website) // Title print ''; print $form->textwithpicto($langs->trans("Templates"), $langs->trans("ThemeDir").' : '.join(", ", $dirthemes)); + print ' '; + print ''; + print img_picto('', 'refresh'); + print ''; print ''; print ''; $url = 'https://www.dolistore.com/43-web-site-templates'; print ''; - print $langs->trans('DownloadMoreSkins'); + print img_picto('', 'globe', 'class="pictofixedwidth"').$langs->trans('DownloadMoreSkins'); print ''; print ''; @@ -645,6 +649,9 @@ function showWebsiteTemplates(Website $website) print $subdir; print '
'; print ''.dol_print_size(dol_filesize($dirtheme."/".$subdir), 1, 1).' - '.dol_print_date(dol_filemtime($templatedir), 'dayhour', 'tzuserrel').''; + if ($user->hasRight('website', 'delete')) { + print ' ref).'&templateuserfile='.urlencode($subdir).'">'.img_picto('', 'delete').''; + } print '
ref).'&templateuserfile='.urlencode($subdir).'" class="button">'.$langs->trans("Load").''; print ''; diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 514c24db164..16985c511e1 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -449,6 +449,36 @@ if ($massaction == 'replace' && GETPOST('confirmmassaction', 'alpha') && !$searc $massaction = ''; } +if ($action == 'deletetemplate') { + $dirthemes = array('/doctemplates/websites'); + if (!empty($conf->modules_parts['websitetemplates'])) { // Using this feature slow down application + foreach ($conf->modules_parts['websitetemplates'] as $reldir) { + $dirthemes = array_merge($dirthemes, (array) ($reldir.'doctemplates/websites')); + } + } + $dirthemes = array_unique($dirthemes); + + + // Delete template files and dir + $mode = 'importsite'; + $action = 'importsite'; + + if (count($dirthemes)) { + $i = 0; + foreach ($dirthemes as $dir) { + //print $dirroot.$dir;exit; + $dirtheme = DOL_DATA_ROOT.$dir; // This include loop on $conf->file->dol_document_root + if (is_dir($dirtheme)) { + $templateuserfile = GETPOST('templateuserfile'); + $imguserfile = preg_replace('/\.zip$/', '', $templateuserfile).'.jpg'; + dol_delete_file($dirtheme.'/'.$templateuserfile); + dol_delete_file($dirtheme.'/'.$imguserfile); + } + } + } +} + + // Set category if ($massaction == 'setcategory' && GETPOST('confirmmassaction', 'alpha') && $usercanedit) { $error = 0; From fa651f756679d17731fd3195b40df956825cd41f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 9 Oct 2022 17:49:44 +0200 Subject: [PATCH 02/19] Enhance website CMS toolbar --- htdocs/core/class/html.formwebsite.class.php | 11 +- htdocs/langs/en_US/website.lang | 3 +- htdocs/theme/eldy/global.inc.php | 7 +- htdocs/theme/md/style.css.php | 2 +- htdocs/website/class/website.class.php | 8 +- htdocs/website/class/websitepage.class.php | 8 +- htdocs/website/index.php | 110 ++++++++++++------- 7 files changed, 94 insertions(+), 55 deletions(-) diff --git a/htdocs/core/class/html.formwebsite.class.php b/htdocs/core/class/html.formwebsite.class.php index c6a6826251f..ed4b56be831 100644 --- a/htdocs/core/class/html.formwebsite.class.php +++ b/htdocs/core/class/html.formwebsite.class.php @@ -231,6 +231,8 @@ class FormWebsite */ public function selectContainer($website, $htmlname = 'pageid', $pageid = 0, $showempty = 0, $action = '', $morecss = 'minwidth200', $excludeids = null) { + global $conf, $langs; + $this->num = 0; $atleastonepage = (is_array($website->lines) && count($website->lines) > 0); @@ -239,13 +241,18 @@ class FormWebsite if ($atleastonepage && $action != 'editsource') { $out .= ''; + $out .= ''; if (empty($object->records)) { $out .= ''; } + + /* if (!empty($conf->use_javascript_ajax)) { $valueoption = ''.img_picto('', 'add', 'class="paddingrightonly"').$langs->trans("AddWebsite").''; $out .= ''; - } + }*/ + // Loop on each sites $i = 0; foreach ($object->records as $key => $valwebsite) { @@ -2826,6 +2830,10 @@ if (!GETPOST('hide_websitemenu')) { print ''; } + print ''; + + print ''; + if ($websitekey && $websitekey != '-1' && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite')) { print '   '; @@ -2852,10 +2860,15 @@ if (!GETPOST('hide_websitemenu')) { // Delete website if ($website->status == $website::STATUS_VALIDATED) { - print ''; + $disabled = ' disabled="disabled"'; + $title = $langs->trans("WebsiteMustBeDisabled", $langs->transnoentitiesnoconv($website->LibStatut(0, 0))); + $url = '#'; } else { - print ''; + $disabled = ''; + $title = $langs->trans("Delete"); + $url = $_SERVER["PHP_SELF"].'?action=deletesite&token='.newToken().'&website='.urlencode($website->ref); } + print ''.img_picto('', 'delete', 'class=""').''.$langs->trans("Delete").''; // Regenerate all pages print 'ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("RegenerateWebsiteContent")).'">'; @@ -2863,6 +2876,7 @@ if (!GETPOST('hide_websitemenu')) { // Generate site map print 'ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("GenerateSitemaps")).'">'; + // Find / replace tool print 'ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("ReplaceWebsiteContent")).'">'; } @@ -2970,53 +2984,53 @@ if (!GETPOST('hide_websitemenu')) { print ''; print '
'; - print ''; + print '
'; print $langs->trans("PageContainer").': '; - print ''; + print '
'; - print ''; - print 'ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("AddPage")).'">'; + print ''; + print 'ref).'" class=""'.$disabled.' title="'.dol_escape_htmltag($langs->trans("AddPage")).'">'; print ''; //print ''; - if ($action != 'addcontainer') { + //if ($action != 'addcontainer') { $out = ''; - $s = $formwebsite->selectContainer($website, 'pageid', $pageid, 0, $action, 'maxwidth200onsmartphone'); + $s = $formwebsite->selectContainer($website, 'pageid', $pageid, 0, $action, 'minwidth100 maxwidth200onsmartphone'); - if ($formwebsite->num > 0) { - $out .= ''; - $out .= $s; - $out .= ''; + if ($formwebsite->num >= 0) { + $out .= ''; + $out .= $s; + $out .= ''; - $urltocreatenewpage = $_SERVER["PHP_SELF"].'?action=createcontainer&token='.newToken().'&website='.urlencode($website->ref); + $urltocreatenewpage = $_SERVER["PHP_SELF"].'?action=createcontainer&token='.newToken().'&website='.urlencode($website->ref); - if (!empty($conf->use_javascript_ajax)) { - $out .= ''; - } + if (!empty($conf->use_javascript_ajax)) { + $out .= ''; } + } print $out; - } else { + /*} else { print $langs->trans("New"); - } + }*/ print ''; - print ''; + print ''; // Print nav arrows $pagepreviousid = 0; @@ -3240,7 +3254,19 @@ if (!GETPOST('hide_websitemenu')) { print 'ref).'&pageid='.((int) $pageid).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'">'; } print ''; - print ''; + + // Delete + //print ''; + if ($websitepage->status == $websitepage::STATUS_DRAFT || !$atleastonepage) { + $disabled = ' disabled="disabled"'; + $title = $langs->trans("WebpageMustBeDisabled", $langs->transnoentitiesnoconv($websitepage->LibStatut(0, 0))); + $url = '#'; + } else { + $disabled = ''; + $title = ''; + $url = $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&website='.urlencode($website->ref); + } + print ''.img_picto('', 'delete', 'class=""').''.$langs->trans("Delete").''; } } @@ -3881,7 +3907,7 @@ if ($action == 'editmeta' || $action == 'createcontainer') { // Edit properties $pageusermodifid = $objectpage->fk_user_modif; $pageauthoralias = $objectpage->author_alias; $pagestatus = $objectpage->status; - } else { + } else { // $action = 'createcontainer' $type_container = 'page'; $pageurl = ''; $pagealiasalt = ''; @@ -4179,6 +4205,7 @@ if ($action == 'editmeta' || $action == 'createcontainer') { // Edit properties print ''; print ''; + if ($action == 'createcontainer') { print '
'; @@ -4207,7 +4234,10 @@ if ($action == 'editmeta' || $action == 'createcontainer') { // Edit properties $arraygrabimagesinto = array('root'=>$langs->trans("WebsiteRootOfImages"), 'subpage'=>$langs->trans("SubdirOfPage")); print $form->selectarray('grabimagesinto', $arraygrabimagesinto, GETPOSTISSET('grabimagesinto') ? GETPOST('grabimagesinto') : 'root', 0, 0, 0, '', 0, 0, 0, '', '', 1); print '
'; - print ''; + + print ''; + print ''; + print ''; print ''; } From 2053ad8f49efc8febc115b3d71e9f553ec526b85 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 9 Oct 2022 20:52:50 +0200 Subject: [PATCH 03/19] NEW Can switch status of website and page from the website toolbar --- htdocs/core/class/commonobject.class.php | 2 +- htdocs/core/lib/ajax.lib.php | 33 ++-- htdocs/langs/en_US/website.lang | 1 + htdocs/website/index.php | 190 ++++++++++++++--------- 4 files changed, 137 insertions(+), 89 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 8eb357a3908..7224949a70b 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4345,7 +4345,7 @@ abstract class CommonObject } /** - * Set status of an object + * Set status of an object. * * @param int $status Status to set * @param int $elementId Id of element to force (use this->id by default if null) diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 8098fa7a16e..b6ec08da434 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -644,36 +644,41 @@ function ajax_constantonoff($code, $input = array(), $entity = null, $revertonof * This is called when MAIN_DIRECT_STATUS_UPDATE is set and it use tha ajax service objectonoff.php * * @param Object $object Object to set - * @param string $code Name of constant : status or status_buy for product by example + * @param string $code Name of property in object : 'status' or 'status_buy' for product by example * @param string $field Name of database field : 'tosell' or 'tobuy' for product by example * @param string $text_on Text if on * @param string $text_off Text if off * @param array $input Array of type->list of CSS element to switch. Example: array('disabled'=>array(0=>'cssid')) * @param string $morecss More CSS + * @param string $htmlname Name of HTML component. Keep '' or use a different value if you need to use this component several time on same page for same property. * @return string html for button on/off */ -function ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input = array(), $morecss = '') +function ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input = array(), $morecss = '', $htmlname = '') { global $langs; + if (empty($htmlname)) { + $htmlname = $code; + } + $out = ''; - $out .= ''.img_picto($langs->trans($text_off), 'switch_off').''; - $out .= ''.img_picto($langs->trans($text_on), 'switch_on').''; + $out .= ''.img_picto($langs->trans($text_off), 'switch_off').''; + $out .= ''.img_picto($langs->trans($text_on), 'switch_on').''; return $out; } diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index 298f7c6ab51..8644becdd8c 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -152,3 +152,4 @@ NextContainer=Next page/container PreviousContainer=Previous page/container WebsiteMustBeDisabled=The website must have the status "%s" WebpageMustBeDisabled=The web page must have the status "%s" +SetWebsiteOnlineBefore=When website is offline, all pages are offline. Change status of website first. diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 7cf58a81971..55c2b8f31a8 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -420,6 +420,18 @@ if ($action == 'renamefile') { // Must be after include DOL_DOCUMENT_ROOT.'/core $action = 'file_manager'; } +if ($action == 'setwebsiteonline') { + $website->setStatut($website::STATUS_VALIDATED, null, '', 'WEBSITE_MODIFY', 'status'); + + header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('websitepage', 'int')); + exit; +} +if ($action == 'setwebsiteoffline') { + $result = $website->setStatut($website::STATUS_DRAFT, null, '', 'WEBSITE_MODIFY', 'status'); + + header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('websitepage', 'int')); + exit; +} if ($action == 'seteditinline') { dolibarr_set_const($db, 'WEBSITE_EDITINLINE', 1); setEventMessages($langs->trans("FeatureNotYetAvailable"), null, 'warnings'); @@ -478,7 +490,6 @@ if ($action == 'deletetemplate') { } } - // Set category if ($massaction == 'setcategory' && GETPOST('confirmmassaction', 'alpha') && $usercanedit) { $error = 0; @@ -517,7 +528,8 @@ if ($massaction == 'setcategory' && GETPOST('confirmmassaction', 'alpha') && $us // Now we reload list $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters, -1); } -// Set category + +// Del category if ($massaction == 'delcategory' && GETPOST('confirmmassaction', 'alpha') && $usercanedit) { $error = 0; $nbupdate = 0; @@ -2750,6 +2762,11 @@ if (!GETPOST('hide_websitemenu')) { } $atleastonepage = (is_array($array) && count($array) > 0); + $websitepage = new WebSitePage($db); + if ($pageid > 0 && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')) { + $websitepage->fetch($pageid); + } + //var_dump($objectpage);exit; print '
'; @@ -2764,15 +2781,14 @@ if (!GETPOST('hide_websitemenu')) { print $langs->trans("Website").': '; print '
'; + // Button Add new website $urltocreatenewwebsite = $_SERVER["PHP_SELF"].'?action=createsite'; - //if (empty($conf->use_javascript_ajax)) { - print ''; - print ''; - print ''; - //} + print ''; + print ''; + print ''; // List of website - print ''; + print ''; $out = ''; $out .= ''; + print ''; + + // Switch offline/onine + if (!empty($conf->use_javascript_ajax)) { + print ''; + // Do not use ajax, we need a refresh of full page when we change status of a website + //print '
'; + //print ajax_object_onoff($object, 'status', 'status', 'Online', 'Offline', array(), 'valignmiddle', 'statuswebsite'); + //print '
'; + if ($website->status == $website::STATUS_DRAFT) { + $text_off = 'Offline'; + print 'ref).'&websitepage='.((int) $websitepage->id).'">'.img_picto($langs->trans($text_off), 'switch_off').''; + } else { + $text_off = 'Online'; + print 'ref).'&websitepage='.((int) $websitepage->id).'">'.img_picto($langs->trans($text_off), 'switch_on').''; + } + print '
'; + } + + // Refresh / Reload web site (for non javascript browers) + if (empty($conf->use_javascript_ajax)) { + print ''; + print ''; + print ''; } - print '
'; print ''; if ($websitekey && $websitekey != '-1' && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite')) { - print '   '; - - //print ''; - print ''.dol_escape_htmltag($langs->trans("EditCss")).''; + // Edit website properties + print ''.dol_escape_htmltag($langs->trans("EditCss")).''; + // Import web site $importlabel = $langs->trans("ImportSite"); $exportlabel = $langs->trans("ExportSite"); if (!empty($conf->dol_optimize_smallscreen)) { @@ -2853,9 +2883,10 @@ if (!GETPOST('hide_websitemenu')) { print ''; } - //print ''; + // Export web site print ''; + // Clone web site print ''; // Delete website @@ -2988,46 +3019,57 @@ if (!GETPOST('hide_websitemenu')) { print $langs->trans("PageContainer").': '; print '
'; + // Button Add new web page print ''; print 'ref).'" class=""'.$disabled.' title="'.dol_escape_htmltag($langs->trans("AddPage")).'">'; print ''; - //print ''; - //if ($action != 'addcontainer') { - $out = ''; + $out = ''; - $s = $formwebsite->selectContainer($website, 'pageid', $pageid, 0, $action, 'minwidth100 maxwidth200onsmartphone'); + $s = $formwebsite->selectContainer($website, 'pageid', $pageid, 0, $action, 'minwidth100 maxwidth200onsmartphone'); - if ($formwebsite->num >= 0) { - $out .= ''; - $out .= $s; - $out .= ''; + $out .= ''; + $out .= $s; + $out .= ''; - $urltocreatenewpage = $_SERVER["PHP_SELF"].'?action=createcontainer&token='.newToken().'&website='.urlencode($website->ref); + $urltocreatenewpage = $_SERVER["PHP_SELF"].'?action=createcontainer&token='.newToken().'&website='.urlencode($website->ref); - if (!empty($conf->use_javascript_ajax)) { - $out .= ''; - } + if (!empty($conf->use_javascript_ajax)) { + $out .= ''; } - print $out; - /*} else { - print $langs->trans("New"); - }*/ + print $out; + if (!empty($conf->use_javascript_ajax)) { + print ''; + //print '
'; + if ($object->status == $object::STATUS_DRAFT) { // website is off, we do not allow to change status of page + $text_off = 'SetWebsiteOnlineBefore'; + if ($objectpage->status == $objectpage::STATUS_DRAFT) { + print ''.img_picto($langs->trans($text_off), 'switch_off').''; + } else { + print ''.img_picto($langs->trans($text_off), 'switch_on').''; + } + } else { + print ajax_object_onoff($objectpage, 'status', 'status', 'Online', 'Offline', array(), 'valignmiddle', 'statuswebsitepage'); + } + //print '
'; + print '
'; + } + print ''; print ''; @@ -3059,23 +3101,18 @@ if (!GETPOST('hide_websitemenu')) { } if ($pagepreviousid) { - print ''.img_previous($langs->trans("PreviousContainer")).''; + print ''.img_previous($langs->trans("PreviousContainer")).''; } else { print ''.img_previous($langs->trans("PreviousContainer")).''; } if ($pagenextid) { - print ''.img_next($langs->trans("NextContainer")).''; + print ''.img_next($langs->trans("NextContainer")).''; } else { print ''.img_next($langs->trans("NextContainer")).''; } print ''; - $websitepage = new WebSitePage($db); - if ($pageid > 0 && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')) { - $websitepage->fetch($pageid); - } - if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite') { $disabled = ''; if (empty($user->rights->website->write)) { @@ -3153,15 +3190,15 @@ if (!GETPOST('hide_websitemenu')) { print ''; - print '   '; - - //print ''; + // Edit web page properties print ''.dol_escape_htmltag($langs->trans("EditPageMeta")).''; - //print ''; + // Edit HTML content print ''.dol_escape_htmltag($langs->trans($conf->dol_optimize_smallscreen ? "HTML" : "EditHTMLSource")).''; print ''; + + // Switch include dynamic content / edit inline print ''."\n"; print '
'; @@ -3522,13 +3559,16 @@ if ($action == 'editcss') { print ''; // Status of web site - print ''."\n"; - print ''; - print $langs->trans('Status'); - print ''; - print ajax_object_onoff($object, 'status', 'status', 'Enabled', 'Disabled'); - //print dol_print_date($pagedatecreation, 'dayhour'); - print ''; + if ($action != 'createcontainer') { + if (empty($conf->use_javascript_ajax)) { + print ''."\n"; + print ''; + print $langs->trans('Status'); + print ''; + print $form->selectyesno('status', $object->status); + print ''; + } + } // Main language print ''; @@ -3954,13 +3994,14 @@ if ($action == 'editmeta' || $action == 'createcontainer') { // Edit properties } if ($action != 'createcontainer') { - print ''."\n"; - print ''; - print $langs->trans('Status'); - print ''; - print ajax_object_onoff($objectpage, 'status', 'status', 'Enabled', 'Disabled'); - //print dol_print_date($pagedatecreation, 'dayhour'); - print ''; + if (empty($conf->use_javascript_ajax)) { + print ''."\n"; + print ''; + print $langs->trans('Status'); + print ''; + print $form->selectyesno('status', $objectpage->status); + print ''; + } } // Type of container @@ -3971,6 +4012,7 @@ if ($action == 'editmeta' || $action == 'createcontainer') { // Edit properties $formwebsite->selectTypeOfContainer('WEBSITE_TYPE_CONTAINER', (GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha') ? GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha') : $type_container), 0, '', 1); print ''; + // Example/templates of page if ($action == 'createcontainer') { print ''; print $langs->trans('WEBSITE_PAGE_EXAMPLE'); From fca09f7a1a3677919bacc8b8538f112395b4ace2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 10 Oct 2022 01:08:22 +0200 Subject: [PATCH 04/19] Debug v17 --- htdocs/admin/bank_extrafields.php | 9 ++++++--- htdocs/admin/bankline_extrafields.php | 6 ++++-- htdocs/core/lib/bank.lib.php | 4 ++-- htdocs/langs/en_US/banks.lang | 1 - 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/htdocs/admin/bank_extrafields.php b/htdocs/admin/bank_extrafields.php index 3626eec4455..d01ac5a93e9 100644 --- a/htdocs/admin/bank_extrafields.php +++ b/htdocs/admin/bank_extrafields.php @@ -65,18 +65,21 @@ require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php'; * View */ -$textobject = $langs->transnoentitiesnoconv("Bank"); +$help_url = ''; +$page_name = "BankSetupModule"; llxHeader('', $langs->trans("BankSetupModule"), $help_url); $linkback = ''.$langs->trans("BackToModuleList").''; -print load_fiche_titre($langs->trans("BankSetupModule"), $linkback, 'title_setup'); +print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup'); $head = bank_admin_prepare_head(null); -print dol_get_fiche_head($head, 'attributes', $langs->trans("BankSetupModule"), -1, 'account'); +print dol_get_fiche_head($head, 'attributes', $langs->trans($page_name), -1, 'account'); + +$textobject = $langs->transnoentitiesnoconv("Bank"); require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php'; diff --git a/htdocs/admin/bankline_extrafields.php b/htdocs/admin/bankline_extrafields.php index 06f1267343a..7e451275f8d 100644 --- a/htdocs/admin/bankline_extrafields.php +++ b/htdocs/admin/bankline_extrafields.php @@ -22,7 +22,7 @@ */ /** - * \file admin/bankline_extrafields.php + * \file htdocs/admin/bankline_extrafields.php * \ingroup bank * \brief Page to setup extra fields of bankline */ @@ -41,7 +41,7 @@ $form = new Form($db); // List of supported format $tmptype2label = ExtraFields::$type2label; -$type2label = []; +$type2label = array(); foreach ($tmptype2label as $key => $val) { $type2label[$key] = $langs->transnoentitiesnoconv($val); } @@ -80,6 +80,8 @@ $head = bank_admin_prepare_head(null); print dol_get_fiche_head($head, 'bankline_extrafields', $langs->trans($page_name), -1, 'account'); +$textobject = $langs->transnoentitiesnoconv("BankTransaction"); + require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php'; print dol_get_fiche_end(); diff --git a/htdocs/core/lib/bank.lib.php b/htdocs/core/lib/bank.lib.php index 1792de89a60..8920808766a 100644 --- a/htdocs/core/lib/bank.lib.php +++ b/htdocs/core/lib/bank.lib.php @@ -153,12 +153,12 @@ function bank_admin_prepare_head($object) complete_head_from_modules($conf, $langs, $object, $head, $h, 'bank_admin'); $head[$h][0] = DOL_URL_ROOT.'/admin/bank_extrafields.php'; - $head[$h][1] = $langs->trans("ExtraFields"); + $head[$h][1] = $langs->trans("ExtraFields").' ('.$langs->trans("BankAccounts").')'; $head[$h][2] = 'attributes'; $h++; $head[$h][0] = DOL_URL_ROOT.'/admin/bankline_extrafields.php'; - $head[$h][1] = $langs->trans("BanklineExtraFields"); + $head[$h][1] = $langs->trans("ExtraFields").' ('.$langs->trans("BankTransactions").')'; $head[$h][2] = 'bankline_extrafields'; $h++; diff --git a/htdocs/langs/en_US/banks.lang b/htdocs/langs/en_US/banks.lang index 71a80406ae4..10ba859e71f 100644 --- a/htdocs/langs/en_US/banks.lang +++ b/htdocs/langs/en_US/banks.lang @@ -185,4 +185,3 @@ AlreadyOneBankAccount=Already one bank account defined SEPAXMLPlacePaymentTypeInformationInCreditTransfertransactionInformation=SEPA transfer: 'Payment Type' at 'Credit Transfer' level SEPAXMLPlacePaymentTypeInformationInCreditTransfertransactionInformationHelp=When generatin a SEPA XML file for Credit transfers, the section "PaymentTypeInformation" can now be placed inside the "CreditTransferTransactionInformation" section (instead of "Payment" section). We strongly recommend to keep this unchecked to place PaymentTypeInformation at Payment level, as all banks will not necessarily accept it at CreditTransferTransactionInformation level. Contact your bank before placing PaymentTypeInformation at CreditTransferTransactionInformation level. ToCreateRelatedRecordIntoBank=To create missing related bank record -BanklineExtraFields=Bank Line Extrafields From 69c5f5df207f8a7ff01f5c635a3c0d0e6afff580 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 10 Oct 2022 04:23:25 +0200 Subject: [PATCH 05/19] Add language de_LU --- htdocs/langs/en_US/languages.lang | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/langs/en_US/languages.lang b/htdocs/langs/en_US/languages.lang index 4e4b2cfafe7..78378c6c5d3 100644 --- a/htdocs/langs/en_US/languages.lang +++ b/htdocs/langs/en_US/languages.lang @@ -23,6 +23,7 @@ Language_da_DK=Danish Language_de_DE=German Language_de_AT=German (Austria) Language_de_CH=German (Switzerland) +Language_de_LU=German (Luxembourg) Language_el_GR=Greek Language_el_CY=Greek (Cyprus) Language_en_AE=English (United Arab Emirates) From 96117ec52b7080013020adf44b7b4fe234823f06 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 10 Oct 2022 10:01:27 +0200 Subject: [PATCH 06/19] Fix no need to enter creation date when creation job application --- htdocs/langs/en_US/recruitment.lang | 2 +- htdocs/recruitment/class/recruitmentcandidature.class.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/langs/en_US/recruitment.lang b/htdocs/langs/en_US/recruitment.lang index 1f80ecf1082..686722a48c5 100644 --- a/htdocs/langs/en_US/recruitment.lang +++ b/htdocs/langs/en_US/recruitment.lang @@ -66,7 +66,7 @@ ContractRefused=Contract refused RecruitmentCandidature=Application JobPositions=Job positions RecruitmentCandidatures=Applications -InterviewToDo=Interview to do +InterviewToDo=Contacts to follow AnswerCandidature=Application answer YourCandidature=Your application YourCandidatureAnswerMessage=Thanks you for your application.
... diff --git a/htdocs/recruitment/class/recruitmentcandidature.class.php b/htdocs/recruitment/class/recruitmentcandidature.class.php index 5aab9d1b391..2ece5dbe217 100644 --- a/htdocs/recruitment/class/recruitmentcandidature.class.php +++ b/htdocs/recruitment/class/recruitmentcandidature.class.php @@ -127,7 +127,7 @@ class RecruitmentCandidature extends CommonObject 'remuneration_requested' => array('type'=>'integer', 'label'=>'RequestedRemuneration', 'enabled'=>'1', 'position'=>80, 'notnull'=>0, 'visible'=>-1,), 'remuneration_proposed' => array('type'=>'integer', 'label'=>'ProposedRemuneration', 'enabled'=>'1', 'position'=>81, 'notnull'=>0, 'visible'=>-1,), 'description' => array('type'=>'html', 'label'=>'Description', 'enabled'=>'1', 'position'=>300, 'notnull'=>0, 'visible'=>3, 'cssview'=>'wordbreak'), - 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>1, 'csslist'=>'nowraponall'), + 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-4, 'csslist'=>'nowraponall'), 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2, 'csslist'=>'nowraponall'), 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,), 'model_pdf' => array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>'1', 'position'=>1010, 'notnull'=>-1, 'visible'=>0,), From 221b2dc2882ffdea666ca7850dc9a372dbecf9a8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 10 Oct 2022 10:46:46 +0200 Subject: [PATCH 07/19] Standardize code --- htdocs/bom/bom_card.php | 9 +++------ htdocs/modulebuilder/template/myobject_card.php | 9 ++++++--- htdocs/mrp/mo_card.php | 10 +++------- htdocs/product/inventory/card.php | 15 +++++---------- .../stock/stocktransfer/stocktransfer_card.php | 14 ++++---------- .../recruitment/recruitmentcandidature_card.php | 12 ++++-------- .../recruitment/recruitmentjobposition_card.php | 10 +++------- htdocs/workstation/workstation_card.php | 13 ++++--------- 8 files changed, 32 insertions(+), 60 deletions(-) diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 09d2b2bcb9d..926797d1f07 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -704,7 +704,7 @@ if (empty($reshook)) { // Clone if ($permissiontoadd) { - print ''.$langs->trans("ToClone").''."\n"; + print dolGetButtonAction($langs->trans("ToClone"), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&object=bom', 'clone', $permissiontoadd); } // Close / Cancel @@ -726,11 +726,8 @@ if (empty($reshook)) { } */ - if ($permissiontodelete) { - print ''.$langs->trans('Delete').''."\n"; - } else { - print ''.$langs->trans('Delete').''."\n"; - } + // Delete + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete); } print '
'."\n"; } diff --git a/htdocs/modulebuilder/template/myobject_card.php b/htdocs/modulebuilder/template/myobject_card.php index 16a471ac51d..d7d91414788 100644 --- a/htdocs/modulebuilder/template/myobject_card.php +++ b/htdocs/modulebuilder/template/myobject_card.php @@ -535,7 +535,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } // Clone - print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.(!empty($object->socid)?'&socid='.$object->socid:'').'&action=clone&token='.newToken(), '', $permissiontoadd); + if ($permissiontoadd) { + print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.(!empty($object->socid)?'&socid='.$object->socid:'').'&action=clone&token='.newToken(), '', $permissiontoadd); + } /* if ($permissiontoadd) { @@ -554,8 +556,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } */ - // Delete (need delete permission, or if draft, just need create/modify permission) - print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken(), '', $permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd)); + // Delete + $params = array(); + print dolGetButtonAction('', $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete, $params); } print '
'."\n"; } diff --git a/htdocs/mrp/mo_card.php b/htdocs/mrp/mo_card.php index fde5811547a..4142693b172 100644 --- a/htdocs/mrp/mo_card.php +++ b/htdocs/mrp/mo_card.php @@ -678,7 +678,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Clone if ($permissiontoadd) { - print ''.$langs->trans("ToClone").''; + print dolGetButtonAction($langs->trans("ToClone"), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&object=mo', 'clone', $permissiontoadd); } // Cancel - Reopen @@ -703,12 +703,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } } - // Delete (need delete permission, or if draft, just need create/modify permission) - if ($permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd)) { - print ''.$langs->trans('Delete').''."\n"; - } else { - print ''.$langs->trans('Delete').''."\n"; - } + // Delete + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete); } print ''."\n"; } diff --git a/htdocs/product/inventory/card.php b/htdocs/product/inventory/card.php index 6e1bb1e8a2e..fb9803dd23b 100644 --- a/htdocs/product/inventory/card.php +++ b/htdocs/product/inventory/card.php @@ -417,17 +417,12 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } // Clone - /*if ($permissiontoadd) - { - print ''.$langs->trans("ToClone").''."\n"; - }*/ - - // Delete (need delete permission, or if draft, just need create/modify permission) - if ($permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd)) { - print ''.$langs->trans('Delete').''."\n"; - } else { - print ''.$langs->trans('Delete').''."\n"; + if ($permissiontoadd) { + //print dolGetButtonAction($langs->trans("ToClone"), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&object=inventory', 'clone', $permissiontoadd); } + + // Delete + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete); } print ''."\n"; } diff --git a/htdocs/product/stock/stocktransfer/stocktransfer_card.php b/htdocs/product/stock/stocktransfer/stocktransfer_card.php index ce8b045a6cd..54384ae0b3f 100644 --- a/htdocs/product/stock/stocktransfer/stocktransfer_card.php +++ b/htdocs/product/stock/stocktransfer/stocktransfer_card.php @@ -84,7 +84,7 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be includ $permissiontoread = $user->rights->stocktransfer->stocktransfer->read; $permissiontoadd = $user->rights->stocktransfer->stocktransfer->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php $permissionnote = $user->rights->stocktransfer->stocktransfer->write; // Used by the include of actions_setnotes.inc.php -$permissiontodelete = $user->rights->stocktransfer->stocktransfer->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); +$permissiontodelete = $user->rights->stocktransfer->stocktransfer->delete || ($permissiontoadd && isset($object->status) && $object->status < $object::STATUS_TRANSFERED); $permissiondellink = $user->rights->stocktransfer->stocktransfer->write; // Used by the include of actions_dellink.inc.php $upload_dir = $conf->stocktransfer->multidir_output[isset($object->entity) ? $object->entity : 1]; @@ -964,7 +964,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Clone if ($permissiontoadd) { - print ''.$langs->trans("ToClone").''."\n"; + print dolGetButtonAction($langs->trans("ToClone"), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&object=stocktransfer', 'clone', $permissiontoadd); } /* @@ -992,14 +992,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } */ - // Delete (need delete permission, or if draft, just need create/modify permission) - if ($object->status < $object::STATUS_TRANSFERED && $permissiontodelete) { - print ''.$langs->trans('Delete').''."\n"; - } - /*else - { - print ''.$langs->trans('Delete').''."\n"; - }*/ + // Delete + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete); } print ''."\n"; } diff --git a/htdocs/recruitment/recruitmentcandidature_card.php b/htdocs/recruitment/recruitmentcandidature_card.php index b5b32fc26db..4226e016e73 100644 --- a/htdocs/recruitment/recruitmentcandidature_card.php +++ b/htdocs/recruitment/recruitmentcandidature_card.php @@ -526,7 +526,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Back to draft if ($object->status == $object::STATUS_VALIDATED) { if ($permissiontoadd) { - print ''.$langs->trans("SetToDraft").''; + print ''.$langs->trans("SetToDraft").''; } } @@ -565,7 +565,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Clone if ($permissiontoadd) { - print ''.$langs->trans("ToClone").''."\n"; + print dolGetButtonAction($langs->trans("ToClone"), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&object=recruitmentcandidature', 'clone', $permissiontoadd); } // Button to convert into a user @@ -592,12 +592,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } } - // Delete (need delete permission, or if draft, just need create/modify permission) - if ($permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd)) { - print ''.$langs->trans('Delete').''."\n"; - } else { - print ''.$langs->trans('Delete').''."\n"; - } + // Delete + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete); } print ''."\n"; } diff --git a/htdocs/recruitment/recruitmentjobposition_card.php b/htdocs/recruitment/recruitmentjobposition_card.php index a23888fd8a9..88424f1b06d 100644 --- a/htdocs/recruitment/recruitmentjobposition_card.php +++ b/htdocs/recruitment/recruitmentjobposition_card.php @@ -435,7 +435,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Clone if ($permissiontoadd) { - print ''.$langs->trans("ToClone").''."\n"; + print dolGetButtonAction($langs->trans("ToClone"), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&object=recruitmentjobposition', 'clone', $permissiontoadd); } /* @@ -452,12 +452,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } } - // Delete (need delete permission, or if draft, just need create/modify permission) - if ($permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd)) { - print ''.$langs->trans('Delete').''."\n"; - } else { - print ''.$langs->trans('Delete').''."\n"; - } + // Delete + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete); } print ''."\n"; } diff --git a/htdocs/workstation/workstation_card.php b/htdocs/workstation/workstation_card.php index 280478c2977..87ee470dce7 100644 --- a/htdocs/workstation/workstation_card.php +++ b/htdocs/workstation/workstation_card.php @@ -451,10 +451,10 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Clone if ($permissiontoadd) { - print ''.$langs->trans("ToClone").''."\n"; + print dolGetButtonAction($langs->trans("ToClone"), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&object=workstation', 'clone', $permissiontoadd); } - + // Disable / Enable if ($permissiontoadd) { if ($object->status == $object::STATUS_ENABLED) { print ''.$langs->trans("Disable").''."\n"; @@ -463,13 +463,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } } - - // Delete (need delete permission, or if draft, just need create/modify permission) - if ($permissiontodelete) { - print ''.$langs->trans('Delete').''."\n"; - } else { - print ''.$langs->trans('Delete').''."\n"; - } + // Delete + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete); } print ''."\n"; } From ae4f8b23d5945adbbaddf77d7dc71620838a3a88 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 10 Oct 2022 11:39:50 +0200 Subject: [PATCH 08/19] Standardize code for action buttons Delete --- htdocs/accountancy/admin/card.php | 8 +++----- htdocs/accountancy/admin/fiscalyear_card.php | 2 +- .../default/tpl/adherentcard_view.tpl.php | 2 +- htdocs/comm/propal/card.php | 5 +---- htdocs/commande/card.php | 2 +- htdocs/compta/deplacement/card.php | 7 ++----- htdocs/compta/facture/card-rec.php | 6 ++---- htdocs/compta/facture/card.php | 3 +-- htdocs/compta/paiement/card.php | 8 +------- htdocs/compta/paiement/cheque/card.php | 3 ++- htdocs/compta/payment_sc/card.php | 4 ++-- htdocs/compta/payment_vat/card.php | 4 ++-- htdocs/contact/card.php | 2 +- htdocs/contrat/card.php | 12 +++--------- htdocs/don/payment/card.php | 4 ++-- htdocs/ecm/dir_add_card.php | 9 ++++----- htdocs/ecm/dir_card.php | 17 ++--------------- htdocs/ecm/file_card.php | 13 +++---------- htdocs/expensereport/payment/card.php | 5 +++-- htdocs/fichinter/card-rec.php | 8 +++----- htdocs/fichinter/card.php | 6 ++---- htdocs/fourn/facture/card-rec.php | 6 ++---- htdocs/fourn/paiement/card.php | 4 ++-- htdocs/hrm/establishment/card.php | 7 ++++++- htdocs/loan/payment/card.php | 4 ++-- htdocs/opensurvey/card.php | 19 +++++++++++-------- htdocs/product/stock/productlot_card.php | 5 +---- htdocs/projet/card.php | 2 +- htdocs/projet/tasks/task.php | 9 +++++---- htdocs/resource/card.php | 9 ++------- htdocs/salaries/payment_salary/card.php | 4 ++-- htdocs/societe/price.php | 2 +- htdocs/supplier_proposal/card.php | 5 +---- htdocs/webhook/target_card.php | 2 +- htdocs/website/websiteaccount_card.php | 15 +++++++++------ 35 files changed, 88 insertions(+), 135 deletions(-) diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php index 36b9f3a8b93..e70bc39bfd0 100644 --- a/htdocs/accountancy/admin/card.php +++ b/htdocs/accountancy/admin/card.php @@ -426,11 +426,9 @@ if ($action == 'create') { print ''.$langs->trans('Modify').''; } - if ($user->hasRight('accounting', 'chartofaccount')) { - print 'id.'">'.$langs->trans('Delete').''; - } else { - print ''.$langs->trans('Delete').''; - } + // Delete + $permissiontodelete = $user->hasRight('accounting', 'chartofaccount'); + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete); print ''; } diff --git a/htdocs/accountancy/admin/fiscalyear_card.php b/htdocs/accountancy/admin/fiscalyear_card.php index 89ed7b538ba..38330a37e13 100644 --- a/htdocs/accountancy/admin/fiscalyear_card.php +++ b/htdocs/accountancy/admin/fiscalyear_card.php @@ -305,7 +305,7 @@ if ($action == 'create') { print ''.$langs->trans('Modify').''; - // print '' . $langs->trans('Delete') . ''; + //print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete); print ''; } diff --git a/htdocs/adherents/canvas/default/tpl/adherentcard_view.tpl.php b/htdocs/adherents/canvas/default/tpl/adherentcard_view.tpl.php index 4b0eed154c0..14da758457f 100644 --- a/htdocs/adherents/canvas/default/tpl/adherentcard_view.tpl.php +++ b/htdocs/adherents/canvas/default/tpl/adherentcard_view.tpl.php @@ -133,7 +133,7 @@ if (empty($user->socid)) { } if ($user->rights->adherent->supprimer) { - echo ''.$langs->trans('Delete').''; + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$this->control->tpl['id'].'&action=delete&token='.newToken().'&canvas='.$canvas, 'delete', $user->rights->adherent->supprimer); } echo '
'; diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 76cc9b23f27..f835ae3ae29 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -2933,10 +2933,7 @@ if ($action == 'create') { } // Delete - if ($usercandelete) { - print ''.$langs->trans('Delete').''; - } + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $usercandelete); } } diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 9428f76dd8e..2afc01914e0 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -2899,7 +2899,7 @@ if ($action == 'create' && $usercancreate) { // Delete order if ($usercandelete) { if ($numshipping == 0) { - print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, ''); + print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, ''); } else { print dolGetButtonAction($langs->trans('ShippingExist'), $langs->trans('Delete'), 'default', $_SERVER['PHP_SELF']. '#', '', false); } diff --git a/htdocs/compta/deplacement/card.php b/htdocs/compta/deplacement/card.php index f8e5f3ba03b..e7929a12697 100644 --- a/htdocs/compta/deplacement/card.php +++ b/htdocs/compta/deplacement/card.php @@ -492,11 +492,8 @@ if ($action == 'create') { } } - if ($user->rights->deplacement->supprimer) { - print ''.$langs->trans('Delete').''; - } else { - print ''.$langs->trans('Delete').''; - } + $permissiontodelete = $user->rights->deplacement->supprimer; + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete); print ''; } diff --git a/htdocs/compta/facture/card-rec.php b/htdocs/compta/facture/card-rec.php index 33b85f707e9..2a15c74c948 100644 --- a/htdocs/compta/facture/card-rec.php +++ b/htdocs/compta/facture/card-rec.php @@ -1677,10 +1677,8 @@ if ($action == 'create') { } } - //if ($object->statut == Facture::STATUS_DRAFT && $user->rights->facture->supprimer) - if ($user->rights->facture->supprimer) { - print ''; - } + // Delete + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $user->rights->facture->supprimer); print ''; diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index b5e756ebb19..3e3ada6e8cf 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -5744,8 +5744,7 @@ if ($action == 'create') { } print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $deleteHref, '', $enableDelete, $params); } else { - $params['attr']['title'] = $langs->trans('NotAllowed'); - print dolGetButtonAction($langs->trans('Delete'), '', 'delete', '#', '', false, $params); + print dolGetButtonAction($langs->trans('Delete'), '', 'delete', '#', '', false); } } print ''; diff --git a/htdocs/compta/paiement/card.php b/htdocs/compta/paiement/card.php index 89ee368b7d5..58a27c94974 100644 --- a/htdocs/compta/paiement/card.php +++ b/htdocs/compta/paiement/card.php @@ -520,13 +520,7 @@ if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) { } if ($user->socid == 0 && $action == '') { - if ($user->rights->facture->paiement) { - if (!$disable_delete) { - print ''.$langs->trans('Delete').''; - } else { - print ''.$langs->trans('Delete').''; - } - } + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $user->rights->facture->paiement && !$disable_delete); } print ''; diff --git a/htdocs/compta/paiement/cheque/card.php b/htdocs/compta/paiement/cheque/card.php index 7b3eaceab3a..f28ebf2ebcf 100644 --- a/htdocs/compta/paiement/cheque/card.php +++ b/htdocs/compta/paiement/cheque/card.php @@ -82,6 +82,7 @@ $usercanread = $user->rights->banque->cheque; $usercancreate = $user->rights->banque->cheque; $usercandelete = $user->rights->banque->cheque; +$permissiontodelete = $user->rights->banque->cheque; /* @@ -750,7 +751,7 @@ if ($user->socid == 0 && !empty($object->id) && $object->statut == 0 && $user->r } if ($user->socid == 0 && !empty($object->id) && $user->rights->banque->cheque) { - print ''.$langs->trans('Delete').''; + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete); } print ''; diff --git a/htdocs/compta/payment_sc/card.php b/htdocs/compta/payment_sc/card.php index 1d93075bc5b..39bac75ba0c 100644 --- a/htdocs/compta/payment_sc/card.php +++ b/htdocs/compta/payment_sc/card.php @@ -253,9 +253,9 @@ if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) if ($action == '') { if ($user->rights->tax->charges->supprimer) { if (!$disable_delete) { - print ''.$langs->trans('Delete').''; + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1); } else { - print ''.$langs->trans('Delete').''; + print dolGetButtonAction($langs->trans("CantRemovePaymentWithOneInvoicePaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0); } } } diff --git a/htdocs/compta/payment_vat/card.php b/htdocs/compta/payment_vat/card.php index 8beeaa1f229..6089f9dbcb5 100644 --- a/htdocs/compta/payment_vat/card.php +++ b/htdocs/compta/payment_vat/card.php @@ -308,9 +308,9 @@ if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) if ($action == '') { if ($user->rights->tax->charges->supprimer) { if (!$disable_delete) { - print ''.$langs->trans('Delete').''; + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1); } else { - print ''.$langs->trans('Delete').''; + print dolGetButtonAction($langs->trans("CantRemovePaymentVATPaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0); } } } diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index 11aebc8fc29..fbe8b4d0c04 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -1579,7 +1579,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { // Delete if ($user->rights->societe->contact->supprimer) { - print ''.$langs->trans('Delete').''; + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().($backtopage ? '&backtopage='.urlencode($backtopage) : ''), 'delete', $user->rights->societe->contact->supprimer); } } diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 93d33565143..0b8ec8d1ad6 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -97,6 +97,7 @@ $extralabelslines = $extrafields->fetch_name_optionals_label($object->table_elem $permissionnote = $user->rights->contrat->creer; // Used by the include of actions_setnotes.inc.php $permissiondellink = $user->rights->contrat->creer; // Used by the include of actions_dellink.inc.php +$permissiontodelete = ($user->rights->contrat->creer && $object->statut == $object::STATUS_DRAFT) || $user->rights->contrat->supprimer; $error = 0; @@ -2172,15 +2173,8 @@ if ($action == 'create') { print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&token='.newToken(), '', true, $params); } - // On peut supprimer entite si - // - Droit de creer + mode brouillon (erreur creation) - // - Droit de supprimer - if (($user->rights->contrat->creer && $object->statut == $object::STATUS_DRAFT) || $user->rights->contrat->supprimer) { - print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), '', true, $params); - } else { - $params['attr']['title'] = $langs->trans("NotAllowed"); - print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), '', false, $params); - } + // Delete + print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), '', $permissiontodelete, $params); } print ""; diff --git a/htdocs/don/payment/card.php b/htdocs/don/payment/card.php index f5507e5e6c7..19f40bc984e 100644 --- a/htdocs/don/payment/card.php +++ b/htdocs/don/payment/card.php @@ -214,9 +214,9 @@ print '
'; if (empty($action)) { if ($user->rights->don->supprimer) { if (!$disable_delete) { - print ''.$langs->trans('Delete').''; + print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), '', 1); } else { - print ''.$langs->trans('Delete').''; + print dolGetButtonAction($langs->trans("CantRemovePaymentWithOneInvoicePaid"), $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), '', 1); } } } diff --git a/htdocs/ecm/dir_add_card.php b/htdocs/ecm/dir_add_card.php index 01a1cfb63a9..3f20188db56 100644 --- a/htdocs/ecm/dir_add_card.php +++ b/htdocs/ecm/dir_add_card.php @@ -283,11 +283,10 @@ if (empty($action) || $action == 'delete_section') { // Actions buttons print '
'; - if ($user->rights->ecm->setup) { - print ''.$langs->trans('Delete').''; - } else { - print ''.$langs->trans('Delete').''; - } + + // Delete + print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), '', $user->rights->ecm->setup); + print '
'; } diff --git a/htdocs/ecm/dir_card.php b/htdocs/ecm/dir_card.php index c36cebfc80c..42607aa0dab 100644 --- a/htdocs/ecm/dir_card.php +++ b/htdocs/ecm/dir_card.php @@ -464,21 +464,8 @@ if ($action != 'edit' && $action != 'delete' && $action != 'deletefile') { print ''.$langs->trans('ECMAddSection').''; } - //if (count($filearrayall) == 0) - //{ - if ($permtoadd) { - print ''.$langs->trans('Delete').''; - } else { - print ''.$langs->trans('Delete').''; - } - /*} - else - { - if (count($filearray) > 0) - print ''.$langs->trans('Delete').''; - else - print ''.$langs->trans('Delete').''; - }*/ + print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().($module ? '&module='.urlencode($module) : '').'§ion='.urlencode($section).($backtopage ? '&backtopage='.urlencode($backtopage) : ''), '', $permtoadd); + print '
'; } diff --git a/htdocs/ecm/file_card.php b/htdocs/ecm/file_card.php index 1b572e44eb8..8202335fbc3 100644 --- a/htdocs/ecm/file_card.php +++ b/htdocs/ecm/file_card.php @@ -424,16 +424,9 @@ if ($action != 'edit') { if ($user->rights->ecm->setup) { print ''.$langs->trans('Edit').''; } - /* - if ($user->rights->ecm->setup) - { - print ''.$langs->trans('Delete').''; - } - else - { - print ''.$langs->trans('Delete').''; - } - */ + + //print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $user->rights->ecm->setup); + print ''; } diff --git a/htdocs/expensereport/payment/card.php b/htdocs/expensereport/payment/card.php index 316dccd91d8..db6c21e202f 100644 --- a/htdocs/expensereport/payment/card.php +++ b/htdocs/expensereport/payment/card.php @@ -238,12 +238,13 @@ if ($resql) { */ print '
'; +// Delete if ($action == '') { if ($user->rights->expensereport->supprimer) { if (!$disable_delete) { - print ''.$langs->trans('Delete').''; + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1); } else { - print ''.$langs->trans('Delete').''; + print dolGetButtonAction($title_button, $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0); } } } diff --git a/htdocs/fichinter/card-rec.php b/htdocs/fichinter/card-rec.php index 6c07ec6837d..2f82b16e1ad 100644 --- a/htdocs/fichinter/card-rec.php +++ b/htdocs/fichinter/card-rec.php @@ -741,11 +741,9 @@ if ($action == 'create') { print $langs->trans("AddIntervention").'
'; } - if ($user->rights->ficheinter->supprimer) { - print ''; - } + // Delete + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $user->rights->ficheinter->supprimer); + print ''; } else { print $langs->trans("ErrorRecordNotFound"); diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index 8b3868bf195..cef3f737c53 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -104,6 +104,7 @@ $result = restrictedArea($user, 'ficheinter', $id, 'fichinter'); $permissionnote = $user->rights->ficheinter->creer; // Used by the include of actions_setnotes.inc.php $permissiondellink = $user->rights->ficheinter->creer; // Used by the include of actions_dellink.inc.php +$permissiontodelete = (($object->statut == Fichinter::STATUS_DRAFT && $user->rights->ficheinter->creer) || $user->rights->ficheinter->supprimer); /* @@ -1688,10 +1689,7 @@ if ($action == 'create') { } // Delete - if (($object->statut == Fichinter::STATUS_DRAFT && $user->rights->ficheinter->creer) || $user->rights->ficheinter->supprimer) { - print ''; - } + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete); } } } diff --git a/htdocs/fourn/facture/card-rec.php b/htdocs/fourn/facture/card-rec.php index 71ba4f6928a..ead5a5f8ea8 100644 --- a/htdocs/fourn/facture/card-rec.php +++ b/htdocs/fourn/facture/card-rec.php @@ -1621,10 +1621,8 @@ if ($action == 'create') { } } - //if ($object->statut == Facture::STATUS_DRAFT && ($user->rights->fournisseur->facture->supprimer || $user->rights->supplier_invoice->supprimer)) - if (($user->rights->fournisseur->facture->supprimer || $user->rights->supplier_invoice->supprimer)) { - print ''; - } + // Delete + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=ask_deleteinvoice&token='.newToken(), 'delete', ($user->rights->fournisseur->facture->supprimer || $user->rights->supplier_invoice->supprimer)); print ''; diff --git a/htdocs/fourn/paiement/card.php b/htdocs/fourn/paiement/card.php index c7c1297e0e8..a11cf769204 100644 --- a/htdocs/fourn/paiement/card.php +++ b/htdocs/fourn/paiement/card.php @@ -374,9 +374,9 @@ if ($result > 0) { if ($user->socid == 0 && $action == '') { if ($user->rights->fournisseur->facture->supprimer) { if ($allow_delete) { - print ''.$langs->trans('Delete').''; + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1); } else { - print ''.$langs->trans('Delete').''; + print dolGetButtonAction($title_button, $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0); } } } diff --git a/htdocs/hrm/establishment/card.php b/htdocs/hrm/establishment/card.php index f1bddce44e4..8e00473bca2 100644 --- a/htdocs/hrm/establishment/card.php +++ b/htdocs/hrm/establishment/card.php @@ -420,8 +420,13 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea * Action bar */ print '
'; + + // Modify print ''.$langs->trans('Modify').''; - print ''.$langs->trans('Delete').''; + + // Delete + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete); + print '
'; } diff --git a/htdocs/loan/payment/card.php b/htdocs/loan/payment/card.php index 6c302feddac..309e0d99f4a 100644 --- a/htdocs/loan/payment/card.php +++ b/htdocs/loan/payment/card.php @@ -223,9 +223,9 @@ print '
'; if (empty($action) && !empty($user->rights->loan->delete)) { if (!$disable_delete) { - print ''.$langs->trans('Delete').''; + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1); } else { - print ''.$langs->trans('Delete').''; + print dolGetButtonAction($langs->trans("CantRemovePaymentWithOneInvoicePaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0); } } diff --git a/htdocs/opensurvey/card.php b/htdocs/opensurvey/card.php index 2fa2f6d9f31..b243b8c8342 100644 --- a/htdocs/opensurvey/card.php +++ b/htdocs/opensurvey/card.php @@ -61,6 +61,10 @@ $hookmanager->initHooks(array('surveycard', 'globalcard')); $expiredate = dol_mktime(0, 0, 0, GETPOST('expiremonth'), GETPOST('expireday'), GETPOST('expireyear')); +$permissiontoread = $user->rights->opensurvey->read; +$permissiontoadd = $user->rights->opensurvey->write; +// permission delete doesn't exists +$permissiontodelete = $user->rights->opensurvey->write; /* @@ -364,26 +368,25 @@ print ''."\n"; -/* - * Action bar - */ +// Action bar + print '
'; if ($action != 'edit' && $user->rights->opensurvey->write) { - //Modify button + // Modify button print ''.$langs->trans("Modify").''; if ($object->status == Opensurveysondage::STATUS_VALIDATED) { - //Close button + // Close button print ''.$langs->trans("Close").''; } if ($object->status == Opensurveysondage::STATUS_CLOSED) { - //Opened button + // Re-Open print ''.$langs->trans("ReOpen").''; } - //Delete button - print ''.$langs->trans('Delete').''; + // Delete + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?suppressionsondage=1&id='.urlencode($numsondage).'&action=delete&token='.newToken(), 'delete', $permissiontodelete); } print '
'; diff --git a/htdocs/product/stock/productlot_card.php b/htdocs/product/stock/productlot_card.php index 5219897ed61..acf2f526773 100644 --- a/htdocs/product/stock/productlot_card.php +++ b/htdocs/product/stock/productlot_card.php @@ -540,10 +540,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''."\n"; } - if ($user->rights->stock->supprimer) - { - print ''."\n"; - } + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $user->rights->stock->supprimer); */ } diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php index a308476ae50..17d5c042389 100644 --- a/htdocs/projet/card.php +++ b/htdocs/projet/card.php @@ -1401,7 +1401,7 @@ if ($action == 'create' && $user->rights->projet->creer) { // Delete if ($user->rights->projet->supprimer || ($object->statut == Project::STATUS_DRAFT && $user->rights->projet->creer)) { if ($userDelete > 0 || ($object->statut == Project::STATUS_DRAFT && $user->rights->projet->creer)) { - print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, ''); + print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, ''); } else { print dolGetButtonAction($langs->trans('NotOwnerOfProject'), $langs->trans('Delete'), 'default', $_SERVER['PHP_SELF']. '#', '', false); } diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php index ef00a85a0d4..77cd9f09c9e 100644 --- a/htdocs/projet/tasks/task.php +++ b/htdocs/projet/tasks/task.php @@ -674,14 +674,15 @@ if ($id > 0 || !empty($ref)) { } // Delete - if ($user->rights->projet->supprimer) { + $permissiontodelete = $user->hasRight('projet', 'supprimer'); + if ($permissiontodelete) { if (!$object->hasChildren() && !$object->hasTimeSpent()) { - print ''.$langs->trans('Delete').''; + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&withproject='.((int) $withproject), 'delete', $permissiontodelete); } else { - print ''.$langs->trans('Delete').''; + print dolGetButtonAction($langs->trans("TaskHasChild"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&withproject='.((int) $withproject), 'delete', 0); } } else { - print ''.$langs->trans('Delete').''; + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&withproject='.((int) $withproject), 'delete', $permissiontodelete); } print '
'; diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index cf4b4b8e110..1816528b854 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -63,7 +63,7 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be includ $result = restrictedArea($user, 'resource', $object->id, 'resource'); $permissiontoadd = $user->rights->resource->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php - +$permissiontodelete = $user->rights->resource->delete; /* @@ -349,12 +349,7 @@ if ($action == 'create' || $object->fetch($id, $ref) > 0) { } } if ($action != "delete" && $action != "create" && $action != "edit") { - // Delete resource - if ($user->rights->resource->delete) { - print '
'; - print ''.$langs->trans('Delete').''; - print '
'; - } + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete); } } print ''; diff --git a/htdocs/salaries/payment_salary/card.php b/htdocs/salaries/payment_salary/card.php index 2d295a23131..c9f0a151901 100644 --- a/htdocs/salaries/payment_salary/card.php +++ b/htdocs/salaries/payment_salary/card.php @@ -251,9 +251,9 @@ print '
'; if ($action == '') { if ($user->rights->salaries->delete) { if (!$disable_delete) { - print ''.$langs->trans('Delete').''; + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1); } else { - print ''.$langs->trans('Delete').''; + print dolGetButtonAction($langs->trans("CantRemovePaymentSalaryPaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0); } } } diff --git a/htdocs/societe/price.php b/htdocs/societe/price.php index a75a194a0e8..b4e60cf0051 100644 --- a/htdocs/societe/price.php +++ b/htdocs/societe/price.php @@ -158,7 +158,7 @@ if (empty($reshook)) { if ($result < 0) { setEventMessages($prodcustprice->error, $prodcustprice->errors, 'mesgs'); } else { - setEventMessages($langs->trans('Delete'), null, 'errors'); + setEventMessages($langs->trans('RecordDeleted'), null, 'errors'); } $action = ''; } diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php index 49f0fc408ce..76c4784b013 100644 --- a/htdocs/supplier_proposal/card.php +++ b/htdocs/supplier_proposal/card.php @@ -2003,10 +2003,7 @@ if ($action == 'create') { } // Delete - if (($object->statut == SupplierProposal::STATUS_DRAFT && $usercancreate) || $usercandelete) { - print ''; - } + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', ($object->statut == SupplierProposal::STATUS_DRAFT && $usercancreate) || $usercandelete); } } diff --git a/htdocs/webhook/target_card.php b/htdocs/webhook/target_card.php index f7536cc15b0..35e18a9cdbc 100644 --- a/htdocs/webhook/target_card.php +++ b/htdocs/webhook/target_card.php @@ -501,7 +501,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea */ // Delete (need delete permission, or if draft, just need create/modify permission) - print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken(), '', $permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd)); + print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken(), '', $permissiontodelete); } print '
'."\n"; } diff --git a/htdocs/website/websiteaccount_card.php b/htdocs/website/websiteaccount_card.php index 39e6e10e3d7..a9fabffba3c 100644 --- a/htdocs/website/websiteaccount_card.php +++ b/htdocs/website/websiteaccount_card.php @@ -63,19 +63,22 @@ if (empty($action) && empty($id) && empty($ref)) { $action = 'view'; } +// Load object +include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once. + // Security check - Protection if external user //if ($user->socid > 0) accessforbidden(); //if ($user->socid > 0) $socid = $user->socid; //$result = restrictedArea($user, 'website', $id); +if (empty($user->rights->websiteaccount->read)) { + accessforbidden('NotAllowed'); +} // Permissions $permissionnote = $user->rights->websiteaccount->write; // Used by the include of actions_setnotes.inc.php $permissiondellink = $user->rights->websiteaccount->write; // Used by the include of actions_dellink.inc.php $permissiontoadd = $user->rights->websiteaccount->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php - -// Load object -include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once. - +$permissiontodelete = $user->rights->websiteaccount->delete; /* @@ -320,8 +323,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } */ - if ($user->rights->website->delete) { - print ''."\n"; + if ($permissiontodelete) { + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete); } } print ''."\n"; From d9f1435cea9e9f9aa5c5c29b72d9a4156d18d416 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 10 Oct 2022 12:05:03 +0200 Subject: [PATCH 09/19] Fix phpunits --- test/phpunit/CodingPhpTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/phpunit/CodingPhpTest.php b/test/phpunit/CodingPhpTest.php index 6af80a304ae..e0f36279437 100644 --- a/test/phpunit/CodingPhpTest.php +++ b/test/phpunit/CodingPhpTest.php @@ -178,6 +178,9 @@ class CodingPhpTest extends PHPUnit\Framework\TestCase if (preg_match('/\/htdocs\/includes\//', $file['fullname'])) { continue; } + if (preg_match('/\/htdocs\/install\/doctemplates\/websites\//', $file['fullname'])) { + continue; + } if (preg_match('/\/htdocs\/custom\//', $file['fullname'])) { continue; } From b6dbdd675795eb7ff52aff2cfb4a5113554abeca Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 10 Oct 2022 14:23:02 +0200 Subject: [PATCH 10/19] Work on php 8.1 compatibility and adodb removal --- htdocs/bookmarks/bookmarks.lib.php | 2 +- htdocs/core/lib/functions.lib.php | 90 +++++++++++++++++--- htdocs/includes/adodbtime/adodb-time.inc.php | 6 +- test/phpunit/DateLibTest.php | 6 ++ 4 files changed, 89 insertions(+), 15 deletions(-) diff --git a/htdocs/bookmarks/bookmarks.lib.php b/htdocs/bookmarks/bookmarks.lib.php index 797bffa187a..d5258ba26f1 100644 --- a/htdocs/bookmarks/bookmarks.lib.php +++ b/htdocs/bookmarks/bookmarks.lib.php @@ -60,7 +60,7 @@ function printDropdownBookmarksList() if ($sortorder) { $tmpurl .= ($tmpurl ? '&' : '').'sortorder='.urlencode($sortorder); } - if (is_array($_POST)) { + if (!empty($_POST) && is_array($_POST)) { foreach ($_POST as $key => $val) { if ((preg_match('/^search_/', $key) || in_array($key, $authorized_var)) && $val != '' diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index d771c75ba48..61871f8b891 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -2535,8 +2535,8 @@ function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs = if ($tzoutput == 'tzserver') { $to_gmt = false; $offsettzstring = @date_default_timezone_get(); // Example 'Europe/Berlin' or 'Indian/Reunion' - $offsettz = 0; // Timezone offset with server timezone, so 0 - $offsetdst = 0; // Dst offset with server timezone, so 0 + $offsettz = 0; // Timezone offset with server timezone (because to_gmt is false), so 0 + $offsetdst = 0; // Dst offset with server timezone (because to_gmt is false), so 0 } elseif ($tzoutput == 'tzuser' || $tzoutput == 'tzuserrel') { $to_gmt = true; $offsettzstring = (empty($_SESSION['dol_tz_string']) ? 'UTC' : $_SESSION['dol_tz_string']); // Example 'Europe/Berlin' or 'Indian/Reunion' @@ -2546,8 +2546,8 @@ function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs = $user_dt = new DateTime(); $user_dt->setTimezone($user_date_tz); $user_dt->setTimestamp($tzoutput == 'tzuser' ? dol_now() : (int) $time); - $offsettz = $user_dt->getOffset(); - } else { // old method (The 'tzuser' was processed like the 'tzuserrel') + $offsettz = $user_dt->getOffset(); // should include dst ? + } else { // with old method (The 'tzuser' was processed like the 'tzuserrel') $offsettz = (empty($_SESSION['dol_tz']) ? 0 : $_SESSION['dol_tz']) * 60 * 60; // Will not be used anymore $offsetdst = (empty($_SESSION['dol_dst']) ? 0 : $_SESSION['dol_dst']) * 60 * 60; // Will not be used anymore } @@ -2628,6 +2628,8 @@ function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs = $format = str_replace('%A', '__A__', $format); } + $noadodb = getDolGlobalInt('MAIN_NO_ADODB_FOR_DATE'); + //$noadodb = 1; // To force test // Analyze date $reg = array(); @@ -2647,23 +2649,76 @@ function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs = $ssec = (!empty($reg[6]) ? $reg[6] : ''); $time = dol_mktime($shour, $smin, $ssec, $smonth, $sday, $syear, true); - $ret = adodb_strftime($format, $time + $offsettz + $offsetdst, $to_gmt); + if ($noadodb) { + if ($to_gmt) { + $tzo = new DateTimeZone('UTC'); // when to_gmt is true, base for offsettz and offsetdst (so timetouse) is UTC + } else { + $tzo = new DateTimeZone(date_default_timezone_get()); // when to_gmt is false, base for offsettz and offsetdst (so timetouse) is PHP server + } + $dtts = new DateTime(); + $dtts->setTimestamp($time); + $dtts->setTimezone($tzo); + $newformat = str_replace( + array('%Y', '%y', '%m', '%d', '%H', '%M', '%S', 'T', 'Z', '__a__', '__A__', '__b__', '__B__'), + array('Y', 'y', 'm', 'd', 'H', 'i', 's', '__£__', '__$__', '__{__', '__}__', '__[__', '__]__'), + $format); + $ret = $dtts->format($newformat); + $ret = str_replace( + array('__£__', '__$__', '__{__', '__}__', '__[__', '__]__'), + array('T', 'Z', '__a__', '__A__', '__b__', '__B__'), + $ret); + } else { + $ret = adodb_strftime($format, $time + $offsettz + $offsetdst, $to_gmt); + } } else { // Date is a timestamps if ($time < 100000000000) { // Protection against bad date values - $timetouse = $time + $offsettz + $offsetdst; // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring. + $timetouse = $time + $offsettz + $offsetdst; // TODO We could be able to disable use of offsettz and offsetdst to use only offsettzstring. - $ret = adodb_strftime($format, $timetouse, $to_gmt); // If to_gmt = false then adodb_strftime use TZ of server + if ($noadodb) { + if ($to_gmt) { + $tzo = new DateTimeZone('UTC'); // when to_gmt is true, base for offsettz and offsetdst (so timetouse) is UTC + } else { + $tzo = new DateTimeZone(date_default_timezone_get()); // when to_gmt is false, base for offsettz and offsetdst (so timetouse) is PHP server + } + $dtts = new DateTime(); + $dtts->setTimestamp($timetouse); + $dtts->setTimezone($tzo); + $newformat = str_replace( + array('%Y', '%y', '%m', '%d', '%H', '%M', '%S', 'T', 'Z', '__a__', '__A__', '__b__', '__B__'), + array('Y', 'y', 'm', 'd', 'H', 'i', 's', '__£__', '__$__', '__{__', '__}__', '__[__', '__]__'), + $format); + $ret = $dtts->format($newformat); + $ret = str_replace( + array('__£__', '__$__', '__{__', '__}__', '__[__', '__]__'), + array('T', 'Z', '__a__', '__A__', '__b__', '__B__'), + $ret); + } else { + $ret = adodb_strftime($format, $timetouse, $to_gmt); // If to_gmt = false then adodb_strftime use TZ of server + } + //var_dump($ret);exit; } else { $ret = 'Bad value '.$time.' for date'; } } if (preg_match('/__b__/i', $format)) { - $timetouse = $time + $offsettz + $offsetdst; // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring. + $timetouse = $time + $offsettz + $offsetdst; // TODO We could be able to disable use of offsettz and offsetdst to use only offsettzstring. - // Here ret is string in PHP setup language (strftime was used). Now we convert to $outputlangs. - $month = adodb_strftime('%m', $timetouse, $to_gmt); // If to_gmt = false then adodb_strftime use TZ of server + if ($noadodb) { + if ($to_gmt) { + $tzo = new DateTimeZone('UTC'); // when to_gmt is true, base for offsettz and offsetdst (so timetouse) is UTC + } else { + $tzo = new DateTimeZone(date_default_timezone_get()); // when to_gmt is false, base for offsettz and offsetdst (so timetouse) is PHP server + } + $dtts = new DateTime(); + $dtts->setTimestamp($timetouse); + $dtts->setTimezone($tzo); + $month = $dtts->format("m"); + } else { + // After this ret is string in PHP setup language (strftime was used). Now we convert to $outputlangs. + $month = adodb_strftime('%m', $timetouse, $to_gmt); // If to_gmt = false then adodb_strftime use TZ of server + } $month = sprintf("%02d", $month); // $month may be return with format '06' on some installation and '6' on other, so we force it to '06'. if ($encodetooutput) { $monthtext = $outputlangs->transnoentities('Month'.$month); @@ -2682,8 +2737,21 @@ function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs = //print "time=$time offsettz=$offsettz offsetdst=$offsetdst offsettzstring=$offsettzstring"; $timetouse = $time + $offsettz + $offsetdst; // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring. - $w = adodb_strftime('%w', $timetouse, $to_gmt); // If to_gmt = false then adodb_strftime use TZ of server + if ($noadodb) { + if ($to_gmt) { + $tzo = new DateTimeZone('UTC'); + } else { + $tzo = new DateTimeZone(date_default_timezone_get()); + } + $dtts = new DateTime(); + $dtts->setTimestamp($timetouse); + $dtts->setTimezone($tzo); + $w = $dtts->format("w"); + } else { + $w = adodb_strftime('%w', $timetouse, $to_gmt); // If to_gmt = false then adodb_strftime use TZ of server + } $dayweek = $outputlangs->transnoentitiesnoconv('Day'.$w); + $ret = str_replace('__A__', $dayweek, $ret); $ret = str_replace('__a__', dol_substr($dayweek, 0, 3), $ret); } diff --git a/htdocs/includes/adodbtime/adodb-time.inc.php b/htdocs/includes/adodbtime/adodb-time.inc.php index 030196db275..1dfa97929a2 100644 --- a/htdocs/includes/adodbtime/adodb-time.inc.php +++ b/htdocs/includes/adodbtime/adodb-time.inc.php @@ -1,8 +1,8 @@ savlangs; $db=$this->savdb; + // Check %Y-%m-%d %H:%M:%S format + $result=dol_print_date('1970-01-01', '%Y-%m-%d %H:%M:%S', true); // A case for compatibility check + print __METHOD__." result=".$result."\n"; + $this->assertEquals('1970-01-01 00:00:00', $result); + + // Check %Y-%m-%d %H:%M:%S format $result=dol_print_date(0, '%Y-%m-%d %H:%M:%S', true); print __METHOD__." result=".$result."\n"; From f4dc43914d53a483d1df41a638c1244d61d44f1d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 10 Oct 2022 14:46:29 +0200 Subject: [PATCH 11/19] Remove php8.1 warnings --- htdocs/conf/conf.php.example | 1 - htdocs/core/lib/functions.lib.php | 15 +++++++-------- .../debugbar/src/DebugBar/JavascriptRenderer.php | 4 ++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/htdocs/conf/conf.php.example b/htdocs/conf/conf.php.example index 05c29459ee2..1cc028ff137 100644 --- a/htdocs/conf/conf.php.example +++ b/htdocs/conf/conf.php.example @@ -409,7 +409,6 @@ $dolibarr_cron_allow_cli='0'; //################################# // Value to overwrite path to use shared libraries instead of embedded one -//$dolibarr_lib_ADODB_PATH='/usr/share/php/adodb'; //$dolibarr_lib_TCPDF_PATH='/usr/share/php/tcpdf'; //$dolibarr_lib_FPDI_PATH='/usr/share/php/fpdi'; //$dolibarr_lib_FPDF_PATH='/usr/share/php/fpdf'; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 61871f8b891..d145358d62f 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1,7 +1,7 @@ * Copyright (C) 2003 Jean-Louis Bergamo - * Copyright (C) 2004-2018 Laurent Destailleur + * Copyright (C) 2004-2022 Laurent Destailleur * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2004 Christophe Combelles @@ -2628,8 +2628,8 @@ function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs = $format = str_replace('%A', '__A__', $format); } - $noadodb = getDolGlobalInt('MAIN_NO_ADODB_FOR_DATE'); - //$noadodb = 1; // To force test + $useadodb = getDolGlobalInt('MAIN_USE_LEGACY_ADODB_FOR_DATE', 0); + //$useadodb = 1; // To switch to adodb // Analyze date $reg = array(); @@ -2649,7 +2649,7 @@ function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs = $ssec = (!empty($reg[6]) ? $reg[6] : ''); $time = dol_mktime($shour, $smin, $ssec, $smonth, $sday, $syear, true); - if ($noadodb) { + if (empty($useadodb)) { if ($to_gmt) { $tzo = new DateTimeZone('UTC'); // when to_gmt is true, base for offsettz and offsetdst (so timetouse) is UTC } else { @@ -2675,7 +2675,7 @@ function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs = if ($time < 100000000000) { // Protection against bad date values $timetouse = $time + $offsettz + $offsetdst; // TODO We could be able to disable use of offsettz and offsetdst to use only offsettzstring. - if ($noadodb) { + if (empty($useadodb)) { if ($to_gmt) { $tzo = new DateTimeZone('UTC'); // when to_gmt is true, base for offsettz and offsetdst (so timetouse) is UTC } else { @@ -2705,7 +2705,7 @@ function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs = if (preg_match('/__b__/i', $format)) { $timetouse = $time + $offsettz + $offsetdst; // TODO We could be able to disable use of offsettz and offsetdst to use only offsettzstring. - if ($noadodb) { + if (empty($useadodb)) { if ($to_gmt) { $tzo = new DateTimeZone('UTC'); // when to_gmt is true, base for offsettz and offsetdst (so timetouse) is UTC } else { @@ -2737,7 +2737,7 @@ function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs = //print "time=$time offsettz=$offsettz offsetdst=$offsetdst offsettzstring=$offsettzstring"; $timetouse = $time + $offsettz + $offsetdst; // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring. - if ($noadodb) { + if (empty($useadodb)) { if ($to_gmt) { $tzo = new DateTimeZone('UTC'); } else { @@ -2782,7 +2782,6 @@ function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs = */ function dol_getdate($timestamp, $fast = false, $forcetimezone = '') { - //$datetimeobj = new DateTime('@'.$timestamp); $datetimeobj = new DateTime(); $datetimeobj->setTimestamp($timestamp); // Use local PHP server timezone if ($forcetimezone) { diff --git a/htdocs/includes/maximebf/debugbar/src/DebugBar/JavascriptRenderer.php b/htdocs/includes/maximebf/debugbar/src/DebugBar/JavascriptRenderer.php index 16689992c4c..7f7ed84e0dd 100644 --- a/htdocs/includes/maximebf/debugbar/src/DebugBar/JavascriptRenderer.php +++ b/htdocs/includes/maximebf/debugbar/src/DebugBar/JavascriptRenderer.php @@ -762,7 +762,7 @@ class JavascriptRenderer return $uris; } - if (substr($uri, 0, 1) === '/' || preg_match('/^([a-zA-Z]+:\/\/|[a-zA-Z]:\/|[a-zA-Z]:\\\)/', $uri)) { + if ($uri && (substr($uri, 0, 1) === '/' || preg_match('/^([a-zA-Z]+:\/\/|[a-zA-Z]:\/|[a-zA-Z]:\\\)/', $uri))) { return $uri; } return rtrim($root, '/') . "/$uri"; @@ -778,7 +778,7 @@ class JavascriptRenderer protected function filterAssetArray($array, $type = null) { $types = array('css', 'js', 'inline_css', 'inline_js', 'inline_head'); - $typeIndex = array_search(strtolower($type), $types); + $typeIndex = is_null($type) ? false : array_search(strtolower($type), $types); return $typeIndex !== false ? $array[$typeIndex] : $array; } From bc413ee8a91784368816e7f340e58a4070b52cf8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 10 Oct 2022 16:06:19 +0200 Subject: [PATCH 12/19] Fix warnings --- htdocs/contact/list.php | 2 +- htdocs/core/lib/functions.lib.php | 2 +- htdocs/index.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index d165a0a4cc1..572bf85da3f 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -1222,7 +1222,7 @@ while ($i < min($num, $limit)) { if (isModEnabled('socialnetworks')) { foreach ($socialnetworks as $key => $value) { if ($value['active'] && !empty($arrayfields['p.'.$key]['checked'])) { - print ''.dol_print_socialnetworks($arraysocialnetworks[$key], $obj->rowid, $obj->socid, $key, $socialnetworks).''; + print ''.(empty($arraysocialnetworks[$key]) ? '' : dol_print_socialnetworks($arraysocialnetworks[$key], $obj->rowid, $obj->socid, $key, $socialnetworks)).''; if (!$i) { $totalarray['nbfield']++; } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index d145358d62f..bb8e2e3b77b 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3256,7 +3256,7 @@ function dol_print_phone($phone, $countrycode = '', $cid = 0, $socid = 0, $addli global $conf, $user, $langs, $mysoc, $hookmanager; // Clean phone parameter - $phone = preg_replace("/[\s.-]/", "", trim($phone)); + $phone = is_null($phone) ? '' : preg_replace("/[\s.-]/", "", trim($phone)); if (empty($phone)) { return ''; } diff --git a/htdocs/index.php b/htdocs/index.php index 97b82fb93ba..f9ca18f530a 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -558,7 +558,7 @@ if (empty($conf->global->MAIN_DISABLE_GLOBAL_WORKBOARD)) { } $textLateTitle = $langs->trans("NActionsLate", $board->nbtodolate); - $textLateTitle .= ' ('.$langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($board->warning_delay) >= 0 ? '+' : '').ceil($board->warning_delay).' '.$langs->trans("days").')'; + $textLateTitle .= ' ('.$langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil(empty($board->warning_delay) ? 0 : $board->warning_delay) >= 0 ? '+' : '').ceil(empty($board->warning_delay) ? 0 : $board->warning_delay).' '.$langs->trans("days").')'; if ($board->id == 'bank_account') { $textLateTitle .= '
'.$langs->trans("IfYouDontReconcileDisableProperty", $langs->transnoentitiesnoconv("Conciliable")).''; From 201b774d6d2f13a52d77f5a0ea00d3a6cd7cf72e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 10 Oct 2022 20:14:51 +0200 Subject: [PATCH 13/19] Clean code --- htdocs/asset/list.php | 2 +- htdocs/asset/model/list.php | 2 +- htdocs/comm/action/list.php | 2 +- htdocs/compta/facture/list.php | 4 ++-- htdocs/contrat/list.php | 2 +- htdocs/core/actions_massactions.inc.php | 10 ++++++---- htdocs/core/class/stats.class.php | 6 ++++-- htdocs/core/lib/functions.lib.php | 9 +++++++++ htdocs/core/modules/societe/mod_codeclient_monkey.php | 2 +- htdocs/core/tpl/massactions_pre.tpl.php | 2 +- htdocs/fichinter/list.php | 2 +- htdocs/modulebuilder/template/myobject_list.php | 2 +- htdocs/partnership/partnership_list.php | 2 +- htdocs/product/stock/movement_list.php | 2 +- htdocs/product/stock/productlot_list.php | 2 +- htdocs/recruitment/recruitmentcandidature_list.php | 2 +- htdocs/recruitment/recruitmentjobposition_list.php | 2 +- htdocs/societe/list.php | 2 +- htdocs/ticket/list.php | 2 +- htdocs/user/list.php | 2 +- htdocs/webhook/target_list.php | 2 +- 21 files changed, 38 insertions(+), 25 deletions(-) diff --git a/htdocs/asset/list.php b/htdocs/asset/list.php index 45f90101adc..5e00c2d2433 100644 --- a/htdocs/asset/list.php +++ b/htdocs/asset/list.php @@ -307,7 +307,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $nbtotalofrecords++; }*/ /* The fast and low memory method to get and count full list converts the sql into a sql count */ - $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),]+FROM/i', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),]+FROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $resql = $db->query($sqlforcount); $objforcount = $db->fetch_object($resql); $nbtotalofrecords = $objforcount->nbtotalofrecords; diff --git a/htdocs/asset/model/list.php b/htdocs/asset/model/list.php index 1d85a982e5d..aa80b4e5426 100644 --- a/htdocs/asset/model/list.php +++ b/htdocs/asset/model/list.php @@ -307,7 +307,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $nbtotalofrecords = $db->num_rows($result); */ /* The fast and low memory method to get and count full list converts the sql into a sql count */ - $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),]+FROM/i', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),]+FROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $resql = $db->query($sqlforcount); if ($resql) { diff --git a/htdocs/comm/action/list.php b/htdocs/comm/action/list.php index a5aca966530..4532e49b622 100644 --- a/htdocs/comm/action/list.php +++ b/htdocs/comm/action/list.php @@ -573,7 +573,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $nbtotalofrecords++; }*/ /* The fast and low memory method to get and count full list converts the sql into a sql count */ - $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),]+FROM/i', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $resql = $db->query($sqlforcount); $objforcount = $db->fetch_object($resql); $nbtotalofrecords = $objforcount->nbtotalofrecords; diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 1d6dbd9f03b..02517537bdf 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -869,9 +869,9 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { */ /* The fast and low memory method to get and count full list converts the sql into a sql count */ if ($sall || $search_product_category > 0 || $search_user > 0) { - $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(DISTINCT f.rowid) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(DISTINCT f.rowid) as nbtotalofrecords FROM', $sql); } else { - $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(f.rowid) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(f.rowid) as nbtotalofrecords FROM', $sql); $sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid/', '', $sqlforcount); } $sqlforcount = preg_replace('/GROUP BY.*$/', '', $sqlforcount); diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index 8c24c4e65ee..e8267f85d58 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -376,7 +376,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { } } } else { - $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'contratdet as cd ON c.rowid = cd.fk_contrat/', '', $sqlforcount); $sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product/', '', $sqlforcount); $sqlforcount = preg_replace('/AND cp.fk_categorie = '.((int) $search_product_category).'/', '', $sqlforcount); diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index de586e80e9f..9a2eda2df8e 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -41,6 +41,9 @@ if (empty($objectclass) || empty($uploaddir)) { dol_print_error(null, 'include of actions_massactions.inc.php is done but var $objectclass or $uploaddir was not defined'); exit; } +if (empty($massaction)) { + $massaction = ''; +} // For backward compatibility if (!empty($permtoread) && empty($permissiontoread)) { @@ -53,14 +56,13 @@ if (!empty($permtodelete) && empty($permissiontodelete)) { $permissiontodelete = $permtodelete; } - // Mass actions. Controls on number of lines checked. $maxformassaction = (empty($conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS) ? 1000 : $conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS); -if (!empty($massaction) && is_array($toselect) && count($toselect) < 1) { +if ($massaction && is_array($toselect) && count($toselect) < 1) { $error++; setEventMessages($langs->trans("NoRecordSelected"), null, "warnings"); } -if (!$error && is_array($toselect) && count($toselect) > $maxformassaction) { +if (!$error && isset($toselect) && is_array($toselect) && count($toselect) > $maxformassaction) { setEventMessages($langs->trans('TooManyRecordForMassAction', $maxformassaction), null, 'errors'); $error++; } @@ -1564,7 +1566,7 @@ if (!$error && ($massaction == 'increaseholiday' || ($action == 'increaseholiday } } -$parameters['toselect'] = $toselect; +$parameters['toselect'] = (empty($toselect) ? array() : $toselect); $parameters['uploaddir'] = $uploaddir; $parameters['massaction'] = $massaction; $parameters['diroutputmassaction'] = isset($diroutputmassaction) ? $diroutputmassaction : null; diff --git a/htdocs/core/class/stats.class.php b/htdocs/core/class/stats.class.php index 63125fffd9f..990bdaf107e 100644 --- a/htdocs/core/class/stats.class.php +++ b/htdocs/core/class/stats.class.php @@ -103,7 +103,8 @@ abstract class Stats $data[$i][] = $datay[$endyear][($i + $sm) % 12][0]; $year = $startyear; while ($year <= $endyear) { - $data[$i][] = $datay[$year - (1 - ((int) ($i + $sm) / 12)) + ($sm == 0 ? 1 : 0)][($i + $sm) % 12][1]; + // floor(($i + $sm) / 12)) is 0 if we are after the month start $sm and same year, become 1 when we reach january of next year + $data[$i][] = $datay[$year - (1 - floor(($i + $sm) / 12)) + ($sm == 0 ? 1 : 0)][($i + $sm) % 12][1]; $year++; } } @@ -204,7 +205,8 @@ abstract class Stats $data[$i][] = isset($datay[$endyear][($i + $sm) % 12]['label']) ? $datay[$endyear][($i + $sm) % 12]['label'] : $datay[$endyear][($i + $sm) % 12][0]; // set label $year = $startyear; while ($year <= $endyear) { - $data[$i][] = $datay[$year - (1 - ((int) ($i + $sm) / 12)) + ($sm == 0 ? 1 : 0)][($i + $sm) % 12][1]; // set yval for x=i + // floor(($i + $sm) / 12)) is 0 if we are after the month start $sm and same year, become 1 when we reach january of next year + $data[$i][] = $datay[$year - (1 - floor(($i + $sm) / 12)) + ($sm == 0 ? 1 : 0)][($i + $sm) % 12][1]; // set yval for x=i $year++; } } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index bb8e2e3b77b..2a4bbf9f6f3 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5753,6 +5753,11 @@ function price2num($amount, $rounding = '', $option = 0) { global $langs, $conf; + // Clean parameters + if (is_null($amount)) { + $amount = ''; + } + // Round PHP function does not allow number like '1,234.56' nor '1.234,56' nor '1 234,56' // Numbers must be '1234.56' // Decimal delimiter for PHP and database SQL requests must be '.' @@ -6784,6 +6789,10 @@ function picto_required() */ function dol_string_nohtmltag($stringtoclean, $removelinefeed = 1, $pagecodeto = 'UTF-8', $strip_tags = 0, $removedoublespaces = 1) { + if (is_null($stringtoclean)) { + return ''; + } + if ($removelinefeed == 2) { $stringtoclean = preg_replace('/]*>(\n|\r)+/ims', '
', $stringtoclean); } diff --git a/htdocs/core/modules/societe/mod_codeclient_monkey.php b/htdocs/core/modules/societe/mod_codeclient_monkey.php index a7ae44323a1..19a5309a374 100644 --- a/htdocs/core/modules/societe/mod_codeclient_monkey.php +++ b/htdocs/core/modules/societe/mod_codeclient_monkey.php @@ -151,7 +151,7 @@ class mod_codeclient_monkey extends ModeleThirdPartyCode } $date = dol_now(); - $yymm = strftime("%y%m", $date); + $yymm = dol_print_date($date, "%y%m", 'tzuserrel'); if ($max >= (pow(10, 5) - 1)) { $num = $max + 1; // If counter > 99999, we do not format on 5 chars, we take number as it is diff --git a/htdocs/core/tpl/massactions_pre.tpl.php b/htdocs/core/tpl/massactions_pre.tpl.php index 656b5b263aa..8a8222101ee 100644 --- a/htdocs/core/tpl/massactions_pre.tpl.php +++ b/htdocs/core/tpl/massactions_pre.tpl.php @@ -285,7 +285,7 @@ if ($massaction == 'preapproveleave') { // Allow Pre-Mass-Action hook (eg for confirmation dialog) $parameters = array( - 'toselect' => $toselect, + 'toselect' => isset($toselect) ? $toselect : array(), 'uploaddir' => isset($uploaddir) ? $uploaddir : null ); diff --git a/htdocs/fichinter/list.php b/htdocs/fichinter/list.php index 731442695d2..cbaab666767 100644 --- a/htdocs/fichinter/list.php +++ b/htdocs/fichinter/list.php @@ -328,7 +328,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $resql = $db->query($sql); $nbtotalofrecords = $db->num_rows($resql); /* The fast and low memory method to get and count full list converts the sql into a sql count */ - /*$sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + /*$sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $resql = $db->query($sqlforcount); if ($resql) { $objforcount = $db->fetch_object($resql); diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 8ab14a190c1..009b7b7de3a 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -378,7 +378,7 @@ if (empty($conf->global->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('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $resql = $db->query($sqlforcount); if ($resql) { $objforcount = $db->fetch_object($resql); diff --git a/htdocs/partnership/partnership_list.php b/htdocs/partnership/partnership_list.php index bc99655efa3..b2eb15563ed 100644 --- a/htdocs/partnership/partnership_list.php +++ b/htdocs/partnership/partnership_list.php @@ -401,7 +401,7 @@ $sql=preg_replace('/,\s*$/','', $sql); $nbtotalofrecords = ''; if (empty($conf->global->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('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $resql = $db->query($sqlforcount); if ($resql) { $objforcount = $db->fetch_object($resql); diff --git a/htdocs/product/stock/movement_list.php b/htdocs/product/stock/movement_list.php index 7e34931f9a8..171ee79be9d 100644 --- a/htdocs/product/stock/movement_list.php +++ b/htdocs/product/stock/movement_list.php @@ -730,7 +730,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $nbtotalofrecords++; }*/ /* The fast and low memory method to get and count full list converts the sql into a sql count */ - $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),]+FROM/i', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $resql = $db->query($sqlforcount); $objforcount = $db->fetch_object($resql); $nbtotalofrecords = $objforcount->nbtotalofrecords; diff --git a/htdocs/product/stock/productlot_list.php b/htdocs/product/stock/productlot_list.php index c15479b1f4f..8981d1cff56 100644 --- a/htdocs/product/stock/productlot_list.php +++ b/htdocs/product/stock/productlot_list.php @@ -315,7 +315,7 @@ if (empty($conf->global->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('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $resql = $db->query($sqlforcount); if ($resql) { $objforcount = $db->fetch_object($resql); diff --git a/htdocs/recruitment/recruitmentcandidature_list.php b/htdocs/recruitment/recruitmentcandidature_list.php index 34b852574f6..0489d68bffb 100644 --- a/htdocs/recruitment/recruitmentcandidature_list.php +++ b/htdocs/recruitment/recruitmentcandidature_list.php @@ -303,7 +303,7 @@ $sql = preg_replace('/,\s*$/', '', $sql); $nbtotalofrecords = ''; if (empty($conf->global->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('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $resql = $db->query($sqlforcount); if ($resql) { $objforcount = $db->fetch_object($resql); diff --git a/htdocs/recruitment/recruitmentjobposition_list.php b/htdocs/recruitment/recruitmentjobposition_list.php index 5b1bee43e56..b2edac8dd4d 100644 --- a/htdocs/recruitment/recruitmentjobposition_list.php +++ b/htdocs/recruitment/recruitmentjobposition_list.php @@ -300,7 +300,7 @@ if (empty($conf->global->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('/^SELECT[a-z0-9\._\s\(\),]+FROM/i', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); print $sqlforcount; $resql = $db->query($sqlforcount); $objforcount = $db->fetch_object($resql); diff --git a/htdocs/societe/list.php b/htdocs/societe/list.php index 96e22d4d0b7..fbdaff3041a 100644 --- a/htdocs/societe/list.php +++ b/htdocs/societe/list.php @@ -698,7 +698,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { dol_print_error($db); }*/ /* The fast and low memory method to get and count full list converts the sql into a sql count */ - $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $resql = $db->query($sqlforcount); if ($resql) { $objforcount = $db->fetch_object($resql); diff --git a/htdocs/ticket/list.php b/htdocs/ticket/list.php index fd4d7f15f9e..c989d6f1c4d 100644 --- a/htdocs/ticket/list.php +++ b/htdocs/ticket/list.php @@ -452,7 +452,7 @@ $sql .= $hookmanager->resPrint; $nbtotalofrecords = ''; if (empty($conf->global->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('/^SELECT[a-z0-9\._\s\(\),]+FROM/i', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $resql = $db->query($sqlforcount); $objforcount = $db->fetch_object($resql); $nbtotalofrecords = $objforcount->nbtotalofrecords; diff --git a/htdocs/user/list.php b/htdocs/user/list.php index 04f8e5679fd..dfc8fdb3568 100644 --- a/htdocs/user/list.php +++ b/htdocs/user/list.php @@ -470,7 +470,7 @@ if (empty($conf->global->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('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $resql = $db->query($sqlforcount); if ($resql) { $objforcount = $db->fetch_object($resql); diff --git a/htdocs/webhook/target_list.php b/htdocs/webhook/target_list.php index 37f4740b463..5d81bec967f 100644 --- a/htdocs/webhook/target_list.php +++ b/htdocs/webhook/target_list.php @@ -328,7 +328,7 @@ if (empty($conf->global->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('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $resql = $db->query($sqlforcount); $objforcount = $db->fetch_object($resql); $nbtotalofrecords = $objforcount->nbtotalofrecords; From 9660e9f0e08bf88cc9979b9d41fc5055683020a0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 10 Oct 2022 23:08:25 +0200 Subject: [PATCH 14/19] Fix warning --- htdocs/comm/action/card.php | 4 ++-- htdocs/core/lib/functions.lib.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 2c008202348..590d1bafe17 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -1865,7 +1865,7 @@ if ($id > 0) { // Location if (empty($conf->global->AGENDA_DISABLE_LOCATION)) { - print ''.$langs->trans("Location").''; + print ''.$langs->trans("Location").''; } // Status @@ -1997,7 +1997,7 @@ if ($id > 0) { print ''; // Reminders - if ($conf->global->AGENDA_REMINDER_EMAIL || $conf->global->AGENDA_REMINDER_BROWSER) { + if (getDolGlobalString('AGENDA_REMINDER_EMAIL') || getDolGlobalString('AGENDA_REMINDER_BROWSER')) { $filteruserid = $user->id; if ($user->rights->agenda->allactions->read) { $filteruserid = 0; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 2a4bbf9f6f3..b45f6f895b3 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3828,6 +3828,10 @@ function isValidPhone($phone) */ function dol_strlen($string, $stringencoding = 'UTF-8') { + if (is_null($string)) { + return 0; + } + if (function_exists('mb_strlen')) { return mb_strlen($string, $stringencoding); } else { From 00e7623bb4b6791fcd917a8364a92c23ae3013e9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 10 Oct 2022 23:15:06 +0200 Subject: [PATCH 15/19] Fix warnings --- htdocs/core/lib/functions.lib.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index b45f6f895b3..1b421224761 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -7099,6 +7099,10 @@ function dol_nl2br($stringtoencode, $nl2brmode = 0, $forxml = false) */ function dol_htmlentitiesbr($stringtoencode, $nl2brmode = 0, $pagecodefrom = 'UTF-8', $removelasteolbr = 1) { + if (is_null($stringtoencode)) { + return ''; + } + $newstring = $stringtoencode; if (dol_textishtml($stringtoencode)) { // Check if text is already HTML or not $newstring = preg_replace('//i', '
', $newstring); // Replace "
" by "
". It's same and avoid pb with FPDF. @@ -7293,6 +7297,10 @@ function dol_nboflines_bis($text, $maxlinesize = 0, $charset = 'UTF-8') */ function dol_textishtml($msg, $option = 0) { + if (is_null($msg)) { + return false; + } + if ($option == 1) { if (preg_match('/ Date: Mon, 10 Oct 2022 23:18:13 +0200 Subject: [PATCH 16/19] Warning --- htdocs/core/class/html.formmargin.class.php | 6 +++--- htdocs/public/opensurvey/studs.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/html.formmargin.class.php b/htdocs/core/class/html.formmargin.class.php index 38ec91ff143..61737ab00f3 100644 --- a/htdocs/core/class/html.formmargin.class.php +++ b/htdocs/core/class/html.formmargin.class.php @@ -108,7 +108,7 @@ class FormMargin // calcul des marges if (isset($line->fk_remise_except) && isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT)) { // remise - if ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '1') { // remise globale considérée comme produit + if (getDolGlobalString('MARGIN_METHODE_FOR_DISCOUNT') == '1') { // remise globale considérée comme produit $marginInfos['pa_products'] += $pa; $marginInfos['pv_products'] += $pv; $marginInfos['pa_total'] += $pa; @@ -120,7 +120,7 @@ class FormMargin //} //else $marginInfos['margin_on_products'] += $pv - $pa; - } elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2') { // remise globale considérée comme service + } elseif (getDolGlobalString('MARGIN_METHODE_FOR_DISCOUNT') == '2') { // remise globale considérée comme service $marginInfos['pa_services'] += $pa; $marginInfos['pv_services'] += $pv; $marginInfos['pa_total'] += $pa; @@ -130,7 +130,7 @@ class FormMargin // $marginInfos['margin_on_services'] += -1 * (abs($pv) - $pa); //else $marginInfos['margin_on_services'] += $pv - $pa; - } elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '3') { // remise globale prise en compte uniqt sur total + } elseif (getDolGlobalString('MARGIN_METHODE_FOR_DISCOUNT') == '3') { // remise globale prise en compte uniqt sur total $marginInfos['pa_total'] += $pa; $marginInfos['pv_total'] += $pv; } diff --git a/htdocs/public/opensurvey/studs.php b/htdocs/public/opensurvey/studs.php index bd49b6afbe4..f11f8aea918 100644 --- a/htdocs/public/opensurvey/studs.php +++ b/htdocs/public/opensurvey/studs.php @@ -116,9 +116,9 @@ if (GETPOST("boutonp") || GETPOST("boutonp.x") || GETPOST("boutonp_x")) { // bo if (GETPOST('nom', 'alphanohtml')) { $nouveauchoix = ''; for ($i = 0; $i < $nbcolonnes; $i++) { - if (GETPOSTISSET("choix$i") && GETPOST("choix$i") == '1') { + if (GETPOSTISSET("choix".$i) && GETPOST("choix".$i) == '1') { $nouveauchoix .= "1"; - } elseif (GETPOSTISSET("choix$i") && GETPOST("choix$i") == '2') { + } elseif (GETPOSTISSET("choix".$i) && GETPOST("choix".$i) == '2') { $nouveauchoix .= "2"; } else { $nouveauchoix .= "0"; From 1f051493e1595260c38d2653dd6fd42beb3506a8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 10 Oct 2022 23:49:41 +0200 Subject: [PATCH 17/19] Clean code: Replace join on category for filter on categ with EXISTS --- htdocs/product/list.php | 35 +++++++++---------- htdocs/societe/list.php | 76 +++++++++++++++++++++++++++-------------- 2 files changed, 67 insertions(+), 44 deletions(-) diff --git a/htdocs/product/list.php b/htdocs/product/list.php index 3561388709d..6121004fd37 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -439,9 +439,6 @@ if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) { if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_extrafields as ef on (p.rowid = ef.fk_object)"; } -if (!empty($searchCategoryProductList) || !empty($catid)) { - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; // We'll need this table joined to the select in order to filter by categ -} $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; // multilang if (getDolGlobalInt('MAIN_MULTILANGS')) { @@ -506,30 +503,32 @@ if ($catid > 0) { if ($catid == -2) { $sql .= " AND cp.fk_categorie IS NULL"; } -$searchCategoryProductSqlList = array(); -if ($searchCategoryProductOperator == 1) { + +// Search for tag/category ($searchCategoryProductList is an array of ID) +if (!empty($searchCategoryProductList)) { + $searchCategoryProductSqlList = array(); + $listofcategoryid = ''; foreach ($searchCategoryProductList as $searchCategoryProduct) { if (intval($searchCategoryProduct) == -2) { - $searchCategoryProductSqlList[] = "cp.fk_categorie IS NULL"; + $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE p.rowid = ck.fk_product)"; } elseif (intval($searchCategoryProduct) > 0) { - $searchCategoryProductSqlList[] = "cp.fk_categorie = ".$db->escape($searchCategoryProduct); + $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct); } } - if (!empty($searchCategoryProductSqlList)) { - $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")"; + if ($listofcategoryid) { + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE p.rowid = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; } -} else { - foreach ($searchCategoryProductList as $searchCategoryProduct) { - if (intval($searchCategoryProduct) == -2) { - $searchCategoryProductSqlList[] = "cp.fk_categorie IS NULL"; - } elseif (intval($searchCategoryProduct) > 0) { - $searchCategoryProductSqlList[] = "p.rowid IN (SELECT fk_product FROM ".MAIN_DB_PREFIX."categorie_product WHERE fk_categorie = ".((int) $searchCategoryProduct).")"; + if ($searchCategoryProductOperator == 1) { + if (!empty($searchCategoryProductSqlList)) { + $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")"; + } + } else { + if (!empty($searchCategoryProductSqlList)) { + $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")"; } - } - if (!empty($searchCategoryProductSqlList)) { - $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")"; } } + if ($fourn_id > 0) { $sql .= " AND pfp.fk_soc = ".((int) $fourn_id); } diff --git a/htdocs/societe/list.php b/htdocs/societe/list.php index fbdaff3041a..92db68c7744 100644 --- a/htdocs/societe/list.php +++ b/htdocs/societe/list.php @@ -478,13 +478,6 @@ $sql .= " region.code_region as region_code, region.nom as region_name"; if ($search_sale && $search_sale != '-1') { $sql .= ", sc.fk_soc, sc.fk_user"; } -// We'll need these fields in order to filter by categ -if ($search_categ_cus && $search_categ_cus != -1) { - $sql .= ", cc.fk_categorie, cc.fk_soc"; -} -if ($search_categ_sup && $search_categ_sup != -1) { - $sql .= ", cs.fk_categorie, cs.fk_soc"; -} // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { @@ -505,13 +498,6 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_ty $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_effectif as staff on (staff.id = s.fk_effectif)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_regions as region on (region.code_region = state.fk_region)"; -// We'll need this table joined to the select in order to filter by categ -if (!empty($search_categ_cus) && $search_categ_cus != '-1') { - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cc ON s.rowid = cc.fk_soc"; // We'll need this table joined to the select in order to filter by categ -} -if (!empty($search_categ_sup) && $search_categ_sup != '-1') { - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_fournisseur as cs ON s.rowid = cs.fk_soc"; // We'll need this table joined to the select in order to filter by categ -} $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."c_stcomm as st ON s.fk_stcomm = st.id"; // We'll need this table joined to the select in order to filter by sale if ($search_sale == -2) { @@ -540,26 +526,64 @@ if ($search_sale == -2) { } elseif ($search_sale > 0) { $sql .= " AND sc.fk_user = ".((int) $search_sale); } -if ($search_categ_cus > 0) { - $sql .= " AND cc.fk_categorie = ".((int) $search_categ_cus); +$searchCategoryCustomerList = array($search_categ_cus); +$searchCategoryCustomerOperator = 0; +// Search for tag/category ($searchCategoryCustomerList is an array of ID) +if (!empty($searchCategoryCustomerList)) { + $searchCategoryCustomerSqlList = array(); + $listofcategoryid = ''; + foreach ($searchCategoryCustomerList as $searchCategoryCustomer) { + if (intval($searchCategoryCustomer) == -2) { + $searchCategoryCustomerSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc)"; + } elseif (intval($searchCategoryCustomer) > 0) { + $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryCustomer); + } + } + if ($listofcategoryid) { + $searchCategoryCustomerSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; + } + if ($searchCategoryCustomerOperator == 1) { + if (!empty($searchCategoryCustomerSqlList)) { + $sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")"; + } + } else { + if (!empty($searchCategoryCustomerSqlList)) { + $sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")"; + } + } } -if ($search_categ_sup > 0) { - $sql .= " AND cs.fk_categorie = ".((int) $search_categ_sup); +$searchCategorySupplierList = array($search_categ_sup); +$searchCategorySupplierOperator = 0; +// Search for tag/category ($searchCategorySupplierList is an array of ID) +if (!empty($searchCategorySupplierList)) { + $searchCategorySupplierSqlList = array(); + $listofcategoryid = ''; + foreach ($searchCategorySupplierList as $searchCategorySupplier) { + if (intval($searchCategorySupplier) == -2) { + $searchCategorySupplierSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc)"; + } elseif (intval($searchCategorySupplier) > 0) { + $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategorySupplier); + } + } + if ($listofcategoryid) { + $searchCategorySupplierSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; + } + if ($searchCategorySupplierOperator == 1) { + if (!empty($searchCategorySupplierSqlList)) { + $sql .= " AND (".implode(' OR ', $searchCategorySupplierSqlList).")"; + } + } else { + if (!empty($searchCategorySupplierSqlList)) { + $sql .= " AND (".implode(' AND ', $searchCategorySupplierSqlList).")"; + } + } } -if ($search_categ_cus == -2) { - $sql .= " AND cc.fk_categorie IS NULL"; -} -if ($search_categ_sup == -2) { - $sql .= " AND cs.fk_categorie IS NULL"; -} - if ($search_all) { $sql .= natural_search(array_keys($fieldstosearchall), $search_all); } if (strlen($search_cti)) { $sql .= natural_search('s.phone', $search_cti); } - if ($search_id > 0) { $sql .= natural_search("s.rowid", $search_id, 1); } From 5dc48c829484fdd06ca09e6d896688fcf877d1be Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 11 Oct 2022 00:01:31 +0200 Subject: [PATCH 18/19] NEW Replace join on category (for filter on categ) with EXISTS/NOT --- htdocs/contact/list.php | 99 +++++++++++++++++++++++++++++++---------- htdocs/societe/list.php | 4 +- 2 files changed, 77 insertions(+), 26 deletions(-) diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index 572bf85da3f..8f4c59bb2f8 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -399,15 +399,6 @@ if (isset($extrafields->attributes[$object->table_element]['label']) && is_array $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = p.fk_pays"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_stcommcontact as st ON st.id = p.fk_stcommcontact"; -if (!empty($search_categ) && $search_categ != '-1') { - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_contact as cc ON p.rowid = cc.fk_socpeople"; // We need this table joined to the select in order to filter by categ -} -if (!empty($search_categ_thirdparty) && $search_categ_thirdparty != '-1') { - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc"; // We need this table joined to the select in order to filter by categ -} -if (!empty($search_categ_supplier) && $search_categ_supplier != '-1') { - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_fournisseur as cs2 ON s.rowid = cs2.fk_soc"; // We need this table joined to the select in order to filter by categ -} if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; } @@ -437,23 +428,83 @@ if ($search_priv != '0' && $search_priv != '1') { } } -if ($search_categ > 0) { - $sql .= " AND cc.fk_categorie = ".((int) $search_categ); +$searchCategoryContactList = $search_categ ? array($search_categ) : array(); +$searchCategoryContactOperator = 0; +// Search for tag/category ($searchCategoryContactList is an array of ID) +if (!empty($searchCategoryContactList)) { + $searchCategoryContactSqlList = array(); + $listofcategoryid = ''; + foreach ($searchCategoryContactList as $searchCategoryContact) { + if (intval($searchCategoryContact) == -2) { + $searchCategoryContactSqlList[] = "NOT EXISTS (SELECT ck.fk_socpeople FROM ".MAIN_DB_PREFIX."categorie_contact as ck WHERE s.rowid = ck.fk_socpeople)"; + } elseif (intval($searchCategoryContact) > 0) { + $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryContact); + } + } + if ($listofcategoryid) { + $searchCategoryContactSqlList[] = " EXISTS (SELECT ck.fk_socpeople FROM ".MAIN_DB_PREFIX."categorie_contact as ck WHERE s.rowid = ck.fk_socpeople AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; + } + if ($searchCategoryContactOperator == 1) { + if (!empty($searchCategoryContactSqlList)) { + $sql .= " AND (".implode(' OR ', $searchCategoryContactSqlList).")"; + } + } else { + if (!empty($searchCategoryContactSqlList)) { + $sql .= " AND (".implode(' AND ', $searchCategoryContactSqlList).")"; + } + } } -if ($search_categ == -2) { - $sql .= " AND cc.fk_categorie IS NULL"; +$searchCategoryCustomerList = $search_categ_thirdparty ? array($search_categ_thirdparty) : array(); +$searchCategoryCustomerOperator = 0; +// Search for tag/category ($searchCategoryCustomerList is an array of ID) +if (!empty($searchCategoryCustomerList)) { + $searchCategoryCustomerSqlList = array(); + $listofcategoryid = ''; + foreach ($searchCategoryCustomerList as $searchCategoryCustomer) { + if (intval($searchCategoryCustomer) == -2) { + $searchCategoryCustomerSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc)"; + } elseif (intval($searchCategoryCustomer) > 0) { + $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryCustomer); + } + } + if ($listofcategoryid) { + $searchCategoryCustomerSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; + } + if ($searchCategoryCustomerOperator == 1) { + if (!empty($searchCategoryCustomerSqlList)) { + $sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")"; + } + } else { + if (!empty($searchCategoryCustomerSqlList)) { + $sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")"; + } + } } -if ($search_categ_thirdparty > 0) { - $sql .= " AND cs.fk_categorie = ".((int) $search_categ_thirdparty); -} -if ($search_categ_thirdparty == -2) { - $sql .= " AND cs.fk_categorie IS NULL"; -} -if ($search_categ_supplier > 0) { - $sql .= " AND cs2.fk_categorie = ".((int) $search_categ_supplier); -} -if ($search_categ_supplier == -2) { - $sql .= " AND cs2.fk_categorie IS NULL"; +$searchCategorySupplierList = $search_categ_supplier ? array($search_categ_supplier) : array(); +$searchCategorySupplierOperator = 0; +// Search for tag/category ($searchCategorySupplierList is an array of ID) +if (!empty($searchCategorySupplierList)) { + $searchCategorySupplierSqlList = array(); + $listofcategoryid = ''; + foreach ($searchCategorySupplierList as $searchCategorySupplier) { + if (intval($searchCategorySupplier) == -2) { + $searchCategorySupplierSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc)"; + } elseif (intval($searchCategorySupplier) > 0) { + $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategorySupplier); + } + } + if ($listofcategoryid) { + $searchCategorySupplierSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; + } + if ($searchCategorySupplierOperator == 1) { + if (!empty($searchCategorySupplierSqlList)) { + $sql .= " AND (".implode(' OR ', $searchCategorySupplierSqlList).")"; + } + } else { + if (!empty($searchCategorySupplierSqlList)) { + $sql .= " AND (".implode(' AND ', $searchCategorySupplierSqlList).")"; + } + } } if ($sall) { diff --git a/htdocs/societe/list.php b/htdocs/societe/list.php index 92db68c7744..f32317163ad 100644 --- a/htdocs/societe/list.php +++ b/htdocs/societe/list.php @@ -526,7 +526,7 @@ if ($search_sale == -2) { } elseif ($search_sale > 0) { $sql .= " AND sc.fk_user = ".((int) $search_sale); } -$searchCategoryCustomerList = array($search_categ_cus); +$searchCategoryCustomerList = $search_categ_cus ? array($search_categ_cus) : array();; $searchCategoryCustomerOperator = 0; // Search for tag/category ($searchCategoryCustomerList is an array of ID) if (!empty($searchCategoryCustomerList)) { @@ -552,7 +552,7 @@ if (!empty($searchCategoryCustomerList)) { } } } -$searchCategorySupplierList = array($search_categ_sup); +$searchCategorySupplierList = $search_categ_sup ? array($search_categ_sup) : array(); $searchCategorySupplierOperator = 0; // Search for tag/category ($searchCategorySupplierList is an array of ID) if (!empty($searchCategorySupplierList)) { From 584d8b53f698394c903907ababecc80c79756ecb Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 11 Oct 2022 00:22:11 +0200 Subject: [PATCH 19/19] FIX filter in member list --- htdocs/adherents/list.php | 103 ++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 43 deletions(-) diff --git a/htdocs/adherents/list.php b/htdocs/adherents/list.php index 4c80627d70e..74373d95eda 100644 --- a/htdocs/adherents/list.php +++ b/htdocs/adherents/list.php @@ -142,31 +142,31 @@ if ($db->type == 'pgsql') { unset($fieldstosearchall['d.rowid']); } $arrayfields = array( - 'd.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1), - 'd.civility'=>array('label'=>$langs->trans("Civility"), 'checked'=>0), - 'd.lastname'=>array('label'=>$langs->trans("Lastname"), 'checked'=>1), - 'd.firstname'=>array('label'=>$langs->trans("Firstname"), 'checked'=>1), - 'd.gender'=>array('label'=>$langs->trans("Gender"), 'checked'=>0), - 'd.company'=>array('label'=>$langs->trans("Company"), 'checked'=>1), - 'd.login'=>array('label'=>$langs->trans("Login"), 'checked'=>1), - 'd.morphy'=>array('label'=>$langs->trans("MemberNature"), 'checked'=>1), - 't.libelle'=>array('label'=>$langs->trans("Type"), 'checked'=>1), - 'd.email'=>array('label'=>$langs->trans("Email"), 'checked'=>1), - 'd.address'=>array('label'=>$langs->trans("Address"), 'checked'=>0), - 'd.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>0), - 'd.town'=>array('label'=>$langs->trans("Town"), 'checked'=>0), - 'd.phone'=>array('label'=>$langs->trans("Phone"), 'checked'=>0), - 'd.phone_perso'=>array('label'=>$langs->trans("PhonePerso"), 'checked'=>0), - 'd.phone_mobile'=>array('label'=>$langs->trans("PhoneMobile"), 'checked'=>0), - 'state.nom'=>array('label'=>$langs->trans("State"), 'checked'=>0), - 'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0), - /*'d.note_public'=>array('label'=>$langs->trans("NotePublic"), 'checked'=>0), - 'd.note_private'=>array('label'=>$langs->trans("NotePrivate"), 'checked'=>0),*/ - 'd.datefin'=>array('label'=>$langs->trans("EndSubscription"), 'checked'=>1, 'position'=>500), - 'd.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), - 'd.birth'=>array('label'=>$langs->trans("Birthday"), 'checked'=>0, 'position'=>500), - 'd.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500), - 'd.statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000), + 'd.ref'=>array('label'=>"Ref", 'checked'=>1), + 'd.civility'=>array('label'=>"Civility", 'checked'=>0), + 'd.lastname'=>array('label'=>"Lastname", 'checked'=>1), + 'd.firstname'=>array('label'=>"Firstname", 'checked'=>1), + 'd.gender'=>array('label'=>"Gender", 'checked'=>0), + 'd.company'=>array('label'=>"Company", 'checked'=>1), + 'd.login'=>array('label'=>"Login", 'checked'=>1), + 'd.morphy'=>array('label'=>"MemberNature", 'checked'=>1), + 't.libelle'=>array('label'=>"Type", 'checked'=>1), + 'd.email'=>array('label'=>"Email", 'checked'=>1), + 'd.address'=>array('label'=>"Address", 'checked'=>0), + 'd.zip'=>array('label'=>"Zip", 'checked'=>0), + 'd.town'=>array('label'=>"Town", 'checked'=>0), + 'd.phone'=>array('label'=>"Phone", 'checked'=>0), + 'd.phone_perso'=>array('label'=>"PhonePerso", 'checked'=>0), + 'd.phone_mobile'=>array('label'=>"PhoneMobile", 'checked'=>0), + 'state.nom'=>array('label'=>"State", 'checked'=>0), + 'country.code_iso'=>array('label'=>"Country", 'checked'=>0), + /*'d.note_public'=>array('label'=>"NotePublic", 'checked'=>0), + 'd.note_private'=>array('label'=>"NotePrivate", 'checked'=>0),*/ + 'd.datefin'=>array('label'=>"EndSubscription", 'checked'=>1, 'position'=>500), + 'd.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500), + 'd.birth'=>array('label'=>"Birthday", 'checked'=>0, 'position'=>500), + 'd.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500), + 'd.statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000), 'd.import_key'=>array('label'=>"ImportId", 'checked'=>0, 'position'=>1100), ); // Extra fields @@ -350,27 +350,43 @@ $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d"; if (!empty($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (d.rowid = ef.fk_object)"; } -if ((!empty($search_categ) && ($search_categ > 0 || $search_categ == -2)) || !empty($catid)) { - // We need this table joined to the select in order to filter by categ - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_member as cm ON d.rowid = cm.fk_member"; -} $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = d.country)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = d.state_id)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on (s.rowid = d.fk_soc)"; $sql .= ", ".MAIN_DB_PREFIX."adherent_type as t"; $sql .= " WHERE d.fk_adherent_type = t.rowid"; -if ($catid > 0) { - $sql .= " AND cm.fk_categorie = ".((int) $catid); + +if ($catid && empty($search_categ)) { + $search_categ = $catid; } -if ($catid == -2) { - $sql .= " AND cm.fk_categorie IS NULL"; -} -if ($search_categ > 0) { - $sql .= " AND cm.fk_categorie = ".((int) $search_categ); -} -if ($search_categ == -2) { - $sql .= " AND cm.fk_categorie IS NULL"; + +$searchCategoryContactList = $search_categ ? array($search_categ) : array(); +$searchCategoryContactOperator = 0; +// Search for tag/category ($searchCategoryContactList is an array of ID) +if (!empty($searchCategoryContactList)) { + $searchCategoryContactSqlList = array(); + $listofcategoryid = ''; + foreach ($searchCategoryContactList as $searchCategoryContact) { + if (intval($searchCategoryContact) == -2) { + $searchCategoryContactSqlList[] = "NOT EXISTS (SELECT ck.fk_categorie FROM ".MAIN_DB_PREFIX."categorie_member as ck WHERE d.rowid = ck.fk_member)"; + } elseif (intval($searchCategoryContact) > 0) { + $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryContact); + } + } + if ($listofcategoryid) { + $searchCategoryContactSqlList[] = " EXISTS (SELECT ck.fk_categorie FROM ".MAIN_DB_PREFIX."categorie_member as ck WHERE d.rowid = ck.fk_member AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; + } + if ($searchCategoryContactOperator == 1) { + if (!empty($searchCategoryContactSqlList)) { + $sql .= " AND (".implode(' OR ', $searchCategoryContactSqlList).")"; + } + } else { + if (!empty($searchCategoryContactSqlList)) { + $sql .= " AND (".implode(' AND ', $searchCategoryContactSqlList).")"; + } + } } + $sql .= " AND d.entity IN (".getEntity('adherent').")"; if ($sall) { $sql .= natural_search(array_keys($fieldstosearchall), $sall); @@ -391,7 +407,7 @@ if ($search_status != '') { // Peut valoir un nombre ou liste de nombre separes par virgules $sql .= " AND d.statut in (".$db->sanitize($db->escape($search_status)).")"; } -if ($search_morphy != '') { +if ($search_morphy != '' && $search_morphy != '-1') { $sql .= natural_search("d.morphy", $search_morphy); } if ($search_ref) { @@ -670,7 +686,7 @@ $moreforfilter = ''; if (isModEnabled('categorie') && $user->rights->categorie->lire) { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $moreforfilter .= '
'; - $moreforfilter .= img_picto($langs->trans('Categories'), 'category', 'class="pictofixedlength"').$formother->select_categories(Categorie::TYPE_MEMBER, $search_categ, 'search_categ', 1); + $moreforfilter .= img_picto($langs->trans('Categories'), 'category', 'class="pictofixedlength"').$formother->select_categories(Categorie::TYPE_MEMBER, $search_categ, 'search_categ', 1, $langs->trans("MembersCategoriesShort")); $moreforfilter .= '
'; } $parameters = array(); @@ -741,10 +757,11 @@ if (!empty($arrayfields['d.login']['checked'])) { print ''; print ''; } +// Nature if (!empty($arrayfields['d.morphy']['checked'])) { - print ''; + print ''; $arraymorphy = array('mor'=>$langs->trans("Moral"), 'phy'=>$langs->trans("Physical")); - print $form->selectarray('search_morphy', $arraymorphy, $search_morphy, 1); + print $form->selectarray('search_morphy', $arraymorphy, $search_morphy, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth100'); print ''; } if (!empty($arrayfields['t.libelle']['checked'])) {