From 644d83d79913b2072441f49342bfaaf547b9b8e6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 2 Apr 2020 19:42:08 +0200 Subject: [PATCH 01/10] Rename field to avoid confusion --- htdocs/admin/defaultvalues.php | 11 ++++++----- htdocs/langs/en_US/admin.lang | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/htdocs/admin/defaultvalues.php b/htdocs/admin/defaultvalues.php index d6981448ea6..0d9775e0fbd 100644 --- a/htdocs/admin/defaultvalues.php +++ b/htdocs/admin/defaultvalues.php @@ -38,6 +38,7 @@ if (!$user->admin) accessforbidden(); $id = GETPOST('rowid', 'int'); $action = GETPOST('action', 'alpha'); +$optioncss = GETPOST('optionscss', 'alphanohtml'); $mode = GETPOST('mode', 'aZ09') ?GETPOST('mode', 'aZ09') : 'createform'; // 'createform', 'filters', 'sortorder', 'focus' @@ -212,10 +213,10 @@ print "
\n"; if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); -if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss); -if ($defaulturl) $param .= '&defaulturl='.urlencode($defaulturl); -if ($defaultkey) $param .= '&defaultkey='.urlencode($defaultkey); -if ($defaultvalue) $param .= '&defaultvalue='.urlencode($defaultvalue); +if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss); +if ($defaulturl) $param .= '&defaulturl='.urlencode($defaulturl); +if ($defaultkey) $param .= '&defaultkey='.urlencode($defaultkey); +if ($defaultvalue) $param .= '&defaultvalue='.urlencode($defaultvalue); print '
entity) && $debug) ? '?debug=1' : '').'" method="POST">'; @@ -252,7 +253,7 @@ $texthelp = $langs->trans("PageUrlForDefaultValues"); if ($mode == 'createform') $texthelp .= $langs->trans("PageUrlForDefaultValuesCreate", 'societe/card.php', 'societe/card.php?abc=val1&def=val2'); else $texthelp .= $langs->trans("PageUrlForDefaultValuesList", 'societe/list.php', 'societe/list.php?abc=val1&def=val2'); $texthelp .= '

