index.php 22 KB

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