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