dir_add_card.php 8.8 KB

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