<?php
// WHO'S THE FUCKING ASSHOLE ?
//////////////////////////////
require_once "head.php";
if (!logged_in()) die();

// DECLARATIONS
//////////////////////////////////////////////////
$email_admin = pg_fetch_result(r_exec('local',"select s_value from settings where s_name='email_nic'",false),0);
$id_user = $_SESSION['current_user'];
$status_ok = "#00ff00";				//
$status_ok_bg = "#005500";			// COULEURS POUR LES CASES DU HAUT
$status_ko = "#888888";				//
$nb_dns_max=8;					// NB DE SERVEURS DNS MAX QU'ON AFFICHE / ENREGISTRE
$aucun = "<center>--- Aucun contact s&#233;lectionn&#233; ---</center>";
$erreur=1; 					// ON CONSIDERE QUE LA PAGE EST A REMPLIR POUR EVITER D'ENREGISTRER DU VIDE
$max_op_visibles = 20;				// NOMBRE DE LIGNES DANS L'HISTORIQUE EN BAS DE PAGE
$edition = 0; 					// ON PART DU PRINCIPE QUE C'EST UN NOUVEAU POUR L'INSTANT //
$nb_jours_resto = 30;				// COMBIEN DE TEMPS UN DOMAINE RESTE RESTORABLE 


// SI DES VARIABLES DE SESSIONS EXISTENT PARCE QU'ON A ENREGISRTRE OU MODIFIE UN CONTACT ////
if (isset($_POST['new_from_domain']) || isset($_POST['update_and_dom']))
	{
		if (isset($_SESSION['dom_new_domain'])) $_POST['ndd'] = $_SESSION['dom_new_domain'];
		if (isset($_SESSION['dom_new_tit_id'])) $_POST['tit_id'] = $_SESSION['dom_new_tit_id'];
		if (isset($_SESSION['dom_new_adm_id'])) $_POST['adm_id'] = $_SESSION['dom_new_adm_id'];
		if (isset($_SESSION['dom_new_tec_id'])) $_POST['tec_id'] = $_SESSION['dom_new_tec_id'];
		if (isset($_SESSION['dom_new_reg_id'])) $_POST['reg_id'] = $_SESSION['dom_new_reg_id'];
		if (isset($_SESSION['dom_new_regname'])) $_POST['choix_reg'] = $_SESSION['dom_new_regname'];
		if (isset($_SESSION['dom_new_check_dnssec'])) $_POST['chek_dnssec'] = 'on';
		if (isset($_SESSION['dom_new_keytag']))	$_POST['keytag'] = $_SESSION['dom_new_keytag'];
		if (isset($_SESSION['dom_new_algorithm'])) $_POST['algorithm'] = $_SESSION['dom_new_algorithm'];
		if (isset($_SESSION['dom_new_digesttype'])) $_POST['digesttype'] = $_SESSION['dom_new_digesttype'];
		if (isset($_SESSION['dom_new_keydigest'])) $_POST['keydigest'] = $_SESSION['dom_new_keydigest'];
		if (isset($_SESSION['dom_new_dns1'])) $_POST['dns1'] = $_SESSION['dom_new_dns1'];
		if (isset($_SESSION['dom_new_dns2'])) $_POST['dns2'] = $_SESSION['dom_new_dns2'];
		if (isset($_SESSION['dom_new_dns3'])) $_POST['dns3'] = $_SESSION['dom_new_dns3'];
		if (isset($_SESSION['dom_new_dns4'])) $_POST['dns4'] = $_SESSION['dom_new_dns4'];
		if (isset($_SESSION['dom_new_dns5'])) $_POST['dns5'] = $_SESSION['dom_new_dns5'];
		if (isset($_SESSION['dom_new_dns6'])) $_POST['dns6'] = $_SESSION['dom_new_dns6'];
		if (isset($_SESSION['dom_new_dns7'])) $_POST['dns7'] = $_SESSION['dom_new_dns7'];
		if (isset($_SESSION['dom_new_dns8'])) $_POST['dns8'] = $_SESSION['dom_new_dns8'];
		if (isset($_SESSION['transfert'])) $_POST['tranfert'] = $_SESSION['transfert'];
		if (isset($_SESSION['reg_id'])) $_POST['reg_id'] = $_SESSION['reg_id'];
		if (isset($_SESSION['reg_id_old'])) $_POST['reg_id_old'] = $_SESSION['reg_id_old'];
		if (isset($_SESSION['tr_tit'])) $_POST['tr_tit'] = $_SESSION['tr_tit'];
		if (isset($_SESSION['tr_adm'])) $_POST['tr_adm'] = $_SESSION['tr_adm'];
		if (isset($_SESSION['tr_tec'])) $_POST['tr_tec'] = $_SESSION['tr_tec'];
	}
// ET SURTOUT ON EFFACE LES VARIABLES DE SESSION
unset($_SESSION['dom_new_tit']);
unset($_SESSION['dom_new_adm']);
unset($_SESSION['dom_new_tec']);
unset($_SESSION['dom_new_domain']);
unset($_SESSION['dom_new_tit_id']);
unset($_SESSION['dom_new_adm_id']);
unset($_SESSION['dom_new_tec_id']);
unset($_SESSION['dom_new_reg_id']);
unset($_SESSION['dom_new_regname']);
unset($_SESSION['dom_new_check_dnssec']);
unset($_SESSION['dom_new_keytag']);
unset($_SESSION['dom_new_algorithm']);
unset($_SESSION['dom_new_digesttype']);
unset($_SESSION['dom_new_keydigest']);
unset($_SESSION['dom_new_dns1']);
unset($_SESSION['dom_new_dns2']);
unset($_SESSION['dom_new_dns3']);
unset($_SESSION['dom_new_dns4']);
unset($_SESSION['dom_new_dns5']);
unset($_SESSION['dom_new_dns6']);
unset($_SESSION['dom_new_dns7']);
unset($_SESSION['dom_new_dns8']);
unset($_SESSION['transfert']);
unset($_SESSION['reg_id']);
unset($_SESSION['reg_id_old']);
unset($_SESSION['tr_tit']);
unset($_SESSION['tr_adm']);
unset($_SESSION['tr_tec']);

/////// Variables Recuperees dans le cas d'un enregistrement ou d'une mise a jour
/////////////////////////////////////////////////////////////////////////////////
if (isset($_GET['id'])) $id_domaine =  $_GET['id'];
	else if (isset($_POST['id_domaine'])) $id_domaine =  $_POST['id_domaine'];

$nom_registrar = $_POST['choix_reg'];
$id_registrar = $_POST['reg_id'];
$ndd = $_POST['ndd'];
if ($_POST['autorenew'] == 'on') $autorenew = 1;
	else $autorenew = 0;

if (isset($_POST['dns'.$i]))
	for ($i=1;$i<=$nb_dns_max;$i++)
		$tab[$i] = $_POST['dns'.$i];

if ($_POST['transfert'] == 'on')				////// UN TRANSFERT DIRECT EST DEMANDE	///////
	{							//
		$id_registrar_old = $_POST['reg_id_old'];	// 
		$nom_registrar_old = id2registrar($id_registrar_old);
		$nom_registrar_tr = $_POST['choix_reg'];
		unset($_POST['choix_reg']);		// CA c'est pour qu'on aille le chercher un peu plus bas dans la fichde du domaine		
	}

// 	ON REPREND LES RECUPS DE VARIABLE
//
$cont['tit']['id'] = $_POST['tit_id'];
$cont['adm']['id'] = $_POST['adm_id'];
$cont['tec']['id'] = $_POST['tec_id'];