'.$langs->trans("AlsoDefaultValuesAreEffectiveForActionCreate"); -$texturl = $form->textwithpicto($langs->trans("Url"), $texthelp); +$texturl = $form->textwithpicto($langs->trans("RelativeURL"), $texthelp); print_liste_field_titre($texturl, $_SERVER["PHP_SELF"], 'page,param', '', $param, '', $sortfield, $sortorder); // Field $texthelp = $langs->trans("TheKeyIsTheNameOfHtmlField"); diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 3fde658960e..3d774b7afdd 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -221,6 +221,7 @@ DoliPartnersDesc=List of companies providing custom-developed modules or feature WebSiteDesc=External websites for more add-on (non-core) modules... DevelopYourModuleDesc=Some solutions to develop your own module... URL=URL +RelativeURL=Relative URL BoxesAvailable=Widgets available BoxesActivated=Widgets activated ActivateOn=Activate on From 4c8a04cf38a89e204d098914ebfdd5f054d713d1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 2 Apr 2020 21:17:04 +0200 Subject: [PATCH 02/10] Fix phpcs --- htdocs/supplier_proposal/class/supplier_proposal.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index 17ab143b6a7..3c2d68f653d 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -1857,7 +1857,7 @@ class SupplierProposal extends CommonObject public function createPriceFournisseur($product, $user) { global $conf; - + $price=price2num($product->subprice*$product->qty, 'MU'); $qty=price2num($product->qty); $unitPrice = price2num($product->subprice, 'MU'); From 193a10bc39a8c644066fffa1fe497c3f49030fe9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 3 Apr 2020 02:29:10 +0200 Subject: [PATCH 03/10] FIX cloning of emailing when no content selected --- htdocs/comm/mailing/card.php | 4 ++-- htdocs/comm/mailing/class/mailing.class.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index a21ea9d7d0a..e4e4237db05 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -90,13 +90,13 @@ if (empty($reshook)) // Action clone object if ($action == 'confirm_clone' && $confirm == 'yes') { - if (empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"])) + if (! GETPOST("clone_content", 'alpha') && ! GETPOST("clone_receivers", 'alpha')) { setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); } else { - $result = $object->createFromClone($user, $object->id, $_REQUEST["clone_content"], $_REQUEST["clone_receivers"]); + $result = $object->createFromClone($user, $object->id, GETPOST("clone_content", 'alpha'), GETPOST("clone_receivers", 'alpha')); if ($result > 0) { header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); diff --git a/htdocs/comm/mailing/class/mailing.class.php b/htdocs/comm/mailing/class/mailing.class.php index 553c5e79c15..a671db7b7f9 100644 --- a/htdocs/comm/mailing/class/mailing.class.php +++ b/htdocs/comm/mailing/class/mailing.class.php @@ -273,8 +273,8 @@ class Mailing extends CommonObject * * @param User $user User making the clone * @param int $fromid Id of object to clone - * @param int $option1 1=Copy content, 0=Forget content - * @param int $option2 Not used + * @param int $option1 1=Clone content, 0=Forget content + * @param int $option2 1=Clone recipients * @return int New id of clone */ public function createFromClone(User $user, $fromid, $option1, $option2) @@ -305,7 +305,7 @@ class Mailing extends CommonObject $object->bgcolor = ''; $object->bgimage = ''; - $object->email_from = ''; + //$object->email_from = ''; // We do not reset from email because it is a mandatory value $object->email_replyto = ''; $object->email_errorsto = ''; @@ -331,7 +331,7 @@ class Mailing extends CommonObject if (! $error) { - //Clone target + // Clone recipient targets if (!empty($option2)) { require_once DOL_DOCUMENT_ROOT .'/core/modules/mailings/modules_mailings.php'; From 71910b21812e80aa983f156d5fff04c4dd4451dc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 3 Apr 2020 13:01:17 +0200 Subject: [PATCH 04/10] Fix warning --- htdocs/modulebuilder/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 0afcd403406..b67508cf08b 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -2082,7 +2082,7 @@ elseif (! empty($module)) print_liste_field_titre("Condition", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); print "\n"; - if (is_array($dicts)) + if (is_array($dicts) && is_array($dicts['tabname'])) { $i = 0; $maxi = count($dicts['tabname']); From f7b6895dc688006f6d4cedf54858a6a1b0a8a473 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 3 Apr 2020 14:02:37 +0200 Subject: [PATCH 05/10] Fix option to not generate doc in modulebuilder. --- htdocs/core/tpl/card_presend.tpl.php | 1 + htdocs/modulebuilder/index.php | 6 ++++-- htdocs/modulebuilder/template/class/myobject.class.php | 9 ++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/htdocs/core/tpl/card_presend.tpl.php b/htdocs/core/tpl/card_presend.tpl.php index 795483b08ba..37920ed1ebc 100644 --- a/htdocs/core/tpl/card_presend.tpl.php +++ b/htdocs/core/tpl/card_presend.tpl.php @@ -219,6 +219,7 @@ if ($action == 'presend') if (!empty($origin) && !empty($origin_id)) { $element = $subelement = $origin; + $regs = array(); if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) { $element = $regs[1]; $subelement = $regs[2]; diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index b67508cf08b..0827d38a2f7 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -887,8 +887,10 @@ if ($dirins && $action == 'initobject' && $module && $objectname) // Edit the setup file and the card page if (GETPOST('includedocgeneration', 'aZ09')) { - // TODO - // dolReplaceInFile(); + // Replace '$includedocgeneration = 0;' into '$includedocgeneration = 1;' into files + $arrayreplacement = array('$includedocgeneration = 0;', '$includedocgeneration = 1;'); + dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1); + } // Scan for object class files diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index 596e47e12c0..8e1f6a945c9 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -982,6 +982,9 @@ class MyObject extends CommonObject { global $conf, $langs; + $result = 0; + $includedocgeneration = 0; + $langs->load("mymodule@mymodule"); if (!dol_strlen($modele)) { @@ -996,7 +999,11 @@ class MyObject extends CommonObject $modelpath = "core/modules/mymodule/doc/"; - return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); + if ($includedocgeneration) { + $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); + } + + return $result; } /** From a13287e2857d9dcf010a33d978a567b803b41ecf Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 3 Apr 2020 14:56:15 +0200 Subject: [PATCH 06/10] Fix: validate of object is ok even if some fields are missing --- htdocs/core/lib/modulebuilder.lib.php | 6 +-- htdocs/modulebuilder/index.php | 53 ++++++++++++++++--- .../template/class/myobject.class.php | 6 +-- .../modulebuilder/template/myobject_card.php | 2 - 4 files changed, 53 insertions(+), 14 deletions(-) diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index fe5d707b10a..6ea1d949833 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -127,10 +127,10 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = { $i++; $texttoinsert .= "\t\t'".$key."' => array('type'=>'".$val['type']."', 'label'=>'".$val['label']."',"; - $texttoinsert .= " 'enabled'=>".($val['enabled'] != '' ? $val['enabled'] : 1).","; - $texttoinsert .= " 'position'=>".($val['position'] != '' ? $val['position'] : 50).","; + $texttoinsert .= " 'enabled'=>".($val['enabled'] !== '' ? $val['enabled'] : 1).","; + $texttoinsert .= " 'position'=>".($val['position'] !== '' ? $val['position'] : 50).","; $texttoinsert .= " 'notnull'=>".(empty($val['notnull']) ? 0 : $val['notnull']).","; - $texttoinsert .= " 'visible'=>".($val['visible'] != '' ? $val['visible'] : -1).","; + $texttoinsert .= " 'visible'=>".($val['visible'] !== '' ? $val['visible'] : -1).","; if ($val['noteditable']) $texttoinsert .= " 'noteditable'=>'".$val['noteditable']."',"; if ($val['default']) $texttoinsert .= " 'default'=>'".$val['default']."',"; if ($val['index']) $texttoinsert .= " 'index'=>".$val['index'].","; diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 0827d38a2f7..16684fc36e4 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -92,6 +92,7 @@ if (empty($newmask)) // This should no happen $result = restrictedArea($user, 'modulebuilder', null); +$error = 0; /* @@ -782,6 +783,8 @@ if ($dirins && $action == 'initobject' && $module && GETPOST('createtablearray', if ($dirins && $action == 'initobject' && $module && $objectname) { + $objectname = ucfirst($objectname); + if (preg_match('/[^a-z0-9_]/i', $objectname)) { $error++; @@ -890,7 +893,6 @@ if ($dirins && $action == 'initobject' && $module && $objectname) // Replace '$includedocgeneration = 0;' into '$includedocgeneration = 1;' into files $arrayreplacement = array('$includedocgeneration = 0;', '$includedocgeneration = 1;'); dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1); - } // Scan for object class files @@ -1711,6 +1713,44 @@ elseif (! empty($module)) $linktoenabledisable.=''; $linktoenabledisable.=img_picto($langs->trans("Activated"), 'switch_on', '', false, 0, 0, '', '', 1); $linktoenabledisable.=''; + + $objMod = $moduleobj; + $backtourlparam = ''; + $backtourlparam .= ($backtourlparam ? '&' : '?').'module='.$module; // No urlencode here, done later + if ($tab) $backtourlparam .= ($backtourlparam ? '&' : '?').'tab='.$tab; // No urlencode here, done later + $backtourl = $_SERVER["PHP_SELF"].$backtourlparam; + + $regs = array(); + if (is_array($objMod->config_page_url)) + { + $i = 0; + foreach ($objMod->config_page_url as $page) + { + $urlpage = $page; + if ($i++) + { + $linktoenabledisable .= ' '.img_picto(ucfirst($page), "setup").''; + // print ''.ucfirst($page).' '; + } + else + { + if (preg_match('/^([^@]+)@([^@]+)$/i', $urlpage, $regs)) + { + $urltouse = dol_buildpath('/'.$regs[2].'/admin/'.$regs[1], 1); + $linktoenabledisable .= '   '.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 6px"').''; + } + else + { + $urltouse = $urlpage; + $linktoenabledisable .= '   '.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 6px"').''; + } + } + } + } + elseif (preg_match('/^([^@]+)@([^@]+)$/i', $objMod->config_page_url, $regs)) + { + $linktoenabledisable .= '   '.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 6px"').''; + } } else { @@ -1718,6 +1758,7 @@ elseif (! empty($module)) $linktoenabledisable.=img_picto($langs->trans("Disabled"), 'switch_off', '', false, 0, 0, '', '', 1); $linktoenabledisable.="\n"; } + if (empty($conf->$modulelowercase->enabled)) { $modulestatusinfo=$form->textwithpicto($langs->trans("ModuleIsNotActive", $urltomodulesetup), '', -1, 'help'); @@ -1747,16 +1788,16 @@ elseif (! empty($module)) $head2[$h][2] = 'objects'; $h++; - $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=menus&module='.$module.($forceddirread?'@'.$dirread:''); - $head2[$h][1] = $langs->trans("Menus"); - $head2[$h][2] = 'menus'; - $h++; - $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=permissions&module='.$module.($forceddirread?'@'.$dirread:''); $head2[$h][1] = $langs->trans("Permissions"); $head2[$h][2] = 'permissions'; $h++; + $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=menus&module='.$module.($forceddirread?'@'.$dirread:''); + $head2[$h][1] = $langs->trans("Menus"); + $head2[$h][2] = 'menus'; + $h++; + $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=hooks&module='.$module.($forceddirread?'@'.$dirread:''); $head2[$h][1] = $langs->trans("Hooks"); $head2[$h][2] = 'hooks'; diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index 8e1f6a945c9..3dbb2b3b233 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -554,9 +554,9 @@ class MyObject extends CommonObject // Validate $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; $sql .= " SET ref = '".$this->db->escape($num)."',"; - $sql .= " status = ".self::STATUS_VALIDATED.","; - $sql .= " date_validation = '".$this->db->idate($now)."',"; - $sql .= " fk_user_valid = ".$user->id; + $sql .= " status = ".self::STATUS_VALIDATED; + if (! empty($this->fields['date_validation'])) $sql .= ", date_validation = '".$this->db->idate($now)."',"; + if (! empty($this->fields['fk_user_valid'])) $sql .= ", fk_user_valid = ".$user->id; $sql .= " WHERE rowid = ".$this->id; dol_syslog(get_class($this)."::validate()", LOG_DEBUG); diff --git a/htdocs/modulebuilder/template/myobject_card.php b/htdocs/modulebuilder/template/myobject_card.php index 93eb7560aaa..ca2516eddb6 100644 --- a/htdocs/modulebuilder/template/myobject_card.php +++ b/htdocs/modulebuilder/template/myobject_card.php @@ -581,7 +581,6 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } //Select mail models is same action as presend - /* if (GETPOST('modelselected')) $action = 'presend'; // Presend form @@ -591,7 +590,6 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $trackid = 'myobject'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; - */ } // End of page From d7e4e5f18cb20b0966e70c246f33dace82a914e8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 3 Apr 2020 15:14:59 +0200 Subject: [PATCH 07/10] Fix modulebuilder clone message --- htdocs/langs/en_US/main.lang | 1 + htdocs/modulebuilder/index.php | 11 +++++++++-- htdocs/modulebuilder/template/myobject_card.php | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 8f8480a03cb..31e0d5a1c8d 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -174,6 +174,7 @@ SaveAndStay=Save and stay SaveAndNew=Save and new TestConnection=Test connection ToClone=Clone +ConfirmCloneAsk=Are you sure you want to clone the object %s? ConfirmClone=Choose data you want to clone: NoCloneOptionsSpecified=No data to clone defined. Of=of diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 16684fc36e4..65f6f4b3643 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -791,6 +791,12 @@ if ($dirins && $action == 'initobject' && $module && $objectname) setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors'); $tabobj = 'newobject'; } + if (class_exists($objectname)) { + // TODO Add a more efficient detection. Scan disk ? + $error++; + setEventMessages($langs->trans("AnObjectWithThisClassNameAlreadyExists"), null, 'errors'); + $tabobj = 'newobject'; + } $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template'; $destdir = $dirins.'/'.strtolower($module); @@ -891,7 +897,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname) // Edit the setup file and the card page if (GETPOST('includedocgeneration', 'aZ09')) { // Replace '$includedocgeneration = 0;' into '$includedocgeneration = 1;' into files - $arrayreplacement = array('$includedocgeneration = 0;', '$includedocgeneration = 1;'); + $arrayreplacement = array('/\$includedocgeneration = 0;/' => '$includedocgeneration = 1;'); dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1); } @@ -2609,6 +2615,7 @@ elseif (! empty($module)) print ''; print ''; + // List of existing properties foreach ($properties as $propkey => $propval) { /* If from Reflection @@ -2680,7 +2687,7 @@ elseif (! empty($module)) print $propenabled?$propenabled:''; print ''; print ''; - print $propvisible?$propvisible:''; + print $propvisible?$propvisible:'0'; print ''; print ''; print $propnoteditable?$propnoteditable:''; diff --git a/htdocs/modulebuilder/template/myobject_card.php b/htdocs/modulebuilder/template/myobject_card.php index ca2516eddb6..97adff0558f 100644 --- a/htdocs/modulebuilder/template/myobject_card.php +++ b/htdocs/modulebuilder/template/myobject_card.php @@ -290,7 +290,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if ($action == 'clone') { // Create an array for form $formquestion = array(); - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneMyObject', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); } // Confirmation of action xxxx From e9bddf5c26783612fef9ea78259036e0d69c7dda Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 3 Apr 2020 15:36:41 +0200 Subject: [PATCH 08/10] Fix enable/disable of module --- htdocs/modulebuilder/index.php | 163 +++++++++++++++++---------------- 1 file changed, 86 insertions(+), 77 deletions(-) diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 65f6f4b3643..313eb65e727 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -1647,12 +1647,90 @@ $head[$h][1] = ''.$langs->trans("New $head[$h][2] = 'initmodule'; $h++; -foreach ($listofmodules as $tmpmodule => $tmpmodulearray) -{ - $head[$h][0] = $_SERVER["PHP_SELF"].'?module='.$tmpmodulearray['modulenamewithcase'].($forceddirread ? '@'.$dirread : ''); - $head[$h][1] = $tmpmodulearray['modulenamewithcase']; - $head[$h][2] = $tmpmodulearray['modulenamewithcase']; - $h++; +$linktoenabledisable = ''; +$modulestatusinfo = ''; + +if (is_array($listofmodules) && count($listofmodules) > 0) { + // Define $linktoenabledisable and $modulestatusinfo + $modulelowercase=strtolower($module); + $const_name = 'MAIN_MODULE_'.strtoupper($module); + + $param=''; + if ($tab) $param.='&tab='.urlencode($tab); + if ($module) $param.='&module='.urlencode($module); + if ($tabobj) $param.='&tabobj='.urlencode($tabobj); + + $urltomodulesetup=''.$langs->trans('Home').'-'.$langs->trans("Setup").'-'.$langs->trans("Modules").''; + if (! empty($conf->global->$const_name)) // If module is already activated + { + $linktoenabledisable.=''; + $linktoenabledisable.=img_picto($langs->trans("Activated"), 'switch_on', '', false, 0, 0, '', '', 1); + $linktoenabledisable.=''; + + $objMod = $moduleobj; + $backtourlparam = ''; + $backtourlparam .= ($backtourlparam ? '&' : '?').'module='.$module; // No urlencode here, done later + if ($tab) $backtourlparam .= ($backtourlparam ? '&' : '?').'tab='.$tab; // No urlencode here, done later + $backtourl = $_SERVER["PHP_SELF"].$backtourlparam; + + $regs = array(); + if (is_array($objMod->config_page_url)) + { + $i = 0; + foreach ($objMod->config_page_url as $page) + { + $urlpage = $page; + if ($i++) + { + $linktoenabledisable .= ' '.img_picto(ucfirst($page), "setup").''; + // print ''.ucfirst($page).' '; + } + else + { + if (preg_match('/^([^@]+)@([^@]+)$/i', $urlpage, $regs)) + { + $urltouse = dol_buildpath('/'.$regs[2].'/admin/'.$regs[1], 1); + $linktoenabledisable .= '   '.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 6px"').''; + } + else + { + $urltouse = $urlpage; + $linktoenabledisable .= '   '.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 6px"').''; + } + } + } + } + elseif (preg_match('/^([^@]+)@([^@]+)$/i', $objMod->config_page_url, $regs)) + { + $linktoenabledisable .= '   '.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 6px"').''; + } + } + else + { + $linktoenabledisable.=''; + $linktoenabledisable.=img_picto($langs->trans("ModuleIsNotActive", $urltomodulesetup), 'switch_off', '', false, 0, 0, '', 'classfortooltip', 1); + $linktoenabledisable.="\n"; + } + + if (! empty($conf->$modulelowercase->enabled)) + { + $modulestatusinfo=$form->textwithpicto('', $langs->trans("Warning").' : '.$langs->trans("ModuleIsLive"), -1, 'warning'); + } + + // Loop to show tab of each module + foreach ($listofmodules as $tmpmodule => $tmpmodulearray) + { + $head[$h][0] = $_SERVER["PHP_SELF"].'?module='.$tmpmodulearray['modulenamewithcase'].($forceddirread ? '@'.$dirread : ''); + $head[$h][1] = $tmpmodulearray['modulenamewithcase']; + $head[$h][2] = $tmpmodulearray['modulenamewithcase']; + + /*if ($tmpmodule == $modulelowercase) { + $head[$h][1] .= ' '.$modulestatusinfo; + $head[$h][1] .= ' '.$linktoenabledisable; + }*/ + + $h++; + } } $head[$h][0] = $_SERVER["PHP_SELF"].'?module=deletemodule'; @@ -1704,75 +1782,6 @@ elseif (! empty($module)) $head2 = array(); $h=0; - $modulelowercase=strtolower($module); - $const_name = 'MAIN_MODULE_'.strtoupper($module); - - $param=''; - if ($tab) $param.='&tab='.urlencode($tab); - if ($module) $param.='&module='.urlencode($module); - if ($tabobj) $param.='&tabobj='.urlencode($tabobj); - - $urltomodulesetup=''.$langs->trans('Home').'-'.$langs->trans("Setup").'-'.$langs->trans("Modules").''; - $linktoenabledisable=''; - if (! empty($conf->global->$const_name)) // If module is already activated - { - $linktoenabledisable.=''; - $linktoenabledisable.=img_picto($langs->trans("Activated"), 'switch_on', '', false, 0, 0, '', '', 1); - $linktoenabledisable.=''; - - $objMod = $moduleobj; - $backtourlparam = ''; - $backtourlparam .= ($backtourlparam ? '&' : '?').'module='.$module; // No urlencode here, done later - if ($tab) $backtourlparam .= ($backtourlparam ? '&' : '?').'tab='.$tab; // No urlencode here, done later - $backtourl = $_SERVER["PHP_SELF"].$backtourlparam; - - $regs = array(); - if (is_array($objMod->config_page_url)) - { - $i = 0; - foreach ($objMod->config_page_url as $page) - { - $urlpage = $page; - if ($i++) - { - $linktoenabledisable .= ' '.img_picto(ucfirst($page), "setup").''; - // print ''.ucfirst($page).' '; - } - else - { - if (preg_match('/^([^@]+)@([^@]+)$/i', $urlpage, $regs)) - { - $urltouse = dol_buildpath('/'.$regs[2].'/admin/'.$regs[1], 1); - $linktoenabledisable .= '   '.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 6px"').''; - } - else - { - $urltouse = $urlpage; - $linktoenabledisable .= '   '.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 6px"').''; - } - } - } - } - elseif (preg_match('/^([^@]+)@([^@]+)$/i', $objMod->config_page_url, $regs)) - { - $linktoenabledisable .= '   '.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 6px"').''; - } - } - else - { - $linktoenabledisable.=''; - $linktoenabledisable.=img_picto($langs->trans("Disabled"), 'switch_off', '', false, 0, 0, '', '', 1); - $linktoenabledisable.="\n"; - } - - if (empty($conf->$modulelowercase->enabled)) - { - $modulestatusinfo=$form->textwithpicto($langs->trans("ModuleIsNotActive", $urltomodulesetup), '', -1, 'help'); - } - else - { - $modulestatusinfo=$form->textwithpicto($langs->trans("ModuleIsLive"), $langs->trans("Warning"), -1, 'warning'); - } $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=description&module='.$module.($forceddirread?'@'.$dirread:''); $head2[$h][1] = $langs->trans("Description"); @@ -1850,8 +1859,8 @@ elseif (! empty($module)) $h++; // Link to enable / disable - print $modulestatusinfo; - print ' '.$linktoenabledisable.'
'; + print '
'.$modulestatusinfo; + print ' '.$linktoenabledisable.'
'; print '
'; From 372d719693dac9da56656b07ba7b4351e514fc96 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 3 Apr 2020 15:48:54 +0200 Subject: [PATCH 09/10] #13482 --- .../template/class/myobject.class.php | 71 ++++++++++--------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index 3dbb2b3b233..f893e244a7c 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -551,29 +551,31 @@ class MyObject extends CommonObject } $this->newref = $num; - // Validate - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; - $sql .= " SET ref = '".$this->db->escape($num)."',"; - $sql .= " status = ".self::STATUS_VALIDATED; - if (! empty($this->fields['date_validation'])) $sql .= ", date_validation = '".$this->db->idate($now)."',"; - if (! empty($this->fields['fk_user_valid'])) $sql .= ", fk_user_valid = ".$user->id; - $sql .= " WHERE rowid = ".$this->id; + if (! empty($num)) { + // Validate + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " SET ref = '".$this->db->escape($num)."',"; + $sql .= " status = ".self::STATUS_VALIDATED; + if (! empty($this->fields['date_validation'])) $sql .= ", date_validation = '".$this->db->idate($now)."',"; + if (! empty($this->fields['fk_user_valid'])) $sql .= ", fk_user_valid = ".$user->id; + $sql .= " WHERE rowid = ".$this->id; - dol_syslog(get_class($this)."::validate()", LOG_DEBUG); - $resql = $this->db->query($sql); - if (!$resql) - { - dol_print_error($this->db); - $this->error = $this->db->lasterror(); - $error++; - } + dol_syslog(get_class($this)."::validate()", LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) + { + dol_print_error($this->db); + $this->error = $this->db->lasterror(); + $error++; + } - if (!$error && !$notrigger) - { - // Call trigger - $result = $this->call_trigger('MYOBJECT_VALIDATE', $user); - if ($result < 0) $error++; - // End call triggers + if (!$error && !$notrigger) + { + // Call trigger + $result = $this->call_trigger('MYOBJECT_VALIDATE', $user); + if ($result < 0) $error++; + // End call triggers + } } if (!$error) @@ -946,23 +948,28 @@ class MyObject extends CommonObject return ''; } - $obj = new $classname(); - $numref = $obj->getNextValue($this); + if (class_exists($classname)) { + $obj = new $classname(); + $numref = $obj->getNextValue($this); - if ($numref != "") - { - return $numref; - } - else - { - $this->error = $obj->error; - //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error); + if ($numref != "") + { + return $numref; + } + else + { + $this->error = $obj->error; + //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error); + return ""; + } + } else { + print $langs->trans("Error")." ".$langs->trans("ClassNotFound"); return ""; } } else { - print $langs->trans("Error")." ".$langs->trans("Error_MYMODULE_MYOBJECT_ADDON_NotDefined"); + print $langs->trans("ErrorNumberingModuleNotSetup", $this->element); return ""; } } From d46417c8bd907df8cb9292c05a151fe9f3705b14 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 3 Apr 2020 17:53:17 +0200 Subject: [PATCH 10/10] FIX #13482 --- htdocs/modulebuilder/index.php | 20 ++++++++++++++++--- .../template/class/myobject.class.php | 6 +++--- .../mymodule/mod_myobject_advanced.php | 15 +++++++++----- .../mymodule/mod_myobject_standard.php | 19 ++++++++++++++---- 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 313eb65e727..31d593926d1 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -888,17 +888,31 @@ if ($dirins && $action == 'initobject' && $module && $objectname) // Edit the class 'class/'.strtolower($objectname).'.class.php' if (GETPOST('includerefgeneration', 'aZ09')) { // Replace 'visible'=>1, 'noteditable'=>0, 'default'=>'' - $arrayreplacement = array('/\'visible\'=>1,\s*\'noteditable\'=>0,\s*\'default\'=>\'\'/' => "'visible'=>4, 'noteditable'=>1, 'default'=>'(PROV)'"); + $arrayreplacement = array( + '/\'visible\'=>1,\s*\'noteditable\'=>0,\s*\'default\'=>\'\'/' => "'visible'=>4, 'noteditable'=>1, 'default'=>'(PROV)'" + ); //var_dump($arrayreplacement);exit; //var_dump($destdir.'/class/'.strtolower($objectname).'.class.php');exit; dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1); + + $arrayreplacement = array( + '/\'models\' => 0,/' => '\'models\' => 1,' + ); + dolReplaceInFile($destdir.'/core/modules/mod'.$module.'.class.php', $arrayreplacement, '', 0, 0, 1); } // Edit the setup file and the card page if (GETPOST('includedocgeneration', 'aZ09')) { - // Replace '$includedocgeneration = 0;' into '$includedocgeneration = 1;' into files - $arrayreplacement = array('/\$includedocgeneration = 0;/' => '$includedocgeneration = 1;'); + // Replace some var init into some files + $arrayreplacement = array( + '/\$includedocgeneration = 0;/' => '$includedocgeneration = 1;' + ); dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1); + + $arrayreplacement = array( + '/\'models\' => 0,/' => '\'models\' => 1,' + ); + dolReplaceInFile($destdir.'/core/modules/mod'.$module.'.class.php', $arrayreplacement, '', 0, 0, 1); } // Scan for object class files diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index f893e244a7c..97997a57542 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -922,7 +922,7 @@ class MyObject extends CommonObject $langs->load("mymodule@myobject"); if (empty($conf->global->MYMODULE_MYOBJECT_ADDON)) { - $conf->global->MYMODULE_MYOBJECT_ADDON = 'mod_mymobject_standard'; + $conf->global->MYMODULE_MYOBJECT_ADDON = 'mod_myobject_standard'; } if (!empty($conf->global->MYMODULE_MYOBJECT_ADDON)) @@ -952,7 +952,7 @@ class MyObject extends CommonObject $obj = new $classname(); $numref = $obj->getNextValue($this); - if ($numref != "") + if ($numref != '' && $numref != '-1') { return $numref; } @@ -963,7 +963,7 @@ class MyObject extends CommonObject return ""; } } else { - print $langs->trans("Error")." ".$langs->trans("ClassNotFound"); + print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname; return ""; } } diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php index 26866a6b9f1..33edc24e983 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php @@ -100,13 +100,18 @@ class mod_myobject_advanced extends ModeleNumRefMyObject { global $conf,$langs,$mysoc; - $old_code_client=$mysoc->code_client; + $object = new MyObject($this->db); + $object->initAsSpecimen(); + + /*$old_code_client=$mysoc->code_client; $old_code_type=$mysoc->typent_code; $mysoc->code_client='CCCCCCCCCC'; - $mysoc->typent_code='TTTTTTTTTT'; - $numExample = $this->getNextValue($mysoc, ''); - $mysoc->code_client=$old_code_client; - $mysoc->typent_code=$old_code_type; + $mysoc->typent_code='TTTTTTTTTT';*/ + + $numExample = $this->getNextValue($object, ''); + + /*$mysoc->code_client=$old_code_client; + $mysoc->typent_code=$old_code_type;*/ if (! $numExample) { diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php index e18e7636b6d..a213fee7174 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php @@ -76,9 +76,10 @@ class mod_myobject_standard extends ModeleNumRefMyObject * Checks if the numbers already in force in the data base do not * cause conflicts that would prevent this numbering from working. * - * @return boolean false if conflict, true if ok + * @param Object $object Object we need next value for + * @return boolean false if conflict, true if ok */ - public function canBeActivated() + public function canBeActivated($object) { global $conf,$langs,$db; @@ -88,7 +89,12 @@ class mod_myobject_standard extends ModeleNumRefMyObject $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; $sql.= " FROM ".MAIN_DB_PREFIX."mymodule_myobject"; $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; - $sql.= " AND entity = ".$conf->entity; + if ($object->ismultientitymanaged == 1) { + $sql.= " AND entity = ".$conf->entity; + } + elseif ($object->ismultientitymanaged == 2) { + // TODO + } $resql=$db->query($sql); if ($resql) @@ -121,7 +127,12 @@ class mod_myobject_standard extends ModeleNumRefMyObject $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; $sql.= " FROM ".MAIN_DB_PREFIX."mymodule_myobject"; $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; - $sql.= " AND entity = ".$conf->entity; + if ($object->ismultientitymanaged == 1) { + $sql.= " AND entity = ".$conf->entity; + } + elseif ($object->ismultientitymanaged == 2) { + // TODO + } $resql=$db->query($sql); if ($resql)