1 #include <infocon.style>
5 <page func=InfoCon title="Stempeluhr">
8 session_name('STEMPEL');
16 for ($idx=0; $idx < $_POST["fields"]; $idx++) {
17 if (isset($_POST["oid_".$idx])) {
18 $query = sprintf('UPDATE stempel SET status=%d WHERE oid=%d',
19 $_POST["status"], $_POST["oid_".$idx]);
21 $sth = pg_exec ($dbh, $query);
24 return sprintf("<br>%d records updated.", $count);
28 function display_tables()
36 $name = load_customers();
38 $table_head = '<h3 class="bar">Kunde: %s</h3><script type="text/javascript">plant(%d,%.2f);</script>
39 <form action="status.php" method="POST">
40 <table class="smallfont border" id="table_%d" width="100%%" cellpadding=0 cellspacing=0>
42 <tr class="head" onclick="edit_task_finish(this)">
43 <th width=15%%>Datum</th>
44 <th width=5%%>Dauer</th>
45 <th width=5%%>St.</th>
46 <th width=75%% align=left>Arbeitsbeschreibung</th>
51 if (!is_array($stati))
52 $stati = find_status();
54 $table_foot = '</table><div align="center"><p>';
56 foreach ($stati as $k=>$v)
57 $table_foot .= sprintf('<input type="radio" name="status" value="%s"%s>%s ', $k, 0==$k?' checked':'', $v);
58 $table_foot .= '<input type="submit" class="button" value="Aktualisieren"></p></div>'.
59 '<input type="hidden" name="fields" value="%d">'.
62 $table_row = '<tr class="t%d"><td>%s</td><td align="center" onclick="toggle_checkbox(%d,this)">%s</td>' .
63 '<td align="center" onclick="toggle_checkbox(%d,this)">%s</td><td onclick="edit_task(this)">%s</td></tr>';
64 $table_sum = '</tbody><tfoot><tr class="t%d"><td> </td><td align="center">%s</td><td> </td><td>Summe</td></tr></tfoot>';
66 $query = "SELECT stempel.oid,start,customer,time,task,kurz FROM stempel JOIN stempel_status ON (stempel.status = stempel_status.id) WHERE time IS NOT NULL ";
67 if (isset($month) && strlen($month))
68 $query .= "AND cast(start AS TEXT) LIKE '".$month."-%' ";
69 if (isset($cust) && strlen($cust))
70 $query .= "AND customer ='".$cust."' ";
72 if (isset($status) && strlen($status)) {
74 $query .= "AND status = $status ";
76 $query .= "AND status = 0 ";
77 $query .= "ORDER BY customer,start";
79 $sth = pg_exec ($dbh, $query);
83 while ($row = pg_fetch_array ($sth)) {
85 if ($customer != $row['customer']) {
86 if (strlen($customer)) {
87 printf($table_sum, $color, min2hour($sum));
88 printf($table_foot, $fieldnr);
91 $cname = $name[$row['customer']]['name'];
92 if (!strlen($cname)) $cname = ucfirst($row['customer']);
93 printf($table_head, $cname, $form, $name[$row['customer']]['rate'], $form);
94 $customer = $row['customer'];
100 $sum += $row['time'];
101 $d = explode(' ', $row['start']);
103 $check = sprintf('<input type="checkbox" class="checkbox" name="oid_%d" value="%d" onclick="add_sum(%d,this)">',
107 $date = sprintf('<span onclick="toggle_checkbox(%d,this)">%s</span>', $form, $d[0]);
108 printf($table_row, $color, $check.$date, $form, min2hour($row['time']), $form, $row['kurz'], htmlspecialchars($row['task'], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1'));
111 if (pg_num_rows($sth) > 0) {
112 printf($table_sum, $color, min2hour($sum));
113 printf($table_foot, $fieldnr);
117 function find_customers()
122 $query = "SELECT DISTINCT customer FROM stempel ORDER BY customer";
123 $sth = pg_exec ($dbh, $query);
125 while ($row = pg_fetch_array ($sth))
131 $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
132 or die("Unable to connect to SQL server");
134 pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
136 if (isset($_POST["status"]) && isset($_POST["fields"])) {
138 $_SESSION['redirect'] = true;
139 header('Location: status.php');
141 } elseif ($_SESSION['redirect']) {
142 $month = $_SESSION['save']["month"];
143 $cust = $_SESSION['save']["customer"];
144 $status = $_SESSION['save']["status"];
145 $_SESSION['redirect'] = false;
147 if (isset($_GET['month'])) {
148 $month = $_GET['month'];
149 $_SESSION['save']['month'] = $month;
150 unset($_SESSION['save']['customer']);
151 unset($_SESSION['save']['status']);
153 if (isset($_POST["filter"])) {
154 $month = $_POST["month"];
155 $cust = $_POST["customer"];
156 $status = $_POST["status"];
157 $_SESSION['save']['month'] = $month;
158 $_SESSION['save']['customer'] = $cust;
159 $_SESSION['save']['status'] = $status;
161 $month = date('Y-m');
162 $_SESSION['save']['month'] = $month;
163 unset($_SESSION['save']['customer']);
164 unset($_SESSION['save']['status']);
169 <script src="<root_prefix>basics.js"></script>
170 <script type="text/javascript">
172 var color_checked = '#c4ffc3';
173 function format_int(value, width)
175 var s = value.toString();
177 while (s.length < width)
183 function timestr(duration)
185 return format_int(Math.floor(duration / 60), 1) + ':'
186 + format_int(duration - (Math.floor(duration / 60) * 60), 2);
189 function strtime(time)
191 var a = time.split(':');
192 return parseInt(a[0],10) * 60 + parseInt(a[1],10);
195 function check(id, value)
197 var hours = $('#time_'+id);
198 var rate = $('#rate_'+id);
199 var sum = $('#sum_'+id);
202 $('table#table_'+id+' tbody tr:visible').each(function(i,e){
203 var checkbox = $(this).find('input[type="checkbox"]');
204 if (checkbox.prop('checked') != value) {
205 checkbox.prop('checked', !checkbox.prop('checked'));
206 if (checkbox.prop('checked'))
207 $(this).css('background-color', color_checked);
209 $(this).css('background-color', '');
210 add_sum(id, checkbox);
217 function plant(form, rate)
219 document.write('<div class="jscode">');
220 document.write('<input class="filter" id="filter_'+form+'" size="10" value="">');
221 document.write('<img class="filter" id="img_'+form+'" src="/pix/Actions-edit-delete-icon.png" border="0" ' +
222 'title="Filter löschen">');
223 document.write('<input type="hidden" id="rate_'+form+'" value="'+rate+'">');
224 document.write('<a href="#" onclick="return check('+form+',true)">Check all</a>');
225 document.write(" / ");
226 document.write('<a href="#" onclick="return check('+form+',false)">Uncheck all</a>');
227 document.write(" ");
228 document.write('<span id="time_'+form+'" class="sum">0:00</span>' );
229 document.write('<span id="sum_'+form+'" class="sum">€0.00</span>');
230 document.write(" ");
231 document.write('</div>');
234 function add_sum(form, checkbox)
236 var hours = $('#time_'+form);
237 var rate = $('#rate_'+form);
238 var sum = $('#sum_'+form);
239 var time = strtime($(checkbox).parents('tr:first').find('td:nth-child(2)').text());
242 if ($(checkbox).prop('checked')) {
243 newval = strtime(hours.text()) + time;
244 $(checkbox).parents('tr:first').css('background-color', color_checked);
246 newval = strtime(hours.text()) - time;
247 $(checkbox).parents('tr:first').css('background-color', '');
249 hours.text(timestr(newval));
250 sum.html('€' + ((newval/60)*rate.val()).toFixed(2));
253 var task_parent = null;
256 function edit_task(obj)
259 if (task_oid != obj.parentNode.children[0].children[0].value)
265 task_title = obj.innerHTML;
266 task_oid = obj.parentNode.children[0].children[0].value;
268 var input = $('<input>');
269 input.val(obj.innerHTML.replace('>', '>').replace('<', '<').replace('&', '&'));
270 input.css('fontSize', '100%').css('width', '100%').css('background', 'yellow');
272 $(obj).append(input);
277 function edit_task_save()
279 if (!task_parent) return;
281 if (task_parent.children[0].value != task_title)
282 $.invoke('Sales/Text', {id: task_oid, text: task_parent.children[0].value});
284 task_parent.innerHTML = task_parent.children[0].value;
290 function edit_task_finish(obj)
296 function toggle_checkbox(form, obj)
298 edit_task_finish(obj);
300 var row = $(obj).parents('tr:first');
301 var checkbox = row.find('input[type="checkbox"]')
302 checkbox.prop('checked', !checkbox.prop('checked'));
304 checkbox.checked = !checkbox.checked;
305 add_sum(form, checkbox);
308 function filter_change(e)
310 var form = $(this).attr('id').split('_')[1];
311 var filter = $('input#filter_'+form).val();
313 $('table#table_'+form+' tbody tr').each(function(i,e){
315 var td = $(this).find('td:nth-child(4)');
316 if (td.text().toLowerCase().indexOf(filter) > -1)
319 if ($(this).find('input[type="checkbox"]').prop('checked')) {
320 toggle_checkbox(form, td);
330 function filter_clear(e)
332 var form = $(this).attr('id').split('_')[1];
333 $('div.jscode input.filter#filter_'+form).val('').change();
337 $('div.jscode input.filter').change(filter_change);
338 $('div.jscode img.filter').click(filter_clear);
343 <style type="text/css">
349 div.jscode input.filter {
354 div.jscode img.filter {
362 border: 1px solid #9b9b9b;
376 <h3 class=bar>Display</h3>
378 <form action=status.php method=POST>
381 if (!is_array($months))
382 $months = find_months();
384 printf('<option value=""%s>alle</option>', !strlen($month)?' selected':'');
385 foreach ($months as $m) {
386 printf('<option value="%s"%s>%s</option>', $m, $month==$m?' selected':'', $m);
391 <select name=customer>
393 if (!is_array($customers))
394 $customers = find_customers();
396 printf('<option value=""%s>alle</option>', !strlen($cust)?' selected':'');
397 foreach ($customers as $c) {
398 printf('<option value="%s"%s>%s</option>', $c, $cust==$c?' selected':'', $c);
404 if (!is_array($stati))
405 $stati = find_status();
407 printf('<input type="radio" name="status" value="all"%s>alle ', $status=='all'?' checked':'');
408 foreach ($stati as $k=>$v)
409 printf('<input type="radio" name="status" value="%s"%s>%s ', $k, $status==$k?' checked':'', $v);
412 <input type="hidden" name="filter" value="form">
413 <input class="button" type="submit" value="Display">