if (isset($_POST['new_dom']) || isset($_POST['maj_dom']))
{
//	$nomOrigine = $_FILES['rci']['name'];
//	$elementsChemin = pathinfo($nomOrigine);
//	$extensionFichier = $elementsChemin['extension'];
//	$extensionsAutorisees = array("pdf", "jpeg", "jpg", "gif", "JPG");
//	$taille=filesize($_FILES["rci"]["tmp_name"]);
//	if (!(in_array($extensionFichier, $extensionsAutorisees)))
//      	$message = "Le fichier n'a pas l'extension attendue";
// 	else {
    		// Copie dans le repertoire
//    		$repertoireDestination = "upload/";
//    		$nomDestination = date("YmdHis");
///        	$nom_total=$repertoireDestination.$_POST['registrar']."-".date("YmdHis")."-".$_ndd."-RCI.".$extensionFichier;

 //   		if (move_uploaded_file($_FILES["rci"]["tmp_name"],$nom_total))
//			{
  //      			$message = "Votre demande a bien &#233;t&#233; enregistr&#233;e. Vous allez recevoir un email &#224; l'adresse <i>".$_POST['reg_email'];
//				$message .= "</i> Cliquez sur le lien contenu dans ce message pour valider votre demande.";
  //      			$message .= "<br>Elle sera trait&#233;e sous 48h.";
  //  			}
//         	else $message = "Le fichier n'a pas été uploadé (trop gros ?) ou le déplacement du fichier temporaire a échoué.<br> Vérifiez l'existence du répertoire ".$repertoireDestination;
//	}

// ANALYSE DE TOUS LES CHMPS PASSES EN PARAMETRE //
//
	if ($_SESSION['post_datas'] != $_POST)
	{
			$erreur = 0;
			$message = "Enregistrement impossible : ";
			// ON TESTE TOUS LES CHAMPS RENTRES
			//
			if ($_POST['transfert'] == 'on')
				{
					if ($nom_registrar_tr == '')
						{
							$erreur = 1;
							$message.= "Le destinataire du transfert n'est pas valide.";
						}
					if ($_POST['reg_id_old'] == $_POST['reg_id'])
						{
							$erreur = 1;
							$message.= "L'ancien et le nouveau bureau d'enregistrement sont identiques.";
						}
				}
			if (exist_domain(strtolower($_POST['ndd'])) && isset($_POST['new_dom']))
				{
					$erreur=1;
					$message.= " Ce domaine existe d&#233;j&#224;.";
				}
			else if (!syntaxe_ok(strtolower($_POST['ndd'])))
                               	{
                               	        $erreur=1;
			       	        $message.= " Erreur dans la syntaxe du domaine.";
                               	}
			else if (bsa_blocked(strtolower($_POST['ndd'])))
				{
					$erreur = 1;
					$message = " Ce domaine est bloqu&#233; par Brand Safety Alliance.";
				}	
			else if (!registrar($_POST['reg_id']))
				{
					$erreur=1;
        	        		$message.= " Probl&#233;me avec le bureau d'enregistrement (Id#".$_POST['reg_id'].").";
                	      	}
			else if (!exist_contact($_POST['tit_hdl']))
	                       	{
        	                       	$erreur=1;
                			$message.= " Probl&#233;me avec le titulaire.";
               			}
			else if (!exist_contact($_POST['adm_hdl']))
                        	{
					$erreur=1;
        	                	$message.= " Probl&#233;me avec le contact administratif.";
	    			}
			else if (!exist_contact($_POST['tec_hdl']))
                              	{
                		       	$erreur=1;
        	                	$message.= " Probl&#233;me avec le contact technique.";
	                 	}
			else if(!reg_contact($_POST['reg_id'],$_POST['tit_id']) && $_POST['tr_tit'] !='on')
				{
					$erreur=1;
					$message.= " Le titulaire n'est pas g&#233;r&#233; par ce bureau d'enregistrement.";
				}
			else if(!reg_contact($_POST['reg_id'],$_POST['adm_id']) && $_POST['tr_adm'] !='on')
				{
					$erreur=1;
					$message.= " Le contact administratif n'est pas g&#233;r&#233; par ce bureau d'enregistrement.";
				}
			else if(!reg_contact($_POST['reg_id'],$_POST['tec_id']) && $_POST['tr_tec'] !='on')
				{
					$erreur=1;
					$message.= " Le contact technique n'est pas g&#233;r&#233; par ce bureau d'enregistrement.";
				}
			else if(dns_doublon($_POST['dns1'],$_POST['dns2'],$_POST['dns3'],$_POST['dns4'],$_POST['dns5'],$_POST['dns6'],$_POST['dns7'],$_POST['dns8']))
				{
					$erreur=1;
					$message.= "Il ne peut pas y avoir deux serveurs DNS identiques.";
				}
			else if (isset($_POST['expiration']) && !verif_date($_POST['expiration']))
				{
					$erreur = 1;
					$message.= " Le format de la date d'expiration est incorrect.";
				}
			else if($_POST['check_dnssec'] == 'on')
				{
					if (!ctype_xdigit($_POST['keydigest']) || !is_numeric($_POST['keytag']))
						{
							$erreur = 1;
							$message.= "Les valeurss DNSSEC sont incorrectes.";
						}
				}
			else
				{
					for($dns_n=1;$dns_n<=$nb_dns_max;$dns_n++)
						{
							if ($_POST['dns'.$dns_n] != '')
								if(!dns_ok(strtolower($_POST['dns'.$dns_n])))
									{
										$erreur = 1;
										if (isset($dns_error)) $dns_error .=",";
											$dns_error .= " #".$dns_n;
									}
						}
					if (isset($dns_error)) $message.= " Erreur sur le(s) serveur(s) DNS suivant(s) : ".$dns_error;
				}
//
// FIN ANALYSE DES CHAMPS

		if ($erreur == 0)  /// TOUT EST NICKEL ON ENREGISTRE
			{
				if ($_POST['maj_dom'])    //////////// C'EST UNE MISE A JOUR ////////////////////////////
                                        {
                                                $object_id = $id_domaine;
						
                                                // ON VA CHERCHER LES ANCIENNES INFOS POUR SAVOIR CE QU'ON MET A JOUR
                                                //////
                                                $req ="select concat(d_nom, nom_extension),id_registrar,to_char(d_date_expiration, 'dd-mm-yyyy'),d_auto_renew from domaine,domaine_extension";
						$req.=" where domaine.id_extension=domaine_extension.id_extension and id_domaine=".$id_domaine;
						$data = pg_fetch_array(r_exec('local',$req,false));					
						$ancien_ndd = $data[0];
						$ancien_reg = $data[1];
						$ancien_exp = $data[2];
						$ancien_auto = $data['d_auto_renew'];
						$dns = "select nameserver from nameserver, dns_domain where dns_domain.id_domaine=".$id_domaine." and dns_domain.id_nameserver=nameserver.id_nameserver order by ordre";
						$res_dns = r_exec('local',$dns,false);
                        			$i=1;
                        			while ($tab_dns = pg_fetch_array($res_dns))
                                			{
                                        			$tab_ancien[$i] = $tab_dns['nameserver'];
                        		       			$i++;
                                			}	
						
						$cherche_contacts = "select dom_contacts.id_contact,type_contact,nichandle from dom_contacts,contact";
                        			$cherche_contacts .=" where id_domaine=".$id_domaine." and dom_contacts.id_contact=contact.id_contact";
						$res_cont = r_exec('local',$cherche_contacts,false);
                        			while ($conts = pg_fetch_assoc($res_cont))
                                        		{
                                                		if ($conts['type_contact'] == 1) $gars ='tit';
                                                       			else if ($conts['type_contact'] == 3) $gars = 'adm';
                                                               			else $gars ='tec';
                                                		$cont[$gars]['nichandle'] = $conts['nichandle'];
							}
						$sec = pg_fetch_row(r_exec("local","select keytag,algorithm,digest_type,key_digest from dnssec where id_dom=".$id_domaine,false));
						if ($sec)
                                			{
                                        			$dnssec_old['keytag'] = $sec[0];
                                        			$dnssec_old['algorithm'] = $sec[1];
                                        			$dnssec_old['digesttype'] = $sec[2];
                                        			$dnssec_old['keydigest'] = $sec[3];
                                			}

					}

				else    $object_id = -1; /////////////// C'EST UN NOUVEAU ///////////////////

	//			$parent_id = new_parent_id('domaine',$object_id,$id_user);
	//			$opid=create_OPID();

                                //enregistrement des infos SI MISE A JOUR
				if ($_POST['maj_dom'])
					{
						// CHECK SI LE NDD A CHANGE. CA PEUT ARRIVER SUITE A UNE ERREUR DE SAISIE
						//
	//					if ($ancien_ndd!=$ndd) request('domaine','ndd',$object_id,$ancien_ndd,$ndd,$parent_id,$opid,$id_user,$id_registrar);
						//
						// DUPLICATION EVENTUELLE DES CONTACTS EN CAS DE CHGT DE REGISTRAR
						//
						if ($_POST['tr_tit'] == 'on')
							{
								// copier contact titulaire
								$cont['tit']['id']= contact_copy($_POST['tit_id'],$id_registrar,$id_user);
								$new_tit_hdl = id2nchdl($cont['tit']['id'],'contact');
							}
						if ($_POST['tr_adm'] == 'on')
							{
								if ($_POST['tr_tit'] == 'on' && $_POST['adm_hdl'] == $_POST['tit_hdl'])
									{
										$cont['adm']['id'] = $cont['tit']['id'];
										$new_adm_hdl = $new_tit_hdl;
									}
								else
									{
										$cont['adm']['id'] = contact_copy($_POST['adm_id'],$id_registrar,$id_user);
										$new_adm_hdl = id2nchdl($cont['adm']['id'],'contact');
									}
							}
						if ($_POST['tr_tec'] == 'on')
							{
								if ($_POST['tr_tit'] == 'on' && $_POST['tec_hdl'] == $_POST['tit_hdl'])
									{
										$cont['tec']['id'] = $cont['tit']['id'];
										$new_tec_hdl = $new_tit_hdl;
									}
								else if ($_POST['tr_adm'] == 'on' && $_POST['tec_hdl'] == $_POST['adm_hdl'])
									{
										$cont['tec']['id'] = $cont['adm']['id'];
										$new_tec_hdl = $new_adm_hdl;
									}
								else
									{
										$cont['tec']['id'] = contact_copy($_POST['tec_id'],$id_registrar,$id_user);
										$new_tec_hdl = id2nchdl($cont['tec']['id'],'contact');
									}
							}
						if (isset($new_tit_hdl)) $_POST['tit_hdl'] = $new_tit_hdl;
						if (isset($new_adm_hdl)) $_POST['adm_hdl'] = $new_adm_hdl;
						if (isset($new_tec_hdl)) $_POST['tec_hdl'] = $new_tec_hdl;
						// FIN DUPLICATION DES CONTACTS
						//
						//
						$parent_id = new_parent_id('domaine',$object_id,$id_user);
						$opid=create_OPID();

						// CHECK SI LE NDD A CHANGE. CA PEUT ARRIVER SUITE A UNE ERREUR DE SAISIE
						//
						if ($ancien_ndd!=$ndd) request('domaine','ndd',$object_id,$ancien_ndd,$ndd,$parent_id,$opid,$id_user,$id_registrar);

						// CHECK SI TRANSFERT DE REGISTRAR ET/OU CHAGNGEMENT EXPIRATION
						if ($ancien_reg!=$_POST['reg_id'])
							{
								request('domaine','registrar',$object_id,$ancien_reg,$_POST['reg_id'],$parent_id,$opid,$id_user,$id_registrar);
								if ($ancien_exp!=$_POST['expiration']) // SI DATE CHANGEE AUSSI ON SUPPOSE QU'IL  Y A UNE RAISON DONC ON FAIT
									request('domaine','expiration',$object_id,$ancien_exp,date("Y-m-d",strtotime($_POST['expiration'])),$parent_id,$opid,$id_user,$id_registrar);
								else	// SINON PAR DEFAUT ON RAJOUTE UN AN
									{
										$new_exp = date('d-m-Y',mktime(0, 0, 0, date("m"), date("d"),   date("Y")+1));
										request('domaine','expiration',$object_id,$ancien_exp,date("Y-m-d",strtotime($new_exp)),$parent_id,$opid,$id_user,$id_registrar);
									}
							}
							else if ($ancien_exp!=$_POST['expiration'])  // SEULE L'EXPIRATION CHANGE, PAS LE RGISTRAR DONC ON FAIT AUSSI CE QUI EST DEMANDE
								request('domaine','expiration',$object_id,$ancien_exp,date("Y-m-d",strtotime($_POST['expiration'])),$parent_id,$opid,$id_user,$id_registrar);

					//	if ($ancien_reg!=$_POST['reg_id']) request('domaine','registrar',$object_id,$ancien_reg,$_POST['reg_id'],$parent_id,$opid,$id_user,$id_registrar);
					//	if ($ancien_exp!=$_POST['expiration']) request('domaine','expiration',$object_id,$ancien_exp,date("Y-m-d",strtotime($_POST['expiration'])),$parent_id,$opid,$id_user,$id_registrar);
						if ($ancien_auto!=$autorenew) request('domaine','autorenew',$object_id,$ancien_auto,$autorenew,$parent_id,$opid,$id_user,$id_registrar);
						if ($id_domaine && $cont['tit']['nichandle']!=$_POST['tit_hdl']) request('domaine','tit',$object_id,$cont['tit']['nichandle'],$_POST['tit_hdl'],$parent_id,$opid,$id_user,$id_registrar);
						if ($id_domaine && $cont['adm']['nichandle']!=$_POST['adm_hdl']) request('domaine','adm',$object_id,$cont['adm']['nichandle'],$_POST['adm_hdl'],$parent_id,$opid,$id_user,$id_registrar);
						if ($id_domaine && $cont['tec']['nichandle']!=$_POST['tec_hdl']) request('domaine','tec',$object_id,$cont['tec']['nichandle'],$_POST['tec_hdl'],$parent_id,$opid,$id_user,$id_registrar);
						if ($_POST['check_dnssec'] == 'on')
							{
								if ($dnssec_old['keytag'] != $_POST['keytag']) request('domaine','keytag',$object_id,$dnssec_old['keytag'],$_POST['keytag'],$parent_id,$opid,$id_user,$id_registrar);
								if ($dnssec_old['algorithm'] != $_POST['algorithm']) request('domaine','algorithm',$object_id,$dnssec_old['algorithm'],$_POST['algorithm'],$parent_id,$opid,$id_user,$id_registrar);
								if ($dnssec_old['digesttype'] != $_POST['digesttype']) request('domaine','digesttype',$object_id,$dnssec_old['digesttype'],$_POST['digesttype'],$parent_id,$opid,$id_user,$id_registrar);
								if ($dnssec_old['keydigest'] != $_POST['keydigest']) request('domaine','keydigest',$object_id,$dnssec_old['keydigest'],$_POST['keydigest'],$parent_id,$opid,$id_user,$id_registrar);
							}
							else if ($_POST['dnssec_check'] != 'on' && $dnssec_old['keydigest'] != '')
								{
									request('domaine','keytag',$object_id,$dnssec_old['keytag'],0,$parent_id,$opid,$id_user,$id_registrar);
									request('domaine','algorithm',$object_id,$dnssec_old['algorithm'],0,$parent_id,$opid,$id_user,$id_registrar);
									request('domaine','digesttype',$object_id,$dnssec_old['digesttype'],0,$parent_id,$opid,$id_user,$id_registrar);
									request('domaine','keydigest',$object_id,$dnssec_old['keydigest'],'off',$parent_id,$opid,$id_user,$id_registrar);
								}
						for ($i=1;$i<=$nb_dns_max;$i++)
				       			if ($tab_ancien[$i] !=$tab[$i]) request('domaine','DNS'.$i,$object_id,$tab_ancien[$i],$tab[$i],$parent_id,$opid,$id_user,$id_registrar);

						// On efface les variables contenant les infos eventuelles de transfert apres l'enregistrement
						//
						unset($_POST['transfert']);
						unset($_POST['choix_reg']);
						unset($_POST['tr_tit']);
						unset($_POST['tr_adm']);
						unset($_POST['tr_tec']);

						//////////////////// ENREGISTREMENT SI ADMIN ///////////////
						 if (admin($id_user))
                        				{
                                				$message = "Probl&#232;me dans la mise &#224; jour de ce domaine (#".$opid."). Erreur #";
                                				if (domain_update($opid) == 1)
                                        				if (update_pending_request($opid,'1'))
                                                				if (log_request($opid))
                                                                			$message= "Le domaine vient d'&#234;tre mis &#224; jour. Une relance DNS est peut-&#234;tre n&#233;cessaire (#".$opid.").";
                                                				else $message .="3";
                                        				else $message .="2";
                                				else $message .="1";
								$message.= $_SESSION['exec_message'];
                        				}
                				else 
							{
								$message = "Votre demande de mise &#224; jour a &#233;t&#233; prise en compte (#".$opid.")";
								$sujet_demande = "[Demande modification domaine] ".$ndd."(#".$opid.")";
								$texte_demande .= "Bonjour,<br><br>";
								$texte_demande .= $_SESSION['current_firstname']." ".$_SESSION['current_name']." a effectu&#233; une demande de modification pour le domaine ".$ndd."<br><br>";
								$texte_demande .= " Cette requ&#234;te doit &#234;tre v&#233;rifi&#233;e et valid&#233;e par un administrateur.<br><br>";
								envoi_mail($texte_demande,$sujet_demande,$email_admin,$opid,"Demande MAJ",$id_domaine);
							}
						///////////////////// FIN ENREGISTREMENT SI ADMIN //////////////////
					}
				else
					{	// Enregistrement des infos si nouveau
						//
						$parent_id = new_parent_id('domaine',$object_id,$id_user);
						$opid=create_OPID();

                                		request('domaine','ndd',$object_id,'',$ndd,$parent_id,$opid,$id_user,$id_registrar);
						request('domaine','autorenew',$object_id,'',$autorenew,$parent_id,$opid,$id_user,$id_registrar);
						request('domaine','registrar',$object_id,'',$_POST['reg_id'],$parent_id,$opid,$id_user,$id_registrar);
                                		request('domaine','tit',$object_id,'',$_POST['tit_hdl'],$parent_id,$opid,$id_user,$id_registrar);
                                		request('domaine','adm',$object_id,'',$_POST['adm_hdl'],$parent_id,$opid,$id_user,$id_registrar);
                                		request('domaine','tec',$object_id,'',$_POST['tec_hdl'],$parent_id,$opid,$id_user,$id_registrar);
						if ($_POST['check_dnssec'] == 'on')
               						{
								request('domaine','keytag',$object_id,'',$_POST['keytag'],$parent_id,$opid,$id_user,$id_registrar);
								request('domaine','algorithm',$object_id,'',$_POST['algorithm'],$parent_id,$opid,$id_user,$id_registrar);
                      						request('domaine','digesttype',$object_id,'',$_POST['digesttype'],$parent_id,$opid,$id_user,$id_registrar);
             							request('domaine','keydigest',$object_id,'',$_POST['keydigest'],$parent_id,$opid,$id_user,$id_registrar);
     							}

                                		request('domaine','rci',$object_id,'',$nom_total,$parent_id,$opid,$id_user,$id_registrar);
						request('domaine','status',$object_id,'',1,$parent_id,$opid,$id_user,$id_registrar);

                                		$i=1;
                                		for ($j=1;$j<=$nb_dns_max;$j++)
                                                	if ($_POST['dns'.$j])
                                                        	{
              								request('domaine','DNS'.$i,$object_id,'',$_POST['dns'.$j],$parent_id,$opid,$id_user,$id_registrar);
                                                                	$i++;
                                                        	}
						//////////////////// ENREGISTREMENT SI ADMIN ///////////////
						if (admin($id_user))
							{
                                				$message = "Probl&#232;me dans la cr&#233;ation de ce domaine (#".$opid."). Erreur #";
                                     				if (domain_create($opid) == 1)
                                                       			if (update_pending_request($opid,'1'))
                                                                        	if (log_request($opid))
											{
												$req = "select id_domaine from domaine,domaine_extension where domaine.id_extension=domaine_extension.id_extension";
												$req.= " and concat(d_nom,nom_extension)='".$ndd."' and id_status=1";
												$new_id = pg_fetch_array(r_exec('local',$req,false));
												$id_domaine = $new_id[0];
	           										$message= "Le domaine vient d'&#234;tre enregistr&#233;. Une relance DNS est peut-&#234;tre n&#233;cessaire (#".$opid.").";
												$edition = 1;
											}
                                                                                else $message .="3";
                                                                        else $message .="2";
                                                                else $message .="1";
                                                        }
						else
							{
								$message = "La demande d'enregistrement du domaine ".$_ndd." a &#233;t&#233; prise en compte (#".$opid.").";
                                                                $sujet_demande = "[Demande enregistrement domaine] ".$ndd."(#".$opid.")";
                                                                $texte_demande .= "Bonjour,<br><br>";
                                                                $texte_demande .= $_SESSION['current_firstname']." ".$_SESSION['current_name']." a effectu&#233; une demande d'enregistrement pour le domaine ".$ndd."<br><br>";
                                                                $texte_demande .= " Cette requ&#234;te doit &#234;tre v&#233;rifi&#233;e et valid&#233;e par un administrateur.<br><br>";
                                                                envoi_mail($texte_demande,$sujet_demande,$email_admin,$opid,"Demande NEW",$id_domaine);
							}
                                                ///////////////////// FIN ENREGISTREMENT SI ADMIN //////////////////
					}
                                $_SESSION['post_datas'] = $_POST;
			}   // FIN DU IF ERRUER=0
	} // FIN DU IF SESSION POSTDATA
}  //FIN DU IF NEW_DOM OU MAJ_DOM

