From f62bc22ee5ea6975c531be2c5a7e6d403d202d09 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Tue, 20 Jul 2021 13:21:28 +0200
Subject: [PATCH 001/250] testing new test branch

---
 README.md | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/README.md b/README.md
index 3f2333b..c8475f3 100644
--- a/README.md
+++ b/README.md
@@ -3,3 +3,5 @@
 There should be a description here
 
 Additional line
+
+additional line 2

From eeb1c9d4ba46784c807aa1c96db292e1bef0ca56 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 29 Jul 2021 13:08:52 +0200
Subject: [PATCH 002/250] testing new search algorithm

---
 include/SearchPage.php | 71 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index e1a3f8e..b29372a 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -128,7 +128,19 @@ class SearchPage extends Page {
         return $translated;
     }
 
+    /*
+        Takes two arrays ($type, $terms)
+        Returns an array ($out) of products (from $type) based on matches with search query terms ($terms)
+
+    */
+
     private function search($type, $terms) {
+        /*
+        
+        ==================================================
+
+        ORIGINAL CODE BACKUP || FOR REFERENCE
+
         $items = get_items($type);
         $out = array();
         foreach($items as $item) {
@@ -138,6 +150,65 @@ class SearchPage extends Page {
             }
         }
         return $out;
+    
+        ==================================================
+
+        */
+
+        /*
+
+        Break down terms into mustIncludeArray (MUST be included),
+                              mustExcludeArray (CANT be included),
+                              canIncludeArray (can be included)
+
+        Then matches all items based on specific MUST/CANT/Can include logic and adds to $out[] if passing the logic checks 
+        
+        */
+
+        
+
+        $mustIncludeArray, $mustExcludeArray, $canIncludeArray = array();
+        
+        foreach(terms) as term{
+            if(term[$i][0] == "+"){
+                // adds to mustIncludeArray
+                $mustIncludeArray[] = array($term)
+            }
+            elseif(term[$i][0] == "!" || term[$i][0] == "-"){
+                // adds to mustExcludeArray
+                $mustExcludeArray[] = array($term)
+            }
+            else{
+                // adds to canIncludeArray
+                $canIncludeArray[] = array($term)
+            }
+        }
+        $items = get_items($type);
+        $out = array();
+        $result = False;
+        foreach($items as $item) {
+            if(($item->matches($mustExcludeArray) == False)){
+                if(($item->matches($canIncludeArray)) || (count($canIncludeArray == 0))){
+                    if(count($mustIncludeArray) > 0){
+                        foreach($mustIncludeArray as $mustIncludeArgument) {
+                            if($item->matches($mustIncludeArgument)){
+                                $result = True;
+                            }
+                            else{
+                                $result = False;
+                                break;
+                            }
+                        }
+                    }
+                    else{
+                        $result = True;
+                    }    
+                }
+            if($result) {
+                $out[] = array($item, $result);
+            }
+        }
+        return $out;
     }
     
     protected function render_body() {

From ca10f4ac8f1f3193f70566c797fe4ae4ad3629a7 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 29 Jul 2021 13:17:23 +0200
Subject: [PATCH 003/250] testing new search algorithm

---
 include/SearchPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index b29372a..7fa53a0 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -172,11 +172,11 @@ class SearchPage extends Page {
         foreach(terms) as term{
             if(term[$i][0] == "+"){
                 // adds to mustIncludeArray
-                $mustIncludeArray[] = array($term)
+                $mustIncludeArray[] = array(substr($term, 1))
             }
             elseif(term[$i][0] == "!" || term[$i][0] == "-"){
                 // adds to mustExcludeArray
-                $mustExcludeArray[] = array($term)
+                $mustExcludeArray[] = array(substr($term, 1))
             }
             else{
                 // adds to canIncludeArray

From d8d12bd9a7f521857b246781106609d3da563938 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 29 Jul 2021 13:23:25 +0200
Subject: [PATCH 004/250] testing new search algorithm

---
 include/SearchPage.php | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 7fa53a0..b0023b2 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -172,11 +172,13 @@ class SearchPage extends Page {
         foreach(terms) as term{
             if(term[$i][0] == "+"){
                 // adds to mustIncludeArray
-                $mustIncludeArray[] = array(substr($term, 1))
+                $mustIncludeArray[] = array(substr(term[$i], 1))
+                echo ("test print " + substr(term[$i], 1));
             }
             elseif(term[$i][0] == "!" || term[$i][0] == "-"){
                 // adds to mustExcludeArray
-                $mustExcludeArray[] = array(substr($term, 1))
+                $mustExcludeArray[] = array(substr(term[$i], 1))
+                echo ("test print " + substr(term[$i], 1));
             }
             else{
                 // adds to canIncludeArray

From ffeb67a93c2c53f8c69fda0e9a8b9fed1a7b14be Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 29 Jul 2021 13:26:43 +0200
Subject: [PATCH 005/250] testing new search algorithm

---
 include/SearchPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index b0023b2..dd4d27b 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -173,12 +173,12 @@ class SearchPage extends Page {
             if(term[$i][0] == "+"){
                 // adds to mustIncludeArray
                 $mustIncludeArray[] = array(substr(term[$i], 1))
-                echo ("test print " + substr(term[$i], 1));
+                echo "test print " substr(term[$i], 1);
             }
             elseif(term[$i][0] == "!" || term[$i][0] == "-"){
                 // adds to mustExcludeArray
                 $mustExcludeArray[] = array(substr(term[$i], 1))
-                echo ("test print " + substr(term[$i], 1));
+                echo "test print " substr(term[$i], 1);
             }
             else{
                 // adds to canIncludeArray

From dd2d7f3e2ad69fe8cb35710cb143fc87418f98d8 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 29 Jul 2021 13:28:42 +0200
Subject: [PATCH 006/250] testing new search algorithm

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index dd4d27b..bca8ebb 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -203,7 +203,7 @@ class SearchPage extends Page {
                         }
                     }
                     else{
-                        $result = True;
+                        //$result = True;
                     }    
                 }
             if($result) {

From ee849ee17668bbe2f882c42a7de99ce9aa516546 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 5 Aug 2021 14:19:11 +0200
Subject: [PATCH 007/250] fixed page breaking code

---
 include/SearchPage.php | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index bca8ebb..325af70 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -167,7 +167,9 @@ class SearchPage extends Page {
 
         
 
-        $mustIncludeArray, $mustExcludeArray, $canIncludeArray = array();
+        $mustIncludeArray = array(); 
+        $mustExcludeArray = array(); 
+        $canIncludeArray = array();
         
         foreach(terms) as term{
             if(term[$i][0] == "+"){
@@ -203,7 +205,7 @@ class SearchPage extends Page {
                         }
                     }
                     else{
-                        //$result = True;
+                        $result = True;
                     }    
                 }
             if($result) {

From a0128ce0293becd32c7e429471e00bb2de60ff5b Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 5 Aug 2021 14:24:08 +0200
Subject: [PATCH 008/250] fixed new pagebreaking code

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 325af70..dc708e6 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -171,7 +171,7 @@ class SearchPage extends Page {
         $mustExcludeArray = array(); 
         $canIncludeArray = array();
         
-        foreach(terms) as term{
+        foreach(terms as term) {
             if(term[$i][0] == "+"){
                 // adds to mustIncludeArray
                 $mustIncludeArray[] = array(substr(term[$i], 1))

From ced3fc736efe4b87d86ec7d7bf0e0343d95df6ba Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 5 Aug 2021 14:26:44 +0200
Subject: [PATCH 009/250] fixed pagebreaking code

---
 include/SearchPage.php | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index dc708e6..b8d38cf 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -171,16 +171,16 @@ class SearchPage extends Page {
         $mustExcludeArray = array(); 
         $canIncludeArray = array();
         
-        foreach(terms as term) {
-            if(term[$i][0] == "+"){
+        foreach($terms as $term) {
+            if($term[$i][0] == "+"){
                 // adds to mustIncludeArray
-                $mustIncludeArray[] = array(substr(term[$i], 1))
-                echo "test print " substr(term[$i], 1);
+                $mustIncludeArray[] = array(substr($term[$i], 1))
+                echo "test print " substr($term[$i], 1);
             }
-            elseif(term[$i][0] == "!" || term[$i][0] == "-"){
+            elseif($term[$i][0] == "!" || $term[$i][0] == "-"){
                 // adds to mustExcludeArray
-                $mustExcludeArray[] = array(substr(term[$i], 1))
-                echo "test print " substr(term[$i], 1);
+                $mustExcludeArray[] = array(substr($term[$i], 1))
+                echo "test print " substr($term[$i], 1);
             }
             else{
                 // adds to canIncludeArray

From d9ab281a02cefe9be86b865fb835d080a23228c4 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 5 Aug 2021 14:28:15 +0200
Subject: [PATCH 010/250] fixed pagebreaking code

---
 include/SearchPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index b8d38cf..9bff8c2 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -175,12 +175,12 @@ class SearchPage extends Page {
             if($term[$i][0] == "+"){
                 // adds to mustIncludeArray
                 $mustIncludeArray[] = array(substr($term[$i], 1))
-                echo "test print " substr($term[$i], 1);
+                //echo "test print " substr($term[$i], 1);
             }
             elseif($term[$i][0] == "!" || $term[$i][0] == "-"){
                 // adds to mustExcludeArray
                 $mustExcludeArray[] = array(substr($term[$i], 1))
-                echo "test print " substr($term[$i], 1);
+                //echo "test print " substr($term[$i], 1);
             }
             else{
                 // adds to canIncludeArray

From 60fe9255651b93c7d88849cdf736d7eaae726254 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 5 Aug 2021 14:34:04 +0200
Subject: [PATCH 011/250] fixed typo

---
 include/SearchPage.php | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 9bff8c2..9e3cfb4 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -172,17 +172,17 @@ class SearchPage extends Page {
         $canIncludeArray = array();
         
         foreach($terms as $term) {
-            if($term[$i][0] == "+"){
+            if($term[$i][0] == "+") {
                 // adds to mustIncludeArray
                 $mustIncludeArray[] = array(substr($term[$i], 1))
                 //echo "test print " substr($term[$i], 1);
             }
-            elseif($term[$i][0] == "!" || $term[$i][0] == "-"){
+            elseif($term[$i][0] == "!" || $term[$i][0] == "-") {
                 // adds to mustExcludeArray
                 $mustExcludeArray[] = array(substr($term[$i], 1))
                 //echo "test print " substr($term[$i], 1);
             }
-            else{
+            else {
                 // adds to canIncludeArray
                 $canIncludeArray[] = array($term)
             }
@@ -191,23 +191,24 @@ class SearchPage extends Page {
         $out = array();
         $result = False;
         foreach($items as $item) {
-            if(($item->matches($mustExcludeArray) == False)){
+            if(($item->matches($mustExcludeArray) == False)) {
                 if(($item->matches($canIncludeArray)) || (count($canIncludeArray == 0))){
-                    if(count($mustIncludeArray) > 0){
+                    if(count($mustIncludeArray) > 0) {
                         foreach($mustIncludeArray as $mustIncludeArgument) {
-                            if($item->matches($mustIncludeArgument)){
+                            if($item->matches($mustIncludeArgument)) {
                                 $result = True;
                             }
-                            else{
+                            else {
                                 $result = False;
                                 break;
                             }
                         }
                     }
-                    else{
+                    else {
                         $result = True;
                     }    
                 }
+            }
             if($result) {
                 $out[] = array($item, $result);
             }

From 25cbafb4754d65e4004462743c73de1046aa266a Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 5 Aug 2021 14:38:42 +0200
Subject: [PATCH 012/250] fixed typos

---
 include/SearchPage.php | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 9e3cfb4..45fbadc 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -130,7 +130,7 @@ class SearchPage extends Page {
 
     /*
         Takes two arrays ($type, $terms)
-        Returns an array ($out) of products (from $type) based on matches with search query terms ($terms)
+        Returns an array ($out) of products ($type) based on matches with search query terms ($terms)
 
     */
 
@@ -176,13 +176,11 @@ class SearchPage extends Page {
                 // adds to mustIncludeArray
                 $mustIncludeArray[] = array(substr($term[$i], 1))
                 //echo "test print " substr($term[$i], 1);
-            }
-            elseif($term[$i][0] == "!" || $term[$i][0] == "-") {
+            } elseif($term[$i][0] == "!" || $term[$i][0] == "-") {
                 // adds to mustExcludeArray
                 $mustExcludeArray[] = array(substr($term[$i], 1))
                 //echo "test print " substr($term[$i], 1);
-            }
-            else {
+            } else {
                 // adds to canIncludeArray
                 $canIncludeArray[] = array($term)
             }
@@ -197,14 +195,12 @@ class SearchPage extends Page {
                         foreach($mustIncludeArray as $mustIncludeArgument) {
                             if($item->matches($mustIncludeArgument)) {
                                 $result = True;
-                            }
-                            else {
+                            } else {
                                 $result = False;
                                 break;
                             }
                         }
-                    }
-                    else {
+                    } else {
                         $result = True;
                     }    
                 }

From ec1f9d13c08b401a2f37a7a193294bda5f54727c Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 5 Aug 2021 14:50:24 +0200
Subject: [PATCH 013/250] fixed code

---
 include/SearchPage.php | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 45fbadc..3919575 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -165,8 +165,6 @@ class SearchPage extends Page {
         
         */
 
-        
-
         $mustIncludeArray = array(); 
         $mustExcludeArray = array(); 
         $canIncludeArray = array();
@@ -176,13 +174,15 @@ class SearchPage extends Page {
                 // adds to mustIncludeArray
                 $mustIncludeArray[] = array(substr($term[$i], 1))
                 //echo "test print " substr($term[$i], 1);
-            } elseif($term[$i][0] == "!" || $term[$i][0] == "-") {
-                // adds to mustExcludeArray
-                $mustExcludeArray[] = array(substr($term[$i], 1))
-                //echo "test print " substr($term[$i], 1);
             } else {
-                // adds to canIncludeArray
-                $canIncludeArray[] = array($term)
+                if($term[$i][0] == "!" || $term[$i][0] == "-") {
+                    // adds to mustExcludeArray
+                    $mustExcludeArray[] = array(substr($term[$i], 1))
+                    //echo "test print " substr($term[$i], 1);
+                } else {
+                    // adds to canIncludeArray
+                    $canIncludeArray[] = array($term)
+                }
             }
         }
         $items = get_items($type);

From 5e5c7971dea5b28b3e230f94b7412320521ec045 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 5 Aug 2021 14:52:55 +0200
Subject: [PATCH 014/250] fixed typo

---
 include/SearchPage.php | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 3919575..a0682f1 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -172,17 +172,15 @@ class SearchPage extends Page {
         foreach($terms as $term) {
             if($term[$i][0] == "+") {
                 // adds to mustIncludeArray
-                $mustIncludeArray[] = array(substr($term[$i], 1))
+                $mustIncludeArray[] = array(substr($term[$i], 1));
+                //echo "test print " substr($term[$i], 1);
+            } elseif($term[$i][0] == "!" || $term[$i][0] == "-") {
+                // adds to mustExcludeArray
+                $mustExcludeArray[] = array(substr($term[$i], 1));
                 //echo "test print " substr($term[$i], 1);
             } else {
-                if($term[$i][0] == "!" || $term[$i][0] == "-") {
-                    // adds to mustExcludeArray
-                    $mustExcludeArray[] = array(substr($term[$i], 1))
-                    //echo "test print " substr($term[$i], 1);
-                } else {
-                    // adds to canIncludeArray
-                    $canIncludeArray[] = array($term)
-                }
+                // adds to canIncludeArray
+                $canIncludeArray[] = array($term);
             }
         }
         $items = get_items($type);

From ec86baae19f047b38517b28994845f9823929ae4 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 5 Aug 2021 16:23:34 +0200
Subject: [PATCH 015/250] changed search algoritm

---
 include/SearchPage.php | 49 +++++++++++++++++++++++++++++++++---------
 1 file changed, 39 insertions(+), 10 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index a0682f1..428452c 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -139,7 +139,7 @@ class SearchPage extends Page {
         
         ==================================================
 
-        ORIGINAL CODE BACKUP || FOR REFERENCE
+        ORIGINAL CODE || BACKUP || FOR REFERENCE
 
         $items = get_items($type);
         $out = array();
@@ -168,25 +168,26 @@ class SearchPage extends Page {
         $mustIncludeArray = array(); 
         $mustExcludeArray = array(); 
         $canIncludeArray = array();
-        
+        $items = get_items($type);
+        $out = array();
+        $resultIsFine = False;
+
         foreach($terms as $term) {
             if($term[$i][0] == "+") {
                 // adds to mustIncludeArray
                 $mustIncludeArray[] = array(substr($term[$i], 1));
-                //echo "test print " substr($term[$i], 1);
-            } elseif($term[$i][0] == "!" || $term[$i][0] == "-") {
+            } else if($term[$i][0] == "!" || $term[$i][0] == "-") {
                 // adds to mustExcludeArray
                 $mustExcludeArray[] = array(substr($term[$i], 1));
-                //echo "test print " substr($term[$i], 1);
             } else {
                 // adds to canIncludeArray
                 $canIncludeArray[] = array($term);
             }
         }
-        $items = get_items($type);
-        $out = array();
-        $result = False;
+
         foreach($items as $item) {
+            
+            /* version 1
             if(($item->matches($mustExcludeArray) == False)) {
                 if(($item->matches($canIncludeArray)) || (count($canIncludeArray == 0))){
                     if(count($mustIncludeArray) > 0) {
@@ -202,10 +203,38 @@ class SearchPage extends Page {
                         $result = True;
                     }    
                 }
+            } */
+
+            // version 2
+            $resultExclude = $item->matches($mustExcludeArray)
+            if ($resultExclude) {
+
+            } else {
+                $mustIncludeCheck = False;
+                foreach ($mustIncludeArray as $mustIncludeArgument) {
+                    $resultInclude = $item->matches($mustIncludeArgument)
+                    if ($resultInclude) {
+                        $mustIncludeCheck = True;
+                    } else {
+                        $mustIncludeCheck = False;
+                        break;
+                    }    
+                }
+                if ($mustIncludeCheck) {
+                    if (count($canIncludeArray) > 0) {
+                        $canIncludeResult = $item->matches($canIncludeArray)
+                        $out[] = array($item, $canIncludeResult);
+                    } else {
+                        $mustIncludeResult = $item->matches($mustIncludeArray)
+                        $out[] = array($item, $mustIncludeResult);
+                    }
+                }
             }
-            if($result) {
+
+
+        /*  if($result) {
                 $out[] = array($item, $result);
-            }
+            }   */
         }
         return $out;
     }

From b82c2f2b0a6e8dbf75da5b9c3a62fa1549fe9a06 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 5 Aug 2021 16:28:16 +0200
Subject: [PATCH 016/250] fixed typos

---
 include/SearchPage.php | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 428452c..a548861 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -207,13 +207,13 @@ class SearchPage extends Page {
 
             // version 2
             $resultExclude = $item->matches($mustExcludeArray)
-            if ($resultExclude) {
+            if($resultExclude) {
 
             } else {
                 $mustIncludeCheck = False;
-                foreach ($mustIncludeArray as $mustIncludeArgument) {
+                foreach($mustIncludeArray as $mustIncludeArgument) {
                     $resultInclude = $item->matches($mustIncludeArgument)
-                    if ($resultInclude) {
+                    if($resultInclude) {
                         $mustIncludeCheck = True;
                     } else {
                         $mustIncludeCheck = False;
@@ -221,7 +221,7 @@ class SearchPage extends Page {
                     }    
                 }
                 if ($mustIncludeCheck) {
-                    if (count($canIncludeArray) > 0) {
+                    if(count($canIncludeArray) > 0) {
                         $canIncludeResult = $item->matches($canIncludeArray)
                         $out[] = array($item, $canIncludeResult);
                     } else {

From 2b12968e43f418d12909268c4dc2484ce65436e0 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 5 Aug 2021 16:40:45 +0200
Subject: [PATCH 017/250] testing search engine changes

---
 include/SearchPage.php | 35 +++++++----------------------------
 1 file changed, 7 insertions(+), 28 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index a548861..4c54d2f 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -186,31 +186,13 @@ class SearchPage extends Page {
         }
 
         foreach($items as $item) {
-            
-            /* version 1
-            if(($item->matches($mustExcludeArray) == False)) {
-                if(($item->matches($canIncludeArray)) || (count($canIncludeArray == 0))){
-                    if(count($mustIncludeArray) > 0) {
-                        foreach($mustIncludeArray as $mustIncludeArgument) {
-                            if($item->matches($mustIncludeArgument)) {
-                                $result = True;
-                            } else {
-                                $result = False;
-                                break;
-                            }
-                        }
-                    } else {
-                        $result = True;
-                    }    
-                }
-            } */
-
-            // version 2
+            $mustExcludeCheck = True;
             $resultExclude = $item->matches($mustExcludeArray)
             if($resultExclude) {
-
-            } else {
-                $mustIncludeCheck = False;
+                $mustExcludeCheck = False;
+            }
+            $mustIncludeCheck = False;
+            if(count($mustIncludeArray) > 0) {
                 foreach($mustIncludeArray as $mustIncludeArgument) {
                     $resultInclude = $item->matches($mustIncludeArgument)
                     if($resultInclude) {
@@ -220,6 +202,8 @@ class SearchPage extends Page {
                         break;
                     }    
                 }
+            }
+            if ($mustExcludeCheck) {
                 if ($mustIncludeCheck) {
                     if(count($canIncludeArray) > 0) {
                         $canIncludeResult = $item->matches($canIncludeArray)
@@ -230,11 +214,6 @@ class SearchPage extends Page {
                     }
                 }
             }
-
-
-        /*  if($result) {
-                $out[] = array($item, $result);
-            }   */
         }
         return $out;
     }

From 38ce91e3327dabcdd0bcbf21678c5d571928e66a Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 5 Aug 2021 16:44:35 +0200
Subject: [PATCH 018/250] fixed typo

---
 include/SearchPage.php | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 4c54d2f..c094129 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -187,29 +187,28 @@ class SearchPage extends Page {
 
         foreach($items as $item) {
             $mustExcludeCheck = True;
-            $resultExclude = $item->matches($mustExcludeArray)
+            $resultExclude = $item->matches($mustExcludeArray);
             if($resultExclude) {
-                $mustExcludeCheck = False;
-            }
-            $mustIncludeCheck = False;
-            if(count($mustIncludeArray) > 0) {
-                foreach($mustIncludeArray as $mustIncludeArgument) {
-                    $resultInclude = $item->matches($mustIncludeArgument)
-                    if($resultInclude) {
-                        $mustIncludeCheck = True;
-                    } else {
-                        $mustIncludeCheck = False;
-                        break;
-                    }    
+
+            } else {
+                $mustIncludeCheck = False;
+                if(count($mustIncludeArray) > 0) {
+                    foreach($mustIncludeArray as $mustIncludeArgument) {
+                        $resultInclude = $item->matches($mustIncludeArgument);
+                        if($resultInclude) {
+                            $mustIncludeCheck = True;
+                        } else {
+                            $mustIncludeCheck = False;
+                            break;
+                        }    
+                    }
                 }
-            }
-            if ($mustExcludeCheck) {
                 if ($mustIncludeCheck) {
                     if(count($canIncludeArray) > 0) {
-                        $canIncludeResult = $item->matches($canIncludeArray)
+                        $canIncludeResult = $item->matches($canIncludeArray);
                         $out[] = array($item, $canIncludeResult);
                     } else {
-                        $mustIncludeResult = $item->matches($mustIncludeArray)
+                        $mustIncludeResult = $item->matches($mustIncludeArray);
                         $out[] = array($item, $mustIncludeResult);
                     }
                 }

From b99c55275bb6daf17d339edbf6c4a6d96c6d814b Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 10:51:57 +0200
Subject: [PATCH 019/250] changes to search function

---
 include/SearchPage.php | 171 ++++++++++++++++++++---------------------
 1 file changed, 82 insertions(+), 89 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index c094129..cdde84a 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -37,6 +37,88 @@ class SearchPage extends Page {
         return $out;
     }
 
+    private function search($type, $terms) {
+        /*
+        
+        ==================================================
+
+        ORIGINAL CODE || BACKUP || FOR REFERENCE
+
+        $items = get_items($type);
+        $out = array();
+        foreach($items as $item) {
+            $result = $item->matches($terms);
+            if($result) {
+                $out[] = array($item, $result);
+            }
+        }
+        return $out;
+    
+        ==================================================
+
+        */
+
+        $mustIncludeArray = array(); 
+        $mustExcludeArray = array(); 
+        $canIncludeArray = array();
+
+        foreach($terms as $term) {
+            switch ($term[$i][0]) {
+                case "+":
+                    $mustIncludeArray[] = array(substr($term[$i], 1));
+                case "!":
+                case "-":
+                    $mustExcludeArray[] = array(substr($term[$i], 1));
+                case "~":
+                    $canIncludeArray[] = array(substr($term[$i], 1));
+                default:
+                    $canIncludeArray[] = array($term);
+            }
+        }
+
+        var_dump($mustIncludeArray);
+        var_dump($mustExcludeArray);
+        var_dump($canIncludeArray);
+
+        $items = get_items($type);
+        $out = array();
+
+        /*
+        foreach($items as $item) {
+            $mustExcludeCheck = True;
+            $resultExclude = $item->matches($mustExcludeArray);
+            if($resultExclude) {
+
+                // if resultExclude is matching, do === nothing ===
+
+            } else {
+                $mustIncludeCheck = False;
+                if(count($mustIncludeArray) > 0) {
+                    foreach($mustIncludeArray as $mustIncludeArgument) {
+                        $resultInclude = $item->matches($mustIncludeArgument);
+                        if($resultInclude) {
+                            $mustIncludeCheck = True;
+                        } else {
+                            $mustIncludeCheck = False;
+                            break;
+                        }    
+                    }
+                }
+                if ($mustIncludeCheck) {
+                    if(count($canIncludeArray) > 0) {
+                        $canIncludeResult = $item->matches($canIncludeArray);
+                        $out[] = array($item, $canIncludeResult);
+                    } else {
+                        $mustIncludeResult = $item->matches($mustIncludeArray);
+                        $out[] = array($item, $mustIncludeResult);
+                    }
+                }
+            }
+        }*/
+
+        return $out;
+    }
+
     private function translate_terms($terms) {
         $matches = array();
         if(isset($terms['q']) && preg_match('/([^:]+):(.*)/',
@@ -127,95 +209,6 @@ class SearchPage extends Page {
         }
         return $translated;
     }
-
-    /*
-        Takes two arrays ($type, $terms)
-        Returns an array ($out) of products ($type) based on matches with search query terms ($terms)
-
-    */
-
-    private function search($type, $terms) {
-        /*
-        
-        ==================================================
-
-        ORIGINAL CODE || BACKUP || FOR REFERENCE
-
-        $items = get_items($type);
-        $out = array();
-        foreach($items as $item) {
-            $result = $item->matches($terms);
-            if($result) {
-                $out[] = array($item, $result);
-            }
-        }
-        return $out;
-    
-        ==================================================
-
-        */
-
-        /*
-
-        Break down terms into mustIncludeArray (MUST be included),
-                              mustExcludeArray (CANT be included),
-                              canIncludeArray (can be included)
-
-        Then matches all items based on specific MUST/CANT/Can include logic and adds to $out[] if passing the logic checks 
-        
-        */
-
-        $mustIncludeArray = array(); 
-        $mustExcludeArray = array(); 
-        $canIncludeArray = array();
-        $items = get_items($type);
-        $out = array();
-        $resultIsFine = False;
-
-        foreach($terms as $term) {
-            if($term[$i][0] == "+") {
-                // adds to mustIncludeArray
-                $mustIncludeArray[] = array(substr($term[$i], 1));
-            } else if($term[$i][0] == "!" || $term[$i][0] == "-") {
-                // adds to mustExcludeArray
-                $mustExcludeArray[] = array(substr($term[$i], 1));
-            } else {
-                // adds to canIncludeArray
-                $canIncludeArray[] = array($term);
-            }
-        }
-
-        foreach($items as $item) {
-            $mustExcludeCheck = True;
-            $resultExclude = $item->matches($mustExcludeArray);
-            if($resultExclude) {
-
-            } else {
-                $mustIncludeCheck = False;
-                if(count($mustIncludeArray) > 0) {
-                    foreach($mustIncludeArray as $mustIncludeArgument) {
-                        $resultInclude = $item->matches($mustIncludeArgument);
-                        if($resultInclude) {
-                            $mustIncludeCheck = True;
-                        } else {
-                            $mustIncludeCheck = False;
-                            break;
-                        }    
-                    }
-                }
-                if ($mustIncludeCheck) {
-                    if(count($canIncludeArray) > 0) {
-                        $canIncludeResult = $item->matches($canIncludeArray);
-                        $out[] = array($item, $canIncludeResult);
-                    } else {
-                        $mustIncludeResult = $item->matches($mustIncludeArray);
-                        $out[] = array($item, $mustIncludeResult);
-                    }
-                }
-            }
-        }
-        return $out;
-    }
     
     protected function render_body() {
         $hidden = 'hidden';

From 4b72d0214852193600d5442f82e1032052f11a53 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 10:57:15 +0200
Subject: [PATCH 020/250] changes to search function

---
 include/SearchPage.php | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index cdde84a..ba91dc4 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -76,9 +76,13 @@ class SearchPage extends Page {
             }
         }
 
-        var_dump($mustIncludeArray);
-        var_dump($mustExcludeArray);
-        var_dump($canIncludeArray);
+//        var_dump($mustIncludeArray);
+//        var_dump($mustExcludeArray);
+//        var_dump($canIncludeArray);
+
+        print_r($mustIncludeArray);
+        print_r($mustExcludeArray);
+        print_r($canIncludeArray);
 
         $items = get_items($type);
         $out = array();

From 70d7dd2a1cae6ce3f5ac811a3858403a0d8b74fc Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 10:59:42 +0200
Subject: [PATCH 021/250] search function changes

---
 include/SearchPage.php | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index ba91dc4..9ba57e1 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -80,9 +80,9 @@ class SearchPage extends Page {
 //        var_dump($mustExcludeArray);
 //        var_dump($canIncludeArray);
 
-        print_r($mustIncludeArray);
-        print_r($mustExcludeArray);
-        print_r($canIncludeArray);
+        print_r("mustIncliudeArray" . $mustIncludeArray . '<br>');
+        print_r("mustExcludeArray" . $mustExcludeArray . '<br>');
+        print_r("canIncludeArray" . $canIncludeArray . '<br>');
 
         $items = get_items($type);
         $out = array();

From fd41340006b2b9937dc1b9e1e245b851a4a665ba Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 11:04:05 +0200
Subject: [PATCH 022/250] search function changes

---
 include/SearchPage.php | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 9ba57e1..25f60ba 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -76,13 +76,18 @@ class SearchPage extends Page {
             }
         }
 
-//        var_dump($mustIncludeArray);
-//        var_dump($mustExcludeArray);
-//        var_dump($canIncludeArray);
-
-        print_r("mustIncliudeArray" . $mustIncludeArray . '<br>');
-        print_r("mustExcludeArray" . $mustExcludeArray . '<br>');
-        print_r("canIncludeArray" . $canIncludeArray . '<br>');
+//      var_dump($mustIncludeArray);
+//      var_dump($mustExcludeArray);
+//      var_dump($canIncludeArray);
+        print('mustIncliudeArray');
+        print_r($mustIncludeArray);
+        print('<br>');
+        print('mustExcludeArray');
+        print_r($mustExcludeArray);
+        print('<br>');
+        print('canIncludeArray');
+        print_r($canIncludeArray);
+        print('<br>');
 
         $items = get_items($type);
         $out = array();

From 9c6cf55b1b6226439de03ddf55434139628c2504 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 11:07:06 +0200
Subject: [PATCH 023/250] search function changes

---
 include/SearchPage.php | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 25f60ba..49d68fb 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -58,6 +58,10 @@ class SearchPage extends Page {
 
         */
 
+        print('terms ');
+        print_r($terms);
+        print('<br>');
+
         $mustIncludeArray = array(); 
         $mustExcludeArray = array(); 
         $canIncludeArray = array();
@@ -79,13 +83,13 @@ class SearchPage extends Page {
 //      var_dump($mustIncludeArray);
 //      var_dump($mustExcludeArray);
 //      var_dump($canIncludeArray);
-        print('mustIncliudeArray');
+        print('mustIncludeArray ');
         print_r($mustIncludeArray);
         print('<br>');
-        print('mustExcludeArray');
+        print('mustExcludeArray ');
         print_r($mustExcludeArray);
         print('<br>');
-        print('canIncludeArray');
+        print('canIncludeArray ');
         print_r($canIncludeArray);
         print('<br>');
 

From 0dc66fa498ab8a5dbe2757c3b18d311fcf8a9331 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 11:12:45 +0200
Subject: [PATCH 024/250] search function changes

---
 include/SearchPage.php | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 49d68fb..67ce41b 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -70,26 +70,30 @@ class SearchPage extends Page {
             switch ($term[$i][0]) {
                 case "+":
                     $mustIncludeArray[] = array(substr($term[$i], 1));
+                    break;
                 case "!":
                 case "-":
                     $mustExcludeArray[] = array(substr($term[$i], 1));
+                    break;
                 case "~":
                     $canIncludeArray[] = array(substr($term[$i], 1));
+                    break;
                 default:
                     $canIncludeArray[] = array($term);
+                    break;
             }
         }
 
 //      var_dump($mustIncludeArray);
 //      var_dump($mustExcludeArray);
 //      var_dump($canIncludeArray);
-        print('mustIncludeArray ');
+        print('mustIncludeArray: ');
         print_r($mustIncludeArray);
         print('<br>');
-        print('mustExcludeArray ');
+        print('mustExcludeArray: ');
         print_r($mustExcludeArray);
         print('<br>');
-        print('canIncludeArray ');
+        print('canIncludeArray: ');
         print_r($canIncludeArray);
         print('<br>');
 

From 15f9ccb234bb52cf7c16bc7f8a5fd49ccfc81825 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 11:16:42 +0200
Subject: [PATCH 025/250] testing search function changes

---
 include/SearchPage.php | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 67ce41b..8b38552 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -58,7 +58,7 @@ class SearchPage extends Page {
 
         */
 
-        print('terms ');
+        print('terms: ');
         print_r($terms);
         print('<br>');
 
@@ -67,6 +67,9 @@ class SearchPage extends Page {
         $canIncludeArray = array();
 
         foreach($terms as $term) {
+            print('term: ');
+            print_r($term);
+            print('<br>');
             switch ($term[$i][0]) {
                 case "+":
                     $mustIncludeArray[] = array(substr($term[$i], 1));

From b2bc7053b1028892a5af726da4cc0bf8205f01c2 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 13:20:31 +0200
Subject: [PATCH 026/250] testing search function

---
 include/SearchPage.php | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 8b38552..64c584f 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -70,6 +70,11 @@ class SearchPage extends Page {
             print('term: ');
             print_r($term);
             print('<br>');
+            print('term[$i][0]: ');
+            print_r($term[$i][0]);
+            print('<br>');
+            print_r(substr($term[$i], 1));
+            print('<br>');
             switch ($term[$i][0]) {
                 case "+":
                     $mustIncludeArray[] = array(substr($term[$i], 1));

From f139519a357e228eba3d72e6debbe266508c2904 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 14:01:03 +0200
Subject: [PATCH 027/250] testing search function

---
 include/SearchPage.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 64c584f..2581f20 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -71,8 +71,9 @@ class SearchPage extends Page {
             print_r($term);
             print('<br>');
             print('term[$i][0]: ');
-            print_r($term[$i][0]);
+            print_r($term[0]);
             print('<br>');
+            print('term substring: ');
             print_r(substr($term[$i], 1));
             print('<br>');
             switch ($term[$i][0]) {

From 26959d3097e7d0ba567c4afe5d6fcd422da6d81a Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 14:03:53 +0200
Subject: [PATCH 028/250] testing search function

---
 include/SearchPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 2581f20..f499a84 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -66,12 +66,12 @@ class SearchPage extends Page {
         $mustExcludeArray = array(); 
         $canIncludeArray = array();
 
-        foreach($terms as $term) {
+        foreach($terms as $term => $i) {
             print('term: ');
             print_r($term);
             print('<br>');
             print('term[$i][0]: ');
-            print_r($term[0]);
+            print_r($term[$i][0]);
             print('<br>');
             print('term substring: ');
             print_r(substr($term[$i], 1));

From 2c26a46c0b93ec9a8bbc5508d56543515341c657 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 14:06:04 +0200
Subject: [PATCH 029/250] testing search function

---
 include/SearchPage.php | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index f499a84..a988121 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -70,6 +70,9 @@ class SearchPage extends Page {
             print('term: ');
             print_r($term);
             print('<br>');
+            print('term[$i]: ');
+            print_r($term[$i]);
+            print('<br>');
             print('term[$i][0]: ');
             print_r($term[$i][0]);
             print('<br>');

From e7a7c89ef8e4477b692b30389543c080a626cdc9 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 14:12:02 +0200
Subject: [PATCH 030/250] testing search function

---
 include/SearchPage.php | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index a988121..ecab9a9 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -67,17 +67,17 @@ class SearchPage extends Page {
         $canIncludeArray = array();
 
         foreach($terms as $term => $i) {
-            print('term: ');
-            print_r($term);
+            print('terms: ');
+            print_r($terms);
             print('<br>');
-            print('term[$i]: ');
-            print_r($term[$i]);
+            print('terms[$i]: ');
+            print_r($terms[$i]);
             print('<br>');
-            print('term[$i][0]: ');
-            print_r($term[$i][0]);
+            print('terms[$i][0]: ');
+            print_r($terms[$i][0]);
             print('<br>');
-            print('term substring: ');
-            print_r(substr($term[$i], 1));
+            print('terms substring: ');
+            print_r(substr($terms[$i], 1));
             print('<br>');
             switch ($term[$i][0]) {
                 case "+":

From 4f2ddecefffaadf87ff70bf55eb4acb8068988a2 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 14:13:30 +0200
Subject: [PATCH 031/250] testing search function

---
 include/SearchPage.php | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index ecab9a9..a988121 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -67,17 +67,17 @@ class SearchPage extends Page {
         $canIncludeArray = array();
 
         foreach($terms as $term => $i) {
-            print('terms: ');
-            print_r($terms);
+            print('term: ');
+            print_r($term);
             print('<br>');
-            print('terms[$i]: ');
-            print_r($terms[$i]);
+            print('term[$i]: ');
+            print_r($term[$i]);
             print('<br>');
-            print('terms[$i][0]: ');
-            print_r($terms[$i][0]);
+            print('term[$i][0]: ');
+            print_r($term[$i][0]);
             print('<br>');
-            print('terms substring: ');
-            print_r(substr($terms[$i], 1));
+            print('term substring: ');
+            print_r(substr($term[$i], 1));
             print('<br>');
             switch ($term[$i][0]) {
                 case "+":

From e73a5790b92b0c48e940a81ab998b4ba5f641857 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 14:17:08 +0200
Subject: [PATCH 032/250] testing search function

---
 include/SearchPage.php | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index a988121..407177e 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -67,16 +67,22 @@ class SearchPage extends Page {
         $canIncludeArray = array();
 
         foreach($terms as $term => $i) {
-            print('term: ');
+            $res = preg_split("/^([+-]?)(.*)$/", $i, -1, PREG_SPLIT_DELIM_CAPTURE);
+            print('$res: ');
+            print_r($res);
+            print('<br>');
+
+
+            print('$term: ');
             print_r($term);
             print('<br>');
-            print('term[$i]: ');
+            print('$term[$i]: ');
             print_r($term[$i]);
             print('<br>');
-            print('term[$i][0]: ');
+            print('$term[$i][0]: ');
             print_r($term[$i][0]);
             print('<br>');
-            print('term substring: ');
+            print('$term substring: ');
             print_r(substr($term[$i], 1));
             print('<br>');
             switch ($term[$i][0]) {

From 741fc7fcf79c5b2609cf0289cf035091cbf48145 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 14:42:49 +0200
Subject: [PATCH 033/250] testing serach function

---
 include/SearchPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 407177e..a7debd9 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -67,9 +67,9 @@ class SearchPage extends Page {
         $canIncludeArray = array();
 
         foreach($terms as $term => $i) {
-            $res = preg_split("/^([+-]?)(.*)$/", $i, -1, PREG_SPLIT_DELIM_CAPTURE);
+            $res = preg_split("/^([+-]?)(.*)$/", $term, -1, PREG_SPLIT_DELIM_CAPTURE);
             print('$res: ');
-            print_r($res);
+            print_r($res[$i]);
             print('<br>');
 
 

From ad67b66427523bc73e7fc43a4827e871c12b950a Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 14:44:39 +0200
Subject: [PATCH 034/250] testing search function

---
 include/SearchPage.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index a7debd9..f5c6358 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -65,9 +65,10 @@ class SearchPage extends Page {
         $mustIncludeArray = array(); 
         $mustExcludeArray = array(); 
         $canIncludeArray = array();
+        $res = array();
 
         foreach($terms as $term => $i) {
-            $res = preg_split("/^([+-]?)(.*)$/", $term, -1, PREG_SPLIT_DELIM_CAPTURE);
+            $res = array(preg_split("/^([+-]?)(.*)$/", $term, -1, PREG_SPLIT_DELIM_CAPTURE));
             print('$res: ');
             print_r($res[$i]);
             print('<br>');

From dabc84a2e9da4d1be7923f92c2b5025f46b1b35d Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 14:45:34 +0200
Subject: [PATCH 035/250] testing search function

---
 include/SearchPage.php | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index f5c6358..407177e 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -65,12 +65,11 @@ class SearchPage extends Page {
         $mustIncludeArray = array(); 
         $mustExcludeArray = array(); 
         $canIncludeArray = array();
-        $res = array();
 
         foreach($terms as $term => $i) {
-            $res = array(preg_split("/^([+-]?)(.*)$/", $term, -1, PREG_SPLIT_DELIM_CAPTURE));
+            $res = preg_split("/^([+-]?)(.*)$/", $i, -1, PREG_SPLIT_DELIM_CAPTURE);
             print('$res: ');
-            print_r($res[$i]);
+            print_r($res);
             print('<br>');
 
 

From 80f1b6543c83b1ef0681fb6de61285ce4553ed90 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 15:56:50 +0200
Subject: [PATCH 036/250] testing search function

---
 include/SearchPage.php | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 407177e..97db2e5 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -67,12 +67,16 @@ class SearchPage extends Page {
         $canIncludeArray = array();
 
         foreach($terms as $term => $i) {
-            $res = preg_split("/^([+-]?)(.*)$/", $i, -1, PREG_SPLIT_DELIM_CAPTURE);
+            $res = preg_split("/^([+-!~]?)(.*)$/", $i, -1, PREG_SPLIT_DELIM_CAPTURE);
             print('$res: ');
             print_r($res);
             print('<br>');
-
-
+            print('$term: ');
+            print_r($res[$i]);
+            print('<br>');
+            print('$term: ');
+            print_r($res[$i][0]);
+            print('<br>');
             print('$term: ');
             print_r($term);
             print('<br>');

From ea4703d1abddd5c81897c62733a1273f62405fb1 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 15:58:36 +0200
Subject: [PATCH 037/250] testing search function

---
 include/SearchPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 97db2e5..76299f2 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -71,10 +71,10 @@ class SearchPage extends Page {
             print('$res: ');
             print_r($res);
             print('<br>');
-            print('$term: ');
+            print('$$res[$i]: ');
             print_r($res[$i]);
             print('<br>');
-            print('$term: ');
+            print('$res[$i][0]: ');
             print_r($res[$i][0]);
             print('<br>');
             print('$term: ');

From 18379cf59fbce6e7a835d3d6aa48c6bdfb4a0664 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 16:15:39 +0200
Subject: [PATCH 038/250] testing search

---
 include/SearchPage.php | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 76299f2..b0526ec 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -68,25 +68,25 @@ class SearchPage extends Page {
 
         foreach($terms as $term => $i) {
             $res = preg_split("/^([+-!~]?)(.*)$/", $i, -1, PREG_SPLIT_DELIM_CAPTURE);
-            print('$res: ');
+            print('DEBUG $res: ');
             print_r($res);
             print('<br>');
-            print('$$res[$i]: ');
+            print('DEBUG $res[$i]: ');
             print_r($res[$i]);
             print('<br>');
-            print('$res[$i][0]: ');
+            print('DEBUG $res[$i][0]: ');
             print_r($res[$i][0]);
             print('<br>');
-            print('$term: ');
+            print('DEBUG $term: ');
             print_r($term);
             print('<br>');
-            print('$term[$i]: ');
+            print('DEBUG $term[$i]: ');
             print_r($term[$i]);
             print('<br>');
-            print('$term[$i][0]: ');
+            print('DEBUG $term[$i][0]: ');
             print_r($term[$i][0]);
             print('<br>');
-            print('$term substring: ');
+            print('DEBUG $term substring: ');
             print_r(substr($term[$i], 1));
             print('<br>');
             switch ($term[$i][0]) {
@@ -109,13 +109,13 @@ class SearchPage extends Page {
 //      var_dump($mustIncludeArray);
 //      var_dump($mustExcludeArray);
 //      var_dump($canIncludeArray);
-        print('mustIncludeArray: ');
+        print('DEBUG mustIncludeArray: ');
         print_r($mustIncludeArray);
         print('<br>');
-        print('mustExcludeArray: ');
+        print('DEBUG mustExcludeArray: ');
         print_r($mustExcludeArray);
         print('<br>');
-        print('canIncludeArray: ');
+        print('DEBUG canIncludeArray: ');
         print_r($canIncludeArray);
         print('<br>');
 

From 69c854d0044178b310c68431f44f1dc5c8021792 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 16:18:18 +0200
Subject: [PATCH 039/250] testing search

---
 include/SearchPage.php | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index b0526ec..62ea7e5 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -58,9 +58,12 @@ class SearchPage extends Page {
 
         */
 
-        print('terms: ');
+        print('DEBUG terms: ');
         print_r($terms);
         print('<br>');
+        print('DEBUG terms[0]: ');
+        print_r($terms[0]);
+        print('<br>');
 
         $mustIncludeArray = array(); 
         $mustExcludeArray = array(); 

From 51d606a90bec23b1727a77711b14d8c9130cb898 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 16:24:58 +0200
Subject: [PATCH 040/250] search test

---
 include/SearchPage.php | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 62ea7e5..0ecdd33 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -57,7 +57,9 @@ class SearchPage extends Page {
         ==================================================
 
         */
-
+        print('DEBUG terms dump: ');
+        var_dump($terms)
+        print('<br>');
         print('DEBUG terms: ');
         print_r($terms);
         print('<br>');

From a17ff3aabab56870d5de674d87f585bfdc2f6e24 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 16:25:27 +0200
Subject: [PATCH 041/250] search testing

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 0ecdd33..29251c0 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -58,7 +58,7 @@ class SearchPage extends Page {
 
         */
         print('DEBUG terms dump: ');
-        var_dump($terms)
+        var_dump($terms);
         print('<br>');
         print('DEBUG terms: ');
         print_r($terms);

From bdd8a581e2cbd18521ebc5b208724bb45fc4b3ac Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 16:43:49 +0200
Subject: [PATCH 042/250] search test

---
 include/SearchPage.php | 58 ++++++++++++++----------------------------
 1 file changed, 19 insertions(+), 39 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 29251c0..d1b2059 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -57,7 +57,7 @@ class SearchPage extends Page {
         ==================================================
 
         */
-        print('DEBUG terms dump: ');
+        /*print('DEBUG terms dump: ');
         var_dump($terms);
         print('<br>');
         print('DEBUG terms: ');
@@ -65,49 +65,29 @@ class SearchPage extends Page {
         print('<br>');
         print('DEBUG terms[0]: ');
         print_r($terms[0]);
-        print('<br>');
+        print('<br>');*/
 
         $mustIncludeArray = array(); 
         $mustExcludeArray = array(); 
         $canIncludeArray = array();
 
-        foreach($terms as $term => $i) {
-            $res = preg_split("/^([+-!~]?)(.*)$/", $i, -1, PREG_SPLIT_DELIM_CAPTURE);
-            print('DEBUG $res: ');
-            print_r($res);
-            print('<br>');
-            print('DEBUG $res[$i]: ');
-            print_r($res[$i]);
-            print('<br>');
-            print('DEBUG $res[$i][0]: ');
-            print_r($res[$i][0]);
-            print('<br>');
-            print('DEBUG $term: ');
-            print_r($term);
-            print('<br>');
-            print('DEBUG $term[$i]: ');
-            print_r($term[$i]);
-            print('<br>');
-            print('DEBUG $term[$i][0]: ');
-            print_r($term[$i][0]);
-            print('<br>');
-            print('DEBUG $term substring: ');
-            print_r(substr($term[$i], 1));
-            print('<br>');
-            switch ($term[$i][0]) {
-                case "+":
-                    $mustIncludeArray[] = array(substr($term[$i], 1));
-                    break;
-                case "!":
-                case "-":
-                    $mustExcludeArray[] = array(substr($term[$i], 1));
-                    break;
-                case "~":
-                    $canIncludeArray[] = array(substr($term[$i], 1));
-                    break;
-                default:
-                    $canIncludeArray[] = array($term);
-                    break;
+        foreach($terms as $key => $inputs) {
+            foreach($inputs as $value => $i) {
+                    switch ($value[$i][0]) {
+                        case "+":
+                            $mustIncludeArray[] = array(substr($value[$i], 1));
+                            break;
+                        case "!":
+                        case "-":
+                            $mustExcludeArray[] = array(substr($value[$i], 1));
+                            break;
+                        case "~":
+                            $canIncludeArray[] = array(substr($value[$i], 1));
+                            break;
+                        default:
+                            $canIncludeArray[] = array($value);
+                            break;
+                } 
             }
         }
 

From c61a72bed398453e7447c1ac760e2988752a198f Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 16:48:24 +0200
Subject: [PATCH 043/250] testing search

---
 include/SearchPage.php | 47 +++++++++++++++++++-----------------------
 1 file changed, 21 insertions(+), 26 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index d1b2059..3607dc0 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -57,37 +57,32 @@ class SearchPage extends Page {
         ==================================================
 
         */
-        /*print('DEBUG terms dump: ');
-        var_dump($terms);
-        print('<br>');
-        print('DEBUG terms: ');
-        print_r($terms);
-        print('<br>');
-        print('DEBUG terms[0]: ');
-        print_r($terms[0]);
-        print('<br>');*/
 
         $mustIncludeArray = array(); 
         $mustExcludeArray = array(); 
         $canIncludeArray = array();
 
-        foreach($terms as $key => $inputs) {
-            foreach($inputs as $value => $i) {
-                    switch ($value[$i][0]) {
-                        case "+":
-                            $mustIncludeArray[] = array(substr($value[$i], 1));
-                            break;
-                        case "!":
-                        case "-":
-                            $mustExcludeArray[] = array(substr($value[$i], 1));
-                            break;
-                        case "~":
-                            $canIncludeArray[] = array(substr($value[$i], 1));
-                            break;
-                        default:
-                            $canIncludeArray[] = array($value);
-                            break;
-                } 
+        foreach($terms as $key => $values) {
+            foreach($values as $value => $i) {
+                switch ($value[$i][0]) {
+                    case "+":
+                         $mustIncludeArray[] = array(substr($value[$i], 1));
+                        break;
+                    case "!":
+                    case "-":
+                        $mustExcludeArray[] = array(substr($value[$i], 1));
+                        break;
+                    case "~":
+                        $canIncludeArray[] = array(substr($value[$i], 1));
+                        break;
+                    default:
+                        $canIncludeArray[] = array($value);
+                        break;
+                }
+
+                print('DEBUG $value: ');
+                print_r($value);
+                print('<br>'); 
             }
         }
 

From dce7d5e62ea7da88f5ff67de68b0cc82bd5d49e5 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 16:50:20 +0200
Subject: [PATCH 044/250] testing search

---
 include/SearchPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 3607dc0..c3dd737 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -80,8 +80,8 @@ class SearchPage extends Page {
                         break;
                 }
 
-                print('DEBUG $value: ');
-                print_r($value);
+                print('DEBUG $value dump: ');
+                var_dump($value);
                 print('<br>'); 
             }
         }

From c572a307cdeadd5d5e5c32eff4b69da104c9f7a4 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 16:51:52 +0200
Subject: [PATCH 045/250] testing search

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index c3dd737..b632f82 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -81,7 +81,7 @@ class SearchPage extends Page {
                 }
 
                 print('DEBUG $value dump: ');
-                var_dump($value);
+                var_dump($key[$value[$i]]);
                 print('<br>'); 
             }
         }

From be64c098dc59c712d1208ced83588acd74b99481 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 16:53:01 +0200
Subject: [PATCH 046/250] testing search

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index b632f82..f67a6db 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -81,7 +81,7 @@ class SearchPage extends Page {
                 }
 
                 print('DEBUG $value dump: ');
-                var_dump($key[$value[$i]]);
+                var_dump($key[$value][$i]);
                 print('<br>'); 
             }
         }

From ad369f3b7fef8dbfb0645a5e839e74d30f637982 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 16:55:02 +0200
Subject: [PATCH 047/250] testing search

---
 include/SearchPage.php | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index f67a6db..4c07cf3 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -81,14 +81,11 @@ class SearchPage extends Page {
                 }
 
                 print('DEBUG $value dump: ');
-                var_dump($key[$value][$i]);
+                var_dump($key[$i][$value]);
                 print('<br>'); 
             }
         }
 
-//      var_dump($mustIncludeArray);
-//      var_dump($mustExcludeArray);
-//      var_dump($canIncludeArray);
         print('DEBUG mustIncludeArray: ');
         print_r($mustIncludeArray);
         print('<br>');
@@ -99,10 +96,11 @@ class SearchPage extends Page {
         print_r($canIncludeArray);
         print('<br>');
 
-        $items = get_items($type);
-        $out = array();
 
         /*
+        $items = get_items($type);
+        $out = array();
+        
         foreach($items as $item) {
             $mustExcludeCheck = True;
             $resultExclude = $item->matches($mustExcludeArray);

From e48b8c6ec2b1b1885340365bb5b5279a2bcfc6d7 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 16:59:22 +0200
Subject: [PATCH 048/250] testing search

---
 include/SearchPage.php | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 4c07cf3..4a75632 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -58,12 +58,16 @@ class SearchPage extends Page {
 
         */
 
+        print('DEBUG $terms dump: ');
+        var_dump($terms);
+        print('<br>'); 
+
         $mustIncludeArray = array(); 
         $mustExcludeArray = array(); 
         $canIncludeArray = array();
 
         foreach($terms as $key => $values) {
-            foreach($values as $value => $i) {
+            foreach($key[$values] as $value => $i) {
                 switch ($value[$i][0]) {
                     case "+":
                          $mustIncludeArray[] = array(substr($value[$i], 1));
@@ -79,11 +83,13 @@ class SearchPage extends Page {
                         $canIncludeArray[] = array($value);
                         break;
                 }
-
-                print('DEBUG $value dump: ');
-                var_dump($key[$i][$value]);
+                print('DEBUG $key[values] dump: ');
+                var_dump($key[$values]);
                 print('<br>'); 
             }
+            print('DEBUG $key dump: ');
+            var_dump($key);
+            print('<br>'); 
         }
 
         print('DEBUG mustIncludeArray: ');

From 93d14e9e98a659ebb43f7716303598cbd573694b Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 17:01:24 +0200
Subject: [PATCH 049/250] testing search

---
 include/SearchPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 4a75632..bd49c5e 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -67,7 +67,7 @@ class SearchPage extends Page {
         $canIncludeArray = array();
 
         foreach($terms as $key => $values) {
-            foreach($key[$values] as $value => $i) {
+            foreach($values as $value => $i) {
                 switch ($value[$i][0]) {
                     case "+":
                          $mustIncludeArray[] = array(substr($value[$i], 1));
@@ -84,7 +84,7 @@ class SearchPage extends Page {
                         break;
                 }
                 print('DEBUG $key[values] dump: ');
-                var_dump($key[$values]);
+                var_dump($values);
                 print('<br>'); 
             }
             print('DEBUG $key dump: ');

From 8f7e4ad15fe98fafe9b26999644c9575a7f487b0 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 17:02:38 +0200
Subject: [PATCH 050/250] testing search

---
 include/SearchPage.php | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index bd49c5e..9f8f142 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -68,19 +68,19 @@ class SearchPage extends Page {
 
         foreach($terms as $key => $values) {
             foreach($values as $value => $i) {
-                switch ($value[$i][0]) {
+                switch ($values[$i][0]) {
                     case "+":
-                         $mustIncludeArray[] = array(substr($value[$i], 1));
+                         $mustIncludeArray[] = array(substr($values[$i], 1));
                         break;
                     case "!":
                     case "-":
-                        $mustExcludeArray[] = array(substr($value[$i], 1));
+                        $mustExcludeArray[] = array(substr($values[$i], 1));
                         break;
                     case "~":
-                        $canIncludeArray[] = array(substr($value[$i], 1));
+                        $canIncludeArray[] = array(substr($values[$i], 1));
                         break;
                     default:
-                        $canIncludeArray[] = array($value);
+                        $canIncludeArray[] = array($values);
                         break;
                 }
                 print('DEBUG $key[values] dump: ');

From 6caa2df236ea56f9e6029d17b4427a3831d9c65a Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 17:04:01 +0200
Subject: [PATCH 051/250] testing search

---
 include/SearchPage.php | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 9f8f142..5adc053 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -70,21 +70,21 @@ class SearchPage extends Page {
             foreach($values as $value => $i) {
                 switch ($values[$i][0]) {
                     case "+":
-                         $mustIncludeArray[] = array(substr($values[$i], 1));
+                         $mustIncludeArray[] = array(substr($values[$value], 1));
                         break;
                     case "!":
                     case "-":
-                        $mustExcludeArray[] = array(substr($values[$i], 1));
+                        $mustExcludeArray[] = array(substr($values[$value], 1));
                         break;
                     case "~":
-                        $canIncludeArray[] = array(substr($values[$i], 1));
+                        $canIncludeArray[] = array(substr($values[$value], 1));
                         break;
                     default:
                         $canIncludeArray[] = array($values);
                         break;
                 }
                 print('DEBUG $key[values] dump: ');
-                var_dump($values);
+                var_dump($values[$value]);
                 print('<br>'); 
             }
             print('DEBUG $key dump: ');

From c9da0908056020ddd1d32a16a6752269d591723d Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 17:05:43 +0200
Subject: [PATCH 052/250] testing search

---
 include/SearchPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 5adc053..a78f5f5 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -68,7 +68,7 @@ class SearchPage extends Page {
 
         foreach($terms as $key => $values) {
             foreach($values as $value => $i) {
-                switch ($values[$i][0]) {
+                switch ($values[$value][0]) {
                     case "+":
                          $mustIncludeArray[] = array(substr($values[$value], 1));
                         break;
@@ -83,7 +83,7 @@ class SearchPage extends Page {
                         $canIncludeArray[] = array($values);
                         break;
                 }
-                print('DEBUG $key[values] dump: ');
+                print('DEBUG $values[$value] dump: ');
                 var_dump($values[$value]);
                 print('<br>'); 
             }

From ddb6de136e350a3fb452985c24d71719ae5f5534 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 12 Aug 2021 17:07:33 +0200
Subject: [PATCH 053/250] testing search

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index a78f5f5..c973eba 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -80,7 +80,7 @@ class SearchPage extends Page {
                         $canIncludeArray[] = array(substr($values[$value], 1));
                         break;
                     default:
-                        $canIncludeArray[] = array($values);
+                        $canIncludeArray[] = array($values[$value]);
                         break;
                 }
                 print('DEBUG $values[$value] dump: ');

From b73524023d4a9ecca62e3b971ed9c6629a2986a5 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 09:43:54 +0200
Subject: [PATCH 054/250] testing search function

---
 include/SearchPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index c973eba..09aad93 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -103,7 +103,7 @@ class SearchPage extends Page {
         print('<br>');
 
 
-        /*
+        
         $items = get_items($type);
         $out = array();
         
@@ -137,7 +137,7 @@ class SearchPage extends Page {
                     }
                 }
             }
-        }*/
+        }
 
         return $out;
     }

From 6097c772eefa71368de5a4c3efa27a8b2dcad656 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 09:48:26 +0200
Subject: [PATCH 055/250] testing search function

---
 include/SearchPage.php | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 09aad93..a6c9683 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -102,8 +102,6 @@ class SearchPage extends Page {
         print_r($canIncludeArray);
         print('<br>');
 
-
-        
         $items = get_items($type);
         $out = array();
         
@@ -115,6 +113,9 @@ class SearchPage extends Page {
                 // if resultExclude is matching, do === nothing ===
 
             } else {
+                $canIncludeResult = $item->matches($canIncludeArray);
+                $out[] = array($item, $canIncludeResult);
+                /*
                 $mustIncludeCheck = False;
                 if(count($mustIncludeArray) > 0) {
                     foreach($mustIncludeArray as $mustIncludeArgument) {
@@ -135,7 +136,7 @@ class SearchPage extends Page {
                         $mustIncludeResult = $item->matches($mustIncludeArray);
                         $out[] = array($item, $mustIncludeResult);
                     }
-                }
+                }*/
             }
         }
 

From 3f3e8104b6f8e152969f4ea2d6f3f1d4953af06f Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 10:54:26 +0200
Subject: [PATCH 056/250] testing search function

---
 include/SearchPage.php | 91 ++++++++++++++++++++----------------------
 1 file changed, 43 insertions(+), 48 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index a6c9683..f2fa8f9 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -58,9 +58,9 @@ class SearchPage extends Page {
 
         */
 
-        print('DEBUG $terms dump: ');
-        var_dump($terms);
-        print('<br>'); 
+        // print('DEBUG $terms dump: ');
+        // var_dump($terms);
+        // print('<br>'); 
 
         $mustIncludeArray = array(); 
         $mustExcludeArray = array(); 
@@ -83,63 +83,58 @@ class SearchPage extends Page {
                         $canIncludeArray[] = array($values[$value]);
                         break;
                 }
-                print('DEBUG $values[$value] dump: ');
-                var_dump($values[$value]);
-                print('<br>'); 
+                // print('DEBUG $values[$value] dump: ');
+                // var_dump($values[$value]);
+                // print('<br>');
             }
-            print('DEBUG $key dump: ');
-            var_dump($key);
-            print('<br>'); 
+            // print('DEBUG $key dump: ');
+            // var_dump($key);
+            // print('<br>'); 
         }
 
-        print('DEBUG mustIncludeArray: ');
-        print_r($mustIncludeArray);
-        print('<br>');
-        print('DEBUG mustExcludeArray: ');
-        print_r($mustExcludeArray);
-        print('<br>');
-        print('DEBUG canIncludeArray: ');
-        print_r($canIncludeArray);
-        print('<br>');
+        // print('DEBUG mustIncludeArray: ');
+        // print_r($mustIncludeArray);
+        // print('<br>');
+        // print('DEBUG mustExcludeArray: ');
+        // print_r($mustExcludeArray);
+        // print('<br>');
+        // print('DEBUG canIncludeArray: ');
+        // print_r($canIncludeArray);
+        // print('<br>');
 
         $items = get_items($type);
+        // $cannotMatchResults = $item->matches($mustExcludeArray);
+        // $mustMatchResults = $item->matches($mustIncludeArray);
+        // $canMatchResults = $item->matches($canIncludeArray);
+        $sanitizedDB = array();
         $out = array();
+        $mustMatchCheck = False;
         
         foreach($items as $item) {
-            $mustExcludeCheck = True;
-            $resultExclude = $item->matches($mustExcludeArray);
-            if($resultExclude) {
-
-                // if resultExclude is matching, do === nothing ===
-
-            } else {
-                $canIncludeResult = $item->matches($canIncludeArray);
-                $out[] = array($item, $canIncludeResult);
-                /*
-                $mustIncludeCheck = False;
-                if(count($mustIncludeArray) > 0) {
-                    foreach($mustIncludeArray as $mustIncludeArgument) {
-                        $resultInclude = $item->matches($mustIncludeArgument);
-                        if($resultInclude) {
-                            $mustIncludeCheck = True;
-                        } else {
-                            $mustIncludeCheck = False;
-                            break;
-                        }    
-                    }
+            foreach ($mustMatchResults as $matchResult) {
+                if($item->matches($mustIncludeArray)) {
+                    $mustMatchCheck = True;
+                } else {
+                    $mustMatchCheck = False;
+                    break;
                 }
-                if ($mustIncludeCheck) {
-                    if(count($canIncludeArray) > 0) {
-                        $canIncludeResult = $item->matches($canIncludeArray);
-                        $out[] = array($item, $canIncludeResult);
-                    } else {
-                        $mustIncludeResult = $item->matches($mustIncludeArray);
-                        $out[] = array($item, $mustIncludeResult);
-                    }
-                }*/
+            }
+            if ($mustMatchCheck) {
+                $sanitizedDB[] = array($item)
             }
         }
+        foreach ($sanitizedDB as $sanitizedItem) {
+                if ($sanitizedItem->matches($mustExcludeArray)) {
 
+                    // === IF TRUE DO NOTHING ===
+
+                } else {
+                    $result = $sanitizedItem->matches($canIncludeArray);
+                    if($result) {
+                        $out[] = array($sanitizedItem, $result);
+                    }
+                }
+            }
         return $out;
     }
 

From bd8c9c87115acd4a45ced0892352c92456afaf49 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 10:56:10 +0200
Subject: [PATCH 057/250] testing search function

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index f2fa8f9..a95587c 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -120,7 +120,7 @@ class SearchPage extends Page {
                 }
             }
             if ($mustMatchCheck) {
-                $sanitizedDB[] = array($item)
+                $sanitizedDB[] = array($item);
             }
         }
         foreach ($sanitizedDB as $sanitizedItem) {

From df0456959efcf4184f68bf742c74ec99a5a61fa3 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 10:58:21 +0200
Subject: [PATCH 058/250] testing search function

---
 include/SearchPage.php | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index a95587c..725b82f 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -103,9 +103,6 @@ class SearchPage extends Page {
         // print('<br>');
 
         $items = get_items($type);
-        // $cannotMatchResults = $item->matches($mustExcludeArray);
-        // $mustMatchResults = $item->matches($mustIncludeArray);
-        // $canMatchResults = $item->matches($canIncludeArray);
         $sanitizedDB = array();
         $out = array();
         $mustMatchCheck = False;
@@ -114,13 +111,16 @@ class SearchPage extends Page {
             foreach ($mustMatchResults as $matchResult) {
                 if($item->matches($mustIncludeArray)) {
                     $mustMatchCheck = True;
+                    print('DEBUG $mustMatchCheck: TRUE');
                 } else {
                     $mustMatchCheck = False;
+                    print('DEBUG $mustMatchCheck: FALSE');
                     break;
                 }
             }
             if ($mustMatchCheck) {
                 $sanitizedDB[] = array($item);
+                print('DEBUG $sanitizedDB: ADDED ITEM');
             }
         }
         foreach ($sanitizedDB as $sanitizedItem) {

From e992b2ec65ef8a4ca1f14f47f7e98bb0ce0d7f60 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:00:17 +0200
Subject: [PATCH 059/250] testing search function

---
 include/SearchPage.php | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 725b82f..5543d5e 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -107,9 +107,10 @@ class SearchPage extends Page {
         $out = array();
         $mustMatchCheck = False;
         
+
         foreach($items as $item) {
-            foreach ($mustMatchResults as $matchResult) {
-                if($item->matches($mustIncludeArray)) {
+            foreach ($mustIncludeArray as $mustIncludeItem) {
+                if($item->matches($mustIncludeItem)) {
                     $mustMatchCheck = True;
                     print('DEBUG $mustMatchCheck: TRUE');
                 } else {

From fc93016b3d680f037a07576a37be7b2e5d81eb79 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:03:07 +0200
Subject: [PATCH 060/250] testing search function

---
 include/SearchPage.php | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 5543d5e..9c47bd0 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -92,9 +92,9 @@ class SearchPage extends Page {
             // print('<br>'); 
         }
 
-        // print('DEBUG mustIncludeArray: ');
-        // print_r($mustIncludeArray);
-        // print('<br>');
+        print('DEBUG mustIncludeArray: ');
+        print_r($mustIncludeArray);
+        print('<br>');
         // print('DEBUG mustExcludeArray: ');
         // print_r($mustExcludeArray);
         // print('<br>');
@@ -112,16 +112,16 @@ class SearchPage extends Page {
             foreach ($mustIncludeArray as $mustIncludeItem) {
                 if($item->matches($mustIncludeItem)) {
                     $mustMatchCheck = True;
-                    print('DEBUG $mustMatchCheck: TRUE');
+                    print('DEBUG $mustMatchCheck: TRUE <br>');
                 } else {
                     $mustMatchCheck = False;
-                    print('DEBUG $mustMatchCheck: FALSE');
+                    print('DEBUG $mustMatchCheck: FALSE <br>');
                     break;
                 }
             }
             if ($mustMatchCheck) {
                 $sanitizedDB[] = array($item);
-                print('DEBUG $sanitizedDB: ADDED ITEM');
+                print('DEBUG $sanitizedDB: ADDED ITEM <br>');
             }
         }
         foreach ($sanitizedDB as $sanitizedItem) {

From 0083976c14f8becb4a240dd47ed639edf1c3bd96 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:07:35 +0200
Subject: [PATCH 061/250] testing search function

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 9c47bd0..da16b92 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -110,7 +110,7 @@ class SearchPage extends Page {
 
         foreach($items as $item) {
             foreach ($mustIncludeArray as $mustIncludeItem) {
-                if($item->matches($mustIncludeItem)) {
+                if($item->matches($mustIncludeArray)) {
                     $mustMatchCheck = True;
                     print('DEBUG $mustMatchCheck: TRUE <br>');
                 } else {

From ddd57a856e0513d549a1d0c9a28d836a3d9b5cfc Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:10:02 +0200
Subject: [PATCH 062/250] testing search function

---
 include/SearchPage.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index da16b92..413a9d8 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -110,7 +110,8 @@ class SearchPage extends Page {
 
         foreach($items as $item) {
             foreach ($mustIncludeArray as $mustIncludeItem) {
-                if($item->matches($mustIncludeArray)) {
+                // $item->matches($mustIncludeItem)
+                if(in_array($mustIncludeItem, $item, $strict = True)) {
                     $mustMatchCheck = True;
                     print('DEBUG $mustMatchCheck: TRUE <br>');
                 } else {

From c4c6c13d33133b462e604b08347e1afc35965b42 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:10:36 +0200
Subject: [PATCH 063/250] testing search

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 413a9d8..7dc1104 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -111,7 +111,7 @@ class SearchPage extends Page {
         foreach($items as $item) {
             foreach ($mustIncludeArray as $mustIncludeItem) {
                 // $item->matches($mustIncludeItem)
-                if(in_array($mustIncludeItem, $item, $strict = True)) {
+                if(in_array($mustIncludeItem, $item,)) {
                     $mustMatchCheck = True;
                     print('DEBUG $mustMatchCheck: TRUE <br>');
                 } else {

From c440ee493ce4903cf212376581f0503f1c8fb6c5 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:13:51 +0200
Subject: [PATCH 064/250] testing search function

---
 include/SearchPage.php | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 7dc1104..c3f0bb6 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -110,8 +110,14 @@ class SearchPage extends Page {
 
         foreach($items as $item) {
             foreach ($mustIncludeArray as $mustIncludeItem) {
+                print('DEBUG $item: ');
+                print_r($item);
+                print('<br>');
+                print('DEBUG $mustMustIncludeItem: ');
+                print_r($mustIncludeItem);
+                print('<br>');
                 // $item->matches($mustIncludeItem)
-                if(in_array($mustIncludeItem, $item,)) {
+                if(in_array($mustIncludeItem, $item, True)) {
                     $mustMatchCheck = True;
                     print('DEBUG $mustMatchCheck: TRUE <br>');
                 } else {

From 1460608b5e473d7ef4973432155bf0fcfcbd2a9f Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:23:10 +0200
Subject: [PATCH 065/250] testing search function

---
 include/SearchPage.php | 40 +++++++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 19 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index c3f0bb6..6891339 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -95,29 +95,28 @@ class SearchPage extends Page {
         print('DEBUG mustIncludeArray: ');
         print_r($mustIncludeArray);
         print('<br>');
+
         // print('DEBUG mustExcludeArray: ');
         // print_r($mustExcludeArray);
         // print('<br>');
+
         // print('DEBUG canIncludeArray: ');
         // print_r($canIncludeArray);
         // print('<br>');
 
         $items = get_items($type);
         $sanitizedDB = array();
-        $out = array();
-        $mustMatchCheck = False;
-        
-
         foreach($items as $item) {
+
+            $mustMatchCheck = False;
             foreach ($mustIncludeArray as $mustIncludeItem) {
-                print('DEBUG $item: ');
-                print_r($item);
-                print('<br>');
+
                 print('DEBUG $mustMustIncludeItem: ');
                 print_r($mustIncludeItem);
                 print('<br>');
-                // $item->matches($mustIncludeItem)
-                if(in_array($mustIncludeItem, $item, True)) {
+
+                $res = $item->matches($mustIncludeItem)
+                if(in_array($mustIncludeItem, $res, True)) {
                     $mustMatchCheck = True;
                     print('DEBUG $mustMatchCheck: TRUE <br>');
                 } else {
@@ -126,23 +125,26 @@ class SearchPage extends Page {
                     break;
                 }
             }
+            
             if ($mustMatchCheck) {
                 $sanitizedDB[] = array($item);
                 print('DEBUG $sanitizedDB: ADDED ITEM <br>');
             }
         }
-        foreach ($sanitizedDB as $sanitizedItem) {
-                if ($sanitizedItem->matches($mustExcludeArray)) {
 
-                    // === IF TRUE DO NOTHING ===
+        // $out = array();
+        // foreach ($sanitizedDB as $sanitizedItem) {
+        //         if ($sanitizedItem->matches($mustExcludeArray)) {
 
-                } else {
-                    $result = $sanitizedItem->matches($canIncludeArray);
-                    if($result) {
-                        $out[] = array($sanitizedItem, $result);
-                    }
-                }
-            }
+        //             // === IF TRUE DO NOTHING ===
+
+        //         } else {
+        //             $result = $sanitizedItem->matches($canIncludeArray);
+        //             if($result) {
+        //                 $out[] = array($sanitizedItem, $result);
+        //             }
+        //         }
+        //     }
         return $out;
     }
 

From 032c94b6a2540dd22d98bb900656f3a0c1ce8db1 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:23:40 +0200
Subject: [PATCH 066/250] testing search function

---
 include/SearchPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 6891339..b2aeee6 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -115,7 +115,7 @@ class SearchPage extends Page {
                 print_r($mustIncludeItem);
                 print('<br>');
 
-                $res = $item->matches($mustIncludeItem)
+                $res = $item->matches($mustIncludeItem);
                 if(in_array($mustIncludeItem, $res, True)) {
                     $mustMatchCheck = True;
                     print('DEBUG $mustMatchCheck: TRUE <br>');
@@ -125,7 +125,7 @@ class SearchPage extends Page {
                     break;
                 }
             }
-            
+
             if ($mustMatchCheck) {
                 $sanitizedDB[] = array($item);
                 print('DEBUG $sanitizedDB: ADDED ITEM <br>');

From 14b0ecfa466499182712d03ad86c974f16eb9d19 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:24:41 +0200
Subject: [PATCH 067/250] testing search function

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index b2aeee6..bc15a15 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -145,7 +145,7 @@ class SearchPage extends Page {
         //             }
         //         }
         //     }
-        return $out;
+        // return $out;
     }
 
     private function translate_terms($terms) {

From 074c44200688bbb8b199244a12c51e52faf18650 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:26:17 +0200
Subject: [PATCH 068/250] testing search function

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index bc15a15..1265d85 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -116,7 +116,7 @@ class SearchPage extends Page {
                 print('<br>');
 
                 $res = $item->matches($mustIncludeItem);
-                if(in_array($mustIncludeItem, $res, True)) {
+                if($res) {
                     $mustMatchCheck = True;
                     print('DEBUG $mustMatchCheck: TRUE <br>');
                 } else {

From 666c30e110b4b72e2e0bdf75479abbd5df287f7d Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:27:21 +0200
Subject: [PATCH 069/250] testing search

---
 include/SearchPage.php | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 1265d85..9e2e42e 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -116,6 +116,11 @@ class SearchPage extends Page {
                 print('<br>');
 
                 $res = $item->matches($mustIncludeItem);
+
+                print('DEBUG $res: ');
+                print_r($res);
+                print('<br>');
+
                 if($res) {
                     $mustMatchCheck = True;
                     print('DEBUG $mustMatchCheck: TRUE <br>');

From 6ad717a3f04c38484e86d2a0080f5a8ecb9a0380 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:28:52 +0200
Subject: [PATCH 070/250] testing search

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 9e2e42e..831c220 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -118,7 +118,7 @@ class SearchPage extends Page {
                 $res = $item->matches($mustIncludeItem);
 
                 print('DEBUG $res: ');
-                print_r($res);
+                var_dump($res);
                 print('<br>');
 
                 if($res) {

From 7db758ca7808cd3def4d4d0932490163136fd9c5 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:37:56 +0200
Subject: [PATCH 071/250] testing search function

---
 include/SearchPage.php | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 831c220..d4fafa8 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -109,19 +109,19 @@ class SearchPage extends Page {
         foreach($items as $item) {
 
             $mustMatchCheck = False;
-            foreach ($mustIncludeArray as $mustIncludeItem) {
+            foreach($mustIncludeArray as $mustIncludeItem => $i) {
 
                 print('DEBUG $mustMustIncludeItem: ');
                 print_r($mustIncludeItem);
                 print('<br>');
 
-                $res = $item->matches($mustIncludeItem);
+                $matchResult = $item->matches($mustIncludeItem);
 
                 print('DEBUG $res: ');
-                var_dump($res);
+                var_dump($matchResult);
                 print('<br>');
 
-                if($res) {
+                if($matchResult) {
                     $mustMatchCheck = True;
                     print('DEBUG $mustMatchCheck: TRUE <br>');
                 } else {

From 52f4470777c3b3a38e8b60fa3ff10116bb7db0fb Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:39:25 +0200
Subject: [PATCH 072/250] testing search function

---
 include/SearchPage.php | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index d4fafa8..5eb3baa 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -112,12 +112,12 @@ class SearchPage extends Page {
             foreach($mustIncludeArray as $mustIncludeItem => $i) {
 
                 print('DEBUG $mustMustIncludeItem: ');
-                print_r($mustIncludeItem);
+                print_r($mustIncludeItem[$i]);
                 print('<br>');
 
-                $matchResult = $item->matches($mustIncludeItem);
+                $matchResult = $item->matches($mustIncludeItem[$i]);
 
-                print('DEBUG $res: ');
+                print('DEBUG $matchResult: ');
                 var_dump($matchResult);
                 print('<br>');
 

From 39872ce0963c2e31f5677c168db612b783fa6e0c Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:41:30 +0200
Subject: [PATCH 073/250] testing search function

---
 include/SearchPage.php | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 5eb3baa..485ff84 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -113,9 +113,15 @@ class SearchPage extends Page {
 
                 print('DEBUG $mustMustIncludeItem: ');
                 print_r($mustIncludeItem[$i]);
+                var_dump($mustIncludeItem);
                 print('<br>');
 
-                $matchResult = $item->matches($mustIncludeItem[$i]);
+                print('DEBUG $i: ');
+                print_r($i);
+                var_dump($i);
+                print('<br>');
+
+                $matchResult = $item->matches($mustIncludeItem);
 
                 print('DEBUG $matchResult: ');
                 var_dump($matchResult);

From b52e5a787a917975d9094fea771d035dc64036f0 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:44:53 +0200
Subject: [PATCH 074/250] testing search function

---
 include/SearchPage.php | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 485ff84..baf4c61 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -132,8 +132,7 @@ class SearchPage extends Page {
                     print('DEBUG $mustMatchCheck: TRUE <br>');
                 } else {
                     $mustMatchCheck = False;
-                    print('DEBUG $mustMatchCheck: FALSE <br>');
-                    break;
+                    // print('DEBUG $mustMatchCheck: FALSE <br>');
                 }
             }
 

From b435f1052a56e924e15a95975d917aa9c4f8d86a Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:45:46 +0200
Subject: [PATCH 075/250] testing search function

---
 include/SearchPage.php | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index baf4c61..8958499 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -109,18 +109,13 @@ class SearchPage extends Page {
         foreach($items as $item) {
 
             $mustMatchCheck = False;
-            foreach($mustIncludeArray as $mustIncludeItem => $i) {
+            foreach($mustIncludeArray as $mustIncludeItem) {
 
                 print('DEBUG $mustMustIncludeItem: ');
                 print_r($mustIncludeItem[$i]);
                 var_dump($mustIncludeItem);
                 print('<br>');
 
-                print('DEBUG $i: ');
-                print_r($i);
-                var_dump($i);
-                print('<br>');
-
                 $matchResult = $item->matches($mustIncludeItem);
 
                 print('DEBUG $matchResult: ');

From 7535602f851ea38eaa13cf5f26dd04d5858409bb Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:48:59 +0200
Subject: [PATCH 076/250] testing search function

---
 include/SearchPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 8958499..7d5b32f 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -116,8 +116,8 @@ class SearchPage extends Page {
                 var_dump($mustIncludeItem);
                 print('<br>');
 
-                $matchResult = $item->matches($mustIncludeItem);
-
+                // $matchResult = $item->matches($mustIncludeItem);
+                $matchResult = in_array($mustIncludeItem, $item)
                 print('DEBUG $matchResult: ');
                 var_dump($matchResult);
                 print('<br>');

From c36ef5d800d4dada3dc4cbc0c431921cc6e5aff4 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:49:58 +0200
Subject: [PATCH 077/250] testing search function

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 7d5b32f..2d0706e 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -117,7 +117,7 @@ class SearchPage extends Page {
                 print('<br>');
 
                 // $matchResult = $item->matches($mustIncludeItem);
-                $matchResult = in_array($mustIncludeItem, $item)
+                $matchResult = in_array($mustIncludeItem, $item);
                 print('DEBUG $matchResult: ');
                 var_dump($matchResult);
                 print('<br>');

From 5642edb80fc6f19eb92d30362ad52741ea48a4ad Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:55:47 +0200
Subject: [PATCH 078/250] testing search function

---
 include/SearchPage.php | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 2d0706e..0839b5f 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -111,10 +111,9 @@ class SearchPage extends Page {
             $mustMatchCheck = False;
             foreach($mustIncludeArray as $mustIncludeItem) {
 
-                print('DEBUG $mustMustIncludeItem: ');
-                print_r($mustIncludeItem[$i]);
-                var_dump($mustIncludeItem);
-                print('<br>');
+                // print('DEBUG $mustMustIncludeItem: ');
+                // var_dump($mustIncludeItem);
+                // print('<br>');
 
                 // $matchResult = $item->matches($mustIncludeItem);
                 $matchResult = in_array($mustIncludeItem, $item);
@@ -137,20 +136,20 @@ class SearchPage extends Page {
             }
         }
 
-        // $out = array();
-        // foreach ($sanitizedDB as $sanitizedItem) {
-        //         if ($sanitizedItem->matches($mustExcludeArray)) {
+        $out = array();
+        foreach ($sanitizedDB as $sanitizedItem) {
+                if ($sanitizedItem->matches($mustExcludeArray)) {
 
-        //             // === IF TRUE DO NOTHING ===
+                    // === IF TRUE DO NOTHING ===
 
-        //         } else {
-        //             $result = $sanitizedItem->matches($canIncludeArray);
-        //             if($result) {
-        //                 $out[] = array($sanitizedItem, $result);
-        //             }
-        //         }
-        //     }
-        // return $out;
+                } else {
+                    // $result = $sanitizedItem->matches($canIncludeArray);
+                    // if($result) {
+                    //     $out[] = array($sanitizedItem, $result);
+                    // }
+                }
+            }
+        return $out;
     }
 
     private function translate_terms($terms) {

From cf827fd88c3febbf144163b37123a831f4f5f1a5 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 11:58:59 +0200
Subject: [PATCH 079/250] testing search function

---
 include/SearchPage.php | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 0839b5f..2affc55 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -111,9 +111,9 @@ class SearchPage extends Page {
             $mustMatchCheck = False;
             foreach($mustIncludeArray as $mustIncludeItem) {
 
-                // print('DEBUG $mustMustIncludeItem: ');
-                // var_dump($mustIncludeItem);
-                // print('<br>');
+                print('DEBUG $mustMustIncludeItem: ');
+                var_dump($mustIncludeItem);
+                print('<br>');
 
                 // $matchResult = $item->matches($mustIncludeItem);
                 $matchResult = in_array($mustIncludeItem, $item);

From 432c6b69699c19c427bee17402fdc63934e14a81 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 12:03:40 +0200
Subject: [PATCH 080/250] testing search

---
 include/SearchPage.php | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 2affc55..9b03241 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -111,6 +111,10 @@ class SearchPage extends Page {
             $mustMatchCheck = False;
             foreach($mustIncludeArray as $mustIncludeItem) {
 
+                print('DEBUG $item: ');
+                var_dump($item);
+                print('<br>');
+
                 print('DEBUG $mustMustIncludeItem: ');
                 var_dump($mustIncludeItem);
                 print('<br>');

From 897b8b0788e9efc9fa41d563dff6bea6afffadec Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 13 Aug 2021 12:06:57 +0200
Subject: [PATCH 081/250] testing search function

---
 include/SearchPage.php | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 9b03241..98ce4c0 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -111,9 +111,9 @@ class SearchPage extends Page {
             $mustMatchCheck = False;
             foreach($mustIncludeArray as $mustIncludeItem) {
 
-                print('DEBUG $item: ');
-                var_dump($item);
-                print('<br>');
+                // print('DEBUG $item: ');
+                // var_dump($item);
+                // print('<br>');
 
                 print('DEBUG $mustMustIncludeItem: ');
                 var_dump($mustIncludeItem);

From 6946b75dc0dd61b6ec6d5946d0ebfa32763e6df1 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 16 Aug 2021 19:25:02 +0200
Subject: [PATCH 082/250] testing search function

---
 include/SearchPage.php | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 98ce4c0..e7c4ba4 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -108,6 +108,19 @@ class SearchPage extends Page {
         $sanitizedDB = array();
         foreach($items as $item) {
 
+            print('DEBUG $item: ');
+            var_dump($item);
+            print('<br>');
+            print('DEBUG $item[0]: ');
+            var_dump($item[0]);
+            print('<br>');
+            print('DEBUG $item[0][0]: ');
+            var_dump($item[0][0]);
+            print('<br>');
+            print('DEBUG $item[0[0]]: ');
+            var_dump($item[0[0]]);
+            print('<br>');
+
             $mustMatchCheck = False;
             foreach($mustIncludeArray as $mustIncludeItem) {
 
@@ -115,15 +128,15 @@ class SearchPage extends Page {
                 // var_dump($item);
                 // print('<br>');
 
-                print('DEBUG $mustMustIncludeItem: ');
-                var_dump($mustIncludeItem);
-                print('<br>');
+                // print('DEBUG $mustMustIncludeItem: ');
+                // var_dump($mustIncludeItem);
+                // print('<br>');
 
-                // $matchResult = $item->matches($mustIncludeItem);
-                $matchResult = in_array($mustIncludeItem, $item);
-                print('DEBUG $matchResult: ');
-                var_dump($matchResult);
-                print('<br>');
+                // // $matchResult = $item->matches($mustIncludeItem);
+                // $matchResult = in_array($mustIncludeItem, $item);
+                // print('DEBUG $matchResult: ');
+                // var_dump($matchResult);
+                // print('<br>');
 
                 if($matchResult) {
                     $mustMatchCheck = True;

From 0192aa32f66110d6baf9d8c658e93c89db32512e Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 16 Aug 2021 19:28:36 +0200
Subject: [PATCH 083/250] testing search function

---
 include/SearchPage.php | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index e7c4ba4..b7df960 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -117,9 +117,9 @@ class SearchPage extends Page {
             print('DEBUG $item[0][0]: ');
             var_dump($item[0][0]);
             print('<br>');
-            print('DEBUG $item[0[0]]: ');
-            var_dump($item[0[0]]);
-            print('<br>');
+            // print('DEBUG $item[0[0]]: ');
+            // var_dump($item[0[0]]);
+            // print('<br>');
 
             $mustMatchCheck = False;
             foreach($mustIncludeArray as $mustIncludeItem) {
@@ -153,20 +153,20 @@ class SearchPage extends Page {
             }
         }
 
-        $out = array();
-        foreach ($sanitizedDB as $sanitizedItem) {
-                if ($sanitizedItem->matches($mustExcludeArray)) {
+        // $out = array();
+        // foreach ($sanitizedDB as $sanitizedItem) {
+        //         if ($sanitizedItem->matches($mustExcludeArray)) {
 
-                    // === IF TRUE DO NOTHING ===
+        //             // === IF TRUE DO NOTHING ===
 
-                } else {
-                    // $result = $sanitizedItem->matches($canIncludeArray);
-                    // if($result) {
-                    //     $out[] = array($sanitizedItem, $result);
-                    // }
-                }
-            }
-        return $out;
+        //         } else {
+        //             // $result = $sanitizedItem->matches($canIncludeArray);
+        //             // if($result) {
+        //             //     $out[] = array($sanitizedItem, $result);
+        //             // }
+        //         }
+        //     }
+        // return $out;
     }
 
     private function translate_terms($terms) {

From 018cb48d4c8282bf1d421c8f804a0822fbba1b15 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 16 Aug 2021 19:31:12 +0200
Subject: [PATCH 084/250] testing search function

---
 include/SearchPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index b7df960..c3bccd8 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -111,8 +111,8 @@ class SearchPage extends Page {
             print('DEBUG $item: ');
             var_dump($item);
             print('<br>');
-            print('DEBUG $item[0]: ');
-            var_dump($item[0]);
+            print('DEBUG $items[item]: ');
+            var_dump($items[$items]);
             print('<br>');
             print('DEBUG $item[0][0]: ');
             var_dump($item[0][0]);

From ecaa25cb14b84d79ceaf422cd5e6644ec5453c0b Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 16 Aug 2021 19:33:07 +0200
Subject: [PATCH 085/250] testing search function

---
 include/SearchPage.php | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index c3bccd8..5e706a1 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -106,20 +106,20 @@ class SearchPage extends Page {
 
         $items = get_items($type);
         $sanitizedDB = array();
-        foreach($items as $item) {
+        foreach($items as $item => $j) {
 
             print('DEBUG $item: ');
             var_dump($item);
             print('<br>');
-            print('DEBUG $items[item]: ');
-            var_dump($items[$items]);
+            print('DEBUG $items[$item]: ');
+            var_dump($items[$item]);
             print('<br>');
-            print('DEBUG $item[0][0]: ');
-            var_dump($item[0][0]);
+            print('DEBUG $items[$j]: ');
+            var_dump($items[$j]);
+            print('<br>');
+            print('DEBUG $item[$j]: ');
+            var_dump($item[$j]);
             print('<br>');
-            // print('DEBUG $item[0[0]]: ');
-            // var_dump($item[0[0]]);
-            // print('<br>');
 
             $mustMatchCheck = False;
             foreach($mustIncludeArray as $mustIncludeItem) {

From 9b2053a7ada4b21773ae9f4c9ece50d420827472 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 16 Aug 2021 19:38:35 +0200
Subject: [PATCH 086/250] testing search function

---
 include/SearchPage.php | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 5e706a1..c839ff8 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -108,18 +108,18 @@ class SearchPage extends Page {
         $sanitizedDB = array();
         foreach($items as $item => $j) {
 
-            print('DEBUG $item: ');
-            var_dump($item);
-            print('<br>');
-            print('DEBUG $items[$item]: ');
-            var_dump($items[$item]);
-            print('<br>');
-            print('DEBUG $items[$j]: ');
-            var_dump($items[$j]);
-            print('<br>');
-            print('DEBUG $item[$j]: ');
-            var_dump($item[$j]);
-            print('<br>');
+            // print('DEBUG $item: ');
+            // var_dump($item);
+            // print('<br>');
+            // print('DEBUG $items[$item]: ');
+            // var_dump($items[$item]);
+            // print('<br>');
+            // print('DEBUG $items[$j]: ');
+            // var_dump($items[$j]);
+            // print('<br>');
+            // print('DEBUG $item[$j]: ');
+            // var_dump($item[$j]);
+            // print('<br>');
 
             $mustMatchCheck = False;
             foreach($mustIncludeArray as $mustIncludeItem) {
@@ -132,11 +132,11 @@ class SearchPage extends Page {
                 // var_dump($mustIncludeItem);
                 // print('<br>');
 
-                // // $matchResult = $item->matches($mustIncludeItem);
-                // $matchResult = in_array($mustIncludeItem, $item);
-                // print('DEBUG $matchResult: ');
-                // var_dump($matchResult);
-                // print('<br>');
+                // $matchResult = $item->matches($mustIncludeItem);
+                $matchResult = in_array($mustIncludeItem, $items[$item]);
+                print('DEBUG $matchResult: ');
+                var_dump($matchResult);
+                print('<br>');
 
                 if($matchResult) {
                     $mustMatchCheck = True;

From b0335ce4ce07853f2cabe29dee9852c8ed31da1d Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 16 Aug 2021 19:39:33 +0200
Subject: [PATCH 087/250] testing search function

---
 include/SearchPage.php | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index c839ff8..e0d01c1 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -128,6 +128,10 @@ class SearchPage extends Page {
                 // var_dump($item);
                 // print('<br>');
 
+                print('DEBUG $mustIncludeItem: ');
+                var_dump($mustIncludeItem);
+                print('<br>');
+
                 // print('DEBUG $mustMustIncludeItem: ');
                 // var_dump($mustIncludeItem);
                 // print('<br>');

From d3f08a4c10c13cad29fffc96033da95dd89d9c95 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 16 Aug 2021 19:40:34 +0200
Subject: [PATCH 088/250] testing search function

---
 include/SearchPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index e0d01c1..da55d74 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -128,8 +128,8 @@ class SearchPage extends Page {
                 // var_dump($item);
                 // print('<br>');
 
-                print('DEBUG $mustIncludeItem: ');
-                var_dump($mustIncludeItem);
+                print('DEBUG $mustIncludeArray[$mustIncludeItem]: ');
+                var_dump($mustIncludeArray[$mustIncludeItem]);
                 print('<br>');
 
                 // print('DEBUG $mustMustIncludeItem: ');

From 795f007153f271b76bed713b1a9311c534756407 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 19 Aug 2021 10:03:27 +0200
Subject: [PATCH 089/250] testing search function

---
 include/SearchPage.php | 98 +++++++++++-------------------------------
 1 file changed, 26 insertions(+), 72 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index da55d74..51cf675 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -37,6 +37,10 @@ class SearchPage extends Page {
         return $out;
     }
 
+    private function outbool($test) {
+        return (bool) $test;
+    }
+
     private function search($type, $terms) {
         /*
         
@@ -58,10 +62,6 @@ class SearchPage extends Page {
 
         */
 
-        // print('DEBUG $terms dump: ');
-        // var_dump($terms);
-        // print('<br>'); 
-
         $mustIncludeArray = array(); 
         $mustExcludeArray = array(); 
         $canIncludeArray = array();
@@ -83,94 +83,48 @@ class SearchPage extends Page {
                         $canIncludeArray[] = array($values[$value]);
                         break;
                 }
-                // print('DEBUG $values[$value] dump: ');
-                // var_dump($values[$value]);
-                // print('<br>');
             }
-            // print('DEBUG $key dump: ');
-            // var_dump($key);
-            // print('<br>'); 
         }
 
         print('DEBUG mustIncludeArray: ');
         print_r($mustIncludeArray);
         print('<br>');
 
-        // print('DEBUG mustExcludeArray: ');
-        // print_r($mustExcludeArray);
-        // print('<br>');
-
-        // print('DEBUG canIncludeArray: ');
-        // print_r($canIncludeArray);
-        // print('<br>');
-
         $items = get_items($type);
         $sanitizedDB = array();
-        foreach($items as $item => $j) {
+        foreach($items as $key => $item) {
 
-            // print('DEBUG $item: ');
-            // var_dump($item);
-            // print('<br>');
-            // print('DEBUG $items[$item]: ');
-            // var_dump($items[$item]);
-            // print('<br>');
-            // print('DEBUG $items[$j]: ');
-            // var_dump($items[$j]);
-            // print('<br>');
-            // print('DEBUG $item[$j]: ');
-            // var_dump($item[$j]);
-            // print('<br>');
+            $mustMatchCheck = array();
+            foreach($mustIncludeArray as $mustIncludeItem) { // pajar om Arrayen enbart har ett item???
 
-            $mustMatchCheck = False;
-            foreach($mustIncludeArray as $mustIncludeItem) {
-
-                // print('DEBUG $item: ');
-                // var_dump($item);
-                // print('<br>');
-
-                print('DEBUG $mustIncludeArray[$mustIncludeItem]: ');
-                var_dump($mustIncludeArray[$mustIncludeItem]);
-                print('<br>');
-
-                // print('DEBUG $mustMustIncludeItem: ');
-                // var_dump($mustIncludeItem);
-                // print('<br>');
-
-                // $matchResult = $item->matches($mustIncludeItem);
-                $matchResult = in_array($mustIncludeItem, $items[$item]);
-                print('DEBUG $matchResult: ');
-                var_dump($matchResult);
-                print('<br>');
-
-                if($matchResult) {
-                    $mustMatchCheck = True;
-                    print('DEBUG $mustMatchCheck: TRUE <br>');
-                } else {
-                    $mustMatchCheck = False;
-                    // print('DEBUG $mustMatchCheck: FALSE <br>');
+                $mustIncludeItemCheck = $item->matches($mustIncludeItem); // matchar inte korrekt???
+                if ($mustIncludeItemCheck) {
+                    $mustMatchCheck[] = outbool(True);
+                }
+                else {
+                    $mustMatchCheck[] = outbool(False);
                 }
             }
 
-            if ($mustMatchCheck) {
+            if (array_product($mustMatchCheck)) {
                 $sanitizedDB[] = array($item);
-                print('DEBUG $sanitizedDB: ADDED ITEM <br>');
             }
         }
 
-        // $out = array();
-        // foreach ($sanitizedDB as $sanitizedItem) {
-        //         if ($sanitizedItem->matches($mustExcludeArray)) {
+        $out = array();
+        foreach ($sanitizedDB as $sanitizedItem) {
+                if ($sanitizedItem->matches($mustExcludeArray)) {
 
-        //             // === IF TRUE DO NOTHING ===
+                    // === IF TRUE DO NOTHING ===
 
-        //         } else {
-        //             // $result = $sanitizedItem->matches($canIncludeArray);
-        //             // if($result) {
-        //             //     $out[] = array($sanitizedItem, $result);
-        //             // }
-        //         }
-        //     }
-        // return $out;
+                } else {
+                    // $result = $sanitizedItem->matches($canIncludeArray);
+                    // if($result) {
+                    //     $out[] = array($sanitizedItem, $result);
+                    // }
+                }
+            }
+        return $out;
     }
 
     private function translate_terms($terms) {

From 428780eb6f97eb8593018088efff719e660d5795 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 19 Aug 2021 10:05:44 +0200
Subject: [PATCH 090/250] testing search function

---
 include/SearchPage.php | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 51cf675..c4ab0d6 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -92,7 +92,7 @@ class SearchPage extends Page {
 
         $items = get_items($type);
         $sanitizedDB = array();
-        foreach($items as $key => $item) {
+        foreach($items as $item) {
 
             $mustMatchCheck = array();
             foreach($mustIncludeArray as $mustIncludeItem) { // pajar om Arrayen enbart har ett item???
@@ -106,25 +106,25 @@ class SearchPage extends Page {
                 }
             }
 
-            if (array_product($mustMatchCheck)) {
-                $sanitizedDB[] = array($item);
-            }
+            // if (array_product($mustMatchCheck)) {
+            //     $sanitizedDB[] = array($item);
+            // }
         }
 
-        $out = array();
-        foreach ($sanitizedDB as $sanitizedItem) {
-                if ($sanitizedItem->matches($mustExcludeArray)) {
+        // $out = array();
+        // foreach ($sanitizedDB as $sanitizedItem) {
+        //         if ($sanitizedItem->matches($mustExcludeArray)) {
 
-                    // === IF TRUE DO NOTHING ===
+        //             // === IF TRUE DO NOTHING ===
 
-                } else {
-                    // $result = $sanitizedItem->matches($canIncludeArray);
-                    // if($result) {
-                    //     $out[] = array($sanitizedItem, $result);
-                    // }
-                }
-            }
-        return $out;
+        //         } else {
+        //             // $result = $sanitizedItem->matches($canIncludeArray);
+        //             // if($result) {
+        //             //     $out[] = array($sanitizedItem, $result);
+        //             // }
+        //         }
+        //     }
+        // return $out;
     }
 
     private function translate_terms($terms) {

From 2779051a820dc2cf61707cee3fb29beee5f6ceac Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 19 Aug 2021 10:07:15 +0200
Subject: [PATCH 091/250] testing search function

---
 include/SearchPage.php | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index c4ab0d6..54b54a8 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -97,13 +97,13 @@ class SearchPage extends Page {
             $mustMatchCheck = array();
             foreach($mustIncludeArray as $mustIncludeItem) { // pajar om Arrayen enbart har ett item???
 
-                $mustIncludeItemCheck = $item->matches($mustIncludeItem); // matchar inte korrekt???
-                if ($mustIncludeItemCheck) {
-                    $mustMatchCheck[] = outbool(True);
-                }
-                else {
-                    $mustMatchCheck[] = outbool(False);
-                }
+                // $mustIncludeItemCheck = $item->matches($mustIncludeItem); // matchar inte korrekt???
+                // if ($mustIncludeItemCheck) {
+                //     $mustMatchCheck[] = outbool(True);
+                // }
+                // else {
+                //     $mustMatchCheck[] = outbool(False);
+                // }
             }
 
             // if (array_product($mustMatchCheck)) {
@@ -111,7 +111,7 @@ class SearchPage extends Page {
             // }
         }
 
-        // $out = array();
+        $out = array();
         // foreach ($sanitizedDB as $sanitizedItem) {
         //         if ($sanitizedItem->matches($mustExcludeArray)) {
 
@@ -124,7 +124,7 @@ class SearchPage extends Page {
         //             // }
         //         }
         //     }
-        // return $out;
+        return $out;
     }
 
     private function translate_terms($terms) {

From 5c4ebeda840f05e13af84a9768497324c69884c9 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 19 Aug 2021 10:11:12 +0200
Subject: [PATCH 092/250] testing search function

---
 include/SearchPage.php | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 54b54a8..310fed9 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -37,10 +37,6 @@ class SearchPage extends Page {
         return $out;
     }
 
-    private function outbool($test) {
-        return (bool) $test;
-    }
-
     private function search($type, $terms) {
         /*
         
@@ -97,12 +93,24 @@ class SearchPage extends Page {
             $mustMatchCheck = array();
             foreach($mustIncludeArray as $mustIncludeItem) { // pajar om Arrayen enbart har ett item???
 
+                print('DEBUG $mustIncludeItem: ');
+                print_r($mustIncludeItem);
+                print('<br>');
+
+                print('DEBUG $mustIncludeArray($mustIncludeItem): ');
+                print_r($mustIncludeArray($mustIncludeItem));
+                print('<br>');
+
+                print('DEBUG $mustIncludeArray[$mustIncludeItem]: ');
+                print_r($mustIncludeArray[$mustIncludeItem]);
+                print('<br>');
+
                 // $mustIncludeItemCheck = $item->matches($mustIncludeItem); // matchar inte korrekt???
                 // if ($mustIncludeItemCheck) {
-                //     $mustMatchCheck[] = outbool(True);
+                //     $mustMatchCheck[] = array(True);
                 // }
                 // else {
-                //     $mustMatchCheck[] = outbool(False);
+                //     $mustMatchCheck[] = array(False);
                 // }
             }
 

From 529e71271ae06d09e41a0d8421a6a0e45f213e84 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 19 Aug 2021 10:12:28 +0200
Subject: [PATCH 093/250] testing search function

---
 include/SearchPage.php | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 310fed9..12be015 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -97,10 +97,11 @@ class SearchPage extends Page {
                 print_r($mustIncludeItem);
                 print('<br>');
 
-                print('DEBUG $mustIncludeArray($mustIncludeItem): ');
-                print_r($mustIncludeArray($mustIncludeItem));
+                print('DEBUG VARDUMP $mustIncludeItem: ');
+                var_dump($mustIncludeItem);
                 print('<br>');
 
+
                 print('DEBUG $mustIncludeArray[$mustIncludeItem]: ');
                 print_r($mustIncludeArray[$mustIncludeItem]);
                 print('<br>');

From 31e9e21d4b90e51409dcd7c4a79c1893aca4fbd3 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 19 Aug 2021 10:29:37 +0200
Subject: [PATCH 094/250] testing search function

---
 include/SearchPage.php | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 12be015..9248f68 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -62,21 +62,21 @@ class SearchPage extends Page {
         $mustExcludeArray = array(); 
         $canIncludeArray = array();
 
-        foreach($terms as $key => $values) {
-            foreach($values as $value => $i) {
-                switch ($values[$value][0]) {
+        foreach($terms as $key => $term) {
+            foreach($term as $value => $i) {
+                switch ($term[$value][0]) {
                     case "+":
-                         $mustIncludeArray[] = array(substr($values[$value], 1));
+                         $mustIncludeArray[] = array(substr($term[$value], 1));
                         break;
                     case "!":
                     case "-":
-                        $mustExcludeArray[] = array(substr($values[$value], 1));
+                        $mustExcludeArray[] = array(substr($term[$value], 1));
                         break;
                     case "~":
-                        $canIncludeArray[] = array(substr($values[$value], 1));
+                        $canIncludeArray[] = array(substr($term[$value], 1));
                         break;
                     default:
-                        $canIncludeArray[] = array($values[$value]);
+                        $canIncludeArray[] = array($term[$value]);
                         break;
                 }
             }
@@ -86,28 +86,34 @@ class SearchPage extends Page {
         print_r($mustIncludeArray);
         print('<br>');
 
+        print('DEBUG VARDUMP $mustIncludeItem: ');
+        var_dump($terms);
+        print('<br>');
+
         $items = get_items($type);
         $sanitizedDB = array();
         foreach($items as $item) {
 
             $mustMatchCheck = array();
-            foreach($mustIncludeArray as $mustIncludeItem) { // pajar om Arrayen enbart har ett item???
+            foreach($mustIncludeArray as $mustIncludeTerm) { // pajar om Arrayen enbart har ett item???
 
-                print('DEBUG $mustIncludeItem: ');
-                print_r($mustIncludeItem);
+                print('DEBUG $mustIncludeTerm: ');
+                print_r($mustIncludeTerm);
                 print('<br>');
 
-                print('DEBUG VARDUMP $mustIncludeItem: ');
-                var_dump($mustIncludeItem);
+                print('DEBUG VARDUMP $mustIncludeTerm: ');
+                var_dump($mustIncludeTerm);
                 print('<br>');
 
 
-                print('DEBUG $mustIncludeArray[$mustIncludeItem]: ');
-                print_r($mustIncludeArray[$mustIncludeItem]);
+                print('DEBUG $mustIncludeArray[$mustIncludeTerm]: ');
+                print_r($mustIncludeArray[$mustIncludeTerm]);
                 print('<br>');
 
-                // $mustIncludeItemCheck = $item->matches($mustIncludeItem); // matchar inte korrekt???
-                // if ($mustIncludeItemCheck) {
+                $res = $item->matches();
+
+                // $mustIncludeTermCheck = $item->matches($mustIncludeTerm); // matchar inte korrekt???
+                // if ($mustIncludeTermCheck) {
                 //     $mustMatchCheck[] = array(True);
                 // }
                 // else {

From efddd93c88065bc92823564435b4d178e024cfb8 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 19 Aug 2021 10:40:13 +0200
Subject: [PATCH 095/250] testing search function

---
 include/SearchPage.php | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 9248f68..f64994a 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -86,7 +86,7 @@ class SearchPage extends Page {
         print_r($mustIncludeArray);
         print('<br>');
 
-        print('DEBUG VARDUMP $mustIncludeItem: ');
+        print('DEBUG VARDUMP $terms: ');
         var_dump($terms);
         print('<br>');
 
@@ -105,11 +105,6 @@ class SearchPage extends Page {
                 var_dump($mustIncludeTerm);
                 print('<br>');
 
-
-                print('DEBUG $mustIncludeArray[$mustIncludeTerm]: ');
-                print_r($mustIncludeArray[$mustIncludeTerm]);
-                print('<br>');
-
                 $res = $item->matches();
 
                 // $mustIncludeTermCheck = $item->matches($mustIncludeTerm); // matchar inte korrekt???

From 1b3c3f07c8ee50d06ceba65528cc0b86b23a2e2a Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 19 Aug 2021 10:41:04 +0200
Subject: [PATCH 096/250] testing search function

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index f64994a..24351cd 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -105,7 +105,7 @@ class SearchPage extends Page {
                 var_dump($mustIncludeTerm);
                 print('<br>');
 
-                $res = $item->matches();
+                $res = $item->matches($mustIncludeTerm);
 
                 // $mustIncludeTermCheck = $item->matches($mustIncludeTerm); // matchar inte korrekt???
                 // if ($mustIncludeTermCheck) {

From 87f78cacc9193a23391954a8cf3ad607eb7efe7f Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 19 Aug 2021 10:45:10 +0200
Subject: [PATCH 097/250] testing search function

---
 include/SearchPage.php | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 24351cd..a5d8ba8 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -89,6 +89,7 @@ class SearchPage extends Page {
         print('DEBUG VARDUMP $terms: ');
         var_dump($terms);
         print('<br>');
+        print('<br>');
 
         $items = get_items($type);
         $sanitizedDB = array();
@@ -104,6 +105,7 @@ class SearchPage extends Page {
                 print('DEBUG VARDUMP $mustIncludeTerm: ');
                 var_dump($mustIncludeTerm);
                 print('<br>');
+                print('<br>');
 
                 $res = $item->matches($mustIncludeTerm);
 

From 3194425bd12cc50e420567b9c6ee16d6da1fadc6 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 19 Aug 2021 10:46:42 +0200
Subject: [PATCH 098/250] cleaning up debug output

---
 include/SearchPage.php | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index a5d8ba8..bc907ee 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -95,6 +95,8 @@ class SearchPage extends Page {
         $sanitizedDB = array();
         foreach($items as $item) {
 
+            print('DEBUG Foreach $item: ');
+            print('<br>');
             $mustMatchCheck = array();
             foreach($mustIncludeArray as $mustIncludeTerm) { // pajar om Arrayen enbart har ett item???
 

From 1c3ee500c88489d2fa21958f9e43e5854717cfca Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 19 Aug 2021 10:47:38 +0200
Subject: [PATCH 099/250] cleaning up debug output

---
 include/SearchPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index bc907ee..d8cfa2e 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -107,7 +107,6 @@ class SearchPage extends Page {
                 print('DEBUG VARDUMP $mustIncludeTerm: ');
                 var_dump($mustIncludeTerm);
                 print('<br>');
-                print('<br>');
 
                 $res = $item->matches($mustIncludeTerm);
 
@@ -119,7 +118,8 @@ class SearchPage extends Page {
                 //     $mustMatchCheck[] = array(False);
                 // }
             }
-
+            print('<br>');
+            
             // if (array_product($mustMatchCheck)) {
             //     $sanitizedDB[] = array($item);
             // }

From f5c55c28b3ac2fa627fbb36e73990a0471869833 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 19 Aug 2021 10:50:34 +0200
Subject: [PATCH 100/250] cleaning up debug output

---
 include/SearchPage.php | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index d8cfa2e..6c621f5 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -29,6 +29,9 @@ class SearchPage extends Page {
             return $out;
         }
         foreach(array('user', 'product') as $type) {
+            print('DEBUG $type: ');
+            print_r($type);
+            print('<br>');
             $result = $this->search($type, $this->terms);
             if($result) {
                 $out[$type] = $result;
@@ -119,7 +122,7 @@ class SearchPage extends Page {
                 // }
             }
             print('<br>');
-            
+
             // if (array_product($mustMatchCheck)) {
             //     $sanitizedDB[] = array($item);
             // }

From 70ad97daf6c7f3795e82a316e62cd03d93486f7c Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 19 Aug 2021 10:51:55 +0200
Subject: [PATCH 101/250] cleaning up debug output

---
 include/SearchPage.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 6c621f5..72dd89f 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -29,8 +29,9 @@ class SearchPage extends Page {
             return $out;
         }
         foreach(array('user', 'product') as $type) {
-            print('DEBUG $type: ');
+            print('DEBUG === $type:');
             print_r($type);
+            print(' ===<br>');
             print('<br>');
             $result = $this->search($type, $this->terms);
             if($result) {

From 6a177bd6153b31b978bd14f11dfc091f361a8fcb Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 19 Aug 2021 10:53:03 +0200
Subject: [PATCH 102/250] testing search function

---
 include/SearchPage.php | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 72dd89f..7bea542 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -29,7 +29,7 @@ class SearchPage extends Page {
             return $out;
         }
         foreach(array('user', 'product') as $type) {
-            print('DEBUG === $type:');
+            print('=== DEBUG $type:');
             print_r($type);
             print(' ===<br>');
             print('<br>');
@@ -114,6 +114,10 @@ class SearchPage extends Page {
 
                 $res = $item->matches($mustIncludeTerm);
 
+                print('DEBUG VARDUMP $res: ');
+                var_dump($res);
+                print('<br>');
+
                 // $mustIncludeTermCheck = $item->matches($mustIncludeTerm); // matchar inte korrekt???
                 // if ($mustIncludeTermCheck) {
                 //     $mustMatchCheck[] = array(True);

From ae4cabf0677b23827281341040453e3c1a38311c Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 19 Aug 2021 10:54:31 +0200
Subject: [PATCH 103/250] testing search function

---
 include/SearchPage.php | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 7bea542..112d00e 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -100,6 +100,7 @@ class SearchPage extends Page {
         foreach($items as $item) {
 
             print('DEBUG Foreach $item: ');
+            var_dump($item);
             print('<br>');
             $mustMatchCheck = array();
             foreach($mustIncludeArray as $mustIncludeTerm) { // pajar om Arrayen enbart har ett item???

From 7377f1bea81e3a05de4ba062162e6b4634e72cbc Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 20 Aug 2021 14:53:26 +0200
Subject: [PATCH 104/250] testing search function

---
 include/SearchPage.php | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 112d00e..e8e15c6 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -68,6 +68,14 @@ class SearchPage extends Page {
 
         foreach($terms as $key => $term) {
             foreach($term as $value => $i) {
+                print('$term[$value]: ');
+                print_r($term[$value]);
+                print('<br>');
+
+                print('$term[$key]: ');
+                print_r($terms[$key]);
+                print('<br>');
+
                 switch ($term[$value][0]) {
                     case "+":
                          $mustIncludeArray[] = array(substr($term[$value], 1));

From 10a7dc434f8f5c3beaffb935a5d69250f9031776 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 20 Aug 2021 14:55:40 +0200
Subject: [PATCH 105/250] testing search function

---
 include/SearchPage.php | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index e8e15c6..5d9db78 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -67,15 +67,16 @@ class SearchPage extends Page {
         $canIncludeArray = array();
 
         foreach($terms as $key => $term) {
+
+            print('$terms[$key]: ');
+            print_r($terms[$key]);
+            print('<br>');
+            
             foreach($term as $value => $i) {
                 print('$term[$value]: ');
                 print_r($term[$value]);
                 print('<br>');
 
-                print('$term[$key]: ');
-                print_r($terms[$key]);
-                print('<br>');
-
                 switch ($term[$value][0]) {
                     case "+":
                          $mustIncludeArray[] = array(substr($term[$value], 1));

From ac6b293c90cc7d316f75477682ca1bf929e0e430 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 20 Aug 2021 14:57:58 +0200
Subject: [PATCH 106/250] testing search function

---
 include/SearchPage.php | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 5d9db78..35efd58 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -71,7 +71,11 @@ class SearchPage extends Page {
             print('$terms[$key]: ');
             print_r($terms[$key]);
             print('<br>');
-            
+
+            print('$terms[$term]: ');
+            print_r($terms[$term]);
+            print('<br>');
+
             foreach($term as $value => $i) {
                 print('$term[$value]: ');
                 print_r($term[$value]);

From 996d76c323fa13f6ff5fff63f3dac63c1ca0894b Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 20 Aug 2021 14:59:36 +0200
Subject: [PATCH 107/250] testing search function

---
 include/SearchPage.php | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 35efd58..964728c 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -68,16 +68,20 @@ class SearchPage extends Page {
 
         foreach($terms as $key => $term) {
 
-            print('$terms[$key]: ');
+            print('DEBUG VAR_DUMP $terms: ');
+            var_dump($terms);
+            print('<br>');
+
+            print('DEBUG $terms[$key]: ');
             print_r($terms[$key]);
             print('<br>');
 
-            print('$terms[$term]: ');
+            print('DEBUG $terms[$term]: ');
             print_r($terms[$term]);
             print('<br>');
 
             foreach($term as $value => $i) {
-                print('$term[$value]: ');
+                print('DEBUG $term[$value]: ');
                 print_r($term[$value]);
                 print('<br>');
 

From 0fd96b4334e66f5d1c14689c66d320cb2091ff24 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 20 Aug 2021 15:06:04 +0200
Subject: [PATCH 108/250] testing search function

---
 include/SearchPage.php | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 964728c..e5dbb4e 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -72,6 +72,10 @@ class SearchPage extends Page {
             var_dump($terms);
             print('<br>');
 
+            print('DEBUG $terms: ');
+            print_r($terms);
+            print('<br>');
+
             print('DEBUG $terms[$key]: ');
             print_r($terms[$key]);
             print('<br>');

From bf48b6a8bf418728ab14fa0f0b80a5872d91cffa Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 14:06:20 +0200
Subject: [PATCH 109/250] testing search function

---
 include/SearchPage.php | 54 +++++++++++++++++++++---------------------
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index e5dbb4e..419c32e 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -66,7 +66,7 @@ class SearchPage extends Page {
         $mustExcludeArray = array(); 
         $canIncludeArray = array();
 
-        foreach($terms as $key => $term) {
+        foreach($terms as $term) {
 
             print('DEBUG VAR_DUMP $terms: ');
             var_dump($terms);
@@ -76,35 +76,35 @@ class SearchPage extends Page {
             print_r($terms);
             print('<br>');
 
-            print('DEBUG $terms[$key]: ');
-            print_r($terms[$key]);
+            // print('DEBUG $terms[$key]: ');
+            // print_r($terms[$key]);
+            // print('<br>');
+
+            print('DEBUG $$term: ');
+            print_r($term);
             print('<br>');
 
-            print('DEBUG $terms[$term]: ');
-            print_r($terms[$term]);
-            print('<br>');
+            // foreach($term as $value => $i) {
+            //     print('DEBUG $term[$value]: ');
+            //     print_r($term[$value]);
+            //     print('<br>');
 
-            foreach($term as $value => $i) {
-                print('DEBUG $term[$value]: ');
-                print_r($term[$value]);
-                print('<br>');
-
-                switch ($term[$value][0]) {
-                    case "+":
-                         $mustIncludeArray[] = array(substr($term[$value], 1));
-                        break;
-                    case "!":
-                    case "-":
-                        $mustExcludeArray[] = array(substr($term[$value], 1));
-                        break;
-                    case "~":
-                        $canIncludeArray[] = array(substr($term[$value], 1));
-                        break;
-                    default:
-                        $canIncludeArray[] = array($term[$value]);
-                        break;
-                }
-            }
+            //     switch ($term[$value][0]) {
+            //         case "+":
+            //              $mustIncludeArray[] = array(substr($term[$value], 1));
+            //             break;
+            //         case "!":
+            //         case "-":
+            //             $mustExcludeArray[] = array(substr($term[$value], 1));
+            //             break;
+            //         case "~":
+            //             $canIncludeArray[] = array(substr($term[$value], 1));
+            //             break;
+            //         default:
+            //             $canIncludeArray[] = array($term[$value]);
+            //             break;
+            //     }
+            // }
         }
 
         print('DEBUG mustIncludeArray: ');

From 0da95f6885171b6237d9a76b2bd53d841eeee3f9 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 14:08:07 +0200
Subject: [PATCH 110/250] testing search function

---
 include/SearchPage.php | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 419c32e..8162eed 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -80,10 +80,16 @@ class SearchPage extends Page {
             // print_r($terms[$key]);
             // print('<br>');
 
-            print('DEBUG $$term: ');
-            print_r($term);
+            print('DEBUG $term[0]: ');
+            print_r($term[0]);
             print('<br>');
 
+            print('DEBUG $term[1]: ');
+            print_r($term[1]);
+            print('<br>');
+
+            // $key =>
+
             // foreach($term as $value => $i) {
             //     print('DEBUG $term[$value]: ');
             //     print_r($term[$value]);

From 58cb8f25835fcb0cafb2fa54302d671f78d157d8 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 14:09:01 +0200
Subject: [PATCH 111/250] testing search function

---
 include/SearchPage.php | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 8162eed..d6508f6 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -80,12 +80,12 @@ class SearchPage extends Page {
             // print_r($terms[$key]);
             // print('<br>');
 
-            print('DEBUG $term[0]: ');
-            print_r($term[0]);
+            print('DEBUG $terms[0]: ');
+            print_r($terms[0]);
             print('<br>');
 
-            print('DEBUG $term[1]: ');
-            print_r($term[1]);
+            print('DEBUG $terms[1]: ');
+            print_r($terms[1]);
             print('<br>');
 
             // $key =>

From 0b8a4c468448b117d726b5c3b0d45e5609cf1870 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 14:11:18 +0200
Subject: [PATCH 112/250] testing search function

---
 include/SearchPage.php | 66 +++++++++++++++++++++++-------------------
 1 file changed, 36 insertions(+), 30 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index d6508f6..d2e5818 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -66,7 +66,7 @@ class SearchPage extends Page {
         $mustExcludeArray = array(); 
         $canIncludeArray = array();
 
-        foreach($terms as $term) {
+        foreach($terms as $key => $term) {
 
             print('DEBUG VAR_DUMP $terms: ');
             var_dump($terms);
@@ -76,41 +76,47 @@ class SearchPage extends Page {
             print_r($terms);
             print('<br>');
 
-            // print('DEBUG $terms[$key]: ');
-            // print_r($terms[$key]);
-            // print('<br>');
-
-            print('DEBUG $terms[0]: ');
-            print_r($terms[0]);
+            print('DEBUG $terms[$key]: ');
+            print_r($terms[$key]);
             print('<br>');
 
-            print('DEBUG $terms[1]: ');
-            print_r($terms[1]);
+            print('DEBUG $terms[$term]: ');
+            print_r($terms[$term]);
             print('<br>');
 
-            // $key =>
+            foreach($term as $value => $i) {
+                print('DEBUG $term[$value]: ');
+                print_r($term[$value]);
+                print('<br>');
 
-            // foreach($term as $value => $i) {
-            //     print('DEBUG $term[$value]: ');
-            //     print_r($term[$value]);
-            //     print('<br>');
+                print('DEBUG $i: ');
+                print_r($i);
+                print('<br>');
 
-            //     switch ($term[$value][0]) {
-            //         case "+":
-            //              $mustIncludeArray[] = array(substr($term[$value], 1));
-            //             break;
-            //         case "!":
-            //         case "-":
-            //             $mustExcludeArray[] = array(substr($term[$value], 1));
-            //             break;
-            //         case "~":
-            //             $canIncludeArray[] = array(substr($term[$value], 1));
-            //             break;
-            //         default:
-            //             $canIncludeArray[] = array($term[$value]);
-            //             break;
-            //     }
-            // }
+                print('DEBUG $term[$i]: ');
+                print_r($term[$i]);
+                print('<br>');
+
+                print('DEBUG $term[$value][0]: ');
+                print_r($term[$value][0]);
+                print('<br>');
+
+                // switch ($term[$value][0]) {
+                //     case "+":
+                //          $mustIncludeArray[] = array(substr($term[$value], 1));
+                //         break;
+                //     case "!":
+                //     case "-":
+                //         $mustExcludeArray[] = array(substr($term[$value], 1));
+                //         break;
+                //     case "~":
+                //         $canIncludeArray[] = array(substr($term[$value], 1));
+                //         break;
+                //     default:
+                //         $canIncludeArray[] = array($term[$value]);
+                //         break;
+                // }
+            }
         }
 
         print('DEBUG mustIncludeArray: ');

From 3f1cba169c7441385a3f38a6e0a020cd6f483e31 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 14:12:58 +0200
Subject: [PATCH 113/250] testing search function

---
 include/SearchPage.php | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index d2e5818..b3b3322 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -101,6 +101,11 @@ class SearchPage extends Page {
                 print_r($term[$value][0]);
                 print('<br>');
 
+                print('DEBUG $i[0]: ');
+                print_r($i[0]);
+                print('<br>');
+                print('<br>');
+
                 // switch ($term[$value][0]) {
                 //     case "+":
                 //          $mustIncludeArray[] = array(substr($term[$value], 1));

From 36f8ff63b4c12839cea69f8f0156f7542433ad52 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 14:13:43 +0200
Subject: [PATCH 114/250] testing search function

---
 include/SearchPage.php | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index b3b3322..769d040 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -83,6 +83,7 @@ class SearchPage extends Page {
             print('DEBUG $terms[$term]: ');
             print_r($terms[$term]);
             print('<br>');
+            print('<br>');
 
             foreach($term as $value => $i) {
                 print('DEBUG $term[$value]: ');

From dece01a78790069bbf3f2f6d0a5dd42fd8e8073f Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 14:15:13 +0200
Subject: [PATCH 115/250] testing search function

---
 include/SearchPage.php | 78 +++++++++++++++++++++++-------------------
 1 file changed, 42 insertions(+), 36 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 769d040..87ee77f 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -66,7 +66,9 @@ class SearchPage extends Page {
         $mustExcludeArray = array(); 
         $canIncludeArray = array();
 
-        foreach($terms as $key => $term) {
+
+        // ($terms as $key => $term)
+        foreach($terms as $term) {
 
             print('DEBUG VAR_DUMP $terms: ');
             var_dump($terms);
@@ -76,53 +78,57 @@ class SearchPage extends Page {
             print_r($terms);
             print('<br>');
 
-            print('DEBUG $terms[$key]: ');
-            print_r($terms[$key]);
+            print('DEBUG $term: ');
+            print_r($term);
             print('<br>');
 
+            // print('DEBUG $terms[$key]: ');
+            // print_r($terms[$key]);
+            // print('<br>');
+
             print('DEBUG $terms[$term]: ');
             print_r($terms[$term]);
             print('<br>');
             print('<br>');
 
-            foreach($term as $value => $i) {
-                print('DEBUG $term[$value]: ');
-                print_r($term[$value]);
-                print('<br>');
+            // foreach($term as $value => $i) {
+            //     print('DEBUG $term[$value]: ');
+            //     print_r($term[$value]);
+            //     print('<br>');
 
-                print('DEBUG $i: ');
-                print_r($i);
-                print('<br>');
+            //     print('DEBUG $i: ');
+            //     print_r($i);
+            //     print('<br>');
 
-                print('DEBUG $term[$i]: ');
-                print_r($term[$i]);
-                print('<br>');
+            //     print('DEBUG $term[$i]: ');
+            //     print_r($term[$i]);
+            //     print('<br>');
 
-                print('DEBUG $term[$value][0]: ');
-                print_r($term[$value][0]);
-                print('<br>');
+            //     print('DEBUG $term[$value][0]: ');
+            //     print_r($term[$value][0]);
+            //     print('<br>');
 
-                print('DEBUG $i[0]: ');
-                print_r($i[0]);
-                print('<br>');
-                print('<br>');
+            //     print('DEBUG $i[0]: ');
+            //     print_r($i[0]);
+            //     print('<br>');
+            //     print('<br>');
 
-                // switch ($term[$value][0]) {
-                //     case "+":
-                //          $mustIncludeArray[] = array(substr($term[$value], 1));
-                //         break;
-                //     case "!":
-                //     case "-":
-                //         $mustExcludeArray[] = array(substr($term[$value], 1));
-                //         break;
-                //     case "~":
-                //         $canIncludeArray[] = array(substr($term[$value], 1));
-                //         break;
-                //     default:
-                //         $canIncludeArray[] = array($term[$value]);
-                //         break;
-                // }
-            }
+            //     // switch ($term[$value][0]) {
+            //     //     case "+":
+            //     //          $mustIncludeArray[] = array(substr($term[$value], 1));
+            //     //         break;
+            //     //     case "!":
+            //     //     case "-":
+            //     //         $mustExcludeArray[] = array(substr($term[$value], 1));
+            //     //         break;
+            //     //     case "~":
+            //     //         $canIncludeArray[] = array(substr($term[$value], 1));
+            //     //         break;
+            //     //     default:
+            //     //         $canIncludeArray[] = array($term[$value]);
+            //     //         break;
+            //     // }
+            // }
         }
 
         print('DEBUG mustIncludeArray: ');

From 188fcf72768547c884f84090ecf6fe7c3bafacf4 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 14:16:27 +0200
Subject: [PATCH 116/250] testing things

---
 include/SearchPage.php | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 87ee77f..77832ec 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -66,9 +66,7 @@ class SearchPage extends Page {
         $mustExcludeArray = array(); 
         $canIncludeArray = array();
 
-
-        // ($terms as $key => $term)
-        foreach($terms as $term) {
+        foreach($terms as $key => $term) {
 
             print('DEBUG VAR_DUMP $terms: ');
             var_dump($terms);
@@ -78,17 +76,21 @@ class SearchPage extends Page {
             print_r($terms);
             print('<br>');
 
-            print('DEBUG $term: ');
-            print_r($term);
+            print('DEBUG $terms[$key]: ');
+            print_r($terms[$key]);
             print('<br>');
 
-            // print('DEBUG $terms[$key]: ');
-            // print_r($terms[$key]);
-            // print('<br>');
-
             print('DEBUG $terms[$term]: ');
             print_r($terms[$term]);
             print('<br>');
+
+            print('DEBUG $terms[0]: ');
+            print_r($terms[0]);
+            print('<br>');
+
+            print('DEBUG $terms[1]: ');
+            print_r($terms[1]);
+            print('<br>');
             print('<br>');
 
             // foreach($term as $value => $i) {

From b25b9512cee148bb7fdd5c444b343d232bffad39 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 14:17:28 +0200
Subject: [PATCH 117/250] testing things

---
 include/SearchPage.php | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 77832ec..c0faf3b 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -91,6 +91,14 @@ class SearchPage extends Page {
             print('DEBUG $terms[1]: ');
             print_r($terms[1]);
             print('<br>');
+
+            print('DEBUG $key: ');
+            print_r($key);
+            print('<br>');
+
+            // print('DEBUG $terms[1]: ');
+            // print_r($terms[1]);
+            // print('<br>');
             print('<br>');
 
             // foreach($term as $value => $i) {

From 24ed30f22b95e2d8122978529779ac0e5e982c73 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 14:20:35 +0200
Subject: [PATCH 118/250] testing things

---
 include/SearchPage.php | 70 ++++++++++--------------------------------
 1 file changed, 17 insertions(+), 53 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index c0faf3b..9546f04 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -80,65 +80,29 @@ class SearchPage extends Page {
             print_r($terms[$key]);
             print('<br>');
 
-            print('DEBUG $terms[$term]: ');
-            print_r($terms[$term]);
-            print('<br>');
-
-            print('DEBUG $terms[0]: ');
-            print_r($terms[0]);
-            print('<br>');
-
-            print('DEBUG $terms[1]: ');
-            print_r($terms[1]);
-            print('<br>');
-
             print('DEBUG $key: ');
             print_r($key);
             print('<br>');
 
-            // print('DEBUG $terms[1]: ');
-            // print_r($terms[1]);
-            // print('<br>');
             print('<br>');
 
-            // foreach($term as $value => $i) {
-            //     print('DEBUG $term[$value]: ');
-            //     print_r($term[$value]);
-            //     print('<br>');
-
-            //     print('DEBUG $i: ');
-            //     print_r($i);
-            //     print('<br>');
-
-            //     print('DEBUG $term[$i]: ');
-            //     print_r($term[$i]);
-            //     print('<br>');
-
-            //     print('DEBUG $term[$value][0]: ');
-            //     print_r($term[$value][0]);
-            //     print('<br>');
-
-            //     print('DEBUG $i[0]: ');
-            //     print_r($i[0]);
-            //     print('<br>');
-            //     print('<br>');
-
-            //     // switch ($term[$value][0]) {
-            //     //     case "+":
-            //     //          $mustIncludeArray[] = array(substr($term[$value], 1));
-            //     //         break;
-            //     //     case "!":
-            //     //     case "-":
-            //     //         $mustExcludeArray[] = array(substr($term[$value], 1));
-            //     //         break;
-            //     //     case "~":
-            //     //         $canIncludeArray[] = array(substr($term[$value], 1));
-            //     //         break;
-            //     //     default:
-            //     //         $canIncludeArray[] = array($term[$value]);
-            //     //         break;
-            //     // }
-            // }
+            foreach($term as $value => $i) {
+                switch ($i[0]) {
+                    case "+":
+                         $mustIncludeArray[] = array($key, (substr($i, 1)));
+                        break;
+                    case "!":
+                    case "-":
+                        $mustExcludeArray[] = array($key, (substr($i, 1)));
+                        break;
+                    case "~":
+                        $canIncludeArray[] = array($key, (substr($i, 1)));
+                        break;
+                    default:
+                        $canIncludeArray[] = array($key, $i);
+                        break;
+                }
+            }
         }
 
         print('DEBUG mustIncludeArray: ');

From 864be389c3d7c8a3be904d8474122736b10e96f5 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 14:21:44 +0200
Subject: [PATCH 119/250] testing things

---
 include/SearchPage.php | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 9546f04..e633c51 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -138,13 +138,13 @@ class SearchPage extends Page {
                 var_dump($res);
                 print('<br>');
 
-                // $mustIncludeTermCheck = $item->matches($mustIncludeTerm); // matchar inte korrekt???
-                // if ($mustIncludeTermCheck) {
-                //     $mustMatchCheck[] = array(True);
-                // }
-                // else {
-                //     $mustMatchCheck[] = array(False);
-                // }
+                $mustIncludeTermCheck = $item->matches($mustIncludeTerm); // matchar inte korrekt???
+                if ($mustIncludeTermCheck) {
+                    $mustMatchCheck[] = array(True);
+                }
+                else {
+                    $mustMatchCheck[] = array(False);
+                }
             }
             print('<br>');
 

From 90246310a323b5129561cdea49fae012e9359ae5 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 14:22:44 +0200
Subject: [PATCH 120/250] testing things

---
 include/SearchPage.php | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index e633c51..95675d2 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -141,9 +141,13 @@ class SearchPage extends Page {
                 $mustIncludeTermCheck = $item->matches($mustIncludeTerm); // matchar inte korrekt???
                 if ($mustIncludeTermCheck) {
                     $mustMatchCheck[] = array(True);
+                    print('DEBUG TRUE added to $mustMatchCheck[] ');
+                    print('<br>');
                 }
                 else {
                     $mustMatchCheck[] = array(False);
+                    print('DEBUG FALSE added to $mustMatchCheck[] ');
+                    print('<br>');
                 }
             }
             print('<br>');

From af75f16791894e50788a2331f6d025c2f6ec3113 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 16:29:45 +0200
Subject: [PATCH 121/250] testing search function

---
 include/SearchPage.php | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 95675d2..67f7279 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -112,14 +112,17 @@ class SearchPage extends Page {
         print('DEBUG VARDUMP $terms: ');
         var_dump($terms);
         print('<br>');
+
         print('<br>');
 
         $items = get_items($type);
         $sanitizedDB = array();
         foreach($items as $item) {
 
-            print('DEBUG Foreach $item: ');
-            var_dump($item);
+            print('DEBUG Foreach $item[0]: ');
+            var_dump($item[0]);
+            print('<br>');
+
             print('<br>');
             $mustMatchCheck = array();
             foreach($mustIncludeArray as $mustIncludeTerm) { // pajar om Arrayen enbart har ett item???
@@ -149,6 +152,7 @@ class SearchPage extends Page {
                     print('DEBUG FALSE added to $mustMatchCheck[] ');
                     print('<br>');
                 }
+                print('<br>');
             }
             print('<br>');
 

From af520b3f033b8e2ae3d7475adca6891cb9be05e0 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 16:30:59 +0200
Subject: [PATCH 122/250] testing search function

---
 include/SearchPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 67f7279..b63758a 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -119,8 +119,8 @@ class SearchPage extends Page {
         $sanitizedDB = array();
         foreach($items as $item) {
 
-            print('DEBUG Foreach $item[0]: ');
-            var_dump($item[0]);
+            print('DEBUG Foreach $item: ');
+            var_dump($item);
             print('<br>');
 
             print('<br>');

From 89f6d06e87f0bedf66a9bda37930ffc4b2b3bb72 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 16:34:14 +0200
Subject: [PATCH 123/250] testing search function

---
 include/SearchPage.php | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index b63758a..524f536 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -89,17 +89,25 @@ class SearchPage extends Page {
             foreach($term as $value => $i) {
                 switch ($i[0]) {
                     case "+":
-                         $mustIncludeArray[] = array($key, (substr($i, 1)));
+                        $mustIncludeArray[] = array($key, (substr($i, 1)));
+                        print('DEBUG CASE $mustIncludeArray[] = array($key, (substr($i, 1))) ');
+                        print('<br>');
                         break;
                     case "!":
                     case "-":
                         $mustExcludeArray[] = array($key, (substr($i, 1)));
+                        print('DEBUG CASE $mustExcludeArray[] = array($key, (substr($i, 1))) ');
+                        print('<br>');
                         break;
                     case "~":
                         $canIncludeArray[] = array($key, (substr($i, 1)));
+                        print('DEBUG CASE $canIncludeArray[] = array($key, (substr($i, 1))) ');
+                        print('<br>');
                         break;
                     default:
                         $canIncludeArray[] = array($key, $i);
+                        print('DEBUG CASE $canIncludeArray[] = array($key, $i) ');
+                        print('<br>');
                         break;
                 }
             }

From 2c758a5a90b28d869547213b88fa966359c8bb3e Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 16:36:50 +0200
Subject: [PATCH 124/250] testing search function

---
 include/SearchPage.php | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 524f536..b785b39 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -90,24 +90,28 @@ class SearchPage extends Page {
                 switch ($i[0]) {
                     case "+":
                         $mustIncludeArray[] = array($key, (substr($i, 1)));
-                        print('DEBUG CASE $mustIncludeArray[] = array($key, (substr($i, 1))) ');
-                        print('<br>');
+                        print('DEBUG CASE $mustIncludeArray[] = array($key, ');
+                        print(substr($i, 1));
+                        print(') <br>');
                         break;
                     case "!":
                     case "-":
                         $mustExcludeArray[] = array($key, (substr($i, 1)));
-                        print('DEBUG CASE $mustExcludeArray[] = array($key, (substr($i, 1))) ');
-                        print('<br>');
+                        print('DEBUG CASE $mustExcludeArray[] = array($key, ');
+                        print(substr($i, 1));
+                        print(') <br>');
                         break;
                     case "~":
                         $canIncludeArray[] = array($key, (substr($i, 1)));
-                        print('DEBUG CASE $canIncludeArray[] = array($key, (substr($i, 1))) ');
-                        print('<br>');
+                        print('DEBUG CASE $canIncludeArray[] = array($key, ');
+                        print(substr($i, 1));
+                        print(') <br>');
                         break;
                     default:
                         $canIncludeArray[] = array($key, $i);
-                        print('DEBUG CASE $canIncludeArray[] = array($key, $i) ');
-                        print('<br>');
+                        print('DEBUG CASE $canIncludeArray[] = array($key, ');
+                        print(substr($i, 1));
+                        print(') <br>');
                         break;
                 }
             }

From 1c601928c3ce4039e66b1172d3b0ed0bab1efae1 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 16:38:21 +0200
Subject: [PATCH 125/250] testing search function

---
 include/SearchPage.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index b785b39..d7729bb 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -110,10 +110,11 @@ class SearchPage extends Page {
                     default:
                         $canIncludeArray[] = array($key, $i);
                         print('DEBUG CASE $canIncludeArray[] = array($key, ');
-                        print(substr($i, 1));
+                        print($i);
                         print(') <br>');
                         break;
                 }
+                print(') <br>');
             }
         }
 

From dac0dbce3c67e2918ec58114bfd57524e85a4abd Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 16:39:10 +0200
Subject: [PATCH 126/250] testing search function

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index d7729bb..e987827 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -114,8 +114,8 @@ class SearchPage extends Page {
                         print(') <br>');
                         break;
                 }
-                print(') <br>');
             }
+            print('<br>');
         }
 
         print('DEBUG mustIncludeArray: ');

From 60c9722663f36673ef976674cf232bede922f5c3 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 16:40:55 +0200
Subject: [PATCH 127/250] testing search function

---
 include/SearchPage.php | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index e987827..f4feec0 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -90,26 +90,34 @@ class SearchPage extends Page {
                 switch ($i[0]) {
                     case "+":
                         $mustIncludeArray[] = array($key, (substr($i, 1)));
-                        print('DEBUG CASE $mustIncludeArray[] = array($key, ');
+                        print('DEBUG CASE $mustIncludeArray[] = array(');
+                        print(substr($key);
+                        print(' ');
                         print(substr($i, 1));
                         print(') <br>');
                         break;
                     case "!":
                     case "-":
                         $mustExcludeArray[] = array($key, (substr($i, 1)));
-                        print('DEBUG CASE $mustExcludeArray[] = array($key, ');
+                        print('DEBUG CASE $mustExcludeArray[] = array(');
+                        print(substr($key);
+                        print(' ');
                         print(substr($i, 1));
                         print(') <br>');
                         break;
                     case "~":
                         $canIncludeArray[] = array($key, (substr($i, 1)));
-                        print('DEBUG CASE $canIncludeArray[] = array($key, ');
+                        print('DEBUG CASE $canIncludeArray[] = array(');
+                        print(substr($key);
+                        print(' ');
                         print(substr($i, 1));
                         print(') <br>');
                         break;
                     default:
                         $canIncludeArray[] = array($key, $i);
-                        print('DEBUG CASE $canIncludeArray[] = array($key, ');
+                        print('DEBUG CASE $canIncludeArray[] = array(');
+                        print(substr($key);
+                        print(' ');
                         print($i);
                         print(') <br>');
                         break;

From 020ff8c784bdd5f6503779da72888bfb897a85ca Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 16:41:37 +0200
Subject: [PATCH 128/250] testing search function

---
 include/SearchPage.php | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index f4feec0..4b07b1a 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -91,7 +91,7 @@ class SearchPage extends Page {
                     case "+":
                         $mustIncludeArray[] = array($key, (substr($i, 1)));
                         print('DEBUG CASE $mustIncludeArray[] = array(');
-                        print(substr($key);
+                        print($key);
                         print(' ');
                         print(substr($i, 1));
                         print(') <br>');
@@ -100,7 +100,7 @@ class SearchPage extends Page {
                     case "-":
                         $mustExcludeArray[] = array($key, (substr($i, 1)));
                         print('DEBUG CASE $mustExcludeArray[] = array(');
-                        print(substr($key);
+                        print($key);
                         print(' ');
                         print(substr($i, 1));
                         print(') <br>');
@@ -108,7 +108,7 @@ class SearchPage extends Page {
                     case "~":
                         $canIncludeArray[] = array($key, (substr($i, 1)));
                         print('DEBUG CASE $canIncludeArray[] = array(');
-                        print(substr($key);
+                        print($key);
                         print(' ');
                         print(substr($i, 1));
                         print(') <br>');
@@ -116,7 +116,7 @@ class SearchPage extends Page {
                     default:
                         $canIncludeArray[] = array($key, $i);
                         print('DEBUG CASE $canIncludeArray[] = array(');
-                        print(substr($key);
+                        print($key);
                         print(' ');
                         print($i);
                         print(') <br>');

From db87a190b442f2a5edd7807cbbb6c35d5ef3a8eb Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 16:42:09 +0200
Subject: [PATCH 129/250] testing search function

---
 include/SearchPage.php | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 4b07b1a..ca141e4 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -92,7 +92,7 @@ class SearchPage extends Page {
                         $mustIncludeArray[] = array($key, (substr($i, 1)));
                         print('DEBUG CASE $mustIncludeArray[] = array(');
                         print($key);
-                        print(' ');
+                        print(', ');
                         print(substr($i, 1));
                         print(') <br>');
                         break;
@@ -101,7 +101,7 @@ class SearchPage extends Page {
                         $mustExcludeArray[] = array($key, (substr($i, 1)));
                         print('DEBUG CASE $mustExcludeArray[] = array(');
                         print($key);
-                        print(' ');
+                        print(', ');
                         print(substr($i, 1));
                         print(') <br>');
                         break;
@@ -109,7 +109,7 @@ class SearchPage extends Page {
                         $canIncludeArray[] = array($key, (substr($i, 1)));
                         print('DEBUG CASE $canIncludeArray[] = array(');
                         print($key);
-                        print(' ');
+                        print(', ');
                         print(substr($i, 1));
                         print(') <br>');
                         break;
@@ -117,7 +117,7 @@ class SearchPage extends Page {
                         $canIncludeArray[] = array($key, $i);
                         print('DEBUG CASE $canIncludeArray[] = array(');
                         print($key);
-                        print(' ');
+                        print(', ');
                         print($i);
                         print(') <br>');
                         break;

From ba19463dfc9c33602f52bad9a76a3a2e5e55d704 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 16:44:17 +0200
Subject: [PATCH 130/250] testing search function

---
 include/SearchPage.php | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index ca141e4..321aaab 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -123,6 +123,9 @@ class SearchPage extends Page {
                         break;
                 }
             }
+            var_dump($mustIncludeArray);
+            var_dump($mustExcludeArray);
+            var_dump($canIncludeArray);
             print('<br>');
         }
 

From 37530311b39d06f3772f8df9249d3440ab327696 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 23 Aug 2021 16:45:19 +0200
Subject: [PATCH 131/250] testing search function

---
 include/SearchPage.php | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 321aaab..02fa20d 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -123,10 +123,16 @@ class SearchPage extends Page {
                         break;
                 }
             }
+            print('DEBUG VAR_DUMP $mustIncludeArray: ');
             var_dump($mustIncludeArray);
+            print('<br>');
+            print('DEBUG VAR_DUMP $mustExcludeArray: ');
             var_dump($mustExcludeArray);
+            print('<br>');
+            print('DEBUG VAR_DUMP $canIncludeArray: ');
             var_dump($canIncludeArray);
             print('<br>');
+            print('<br>');
         }
 
         print('DEBUG mustIncludeArray: ');

From f0faaa52c0c440ea889cbf3d5e8b16e4c9aa83ef Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 2 Sep 2021 10:56:54 +0200
Subject: [PATCH 132/250] cleaned up search function

---
 include/SearchPage.php | 141 +++++++++++------------------------------
 1 file changed, 38 insertions(+), 103 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 02fa20d..5f33389 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -29,10 +29,10 @@ class SearchPage extends Page {
             return $out;
         }
         foreach(array('user', 'product') as $type) {
-            print('=== DEBUG $type:');
-            print_r($type);
-            print(' ===<br>');
-            print('<br>');
+            // print('=== DEBUG $type:');
+            // print_r($type);
+            // print(' ===<br>');
+            // print('<br>');
             $result = $this->search($type, $this->terms);
             if($result) {
                 $out[$type] = $result;
@@ -42,8 +42,8 @@ class SearchPage extends Page {
     }
 
     private function search($type, $terms) {
+
         /*
-        
         ==================================================
 
         ORIGINAL CODE || BACKUP || FOR REFERENCE
@@ -59,7 +59,21 @@ class SearchPage extends Page {
         return $out;
     
         ==================================================
+        */
 
+
+        /*
+        ==================================================
+        
+        $terms = array(??,??,??)
+        $term = tbd
+        $key = e.g. "Fritext", "Tag", etc
+        $parsedTerm = e.g. "c426", "Dell"
+        $value = ????
+        $i = ????
+        $type = users, products
+
+        ==================================================
         */
 
         $mustIncludeArray = array(); 
@@ -67,127 +81,48 @@ class SearchPage extends Page {
         $canIncludeArray = array();
 
         foreach($terms as $key => $term) {
-
-            print('DEBUG VAR_DUMP $terms: ');
-            var_dump($terms);
-            print('<br>');
-
-            print('DEBUG $terms: ');
-            print_r($terms);
-            print('<br>');
-
-            print('DEBUG $terms[$key]: ');
-            print_r($terms[$key]);
-            print('<br>');
-
-            print('DEBUG $key: ');
-            print_r($key);
-            print('<br>');
-
-            print('<br>');
-
-            foreach($term as $value => $i) {
-                switch ($i[0]) {
+            foreach($term as $value => $parsedTerm) {
+                switch ($parsedTerm[0]) {
                     case "+":
-                        $mustIncludeArray[] = array($key, (substr($i, 1)));
-                        print('DEBUG CASE $mustIncludeArray[] = array(');
-                        print($key);
-                        print(', ');
-                        print(substr($i, 1));
-                        print(') <br>');
+                        $mustIncludeArray[] = array($key, substr($parsedTerm, 1));
                         break;
                     case "!":
                     case "-":
-                        $mustExcludeArray[] = array($key, (substr($i, 1)));
-                        print('DEBUG CASE $mustExcludeArray[] = array(');
-                        print($key);
-                        print(', ');
-                        print(substr($i, 1));
-                        print(') <br>');
-                        break;
+                        $mustExcludeArray[] = array($key, substr($parsedTerm, 1));
                     case "~":
-                        $canIncludeArray[] = array($key, (substr($i, 1)));
-                        print('DEBUG CASE $canIncludeArray[] = array(');
-                        print($key);
-                        print(', ');
-                        print(substr($i, 1));
-                        print(') <br>');
+                        $canIncludeArray[] = array($key, substr($parsedTerm, 1));
                         break;
                     default:
-                        $canIncludeArray[] = array($key, $i);
-                        print('DEBUG CASE $canIncludeArray[] = array(');
-                        print($key);
-                        print(', ');
-                        print($i);
-                        print(') <br>');
+                        $canIncludeArray[] = array($key, $parsedTerm);
                         break;
                 }
             }
-            print('DEBUG VAR_DUMP $mustIncludeArray: ');
-            var_dump($mustIncludeArray);
-            print('<br>');
-            print('DEBUG VAR_DUMP $mustExcludeArray: ');
-            var_dump($mustExcludeArray);
-            print('<br>');
-            print('DEBUG VAR_DUMP $canIncludeArray: ');
-            var_dump($canIncludeArray);
-            print('<br>');
-            print('<br>');
         }
 
-        print('DEBUG mustIncludeArray: ');
-        print_r($mustIncludeArray);
-        print('<br>');
-
-        print('DEBUG VARDUMP $terms: ');
-        var_dump($terms);
-        print('<br>');
-
-        print('<br>');
-
         $items = get_items($type);
         $sanitizedDB = array();
         foreach($items as $item) {
 
-            print('DEBUG Foreach $item: ');
-            var_dump($item);
-            print('<br>');
-
-            print('<br>');
             $mustMatchCheck = array();
             foreach($mustIncludeArray as $mustIncludeTerm) { // pajar om Arrayen enbart har ett item???
 
-                print('DEBUG $mustIncludeTerm: ');
-                print_r($mustIncludeTerm);
-                print('<br>');
-
-                print('DEBUG VARDUMP $mustIncludeTerm: ');
-                var_dump($mustIncludeTerm);
-                print('<br>');
-
-                $res = $item->matches($mustIncludeTerm);
-
-                print('DEBUG VARDUMP $res: ');
-                var_dump($res);
-                print('<br>');
-
-                $mustIncludeTermCheck = $item->matches($mustIncludeTerm); // matchar inte korrekt???
-                if ($mustIncludeTermCheck) {
-                    $mustMatchCheck[] = array(True);
-                    print('DEBUG TRUE added to $mustMatchCheck[] ');
-                    print('<br>');
-                }
-                else {
-                    $mustMatchCheck[] = array(False);
-                    print('DEBUG FALSE added to $mustMatchCheck[] ');
-                    print('<br>');
-                }
-                print('<br>');
+                // $mustIncludeTermCheck = $item->matches($mustIncludeTerm); // matchar inte korrekt???
+                // if ($mustIncludeTermCheck) {
+                //     $mustMatchCheck[] = array(True);
+                //     print('DEBUG TRUE added to $mustMatchCheck[] ');
+                //     print('<br>');
+                // }
+                // else {
+                //     $mustMatchCheck[] = array(False);
+                //     print('DEBUG FALSE added to $mustMatchCheck[] ');
+                //     print('<br>');
+                // }
+                // print('<br>');
             }
             print('<br>');
 
             // if (array_product($mustMatchCheck)) {
-            //     $sanitizedDB[] = array($item);
+            //     $sanitizedDB[] = array($item, $mustIncludeTermCheck);
             // }
         }
 

From e839a5b3a16d74ee1accf995f54270ceab5712cd Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 2 Sep 2021 11:00:28 +0200
Subject: [PATCH 133/250] fixed debug printouts search function

---
 include/SearchPage.php | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 5f33389..e2437e2 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -82,6 +82,23 @@ class SearchPage extends Page {
 
         foreach($terms as $key => $term) {
             foreach($term as $value => $parsedTerm) {
+
+                print('DEBUG VAR_DUMP: $terms ');
+                var_dump($terms);
+                print('<br>');
+                print('DEBUG VAR_DUMP: $key ');
+                var_dump($key);
+                print('<br>');
+                print('DEBUG VAR_DUMP: $term ');
+                var_dump($term);
+                print('<br>');
+                print('DEBUG VAR_DUMP: $value ');
+                var_dump($value);
+                print('<br>');
+                print('DEBUG VAR_DUMP: $parsedTerm ');
+                var_dump($parsedTerm);
+                print('<br>');
+
                 switch ($parsedTerm[0]) {
                     case "+":
                         $mustIncludeArray[] = array($key, substr($parsedTerm, 1));

From 815021cd1e1bc95509aef0b7b92b79db8e9f448e Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 2 Sep 2021 11:03:15 +0200
Subject: [PATCH 134/250] cleaning up debug printouts in search function

---
 include/SearchPage.php | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index e2437e2..8def834 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -29,10 +29,10 @@ class SearchPage extends Page {
             return $out;
         }
         foreach(array('user', 'product') as $type) {
-            // print('=== DEBUG $type:');
-            // print_r($type);
-            // print(' ===<br>');
-            // print('<br>');
+            print('=== DEBUG $type:');
+            print_r($type);
+            print(' ===<br>');
+            print('<br>');
             $result = $this->search($type, $this->terms);
             if($result) {
                 $out[$type] = $result;
@@ -113,7 +113,18 @@ class SearchPage extends Page {
                         $canIncludeArray[] = array($key, $parsedTerm);
                         break;
                 }
+
+                print('DEBUG VAR_DUMP: $mustIncludeArray ');
+                var_dump($mustIncludeArray);
+                print('<br>');
+                print('DEBUG VAR_DUMP: $mustExcludeArray ');
+                var_dump($mustExcludeArray);
+                print('<br>');
+                print('DEBUG VAR_DUMP: $canIncludeArray ');
+                var_dump($canIncludeArray);
+                print('<br>');
             }
+            print('<br>');
         }
 
         $items = get_items($type);
@@ -136,7 +147,7 @@ class SearchPage extends Page {
                 // }
                 // print('<br>');
             }
-            print('<br>');
+            // print('<br>');
 
             // if (array_product($mustMatchCheck)) {
             //     $sanitizedDB[] = array($item, $mustIncludeTermCheck);

From 2572ee898135196a76e8bffd86a24ea762cd7e23 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 2 Sep 2021 11:19:34 +0200
Subject: [PATCH 135/250] cleaning up debug printouts in search function

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 8def834..1ee46ca 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -124,7 +124,7 @@ class SearchPage extends Page {
                 var_dump($canIncludeArray);
                 print('<br>');
             }
-            print('<br>');
+            // print('<br>');
         }
 
         $items = get_items($type);

From 102f10f154df595aa0bf2008150b6dbbf3c5752f Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 2 Sep 2021 11:20:13 +0200
Subject: [PATCH 136/250] fixing debug printouts

---
 include/SearchPage.php | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 1ee46ca..47f413a 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -123,6 +123,7 @@ class SearchPage extends Page {
                 print('DEBUG VAR_DUMP: $canIncludeArray ');
                 var_dump($canIncludeArray);
                 print('<br>');
+                print('<br>');
             }
             // print('<br>');
         }

From 3ec8e9f666cee357849e5bf30dc0431125bc6cd6 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 2 Sep 2021 11:28:36 +0200
Subject: [PATCH 137/250] cleaned up debug printouts

---
 include/SearchPage.php | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 47f413a..e66f844 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -29,7 +29,7 @@ class SearchPage extends Page {
             return $out;
         }
         foreach(array('user', 'product') as $type) {
-            print('=== DEBUG $type:');
+            print('=== DEBUG $type: ');
             print_r($type);
             print(' ===<br>');
             print('<br>');
@@ -83,19 +83,19 @@ class SearchPage extends Page {
         foreach($terms as $key => $term) {
             foreach($term as $value => $parsedTerm) {
 
-                print('DEBUG VAR_DUMP: $terms ');
+                print('DEBUG VAR_DUMP $terms: ');
                 var_dump($terms);
                 print('<br>');
-                print('DEBUG VAR_DUMP: $key ');
+                print('DEBUG VAR_DUMP $key: ');
                 var_dump($key);
                 print('<br>');
-                print('DEBUG VAR_DUMP: $term ');
+                print('DEBUG VAR_DUMP $term: ');
                 var_dump($term);
                 print('<br>');
-                print('DEBUG VAR_DUMP: $value ');
+                print('DEBUG VAR_DUMP $value: ');
                 var_dump($value);
                 print('<br>');
-                print('DEBUG VAR_DUMP: $parsedTerm ');
+                print('DEBUG VAR_DUMP $parsedTerm: ');
                 var_dump($parsedTerm);
                 print('<br>');
 
@@ -114,13 +114,13 @@ class SearchPage extends Page {
                         break;
                 }
 
-                print('DEBUG VAR_DUMP: $mustIncludeArray ');
+                print('DEBUG VAR_DUMP $mustIncludeArray: ');
                 var_dump($mustIncludeArray);
                 print('<br>');
-                print('DEBUG VAR_DUMP: $mustExcludeArray ');
+                print('DEBUG VAR_DUMP $mustExcludeArray: ');
                 var_dump($mustExcludeArray);
                 print('<br>');
-                print('DEBUG VAR_DUMP: $canIncludeArray ');
+                print('DEBUG VAR_DUMP $canIncludeArray: ');
                 var_dump($canIncludeArray);
                 print('<br>');
                 print('<br>');

From 7268b655b1638bccad9b92a0af865cd9a1fdcdad Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 2 Sep 2021 15:15:23 +0200
Subject: [PATCH 138/250] fixing typo

---
 include/SearchPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index e66f844..d4b366c 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -106,6 +106,7 @@ class SearchPage extends Page {
                     case "!":
                     case "-":
                         $mustExcludeArray[] = array($key, substr($parsedTerm, 1));
+                        break;
                     case "~":
                         $canIncludeArray[] = array($key, substr($parsedTerm, 1));
                         break;
@@ -125,7 +126,6 @@ class SearchPage extends Page {
                 print('<br>');
                 print('<br>');
             }
-            // print('<br>');
         }
 
         $items = get_items($type);
@@ -133,7 +133,7 @@ class SearchPage extends Page {
         foreach($items as $item) {
 
             $mustMatchCheck = array();
-            foreach($mustIncludeArray as $mustIncludeTerm) { // pajar om Arrayen enbart har ett item???
+            foreach($mustIncludeArray as $i => $mustIncludeTerm) { // pajar om Arrayen enbart har ett item???
 
                 // $mustIncludeTermCheck = $item->matches($mustIncludeTerm); // matchar inte korrekt???
                 // if ($mustIncludeTermCheck) {

From 9c27f70a77fb8250bfdffd49af7fb5654735f3e5 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Fri, 3 Sep 2021 12:21:59 +0200
Subject: [PATCH 139/250] testing search function

---
 include/SearchPage.php | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index d4b366c..bd16304 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -28,6 +28,7 @@ class SearchPage extends Page {
         if(!$this->terms) {
             return $out;
         }
+        print('<br>');
         foreach(array('user', 'product') as $type) {
             print('=== DEBUG $type: ');
             print_r($type);
@@ -98,20 +99,21 @@ class SearchPage extends Page {
                 print('DEBUG VAR_DUMP $parsedTerm: ');
                 var_dump($parsedTerm);
                 print('<br>');
+                print('<br>');
 
                 switch ($parsedTerm[0]) {
                     case "+":
-                        $mustIncludeArray[] = array($key, substr($parsedTerm, 1));
+                        $mustIncludeArray[$key] = substr($parsedTerm, 1);
                         break;
                     case "!":
                     case "-":
-                        $mustExcludeArray[] = array($key, substr($parsedTerm, 1));
+                        $mustExcludeArray[$key] = substr($parsedTerm, 1);
                         break;
                     case "~":
-                        $canIncludeArray[] = array($key, substr($parsedTerm, 1));
+                        $canIncludeArray[$key] = substr($parsedTerm, 1);
                         break;
                     default:
-                        $canIncludeArray[] = array($key, $parsedTerm);
+                        $canIncludeArray[$key] = $parsedTerm;
                         break;
                 }
 

From 1db730b2cab71f96089d81c2d9289e0d08797a60 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 09:29:17 +0200
Subject: [PATCH 140/250] testing search function

---
 include/SearchPage.php | 80 ++++++++++++++++--------------------------
 1 file changed, 30 insertions(+), 50 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index bd16304..780504a 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -66,12 +66,11 @@ class SearchPage extends Page {
         /*
         ==================================================
         
-        $terms = array(??,??,??)
-        $term = tbd
+        $terms = array av arrayer
+        $term = array(key, parsedTerm)
         $key = e.g. "Fritext", "Tag", etc
         $parsedTerm = e.g. "c426", "Dell"
-        $value = ????
-        $i = ????
+        $value = någon form av key
         $type = users, products
 
         ==================================================
@@ -84,25 +83,9 @@ class SearchPage extends Page {
         foreach($terms as $key => $term) {
             foreach($term as $value => $parsedTerm) {
 
-                print('DEBUG VAR_DUMP $terms: ');
-                var_dump($terms);
-                print('<br>');
-                print('DEBUG VAR_DUMP $key: ');
-                var_dump($key);
-                print('<br>');
-                print('DEBUG VAR_DUMP $term: ');
-                var_dump($term);
-                print('<br>');
-                print('DEBUG VAR_DUMP $value: ');
-                var_dump($value);
-                print('<br>');
-                print('DEBUG VAR_DUMP $parsedTerm: ');
-                var_dump($parsedTerm);
-                print('<br>');
-                print('<br>');
-
                 switch ($parsedTerm[0]) {
                     case "+":
+                        // gör $mustIncludeArray till en array av arrayer?
                         $mustIncludeArray[$key] = substr($parsedTerm, 1);
                         break;
                     case "!":
@@ -116,48 +99,45 @@ class SearchPage extends Page {
                         $canIncludeArray[$key] = $parsedTerm;
                         break;
                 }
-
-                print('DEBUG VAR_DUMP $mustIncludeArray: ');
-                var_dump($mustIncludeArray);
-                print('<br>');
-                print('DEBUG VAR_DUMP $mustExcludeArray: ');
-                var_dump($mustExcludeArray);
-                print('<br>');
-                print('DEBUG VAR_DUMP $canIncludeArray: ');
-                var_dump($canIncludeArray);
-                print('<br>');
-                print('<br>');
             }
         }
 
         $items = get_items($type);
-        $sanitizedDB = array();
+        $out = array();
+        // $sanitizedDB = array();
         foreach($items as $item) {
 
-            $mustMatchCheck = array();
-            foreach($mustIncludeArray as $i => $mustIncludeTerm) { // pajar om Arrayen enbart har ett item???
-
-                // $mustIncludeTermCheck = $item->matches($mustIncludeTerm); // matchar inte korrekt???
-                // if ($mustIncludeTermCheck) {
-                //     $mustMatchCheck[] = array(True);
-                //     print('DEBUG TRUE added to $mustMatchCheck[] ');
-                //     print('<br>');
-                // }
-                // else {
-                //     $mustMatchCheck[] = array(False);
-                //     print('DEBUG FALSE added to $mustMatchCheck[] ');
-                //     print('<br>');
-                // }
-                // print('<br>');
+            // $mustMatchCheck = array();
+            if ($item->matches($mustExcludeArray)) {
+                    // === IF TRUE DO NOTHING ===
+            } else {
+                $result = $item->matches($canIncludeArray);
+                if($result) {
+                    $out[] = array($item, $result);
+                }
             }
+            // foreach($mustIncludeArray as $mustIncludeTerm) { // pajar om Arrayen enbart har ett item???
+
+            //     // $mustIncludeTermCheck = $item->matches($mustIncludeTerm); // matchar inte korrekt???
+            //     // if ($mustIncludeTermCheck) {
+            //     //     $mustMatchCheck[] = array(True);
+            //     //     print('DEBUG TRUE added to $mustMatchCheck[] ');
+            //     //     print('<br>');
+            //     // }
+            //     // else {
+            //     //     $mustMatchCheck[] = array(False);
+            //     //     print('DEBUG FALSE added to $mustMatchCheck[] ');
+            //     //     print('<br>');
+            //     // }
+            //     // print('<br>');
+            // }
             // print('<br>');
 
             // if (array_product($mustMatchCheck)) {
             //     $sanitizedDB[] = array($item, $mustIncludeTermCheck);
             // }
         }
-
-        $out = array();
+        // $out = array();
         // foreach ($sanitizedDB as $sanitizedItem) {
         //         if ($sanitizedItem->matches($mustExcludeArray)) {
 

From 469f322113dcfa16e91521eabef695e6db58139d Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 10:15:26 +0200
Subject: [PATCH 141/250] testing search function

---
 include/SearchPage.php | 52 ++++++++++++------------------------------
 1 file changed, 15 insertions(+), 37 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 780504a..b14bc6e 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -101,55 +101,33 @@ class SearchPage extends Page {
                 }
             }
         }
-
+        print('DEBUG $mustIncludeArray: ');
+        var_dump($mustIncludeArray)
+        print('<br>');
+        print('DEBUG $mustExcludeArray: ');
+        var_dump($mustExcludeArray)
+        print('<br>');
+        print('DEBUG $canIncludeArray: ');
+        var_dump($canIncludeArray)
+        print('<br>');
+        
         $items = get_items($type);
         $out = array();
-        // $sanitizedDB = array();
         foreach($items as $item) {
 
-            // $mustMatchCheck = array();
+            $mustMatchCheck = array();
+
             if ($item->matches($mustExcludeArray)) {
-                    // === IF TRUE DO NOTHING ===
+
+            //  === IF TRUE DO NOTHING ===
+
             } else {
                 $result = $item->matches($canIncludeArray);
                 if($result) {
                     $out[] = array($item, $result);
                 }
             }
-            // foreach($mustIncludeArray as $mustIncludeTerm) { // pajar om Arrayen enbart har ett item???
-
-            //     // $mustIncludeTermCheck = $item->matches($mustIncludeTerm); // matchar inte korrekt???
-            //     // if ($mustIncludeTermCheck) {
-            //     //     $mustMatchCheck[] = array(True);
-            //     //     print('DEBUG TRUE added to $mustMatchCheck[] ');
-            //     //     print('<br>');
-            //     // }
-            //     // else {
-            //     //     $mustMatchCheck[] = array(False);
-            //     //     print('DEBUG FALSE added to $mustMatchCheck[] ');
-            //     //     print('<br>');
-            //     // }
-            //     // print('<br>');
-            // }
-            // print('<br>');
-
-            // if (array_product($mustMatchCheck)) {
-            //     $sanitizedDB[] = array($item, $mustIncludeTermCheck);
-            // }
         }
-        // $out = array();
-        // foreach ($sanitizedDB as $sanitizedItem) {
-        //         if ($sanitizedItem->matches($mustExcludeArray)) {
-
-        //             // === IF TRUE DO NOTHING ===
-
-        //         } else {
-        //             // $result = $sanitizedItem->matches($canIncludeArray);
-        //             // if($result) {
-        //             //     $out[] = array($sanitizedItem, $result);
-        //             // }
-        //         }
-        //     }
         return $out;
     }
 

From 1a0bee19e117053eb7ab5e52ec72658efd4bf705 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 10:15:52 +0200
Subject: [PATCH 142/250] fixed typo

---
 include/SearchPage.php | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index b14bc6e..a4291f6 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -102,15 +102,15 @@ class SearchPage extends Page {
             }
         }
         print('DEBUG $mustIncludeArray: ');
-        var_dump($mustIncludeArray)
+        var_dump($mustIncludeArray);
         print('<br>');
         print('DEBUG $mustExcludeArray: ');
-        var_dump($mustExcludeArray)
+        var_dump($mustExcludeArray);
         print('<br>');
         print('DEBUG $canIncludeArray: ');
-        var_dump($canIncludeArray)
+        var_dump($canIncludeArray);
         print('<br>');
-        
+
         $items = get_items($type);
         $out = array();
         foreach($items as $item) {

From eaf81a19cb3b8f7e91b63110d0906c9150b4b9a0 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 10:24:43 +0200
Subject: [PATCH 143/250] testing search function

---
 include/SearchPage.php | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index a4291f6..9f28235 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -86,14 +86,14 @@ class SearchPage extends Page {
                 switch ($parsedTerm[0]) {
                     case "+":
                         // gör $mustIncludeArray till en array av arrayer?
-                        $mustIncludeArray[$key] = substr($parsedTerm, 1);
+                        $mustIncludeArray[$key] = array($key => substr($parsedTerm, 1));
                         break;
                     case "!":
                     case "-":
-                        $mustExcludeArray[$key] = substr($parsedTerm, 1);
+                        $mustExcludeArray = array($key => substr($parsedTerm, 1));
                         break;
                     case "~":
-                        $canIncludeArray[$key] = substr($parsedTerm, 1);
+                        $canIncludeArray[$key] = array($key => substr($parsedTerm, 1));
                         break;
                     default:
                         $canIncludeArray[$key] = $parsedTerm;
@@ -113,21 +113,21 @@ class SearchPage extends Page {
 
         $items = get_items($type);
         $out = array();
-        foreach($items as $item) {
+        // foreach($items as $item) {
 
-            $mustMatchCheck = array();
+        //     $mustMatchCheck = array();
 
-            if ($item->matches($mustExcludeArray)) {
+        //     if ($item->matches($mustExcludeArray)) {
 
-            //  === IF TRUE DO NOTHING ===
+        //     //  === IF TRUE DO NOTHING ===
 
-            } else {
-                $result = $item->matches($canIncludeArray);
-                if($result) {
-                    $out[] = array($item, $result);
-                }
-            }
-        }
+        //     } else {
+        //         $result = $item->matches($canIncludeArray);
+        //         if($result) {
+        //             $out[] = array($item, $result);
+        //         }
+        //     }
+        // }
         return $out;
     }
 

From dad9200ffc70d50eabfa8d33a1871c554e855d1c Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 10:26:06 +0200
Subject: [PATCH 144/250] testing search function

---
 include/SearchPage.php | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 9f28235..50b6825 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -86,17 +86,17 @@ class SearchPage extends Page {
                 switch ($parsedTerm[0]) {
                     case "+":
                         // gör $mustIncludeArray till en array av arrayer?
-                        $mustIncludeArray[$key] = array($key => substr($parsedTerm, 1));
+                        $mustIncludeArray[] = array($key => substr($parsedTerm, 1));
                         break;
                     case "!":
                     case "-":
-                        $mustExcludeArray = array($key => substr($parsedTerm, 1));
+                        $mustExcludeArray[] = array($key => substr($parsedTerm, 1));
                         break;
                     case "~":
-                        $canIncludeArray[$key] = array($key => substr($parsedTerm, 1));
+                        $canIncludeArray[] = array($key => substr($parsedTerm, 1));
                         break;
                     default:
-                        $canIncludeArray[$key] = $parsedTerm;
+                        $canIncludeArray[] = array($key => $parsedTerm);
                         break;
                 }
             }

From 4b6af75547ca4c627f90061f6408399b2a61ca4d Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 10:28:40 +0200
Subject: [PATCH 145/250] testing search function

---
 include/SearchPage.php | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 50b6825..2be498a 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -113,21 +113,24 @@ class SearchPage extends Page {
 
         $items = get_items($type);
         $out = array();
-        // foreach($items as $item) {
+        foreach($items as $item) {
 
-        //     $mustMatchCheck = array();
+            $mustMatchCheck = array();
+            foreach($mustExcludeArray as $mustExcludeTerm) {
+                if ($item->matches($mustExcludeTerm)) {
 
-        //     if ($item->matches($mustExcludeArray)) {
+                //  === IF TRUE DO NOTHING ===
 
-        //     //  === IF TRUE DO NOTHING ===
-
-        //     } else {
-        //         $result = $item->matches($canIncludeArray);
-        //         if($result) {
-        //             $out[] = array($item, $result);
-        //         }
-        //     }
-        // }
+                } else {
+                    foreach ($canIncludeArray as $canIncludeTerm) {                    
+                        $result = $item->matches($canIncludeTerm);
+                        if($result) {
+                            $out[] = array($item, $result);
+                        }
+                    }
+                }
+            }
+        }
         return $out;
     }
 

From a3b720eaba4d731cd86e6ddcf2066f2c12a317f4 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 10:35:19 +0200
Subject: [PATCH 146/250] testing search function

---
 include/SearchPage.php | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 2be498a..f5dbdeb 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -110,23 +110,44 @@ class SearchPage extends Page {
         print('DEBUG $canIncludeArray: ');
         var_dump($canIncludeArray);
         print('<br>');
+        print('<br>');
 
         $items = get_items($type);
         $out = array();
         foreach($items as $item) {
 
-            $mustMatchCheck = array();
+            // $mustIncludeCheck = array();
+            // foreach($mustIncludeArray as $mustIncludeTerm) {
+            //     if ($item->matches($mustIncludeTerm)) {
+            //         $mustIncludeCheck[] = False
+            //     } else {
+            //         $mustIncludeCheck[] = True
+            //     }
+            // }
+
+            $mustExcludeCheck = array();
             foreach($mustExcludeArray as $mustExcludeTerm) {
                 if ($item->matches($mustExcludeTerm)) {
+                    $mustExcludeCheck[] = False
+                    print('Added FALSE to $mustExcludeCheck[]<br>');
+                } else {
+                    $mustExcludeCheck[] = True
+                    print('Added TRUE to $mustExcludeCheck[]<br>');
+                }
+                print('DEBUG $mustExcludeCheck: ');
+                var_dump($mustExcludeCheck);
+                print('<br>');
+                print('<br>');
+            }
+            if ($mustExcludeCheck) {
 
                 //  === IF TRUE DO NOTHING ===
 
-                } else {
-                    foreach ($canIncludeArray as $canIncludeTerm) {                    
-                        $result = $item->matches($canIncludeTerm);
-                        if($result) {
-                            $out[] = array($item, $result);
-                        }
+            } else {
+                foreach ($canIncludeArray as $canIncludeTerm) {                    
+                    $result = $item->matches($canIncludeTerm);
+                    if($result) {
+                        $out[] = array($item, $result);
                     }
                 }
             }

From 4a6e62d89810b6b1d641048602458373fd323ca5 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 10:36:07 +0200
Subject: [PATCH 147/250] fixed typo

---
 include/SearchPage.php | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index f5dbdeb..c405216 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -119,19 +119,19 @@ class SearchPage extends Page {
             // $mustIncludeCheck = array();
             // foreach($mustIncludeArray as $mustIncludeTerm) {
             //     if ($item->matches($mustIncludeTerm)) {
-            //         $mustIncludeCheck[] = False
+            //         $mustIncludeCheck[] = False;
             //     } else {
-            //         $mustIncludeCheck[] = True
+            //         $mustIncludeCheck[] = True;
             //     }
             // }
 
             $mustExcludeCheck = array();
             foreach($mustExcludeArray as $mustExcludeTerm) {
                 if ($item->matches($mustExcludeTerm)) {
-                    $mustExcludeCheck[] = False
+                    $mustExcludeCheck[] = False;
                     print('Added FALSE to $mustExcludeCheck[]<br>');
                 } else {
-                    $mustExcludeCheck[] = True
+                    $mustExcludeCheck[] = True;
                     print('Added TRUE to $mustExcludeCheck[]<br>');
                 }
                 print('DEBUG $mustExcludeCheck: ');

From c4318c03332e503c80b1d5d9aafe1ea72b5f1b3b Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 10:42:16 +0200
Subject: [PATCH 148/250] testing search function

---
 include/SearchPage.php | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index c405216..f0a3ede 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -134,23 +134,26 @@ class SearchPage extends Page {
                     $mustExcludeCheck[] = True;
                     print('Added TRUE to $mustExcludeCheck[]<br>');
                 }
+                print('DEBUG $item: ');
+                var_dump($item);
+                print('<br>');
                 print('DEBUG $mustExcludeCheck: ');
                 var_dump($mustExcludeCheck);
                 print('<br>');
                 print('<br>');
             }
-            if ($mustExcludeCheck) {
+            // if ($mustExcludeCheck) {
 
-                //  === IF TRUE DO NOTHING ===
+            //     //  === IF TRUE DO NOTHING ===
 
-            } else {
-                foreach ($canIncludeArray as $canIncludeTerm) {                    
-                    $result = $item->matches($canIncludeTerm);
-                    if($result) {
-                        $out[] = array($item, $result);
-                    }
-                }
-            }
+            // } else {
+            //     foreach ($canIncludeArray as $canIncludeTerm) {                    
+            //         $result = $item->matches($canIncludeTerm);
+            //         if($result) {
+            //             $out[] = array($item, $result);
+            //         }
+            //     }
+            // }
         }
         return $out;
     }

From 8cda27560a73d794e7cf453486e200c11c7b25f3 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 10:50:50 +0200
Subject: [PATCH 149/250] testing search function

---
 include/SearchPage.php | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index f0a3ede..268bc2d 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -129,10 +129,14 @@ class SearchPage extends Page {
             foreach($mustExcludeArray as $mustExcludeTerm) {
                 if ($item->matches($mustExcludeTerm)) {
                     $mustExcludeCheck[] = False;
-                    print('Added FALSE to $mustExcludeCheck[]<br>');
+                    print('Added FALSE to $mustExcludeCheck[] because of maching ');
+                    print('$mustExcludeTerm');
+                    print('<br>');
                 } else {
                     $mustExcludeCheck[] = True;
-                    print('Added TRUE to $mustExcludeCheck[]<br>');
+                    print('Added TRUE to $mustExcludeCheck[] because of not maching ');
+                    print('$mustExcludeTerm');
+                    print('<br>');
                 }
                 print('DEBUG $item: ');
                 var_dump($item);

From 8ec74b09c715ae139ea4919cb7fb8de44fdb4a5c Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 11:06:43 +0200
Subject: [PATCH 150/250] testing search function

---
 include/SearchPage.php | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 268bc2d..f4e19c9 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -141,23 +141,24 @@ class SearchPage extends Page {
                 print('DEBUG $item: ');
                 var_dump($item);
                 print('<br>');
-                print('DEBUG $mustExcludeCheck: ');
-                var_dump($mustExcludeCheck);
-                print('<br>');
                 print('<br>');
             }
-            // if ($mustExcludeCheck) {
+            print('DEBUG $mustExcludeCheck: ');
+            var_dump($mustExcludeCheck);
+            print('<br>');
 
-            //     //  === IF TRUE DO NOTHING ===
+            if ($mustExcludeCheck) {
 
-            // } else {
-            //     foreach ($canIncludeArray as $canIncludeTerm) {                    
-            //         $result = $item->matches($canIncludeTerm);
-            //         if($result) {
-            //             $out[] = array($item, $result);
-            //         }
-            //     }
-            // }
+                //  === IF TRUE DO NOTHING ===
+
+            } else {
+                foreach ($canIncludeArray as $canIncludeTerm) {                    
+                    $result = $item->matches($canIncludeTerm);
+                    if($result) {
+                        $out[] = array($item, $result);
+                    }
+                }
+            }
         }
         return $out;
     }

From e8829577469d8b8f7095bb8e8e409c4304496c7c Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 11:07:43 +0200
Subject: [PATCH 151/250] fixed typo

---
 include/SearchPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index f4e19c9..d111fb6 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -130,12 +130,12 @@ class SearchPage extends Page {
                 if ($item->matches($mustExcludeTerm)) {
                     $mustExcludeCheck[] = False;
                     print('Added FALSE to $mustExcludeCheck[] because of maching ');
-                    print('$mustExcludeTerm');
+                    print($mustExcludeTerm);
                     print('<br>');
                 } else {
                     $mustExcludeCheck[] = True;
                     print('Added TRUE to $mustExcludeCheck[] because of not maching ');
-                    print('$mustExcludeTerm');
+                    print($mustExcludeTerm);
                     print('<br>');
                 }
                 print('DEBUG $item: ');

From aeb9533e22cfbecbf6c6e80b47755abda2a88227 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 11:08:40 +0200
Subject: [PATCH 152/250] testing search function

---
 include/SearchPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index d111fb6..cf3cdc7 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -130,12 +130,12 @@ class SearchPage extends Page {
                 if ($item->matches($mustExcludeTerm)) {
                     $mustExcludeCheck[] = False;
                     print('Added FALSE to $mustExcludeCheck[] because of maching ');
-                    print($mustExcludeTerm);
+                    var_dump($mustExcludeTerm);
                     print('<br>');
                 } else {
                     $mustExcludeCheck[] = True;
                     print('Added TRUE to $mustExcludeCheck[] because of not maching ');
-                    print($mustExcludeTerm);
+                    var_dump($mustExcludeTerm);
                     print('<br>');
                 }
                 print('DEBUG $item: ');

From 3b52c1310473a55bf6d66db6c13f06698460f626 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 11:11:04 +0200
Subject: [PATCH 153/250] cleaned up debug output

---
 include/SearchPage.php | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index cf3cdc7..7f4b336 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -138,14 +138,14 @@ class SearchPage extends Page {
                     var_dump($mustExcludeTerm);
                     print('<br>');
                 }
-                print('DEBUG $item: ');
-                var_dump($item);
-                print('<br>');
-                print('<br>');
             }
             print('DEBUG $mustExcludeCheck: ');
             var_dump($mustExcludeCheck);
             print('<br>');
+            print('DEBUG $item: ');
+            var_dump($item);
+            print('<br>');
+            print('<br>');
 
             if ($mustExcludeCheck) {
 

From f7fa9e77aa3ec3f25c91f85a2639091572854d57 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 11:14:25 +0200
Subject: [PATCH 154/250] testing search function

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 7f4b336..ef66d6b 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -147,7 +147,7 @@ class SearchPage extends Page {
             print('<br>');
             print('<br>');
 
-            if ($mustExcludeCheck) {
+            if (in_array(False, $mustExcludeCheck, True) === False) {
 
                 //  === IF TRUE DO NOTHING ===
 

From fdfd94c4842ffc2a056b7dd3aff1ff924c951b77 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 11:15:01 +0200
Subject: [PATCH 155/250] fixed typo

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index ef66d6b..e8f38f8 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -147,7 +147,7 @@ class SearchPage extends Page {
             print('<br>');
             print('<br>');
 
-            if (in_array(False, $mustExcludeCheck, True) === False) {
+            if (in_array(False, $mustExcludeCheck, True) === True) {
 
                 //  === IF TRUE DO NOTHING ===
 

From 29678534f3841b54405cf34123535e0979c9dad2 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 11:40:48 +0200
Subject: [PATCH 156/250] testing new stuff

---
 include/SearchPage.php | 59 +++++++++++++++++++-----------------------
 1 file changed, 27 insertions(+), 32 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index e8f38f8..5570e4a 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -87,6 +87,10 @@ class SearchPage extends Page {
                     case "+":
                         // gör $mustIncludeArray till en array av arrayer?
                         $mustIncludeArray[] = array($key => substr($parsedTerm, 1));
+                        if (!in_array($key, $mustIncludeArray)) {
+                            $mustIncludeArray[$key] = array();
+                        }
+                        $mustIncludeArray[$key][] = substr($parsedTerm, 1);
                         break;
                     case "!":
                     case "-":
@@ -101,27 +105,22 @@ class SearchPage extends Page {
                 }
             }
         }
-        print('DEBUG $mustIncludeArray: ');
-        var_dump($mustIncludeArray);
-        print('<br>');
-        print('DEBUG $mustExcludeArray: ');
-        var_dump($mustExcludeArray);
-        print('<br>');
-        print('DEBUG $canIncludeArray: ');
-        var_dump($canIncludeArray);
-        print('<br>');
-        print('<br>');
 
         $items = get_items($type);
         $out = array();
         foreach($items as $item) {
 
+            print('<br>');
+            $mustMatch = $item->matches($mustIncludeArray);
+            var_dump($mustMatch);
+            print('<br>');
+
             // $mustIncludeCheck = array();
             // foreach($mustIncludeArray as $mustIncludeTerm) {
             //     if ($item->matches($mustIncludeTerm)) {
-            //         $mustIncludeCheck[] = False;
-            //     } else {
             //         $mustIncludeCheck[] = True;
+            //     } else {
+            //         $mustIncludeCheck[] = False;
             //     }
             // }
 
@@ -129,36 +128,32 @@ class SearchPage extends Page {
             foreach($mustExcludeArray as $mustExcludeTerm) {
                 if ($item->matches($mustExcludeTerm)) {
                     $mustExcludeCheck[] = False;
-                    print('Added FALSE to $mustExcludeCheck[] because of maching ');
-                    var_dump($mustExcludeTerm);
-                    print('<br>');
                 } else {
                     $mustExcludeCheck[] = True;
-                    print('Added TRUE to $mustExcludeCheck[] because of not maching ');
-                    var_dump($mustExcludeTerm);
-                    print('<br>');
                 }
             }
-            print('DEBUG $mustExcludeCheck: ');
-            var_dump($mustExcludeCheck);
-            print('<br>');
-            print('DEBUG $item: ');
-            var_dump($item);
-            print('<br>');
-            print('<br>');
 
-            if (in_array(False, $mustExcludeCheck, True) === True) {
+            if (in_array(False, $mustIncludeCheck, True) === False) {
+                if (in_array(False, $mustExcludeCheck, True) === True) {
 
-                //  === IF TRUE DO NOTHING ===
+                    //  === IF TRUE DO NOTHING ===
 
-            } else {
-                foreach ($canIncludeArray as $canIncludeTerm) {                    
-                    $result = $item->matches($canIncludeTerm);
-                    if($result) {
-                        $out[] = array($item, $result);
+                } else {
+                    foreach ($canIncludeArray as $canIncludeTerm) {                    
+                        $result = $item->matches($canIncludeTerm);
+                        if($result) {
+                            $out[] = array($item, $result);
+                        }
                     }
                 }
             }
+            else if () {
+
+
+            }
+            else {
+
+            }
         }
         return $out;
     }

From 7079ba508a38e8fe604e552d8a8680ee0ee4668b Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 11:42:09 +0200
Subject: [PATCH 157/250] fixed typo

---
 include/SearchPage.php | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 5570e4a..621b577 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -86,7 +86,7 @@ class SearchPage extends Page {
                 switch ($parsedTerm[0]) {
                     case "+":
                         // gör $mustIncludeArray till en array av arrayer?
-                        $mustIncludeArray[] = array($key => substr($parsedTerm, 1));
+                        // $mustIncludeArray[] = array($key => substr($parsedTerm, 1));
                         if (!in_array($key, $mustIncludeArray)) {
                             $mustIncludeArray[$key] = array();
                         }
@@ -133,27 +133,27 @@ class SearchPage extends Page {
                 }
             }
 
-            if (in_array(False, $mustIncludeCheck, True) === False) {
-                if (in_array(False, $mustExcludeCheck, True) === True) {
+            // if (in_array(False, $mustIncludeCheck, True) === False) {
+            //     if (in_array(False, $mustExcludeCheck, True) === True) {
 
-                    //  === IF TRUE DO NOTHING ===
+            //         //  === IF TRUE DO NOTHING ===
 
-                } else {
-                    foreach ($canIncludeArray as $canIncludeTerm) {                    
-                        $result = $item->matches($canIncludeTerm);
-                        if($result) {
-                            $out[] = array($item, $result);
-                        }
-                    }
-                }
-            }
-            else if () {
+            //     } else {
+            //         foreach ($canIncludeArray as $canIncludeTerm) {                    
+            //             $result = $item->matches($canIncludeTerm);
+            //             if($result) {
+            //                 $out[] = array($item, $result);
+            //             }
+            //         }
+            //     }
+            // }
+            // else if (True) {
 
 
-            }
-            else {
+            // }
+            // else {
 
-            }
+            // }
         }
         return $out;
     }

From 4976b58f84af53b757c240088c7786f896474976 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 11:47:16 +0200
Subject: [PATCH 158/250] tesing search function

---
 include/SearchPage.php | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 621b577..d278bec 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -85,8 +85,6 @@ class SearchPage extends Page {
 
                 switch ($parsedTerm[0]) {
                     case "+":
-                        // gör $mustIncludeArray till en array av arrayer?
-                        // $mustIncludeArray[] = array($key => substr($parsedTerm, 1));
                         if (!in_array($key, $mustIncludeArray)) {
                             $mustIncludeArray[$key] = array();
                         }
@@ -94,12 +92,21 @@ class SearchPage extends Page {
                         break;
                     case "!":
                     case "-":
+                        if (!in_array($key, $mustExcludeArray)) {
+                            $mustExcludeArray[$key] = array();
+                        }
                         $mustExcludeArray[] = array($key => substr($parsedTerm, 1));
                         break;
                     case "~":
+                        if (!in_array($key, $canIncludeArray)) {
+                            $canIncludeArray[$key] = array();
+                        }
                         $canIncludeArray[] = array($key => substr($parsedTerm, 1));
                         break;
                     default:
+                        if (!in_array($key, $canIncludeArray)) {
+                            $canIncludeArray[$key] = array();
+                        }
                         $canIncludeArray[] = array($key => $parsedTerm);
                         break;
                 }
@@ -110,11 +117,15 @@ class SearchPage extends Page {
         $out = array();
         foreach($items as $item) {
 
+            print('<br>');
+            print($item["name"]);
             print('<br>');
             $mustMatch = $item->matches($mustIncludeArray);
             var_dump($mustMatch);
             print('<br>');
 
+
+
             // $mustIncludeCheck = array();
             // foreach($mustIncludeArray as $mustIncludeTerm) {
             //     if ($item->matches($mustIncludeTerm)) {
@@ -124,14 +135,14 @@ class SearchPage extends Page {
             //     }
             // }
 
-            $mustExcludeCheck = array();
-            foreach($mustExcludeArray as $mustExcludeTerm) {
-                if ($item->matches($mustExcludeTerm)) {
-                    $mustExcludeCheck[] = False;
-                } else {
-                    $mustExcludeCheck[] = True;
-                }
-            }
+            // $mustExcludeCheck = array();
+            // foreach($mustExcludeArray as $mustExcludeTerm) {
+            //     if ($item->matches($mustExcludeTerm)) {
+            //         $mustExcludeCheck[] = False;
+            //     } else {
+            //         $mustExcludeCheck[] = True;
+            //     }
+            // }
 
             // if (in_array(False, $mustIncludeCheck, True) === False) {
             //     if (in_array(False, $mustExcludeCheck, True) === True) {

From 41df4f647692e860bed68d0b23a777f64339b996 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 11:47:46 +0200
Subject: [PATCH 159/250] fixing typo

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index d278bec..86d64e7 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -118,7 +118,7 @@ class SearchPage extends Page {
         foreach($items as $item) {
 
             print('<br>');
-            print($item["name"]);
+            var_dump($item);
             print('<br>');
             $mustMatch = $item->matches($mustIncludeArray);
             var_dump($mustMatch);

From de9dee7374be7d8edc62da9fa7f1010e07570f63 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 11:48:52 +0200
Subject: [PATCH 160/250] fixed debug output

---
 include/SearchPage.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 86d64e7..4e62734 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -117,10 +117,11 @@ class SearchPage extends Page {
         $out = array();
         foreach($items as $item) {
 
-            print('<br>');
+            print('DEBUG $item: ');
             var_dump($item);
             print('<br>');
             $mustMatch = $item->matches($mustIncludeArray);
+            print('DEBUG matchresult of $mustMatch: ');
             var_dump($mustMatch);
             print('<br>');
 

From 7d99899acdeb74a8a8613a24df95cd49526153b2 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 11:49:17 +0200
Subject: [PATCH 161/250] fixed typo

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 4e62734..1f8e45b 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -124,7 +124,7 @@ class SearchPage extends Page {
             print('DEBUG matchresult of $mustMatch: ');
             var_dump($mustMatch);
             print('<br>');
-
+            print('<br>');
 
 
             // $mustIncludeCheck = array();

From b9b37e07dd0dbf701cbd07a4af7a4f26cd1edded Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 11:51:27 +0200
Subject: [PATCH 162/250] testing search function

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 1f8e45b..8cc5665 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -118,7 +118,7 @@ class SearchPage extends Page {
         foreach($items as $item) {
 
             print('DEBUG $item: ');
-            var_dump($item);
+            var_dump($item->get_name());
             print('<br>');
             $mustMatch = $item->matches($mustIncludeArray);
             print('DEBUG matchresult of $mustMatch: ');

From 336b170aa305b88f1f3c0a2d36483928afc6eae8 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 15:41:42 +0200
Subject: [PATCH 163/250] testing search function

---
 include/SearchPage.php | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 8cc5665..2b08012 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -113,6 +113,10 @@ class SearchPage extends Page {
             }
         }
 
+        print('DEBUG result of $mustIncludeArray: ');
+        var_dump($mustIncludeArray);
+        print('<br>');
+
         $items = get_items($type);
         $out = array();
         foreach($items as $item) {
@@ -127,6 +131,24 @@ class SearchPage extends Page {
             print('<br>');
 
 
+            /* ============
+
+            if () {
+                
+                
+                
+
+            }
+            else if () {
+    
+                
+
+            }
+            else
+
+
+            */ 
+
             // $mustIncludeCheck = array();
             // foreach($mustIncludeArray as $mustIncludeTerm) {
             //     if ($item->matches($mustIncludeTerm)) {
@@ -159,13 +181,6 @@ class SearchPage extends Page {
             //         }
             //     }
             // }
-            // else if (True) {
-
-
-            // }
-            // else {
-
-            // }
         }
         return $out;
     }

From d9feba187d44684af02b73417de051d7c04ad41f Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 15:44:06 +0200
Subject: [PATCH 164/250] testing search function

---
 include/SearchPage.php | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 2b08012..5193fa2 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -85,26 +85,26 @@ class SearchPage extends Page {
 
                 switch ($parsedTerm[0]) {
                     case "+":
-                        if (!in_array($key, $mustIncludeArray)) {
+                        if (!array_key_exists($key, $mustIncludeArray)) {
                             $mustIncludeArray[$key] = array();
                         }
                         $mustIncludeArray[$key][] = substr($parsedTerm, 1);
                         break;
                     case "!":
                     case "-":
-                        if (!in_array($key, $mustExcludeArray)) {
+                        if (!array_key_exists($key, $mustExcludeArray)) {
                             $mustExcludeArray[$key] = array();
                         }
                         $mustExcludeArray[] = array($key => substr($parsedTerm, 1));
                         break;
                     case "~":
-                        if (!in_array($key, $canIncludeArray)) {
+                        if (!array_key_exists($key, $canIncludeArray)) {
                             $canIncludeArray[$key] = array();
                         }
                         $canIncludeArray[] = array($key => substr($parsedTerm, 1));
                         break;
                     default:
-                        if (!in_array($key, $canIncludeArray)) {
+                        if (!array_key_exists($key, $canIncludeArray)) {
                             $canIncludeArray[$key] = array();
                         }
                         $canIncludeArray[] = array($key => $parsedTerm);
@@ -116,6 +116,7 @@ class SearchPage extends Page {
         print('DEBUG result of $mustIncludeArray: ');
         var_dump($mustIncludeArray);
         print('<br>');
+        print('<br>');
 
         $items = get_items($type);
         $out = array();

From 0c74d97e9643236b075339780052490faa3e8485 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 16:07:04 +0200
Subject: [PATCH 165/250] testing search function

---
 include/SearchPage.php | 77 +++++++++++++++++-------------------------
 1 file changed, 31 insertions(+), 46 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 5193fa2..d62c8d3 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -62,76 +62,50 @@ class SearchPage extends Page {
         ==================================================
         */
 
-
-        /*
-        ==================================================
-        
-        $terms = array av arrayer
-        $term = array(key, parsedTerm)
-        $key = e.g. "Fritext", "Tag", etc
-        $parsedTerm = e.g. "c426", "Dell"
-        $value = någon form av key
-        $type = users, products
-
-        ==================================================
-        */
-
-        $mustIncludeArray = array(); 
-        $mustExcludeArray = array(); 
-        $canIncludeArray = array();
+        $mustMatchArray = array(); 
+        $cannotMatchArray = array(); 
+        $mayMatchArray = array();
 
         foreach($terms as $key => $term) {
             foreach($term as $value => $parsedTerm) {
 
                 switch ($parsedTerm[0]) {
                     case "+":
-                        if (!array_key_exists($key, $mustIncludeArray)) {
-                            $mustIncludeArray[$key] = array();
+                        if (!array_key_exists($key, $mustMatchArray)) {
+                            $mustMatchArray[$key] = array();
                         }
-                        $mustIncludeArray[$key][] = substr($parsedTerm, 1);
+                        $mustMatchArray[$key][] = substr($parsedTerm, 1);
                         break;
                     case "!":
                     case "-":
-                        if (!array_key_exists($key, $mustExcludeArray)) {
-                            $mustExcludeArray[$key] = array();
+                        if (!array_key_exists($key, $cannotMatchArray)) {
+                            $cannotMatchArray[$key] = array();
                         }
-                        $mustExcludeArray[] = array($key => substr($parsedTerm, 1));
+                        $cannotMatchArray[] = array($key => substr($parsedTerm, 1));
                         break;
                     case "~":
-                        if (!array_key_exists($key, $canIncludeArray)) {
-                            $canIncludeArray[$key] = array();
+                        if (!array_key_exists($key, $mayMatchArray)) {
+                            $mayMatchArray[$key] = array();
                         }
-                        $canIncludeArray[] = array($key => substr($parsedTerm, 1));
+                        $mayMatchArray[] = array($key => substr($parsedTerm, 1));
                         break;
                     default:
-                        if (!array_key_exists($key, $canIncludeArray)) {
-                            $canIncludeArray[$key] = array();
+                        if (!array_key_exists($key, $mayMatchArray)) {
+                            $mayMatchArray[$key] = array();
                         }
-                        $canIncludeArray[] = array($key => $parsedTerm);
+                        $mayMatchArray[] = array($key => $parsedTerm);
                         break;
                 }
             }
         }
 
-        print('DEBUG result of $mustIncludeArray: ');
-        var_dump($mustIncludeArray);
-        print('<br>');
-        print('<br>');
-
         $items = get_items($type);
-        $out = array();
+        $sanitizedItems = array();
         foreach($items as $item) {
-
-            print('DEBUG $item: ');
-            var_dump($item->get_name());
-            print('<br>');
-            $mustMatch = $item->matches($mustIncludeArray);
-            print('DEBUG matchresult of $mustMatch: ');
-            var_dump($mustMatch);
-            print('<br>');
-            print('<br>');
-
-
+            $mustMatch = $item->matches($mustMatchArray);
+            if($mustMatch) {
+                $sanitizedItems[] = array($item, $mustMatch);
+            }
             /* ============
 
             if () {
@@ -183,6 +157,17 @@ class SearchPage extends Page {
             //     }
             // }
         }
+
+
+        $out = array();
+        foreach($sanitizedItems as $sanitizedItem) {
+            print('DEBUG $sanitizedItem: ');
+            var_dump($sanitizedItem)
+            print('<br>');
+
+        }
+        print('<br>');
+
         return $out;
     }
 

From 9bffde6072f80de0e68d5b4b895daa79cf96edad Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 16:07:25 +0200
Subject: [PATCH 166/250] fixed typo

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index d62c8d3..8ffbfba 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -162,7 +162,7 @@ class SearchPage extends Page {
         $out = array();
         foreach($sanitizedItems as $sanitizedItem) {
             print('DEBUG $sanitizedItem: ');
-            var_dump($sanitizedItem)
+            var_dump($sanitizedItem);
             print('<br>');
 
         }

From e2bbcc2d19789510fc1480fe9fc557c2793a730e Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 16:08:11 +0200
Subject: [PATCH 167/250] cleaned up debug printout

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 8ffbfba..013ce8d 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -162,7 +162,7 @@ class SearchPage extends Page {
         $out = array();
         foreach($sanitizedItems as $sanitizedItem) {
             print('DEBUG $sanitizedItem: ');
-            var_dump($sanitizedItem);
+            var_dump($sanitizedItem->get_name());
             print('<br>');
 
         }

From 2ad2fb1a7a742c19fed1741586965b8424f3821c Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 16:10:38 +0200
Subject: [PATCH 168/250] fixed typo

---
 include/SearchPage.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 013ce8d..a22b8b4 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -161,9 +161,10 @@ class SearchPage extends Page {
 
         $out = array();
         foreach($sanitizedItems as $sanitizedItem) {
-            print('DEBUG $sanitizedItem: ');
+            print('DEBUG $sanitizedItem->get_name(): ');
             var_dump($sanitizedItem->get_name());
             print('<br>');
+            print('<br>');
 
         }
         print('<br>');

From df90e48b092eb2613336db81eeebcb15494842cc Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 16:13:48 +0200
Subject: [PATCH 169/250] testing search function

---
 include/SearchPage.php | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index a22b8b4..dc17fbf 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -157,18 +157,17 @@ class SearchPage extends Page {
             //     }
             // }
         }
+        print('DEBUG $sanitizedItems: ');
+        var_dump($sanitizedItems);
+        print('<br><br>');
 
 
         $out = array();
-        foreach($sanitizedItems as $sanitizedItem) {
-            print('DEBUG $sanitizedItem->get_name(): ');
-            var_dump($sanitizedItem->get_name());
-            print('<br>');
-            print('<br>');
-
-        }
-        print('<br>');
-
+        // foreach($sanitizedItems as $sanitizedItem) {
+        //     print('DEBUG $sanitizedItem->get_name(): ');
+        //     var_dump($sanitizedItem->get_name());
+        //     print('<br><br>');
+        // }
         return $out;
     }
 

From c24d0cee8d63ac8d8a9510af12f28363931be90e Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 16:14:23 +0200
Subject: [PATCH 170/250] testing search function

---
 include/SearchPage.php | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index dc17fbf..e62fdce 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -157,17 +157,17 @@ class SearchPage extends Page {
             //     }
             // }
         }
-        print('DEBUG $sanitizedItems: ');
-        var_dump($sanitizedItems);
-        print('<br><br>');
+        // print('DEBUG $sanitizedItems: ');
+        // var_dump($sanitizedItems);
+        // print('<br><br>');
 
 
         $out = array();
-        // foreach($sanitizedItems as $sanitizedItem) {
-        //     print('DEBUG $sanitizedItem->get_name(): ');
-        //     var_dump($sanitizedItem->get_name());
-        //     print('<br><br>');
-        // }
+        foreach($sanitizedItems as $sanitizedItem) {
+            print('DEBUG $sanitizedItem->get_name(): ');
+            var_dump($sanitizedItem->get_name());
+            print('<br><br>');
+        }
         return $out;
     }
 

From 40379061df7655b3c6b965ed66453a5d066d2fce Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 16:15:29 +0200
Subject: [PATCH 171/250] testing search function

---
 include/SearchPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index e62fdce..cc87f75 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -164,8 +164,8 @@ class SearchPage extends Page {
 
         $out = array();
         foreach($sanitizedItems as $sanitizedItem) {
-            print('DEBUG $sanitizedItem->get_name(): ');
-            var_dump($sanitizedItem->get_name());
+            print('DEBUG $sanitizedItem: ');
+            var_dump($sanitizedItem);
             print('<br><br>');
         }
         return $out;

From dc3cd3251bae8defd5fafcc02e8ff8f9b1361139 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 17:00:03 +0200
Subject: [PATCH 172/250] search function testing

---
 include/SearchPage.php | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index cc87f75..2cbb9d6 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -103,27 +103,18 @@ class SearchPage extends Page {
         $sanitizedItems = array();
         foreach($items as $item) {
             $mustMatch = $item->matches($mustMatchArray);
-            if($mustMatch) {
+
+            $mustMatchCheck = array();
+            foreach($mustIncludeArray as $mustIncludeTerm) {
+                if (array_key_exists($mustIncludeTerm, $mustMatchCheck)) {
+                    $mustMatchCheck[] = True;
+                } else {
+                    $mustMatchCheck[] = False;
+                }
+            }
+            if(in_array(False, $mustIncludeCheck, True) === False) {
                 $sanitizedItems[] = array($item, $mustMatch);
             }
-            /* ============
-
-            if () {
-                
-                
-                
-
-            }
-            else if () {
-    
-                
-
-            }
-            else
-
-
-            */ 
-
             // $mustIncludeCheck = array();
             // foreach($mustIncludeArray as $mustIncludeTerm) {
             //     if ($item->matches($mustIncludeTerm)) {

From 976ca1cfaac92e494e2831e2614c7be4d4bf4a8e Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 17:02:54 +0200
Subject: [PATCH 173/250] testing search function

---
 include/SearchPage.php | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 2cbb9d6..9ee2d94 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -108,10 +108,16 @@ class SearchPage extends Page {
             foreach($mustIncludeArray as $mustIncludeTerm) {
                 if (array_key_exists($mustIncludeTerm, $mustMatchCheck)) {
                     $mustMatchCheck[] = True;
+                    print('DEBUG added TRUE to $mustMatchCheck[]<br>');
                 } else {
                     $mustMatchCheck[] = False;
+                    print('DEBUG added FALSE to $mustMatchCheck[]<br>');
                 }
             }
+            print('DEBUG $sanitizedItem: ');
+            var_dump($sanitizedItem);
+            print('<br><br>');
+
             if(in_array(False, $mustIncludeCheck, True) === False) {
                 $sanitizedItems[] = array($item, $mustMatch);
             }

From 51194682dbafd47d2b3d7f2ecf2684505383d74b Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 17:05:00 +0200
Subject: [PATCH 174/250] testing search function

---
 include/SearchPage.php | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 9ee2d94..9c3e3a4 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -106,7 +106,7 @@ class SearchPage extends Page {
 
             $mustMatchCheck = array();
             foreach($mustIncludeArray as $mustIncludeTerm) {
-                if (array_key_exists($mustIncludeTerm, $mustMatchCheck)) {
+                if (in_array(False, $mustMatchCheck, True) === True) {
                     $mustMatchCheck[] = True;
                     print('DEBUG added TRUE to $mustMatchCheck[]<br>');
                 } else {
@@ -114,13 +114,15 @@ class SearchPage extends Page {
                     print('DEBUG added FALSE to $mustMatchCheck[]<br>');
                 }
             }
-            print('DEBUG $sanitizedItem: ');
-            var_dump($sanitizedItem);
-            print('<br><br>');
+
 
             if(in_array(False, $mustIncludeCheck, True) === False) {
                 $sanitizedItems[] = array($item, $mustMatch);
             }
+            print('DEBUG $sanitizedItem: ');
+            var_dump($sanitizedItem);
+            print('<br><br>');
+
             // $mustIncludeCheck = array();
             // foreach($mustIncludeArray as $mustIncludeTerm) {
             //     if ($item->matches($mustIncludeTerm)) {

From d5571507e99ba1657767816b6709b7c9a736f818 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 17:06:05 +0200
Subject: [PATCH 175/250] testing search function

---
 include/SearchPage.php | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 9c3e3a4..df889ed 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -104,19 +104,7 @@ class SearchPage extends Page {
         foreach($items as $item) {
             $mustMatch = $item->matches($mustMatchArray);
 
-            $mustMatchCheck = array();
-            foreach($mustIncludeArray as $mustIncludeTerm) {
-                if (in_array(False, $mustMatchCheck, True) === True) {
-                    $mustMatchCheck[] = True;
-                    print('DEBUG added TRUE to $mustMatchCheck[]<br>');
-                } else {
-                    $mustMatchCheck[] = False;
-                    print('DEBUG added FALSE to $mustMatchCheck[]<br>');
-                }
-            }
-
-
-            if(in_array(False, $mustIncludeCheck, True) === False) {
+            if($mustMatch) {
                 $sanitizedItems[] = array($item, $mustMatch);
             }
             print('DEBUG $sanitizedItem: ');

From 165f0eee2a270da5ffd60305238b0b79a7065e82 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 17:07:28 +0200
Subject: [PATCH 176/250] fixed typos

---
 include/SearchPage.php | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index df889ed..2f7e5b8 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -107,9 +107,12 @@ class SearchPage extends Page {
             if($mustMatch) {
                 $sanitizedItems[] = array($item, $mustMatch);
             }
-            print('DEBUG $sanitizedItem: ');
-            var_dump($sanitizedItem);
-            print('<br><br>');
+
+            foreach($sanitizedItems as $sanitizedItem) {
+                print('DEBUG $sanitizedItem: ');
+                var_dump($sanitizedItem);
+                print('<br><br>');
+            }
 
             // $mustIncludeCheck = array();
             // foreach($mustIncludeArray as $mustIncludeTerm) {
@@ -150,11 +153,6 @@ class SearchPage extends Page {
 
 
         $out = array();
-        foreach($sanitizedItems as $sanitizedItem) {
-            print('DEBUG $sanitizedItem: ');
-            var_dump($sanitizedItem);
-            print('<br><br>');
-        }
         return $out;
     }
 

From bb03439acf81e46c033016264f9dd93d9bbb1b7f Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 6 Sep 2021 17:08:33 +0200
Subject: [PATCH 177/250] fixed things

---
 include/SearchPage.php | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 2f7e5b8..f274721 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -108,12 +108,6 @@ class SearchPage extends Page {
                 $sanitizedItems[] = array($item, $mustMatch);
             }
 
-            foreach($sanitizedItems as $sanitizedItem) {
-                print('DEBUG $sanitizedItem: ');
-                var_dump($sanitizedItem);
-                print('<br><br>');
-            }
-
             // $mustIncludeCheck = array();
             // foreach($mustIncludeArray as $mustIncludeTerm) {
             //     if ($item->matches($mustIncludeTerm)) {
@@ -147,10 +141,12 @@ class SearchPage extends Page {
             //     }
             // }
         }
-        // print('DEBUG $sanitizedItems: ');
-        // var_dump($sanitizedItems);
-        // print('<br><br>');
 
+        foreach($sanitizedItems as $sanitizedItem) {
+            print('DEBUG $sanitizedItem: ');
+            var_dump($sanitizedItem);
+            print('<br><br>');
+        }
 
         $out = array();
         return $out;

From a850841dbc99ed2a816cc397647c4d271dc8b2f6 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 10:26:59 +0200
Subject: [PATCH 178/250] testing search function

---
 include/SearchPage.php | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index f274721..39bafda 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -102,20 +102,22 @@ class SearchPage extends Page {
         $items = get_items($type);
         $sanitizedItems = array();
         foreach($items as $item) {
-            $mustMatch = $item->matches($mustMatchArray);
+            // $mustMatch = $item->matches($mustMatchArray);
 
-            if($mustMatch) {
-                $sanitizedItems[] = array($item, $mustMatch);
+
+            $mustMatchCheck = array();
+            foreach($mustMatchArray as $mustMatchTerm) {
+                $mustMatch = $item->matches($mustMatchTerm);
+                if ($mustMatch) {
+                    $mustMatchCheck[] = True;
+                } else {
+                    $mustMatchCheck[] = False;
+                }
             }
 
-            // $mustIncludeCheck = array();
-            // foreach($mustIncludeArray as $mustIncludeTerm) {
-            //     if ($item->matches($mustIncludeTerm)) {
-            //         $mustIncludeCheck[] = True;
-            //     } else {
-            //         $mustIncludeCheck[] = False;
-            //     }
-            // }
+            if(in_array(False, $mustMatchCheck, True) === False) {
+                $sanitizedItems[] = array($item, $mustMatch);
+            }
 
             // $mustExcludeCheck = array();
             // foreach($mustExcludeArray as $mustExcludeTerm) {
@@ -144,7 +146,7 @@ class SearchPage extends Page {
 
         foreach($sanitizedItems as $sanitizedItem) {
             print('DEBUG $sanitizedItem: ');
-            var_dump($sanitizedItem);
+            var_dump($sanitizedItem;
             print('<br><br>');
         }
 

From 3b4da1e5ddcbefc3c018d30ebbf8a94561bc13b9 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 10:29:04 +0200
Subject: [PATCH 179/250] fixed typo

---
 include/SearchPage.php | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 39bafda..f351a24 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -107,8 +107,8 @@ class SearchPage extends Page {
 
             $mustMatchCheck = array();
             foreach($mustMatchArray as $mustMatchTerm) {
-                $mustMatch = $item->matches($mustMatchTerm);
-                if ($mustMatch) {
+                $matchingResult = $item->matches($mustMatchTerm);
+                if ($matchingResult) {
                     $mustMatchCheck[] = True;
                 } else {
                     $mustMatchCheck[] = False;
@@ -116,7 +116,7 @@ class SearchPage extends Page {
             }
 
             if(in_array(False, $mustMatchCheck, True) === False) {
-                $sanitizedItems[] = array($item, $mustMatch);
+                $sanitizedItems[] = array($item);
             }
 
             // $mustExcludeCheck = array();

From 9f9fd166f603fd6b640a36c2fd5aab27f4b25ccb Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 10:30:39 +0200
Subject: [PATCH 180/250] testing search function

---
 include/SearchPage.php | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index f351a24..18469f4 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -102,21 +102,22 @@ class SearchPage extends Page {
         $items = get_items($type);
         $sanitizedItems = array();
         foreach($items as $item) {
-            // $mustMatch = $item->matches($mustMatchArray);
+            $mustMatch = $item->matches($mustMatchArray);
 
 
-            $mustMatchCheck = array();
-            foreach($mustMatchArray as $mustMatchTerm) {
-                $matchingResult = $item->matches($mustMatchTerm);
-                if ($matchingResult) {
-                    $mustMatchCheck[] = True;
-                } else {
-                    $mustMatchCheck[] = False;
-                }
-            }
+            // $mustMatchCheck = array();
+            // foreach($mustMatchArray as $mustMatchTerm) {
+
+            //     $matchingResult = $item->matches($mustMatchTerm);
+            //     if ($matchingResult) {
+            //         $mustMatchCheck[] = True;
+            //     } else {
+            //         $mustMatchCheck[] = False;
+            //     }
+            // }
 
             if(in_array(False, $mustMatchCheck, True) === False) {
-                $sanitizedItems[] = array($item);
+                $sanitizedItems[] = array($item, $mustMatch);
             }
 
             // $mustExcludeCheck = array();

From a1e187744b24dd02d0949eaee6b9660183ff7cb0 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 10:31:45 +0200
Subject: [PATCH 181/250] testing search function

---
 include/SearchPage.php | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 18469f4..b823aef 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -115,8 +115,11 @@ class SearchPage extends Page {
             //         $mustMatchCheck[] = False;
             //     }
             // }
-
-            if(in_array(False, $mustMatchCheck, True) === False) {
+            // if(in_array(False, $mustMatchCheck, True) === False) {
+            //     $sanitizedItems[] = array($item, $mustMatch);
+            // }
+            
+            if($mustMatch) {
                 $sanitizedItems[] = array($item, $mustMatch);
             }
 

From 141a3017c53edfd699517ad706b50446c218d66d Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 10:37:03 +0200
Subject: [PATCH 182/250] fixed typo

---
 include/SearchPage.php | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index b823aef..f7761c9 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -103,7 +103,9 @@ class SearchPage extends Page {
         $sanitizedItems = array();
         foreach($items as $item) {
             $mustMatch = $item->matches($mustMatchArray);
-
+            if($mustMatch) {
+                $sanitizedItems[] = array($item, $mustMatch);
+            }
 
             // $mustMatchCheck = array();
             // foreach($mustMatchArray as $mustMatchTerm) {
@@ -118,10 +120,8 @@ class SearchPage extends Page {
             // if(in_array(False, $mustMatchCheck, True) === False) {
             //     $sanitizedItems[] = array($item, $mustMatch);
             // }
+
             
-            if($mustMatch) {
-                $sanitizedItems[] = array($item, $mustMatch);
-            }
 
             // $mustExcludeCheck = array();
             // foreach($mustExcludeArray as $mustExcludeTerm) {
@@ -150,7 +150,7 @@ class SearchPage extends Page {
 
         foreach($sanitizedItems as $sanitizedItem) {
             print('DEBUG $sanitizedItem: ');
-            var_dump($sanitizedItem;
+            var_dump($sanitizedItem);
             print('<br><br>');
         }
 

From 4e6ad4f94ef783686dbea7fe4f6fbcb207d94380 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 10:38:02 +0200
Subject: [PATCH 183/250] testing search function

---
 include/SearchPage.php | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index f7761c9..3e25fc3 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -102,25 +102,25 @@ class SearchPage extends Page {
         $items = get_items($type);
         $sanitizedItems = array();
         foreach($items as $item) {
-            $mustMatch = $item->matches($mustMatchArray);
-            if($mustMatch) {
-                $sanitizedItems[] = array($item, $mustMatch);
-            }
-
-            // $mustMatchCheck = array();
-            // foreach($mustMatchArray as $mustMatchTerm) {
-
-            //     $matchingResult = $item->matches($mustMatchTerm);
-            //     if ($matchingResult) {
-            //         $mustMatchCheck[] = True;
-            //     } else {
-            //         $mustMatchCheck[] = False;
-            //     }
-            // }
-            // if(in_array(False, $mustMatchCheck, True) === False) {
+            // $mustMatch = $item->matches($mustMatchArray);
+            // if($mustMatch) {
             //     $sanitizedItems[] = array($item, $mustMatch);
             // }
 
+            $mustMatchCheck = array();
+            foreach($mustMatchArray as $mustMatchTerm) {
+
+                $matchingResult = $item->matches($mustMatchTerm);
+                if ($matchingResult) {
+                    $mustMatchCheck[] = True;
+                } else {
+                    $mustMatchCheck[] = False;
+                }
+            }
+            if(in_array(False, $mustMatchCheck, True) === False) {
+                $sanitizedItems[] = array($item, $mustMatch);
+            }
+
             
 
             // $mustExcludeCheck = array();

From 18b4267f5141c1d4177ff7c7e47f67a924ae5966 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 10:39:08 +0200
Subject: [PATCH 184/250] testing search function

---
 include/SearchPage.php | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 3e25fc3..4469353 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -110,15 +110,15 @@ class SearchPage extends Page {
             $mustMatchCheck = array();
             foreach($mustMatchArray as $mustMatchTerm) {
 
-                $matchingResult = $item->matches($mustMatchTerm);
-                if ($matchingResult) {
+                $matchResult = $item->matches($mustMatchTerm);
+                if ($matchResult) {
                     $mustMatchCheck[] = True;
                 } else {
                     $mustMatchCheck[] = False;
                 }
             }
             if(in_array(False, $mustMatchCheck, True) === False) {
-                $sanitizedItems[] = array($item, $mustMatch);
+                $sanitizedItems[] = array($item, $matchResult);
             }
 
             

From 2240fd0e04cfb97942529f9a740c0cb413ee133d Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 11:08:44 +0200
Subject: [PATCH 185/250] testing new implementation of matching function

---
 include/SearchPage.php | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 4469353..ea9d9b3 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -102,24 +102,24 @@ class SearchPage extends Page {
         $items = get_items($type);
         $sanitizedItems = array();
         foreach($items as $item) {
-            // $mustMatch = $item->matches($mustMatchArray);
-            // if($mustMatch) {
-            //     $sanitizedItems[] = array($item, $mustMatch);
+            $mustMatch = $item->matches($mustMatchArray, True);
+            if($mustMatch) {
+                $sanitizedItems[] = array($item, $mustMatch);
+            }
+
+            // $mustMatchCheck = array();
+            // foreach($mustMatchArray as $mustMatchTerm) {
+
+            //     $matchResult = $item->matches($mustMatchTerm);
+            //     if ($matchResult) {
+            //         $mustMatchCheck[] = True;
+            //     } else {
+            //         $mustMatchCheck[] = False;
+            //     }
+            // }
+            // if(in_array(False, $mustMatchCheck, True) === False) {
+            //     $sanitizedItems[] = array($item, $matchResult);
             // }
-
-            $mustMatchCheck = array();
-            foreach($mustMatchArray as $mustMatchTerm) {
-
-                $matchResult = $item->matches($mustMatchTerm);
-                if ($matchResult) {
-                    $mustMatchCheck[] = True;
-                } else {
-                    $mustMatchCheck[] = False;
-                }
-            }
-            if(in_array(False, $mustMatchCheck, True) === False) {
-                $sanitizedItems[] = array($item, $matchResult);
-            }
 
             
 

From 7166a31d99ac058651586f1a11acdc3ecda6d733 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 11:12:44 +0200
Subject: [PATCH 186/250] testing new matching functionality

---
 include/Product.php | 5 ++++-
 include/User.php    | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/include/Product.php b/include/Product.php
index c4f342b..d84ec1d 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -110,7 +110,7 @@ class Product extends Entity {
         return true;
     }
 
-    public function matches($terms) {
+    public function matches($terms, $matchAll=false) {
         $terms = $this->specify_search($terms, array('brand',
                                                      'name',
                                                      'serial',
@@ -140,6 +140,9 @@ class Product extends Entity {
                 }
             }
         }
+        if($matchAll && array_diff_assoc($terms, $matches)) {
+            return array();
+        }
         return $matches;
     }
 
diff --git a/include/User.php b/include/User.php
index aee33f5..18a619d 100644
--- a/include/User.php
+++ b/include/User.php
@@ -47,7 +47,7 @@ class User extends Entity {
         return true;
     }
 
-    public function matches($terms) {
+    public function matches($terms, $matchAll=false) {
         $terms = $this->specify_search($terms, array('name',
                                                      'email',
                                                      'notes'));
@@ -75,6 +75,9 @@ class User extends Entity {
                     break;
             }
         }
+        if($matchAll && array_diff_assoc($terms, $matches)) {
+            return array();
+        }
         return $matches;
     }
 

From 04c919f32d9d9365c5af1d1cada819c3803993af Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 11:16:17 +0200
Subject: [PATCH 187/250] bug searching

---
 include/Product.php | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/Product.php b/include/Product.php
index d84ec1d..5b3d7d0 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -140,7 +140,9 @@ class Product extends Entity {
                 }
             }
         }
+
         if($matchAll && array_diff_assoc($terms, $matches)) {
+            var_dump(array_diff_assoc($terms, $matches));
             return array();
         }
         return $matches;

From 8686eba653e1c3a5de99e95461fd2675319a3eb8 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 11:18:53 +0200
Subject: [PATCH 188/250] bug testing

---
 include/Product.php | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/Product.php b/include/Product.php
index 5b3d7d0..ba6611e 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -142,7 +142,9 @@ class Product extends Entity {
         }
 
         if($matchAll && array_diff_assoc($terms, $matches)) {
-            var_dump(array_diff_assoc($terms, $matches));
+            var_dump($terms, $matches);
+            // var_dump(expression);
+            // var_dump(array_diff_assoc($terms, $matches));
             return array();
         }
         return $matches;

From fa765dde5e381938996e54cc71459c5bf02fa8ef Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 11:20:28 +0200
Subject: [PATCH 189/250] bug searching

---
 include/Product.php | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/include/Product.php b/include/Product.php
index ba6611e..ee07a6b 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -142,8 +142,12 @@ class Product extends Entity {
         }
 
         if($matchAll && array_diff_assoc($terms, $matches)) {
-            var_dump($terms, $matches);
-            // var_dump(expression);
+            print('=== DEBUG $terms: ');
+            var_dump($terms);
+            print(' ===<br>');
+            print('=== DEBUG $matches: ');
+            var_dump($matches);
+            print(' ===<br><br>');
             // var_dump(array_diff_assoc($terms, $matches));
             return array();
         }

From b8ba31fc70a9b6aeb16d307527ad06786fcc5ffc Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 11:34:10 +0200
Subject: [PATCH 190/250] testing search function

---
 include/SearchPage.php | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index ea9d9b3..2b23da8 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -68,7 +68,6 @@ class SearchPage extends Page {
 
         foreach($terms as $key => $term) {
             foreach($term as $value => $parsedTerm) {
-
                 switch ($parsedTerm[0]) {
                     case "+":
                         if (!array_key_exists($key, $mustMatchArray)) {
@@ -102,16 +101,16 @@ class SearchPage extends Page {
         $items = get_items($type);
         $sanitizedItems = array();
         foreach($items as $item) {
-            $mustMatch = $item->matches($mustMatchArray, True);
-            if($mustMatch) {
-                $sanitizedItems[] = array($item, $mustMatch);
+            $result = $item->matches($mustMatchArray);
+            if($result) {
+                $sanitizedItems[] = array($item, $result);
             }
 
             // $mustMatchCheck = array();
             // foreach($mustMatchArray as $mustMatchTerm) {
 
             //     $matchResult = $item->matches($mustMatchTerm);
-            //     if ($matchResult) {
+            //     if($matchResult) {
             //         $mustMatchCheck[] = True;
             //     } else {
             //         $mustMatchCheck[] = False;
@@ -125,7 +124,7 @@ class SearchPage extends Page {
 
             // $mustExcludeCheck = array();
             // foreach($mustExcludeArray as $mustExcludeTerm) {
-            //     if ($item->matches($mustExcludeTerm)) {
+            //     if($item->matches($mustExcludeTerm)) {
             //         $mustExcludeCheck[] = False;
             //     } else {
             //         $mustExcludeCheck[] = True;
@@ -133,7 +132,7 @@ class SearchPage extends Page {
             // }
 
             // if (in_array(False, $mustIncludeCheck, True) === False) {
-            //     if (in_array(False, $mustExcludeCheck, True) === True) {
+            //     if(in_array(False, $mustExcludeCheck, True) === True) {
 
             //         //  === IF TRUE DO NOTHING ===
 
@@ -152,10 +151,22 @@ class SearchPage extends Page {
             print('DEBUG $sanitizedItem: ');
             var_dump($sanitizedItem);
             print('<br><br>');
-        }
 
-        $out = array();
-        return $out;
+        //     if($sanitizedItem->matches($cannotMatchArray)) {
+
+        //         //  === IF TRUE DO NOTHING ===
+
+        //     }
+        //     else {
+        //         $result = $sanitizedItem->matches($mayMatchArray);
+        //         if($result) {
+        //             $out[] = array($sanitizedItem, $result);
+        //         }
+        //     }
+        // }
+
+        return array();
+        // return $out;
     }
 
     private function translate_terms($terms) {

From 7898227af349503deed31f422706c7875427b0ff Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 11:34:47 +0200
Subject: [PATCH 191/250] testing search function

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 2b23da8..6139283 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -163,7 +163,7 @@ class SearchPage extends Page {
         //             $out[] = array($sanitizedItem, $result);
         //         }
         //     }
-        // }
+        }
 
         return array();
         // return $out;

From a2a20b0b7178aa8cc77734736c94789997f67800 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 11:40:56 +0200
Subject: [PATCH 192/250] teasting search function

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 6139283..e092b07 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -101,7 +101,7 @@ class SearchPage extends Page {
         $items = get_items($type);
         $sanitizedItems = array();
         foreach($items as $item) {
-            $result = $item->matches($mustMatchArray);
+            $result = $item->matches($mustMatchArray, True);
             if($result) {
                 $sanitizedItems[] = array($item, $result);
             }

From ffec00444ff50da69b5404cd35589076cbbd0e3e Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 13:48:14 +0200
Subject: [PATCH 193/250] cleanup of debug output

---
 include/Product.php | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/Product.php b/include/Product.php
index ee07a6b..329bb3e 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -142,12 +142,12 @@ class Product extends Entity {
         }
 
         if($matchAll && array_diff_assoc($terms, $matches)) {
-            print('=== DEBUG $terms: ');
+            print('=== DEBUG $terms ===<br>');
             var_dump($terms);
-            print(' ===<br>');
-            print('=== DEBUG $matches: ');
+            print('<br><br>');
+            print('=== DEBUG $matches ===<br>');
             var_dump($matches);
-            print(' ===<br><br>');
+            print('<br><br>');
             // var_dump(array_diff_assoc($terms, $matches));
             return array();
         }

From 6c9aa4dcddae8a125b4cf07f743464100a96b53c Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 14:32:35 +0200
Subject: [PATCH 194/250] testing search function

---
 include/Product.php    | 6 +++---
 include/SearchPage.php | 7 +++----
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/include/Product.php b/include/Product.php
index 329bb3e..398735c 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -142,9 +142,9 @@ class Product extends Entity {
         }
 
         if($matchAll && array_diff_assoc($terms, $matches)) {
-            print('=== DEBUG $terms ===<br>');
-            var_dump($terms);
-            print('<br><br>');
+            // print('=== DEBUG $terms ===<br>');
+            // var_dump($terms);
+            // print('<br><br>');
             print('=== DEBUG $matches ===<br>');
             var_dump($matches);
             print('<br><br>');
diff --git a/include/SearchPage.php b/include/SearchPage.php
index e092b07..7a8a1d5 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -30,10 +30,9 @@ class SearchPage extends Page {
         }
         print('<br>');
         foreach(array('user', 'product') as $type) {
-            print('=== DEBUG $type: ');
-            print_r($type);
-            print(' ===<br>');
-            print('<br>');
+            // print('=== DEBUG $type: ');
+            // print_r($type);
+            // print(' ===<br><br>');
             $result = $this->search($type, $this->terms);
             if($result) {
                 $out[$type] = $result;

From 11f775493d0935a413bf5b0de981b2fa6401255f Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 14:49:03 +0200
Subject: [PATCH 195/250] testing search function

---
 include/Product.php | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/include/Product.php b/include/Product.php
index 398735c..2475145 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -145,10 +145,14 @@ class Product extends Entity {
             // print('=== DEBUG $terms ===<br>');
             // var_dump($terms);
             // print('<br><br>');
+
+            print('=== DEBUG diff $terms and $matches ===<br>');
+            var_dump($array_diff_assoc($terms, $matches));
+            print('<br><br>');
             print('=== DEBUG $matches ===<br>');
             var_dump($matches);
             print('<br><br>');
-            // var_dump(array_diff_assoc($terms, $matches));
+
             return array();
         }
         return $matches;

From 4c11bc605bdc7a2417b0ca1ca14f848471dee588 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 14:50:30 +0200
Subject: [PATCH 196/250] testing search function

---
 include/Product.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/Product.php b/include/Product.php
index 2475145..111677c 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -147,7 +147,7 @@ class Product extends Entity {
             // print('<br><br>');
 
             print('=== DEBUG diff $terms and $matches ===<br>');
-            var_dump($array_diff_assoc($terms, $matches));
+            var_dump(array_diff_assoc($terms, $matches));
             print('<br><br>');
             print('=== DEBUG $matches ===<br>');
             var_dump($matches);

From 55882611e7e9224d46751a71cd1c61216aafedc4 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 14:52:03 +0200
Subject: [PATCH 197/250] testing search function

---
 include/Product.php | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/include/Product.php b/include/Product.php
index 111677c..3362e72 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -142,10 +142,9 @@ class Product extends Entity {
         }
 
         if($matchAll && array_diff_assoc($terms, $matches)) {
-            // print('=== DEBUG $terms ===<br>');
-            // var_dump($terms);
-            // print('<br><br>');
-
+            print('=== DEBUG $terms ===<br>');
+            var_dump($terms);
+            print('<br><br>');
             print('=== DEBUG diff $terms and $matches ===<br>');
             var_dump(array_diff_assoc($terms, $matches));
             print('<br><br>');

From fa30f4b0f79eb02165f549ad476c8916a50cca92 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 16:05:43 +0200
Subject: [PATCH 198/250] testing search function

---
 include/Product.php | 35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/include/Product.php b/include/Product.php
index 3362e72..5ff909f 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -122,38 +122,43 @@ class Product extends Entity {
             if(property_exists($this, $field)) {
                 if(match($values, $this->$field)) {
                     $matches[$field] = $this->$field;
+                } else {
+                    if($matchAll) {
+                        return array();
+                    }
                 }
             } else if(array_key_exists($field, $this->get_info())) {
                 if(match($values, $this->get_info()[$field])) {
                     $matches[$field] = $this->get_info()[$field];
+                } else {
+                    if($matchAll) {
+                        return array();
+                    }
                 }
             } else if($field == 'tag') {
                 foreach($this->get_tags() as $tag) {
                     if(match($values, $tag)) {
-                        $matches['tags'] = $this->get_tags();
+                        if(!array_key_exists('tags', $matches)) {
+                            $matches['tags'] = array();
+                        }
+                        $matches['tags'][] = $tag;
                         break;
+                    } else {
+                        if($matchAll) {
+                            return array();
+                        }
                     }
                 }
             } else if($field == 'status') {
                 if(match($values, $this->get_status())) {
                     $matches['status'] = $this->get_status();
+                } else {
+                    if($matchAll) {
+                        return array();
+                    }
                 }
             }
         }
-
-        if($matchAll && array_diff_assoc($terms, $matches)) {
-            print('=== DEBUG $terms ===<br>');
-            var_dump($terms);
-            print('<br><br>');
-            print('=== DEBUG diff $terms and $matches ===<br>');
-            var_dump(array_diff_assoc($terms, $matches));
-            print('<br><br>');
-            print('=== DEBUG $matches ===<br>');
-            var_dump($matches);
-            print('<br><br>');
-
-            return array();
-        }
         return $matches;
     }
 

From 1c6f3ae058a150ff8ab37c50213ebd6141188bfe Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 16:08:35 +0200
Subject: [PATCH 199/250] testing search function

---
 include/SearchPage.php | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 7a8a1d5..36f7ff0 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -102,7 +102,8 @@ class SearchPage extends Page {
         foreach($items as $item) {
             $result = $item->matches($mustMatchArray, True);
             if($result) {
-                $sanitizedItems[] = array($item, $result);
+                // $sanitizedItems[] = array($item, $result);
+                $out[] = array($item, $result);
             }
 
             // $mustMatchCheck = array();
@@ -146,10 +147,10 @@ class SearchPage extends Page {
             // }
         }
 
-        foreach($sanitizedItems as $sanitizedItem) {
-            print('DEBUG $sanitizedItem: ');
-            var_dump($sanitizedItem);
-            print('<br><br>');
+        // foreach($sanitizedItems as $sanitizedItem) {
+        //     print('DEBUG $sanitizedItem: ');
+        //     var_dump($sanitizedItem);
+        //     print('<br><br>');
 
         //     if($sanitizedItem->matches($cannotMatchArray)) {
 
@@ -164,8 +165,8 @@ class SearchPage extends Page {
         //     }
         }
 
-        return array();
-        // return $out;
+        // return array();
+        return $out;
     }
 
     private function translate_terms($terms) {

From 79c7af32b3f0d487c84c95d0234c46e777865cb5 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 16:09:27 +0200
Subject: [PATCH 200/250] testing search function

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 36f7ff0..7c29f1f 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -163,7 +163,7 @@ class SearchPage extends Page {
         //             $out[] = array($sanitizedItem, $result);
         //         }
         //     }
-        }
+        // }
 
         // return array();
         return $out;

From 0b6f25f2ab1245162a66a358ba8d2c00c94aeb04 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 16:13:47 +0200
Subject: [PATCH 201/250] testing search function

---
 include/Product.php    | 6 ++++++
 include/SearchPage.php | 4 +++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/include/Product.php b/include/Product.php
index 5ff909f..1808aca 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -111,12 +111,18 @@ class Product extends Entity {
     }
 
     public function matches($terms, $matchAll=false) {
+        print('DEBUG $terms: ');
+        var_dump($terms);
+        print('<br><br>');
         $terms = $this->specify_search($terms, array('brand',
                                                      'name',
                                                      'serial',
                                                      'invoice',
                                                      'status',
                                                      'tag'));
+        print('DEBUG $terms post translation: ');
+        var_dump($terms);
+        print('<br><br>');
         $matches = array();
         foreach($terms as $field => $values) {
             if(property_exists($this, $field)) {
diff --git a/include/SearchPage.php b/include/SearchPage.php
index 7c29f1f..ba7d7f4 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -146,7 +146,9 @@ class SearchPage extends Page {
             //     }
             // }
         }
-
+        print('DEBUG $sanitizedItem: ');
+        var_dump($out);
+        print('<br><br>');
         // foreach($sanitizedItems as $sanitizedItem) {
         //     print('DEBUG $sanitizedItem: ');
         //     var_dump($sanitizedItem);

From 193f2cf12175c6fa06884cb2ed921f7b34c49c3b Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 16:22:39 +0200
Subject: [PATCH 202/250] testing search function

---
 include/SearchPage.php | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index ba7d7f4..76ed86c 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -66,6 +66,7 @@ class SearchPage extends Page {
         $mayMatchArray = array();
 
         foreach($terms as $key => $term) {
+            var_dump("key-term map", $key, $term);
             foreach($term as $value => $parsedTerm) {
                 switch ($parsedTerm[0]) {
                     case "+":
@@ -79,19 +80,19 @@ class SearchPage extends Page {
                         if (!array_key_exists($key, $cannotMatchArray)) {
                             $cannotMatchArray[$key] = array();
                         }
-                        $cannotMatchArray[] = array($key => substr($parsedTerm, 1));
+                        $cannotMatchArray[$key][] = array($key => substr($parsedTerm, 1));
                         break;
                     case "~":
                         if (!array_key_exists($key, $mayMatchArray)) {
                             $mayMatchArray[$key] = array();
                         }
-                        $mayMatchArray[] = array($key => substr($parsedTerm, 1));
+                        $mayMatchArray[$key][] = array($key => substr($parsedTerm, 1));
                         break;
                     default:
                         if (!array_key_exists($key, $mayMatchArray)) {
                             $mayMatchArray[$key] = array();
                         }
-                        $mayMatchArray[] = array($key => $parsedTerm);
+                        $mayMatchArray[$key][] = array($key => $parsedTerm);
                         break;
                 }
             }
@@ -99,6 +100,7 @@ class SearchPage extends Page {
 
         $items = get_items($type);
         $sanitizedItems = array();
+        $out = array();
         foreach($items as $item) {
             $result = $item->matches($mustMatchArray, True);
             if($result) {
@@ -146,7 +148,7 @@ class SearchPage extends Page {
             //     }
             // }
         }
-        print('DEBUG $sanitizedItem: ');
+        print('DEBUG $out: ');
         var_dump($out);
         print('<br><br>');
         // foreach($sanitizedItems as $sanitizedItem) {

From aef524616ec2b54537b072e011e9dad42104f4fd Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 16:25:04 +0200
Subject: [PATCH 203/250] testing search function

---
 include/SearchPage.php | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 76ed86c..de47d8d 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -66,33 +66,33 @@ class SearchPage extends Page {
         $mayMatchArray = array();
 
         foreach($terms as $key => $term) {
-            var_dump("key-term map", $key, $term);
+            var_dump("key-term map", $key, $term, "<br>");
             foreach($term as $value => $parsedTerm) {
                 switch ($parsedTerm[0]) {
                     case "+":
                         if (!array_key_exists($key, $mustMatchArray)) {
                             $mustMatchArray[$key] = array();
                         }
-                        $mustMatchArray[$key][] = substr($parsedTerm, 1);
+                        $mustMatchArray[] = substr($parsedTerm, 1);
                         break;
                     case "!":
                     case "-":
                         if (!array_key_exists($key, $cannotMatchArray)) {
                             $cannotMatchArray[$key] = array();
                         }
-                        $cannotMatchArray[$key][] = array($key => substr($parsedTerm, 1));
+                        $cannotMatchArray[] = array($key => substr($parsedTerm, 1));
                         break;
                     case "~":
                         if (!array_key_exists($key, $mayMatchArray)) {
                             $mayMatchArray[$key] = array();
                         }
-                        $mayMatchArray[$key][] = array($key => substr($parsedTerm, 1));
+                        $mayMatchArray[] = array($key => substr($parsedTerm, 1));
                         break;
                     default:
                         if (!array_key_exists($key, $mayMatchArray)) {
                             $mayMatchArray[$key] = array();
                         }
-                        $mayMatchArray[$key][] = array($key => $parsedTerm);
+                        $mayMatchArray[] = array($key => $parsedTerm);
                         break;
                 }
             }

From 9fe090ea4dc493e1986ef5c4b6a560f982257d0d Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 16:27:09 +0200
Subject: [PATCH 204/250] fixing typos

---
 include/SearchPage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index de47d8d..862edce 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -66,7 +66,7 @@ class SearchPage extends Page {
         $mayMatchArray = array();
 
         foreach($terms as $key => $term) {
-            var_dump("key-term map", $key, $term, "<br>");
+            var_dump("key-term map", $key, $term, '<br>');
             foreach($term as $value => $parsedTerm) {
                 switch ($parsedTerm[0]) {
                     case "+":

From 2479d46bbb5340d3bec38eb56c5c532ab9e998f7 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 16:36:38 +0200
Subject: [PATCH 205/250] testing search function

---
 include/Product.php    | 4 +---
 include/SearchPage.php | 8 ++++----
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/include/Product.php b/include/Product.php
index 1808aca..46ed39f 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -120,9 +120,7 @@ class Product extends Entity {
                                                      'invoice',
                                                      'status',
                                                      'tag'));
-        print('DEBUG $terms post translation: ');
-        var_dump($terms);
-        print('<br><br>');
+        var_dump('DEBUG $terms post translation: ', $terms, '<br><br>');
         $matches = array();
         foreach($terms as $field => $values) {
             if(property_exists($this, $field)) {
diff --git a/include/SearchPage.php b/include/SearchPage.php
index 862edce..9be7a54 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -73,26 +73,26 @@ class SearchPage extends Page {
                         if (!array_key_exists($key, $mustMatchArray)) {
                             $mustMatchArray[$key] = array();
                         }
-                        $mustMatchArray[] = substr($parsedTerm, 1);
+                        $mustMatchArray[$key][] = substr($parsedTerm, 1);
                         break;
                     case "!":
                     case "-":
                         if (!array_key_exists($key, $cannotMatchArray)) {
                             $cannotMatchArray[$key] = array();
                         }
-                        $cannotMatchArray[] = array($key => substr($parsedTerm, 1));
+                        $cannotMatchArray[$key][] = substr($parsedTerm, 1);
                         break;
                     case "~":
                         if (!array_key_exists($key, $mayMatchArray)) {
                             $mayMatchArray[$key] = array();
                         }
-                        $mayMatchArray[] = array($key => substr($parsedTerm, 1));
+                        $mayMatchArray[$key][] = substr($parsedTerm, 1);
                         break;
                     default:
                         if (!array_key_exists($key, $mayMatchArray)) {
                             $mayMatchArray[$key] = array();
                         }
-                        $mayMatchArray[] = array($key => $parsedTerm);
+                        $mayMatchArray[$key][] = $parsedTerm;
                         break;
                 }
             }

From 12a08d4227d9461c7cf19009c502f893fc9758c8 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 16:43:23 +0200
Subject: [PATCH 206/250] testing search function

---
 include/SearchPage.php | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 9be7a54..f2a1885 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -74,6 +74,7 @@ class SearchPage extends Page {
                             $mustMatchArray[$key] = array();
                         }
                         $mustMatchArray[$key][] = substr($parsedTerm, 1);
+                        var_dump("$mustMatchArray", $mustMatchArray, '<br>');
                         break;
                     case "!":
                     case "-":

From 08cffa9d9dfa33a1e60d79a524f09c4c30ab3c2f Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 16:45:58 +0200
Subject: [PATCH 207/250] searching for bugs

---
 include/SearchPage.php | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index f2a1885..c195f89 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -68,6 +68,8 @@ class SearchPage extends Page {
         foreach($terms as $key => $term) {
             var_dump("key-term map", $key, $term, '<br>');
             foreach($term as $value => $parsedTerm) {
+                var_dump("$parsedTerm", $parsedTerm, '<br>');
+                var_dump("$parsedTerm[0]", $parsedTerm[0], '<br>');
                 switch ($parsedTerm[0]) {
                     case "+":
                         if (!array_key_exists($key, $mustMatchArray)) {

From 325bc500ed3f54095e2c2a4b902464cfbddb4023 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 16:49:53 +0200
Subject: [PATCH 208/250] testing search function

---
 include/SearchPage.php | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index c195f89..65a41ab 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -66,17 +66,21 @@ class SearchPage extends Page {
         $mayMatchArray = array();
 
         foreach($terms as $key => $term) {
-            var_dump("key-term map", $key, $term, '<br>');
+            var_dump("key-term map: ", $key, $term);
+            print('<br>');
             foreach($term as $value => $parsedTerm) {
-                var_dump("$parsedTerm", $parsedTerm, '<br>');
-                var_dump("$parsedTerm[0]", $parsedTerm[0], '<br>');
+                var_dump("$parsedTerm: ", $parsedTerm);
+                print('<br>');
+                var_dump("$parsedTerm[0]: ", $parsedTerm[0]);
+                print('<br>');
                 switch ($parsedTerm[0]) {
                     case "+":
                         if (!array_key_exists($key, $mustMatchArray)) {
                             $mustMatchArray[$key] = array();
                         }
                         $mustMatchArray[$key][] = substr($parsedTerm, 1);
-                        var_dump("$mustMatchArray", $mustMatchArray, '<br>');
+                        var_dump("$mustMatchArray: ", $mustMatchArray);
+                        print('<br>');
                         break;
                     case "!":
                     case "-":

From e18ff2f1acb7c1ad6f4b2a4b9d6ac9798b8458a2 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Wed, 8 Sep 2021 16:53:52 +0200
Subject: [PATCH 209/250] searching for bugs

---
 include/SearchPage.php | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 65a41ab..110f9f0 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -66,12 +66,11 @@ class SearchPage extends Page {
         $mayMatchArray = array();
 
         foreach($terms as $key => $term) {
-            var_dump("key-term map: ", $key, $term);
-            print('<br>');
             foreach($term as $value => $parsedTerm) {
-                var_dump("$parsedTerm: ", $parsedTerm);
-                print('<br>');
-                var_dump("$parsedTerm[0]: ", $parsedTerm[0]);
+                print('DEBUG $parsedTerm: ');
+                var_dump($parsedTerm);
+                print('<br>DEBUG $parsedTerm[0]: ');
+                var_dump($parsedTerm[0]);
                 print('<br>');
                 switch ($parsedTerm[0]) {
                     case "+":
@@ -79,7 +78,8 @@ class SearchPage extends Page {
                             $mustMatchArray[$key] = array();
                         }
                         $mustMatchArray[$key][] = substr($parsedTerm, 1);
-                        var_dump("$mustMatchArray: ", $mustMatchArray);
+                        print('DEBUG $mustMatchArray: ');
+                        var_dump($mustMatchArray);
                         print('<br>');
                         break;
                     case "!":

From c3c128fe0afbd118847a14ac3b95bf29abdf50cb Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 9 Sep 2021 11:11:10 +0200
Subject: [PATCH 210/250] bug search

---
 include/Product.php    |  4 +++-
 include/SearchPage.php | 10 ++++++----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/include/Product.php b/include/Product.php
index 46ed39f..6451afa 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -120,7 +120,9 @@ class Product extends Entity {
                                                      'invoice',
                                                      'status',
                                                      'tag'));
-        var_dump('DEBUG $terms post translation: ', $terms, '<br><br>');
+        print('DEBUG $terms POST TRANSLATION: ');
+        var_dump($terms);
+        print('<br><br>');
         $matches = array();
         foreach($terms as $field => $values) {
             if(property_exists($this, $field)) {
diff --git a/include/SearchPage.php b/include/SearchPage.php
index 110f9f0..15cc9c1 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -66,6 +66,7 @@ class SearchPage extends Page {
         $mayMatchArray = array();
 
         foreach($terms as $key => $term) {
+            var_dump("dump term: ", $term);
             foreach($term as $value => $parsedTerm) {
                 print('DEBUG $parsedTerm: ');
                 var_dump($parsedTerm);
@@ -111,8 +112,7 @@ class SearchPage extends Page {
         foreach($items as $item) {
             $result = $item->matches($mustMatchArray, True);
             if($result) {
-                // $sanitizedItems[] = array($item, $result);
-                $out[] = array($item, $result);
+                $sanitizedItems[] = array($item, $result);
             }
 
             // $mustMatchCheck = array();
@@ -156,8 +156,9 @@ class SearchPage extends Page {
             // }
         }
         print('DEBUG $out: ');
-        var_dump($out);
+        var_dump($sanitizedItems);
         print('<br><br>');
+        // $out = array();
         // foreach($sanitizedItems as $sanitizedItem) {
         //     print('DEBUG $sanitizedItem: ');
         //     var_dump($sanitizedItem);
@@ -177,7 +178,8 @@ class SearchPage extends Page {
         // }
 
         // return array();
-        return $out;
+        // return $out;
+        return $sanitizedItems;
     }
 
     private function translate_terms($terms) {

From 5414ba7da16e073d22009bc8948ead810715fa99 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 9 Sep 2021 11:17:05 +0200
Subject: [PATCH 211/250] bug searching in search function

---
 include/SearchPage.php | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index 15cc9c1..0d5c4e3 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -65,20 +65,25 @@ class SearchPage extends Page {
         $cannotMatchArray = array(); 
         $mayMatchArray = array();
 
-        foreach($terms as $key => $term) {
-            var_dump("dump term: ", $term);
-            foreach($term as $value => $parsedTerm) {
+
+
+        foreach($terms as $key => $value) {
+            var_dump("dump term: ", $value);
+            if(!is_array($value)) {
+                $value = array($value);
+            }
+            foreach($value as $term) {
                 print('DEBUG $parsedTerm: ');
-                var_dump($parsedTerm);
+                var_dump($term);
                 print('<br>DEBUG $parsedTerm[0]: ');
-                var_dump($parsedTerm[0]);
+                var_dump($term[0]);
                 print('<br>');
-                switch ($parsedTerm[0]) {
+                switch ($term[0]) {
                     case "+":
                         if (!array_key_exists($key, $mustMatchArray)) {
                             $mustMatchArray[$key] = array();
                         }
-                        $mustMatchArray[$key][] = substr($parsedTerm, 1);
+                        $mustMatchArray[$key][] = substr($term, 1);
                         print('DEBUG $mustMatchArray: ');
                         var_dump($mustMatchArray);
                         print('<br>');
@@ -88,19 +93,19 @@ class SearchPage extends Page {
                         if (!array_key_exists($key, $cannotMatchArray)) {
                             $cannotMatchArray[$key] = array();
                         }
-                        $cannotMatchArray[$key][] = substr($parsedTerm, 1);
+                        $cannotMatchArray[$key][] = substr($term, 1);
                         break;
                     case "~":
                         if (!array_key_exists($key, $mayMatchArray)) {
                             $mayMatchArray[$key] = array();
                         }
-                        $mayMatchArray[$key][] = substr($parsedTerm, 1);
+                        $mayMatchArray[$key][] = substr($term, 1);
                         break;
                     default:
                         if (!array_key_exists($key, $mayMatchArray)) {
                             $mayMatchArray[$key] = array();
                         }
-                        $mayMatchArray[$key][] = $parsedTerm;
+                        $mayMatchArray[$key][] = $term;
                         break;
                 }
             }

From f1a731c859a3b37036a7a9f6530484d0df5b74c7 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 9 Sep 2021 11:26:15 +0200
Subject: [PATCH 212/250] bug searching in search function

---
 include/Product.php   | 8 +++-----
 include/functions.php | 9 ++++++---
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/include/Product.php b/include/Product.php
index 6451afa..a3a98bc 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -143,11 +143,9 @@ class Product extends Entity {
                 }
             } else if($field == 'tag') {
                 foreach($this->get_tags() as $tag) {
-                    if(match($values, $tag)) {
-                        if(!array_key_exists('tags', $matches)) {
-                            $matches['tags'] = array();
-                        }
-                        $matches['tags'][] = $tag;
+                    $match = match($values, $tag, $matchAll);
+                    if($match) {
+                        $matches['tags'] = $tag;
                         break;
                     } else {
                         if($matchAll) {
diff --git a/include/functions.php b/include/functions.php
index 099b4bb..1f16f6f 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -253,16 +253,19 @@ function suggest_content($fieldname) {
     return $out;
 }
 
-function match($searchterms, $subject) {
+function match($searchterms, $subject, $matchAll=false) {
+    $out = array();
     if(!is_array($searchterms)) {
         $searchterms = array($searchterms);
     }
     foreach($searchterms as $term) {
         if(fnmatch('*'.$term.'*', $subject, FNM_CASEFOLD)) {
-            return true;
+            $out[] = $term;
+        } else if($matchAll) {
+            return array();
         }
     }
-    return false;
+    return $out;
 }
 
 function format_date($date) {

From 84ee8f10d68dcf4f266501dbe8a96940ba59b8a6 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Thu, 9 Sep 2021 11:31:46 +0200
Subject: [PATCH 213/250] bug searching in search function

---
 include/Product.php   | 9 +++++----
 include/functions.php | 9 +++------
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/include/Product.php b/include/Product.php
index a3a98bc..d3dd24c 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -143,10 +143,11 @@ class Product extends Entity {
                 }
             } else if($field == 'tag') {
                 foreach($this->get_tags() as $tag) {
-                    $match = match($values, $tag, $matchAll);
-                    if($match) {
-                        $matches['tags'] = $tag;
-                        break;
+                    if(match($values, $tag)) {
+                        if(!array_key_exists('tags', $matches)) {
+                            $matches['tags'] = array();
+                        }
+                        $matches['tags'][] = $tag;
                     } else {
                         if($matchAll) {
                             return array();
diff --git a/include/functions.php b/include/functions.php
index 1f16f6f..099b4bb 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -253,19 +253,16 @@ function suggest_content($fieldname) {
     return $out;
 }
 
-function match($searchterms, $subject, $matchAll=false) {
-    $out = array();
+function match($searchterms, $subject) {
     if(!is_array($searchterms)) {
         $searchterms = array($searchterms);
     }
     foreach($searchterms as $term) {
         if(fnmatch('*'.$term.'*', $subject, FNM_CASEFOLD)) {
-            $out[] = $term;
-        } else if($matchAll) {
-            return array();
+            return true;
         }
     }
-    return $out;
+    return false;
 }
 
 function format_date($date) {

From 0eebf93ccadfcb6c7727a1b10d5518f4e44ab9a9 Mon Sep 17 00:00:00 2001
From: Viktor Pedersen <viktor@dsv.su.se>
Date: Mon, 13 Sep 2021 11:14:46 +0200
Subject: [PATCH 214/250] cleaning up debug output

---
 include/Product.php    |  2 +-
 include/SearchPage.php | 15 +--------------
 2 files changed, 2 insertions(+), 15 deletions(-)

diff --git a/include/Product.php b/include/Product.php
index d3dd24c..b09a121 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -111,7 +111,7 @@ class Product extends Entity {
     }
 
     public function matches($terms, $matchAll=false) {
-        print('DEBUG $terms: ');
+        print('DEBUG $terms in matches: ');
         var_dump($terms);
         print('<br><br>');
         $terms = $this->specify_search($terms, array('brand',
diff --git a/include/SearchPage.php b/include/SearchPage.php
index 0d5c4e3..859605f 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -64,29 +64,17 @@ class SearchPage extends Page {
         $mustMatchArray = array(); 
         $cannotMatchArray = array(); 
         $mayMatchArray = array();
-
-
-
         foreach($terms as $key => $value) {
-            var_dump("dump term: ", $value);
             if(!is_array($value)) {
                 $value = array($value);
             }
             foreach($value as $term) {
-                print('DEBUG $parsedTerm: ');
-                var_dump($term);
-                print('<br>DEBUG $parsedTerm[0]: ');
-                var_dump($term[0]);
-                print('<br>');
                 switch ($term[0]) {
                     case "+":
                         if (!array_key_exists($key, $mustMatchArray)) {
                             $mustMatchArray[$key] = array();
                         }
                         $mustMatchArray[$key][] = substr($term, 1);
-                        print('DEBUG $mustMatchArray: ');
-                        var_dump($mustMatchArray);
-                        print('<br>');
                         break;
                     case "!":
                     case "-":
@@ -113,7 +101,6 @@ class SearchPage extends Page {
 
         $items = get_items($type);
         $sanitizedItems = array();
-        $out = array();
         foreach($items as $item) {
             $result = $item->matches($mustMatchArray, True);
             if($result) {
@@ -160,7 +147,7 @@ class SearchPage extends Page {
             //     }
             // }
         }
-        print('DEBUG $out: ');
+        print('DEBUG $sanitizedItems: ');
         var_dump($sanitizedItems);
         print('<br><br>');
         // $out = array();

From 9f4bc39e55319e736b023890f844e53eccc2cb18 Mon Sep 17 00:00:00 2001
From: root <root@dsv.su.se>
Date: Tue, 14 Sep 2021 22:45:28 +0200
Subject: [PATCH 215/250] Testing a hopefully faster ldap lookup

---
 include/Ajax.php         |  2 +-
 include/CheckoutPage.php |  2 +-
 include/Cron.php         |  6 ++++--
 include/Page.php         |  6 +++---
 include/Responder.php    |  2 ++
 include/User.php         | 23 +++++++++++------------
 include/UserPage.php     |  2 +-
 7 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/include/Ajax.php b/include/Ajax.php
index 8ddadd3..4ede200 100644
--- a/include/Ajax.php
+++ b/include/Ajax.php
@@ -112,7 +112,7 @@ class Ajax extends Responder {
             $user = $loan->get_user();
             $userlink = replace(array('page' => 'users',
                                       'id'   => $user->get_id(),
-                                      'name' => $user->get_displayname()),
+                                      'name' => $user->get_displayname($this->ldap)),
                                 $this->fragments['item_link']);
             $productlink = replace(array('page' => 'products',
                                          'id'   => $product->get_id(),
diff --git a/include/CheckoutPage.php b/include/CheckoutPage.php
index e07f199..1da4759 100644
--- a/include/CheckoutPage.php
+++ b/include/CheckoutPage.php
@@ -33,7 +33,7 @@ class CheckoutPage extends Page {
         $disabled = 'disabled';
         if($this->user !== null) {
             $username = $this->user->get_name();
-            $displayname = $this->user->get_displayname();
+            $displayname = $this->user->get_displayname($this->ldap);
             $notes = $this->user->get_notes();
             $enddate = format_date(default_loan_end(time()));
             $disabled = '';
diff --git a/include/Cron.php b/include/Cron.php
index 50682f7..7ca58e8 100644
--- a/include/Cron.php
+++ b/include/Cron.php
@@ -4,11 +4,13 @@ class Cron {
     private $sender = '';
     private $error = '';
     private $kvs;
+    private $ldap;
     public function __construct($sender, $error) {
         $this->now = time();
         $this->sender = $sender;
         $this->error = $error;
         $this->kvs = new Kvs();
+        $this->ldap = new Ldap();
     }
 
     public function run() {
@@ -89,7 +91,7 @@ EOF;
 
         $subject = replace(array('count' => $overdue_count,
                                  'late'  => $late), $subject_template);
-        $message = replace(array('name'       => $user->get_displayname(),
+        $message = replace(array('name'       => $user->get_displayname($this->ldap),
                                  'list_sv'    => $reminder_list_sv,
                                  'product_sv' => $product_sv,
                                  'it_sv'      => $it_sv,
@@ -101,7 +103,7 @@ EOF;
                            $message_template);
 
         try {
-            mb_send_mail($user->get_email(),
+            mb_send_mail($user->get_email($this->ldap),
                          $subject,
                          $message,
                          'From: '.$this->sender);
diff --git a/include/Page.php b/include/Page.php
index b783547..696bed7 100644
--- a/include/Page.php
+++ b/include/Page.php
@@ -103,7 +103,7 @@ abstract class Page extends Responder {
                 $replacements['has_notes'] = '*';
             }
             $userlink = replace(array('id' => $user->get_id(),
-                                      'name' => $user->get_displayname(),
+                                      'name' => $user->get_displayname($this->ldap),
                                       'page' => 'users'),
                                 $this->fragments['item_link']);
             $replacements['item_link'] = $userlink;
@@ -151,7 +151,7 @@ abstract class Page extends Responder {
                 case 'overdue':
                     $loan = $product->get_active_loan();
                     $user = $loan->get_user();
-                    $replacements = array('name' => $user->get_displayname(),
+                    $replacements = array('name' => $user->get_displayname($this->ldap),
                                           'id'   => $user->get_id(),
                                           'page' => 'users');
                     $userlink = replace($replacements,
@@ -237,7 +237,7 @@ abstract class Page extends Responder {
                 }
             } else if($event instanceof Loan) {
                 $user = $event->get_user();
-                $userlink = replace(array('name' => $user->get_displayname(),
+                $userlink = replace(array('name' => $user->get_displayname($this->ldap),
                                           'id' => $user->get_id(),
                                           'page' => 'users'),
                                     $this->fragments['item_link']);
diff --git a/include/Responder.php b/include/Responder.php
index 6d05f51..ff621cd 100644
--- a/include/Responder.php
+++ b/include/Responder.php
@@ -1,9 +1,11 @@
 <?php
 abstract class Responder {
     protected $fragments = array();
+    protected $ldap = null;
     
     public function __construct() {
         $this->fragments = get_fragments('./html/fragments.html');
+        $this->ldap = new Ldap();
     }
     
     final protected function escape_tags($tags) {
diff --git a/include/User.php b/include/User.php
index 18a619d..34d5699 100644
--- a/include/User.php
+++ b/include/User.php
@@ -3,7 +3,6 @@ class User extends Entity {
     private $id = 0;
     private $name = '';
     private $notes = '';
-    private $ldap = null;
     
     public static function create_user($name) {
         $ins_user = prepare('insert into `user`(`name`) values (?)');
@@ -34,7 +33,6 @@ class User extends Entity {
         }
         $this->id = $id;
         $this->update_fields();
-        $this->ldap = new Ldap();
     }
     
     private function update_fields() {
@@ -47,7 +45,7 @@ class User extends Entity {
         return true;
     }
 
-    public function matches($terms, $matchAll=false) {
+    public function matches($terms, $ldap, $matchAll=false) {
         $terms = $this->specify_search($terms, array('name',
                                                      'email',
                                                      'notes'));
@@ -58,14 +56,15 @@ class User extends Entity {
                     if(match($values, $this->name)) {
                         $matches['name'] = $this->name;
                     }
-                    if(match($values, $this->get_displayname())) {
-                        $matches['displayname'] = $this->get_displayname();
+                    $dname = $this->get_displayname($ldap);
+                    if(match($values, $dname)) {
+                        $matches['displayname'] = $dname;
                     }
                     break;
                 case 'email':
-                    if($this->get_email(false) && match($values,
-                                                        $this->get_email())) {
-                        $matches['email'] = $this->get_email();
+                    $email = $this->get_email($ldap, false);
+                    if($email && match($values, $email)) {
+                        $matches['email'] = $email;
                     }
                     break;
                 case 'notes':
@@ -81,17 +80,17 @@ class User extends Entity {
         return $matches;
     }
 
-    public function get_displayname() {
+    public function get_displayname($ldap) {
         try {
-            return $this->ldap->get_user($this->name);
+            return $ldap->get_user($this->name);
         } catch(Exception $e) {
             return 'Ej i SUKAT';
         }
     }
 
-    public function get_email($format = true) {
+    public function get_email($ldap, $format = true) {
         try {
-            return $this->ldap->get_user_email($this->name);
+            return $ldap->get_user_email($this->name);
         } catch(Exception $e) {
             if($format) {
                 return 'Mailadress saknas';
diff --git a/include/UserPage.php b/include/UserPage.php
index ab1b544..c5ff4e1 100644
--- a/include/UserPage.php
+++ b/include/UserPage.php
@@ -56,7 +56,7 @@ class UserPage extends Page {
                              'inactive_loans' => $table_inactive,
                              'id' => $this->user->get_id(),
                              'name' => $this->user->get_name(),
-                             'displayname' => $this->user->get_displayname(),
+                             'displayname' => $this->user->get_displayname($this->ldap),
                              'notes' => $this->user->get_notes()),
                        $this->fragments['user_details']);
     }

From 78ac0574b936779186c291e3c273e23dda625d22 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Wed, 15 Sep 2021 15:53:52 +0200
Subject: [PATCH 216/250] Major search overhaul

---
 include/Entity.php     |  24 +---
 include/Product.php    | 153 +++++++++++++++++--------
 include/SearchPage.php | 247 ++++++++++++++++-------------------------
 include/User.php       |  57 +++++++---
 include/functions.php  |  21 ++--
 5 files changed, 260 insertions(+), 242 deletions(-)

diff --git a/include/Entity.php b/include/Entity.php
index 4edcd23..37c5f8e 100644
--- a/include/Entity.php
+++ b/include/Entity.php
@@ -1,27 +1,9 @@
 <?php
-class Entity {
+abstract class Entity {
     protected function __construct() {
         
     }
-    
-    protected function specify_search($searchterms, $searchfields) {
-        if(array_key_exists('fritext', $searchterms)) {
-            $freeterm = $searchterms['fritext'];
-            unset($searchterms['fritext']);
-            foreach($searchfields as $field) {
-                if(array_key_exists($field, $searchterms)) {
-                    $term = $searchterms[$field];
-                    if(is_array($term)) {
-                        $term[] = $freeterm;
-                    } else {
-                        $searchterms[$field] = array($term, $freeterm);
-                    }
-                } else {
-                    $searchterms[$field] = $freeterm;
-                }
-            }
-        }
-        return $searchterms;
-    }
+
+    abstract public function matches($term, $ldap);
 }
 ?>
diff --git a/include/Product.php b/include/Product.php
index b09a121..13b9322 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -110,58 +110,117 @@ class Product extends Entity {
         return true;
     }
 
-    public function matches($terms, $matchAll=false) {
-        print('DEBUG $terms in matches: ');
-        var_dump($terms);
-        print('<br><br>');
-        $terms = $this->specify_search($terms, array('brand',
-                                                     'name',
-                                                     'serial',
-                                                     'invoice',
-                                                     'status',
-                                                     'tag'));
-        print('DEBUG $terms POST TRANSLATION: ');
-        var_dump($terms);
-        print('<br><br>');
+    /*
+      Return a list of field-value mappings containing all matching search terms.
+     */
+    public function matches($terms, $ldap) {
         $matches = array();
-        foreach($terms as $field => $values) {
-            if(property_exists($this, $field)) {
-                if(match($values, $this->$field)) {
-                    $matches[$field] = $this->$field;
-                } else {
-                    if($matchAll) {
-                        return array();
+
+        // Create a list mapping all basic fields to getters
+        $fields = array('brand' => 'get_brand',
+                        'name' => 'get_name',
+                        'invoice' => 'get_invoice',
+                        'serial' => 'get_serial');
+
+        foreach($terms as $term) {
+            $key = $term->get_key();
+            $matched = false;
+            switch($key) {
+                case 'brand':
+                case 'name':
+                case 'invoice':
+                case 'serial':
+                    // If $key is a standard field, check against its value
+                    $getter = $fields[$key];
+                    $value = $this->$getter();
+                    if(match($term, $value)) {
+                        //Record a successful match
+                        $matches[$key] = $value;
+                        $matched = true;
                     }
-                }
-            } else if(array_key_exists($field, $this->get_info())) {
-                if(match($values, $this->get_info()[$field])) {
-                    $matches[$field] = $this->get_info()[$field];
-                } else {
-                    if($matchAll) {
-                        return array();
-                    }
-                }
-            } else if($field == 'tag') {
-                foreach($this->get_tags() as $tag) {
-                    if(match($values, $tag)) {
-                        if(!array_key_exists('tags', $matches)) {
-                            $matches['tags'] = array();
-                        }
-                        $matches['tags'][] = $tag;
-                    } else {
-                        if($matchAll) {
-                            return array();
+                    break;
+                case 'tag':
+                    // If $key is tag, iterate over the tags
+                    $matched_tags = $this->match_tags($term);
+                    if($matched_tags) {
+                        // Record a successful match
+                        $matched = true;
+                        if(!isset($matches['tags'])) {
+                            // This is the first list of matching tags
+                            $matches['tags'] = $matched_tags;
+                        } else {
+                            // Merge these results with existing results
+                            $matches['tags'] = array_unique(
+                                array_merge($matches['tags'],
+                                            $matched_tags));
                         }
                     }
-                }
-            } else if($field == 'status') {
-                if(match($values, $this->get_status())) {
-                    $matches['status'] = $this->get_status();
-                } else {
-                    if($matchAll) {
-                        return array();
+                    break;
+                case 'fritext':
+                    // if $key is fritext:
+                    // First check basic fields
+                    foreach($fields as $field => $getter) {
+                        $value = $this->$getter();
+                        if(match($term, $value)) {
+                            $matches[$field] = $value;
+                            $matched = true;
+                        }
                     }
-                }
+                    // Then tags
+                    $matched_tags = $this->match_tags($term);
+                    if($matched_tags) {
+                        $matched = true;
+                        if(!isset($matches['tags'])) {
+                            $matches['tags'] = $matched_tags;
+                        } else {
+                            $matches['tags'] = array_unique(
+                                array_merge($matches['tags'],
+                                            $matched_tags));
+                        }
+                    }
+                    // Then custom fields
+                    foreach($this->get_info() as $field => $value) {
+                        if(match($term, $value)) {
+                            //Record a successful match
+                            $matches[$field] = $value;
+                            $matched = true;
+                        }
+                    }
+                    break;
+                default:
+                    // Handle custom fields
+                    $info = $this->get_info();
+                    if(isset($info[$key])) {
+                        // If $key is a valid custom field on this product
+                        $value = $info[$key];
+                        if(match($term, $value)) {
+                            //Record a successful match
+                            $matches[$key] = $value;
+                            $matched = true;
+                        }
+                    }
+                    break;
+            }
+            // If a mandatory match failed, the entire search has failed
+            // and we return an empty result.
+            if($term->is_mandatory() && !$matched) {
+                return array();
+            }
+            // If a negative match succeeded, the entire search has failed
+            // and we return an empty result.
+            if($term->is_negative() && $matched) {
+                return array();
+            }
+        }
+        return $matches;
+    }
+
+    private function match_tags($term) {
+        $tags = $this->get_tags();
+        $matches = array();
+        foreach($tags as $tag) {
+            if(match($term, $tag)) {
+                $matches[] = $tag;
             }
         }
         return $matches;
diff --git a/include/SearchPage.php b/include/SearchPage.php
index 859605f..2e9340b 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -28,11 +28,7 @@ class SearchPage extends Page {
         if(!$this->terms) {
             return $out;
         }
-        print('<br>');
         foreach(array('user', 'product') as $type) {
-            // print('=== DEBUG $type: ');
-            // print_r($type);
-            // print(' ===<br><br>');
             $result = $this->search($type, $this->terms);
             if($result) {
                 $out[$type] = $result;
@@ -42,148 +38,32 @@ class SearchPage extends Page {
     }
 
     private function search($type, $terms) {
-
-        /*
-        ==================================================
-
-        ORIGINAL CODE || BACKUP || FOR REFERENCE
-
-        $items = get_items($type);
-        $out = array();
-        foreach($items as $item) {
-            $result = $item->matches($terms);
-            if($result) {
-                $out[] = array($item, $result);
+        $matches = array();
+        foreach(get_items($type) as $item) {
+            if($result = $item->matches($terms, $this->ldap)) {
+                $matches[] = array($item, $result);
             }
         }
-        return $out;
-    
-        ==================================================
-        */
-
-        $mustMatchArray = array(); 
-        $cannotMatchArray = array(); 
-        $mayMatchArray = array();
-        foreach($terms as $key => $value) {
-            if(!is_array($value)) {
-                $value = array($value);
-            }
-            foreach($value as $term) {
-                switch ($term[0]) {
-                    case "+":
-                        if (!array_key_exists($key, $mustMatchArray)) {
-                            $mustMatchArray[$key] = array();
-                        }
-                        $mustMatchArray[$key][] = substr($term, 1);
-                        break;
-                    case "!":
-                    case "-":
-                        if (!array_key_exists($key, $cannotMatchArray)) {
-                            $cannotMatchArray[$key] = array();
-                        }
-                        $cannotMatchArray[$key][] = substr($term, 1);
-                        break;
-                    case "~":
-                        if (!array_key_exists($key, $mayMatchArray)) {
-                            $mayMatchArray[$key] = array();
-                        }
-                        $mayMatchArray[$key][] = substr($term, 1);
-                        break;
-                    default:
-                        if (!array_key_exists($key, $mayMatchArray)) {
-                            $mayMatchArray[$key] = array();
-                        }
-                        $mayMatchArray[$key][] = $term;
-                        break;
-                }
-            }
-        }
-
-        $items = get_items($type);
-        $sanitizedItems = array();
-        foreach($items as $item) {
-            $result = $item->matches($mustMatchArray, True);
-            if($result) {
-                $sanitizedItems[] = array($item, $result);
-            }
-
-            // $mustMatchCheck = array();
-            // foreach($mustMatchArray as $mustMatchTerm) {
-
-            //     $matchResult = $item->matches($mustMatchTerm);
-            //     if($matchResult) {
-            //         $mustMatchCheck[] = True;
-            //     } else {
-            //         $mustMatchCheck[] = False;
-            //     }
-            // }
-            // if(in_array(False, $mustMatchCheck, True) === False) {
-            //     $sanitizedItems[] = array($item, $matchResult);
-            // }
-
-            
-
-            // $mustExcludeCheck = array();
-            // foreach($mustExcludeArray as $mustExcludeTerm) {
-            //     if($item->matches($mustExcludeTerm)) {
-            //         $mustExcludeCheck[] = False;
-            //     } else {
-            //         $mustExcludeCheck[] = True;
-            //     }
-            // }
-
-            // if (in_array(False, $mustIncludeCheck, True) === False) {
-            //     if(in_array(False, $mustExcludeCheck, True) === True) {
-
-            //         //  === IF TRUE DO NOTHING ===
-
-            //     } else {
-            //         foreach ($canIncludeArray as $canIncludeTerm) {                    
-            //             $result = $item->matches($canIncludeTerm);
-            //             if($result) {
-            //                 $out[] = array($item, $result);
-            //             }
-            //         }
-            //     }
-            // }
-        }
-        print('DEBUG $sanitizedItems: ');
-        var_dump($sanitizedItems);
-        print('<br><br>');
-        // $out = array();
-        // foreach($sanitizedItems as $sanitizedItem) {
-        //     print('DEBUG $sanitizedItem: ');
-        //     var_dump($sanitizedItem);
-        //     print('<br><br>');
-
-        //     if($sanitizedItem->matches($cannotMatchArray)) {
-
-        //         //  === IF TRUE DO NOTHING ===
-
-        //     }
-        //     else {
-        //         $result = $sanitizedItem->matches($mayMatchArray);
-        //         if($result) {
-        //             $out[] = array($sanitizedItem, $result);
-        //         }
-        //     }
-        // }
-
-        // return array();
-        // return $out;
-        return $sanitizedItems;
+        return $matches;
     }
 
     private function translate_terms($terms) {
         $matches = array();
+
+        // If there is a q-query
+        // and it contains a : character
         if(isset($terms['q']) && preg_match('/([^:]+):(.*)/',
                                             $terms['q'],
                                             $matches)) {
+            // remove the q key
             unset($terms['q']);
+            // insert the term, using whatever came before
+            // the : as the key and whatever came after as the value
             $terms[$matches[1]] = $matches[2];
         }
         $translated = array();
-        foreach($terms as $key => $value) {
+        // Translate all keys into a standard format
+        foreach($terms as $key => $values) {
             $newkey = $key;
             switch($key) {
                 case 'q':
@@ -204,17 +84,38 @@ class SearchPage extends Page {
                     $newkey = 'serial';
                     break;
                 case 'tagg':
+                case 'tags':
                     $newkey = 'tag';
                     break;
+                case 'anteckning':
+                    $newkey = 'note';
+                    break;
+                case 'e-post':
+                case 'epost':
+                case 'mail':
+                    $newkey = 'email';
+                    break;
                 case 'status':
-                    $value = $this->translate_values($value);
+                    // Translate all status values into a standard format
+                    $values = $this->translate_values($values);
                     break;
             }
-            if(!array_key_exists($newkey, $translated)) {
-                $translated[$newkey] = $value;
-            } else {
-                $temp = $translated[$newkey];
-                $translated[$newkey] = array_merge((array)$temp, (array)$value);
+            // Wrap the value in an array if it isn't one
+            if(!is_array($values)) {
+                $values = array($values);
+            }
+            // Make a SearchTerm object from each term
+            foreach($values as $value) {
+                // Check for flags
+                $flag = SearchTerm::OPTIONAL;
+                if(in_array($value[0], array(SearchTerm::MANDATORY,
+                                             SearchTerm::OPTIONAL,
+                                             SearchTerm::NEGATIVE))) {
+                    $flag = $value[0];
+                    $value = substr($value, 1);
+                }
+                // Collect the new SearchTerm
+                $translated[] = new SearchTerm($key, $value, $flag);
             }
         }
         return $translated;
@@ -270,16 +171,15 @@ class SearchPage extends Page {
         $terms = '';
         if($this->terms) {
             $hidden = '';
-            foreach($this->terms as $key => $value) {
-                if(!is_array($value)) {
-                    $value = array($value);
-                }
-                foreach($value as $item) {
-                    $terms .= replace(array('term' => ucfirst($key).": $item",
-                                            'key' => $key,
-                                            'value' => $item),
-                                      $this->fragments['search_term']);
-                }
+            foreach($this->terms as $term) {
+                $key = $term->get_key();
+                $flag = $term->get_flag();
+                $query = $term->get_query();
+                $fullterm = ucfirst($key).": ".$flag.$query;
+                $terms .= replace(array('term' => $fullterm,
+                                        'key' => $key,
+                                        'value' => $flag.$query),
+                                  $this->fragments['search_term']);
             }
         }
         $products = 'Inga artiklar hittade.';
@@ -327,4 +227,53 @@ class SearchPage extends Page {
              . $data . '<br/>';
     }
 }
+
+class SearchTerm {
+    public const MANDATORY = '+';
+    public const OPTIONAL = '~';
+    public const NEGATIVE = '-';
+
+    private $key;
+    private $query;
+    private $flag;
+
+    public function __construct($key, $query, $flag=SearchTerm::OPTIONAL) {
+        $this->key = $key;
+        $this->query = $query;
+        $this->flag = $flag;
+    }
+
+    public function get_key() {
+        return $this->key;
+    }
+
+    public function get_query() {
+        return $this->query;
+    }
+
+    public function get_flag() {
+        return $this->flag;
+    }
+
+    public function is_optional() {
+        if($this->flag == SearchTerm::OPTIONAL) {
+            return true;
+        }
+        return false;
+    }
+
+    public function is_mandatory() {
+        if($this->flag == SearchTerm::MANDATORY) {
+            return true;
+        }
+        return false;
+    }
+
+    public function is_negative() {
+        if($this->flag == SearchTerm::NEGATIVE) {
+            return true;
+        }
+        return false;
+    }
+}
 ?>
diff --git a/include/User.php b/include/User.php
index 34d5699..d77475f 100644
--- a/include/User.php
+++ b/include/User.php
@@ -45,37 +45,60 @@ class User extends Entity {
         return true;
     }
 
-    public function matches($terms, $ldap, $matchAll=false) {
-        $terms = $this->specify_search($terms, array('name',
-                                                     'email',
-                                                     'notes'));
+    public function matches($terms, $ldap) {
         $matches = array();
-        foreach($terms as $field => $values) {
-            switch($field) {
+        foreach($terms as $term) {
+            // Iterate over the terms
+            $matched = false;
+            $key = $term->get_key();
+            switch($key) {
                 case 'name':
-                    if(match($values, $this->name)) {
-                        $matches['name'] = $this->name;
+                    // If the key is name, check username and displayname
+                    $name = $this->get_name();
+                    if(match($term, $name)) {
+                        $matches['name'] = $name;
+                        $matched = true;
                     }
                     $dname = $this->get_displayname($ldap);
-                    if(match($values, $dname)) {
+                    if(match($term, $dname)) {
                         $matches['displayname'] = $dname;
+                        $matched = true;
+                    }
+                    break;
+                case 'note':
+                    // If the key is note, check it.
+                    $note = $this->get_note();
+                    if($note && match($term, $note)) {
+                        $matches['note'] = $note;
+                        $matched = true;
                     }
                     break;
                 case 'email':
                     $email = $this->get_email($ldap, false);
-                    if($email && match($values, $email)) {
+                    if($email && match($term, $email)) {
                         $matches['email'] = $email;
+                        $matched = true;
                     }
                     break;
-                case 'notes':
-                    if(match($values, $this->notes)) {
-                        $matches['notes'] = $this->notes;
+                case 'fritext':
+                    //Check everything if the key is fritext
+                    $name = $this->get_name();
+                    if(match($term, $name)) {
+                        $matches['name'] = $name;
+                        $matched = true;
+                    }
+                    $dname = $this->get_displayname($ldap);
+                    if(match($term, $dname)) {
+                        $matches['displayname'] = $dname;
+                        $matched = true;
                     }
-                    break;
             }
-        }
-        if($matchAll && array_diff_assoc($terms, $matches)) {
-            return array();
+            if($term->is_mandatory() && !$matched) {
+                return array();
+            }
+            if($term->is_negative() && $matched) {
+                return array();
+            }
         }
         return $matches;
     }
diff --git a/include/functions.php b/include/functions.php
index 099b4bb..b85f1b3 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -253,18 +253,23 @@ function suggest_content($fieldname) {
     return $out;
 }
 
-function match($searchterms, $subject) {
-    if(!is_array($searchterms)) {
-        $searchterms = array($searchterms);
-    }
-    foreach($searchterms as $term) {
-        if(fnmatch('*'.$term.'*', $subject, FNM_CASEFOLD)) {
-            return true;
-        }
+function match($term, $subject) {
+    if(fnmatch('*'.$term->get_query().'*', $subject, FNM_CASEFOLD)) {
+        return true;
     }
     return false;
 }
 
+function match_tags($searchterm, $tags) {
+    $found = array();
+    foreach($tags as $tag) {
+        if(fnmatch('*'.$tag.'*', $searchterm, FNM_CASEFOLD)) {
+            $found[] = $tag;
+        }
+    }
+    return $found;
+}
+
 function format_date($date) {
     if($date) {
         return gmdate('Y-m-d', $date);

From dbdceadb5eba5d175837014091c0ce2111a12699 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Wed, 15 Sep 2021 16:34:25 +0200
Subject: [PATCH 217/250] Added the ability to search on product status

---
 include/Product.php | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/Product.php b/include/Product.php
index 13b9322..9a4798c 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -120,7 +120,8 @@ class Product extends Entity {
         $fields = array('brand' => 'get_brand',
                         'name' => 'get_name',
                         'invoice' => 'get_invoice',
-                        'serial' => 'get_serial');
+                        'serial' => 'get_serial',
+                        'status' => 'get_status');
 
         foreach($terms as $term) {
             $key = $term->get_key();
@@ -130,6 +131,7 @@ class Product extends Entity {
                 case 'name':
                 case 'invoice':
                 case 'serial':
+                case 'status':
                     // If $key is a standard field, check against its value
                     $getter = $fields[$key];
                     $value = $this->$getter();

From cb4a3b131ac53437999b8e47b65e2b47fcb395d7 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Wed, 22 Sep 2021 15:14:35 +0200
Subject: [PATCH 218/250] Implemented picking users based on email on the
 checkout page

---
 html/fragments.html      | 14 ++++++++--
 include/CheckoutPage.php | 56 ++++++++++++++++++++++++++++++++++------
 include/Ldap.php         | 19 +++++++-------
 3 files changed, 70 insertions(+), 19 deletions(-)

diff --git a/html/fragments.html b/html/fragments.html
index b09a101..409dc08 100644
--- a/html/fragments.html
+++ b/html/fragments.html
@@ -534,12 +534,22 @@
              list="user_suggest"
              autocomplete="off"
              placeholder="Användarnamn"
-             value="¤user¤"
-             required />
+             value="¤user¤" />
       <button type="submit" >
         Välj
       </button>
     </div>
+    <div>
+      <label for="email">
+        E-post:
+      </label>
+      <input type="text"
+             name="email"
+             id="email"
+             autocomplete="off"
+             placeholder="E-post"
+             value="¤email¤" />
+    </div>
     <div>
       <label for="displayname">
         Namn:
diff --git a/include/CheckoutPage.php b/include/CheckoutPage.php
index 1da4759..e779b1c 100644
--- a/include/CheckoutPage.php
+++ b/include/CheckoutPage.php
@@ -1,30 +1,68 @@
 <?php
 class CheckoutPage extends Page {
     private $userstr = '';
+    private $emailstr = '';
     private $user = null;
 
     public function __construct() {
         parent::__construct();
         if(isset($_GET['user'])) {
             $this->userstr = trim(strtolower($_GET['user']));
+        }
+        if(isset($_GET['email'])) {
+            $this->emailstr = trim(strtolower($_GET['email']));
+        }
+        try {
+            $this->user = $this->user_init($this->userstr,
+                                           $this->emailstr);
+        } catch(Exception $e) {
+            $this->error = $e->getMessage();
+        }
+    }
+
+    protected function user_init($name, $email) {
+        $nameuser = null;
+        $emailuser = null;
+        if($name) {
             try {
-                $this->user = new User($this->userstr, 'name');
+                $nameuser = new User($this->userstr, 'name');
             } catch(Exception $ue) {
+                # The user wasn't found locally
                 try {
-                    $ldap = new Ldap();
-                    $ldap->get_user($this->userstr);
-                    $this->user = User::create_user($this->userstr);
+                    $this->ldap->get_user($this->userstr);
+                    $nameuser = User::create_user($this->userstr);
                 } catch(Exception $le) {
-                    $this->error = "Användarnamnet '";
-                    $this->error .= $this->userstr;
-                    $this->error .= "' kunde inte hittas.";
+                    $err = "Användarnamnet '$name' kunde inte hittas.";
+                    throw new Exception($err);
                 }
             }
         }
+        if($email) {
+            try {
+                # Lookup email directly in ldap since we don't store it
+                $emailuser = new User($this->ldap->search_email($email),
+                                      'name');
+            } catch(Exception $ue) {
+                $err = "E-postadressen '$emailuser' kunde inte hittas.";
+                throw new Exception($err);
+            }
+        }
+        if($nameuser && $emailuser) {
+            if($nameuser != $emailuser) {
+                $err = "Användarnamn och e-post matchar olika användare.";
+                throw new Exception($err);
+            }
+            return $nameuser;
+        }
+        if($nameuser) {
+            return $nameuser;
+        }
+        return $emailuser;
     }
 
     protected function render_body() {
         $username = '';
+        $email = '';
         $displayname = '';
         $notes = '';
         $loan_table = '';
@@ -33,6 +71,7 @@ class CheckoutPage extends Page {
         $disabled = 'disabled';
         if($this->user !== null) {
             $username = $this->user->get_name();
+            $email = $this->user->get_email($this->ldap);
             $displayname = $this->user->get_displayname($this->ldap);
             $notes = $this->user->get_notes();
             $enddate = format_date(default_loan_end(time()));
@@ -45,7 +84,8 @@ class CheckoutPage extends Page {
             $subhead = replace(array('title' => 'Lånade artiklar'),
                                $this->fragments['subtitle']);
         }
-        print(replace(array('user' => $this->userstr,
+        print(replace(array('user' => $username,
+                            'email' => $email,
                             'displayname' => $displayname,
                             'notes' => $notes,
                             'end' => $enddate,
diff --git a/include/Ldap.php b/include/Ldap.php
index 91c7c84..00e17b4 100644
--- a/include/Ldap.php
+++ b/include/Ldap.php
@@ -17,7 +17,8 @@ class Ldap {
     public function get_user($uid) {
         $data = $this->search("uid=$uid", 'cn', 'uid');
         if($data['count'] !== 1) {
-            throw new Exception("LDAP search for '$uid' did not return exactly one result");
+            $err = "LDAP search for '$uid' did not return exactly one result";
+            throw new Exception($err);
         }
         return $data[0]['cn'][0];
     }
@@ -25,20 +26,20 @@ class Ldap {
     public function get_user_email($uid) {
         $data = $this->search("uid=$uid", 'mail', 'uid');
         if($data['count'] !== 1) {
-            throw new Exception("LDAP search for '$uid' did not return exactly one result");
+            $err = "LDAP search for '$uid' did not return exactly one result";
+            throw new Exception($err);
         }
         return $data[0]['mail'][0];
     }
 
-    public function search_user($uid) {
-        $data = $this->search("uid=$uid", 'cn', 'uid');
+    public function search_email($email) {
+        $data = $this->search("mail=$email", 'mail', 'uid');
         $out = array();
-        foreach($data as $result) {
-            if(isset($result['uid'])) {
-                $out[$result['uid'][0]] = $result['cn'][0];
-            }
+        if($data['count'] !== 1) {
+            $err = "LDAP search for '$email' did not return exactly one result.";
+            throw new Exception($err);
         }
-        return $out;
+        return $data[0]['uid'][0];
     }
 }
 ?>

From 4fbffa1402bdedb531601494854c2a22b70203c0 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Wed, 22 Sep 2021 15:34:33 +0200
Subject: [PATCH 219/250] Changed checkoutPage email search behaviour Now a
 default domain is appended on email string that don't contain an @ character

---
 include/CheckoutPage.php | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/include/CheckoutPage.php b/include/CheckoutPage.php
index e779b1c..e209b81 100644
--- a/include/CheckoutPage.php
+++ b/include/CheckoutPage.php
@@ -25,12 +25,12 @@ class CheckoutPage extends Page {
         $emailuser = null;
         if($name) {
             try {
-                $nameuser = new User($this->userstr, 'name');
+                $nameuser = new User($name, 'name');
             } catch(Exception $ue) {
                 # The user wasn't found locally
                 try {
-                    $this->ldap->get_user($this->userstr);
-                    $nameuser = User::create_user($this->userstr);
+                    $this->ldap->get_user($name);
+                    $nameuser = User::create_user($name);
                 } catch(Exception $le) {
                     $err = "Användarnamnet '$name' kunde inte hittas.";
                     throw new Exception($err);
@@ -39,11 +39,15 @@ class CheckoutPage extends Page {
         }
         if($email) {
             try {
+                $search = $email;
+                if(strpos($email, '@') === false) {
+                    $search = $email .'@dsv.su.se';
+                }
                 # Lookup email directly in ldap since we don't store it
-                $emailuser = new User($this->ldap->search_email($email),
+                $emailuser = new User($this->ldap->search_email($search),
                                       'name');
             } catch(Exception $ue) {
-                $err = "E-postadressen '$emailuser' kunde inte hittas.";
+                $err = "E-postadressen '$search' kunde inte hittas.";
                 throw new Exception($err);
             }
         }
@@ -61,8 +65,8 @@ class CheckoutPage extends Page {
     }
 
     protected function render_body() {
-        $username = '';
-        $email = '';
+        $username = $this->userstr;
+        $email = $this->emailstr;
         $displayname = '';
         $notes = '';
         $loan_table = '';

From 8502fbf0a15025204d3b9384fc978ef0d09b3914 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Tue, 1 Mar 2022 16:33:00 +0100
Subject: [PATCH 220/250] Initial implementation of search result detail output

---
 html/fragments.html     |  22 ++++++++-
 include/NewPage.php     |   2 +-
 include/Page.php        | 102 +++++++++++++++++++++++++---------------
 include/ProductPage.php |   6 +--
 include/SearchPage.php  |  31 +++++-------
 style.css               |  13 +++++
 6 files changed, 113 insertions(+), 63 deletions(-)

diff --git a/html/fragments.html b/html/fragments.html
index 409dc08..ee6f993 100644
--- a/html/fragments.html
+++ b/html/fragments.html
@@ -105,6 +105,26 @@
   </td>
 </tr>
 
+¤¤ product_detail_row ¤¤
+<tr>
+  <td class="status ¤status¤">
+  </td>
+  <td colspan="3">
+    <div class="minitable">
+      ¤details¤
+    </div>
+  </td>
+</tr>
+
+¤¤ product_detail ¤¤
+<span class="minitable_name">
+  ¤name¤
+</span>
+<span class="minitable_value">
+  ¤value¤
+</span>
+<br/>
+
 ¤¤ template_management ¤¤
 <div>
   <h2>Mallar</h2>
@@ -133,7 +153,7 @@
   </form>
 </div>
 
-¤¤ product_details ¤¤
+¤¤ product_form ¤¤
 <div id="product-details">
   <h2>Artikeldata</h2>
   <form id="product-data"
diff --git a/include/NewPage.php b/include/NewPage.php
index ffe6a48..dd0e15e 100644
--- a/include/NewPage.php
+++ b/include/NewPage.php
@@ -49,7 +49,7 @@ class NewPage extends Page {
                               'info' => $fields,
                               'label' => '',
                               'hidden' => 'hidden'),
-                        $this->fragments['product_details']);
+                        $this->fragments['product_form']);
         return $out;
     }
 }
diff --git a/include/Page.php b/include/Page.php
index 696bed7..8a79123 100644
--- a/include/Page.php
+++ b/include/Page.php
@@ -128,48 +128,72 @@ abstract class Page extends Responder {
                        $this->fragments['user_table']);
     }
 
+    final protected function build_product_row($product, $matches = null) {
+        $prodlink = replace(array('id' => $product->get_id(),
+                                  'name' => $product->get_name(),
+                                  'page' => 'products'),
+                            $this->fragments['item_link']);
+        $note = 'Tillgänglig';
+        $status = $product->get_status();
+        switch($status) {
+        case 'discarded':
+            $discarded = format_date($product->get_discardtime());
+            $note = 'Skrotad '.$discarded;
+            break;
+        case 'service':
+            $service = $product->get_active_service();
+            $note = 'På service sedan '
+                  .format_date($service->get_starttime());
+            break;
+        case 'on_loan':
+        case 'overdue':
+            $loan = $product->get_active_loan();
+            $user = $loan->get_user();
+            $replacements = array('name' => $user->get_displayname($this->ldap),
+                                  'id'   => $user->get_id(),
+                                  'page' => 'users');
+            $userlink = replace($replacements,
+                                $this->fragments['item_link']);
+            $note = 'Utlånad till '.$userlink;
+            if($loan->is_overdue()) {
+                $note .= ', försenad';
+            } else {
+                $note .= ', slutdatum '
+                      .format_date($loan->get_endtime());
+            }
+            break;
+        }
+        $out = replace(array('status'    => $status,
+                             'item_link' => $prodlink,
+                             'serial'    => $product->get_serial(),
+                             'note'      => $note),
+                       $this->fragments['product_row']);
+        if($matches) {
+            $details = $this->build_product_details($product, $matches);
+            $out .= replace(array('status'  => $status,
+                                  'details' => $details),
+                            $this->fragments['product_detail_row']);
+        }
+        return $out;
+    }
+
+    final protected function build_product_details($product, $matches) {
+        $out = '';
+        foreach($matches as $name => $value) {
+            if(is_array($value)) {
+                $value = implode(', ', $value);
+            }
+            $out .= replace(array('name'   => ucfirst($name),
+                                  'value'  => $value),
+                            $this->fragments['product_detail']);
+        }
+        return $out;
+    }
+
     final protected function build_product_table($products) {
         $rows = '';
         foreach($products as $product) {
-            $prodlink = replace(array('id' => $product->get_id(),
-                                      'name' => $product->get_name(),
-                                      'page' => 'products'),
-                                $this->fragments['item_link']);
-            $note = 'Tillgänglig';
-            $status = $product->get_status();
-            switch($status) {
-                case 'discarded':
-                    $discarded = format_date($product->get_discardtime());
-                    $note = 'Skrotad '.$discarded;
-                    break;
-                case 'service':
-                    $service = $product->get_active_service();
-                    $note = 'På service sedan '
-                                .format_date($service->get_starttime());
-                    break;
-                case 'on_loan':
-                case 'overdue':
-                    $loan = $product->get_active_loan();
-                    $user = $loan->get_user();
-                    $replacements = array('name' => $user->get_displayname($this->ldap),
-                                          'id'   => $user->get_id(),
-                                          'page' => 'users');
-                    $userlink = replace($replacements,
-                                        $this->fragments['item_link']);
-                    $note = 'Utlånad till '.$userlink;
-                    if($loan->is_overdue()) {
-                        $note .= ', försenad';
-                    } else {
-                        $note .= ', slutdatum '
-                                .format_date($loan->get_endtime());
-                    }
-                    break;
-            }
-            $rows .= replace(array('status' => $status,
-                                   'item_link' => $prodlink,
-                                   'serial' => $product->get_serial(),
-                                   'note' => $note),
-                             $this->fragments['product_row']);
+            $rows .= $this->build_product_row($product);
         }
         return replace(array('rows' => $rows),
                        $this->fragments['product_table']);
diff --git a/include/ProductPage.php b/include/ProductPage.php
index e385f62..afb25b1 100644
--- a/include/ProductPage.php
+++ b/include/ProductPage.php
@@ -38,12 +38,12 @@ class ProductPage extends Page {
                               $this->fragments['product_page']));
                 break;
             case 'show':
-                print($this->build_product_details());
+                print($this->build_product_form());
                 break;
         }
     }
     
-    private function build_product_details() {
+    private function build_product_form() {
         $info = '';
         foreach($this->product->get_info() as $key => $value) {
             $info .= replace(array('name' => ucfirst($key),
@@ -81,7 +81,7 @@ class ProductPage extends Page {
                 $fields['service'] = 'Avsluta service';
             }
         }
-        return replace($fields, $this->fragments['product_details']);
+        return replace($fields, $this->fragments['product_form']);
     }
 
     private function build_history_table($history) {
diff --git a/include/SearchPage.php b/include/SearchPage.php
index 2e9340b..cfe8c4a 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -182,47 +182,40 @@ class SearchPage extends Page {
                                   $this->fragments['search_term']);
             }
         }
-        $products = 'Inga artiklar hittade.';
+        $prod_table = 'Inga artiklar hittade.';
         if($this->product_hits) {
             $products = '';
             foreach($this->product_hits as $hit) {
-                $products .= $this->render_product($hit[0], $hit[1]);
+                $products .= $this->build_product_row($hit[0], $hit[1]);
             }
+            $prod_table = replace(array('rows' => $products),
+                                  $this->fragments['product_table']);
         }
-        $users = 'Inga användare hittade.';
+        $user_table = 'Inga användare hittade.';
         if($this->user_hits) {
             $users = '';
             foreach($this->user_hits as $hit) {
                 $users .= $this->render_user($hit[0], $hit[1]);
             }
+            $user_table = replace(array('rows' => $users),
+                                  $this->fragments['user_table']);
         }
+
         print(replace(array('terms' => $terms,
                             'hidden' => $hidden,
-                            'product_results' => $products,
-                            'user_results' => $users),
+                            'product_results' => $prod_table,
+                            'user_results' => $user_table),
                       $this->fragments['search_form']));
     }
 
-    private function render_product($product, $matches) {
-        $link = replace(array('id' => $product->get_id(),
-                              'name' => $product->get_name(),
-                              'page' => 'products'),
-                        $this->fragments['item_link']);
-
-        $data =  print_r($matches, true);
-        
-        return $link . '<br/>'
-             . $data . '<br/>';
-    }
-
     private function render_user($user, $matches) {
         $link = replace(array('id' => $user->get_id(),
                               'name' => $user->get_name(),
                               'page' => 'users'),
                         $this->fragments['item_link']);
 
-        $data =  print_r($matches, true);
-        
+        $data = print_r($matches, true);
+
         return $link . '<br/>'
              . $data . '<br/>';
     }
diff --git a/style.css b/style.css
index c1ec303..76a9990 100644
--- a/style.css
+++ b/style.css
@@ -117,6 +117,19 @@ thead th:nth-last-child(-n+2) {
    word-break: break-word;
 }
 
+.minitable {
+    display: grid;
+    grid-template-columns: [col] auto [col] auto [col] auto [col];
+}
+
+.minitable_name {
+    grid-column: col 1;
+}
+
+.minitable_value {
+    grid-column: col 2;
+}
+
 input:disabled, textarea:disabled {
     background-color: #ededed;
 }

From 0f66c8212fe2829ee5f4e894dc168981d8159cb3 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Wed, 2 Mar 2022 10:18:54 +0100
Subject: [PATCH 221/250] User results are printed properly now

---
 include/SearchPage.php | 19 +++----------------
 1 file changed, 3 insertions(+), 16 deletions(-)

diff --git a/include/SearchPage.php b/include/SearchPage.php
index cfe8c4a..ffe29fd 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -193,12 +193,11 @@ class SearchPage extends Page {
         }
         $user_table = 'Inga användare hittade.';
         if($this->user_hits) {
-            $users = '';
+            $users = array();
             foreach($this->user_hits as $hit) {
-                $users .= $this->render_user($hit[0], $hit[1]);
+                $users[] = $hit[0];
             }
-            $user_table = replace(array('rows' => $users),
-                                  $this->fragments['user_table']);
+            $user_table = $this->build_user_table($users);
         }
 
         print(replace(array('terms' => $terms,
@@ -207,18 +206,6 @@ class SearchPage extends Page {
                             'user_results' => $user_table),
                       $this->fragments['search_form']));
     }
-
-    private function render_user($user, $matches) {
-        $link = replace(array('id' => $user->get_id(),
-                              'name' => $user->get_name(),
-                              'page' => 'users'),
-                        $this->fragments['item_link']);
-
-        $data = print_r($matches, true);
-
-        return $link . '<br/>'
-             . $data . '<br/>';
-    }
 }
 
 class SearchTerm {

From 3fae0ce1ff50a6db533c9a059bd04bf26c1403d2 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Thu, 3 Mar 2022 11:37:35 +0100
Subject: [PATCH 222/250] Search overhaul possibly finished?

---
 html/fragments.html    | 17 ++++++++---------
 include/Page.php       | 24 +++++++++++++-----------
 include/Product.php    | 23 +++++++++++++++++++++++
 include/SearchPage.php |  5 +++--
 style.css              | 30 ++++++++++++++++--------------
 5 files changed, 63 insertions(+), 36 deletions(-)

diff --git a/html/fragments.html b/html/fragments.html
index ee6f993..1e0e633 100644
--- a/html/fragments.html
+++ b/html/fragments.html
@@ -85,7 +85,7 @@
       </th>
     </tr>
   </thead>
-  <tbody>
+  <tbody class="¤type¤">
     ¤rows¤
   </tbody>
 </table>
@@ -110,20 +110,19 @@
   <td class="status ¤status¤">
   </td>
   <td colspan="3">
-    <div class="minitable">
+    <dl>
       ¤details¤
-    </div>
+    </dl>
   </td>
 </tr>
 
 ¤¤ product_detail ¤¤
-<span class="minitable_name">
-  ¤name¤
-</span>
-<span class="minitable_value">
+<dt>
+  ¤name¤:
+</dt>
+<dd>
   ¤value¤
-</span>
-<br/>
+</dd>
 
 ¤¤ template_management ¤¤
 <div>
diff --git a/include/Page.php b/include/Page.php
index 8a79123..1d2607e 100644
--- a/include/Page.php
+++ b/include/Page.php
@@ -128,6 +128,16 @@ abstract class Page extends Responder {
                        $this->fragments['user_table']);
     }
 
+    final protected function build_product_table($products) {
+        $rows = '';
+        foreach($products as $product) {
+            $rows .= $this->build_product_row($product);
+        }
+        return replace(array('rows' => $rows,
+                             'type' => 'single'),
+                       $this->fragments['product_table']);
+    }
+
     final protected function build_product_row($product, $matches = null) {
         $prodlink = replace(array('id' => $product->get_id(),
                                   'name' => $product->get_name(),
@@ -183,22 +193,13 @@ abstract class Page extends Responder {
             if(is_array($value)) {
                 $value = implode(', ', $value);
             }
-            $out .= replace(array('name'   => ucfirst($name),
+            $out .= replace(array('name'   => $product->get_label($name),
                                   'value'  => $value),
                             $this->fragments['product_detail']);
         }
         return $out;
     }
 
-    final protected function build_product_table($products) {
-        $rows = '';
-        foreach($products as $product) {
-            $rows .= $this->build_product_row($product);
-        }
-        return replace(array('rows' => $rows),
-                       $this->fragments['product_table']);
-    }
-
     final protected function build_user_loan_table($loans) {
         $rows = '';
         foreach($loans as $loan) {
@@ -284,7 +285,8 @@ abstract class Page extends Responder {
                                    'note' => $note),
                              $this->fragments['product_row']);
         }
-        return replace(array('rows' => $rows),
+        return replace(array('rows' => $rows,
+                             'type' => 'single'),
                        $this->fragments['product_table']);
 
     }
diff --git a/include/Product.php b/include/Product.php
index 9a4798c..1f4468c 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -228,6 +228,29 @@ class Product extends Entity {
         return $matches;
     }
 
+    public function get_label($name) {
+        switch($name) {
+            case 'brand':
+                return 'Tillverkare';
+                break;
+            case 'name':
+                return 'Namn';
+                break;
+            case 'invoice':
+                return 'Fakturanummer';
+                break;
+            case 'serial':
+                return 'Serienummer';
+                break;
+            case 'tags':
+                return 'Taggar';
+                break;
+            default:
+                return ucfirst($name);
+                break;
+        }
+    }
+
     public function get_id() {
         return $this->id;
     }
diff --git a/include/SearchPage.php b/include/SearchPage.php
index ffe29fd..1d47bf3 100644
--- a/include/SearchPage.php
+++ b/include/SearchPage.php
@@ -115,7 +115,7 @@ class SearchPage extends Page {
                     $value = substr($value, 1);
                 }
                 // Collect the new SearchTerm
-                $translated[] = new SearchTerm($key, $value, $flag);
+                $translated[] = new SearchTerm($newkey, $value, $flag);
             }
         }
         return $translated;
@@ -188,7 +188,8 @@ class SearchPage extends Page {
             foreach($this->product_hits as $hit) {
                 $products .= $this->build_product_row($hit[0], $hit[1]);
             }
-            $prod_table = replace(array('rows' => $products),
+            $prod_table = replace(array('rows' => $products,
+                                        'type' => 'double'),
                                   $this->fragments['product_table']);
         }
         $user_table = 'Inga användare hittade.';
diff --git a/style.css b/style.css
index 76a9990..61c9529 100644
--- a/style.css
+++ b/style.css
@@ -104,10 +104,25 @@ tbody tr {
     background-color: #d7e0eb;
 }
 
-tbody tr:nth-child(odd) {
+tbody.single tr:nth-child(odd) {
     background-color: #ebf0f5;
 }
 
+tbody.double tr:is(:nth-child(4n+1), :nth-child(4n+2)) {
+    background-color: #ebf0f5;
+}
+
+tbody dl {
+    margin: 0;
+    display: grid;
+    grid-template-columns: 2fr 5fr;
+}
+
+tbody dd {
+    margin: 0;
+    grid-column: 2;
+}
+
 thead th, tfoot tr {
     background-color: #c3d1e2;
 }
@@ -117,19 +132,6 @@ thead th:nth-last-child(-n+2) {
    word-break: break-word;
 }
 
-.minitable {
-    display: grid;
-    grid-template-columns: [col] auto [col] auto [col] auto [col];
-}
-
-.minitable_name {
-    grid-column: col 1;
-}
-
-.minitable_value {
-    grid-column: col 2;
-}
-
 input:disabled, textarea:disabled {
     background-color: #ededed;
 }

From 0ee0f810245229fc748526210952fa834824cb1a Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Fri, 29 Apr 2022 15:58:38 +0200
Subject: [PATCH 223/250] Changed cron behaviour to warn users 3 days before
 their loans end

---
 include/Cron.php | 221 +++++++++++++++++++++++++++++++++--------------
 include/Kvs.php  |   4 +-
 include/Ldap.php |  25 +++---
 include/Loan.php |  14 ++-
 include/User.php |  10 +++
 5 files changed, 194 insertions(+), 80 deletions(-)

diff --git a/include/Cron.php b/include/Cron.php
index 7ca58e8..ad6d26b 100644
--- a/include/Cron.php
+++ b/include/Cron.php
@@ -6,22 +6,26 @@ class Cron {
     private $kvs;
     private $ldap;
     public function __construct($sender, $error) {
-        $this->now = time();
+        $this->now = new DateTimeImmutable();
         $this->sender = $sender;
         $this->error = $error;
+        $warn_time = DateInterval::createFromDateString('3 days');
+        $this->warn_date = $this->now->add($warn_time);
+        $this->run_interval = DateInterval::createFromDateString('1 day');
         $this->kvs = new Kvs();
         $this->ldap = new Ldap();
     }
 
     public function run() {
-        $lastrun = $this->kvs->get_value('lastrun');
-        $interval = 3600*24; //1 day in seconds
-        
-        if($lastrun && $this->now - $lastrun < $interval) {
+        $lastrun = $this->kvs->get_value('lastrun', 0);
+        $nextrun = $this->now
+                        ->setTimestamp($lastrun)
+                        ->add($this->run_interval);
+        if($nextrun > $this->now) {
             return;
         }
-        $this->kvs->set_key('lastrun', $this->now);
-        
+        $this->kvs->set_key('lastrun', $this->now->getTimestamp());
+
         $users = get_items('user');
         foreach($users as $user) {
             $this->check_loans($user);
@@ -29,89 +33,174 @@ class Cron {
     }
 
     private function check_loans($user) {
+        $expiring = $user->get_expiring_loans($this->warn_date);
         $overdue = $user->get_overdue_loans();
-        if($overdue) {
-            $this->send_reminder($user, $overdue);
+        if($expiring || $overdue) {
+            $this->send_reminder($user, $expiring, $overdue);
         }
     }
-    
-    private function send_reminder($user, $loans) {
-        $subject_template = "DSV Helpdesk: Du har ¤count¤ ¤late¤ lån";
-        $reminder_template_sv = "¤brand¤ ¤name¤, försenad sedan ¤due¤\n";
-        $reminder_template_en = "¤brand¤ ¤name¤, late since ¤due¤\n";
-        $message_template = <<<EOF
-Hej ¤name¤
 
-Vi vill påminna dig om att ditt lån har gått ut på följande ¤product_sv¤:
+    private function make_subject($num_expiring, $num_expired) {
+        $subject = "DSV Helpdesk: ";
+        $messages = array();
+        if($num_expiring > 0) {
+            $messages[] = $num_expiring." utgående lån";
+        }
+        if($num_expired > 1) {
+            $messages[] = $num_expired." försenade lån";
+        } elseif($num_expired > 0) {
+            $messages[] = $num_expired." försenat lån";
+        }
+        return $subject.implode(" och ", $messages);
+    }
 
-¤list_sv¤
+    private function make_expiring_notice($lang, $expiring) {
+        if(!$expiring) {
+            return '';
+        }
+        $days = $this->warn_date->d;
+        switch($lang) {
+            case 'sv':
+                $msg = "Följande lån går ut om mindre än ".$days." dagar:";
+                $itemglue = ", går ut ";
+                break;
+            case 'en':
+                if(count($expiring) == 1) {
+                    $loanstr = "loan expires";
+                } else {
+                    $loanstr = "loans expire";
+                }
+                $msg = "The following ".$loanstr." in less than ".$days." days:";
+                $itemglue = ", expires on ";
+                break;
+            default:
+                throw new Exception("Invalid language: ".$lang);
+        }
+        $msg .= "\n\n";
+        foreach($expiring as $loan) {
+            $product = $loan->get_product();
+            $serial = $product->get_serial();
+            $brand = $product->get_brand();
+            $name = $product->get_name();
+            $endtime = format_date($loan->get_endtime());
+            $msg .= $serial.": ".$brand." ".$name.$itemglue.$endtime;
+        }
+        return $msg;
+    }
 
-Vänligen återlämna ¤it_sv¤ till Helpdesk så snart som möjligt, alternativt svara på det här meddelandet för att förlänga ¤loan_sv¤.
+    private function make_overdue_notice($lang, $overdue) {
+        if(!$overdue) {
+            return '';
+        }
+        switch($lang) {
+            case 'sv':
+                $msg = "Följande lån har gått ut:";
+                $itemglue = ", gick ut ";
+                break;
+            case 'en':
+                if(count($overdue) == 1) {
+                    $msg = "The following loan has expired:";
+                } else {
+                    $msg = "The following loans have expired:";
+                }
+                $itemglue = ", expired on ";
+                break;
+            default:
+                throw new Exception("Invalid language: ".$lang);
+        }
+        $msg .= "\n\n";
+        foreach($overdue as $loan) {
+            $product = $loan->get_product();
+            $serial = $product->get_serial();
+            $brand = $product->get_brand();
+            $name = $product->get_name();
+            $endtime = format_date($loan->get_endtime());
+            $msg .= $serial.": ".$brand." ".$name.$itemglue.$endtime;
+        }
+        return $msg;
+    }
+
+    private function make_return_info($lang, $count) {
+        switch($lang) {
+            case 'sv':
+                if($count > 1) {
+                    $loan = "lånen";
+                    $product = "artiklarna";
+                } else {
+                    $loan = "lånet";
+                    $product = "artikeln";
+                }
+                return "Vänligen kontakta Helpdesk för att förlänga $loan eller lämna tillbaka $product.";
+                break;
+            case 'en':
+                if($count > 1) {
+                    $loan = "loans";
+                    $product = "items";
+                } else {
+                    $loan = "loan";
+                    $product = "item";
+                }
+                return "Please contact Helpdesk in order to extend the $loan or return the $product.";
+                break;
+            default:
+                throw new Exception("Invalid language: ".$lang);
+        }
+
+    }
+
+    private function send_reminder($user, $expiring, $expired) {
+        $uid = $user->get_name();
+        $name = $this->ldap->get_firstname($uid);
+
+        $subject = $this->make_subject(count($expiring), count($expired));
+
+        $info_sv = array();
+        $info_sv[] = $this->make_expiring_notice('sv', $expiring);
+        $info_sv[] = $this->make_overdue_notice('sv', $expired);
+        $info_sv = implode("\n\n", $info_sv);
+        $returns_sv = $this->make_return_info(
+            'sv', count($expiring) + count($expired));
+
+        $info_en = array();
+        $info_en[] = $this->make_expiring_notice('en', $expiring);
+        $info_en[] = $this->make_overdue_notice('en', $expired);
+        $info_en = implode("\n\n", $info_en);
+        $returns_en = $this->make_return_info(
+            'en', count($expiring) + count($expired));
+
+        $message = <<<EOF
+Hej $name!
+
+Det här är en automatisk påminnelse om lånade artiklar från Helpdesk.
+
+$info_sv
+
+$returns_sv
 
 ----
 
-We would like to remind you that your loan has expired on the following ¤product_en¤:
+This is an automated reminder regarding items on loan from Helpdesk.
 
-¤list_en¤
+$info_en
 
-Please return ¤it_en¤ to the Helpdesk as soon as possible, or reply to this message in order to extend the ¤loan_en¤.
+$returns_en
 
 Mvh
 DSV Helpdesk
 helpdesk@dsv.su.se
 08 - 16 16 48
+
 EOF;
-
-        $overdue_count = count($loans);
-        $reminder_list_sv = '';
-        $reminder_list_en = '';
-        $late = 'försenat';
-        $product_sv = 'artikel';
-        $product_en = 'product';
-        $it_sv = 'den';
-        $it_en = 'it';
-        $loan_sv = 'lånet';
-        $loan_en = 'loan';
-        if($overdue_count > 1) {
-            $late = 'försenade';
-            $product_sv = 'artiklar';
-            $product_en = 'products';
-            $it_sv = 'dem';
-            $it_en = 'them';
-            $loan_sv = 'lånen';
-            $loan_en = 'loans';
-        }
-        foreach($loans as $loan) {
-            $replacements = array('name'  => $loan->get_product()->get_name(),
-                                  'brand' => $loan->get_product()->get_brand(),
-                                  'due'   => format_date($loan->get_endtime()));
-            $reminder_list_sv .= replace($replacements, $reminder_template_sv);
-            $reminder_list_en .= replace($replacements, $reminder_template_en);
-        }
-
-        $subject = replace(array('count' => $overdue_count,
-                                 'late'  => $late), $subject_template);
-        $message = replace(array('name'       => $user->get_displayname($this->ldap),
-                                 'list_sv'    => $reminder_list_sv,
-                                 'product_sv' => $product_sv,
-                                 'it_sv'      => $it_sv,
-                                 'loan_sv'    => $loan_sv,
-                                 'list_en'    => $reminder_list_en,
-                                 'product_en' => $product_en,
-                                 'it_en'      => $it_en,
-                                 'loan_en'    => $loan_en),
-                           $message_template);
-
         try {
-            mb_send_mail($user->get_email($this->ldap),
+            mb_send_mail($this->ldap->get_user_email($uid),
                          $subject,
                          $message,
                          'From: '.$this->sender);
         } catch(Exception $e) {
+            error_log($e->message);
             mb_send_mail($this->error,
                          "Kunde inte skicka påminnelse",
-                         "Påminnelse kunde inte skickas till "
-                         .$user->get_name());
+                         "Påminnelse kunde inte skickas till ".$uid);
         }
     }
 }
diff --git a/include/Kvs.php b/include/Kvs.php
index e80edf8..2900dcd 100644
--- a/include/Kvs.php
+++ b/include/Kvs.php
@@ -16,11 +16,11 @@ class Kvs {
         return array_keys($this->items);
     }
     
-    public function get_value($key) {
+    public function get_value($key, $default=null) {
         if(isset($this->items[$key])) {
             return $this->items[$key];
         }
-        return null;
+        return $default;
     }
     
     public function set_key($key, $value) {
diff --git a/include/Ldap.php b/include/Ldap.php
index 00e17b4..f43d7f9 100644
--- a/include/Ldap.php
+++ b/include/Ldap.php
@@ -2,7 +2,7 @@
 class Ldap {
     private $conn;
     private $base_dn = "dc=su,dc=se";
-    
+
     public function __construct() {
         $this->conn = ldap_connect('ldaps://ldap.su.se');
         ldap_set_option($this->conn, LDAP_OPT_PROTOCOL_VERSION, 3);
@@ -13,23 +13,26 @@ class Ldap {
         $result = ldap_search($this->conn, $this->base_dn, $term, $attributes);
         return ldap_get_entries($this->conn, $result);
     }
-    
-    public function get_user($uid) {
-        $data = $this->search("uid=$uid", 'cn', 'uid');
+
+    public function get_attribute($uid, $attribute) {
+        $data = $this->search("uid=$uid", $attribute);
         if($data['count'] !== 1) {
             $err = "LDAP search for '$uid' did not return exactly one result";
             throw new Exception($err);
         }
-        return $data[0]['cn'][0];
+        return $data[0][strtolower($attribute)][0];
+    }
+
+    public function get_user($uid) {
+        return $this->get_attribute($uid, 'cn');
+    }
+
+    public function get_firstname($uid) {
+        return $this->get_attribute($uid, 'givenName');
     }
 
     public function get_user_email($uid) {
-        $data = $this->search("uid=$uid", 'mail', 'uid');
-        if($data['count'] !== 1) {
-            $err = "LDAP search for '$uid' did not return exactly one result";
-            throw new Exception($err);
-        }
-        return $data[0]['mail'][0];
+        return $this->get_attribute($uid, 'mail');
     }
 
     public function search_email($email) {
diff --git a/include/Loan.php b/include/Loan.php
index 9bf38c8..08311b7 100644
--- a/include/Loan.php
+++ b/include/Loan.php
@@ -54,7 +54,7 @@ class Loan extends Event {
         $this->endtime = $ts;
         return true;
     }
-    
+
     public function end() {
         $now = time();
         $query = prepare('update `event` set `returntime`=? where `id`=?');
@@ -75,6 +75,18 @@ class Loan extends Event {
         return false;
     }
 
+    public function expires_before($datetime) {
+        if($this->returntime !== null) {
+            return false;
+        }
+        $endtime = new DateTime();
+        $endtime->setTimestamp($this->endtime);
+        if(!$this->is_overdue() && $endtime < $datetime) {
+            return true;
+        }
+        return false;
+    }
+
     public function get_status() {
         if($this->is_overdue()) {
             return 'overdue_loan';
diff --git a/include/User.php b/include/User.php
index d77475f..a34ca03 100644
--- a/include/User.php
+++ b/include/User.php
@@ -189,5 +189,15 @@ class User extends Entity {
         }
         return $overdue;
     }
+
+    public function get_expiring_loans($end_date) {
+        $expiring = array();
+        foreach($this->get_loans('active') as $loan) {
+            if($loan->expires_before($end_date)) {
+                $expiring[] = $loan;
+            }
+        }
+        return $expiring;
+    }
 }
 ?>

From 15f4597637cdd6e041fce61a186145cc93bb96b1 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Mon, 2 May 2022 15:21:56 +0200
Subject: [PATCH 224/250] Fixed formatting bugs in the outgoing emails

---
 include/Cron.php | 48 +++++++++++++++++++++++++++---------------------
 1 file changed, 27 insertions(+), 21 deletions(-)

diff --git a/include/Cron.php b/include/Cron.php
index ad6d26b..eeb26bd 100644
--- a/include/Cron.php
+++ b/include/Cron.php
@@ -9,8 +9,8 @@ class Cron {
         $this->now = new DateTimeImmutable();
         $this->sender = $sender;
         $this->error = $error;
-        $warn_time = DateInterval::createFromDateString('3 days');
-        $this->warn_date = $this->now->add($warn_time);
+        $this->warn_time = DateInterval::createFromDateString('3 days');
+        $this->warn_date = $this->now->add($this->warn_time);
         $this->run_interval = DateInterval::createFromDateString('1 day');
         $this->kvs = new Kvs();
         $this->ldap = new Ldap();
@@ -58,7 +58,7 @@ class Cron {
         if(!$expiring) {
             return '';
         }
-        $days = $this->warn_date->d;
+        $days = $this->warn_time->d;
         switch($lang) {
             case 'sv':
                 $msg = "Följande lån går ut om mindre än ".$days." dagar:";
@@ -76,16 +76,16 @@ class Cron {
             default:
                 throw new Exception("Invalid language: ".$lang);
         }
-        $msg .= "\n\n";
+        $lines = array();
         foreach($expiring as $loan) {
             $product = $loan->get_product();
             $serial = $product->get_serial();
             $brand = $product->get_brand();
             $name = $product->get_name();
             $endtime = format_date($loan->get_endtime());
-            $msg .= $serial.": ".$brand." ".$name.$itemglue.$endtime;
+            $lines[] = $serial.": ".$brand." ".$name.$itemglue.$endtime;
         }
-        return $msg;
+        return $msg."\n\n".implode("\n", $lines);
     }
 
     private function make_overdue_notice($lang, $overdue) {
@@ -108,16 +108,16 @@ class Cron {
             default:
                 throw new Exception("Invalid language: ".$lang);
         }
-        $msg .= "\n\n";
+        $lines = array();
         foreach($overdue as $loan) {
             $product = $loan->get_product();
             $serial = $product->get_serial();
             $brand = $product->get_brand();
             $name = $product->get_name();
             $endtime = format_date($loan->get_endtime());
-            $msg .= $serial.": ".$brand." ".$name.$itemglue.$endtime;
+            $lines[] = $serial.": ".$brand." ".$name.$itemglue.$endtime;
         }
-        return $msg;
+        return $msg."\n\n".implode("\n", $lines);
     }
 
     private function make_return_info($lang, $count) {
@@ -148,25 +148,31 @@ class Cron {
 
     }
 
-    private function send_reminder($user, $expiring, $expired) {
+    private function send_reminder($user, $expiring, $overdue) {
         $uid = $user->get_name();
         $name = $this->ldap->get_firstname($uid);
 
-        $subject = $this->make_subject(count($expiring), count($expired));
+        $expiring_count = count($expiring);
+        $overdue_count = count($overdue);
+        $total = $expiring_count + $overdue_count;
+
+        $subject = $this->make_subject($expiring_count, $overdue_count);
 
         $info_sv = array();
-        $info_sv[] = $this->make_expiring_notice('sv', $expiring);
-        $info_sv[] = $this->make_overdue_notice('sv', $expired);
-        $info_sv = implode("\n\n", $info_sv);
-        $returns_sv = $this->make_return_info(
-            'sv', count($expiring) + count($expired));
-
         $info_en = array();
-        $info_en[] = $this->make_expiring_notice('en', $expiring);
-        $info_en[] = $this->make_overdue_notice('en', $expired);
+        if($expiring_count > 0) {
+            $info_sv[] = $this->make_expiring_notice('sv', $expiring);
+            $info_en[] = $this->make_expiring_notice('en', $expiring);
+        }
+        if($overdue_count > 0) {
+            $info_sv[] = $this->make_overdue_notice('sv', $overdue);
+            $info_en[] = $this->make_overdue_notice('en', $overdue);
+        }
+        $info_sv = implode("\n\n", $info_sv);
+        $returns_sv = $this->make_return_info('sv', $total);
+
         $info_en = implode("\n\n", $info_en);
-        $returns_en = $this->make_return_info(
-            'en', count($expiring) + count($expired));
+        $returns_en = $this->make_return_info('en', $total);
 
         $message = <<<EOF
 Hej $name!

From 79d9f45c383a061ad1899a4bd14c1145deb25b1d Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Mon, 16 May 2022 13:49:22 +0200
Subject: [PATCH 225/250] Refactored the reminder generaion

---
 include/Cron.php | 106 +++++++++++++++++++++++------------------------
 1 file changed, 52 insertions(+), 54 deletions(-)

diff --git a/include/Cron.php b/include/Cron.php
index eeb26bd..a8a5159 100644
--- a/include/Cron.php
+++ b/include/Cron.php
@@ -14,6 +14,38 @@ class Cron {
         $this->run_interval = DateInterval::createFromDateString('1 day');
         $this->kvs = new Kvs();
         $this->ldap = new Ldap();
+
+        $days = $this->warn_time->d;
+        $this->strings = array(
+            'en' => array(
+                'expiring' => array(
+                    'single' => "The following loan expires in less than $days days:",
+                    'multi'  => "The following loans expire in less than $days days:",
+                    'expiry' => "expires on",
+                    'serial' => "serial number",
+                ),
+                'overdue' => array(
+                    'single' => "The following loan has expired:",
+                    'multi'  => "The following loans have expired:",
+                    'expiry' => "expired on",
+                    'serial' => "serial number",
+                ),
+            ),
+            'sv' => array(
+                'expiring' => array(
+                    'single' => "Följande lån går ut om mindre än $days dagar:",
+                    'multi'  => "Följande lån går ut om mindre än $days dagar:",
+                    'expiry' => "går ut",
+                    'serial' => "artikelnummer",
+                ),
+                'overdue' => array(
+                    'single' => "Följande lån har gått ut:",
+                    'multi'  => "Följande lån har gått ut:",
+                    'expiry' => "gick ut",
+                    'serial' => "artikelnummer",
+                ),
+            ),
+        );
     }
 
     public function run() {
@@ -54,68 +86,34 @@ class Cron {
         return $subject.implode(" och ", $messages);
     }
 
-    private function make_expiring_notice($lang, $expiring) {
-        if(!$expiring) {
+    private function make_notice($lang, $type, $list) {
+        if(!$list) {
             return '';
         }
-        $days = $this->warn_time->d;
-        switch($lang) {
-            case 'sv':
-                $msg = "Följande lån går ut om mindre än ".$days." dagar:";
-                $itemglue = ", går ut ";
-                break;
-            case 'en':
-                if(count($expiring) == 1) {
-                    $loanstr = "loan expires";
-                } else {
-                    $loanstr = "loans expire";
-                }
-                $msg = "The following ".$loanstr." in less than ".$days." days:";
-                $itemglue = ", expires on ";
-                break;
-            default:
-                throw new Exception("Invalid language: ".$lang);
+        if(!array_key_exists($lang, $this->strings)) {
+            throw new Exception("Invalid languange: $lang");
         }
-        $lines = array();
-        foreach($expiring as $loan) {
-            $product = $loan->get_product();
-            $serial = $product->get_serial();
-            $brand = $product->get_brand();
-            $name = $product->get_name();
-            $endtime = format_date($loan->get_endtime());
-            $lines[] = $serial.": ".$brand." ".$name.$itemglue.$endtime;
+        $strings = $this->strings[$lang];
+        if(!array_key_exists($type, $strings)) {
+            throw new Exception("Invalid type: $type");
         }
-        return $msg."\n\n".implode("\n", $lines);
-    }
+        $strings = $strings[$type];
 
-    private function make_overdue_notice($lang, $overdue) {
-        if(!$overdue) {
-            return '';
-        }
-        switch($lang) {
-            case 'sv':
-                $msg = "Följande lån har gått ut:";
-                $itemglue = ", gick ut ";
-                break;
-            case 'en':
-                if(count($overdue) == 1) {
-                    $msg = "The following loan has expired:";
-                } else {
-                    $msg = "The following loans have expired:";
-                }
-                $itemglue = ", expired on ";
-                break;
-            default:
-                throw new Exception("Invalid language: ".$lang);
+        $msg = $strings['single'];
+        if(count($list) > 1) {
+            $msg = $strings['multi'];
         }
+
         $lines = array();
-        foreach($overdue as $loan) {
+        foreach($list as $loan) {
             $product = $loan->get_product();
             $serial = $product->get_serial();
             $brand = $product->get_brand();
             $name = $product->get_name();
             $endtime = format_date($loan->get_endtime());
-            $lines[] = $serial.": ".$brand." ".$name.$itemglue.$endtime;
+
+            $lines[] = "$brand $name, ".$strings['serial']
+                      ." $serial, ".$strings['expiry']." $endtime";
         }
         return $msg."\n\n".implode("\n", $lines);
     }
@@ -161,12 +159,12 @@ class Cron {
         $info_sv = array();
         $info_en = array();
         if($expiring_count > 0) {
-            $info_sv[] = $this->make_expiring_notice('sv', $expiring);
-            $info_en[] = $this->make_expiring_notice('en', $expiring);
+            $info_sv[] = $this->make_notice('sv', 'expiring', $expiring);
+            $info_en[] = $this->make_notice('en', 'expiring', $expiring);
         }
         if($overdue_count > 0) {
-            $info_sv[] = $this->make_overdue_notice('sv', $overdue);
-            $info_en[] = $this->make_overdue_notice('en', $overdue);
+            $info_sv[] = $this->make_notice('sv', 'overdue', $overdue);
+            $info_en[] = $this->make_notice('en', 'overdue', $overdue);
         }
         $info_sv = implode("\n\n", $info_sv);
         $returns_sv = $this->make_return_info('sv', $total);

From c1ba468807b5ceb9201c5b08888857e70055d928 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Tue, 19 Jul 2022 15:27:31 +0200
Subject: [PATCH 226/250] Whitespace cleanup

---
 include/User.php | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/User.php b/include/User.php
index a34ca03..ba218b4 100644
--- a/include/User.php
+++ b/include/User.php
@@ -3,7 +3,7 @@ class User extends Entity {
     private $id = 0;
     private $name = '';
     private $notes = '';
-    
+
     public static function create_user($name) {
         $ins_user = prepare('insert into `user`(`name`) values (?)');
         bind($ins_user, 's', $name);
@@ -34,7 +34,7 @@ class User extends Entity {
         $this->id = $id;
         $this->update_fields();
     }
-    
+
     private function update_fields() {
         $get = prepare('select * from `user` where `id`=?');
         bind($get, 'i', $this->id);
@@ -125,11 +125,11 @@ class User extends Entity {
     public function get_id() {
         return $this->id;
     }
-    
+
     public function get_name() {
         return $this->name;
     }
-    
+
     public function set_name($newname) {
         $update = prepare('update `user` set `name`=? where `id`=?');
         bind($update, 'si', $newname, $this->id);
@@ -141,7 +141,7 @@ class User extends Entity {
     public function get_notes() {
         return $this->notes;
     }
-    
+
     public function set_notes($newnotes) {
         $update = prepare('update `user` set `notes`=? where `id`=?');
         bind($update, 'si', $newnotes, $this->id);
@@ -151,7 +151,7 @@ class User extends Entity {
     }
 
     public function get_loans($type = 'both') {
-        $statement = "select `id` from `event` 
+        $statement = "select `id` from `event`
                       left join `loan` on `event`.`id` = `loan`.`event`
                       where
                           `type`='loan' and `user`=?";

From 396a3f067e2394b288a87fef6c07e44c90a6734b Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Tue, 19 Jul 2022 15:29:58 +0200
Subject: [PATCH 227/250] Config item $reminder_sender changed to $sender

---
 config.php.example | 2 +-
 cron.php           | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/config.php.example b/config.php.example
index 982e551..9a6fbb8 100644
--- a/config.php.example
+++ b/config.php.example
@@ -7,7 +7,7 @@ $db_pass = 'dbpassword';
 $db_name = 'dbuser';
 
 # Address to use as the sender for reminder emails
-$reminder_sender = 'noreply@example.com';
+$sender = 'noreply@example.com';
 
 # Address to send cron error messages to
 $error_address = 'root@example.com';
diff --git a/cron.php b/cron.php
index d2170df..5e52909 100755
--- a/cron.php
+++ b/cron.php
@@ -7,7 +7,7 @@ require('./include/functions.php');
 
 header('Content-Type: text/html; charset=UTF-8');
 
-$cron = new Cron($reminder_sender, $error_address);
+$cron = new Cron($sender, $error_address);
 $cron->run();
 
 ?>

From a16e5f2479b45db07e92f3bc253750302d6e7c3c Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Tue, 19 Jul 2022 15:48:35 +0200
Subject: [PATCH 228/250] Whitespace cleanup

---
 include/Event.php | 6 +++---
 include/Loan.php  | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/Event.php b/include/Event.php
index 865a5d3..711bb5b 100644
--- a/include/Event.php
+++ b/include/Event.php
@@ -44,7 +44,7 @@ class Event {
         $event_id = $insert->insert_id;
         return new Event($event_id);
     }
-    
+
     public function __construct($id) {
         $search = prepare('select `id` from `event`
                            where `id`=?');
@@ -57,7 +57,7 @@ class Event {
         $this->id = $result['id'];
         $this->update_fields();
     }
-    
+
     protected function update_fields() {
         $get = prepare('select * from `event` where `id`=?');
         bind($get, 'i', $this->id);
@@ -83,7 +83,7 @@ class Event {
     public function get_returntime() {
         return $this->returntime;
     }
-    
+
     public function is_active() {
         if($this->returntime === null) {
             return true;
diff --git a/include/Loan.php b/include/Loan.php
index 08311b7..fe8346b 100644
--- a/include/Loan.php
+++ b/include/Loan.php
@@ -15,7 +15,7 @@ class Loan extends Event {
         commit_trans();
         return new Loan($event_id);
     }
-    
+
     public function __construct($id) {
         parent::__construct($id);
         $search = prepare('select * from `loan` where `event`=?');
@@ -27,7 +27,7 @@ class Loan extends Event {
         }
         $this->update_fields();
     }
-    
+
     protected function update_fields() {
         parent::update_fields();
         $get = prepare('select * from `loan` where `event`=?');

From 04af074849a7b602d9c58b440e4115376c2d6c34 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Tue, 19 Jul 2022 16:57:42 +0200
Subject: [PATCH 229/250] Whitespace cleanup

---
 include/Ajax.php | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/Ajax.php b/include/Ajax.php
index 4ede200..1fa756d 100644
--- a/include/Ajax.php
+++ b/include/Ajax.php
@@ -1,14 +1,14 @@
 <?php
 class Ajax extends Responder {
     private $action = '';
-    
+
     public function __construct() {
         parent::__construct();
         if(isset($_GET['action'])) {
             $this->action = $_GET['action'];
         }
     }
-    
+
     public function render() {
         $out = '';
         switch($this->action) {
@@ -98,7 +98,7 @@ class Ajax extends Responder {
             return new Failure('Artikeln är redan utlånad.');
         }
     }
-    
+
     private function return_product() {
         $product = null;
         try {
@@ -138,7 +138,7 @@ class Ajax extends Responder {
         }
         return new Failure('Lån saknas.');
     }
-    
+
     private function start_inventory() {
         try {
             Inventory::begin();
@@ -147,7 +147,7 @@ class Ajax extends Responder {
             return new Failure('Inventering redan igång.');
         }
     }
-    
+
     private function end_inventory() {
         $inventory = Inventory::get_active();
         if($inventory === null) {
@@ -156,7 +156,7 @@ class Ajax extends Responder {
         $inventory->end();
         return new Success('Inventering avslutad.');
     }
-    
+
     private function inventory_product() {
         $inventory = Inventory::get_active();
         if($inventory === null) {
@@ -273,7 +273,7 @@ class Ajax extends Responder {
         }
         return new Success('Ändringarna sparade.');
     }
-    
+
     private function update_user() {
         $id = $_POST['id'];
         $name = $_POST['name'];
@@ -355,7 +355,7 @@ class Ajax extends Responder {
             return new Failure('Det finns ingen mall med det namnet.');
         }
     }
-    
+
     private function suggest() {
         return new Success(suggest($_POST['type']));
     }

From 311402e1b894a74cac0af05941fba5ac8867ca0e Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Tue, 19 Jul 2022 17:00:08 +0200
Subject: [PATCH 230/250] Initial implementation of loan receipts

---
 include/Cron.php     | 105 ++++++++++++++++++++++++++++++++++++++++---
 include/Loan.php     |  16 ++++++-
 pending_receipts.sql |   9 ++++
 3 files changed, 122 insertions(+), 8 deletions(-)
 create mode 100644 pending_receipts.sql

diff --git a/include/Cron.php b/include/Cron.php
index a8a5159..66e65d2 100644
--- a/include/Cron.php
+++ b/include/Cron.php
@@ -18,6 +18,10 @@ class Cron {
         $days = $this->warn_time->d;
         $this->strings = array(
             'en' => array(
+                'new' => array(
+                    'expiry' => "expires on",
+                    'serial' => "serial number",
+                ),
                 'expiring' => array(
                     'single' => "The following loan expires in less than $days days:",
                     'multi'  => "The following loans expire in less than $days days:",
@@ -32,6 +36,10 @@ class Cron {
                 ),
             ),
             'sv' => array(
+                'new' => array(
+                    'expiry' => "går ut",
+                    'serial' => "artikelnummer",
+                ),
                 'expiring' => array(
                     'single' => "Följande lån går ut om mindre än $days dagar:",
                     'multi'  => "Följande lån går ut om mindre än $days dagar:",
@@ -49,6 +57,81 @@ class Cron {
     }
 
     public function run() {
+        $this->run_receipts();
+        $this->run_reminders();
+    }
+
+    private function run_receipts() {
+        begin_trans();
+        $get = prepare('select * from `pending_receipt`
+                        where `send_time` < ?');
+        bind($get, 'i', $this->now->getTimestamp());
+        execute($get);
+        foreach(result_list($get) as $row) {
+            $user = new User($row['user']);
+            $since_time = $row['since_time'];
+
+            $notify_loans = array();
+            foreach($user->get_loans('active') as $loan) {
+                if($loan->get_starttime() >= $since_time) {
+                    $notify_loans[] = $loan;
+                }
+            }
+            $this->send_receipt($user, $loans);
+            $delete = prepare('delete from `pending_receipt`
+                               where `user = ? and `send_time` < ?');
+            bind($delete, 'ii', $user->get_id(), $this->now->getTimestamp());
+            execute($delete);
+        }
+        commit_trans();
+    }
+
+    private function send_receipt($user, $loans) {
+        $count = count($loans);
+        if($count > 1) {
+            $new_sv = "nya lån";
+            $new_en = "new loans";
+            $have = "have";
+        } else {
+            $new_sv = "nytt lån";
+            $new_en = "new loan";
+            $have = "has";
+        }
+        $subject = "DSV Helpdesk: $count $new_sv";
+
+        $intro_sv = "";
+        $intro_en = "$count $new_en $have been registered to your user:";
+
+        $list_sv = $this->make_notice('sv', 'new', $loans);
+        $list_en = $this->make_notice('en', 'new', $loans);
+
+        $message = <<<EOF
+Hej $name!
+
+Det här är ett automatiskt meddelande om att $count $new_sv har registrerats på din användare:
+
+$list_sv
+
+Eventuella artiklar du inte hämtat ut redan kan hämtas från Helpdesk. Svara på det här mailet om du har några frågor.
+
+----
+
+This is an automated message to inform you that $count $new_en $have been registered in your name:
+
+$list_en
+
+Any products you haven't already picked up can be collected from Helpdesk. Please reply to this email if you have any questions.
+
+Mvh
+DSV Helpdesk
+helpdesk@dsv.su.se
+08 - 16 16 48
+
+EOF;
+        $this->send_email($uid, $subject, $message);
+    }
+
+    private function run_reminders() {
         $lastrun = $this->kvs->get_value('lastrun', 0);
         $nextrun = $this->now
                         ->setTimestamp($lastrun)
@@ -99,11 +182,6 @@ class Cron {
         }
         $strings = $strings[$type];
 
-        $msg = $strings['single'];
-        if(count($list) > 1) {
-            $msg = $strings['multi'];
-        }
-
         $lines = array();
         foreach($list as $loan) {
             $product = $loan->get_product();
@@ -115,6 +193,15 @@ class Cron {
             $lines[] = "$brand $name, ".$strings['serial']
                       ." $serial, ".$strings['expiry']." $endtime";
         }
+
+        if($type === 'new') {
+            return implode("\n", $lines);
+        }
+
+        $msg = $strings['single'];
+        if(count($list) > 1) {
+            $msg = $strings['multi'];
+        }
         return $msg."\n\n".implode("\n", $lines);
     }
 
@@ -195,6 +282,10 @@ helpdesk@dsv.su.se
 08 - 16 16 48
 
 EOF;
+        $this->send_email($uid, $subject, $message);
+    }
+
+    private function send_email($uid, $subject, $message) {
         try {
             mb_send_mail($this->ldap->get_user_email($uid),
                          $subject,
@@ -203,8 +294,8 @@ EOF;
         } catch(Exception $e) {
             error_log($e->message);
             mb_send_mail($this->error,
-                         "Kunde inte skicka påminnelse",
-                         "Påminnelse kunde inte skickas till ".$uid);
+                         "Kunde inte skicka mail",
+                         "Mail kunde inte skickas till ".$uid);
         }
     }
 }
diff --git a/include/Loan.php b/include/Loan.php
index fe8346b..cb7f0ae 100644
--- a/include/Loan.php
+++ b/include/Loan.php
@@ -12,8 +12,22 @@ class Loan extends Event {
         $endtime .= '13:00';
         bind($insert, 'iii', $event_id, $user->get_id(), strtotime($endtime));
         execute($insert);
+        $loan = new Loan($event_id);
+
+        $now = time();
+        $pending = prepare('select * from `pending_receipt` where `user` = ?
+                                and `since_time` < ? and `send_time` > ?');
+        bind($pending, 'iii', $user->get_id(), $now, $now);
+        execute($pending);
+        if(result_single($pending) === null) {
+            $add = prepare('insert into `pending_receipt`
+                                (`user`, `since_time`, `send_time`)
+                                values(?, ?, ?)');
+            bind($add, 'iii', $user->get_id(), $now, $now + 3600);
+            execute($add);
+        }
         commit_trans();
-        return new Loan($event_id);
+        return $loan;
     }
 
     public function __construct($id) {
diff --git a/pending_receipts.sql b/pending_receipts.sql
new file mode 100644
index 0000000..550da5b
--- /dev/null
+++ b/pending_receipts.sql
@@ -0,0 +1,9 @@
+create table `pending_receipt` (
+  `user` bigint(20) not null,
+  primary key (`user`),
+  constraint `pr_f_user`
+    foreign key(`user`) references `user`(`id`),
+  `send_time` bigint(20) not null,
+  `since_time` bigint(20) not null
+) character set utf8mb4,
+  collate utf8mb4_unicode_ci;

From cd627f811d8d894843df06702d397bfd73fa91d2 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Wed, 20 Jul 2022 10:41:35 +0200
Subject: [PATCH 231/250] Made it work

---
 include/Cron.php | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/include/Cron.php b/include/Cron.php
index 66e65d2..3303ff5 100644
--- a/include/Cron.php
+++ b/include/Cron.php
@@ -77,9 +77,9 @@ class Cron {
                     $notify_loans[] = $loan;
                 }
             }
-            $this->send_receipt($user, $loans);
+            $this->send_receipt($user, $notify_loans);
             $delete = prepare('delete from `pending_receipt`
-                               where `user = ? and `send_time` < ?');
+                               where `user` = ? and `send_time` < ?');
             bind($delete, 'ii', $user->get_id(), $this->now->getTimestamp());
             execute($delete);
         }
@@ -87,6 +87,9 @@ class Cron {
     }
 
     private function send_receipt($user, $loans) {
+        $uid = $user->get_name();
+        $name = $this->ldap->get_firstname($uid);
+
         $count = count($loans);
         if($count > 1) {
             $new_sv = "nya lån";
@@ -292,7 +295,7 @@ EOF;
                          $message,
                          'From: '.$this->sender);
         } catch(Exception $e) {
-            error_log($e->message);
+            error_log($e->getMessage());
             mb_send_mail($this->error,
                          "Kunde inte skicka mail",
                          "Mail kunde inte skickas till ".$uid);

From 0af33c5dd660c510e992b2274de9f781bf1fbb2a Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Tue, 26 Jul 2022 10:23:09 +0200
Subject: [PATCH 232/250] Added buttons to quickly change the runtime of a loan

---
 html/fragments.html |  5 +++++
 script.js           | 19 ++++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/html/fragments.html b/html/fragments.html
index 1e0e633..9dbb066 100644
--- a/html/fragments.html
+++ b/html/fragments.html
@@ -610,6 +610,11 @@
       Låna ut
     </button>
     <br/>
+    <label>Löptid:</label>
+    <button onClick="JavaScript:loanLength(event, 7)">1 vecka</button>
+    <button onClick="JavaScript:loanLength(event, 365)">1 år</button>
+    <button onClick="JavaScript:loanLength(event, 1095)">3 år</button>
+    <br/>
     <label for="end">Slutdatum:</label>
     <input type="text"
            id="end"
diff --git a/script.js b/script.js
index a708d23..d79d1d6 100644
--- a/script.js
+++ b/script.js
@@ -97,7 +97,7 @@ function getFragment(name, callback) {
             console.log(result);
         }
     }
-    
+
     var data = new FormData()
     data.append('fragment', name)
     ajaxRequest('getfragment', data, unpack)
@@ -573,3 +573,20 @@ function showFile(event) {
     var filefield = event.currentTarget.parentNode.filename
     filefield.value = event.currentTarget.files[0].name
 }
+
+function loanLength(event, days) {
+    event.preventDefault()
+    var end = document.getElementById('end')
+    var enddate = new Date()
+    enddate.setDate(enddate.getDate() + days)
+    console.log(enddate)
+    var month = enddate.getMonth()
+    if(month < 10) {
+        month = '0' + month
+    }
+    var day = enddate.getDay()
+    if(day < 10) {
+        day = '0' + day
+    }
+    end.value = enddate.getFullYear() + '-' + month + '-' + day
+}

From dbe2a0ee9070583a2591818e19faa3a6a91870b4 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Tue, 26 Jul 2022 10:24:16 +0200
Subject: [PATCH 233/250] Removed debug line

---
 script.js | 1 -
 1 file changed, 1 deletion(-)

diff --git a/script.js b/script.js
index d79d1d6..2dc75e4 100644
--- a/script.js
+++ b/script.js
@@ -579,7 +579,6 @@ function loanLength(event, days) {
     var end = document.getElementById('end')
     var enddate = new Date()
     enddate.setDate(enddate.getDate() + days)
-    console.log(enddate)
     var month = enddate.getMonth()
     if(month < 10) {
         month = '0' + month

From 1d0caf95134f9149428d3f41eb012a34b7a6bf54 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Tue, 26 Jul 2022 10:56:59 +0200
Subject: [PATCH 234/250] Sorted the bugs when picking an interval via button

---
 html/fragments.html |  6 +++---
 script.js           | 17 +++++++++++++----
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/html/fragments.html b/html/fragments.html
index 9dbb066..761a059 100644
--- a/html/fragments.html
+++ b/html/fragments.html
@@ -611,9 +611,9 @@
     </button>
     <br/>
     <label>Löptid:</label>
-    <button onClick="JavaScript:loanLength(event, 7)">1 vecka</button>
-    <button onClick="JavaScript:loanLength(event, 365)">1 år</button>
-    <button onClick="JavaScript:loanLength(event, 1095)">3 år</button>
+    <button onClick="JavaScript:loanLength(event, 7, 'day')">1 vecka</button>
+    <button onClick="JavaScript:loanLength(event, 1, 'year')">1 år</button>
+    <button onClick="JavaScript:loanLength(event, 3, 'year')">3 år</button>
     <br/>
     <label for="end">Slutdatum:</label>
     <input type="text"
diff --git a/script.js b/script.js
index 2dc75e4..3478b9a 100644
--- a/script.js
+++ b/script.js
@@ -483,6 +483,7 @@ function calendar(event) {
     if(!input.cal) {
         var cal = new dhtmlXCalendarObject(input.id)
         cal.hideTime()
+        cal.setDate(input.value)
         input.cal = cal
         cal.show()
     }
@@ -574,16 +575,24 @@ function showFile(event) {
     filefield.value = event.currentTarget.files[0].name
 }
 
-function loanLength(event, days) {
+function loanLength(event, length, unit) {
     event.preventDefault()
     var end = document.getElementById('end')
     var enddate = new Date()
-    enddate.setDate(enddate.getDate() + days)
-    var month = enddate.getMonth()
+    switch(unit) {
+    case 'day':
+        enddate.setDate(enddate.getDate() + length)
+        break
+    case 'year':
+        enddate.setFullYear(enddate.getFullYear() + length)
+        break;
+    }
+    // javascript zero-indexes months because of course
+    var month = enddate.getMonth() + 1
     if(month < 10) {
         month = '0' + month
     }
-    var day = enddate.getDay()
+    var day = enddate.getDate()
     if(day < 10) {
         day = '0' + day
     }

From 22d760a0af2828933f14e24be121f225a126d20f Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Wed, 27 Jul 2022 10:48:53 +0200
Subject: [PATCH 235/250] Whitespace cleanup

---
 include/Page.php | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/Page.php b/include/Page.php
index 1d2607e..4d97158 100644
--- a/include/Page.php
+++ b/include/Page.php
@@ -1,7 +1,7 @@
 <?php
 abstract class Page extends Responder {
     protected abstract function render_body();
-    
+
     protected $page = 'checkout';
     protected $title = "DSV Utlåning";
     protected $subtitle = '';
@@ -15,11 +15,11 @@ abstract class Page extends Responder {
                                  'history' => 'Historik',
                                  'search' => 'Sök');
     private $template_parts = array();
-    
+
     public function __construct() {
         parent::__construct();
         $this->template_parts = get_fragments('./html/base.html');
-        
+
         if(isset($_GET['page'])) {
             $this->page = $_GET['page'];
         }
@@ -27,7 +27,7 @@ abstract class Page extends Responder {
             $this->subtitle = $this->menuitems[$this->page];
         }
     }
-    
+
     public function render() {
         $this->render_head();
         $this->render_body();
@@ -36,7 +36,7 @@ abstract class Page extends Responder {
         }
         $this->render_foot();
     }
-    
+
     final private function render_head() {
         $headtitle = $this->title;
         $pagetitle = $this->title;
@@ -83,7 +83,7 @@ abstract class Page extends Responder {
                             'message' => $this->error),
                       $this->fragments['message']));
     }
-    
+
     final private function render_foot() {
         print($this->template_parts['foot']);
     }

From b3434dbb6a66813d0d6281618c562353994abd5d Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Wed, 27 Jul 2022 10:52:52 +0200
Subject: [PATCH 236/250] Changed loan extension form to have a saner default
 end time.

---
 include/Page.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/Page.php b/include/Page.php
index 4d97158..7c4060a 100644
--- a/include/Page.php
+++ b/include/Page.php
@@ -211,7 +211,7 @@ abstract class Page extends Responder {
             $status = $loan->get_status();
             $note = '';
             if($status !== 'inactive_loan') {
-                $extend = format_date(default_loan_end(time()));
+                $extend = format_date($loan->get_endtime());
                 $note = replace(array('id' => $product->get_id(),
                                       'end_new' => $extend),
                                 $this->fragments['loan_extend_form']);

From b967c7dde296c8638a5c4fb5377c42e789dbbfee Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Wed, 27 Jul 2022 10:58:11 +0200
Subject: [PATCH 237/250] Added the new tables pending_receipt and
 loan_extension to the schema

---
 database.sql | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/database.sql b/database.sql
index 840e57b..7f459e7 100644
--- a/database.sql
+++ b/database.sql
@@ -147,3 +147,24 @@ create table `kvs` (
   `value` varchar(64) not null default ''
 ) character set utf8mb4,
   collate utf8mb4_unicode_ci;
+
+create table `pending_receipt` (
+  `user` bigint(20) not null,
+  primary key (`user`),
+  constraint `pr_f_user`
+    foreign key(`user`) references `user`(`id`),
+  `send_time` bigint(20) not null,
+  `since_time` bigint(20) not null
+) character set utf8mb4,
+  collate utf8mb4_unicode_ci;
+
+create table `loan_extension` (
+  `loan` bigint(20) not null,
+  constraint `le_f_loan`
+    foreign key(`loan`) references `loan`(`event`),
+  `extend_time` bigint(20) not null,
+  primary key (`loan`, `extend_time`),
+  `old_end` bigint(20) not null,
+  `new_end` bigint(20) not null
+) character set utf8mb4,
+  collate utf8mb4_unicode_ci;

From 4e9e5b93af0bac7343e37854402112dfef8c0fe4 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Wed, 27 Jul 2022 11:04:09 +0200
Subject: [PATCH 238/250] Added a function to get the latest loan extension.
 Broke receipt queueing into a function. Changed $this->id to $this->get_id()
 for the sake of consistency.

---
 include/Loan.php | 61 ++++++++++++++++++++++++++++++++++--------------
 1 file changed, 43 insertions(+), 18 deletions(-)

diff --git a/include/Loan.php b/include/Loan.php
index cb7f0ae..2640d73 100644
--- a/include/Loan.php
+++ b/include/Loan.php
@@ -13,19 +13,7 @@ class Loan extends Event {
         bind($insert, 'iii', $event_id, $user->get_id(), strtotime($endtime));
         execute($insert);
         $loan = new Loan($event_id);
-
-        $now = time();
-        $pending = prepare('select * from `pending_receipt` where `user` = ?
-                                and `since_time` < ? and `send_time` > ?');
-        bind($pending, 'iii', $user->get_id(), $now, $now);
-        execute($pending);
-        if(result_single($pending) === null) {
-            $add = prepare('insert into `pending_receipt`
-                                (`user`, `since_time`, `send_time`)
-                                values(?, ?, ?)');
-            bind($add, 'iii', $user->get_id(), $now, $now + 3600);
-            execute($add);
-        }
+        $loan->queue_receipt($user);
         commit_trans();
         return $loan;
     }
@@ -45,13 +33,28 @@ class Loan extends Event {
     protected function update_fields() {
         parent::update_fields();
         $get = prepare('select * from `loan` where `event`=?');
-        bind($get, 'i', $this->id);
+        bind($get, 'i', $this->get_id());
         execute($get);
         $loan = result_single($get);
         $this->user = $loan['user'];
         $this->endtime = $loan['endtime'];
     }
 
+    protected function queue_receipt($user) {
+        $now = time();
+        $pending = prepare('select * from `pending_receipt` where `user` = ?
+                                and `since_time` < ? and `send_time` > ?');
+        bind($pending, 'iii', $user->get_id(), $now, $now);
+        execute($pending);
+        if(result_single($pending) === null) {
+            $add = prepare('insert into `pending_receipt`
+                                (`user`, `since_time`, `send_time`)
+                                values(?, ?, ?)');
+            bind($add, 'iii', $user->get_id(), $now, $now + 3600);
+            execute($add);
+        }
+    }
+
     public function get_user() {
         return new User($this->user);
     }
@@ -61,18 +64,40 @@ class Loan extends Event {
     }
 
     public function extend($time) {
+        $oldend = $this->get_endtime();
+        $now = time();
         $ts = strtotime($time . ' 13:00');
-        $query = prepare('update `loan` set `endtime`=? where `event`=?');
-        bind($query, 'ii', $ts, $this->id);
-        execute($query);
+
+        begin_trans();
+        $extend = prepare('update `loan` set `endtime`=? where `event`=?');
+        bind($extend, 'ii', $ts, $this->get_id());
+        execute($extend);
+
+        $log = prepare('insert into `loan_extension`
+                            (`loan`, `extend_time`, `old_end`, `new_end`)
+                            values (?, ?, ?, ?)');
+        bind($log, 'iiii', $this->get_id(), $now, $oldend, $ts);
+        execute($log);
+
+        $this->queue_receipt($this->get_user());
+
         $this->endtime = $ts;
+        commit_trans();
         return true;
     }
 
+    public function get_last_extension() {
+        $select = prepare('select max(`extend_time`) as `extend_time`
+                           from `loan_extension` where `loan`=?');
+        bind($select, 'i', $this->get_id());
+        execute($select);
+        return result_single($select)['max(`extend_time`)'];
+    }
+
     public function end() {
         $now = time();
         $query = prepare('update `event` set `returntime`=? where `id`=?');
-        bind($query, 'ii', $now, $this->id);
+        bind($query, 'ii', $now, $this->get_id());
         execute($query);
         $this->returntime = $now;
         return true;

From ae8b73cb88fecd4afb470c14270794a5bab117f4 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Wed, 27 Jul 2022 13:15:06 +0200
Subject: [PATCH 239/250] Trim whitespace from serials when checking out and
 returning products

---
 include/Ajax.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/Ajax.php b/include/Ajax.php
index 1fa756d..99abc22 100644
--- a/include/Ajax.php
+++ b/include/Ajax.php
@@ -87,7 +87,7 @@ class Ajax extends Responder {
         }
         $product = null;
         try {
-            $product = new Product($_POST['product'], 'serial');
+            $product = new Product(trim($_POST['product']), 'serial');
         } catch(Exception $e) {
             return new Failure('Ogiltigt serienummer.');
         }
@@ -102,7 +102,7 @@ class Ajax extends Responder {
     private function return_product() {
         $product = null;
         try {
-            $product = new Product($_POST['serial'], 'serial');
+            $product = new Product(trim($_POST['serial']), 'serial');
         } catch(Exception $e) {
             return new Failure('Ogiltigt serienummer.');
         }

From 1b8c2e1e181d7b5070f62e670053be3a5bc91b78 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Wed, 27 Jul 2022 13:52:54 +0200
Subject: [PATCH 240/250] Corrected a database field name

---
 include/Loan.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/Loan.php b/include/Loan.php
index 2640d73..89b8465 100644
--- a/include/Loan.php
+++ b/include/Loan.php
@@ -91,7 +91,7 @@ class Loan extends Event {
                            from `loan_extension` where `loan`=?');
         bind($select, 'i', $this->get_id());
         execute($select);
-        return result_single($select)['max(`extend_time`)'];
+        return result_single($select)['extend_time'];
     }
 
     public function end() {

From 9307604aa08b4c793cdd44b53fb8bb0ae00e4243 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Wed, 27 Jul 2022 13:53:18 +0200
Subject: [PATCH 241/250] Implemented receipts for loan extensions

---
 include/Cron.php | 108 ++++++++++++++++++++++++++++++++---------------
 1 file changed, 75 insertions(+), 33 deletions(-)

diff --git a/include/Cron.php b/include/Cron.php
index 3303ff5..80bc67a 100644
--- a/include/Cron.php
+++ b/include/Cron.php
@@ -19,9 +19,17 @@ class Cron {
         $this->strings = array(
             'en' => array(
                 'new' => array(
+                    'single' => "The following loan has been registered in your name:",
+                    'multi'  => "The following loans have been registered in your name:",
                     'expiry' => "expires on",
                     'serial' => "serial number",
                 ),
+                'extend' => array(
+                    'single' => "The following loan has been extended:",
+                    'multi'  => "The following loans have been extended:",
+                    'expiry' => "extended to",
+                    'serial' => "serial number",
+                ),
                 'expiring' => array(
                     'single' => "The following loan expires in less than $days days:",
                     'multi'  => "The following loans expire in less than $days days:",
@@ -37,9 +45,17 @@ class Cron {
             ),
             'sv' => array(
                 'new' => array(
+                    'single' => "Följande lån har registrerats på din användare:",
+                    'multi'  => "Följande lån har registrerats på din användare:",
                     'expiry' => "går ut",
                     'serial' => "artikelnummer",
                 ),
+                'extend' => array(
+                    'single' => "Följande lån har förlängts:",
+                    'multi'  => "Följande lån har förlängts:",
+                    'expiry' => "förlängt till",
+                    'serial' => "artikelnummer",
+                ),
                 'expiring' => array(
                     'single' => "Följande lån går ut om mindre än $days dagar:",
                     'multi'  => "Följande lån går ut om mindre än $days dagar:",
@@ -71,13 +87,16 @@ class Cron {
             $user = new User($row['user']);
             $since_time = $row['since_time'];
 
-            $notify_loans = array();
+            $new_loans = array();
+            $extended_loans = array();
             foreach($user->get_loans('active') as $loan) {
                 if($loan->get_starttime() >= $since_time) {
-                    $notify_loans[] = $loan;
+                    $new_loans[] = $loan;
+                } else if($loan->get_last_extension() >= $since_time) {
+                    $extended_loans[] = $loan;
                 }
             }
-            $this->send_receipt($user, $notify_loans);
+            $this->send_receipt($user, $new_loans, $extended_loans);
             $delete = prepare('delete from `pending_receipt`
                                where `user` = ? and `send_time` < ?');
             bind($delete, 'ii', $user->get_id(), $this->now->getTimestamp());
@@ -86,44 +105,70 @@ class Cron {
         commit_trans();
     }
 
-    private function send_receipt($user, $loans) {
+    private function make_receipt_subject($num_new, $num_extended) {
+        $subject = "DSV Helpdesk: ";
+        $messages = array();
+        if($num_new > 1) {
+            $messages[] = $num_new." nya";
+        } else if($num_new > 0) {
+            $messages[] = $num_new." nytt";
+        }
+        if($num_extended > 1) {
+            $messages[] = $num_extended." förlängda";
+        } else if($num_extended > 0) {
+            $messages[] = $num_extended." förlängt";
+        }
+        return $subject.implode(" och ", $messages)." lån";
+    }
+
+    private function send_receipt($user, $new, $extended) {
         $uid = $user->get_name();
         $name = $this->ldap->get_firstname($uid);
 
-        $count = count($loans);
-        if($count > 1) {
-            $new_sv = "nya lån";
-            $new_en = "new loans";
-            $have = "have";
-        } else {
-            $new_sv = "nytt lån";
-            $new_en = "new loan";
-            $have = "has";
+        $new_count = count($new);
+        $extended_count = count($extended);
+        $subject = $this->make_receipt_subject($new_count, $extended_count);
+
+        $list_sv = array();
+        $list_en = array();
+        if($new_count > 0) {
+            $list_sv[] = $this->make_notice('sv', 'new', $new);
+            $list_en[] = $this->make_notice('en', 'new', $new);
         }
-        $subject = "DSV Helpdesk: $count $new_sv";
+        if($extended_count > 0) {
+            $list_sv[] = $this->make_notice('sv', 'extend', $extended);
+            $list_en[] = $this->make_notice('en', 'extend', $extended);
+        }
+        $list_sv = implode("\n\n", $list_sv);
+        $list_en = implode("\n\n", $list_en);
 
-        $intro_sv = "";
-        $intro_en = "$count $new_en $have been registered to your user:";
-
-        $list_sv = $this->make_notice('sv', 'new', $loans);
-        $list_en = $this->make_notice('en', 'new', $loans);
+        $info_sv = array();
+        $info_en = array();
+        if($new_count > 0) {
+            $info_sv[] = "Eventuella artiklar du inte hämtat ut redan kan hämtas från Helpdesk.";
+            $info_en[] = "Any products you haven't already picked up can be collected from Helpdesk.";
+        }
+        $info_sv[] = "Svara på det här mailet om du har några frågor.";
+        $info_en[] = "Please reply to this email if you have any questions.";
+        $info_sv = implode(' ', $info_sv);
+        $info_en = implode(' ', $info_en);
 
         $message = <<<EOF
 Hej $name!
 
-Det här är ett automatiskt meddelande om att $count $new_sv har registrerats på din användare:
+Det här är ett automatiskt meddelande från Helpdesk.
 
 $list_sv
 
-Eventuella artiklar du inte hämtat ut redan kan hämtas från Helpdesk. Svara på det här mailet om du har några frågor.
+$info_sv
 
 ----
 
-This is an automated message to inform you that $count $new_en $have been registered in your name:
+This is an automated message from Helpdesk.
 
 $list_en
 
-Any products you haven't already picked up can be collected from Helpdesk. Please reply to this email if you have any questions.
+$info_en
 
 Mvh
 DSV Helpdesk
@@ -158,18 +203,18 @@ EOF;
         }
     }
 
-    private function make_subject($num_expiring, $num_expired) {
+    private function make_reminder_subject($num_expiring, $num_expired) {
         $subject = "DSV Helpdesk: ";
         $messages = array();
         if($num_expiring > 0) {
-            $messages[] = $num_expiring." utgående lån";
+            $messages[] = $num_expiring." utgående";
         }
         if($num_expired > 1) {
-            $messages[] = $num_expired." försenade lån";
+            $messages[] = $num_expired." försenade";
         } elseif($num_expired > 0) {
-            $messages[] = $num_expired." försenat lån";
+            $messages[] = $num_expired." försenat";
         }
-        return $subject.implode(" och ", $messages);
+        return $subject.implode(" och ", $messages)." lån";
     }
 
     private function make_notice($lang, $type, $list) {
@@ -197,10 +242,6 @@ EOF;
                       ." $serial, ".$strings['expiry']." $endtime";
         }
 
-        if($type === 'new') {
-            return implode("\n", $lines);
-        }
-
         $msg = $strings['single'];
         if(count($list) > 1) {
             $msg = $strings['multi'];
@@ -244,7 +285,8 @@ EOF;
         $overdue_count = count($overdue);
         $total = $expiring_count + $overdue_count;
 
-        $subject = $this->make_subject($expiring_count, $overdue_count);
+        $subject = $this->make_reminder_subject($expiring_count,
+                                                $overdue_count);
 
         $info_sv = array();
         $info_en = array();

From fa46874ae38f0d3318ac78f1bbd9db5442a6ae20 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Wed, 11 Jan 2023 10:43:57 +0100
Subject: [PATCH 242/250] Mail notifications get pushed forward in time when a
 new loan is created if there is a pending notification. This way the user can
 add multiple loans over time without the notification getting sent
 prematurely.

---
 include/Loan.php     | 12 ++++++++++--
 pending_receipts.sql |  9 ---------
 2 files changed, 10 insertions(+), 11 deletions(-)
 delete mode 100644 pending_receipts.sql

diff --git a/include/Loan.php b/include/Loan.php
index 89b8465..26254ed 100644
--- a/include/Loan.php
+++ b/include/Loan.php
@@ -42,16 +42,24 @@ class Loan extends Event {
 
     protected function queue_receipt($user) {
         $now = time();
+        $sendtime = $now + 3600;
         $pending = prepare('select * from `pending_receipt` where `user` = ?
                                 and `since_time` < ? and `send_time` > ?');
         bind($pending, 'iii', $user->get_id(), $now, $now);
         execute($pending);
-        if(result_single($pending) === null) {
+        $result = result_single($pending);
+        if($result === null) {
             $add = prepare('insert into `pending_receipt`
                                 (`user`, `since_time`, `send_time`)
                                 values(?, ?, ?)');
-            bind($add, 'iii', $user->get_id(), $now, $now + 3600);
+            bind($add, 'iii', $user->get_id(), $now, $sendtime);
             execute($add);
+        } else {
+            $update = prepare('update `pending_receipt` set `send_time` = ?
+                               where `user` = ? and `since_time` < ?
+                                   and `send_time` > ?');
+            bind($update, 'iiii', $sendtime, $user->get_id(), $now, $now);
+            execute($update);
         }
     }
 
diff --git a/pending_receipts.sql b/pending_receipts.sql
deleted file mode 100644
index 550da5b..0000000
--- a/pending_receipts.sql
+++ /dev/null
@@ -1,9 +0,0 @@
-create table `pending_receipt` (
-  `user` bigint(20) not null,
-  primary key (`user`),
-  constraint `pr_f_user`
-    foreign key(`user`) references `user`(`id`),
-  `send_time` bigint(20) not null,
-  `since_time` bigint(20) not null
-) character set utf8mb4,
-  collate utf8mb4_unicode_ci;

From b10bf1eed809f439c4b520592277378ec8c46b0f Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Wed, 11 Jan 2023 11:11:42 +0100
Subject: [PATCH 243/250] Added ability to check out a product from the product
 page directly

---
 html/fragments.html     | 42 ++++++++++++++++++++++++++++++++++++++---
 include/ProductPage.php | 11 ++++++++---
 2 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/html/fragments.html b/html/fragments.html
index 761a059..3fade23 100644
--- a/html/fragments.html
+++ b/html/fragments.html
@@ -306,16 +306,52 @@
     <button>Ladda upp</button>
   </form>
 </div>
-<div id="product-history"
-     class="¤hidden¤">
+<div id="product-history">
   <h2>Artikelhistorik</h2>
   ¤history¤
 </div>
 <div id="product-label"
-     class="¤hidden¤">
+     class="¤label_hidden¤">
   <h2>Etikett</h2>
   ¤label¤
 </div>
+<div id="product-direct-checkout" class="¤checkout_hidden¤">
+  <h2>Låna ut</h2>
+  <form class="light"
+        onSubmit="JavaScript:checkoutProduct(event)">
+    <datalist id="user_suggest"></datalist>
+    <input type="hidden"
+           name="page"
+           value="checkout" />
+    <label for="user">Användarnamn:</label>
+    <input onFocus="JavaScript:suggest(this, 'user')"
+           type="text"
+           name="user"
+           list="user_suggest"
+           autocomplete="off"
+           placeholder="Användarnamn"
+           required />
+    <input type="hidden"
+           id="product"
+           name="product"
+           value="¤serial¤" />
+    <button>
+      Låna ut
+    </button>
+    <br/>
+    <label>Löptid:</label>
+    <button onClick="JavaScript:loanLength(event, 7, 'day')">1 vecka</button>
+    <button onClick="JavaScript:loanLength(event, 1, 'year')">1 år</button>
+    <button onClick="JavaScript:loanLength(event, 3, 'year')">3 år</button>
+    <br/>
+    <label for="end">Slutdatum:</label>
+    <input type="text"
+           id="end"
+           onClick="JavaScript:calendar(event)"
+           name="end"
+           value="¤end¤" />
+  </form>
+</div>
 
 ¤¤ attachment_list ¤¤
 <ul class="attachment-list">
diff --git a/include/ProductPage.php b/include/ProductPage.php
index afb25b1..b0fefb4 100644
--- a/include/ProductPage.php
+++ b/include/ProductPage.php
@@ -67,19 +67,24 @@ class ProductPage extends Page {
                         'tags'        => $tags,
                         'info'        => $info,
                         'label'       => '',
-                        'hidden'      => 'hidden',
+                        'label_hidden' => 'hidden',
+                        'checkout_hidden'      => 'hidden',
                         'service'     => 'Starta service',
                         'history'     => $history,
-                        'attachments' => $attachments);
+                        'attachments' => $attachments,
+                        'end'         => format_date(default_loan_end(time())));
         if(class_exists('QRcode')) {
             $fields['label'] = replace($fields,
                                        $this->fragments['product_label']);
         }
         if(!$this->product->get_discardtime()) {
-            $fields['hidden'] = '';
+            $fields['label_hidden'] = '';
             if($this->product->get_status() == 'service') {
                 $fields['service'] = 'Avsluta service';
             }
+            if($this->product->get_status() == 'available') {
+                $fields['checkout_hidden'] = '';
+            }
         }
         return replace($fields, $this->fragments['product_form']);
     }

From a7d961c4d33d21dbb179bdd3c5521cabb50ab865 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Fri, 13 Jan 2023 16:14:41 +0100
Subject: [PATCH 244/250] If a product was checked out and immediately
 returned, an empty email receipt was being sent. Fixed.

---
 include/Cron.php | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/Cron.php b/include/Cron.php
index 80bc67a..f0f41a0 100644
--- a/include/Cron.php
+++ b/include/Cron.php
@@ -96,7 +96,9 @@ class Cron {
                     $extended_loans[] = $loan;
                 }
             }
-            $this->send_receipt($user, $new_loans, $extended_loans);
+            if($new_loans || $extended_loans) {
+                $this->send_receipt($user, $new_loans, $extended_loans);
+            }
             $delete = prepare('delete from `pending_receipt`
                                where `user` = ? and `send_time` < ?');
             bind($delete, 'ii', $user->get_id(), $this->now->getTimestamp());

From d3e6ee7ab2dfe983bd170b25f5d837d60bf53722 Mon Sep 17 00:00:00 2001
From: root <root@dsv.su.se>
Date: Wed, 8 Mar 2023 10:04:13 +0100
Subject: [PATCH 245/250] Fixed too many fields showing up when creating a new
 product

---
 html/fragments.html     | 2 ++
 include/ProductPage.php | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/html/fragments.html b/html/fragments.html
index 3fade23..dcaca53 100644
--- a/html/fragments.html
+++ b/html/fragments.html
@@ -306,6 +306,8 @@
     <button>Ladda upp</button>
   </form>
 </div>
+
+¤¤ product_meta ¤¤
 <div id="product-history">
   <h2>Artikelhistorik</h2>
   ¤history¤
diff --git a/include/ProductPage.php b/include/ProductPage.php
index b0fefb4..57cefd8 100644
--- a/include/ProductPage.php
+++ b/include/ProductPage.php
@@ -86,7 +86,9 @@ class ProductPage extends Page {
                 $fields['checkout_hidden'] = '';
             }
         }
-        return replace($fields, $this->fragments['product_form']);
+        $out = replace($fields, $this->fragments['product_form']);
+        $out .= replace($fields, $this->fragments['product_meta']);
+        return $out;
     }
 
     private function build_history_table($history) {

From 019725dade693f618c2fa5bce777570a3231fac6 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Thu, 8 Feb 2024 13:39:09 +0100
Subject: [PATCH 246/250] Missed replacing a placeholder in the product_form
 fragment

---
 include/ProductPage.php | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/ProductPage.php b/include/ProductPage.php
index 57cefd8..bef9807 100644
--- a/include/ProductPage.php
+++ b/include/ProductPage.php
@@ -69,6 +69,7 @@ class ProductPage extends Page {
                         'label'       => '',
                         'label_hidden' => 'hidden',
                         'checkout_hidden'      => 'hidden',
+                        'hidden'      => '',
                         'service'     => 'Starta service',
                         'history'     => $history,
                         'attachments' => $attachments,

From c31c827b3622bfd96e7d70574a74bfd1d7585c74 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Thu, 8 Feb 2024 15:30:33 +0100
Subject: [PATCH 247/250] Upped the default font size a bit.

---
 style.css | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/style.css b/style.css
index 61c9529..d3eeec8 100644
--- a/style.css
+++ b/style.css
@@ -1,3 +1,7 @@
+body {
+    font-size: 90%;
+}
+
 textarea {
     height: 80px;
 }

From 1f33f739380ffc812e38086a5500b795fb56bcab Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Thu, 8 Feb 2024 15:33:00 +0100
Subject: [PATCH 248/250] Implemented notification emails when discarding
 products.

---
 config.php.example  |  5 ++++-
 cron.php            |  2 +-
 include/Cron.php    |  5 +++--
 include/Product.php | 42 +++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 49 insertions(+), 5 deletions(-)

diff --git a/config.php.example b/config.php.example
index 9a6fbb8..32cc899 100644
--- a/config.php.example
+++ b/config.php.example
@@ -6,6 +6,9 @@ $db_user = 'dbname';
 $db_pass = 'dbpassword';
 $db_name = 'dbuser';
 
+# Email subject prefix
+$email_subject_prefix = "System name: ";
+
 # Address to use as the sender for reminder emails
 $sender = 'noreply@example.com';
 
@@ -15,7 +18,7 @@ $error_address = 'root@example.com';
 # Discard notifications
 # If this is set to an email address, the system will send a notification
 # there each time a product is discarded.
-#$notify_discard = 'inventory-tracking@example.com';
+#$discard_notify = 'inventory-tracking@example.com';
 $discard_notify = false;
 
 # Directory to save attachments to
diff --git a/cron.php b/cron.php
index 5e52909..7761e2f 100755
--- a/cron.php
+++ b/cron.php
@@ -7,7 +7,7 @@ require('./include/functions.php');
 
 header('Content-Type: text/html; charset=UTF-8');
 
-$cron = new Cron($sender, $error_address);
+$cron = new Cron($sender, $error_address, $email_subject_prefix);
 $cron->run();
 
 ?>
diff --git a/include/Cron.php b/include/Cron.php
index f0f41a0..d72b957 100644
--- a/include/Cron.php
+++ b/include/Cron.php
@@ -5,10 +5,11 @@ class Cron {
     private $error = '';
     private $kvs;
     private $ldap;
-    public function __construct($sender, $error) {
+    public function __construct($sender, $error, $prefix) {
         $this->now = new DateTimeImmutable();
         $this->sender = $sender;
         $this->error = $error;
+        $this->subject_prefix = $prefix;
         $this->warn_time = DateInterval::createFromDateString('3 days');
         $this->warn_date = $this->now->add($this->warn_time);
         $this->run_interval = DateInterval::createFromDateString('1 day');
@@ -108,7 +109,7 @@ class Cron {
     }
 
     private function make_receipt_subject($num_new, $num_extended) {
-        $subject = "DSV Helpdesk: ";
+        $subject = $this->subject_prefix;
         $messages = array();
         if($num_new > 1) {
             $messages[] = $num_new." nya";
diff --git a/include/Product.php b/include/Product.php
index 1f4468c..a13c1b3 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -68,6 +68,13 @@ class Product extends Entity {
         $this->update_fields();
         $this->update_info();
         $this->update_tags();
+
+        # Global variables are bad, but passing these email properties
+        # around everywhere would be worse
+        global $sender, $notify_discard, $email_subject_prefix;
+        $this->discard_email_address = $notify_discard;
+        $this->email_sender = $sender;
+        $this->email_subject_prefix = $email_subject_prefix;
     }
     
     private function update_fields() {
@@ -272,9 +279,42 @@ class Product extends Entity {
         bind($update, 'ii', $now, $this->id);
         execute($update);
         $this->discardtime = $now;
+        if($this->discard_email_address) {
+            $this->send_discard_email();
+        }
         return true;
     }
-    
+
+    private function send_discard_email() {
+        $brand = $this->brand;
+        $name = $this->name;
+        $invoice = $this->invoice;
+        $serial = $this->serial;
+        $discardtime = format_date($this->discardtime);
+
+        $subject = $this->email_subject_prefix.$brand.' '.$name.' skrotad';
+        $message = <<<EOF
+Hej!
+
+Följande artikel har skrotats i Boka:
+
+$brand $name, serienummer: $serial, fakturanummer: $invoice
+
+EOF;
+        try {
+            mb_send_mail($this->discard_email_address,
+                         $subject,
+                         $message,
+                         'From: '.$this->email_sender);
+        } catch(Exception $e) {
+            error_log($e->getMessage());
+            mb_send_mail($this->error,
+                         "Kunde inte skicka mail",
+                         "Mail kunde inte skickas till "
+                          . $this->discard_email_address);
+        }
+    }
+
     public function toggle_service() {
         $status = $this->get_status();
         $now = time();

From 4f8bc9486d905f339b7fdb7bd59f8f52c2b1c199 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Thu, 8 Feb 2024 15:38:54 +0100
Subject: [PATCH 249/250] Fixed the inventory registry field not trimming
 whitespace

---
 include/Ajax.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/Ajax.php b/include/Ajax.php
index 99abc22..bc4a4cc 100644
--- a/include/Ajax.php
+++ b/include/Ajax.php
@@ -164,7 +164,7 @@ class Ajax extends Responder {
         }
         $product = null;
         try {
-            $product = new Product($_POST['serial'], 'serial');
+            $product = new Product(trim($_POST['serial']), 'serial');
         } catch(Exception $e) {
             return new Failure('Ogiltigt serienummer.');
         }

From 2f6cc432b1642c3d84dd6be2d1e31a7886b225c8 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Thu, 8 Feb 2024 16:36:35 +0100
Subject: [PATCH 250/250] Missed using the configured subject prefix in a spot

---
 include/Cron.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/Cron.php b/include/Cron.php
index d72b957..9fcaed8 100644
--- a/include/Cron.php
+++ b/include/Cron.php
@@ -207,7 +207,7 @@ EOF;
     }
 
     private function make_reminder_subject($num_expiring, $num_expired) {
-        $subject = "DSV Helpdesk: ";
+        $subject = $this->subject_prefix;
         $messages = array();
         if($num_expiring > 0) {
             $messages[] = $num_expiring." utgående";