Domain-Klasse benutzen
bernd

bernd commited on 2007-07-05 18:43:18
Zeige 11 geänderte Dateien mit 43 Einfügungen und 109 Löschungen.


git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@536 87cf0b9e-d624-0410-a070-f6ee81989793
... ...
@@ -30,6 +30,8 @@ class Domain extends KeksData
30 30
   {
31 31
     $name = mysql_real_escape_string($name);
32 32
     $res = $this->getData("*", "CONCAT_WS('.', domainname, tld)='{$name}' LIMIT 1");
33
+    if (count($res) < 1)
34
+      return false;
33 35
     $this->parse($res[0]);
34 36
   }
35 37
 
... ...
@@ -39,6 +39,7 @@ abstract class KeksData
39 39
       $fields[$f->Field] = $f->Default;
40 40
     }
41 41
     $this->data = $fields;
42
+    $this->data['id'] = NULL;
42 43
   }
43 44
 
44 45
 
... ...
@@ -64,6 +65,8 @@ abstract class KeksData
64 65
   {
65 66
     $id = (int) $id;
66 67
     $res = $this->getData('*', "id={$id} LIMIT 1");
68
+    if (count($res) < 1)
69
+      return false;
67 70
     $this->parse($res[0]);
68 71
   }
69 72
 
... ...
@@ -4,18 +4,18 @@ require_once('inc/debug.php');
4 4
 
5 5
 require_once('session/start.php');
6 6
 
7
-require_once('domains.php');
7
+require_once('class/domain.php');
8 8
 
9 9
 require_role(array(ROLE_SYSTEMUSER, ROLE_CUSTOMER));
10 10
 
11 11
 switch ($_SESSION['role'])