if (isset($_POST['activer']) || isset($_POST['bloquer']) || isset($_POST['geler']) || isset($_POST['supprimer']) || isset($_POST['archiver'])) ////////////////////////////// SI ON CHANGE L ETAT DU DOMAINE  ////////////////////////
{
	$parent_id = new_parent_id('domaine',$id_domaine,$id_user);
	$opid=create_OPID();

	if ($_POST['activer'])  // ON REACTIVE LE DOMAINE MAIS ON TESTE TOUT CE QU'ON PEUT AVANT
	{
		$new = 1;
		$state = "Activ&#233;";

		// CONTROLE INTEGRITE DES CHAMPS 1A FAIRE ///////
		/////////////////////////////////////////////////

		$ancien_exp = pg_fetch_result(r_exec('local',"select d_date_expiration from domaine where id_domaine=".$id_domaine,false),0);		
		if (in_array($_POST['id_status'],array(4,6)))
			{
				if ($ancien_exp <= date('Y-m-d'))
					{
						$new_exp = date('Y-m-d', strtotime($ancien_exp.' +1 year'));							// ON AJOUTE UN AN UNIQUEMENT SI DATE DEPASSEE
						request('domaine','expiration',$id_domaine,$ancien_exp,$new_exp,$parent_id,$opid,$id_user,$id_registrar);	// ON FACTURE RENOUVELLEMENT EN PLUS DE RESTAURATION
					}
			}
	}
	if ($_POST['geler'])
	{
		$new = 2;
		$state = "Gel&#233;";
	}
	if ($_POST['bloquer'])
        {
                $new = 3;
		$state = "Bloqu&#233;";
        }
	if ($_POST['supprimer'])
        {
                $new = 4;
		$state = "En r&#233;demption";
        }
	if ($_POST['archiver'])
	{
		$new = 99;
		$state = "Archiv&#233;";
	}

	if (request('domaine','status',$id_domaine,$_POST['id_status'],$new,$parent_id,$opid,$id_user,$id_registrar))
		if (admin($id_user)) //// EN FONCTION DE QUI EST CONNECTE ON FAIT DIRECT OU CA PASSE EN DEMANDE ////
			{
                        	$message = "Probl&#232;me dans le changement d'&#233;tat de ce domaine (#".$opid."). Erreur #";
                                        if (domain_update($opid) == 1)
                                                if (update_pending_request($opid,'1'))
                                                        if (log_request($opid))
                                                                {
									$message = "Le domaine est pass&#233; &#224; l'&#233;tat : ".$state.".<br>";
									$message .= "Une mise &#224; jour DNS est peut-&#234;tre n&#233;cessaire pour prendre en compte la modification.";
									if ($new == 1 && $ancien_exp < date('Y-m-d'))
										$message .= "<br><br>ATTENTION !!! La date d'expiration &#233;tait d&#233;pass&#233;e et a &#233;t&#233; &#233;tendue.";
									if ($new == 4)
										if (cancel_renew($id_domaine))
											$message.="<br> Le renouvellement a &#233;t&#233; annul&#233;.";
								}
                                                        else $message .= 3;
                                                else $message .= 2;
                                        else $message .= 1;
                                }
                        else 		// ON N'EST PAS ADMIN - CA PASSE EN DEMANDE
				{
					$message = "Votre demande de changement d'&#233;tat a &#233;t&#233; prise en compte (#".$opid.").";
					$sujet_demande = "[Demande modification statut] ".$ndd."(#".$opid.")";
					$texte_demande .= "Bonjour,<br><br>";
					$texte_demande .= $_SESSION['current_firstname']." ".$_SESSION['current_name']." a effectu&#233; une demande de changement de statut pour le domaine ".$ndd."<br><br>";
					$texte_demande .= " Cette requ&#234;te doit &#234;tre v&#233;rifi&#233;e et valid&#233;e par un administrateur.";
					envoi_mail($texte_demande,$sujet_demande,$email_admin,$opid,"Demande etat",$id_domaine);
				}
}	////////////////////////////////////////////// FIN CHANGEMENT ETAT ///////////////////////////////////////

