23use Luracast\Restler\RestException;
25require_once DOL_DOCUMENT_ROOT.
'/main.inc.php';
26require_once DOL_DOCUMENT_ROOT.
'/api/class/api.class.php';
27require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
63 public function index($modulepart, $original_file =
'')
67 if (empty($modulepart)) {
68 throw new RestException(400,
'bad value for parameter modulepart');
70 if (empty($original_file)) {
71 throw new RestException(400,
'bad value for parameter original_file');
75 $entity =
$conf->entity;
86 $relativefile = $original_file;
89 $accessallowed = $check_access[
'accessallowed'];
90 $sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
91 $original_file = $check_access[
'original_file'];
93 if (preg_match(
'/\.\./', $original_file) || preg_match(
'/[<>|]/', $original_file)) {
94 throw new RestException(403);
96 if (!$accessallowed) {
97 throw new RestException(403);
100 $filename = basename($original_file);
101 $original_file_osencoded =
dol_osencode($original_file);
103 if (!file_exists($original_file_osencoded)) {
104 dol_syslog(
"Try to download not found file ".$original_file_osencoded, LOG_WARNING);
105 throw new RestException(404,
'File not found');
108 $file_content = file_get_contents($original_file_osencoded);
109 return array(
'filename'=>$filename,
'content-type' =>
dol_mimetype($filename),
'filesize'=>filesize($original_file),
'content'=>base64_encode($file_content),
'encoding'=>
'base64');
134 public function builddoc($modulepart, $original_file =
'', $doctemplate =
'', $langcode =
'')
136 global
$conf, $langs;
138 if (empty($modulepart)) {
139 throw new RestException(400,
'bad value for parameter modulepart');
141 if (empty($original_file)) {
142 throw new RestException(400,
'bad value for parameter original_file');
145 $outputlangs = $langs;
146 if ($langcode && $langs->defaultlang != $langcode) {
148 $outputlangs->setDefaultLang($langcode);
152 $entity =
$conf->entity;
163 $relativefile = $original_file;
166 $accessallowed = $check_access[
'accessallowed'];
167 $sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
168 $original_file = $check_access[
'original_file'];
170 if (preg_match(
'/\.\./', $original_file) || preg_match(
'/[<>|]/', $original_file)) {
171 throw new RestException(403);
173 if (!$accessallowed) {
174 throw new RestException(403);
184 if ($modulepart ==
'facture' || $modulepart ==
'invoice') {
185 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
186 $tmpobject =
new Facture($this->db);
187 $result = $tmpobject->fetch(0, preg_replace(
'/\.[^\.]+$/',
'', basename($original_file)));
189 throw new RestException(404,
'Invoice not found');
192 $templateused = $doctemplate ? $doctemplate : $tmpobject->model_pdf;
193 $result = $tmpobject->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
195 throw new RestException(500,
'Error generating document');
197 } elseif ($modulepart ==
'facture_fournisseur' || $modulepart ==
'invoice_supplier') {
198 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.facture.class.php';
200 $result = $tmpobject->fetch(0, preg_replace(
'/\.[^\.]+$/',
'', basename($original_file)));
202 throw new RestException(404,
'Supplier invoice not found');
205 $templateused = $doctemplate ? $doctemplate : $tmpobject->model_pdf;
206 $result = $tmpobject->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
208 throw new RestException(500,
'Error generating document');
210 } elseif ($modulepart ==
'commande' || $modulepart ==
'order') {
211 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
212 $tmpobject =
new Commande($this->db);
213 $result = $tmpobject->fetch(0, preg_replace(
'/\.[^\.]+$/',
'', basename($original_file)));
215 throw new RestException(404,
'Order not found');
217 $templateused = $doctemplate ? $doctemplate : $tmpobject->model_pdf;
218 $result = $tmpobject->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
220 throw new RestException(500,
'Error generating document');
222 } elseif ($modulepart ==
'propal' || $modulepart ==
'proposal') {
223 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
224 $tmpobject =
new Propal($this->db);
225 $result = $tmpobject->fetch(0, preg_replace(
'/\.[^\.]+$/',
'', basename($original_file)));
227 throw new RestException(404,
'Proposal not found');
229 $templateused = $doctemplate ? $doctemplate : $tmpobject->model_pdf;
230 $result = $tmpobject->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
232 throw new RestException(500,
'Error generating document');
234 } elseif ($modulepart ==
'contrat' || $modulepart ==
'contract') {
235 require_once DOL_DOCUMENT_ROOT .
'/contrat/class/contrat.class.php';
237 $tmpobject =
new Contrat($this->db);
238 $result = $tmpobject->fetch(0, preg_replace(
'/\.[^\.]+$/',
'', basename($original_file)));
241 throw new RestException(404,
'Contract not found');
244 $templateused = $doctemplate ? $doctemplate : $tmpobject->model_pdf;
245 $result = $tmpobject->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
248 throw new RestException(500,
'Error generating document missing doctemplate parameter');
250 } elseif ($modulepart ==
'expedition' || $modulepart ==
'shipment') {
251 require_once DOL_DOCUMENT_ROOT .
'/expedition/class/expedition.class.php';
254 $result = $tmpobject->fetch(0, preg_replace(
'/\.[^\.]+$/',
'', basename($original_file)));
257 throw new RestException(404,
'Shipment not found');
260 $templateused = $doctemplate ? $doctemplate : $tmpobject->model_pdf;
261 $result = $tmpobject->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
264 throw new RestException(500,
'Error generating document missing doctemplate parameter');
266 } elseif ($modulepart ==
'mrp') {
267 require_once DOL_DOCUMENT_ROOT .
'/mrp/class/mo.class.php';
269 $tmpobject =
new Mo($this->db);
270 $result = $tmpobject->fetch(0, preg_replace(
'/\.[^\.]+$/',
'', basename($original_file)));
273 throw new RestException(404,
'MO not found');
276 $templateused = $doctemplate ? $doctemplate : $tmpobject->model_pdf;
277 $result = $tmpobject->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
280 throw new RestException(500,
'Error generating document missing doctemplate parameter');
283 throw new RestException(403,
'Generation not available for this modulepart');
286 $filename = basename($original_file);
287 $original_file_osencoded =
dol_osencode($original_file);
289 if (!file_exists($original_file_osencoded)) {
290 throw new RestException(404,
'File not found');
293 $file_content = file_get_contents($original_file_osencoded);
294 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');
321 if (empty($modulepart)) {
322 throw new RestException(400,
'bad value for parameter modulepart');
325 if (empty(
$id) && empty($ref)) {
326 throw new RestException(400,
'bad value for parameter id or ref');
333 if ($modulepart ==
'societe' || $modulepart ==
'thirdparty') {
334 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
336 if (!DolibarrApiAccess::$user->hasRight(
'societe',
'lire')) {
337 throw new RestException(403);
343 throw new RestException(404,
'Thirdparty not found');
347 } elseif ($modulepart ==
'user') {
348 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
351 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && DolibarrApiAccess::$user->
id !=
$id) {
352 throw new RestException(403);
358 throw new RestException(404,
'User not found');
362 } elseif ($modulepart ==
'adherent' || $modulepart ==
'member') {
363 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
365 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'lire')) {
366 throw new RestException(403);
372 throw new RestException(404,
'Member not found');
376 } elseif ($modulepart ==
'propal' || $modulepart ==
'proposal') {
377 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
379 if (!DolibarrApiAccess::$user->hasRight(
'propal',
'lire')) {
380 throw new RestException(403);
386 throw new RestException(404,
'Proposal not found');
390 } elseif ($modulepart ==
'supplier_proposal') {
391 require_once DOL_DOCUMENT_ROOT.
'/supplier_proposal/class/supplier_proposal.class.php';
393 if (!DolibarrApiAccess::$user->hasRight(
'supplier_proposal',
'read')) {
394 throw new RestException(403);
400 throw new RestException(404,
'Supplier proposal not found');
404 } elseif ($modulepart ==
'commande' || $modulepart ==
'order') {
405 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
407 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
408 throw new RestException(403);
414 throw new RestException(404,
'Order not found');
418 } elseif ($modulepart ==
'commande_fournisseur' || $modulepart ==
'supplier_order') {
419 $modulepart =
'supplier_order';
421 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
423 if (!DolibarrApiAccess::$user->hasRight(
'fournisseur',
'commande',
'lire') && !DolibarrApiAccess::$user->hasRight(
'supplier_order',
'lire')) {
424 throw new RestException(403);
430 throw new RestException(404,
'Purchase order not found');
434 } elseif ($modulepart ==
'shipment' || $modulepart ==
'expedition') {
435 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
437 if (!DolibarrApiAccess::$user->hasRight(
'expedition',
'lire')) {
438 throw new RestException(403);
444 throw new RestException(404,
'Shipment not found');
448 } elseif ($modulepart ==
'facture' || $modulepart ==
'invoice') {
449 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
451 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
452 throw new RestException(403);
458 throw new RestException(404,
'Invoice not found');
462 } elseif ($modulepart ==
'facture_fournisseur' || $modulepart ==
'supplier_invoice') {
463 $modulepart =
'supplier_invoice';
465 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
467 if (!DolibarrApiAccess::$user->hasRight(
'fournisseur',
'facture',
'lire') && !DolibarrApiAccess::$user->hasRight(
'supplier_invoice',
'lire')) {
468 throw new RestException(403);
474 throw new RestException(404,
'Invoice not found');
478 } elseif ($modulepart ==
'produit' || $modulepart ==
'product') {
479 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
481 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
482 throw new RestException(403);
488 throw new RestException(404,
'Product not found');
489 } elseif ($result < 0) {
490 throw new RestException(500,
'Error while fetching object: '.
$object->error);
494 } elseif ($modulepart ==
'agenda' || $modulepart ==
'action' || $modulepart ==
'event') {
495 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
497 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'myactions',
'read') && !DolibarrApiAccess::$user->hasRight(
'agenda',
'allactions',
'read')) {
498 throw new RestException(403);
504 throw new RestException(404,
'Event not found');
508 } elseif ($modulepart ==
'expensereport') {
509 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
511 if (!DolibarrApiAccess::$user->hasRight(
'expensereport',
'read')) {
512 throw new RestException(403);
518 throw new RestException(404,
'Expense report not found');
522 } elseif ($modulepart ==
'knowledgemanagement') {
523 require_once DOL_DOCUMENT_ROOT.
'/knowledgemanagement/class/knowledgerecord.class.php';
525 if (!DolibarrApiAccess::$user->hasRight(
'knowledgemanagement',
'knowledgerecord',
'read') && !DolibarrApiAccess::$user->hasRight(
'knowledgemanagement',
'knowledgerecord',
'read')) {
526 throw new RestException(403);
532 throw new RestException(404,
'KM article not found');
536 } elseif ($modulepart ==
'categorie' || $modulepart ==
'category') {
537 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
539 if (!DolibarrApiAccess::$user->hasRight(
'categorie',
'lire')) {
540 throw new RestException(403);
546 throw new RestException(404,
'Category not found');
550 } elseif ($modulepart ==
'ecm') {
551 throw new RestException(500,
'Modulepart Ecm not implemented yet.');
566 } elseif ($modulepart ==
'contrat' || $modulepart ==
'contract') {
567 $modulepart =
'contrat';
568 require_once DOL_DOCUMENT_ROOT .
'/contrat/class/contrat.class.php';
573 throw new RestException(404,
'Contract not found');
577 } elseif ($modulepart ==
'projet' || $modulepart ==
'project') {
578 $modulepart =
'project';
579 require_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
584 throw new RestException(404,
'Project not found');
588 } elseif ($modulepart ==
'mrp') {
590 require_once DOL_DOCUMENT_ROOT .
'/mrp/class/mo.class.php';
595 throw new RestException(404,
'MO not found');
600 throw new RestException(500,
'Modulepart '.$modulepart.
' not implemented yet.');
603 $objectType = $modulepart;
605 $objectType =
$object->table_element;
608 $filearray =
dol_dir_list($upload_dir, $type, $recursive,
'',
'(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) ==
'desc' ? SORT_DESC : SORT_ASC), 1);
609 if (empty($filearray)) {
610 throw new RestException(404,
'Search for modulepart '.$modulepart.
' with Id '.
$object->id.(!empty(
$object->ref) ?
' or Ref '.$object->ref :
'').
' does not return any document.');
612 if ((
$object->id) > 0 && !empty($modulepart)) {
613 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
615 $result = $ecmfile->fetchAll(
'',
'', 0, 0, array(
't.src_object_type' => $objectType,
't.src_object_id' =>
$object->id));
617 throw new RestException(503,
'Error when retrieve ecm list : '.$this->db->lasterror());
618 } elseif (is_array($ecmfile->lines) && count($ecmfile->lines) > 0) {
619 $count = count($filearray);
620 for ($i = 0 ; $i < $count ; $i++) {
621 foreach ($ecmfile->lines as $line) {
622 if ($filearray[$i][
'name'] == $line->filename) {
623 $filearray[$i] = array_merge($filearray[$i], (array) $line);
678 public function post($filename, $modulepart, $ref =
'', $subdir =
'', $filecontent =
'', $fileencoding =
'', $overwriteifexists = 0, $createdirifnotexists = 1, $position = 0, $cover =
'', $array_options = [])
682 $modulepartorig = $modulepart;
684 if (empty($modulepart)) {
685 throw new RestException(400,
'Modulepart not provided.');
688 $newfilecontent =
'';
689 if (empty($fileencoding)) {
690 $newfilecontent = $filecontent;
692 if ($fileencoding ==
'base64') {
693 $newfilecontent = base64_decode($filecontent);
700 $entity = DolibarrApiAccess::$user->entity;
701 if (empty($entity)) {
709 if ($modulepart ==
'facture' || $modulepart ==
'invoice') {
710 $modulepart =
'facture';
712 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
714 } elseif ($modulepart ==
'facture_fournisseur' || $modulepart ==
'supplier_invoice') {
715 $modulepart =
'supplier_invoice';
717 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
719 } elseif ($modulepart ==
'commande' || $modulepart ==
'order') {
720 $modulepart =
'commande';
722 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
724 } elseif ($modulepart ==
'commande_fournisseur' || $modulepart ==
'supplier_order') {
725 $modulepart =
'supplier_order';
727 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
729 } elseif ($modulepart ==
'projet' || $modulepart ==
'project') {
730 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
732 } elseif ($modulepart ==
'task' || $modulepart ==
'project_task') {
733 $modulepart =
'project_task';
735 require_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
738 $task_result =
$object->fetch(0, $ref);
741 if ($task_result > 0) {
742 $project_result =
$object->fetchProject();
744 if ($project_result >= 0) {
748 throw new RestException(500,
'Error while fetching Task '.$ref);
750 } elseif ($modulepart ==
'product' || $modulepart ==
'produit' || $modulepart ==
'service' || $modulepart ==
'produit|service') {
751 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
753 } elseif ($modulepart ==
'expensereport') {
754 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
756 } elseif ($modulepart ==
'fichinter') {
757 require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
759 } elseif ($modulepart ==
'adherent' || $modulepart ==
'member') {
760 $modulepart =
'adherent';
761 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
763 } elseif ($modulepart ==
'proposal' || $modulepart ==
'propal' || $modulepart ==
'propale') {
764 $modulepart =
'propale';
765 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
767 } elseif ($modulepart ==
'agenda' || $modulepart ==
'action' || $modulepart ==
'event') {
768 $modulepart =
'agenda';
769 require_once DOL_DOCUMENT_ROOT .
'/comm/action/class/actioncomm.class.php';
771 } elseif ($modulepart ==
'contact' || $modulepart ==
'socpeople') {
772 $modulepart =
'contact';
773 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
776 } elseif ($modulepart ==
'contrat' || $modulepart ==
'contract') {
777 $modulepart =
'contrat';
778 require_once DOL_DOCUMENT_ROOT .
'/contrat/class/contrat.class.php';
780 } elseif ($modulepart ==
'mrp') {
782 require_once DOL_DOCUMENT_ROOT .
'/mrp/class/mo.class.php';
786 throw new RestException(500,
'Modulepart '.$modulepart.
' not implemented yet.');
792 $result =
$object->fetch($ref);
794 $result =
$object->fetch(0, $ref);
798 throw new RestException(404,
"Object with ref '".$ref.
"' was not found.");
799 } elseif ($result < 0) {
800 throw new RestException(500,
'Error while fetching object: '.
$object->error);
805 throw new RestException(404,
'The object '.$modulepart.
" with ref '".$ref.
"' was not found.");
810 if ($modulepart ==
'supplier_invoice') {
815 if ($modulepart !=
'ecm') {
816 $relativefile = $tmpreldir.dol_sanitizeFileName(
$object->ref);
818 $upload_dir = $tmp[
'original_file'];
820 if (!DolibarrApiAccess::$user->hasRight(
'ecm',
'upload')) {
821 throw new RestException(403,
'Missing permission to upload files in ECM module');
823 $upload_dir =
$conf->medias->multidir_output[
$conf->entity];
826 if (empty($upload_dir) || $upload_dir ==
'/') {
827 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.');
830 if ($modulepart ==
'invoice') {
831 $modulepart =
'facture';
833 if ($modulepart ==
'member') {
834 $modulepart =
'adherent';
838 if ($modulepart !=
'ecm') {
839 $relativefile = $subdir;
841 $upload_dir = $tmp[
'original_file'];
843 if (!DolibarrApiAccess::$user->hasRight(
'ecm',
'upload')) {
844 throw new RestException(403,
'Missing permission to upload files in ECM module');
846 $upload_dir =
$conf->medias->multidir_output[
$conf->entity];
849 if (empty($upload_dir) || $upload_dir ==
'/') {
850 if (!empty($tmp[
'error'])) {
851 throw new RestException(403,
'Error returned by dol_check_secure_access_document: '.$tmp[
'error']);
853 throw new RestException(400,
'This value of modulepart ('.$modulepart.
') is not allowed with this value of subdir ('.$relativefile.
')');
861 if (!empty($createdirifnotexists)) {
863 throw new RestException(500,
'Error while trying to create directory '.$upload_dir);
867 $destfile = $upload_dir.
'/'.$original_file;
868 $destfiletmp = DOL_DATA_ROOT.
'/admin/temp/'.$original_file;
873 throw new RestException(400,
'Directory does not exists : '.dirname($destfile));
876 if (!$overwriteifexists &&
dol_is_file($destfile)) {
877 throw new RestException(400,
"File with name '".$original_file.
"' already exists.");
885 $fhandle = @fopen($destfiletmp,
'w');
887 $nbofbyteswrote = fwrite($fhandle, $newfilecontent);
891 throw new RestException(500,
"Failed to open file '".$destfiletmp.
"' for write");
894 $disablevirusscan = 0;
895 $src_file = $destfiletmp;
896 $dest_file = $destfile;
900 if (empty($disablevirusscan) && file_exists($src_file)) {
902 if (count($checkvirusarray)) {
903 dol_syslog(
'Files.lib::dol_move_uploaded_file File "'.$src_file.
'" (target name "'.$dest_file.
'") KO with antivirus: errors='.implode(
',', $checkvirusarray), LOG_WARNING);
904 throw new RestException(500,
'ErrorFileIsInfectedWithAVirus: '.implode(
',', $checkvirusarray));
913 $publicmediasdirwithslash =
$conf->medias->multidir_output[
$conf->entity];
914 if (!preg_match(
'/\/$/', $publicmediasdirwithslash)) {
915 $publicmediasdirwithslash .=
'/';
918 if (strpos($upload_dir, $publicmediasdirwithslash) !== 0 || !
getDolGlobalInt(
"MAIN_DOCUMENT_DISABLE_NOEXE_IN_MEDIAS_DIR")) {
919 $dest_file .=
'.noexe';
925 if (preg_match(
'/^\./', basename($src_file)) || preg_match(
'/\.\./', $src_file) || preg_match(
'/[<>|]/', $src_file)) {
926 dol_syslog(
"Refused to deliver file ".$src_file, LOG_WARNING);
927 throw new RestException(500,
"Refused to deliver file ".$src_file);
932 if (preg_match(
'/^\./', basename($dest_file)) || preg_match(
'/\.\./', $dest_file) || preg_match(
'/[<>|]/', $dest_file)) {
933 dol_syslog(
"Refused to deliver file ".$dest_file, LOG_WARNING);
934 throw new RestException(500,
"Refused to deliver file ".$dest_file);
937 $moreinfo = array(
'note_private' =>
'File uploaded using API /documents from IP '.
getUserRemoteIP());
939 $moreinfo[
'src_object_type'] =
$object->table_element;
940 $moreinfo[
'src_object_id'] =
$object->id;
942 if (!empty($array_options)) {
943 $moreinfo = array_merge($moreinfo, [
"array_options" => $array_options]);
945 if (!empty($position)) {
946 $moreinfo = array_merge($moreinfo, [
"position" => $position]);
948 if (!empty($cover)) {
949 $moreinfo = array_merge($moreinfo, [
"cover" => $cover]);
953 $result =
dol_move($destfiletmp, $dest_file,
'0', $overwriteifexists, 1, 1, $moreinfo);
955 throw new RestException(500,
"Failed to move file into '".$dest_file.
"'");
976 public function delete($modulepart, $original_file)
978 global
$conf, $langs;
980 if (empty($modulepart)) {
981 throw new RestException(400,
'bad value for parameter modulepart');
983 if (empty($original_file)) {
984 throw new RestException(400,
'bad value for parameter original_file');
988 $entity =
$conf->entity;
999 $relativefile = $original_file;
1002 $accessallowed = $check_access[
'accessallowed'];
1003 $sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
1004 $original_file = $check_access[
'original_file'];
1006 if (preg_match(
'/\.\./', $original_file) || preg_match(
'/[<>|]/', $original_file)) {
1007 throw new RestException(403);
1009 if (!$accessallowed) {
1010 throw new RestException(403);
1013 $filename = basename($original_file);
1014 $original_file_osencoded =
dol_osencode($original_file);
1016 if (!file_exists($original_file_osencoded)) {
1017 dol_syslog(
"Try to download not found file ".$original_file_osencoded, LOG_WARNING);
1018 throw new RestException(404,
'File not found');
1021 if (@unlink($original_file_osencoded)) {
1025 'message' =>
'Document deleted'
1030 throw new RestException(403);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage agenda events (actions)
Class to manage members of a foundation.
Class to manage categories.
Class to manage predefined suppliers products.
Class to manage customers orders.
API class for receive files.
post($filename, $modulepart, $ref='', $subdir='', $filecontent='', $fileencoding='', $overwriteifexists=0, $createdirifnotexists=1, $position=0, $cover='', $array_options=[])
Return a document.
__construct()
Constructor.
index($modulepart, $original_file='')
Download a document.
getDocumentsListByElement($modulepart, $id=0, $ref='', $sortfield='', $sortorder='')
Return the list of documents of a dedicated element (from its ID or Ref)
builddoc($modulepart, $original_file='', $doctemplate='', $langcode='')
Build a document.
Class to manage ECM files.
Class to manage Trips and Expenses.
Class to manage suppliers invoices.
Class to manage invoices.
Class for KnowledgeRecord.
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 translations.
Class to manage Dolibarr users.
dol_basename($pathfile)
Make a basename working with all page code (default PHP basenamed fails with cyrillic).
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_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array())
Move a file into another name.
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.
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.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
isAFileWithExecutableContent($filename)
Return if a file can contains executable content.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
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_sanitizePathName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a path name.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...