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" onclick="edit_task_finish(this)">' .
66 '<td> </td><td align="center">%s</td><td> </td><td>Summe</td></tr></tfoot>';
68 $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 ";
69 if (isset($month) && strlen($month))
70 $query .= "AND cast(start AS TEXT) LIKE '".$month."-%' ";
71 if (isset($cust) && strlen($cust))
72 $query .= "AND customer ='".$cust."' ";
74 if (isset($status) && strlen($status)) {
76 $query .= "AND status = $status ";
78 $query .= "AND status = 0 ";
79 $query .= "ORDER BY customer,start";
81 $sth = pg_exec ($dbh, $query);
85 while ($row = pg_fetch_array ($sth)) {
87 if ($customer != $row['customer']) {
88 if (strlen($customer)) {
89 printf($table_sum, $color, min2hour($sum));
90 printf($table_foot, $fieldnr);
93 $cname = $name[$row['customer']]['name'];
94 if (!strlen($cname)) $cname = ucfirst($row['customer']);
95 printf($table_head, $cname, $form, $name[$row['customer']]['rate'], $form);
96 $customer = $row['customer'];
102 $sum += $row['time'];
103 $d = explode(' ', $row['start']);
105 $check = sprintf('<input type="checkbox" class="checkbox" name="oid_%d" value="%d" onclick="add_sum(%d,this)">',
109 $date = sprintf('<span onclick="toggle_checkbox(%d,this)">%s</span>', $form, $d[0]);
110 printf($table_row, $color, $row['status'], $check.$date, $form, min2hour($row['time']), $form, $row['kurz'],
112 htmlspecialchars($row['task'], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1'));
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 $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
136 or die("Unable to connect to SQL server");
138 pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
140 if (isset($_POST["status"]) && isset($_POST["fields"])) {
142 $_SESSION['redirect'] = true;
143 header('Location: status.php');
145 } elseif ($_SESSION['redirect']) {
146 $month = $_SESSION['save']["month"];
147 $cust = $_SESSION['save']["customer"];
148 $status = $_SESSION['save']["status"];
149 $_SESSION['redirect'] = false;
151 if (isset($_GET['month'])) {
152 $month = $_GET['month'];
153 $_SESSION['save']['month'] = $month;
154 unset($_SESSION['save']['customer']);
155 unset($_SESSION['save']['status']);
157 if (isset($_POST["filter"])) {
158 $month = $_POST["month"];
159 $cust = $_POST["customer"];
160 $status = $_POST["status"];
161 $_SESSION['save']['month'] = $month;
162 $_SESSION['save']['customer'] = $cust;
163 $_SESSION['save']['status'] = $status;
165 $month = date('Y-m');
166 $_SESSION['save']['month'] = $month;
167 unset($_SESSION['save']['customer']);
168 unset($_SESSION['save']['status']);
173 <script src="<root_prefix>basics.js"></script>
174 <script type="text/javascript">
176 var color_checked = '#c4ffc3';
177 function format_int(value, width)
179 var s = value.toString();
181 while (s.length < width)
187 function timestr(duration)
189 return format_int(Math.floor(duration / 60), 1) + ':'
190 + format_int(duration - (Math.floor(duration / 60) * 60), 2);
193 function strtime(time)
195 var a = time.split(':');
196 return parseInt(a[0],10) * 60 + parseInt(a[1],10);
199 function check(id, value)
201 var hours = $('#time_'+id);
202 var rate = $('#rate_'+id);
203 var sum = $('#sum_'+id);
206 $('table#table_'+id+' tbody tr:visible').each(function(i,e){
207 var checkbox = $(this).find('input[type="checkbox"]');
208 if (checkbox.prop('checked') != value) {
209 checkbox.prop('checked', !checkbox.prop('checked'));
210 if (checkbox.prop('checked'))
211 $(this).css('background-color', color_checked);
213 $(this).css('background-color', '');
214 add_sum(id, checkbox);
221 function plant(form, rate)
223 document.write('<div class="jscode">');
224 document.write('<input class="filter" id="filter_'+form+'" size="10" value="">');
225 document.write('<img class="filter" id="img_'+form+'" src="/pix/Actions-edit-delete-icon.png" border="0" ' +
226 'title="Filter löschen">');
227 document.write('<input type="hidden" id="rate_'+form+'" value="'+rate+'">');
228 document.write('<a href="#" onclick="return check('+form+',true)">Check all</a>');
229 document.write(" / ");
230 document.write('<a href="#" onclick="return check('+form+',false)">Uncheck all</a>');
231 document.write(" ");
232 document.write('<span id="time_'+form+'" class="sum">0:00</span>' );
233 document.write('<span id="sum_'+form+'" class="sum">€0.00</span>');
234 document.write(" ");
235 document.write('</div>');
238 function add_sum(form, checkbox)
240 var hours = $('#time_'+form);
241 var rate = $('#rate_'+form);
242 var sum = $('#sum_'+form);
243 var time = strtime($(checkbox).parents('tr:first').find('td:nth-child(2)').text());
246 if ($(checkbox).prop('checked')) {
247 newval = strtime(hours.text()) + time;
248 $(checkbox).parents('tr:first').css('background-color', color_checked);
250 newval = strtime(hours.text()) - time;
251 $(checkbox).parents('tr:first').css('background-color', '');
253 hours.text(timestr(newval));
254 sum.html('€' + ((newval/60)*rate.val()).toFixed(2));
257 function toggle_checkbox(form, obj)
259 var row = $(obj).parents('tr:first');
260 var checkbox = row.find('input[type="checkbox"]')
261 checkbox.prop('checked', !checkbox.prop('checked'));
263 checkbox.checked = !checkbox.checked;
264 add_sum(form, checkbox);
267 function filter_change(e)
269 var form = $(this).attr('id').split('_')[1];
270 var filter = $('input#filter_'+form).val();
273 $('table#table_'+form+' tbody tr').not('.deleted').each(function(i,e){
275 var td = $(this).find('td:nth-child(4)');
276 if (td.text().toLowerCase().indexOf(filter) > -1) {
277 $(this).removeClass('t0').removeClass('t1').addClass('t'+cnum).show();
280 if ($(this).find('input[type="checkbox"]').prop('checked')) {
281 toggle_checkbox(form, td);
286 $(this).removeClass('t0').removeClass('t1').addClass('t'+cnum).show();
292 function filter_clear(e)
294 var form = $(this).attr('id').split('_')[1];
295 $('div.jscode input.filter#filter_'+form).val('').keyup();
298 function status_change(e)
301 var form = $(e.target).parents('form:first');
302 var p = $(e.target).parents('p:first');
303 form.find('tr').not('.deleted').find('input.checkbox').each(function(i,e){
304 if ($(this).prop('checked') == true)
305 ids.push($(this).val());
309 p.find('input[name="status"]').each(function(i,e){
310 if ($(this).prop('checked') == true)
311 new_status = $(this).val();
314 $.invoke('Sales/SetStatus', {status: new_status, ids: ids}, function(data){
315 for (var i=0; i < ids.length; i++) {
316 show_message('Positionen aktualisiert');
317 var checkbox = form.find('input.checkbox[value="'+ids[i]+'"]');
318 var row = checkbox.parents('tr:first');
320 checkbox.prop('checked',false);
321 add_sum(form.find('table:first').attr('id').split('_')[1], checkbox);
323 if (row.attr('status') != new_status)
324 row.addClass('deleted').hide();
332 $('div.jscode input.filter').keyup(filter_change);
333 $('div.jscode img.filter').click(filter_clear);
334 make_editable('table.smallfont tr span');
339 <style type="text/css">
345 div.jscode input.filter {
350 div.jscode img.filter {
358 border: 1px solid #9b9b9b;
372 <h3 class=bar>Display</h3>
374 <form action=status.php method=POST>
377 if (!is_array($months))
378 $months = find_months();
380 printf('<option value=""%s>alle</option>', !strlen($month)?' selected':'');
381 foreach ($months as $m) {
382 printf('<option value="%s"%s>%s</option>', $m, $month==$m?' selected':'', $m);
387 <select name=customer>
389 if (!is_array($customers))
390 $customers = find_customers();
392 printf('<option value=""%s>alle</option>', !strlen($cust)?' selected':'');
393 foreach ($customers as $c) {
394 printf('<option value="%s"%s>%s</option>', $c, $cust==$c?' selected':'', $c);
400 if (!is_array($stati))
401 $stati = find_status();
403 printf('<input type="radio" name="status" value="all"%s>alle ', $status=='all'?' checked':'');
404 foreach ($stati as $k=>$v)
405 printf('<input type="radio" name="status" value="%s"%s>%s ', $k, $status==$k?' checked':'', $v);
408 <input type="hidden" name="filter" value="form">
409 <input class="button" type="submit" value="Display">