From 3844c02058bc402a04778a0619b5cfbd009996f2 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Wed, 30 Sep 2009 16:11:54 +0000
Subject: [PATCH] Better error management in FTP client module

---
 htdocs/admin/ftpclient.php               | 30 +++++++++++++++++-------
 htdocs/ftp/index.php                     |  2 +-
 htdocs/includes/modules/modFTP.class.php |  7 +++---
 htdocs/langs/en_US/admin.lang            |  2 +-
 4 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/htdocs/admin/ftpclient.php b/htdocs/admin/ftpclient.php
index 51dcadeebd7..3fd4c0bf27e 100644
--- a/htdocs/admin/ftpclient.php
+++ b/htdocs/admin/ftpclient.php
@@ -1,9 +1,5 @@
 <?php
-/* Copyright (C) 2003      Eric Seigne          <erics@rycks.com>
- * Copyright (C) 2003,2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2008 Laurent Destailleur  <eldy@users.sourceforge.net>
- * Copyright (C) 2004      Sebastien Di Cintio  <sdicintio@ressource-toi.org>
- * Copyright (C) 2004      Benoit Mortier       <benoit.mortier@opensides.be>
+/* Copyright (C) 2004-2009 Laurent Destailleur  <eldy@users.sourceforge.net>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -30,15 +26,15 @@
 require("./pre.inc.php");
 require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
 
-
 $langs->load("admin");
 
+// Security check
 if (!$user->admin) accessforbidden();
 
 $def = array();
 $lastftpentry=0;
 
-// positionne la variable pour le nombre de rss externes
+// Positionne la variable pour le nombre de rss externes
 $sql ="select MAX(name) name from ".MAIN_DB_PREFIX."const";
 $sql.=" WHERE name like 'FTP_SERVER_%'";
 $result=$db->query($sql);
@@ -58,7 +54,22 @@ if ($_POST["action"] == 'add' || $_POST["modify"])
     $ftp_name = "FTP_NAME_" . $_POST["numero_entry"];
 	$ftp_server = "FTP_SERVER_" . $_POST["numero_entry"];
 
-    if (isset($_POST[$ftp_name]) && isset($_POST[$ftp_server]))
+	$error=0;
+	$mesg='';
+	
+	if (empty($_POST[$ftp_name]))
+	{
+		$error=1;
+		$mesg.='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Label")).'</div>';
+	}
+	
+	if (empty($_POST[$ftp_server]))
+	{
+		$error=1;
+		$mesg.='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Server")).'</div>';
+	}
+	
+    if (! $error)
     {
     	$ftp_port = "FTP_PORT_" . $_POST["numero_entry"];
         $ftp_user = "FTP_USER_" . $_POST["numero_entry"];
@@ -131,7 +142,8 @@ if (! function_exists('ftp_connect'))
 }
 else
 {
-
+	if ($mesg) print $mesg;
+	
 	// Formulaire ajout
 	print '<form name="ftpconfig" action="ftpclient.php" method="post">';
 	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
diff --git a/htdocs/ftp/index.php b/htdocs/ftp/index.php
index e9852baccbe..fa3cd458c21 100644
--- a/htdocs/ftp/index.php
+++ b/htdocs/ftp/index.php
@@ -69,7 +69,7 @@ $s_ftp_user='FTP_USER_'.$numero_ftp;
 $s_ftp_password='FTP_PASSWORD_'.$numero_ftp;
 $ftp_name=$conf->global->$s_ftp_name;
 $ftp_server=$conf->global->$s_ftp_server;
-$ftp_port=$conf->global->$s_ftp_port;
+$ftp_port=$conf->global->$s_ftp_port; if (empty($ftp_port)) $ftp_port=21;
 $ftp_user=$conf->global->$s_ftp_user;
 $ftp_password=$conf->global->$s_ftp_password;
 
diff --git a/htdocs/includes/modules/modFTP.class.php b/htdocs/includes/modules/modFTP.class.php
index 62805430e3e..7c0d6118500 100644
--- a/htdocs/includes/modules/modFTP.class.php
+++ b/htdocs/includes/modules/modFTP.class.php
@@ -95,18 +95,19 @@ class modFTP extends DolibarrModules
 
 		$r++;
 		$this->rights[$r][0] = 2800;
-		$this->rights[$r][1] = 'Use FTP client in read mode';
+		$this->rights[$r][1] = 'Use FTP client in read mode (browse and download only)';
 		$this->rights[$r][2] = 'r';
 		$this->rights[$r][3] = 1;
 		$this->rights[$r][4] = 'read';
 
+		/* Not yet developed
 		$r++;
 		$this->rights[$r][0] = 2801;
-		$this->rights[$r][1] = 'Use FTP client in write mode';
+		$this->rights[$r][1] = 'Use FTP client in write mode (can also upload files)';
 		$this->rights[$r][2] = 'w';
 		$this->rights[$r][3] = 0;
 		$this->rights[$r][4] = 'write';
-
+		*/
 
         // Menus
 		//------
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index 4d08061cb90..f4e210c06f9 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -335,7 +335,7 @@ Module600Name=Notifications
 Module600Desc=Send notifications by email on some Dolibarr business events to third party's contacts
 Module700Name=Donations
 Module700Desc=Donations' management
-Module800Name=OSCommerce direct
+Module800Name=OSCommerce by direct database access
 Module800Desc=Interface to show an OSCommerce or OSCSS shop via direct database access
 Module900Name=OSCommerce by WS
 Module900Desc=Interface to show an OSCommerce shop via Web services.\nThis module requiere you to install components from /oscommerce_ws/ws_server into your OSCommerce server. See README file in /oscommerce_ws/ws_server.
-- 
GitLab