diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index b30b7e0806a..282a02835c3 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -46,10 +46,20 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir=' // Check parameters if (count($addfieldentry) > 0) { + if (empty($addfieldentry['name'])) + { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Name")), null, 'errors'); + return -2; + } + if (empty($addfieldentry['label'])) + { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Label")), null, 'errors'); + return -2; + } if (! preg_match('/^(integer|date|timestamp|varchar|double)/', $addfieldentry['type'])) { - setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null, 'errors'); - return -1; + setEventMessages($langs->trans('BadFormatForType', $objectname), null, 'errors'); + return -2; } } @@ -59,7 +69,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir=' { $langs->load("errors"); setEventMessages($langs->trans("ErrorFileNotFound", $pathoffiletoeditsrc), null, 'errors'); - return -1; + return -3; } //$pathoffiletoedittmp=$destdir.'/class/'.strtolower($objectname).'.class.php.tmp'; @@ -69,7 +79,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir=' { include_once $pathoffiletoeditsrc; if (class_exists($objectname)) $object=new $objectname($db); - else return -1; + else return -4; // Backup old file dol_copy($pathoffiletoedittarget, $pathoffiletoedittarget.'.back', $newmask, 1); @@ -157,7 +167,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir=' catch(Exception $e) { print $e->getMessage(); - return -1; + return -5; } } diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index 1b9b00a28d2..726cf56c0d5 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -63,4 +63,6 @@ UseAsciiDocFormat=You can use Markdown format, but it is recommanded to use Asci IsAMeasure=Is a measure DirScanned=Directory scanned NoTrigger=No trigger -NoWidget=No widget \ No newline at end of file +NoWidget=No widget +EnabledDesc=Condition to have this field active (Examples: 1 or $conf->global->MYMODULE_MYOPTION) +VisibleDesc=Is field is visible in list (-1 means not shown by default but can be added into list to be viewed) diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index dfd12354399..1c7d8156aa6 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -362,7 +362,7 @@ if ($dirins && $action == 'addproperty' && !empty($module) && ! empty($tabobj)) dol_mkdir($destdir); $addfieldentry = array( - 'name'=>GETPOST('propname','aZ09'),'type'=>GETPOST('proptype','aZ09'),'label'=>GETPOST('proplabel','aZ09'),'visible'=>GETPOST('propvisible','int'),'enabled'=>GETPOST('propenabled','int'), + 'name'=>GETPOST('propname','aZ09'),'type'=>GETPOST('proptype','alpha'),'label'=>GETPOST('proplabel','alpha'),'visible'=>GETPOST('propvisible','int'),'enabled'=>GETPOST('propenabled','int'), 'position'=>GETPOST('propposition','int'),'notnull'=>GETPOST('propnotnull','int'),'index'=>GETPOST('propindex','int'),'searchall'=>GETPOST('propsearchall','int'), 'isameasure'=>GETPOST('propisameasure','int'), 'comment'=>GETPOST('propcomment','alpha'),'help'=>GETPOST('prophelp')); @@ -370,14 +370,21 @@ if ($dirins && $action == 'addproperty' && !empty($module) && ! empty($tabobj)) if (! $error) { $result=rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, $addfieldentry); - if ($result <= 0) $error++; + // var_dump($result);exit; + if ($result <= 0) + { + $error++; + } } // Edit sql with new properties if (! $error) { $result=rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir); - if ($result <= 0) $error++; + if ($result <= 0) + { + $error++; + } } if (! $error) @@ -1423,6 +1430,7 @@ elseif (! empty($module)) print load_fiche_titre($langs->trans("Properties"), '', ''); print '