<?php
// Created by Ardora www.webardora.net
//ArdoraFormularios-ardoraXML
//bajo licencia Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)
//para otros usos contacte con el autor
session_start();
$slogin_noauthpage = 0;
$slogin_pagetitle = "";
include_once ("para.php");include_once (profUname.uName."/".uName."_lib.php");
session_cache_limiter('nocache,private');
$folderN="../".folderWork; $folUser=$_SESSION["Username"];
if($_POST["action"]=="new"){$xml=new DomDocument("1.0","UTF-8");if ($_POST["type"]=="0"){$xmlName=$_SESSION["Username"];} else {$xmlName=$_POST["nameUser"];}
$initial=$xml->createElement($xmlName);$initial=$xml->appendChild($initial);$form=$xml->createElement("form");$form=$initial->appendChild($form);$idNum=$xml->createElement("idNum",$_POST["idNum"]);$idNum=$form->appendChild($idNum);
$paragrafo5=$xml->createElement("paragrafo5",$_POST["paragrafo5"]);$paragrafo5=$form->appendChild($paragrafo5);$paragrafo8=$xml->createElement("paragrafo8",$_POST["paragrafo8"]);$paragrafo8=$form->appendChild($paragrafo8);$edit1=$xml->createElement("edit1",$_POST["edit1"]);$edit1=$form->appendChild($edit1);$edit2=$xml->createElement("edit2",$_POST["edit2"]);$edit2=$form->appendChild($edit2);$edit3=$xml->createElement("edit3",$_POST["edit3"]);$edit3=$form->appendChild($edit3);
$xml->formatOut=true;$strings_xml=$xml->saveXML();if($xml->save($folderN.$xmlName.".xml")){$arr=array("status" => "Ok");}else{$arr=array("status" => "Error");}; echo json_encode($arr);}
if($_POST["action"]=="getUser"){if (file_exists($folderN.$_SESSION["Username"].".xml")){$xml = new DOMDocument("1.0", "utf-8");$xml->formatOutput = true;$xml->preserveWhiteSpace = false;$xml->load($folderN.$_SESSION["Username"].".xml");$form=$xml->getElementsByTagName("form")->item(0);
$paragrafo5=$form->getElementsByTagName("paragrafo5")->item(0);
$paragrafo8=$form->getElementsByTagName("paragrafo8")->item(0);
$edit1=$form->getElementsByTagName("edit1")->item(0);
$edit2=$form->getElementsByTagName("edit2")->item(0);
$edit3=$form->getElementsByTagName("edit3")->item(0);
echo json_encode(array("tiUser"=>"1","paragrafo5"=>$paragrafo5->nodeValue,"paragrafo8"=>$paragrafo8->nodeValue,"edit1"=>$edit1->nodeValue,"edit2"=>$edit2->nodeValue,"edit3"=>$edit3->nodeValue,"userType"=>dameValor($_SESSION["Username"],"TIP")));
}else{echo json_encode(array("tiUser"=>"0","userType"=>dameValor($_SESSION["Username"],"TIP")));}}
if($_POST["action"]=="delete"){if(unlink($folderN.$_SESSION["Username"].".xml")){$arr=array("status" => "Ok");} else{ $arr=array("status" => "Error"); }; echo json_encode($arr);}
if($_POST["action"]=="getUserData"){if (file_exists($folderN.$_POST["nameUser"].".xml")){$xml = new DOMDocument("1.0", "utf-8");$xml->formatOutput = true;$xml->preserveWhiteSpace = false;$xml->load($folderN.$_POST["nameUser"].".xml");$form=$xml->getElementsByTagName("form")->item(0);
$paragrafo5=$form->getElementsByTagName("paragrafo5")->item(0);
$paragrafo8=$form->getElementsByTagName("paragrafo8")->item(0);
$edit1=$form->getElementsByTagName("edit1")->item(0);
$edit2=$form->getElementsByTagName("edit2")->item(0);
$edit3=$form->getElementsByTagName("edit3")->item(0);
echo json_encode(array("tiUser"=>"1","paragrafo5"=>$paragrafo5->nodeValue,"paragrafo8"=>$paragrafo8->nodeValue,"edit1"=>$edit1->nodeValue,"edit2"=>$edit2->nodeValue,"edit3"=>$edit3->nodeValue,"userType"=>dameValor($_SESSION["Username"],"TIP")));
}else{echo json_encode(array("tiUser"=>"0","userType"=>dameValor($_SESSION["Username"],"TIP")));}}
if($_POST["action"]=="deleteJob"){if(unlink($folderN.$_POST["nameUser"].".xml")){$arr=array("status" => "Ok");}else{$arr=array("status" => "Error");}; echo json_encode($arr);}
if ($_POST["action"]=="indexUsers") {$orderName=scandir("../".folderWork."/");for ($i = 0; $i < count($orderName); $i++) {if (strcmp ($orderName[$i],".")==0 || strcmp ($orderName[$i],"..")==0){$orderData[$i]="";} else {$orderData[$i]=dameValor(basename($orderName[$i],".xml"),"NOM");}};
for ($i = 0; $i < count($orderName); $i++) {if (strcmp ($orderName[$i],".")!=0 && strcmp ($orderName[$i],"..")!=0){$resultArray[$i]=array($orderName[$i],$orderData[$i]);}} echo json_encode($resultArray);}
?>
