dolibarr  7.0.0-beta
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@capnetworks.com>
4  * Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.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 <http://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 traductions files
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)) $module='ecm';
45 
46 // Security check
47 if ($user->societe_id > 0)
48 {
49  $action = '';
50  $socid = $user->societe_id;
51 }
52 
53 $section=$urlsection=GETPOST('section','alpha');
54 if (empty($urlsection)) $urlsection='misc';
55 
56 if ($module == 'ecm')
57 {
58  $upload_dir = $conf->ecm->dir_output.'/'.$urlsection;
59 }
60 else // For example $module == 'medias'
61 {
62  $upload_dir = $conf->medias->multidir_output[$conf->entity];
63 }
64 
65 $sortfield = GETPOST("sortfield",'alpha');
66 $sortorder = GETPOST("sortorder",'alpha');
67 $page = GETPOST("page",'int');
68 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
69 $offset = $conf->liste_limit * $page;
70 $pageprev = $page - 1;
71 $pagenext = $page + 1;
72 if (! $sortorder) $sortorder="ASC";
73 if (! $sortfield) $sortfield="label";
74 
75 $ecmdir = new EcmDirectory($db);
76 if (! empty($section))
77 {
78  $result=$ecmdir->fetch($section);
79  if (! $result > 0)
80  {
81  dol_print_error($db,$ecmdir->error);
82  exit;
83  }
84 }
85 
86 // Permissions
87 $permtoadd = 0;
88 $permtoupload = 0;
89 if ($module == 'ecm')
90 {
91  $permtoadd = $user->rights->ecm->setup;
92  $permtoupload = $user->rights->ecm->upload;
93 }
94 if ($module == 'medias')
95 {
96  $permtoadd = ($user->rights->mailing->creer || $user->rights->website->write);
97  $permtoupload = ($user->rights->mailing->creer || $user->rights->website->write);
98 }
99 
100 if (! $permtoadd) accessforbidden();
101 
102 
103 
104 /*
105  * Actions
106  */
107 
108 // Action ajout d'un produit ou service
109 if ($action == 'add' && $permtoadd)
110 {
111  if ($cancel)
112  {
113  if (! empty($backtopage))
114  {
115  header("Location: ".$backtopage);
116  exit;
117  }
118  else
119  {
120  header("Location: ".DOL_URL_ROOT.'/ecm/index.php?action=file_manager'.($module?'&module='.$module:''));
121  exit;
122  }
123  }
124 
125  $ref = trim(GETPOST("ref", 'alpha'));
126  $label = trim(GETPOST("label", 'alpha'));
127  $desc = trim(GETPOST("desc", 'alpha'));
128  $catParent = GETPOST("catParent", 'alpha'); // Can be an int (with ECM) or a string (with generic filemanager)
129  if ($catParent == '-1') $catParent=0;
130 
131  $error=0;
132 
133  if (empty($label))
134  {
135  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
136  $action = 'create';
137  $error++;
138  }
139 
140  if (! $error)
141  {
142  if ($module == 'ecm')
143  {
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  {
152  $error++;
153  $langs->load("errors");
154  setEventMessages($ecmdir->error, $ecmdir->errors, 'errors');
155  $action = 'create';
156  }
157  }
158  else // For example $module == 'medias'
159  {
160  $dirfornewdir = '';
161  if ($module == 'medias')
162  {
163  $dirfornewdir = $conf->medias->multidir_output[$conf->entity];
164  }
165  if (empty($dirfornewdir))
166  {
167  $error++;
168  dol_print_error('', 'Bad value for module. Not supported.');
169  }
170 
171  if (! $error)
172  {
173  $fullpathofdir = $dirfornewdir.'/'.($catParent? $catParent.'/' : '').$label;
174  $result = dol_mkdir($fullpathofdir, DOL_DATA_ROOT);
175  if ($result < 0)
176  {
177  setEventMessages($langs->trans('ErrorFailToCreateDir', $label), null, 'errors');
178  $error++;
179  }
180  else
181  {
182  setEventMessages($langs->trans("ECMSectionWasCreated", $label), null, 'mesgs');
183  }
184  }
185  }
186  }
187 
188  if (! $error)
189  {
190  if (! empty($backtopage))
191  {
192  header("Location: ".$backtopage);
193  exit;
194  }
195  else
196  {
197  header("Location: ".DOL_URL_ROOT.'/ecm/index.php?action=file_manager');
198  exit;
199  }
200  }
201 }
202 
203 // Deleting file
204 else if ($action == 'confirm_deletesection' && $confirm == 'yes')
205 {
206  $result=$ecmdir->delete($user);
207  setEventMessages($langs->trans("ECMSectionWasRemoved", $ecmdir->label), null, 'mesgs');
208 }
209 
210 
211 
212 
213 /*
214  * View
215  */
216 
217 llxHeader('', $langs->trans("ECMNewSection"));
218 
219 $form=new Form($db);
220 $formecm=new FormEcm($db);
221 
222 if ($action == 'create')
223 {
224  //***********************
225  // Create
226  //***********************
227  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
228  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
229  print '<input type="hidden" name="action" value="add">';
230  print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
231  print '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($backtopage).'">';
232  if ($website) print '<input type="hidden" name="website" value="'.dol_escape_htmltag($website).'">';
233  if ($pageid) print '<input type="hidden" name="pageid" value="'.dol_escape_htmltag($pageid).'">';
234 
235  $title=$langs->trans("ECMNewSection");
237 
238  dol_fiche_head();
239 
240  print '<table class="border" width="100%">';
241 
242  // Label
243  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" class="minwidth100" maxlength="32" value="'.$ecmdir->label.'"></td></tr>'."\n";
244 
245  print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
246  print $formecm->selectAllSections((GETPOST("catParent",'alpha') ? GETPOST("catParent",'alpha') : $ecmdir->fk_parent), 'catParent', $module);
247  print '</td></tr>'."\n";
248 
249  // Description
250  if ($module == 'ecm')
251  {
252  print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
253  print '<textarea name="desc" rows="4" class="quatrevingtpercent">';
254  print $ecmdir->description;
255  print '</textarea>';
256  print '</td></tr>'."\n";
257  }
258 
259  print '</table>';
260 
261  dol_fiche_end();
262 
263  print '<div class="center">';
264  print '<input type="submit" class="button" name="create" value="'.$langs->trans("Create").'">';
265  print ' &nbsp; &nbsp; ';
266  print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
267  print '</div>';
268  print '</form>';
269 }
270 
271 
272 if (empty($action) || $action == 'delete_section')
273 {
274  //***********************
275  // List
276  //***********************
277  print load_fiche_titre($langs->trans("ECMSectionOfDocuments"));
278  print '<br>';
279 
280 /*
281  $ecmdir->ref=$ecmdir->label;
282  print $langs->trans("ECMSection").': ';
283  print img_picto('','object_dir').' ';
284  print '<a href="'.DOL_URL_ROOT.'/ecm/dir_add_card.php">'.$langs->trans("ECMRoot").'</a>';
285  //print ' -> <b>'.$ecmdir->getNomUrl(1).'</b><br>';
286  print "<br><br>";
287 */
288 
289  // Confirmation de la suppression d'une ligne categorie
290  if ($action == 'delete_section')
291  {
292  print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.$section, $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection');
293 
294  }
295 
296  // Construit fiche rubrique
297 
298 
299  // Actions buttons
300  print '<div class="tabsAction">';
301  if ($user->rights->ecm->setup)
302  {
303  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=delete_section">'.$langs->trans('Delete').'</a>';
304  }
305  else
306  {
307  print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('Delete').'</a>';
308  }
309  print '</div>';
310 }
311 
312 
313 // End of page
314 llxFooter();
315 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
Class to manage HTML component for ECM and generic filemanager.
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
dol_fiche_end($notab=0)
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
print
Draft customers invoices.
Definition: index.php:91
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
Class to manage ECM directories.