<?php
//Update 3.1.0
// See version Apache, PHP, MySQL, MariaDB, PhpMyAdmin in tray menu
//
//
//
//
//
//
//
//
//

require ('config.inc.php');
require ('wampserver.lib.php');

//Verify some files before generate wampmanager.ini file
//Check some files are DOS line ending
file_get_contents_dos($templateFile, false);
file_get_contents_dos($c_apacheVhostConfFile, false);

// Insert do not EDIT to wamp/bin/php/phpx.y.z/php.ini file
$do_not_edit = <<< NOTEDITEOF
[PHP]
; **************************************************************
; ****** DO NOT EDIT THIS FILE **** DO NOT EDIT THIS FILE ******
; * This file is only use by PHP CLI (Command Line Interface)  *
; * that is to say by Wampserver internal PHP scripts          *
; * THE CORRECT FILE TO EDIT is Wampmanager Icon->PHP->php.ini *
; * that is wamp/bin/apache/apache2.x.y/bin/php.ini            *
; **************************************************************

NOTEDITEOF;
$iniFileContents = file_get_contents($c_phpVersionDir."/php".$wampConf['phpVersion']."/".$wampConf['phpConfFile']);
if(strpos($iniFileContents,"* DO NOT EDIT THIS FILE *") === false) {
	$iniFileContents = str_replace("[PHP]", $do_not_edit, $iniFileContents);
	$fp = fopen($c_phpVersionDir."/php".$wampConf['phpVersion']."/".$wampConf['phpConfFile'],'w');
	fwrite($fp,$iniFileContents);
	fclose($fp);
}

//Check if the file wamp/bin/php/DO_NOT_DELETE_x.y.z.txt match CLI php version used
if(!file_exists($c_phpVersionDir."/DO_NOT_DELETE_".$c_phpCliVersion.".txt")) {
	$do_not_delete_txt = "This PHP version ".$c_phpCliVersion." is used by WampServer in CLI mode.\r\nIf you delete it, WampServer won't work anymore.";
	if ($handle = opendir($c_phpVersionDir))	{
		while (false !== ($file = readdir($handle)))	{
			if ($file != "." && $file != ".." && !is_dir($c_phpVersionDir.'/'.$file)) {
				$list[] = $file;
			}
		}
		closedir($handle);
	}
	if(!empty($list)) {
		foreach($list as $value) {
			if(strpos($value,"DO_NOT_DELETE") !== false)
				unlink($c_phpVersionDir."/".$value);
		}
	}
	$fp = fopen($c_phpVersionDir."/DO_NOT_DELETE_".$c_phpCliVersion.".txt",'w');
	fwrite($fp,$do_not_delete_txt);
	fclose($fp);
}

//Add or verify some Apache variables into httpd.conf - Only for Apache 2.4.x
$c_ApacheDefine = array();
if(substr($c_apacheVersion,0,3) == '2.4') {
	$tryfind = 'Define VERSION_APACHE';
	$search = 'Define APACHE24 Apache2.4
';
	$replace = <<< EOF
# Apache variable names used by Apache conf files:
# The names and contents of variables:
# APACHE24, VERSION_APACHE, INSTALL_DIR, APACHE_DIR
# should never be changed.
Define APACHE24 Apache2.4
Define VERSION_APACHE ${c_apacheVersion}
Define INSTALL_DIR ${c_installDir}
Define APACHE_DIR \${INSTALL_DIR}/bin/apache/apache\${VERSION_APACHE}

EOF;
	$httpdFileContents = file_get_contents_dos($c_apacheConfFile);
	$count = $counts = 0;
	if(strpos($httpdFileContents,$tryfind) === false) {
  	$httpdFileContents = str_replace($search, $replace, $httpdFileContents, $count);
  	$counts += $count;
	}
	else { // Variables exists - Verify contents
		$search = array(
			'~^(Define VERSION_APACHE[ \t]*)(.*)\r$~m',
			'~^(Define INSTALL_DIR[ \t]*)(.*)\r$~m',
			'~^(Define APACHE_DIR[ \t]*)(.*)\r$~m',
		);
		$verify = array(
			$c_apacheVersion,
			$c_installDir,
			'\${INSTALL_DIR}/bin/apache/apache\${VERSION_APACHE}',
		);
		for($i = 0 ; $i < count($search) ; $i++) {
			preg_match($search[$i],$httpdFileContents,$matches);
			if($matches[2] != $verify[$i]) {
				$httpdFileContents = preg_replace($search[$i],'${1}'.$verify[$i],$httpdFileContents,1,$count);
				$counts += $count;
			}
		}
	}

	//Modify ServerRoot and move it after Define's ServerRoot "j:/wamp/bin/apache/apache2.4.xx"
	if(preg_match('~^ServerRoot[ \t]*"'.$c_installDir.'.*$~m',$httpdFileContents,$matches) > 0) {
		$search = array(
			$matches[0],
			'Define APACHE_DIR ${INSTALL_DIR}/bin/apache/apache${VERSION_APACHE}',
		);
		$replace = array(
			'',
			'Define APACHE_DIR ${INSTALL_DIR}/bin/apache/apache${VERSION_APACHE}

ServerRoot "${APACHE_DIR}"
',
		);
		$httpdFileContents = str_replace($search,$replace,$httpdFileContents,$count);
		$counts += $count;
	}

	//Replace all install paths like "c:/wamp by "${INSTALL_DIR}
	$httpdFileContents = str_replace('"'.$c_installDir,'"${INSTALL_DIR}',$httpdFileContents, $count);
	$counts += $count;

	if($counts > 0) {
  	$fp = fopen($c_apacheConfFile,'wb');
  	fwrite($fp,$httpdFileContents);
  	fclose($fp);
	}


	//Get Apache variables (Define)
	$command = "start /b /min /wait ".$c_apacheExe." -t -D DUMP_RUN_CFG";
	$output = `$command`;
	if(!empty($output)) {
		if(preg_match_all("~^Define: (.+)=(.+)\r?$~m",$output, $matches) > 0 )
			$c_ApacheDefine = array_combine($matches[1], $matches[2]);
	}
}
$file = fopen($c_apacheDefineConf,'wb');
fwrite($file,"; Variables defined by Apache - To be used by some PHP scripts.\n\n");
if(count($c_ApacheDefine) > 0) {
	foreach($c_ApacheDefine as $key => $value)
		fwrite($file, $key.' = "'.$value.'"'."\n");
}
fwrite($file,"\n");
fclose($file);

// Check PhpMyAdmin version
$phpmyadminVersion = '';
if(file_exists($aliasDir.'phpmyadmin.conf')) {
	$myalias = @file_get_contents($aliasDir.'phpmyadmin.conf');
	//Alias /phpmyadmin "J:/wamp/apps/phpmyadmin4.7.3/"
if(preg_match('~^Alias\s*/phpmyadmin\s*".*apps/phpmyadmin([0-9\.]*)/"\s?$~m',$myalias,$matches) > 0 )
	$phpmyadminVersion = $matches[1];
}
//End of verify files


// ************************
// language management
// Get current language
$lang = $wampConf['language'];

// Load language file if exists
require($langDir.$wampConf['defaultLanguage'].'.lang');
if (is_file($langDir.$lang.'.lang'))
	require($langDir.$lang.'.lang');

// Load modules default language files
if ($handle = opendir($langDir.$modulesDir)) {
	while (false !== ($file = readdir($handle)))	{
		if ($file != "." && $file != ".." && preg_match('|_'.$wampConf['defaultLanguage'].'|',$file))
			include($langDir.$modulesDir.$file);
	}
	closedir($handle);
}

// Load modules current language files if exists
if ($handle = opendir($langDir.$modulesDir)) {
	while (false !== ($file = readdir($handle)))	{
		if ($file != "." && $file != ".." && preg_match('|_'.$lang.'|',$file))
			include($langDir.$modulesDir.$file);
	}
	closedir($handle);
}

//Check if language file does not content Offline or Online
if (strtolower($w_serverOffline) == "offline")
  $w_serverOffline .= ' ';
if (strtolower($w_serverOnline) == "online")
  $w_serverOnline .= ' ';

//Update string to use alternate port.
$w_AlternatePort = sprintf($w_UseAlternatePort, $c_UsedPort);
if($c_UsedPort == $c_DefaultPort) {
	$UrlPort = '';
	$w_newPort = "8080";
}
else {
	$UrlPort = ':'.$c_UsedPort;
	$w_newPort = "80";
}
//Update string if there are more than one Apache Listen ports
$c_listenPort = listen_ports();
$TplListenPorts = ';';
$ListenPorts = '';
$ListenPortsExists = false;
if(count($c_listenPort) > 1) {
	$ListenPorts = implode(" ",$c_listenPort);
	$TplListenPorts = '';
	$ListenPortsExists = true;
}
//Update string for add Listen Port
$w_addPort = 8081;
while(in_array($w_addPort, $c_listenPort)) {
	$w_addPort++;
}
$w_addPort = (string)$w_addPort;

//Update string to use alternate MySQL port.
$w_AlternateMysqlPort = sprintf($w_UseAlternatePort, $c_UsedMysqlPort);
if($c_UsedMysqlPort == $c_DefaultMysqlPort) {
	$w_newMysqlPort = "3308";
}
else {
	$w_newMysqlPort = "3306";
}
//Update string to use alternate MariaDB port.
$w_AlternateMariaPort = sprintf($w_UseAlternatePort, $c_UsedMariaPort);
if($c_UsedMariaPort == $c_DefaultMysqlPort) {
	$w_newMariaPort = "3309";
}
else {
	$w_newMariaPort = "3306";
}

