Abstrahieren der Anzeigefunktion, Style-Änderungen, Verweigere das Löschen des Namens aus dem Kundenkontakt
Bernd Wurst

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

... ...
@@ -22,7 +22,8 @@ require_once('contactapi.php');
22 22
 
23 23
 /*
24 24
 Todo:
25
-    - "separate Rechnungsadresse einrichten" / "Zusätzliche Adresse für den Notfall"
25
+    - Ausgabe-Funktion abstrahieren
26
+    - Telefonnummern bei Ausgabe durch filter_input_general schieben
26 27
     - Domaininhaber festlegen    
27 28
 */
28 29
 
... ...
@@ -253,3 +254,27 @@ function domainlist_by_contact($c) {
253 254
 }
254 255
 
255 256
 
257
+function display_contact($contact, $additional_html='', $cssclass='')
258
+{
259
+    $adresse = nl2br("\n".filter_input_general($contact['address'])."\n".filter_input_general($contact['country']).'-'.filter_input_general($contact['zip']).' '.filter_input_general($contact['city']));
260
+    if (! $contact['city']) {
261
+        $adresse = '';
262
+    }
263
+    $name = filter_input_general($contact['name']);
264
+    if ($contact['company']) {
265
+        $name = filter_input_general($contact['company'])."<br />".filter_input_general($contact['name']);
266
+    }
267
+    $email = filter_input_general($contact['email']);
268
+    $new_email = update_pending($contact['id']);
269
+    if ($new_email) {
270
+        $email = "<strike>$email</strike><br/>".filter_input_general($new_email).footnote('Die E-Mail-Adresse wurde noch nicht bestätigt');
271
+    }
272
+    $email = implode("<br>\n", array_filter(array($email, filter_input_general($contact['phone']), filter_input_general($contact['fax']), filter_input_general($contact['mobile']))));
273
+ 
274
+
275
+    $contact_string = "<div class=\"contact {$cssclass}\" id=\"contact-{$contact['id']}\"><p class=\"contact-id\">#{$contact['id']}</p><p class=\"contact-address\"><strong>$name</strong>$adresse</p><p class=\"contact-contact\">$email</p>{$additional_html}</div>";
276
+    return $contact_string;
277
+}
278
+
279
+
280
+
... ...
@@ -40,10 +40,6 @@ foreach ($liste as $id) {
40 40
     }
41 41
     $cssclass = '';
42 42
     $contact = $contacts[$id];
43
-    $adresse = nl2br("\n".filter_input_general($contact['address'])."\n".filter_input_general($contact['country']).'-'.filter_input_general($contact['zip']).' '.filter_input_general($contact['city']));
44
-    if (! $contact['city']) {
45
-        $adresse = '';
46
-    }
47 43
     $usage = array();
