Vorbereitung für edit/new
Bernd Wurst

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

... ...
@@ -0,0 +1,40 @@
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
+
20
+require_once('session/start.php');
21
+
22
+
23
+require_role(array(ROLE_CUSTOMER));
24
+
25
+$new = False;
26
+if ($_REQUEST['action'] == 'new') {
27
+    title("Adresse anlegen");
28
+    $new = True;
29
+} else {
30
+    title("Adresse bearbeiten");
31
+}
32
+
33
+$contact = new_contact();
34
+if (! $new) {
35
+    $contact = get_contact($_REQUEST['id']);
36
+}
37
+
38
+
39
+
40
+
... ...
@@ -30,9 +30,45 @@ function api_fetch_contact($nic_id)
30 30
 */
31 31
 
32 32
 
33
+function new_contact() {
34
+    return array("id" => NULL,
35
+        "state" => NULL,
36
+        "lastchange" => time(),
37
+        "nic_handle" => NULL,
38
+        "nic_id" => NULL,
39
+        "company" => NULL,
40
+        "name" => NULL,
41
+        "address" => NULL,
42
+        "zip" => NULL,
43
+        "city" => NULL,
44
+        "country" => "DE",
45
+        "phone" => NULL,
46
+        "mobile" => NULL,
47
+        "fax" => NULL,
48
+        "email" => NULL,
49
+        "pgp_id" => NULL,
50
+        "pgp_key" => NULL,
51
+        "customer" => $_SESSION['customerinfo']['customerno']);
52
+}
53
+
54
+
55
+function get_contact($id)
56
+{
57
+    $args = array(
58
+        "cid" => (int) $_SESSION['customerinfo']['customerno'],
59
+        "id" => (int) $id);
60
+    $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);
61
+    if ($result->rowCount() == 0) {
62
+        system_failure("Kontakt nicht gefunden oder gehört nicht diesem Kunden");
63
+    }
64
+    $res = $result->fetch()
65
+    $contact = $res[0];
66
+    return $contact;
67
+}
68
+
33 69
 function get_contacts() {
34 70
     $cid = (int) $_SESSION['customerinfo']['customerno'];
35
-    $result = db_query("SELECT id, state, lastchange, nic_handle, company, name, address, zip, city, country, phone, mobile, fax, email, pgp_id FROM kundendaten.contacts WHERE customer=? ORDER BY id", array($cid));
71
+    $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 customer=? ORDER BY id", array($cid));
36 72
     $ret = array();
37 73
     while ($contact = $result->fetch()) {
38 74
         $ret[$contact['id']] = $contact;
... ...
@@ -57,7 +57,7 @@ foreach ($contacts as $id => $contact) {
57 57
 }
58 58
 output('</table>');
59 59
 output("<br />");
60
-
60
+addnew('edit', 'Neuen Kontakt erstellen', 'action=new');
61 61
 
62 62
 
63 63
 ?>
64 64