if (isset($_POST['renew_1y']))	///////////////////// RENOUVELLEMENT POUR UN AN //////////////////////////////////
{
	$parent_id = new_parent_id('domaine',$id_domaine,$id_user);
	$opid=create_OPID();
	$req = "select to_char(d_date_expiration, 'dd'),to_char(d_date_expiration,'mm'),to_char(d_date_expiration,'yyyy') from domaine where id_domaine=".$id_domaine;
	$ancien = pg_fetch_row(r_exec('local',$req,false));
	if (request('domaine','renew',$id_domaine,$ancien[0]."-".$ancien[1]."-".$ancien[2],intval($ancien[2]+1)."-".$ancien[1]."-".$ancien[0],$parent_id,$opid,$id_user,$id_registrar));
		if (admin($id_user)) //// EN FONCTION DE QUI EST CONNECTE ON FAIT DIRECT OU CA PASSE EN DEMANDE ////
			{
				$message = "Probl&#232;me avec le renouvellement de ce domaine (#".$opid."). Erreur #";
					if (domain_update($opid) == 1)
						if (update_pending_request($opid,'1'))
							if (log_request($opid))
								{
									$message = "Le renouvellement de ce domaine a bien &#233;t&#233; effectu&#233;.<br>";
								}
							else $message .= 3;
						else $message .= 2;
					else $message .= 1;
			}

		else						// ON N'EST PAS ADMIN - CA PASSE EN DEMANDE
			$message = "Votre demande de renouvellement a &#233;t&#233; prise en compte (#".$opid.").";

}	///////////////////////////////////////////// FIN RENOUVELLEMENT UN AN ///////////////////////////////////

if ($id_domaine) // C'EST DONC UNE EDITION PAS UN NOUVEAU
	{
		$edition=1;			
		$req ="select d_nom,nom_extension,id_status, d_date_enregistrement,d_date_expiration,registrar.id_registrar,nichandle,designation,id_domaine,d_auto_renew from domaine,domaine_extension,registrar";
		$req.=" where id_domaine=".$id_domaine." and domaine.id_extension=domaine_extension.id_extension and domaine.id_registrar=registrar.id_registrar";
		$dom = pg_fetch_array(r_exec('local',$req,false));
		$ndd=$dom[0].$dom[1];

		// SI ON VIENT DE CRRER UN CONTACT SUR UN DOMAINE EXISTANT - ON VA PAS CHERCHER CELUI QUI EST ENCROE DANS LA BASE
		if (!isset($_POST['reg_id'])) $id_registrar = $dom['id_registrar'];
		if (!isset($_POST['choix_reg'])) $nom_registrar = $dom['designation'];

		// Y'A T IL DES FACTURES NON PAYEES ?
		$payment_delay = pg_fetch_result(r_exec("local","select s_value from settings where s_name='payment_delay'",false),0);
		$retard_paiement = pg_fetch_result(r_exec("local","select count(invoice_number) from invoices where id_registrar=".$id_registrar." and status=0 and invoice_date <current_date -".$payment_delay,false),0);
		$status_registrar = pg_fetch_result(r_exec("local","select valid from registrar where id_registrar=".$id_registrar,false),0);
		if ($status_registrar == 2) $message.="ATTENTION !!! Le bureau d'enregistrement de ce domaine est gel&#233;. Ses domaines fonctionnent toujours mais aucune op&#233;ration ne peut &#234;tre effectu&#233;e.";
		else if ($status_registrar == 3) $message.="ATTENTION !!! Le bureau d'enregistrement de ce domaine est bloqu&#233;. Tous ses domaines sont inactifs et aucune op&#233;ration ne peut &#234;tre effectu&#233;e.";
			else if ($retard_paiement >0) $message.="<br>ATTENTION !!! Le bureau d'enregistrement de ce domaine a ".$retard_paiement." facture(s) en retard de paiement. Les op&#233;rations sur ce domaine sont limit&#233;es.<br>";

		// RECHERCHE DNSSEC
		$sec = pg_fetch_row(r_exec("local","select keytag,algorithm,digest_type,key_digest from dnssec where id_dom=".$id_domaine,false));
		if ($sec)
			{
				$dnssec_old['keytag'] = $sec[0];
				$dnssec_old['algorithm'] = $sec[1];
				$dnssec_old['digesttype'] = $sec[2];
				$dnssec_old['keydigest'] = $sec[3];
			}
		$dns = "select nameserver from nameserver, dns_domain where dns_domain.id_domaine=".$id_domaine." and dns_domain.id_nameserver=nameserver.id_nameserver order by ordre";
		$res_dns = r_exec('local',$dns,false);
		$i=1;
		while ($tab_dns = pg_fetch_array($res_dns))
			{
				$tab[$i] = $tab_dns['nameserver'];
				$i++;
			}

		// recherche detail contacts
	
		$cherche_contacts = "select dom_contacts.id_contact,type_contact from dom_contacts";
		$cherche_contacts .=" where id_domaine=".$id_domaine;
		$res_cont = r_exec('local',$cherche_contacts,false);
                while ($conts = pg_fetch_assoc($res_cont))
                	{
                        	if ($conts['type_contact'] == 1) $gars = 'tit';
                                	else if ($conts['type_contact'] == 3) $gars = 'adm';
                                        	else $gars ='tec';
				if (!isset($cont[$gars]['id']))
					$cont[$gars]['id'] = $conts['id_contact'];
                 	}

		// Recherche date du dernier etat dans l'historique //////////////////////////
		$req = "select timestamp_check from request_log where object_id=".$id_domaine." and status in (1,11,21) and object='domaine' and field='status' and value_new='".$dom['id_status']."'";
		$req.= "order by timestamp_check desc limit 1";
		$date_last_state = pg_fetch_row(r_exec('local',$req,false));
		if (!$date_last_state) $date_last_state[0] = $dom['d_date_enregistrement'];

		// Recherche date derniere MAJ dans l'historique //////////////////////////
                $req = "select timestamp_check from request_log where object_id=".$id_domaine." and object='domaine' order by timestamp_check desc limit 1";
                $date_last_MAJ = pg_fetch_row(r_exec('local',$req,false));
		if (!$date_last_MAJ) $date_last_MAJ[0] = $dom['d_date_enregistrement'];

		// ON VERIFIE SI DES DEMANDES SONT EN COURS SUR CE DOMAINE
		$nb_demandes = pg_fetch_result(r_exec('remote',"select count(opid) from pending where object='domaine' and object_id=".$id_domaine." and status=0",false),0);
		if ($nb_demandes > 0 && !isset($message))
			{
			//	if (isset($message)) $message.="<br>";
				$message = "<b>Attention !</b> Il y a ".$nb_demandes." demande";
				if ($nb_demandes > 1) $message.="s";
				$message .= " en cours sur ce domaine.";
			}

	} // Fin if ($id_domaine)

	/// ON CHERCHE LES CONTACTS SI ON EST DANS LE CAS D'UN ENREGISTREMENT MAIS QU'UNE ERREUR A ETE DETECTEE ($erreur = 1)
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	if (isset($cont['tit']['id'])) $tab_c[0] = $cont['tit']['id'];	
	if (isset($cont['adm']['id'])) $tab_c[1] = $cont['adm']['id'];
	if (isset($cont['tec']['id'])) $tab_c[2] = $cont['tec']['id'];

	for ($i=0;$i<3;$i++)
		{
			if ($tab_c[$i] !='')
				{
					$cherche_contacts = "select id_contact,nichandle,nom,prenom,societe,adresse1,adresse2,cp,ville,email,tel1,tel2,desc_pays from contact,pays";
					$cherche_contacts .=" where id_contact=".$tab_c[$i]." and contact.code_pays=pays.code_pays";
					$res_cont = r_exec('local',$cherche_contacts,false);
					while ($conts = pg_fetch_assoc($res_cont))
	                        		{
              	                        		if ($i==0) $gars ='tit';
                      	                       			else if ($i==1) $gars = 'adm';
                              	                       			else $gars = 'tec';
                                    			$cont[$gars]['nom'] = $conts['nom'].' '.$conts['prenom'];
        						$cont[$gars]['societe'] = $conts['societe'];
                               	        		$cont[$gars]['nichandle'] = $conts['nichandle'];
                                       			$cont[$gars]['adr1'] = $conts['adresse1'];
							$cont[$gars]['adr2'] = $conts['adresse2'];
                                        		$cont[$gars]['ville'] = $conts['cp'].' '.$conts['ville'];
                                        		$cont[$gars]['pays'] = $conts['desc_pays'];
                                        		$cont[$gars]['tel'] = $conts['tel1'].' '.$conts['tel2'];
                                        		$cont[$gars]['email'] = $conts['email'];
                      				}
				}
		}

	// SI DES VALEURS DNSSEC ONT ETE PASSEES ON LES RECUPERE - PAS PROPRE, DEFINITVEMENT TOUT LE CODE DE CETTE PAGE EST A REPRENDRE :(
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	if (isset($_POST['keytag'])) $dnssec_old['keytag'] = $_POST['keytag'];
	if (isset($_POST['algorithm'])) $dnssec_old['algorithm'] = $_POST['algorithm'];
	if (isset($_POST['digesttype'])) $dnssec_old['digesttype'] = $_POST['digesttype'];
	if (isset($_POST['keydigest'])) $dnssec_old['keydigest'] = $_POST['keydigest'];


