Nummercheck ausgelagert und für alle Rufnummern
Bernd Wurst

Bernd Wurst commited on 2018-01-24 10:34:58
Zeige 2 geänderte Dateien mit 54 Einfügungen und 12 Löschungen.

... ...
@@ -0,0 +1,30 @@
1
+<?php
2
+/*
3
+This file belongs to the Webinterface of schokokeks.org Hosting
4
+
5
+Written 2008-2018 by schokokeks.org Hosting, namely
6
+  Bernd Wurst <bernd@schokokeks.org>
7
+  Hanno Böck <hanno@schokokeks.org>
8
+
9
+To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10
+
11
+You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
12
+http://creativecommons.org/publicdomain/zero/1.0/
13
+
14
+Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15
+*/
16
+
17
+require_once('vendor/autoload.php');
18
+
19
+function format_number($number, $country) {
20
+    $phoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance();
21
+    try {
22
+        $phoneNumber = $phoneNumberUtil->parse($number, $country);
23
+    } catch (Exception $e) {
24
+        return NULL;
25
+    }
26
+    if ($phoneNumberUtil->isValidNumber($phoneNumber)) {
27
+        return $phoneNumberUtil->format($phoneNumber, 1);
28
+    }
29
+    return NULL;
30
+}
... ...
@@ -15,8 +15,8 @@ Nevertheless, in case you use a significant part of this code, we ask (but not r
15 15
 */
16 16
 
17 17
 require_once('contacts.php');
18
+require_once('numbers.php');
18 19
 require_once('inc/debug.php');
19
-require_once('vendor/autoload.php');
20 20
 
21 21
 require_once('session/start.php');
22 22
 
... ...
@@ -54,25 +54,37 @@ $c['zip'] = maybe_null($_REQUEST['plz']);
54 54
 $c['city'] = maybe_null($_REQUEST['ort']);
55 55
 
56 56
     
57
+
57 58
 if ($_REQUEST['telefon']) {
58
-    $phoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance();
59
-    try {
60
-        $phoneNumber = $phoneNumberUtil->parse($_REQUEST['telefon'], $_REQUEST['land'], null, true);
61
-    } catch (Exception $e) {
59
+    $num = format_number($_REQUEST['telefon'], $_REQUEST['land']);
60
+    if ($num) {
61
+        $c['phone'] = $num;
62
+    } else {
62 63
         system_failure('Die eingegebene Telefonnummer scheint nicht gültig zu sein!');
63 64
     }
64
-    if ($phoneNumberUtil->isValidNumber($phoneNumber)) {
65
-        $c['phone'] = $phoneNumberUtil->format($phoneNumber, 1);
66 65
 } else {
67
-        system_failure('Die eingegebene Telefonnummer scheint nicht gültig zu sein!');
68 66
     $c['phone'] = NULL;
69 67
 }
68
+if ($_REQUEST['mobile']) {
69
+    $num = format_number($_REQUEST['mobile'], $_REQUEST['land']);
70
+    if ($num) {
71
+        $c['mobile'] = $num;
70 72
     } else {
71
-    $c['phone'] = NULL;
73
+        system_failure('Die eingegebene Mobiltelefonnummer scheint nicht gültig zu sein!');
74
+    }
75
+} else {
76
+    $c['mobile'] = NULL;
77
+}
78
+if ($_REQUEST['telefax']) {
79
+    $num = format_number($_REQUEST['telefax'], $_REQUEST['land']);
80
+    if ($num) {
81
+        $c['fax'] = $num;
82
+    } else {
83
+        system_failure('Die eingegebene Faxnummer scheint nicht gültig zu sein!');
84
+    }
85
+} else {
86
+    $c['fax'] = NULL;
72 87
 }
73
-//$c['phone'] = maybe_null($_REQUEST['telefon']);
74
-$c['mobile'] = maybe_null($_REQUEST['mobile']);
75
-$c['fax'] = maybe_null($_REQUEST['telefax']);
76 88
 
77 89
 // FIXME: PGP-ID/Key fehlen
78 90
 
79 91