1
2function QuickstatsShowPage(ns) {
3    var page = DOKU_BASE +'doku.php?&id=' + ns;
4    window.open(page,'quickstats_win',"width=900,height=600,scrollbars=yes,resizable=yes");
5}
6
7function uncheck(key) {
8
9   var dom = document.getElementById(key);
10   dom.style.backgroundColor='white';
11   key = key + '_1';
12    var dom = document.getElementById(key);
13
14    dom.style.backgroundColor='white';
15}
16
17function qs_close_panel(which) {
18   var dom = document.getElementById(which);
19   dom.style.display = 'none';
20}
21
22function qs_open_panel(which) {
23   var dom = document.getElementById(which);
24   dom.style.display = 'block';
25}
26
27function qs_open_info(which) {
28   var dom = document.getElementById(which) ;
29   if(dom.style.display == 'block') {
30       qs_close_panel(which);
31       return;
32   }
33   qs_open_panel(which);
34   qs_open_panel('quick__stats');
35   qs_close_panel('qs_general_intro');
36}
37
38function toggle_panel(which) {
39    qs_close_panel('qs_general_intro');
40    var dom = document.getElementById(which);
41    var display = dom.style.display;
42
43    if(display == 'block') {
44       dom.style.display = 'none';
45    }
46    else if(display == 'none') {
47       dom.style.display = 'block';
48    }
49    else dom.style.display = 'block';
50
51}
52
53function qs_check_year(year) {
54 if(!year) year = document.getElementById('year');
55
56   if(parseInt(year.value) < 2010) {
57        alert("Year values must have four digits, e.g 2012");
58        return false;
59   }
60    return true;
61}
62
63function checkforJQuery() {  }
64
65function onChangeQS(which) {
66  if(which.selectedIndex == 0)  {
67      alert('You must select a <namespace:>page');
68      return;
69  }
70  QuickstatsShowPage(which.options[which.selectedIndex].value) ;
71 }
72
73 function qs_priority_error(err) {
74    elems = err.split(';;');
75    alert('You have selected ' + elems[0] + ' priority, but have not  ' + elems[1] + ' in your query');
76 }
77
78var qs_timer_on=false;
79var qs_tid;
80var qs_seconds=0;
81function set_timer(dom,immediate_display) {
82    qs_timer_on=true;
83    var max_script_time = document.getElementById('qs_script_max_time').value;
84    var throbber = DOKU_BASE + 'lib/plugins/quickstats/throbber.gif';
85    dom.innerHTML = "<div id='qs_throbber_div' style='display:none'><center>Loading<br /><br /><img src='" + throbber +"'><br /><span id='qs_throbber_tm'></span></center></div>";
86
87    qs_tid=setInterval("qs_timer()", 1025);
88	var dom = document.getElementById("qs_throbber_div");
89    if(!immediate_display) {
90	dom.style.display='none';
91}
92     else dom.style.display='block';
93
94}
95 function qs_timer() {
96  if(qs_seconds && !qs_timer_on) {
97      clearInterval(qs_tid);
98	  return;
99  }
100   qs_seconds++;
101   if(qs_seconds < 8) return;
102   var dom = document.getElementById("qs_throbber_div");
103   if(!dom) return;
104   if(dom.style.display=='none' || dom.style.display=='') dom.style.display='block';
105
106   var dom = document.getElementById("qs_throbber_tm");
107   if(!dom) {
108      clearInterval(qs_tid);
109	  return;
110   }
111   dom.innerHTML=qs_seconds ;
112 }
113
114function getExtendedData(f,DOKU_INCL) {
115
116    var priority_error = "";
117    var priority = "";
118    var page = "";
119    qs_seconds=0;
120    if(!qs_check_year(null)) return;
121    var params="doku_inc="+encodeURIComponent(DOKU_INCL);
122    var inp = f.getElementsByTagName('input');
123    for(el in inp) {
124      if(inp[el].type == 'hidden') {
125          var p = '&' + inp[el].name + '=' + inp[el].value;
126          params += p;
127      }
128    }
129    var ignore = document.getElementById('qs_ignore').checked;
130
131    var p_brief = document.getElementById('qs_p_brief');
132    if(p_brief.checked) params+="&p_brief=1";
133    var months = document.getElementById('month');
134    if(months.selectedIndex == 0 && !whole_year.checked) {
135       alert("You must select a month");
136       return;
137    }
138    else month = months.selectedIndex;
139
140    var priority_types = new Array('page','ip','agent','country');
141    for(var p in priority_types) {
142        var dom = document.getElementById('qs_priority_'+ priority_types[p]);
143        if(dom.checked) {
144            priority = priority_types[p];
145        }
146    }
147    if(priority != 'ip') {
148        var countries=document.getElementById('country_names');
149        var option = countries.options[countries.selectedIndex];
150        var country_set = false;
151        if(option.value != 0) {
152            if(!ignore || priority == 'country') {
153                params+="&country_name=" + encodeURIComponent(option.text);
154                params+="&country_code=" + encodeURIComponent(option.value);
155                country_set = true;
156            }
157        }
158
159       var ua_set = false;
160        var ua =document.getElementById('user_agent');
161        var option = ua.options[ua.selectedIndex];
162        if(option.value != 0) {
163            if(!ignore || priority == 'agent') {
164                params+="&user_agent=" + encodeURIComponent(option.value);
165               ua_set = true;
166            }
167        }
168        var page = document.getElementById('page').value;
169    }
170    var ip = document.getElementById('ip').value;
171
172     if(!country_set && !page && !ip &&!ua_set) {
173         alert('Query term(s) missing: Page/IP/Country/User Agent');
174         return;
175    }
176
177       if(priority == 'page' && !page)  {
178            priority_error = 'page;;entered a page name';
179       }
180       else if(priority == 'country' && !country_set)  {
181           priority_error = 'country;;chosen a Country';
182       }
183      else if(priority == 'agent' && !ua_set)  {
184         priority_error = 'user agent;;selected a User Agent';
185       }
186      else if(priority == 'ip' && !ip)  {
187         priority_error = 'ip;;entered an IP address';
188       }
189
190
191    if(priority_error) {
192        qs_priority_error(priority_error);
193        return;
194    }
195
196    params +=  '&priority='  + priority;
197     if(!ignore || priority == 'ip') {
198        if(ip != "") {
199            params+="&ip=" + ip;
200        }
201    }
202    if(!ignore || priority == 'page') {
203        if(page !="") {
204            params+="&page=" + page;
205        }
206    }
207    var year = document.getElementById('year').value;
208    date = '&date=' +month + '_' + year;
209    for(i=months.selectedIndex+1; i<months.options.length; i++) {
210        if(months.options[i].selected) {
211            date += '&date_' + i + '=' + i + '_' + year;
212        }
213    }
214
215    params += date;
216
217
218
219    var dom = document.getElementById('extended_data');
220    set_timer(dom,false) ;
221    jQuery.post(
222    DOKU_BASE + 'lib/plugins/quickstats/scripts/extended_data.php',
223    params,
224    function (data) {
225	     qs_timer_on=false;
226          dom.innerHTML = decodeURIComponent(decodeURIComponent(data));
227    },
228    'html'
229   );
230
231}
232
233function qs_country_search() {
234
235    var select = document.getElementById('country_names');
236
237    var params = "";
238    params+="doku_inc="+encodeURIComponent(DOKU_BASE);
239    var dom=document.getElementById('cc_extra');
240    params += '&cc_cntry=' + dom.value;
241
242    jQuery.post(
243    DOKU_BASE + 'lib/plugins/quickstats/scripts/country_data.php',
244    params,
245    function (data) {
246           if(!data) {
247               alert("Nothing found  for " + dom.value);
248               return;
249           }
250           var str =decodeURIComponent(data);
251           var entries = str.split(/\n/);
252           for (i=0; i< entries.length; i++) {
253               var elems = entries[i].split(/::/);
254               var obj = new Option(elems[1], elems[0],false,false);
255                select.add(obj,1);
256           }
257    },
258    'html'
259   );
260
261}
262
263function qs_agent_search() {
264
265
266    var select = document.getElementById('user_agent');
267
268    var params = "";
269    var dom=document.getElementById('other_agent');
270    params += '&other_agent=' + encodeURIComponent(dom.value);
271
272    jQuery.post(
273    DOKU_BASE + 'lib/plugins/quickstats/scripts/get_useragent.php',
274    params,
275    function (data) {
276           if(!data) {
277               alert("Nothing found  for " + dom.value);
278               return;
279           }
280           var str =decodeURIComponent(data);
281           var entries = str.split(/::/);
282           if(!entries.length) return;
283           for (i=0; i< entries.length; i++) {
284               var obj = new Option(entries[i], entries[i],false,false);
285                select.add(obj,1);
286           }
287
288    },
289    'html'
290   );
291
292}
293
294  function qs_download_GeoLite(geoip_local)  {
295        var params="&geoip_local=" + geoip_local;
296        var dom = document.getElementById('download_results');
297        var test = document.getElementById('gc2_test');
298        if(test && test.checked)  {
299           params += '&test=test';
300        }
301        qs_seconds=0;
302        set_timer(dom,true);
303
304        jQuery.post(
305        DOKU_BASE  + 'lib/plugins/quickstats/scripts/get_geocity2.php',
306        params,
307        function (data) {
308           dom.innerHTML ='<pre>' +data +'</pre>';
309        },
310        'html'
311        );
312}
313jQuery(document).ready(function() {
314         if(JSINFO['ajax'] == 'ajax') {
315           var act = JSINFO['act'] ? JSINFO['act'] : "";
316           var params = 'call=quickstats&id=' + JSINFO['id'] + "&qs=" + location.search + '&act='+act;
317          jQuery.post(
318               DOKU_BASE + 'lib/exe/ajax.php',
319               params,
320               function(data) {
321                   if(data)  alert(data);
322                },
323                'html'
324            );
325         }
326   });
327