From eab60a4dcb47d1e50b56ba7e36d16d7da5cbe562 Mon Sep 17 00:00:00 2001
From: Leif Andersson <leif.andersson@control.lth.se>
Date: Wed, 31 Aug 2016 12:55:30 +0200
Subject: [PATCH] =?UTF-8?q?Rensade=20upp=20n=C3=A5gra=20n=C3=A4rmast=20kos?=
 =?UTF-8?q?metiska=20buggar.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 action.default.php          |  4 +--
 lib/class.RegisterUtils.php | 58 +++++++++++++++++++------------------
 2 files changed, 32 insertions(+), 30 deletions(-)

diff --git a/action.default.php b/action.default.php
index 1d09b28..50d2f07 100644
--- a/action.default.php
+++ b/action.default.php
@@ -90,7 +90,7 @@ if (isset($params['maxparticipants'])) {
     . 'has already been reached for this event. ';
 
   //echo '<pre>'; print_r($numparticipants); echo'</pre>';
-  if ($numparticipants < $maxparticipants) {
+  if ($numParticipants < $maxparticipants) {
     $smarty->assign('participants',$partMessage);
   } else {
     $smarty->assign('tooMany',$tooManyMessage);
@@ -98,7 +98,7 @@ if (isset($params['maxparticipants'])) {
   }
 }      
 
-if ($params['send']) {
+if (isset($params['send'])) {
   $fieldsOK = true;
   foreach (RegisterUtils::$mandatoryKeys as $key) {
     if ($reg->values[$key] == '') {
diff --git a/lib/class.RegisterUtils.php b/lib/class.RegisterUtils.php
index 0c07615..b3b6c82 100644
--- a/lib/class.RegisterUtils.php
+++ b/lib/class.RegisterUtils.php
@@ -54,18 +54,18 @@ class RegisterUtils {
     }
     foreach (self::$mandatoryKeys as $key) {
       $this->values[$key] = '';
-      if($params[$key]) {
+      if(isset($params[$key])) {
         $val = htmlspecialchars_decode(trim($params[$key]));
-	$this->mandatory[$key] = $val;
-	$this->values[$key] = $val;
+        $this->mandatory[$key] = $val;
+        $this->values[$key] = $val;
       }
     }
     foreach (self::$optionalKeys as $key) {
       $this->values[$key] = '';
-      if($params[$key]) {
+      if(isset($params[$key])) {
         $val = htmlspecialchars_decode(trim($params[$key]));
-	$this->optional[$key] = $val;
-	$this->values[$key] = $val;
+        $this->optional[$key] = $val;
+        $this->values[$key] = $val;
       }
     }
     $i = 0;
@@ -73,8 +73,10 @@ class RegisterUtils {
       $check = 'meal'.$i++;
       $this->checkBoxes[$key] = $check;
       $this->selectedBoxes[$key] = '';
-      $res = $params[$check];
-      if ($res) $this->selectedBoxes[$key] = $res;
+      if (isset($params[$check])) {
+        $res = $params[$check];
+        if ($res) $this->selectedBoxes[$key] = $res;
+      }
     }
     //echo '<pre>'; print_r($this->values); echo '</pre>';
   }
@@ -128,7 +130,7 @@ class RegisterUtils {
       //fwrite($outFile,$f.PHP_EOL);
       if (preg_match('|(\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d)|',$f,$matches)) {
       } else {
-	continue;
+        continue;
       }
       // ignore the MacOSX special files
       $pos = strpos($f,'._');
@@ -140,35 +142,35 @@ class RegisterUtils {
 			     $this->mealKeys);
       foreach ($allKeys as $key) {
 	//fwrite($outFile,$key.PHP_EOL);
-	$values[$key] = '';
+        $values[$key] = '';
       }
 
       $fs =  sprintf('%s/%s',$dirname,$f);
       $lines = file($fs);
       $readInvoice = false;
       foreach ($lines as $line) {
-	if ($readInvoice) {
-	  $values['invoice'] .= $line;
-	  continue;
-	}
-	$line = rtrim($line);
-	list($key,$val) = explode(':',$line) + Array(null, null);
-	$val = ltrim($val);
-	if ($key == 'invoice') {
-	  $readInvoice = true;
-	  $values['invoice'] = '';
-	  continue;
-	}	  
-	if (in_array($key,$allKeys)) {
-	  $values[$key] = $val;
-	  continue;
-	}
+        if ($readInvoice) {
+          $values['invoice'] .= $line;
+          continue;
+        }
+        $line = rtrim($line);
+        list($key,$val) = explode(':',$line) + Array(null, null);
+        $val = ltrim($val);
+        if ($key == 'invoice') {
+          $readInvoice = true;
+          $values['invoice'] = '';
+          continue;
+        }	  
+        if (in_array($key,$allKeys)) {
+          $values[$key] = $val;
+          continue;
+        }
       }
 
       $fields = array(); $dquot = '"'; $ddquot = '""';
       foreach ($allKeys as $key) {
-	$value = str_replace($dquot,$ddquot,$values[$key]);
-	$value = sprintf('"%s"',$value);
+        $value = str_replace($dquot,$ddquot,$values[$key]);
+        $value = sprintf('"%s"',$value);
         $fields[] = $value;
       }
       $outLine = join(';',$fields).PHP_EOL;
-- 
GitLab