12 12
 {
13 13
   case ROLE_SYSTEMUSER:
14
-    $user_domains = get_domain_names($_SESSION['userinfo']['customerno'], $_SESSION['userinfo']['uid']);
14
+    $user_domains = get_domain_list($_SESSION['userinfo']['customerno'], $_SESSION['userinfo']['uid']);
15 15
     $info = 'userinfo';
16 16
     break;
17 17
   case ROLE_CUSTOMER:
18
-    $user_domains = get_domain_names($_SESSION['customerinfo']['customerno']);
18
+    $user_domains = get_domain_list($_SESSION['customerinfo']['customerno']);
19 19
     break;
20 20
   default:
21 21
     $info = NULL;
... ...
@@ -31,8 +31,7 @@ output('<h3>Domains</h3>
31 31
 ');
32 32
 foreach ($user_domains as $domain)
33 33
 {
34
-  $canc = $domain['cancel_date'];
35
-  output("  <tr><td><a href=\"http://www.{$domain['domainname']}\">{$domain['domainname']}</a></td><td>{$domain['reg_date']}</td><td>{$canc}</td></tr>\n");
34
+  output("  <tr><td><a href=\"http://www.{$domain->fqdn}\">{$domain->fqdn}</a></td><td>{$domain->reg_date}</td><td>{$domain->cancel_date}</td></tr>\n");
36 35
 }
37 36
 output('</table>');
38 37
 output("<br />");
... ...
@@ -1,66 +0,0 @@
1
-<?php
2
-
3
-require_once('inc/db_connect.php');
4
-require_once('inc/debug.php');
5
-
6
-function get_domain_names($customerno, $uid = NULL)
7
-{
8
-  $customerno = (int) $customerno;
9
-  $query = "SELECT id,CONCAT_WS('.', domainname, tld) AS domainname, registrierungsdatum, kuendigungsdatum FROM kundendaten.domains WHERE";
10
-  if ($uid !== NULL)
11
-  {
12
-    $uid = (int) $uid;
13
-    $query .= " useraccount={$uid};";
14
-  }
15
-  else
16
-  {
17
-    $query .= " kunde={$customerno};";
18
-  }
19
-  $result = db_query($query);
20
-  $domains = array();
21
-  DEBUG('Result set is '.mysql_num_rows($result)." rows.<br />\n");
22
-  if (mysql_num_rows($result) > 0)
23
-    while ($domain = mysql_fetch_object($result))
24
-      array_push($domains, array('id' => $domain->id,
25
-                              'domainname'  => $domain->domainname,
26
-                              'reg_date' => $domain->registrierungsdatum,
27
-                              'cancel_date' => $domain->kuendigungsdatum));
28
-
29
-	return $domains;	
30
-}
31
-
32
-
33
-
34
-function get_domain_name($domid)
35
-{
36
-  if ($domid === NULL)
37
-    return 'schokokeks.org';
38
-  $domid = (int) $domid;
39
-  static $domainlist = array();
40
-
41
-  $result = db_query("SELECT CONCAT_WS('.', domainname, tld) AS domainname FROM kundendaten.domains WHERE id=$domid;");
42
-  if (@mysql_num_rows($result) > 0)
43
-    return mysql_fetch_object($result)->domainname;
44
-  else
45
-    return NULL;
46
-
47
-}
48
-
49
-
50
-function get_jabberable_domains()
51
-{
52
-  require_role(ROLE_CUSTOMER);
53
-  $customerno = (int) $_SESSION['customerinfo']['customerno'];
54
-  $result = db_query("SELECT id, CONCAT_WS('.', domainname, tld) AS name FROM kundendaten.domains WHERE jabber=1 AND kunde={$customerno}");
55
-  
56
-  $domains = array(array('id' => 0, 'name' => 'schokokeks.org'));
57
-  if (mysql_num_rows($result) > 0)
58
-    while ($domain = mysql_fetch_object($result))
59
-      array_push($domains, array('id' => $domain->id,
60
-                                'name' => $domain->name));
61
-
62
-  return $domains;
63
-
64
-}
65
-
66
-?>
... ...
@@ -2,7 +2,7 @@
2 2
 
3 3
 require_once('session/start.php');
4 4
 
5
-require_once('domains.php');
5
+require_once('class/domain.php');
6 6
 require_once('mailaccounts.php');
7 7
 
8 8
 require_role(ROLE_SYSTEMUSER);
... ...
@@ -85,12 +85,11 @@ elseif (isset($_GET['action']) && $_GET['action'] == 'create')
85 85
     <td><input type="text" id="user" name="user" />@<select name="domain" size="1">
86 86
     <option value="schokokeks.org">schokokeks.org</option>
87 87
     ');
88
-    require_once('domains.php');
89
-    $domains = get_domain_names($user['customerno'], $user['uid']);
88
+    $domains = get_domain_list($user['customerno'], $user['uid']);
90 89
     if (count($domains) > 0)
91 90
       output('<option>----------------------------</option>');
92 91
     foreach ($domains as $dom)
93
-      output('<option value="'.$dom['domainname'].'">'.$dom['domainname'].'</option>');
92
+      output('<option value="'.$dom->fqdn.'">'.$dom->fqdn.'</option>');
94 93
     output('</select></td>
95 94
 
96 95
   </tr>
... ...
@@ -165,15 +164,14 @@ elseif (isset($_GET['edit']))
165 164
           <td><input type="text" id="user" name="user" value="'.$username.'" />@<select name="domain" id="domain" size="1">
166 165
     <option value="schokokeks.org">schokokeks.org</option>
167 166
     ');
168
-    require_once('domains.php');
169
-    $domains = get_domain_names($user['customerno'], $user['uid']);
167
+    $domains = get_domain_list($user['customerno'], $user['uid']);
170 168
     if (count($domains) > 0)
171 169
       output('<option>----------------------------</option>');
172 170
     foreach ($domains as $dom)
173
-      if ($domain == $dom['domainname'])
174
-        output('<option value="'.$dom['domainname'].'" selected="selected">'.$dom['domainname'].'</option>');
171
+      if ($domain == $dom->fqdn)
172
+        output('<option value="'.$dom->fqdn.'" selected="selected">'.$dom->fqdn.'</option>');
175 173
       else
176
-        output('<option value="'.$dom['domainname'].'">'.$dom['domainname'].'</option>');
174
+        output('<option value="'.$dom->fqdn.'">'.$dom->fqdn.'</option>');
177 175
 
178 176
     output('</select></td>
179 177
           <td><input type="button" onclick="document.getElementById(\'user\').value = \''.$username.'\' ; document.getElementById(\'domain\').value = \''.$domain.'\'" value="Zeile zur&uuml;cksetzen" /></td></tr>
... ...
@@ -1 +0,0 @@
1
-../../domains/include/domains.php
2 0
\ No newline at end of file
... ...
@@ -4,6 +4,8 @@ require_once('inc/debug.php');
4 4
 require_once('inc/db_connect.php');
5 5
 require_once('inc/base.php');
6 6
 
7
+require_once('class/domain.php');
8
+
7 9
 function mailaccounts($uid)
8 10
 {
9 11
   $uid = (int) $uid;
... ...
@@ -38,16 +40,6 @@ function encrypt_mail_password($pw)
38 40
 
39 41
 }
40 42
 
41
-function get_domain_id($domain) 
42
-{
43
-  $domain = mysql_real_escape_string($domain);
44
-  $result = db_query("SELECT id FROM mail.v_domains WHERE domainname = '{$domain}';");
45
-  if (mysql_num_rows($result) == 0)
46
-    return NULL;
47
-  return mysql_fetch_object($result)->id;
48
-}
49
-
50
-
51 43
 function change_mailaccount($id, $arr)
52 44
 {
53 45
   $id = (int) $id;
... ...
@@ -56,10 +48,13 @@ function change_mailaccount($id, $arr)
56 48
   if (isset($arr['account']))
57 49
   {
58 50
     list($local, $domain) = explode('@', $arr['account'], 2);
59
-    $domainid = get_domain_id($domain);
60
-    if ($domainid == NULL)
61
-      $domainid='NULL';
62
-    array_push($conditions, "local='".mysql_real_escape_string($local)."', domain=$domainid");
51
+    $domain = new Domain( (string) $domain);
52
+    if ($domain->id == NULL)
53
+      array_push($conditions, "domain=NULL");
54
+    else
55
+      array_push($conditions, "domain={$domain->id}");
56
+
57
+    array_push($conditions, "local='".mysql_real_escape_string($local)."'");
63 58
   }
64 59
   if (isset($arr['mailbox']))
65 60
     if ($arr['mailbox'] == '')
... ...
@@ -92,11 +87,13 @@ function create_mailaccount($arr)
92 87
   $values['uid'] = (int) $_SESSION['userinfo']['uid'];
93 88
 
94 89
   list($local, $domain) = explode('@', $arr['account'], 2);
95
-  $domainid = get_domain_id($domain);
96
-  if ($domainid == NULL)
97
-    $domainid='NULL';
90
+  $domain = new Domain( (string) $domain);
91
+  if ($domain->id == NULL)
92
+    $values['domain'] = "NULL";
93
+  else
94
+    $values['domain'] = $domain->id;
95
+
98 96
   $values['local'] = "'".mysql_real_escape_string($local)."'";
99
-  $values['domain'] = $domainid;
100 97
 
101 98
   if (isset($arr['mailbox']))
102 99
     if ($arr['mailbox'] == '')
... ...
@@ -147,11 +144,10 @@ function check_valid($acc)
147 144
     return "Es wurde kein Domain-Teil im Account-Name angegeben. Account-Namen m&uuml;ssen einen Domain-Teil enthalten. Im Zweifel versuchen Sie &quot;@schokokeks.org&quot;.";
148 145
 
149 146
   list($local, $domain) = explode('@', $acc['account'], 2);
150
-  require_once('domains.php');
151
-  $tmpdomains = get_domain_names($user['customerno'], $user['uid']);
147
+  $tmpdomains = get_domain_list($user['customerno'], $user['uid']);
152 148
   $domains = array();
153 149
   foreach ($tmpdomains as $dom)
154
-    array_push($domains, $dom['domainname']);
150
+    $domains[] = $dom->fqdn;
155 151
 
156 152
   if (array_search($domain, $domains) === false)
157 153
   {
... ...
@@ -2,7 +2,7 @@
2 2
 
3 3
 require_once('session/start.php');
4 4
 
5
-require_once('domains.php');
5
+require_once('class/domain.php');
6 6
 require_once('jabberaccounts.php');
7 7
 
8 8
 require_once('inc/security.php');
... ...
@@ -22,8 +22,13 @@ output("<h3>Jabber-Accounts</h3>
22 22
 foreach ($jabberaccounts as $acc)
23 23
 {
24 24
   $local = filter_input_general($acc['local']);
25
-  $domain = filter_input_general( get_domain_name($acc['domain']) );
26
-  output("<tr><td>{$local}@$domain</td><td>".internal_link('chpass.php', 'Passwort ändern', 'account='.$acc['id'])."&nbsp;&nbsp;&nbsp;".internal_link('save.php', 'Löschen', 'action=delete&account='.$acc['id']).'</td></tr>');
25
+  $domain = new Domain( (int) $acc['domain']  );
26
+  if ($domain->id == NULL)
27
+  {
28
+    $domain = new Domain();
29
+    $domain->fqdn='schokokeks.org';
30
+  }
31
+  output("<tr><td>{$local}@{$domain->fqdn}</td><td>".internal_link('chpass.php', 'Passwort ändern', 'account='.$acc['id'])."&nbsp;&nbsp;&nbsp;".internal_link('save.php', 'Löschen', 'action=delete&account='.$acc['id']).'</td></tr>');
27 32
 }
28 33
 
29 34
 output('</table>
... ...
@@ -2,7 +2,6 @@
2 2
 
3 3
 require_once('session/start.php');
4 4
 
5
-require_once('domains.php');
6 5
 require_once('jabberaccounts.php');
7 6
 
8 7
 require_role(ROLE_CUSTOMER);
... ...
@@ -1 +0,0 @@
1
-../../domains/include/domains.php
2 0
\ No newline at end of file
... ...
@@ -2,7 +2,7 @@
2 2
 
3 3
 require_once('session/start.php');
4 4
 
5
-require_once('domains.php');
5
+require_once('class/domain.php');
6 6
 require_once('jabberaccounts.php');
7 7
 
8 8
 require_role(ROLE_CUSTOMER);
... ...
@@ -16,7 +16,7 @@ $jabberdomains = get_jabberable_domains();
16 16
 $options = '';
17 17
 foreach ($jabberdomains as $dom)
18 18
 {
19
-  $options .= '<option value="'.$dom['id'].'">'.$dom['name'].'</option>'."\n";
19
+  $options .= '<option value="'.$dom->id.'">'.$dom->fqdn.'</option>'."\n";
20 20
 }
21 21
 
22 22
 
23 23