Ermögliche das Speichern der Anrede für Kontakte
Bernd Wurst

Bernd Wurst commited on 2018-12-29 13:43:24
Zeige 3 geänderte Dateien mit 27 Einfügungen und 14 Löschungen.

... ...
@@ -53,6 +53,14 @@ if (isset($_REQUEST['domainholder']) && $_REQUEST['domainholder'] == 1) {
53 53
 }
54 54
 $odd = false;
55 55
 $html = '<table>';
56
+$buttons = '<span class="buttonset" id="buttonset-salutation">
57
+         <input type="radio" name="salutation" id="salutation-firma" value="Firma" '.($c['salutation'] === null ? 'checked="checked"' : '').'/>
58
+         <label for="salutation-firma">Neutral</label>
59
+         <input type="radio" name="salutation" id="salutation-herr" value="Herr" '.($c['salutation'] === 'Herr' ? 'checked="checked"' : '').'/>
60
+         <label for="salutation-herr">Herr</label>
61
+         <input type="radio" name="salutation" id="salutation-frau" value="Frau" '.($c['salutation'] === 'Frau' ? 'checked="checked"' : '').'/>
62
+         <label for="salutation-frau">Frau</label>';
63
+$html .= '    <tr class="'.($odd == true ? 'odd' : 'even').'"><td>Bevorzugte Anrede:</td><td>'.$buttons.'</td></tr>';
56 64
 $html .= '    <tr class="'.($odd == true ? 'odd' : 'even').'"><td>Firmenname:</td><td><input type="text" name="firma" id="firma" value="'.$c['company'].'" '.$readonly.' /></td></tr>';
57 65
 $odd = !$odd;
58 66
 $html .= '<tr class="'.($odd == true ? 'odd' : 'even').'"><td>'.($c['company'] ? 'Ansprechpartner' : 'Name').':</td><td><input type="text" name="name" id="name" value="'.$c['name'].'" '.$readonly.' /></td></tr>';
... ...
@@ -22,13 +22,6 @@ require_once('class/domain.php');
22 22
 
23 23
 require_once('contactapi.php');
24 24
 
25
-/*
26
-Todo:
27
-    - Ausgabe-Funktion abstrahieren
28
-    - Telefonnummern bei Ausgabe durch filter_input_general schieben
29
-    - Domaininhaber festlegen
30
-*/
31
-
32 25
 
33 26
 function new_contact()
34 27
 {
... ...
@@ -37,6 +30,7 @@ function new_contact()
37 30
         "lastchange" => time(),
38 31
         "nic_handle" => null,
39 32
         "nic_id" => null,
33
+        "salutation" => null,
40 34
         "company" => null,
41 35
         "name" => null,
42 36
         "address" => null,
... ...
@@ -53,12 +47,16 @@ function new_contact()
53 47
 }
54 48
 
55 49
 
