Fixed a time bug
[rb-clock.git] / php / index.php
1 <?php
2
3 header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
4 header("Pragma: no-cache"); // HTTP 1.0.
5 header("Expires: 0"); // Proxies.
6
7 ?>
8 <!doctype html>
9 <html lang="en">
10 <head>
11 <meta charset="utf-8">
12 <title></title>
13 <meta name="description" content="">
14 <meta name="author" content="">
15 <style type="text/css">
16 .form-container {
17    border: 1px solid #f2e3d2;
18    background: #c9b7a2;
19    background: -webkit-gradient(linear, left top, left bottom, from(#f2e3d2), to(#c9b7a2));
20    background: -webkit-linear-gradient(top, #f2e3d2, #c9b7a2);
21    background: -moz-linear-gradient(top, #f2e3d2, #c9b7a2);
22    background: -ms-linear-gradient(top, #f2e3d2, #c9b7a2);
23    background: -o-linear-gradient(top, #f2e3d2, #c9b7a2);
24    background-image: -ms-linear-gradient(top, #f2e3d2 0%, #c9b7a2 100%);
25    -webkit-border-radius: 8px;
26    -moz-border-radius: 8px;
27    border-radius: 8px;
28    -webkit-box-shadow: rgba(000,000,000,0.9) 0 1px 2px, inset rgba(255,255,255,0.4) 0 0px 0;
29    -moz-box-shadow: rgba(000,000,000,0.9) 0 1px 2px, inset rgba(255,255,255,0.4) 0 0px 0;
30    box-shadow: rgba(000,000,000,0.9) 0 1px 2px, inset rgba(255,255,255,0.4) 0 0px 0;
31    font-family: 'Helvetica Neue',Helvetica,sans-serif;
32    text-decoration: none;
33    vertical-align: middle;
34    min-width:500px;
35    padding:20px;
36    width:500px;
37    margin: 0 auto;
38    }
39 .form-field {
40    border: 1px solid #c9b7a2;
41    background: #e4d5c3;
42    -webkit-border-radius: 4px;
43    -moz-border-radius: 4px;
44    border-radius: 4px;
45    color: #c9b7a2;
46    -webkit-box-shadow: rgba(255,255,255,0.4) 0 1px 0, inset rgba(000,000,000,0.7) 0 0px 0px;
47    -moz-box-shadow: rgba(255,255,255,0.4) 0 1px 0, inset rgba(000,000,000,0.7) 0 0px 0px;
48    box-shadow: rgba(255,255,255,0.4) 0 1px 0, inset rgba(000,000,000,0.7) 0 0px 0px;
49    padding:8px;
50    margin-bottom:20px;
51    width:280px;
52    }
53 .form-field:focus {
54    background: #fff;
55    color: #725129;
56    }
57 .form-container h2 {
58    text-shadow: #fdf2e4 0 1px 0;
59    font-size:24px;
60    margin: 0 0 10px 0;
61    font-weight:bold;
62    text-align:center;
63     }
64 .form-container h3 {
65    text-shadow: #fdf2e4 0 1px 0;
66    font-size:18px;
67    margin: 0 0 10px 0;
68    text-align:center;
69     }
70 .form-title {
71    margin-bottom:10px;
72    color: #725129;
73    text-shadow: #fdf2e4 0 1px 0;
74    }
75 .submit-container {
76    margin:8px 0;
77    text-align:right;
78    }
79 .submit-button {
80    border: 1px solid #447314;
81    background: #6aa436;
82    background: -webkit-gradient(linear, left top, left bottom, from(#8dc059), to(#6aa436));
83    background: -webkit-linear-gradient(top, #8dc059, #6aa436);
84    background: -moz-linear-gradient(top, #8dc059, #6aa436);
85    background: -ms-linear-gradient(top, #8dc059, #6aa436);
86    background: -o-linear-gradient(top, #8dc059, #6aa436);
87    background-image: -ms-linear-gradient(top, #8dc059 0%, #6aa436 100%);
88    -webkit-border-radius: 4px;
89    -moz-border-radius: 4px;
90    border-radius: 4px;
91    -webkit-box-shadow: rgba(255,255,255,0.4) 0 1px 0, inset rgba(255,255,255,0.4) 0 1px 0;
92    -moz-box-shadow: rgba(255,255,255,0.4) 0 1px 0, inset rgba(255,255,255,0.4) 0 1px 0;
93    box-shadow: rgba(255,255,255,0.4) 0 1px 0, inset rgba(255,255,255,0.4) 0 1px 0;
94    text-shadow: #addc7e 0 1px 0;
95    color: #31540c;
96    font-family: helvetica, serif;
97    padding: 8.5px 18px;
98    font-size: 14px;
99    text-decoration: none;
100    vertical-align: middle;
101    }
102 .submit-button:hover {
103    border: 1px solid #447314;
104    text-shadow: #31540c 0 1px 0;
105    background: #6aa436;
106    background: -webkit-gradient(linear, left top, left bottom, from(#8dc059), to(#6aa436));
107    background: -webkit-linear-gradient(top, #8dc059, #6aa436);
108    background: -moz-linear-gradient(top, #8dc059, #6aa436);
109    background: -ms-linear-gradient(top, #8dc059, #6aa436);
110    background: -o-linear-gradient(top, #8dc059, #6aa436);
111    background-image: -ms-linear-gradient(top, #8dc059 0%, #6aa436 100%);
112    color: #fff;
113    }
114 .submit-button:active {
115    text-shadow: #31540c 0 1px 0;
116    border: 1px solid #447314;
117    background: #8dc059;
118    background: -webkit-gradient(linear, left top, left bottom, from(#6aa436), to(#6aa436));
119    background: -webkit-linear-gradient(top, #6aa436, #8dc059);
120    background: -moz-linear-gradient(top, #6aa436, #8dc059);
121    background: -ms-linear-gradient(top, #6aa436, #8dc059);
122    background: -o-linear-gradient(top, #6aa436, #8dc059);
123    background-image: -ms-linear-gradient(top, #6aa436 0%, #8dc059 100%);
124    color: #fff;
125    }
126
127 html {
128     height: 100%;
129 }
130 body {
131     height: 100%;
132     margin: 0;
133     background-repeat: no-repeat;
134     background-attachment: fixed;
135     background: rgb(167,199,220); /* Old browsers */
136     background: -moz-radial-gradient(center, ellipse cover,  rgba(167,199,220,1) 0%, rgba(133,178,211,1) 100%); /* FF3.6-15 */
137     background: -webkit-radial-gradient(center, ellipse cover,  rgba(167,199,220,1) 0%,rgba(133,178,211,1) 100%); /* Chrome10-25,Safari5.1-6 */
138     background: radial-gradient(ellipse at center,  rgba(167,199,220,1) 0%,rgba(133,178,211,1) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
139     filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#a7c7dc', endColorstr='#85b2d3',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */
140 }
141
142 </style>
143 <script type="text/javascript">
144 get_time();
145 var utcSeconds = 0;
146 var date = new Date(0);
147 date.setUTCSeconds(utcSeconds);
148 var ntpcounter=0;
149
150 function loadpage(page_request){
151   if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) {
152     utcSeconds = parseInt(page_request.responseText,10);
153     var tmpdate = new Date(0);
154     tmpdate.setUTCSeconds(utcSeconds);
155     date = tmpdate;
156     //document.getElementById('times').innerHTML=utcSeconds;
157   }
158 }
159
160 function loadpagepps(page_request){
161   if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) {
162     ppsstatus = page_request.responseText;
163     document.getElementById('ppsstatus').innerHTML='PPS STATUS: '+ppsstatus;
164   }
165 }
166
167 function get_time() {
168   var page_request = false
169   if (window.XMLHttpRequest) // if Mozilla, Safari etc
170     page_request = new XMLHttpRequest()
171   else if (window.ActiveXObject){ // if IE
172     try {
173       page_request = new ActiveXObject("Msxml2.XMLHTTP")
174     } 
175     catch (e){
176       try{
177         page_request = new ActiveXObject("Microsoft.XMLHTTP")
178       }
179     catch (e){}
180     }
181   }
182   else
183     return false
184   page_request.onreadystatechange=function(){
185     loadpage(page_request);
186   }
187   page_request.open('GET', '/time-ajax.php', true)
188   page_request.send(null)
189 }
190
191 function update_time() {
192   ntpcounter=ntpcounter+1;
193   document.getElementById("updatetime").innerHTML = (date);
194   date.setSeconds(date.getSeconds() + 1);
195   if (ntpcounter>600) {
196     ntpcounter=0;
197     get_time();
198   }
199   setTimeout("update_time()", 1000);
200 }
201
202 function update_pps() {
203     var page_request = false
204   if (window.XMLHttpRequest) // if Mozilla, Safari etc
205     page_request = new XMLHttpRequest()
206   else if (window.ActiveXObject){ // if IE
207     try {
208       page_request = new ActiveXObject("Msxml2.XMLHTTP")
209     }
210     catch (e){
211       try{
212         page_request = new ActiveXObject("Microsoft.XMLHTTP")
213       }
214     catch (e){}
215     }
216   }
217   else
218     return false
219   page_request.onreadystatechange=function(){
220     loadpagepps(page_request);
221   }
222   page_request.open('GET', '/ppsstatus.php', true)
223   page_request.send(null)
224   setTimeout("update_pps()", 5000);
225 }
226
227 function update_satellite() {
228   var satellite = document.getElementById('satellite');
229   satellite.src = "http://ntp.dyn.spangdorfia.com/gpsd/gpsd.php?op=view&"+ new Date().getTime();
230   setTimeout("update_satellite()", 3000);
231 }
232
233 </script>
234 </head>
235 <body onload="update_time(); update_satellite(); update_pps();">
236 <br><br>
237 <form class="form-container">
238 <div class="form-title"><h2>Atomic Clock Status</h2></div>
239 <h3><div class="form-title" id="updatetime"></div></h3>
240 <h3><div class="form-title">
241 <?php
242 $contents = file_get_contents("http://localhost/gpsd/gpsd.php?op=json");
243 $contents = utf8_encode($contents);
244 $results = json_decode($contents,true); 
245 echo "Total Satellites: " . count($results['sky'][0]['satellites']);
246 ?>
247 </div></h3>
248 <div><h3><img id="satellite" name="satellite" src="http://ntp.dyn.spangdorfia.com/gpsd/gpsd.php?op=view" width="50%" height="50%"></h3></div>
249
250 <h3><div class="form-title" id="rbstatus">*Rb LOCK: YES</div></h3>
251 <h3><div class="form-title" id="ppsstatus">PPS STATUS: 0</div></h3>
252 <h3><div class="form-title" id="freqstatus">*CURRENT FREQ: 10MHz</div></h3>
253 </div>
254 </form>
255
256 </body>
257 </html>