// ************************
//Before to require wampmanager.tpl ($templateFile)
// we need to change some options, otherwise the variables are replaced by their content.
// Option to launch Homepage at startup
$RunAtStart = ($wampConf['HomepageAtStartup'] == 'on' ? '' : ';');
// Item menu Online / Offline
$ItemPutOnline = ($wampConf['MenuItemOnline'] == 'on' ? '' : ';');
// Item submenu Apache Check port used (if not 80)
$ApaTestPortUsed = ($wampConf['apacheUseOtherPort'] == 'on' ? '' : ';');
// Item Tools submenu Check MySQL port used (if not 3306)
$MysqlTestPortUsed = (($wampConf['SupportMySQL'] == 'on' && $wampConf['mysqlUseOtherPort'] == 'on') ? '' : ';');
// Item Tools submenu Check MariaDB port used (if not 3306)
$MariaTestPortUsed = (($wampConf['SupportMariaDB'] == 'on' && $wampConf['mariaUseOtherPort'] == 'on') ? '' : ';');
// Item Tools submenu Change the names of the services
$ItemChangeServiceNames = ($wampConf['ItemServicesNames'] == 'on' ? '' : ';');
//Check some values about Apache VirtualHost
$virtualHost = check_virtualhost(true);
//Option to show Edit httpd-vhosts.conf
$EditVhostConf  = (($virtualHost['include_vhosts'] === false || $virtualHost['vhosts_exist'] === false) ? ';' : '');
//Translated by in About
$w_translated_by = (isset($w_translated_by )) ? $w_translated_by : '';

//Update MySQL and/or MariaDB my.ini file
//Replace # comment by ; to be compatible with parse_ini_file
//PHP 5.3.0 Hash marks (#) should no longer be used as comments and will throw a deprecation warning if used.
//PHP 7.0.0 Hash marks (#) are no longer recognized as comments.
// Option to support MySQL
$mysqlVersionList = listDir($c_mysqlVersionDir,'checkMysqlConf','mysql');
if($wampConf['SupportMySQL'] == 'on' && count($mysqlVersionList) > 0) {
	$SupportMySQL = '';
	$EmptyMysqlLog = ' '.$c_installDir.'/'.$logDir.'mysql.log';
	$newMysqlService = ' %MysqlService%';
	$myIniContents = file_get_contents($c_mysqlConfFile);
	$myIniContents = preg_replace('/^#(.*)$/m',';${1}',$myIniContents,-1,$count);
	if($count > 0) {
		$fp = fopen($c_mysqlConfFile,'w');
		fwrite($fp,$myIniContents);
		fclose($fp);
	}
	unset ($myIniContents);
}
else {
	$SupportMySQL = ';';
	$EmptyMysqlLog = '';
	$newMysqlService = '';
}

// Option to support MariaDB
$mariadbVersionList = listDir($c_mariadbVersionDir,'checkMariaDBConf','mariadb');
if($wampConf['SupportMariaDB'] == 'on' && count($mariadbVersionList) > 0) {
	$SupportMariaDB = '';
	$EmptyMariaLog = ' '.$c_installDir.'/'.$logDir.'mariadb.log';
	$myIniContents = file_get_contents($c_mariadbConfFile);
	$myIniContents = preg_replace('/^#(.*)$/m',';${1}',$myIniContents,-1,$count);
	if($count > 0) {
		$fp = fopen($c_mariadbConfFile,'w');
		fwrite($fp,$myIniContents);
		fclose($fp);
	}
	unset ($myIniContents);
}
else {
	$SupportMariaDB = ';';
	$EmptyMariaLog = '';
}
// Option if neither MySQL nor MariaDB
if($SupportMySQL == ';' && $SupportMariaDB == ';') {
	$noDBMS = true;
	$SupportDBMS = ';';
}
else {
	$noDBMS = false;
	$SupportDBMS = '';
}

//Warnings at the end if needed
$WarningsAtEnd = false;
$WarningMenu = ';WAMPMENULEFTEND
';
$WarningText = '';

//Warning if hosts file is not writable
if(!$c_hostsFile_writable) {
	$WarningsAtEnd = true;
	$WarningMenu .= 'Type: item; Caption: "hosts file not writable"; Glyph: 19; Action: multi; Actions: warning_hostnotwritable
';
	$message = "\r\nThe file C:\\Windows\\System32\\drivers\\etc\\hosts\r\nis not writable.\r\nIn order to create or modify VirtualHost,\r\nit is imperative to be able to write to the hosts file.\r\nCheck that your anti-virus allows to write the hosts file.\r\n";
	$WarningText .= '[warning_hostnotwritable]
Action: run; FileName: "'.$c_phpExe.'";Parameters: "msg.php 11 '.base64_encode($message).'";WorkingDir: "'.$c_installDir.'/scripts"; Flags: waituntilterminated
';
}

//Forum for help
$forum = ($lang == 'french') ? '1' : '2';

// Template file
require($templateFile);

// ************************
// management of online / offline mode
$c_OnOffLine = 'off';
if ($wampConf['status'] == 'online')
{
	$tpl = str_replace('images_off.bmp', 'images_on.bmp',$tpl);
  $tpl = str_replace($w_serverOffline, $w_serverOnline,$tpl);
  $tpl = str_replace('onlineOffline.php on', 'onlineOffline.php off', $tpl);
  $tpl = str_replace($w_putOnline,$w_putOffline,$tpl);
  $c_OnOffLine = 'on';
}

// ************************
// load menu with the available languages
if ($handle = opendir($langDir))
{
	while (false !== ($file = readdir($handle)))
	{
		if ($file != "." && $file != ".." && preg_match('|\.lang|',$file))
		{
			if ($file == $lang.'.lang')
				$langList[$file] = 1;
			else
				$langList[$file] = 0;
		}
	}
	closedir($handle);
}

$langText = ";WAMPLANGUAGESTART
Type: separator; Caption: \"".$w_language."\";
";
ksort($langList);
foreach ($langList as $langname=>$langstatus)
{
  $cleanLangName = str_replace('.lang','',$langname);
  if ($langList[$langname] == 1)
    $langText .= 'Type: item; Caption: "'.$cleanLangName.'"; Glyph: 13; Action: multi; Actions: lang_'.$cleanLangName.'
';
  else
    $langText .= 'Type: item; Caption: "'.$cleanLangName.'"; Action: multi; Actions: lang_'.$cleanLangName.'
';

}

foreach ($langList as $langname=>$langstatus)
{
  $cleanLangName = str_replace('.lang','',$langname);
  $langText .= <<< EOF
[lang_${cleanLangName}]
Action: run; FileName: "${c_phpCli}";Parameters: "changeLanguage.php ${cleanLangName}";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "refresh.php";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: resetservices
Action: readconfig;

EOF;
}

$tpl = str_replace(';WAMPLANGUAGESTART',$langText,$tpl);

// ************************
// Creating the PHP extensions menu
$myphpini = @file_get_contents($c_phpConfFile);
//recovering the extensions loading configuration
preg_match_all('/^extension\s*=\s*"?([a-z0-9_]+)\.dll"?/im',$myphpini,$matchesON);
preg_match_all('/^;extension\s*=\s*"?([a-z0-9_]+)\.dll"?/im',$myphpini,$matchesOFF);
$ext = array_fill_keys($matchesON[1], '1') + array_fill_keys($matchesOFF[1], '0');

//recovering the zend_extensions loading configuration
preg_match_all('~^zend_extension\s*=\s*"([a-z0-9_:/\-\.]+)\.dll"?~im',$myphpini,$matchesON);
preg_match_all('~^;zend_extension\s*=\s*"([a-z0-9_:/\-\.]+)\.dll"?~im',$myphpini,$matchesOFF);
if(count($matchesON[0]) > 0 ) {
	$i = 0 ;
	foreach($matchesON[0] as $value) {
		foreach($zend_extensions as $key => $zend_value) {
			if(stripos($value,$key) !== false) {
				$zend_extensions[$key]['loaded'] = '1';
				$zend_extensions[$key]['content'] = $matchesON[1][$i];
				$i++;
			}
		}
	}
}

if(count($matchesOFF[0]) > 0 ) {
	$i = 0 ;
	foreach($matchesOFF[0] as $value) {
		foreach($zend_extensions as $key => $zend_value) {
			if(stripos($value,$key) !== false) {
				$zend_extensions[$key]['loaded'] = '0';
				$zend_extensions[$key]['content'] = $matchesOFF[1][$i];
				$i++;
			}
		}
	}
}

if(preg_match('/^.*php_xdebug\-([0-9\.]*)\-.*\s?$/m',$zend_extensions['php_xdebug']['content'],$matches) > 0 )
	$zend_extensions['php_xdebug']['version'] = $matches[1];
foreach($zend_extensions as $key => $value) {
	$ext[$key] = $zend_extensions[$key]['loaded'];
}
ksort($ext);
$Extensions_in_php_ini = array_combine(array_keys($ext),array_keys($ext));

// recovering the extensions list (.dll files) present in the directory ext
$extDirContents = glob($phpExtDir.'/*.dll');
array_walk($extDirContents,function(&$item){
	$item = str_replace('.dll','',basename($item));
	});
$dll_in_php_ext_dir = array_combine($extDirContents,$extDirContents);

