<?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 zone DNS

if ( VerifPOST('Domaine', '#^[a-z0-9.-]+\.[a-z]+$#', 3, 50) != 'ChaineValide' ){
	$_SESSION['Resultat'] = "La syntaxe du nom de domaine est invalide";
	$_SESSION['Lien'] = "Page-DNS-AjoutDomaine.html";
	Redirect ('resultat.html');
} elseif  ( VerifPOST("Domaine", "#kelio\.org#", 5, 120) == "ChaineValide") {
	$_SESSION['Resultat'] = "Vous ne pouvez ajouter kelio.org";
	$_SESSION['Lien'] = "Page-DNS-AjoutDomaine.html";
	Redirect ('resultat.html');
}
$Commentaire = htmlspecialchars($_POST['Commentaire']);

if ( (VerifPOST("Racine", "#^/[.a-z0-9/_-]+/$#", 1, 120) != "ChaineValide") and (VerifPOST("Racine", "#^/$#", 1, 120) != "ChaineValide") ) {
	$_SESSION['Resultat'] = "La racine du nom de domaine est invalide";
	$_SESSION['Lien'] = "Page-DNS-AjoutDomaine.html";
	Redirect ('resultat.html');
}

if ( (VerifPOST("OpenBasedir", "#^/[.a-z0-9/_-]+/$#", 1, 120) != "ChaineValide") and (VerifPOST("OpenBasedir", "#^/$#", 1, 120) != "ChaineValide") ) {
	$_SESSION['Resultat'] = "L'Open Basedir du nom de domaine est invalide";
	$_SESSION['Lien'] = "Page-DNS-AjoutDomaine.html";
	Redirect ('resultat.html');
}

$VerifExistence = $MySql->Count('id', 'domaineinterdit', "Adresse='{$_POST['Domaine']}'", '', '', '', '');
if ($VerifExistence >= 1) {
	$_SESSION['Resultat'] = "Ce nom de domaine ne vous appartient pas !";
	$_SESSION['Lien'] = "Page-DNS-AjoutDomaine.html";
	Redirect ('resultat.html');	
}

$VerifExistence = $MySql->Count('id', 'domainedns', "Domaine='{$_POST['Domaine']}'", '', '', '', '');
if ($VerifExistence >= 1) {
	$_SESSION['Resultat'] = "Ce nom de domaine existe deja sur Kelio";
	$_SESSION['Lien'] = "Page-DNS-AjoutDomaine.html";
	Redirect ('resultat.html');	
}

$CountDns = $MySql->Count('id', 'domainedns', "Utilisateur='{$_SESSION['Utilisateur']}'");
if ( ($_SESSION['Offre']['DomaineDns'] != '-1') and ($CountDns >= $_SESSION['Offre']['DomaineDns']) ) {
	$_SESSION['Resultat'] = "Votre offre ne vous permet pas d'ajouter plus de noms de domaine";
	$_SESSION['Lien'] = "Page-DNS-AjoutDomaine.html";
	Redirect ('resultat.html');
}

if($_POST['Mail'] == "autre")
	$Mail = $_POST['ServeurMail'];
else
	$Mail = $_POST['Mail'];

$conteneur = 'Domaine, Utilisateur, Racine, OpenBasedir, Mail, Commentaire, DateDeCreation, Status';
$contenu = "'{$_POST['Domaine']}', '{$_SESSION['Utilisateur']}', '{$_POST['Racine']}', '{$_POST['OpenBasedir']}', '{$Mail}', '{$Commentaire}', '".time()."', 1";
$MySql->Insert ($conteneur,$contenu, "domainedns");
Redirect ('Page-DNS-Recapitulatif.html');

?>
