Unify column title
[infodrom.org/service.infodrom.org] / src / InfoCon / stempel / status.wml
index 517cf95..2141735 100644 (file)
@@ -2,6 +2,9 @@
 #include "common.inc"
 
 <?
+  session_name('STEMPEL');
+  session_start();
+
   function update_db()
   {
     global $dbh;
     global $dbh;
     global $stati;
 
-    $table_head = '<h3 class="bar">Kunde: %s</h3><form action="status.php" method="POST">
-  <table class="smallfont border" width="100%%" cellpadding=0 cellspacing=1>
-  <tr class="head">
+    $name = load_customers();
+
+    $table_head = '<h3 class="bar">Kunde: %s</h3><script type="text/javascript">plant(%d);</script>
+  <form action="status.php" method="POST">
+  <table class="smallfont border" width="100%%" cellpadding=0 cellspacing=0>
+  <tr class="head" onclick="edit_task_finish(this)">
     <th width=15%%>Datum</th>
     <th width=5%%>Dauer</th>
     <th width=5%%>St.</th>
-    <th width=75%%>Verwendungszweck</th>
+    <th width=75%% align=left>Arbeitsbeschreibung</th>
   </tr>';
 
     if (!is_array($stati))
 
     foreach ($stati as $k=>$v)
       $table_foot .= sprintf('<input type="radio" name="status" value="%s"%s>%s&nbsp;', $k, 0==$k?' checked':'', $v);
-      $table_foot .= '</p><p><input type="submit" class="button" value="Aktualisieren"></div>'.
-                 '<input type="hidden" name="fields" value="%d"></p>'.
+      $table_foot .= '<input type="submit" class="button" value="Aktualisieren"></p></div>'.
+                 '<input type="hidden" name="fields" value="%d">'.
                  '</form>';
 
-    $table_row = '<tr class=t%d><td>%s</td><td align="center">%s</td><td align="center">%s</td><td>%s</td></tr>';
+    $table_row = '<tr class="t%d"><td>%s</td><td align="center">%s</td><td align="center">%s</td><td onclick="edit_task(this)">%s</td></tr>';
     $table_sum = '<tr class="t%d"><td>&nbsp;</td><td align="center">%s</td><td>&nbsp;</td><td>Summe</td></tr>';
 
     $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 ";
@@ -55,9 +61,8 @@
       $query .= "AND cast(start AS TEXT) LIKE '".$month."-%' ";
     if (isset($cust) && strlen($cust))
       $query .= "AND customer ='".$cust."' ";
-    // xxxxxxxxxxx
 
-    if (isset($status)) {
+    if (isset($status) && strlen($status)) {
       if ($status != 'all')
         $query .= "AND status = $status ";
     } else
@@ -66,6 +71,7 @@
 
     $sth = pg_exec ($dbh, $query);
 
+    $form = 0;
     $customer = '';
     while ($row = pg_fetch_array ($sth)) {
 
        if (strlen($customer)) {
          printf($table_sum, $color, min2hour($sum));
          printf($table_foot, $fieldnr);
+         $form++;
        }
-       printf($table_head, $row['customer']);
+       $cname = $name[$row['customer']];
+       if (!strlen($cname)) $cname = ucfirst($row['customer']);
+       printf($table_head, $cname, $form);
        $customer = $row['customer'];
        $fieldnr = 0;
        $sum = 0;
       $sum += $row['time'];
       $d = explode(' ', $row['start']);
 
-      $check = '<input type="checkbox" name="oid_'.$fieldnr++.'" value="'.$row['oid'].'">';
-      printf($table_row, $color, $check.$d[0], min2hour($row['time']), $row['kurz'], $row['task']);
+      $check = sprintf('<input type="checkbox" class="checkbox" name="oid_%d" value="%d" onclick="add_sum(%d,this)">',
+                      $fieldnr++,
+                      $row['oid'],
+                      $form);
+      printf($table_row, $color, $check.$d[0], min2hour($row['time']), $row['kurz'], htmlspecialchars($row['task']));
       $color = !$color;
     }
     if (pg_num_rows($sth) > 0) {
 
   if (isset($_POST["status"]) && isset($_POST["fields"])) {
     $msg = update_db();
+    $_SESSION['redirect'] = true;
+    header('Location: status.php');
+    exit;
+  } elseif ($_SESSION['redirect']) {
+    $month = $_SESSION['save']["month"];
+    $cust = $_SESSION['save']["customer"];
+    $status = $_SESSION['save']["status"];
+    $_SESSION['redirect'] = false;
   } else {
-    if (isset($_GET['month']))
+    if (isset($_GET['month'])) {
       $month = $_GET['month'];
-    else
+      $_SESSION['save']['month'] = $month;
+      unset($_SESSION['save']['customer']);
+      unset($_SESSION['save']['status']);
+    } else
       if (isset($_POST["filter"])) {
         $month = $_POST["month"];
         $cust = $_POST["customer"];
        $status = $_POST["status"];
-      } else
+       $_SESSION['save']['month'] = $month;
+       $_SESSION['save']['customer'] = $cust;
+       $_SESSION['save']['status'] = $status;
+      } else {
         $month = date('Y-m');
+       $_SESSION['save']['month'] = $month;
+       unset($_SESSION['save']['customer']);
+       unset($_SESSION['save']['status']);
+      }
   }
 ?>
 
+<script src="<root_prefix>basics.js"></script>
+<script type="text/javascript">
+var color_checked = '#c4ffc3';
+function format_int(value, width)
+{
+  var s = value.toString();
+
+  while (s.length < width)
+    s = '0' + s;
+
+  return s;
+}
+
+function timestr(duration)
+{
+    return format_int(Math.floor(duration / 60), 1) + ':'
+       + format_int(duration - (Math.floor(duration / 60) * 60), 2);
+}
+
+function strtime(time)
+{
+    var a = time.split(':');
+    return parseInt(a[0],10) * 60 + parseInt(a[1],10);
+}
+
+function check(id, value)
+{
+  var form = document.forms[id];
+  var sum = document.getElementById('sum_'+id.toString()); 
+  var newval = 0;
+
+  for (i=0; i< form.elements.length; i++) {
+      if (form.elements[i].name.substr(0,4) == 'oid_') {
+         form.elements[i].checked = value;
+         if (value) {
+             var ta = form.elements[i].parentNode.nextSibling.innerHTML.split(':');
+             newval = newval + parseInt(ta[0],10) * 60 + parseInt(ta[1],10);
+             form.elements[i].parentNode.parentNode.style.backgroundColor = color_checked;
+         } else
+             form.elements[i].parentNode.parentNode.style.backgroundColor = '';
+      }
+  }
+
+  sum.innerHTML = timestr(newval);
+}
+
+function plant(form)
+{
+  document.write('<div class="jscode">');
+  document.write('<a href="javascript:check('+form+',true)">Check all</a>');
+  document.write("&nbsp;/&nbsp;");
+  document.write('<a href="javascript:check('+form+',false)">Uncheck all</a>');
+  document.write("&nbsp;");
+  document.write('<span id="sum_'+form+'" class="sum">0:00</span>');
+  document.write("&nbsp;");
+  document.write('</div>');
+}
+
+function add_sum(form, checkbox)
+{
+    var sum = document.getElementById('sum_'+form.toString()); 
+    var time = strtime(checkbox.parentNode.nextSibling.innerHTML);
+    var newval;
+
+    if (checkbox.checked) {
+       newval = strtime(sum.innerHTML) + time;
+       checkbox.parentNode.parentNode.style.backgroundColor = color_checked;
+    } else {
+       newval = strtime(sum.innerHTML) - time;
+       checkbox.parentNode.parentNode.style.backgroundColor = '';
+    }
+    sum.innerHTML = timestr(newval);
+}
+
+var task_parent = null;
+var task_title = '';
+var task_oid = 0;
+function edit_task(obj)
+{
+    if (task_oid) {
+       if (task_oid != obj.parentNode.children[0].children[0].value)
+           edit_task_save();
+    }
+
+    if (!task_oid) {
+       task_parent = obj;
+       task_title = obj.innerHTML;
+       task_oid = obj.parentNode.children[0].children[0].value;
+
+       var input = document.createElement('input');
+       input.value = obj.innerHTML
+       input.style.fontSize = '100%';
+       input.style.width = '100%';
+       input.style.background = 'yellow';
+
+       obj.innerHTML = '';
+       obj.appendChild(input);
+       input.focus();
+    }
+}
+
+function edit_task_save()
+{
+    if (!task_parent) return;
+
+    if (task_parent.children[0].value != task_title)
+       ajax_request('save','oid='+task_oid+'&task='+encodeURIComponent(task_parent.children[0].value));
+
+    task_parent.innerHTML = task_parent.children[0].value;
+    task_parent = null;
+    task_title = '';
+    task_oid = 0;
+}
+
+function edit_task_finish(obj)
+{
+    if (task_oid)
+       edit_task_save();
+}
+
+</script>
+
+<style type="text/css">
+div.jscode {
+  text-align: right;
+  margin-top: -13px;
+  font-size: 12px;
+}
+span.sum {
+  display: inline;
+  border: 1px solid #9b9b9b;
+  background: #d9e2ea;
+  width: 20px;
+  margin-left: 3px;
+}
+</style>
+
 <page func=InfoCon title="Stempeluhr">
 
 <?
   if (!is_array($months))
     $months = find_months();
 
-  printf('<option value=""%s>alle</option>', !strlen($_POST['month'])?' selected':'');
+  printf('<option value=""%s>alle</option>', !strlen($month)?' selected':'');
   foreach ($months as $m) {
-    printf('<option value="%s"%s>%s</option>', $m, $_POST['month']==$m?' selected':'', $m);
+    printf('<option value="%s"%s>%s</option>', $m, $month==$m?' selected':'', $m);
   }
 ?>
 </select>
   if (!is_array($customers))
     $customers = find_customers();
 
-  printf('<option value=""%s>alle</option>', !strlen($_POST['month'])?' selected':'');
+  printf('<option value=""%s>alle</option>', !strlen($cust)?' selected':'');
   foreach ($customers as $c) {
-    printf('<option value="%s"%s>%s</option>', $c, $_POST['customer']==$c?' selected':'', $c);
+    printf('<option value="%s"%s>%s</option>', $c, $cust==$c?' selected':'', $c);
   }
 ?>
 </select>
 </page>
 
 # Local variables:
-# mode: text
-# mode: auto-fill
+# mode: php
 # end: