index.php 8.39 KB
Newer Older
David's avatar
David committed
1
<?php
David's avatar
David committed
2
$CalcPvAutonomeVersion='4.2';
David's avatar
David committed
3 4
include_once('./lib/Fonction.php');
$config_ini = parse_ini_file('./config.ini', true); 
5
$lang_ini = parse_ini_file('./lang/lang.ini',true);
David's avatar
David committed
6

David's avatar
David committed
7 8 9
// Dans les URL on utilisera les codes langues https://support.crowdin.com/api/language-codes/
// On a une fonction pour retrouve le local à partir (et vis et versa)

David's avatar
David committed
10
// Fonction de langue : 
David's avatar
David committed
11
include('./lang/lang-dispo.php');
David's avatar
David committed
12 13

// Détection et redirection (langue toujours)
David's avatar
David committed
14 15 16 17 18
if (isset($_GET['langue'])) {
	$locale = lang2locale($_GET['langue']);
	$localeshort=locale2lang($locale);
	if ($_COOKIE['langue'] != $localeshort) {
		setcookie("langue",$localeshort,strtotime( '+1 year' ));
David's avatar
David committed
19
	}
David's avatar
David committed
20
} elseif (isset($_COOKIE['langue'])) {
David's avatar
David committed
21
	$locale = lang2locale($_COOKIE['langue']);
22 23
	$lang=locale2lang($locale);
	header('Location: '.addLang2url($lang));
David's avatar
David committed
24
} else {
25 26 27 28 29 30 31 32 33 34 35 36 37 38
	$HTTP_ACCEPT_LANGUAGE=$_SERVER['HTTP_ACCEPT_LANGUAGE'];
	//echo $HTTP_ACCEPT_LANGUAGE.'<br />';
	$lang_from_http_accept = explode(',', $HTTP_ACCEPT_LANGUAGE);
	//echo $lang_from_http_accept[0].'<br />';
	$locale = lang2locale($lang_from_http_accept[0]);
	if (substr($locale,0,2) != substr($lang_from_http_accept[0],0,2)) {
		//echo "Non trouvé, 2ème tentative";
		$lang_from_http_accept = explode('-', $lang_from_http_accept[0]);
		//echo $lang_from_http_accept[0].'<br />';
		$locale = lang2locale($lang_from_http_accept[0]);
	}
	//echo $locale.'<br />';
	$lang = locale2lang($locale);
	//echo $lang.'<br />';
39
	header('Location: '.addLang2url($lang));
David's avatar
David committed
40
	exit();
David's avatar
David committed
41
}
David's avatar
David committed
42

David's avatar
David committed
43
// Définition de la langue :
David's avatar
David committed
44
$results=putenv("LC_ALL=$locale.utf8");
David's avatar
David committed
45 46 47
if (!$results) {
    exit ('putenv failed');
}
David's avatar
David committed
48
$results=putenv("LC_LANG=$locale.utf8");
David's avatar
David committed
49 50 51
if (!$results) {
    exit ('putenv failed');
}
David's avatar
David committed
52
$results=putenv("LC_LANGUAGE=$locale.utf8");
David's avatar
David committed
53 54 55
if (!$results) {
    exit ('putenv failed');
}
David's avatar
David committed
56
$results=setlocale(LC_ALL, "$locale.utf8");
David's avatar
David committed
57 58 59
if (!$results) {
    exit ('setlocale failed: locale function is not available on this platform, or the given local does not exist in this environment');
}
David's avatar
David committed
60 61 62 63 64 65
bindtextdomain("messages", "./lang");
textdomain("messages");
// Définition du pays (selon l'IP
$country = @geoip_country_code_by_name(get_ip());

?>
root's avatar
root committed
66
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
David's avatar
David committed
67 68 69 70 71 72
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php if ($localeshort == 'fa') { ?>
	<html xmlns="http://www.w3.org/1999/xhtml"  dir="rtl"  xml:lang="<?= $localeshort ?>" lang="<?= $localeshort ?>
<?php } else { ?>
	<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?= $localeshort ?>" lang="<?= $localeshort ?>
<?php } ?>
root's avatar
root committed
73
<head>
74
	<title>[CalcPvAutonome] <?= _('Calculate/size photovoltaic stand-alone (autonomous) set') ?></title>
