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

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

	// Fields that can be displayed in the table view
	$x->QueryFieldsTV = array(   
		"`conges_permissions`.`idconge_permission`" => "idconge_permission",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`matricule`), CONCAT_WS('',   `dossier_individuel1`.`matricule`), '') /* MATRICULE */" => "matricule",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`nom_prenom`), CONCAT_WS('',   `dossier_individuel1`.`nom_prenom`), '') /* NOM ET PRENOM */" => "nom_prenom",
		"if(`conges_permissions`.`date_naissance`,date_format(`conges_permissions`.`date_naissance`,'%d/%m/%Y'),'')" => "date_naissance",
		"if(`conges_permissions`.`date_recrutement_cp`,date_format(`conges_permissions`.`date_recrutement_cp`,'%d/%m/%Y'),'')" => "date_recrutement_cp",
		"`conges_permissions`.`age`" => "age",
		"`conges_permissions`.`annees_service`" => "annees_service",
		"`conges_permissions`.`date_depart_conge`" => "date_depart_conge",
		"`conges_permissions`.`date_depart_retraite`" => "date_depart_retraite"
	);
	// mapping incoming sort by requests to actual query fields
	$x->SortFields = array(   
		1 => '`conges_permissions`.`idconge_permission`',
		2 => '`dossier_individuel1`.`matricule`',
		3 => '`dossier_individuel1`.`nom_prenom`',
		4 => '`conges_permissions`.`date_naissance`',
		5 => '`conges_permissions`.`date_recrutement_cp`',
		6 => '`conges_permissions`.`age`',
		7 => '`conges_permissions`.`annees_service`',
		8 => 8,
		9 => 9
	);

	// Fields that can be displayed in the csv file
	$x->QueryFieldsCSV = array(   
		"`conges_permissions`.`idconge_permission`" => "idconge_permission",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`matricule`), CONCAT_WS('',   `dossier_individuel1`.`matricule`), '') /* MATRICULE */" => "matricule",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`nom_prenom`), CONCAT_WS('',   `dossier_individuel1`.`nom_prenom`), '') /* NOM ET PRENOM */" => "nom_prenom",
		"if(`conges_permissions`.`date_naissance`,date_format(`conges_permissions`.`date_naissance`,'%d/%m/%Y'),'')" => "date_naissance",
		"if(`conges_permissions`.`date_recrutement_cp`,date_format(`conges_permissions`.`date_recrutement_cp`,'%d/%m/%Y'),'')" => "date_recrutement_cp",
		"`conges_permissions`.`age`" => "age",
		"`conges_permissions`.`annees_service`" => "annees_service",
		"`conges_permissions`.`date_depart_conge`" => "date_depart_conge",
		"`conges_permissions`.`date_depart_retraite`" => "date_depart_retraite"
	);
	// Fields that can be filtered
	$x->QueryFieldsFilters = array(   
		"`conges_permissions`.`idconge_permission`" => "ID",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`matricule`), CONCAT_WS('',   `dossier_individuel1`.`matricule`), '') /* MATRICULE */" => "MATRICULE",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`nom_prenom`), CONCAT_WS('',   `dossier_individuel1`.`nom_prenom`), '') /* NOM ET PRENOM */" => "NOM ET PRENOM",
		"`conges_permissions`.`date_naissance`" => "DATE DE NAISSANCE",
		"`conges_permissions`.`date_recrutement_cp`" => "DATE DE RECRUTEMENT",
		"`conges_permissions`.`age`" => "AGE",
		"`conges_permissions`.`annees_service`" => "ANNEES DE SERVICE",
		"`conges_permissions`.`date_depart_conge`" => "DATE DE DEPART CONGE",
		"`conges_permissions`.`date_depart_retraite`" => "DATE DE DEPART RETRAITE"
	);

	// Fields that can be quick searched
	$x->QueryFieldsQS = array(   
		"`conges_permissions`.`idconge_permission`" => "idconge_permission",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`matricule`), CONCAT_WS('',   `dossier_individuel1`.`matricule`), '') /* MATRICULE */" => "matricule",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`nom_prenom`), CONCAT_WS('',   `dossier_individuel1`.`nom_prenom`), '') /* NOM ET PRENOM */" => "nom_prenom",
		"if(`conges_permissions`.`date_naissance`,date_format(`conges_permissions`.`date_naissance`,'%d/%m/%Y'),'')" => "date_naissance",
		"if(`conges_permissions`.`date_recrutement_cp`,date_format(`conges_permissions`.`date_recrutement_cp`,'%d/%m/%Y'),'')" => "date_recrutement_cp",
		"`conges_permissions`.`age`" => "age",
		"`conges_permissions`.`annees_service`" => "annees_service",
		"`conges_permissions`.`date_depart_conge`" => "date_depart_conge",
		"`conges_permissions`.`date_depart_retraite`" => "date_depart_retraite"
	);

	// Lookup fields that can be used as filterers
	$x->filterers = array(  'matricule' => 'MATRICULE');

	$x->QueryFrom = "`conges_permissions` LEFT JOIN `dossier_individuel` as dossier_individuel1 ON `dossier_individuel1`.`iddindividuel`=`conges_permissions`.`matricule` ";
	$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 = 100;
	$x->QuickSearch = 1;
	$x->QuickSearchText = $Translation["quick search"];
	$x->ScriptFileName = "conges_permissions_view.php";
	$x->RedirectAfterInsert = "conges_permissions_view.php?SelectedID=#ID#";
	$x->TableTitle = "RETRAITES";
	$x->TableIcon = "resources/table_icons/folder_palette.png";
	$x->PrimaryKey = "`conges_permissions`.`idconge_permission`";
	$x->DefaultSortField = '1';
	$x->DefaultSortDirection = 'desc';

	$x->ColWidth   = array(  150, 150, 150, 150);
	$x->ColCaption = array("ID", "DATE DE RECRUTEMENT", "AGE", "ANNEES DE SERVICE");
	$x->ColFieldName = array('idconge_permission', 'date_recrutement_cp', 'age', 'annees_service');
	$x->ColNumber  = array(1, 5, 6, 7);

	// template paths below are based on the app main directory
	$x->Template = 'templates/conges_permissions_templateTV.html';
	$x->SelectedTemplate = 'templates/conges_permissions_templateTVS.html';
	$x->TemplateDV = 'templates/conges_permissions_templateDV.html';
	$x->TemplateDVP = 'templates/conges_permissions_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 `conges_permissions`.`idconge_permission`=membership_userrecords.pkValue and membership_userrecords.tableName='conges_permissions' 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 `conges_permissions`.`idconge_permission`=membership_userrecords.pkValue and membership_userrecords.tableName='conges_permissions' 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 = '`conges_permissions`';
		$x->QueryWhere = '';
		$x->DefaultSortField = '';
	}
	// hook: conges_permissions_init
	$render=TRUE;
	if(function_exists('conges_permissions_init')){
		$args=array();
		$render=conges_permissions_init($x, getMemberInfo(), $args);
	}

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

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