Alter anbaugraet according to the selected geraet
[misc/kostenrechnung] / masks / arbeitsberichte.php
index 5b8c593..78798ce 100644 (file)
@@ -19,6 +19,24 @@ function select_group(obj)
 
   get_info('kostenstellen', {gebiet: obj.options[obj.selectedIndex].value}, select_gebiet_callback);
 }
+
+function select_geraet_callback(data)
+{
+    var obj = document.getElementById('edit_anbaugeraet');
+    if (!obj) return;
+
+    obj.options.length = 0;
+
+    for (var i=0; i < data.info.length; i++)
+      obj.options[i] = new Option(data.info[i].anbaugeraet,data.info[i].id,false,false);
+}
+
+function select_geraet(obj)
+{
+  setvar(obj,'geraet',false,false);
+
+  get_info('anbaugeraete', {geraet: obj.options[obj.selectedIndex].value}, select_geraet_callback);
+}
 EOC;
 
 function first_gebiet()
@@ -36,6 +54,7 @@ function first_gebiet()
 }
 
 if (empty($_SESSION['arbeitsberichte.gebiet'])) $_SESSION['arbeitsberichte.gebiet'] = first_gebiet();
+if (empty($_SESSION['arbeitsberichte.geraet'])) $_SESSION['arbeitsberichte.geraet'] = 0;
 
 $mask = array(
              'table' => 'einsatz',
@@ -51,6 +70,7 @@ $mask = array(
              'where' => "arbeitsarten.arbeitsart <> 'Urlaub' AND arbeitsarten.arbeitsart <> 'Krank' AND arbeitsarten.arbeitsart <> 'Sonstige Fehltage'",
              'variables' => array(
                                   'gebiet' => array(),
+                                  'geraet' => array(),
                                   ),
              'list' => array(
                              'id' => array(
@@ -143,11 +163,16 @@ $mask = array(
                                            'name' => 'Gerät',
                                            'type' => 'select',
                                            'options' => "SELECT id,geraet AS text FROM gerate ORDER BY text",
+                                           'selected' => $_SESSION['arbeitsberichte.geraet'],
+                                           'onchange' => 'select_geraet(this)',
                                            ),
                              'anbaugeraet' => array(
                                            'name' => 'Anbaugerät',
                                            'type' => 'select',
-                                           'options' => "SELECT id,anbaugeraet AS text FROM anbaugeraete ORDER BY text",
+                                           'options' => "SELECT anbaugeraete.id,anbaugeraet AS text FROM anbaugeraete " . 
+                                                        "JOIN gerate ON anbaugeraete.geraetetyp = gerate.geraetetyp " .
+                                                        "WHERE gerate.id = " . intval($_SESSION['arbeitsberichte.geraet']) . " " .
+                                                        "ORDER BY text",
                                            ),
                              'arbeiten' => array(
                                            'name' => 'Arbeitsart',
@@ -182,6 +207,11 @@ $mask = array(
                              'kostenstellen' => array(
                                            'sql' => 'SELECT id,kostenstelle FROM kostenstellen WHERE gebiet = {gebiet}',
                                            ),
+                             'anbaugeraete' => array(
+                                           'sql' => 'SELECT anbaugeraete.id,anbaugeraet FROM anbaugeraete ' .
+                                                    'JOIN gerate ON anbaugeraete.geraetetyp = gerate.geraetetyp ' .
+                                                    'WHERE gerate.id = {geraet}',
+                                           ),
                                   ),
              );