var latitude = 0 var longitude = 0 var eventtoreg = 0 var eventname = '' var posiblelocation = 1 var idfirmy = '' var infotimeout var positionoptions = { enableHighAccuracy: true, timeout: 7500, maximumAge: 0 }; function odswiez(){ location.reload(); } function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(SetPosition,errorPosition,positionoptions); } else { latitude = 0 ; longitude = 0 ; } } function testLocation(issetting){ if (issetting > 0){ if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(TestPosition,errorPosition,positionoptions ); } else { posiblelocation = 0; ShowInfo(`No support for geolocation` ); } } else { posiblelocation = 0; } } function TestPosition(position) { if (position.coords.latitude>0 && position.coords.longitude>0){ posiblelocation=1; }else{ posiblelocation=-1; ShowInfo(`Failing to try to prodigit the localization` ); } } function errorPosition(err) { posiblelocation=0; ShowInfo(`GEOLOCALISATION ERROR
ERROR: ${err.code}
${err.message}
` ); } function SetPosition(position) { latitude = position.coords.latitude; longitude = position.coords.longitude; ConfirmData(); } function ConfirmData(){ if (latitude>0 && longitude>0) { gpsinfo=`with geolocation [MAP]` }else{ gpsinfo=`without geolocation ` } ShowInfo(`The ${eventname} event will be recorded in the system ${gpsinfo}`, showbutton=true, confirm=true, timeout=30); } function SendData(){ ShowInfo(`Uploading data in progress`, showbutton=false, confirm=false, timeout=-1) var dane={'userid':userid, 'event': eventtoreg, 'latitude':latitude, 'longitude':longitude} $.post( `/regevent?${idfirmy}`, dane , function( result ) { //$('#parametry').empty(); if (result.OK == 0){ ShowInfo(`

Event recorded

${result.eventname}

Registration time

${result.timestamp}`); }else{ ShowInfo(`Error ${result.error}`); } }, dataType='json') .fail(function() { ShowInfo(`No communication with the server`); }) }; function SendEvent(eventnr, eventname){ var isdialog = $('#dialog').is(":hidden"); //(':visible') if (eventnr >= 0 && isdialog){ //$(this).addClass('negative'); eventtoreg = eventnr; eventname = eventname; if (posiblelocation != 0){ ShowInfo(`Geolocation in progress`, showbutton=false); getLocation(); }else{ //sendData(); ConfirmData(); } } } function CloseInfo(){ if ($('#dialog').is(':visible')){ $('#dialog').hide('slow'); $('.eventbutton').css('cursor', 'pointer'); //$('.negative').removeClass('negative') } } function ShowInfo(info, showbutton, confirm, timeout){ showbutton = (typeof showbutton !== 'undefined') ? showbutton : true; confirm = (typeof confirm !== 'undefined') ? confirm : false; timeout = (typeof timeout !== 'undefined') ? timeout : 5; clearTimeout(infotimeout); $('#info').html(info); if (showbutton){ $('#animacja').hide(); $('#closebutton').show(); if (confirm) { $('#confirmbutton').show(); } else { $('#confirmbutton').hide(); }; }else{ $('#closebutton').hide(); $('#confirmbutton').hide(); $('#animacja').show(); }; if (!$('#dialog').is(':visible')){ $('.eventbutton').css('cursor','default'); $('#dialog').show('slow'); }; //if (!confirm) { // $('#dialog').on( "click", CloseInfo); //} else { // $('#dialog').off('click'); //} if (timeout>0 && showbutton){ //&& !confirm){ infotimeout = setTimeout(CloseInfo, timeout*1000); }; } /* $(document).ready(function() { //$('#dialog').on( "click", function() { // CloseInfo(); //}); testLocation(); }); */