root's avatar
root committed
75 76
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<link href="./lib/style.css" media="screen" rel="stylesheet" type="text/css" />	
77 78
	<meta http-equiv="Pragma" content="no-cache">
	<meta http-equiv="Expires" content="-1">
79 80 81 82 83 84 85
	<?php if ($localeshort == 'aa') { ?>
		<script type="text/javascript">
			var _jipt = [];
			_jipt.push(['project', 'calcpvautonome']);
		</script>
		<script type="text/javascript" src="//cdn.crowdin.com/jipt/jipt.js"></script>
	<?php } ?>
86 87 88 89 90 91 92 93 94 95 96
	<script> 
	<!-- https://www.browser-update.org/ -->
	var $buoop = {vs:{i:10,f:40,o:-8,s:8,c:50},api:4}; 
	function $buo_f(){ 
	 var e = document.createElement("script"); 
	 e.src = "//browser-update.org/update.min.js"; 
	 document.body.appendChild(e);
	};
	try {document.addEventListener("DOMContentLoaded", $buo_f,false)}
	catch(e){window.attachEvent("onload", $buo_f)}
	</script>
root's avatar
root committed
97
	<script src="./lib/jquery-3.1.1.slim.min.js"></script> 
root's avatar
root committed
98 99
</head>
<body>
David's avatar
David committed
100
		<div id="langues">
David's avatar
David committed
101
			<?php 
