<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<link rel="stylesheet" href="{{ asset('assets/css/quiz-front.css') }}">
<title>Quiz Front Page</title>
</head>
<style id="dynamic-css"></style>
<style>
</style>
<body style="background: {% if questionnaire.getCodeCouleur() is not empty %}{{ 'background-color: ' ~ questionnaire.getCodeCouleur() ~ ' !important;' }}{% else %}url('/images/FOND-QUIZZ.png') center center fixed no-repeat; background-size: cover;{% endif %}">
<header class="d-none"> <span id="quizHeader">{{questionnaire.header}} </span> - <span id="headerGeneral">{{HeaderGeneral}}</span></header>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
const elem = document.getElementById("headerGeneral").innerText;
const quizheader = document.getElementById("quizHeader").innerText;
const formattedCode = `
${elem}
${quizheader}
`;
if (elem.trim().startsWith("<style")) {
const dynamicCss = elem;
const cssContent = elem.replace(/<style[^>]*>/, '').replace(/<\/style>/, '');
document.getElementById("dynamic-css").innerHTML = cssContent;
} else {
eval(formattedCode);
}
});
</script>
<div class="quiz-container">
<div class="image-container">
<img src="https://akoyaconfig.services-unifies.fr/uploads/logo/logo.png" alt="Akoya Logo" class="brand-image elevation-3 mb-3 " style="opacity: .8; width: 33%;">
<img src="{{ asset('/uploads/quiz/' ~ questionnaire.getImgPrincipale()) }}" alt="Questionnaire Image" class="questionnaire-image mainimg image_quiz">
</div>
<div class="congrats-container texte_done m-5 d-none">
<h2>Félicitations ! Voici votre résultat basé sur vos réponses :</h2>
</div>
<input type="hidden" id="quizId" name="quizId" value="{{ questionnaire.id }}">
<div class="content-container">
<div class="title-stepper">
<div class="progress-container">
<div class="progress-bar"></div>
<div class="stepper">
{% for question in questionnaire.questions %}
<div style="background-color: {{ questionnaire.getCouleurContraste() }};" class="step">{{ loop.index }}</div>
{% endfor %}
</div>
</div>
</div>
<img src="https://akoyaconfig.services-unifies.fr/uploads/logo/logo.png" alt="Akoya Logo" class="after d-none" style="opacity: .8; width: 33%;">
<div id="loader" class="loader"></div>
<div class="question-container" style="display: none;">
<h2 class="question"></h2>
<div class="body">
<ul class="sortable-list list-group" data-questionnaire-id="{{ questionnaire.id }}">
{% for question in questionnaire.questions %}
<li class="list-group-item mb-4 p-4 border border-secondary question-item" data-num-responses="{{ question.numResponses }}">
<div class="mb-3">
<p class="font-weight-bold">{{ question.question }}</p>
<span style="color: {{ questionnaire.getCouleurContraste() }};" >{% if question.numResponses > 1 %}
Choisir <b>{{ question.numResponses }}</b> options
{% else %}
Choisir <b>{{ question.numResponses }}</b> option
{% endif %}
</span>
</div>
<input type="hidden" id="{{ question.id }}" value="{{ question.numResponses }}" />
<ul class="pl-4">
{% for questionReponse in question.reponses %}
<li style="list-style: none !important;">
<div class="mb-2">
<div class="form-check">
<input type="checkbox" class="form-check-input edit-response-checkbox" id="editResponse-{{ question.id }}-{{ questionReponse.id }}" data-rep-number="{{ question.numResponses }}" data-response-id="{{ questionReponse.id }}" required>
<label class="form-check-label" for="editResponse-{{ question.id }}-{{ questionReponse.id }}">{{ questionReponse.content }}</label>
</div>
</div>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
<button class="next-btn" style="background-color: {{ questionnaire.getCouleurContraste() }} !important;">Valider</button>
</div>
</div>
<button class="cta" id="start-button" style="--background-color: {{ questionnaire.getCouleurContraste() }};">
<input type="hidden" value="{{ questionnaire.getCouleurContraste() }}" id="buttons-color">
<span>Commencer</span>
<svg viewBox="0 0 13 10" height="10px" width="15px">
<path d="M1,5 L11,5"></path>
<polyline points="8 1 12 5 8 9"></polyline>
</svg>
</button>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
<script>
$(document).ready(function () {
$("#start-button").click(function () {
console.log("click");
$("#loader").show();
$(this).hide();
setTimeout(function () {
$("#loader").hide();
$(".question-container").show();
}, 2000);
});
});
</script>
<script>
let currentNumReponses = 0;
$(document).ready(function() {
$(document).on('submit', '.userDataForm', function(event) {
event.preventDefault();
if (!$('#acceptData').is(':checked')) {
toastr.error("Vous devez accepter les conditions pour pouvoir envoyer par mail.");
return false;
}
var allInputsValid = true;
var formData = {};
$(this).find('input').each(function() {
var input = $(this);
var inputName = input.attr('name');
var inputSociete = input.attr('societe');
var inputPrenom = input.attr('prenom');
var inputTelephone = input.attr('telephone');
var inputEmail= input.attr('email');
var inputValue = input.val().trim();
if (inputName === 'prenom' && inputValue === '') {
allInputsValid = false;
toastr.error("Le prénom est obligatoire.");
return false;
}
if (inputName === 'societe' && inputValue === '') {
// Societe field is optional, so no validation required
return true;
}
if (inputName === 'telephone' && inputValue === '') {
allInputsValid = false;
toastr.error("Le numéro de téléphone est obligatoire.");
return false;
}
if (inputName === 'email' && inputValue === '') {
allInputsValid = false;
toastr.error("L'adresse e-mail est obligatoire.");
return false;
}
if (inputName === 'nom' && inputValue === '') {
allInputsValid = false;
toastr.error("Le nom est obligatoire.");
return false;
}
});
var profilesData = $('#profilesDataContainer').text();
const pointsData = {};
$.each(JSON.parse(profilesData), function (profileId, points) {
// Convert the profileId to a string before using it as a key
pointsData[profileId.toString()] = points;
});
formData['profiles'] = JSON.stringify(pointsData);
formData['prenom'] = $('#prenom').val().trim();
formData['societe'] = $('#societe').val().trim();
formData['telephone'] = $('#telephone').val().trim();
formData['email'] = $('#email').val().trim();
formData['nom'] = $('#nom').val().trim();
formData['quizId'] = $('#quizId').val();
if (!allInputsValid) {
return false;
}
$.ajax({
method: 'POST',
url: '/candidat/save',
data: formData,
dataType: 'json',
success: function(response) {
toastr.success(response.success);
location.reload();
},
error: function(xhr, status, error) {
const errorMessage = xhr.responseJSON ? xhr.responseJSON.error : 'An error occurred while saving your data.';
toastr.error(errorMessage);
}
});
});
const $questions = $('.question-item');
let currentQuestionIndex = 0;
let questionResponses = new Array($questions.length).fill(null).map(() => []);
function showQuestion(index) {
$questions.hide();
var currentNumReponses = parseInt($($questions[index]).find('input[type="hidden"]').val());
updateActiveStep(index);
//console.log(currentNumReponses);
$($questions[index]).show();
}
function checkNextButton() {
$('.next-btn').prop('disabled', $('.edit-response-checkbox:checked').length === 0);
}
function calculateScore() {
let scoreDetails = '';
const url = '/findProfile';
const requestData = JSON.stringify(questionResponses);
for (let i = 0; i < questionResponses.length; i++) {
const question = $questions.eq(i).find('.font-weight-bold').text();
const selectedResponseIds = questionResponses[i];
if (selectedResponseIds.length > 0) {
let questionScoreDetails = `<p><strong>${question}</strong><br>`;
for (const responseId of selectedResponseIds) {
const responseText = $(`#editResponse${responseId}`).siblings('.form-check-label').text();
questionScoreDetails += `- ${responseText}<br>`;
}
questionScoreDetails += '</p>';
scoreDetails += questionScoreDetails;
}
}
var buttonColor = $("#buttons-color").val();
$.ajax({
url: url,
method: 'POST',
data: requestData,
contentType: 'application/json',
success: function(response) {
let scoreDetails = `
<div class="justify-content-center mb-1 resultat1">
`;
var profileIds = [];
var mostPointsProfile;
let pointsData = {};
for (let i = 0; i < response.length; i++) {
const responseDetails = response[i];
const profile = responseDetails.profile;
const profileId = response[i].profile.id;
profileIds.push(profileId);
const points = responseDetails.points;
pointsData[profileId] = points;
if (profile) {
const responseNumber = i + 1;
const profileNumber = responseDetails.points === 0 ? 'aucun' : responseDetails.points;
let profileCardClass = 'winnerprofile';
if (i === 0) {
profileCardClass += ' winner';
}
const showPoints = responseDetails.testModeEnabled;
console.log(showPoints);
let pointsHtml = '';
if (showPoints) {
pointsHtml = `<p class="profile-points">Points: ${responseDetails.points}</p>`;
}
//mostPointsProfile = responseProfiles[0];
scoreDetails += `
<div class="mb-4">
<div class="${profileCardClass}">
<h3>${ i === 0 ? "Votre profil dominant" : "Mais aussi..."}</h3>
<div class="profile-details winner-profile}">
<div class="profile-picture">
<img class="winner-picture ${i === 0 ? ' resultat1_image' : 'resultat_secondaire_image'}" style="width: 280px ; height: 280px"' src="{{ asset('uploads/profils/${profile.imageProfil}') }}" alt="${profile.nomProfil}">
</div>
<div class="${i === 0 ? 'profile-info resultat1_texte' : 'profile-info resultat_secondaire_texte'}">
<h5 class="profile-name">${profile.nomProfil}</h5>
<p class="profile-description">${profile.textCourt}</p>
${pointsHtml}
</div>
${i === 0 ? '<div class="winner-icon"><i class="fas fa-trophy"></i></div>' : ''}
</div>
</div>
</div>
`;
if (i === 0) {
scoreDetails += `
</div>
<div class="justify-content-around">
`;
}
}
}
console.log(pointsData)
scoreDetails += `
</div> <br>
<p class="text-muted">Vous voulez en savoir plus? Souhaitez vous avoir un rapport complet et des conseils liés a votre résultat? Rien de plus facile !
renseigner vos coordonnées ci desous, un conseillé Akoya va vous recontacter trés vite !</p>
`;
var profilesData = JSON.stringify(pointsData);
//$('#profilesDataContainer').text(profilesData);
// Add the user data form here
scoreDetails += `
<form class="userDataForm ml-1 mt-5">
<h3>Informations personnelles :</h3>
<div id="profilesDataContainer" style="display: none;">${profilesData}</div>
<div class="form-row">
<div class="form-group col-3">
<label for="nom">Nom* :</label>
<input type="text" class="form-control" id="nom" name="nom">
</div>
<div class="form-group col-3">
<label for="prenom">Prénom* :</label>
<input type="text" class="form-control" id="prenom" name="prenom">
</div>
<div class="form-group col-3">
<label for="societe">Société :</label>
<input type="text" class="form-control" id="societe" name="societe">
</div>
<div class="form-group col-3">
<label for="telephone">Téléphone* :</label>
<input type="tel" class="form-control" id="telephone" name="telephone">
</div>
</div>
<div class="form-group">
<label for="email">Adresse e-mail* :</label>
<input type="email" class="form-control" id="email" name="email">
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="acceptData" name="acceptData">
<label class="form-check-label" for="acceptData">J'accepte que mes données ci-dessus soient enregistrées et conservées pour une durée de 12 mois par AKOYA.
Je peux à tout moment contacter AKOYA par email contact@akoya-academie.fr pour demander la suppresison de mes données</label>
</div><br>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="contactMe" name="contactMe">
<label class="form-check-label" for="contactMe">Je souhaite être contacté(e) par Akoya pour approfondir mon résultat</label>
</div><br>
<button type="submit" style="background: ${buttonColor} !important;" class="btn text-white">Valider</button>
</form>
`;
$('.body').html(scoreDetails);
$('.progress-container').hide();
$('.image-container').hide();
$('.after').removeClass('d-none');
},
error: function(xhr, textStatus, errorThrown) {
// Handle error if the AJAX request fails
console.log('Error:', errorThrown);
}
});
}
function nextQuestion() {
const selectedResponses = $('.edit-response-checkbox:checked').map(function() {
const responseId = $(this).data('response-id');
const repNumber = $(this).data('rep-number');
console.log(responseId, repNumber);
return { responseId, repNumber };
}).get();
//const currentNumReponses = parseInt($('.question-item.active').data('num-responses'));
if (selectedResponses.length === 0) {
toastr.error("Vous devez sélectionner au moins une réponse avant de passer à la question suivante.");
return;
}
const totalSelectedReps = selectedResponses.map(response => response.repNumber);
const hasUnexpectedRepNumber = selectedResponses.some(response => response.repNumber);
console.log(totalSelectedReps.length, );
if (totalSelectedReps.length !== totalSelectedReps[0]) {
toastr.error("Vous devez sélectionner exactement " + totalSelectedReps[0] + " réponse(s) pour cette question.");
return;
}
questionResponses[currentQuestionIndex] = selectedResponses.map(response => response.responseId);
// Uncheck all checkboxes before moving to the next question
$('.edit-response-checkbox').prop('checked', false);
if (currentQuestionIndex < $questions.length - 1) {
showQuestion(currentQuestionIndex + 1);
currentQuestionIndex++;
$('.next-btn').prop('disabled', true);
checkNextButton();
updateActiveStep(currentQuestionIndex);
} else {
calculateScore();
}
}
// Show the first question initially
showQuestion(currentQuestionIndex);
$('.edit-response-checkbox').on('change', function() {
checkNextButton();
});
$('.next-btn').on('click', function() {
nextQuestion();
});
function updateActiveStep(index) {
$('.step').removeClass('active');
$('.step:nth-child(' + (index + 1) + ')').addClass('active');
}
});
</script>
</body>
</html>