// ON ATTAQUE L'AFFICHAGE /////////////////
///////////////////////////////////////////

?>
<head>
<link type="text/css" href="jquery-ui/css/smoothness/jquery-ui-1.10.3.custom.css" rel="stylesheet" />
<script language="javascript">
function act_autorenew()
{
	var checkbox = document.getElementById("autorenew");
	var a1 = document.getElementById("renew_1y");
	var expiration = <? if ($dom['d_date_expiration'] >= date('Y-m-d',strtotime('+1 year'))) echo "0"; else echo "1"; ?>;

	if (expiration == 1)
	{
		if (checkbox.checked)
			a1.disabled=true;
		else
			a1.disabled=false;
	}
}

function act_transfert()
{
	var checkBox = document.getElementById("transfert");
	var t1 = document.getElementById("choix_reg");
	var t2 = document.getElementById("tr_tit");
	var t3 = document.getElementById("tr_adm");
	var t4 = document.getElementById("tr_tec");
	var reg = document.getElementById("reg_id");

	if (checkBox.checked){
			t1.disabled=false;
			t2.disabled=false;
			t3.disabled=false;
			t4.disabled=false;


	}

	else	{
			t1.disabled=true;
			t2.disabled=true;
			t3.disabled=true;
			t4.disabled=true;
			reg_id.value=reg_id_old.value;
		}
}

function check_contact(qui)
{
	var checkBox = document.getElementById('tr_'+qui);
	var t1 = document.getElementById('rec_'+qui+'_nom');
	var t2 = document.getElementById('rec_'+qui+'_hdl');
	var t3 = document.getElementById(qui+'_edit');	
	var t4 = document.getElementById(qui+'_create');

	if (checkBox.checked)
		{
			document.getElementById('dup_' + qui).style.display = true ? '' : 'none';
			t1.disabled = true;
			t2.disabled = true;
			t3.disabled = true;
			t4.disabled = true;
		}
	else
		{
			document.getElementById('dup_' + qui).style.display = false ? '' : 'none';
			t1.disabled = false;
			t2.disabled = false;
			t3.disabled = false;
			t4.disabled = false;
		}
}
function act_dnssec()
{
        var checkBox = document.getElementById("check_dnssec");
        var t1 = document.getElementById("keytag");
	var t2 = document.getElementById("algorithm");
	var t3 = document.getElementById("digesttype");
	var t4 = document.getElementById("keydigest");


        if (checkBox.checked){
                t1.value='<? echo $dnssec_old['keytag'] ?>';
                t1.disabled=false;
		t2.value='<? echo $dnssec_old['algorithm'] ?>';
                t2.disabled=false;
		t3.value='<? echo $dnssec_old['digesttype'] ?>';
                t3.disabled=false;
		t4.value='<? echo $dnssec_old['keydigest'] ?>';
                t4.disabled=false;
        }

        else    {
                t1.disabled = true;
		t2.disabled = true;
		t3.disabled = true;
		t4.disabled = true;
        }
}
function verif_ndd()
{
        var ndd = document.getElementById("ndd").value;
        var exist_ndd = document.getElementById("exist_ndd");
        if (ndd !== "")
        {
                // Effectue une requête AJAX pour vérifier si le nom existe dans la base de données
                var xhr = new XMLHttpRequest();
                xhr.onreadystatechange = function()
                {
                        if (xhr.readyState === 4 && xhr.status === 200)
                                {
                                        exist_ndd.innerHTML = xhr.responseText;
                                }
                };
                xhr.open("GET", "scripts/exist_ndd.php?ndd=" + ndd, true);
                xhr.send();
        }
        else
        {
                exist_ndd.innerHTML = "Veuillez indiquer le nom de domaine !";
        }
}
</script>
</head>
<?

// ON COMMENCE L'AFFICHAGE
$titre = "Gestion > Enregistrer un nom de domaine";
if ($dom['id_status'] >90) $titre = "Archives > D&#233;tail nom de domaine";

//      AFFICHAGE TITRE ET MESSAGE      //
titre($titre);
if (isset($message)) info($message);

$bg_c_1 ="#bbbbbb";

if ($dom['id_status'] >90)
{
	$bg_2 = "#dddd88";
	$bg_c_2 ="#ffff99";
}
else 
	$bg_c_2 ="#ffbfbf";

$bgcolor=$bg_2;
?>
<br>
<center>
<table border=0 width=75% cellpadding=10 cellspacing=0>
<form name=dns_enreg method=post action="choix.php" autocomplete="off" enctype="multipart/form-data">
<input type=hidden name=id value=<?php echo $id_domaine ?>>

