dolibarr 23.0.3
dir_add_card.php
Go to the documentation of this file.
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-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
5 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28if (! defined('DISABLE_JS_GRAHP')) {
29 define('DISABLE_JS_GRAPH', 1);
30}
31
32// Load Dolibarr environment
33require '../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
35require_once DOL_DOCUMENT_ROOT.'/ecm/class/htmlecm.form.class.php';
36require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
37
46// Load translation files required by the page
47$langs->loadLangs(array("ecm", "companies", "other", "users", "orders", "propal", "bills", "contracts", "categories"));
48
49// Get parameters
50$socid = GETPOSTINT('socid');
51$action = GETPOST('action', 'alpha');
52$cancel = GETPOST('cancel');
53$backtopage = GETPOST('backtopage', 'alpha');
54$confirm = GETPOST('confirm', 'alpha');
55
56$module = GETPOST('module', 'alpha');
57$website = GETPOST('website', 'alpha');
58$pageid = GETPOSTINT('pageid');
59if (empty($module)) {
60 $module = 'ecm';
61}
62
63// Security check
64if ($user->socid > 0) {
65 $action = '';
66 $socid = $user->socid;
67}
68
69$section = $urlsection = GETPOST('section', 'alpha');
70if (empty($urlsection)) {
71 $urlsection = 'misc';
72}
73
74if ($module == 'ecm') {
75 $upload_dir = $conf->ecm->dir_output.'/'.$urlsection;
76} else { // For example $module == 'medias'
77 $upload_dir = $conf->medias->multidir_output[$conf->entity];
78}
79
80$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
81$sortfield = GETPOST('sortfield', 'aZ09comma');
82$sortorder = GETPOST('sortorder', 'aZ09comma');
83$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
84if (empty($page) || $page == -1) {
85 $page = 0;
86} // If $page is not defined, or '' or -1
87$offset = $limit * $page;
88$pageprev = $page - 1;
89$pagenext = $page + 1;
90if (!$sortorder) {
91 $sortorder = "ASC";
92}
93if (!$sortfield) {
94 $sortfield = "label";
95}
96
97$ecmdir = new EcmDirectory($db);
98if (!empty($section)) {
99 $result = $ecmdir->fetch((int) $section);
100 if (!($result > 0)) {
101 dol_print_error($db, $ecmdir->error);
102 exit;
103 }
104}
105
106// Permissions
107$permissiontoadd = 0;
108$permissiontodelete = 0;
109$permissiontoupload = 0;
110if ($module == 'ecm') {
111 $permissiontoadd = $user->hasRight('ecm', 'setup');
112 $permissiontodelete = $user->hasRight('ecm', 'setup');
113 $permissiontoupload = $user->hasRight('ecm', 'upload');
114}
115if ($module == 'medias') {
116 $permissiontoadd = ($user->hasRight('mailing', 'creer') || $user->hasRight('website', 'write'));
117 $permissiontodelete = ($user->hasRight('mailing', 'creer') || $user->hasRight('website', 'write'));
118 $permissiontoupload = ($user->hasRight('mailing', 'creer') || $user->hasRight('website', 'write'));
119}
120
121if (!$permissiontoadd) {
123}
124
125
126
127/*
128 * Actions
129 */
130
131// Action ajout d'un produit ou service
132if ($action == 'add' && $permissiontoadd) {
133 if ($cancel) {
134 if (!empty($backtopage)) {
135 header("Location: ".$backtopage);
136 exit;
137 } else {
138 header("Location: ".DOL_URL_ROOT.'/ecm/index.php?action=file_manager&module='.$module);
139 exit;
140 }
141 }
142
143 $ref = (string) GETPOST("ref", 'alpha');
144 $label = dol_sanitizeFileName(GETPOST("label", 'alpha'));
145 $desc = (string) GETPOST("desc", 'alpha');
146 $catParent = GETPOST("catParent", 'alpha'); // Can be an int (with ECM) or a string (with generic filemanager)
147 if ($catParent == '-1') {
148 $catParent = 0;
149 }
150
151 $error = 0;
152
153 if (empty($label)) {
154 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
155 $action = 'create';
156 $error++;
157 }
158
159 if (!$error) {
160 if ($module == 'ecm') {
161 $ecmdir->ref = $ref;
162 $ecmdir->label = $label;
163 $ecmdir->description = $desc;
164 $ecmdir->fk_parent = (int) $catParent;
165
166 $id = $ecmdir->create($user);
167 if ($id <= 0) {
168 $error++;
169 $langs->load("errors");
170 setEventMessages($ecmdir->error, $ecmdir->errors, 'errors');
171 $action = 'create';
172 }
173 } else { // For example $module == 'medias'
174 $dirfornewdir = '';
175 if ($module == 'medias') {
176 $dirfornewdir = $conf->medias->multidir_output[$conf->entity];
177 }
178 if (empty($dirfornewdir)) {
179 $error++;
180 dol_print_error(null, 'Bad value for module. Not supported.');
181 }
182
183 if (!$error) {
184 $fullpathofdir = $dirfornewdir.'/'.($catParent ? $catParent.'/' : '').$label;
185 $result = dol_mkdir($fullpathofdir, DOL_DATA_ROOT);
186 if ($result < 0) {
187 $langs->load("errors");
188 setEventMessages($langs->trans('ErrorFailToCreateDir', $label), null, 'errors');
189 $error++;
190 } else {
191 setEventMessages($langs->trans("ECMSectionWasCreated", $label), null, 'mesgs');
192 }
193 }
194 }
195 }
196
197 if (!$error) {
198 if (!empty($backtopage)) {
199 header("Location: ".$backtopage);
200 exit;
201 } else {
202 header("Location: ".DOL_URL_ROOT.'/ecm/index.php?action=file_manager');
203 exit;
204 }
205 }
206} elseif ($action == 'confirm_deletesection' && $confirm == 'yes' && $permissiontodelete) {
207 // Deleting file
208 $result = $ecmdir->delete($user);
209 setEventMessages($langs->trans("ECMSectionWasRemoved", $ecmdir->label), null, 'mesgs');
210}
211
212
213
214
215/*
216 * View
217 */
218
219llxHeader('', $langs->trans("ECMNewSection"), '', '', 0, 0, '', '', '', 'mod-ecm page-dir_add_card');
220
221$form = new Form($db);
222$formecm = new FormEcm($db);
223
224if ($action == 'create') {
225 //***********************
226 // Create
227 //***********************
228 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
229 print '<input type="hidden" name="token" value="'.newToken().'">';
230 print '<input type="hidden" name="action" value="add">';
231 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
232 print '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($backtopage).'">';
233 if ($website) {
234 print '<input type="hidden" name="website" value="'.dol_escape_htmltag($website).'">';
235 }
236 if ($pageid) {
237 print '<input type="hidden" name="pageid" value="'.dol_escape_htmltag((string) $pageid).'">';
238 }
239
240 $title = $langs->trans("ECMNewSection");
241 print load_fiche_titre($title);
242
243 print dol_get_fiche_head();
244
245 print '<table class="border centpercent">';
246
247 // Label
248 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td>';
249 print '<input name="label" class="minwidth100" maxlength="32" value="'.GETPOST("label", 'alpha').'" autofocus></td></tr>'."\n";
250
251 print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
252 print $formecm->selectAllSections((GETPOST("catParent", 'alpha') ? GETPOST("catParent", 'alpha') : $ecmdir->fk_parent), 'catParent', $module);
253 print '</td></tr>'."\n";
254
255 // Description
256 if ($module == 'ecm') {
257 print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
258 print '<textarea name="desc" rows="4" class="quatrevingtpercent">';
259 print $ecmdir->description;
260 print '</textarea>';
261 print '</td></tr>'."\n";
262 }
263
264 print '</table>';
265
266 print dol_get_fiche_end();
267
268 print '<div class="center">';
269 print '<input type="submit" class="button" name="create" value="'.$langs->trans("Create").'">';
270 print ' &nbsp; &nbsp; ';
271 print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
272 print '</div>';
273 print '</form>';
274}
275
276
277if (empty($action) || $action == 'delete_section') {
278 //***********************
279 // List
280 //***********************
281 print load_fiche_titre($langs->trans("ECMSectionOfDocuments"));
282 print '<br>';
283
284 /*
285 $ecmdir->ref=$ecmdir->label;
286 print $langs->trans("ECMSection").': ';
287 print img_picto('','object_dir').' ';
288 print '<a href="'.DOL_URL_ROOT.'/ecm/dir_add_card.php">'.$langs->trans("ECMRoot").'</a>';
289 //print ' -> <b>'.$ecmdir->getNomUrl(1).'</b><br>';
290 print "<br><br>";
291 */
292
293 // Confirmation de la suppression d'une ligne categorie
294 if ($action == 'delete_section') {
295 print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.$section, $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection', $ecmdir->label), 'confirm_deletesection');
296 }
297
298
299 // Actions buttons
300 print '<div class="tabsAction">';
301
302 // Delete
303 print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), '', $user->hasRight('ecm', 'setup'));
304
305 print '</div>';
306}
307
308
309// End of page
310llxFooter();
311$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage ECM directories.
Class to manage HTML component for ECM and generic filemanager.
Class to manage generation of HTML components Only common components must be here.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.