Browse code

Setzen als Kundenkontakte ermöglicht

Bernd Wurst authored on20/01/2018 09:44:57
Showing4 changed files
1 1
new file mode 100644
2 2
Binary files /dev/null and b/images/attach.png differ
... ...
@@ -17,7 +17,7 @@ Nevertheless, in case you use a significant part of this code, we ask (but not r
17 17
 require_once('inc/debug.php');
18 18
 require_role(array(ROLE_CUSTOMER));
19 19
 
20
-require_once('api.php');
20
+require_once('contactapi.php');
21 21
 
22 22
 /*
23 23
 Todo:
... ...
@@ -112,6 +112,36 @@ function have_mailaddress($email)
112 112
 }
113 113
 
114 114
 
115
+function possible_kundenkontakt($c) {
116
+    if ($c['name'] && $c['email']) {
117
+        return true;
118
+    }
119
+}
120
+
121
+
122
+function set_kundenkontakt($typ, $id) {
123
+    if (! $id) {
124
+        $id = NULL;
125
+    } else {
126
+        $id = (int) $id;
127
+    }
128
+    $args = array(
129
+        "kunde" => (int) $_SESSION['customerinfo']['customerno'],
130
+        "contact" => $id
131
+        );
132
+    $field = NULL;
133
+    if ($typ == 'kunde') {
134
+        $field = 'contact_kunde';
135
+    } elseif ($typ == 'extern') {
136
+        $field = 'contact_extern';
137
+    } elseif ($typ == 'rechnung') {
138
+        $field = 'contact_rechnung';
139
+    } else {
140
+        system_failure("Falscher Typ!");
141
+    }
142
+    db_query("UPDATE kundendaten.kunden SET ".$field."=:contact WHERE id=:kunde", $args);
143
+}
144
+
115 145
 function get_kundenkontakte() {
116 146
     $cid = (int) $_SESSION['customerinfo']['customerno'];
117 147
     $result = db_query("SELECT contact_kunde, contact_extern, contact_rechnung FROM kundendaten.kunden WHERE id=?", array($cid));
... ...
@@ -63,12 +63,13 @@ foreach ($contacts as $id => $contact) {
63 63
     $actions[] = internal_link('edit', icon_edit('Adresse bearbeiten')." Bearbeiten", 'id='.$contact['id']);
64 64
     if ($id != $kundenkontakte['kunde'] && ! is_domainholder($id)) {
65 65
         // Die Stamm-Adresse kann man nicht löschen und verwendete Domain-Kontakte auch nicht
66
-        $actions[] = internal_link('save', icon_delete('Adresse löschen')." Löschen", 'action=delete&id='.$contact['id']);
66
+        $actions[] = internal_link('save', icon_delete()." Löschen", 'action=delete&id='.$contact['id']);
67 67
     }
68
-    $actions[] = internal_link('edit', other_icon('page_copy.png', 'Kopie erstellen')." Kopie erstellen", 'id=new&copy='.$contact['id']);
68
+    $actions[] = internal_link('edit', other_icon('page_copy.png')." Kopie erstellen", 'id=new&copy='.$contact['id']);
69
+    $actions[] = internal_link('useas', other_icon('attach.png')." Benutzen als...", 'id='.$contact['id']);
69 70
         
70 71
     $email = implode("<br>\n", array_filter(array($email, $contact['phone'], $contact['fax'], $contact['mobile'])));
71
-    output("<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><p class=\"contact-usage\">Verwendung als $usage</p><p class=\"contact-actions\">".implode(' ', $actions)."</p></div>");
72
+    output("<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><p class=\"contact-usage\">Verwendung als $usage</p><p class=\"contact-actions\">".implode("<br>\n", $actions)."</p></div>");
72 73
 }
73 74
 output("</div><br />");
74 75
 addnew('edit', 'Neuen Kontakt erstellen', 'id=new');
75 76
new file mode 100644
... ...
@@ -0,0 +1,108 @@
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('contacts.php');
18
+require_once('inc/debug.php');
19
+require_once('inc/icons.php');
20
+require_once('inc/jquery.php');
21
+#javascript();
22
+
23
+require_once('session/start.php');
24
+
25
+
26
+require_role(array(ROLE_CUSTOMER));
27
+$section = 'contacts_list';
28
+
29
+title("Adresse verwenden als...");
30
+
31
+
32
+output(internal_link('list', 'Zurück zur Übersicht'));
33
+
34
+$contact = get_contact($_REQUEST['id']);
35
+$kundenkontakte = get_kundenkontakte();
36
+$id = $contact['id'];
37
+
38
+
39
+if (isset($_REQUEST['useas'])) {
40
+    if ($_REQUEST['useas'] == 'kunde') {
41
+        if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete') {
42
+            system_failure("Man kann eine Kunden-Adresse nicht löschen, bitte eine neue als Ersatz festlegen!");
43
+        } else {
44
+            set_kundenkontakt('kunde', $id);
45
+            redirect('useas?id='.$id);
46
+        }
47
+    }
48
+    if ($_REQUEST['useas'] == 'extern') {
49
+        if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete') {
50
+            set_kundenkontakt('extern', NULL);
51
+            redirect('useas?id='.$id);
52
+        } else {
53
+            set_kundenkontakt('extern', $id);
54
+            redirect('useas?id='.$id);
55
+        }
56
+    }
57
+    if ($_REQUEST['useas'] == 'rechnung') {
58
+        if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete') {
59
+            set_kundenkontakt('rechnung', NULL);
60
+            redirect('useas?id='.$id);
61
+        } else {
62
+            set_kundenkontakt('rechnung', $id);
63
+            redirect('useas?id='.$id);
64
+        }
65
+    }
66
+} else {
67
+    $adresse = nl2br("\n".$contact['address']."\n".$contact['country'].'-'.$contact['zip'].' '.$contact['city']);
68
+    if (! $contact['city']) {
69
+        $adresse = '';
70
+    }
71
+    $name = $contact['name'];
72
+    if ($contact['company']) {
73
+        $name = $contact['company']."<br />".$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);
80
+
81
+    output('<h4>Verwendung als Kundenkontakt</h4>');
82
+    if ($id == $kundenkontakte['kunde']) {
83
+        output("<p>Diese Adresse ist die Stamm-Adresse!</p>");
84
+    } else {
85
+        if (possible_kundenkontakt($contact)) {
86
+            addnew('useas', 'Diese Adresse als Haupt-Adresse des Kontoinhabers festlegen.', 'id='.$_REQUEST['id'].'&useas=kunde');
87
+        }
88
+        if ($id == $kundenkontakte['extern']) {
89
+            output("<p>Diese Adresse ist die Ersatz-Adresse bei Störungen! ".icon_delete().internal_link('useas', "Zuordnung löschen", 'id='.$_REQUEST['id'].'&useas=extern&action=delete')."</p>");
90
+        } else {
91
+            addnew('useas', 'Diese Adresse als Ersatz-Adresse des Kontoinhabers für Störungen festlegen.', 'id='.$_REQUEST['id'].'&useas=extern');
92
+        }
93
+        if ($id == $kundenkontakte['rechnung']) {
94
+            output("<p>Diese Adresse ist die Rechnungs-Adresse. ".icon_delete().internal_link('useas', "Zuordnung löschen", 'id='.$_REQUEST['id'].'&useas=rechnung&action=delete')."</p>");
95
+        } else {
96
+            addnew('useas', 'Diese Adresse als Rechnungs-Adresse festlegen.', 'id='.$_REQUEST['id'].'&useas=rechnung');
97
+        }
98
+    }
99
+
100
+
101
+    if (possible_domainholder($contact)) {
102
+        output("<h4>Verwendung als Domaininhaber bzw. -Verwalter</h4>");
103
+
104
+        output("<p>Kann als Domaininhaber verwendet werden!</p>");
105
+    }
106
+
107
+
108
+}