* save detected country on create account in session

* warning about leaving news page with changes
This commit is contained in:
slawkens1 2018-01-03 22:03:56 +01:00
parent 01c0d021b2
commit 4a948b8ba2
2 changed files with 74 additions and 36 deletions

View File

@ -206,36 +206,43 @@ if($save)
}
}
$country_recognized = null;
if($config['account_country_recognize']) {
$country_recognized = null;
if($config['account_country_recognize']) {
$country_session = getSession('country');
if($country_session !== false) { // get from session
$country_recognized = $country_session;
}
else {
$info = json_decode(@file_get_contents('http://ipinfo.io/' . $_SERVER['REMOTE_ADDR'] . '/geo'), true);
if(isset($info['country'])) {
$country_recognized = strtolower($info['country']);
setSession('country', $country_recognized);
}
}
}
if(!empty($errors))
echo $twig->render('error_box.html.twig', array('errors' => $errors));
if(!empty($errors))
echo $twig->render('error_box.html.twig', array('errors' => $errors));
if($config['account_country']) {
$countries = array();
foreach (array('pl', 'se', 'br', 'us', 'gb') as $c)
$countries[$c] = $config['countries'][$c];
if($config['account_country']) {
$countries = array();
foreach (array('pl', 'se', 'br', 'us', 'gb') as $c)
$countries[$c] = $config['countries'][$c];
$countries['--'] = '----------';
foreach ($config['countries'] as $code => $c)
$countries[$code] = $c;
}
$countries['--'] = '----------';
foreach ($config['countries'] as $code => $c)
$countries[$code] = $c;
}
echo $twig->render('account.create.js.html.twig');
echo $twig->render('account.create.html.twig', array(
'account' => isset($_POST['account']) ? $_POST['account'] : '',
'email' => isset($_POST['email']) ? $_POST['email'] : '',
'countries' => isset($countries) ? $countries : null,
'accept_rules' => isset($_POST['accept_rules']) ? $_POST['accept_rules'] : false,
'country_recognized' => $country_recognized,
'country' => isset($country) ? $country : null,
'errors' => $errors,
'save' => $save
));
echo $twig->render('account.create.js.html.twig');
echo $twig->render('account.create.html.twig', array(
'account' => isset($_POST['account']) ? $_POST['account'] : '',
'email' => isset($_POST['email']) ? $_POST['email'] : '',
'countries' => isset($countries) ? $countries : null,
'accept_rules' => isset($_POST['accept_rules']) ? $_POST['accept_rules'] : false,
'country_recognized' => $country_recognized,
'country' => isset($country) ? $country : null,
'errors' => $errors,
'save' => $save
));
?>

View File

@ -1,13 +1,3 @@
<script type="text/javascript" src="{{ constant('BASE_URL') }}tools/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
selector : "#body",
theme : "modern",
plugins: 'print preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists textcolor wordcount spellchecker imagetools contextmenu colorpicker textpattern help code',
toolbar1: 'formatselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat code',
image_advtab: true
});
</script>
{% if action != 'edit' %}
<a id="news-button" href="#">Add news</a>
{% endif %}
@ -121,7 +111,7 @@
<input type="submit" value="Submit"/>
</td>
<td align="left">
<input type="button" onclick="window.location = '{{ news_link }}';" value="Cancel"/>
<input id="cancel" type="button" value="Cancel"/>
</td>
</tr>
</table>
@ -151,3 +141,44 @@
});
</script>
{% endif %}
<script type="text/javascript" src="{{ constant('BASE_URL') }}tools/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
var unsaved = false;
var lastContent = '';
tinymce.init({
selector : "#body",
theme : "modern",
plugins: 'print preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists textcolor wordcount spellchecker imagetools contextmenu colorpicker textpattern help code',
toolbar1: 'formatselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat code',
image_advtab: true,
setup: function(ed){
ed.on('NodeChange', function(e) {
if(ed.getContent() != lastContent) {
unsaved = true;
}
});
}
});
$(document).ready(function() {
$(":input").change(function(){ //trigers change in all input fields including text type
unsaved = true;
});
$("#cancel").click(function( event ) {
unsaved = false;
window.location = '{{ news_link }}';
});
lastContent = $("#body").val();
});
function unloadPage(){
if(unsaved){
return "You have unsaved changes on this page. Do you want to leave this page and discard your changes or stay on this page?";
}
}
window.onbeforeunload = unloadPage;
</script>