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