Restore lost file and better generation of modules

This commit is contained in:
Laurent Destailleur 2017-06-02 23:02:48 +02:00
parent 5e29817910
commit 66420d0e80
6 changed files with 173 additions and 71 deletions

View File

@ -0,0 +1,86 @@
<?php
/* Copyright (C) 2014 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
* 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 <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**
* \file htdocs/core/actions_setnotes.inc.php
* \brief Code for actions on setting notes of object page
*/
// $action must be defined
// $_FILES may be defined
// $nomessageinsetmoduleoptions can be set to 1
// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...)
if ($action == 'setModuleOptions')
{
$db->begin();
// Process common param fields
foreach($_POST as $key => $val)
{
if (preg_match('/^param(\d*)$/', $key, $reg)) // Works for POST['param'], POST['param1'], POST['param2'], ...
{
$param=GETPOST("param".$reg[1],'alpha');
$value=GETPOST("value".$reg[1],'alpha');
if ($param)
{
$res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity);
if (! $res > 0) $error++;
}
}
}
// Process upload fields
if (GETPOST('upload','alpha') && GETPOST('keyforuploaddir','aZ09'))
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$keyforuploaddir=GETPOST('keyforuploaddir','aZ09');
$listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->$keyforuploaddir)));
foreach($listofdir as $key=>$tmpdir)
{
$tmpdir=trim($tmpdir);
$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
if (! $tmpdir) {
unset($listofdir[$key]); continue;
}
if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
else
{
$upload_dir=$tmpdir;
}
}
if ($upload_dir)
{
$result = dol_add_file_process($upload_dir, 0, 1, 'uploadfile', '');
if ($result <= 0) $error++;
}
}
if (! $error)
{
$db->commit();
if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
}
else
{
$db->rollback();
if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
}
}

View File