// both tables are "crossed"
//DLL extension file exists but no extension= line in phpForApache.ini
$noExtLine = array_diff_key($dll_in_php_ext_dir,$Extensions_in_php_ini);
//extension= line exists in phpForApache.ini but no dll file
$noDllFile = array_diff_key($Extensions_in_php_ini,$dll_in_php_ext_dir);
foreach($noExtLine as $value) {
	if(array_key_exists($value,$zend_extensions))
		$ext[$value] = -4; //dll must be loaded by zend_extension
	elseif(in_array($value,$phpNotLoadExt))
		$ext[$value] = -3; //dll not to be loaded by extension = in php.ini
	else
		$ext[$value] = -1; //dll file exists but not extension line in php.ini
}
foreach($noDllFile as $value) {
	if(array_key_exists($value,$zend_extensions))
		$ext[$value] = -4; //dll must be loaded by zend_extension
	else
		$ext[$value] = -2; //extension line in php.ini but not dll file
}

// Check if it is a zend_extension
foreach($ext as $key => $value) {
	if(array_key_exists($key,$zend_extensions)) {
		$ext[$key] = -4; //dll must be loaded by zend_extension
		// Check if there is content
		if(empty($zend_extensions[$key]['content']))
			$ext[$key] = -5; //Does not exists
	}
}

//we construct the corresponding menu
$extText = ';WAMPPHP_EXTSTART
';
$extTextInfo = "";
$notloadExt = false;
$notloadExtZend = false;
$extTextNoDll = "";
$notDll = false;
$extTextNoline = "";
$notLine = false;

foreach ($ext as $extname=>$extstatus)
{
  if ($ext[$extname] == 1)
    $extText .= 'Type: item; Caption: "'.$extname.'"; Glyph: 13; Action: multi; Actions: php_ext_'.$extname.'
';
  elseif($ext[$extname] == -1)
  {
		if(!$notLine) {
			$extTextNoline .= 'Type: separator; Caption: "'.$w_ext_noline.'"
';
			$notLine = true;
		}
   	//Warning icon to indicate problem with this extension: No extension line in php.ini
    $extTextNoline .= 'Type: item; Caption: "'.$extname.'"; Action: multi; Actions: php_ext_'.$extname.' ; Glyph: 19;
';
	}
  elseif($ext[$extname] == -2)
  {
		if(!$notDll) {
			$extTextNoDll .= 'Type: separator; Caption: "'.$w_ext_nodll.'"
';
			$notDll = true;
		}
   	//Square red icon to indicate problem with this extension: no dll file in ext directory
    $extTextNoDll .= 'Type: item; Caption: "'.$extname.'"; Action: multi; Actions: php_ext_'.$extname.' ; Glyph: 11;
';
	}
  elseif($ext[$extname] == -3)
  {
		if(!$notloadExt) {
			$extTextInfo .= 'Type: separator; Caption: "'.$w_ext_spec.'"
';
			$notloadExt = true;
		}
   	//blue || icon to indicate that the dll must not be loaded by extension = in php.ini
    $extTextInfo .= 'Type: item; Caption: "'.$extname.'"; Action: multi; Actions: php_ext_'.$extname.' ; Glyph: 22;
';
	}
  elseif($ext[$extname] == -4) //Must be loaded by zend_extension
  {
		if(!$notloadExtZend) {
			$extTextInfo .= 'Type: separator; Caption: "'.$w_ext_zend.'"
';
			$notloadExtZend = true;
		}
		$GlyphZend = '';
		if($zend_extensions[$extname]['loaded'] == '1')
			$GlyphZend = "Glyph: 13;";
   	$extTextInfo .= 'Type: item; Caption: "'.$extname.' '.$zend_extensions[$extname]['version'].'"; '.$GlyphZend.'Action: multi; Actions: php_ext_'.$extname.'
';
	}
  elseif($ext[$extname] == -5)
  {
  	 //Zend extension does not exixts - do nothing
  }
  else
  {
    $extText .= 'Type: item; Caption: "'.$extname.'"; Action: multi; Actions: php_ext_'.$extname.'
';
	}
}
$extText .= $extTextNoline.$extTextNoDll.$extTextInfo;

foreach ($ext as $extname=>$extstatus)
{
	if($ext[$extname] == 1 || $ext[$extname] == 0) {
		$SwitchAction = ($ext[$extname] == 1 ? 'off' : 'on');
	$extText .= <<< EOF
[php_ext_${extname}]
Action: service; Service: ${c_apacheService}; ServiceAction: stop; Flags: waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "switchPhpExt.php ${extname} ${SwitchAction}";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "refresh.php";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "net"; Parameters: "start ${c_apacheService}"; ShowCmd: hidden; Flags: waituntilterminated
Action: resetservices;
Action: readconfig;

EOF;
	}
	elseif($ext[$extname] == -4) {
		$SwitchAction = ($zend_extensions[$extname]['loaded'] == 1 ? 'zendoff' : 'zendon');
		$extcontent = $zend_extensions[$extname]['content'];
	$extText .= <<< EOF
[php_ext_${extname}]
Action: service; Service: ${c_apacheService}; ServiceAction: stop; Flags: waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "switchPhpExt.php ${extcontent} ${SwitchAction}";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "refresh.php";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "net"; Parameters: "start ${c_apacheService}"; ShowCmd: hidden; Flags: waituntilterminated
Action: resetservices;
Action: readconfig;

EOF;
	}
	elseif($ext[$extname] == -1 || $ext[$extname] == -2 || $ext[$extname] == -3) {
		if($ext[$extname] == -1) $msgNum = 3;
		elseif($ext[$extname] == -2) $msgNum = 4;
		elseif($ext[$extname] == -3) $msgNum = 5;
    $extText .= '[php_ext_'.$extname.']
Action: run; FileName: "'.$c_phpExe.'";Parameters: "msg.php '.$msgNum.' '.base64_encode($extname).'";WorkingDir: "'.$c_installDir.'/scripts"; Flags: waituntilterminated
';
	}
}

$tpl = str_replace(';WAMPPHP_EXTSTART',$extText,$tpl);

// ************************
// Creating the PHP configuration menu
$myphpini = parse_ini_file($c_phpConfFile);

// values are recovered from the file phpForApache.ini
$phpParams = array_combine($phpParams,$phpParams);
foreach($phpParams as $next_param_name=>$next_param_text) {
  if (isset($myphpini[$next_param_text])) {
  	if(empty($myphpini[$next_param_text]))
  		$params_for_wampini[$next_param_name] = '0';
  	if(array_key_exists($next_param_name, $phpParamsNotOnOff)) {
  		if($phpParamsNotOnOff[$next_param_name]['change'] !== true) {
  	  	$params_for_wampini[$next_param_name] = -2;
  	  	$phpErrorMsg = "\nThe value of this PHP parameter must be modified in the file:\n".$c_phpConfFile."\nNot to change the wrong file, the best way to access this file is:\nWampmanager icon->PHP->php.ini\n";
  		}
  		else {
  	  $params_for_wampini[$next_param_name] = -3;
  		}
  	}
  	elseif((stripos($next_param_name, 'xdebug') !== false) && $zend_extensions['php_xdebug']['loaded'] == '0')
			$params_for_wampini[$next_param_name] = -4; //Extension not loaded - Parameter not to display
  	elseif($myphpini[$next_param_text] == "Off")
  		$params_for_wampini[$next_param_name] = '0';
  	elseif($myphpini[$next_param_text] == 0)
  		$params_for_wampini[$next_param_name] = '0';
  	elseif($myphpini[$next_param_text] == "On")
  		$params_for_wampini[$next_param_name] = '1';
  	elseif($myphpini[$next_param_text] == 1)
  		$params_for_wampini[$next_param_name] = '1';
  	else
  	  $params_for_wampini[$next_param_name] = -2;
  }
  else //Parameter in $phpParams (config.inc.php) does not exist in php.ini
    $params_for_wampini[$next_param_name] = -1;
}

