<?php 
$idCampaign = $_GET['id'];

$data = $connection->query("SELECT * FROM campaigns WHERE id = '$idCampaign'");
$campaignData = $data->fetchAll(PDO::FETCH_ASSOC);

$meta = $connection->query("SELECT meta_key,meta_value FROM campaigns_meta WHERE campaign_id = '$idCampaign'");
$campaignMeta = $meta->fetchAll(PDO::FETCH_KEY_PAIR);


// domande pre-form
$questionSet = $campaignMeta['questionset'];
// domande post-form
$profilationSet = $campaignMeta['questionset_after'];


if($profilationSet != "")
{
	$profilationQ = $connection->query("SELECT id,text FROM profilation_questions WHERE sets_in = '$profilationSet'");
	$profilationQuestions = $profilationQ->fetchAll(PDO::FETCH_ASSOC);
	//print_r($profilationQuestions);

	$profilationA = $connection->query("SELECT question_id,id,text FROM profilation_answers WHERE sets_in = '$profilationSet'");
	$profilationAnswers = $profilationA->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
//print_r($profilationAnswers);
}
else
{
	$profilationQuestions = array();
}
?>
<link href="assets/plugins/custom/datatables/datatables.bundle.css" rel="stylesheet" type="text/css" />
<div class="kt-container  kt-container--fluid  kt-grid__item kt-grid__item--fluid">
							<div class="kt-portlet kt-portlet--mobile">
								<div class="kt-portlet__head kt-portlet__head--lg">
									<div class="kt-portlet__head-label">
										<span class="kt-portlet__head-icon">
											<i class="kt-font-brand flaticon2-line-chart"></i>
										</span>
										<h3 class="kt-portlet__head-title">
											Lista lead raccolte per la campagna <b><?php echo $campaignData[0]['campaign_name'] ?></b>
										</h3>
									</div>
									
								</div>
								<div class="kt-portlet__body">

<div id="filtri" style="width:800px";><? if($_SESSION['id_user']!= 5 ) { ?>
<div style="width:300px;float:left;" >
<label>Sesso:</label> <select id="sesso"><option value=""></option><option value="m">Uomo</option><option value="F">Donna</option></select>
<br />
<label>Da CAP:</label> <input type="text" id="capMin" size="5" maxlength="5"> <label>A CAP:</label> <input type="text" id="capMax" size="5" maxlength="5">
<br />
<label>Città:</label> <input type="text" id="citta"> 
<br />
<!-- <label>Provincia:</label> <input type="text" id="provincia"> -->
</div><?}?>

<script>
	window.campaignId = <?php echo $idCampaign; ?>;
	window.filtersNum = <?php echo count($profilationQuestions); ?>;
</script>


<div style="width:300px;float:right;">
<?php 
for($pq = 0; $pq < count($profilationQuestions); $pq++)
{
	echo $profilationQuestions[$pq]['text'] . "<br />";
?>
<select class="filter" id="filtro<?php echo $pq; ?>" data-qid="<?php echo $profilationQuestions[$pq]['id']; ?>"><option value="0"></option>
<?php 
for($pa = 0; $pa < count($profilationAnswers[$profilationQuestions[$pq]['id']]); $pa++)
{
?>
<option value="<?php echo $profilationAnswers[$profilationQuestions[$pq]['id']][$pa]['id']; ?>"><?php echo $profilationAnswers[$profilationQuestions[$pq]['id']][$pa]['text'] ; ?></option>
<?php 
}
?>
</select> <br />
<?php	
}

?>
</div>

<br style="clear:both" />
<? if($_SESSION['id_user']!= 5 ) { ?><button type="button" class="btn btn-info btn-custom filtra">Filtra</button>
<button type="button" class="btn btn-info btn-custom esporta">Esporta</button><?}?>
</div>
<br /><br />
									<!--begin: Datatable -->
									<table class="table table-striped- table-bordered table-hover table-checkable" id="kt_table_1">
										<thead>
											<tr>
												<th>Nome</th>
												<th>Cognome</th>
												<th>Sesso</th>
												<th>Nascita</th>
												<th>Email</th>
												<th>Cellulare</th>
												<th>Cap</th>
												<th>Città</th>
												<th>Indirizzo</th>
												<th>N. civico</th>
												<th>Flag privacy</th>
											</tr>
										</thead>
										

<tfoot>
											<tr>
												<th>Nome</th>
												<th>Cognome</th>
												<th>Sesso</th>
												<th>Nascita</th>
												<th>Email</th>
												<th>Cellulare</th>
												<th>Cap</th>
												<th>Città</th>
												<th>Indirizzo</th>
												<th>N. civico</th>
												<th>Flag privacy</th>
											</tr>
										</tfoot>

									</table>

									<!--end: Datatable -->



								</div>
							</div>
						</div>