@ -133,10 +133,12 @@ class HookManager
if (in_array( if (in_array(
$method, $method,
array( array(
'addMoreActionsButtons', 'addCalendarChoice',
'addMoreActionsButtons',
'addMoreMassActions',
'addSearchEntry', 'addSearchEntry',
'addStatisticLine', 'addStatisticLine',
'deleteFile', 'deleteFile',
'doActions', 'doActions',
'formCreateThirdpartyOptions', 'formCreateThirdpartyOptions',
'formObjectOptions', 'formObjectOptions',
@ -169,7 +171,6 @@ class HookManager
'printSearchForm', 'printSearchForm',
'printTabsHead', 'printTabsHead',
'formatEvent', 'formatEvent',
'addCalendarChoice',
'printObjectLine', 'printObjectLine',
'printObjectSubLine', 'printObjectSubLine',
'createDictionaryFieldList', 'createDictionaryFieldList',
@ -181,14 +182,16 @@ class HookManager
if ($method == 'insertExtraFields') if ($method == 'insertExtraFields')
{ {
$hooktype='returnvalue'; // deprecated. TODO Remove all code with "executeHooks('insertExtraFields'" as soon as there is a trigger available. $hooktype='returnvalue'; // @deprecated. TODO Remove all code with "executeHooks('insertExtraFields'" as soon as there is a trigger available.
dol_syslog("Warning: The hook 'insertExtraFields' is deprecated and must not be used. Use instead trigger on CRUD event (ask it to dev team if not implemented)", LOG_WARNING); dol_syslog("Warning: The hook 'insertExtraFields' is deprecated and must not be used. Use instead trigger on CRUD event (ask it to dev team if not implemented)", LOG_WARNING);
} }
// Init return properties
$this->resPrint=''; $this->resArray=array();
// Loop on each hook to qualify modules that have declared context // Loop on each hook to qualify modules that have declared context
$modulealreadyexecuted=array(); $modulealreadyexecuted=array();
$resaction=0; $error=0; $result=''; $resaction=0; $error=0; $result='';
$this->resPrint=''; $this->resArray=array();
foreach($this->hooks as $context => $modules) // $this->hooks is an array with context as key and value is an array of modules that handle this context foreach($this->hooks as $context => $modules) // $this->hooks is an array with context as key and value is an array of modules that handle this context
{ {
if (! empty($modules)) if (! empty($modules))

View File

@ -545,11 +545,20 @@ class Form
$disabled=0; $disabled=0;
$ret='<div class="centpercent center">'; $ret='<div class="centpercent center">';
$ret.='<select data-role="none" class="flat'.(empty($conf->use_javascript_ajax)?'':' hideobject').' massaction massactionselect" name="massaction"'.($disabled?' disabled="disabled"':'').'>'; $ret.='<select data-role="none" class="flat'.(empty($conf->use_javascript_ajax)?'':' hideobject').' massaction massactionselect" name="massaction"'.($disabled?' disabled="disabled"':'').'>';
$ret.='<option value="0"'.($disabled?' disabled="disabled"':'').'>-- '.$langs->trans("SelectAction").' --</option>';
foreach($arrayofaction as $code => $label) // Complete list with data from external modules. THe module can use $_SERVER['PHP_SELF'] to know on which page we are, or use the $parameters['context'] completed by executeHooks.
{ $parameters=array();
$ret.='<option value="'.$code.'"'.($disabled?' disabled="disabled"':'').'>'.$label.'</option>'; $reshook=$hookmanager->executeHooks('addMoreMassActions',$parameters); // Note that $action and $object may have been modified by hook
} if (empty($reshook))
{
$ret.='<option value="0"'.($disabled?' disabled="disabled"':'').'>-- '.$langs->trans("SelectAction").' --</option>';
foreach($arrayofaction as $code => $label)
{
$ret.='<option value="'.$code.'"'.($disabled?' disabled="disabled"':'').'>'.$label.'</option>';
}
}
$ret.=$hookmanager->resPrint;
$ret.='</select>'; $ret.='</select>';
// Warning: if you set submit button to disabled, post using 'Enter' will no more work. // Warning: if you set submit button to disabled, post using 'Enter' will no more work.
$ret.='<input type="submit" data-role="none" name="confirmmassaction" class="button'.(empty($conf->use_javascript_ajax)?'':' hideobject').' massaction massactionconfirmed" value="'.dol_escape_htmltag($langs->trans("Confirm")).'">'; $ret.='<input type="submit" data-role="none" name="confirmmassaction" class="button'.(empty($conf->use_javascript_ajax)?'':' hideobject').' massaction massactionconfirmed" value="'.dol_escape_htmltag($langs->trans("Confirm")).'">';

View File

@ -538,8 +538,8 @@ class DolibarrModules // Can not be abstract, because we need to insta
return $langs->trans("Module".$this->numero."Name"); return $langs->trans("Module".$this->numero."Name");
} }
else else
{ {
// If module name translation using it's unique id does not exists, we take use its name to find translation // If module name translation using it's unique id does not exists, we try to use its name to find translation
if (is_array($this->langfiles)) if (is_array($this->langfiles))
{ {
foreach($this->langfiles as $val) foreach($this->langfiles as $val)
@ -547,6 +547,14 @@ class DolibarrModules // Can not be abstract, because we need to insta
if ($val) $langs->load($val); if ($val) $langs->load($val);
} }
} }
if ($langs->trans("Module".$this->name."Name") != ("Module".$this->name."Name"))
{
// If module name translation exists
return $langs->trans("Module".$this->name."Name");
}
// Last change with simple product label
return $langs->trans($this->name); return $langs->trans($this->name);
} }
} }

View File

@ -18,12 +18,10 @@
# Generic # Generic
# #
# Module label 'ModuleXXXName' # Module label 'ModuleMyModuleName'
# (where XXX is value of numeric property 'numero' of module) ModuleMyModuleName = My module
Module500000Name = My module # Module description 'ModuleMyModuleDesc'
# Module description 'ModuleXXXDesc' ModuleMyModuleDesc = My module description
# (where XXX is value of numeric property 'numero' of module)
Module500000Desc = My module description
# #
# Admin page # Admin page

View File

@ -18,12 +18,10 @@
# Générique # Générique
# #
# Module label 'ModuleXXXName' # Module label 'ModuleMyModuleName'
# (where XXX is value of numeric property 'numero' of module) ModuleMyModuleName = Mon module
Module500000Name = Mon module # Module description 'ModuleMyModuleDesc'
# Module description 'ModuleXXXDesc' ModuleMyModuleDesc = Description de mon module
# (where XXX is value of numeric property 'numero' of module)
Module500000Desc = Description de mon module
# #
# Page d'administration # Page d'administration