diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php
new file mode 100644
index 00000000000..f5f37ae91b1
--- /dev/null
+++ b/htdocs/core/lib/modulebuilder.lib.php
@@ -0,0 +1,93 @@
+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ * or see http://www.gnu.org/
+ */
+
+/**
+ * \file htdocs/core/lib/memory.lib.php
+ * \brief Set of function for memory/cache management
+ */
+
+
+/**
+ * Save data into a memory area shared by all users, all sessions on server
+ *
+ * @param string $destdir Directory
+ * @param string $module Module name
+ * @param string $objectname Name of object
+ * @param string $newmask New mask
+ * @return int <0 if KO, >0 if OK
+ */
+function rebuildobjectsql($destdir, $module, $objectname, $newmask)
+{
+ global $db;
+
+ if (empty($objectname)) return -1;
+
+ dol_include_once(strtolower($module).'/class/'.strtolower($objectname).'.class.php');
+ $object=new $objectname($db);
+
+ // Edit sql files
+ $pathoffiletoedit=dol_osencode($destdir.'/sql/llx_'.strtolower($objectname).'.sql');
+
+ $contentsql = file_get_contents($pathoffiletoedit, 'r');
+
+ $i=0;
+ $texttoinsert = '-- BEGIN MODULEBUILDER FIELDS'."\n";
+ foreach($object->fields as $key => $val)
+ {
+ $i++;
+ $texttoinsert.= "\t".$key." ".$val['type'];
+ if ($key == 'rowid') $texttoinsert.= ' AUTO_INCREMENT PRIMARY KEY';
+ if ($key == 'entity') $texttoinsert.= ' DEFAULT 1';
+ $texttoinsert.= ($val['notnull']?' NOT NULL':'');
+ if ($i < count($object->fields)) $texttoinsert.=", ";
+ $texttoinsert.= "\n";
+ }
+ $texttoinsert.= "\t".'-- END MODULEBUILDER FIELDS';
+
+ $contentsql = preg_replace('/-- BEGIN MODULEBUILDER FIELDS.*END MODULEBUILDER FIELDS/ims', $texttoinsert, $contentsql);
+
+ file_put_contents($pathoffiletoedit, $contentsql);
+ @chmod($pathoffiletoedit, octdec($newmask));
+
+
+
+ // Edit sql files
+ $pathoffiletoedit=dol_osencode($destdir.'/sql/llx_'.strtolower($objectname).'.key.sql');
+
+ $contentsql = file_get_contents($pathoffiletoedit, 'r');
+
+ $i=0;
+ $texttoinsert = '-- BEGIN MODULEBUILDER INDEXES'."\n";
+ foreach($object->fields as $key => $val)
+ {
+ $i++;
+ if ($val['index'])
+ {
+ $texttoinsert.= "ALTER TABLE llx_".strtolower($objectname)." ADD INDEX idx_".strtolower($objectname)."_".$key." (".$key.");";
+ $texttoinsert.= "\n";
+ }
+ }
+ $texttoinsert.= '-- END MODULEBUILDER INDEXES';
+
+ $contentsql = preg_replace('/-- BEGIN MODULEBUILDER INDEXES.*END MODULEBUILDER INDEXES/ims', $texttoinsert, $contentsql);
+
+ file_put_contents($pathoffiletoedit, $contentsql);
+ @chmod($pathoffiletoedit, octdec($newmask));
+
+ return 1;
+}
diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang
index a58d177061a..9251db5311f 100644
--- a/htdocs/langs/en_US/main.lang
+++ b/htdocs/langs/en_US/main.lang
@@ -736,6 +736,7 @@ ShowTransaction=Show entry on bank account
GoIntoSetupToChangeLogo=Go into Home - Setup - Company to change logo or go into Home - Setup - Display to hide.
Deny=Deny
Denied=Denied
+ListOf=List of %s
ListOfTemplates=List of templates
Gender=Gender
Genderman=Man
diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang
index 5a3470aebce..f73aa4a1eb8 100644
--- a/htdocs/langs/en_US/modulebuilder.lang
+++ b/htdocs/langs/en_US/modulebuilder.lang
@@ -9,7 +9,8 @@ NewObject=New object
ModuleKey=Module key
ObjectKey=Object key
ModuleInitialized=Module initialized
-FilesForObjectInitialized=Files for new object initialized
+FilesForObjectInitialized=Files for new object '%s' initialized
+FilesForObjectUpdated=Files for object '%s' updated
ModuleBuilderDescdescription=Enter here all general information that describe your module
ModuleBuilderDescspecifications=You can enter here a long text to describe the specifications of your module that is not already structured into other tabs. So you have on hand the rules to develop. Also this text content will be included into the generated documentation (see last tab).
ModuleBuilderDescobjects=Define here the objects you want to manage with your module. A sql file, a page to list them, to create/edit/view a card and an API will be generated.
@@ -39,4 +40,8 @@ PathToModuleDocumentation=Path to file of module/application documentation
SpaceOrSpecialCharAreNotAllowed=Spaces or special characters are not allowed.
FileNotYetGenerated=File not yet generated
SpecificationFile=File with business rules
-ConfirmDeleteProperty=Are you sure you want to delete the property %s ? This will change code in PHP class but also remove column from table definition of object.
\ No newline at end of file
+ConfirmDeleteProperty=Are you sure you want to delete the property %s ? This will change code in PHP class but also remove column from table definition of object.
+NotNull=Not NULL
+SearchAll=Used for 'search all'
+DatabaseIndex=Database index
+FileAlreadyExists=File %s already exists
\ No newline at end of file
diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php
index a1c30b7c94a..18d66187f16 100644
--- a/htdocs/modulebuilder/index.php
+++ b/htdocs/modulebuilder/index.php
@@ -24,6 +24,7 @@ if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION','1');
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/modulebuilder.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$langs->load("admin");
@@ -58,6 +59,12 @@ $dirins = $tmp[0];
$FILEFLAG='modulebuilder.txt';
$now=dol_now();
+$newmask = 0;
+if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
+if (empty($newmask)) // This should no happen
+{
+ $newmask='0664';
+}
/*
@@ -158,14 +165,6 @@ if ($dirins && $action == 'initobject' && $module && $objectname)
$srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
$destdir = $dirins.'/'.strtolower($module);
- $arrayreplacement=array(
- 'mymodule'=>strtolower($module),
- 'MyModule'=>$module,
- 'myobject'=>strtolower($objectname),
- 'MyObject'=>$objectname
- );
-
-
// Delete some files
$filetogenerate = array(
'myobject_card.php'=>strtolower($objectname).'_card.php',
@@ -182,7 +181,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname)
foreach($filetogenerate as $srcfile => $destfile)
{
- $result = dol_copy($srcdir.'/'.$srcfile, $destdir.'/'.$destfile);
+ $result = dol_copy($srcdir.'/'.$srcfile, $destdir.'/'.$destfile, $newmask, 0);
if ($result <= 0)
{
if ($result < 0)
@@ -193,7 +192,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname)
}
else // $result == 0
{
- setEventMessages($langs->trans("FileAlreadyExists", $srcdir.'/'.$srcfile, $destdir.'/'.$destfile), null, 'warnings');
+ setEventMessages($langs->trans("FileAlreadyExists", $destfile), null, 'warnings');
}
}
else
@@ -212,10 +211,10 @@ if ($dirins && $action == 'initobject' && $module && $objectname)
//var_dump($phpfileval['fullname']);
$arrayreplacement=array(
- 'mymodule'=>strtolower($modulename),
- 'MyModule'=>$modulename,
- 'MYMODULE'=>strtoupper($modulename),
- 'My module'=>$modulename,
+ 'mymodule'=>strtolower($module),
+ 'MyModule'=>$module,
+ 'MYMODULE'=>strtoupper($module),
+ 'My module'=>$module,
'htdocs/modulebuilder/template/'=>'',
'myobject'=>strtolower($objectname),
'MyObject'=>$objectname
@@ -232,7 +231,32 @@ if ($dirins && $action == 'initobject' && $module && $objectname)
if (! $error)
{
- setEventMessages('FilesForObjectInitialized', null);
+ // Edit sql with new properties
+ rebuildobjectsql($destdir, $module, $objectname, $newmask);
+
+ // Edit the class file to write properties
+
+
+ }
+
+ if (! $error)
+ {
+ setEventMessages($langs->trans('FilesForObjectInitialized', $objectname), null);
+ }
+}
+
+if ($dirins && $action == 'addproperty' && !empty($module) && ! empty($tabobj))
+{
+ $objectname = $tabobj;
+
+ $destdir = $dirins.'/'.strtolower($module);
+
+ // Edit sql with new properties
+ rebuildobjectsql($destdir, $module, $objectname, $newmask);
+
+ if (! $error)
+ {
+ setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
}
}
@@ -426,15 +450,7 @@ if ($action == 'savefile' && empty($cancel))
$content = GETPOST('editfilecontent');
// Save file on disk
- $newmask = 0;
-
file_put_contents($pathoffile, $content);
- if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
- if (empty($newmask)) // This should no happen
- {
- $newmask='0664';
- }
-
@chmod($pathoffile, octdec($newmask));
setEventMessages($langs->trans("FileSaved"), null);
@@ -939,18 +955,22 @@ elseif (! empty($module))
$pathtoapi = strtolower($module).'/class/api_'.strtolower($tabobj).'.class.php';
$pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.php';
$pathtocard = strtolower($module).'/'.strtolower($tabobj).'_card.php';
+ print '
';
+ print '';
+
+ print '
';
$result = dol_include_once($pathtoclass);
$tmpobjet = new $tabobj($db);
@@ -964,7 +984,7 @@ elseif (! empty($module))
print '