<!--- 

Developer: Coralys Cubero Rivera
Fall 2018

This file contains the function that allows us to associate a questionnaire that already exists, 
to a particular experience. 



Updated by: Víctor A. Hernández
Summer 2019

--->

<?php

	require_once 'processes/config.php';
	require_once 'processes/dbh.inc.php';

	// IF USER ENTERS PAGE AFTER SUBMIT BUTTON HAS BEEN PRESSED (FROM viewExperience.php), ADD QUESTIONNAIRE TO EXPERIENCE
	// ELSE DO NOTHING
	// WARNING: ESTO NO PROVEE PROTECCIÓN POR SI EL VALOR DEL SELECT ES '' (CUESTIONARIO INVÁLIDO) O SI YA HAY UN CUESTIONARIO REPETIDO
	if(isset($_POST['submitQuestionnaireQuestion'])) {
		$query = "INSERT INTO `experience_questionnair` (`id_experience`, `id_questionnair`) VALUES ('".$_POST['id_experience']."', '".$_POST['questionnaire']."');";
		if(!mysqli_query($connection, $query)) die("Error: ".mysqli_error($connection));
		// WHY NOT USE header INSTEAD OF window.top.location?
		//header('Location: http://emaapp.online/admin_nuevo/viewExperience.php?='.$_POST['id_experience']);
		//exit();
		echo "<script>window.top.location='http://emaapp.online/admin_nuevo/viewExperience.php?view=".$_POST['id_experience']."'</script>";
	
	}