Newer
Older
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
<?php
/**
* Created by PhpStorm.
* User: tim
* Date: 8/21/14
* Time: 10:50 PM
*/
global $config_studitypen, $config_reisearten, $config_essen, $admin_db, $config_current_fahrt_id, $config_admin_verbose_level, $config_verbose_level, $text, $headers, $ajax;
$headers .= '<script type="text/javascript" src="../view/js/jquery-1.11.1.min.js"></script>
<script src="../view/js/jquery.tabletojson.js"></script>
<script src="../view/js/jquery.jeditable.js"></script>';
$text .= "<h3>Kalkulation</h3>";
$h1 = array("Position", "Anzahl (normal)", "Satz", "Summe");
$s1[3] = array(1,2);
$t1[2] = " €";
$t1[3] = " €";
$d1 = array(array("Reisekosten", 2, 1.9),
array("Übernachtung (HP)", 2, 17.8),
array("Bettwäsche", 1, 4),
array("Grillen", 1, 0.3),
array("Kurzreisezuschlag", 1, 2));
$text .= html_table($h1, $d1, $s1, $t1, "test");
$text .= '<span id="anc_add">add</span> - <span id="anc_rem">rem</span>';
$text .= "<h2>Einkaufen</h2>";
$h2 = array("Position", "Anzahl", "Satz", "Summe");
$s2[3] = array(1,2);
$t2[2] = " €";
$t2[3] = " €";
$d2 = array(array("Club Mate", 120, 0.69),
array("Chips", 15,0.5),
array("Flips", 15, 0.5),
array("Fanta", 24, 0.39),
array("Wasser", 42, 0.3));
$text .= html_table($h2, $d2, $s2, $t2);
$text .= "<h3>Rechnung</h3>";
$h3 = array("Position", "Menge", "Anzahl", "Satz", "Summe");
$s3[4] = array(1,2,3);
$t3[3] = " €";
$t3[4] = " €";
$d3 = array(
array("Übernachtung", 2, 69, 10.5),
array("Bettwäsche", 1, 75, 4),
array("Grillnutzung", 1, 69, 0.3),
array("Kurzreisezuschlag", 1, 69, 2),
array("Halbpension", 2, 69, 7.3));
$text .= html_table($h3, $d3, $s3, $t3);
$text .= "<h2>Money In/Out</h2>";
$text .= '<div style="float:left">';
$h4 = array("Position", "Summe");
$s4 = array();
$t4[1] = " €";
$d4_out = array(
array("Frauensee", 2815.1),
array("Einkauf", 590.13),
array("Busfahrt", 216),
array("Bäcker", 22.4),
array("Kaution", 100)
);
$d4_in = array(
array("Pfand1", 82.17),
array("Pfand2", 10),
array("Pfand3", 15),
array("Fachschaft (Reste)", 76),
array("Kollekte", 4620),
array("Förderung", 2200),
array("Kaution", 100)
);
$text .= html_table($h4, $d4_out, $s4, $t4);
$text .= '</div><div style="float:left">';
$text .= html_table($h4, $d4_in, $s4, $t4);
$text .= '</div><div style="clear:both"></div>';
$text .="<script type='text/javascript'>
$('#testy').click( function() {
var table = $('#test').tableToJSON(); // Convert the table into a javascript object
console.log(table);
alert(JSON.stringify(table));
});
function ref_editable(){
$('.edita').editable(function(value, settings){return(value);},
{
indicator : '<img src=\'img/indicator.gif\'>',
tooltip : 'Click to edit...',
style : 'inherit',
callback : function(value, settings){
var table = $('#test').tableToJSON(); // Convert the table into a javascript object
console.log(JSON.stringify(table));
}
}
);
}
$(function(){
ref_editable();
var cnt = 2;
$('#anc_add').click(function(){
$('#test>tbody tr').last().after('<tr><td class=\'edita\'>Static Content ['+cnt+']</td><td class=\'edita\'></td><td class=\'edita\'></td><td class=\'edita\'></td></tr>');
cnt++;
ref_editable();
});
$('#anc_rem').click(function(){
if($('#test>tbody tr').size()>1){
$('#test>tbody tr:last-child').remove();
}else{
alert('One row should be present in table');
}
});
});
</script>";
/**
* $headers
* is an array of the headers
* $data
* is an array with the data to output
* $sum
* is an array declaring which cols should be summed up and put below the table,
* second dimension declares which cols need to be multiplied (if no second dimension, just sum at the end)
* $type
* is an array declaring type of data to put behind the value (i.e. €), not all cols need to be declared
*
* return value: variable containing the html code for echo
*/
function html_table($header, $data, $sum = array(), $type = array(), $id=""){
$summy = array();
$ret = "<table class=\"cost-table\" id=\"".$id."\">
<thead>
<tr>\n";
foreach($header as $h)
$ret.= "<th>".$h."</th>\n";
$ret.=" </tr>
</thead>
<tbody>\n";
$cnt = 0;
foreach($data as $row){
$ret.="<tr>";
for($i = 0; $i < count($header); $i++){
$cnt++;
$ret.= "<td".numeric_class($row, $sum, $i)." id='cell".$id.$cnt."'>";
if(isset($row[$i])){
$ret .= prepval($row[$i],(isset($type[$i]) ? $type[$i] : ""));
if(isset($sum[$i])){
if(!isset($summy[$i]))
$summy[$i] = $row[$i];
else
$summy[$i] += $row[$i];
}
} elseif(isset($sum[$i])) {
if(count($sum[$i])>1){
$tmp = NULL;
foreach($sum[$i] as $s){
$tmp = (is_null($tmp)) ? $row[$s] : $tmp*$row[$s];
}
$ret .= prepval($tmp,(isset($type[$i]) ? $type[$i] : ""));
if(!isset($summy[$i]))
$summy[$i] = $tmp;
else
$summy[$i] += $tmp;
} else {
// do nothing, sum at the end
}
}
$ret.="</td>";
}
$ret.="</tr>";
}
$ret.= "</tbody>\n";
if(count($sum)>0){
$ret.= "<tfoot>
<tr>\n";
for($i = 0; $i < count($header); $i++){
if(isset($sum[$i])){
$ret.='<td>'.prepval($summy[$i],(isset($type[$i]) ? $type[$i] : "")).'</td>';
} else {
$ret.='<td class="cost-table-invisible"></td>';
}
}
$ret.= " </tr>
</tfoot>\n";
}
$ret.= "</table>";
return $ret;
}
function prepval($val, $post){
if(strpos($post, "€")!==false)
return number_format($val, 2, ',', ' ').$post;
return $val.$post;
}
function numeric_class($a,$b,$c){
$d = ' class="cost-table-numeric edita"';
if(isset($a[$c])){
if(is_numeric($a[$c]))
return $d;
}
if(isset($b[$c]))
return $d;
return ' class="edita"';
}