dolibarr 25.0.0-alpha
quickmemo.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2026 John BOTELLA
3 * Copyright (C) 2025-2026 Frédéric France <frederic.france@free.fr>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
31{
32 global $langs, $conf;
33
34 // global $db;
35 // $extrafields = new ExtraFields($db);
36 // $extrafields->fetch_name_optionals_label('myobject');
37
38 $langs->load("quickmemo");
39
40 $h = 0;
41 $head = array();
42
43 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/quickmemo/admin/setup.php");
44 $head[$h][1] = $langs->trans("Settings");
45 $head[$h][2] = 'settings';
46 $h++;
47
48
49 // $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/extrafields.php', array('elementtype' => 'quickmemo_memo'));
50 // $head[$h][1] = $langs->trans("ExtraFields");
51 // $nbExtrafields = (isset($extrafields->attributes['memo']['label']) && is_countable($extrafields->attributes['memo']['label'])) ? count($extrafields->attributes['memo']['label']) : 0;
52 // if ($nbExtrafields > 0) {
53 // $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>';
54 // }
55 // $head[$h][2] = 'memo_extrafields';
56 // $h++;
57
58 /*
59 $head[$h][0] = dolBuildUrl(dol_buildpath("/quickmemo/admin/myobjectline_extrafields.php", 1));
60 $head[$h][1] = $langs->trans("ExtraFieldsLines");
61 $nbExtrafields = (isset($extrafields->attributes['myobjectline']['label']) && is_countable($extrafields->attributes['myobjectline']['label'])) ? count($extrafields->attributes['myobject']['label']) : 0;
62 if ($nbExtrafields > 0) {
63 $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>';
64 }
65 $head[$h][2] = 'myobject_extrafieldsline';
66 $h++;
67 */
68
69
70 // Show more tabs from modules
71 // Entries must be declared in modules descriptor with line
72 //$this->tabs = array(
73 // 'entity:+tabname:Title:@quickmemo:/quickmemo/mypage.php?id=__ID__'
74 //); // to add new tab
75 //$this->tabs = array(
76 // 'entity:-tabname:Title:@quickmemo:/quickmemo/mypage.php?id=__ID__'
77 //); // to remove a tab
78 complete_head_from_modules($conf, $langs, null, $head, $h, 'quickmemo@quickmemo');
79
80 complete_head_from_modules($conf, $langs, null, $head, $h, 'quickmemo@quickmemo', 'remove');
81
82 return $head;
83}
84
94function quickMemoInterfaceCanAccessElement($element_type, $element_id, $moduleLevelOnly = false)
95{
96 global $user, $hookmanager;
97
98 if (empty($element_type)) {
99 return true;
100 }
101
102 $parameters = array('element_type' => $element_type, 'element_id' => $element_id, 'moduleLevelOnly' => $moduleLevelOnly);
103 $hookobject = null;
104 $action = '';
105 $reshook = $hookmanager->executeHooks('quickMemoCheckElementAccess', $parameters, $hookobject, $action);
106 if ($reshook > 0) {
107 return true;
108 } elseif ($reshook < 0) {
109 return false;
110 }
111
112 $element_type = quickMemoInterfaceResolveElementType($element_type);
113 $object = fetchObjectByElement($moduleLevelOnly ? 0 : (int) $element_id, $element_type, '', $moduleLevelOnly ? 0 : 1);
114 if (!is_object($object) || empty($object->element)) {
115 return false;
116 }
117 if (!$moduleLevelOnly && empty($object->id)) {
118 return false;
119 }
120
121 // Property module is set by fetchObjectByElement() only when object is fetched
122 $module = !empty($object->module) ? $object->module : getElementProperties($element_type)['module'];
123 if (empty($module)) {
124 return false;
125 }
126
127 $feature2 = ($module != $object->element ? $object->element : '');
128 if ($feature2 && !$user->hasRight($module, $object->element, 'read')) {
129 $feature2 = '';
130 }
131
132 // Force mode 'read', else restrictedArea() guesses the mode from our 'action' (create, delete...) and checks write permission on the object
133 return (bool) restrictedArea($user, $module, $moduleLevelOnly ? 0 : $object, $object->table_element, $feature2, 'fk_soc', 'rowid', 0, 1, 'read');
134}
135
146function quickMemoInterfaceResolveElementType($element_type)
147{
148 global $conf;
149 static $cache = array();
150
151 $element_type = (string) $element_type;
152 if ($element_type === '' || strpos($element_type, '@') !== false || !preg_match('/^[a-z0-9_]+$/i', $element_type)) {
153 return $element_type;
154 }
155 if (isset($cache[$element_type])) {
156 return $cache[$element_type];
157 }
158
159 $cache[$element_type] = $element_type;
160 $properties = getElementProperties($element_type);
161 if (file_exists(dol_buildpath('/'.$properties['classpath'].'/'.$properties['classfile'].'.class.php', 0))) {
162 return $element_type;
163 }
164 foreach (array_keys($conf->modules) as $module) {
165 $module = strtolower((string) $module);
166 if (preg_match('/^[a-z0-9_]+$/', $module) && file_exists(dol_buildpath('/'.$module.'/class/'.strtolower($element_type).'.class.php', 0))) {
167 $cache[$element_type] = $element_type.'@'.$module;
168 break;
169 }
170 }
171
172 return $cache[$element_type];
173}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
getElementProperties($elementType)
Get an array with properties of an element.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
quickMemoInterfaceCanAccessElement($element_type, $element_id, $moduleLevelOnly=false)
Check that current user can read the object a memo is attached to.
quickmemoAdminPrepareHead()
Prepare admin pages header.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.