function display_results($token) { $rank = retrieve_results($token); $total_step = get_steps(); $first = key($rank); $desc = get_description($first); echo '<p>Tu es donc <strong> ' . $first . '<strong><p><p class="hero_desc">' . $desc . '</p>'; echo '<p>Plus de détails : </p>'; foreach ($rank as $key => $profile) { $percent = round($profile / $total_step * 100); echo 'Tu es à ' . $percent . ' % ' . $key . '<br/>'; } }
<?php session_start(); $nb_steps = get_steps(); /* Token generation and initialization of the current step */ if (empty($_SESSION['step'])) { $_SESSION['step'] = 1; $_SESSION["token"] = generate_random_string(); } else { if ($_SESSION['step'] > $nb_steps) { $_SESSION['step'] = 1; $_SESSION["token"] = generate_random_string(); } } /* If some datas have been submited, we go to the next step */ if (!empty($_POST) && $_SESSION['step'] <= $nb_steps) { $id_answer = trim($_POST["id_answer"]); $token = $_SESSION["token"]; $step = $_SESSION["step"]; if (check_answer($id_answer, $step)) { $_SESSION["step"]++; add_user_answer($token, $id_answer); if ($_SESSION['step'] > $nb_steps) { header("Location:result.php"); } } } $progress = $_SESSION['step'] / $nb_steps * 100; $question = get_question($_SESSION['step']); $answers = get_answers($_SESSION['step']);
/** * mostrar em que etapa do cadastro o usuário está */ function show_steps($step) { $steps = get_steps(); if (empty($step)) { $step = 'step1'; } ?> <?php if (is_array($steps)) { ?> <div class="steps__content"> <ol class="steps"> <?php foreach ($steps as $key => $titulo) { ?> <li> <span title="<?php print $titulo; if ($key == $step) { print ' você está aqui'; } ?> " class="<?php if ($key == $step) { print 'current'; } ?> "><?php print $titulo; ?> </span> </li> <?php } ?> </ol> </div> <?php } ?> <?php }
<?php session_start(); $rank = retrieve_results($_SESSION["token"]); $first_key = array_keys($rank)[0]; // We add to the database the result add_to_result_list($first_key, $_SESSION["token"]); $total_step = get_steps(); $infos = array(); foreach ($rank as $id => $value) { $infos[] = get_informations($id); }