changed machine output to DOM (fixes charset problems)
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 13 Jan 2008 19:49:25 +0000 (19:49 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 13 Jan 2008 19:49:25 +0000 (19:49 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@84 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

www/inc/session.php

index ddac732..2f3a2d4 100644 (file)
@@ -223,11 +223,15 @@ function getAllUsersXml()
        global $db;
        header("X-MagicSmoke-Status: Ok");
        $res=$db->select("users","uname,description","");
-       print("<Users>\n");
+       $dom=new DomDocument;
+       $root=$dom->createElement("Users");
        for($i=0;$i<count($res);$i++){
-               print("<User name=\"".htmlentities($res[$i]["uname"])."\">".htmlentities($res[$i]["description"])."</User>\n");
+               $usr=$dom->createElement("User",$res[$i]["description"]);
+               $usr->setAttributeNode(new DOMAttr("name",$res[$i]["uname"]));
+               $root->appendChild($usr);
        }
-       print("</Users>");
+       $dom->appendChild($root);
+       print($dom->saveXML());
 }
 
 //return the roles of a specific user
@@ -249,14 +253,18 @@ function getUserAclXml($user)
        $res=$db->select("userrole","role","uname=".$user);
        $acl=array();
        foreach($res as $rl)$acl[]=$rl["role"];
-       print("<ACL user=\"$user\">\n");
+       $dom=new DOMDocument;
+       $root=$dom->createElement("ACL");
+       $root->setAttributeNode(new DOMAttr("user",$user));
        foreach($roles as $rl){
-               print("<Role name=\"$rl\" set=\"");
-               if(array_search($rl,$acl)===false)print("0");
-               else print("1");
-               print("\">\n");
+               $re=$dom->createElement("Role");
+               $re->setAttributeNode(new DOMAttr("name",$rl));
+               if(array_search($rl,$acl)===false)$re->setAttributeNode(new DOMAttr("set","0"));
+               else $re->setAttributeNode(new DOMAttr("set","0"));
+               $root->appendChild($re);
        }
-       print("</ACL>\n");
+       $dom->appendChild($root);
+       print($dom->saveXML());
 }
 
 //helper function: parse User-XML-structure
@@ -295,8 +303,8 @@ function addUserXml($txt)
 {
        global $db;
        $usr=parseUserXml($txt);
-       header("X-MagicSmoke-Status: Ok");
-       print("<Users>\n");
+       $dom=new DOMDocument;
+       $root=$dom->createElement("Users");
        for($i=0;$i<count($usr);$i++){
                //syntax check
                if(ereg("^[A-Za-z0-9_]+$",$usr[$i]["name"])===false)continue;
@@ -307,11 +315,14 @@ function addUserXml($txt)
                        //create new
                        $db->insert("users",array("uname"=>$usr[$i]["name"],"description"=>$usr[$i]["descr"]));
                        //print data
-                       print("<User name=\"".htmlentities($usr[$i]["name"])."\">".htmlentities($usr[$i]["descr"])."</User>\n");
+                       $usr=$dom->createElement("User",$usr[$i]["descr"]);
+                       $usr->setAttributeNode(new DOMAttr("name",$usr[$i]["name"]));
+                       $root->appendChild($usr);
                }
                $db->commitTransaction();
        }
-       print("</Users>\n");
+       $dom->appendChild($root);
+       print($dom->saveXML());
 }
 
 ?>
\ No newline at end of file