<?php
// This script and data application were generated by AppGini 5.81
// Download AppGini for free from https://bigprof.com/appgini/download/

	$currDir=dirname(__FILE__);
	include("$currDir/defaultLang.php");
	include("$currDir/language.php");
	include("$currDir/lib.php");
	@include("$currDir/hooks/assurances.php");
	include("$currDir/assurances_dml.php");

	// mm: can the current member access this page?
	$perm=getTablePermissions('assurances');
	if(!$perm[0]) {
		echo error_message($Translation['tableAccessDenied'], false);
		echo '<script>setTimeout("window.location=\'index.php?signOut=1\'", 2000);</script>';
		exit;
	}

	$x = new DataList;
	$x->TableName = "assurances";

	// Fields that can be displayed in the table view
	$x->QueryFieldsTV = array(
		"`assurances`.`idassurance`" => "idassurance",
		"if(`assurances`.`date`,date_format(`assurances`.`date`,'%d/%m/%Y'),'')" => "date",
		"IF(    CHAR_LENGTH(`clients1`.`nom_prenom`), CONCAT_WS('',   `clients1`.`nom_prenom`), '') /* Nom & pr&#233;nom */" => "nom_prenom",
		"IF(    CHAR_LENGTH(`intermediares1`.`intermediare`), CONCAT_WS('',   `intermediares1`.`intermediare`), '') /* Intermediare */" => "intermediare",
		"IF(    CHAR_LENGTH(`pays1`.`pays`), CONCAT_WS('',   `pays1`.`pays`), '') /* Pays de residence */" => "pays_residence",
		"IF(    CHAR_LENGTH(`clients2`.`adresse`), CONCAT_WS('',   `clients2`.`adresse`), '') /* Adresse */" => "adresse",
		"IF(    CHAR_LENGTH(`clients1`.`telephone`), CONCAT_WS('',   `clients1`.`telephone`), '') /* Telephone */" => "telephone",
		"IF(    CHAR_LENGTH(`clients1`.`email`), CONCAT_WS('',   `clients1`.`email`), '') /* Email */" => "email",
		"IF(    CHAR_LENGTH(`pays2`.`pays`), CONCAT_WS('',   `pays2`.`pays`), '') /* Destination */" => "destination",
		"IF(    CHAR_LENGTH(`formule1`.`formule`), CONCAT_WS('',   `formule1`.`formule`), '') /* Formule */" => "formule",
		"`assurances`.`certificat`" => "certificat",
		"if(`assurances`.`date_depart`,date_format(`assurances`.`date_depart`,'%d/%m/%Y'),'')" => "date_depart",
		"if(`assurances`.`date_retour`,date_format(`assurances`.`date_retour`,'%d/%m/%Y'),'')" => "date_retour",
		"IF(    CHAR_LENGTH(`clients1`.`passport`), CONCAT_WS('',   `clients1`.`passport`), '') /* Passport */" => "passport",
		"`assurances`.`beneficiaire`" => "beneficiaire",
		"IF(    CHAR_LENGTH(`clients3`.`nom_prenom`), CONCAT_WS('',   `clients3`.`nom_prenom`), '') /* Nom & Pr&#233;nom */" => "nom_prenomb",
		"IF(    CHAR_LENGTH(if(`clients1`.`date_naissance`,date_format(`clients1`.`date_naissance`,'%d/%m/%Y'),'')), CONCAT_WS('',   if(`clients1`.`date_naissance`,date_format(`clients1`.`date_naissance`,'%d/%m/%Y'),'')), '') /* Date de naissance */" => "date_de_naissance",
		"`assurances`.`dossier_pdf`" => "dossier_pdf",
		"`assurances`.`dossier_zippe`" => "dossier_zippe",
		"`assurances`.`statut`" => "statut",
		"`assurances`.`questionnaire_medical`" => "questionnaire_medical",
		"`assurances`.`question1`" => "question1",
		"`assurances`.`question2`" => "question2",
		"`assurances`.`question2a`" => "question2a",
		"`assurances`.`question3`" => "question3",
		"`assurances`.`question4`" => "question4",
		"`assurances`.`question5`" => "question5",
		"`assurances`.`prime_total`" => "prime_total",
	);
	// mapping incoming sort by requests to actual query fields
	$x->SortFields = array(
		1 => '`assurances`.`idassurance`',
		2 => '`assurances`.`date`',
		3 => '`clients1`.`nom_prenom`',
		4 => '`intermediares1`.`intermediare`',
		5 => '`pays1`.`pays`',
		6 => '`clients2`.`adresse`',
		7 => '`clients1`.`telephone`',
		8 => '`clients1`.`email`',
		9 => '`pays2`.`pays`',
		10 => '`formule1`.`formule`',
		11 => 11,
		12 => '`assurances`.`date_depart`',
		13 => '`assurances`.`date_retour`',
		14 => '`clients1`.`passport`',
		15 => 15,
		16 => '`clients3`.`nom_prenom`',
		17 => 'date_format(`clients1`.`date_naissance`,\'%d/%m/%Y\')',
		18 => 18,
		19 => 19,
		20 => 20,
		21 => 21,
		22 => 22,
		23 => 23,
		24 => 24,
		25 => 25,
		26 => 26,
		27 => 27,
		28 => 28,
	);

	// Fields that can be displayed in the csv file
	$x->QueryFieldsCSV = array(
		"`assurances`.`idassurance`" => "idassurance",
		"if(`assurances`.`date`,date_format(`assurances`.`date`,'%d/%m/%Y'),'')" => "date",
		"IF(    CHAR_LENGTH(`clients1`.`nom_prenom`), CONCAT_WS('',   `clients1`.`nom_prenom`), '') /* Nom & pr&#233;nom */" => "nom_prenom",
		"IF(    CHAR_LENGTH(`intermediares1`.`intermediare`), CONCAT_WS('',   `intermediares1`.`intermediare`), '') /* Intermediare */" => "intermediare",
		"IF(    CHAR_LENGTH(`pays1`.`pays`), CONCAT_WS('',   `pays1`.`pays`), '') /* Pays de residence */" => "pays_residence",
		"IF(    CHAR_LENGTH(`clients2`.`adresse`), CONCAT_WS('',   `clients2`.`adresse`), '') /* Adresse */" => "adresse",
		"IF(    CHAR_LENGTH(`clients1`.`telephone`), CONCAT_WS('',   `clients1`.`telephone`), '') /* Telephone */" => "telephone",
		"IF(    CHAR_LENGTH(`clients1`.`email`), CONCAT_WS('',   `clients1`.`email`), '') /* Email */" => "email",
		"IF(    CHAR_LENGTH(`pays2`.`pays`), CONCAT_WS('',   `pays2`.`pays`), '') /* Destination */" => "destination",
		"IF(    CHAR_LENGTH(`formule1`.`formule`), CONCAT_WS('',   `formule1`.`formule`), '') /* Formule */" => "formule",
		"`assurances`.`certificat`" => "certificat",
		"if(`assurances`.`date_depart`,date_format(`assurances`.`date_depart`,'%d/%m/%Y'),'')" => "date_depart",
		"if(`assurances`.`date_retour`,date_format(`assurances`.`date_retour`,'%d/%m/%Y'),'')" => "date_retour",
		"IF(    CHAR_LENGTH(`clients1`.`passport`), CONCAT_WS('',   `clients1`.`passport`), '') /* Passport */" => "passport",
		"`assurances`.`beneficiaire`" => "beneficiaire",
		"IF(    CHAR_LENGTH(`clients3`.`nom_prenom`), CONCAT_WS('',   `clients3`.`nom_prenom`), '') /* Nom & Pr&#233;nom */" => "nom_prenomb",
		"IF(    CHAR_LENGTH(if(`clients1`.`date_naissance`,date_format(`clients1`.`date_naissance`,'%d/%m/%Y'),'')), CONCAT_WS('',   if(`clients1`.`date_naissance`,date_format(`clients1`.`date_naissance`,'%d/%m/%Y'),'')), '') /* Date de naissance */" => "date_de_naissance",
		"`assurances`.`dossier_pdf`" => "dossier_pdf",
		"`assurances`.`dossier_zippe`" => "dossier_zippe",
		"`assurances`.`statut`" => "statut",
		"`assurances`.`questionnaire_medical`" => "questionnaire_medical",
		"`assurances`.`question1`" => "question1",
		"`assurances`.`question2`" => "question2",
		"`assurances`.`question2a`" => "question2a",
		"`assurances`.`question3`" => "question3",
		"`assurances`.`question4`" => "question4",
		"`assurances`.`question5`" => "question5",
		"`assurances`.`prime_total`" => "prime_total",
	);
	// Fields that can be filtered
	$x->QueryFieldsFilters = array(
		"`assurances`.`idassurance`" => "ID",
		"`assurances`.`date`" => "Date",
		"IF(    CHAR_LENGTH(`clients1`.`nom_prenom`), CONCAT_WS('',   `clients1`.`nom_prenom`), '') /* Nom & pr&#233;nom */" => "Nom & pr&#233;nom",
		"IF(    CHAR_LENGTH(`intermediares1`.`intermediare`), CONCAT_WS('',   `intermediares1`.`intermediare`), '') /* Intermediare */" => "Intermediare",
		"IF(    CHAR_LENGTH(`pays1`.`pays`), CONCAT_WS('',   `pays1`.`pays`), '') /* Pays de residence */" => "Pays de residence",
		"IF(    CHAR_LENGTH(`clients2`.`adresse`), CONCAT_WS('',   `clients2`.`adresse`), '') /* Adresse */" => "Adresse",
		"IF(    CHAR_LENGTH(`clients1`.`telephone`), CONCAT_WS('',   `clients1`.`telephone`), '') /* Telephone */" => "Telephone",
		"IF(    CHAR_LENGTH(`clients1`.`email`), CONCAT_WS('',   `clients1`.`email`), '') /* Email */" => "Email",
		"IF(    CHAR_LENGTH(`pays2`.`pays`), CONCAT_WS('',   `pays2`.`pays`), '') /* Destination */" => "Destination",
		"IF(    CHAR_LENGTH(`formule1`.`formule`), CONCAT_WS('',   `formule1`.`formule`), '') /* Formule */" => "Formule",
		"`assurances`.`certificat`" => "N&#176; Certificat",
		"`assurances`.`date_depart`" => "Date depart",
		"`assurances`.`date_retour`" => "Date retour",
		"IF(    CHAR_LENGTH(`clients1`.`passport`), CONCAT_WS('',   `clients1`.`passport`), '') /* Passport */" => "Passport",
		"`assurances`.`beneficiaire`" => "Liste du B&#233;n&#233;ficiaire",
		"IF(    CHAR_LENGTH(`clients3`.`nom_prenom`), CONCAT_WS('',   `clients3`.`nom_prenom`), '') /* Nom & Pr&#233;nom */" => "Nom & Pr&#233;nom",
		"IF(    CHAR_LENGTH(if(`clients1`.`date_naissance`,date_format(`clients1`.`date_naissance`,'%d/%m/%Y'),'')), CONCAT_WS('',   if(`clients1`.`date_naissance`,date_format(`clients1`.`date_naissance`,'%d/%m/%Y'),'')), '') /* Date de naissance */" => "Date de naissance",
		"`assurances`.`dossier_pdf`" => "Dossier",
		"`assurances`.`dossier_zippe`" => "Dossier compress&#233;",
		"`assurances`.`statut`" => "Statut",
		"`assurances`.`questionnaire_medical`" => "QUESTIONNAIRE MEDICAL",
		"`assurances`.`question1`" => "Etes-vous actuellement en bonne sant&#233; ?",
		"`assurances`.`question2`" => "Avez-vous un d&#233;faut de constitution, une infirmit&#233; ou une maladie chronique ?",
		"`assurances`.`question2a`" => "Si oui, en pr&#233;ciser la nature",
		"`assurances`.`question3`" => "Avez-vous dans le pass&#233; (&#224; quel &#226;ge) &#233;t&#233; atteint d\'affection pulmonaire, nerveuse, nerveuse, cardiaque, r&#233;nale, d\'albumine, de diab&#232;te, maladie de foie, de cancer, d\'an&#233;mie, d\'h&#233;patite infectieuse grave ?",
		"`assurances`.`question4`" => "Suivez-vous actuellement un traitement ?",
		"`assurances`.`question5`" => "Indiquez vos maladies ant&#233;rieures et l\'&#233;poque &#224; laquelle vous les avez contract&#233;s ?",
		"`assurances`.`prime_total`" => "PRIME TOTALE",
	);

	// Fields that can be quick searched
	$x->QueryFieldsQS = array(
		"`assurances`.`idassurance`" => "idassurance",
		"if(`assurances`.`date`,date_format(`assurances`.`date`,'%d/%m/%Y'),'')" => "date",
		"IF(    CHAR_LENGTH(`clients1`.`nom_prenom`), CONCAT_WS('',   `clients1`.`nom_prenom`), '') /* Nom & pr&#233;nom */" => "nom_prenom",
		"IF(    CHAR_LENGTH(`intermediares1`.`intermediare`), CONCAT_WS('',   `intermediares1`.`intermediare`), '') /* Intermediare */" => "intermediare",
		"IF(    CHAR_LENGTH(`pays1`.`pays`), CONCAT_WS('',   `pays1`.`pays`), '') /* Pays de residence */" => "pays_residence",
		"IF(    CHAR_LENGTH(`clients2`.`adresse`), CONCAT_WS('',   `clients2`.`adresse`), '') /* Adresse */" => "adresse",
		"IF(    CHAR_LENGTH(`clients1`.`telephone`), CONCAT_WS('',   `clients1`.`telephone`), '') /* Telephone */" => "telephone",
		"IF(    CHAR_LENGTH(`clients1`.`email`), CONCAT_WS('',   `clients1`.`email`), '') /* Email */" => "email",
		"IF(    CHAR_LENGTH(`pays2`.`pays`), CONCAT_WS('',   `pays2`.`pays`), '') /* Destination */" => "destination",
		"IF(    CHAR_LENGTH(`formule1`.`formule`), CONCAT_WS('',   `formule1`.`formule`), '') /* Formule */" => "formule",
		"`assurances`.`certificat`" => "certificat",
		"if(`assurances`.`date_depart`,date_format(`assurances`.`date_depart`,'%d/%m/%Y'),'')" => "date_depart",
		"if(`assurances`.`date_retour`,date_format(`assurances`.`date_retour`,'%d/%m/%Y'),'')" => "date_retour",
		"IF(    CHAR_LENGTH(`clients1`.`passport`), CONCAT_WS('',   `clients1`.`passport`), '') /* Passport */" => "passport",
		"`assurances`.`beneficiaire`" => "beneficiaire",
		"IF(    CHAR_LENGTH(`clients3`.`nom_prenom`), CONCAT_WS('',   `clients3`.`nom_prenom`), '') /* Nom & Pr&#233;nom */" => "nom_prenomb",
		"IF(    CHAR_LENGTH(if(`clients1`.`date_naissance`,date_format(`clients1`.`date_naissance`,'%d/%m/%Y'),'')), CONCAT_WS('',   if(`clients1`.`date_naissance`,date_format(`clients1`.`date_naissance`,'%d/%m/%Y'),'')), '') /* Date de naissance */" => "date_de_naissance",
		"`assurances`.`dossier_pdf`" => "dossier_pdf",
		"`assurances`.`dossier_zippe`" => "dossier_zippe",
		"`assurances`.`statut`" => "statut",
		"`assurances`.`questionnaire_medical`" => "questionnaire_medical",
		"`assurances`.`question1`" => "question1",
		"`assurances`.`question2`" => "question2",
		"`assurances`.`question2a`" => "question2a",
		"`assurances`.`question3`" => "question3",
		"`assurances`.`question4`" => "question4",
		"`assurances`.`question5`" => "question5",
		"`assurances`.`prime_total`" => "prime_total",
	);

	// Lookup fields that can be used as filterers
	$x->filterers = array('nom_prenom' => 'Nom & pr&#233;nom', 'intermediare' => 'Intermediare', 'pays_residence' => 'Pays de residence', 'adresse' => 'Adresse', 'destination' => 'Destination', 'formule' => 'Formule', 'nom_prenomb' => 'Nom & Pr&#233;nom', );

	$x->QueryFrom = "`assurances` LEFT JOIN `clients` as clients1 ON `clients1`.`matricule_client`=`assurances`.`nom_prenom` LEFT JOIN `intermediares` as intermediares1 ON `intermediares1`.`idintermediaire`=`assurances`.`intermediare` LEFT JOIN `pays` as pays1 ON `pays1`.`idpays`=`assurances`.`pays_residence` LEFT JOIN `clients` as clients2 ON `clients2`.`matricule_client`=`assurances`.`adresse` LEFT JOIN `pays` as pays2 ON `pays2`.`idpays`=`assurances`.`destination` LEFT JOIN `formule` as formule1 ON `formule1`.`idformule`=`assurances`.`formule` LEFT JOIN `clients` as clients3 ON `clients3`.`matricule_client`=`assurances`.`nom_prenomb` ";
	$x->QueryWhere = '';
	$x->QueryOrder = '';

	$x->AllowSelection = 1;
	$x->HideTableView = ($perm[2]==0 ? 1 : 0);
	$x->AllowDelete = $perm[4];
	$x->AllowMassDelete = true;
	$x->AllowInsert = $perm[1];
	$x->AllowUpdate = $perm[3];
	$x->SeparateDV = 1;
	$x->AllowDeleteOfParents = 0;
	$x->AllowFilters = 1;
	$x->AllowSavingFilters = 1;
	$x->AllowSorting = 1;
	$x->AllowNavigation = 1;
	$x->AllowPrinting = 1;
	$x->AllowPrintingDV = 1;
	$x->AllowCSV = 1;
	$x->RecordsPerPage = 10;
	$x->QuickSearch = 1;
	$x->QuickSearchText = $Translation["quick search"];
	$x->ScriptFileName = "assurances_view.php";
	$x->RedirectAfterInsert = "assurances_view.php?SelectedID=#ID#";
	$x->TableTitle = "ASSURANCES";
	$x->TableIcon = "resources/table_icons/color_wheel.png";
	$x->PrimaryKey = "`assurances`.`idassurance`";
	$x->DefaultSortField = '`assurances`.`date`';
	$x->DefaultSortDirection = 'desc';

	$x->ColWidth   = array(  150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150);
	$x->ColCaption = array("Date", "Nom & pr&#233;nom", "Intermediare", "Pays de residence", "Adresse", "Telephone", "Email", "Destination", "Formule", "N&#176; Certificat", "Date depart", "Date retour", "Passport", "Liste du B&#233;n&#233;ficiaire", "Nom & Pr&#233;nom", "Date de naissance", "Dossier compress&#233;", "Statut", "QUESTIONNAIRE MEDICAL", "Etes-vous actuellement en bonne sant&#233; ?", "Avez-vous un d&#233;faut de constitution, une infirmit&#233; ou une maladie chronique ?", "Si oui, en pr&#233;ciser la nature", "Avez-vous dans le pass&#233; (&#224; quel &#226;ge) &#233;t&#233; atteint d'affection pulmonaire, nerveuse, nerveuse, cardiaque, r&#233;nale, d'albumine, de diab&#232;te, maladie de foie, de cancer, d'an&#233;mie, d'h&#233;patite infectieuse grave ?", "Suivez-vous actuellement un traitement ?", "Indiquez vos maladies ant&#233;rieures et l'&#233;poque &#224; laquelle vous les avez contract&#233;s ?", "PRIME TOTALE");
	$x->ColFieldName = array('date', 'nom_prenom', 'intermediare', 'pays_residence', 'adresse', 'telephone', 'email', 'destination', 'formule', 'certificat', 'date_depart', 'date_retour', 'passport', 'beneficiaire', 'nom_prenomb', 'date_de_naissance', 'dossier_zippe', 'statut', 'questionnaire_medical', 'question1', 'question2', 'question2a', 'question3', 'question4', 'question5', 'prime_total');
	$x->ColNumber  = array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28);

	// template paths below are based on the app main directory
	$x->Template = 'templates/assurances_templateTV.html';
	$x->SelectedTemplate = 'templates/assurances_templateTVS.html';
	$x->TemplateDV = 'templates/assurances_templateDV.html';
	$x->TemplateDVP = 'templates/assurances_templateDVP.html';

	$x->ShowTableHeader = 1;
	$x->TVClasses = "";
	$x->DVClasses = "";
	$x->HighlightColor = '#FFF0C2';
	$x->HasCalculatedFields = false;

	// mm: build the query based on current member's permissions
	$DisplayRecords = $_REQUEST['DisplayRecords'];
	if(!in_array($DisplayRecords, array('user', 'group'))) { $DisplayRecords = 'all'; }
	if($perm[2]==1 || ($perm[2]>1 && $DisplayRecords=='user' && !$_REQUEST['NoFilter_x'])) { // view owner only
		$x->QueryFrom.=', membership_userrecords';
		$x->QueryWhere="where `assurances`.`idassurance`=membership_userrecords.pkValue and membership_userrecords.tableName='assurances' and lcase(membership_userrecords.memberID)='".getLoggedMemberID()."'";
	}elseif($perm[2]==2 || ($perm[2]>2 && $DisplayRecords=='group' && !$_REQUEST['NoFilter_x'])) { // view group only
		$x->QueryFrom.=', membership_userrecords';
		$x->QueryWhere="where `assurances`.`idassurance`=membership_userrecords.pkValue and membership_userrecords.tableName='assurances' and membership_userrecords.groupID='".getLoggedGroupID()."'";
	}elseif($perm[2]==3) { // view all
		// no further action
	}elseif($perm[2]==0) { // view none
		$x->QueryFields = array("Not enough permissions" => "NEP");
		$x->QueryFrom = '`assurances`';
		$x->QueryWhere = '';
		$x->DefaultSortField = '';
	}
	// hook: assurances_init
	$render=TRUE;
	if(function_exists('assurances_init')) {
		$args=array();
		$render=assurances_init($x, getMemberInfo(), $args);
	}

	if($render) $x->Render();

	// hook: assurances_header
	$headerCode='';
	if(function_exists('assurances_header')) {
		$args=array();
		$headerCode=assurances_header($x->ContentType, getMemberInfo(), $args);
	}  
	if(!$headerCode) {
		include_once("$currDir/header.php"); 
	}else{
		ob_start(); include_once("$currDir/header.php"); $dHeader=ob_get_contents(); ob_end_clean();
		echo str_replace('<%%HEADER%%>', $dHeader, $headerCode);
	}

	echo $x->HTML;
	// hook: assurances_footer
	$footerCode='';
	if(function_exists('assurances_footer')) {
		$args=array();
		$footerCode=assurances_footer($x->ContentType, getMemberInfo(), $args);
	}  
	if(!$footerCode) {
		include_once("$currDir/footer.php"); 
	}else{
		ob_start(); include_once("$currDir/footer.php"); $dFooter=ob_get_contents(); ob_end_clean();
		echo str_replace('<%%FOOTER%%>', $dFooter, $footerCode);
	}
?>