Adjust text discovery after layout change
[infodrom.org/service.infodrom.org] / src / InfoCon / stempel / status.wml
index 9247bb2..72fc3da 100644 (file)
@@ -9,22 +9,6 @@
   session_name('STEMPEL');
   session_start();
 
-  function update_db()
-  {
-    global $dbh;
-
-    $count = 0;
-    for ($idx=0; $idx < $_POST["fields"]; $idx++) {
-      if (isset($_POST["oid_".$idx])) {
-        $query = sprintf('UPDATE stempel SET status=%d WHERE oid=%d',
-                $_POST["status"], $_POST["oid_".$idx]);
-       $count++;
-       $sth = pg_exec ($dbh, $query);
-      }
-    }
-    return sprintf("<br>%d records updated.", $count);
-  }
-
   $stati = false;
   function display_tables()
   {
@@ -33,6 +17,7 @@
     global $status;
     global $dbh;
     global $stati;
+    $wdays = array('So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa');
 
     $name = load_customers();
 
@@ -41,7 +26,7 @@
   <table class="smallfont border" id="table_%d" width="100%%" cellpadding=0 cellspacing=0>
   <thead>
   <tr class="head">
-    <th width=15%%>Datum</th>
+    <th width=15%% colspan="2">Datum</th>
     <th width=5%%>Dauer</th>
     <th width=5%%>St.</th>
     <th width=75%% align=left>Arbeitsbeschreibung</th>
                  '<input type="hidden" name="fields" value="%d">'.
                  '</form>';
 
-    $table_row = '<tr class="t%d" status="%d"><td>%s</td><td align="center" onclick="toggle_checkbox(%d,this)">%s</td>' .
+    $table_row = '<tr class="t%d" status="%d"><td>%s</td><td>%s</td><td align="center" onclick="toggle_checkbox(%d,this)">%s</td>' .
       '<td align="center" onclick="toggle_checkbox(%d,this)">%s</td><td><span class="edit" route="Stempel/EditTask" item_id="%d">%s</span></td></tr>';
     $table_sum = '</tbody><tfoot><tr class="t%d" onclick="edit_task_finish(this)">' .
-       '<td>&nbsp;</td><td align="center">%s</td><td>&nbsp;</td><td>Summe</td></tr></tfoot>';
+       '<td colspan="2">&nbsp;</td><td align="center">%s</td><td>&nbsp;</td><td>Summe</td></tr></tfoot>';
 
     $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 ";
     if (isset($month) && strlen($month))
       $sum += $row['time'];
       $d = explode(' ', $row['start']);
 
-      $check = sprintf('<input type="checkbox" class="checkbox" name="oid_%d" value="%d" onclick="add_sum(%d,this)">',
+      $check = sprintf('<input type="checkbox" class="checkbox" name="id_%d" value="%d" onclick="add_sum(%d,this)">',
                       $fieldnr++,
-                      $row['oid'],
+                      $row['id'],
                       $form);
-      $date = sprintf('<span onclick="toggle_checkbox(%d,this)">%s</span>', $form, $d[0]);
-      printf($table_row, $color, $row['status'], $check.$date, $form, min2hour($row['time']), $form, $row['kurz'],
+      $dt = new Datetime($d[0]);
+      $date = sprintf('<span onclick="toggle_checkbox(%d,this)">%s, %s</span>', $form, $wdays[$dt->format('w')], $d[0]);
+      printf($table_row, $color, $row['status'], $check, $date, $form, min2hour($row['time']), $form, $row['kurz'],
             $row['id'],
             htmlspecialchars($row['task'], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1'));
       $color = !$color;
@@ -240,7 +226,7 @@ function add_sum(form, checkbox)
     var hours = $('#time_'+form);
     var rate = $('#rate_'+form);
     var sum = $('#sum_'+form);
-    var time = strtime($(checkbox).parents('tr:first').find('td:nth-child(2)').text());
+    var time = strtime($(checkbox).parents('tr:first').find('td:nth-child(3)').text());
     var newval;
 
     if ($(checkbox).prop('checked')) {
@@ -254,6 +240,49 @@ function add_sum(form, checkbox)
     sum.html('&euro;' + ((newval/60)*rate.val()).toFixed(2));
 }
 
+var task_parent = null;
+var task_title = '';
+var task_id = 0;
+function edit_task(obj)
+{
+    if (task_id) {
+       if (task_id != obj.parentNode.children[0].children[0].value)
+           edit_task_save();
+    }
+
+    if (!task_id) {
+       task_parent = obj;
+       task_title = obj.innerHTML;
+       task_id = obj.parentNode.children[0].children[0].value;
+
+       var input = $('<input>');
+       input.val(obj.innerHTML.replace('&gt;', '>').replace('&lt;', '<').replace('&amp;', '&'));
+       input.css('fontSize', '100%').css('width', '100%').css('background', 'yellow');
+       obj.innerHTML = '';
+       $(obj).append(input);
+       input.focus();
+    }
+}
+
+function edit_task_save()
+{
+    if (!task_parent) return;
+
+    if (task_parent.children[0].value != task_title)
+       $.invoke('Stempel/Task', {id: task_id, content: task_parent.children[0].value});
+
+    task_parent.innerHTML = task_parent.children[0].value;
+    task_parent = null;
+    task_title = '';
+    task_id = 0;
+}
+
+function edit_task_finish(obj)
+{
+    if (task_id)
+       edit_task_save();
+}
+
 function toggle_checkbox(form, obj)
 {
     var row = $(obj).parents('tr:first');
@@ -267,12 +296,12 @@ function toggle_checkbox(form, obj)
 function filter_change(e)
 {
     var form = $(this).attr('id').split('_')[1];
-    var filter = $('input#filter_'+form).val();
+    var filter = $('input#filter_'+form).val().toLowerCase();
 
     var cnum = 0;
     $('table#table_'+form+' tbody tr').not('.deleted').each(function(i,e){
        if (filter.length) {
-           var td = $(this).find('td:nth-child(4)');
+           var td = $(this).find('td:nth-child(5)');
            if (td.text().toLowerCase().indexOf(filter) > -1) {
                $(this).removeClass('t0').removeClass('t1').addClass('t'+cnum).show();
                cnum = cnum ? 0 : 1;
@@ -311,7 +340,7 @@ function status_change(e)
            new_status = $(this).val();
     });
 
-    $.invoke('Sales/SetStatus', {status: new_status, ids: ids}, function(data){
+    $.invoke('Stempel/SetStatus', {status: new_status, ids: ids}, function(data){
        for (var i=0; i < ids.length; i++) {
            show_message('Positionen aktualisiert');
            var checkbox = form.find('input.checkbox[value="'+ids[i]+'"]');