środa, 12 listopada 2008

Javascript+AJAX


function ajaxFunc(step,param1)
{
var http_request;
var params;
try // Firefox, Opera 8.0+, Safari
{
http_request=new XMLHttpRequest();
}
catch (e){ // Internet Explorer
try{
http_request=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try {
http_request=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("Twoja przeglÄ_darka nie wspiera AJAX!!");
return false;
}
}
}

if (typeof http_request != "undefined") {
if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); }
//http_request.open("POST","inc/lektor.php",true);
(step<5) ? http_request.open("POST","inc/lektor.php",true) : http_request.open("POST","inc/katpliki.php",true); http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded;"); switch (step) { case 1 : { //utworzenie pliku tekstowego var opis=""; if (document.getElementById("opisread")) { opis=document.getElementById("opisread").value; } params="act=gen&opis="+opis; http_request.send(params); http_request.onreadystatechange=function() { if (http_request.readyState==4 && http_request.status==200) { status = document.getElementById("generator_status"); if (http_request.responseText.length>1)
{
if (parseInt(http_request.responseText[0])==0) {
status.innerHTML=http_request.responseText.substring(2); }
}
else {
if (parseInt(http_request.responseText[0])==1) { status.innerHTML="Utworzono plik tekstowy"; }
}
}
}
} break;

case 2 : { //wywolanie generatora
//filename="lektor.wav";
filename=CreateFileName("autorid","tytulid")+".mp3";
params="act=wav&file="+filename;
http_request.send(params);
status = document.getElementById("generator_status");
status.innerHTML='wywolanie generatora';
http_request.onreadystatechange=function()
{
if (http_request.readyState==4 && http_request.status==200) {
status = document.getElementById("generator_status");
if (http_request.responseText.length>1)
{
//alert(http_request.responseText);
if (parseInt(http_request.responseText[0])==0) {
status.innerHTML="WystÄ_pi__ b__Ä_d przy tworzeniu pliku mp3"; }
}
else { //alert(http_request.responseText);
if (parseInt(http_request.responseText[0])==1) {
status.innerHTML="rozpoczÄ_to tworzenie pliku";
}
}
} //alert( http_request.readyState+" "+http_request.status);
}
} break;

case 3 : {
//filename="lektor.wav";
filename=CreateFileName("autorid","tytulid")+".mp3";
params="act=mp3&file="+filename;
http_request.send(params);
http_request.onreadystatechange=function()
{
if (http_request.readyState==4 && http_request.status==200) {
status = document.getElementById("generator_status");
statusid =document.getElementsByName("statusid");
//alert(statusid[0].value);
//alert("jesten kod= "+http_request.responseText[0]);
switch (parseInt(http_request.responseText[0])) {
case 0: {
status.innerHTML="tworzenie pliku lektora ...";
statusid[0].setAttribute('value','0');
idtime=setTimeout('ajaxFunc(3)',5000);
if (document.getElementById("timerid2")) document.getElementById("timerid2").value=idtime;
} break;
case -1 : {
statusid[0].setAttribute('value','0');
idtime=setTimeout('ajaxFunc(3)',5000);
if (document.getElementById("timerid2")) document.getElementById("timerid2").value=idtime;
} break; //brak jessze pliku;
case 1: {
status.innerHTML="Utworzono plik lektora!!!"; statusid[0].setAttribute('value','1');
// progress stop //
if (document.getElementById("timerid1")) {
timeid=document.getElementById("timerid1").value;
progress(false,1,31,50,timeid);
}
if (document.getElementById("timerid2")) {
timeid=document.getElementById("timerid2").value;
clearTimeout(timeid);
}

//--stop progress --//
var filepath="..////pliki//temp//"+filename;
//alert(filepath);
var html=Mp3Player(filepath,"");
if (document.getElementById("playlektor")) document.getElementById("playlektor").innerHTML=html;
if (document.getElementById("blektorprzypisz")) document.getElementById("blektorprzypisz").style.visibility="visible";
if (document.getElementById("filelektor")) document.getElementById("filelektor").value=filename;

} break;
}

} //else alert(http_request.readyState+" "+http_request.status);
}

} break;

case 4 : {
if (document.getElementById("filelektor")) filename = document.getElementById("filelektor").value;
params="act=move&file="+filename;
http_request.send(params);
http_request.onreadystatechange=function() {
if (http_request.readyState==4 && http_request.status==200) {
//alert(http_request.responseText);
status = document.getElementById("generator_status");
if (http_request.responseText.length>0)
{
if (parseInt(http_request.responseText[0])==0) {
status.innerHTML="WystÄ_pi__ b__Ä_d przy kopiowaniu pliku mp3";
}
else {
if (parseInt(http_request.responseText[0])==1) {
status.innerHTML="Przypisano plik lektora";
}
}
// progress stop //
if (document.getElementById("timerid1")) {
timeid=document.getElementById("timerid1").value;
progress(false,1,31,50,timeid);
}
}

//Schowanie przyciskow niepotrzebnych
if (document.getElementById("blektorprzypisz")) document.getElementById("blektorprzypisz").style.visibility="hidden";
if (document.getElementById("playlektor")) document.getElementById("playlektor").innerHTML="";
}
}
} break;

case 5 : { //Odczyt listy plikow rysunkow z katalogu kategorii
params="path="+param1;
http_request.send(params);
http_request.onreadystatechange=function()
{
if (http_request.readyState==4 && http_request.status==200) {
if (http_request.responseText.length>0)
{
if (document.getElementById("kategoriepic")) {
var divpicall= document.getElementById("kategoriepic");
var lista = new Array();
var plik = new Array();
var html='';
lista = http_request.responseText.split('\n');
for (var i=0;i
";
html+="";
html+="
";
}
divpicall.innerHTML=html;
}
}
}
}
} break;
}

}
}

Brak komentarzy:

Prześlij komentarz