1/*licence/ 2 3Module écrit, supporté par la société Alkante SAS <[email protected]> 4 5Nom du module : Alkanet::Library 6Librairie js et php globale à Alkanet. 7Ce module appartient au framework Alkanet. 8 9Ce logiciel est régi par la licence CeCILL-C soumise au droit français et 10respectant les principes de diffusion des logiciels libres. Vous pouvez 11utiliser, modifier et/ou redistribuer ce programme sous les conditions 12de la licence CeCILL-C telle que diffusée par le CEA, le CNRS et l'INRIA 13sur le site http://www.cecill.info. 14 15En contrepartie de l'accessibilité au code source et des droits de copie, 16de modification et de redistribution accordés par cette licence, il n'est 17offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, 18seule une responsabilité restreinte pèse sur l'auteur du programme, le 19titulaire des droits patrimoniaux et les concédants successifs. 20 21A cet égard l'attention de l'utilisateur est attirée sur les risques 22associés au chargement, à l'utilisation, à la modification et/ou au 23développement et à la reproduction du logiciel par l'utilisateur étant 24donné sa spécificité de logiciel libre, qui peut le rendre complexe à 25manipuler et qui le réserve donc à des développeurs et des professionnels 26avertis possédant des connaissances informatiques approfondies. Les 27utilisateurs sont donc invités à charger et tester l'adéquation du 28logiciel à leurs besoins dans des conditions permettant d'assurer la 29sécurité de leurs systèmes et ou de leurs données et, plus généralement, 30à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. 31 32Le fait que vous puissiez accéder à cet en-tête signifie que vous avez 33pris connaissance de la licence CeCILL-C, et que vous en avez accepté les 34termes. 35 36/licence*/ 37 38 verStr = navigator.appVersion; 39app = navigator.appName; 40version = parseFloat(verStr); 41if( (app.indexOf('Netscape') != -1)&&(version <= 4.75) ) { 42 // alert('netscape <= 4,75'); 43 var navigateur = "ecrit"; 44} 45navigateur = navigator.appName; 46x = null; 47y = null; 48 49var ALK_GT_START = ""; 50var ALK_GT_END = ""; 51 52/** 53 * @brief Définition de document.getElementById si n'existe pas 54 */ 55if (!document.getElementById){ 56 function _getElementById(elt_id) 57 { 58 var oElt = null; 59 if ( document.getElementById && document.getElementById( elt_id ) ) {// Pour les navigateurs récents 60 oElt = document.getElementById( elt_id ); 61 } 62 else if ( document.all && document.all[ elt_id ] ) {// Pour les veilles versions 63 oElt = document.all[ elt_id ]; 64 } 65 else if ( document.layers && document.layers[ elt_id ] ) {// Pour les très veilles versions 66 oElt = document.layers[ elt_id ]; 67 } 68 return oElt; 69 } 70 document.getElementById = _getElementById; 71} 72 73/** 74 * Fonction qui ne fait rien (NothingToDo NTD), à appeler dans le href au lieu de # 75 */ 76function ntd() 77{ 78 79} 80 81/** 82 * Fonction de formatage avec le joker %s équivalente à la fonction php 83 * Retourne la chaine texte en remplaçant les jokers par leur valeur passée en paramètre 84 * @param strText texte à transformer 85 * @param optionnels valeurs de jokers à remplacer dans strText 86 * @return string 87 */ 88function sprintf(strText) 89{ 90 var arg = arguments; 91 var i = 1; 92 return strText.replace(/%((%)|s)/g, function (m) { return m[2] || arg[i++] }); 93} 94 95/** 96 * Retourne la traduction correspondant à la clé fournie 97 * Si la traduction n'existe pas, retourne la clé 98 * @param strKey clé de la chaine à traduire 99 * @return string 100 */ 101function _gt(strKey) 102{ 103 var idInterface = typeof ALK_LG_ID_INTERFACE === 'undefined' ? 0 : ALK_LG_ID_INTERFACE; 104 var strRes = strKey; 105 //oAlkTranslate est défini en chargeant le fichier locales_js.json correspondant à la locale sélectionnée 106 if( typeof(oAlkTranslate)!="undefined" && oAlkTranslate[strKey] && oAlkTranslate[strKey]!="") { 107 strRes = oAlkTranslate[strKey]; 108 } 109 // tabAlkTranslate est défini en chargeant le fichier locales_js.json correspondant à toutes les locales sélectionnées 110 // la langue sélectionnée est donnée par ALK_LG_ID_DATA chargé par lib_js.php 111 else if( typeof(tabAlkTranslate)!="undefined" ) { 112 if( typeof(tabAlkTranslate[idInterface][strKey])!="undefined" && tabAlkTranslate[idInterface][strKey]!="" ) { 113 strRes = tabAlkTranslate[idInterface][strKey]; 114 } else if( idInterface != 0 && typeof(tabAlkTranslate[0][strKey])!="undefined" && tabAlkTranslate[0][strKey]!="") { 115 strRes = tabAlkTranslate[0][strKey]; 116 } 117 } 118 return ALK_GT_START+strRes+ALK_GT_END; 119} 120 121/** 122 * Alias de fonction équivalente à sprintf(_gt(strKey), param1, param2, ..., paramN) 123 * Retourne la traduction correspondant à la clé fournie 124 * Si la traduction n'existe pas, retourne la clé 125 * @param strKey clé de la chaine à traduire 126 * @return string 127 */ 128function _gtf(strKey) 129{ 130 var arg = arguments; 131 var tabArgs = Array.prototype.slice.call(arguments, 1); 132 var strRes = _gt(strKey); 133 strRes = strRes.replace("%nl", "%s");
134 strRes = sprintf.apply(this, [strRes].concat(tabArgs)); 135 136 return strRes; 137} 138 139/** 140 * Retourne la traduction conditionnée par le nombre pour gérer le singulier et le pluriel 141 * Si la traduction n'est pas trouvée, retourne la clé en fonction du nombre 142 * @param strKeyS clé identifiant la chaine au singulier 143 * @param strKeyP clé identifiant la chaine au plurier 144 * @param nb nombre 145 * @return string 146 */ 147function _ngt(strKeyS, strKeyP, nb) 148{ 149 var strKey = ( nb > 1 ? strKeyP : strKeyS ); 150 var strRes = strKey; 151 var idInterface = typeof ALK_LG_ID_INTERFACE === 'undefined' ? 0 : ALK_LG_ID_INTERFACE; 152 //oAlkTranslate est défini en chargeant le fichier locales_js.json correspondant à la locale sélectionnée 153 if( typeof(oAlkTranslate)!="undefined" && oAlkTranslate && oAlkTranslate[strKey] && oAlkTranslate[strKey]!="") { 154 strRes = oAlkTranslate[strKey]; 155 } 156 // tabAlkTranslate est défini en chargeant le fichier locales_js.json correspondant à toutes les locales sélectionnées 157 // la langue sélectionnée est donnée par ALK_LG_ID_DATA chargé par lib_js.php 158 else if( typeof(tabAlkTranslate)!="undefined" ) { 159 if( typeof(tabAlkTranslate[idInterface][strKey])!="undefined" && tabAlkTranslate[idInterface][strKey]!="" ) { 160 strRes = tabAlkTranslate[idInterface][strKey]; 161 } else if( idInterface != 0 && typeof(tabAlkTranslate[0][strKey])!="undefined" && tabAlkTranslate[0][strKey]!="") { 162 strRes = tabAlkTranslate[0][strKey]; 163 } 164 } 165 166 return ALK_GT_START+strRes+ALK_GT_END; 167} 168 169/** 170 * Alias de fonction équivalente à sprintf(_ngt(strKeyS, strKeyP, nb), param1, param2, ..., paramN) 171 * Si la traduction n'est pas trouvée, retourne la clé en fonction du nombre 172 * @param strKeyS clé identifiant la chaine au singulier 173 * @param strKeyP clé identifiant la chaine au plurier 174 * @param nb nombre 175 * @return string 176 */ 177function _ngtf(strKeyS, strKeyP, nb) 178{ 179 var arg = arguments; 180 var tabArgs = Array.prototype.slice.call(arguments, 3); 181 if( tabArgs.length == 0 ) { 182 tabArgs[0] = nb; 183 } 184 var strRes = _ngt(strKeyS, strKeyP, nb); 185 strRes = strRes.replace("%nl", "%s"); 186 strRes = sprintf.apply(this, [strRes].concat(tabArgs)); 187 188 return strRes; 189} 190 191/** 192 * @brief Fonctions diverses 193 */ 194function position(e) { 195 var nH2, h2, v; 196 x = (navigator.appName.substring(0,3) == "Net") ? e.pageX : event.x; //+document.body.scrollLeft; 197 y = (navigator.appName.substring(0,3) == "Net") ? e.pageY : event.y; //+document.body.sc 198} 199function MM_reloadPage(init) { //reloads the window if Nav4 resized 200 if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) { 201 document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }} 202 else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload(); 203} 204MM_reloadPage(true); 205function MM_findObj(n, d) { //v4.01 206 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { 207 d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} 208 if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; 209 for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); 210 if(!x && d.getElementById) x=d.getElementById(n); return x; 211} 212function MM_showHideLayers() { //v3.0 213 var i,p,v,obj,args=MM_showHideLayers.arguments; 214 for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2]; 215 if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; } 216 obj.visibility=v; } 217} 218function MM_swapImgRestore() { //v3.0 219 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; 220} 221function MM_preloadImages() { //v3.0 222 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); 223 var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) 224 if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} 225} 226function MM_swapImage() { //v3.0 227 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) 228 if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} 229} 230 231/** 232 * Affiche un message en popup 233 * @param strMsg message à afficher 234 */ 235function alkAlert(strMsg) 236{ 237 if( alert ) { 238 alert(strMsg); 239 } 240} 241 242/** 243 * Affiche une popup de confirmation 244 * @param strMsg message à afficher demandant une confirmation 245 * @return bool 246 */ 247function alkConfirm(strMsg) 248{ 249 // affiche le message avec une fenêtre modal 250 // Le navigateur Chrome affiche une fenêtre non modal => affiche le message de confirmation par défaut 251// if ( navigator.userAgent.toLowerCase().indexOf('chrome') == -1 && window.showModalDialog ) { 252// var strToken = TextEncode("cont_id="+ALK_CONT_ID+"&appli_id=-1&iTypeSheet="+ALK_TYPESHEET_POPUP+"&iSheet="+ALK_SHEET_CONFIRM_RESA); 253// var res = window.showModalDialog(ALK_ALKANET+'?token='+strToken, {pageTitle : window.document.title, msgTitle : _gt("Confirmation"), msgContent : strMsg}, "dialogWidth:500px;dialogHeight:150px;status:no;unadorned:yes;"); 254// return ( res == 1 ); 255// } 256// // affiche le message avec la méthode de confirmation du navigateur 257// else { 258 return window.confirm(strMsg); 259// } 260} 261 262/** Mémorise le niveau de la dernière popup ouverte, =0 pas de popup ouverte */ 263var iLevelAlkPopup = 0; 264 265/** 266 * @brief Retourne la référence de la fenêtre popup de niveau iLevel 267 * @param iLevel Niveau de la popup 268 * @return Retourne la référence sur la fenêtre de niveau iLevel 269 */ 270function GetWindowByNiv(iLevel) 271{ 272 if( iLevel <=0 ) { 273 return window; 274 } 275 return top.window.document.getElementById("alkIFrameNiv"+iLevel.toString()).contentWindow; 276} 277 278/** 279 * @brief Création d'une popup de niveau iLevel 280 * @param iLevel Niveau de la popup =1 pour la première 281 * @return Retourne une référence sur le layer caractérisant la popup 282 */ 283function addPopup(iLevel) 284{ 285 var oWind = top.window; 286 var oPopup = oWind.document.createElement("div"); 287 if( oPopup ) { 288 oPopup.id = "alkPopupNiv"+iLevel; 289 oPopup.className = "windPopupNiv"+iLevel; 290 oPopup.iAlkLevel = iLevel; 291 var oStyle = ( oPopup.style ? oPopup.style : oPopup ); 292 oStyle.zIndex = 20000+(iLevel*2); 293 // scrollHeight fonctionne : ie6, ie7 et firefox 294 oStyle.height = top.document.documentElement.scrollHeight+"px"; 295 oWind.document.body.appendChild(oPopup); 296 return oPopup; 297 } 298 return null; 299} 300 301/** 302 * @brief Ferme la dernière popup ouverte 303 * @param strUrlToken url de réaffichage de l'opener. 304 * si la chaine ne contient pas .php, le paramètre est considéré comme un token 305 * sur l'url alkanet.php 306 * si la chaine = reload, un reload est effectué sur l'opener 307 */ 308function removePopup(strUrlToken) 309{ 310 var bClose = false;
311 var iLevel = top.iLevelAlkPopup; 312 var oOpenerIFrame = null; 313 var iLevelNext = 0; 314 var oPopup = top.document.getElementById("alkPopupNiv"+iLevel.toString()); 315 if( oPopup ) { 316 // reaffiche l'opener si le tokenClose ou l'url sont fournis 317 if( typeof(strUrlToken)!="undefined" && strUrlToken != "" ) { 318 var iLevelOpener = iLevel-1; 319 oOpenerIFrame = top.window; 320 if( iLevelOpener >= 1 ) { 321 oOpenerIFrame = top.document.getElementById("alkIFrameNiv"+iLevelOpener.toString()); 322 } 323 324 // le paramètre &r=1 est présent pour éviter l'utilisation du cache navigateur 325 if( strUrlToken == "reload" && oOpenerIFrame==top.window ) { 326 oOpenerIFrame.location.reload(); 327 } else { 328 var strUrl = ( strUrlToken.indexOf(".php")>-1 329 ? strUrlToken+(strUrlToken.substr(-4)==".php" ? "?" : "&")+"rndm="+Math.random() 330 : ( isToken(strUrlToken) 331 ? ALK_ALKANET_EXTRA+"?token="+strUrlToken+"&rndm="+Math.random() 332 : strUrlToken )); 333 if( oOpenerIFrame==top.window ) { 334 oOpenerIFrame.location = strUrl; 335 } else { 336 oOpenerIFrame.src = strUrl; 337 } 338 } 339 } 340 341 top.iLevelAlkPopup = top.iLevelAlkPopup - 1; 342 iLevelNext = top.iLevelAlkPopup; 343 if (oPopup.popupFrame){ 344 oPopup.popupFrame.parentNode.removeChild(oPopup.popupFrame); 345 } 346 if ( iLevel==1 && oPopup.popupMsg ) { 347 oPopup.popupMsg.parentNode.removeChild(oPopup.popupMsg); 348 } 349 oPopup.parentNode.removeChild(oPopup); 350 delete(oPopup); 351 bClose = true; 352 } 353 return bClose; 354} 355 356/** 357 * @brief Ferme toute les popup ouvertes 358 */ 359function removeAllPopup() 360{ 361 var bClose = false; 362 for(iLevel=1; iLevel<=top.iLevelAlkPopup; iLevel++) { 363 var oOpenerIFrame = null; 364 var oPopup = top.document.getElementById("alkPopupNiv"+iLevel.toString()); 365 if( oPopup ) { 366 if( oPopup.popupFrame ) { 367 oPopup.popupFrame.parentNode.removeChild(oPopup.popupFrame); 368 } 369 if( iLevel==1 && oPopup.popupMsg ) { 370 oPopup.popupMsg.parentNode.removeChild(oPopup.popupMsg); 371 } 372 oPopup.parentNode.removeChild(oPopup); 373 delete(oPopup); 374 bClose = true; 375 } 376 } 377 top.iLevelAlkPopup = 0; 378 379 return bClose; 380} 381 382 383/** 384 * @brief ferme une fenêtre popup 385 * @param strUrlToken url de réaffichage de l'opener. 386 * si la chaine ne contient pas .php, le paramètre est considéré comme un token 387 * sur l'url alkanet.php 388 */ 389function closeWindow(strUrlToken) 390{ 391 return removePopup(strUrlToken); 392} 393 394/** 395 * Verifie si le paramètre est un token 396 * Vérification indépendante du mode de calcul 397 * La regle utilisée : ne contient que des caractères hexa 398 * @param strToken valeur du token à tester 399 * @return bool 400 */ 401function isToken(strToken) 402{ 403 var strPattern = "0123456789abcdef"; 404 var bRes = ( strToken.length % 2 == 0 ); 405 if( bRes ) { 406 for(i=0; i < strToken.length; i++) { 407 bRes= bRes && ( strPattern.indexOf(strToken[i]) >= 0 ); 408 } 409 } 410 return bRes; 411} 412 413/** 414 * @brief ferme toutes les fenêtres popup ouverte 415 * @param strUrlToken url de réaffichage de l'opener. 416 * si la chaine ne contient pas .php, le paramètre est considéré comme un token 417 * sur l'url alkanet.php 418 */ 419function closeAllWindow(strUrlToken) 420{ 421 if( typeof(strUrlToken)!="undefined" && strUrlToken != "" ) { 422 var oOpenerIFrame = top.window; 423 if( strUrlToken == "reload" ) { 424 oOpenerIFrame.location.reload(); 425 } else { 426 var strUrl = ( strUrlToken.indexOf(".php")>-1 427 ? strUrlToken+(strUrlToken.substr(-4)==".php" ? "?" : "&")+"rndm="+Math.random() 428 : ( isToken(strUrlToken) 429 ? ALK_ALKANET_EXTRA+"?token="+strUrlToken+"&rndm="+Math.random() 430 : strUrlToken )); 431 oOpenerIFrame.location = strUrl; 432 } 433 return true; 434 } 435 return removeAllPopup(); 436} 437 438/** 439 * @brief Crée une iframe cachée nommée 'footerExec' si n'existe pas, utilise l'existant sinon 440 * @param strUrl Url à lire 441 * @param @optionnal frameName Nom de la frame cachée 442 */ 443function OpenFooterExec(strUrl) 444{ 445 var strName = (arguments.length>1 ? arguments[1] : "footerExec"); 446 var oIFrame; 447 if ( top.document.getElementById(strName) ) { 448 oIFrame = top.document.getElementById(strName); 449 } else { 450 var oIFrame = top.document.createElement("iframe"); 451 oIFrame.id = strName; 452 oIFrame.name = strName; 453 oIFrame.style.display = 'none'; 454 top.document.body.appendChild(oIFrame); 455 oIFrame.contentWindow.name = oIFrame.name; 456 } 457 AddWindOpener(oIFrame.name, top.window); 458 oIFrame.contentWindow.location.href = strUrl; 459 if ( arguments.length>2 && arguments[2] ){ 460 return oIFrame; 461 } 462} 463 464/** 465 * @brief Simule l'ouverture d'une fenêtre popup dans un layer et iframe combinés 466 * @param strUrl url de iframe 467 * @param iHeight hauteur de l'iframe 468 * @param iWidth largeur de l'iframe 469 * @param strName Nom de l'iFrame 470 * @return Une référence sur l'iframe ouverte 471 */ 472function OpenWindow(strUrl, iHeight, iWidth, strName) 473{ 474 if( top.iLevelAlkPopup > 4 ) { 475 alert("Conception à revoir. Trop de popup."); 476 return null; 477 } 478 479 var oWind = top; 480 var oPopup = addPopup(top.iLevelAlkPopup+1); 481 if( oPopup ) { 482 top.iLevelAlkPopup = top.iLevelAlkPopup + 1; 483 484 var windowWidth = ( top.window.innerWidth 485 ? top.window.innerWidth 486 : top.window.document.body.clientWidth ); 487 var windowHeight = ( top.window.innerHeight 488 ? top.window.innerHeight 489 : ( top.document.getElementsByTagName('html')[0].offsetHeight>=top.window.document.body.clientHeight 490 ? 0 491 : Math.min(top.document.getElementsByTagName('html')[0].offsetHeight, top.window.document.body.clientHeight) /*top.window.document.body.clientHeight : n'est pas satisfaisant */)); 492 493 var iLeft = Math.max(0, Math.floor((windowWidth - iWidth ) / 2)); 494 var iTop = ( windowHeight>0 495 ? Math.max(0, Math.floor((windowHeight - iHeight ) / 2)) + top.document.documentElement.scrollTop 496 : 50+top.document.documentElement.scrollTop ); 497 498 var iWidth2 = 150, iHeight2 = 12; 499 var iLeft2 = Math.floor((windowWidth - iWidth2 ) / 2); 500 var iTop2 = ( windowHeight>0 501 ? Math.floor((windowHeight - iHeight2 ) / 2)+top.document.documentElement.scrollTop 502 : 50+top.document.documentElement.scrollTop ); 503 504 var oIFrame = top.document.createElement("iframe"); 505 oIFrame.id = "alkIFrameNiv"+oPopup.iAlkLevel.toString(); 506 oIFrame.name = ( !strName ? oIFrame.id : strName ); 507 508 var oOpener = window;//GetWindowByNiv(top.iLevelAlkPopup-1); 509 AddWindOpener(oIFrame.name, oOpener); 510 511 oIFrame.className = oPopup.className; 512 var oStyle = getStyleObj(oIFrame); 513 oStyle.width = iWidth+"px"; 514 oStyle.height = iHeight+"px"; 515 516 var oPopup2 = createAbsoluteDiv("alkPopupFrameNiv"+top.iLevelAlkPopup, 517 iWidth, iHeight, iTop, iLeft, 20001+(top.iLevelAlkPopup*2)); 518 if ( !oPopup2 ) return; 519 var oStyle = getStyleObj(oPopup2); 520 oStyle.display = "block"; 521 522 if ( oWind.document.getElementById("alkPopupMsg") ){ 523 oPopup3 = oWind.document.getElementById("alkPopupMsg"); 524 var oStyle = getStyleObj(oPopup3); 525 oStyle.display = "block"; 526 } 527 else { 528 var oPopup3 = createAbsoluteDiv("alkPopupMsg", iWidth2, iHeight2, iTop2, iLeft2, 30000); 529 if ( !oPopup3 ) return; 530 oPopup3.className = "windPopupMsg"; 531 oPopup3.innerHTML = _gt("Chargement en cours..."); 532 } 533 oIFrame.popupMsg = oPopup3; 534 oIFrame.popupFrame = oPopup2;
535 oIFrame.popupBackground = oPopup; 536 oIFrame.iLevel = top.iLevelAlkPopup; 537 538 oPopup.popupMsg = oPopup3; 539 oPopup.popupFrame = oPopup2; 540 541 oWind.document.body.appendChild(oPopup2); 542 oPopup2.appendChild(oIFrame); 543 oIFrame.src = strUrl; 544 oWind.document.body.appendChild(oPopup3); 545 oIFrame.contentWindow.name = oIFrame.name; 546 } 547 return oIFrame.contentWindow; 548} 549 550function HideLoadMsg() 551{ 552 if ( top.document.getElementById("alkPopupMsg") ){ 553 var oMsg = top.document.getElementById("alkPopupMsg"); 554 var oStyle = getStyleObj(oMsg); 555 oStyle.display = "none"; 556 }/* 557 if ( typeof popupFrame != "undefined" ){ 558 var oStyle = getStyleObj( popupFrame ); 559 oStyle.display = "block"; 560 }*/ 561} 562 563function createAbsoluteDiv(id, iWidth, iHeight, iTop, iLeft, zIndex){ 564 var oWind = top; 565 var oPopup = oWind.document.createElement("div"); 566 oPopup.id = id; 567 if( oPopup ) { 568 var oStyle = getStyleObj(oPopup); 569 oStyle.position = "absolute"; 570 oStyle.width = iWidth+"px"; 571 oStyle.height = iHeight+"px"; 572 oStyle.top = iTop+"px"; 573 oStyle.left = iLeft+"px"; 574 oStyle.zIndex = zIndex; 575 } 576 return oPopup; 577} 578 579function getStyleObj(oObj) 580{ 581 return ( oObj.style ? oObj.style : oObj ); 582} 583 584/** 585 * @brief Ouvre une vrai fenêtre popup 586 * @param strUrl url de iframe 587 * @param iHeight hauteur de l'iframe 588 * @param iWidth largeur de l'iframe 589 * @param strName Nom de l'iFrame (_blank par défaut) 590 * @param strStatus yes ou no pour afficher la barre de statut (yes par défaut) 591 * @param strMenu yes ou no pour afficher le menu (no par défaut) 592 * @return Une référence sur l'iframe ouverte 593 * 594 */ 595function OpenPopupWindow(strUrl, iHeight, iWidth, strName, strStatus, strMenu) 596{ 597 if( !strName ) strName = "_blank"; 598 if( !strStatus ) strStatus = "yes"; 599 if( !strMenu ) strMenu = "no"; 600 601 var hauteur_popup = (typeof iHeight=="undefined" ? 400 : iHeight); 602 var largeur_popup = (typeof iWidth=="undefined" ? 520 : iWidth); 603 var H = (screen.height - hauteur_popup) / 2; 604 var L = (screen.width - largeur_popup) / 2; 605 606 AddWindOpener(strName, window); 607 608 popupWindow = window.open(strUrl, strName, 609 "status="+strStatus+",menubar="+strMenu+ 610 ",scrollbars=yes,resizable=yes,height="+hauteur_popup+ 611 ",width="+largeur_popup+",top="+H+",left="+L); 612 if( !popupWindow ) { 613 alert(_gt("Attention, votre navigateur bloque l'ouverture de fenêtre popup.%sVous devez autoriser l'ouverture de popup pour ce site.", "\n")); 614 } else { 615 popupWindow.id = strName; 616 } 617 return popupWindow; 618} 619 620/** 621 * @brief Mémorise l'opener pour une fenêtre 622 * @param strName Nom de la fenêtre 623 * @param oOpener Référence sur sa fenêtre opener 624 */ 625function AddWindOpener(strName, oOpener) 626{ 627 if( typeof(top.navigator.AlkOpener) == "undefined" || top.navigator.AlkOpener.constructor.toString().indexOf("Array()") < 0 ) { 628 top.navigator.AlkOpener = new Array(); 629 } 630 top.navigator.AlkOpener[strName] = oOpener; 631} 632 633/** 634 * @brief Retourne la référence sur la fenêtre ouvreuse de la popup courante ou de la popup portant le nom passé en paramètre 635 * @param strName nom de la popup (optionnel) 636 * @return référence sur objet de type window 637 */ 638function GetWindowOpener(strName) 639{ 640 var strName = strName || ( window.name == "" ? "_top" : window.name ); 641 var oOpener = null; 642 if( typeof top.navigator.AlkOpener != "undefined" && typeof(top.navigator.AlkOpener[strName]) != "undefined" ) { 643 oOpener = top.navigator.AlkOpener[strName]; 644 } 645 return oOpener; 646} 647 648/** 649 * @brief Appel une url par le biais du javascript (nécessaire lien sur event onclick) 650 * @param strUrl Url de redirection 651 */ 652function AlkGoUrl(strUrl) 653{ 654 window.location = strUrl; 655} 656 657/** 658 * @brief Affiche une confirmation avec strMsg avant d'appeler strLink 659 * @param strLink Url appelée après confirmation 660 * @param strMsg Message de confirmation 661 */ 662function Confirmation(strLink, strMsg) 663{ 664 var strTmp = _gt("Veuillez confirmer la suppression ?"); 665 666 if( typeof(strMsg) != 'undefined' ) strTmp = strMsg; 667 var res = alkConfirm(strTmp); 668 if( res ) document.location.href = strLink; 669} 670 671/** 672 * @brief Affiche une confirmation avant d'appeler l'url effectuant 673 * la suppression en utilisant le token 674 * @param strToken token pour suppression 675 */ 676function DeleteData(strToken) 677{ 678 var strMsg = _gt("Veuillez confirmer la suppression de cette information ?"); 679 if ( arguments.length>1 ) 680 strMsg = arguments[1]; 681 Confirmation(ALK_ALKANET_SQL+"?token="+strToken, strMsg); 682} 683 684/** 685 * @brief Demande confirmation avant de fermer la session 686 */ 687function CloseSession(strToken) 688{ 689 if( typeof(strToken) == 'undefined' ) strToken = ''; 690 var res = alkConfirm(_gt("Vous allez fermer votre session. Confirmer ?")); 691 if( res ) top.document.location.href = ALK_ALKANET_DISCONNECT+( strToken!="" ? "?token="+strToken : "" ); 692} 693 694/** 695 * @brief Ouvre la fenêtre d'aide 696 */ 697function OpenHelp(strToken) 698{ 699 var ht = 400; 700 var lg = 950; 701 var t = (screen.height-ht)/2; 702 var l = (screen.width-lg)/2; 703 var strPage = ALK_ALKANET_HELP+"?token="+strToken; 704 window.open(strPage, 'WindowHelp', 705 'status=yes,scrollbars=yes,resizable=yes,height='+ht+',width='+lg+',top='+t+',left='+l); 706} 707 708/** 709 * Ouvre la popup de calcul de performance 710 */ 711function OpenPerf(strToken) 712{ 713 OpenWindow(ALK_ALKANET+"?token="+strToken, "330", "400", "windPerf"); 714} 715 716/** 717 * Ouvre la popup de calcul de performance 718 */ 719function OpenContactAdmin(strToken) 720{ 721 OpenWindow(ALK_ALKANET_EXTRA+"?token="+strToken, "420", "550", "windContact"); 722} 723 724 725/** 726 * @brief Gestion encodage de token 727 * @todo A vérifier 728 */ 729 730function TextEncode(strParam) 731{ 732 var t = new String("test"); 733 if (!t.charCodeAt) return strParam; 734 strParam = encodeToUTF8(strParam); 735 var strEncode = ""; 736 for(var i=0; i<strParam.length; i++) { 737 strEncode += DecToHexa(strParam.charCodeAt(i)); 738 } 739/* 740 var bCheckSum = (arguments.length==1 || arguments[1]); 741 if ( bCheckSum ){ 742 var iChecksum = getCheckSumEncodage(strEncode); 743 strEncode += TextEncode("&ALK_CHECKSUM="+iChecksum, false); 744 }*/ 745 return strEncode; 746} 747 748function TextDecode(strParam) 749{ 750 var test = ""; 751 var t = new String("test"); 752 if (!t.fromCharCode && !String.fromCharCode) return strParam; 753 //décodage 754 var strDecode = ""; 755 for(var i=0; i<strParam.length; i+=2 ) { 756 strDecode = new String(strDecode) + String.fromCharCode( HexaToDec(strParam.substr(i, 2) ) ) ; 757 } 758 759 return decodeFromUTF8(strDecode); 760} 761 762function DecToHexa(integer, bIter){ 763 var tabConv = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"); 764 if (integer<=15 ) { 765 if( bIter) return tabConv[integer]; 766 return "0"+tabConv[integer]; 767 } 768 var quotient = Math.floor(integer/16); 769 var remainder = integer % 16; 770 return new String(DecToHexa(quotient,true))+new String(DecToHexa(remainder,true)); 771} 772 773function HexaToDec(hexa){ 774 var tabConv = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"); 775 if (hexa.length==1){ 776 for (var j=0; j<tabConv.length; j++){ 777 if (tabConv[j].toLowerCase()==hexa.toLowerCase()) return j; 778 } 779 return 0; 780 } 781 var res = 0; 782 for (var p=0; p<hexa.length; p++){
783 res = new Number( new Number(res) + new Number(HexaToDec(hexa.charAt(p))*Math.pow(16, hexa.length - p -1)) ); 784 } 785 return res; 786} 787function encodeToUTF8(strLatin1) 788{ 789 var strUTF8 = ""; 790 791 for (var n = 0; n < strLatin1.length; n++) { 792 var c = strLatin1.charCodeAt(n); 793 if (c < 128) { 794 strUTF8 += String.fromCharCode(c); 795 } 796 else if((c > 127) && (c < 2048)) { 797 strUTF8 += String.fromCharCode((c >> 6) | 192); 798 strUTF8 += String.fromCharCode((c & 63) | 128); 799 } 800 else { 801 strUTF8 += String.fromCharCode((c >> 12) | 224); 802 strUTF8 += String.fromCharCode(((c >> 6) & 63) | 128); 803 strUTF8 += String.fromCharCode((c & 63) | 128); 804 } 805 } 806 807 return strUTF8; 808} 809 810function decodeFromUTF8(strUTF8) { 811 var strLatin1 = ""; 812 var i = 0; 813 var c = c1 = c2 = 0; 814 815 while ( i < strUTF8.length ) { 816 c = strUTF8.charCodeAt(i); 817 if (c < 128) { 818 strLatin1 += String.fromCharCode(c); 819 i++; 820 } 821 else if((c > 191) && (c < 224)) { 822 c2 = strUTF8.charCodeAt(i+1); 823 strLatin1 += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); 824 i += 2; 825 } 826 else { 827 c2 = strUTF8.charCodeAt(i+1); 828 c3 = strUTF8.charCodeAt(i+2); 829 strLatin1 += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); 830 i += 3; 831 } 832 } 833 834 return strLatin1; 835} 836function getCheckSumEncodage(strToken) 837{ 838 var tabTrad = new Array(); 839 for(var i=0; i<10; i++) tabTrad[i] = i; 840 tabTrad["A"] = tabTrad["a"] = 10; 841 tabTrad["B"] = tabTrad["b"] = 11; 842 tabTrad["C"] = tabTrad["c"] = 12; 843 tabTrad["D"] = tabTrad["d"] = 13; 844 tabTrad["E"] = tabTrad["e"] = 14; 845 tabTrad["F"] = tabTrad["f"] = 15; 846 847 var iChecksum = 0; 848 for(i=0; i<strToken.length; i++) { 849 iChecksum += parseInt(tabTrad[strToken.charAt(i)]); 850 } 851 return iChecksum; 852} 853/** 854 * @brief construit un token à partir des paramètres donnés. 855 * La partie cont_id et appli_id est donnée par la variable globale ALK_APPLI_TOKEN (utilisé par cette fonction) 856 * ATTENTION : Les paramètres supplémentaires (strParam) ne doivent pas contenir de caractères accentués 857 * @param iTypeSheet Identifiant du type d'onglet 858 * @param iSheet Identifiant de l'onglet 859 * @param iSSheet Identifiant du sous-onglet 860 * @param strParam (option) Chaine de paramètres supplémentaires. ATTENTION : caractères accentués non acceptés 861 * @return string : token d'une url 862 */ 863function getToken(iTypeSheet, iSheet, iSSheet, strParam) 864{ 865 if ( typeof strParam=="undefined" ) 866 strParam = ""; 867 868 var strAppliToken = ""; 869 if ( typeof ALK_APPLI_TOKEN=="undefined" ){ 870 strAppliToken = ""; 871 } 872 else 873 strAppliToken = ALK_APPLI_TOKEN; 874 if ( arguments.length>4 ){ 875 strAppliToken = TextEncode(arguments[4], false); 876 } 877 878 var strToken = "&iTypeSheet="+iTypeSheet+"&iSheet="+iSheet+"&iSSheet="+iSSheet+strParam; 879 strToken = TextEncode(strToken, false); 880 strToken = strAppliToken+strToken; 881 /*var iChecksum = getCheckSumEncodage(strToken); 882 strToken += TextEncode("&ALK_CHECKSUM="+iChecksum, false);*/ 883 884 return strToken; 885} 886/** 887 * Retourne la chaine d'évaluation d'une variable définie (typeof xxx != 'undefined') 888 * @param param_name Nom de la variable à évaluer 889 * @return string retourne la chaine d'évaluation d'une variable définie 890 */ 891function getStrIsDefined(param_name) 892{ 893 return "typeof "+param_name+' != "undefined"'; 894} 895/** 896 * Change le titre d'un onglet 897 * @param iSheet numero de l'onglet 898 * @param newName nouveau titre de l'onglet 899 */ 900function setSheetName(iSheet, newName) 901{ 902 // un onglet est défini par la structure : 903 // <li id="sheetHeader_contents_contents_sheetXX" ...><a onclick="action...">Sheet Name</a></li> 904 var sheet = document.getElementById('sheetHeader_contents_contents_sheet'+iSheet); 905 if ( sheet ) 906 sheet.firstChild.innerHTML = newName; 907} 908/** 909 * Retourne dans une chaine la liste couples paramètres/valuers d'un formulaire pour une intégration dans URL 910 * 911 * @param oForm réfèrence sur le formulaire à analyser. 912 * @return string 913 */ 914function convertFormValuesToUrlParam(oForm) 915{ 916 var getstr = ""; 917 for (i=0; i<oForm.childNodes.length; i++) { 918 if (oForm.childNodes[i].tagName == "INPUT") { 919 if (oForm.childNodes[i].type == "text") { 920 getstr += oForm.childNodes[i].name + "=" + oForm.childNodes[i].value + "&"; 921 } 922 if (oForm.childNodes[i].type == "hidden") { 923 getstr += oForm.childNodes[i].name + "=" + oForm.childNodes[i].value + "&"; 924 } 925 if (oForm.childNodes[i].type == "checkbox") { 926 if (oForm.childNodes[i].checked) { 927 getstr += oForm.childNodes[i].name + "=" + oForm.childNodes[i].value + "&"; 928 } else { 929 getstr += oForm.childNodes[i].name + "=&"; 930 } 931 } 932 if (oForm.childNodes[i].type == "radio") { 933 if (oForm.childNodes[i].checked) { 934 getstr += oForm.childNodes[i].name + "=" + oForm.childNodes[i].value + "&"; 935 } 936 } 937 } 938 if (oForm.childNodes[i].tagName == "SELECT") { 939 var sel = oForm.childNodes[i]; 940 getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&"; 941 } 942 943 } 944 return getstr; 945} 946/** 947 * Retourne dans une chaine la liste couples paramètres/valuers d'un formulaire pour une intégration dans URL 948 * 949 * @param thingId nom de l'entité à rendre visible 950 * @return string 951 */ 952function visible(thingId) 953{ 954 var targetElement = document.getElementById(thingId); 955 if( targetElement ) { 956 var oStyle = ( targetElement.style ? targetElement.style : targetElement ); 957 oStyle.display = "block" ; 958 } 959} 960/** 961 * Retourne dans une chaine la liste couples paramètres/valuers d'un formulaire pour une intégration dans URL 962 * 963 * @param thingId nom de l'entité à rendre invisible 964 * @return string 965 */ 966function invisible(thingId) 967{ 968 var targetElement = document.getElementById(thingId); 969 if( targetElement ) { 970 var oStyle = ( targetElement.style ? targetElement.style : targetElement ); 971 oStyle.display = "none"; 972 } 973} 974/** 975 * Change la propriété display de l'objet block si invisible, none si visible 976 * 977 * @param thingId nom de l'entité à rendre visible ou invisible 978 * @return string 979 */ 980function OpenCloseHtmlBlock(thingId, strClassStyleShow, strClassStyleHide) 981{ 982 var oTbody = document.getElementById(thingId) ; 983 984 if (!oTbody) 985 return; 986 // on récupère les différents div 987 var oListDiv = oTbody.childNodes; 988 for(var i=1; i< oListDiv.length; i++){ 989 var oDiv = oListDiv[i]; 990 if(oDiv.className.indexOf(strClassStyleHide)!=-1){ 991 oDiv.className = oDiv.className.replace(new RegExp("("+strClassStyleHide+")", "g"), strClassStyleShow); 992 //oTbody.style.display = "" ; 993 } else { 994 oDiv.className = oDiv.className.replace(new RegExp("("+strClassStyleHide+")", "g"), strClassStyleShow) + " "+ strClassStyleHide; 995 //oDiv.style.display = "none" ; 996 } 997 } 998 999} 1000/** 1001 * charge une nouvelle image 1002 * @param idImg identifiant du ctrl image à mettre à jour 1003 */ 1004function loadSecureImg(idImg) 1005{ 1006 var oImg = document.getElementById(idImg); 1007 if( oImg ) { 1008 var strAlea = new String(Math.random()); 1009 strAlea = strAlea.substr(2); 1010 oImg.src = ALK_ALKANET_CAPTCHA+"?i="+strAlea; 1011 } 1012} 1013 1014/** 1015 * Se charge de décoder une chaine 1016 * Cette methode doit etre appele sur l'event onmousedown 1017 * @param oThis reference de la balise 1018 * @param strTmp texte à décoder 1019 * @return string 1020 */ 1021function getDecodeEM(oThis, strTmp) 1022{ 1023 strTmp = strTmp+":"+"o"+"t"+"l"; 1024 strTmp = strTmp.toLowerCase(); 1025 strTmp = strTmp+"i"+"a"+"m" 1026 strTmp = strTmp.replace(String.fromCharCode(35), String.fromCharCode(64)); 1027 var strRes = ""; 1028 for(var i=strTmp.length-1; i>=0; i--) { 1029 var c = strTmp.charAt(i); 1030 if( c == "," ) c = "."; 1031 strRes += c; 1032 } 1033 document.location.href = strRes; 1034} 1035 1036/** 1037* supprime le cache 1038*/ 1039function DeleteCache(token){ 1040 AlkAjax("cache", "fnDeleteCache", "GET", ALK_ALKANET_PROCESS+"?iMode=15&token=" + token, null); 1041} 1042function fnDeleteCache(strRep){ 1043 if (strRep=="1"){ 1044 alkAlert("Le cache a été bien supprimé"); 1045 }else { 1046 alkAlert("Echec de suppression de cache"); 1047 } 1048} 1049 1050/** 1051 * Check whether an object is Array or not 1052 * @type Boolean 1053 * @param {object} subject is the variable that is 1054 * tested for Array identity check 1055 */ 1056var isArray = (function () { 1057 // Use compiler's own isArray when available 1058 if (Array.isArray) { 1059 return Array.isArray; 1060 } 1061 1062 // Retain references to variables for performance 1063 // optimization 1064 var objectToStringFn = Object.prototype.toString, 1065 arrayToStringResult = objectToStringFn.call([]); 1066
1067 return function (subject) { 1068 return objectToStringFn.call(subject) === arrayToStringResult; 1069 }; 1070}()); 1071 1072 1073/** 1074 * Permet la communication entre l'iframe et son parent 1075 * @param data tableau de donnée 1076 */ 1077function parentPostMessage(data){ 1078 if(parent.postMessage){ 1079 parent.postMessage(data, '*'); 1080 } 1081} 1082 1083/** 1084 * Permet de définir la fonction gérant la récupération des messages reçu par la fenêtre 1085 * @param functionEvent Fonction javascript avec en parametre event 1086 */ 1087function setEventIframeListenerFunction(functionEvent){ 1088 if(typeof functionEvent == "function"){ 1089 // Create browser compatible event handler. 1090 var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent"; 1091 var eventer = window[eventMethod]; 1092 var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message"; 1093 // Listen for a message from the iframe. 1094 eventer(messageEvent, functionEvent, false); 1095 } 1096}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.