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