27require 
'../main.inc.php';
 
   28require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
 
   29require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
 
   30require_once DOL_DOCUMENT_ROOT.
'/core/lib/treeview.lib.php';
 
   31require_once DOL_DOCUMENT_ROOT.
'/core/lib/ftp.lib.php';
 
   34$langs->loadLangs(array(
'companies', 
'other'));
 
   38  $socid = $user->socid;
 
   43$action = 
GETPOST(
'action', 
'aZ09');
 
   45$newfolder = 
GETPOST(
'newfolder');
 
   49$numero_ftp = 
GETPOST(
"numero_ftp");
 
   54$upload_dir = $conf->ftp->dir_temp;
 
   55$download_dir = $conf->ftp->dir_temp;
 
   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');
 
   61if (empty($page) || $page == -1) {
 
   64$offset = $limit * $page;
 
   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;
 
   83if (empty($ftp_port)) {
 
  101if ($action == 
'uploadfile') {
 
  104    $newsectioniso = mb_convert_encoding($section, 
'ISO-8859-1');
 
  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'];
 
  110  if ($conn_id && $ok && !$mesg) {
 
  111    $nbfile = count($_FILES[
'userfile'][
'name']);
 
  112    for ($i = 0; $i < $nbfile; $i++) {
 
  113      $newsection = $newsectioniso;
 
  116      $result = 
dol_ftp_put($conn_id, $fileupload, $fileuploadpath, $newsection);
 
  119        setEventMessages($langs->trans(
"FileWasUpload", $fileupload), 
null, 
'mesgs');
 
  121        dol_syslog(
"ftp/index.php ftp_delete", LOG_ERR);
 
  122        setEventMessages($langs->trans(
"FTPFailedToUploadFile", $fileupload), 
null, 
'errors');
 
  131if ($action == 
'addfolder') {
 
  134    $newsectioniso = mb_convert_encoding($section, 
'ISO-8859-1');
 
  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'];
 
  140  if ($conn_id && $ok && !$mesg) {
 
  141    $result = 
dol_ftp_mkdir($conn_id, $newfolder, $newsectioniso);
 
  144      setEventMessages($langs->trans(
"FileWasCreateFolder", $newfolder), 
null, 
'mesgs');
 
  146      dol_syslog(
"ftp/index.php ftp_delete", LOG_ERR);
 
  147      setEventMessages($langs->trans(
"FTPFailedToCreateFolder", $newfolder), 
null, 
'errors');
 
  156if ($action == 
'add' && $user->hasRight(
'ftp', 
'setup')) {
 
  159  $ecmdir->label              = 
GETPOST(
"label");
 
  160  $ecmdir->description        = 
GETPOST(
"desc");
 
  162  $id = $ecmdir->create($user);
 
  164    header(
"Location: ".$_SERVER[
"PHP_SELF"]);
 
  173if ($action == 
'confirm_deletefile' && 
GETPOST(
'confirm') == 
'yes') {
 
  176    $newsectioniso = mb_convert_encoding($section, 
'ISO-8859-1');
 
  177    $resultarray = 
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
 
  178    $conn_id = $resultarray[
'conn_id'];
 
  179    $ok = $resultarray[
'ok'];
 
  180    $mesg = $resultarray[
'mesg'];
 
  183  if ($conn_id && $ok && !$mesg) {
 
  184    $newsection = $section;
 
  190      dol_syslog(
"ftp/index.php ftp_delete", LOG_ERR);
 
  191      setEventMessages($langs->trans(
"FTPFailedToRemoveFile", $file), 
null, 
'errors');
 
  204    $newsectioniso = mb_convert_encoding($section, 
'ISO-8859-1');
 
  205    $resultarray = 
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
 
  206    $conn_id = $resultarray[
'conn_id'];
 
  207    $ok = $resultarray[
'ok'];
 
  208    $mesg = $resultarray[
'mesg'];
 
  211  if ($conn_id && $ok && !$mesg) {
 
  212    foreach (
GETPOST(
'const', 
'array') as $const) {
 
  213      if (isset($const[
"check"])) { 
 
  214        $langs->load(
"other");
 
  217        $file = $const[
"file"];
 
  218        $newsection = $const[
"section"];
 
  225          dol_syslog(
"ftp/index.php ftp_delete n files", LOG_ERR);
 
  226          setEventMessages($langs->trans(
"FTPFailedToRemoveFile", $file), 
null, 
'errors');
 
  240if ($action == 
'confirm_deletesection' && $confirm == 
'yes') {
 
  243    $newsectioniso = mb_convert_encoding($section, 
'ISO-8859-1');
 
  244    $resultarray = 
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
 
  245    $conn_id = $resultarray[
'conn_id'];
 
  246    $ok = $resultarray[
'ok'];
 
  247    $mesg = $resultarray[
'mesg'];
 
  250  if ($conn_id && $ok && !$mesg) {
 
  251    $newsection = $section;
 
  258      setEventMessages($langs->trans(
"FTPFailedToRemoveDir", $file), 
null, 
'errors');
 
  270if ($action == 
'download') {
 
  273    $newsectioniso = mb_convert_encoding($section, 
'ISO-8859-1');
 
  274    $resultarray = 
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
 
  275    $conn_id = $resultarray[
'conn_id'];
 
  276    $ok = $resultarray[
'ok'];
 
  277    $mesg = $resultarray[
'mesg'];
 
  280  if ($conn_id && $ok && !$mesg) {
 
  282    $localfile = tempnam($download_dir, 
'dol_');
 
  284    $newsection = $section;
 
  286    $result = 
dol_ftp_get($conn_id, $localfile, $file, $newsection);
 
  293      $type = 
'application/octet-stream';
 
  294      if (GETPOSTISSET(
"type")) {
 
  305        header(
'Content-Type: '.$type);
 
  308        header(
'Content-Disposition: attachment; filename="'.$file.
'"');
 
  310        header(
'Content-Disposition: inline; filename="'.$file.
'"');
 
  314      header(
'Cache-Control: Public, must-revalidate');
 
  315      header(
'Pragma: public');
 
  317      readfile($localfile);
 
  321      setEventMessages($langs->transnoentitiesnoconv(
'FailedToGetFile', $file), 
null, 
'errors');
 
  340if ($conf->use_javascript_ajax) {
 
  342<script 
type=
"text/javascript">
 
  343jQuery(document).ready(
function() {
 
  344  jQuery(
"#delconst").hide();
 
  346  jQuery(
".checkboxfordelete").click(
function() {
 
  347    jQuery(
"#delconst").show();
 
  350  $(
"#checkall").click(
function() {
 
  351    $(
".checkboxfordelete").prop(
'checked', 
true);
 
  352    jQuery(
"#delconst").show();
 
  354  $(
"#checknone").click(
function() {
 
  355    $(
".checkboxfordelete").prop(
'checked', 
false);
 
  356    jQuery(
"#delconst").hide();
 
  366$form = 
new Form($db);
 
  368$userstatic = 
new User($db);
 
  374print $langs->trans(
"FTPAreaDesc").
"<br>";
 
  376if (!function_exists(
'ftp_connect')) {
 
  377  print $langs->trans(
"FTPFeatureNotSupportedByYourPHP");
 
  379  if (!empty($ftp_server)) {
 
  381    if ($action == 
'delete') {
 
  382      print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?numero_ftp='.$numero_ftp.
'§ion='.urlencode(
GETPOST(
'section')).
'&file='.urlencode(
GETPOST(
'file')), $langs->trans(
'DeleteFile'), $langs->trans(
'ConfirmDeleteFile', 
GETPOST(
'file')), 
'confirm_deletefile', 
'', 
'', 1);
 
  386    if ($action == 
'delete_section') {
 
  387      print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?numero_ftp='.$numero_ftp.
'§ion='.urlencode(
GETPOST(
'section')).
'&file='.urlencode(
GETPOST(
'file')), $langs->trans(
'DeleteSection'), $langs->trans(
'ConfirmDeleteSection', 
GETPOST(
'file')), 
'confirm_deletesection', 
'', 
'', 1);
 
  390    print $langs->trans(
"Server").
': <b>'.$ftp_server.
'</b><br>';
 
  391    print $langs->trans(
"Port").
': <b>'.$ftp_port.
'</b> '.($ftp_passive ? 
"(Passive)" : 
"(Active)").
'<br>';
 
  392    print $langs->trans(
"User").
': <b>'.$ftp_user.
'</b><br>';
 
  393    print $langs->trans(
"FTPs (FTP over SSH)").
': <b>'.
yn($conf->global->FTP_CONNECT_WITH_SSL).
'</b><br>';
 
  394    print $langs->trans(
"SFTP (FTP as a subsytem of SSH)").
': <b>'.
yn($conf->global->FTP_CONNECT_WITH_SFTP).
'</b><br>';
 
  395    print $langs->trans(
"Directory").
': ';
 
  396    $sectionarray = preg_split(
'|[\/]|', $section);
 
  399    print 
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection ? 
'§ion='.urlencode($newsection) : 
'').
'">';
 
  404    foreach ($sectionarray as $val) {
 
  413      print 
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection ? 
'§ion='.urlencode($newsection) : 
'').
'">';
 
  421    print 
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
 
  422    print 
'<input type="hidden" name="numero_ftp" value="'.$numero_ftp.
'">';
 
  423    print 
'<input type="hidden" name="token" value="'.newToken().
'">';
 
  427    print 
'<table width="100%" class="noborder">'.
"\n";
 
  429    print 
'<tr class="liste_titre">'.
"\n";
 
  430    print 
'<td class="liste_titre left">'.$langs->trans(
"Content").
'</td>'.
"\n";
 
  431    print 
'<td class="liste_titre center">'.$langs->trans(
"Size").
'</td>'.
"\n";
 
  432    print 
'<td class="liste_titre center">'.$langs->trans(
"Date").
'</td>'.
"\n";
 
  433    print 
'<td class="liste_titre center">'.$langs->trans(
"Owner").
'</td>'.
"\n";
 
  434    print 
'<td class="liste_titre center">'.$langs->trans(
"Group").
'</td>'.
"\n";
 
  435    print 
'<td class="liste_titre center">'.$langs->trans(
"Permissions").
'</td>'.
"\n";
 
  436    print 
'<td class="liste_titre nowrap right">';
 
  437    if ($conf->use_javascript_ajax) {
 
  438      print 
'<a href="#" id="checkall">'.$langs->trans(
"All").
'</a> / <a href="#" id="checknone">'.$langs->trans(
"None").
'</a> ';
 
  440    print 
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=refreshmanual&numero_ftp='.$numero_ftp.($section ? 
'§ion='.urlencode($section) : 
'').
'">'.
img_picto($langs->trans(
"Refresh"), 
'refresh').
'</a> ';
 
  445    if (empty($conn_id)) {
 
  446      $resultarray = 
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive);
 
  448      $conn_id = $resultarray[
'conn_id'];
 
  449      $ok = $resultarray[
'ok'];
 
  450      $mesg = $resultarray[
'mesg'];
 
  456      $newsection = $section;
 
  457      $newsectioniso = mb_convert_encoding($section, 
'ISO-8859-1');
 
  462        if ($newsection == 
'/') {
 
  464          $newsection = ssh2_sftp_realpath($conn_id, 
".").
'/./'; 
 
  471        $contents = scandir(
'ssh2.sftp://'.intval($conn_id).$newsection);
 
  473        foreach ($contents as $i => $key) {
 
  474          $buff[$i] = 
"---------- - root root 1234 Aug 01 2000 ".$key;
 
  491        $buff = ftp_rawlist($conn_id, $newsectioniso);
 
  492        $contents = ftp_nlist($conn_id, $newsectioniso); 
 
  495      $nboflines = count($contents);
 
  496      $rawlisthasfailed = 
false;
 
  499      while ($i < $nboflines && $i < 1000) {
 
  500        $vals = preg_split(
'@ +@', mb_convert_encoding($buff[$i], 
'UTF-8', 
'ISO-8859-1'), 9);
 
  504          $rawlisthasfailed = 
true;
 
  505          $file = mb_convert_encoding($contents[$i], 
'UTF-8', 
'ISO-8859-1');
 
  508        if ($file == 
'.' || ($file == 
'..' && $section == 
'/')) {
 
  518        } elseif (!$rawlisthasfailed) {
 
  519          if (preg_match(
'/^d/', $vals[0])) {
 
  522          if (preg_match(
'/^l/', $vals[0])) {
 
  531          $remotefile = $section.(preg_match(
'@[\\\/]$@', $section) ? 
'' : 
'/').preg_replace(
'@^[\\\/]@', 
'', $file);
 
  533          $newremotefileiso = mb_convert_encoding($remotefile, 
'ISO-8859-1');
 
  535          $is_directory = 
ftp_isdir($conn_id, $newremotefileiso);
 
  539        print 
'<tr class="oddeven" height="18">';
 
  542        $newsection = $section.(preg_match(
'@[\\\/]$@', $section) ? 
'' : 
'/').$file;
 
  543        $newsection = preg_replace(
'@[\\\/][^\\\/]+[\\\/]\.\.$@', 
'/', $newsection); 
 
  545          print 
'<a href="'.$_SERVER[
"PHP_SELF"].
'?section='.urlencode($newsection).
'&numero_ftp='.$numero_ftp.
'">';
 
  553        print 
'<td class="center nowrap">';
 
  554        if (!$is_directory && !$is_link) {
 
  561        print 
'<td class="center nowrap">';
 
  562        print $vals[5].
' '.$vals[6].
' '.$vals[7];
 
  565        print 
'<td class="center nowrap">';
 
  569        print 
'<td class="center nowrap">';
 
  573        print 
'<td class="center nowrap">';
 
  577        print 
'<td class="right nowrap" width="64">';
 
  580            print 
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete_section&token='.newToken().
'&numero_ftp='.$numero_ftp.
'§ion='.urlencode($section).
'&file='.urlencode($file).
'">'.
img_delete().
'</a>';
 
  584        } elseif ($is_link) {
 
  586          $newfile = preg_replace(
'/ ->.*/', 
'', $newfile);
 
  587          print 
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete&token='.newToken().
'&numero_ftp='.$numero_ftp.
'§ion='.urlencode($section).
'&file='.urlencode($newfile).
'">'.
img_delete().
'</a>';
 
  589          print 
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=download&token='.newToken().
'&numero_ftp='.$numero_ftp.
'§ion='.urlencode($section).
'&file='.urlencode($file).
'">'.
img_picto(
'', 
'file').
'</a>';
 
  591          print 
'<input type="checkbox" class="flat checkboxfordelete" id="check_'.$i.
'" name="const['.$i.
'][check]" value="1">';
 
  593          print 
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete&token='.newToken().
'&numero_ftp='.$numero_ftp.
'§ion='.urlencode($section).
'&file='.urlencode($file).
'">'.
img_delete().
'</a>';
 
  594          print 
'<input type="hidden" name="const['.$i.
'][section]" value="'.$section.
'">';
 
  595          print 
'<input type="hidden" name="const['.$i.
'][file]" value="'.$file.
'">';
 
  608      print $mesg.
'<br>'.
"\n";
 
  623    print 
'<div id="delconst" class="right">';
 
  624    print 
'<input type="submit" name="delete" class="button" value="'.$langs->trans(
"Delete").
'">';
 
  629    if ($user->hasRight(
'ftp', 
'write')) {
 
  631      print 
'<form enctype="multipart/form-data" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
 
  632      print 
'<input type="hidden" name="token" value="'.newToken().
'">';
 
  633      print 
'<input type="hidden" name="numero_ftp" value="'.$numero_ftp.
'">';
 
  634      print 
'<input type="hidden" name="section" value="'.$section.
'">';
 
  635      print 
'<input type="hidden" name="action" value="uploadfile">';
 
  636      print 
'<td><input type="file" class="flat"  name="userfile[]" multiple></td>';
 
  638      print 
'<td align="center"><button type="submit" class="butAction" name="uploadfile" value="'.$langs->trans(
"Save").
'">'.$langs->trans(
"Upload").
'</button></td>';
 
  644      print 
'<form enctype="multipart/form-data" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
 
  645      print 
'<input type="hidden" name="token" value="'.newToken().
'">';
 
  646      print 
'<input type="hidden" name="numero_ftp" value="'.$numero_ftp.
'">';
 
  647      print 
'<input type="hidden" name="section" value="'.$section.
'">';
 
  648      print 
'<input type="hidden" name="action" value="addfolder">';
 
  649      print 
'<td><input type="text" class="flat"  name="newfolder" multiple></td>';
 
  651      print 
'<td align="center"><button type="submit" class="butAction" name="addfolder" value="'.$langs->trans(
"Save").
'">'.$langs->trans(
"AddFolder").
'</button></td>';
 
  658    while ($i <= $MAXFTP) {
 
  659      $paramkey = 
'FTP_NAME_'.$i;
 
  668      print $langs->trans(
"SetupOfFTPClientModuleNotComplete");
 
  670      print $langs->trans(
"ChooseAFTPEntryIntoMenu");
 
  677if (!empty($conn_id)) {
 
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
 
Class to manage ECM directories.
 
Class to manage Dolibarr users.
 
dol_ftp_mkdir($connect_id, $newdir, $newsection)
Remove FTP directory.
 
ftp_isdir($connect_id, $dir)
Tell if an entry is a FTP directory.
 
dol_ftp_close($connect_id)
Tell if an entry is a FTP directory.
 
dol_ftp_delete($connect_id, $file, $newsection)
Delete a FTP file.
 
dol_ftp_rmdir($connect_id, $file, $newsection)
Remove FTP directory.
 
dol_ftp_put($connect_id, $file, $localfile, $newsection)
Upload a FTP file.
 
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive=0)
Connect to FTP server.
 
dol_ftp_get($connect_id, $localfile, $file, $newsection)
Download a FTP file.
 
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.
 
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...
 
dolChmod($filepath, $newmask='')
Change mod of a file.
 
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
 
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
 
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
 
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
 
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
 
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
 
dol_sanitizePathName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a path name.
 
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
 
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
 
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.