Cookie einen eindeutigen Namen geben
bernd

bernd commited on 2007-07-26 10:56:10
Zeige 3 geänderte Dateien mit 123 Einfügungen und 2 Löschungen.


git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@557 87cf0b9e-d624-0410-a070-f6ee81989793
... ...
@@ -0,0 +1,99 @@
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 ContactMethod extends KeksData
11
+{
12
+  function __construct($init = NULL)
13
+  {
14
+    $this->default_table = 'kundendaten.kundenkontakt';
15
+    $this->setup();
16
+    if ($init != NULL)
17
+      switch (gettype($init))
18
+      {
19
+        case 'string':
20
+          $this->loadByAddress($init);
21
+          break;
22
+        case 'integer':
23
+          $this->loadByID($init);
24
+          break;
25
+      }
26
+  }
27
+
28
+
29
+  function loadByAddress($name)
30
+  {
31
+    $name = mysql_real_escape_string($name);
32
+    DEBUG("Requested to load ContactMethod-object for address »{$name}«");
33
+    $res = $this->getData("*", "wert='{$name}' LIMIT 1");
34
+    if (count($res) < 1)
35
+    {
36
+      DEBUG('nothing found');
37
+      return false;
38
+    }
39
+    $this->parse($res[0]);
40
+    return true;
41
+  }
42
+
43
+
44
+  function loadByCustomer($cid, $comment = '')
45
+  {
46
+    $cid = (int) $cid;
47
+    $comment = mysql_real_escape_string($comment);
48
+    DEBUG("Requested to load ContactMethod-object for customer »{$cid}« (comment = {$comment})");
49
+    $res = $this->getData("*", "kundennr='{$cid}' AND (comment='{$comment}' OR (comment IS NULL AND '{$comment}'='')) LIMIT 1");
50
+    if (count($res) < 1)
51
+    {
52
+      DEBUG('nothing found');
53
+      return false;
54
+    }
55
+    $this->parse($res[0]);
56
+    return true;
57
+  }
58
+  
59
+  function parse($data)
60
+  {
61
+    foreach (array_keys($this->data) as $key)
62
+      if (array_key_exists($key, $data))
63
+        $this->data[$key] = $data[$key];
64
+  }
65
+
66
+}
67
+
68
+
69
+
70
+class Customer extends KeksData
71
+{
72
+  function __construct($init = NULL)
73
+  {
74
+    $this->default_table = 'kundendaten.kunden';
75
+    $this->setup();
76
+    if ($init != NULL)
77
+      $this->loadByID( (int) $init);
78
+  }
79
+
80
+  function parse($data)
81
+  {
82
+    foreach (array_keys($this->data) as $key)
83
+      if (array_key_exists($key, $data))
84
+        $this->data[$key] = $data[$key];
85
+    $this->data['fullname'] = $data['vorname'].' '.$data['nachname'];
86
+    $this->data['email'] = new ContactMethod();
87
+    $this->data['email']->loadByCustomer($this->data['id']);
88
+    $this->data['email_rechnung'] = new ContactMethod();
89
+    if (! $this->data['email_rechnung']->loadByCustomer($this->data['id'], 'rechnung'))
90
+      $this->data['email_rechnung'] = $this->data['email'];
91
+    $this->data['email_extern'] = new ContactMethod();
92
+    if (! $this->data['email_extern']->loadByCustomer($this->data['id'], 'extern'))
93
+      $this->data['email_extern'] = $this->data['email'];
94
+  }
95
+
96
+}
97
+
98
+
99
+?> 
... ...
@@ -9,7 +9,9 @@ abstract class KeksData
9 9
 {
10 10
   protected $default_table;
11 11
   
12
+  protected $raw_data = array();
12 13
   protected $data = array();
14
+  protected $changes = array();
13 15
 
14 16
   function __get($key)
15 17
   {
... ...
@@ -22,8 +24,14 @@ abstract class KeksData
22 24
 
23 25
   function __set($key, $value)
24 26
   {
25
-    if (array_key_exists($key, $this->data))
26
-      $this->data[$key] = $value;
27
+    if (array_key_exists($key, $this->raw_data))
28
+    {
29
+      $this->raw_data[$key] = $value;
30
+      $this->changes[$key] = $value;
31
+      $this->parse($this->raw_data);
32
+    }
33
+    elseif (array_key_exists($key, $this->data))
34
+      return false;
27 35
     elseif (isset($this->$key))
28 36
       $this->$key = $value;
29 37
     else
... ...
@@ -64,6 +72,7 @@ abstract class KeksData
64 72
   function loadByID($id)
65 73
   {
66 74
     $id = (int) $id;
75
+    DEBUG("requested to load ID »{$id}«");
67 76
     $res = $this->getData('*', "id={$id} LIMIT 1");
68 77
     if (count($res) < 1)
69 78
       return false;
... ...
@@ -71,6 +80,17 @@ abstract class KeksData
71 80
   }
72 81
 
73 82
 
83
+  function save()
84
+  {
85
+    $upd = array();
86
+    foreach ($this->changes as $key => $value)
87
+    {
88
+      $value = mysql_real_escape_string($value);
89
+      array_push($upd, "`{$key}`='{$value}'");
90
+    }
91
+    db_query("UPDATE {$this->default_table} SET ".implode(', ', $upd)." WHERE id={$this->data['id']};");
92
+  }
93
+
74 94
   abstract function parse($data);
75 95
 
76 96
 }
... ...
@@ -11,6 +11,8 @@ require_once('inc/debug.php');
11 11
 
12 12
 require_once('inc/base.php');
13 13
 
14
+session_name('CONFIG_SCHOKOKEKS_ORG');
15
+
14 16
 if (!session_start())
15 17
 {
16 18
         logger("session/start.php", "session", "Die session konnte nicht gestartet werden!");
17 19