Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2026-04-16 21:17:14 +02:00
commit 700e4095ce
9 changed files with 172 additions and 37 deletions

View file

@ -92,7 +92,7 @@ $upload_dir = $conf->contrat->multidir_output[$object->entity ?? $conf->entity].
$modulepart = 'contract';
// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
$hookmanager->initHooks(array('contractcard', 'globalcard'));
$hookmanager->initHooks(array('contractcard', 'contractdocument', 'globalcard'));
$permissiontoadd = $user->hasRight('contrat', 'creer'); // Used by the include of actions_dellink.inc.php

View file

@ -156,7 +156,7 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it
public $menu = array();
/**
* @var array{triggers?:int<0,1>,login?:int<0,1>,substitutions?:int<0,1>,menus?:int<0,1>,theme?:int<0,1>,tpl?:int<0,1>,barcode?:int<0,1>,models?:int<0,1>,printing?:int<0,1>,css?:string[],js?:string[],hooks?:array{data?:string[],entity?:string},moduleforexternal?:int<0,1>,websitetemplates?:int<0,1>,contactelement?:int<0,1>} Module parts
* @var array{triggers?:int<0,1>,login?:int<0,1>,substitutions?:int<0,1>,menus?:int<0,1>,theme?:int<0,1>,tpl?:int<0,1>,barcode?:int<0,1>,models?:int<0,1>,printing?:int<0,1>,css?:string[],js?:string[],hooks?:array{data?:string[],entity?:string}|string[],moduleforexternal?:int<0,1>,websitetemplates?:int<0,1>,contactelement?:int<0,1>} Module parts
* array(
* // Set this to 1 if module has its own trigger directory (/mymodule/core/triggers)
* 'triggers' => 0,

View file

@ -27,6 +27,7 @@
* \brief Description and activation file for module QuickMemo
*/
include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
require_once DOL_DOCUMENT_ROOT.'/quickmemo/class/memo.class.php';
/**
@ -87,6 +88,20 @@ class modQuickMemo extends DolibarrModules
// To use a supported fa-xxx css style of font awesome, use this->picto='xxx'
$this->picto = 'fa-sticky-note_far_#9bdb07';
// Define hooks
$contextTabMapping = Memo::getAvailableMemoContextMapping(null, false);
$compatibleHooks = [];
foreach ($contextTabMapping as $values) {
foreach ((array) $values as $value) {
$compatibleHooks[] = (string) $value;
}
}
$compatibleHooks = array_unique($compatibleHooks);
// Security check
$compatibleHooks = array_filter($compatibleHooks, function (string $k) {
return preg_match('/^[a-zA-Z0-9_]+$/', $k);
});
// Define some features supported by module (triggers, login, substitutions, menus, css, etc...)
$this->module_parts = array(
// Set this to 1 if module has its own trigger directory (core/triggers)
@ -117,10 +132,7 @@ class modQuickMemo extends DolibarrModules
),
// Set here all hooks context managed by module. To find available hook context, make a "grep -r '>initHooks(' *" on source code. You can also set hook context to 'all'
'hooks' => array(
'globalcard',
'index'
),
'hooks' => $compatibleHooks,
// Set this to 1 if features of module are opened to external users
'moduleforexternal' => 0,

View file

@ -2321,18 +2321,21 @@ class ExpenseReport extends CommonObject
$this->db->free($resql);
}
// Select des information du projet
$sql = "SELECT p.ref as ref_projet, p.title as title_projet";
$sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
$sql .= " WHERE p.rowid = ".((int) $projet_id);
$resql = $this->db->query($sql);
if ($resql) {
$objp_projet = $this->db->fetch_object($resql);
$this->line->projet_ref = $objp_projet->ref_projet;
$this->line->projet_title = $objp_projet->title_projet;
$this->db->free($resql);
if ($projet_id > 0) {
// Select des information du projet
$sql = "SELECT p.ref as ref_projet, p.title as title_projet";
$sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
$sql .= " WHERE p.rowid = ".((int) $projet_id);
$resql = $this->db->query($sql);
if ($resql) {
if ($this->db->num_rows($resql) > 0) {
$objp_projet = $this->db->fetch_object($resql);
$this->line->projet_ref = $objp_projet->ref_projet;
$this->line->projet_title = $objp_projet->title_projet;
}
$this->db->free($resql);
}
}
$this->applyOffset();
$this->checkRules();

View file

@ -139,7 +139,7 @@ if (!getDolGlobalString('EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES')) {
//var_dump($file['relativename']);
//var_dump($_FILES['userfile']['name']);
// If a file was just uploaded, we check to preselect it
if (is_array($_FILES['userfile']) && is_array($_FILES['userfile']['name'])) {
if (isset($_FILES['userfile']) && is_array($_FILES['userfile']['name'])) {
foreach ($_FILES['userfile']['name'] as $tmpfile) {
if ($file['relativename'] == (GETPOST('savingdocmask', 'alpha') ? dol_sanitizeFileName($object->ref.'-') : '').$tmpfile) {
$checked = ' checked';

View file

@ -70,6 +70,10 @@ class modMyModule extends DolibarrModules
// Used only if file README.md and README-LL.md not found.
$this->descriptionlong = "MyModuleDescription";
// Enables the module for all entities (Multicompany)
// Can be enabled / disabled only from the main company with superadmin account
// $this->core_enabled = 1;
// Author
$this->editor_name = 'Editor name';
$this->editor_url = 'https://www.example.com'; // Must be an external online web site
@ -90,6 +94,18 @@ class modMyModule extends DolibarrModules
$this->picto = 'generic';
// Define some features supported by module (triggers, login, substitutions, menus, css, etc...)
// If your module use the parameter "core_enabled" and you would like to activate the parts in all entities (Multicompany):
// 'xxxxxx' => array(
// 'data' => 1 or '/mymodule/xxx/mymodule.xxx.php',
// 'entity' => '0'
// ),
// 'hooks' => array(
// 'data' => array(
// 'hookcontext1',
// 'hookcontext2',
// )
// 'entity' => '0'
// )
$this->module_parts = array(
// Set this to 1 if module has its own trigger directory (core/triggers)
'triggers' => 0,
@ -120,11 +136,8 @@ class modMyModule extends DolibarrModules
// Set here all hooks context managed by module. To find available hook context, make a "grep -r '>initHooks(' *" on source code. You can also set hook context to 'all'
/* BEGIN MODULEBUILDER HOOKSCONTEXTS */
'hooks' => array(
// 'data' => array(
// 'hookcontext1',
// 'hookcontext2',
// ),
// 'entity' => '0',
// 'hookcontext1',
// 'hookcontext2',
),
/* END MODULEBUILDER HOOKSCONTEXTS */
// Set this to 1 if features of module are opened to external users

