// -----------------------------------------------------------------------------
// - Fonctions de demandes d'informations et de remplissage des zones de saisies
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
function tools_ConvertDataToSelect(strData) {
// * Remplissage de la boîte de sélection depuis les données disponible
// * au format : A(1) , B(1) | A(2) , B(2) | ... | A(n) , B(n)
// variable utile
var strContentData = "";
// récupération des données depuis le module externe
if (strData != "" && strData != "-") {
// préparation des expressions régulières
var regCellule = new RegExp("[|]+", "g");
var regCelluleInterne = new RegExp("[,]+", "g");
// convertion en tableau des éléments
var arrayDatas = strData.split(regCellule);
// affichage des éléments
for (var i = 0; i < arrayDatas.length; i++) {
// convertion de la cellule courante en tableau
var arrayCell = arrayDatas[i].split(regCelluleInterne);
// affichage des données
if (arrayCell[0] != "" && arrayCell[1] != undefined)
strContentData += "";
}
} // fin si : choix d'une ou plusieurs centrales
// retour de la convertion
return strContentData;
} // fin de la fonction tools_ConvertDataToSelect(str)
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// - Fonctions de service AJAX
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
function ajax_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 les objets XMLHTTPRequest...");
xhr = false;
}
return xhr;
} // fin de la fonction ajax_getXhr()
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
function ajax_OnSubmit(strUrlScript, strUserArguments, funcCallBack, funcCallBackArgObj, funcCallBackArgObjName) {
// * Foncion de rappel lors de l'envoi du formulaire
// vérification d'usage
if (strUserArguments == null || strUserArguments == "") {
alert("Error response with arguments!");
return;
}
// récupération du moteur ajax
var xhr = ajax_getXhr();
// fonction de retour en cas de réussite de la procédure
xhr.onreadystatechange = function() {
if (xhr.readyState == 4)
funcCallBack(funcCallBackArgObj, funcCallBackArgObjName, xhr.responseText);
};
// debug
//alert("url = " + strUrlScript + "\nargument = " + strUserArguments);
// Envoi du formulaire en POST
xhr.open("POST", strUrlScript, true);
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xhr.send(strUserArguments);
// retour de la réponse
return ;
} // fin de la fonction ajax_OnSubmit(str, str)
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// - Fonctions de demandes d'informations et de remplissage des zones de saisies
// -----------------------------------------------------------------------------
// * les prestations
// -----------------------------------------------------------------------------
function ajax_getPrestation(objCallBackFunc, objForm, strFormName, strCentralName) {
// * Récupération des informations sur les prestations de la centrale
return ajax_OnSubmit("portail3v/portail/ajax/getPrestations.ajax.php", "cen=" + strCentralName, objCallBackFunc, objForm, strFormName);
} // fin de la fonction ajax_getPrestation(str)
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
function ajax_displayPrestation(objSelectPrestation, strNameForm, strData) {
// * Remplissage de la boîte de sélection de la prestation
// * format d'affichage : [code prestation , nom prestation] | ... | [code prestation(n) , nom prestation(n) ]
// Contenu à insérer dans la boîte de sélection
var strContent = "";
// affichage du contenu de la boîte de sélection
objSelectPrestation.innerHTML = strContent;
} // fin de la fonction ajax_displayPrestation(obj, str)
// -----------------------------------------------------------------------------
// * les dates : mois
// -----------------------------------------------------------------------------
function ajax_getMonthAvailable(objCallBackFunc, objForm, strFormName, strCentralName, strPrestationName) {
// * Récupération des informations sur les prestations de la centrale
return ajax_OnSubmit("portail3v/portail/ajax/getDatesConfig.ajax.php", "cen=" + strCentralName + "&prest=" + strPrestationName, objCallBackFunc, objForm, strFormName);
} // fin de la fonction ajax_getMonthAvailable(str)
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
function ajax_displayMonth(objSelectPrestation, strNameForm, strData) {
// * Remplissage de la boîte de sélection des mois disponibles
// * format d'affichage : [mois format mm/aaaa, mois affichable] | ... | [mois format mm/aaaa(n), mois affichable(n)]
// Contenu à insérer dans la boîte de sélection
var strContent = "";
// affichage du contenu de la boîte de sélection
objSelectPrestation.innerHTML = strContent;
} // fin de la fonction ajax_displayMonth(obj, str)
// -----------------------------------------------------------------------------
// * les dates : Jour
// -----------------------------------------------------------------------------
function ajax_getDayAvailable(objCallBackFunc, objForm, strFormName, strCentralName, strPrestationName, strMonth) {
// * Récupération des informations sur les prestations de la centrale
return ajax_OnSubmit("portail3v/portail/ajax/getDatesConfig.ajax.php", "cen=" + strCentralName + "&prest=" + strPrestationName + "&month=" + strMonth, objCallBackFunc, objForm, strFormName);
} // fin de la fonction ajax_getDayAvailable(str)
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
function ajax_displayDay(objSelectPrestation, strNameForm, strData) {
// * Remplissage de la boîte de sélection des mois disponibles
// * format d'affichage : [numéro jour , jour affichable] | ... | [numéro jour(n) , jour affichable(n)]
// Contenu à insérer dans la boîte de sélection
var strContent = "";
// affichage du contenu de la boîte de sélection
objSelectPrestation.innerHTML = strContent;
} // fin de la fonction ajax_displayDay(obj, str)
// -----------------------------------------------------------------------------
// * les dates : Durées de séjour
// -----------------------------------------------------------------------------
function ajax_getDuringStayAvailable(objCallBackFunc, objForm, strFormName, strCentralName, strPrestationName, strDay, strMonth) {
// * Récupération des informations sur les prestations de la centrale
// convertion des espaces en +
strDay = strDay.replace(" ", "+");
strMonth = strMonth.replace(" ", "+");
// execution du moteur ajax
return ajax_OnSubmit("portail3v/portail/ajax/getDatesConfig.ajax.php", "cen=" + strCentralName + "&prest=" + strPrestationName + "&daytime=" + strDay + "&monthtime=" + strMonth, objCallBackFunc, objForm, strFormName);
} // fin de la fonction ajax_getDuringStayAvailable(str)
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
function ajax_displayDuringStay(objSelectPrestation, strNameForm, strData) {
// * Remplissage de la boîte de sélection des mois disponibles
// * format d'affichage : [durée , durée humaine] | ... | [durée(n) | durée humaine(n)]
// Contenu à insérer dans la boîte de sélection
var strContent = "";
// affichage du contenu de la boîte de sélection
objSelectPrestation.innerHTML = strContent;
} // fin de la fonction ajax_displayDuringStay(obj, str)
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// - Fonctions accesseurs
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
function changeCentrale(iFCT_ChangeLevel) {
// * fonction de changement de centrale
// * strFormName détermine le nom du champ du formulaire
// * iFCT_ChangeLevel détermine le niveau de changement
// * 1 => à partir de la centrale
// * 2 => à partir de la prestation
// * 3 => à partir du mois
// * 4 => à partir du jour
// détermination des noms des champs du formulaire
var strFormCentrale = "station";
var strFormPrestation = "typ_id";
var strFormMonth = "dtdebut_mois";
var strFormDay = "dtdebut_jour";
var strFormDuringStay = "dtdebut_duree";
// récupération des zones de sélection du formulaire
var objDivCentrale = document.getElementById("Portail3v_DivCentral");
var objDivPrestation = document.getElementById("Portail3v_DivPrestation");
var objDivMonth = document.getElementById("Portail3v_DivMonth");
var objDivDay = document.getElementById("Portail3v_DivDay");
var objDivDuringStay = document.getElementById("Portail3v_DivDuringStay");
// récupération des objets Select
var objSelectCentrale = document.getElementById("Portail3v_SelectCentral");
var objSelectPrestation = document.getElementById("Portail3v_SelectPrestation");
var objSelectMonth = document.getElementById("Portail3v_SelectMonth");
var objSelectDay = document.getElementById("Portail3v_SelectDay");
var objSelectDuringStay = document.getElementById("Portail3v_SelectDuringStay");
// récupération de la centrale à prendre en compte
var strCentralName = objSelectCentrale.options[objSelectCentrale.selectedIndex].innerHTML;
var iCentralId = objSelectCentrale.options[objSelectCentrale.selectedIndex].value;
// récupération de la prestation à prendre en compte
var strPrestationName = objSelectPrestation.options[objSelectPrestation.selectedIndex].innerHTML;
var iPrestationId = objSelectPrestation.options[objSelectPrestation.selectedIndex].value;
// récupération du mois à prendre en compte
var strMonth = objSelectMonth.options[objSelectMonth.selectedIndex].innerHTML;
var iMonthId = objSelectMonth.options[objSelectMonth.selectedIndex].value;
// récupération du jour à prendre en compte
var strDay = objSelectDay.options[objSelectDay.selectedIndex].innerHTML;
var iDayId = objSelectDay.options[objSelectDay.selectedIndex].value;
// changement dans le formulaire globale
switch(strCentralName) {
case "Station":
// plus de choix choisi !
ajax_displayPrestation(objDivPrestation, strFormPrestation, "-");
ajax_displayMonth(objDivMonth, strFormMonth, "-");
ajax_displayDay(objDivDay, strFormDay, "-");
ajax_displayDuringStay(objDivDuringStay, strFormDuringStay, "-");
break;
case "Indifférent":
default:
// * toutes les centrales ou choix d'une centrale
// Changement de prestation
if (iFCT_ChangeLevel < 2) {
//alert(iCentralId);
ajax_getPrestation(ajax_displayPrestation, objDivPrestation, strFormPrestation, iCentralId);
ajax_displayMonth(objDivMonth, strFormMonth, "-");
ajax_displayDay(objDivDay, strFormDay, "-");
ajax_displayDuringStay(objDivDuringStay, strFormDuringStay, "-");
}
// changement de mois
if (iFCT_ChangeLevel < 3) {
ajax_getMonthAvailable(ajax_displayMonth, objDivMonth, strFormMonth, iCentralId, iPrestationId);
ajax_displayDay(objDivDay, strFormDay, "-");
ajax_displayDuringStay(objDivDuringStay, strFormDuringStay, "-");
}
// changement de jour (uniquement lorsque le mois est choisi)
if (iFCT_ChangeLevel == 3) {
ajax_getDayAvailable(ajax_displayDay, objDivDay, strFormDay, iCentralId, strPrestationName, strMonth);
ajax_displayDuringStay(objDivDuringStay, strFormDuringStay, "-");
}
// changement des durées
if (iFCT_ChangeLevel == 4) {
ajax_getDuringStayAvailable(ajax_displayDuringStay, objDivDuringStay, strFormDuringStay, iCentralId, strPrestationName, strDay, strMonth);
}
} // fin switch
} // fin de la fonction changeCentrale()
// -----------------------------------------------------------------------------