48 44
     if ($id == $kundenkontakte['kunde']) {
49 45
         $cssclass='mainaddress';
... ...
@@ -56,18 +52,13 @@ foreach ($liste as $id) {
56 52
     if ($id == $kundenkontakte['rechnung'] || ($id == $kundenkontakte['kunde'] && $kundenkontakte['rechnung'] == NULL)) {
57 53
         $usage[] = 'Rechnungs-Adresse';
58 54
     }
59
-    if ($contact['nic_handle']) {
55
+    if (is_domainholder($id)) {
60 56
         $usage[] = 'Domain-Kontakt';
61 57
     }
62
-    $usage = join(', ', $usage);
63
-    $name = $contact['name'];
64
-    if (nl2br(filter_input_general($contact['company']))) {
65
-        $name = filter_input_general($contact['company'])."<br />".nl2br(filter_input_general($contact['name']));
66
-    }
67
-    $email = $contact['email'];
68
-    $new_email = update_pending($id);
69
-    if ($new_email) {
70
-        $email = "<strike>$email</strike><br/>".$new_email.footnote('Die E-Mail-Adresse wurde noch nicht bestätigt');
58
+    if ($usage) {
59
+        $usage = "Verwendet als ".join(', ', $usage);
60
+    } else {
61
+        $usage = "Zur Zeit unbenutzt";
71 62
     }
72 63
     $actions = array();
73 64
     $actions[] = internal_link('edit', icon_edit('Adresse bearbeiten')." Bearbeiten", 'id='.$contact['id']);
... ...
@@ -78,8 +69,7 @@ foreach ($liste as $id) {
78 69
     $actions[] = internal_link('edit', other_icon('page_copy.png')." Kopie erstellen", 'id=new&copy='.$contact['id']);
79 70
     $actions[] = internal_link('useas', other_icon('attach.png')." Benutzen als...", 'id='.$contact['id']);
80 71
     
81
-    $email = implode("<br>\n", array_filter(array($email, $contact['phone'], $contact['fax'], $contact['mobile'])));
82
-    output("<div class=\"contact {$cssclass}\" id=\"contact-{$contact['id']}\"><p class=\"contact-id\">#{$contact['id']}</p><p class=\"contact-address\"><strong>$name</strong>$adresse</p><p class=\"contact-contact\">$email</p><p class=\"contact-usage\">Verwendung als $usage</p><p class=\"contact-actions\">".implode("<br>\n", $actions)."</p></div>");
72
+    output(display_contact($contact, "<p class=\"contact-usage\">$usage</p><p class=\"contact-actions\">".implode("<br>\n", $actions)."</p>", $cssclass));
83 73
 }
84 74
 output("</div><br />");
85 75
 addnew('edit', 'Neue Adresse erstellen', 'id=new');
... ...
@@ -27,18 +27,7 @@ $section = 'contacts_list';
27 27
 if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete') {
28 28
     $contact = get_contact($_REQUEST['id']);
29 29
     
30
-    $adresse = nl2br("\n".filter_input_general($contact['address'])."\n".filter_input_general($contact['country']).'-'.filter_input_general($contact['zip']).' '.filter_input_general($contact['city']));
31
-    if (! $contact['city']) {
32
-        $adresse = '';
33
-    }
34
-    $name = filter_input_general($contact['name']);
35
-    if ($contact['company']) {
36
-        $name = filter_input_general($contact['company'])."<br />".filter_input_general($contact['name']);
37
-    }
38
-    $email = implode("<br>\n", array_filter(array($contact['email'], $contact['phone'], $contact['fax'], $contact['mobile'])));
39
- 
40
-    $contact_string = "<div class=\"contact\" id=\"contact-{$contact['id']}\"><p class=\"contact-id\">#{$contact['id']}</p><p class=\"contact-address\"><strong>$name</strong>$adresse</p><p class=\"contact-contact\">$email</p></div>";
41
-    
30
+    $contact_string = display_contact($contact);
42 31
 
43 32
     $sure = user_is_sure();
44 33
     if ($sure === NULL)
... ...
@@ -90,6 +79,12 @@ if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete') {
90 79
         }
91 80
     }
92 81
 
82
+    $kundenkontakte = get_kundenkontakte();
83
+    if ($c['id'] == $kundenkontakte['kunde']) {
84
+        if (!$_REQUEST['name'] && !$_REQUEST['firma']) {
85
+            system_failure('Beim Inhaber darf nicht Firmenname und Name leer sein.');
86
+        }
87
+    }
93 88
 
94 89
     $c['company'] = verify_input_general(maybe_null($_REQUEST['firma']));
95 90
     $c['name'] = verify_input_general(maybe_null($_REQUEST['name']));
... ...
@@ -47,5 +47,9 @@ p.contact-id {
47 47
     padding: 0;
48 48
 }
49 49
 
50
+p.contact-usage {
51
+    font-style: italic;
52
+}
53
+
50 54
 p.contact-actions {
51 55
 }
... ...
@@ -42,7 +42,9 @@ if (isset($_REQUEST['useas'])) {
42 42
             system_failure("Man kann eine Kunden-Adresse nicht löschen, bitte eine neue als Ersatz festlegen!");
43 43
         } else {
44 44
             set_kundenkontakt('kunde', $id);
45
-            redirect('useas?id='.$id);
45
+            //redirect('useas?id='.$id);
46
+            // usability: Dann kann man da eh nichts mehr machen, also zurück zur Übersicht
47
+            redirect('list');
46 48
         }
47 49
     }
48 50
     if ($_REQUEST['useas'] == 'extern') {
... ...
@@ -64,19 +66,7 @@ if (isset($_REQUEST['useas'])) {
64 66
         }
65 67
     }
66 68
 } else {
67
-    $adresse = nl2br("\n".filter_input_general($contact['address'])."\n".filter_input_general($contact['country']).'-'.filter_input_general($contact['zip']).' '.filter_input_general($contact['city']));
68
-    if (! $contact['city']) {
69
-        $adresse = '';
70
-    }
71
-    $name = filter_input_general($contact['name']);
72
-    if ($contact['company']) {
73
-        $name = filter_input_general($contact['company'])."<br />".filter_input_general($contact['name']);
74
-    }
75
-    $email = implode("<br>\n", array_filter(array($contact['email'], $contact['phone'], $contact['fax'], $contact['mobile'])));
76
-
77
-    $contact_string = "<div class=\"contact\" id=\"contact-{$contact['id']}\"><p class=\"contact-id\">#{$contact['id']}</p><p class=\"contact-address\"><strong>$name</strong>$adresse</p><p class=\"contact-contact\">$email</p></div>";
78
-
79
-    output($contact_string);
69
+    output(display_contact($contact));
80 70
 
81 71
     output('<h4>Verwendung als Kundenkontakt</h4>');
82 72
     if ($id == $kundenkontakte['kunde']) {
83 73