<?php
/*
Copyright (C) 2007 Mercier Benjamin

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.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
*/

// Librairie contenant l'ajout de compte ftp

if (  VerifPOST("Nom", "#^[a-z0-9]+$#", 3, 9) == "ChaineValide" )
	{
	if ( VerifPOST("MotDePasse", "#^[a-z0-9]+$#i", 3, 9) == "ChaineValide" )
		{
		if ( (VerifPOST("Chemin", "#^/[a-z0-9/_-]+/$#", 1, 70) == "ChaineValide") or (VerifPOST("Chemin", "#^/$#", 1, 70) == "ChaineValide") )
			{
			if ( (VerifPOST("Commentaire", "#^[a-z0-9 ]+$#i", 1, 50) == "ChaineValide") or (VerifPOST("Commentaire", "#^[a-z0-9]+$#i", 1, 50) == "ChaineVide") )
				{
				$VerifExistance = $MySql->Select ("*", "ftp", "Nom='".$_SESSION['Utilisateur']."_".$_POST['Nom']."'", "", "", "", "");
				if ( $VerifExistance == FALSE )
					{
						$CountFTP = $MySql->Count('id', 'ftp', "Utilisateur='{$_SESSION['Utilisateur']}'");
						if ( ($CountFTP >= $_SESSION['Offre']['Ftp']) and ($_SESSION['Offre']['Ftp'] != '-1')) {
							$_SESSION['Resultat'] = "Desole, votre offre ne vous permet pas d'ajouter plus de compte(s) FTP.";
							$_SESSION['Lien'] = "Page-Ftp-SuppressionCompte.html";
							Redirect ('resultat.html');
						} else {
							$Conteneur = "Utilisateur, Nom, Password, Status, Chemin, Commentaire, DateDeCreation";
							$Contenu   = "'".$_SESSION['Utilisateur']."', '".$_SESSION['Utilisateur']."_".$_POST['Nom']."', '".$_POST['MotDePasse']."', '1', '".$_POST['Chemin']."', '".$_POST['Commentaire']."', '".time()."'";
							$MySql->Insert ($Conteneur,$Contenu, "ftp");
							Redirect ('Page-Ftp-Recapitulatif.html');
						}
					}
				else
					{
					$_SESSION['Resultat'] = "Ce compte existe deja.";
					$_SESSION['Lien'] = "Page-Ftp-AjoutCompte.html";
					Redirect ('resultat.html');
					}
				}
			else
				{
				$_SESSION['Resultat'] = "Le commentaire est incorrect.";
				$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
				Redirect ('resultat.html');
				}
			}
		else
			{
			$_SESSION['Resultat'] = "Le chemin est incorrect (il doit commencer et finir par /)";
			$_SESSION['Lien'] = "Page-Ftp-AjoutCompte.html";
			Redirect ('resultat.html');
			}
		}
	else
		{
		$_SESSION['Resultat'] = "Le mot de passe est incorrect";
		$_SESSION['Lien'] = "Page-Ftp-AjoutCompte.html";
		Redirect ('resultat.html');
		}
	}
else
	{
	$_SESSION['Resultat'] = "Le nom du compte est incorrect";
	$_SESSION['Lien'] = "Page-Ftp-AjoutCompte.html";
	Redirect ('resultat.html');
	}
	
?>