*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* \file htdocs/ftp/admin/ftpclient.php
* \ingroup ftp
* \brief Admin page to setup FTP client module
* \version $Id$
*/
require("../../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
$langs->load("admin");
$langs->load("ftp");
// Security check
if (!$user->admin) accessforbidden();
$def = array();
$lastftpentry=0;
// Positionne la variable pour le nombre de rss externes
$sql ="select MAX(name) as name from ".MAIN_DB_PREFIX."const";
$sql.=" WHERE name like 'FTP_SERVER_%'";
$result=$db->query($sql);
if ($result)
{
$obj = $db->fetch_object($result);
preg_match('/([0-9]+)$/i',$obj->name,$reg);
if ($reg[1]) $lastftpentry = $reg[1];
}
else
{
dol_print_error($db);
}
if ($_POST["action"] == 'add' || $_POST["modify"])
{
$ftp_name = "FTP_NAME_" . $_POST["numero_entry"];
$ftp_server = "FTP_SERVER_" . $_POST["numero_entry"];
$error=0;
$mesg='';
if (empty($_POST[$ftp_name]))
{
$error=1;
$mesg.='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Label")).'
';
}
if (empty($_POST[$ftp_server]))
{
$error=1;
$mesg.=''.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Server")).'
';
}
if (! $error)
{
$ftp_port = "FTP_PORT_" . $_POST["numero_entry"];
$ftp_user = "FTP_USER_" . $_POST["numero_entry"];
$ftp_password = "FTP_PASSWORD_" . $_POST["numero_entry"];
$db->begin();
$result1=dolibarr_set_const($db, "FTP_PORT_" . $_POST["numero_entry"],$_POST[$ftp_port],'chaine',0,'',$conf->entity);
if ($result1) $result2=dolibarr_set_const($db, "FTP_SERVER_" . $_POST["numero_entry"],$_POST[$ftp_server],'chaine',0,'',$conf->entity);
if ($result2) $result3=dolibarr_set_const($db, "FTP_USER_" . $_POST["numero_entry"],$_POST[$ftp_user],'chaine',0,'',$conf->entity);
if ($result3) $result4=dolibarr_set_const($db, "FTP_PASSWORD_" . $_POST["numero_entry"],$_POST[$ftp_password],'chaine',0,'',$conf->entity);
if ($result4) $result5=dolibarr_set_const($db, "FTP_NAME_" . $_POST["numero_entry"],$_POST[$ftp_name],'chaine',0,'',$conf->entity);
if ($result1 && $result2 && $result3 && $result4 && $result5)
{
$db->commit();
//$mesg=''.$langs->trans("Success").'
';
header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
else
{
$db->rollback();
dol_print_error($db);
}
}
}
if ($_POST["delete"])
{
if(isset($_POST["numero_entry"]))
{
$db->begin();
$result1=dolibarr_del_const($db,"ftp_port_" . $_POST["numero_entry"],$conf->entity);
if ($result1) $result2=dolibarr_del_const($db,"ftp_server_" . $_POST["numero_entry"],$conf->entity);
if ($result2) $result3=dolibarr_del_const($db,"ftp_user_" . $_POST["numero_entry"],$conf->entity);
if ($result3) $result4=dolibarr_del_const($db,"ftp_password_" . $_POST["numero_entry"],$conf->entity);
if ($result4) $result5=dolibarr_del_const($db,"ftp_name_" . $_POST["numero_entry"],$conf->entity);
if ($result1 && $result2 && $result3 && $result4 && $result5)
{
$db->commit();
//$mesg=''.$langs->trans("Success").'
';
header("Location: ftpclient.php");
exit;
}
else
{
$db->rollback();
dol_print_error($db);
}
}
}
/*
* View
*/
llxHeader();
$linkback=''.$langs->trans("BackToModuleList").'';
print_fiche_titre($langs->trans("FTPClientSetup"), $linkback, 'setup');
print '
';
if (! function_exists('ftp_connect'))
{
print $langs->trans("FTPFeatureNotSupportedByYourPHP");
}
else
{
if ($mesg) print $mesg;
// Formulaire ajout
print '