56
-function get_contact($id)
50
+function get_contact($id, $customer = null)
57 51
 {
52
+    $c = $_SESSION['customerinfo']['customerno'];
53
+    if ($customer != null && have_role(ROLE_SYSADMIN)) {
54
+        $c = $customer;
55
+    }
58 56
     $args = array(
59
-        "cid" => (int) $_SESSION['customerinfo']['customerno'],
57
+        "cid" => (int) $c,
60 58
         "id" => (int) $id);
61
-    $result = db_query("SELECT id, state, lastchange, nic_id, nic_handle, company, name, address, zip, city, country, phone, mobile, fax, email, pgp_id, pgp_key FROM kundendaten.contacts WHERE id=:id AND customer=:cid", $args);
59
+    $result = db_query("SELECT id, state, lastchange, nic_id, nic_handle, salutation, company, name, address, zip, city, country, phone, mobile, fax, email, pgp_id, pgp_key FROM kundendaten.contacts WHERE id=:id AND customer=:cid", $args);
62 60
     if ($result->rowCount() == 0) {
63 61
         system_failure("Kontakt nicht gefunden oder gehört nicht diesem Kunden");
64 62
     }
... ...
@@ -69,7 +67,7 @@ function get_contact($id)
69 67
 function get_contacts()
70 68
 {
71 69
     $cid = (int) $_SESSION['customerinfo']['customerno'];
72
-    $result = db_query("SELECT id, state, lastchange, nic_id, nic_handle, company, name, address, zip, city, country, phone, mobile, fax, email, pgp_id, pgp_key FROM kundendaten.contacts WHERE (state<>'deleted' OR state IS NULL) AND customer=? ORDER BY COALESCE(company, name)", array($cid));
70
+    $result = db_query("SELECT id, state, lastchange, nic_id, nic_handle, salutation, company, name, address, zip, city, country, phone, mobile, fax, email, pgp_id, pgp_key FROM kundendaten.contacts WHERE (state<>'deleted' OR state IS NULL) AND customer=? ORDER BY COALESCE(company, name)", array($cid));
73 71
     $ret = array();
74 72
     while ($contact = $result->fetch()) {
75 73
         $ret[$contact['id']] = $contact;
... ...
@@ -168,6 +166,7 @@ function sync_legacy_contactdata()
168 166
         $nachname = explode(' ', $kunde['name'], 2)[1];
169 167
     }
170 168
     $args = array("firma" => $kunde['company'],
169
+            "anrede" => $kunde['salutation'],
171 170
             "vorname" => $vorname,
172 171
             "nachname" => $nachname,
173 172
             "adresse" => $kunde['address'],
... ...
@@ -181,7 +180,7 @@ function sync_legacy_contactdata()
181 180
             "pgp_id" => $kunde['pgp_id'],
182 181
             "pgp_key" => $kunde['pgp_key'],
183 182
             "cid" => $cid);
184
-    db_query("UPDATE kundendaten.kunden SET firma=:firma, vorname=:vorname, nachname=:nachname, adresse=:adresse,
183
+    db_query("UPDATE kundendaten.kunden SET anrede=:anrede, firma=:firma, vorname=:vorname, nachname=:nachname, adresse=:adresse,
185 184
             plz=:plz, ort=:ort, land=:land, telefon=:telefon, mobile=:mobile, telefax=:telefax, email=:email, 
186 185
             pgp_id=:pgp_id, pgp_key=:pgp_key WHERE id=:cid", $args);
187 186
     if ($kundenkontakte['extern']) {
... ...
@@ -242,11 +241,11 @@ function save_contact($c)
242 241
     $c['customer'] = (int) $_SESSION['customerinfo']['customerno'];
243 242
     if ($c['id']) {
244 243
         // Kontakt bestaht schon, Update
245
-        db_query("UPDATE kundendaten.contacts SET nic_id=:nic_id, nic_handle=:nic_handle, company=:company, name=:name, address=:address, zip=:zip, city=:city, country=:country, phone=:phone, mobile=:mobile, fax=:fax, pgp_id=:pgp_id, pgp_key=:pgp_key WHERE id=:id AND customer=:customer", $c);
244
+        db_query("UPDATE kundendaten.contacts SET nic_id=:nic_id, nic_handle=:nic_handle, salutation=:salutation, company=:company, name=:name, address=:address, zip=:zip, city=:city, country=:country, phone=:phone, mobile=:mobile, fax=:fax, pgp_id=:pgp_id, pgp_key=:pgp_key WHERE id=:id AND customer=:customer", $c);
246 245
     } else {
247 246
         unset($c['id']);
248 247
         // Neu anlegen
249
-        db_query("INSERT INTO kundendaten.contacts (nic_id, nic_handle, customer, company, name, address, zip, city, country, phone, mobile, fax, pgp_id, pgp_key) VALUES (:nic_id, :nic_handle, :customer, :company, :name, :address, :zip, :city, :country, :phone, :mobile, :fax, :pgp_id, :pgp_key)", $c);
248
+        db_query("INSERT INTO kundendaten.contacts (nic_id, nic_handle, customer, salutation, company, name, address, zip, city, country, phone, mobile, fax, pgp_id, pgp_key) VALUES (:nic_id, :nic_handle, :customer, :salutation, :company, :name, :address, :zip, :city, :country, :phone, :mobile, :fax, :pgp_id, :pgp_key)", $c);
250 249
         $c['id'] = db_insert_id();
251 250
     }
252 251
     // FIXME: Das sollte eigentlich nicht bei jedem einzelnen Speicherovrgang passieren
... ...
@@ -86,6 +86,12 @@ if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete') {
86 86
         }
87 87
     }
88 88
 
89
+    $c['salutation'] = null;
90
+    if ($_REQUEST['salutation'] == 'Herr') {
91
+        $c['salutation'] = 'Herr';
92
+    } elseif ($_REQUEST['salutation'] == 'Frau') {
93
+        $c['salutation'] = 'Frau';
94
+    }
89 95
     $c['company'] = verify_input_general(maybe_null($_REQUEST['firma']));
90 96
     $c['name'] = verify_input_general(maybe_null($_REQUEST['name']));
91 97
     $c['address'] = verify_input_general(maybe_null($_REQUEST['adresse']));
92 98