var Netquiz = Class.create({
currentPageIndex:0,
gSoundVolume: 75,
participantId: -1,
//servercmdpage: 'srvcmd.php',
showingResult: false,
resultNbPagesBFScroll:7,
imgPreloader: null,
startingQuiz: true,
firstLoad: false,
numberPagesQuiz: 0,
initializedSequence: false,
isPageSection: false,
questionSequence: new Array(),
indexShuffleStart: new Array(),
indexShuffleEnd: new Array(),
pageAdded: new Array(),
pageInitVal: new Array(),
numberOfQuestions: null,
//Debut consigne
/*consigneHeader: '',
consigneAssociation: '',
consigneBlankText: '',
consigneCheckerBoard: '',
consigneClassement: '',
consigneDictee: '',
consigneImagePart: '',
consigneLongText: '',
consigneMarquage: '',
consigneMultipleAnswers: '',
consigneMultipleChoices: '',
consigneRanking: '',
consigneShortText: '',*/
//Fin consigne
//Dictee
sMsgMotsMOrtho: "",
sMsgMotsManq: "",
sMsgMotsTrop: "",
//msgs
msgQuizNotExist: null,
msgQuizInactive: null,
msgKeyNotExist: null,
msgKeyUsed: null,
msgGeneralError: null,
msgUnonload: null,
msgRepeatNumEtudiant: null,
msgModuleError: null,
msgAddressModuleError: null,
//Labels
pageLabel: null,
resultTitle: null,
goodAnswerLabel: null,
wrongAnswerLabel: null,
incompleteAnswerLabel: null,
solutionLabel: null,
suggestionLabel: null,
msgRestartQuiz: null,
removeHiliteLabel: null,
//Status
statusToDo: '',
statusToRedo: '',
statusCompleted: '',
//Nav Bar
navbResult: null,
navbRedo: null,
navbSolution: null,
navbValidate: null,
navBarOf: 'de',
//Result
resultHeaderCol0: '',
resultHeaderCol1: '',
resultHeaderCol2: '',
resultHeaderCol3: '',
resultHeaderCol4: '',
resultIdentTitle: '',
resultButtonRedo: '',
resultButtonSendTo: '',
resultButtonPrint: '',
resultButtonOK: '',
resultButtonCancel: '',
rifLblLastName: '',
rifLblName: '',
rifLblCode: '',
rifLblGroup: '',
rifLblEmail: '',
rifLblOther: '',
resultHTMLVersion: '',
//Settings
mode:0, /*0 = Preview/Formatif, 1= Formatif w/ submit, 2= Sommatif */
urlServer: null,
quizId: null,
videoFixedWidth: 320,
showNavTextBox: true,
resultPageEnabled: true,
decimalSymbol: 0,
mediasFolder: 'medias',
bgSkinColor: '797979',
quizTitle: '',
//Timer (each page)
answerTimerEnabled: false,
pageTimer: new Array(),
secs: null,
timerID: null,
timerRunning: false,
delay: 1000,
//user info
userLastName: '',
userName: '',
userCode: '',
userGroup: '',
userEmail: '',
userOther: '',
//pour zoom image
imagePathHS: '',
imgMaxWidth: 550,
//Construct
initialize: function(){
//Hide pour pas avoir de glitch au load du quiz si video dans premiere page
$('contentwrapper').hide();
$('btnBackDisabled').hide();
$('btnNextDisabled').hide();
$('indice').hide();
$('resultIdentForm').hide();
$('scrollwrapper').hide();
this.pages = new Array();
this.imgPreloader = getImgPreloader();
},
//Init
init: function(){
document.body.style.backgroundColor = '#' + this.bgSkinColor;
if (isMobile.Android() == true){
jQuery("#pagewrapper").removeClass("pagewrapper");
}
//Show apres les hide dans initialize
$('contentwrapper').show();
this.solutionLabel = '' + this.solutionLabel + '';
this.suggestionLabel = '' + this.suggestionLabel + '';
var newPageSequence = new Array();
for(i = 0;i < this.questionSequence.length;i++){
this.pageInitVal[i] = this.pages[i];
for(j = 0;j < this.questionSequence.length;j++){
if (j == this.questionSequence[i]){
newPageSequence[newPageSequence.length] = this.pages[j];
}
}
}
for(i = 0;i < newPageSequence.length;i++){
this.pages[i] = newPageSequence[i];
}
for(i = 0;i <= this.numberPagesQuiz - 1;i++){
this.pageTimer[i] = 0;
}
if (this.numberOfQuestions){
for(i = 0;i < this.questionSequence.length;i++){
if (i >= this.numberOfQuestions){
this.pages[i] = null;
}
}
this.pages.length = this.numberOfQuestions;
}
//Result
$('resultHeaderCol0WOT').update(this.resultHeaderCol0);
$('resultHeaderCol1WOT').update(this.resultHeaderCol1);
$('resultHeaderCol2WOT').update(this.resultHeaderCol3);
$('resultHeaderCol3WOT').update(this.resultHeaderCol4);
$('resultHeaderCol0WT').update(this.resultHeaderCol0);
$('resultHeaderCol1WT').update(this.resultHeaderCol1);
$('resultHeaderCol2WT').update(this.resultHeaderCol2);
$('resultHeaderCol3WT').update(this.resultHeaderCol3);
$('resultHeaderCol4WT').update(this.resultHeaderCol4);
$('resultIdentFormHeader').update(this.resultIdentTitle);
$('resultButtonRedo').update(this.resultButtonRedo);
//$('resultButtonSendTo').update(this.resultButtonSendTo);
$('resultButtonPrint').update(this.resultButtonPrint);
$('resultButtonOK').update(this.resultButtonOK);
$('resultButtonCancel').update(this.resultButtonCancel);
$('rifLblLastName').update(this.rifLblLastName);
$('rifLblName').update(this.rifLblName);
$('rifLblCode').update(this.rifLblCode);
$('rifLblGroup').update(this.rifLblGroup);
$('rifLblEmail').update(this.rifLblEmail);
$('rifLblOther').update(this.rifLblOther);
//Netquiz Nav bar
if(this.navbResult)
$$('#navbResult a')[0].update(this.navbResult);
if(this.navbRedo)
$$('#navbRedo')[0].update('' + this.navbRedo + '');
if(this.navbSolution)
$$('#navbSolution')[0].update('' + this.navbSolution + '');
if(this.navbValidate)
$$('#navbValidate')[0].update('' + this.navbValidate + '');
$$('#pagenavbIndice a')[0].update(this.pages[this.currentPageIndex].indiceTag);
$$('#pagenavbSource a')[0].update(this.pages[this.currentPageIndex].sourceTag);
$('pageLabel').update(this.pageLabel);
var navBarOfStr = ' ' + this.navBarOf + ' ';
$('navBarOf').update(navBarOfStr);
if(this.showNavTextBox)
$('navBarPageIndex').hide();
else
$('navBarTxtPageIndex').hide();
if(this.resultPageEnabled)
$('navBarPageCount').update(this.pages.length + 1);
else
$('navBarPageCount').update(this.pages.length);
$('username').update(' ');
updateWrappersSize();
this.imgPreloader.sFolder = this.mediasFolder;
this.imgPreloader.onFinish = nq4_onImgsPreloadFinish;
this.imgPreloader.preload();
},
begin: function(){
this.pageGoto(0);
$('scrollwrapper').show();
//Ass-rank temp "fix"
if (this.pages[0].question){
if (this.firstLoad == false){
this.firstLoad = true;
this.pageGoto(0);
this.redo();
addHighSlideToOtherImages('page');
}
}
},
initShuffleQuestion: function(indexStart,indexEnd){
if (this.initializedSequence == false){
for(i = 0;i <= this.numberPagesQuiz - 1;i++){
this.questionSequence[i] = i;
}
this.indexShuffleStart[this.indexShuffleStart.length] = indexStart;
this.indexShuffleEnd[this.indexShuffleEnd.length] = indexEnd;
this.initializedSequence = true;
}
var o = new Array();
var arrayToSort = new Array();
for(i = indexStart;i <= indexEnd;i++){
arrayToSort[arrayToSort.length] = this.questionSequence[i];
}
o = arrayToSort;
for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
arrayToSort = o;
for(i = 0;i < arrayToSort.length;i++){
this.questionSequence[indexStart + i] = arrayToSort[i];
}
},
restartQuiz: function(){
var input_box = confirm(this.msgRestartQuiz);
if (input_box == true){
window.location.reload();
/*À GARDER AU CAS OÙ PROBLÈMES AVEC LE RELOAD / SI ON CHANGE D'IDÉE EN AJOUTANT UN PARAMÈTRE*/
/*var newPageSequence = new Array();
var o = new Array();
var arrayToSort = new Array();
if (this.indexShuffleStart.length > 0){
for(i = 0;i < this.indexShuffleStart.length;i++){
var indShufStart = this.indexShuffleStart[i];
var indShufEnd = this.indexShuffleEnd[i];
for(j = indShufStart;j <= indShufEnd.length;j++){
arrayToSort[arrayToSort.length] = this.pageInitVal[j];
}
}
}
else{
for(i = 0;i < this.questionSequence.length;i++){
arrayToSort[arrayToSort.length] = this.pageInitVal[i];
}
}
o = arrayToSort;
for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
arrayToSort = o;
for(i = 0;i < arrayToSort.length;i++){
this.pages[i] = arrayToSort[i];
newPageSequence[newPageSequence.length] = this.pages[i];
}
var indexEndPages;
if (this.numberOfQuestions){
indexEndPages = this.numberOfQuestions;
}
else{
indexEndPages = this.numberPagesQuiz;
}
for(i = 0;i <= indexEndPages - 1;i++){
this.pageTimer[i] = 0;
if(this.pages[i].question){
this.pages[i].question.triesCount = 0;
this.pages[i].question.redoQuiz();
}
}
if (this.numberOfQuestions){
for(i = 0;i < this.questionSequence.length;i++){
if (i >= this.numberOfQuestions){
this.pages[i] = null;
}
}
this.pages.length = this.numberOfQuestions;
}
this.pageGoto(0); */
}
},
connect: function(){
/*if((this.urlServer.substr(0,7) != 'http://') || (this.urlServer.length == 0) || (this.urlServer.replace('http://','').length == 0)){
$('msgErreur').update(this.msgAddressModuleError);
return;
}
var url = this.urlServer + '/' + this.servercmdpage + '?cmd=checkstatus';
var params = {
qidentifier: this.quizId
};
new Ajax.Request(url, {
method: 'post',
parameters: params,
asynchronous: true,
onSuccess: nq4_onConnectSuccess,
encoding: 'ISO-8859-1'
});*/
},
connectSuccess: function(transport){
/*var response = transport.responseJSON;
var serverMsg = response.msg;
switch(serverMsg){
case 0:
$('msgErreur').update(this.msgQuizNotExist);
break;
case 1:
//exist and active
break;
case 2:
$('msgErreur').update(this.msgQuizInactive);
break;
}*/
},
auth: function(){
},
authSuccess: function(transport){
var response = transport.responseJSON;
var serverMsg = response.msg;
switch(serverMsg){
case 0:
$('pagewrapperauth').hide();
$('pagewrapperquiz').show();
this.participantId = response.participantId;
$('username').update(response.username);
window.onbeforeunload = tcals_onunload;
if(response.questionNb == -1)
this.pageGoto(0);
else
this.resume(response.questionNb);
break;
case 1:
$('msgErreur').update(this.msgKeyNotExist);
break;
case 2:
$('msgErreur').update(this.msgKeyUsed);
break;
case 3:
$('msgErreur').update(this.msgGeneralError);
break;
}
},
//Navbar
newPage: function(){
this.pages[this.pages.length] = new Page(this);
return this.pages[this.pages.length - 1];
},
pageNext: function(){
if(this.resultPageEnabled){
if(this.currentPageIndex < (this.pages.length))
this.pageGoto(this.currentPageIndex + 1);
}else{
if(this.currentPageIndex < (this.pages.length - 1))
this.pageGoto(this.currentPageIndex + 1);
}
},
pageBack: function(){
if(this.currentPageIndex > 0)
this.pageGoto(this.currentPageIndex - 1);
},
pageGoto: function(pageIndex){
if(pageIndex > -1 && pageIndex < this.pages.length){
$('quizpage').style.height = '';
$('feedbackcontent').innerHTML = '';
if(!this.showingResult)
if (this.startingQuiz == false)
this.savePage();
else
this.startingQuiz = false;
this.hideResultIdentForm();
indiceWindow.close();
showFeedback();
closeFeedback();
this.displayPage(this.pages[pageIndex]);
this.currentPageIndex = pageIndex;
addHighSlideToOtherImages('page');
}else if (pageIndex == this.pages.length && this.resultPageEnabled){
$('quizpage').style.height = '';
$('feedbackcontent').innerHTML = '';
if(!this.showingResult)
this.savePage();
this.hideResultIdentForm();
indiceWindow.close();
closeFeedback();
this.displayResultPage();
this.currentPageIndex = pageIndex;
}
},
pageGotoResult: function(){
if (this.resultPageEnabled){
if(!this.showingResult)
this.savePage();
indiceWindow.close();
closeFeedback();
this.displayResultPage();
this.currentPageIndex = this.pages.length;
}
},
resume: function(questionNb){
var questionAt = 0;
var thePage;
for(i = 0;i < this.pages.length;i++){
thePage = this.pages[i];
if (thePage.question){
if (questionAt == questionNb){
this.pageGoto(i);
return;
}
else{
questionAt = questionAt + 1;
}
}
}
},
redo: function(){
var currentPage = this.pages[this.currentPageIndex];
currentPage.redo();
this.updateNavBar(currentPage);
},
validate: function(){
var currentPage = this.pages[this.currentPageIndex];
currentPage.validate();
this.updateNavBar(currentPage);
var element = document.getElementById('feedback');
element.scrollIntoView(true);
},
showSolution: function(){
var currentPage = this.pages[this.currentPageIndex];
currentPage.showSolution();
var element = document.getElementById('feedback');
element.scrollIntoView(true);
},
showIndice: function(){
var indiceBR = "
" + this.pages[this.currentPageIndex].indice + "";
$$('#indiceheader span')[0].update(this.pages[this.currentPageIndex].indiceTag);
$$('#indicewrapper div')[0].update(indiceBR);
/*AVANT NETQUIZ TABLETTE, CHANGER DE PLAYER*/
/*
if (this.pages[this.currentPageIndex].videoPath)
$('videoInPage').hide();
if (this.pages[this.currentPageIndex].soundPath)
$('theSound').hide();*/
indiceWindow.open('indice');
},
showSource: function(){
var sourceBR = "" + this.pages[this.currentPageIndex].source + "";
$$('#indiceheader span')[0].update(this.pages[this.currentPageIndex].sourceTag);
$$('#indicewrapper div')[0].update(sourceBR);
/*AVANT NETQUIZ TABLETTE, CHANGER DE PLAYER*/
/*
if (this.pages[this.currentPageIndex].videoPath)
$('videoInPage').hide();
if (this.pages[this.currentPageIndex].soundPath)
$('theSound').hide();*/
indiceWindow.open('indice');
},
showConsigne: function(){
var consigneBR = "" + this.pages[this.currentPageIndex].consigne + "";
$$('#indiceheader span')[0].update(this.pages[this.currentPageIndex].readableType);
$$('#indicewrapper div')[0].update(consigneBR);
/*AVANT NETQUIZ TABLETTE, CHANGER DE PLAYER*/
/*
if (this.pages[this.currentPageIndex].videoPath)
$('videoInPage').hide();
if (this.pages[this.currentPageIndex].soundPath)
$('theSound').hide();*/
indiceWindow.open('indice');
},
//Private
savePage: function(){
var currentPage = this.pages[this.currentPageIndex];
if (currentPage.question){
var answer = currentPage.question.save();
if (!this.previewMode){
var url = this.urlServer + '/' + this.servercmdpage + '?cmd=save';
var params = {
participantId: this.participantId,
questionNb: currentPage.question.questionNb,
value: answer
}
/*new Ajax.Request(url, {
method: 'post',
parameters: params,
asynchronous: false,
encoding: 'ISO-8859-1'
});*/
}
}
},
displayPage: function(page){
var theBrowser = detectBrowser();
$('videoContainer').style.paddingBottom = '0px';
$('soundContainer').style.paddingBottom = '0px';
$('imageContainer').style.paddingBottom = '0px';
$('navbSep3_1').show();
$('navbSep3_2').show();
$('navbSep3_3').show();
$('quizpage').show();
$('resultpage').hide();
this.showingResult = false;
this.resetLayout();
if (page.title){
$('pageTitle').update(page.title);
$('pageTitleContainer').show();
$('pagenavbar').style.marginTop = '0px';
if (page.question){
if(page.imagePath || page.videoPath){
$('pagecontent').style.marginTop = '38px';
}
else{
$('pagecontent').style.marginTop = '28px';
}
}
else{
if (theBrowser.indexOf("Safari") != -1 || theBrowser.indexOf("safari") != -1){
$('pagecontent').style.marginTop = '65px';
}
else{
$('pagecontent').style.marginTop = '68px';
}
}
}
else{
$('pageTitle').update(' ');
$('pageTitleContainer').hide();
$('pagenavbar').style.marginTop = '-2px';
if (page.question){
if (theBrowser.indexOf("Safari") != -1 || theBrowser.indexOf("safari") != -1){
$('pagecontent').style.marginTop = '52px';
}
else{
$('pagecontent').style.marginTop = '54px';
}
}
else{
$('pagecontent').style.marginTop = '70px';
}
}
//statement
if(page.statement){
$('statement').show();
$('statement').update(page.statement);
}
//guideline
if(page.textGuideline){
$('textGuidelinequiz').show();
$('textGuidelinequizSep').show();
$('textGuidelinequiz').update(page.textGuideline);
}
//image
if(page.imagePath){
var srcImage = this.mediasFolder + "/" + page.imagePath;
this.imagePathHS = srcImage;
var myImage = new Image();
myImage.name = srcImage;
myImage.onload = findHHandWW;
myImage.src = srcImage;
}
//sound
if(page.soundPath){
var theSoundId = 'soundInPage' + parseInt(this.currentPageIndex); //START AT 0
var theSoundPath = this.mediasFolder + "/" + page.soundPath;
var sWidth = 280;
var sHeight = 24;
if (isMobile.any()) {
var theControls = "";
var theAutoPlay = "";
if (page.showSoundController == true){
theControls = " controls";
}
if (page.autoplaySound == true){
theAutoPlay = " autoplay";
}
htmlSound = "";
$('soundContainer').update(htmlSound);
$('soundContainer').show();
}
else{
/*JW NE SUPPORTE PAS ENCORE