dolibarr  17.0.4
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2008-2016 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2008-2009 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.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 // Load Dolibarr environment
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/ftp.lib.php';
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array('companies', 'other'));
35 
36 // Security check
37 if ($user->socid) {
38  $socid = $user->socid;
39 }
40 $result = restrictedArea($user, 'ftp', '');
41 
42 // Get parameters
43 $action = GETPOST('action', 'aZ09');
44 $section = GETPOST('section');
45 $newfolder = GETPOST('newfolder');
46 if (!$section) {
47  $section = '/';
48 }
49 $numero_ftp = GETPOST("numero_ftp");
50 /* if (! $numero_ftp) $numero_ftp=1; */
51 $file = GETPOST("file");
52 $confirm = GETPOST('confirm');
53 
54 $upload_dir = $conf->ftp->dir_temp;
55 $download_dir = $conf->ftp->dir_temp;
56 
57 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
58 $sortfield = GETPOST('sortfield', 'aZ09comma');
59 $sortorder = GETPOST('sortorder', 'aZ09comma');
60 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
61 if (empty($page) || $page == -1) {
62  $page = 0;
63 } // If $page is not defined, or '' or -1
64 $offset = $limit * $page;
65 $pageprev = $page - 1;
66 $pagenext = $page + 1;
67 if (!$sortorder) {
68  $sortorder = "ASC";
69 }
70 if (!$sortfield) {
71  $sortfield = "label";
72 }
73 
74 $s_ftp_name = 'FTP_NAME_'.$numero_ftp;
75 $s_ftp_server = 'FTP_SERVER_'.$numero_ftp;
76 $s_ftp_port = 'FTP_PORT_'.$numero_ftp;
77 $s_ftp_user = 'FTP_USER_'.$numero_ftp;
78 $s_ftp_password = 'FTP_PASSWORD_'.$numero_ftp;
79 $s_ftp_passive = 'FTP_PASSIVE_'.$numero_ftp;
80 $ftp_name = getDolGlobalString($s_ftp_name);
81 $ftp_server = getDolGlobalString($s_ftp_server);
82 $ftp_port = getDolGlobalString($s_ftp_port);
83 if (empty($ftp_port)) {
84  $ftp_port = 21;
85 }
86 $ftp_user = getDolGlobalString($s_ftp_user);
87 $ftp_password = getDolGlobalString($s_ftp_password);
88 $ftp_passive = getDolGlobalString($s_ftp_passive);
89 
90 // For result on connection
91 $ok = 0;
92 $conn_id = null; // FTP connection ID
93 $mesg = '';
94 
95 
96 
97 /*
98  * ACTIONS
99  */
100 
101 if ($action == 'uploadfile') {
102  // set up a connection or die
103  if (!$conn_id) {
104  $newsectioniso = utf8_decode($section);
105  $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
106  $conn_id = $resultarray['conn_id'];
107  $ok = $resultarray['ok'];
108  $mesg = $resultarray['mesg'];
109  }
110  if ($conn_id && $ok && !$mesg) {
111  $nbfile = count($_FILES['userfile']['name']);
112  for ($i = 0; $i < $nbfile; $i++) {
113  $newsection = $newsectioniso;
114  $fileupload = $_FILES['userfile']['name'][$i];
115  $fileuploadpath = $_FILES['userfile']['tmp_name'][$i];
116  $result = dol_ftp_put($conn_id, $fileupload, $fileuploadpath, $newsection);
117 
118  if ($result) {
119  setEventMessages($langs->trans("FileWasUpload", $fileupload), null, 'mesgs');
120  } else {
121  dol_syslog("ftp/index.php ftp_delete", LOG_ERR);
122  setEventMessages($langs->trans("FTPFailedToUploadFile", $fileupload), null, 'errors');
123  }
124  }
125  $action = '';
126  } else {
127  dol_print_error('', $mesg);
128  }
129 }
130 
131 if ($action == 'addfolder') {
132  // set up a connection or die
133  if (!$conn_id) {
134  $newsectioniso = utf8_decode($section);
135  $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
136  $conn_id = $resultarray['conn_id'];
137  $ok = $resultarray['ok'];
138  $mesg = $resultarray['mesg'];
139  }
140  if ($conn_id && $ok && !$mesg) {
141  $result = dol_ftp_mkdir($conn_id, $newfolder, $newsectioniso);
142 
143  if ($result) {
144  setEventMessages($langs->trans("FileWasCreateFolder", $newfolder), null, 'mesgs');
145  } else {
146  dol_syslog("ftp/index.php ftp_delete", LOG_ERR);
147  setEventMessages($langs->trans("FTPFailedToCreateFolder", $newfolder), null, 'errors');
148  }
149  $action = '';
150  } else {
151  dol_print_error('', $mesg);
152  }
153 }
154 
155 // Action ajout d'un rep
156 if ($action == 'add' && $user->rights->ftp->setup) {
157  $ecmdir->ref = GETPOST("ref");
158  $ecmdir->label = GETPOST("label");
159  $ecmdir->description = GETPOST("desc");
160 
161  $id = $ecmdir->create($user);
162  if ($id > 0) {
163  header("Location: ".$_SERVER["PHP_SELF"]);
164  exit;
165  } else {
166  setEventMessages($langs->trans("ErrorFailToCreateDir"), null, 'errors');
167  $action = "create";
168  }
169 }
170 
171 // Remove 1 file
172 if ($action == 'confirm_deletefile' && GETPOST('confirm') == 'yes') {
173  // set up a connection or die
174  if (!$conn_id) {
175  $newsectioniso = utf8_decode($section);
176  $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
177  $conn_id = $resultarray['conn_id'];
178  $ok = $resultarray['ok'];
179  $mesg = $resultarray['mesg'];
180  }
181 
182  if ($conn_id && $ok && !$mesg) {
183  $newsection = $section;
184  $result = dol_ftp_delete($conn_id, $file, $newsection);
185 
186  if ($result) {
187  setEventMessages($langs->trans("FileWasRemoved", $file), null, 'mesgs');
188  } else {
189  dol_syslog("ftp/index.php ftp_delete", LOG_ERR);
190  setEventMessages($langs->trans("FTPFailedToRemoveFile", $file), null, 'errors');
191  }
192 
193  $action = '';
194  } else {
195  dol_print_error('', $mesg);
196  }
197 }
198 
199 // Delete several lines at once
200 if (GETPOST("const", 'array') && GETPOST("delete") && GETPOST("delete") == $langs->trans("Delete")) {
201  // set up a connection or die
202  if (!$conn_id) {
203  $newsectioniso = utf8_decode($section);
204  $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
205  $conn_id = $resultarray['conn_id'];
206  $ok = $resultarray['ok'];
207  $mesg = $resultarray['mesg'];
208  }
209 
210  if ($conn_id && $ok && !$mesg) {
211  foreach (GETPOST('const', 'array') as $const) {
212  if (isset($const["check"])) { // Is checkbox checked
213  $langs->load("other");
214 
215  // Remote file
216  $file = $const["file"];
217  $newsection = $const["section"];
218 
219  $result = dol_ftp_delete($conn_id, $file, $newsection);
220 
221  if ($result) {
222  setEventMessages($langs->trans("FileWasRemoved", $file), null, 'mesgs');
223  } else {
224  dol_syslog("ftp/index.php ftp_delete n files", LOG_ERR);
225  setEventMessages($langs->trans("FTPFailedToRemoveFile", $file), null, 'errors');
226  }
227 
228  //ftp_close($conn_id); Close later
229 
230  $action = '';
231  }
232  }
233  } else {
234  dol_print_error('', $mesg);
235  }
236 }
237 
238 // Remove directory
239 if ($action == 'confirm_deletesection' && $confirm == 'yes') {
240  // set up a connection or die
241  if (!$conn_id) {
242  $newsectioniso = utf8_decode($section);
243  $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
244  $conn_id = $resultarray['conn_id'];
245  $ok = $resultarray['ok'];
246  $mesg = $resultarray['mesg'];
247  }
248 
249  if ($conn_id && $ok && !$mesg) {
250  $newsection = $section;
251 
252  $result = dol_ftp_rmdir($conn_id, $file, $newsection);
253 
254  if ($result) {
255  setEventMessages($langs->trans("DirWasRemoved", $file), null, 'mesgs');
256  } else {
257  setEventMessages($langs->trans("FTPFailedToRemoveDir", $file), null, 'errors');
258  }
259 
260  //ftp_close($conn_id); Close later
261 
262  $action = '';
263  } else {
264  dol_print_error('', $mesg);
265  }
266 }
267 
268 // Download directory
269 if ($action == 'download') {
270  // set up a connection or die
271  if (!$conn_id) {
272  $newsectioniso = utf8_decode($section);
273  $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
274  $conn_id = $resultarray['conn_id'];
275  $ok = $resultarray['ok'];
276  $mesg = $resultarray['mesg'];
277  }
278 
279  if ($conn_id && $ok && !$mesg) {
280  // Local file
281  $localfile = tempnam($download_dir, 'dol_');
282 
283  $newsection = $section;
284 
285  $result = dol_ftp_get($connect_id, $localfile, $file, $newsection);
286 
287 
288  if ($result) {
289  if (!empty($conf->global->MAIN_UMASK)) {
290  @chmod($localfile, octdec($conf->global->MAIN_UMASK));
291  }
292 
293  // Define mime type
294  $type = 'application/octet-stream';
295  if (GETPOSTISSET("type")) {
296  $type = GETPOST("type");
297  } else {
298  $type = dol_mimetype($file);
299  }
300 
301  // Define attachment (attachment=true to force choice popup 'open'/'save as')
302  $attachment = true;
303 
304  //if ($encoding) header('Content-Encoding: '.$encoding);
305  if ($type) {
306  header('Content-Type: '.$type);
307  }
308  if ($attachment) {
309  header('Content-Disposition: attachment; filename="'.$filename.'"');
310  } else {
311  header('Content-Disposition: inline; filename="'.$filename.'"');
312  }
313 
314  // Ajout directives pour resoudre bug IE
315  header('Cache-Control: Public, must-revalidate');
316  header('Pragma: public');
317 
318  readfile($localfile);
319 
320  exit;
321  } else {
322  setEventMessages($langs->transnoentitiesnoconv('FailedToGetFile', $remotefile), null, 'errors');
323  }
324  } else {
325  dol_print_error('', $mesg);
326  }
327 
328  //ftp_close($conn_id); Close later
329 }
330 
331 
332 
333 
334 /*
335  * View
336  */
337 
338 llxHeader();
339 
340 // Add logic to shoow/hide buttons
341 if ($conf->use_javascript_ajax) {
342  ?>
343 <script type="text/javascript">
344 jQuery(document).ready(function() {
345  jQuery("#delconst").hide();
346 
347  jQuery(".checkboxfordelete").click(function() {
348  jQuery("#delconst").show();
349  });
350 
351  $("#checkall").click(function() {
352  $(".checkboxfordelete").prop('checked', true);
353  jQuery("#delconst").show();
354  });
355  $("#checknone").click(function() {
356  $(".checkboxfordelete").prop('checked', false);
357  jQuery("#delconst").hide();
358  });
359 
360 });
361 
362 </script>
363 
364  <?php
365 }
366 
367 $form = new Form($db);
368 $formfile = new FormFile($db);
369 $userstatic = new User($db);
370 
371 
372 // List
373 print load_fiche_titre($langs->trans("FTPArea"));
374 
375 print $langs->trans("FTPAreaDesc")."<br>";
376 
377 if (!function_exists('ftp_connect')) {
378  print $langs->trans("FTPFeatureNotSupportedByYourPHP");
379 } else {
380  if (!empty($ftp_server)) {
381  // Confirm remove file
382  if ($action == 'delete') {
383  print $form->formconfirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'&section='.urlencode(GETPOST('section')).'&file='.urlencode(GETPOST('file')), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile', GETPOST('file')), 'confirm_deletefile', '', '', 1);
384  }
385 
386  // Confirmation de la suppression d'une ligne categorie
387  if ($action == 'delete_section') {
388  print $form->formconfirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'&section='.urlencode(GETPOST('section')).'&file='.urlencode(GETPOST('file')), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection', GETPOST('file')), 'confirm_deletesection', '', '', 1);
389  }
390 
391  print $langs->trans("Server").': <b>'.$ftp_server.'</b><br>';
392  print $langs->trans("Port").': <b>'.$ftp_port.'</b> '.($ftp_passive ? "(Passive)" : "(Active)").'<br>';
393  print $langs->trans("User").': <b>'.$ftp_user.'</b><br>';
394  print $langs->trans("FTPs (FTP over SSH)").': <b>'.yn($conf->global->FTP_CONNECT_WITH_SSL).'</b><br>';
395  print $langs->trans("SFTP (FTP as a subsytem of SSH)").': <b>'.yn($conf->global->FTP_CONNECT_WITH_SFTP).'</b><br>';
396  print $langs->trans("Directory").': ';
397  $sectionarray = preg_split('|[\/]|', $section);
398  // For /
399  $newsection = '/';
400  print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection ? '&section='.urlencode($newsection) : '').'">';
401  print '/';
402  print '</a> ';
403  // For other directories
404  $i = 0;
405  foreach ($sectionarray as $val) {
406  if (empty($val)) {
407  continue; // Discard first and last entry that should be empty as section start/end with /
408  }
409  if ($i > 0) {
410  print ' / ';
411  $newsection .= '/';
412  }
413  $newsection .= $val;
414  print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection ? '&section='.urlencode($newsection) : '').'">';
415  print $val;
416  print '</a>';
417  $i++;
418  }
419  print '<br>';
420  print "<br>\n";
421 
422  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
423  print '<input type="hidden" name="numero_ftp" value="'.$numero_ftp.'">';
424  print '<input type="hidden" name="token" value="'.newToken().'">';
425 
426 
427  // Construit liste des repertoires
428  print '<table width="100%" class="noborder">'."\n";
429 
430  print '<tr class="liste_titre">'."\n";
431  print '<td class="liste_titre left">'.$langs->trans("Content").'</td>'."\n";
432  print '<td class="liste_titre center">'.$langs->trans("Size").'</td>'."\n";
433  print '<td class="liste_titre center">'.$langs->trans("Date").'</td>'."\n";
434  print '<td class="liste_titre center">'.$langs->trans("Owner").'</td>'."\n";
435  print '<td class="liste_titre center">'.$langs->trans("Group").'</td>'."\n";
436  print '<td class="liste_titre center">'.$langs->trans("Permissions").'</td>'."\n";
437  print '<td class="liste_titre nowrap right">';
438  if ($conf->use_javascript_ajax) {
439  print '<a href="#" id="checkall">'.$langs->trans("All").'</a> / <a href="#" id="checknone">'.$langs->trans("None").'</a> ';
440  }
441  print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($section ? '&section='.urlencode($section) : '').'">'.img_picto($langs->trans("Refresh"), 'refresh').'</a>&nbsp;';
442  print '</td>'."\n";
443  print '</tr>'."\n";
444 
445  // set up a connection or die
446  if (empty($conn_id)) {
447  $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive);
448 
449  $conn_id = $resultarray['conn_id'];
450  $ok = $resultarray['ok'];
451  $mesg = $resultarray['mesg'];
452  }
453 
454  if ($ok) {
455  //$type = ftp_systype($conn_id);
456 
457  $newsection = $section;
458  $newsectioniso = utf8_decode($section);
459  //$newsection='/home';
460 
461  // List content of directory ($newsection = '/', '/home', ...)
462  if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
463  if ($newsection == '/') {
464  //$newsection = '/./';
465  $newsection = ssh2_sftp_realpath($conn_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169
466  }
467 
468  //$newsection='/';
469  //$dirHandle = opendir("ssh2.sftp://$conn_id".$newsection);
470  //$dirHandle = opendir("ssh2.sftp://".intval($conn_id).ssh2_sftp_realpath($conn_id, ".").'/./');
471 
472  $contents = scandir('ssh2.sftp://'.intval($conn_id).$newsection);
473  $buff = array();
474  foreach ($contents as $i => $key) {
475  $buff[$i] = "---------- - root root 1234 Aug 01 2000 ".$key;
476  }
477 
478  //$i = 0;
479  //$handle = opendir('ssh2.sftp://'.intval($conn_id).$newsection);
480  //$buff=array();
481  //while (false !== ($file = readdir($handle))) {
482  // if (substr("$file", 0, 1) != "."){
483  // if (is_dir($file)) {
484  // $buff[$i]="d--------- - root root 1234 Aug 01 2000 ".$file;
485  // } else {
486  // $buff[$i]="---------- - root root 1234 Aug 01 2000 ".$file;
487  // }
488  // }
489  // $i++;
490  //}
491  } else {
492  $buff = ftp_rawlist($conn_id, $newsectioniso);
493  $contents = ftp_nlist($conn_id, $newsectioniso); // Sometimes rawlist fails but never nlist
494  }
495 
496  $nboflines = count($contents);
497  $rawlisthasfailed = false;
498  $i = 0;
499  $nbofentries = 0;
500  while ($i < $nboflines && $i < 1000) {
501  $vals = preg_split('@ +@', utf8_encode($buff[$i]), 9);
502  //$vals=preg_split('@ +@','drwxr-xr-x 2 root root 4096 Aug 30 2008 backup_apollon1',9);
503  $file = $vals[8];
504  if (empty($file)) {
505  $rawlisthasfailed = true;
506  $file = utf8_encode($contents[$i]);
507  }
508 
509  if ($file == '.' || ($file == '..' && $section == '/')) {
510  $i++;
511  continue;
512  }
513 
514  // Is it a directory ?
515  $is_directory = 0;
516  $is_link = 0;
517  if ($file == '..') {
518  $is_directory = 1;
519  } elseif (!$rawlisthasfailed) {
520  if (preg_match('/^d/', $vals[0])) {
521  $is_directory = 1;
522  }
523  if (preg_match('/^l/', $vals[0])) {
524  $is_link = 1;
525  }
526  } else {
527  // Remote file
528  $filename = $file;
529  //print "section=".$section.' file='.$file.'X';
530  //print preg_match('@[\/]$@','aaa/').'Y';
531  //print preg_match('@[\\\/]$@',"aaa\\").'Y';
532  $remotefile = $section.(preg_match('@[\\\/]$@', $section) ? '' : '/').preg_replace('@^[\\\/]@', '', $file);
533  //print 'A'.$remotefile.'A';
534  $newremotefileiso = utf8_decode($remotefile);
535  //print 'Z'.$newremotefileiso.'Z';
536  $is_directory = ftp_isdir($conn_id, $newremotefileiso);
537  }
538 
539 
540  print '<tr class="oddeven" height="18">';
541  // Name
542  print '<td>';
543  $newsection = $section.(preg_match('@[\\\/]$@', $section) ? '' : '/').$file;
544  $newsection = preg_replace('@[\\\/][^\\\/]+[\\\/]\.\.$@', '/', $newsection); // Change aaa/xxx/.. to new aaa
545  if ($is_directory) {
546  print '<a href="'.$_SERVER["PHP_SELF"].'?section='.urlencode($newsection).'&numero_ftp='.$numero_ftp.'">';
547  }
548  print dol_escape_htmltag($file);
549  if ($is_directory) {
550  print '</a>';
551  }
552  print '</td>';
553  // Size
554  print '<td class="center nowrap">';
555  if (!$is_directory && !$is_link) {
556  print $vals[4];
557  } else {
558  print '&nbsp;';
559  }
560  print '</td>';
561  // Date
562  print '<td class="center nowrap">';
563  print $vals[5].' '.$vals[6].' '.$vals[7];
564  print '</td>';
565  // User
566  print '<td class="center nowrap">';
567  print $vals[2];
568  print '</td>';
569  // Group
570  print '<td class="center nowrap">';
571  print $vals[3];
572  print '</td>';
573  // Permissions
574  print '<td class="center nowrap">';
575  print $vals[0];
576  print '</td>';
577  // Action
578  print '<td class="right nowrap" width="64">';
579  if ($is_directory) {
580  if ($file != '..') {
581  print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete_section&token='.newToken().'&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>';
582  } else {
583  print '&nbsp;';
584  }
585  } elseif ($is_link) {
586  $newfile = $file;
587  $newfile = preg_replace('/ ->.*/', '', $newfile);
588  print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($newfile).'">'.img_delete().'</a>';
589  } else {
590  print '<a href="'.$_SERVER["PHP_SELF"].'?action=download&token='.newToken().'&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_picto('', 'file').'</a>';
591  print ' &nbsp; ';
592  print '<input type="checkbox" class="flat checkboxfordelete" id="check_'.$i.'" name="const['.$i.'][check]" value="1">';
593  print ' &nbsp; ';
594  print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>';
595  print '<input type="hidden" name="const['.$i.'][section]" value="'.$section.'">';
596  print '<input type="hidden" name="const['.$i.'][file]" value="'.$file.'">';
597  }
598  print '</td>';
599  print '</tr>'."\n";
600  $i++;
601  $nbofentries++;
602  }
603  }
604 
605  print "</table>";
606 
607 
608  if (!$ok) {
609  print $mesg.'<br>'."\n";
610  setEventMessages($mesg, null, 'errors');
611  }
612 
613 
614  // Actions
615  /*
616  if ($user->rights->ftp->write && !empty($section))
617  {
618  $formfile->form_attach_new_file(DOL_URL_ROOT.'/ftp/index.php','',0,$section,1);
619  }
620  else print '&nbsp;';
621  */
622 
623  print '<br>';
624  print '<div id="delconst" class="right">';
625  print '<input type="submit" name="delete" class="button" value="'.$langs->trans("Delete").'">';
626  print '</div>';
627 
628  print "</form>";
629 
630  if ($user->hasRight('ftp', 'write')) {
631  print load_fiche_titre($langs->trans("AttachANewFile"), null, null);
632  print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post">';
633  print '<input type="hidden" name="token" value="'.newToken().'">';
634  print '<input type="hidden" name="numero_ftp" value="'.$numero_ftp.'">';
635  print '<input type="hidden" name="section" value="'.$section.'">';
636  print '<input type="hidden" name="action" value="uploadfile">';
637  print '<td><input type="file" class="flat" name="userfile[]" multiple></td>';
638  print '<td></td>';
639  print '<td align="center"><button type="submit" class="butAction" name="uploadfile" value="'.$langs->trans("Save").'">'.$langs->trans("Upload").'</button></td>';
640  print '</form>';
641 
642  print '<br><br>';
643 
644  print load_fiche_titre($langs->trans("AddFolder"), null, null);
645  print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post">';
646  print '<input type="hidden" name="token" value="'.newToken().'">';
647  print '<input type="hidden" name="numero_ftp" value="'.$numero_ftp.'">';
648  print '<input type="hidden" name="section" value="'.$section.'">';
649  print '<input type="hidden" name="action" value="addfolder">';
650  print '<td><input type="text" class="flat" name="newfolder" multiple></td>';
651  print '<td></td>';
652  print '<td align="center"><button type="submit" class="butAction" name="addfolder" value="'.$langs->trans("Save").'">'.$langs->trans("AddFolder").'</button></td>';
653  print '</form>';
654  }
655  } else {
656  $foundsetup = false;
657  $MAXFTP = 20;
658  $i = 1;
659  while ($i <= $MAXFTP) {
660  $paramkey = 'FTP_NAME_'.$i;
661  //print $paramkey;
662  if (!empty($conf->global->$paramkey)) {
663  $foundsetup = true;
664  break;
665  }
666  $i++;
667  }
668  if (!$foundsetup) {
669  print $langs->trans("SetupOfFTPClientModuleNotComplete");
670  } else {
671  print $langs->trans("ChooseAFTPEntryIntoMenu");
672  }
673  }
674 }
675 
676 print '<br>';
677 
678 if (!empty($conn_id)) {
679  $disconnect = dol_ftp_close($conn_id);
680 
681  if (!$disconnect) {
682  setEventMessages($langs->trans("ErrorFTPNodisconnect"), null, 'errors');
683  }
684 }
685 
686 // End of page
687 llxFooter();
688 $db->close();
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage Dolibarr users.
Definition: user.class.php:47
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_ftp_mkdir($connect_id, $newdir, $newsection)
Remove FTP directory.
Definition: ftp.lib.php:290
ftp_isdir($connect_id, $dir)
Tell if an entry is a FTP directory.
Definition: ftp.lib.php:128
dol_ftp_close($connect_id)
Tell if an entry is a FTP directory.
Definition: ftp.lib.php:145
dol_ftp_delete($connect_id, $file, $newsection)
Delete a FTP file.
Definition: ftp.lib.php:169
dol_ftp_rmdir($connect_id, $file, $newsection)
Remove FTP directory.
Definition: ftp.lib.php:260
dol_ftp_put($connect_id, $file, $localfile, $newsection)
Upload a FTP file.
Definition: ftp.lib.php:231
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive=0)
Connect to FTP server.
Definition: ftp.lib.php:40
dol_ftp_get($connect_id, $localfile, $file, $newsection)
Download a FTP file.
Definition: ftp.lib.php:201
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
llxFooter()
Footer empty.
Definition: index.php:71
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.