Debug and enhance modulebuilder.

This commit is contained in:
Laurent Destailleur 2019-03-10 19:33:28 +01:00
parent 1bd422b8b9
commit 935fe7c22a
12 changed files with 496 additions and 143 deletions

View File

@ -397,7 +397,8 @@ class ModeleBoxes // Can't be abtract as it is instantiated to build "empty" box
$orders = array(); $orders = array();
$i = 0; $i = 0;
$dirwidget=array_merge(array('/core/boxes/')); //$dirwidget=array_merge(array('/core/boxes/'), $conf->modules_parts['widgets']);
$dirwidget=array('/core/boxes/'); // $conf->modules_parts['widgets'] is not required
if (is_array($forcedirwidget)) if (is_array($forcedirwidget))
{ {
$dirwidget=$forcedirwidget; $dirwidget=$forcedirwidget;

View File

@ -443,6 +443,17 @@ function dol_is_dir($folder)
else return false; else return false;
} }
/**
* Return if path is empty
*
* @param string $dir Path of Directory
* @return boolean True or false
*/
function dol_is_dir_empty($dir) {
if (!is_readable($dir)) return false;
return (count(scandir($dir)) == 2);
}
/** /**
* Return if path is a file * Return if path is a file
* *

View File

@ -2,7 +2,7 @@
ModuleBuilderDesc=This tool must be used by only by experienced users or developers. It gives you utilities to build or edit your own module.<br>Documentation for alternative <a href="%s" target="_blank">manual development is here</a>. ModuleBuilderDesc=This tool must be used by only by experienced users or developers. It gives you utilities to build or edit your own module.<br>Documentation for alternative <a href="%s" target="_blank">manual development is here</a>.
EnterNameOfModuleDesc=Enter name of the module/application to create with no spaces. Use uppercase to separate words (For example: MyModule, EcommerceForShop, SyncWithMySystem...) EnterNameOfModuleDesc=Enter name of the module/application to create with no spaces. Use uppercase to separate words (For example: MyModule, EcommerceForShop, SyncWithMySystem...)
EnterNameOfObjectDesc=Enter name of the object to create with no spaces. Use uppercase to separate words (For example: MyObject, Student, Teacher...). The CRUD class file, but also API file, pages to list/add/edit/delete object and SQL files will be generated. EnterNameOfObjectDesc=Enter name of the object to create with no spaces. Use uppercase to separate words (For example: MyObject, Student, Teacher...). The CRUD class file, but also API file, pages to list/add/edit/delete object and SQL files will be generated.
ModuleBuilderDesc2=Path where modules are generated/edited (first alternative directory defined into %s): <strong>%s</strong> ModuleBuilderDesc2=Path where modules are generated/edited (first directory for external modules defined into %s): <strong>%s</strong>
ModuleBuilderDesc3=Generated/editable modules found: <strong>%s</strong> ModuleBuilderDesc3=Generated/editable modules found: <strong>%s</strong>
ModuleBuilderDesc4=A module is detected as 'editable' when the file <strong>%s</strong> exists in root of module directory ModuleBuilderDesc4=A module is detected as 'editable' when the file <strong>%s</strong> exists in root of module directory
NewModule=New module NewModule=New module
@ -101,3 +101,7 @@ UseDocFolder=Disable the documentation folder
UseSpecificReadme=Use a specific ReadMe UseSpecificReadme=Use a specific ReadMe
RealPathOfModule=Real path of module RealPathOfModule=Real path of module
ContentCantBeEmpty=Content of file can't be empty ContentCantBeEmpty=Content of file can't be empty
WidgetDesc=You can generate and edit here the widgets that will be embedded with your module.
CLIDesc=You can generate here some command line scripts you want to provide with your module.
CLIFile=CLI File
NoCLIFile=No CLI files

View File

@ -132,27 +132,41 @@ if ($dirins && $action == 'initmodule' && $modulename)
{ {
dol_delete_file($destdir.'/admin/about.php'); dol_delete_file($destdir.'/admin/about.php');
} }
if (!empty($conf->global->MODULEBUILDER_USE_DOCFOLDER))
{
dol_delete_dir($destdir.'/doc/');
}
// Delete some files related to object (because to previous dolCopyDir has copied everything) // Delete dir and files that can be generated in sub tabs later if we need them (we want a minimal module first)
dol_delete_dir_recursive($destdir.'/build/doxygen');
dol_delete_dir_recursive($destdir.'/core/modules/mailings');
dol_delete_dir_recursive($destdir.'/core/tpl');
dol_delete_dir_recursive($destdir.'/core/triggers');
dol_delete_dir_recursive($destdir.'/doc');
dol_delete_dir_recursive($destdir.'/.tx');
dol_delete_dir_recursive($destdir.'/core/boxes');
dol_delete_file($destdir.'/sql/data.sql');
dol_delete_file($destdir.'/sql/update_x.x.x-y.y.y.sql');
dol_delete_dir($destdir.'/sql');
dol_delete_file($destdir.'/class/actions_'.strtolower($modulename).'.class.php');
dol_delete_file($destdir.'/class/api_'.strtolower($modulename).'.class.php');
dol_delete_dir($destdir.'/class');
dol_delete_file($destdir.'/scripts/'.strtolower($modulename).'.php');
dol_delete_dir($destdir.'/scripts');
// Delete some files related to Object (because the dolCopyDir has copied everything)
dol_delete_file($destdir.'/myobject_card.php'); dol_delete_file($destdir.'/myobject_card.php');
dol_delete_file($destdir.'/myobject_note.php'); dol_delete_file($destdir.'/myobject_note.php');
dol_delete_file($destdir.'/myobject_document.php'); dol_delete_file($destdir.'/myobject_document.php');
dol_delete_file($destdir.'/myobject_agenda.php'); dol_delete_file($destdir.'/myobject_agenda.php');
dol_delete_file($destdir.'/myobject_list.php'); dol_delete_file($destdir.'/myobject_list.php');
dol_delete_file($destdir.'/lib/mymodule_myobject.lib.php'); dol_delete_file($destdir.'/lib/'.strtolower($modulename).'_myobject.lib.php');
dol_delete_file($destdir.'/test/phpunit/MyObjectTest.php'); dol_delete_file($destdir.'/test/phpunit/MyObjectTest.php');
dol_delete_file($destdir.'/sql/llx_mymodule_myobject.sql'); dol_delete_file($destdir.'/sql/llx'.strtolower($modulename).'_myobject.sql');
dol_delete_file($destdir.'/sql/llx_mymodule_myobject_extrafields.sql'); dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject_extrafields.sql');
dol_delete_file($destdir.'/sql/llx_mymodule_myobject.key.sql'); dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject.key.sql');
dol_delete_file($destdir.'/scripts/myobject.php');
dol_delete_file($destdir.'/img/object_myobject.png'); dol_delete_file($destdir.'/img/object_myobject.png');
dol_delete_file($destdir.'/class/myobject.class.php'); dol_delete_file($destdir.'/class/myobject.class.php');
dol_delete_file($destdir.'/class/api_mymodule.class.php');
dol_delete_file($destdir.'/doc/*example*');
} }
// Edit PHP files // Edit PHP files
@ -174,7 +188,6 @@ if ($dirins && $action == 'initmodule' && $modulename)
'---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email?' <'.$user->email.'>':'') '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email?' <'.$user->email.'>':'')
); );
$result=dolReplaceInFile($phpfileval['fullname'], $arrayreplacement); $result=dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
//var_dump($result); //var_dump($result);
if ($result < 0) if ($result < 0)
@ -198,6 +211,132 @@ if ($dirins && $action == 'initmodule' && $modulename)
} }
} }
if ($dirins && $action == 'inithook' && !empty($module))
{
dol_mkdir($dirins.'/'.strtolower($module).'/class');
$srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
$srcfile = $srcdir.'/class/actions_mymodule.class.php';
$destfile = $dirins.'/'.strtolower($module).'/class/actions_'.strtolower($module).'.class.php';
//var_dump($srcfile);var_dump($destfile);
$result = dol_copy($srcfile, $destfile, 0, 0);
}
if ($dirins && $action == 'inittrigger' && !empty($module))
{
dol_mkdir($dirins.'/'.strtolower($module).'/core/triggers');
$srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
$srcfile = $srcdir.'/core/triggers/interface_99_modMyModule_MyModuleTriggers.class.php';
$destfile = $dirins.'/'.strtolower($module).'/core/triggers/interface_99_mod'.$module.'_'.$module.'Triggers.class.php';
//var_dump($srcfile);var_dump($destfile);
$result = dol_copy($srcfile, $destfile, 0, 0);
if ($result > 0)
{
$modulename = ucfirst($module); // Force first letter in uppercase
//var_dump($phpfileval['fullname']);
$arrayreplacement=array(
'mymodule'=>strtolower($modulename),
'MyModule'=>$modulename,
'MYMODULE'=>strtoupper($modulename),
'My module'=>$modulename,
'my module'=>$modulename,
'Mon module'=>$modulename,
'mon module'=>$modulename,
'htdocs/modulebuilder/template'=>strtolower($modulename),
'---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email?' <'.$user->email.'>':'')
);
dolReplaceInFile($destfile, $arrayreplacement);
}
}
if ($dirins && $action == 'initwidget' && !empty($module))
{
dol_mkdir($dirins.'/'.strtolower($module).'/core/boxes');
$srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
$srcfile = $srcdir.'/core/boxes/mymodulewidget1.php';
$destfile = $dirins.'/'.strtolower($module).'/core/boxes/'.strtolower($module).'widget1.php';
//var_dump($srcfile);var_dump($destfile);
$result = dol_copy($srcfile, $destfile, 0, 0);
if ($result > 0)
{
$modulename = ucfirst($module); // Force first letter in uppercase
//var_dump($phpfileval['fullname']);
$arrayreplacement=array(
'mymodule'=>strtolower($modulename),
'MyModule'=>$modulename,
'MYMODULE'=>strtoupper($modulename),
'My module'=>$modulename,
'my module'=>$modulename,
'Mon module'=>$modulename,
'mon module'=>$modulename,
'htdocs/modulebuilder/template'=>strtolower($modulename),
'---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email?' <'.$user->email.'>':'')
);
dolReplaceInFile($destfile, $arrayreplacement);
}
}
if ($dirins && $action == 'initcli' && !empty($module))
{
dol_mkdir($dirins.'/'.strtolower($module).'/scripts');
$srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
$srcfile = $srcdir.'/scripts/mymodule.php';
$destfile = $dirins.'/'.strtolower($module).'/scripts/'.strtolower($module).'.php';
//var_dump($srcfile);var_dump($destfile);
$result = dol_copy($srcfile, $destfile, 0, 0);
if ($result > 0)
{
$modulename = ucfirst($module); // Force first letter in uppercase
//var_dump($phpfileval['fullname']);
$arrayreplacement=array(
'mymodule'=>strtolower($modulename),
'MyModule'=>$modulename,
'MYMODULE'=>strtoupper($modulename),
'My module'=>$modulename,
'my module'=>$modulename,
'Mon module'=>$modulename,
'mon module'=>$modulename,
'htdocs/modulebuilder/template'=>strtolower($modulename),
'---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email?' <'.$user->email.'>':'')
);
dolReplaceInFile($destfile, $arrayreplacement);
}
}
if ($dirins && $action == 'initdoc' && !empty($module))
{
dol_mkdir($dirins.'/'.strtolower($module).'/doc');
$srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
$srcfile = $srcdir.'/doc/Specifications.asciidoc';
$destfile = $dirins.'/'.strtolower($module).'/doc/Specifications.asciidoc';
//var_dump($srcfile);var_dump($destfile);
$result = dol_copy($srcfile, $destfile, 0, 0);
if ($result > 0)
{
$modulename = ucfirst($module); // Force first letter in uppercase
//var_dump($phpfileval['fullname']);
$arrayreplacement=array(
'mymodule'=>strtolower($modulename),
'MyModule'=>$modulename,
'MYMODULE'=>strtoupper($modulename),
'My module'=>$modulename,
'my module'=>$modulename,
'Mon module'=>$modulename,
'mon module'=>$modulename,
'htdocs/modulebuilder/template'=>strtolower($modulename),
'---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email?' <'.$user->email.'>':'')
);
dolReplaceInFile($destfile, $arrayreplacement);
}
}
if ($dirins && $action == 'addlanguage' && !empty($module)) if ($dirins && $action == 'addlanguage' && !empty($module))
{ {
$newlangcode=GETPOST('newlangcode', 'aZ09'); $newlangcode=GETPOST('newlangcode', 'aZ09');
@ -206,6 +345,20 @@ if ($dirins && $action == 'addlanguage' && !empty($module))
$result = dolCopyDir($srcfile, $destfile, 0, 0); $result = dolCopyDir($srcfile, $destfile, 0, 0);
} }
if ($dirins && $action == 'confirm_removefile' && !empty($module))
{
$relativefilename=dol_sanitizePathName(GETPOST('file', 'none'));
if ($relativefilename)
{
$dirnametodelete = dirname($relativefilename);
$filetodelete = $dirins.'/'.$relativefilename;
$dirtodelete = $dirins.'/'.$dirnametodelete;
$result = dol_delete_file($filetodelete);
if (dol_is_dir_empty($dirtodelete)) dol_delete_dir($dirtodelete);
}
}
if ($dirins && $action == 'initobject' && $module && GETPOST('createtablearray', 'alpha')) if ($dirins && $action == 'initobject' && $module && GETPOST('createtablearray', 'alpha'))
{ {
$tablename = GETPOST('initfromtablename', 'alpha'); $tablename = GETPOST('initfromtablename', 'alpha');
@ -1067,6 +1220,7 @@ if ($module == 'initmodule')
print $langs->trans("EnterNameOfModuleDesc").'<br><br>'; print $langs->trans("EnterNameOfModuleDesc").'<br><br>';
print '<input type="text" name="modulename" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'">'; print '<input type="text" name="modulename" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'">';
print '<input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("Create")).'"'.($dirins?'':' disabled="disabled"').'>'; print '<input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("Create")).'"'.($dirins?'':' disabled="disabled"').'>';
print '</form>'; print '</form>';
} }
@ -1162,6 +1316,11 @@ elseif (! empty($module))
$head2[$h][2] = 'widgets'; $head2[$h][2] = 'widgets';
$h++; $h++;
$head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=cli&module='.$module.($forceddirread?'@'.$dirread:'');
$head2[$h][1] = $langs->trans("CLI");
$head2[$h][2] = 'cli';
$h++;
$head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=cron&module='.$module.($forceddirread?'@'.$dirread:''); $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=cron&module='.$module.($forceddirread?'@'.$dirread:'');
$head2[$h][1] = $langs->trans("CronList"); $head2[$h][1] = $langs->trans("CronList");
$head2[$h][2] = 'cron'; $head2[$h][2] = 'cron';
@ -1198,21 +1357,24 @@ elseif (! empty($module))
{ {
dol_fiche_head($head2, $tab, '', -1, ''); // Description - level 2 dol_fiche_head($head2, $tab, '', -1, ''); // Description - level 2
print $langs->trans("ModuleBuilderDesc".$tab).'<br><br>'; print '<span class="opacitymedium">'.$langs->trans("ModuleBuilderDesc".$tab).'</span><br><br>';
print '<table>';
print '<tr><td>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>'; print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>'; print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print '<br>'; print '</td></tr>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("ReadmeFile").' : <strong>'.$pathtofilereadme.'</strong>'; print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("ReadmeFile").' : <strong>'.$pathtofilereadme.'</strong>';
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&format=markdown&file='.urlencode($pathtofilereadme).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>'; print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&format=markdown&file='.urlencode($pathtofilereadme).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print '<br>'; print '</td></tr>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("ChangeLog").' : <strong>'.$pathtochangelog.'</strong>'; print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("ChangeLog").' : <strong>'.$pathtochangelog.'</strong>';
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&format=markdown&file='.urlencode($pathtochangelog).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>'; print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&format=markdown&file='.urlencode($pathtochangelog).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print '<br>'; print '</td></tr>';
print '<br>'; print '</table>';
print '<br>'; print '<br>';
print load_fiche_titre($langs->trans("DescriptorFile")); print load_fiche_titre($langs->trans("DescriptorFile"));
@ -1344,62 +1506,11 @@ elseif (! empty($module))
dol_fiche_head($head2, $tab, '', -1, ''); // Level 2 dol_fiche_head($head2, $tab, '', -1, ''); // Level 2
} }
if ($tab == 'specifications')
{
if ($action != 'editfile' || empty($file))
{
print $langs->trans("SpecDefDesc").'<br>';
print '<br>';
$specs=dol_dir_list(dol_buildpath($modulelowercase.'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/'));
foreach ($specs as $spec)
{
$pathtofile = $modulelowercase.'/doc/'.$spec['relativename'];
$format='asciidoc';
if (preg_match('/\.md$/i', $spec['name'])) $format='markdown';
print '<span class="fa fa-file-o"></span> '.$langs->trans("SpecificationFile").' : <strong>'.$pathtofile.'</strong>';
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print '<br>';
}
}
else
{
// Use MD or asciidoc
//print $langs->trans("UseAsciiDocFormat").'<br>';
$fullpathoffile=dol_buildpath($file, 0);
$content = file_get_contents($fullpathoffile);
// New module
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="savefile">';
print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
print '<input type="hidden" name="tab" value="'.$tab.'">';
print '<input type="hidden" name="module" value="'.$module.'">';
$doleditor=new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09')?GETPOST('format', 'aZ09'):'html'));
print '<br>';
print '<center>';
print '<input type="submit" class="button buttonforacesave" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
print ' &nbsp; ';
print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
print '</center>';
print '</form>';
}
}
if ($tab == 'languages') if ($tab == 'languages')
{ {
if ($action != 'editfile' || empty($file)) if ($action != 'editfile' || empty($file))
{ {
print $langs->trans("LanguageDefDesc").'<br>'; print '<span class="opacitymedium">'.$langs->trans("LanguageDefDesc").'</span><br>';
print '<br>'; print '<br>';
@ -1418,13 +1529,16 @@ elseif (! empty($module))
$langfiles=dol_dir_list(dol_buildpath($modulelowercase.'/langs', 0), 'files', 1, '\.lang$'); $langfiles=dol_dir_list(dol_buildpath($modulelowercase.'/langs', 0), 'files', 1, '\.lang$');
print '<table class="none">';
foreach ($langfiles as $langfile) foreach ($langfiles as $langfile)
{ {
$pathtofile = $modulelowercase.'/langs/'.$langfile['relativename']; $pathtofile = $modulelowercase.'/langs/'.$langfile['relativename'];
print '<span class="fa fa-file-o"></span> '.$langs->trans("LanguageFile").' '.basename(dirname($pathtofile)).' : <strong>'.$pathtofile.'</strong>'; print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("LanguageFile").' '.basename(dirname($pathtofile)).' : <strong>'.$pathtofile.'</strong>';
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>'; print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print '<br>'; print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=confirm_removefile&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
print '</td>';
} }
print '</table>';
} }
else else
{ {
@ -1516,7 +1630,7 @@ elseif (! empty($module))
print '<input type="hidden" name="tab" value="objects">'; print '<input type="hidden" name="tab" value="objects">';
print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">'; print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
print $langs->trans("EnterNameOfObjectDesc").'<br><br>'; print '<span class="opacitymedium">'.$langs->trans("EnterNameOfObjectDesc").'</span><br><br>';
print '<input type="text" name="objectname" value="'.dol_escape_htmltag(GETPOST('objectname', 'alpha')?GETPOST('objectname', 'alpha'):$modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ObjectKey")).'">'; print '<input type="text" name="objectname" value="'.dol_escape_htmltag(GETPOST('objectname', 'alpha')?GETPOST('objectname', 'alpha'):$modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ObjectKey")).'">';
print '<input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("Generate")).'"'.($dirins?'':' disabled="disabled"').'>'; print '<input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("Generate")).'"'.($dirins?'':' disabled="disabled"').'>';
@ -1852,6 +1966,55 @@ elseif (! empty($module))
} }
else else
{ {
if ($tab == 'specifications')
{
if ($action != 'editfile' || empty($file))
{
print '<span class="opacitymedium">'.$langs->trans("SpecDefDesc").'</span><br>';
print '<br>';
$specs=dol_dir_list(dol_buildpath($modulelowercase.'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/'));
foreach ($specs as $spec)
{
$pathtofile = $modulelowercase.'/doc/'.$spec['relativename'];
$format='asciidoc';
if (preg_match('/\.md$/i', $spec['name'])) $format='markdown';
print '<span class="fa fa-file-o"></span> '.$langs->trans("SpecificationFile").' : <strong>'.$pathtofile.'</strong>';
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print '<br>';
}
}
else
{
// Use MD or asciidoc
//print $langs->trans("UseAsciiDocFormat").'<br>';
$fullpathoffile=dol_buildpath($file, 0);
$content = file_get_contents($fullpathoffile);
// New module
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="savefile">';
print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
print '<input type="hidden" name="tab" value="'.$tab.'">';
print '<input type="hidden" name="module" value="'.$module.'">';
$doleditor=new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09')?GETPOST('format', 'aZ09'):'html'));
print '<br>';
print '<center>';
print '<input type="submit" class="button buttonforacesave" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
print ' &nbsp; ';
print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
print '</center>';
print '</form>';
}
}
print '<tr><td><span class="warning">'.$langs->trans('Property $field not found into the class. The class was probably not generated by modulebuilder.').'</warning></td></tr>'; print '<tr><td><span class="warning">'.$langs->trans('Property $field not found into the class. The class was probably not generated by modulebuilder.').'</warning></td></tr>';
} }
print '</table>'; print '</table>';
@ -1915,7 +2078,7 @@ elseif (! empty($module))
if ($action != 'editfile' || empty($file)) if ($action != 'editfile' || empty($file))
{ {
print $langs->trans("MenusDefDesc", '<a href="'.DOL_URL_ROOT.'/admin/menus/index.php">'.$langs->trans('Menus').'</a>').'<br>'; print '<span class="opacitymedium">'.$langs->trans("MenusDefDesc", '<a href="'.DOL_URL_ROOT.'/admin/menus/index.php">'.$langs->trans('Menus').'</a>').'</span><br>';
print '<br>'; print '<br>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>'; print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
@ -2040,7 +2203,7 @@ elseif (! empty($module))
if ($action != 'editfile' || empty($file)) if ($action != 'editfile' || empty($file))
{ {
print $langs->trans("PermissionsDefDesc", '<a href="'.DOL_URL_ROOT.'/admin/perms.php">'.$langs->trans('DefaultPermissions').'</a>').'<br>'; print '<span class="opacitymedium">'.$langs->trans("PermissionsDefDesc", '<a href="'.DOL_URL_ROOT.'/admin/perms.php">'.$langs->trans('DefaultPermissions').'</a>').'</span><br>';
print '<br>'; print '<br>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>'; print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
@ -2161,18 +2324,32 @@ elseif (! empty($module))
{ {
if ($action != 'editfile' || empty($file)) if ($action != 'editfile' || empty($file))
{ {
print $langs->trans("HooksDefDesc").'<br>'; print '<span class="opacitymedium">'.$langs->trans("HooksDefDesc").'</span><br>';
print '<br>'; print '<br>';
print '<table><tr><td>';
$pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>'; print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="">'.$pathtofile.'</strong>';
print '</td><td>';
print '<a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>'; print '<a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print '<br>'; print '</td></tr>';
print '<tr><td>';
$pathtohook = strtolower($module).'/class/actions_'.strtolower($module).'.class.php'; $pathtohook = strtolower($module).'/class/actions_'.strtolower($module).'.class.php';
print '<span class="fa fa-file-o"></span> '.$langs->trans("HooksFile").' : <strong>'.$pathtohook.'</strong>'; print '<span class="fa fa-file-o"></span> '.$langs->trans("HooksFile").' : ';
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format=php&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>'; if (dol_is_file($dirins.'/'.$pathtohook))
print '<br>'; {
print '<strong>'.$pathtohook.'</strong>';
print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format=php&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Edit"), 'edit').'</a></td>';
print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=confirm_removefile&format='.$format.'&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
}
else
{
print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=inithook&format=php&file='.urlencode($pathtohook).'"><input type="button" class="button" value="'.$langs->trans("Generate").'"></a></td>';
}
print '</tr>';
} }
else else
{ {
@ -2210,24 +2387,31 @@ elseif (! empty($module))
if ($action != 'editfile' || empty($file)) if ($action != 'editfile' || empty($file))
{ {
print $langs->trans("TriggerDefDesc").'<br>'; print '<span class="opacitymedium">'.$langs->trans("TriggerDefDesc").'</span><br>';
print '<br>'; print '<br>';
print '<table>';
if (! empty($triggers)) if (! empty($triggers))
{ {
foreach ($triggers as $trigger) foreach ($triggers as $trigger)
{ {
$pathtofile = $trigger['relpath']; $pathtofile = $trigger['relpath'];
print '<tr><td>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("TriggersFile").' : <strong>'.$pathtofile.'</strong>'; print '<span class="fa fa-file-o"></span> '.$langs->trans("TriggersFile").' : <strong>'.$pathtofile.'</strong>';
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>'; print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a></td>';
print '<br>'; print '<td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=confirm_removefile&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
print '</tr>';
} }
} }
else else
{ {
print $langs->trans("NoTrigger"); print '<tr><td>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("NoTrigger");
print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=inittrigger&format=php"><input type="button" class="button" value="'.$langs->trans("Generate").'"></a></td>';
print '</tr>';
} }
print '</table>';
} }
else else
{ {
@ -2264,21 +2448,116 @@ elseif (! empty($module))
if ($action != 'editfile' || empty($file)) if ($action != 'editfile' || empty($file))
{ {
if (! empty($widget)) print '<span class="opacitymedium">'.$langs->trans("WidgetDesc").'</span><br>';
print '<br>';
print '<table>';
if (! empty($widgets))
{ {
foreach ($widgets as $widget) foreach ($widgets as $widget)
{ {
$pathtofile = $widget['relpath']; $pathtofile = $widget['relpath'];
print '<span class="fa fa-file-o"></span> '.$langs->trans("WidgetFile").' : <strong>'.$pathtofile.'</strong>'; print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("WidgetFile").' : <strong>'.$pathtofile.'</strong>';
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>'; print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print '<br>'; print '</td>';
print '<td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=confirm_removefile&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
print '</tr>';
} }
} }
else else
{ {
print $langs->trans("NoWidget"); print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("NoWidget");
print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=initwidget&format=php"><input type="button" class="button" value="'.$langs->trans("Generate").'"></a>';
print '</td></tr>';
} }
print '</table>';
}
else
{
$fullpathoffile=dol_buildpath($file, 0);
$content = file_get_contents($fullpathoffile);
// New module
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="savefile">';
print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
print '<input type="hidden" name="tab" value="'.$tab.'">';
print '<input type="hidden" name="module" value="'.$module.'">';
$doleditor=new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09')?GETPOST('format', 'aZ09'):'html'));
print '<br>';
print '<center>';
print '<input type="submit" class="button buttonforacesave" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
print ' &nbsp; ';
print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
print '</center>';
print '</form>';
}
}
if ($tab == 'cli')
{
$clifiles = array();
$i = 0;
$dircli=array('/'.strtolower($module).'/scripts');
foreach($dircli as $reldir)
{
$dir=dol_buildpath($reldir, 0);
$newdir=dol_osencode($dir);
// Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php at each call)
if (! is_dir($newdir)) continue;
$handle=opendir($newdir);
if (is_resource($handle))
{
while (($tmpfile = readdir($handle))!==false)
{
if (is_readable($newdir.'/'.$file) && preg_match('/^(.+)\.php/', $tmpfile, $reg))
{
if (preg_match('/\.back$/', $tmpfile)) continue;
$clifiles[$i]['relpath'] = preg_replace('/^\//', '', $reldir).'/'.$tmpfile;
$i++;
}
}
closedir($handle);
}
}
if ($action != 'editfile' || empty($file))
{
print '<span class="opacitymedium">'.$langs->trans("CLIDesc").'</span><br>';
print '<br>';
print '<table>';
if (! empty($clifiles))
{
foreach ($clifiles as $clifile)
{
$pathtofile = $clifile['relpath'];
print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("CLIFile").' : <strong>'.$pathtofile.'</strong>';
print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a></td>';
print '<td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=confirm_removefile&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
print '</tr>';
}
}
else
{
print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("NoCLIFile");
print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=initcli&format=php"><input type="button" class="button" value="'.$langs->trans("Generate").'"></a>';
print '</td></tr>';
}
print '</table>';
} }
else else
{ {
@ -2315,7 +2594,7 @@ elseif (! empty($module))
if ($action != 'editfile' || empty($file)) if ($action != 'editfile' || empty($file))
{ {
print $langs->trans("CronJobDefDesc", '<a href="'.DOL_URL_ROOT.'/cron/list.php?status=-2">'.$langs->transnoentities('CronList').'</a>').'<br>'; print '<span class="opacitymedium">'.$langs->trans("CronJobDefDesc", '<a href="'.DOL_URL_ROOT.'/cron/list.php?status=-2">'.$langs->transnoentities('CronList').'</a>').'</span><br>';
print '<br>'; print '<br>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>'; print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
@ -2429,6 +2708,70 @@ elseif (! empty($module))
} }
} }
if ($tab == 'specifications')
{
if ($action != 'editfile' || empty($file))
{
print '<span class="opacitymedium">'.$langs->trans("SpecDefDesc").'</span><br>';
print '<br>';
$specs=dol_dir_list(dol_buildpath($modulelowercase.'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/'));
print '<table>';
if (is_array($specs) && ! empty($specs))
{
foreach ($specs as $spec)
{
$pathtofile = $modulelowercase.'/doc/'.$spec['relativename'];
$format='asciidoc';
if (preg_match('/\.md$/i', $spec['name'])) $format='markdown';
print '<tr><td>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("SpecificationFile").' : <strong>'.$pathtofile.'</strong>';
print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a></td>';
print '<td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=confirm_removefile&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
print '</tr>';
}
}
else
{
print '<tr><td>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("FileNotYetGenerated");
print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=initdoc&format=php"><input type="button" class="button" value="'.$langs->trans("Generate").'"></a></td>';
print '</tr>';
}
print '</table>';
}
else
{
// Use MD or asciidoc
//print $langs->trans("UseAsciiDocFormat").'<br>';
$fullpathoffile=dol_buildpath($file, 0);
$content = file_get_contents($fullpathoffile);
// New module
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="savefile">';
print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
print '<input type="hidden" name="tab" value="'.$tab.'">';
print '<input type="hidden" name="module" value="'.$module.'">';
$doleditor=new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09')?GETPOST('format', 'aZ09'):'html'));
print '<br>';
print '<center>';
print '<input type="submit" class="button buttonforacesave" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
print ' &nbsp; ';
print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
print '</center>';
print '</form>';
}
}
if ($tab == 'buildpackage') if ($tab == 'buildpackage')
{ {
if (! class_exists('ZipArchive') && ! defined('ODTPHP_PATHTOPCLZIP')) if (! class_exists('ZipArchive') && ! defined('ODTPHP_PATHTOPCLZIP'))

View File

@ -87,14 +87,8 @@ Licenses
### Main code ### Main code
![GPLv3 logo](img/gplv3.png) GPLv3 or (at your option) any later version. See file COPYING for more information.
GPLv3 or (at your option) any later version.
See file COPYING for more information.
#### Documentation #### Documentation
All texts and readmes. All texts and readmes are licensed under GFDL.
![GFDL logo](img/gfdl.png)

View File

@ -18,7 +18,7 @@
*/ */
/** /**
* \file modulebuilder/template/core/boxes/mymodulewidget1.php * \file htdocs/modulebuilder/template/core/boxes/mymodulewidget1.php
* \ingroup mymodule * \ingroup mymodule
* \brief Widget provided by MyModule * \brief Widget provided by MyModule
* *

View File

@ -91,14 +91,14 @@ class modMyModule extends DolibarrModules
'substitutions' => 1, 'substitutions' => 1,
// Set this to 1 if module has its own menus handler directory (core/menus) // Set this to 1 if module has its own menus handler directory (core/menus)
'menus' => 0, 'menus' => 0,
// Set this to 1 if module has its own theme directory (theme)
'theme' => 0,
// Set this to 1 if module overwrite template dir (core/tpl) // Set this to 1 if module overwrite template dir (core/tpl)
'tpl' => 0, 'tpl' => 0,
// Set this to 1 if module has its own barcode directory (core/modules/barcode) // Set this to 1 if module has its own barcode directory (core/modules/barcode)
'barcode' => 0, 'barcode' => 0,
// Set this to 1 if module has its own models directory (core/modules/xxx) // Set this to 1 if module has its own models directory (core/modules/xxx)
'models' => 0, 'models' => 0,
// Set this to 1 if module has its own theme directory (theme)
'theme' => 0,
// Set this to relative path of css file if module has its own css file // Set this to relative path of css file if module has its own css file
'css' => array( 'css' => array(
'/mymodule/css/mymodule.css.php', '/mymodule/css/mymodule.css.php',

View File

@ -13,7 +13,7 @@ This document describe specifications of module MyModule
[options="header",format="csv"] [options="header",format="csv"]
|=== |===
Author, Date, Version Author, Date, Version
---Put here your own copyright and developer email---, Date YYY-MM-DD, Version 1.0 ---Put here your own copyright and developer email---, Date YYYY-MM-DD, Version 1.0
|=== |===

View File

@ -39,7 +39,7 @@ external documents stored in the *Appendices* directory accompanying this docume
[options="header",format="csv"] [options="header",format="csv"]
|=== |===
Author, Date, Version Author, Date, Version
John Doe, Date YYY-MM-DD, Version 1.0 John Doe, Date YYYY-MM-DD, Version 1.0
|=== |===

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -18,9 +18,9 @@
*/ */
/** /**
* \file htdocs/modulebuilder/template/scripts/myobject.php * \file htdocs/modulebuilder/template/scripts/mymodule.php
* \ingroup mymodule * \ingroup mymodule
* \brief This file is an example for a command line script to work on MyObject * \brief This file is an example for a command line script for module MyModule
*/ */
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
@ -81,8 +81,8 @@ $db->begin();
// Examples for manipulating class MyObject // Examples for manipulating class MyObject
dol_include_once("/mymodule/class/myobject.class.php"); //dol_include_once("/mymodule/class/myobject.class.php");
$myobject=new MyObject($db); //$myobject=new MyObject($db);
// Example for inserting creating object in database // Example for inserting creating object in database
/* /*