Browse code

Alte Klassen entfernt

Bernd Wurst authored on23/01/2018 14:01:15
Showing9 changed files
1 1
deleted file mode 100644
... ...
@@ -1,47 +0,0 @@
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('inc/base.php');
18
-require_once('inc/debug.php');
19
-
20
-require_once('class/keksdata.php');
21
-
22
-
23
-class Customer extends KeksData
24
-{
25
-  function __construct($init = NULL)
26
-  {
27
-    $this->default_table = 'kundendaten.kunden';
28
-    $this->setup();
29
-    if ($init != NULL)
30
-      $this->loadByID( (int) $init);
31
-  }
32
-
33
-  function parse($data)
34
-  {
35
-    foreach (array_keys($this->data) as $key)
36
-      if (array_key_exists($key, $data))
37
-        $this->data[$key] = $data[$key];
38
-    $this->data['fullname'] = $data['vorname'].' '.$data['nachname'];
39
-    if ($this->data['fullname'] == ' ')
40
-      $this->data['fullname'] = $data['firma'];
41
-    if (! $this->data['email_rechnung'])
42
-      $this->data['email_rechnung'] = $this->data['email'];
43
-  }
44
-
45
-}
46
-
47
-
... ...
@@ -17,14 +17,12 @@ Nevertheless, in case you use a significant part of this code, we ask (but not r
17 17
 require_once('inc/base.php');
18 18
 require_once('inc/debug.php');
19 19
 
20
-require_once('class/keksdata.php');
21 20
 
22
-
23
-class Domain extends KeksData
21
+class Domain
24 22
 {
23
+    protected $data = array();
25 24
   function __construct($init = NULL)
26 25
   {
27
-    $this->default_table = 'kundendaten.domains';
28 26
     $this->setup();
29 27
     switch (gettype($init))
30 28
     {
... ...
@@ -39,13 +37,44 @@ class Domain extends KeksData
39 37
     }
40 38
   }
41 39
 
42
-  function loadByName($name)
40
+  function __set($key, $value)
43 41
   {
44
-    $name = db_escape_string($name);
45
-    $res = $this->getData("*", "CONCAT_WS('.', domainname, tld)='{$name}' LIMIT 1");
46
-    if (count($res) < 1)
47
-      return false;
48
-    $this->parse($res[0]);
42
+    if (array_key_exists($key, $this->data)) {
43
+      $this->data[$key] = $value;
44
+    } elseif (isset($this->$key)) {
45
+      $this->$key = $value;
46
+    } else {
47
+      $this->data[$key] = $value;
48
+    }
49
+  }
50
+
51
+
52
+  function __get($key)
53
+  {
54
+    if (array_key_exists($key, $this->data))
55
+      return $this->data[$key];
56
+    elseif (isset($this->$key))
57
+      return $this->$key;
58
+    // else werfe fehler
59
+  }
60
+
61
+
62
+  function loadByID($id)
63
+  {
64
+      $res = db_query("SELECT * FROM kundendaten.domains WHERE id=?", array($id));
65
+      if ($res->rowCount() < 1)
66
+         return false;
67
+      $data = $res->fetch();
68
+      $this->parse($data);
69
+  }
70
+
71
+   function loadByName($name)
72
+  {
73
+      $res = db_query("SELECT * FROM kundendaten.domains WHERE CONCAT_WS('.', domainname, tld)=?", array($name));
74
+      if ($res->rowCount() < 1)
75
+         return false;
76
+      $data = $res->fetch();
77
+      $this->parse($data);
49 78
   }
50 79
 
51 80
   function ensure_customerdomain()
... ...
@@ -76,6 +105,20 @@ class Domain extends KeksData
76 105
     return ($this->useraccount == $uid);
77 106
   }
78 107
 
108
+  function setup()
109
+  {
110
+    $fields = array();
111
+    $res = db_query("DESCRIBE kundendaten.domains");
112
+    while ($f = $res->fetch(PDO::FETCH_OBJ))
113
+    {
114
+      $fields[$f->Field] = $f->Default;
115
+    }
116
+    $this->data = $fields;
117
+    $this->data['id'] = NULL;
118
+  }
119
+
120
+
121
+
79 122
   function parse($data)
80 123
   {
81 124
     DEBUG($data);
... ...
@@ -142,4 +185,3 @@ function get_jabberable_domains()
142 185
 
143 186
 }
144 187
 
145
-?>
146 188
deleted file mode 100644
... ...
@@ -1,114 +0,0 @@
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('inc/base.php');
18
-require_once('inc/debug.php');
19
-
20
-
21
-abstract class KeksData
22
-{
23
-  protected $default_table;
24
-  
25
-  protected $raw_data = array();
26
-  protected $data = array();
27
-  protected $changes = array();
28
-
29
-  function __get($key)
30
-  {
31
-    if (array_key_exists($key, $this->data))
32
-      return $this->data[$key];
33
-    elseif (isset($this->$key))
34
-      return $this->$key;
35
-    // else werfe fehler
36
-  }
37
-
38
-  function __set($key, $value)
39
-  {
40
-    if (array_key_exists($key, $this->raw_data))
41
-    {
42
-      $this->raw_data[$key] = $value;
43
-      $this->changes[$key] = $value;
44
-      $this->parse($this->raw_data);
45
-    }
46
-    elseif (array_key_exists($key, $this->data))
47
-      $this->data[$key] = $value;
48
-      // return false;
49
-    elseif (isset($this->$key))
50
-      $this->$key = $value;
51
-    else
52
-      $this->data[$key] = $value;
53
-  }
54
-
55
-  protected function setup()
56
-  {
57
-    $fields = array();
58
-    $res = db_query("DESCRIBE {$this->default_table}");
59
-    while ($f = $res->fetch(PDO::FETCH_OBJ))
60
-    {
61
-      $fields[$f->Field] = $f->Default;
62
-    }
63
-    $this->raw_data = $fields;
64
-    $this->raw_data['id'] = NULL;
65
-    $this->data = $fields;
66
-    $this->data['id'] = NULL;
67
-  }
68
-
69
-
70
-  function getData($fields, $restriction = NULL, $table = NULL)
71
-  {
72
-    $where = '';
73
-    if ($restriction)
74
-      $where = 'WHERE '.$restriction;
75
-    if (! $table)
76
-      $table = $this->default_table;
77
-    if (is_array($fields))
78
-      $fields = implode(',', $fields);
79
-    
80
-    $res = db_query("SELECT {$fields} FROM {$table} {$where}", array()); // FIXME Übergebe leeren array um die Warnung zu unterdrücken
81
-    $return = array();
82
-    while ($arr = $res->fetch())
83
-      array_push($return, $arr);
84
-    return $return;
85
-  }
86
-
87
-
88
-  function loadByID($id)
89
-  {
90
-    $id = (int) $id;
91
-    DEBUG("requested to load ID »{$id}«");
92
-    $res = $this->getData('*', "id={$id} LIMIT 1");
93
-    if (count($res) < 1)
94
-      return false;
95
-    $this->parse($res[0]);
96
-  }
97
-
98
-
99
-  function save()
100
-  {
101
-    $upd = array();
102
-    foreach ($this->changes as $key => $value)
103
-    {
104
-      $value = db_escape_string($value);
105
-      array_push($upd, "`{$key}`='{$value}'");
106
-    }
107
-    db_query("UPDATE {$this->default_table} SET ".implode(', ', $upd)." WHERE id=?", array($this->data['id']));
108
-  }
109
-
110
-  abstract function parse($data);
111
-
112
-}
113
-
114
-?>
115 0
deleted file mode 100644
... ...
@@ -1,38 +0,0 @@
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('inc/base.php');
18
-require_once('inc/debug.php');
19
-
20
-require_once('session/start.php');
21
-require_once('crm.php');
22
-
23
-require_once('class/customer.php');
24
-
25
-require_role(ROLE_SYSADMIN);
26
-
27
-$ajax_formtoken = generate_form_token('crm_crm_ajax');
28
-
29
-$result = array_unique(find_customers($_GET['q']));
30
-sort($result);
31
-foreach ($result as $val) {
32
-  $c = new Customer((int) $val);
33
-  echo '<p style="margin-bottom: 0.5em;">'.internal_link('select_customer', 'Kunde '.$c->id.': <strong>'.$c->fullname.'</strong>', 'customer='.$c->id.'&formtoken='.$ajax_formtoken);
34
-  echo '</p>';
35
-}
36
-die();
37
-
38
-
39 0
deleted file mode 100644
... ...
@@ -1,69 +0,0 @@
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('inc/base.php');
18
-
19
-
20
-function find_customers($string) 
21
-{
22
-  $string = db_escape_string(chop($string));
23
-  $return = array();
24
-  $result = db_query("SELECT k.id FROM kundendaten.kunden AS k LEFT JOIN kundendaten.kundenkontakt AS kk ".
25
-                     "ON (kk.kundennr = k.id) LEFT JOIN system.useraccounts AS u ON (k.id=u.kunde) WHERE ".
26
-                     "firma LIKE '%{$string}%' OR firma2 LIKE '%{$string}%' OR ".
27
-                     "nachname LIKE '%{$string}%' OR vorname LIKE '%{$string}%' OR ".
28
-                     "adresse LIKE '%{$string}%' OR adresse2 LIKE '%{$string}%' OR ".
29
-                     "ort LIKE '%{$string}%' OR pgp_id LIKE '%{$string}%' OR ".
30
-                     "notizen LIKE '%{$string}%' OR kk.name LIKE '%{$string}%' OR ".
31
-                     "kk.wert LIKE '%{$string}%' OR u.name LIKE '%{$string}%' OR ".
32
-                     "u.username LIKE '%{$string}%' OR k.id='{$string}' OR u.uid='{$string}';");
33
-  while ($entry = $result->fetch())
34
-    $return[] = $entry['id'];
35
-
36
-  return $return;
37
-}
38
-
39
-
40
-function find_users_for_customer($id)
41
-{
42
-  $id = (int) $id;
43
-  $return = array();
44
-  $result = db_query("SELECT uid, username FROM system.useraccounts WHERE ".
45
-                     "kunde='{$id}';");
46
-  while ($entry = $result->fetch())
47
-    $return[$entry['uid']] = $entry['username'];
48
-
49
-  return $return;
50
-}
51
-
52
-
53
-
54
-function hosting_contracts($cid)
55
-{
56
-  $cid = (int) $cid;
57
-  $result = db_query("SELECT u.username, werber, beschreibung, betrag, brutto, monate, anzahl, startdatum, startdatum + INTERVAL laufzeit MONTH - INTERVAL 1 DAY AS mindestlaufzeit, kuendigungsdatum, gesperrt, notizen FROM kundendaten.hosting AS h LEFT JOIN system.useraccounts AS u ON (h.hauptuser=u.uid) WHERE h.kunde=".$cid);
58
-  $ret = array();
59
-  while ($x = $result->fetch())
60
-    array_push($ret, $x);
61
-  DEBUG($ret);
62
-
63
-}
64
-
65
-
66
-
67
-
68
-
69
-
70 0
deleted file mode 100644
... ...
@@ -1,98 +0,0 @@
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('inc/base.php');
18
-require_once('inc/debug.php');
19
-
20
-require_once('class/customer.php');
21
-
22
-require_once('session/start.php');
23
-require_once('crm.php');
24
-
25
-require_role(ROLE_SYSADMIN);
26
-
27
-
28
-$debug = '';
29
-if ($debugmode)
30
-  $debug = 'debug&amp;';
31
-
32
-html_header('<script type="text/javascript" src="'.$prefix.'js/ajax.js" ></script>
33
-<script type="text/javascript">
34
-<!--
35
-
36
-function doRequest() {
37
-  ajax_request(\'crm_ajax\', \''.$debug.'q=\'+document.getElementById(\'query\').value, got_response)
38
-}
39
-
40
-function keyPressed() {
41
-  if(window.mytimeout) window.clearTimeout(window.mytimeout);
42
-  window.mytimeout = window.setTimeout(doRequest, 500);
43
-  return true;
44
-}
45
-
46
-function got_response() {
47
-  if (xmlHttp.readyState == 4) {
48
-    document.getElementById(\'response\').innerHTML = xmlHttp.responseText;
49
-  }
50
-}
51
-
52
-// -->
53
-</script>
54
-');
55
-
56
-
57
-title('Customer Relationship Management');
58
-
59
-
60
-
61
-output(html_form('crm_main', '', '', 'Kunde nach Stichwort suchen: <input type="text" id="query" onkeyup="keyPressed()" />
62
-'));
63
-output('<div id="response"></div>');
64
-
65
-if (isset($_SESSION['crm_customer'])) {
66
-  $cid = $_SESSION['crm_customer'];
67
-  $cust = new Customer($cid);
68
-
69
-  $hostingcont = hosting_contracts($cust->id);
70
-  $hosting = '<ul>';
71
-  foreach ($hostingcont AS $h) {
72
-    $hosting .= '<li>Hosting: ';
73
-  }
74
-  $hosting .= '</ul>';
75
-
76
-  output('<h3>Aktueller Kunde</h3>
77
-<div><strong>'.$cust->fullname.'</strong><br />
78
-Firma: '.$cust->firma.'<br />
79
-Name: '.$cust->vorname.' '.$cust->nachname.'<br />
80
-Adresse: '.$cust->adresse.' - '.$cust->plz.' '.$cust->ort.'</div>
81
-
82
-
83
-<h3>Kundendaten</h3>
84
-
85
-
86
-<h4>Letzte Rechnungen</h4>
87
-
88
-
89
-<h4>Kommende Rechnungsposten</h4>
90
-
91
-');
92
-   
93
-  output ( print_r($cust, true) );
94
-}
95
-
96
-
97
-
98
-
99 0
deleted file mode 100644
... ...
@@ -1,24 +0,0 @@
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
-$role = $_SESSION['role'];
18
-
19
-if ($role & ROLE_SYSADMIN)
20
-{
21
-  $menu["crm_main"] = array("label" => "CRM", "file" => "main", "weight" => -9);
22
-}
23
-
24
-?>
25 0
deleted file mode 100644
... ...
@@ -14,9 +14,6 @@ http://creativecommons.org/publicdomain/zero/1.0/
14 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 15
 */
16 16
 
17
-require_once('inc/base.php');
18
-require_once('class/customer.php');
19
-
20 17
 function list_system_users()
21 18
 {
22 19
   require_role(ROLE_SYSADMIN);
... ...
@@ -42,6 +39,17 @@ function list_customers()
42 39
   return $ret;
43 40
 }
44 41
 
42
+function customer_details($id) 
43
+{
44
+    $id = (int) $id; 
45
+    $result = db_query("SELECT id, IF(firma IS NULL, CONCAT_WS(' ', vorname, nachname), CONCAT(firma, ' (', CONCAT_WS(' ', vorname, nachname), ')')) AS name FROM kundendaten.kunden WHERE id=?", array($id));
46
+    if ($result->rowCount() < 1) {
47
+        return NULL;
48
+    }
49
+    $kunde = $result->fetch();
50
+    return $kunde;
51
+}
52
+
45 53
 
46 54
 function find_customers($string) 
47 55
 {
... ...
@@ -102,15 +110,15 @@ function build_results($term) {
102 110
   $result = array_unique(find_customers($term));
103 111
   sort($result);
104 112
   foreach ($result as $val) {
105
-    $c = new Customer((int) $val);
106
-    if ($c->id == $term) {
107
-      $add(10, "c{$c->id}", "Kunde {$c->id}: {$c->fullname}");
113
+    $c = customer_details($val);
114
+    if ($c['id'] == $term) {
115
+      $add(10, "c{$c['id']}", "Kunde {$c['id']}: {$c['name']}");
108 116
     } else {
109
-      $add(90, "c{$c->id}", "Kunde {$c->id}: {$c->fullname}");
117
+      $add(90, "c{$c['id']}", "Kunde {$c['id']}: {$c['name']}");
110 118
     }
111
-    $users = find_users_for_customer($c->id);
119
+    $users = find_users_for_customer($c['id']);
112 120
     foreach ($users as $u) {
113
-      $realname = $c->fullname;
121
+      $realname = $c['name'];
114 122
       if ($u['name']) {
115 123
         $realname = $u['name'];
116 124
       }