dcc202fb249a446ac15c7cf413b9f1b4a3f31b58
Bernd Wurst Speichern der Eingaben (unv...

Bernd Wurst authored 6 years ago

1) <?php
2) /*
3) This file belongs to the Webinterface of schokokeks.org Hosting
4) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 1 year ago

5) Written by schokokeks.org Hosting, namely
Bernd Wurst Speichern der Eingaben (unv...

Bernd Wurst authored 6 years ago

6)   Bernd Wurst <bernd@schokokeks.org>
7)   Hanno Böck <hanno@schokokeks.org>
8) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 1 year ago

9) This code is published under a 0BSD license.
Bernd Wurst Speichern der Eingaben (unv...

Bernd Wurst authored 6 years ago

10) 
11) 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.
12) */
13) 
14) require_once('contacts.php');
Bernd Wurst Nummercheck ausgelagert und...

Bernd Wurst authored 6 years ago

15) require_once('numbers.php');
Bernd Wurst Speichern der Eingaben (unv...

Bernd Wurst authored 6 years ago

16) require_once('inc/debug.php');
17) 
18) require_once('session/start.php');
19) 
20) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

21) require_role([ROLE_CUSTOMER]);
Bernd Wurst Speichern der Eingaben (unv...

Bernd Wurst authored 6 years ago

22) $section = 'contacts_list';
23) 
Bernd Wurst Ermögliche das Ändern eines...

Bernd Wurst authored 6 years ago

24) $back = 'list';
25) if (isset($_REQUEST['back'])) {
26)     $back = urldecode($_REQUEST['back']);
27) }
28) 
Bernd Wurst Neue Darstellung der Kontak...

Bernd Wurst authored 6 years ago

29) if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete') {
30)     $contact = get_contact($_REQUEST['id']);
Hanno remove whitespace in empty...

Hanno authored 5 years ago

31) 
Bernd Wurst Abstrahieren der Anzeigefun...

Bernd Wurst authored 6 years ago

32)     $contact_string = display_contact($contact);
Bernd Wurst Neue Darstellung der Kontak...

Bernd Wurst authored 6 years ago

33) 
34)     $sure = user_is_sure();
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

35)     if ($sure === null) {
36)         are_you_sure("action=delete&id={$contact['id']}&back=".urlencode($back), "Möchten Sie diese Adresse wirklich löschen? {$contact_string}");
37)     } elseif ($sure === true) {
38)         delete_contact($contact['id']);
39)         if (! $debugmode) {
Bernd Wurst Ermögliche das Ändern eines...

Bernd Wurst authored 6 years ago

40)             header("Location: ".$back);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

41)         }
42)     } elseif ($sure === false) {
43)         if (! $debugmode) {
44)             header("Location: ".$back);
45)         }
Bernd Wurst Neue Darstellung der Kontak...

Bernd Wurst authored 6 years ago

46)     }
Bernd Wurst Speichern der Eingaben (unv...

Bernd Wurst authored 6 years ago

47) } else {
Bernd Wurst Neue Darstellung der Kontak...

Bernd Wurst authored 6 years ago

48)     check_form_token('contacts_edit');
Bernd Wurst Speichern der Eingaben (unv...

Bernd Wurst authored 6 years ago

49) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

50)     $new = false;
Bernd Wurst Neue Darstellung der Kontak...

Bernd Wurst authored 6 years ago

51)     if ($_REQUEST['id'] == 'new') {
52)         title("Adresse anlegen");
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

53)         $new = true;
Bernd Wurst Neue Darstellung der Kontak...

Bernd Wurst authored 6 years ago

54)     } else {
55)         title("Adresse bearbeiten");
56)     }
Bernd Wurst Speichern der Eingaben (unv...

Bernd Wurst authored 6 years ago

57) 
Bernd Wurst Neue Darstellung der Kontak...

Bernd Wurst authored 6 years ago

58)     $c = new_contact();
59)     if (! $new) {
60)         $c = get_contact($_REQUEST['id']);
61)     }
Bernd Wurst API-Funktionen um Kontakte...

Bernd Wurst authored 6 years ago

62) 
Bernd Wurst Neue Darstellung der Kontak...

