<?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/dossier_individuel.php");
	include("$currDir/dossier_individuel_dml.php");

	// mm: can the current member access this page?
	$perm=getTablePermissions('dossier_individuel');
	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 = "dossier_individuel";

	// Fields that can be displayed in the table view
	$x->QueryFieldsTV = array(
		"`dossier_individuel`.`iddindividuel`" => "iddindividuel",
		"IF(    CHAR_LENGTH(`gestion_primes1`.`link`), CONCAT_WS('',   `gestion_primes1`.`link`), '') /* PRIME */" => "option_prime",
		"`dossier_individuel`.`matricule`" => "matricule",
		"`dossier_individuel`.`nom_prenom`" => "nom_prenom",
		"if(`dossier_individuel`.`date_naissance`,date_format(`dossier_individuel`.`date_naissance`,'%d/%m/%Y'),'')" => "date_naissance",
		"`dossier_individuel`.`age`" => "age",
		"`dossier_individuel`.`matrimoniale`" => "matrimoniale",
		"`dossier_individuel`.`enfants`" => "enfants",
		"`dossier_individuel`.`nni`" => "nni",
		"`dossier_individuel`.`telephone`" => "telephone",
		"`dossier_individuel`.`courriel`" => "courriel",
		"`dossier_individuel`.`postale`" => "postale",
		"if(`dossier_individuel`.`date_recrutement`,date_format(`dossier_individuel`.`date_recrutement`,'%d/%m/%Y'),'')" => "date_recrutement",
		"IF(    CHAR_LENGTH(`statuts1`.`statut`), CONCAT_WS('',   `statuts1`.`statut`), '') /* Statut */" => "statut",
		"IF(    CHAR_LENGTH(`directions1`.`direction`), CONCAT_WS('',   `directions1`.`direction`), '') /* Direction */" => "direction",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* Fonction */" => "fonction",
		"IF(    CHAR_LENGTH(`services1`.`service`), CONCAT_WS('',   `services1`.`service`), '') /* Service */" => "service",
		"IF(    CHAR_LENGTH(`divisions1`.`division`), CONCAT_WS('',   `divisions1`.`division`), '') /* Division */" => "division",
		"IF(    CHAR_LENGTH(`categories1`.`categorie`), CONCAT_WS('',   `categories1`.`categorie`), '') /* Categorie */" => "categorie",
		"`dossier_individuel`.`anciennete`" => "anciennete",
		"REPLACE(FORMAT(`dossier_individuel`.`salaire`, 0), ',', ' ')" => "salaire",
		"IF(    CHAR_LENGTH(`categories1`.`prime`), CONCAT_WS('',   `categories1`.`prime`), '') /* Prime */" => "prime",
		"IF(    CHAR_LENGTH(`rythme_prime1`.`rythme`), CONCAT_WS('',   `rythme_prime1`.`rythme`), '') /* Qty */" => "qty",
		"`dossier_individuel`.`total`" => "total",
		"`dossier_individuel`.`compte`" => "compte",
		"IF(    CHAR_LENGTH(`banques1`.`banque`), CONCAT_WS('',   `banques1`.`banque`), '') /* Banque */" => "banque",
		"`dossier_individuel`.`cv`" => "cv",
		"`dossier_individuel`.`dossier`" => "dossier",
		"`dossier_individuel`.`contrat`" => "contrat",
		"`dossier_individuel`.`photo`" => "photo",
		"`dossier_individuel`.`observation`" => "observation",
	);
	// mapping incoming sort by requests to actual query fields
	$x->SortFields = array(
		1 => '`dossier_individuel`.`iddindividuel`',
		2 => '`gestion_primes1`.`link`',
		3 => 3,
		4 => 4,
		5 => '`dossier_individuel`.`date_naissance`',
		6 => '`dossier_individuel`.`age`',
		7 => 7,
		8 => '`dossier_individuel`.`enfants`',
		9 => 9,
		10 => 10,
		11 => 11,
		12 => 12,
		13 => '`dossier_individuel`.`date_recrutement`',
		14 => '`statuts1`.`statut`',
		15 => '`directions1`.`direction`',
		16 => '`fonctions1`.`fonction`',
		17 => '`services1`.`service`',
		18 => '`divisions1`.`division`',
		19 => '`categories1`.`categorie`',
		20 => '`dossier_individuel`.`anciennete`',
		21 => '`dossier_individuel`.`salaire`',
		22 => '`categories1`.`prime`',
		23 => 23,
		24 => '`dossier_individuel`.`total`',
		25 => 25,
		26 => '`banques1`.`banque`',
		27 => 27,
		28 => 28,
		29 => 29,
		30 => 30,
		31 => 31,
	);

	// Fields that can be displayed in the csv file
	$x->QueryFieldsCSV = array(
		"`dossier_individuel`.`iddindividuel`" => "iddindividuel",
		"IF(    CHAR_LENGTH(`gestion_primes1`.`link`), CONCAT_WS('',   `gestion_primes1`.`link`), '') /* PRIME */" => "option_prime",
		"`dossier_individuel`.`matricule`" => "matricule",
		"`dossier_individuel`.`nom_prenom`" => "nom_prenom",
		"if(`dossier_individuel`.`date_naissance`,date_format(`dossier_individuel`.`date_naissance`,'%d/%m/%Y'),'')" => "date_naissance",
		"`dossier_individuel`.`age`" => "age",
		"`dossier_individuel`.`matrimoniale`" => "matrimoniale",
		"`dossier_individuel`.`enfants`" => "enfants",
		"`dossier_individuel`.`nni`" => "nni",
		"`dossier_individuel`.`telephone`" => "telephone",
		"`dossier_individuel`.`courriel`" => "courriel",
		"`dossier_individuel`.`postale`" => "postale",
		"if(`dossier_individuel`.`date_recrutement`,date_format(`dossier_individuel`.`date_recrutement`,'%d/%m/%Y'),'')" => "date_recrutement",
		"IF(    CHAR_LENGTH(`statuts1`.`statut`), CONCAT_WS('',   `statuts1`.`statut`), '') /* Statut */" => "statut",
		"IF(    CHAR_LENGTH(`directions1`.`direction`), CONCAT_WS('',   `directions1`.`direction`), '') /* Direction */" => "direction",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* Fonction */" => "fonction",
		"IF(    CHAR_LENGTH(`services1`.`service`), CONCAT_WS('',   `services1`.`service`), '') /* Service */" => "service",
		"IF(    CHAR_LENGTH(`divisions1`.`division`), CONCAT_WS('',   `divisions1`.`division`), '') /* Division */" => "division",
		"IF(    CHAR_LENGTH(`categories1`.`categorie`), CONCAT_WS('',   `categories1`.`categorie`), '') /* Categorie */" => "categorie",
		"`dossier_individuel`.`anciennete`" => "anciennete",
		"REPLACE(FORMAT(`dossier_individuel`.`salaire`, 0), ',', ' ')" => "salaire",
		"IF(    CHAR_LENGTH(`categories1`.`prime`), CONCAT_WS('',   `categories1`.`prime`), '') /* Prime */" => "prime",
		"IF(    CHAR_LENGTH(`rythme_prime1`.`rythme`), CONCAT_WS('',   `rythme_prime1`.`rythme`), '') /* Qty */" => "qty",
		"`dossier_individuel`.`total`" => "total",
		"`dossier_individuel`.`compte`" => "compte",
		"IF(    CHAR_LENGTH(`banques1`.`banque`), CONCAT_WS('',   `banques1`.`banque`), '') /* Banque */" => "banque",
		"`dossier_individuel`.`cv`" => "cv",
		"`dossier_individuel`.`dossier`" => "dossier",
		"`dossier_individuel`.`contrat`" => "contrat",
		"`dossier_individuel`.`photo`" => "photo",
		"`dossier_individuel`.`observation`" => "observation",
	);
	// Fields that can be filtered
	$x->QueryFieldsFilters = array(
		"`dossier_individuel`.`iddindividuel`" => "ID",
		"IF(    CHAR_LENGTH(`gestion_primes1`.`link`), CONCAT_WS('',   `gestion_primes1`.`link`), '') /* PRIME */" => "PRIME",
		"`dossier_individuel`.`matricule`" => "Matricule",
		"`dossier_individuel`.`nom_prenom`" => "Nom & Pr&#233;nom",
		"`dossier_individuel`.`date_naissance`" => "Date de naissance",
		"`dossier_individuel`.`age`" => "Age",
		"`dossier_individuel`.`matrimoniale`" => "Matrimoniale",
		"`dossier_individuel`.`enfants`" => "Enfants",
		"`dossier_individuel`.`nni`" => "NNI",
		"`dossier_individuel`.`telephone`" => "T&#233;l&#233;phone",
		"`dossier_individuel`.`courriel`" => "Courriel",
		"`dossier_individuel`.`postale`" => "Boite postale",
		"`dossier_individuel`.`date_recrutement`" => "Date de recrutement",
		"IF(    CHAR_LENGTH(`statuts1`.`statut`), CONCAT_WS('',   `statuts1`.`statut`), '') /* Statut */" => "Statut",
		"IF(    CHAR_LENGTH(`directions1`.`direction`), CONCAT_WS('',   `directions1`.`direction`), '') /* Direction */" => "Direction",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* Fonction */" => "Fonction",
		"IF(    CHAR_LENGTH(`services1`.`service`), CONCAT_WS('',   `services1`.`service`), '') /* Service */" => "Service",
		"IF(    CHAR_LENGTH(`divisions1`.`division`), CONCAT_WS('',   `divisions1`.`division`), '') /* Division */" => "Division",
		"IF(    CHAR_LENGTH(`categories1`.`categorie`), CONCAT_WS('',   `categories1`.`categorie`), '') /* Categorie */" => "Categorie",
		"`dossier_individuel`.`anciennete`" => "Anciennet&#233;",
		"`dossier_individuel`.`salaire`" => "Salaire",
		"IF(    CHAR_LENGTH(`categories1`.`prime`), CONCAT_WS('',   `categories1`.`prime`), '') /* Prime */" => "Prime",
		"IF(    CHAR_LENGTH(`rythme_prime1`.`rythme`), CONCAT_WS('',   `rythme_prime1`.`rythme`), '') /* Qty */" => "Qty",
		"`dossier_individuel`.`total`" => "Total",
		"`dossier_individuel`.`compte`" => "Compte",
		"IF(    CHAR_LENGTH(`banques1`.`banque`), CONCAT_WS('',   `banques1`.`banque`), '') /* Banque */" => "Banque",
		"`dossier_individuel`.`cv`" => "Curriculum vitae",
		"`dossier_individuel`.`dossier`" => "Dossier",
		"`dossier_individuel`.`contrat`" => "Contrat",
		"`dossier_individuel`.`observation`" => "Observation",
	);

	// Fields that can be quick searched
	$x->QueryFieldsQS = array(
		"`dossier_individuel`.`iddindividuel`" => "iddindividuel",
		"IF(    CHAR_LENGTH(`gestion_primes1`.`link`), CONCAT_WS('',   `gestion_primes1`.`link`), '') /* PRIME */" => "option_prime",
		"`dossier_individuel`.`matricule`" => "matricule",
		"`dossier_individuel`.`nom_prenom`" => "nom_prenom",
		"if(`dossier_individuel`.`date_naissance`,date_format(`dossier_individuel`.`date_naissance`,'%d/%m/%Y'),'')" => "date_naissance",
		"`dossier_individuel`.`age`" => "age",
		"`dossier_individuel`.`matrimoniale`" => "matrimoniale",
		"`dossier_individuel`.`enfants`" => "enfants",
		"`dossier_individuel`.`nni`" => "nni",
		"`dossier_individuel`.`telephone`" => "telephone",
		"`dossier_individuel`.`courriel`" => "courriel",
		"`dossier_individuel`.`postale`" => "postale",
		"if(`dossier_individuel`.`date_recrutement`,date_format(`dossier_individuel`.`date_recrutement`,'%d/%m/%Y'),'')" => "date_recrutement",
		"IF(    CHAR_LENGTH(`statuts1`.`statut`), CONCAT_WS('',   `statuts1`.`statut`), '') /* Statut */" => "statut",
		"IF(    CHAR_LENGTH(`directions1`.`direction`), CONCAT_WS('',   `directions1`.`direction`), '') /* Direction */" => "direction",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* Fonction */" => "fonction",
		"IF(    CHAR_LENGTH(`services1`.`service`), CONCAT_WS('',   `services1`.`service`), '') /* Service */" => "service",
		"IF(    CHAR_LENGTH(`divisions1`.`division`), CONCAT_WS('',   `divisions1`.`division`), '') /* Division */" => "division",
		"IF(    CHAR_LENGTH(`categories1`.`categorie`), CONCAT_WS('',   `categories1`.`categorie`), '') /* Categorie */" => "categorie",
		"`dossier_individuel`.`anciennete`" => "anciennete",
		"REPLACE(FORMAT(`dossier_individuel`.`salaire`, 0), ',', ' ')" => "salaire",
		"IF(    CHAR_LENGTH(`categories1`.`prime`), CONCAT_WS('',   `categories1`.`prime`), '') /* Prime */" => "prime",
		"IF(    CHAR_LENGTH(`rythme_prime1`.`rythme`), CONCAT_WS('',   `rythme_prime1`.`rythme`), '') /* Qty */" => "qty",
		"`dossier_individuel`.`total`" => "total",
		"`dossier_individuel`.`compte`" => "compte",
		"IF(    CHAR_LENGTH(`banques1`.`banque`), CONCAT_WS('',   `banques1`.`banque`), '') /* Banque */" => "banque",
		"`dossier_individuel`.`cv`" => "cv",
		"`dossier_individuel`.`dossier`" => "dossier",
		"`dossier_individuel`.`contrat`" => "contrat",
		"`dossier_individuel`.`observation`" => "observation",
	);

	// Lookup fields that can be used as filterers
	$x->filterers = array('option_prime' => 'PRIME', 'statut' => 'Statut', 'direction' => 'Direction', 'fonction' => 'Fonction', 'service' => 'Service', 'division' => 'Division', 'categorie' => 'Categorie', 'banque' => 'Banque', );

	$x->QueryFrom = "`dossier_individuel` LEFT JOIN `gestion_primes` as gestion_primes1 ON `gestion_primes1`.`idgestion_prime`=`dossier_individuel`.`option_prime` LEFT JOIN `statuts` as statuts1 ON `statuts1`.`idstatut`=`dossier_individuel`.`statut` LEFT JOIN `directions` as directions1 ON `directions1`.`iddirection`=`dossier_individuel`.`direction` LEFT JOIN `fonctions` as fonctions1 ON `fonctions1`.`idfonction`=`dossier_individuel`.`fonction` LEFT JOIN `services` as services1 ON `services1`.`idservice`=`dossier_individuel`.`service` LEFT JOIN `divisions` as divisions1 ON `divisions1`.`iddivision`=`dossier_individuel`.`division` LEFT JOIN `categories` as categories1 ON `categories1`.`idcategorie`=`dossier_individuel`.`categorie` LEFT JOIN `banques` as banques1 ON `banques1`.`idbanque`=`dossier_individuel`.`banque` LEFT JOIN `rythme_prime` as rythme_prime1 ON `rythme_prime1`.`idrythme_prime`=`gestion_primes1`.`echeance` ";
	$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 = 1;
	$x->AllowFilters = 1;
	$x->AllowSavingFilters = 1;
	$x->AllowSorting = 1;
	$x->AllowNavigation = 1;
	$x->AllowPrinting = 1;
	$x->AllowPrintingDV = 1;
	$x->AllowCSV = 1;
	$x->RecordsPerPage = 500;
	$x->QuickSearch = 1;
	$x->QuickSearchText = $Translation["quick search"];
	$x->ScriptFileName = "dossier_individuel_view.php";
	$x->RedirectAfterInsert = "dossier_individuel_view.php?SelectedID=#ID#";
	$x->TableTitle = "LISTE DU PERSONNEL";
	$x->TableIcon = "resources/table_icons/folder_table.png";
	$x->PrimaryKey = "`dossier_individuel`.`iddindividuel`";
	$x->DefaultSortField = '26';
	$x->DefaultSortDirection = 'asc';

	$x->ColWidth   = array(  150, 150, 150, 150, 150, 150, 150);
	$x->ColCaption = array("Matricule", "Nom & Pr&#233;nom", "Fonction", "Categorie", "Prime", "Compte", "Banque");
	$x->ColFieldName = array('matricule', 'nom_prenom', 'fonction', 'categorie', 'prime', 'compte', 'banque');
	$x->ColNumber  = array(3, 4, 16, 19, 22, 25, 26);

	// template paths below are based on the app main directory
	$x->Template = 'templates/dossier_individuel_templateTV.html';
	$x->SelectedTemplate = 'templates/dossier_individuel_templateTVS.html';
	$x->TemplateDV = 'templates/dossier_individuel_templateDV.html';
	$x->TemplateDVP = 'templates/dossier_individuel_templateDVP.html';

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

	// 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 `dossier_individuel`.`iddindividuel`=membership_userrecords.pkValue and membership_userrecords.tableName='dossier_individuel' 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 `dossier_individuel`.`iddindividuel`=membership_userrecords.pkValue and membership_userrecords.tableName='dossier_individuel' 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 = '`dossier_individuel`';
		$x->QueryWhere = '';
		$x->DefaultSortField = '';
	}
	// hook: dossier_individuel_init
	$render=TRUE;
	if(function_exists('dossier_individuel_init')) {
		$args=array();
		$render=dossier_individuel_init($x, getMemberInfo(), $args);
	}

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

	// hook: dossier_individuel_header
	$headerCode='';
	if(function_exists('dossier_individuel_header')) {
		$args=array();
		$headerCode=dossier_individuel_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: dossier_individuel_footer
	$footerCode='';
	if(function_exists('dossier_individuel_footer')) {
		$args=array();
		$footerCode=dossier_individuel_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);
	}
?>