diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index a1c35515f9d..32ad40ea6c6 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -60,6 +60,8 @@ HooksFile=File for hooks code ArrayOfKeyValues=Array of key-val ArrayOfKeyValuesDesc=Array of keys and values if field is a combo list with fixed values WidgetFile=Widget file +CSSFile=CSS file +JSFile=Javascript file ReadmeFile=Readme file ChangeLog=ChangeLog file TestClassFile=File for PHP Unit Test class @@ -109,6 +111,8 @@ ContentOfREADMECustomized=Note: The content of the README.md file has been repla RealPathOfModule=Real path of module ContentCantBeEmpty=Content of file can't be empty WidgetDesc=You can generate and edit here the widgets that will be embedded with your module. +CSSDesc=You can generate and edit here a file with personalized CSS embedded with your module. +JSDesc=You can generate and edit here a file with personalized Javascript 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 diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index a90fb5c3331..50de723d7be 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -153,6 +153,12 @@ if ($dirins && $action == 'initmodule' && $modulename) dol_delete_file($destdir.'/class/api_'.strtolower($modulename).'.class.php'); dol_delete_dir($destdir.'/class'); + dol_delete_file($destdir.'/css/'.strtolower($modulename).'.css.php'); + dol_delete_dir($destdir.'/css'); + + dol_delete_file($destdir.'/js/'.strtolower($modulename).'.js.php'); + dol_delete_dir($destdir.'/js'); + dol_delete_file($destdir.'/scripts/'.strtolower($modulename).'.php'); dol_delete_dir($destdir.'/scripts'); @@ -427,6 +433,64 @@ if ($dirins && $action == 'initwidget' && !empty($module)) dolReplaceInFile($destfile, $arrayreplacement); } } +if ($dirins && $action == 'initcss' && !empty($module)) +{ + dol_mkdir($dirins.'/'.strtolower($module).'/css'); + $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template'; + $srcfile = $srcdir.'/css/mymodule.css.php'; + $destfile = $dirins.'/'.strtolower($module).'/css/mymodule/'.strtolower($module).'.css.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 == 'initjs' && !empty($module)) +{ + dol_mkdir($dirins.'/'.strtolower($module).'/js'); + $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template'; + $srcfile = $srcdir.'/js/mymodule.js.php'; + $destfile = $dirins.'/'.strtolower($module).'/css/mymodule/'.strtolower($module).'.js.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'); @@ -1574,6 +1638,16 @@ elseif (! empty($module)) $head2[$h][2] = 'widgets'; $h++; + $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=css&module='.$module.($forceddirread?'@'.$dirread:''); + $head2[$h][1] = $langs->trans("CSS"); + $head2[$h][2] = 'css'; + $h++; + + $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=js&module='.$module.($forceddirread?'@'.$dirread:''); + $head2[$h][1] = $langs->trans("JS"); + $head2[$h][2] = 'js'; + $h++; + $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=cli&module='.$module.($forceddirread?'@'.$dirread:''); $head2[$h][1] = $langs->trans("CLI"); $head2[$h][2] = 'cli'; @@ -2755,6 +2829,110 @@ elseif (! empty($module)) } } + if ($tab == 'css') + { + if ($action != 'editfile' || empty($file)) + { + print ''.$langs->trans("CSSDesc").'
'; + print '
'; + + print ''; + + print ''; + print ''; + } + else + { + print ''.$langs->trans("FileNotYetGenerated").''; + print ''; + } + print ''; + } + else + { + $fullpathoffile=dol_buildpath($file, 0); + + $content = file_get_contents($fullpathoffile); + + // New module + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $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 '
'; + print '
'; + print ''; + print '   '; + print ''; + print '
'; + + print ''; + } + } + + if ($tab == 'js') + { + if ($action != 'editfile' || empty($file)) + { + print ''.$langs->trans("JSDesc").'
'; + print '
'; + + print '
'; + $pathtohook = strtolower($module).'/css/'.strtolower($module).'.css.php'; + print ' '.$langs->trans("CSSFile").' : '; + if (dol_is_file($dirins.'/'.$pathtohook)) + { + print ''.$pathtohook.''; + print ''.img_picto($langs->trans("Edit"), 'edit').''.img_picto($langs->trans("Delete"), 'delete').'
'; + + print ''; + print ''; + } + else + { + print ''.$langs->trans("FileNotYetGenerated").''; + print ''; + } + print ''; + } + else + { + $fullpathoffile=dol_buildpath($file, 0); + + $content = file_get_contents($fullpathoffile); + + // New module + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $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 '
'; + print '
'; + print ''; + print '   '; + print ''; + print '
'; + + print ''; + } + } + if ($tab == 'widgets') { require_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
'; + $pathtohook = strtolower($module).'/js/'.strtolower($module).'.js.php'; + print ' '.$langs->trans("JSFile").' : '; + if (dol_is_file($dirins.'/'.$pathtohook)) + { + print ''.$pathtohook.''; + print ''.img_picto($langs->trans("Edit"), 'edit').''.img_picto($langs->trans("Delete"), 'delete').'