dolibarr  13.0.2
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 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/ecm/class/htmlecm.form.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array("ecm", "companies", "other", "users", "orders", "propal", "bills", "contracts", "categories"));
33 
34 // Get parameters
35 $socid = GETPOST('socid', 'int');
36 $action = GETPOST('action', 'alpha');
37 $cancel = GETPOST('cancel', 'aZ09');
38 $backtopage = GETPOST('backtopage', 'alpha');
39 $confirm = GETPOST('confirm', 'alpha');
40 
41 $module = GETPOST('module', 'alpha');
42 $website = GETPOST('website', 'alpha');
43 $pageid = GETPOST('pageid', 'int');
44 if (empty($module)) {
45  $module = 'ecm';
46 }
47 
48 // Security check
49 if ($user->socid > 0) {
50  $action = '';
51  $socid = $user->socid;
52 }
53 
54 $section = $urlsection = GETPOST('section', 'alpha');
55 if (empty($urlsection)) {
56  $urlsection = 'misc';
57 }
58 
59 if ($module == 'ecm') {
60  $upload_dir = $conf->ecm->dir_output.'/'.$urlsection;
61 } else // For example $module == 'medias'
62 {
63  $upload_dir = $conf->medias->multidir_output[$conf->entity];
64 }
65 
66 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
67 $sortfield = GETPOST("sortfield", 'alpha');
68 $sortorder = GETPOST("sortorder", 'alpha');
69 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
70 if (empty($page) || $page == -1) {
71  $page = 0;
72 } // If $page is not defined, or '' or -1
73 $offset = $limit * $page;
74 $pageprev = $page - 1;
75 $pagenext = $page + 1;
76 if (!$sortorder) {
77  $sortorder = "ASC";
78 }
79 if (!$sortfield) {
80  $sortfield = "label";
81 }
82 
83 $ecmdir = new EcmDirectory($db);
84 if (!empty($section)) {
85  $result = $ecmdir->fetch($section);
86  if (!$result > 0) {
87  dol_print_error($db, $ecmdir->error);
88  exit;
89  }
90 }
91 
92 // Permissions
93 $permtoadd = 0;
94 $permtoupload = 0;
95 if ($module == 'ecm') {
96  $permtoadd = $user->rights->ecm->setup;
97  $permtoupload = $user->rights->ecm->upload;
98 }
99 if ($module == 'medias') {
100  $permtoadd = ($user->rights->mailing->creer || $user->rights->website->write);
101  $permtoupload = ($user->rights->mailing->creer || $user->rights->website->write);
102 }
103 
104 if (!$permtoadd) {
105  accessforbidden();
106 }
107 
108 
109 
110 /*
111  * Actions
112  */
113 
114 // Action ajout d'un produit ou service
115 if ($action == 'add' && $permtoadd) {
116  if ($cancel) {
117  if (!empty($backtopage)) {
118  header("Location: ".$backtopage);
119  exit;
120  } else {
121  header("Location: ".DOL_URL_ROOT.'/ecm/index.php?action=file_manager'.($module ? '&module='.$module : ''));
122  exit;
123  }
124  }
125 
126  $ref = (string) GETPOST("ref", 'alpha');
127  $label = (string) GETPOST("label", 'alpha');
128  $desc = (string) GETPOST("desc", 'alpha');
129  $catParent = GETPOST("catParent", 'alpha'); // Can be an int (with ECM) or a string (with generic filemanager)
130  if ($catParent == '-1') {
131  $catParent = 0;
132  }
133 
134  $error = 0;
135 
136  if (empty($label)) {
137  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
138  $action = 'create';
139  $error++;
140  }
141 
142  if (!$error) {
143  if ($module == 'ecm') {
144  $ecmdir->ref = $ref;
145  $ecmdir->label = $label;
146  $ecmdir->description = $desc;
147  $ecmdir->fk_parent = (int) $catParent;
148 
149  $id = $ecmdir->create($user);
150  if ($id <= 0) {
151  $error++;
152  $langs->load("errors");
153  setEventMessages($ecmdir->error, $ecmdir->errors, 'errors');
154  $action = 'create';
155  }
156  } else // For example $module == 'medias'
157  {
158  $dirfornewdir = '';
159  if ($module == 'medias') {
160  $dirfornewdir = $conf->medias->multidir_output[$conf->entity];
161  }
162  if (empty($dirfornewdir)) {
163  $error++;
164  dol_print_error('', 'Bad value for module. Not supported.');
165  }
166 
167  if (!$error) {
168  $fullpathofdir = $dirfornewdir.'/'.($catParent ? $catParent.'/' : '').$label;
169  $result = dol_mkdir($fullpathofdir, DOL_DATA_ROOT);
170  if ($result < 0) {
171  setEventMessages($langs->trans('ErrorFailToCreateDir', $label), null, 'errors');
172  $error++;
173  } else {
174  setEventMessages($langs->trans("ECMSectionWasCreated", $label), null, 'mesgs');
175  }
176  }
177  }
178  }
179 
180  if (!$error) {
181  if (!empty($backtopage)) {
182  header("Location: ".$backtopage);
183  exit;
184  } else {
185  header("Location: ".DOL_URL_ROOT.'/ecm/index.php?action=file_manager');
186  exit;
187  }
188  }
189 }
190 
191 // Deleting file
192 elseif ($action == 'confirm_deletesection' && $confirm == 'yes') {
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 
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 
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();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
Class to manage HTML component for ECM and generic filemanager.
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 ...
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59
Class to manage ECM directories.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)