1 #include <infocon.style>
5 <page func=InfoCon title="Stempeluhr">
6 <script type="text/javascript" src="<root_prefix>jquery.editable.js"></script>
7 <style type="text/css">
8 table.smallfont.border tr.sep td {
9 border-bottom: 1px solid #555;
14 session_name('STEMPEL');
18 function display_tables()
22 $wdays = array('So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa');
24 $name = load_customers();
26 $table_head = '<h3 class="bar">Kunde: %s</h3><script type="text/javascript">plant(%d,%.2f);</script>
27 <form action="status.php" method="POST">
28 <table class="smallfont border" id="table_%d" width="100%%" cellpadding=0 cellspacing=0>
31 <th width=15%% colspan="2">Datum</th>
32 <th width=5%%>Dauer</th>
33 <th width=5%%>St.</th>
34 <th width=75%% align=left>Arbeitsbeschreibung</th>
39 if (!is_array($stati))
40 $stati = find_status();
42 $table_foot = '</table><div align="center"><p>';
44 foreach ($stati as $k=>$v)
45 $table_foot .= sprintf('<input type="radio" name="status" value="%s"%s><span class="radio" data-value="%d" onclick="set_status(event)">%s</span> ', $k, 0==$k?' checked':'', $k, $v);
46 $table_foot .= '<input type="submit" class="button" value="Aktualisieren" onclick="return status_change(event)"></p></div>'.
47 '<input type="hidden" name="fields" value="%d">'.
50 $table_row = '<tr class="t%d" status="%d"><td>%s</td><td>%s</td><td align="center" onclick="toggle_checkbox(%d,this)">%s</td>' .
51 '<td align="center" onclick="toggle_checkbox(%d,this)">%s</td><td><span class="edit" route="Stempel/EditTask" item_id="%d">%s</span></td></tr>';
52 $table_sum = '</tbody><tfoot><tr class="t%d" onclick="edit_task_finish(this)">' .
53 '<td colspan="2"> </td><td align="center">%s</td><td> </td><td>Summe</td></tr></tfoot>';
55 $query = "SELECT stempel.oid,stempel.id,stempel.status,start,customer,time,task,kurz FROM stempel JOIN stempel_status ON (stempel.status = stempel_status.id) WHERE time IS NOT NULL ";
56 if (isset($_SESSION['save']['month']) && strlen($_SESSION['save']['month']))
57 $query .= "AND cast(start AS TEXT) LIKE '".$_SESSION['save']['month']."-%' ";
58 if (isset($_SESSION['save']['customer']) && strlen($_SESSION['save']['customer']))
59 $query .= "AND customer ='".$_SESSION['save']['customer']."' ";
60 if (isset($_SESSION['save']['keyword1']) && strlen($_SESSION['save']['keyword1']))
61 $query .= "AND task ILIKE '%".$_SESSION['save']['keyword1']."%' ";
62 if (isset($_SESSION['save']['keyword2']) && strlen($_SESSION['save']['keyword2']))
63 $query .= "AND task ILIKE '%".$_SESSION['save']['keyword2']."%' ";
64 if (isset($_SESSION['save']['time_from']) && strlen($_SESSION['save']['time_from']))
65 $query .= "AND start >= '".$_SESSION['save']['time_from']."' ";
66 if (isset($_SESSION['save']['time_to']) && strlen($_SESSION['save']['time_to']))
67 $query .= "AND stop <= '".$_SESSION['save']['time_to']."' ";
69 if (isset($_SESSION['save']['status']) && strlen($_SESSION['save']['status'])) {
70 if ($_SESSION['save']['status'] != 'all')
71 $query .= "AND status = ".$_SESSION['save']['status']." ";
73 $query .= "AND status = 0 ";
74 $query .= "ORDER BY customer,start";
76 $sth = pg_exec ($dbh, $query);
81 while ($row = pg_fetch_array ($sth)) {
83 if ($customer != $row['customer']) {
84 if (strlen($customer)) {
85 printf($table_sum, $color, min2hour($sum));
86 printf($table_foot, $fieldnr);
89 $cname = $name[$row['customer']]['name'];
90 if (!strlen($cname)) $cname = ucfirst($row['customer']);
91 printf($table_head, $cname, $form, $name[$row['customer']]['rate'], $form);
92 $customer = $row['customer'];
99 $d = explode(' ', $row['start']);
101 $check = sprintf('<input type="checkbox" class="checkbox" name="id_%d" value="%d" onclick="add_sum(%d,this)">',
105 $dt = new Datetime($d[0]);
106 if ($lastmonth !== false && $lastmonth != $dt->format('Y-m'))
107 printf('<tr class="sep"><td colspan="100%%"></td></tr>');
108 $date = sprintf('<span onclick="toggle_checkbox(%d,this)">%s, %s</span>', $form, $wdays[$dt->format('w')], $d[0]);
109 printf($table_row, $color, $row['status'], $check, $date, $form, min2hour($row['time']), $form, $row['kurz'],
111 htmlspecialchars($row['task'], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1'));
113 $lastmonth = $dt->format('Y-m');
115 if (pg_num_rows($sth) > 0) {
116 printf($table_sum, $color, min2hour($sum));
117 printf($table_foot, $fieldnr);
121 function find_customers()
126 $query = "SELECT DISTINCT customer FROM stempel ORDER BY customer";
127 $sth = pg_exec ($dbh, $query);
129 while ($row = pg_fetch_array ($sth))
135 if ($_SERVER['REQUEST_METHOD'] == 'GET' && count($_GET)) {
136 $_SESSION['save'] = [];
137 if (isset($_GET['customer']))
138 $_SESSION['save']['customer'] = $_GET['customer'];
139 if (isset($_GET['status']))
140 $_SESSION['save']['status'] = $_GET['status'];
141 if (isset($_GET['month']))
142 $_SESSION['save']['month'] = $_GET['month'];
143 header('Location: status.php');
147 $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
148 or die("Unable to connect to SQL server");
150 pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
152 if (isset($_POST["filter"])) {
153 $_SESSION['save']['month'] = $_POST['month'];
154 $_SESSION['save']['customer'] = $_POST['customer'];
155 $_SESSION['save']['status'] = $_POST['status'];
156 $_SESSION['save']['time_from'] = $_POST['time_from'];
157 $_SESSION['save']['time_to'] = $_POST['time_to'];
158 $_SESSION['save']['keyword1'] = $_POST['keyword1'];
159 $_SESSION['save']['keyword2'] = $_POST['keyword2'];
160 $_SESSION['redirect'] = true;
161 header('Location: status.php');
163 } elseif (isset($_POST["status"]) && isset($_POST["fields"])) {
165 $_SESSION['redirect'] = true;
166 header('Location: status.php');
168 } elseif (isset($_SESSION['redirect'])) {
169 $_SESSION['redirect'] = false;
171 if (isset($_GET['month'])) {
172 $_SESSION['save']['month'] = $_GET['month'];
173 unset($_SESSION['save']['customer']);
174 unset($_SESSION['save']['status']);
175 } elseif (!isset($_SESSION['save']['month'])) {
176 $_SESSION['save']['month'] = date('Y-m');
181 <script src="<root_prefix>basics.js"></script>
182 <script type="text/javascript">
184 var color_checked = '#c4ffc3';
185 function format_int(value, width)
187 var s = value.toString();
189 while (s.length < width)
195 function timestr(duration)
197 return format_int(Math.floor(duration / 60), 1) + ':'
198 + format_int(duration - (Math.floor(duration / 60) * 60), 2);
201 function strtime(time)
203 var a = time.split(':');
204 return parseInt(a[0],10) * 60 + parseInt(a[1],10);
207 function check(id, value)
209 var hours = $('#time_'+id);
210 var rate = $('#rate_'+id);
211 var sum = $('#sum_'+id);
214 $('table#table_'+id+' tbody tr:visible').each(function(i,e){
215 if (e.className == 'sep')
218 if (e.className.indexOf('sep ') > -1)
221 var checkbox = $(this).find('input[type="checkbox"]');
222 if (checkbox.prop('checked') != value) {
223 checkbox.prop('checked', !checkbox.prop('checked'));
224 if (checkbox.prop('checked'))
225 $(this).css('background-color', color_checked);
227 $(this).css('background-color', '');
228 add_sum(id, checkbox);
235 function plant(form, rate)
237 document.write('<div class="jscode">');
238 document.write('<input class="filter" id="filter_'+form+'" size="10" value="">');
239 document.write('<img class="filter" id="img_'+form+'" src="/pix/Actions-edit-delete-icon.png" border="0" ' +
240 'title="Filter löschen">');
241 document.write('<input type="hidden" id="rate_'+form+'" value="'+rate+'">');
242 document.write('<a href="#" onclick="return check('+form+',true)">Check all</a>');
243 document.write(" / ");
244 document.write('<a href="#" onclick="return check('+form+',false)">Uncheck all</a>');
245 document.write(" ");
246 document.write('<span id="time_'+form+'" class="sum">0:00</span>' );
247 document.write('<span id="sum_'+form+'" class="sum">€0.00</span>');
248 document.write(" ");
249 document.write('</div>');
252 function add_sum(form, checkbox)
254 var hours = $('#time_'+form);
255 var rate = $('#rate_'+form);
256 var sum = $('#sum_'+form);
257 var time = strtime($(checkbox).parents('tr:first').find('td:nth-child(3)').text());
260 if ($(checkbox).prop('checked')) {
261 newval = strtime(hours.text()) + time;
262 $(checkbox).parents('tr:first').css('background-color', color_checked);
264 newval = strtime(hours.text()) - time;
265 $(checkbox).parents('tr:first').css('background-color', '');
267 hours.text(timestr(newval));
268 sum.html('€' + ((newval/60)*rate.val()).toFixed(2));
271 var task_parent = null;
274 function edit_task(obj)
277 if (task_id != obj.parentNode.children[0].children[0].value)
283 task_title = obj.innerHTML;
284 task_id = obj.parentNode.children[0].children[0].value;
286 var input = $('<input>');
287 input.val(obj.innerHTML.replace('>', '>').replace('<', '<').replace('&', '&'));
288 input.css('fontSize', '100%').css('width', '100%').css('background', 'yellow');
290 $(obj).append(input);
295 function edit_task_save()
297 if (!task_parent) return;
299 if (task_parent.children[0].value != task_title)
300 $.invoke('Stempel/Task', {id: task_id, content: task_parent.children[0].value});
302 task_parent.innerHTML = task_parent.children[0].value;
308 function edit_task_finish(obj)
314 function toggle_checkbox(form, obj)
316 var row = $(obj).parents('tr:first');
317 var checkbox = row.find('input[type="checkbox"]')
318 checkbox.prop('checked', !checkbox.prop('checked'));
320 checkbox.checked = !checkbox.checked;
321 add_sum(form, checkbox);
324 function filter_change(e)
326 var form = $(this).attr('id').split('_')[1];
327 var filter = $('input#filter_'+form).val().toLowerCase();
330 $('table#table_'+form+' tbody tr').not('.sep').not('.deleted').each(function(i,e){
332 var td = $(this).find('td:nth-child(5)');
333 if (td.text().toLowerCase().indexOf(filter) > -1) {
334 $(this).removeClass('t0').removeClass('t1').addClass('t'+cnum).show();
337 if ($(this).find('input[type="checkbox"]').prop('checked')) {
338 toggle_checkbox(form, td);
343 $(this).removeClass('t0').removeClass('t1').addClass('t'+cnum).show();
349 function filter_clear(e)
351 var form = $(this).attr('id').split('_')[1];
352 $('div.jscode input.filter#filter_'+form).val('').keyup();
355 function status_change(e)
358 var form = $(e.target).parents('form:first');
359 var p = $(e.target).parents('p:first');
360 form.find('tr').not('.deleted').find('input.checkbox').each(function(i,e){
361 if ($(this).prop('checked') == true)
362 ids.push($(this).val());
366 p.find('input[name="status"]').each(function(i,e){
367 if ($(this).prop('checked') == true)
368 new_status = $(this).val();
371 $.invoke('Stempel/SetStatus', {status: new_status, ids: ids}, function(data){
372 for (var i=0; i < ids.length; i++) {
373 show_message('Positionen aktualisiert');
374 var checkbox = form.find('input.checkbox[value="'+ids[i]+'"]');
375 var row = checkbox.parents('tr:first');
377 checkbox.prop('checked',false);
378 add_sum(form.find('table:first').attr('id').split('_')[1], checkbox);
380 if (row.attr('status') != new_status)
381 row.addClass('deleted').hide();
388 function set_status(e)
390 var form = $(e.target).parents('form:first');
392 form.find('input[type="radio"]').each(function(i,el){
393 $(this).prop('checked', false);
395 $('input[type="radio"][value="'+$(e.target).attr('data-value')+'"]').prop('checked', true);
397 form.find('span.radio').each(function(i,el){
398 ($(this).css('fontWeight', ''))
400 $('span.radio[data-value="'+$(e.target).attr('data-value')+'"]').css('fontWeight', 'bold');
404 $('div.jscode input.filter').keyup(filter_change);
405 $('div.jscode img.filter').click(filter_clear);
406 make_editable('table.smallfont tr span.edit');
411 <style type="text/css">
417 div.jscode input.filter {
422 div.jscode img.filter {
430 border: 1px solid #9b9b9b;
444 <h3 class=bar>Display</h3>
446 <form action=status.php method=POST>
449 $month = isset($_SESSION['save']['month']) ? $_SESSION['save']['month'] : date('Y-m');
450 if (!isset($months) || !is_array($months))
451 $months = find_months();
453 printf('<option value=""%s>alle</option>', !strlen($month)?' selected':'');
454 foreach ($months as $m) {
455 printf('<option value="%s"%s>%s</option>', $m, $month==$m?' selected':'', $m);
460 <select name=customer>
462 $cust = isset($_SESSION['save']['customer']) ? $_SESSION['save']['customer'] : '';
463 if (!isset($customers) || !is_array($customers))
464 $customers = find_customers();
466 printf('<option value=""%s>alle</option>', !strlen($cust)?' selected':'');
467 foreach ($customers as $c) {
468 printf('<option value="%s"%s>%s</option>', $c, $cust==$c?' selected':'', $c);
474 $status = isset($_SESSION['save']['status']) ? $_SESSION['save']['status'] : 0;
475 if (!is_array($stati))
476 $stati = find_status();
478 printf('<input type="radio" name="status" value="all"%s>alle ', $status=='all'?' checked':'');
479 foreach ($stati as $k=>$v)
480 printf('<input type="radio" name="status" value="%s"%s>%s ', $k, $status==$k?' checked':'', $v);
483 <input type="hidden" name="filter" value="form">
484 <input class="button" type="submit" value="Display">
487 <input type="date" name="time_from" id="time_from" value="<?php echo isset($_SESSION['save']['time_from'])?$_SESSION['save']['time_from']:''?>">
489 <input type="date" name="time_to" id="time_to" value="<?php echo isset($_SESSION['save']['time_to'])?$_SESSION['save']['time_to']:''?>">
491 Keywords:
492 <input type="text" name="keyword1" id="keyword1" value="<?php echo isset($_SESSION['save']['keyword1'])?$_SESSION['save']['keyword1']:''?>">
493 <input type="text" name="keyword2" id="keyword2" value="<?php echo isset($_SESSION['save']['keyword2'])?$_SESSION['save']['keyword2']:''?>">