document_actions_pre_headers.tpl.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  3. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. * or see http://www.gnu.org/
  18. */
  19. // Variable $upload_dir must be defined when entering here
  20. // Send file/link
  21. if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
  22. {
  23. if ($object->id)
  24. {
  25. dol_add_file_process($upload_dir, 0, 1, 'userfile', GETPOST('savingdocmask'));
  26. }
  27. }
  28. elseif (GETPOST('linkit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
  29. {
  30. if ($object->id)
  31. {
  32. $link = GETPOST('link', 'alpha');
  33. if ($link)
  34. {
  35. if (substr($link, 0, 7) != 'http://' && substr($link, 0, 8) != 'https://') {
  36. $link = 'http://' . $link;
  37. }
  38. dol_add_file_process($upload_dir, 0, 1, 'userfile', null, $link);
  39. }
  40. }
  41. }
  42. // Delete file/link
  43. if ($action == 'confirm_deletefile' && $confirm == 'yes')
  44. {
  45. if ($object->id)
  46. {
  47. $urlfile = GETPOST('urlfile', 'alpha'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  48. if (GETPOST('section')) $file = $upload_dir . "/" . $urlfile; // For a delete of GED module urlfile contains full path from upload_dir
  49. else // For documents pages, upload_dir contains already path to file from module dir, so we clean path into urlfile.
  50. {
  51. $urlfile=basename($urlfile);
  52. $file = $upload_dir . "/" . $urlfile;
  53. }
  54. $linkid = GETPOST('linkid', 'int'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  55. if ($urlfile)
  56. {
  57. $dir = dirname($file).'/'; // Chemin du dossier contenant l'image d'origine
  58. $dirthumb = $dir.'/thumbs/'; // Chemin du dossier contenant la vignette
  59. $ret = dol_delete_file($file, 0, 0, 0, $object);
  60. // Si elle existe, on efface la vignette
  61. if (preg_match('/(\.jpg|\.jpeg|\.bmp|\.gif|\.png|\.tiff)$/i',$file,$regs))
  62. {
  63. $photo_vignette=basename(preg_replace('/'.$regs[0].'/i','',$file).'_small'.$regs[0]);
  64. if (file_exists(dol_osencode($dirthumb.$photo_vignette)))
  65. {
  66. dol_delete_file($dirthumb.$photo_vignette);
  67. }
  68. $photo_vignette=basename(preg_replace('/'.$regs[0].'/i','',$file).'_mini'.$regs[0]);
  69. if (file_exists(dol_osencode($dirthumb.$photo_vignette)))
  70. {
  71. dol_delete_file($dirthumb.$photo_vignette);
  72. }
  73. }
  74. if ($ret) setEventMessage($langs->trans("FileWasRemoved", $urlfile));
  75. else setEventMessage($langs->trans("ErrorFailToDeleteFile", $urlfile), 'errors');
  76. }
  77. elseif ($linkid)
  78. {
  79. require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
  80. $link = new Link($db);
  81. $link->id = $linkid;
  82. $link->fetch();
  83. $res = $link->delete($user);
  84. $langs->load('link');
  85. if ($res > 0) {
  86. setEventMessage($langs->trans("LinkRemoved", $link->label));
  87. } else {
  88. if (count($link->errors)) {
  89. setEventMessages('', $link->errors, 'errors');
  90. } else {
  91. setEventMessage($langs->trans("ErrorFailedToDeleteLink", $link->label), 'errors');
  92. }
  93. }
  94. }
  95. header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id.(!empty($withproject)?'&withproject=1':''));
  96. exit;
  97. }
  98. }
  99. elseif ($action == 'confirm_updateline' && GETPOST('save') && GETPOST('link', 'alpha'))
  100. {
  101. require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
  102. $langs->load('link');
  103. $link = new Link($db);
  104. $link->id = GETPOST('linkid', 'int');
  105. $f = $link->fetch();
  106. if ($f)
  107. {
  108. $link->url = GETPOST('link', 'alpha');
  109. if (substr($link->url, 0, 7) != 'http://' && substr($link->url, 0, 8) != 'https://')
  110. {
  111. $link->url = 'http://' . $link->url;
  112. }
  113. $link->label = GETPOST('label', 'alpha');
  114. $res = $link->update($user);
  115. if (!$res)
  116. {
  117. setEventMessage($langs->trans("ErrorFailedToUpdateLink", $link->label));
  118. }
  119. }
  120. else
  121. {
  122. //error fetching
  123. }
  124. }