1 #include <infocon.style>
4 <page func=InfoCon title="Stempeluhr">
7 session_name('STEMPEL');
15 for ($idx=0; $idx < $_POST["fields"]; $idx++) {
16 if (isset($_POST["oid_".$idx])) {
17 $query = sprintf('UPDATE stempel SET status=%d WHERE oid=%d',
18 $_POST["status"], $_POST["oid_".$idx]);
20 $sth = pg_exec ($dbh, $query);
23 return sprintf("<br>%d records updated.", $count);
27 function display_tables()
35 $name = load_customers();
37 $table_head = '<h3 class="bar">Kunde: %s</h3><script type="text/javascript">plant(%d,%.2f);</script>
38 <form action="status.php" method="POST">
39 <table class="smallfont border" width="100%%" cellpadding=0 cellspacing=0>
40 <tr class="head" onclick="edit_task_finish(this)">
41 <th width=15%%>Datum</th>
42 <th width=5%%>Dauer</th>
43 <th width=5%%>St.</th>
44 <th width=75%% align=left>Arbeitsbeschreibung</th>
47 if (!is_array($stati))
48 $stati = find_status();
50 $table_foot = '</table><div align="center"><p>';
52 foreach ($stati as $k=>$v)
53 $table_foot .= sprintf('<input type="radio" name="status" value="%s"%s>%s ', $k, 0==$k?' checked':'', $v);
54 $table_foot .= '<input type="submit" class="button" value="Aktualisieren"></p></div>'.
55 '<input type="hidden" name="fields" value="%d">'.
58 $table_row = '<tr class="t%d"><td>%s</td><td align="center" onclick="toggle_checkbox(%d,this)">%s</td>' .
59 '<td align="center" onclick="toggle_checkbox(%d,this)">%s</td><td onclick="edit_task(this)">%s</td></tr>';
60 $table_sum = '<tr class="t%d"><td> </td><td align="center">%s</td><td> </td><td>Summe</td></tr>';
62 $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 ";
63 if (isset($month) && strlen($month))
64 $query .= "AND cast(start AS TEXT) LIKE '".$month."-%' ";
65 if (isset($cust) && strlen($cust))
66 $query .= "AND customer ='".$cust."' ";
68 if (isset($status) && strlen($status)) {
70 $query .= "AND status = $status ";
72 $query .= "AND status = 0 ";
73 $query .= "ORDER BY customer,start";
75 $sth = pg_exec ($dbh, $query);
79 while ($row = pg_fetch_array ($sth)) {
81 if ($customer != $row['customer']) {
82 if (strlen($customer)) {
83 printf($table_sum, $color, min2hour($sum));
84 printf($table_foot, $fieldnr);
87 $cname = $name[$row['customer']]['name'];
88 if (!strlen($cname)) $cname = ucfirst($row['customer']);
89 printf($table_head, $cname, $form, $name[$row['customer']]['rate']);
90 $customer = $row['customer'];
97 $d = explode(' ', $row['start']);
99 $check = sprintf('<input type="checkbox" class="checkbox" name="oid_%d" value="%d" onclick="add_sum(%d,this)">',
103 $date = sprintf('<span onclick="toggle_checkbox(%d,this)">%s</span>', $form, $d[0]);
104 printf($table_row, $color, $check.$date, $form, min2hour($row['time']), $form, $row['kurz'], htmlspecialchars($row['task'], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1'));
107 if (pg_num_rows($sth) > 0) {
108 printf($table_sum, $color, min2hour($sum));
109 printf($table_foot, $fieldnr);
113 function find_customers()
118 $query = "SELECT DISTINCT customer FROM stempel ORDER BY customer";
119 $sth = pg_exec ($dbh, $query);
121 while ($row = pg_fetch_array ($sth))
127 $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
128 or die("Unable to connect to SQL server");
130 pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
132 if (isset($_POST["status"]) && isset($_POST["fields"])) {
134 $_SESSION['redirect'] = true;
135 header('Location: status.php');
137 } elseif ($_SESSION['redirect']) {
138 $month = $_SESSION['save']["month"];
139 $cust = $_SESSION['save']["customer"];
140 $status = $_SESSION['save']["status"];
141 $_SESSION['redirect'] = false;
143 if (isset($_GET['month'])) {
144 $month = $_GET['month'];
145 $_SESSION['save']['month'] = $month;
146 unset($_SESSION['save']['customer']);
147 unset($_SESSION['save']['status']);
149 if (isset($_POST["filter"])) {
150 $month = $_POST["month"];
151 $cust = $_POST["customer"];
152 $status = $_POST["status"];
153 $_SESSION['save']['month'] = $month;
154 $_SESSION['save']['customer'] = $cust;
155 $_SESSION['save']['status'] = $status;
157 $month = date('Y-m');
158 $_SESSION['save']['month'] = $month;
159 unset($_SESSION['save']['customer']);
160 unset($_SESSION['save']['status']);
165 <script src="<root_prefix>basics.js"></script>
166 <script type="text/javascript">
167 var color_checked = '#c4ffc3';
168 function format_int(value, width)
170 var s = value.toString();
172 while (s.length < width)
178 function timestr(duration)
180 return format_int(Math.floor(duration / 60), 1) + ':'
181 + format_int(duration - (Math.floor(duration / 60) * 60), 2);
184 function strtime(time)
186 var a = time.split(':');
187 return parseInt(a[0],10) * 60 + parseInt(a[1],10);
190 function check(id, value)
192 var form = document.forms[id];
193 var hours=document.getElementById('time_'+id.toString());
194 var rate= document.getElementById('rate_'+id.toString());
195 var sum = document.getElementById('sum_'+id.toString());
198 for (i=0; i< form.elements.length; i++) {
199 if (form.elements[i].name.substr(0,4) == 'oid_') {
200 form.elements[i].checked = value;
202 var ta = form.elements[i].parentNode.nextSibling.innerHTML.split(':');
203 newval = newval + parseInt(ta[0],10) * 60 + parseInt(ta[1],10);
204 form.elements[i].parentNode.parentNode.style.backgroundColor = color_checked;
206 form.elements[i].parentNode.parentNode.style.backgroundColor = '';
210 hours.innerHTML = timestr(newval);
211 sum.innerHTML = '€' + ((newval/60)*rate.value).toFixed(2);
214 function plant(form, rate)
216 document.write('<div class="jscode">');
217 document.write('<input type="hidden" id="rate_'+form+'" value="'+rate+'">');
218 document.write('<a href="javascript:check('+form+',true)">Check all</a>');
219 document.write(" / ");
220 document.write('<a href="javascript:check('+form+',false)">Uncheck all</a>');
221 document.write(" ");
222 document.write('<span id="time_'+form+'" class="sum">0:00</span>' );
223 document.write('<span id="sum_'+form+'" class="sum">€0.00</span>');
224 document.write(" ");
225 document.write('</div>');
228 function add_sum(form, checkbox)
230 var hours = document.getElementById('time_'+form.toString());
231 var rate= document.getElementById('rate_'+form.toString());
232 var sum = document.getElementById('sum_'+form.toString());
233 var time = strtime(checkbox.parentNode.nextSibling.innerHTML);
236 if (checkbox.checked) {
237 newval = strtime(hours.innerHTML) + time;
238 checkbox.parentNode.parentNode.style.backgroundColor = color_checked;
240 newval = strtime(hours.innerHTML) - time;
241 checkbox.parentNode.parentNode.style.backgroundColor = '';
243 hours.innerHTML = timestr(newval);
244 sum.innerHTML = '€' + ((newval/60)*rate.value).toFixed(2);
247 var task_parent = null;
250 function edit_task(obj)
253 if (task_oid != obj.parentNode.children[0].children[0].value)
259 task_title = obj.innerHTML;
260 task_oid = obj.parentNode.children[0].children[0].value;
262 var input = document.createElement('input');
263 input.value = obj.innerHTML
264 input.style.fontSize = '100%';
265 input.style.width = '100%';
266 input.style.background = 'yellow';
269 obj.appendChild(input);
274 function edit_task_save()
276 if (!task_parent) return;
278 if (task_parent.children[0].value != task_title)
279 ajax_request('save','oid='+task_oid+'&task='+encodeURIComponent(task_parent.children[0].value));
281 task_parent.innerHTML = task_parent.children[0].value;
287 function edit_task_finish(obj)
293 function toggle_checkbox(form, obj)
295 edit_task_finish(obj);
298 while (row.tagName.toLowerCase() != 'tr')
299 row = row.parentNode;
301 var checkbox = row.children[0].children[0];
303 checkbox.checked = !checkbox.checked;
304 add_sum(form, checkbox);
308 <style type="text/css">
316 border: 1px solid #9b9b9b;
330 <h3 class=bar>Display</h3>
332 <form action=status.php method=POST>
335 if (!is_array($months))
336 $months = find_months();
338 printf('<option value=""%s>alle</option>', !strlen($month)?' selected':'');
339 foreach ($months as $m) {
340 printf('<option value="%s"%s>%s</option>', $m, $month==$m?' selected':'', $m);
345 <select name=customer>
347 if (!is_array($customers))
348 $customers = find_customers();
350 printf('<option value=""%s>alle</option>', !strlen($cust)?' selected':'');
351 foreach ($customers as $c) {
352 printf('<option value="%s"%s>%s</option>', $c, $cust==$c?' selected':'', $c);
358 if (!is_array($stati))
359 $stati = find_status();
361 printf('<input type="radio" name="status" value="all"%s>alle ', $status=='all'?' checked':'');
362 foreach ($stati as $k=>$v)
363 printf('<input type="radio" name="status" value="%s"%s>%s ', $k, $status==$k?' checked':'', $v);
366 <input type="hidden" name="filter" value="form">
367 <input class="button" type="submit" value="Display">