<?php 
 include("../includes/connect.php");

// TODO: sanitize input
$externalId = $_POST['externalId'];

$cid = explode("-",$externalId);
$campaignId = $cid[1];


$queryMeta = $connection->query("SELECT meta_key,meta_value FROM campaigns_meta WHERE campaign_id = '$campaignId' AND meta_key = 'questionset_after'");
$datiMeta = $queryMeta->fetchAll(PDO::FETCH_KEY_PAIR);

if(count($datiMeta) != 0)
{

//print_r($datiMeta);

$questionsetId = $datiMeta['questionset_after'];

$queryDomande = $connection->query("SELECT id FROM profilation_questions WHERE sets_in = '$questionsetId'");
$datiDomande = $queryDomande->fetchAll(PDO::FETCH_COLUMN);
//print_r($datiDomande);

 ?>
{"success":true,"questions":<?php echo json_encode($datiDomande)?>}
<?php
}
else
{
?>
{"success":false}
<?php 
}
?>