PageRenderTime 39ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/ecm/docmine.php

https://github.com/asterix14/dolibarr
PHP | 381 lines | 264 code | 53 blank | 64 comment | 68 complexity | e4157ceea3dab9293497c25901b0f6da MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2008-2010 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/docmine.php
  19. * \ingroup ecm
  20. * \brief Card of a directory 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. // Load permissions
  33. $user->getrights('ecm');
  34. // Security check
  35. if ($user->societe_id > 0) $socid = $user->societe_id;
  36. // Get parameters
  37. $sortfield = GETPOST("sortfield",'alpha');
  38. $sortorder = GETPOST("sortorder",'alpha');
  39. $page = GETPOST("page",'int');
  40. if ($page == -1) { $page = 0; }
  41. $offset = $conf->liste_limit * $page;
  42. $pageprev = $page - 1;
  43. $pagenext = $page + 1;
  44. if (! $sortorder) $sortorder="ASC";
  45. if (! $sortfield) $sortfield="name";
  46. $section=GETPOST("section");
  47. if (! $section)
  48. {
  49. dol_print_error('',"ErrorSectionParamNotDefined");
  50. exit;
  51. }
  52. // Load ecm object
  53. $ecmdir = new ECMDirectory($db);
  54. $result=$ecmdir->fetch(GETPOST("section"));
  55. if (! $result > 0)
  56. {
  57. dol_print_error($db,$ecmdir->error);
  58. exit;
  59. }
  60. $relativepath=$ecmdir->getRelativePath();
  61. $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
  62. /*******************************************************************
  63. * ACTIONS
  64. *
  65. * Put here all code to do according to value of "action" parameter
  66. ********************************************************************/
  67. // Upload file
  68. if (GETPOST("sendit") && ! empty($conf->global->MAIN_UPLOAD_DOC))
  69. {
  70. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  71. if (create_exdir($upload_dir) >= 0)
  72. {
  73. $resupload = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
  74. if (is_numeric($resupload) && $resupload > 0)
  75. {
  76. $result=$ecmdir->changeNbOfFiles('+');
  77. }
  78. else
  79. {
  80. $langs->load("errors");
  81. if ($resupload < 0) // Unknown error
  82. {
  83. $mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
  84. }
  85. else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
  86. {
  87. $mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
  88. }
  89. else // Known error
  90. {
  91. $mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
  92. }
  93. }
  94. }
  95. else
  96. {
  97. // Echec transfert (fichier depassant la limite ?)
  98. $langs->load("errors");
  99. $mesg = '<div class="error">'.$langs->trans("ErrorFailToCreateDir",$upload_dir).'</div>';
  100. }
  101. }
  102. // Remove file
  103. if (GETPOST('action') == 'confirm_deletefile' && GETPOST('confirm') == 'yes')
  104. {
  105. $file = $upload_dir . "/" . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  106. $result=dol_delete_file($file);
  107. $mesg = '<div class="ok">'.$langs->trans("FileWasRemoved").'</div>';
  108. $result=$ecmdir->changeNbOfFiles('-');
  109. }
  110. // Remove dir
  111. if (GETPOST('action') == 'confirm_deletedir' && GETPOST('confirm') == 'yes')
  112. {
  113. // Fetch was already done
  114. $result=$ecmdir->delete($user);
  115. if ($result > 0)
  116. {
  117. header("Location: ".DOL_URL_ROOT."/ecm/index.php");
  118. exit;
  119. }
  120. else
  121. {
  122. $mesg = '<div class="error">'.$langs->trans($ecmdir->error,$ecmdir->label).'</div>';
  123. }
  124. }
  125. // Update description
  126. if (GETPOST('action') == 'update' && ! GETPOST('cancel'))
  127. {
  128. $error=0;
  129. $db->begin();
  130. $oldlabel=$ecmdir->label;
  131. $olddir=$ecmdir->getRelativePath(0);
  132. $olddir=$conf->ecm->dir_output.'/'.$olddir;
  133. // Fetch was already done
  134. $ecmdir->label = GETPOST("label");
  135. $ecmdir->description = GETPOST("description");
  136. $result=$ecmdir->update($user);
  137. if ($result > 0)
  138. {
  139. // Try to rename file if changed
  140. if ($oldlabel != $ecmdir->label
  141. && file_exists($olddir))
  142. {
  143. $newdir=$ecmdir->getRelativePath(1); // return "xxx/zzz/" from ecm directory
  144. $newdir=$conf->ecm->dir_output.'/'.$newdir;
  145. //print $olddir.'-'.$newdir;
  146. $result=@rename($olddir,$newdir);
  147. if (! $result)
  148. {
  149. $langs->load('errors');
  150. $mesg='<div class="error">'.$langs->trans('ErrorFailToRenameDir',$olddir,$newdir).'</div>';
  151. $error++;
  152. }
  153. }
  154. if (! $error)
  155. {
  156. $db->commit();
  157. $relativepath=$ecmdir->getRelativePath();
  158. $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
  159. }
  160. else
  161. {
  162. $db->rollback();
  163. }
  164. }
  165. else
  166. {
  167. $db->rollback();
  168. $mesg='<div class="error">'.$ecmdir->error.'</div>';
  169. }
  170. }
  171. /*******************************************************************
  172. * PAGE
  173. *
  174. * Put here all code to do according to value of "action" parameter
  175. ********************************************************************/
  176. llxHeader();
  177. $form=new Form($db);
  178. // Construit liste des fichiers
  179. $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  180. $totalsize=0;
  181. foreach($filearray as $key => $file)
  182. {
  183. $totalsize+=$file['size'];
  184. }
  185. $head = ecm_prepare_head($ecmdir);
  186. dol_fiche_head($head, 'card', $langs->trans("ECMSectionManual"), '', 'dir');
  187. if ($_GET["action"] == 'edit')
  188. {
  189. print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  190. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  191. print '<input type="hidden" name="section" value="'.$section.'">';
  192. print '<input type="hidden" name="action" value="update">';
  193. }
  194. print '<table class="border" width="100%">';
  195. print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td>';
  196. $s='';
  197. $tmpecmdir=new ECMDirectory($db); // Need to create a new one
  198. $tmpecmdir->fetch($ecmdir->id);
  199. $result = 1;
  200. $i=0;
  201. while ($tmpecmdir && $result > 0)
  202. {
  203. $tmpecmdir->ref=$tmpecmdir->label;
  204. if ($i == 0 && $_GET["action"] == 'edit')
  205. {
  206. $s='<input type="text" name="label" size="40" maxlength="32" value="'.$tmpecmdir->label.'">';
  207. }
  208. else $s=$tmpecmdir->getNomUrl(1).$s;
  209. if ($tmpecmdir->fk_parent)
  210. {
  211. $s=' -> '.$s;
  212. $result=$tmpecmdir->fetch($tmpecmdir->fk_parent);
  213. }
  214. else
  215. {
  216. $tmpecmdir=0;
  217. }
  218. $i++;
  219. }
  220. print img_picto('','object_dir').' <a href="'.DOL_URL_ROOT.'/ecm/index.php">'.$langs->trans("ECMRoot").'</a> -> ';
  221. print $s;
  222. print '</td></tr>';
  223. print '<tr><td valign="top">'.$langs->trans("Description").'</td><td>';
  224. if ($_GET["action"] == 'edit')
  225. {
  226. print '<textarea class="flat" name="description" cols="80">';
  227. print $ecmdir->description;
  228. print '</textarea>';
  229. }
  230. else print dol_nl2br($ecmdir->description);
  231. print '</td></tr>';
  232. print '<tr><td>'.$langs->trans("ECMCreationUser").'</td><td>';
  233. $userecm=new User($db);
  234. $userecm->fetch($ecmdir->fk_user_c);
  235. print $userecm->getNomUrl(1);
  236. print '</td></tr>';
  237. print '<tr><td>'.$langs->trans("ECMCreationDate").'</td><td>';
  238. print dol_print_date($ecmdir->date_c,'dayhour');
  239. print '</td></tr>';
  240. print '<tr><td>'.$langs->trans("ECMDirectoryForFiles").'</td><td>';
  241. print '/ecm/'.$relativepath;
  242. print '</td></tr>';
  243. print '<tr><td>'.$langs->trans("ECMNbOfDocs").'</td><td>';
  244. print count($filearray);
  245. print '</td></tr>';
  246. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>';
  247. print dol_print_size($totalsize);
  248. print '</td></tr>';
  249. if ($_GET["action"] == 'edit')
  250. {
  251. print '<tr><td colspan="2" align="center">';
  252. print '<input type="submit" class="button" name="submit" value="'.$langs->trans("Save").'">';
  253. print ' &nbsp; &nbsp; ';
  254. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  255. print '</td></tr>';
  256. }
  257. print '</table>';
  258. if ($_GET["action"] == 'edit')
  259. {
  260. print '</form>';
  261. }
  262. print '</div>';
  263. // Actions buttons
  264. if ($_GET["action"] != 'edit' && $_GET['action'] != 'delete')
  265. {
  266. print '<div class="tabsAction">';
  267. if ($user->rights->ecm->setup)
  268. {
  269. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&section='.$section.'">'.$langs->trans('Edit').'</a>';
  270. }
  271. if ($user->rights->ecm->setup)
  272. {
  273. print '<a class="butAction" href="'.DOL_URL_ROOT.'/ecm/docdir.php?action=create&catParent='.$section.'">'.$langs->trans('ECMAddSection').'</a>';
  274. }
  275. else
  276. {
  277. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('ECMAddSection').'</a>';
  278. }
  279. if (count($filearray) == 0)
  280. {
  281. if ($user->rights->ecm->setup)
  282. {
  283. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete_dir&section='.$section.'">'.$langs->trans('Delete').'</a>';
  284. }
  285. else
  286. {
  287. print '<a class="butActionDeleteRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('Delete').'</a>';
  288. }
  289. }
  290. else
  291. {
  292. print '<a class="butActionRefused" href="#" title="'.$langs->trans("CannotRemoveDirectoryContainsFiles").'">'.$langs->trans('Delete').'</a>';
  293. }
  294. print '</div>';
  295. }
  296. if ($mesg) { print '<br>'.$mesg.'<br>'; }
  297. // Confirm remove file
  298. if ($_GET['action'] == 'delete')
  299. {
  300. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.$_REQUEST["section"].'&amp;urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile');
  301. if ($ret == 'html') print '<br>';
  302. }
  303. // Confirm remove file
  304. if ($_GET['action'] == 'delete_dir')
  305. {
  306. $relativepathwithoutslash=preg_replace('/[\/]$/','',$relativepath);
  307. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.$_REQUEST["section"], $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$relativepathwithoutslash), 'confirm_deletedir', '', 1, 1);
  308. if ($ret == 'html') print '<br>';
  309. }
  310. $formfile=new FormFile($db);
  311. /*
  312. // Affiche formulaire upload
  313. if ($user->rights->ecm->upload)
  314. {
  315. $formfile->form_attach_new_file(DOL_URL_ROOT.'/ecm/docmine.php','',0,$section);
  316. }
  317. // List of document
  318. if ($user->rights->ecm->read)
  319. {
  320. $param='&amp;section='.$section;
  321. $formfile->list_of_documents($filearray,'','ecm',$param,1,$relativepath,$user->rights->ecm->upload);
  322. }
  323. */
  324. // End of page
  325. $db->close();
  326. llxFooter();
  327. ?>