PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/ecm/docdir.php

https://github.com/asterix14/dolibarr
PHP | 233 lines | 132 code | 44 blank | 57 comment | 31 complexity | 235917adafee3231ea7241928a70524a MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2008-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2008 Regis Houssin <regis@dolibarr.fr>
  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 2 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. // Load permissions
  39. $user->getrights('ecm');
  40. if (!$user->rights->ecm->setup) accessforbidden();
  41. // Get parameters
  42. $socid = isset($_GET["socid"])?$_GET["socid"]:'';
  43. $section=$_GET["section"];
  44. if (! $section) $section='misc';
  45. $upload_dir = $conf->ecm->dir_output.'/'.$section;
  46. $sortfield = GETPOST("sortfield",'alpha');
  47. $sortorder = GETPOST("sortorder",'alpha');
  48. $page = GETPOST("page",'int');
  49. if ($page == -1) { $page = 0; }
  50. $offset = $conf->liste_limit * $page;
  51. $pageprev = $page - 1;
  52. $pagenext = $page + 1;
  53. if (! $sortorder) $sortorder="ASC";
  54. if (! $sortfield) $sortfield="label";
  55. $ecmdir = new ECMDirectory($db);
  56. if (! empty($_GET["section"]))
  57. {
  58. $result=$ecmdir->fetch($_GET["section"]);
  59. if (! $result > 0)
  60. {
  61. dol_print_error($db,$ecmdir->error);
  62. exit;
  63. }
  64. }
  65. /*******************************************************************
  66. * ACTIONS
  67. *
  68. * Put here all code to do according to value of "action" parameter
  69. ********************************************************************/
  70. // Action ajout d'un produit ou service
  71. if ($_POST["action"] == 'add' && $user->rights->ecm->setup)
  72. {
  73. if (! empty($_POST["cancel"]))
  74. {
  75. Header("Location: ".DOL_URL_ROOT.'/ecm/index.php?action=file_manager');
  76. exit;
  77. }
  78. $ecmdir->ref = trim($_POST["ref"]);
  79. $ecmdir->label = trim($_POST["label"]);
  80. $ecmdir->description = trim($_POST["desc"]);
  81. $ecmdir->fk_parent = $_POST["catParent"];
  82. $ok=true;
  83. if (! $ecmdir->label)
  84. {
  85. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'</div>';
  86. $_GET["action"] = "create";
  87. $ok=false;
  88. }
  89. if ($ok)
  90. {
  91. $id = $ecmdir->create($user);
  92. if ($id > 0)
  93. {
  94. Header("Location: ".DOL_URL_ROOT.'/ecm/index.php?action=file_manager');
  95. exit;
  96. }
  97. else
  98. {
  99. $langs->load("errors");
  100. $mesg='<div class="error">'.$langs->trans($ecmdir->error).'</div>';
  101. $_GET["action"] = "create";
  102. }
  103. }
  104. }
  105. // Suppression fichier
  106. if ($_POST['action'] == 'confirm_deletesection' && $_POST['confirm'] == 'yes')
  107. {
  108. $result=$ecmdir->delete($user);
  109. $mesg = '<div class="ok">'.$langs->trans("ECMSectionWasRemoved", $ecmdir->label).'</div>';
  110. }
  111. /*******************************************************************
  112. * PAGE
  113. *
  114. * Put here all code to do according to value of "action" parameter
  115. ********************************************************************/
  116. llxHeader();
  117. $form=new Form($db);
  118. $formecm=new FormEcm($db);
  119. if ($_GET["action"] == 'create')
  120. {
  121. //***********************
  122. // Create
  123. //***********************
  124. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  125. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  126. print '<input type="hidden" name="action" value="add">';
  127. $title=$langs->trans("ECMNewSection");
  128. print_fiche_titre($title);
  129. if ($mesg) { print $mesg."<br>"; }
  130. print '<table class="border" width="100%">';
  131. // Label
  132. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" size="40" maxlength="32" value="'.$ecmdir->label.'"></td></tr>'."\n";
  133. print '<tr><td>'.$langs->trans ("AddIn").'</td><td>';
  134. print $formecm->select_all_sections(! empty($_GET["catParent"])?$_GET["catParent"]:$ecmdir->fk_parent,'catParent');
  135. print '</td></tr>'."\n";
  136. // Description
  137. print '<tr><td valign="top">'.$langs->trans("Description").'</td><td>';
  138. print '<textarea name="desc" rows="4" cols="90">';
  139. print $ecmdir->description;
  140. print '</textarea>';
  141. print '</td></tr>'."\n";
  142. print '</td></tr>'."\n";
  143. print '</table><br>';
  144. print '<center>';
  145. print '<input type="submit" class="button" name="create" value="'.$langs->trans("Create").'">';
  146. print ' &nbsp; &nbsp; ';
  147. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  148. print '</center>';
  149. print '</form>';
  150. }
  151. if (! $_GET["action"] || $_GET["action"] == 'delete_section')
  152. {
  153. //***********************
  154. // List
  155. //***********************
  156. print_fiche_titre($langs->trans("ECMSectionOfDocuments"));
  157. print '<br>';
  158. /*
  159. $ecmdir->ref=$ecmdir->label;
  160. print $langs->trans("ECMSection").': ';
  161. print img_picto('','object_dir').' ';
  162. print '<a href="'.DOL_URL_ROOT.'/ecm/docdir.php">'.$langs->trans("ECMRoot").'</a>';
  163. //print ' -> <b>'.$ecmdir->getNomUrl(1).'</b><br>';
  164. print "<br><br>";
  165. */
  166. // Confirmation de la suppression d'une ligne categorie
  167. if ($_GET['action'] == 'delete_section')
  168. {
  169. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.$_GET["section"], $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection');
  170. if ($ret == 'html') print '<br>';
  171. }
  172. if ($mesg) { print $mesg."<br>"; }
  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. $db->close();
  188. llxFooter();
  189. ?>