* Copyright (C) 2011 Juanjo Menent * * 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 3 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, see . */ /** * \file htdocs/ftp/admin/ftpclient.php * \ingroup ftp * \brief Admin page to setup FTP client module */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; $langs->load("admin"); $langs->load("ftp"); // Security check if (!$user->admin) accessforbidden(); $def = array(); $lastftpentry=0; $action = GETPOST('action','alpha'); $entry = GETPOST('numero_entry','alpha'); // 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 ($action == 'add' || GETPOST('modify','alpha')) { $ftp_name = "FTP_NAME_" . $entry;// $_POST["numero_entry"]; $ftp_server = "FTP_SERVER_" . $entry; //$_POST["numero_entry"]; $error=0; if (! GETPOST("$ftp_name",'alpha')) { $error=1; setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Label")), 'errors'); } if (! GETPOST("$ftp_server",'alpha')) { $error=1; setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Server")), 'errors'); } if (! $error) { $ftp_port = "FTP_PORT_" . $entry; $ftp_user = "FTP_USER_" . $entry; $ftp_password = "FTP_PASSWORD_" . $entry; $ftp_passive = "FTP_PASSIVE_" . $entry; $db->begin(); $result1=dolibarr_set_const($db, "FTP_PORT_" . $entry,GETPOST($ftp_port,'alpha'),'chaine',0,'',$conf->entity); if ($result1) $result2=dolibarr_set_const($db, "FTP_SERVER_" . $entry, GETPOST($ftp_server,'alpha'),'chaine',0,'',$conf->entity); if ($result2) $result3=dolibarr_set_const($db, "FTP_USER_" . $entry,GETPOST($ftp_user,'alpha'),'chaine',0,'',$conf->entity); if ($result3) $result4=dolibarr_set_const($db, "FTP_PASSWORD_" . $entry,GETPOST($ftp_password,'alpha'),'chaine',0,'',$conf->entity); if ($result4) $result5=dolibarr_set_const($db, "FTP_NAME_" . $entry,GETPOST($ftp_name,'alpha'),'chaine',0,'',$conf->entity); if ($result5) $result6=dolibarr_set_const($db, "FTP_PASSIVE_" . $entry,GETPOST($ftp_passive,'alpha'),'chaine',0,'',$conf->entity); if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6) { $db->commit(); header("Location: ".$_SERVER["PHP_SELF"]); exit; } else { $db->rollback(); dol_print_error($db); } } } if (GETPOST('delete','alpha')) { if($entry) { $db->begin(); $result1=dolibarr_del_const($db,"FTP_PORT_" . $entry,$conf->entity); if ($result1) $result2=dolibarr_del_const($db,"FTP_SERVER_" . $entry,$conf->entity); if ($result2) $result3=dolibarr_del_const($db,"FTP_USER_" . $entry,$conf->entity); if ($result3) $result4=dolibarr_del_const($db,"FTP_PASSWORD_" . $entry,$conf->entity); if ($result4) $result5=dolibarr_del_const($db,"FTP_NAME_" . $entry,$conf->entity); if ($result4) $result6=dolibarr_del_const($db,"FTP_PASSIVE_" . $entry,$conf->entity); if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6) { $db->commit(); header("Location: ".$_SERVER["PHP_SELF"]); exit; } else { $db->rollback(); dol_print_error($db); } } } /* * View */ $form=new Form($db); llxHeader(); $linkback=''.$langs->trans("BackToModuleList").''; print_fiche_titre($langs->trans("FTPClientSetup"), $linkback, 'title_setup'); print '
'; if (! function_exists('ftp_connect')) { print $langs->trans("FTPFeatureNotSupportedByYourPHP"); } else { // Formulaire ajout print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $defaultpassive=GETPOST("FTP_PASSIVE_" . ($lastftpentry+1)); if (! isset($_POST["FTP_PASSIVE_" . ($lastftpentry+1)])) $defaultpassive=empty($conf->global->FTP_SUGGEST_PASSIVE_BYDEFAULT)?0:1; print ''; print ''; print ''; print '
'.$langs->trans("NewFTPClient").''.$langs->trans("Example").'
'.$langs->trans("Label").'My FTP access
'.$langs->trans("Server").'localhost
'.$langs->trans("Port").'21
'.$langs->trans("User").'myftplogin
'.$langs->trans("Password").'myftppassword
'.$langs->trans("FTPPassiveMode").''.$form->selectyesno('FTP_PASSIVE_'.($lastftpentry+1), $defaultpassive, 2).''.$langs->trans("No").'
'; ?>
">
'; ?>
'."\n"; $sql ="select name, value, note from ".MAIN_DB_PREFIX."const"; $sql.=" WHERE name like 'FTP_SERVER_%'"; $sql.=" ORDER BY name"; dol_syslog("ftpclient select ftp setup", LOG_DEBUG); $resql=$db->query($sql); if ($resql) { $num =$db->num_rows($resql); $i=0; while ($i < $num) { $obj = $db->fetch_object($resql); preg_match('/([0-9]+)$/i',$obj->name,$reg); $idrss = $reg[0]; //print "x".join(',',$reg)."=".$obj->name."=".$idrss; $var=true; print ""; print ''; print ""; print "".$langs->trans("FTP")." ".($idrss).""; print ""; $var=!$var; print ""; print "".$langs->trans("Name").""; print ""; print ""; $var=!$var; print ""; print "".$langs->trans("Server").""; print ""; print ""; $var=!$var; print ""; print "".$langs->trans("Port").""; print ""; print ""; $var=!$var; print ""; print "".$langs->trans("User").""; print ""; print ""; $var=!$var; print ""; print "".$langs->trans("Password").""; print ""; print ""; $var=!$var; print ""; print "".$langs->trans("FTPPassiveMode").""; print ''.$form->selectyesno('FTP_PASSIVE_'.$idrss, @constant("FTP_PASSIVE_" . $idrss), 1).''; print ""; print ""; print ""; print "trans("Modify")."\">"; print "   "; print "trans("Delete")."\">"; print ""; print ""; print ""; print "
"; $i++; } } else { dol_print_error($db); } print ''; } llxFooter(); $db->close();