Bernd Wurst authored 6 years ago

63)     if (!isset($_REQUEST['firma'])) {
64)         $_REQUEST['firma'] = $c['company'];
65)     }
66)     if (!isset($_REQUEST['name'])) {
67)         $_REQUEST['name'] = $c['name'];
68)     }
69)     if (!isset($_REQUEST['land'])) {
70)         $_REQUEST['land'] = $c['country'];
Bernd Wurst Speichern der Eingaben (unv...

Bernd Wurst authored 6 years ago

71)     }
72) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

73)     if ($c['nic_handle'] != null) {
Bernd Wurst Neue Darstellung der Kontak...

Bernd Wurst authored 6 years ago

74)         if ($c['name'] != $_REQUEST['name'] || $c['company'] != $_REQUEST['firma'] || $c['country'] != $_REQUEST['land']) {
75)             system_failure('Name/Firma/Land kann bei diesem Kontakt nicht geändert werden.');
76)         }
77)     }
Bernd Wurst Speichern der Eingaben (unv...

Bernd Wurst authored 6 years ago

78) 
Bernd Wurst Abstrahieren der Anzeigefun...

Bernd Wurst authored 6 years ago

79)     $kundenkontakte = get_kundenkontakte();
80)     if ($c['id'] == $kundenkontakte['kunde']) {
81)         if (!$_REQUEST['name'] && !$_REQUEST['firma']) {
82)             system_failure('Beim Inhaber darf nicht Firmenname und Name leer sein.');
83)         }
84)     }
Bernd Wurst Prüfe Telefonnummer

Bernd Wurst authored 6 years ago

85) 
Bernd Wurst Ermögliche das Speichern de...

Bernd Wurst authored 5 years ago

86)     $c['salutation'] = null;
87)     if ($_REQUEST['salutation'] == 'Herr') {
88)         $c['salutation'] = 'Herr';
89)     } elseif ($_REQUEST['salutation'] == 'Frau') {
90)         $c['salutation'] = 'Frau';
91)     }
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

92)     $c['company'] = filter_input_general(maybe_null($_REQUEST['firma']));
93)     $c['name'] = filter_input_general(maybe_null($_REQUEST['name']));
94)     $c['address'] = filter_input_general(maybe_null($_REQUEST['adresse']));
95)     $c['country'] = filter_input_oneline(maybe_null(strtoupper($_REQUEST['land'])));
96)     $c['zip'] = filter_input_oneline(maybe_null($_REQUEST['plz']));
97)     $c['city'] = filter_input_oneline(maybe_null($_REQUEST['ort']));
Bernd Wurst möglicherweise undefinierte...

Bernd Wurst authored 5 years ago

98)     if ($new && isset($_REQUEST['email'])) {
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

99)         $c['email'] = filter_input_oneline(maybe_null($_REQUEST['email']));
Bernd Wurst Ermögliche das Erstellen ei...

Bernd Wurst authored 6 years ago

100)         if (!check_emailaddr($c['email'])) {
101)             system_failure("Ungültige E-Mail-Adresse!");
102)         }
103)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

104) 
Bernd Wurst Neue Darstellung der Kontak...

Bernd Wurst authored 6 years ago

105) 
Bernd Wurst möglicherweise undefinierte...

Bernd Wurst authored 5 years ago

106)     if (isset($_REQUEST['telefon']) && $_REQUEST['telefon'] != '') {
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

107)         $num = format_number(filter_input_oneline($_REQUEST['telefon']), $_REQUEST['land']);
Bernd Wurst Neue Darstellung der Kontak...

Bernd Wurst authored 6 years ago

108)         if ($num) {
109)             $c['phone'] = $num;
110)         } else {
111)             system_failure('Die eingegebene Telefonnummer scheint nicht gültig zu sein!');
112)         }
Bernd Wurst Prüfe Telefonnummer

Bernd Wurst authored 6 years ago

113)     } else {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

114)         $c['phone'] = null;
Bernd Wurst Prüfe Telefonnummer

Bernd Wurst authored 6 years ago

115)     }
Bernd Wurst möglicherweise undefinierte...

Bernd Wurst authored 5 years ago

