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