PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/ecm/docdir.php

https://bitbucket.org/speedealing/speedealing
PHP | 230 lines | 136 code | 41 blank | 53 comment | 31 complexity | dcb52d8f38e9f6ab4883506b36194806 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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. *
  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. */
  18. /**
  19. * \file htdocs/ecm/docdir.php
  20. * \ingroup ecm
  21. * \brief Main page for ECM section area
  22. * \author Laurent Destailleur
  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 ($page == -1) { $page = 0; }
  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. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")), '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. setEventMessage($langs->trans($ecmdir->error), 'errors');
  105. $action = 'create';
  106. }
  107. }
  108. }
  109. // Suppression fichier
  110. else if ($action == 'confirm_deletesection' && $confirm == 'yes')
  111. {
  112. $result=$ecmdir->delete($user);
  113. setEventMessage($langs->trans("ECMSectionWasRemoved", $ecmdir->label));
  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_fiche_titre($title);
  131. print '<table class="border" width="100%">';
  132. // Label
  133. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" size="40" maxlength="32" value="'.$ecmdir->label.'"></td></tr>'."\n";
  134. print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
  135. print $formecm->select_all_sections(! empty($_GET["catParent"])?$_GET["catParent"]:$ecmdir->fk_parent,'catParent');
  136. print '</td></tr>'."\n";
  137. // Description
  138. print '<tr><td valign="top">'.$langs->trans("Description").'</td><td>';
  139. print '<textarea name="desc" rows="4" cols="90">';
  140. print $ecmdir->description;
  141. print '</textarea>';
  142. print '</td></tr>'."\n";
  143. print '</td></tr>'."\n";
  144. print '</table><br>';
  145. print '<center>';
  146. print '<input type="submit" class="button" name="create" value="'.$langs->trans("Create").'">';
  147. print ' &nbsp; &nbsp; ';
  148. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  149. print '</center>';
  150. print '</form>';
  151. }
  152. if (empty($action) || $action == 'delete_section')
  153. {
  154. //***********************
  155. // List
  156. //***********************
  157. print_fiche_titre($langs->trans("ECMSectionOfDocuments"));
  158. print '<br>';
  159. /*
  160. $ecmdir->ref=$ecmdir->label;
  161. print $langs->trans("ECMSection").': ';
  162. print img_picto('','object_dir').' ';
  163. print '<a href="'.DOL_URL_ROOT.'/ecm/docdir.php">'.$langs->trans("ECMRoot").'</a>';
  164. //print ' -> <b>'.$ecmdir->getNomUrl(1).'</b><br>';
  165. print "<br><br>";
  166. */
  167. // Confirmation de la suppression d'une ligne categorie
  168. if ($action == 'delete_section')
  169. {
  170. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.$section, $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection');
  171. if ($ret == 'html') print '<br>';
  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();
  189. ?>