dir_add_card.php 8.3 KB

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