docfile.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <?php
  2. /* Copyright (C) 2008-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/ecm/docfile.php
  19. * \ingroup ecm
  20. * \brief Card of a file for ECM module
  21. * \author Laurent Destailleur
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/ecm.lib.php';
  28. // Load traductions files
  29. $langs->load("ecm");
  30. $langs->load("companies");
  31. $langs->load("other");
  32. $langs->load("users");
  33. $langs->load("orders");
  34. $langs->load("propal");
  35. $langs->load("bills");
  36. $langs->load("contracts");
  37. $langs->load("categories");
  38. if (!$user->rights->ecm->setup) accessforbidden();
  39. // Get parameters
  40. $socid = GETPOST("socid","int");
  41. // Security check
  42. if ($user->societe_id > 0)
  43. {
  44. $action = '';
  45. $socid = $user->societe_id;
  46. }
  47. $sortfield = GETPOST("sortfield",'alpha');
  48. $sortorder = GETPOST("sortorder",'alpha');
  49. $page = GETPOST("page",'int');
  50. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  51. $offset = $conf->liste_limit * $page;
  52. $pageprev = $page - 1;
  53. $pagenext = $page + 1;
  54. if (! $sortorder) $sortorder="ASC";
  55. if (! $sortfield) $sortfield="label";
  56. $cancel=GETPOST('cancel');
  57. $action=GETPOST('action','aZ09');
  58. $section=GETPOST("section");
  59. if (! $section)
  60. {
  61. dol_print_error('','Error, section parameter missing');
  62. exit;
  63. }
  64. $urlfile=GETPOST("urlfile");
  65. if (! $urlfile)
  66. {
  67. dol_print_error('',"ErrorParamNotDefined");
  68. exit;
  69. }
  70. // Load ecm object
  71. $ecmdir = new EcmDirectory($db);
  72. $result=$ecmdir->fetch(GETPOST("section"));
  73. if (! $result > 0)
  74. {
  75. dol_print_error($db,$ecmdir->error);
  76. exit;
  77. }
  78. $relativepath=$ecmdir->getRelativePath();
  79. $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
  80. /*
  81. $ecmfile = new ECMFile($db);
  82. if (! empty($_GET["fileid"]))
  83. {
  84. $result=$ecmfile->fetch($_GET["fileid"]);
  85. if (! $result > 0)
  86. {
  87. dol_print_error($db,$ecmfile->error);
  88. exit;
  89. }
  90. }
  91. */
  92. /*******************************************************************
  93. * ACTIONS
  94. *
  95. * Put here all code to do according to value of "action" parameter
  96. ********************************************************************/
  97. if ($action == 'cancel')
  98. {
  99. $action ='';
  100. if ($backtourl)
  101. {
  102. header("Location: ".$backtourl);
  103. exit;
  104. }
  105. else
  106. {
  107. header("Location: ".DOL_URL_ROOT.'/ecm/index.php?action=file_manager&section='.$section);
  108. exit;
  109. }
  110. }
  111. // Rename file
  112. if ($action == 'update')
  113. {
  114. $error=0;
  115. $oldlabel=GETPOST('urlfile');
  116. $newlabel=GETPOST('label');
  117. //$db->begin();
  118. $olddir=$ecmdir->getRelativePath(0);
  119. $olddir=$conf->ecm->dir_output.'/'.$olddir;
  120. $newdir=$olddir;
  121. $oldfile=$olddir.$oldlabel;
  122. $newfile=$newdir.$newlabel;
  123. //print $oldfile.' - '.$newfile;
  124. if ($newlabel != $oldlabel)
  125. {
  126. $result=dol_move($oldfile,$newfile);
  127. if (! $result)
  128. {
  129. $langs->load('errors');
  130. setEventMessages($langs->trans('ErrorFailToRenameFile',$oldfile,$newfile), null, 'errors');
  131. $error++;
  132. }
  133. }
  134. if (! $error)
  135. {
  136. //$db->commit();
  137. $urlfile=$newlabel;
  138. }
  139. else
  140. {
  141. //$db->rollback();
  142. }
  143. }
  144. /*******************************************************************
  145. * PAGE
  146. *
  147. * Put here all code to do according to value of "action" parameter
  148. ********************************************************************/
  149. llxHeader();
  150. $form=new Form($db);
  151. $fullpath=$conf->ecm->dir_output.'/'.$relativepath.$urlfile;
  152. $file = new stdClass();
  153. $file->section_id=$ecmdir->id;
  154. $file->label=$urlfile;
  155. $head = ecm_file_prepare_head($file);
  156. if ($_GET["action"] == 'edit')
  157. {
  158. print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  159. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  160. print '<input type="hidden" name="section" value="'.$section.'">';
  161. print '<input type="hidden" name="urlfile" value="'.$urlfile.'">';
  162. print '<input type="hidden" name="action" value="update">';
  163. }
  164. dol_fiche_head($head, 'card', $langs->trans("File"), 0, 'generic');
  165. print '<table class="border" width="100%">';
  166. print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>';
  167. $s='';
  168. $tmpecmdir=new EcmDirectory($db); // Need to create a new one
  169. $tmpecmdir->fetch($ecmdir->id);
  170. $result = 1;
  171. $i=0;
  172. while ($tmpecmdir && $result > 0)
  173. {
  174. $tmpecmdir->ref=$tmpecmdir->label;
  175. $s=$tmpecmdir->getNomUrl(1).$s;
  176. if ($tmpecmdir->fk_parent)
  177. {
  178. $s=' -> '.$s;
  179. $result=$tmpecmdir->fetch($tmpecmdir->fk_parent);
  180. }
  181. else
  182. {
  183. $tmpecmdir=0;
  184. }
  185. $i++;
  186. }
  187. print img_picto('','object_dir').' <a href="'.DOL_URL_ROOT.'/ecm/index.php">'.$langs->trans("ECMRoot").'</a> -> ';
  188. print $s;
  189. print ' -> ';
  190. if (GETPOST('action','aZ09') == 'edit') print '<input type="text" name="label" class="quatrevingtpercent" value="'.$urlfile.'">';
  191. else print $urlfile;
  192. print '</td></tr>';
  193. /*print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
  194. if ($_GET["action"] == 'edit')
  195. {
  196. print '<textarea class="flat" name="description" cols="80">';
  197. print $ecmdir->description;
  198. print '</textarea>';
  199. }
  200. else print dol_nl2br($ecmdir->description);
  201. print '</td></tr>';
  202. print '<tr><td>'.$langs->trans("ECMCreationUser").'</td><td>';
  203. $userecm=new User($db);
  204. $userecm->fetch($ecmdir->fk_user_c);
  205. print $userecm->getNomUrl(1);
  206. print '</td></tr>';
  207. */
  208. print '<tr><td>'.$langs->trans("ECMCreationDate").'</td><td>';
  209. print dol_print_date(dol_filemtime($fullpath),'dayhour');
  210. print '</td></tr>';
  211. /*print '<tr><td>'.$langs->trans("ECMDirectoryForFiles").'</td><td>';
  212. print '/ecm/'.$relativepath;
  213. print '</td></tr>';
  214. print '<tr><td>'.$langs->trans("ECMNbOfDocs").'</td><td>';
  215. print count($filearray);
  216. print '</td></tr>';
  217. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>';
  218. print dol_print_size($totalsize);
  219. print '</td></tr>';
  220. */
  221. // Define $urlwithroot
  222. $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
  223. $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  224. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  225. print '<tr><td>'.$langs->trans("DirectDownloadLink").'</td><td>';
  226. $modulepart='ecm';
  227. $forcedownload=1;
  228. $rellink='/document.php?modulepart='.$modulepart;
  229. if ($forcedownload) $rellink.='&attachment=1';
  230. if (! empty($object->entity)) $rellink.='&entity='.$object->entity;
  231. $filepath=$relativepath.$file->label;
  232. $rellink.='&file='.urlencode($filepath);
  233. $fulllink=$urlwithroot.$rellink;
  234. print img_picto('','object_globe.png').' ';
  235. print '<input type="text" class="quatrevingtpercent" name="downloadlink" value="'.dol_escape_htmltag($fulllink).'">';
  236. print ' <a data-ajax="false" href="'.$fulllink.'">'.$langs->trans("Download").'</a>';
  237. print '</td></tr>';
  238. print '</table>';
  239. dol_fiche_end();
  240. if ($_GET["action"] == 'edit')
  241. {
  242. print '<div class="center">';
  243. print '<input type="submit" class="button" name="submit" value="'.$langs->trans("Save").'">';
  244. print ' &nbsp; &nbsp; ';
  245. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  246. print '</div>';
  247. print '</form>';
  248. }
  249. // Confirmation de la suppression d'une ligne categorie
  250. if ($_GET['action'] == 'delete_file')
  251. {
  252. print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.urlencode($_GET["section"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile',$urlfile), 'confirm_deletefile', '', 1, 1);
  253. }
  254. if ($_GET["action"] != 'edit')
  255. {
  256. // Actions buttons
  257. print '<div class="tabsAction">';
  258. if ($user->rights->ecm->setup)
  259. {
  260. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&section='.$section.'&urlfile='.urlencode($urlfile).'">'.$langs->trans('Edit').'</a>';
  261. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=cancel&section='.$section.'&urlfile='.urlencode($urlfile).'&backtourl='.urlencode($backtourl).'">'.$langs->trans('Cancel').'</a>';
  262. }
  263. /*
  264. if ($user->rights->ecm->setup)
  265. {
  266. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=delete_file&section='.$section.'&urlfile='.urlencode($urlfile).'">'.$langs->trans('Delete').'</a>';
  267. }
  268. else
  269. {
  270. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('Delete').'</a>';
  271. }
  272. */
  273. print '</div>';
  274. }
  275. // End of page
  276. llxFooter();
  277. $db->close();