<?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);
$paragrafo1=$xml->createElement("paragrafo1");$cdparagrafo1=$xml->createCDATASection($_POST["paragrafo1"]);$paragrafo1->appendChild($cdparagrafo1);$form->appendChild($paragrafo1);$edit1=$xml->createElement("edit1",$_POST["edit1"]);$edit1=$form->appendChild($edit1);$edit2=$xml->createElement("edit2",$_POST["edit2"]);$edit2=$form->appendChild($edit2);
$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);
$paragrafo1=$form->getElementsByTagName("paragrafo1")->item(0);
$edit1=$form->getElementsByTagName("edit1")->item(0);
$edit2=$form->getElementsByTagName("edit2")->item(0);
echo json_encode(array("tiUser"=>"1","paragrafo1"=>stripslashes($paragrafo1->nodeValue),"edit1"=>$edit1->nodeValue,"edit2"=>$edit2->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);
$paragrafo1=$form->getElementsByTagName("paragrafo1")->item(0);
$edit1=$form->getElementsByTagName("edit1")->item(0);
$edit2=$form->getElementsByTagName("edit2")->item(0);
echo json_encode(array("tiUser"=>"1","paragrafo1"=>stripslashes($paragrafo1->nodeValue),"edit1"=>$edit1->nodeValue,"edit2"=>$edit2->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);}
?>
