PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/ecm/docfile.php

https://github.com/asterix14/dolibarr
PHP | 287 lines | 154 code | 43 blank | 90 comment | 35 complexity | 7367a06d013387f6e54054ab35bc9ae1 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2008 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 2 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. // Load permissions
  39. $user->getrights('ecm');
  40. if (!$user->rights->ecm->setup) accessforbidden();
  41. // Get parameters
  42. $socid = isset($_GET["socid"])?$_GET["socid"]:'';
  43. $sortfield = GETPOST("sortfield",'alpha');
  44. $sortorder = GETPOST("sortorder",'alpha');
  45. $page = GETPOST("page",'int');
  46. if ($page == -1) { $page = 0; }
  47. $offset = $conf->liste_limit * $page;
  48. $pageprev = $page - 1;
  49. $pagenext = $page + 1;
  50. if (! $sortorder) $sortorder="ASC";
  51. if (! $sortfield) $sortfield="label";
  52. $section=GETPOST("section");
  53. if (! $section)
  54. {
  55. dol_print_error('','Error, section parameter missing');
  56. exit;
  57. }
  58. $urlfile=GETPOST("urlfile");
  59. if (! $urlfile)
  60. {
  61. dol_print_error('',"ErrorParamNotDefined");
  62. exit;
  63. }
  64. // Load ecm object
  65. $ecmdir = new ECMDirectory($db);
  66. $result=$ecmdir->fetch(GETPOST("section"));
  67. if (! $result > 0)
  68. {
  69. dol_print_error($db,$ecmdir->error);
  70. exit;
  71. }
  72. $relativepath=$ecmdir->getRelativePath();
  73. $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
  74. /*
  75. $ecmfile = new ECMFile($db);
  76. if (! empty($_GET["fileid"]))
  77. {
  78. $result=$ecmfile->fetch($_GET["fileid"]);
  79. if (! $result > 0)
  80. {
  81. dol_print_error($db,$ecmfile->error);
  82. exit;
  83. }
  84. }
  85. */
  86. /*******************************************************************
  87. * ACTIONS
  88. *
  89. * Put here all code to do according to value of "action" parameter
  90. ********************************************************************/
  91. // Rename file
  92. if (GETPOST('action') == 'update' && ! GETPOST('cancel'))
  93. {
  94. $error=0;
  95. $oldlabel=GETPOST('urlfile');
  96. $newlabel=GETPOST('label');
  97. //$db->begin();
  98. $olddir=$ecmdir->getRelativePath(0);
  99. $olddir=$conf->ecm->dir_output.'/'.$olddir;
  100. $newdir=$olddir;
  101. $oldfile=$olddir.$oldlabel;
  102. $newfile=$newdir.$newlabel;
  103. //print $oldfile.' - '.$newfile;
  104. if ($newlabel != $oldlabel)
  105. {
  106. $result=dol_move($oldfile,$newfile);
  107. if (! $result)
  108. {
  109. $langs->load('errors');
  110. $mesg='<div class="error">'.$langs->trans('ErrorFailToRenameFile',$oldfile,$newfile).'</div>';
  111. $error++;
  112. }
  113. }
  114. if (! $error)
  115. {
  116. //$db->commit();
  117. $urlfile=$newlabel;
  118. }
  119. else
  120. {
  121. //$db->rollback();
  122. }
  123. }
  124. /*******************************************************************
  125. * PAGE
  126. *
  127. * Put here all code to do according to value of "action" parameter
  128. ********************************************************************/
  129. llxHeader();
  130. $form=new Form($db);
  131. $fullpath=$conf->ecm->dir_output.'/'.$ecmdir->label.'/'.$urlfile;
  132. $file->section_id=$ecmdir->id;
  133. $file->label=$urlfile;
  134. $head = ecm_file_prepare_head($file);
  135. dol_fiche_head($head, 'card', $langs->trans("File"), 0, 'generic');
  136. if ($_GET["action"] == 'edit')
  137. {
  138. print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  139. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  140. print '<input type="hidden" name="section" value="'.$section.'">';
  141. print '<input type="hidden" name="urlfile" value="'.$urlfile.'">';
  142. print '<input type="hidden" name="action" value="update">';
  143. }
  144. print '<table class="border" width="100%">';
  145. print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td>';
  146. $s='';
  147. $tmpecmdir=new ECMDirectory($db); // Need to create a new one
  148. $tmpecmdir->fetch($ecmdir->id);
  149. $result = 1;
  150. $i=0;
  151. while ($tmpecmdir && $result > 0)
  152. {
  153. $tmpecmdir->ref=$tmpecmdir->label;
  154. $s=$tmpecmdir->getNomUrl(1).$s;
  155. if ($tmpecmdir->fk_parent)
  156. {
  157. $s=' -> '.$s;
  158. $result=$tmpecmdir->fetch($tmpecmdir->fk_parent);
  159. }
  160. else
  161. {
  162. $tmpecmdir=0;
  163. }
  164. $i++;
  165. }
  166. print img_picto('','object_dir').' <a href="'.DOL_URL_ROOT.'/ecm/index.php">'.$langs->trans("ECMRoot").'</a> -> ';
  167. print $s;
  168. print ' -> ';
  169. if (GETPOST('action') == 'edit') print '<input type="text" name="label" size="64" value="'.$urlfile.'">';
  170. else print $urlfile;
  171. print '</td></tr>';
  172. /*print '<tr><td valign="top">'.$langs->trans("Description").'</td><td>';
  173. if ($_GET["action"] == 'edit')
  174. {
  175. print '<textarea class="flat" name="description" cols="80">';
  176. print $ecmdir->description;
  177. print '</textarea>';
  178. }
  179. else print dol_nl2br($ecmdir->description);
  180. print '</td></tr>';
  181. print '<tr><td>'.$langs->trans("ECMCreationUser").'</td><td>';
  182. $userecm=new User($db);
  183. $userecm->fetch($ecmdir->fk_user_c);
  184. print $userecm->getNomUrl(1);
  185. print '</td></tr>';
  186. */
  187. print '<tr><td>'.$langs->trans("ECMCreationDate").'</td><td>';
  188. print dol_print_date(dol_filemtime($fullpath),'dayhour');
  189. print '</td></tr>';
  190. /*print '<tr><td>'.$langs->trans("ECMDirectoryForFiles").'</td><td>';
  191. print '/ecm/'.$relativepath;
  192. print '</td></tr>';
  193. print '<tr><td>'.$langs->trans("ECMNbOfDocs").'</td><td>';
  194. print count($filearray);
  195. print '</td></tr>';
  196. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>';
  197. print dol_print_size($totalsize);
  198. print '</td></tr>';
  199. */
  200. if ($_GET["action"] == 'edit')
  201. {
  202. print '<tr><td colspan="2" align="center">';
  203. print '<input type="submit" class="button" name="submit" value="'.$langs->trans("Save").'">';
  204. print ' &nbsp; &nbsp; ';
  205. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  206. print '</td></tr>';
  207. }
  208. print '</table>';
  209. if ($_GET["action"] == 'edit')
  210. {
  211. print '</form>';
  212. }
  213. print '</div>';
  214. // Confirmation de la suppression d'une ligne categorie
  215. if ($_GET['action'] == 'delete_file')
  216. {
  217. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.urlencode($_GET["section"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile',$urlfile), 'confirm_deletefile', '', 1, 1);
  218. if ($ret == 'html') print '<br>';
  219. }
  220. if ($_GET["action"] != 'edit')
  221. {
  222. if ($mesg) { print $mesg."<br>"; }
  223. // Actions buttons
  224. print '<div class="tabsAction">';
  225. if ($user->rights->ecm->setup)
  226. {
  227. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&section='.$section.'&urlfile='.urlencode($urlfile).'">'.$langs->trans('Edit').'</a>';
  228. }
  229. /*
  230. if ($user->rights->ecm->setup)
  231. {
  232. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=delete_file&section='.$section.'&urlfile='.urlencode($urlfile).'">'.$langs->trans('Delete').'</a>';
  233. }
  234. else
  235. {
  236. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('Delete').'</a>';
  237. }
  238. */
  239. print '</div>';
  240. }
  241. // End of page
  242. $db->close();
  243. llxFooter();
  244. ?>