From 1fe1b90be94c974aabdaff21919bc5a189f60efb Mon Sep 17 00:00:00 2001
From: Leif Andersson <leif.andersson@control.lth.se>
Date: Fri, 9 Sep 2016 12:48:45 +0200
Subject: [PATCH] Konverterade UTF8 till Latin1 eller ascii

---
 lib/class.RegisterUtils.php | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/lib/class.RegisterUtils.php b/lib/class.RegisterUtils.php
index b3b6c82..34de293 100644
--- a/lib/class.RegisterUtils.php
+++ b/lib/class.RegisterUtils.php
@@ -15,9 +15,14 @@ class RegisterUtils {
   private $mandatory = array();
   private $optional = array();
   public $values = array();
- 
 
-  function __construct($directory = NULL) {
+  private static function toASCII($data) {
+    $ss = utf8_decode($data);
+    $s = iconv("LATIN1", "ASCII//TRANSLIT", $ss);
+    return $s;
+  }
+ 
+  function __construct($directory = NULL) {    
     clearstatcache();
     $this->errorString='';
     if (!$directory) {
@@ -97,8 +102,10 @@ class RegisterUtils {
   }
 
   public function saveRegistration() {
-    $last = $this->mandatory{'last'};
-    $first = $this->mandatory{'first'};
+    $last = self::toASCII($this->mandatory{'last'});
+    $last = strtr($last, ' ','_');
+    $first = self::toASCII($this->mandatory{'first'});
+    $first = strtr($first, ' ','_');
     $date = substr(date(DateTime::ISO8601),0,-5);
     $filename =  $this->directory.'/'.$last . '_' . $first . '_' . $date;
     $contents = '';
@@ -171,7 +178,7 @@ class RegisterUtils {
       foreach ($allKeys as $key) {
         $value = str_replace($dquot,$ddquot,$values[$key]);
         $value = sprintf('"%s"',$value);
-        $fields[] = $value;
+        $fields[] = utf8_decode($value);
       }
       $outLine = join(';',$fields).PHP_EOL;
       fwrite($outFile,$outLine);
-- 
GitLab