1 #include <infocon.style>
5 <page func=InfoCon title="Stempeluhr">
6 <script type="text/javascript" src="<root_prefix>jquery.editable.js"></script>
9 session_name('STEMPEL');
13 function display_tables()
21 $name = load_customers();
23 $table_head = '<h3 class="bar">Kunde: %s</h3><script type="text/javascript">plant(%d,%.2f);</script>
24 <form action="status.php" method="POST">
25 <table class="smallfont border" id="table_%d" width="100%%" cellpadding=0 cellspacing=0>
28 <th width=15%%>Datum</th>
29 <th width=5%%>Dauer</th>
30 <th width=5%%>St.</th>
31 <th width=75%% align=left>Arbeitsbeschreibung</th>
36 if (!is_array($stati))
37 $stati = find_status();
39 $table_foot = '</table><div align="center"><p>';
41 foreach ($stati as $k=>$v)
42 $table_foot .= sprintf('<input type="radio" name="status" value="%s"%s>%s ', $k, 0==$k?' checked':'', $v);
43 $table_foot .= '<input type="submit" class="button" value="Aktualisieren" onclick="return status_change(event)"></p></div>'.
44 '<input type="hidden" name="fields" value="%d">'.
47 $table_row = '<tr class="t%d" status="%d"><td>%s</td><td align="center" onclick="toggle_checkbox(%d,this)">%s</td>' .
48 '<td align="center" onclick="toggle_checkbox(%d,this)">%s</td><td><span class="edit" route="Stempel/EditTask" item_id="%d">%s</span></td></tr>';
49 $table_sum = '</tbody><tfoot><tr class="t%d" onclick="edit_task_finish(this)">' .
50 '<td> </td><td align="center">%s</td><td> </td><td>Summe</td></tr></tfoot>';
52 $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 ";
53 if (isset($month) && strlen($month))
54 $query .= "AND cast(start AS TEXT) LIKE '".$month."-%' ";
55 if (isset($cust) && strlen($cust))
56 $query .= "AND customer ='".$cust."' ";
58 if (isset($status) && strlen($status)) {
60 $query .= "AND status = $status ";
62 $query .= "AND status = 0 ";
63 $query .= "ORDER BY customer,start";
65 $sth = pg_exec ($dbh, $query);
69 while ($row = pg_fetch_array ($sth)) {
71 if ($customer != $row['customer']) {
72 if (strlen($customer)) {
73 printf($table_sum, $color, min2hour($sum));
74 printf($table_foot, $fieldnr);
77 $cname = $name[$row['customer']]['name'];
78 if (!strlen($cname)) $cname = ucfirst($row['customer']);
79 printf($table_head, $cname, $form, $name[$row['customer']]['rate'], $form);
80 $customer = $row['customer'];
87 $d = explode(' ', $row['start']);
89 $check = sprintf('<input type="checkbox" class="checkbox" name="id_%d" value="%d" onclick="add_sum(%d,this)">',
93 $date = sprintf('<span onclick="toggle_checkbox(%d,this)">%s</span>', $form, $d[0]);
94 printf($table_row, $color, $row['status'], $check.$date, $form, min2hour($row['time']), $form, $row['kurz'],
96 htmlspecialchars($row['task'], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1'));
99 if (pg_num_rows($sth) > 0) {
100 printf($table_sum, $color, min2hour($sum));
101 printf($table_foot, $fieldnr);
105 function find_customers()
110 $query = "SELECT DISTINCT customer FROM stempel ORDER BY customer";
111 $sth = pg_exec ($dbh, $query);
113 while ($row = pg_fetch_array ($sth))
119 $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
120 or die("Unable to connect to SQL server");
122 pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
124 if (isset($_POST["status"]) && isset($_POST["fields"])) {
126 $_SESSION['redirect'] = true;
127 header('Location: status.php');
129 } elseif ($_SESSION['redirect']) {
130 $month = $_SESSION['save']["month"];
131 $cust = $_SESSION['save']["customer"];
132 $status = $_SESSION['save']["status"];
133 $_SESSION['redirect'] = false;
135 if (isset($_GET['month'])) {
136 $month = $_GET['month'];
137 $_SESSION['save']['month'] = $month;
138 unset($_SESSION['save']['customer']);
139 unset($_SESSION['save']['status']);
141 if (isset($_POST["filter"])) {
142 $month = $_POST["month"];
143 $cust = $_POST["customer"];
144 $status = $_POST["status"];
145 $_SESSION['save']['month'] = $month;
146 $_SESSION['save']['customer'] = $cust;
147 $_SESSION['save']['status'] = $status;
149 $month = date('Y-m');
150 $_SESSION['save']['month'] = $month;
151 unset($_SESSION['save']['customer']);
152 unset($_SESSION['save']['status']);
157 <script src="<root_prefix>basics.js"></script>
158 <script type="text/javascript">
160 var color_checked = '#c4ffc3';
161 function format_int(value, width)
163 var s = value.toString();
165 while (s.length < width)
171 function timestr(duration)
173 return format_int(Math.floor(duration / 60), 1) + ':'
174 + format_int(duration - (Math.floor(duration / 60) * 60), 2);
177 function strtime(time)
179 var a = time.split(':');
180 return parseInt(a[0],10) * 60 + parseInt(a[1],10);
183 function check(id, value)
185 var hours = $('#time_'+id);
186 var rate = $('#rate_'+id);
187 var sum = $('#sum_'+id);
190 $('table#table_'+id+' tbody tr:visible').each(function(i,e){
191 var checkbox = $(this).find('input[type="checkbox"]');
192 if (checkbox.prop('checked') != value) {
193 checkbox.prop('checked', !checkbox.prop('checked'));
194 if (checkbox.prop('checked'))
195 $(this).css('background-color', color_checked);
197 $(this).css('background-color', '');
198 add_sum(id, checkbox);
205 function plant(form, rate)
207 document.write('<div class="jscode">');
208 document.write('<input class="filter" id="filter_'+form+'" size="10" value="">');
209 document.write('<img class="filter" id="img_'+form+'" src="/pix/Actions-edit-delete-icon.png" border="0" ' +
210 'title="Filter löschen">');
211 document.write('<input type="hidden" id="rate_'+form+'" value="'+rate+'">');
212 document.write('<a href="#" onclick="return check('+form+',true)">Check all</a>');
213 document.write(" / ");
214 document.write('<a href="#" onclick="return check('+form+',false)">Uncheck all</a>');
215 document.write(" ");
216 document.write('<span id="time_'+form+'" class="sum">0:00</span>' );
217 document.write('<span id="sum_'+form+'" class="sum">€0.00</span>');
218 document.write(" ");
219 document.write('</div>');
222 function add_sum(form, checkbox)
224 var hours = $('#time_'+form);
225 var rate = $('#rate_'+form);
226 var sum = $('#sum_'+form);
227 var time = strtime($(checkbox).parents('tr:first').find('td:nth-child(2)').text());
230 if ($(checkbox).prop('checked')) {
231 newval = strtime(hours.text()) + time;
232 $(checkbox).parents('tr:first').css('background-color', color_checked);
234 newval = strtime(hours.text()) - time;
235 $(checkbox).parents('tr:first').css('background-color', '');
237 hours.text(timestr(newval));
238 sum.html('€' + ((newval/60)*rate.val()).toFixed(2));
241 var task_parent = null;
244 function edit_task(obj)
247 if (task_id != obj.parentNode.children[0].children[0].value)
253 task_title = obj.innerHTML;
254 task_id = obj.parentNode.children[0].children[0].value;
256 var input = $('<input>');
257 input.val(obj.innerHTML.replace('>', '>').replace('<', '<').replace('&', '&'));
258 input.css('fontSize', '100%').css('width', '100%').css('background', 'yellow');
260 $(obj).append(input);
265 function edit_task_save()
267 if (!task_parent) return;
269 if (task_parent.children[0].value != task_title)
270 $.invoke('Stempel/Task', {id: task_id, content: task_parent.children[0].value});
272 task_parent.innerHTML = task_parent.children[0].value;
278 function edit_task_finish(obj)
284 function toggle_checkbox(form, obj)
286 var row = $(obj).parents('tr:first');
287 var checkbox = row.find('input[type="checkbox"]')
288 checkbox.prop('checked', !checkbox.prop('checked'));
290 checkbox.checked = !checkbox.checked;
291 add_sum(form, checkbox);
294 function filter_change(e)
296 var form = $(this).attr('id').split('_')[1];
297 var filter = $('input#filter_'+form).val();
300 $('table#table_'+form+' tbody tr').not('.deleted').each(function(i,e){
302 var td = $(this).find('td:nth-child(4)');
303 if (td.text().toLowerCase().indexOf(filter) > -1) {
304 $(this).removeClass('t0').removeClass('t1').addClass('t'+cnum).show();
307 if ($(this).find('input[type="checkbox"]').prop('checked')) {
308 toggle_checkbox(form, td);
313 $(this).removeClass('t0').removeClass('t1').addClass('t'+cnum).show();
319 function filter_clear(e)
321 var form = $(this).attr('id').split('_')[1];
322 $('div.jscode input.filter#filter_'+form).val('').keyup();
325 function status_change(e)
328 var form = $(e.target).parents('form:first');
329 var p = $(e.target).parents('p:first');
330 form.find('tr').not('.deleted').find('input.checkbox').each(function(i,e){
331 if ($(this).prop('checked') == true)
332 ids.push($(this).val());
336 p.find('input[name="status"]').each(function(i,e){
337 if ($(this).prop('checked') == true)
338 new_status = $(this).val();
341 $.invoke('Stempel/SetStatus', {status: new_status, ids: ids}, function(data){
342 for (var i=0; i < ids.length; i++) {
343 show_message('Positionen aktualisiert');
344 var checkbox = form.find('input.checkbox[value="'+ids[i]+'"]');
345 var row = checkbox.parents('tr:first');
347 checkbox.prop('checked',false);
348 add_sum(form.find('table:first').attr('id').split('_')[1], checkbox);
350 if (row.attr('status') != new_status)
351 row.addClass('deleted').hide();
359 $('div.jscode input.filter').keyup(filter_change);
360 $('div.jscode img.filter').click(filter_clear);
361 make_editable('table.smallfont tr span.edit');
366 <style type="text/css">
372 div.jscode input.filter {
377 div.jscode img.filter {
385 border: 1px solid #9b9b9b;
399 <h3 class=bar>Display</h3>
401 <form action=status.php method=POST>
404 if (!is_array($months))
405 $months = find_months();
407 printf('<option value=""%s>alle</option>', !strlen($month)?' selected':'');
408 foreach ($months as $m) {
409 printf('<option value="%s"%s>%s</option>', $m, $month==$m?' selected':'', $m);
414 <select name=customer>
416 if (!is_array($customers))
417 $customers = find_customers();
419 printf('<option value=""%s>alle</option>', !strlen($cust)?' selected':'');
420 foreach ($customers as $c) {
421 printf('<option value="%s"%s>%s</option>', $c, $cust==$c?' selected':'', $c);
427 if (!is_array($stati))
428 $stati = find_status();
430 printf('<input type="radio" name="status" value="all"%s>alle ', $status=='all'?' checked':'');
431 foreach ($stati as $k=>$v)
432 printf('<input type="radio" name="status" value="%s"%s>%s ', $k, $status==$k?' checked':'', $v);
435 <input type="hidden" name="filter" value="form">
436 <input class="button" type="submit" value="Display">