Ein paar neue Klassen
bernd

bernd commited on 2007-07-05 18:22:41
Zeige 2 geänderte Dateien mit 173 Einfügungen und 0 Löschungen.


git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@535 87cf0b9e-d624-0410-a070-f6ee81989793
... ...
@@ -0,0 +1,98 @@
1
+<?php
2
+
3
+require_once('inc/db_connect.php');
4
+require_once('inc/base.php');
5
+require_once('inc/debug.php');
6
+
7
+require_once('class/keksdata.php');
8
+
9
+
10
+class Domain extends KeksData
11
+{
12
+  function __construct($init = NULL)
13
+  {
14
+    $this->default_table = 'kundendaten.domains';
15
+    $this->setup();
16
+    switch (gettype($init))
17
+    {
18
+      case 'string':
19
+        $this->loadByName($init);
20
+        break;
21
+      case 'integer':
22
+        $this->loadByID($init);
23
+        break;
24
+      case 'NULL':
25
+        break;
26
+    }
27
+  }
28
+
29
+  function loadByName($name)
30
+  {
31
+    $name = mysql_real_escape_string($name);
32
+    $res = $this->getData("*", "CONCAT_WS('.', domainname, tld)='{$name}' LIMIT 1");
33
+    $this->parse($res[0]);
34
+  }
35
+
36
+  function parse($data)
37
+  {
38
+    foreach (array_keys($this->data) as $key)
39
+      if (array_key_exists($key, $data))
40
+        $this->data[$key] = $data[$key];
41
+    $this->data['fqdn'] = $data['domainname'].'.'.$data['tld'];
42
+    $this->data['reg_date'] = $data['registrierungsdatum'];
43
+    $this->data['cancel_date'] = $data['kuendigungsdatum'];
44
+  }
45
+
46
+}
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+function get_domain_list($customerno, $uid = NULL)
55
+{
56
+  $customerno = (int) $customerno;
57
+  $query = "SELECT id FROM kundendaten.domains WHERE";
58
+  if ($uid !== NULL)
59
+  {
60
+    $uid = (int) $uid;
61
+    $query .= " useraccount={$uid};";
62
+  }
63
+  else
64
+  {
65
+    $query .= " kunde={$customerno};";
66
+  }
67
+  $result = db_query($query);
68
+  $domains = array();
69
+  DEBUG('Result set is '.mysql_num_rows($result)." rows.<br />\n");
70
+  if (mysql_num_rows($result) > 0)
71
+    while ($domain = mysql_fetch_object($result)->id)
72
+      array_push($domains, new Domain((int) $domain));
73
+  DEBUG($domains);
74
+	return $domains;	
75
+}
76
+
77
+
78
+
79
+function get_jabberable_domains()
80
+{
81
+  require_role(ROLE_CUSTOMER);
82
+  $customerno = (int) $_SESSION['customerinfo']['customerno'];
83
+
84
+  $domains = get_domain_list($customerno);
85
+  DEBUG($domains);
86
+  $result = array( new Domain() );
87
+  $result[0]->id = 0;
88
+  $result[0]->fqdn = "schokokeks.org";
89
+  foreach ($domains as $dom)
90
+  {
91
+    if ($dom->jabber)
92
+      $result[] = $dom;
93
+  }
94
+  return $result;
95
+
96
+}
97
+
98
+?>
... ...
@@ -0,0 +1,75 @@
1
+<?php
2
+
3
+require_once('inc/db_connect.php');
4
+require_once('inc/base.php');
5
+require_once('inc/debug.php');
6
+
7
+
8
+abstract class KeksData
9
+{
10
+  protected $default_table;
11
+  
12
+  protected $data = array();
13
+
14
+  function __get($key)
15
+  {
16
+    if (array_key_exists($key, $this->data))
17
+      return $this->data[$key];
18
+    elseif (isset($this->$key))
19
+      return $this->$key;
20
+    // else werfe fehler
21
+  }
22
+
23
+  function __set($key, $value)
24
+  {
25
+    if (array_key_exists($key, $this->data))
26
+      $this->data[$key] = $value;
27
+    elseif (isset($this->$key))
28
+      $this->$key = $value;
29
+    else
30
+      $this->data[$key] = $value;
31
+  }
32
+
33
+  protected function setup()
34
+  {
35
+    $fields = array();
36
+    $res = db_query("DESCRIBE {$this->default_table}");
37
+    while ($f = mysql_fetch_object($res))
38
+    {
39
+      $fields[$f->Field] = $f->Default;
40
+    }
41
+    $this->data = $fields;
42
+  }
43
+
44
+
45
+  function getData($fields, $restriction = NULL, $table = NULL)
46
+  {
47
+    $where = '';
48
+    if ($restriction)
49
+      $where = 'WHERE '.$restriction;
50
+    if (! $table)
51
+      $table = $this->default_table;
52
+    if (is_array($fields))
53
+      $fields = implode(',', $fields);
54
+    
55
+    $res = db_query("SELECT {$fields} FROM {$table} {$where}");
56
+    $return = array();
57
+    while ($arr = mysql_fetch_assoc($res))
58
+      array_push($return, $arr);
59
+    return $return;
60
+  }
61
+
62
+
63
+  function loadByID($id)
64
+  {
65
+    $id = (int) $id;
66
+    $res = $this->getData('*', "id={$id} LIMIT 1");
67
+    $this->parse($res[0]);
68
+  }
69
+
70
+
71
+  abstract function parse($data);
72
+
73
+}
74
+
75
+?>
0 76