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 '
'; + print ''; print ''; print ''; @@ -1443,31 +1451,33 @@ elseif (! empty($module)) //print ''.$langs->trans("DefaultValue").''; print ''.$langs->trans("DatabaseIndex").''; print ''.$langs->trans("Position").''; - print ''.$langs->trans("Enabled").''; - print ''.$langs->trans("Visible").''; - print ''.$langs->trans("IsAMeasure").''; + print ''.$form->textwithpicto($langs->trans("Enabled"), $langs->trans("EnabledDesc")).''; + print ''.$form->textwithpicto($langs->trans("Visible"), $langs->trans("VisibleDesc")).''; + print ''.$langs->trans("IsAMeasure").''; print ''.$langs->trans("SearchAll").''; print ''.$langs->trans("Comment").''; print ''; print ''; + + // Line to add a property print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; //print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; print ''; print ''; print ''; - $properties = $tmpobjet->fields; + $properties = dol_sort_array($tmpobjet->fields, 'position'); foreach($properties as $propkey => $propval) { diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index 1ad33b502ad..acf79e837db 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -62,7 +62,7 @@ class MyObject extends CommonObject * 'type' if the field format. * 'label' the translation key. * 'enabled' is a condition when the filed must be managed. - * 'visible' says if field is visible in list (-1 means not shown by default but can be aded into list to be viewed). + * 'visible' says if field is visible in list (-1 means not shown by default but can be added into list to be viewed). * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0). * 'index' if we want an index in database. * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).