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
$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
{
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;
//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