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');
17 for ($idx=0; $idx < $_POST["fields"]; $idx++) {
18 if (isset($_POST["oid_".$idx])) {
19 $query = sprintf('UPDATE stempel SET status=%d WHERE oid=%d',
20 $_POST["status"], $_POST["oid_".$idx]);
22 $sth = pg_exec ($dbh, $query);
25 return sprintf("<br>%d records updated.", $count);
29 function display_tables()
37 $name = load_customers();
39 $table_head = '<h3 class="bar">Kunde: %s</h3><script type="text/javascript">plant(%d,%.2f);</script>
40 <form action="status.php" method="POST">
41 <table class="smallfont border" id="table_%d" width="100%%" cellpadding=0 cellspacing=0>
44 <th width=15%%>Datum</th>
45 <th width=5%%>Dauer</th>
46 <th width=5%%>St.</th>
47 <th width=75%% align=left>Arbeitsbeschreibung</th>
52 if (!is_array($stati))
53 $stati = find_status();
55 $table_foot = '</table><div align="center"><p>';
57 foreach ($stati as $k=>$v)
58 $table_foot .= sprintf('<input type="radio" name="status" value="%s"%s>%s ', $k, 0==$k?' checked':'', $v);
59 $table_foot .= '<input type="submit" class="button" value="Aktualisieren" onclick="return status_change(event)"></p></div>'.
60 '<input type="hidden" name="fields" value="%d">'.
63 $table_row = '<tr class="t%d" status="%d"><td>%s</td><td align="center" onclick="toggle_checkbox(%d,this)">%s</td>' .
64 '<td align="center" onclick="toggle_checkbox(%d,this)">%s</td><td><span route="Stempel/EditTask" item_id="%d">%s</span></td></tr>';
65 $table_sum = '</tbody><tfoot><tr class="t%d"><td> </td><td align="center">%s</td><td> </td><td>Summe</td></tr></tfoot>';
67 $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 ";
68 if (isset($month) && strlen($month))
69 $query .= "AND cast(start AS TEXT) LIKE '".$month."-%' ";
70 if (isset($cust) && strlen($cust))
71 $query .= "AND customer ='".$cust."' ";
73 if (isset($status) && strlen($status)) {
75 $query .= "AND status = $status ";
77 $query .= "AND status = 0 ";
78 $query .= "ORDER BY customer,start";
80 $sth = pg_exec ($dbh, $query);
84 while ($row = pg_fetch_array ($sth)) {
86 if ($customer != $row['customer']) {
87 if (strlen($customer)) {
88 printf($table_sum, $color, min2hour($sum));
89 printf($table_foot, $fieldnr);
92 $cname = $name[$row['customer']]['name'];
93 if (!strlen($cname)) $cname = ucfirst($row['customer']);
94 printf($table_head, $cname, $form, $name[$row['customer']]['rate'], $form);
95 $customer = $row['customer'];
101 $sum += $row['time'];
102 $d = explode(' ', $row['start']);
104 $check = sprintf('<input type="checkbox" class="checkbox" name="oid_%d" value="%d" onclick="add_sum(%d,this)">',
108 $date = sprintf('<span onclick="toggle_checkbox(%d,this)">%s</span>', $form, $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'));
114 if (pg_num_rows($sth) > 0) {
115 printf($table_sum, $color, min2hour($sum));
116 printf($table_foot, $fieldnr);
120 function find_customers()
125 $query = "SELECT DISTINCT customer FROM stempel ORDER BY customer";
126 $sth = pg_exec ($dbh, $query);
128 while ($row = pg_fetch_array ($sth))
134 $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
135 or die("Unable to connect to SQL server");
137 pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
139 if (isset($_POST["status"]) && isset($_POST["fields"])) {
141 $_SESSION['redirect'] = true;
142 header('Location: status.php');
144 } elseif ($_SESSION['redirect']) {
145 $month = $_SESSION['save']["month"];
146 $cust = $_SESSION['save']["customer"];
147 $status = $_SESSION['save']["status"];
148 $_SESSION['redirect'] = false;
150 if (isset($_GET['month'])) {
151 $month = $_GET['month'];
152 $_SESSION['save']['month'] = $month;
153 unset($_SESSION['save']['customer']);
154 unset($_SESSION['save']['status']);
156 if (isset($_POST["filter"])) {
157 $month = $_POST["month"];
158 $cust = $_POST["customer"];
159 $status = $_POST["status"];
160 $_SESSION['save']['month'] = $month;
161 $_SESSION['save']['customer'] = $cust;
162 $_SESSION['save']['status'] = $status;
164 $month = date('Y-m');
165 $_SESSION['save']['month'] = $month;
166 unset($_SESSION['save']['customer']);
167 unset($_SESSION['save']['status']);
172 <script src="<root_prefix>basics.js"></script>
173 <script type="text/javascript">
175 var color_checked = '#c4ffc3';
176 function format_int(value, width)
178 var s = value.toString();
180 while (s.length < width)
186 function timestr(duration)
188 return format_int(Math.floor(duration / 60), 1) + ':'
189 + format_int(duration - (Math.floor(duration / 60) * 60), 2);
192 function strtime(time)
194 var a = time.split(':');
195 return parseInt(a[0],10) * 60 + parseInt(a[1],10);
198 function check(id, value)
200 var hours = $('#time_'+id);
201 var rate = $('#rate_'+id);
202 var sum = $('#sum_'+id);
205 $('table#table_'+id+' tbody tr:visible').each(function(i,e){
206 var checkbox = $(this).find('input[type="checkbox"]');
207 if (checkbox.prop('checked') != value) {
208 checkbox.prop('checked', !checkbox.prop('checked'));
209 if (checkbox.prop('checked'))
210 $(this).css('background-color', color_checked);
212 $(this).css('background-color', '');
213 add_sum(id, checkbox);
220 function plant(form, rate)
222 document.write('<div class="jscode">');
223 document.write('<input class="filter" id="filter_'+form+'" size="10" value="">');
224 document.write('<img class="filter" id="img_'+form+'" src="/pix/Actions-edit-delete-icon.png" border="0" ' +
225 'title="Filter löschen">');
226 document.write('<input type="hidden" id="rate_'+form+'" value="'+rate+'">');
227 document.write('<a href="#" onclick="return check('+form+',true)">Check all</a>');
228 document.write(" / ");
229 document.write('<a href="#" onclick="return check('+form+',false)">Uncheck all</a>');
230 document.write(" ");
231 document.write('<span id="time_'+form+'" class="sum">0:00</span>' );
232 document.write('<span id="sum_'+form+'" class="sum">€0.00</span>');
233 document.write(" ");
234 document.write('</div>');
237 function add_sum(form, checkbox)
239 var hours = $('#time_'+form);
240 var rate = $('#rate_'+form);
241 var sum = $('#sum_'+form);
242 var time = strtime($(checkbox).parents('tr:first').find('td:nth-child(2)').text());
245 if ($(checkbox).prop('checked')) {
246 newval = strtime(hours.text()) + time;
247 $(checkbox).parents('tr:first').css('background-color', color_checked);
249 newval = strtime(hours.text()) - time;
250 $(checkbox).parents('tr:first').css('background-color', '');
252 hours.text(timestr(newval));
253 sum.html('€' + ((newval/60)*rate.val()).toFixed(2));
256 function toggle_checkbox(form, obj)
258 var row = $(obj).parents('tr:first');
259 var checkbox = row.find('input[type="checkbox"]')
260 checkbox.prop('checked', !checkbox.prop('checked'));
262 checkbox.checked = !checkbox.checked;
263 add_sum(form, checkbox);
266 function filter_change(e)
268 var form = $(this).attr('id').split('_')[1];
269 var filter = $('input#filter_'+form).val();
272 $('table#table_'+form+' tbody tr').not('.deleted').each(function(i,e){
274 var td = $(this).find('td:nth-child(4)');
275 if (td.text().toLowerCase().indexOf(filter) > -1) {
276 $(this).removeClass('t0').removeClass('t1').addClass('t'+cnum).show();
279 if ($(this).find('input[type="checkbox"]').prop('checked')) {
280 toggle_checkbox(form, td);
285 $(this).removeClass('t0').removeClass('t1').addClass('t'+cnum).show();
291 function filter_clear(e)
293 var form = $(this).attr('id').split('_')[1];
294 $('div.jscode input.filter#filter_'+form).val('').keyup();
297 function status_change(e)
300 var form = $(e.target).parents('form:first');
301 var p = $(e.target).parents('p:first');
302 form.find('tr').not('.deleted').find('input.checkbox').each(function(i,e){
303 if ($(this).prop('checked') == true)
304 ids.push($(this).val());
308 p.find('input[name="status"]').each(function(i,e){
309 if ($(this).prop('checked') == true)
310 new_status = $(this).val();
313 $.invoke('Sales/SetStatus', {status: new_status, ids: ids}, function(data){
314 for (var i=0; i < ids.length; i++) {
315 show_message('Positionen aktualisiert');
316 var checkbox = form.find('input.checkbox[value="'+ids[i]+'"]');
317 var row = checkbox.parents('tr:first');
319 checkbox.prop('checked',false);
320 add_sum(form.find('table:first').attr('id').split('_')[1], checkbox);
322 if (row.attr('status') != new_status)
323 row.addClass('deleted').hide();
331 $('div.jscode input.filter').keyup(filter_change);
332 $('div.jscode img.filter').click(filter_clear);
333 make_editable('table.smallfont tr span');
338 <style type="text/css">
344 div.jscode input.filter {
349 div.jscode img.filter {
357 border: 1px solid #9b9b9b;
371 <h3 class=bar>Display</h3>
373 <form action=status.php method=POST>
376 if (!is_array($months))
377 $months = find_months();
379 printf('<option value=""%s>alle</option>', !strlen($month)?' selected':'');
380 foreach ($months as $m) {
381 printf('<option value="%s"%s>%s</option>', $m, $month==$m?' selected':'', $m);
386 <select name=customer>
388 if (!is_array($customers))
389 $customers = find_customers();
391 printf('<option value=""%s>alle</option>', !strlen($cust)?' selected':'');
392 foreach ($customers as $c) {
393 printf('<option value="%s"%s>%s</option>', $c, $cust==$c?' selected':'', $c);
399 if (!is_array($stati))
400 $stati = find_status();
402 printf('<input type="radio" name="status" value="all"%s>alle ', $status=='all'?' checked':'');
403 foreach ($stati as $k=>$v)
404 printf('<input type="radio" name="status" value="%s"%s>%s ', $k, $status==$k?' checked':'', $v);
407 <input type="hidden" name="filter" value="form">
408 <input class="button" type="submit" value="Display">