<?xml version="1.0" encoding="UTF-8"?>
<authdriver name="ftp" label="CONF_MESSAGE[FTP Authentification]" description="CONF_MESSAGE[Authenticate user directly to an FTP server, and connect him to this server.]" mixins="authdriver_commons"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:../core.ajaxplorer/ajxp_registry.xsd">
    <client_settings>
        <resources>
            <i18n namespace="ftp_auth" path="plugins/auth.ftp/i18n"/>
        </resources>
    </client_settings>
	<server_settings>
        <param name="TEST_CONNEXION" type="button" choices="run_plugin_action:auth.ftp:testParameters" default="auth.ftp" label="CONF_MESSAGE[Test Connexion]" description="CONF_MESSAGE[Test connexion to the FTP server]" mandatory="false"/>
        <param name="FTP_LOGIN_SCREEN" type="boolean" label="CONF_MESSAGE[FTP Login Screen]" description="CONF_MESSAGE[Whether to display a generic 'FTP connexion' dialog at startup (allowing the user to enter his own host/port data) or the standard login dialog.]" mandatory="true" default="false"/>
        <param name="REPOSITORY_ID" type="select" choices="json_list:list_all_repositories_json" label="CONF_MESSAGE[Repository]" description="CONF_MESSAGE[Id of the repository to use for testing connexion]" mandatory="true"/>
	</server_settings>
	<class_definition filename="plugins/auth.ftp/class.ftpAuthDriver.php" classname="ftpAuthDriver"/>
	<registry_contributions>
		<external_file filename="plugins/core.auth/standard_auth_actions.xml" include="actions/action[@name='login'],actions/action[@name='get_seed'],actions/action[@name='get_secure_token'],actions/action[@name='get_captcha'],actions/action[@name='back']" exclude=""/>
        <client_configs>
            <template element="ajxp_desktop" name="hide_remember_me" position="bottom"><![CDATA[
                    <style type="text/css"> form#login_form > div > div.SF_element:last-child{ display:none; }</style>
                    ]]></template>
        </client_configs>
        <actions>
			<action name="set_ftp_data">
				<rightsContext noUser="false" userLogged="hidden" guestLogged="show" read="false" write="false" adminOnly=""></rightsContext>
				<processing>
					<serverCallback methodName="setFtpDataCallback"></serverCallback>
				</processing>
			</action>
			<action name="dynamic_login">
				<gui text="163" title="168" src="encrypted.png"
					accessKey="" hasAccessKey="false" iconClass="icon-signin">
					<context selection="false" dir="" recycle="false"
						actionBar="true" contextMenu="false" infoPanel="false"
						actionBarGroup="user">
					</context>
				</gui>
				<rightsContext noUser="false" userLogged="hidden" guestLogged="show" read="false" write="false" adminOnly=""></rightsContext>			
				<processing>
					<clientCallback prepareModal="true"><![CDATA[
						var loginRedirect = AJXP_LOGIN_REDIRECT;
						if(loginRedirect){
							document.location.href=loginRedirect;
						}else{
							modal.showDialogForm('Log In', 'ftp_login_form', 
							function(oForm){
                                ajaxplorer.loadSeedOrCaptcha(oForm.down('#login_seed'), oForm.down('img#captcha_image'), oForm.down('div.dialogLegend'), 'before');
							},
							function(){
								var oForm = modal.getForm();
																
								var connexion = new Connexion();
								connexion.addParameter("get_action", "set_ftp_data");
								oForm.getElements().each(function(el){
									if(el.name != "userid" && el.name!="password" && el.name != "get_action" && el.name!="login_seed"){
										connexion.addParameter(el.name, el.getValue());
									}
								});
								connexion.onComplete = function(transport){
									ajaxplorer.actionBar.submitForm(oForm, true, function(transport){
                                        ajaxplorer.actionBar.parseXmlMessage(transport.responseXML);
                                        if(transport.responseXML && XPathGetSingleNodeText(transport.responseXML.documentElement, "logging_result/@value") == "-4"){
                                            ajaxplorer.loadSeedOrCaptcha(oForm.down('#login_seed'), oForm.down('img#captcha_image'), oForm.down('div.dialogLegend'), 'before');
                                        }
                                    });
									oForm.reset();
								};
								connexion.sendSync();								
								return false;				
							});
						}
						]]></clientCallback>
						<clientForm id="ftp_login_form"><![CDATA[						
							<div id="ftp_login_form" action="login" box_width="350">
							<input type="hidden" name="get_action" value="login">
							<input type="hidden" name="login_seed" id="login_seed" value="-1">
							<div>
								<table cellpadding="2" border="0" cellspacing="0" style="font-size:11px;margin-bottom:5px;">
								<tr>
									<td colspan="4">
										<div class="dialogLegend" ajxp_message_id="ftp_auth.1">AJXP_MESSAGE[ftp_auth.1]</div>
									</td>
								</tr>
								<tr>
									<td align="right"><ajxp:message ajxp_message_id="ftp_auth.2">AJXP_MESSAGE[ftp_auth.2]</ajxp:message> </td><td colspan="3"><input type="text" name="FTP_HOST" style="width: 190px; padding:0px; margin-right: 10px;" class="dialogFocus"><ajxp:message ajxp_message_id="ftp_auth.8">AJXP_MESSAGE[ftp_auth.8]</ajxp:message> &nbsp;<input type="text" name="FTP_PORT" style="width: 25px; padding:0px;" value="21"></td>
								</tr>
								<tr>
									<td align="right"><ajxp:message ajxp_message_id="181">AJXP_MESSAGE[181]</ajxp:message> </td><td><input type="text" name="userid" style="width: 100px; padding:0px;"></td>
									<td align="right"><ajxp:message ajxp_message_id="182">AJXP_MESSAGE[182]</ajxp:message> </td><td><input type="password" name="password"  style="width: 90px; padding:0px;"></td>
								</tr>
								<tr>
									<td colspan="4">
										<div class="dialogLegend" style="margin-top: 12px;" ajxp_message_id="ftp_auth.3">AJXP_MESSAGE[ftp_auth.3]</div>
									</td>
								</tr>
								<tr>
									<td align="right"><ajxp:message ajxp_message_id="ftp_auth.4">AJXP_MESSAGE[ftp_auth.4]</ajxp:message> </td><td><input type="text" name="PATH" style="width: 100px; padding:0px;" class="" value="/"></td>
									<td align="right" style="padding-left:10px;"><ajxp:message ajxp_message_id="ftp_auth.5">AJXP_MESSAGE[ftp_auth.5]</ajxp:message> </td><td><input type="radio" name="FTP_SECURE" style="width: 12px; padding:0px;" value="FALSE" checked><label style="display:inline-block;width:27px;"> FTP</label><input type="radio" name="FTP_SECURE" style="width: 12px; padding:0px;" value="TRUE"><label style="display:inline-block;width:27px;"> FTPS</label></td>
								</tr>								
								<tr>
									<td align="right"><ajxp:message ajxp_message_id="ftp_auth.6">AJXP_MESSAGE[ftp_auth.6]</ajxp:message> </td><td><input type="text" name="CHARSET" style="width: 100px; padding:0px;" class="" value=""></td>
									<td align="right"><ajxp:message ajxp_message_id="ftp_auth.7">AJXP_MESSAGE[ftp_auth.7]</ajxp:message> </td><td><input type="radio" name="FTP_DIRECT" style="width: 12px; padding:0px;" value="TRUE"><label style="display:inline-block;width:27px;">AJXP_MESSAGE[440]</label><input type="radio" name="FTP_DIRECT" style="width: 12px; padding:0px;" value="FALSE" checked><label style="display:inline-block;width:27px;">AJXP_MESSAGE[441]</label></td>
								</tr>
								</table>
							</div>
							
							</div>
						]]></clientForm>
					<serverCallback methodName="switchAction"></serverCallback>
				</processing>
			</action>	
			<!-- OVERRIDE LOGOUT -->
			<action name="ftp_logout" expireDefault="true">
				<gui text="164" title="169" src="decrypted.png"
					accessKey="" hasAccessKey="false" iconClass="icon-signout">
					<context selection="false" dir="" recycle="false"
						actionBar="false" contextMenu="false" infoPanel="false"
						actionBarGroup="user" ajxpWidgets="UserWidget::logging_string">
					</context>
				</gui>
				<rightsContext noUser="false" userLogged="only" guestLogged="hidden" read="false" write="false" adminOnly=""></rightsContext>			
				<processing>
					<clientCallback prepareModal="false"><![CDATA[
						clearRememberData();
						var connexion = new Connexion();
						connexion.addParameter('get_action', 'ftp_logout');
						connexion.onComplete = function(transport){
							ajaxplorer.actionBar.parseXmlMessage(transport.responseXML);
							};
						connexion.sendAsync();
						]]></clientCallback>
					<serverCallback methodName="logoutCallback"></serverCallback>
				</processing>
			</action>
		</actions>
	</registry_contributions>
	<dependencies>
		<pluginClass pluginName="access.ftp"/>
	</dependencies>
</authdriver>