Commit 85e52dfcef2be1d8cc56a6651abfd4db6e2b627e

Authored by Georg Hopp
1 parent d4303ecf

--no commit message

1 1 <?php
2 2
3   -// $english = mysql_escape_string($_REQUEST['translate']);
4   -// Der Service ist zur Zeit leider deaktiviert....
5   -// $trans = new SoapClient(
6   -// "http://www.xmethods.net/sd/2001/BabelFishService.wsdl");
7   -
8   -/*
9   - try
10   - {
11   - $german = $trans->BabelFish("en_de",$english);
12   - $french = $trans->BabelFish("en_fr",$english);
13   - }
14   - catch(SoapFault $e)
15   - {
16   - $english = "not found";
17   - $german = "not found";
18   - $french = "not found";
19   - }
20   -*/
21   - class dummy
22   - {
23   - // nur public member werden via json verschickt.
24   - public $german;
25   - public $english;
26   - public $french;
27   -
28   - function __construct ($english, $german, $french)
29   - {
30   - $this->german = $german;
31   - $this->english = $english;
32   - $this->french["val1"] = $french;
33   - $this->french["val2"] = "jokus";
34   - }
35   - }
36   -
37   - $encoding = FALSE;
38   - if (isset ($_SERVER['HTTP_ACCEPT_ENCODING']) &&
39   - strpos ($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== FALSE)
40   - $encoding = "x-gzip";
41   - if (isset ($_SERVER['HTTP_ACCEPT_ENCODING']) &&
42   - strpos ($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE)
43   - $encoding = "gzip";
44   -
45   - header ('Content-type: text/plain');
46   -
47   - $result = FALSE;
48   - if ($encoding !== FALSE)
49   - $result = gzcompress (json_encode (new dummy (
50   - 'doing gzip', 'gezipedte Daten', 'la zippo')));
51   -
52   - if ($result !== FALSE)
53   - {
54   - header ('Content-Encoding: ' . $encoding);
55   -
56   - print ("\x1f\x8b\x08\x00\x00\x00\x00\x00");
57   - print ($result);
58   - }
59   - else
60   - {
61   - $result = json_encode (new dummy (
62   - 'doing no gzip', 'nicht gezipedte Daten', 'no la zippo'));
63   -
64   - print ($result);
65   - }
  3 +require_once dirname(__FILE__) . '/../config.php';
  4 +require_once LIBDIR . 'c_personAdmin.php';
  5 +require_once LIBDIR . 'c_xmlify.php';
  6 +
  7 +$personAdmin = new c_personAdmin ();
  8 +$persons = xmlify ($personAdmin->getPersons ());
  9 +$p = deXmlify ($persons);
  10 +
  11 +exit (1);
  12 +
  13 +$encoding = FALSE;
  14 +if (isset ($_SERVER['HTTP_ACCEPT_ENCODING']) &&
  15 + strpos ($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== FALSE)
  16 +$encoding = "x-gzip";
  17 +if (isset ($_SERVER['HTTP_ACCEPT_ENCODING']) &&
  18 + strpos ($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE)
  19 +$encoding = "gzip";
  20 +
  21 +header ('Content-type: text/xml');
  22 +
  23 +$result = FALSE;
  24 +if ($encoding !== FALSE)
  25 + $result = gzcompress ($persons);
  26 +
  27 +if ($result !== FALSE)
  28 +{
  29 + header ('Content-Encoding: ' . $encoding);
  30 +
  31 + print ("\x1f\x8b\x08\x00\x00\x00\x00\x00");
  32 + print ($result);
  33 +}
  34 +else
  35 + print ($persons);
66 36
67 37 ?>
... ...
... ... @@ -7,9 +7,72 @@
7 7
8 8 <script type="text/javascript">
9 9 <!--
  10 + function xmlToArray (xr)
  11 + {
  12 + ret = new Array ();
  13 +
  14 + if (! xr.hasChildNodes ())
  15 + return ret;
  16 +
  17 + for (node in xr.childNodes)
  18 + {
  19 + if (node.nodeType == 1 &&
  20 + node.name == 'item')
  21 + {
  22 + key = childNode->getAttribute ('key');
  23 + if (parseInt (key, 10) !== NaN)
  24 + key = parseInt (key, 10);
  25 +
  26 + for (_node in node.childNodes)
  27 + {
  28 + if (_node->nodeType == 1)
  29 + {
  30 + switch (_node->nodeName)
  31 + {
  32 + case 'variable':
  33 + ret[key] = xmlToVar (_node);
  34 + type = _node->getAttribute ('type');
  35 + //settype (ret[key], type);
  36 + break;
  37 +
  38 + case 'array':
  39 + ret[key] = xmlToArray (_node);
  40 + break;
  41 +
  42 + case 'class':
  43 + _class = _node->getAttribute ('class');
  44 + eval ('ret[key] = new ' + _class + '(_node)');
  45 + }
  46 + }
  47 + }
  48 + }
  49 + }
  50 +
  51 + return ret;
  52 + }
  53 +
  54 +
  55 + function xmlToVar (xr)
  56 + {
  57 + if (!xr.hasChildNodes ())
  58 + return null;
  59 +
  60 + var ret = null;
  61 +
  62 + for (node in xr.childNodes)
  63 + if (node.nodeType === 3 && node.nodeValue !== null)
  64 + {
  65 + ret = node.nodeValue;
  66 + break;
  67 + }
  68 +
  69 + return ret;
  70 + }
  71 +
  72 +
10 73 var req = null;
11 74
12   - function handleTranslation ()
  75 + function getPersons ()
13 76 {
14 77 switch (req.readyState)
15 78 {
... ... @@ -18,16 +81,38 @@
18 81 alert("Fehler:"+req.status);
19 82 else
20 83 {
21   - // felder des formulars
22   - german_field = document.getElementById("german");
23   - french_field = document.getElementById("french");
24   -
  84 + //for (x in req.responseXML)
  85 + //{
  86 + // console.dir (x);
  87 + // break;
  88 + // }
  89 + data = req.responseXML.firstChild;
  90 +
  91 + //console.dir (data);
  92 + switch (data.nodeName)
  93 + {
  94 + case 'variable': ret = xmlToVar (data); break;
  95 + //case 'array': ret = xmlToArray (data); break;
  96 + //case 'class': ret = xmlToObject (data);
  97 + }
  98 +
  99 + console.log ('%s', ret);
  100 +
  101 + // ----
  102 + //german_resp = xml.getElementsByTagName("german")[0];
  103 + //french_resp = xml.getElementsByTagName("french")[0];
  104 +
  105 + //schreiben des ergebnisses
  106 + //german_field.value = german_resp.firstChild.nodeValue;
  107 + //french_field.value = french_resp.firstChild.nodeValue;
  108 + // ----
  109 +
25 110 // antwort des servers
26   - var translation = eval('(' + req.responseText + ')');
  111 + //var translation = eval('(' + req.responseText + ')');
27 112
28 113 // schreiben des ergebnisses
29   - german_field.value = translation.german;
30   - french_field.value = translation.french.val1;
  114 + //german_field.value = translation.german;
  115 + //french_field.value = translation.french.val1;
31 116 }
32 117 return true;
33 118
... ... @@ -36,7 +121,7 @@
36 121 }
37 122 }
38 123
39   - function translate ()
  124 + function updPersons ()
40 125 {
41 126 // erstellen des requests
42 127
... ... @@ -68,13 +153,12 @@
68 153
69 154 // anfrage erstellen (GET, url ist localhost,
70 155 // request ist asynchron
71   - var url = 'http://muedv031/~georg/bilder/ajax+json/ajax.php' +
72   - '?translate=' + document.getElementById ('myword').value;
  156 + var url = 'http://localhost/~georg/bilder/ajax+json/ajax.php';
73 157
74 158 req.open("GET", url, true);
75 159
76 160 // Beim abschliessen des request wird diese Funktion ausgeführt
77   - req.onreadystatechange = handleTranslation;
  161 + req.onreadystatechange = getPersons;
78 162
79 163 req.setRequestHeader("Content-Type",
80 164 "application/x-www-form-urlencoded");
... ... @@ -87,11 +171,11 @@
87 171 </head>
88 172
89 173 <body>
90   - <div id="eins" style="width: 80%; height: 80%; border: dashed 1px;">
91   - englisch: <input type="text" id="myword" onchange="translate();" />
92   - <br />
93   - deutsch: <input type="text" id="german" /><br />
94   - französisch: <input type="text" id="french" /><br />
  174 + <div id="eins" style="width: 600px; height: 450px; border: dashed 1px;">
  175 + dummy: <input type="text" id="myword" onchange="updPersons ();" />
  176 + <p id="persons">
  177 + Hier koennen personen stehen....
  178 + </p>
95 179 </div>
96 180 </body>
97 181 </html>
... ...
Please register or login to post a comment