dir_add_card.php 8.8 KB

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