View file

@ -136,7 +136,7 @@ class ActionsQuickMemo extends CommonHookActions
'archivesUrlParams' => '&search_fk_element='. (int) $object->id .'&search_element_type='.$object->element,
'elementId' => (int) $object->id,
'elementType' => $object->element,
'context' => Memo::getMemoContext($parameters['context']??''),
'context' => Memo::getMemoContext($parameters['context']??'', $object),
];
Memo::loadQuickMemoJsInterface($jsConfVars);

View file

@ -1279,23 +1279,33 @@ class Memo extends CommonObject
* Get memo context
*
* @param string|array<string> $context Context
* @param CommonObject|null $object the common Dolibarr object
*
* @return mixed|string
*/
public static function getMemoContext($context)
public static function getMemoContext($context, $object = null)
{
global $db,$action, $hookmanager;
if (!isModEnabled('quickmemo')) {
return '';
}
if (!is_array($context)) {
$context = explode(':', $context);
}
$memoContext = '';
if (in_array('index', $context)) {
$memoContext = 'index';
} elseif (in_array('globalcard', $context)) {
$memoContext = 'card';
}
$contextMapping = self::getAvailableMemoContextMapping();
$memoContext = '';
foreach ($contextMapping as $key => $values) {
$values = (array) $values;
if (array_intersect($context, $values)) {
$memoContext = $key;
break;
}
}
$staticMemo = new self($db);
@ -1303,7 +1313,7 @@ class Memo extends CommonObject
$parameters = array(
'memoContext' =>& $memoContext
);
$object = null;
$reshook = $hookmanager->executeHooks('getMemoContext', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) {
return $hookmanager->resPrint;
@ -1315,13 +1325,97 @@ class Memo extends CommonObject
/**
* Get available memo context
*
* @return mixed|mixed[]|string[]
* @param null $object the common Dolibarr object
* @param bool $onlyActiveModules on true return only
*
* @return array|string[]
*/
public static function getAvailableMemoContextMapping($object = null, $onlyActiveModules = true)
{
global $db,$action, $hookmanager;
$contextTabMapping = [];
$commonCardContext = ['document', 'agenda', 'contactcard', 'stats'];
foreach ($commonCardContext as $context) {
// init common contexts
$contextTabMapping[$context] = [];
}
// Start Correction of no standard Dolibarr context and special context
if (isModEnabled('propal') || !$onlyActiveModules) {
$contextTabMapping['contactcard'][] = 'proposalcontactcard';
}
if (isModEnabled('supplier_order') || !$onlyActiveModules) {
$contextTabMapping['contactcard'][] = 'ordersuppliercontactcard';
$contextTabMapping['document'][] = 'ordersuppliercarddocument';
$contextTabMapping['agenda'][] = 'ordersuppliercardinfo';
$contextTabMapping['ordersupplierdispatch'][] = 'ordersupplierdispatch';
}
if (isModEnabled('contract') || !$onlyActiveModules) {
$contextTabMapping['agenda'][] = 'agendacontract';
}
if (isModEnabled('order') || !$onlyActiveModules) {
$contextTabMapping['ordershipmentcard'][] = 'ordershipmentcard';
}
// End of corrections
// Generate standard context
foreach (['order', 'propal', 'invoice', 'supplier_proposal', 'supplier_order', 'supplier_invoice', 'contract'] as $module) {
if (!isModEnabled($module) && $onlyActiveModules) {
continue;
}
$moduleClean = str_replace('_', '', $module);
foreach ($commonCardContext as $context) {
$contextTabMapping[$context][] = $moduleClean.$context;
}
}
if (!empty($object) && !empty($object->element)) {
foreach ($commonCardContext as $context) {
$contextTabMapping[$context][] = $object->element.$context;
}
}
$contextTabMapping = array_replace_recursive($contextTabMapping, [
// Need to by at end of tests
'index' => 'index',
'card' => 'globalcard'
]);
$staticMemo = new self($db);
$hookmanager->initHooks(array($staticMemo->element.'dao'));
$parameters = array(
'contextTabMapping' =>& $contextTabMapping,
'onlyActiveModules' => $onlyActiveModules
);
$reshook = $hookmanager->executeHooks('getAvailableMemoContextMapping', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) {
return $hookmanager->resArray;
}
return $contextTabMapping;
}
/**
* Get available memo context
*
* @return string[]
*/
public static function getAvailableMemoContext()
{
global $db,$action, $hookmanager;
$list = ['card', 'index'];
$contextMapping = self::getAvailableMemoContextMapping();
$list = array_keys($contextMapping);
$staticMemo = new self($db);
$hookmanager->initHooks(array($staticMemo->element.'dao'));
@ -1331,10 +1425,19 @@ class Memo extends CommonObject
$object = null;
$reshook = $hookmanager->executeHooks('getAvailableMemoContext', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) {
return $hookmanager->resArray;
$list = $hookmanager->resArray;
}
return $list;
// Security check
$result = [];
foreach ($list as $k => $v) {
if (!is_string($v)) { continue; }
if (strlen($v) > 64) { continue; }
if (preg_match('/^[a-zA-Z0-9_]+$/', $k) !== 1) { continue; }
$result[] = $v;
}
return $result;
}
@ -1486,6 +1589,10 @@ class Memo extends CommonObject
{
global $user;
if (!isModEnabled('quickmemo')) {
return false;
}
// DO NOT LOAD TWICE
if (defined('QUICKMEMOJS')) {
return false;

View file

@ -58,7 +58,7 @@ foreach ($linkedObjectBlock as $key => $objectlink) {
} ?>
<tr class="<?php echo $trclass; ?>">
<td class="tdoverflowmax125" title="<?php echo dolPrintHTMLForAttribute($langs->trans("SupplierProposal")); ?>"><?php echo dolPrintHTML($langs->trans("SupplierProposal")); ?></td>
<td><a href="<?php echo DOL_URL_ROOT.'/supplier_proposal/card.php?id='.$objectlink->id ?>"><?php echo img_object($langs->trans("ShowSupplierProposal"), "supplier_proposal").' '.$objectlink->ref; ?></a></td>
<td><?php echo $objectlink->getNomUrl(1); ?></td>
<td></td>
<td class="center"><?php echo dol_print_date($objectlink->date_creation, 'day'); ?></td>
<td class="right"><?php