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