dolibarr 25.0.0-alpha
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-2026 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2025-2026 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', 'aZ09arobase');
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 - add product or 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 if ($result > 0) {
210 setEventMessages($langs->trans("ECMSectionWasRemoved", $ecmdir->label), null, 'mesgs');
211 } else {
212 setEventMessages($ecmdir->error, $ecmdir->errors, 'errors');
213 }
214}
215
216
217
218
219/*
220 * View
221 */
222
223llxHeader('', $langs->trans("ECMNewSection"), '', '', 0, 0, '', '', '', 'mod-ecm page-dir_add_card');
224
225$form = new Form($db);
226$formecm = new FormEcm($db);
227
228if ($action == 'create') {
229 //***********************
230 // Create
231 //***********************
232 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
233 print '<input type="hidden" name="token" value="'.newToken().'">';
234 print '<input type="hidden" name="action" value="add">';
235 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
236 print '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($backtopage).'">';
237 if ($website) {
238 print '<input type="hidden" name="website" value="'.dol_escape_htmltag($website).'">';
239 }
240 if ($pageid) {
241 print '<input type="hidden" name="pageid" value="'.dol_escape_htmltag((string) $pageid).'">';
242 }
243
244 $title = $langs->trans("ECMNewSection");
245 print load_fiche_titre($title);
246
247 print dol_get_fiche_head();
248
249 print '<table class="border centpercent">';
250
251 // Label
252 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td>';
253 print '<input name="label" class="minwidth100" maxlength="32" value="'.GETPOST("label", 'alpha').'" autofocus></td></tr>'."\n";
254
255 print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
256 print $formecm->selectAllSections((GETPOST("catParent", 'alpha') ? GETPOST("catParent", 'alpha') : $ecmdir->fk_parent), 'catParent', $module);
257 print '</td></tr>'."\n";
258
259 // Description
260 if ($module == 'ecm') {
261 print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
262 print '<textarea name="desc" rows="4" class="quatrevingtpercent">';
263 print $ecmdir->description;
264 print '</textarea>';
265 print '</td></tr>'."\n";
266 }
267
268 print '</table>';
269
270 print dol_get_fiche_end();
271
272 print '<div class="center">';
273 print '<input type="submit" class="button" name="create" value="'.$langs->trans("Create").'">';
274 print ' &nbsp; &nbsp; ';
275 print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
276 print '</div>';
277 print '</form>';
278}
279
280
281if (empty($action) || $action == 'delete_section') {
282 //***********************
283 // List
284 //***********************
285 print load_fiche_titre($langs->trans("ECMSectionOfDocuments"));
286 print '<br>';
287
288 /*
289 $ecmdir->ref=$ecmdir->label;
290 print $langs->trans("ECMSection").': ';
291 print img_picto('','object_dir').' ';
292 print '<a href="'.DOL_URL_ROOT.'/ecm/dir_add_card.php">'.$langs->trans("ECMRoot").'</a>';
293 //print ' -> <b>'.$ecmdir->getNomUrl(1).'</b><br>';
294 print "<br><br>";
295 */
296
297 // Generate form to confirm deletion of a category line
298 if ($action == 'delete_section') {
299 print $form->formconfirm(dolBuildUrl($_SERVER["PHP_SELF"], array('section' => $section)), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection', $ecmdir->label), 'confirm_deletesection');
300 }
301
302
303 // Actions buttons
304 print '<div class="tabsAction">';
305
306 // Delete
307 print dolGetButtonAction($langs->trans('Delete'), $langs->trans('Delete'), 'delete', dolBuildUrl($_SERVER["PHP_SELF"], array('section' => $section, 'action' => 'delete_section'), true), '', $user->hasRight('ecm', 'setup'), array('attr' => array('class' => 'reposition')))."\n";
308
309 print '</div>';
310}
311
312
313// End of page
314llxFooter();
315$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
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.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
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.
Definition html.lib.php:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.