Add more options to query form
authorJoey Schulze <joey@infodrom.org>
Mon, 23 Mar 2020 11:49:11 +0000 (12:49 +0100)
committerJoey Schulze <joey@infodrom.org>
Mon, 23 Mar 2020 11:49:11 +0000 (12:49 +0100)
src/InfoCon/stempel/status.wml

index 72fc3da..bc3bb98 100644 (file)
@@ -12,9 +12,6 @@
   $stati = false;
   function display_tables()
   {
-    global $month;
-    global $cust;
-    global $status;
     global $dbh;
     global $stati;
     $wdays = array('So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa');
        '<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))
-      $query .= "AND cast(start AS TEXT) LIKE '".$month."-%' ";
-    if (isset($cust) && strlen($cust))
-      $query .= "AND customer ='".$cust."' ";
-
-    if (isset($status) && strlen($status)) {
-      if ($status != 'all')
-        $query .= "AND status = $status ";
+    if (isset($_SESSION['save']['month']) && strlen($_SESSION['save']['month']))
+      $query .= "AND cast(start AS TEXT) LIKE '".$_SESSION['save']['month']."-%' ";
+    if (isset($_SESSION['save']['customer']) && strlen($_SESSION['save']['customer']))
+      $query .= "AND customer ='".$_SESSION['save']['customer']."' ";
+    if (isset($_SESSION['save']['keyword1']) && strlen($_SESSION['save']['keyword1']))
+      $query .= "AND task ILIKE '%".$_SESSION['save']['keyword1']."%' ";
+    if (isset($_SESSION['save']['keyword2']) && strlen($_SESSION['save']['keyword2']))
+      $query .= "AND task ILIKE '%".$_SESSION['save']['keyword2']."%' ";
+    if (isset($_SESSION['save']['time_from']) && strlen($_SESSION['save']['time_from']))
+      $query .= "AND start >= '".$_SESSION['save']['time_from']."' ";
+    if (isset($_SESSION['save']['time_to']) && strlen($_SESSION['save']['time_to']))
+      $query .= "AND stop <= '".$_SESSION['save']['time_to']."' ";
+
+    if (isset($_SESSION['save']['status']) && strlen($_SESSION['save']['status'])) {
+      if ($_SESSION['save']['status'] != 'all')
+        $query .= "AND status = ".$_SESSION['save']['status']." ";
     } else
       $query .= "AND status = 0 ";
     $query .= "ORDER BY customer,start";
     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'])) {
-      $month = $_GET['month'];
-      $_SESSION['save']['month'] = $month;
+      $_SESSION['save']['month'] = $_GET['month'];
       unset($_SESSION['save']['customer']);
       unset($_SESSION['save']['status']);
     } else
       if (isset($_POST["filter"])) {
-        $month = $_POST["month"];
-        $cust = $_POST["customer"];
-       $status = $_POST["status"];
-       $_SESSION['save']['month'] = $month;
-       $_SESSION['save']['customer'] = $cust;
-       $_SESSION['save']['status'] = $status;
+       $_SESSION['save']['month'] = $_POST['month'];
+       $_SESSION['save']['customer'] = $_POST['customer'];
+       $_SESSION['save']['status'] = $_POST['status'];
+       $_SESSION['save']['time_from'] = $_POST['time_from'];
+       $_SESSION['save']['time_to'] = $_POST['time_to'];
+       $_SESSION['save']['keyword1'] = $_POST['keyword1'];
+       $_SESSION['save']['keyword2'] = $_POST['keyword2'];
+       $_SESSION['redirect'] = true;
+       header('Location: status.php');
+       exit;
       } else {
-        $month = date('Y-m');
-       $_SESSION['save']['month'] = $month;
+       $_SESSION['save']['month'] = date('Y-m');
        unset($_SESSION['save']['customer']);
        unset($_SESSION['save']['status']);
       }
@@ -403,7 +407,8 @@ span.sum {
 <form action=status.php method=POST>
 <select name=month>
 <?
-  if (!is_array($months))
+  $month = isset($_SESSION['save']['month']) ? $_SESSION['save']['month'] : date('Y-m');
+  if (!isset($months) || !is_array($months))
     $months = find_months();
 
   printf('<option value=""%s>alle</option>', !strlen($month)?' selected':'');
@@ -415,7 +420,8 @@ span.sum {
 
 <select name=customer>
 <?
-  if (!is_array($customers))
+  $cust = isset($_SESSION['save']['customer']) ? $_SESSION['save']['customer'] : '';
+  if (!isset($customers) || !is_array($customers))
     $customers = find_customers();
 
   printf('<option value=""%s>alle</option>', !strlen($cust)?' selected':'');
@@ -426,6 +432,7 @@ span.sum {
 </select>
 
 <?
+  $status = isset($_SESSION['save']['status']) ? $_SESSION['save']['status'] : 0;
   if (!is_array($stati))
     $stati = find_status();
 
@@ -436,6 +443,15 @@ span.sum {
 
 <input type="hidden" name="filter" value="form">
 <input class="button" type="submit" value="Display">
+
+     <br><br>
+     <input type="date" name="time_from" id="time_from" value="<?php echo isset($_SESSION['save']['time_from'])?$_SESSION['save']['time_from']:''?>">
+     &ndash;
+     <input type="date" name="time_to" id="time_to" value="<?php echo isset($_SESSION['save']['time_to'])?$_SESSION['save']['time_to']:''?>">
+
+         &nbsp;&nbsp;Keywords:
+     <input type="text" name="keyword1" id="keyword1" value="<?php echo isset($_SESSION['save']['keyword1'])?$_SESSION['save']['keyword1']:''?>">
+     <input type="text" name="keyword2" id="keyword2" value="<?php echo isset($_SESSION['save']['keyword2'])?$_SESSION['save']['keyword2']:''?>">
 </form>
 
 <? } ?>