index.php 8.96 KB
Newer Older
David's avatar
David committed
1
<?php
David's avatar
David committed
2
$CalcPvAutonomeVersion='4.4';
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
bindtextdomain("messages", "./lang");
textdomain("messages");
62

David's avatar
David committed
63 64 65
// Définition du pays (selon l'IP
$country = @geoip_country_code_by_name(get_ip());

David's avatar
David committed
66 67 68 69
// Pour l'interface de conso : 
if (isset($_POST['email'])) {
	setcookie ('email', $_POST['email'], time() + 31536000);
}
David's avatar
David committed
70
?>
root's avatar
root committed
71
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
David's avatar
David committed
72 73
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php if ($localeshort == 'fa') { ?>
David's avatar
David committed
74
	<html xmlns="http://www.w3.org/1999/xhtml"  dir="rtl"  xml:lang="<?= $localeshort ?>" lang="<?= $localeshort ?>">
David's avatar
David committed
75
<?php } else { ?>
David's avatar
David committed
76
	<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?= $localeshort ?>" lang="<?= $localeshort ?>">
David's avatar
David committed
77
<?php } ?>
root's avatar
root committed
78
<head>
79
	<title>[CalcPvAutonome] <?= _('Calculate/size photovoltaic stand-alone (autonomous) set') ?></title>
root's avatar
root committed
80 81
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<link href="./lib/style.css" media="screen" rel="stylesheet" type="text/css" />	
82 83
	<meta http-equiv="Pragma" content="no-cache">
	<meta http-equiv="Expires" content="-1">
84 85 86 87 88 89 90
	<?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 } ?>
91 92 93 94 95 96 97 98 99 100 101
	<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>
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
	<script src="./lib/jquery-3.1.1.slim.min.js"></script>
	<!-- Cookies -->
	<link rel="stylesheet" type="text/css" href="./lib/cookieconsent.min.css" />
	<script src="./lib//cookieconsent.min.js"></script>
	<script>
	window.addEventListener("load", function(){
	window.cookieconsent.initialise({
	  "palette": {
	    "popup": {
	      "background": "#eaf7f7",
	      "text": "#5c7291"
	    },
	    "button": {
	      "background": "#56cbdb",
	      "text": "#ffffff"
	    }
	  },
	  "position": "bottom-left"
	})});
	</script>
root's avatar
root committed
122 123
</head>
<body>
David's avatar
David committed
124
		<div id="langues">
David's avatar
David committed
125
			<?php 
126 127
			ksort($lang_ini);
			foreach($lang_ini as $lang) {
David's avatar
David committed
128
				$flag='';
David's avatar
David committed
129
				if ($localeshort == $lang['code']) {
David's avatar
David committed
130 131
					$flag=' drapeauActif';
				}
132 133 134 135 136 137
				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
138 139
						} else if ($lang['translated_progress'] < 90) {
							echo '$("#languesLegende").html("<b>'.$lang['code'].'</b> '._('partial translation').' ('.$lang['translated_progress'].'%)");';
140
						} else {
David's avatar
David committed
141
							echo '$("#languesLegende").html("<b>'.$lang['code'].'</b> ('.$lang['translated_progress'].'%)");';
142 143 144 145 146 147
						}
				echo '})
					.mouseout(function() {
						$("#languesLegende").hide();
					});
					</script>';
David's avatar
David committed
148 149
			}
			?>
150
			<!--<a href="https://crwd.in/calcpvautonome"><img class="drapeau" src="./lib/trad.png" alt="Help to translate" /></a>-->
David's avatar
David committed
151
		</div>
152 153
		<div id="languesLegende" style="display: none"></div>
	<div id="page-wrap">
154
		<?php
155
		$footer=true;
root's avatar
root committed
156
		if (isset($_GET['p']) && $_GET['p'] == 'CalcConsommation'
David's avatar
David committed
157 158
		 || isset($_GET['p']) && $_GET['p'] == 'CalcConso'
		 || $_SERVER['HTTP_HOST'] == 'conso.calcpv.net'
root's avatar
root committed
159 160
		 || $_SERVER['HTTP_HOST'] == 'calconso.zici.fr'
		 || $_SERVER['HTTP_HOST'] == 'calcconso.zici.fr') {
161
			echo '<h1>'._('Calculate daily electric needs').'</h1>';
root's avatar
root committed
162
			@include_once('./header.php');
David's avatar
David committed
163
			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>');
164
			include('./CalcConsommation.php'); 
root's avatar
root committed
165
			@include_once('./bottom.php'); 
166 167 168
		} elseif (isset($_GET['p']) && $_GET['p'] == 'Modeles') {
			include('./Modeles.php'); 
			$footer=false;
169
		} else {
170
			echo '<h1>'._('Calculate/size photovoltaic stand-alone (autonomous) set').'</h1>';
root's avatar
root committed
171
			@include_once('./header.php'); 
David's avatar
David committed
172
			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>');
173
			include('./CalcPvAutonome.php'); 
root's avatar
root committed
174
			@include_once('./bottom.php'); 
175
		}
176
		if ($footer == true) {
177
		?>
root's avatar
root committed
178
		<div id="footer">
David's avatar
David committed
179 180
			<?php if ($localeshort != 'fr') { ?>
            <p class="footer_translator"><?= _('Thanks to') ?> : 
181 182 183 184 185 186 187 188 189 190 191
            <?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
192
            ?>
David's avatar
David committed
193
            <?= _('for this <a target="_blank" href="https://crwd.in/calcpvautonome">translation</a>') ?></p>
David's avatar
David committed
194
            <?php } ?>
David's avatar
David committed
195
            <?=  _('<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
196 197
            <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>
root's avatar
root committed
198
        </div>
199 200 201
        <?php 
		}
		?>
root's avatar
root committed
202 203
	</div>
	<div id="bg">
David's avatar
David committed
204
		<img src="./lib/solar-panel-1393880_1280.png" alt="">
root's avatar
root committed
205
	</div>
root's avatar
root committed
206
	<?php @include_once('./footer.php'); ?>
root's avatar
root committed
207

root's avatar
root committed
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
<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
235
</body>
root's avatar
root committed
236
</html>