$phpConfText = ";WAMPPHP_PARAMSSTART
";
$phpConfTextInfo = "";
$action_sup = array();
$information_only = false;
foreach ($params_for_wampini as $paramname=>$paramstatus) {
  if ($params_for_wampini[$paramname] == 1)
    $phpConfText .= 'Type: item; Caption: "'.$paramname.'"; Glyph: 13; Action: multi; Actions: '.$phpParams[$paramname].'
';
  elseif ($params_for_wampini[$paramname] == 0) //It does not display non-existent settings in php.ini
    $phpConfText .= 'Type: item; Caption: "'.$paramname.'"; Action: multi; Actions: '.$phpParams[$paramname].'
';
	elseif ($params_for_wampini[$paramname] == -3) { // Indicate different from 0 or 1 or On or Off but can be changed
		$action_sup[] = $paramname;
			$phpConfText .= 'Type: submenu; Caption: "'.$paramname.' = '.$myphpini[$paramname].'"; Submenu: '.$paramname.'; Glyph: 9
';
	}
	elseif ($params_for_wampini[$paramname] == -2) { // I blue to indicate different from 0 or 1 or On or Off
		if(!$information_only) {
			$phpConfTextInfo .= 'Type: separator; Caption: "'.$w_phpparam_info.'"
';
			$information_only = true;
		}
     $phpConfTextInfo .= 'Type: item; Caption: "'.$paramname.' = '.$myphpini[$paramname].'"; Glyph: 22; Action: multi; Actions: '.$phpParams[$paramname].' ;
';
	}
	elseif ($params_for_wampini[$paramname] == -4) {
		// Do nothing
	}

}
//Check for supplemtary actions
$MenuSup = $SubMenuSup = array();
if(count($action_sup) > 0) {
	$i = 0;
	foreach($action_sup as $action) {
		$MenuSup[$i] = $SubMenuSup[$i] = '';
		if($action == 'date.timezone') {
			if($phpParamsNotOnOff[$action]['quoted'])
				$quoted = 'quotes';
			else
				$quoted = 'noquotes';
			$MenuSup[$i] .= '['.$action.']
Type: separator; Caption: "'.$phpParamsNotOnOff[$action]['title'].'"
';
			$tzs = timezone_identifiers_list();
			sort($tzs);
			$regions = $phpParamsNotOnOff[$action]['values'];
			$group = '';
			foreach ($regions as $value) {
			    $MenuSup[$i] .= 'Type: submenu; Caption: "'.$value.'"; Submenu: tz'.$value.'
';
			}
			foreach ($tzs as $tz) {
			  $z = explode('/', $tz, 2);
			  if (count($z) != 2 || !in_array($z[0], $regions)) continue;
			  if ($group != $z[0]) {
			    $group = $z[0];
			    $MenuSup[$i] .= "[tz".$z[0]."]
";
			  }
				$MenuSup[$i] .= 'Type: item; Caption: "'.$tz.'"; Action: multi; Actions: time_'.$tz.'
';
				$SubMenuSup[$i] .= <<< EOF
[time_${tz}]
Action: service; Service: ${c_apacheService}; ServiceAction: stop; Flags: waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "changePhpParam.php ${quoted} ${action} ${tz}";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "refresh.php";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "net"; Parameters: "start ${c_apacheService}"; ShowCmd: hidden; Flags: waituntilterminated
Action: resetservices
Action: readconfig;

EOF;
			}
		}
		else {
			$MenuSup[$i] .= '['.$action.']
Type: separator; Caption: "'.$phpParamsNotOnOff[$action]['title'].'"
';
			$c_values = $phpParamsNotOnOff[$action]['values'];
			if($phpParamsNotOnOff[$action]['quoted'])
				$quoted = 'quotes';
			else
				$quoted = 'noquotes';
			foreach($c_values as $value) {
				$MenuSup[$i] .= 'Type: item; Caption: "'.$value.'"; Action: multi; Actions: '.$action.$value.'
';
				if(strtolower($value) == 'choose') {
					$param_value = '%'.$phpParamsNotOnOff[$action]['title'].'%';
					$param_third = ' '.$phpParamsNotOnOff[$action]['title'];
					if($phpParamsNotOnOff[$action]['title'] == 'Integer')
						$param_third .= ' '.$phpParamsNotOnOff[$action]['min'].'^'.$phpParamsNotOnOff[$action]['max'].'^'.$phpParamsNotOnOff[$action]['default'];
					$c_phpRun = $c_phpExe;
				}
				else {
					$param_value = $value;
					$param_third = '';
					$c_phpRun = $c_phpCli;
				}
				$SubMenuSup[$i] .= <<< EOF
[${action}${value}]
Action: service; Service: ${c_apacheService}; ServiceAction: stop; Flags: waituntilterminated
Action: run; FileName: "${c_phpRun}";Parameters: "changePhpParam.php ${quoted} ${action} ${param_value}${param_third}";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "refresh.php";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "net"; Parameters: "start ${c_apacheService}"; ShowCmd: hidden; Flags: waituntilterminated
Action: resetservices
Action: readconfig;

EOF;
			}
		}
	$i++;
	}
}
$phpConfText .= $phpConfTextInfo;
foreach ($params_for_wampini as $paramname=>$paramstatus)
{
	if($params_for_wampini[$paramname] == 1 || $params_for_wampini[$paramname] == 0) {
		$SwitchAction = ($params_for_wampini[$paramname] == 1 ? 'off' : 'on');
  	$phpConfText .= <<< EOF
[${phpParams[$paramname]}]
Action: service; Service: ${c_apacheService}; ServiceAction: stop; Flags: waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "switchPhpParam.php ${phpParams[$paramname]} ${SwitchAction}";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "refresh.php";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "net"; Parameters: "start ${c_apacheService}"; ShowCmd: hidden; Flags: waituntilterminated
Action: resetservices
Action: readconfig;

EOF;
	}
  elseif ($params_for_wampini[$paramname] == -2)  {//Parameter is neither 'on' nor 'off'
  	$phpConfText .= '['.$phpParams[$paramname].']
Action: run; FileName: "'.$c_phpExe.'";Parameters: "msg.php 6 '.base64_encode($paramname).' '.base64_encode($phpErrorMsg).'";WorkingDir: "'.$c_installDir.'/scripts"; Flags: waituntilterminated
';
	}
}
if(count($MenuSup) > 0) {
	for($i = 0 ; $i < count($MenuSup); $i++)
		$phpConfText .= $MenuSup[$i].$SubMenuSup[$i];
}

$tpl = str_replace(';WAMPPHP_PARAMSSTART',$phpConfText,$tpl);

// ************************
// Creating the menu for Apache modules
$myhttpdContents = @file_get_contents($c_apacheConfFile);
// Recovering the extensions loading configuration
preg_match_all('~^LoadModule\s+([0-9a-z_]+)\s+(?:modules/|)(.+)\r?$~im',$myhttpdContents,$matchesON);
preg_match_all('~^#LoadModule\s+([0-9a-z_]+)\s+(?:modules/|)(.+)\\r?$~im',$myhttpdContents,$matchesOFF);
// Key = module_name - Value = Module loaded = 1, not loaded = 0
$mod = array_fill_keys($matchesON[1], '1') + array_fill_keys($matchesOFF[1], '0');
// Key = module_name - Value = file name in modules/ folder
$mod_load = array_combine($matchesON[1],$matchesON[2]) + array_combine($matchesOFF[1],$matchesOFF[2]);
array_walk($mod_load,function(&$item){$item = trim($item);});
ksort($mod);
ksort($mod_load);

// Retrieve list of modules in the /modules/ folder
$modDirContents = glob($c_apacheVersionDir.'/apache'.$wampConf['apacheVersion'].'/modules/*.so');
array_walk($modDirContents,function(&$item){$item = basename($item);});
$mod_in_modules_dir = array_combine($modDirContents,$modDirContents);

// xxxxx.so file exists but no LoadModule line in httpd.conf
$noModLine = array_diff($mod_in_modules_dir,$mod_load);
foreach($noModLine as $value) {
	$value = str_replace(array("mod_",".so"),array("","_module"),$value);
	$mod[$value] = -2 ; //Module file exists but no loadModule line in httpd.conf
}

// LoadModule line exists in httpd.conf but no xxxxx.so file in modules/ folder
$noModFile = array_diff($mod_load,$mod_in_modules_dir);
foreach($noModFile as $key => $value) {
	$mod[$key] = -1 ; // loadModule line in httpd.conf but no file .so in modules dir
}
// LoadModule should not be disabled
foreach($apacheModNotDisable as $value) {
	if(array_key_exists($value,$mod))
		$mod[$value] = -3 ; //not to be switched in Apache Modules sub-menu
}

$httpdText = 'Type: separator; Caption: "'.$w_apacheModules.'"
';
$httpdTextInfo ="";
$httpdInfo = false;
$httpdTextNoModule ="";
$httpdNoModule = false;
$httpdTextNoLoad ="";
$httpdNoLoad = false;

foreach ($mod as $modname=>$modstatus)
{
  if ($modstatus == 1)
    $httpdText .= 'Type: item; Caption: "'.$modname.'"; Glyph: 13; Action: multi; Actions: apache_mod_'.$modname.'
';
	elseif ($modstatus == -1) { //Red square - No module file
		if(!$httpdNoModule) {
			$httpdTextNoModule .= 'Type: separator; Caption: "'.$w_no_module.'"
';
			$httpdNoModule = true;
		}
		$httpdTextNoModule .= 'Type: item; Caption: "'.$modname.'"; Action: multi; Actions: apache_mod_'.$modname.' ; Glyph: 11;
';
	}
	elseif ($modstatus == -2) {// /!\ Warning - Module file exists but no loadModule line in httpd.conf
		if(!$httpdNoLoad) {
			$httpdTextNoLoad .= 'Type: separator; Caption: "'.$w_no_moduleload.'"
';
			$httpdNoLoad = true;
		}
		$httpdTextNoLoad .= 'Type: item; Caption: "'.$modname.'"; Action: multi; Actions: apache_mod_'.$modname.' ; Glyph: 19;
';
	}
	elseif ($modstatus == -3) {//not to be switched in Apache Modules sub-menu
		if(!$httpdInfo) {
			$httpdTextInfo .= 'Type: separator; Caption: "'.$w_mod_fixed.'"
';
			$httpdInfo = true;
		}
		$httpdTextInfo .= 'Type: item; Caption: "'.$modname.'"; Action: multi; Actions: apache_mod_'.$modname.' ; Glyph: 22;
';
	}
  else
    $httpdText .= 'Type: item; Caption: "'.$modname.'"; Action: multi; Actions: apache_mod_'.$modname.'
';

}

$httpdText = ";WAMPAPACHE_MODSTART
".$httpdTextNoLoad.$httpdTextNoModule.$httpdText.$httpdTextInfo;

