diff --git a/system/pages/createaccount.php b/system/pages/createaccount.php index 9654a2c9..b876f504 100644 --- a/system/pages/createaccount.php +++ b/system/pages/createaccount.php @@ -213,36 +213,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]; - - $countries['--'] = '----------'; - foreach ($config['countries'] as $code => $c) - $countries[$code] = $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; +} - 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 +)); ?> \ No newline at end of file diff --git a/system/templates/news.add.html.twig b/system/templates/news.add.html.twig index d4cde4c1..c8e769e6 100644 --- a/system/templates/news.add.html.twig +++ b/system/templates/news.add.html.twig @@ -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> @@ -150,4 +140,45 @@ }); }); </script> -{% endif %} \ No newline at end of file +{% 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> \ No newline at end of file