dir_add_card.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. /* Copyright (C) 2008-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2008-2012 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
  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 <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/ecm/dir_add_card.php
  21. * \ingroup ecm
  22. * \brief Main page for ECM section area
  23. */
  24. if (! defined('DISABLE_JS_GRAHP')) define('DISABLE_JS_GRAPH', 1);
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/ecm/class/htmlecm.form.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
  29. // Load translation files required by the page
  30. $langs->loadLangs(array("ecm", "companies", "other", "users", "orders", "propal", "bills", "contracts", "categories"));
  31. // Get parameters
  32. $socid = GETPOST('socid', 'int');
  33. $action = GETPOST('action', 'alpha');
  34. $cancel = GETPOST('cancel', 'aZ09');
  35. $backtopage = GETPOST('backtopage', 'alpha');
  36. $confirm = GETPOST('confirm', 'alpha');
  37. $module = GETPOST('module', 'alpha');
  38. $website = GETPOST('website', 'alpha');
  39. $pageid = GETPOST('pageid', 'int');
  40. if (empty($module)) {
  41. $module = 'ecm';
  42. }
  43. // Security check
  44. if ($user->socid > 0) {
  45. $action = '';
  46. $socid = $user->socid;
  47. }
  48. $section = $urlsection = GETPOST('section', 'alpha');
  49. if (empty($urlsection)) {
  50. $urlsection = 'misc';
  51. }
  52. if ($module == 'ecm') {
  53. $upload_dir = $conf->ecm->dir_output.'/'.$urlsection;
  54. } else // For example $module == 'medias'
  55. {
  56. $upload_dir = $conf->medias->multidir_output[$conf->entity];
  57. }
  58. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  59. $sortfield = GETPOST('sortfield', 'aZ09comma');
  60. $sortorder = GETPOST('sortorder', 'aZ09comma');
  61. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  62. if (empty($page) || $page == -1) {
  63. $page = 0;
  64. } // If $page is not defined, or '' or -1
  65. $offset = $limit * $page;
  66. $pageprev = $page - 1;
  67. $pagenext = $page + 1;
  68. if (!$sortorder) {
  69. $sortorder = "ASC";
  70. }
  71. if (!$sortfield) {
  72. $sortfield = "label";
  73. }
  74. $ecmdir = new EcmDirectory($db);
  75. if (!empty($section)) {
  76. $result = $ecmdir->fetch($section);
  77. if (!$result > 0) {
  78. dol_print_error($db, $ecmdir->error);
  79. exit;
  80. }
  81. }
  82. // Permissions
  83. $permtoadd = 0;
  84. $permtoupload = 0;
  85. if ($module == 'ecm') {
  86. $permtoadd = $user->rights->ecm->setup;
  87. $permtoupload = $user->rights->ecm->upload;
  88. }
  89. if ($module == 'medias') {
  90. $permtoadd = ($user->rights->mailing->creer || $user->rights->website->write);
  91. $permtoupload = ($user->rights->mailing->creer || $user->rights->website->write);
  92. }
  93. if (!$permtoadd) {
  94. accessforbidden();
  95. }
  96. /*
  97. * Actions
  98. */
  99. // Action ajout d'un produit ou service
  100. if ($action == 'add' && $permtoadd) {
  101. if ($cancel) {
  102. if (!empty($backtopage)) {
  103. header("Location: ".$backtopage);
  104. exit;
  105. } else {
  106. header("Location: ".DOL_URL_ROOT.'/ecm/index.php?action=file_manager'.($module ? '&module='.$module : ''));
  107. exit;
  108. }
  109. }
  110. $ref = (string) GETPOST("ref", 'alpha');
  111. $label = dol_sanitizeFileName(GETPOST("label", 'alpha'));
  112. $desc = (string) GETPOST("desc", 'alpha');
  113. $catParent = GETPOST("catParent", 'alpha'); // Can be an int (with ECM) or a string (with generic filemanager)
  114. if ($catParent == '-1') {
  115. $catParent = 0;
  116. }
  117. $error = 0;
  118. if (empty($label)) {
  119. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  120. $action = 'create';
  121. $error++;
  122. }
  123. if (!$error) {
  124. if ($module == 'ecm') {
  125. $ecmdir->ref = $ref;
  126. $ecmdir->label = $label;
  127. $ecmdir->description = $desc;
  128. $ecmdir->fk_parent = (int) $catParent;
  129. $id = $ecmdir->create($user);
  130. if ($id <= 0) {
  131. $error++;
  132. $langs->load("errors");
  133. setEventMessages($ecmdir->error, $ecmdir->errors, 'errors');
  134. $action = 'create';
  135. }
  136. } else { // For example $module == 'medias'
  137. $dirfornewdir = '';
  138. if ($module == 'medias') {
  139. $dirfornewdir = $conf->medias->multidir_output[$conf->entity];
  140. }
  141. if (empty($dirfornewdir)) {
  142. $error++;
  143. dol_print_error('', 'Bad value for module. Not supported.');
  144. }
  145. if (!$error) {
  146. $fullpathofdir = $dirfornewdir.'/'.($catParent ? $catParent.'/' : '').$label;
  147. $result = dol_mkdir($fullpathofdir, DOL_DATA_ROOT);
  148. if ($result < 0) {
  149. $langs->load("errors");
  150. setEventMessages($langs->trans('ErrorFailToCreateDir', $label), null, 'errors');
  151. $error++;
  152. } else {
  153. setEventMessages($langs->trans("ECMSectionWasCreated", $label), null, 'mesgs');
  154. }
  155. }
  156. }
  157. }
  158. if (!$error) {
  159. if (!empty($backtopage)) {
  160. header("Location: ".$backtopage);
  161. exit;
  162. } else {
  163. header("Location: ".DOL_URL_ROOT.'/ecm/index.php?action=file_manager');
  164. exit;
  165. }
  166. }
  167. } elseif ($action == 'confirm_deletesection' && $confirm == 'yes' && $permtoadd) {
  168. // Deleting file
  169. $result = $ecmdir->delete($user);
  170. setEventMessages($langs->trans("ECMSectionWasRemoved", $ecmdir->label), null, 'mesgs');
  171. }
  172. /*
  173. * View
  174. */
  175. llxHeader('', $langs->trans("ECMNewSection"));
  176. $form = new Form($db);
  177. $formecm = new FormEcm($db);
  178. if ($action == 'create') {
  179. //***********************
  180. // Create
  181. //***********************
  182. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  183. print '<input type="hidden" name="token" value="'.newToken().'">';
  184. print '<input type="hidden" name="action" value="add">';
  185. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  186. print '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($backtopage).'">';
  187. if ($website) {
  188. print '<input type="hidden" name="website" value="'.dol_escape_htmltag($website).'">';
  189. }
  190. if ($pageid) {
  191. print '<input type="hidden" name="pageid" value="'.dol_escape_htmltag($pageid).'">';
  192. }
  193. $title = $langs->trans("ECMNewSection");
  194. print load_fiche_titre($title);
  195. print dol_get_fiche_head();
  196. print '<table class="border centpercent">';
  197. // Label
  198. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" class="minwidth100" maxlength="32" value="'.$ecmdir->label.'" autofocus></td></tr>'."\n";
  199. print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
  200. print $formecm->selectAllSections((GETPOST("catParent", 'alpha') ? GETPOST("catParent", 'alpha') : $ecmdir->fk_parent), 'catParent', $module);
  201. print '</td></tr>'."\n";
  202. // Description
  203. if ($module == 'ecm') {
  204. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
  205. print '<textarea name="desc" rows="4" class="quatrevingtpercent">';
  206. print $ecmdir->description;
  207. print '</textarea>';
  208. print '</td></tr>'."\n";
  209. }
  210. print '</table>';
  211. print dol_get_fiche_end();
  212. print '<div class="center">';
  213. print '<input type="submit" class="button" name="create" value="'.$langs->trans("Create").'">';
  214. print ' &nbsp; &nbsp; ';
  215. print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  216. print '</div>';
  217. print '</form>';
  218. }
  219. if (empty($action) || $action == 'delete_section') {
  220. //***********************
  221. // List
  222. //***********************
  223. print load_fiche_titre($langs->trans("ECMSectionOfDocuments"));
  224. print '<br>';
  225. /*
  226. $ecmdir->ref=$ecmdir->label;
  227. print $langs->trans("ECMSection").': ';
  228. print img_picto('','object_dir').' ';
  229. print '<a href="'.DOL_URL_ROOT.'/ecm/dir_add_card.php">'.$langs->trans("ECMRoot").'</a>';
  230. //print ' -> <b>'.$ecmdir->getNomUrl(1).'</b><br>';
  231. print "<br><br>";
  232. */
  233. // Confirmation de la suppression d'une ligne categorie
  234. if ($action == 'delete_section') {
  235. print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.$section, $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection', $ecmdir->label), 'confirm_deletesection');
  236. }
  237. // Actions buttons
  238. print '<div class="tabsAction">';
  239. if ($user->rights->ecm->setup) {
  240. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=delete_section&token='.newToken().'">'.$langs->trans('Delete').'</a>';
  241. } else {
  242. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('Delete').'</a>';
  243. }
  244. print '</div>';
  245. }
  246. // End of page
  247. llxFooter();
  248. $db->close();