116)     if (isset($_REQUEST['mobile']) && $_REQUEST['mobile'] != '') {
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

117)         $num = format_number(filter_input_oneline($_REQUEST['mobile']), $_REQUEST['land']);
Bernd Wurst Neue Darstellung der Kontak...

Bernd Wurst authored 6 years ago

118)         if ($num) {
119)             $c['mobile'] = $num;
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

120)             if (! $c['phone']) {
121)                 // dupliziere die Mobiltelefonnummer als normale Nummer wegen der Nutzung als Domainhandles
122)                 $c['phone'] = $num;
123)             }
Bernd Wurst Neue Darstellung der Kontak...

Bernd Wurst authored 6 years ago

124)         } else {
125)             system_failure('Die eingegebene Mobiltelefonnummer scheint nicht gültig zu sein!');
126)         }
Bernd Wurst Nummercheck ausgelagert und...

Bernd Wurst authored 6 years ago

127)     } else {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

128)         $c['mobile'] = null;
Bernd Wurst Nummercheck ausgelagert und...

Bernd Wurst authored 6 years ago

129)     }
Bernd Wurst möglicherweise undefinierte...

Bernd Wurst authored 5 years ago

130)     if (isset($_REQUEST['telefax']) && $_REQUEST['telefax'] != '') {
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

131)         $num = format_number(filter_input_oneline($_REQUEST['telefax']), $_REQUEST['land']);
Bernd Wurst Neue Darstellung der Kontak...

Bernd Wurst authored 6 years ago

132)         if ($num) {
133)             $c['fax'] = $num;
134)         } else {
135)             system_failure('Die eingegebene Faxnummer scheint nicht gültig zu sein!');
136)         }
Bernd Wurst Nummercheck ausgelagert und...

Bernd Wurst authored 6 years ago

137)     } else {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

138)         $c['fax'] = null;
Bernd Wurst Nummercheck ausgelagert und...

Bernd Wurst authored 6 years ago

139)     }
Bernd Wurst Speichern der Eingaben (unv...

Bernd Wurst authored 6 years ago

140) 
Hanno remove whitespace in empty...

Hanno authored 5 years ago

141) 
Bernd Wurst Suche PGP-Key nur wenn der...

Bernd Wurst authored 6 years ago

142)     if (isset($_REQUEST['usepgp']) && $_REQUEST['usepgp'] == 'yes' && isset($_REQUEST['pgpid'])) {
Bernd Wurst Ermögliche das Setzen des P...

Bernd Wurst authored 6 years ago

143)         $pgpid = preg_replace('/[^0-9a-fA-F]/', '', $_REQUEST['pgpid']);
Bernd Wurst Prüfe die Verwendbarkeit vo...

Bernd Wurst authored 5 years ago

144)         DEBUG('PGP-ID: '.$pgpid);
145)         if (isset($_REQUEST['pgpkey']) && $_REQUEST['pgpkey']) {
146)             DEBUG('Key angegeben, wird importiert');
147)             $c['pgp_id'] = $pgpid;
148)             import_pgp_key($_REQUEST['pgpkey']);
149)             $c['pgp_key'] = $_REQUEST['pgpkey'];
Bernd Wurst Ermögliche das Setzen des P...

Bernd Wurst authored 6 years ago

150)         } else {
Bernd Wurst Prüfe die Verwendbarkeit vo...

Bernd Wurst authored 5 years ago

151)             DEBUG('Kein Key, wird vom Keyserver geholt!');
152)             $c['pgp_id'] = fetch_pgp_key($pgpid);
153)         }
154)         if (!test_pgp_key($c['pgp_id'])) {
155)             $c['pgp_id'] = null;
156)             $c['pgp_key'] = null;
157)             warning('Ihr PGP-Key wurde nicht übernommen, da er nicht gültig zu sein scheint. Bitte geben Sie im Zweifel die vollständige Key-ID (Fingerprint) und einen Key in der ASCII-Form ein.');
Bernd Wurst Ermögliche das Setzen des P...

Bernd Wurst authored 6 years ago

158)         }
Bernd Wurst Suche PGP-Key nur wenn der...

Bernd Wurst authored 6 years ago

