dolibarr 24.0.3
api_documents.class.php
1<?php
2
3/* Copyright (C) 2016 Xebax Christy <xebax@wanadoo.fr>
4 * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2016 Jean-François Ferry <jfefe@aternatik.fr>
6 * Copyright (C) 2023 Romain Neil <contact@romain-neil.fr>
7 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2025-2026 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2025 William Mead <william@m34d.com>
10 * Copyright (C) 2025-2026 Charlene Benke <charlene@patas-monkey.com>
11 *
12 * This program is free software you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
26use Luracast\Restler\RestException;
27
28require_once DOL_DOCUMENT_ROOT.'/main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/api/class/api.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
31
41{
45 public function __construct()
46 {
47 global $db;
48 $this->db = $db;
49 }
50
51
72 public function index($modulepart, $original_file = '')
73 {
74 global $conf;
75
76 if (empty($modulepart)) {
77 throw new RestException(400, 'bad value for parameter modulepart');
78 }
79 if (empty($original_file)) {
80 throw new RestException(400, 'bad value for parameter original_file');
81 }
82
83 // Normalize modulepart for project_task
84 if ($modulepart == 'task' || $modulepart == 'project_task') {
85 $modulepart = 'project_task';
86 }
87
88 //--- Finds and returns the document
89 $entity = $conf->entity;
90
91 // Special cases that need to use get_exdir to get real dir of object
92 // If future, all object should use this to define path of documents.
93 /*
94 $tmpreldir = '';
95 if ($modulepart == 'supplier_invoice') {
96 $tmpreldir = get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier');
97 }
98
99 $relativefile = $tmpreldir.dol_sanitizeFileName($object->ref); */
100 $relativefile = $original_file;
101
102 $check_access = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, '', 'read');
103 $accessallowed = $check_access['accessallowed'];
104 $sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals'];
105 $original_file = $check_access['original_file'];
106
107 if (preg_match('/\.\./', $original_file) || preg_match('/[<>|]/', $original_file)) {
108 throw new RestException(403);
109 }
110 if (!$accessallowed) {
111 throw new RestException(403);
112 }
113 // Check permission on the object the document is attached to (thirdparties of a restricted sales representative, ...)
114 if (!checkUserAccessToDocumentObject(DolibarrApiAccess::$user, $modulepart, $relativefile, 'read')) {
115 throw new RestException(403, 'Access not allowed to the object of this document');
116 }
117
118 if (DolibarrApiAccess::$user->socid > 0) {
119 if ($sqlprotectagainstexternals) {
120 $resql = $this->db->query($sqlprotectagainstexternals);
121 if ($resql) {
122 $num = $this->db->num_rows($resql);
123 $i = 0;
124 while ($i < $num) {
125 $obj = $this->db->fetch_object($resql);
126 if (DolibarrApiAccess::$user->socid != $obj->fk_soc) {
127 throw new RestException(403, 'Not allowed to download documents with such a ref');
128 }
129 $i++;
130 }
131 }
132 }
133 }
134
135 $filename = basename($original_file);
136 $original_file_osencoded = dol_osencode($original_file); // New file name encoded in OS encoding charset
137
138 if (!file_exists($original_file_osencoded)) {
139 dol_syslog("Try to download not found file ".$original_file_osencoded, LOG_WARNING);
140 throw new RestException(404, 'File not found');
141 }
142
143 $file_content = file_get_contents($original_file_osencoded);
144 return array('filename' => $filename, 'content-type' => dol_mimetype($filename), 'filesize' => filesize($original_file), 'content' => base64_encode($file_content), 'encoding' => 'base64');
145 }
146
147
178 public function builddoc($modulepart, $original_file = '', $doctemplate = '', $langcode = '')
179 {
180 global $conf, $langs;
181
182 if (empty($modulepart)) {
183 throw new RestException(400, 'bad value for parameter modulepart');
184 }
185 if (empty($original_file)) {
186 throw new RestException(400, 'bad value for parameter original_file');
187 }
188
189 $outputlangs = $langs;
190 if ($langcode && $langs->defaultlang != $langcode) {
191 $outputlangs = new Translate('', $conf);
192 $outputlangs->setDefaultLang($langcode);
193 }
194
195 //--- Finds and returns the document
196 $entity = $conf->entity;
197
198 // Special cases that need to use get_exdir to get real dir of object
199 // If future, all object should use this to define path of documents.
200 /*
201 $tmpreldir = '';
202 if ($modulepart == 'supplier_invoice') {
203 $tmpreldir = get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier');
204 }
205
206 $relativefile = $tmpreldir.dol_sanitizeFileName($object->ref); */
207 $relativefile = $original_file;
208
209 $check_access = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, '', 'write');
210 $accessallowed = $check_access['accessallowed'];
211 $sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals'];
212 $original_file = $check_access['original_file'];
213
214 if (preg_match('/\.\./', $original_file) || preg_match('/[<>|]/', $original_file)) {
215 throw new RestException(403);
216 }
217 if (!$accessallowed) {
218 throw new RestException(403);
219 }
220 // Check permission on the object the document is attached to (thirdparties of a restricted sales representative, ...)
221 if (!checkUserAccessToDocumentObject(DolibarrApiAccess::$user, $modulepart, $relativefile, 'write')) {
222 throw new RestException(403, 'Access not allowed to the object of this document');
223 }
224
225 if (DolibarrApiAccess::$user->socid > 0) {
226 if ($sqlprotectagainstexternals) {
227 $resql = $this->db->query($sqlprotectagainstexternals);
228 if ($resql) {
229 $num = $this->db->num_rows($resql);
230 $i = 0;
231 while ($i < $num) {
232 $obj = $this->db->fetch_object($resql);
233 if (DolibarrApiAccess::$user->socid != $obj->fk_soc) {
234 throw new RestException(403, 'Not allowed to download documents with such a ref');
235 }
236 $i++;
237 }
238 }
239 }
240 }
241
242 // --- Generates the document
243 $hidedetails = !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 0 : 1;
244 $hidedesc = !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 0 : 1;
245 $hideref = !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 0 : 1;
246
247 $templateused = '';
248
249 if ($modulepart == 'facture' || $modulepart == 'invoice') {
250 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
251 $tmpobject = new Facture($this->db);
252 $result = $tmpobject->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
253 if (!$result) {
254 throw new RestException(404, 'Invoice not found');
255 }
256
257 $templateused = $doctemplate ? $doctemplate : $tmpobject->model_pdf;
258 $result = $tmpobject->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
259 if ($result <= 0) {
260 throw new RestException(500, 'Error generating document');
261 }
262 } elseif ($modulepart == 'facture_fournisseur' || $modulepart == 'invoice_supplier') {
263 require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
264 $tmpobject = new FactureFournisseur($this->db);
265 $result = $tmpobject->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
266 if (!$result) {
267 throw new RestException(404, 'Supplier invoice not found');
268 }
269
270 $templateused = $doctemplate ? $doctemplate : $tmpobject->model_pdf;
271 $result = $tmpobject->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
272 if ($result < 0) {
273 throw new RestException(500, 'Error generating document');
274 }
275 } elseif ($modulepart == 'commande' || $modulepart == 'order') {
276 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
277 $tmpobject = new Commande($this->db);
278 $result = $tmpobject->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
279 if (!$result) {
280 throw new RestException(404, 'Order not found');
281 }
282 $templateused = $doctemplate ? $doctemplate : $tmpobject->model_pdf;
283 $result = $tmpobject->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
284 if ($result <= 0) {
285 throw new RestException(500, 'Error generating document');
286 }
287 } elseif ($modulepart == 'propal' || $modulepart == 'proposal') {
288 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
289 $tmpobject = new Propal($this->db);
290 $result = $tmpobject->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
291 if (!$result) {
292 throw new RestException(404, 'Proposal not found');
293 }
294 $templateused = $doctemplate ? $doctemplate : $tmpobject->model_pdf;
295 $result = $tmpobject->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
296 if ($result <= 0) {
297 throw new RestException(500, 'Error generating document');
298 }
299 } elseif ($modulepart == 'contrat' || $modulepart == 'contract') {
300 require_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php';
301
302 $tmpobject = new Contrat($this->db);
303 $result = $tmpobject->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
304
305 if (!$result) {
306 throw new RestException(404, 'Contract not found');
307 }
308
309 $templateused = $doctemplate ? $doctemplate : $tmpobject->model_pdf;
310 $result = $tmpobject->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
311
312 if ($result <= 0) {
313 throw new RestException(500, 'Error generating document');
314 }
315 } elseif ($modulepart == 'expedition' || $modulepart == 'shipment') {
316 require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php';
317
318 $tmpobject = new Expedition($this->db);
319 $result = $tmpobject->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
320
321 if (!$result) {
322 throw new RestException(404, 'Shipment not found');
323 }
324
325 $templateused = $doctemplate ? $doctemplate : $tmpobject->model_pdf;
326 $result = $tmpobject->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
327
328 if ($result <= 0) {
329 throw new RestException(500, 'Error generating document');
330 }
331 } elseif ($modulepart == 'mrp') {
332 require_once DOL_DOCUMENT_ROOT . '/mrp/class/mo.class.php';
333
334 $tmpobject = new Mo($this->db);
335 $result = $tmpobject->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
336
337 if (!$result) {
338 throw new RestException(404, 'MO not found');
339 }
340
341 $templateused = $doctemplate ? $doctemplate : $tmpobject->model_pdf;
342 $result = $tmpobject->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
343
344 if ($result <= 0) {
345 throw new RestException(500, 'Error generating document');
346 }
347 } elseif ($modulepart == 'expensereport') {
348 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
349
350 $tmpobject = new ExpenseReport($this->db);
351 $result = $tmpobject->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
352
353 if (!$result) {
354 throw new RestException(404, 'Expense report not found');
355 }
356
357 $templateused = $doctemplate ? $doctemplate : $tmpobject->model_pdf;
358 $result = $tmpobject->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
359
360 if ($result <= 0) {
361 throw new RestException(500, 'Error generating document');
362 }
363 } elseif ($modulepart == 'holiday') {
364 require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
365
366 $tmpobject = new Holiday($this->db);
367 $result = $tmpobject->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
368
369 if (!$result) {
370 throw new RestException(404, 'Holiday not found');
371 }
372
373 $templateused = $doctemplate ? $doctemplate : $tmpobject->model_pdf;
374 $result = $tmpobject->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
375
376 if ($result <= 0) {
377 throw new RestException(500, 'Error generating document');
378 }
379 } elseif ($modulepart == 'product') {
380 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
381
382 $tmpobject = new Product($this->db);
383 $result = $tmpobject->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
384
385 if (!$result) {
386 throw new RestException(404, 'Product not found');
387 }
388
389 $templateused = $doctemplate ? $doctemplate : $tmpobject->model_pdf;
390 $result = $tmpobject->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
391
392 if ($result <= 0) {
393 throw new RestException(500, 'Error generating document');
394 }
395 } elseif ($modulepart == 'stock' || $modulepart == 'entrepot') {
396 require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php';
397
398 $tmpobject = new Entrepot($this->db);
399 $result = $tmpobject->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
400
401 if (!$result) {
402 throw new RestException(404, 'Warehouse not found');
403 }
404
405 $templateused = $doctemplate ? $doctemplate : $tmpobject->model_pdf;
406 $result = $tmpobject->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
407
408 if ($result <= 0) {
409 throw new RestException(500, 'Error generating document');
410 }
411 } elseif ($modulepart == 'fichinter' || $modulepart == 'intervention') {
412 require_once DOL_DOCUMENT_ROOT . '/fichinter/class/fichinter.class.php';
413
414 $tmpobject = new Fichinter($this->db);
415 $result = $tmpobject->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
416
417 if (!$result) {
418 throw new RestException(404, 'Intervention not found');
419 }
420
421 $templateused = $doctemplate ? $doctemplate : $tmpobject->model_pdf;
422 $result = $tmpobject->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
423
424 if ($result <= 0) {
425 throw new RestException(500, 'Error generating document');
426 }
427 } else {
428 throw new RestException(403, 'Generation not available for this modulepart');
429 }
430
431 $filename = basename($original_file);
432 $original_file_osencoded = dol_osencode($original_file); // New file name encoded in OS encoding charset
433
434 if (!file_exists($original_file_osencoded)) {
435 throw new RestException(404, 'File not found');
436 }
437
438 $file_content = file_get_contents($original_file_osencoded);
439 return array('filename' => $filename, 'content-type' => dol_mimetype($filename), 'filesize' => filesize($original_file), 'content' => base64_encode($file_content), 'langcode' => $outputlangs->defaultlang, 'template' => $templateused, 'encoding' => 'base64');
440 }
441
471 public function getDocumentsListByElement($modulepart, $id = 0, $ref = '', $sortfield = '', $sortorder = '', $limit = 100, $page = 0, $content_type = '', $pagination_data = false)
472 {
473 if (empty($modulepart)) {
474 throw new RestException(400, 'bad value for parameter modulepart');
475 }
476
477 if (empty($id) && empty($ref)) {
478 throw new RestException(400, 'bad value for parameter id or ref');
479 }
480
481 $id = (empty($id) ? 0 : $id);
482
483 if ($modulepart == 'facture_fournisseur') {
484 $modulepart = 'supplier_invoice'; // Alias unknown by fetchObjectByElement()
485 }
486
487 // Define $object
488 $object = fetchObjectByElement($id, $modulepart, $ref); // Note that we don't mind id and ref, we want to get a valid instantiated $object but not necessarily initialized
489 if (!is_object($object)) {
490 throw new RestException(404, 'Module for modulepart = '.$modulepart." is not enabled (or not yet supported by API");
491 }
492
493 // Define $upload_dir to scan
494 if ($object->element == 'invoice_supplier' && $object->id > 0) {
495 // Supplier invoices are stored under a hashed subdir, as in the other methods of this file
496 $upload_dir = getMultidirOutput($object).'/'.get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').dol_sanitizeFileName($object->ref);
497 } else {
498 $upload_dir = (string) getMultidirOutput($object, '', 1);
499 }
500
501 // Check object-level permissions
502 $ok = checkUserAccessToObject(DolibarrApiAccess::$user, array($object->element), $object, $object->table_element, '');
503 if (empty($ok)) {
504 throw new RestException(403, 'Access not allowed to this object (refused by checkUserAccessToObject)');
505 }
506
507 // Check permission on module
508 if ($modulepart == 'societe' || $modulepart == 'thirdparty') {
509 if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
510 throw new RestException(403);
511 }
512 } elseif ($modulepart == 'user') {
513 // Can get doc if has permission to read all user or if it is user itself
514 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && DolibarrApiAccess::$user->id != $id) {
515 throw new RestException(403);
516 }
517 } elseif ($modulepart == 'adherent' || $modulepart == 'member') {
518 if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) {
519 throw new RestException(403);
520 }
521 } elseif ($modulepart == 'propal' || $modulepart == 'proposal') {
522 if (!DolibarrApiAccess::$user->hasRight('propal', 'lire')) {
523 throw new RestException(403);
524 }
525 } elseif ($modulepart == 'supplier_proposal') {
526 if (!DolibarrApiAccess::$user->hasRight('supplier_proposal', 'read')) {
527 throw new RestException(403);
528 }
529 } elseif ($modulepart == 'commande' || $modulepart == 'order') {
530 if (!DolibarrApiAccess::$user->hasRight('commande', 'lire')) {
531 throw new RestException(403);
532 }
533 } elseif ($modulepart == 'commande_fournisseur' || $modulepart == 'supplier_order') {
534 $modulepart = 'supplier_order';
535 if (!DolibarrApiAccess::$user->hasRight('fournisseur', 'commande', 'lire') && !DolibarrApiAccess::$user->hasRight('supplier_order', 'lire')) {
536 throw new RestException(403);
537 }
538 } elseif ($modulepart == 'shipment' || $modulepart == 'expedition') {
539 if (!DolibarrApiAccess::$user->hasRight('expedition', 'lire')) {
540 throw new RestException(403);
541 }
542 } elseif ($modulepart == 'facture' || $modulepart == 'invoice') {
543 if (!DolibarrApiAccess::$user->hasRight('facture', 'lire')) {
544 throw new RestException(403);
545 }
546 } elseif ($modulepart == 'facture_fournisseur' || $modulepart == 'supplier_invoice') {
547 $modulepart = 'supplier_invoice';
548 if (!DolibarrApiAccess::$user->hasRight('fournisseur', 'facture', 'lire') && !DolibarrApiAccess::$user->hasRight('supplier_invoice', 'lire')) {
549 throw new RestException(403);
550 }
551 } elseif ($modulepart == 'produit' || $modulepart == 'product' || $modulepart == 'service') {
552 if (!DolibarrApiAccess::$user->hasRight('produit', 'lire')) {
553 throw new RestException(403);
554 }
555 } elseif ($modulepart == 'agenda' || $modulepart == 'action' || $modulepart == 'event' || $modulepart == 'actioncomm') {
556 if (!DolibarrApiAccess::$user->hasRight('agenda', 'myactions', 'read') && !DolibarrApiAccess::$user->hasRight('agenda', 'allactions', 'read')) {
557 throw new RestException(403);
558 }
559 } elseif ($modulepart == 'expensereport') {
560 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'read')) {
561 throw new RestException(403);
562 }
563 } elseif ($modulepart == 'holiday') {
564 if (!DolibarrApiAccess::$user->hasRight('holiday', 'read')) {
565 throw new RestException(403);
566 }
567 } elseif ($modulepart == 'ticket') {
568 if (!DolibarrApiAccess::$user->hasRight('ticket', 'read')) {
569 throw new RestException(403);
570 }
571 } elseif ($modulepart == 'knowledgemanagement') {
572 if (!DolibarrApiAccess::$user->hasRight('knowledgemanagement', 'knowledgerecord', 'read')) {
573 throw new RestException(403);
574 }
575 } elseif ($modulepart == 'categorie' || $modulepart == 'category') {
576 if (!DolibarrApiAccess::$user->hasRight('categorie', 'lire')) {
577 throw new RestException(403);
578 }
579 } elseif ($modulepart == 'ecm') {
580 throw new RestException(500, 'Modulepart Ecm not implemented yet.');
581 // if (!DolibarrApiAccess::$user->hasRight('ecm', 'read')) {
582 // throw new RestException(403);
583 // }
584 } elseif ($modulepart == 'contrat' || $modulepart == 'contract') {
585 $modulepart = 'contrat';
586 if (!DolibarrApiAccess::$user->hasRight('contrat', 'lire')) {
587 throw new RestException(403);
588 }
589 } elseif ($modulepart == 'intervention' || $modulepart == 'ficheinter') {
590 $modulepart = 'ficheinter';
591 if (!DolibarrApiAccess::$user->hasRight('ficheinter', 'lire')) {
592 throw new RestException(403);
593 }
594 } elseif ($modulepart == 'projet' || $modulepart == 'project') {
595 $modulepart = 'project';
596 if (!DolibarrApiAccess::$user->hasRight('projet', 'lire')) {
597 throw new RestException(403);
598 }
599 } elseif ($modulepart == 'task' || $modulepart == 'project_task') {
600 $modulepart = 'project_task';
601 if (!DolibarrApiAccess::$user->hasRight('projet', 'lire')) {
602 throw new RestException(403);
603 }
604 } elseif ($modulepart == 'mrp') {
605 $modulepart = 'mrp';
606 if (!DolibarrApiAccess::$user->hasRight('mrp', 'read')) {
607 throw new RestException(403);
608 }
609 } elseif ($modulepart == 'contact' || $modulepart == 'socpeople') {
610 $modulepart = 'contact';
611 if (!DolibarrApiAccess::$user->hasRight('societe', 'contact', 'lire')) {
612 throw new RestException(403);
613 }
614 } elseif ($modulepart == 'stock') {
615 if (!DolibarrApiAccess::$user->hasRight('stock', 'lire')) {
616 throw new RestException(403);
617 }
618 } else {
619 throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.');
620 }
621
622 // Scan files into directory
623 $recursive = 0;
624 $type = 'files';
625
626 $objectType = $modulepart;
627 if (! empty($object->id) && ! empty($object->table_element)) {
628 $objectType = $object->table_element;
629 }
630
631 $filearray = dol_dir_list($upload_dir, $type, $recursive, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
632
633 $countarray = is_array($filearray) ? count($filearray) : 0;
634
635 if (empty($filearray)) {
636 throw new RestException(404, 'Search for modulepart '.$modulepart.' with Id '.$id.(!empty($ref) ? ' or Ref '.$ref : '').' does not return any document.');
637 } else {
638 $filearray = array_slice($filearray, $limit * $page, $limit);
639 if (($object->id) > 0 && !empty($modulepart)) {
640 require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
641 $ecmfile = new EcmFiles($this->db);
642 $result = $ecmfile->fetchAll('', '', 0, 0, array('t.src_object_type' => $objectType, 't.src_object_id' => $object->id));
643 if ($result < 0) {
644 throw new RestException(503, 'Error when retrieve ecm list : '.$this->db->lasterror());
645 } elseif (is_array($ecmfile->lines) && count($ecmfile->lines) > 0) {
646 foreach ($filearray as &$fileitem) {
647 foreach ($ecmfile->lines as $line) {
648 if ($fileitem['name'] == $line->filename) {
649 // Next line converts EcmFilesLine properties to array
650 //$fileitem = array_merge($fileitem, (array) $line);
651 $fileitem['ref'] = $line->ref;
652 $fileitem['label'] = $line->label;
653 $fileitem['filepath'] = $line->filepath;
654 $fileitem['filename'] = $line->filename;
655 $fileitem['fullpath_orig'] = $line->fullpath_orig;
656 $fileitem['position'] = $line->position;
657 $fileitem['gen_or_uploaded'] = $line->gen_or_uploaded;
658 $fileitem['description'] = $line->desc;
659 $fileitem['keywords'] = $line->keywords;
660 $fileitem['cover'] = $line->cover;
661 $fileitem['share'] = $line->share;
662 $fileitem['date_c'] = $line->date_c;
663 $fileitem['agenda_id'] = $line->agenda_id;
664 $fileitem['fk_user_c'] = $line->fk_user_c;
665 $fileitem['fk_user_m'] = $line->fk_user_m;
666 $fileitem['note_private'] = $line->note_private;
667 $fileitem['note_public'] = $line->note_public;
668 }
669 }
670 if (isset($fileitem['relativename'])) {
671 $fileitem['content-type'] = dol_mimetype((string) $fileitem['relativename']);
672 }
673 }
674
675 // Select only files that match the requested $content_type, if provided
676 $arraycontenttype = explode(",", $content_type);
677 if (!empty($content_type)) {
678 $filearray = array_filter(
679 $filearray,
684 static function ($fileitem) use (&$arraycontenttype) {
685 return in_array(($fileitem['content-type'] ?: 'UNKNOWN'), $arraycontenttype);
686 }
687 );
688 }
689 }
690 }
691 }
692
693 // Clean result from fullname
694 foreach ($filearray as $tmpkey => $tmpval) {
695 unset($filearray[$tmpkey]['path']);
696 unset($filearray[$tmpkey]['fullname']);
697 }
698
699 //if $pagination_data is true the response will contain element data with all values and element pagination with pagination data(total,page,limit)
700 if ($pagination_data) {
701 $filearray = [
702 'data' => $filearray,
703 'pagination' => [
704 'total' => (int) $countarray,
705 'page' => $page, // count starts from 0
706 'page_count' => (int) ceil((int) $countarray / $limit),
707 'limit' => $limit
708 ]
709 ];
710 }
711
712 return $filearray;
713 }
714
715
724 /*
725 public function get($id) {
726 return array('note'=>'xxx');
727 }*/
728
729
766 public function post($filename, $modulepart, $ref = '', $subdir = '', $filecontent = '', $fileencoding = '', $overwriteifexists = 0, $createdirifnotexists = 1, $position = 0, $cover = '', $array_options = [], $generateThumbs = 0, $share = 0)
767 {
768 global $conf;
769
770 $modulepartorig = $modulepart;
771
772 if (empty($modulepart)) {
773 throw new RestException(400, 'Modulepart not provided.');
774 }
775
776 $newfilecontent = '';
777 if (empty($fileencoding)) {
778 $newfilecontent = $filecontent;
779 }
780 if ($fileencoding == 'base64') {
781 $newfilecontent = base64_decode($filecontent);
782 }
783
784 $original_file = dol_sanitizeFileName($filename);
785 $relativefile = 'UNSET';
786
787 // Define $uploadir
788 $object = null;
789 $entity = DolibarrApiAccess::$user->entity;
790 if (empty($entity)) {
791 $entity = 1;
792 }
793
794 if ($ref) {
795 $tmpreldir = '';
796 $fetchbyid = false;
797
798 if ($modulepart == 'facture' || $modulepart == 'invoice') {
799 $modulepart = 'facture';
800
801 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
802 $object = new Facture($this->db);
803 } elseif ($modulepart == 'facture_fournisseur' || $modulepart == 'supplier_invoice') {
804 $modulepart = 'supplier_invoice';
805
806 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
807 $object = new FactureFournisseur($this->db);
808 } elseif ($modulepart == 'commande' || $modulepart == 'order') {
809 $modulepart = 'commande';
810
811 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
812 $object = new Commande($this->db);
813 } elseif ($modulepart == 'commande_fournisseur' || $modulepart == 'supplier_order') {
814 $modulepart = 'supplier_order';
815
816 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
817 $object = new CommandeFournisseur($this->db);
818 } elseif ($modulepart == 'projet' || $modulepart == 'project') {
819 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
820 $object = new Project($this->db);
821 } elseif ($modulepart == 'task' || $modulepart == 'project_task') {
822 $modulepart = 'project_task';
823
824 require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
825 $object = new Task($this->db);
826
827 $task_result = $object->fetch(0, $ref);
828
829 // Fetching the tasks project is required because its out_dir might be a sub-directory of the project
830 if ($task_result > 0) {
831 $project_result = $object->fetchProject();
832
833 if ($project_result >= 0) {
834 $tmpreldir = dol_sanitizeFileName((string) $object->project->ref).'/';
835 }
836 } else {
837 throw new RestException(500, 'Error while fetching Task '.$ref);
838 }
839 } elseif ($modulepart == 'product' || $modulepart == 'produit' || $modulepart == 'service' || $modulepart == 'produit|service') {
840 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
841 $object = new Product($this->db);
842 } elseif ($modulepart == 'expensereport') {
843 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
844 $object = new ExpenseReport($this->db);
845 } elseif ($modulepart == 'holiday') {
846 require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
847 $object = new Holiday($this->db);
848 } elseif ($modulepart == 'ficheinter' || $modulepart == 'intervention') {
849 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
850 $object = new Fichinter($this->db);
851 } elseif ($modulepart == 'shipment' || $modulepart == 'expedition') {
852 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
853 $object = new Expedition($this->db);
854 } elseif ($modulepart == 'adherent' || $modulepart == 'member') {
855 $modulepart = 'adherent';
856 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
857 $object = new Adherent($this->db);
858 } elseif ($modulepart == 'proposal' || $modulepart == 'propal' || $modulepart == 'propale') {
859 $modulepart = 'propale';
860 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
861 $object = new Propal($this->db);
862 } elseif ($modulepart == 'agenda' || $modulepart == 'action' || $modulepart == 'event') {
863 $modulepart = 'agenda';
864 require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
865 $object = new ActionComm($this->db);
866 } elseif ($modulepart == 'contact' || $modulepart == 'socpeople') {
867 $modulepart = 'contact';
868 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
869 $object = new Contact($this->db);
870 $fetchbyid = true;
871 } elseif ($modulepart == 'societe' || $modulepart == 'company') {
872 $modulepart = 'societe';
873 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
874 $object = new Societe($this->db);
875 $fetchbyid = true;
876 } elseif ($modulepart == 'knowledgemanagement') {
877 $modulepart = 'knowledgemanagement';
878 require_once DOL_DOCUMENT_ROOT.'/knowledgemanagement/class/knowledgerecord.class.php';
879 $object = new KnowledgeRecord($this->db);
880 $fetchbyid = true;
881 } elseif ($modulepart == 'ticket') {
882 $modulepart = 'ticket';
883 require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
884 $object = new Ticket($this->db);
885 $fetchbyid = true;
886 } elseif ($modulepart == 'contrat' || $modulepart == 'contract') {
887 $modulepart = 'contrat';
888 require_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php';
889 $object = new Contrat($this->db);
890 } elseif ($modulepart == 'mrp') {
891 $modulepart = 'mrp';
892 require_once DOL_DOCUMENT_ROOT . '/mrp/class/mo.class.php';
893 $object = new Mo($this->db);
894 } elseif ($modulepart == 'stock') {
895 $modulepart = 'stock';
896 require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php';
897 $object = new Entrepot($this->db);
898 } elseif ($modulepart == 'ecm') {
899 throw new RestException(500, 'Using a non empty "ref" is not compatible with using modulepart = '.$modulepart);
900 } else {
901 // TODO Implement additional moduleparts
902 throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.');
903 }
904
905 // at this step $object is always an object
906 if ($fetchbyid) {
907 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
908 $result = $object->fetch((int) $ref);
909 } else {
910 $result = $object->fetch(0, $ref);
911 }
912
913 if ($result == 0) {
914 throw new RestException(404, "Object with ref '".$ref."' was not found.");
915 } elseif ($result < 0) {
916 throw new RestException(500, 'Error while fetching object: '.$object->error);
917 }
918
919 if (!($object->id > 0)) {
920 throw new RestException(404, 'The object '.$modulepart." with ref '".$ref."' was not found.");
921 }
922
923 // Special cases that need to use get_exdir to get real dir of object
924 // In future, all object should use this to define path of documents.
925 if ($modulepart == 'supplier_invoice') {
926 $tmpreldir = get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier');
927 }
928
929 // Test on permissions
930 //if ($modulepart != 'ecm') { // Here $modulepart is always != 'ecm'
931 if ($modulepart == 'societe') {
932 $relativefile = $tmpreldir.dol_sanitizeFileName((string) $object->id);
933 } else {
934 $relativefile = $tmpreldir.dol_sanitizeFileName((string) $object->ref);
935 }
936 $tmp = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, $ref, 'write');
937 if (empty($tmp['accessallowed'])) {
938 throw new RestException(403, 'Access not allowed to upload file into this directory');
939 }
940 // Check permission on the object the document is attached to (thirdparties of a restricted sales representative, ...)
941 if (!checkUserAccessToDocumentObject(DolibarrApiAccess::$user, $modulepart, $relativefile.'/'.$original_file, 'write')) {
942 throw new RestException(403, 'Access not allowed to the object of this document');
943 }
944 $upload_dir = $tmp['original_file']; // No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir
945 /*} else {
946 if (!DolibarrApiAccess::$user->hasRight('ecm', 'upload')) {
947 throw new RestException(403, 'Missing permission to upload files in ECM module');
948 }
949 $upload_dir = $conf->medias->multidir_output[$conf->entity];
950 }*/
951
952 if (empty($upload_dir) || $upload_dir == '/') {
953 throw new RestException(500, 'This value of modulepart ('.$modulepart.') does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.');
954 }
955 } else {
956 if ($modulepart == 'invoice') {
957 $modulepart = 'facture';
958 }
959 if ($modulepart == 'member') {
960 $modulepart = 'adherent';
961 }
962
963 // Test on permissions
964 if ($modulepart != 'ecm') {
965 $relativefile = $subdir;
966 $tmp = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, '', 'write');
967 if (empty($tmp['accessallowed'])) {
968 throw new RestException(403, 'Access not allowed to upload file into this directory');
969 }
970 // Check permission on the object the document is attached to (thirdparties of a restricted sales representative, ...)
971 if (!checkUserAccessToDocumentObject(DolibarrApiAccess::$user, $modulepart, $relativefile.'/'.$original_file, 'write')) {
972 throw new RestException(403, 'Access not allowed to the object of this document');
973 }
974 $upload_dir = $tmp['original_file']; // No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir
975 } else {
976 if (!DolibarrApiAccess::$user->hasRight('ecm', 'upload')) {
977 throw new RestException(403, 'Missing permission to upload files in ECM module');
978 }
979 $upload_dir = $conf->medias->multidir_output[$conf->entity];
980 }
981
982 if (empty($upload_dir) || $upload_dir == '/') {
983 if (!empty($tmp['error'])) {
984 throw new RestException(403, 'Error returned by dol_check_secure_access_document: '.$tmp['error']);
985 } else {
986 throw new RestException(400, 'This value of modulepart ('.$modulepart.') is not allowed with this value of subdir ('.$relativefile.')');
987 }
988 }
989 }
990 // $original_file here is still value of filename without any dir.
991
992 $upload_dir = dol_sanitizePathName($upload_dir);
993
994 if (!empty($createdirifnotexists)) {
995 if (dol_mkdir($upload_dir) < 0) { // needed by products
996 throw new RestException(500, 'Error while trying to create directory '.$upload_dir);
997 }
998 }
999
1000 $destfile = $upload_dir.'/'.$original_file;
1001 $destfiletmp = DOL_DATA_ROOT.'/admin/temp/'.$original_file;
1002 dol_delete_file($destfiletmp);
1003 //var_dump($original_file);exit;
1004
1005 if (!dol_is_dir(dirname($destfile))) {
1006 throw new RestException(400, 'Directory does not exists : '.dirname($destfile));
1007 }
1008
1009 if (!$overwriteifexists && dol_is_file($destfile)) {
1010 throw new RestException(400, "File with name '".$original_file."' already exists.");
1011 }
1012
1013 // in case temporary directory admin/temp doesn't exist
1014 if (!dol_is_dir(dirname($destfiletmp))) {
1015 dol_mkdir(dirname($destfiletmp));
1016 }
1017
1018 $fhandle = @fopen($destfiletmp, 'w');
1019 if ($fhandle) {
1020 $nbofbyteswrote = fwrite($fhandle, $newfilecontent);
1021 fclose($fhandle);
1022 dolChmod($destfiletmp);
1023 } else {
1024 throw new RestException(500, "Failed to open file '".$destfiletmp."' for write");
1025 }
1026
1027 $disablevirusscan = 0;
1028 $src_file = $destfiletmp;
1029 $dest_file = $destfile;
1030
1031 // Security:
1032 // If we need to make a virus scan
1033 if (empty($disablevirusscan) && file_exists($src_file)) {
1034 $checkvirusarray = dolCheckVirus($src_file, $dest_file);
1035 if (count($checkvirusarray)) {
1036 dol_syslog('Files.lib::dol_move_uploaded_file File "'.$src_file.'" (target name "'.$dest_file.'") KO with antivirus: errors='.implode(',', $checkvirusarray), LOG_WARNING);
1037 throw new RestException(500, 'ErrorFileIsInfectedWithAVirus: '.implode(',', $checkvirusarray));
1038 }
1039 }
1040
1041 // Security:
1042 // Disallow file with some extensions. We rename them.
1043 // Because if we put the documents directory into a directory inside web root (very bad), this allows to execute on demand arbitrary code.
1044 if (isAFileWithExecutableContent($dest_file) && !getDolGlobalString('MAIN_DOCUMENT_IS_OUTSIDE_WEBROOT_SO_NOEXE_NOT_REQUIRED')) {
1045 // $upload_dir ends with a slash, so be must be sure the medias dir to compare to ends with slash too.
1046 $publicmediasdirwithslash = $conf->medias->multidir_output[$conf->entity];
1047 if (!preg_match('/\/$/', $publicmediasdirwithslash)) {
1048 $publicmediasdirwithslash .= '/';
1049 }
1050
1051 if (strpos($upload_dir, $publicmediasdirwithslash) !== 0 || !getDolGlobalInt("MAIN_DOCUMENT_DISABLE_NOEXE_IN_MEDIAS_DIR")) { // We never add .noexe on files into media directory
1052 $dest_file .= '.noexe';
1053 }
1054 }
1055
1056 // Security:
1057 // We refuse cache files/dirs, upload using .. and pipes into filenames.
1058 if (preg_match('/^\./', basename($src_file)) || preg_match('/\.\./', $src_file) || preg_match('/[<>|]/', $src_file)) {
1059 dol_syslog("Refused to deliver file ".$src_file, LOG_WARNING);
1060 throw new RestException(500, "Refused to deliver file ".$src_file);
1061 }
1062
1063 // Security:
1064 // We refuse cache files/dirs, upload using .. and pipes into filenames.
1065 if (preg_match('/^\./', basename($dest_file)) || preg_match('/\.\./', $dest_file) || preg_match('/[<>|]/', $dest_file)) {
1066 dol_syslog("Refused to deliver file ".$dest_file, LOG_WARNING);
1067 throw new RestException(500, "Refused to deliver file ".$dest_file);
1068 }
1069
1070 $moreinfo = array('note_private' => 'File uploaded using API /documents from IP '.getUserRemoteIP());
1071 // $object may be null
1072 if (is_object($object) && $object->id > 0) {
1073 $moreinfo['src_object_type'] = $object->table_element;
1074 $moreinfo['src_object_id'] = $object->id;
1075 }
1076 if (!empty($array_options)) {
1077 $moreinfo = array_merge($moreinfo, ["array_options" => $array_options]);
1078 }
1079 if (!empty($position)) {
1080 $moreinfo = array_merge($moreinfo, ["position" => $position]);
1081 }
1082 if (!empty($cover)) {
1083 $moreinfo = array_merge($moreinfo, ["cover" => $cover]);
1084 }
1085 if (!empty($share)) {
1086 require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
1087 $moreinfo = array_merge($moreinfo, ["share" => getRandomPassword(true)]);
1088 }
1089 $moreinfo['gen_or_uploaded'] = 'api';
1090
1091 // Move the temporary file at its final emplacement
1092 $result = dol_move($destfiletmp, $dest_file, '0', $overwriteifexists, 1, 1, $moreinfo);
1093 if (!$result) {
1094 throw new RestException(500, "Failed to move file into '".$dest_file."'");
1095 }
1096
1097 if (is_object($object) && $generateThumbs) {
1098 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1099 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; // image_format_supported() is defined here
1100 if (image_format_supported($dest_file)) {
1101 $object->addThumbs($dest_file);
1102 }
1103 }
1104
1105 return dol_basename($destfile);
1106 }
1107
1127 public function delete($modulepart, $original_file)
1128 {
1129 global $conf;
1130
1131 if (empty($modulepart)) {
1132 throw new RestException(400, 'bad value for parameter modulepart');
1133 }
1134 if (empty($original_file)) {
1135 throw new RestException(400, 'bad value for parameter original_file');
1136 }
1137
1138 // Normalize modulepart for project_task
1139 if ($modulepart == 'task') {
1140 $modulepart = 'project_task';
1141 }
1142
1143 //--- Finds and returns the document
1144 $entity = $conf->entity;
1145
1146 // Special cases that need to use get_exdir to get real dir of object
1147 // If future, all object should use this to define path of documents.
1148 /*
1149 $tmpreldir = '';
1150 if ($modulepart == 'supplier_invoice') {
1151 $tmpreldir = get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier');
1152 }
1153
1154 $relativefile = $tmpreldir.dol_sanitizeFileName($object->ref); */
1155 $relativefile = $original_file;
1156
1157 $check_access = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, '', 'write');
1158 $accessallowed = $check_access['accessallowed'];
1159 $sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals'];
1160 $original_file = $check_access['original_file'];
1161
1162 if (preg_match('/\.\./', $original_file) || preg_match('/[<>|]/', $original_file)) {
1163 throw new RestException(403);
1164 }
1165 if (!$accessallowed) {
1166 throw new RestException(403);
1167 }
1168 // Check permission on the object the document is attached to (thirdparties of a restricted sales representative, ...)
1169 if (!checkUserAccessToDocumentObject(DolibarrApiAccess::$user, $modulepart, $relativefile, 'write')) {
1170 throw new RestException(403, 'Access not allowed to the object of this document');
1171 }
1172
1173 if (DolibarrApiAccess::$user->socid > 0) {
1174 if ($sqlprotectagainstexternals) {
1175 $resql = $this->db->query($sqlprotectagainstexternals);
1176 if ($resql) {
1177 $num = $this->db->num_rows($resql);
1178 $i = 0;
1179 while ($i < $num) {
1180 $obj = $this->db->fetch_object($resql);
1181 if (DolibarrApiAccess::$user->socid != $obj->fk_soc) {
1182 throw new RestException(403, 'Not allowed to download documents with such a ref');
1183 }
1184 $i++;
1185 }
1186 }
1187 }
1188 }
1189
1190 $filename = basename($original_file);
1191 $original_file_osencoded = dol_osencode($original_file); // New file name encoded in OS encoding charset
1192
1193 if (!file_exists($original_file_osencoded)) {
1194 dol_syslog("Try to download not found file ".$original_file_osencoded, LOG_WARNING);
1195 throw new RestException(404, 'File not found');
1196 }
1197
1198 if (@unlink($original_file_osencoded)) {
1199 return array(
1200 'success' => array(
1201 'code' => 200,
1202 'message' => 'Document deleted'
1203 )
1204 );
1205 }
1206
1207 throw new RestException(403);
1208 }
1209}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to manage agenda events (actions)
Class to manage members of a foundation.
Class to manage predefined suppliers products.
Class to manage customers orders.
Class to manage contact/addresses.
API class for receive files.
post($filename, $modulepart, $ref='', $subdir='', $filecontent='', $fileencoding='', $overwriteifexists=0, $createdirifnotexists=1, $position=0, $cover='', $array_options=[], $generateThumbs=0, $share=0)
Return a document.
__construct()
Constructor.
getDocumentsListByElement($modulepart, $id=0, $ref='', $sortfield='', $sortorder='', $limit=100, $page=0, $content_type='', $pagination_data=false)
List all documents of an element.
index($modulepart, $original_file='')
Download a given document.
builddoc($modulepart, $original_file='', $doctemplate='', $langcode='')
Build a document.
Class for API REST v1.
Definition api.class.php:35
Class to manage ECM files.
Class to manage warehouses.
Class to manage Trips and Expenses.
Class to manage suppliers invoices.
Class to manage invoices.
Class of the module paid holiday.
Class for KnowledgeRecord.
Class for Mo.
Definition mo.class.php:35
Class to manage products or services.
Class to manage projects.
Class to manage proposals.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage tasks.
Class to manage translations.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array(), $entity=null)
Move a file into another name.
dol_basename($pathfile)
Make a basename working with all page code (default PHP basenamed fails with cyrillic).
Definition files.lib.php:39
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser=null, $refname='', $mode='read')
Security check when accessing to a document (used by document.php, viewimage.php and webservices to g...
dol_is_file($pathoffile)
Return if path is a file.
dolCheckVirus($src_file, $dest_file='')
Check virus into a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:64
dol_is_dir($folder)
Test if filename is a directory.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_sanitizePathName($str, $newstr='_', $unaccent=0, $allowdash=0)
Clean a string to use it as a path name.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
isAFileWithExecutableContent($filename)
Return if a file can contains executable content.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
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
Class to generate the form for creating a new ticket.
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
checkUserAccessToObject($user, array $featuresarray, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='', $dbt_select='rowid', $parenttableforentity='')
Check that access by a given user to an object is ok.
checkUserAccessToDocumentObject(User $user, $modulepart, $original_file, $mode='read')
Check that a user can access the object a document is attached to.