<?
if ($edition == 1)
{
	if ($bgcolor==$bg_2) $bgcolor=$bg_1; else $bgcolor=$bg_2; ?>
		<tr bgcolor=<? echo $bgcolor ?>><td colspan=2>

		<? ///////////////////// INFOS STATIQUES EN HAUT //////////////////// ?>
		<input type=hidden name=id_status value=<? echo $dom['id_status'] ?>>

		<table border=0 width=100% cellspacing=0 cellpadding=5><tr bgcolor=<? echo $bg_c_1 ?>>
		<td align=right width=180>Enregistr&#233; le : <td width=250><b><? echo date_format(date_create($dom['d_date_enregistrement']),'d-m-Y H:i:s') ?></b>
		<td align=right> Statut :
		
		<td align=center <? if ($dom['id_status'] == 1) echo "bgcolor=".$status_ok_bg."><font color=".$status_ok.">"; else echo "><font color=".$status_ko.">"; ?> Actif 
		<td align=center <? if ($dom['id_status'] == 2) echo "bgcolor=".$status_ok_bg."><font color=".$status_ok.">"; else echo "><font color=".$status_ko.">"; ?> Gel&#233; 
		<td align=center <? if ($dom['id_status'] == 3) echo "bgcolor=".$status_ok_bg."><font color=".$status_ok.">"; else echo "><font color=".$status_ko.">"; ?> Bloqu&#233; 
		<td align=center <? if (in_array($dom['id_status'],array(4,6))) echo "bgcolor=".$status_ok_bg."><font color=".$status_ok.">"; else echo "><font color=".$status_ko.">"; ?> R&#233;demption 
		<td align=center <? if ($dom['id_status'] == 5) echo "bgcolor=".$status_ok_bg."><font color=".$status_ok.">"; else echo "><font color=".$status_ko.">"; ?> Orphelin 
		<? if ($bgcolor==$bg_c_2) $bgcolor=$bg_c_1; else $bgcolor=$bg_c_2; ?>
		<tr bgcolor=<? echo $bgcolor ?>><td align=right>Derni&#232;re mise &#224; jour : <td><b><? echo date_format(date_create($date_last_MAJ[0]),'d-m-Y H:i:s') ?></b>
		<td align=right><i>Depuis le <? echo date_format(date_create($date_last_state[0]),'d-m-Y &#224; H:i:s') ?></i>
		<td colspan=5 align=center>
		<?
		if ($dom['id_status'] < 90)
			{
				?>
				<input style='width:150px' type=submit name=activer value="R&#233;-activer" <? if (!in_array($dom['id_status'],array(2,3,4,5,6))) echo "disabled=disabled"; ?>>
				<input type=submit style='width:150px' name=geler value="Geler" <? if (!in_array($dom['id_status'],array(1,5))) echo "disabled=disabled"; ?>>
				<input type=submit style='width:150px' name=bloquer value="Bloquer" <? if (!in_array($dom['id_status'],array(1,2,5))) echo "disabled=disabled"; ?>>
				<input type=submit style='width:150px' name=supprimer value="Supprimer"<? if (in_array($dom['id_status'],array(4,6))) echo "disabled=disabled"; ?>>
				<input type=submit style='width:150px' name=archiver value="Archiver"<? if (!in_array($dom['id_status'],array(4,6))) echo "disabled=disabled"; ?>>
				<?
			}
		else 
			echo "<b>Domaine supprim&#233; et archiv&#233;.</b>";
		?>
		<? if ($bgcolor==$bg_c_2) $bgcolor=$bg_c_1; else $bgcolor=$bg_c_2; ?>
			<tr bgcolor=<? echo $bgcolor ?>><td align=right>Expiration :
			<td colspan=7><input type=text size=8 maxlength=10 value=<? echo date_format(date_create($dom['d_date_expiration']),'d-m-Y') ?> name=expiration id=expiration <? if (in_array($dom['id_status'],array(4,6))) echo "disabled=disabled" ?>>
                <? if ($bgcolor==$bg_c_2) $bgcolor=$bg_c_1; else $bgcolor=$bg_c_2;


		if (in_array($dom['id_status'],array(4,6)))	////////////// SI SUPPRIME OU EXPIRE MAIS EN PERDIODE DE RESTORAITON ON NE GERE PLUS L'AUTORENEW
			{
				?>
				<tr bgcolor=<? echo $bgcolor ?>><td align=right>Restorable jusqu'au :<td colspan=7><b><? echo date("d-m-Y", strtotime($date_last_state[0].'+'.intval($nb_jours_resto-1).' days')) ?></b>
				<?
			}
		else						////////////// SINON POSSIBLE AUTO RENEW
			{
				if ($dom['id_status'] < 90)	//// SI DOMAINE DEJA ARCHIVE, ON N'AFFICHE PAS 
					{
						?>
						<tr bgcolor=<? echo $bgcolor ?>><td align=right>Renouvellement auto : <td><input type=checkbox name=autorenew id=autorenew <? if ($dom['d_auto_renew'] == 1) echo "checked" ?> onclick="act_autorenew()">
						<td colspan=6><input type=submit style='width:200px' name=renew_1y id=renew_1y value='Renouveler 1 an' <? if ($dom['d_auto_renew'] == 1 || $dom['d_date_expiration'] >= date('Y-m-d',strtotime('+1 year'))) echo "disabled=disabled" ?> >
						<?
					}
			}
		?>
		</table>
		<? /////////////////// FIN INFOS STATIQUES EN HAUT //////////////////
}

if ($bgcolor==$bg_2) $bgcolor=$bg_1; else $bgcolor=$bg_2;
?>
<tr bgcolor=<? echo $bgcolor ?>><td>Nom du domaine : <td><input type=text size=80 name=ndd value="<?php echo $ndd ?>" id=ndd <? if ($edition == 0) echo "onblur='verif_ndd()'" ?>>
	<? if ($edition == 0) echo "<td width=700> <font size=4 color=#cc0000><i><p id='exist_ndd'></p></i></font>" ?>
	<input type=hidden name=id_domaine value="<?php echo $id_domaine ?>">
<?
	if ($edition == 1) echo "<input type=submit style='width:150px' name=whois value='WhoIS ...'>";
	if ($edition == 0) 
		{
			if ($bgcolor==$bg_2) $bgcolor=$bg_1;
				else $bgcolor=$bg_2;
			echo "<tr bgcolor=".$bgcolor."><td>Renouvellement auto : <td colspan=2><input type=checkbox name=autorenew id=autorenew checked>";
		}
?>
<? if ($bgcolor==$bg_2) $bgcolor=$bg_1; else $bgcolor=$bg_2; ?>
<tr bgcolor=<? echo $bgcolor ?>>

	<?
	if ($edition == 1)	//////////////////////////////////////////////////// TRANSFERT POSSIBLE ///////////////////////////////
		{
			?>
			<td colspan=2>
			<table border=0 width=100% cellspacing=0 cellpadding=5><tr bgcolor=<? echo $bg_c_1 ?>>
			<td>Bureau d'enregistrement : <td width=40%><font size=+1><b><?php echo $nom_registrar ?></b>
			<td align=right><input type=checkbox name=transfert id=transfert onclick='act_transfert();' <? if ($_POST['transfert'] == 'on') echo "checked"; if ($retard_paiement>1) echo "disabled=disabled"; ?>> Transf&#233;rer &#224; :
			<td align=left><input type=text size=60 name=choix_reg id=choix_reg <? if ($_POST['transfert'] == 'on') echo "value='".$nom_registrar_tr."'"; else echo "disabled=disabled"; ?>>
			<input type=hidden name=reg_id id=reg_id value=<?php echo $id_registrar ?>>
			<input type=hidden name=reg_id_old id=reg_id_old value=<?php echo $dom['id_registrar'] ?>>
			<tr bgcolor=<? echo $bg_c_2 ?>><td><td><td align=right>Contacts &#224; dupliquer :<td align=left> 
			<input type=checkbox name=tr_tit id=tr_tit onclick="check_contact('tit');" <? if ($_POST['transfert'] != 'on') echo "disabled=disabled"; if ($_POST['tr_tit'] == 'on') echo "checked"; ?>> Titulaire | 
			<input type=checkbox name=tr_adm id=tr_adm onclick="check_contact('adm');"<? if ($_POST['transfert'] != 'on') echo "disabled=disabled"; if ($_POST['tr_adm'] == 'on') echo "checked"; ?>> Administratif | 
			<input type=checkbox name=tr_tec id=tr_tec onclick="check_contact('tec');"<? if ($_POST['transfert'] != 'on') echo "disabled=disabled"; if ($_POST['tr_tec'] == 'on') echo "checked"; ?>> Technique
			</table>
			<?
		}
	else			//////////////////////////////////////////////////// NOUVEAU DOMAINE  ///////////////////////////////
		{
			?>
			<td>Bureau d'enregistrement : <td colspan=2>
			<input type=text name=choix_reg id=choix_reg size=80 value='<?php echo $nom_registrar ?>'>
			<input type=hidden name=reg_id id=reg_id value=<?php echo $id_registrar ?>>
			<?
		}

if ($bgcolor==$bg_2) $bgcolor=$bg_1; else $bgcolor=$bg_2; ?>
<tr bgcolor=<? echo $bgcolor ?>><td colspan=3>Contacts :<hr>
<center>
<table border=0 cellpadding=5 cellspacing=0> <!-- table contacts -->
<tr><td valign=top>
	<table border=0 cellpadding=7 cellspacing=0> <!-- table titulaire -->
	<tr bgcolor=<? echo $bg_c_2 ?>><td colspan=2>Titulaire :<td align=center><font size=+1><b><div id='dup_tit' style="display:none;"> -- DUPLIQU&#201; --</div></b>
	<tr bgcolor=<? echo $bg_c_1 ?>><td colspan=3><hr>
	<tr bgcolor=<? echo $bg_c_2 ?>><td rowspan=2> Recherche <td> Par nom <td><input type=text size=40 name=rec_nom id=rec_tit_nom <? if (!isset($id_registrar)) echo "disabled=disabled" ?>>
	<tr bgcolor=<? echo $bg_c_2 ?>>	     <td><nobr> Par NicHandle<td><input type=text size=12 name=tit_nch id=rec_tit_hdl <? if (!isset($id_registrar)) echo "disabled=disabled" ?>><input type=hidden name=tit_id id=tit_id value=<?php echo $cont['tit']['id'] ?>>
							<input type=hidden name=tit_hdl id=tit_hdl value=<? echo $cont['tit']['nichandle'] ?>>
	<tr bgcolor=<? echo $bg_c_1 ?>><td colspan=3><hr>
	<tr bgcolor=<? echo $bg_c_2 ?>><td colspan=3 height="250" valign=top><font size=-1><span id=hdl_tit><? echo $cont['tit']['nichandle'] ?></span></font><br>
			<span id=tit_societe><? echo $cont['tit']['societe'] ?></span><br>
			<span id=tit_nom><? if ($cont['tit']['nom']) echo $cont['tit']['nom']; else echo $aucun; ?></span>
			<br><span id=tit_adr1><? echo $cont['tit']['adr1'] ?></span>
			<br><span id=tit_adr2><? echo $cont['tit']['adr2'] ?></span><br><span id=tit_ville><? echo $cont['tit']['ville'] ?></span><br>
			<span id=tit_pays><? echo $cont['tit']['pays'] ?></span><br><span id=tit_tel><? echo $cont['tit']['tel'] ?></span><br><span id=tit_email><? echo $cont['tit']['email'] ?></span>
	<tr bgcolor=<? echo $bg_c_1 ?>><td colspan=3><hr>
	<? if ($dom['id_status'] < 90)
		{
			?>
			<tr bgcolor=<? echo $bg_c_2 ?>><td colspan=3 align=center><input type=submit id=tit_edit name=tit_edit <? if (!isset($id_domaine)) echo "disabled=disabled" ?> value="Editer ..." style='width:200px'> 
								<input type=submit name=tit_create id=tit_create <? if (!isset($id_registrar)) echo "disabled=disabled" ?> value="Cr&#233;er un nouveau contact ..." style='width:230px'>
			<?
		}
	?>
	</table>  <!-- fin table titulaire -->
