diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang
index e53220e661d..d0e32e480d9 100644
--- a/htdocs/langs/en_US/errors.lang
+++ b/htdocs/langs/en_US/errors.lang
@@ -294,6 +294,7 @@ ErrorFailedToLoadThirdParty=Failed to find/load thirdparty from id=%s, email=%s,
ErrorThisPaymentModeIsNotSepa=This payment mode is not a bank account
ErrorStripeCustomerNotFoundCreateFirst=Stripe customer is not set for this thirdparty (or set to a value deleted on Stripe side). Create (or re-attach) it first.
ErrorCharPlusNotSupportedByImapForSearch=IMAP search is not able to search into sender or recipient for a string containing the character +
+ErrorTableNotFound=Table %s not found
# Warnings
WarningParamUploadMaxFileSizeHigherThanPostMaxSize=Your PHP parameter upload_max_filesize (%s) is higher than PHP parameter post_max_size (%s). This is not a consistent setup.
diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang
index c7ca26ee149..cab7667484f 100644
--- a/htdocs/langs/en_US/modulebuilder.lang
+++ b/htdocs/langs/en_US/modulebuilder.lang
@@ -133,9 +133,9 @@ UseSpecificEditorURL = Use a specific editor URL
UseSpecificFamily = Use a specific family
UseSpecificAuthor = Use a specific author
UseSpecificVersion = Use a specific initial version
-IncludeRefGeneration=The reference of object must be generated automatically by custom numbering rules
+IncludeRefGeneration=The reference of this object must be generated automatically by custom numbering rules
IncludeRefGenerationHelp=Check this if you want to include code to manage the generation of the reference automatically using custom numbering rules
-IncludeDocGeneration=I want to generate some documents from templates for the object
+IncludeDocGeneration=I want the feature to generate some documents (PDF, ODT) from templates for this object
IncludeDocGenerationHelp=If you check this, some code will be generated to add a "Generate document" box on the record.
ShowOnCombobox=Show value into combobox
KeyForTooltip=Key for tooltip
@@ -156,4 +156,7 @@ LinkToParentMenu=Parent menu (fk_xxxxmenu)
ListOfTabsEntries=List of tab entries
TabsDefDesc=Define here the tabs provided by your module
TabsDefDescTooltip=The tabs provided by your module/application are defined into the array $this->tabs into the module descriptor file. You can edit manually this file or use the embedded editor.
-BadValueForType=Bad value for type %s
\ No newline at end of file
+BadValueForType=Bad value for type %s
+DefinePropertiesFromExistingTable=Define properties from an existing table
+DefinePropertiesFromExistingTableDesc=If a table in the database (for the object to create) already exists, you can use it to define the properties of the object.
+DefinePropertiesFromExistingTableDesc2=Keep empty if not table exists. The code generator will use different kinds of fields to build an example of table that you can edit later.
diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php
index b41342abc13..1c30d709576 100644
--- a/htdocs/modulebuilder/index.php
+++ b/htdocs/modulebuilder/index.php
@@ -894,238 +894,7 @@ if ($dirins && $action == 'confirm_removefile' && !empty($module)) {
}
}
-
-// Build the $fields array from SQL table (initfromtablename)
-if ($dirins && $action == 'initobject' && $module && GETPOST('createtablearray', 'alpha')) {
- $tablename = GETPOST('initfromtablename', 'alpha');
- $_results = $db->DDLDescTable($tablename);
- if (empty($_results)) {
- setEventMessages($langs->trans("ErrorTableNotFound", $tablename), null, 'errors');
- } else {
- /**
- * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter[:Sortfield]]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
- * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
- * 'label' the translation key.
- * 'picto' is code of a picto to show before value in forms
- * 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM' or 'isModEnabled("multicurrency")' ...)
- * 'position' is the sort order of field.
- * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
- * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing)
- * 'noteditable' says if field is not editable (1 or 0)
- * 'alwayseditable' says if field can be modified also when status is not draft ('1' or '0')
- * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created.
- * '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_...).
- * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
- * 'isameasure' must be set to 1 or 2 if field can be used for measure. Field type must be summable like integer or double(24,8). Use 1 in most cases, or 2 if you don't want to see the column total into list (for example for percentage)
- * 'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'cssview'=>'wordbreak', 'csslist'=>'tdoverflowmax200'
- * 'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
- * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
- * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code.
- * 'arrayofkeyval' to set a list of values if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel"). Note that type can be 'integer' or 'varchar'
- * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
- * 'comment' is not used. You can store here any text of your choice. It is not used by application.
- * 'validate' is 1 if need to validate with $this->validateField()
- * 'copytoclipboard' is 1 or 2 to allow to add a picto to copy value into clipboard (1=picto after label, 2=picto after value)
- */
-
- /*public $fields=array(
- 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
- 'ref' =>array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
- 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20),
- 'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'css'=>'minwidth200', 'help'=>'Help text', 'alwayseditable'=>'1'),
- 'amount' =>array('type'=>'double(24,8)', 'label'=>'Amount', 'enabled'=>1, 'visible'=>1, 'default'=>'null', 'position'=>40, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text'),
- 'fk_soc' =>array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'visible'=>1, 'enabled'=>1, 'position'=>50, 'notnull'=>-1, 'index'=>1, 'searchall'=>1, 'help'=>'LinkToThirdparty'),
- 'description' =>array('type'=>'text', 'label'=>'Descrption', 'enabled'=>1, 'visible'=>0, 'position'=>60),
- 'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61),
- 'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>62),
- 'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500),
- 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501),
- //'date_valid' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>502),
- 'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>510),
- 'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
- //'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
- 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>0, 'position'=>1000),
- 'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'default'=>0, 'index'=>1, 'position'=>1000, 'arrayofkeyval'=>array(0=>'Draft', 1=>'Active', -1=>'Cancel')),
- );*/
-
- $string = 'public $fields=array('."\n";
- $string .= "
";
- $i = 10;
- while ($obj = $db->fetch_object($_results)) {
- // fieldname
- $fieldname = $obj->Field;
- // type
- $type = $obj->Type;
- if ($type == 'int(11)') {
- $type = 'integer';
- }
- if ($type == 'float') {
- $type = 'real';
- }
- if (strstr($type, 'tinyint')) {
- $type = 'integer';
- }
- if ($obj->Field == 'fk_soc') {
- $type = 'integer:Societe:societe/class/societe.class.php';
- }
- if (preg_match('/^fk_proj/', $obj->Field)) {
- $type = 'integer:Project:projet/class/project.class.php:1:fk_statut=1';
- }
- if (preg_match('/^fk_prod/', $obj->Field)) {
- $type = 'integer:Product:product/class/product.class.php:1';
- }
- if ($obj->Field == 'fk_warehouse') {
- $type = 'integer:Entrepot:product/stock/class/entrepot.class.php';
- }
- if (preg_match('/^(fk_user|fk_commercial)/', $obj->Field)) {
- $type = 'integer:User:user/class/user.class.php';
- }
-
- // notnull
- $notnull = ($obj->Null == 'YES' ? 0 : 1);
- if ($fieldname == 'fk_user_modif') {
- $notnull = -1;
- }
- // label
- $label = preg_replace('/_/', '', ucfirst($fieldname));
- if ($fieldname == 'rowid') {
- $label = 'TechnicalID';
- }
- if ($fieldname == 'import_key') {
- $label = 'ImportId';
- }
- if ($fieldname == 'fk_soc') {
- $label = 'ThirdParty';
- }
- if ($fieldname == 'tms') {
- $label = 'DateModification';
- }
- if ($fieldname == 'datec') {
- $label = 'DateCreation';
- }
- if ($fieldname == 'date_valid') {
- $label = 'DateValidation';
- }
- if ($fieldname == 'datev') {
- $label = 'DateValidation';
- }
- if ($fieldname == 'note_private') {
- $label = 'NotePublic';
- }
- if ($fieldname == 'note_public') {
- $label = 'NotePrivate';
- }
- if ($fieldname == 'fk_user_creat') {
- $label = 'UserAuthor';
- }
- if ($fieldname == 'fk_user_modif') {
- $label = 'UserModif';
- }
- if ($fieldname == 'fk_user_valid') {
- $label = 'UserValidation';
- }
- // visible
- $visible = -1;
- if ($fieldname == 'entity') {
- $visible = -2;
- }
- if ($fieldname == 'import_key') {
- $visible = -2;
- }
- if ($fieldname == 'fk_user_creat') {
- $visible = -2;
- }
- if ($fieldname == 'fk_user_modif') {
- $visible = -2;
- }
- if (in_array($fieldname, array('ref_ext', 'model_pdf', 'note_public', 'note_private'))) {
- $visible = 0;
- }
- // enabled
- $enabled = 1;
- // default
- $default = '';
- if ($fieldname == 'entity') {
- $default = 1;
- }
- // position
- $position = $i;
- if (in_array($fieldname, array('status', 'statut', 'fk_status', 'fk_statut'))) {
- $position = 500;
- }
- if ($fieldname == 'import_key') {
- $position = 900;
- }
- // index
- $index = 0;
- if ($fieldname == 'entity') {
- $index = 1;
- }
- // css, cssview, csslist
- $css = '';
- $cssview = '';
- $csslist = '';
- if (preg_match('/^fk_/', $fieldname)) {
- $css = 'maxwidth500 widthcentpercentminusxx';
- }
- if ($fieldname == 'label') {
- $css = 'minwidth300';
- $cssview = 'wordbreak';
- }
- if (in_array($fieldname, array('note_public', 'note_private'))) {
- $cssview = 'wordbreak';
- }
-
- // type
- $picto = $obj->Picto;
- if ($obj->Field == 'fk_soc') {
- $picto = 'company';
- }
- if (preg_match('/^fk_proj/', $obj->Field)) {
- $picto = 'project';
- }
-
- // Build the property string
- $string .= "'".$obj->Field."'=>array('type'=>'".$type."', 'label'=>'".$label."',";
- if ($default != '') {
- $string .= " 'default'=>".$default.",";
- }
- $string .= " 'enabled'=>".$enabled.",";
- $string .= " 'visible'=>".$visible;
- if ($notnull) {
- $string .= ", 'notnull'=>".$notnull;
- }
- if ($fieldname == 'ref' || $fieldname == 'code') {
- $string .= ", 'showoncombobox'=>1";
- }
- $string .= ", 'position'=>".$position;
- if ($index) {
- $string .= ", 'index'=>".$index;
- }
- if ($picto) {
- $string .= ", 'picto'=>'".$picto."'";
- }
- if ($css) {
- $string .= ", 'css'=>".$css;
- }
- if ($cssview) {
- $string .= ", 'cssview'=>".$cssview;
- }
- if ($csslist) {
- $string .= ", 'csslist'=>".$csslist;
- }
- $string .= "),\n";
- $string .= "
";
- $i += 5;
- }
- $string .= ');'."\n";
- $string .= "
";
- print $string;
- exit;
- }
-}
-
+// Init an object
if ($dirins && $action == 'initobject' && $module && $objectname) {
$objectname = ucfirst($objectname);
@@ -1169,6 +938,247 @@ if ($dirins && $action == 'initobject' && $module && $objectname) {
}
}
+ // If we must reuse a table for properties, define $stringforproperties
+ $stringforproperties = '';
+ $tablename = GETPOST('initfromtablename', 'alpha');
+ if ($tablename) {
+ $_results = $db->DDLDescTable($tablename);
+ if (empty($_results)) {
+ $error++;
+ $langs->load("errors");
+ setEventMessages($langs->trans("ErrorTableNotFound", $tablename), null, 'errors');
+ } else {
+ /**
+ * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter[:Sortfield]]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
+ * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
+ * 'label' the translation key.
+ * 'picto' is code of a picto to show before value in forms
+ * 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM' or 'isModEnabled("multicurrency")' ...)
+ * 'position' is the sort order of field.
+ * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
+ * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing)
+ * 'noteditable' says if field is not editable (1 or 0)
+ * 'alwayseditable' says if field can be modified also when status is not draft ('1' or '0')
+ * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created.
+ * '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_...).
+ * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
+ * 'isameasure' must be set to 1 or 2 if field can be used for measure. Field type must be summable like integer or double(24,8). Use 1 in most cases, or 2 if you don't want to see the column total into list (for example for percentage)
+ * 'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'cssview'=>'wordbreak', 'csslist'=>'tdoverflowmax200'
+ * 'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
+ * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
+ * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code.
+ * 'arrayofkeyval' to set a list of values if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel"). Note that type can be 'integer' or 'varchar'
+ * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
+ * 'comment' is not used. You can store here any text of your choice. It is not used by application.
+ * 'validate' is 1 if need to validate with $this->validateField()
+ * 'copytoclipboard' is 1 or 2 to allow to add a picto to copy value into clipboard (1=picto after label, 2=picto after value)
+ */
+
+ /*public $fields=array(
+ 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
+ 'ref' =>array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
+ 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20),
+ 'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'css'=>'minwidth200', 'help'=>'Help text', 'alwayseditable'=>'1'),
+ 'amount' =>array('type'=>'double(24,8)', 'label'=>'Amount', 'enabled'=>1, 'visible'=>1, 'default'=>'null', 'position'=>40, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text'),
+ 'fk_soc' =>array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'visible'=>1, 'enabled'=>1, 'position'=>50, 'notnull'=>-1, 'index'=>1, 'searchall'=>1, 'help'=>'LinkToThirdparty'),
+ 'description' =>array('type'=>'text', 'label'=>'Descrption', 'enabled'=>1, 'visible'=>0, 'position'=>60),
+ 'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61),
+ 'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>62),
+ 'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500),
+ 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501),
+ //'date_valid' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>502),
+ 'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>510),
+ 'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
+ //'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
+ 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>0, 'position'=>1000),
+ 'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'default'=>0, 'index'=>1, 'position'=>1000, 'arrayofkeyval'=>array(0=>'Draft', 1=>'Active', -1=>'Cancel')),
+ );*/
+
+ $stringforproperties = '// BEGIN MODULEBUILDER PROPERTIES'."\n";
+ $stringforproperties .= 'public $fields=array('."\n";
+ $i = 10;
+ while ($obj = $db->fetch_object($_results)) {
+ // fieldname
+ $fieldname = $obj->Field;
+ // type
+ $type = $obj->Type;
+ if ($type == 'int(11)') {
+ $type = 'integer';
+ }
+ if ($type == 'float') {
+ $type = 'real';
+ }
+ if (strstr($type, 'tinyint')) {
+ $type = 'integer';
+ }
+ if ($obj->Field == 'fk_soc') {
+ $type = 'integer:Societe:societe/class/societe.class.php';
+ }
+ if (preg_match('/^fk_proj/', $obj->Field)) {
+ $type = 'integer:Project:projet/class/project.class.php:1:fk_statut=1';
+ }
+ if (preg_match('/^fk_prod/', $obj->Field)) {
+ $type = 'integer:Product:product/class/product.class.php:1';
+ }
+ if ($obj->Field == 'fk_warehouse') {
+ $type = 'integer:Entrepot:product/stock/class/entrepot.class.php';
+ }
+ if (preg_match('/^(fk_user|fk_commercial)/', $obj->Field)) {
+ $type = 'integer:User:user/class/user.class.php';
+ }
+
+ // notnull
+ $notnull = ($obj->Null == 'YES' ? 0 : 1);
+ if ($fieldname == 'fk_user_modif') {
+ $notnull = -1;
+ }
+ // label
+ $label = preg_replace('/_/', '', ucfirst($fieldname));
+ if ($fieldname == 'rowid') {
+ $label = 'TechnicalID';
+ }
+ if ($fieldname == 'import_key') {
+ $label = 'ImportId';
+ }
+ if ($fieldname == 'fk_soc') {
+ $label = 'ThirdParty';
+ }
+ if ($fieldname == 'tms') {
+ $label = 'DateModification';
+ }
+ if ($fieldname == 'datec') {
+ $label = 'DateCreation';
+ }
+ if ($fieldname == 'date_valid') {
+ $label = 'DateValidation';
+ }
+ if ($fieldname == 'datev') {
+ $label = 'DateValidation';
+ }
+ if ($fieldname == 'note_private') {
+ $label = 'NotePublic';
+ }
+ if ($fieldname == 'note_public') {
+ $label = 'NotePrivate';
+ }
+ if ($fieldname == 'fk_user_creat') {
+ $label = 'UserAuthor';
+ }
+ if ($fieldname == 'fk_user_modif') {
+ $label = 'UserModif';
+ }
+ if ($fieldname == 'fk_user_valid') {
+ $label = 'UserValidation';
+ }
+ // visible
+ $visible = -1;
+ if ($fieldname == 'entity') {
+ $visible = -2;
+ }
+ if ($fieldname == 'import_key') {
+ $visible = -2;
+ }
+ if ($fieldname == 'fk_user_creat') {
+ $visible = -2;
+ }
+ if ($fieldname == 'fk_user_modif') {
+ $visible = -2;
+ }
+ if (in_array($fieldname, array('ref_ext', 'model_pdf', 'note_public', 'note_private'))) {
+ $visible = 0;
+ }
+ // enabled
+ $enabled = 1;
+ // default
+ $default = '';
+ if ($fieldname == 'entity') {
+ $default = 1;
+ }
+ // position
+ $position = $i;
+ if (in_array($fieldname, array('status', 'statut', 'fk_status', 'fk_statut'))) {
+ $position = 500;
+ }
+ if ($fieldname == 'import_key') {
+ $position = 900;
+ }
+ // $alwayseditable
+ if ($fieldname == 'label') {
+ $alwayseditable = 1;
+ }
+ // index
+ $index = 0;
+ if ($fieldname == 'entity') {
+ $index = 1;
+ }
+ // css, cssview, csslist
+ $css = '';
+ $cssview = '';
+ $csslist = '';
+ if (preg_match('/^fk_/', $fieldname)) {
+ $css = 'maxwidth500 widthcentpercentminusxx';
+ }
+ if ($fieldname == 'label') {
+ $css = 'minwidth300';
+ $cssview = 'wordbreak';
+ }
+ if (in_array($fieldname, array('note_public', 'note_private'))) {
+ $cssview = 'wordbreak';
+ }
+ if (in_array($fieldname, array('ref', 'label')) || preg_match('/integer:/', $type)) {
+ $csslist = 'tdoverflowmax150';
+ }
+
+ // type
+ $picto = $obj->Picto;
+ if ($obj->Field == 'fk_soc') {
+ $picto = 'company';
+ }
+ if (preg_match('/^fk_proj/', $obj->Field)) {
+ $picto = 'project';
+ }
+
+ // Build the property string
+ $stringforproperties .= "'".$obj->Field."'=>array('type'=>'".$type."', 'label'=>'".$label."',";
+ if ($default != '') {
+ $stringforproperties .= " 'default'=>".$default.",";
+ }
+ $stringforproperties .= " 'enabled'=>".$enabled.",";
+ $stringforproperties .= " 'visible'=>".$visible;
+ if ($notnull) {
+ $stringforproperties .= ", 'notnull'=>".$notnull;
+ }
+ if ($alwayseditable) {
+ $stringforproperties .= ", 'alwayseditable'=>1";
+ }
+ if ($fieldname == 'ref' || $fieldname == 'code') {
+ $stringforproperties .= ", 'showoncombobox'=>1";
+ }
+ $stringforproperties .= ", 'position'=>".$position;
+ if ($index) {
+ $stringforproperties .= ", 'index'=>".$index;
+ }
+ if ($picto) {
+ $stringforproperties .= ", 'picto'=>'".$picto."'";
+ }
+ if ($css) {
+ $stringforproperties .= ", 'css'=>'".$css."'";
+ }
+ if ($cssview) {
+ $stringforproperties .= ", 'cssview'=>'".$cssview."'";
+ }
+ if ($csslist) {
+ $stringforproperties .= ", 'csslist'=>'".$csslist."'";
+ }
+ $stringforproperties .= "),\n";
+ $i += 5;
+ }
+ $stringforproperties .= ');'."\n";
+ $stringforproperties .= '// END MODULEBUILDER PROPERTIES'."\n";
+ }
+ }
+
if (!$error) {
// Copy some files
$filetogenerate = array(
@@ -1209,20 +1219,33 @@ if ($dirins && $action == 'initobject' && $module && $objectname) {
);
}
- foreach ($filetogenerate as $srcfile => $destfile) {
- $result = dol_copy($srcdir.'/'.$srcfile, $destdir.'/'.$destfile, $newmask, 0);
- if ($result <= 0) {
- if ($result < 0) {
- $error++;
- $langs->load("errors");
- setEventMessages($langs->trans("ErrorFailToCopyFile", $srcdir.'/'.$srcfile, $destdir.'/'.$destfile), null, 'errors');
- } else {
- // $result == 0
- setEventMessages($langs->trans("FileAlreadyExists", $destfile), null, 'warnings');
+
+ if (!$error) {
+ foreach ($filetogenerate as $srcfile => $destfile) {
+ $result = dol_copy($srcdir.'/'.$srcfile, $destdir.'/'.$destfile, $newmask, 0);
+ if ($result <= 0) {
+ if ($result < 0) {
+ $error++;
+ $langs->load("errors");
+ setEventMessages($langs->trans("ErrorFailToCopyFile", $srcdir.'/'.$srcfile, $destdir.'/'.$destfile), null, 'errors');
+ } else {
+ // $result == 0
+ setEventMessages($langs->trans("FileAlreadyExists", $destfile), null, 'warnings');
+ }
}
}
}
+ // Replace property section with $stringforproperties
+ if (!$error && $stringforproperties) {
+ //var_dump($stringforproperties);exit;
+ $arrayreplacement = array(
+ '/\/\/ BEGIN MODULEBUILDER PROPERTIES.*\/\/ END MODULEBUILDER PROPERTIES/ims' => $stringforproperties
+ );
+
+ dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1);
+ }
+
// Edit the class 'class/'.strtolower($objectname).'.class.php'
if (GETPOST('includerefgeneration', 'aZ09')) {
// Replace 'visible'=>1, 'noteditable'=>0, 'default'=>''
@@ -1405,6 +1428,8 @@ if ($dirins && $action == 'initobject' && $module && $objectname) {
if (!$error) {
setEventMessages($langs->trans('FilesForObjectInitialized', $objectname), null);
$tabobj = $objectname;
+ } else {
+ $tabobj = 'newobject';
}
}
@@ -1489,26 +1514,26 @@ if ($dirins && $action == 'addproperty' && empty($cancel) && !empty($module) &&
if (!$error && !GETPOST('regenerateclasssql')&& !GETPOST('regeneratemissing')) {
$addfieldentry = array(
- 'name'=>GETPOST('propname', 'aZ09'),
- 'label'=>GETPOST('proplabel', 'alpha'),
- 'type'=>GETPOST('proptype', 'alpha'),
- 'arrayofkeyval'=>GETPOST('proparrayofkeyval', 'restricthtml'), // Example json string '{"0":"Draft","1":"Active","-1":"Cancel"}'
- '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', 'alpha'),
- 'css'=>GETPOST('propcss', 'alpha'), // Can be 'maxwidth500 widthcentpercentminusxx' for example
- 'cssview'=>GETPOST('propcssview', 'alpha'),
- 'csslist'=>GETPOST('propcsslist', 'alpha'),
- 'default'=>GETPOST('propdefault', 'restricthtml'),
- 'noteditable'=>intval(GETPOST('propnoteditable', 'int')),
- 'alwayseditable'=>intval(GETPOST('propalwayseditable', 'int')),
- 'validate' => GETPOST('propvalidate', 'int')
+ 'name'=>GETPOST('propname', 'aZ09'),
+ 'label'=>GETPOST('proplabel', 'alpha'),
+ 'type'=>GETPOST('proptype', 'alpha'),
+ 'arrayofkeyval'=>GETPOST('proparrayofkeyval', 'restricthtml'), // Example json string '{"0":"Draft","1":"Active","-1":"Cancel"}'
+ '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', 'alpha'),
+ 'css'=>GETPOST('propcss', 'alpha'), // Can be 'maxwidth500 widthcentpercentminusxx' for example
+ 'cssview'=>GETPOST('propcssview', 'alpha'),
+ 'csslist'=>GETPOST('propcsslist', 'alpha'),
+ 'default'=>GETPOST('propdefault', 'restricthtml'),
+ 'noteditable'=>intval(GETPOST('propnoteditable', 'int')),
+ 'alwayseditable'=>intval(GETPOST('propalwayseditable', 'int')),
+ 'validate' => GETPOST('propvalidate', 'int')
);
@@ -2285,6 +2310,8 @@ if ($module == 'initmodule') {
$head2[$h][2] = 'buildpackage';
$h++;
+ $MAXTABFOROBJECT = 15;
+
print '';
// Note module is inside $dirread
@@ -2296,7 +2323,7 @@ if ($module == 'initmodule') {
$pathtochangelog = $modulelowercase.'/ChangeLog.md';
if ($action != 'editfile' || empty($file)) {
- print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', 0, 'formodulesuffix'); // Description - level 2
+ print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', $MAXTABFOROBJECT, 'formodulesuffix'); // Description - level 2
print ''.$langs->trans("ModuleBuilderDesc".$tab).'';
$infoonmodulepath = '';
@@ -2456,7 +2483,7 @@ if ($module == 'initmodule') {
print '';
}
} else {
- print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', 0, 'formodulesuffix'); // Level 2
+ print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', $MAXTABFOROBJECT, 'formodulesuffix'); // Level 2
}
if ($tab == 'languages') {
@@ -2603,12 +2630,38 @@ if ($module == 'initmodule') {
print ''.$langs->trans("EnterNameOfObjectDesc").'
';
- print '
';
- print '
';
+ print '