index.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  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. /**
  20. * \file htdocs/ftp/index.php
  21. * \ingroup ftp
  22. * \brief Main page for FTP section area
  23. */
  24. // Load Dolibarr environment
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/ftp.lib.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array('companies', 'other'));
  32. // Security check
  33. if ($user->socid) {
  34. $socid = $user->socid;
  35. }
  36. $result = restrictedArea($user, 'ftp', '');
  37. // Get parameters
  38. $action = GETPOST('action', 'aZ09');
  39. $section = GETPOST('section');
  40. $newfolder = GETPOST('newfolder');
  41. if (!$section) {
  42. $section = '/';
  43. }
  44. $numero_ftp = GETPOST("numero_ftp");
  45. /* if (! $numero_ftp) $numero_ftp=1; */
  46. $file = GETPOST("file");
  47. $confirm = GETPOST('confirm');
  48. $upload_dir = $conf->ftp->dir_temp;
  49. $download_dir = $conf->ftp->dir_temp;
  50. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  51. $sortfield = GETPOST('sortfield', 'aZ09comma');
  52. $sortorder = GETPOST('sortorder', 'aZ09comma');
  53. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  54. if (empty($page) || $page == -1) {
  55. $page = 0;
  56. } // If $page is not defined, or '' or -1
  57. $offset = $limit * $page;
  58. $pageprev = $page - 1;
  59. $pagenext = $page + 1;
  60. if (!$sortorder) {
  61. $sortorder = "ASC";
  62. }
  63. if (!$sortfield) {
  64. $sortfield = "label";
  65. }
  66. $s_ftp_name = 'FTP_NAME_'.$numero_ftp;
  67. $s_ftp_server = 'FTP_SERVER_'.$numero_ftp;
  68. $s_ftp_port = 'FTP_PORT_'.$numero_ftp;
  69. $s_ftp_user = 'FTP_USER_'.$numero_ftp;
  70. $s_ftp_password = 'FTP_PASSWORD_'.$numero_ftp;
  71. $s_ftp_passive = 'FTP_PASSIVE_'.$numero_ftp;
  72. $ftp_name = getDolGlobalString($s_ftp_name);
  73. $ftp_server = getDolGlobalString($s_ftp_server);
  74. $ftp_port = getDolGlobalString($s_ftp_port);
  75. if (empty($ftp_port)) {
  76. $ftp_port = 21;
  77. }
  78. $ftp_user = getDolGlobalString($s_ftp_user);
  79. $ftp_password = getDolGlobalString($s_ftp_password);
  80. $ftp_passive = getDolGlobalString($s_ftp_passive);
  81. // For result on connection
  82. $ok = 0;
  83. $conn_id = null; // FTP connection ID
  84. $mesg = '';
  85. /*
  86. * ACTIONS
  87. */
  88. if ($action == 'uploadfile') {
  89. // set up a connection or die
  90. if (!$conn_id) {
  91. $newsectioniso = utf8_decode($section);
  92. $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
  93. $conn_id = $resultarray['conn_id'];
  94. $ok = $resultarray['ok'];
  95. $mesg = $resultarray['mesg'];
  96. }
  97. if ($conn_id && $ok && !$mesg) {
  98. $nbfile = count($_FILES['userfile']['name']);
  99. for ($i = 0; $i < $nbfile; $i++) {
  100. $newsection = $newsectioniso;
  101. $fileupload = $_FILES['userfile']['name'][$i];
  102. $fileuploadpath = $_FILES['userfile']['tmp_name'][$i];
  103. $result = dol_ftp_put($conn_id, $fileupload, $fileuploadpath, $newsection);
  104. if ($result) {
  105. setEventMessages($langs->trans("FileWasUpload", $fileupload), null, 'mesgs');
  106. } else {
  107. dol_syslog("ftp/index.php ftp_delete", LOG_ERR);
  108. setEventMessages($langs->trans("FTPFailedToUploadFile", $fileupload), null, 'errors');
  109. }
  110. }
  111. $action = '';
  112. } else {
  113. dol_print_error('', $mesg);
  114. }
  115. }
  116. if ($action == 'addfolder') {
  117. // set up a connection or die
  118. if (!$conn_id) {
  119. $newsectioniso = utf8_decode($section);
  120. $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
  121. $conn_id = $resultarray['conn_id'];
  122. $ok = $resultarray['ok'];
  123. $mesg = $resultarray['mesg'];
  124. }
  125. if ($conn_id && $ok && !$mesg) {
  126. $result = dol_ftp_mkdir($conn_id, $newfolder, $newsectioniso);
  127. if ($result) {
  128. setEventMessages($langs->trans("FileWasCreateFolder", $newfolder), null, 'mesgs');
  129. } else {
  130. dol_syslog("ftp/index.php ftp_delete", LOG_ERR);
  131. setEventMessages($langs->trans("FTPFailedToCreateFolder", $newfolder), null, 'errors');
  132. }
  133. $action = '';
  134. } else {
  135. dol_print_error('', $mesg);
  136. }
  137. }
  138. // Action ajout d'un rep
  139. if ($action == 'add' && $user->rights->ftp->setup) {
  140. $ecmdir = new EcmDirectory($db);
  141. $ecmdir->ref = GETPOST("ref");
  142. $ecmdir->label = GETPOST("label");
  143. $ecmdir->description = GETPOST("desc");
  144. $id = $ecmdir->create($user);
  145. if ($id > 0) {
  146. header("Location: ".$_SERVER["PHP_SELF"]);
  147. exit;
  148. } else {
  149. setEventMessages($langs->trans("ErrorFailToCreateDir"), null, 'errors');
  150. $action = "create";
  151. }
  152. }
  153. // Remove 1 file
  154. if ($action == 'confirm_deletefile' && GETPOST('confirm') == 'yes') {
  155. // set up a connection or die
  156. if (!$conn_id) {
  157. $newsectioniso = utf8_decode($section);
  158. $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
  159. $conn_id = $resultarray['conn_id'];
  160. $ok = $resultarray['ok'];
  161. $mesg = $resultarray['mesg'];
  162. }
  163. if ($conn_id && $ok && !$mesg) {
  164. $newsection = $section;
  165. $result = dol_ftp_delete($conn_id, $file, $newsection);
  166. if ($result) {
  167. setEventMessages($langs->trans("FileWasRemoved", $file), null, 'mesgs');
  168. } else {
  169. dol_syslog("ftp/index.php ftp_delete", LOG_ERR);
  170. setEventMessages($langs->trans("FTPFailedToRemoveFile", $file), null, 'errors');
  171. }
  172. $action = '';
  173. } else {
  174. dol_print_error('', $mesg);
  175. }
  176. }
  177. // Delete several lines at once
  178. if (GETPOST("const", 'array') && GETPOST("delete") && GETPOST("delete") == $langs->trans("Delete")) {
  179. // set up a connection or die
  180. if (!$conn_id) {
  181. $newsectioniso = utf8_decode($section);
  182. $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
  183. $conn_id = $resultarray['conn_id'];
  184. $ok = $resultarray['ok'];
  185. $mesg = $resultarray['mesg'];
  186. }
  187. if ($conn_id && $ok && !$mesg) {
  188. foreach (GETPOST('const', 'array') as $const) {
  189. if (isset($const["check"])) { // Is checkbox checked
  190. $langs->load("other");
  191. // Remote file
  192. $file = $const["file"];
  193. $newsection = $const["section"];
  194. $result = dol_ftp_delete($conn_id, $file, $newsection);
  195. if ($result) {
  196. setEventMessages($langs->trans("FileWasRemoved", $file), null, 'mesgs');
  197. } else {
  198. dol_syslog("ftp/index.php ftp_delete n files", LOG_ERR);
  199. setEventMessages($langs->trans("FTPFailedToRemoveFile", $file), null, 'errors');
  200. }
  201. //ftp_close($conn_id); Close later
  202. $action = '';
  203. }
  204. }
  205. } else {
  206. dol_print_error('', $mesg);
  207. }
  208. }
  209. // Remove directory
  210. if ($action == 'confirm_deletesection' && $confirm == 'yes') {
  211. // set up a connection or die
  212. if (!$conn_id) {
  213. $newsectioniso = utf8_decode($section);
  214. $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
  215. $conn_id = $resultarray['conn_id'];
  216. $ok = $resultarray['ok'];
  217. $mesg = $resultarray['mesg'];
  218. }
  219. if ($conn_id && $ok && !$mesg) {
  220. $newsection = $section;
  221. $result = dol_ftp_rmdir($conn_id, $file, $newsection);
  222. if ($result) {
  223. setEventMessages($langs->trans("DirWasRemoved", $file), null, 'mesgs');
  224. } else {
  225. setEventMessages($langs->trans("FTPFailedToRemoveDir", $file), null, 'errors');
  226. }
  227. //ftp_close($conn_id); Close later
  228. $action = '';
  229. } else {
  230. dol_print_error('', $mesg);
  231. }
  232. }
  233. // Download directory
  234. if ($action == 'download') {
  235. // set up a connection or die
  236. if (!$conn_id) {
  237. $newsectioniso = utf8_decode($section);
  238. $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
  239. $conn_id = $resultarray['conn_id'];
  240. $ok = $resultarray['ok'];
  241. $mesg = $resultarray['mesg'];
  242. }
  243. if ($conn_id && $ok && !$mesg) {
  244. // Local file
  245. $localfile = tempnam($download_dir, 'dol_');
  246. $newsection = $section;
  247. $result = dol_ftp_get($conn_id, $localfile, $file, $newsection);
  248. if ($result) {
  249. dolChmod($localfile);
  250. // Define mime type
  251. $type = 'application/octet-stream';
  252. if (GETPOSTISSET("type")) {
  253. $type = GETPOST("type");
  254. } else {
  255. $type = dol_mimetype($file);
  256. }
  257. // Define attachment (attachment=true to force choice popup 'open'/'save as')
  258. $attachment = true;
  259. //if ($encoding) header('Content-Encoding: '.$encoding);
  260. if ($type) {
  261. header('Content-Type: '.$type);
  262. }
  263. if ($attachment) {
  264. header('Content-Disposition: attachment; filename="'.$file.'"');
  265. } else {
  266. header('Content-Disposition: inline; filename="'.$file.'"');
  267. }
  268. // Ajout directives pour resoudre bug IE
  269. header('Cache-Control: Public, must-revalidate');
  270. header('Pragma: public');
  271. readfile($localfile);
  272. exit;
  273. } else {
  274. setEventMessages($langs->transnoentitiesnoconv('FailedToGetFile', $file), null, 'errors');
  275. }
  276. } else {
  277. dol_print_error('', $mesg);
  278. }
  279. //ftp_close($conn_id); Close later
  280. }
  281. /*
  282. * View
  283. */
  284. llxHeader();
  285. // Add logic to shoow/hide buttons
  286. if ($conf->use_javascript_ajax) {
  287. ?>
  288. <script type="text/javascript">
  289. jQuery(document).ready(function() {
  290. jQuery("#delconst").hide();
  291. jQuery(".checkboxfordelete").click(function() {
  292. jQuery("#delconst").show();
  293. });
  294. $("#checkall").click(function() {
  295. $(".checkboxfordelete").prop('checked', true);
  296. jQuery("#delconst").show();
  297. });
  298. $("#checknone").click(function() {
  299. $(".checkboxfordelete").prop('checked', false);
  300. jQuery("#delconst").hide();
  301. });
  302. });
  303. </script>
  304. <?php
  305. }
  306. $form = new Form($db);
  307. $formfile = new FormFile($db);
  308. $userstatic = new User($db);
  309. // List
  310. print load_fiche_titre($langs->trans("FTPArea"));
  311. print $langs->trans("FTPAreaDesc")."<br>";
  312. if (!function_exists('ftp_connect')) {
  313. print $langs->trans("FTPFeatureNotSupportedByYourPHP");
  314. } else {
  315. if (!empty($ftp_server)) {
  316. // Confirm remove file
  317. if ($action == 'delete') {
  318. 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);
  319. }
  320. // Confirmation de la suppression d'une ligne categorie
  321. if ($action == 'delete_section') {
  322. 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);
  323. }
  324. print $langs->trans("Server").': <b>'.$ftp_server.'</b><br>';
  325. print $langs->trans("Port").': <b>'.$ftp_port.'</b> '.($ftp_passive ? "(Passive)" : "(Active)").'<br>';
  326. print $langs->trans("User").': <b>'.$ftp_user.'</b><br>';
  327. print $langs->trans("FTPs (FTP over SSH)").': <b>'.yn($conf->global->FTP_CONNECT_WITH_SSL).'</b><br>';
  328. print $langs->trans("SFTP (FTP as a subsytem of SSH)").': <b>'.yn($conf->global->FTP_CONNECT_WITH_SFTP).'</b><br>';
  329. print $langs->trans("Directory").': ';
  330. $sectionarray = preg_split('|[\/]|', $section);
  331. // For /
  332. $newsection = '/';
  333. print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection ? '&section='.urlencode($newsection) : '').'">';
  334. print '/';
  335. print '</a> ';
  336. // For other directories
  337. $i = 0;
  338. foreach ($sectionarray as $val) {
  339. if (empty($val)) {
  340. continue; // Discard first and last entry that should be empty as section start/end with /
  341. }
  342. if ($i > 0) {
  343. print ' / ';
  344. $newsection .= '/';
  345. }
  346. $newsection .= $val;
  347. print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection ? '&section='.urlencode($newsection) : '').'">';
  348. print $val;
  349. print '</a>';
  350. $i++;
  351. }
  352. print '<br>';
  353. print "<br>\n";
  354. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  355. print '<input type="hidden" name="numero_ftp" value="'.$numero_ftp.'">';
  356. print '<input type="hidden" name="token" value="'.newToken().'">';
  357. // Construit liste des repertoires
  358. print '<table width="100%" class="noborder">'."\n";
  359. print '<tr class="liste_titre">'."\n";
  360. print '<td class="liste_titre left">'.$langs->trans("Content").'</td>'."\n";
  361. print '<td class="liste_titre center">'.$langs->trans("Size").'</td>'."\n";
  362. print '<td class="liste_titre center">'.$langs->trans("Date").'</td>'."\n";
  363. print '<td class="liste_titre center">'.$langs->trans("Owner").'</td>'."\n";
  364. print '<td class="liste_titre center">'.$langs->trans("Group").'</td>'."\n";
  365. print '<td class="liste_titre center">'.$langs->trans("Permissions").'</td>'."\n";
  366. print '<td class="liste_titre nowrap right">';
  367. if ($conf->use_javascript_ajax) {
  368. print '<a href="#" id="checkall">'.$langs->trans("All").'</a> / <a href="#" id="checknone">'.$langs->trans("None").'</a> ';
  369. }
  370. print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($section ? '&section='.urlencode($section) : '').'">'.img_picto($langs->trans("Refresh"), 'refresh').'</a>&nbsp;';
  371. print '</td>'."\n";
  372. print '</tr>'."\n";
  373. // set up a connection or die
  374. if (empty($conn_id)) {
  375. $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive);
  376. $conn_id = $resultarray['conn_id'];
  377. $ok = $resultarray['ok'];
  378. $mesg = $resultarray['mesg'];
  379. }
  380. if ($ok) {
  381. //$type = ftp_systype($conn_id);
  382. $newsection = $section;
  383. $newsectioniso = utf8_decode($section);
  384. //$newsection='/home';
  385. // List content of directory ($newsection = '/', '/home', ...)
  386. if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
  387. if ($newsection == '/') {
  388. //$newsection = '/./';
  389. $newsection = ssh2_sftp_realpath($conn_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169
  390. }
  391. //$newsection='/';
  392. //$dirHandle = opendir("ssh2.sftp://$conn_id".$newsection);
  393. //$dirHandle = opendir("ssh2.sftp://".intval($conn_id).ssh2_sftp_realpath($conn_id, ".").'/./');
  394. $contents = scandir('ssh2.sftp://'.intval($conn_id).$newsection);
  395. $buff = array();
  396. foreach ($contents as $i => $key) {
  397. $buff[$i] = "---------- - root root 1234 Aug 01 2000 ".$key;
  398. }
  399. //$i = 0;
  400. //$handle = opendir('ssh2.sftp://'.intval($conn_id).$newsection);
  401. //$buff=array();
  402. //while (false !== ($file = readdir($handle))) {
  403. // if (substr("$file", 0, 1) != "."){
  404. // if (is_dir($file)) {
  405. // $buff[$i]="d--------- - root root 1234 Aug 01 2000 ".$file;
  406. // } else {
  407. // $buff[$i]="---------- - root root 1234 Aug 01 2000 ".$file;
  408. // }
  409. // }
  410. // $i++;
  411. //}
  412. } else {
  413. $buff = ftp_rawlist($conn_id, $newsectioniso);
  414. $contents = ftp_nlist($conn_id, $newsectioniso); // Sometimes rawlist fails but never nlist
  415. }
  416. $nboflines = count($contents);
  417. $rawlisthasfailed = false;
  418. $i = 0;
  419. $nbofentries = 0;
  420. while ($i < $nboflines && $i < 1000) {
  421. $vals = preg_split('@ +@', utf8_encode($buff[$i]), 9);
  422. //$vals=preg_split('@ +@','drwxr-xr-x 2 root root 4096 Aug 30 2008 backup_apollon1',9);
  423. $file = $vals[8];
  424. if (empty($file)) {
  425. $rawlisthasfailed = true;
  426. $file = utf8_encode($contents[$i]);
  427. }
  428. if ($file == '.' || ($file == '..' && $section == '/')) {
  429. $i++;
  430. continue;
  431. }
  432. // Is it a directory ?
  433. $is_directory = 0;
  434. $is_link = 0;
  435. if ($file == '..') {
  436. $is_directory = 1;
  437. } elseif (!$rawlisthasfailed) {
  438. if (preg_match('/^d/', $vals[0])) {
  439. $is_directory = 1;
  440. }
  441. if (preg_match('/^l/', $vals[0])) {
  442. $is_link = 1;
  443. }
  444. } else {
  445. // Remote file
  446. $filename = $file;
  447. //print "section=".$section.' file='.$file.'X';
  448. //print preg_match('@[\/]$@','aaa/').'Y';
  449. //print preg_match('@[\\\/]$@',"aaa\\").'Y';
  450. $remotefile = $section.(preg_match('@[\\\/]$@', $section) ? '' : '/').preg_replace('@^[\\\/]@', '', $file);
  451. //print 'A'.$remotefile.'A';
  452. $newremotefileiso = utf8_decode($remotefile);
  453. //print 'Z'.$newremotefileiso.'Z';
  454. $is_directory = ftp_isdir($conn_id, $newremotefileiso);
  455. }
  456. print '<tr class="oddeven" height="18">';
  457. // Name
  458. print '<td>';
  459. $newsection = $section.(preg_match('@[\\\/]$@', $section) ? '' : '/').$file;
  460. $newsection = preg_replace('@[\\\/][^\\\/]+[\\\/]\.\.$@', '/', $newsection); // Change aaa/xxx/.. to new aaa
  461. if ($is_directory) {
  462. print '<a href="'.$_SERVER["PHP_SELF"].'?section='.urlencode($newsection).'&numero_ftp='.$numero_ftp.'">';
  463. }
  464. print dol_escape_htmltag($file);
  465. if ($is_directory) {
  466. print '</a>';
  467. }
  468. print '</td>';
  469. // Size
  470. print '<td class="center nowrap">';
  471. if (!$is_directory && !$is_link) {
  472. print $vals[4];
  473. } else {
  474. print '&nbsp;';
  475. }
  476. print '</td>';
  477. // Date
  478. print '<td class="center nowrap">';
  479. print $vals[5].' '.$vals[6].' '.$vals[7];
  480. print '</td>';
  481. // User
  482. print '<td class="center nowrap">';
  483. print $vals[2];
  484. print '</td>';
  485. // Group
  486. print '<td class="center nowrap">';
  487. print $vals[3];
  488. print '</td>';
  489. // Permissions
  490. print '<td class="center nowrap">';
  491. print $vals[0];
  492. print '</td>';
  493. // Action
  494. print '<td class="right nowrap" width="64">';
  495. if ($is_directory) {
  496. if ($file != '..') {
  497. print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete_section&token='.newToken().'&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>';
  498. } else {
  499. print '&nbsp;';
  500. }
  501. } elseif ($is_link) {
  502. $newfile = $file;
  503. $newfile = preg_replace('/ ->.*/', '', $newfile);
  504. print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($newfile).'">'.img_delete().'</a>';
  505. } else {
  506. print '<a href="'.$_SERVER["PHP_SELF"].'?action=download&token='.newToken().'&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_picto('', 'file').'</a>';
  507. print ' &nbsp; ';
  508. print '<input type="checkbox" class="flat checkboxfordelete" id="check_'.$i.'" name="const['.$i.'][check]" value="1">';
  509. print ' &nbsp; ';
  510. print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>';
  511. print '<input type="hidden" name="const['.$i.'][section]" value="'.$section.'">';
  512. print '<input type="hidden" name="const['.$i.'][file]" value="'.$file.'">';
  513. }
  514. print '</td>';
  515. print '</tr>'."\n";
  516. $i++;
  517. $nbofentries++;
  518. }
  519. }
  520. print "</table>";
  521. if (!$ok) {
  522. print $mesg.'<br>'."\n";
  523. setEventMessages($mesg, null, 'errors');
  524. }
  525. // Actions
  526. /*
  527. if ($user->rights->ftp->write && !empty($section))
  528. {
  529. $formfile->form_attach_new_file(DOL_URL_ROOT.'/ftp/index.php','',0,$section,1);
  530. }
  531. else print '&nbsp;';
  532. */
  533. print '<br>';
  534. print '<div id="delconst" class="right">';
  535. print '<input type="submit" name="delete" class="button" value="'.$langs->trans("Delete").'">';
  536. print '</div>';
  537. print "</form>";
  538. if ($user->hasRight('ftp', 'write')) {
  539. print load_fiche_titre($langs->trans("AttachANewFile"), null, null);
  540. print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  541. print '<input type="hidden" name="token" value="'.newToken().'">';
  542. print '<input type="hidden" name="numero_ftp" value="'.$numero_ftp.'">';
  543. print '<input type="hidden" name="section" value="'.$section.'">';
  544. print '<input type="hidden" name="action" value="uploadfile">';
  545. print '<td><input type="file" class="flat" name="userfile[]" multiple></td>';
  546. print '<td></td>';
  547. print '<td align="center"><button type="submit" class="butAction" name="uploadfile" value="'.$langs->trans("Save").'">'.$langs->trans("Upload").'</button></td>';
  548. print '</form>';
  549. print '<br><br>';
  550. print load_fiche_titre($langs->trans("AddFolder"), null, null);
  551. print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  552. print '<input type="hidden" name="token" value="'.newToken().'">';
  553. print '<input type="hidden" name="numero_ftp" value="'.$numero_ftp.'">';
  554. print '<input type="hidden" name="section" value="'.$section.'">';
  555. print '<input type="hidden" name="action" value="addfolder">';
  556. print '<td><input type="text" class="flat" name="newfolder" multiple></td>';
  557. print '<td></td>';
  558. print '<td align="center"><button type="submit" class="butAction" name="addfolder" value="'.$langs->trans("Save").'">'.$langs->trans("AddFolder").'</button></td>';
  559. print '</form>';
  560. }
  561. } else {
  562. $foundsetup = false;
  563. $MAXFTP = 20;
  564. $i = 1;
  565. while ($i <= $MAXFTP) {
  566. $paramkey = 'FTP_NAME_'.$i;
  567. //print $paramkey;
  568. if (getDolGlobalString($paramkey)) {
  569. $foundsetup = true;
  570. break;
  571. }
  572. $i++;
  573. }
  574. if (!$foundsetup) {
  575. print $langs->trans("SetupOfFTPClientModuleNotComplete");
  576. } else {
  577. print $langs->trans("ChooseAFTPEntryIntoMenu");
  578. }
  579. }
  580. }
  581. print '<br>';
  582. if (!empty($conn_id)) {
  583. $disconnect = dol_ftp_close($conn_id);
  584. if (!$disconnect) {
  585. setEventMessages($langs->trans("ErrorFTPNodisconnect"), null, 'errors');
  586. }
  587. }
  588. // End of page
  589. llxFooter();
  590. $db->close();