foreach ($mod as $modname=>$modstatus)
{
	if ($mod[$modname] == 1 || $mod[$modname] == 0) {
		$SwitchAction = ($mod[$modname] == 1 ? 'on' : 'off');
    $httpdText .= <<< EOF
[apache_mod_${modname}]
Action: service; Service: ${c_apacheService}; ServiceAction: stop; Flags: waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "switchApacheMod.php ${modname} ${SwitchAction}";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "refresh.php";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "net"; Parameters: "start ${c_apacheService}"; ShowCmd: hidden; Flags: waituntilterminated
Action: resetservices
Action: readconfig;

EOF;
	}
	elseif($mod[$modname] == -1 || $mod[$modname] == -2 || $mod[$modname] == -3) {
		if($mod[$modname] == -1) $msgNum = 7;
		elseif($mod[$modname] == -2) $msgNum = 8;
		elseif($mod[$modname] == -3) $msgNum = 12;
		$modFile = 'mod_'.str_replace('_module','',$modname).'.so';
    $httpdText .= '[apache_mod_'.$modname.']
Action: run; FileName: "'.$c_phpExe.'";Parameters: "msg.php '.$msgNum.' '.base64_encode($modname).' '.base64_encode($modFile).'";WorkingDir: "'.$c_installDir.'/scripts"; Flags: waituntilterminated
';
	}
}

$tpl = str_replace(';WAMPAPACHE_MODSTART',$httpdText,$tpl);

// ************************
// Creating alias Apache menu
$aliasDirContents = glob($aliasDir.'/*.conf');
array_walk($aliasDirContents,function(&$item){$item = basename($item);});

$myreplace = $myreplacemenu = $mydeletemenu = '';
foreach ($aliasDirContents as $one_alias)
{
  $mypattern = ';WAMPADDALIAS';
  $newalias_dir = str_replace('.conf','',$one_alias);
  $alias_contents = @file_get_contents ($aliasDir.$one_alias);
  preg_match('|^Alias /'.$newalias_dir.'/ "(.+)"|',$alias_contents,$match);
  $newalias_dest = (isset($match[1])  ? $match[1] : NULL);

	$newalias_dir_ori = $newalias_dir;
	$newalias_dir_del = str_replace(' ','-whitespace-',$newalias_dir);
	$newalias_dir = str_replace(' ','_',$newalias_dir);
  $myreplace .= 'Type: submenu; Caption: "http://localhost/'.$newalias_dir.'/"; SubMenu: alias_'.$newalias_dir.'; Glyph: 3
';

  $myreplacemenu .= <<< EOF

[alias_${newalias_dir}]
Type: separator; Caption: "${newalias_dir}"
Type: item; Caption: "${w_editAlias}"; Glyph: 33; Action: multi; Actions: edit_${newalias_dir}
Type: item; Caption: "${w_deleteAlias}"; Glyph: 32; Action: multi; Actions: delete_${newalias_dir}

EOF;

  $mydeletemenu .= <<< EOF

[delete_${newalias_dir}]
Action: service; Service: ${c_apacheService}; ServiceAction: stop; Flags: waituntilterminated
Action: run; FileName: "${c_phpExe}";Parameters: "deleteAlias.php ${newalias_dir_del}";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "refresh.php";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "net"; Parameters: "start ${c_apacheService}"; ShowCmd: hidden; Flags: waituntilterminated
Action: resetservices
Action: readconfig;
[edit_${newalias_dir}]
Action: run; FileName: "${c_editor}"; parameters:"${c_installDir}/alias/${newalias_dir_ori}.conf"; Flags: waituntilterminated
Action: service; Service: ${c_apacheService}; ServiceAction: restart;

EOF;

}

$tpl = str_replace($mypattern,$myreplace.$myreplacemenu.$mydeletemenu,$tpl);

// ************************
// Versions of PHP
$phpVersionList = listDir($c_phpVersionDir,'checkPhpConf','php');
// Sort in versions number order
natcasesort($phpVersionList);

$myPattern = ';WAMPPHPVERSIONSTART';
$myreplace = $myPattern."
";
$myreplacemenu = '';
foreach ($phpVersionList as $onePhp)
{
  $phpGlyph = '';
  $onePhpVersion = str_ireplace('php','',$onePhp);
  //it checks if the PHP is compatible with the current version of apache
  unset($phpConf);
  include $c_phpVersionDir.'/php'.$onePhpVersion.'/'.$wampBinConfFiles;

  $apacheVersionTemp = $wampConf['apacheVersion'];
  while (!isset($phpConf['apache'][$apacheVersionTemp]) && $apacheVersionTemp != '')
  {
    $pos = strrpos($apacheVersionTemp,'.');
    $apacheVersionTemp = substr($apacheVersionTemp,0,$pos);
  }

  // PHP incompatible with the current version of apache
  $incompatiblePhp = 0;
  if (empty($apacheVersionTemp))
  {
    $incompatiblePhp = -1;
    $phpGlyph = '; Glyph: 19';
		$phpErrorMsg = "apacheVersion = empty in wampmanager.conf file";
  }
  elseif (empty($phpConf['apache'][$apacheVersionTemp]['LoadModuleFile']))
  {
    $incompatiblePhp = -2;
    $phpGlyph = '; Glyph: 19';
		$phpErrorMsg = "\$phpConf['apache']['".$apacheVersionTemp."']['LoadModuleFile'] does not exists or is empty in ".$c_phpVersionDir.'/php'.$onePhpVersion.'/'.$wampBinConfFiles;
  }
  elseif (!file_exists($c_phpVersionDir.'/php'.$onePhpVersion.'/'.$phpConf['apache'][$apacheVersionTemp]['LoadModuleFile']))
  {
    $incompatiblePhp = -3;
    $phpGlyph = '; Glyph: 19';
		$phpErrorMsg = $c_phpVersionDir.'/php'.$onePhpVersion.'/'.$phpConf['apache'][$apacheVersionTemp]['LoadModuleFile']." does not exists.";
  }

  if ($onePhpVersion === $wampConf['phpVersion'])
    $phpGlyph = '; Glyph: 13';

    $myreplace .= 'Type: item; Caption: "'.$onePhpVersion.'"; Action: multi; Actions:switchPhp'.$onePhpVersion.$phpGlyph.'
';
  if ($incompatiblePhp == 0)
  {
  $myreplacemenu .= <<< EOF
[switchPhp${onePhpVersion}]
Action: service; Service: ${c_apacheService}; ServiceAction: stop; Flags: ignoreerrors waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "switchPhpVersion.php ${onePhpVersion}";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "${c_phpExe}";Parameters: "switchMysqlPort.php ${c_UsedMysqlPort}";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "refresh.php";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "net"; Parameters: "start ${c_apacheService}"; ShowCmd: hidden; Flags: waituntilterminated
Action: resetservices
Action: readconfig;

EOF;
  }
  else
  {
  $myreplacemenu .= '[switchPhp'.$onePhpVersion.']
Action: run; FileName: "'.$c_phpExe.'";Parameters: "msg.php 1 '.base64_encode($onePhpVersion).' '.base64_encode($phpErrorMsg).'";WorkingDir: "'.$c_installDir.'/scripts"; Flags: waituntilterminated
';
  }

}

$tpl = str_replace($myPattern,$myreplace.$myreplacemenu,$tpl);

// ************************
// versions of Apache
$apacheVersionList = listDir($c_apacheVersionDir,'checkApacheConf','apache');
// Sort in versions number order
natcasesort($apacheVersionList);

$myPattern = ';WAMPAPACHEVERSIONSTART';
$myreplace = $myPattern."
";
$myreplacemenu = '';

