-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.php
287 lines (233 loc) · 10.7 KB
/
stats.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<?php require_once "inc/auth.http.php" ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<title>Statistiikat</title>
<!-- Remote CSS and JS -->
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/vader/jquery-ui.min.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<!-- Local CSS -->
<link href="css/tasker.css" rel="stylesheet">
<link href="css/jquery.tidy.table.css" rel="stylesheet" type="text/css">
<!-- Local JS -->
<!-- <script src="js/tasker.js"></script> -->
<script src="js/jquery.tidy.table.min.js"></script>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<style type="text/css"> .gradient { filter: none; } </style>
<![endif]-->
<script>
$(function() {
var statsData;
var tooltipTimeOut = 1500;
$(document).tooltip({
show: {
effect: 'fade'
},
track: true,
open: function (event, ui) {
setTimeout(function () {
$(ui.tooltip).hide('fade');
}, tooltipTimeOut);
}
});
// Initialize date picker
$( ".datepicker" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
minDate: new Date(2013, 11 - 1, 1),
// monthNames: [ "Tammi", "Helmi", "Maalis", "Huhti", "Touko", "Kesä", "Heinä", "Elo", "Syys", "Loka", "Marras", "Joulu" ],
showAnim: "fadeIn"
});
$('#stats').on('submit', function (e) {
var postData = $('#stats').serialize();
console.log('#stats: Post DATA: '+postData);
post(postData);
return false;
});
function post(pData) {
pData += "&userId=<?= $_SESSION['userId'] ?>";
console.log('Posting DATA: '+pData);
$.ajax({
type: 'post',
url: 'inc/dbStore.php',
data: pData,
success: function (data) {
console.log('form was submitted DATA:'+data.message);
tmpData = data.data;
if (tmpData.length > 0) {
statsData = data.data;
tmpData = "";
// arrange to table
tidify();
} else {
var msg = "Ei tuloksia. Voit yrittää toisella ajan jaksolla.";
$('#notes').html(msg);
}
}
});
}
function tidify() {
// put results into an array
var rows = [];
$.each(statsData, function(idx, rs) {
var row = [];
var address = rs.siteAddress+"<br>"+rs.siteZip+" "+rs.siteCity;
row.push(rs.entryDate, rs.taskType, rs.siteName, rs.siteType, address, rs.notes);
rows.push(row);
});
// console.log("rows 1 : " + JSON.stringify(rows));
$('#tidyContainer').TidyTable({
enableCheckbox : false,
enableMenu : true
},
{
columnTitles : ['Päivämäärä','Tehtävä tyyppi','Kohde','Kohde Tyyppi','Osoite','Muistiinpanot'],
// osoite : siteAddress, s.siteZip, s.siteCity
columnValues : rows
,
menuOptions : [
['- Valitse -', null],
['Exceliin CSV:nä', { callback : doSomething1 }],
// ['Tulosta', { callback : doSomething2 }]
['Tulosta Taulukko', { callback : doSomething2 }]
],
postProcess : {
table : doSomething3,
column : doSomething4,
menu : doSomething5
}
});
}
// do something with selected results
function doSomething1(rows) {
var csv = JSON2CSV(statsData);
var name = "tasker_export.csv";
window.open("data:text/csv;charset=utf-8," + escape(csv));
// http://stackoverflow.com/questions/14964035/how-to-export-javascript-array-info-to-csv-on-client-side
// var encodedUri = encodeURI(csvContent);
// var link = document.createElement("a");
// link.setAttribute("href", encodedUri);
// link.setAttribute("download", "my_data.csv");
// link.click(); // This will download the data file named "my_data.csv".
}
// function doSomething2(rows) {
function doSomething2(rows) {
// alert('callback2(rows=' + rows.length + "')");
var rawTable = $('#tidyContainer table').html();
// rawTable = rawTable.replace(/<th><input type="checkbox"><\/th>/g, '');
// rawTable = rawTable.replace(/<td><input type="checkbox"><\/td>/g, '');
rawTable = rawTable.replace(/<td title=""><\/td>/g, '<td> <\/td>');
var button = "<button id=\"close\" onclick='window.close()'>Sulje Ikkuna</button>";
var header = "<html><head><title>Print</title><style>";
header += "table td, table th { border: 1px solid #EEEEEE; padding: 3px; }";
header += "#close { clear:both; position:absolute; right:100px; bottom:60px; }";
header += "</style></head><body>";
var footer = "</body></html>";
newWin = window.open(", ", 'popup', 'toolbar = no, status = no');
newWin.document.write(header + "<table>" + rawTable + "</table>" + footer);
newWin.window.location.reload(); // this is the secret ingredient
newWin.focus();
newWin.print();
}
// post-process DOM elements
function doSomething3(table) {
// alert(table[0]);
}
function doSomething4(col) {
//alert(col[0]);
}
function doSomething5(menu) {
//alert(menu[0]);
}
function JSON2CSV(objArray) {
// http://jsfiddle.net/sturtevant/vUnF9/
var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
var str = '';
var line = '';
var labels = true;
var quotes = true;
if (labels) {
var head = array[0];
if (quotes) {
for (var index in array[0]) {
var value = index + "";
line += '"' + value.replace(/"/g, '""') + '",';
}
} else {
for (var index in array[0]) {
line += index + ',';
}
}
line = line.slice(0, -1);
str += line + '\r\n';
}
for (var i = 0; i < array.length; i++) {
var line = '';
if (quotes) {
for (var index in array[i]) {
var value = array[i][index] + "";
line += '"' + value.replace(/"/g, '""') + '",';
}
} else {
for (var index in array[i]) {
line += array[i][index] + ',';
}
}
line = line.slice(0, -1);
str += line + '\r\n';
}
return str;
}
// $("#convert").click(function() {
// var json = $.parseJSON($("#json").val());
// var csv = JSON2CSV(json);
// $("#csv").val(csv);
// });
// $("#download").click(function() {
// var json = $.parseJSON($("#json").val());
// var csv = JSON2CSV(json);
// window.open("data:text/csv;charset=utf-8," + escape(csv))
// });
});
</script>
</head>
<body>
<div id="pageContainer">
<header id="pageHeader">
<h2>Tehtävän tallettajan raportit</h2>
</header>
<nav id="pageNav">
<p>
<form id="stats" action="" method="POST">
Valitse ajanjakso:
<input id="dateStart" class="datepicker" type="text" name="dateStart" size="10" title="Haettavan ajanjakson alkamisajankohta">
-
<input id="dateEnd" class="datepicker" type="text" name="dateEnd" size="10" title="Haettavan ajanjakson päättymisajankohta">
<input id="removed" type="checkbox" name="removed" value="yes" title="Merkkaa tämä sisällyttääksesi myös poistetut kohteet">
<input id="taskAct" name="action" value="selectStats" type="hidden">
<input id="fetchButton" type="submit" value="Hae Raportti">
</form>
</p>
<button style="float:right" type="button" onclick="location.href='./tasker.php';" rel="external">Tallettajaan</button>
</nav>
<div id="contentContainer" class="clearfix">
<section id="pageSection">
<header class="sectionHeader"><div id="notes"></div></header>
<article class="sectionArticle">
<div id="tidyContainer"></div>
</article>
</section>
</div>
<footer id="pageFooter">
<!-- <button style="margin:5px auto 5px auto;">Export</button> -->
</footer>
</div>
</body>
</html>