Enhance modulebuilder

This commit is contained in:
Laurent Destailleur 2017-08-26 15:22:13 +02:00
parent a9e7f8b9e6
commit f2a437fa89
11 changed files with 159 additions and 56 deletions

View File

@ -495,7 +495,6 @@ print "<br>";
/*
* Other options
*
*/
print load_fiche_titre($langs->trans("OtherOptions"),'','');

View File

@ -101,25 +101,24 @@ if ($action == 'edit')
print '<input type="hidden" name="action" value="update">';
clearstatcache();
$var=true;
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
print '<tr class="oddeven"><td>';
print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_UNIT"),$langs->trans("ParameterActiveForNextInputOnly"));
print '</td><td><input class="flat" name="MAIN_MAX_DECIMALS_UNIT" size="3" value="' . $conf->global->MAIN_MAX_DECIMALS_UNIT . '"></td></tr>';
print '<tr class="oddeven"><td>';
print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_TOT"),$langs->trans("ParameterActiveForNextInputOnly"));
print '</td><td><input class="flat" name="MAIN_MAX_DECIMALS_TOT" size="3" value="' . $conf->global->MAIN_MAX_DECIMALS_TOT . '"></td></tr>';
print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAX_DECIMALS_SHOWN").'</td><td><input class="flat" name="MAIN_MAX_DECIMALS_SHOWN" size="3" value="' . $conf->global->MAIN_MAX_DECIMALS_SHOWN . '"></td></tr>';
print '<tr class="oddeven"><td>';
print $form->textwithpicto($langs->trans("MAIN_ROUNDING_RULE_TOT"),$langs->trans("ParameterActiveForNextInputOnly"));
print '</td><td><input class="flat" name="MAIN_ROUNDING_RULE_TOT" size="3" value="' . $conf->global->MAIN_ROUNDING_RULE_TOT . '"></td></tr>';
@ -135,25 +134,23 @@ if ($action == 'edit')
}
else
{
$var=true;
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
print '<tr class="oddeven"><td>';
print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_UNIT"),$langs->trans("ParameterActiveForNextInputOnly"));
print '</td><td align="right">'.$conf->global->MAIN_MAX_DECIMALS_UNIT.'</td></tr>';
print '<tr class="oddeven"><td>';
print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_TOT"),$langs->trans("ParameterActiveForNextInputOnly"));
print '</td><td align="right">'.$conf->global->MAIN_MAX_DECIMALS_TOT.'</td></tr>';
print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAX_DECIMALS_SHOWN").'</td><td align="right">'.$conf->global->MAIN_MAX_DECIMALS_SHOWN.'</td></tr>';
print '<tr class="oddeven"><td>';
print $form->textwithpicto($langs->trans("MAIN_ROUNDING_RULE_TOT"),$langs->trans("ParameterActiveForNextInputOnly"));
print '</td><td align="right">'.$conf->global->MAIN_ROUNDING_RULE_TOT.'</td></tr>';

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2014 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2014-2017 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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
@ -17,15 +17,43 @@
*/
/**
* \file htdocs/core/actions_setnotes.inc.php
* \file htdocs/core/actions_setmoduleoptions.inc.php
* \brief Code for actions on setting notes of object page
*/
// $action must be defined
// $_FILES may be defined
// $arrayofparameters must be set for action 'update'
// $nomessageinupdate can be set to 1
// $nomessageinsetmoduleoptions can be set to 1
if ($action == 'update' && is_array($arrayofparameters))
{
$db->begin();
$ok=True;
foreach($arrayofparameters as $key => $val)
{
$result=dolibarr_set_const($db,$key,GETPOST($key, 'alpha'),'chaine',0,'',$conf->entity);
if ($result < 0)
{
$ok=False;
break;
}
}
if (! $error)
{
$db->commit();
if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
}
else
{
$db->rollback();
if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
}
}
// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...)
if ($action == 'setModuleOptions')
{

View File

@ -1929,7 +1929,7 @@ function dol_most_recent_file($dir,$regexfilter='',$excludefilter=array('(\.meta
function dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser='', $refname='', $mode='read')
{
global $user, $conf, $db;
global $dolibarr_main_data_root;
global $dolibarr_main_data_root, $dolibarr_main_document_root_alt;
if (! is_object($fuser)) $fuser=$user;
@ -1965,6 +1965,16 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity,
$accessallowed=($user->admin && basename($original_file) == $original_file && preg_match('/^dolibarr.*\.log$/', basename($original_file)));
$original_file=$dolibarr_main_data_root.'/'.$original_file;
}
// Wrapping for *.zip files, like when used with url http://.../document.php?modulepart=packages&file=module_myfile.zip
elseif ($modulepart == 'packages' && !empty($dolibarr_main_data_root))
{
// Dir for custom dirs
$tmp=explode(',', $dolibarr_main_document_root_alt);
$dirins = $tmp[0];
$accessallowed=($user->admin && preg_match('/^module_.*\.zip$/', basename($original_file)));
$original_file=$dirins.'/'.$original_file;
}
// Wrapping for some images
elseif (($modulepart == 'mycompany' || $modulepart == 'companylogo') && !empty($conf->mycompany->dir_output))
{

View File

@ -55,7 +55,7 @@ CronSaveSucess=Save successfully
CronNote=Comment
CronFieldMandatory=Fields %s is mandatory
CronErrEndDateStartDt=End date cannot be before start date
StatusAtInstall=Status at installation
StatusAtInstall=Status at module installation
CronStatusActiveBtn=Enable
CronStatusInactiveBtn=Disable
CronTaskInactive=This job is disabled

View File

@ -58,4 +58,6 @@ SqlFileKey=Sql file for keys
AnObjectAlreadyExistWithThisNameAndDiffCase=An object already exists with this name and a different case
UseAsciiDocFormat=You can use Markdown format, but it is recommanded to use Asciidoc format (Comparison between .md and .asciidoc: http://asciidoctor.org/docs/user-manual/#compared-to-markdown)
IsAMeasure=Is a measure
DirScanned=Directory scanned
DirScanned=Directory scanned
NoTrigger=No trigger
NoWidget=No widget

View File

@ -149,7 +149,7 @@ if ($dirins && $action == 'initmodule' && $modulename)
'my module'=>$modulename,
'Mon module'=>$modulename,
'mon module'=>$modulename,
'htdocs/modulebuilder/template/'=>strtolower($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.'>':'')
);
@ -508,11 +508,11 @@ if ($dirins && $action == 'generatepackage')
$FILENAMEZIP="module_".$modulelowercase.'-'.$arrayversion[0].'.'.$arrayversion[1].($arrayversion[2]?".".$arrayversion[2]:"").".zip";
$dirofmodule = dol_buildpath($modulelowercase, 0).'/bin';
$outputfile = $dirofmodule.'/'.$FILENAMEZIP;
$outputfilezip = $dirofmodule.'/'.$FILENAMEZIP;
if ($dirofmodule)
{
if (! dol_is_dir($dirofmodule)) dol_mkdir($dirofmodule);
$result = dol_compress_dir($dir, $outputfile, 'zip');
$result = dol_compress_dir($dir, $outputfilezip, 'zip');
}
else
{
@ -521,13 +521,13 @@ if ($dirins && $action == 'generatepackage')
if ($result > 0)
{
setEventMessages($langs->trans("ZipFileGeneratedInto", $outputfile), null);
setEventMessages($langs->trans("ZipFileGeneratedInto", $outputfilezip), null);
}
else
{
$error++;
$langs->load("errors");
setEventMessages($langs->trans("ErrorFailToGenerateFile", $outputfile), null, 'errors');
setEventMessages($langs->trans("ErrorFailToGenerateFile", $outputfilezip), null, 'errors');
}
}
else
@ -576,7 +576,7 @@ if ($dirins && $action == 'generatedoc')
$FILENAMEDOC=$modulelowercase.'.html';
$dirofmodule = dol_buildpath($modulelowercase, 0).'/doc';
$outputfile = $dirofmodule.'/'.$FILENAMEDOC;
$outputfiledoc = $dirofmodule.'/'.$FILENAMEDOC;
if ($dirofmodule)
{
if (! dol_is_dir($dirofmodule)) dol_mkdir($dirofmodule);
@ -591,13 +591,13 @@ if ($dirins && $action == 'generatedoc')
if ($result > 0)
{
setEventMessages($langs->trans("DocFileGeneratedInto", $outputfile), null);
setEventMessages($langs->trans("DocFileGeneratedInto", $outputfiledoc), null);
}
else
{
$error++;
$langs->load("errors");
setEventMessages($langs->trans("ErrorFailToGenerateFile", $outputfile), null, 'errors');
setEventMessages($langs->trans("ErrorFailToGenerateFile", $outputfiledoc), null, 'errors');
}
}
else
@ -1578,14 +1578,21 @@ elseif (! empty($module))
if ($action != 'editfile' || empty($file))
{
foreach ($triggers as $trigger)
{
$pathtofile = $trigger['relpath'];
if (! empty($triggers))
{
foreach ($triggers as $trigger)
{
$pathtofile = $trigger['relpath'];
print '<span class="fa fa-file"></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 '<br>';
}
print '<span class="fa fa-file"></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 '<br>';
}
}
else
{
print $langs->trans("NoTrigger");
}
}
else
{
@ -1622,13 +1629,20 @@ elseif (! empty($module))
if ($action != 'editfile' || empty($file))
{
foreach ($widgets as $widget)
{
$pathtofile = $widget['relpath'];
if (! empty($widget))
{
foreach ($widgets as $widget)
{
$pathtofile = $widget['relpath'];
print '<span class="fa fa-file"></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 '<br>';
print '<span class="fa fa-file"></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 '<br>';
}
}
else
{
print $langs->trans("NoWidget");
}
}
else
@ -1811,7 +1825,7 @@ elseif (! empty($module))
if (count($arrayversion))
{
$FILENAMEZIP="module_".$modulelowercase.'-'.$arrayversion[0].'.'.$arrayversion[1].($arrayversion[2]?".".$arrayversion[2]:"").".zip";
$outputfile = dol_buildpath($modulelowercase, 0).'/bin/'.$FILENAMEZIP;
$outputfilezip = dol_buildpath($modulelowercase, 0).'/bin/'.$FILENAMEZIP;
$FILENAMEDOC=$modulelowercase.'.html';
$outputfiledoc = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOC;
@ -1820,10 +1834,11 @@ elseif (! empty($module))
print '<br>';
print '<span class="fa fa-file"></span> '. $langs->trans("PathToModulePackage") . ' : ';
if (! dol_is_file($outputfile)) print '<strong>'.$langs->trans("FileNotYetGenerated").'</strong>';
if (! dol_is_file($outputfilezip)) print '<strong>'.$langs->trans("FileNotYetGenerated").'</strong>';
else {
print '<strong>'.$outputfile.'</strong>';
print ' ('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfile), 'dayhour').')';
$relativepath = $modulelowercase.'/bin/'.$FILENAMEZIP;
print '<strong><a href="'.DOL_URL_ROOT.'/document.php?modulepart=packages&file='.urlencode($relativepath).'">'.$outputfilezip.'</a></strong>';
print ' ('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfilezip), 'dayhour').')';
}
print '</strong><br>';

View File

@ -81,16 +81,11 @@ $head = mymoduleAdminPrepareHead();
dol_fiche_head(
$head,
'about',
$langs->trans("MyModuleName"),
$langs->trans("ModuleMyModuleName"),
0,
'mymodule@mymodule'
);
// About page goes here
echo $langs->trans("MyModuleAboutPage");
echo '<br>';
dol_include_once('/mymodule/core/modules/modMyModule.class.php');
$tmpmodule = new modMyModule($db);
print $tmpmodule->getDescLong();

View File

@ -42,8 +42,9 @@ global $langs, $user;
require_once DOL_DOCUMENT_ROOT . "/core/lib/admin.lib.php";
require_once '../lib/mymodule.lib.php';
//require_once "../class/myclass.class.php";
// Translations
$langs->load("mymodule@mymodule");
$langs->loadLangs(array("admin", "mymodule@mymodule"));
// Access control
if (! $user->admin) accessforbidden();
@ -51,6 +52,8 @@ if (! $user->admin) accessforbidden();
// Parameters
$action = GETPOST('action', 'alpha');
$arrayofparameters=array('MYMODULE_MYPARAM1'=>'1', 'MYMODULE_MYPARAM2'=>'2');
/*
* Actions
@ -76,14 +79,62 @@ $head = mymoduleAdminPrepareHead();
dol_fiche_head(
$head,
'settings',
$langs->trans("Module500000Name"),
0,
$langs->trans("ModuleMyModuleName"),
-1,
"mymodule@mymodule"
);
// Setup page goes here
echo $langs->trans("MyModuleSetupPage");
if ($action == 'edit')
{
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
foreach($arrayofparameters as $key => $val)
{
print '<tr class="oddeven"><td>';
print $form->textwithpicto($langs->trans($key),$langs->trans($key.'Tooltip'));
print '</td><td><input class="flat" name="'.$key.'" size="3" value="' . $conf->global->$key . '"></td></tr>';
}
print '</table>';
print '<br><div class="center">';
print '<input class="button" type="submit" value="'.$langs->trans("Save").'">';
print '</div>';
print '</form>';
print '<br>';
}
else
{
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
foreach($arrayofparameters as $key => $val)
{
print '<tr class="oddeven"><td>';
print $form->textwithpicto($langs->trans($key),$langs->trans($key.'Tooltip'));
print '</td><td>' . $conf->global->$key . '</td></tr>';
}
print '</table>';
print '<div class="tabsAction">';
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
print '</div>';
}
// Page end
dol_fiche_end();
llxFooter();
$db->close();

View File

@ -311,10 +311,11 @@ class modMyModule extends DolibarrModules
include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafields = new ExtraFields($this->db);
//$result1=$extrafields->addExtraField('myattr1', "New Attr 1 label", 'boolean', 1, 3, 'thirdparty');
//$result2=$extrafields->addExtraField('myattr2', "New Attr 2 label", 'string', 1, 10, 'project');
//$param=array('options'=>array('code1'=>'Val1','code2'=>'Val2','code3'=>'Val3'));
//$result3=$extrafields->addExtraField('myattr3', "New Attr 3 label", 'select', 1, 3, 'thirdparty', 0, 1, '', $param, 1);
$result1=$extrafields->addExtraField('myattr1', "New Attr 1 label", 'boolean', 1, 3, 'thirdparty');
//$result2=$extrafields->addExtraField('myattr2', "New Attr 2 label", 'varchar', 1, 10, 'project');
//$result3=$extrafields->addExtraField('myattr3', "New Attr 3 label", 'varchar', 1, 10, 'bank_account');
//$result4=$extrafields->addExtraField('myattr4', "New Attr 4 label", 'select', 1, 3, 'thirdparty', 0, 1, '', array('options'=>array('code1'=>'Val1','code2'=>'Val2','code3'=>'Val3')), 1);
//$result5=$extrafields->addExtraField('myattr5', "New Attr 5 label", 'text', 1, 10, 'user');
$sql = array();

View File

@ -28,6 +28,11 @@ ModuleMyModuleDesc = My module description
MyModuleSetup = My module setup
Settings = Settings
MyModuleSetupPage = My module setup page
MYMODULE_MYPARAM1 = My param 1
MYMODULE_MYPARAM1Tooltip = My param 1 tooltip
MYMODULE_MYPARAM2=My param 2
MYMODULE_MYPARAM2Tooltip=My param 2 tooltip
#
# About page