<?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_cache_limiter('nocache,private');
session_start();
$slogin_noauthpage = 0;
$slogin_pagetitle = "";
include_once ("para.php");include_once (profUname.uName."/".uName."_lib.php");
$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);
$paragrafo2=$xml->createElement("paragrafo2");$cdparagrafo2=$xml->createCDATASection($_POST["paragrafo2"]);$paragrafo2->appendChild($cdparagrafo2);$form->appendChild($paragrafo2);
$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);
$paragrafo2=$form->getElementsByTagName("paragrafo2")->item(0);
echo json_encode(array("tiUser"=>"1","paragrafo2"=>stripslashes($paragrafo2->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);
$paragrafo2=$form->getElementsByTagName("paragrafo2")->item(0);
echo json_encode(array("tiUser"=>"1","paragrafo2"=>stripslashes($paragrafo2->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);}
?>