foreach ($apacheVersionList as $oneApache)
{
  $apacheGlyph = '';
  $oneApacheVersion = str_ireplace('apache','',$oneApache);

	//we check if Apache is compatible with the current version of PHP
  unset($phpConf);
  include $c_phpVersionDir.'/php'.$wampConf['phpVersion'].'/'.$wampBinConfFiles;
  $apacheVersionTemp = $oneApacheVersion;
  while (!isset($phpConf['apache'][$apacheVersionTemp]) && $apacheVersionTemp != '')
  {
    $pos = strrpos($apacheVersionTemp,'.');
    $apacheVersionTemp = substr($apacheVersionTemp,0,$pos);
  }

  // Apache incompatible with the current version of PHP
  $incompatibleApache = 0;
  if (empty($apacheVersionTemp))
  {
    $incompatibleApache = -1;
    $apacheGlyph = '; Glyph: 19';
		$apacheErrorMsg = "apacheVersion = empty in wampmanager.conf file";
  }
  elseif (!isset($phpConf['apache'][$apacheVersionTemp]['LoadModuleFile'])
      || empty($phpConf['apache'][$apacheVersionTemp]['LoadModuleFile']))
  {
    $incompatibleApache = -2;
    $apacheGlyph = '; Glyph: 19';
		$apacheErrorMsg = "\$phpConf['apache']['".$apacheVersionTemp."']['LoadModuleFile'] does not exists or is empty in ".$c_phpVersionDir.'/php'.$wampConf['phpVersion'].'/'.$wampBinConfFiles;
  }
  elseif (!file_exists($c_phpVersionDir.'/php'.$wampConf['phpVersion'].'/'.$phpConf['apache'][$apacheVersionTemp]['LoadModuleFile']))
  {
    $incompatibleApache = -3;
    $apacheGlyph = '; Glyph: 23';
		$apacheErrorMsg = $c_phpVersionDir.'/php'.$wampConf['phpVersion'].'/'.$phpConf['apache'][$apacheVersionTemp]['LoadModuleFile']." does not exists.".PHP_EOL.PHP_EOL."First switch on a version of PHP that contains ".$phpConf['apache'][$apacheVersionTemp]['LoadModuleFile']." file before you change to Apache version ".$oneApacheVersion.".";
  }

  //File wamp/bin/apache/apachex.y.z/wampserver.conf
  //Update apache service name if it is modified.
  $ApacheConfFile = $c_apacheVersionDir.'/apache'.$oneApacheVersion.'/'.$wampBinConfFiles;
  $myApacheContents = file_get_contents($ApacheConfFile);
	if(substr_count($myApacheContents, " ".$c_apacheService." ") < 2) {
		$pattern = array(
			"/^.*apacheServiceInstallParams.*\n/m",
			"/^.*apacheServiceRemoveParams.*\n/m");
		$replace = array(
			"\$apacheConf['apacheServiceInstallParams'] = '-n ".$c_apacheService." -k install';\n",
			"\$apacheConf['apacheServiceRemoveParams'] = '-n ".$c_apacheService." -k uninstall';\n");
		$myApacheContents = preg_replace($pattern,$replace,$myApacheContents, 1, $count);
		if(!is_null($myApacheContents) && $count > 0) {
			$fp = fopen($ApacheConfFile,'w');
			fwrite($fp,$myApacheContents);
			fclose($fp);
		}
	}

  unset($apacheConf);
  include $ApacheConfFile;

  if ($oneApacheVersion === $wampConf['apacheVersion'])
    $apacheGlyph = '; Glyph: 13';

  $myreplace .= 'Type: item; Caption: "'.$oneApacheVersion.'"; Action: multi; Actions:switchApache'.$oneApacheVersion.$apacheGlyph.'
';

  if ($incompatibleApache == 0)
  {
    $myreplacemenu .= <<< EOF
[switchApache${oneApacheVersion}]
Action: service; Service: ${c_apacheService}; ServiceAction: stop; Flags: ignoreerrors waituntilterminated
Action: run; Filename: "sc"; Parameters: "\\\\. stop ${c_apacheService}"; ShowCmd: hidden; Flags: waituntilterminated
Action: run; Filename: "sc"; Parameters: "\\\\. delete ${c_apacheService}"; ShowCmd: hidden; Flags: waituntilterminated
Action: closeservices; Flags: ignoreerrors
Action: run; Filename: "taskkill"; Parameters: "/FI ""IMAGENAME eq httpd.exe"" /T /F"; ShowCmd: hidden; Flags: waituntilterminated
Action: run; FileName: "${c_phpExe}";Parameters: "switchApacheVersion.php ${oneApacheVersion}";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "switchPhpVersion.php ${wampConf['phpVersion']}";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "${c_apacheVersionDir}/apache${oneApacheVersion}/${apacheConf['apacheExeDir']}/${apacheConf['apacheExeFile']}"; Parameters: "${apacheConf['apacheServiceInstallParams']}"; ShowCmd: hidden; Flags: waituntilterminated
Action: run; Filename: "sc"; Parameters: "\\\\. config ${c_apacheService} start= demand"; ShowCmd: hidden; Flags: waituntilterminated
Action: run; FileName: "${c_phpExe}";Parameters: "switchWampPort.php ${c_UsedPort}";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "onlineOffline.php ${c_OnOffLine}";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "net"; Parameters: "start ${c_apacheService}"; ShowCmd: hidden; Flags: waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "refresh.php";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: resetservices
Action: readconfig;

EOF;
  }
  else
  {
    $myreplacemenu .= '[switchApache'.$oneApacheVersion.']
Action: run; FileName: "'.$c_phpExe.'";Parameters: "msg.php 2 '.base64_encode($oneApacheVersion).' '.base64_encode($apacheErrorMsg).'";WorkingDir: "'.$c_installDir.'/scripts"; Flags: waituntilterminated
';
  }
}

$tpl = str_replace($myPattern,$myreplace.$myreplacemenu,$tpl);

// *****************************
// DBMS menus
$myDBMSPattern = ';WAMPDBMSMENU';
$myDBMSreplace = $myDBMSPattern."
";
if($noDBMS) {
	$myDBMSreplace .= <<< EOF
Type: separator; Caption: "${w_noDBMS}"
Type: separator
EOF;
}
else {
	$myDBMSreplacearray = array();
	$DBMSdefault = 'none';
	// MySQL versions and settings
	if($wampConf['SupportMySQL'] == 'on') {
		$glyph = '28';
		if($c_UsedMysqlPort == $c_DefaultMysqlPort) {
			$glyph = '36';
			$DBMSdefault = 0;
		}
		$myDBMSreplacearray[] = <<< EOF
Type: submenu; Caption: "MySQL		${c_mysqlVersion}"; SubMenu: mysqlMenu; Glyph: ${glyph}

EOF;
		include 'refreshMySQL.php';
	}
	//MariaDB versions and settings
	if($wampConf['SupportMariaDB'] == 'on') {
		$glyph = '28';
	if($c_UsedMariaPort == $c_DefaultMysqlPort) {
		$glyph = '36';
		$DBMSdefault = 1;
	}
	$myDBMSreplacearray[] = <<< EOF
Type: submenu; Caption: "MariaDB		${c_mariadbVersion}"; SubMenu: mariadbMenu; Glyph: ${glyph}

EOF;
		include 'refreshMariadb.php';
	}
	if(count($myDBMSreplacearray) > 1 && $DBMSdefault == 1) {
		krsort($myDBMSreplacearray);
	}
	foreach($myDBMSreplacearray as $value)
		$myDBMSreplace .= $value;
}
$tpl = str_replace($myDBMSPattern,$myDBMSreplace,$tpl);

