<?php
include_once('inc/header.php');
/*echo '<pre>';
var_dump($_SESSION);
var_dump($_POST);
echo '<pre>';*/

$survey=R::dispense('surveys');
$survey->user_id = $_SESSION['id'];
$survey->pharmacy_id = $_POST['pharmacyid'];
$survey->date = date('Y-m-d');
$ids=R::store($survey);


for($i=1;$i<=10;$i++){
    $x='q'.$i;
    if(isset($_POST[$x])) {
        if ($i == 2 || $i == 6 || $i == 8 || $i == 9) {
            foreach ($_POST[$x] as $r) {
                $response = R::dispense('responses');
                $response->survey_id = $ids;
                $response->question = $x;
                $response->answer_id = $r;
                $idr = R::store($response);
            }

        } else {
            $response = R::dispense('responses');
            $response->survey_id = $ids;
            $response->question = $x;
            $response->answer_id = $_POST[$x];
            $idr = R::store($response);
        }
    }
    else{
        $response = R::dispense('responses');
        $response->survey_id = $ids;
        $response->question = $x;
        $response->answer_id = 0;
        $idr = R::store($response);
    }
}

?>

<div class="content-wrapper" style="margin-left: 0px !important;">
    <!-- Main content -->
    <section class="content">
        <!-- Default box -->
        <div class="callout text-center" style="background-color: paleturquoise;" >
            <h4>ENQUÊTE PHARMACIENS</h4>
            <p>GENPHARMA vous remercie pour votre collaboration.</p> <br>
                <div class="form-group">
                    <a href="index.php" class="btn btn-success btn-flat" style="text-decoration: none">Nouvelle enquête</a>
                    <!-- /.input group -->
                </div>
        </div>

    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->
<?php
include_once('inc/footer.php');
?>



