<?php

//   -------------------------------------------------------------------------------
//  |                  net2ftp: a web based FTP client                              |
//  |              Copyright (c) 2003-2005 by David Gartner                         |
//  |                                                                               |
//  | 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.                        |
//  |                                                                               |
//   -------------------------------------------------------------------------------




// **************************************************************************************
// **************************************************************************************
// **                                                                                  **
// **                                                                                  **

function net2ftp_loginform($net2ftp_directory, $net2ftp_url) {

// -------------------------------------------------------------------------
// This function prints the net2ftp login form.
//
// ----- VARIABLES -----
// $includes_directory = directory where the net2ftp includes are located, for example 
//                          /usr/web/net2ftp/includes
//                       Note that there is a leading / but no trailing / at the end.
// $net2ftp_url        = URL of net2ftp on your website, for example
//                          http://www.mydomain.com/tools/net2ftp/index.php
//
// ----- STYLE -----
// The look of the login form can be customized with CSS (cascading style sheets) classes.
// The input textboxes use class "input" and the login button uses class "button".
// -------------------------------------------------------------------------


// -------------------------------------------------------------------------
// Includes
// -------------------------------------------------------------------------
	require_once($net2ftp_directory . "/settings.inc.php");
	require_once($net2ftp_directory . "/settings_authorizations.inc.php");
	require_once($net2ftp_directory . "/settings_screens.inc.php");
	require_once($net2ftp_directory . "/includes/errorhandling.inc.php");
	require_once($net2ftp_directory . "/includes/languages.inc.php");
	require_once($net2ftp_directory . "/includes/skins.inc.php");


// -------------------------------------------------------------------------
// Global variables and settings
// -------------------------------------------------------------------------
	global $settings;
	global $net2ftpcookie_ftpserver;
	global $net2ftpcookie_ftpserverport;
	global $net2ftpcookie_username;
	global $net2ftpcookie_language;
	global $net2ftpcookie_skin;
	global $net2ftpcookie_ftpmode;
	global $net2ftpcookie_passivemode;
	global $net2ftpcookie_sslconnect;
	global $net2ftpcookie_viewmode;
	global $net2ftpcookie_directory;
//	global $net2ftpcookie_sort;
//	global $net2ftpcookie_sortorder;

	global $PHP_SELF;

	$net2ftp_allowed_ftpservers    = $settings["net2ftp_allowed_ftpservers"];
	$net2ftp_allowed_ftpserverport = $settings["net2ftp_allowed_ftpserverport"];
	$logindirectory                = $settings["logindirectory"];


// -------------------------------------------------------------------------
// Load the language file
// -------------------------------------------------------------------------
	if (is_array($settings) == false) {
		includeLanguageFile();
	}


// -------------------------------------------------------------------------
// Begin output
// -------------------------------------------------------------------------
	echo "\n\n\n\n\n";
	echo "<!-- This login form is generated by the net2ftp function net2ftp_loginform() -->\n";
	echo "<!-- net2ftp's main code is free software, released under the GNU/GPL license -->\n";


// -------------------------------------------------------------------------
// Javascript
// -------------------------------------------------------------------------
		echo "<script type=\"text/javascript\"><!--\n";

// Check that some values are entered on the input form
		echo "function CheckInput(form) {\n";
		echo "	var u,p1,p2,e;\n";
		echo "	s=form.ftpserver.value;\n";
		echo "	u=form.username.value;\n";
		echo "	p=form.password.value;\n";

		echo "	if (s.length==0) {\n";
		echo "		form.ftpserver.focus();\n";
		echo "		alert(\"" . __("Please enter an FTP server.") . "\");\n";
		echo "		return false;\n";
		echo "	}\n";

		echo "	if (u.length==0) {\n";
		echo "		form.username.focus();\n";
		echo "		alert(\"" . __("Please enter a username.") . "\");\n";
		echo "		return false;\n";
		echo "	}\n";

//		echo "	if (p.length==0) {\n";
//		echo "		form.password.focus();\n";
//		echo "		alert(\"" . __("Please enter a password.") . "\");\n";
//		echo "		return false;\n";
//		echo "	}\n";

		echo "	return true;\n";
		echo "}\n";

// Anonymous login
		echo "function do_anonymous(form) {\n";
		echo "	var checked = form.anonymous.checked;\n";
		echo "	if (checked == true) {\n";
		echo "		vars_defined = 'true';\n";
		echo "		last_username = form.username.value;\n";
		echo "		last_password = form.password.value;\n";
		echo "		form.username.value = \"anonymous\";\n";
		echo "		form.password.value = \"user@net2ftp\";\n";
		echo "	} else {\n";
		echo "		form.username.value = last_username;\n";
		echo "		form.password.value = last_password;\n";
		echo "	}\n";
		echo "	return true;\n";
		echo "}\n";
		
// Clear Cookies
		echo "function ClearCookies() {\n";
		echo "	document.LoginForm.state.value='homepage';\n";
		echo "	document.LoginForm.state2.value='';\n";
		echo "	document.LoginForm.cookieset.value='clear';\n";
		echo "	document.LoginForm.submit();\n";
		echo "}\n";

		echo "//--></script>\n";


} // End function net2ftp_loginform

// **                                                                                  **
// **                                                                                  **
// **************************************************************************************
// **************************************************************************************



?>