/* ------------------------------ */ /* - Méthodes pour afficher les */ /* - résultats d'un forumlaire */ /* ------------------------------ */ var xmlDoc; var tableInputIdPage; var tableInputDiv; var tableInputAdmin; var tableInputFile; function tableInputInit(idPage , file , div , admin ) { tableInputIdPage = idPage; tableInputDiv = div; tableInputAdmin = admin; tableInputFile = file; tableInputImportXML(); } function tableInputImportXML() { if (document.implementation && document.implementation.createDocument) { xmlDoc = document.implementation.createDocument("", "doc", null); xmlDoc.onload = tableInputCreateTable; if( tableInputAdmin ) xmlDoc.onload = tableInputGetListePages; } else if (window.ActiveXObject) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); } else { alert("Votre navigateur ne supporte pas ce script"); return; } xmlDoc.onreadystatechange = function () { if (xmlDoc.readyState == 4) { tableInputCreateTable( ); if( tableInputAdmin ) tableInputGetListePages(); } }; xmlDoc.load( tableInputFile ); } function leftFill(num) { num = parseInt(num); return "" + ((num < 10) ? "0" : "") + num; } function tableInputCreateTable( ) { // Récupère la liste des LIGNES var ndConfig2 = document.getElementsByTagName('INPUT'); var ndConfig = xmlDoc.getElementsByTagName('CONFIG' + tableInputIdPage ); var ndLine = xmlDoc.getElementsByTagName('LINE' + tableInputIdPage ); // On crée la table var newEl = document.createElement('TABLE'); // newEl.setAttribute('cellPadding',5); var tmp = document.createElement('TBODY'); newEl.appendChild(tmp); // Si y'a des inputs if( ndConfig.length > 0 ) { // On crée le tableau ordonée var tab = new Array(); for ( var i = 0 ; i < ndConfig.length ; i++ ) { var champs = ndConfig[i].getElementsByTagName("CHAMP"); for( var j = 0 ; j < champs.length ; j++ ) { var id = champs[j].getAttribute( "id"); var ordre = leftFill( champs[j].getAttribute( "ordre" ) ); var nom = champs[j].getAttribute("nom") ; var size = champs[j].getAttribute("size") ; tab[ tab.length ] = ordre + "~" + size + "~" + id + "~" + nom; } } // Trie le tableau tab.sort(); // Supprime le ~ var reg = new RegExp("[~]+", "g"); // On crée la ligne de titre et on supprime les infos inutiles var row = document.createElement('TR'); for ( var j = 0 ; j < tab.length ; j++ ) { // Split var tabTmp = tab[j].split( reg ); // Met à jout le tableau tab[j] = tabTmp[2]; // Crée le th var container = document.createElement('TH'); container.appendChild( document.createTextNode( tabTmp[3] ) ); // Paramètre container.setAttribute('width' , tabTmp[1] ); row.appendChild(container); } tmp.appendChild(row); // Pour chaque ligne, for ( var i = 0 ; i < ndLine.length ; i++) { // On n'affiche pas les "invisibles" if( ndLine[i].getAttribute('visible') != "1" ) continue; // On crée la ligne var row = document.createElement('TR'); for ( var j = 0 ; j < tab.length ; j++) { // On recherche les noeuds tab[j] var attr = ndLine[i].getElementsByTagName( tab[j] ); // On crée une cellule de la table var container = document.createElement('TD'); // On lui attribue sa valeur if( attr.length == 1 && attr[0].childNodes.length > 0) container.appendChild( document.createTextNode( stripslashes( attr[0].childNodes[0].nodeValue ) ) ); else container.appendChild( document.createTextNode( '' ) ); row.appendChild(container); } tmp.appendChild(row); } } // On dessine le tableau document.getElementById( tableInputDiv ).innerHTML = ' '; document.getElementById( tableInputDiv ).appendChild(newEl); } /* ------------------------------ */ /* - Méthodes pour valider un */ /* - forumlaire */ /* ------------------------------ */ function getXhr(){ var xhr = null; if(window.XMLHttpRequest) // Firefox et autres xhr = new XMLHttpRequest(); else if(window.ActiveXObject){ // Internet Explorer try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } } else { // XMLHttpRequest non supporté par le navigateur alert("Votre navigateur ne supporte pas l'AJAX, la wishList ne sera pas enregistrée"); xhr = false; } return xhr } function submitForm( idPage ) { var aPoster = ""; var aPosterValue = new Array(); // Recherche tous les inputs var inputs = document.getElementsByTagName( 'INPUT' ); for ( var i = 0 ; i < inputs.length ; i++ ) { // Si c'est un text var type = inputs[i].getAttribute('type'); if( !type || type == 'text' ) aPoster += inputs[i].getAttribute('name') + '='+ escape(inputs[i].value) + "&"; } // Rebelote pour les textarea var textareas = document.getElementsByTagName( 'TEXTAREA' ); for ( var i = 0 ; i < textareas.length ; i++ ) aPoster += textareas[i].getAttribute('name') + '='+ escape(textareas[i].value) + "&"; // On envoi par ajax var xhr = getXhr() xhr.onreadystatechange = function(){ if ( xhr.readyState == 4 && xhr.status == 200 ){ var txtServ = xhr.responseText; if ( txtServ != '' ) { eval( txtServ ); } else alert("Erreur le serveur n'a pas répondu"); } } xhr.open("POST", "./pages/submitForm.php?idPage=" + idPage , true ) ; xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send( aPoster ); } function stripslashes( txt ){ txt = txt.replace(/\\"/g,'"'); return txt.replace(/\\'/g,"'"); }