159)     } else {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

160)         $c['pgp_id'] = null;
161)         $c['pgp_key'] = null;
Bernd Wurst Ermögliche das Setzen des P...

Bernd Wurst authored 6 years ago

162)     }
Bernd Wurst Speichern der Eingaben (unv...

Bernd Wurst authored 6 years ago

163) 
Bernd Wurst Ermögliche das Erstellen ei...

Bernd Wurst authored 6 years ago

164) 
165)     if (isset($_REQUEST['domainholder']) && $_REQUEST['domainholder'] == 1) {
166)         if (!possible_domainholder($c)) {
167)             DEBUG("Kein möglicher Domaininhaber:");
168)             DEBUG($c);
169)             warning('Zur Verwendung als Domaininhaber fehlen noch Angaben.');
170)             redirect('edit?id='.$_REQUEST['id'].'&back='.$_REQUEST['back'].'&domainholder=1');
171)         }
Bernd Wurst möglicherweise undefinierte...

Bernd Wurst authored 5 years ago

172)         if (isset($_REQUEST['email']) && !have_mailaddress($_REQUEST['email'])) {
Bernd Wurst Zeige eine Warnung an, dass...

Bernd Wurst authored 6 years ago

173)             warning("Die neu angelegte Adresse kann erst dann als Domaininhaber genutzt werden, wenn die E-Mail-Adresse bestätigt wurde.");
174)         }
Bernd Wurst Ermögliche das Erstellen ei...

Bernd Wurst authored 6 years ago

175)     }
176) 
Bernd Wurst Frage die Zustimmung des Do...

Bernd Wurst authored 6 years ago

177)     $domains = domainlist_by_contact($c);
178)     if ($domains) {
Bernd Wurst möglicherweise undefinierte...

Bernd Wurst authored 5 years ago

179)         if (isset($_REQUEST['email']) && $c['email'] != $_REQUEST['email'] && !(isset($_REQUEST['designated']) && $_REQUEST['designated'] == 'yes')) {
Bernd Wurst Frage die Zustimmung des Do...

Bernd Wurst authored 6 years ago

180)             system_failure("Sie müssen die explizite Zustimmung des Domaininhabers bestätigen um diese Änderungen zu speichern.");
181)         }
182)     }
183) 
Bernd Wurst Neue Darstellung der Kontak...

Bernd Wurst authored 6 years ago

184)     // Zuerst Kontakt speichern und wenn eine Änderung der E-Mail gewünscht war,
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

185)     // dann hinterher das Token erzeugen und senden. Weil wir für das Token die
186)     // Contact-ID brauchen und die bekommen wir bei einer Neueintragung erst nach
Bernd Wurst Neue Darstellung der Kontak...

Bernd Wurst authored 6 years ago

187)     // dem Speichern.
Bernd Wurst Speichern der Änderungen mö...

Bernd Wurst authored 6 years ago

188) 
Bernd Wurst Neue Darstellung der Kontak...

Bernd Wurst authored 6 years ago

189)     $id = save_contact($c);
190)     $c['id'] = $id;
Bernd Wurst Speichern der Eingaben (unv...

Bernd Wurst authored 6 years ago

191) 
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

192)     if (isset($_REQUEST['email']) && check_emailaddr($_REQUEST['email']) && ($new || $c['email'] != $_REQUEST['email'])) {
Bernd Wurst Neue Darstellung der Kontak...

Bernd Wurst authored 6 years ago

193)         if (have_mailaddress($_REQUEST['email'])) {
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

194)             save_emailaddress($c['id'], $_REQUEST['email']);
Bernd Wurst Neue Darstellung der Kontak...

Bernd Wurst authored 6 years ago

195)         } else {
196)             send_emailchange_token($c['id'], $_REQUEST['email']);
197)         }
198)     }
199)     if ($c['nic_id']) {
200)         $c = get_contact($c['id']);
201)         upload_contact($c);
Bernd Wurst Speichern der Änderungen mö...

Bernd Wurst authored 6 years ago

202)     }
Bernd Wurst Speichern der Eingaben (unv...

Bernd Wurst authored 6 years ago

203) 
204) 
Bernd Wurst Suche PGP-Key nur wenn der...

Bernd Wurst authored 6 years ago

205)     redirect($back);