// ***************
//Projects submenu
if($wampConf['ProjectSubMenu'] == "on")
{
	//Add item for submenu
	$myPattern = ';WAMPPROJECTSUBMENU';
	$myreplace = $myPattern."
";
	$myreplacesubmenu = 'Type: submenu; Caption: "'.$w_projectsSubMenu.'"; Submenu: myProjectsMenu; Glyph: 3
';
	$tpl = str_replace($myPattern,$myreplace.$myreplacesubmenu,$tpl);

	//Add submenu
	$myPattern = ';WAMPMENULEFTEND';
	$myreplace = $myPattern."
";
	$myreplacesubmenu = '

[myProjectsMenu]
;WAMPPROJECTMENUSTART
;WAMPPROJECTMENUEND

';
	$tpl = str_replace($myPattern,$myreplace.$myreplacesubmenu,$tpl);

	//Construct submenu
	$myPattern = ';WAMPPROJECTMENUSTART';
	$myreplace = $myPattern."
Type: separator; Caption: \"".$w_projectsSubMenu."\"
";
	// Place projects into submenu Hosts
	// Folder to ignore in projects
	$projectsListIgnore = $projectsListIgnore = array ('.','..','wampthemes','wamplangues');
	// List projects
	$myDir = $wwwDir;
	if(substr($myDir,-1) != "/")
		$myDir .= "/";
	$handle=opendir($myDir);
	$projectContents = array();
	while (($file = readdir($handle))!==false)
	{
		if (is_dir($myDir.$file) && !in_array($file,$projectsListIgnore))
			$projectContents[] = $file;
	}
	closedir($handle);

	$myreplacesubmenuProjects = '';
	if (count($projectContents) > 0)
	{
		for($i = 0 ; $i < count($projectContents) ; $i++)
		{ //Support de suppressLocalhost dans wampmanager.conf
			$myreplacesubmenuProjects .= 'Type: item; Caption: "'.$projectContents[$i].'"; Action: run; FileName: "'.$c_navigator.'"; Parameters: "';
			if($c_suppressLocalhost)
				 $myreplacesubmenuProjects .= $c_edge.'http://'.$projectContents[$i].$UrlPort.'/"';
			else
				$myreplacesubmenuProjects .= $c_edge.'http://localhost'.$UrlPort.'/'.$projectContents[$i].'/"';
			$myreplacesubmenuProjects .= '; Glyph: 5
';
		}
	}
	$tpl = str_replace($myPattern,$myreplace.$myreplacesubmenuProjects,$tpl);
}
// ************
//Submenu Alias
if($wampConf['AliasSubmenu'] == "on")
{
	//Add item for submenu
	$myPattern = ';WAMPALIASSUBMENU';
	$myreplace = $myPattern."
";
	$myreplacesubmenu = 'Type: submenu; Caption: "'.$w_aliasSubMenu.'"; Submenu: myAliasMenu; Glyph: 3
';
	$tpl = str_replace($myPattern,$myreplace.$myreplacesubmenu,$tpl);

	//Add submenu
	$myPattern = ';WAMPMENULEFTEND';
	$myreplace = $myPattern."
";
	$myreplacesubmenu = '

[myAliasMenu]
;WAMPALIASMENUSTART
;WAMPALIASMENUEND

';
	$tpl = str_replace($myPattern,$myreplace.$myreplacesubmenu,$tpl);

	//Construct submenu
	$myPattern = ';WAMPALIASMENUSTART';
	$myreplace = $myPattern."
Type: separator; Caption: \"".$w_aliasSubMenu."\"
";
	// Place projects into submenu Hosts
	// Folder to ignore in projects
	$AliasListIgnore = array ('.','..');
	// récupération des alias
	$AliasContents = array();
	if (is_dir($aliasDir)) {
    $handle=opendir($aliasDir);
    while (($file = readdir($handle))!==false) {
	    if (is_file($aliasDir.$file) && strstr($file, '.conf')) {
		    $AliasContents[] = str_replace('.conf','',$file);
	    }
    }
    closedir($handle);
	}
	$myreplacesubmenuAlias = '';
	if (count($AliasContents) > 0)	{
		foreach($AliasContents as $AliasValue) {
			$glyph = '5';
			if(strpos($AliasValue,'phpmyadmin') !== false || strpos($AliasValue,'adminer') !== false)
				$glyph = '28';
			$myreplacesubmenuAlias .= 'Type: item; Caption: "'.$AliasValue.'"; Action: run; FileName: "'.$c_navigator.'"; Parameters: "';
			$myreplacesubmenuAlias .= $c_edge.'http://localhost'.$UrlPort.'/'.$AliasValue.'/"; Glyph: '.$glyph.'
';
		}
		$tpl = str_replace($myPattern,$myreplace.$myreplacesubmenuAlias,$tpl);
	}
}
// ********************
//Submenu Virtual Hosts
if($wampConf['VirtualHostSubMenu'] == "on")
{
	//Add item for submenu
	$myPattern = ';WAMPVHOSTSUBMENU';
	$myreplace = $myPattern."
";
	$myreplacesubmenu = 'Type: submenu; Caption: "'.$w_virtualHostsSubMenu.'"; Submenu: myVhostsMenu; Glyph: 3
';
	$tpl = str_replace($myPattern,$myreplace.$myreplacesubmenu,$tpl);
	//Add submenu
	$myPattern = ';WAMPMENULEFTEND';
	$myreplace = $myPattern."
";
	$myreplacesubmenu = '

[myVhostsMenu]
;WAMPVHOSTMENUSTART
;WAMPVHOSTMENUEND

';
	$tpl = str_replace($myPattern,$myreplace.$myreplacesubmenu,$tpl);
	$myPattern = ';WAMPVHOSTMENUSTART';
	$myreplace = $myPattern."
Type: separator; Caption: \"".$w_virtualHostsSubMenu."\"
";
	$myreplacesubmenuVhosts = '';

	$virtualHost = check_virtualhost();

	//is Include conf/extra/httpd-vhosts.conf uncommented?
	if($virtualHost['include_vhosts'] === false) {
		$myreplacesubmenuVhosts .= 'Type: item; Caption: "Virtual Host ERROR"; Action: multi; Actions: server_not_included; Glyph: 21
';
    $myreplacesubmenuVhosts .= '[server_not_included]
Action: run; FileName: "'.$c_phpExe.'";Parameters: "msg.php 14";WorkingDir: "'.$c_installDir.'/scripts"; Flags: waituntilterminated
';
	}
	else
	{
		if($virtualHost['vhosts_exist'] === false) {
			$myreplacesubmenuVhosts .= 'Type: item; Caption: "Virtual Host ERROR"; Action: multi; Actions: server_not_exists; Glyph: 21
';
    	$myreplacesubmenuVhosts .= '[server_not_exists]
Action: run; FileName: "'.$c_phpExe.'";Parameters: "msg.php 15 '.base64_encode($virtualHost['vhosts_file']).'";WorkingDir: "'.$c_installDir.'/scripts"; Flags: waituntilterminated
';
		}
		else
		{
			$server_name = array();

			if($virtualHost['nb_Server'] > 0)
			{
				$nb_Server = $virtualHost['nb_Server'];
				$nb_Virtual = $virtualHost['nb_Virtual'];
				$nb_Document = $virtualHost['nb_Document'];
				$nb_Directory = $virtualHost['nb_Directory'];
				$nb_End_Directory = $virtualHost['nb_End_Directory'];

				$port_number = true;
				//Check number of <Directory equals to number of </Directory
				if($nb_End_Directory != $nb_Directory) {
					$value = "ServerName_Directory";
					$server_name[$value] = -2;
					$myreplacesubmenuVhosts .= 'Type: item; Caption: "'.$value.'"; Action: multi; Actions: server_'.$value.'; Glyph: 23
';
				}
				//Check number of DocumentRoot equals to number of ServerName
				if($nb_Document != $nb_Server) {
					$value = "ServerName_Document";
					$server_name[$value] = -7;
					$myreplacesubmenuVhosts .= 'Type: item; Caption: "'.$value.'"; Action: multi; Actions: server_'.$value.'; Glyph: 23
';
				}
				//Check validity of DocumentRoot
				$documentPathError = '';
				if($virtualHost['document'] === false) {
					foreach($virtualHost['documentPath'] as $value) {
						if($virtualHost['documentPathValid'][$value] === false) {
							$documentPathError = $value;
							break;
						}
					}
					$value = "DocumentRoot_error";
					$server_name[$value] = -8;
					$myreplacesubmenuVhosts .= 'Type: item; Caption: "'.$value.'"; Action: multi; Actions: server_'.$value.'; Glyph: 23
';
				}
				//Check validity of Directory Path
				$directoryPathError = '';
				if($virtualHost['directory'] === false) {
					foreach($virtualHost['directoryPath'] as $value) {
						if($virtualHost['directoryPathValid'][$value] === false) {
							$directoryPathError = $value;
							break;
						}
					}
					$value = "Directory_Path_error";
					$server_name[$value] = -9;
					$myreplacesubmenuVhosts .= 'Type: item; Caption: "'.$value.'"; Action: multi; Actions: server_'.$value.'; Glyph: 23
';
				}

				//Check number of <VirtualHost equals or > to number of ServerName
				if($nb_Server != $nb_Virtual && $wampConf['NotCheckDuplicate'] == 'off') {
					$value = "ServerName_Virtual";
					$server_name[$value] = -3;
					$port_number = false;
					$myreplacesubmenuVhosts .= 'Type: item; Caption: "'.$value.'"; Action: multi; Actions: server_'.$value.'; Glyph: 23
';
				}

				//Check number of port definition of <VirtualHost *:xx> equals to number of ServerName
				if($virtualHost['nb_Virtual_Port'] != $nb_Virtual) {
					$value = "VirtualHost_Port";
					$server_name[$value] = -4;
					$port_number = false;
					$myreplacesubmenuVhosts .= 'Type: item; Caption: "'.$value.'"; Action: multi; Actions: server_'.$value.'; Glyph: 23
';
				}
				//Check validity of port number
				if($port_number && $virtualHost['port_number'] === false) {
					$value = "VirtualHost_PortValue";
					$server_name[$value] = -5;
					$port_number = false;
					$myreplacesubmenuVhosts .= 'Type: item; Caption: "'.$value.'"; Action: multi; Actions: server_'.$value.'; Glyph: 23
';
				}
				//Check if duplicate ServerName
				if($virtualHost['nb_duplicate'] > 0) {
					$DuplicateNames = '';
					$value = "Duplicate_ServerName";
					$server_name[$value] = -10;
					foreach($virtualHost['duplicate'] as $NameValue)
						$DuplicateNames .= "\r\n\t".$NameValue;
					$myreplacesubmenuVhosts .= 'Type: item; Caption: "'.$value.'"; Action: multi; Actions: server_'.$value.'; Glyph: 23
';
				}

				foreach($virtualHost['ServerName'] as $key => $value) {
					if($virtualHost['ServerNameValid'][$value] === false) {
						$myreplacesubmenuVhosts .= 'Type: item; Caption: "'.$value.'"; Action: multi; Actions: server_'.$value.'; Glyph: 20
';
						$server_name[$value] = -1;
					}
					elseif($virtualHost['ServerNameValid'][$value] === true) {
						$UrlPortVH = ($virtualHost['ServerNamePort'][$value] != '80') ? ':'.$virtualHost['ServerNamePort'][$value] : '';
						if(!$virtualHost['port_listen'] && $virtualHost['ServerNamePortListen'][$value] !== true) {
							$myreplacesubmenuVhosts .= 'Type: item; Caption: "'.$value.'"; Action: multi; Actions: server_'.$value.'; Glyph: 23
';
							$server_name[$value] = -12;
						}
						elseif($virtualHost['ServerNameIp'][$value] !== false) {
							$vh_ip = $virtualHost['ServerNameIp'][$value];
							if($virtualHost['ServerNameIpValid'][$value] !== false) {
								$myreplacesubmenuVhosts .= 'Type: item; Caption: "'.$vh_ip.' ('.$value.')"; Action: run; FileName: "'.$c_navigator.'"; Parameters: "'.$c_edge.'http://'.$vh_ip.$UrlPortVH.'/"; Glyph: 5
';
								$server_name[$value] = 1;
							}
							else {
								$myreplacesubmenuVhosts .= 'Type: item; Caption: "'.$vh_ip.' ('.$value.')"; Action: multi; Actions: server_'.$value.'; Glyph: 20
';
								$server_name[$value] = -11;
							}
						}
						else {
							$glyph = '5';
							if($value == 'localhost')
								$glyph = '27';
							$myreplacesubmenuVhosts .= 'Type: item; Caption: "'.$value.'"; Action: run; FileName: "'.$c_navigator.'"; Parameters: "'.$c_edge.'http://'.$value.$UrlPortVH.'/"; Glyph: '.$glyph.'
';
							$server_name[$value] = 1;
						}
					}
					else {
						$myreplacesubmenuVhosts .= 'Type: item; Caption: "'.$value.'"; Action: multi; Actions: server_'.$value.'; Glyph: 20
';
						$server_name[$value] = -6;
					}
				} //End foreach
				$myreplacesubmenuVhosts .= 'Type: separator
Type: item; Caption: "'.$w_add_VirtualHost.'"; Action: run; FileName: "'.$c_navigator.'"; Parameters: "'.$c_edge.'http://localhost'.$UrlPort.'/add_vhost.php"; Glyph: 33
';
				foreach($server_name as $name=>$value) {
					if($server_name[$name] != 1) {
						if($server_name[$name] == -1) {
    					$myreplacesubmenuVhosts .= '[server_'.$name.']
Action: run; FileName: "'.$c_phpExe.'";Parameters: "msg.php 9 '.base64_encode($name).'";WorkingDir: "'.$c_installDir.'/scripts"; Flags: waituntilterminated
';
						}
						else {
							if($server_name[$name] == -2)
								$message = "In the httpd-vhosts.conf file:\r\n\r\n\tThe number of\r\n\r\n\t\t<Directory ...>\r\n\t\tis not equal to the number of\r\n\r\n\t\t</Directory>\r\n\r\nThey should be identical.";
							elseif($server_name[$name] == -3)
								$message = "In the httpd-vhosts.conf file:\r\n\r\n\tThe number of\r\n\r\n\t\t<VirtualHost ...>\r\n\tis not equal to the number of\r\n\r\n\t\tServerName\r\n\r\nThey should be identical.\r\n\r\n\tCorrect syntax is: <VirtualHost *:80>\r\n";
							elseif($server_name[$name] == -4)
								$message = "In the httpd-vhosts.conf file:\r\n\r\n\tPort number into <VirtualHost *:port>\r\n\tis not defined for all\r\n\r\n\t\t<VirtualHost...>\r\n\r\n\tCorrect syntax is: <VirtualHost *:xx>\r\n\r\n\t\twith xx = port number [80 by default]\r\n";
							elseif($server_name[$name] == -5)
								$message = "In the httpd-vhosts.conf file:\r\n\r\n\tPort number into <VirtualHost *:port>\r\n\thas not correct value\r\n\r\nValue are:".print_r($virtualHost['virtual_port'],true)."\r\n";
							elseif($server_name[$name] == -6)
								$message = "The httpd-vhosts.conf file has not been cleaned.\r\nThere remain VirtualHost examples like: dummy-host.example.com\r\n";
							elseif($server_name[$name] == -7)
								$message = "In the httpd-vhosts.conf file:\r\n\r\n\tThe number of\r\n\r\n\t\tDocumentRoot\r\n\tis not equal to the number of\r\n\r\n\t\tServerName\r\n\r\nThey should be identical.\r\n";
							elseif($server_name[$name] == -8)
								$message = "In the httpd-vhosts.conf file:\r\n\r\nThe DocumentRoot path\r\n\r\n\t".$documentPathError."\r\n\r\ndoes not exits\r\n";
							elseif($server_name[$name] == -9)
								$message = "In the httpd-vhosts.conf file:\r\n\r\nThe Directory path\r\n\r\n\t".$directoryPathError."\r\n\r\ndoes not exits\r\n";
							elseif($server_name[$name] == -10)
								$message = "In the httpd-vhosts.conf file:\r\n\r\nThere is duplicate ServerName\r\n".$DuplicateNames."\r\n";
							elseif($server_name[$name] == -11)
								$message = "In the httpd-vhosts.conf file:\r\n\r\nThe IP used for the VirtualHost is not valid local IP\r\n";
							elseif($server_name[$name] == -12)
								$message = "In the httpd-vhost.conf file:\r\n\r\nThe Port used (".$virtualHost['ServerNamePortListen'][$name].") for the VirtualHost ".$name." is not a Listen port\r\n";
    					$myreplacesubmenuVhosts .= '[server_'.$name.']
Action: run; FileName: "'.$c_phpExe.'";Parameters: "msg.php 11 '.base64_encode($message).'";WorkingDir: "'.$c_installDir.'/scripts"; Flags: waituntilterminated
';
						}
					}
				}
			}
		}
	}
	$tpl = str_replace($myPattern,$myreplace.$myreplacesubmenuVhosts,$tpl);
}