<td valign=top>
        <table border=0 cellpadding=7 cellspacing=0> <!-- table admin -->
        <tr bgcolor=<? echo $bg_c_2 ?>><td colspan=2>Contact administratif :<td align=center><font size=+1><b><div id='dup_adm' style="display:none;"> -- DUPLIQU&#201; --</div></b>
        <tr bgcolor=<? echo $bg_c_1 ?>><td colspan=3><hr>
        <tr bgcolor=<? echo $bg_c_2 ?>><td rowspan=2> Recherche <td> Par nom <td><input type=text size=40 name=rec_nom id=rec_adm_nom <? if (!isset($id_registrar)) echo "disabled=disabled" ?>>
        <tr bgcolor=<? echo $bg_c_2 ?>>      <td><nobr> Par NicHandle<td><input type=text size=12 name=adm_nch id=rec_adm_hdl <? if (!isset($id_registrar)) echo "disabled=disabled" ?>><input type=hidden name=adm_id id=adm_id value=<?php echo $cont['adm']['id'] ?>>
							<input type=hidden name=adm_hdl id=adm_hdl value=<? echo $cont['adm']['nichandle'] ?>>
        <tr bgcolor=<? echo $bg_c_1 ?>><td colspan=3><hr>
        <tr bgcolor=<? echo $bg_c_2 ?>><td colspan=3 height="250" valign=top><font size=-1><span id=hdl_adm><? echo $cont['adm']['nichandle'] ?></span></font><br>
			<span id=adm_societe><? echo $cont['adm']['societe'] ?></span><br>
			<span id=adm_nom><? if ($cont['adm']['nom']) echo $cont['adm']['nom']; else echo $aucun; ?></span>
			<br><span id=adm_adr1><? echo $cont['adm']['adr1'] ?></span>
                        <br><span id=adm_adr2><? echo $cont['adm']['adr2'] ?></span><br><span id=adm_ville><? echo $cont['adm']['ville'] ?></span><br>
			<span id=adm_pays><? echo $cont['adm']['pays'] ?></span><br><span id=adm_tel><? echo $cont['adm']['tel'] ?></span><br><span id=adm_email><? echo $cont['adm']['email'] ?></span>
        <tr bgcolor=<? echo $bg_c_1 ?>><td colspan=3><hr>
	<? if ($dom['id_status'] < 90)
                {
                        ?>
			<tr bgcolor=<? echo $bg_c_2 ?>><td colspan=3 align=center><input type=submit id=adm_edit name=adm_edit <? if (!isset($id_domaine)) echo "disabled=disabled" ?> value="Editer ..." style='width:200px'>
								<input type=submit name=adm_create id=adm_create <? if (!isset($id_registrar)) echo "disabled=disabled" ?> value="Cr&#233;er un nouveau contact ..." style='width:230px'>
			<?
		}
	?>
        </table>  <!-- fin table admin -->
<td valign=top>
	<table border=0 cellpadding=7 cellspacing=0> <!-- table tech -->
	<tr bgcolor=<? echo $bg_c_2 ?>><td colspan=2>Contact technique :<td align=center><font size=+1><b><div id='dup_tec' style="display:none;"> -- DUPLIQU&#201; --</div></b>
	<tr bgcolor=<? echo $bg_c_1 ?>><td colspan=3><hr>
	<tr bgcolor=<? echo $bg_c_2 ?>><td rowspan=2> Recherche <td> Par nom <td><input type=text size=40 name=rec_nom id=rec_tec_nom <? if (!isset($id_registrar)) echo "disabled=disabled" ?>>
	<tr bgcolor=<? echo $bg_c_2 ?>>      <td><nobr> Par NicHandle<td><input type=text size=12 name=tec_nch id=rec_tec_hdl <? if (!isset($id_registrar)) echo "disabled=disabled" ?>><input type=hidden name=tec_id id=tec_id value=<?php echo $cont['tec']['id'] ?>>
							<input type=hidden name=tec_hdl id=tec_hdl value=<? echo $cont['tec']['nichandle'] ?>>
	<tr bgcolor=<? echo $bg_c_1 ?>><td colspan=3><hr>
	<tr bgcolor=<? echo $bg_c_2 ?>><td colspan=3 height="250" valign=top><font size=-1><span id=hdl_tec><? echo $cont['tec']['nichandle'] ?></span></font><br>
			<span id=tec_societe><? echo $cont['tec']['societe'] ?></span><br>
			<span id=tec_nom><? if ($cont['tec']['nom']) echo $cont['tec']['nom']; else echo $aucun; ?></span>
			<br><span id=tec_adr1><? echo $cont['tec']['adr1'] ?></span>
                        <br><span id=tec_adr2><? echo $cont['tec']['adr2'] ?></span><br><span id=tec_ville><? echo $cont['tec']['ville'] ?></span><br><span id=tec_pays><? echo $cont['tec']['pays'] ?></span>
			<br><span id=tec_tel><? echo $cont['tec']['tel'] ?></span><br><span id=tec_email><? echo $cont['tec']['email'] ?></span>
        <tr bgcolor=<? echo $bg_c_1 ?>><td colspan=3><hr>
	<? if ($dom['id_status'] < 90)
                {
                        ?>
			<tr bgcolor=<? echo $bg_c_2 ?>><td colspan=3 align=center><input type=submit id=tec_edit name=tec_edit <? if (!isset($id_domaine)) echo "disabled=disabled" ?> value="Editer ..." style='width:200px'>
										<input type=submit name=tec_create id=tec_create <? if (!isset($id_registrar)) echo "disabled=disabled" ?> value="Cr&#233;er un nouveau contact ..." style='width:230px'>
			<?
		}
	?>
        </table>  <!-- fin table tec -->

</table> <!-- fin table contacts -->
<? if ($bgcolor==$bg_2) $bgcolor=$bg_1; else $bgcolor=$bg_2; ?>
<tr bgcolor=<? echo $bgcolor ?>><td>RCI <td <? if ($edition == 0) echo "colspan=2" ?>><input type="hidden" name="MAX_FILE_SIZE" value="10000000"><input type="file" name="rci">
<? /////////////////////// DNSSEC ////////////////////////// ?>
<? if ($bgcolor==$bg_2) $bgcolor=$bg_1; else $bgcolor=$bg_2; ?>
<tr bgcolor=<? echo $bgcolor ?>><td>DNSSec activ&#233; : <input type=checkbox name=check_dnssec id=check_dnssec <? if (isset($dnssec_old['keydigest']) || $_POST['check_dnssec'] == 'on') echo "CHECKED" ?> onclick="act_dnssec()">
				<td <? if ($edition == 0) echo "colspan=2" ?>>Key Tag : <input type=text size=5 name=keytag id=keytag <? if (isset($dnssec_old['keytag'])) echo "value=".$dnssec_old['keytag']; else echo "disabled=disabled" ?>> &nbsp;
					Key Algorithm : <select name=algorithm id=algorithm <? if (!isset($dnssec_old['algorithm'])) echo "disabled=disabled" ?>>
					<?
					$result = r_exec('local',"select algo_value,algo_desc from dnssec_algorithm order by id_algo",false);
					while ($algo= pg_fetch_array($result))
						{
							echo "<option value=".$algo[0];
							if (isset($dnssec_old))
								if ($dnssec_old['algorithm'] == $algo[0]) echo " selected";
							echo ">".$algo[1]."</option>";
						}
					?></select>
					&nbsp;
					Digest Type : <select name=digesttype id=digesttype <? if (!isset($dnssec_old['digesttype'])) echo "disabled=disabled" ?>>
                                        <?
                                        $result = r_exec('local',"select digest_value,digest_desc from dnssec_digest order by id_digest",false);
                                        while ($digest= pg_fetch_array($result))
                                                {
                                                        echo "<option value=".$digest[0];
                                                        if (isset($dnssec_old))
								if ($dnssec_old['digesttype'] == $digest[0]) echo " selected";
                                                        echo ">".$digest[1]."</option>";
                                                }
                                        ?></select>
                                        &nbsp;
					Key Digest : <input type=text size=72 name=keydigest id=keydigest <? if (isset($dnssec_old['keydigest'])) echo "value=".$dnssec_old['keydigest']; else echo "disabled=disabled" ?>>
<? ///////////////////// FIN DNSSEC /////////////////////////?>
<? if ($bgcolor==$bg_2) $bgcolor=$bg_1; else $bgcolor=$bg_2; ?>
<tr bgcolor=<? echo $bgcolor ?>><td colspan=3>Serveurs DNS :<hr>
<? ////////////////// TABLE SERVEURS DNS ////////// ?>
<table border=0 width=100% cellspacing=0 cellpadding=6>
<?
	for ($dns=1;$dns<=$nb_dns_max;$dns++)
		{
			if ($bgcolor==$bg_c_2)
				$bgcolor=$bg_c_1;
				else $bgcolor=$bg_c_2;
			if ($dns<=2)
				$mandatory = "Obligatoire";
				else $mandatory = "facultatif";
			if (isset($_POST['dns'.$dns])) 
				$ns = $_POST['dns'.$dns];
				else $ns = $tab[$dns];

			echo "<tr bgcolor=".$bgcolor."><td width=25%> DNS ".$dns." <i>(".$mandatory.")</i><td width=35%><input type=text size=50 name=dns".$dns." id=dns".$dns." value=".$ns.">";
//			if (isset($ns))
//				{
//					if (domain_check($ndd,$tab[$dns])) 
//						{
//							$res = " Zone OK";
//							$light = "green";
//						}
//					else
//						{
//							$res = " La zone ne semble pas install&#233;e sur ce serveur.";
//							$light = "red";
//						}
//					echo "<td width=25><img src='images/".$light.".png' width=25><td>".$res;
//				}
//			else echo "<td colspan=2>";
		}
