dolibarr 24.0.0-beta
modQuickMemo.class.php
1<?php
2/* Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2018-2019 Nicolas ZABOURI <info@inovea-conseil.com>
4 * Copyright (C) 2019-2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2026 John BOTELLA
6 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
30include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
31require_once DOL_DOCUMENT_ROOT.'/quickmemo/class/memo.class.php';
32
33
38{
44 public function __construct($db)
45 {
46 global $conf, $langs;
47
48 $this->db = $db;
49
50 // Id for module (must be unique).
51 // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
52 $this->numero = 141916;
53
54 // Key text used to identify module (for permissions, menus, etc...)
55 $this->rights_class = 'quickmemo';
56
57 // Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...'
58 // It is used to group modules by family in module setup page
59 $this->family = "technic";
60
61 // Module position in the family on 2 digits ('01', '10', '20', ...)
62 $this->module_position = '90';
63
64 // Gives the possibility for the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this)
65 //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));
66 // Module label (no space allowed), used if translation string 'ModuleQuickMemoName' not found (QuickMemo is name of module).
67 $this->name = preg_replace('/^mod/i', '', get_class($this));
68
69 // DESCRIPTION_FLAG
70 $langs->load("quickmemo");
71
72 // Module description, used if translation string 'ModuleQuickMemoDesc' not found (QuickMemo is name of module).
73 $this->description = $langs->trans("ModuleQuickMemoDesc");
74 // Used only if file README.md and README-LL.md not found.
75 $this->descriptionlong = $langs->trans("ModuleQuickMemoDesc");
76
77 // Author
78 $this->editor_squarred_logo = ''; // Must be image filename into the module/img directory followed with @modulename. Example: 'myimage.png@quickmemo'
79
80 // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated', 'experimental_deprecated' or a version string like 'x.y.z'
81 $this->version = 'experimental';
82 // Url to the file with your last numberversion of this module
83 //$this->url_last_version = 'http://www.example.com/versionmodule.txt';
84
85 // Key used in llx_const table to save module status enabled/disabled (where QUICKMEMO is value of property name of module in uppercase)
86 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
87
88 // Name of image file used for this module.
89 // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
90 // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
91 // To use a supported fa-xxx css style of font awesome, use this->picto='xxx'
92 $this->picto = 'fa-sticky-note_far_#9bdb07';
93
94 // Define hooks
95 $contextTabMapping = Memo::getAvailableMemoContextMapping(null, false);
96 $compatibleHooks = [];
97 foreach ($contextTabMapping as $values) {
98 foreach ((array) $values as $value) {
99 $compatibleHooks[] = (string) $value;
100 }
101 }
102 $compatibleHooks = array_unique($compatibleHooks);
103 // Security check
104 $compatibleHooks = array_filter($compatibleHooks, static function (string $k) {
105 return preg_match('/^[a-zA-Z0-9_]+$/', $k);
106 });
107
108 // Define some features supported by module (triggers, login, substitutions, menus, css, etc...)
109 $this->module_parts = array(
110 // Set this to 1 if module has its own trigger directory (core/triggers)
111 'triggers' => 0,
112 // Set this to 1 if module has its own login method file (core/login)
113 'login' => 0,
114 // Set this to 1 if module has its own substitution function file (core/substitutions)
115 'substitutions' => 0,
116 // Set this to 1 if module has its own menus handler directory (core/menus)
117 'menus' => 0,
118 // Set this to 1 if module overwrite template dir (core/tpl)
119 'tpl' => 0,
120 // Set this to 1 if module has its own barcode directory (core/modules/barcode)
121 'barcode' => 0,
122 // Set this to 1 if module has its own models directory (core/modules/xxx)
123 'models' => 0,
124 // Set this to 1 if module has its own printing directory (core/modules/printing)
125 'printing' => 0,
126 // Set this to 1 if module has its own theme directory (theme)
127 'theme' => 0,
128 // Set this to relative path of css file if module has its own css file
129 'css' => array(
130 // '/quickmemo/css/quickmemo.css.php',
131 ),
132 // Set this to relative path of js file if module must load a js on all pages
133 'js' => array(
134 // '/quickmemo/js/quickmemo.js.php',
135 ),
136 // 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'
137
138 'hooks' => $compatibleHooks,
139
140 // Set this to 1 if features of module are opened to external users
141 'moduleforexternal' => 0,
142 // Set this to 1 if the module provides a website template into doctemplates/websites/website_template-mytemplate
143 'websitetemplates' => 0,
144 // Set this to 1 if the module provides a captcha driver
145 'captcha' => 0
146 );
147
148 // Data directories to create when module is enabled.
149 // Example: this->dirs = array("/quickmemo/temp","/quickmemo/subdir");
150 $this->dirs = array("");
151
152 // Config pages. Put here list of php page, stored into quickmemo/admin directory, to use to setup module.
153 $this->config_page_url = array("setup.php@quickmemo");
154
155 // Dependencies
156 // A condition to hide module
157 $this->hidden = getDolGlobalInt('MODULE_QUICKMEMO_DISABLED'); // A condition to disable module;
158 // List of module class names that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR')...)
159 $this->depends = array();
160 // List of module class names to disable if this one is disabled. Example: array('modModuleToDisable1', ...)
161 $this->requiredby = array();
162 // List of module class names this module is in conflict with. Example: array('modModuleToDisable1', ...)
163 $this->conflictwith = array();
164
165 // The language file dedicated to your module
166 $this->langfiles = array("quickmemo@quickmemo");
167
168 // Prerequisites
169 $this->phpmin = array(7, 2); // Minimum version of PHP required by module
170 // $this->phpmax = array(8, 0); // Maximum version of PHP required by module
171 $this->need_dolibarr_version = array(19, -3); // Minimum version of Dolibarr required by module
172 // $this->max_dolibarr_version = array(19, -3); // Maximum version of Dolibarr required by module
173 $this->need_javascript_ajax = 0;
174
175 // Messages at activation
176 $this->warnings_activation = array(); // Warning to show when we activate a module. Example: array('always'='text') or array('FR'='textfr','MX'='textmx'...)
177 $this->warnings_activation_ext = array(); // Warning to show when we activate a module if another module is on. Example: array('modOtherModule' => array('always'=>'text')) or array('always' => array('FR'=>'textfr','MX'=>'textmx'...))
178 //$this->automatic_activation = array('FR'=>'QuickMemoWasAutomaticallyActivatedBecauseOfYourCountryChoice');
179 //$this->always_enabled = false; // If true, can't be disabled. Value true is reserved for core modules. Not allowed for external modules.
180
181 // Constants
182 // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
183 // Example: $this->const=array(1 => array('QUICKMEMO_MYNEWCONST1', 'chaine', 'myvalue', 'This is a constant to add', 1),
184 // 2 => array('QUICKMEMO_MYNEWCONST2', 'chaine', 'myvalue', 'This is another constant to add', 0, 'current', 1)
185 // );
186 $this->const = array();
187
188 // Some keys to add into the overwriting translation tables
189 /*$this->overwrite_translation = array(
190 'en_US:ParentCompany'=>'Parent company or reseller',
191 'fr_FR:ParentCompany'=>'Maison mère ou revendeur'
192 )*/
193
194 if (!isModEnabled("quickmemo")) {
195 $conf->quickmemo = new stdClass();
196 $conf->quickmemo->enabled = 0;
197 }
198
199
200 // Array to add new pages in new tabs
201 /* BEGIN MODULEBUILDER TABS */
202 // Don't forget to deactivate/reactivate your module to test your changes
203 $this->tabs = array();
204 /* END MODULEBUILDER TABS */
205 // Example:
206 // To add a new tab identified by code tabname1
207 // $this->tabs[] = array('data' => 'objecttype:+tabname1:Title1:mylangfile@quickmemo:$user->hasRight('quickmemo', 'memo', 'read'):/quickmemo/mynewtab1.php?id=__ID__');
208 // To add another new tab identified by code tabname2. Label will be result of calling all substitution functions on 'Title2' key.
209 // $this->tabs[] = array('data' => 'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@quickmemo:$user->hasRight('othermodule', 'otherobject', 'read'):/quickmemo/mynewtab2.php?id=__ID__',
210 // To remove an existing tab identified by code tabname
211 // $this->tabs[] = array('data' => 'objecttype:-tabname:NU:conditiontoremove');
212 //
213 // Where objecttype can be
214 // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
215 // 'contact' to add a tab in contact view
216 // 'contract' to add a tab in contract view
217 // 'delivery' to add a tab in delivery view
218 // 'group' to add a tab in group view
219 // 'intervention' to add a tab in intervention view
220 // 'invoice' to add a tab in customer invoice view
221 // 'supplier_invoice' to add a tab in supplier invoice view
222 // 'member' to add a tab in foundation member view
223 // 'opensurveypoll' to add a tab in opensurvey poll view
224 // 'order' to add a tab in sale order view
225 // 'supplier_order' to add a tab in supplier order view
226 // 'payment' to add a tab in payment view
227 // 'supplier_payment' to add a tab in supplier payment view
228 // 'product' to add a tab in product view
229 // 'propal' to add a tab in propal view
230 // 'project' to add a tab in project view
231 // 'stock' to add a tab in stock view
232 // 'thirdparty' to add a tab in third party view
233 // 'user' to add a tab in user view
234
235
236 // Dictionaries
237 /* Example:
238 $this->dictionaries=array(
239 'langs' => 'quickmemo@quickmemo',
240 // List of tables we want to see into dictionary editor
241 'tabname' => array("table1", "table2", "table3"),
242 // Label of tables
243 'tablib' => array("Table1", "Table2", "Table3"),
244 // Request to select fields
245 'tabsql' => array('SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.$this->db->prefix().'table1 as f', 'SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.$this->db->prefix().'table2 as f', 'SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.$this->db->prefix().'table3 as f'),
246 // Sort order
247 'tabsqlsort' => array("label ASC", "label ASC", "label ASC"),
248 // List of fields (result of select to show dictionary)
249 'tabfield' => array("code,label", "code,label", "code,label"),
250 // List of fields (list of fields to edit a record)
251 'tabfieldvalue' => array("code,label", "code,label", "code,label"),
252 // List of fields (list of fields for insert)
253 'tabfieldinsert' => array("code,label", "code,label", "code,label"),
254 // Name of columns with primary key (try to always name it 'rowid')
255 'tabrowid' => array("rowid", "rowid", "rowid"),
256 // Condition to show each dictionary
257 'tabcond' => array(isModEnabled('quickmemo'), isModEnabled('quickmemo'), isModEnabled('quickmemo')),
258 // Tooltip for every fields of dictionaries: DO NOT PUT AN EMPTY ARRAY
259 'tabhelp' => array(array('code' => $langs->trans('CodeTooltipHelp'), 'field2' => 'field2tooltip'), array('code' => $langs->trans('CodeTooltipHelp'), 'field2' => 'field2tooltip'), ...),
260 );
261 */
262 /* BEGIN MODULEBUILDER DICTIONARIES */
263 $this->dictionaries = array();
264 /* END MODULEBUILDER DICTIONARIES */
265
266 // Boxes/Widgets
267 // Add here list of php file(s) stored in quickmemo/core/boxes that contains a class to show a widget.
268 /* BEGIN MODULEBUILDER WIDGETS */
269 $this->boxes = array(
270 // 0 => array(
271 // 'file' => 'quickmemowidget1.php@quickmemo',
272 // 'note' => 'Widget provided by QuickMemo',
273 // 'enabledbydefaulton' => 'Home',
274 // ),
275 // ...
276 );
277 /* END MODULEBUILDER WIDGETS */
278
279 // Cronjobs (List of cron jobs entries to add when module is enabled)
280 // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
281 /* BEGIN MODULEBUILDER CRON */
282 $this->cronjobs = array(
283 // 0 => array(
284 // 'label' => 'MyJob label',
285 // 'jobtype' => 'method',
286 // 'class' => '/quickmemo/class/memo.class.php',
287 // 'objectname' => 'Memo',
288 // 'method' => 'doScheduledJob',
289 // 'parameters' => '',
290 // 'comment' => 'Comment',
291 // 'frequency' => 2,
292 // 'unitfrequency' => 3600,
293 // 'status' => 0,
294 // 'test' => 'isModEnabled("quickmemo")',
295 // 'priority' => 50,
296 // ),
297 );
298 /* END MODULEBUILDER CRON */
299 // Example: $this->cronjobs=array(
300 // 0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'/dir/class/file.class.php', 'objectname'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600, 'status'=>0, 'test'=>'isModEnabled("quickmemo")', 'priority'=>50),
301 // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'status'=>0, 'test'=>'isModEnabled("quickmemo")', 'priority'=>50)
302 // );
303
304 // Permissions provided by this module
305 $this->rights = array();
306 $r = 0;
307 // Add here entries to declare new permissions
308
309 $o = 1;
310 $this->rights[$r][0] = $this->numero . sprintf("%02d", ($o * 10) + 1); // Permission id (must not be already used)
311 $this->rights[$r][1] = 'Read objects of QuickMemo'; // Permission label
312 $this->rights[$r][4] = 'memo';
313 $this->rights[$r][5] = 'read'; // In php code, permission will be checked by test if ($user->hasRight('quickmemo', 'memo', 'read'))
314 $r++;
315 $this->rights[$r][0] = $this->numero . sprintf("%02d", ($o * 10) + 2); // Permission id (must not be already used)
316 $this->rights[$r][1] = 'Create/Update objects of QuickMemo'; // Permission label
317 $this->rights[$r][4] = 'memo';
318 $this->rights[$r][5] = 'write'; // In php code, permission will be checked by test if ($user->hasRight('quickmemo', 'memo', 'write'))
319 $r++;
320 $this->rights[$r][0] = $this->numero . sprintf("%02d", ($o * 10) + 3); // Permission id (must not be already used)
321 $this->rights[$r][1] = 'Delete objects of QuickMemo'; // Permission label
322 $this->rights[$r][4] = 'memo';
323 $this->rights[$r][5] = 'delete'; // In php code, permission will be checked by test if ($user->hasRight('quickmemo', 'memo', 'delete'))
324 $r++;
325
326
327 // Main menu entries to add
328 $this->menu = array();
329 $r = 0;
330 // Add here entries to declare new menus
331
332 $this->menu[$r++] = array(
333 'fk_menu' => 'fk_mainmenu=tools',
334 'type' => 'left',
335 'titre' => 'Memo',
336 'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth valignmiddle"'),
337 'mainmenu' => 'tools',
338 'leftmenu' => 'memo',
339 'url' => '/quickmemo/memo_list.php',
340 'langs' => 'quickmemo',
341 'position' => 1000 + $r,
342 'enabled' => 'isModEnabled("quickmemo")',
343 'perms' => '1',
344 'target' => '',
345 'user' => 2,
346 'object' => 'Memo'
347 );
348 $this->menu[$r++] = array(
349 'fk_menu' => 'fk_mainmenu=tools,fk_leftmenu=memo',
350 'type' => 'left',
351 'titre' => 'List Memo',
352 'mainmenu' => 'tools',
353 'leftmenu' => 'quickmemo_memo_list',
354 'url' => '/quickmemo/memo_list.php',
355 'langs' => 'quickmemo',
356 'position' => 1000 + $r,
357 'enabled' => 'isModEnabled("quickmemo")',
358 'perms' => '1',
359 'target' => '',
360 'user' => 2,
361 'object' => 'Memo'
362 );
363 }
364
373 public function init($options = '')
374 {
375
376 // Create tables of module at module activation
377 $result = $this->_load_tables('/install/mysql/', 'quickmemo');
378 if ($result < 0) {
379 return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default')
380 }
381
382 // Create extrafields during init
383 //include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
384 //$extrafields = new ExtraFields($this->db);
385 //$result0=$extrafields->addExtraField('quickmemo_separator1', "Separator 1", 'separator', 1, 0, 'thirdparty', 0, 0, '', array('options'=>array(1=>1)), 1, '', 1, 0, '', '', 'quickmemo@quickmemo', 'isModEnabled("quickmemo")');
386 //$result1=$extrafields->addExtraField('quickmemo_myattr1', "New Attr 1 label", 'boolean', 1, 3, 'thirdparty', 0, 0, '', '', 1, '', -1, 0, '', '', 'quickmemo@quickmemo', 'isModEnabled("quickmemo")');
387 //$result2=$extrafields->addExtraField('quickmemo_myattr2', "New Attr 2 label", 'varchar', 1, 10, 'project', 0, 0, '', '', 1, '', -1, 0, '', '', 'quickmemo@quickmemo', 'isModEnabled("quickmemo")');
388 //$result3=$extrafields->addExtraField('quickmemo_myattr3', "New Attr 3 label", 'varchar', 1, 10, 'bank_account', 0, 0, '', '', 1, '', -1, 0, '', '', 'quickmemo@quickmemo', 'isModEnabled("quickmemo")');
389 //$result4=$extrafields->addExtraField('quickmemo_myattr4', "New Attr 4 label", 'select', 1, 3, 'thirdparty', 0, 1, '', array('options'=>array('code1'=>'Val1','code2'=>'Val2','code3'=>'Val3')), 1,'', -1, 0, '', '', 'quickmemo@quickmemo', 'isModEnabled("quickmemo")');
390 //$result5=$extrafields->addExtraField('quickmemo_myattr5', "New Attr 5 label", 'text', 1, 10, 'user', 0, 0, '', '', 1, '', -1, 0, '', '', 'quickmemo@quickmemo', 'isModEnabled("quickmemo")');
391
392 // Permissions
393 $this->remove($options);
394
395 $sql = array();
396
397 return $this->_init($sql, $options);
398 }
399
408 public function remove($options = '')
409 {
410 $sql = array();
411 return $this->_remove($sql, $options);
412 }
413}
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
_remove($array_sql, $options='')
Disable function.
_load_tables($reldir, $onlywithsuffix='')
Create tables and keys required by module:
static getAvailableMemoContextMapping($object=null, $onlyActiveModules=true)
Get available memo context.
Description and activation class for module QuickMemo.
init($options='')
Function called when module is enabled.
__construct($db)
Constructor.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
isModEnabled($module)
Is Dolibarr module enabled.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133