// *********************************
//Right submenu Wampmanager settings
foreach($wamp_Param as $value) {
  if (isset($wampConf[$value]))
  {
    $wampConfParams[$value] = $value;
    if ($wampConf[$value] == 'on')
      $params_for_wampconf[$value] = '1';
    elseif ($wampConf[$value] == 'off')
      $params_for_wampconf[$value] = '0';
    else
      $params_for_wampconf[$value] = '-1';
  }
  elseif(strpos($value, '##') !== false) { // Separator
  	$value = substr($value,2);
  	$params_for_wampconf[$value] = -2;
  }
  else {//Parameter does not exist in wampmanager.conf
    $params_for_wampconf[$value] = -1;
    $wampConfParams[$value] = $value;
  }
}
$wampConfActions = '';
$wampConfText = ";WAMPSETTINGSSTART
Type: Separator; Caption: \"".$w_wampSettings."\"
";
foreach ($params_for_wampconf as $paramname=>$paramstatus) {
  if ($params_for_wampconf[$paramname] == 1) {
    $wampConfText .= 'Type: item; Caption: "'.$w_settings[$paramname].'"; Glyph: 13; Action: multi; Actions: '.$wampConfParams[$paramname].'
';
		$SwitchAction = 'off';
	}
  elseif ($params_for_wampconf[$paramname] == 0) {
    $wampConfText .= 'Type: item; Caption: "'.$w_settings[$paramname].'"; Action: multi; Actions: '.$wampConfParams[$paramname].'
';
		$SwitchAction = 'on';
	}
  elseif ($params_for_wampconf[$paramname] == -1) {
    $wampConfText .= 'Type: item; Caption: "'.$w_settings[$paramname].'"; Action: multi; Actions: '.$wampConfParams[$paramname].' ;Glyph: 11;
';
		$SwitchAction = 'create off [options]';
	}
  if ($params_for_wampconf[$paramname] == -2) {
    $wampConfText .= 'Type: Separator; Caption: "'.$w_settings[$paramname].'"
';
	}
	else {
	$php_exe_type = (in_array($paramname,$wamp_ParamPhpExe)) ? $c_phpExe : $c_phpCli ;
  $wampConfActions .= <<< EOF
[${wampConfParams[$paramname]}]
Action: service; Service: ${c_apacheService}; ServiceAction: stop; Flags: waituntilterminated
Action: run; FileName: "${php_exe_type}";Parameters: "switchWampParam.php ${wampConfParams[$paramname]} ${SwitchAction}";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "refresh.php";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "net"; Parameters: "start ${c_apacheService}"; ShowCmd: hidden; Flags: waituntilterminated
Action: resetservices
Action: readconfig;

EOF;
	}
}

$tpl = str_replace(';WAMPSETTINGSSTART',$wampConfText.$wampConfActions,$tpl);

// ************************
// Tool delete old versions
$delOldVer = ";WAMPDELETEOLDVERSIONSSTART
Type: separator; Caption: \"".$w_deleteVer."\"
";
$delOldVerMenu = $delOldVerSub = '';
$Versions = ListVersions();
foreach(array_keys($Versions) as $appli) {
	if(count($Versions[$appli]) > 0) {
		$delOldVerMenu .= "Type: separator; Caption: \" ".strtoupper($appli)." \"
";
		foreach ($Versions[$appli] as $appliVersion) {
  		$delOldVerMenu .= 'Type: item; Caption: "'.$w_delete.' '.$appli.' '.$appliVersion.'"; Glyph: 32; Action: multi; Actions: del_'.$appli.$appliVersion.'
';
		}
		foreach ($Versions[$appli] as $appliVersion) {
			$delOldVerSub .= <<< EOF
[del_${appli}${appliVersion}]
Action: run; FileName: "${c_phpCli}";Parameters: "deleteVersion.php ${appli} ${appliVersion}";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "refresh.php";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: resetservices
Action: readconfig;

EOF;
		}
	}
}
$tpl = str_replace(';WAMPDELETEOLDVERSIONSSTART',$delOldVer.$delOldVerMenu.$delOldVerSub,$tpl);


//*******************************
// Tool delete Listen Port Apache
if($ListenPortsExists) {
	$ForbidenToDel = array('80', '8080',$c_DefaultPort, $c_UsedPort);
	$delListenPort = ";WAMPDELETELISTENPORTSTART
Type: separator; Caption: \"".$w_deleteListenPort."\"
";
	$delListenPortMenu = $delListenPortSub = '';
	foreach($c_listenPort as $ListenPort) {
		if(!in_array($ListenPort,$ForbidenToDel)) {
 			$delListenPortMenu .= 'Type: item; Caption: "'.$w_delete.' Listen port Apache '.$ListenPort.'"; Glyph: 32; Action: multi; Actions: del_apache_port'.$ListenPort.'
';
			$delListenPortSub .= <<< EOF
[del_apache_port${ListenPort}]
Action: service; Service: ${c_apacheService}; ServiceAction: stop; Flags: ignoreerrors waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "ListenPortApache.php delete ${ListenPort}";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: service; Service: ${c_apacheService}; ServiceAction: startresume; Flags: ignoreerrors waituntilterminated
Action: run; FileName: "${c_phpCli}";Parameters: "refresh.php";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated
Action: resetservices
Action: readconfig;

EOF;
		}
	}
$tpl = str_replace(';WAMPDELETELISTENPORTSTART',$delListenPort.$delListenPortMenu.$delListenPortSub,$tpl);
}

//Add warnings if needed
if($WarningsAtEnd) {
	$WarningTextAll = '
Type: Separator;
';
	$tpl = str_replace(';WAMPMENULEFTEND',$WarningTextAll.$WarningMenu.$WarningText,$tpl);
}

// ************************
//The creation of wampmanager.ini file is complete, save the file.
$fp = fopen($wampserverIniFile,'w');
fwrite($fp,$tpl);
fclose($fp);

//Check alias and paths in httpd-autoindex.conf
check_autoindex();

//Checking symbolic links from Apache/bin
//  on the dll files and phpForApache.ini in the active version of php
linkPhpDllToApacheBin($wampConf['phpVersion']);

if(!file_exists($c_installDir.'/logs/php_error.log'))
	error_log("No error - Only to create the file");

?>