?>
</table>
<? /////////////// FIN TABLE SERVEURS DNS ////////// ?>
</table><br>
<?
if ($dom['id_status'] < 90)
	if ($edition == 1)
		{
			?>
			<input type=hidden name=edition value=<? echo $edition ?>>
			<input type=submit name=maj_dom Value="Mettre &#224; jour" style='width:600px;height:100px' <? if (in_array($status_registrar,array(2,3))) echo "disabled=disabled" ?>>
			<input type=submit name=new_dom Value="Enregistrer comme un nouveau domaine" style='width:600px;height:100px' <? if (in_array($status_registrar,array(2,3))) echo "disabled=disabled" ?>>
			<?
		}
	else
		{
			?>
			<input type=submit name=new_dom Value="Enregistrer" style='width:600px;height:100px'>
			<?
		}

?>
</form>

<?  ///////// RECHERCHE HISTORIQUE /////////////////
if ($id_domaine!='') historique('domaine',$id_domaine,$ndd,$max_op_visibles,$bg_1,$bg_2);

// FIN HISTORIQUE ////
?>
	
<script type="application/javascript" src="jquery-ui/js/jquery-1.9.1.js"></script>
<script type="application/javascript" src="jquery-ui/js/jquery-ui-1.10.3.custom.js"></script>
<script type="application/javascript">
$(function()
{
        $("#choix_reg").on('input', function()
                 {
                        $("#choix_reg").autocomplete({
                                source: "scripts/get_reg.php",
                                select : function(event, ui)
					{
						$('#reg_id').val(ui.item.reg_id),
						$('#tit_create').prop('disabled',false),
						$('#rec_tit_nom').prop('disabled',false),
						$('#rec_tit_hdl').prop('disabled',false),
						$('#adm_create').prop('disabled',false),
						$('#rec_adm_nom').prop('disabled',false),
						$('#rec_adm_hdl').prop('disabled',false),
						$('#tec_create').prop('disabled',false),
						$('#rec_tec_nom').prop('disabled',false),
						$('#rec_tec_hdl').prop('disabled',false);
						
                                        }
                        });
                });

	$("#rec_tit_nom").on('input', function()
                 {
			var param = $("#reg_id").val();
                        $("#rec_tit_nom").autocomplete({
                                source: "scripts/get_cont.php?reg_id="+param,
				
                                select : function(event, ui)
                                        {
                                                $('#tit_id').val( ui.item.cont_id );
						$('#tit_societe').text( ui.item.cont_societe);
						$('#tit_nom').text( ui.item.cont_nom);
						$('#tit_adr1').text( ui.item.cont_adr1);
						$('#tit_adr2').text( ui.item.cont_adr2);
						$('#tit_ville').text( ui.item.cont_ville);
						$('#tit_pays').text( ui.item.cont_pays);
						$('#tit_tel').text( ui.item.cont_tel);
						$('#tit_email').text( ui.item.cont_email);
						$('#hdl_tit').text('NIC Handle : ' + ui.item.cont_nch);
						$('#tit_hdl').val( ui.item.cont_nch);
						$('#rec_tit_hdl').val( ui.item.cont_nch);
						$('#tit_edit').prop('disabled',false);
                                        }
                        });
		});
	
	$("#rec_tit_hdl").on('input', function()
                 {
			var param = $("#reg_id").val();
                        $("#rec_tit_hdl").autocomplete({
                                source: "scripts/get_hdl.php?reg_id="+param,
                                select : function(event, ui)
                                        {
                                                $('#tit_id').val( ui.item.cont_id );
                                                $('#tit_societe').text( ui.item.cont_societe);
                                                $('#tit_nom').text( ui.item.cont_nom);
                                                $('#tit_adr1').text( ui.item.cont_adr1);
                                                $('#tit_adr2').text( ui.item.cont_adr2);
                                                $('#tit_ville').text( ui.item.cont_ville);
                                                $('#tit_pays').text( ui.item.cont_pays);
                                                $('#tit_tel').text( ui.item.cont_tel);
                                                $('#tit_email').text( ui.item.cont_email);
                                                $('#rec_tit_nom').val( ui.item.cont_nom);
						$('#tit_hdl').val( ui.item.cont_nch);
						$('#hdl_tit').text('NIC Handle : ' + ui.item.cont_nch);
						$('#tit_edit').prop('disabled',false);
                                        }
                        });
                });


	$("#rec_adm_nom").on('input', function()
                 {
			var param = $("#reg_id").val();
                        $("#rec_adm_nom").autocomplete({
                                source: "scripts/get_cont.php?reg_id="+param,
                                select : function(event, ui)
                                        {
                                                $('#adm_id').val( ui.item.cont_id );
                                                $('#adm_societe').text( ui.item.cont_societe);
                                                $('#adm_nom').text( ui.item.cont_nom);
                                                $('#adm_adr1').text( ui.item.cont_adr1);
                                                $('#adm_adr2').text( ui.item.cont_adr2);
                                                $('#adm_ville').text( ui.item.cont_ville);
                                                $('#adm_pays').text( ui.item.cont_pays);
                                                $('#adm_tel').text( ui.item.cont_tel);
                                                $('#adm_email').text( ui.item.cont_email);
						$('#hdl_adm').text('NIC Handle : ' + ui.item.cont_nch);
						$('#adm_hdl').val( ui.item.cont_nch);
                                                $('#rec_adm_hdl').val( ui.item.cont_nch);
                                                $('#adm_edit').prop('disabled',false);
                                        }
                        });
                });

        $("#rec_adm_hdl").on('input', function()
                 {
			var param = $("#reg_id").val();
                        $("#rec_adm_hdl").autocomplete({
                                source: "scripts/get_hdl.php?reg_id="+param,
                                select : function(event, ui)
                                        {
                                                $('#adm_id').val( ui.item.cont_id );
                                                $('#adm_societe').text( ui.item.cont_societe);
                                                $('#adm_nom').text( ui.item.cont_nom);
                                                $('#adm_adr1').text( ui.item.cont_adr1);
                                                $('#adm_adr2').text( ui.item.cont_adr2);
                                                $('#adm_ville').text( ui.item.cont_ville);
                                                $('#adm_pays').text( ui.item.cont_pays);
                                                $('#adm_tel').text( ui.item.cont_tel);
                                                $('#adm_email').text( ui.item.cont_email);
						$('#hdl_adm').text('NIC Handle : ' + ui.item.cont_nch);
						$('#adm_hdl').val( ui.item.cont_nch);
                                                $('#rec_adm_nom').val( ui.item.cont_nom);
						$('#adm_edit').prop('disabled',false);
                                        }
                        });
                });

	$("#rec_tec_nom").on('input', function()
                 {
			var param = $("#reg_id").val();
                        $("#rec_tec_nom").autocomplete({
                                source: "scripts/get_cont.php?reg_id="+param,
                                select : function(event, ui)
                                        {
                                                $('#tec_id').val( ui.item.cont_id );
                                                $('#tec_societe').text( ui.item.cont_societe);
                                                $('#tec_nom').text( ui.item.cont_nom);
                                                $('#tec_adr1').text( ui.item.cont_adr1);
                                                $('#tec_adr2').text( ui.item.cont_adr2);
                                                $('#tec_ville').text( ui.item.cont_ville);
                                                $('#tec_pays').text( ui.item.cont_pays);
                                                $('#tec_tel').text( ui.item.cont_tel);
                                                $('#tec_email').text( ui.item.cont_email);
						$('#hdl_tec').text('NIC Handle : ' + ui.item.cont_nch);
						$('#tec_hdl').val( ui.item.cont_nch);
                                                $('#rec_tec_hdl').val( ui.item.cont_nch);
                                                $('#tec_edit').prop('disabled',false);
                                        }
                        });
                });

        $("#rec_tec_hdl").on('input', function()
                 {
			var param = $("#reg_id").val();
                        $("#rec_tec_hdl").autocomplete({
                                source: "scripts/get_hdl.php?reg_id="+param,
                                select : function(event, ui)
                                        {
                                                $('#tec_id').val( ui.item.cont_id );
                                                $('#tec_societe').text( ui.item.cont_societe);
                                                $('#tec_nom').text( ui.item.cont_nom);
                                                $('#tec_adr1').text( ui.item.cont_adr1);
                                                $('#tec_adr2').text( ui.item.cont_adr2);
                                                $('#tec_ville').text( ui.item.cont_ville);
                                                $('#tec_pays').text( ui.item.cont_pays);
                                                $('#tec_tel').text( ui.item.cont_tel);
                                                $('#tec_email').text( ui.item.cont_email);
						$('#hdl_tec').text('NIC Handle : ' + ui.item.cont_nch);
						$('#tec_hdl').val( ui.item.cont_nch);
                                                $('#rec_tec_nom').val( ui.item.cont_nom);
						$('#tec_edit').prop('disabled',false);
                                        }
                        });
                });

	$("#dns1").on('input', function()
                 {
                        $("#dns1").autocomplete({
                                source: "scripts/get_ns.php"
                        });
                });
        $("#dns2").on('input', function()
                 {
                        $("#dns2").autocomplete({
                                source: "scripts/get_ns.php"
                        });
                });
        $("#dns3").on('input', function()
                 {
                        $("#dns3").autocomplete({
                                source: "scripts/get_ns.php"
                        });
                });
        $("#dns4").on('input', function()
                 {
                        $("#dns4").autocomplete({
                                source: "scripts/get_ns.php"
                        });
                });
        $("#dns5").on('input', function()
                 {
                        $("#dns5").autocomplete({
                                source: "scripts/get_ns.php"
                        });
                });
        $("#dns6").on('input', function()
                 {
                        $("#dns6").autocomplete({
                                source: "scripts/get_ns.php"
                        });
                });
        $("#dns7").on('input', function()
                 {
                        $("#dns7").autocomplete({
                                source: "scripts/get_ns.php"
                        });
                });
        $("#dns8").on('input', function()
                 {
                        $("#dns8").autocomplete({
                                source: "scripts/get_ns.php"
                        });
                });
});
</script>
<?
require "footer.php";
