<?php
// This script and data application were generated by AppGini 5.76
// 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`.`photo`" => "photo",
		"`dossier_individuel`.`matricule`" => "matricule",
		"`dossier_individuel`.`iddindividuel`" => "iddindividuel",
		"`dossier_individuel`.`nom_prenom`" => "nom_prenom",
		"if(`dossier_individuel`.`date_naissance`,date_format(`dossier_individuel`.`date_naissance`,'%d/%m/%Y'),'')" => "date_naissance",
		"`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(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* FONCTION */" => "fonction",
		"IF(    CHAR_LENGTH(`directions1`.`direction`), CONCAT_WS('',   `directions1`.`direction`), '') /* DIRECTION */" => "direction",
		"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(`categorie_prime1`.`categorie`), CONCAT_WS('',   `categorie_prime1`.`categorie`), '') /* Categorie */" => "categorie",
		"IF(    CHAR_LENGTH(`statut1`.`statut`), CONCAT_WS('',   `statut1`.`statut`), '') /* STATUT */" => "statut",
		"REPLACE(FORMAT(`dossier_individuel`.`salaire`, 0), ',', ' ')" => "salaire",
		"IF(    CHAR_LENGTH(`categorie_prime1`.`prime`), CONCAT_WS('',   `categorie_prime1`.`prime`), '') /* PRIME */" => "prime_ts",
		"`dossier_individuel`.`compte`" => "compte",
		"IF(    CHAR_LENGTH(`les_banques1`.`banque`), CONCAT_WS('',   `les_banques1`.`banque`), '') /* BANQUE */" => "banque",
		"`dossier_individuel`.`total_income`" => "total_income",
		"`dossier_individuel`.`total_expense`" => "total_expense",
		"`dossier_individuel`.`available_budget`" => "available_budget",
		"`dossier_individuel`.`observation`" => "observation"
	);
	// mapping incoming sort by requests to actual query fields
	$x->SortFields = array(   
		1 => 1,
		2 => 2,
		3 => '`dossier_individuel`.`iddindividuel`',
		4 => 4,
		5 => '`dossier_individuel`.`date_naissance`',
		6 => 6,
		7 => 7,
		8 => 8,
		9 => 9,
		10 => 10,
		11 => 11,
		12 => '`dossier_individuel`.`date_recrutement`',
		13 => '`fonctions1`.`fonction`',
		14 => '`directions1`.`direction`',
		15 => '`services1`.`service`',
		16 => '`divisions1`.`division`',
		17 => '`categorie_prime1`.`categorie`',
		18 => '`statut1`.`statut`',
		19 => '`dossier_individuel`.`salaire`',
		20 => '`categorie_prime1`.`prime`',
		21 => 21,
		22 => '`les_banques1`.`banque`',
		23 => '`dossier_individuel`.`total_income`',
		24 => '`dossier_individuel`.`total_expense`',
		25 => '`dossier_individuel`.`available_budget`',
		26 => 26
	);

	// Fields that can be displayed in the csv file
	$x->QueryFieldsCSV = array(   
		"`dossier_individuel`.`photo`" => "photo",
		"`dossier_individuel`.`matricule`" => "matricule",
		"`dossier_individuel`.`iddindividuel`" => "iddindividuel",
		"`dossier_individuel`.`nom_prenom`" => "nom_prenom",
		"if(`dossier_individuel`.`date_naissance`,date_format(`dossier_individuel`.`date_naissance`,'%d/%m/%Y'),'')" => "date_naissance",
		"`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(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* FONCTION */" => "fonction",
		"IF(    CHAR_LENGTH(`directions1`.`direction`), CONCAT_WS('',   `directions1`.`direction`), '') /* DIRECTION */" => "direction",
		"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(`categorie_prime1`.`categorie`), CONCAT_WS('',   `categorie_prime1`.`categorie`), '') /* Categorie */" => "categorie",
		"IF(    CHAR_LENGTH(`statut1`.`statut`), CONCAT_WS('',   `statut1`.`statut`), '') /* STATUT */" => "statut",
		"REPLACE(FORMAT(`dossier_individuel`.`salaire`, 0), ',', ' ')" => "salaire",
		"IF(    CHAR_LENGTH(`categorie_prime1`.`prime`), CONCAT_WS('',   `categorie_prime1`.`prime`), '') /* PRIME */" => "prime_ts",
		"`dossier_individuel`.`compte`" => "compte",
		"IF(    CHAR_LENGTH(`les_banques1`.`banque`), CONCAT_WS('',   `les_banques1`.`banque`), '') /* BANQUE */" => "banque",
		"`dossier_individuel`.`total_income`" => "total_income",
		"`dossier_individuel`.`total_expense`" => "total_expense",
		"`dossier_individuel`.`available_budget`" => "available_budget",
		"`dossier_individuel`.`observation`" => "observation"
	);
	// Fields that can be filtered
	$x->QueryFieldsFilters = array(   
		"`dossier_individuel`.`matricule`" => "N&#176; MATRICULE",
		"`dossier_individuel`.`iddindividuel`" => "ID",
		"`dossier_individuel`.`nom_prenom`" => "NOM ET PRENOM",
		"`dossier_individuel`.`date_naissance`" => "DATE DE NAISSANCE",
		"`dossier_individuel`.`matrimoniale`" => "SITUATION MATRIMONIALE",
		"`dossier_individuel`.`enfants`" => "NOMBRE ENFANTS A CHARGE",
		"`dossier_individuel`.`nni`" => "NNI",
		"`dossier_individuel`.`telephone`" => "TELEPHONE",
		"`dossier_individuel`.`courriel`" => "COURRIEL",
		"`dossier_individuel`.`postale`" => "ADRESSE POSTALE",
		"`dossier_individuel`.`date_recrutement`" => "DATE DE RECRUTEMENT",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* FONCTION */" => "FONCTION",
		"IF(    CHAR_LENGTH(`directions1`.`direction`), CONCAT_WS('',   `directions1`.`direction`), '') /* DIRECTION */" => "DIRECTION",
		"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(`categorie_prime1`.`categorie`), CONCAT_WS('',   `categorie_prime1`.`categorie`), '') /* Categorie */" => "Categorie",
		"IF(    CHAR_LENGTH(`statut1`.`statut`), CONCAT_WS('',   `statut1`.`statut`), '') /* STATUT */" => "STATUT",
		"`dossier_individuel`.`salaire`" => "SALAIRE",
		"IF(    CHAR_LENGTH(`categorie_prime1`.`prime`), CONCAT_WS('',   `categorie_prime1`.`prime`), '') /* PRIME */" => "PRIME",
		"`dossier_individuel`.`compte`" => "COMPTE",
		"IF(    CHAR_LENGTH(`les_banques1`.`banque`), CONCAT_WS('',   `les_banques1`.`banque`), '') /* BANQUE */" => "BANQUE",
		"`dossier_individuel`.`total_income`" => "DROIT DE CONGE",
		"`dossier_individuel`.`total_expense`" => "CONGE PRIS",
		"`dossier_individuel`.`available_budget`" => "CONGE RESTANT",
		"`dossier_individuel`.`observation`" => "OBSERVATION"
	);

	// Fields that can be quick searched
	$x->QueryFieldsQS = array(   
		"`dossier_individuel`.`matricule`" => "matricule",
		"`dossier_individuel`.`iddindividuel`" => "iddindividuel",
		"`dossier_individuel`.`nom_prenom`" => "nom_prenom",
		"if(`dossier_individuel`.`date_naissance`,date_format(`dossier_individuel`.`date_naissance`,'%d/%m/%Y'),'')" => "date_naissance",
		"`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(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* FONCTION */" => "fonction",
		"IF(    CHAR_LENGTH(`directions1`.`direction`), CONCAT_WS('',   `directions1`.`direction`), '') /* DIRECTION */" => "direction",
		"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(`categorie_prime1`.`categorie`), CONCAT_WS('',   `categorie_prime1`.`categorie`), '') /* Categorie */" => "categorie",
		"IF(    CHAR_LENGTH(`statut1`.`statut`), CONCAT_WS('',   `statut1`.`statut`), '') /* STATUT */" => "statut",
		"REPLACE(FORMAT(`dossier_individuel`.`salaire`, 0), ',', ' ')" => "salaire",
		"IF(    CHAR_LENGTH(`categorie_prime1`.`prime`), CONCAT_WS('',   `categorie_prime1`.`prime`), '') /* PRIME */" => "prime_ts",
		"`dossier_individuel`.`compte`" => "compte",
		"IF(    CHAR_LENGTH(`les_banques1`.`banque`), CONCAT_WS('',   `les_banques1`.`banque`), '') /* BANQUE */" => "banque",
		"`dossier_individuel`.`total_income`" => "total_income",
		"`dossier_individuel`.`total_expense`" => "total_expense",
		"`dossier_individuel`.`available_budget`" => "available_budget",
		"`dossier_individuel`.`observation`" => "observation"
	);

	// Lookup fields that can be used as filterers
	$x->filterers = array(  'fonction' => 'FONCTION', 'direction' => 'DIRECTION', 'service' => 'SERVICE', 'division' => 'DIVISION', 'categorie' => 'Categorie', 'statut' => 'STATUT', 'banque' => 'BANQUE');

	$x->QueryFrom = "`dossier_individuel` LEFT JOIN `fonctions` as fonctions1 ON `fonctions1`.`idfonction`=`dossier_individuel`.`fonction` LEFT JOIN `directions` as directions1 ON `directions1`.`iddirection`=`dossier_individuel`.`direction` LEFT JOIN `services` as services1 ON `services1`.`idservice`=`dossier_individuel`.`service` LEFT JOIN `divisions` as divisions1 ON `divisions1`.`iddivision`=`dossier_individuel`.`division` LEFT JOIN `categorie_prime` as categorie_prime1 ON `categorie_prime1`.`id_categorie_prime`=`dossier_individuel`.`categorie` LEFT JOIN `statut` as statut1 ON `statut1`.`idstatut`=`dossier_individuel`.`statut` LEFT JOIN `les_banques` as les_banques1 ON `les_banques1`.`id`=`dossier_individuel`.`banque` ";
	$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 = 1000;
	$x->QuickSearch = 1;
	$x->QuickSearchText = $Translation["quick search"];
	$x->ScriptFileName = "dossier_individuel_view.php";
	$x->RedirectAfterInsert = "dossier_individuel_view.php?SelectedID=#ID#";
	$x->TableTitle = "GESTION DU PERSONNEL";
	$x->TableIcon = "resources/table_icons/folder_user.png";
	$x->PrimaryKey = "`dossier_individuel`.`iddindividuel`";
	$x->DefaultSortField = '3';
	$x->DefaultSortDirection = 'asc';

	$x->ColWidth   = array(  150, 150, 150, 150, 150, 150, 150, 150, 150, 150);
	$x->ColCaption = array("N&#176; MATRICULE", "NOM ET PRENOM", "FONCTION", "SALAIRE", "PRIME", "COMPTE", "BANQUE", "DROIT DE CONGE", "CONGE PRIS", "CONGE RESTANT");
	$x->ColFieldName = array('matricule', 'nom_prenom', 'fonction', 'salaire', 'prime_ts', 'compte', 'banque', 'total_income', 'total_expense', 'available_budget');
	$x->ColNumber  = array(2, 4, 13, 19, 20, 21, 22, 23, 24, 25);

	// 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';

	// 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);
	}
?>