<?php
// Created by Ardora www.webardora.net
//POLAROID-ardoraAjaxJson
//bajo licencia Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)
//para otros usos contacte con el autor
$_SERVER["HTTP_REFERER"]="introDatos.php";session_start();$slogin_noauthpage = 0;$slogin_pagetitle = "";
include_once ("../stu1A/stu1A_lib.php");
session_cache_limiter("nocache,private");
$thumb_directory = "../ardoraWorkFiles/computertime/img/thumbs/";
$orig_directory = "../ardoraWorkFiles/computertime/img/original/";
$datos_directory = "../ardoraWorkFiles/computertime/";
$allowed_types=array("jpg","jpeg","gif","png");$file_parts=array();$ext="";$title="";$i=1;$contador=0;
$GLOBALS["normalizeChars"] = array(
"Š"=>"S", "š"=>"s", "Ð"=>"Dj","Ž"=>"Z", "ž"=>"z", "À"=>"A", "Á"=>"A", "Â"=>"A", "Ã"=>"A", "Ä"=>"A",
"Å"=>"A", "Æ"=>"A", "Ç"=>"Cz", "È"=>"E", "É"=>"E", "Ê"=>"E", "Ë"=>"E", "Ì"=>"I", "Í"=>"I", "Î"=>"I",
"Ï"=>"I", "Ñ"=>"Nz", "Ò"=>"O", "Ó"=>"O", "Ô"=>"O", "Õ"=>"O", "Ö"=>"O", "Ø"=>"O", "Ù"=>"U", "Ú"=>"U",
"Û"=>"U", "Ü"=>"U", "Ý"=>"Y", "Þ"=>"B", "ß"=>"Ss","à"=>"a", "á"=>"a", "â"=>"a", "ã"=>"a", "ä"=>"a",
"å"=>"a", "æ"=>"a", "ç"=>"cz", "è"=>"e", "é"=>"e", "ê"=>"e", "ë"=>"e", "ì"=>"i", "í"=>"i", "î"=>"i",
"ï"=>"i", "ð"=>"o", "ñ"=>"nz", "ò"=>"o", "ó"=>"o", "ô"=>"o", "õ"=>"o", "ö"=>"o", "ø"=>"o", "ù"=>"u",
"ú"=>"u", "û"=>"u", "ý"=>"y", "ý"=>"y", "þ"=>"b", "ÿ"=>"y", "ƒ"=>"f"
);
function normaliza($toClean) {
$toClean     =     str_replace("&", "-and-", $toClean);
$toClean     =    trim(preg_replace("/[^\w\d_ -]/si", "", $toClean));
$toClean     =     str_replace(" ", "-", $toClean);
$toClean     =     str_replace("--", "-", $toClean);
return strtr($toClean, $GLOBALS["normalizeChars"]);
}
$dir_handle = @opendir($datos_directory) or die("There is an error with your image directory!");
if($_POST["action"]=="all"){
while ($file = readdir($dir_handle)){
if (!is_dir($file)) {if($file=="." || $file == "..") continue;$file_parts = explode(".",$file);if (end($file_parts)=="txt"){
$title = implode(".",$file_parts);$title = htmlspecialchars($title);$nome_arquivo[$contador]["arquivo"] =$datos_directory.$title;$datos_arquivo = file($nome_arquivo[$contador]["arquivo"]);
$nome_arquivo[$contador]["autor"]=$datos_arquivo[0];$nome_arquivo[$contador]["palabra"]=$datos_arquivo[1];$nome_arquivo[$contador]["url"]=$datos_arquivo[2];$nome_arquivo[$contador]["arquiIma"]=$datos_arquivo[17];
$totalArray=count($datos_arquivo);for ( $i = 19 ; $i <= $totalArray ; $i ++) {$textoCom=$textoCom.$datos_arquivo[$i];}
$nome_arquivo[$contador]["describe"]=$textoCom;$nome_arquivo[$contador]["txt"]=$title;$contador++;$textoCom="";}}}
if ($contador>0){
foreach ($nome_arquivo as $llave => $fila){$autor_[$llave]=$fila["autor"];$palabra_[$llave]=normaliza($fila["palabra"]);
$url_[$llave]=$fila["url"];$arquiIma[$llave]=$fila["arquiIma"];$txt[$llave]=$fila["txt"];}
$palabra_maius = array_map("strtolower", $palabra_);array_multisort($palabra_maius,SORT_ASC,SORT_STRING,  $nome_arquivo);
unset($palabra_,$autor_,$comentario_,$data_,$palabra_maius);$contador=0;$dataNew = array();
$i=0;
foreach ($nome_arquivo as $llave=> $fila){$autor=$fila["autor"];$palabra=$fila["palabra"];$url=$fila["url"];
$arquiIma=$fila["arquiIma"];$describe=$fila["describe"];$txt=$fila["txt"]; $nome = explode(".", $txt); $pos= strripos($nome[0],"_")+1;$idP = substr($nome[0],$pos,4);
$dataS=array("i"=>$i++, "word"=>$palabra,"url"=>$url,"author"=>$autor,"srcIma"=>$arquiIma, "txt"=>$txt,"describe" => substr($describe,0,35),"idP"=>$idP);array_push($dataNew ,$dataS);}}else{$dataNew=array();}echo json_encode($dataNew);}
if($_POST["action"]=="deleteItem"){$indi=$_POST["item"];$indi=(int)$indi;$indi=$indi-1;$nomeArquivo=$_POST["author"]."_".$indi;
$pathTXT = "../ardoraWorkFiles/computertime/";$pathImages ="../ardoraWorkFiles/computertime/img/original/";$pathThumb ="../ardoraWorkFiles/computertime/img/thumbs/";
$datos_arquivo = file($pathTXT.$nomeArquivo.".txt");$nomeThumb=trim($datos_arquivo[4]);$ima1=$pathImages.$nomeThumb;$ima2=$pathThumb.$nomeThumb;$txt1=$pathTXT.$nomeArquivo.".txt";
$old = getcwd();chdir($pathImages);chown($nomeThumb,666);unlink($nomeThumb);chdir($old);
chdir($pathThumb);chown($nomeThumb,666);unlink($nomeThumb);chdir($old);unlink($txt1);
$file = simplexml_load_file("../ardoraWorkFiles/computertime/computertime.xml");
foreach ($file->event as $event) {if ($event["id"]==$nomeArquivo){$dom=dom_import_simplexml($event);$dom->parentNode->removeChild($dom);}}
$file->asXML("../ardoraWorkFiles/computertime/computertime.xml");
}
if ($_POST["action"] == "getDataUser") {$autor = trim($_POST["author"]);$type=dameValor($autor, "TIP");$userName=dameValor($autor, "NOM");
$course=dameValor($autor, "CUR");$group=dameValor($autor, "GRU");echo json_encode(array("type"=>$type, "userName"=>$userName, "course"=>$course, "group"=>$group));}
closedir($dir_handle);
?>
