<?php

	// http://192.168.1.70/create_one_site_target_execute_script.php
		
	$code_erreur = 0;

	$Flag_debug_1 = 1 ;
	$Flag_debug_1 = 0 ;
	
	$MySQL_connected = false;
	
	$p_NEW_SITE = isset($_POST["NEW_SITE_ID"]) ? $_POST["NEW_SITE_ID"] : "00000_000";

	if ( ( $p_NEW_SITE == "00000_000" ) or ( $p_NEW_SITE == "" ) ) {
		echo( "<font color='Salmon'>" . "saisir un identifiant pour le site à créer !" . "</font>" . "<br>") ;
		$code_erreur = 1 ;
	}

	
	//--------------------------------------------------------------------------------------------------------
	// connexion à la base de données
	//--------------------------------------------------------------------------------------------------------
	if ( $code_erreur == 0 ) {
		
		include("../_identifiants/sql_identification_main.php");

		$link_AQCM05 = mysqli_connect($mysql_host,$mysql_user,$mysql_password, $mysql_base);
		
		if (!$link_AQCM05) {
			
			$code_erreur = 2 ;
			echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; echo '</br>';
			echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; echo '</br>';
			echo "Connexion impossible à la base de donnée MySQL !" . PHP_EOL; echo '</br>';
			
		}
		else {
			$MySQL_connected = true;
		}

	}

	//--------------------------------------------------------------------------------------------------------
	// test d'existence du site : 
	// 1 - recherche des sites répertoriés
	//--------------------------------------------------------------------------------------------------------
	if ( $code_erreur == 0 ) {
		
		$NB_sites = 0 ;

		$query_sites_list = "SELECT SITES_ID, SITES_STATUS, SITES_T_MAX, SITES_NB_MAX FROM AQCM05_LIST_SITES ORDER BY SITES_ID";

		$result_sites_list = mysqli_query($link_AQCM05, $query_sites_list); 
		
		if (!$result_sites_list) {
			$code_erreur = 11;
		} 
		else {
			
			if ( mysqli_num_rows($result_sites_list) != 0 ) {	
				
				$i=0;
				while ($row = mysqli_fetch_array($result_sites_list, MYSQLI_BOTH)) {

					$aqcm_SITES_ID[$i]		  	= $row["SITES_ID"];
					$aqcm_SITES_STATUS[$i]		= $row["SITES_STATUS"];
					$aqcm_SITES_T_MAX[$i]	    = $row["SITES_T_MAX"];
					$aqcm_SITES_NB_MAX[$i]      = $row["SITES_NB_MAX"];
					
					$i++ ;
				}
				
				$NB_sites = $i;
				
				if ($Flag_debug_1 == 1) {
					echo("NB_sites = " . $NB_sites . "</br>") ;
					
				}
				
				for ($j = 0; $j < $NB_sites; $j++) {
					if ($Flag_debug_1 == 1) {
						echo($aqcm_SITES_ID[$j] . "</br>") ;
					}
				}

			}
		}

	}


	//--------------------------------------------------------------------------------------------------------
	// test d'existence du site
	// 2 - le nouveau site est-il déjà répertorié ?
	//--------------------------------------------------------------------------------------------------------
	if ( ( $code_erreur == 0 ) and ( $NB_sites != 0 ) ) {
		
		//echo( $p_NEW_SITE ) ; echo("<br>") ;
		
		$k = 0 ;
		
		for ($j = 0; $j < $NB_sites; $j++) {
			
			if ( $aqcm_SITES_ID[$j] == $p_NEW_SITE ) {
			
				$k++;
				
			}
		}
		
		if ( $k != 0 ) {
			$code_erreur = 21 ;
			echo( "<font color='Salmon'>" . "le site existe déjà !" . "</font>" . "<br>") ;
		}

	}

	//--------------------------------------------------------------------------------------------------------
	// test d'existence de la base associée au nouveau site
	//--------------------------------------------------------------------------------------------------------
	$new_data_base = "AQCM05_SITE_" . $p_NEW_SITE ;

	if ( $code_erreur == 0 ) {
		
		if ( mysqli_select_db($link_AQCM05, $new_data_base ) ) {
			
			$code_erreur = 22;
			echo( "<font color='Salmon'>" . "la base existe déjà !" . "</font>" . "<br>") ;

		}
		
	}
	
	//--------------------------------------------------------------------------------------------------------
	// création du site
	//--------------------------------------------------------------------------------------------------------
	if ( $code_erreur == 0 ) {
		
		$query = "CREATE DATABASE IF NOT EXISTS `" . $new_data_base . "` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;" ;
		$result = mysqli_query($link_AQCM05, $query);
		if ( !$result )  { $code_erreur = 31; }
		
	}		

	if ( $code_erreur == 0 ) {
		
		if ( !mysqli_select_db($link_AQCM05, $new_data_base ) ) { $code_erreur = 32; }

	}
	
	if ( $code_erreur == 0 ) {
		
		$query = "CREATE TABLE `AQCM05_SITE_USERS` (
			`idx` int(11) NOT NULL AUTO_INCREMENT,
			`USER_ID` varchar(64) NOT NULL DEFAULT 'default@gmail.com',
			`USER_PW` varchar(80) NOT NULL DEFAULT '12345678',
			`USER_STATUS` varchar(3) NOT NULL DEFAULT 'ON',
			`USER_LEVEL` tinyint(4) NOT NULL DEFAULT 1,
			`USER_T_MAX` varchar(12) NOT NULL DEFAULT '1999999999',
			PRIMARY KEY (`idx`),
			UNIQUE KEY `idx_2` (`idx`),
			KEY `idx` (`idx`)
			) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;" ;

		$result = mysqli_query($link_AQCM05, $query); 
		if (!$result)  { $code_erreur = 33; }

	}
	
	if ( $code_erreur == 0 ) {
		
		$query = "
			CREATE TABLE `AQCM05_SONDES_FIRMWARE` (
			`idx` mediumint(9) NOT NULL AUTO_INCREMENT,
			`aqcm_MAC` varchar(17) NOT NULL DEFAULT '00_00_00_00_00_00',
			`aqcm_NAME` varchar(20) NOT NULL DEFAULT 'NONAME',
			`aqcm_IP_SONDE` varchar(15) NOT NULL DEFAULT '---.---.---.---',
			`aqcm_FW_FILENAME` varchar(64) NOT NULL DEFAULT 'AQCM05_firmware_OK.zip',
			`aqcm_FW_UPDATE_FF` varchar(4) NOT NULL DEFAULT 'Done',
			`aqcm_BAT` varchar(2) NOT NULL DEFAULT 'B1',
			`aqcm_NIVEAU` varchar(2) NOT NULL DEFAULT 'N0',
			`aqcm_FIRMWARE_PWD` varchar(80) NOT NULL DEFAULT '87654321',
			`aqcm_SITE_ID` varchar(16) NOT NULL DEFAULT '00000_000',
			`aqcm_TYPE` varchar(20) NOT NULL DEFAULT 'AQCM05',
			`aqcm_MAIL` varchar(64) NOT NULL DEFAULT 'unknown@gmail.com',
			`aqcm_HW` varchar(6) NOT NULL DEFAULT 'HW_03',
			`aqcm_T_MAX` varchar(12) NOT NULL DEFAULT '1999999999',
			PRIMARY KEY (`idx`),
			UNIQUE KEY `idx_2` (`idx`),
			KEY `idx` (`idx`)
			) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			" ;

		$result = mysqli_query($link_AQCM05, $query);
		if ( !$result ) { $code_erreur = 34; } 
		
	}
	
	if ( $code_erreur == 0 ) {

		$query = "
			CREATE TABLE `AQCM05_SONDES_MESURES` (
			`idx` mediumint(9) NOT NULL AUTO_INCREMENT,
			`aqcm_MAC` varchar(17) NOT NULL DEFAULT '00_00_00_00_00_00',
			`aqcm_NAME` varchar(20) NOT NULL DEFAULT 'NONAME',
			`aqcm_IP_SONDE` varchar(15) NOT NULL DEFAULT '---.---.---.---',
			`aqcm_MESURES` varchar(10) NOT NULL DEFAULT 'YYYNNNNNNN',
			`aqcm_BAT` varchar(2) NOT NULL DEFAULT 'B1',
			`aqcm_NIVEAU` varchar(2) NOT NULL DEFAULT 'N0',
			`aqcm_PWD` varchar(80) NOT NULL DEFAULT '12345678',
			`aqcm_SERVER_PWD` varchar(80) NOT NULL,
			`aqcm_SITE_ID` varchar(16) NOT NULL DEFAULT '00000_000',
			`aqcm_TYPE` varchar(20) NOT NULL DEFAULT 'AQCM05',
			`aqcm_MAIL` varchar(64) NOT NULL DEFAULT 'unknown@gmail.com',
			`aqcm_HW` varchar(2) NOT NULL DEFAULT '00',
			`aqcm_T_MAX` varchar(12) NOT NULL DEFAULT '1999999999',
			PRIMARY KEY (`idx`),
			UNIQUE KEY `idx_2` (`idx`),
			KEY `idx` (`idx`)
			) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			" ;

		$result = mysqli_query($link_AQCM05, $query); 
		if (!$result) { $code_erreur = 35; } 

	}
	
	if ( $code_erreur == 0 ) {

		$query = "
			CREATE TABLE `AQCM05_SONDES_WG` (
			  `idx` mediumint(9) NOT NULL AUTO_INCREMENT,
			  `aqcm_WG_NAME` varchar(20) NOT NULL DEFAULT 'NONAME',
			  `aqcm_WG_Peer_AllowedIPs` varchar(18) NOT NULL DEFAULT '---.---.---.---/--',
			  `aqcm_WG_MAC` varchar(17) NOT NULL DEFAULT '00_00_00_00_00_00',
			  `aqcm_WG_IP_LAN` varchar(15) NOT NULL DEFAULT '---.---.---.---',
			  `aqcm_WG_BAT` varchar(2) NOT NULL DEFAULT 'B1',
			  `aqcm_WG_NIVEAU` varchar(2) NOT NULL DEFAULT 'N0',
			  `aqcm_WG_HW` varchar(2) NOT NULL DEFAULT '00',
			  `aqcm_WG_MAIL` varchar(64) NOT NULL DEFAULT 'unknown@gmail.com',
			  `aqcm_WG_PW` varchar(80) NOT NULL DEFAULT '1234',
			  `aqcm_WG_Peer_PublicKey` varchar(50) NOT NULL DEFAULT '123456abcdef123456abcdef123456abcdef123456abcdef',
			  `aqcm_WG_T_MAX` varchar(12) NOT NULL DEFAULT '1999999999',
			  `aqcm_WG_STATUS` varchar(3) NOT NULL DEFAULT 'ON',
			  PRIMARY KEY (`idx`),
			  UNIQUE KEY `idx_2` (`idx`),
			  KEY `idx` (`idx`)
			) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			" ;

		$result = mysqli_query($link_AQCM05, $query); 
		if (!$result) { $code_erreur = 36; } 

	}
	
	if ( $code_erreur == 0 ) {

		$query = "
			CREATE TABLE `AQCM05_TRIG_CO2` (
			  `idx` int(11) NOT NULL AUTO_INCREMENT,
			  `aqcm_CO2_TRIG_0` varchar(6) NOT NULL DEFAULT '700',
			  `aqcm_CO2_TRIG_1` varchar(6) NOT NULL DEFAULT '1000',
			  `aqcm_CO2_TRIG_2` varchar(6) NOT NULL DEFAULT '1300',
			  `aqcm_CO2_TRIG_3` varchar(6) NOT NULL DEFAULT '1700',
			  `aqcm_CO2_TRIG_4` varchar(6) NOT NULL DEFAULT '2000',
			  `aqcm_CO2_TRIG_5` varchar(6) NOT NULL DEFAULT '3000',
			  PRIMARY KEY (`idx`),
			  UNIQUE KEY `idx` (`idx`),
			  KEY `idx_2` (`idx`)
			) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			" ;

		$result = mysqli_query($link_AQCM05, $query); 
		if (!$result) { $code_erreur = 101; } 

	}
	
	if ( $code_erreur == 0 ) {

		$query = "
			INSERT INTO `AQCM05_TRIG_CO2` (`idx`, `aqcm_CO2_TRIG_0`, `aqcm_CO2_TRIG_1`, `aqcm_CO2_TRIG_2`, `aqcm_CO2_TRIG_3`, `aqcm_CO2_TRIG_4`, `aqcm_CO2_TRIG_5`) VALUES
			(1,	'600',	'800',	'1000',	'1300',	'1700',	'2200');
			" ;

		$result = mysqli_query($link_AQCM05, $query); 
		if (!$result) { $code_erreur = 102; } 

	}

	if ( $code_erreur == 0 ) {

		$query = "
			CREATE TABLE `AQCM05_TRIG_COV` (
			  `idx` int(11) NOT NULL AUTO_INCREMENT,
			  `aqcm_COV_TRIG_0` varchar(6) NOT NULL DEFAULT '50',
			  `aqcm_COV_TRIG_1` varchar(6) NOT NULL DEFAULT '100',
			  `aqcm_COV_TRIG_2` varchar(6) NOT NULL DEFAULT '150',
			  `aqcm_COV_TRIG_3` varchar(6) NOT NULL DEFAULT '200',
			  `aqcm_COV_TRIG_4` varchar(6) NOT NULL DEFAULT '300',
			  `aqcm_COV_TRIG_5` varchar(6) NOT NULL DEFAULT '400',
			  PRIMARY KEY (`idx`),
			  UNIQUE KEY `idx` (`idx`),
			  KEY `idx_2` (`idx`)
			) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			" ;

		$result = mysqli_query($link_AQCM05, $query); 
		if (!$result) { $code_erreur = 111; } 

	}

	if ( $code_erreur == 0 ) {

		$query = "
			INSERT INTO `AQCM05_TRIG_COV` (`idx`, `aqcm_COV_TRIG_0`, `aqcm_COV_TRIG_1`, `aqcm_COV_TRIG_2`, `aqcm_COV_TRIG_3`, `aqcm_COV_TRIG_4`, `aqcm_COV_TRIG_5`) VALUES
			(1,	'100',	'180',	'260',	'340',	'400',	'460');
			" ;

		$result = mysqli_query($link_AQCM05, $query); 
		if (!$result) { $code_erreur = 112; } 

	}
	
	if ( $code_erreur == 0 ) {

		$query = "
			CREATE TABLE `AQCM05_TRIG_HCHO` (
			  `idx` int(11) NOT NULL AUTO_INCREMENT,
			  `aqcm_HCHO_TRIG_0` varchar(6) NOT NULL DEFAULT '10',
			  `aqcm_HCHO_TRIG_1` varchar(6) NOT NULL DEFAULT '30',
			  `aqcm_HCHO_TRIG_2` varchar(6) NOT NULL DEFAULT '50',
			  `aqcm_HCHO_TRIG_3` varchar(6) NOT NULL DEFAULT '100',
			  `aqcm_HCHO_TRIG_4` varchar(6) NOT NULL DEFAULT '200',
			  `aqcm_HCHO_TRIG_5` varchar(6) NOT NULL DEFAULT '300',
			  PRIMARY KEY (`idx`),
			  UNIQUE KEY `idx` (`idx`),
			  KEY `idx_2` (`idx`)
			) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			" ;

		$result = mysqli_query($link_AQCM05, $query); 
		if (!$result) { $code_erreur = 121; } 

	}
	
	if ( $code_erreur == 0 ) {

		$query = "
			INSERT INTO `AQCM05_TRIG_HCHO` (`idx`, `aqcm_HCHO_TRIG_0`, `aqcm_HCHO_TRIG_1`, `aqcm_HCHO_TRIG_2`, `aqcm_HCHO_TRIG_3`, `aqcm_HCHO_TRIG_4`, `aqcm_HCHO_TRIG_5`) VALUES
			(1,	'10',	'25',	'50',	'100',	'200',	'500');
			" ;

		$result = mysqli_query($link_AQCM05, $query); 
		if (!$result) { $code_erreur = 122; } 

	}
	
	if ( $code_erreur == 0 ) {

		$query = "
			CREATE TABLE `AQCM05_TRIG_HR` (
			  `idx` int(11) NOT NULL AUTO_INCREMENT,
			  `aqcm_HR_TRIG_0` varchar(6) NOT NULL DEFAULT '20.0',
			  `aqcm_HR_TRIG_1` varchar(6) NOT NULL DEFAULT '30.0',
			  `aqcm_HR_TRIG_2` varchar(6) NOT NULL DEFAULT '40.0',
			  `aqcm_HR_TRIG_3` varchar(6) NOT NULL DEFAULT '60.0',
			  `aqcm_HR_TRIG_4` varchar(6) NOT NULL DEFAULT '70.0',
			  `aqcm_HR_TRIG_5` varchar(6) NOT NULL DEFAULT '80.0',
			  PRIMARY KEY (`idx`),
			  UNIQUE KEY `idx` (`idx`),
			  KEY `idx_2` (`idx`)
			) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			" ;

		$result = mysqli_query($link_AQCM05, $query); 
		if (!$result) { $code_erreur = 131; } 

	}
	
	if ( $code_erreur == 0 ) {

		$query = "
			INSERT INTO `AQCM05_TRIG_HR` (`idx`, `aqcm_HR_TRIG_0`, `aqcm_HR_TRIG_1`, `aqcm_HR_TRIG_2`, `aqcm_HR_TRIG_3`, `aqcm_HR_TRIG_4`, `aqcm_HR_TRIG_5`) VALUES
			(1,	'20.0',	'30.0',	'40.0',	'60.0',	'70.0',	'80.0');
			" ;

		$result = mysqli_query($link_AQCM05, $query); 
		if (!$result) { $code_erreur = 132; } 

	}
	
	if ( $code_erreur == 0 ) {

		$query = "
			CREATE TABLE `AQCM05_TRIG_NOX` (
			  `idx` int(11) NOT NULL AUTO_INCREMENT,
			  `aqcm_NOX_TRIG_0` varchar(6) NOT NULL DEFAULT '50',
			  `aqcm_NOX_TRIG_1` varchar(6) NOT NULL DEFAULT '100',
			  `aqcm_NOX_TRIG_2` varchar(6) NOT NULL DEFAULT '150',
			  `aqcm_NOX_TRIG_3` varchar(6) NOT NULL DEFAULT '200',
			  `aqcm_NOX_TRIG_4` varchar(6) NOT NULL DEFAULT '300',
			  `aqcm_NOX_TRIG_5` varchar(6) NOT NULL DEFAULT '400',
			  PRIMARY KEY (`idx`),
			  UNIQUE KEY `idx` (`idx`),
			  KEY `idx_2` (`idx`)
			) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			" ;

		$result = mysqli_query($link_AQCM05, $query); 
		if (!$result) { $code_erreur = 141; } 

	}
	
	if ( $code_erreur == 0 ) {

		$query = "
			INSERT INTO `AQCM05_TRIG_NOX` (`idx`, `aqcm_NOX_TRIG_0`, `aqcm_NOX_TRIG_1`, `aqcm_NOX_TRIG_2`, `aqcm_NOX_TRIG_3`, `aqcm_NOX_TRIG_4`, `aqcm_NOX_TRIG_5`) VALUES
			(1,	'10',	'20',	'30',	'40',	'50',	'60');
			" ;

		$result = mysqli_query($link_AQCM05, $query); 
		if (!$result) { $code_erreur = 142; } 

	}
	
	if ( $code_erreur == 0 ) {

		$query = "
			CREATE TABLE `AQCM05_TRIG_PM25` (
			  `idx` int(11) NOT NULL AUTO_INCREMENT,
			  `aqcm_PM25_TRIG_0` varchar(6) NOT NULL DEFAULT '10',
			  `aqcm_PM25_TRIG_1` varchar(6) NOT NULL DEFAULT '30',
			  `aqcm_PM25_TRIG_2` varchar(6) NOT NULL DEFAULT '50',
			  `aqcm_PM25_TRIG_3` varchar(6) NOT NULL DEFAULT '100',
			  `aqcm_PM25_TRIG_4` varchar(6) NOT NULL DEFAULT '200',
			  `aqcm_PM25_TRIG_5` varchar(6) NOT NULL DEFAULT '300',
			  PRIMARY KEY (`idx`),
			  UNIQUE KEY `idx` (`idx`),
			  KEY `idx_2` (`idx`)
			) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			" ;

		$result = mysqli_query($link_AQCM05, $query); 
		if (!$result) { $code_erreur = 151; } 

	}
	
	if ( $code_erreur == 0 ) {

		$query = "
			INSERT INTO `AQCM05_TRIG_PM25` (`idx`, `aqcm_PM25_TRIG_0`, `aqcm_PM25_TRIG_1`, `aqcm_PM25_TRIG_2`, `aqcm_PM25_TRIG_3`, `aqcm_PM25_TRIG_4`, `aqcm_PM25_TRIG_5`) VALUES
			(1,	'10',	'25',	'50',	'100',	'200',	'500');
			" ;

		$result = mysqli_query($link_AQCM05, $query); 
		if (!$result) { $code_erreur = 152; } 

	}
	
	if ( $code_erreur == 0 ) {

		$query = "
			CREATE TABLE `AQCM05_TRIG_SPL` (
			  `idx` int(11) NOT NULL AUTO_INCREMENT,
			  `aqcm_SPL_TRIG_0` varchar(6) NOT NULL DEFAULT '35',
			  `aqcm_SPL_TRIG_1` varchar(6) NOT NULL DEFAULT '65',
			  `aqcm_SPL_TRIG_2` varchar(6) NOT NULL DEFAULT '75',
			  `aqcm_SPL_TRIG_3` varchar(6) NOT NULL DEFAULT '90',
			  `aqcm_SPL_TRIG_4` varchar(6) NOT NULL DEFAULT '105',
			  `aqcm_SPL_TRIG_5` varchar(6) NOT NULL DEFAULT '120',
			  `aqcm_SPL_TRIG_MOY` varchar(4) NOT NULL DEFAULT '38.0',
			  `aqcm_SPL_TRIG_MAX` varchar(4) NOT NULL DEFAULT '45.0',
			  `aqcm_SPL_TRIG_EN` varchar(3) NOT NULL DEFAULT 'OFF',
			  `aqcm_SPL_TRIG_ET_OU` varchar(2) NOT NULL DEFAULT 'OU',
			  PRIMARY KEY (`idx`),
			  UNIQUE KEY `idx` (`idx`),
			  KEY `idx_2` (`idx`)
			) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			" ;

		$result = mysqli_query($link_AQCM05, $query); 
		if (!$result) { $code_erreur = 161; } 

	}
	
	if ( $code_erreur == 0 ) {

		$query = "
			INSERT INTO `AQCM05_TRIG_SPL` (`idx`, `aqcm_SPL_TRIG_0`, `aqcm_SPL_TRIG_1`, `aqcm_SPL_TRIG_2`, `aqcm_SPL_TRIG_3`, `aqcm_SPL_TRIG_4`, `aqcm_SPL_TRIG_5`, `aqcm_SPL_TRIG_MOY`, `aqcm_SPL_TRIG_MAX`, `aqcm_SPL_TRIG_EN`, `aqcm_SPL_TRIG_ET_OU`) VALUES
			(1,	'35',	'65',	'75',	'90',	'105',	'120',	'35.0',	'45.0',	'ON',	'OU');
			" ;

		$result = mysqli_query($link_AQCM05, $query); 
		if (!$result) { $code_erreur = 162; } 

	}
	
	if ( $code_erreur == 0 ) {

		$query = "
			CREATE TABLE `AQCM05_TRIG_T` (
			  `idx` int(11) NOT NULL AUTO_INCREMENT,
			  `aqcm_T_TRIG_0` varchar(6) NOT NULL DEFAULT '15.0',
			  `aqcm_T_TRIG_1` varchar(6) NOT NULL DEFAULT '17.0',
			  `aqcm_T_TRIG_2` varchar(6) NOT NULL DEFAULT '19.0',
			  `aqcm_T_TRIG_3` varchar(6) NOT NULL DEFAULT '23.0',
			  `aqcm_T_TRIG_4` varchar(6) NOT NULL DEFAULT '25.0',
			  `aqcm_T_TRIG_5` varchar(6) NOT NULL DEFAULT '27.0',
			  PRIMARY KEY (`idx`),
			  UNIQUE KEY `idx` (`idx`),
			  KEY `idx_2` (`idx`)
			) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			" ;

		$result = mysqli_query($link_AQCM05, $query); 
		if (!$result) { $code_erreur = 171; } 

	}
	
	if ( $code_erreur == 0 ) {

		$query = "
			INSERT INTO `AQCM05_TRIG_T` (`idx`, `aqcm_T_TRIG_0`, `aqcm_T_TRIG_1`, `aqcm_T_TRIG_2`, `aqcm_T_TRIG_3`, `aqcm_T_TRIG_4`, `aqcm_T_TRIG_5`) VALUES
			(1,	'15.0',	'17.0',	'19.0',	'22.0',	'24.0',	'26.0');
			" ;

		$result = mysqli_query($link_AQCM05, $query); 
		if (!$result) { $code_erreur = 172; } 

	}

	if ( $code_erreur == 0 ) {

		if ( !mysqli_select_db($link_AQCM05, "AQCM05_main" ) ) { $code_erreur = 36; }

	}
	
	if ( $code_erreur == 0 ) {

		$query = "
			INSERT INTO `AQCM05_LIST_SITES` (SITES_ID, SITES_STATUS, SITES_T_MAX, SITES_NB_MAX)
			VALUES ('" . $p_NEW_SITE . "', 'ON', '1999999999', '9');
			" ;
			
		$result = mysqli_query($link_AQCM05, $query); 
		if (!$result) { $code_erreur = 37; } 

	}
	
	if ( $code_erreur == 0 ) {
		echo( "<font color='Lime'>" . "création du nouveau site : succès..." . "</font>" . "<br>") ;
	}
	else {
		echo( "<font color='Salmon'>" . "création du nouveau site : échec!!!" . "</font>" . "<br>") ;
	}
		

	//--------------------------------------------------------------------------------------------------------
	// 
	//--------------------------------------------------------------------------------------------------------
	if ( $MySQL_connected ) {
		mysqli_close($link_AQCM05);
	}

	//--------------------------------------------------------------------------------------------------------


?>