102 103
			ksort($lang_ini);
			foreach($lang_ini as $lang) {
David's avatar
David committed
104
				$flag='';
David's avatar
David committed
105
				if ($localeshort == $lang['code']) {
David's avatar
David committed
106 107
					$flag=' drapeauActif';
				}
108 109 110 111 112 113
				echo '<a id="href'.$lang['code'].'" href="'.replaceLang2url($lang['code']).'"><img class="drapeau'.$flag.'" src="./lib/'.$lang['code'].'.png" alt="'.$lang['code'].'" width="23" height="15" /></a>';
				echo '<script type="text/javascript">
					$( "#href'.$lang['code'].'" ) .mouseover(function() {
						$("#languesLegende").show();';
						if ($lang['code'] == 'aa') {
							echo '$("#languesLegende").html("<b>Contribute to translation</b> (in-context)");';
David's avatar
David committed
114 115
						} else if ($lang['translated_progress'] < 90) {
							echo '$("#languesLegende").html("<b>'.$lang['code'].'</b> '._('partial translation').' ('.$lang['translated_progress'].'%)");';
116
						} else {
David's avatar
David committed
117
							echo '$("#languesLegende").html("<b>'.$lang['code'].'</b> ('.$lang['translated_progress'].'%)");';
118 119 120 121 122 123
						}
				echo '})
					.mouseout(function() {
						$("#languesLegende").hide();
					});
					</script>';
David's avatar
David committed
124 125
			}
			?>
126
			<!--<a href="https://crwd.in/calcpvautonome"><img class="drapeau" src="./lib/trad.png" alt="Help to translate" /></a>-->
David's avatar
David committed
127
		</div>
128 129
		<div id="languesLegende" style="display: none"></div>
	<div id="page-wrap">
130
		<?php
131
		$footer=true;
root's avatar
root committed
132
		if (isset($_GET['p']) && $_GET['p'] == 'CalcConsommation'
David's avatar
David committed
133 134
		 || isset($_GET['p']) && $_GET['p'] == 'CalcConso'
		 || $_SERVER['HTTP_HOST'] == 'conso.calcpv.net'
root's avatar
root committed
135 136
		 || $_SERVER['HTTP_HOST'] == 'calconso.zici.fr'
		 || $_SERVER['HTTP_HOST'] == 'calcconso.zici.fr') {
137
			echo '<h1>'._('Calculate daily electric needs').'</h1>';
root's avatar
root committed
138
			@include_once('./header.php');
David's avatar
David committed
139
			echo _('<p>Go to the <a href="https://crwd.in/calcpvautonome" target="_blank">colaborative translation platform</a> to help us translate this free software.</p>');
140
			include('./CalcConsommation.php'); 
root's avatar
root committed
141
			@include_once('./bottom.php'); 
142 143 144
		} elseif (isset($_GET['p']) && $_GET['p'] == 'Modeles') {
			include('./Modeles.php'); 
			$footer=false;
145
		} else {
146
			echo '<h1>'._('Calculate/size photovoltaic stand-alone (autonomous) set').'</h1>';
root's avatar
root committed
147
			@include_once('./header.php'); 
David's avatar
David committed
148
			echo _('<p>Go to the <a href="https://crwd.in/calcpvautonome" target="_blank">colaborative translation platform</a> to help us translate this free software.</p>');
149
			include('./CalcPvAutonome.php'); 
root's avatar
root committed
150
			@include_once('./bottom.php'); 
151
		}
152
		if ($footer == true) {
153
		?>
root's avatar
root committed
154
		<div id="footer">
David's avatar
David committed
155 156
			<?php if ($localeshort != 'fr') { ?>
            <p class="footer_translator"><?= _('Thanks to') ?> : 
157 158 159 160 161 162 163 164 165 166 167
            <?php
				$nb_translator=0;
				foreach($lang_ini[$localeshort] as $key => $value) {
					if (substr($key, 0, 10) == 'translator') {
						$nb_translator++;
						if ($nb_translator != 1) {
							echo ', ';
						}
						echo $value['name'];
					}
				}
David's avatar
David committed
168
            ?>
David's avatar
David committed
169
            <?= _('for this <a target="_blank" href="https://crwd.in/calcpvautonome">translation</a>') ?></p>
David's avatar
David committed
170
            <?php } ?>
David's avatar
David committed
171
            <?=  _('<p>Go to the <a href="https://crwd.in/calcpvautonome" target="_blank">colaborative translation platform</a> to help us translate this free software.</p>'); ?>
David's avatar
David committed
172 173
            <p class="footer_right"><?= _('By') ?> <a href="http://david.mercereau.info/">David Mercereau</a> (<a href="https://framagit.org/kepon/CalcPvAutonome"><?= _('Git repository') ?></a>)</p>
            <p class="footer_left">CalcPvAutonome <?= _('version') ?> <?= $CalcPvAutonomeVersion ?> <?= _('is an open software licensed <a href="https://en.wikipedia.org/wiki/Beerware">Beerware</a>') ?></p>
David's avatar
David committed
174 175 176 177 178



	

root's avatar
root committed
179
        </div>
David's avatar
David committed
180 181 182



183 184 185
        <?php 
		}
		?>
root's avatar
root committed
186 187
	</div>
	<div id="bg">
David's avatar
David committed
188
		<img src="./lib/solar-panel-1393880_1280.png" alt="">
root's avatar
root committed
189
	</div>
root's avatar
root committed
190
	<?php @include_once('./footer.php'); ?>
root's avatar
root committed
191

root's avatar
root committed
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
<script type="text/javascript">
$(document).ready(function() {	
	/* infobulles http://javascript.developpez.com/tutoriels/javascript/creer-info-bulles-css-et-javascript-simplement-avec-jquery/ */
    // Sélectionner tous les liens ayant l'attribut rel valant tooltip
    $('a[rel=tooltip]').mouseover(function(e) {
		// Récupérer la valeur de l'attribut title et l'assigner à une variable
		var tip = $(this).attr('title');   
		// Supprimer la valeur de l'attribut title pour éviter l'infobulle native
		$(this).attr('title','');
		// Insérer notre infobulle avec son texte dans la page
		$(this).append('<div id="tooltip"><div class="tipBody">' + tip + '</div></div>');    
		// Ajuster les coordonnées de l'infobulle
		$('#tooltip').css('top', e.pageY - 30 );
		$('#tooltip').css('left', e.pageX - 145 );
		// Faire apparaitre l'infobulle avec un effet fadeIn
	}).mousemove(function(e) {
		// Ajuster la position de l'infobulle au déplacement de la souris
		$('#tooltip').css('top', e.pageY - 30 );
		$('#tooltip').css('left', e.pageX - 145 );
	}).mouseout(function() {
		// Réaffecter la valeur de l'attribut title
		$(this).attr('title',$('.tipBody').html());
		// Supprimer notre infobulle
		$(this).children('div#tooltip').remove();
	});
}); 
</script>
root's avatar
root committed
219
</body>
root's avatar
root committed
220
</html>