docdir.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. /* Copyright (C) 2008-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2008-2012 Regis Houssin <regis.houssin@capnetworks.com>
  4. * Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/ecm/docdir.php
  21. * \ingroup ecm
  22. * \brief Main page for ECM section area
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/ecm/class/htmlecm.form.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.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. $action=GETPOST('action','alpha');
  42. $confirm=GETPOST('confirm','alpha');
  43. // Security check
  44. if ($user->societe_id > 0)
  45. {
  46. $action = '';
  47. $socid = $user->societe_id;
  48. }
  49. $section=$urlsection=GETPOST('section');
  50. if (empty($urlsection)) $urlsection='misc';
  51. $upload_dir = $conf->ecm->dir_output.'/'.$urlsection;
  52. $sortfield = GETPOST("sortfield",'alpha');
  53. $sortorder = GETPOST("sortorder",'alpha');
  54. $page = GETPOST("page",'int');
  55. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  56. $offset = $conf->liste_limit * $page;
  57. $pageprev = $page - 1;
  58. $pagenext = $page + 1;
  59. if (! $sortorder) $sortorder="ASC";
  60. if (! $sortfield) $sortfield="label";
  61. $ecmdir = new EcmDirectory($db);
  62. if (! empty($section))
  63. {
  64. $result=$ecmdir->fetch($section);
  65. if (! $result > 0)
  66. {
  67. dol_print_error($db,$ecmdir->error);
  68. exit;
  69. }
  70. }
  71. /*
  72. * Actions
  73. */
  74. // Action ajout d'un produit ou service
  75. if ($action == 'add' && $user->rights->ecm->setup)
  76. {
  77. if (! empty($_POST["cancel"]))
  78. {
  79. header("Location: ".DOL_URL_ROOT.'/ecm/index.php?action=file_manager');
  80. exit;
  81. }
  82. $ecmdir->ref = trim($_POST["ref"]);
  83. $ecmdir->label = trim($_POST["label"]);
  84. $ecmdir->description = trim($_POST["desc"]);
  85. $ecmdir->fk_parent = $_POST["catParent"];
  86. $ok=true;
  87. if (! $ecmdir->label)
  88. {
  89. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  90. $action = 'create';
  91. $ok=false;
  92. }
  93. if ($ok)
  94. {
  95. $id = $ecmdir->create($user);
  96. if ($id > 0)
  97. {
  98. header("Location: ".DOL_URL_ROOT.'/ecm/index.php?action=file_manager');
  99. exit;
  100. }
  101. else
  102. {
  103. $langs->load("errors");
  104. setEventMessages($langs->trans($ecmdir->error), $ecmdir->errors, 'errors');
  105. $action = 'create';
  106. }
  107. }
  108. }
  109. // Deleting file
  110. else if ($action == 'confirm_deletesection' && $confirm == 'yes')
  111. {
  112. $result=$ecmdir->delete($user);
  113. setEventMessages($langs->trans("ECMSectionWasRemoved", $ecmdir->label), null, 'mesgs');
  114. }
  115. /*
  116. * View
  117. */
  118. llxHeader();
  119. $form=new Form($db);
  120. $formecm=new FormEcm($db);
  121. if ($action == 'create')
  122. {
  123. //***********************
  124. // Create
  125. //***********************
  126. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  127. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  128. print '<input type="hidden" name="action" value="add">';
  129. $title=$langs->trans("ECMNewSection");
  130. print load_fiche_titre($title);
  131. dol_fiche_head();
  132. print '<table class="border" width="100%">';
  133. // Label
  134. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" size="40" maxlength="32" value="'.$ecmdir->label.'"></td></tr>'."\n";
  135. print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
  136. print $formecm->select_all_sections(! empty($_GET["catParent"])?$_GET["catParent"]:$ecmdir->fk_parent,'catParent');
  137. print '</td></tr>'."\n";
  138. // Description
  139. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
  140. print '<textarea name="desc" rows="4" cols="90">';
  141. print $ecmdir->description;
  142. print '</textarea>';
  143. print '</td></tr>'."\n";
  144. print '</table>';
  145. dol_fiche_end();
  146. print '<div class="center">';
  147. print '<input type="submit" class="button" name="create" value="'.$langs->trans("Create").'">';
  148. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  149. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  150. print '</div>';
  151. print '</form>';
  152. }
  153. if (empty($action) || $action == 'delete_section')
  154. {
  155. //***********************
  156. // List
  157. //***********************
  158. print load_fiche_titre($langs->trans("ECMSectionOfDocuments"));
  159. print '<br>';
  160. /*
  161. $ecmdir->ref=$ecmdir->label;
  162. print $langs->trans("ECMSection").': ';
  163. print img_picto('','object_dir').' ';
  164. print '<a href="'.DOL_URL_ROOT.'/ecm/docdir.php">'.$langs->trans("ECMRoot").'</a>';
  165. //print ' -> <b>'.$ecmdir->getNomUrl(1).'</b><br>';
  166. print "<br><br>";
  167. */
  168. // Confirmation de la suppression d'une ligne categorie
  169. if ($action == 'delete_section')
  170. {
  171. print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.$section, $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection');
  172. }
  173. // Construit fiche rubrique
  174. // Actions buttons
  175. print '<div class="tabsAction">';
  176. if ($user->rights->ecm->setup)
  177. {
  178. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=delete_section">'.$langs->trans('Delete').'</a>';
  179. }
  180. else
  181. {
  182. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('Delete').'</a>';
  183. }
  184. print '</div>';
  185. }
  186. // End of page
  187. llxFooter();
  188. $db->close();