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

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

	// Fields that can be displayed in the table view
	$x->QueryFieldsTV = array(   
		"`demandes_conge_m`.`iddemande_permission`" => "iddemande_permission",
		"if(`demandes_conge_m`.`date_demande_p`,date_format(`demandes_conge_m`.`date_demande_p`,'%d/%m/%Y'),'')" => "date_demande_p",
		"`demandes_conge_m`.`numero`" => "numero",
		"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(    CHAR_LENGTH(if(`dossier_individuel1`.`date_recrutement`,date_format(`dossier_individuel1`.`date_recrutement`,'%d/%m/%Y'),'')), CONCAT_WS('',   if(`dossier_individuel1`.`date_recrutement`,date_format(`dossier_individuel1`.`date_recrutement`,'%d/%m/%Y'),'')), '') /* DATE DE RECRUTEMENT */" => "date_recrutement",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* FONCTION */" => "fonction",
		"IF(    CHAR_LENGTH(`divisions1`.`division`), CONCAT_WS('',   `divisions1`.`division`), '') /* DIVISION */" => "division",
		"IF(    CHAR_LENGTH(`directions1`.`direction`), CONCAT_WS('',   `directions1`.`direction`), '') /* DIRECTION */" => "direction",
		"IF(    CHAR_LENGTH(`services1`.`service`), CONCAT_WS('',   `services1`.`service`), '') /* SERVICE */" => "service",
		"if(`demandes_conge_m`.`depart`,date_format(`demandes_conge_m`.`depart`,'%d/%m/%Y'),'')" => "depart",
		"if(`demandes_conge_m`.`retour`,date_format(`demandes_conge_m`.`retour`,'%d/%m/%Y'),'')" => "retour",
		"`demandes_conge_m`.`raison`" => "raison",
		"if(`demandes_conge_m`.`date_dernier_permission`,date_format(`demandes_conge_m`.`date_dernier_permission`,'%d/%m/%Y'),'')" => "date_dernier_permission",
		"`demandes_conge_m`.`jours`" => "jours",
		"`demandes_conge_m`.`adresse_permission`" => "adresse_permission",
		"`demandes_conge_m`.`justificatif_permission`" => "justificatif_permission",
		"`demandes_conge_m`.`observation`" => "observation"
	);
	// mapping incoming sort by requests to actual query fields
	$x->SortFields = array(   
		1 => '`demandes_conge_m`.`iddemande_permission`',
		2 => '`demandes_conge_m`.`date_demande_p`',
		3 => 3,
		4 => '`dossier_individuel1`.`matricule`',
		5 => '`dossier_individuel1`.`nom_prenom`',
		6 => 'date_format(`dossier_individuel1`.`date_recrutement`,\'%d/%m/%Y\')',
		7 => 7,
		8 => 8,
		9 => 9,
		10 => 10,
		11 => '`demandes_conge_m`.`depart`',
		12 => '`demandes_conge_m`.`retour`',
		13 => 13,
		14 => '`demandes_conge_m`.`date_dernier_permission`',
		15 => '`demandes_conge_m`.`jours`',
		16 => 16,
		17 => 17,
		18 => 18
	);

	// Fields that can be displayed in the csv file
	$x->QueryFieldsCSV = array(   
		"`demandes_conge_m`.`iddemande_permission`" => "iddemande_permission",
		"if(`demandes_conge_m`.`date_demande_p`,date_format(`demandes_conge_m`.`date_demande_p`,'%d/%m/%Y'),'')" => "date_demande_p",
		"`demandes_conge_m`.`numero`" => "numero",
		"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(    CHAR_LENGTH(if(`dossier_individuel1`.`date_recrutement`,date_format(`dossier_individuel1`.`date_recrutement`,'%d/%m/%Y'),'')), CONCAT_WS('',   if(`dossier_individuel1`.`date_recrutement`,date_format(`dossier_individuel1`.`date_recrutement`,'%d/%m/%Y'),'')), '') /* DATE DE RECRUTEMENT */" => "date_recrutement",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* FONCTION */" => "fonction",
		"IF(    CHAR_LENGTH(`divisions1`.`division`), CONCAT_WS('',   `divisions1`.`division`), '') /* DIVISION */" => "division",
		"IF(    CHAR_LENGTH(`directions1`.`direction`), CONCAT_WS('',   `directions1`.`direction`), '') /* DIRECTION */" => "direction",
		"IF(    CHAR_LENGTH(`services1`.`service`), CONCAT_WS('',   `services1`.`service`), '') /* SERVICE */" => "service",
		"if(`demandes_conge_m`.`depart`,date_format(`demandes_conge_m`.`depart`,'%d/%m/%Y'),'')" => "depart",
		"if(`demandes_conge_m`.`retour`,date_format(`demandes_conge_m`.`retour`,'%d/%m/%Y'),'')" => "retour",
		"`demandes_conge_m`.`raison`" => "raison",
		"if(`demandes_conge_m`.`date_dernier_permission`,date_format(`demandes_conge_m`.`date_dernier_permission`,'%d/%m/%Y'),'')" => "date_dernier_permission",
		"`demandes_conge_m`.`jours`" => "jours",
		"`demandes_conge_m`.`adresse_permission`" => "adresse_permission",
		"`demandes_conge_m`.`justificatif_permission`" => "justificatif_permission",
		"`demandes_conge_m`.`observation`" => "observation"
	);
	// Fields that can be filtered
	$x->QueryFieldsFilters = array(   
		"`demandes_conge_m`.`iddemande_permission`" => "N&#176;",
		"`demandes_conge_m`.`date_demande_p`" => "DATE DE DEMANDE",
		"`demandes_conge_m`.`numero`" => "NUMERO",
		"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",
		"IF(    CHAR_LENGTH(if(`dossier_individuel1`.`date_recrutement`,date_format(`dossier_individuel1`.`date_recrutement`,'%d/%m/%Y'),'')), CONCAT_WS('',   if(`dossier_individuel1`.`date_recrutement`,date_format(`dossier_individuel1`.`date_recrutement`,'%d/%m/%Y'),'')), '') /* DATE DE RECRUTEMENT */" => "DATE DE RECRUTEMENT",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* FONCTION */" => "FONCTION",
		"IF(    CHAR_LENGTH(`divisions1`.`division`), CONCAT_WS('',   `divisions1`.`division`), '') /* DIVISION */" => "DIVISION",
		"IF(    CHAR_LENGTH(`directions1`.`direction`), CONCAT_WS('',   `directions1`.`direction`), '') /* DIRECTION */" => "DIRECTION",
		"IF(    CHAR_LENGTH(`services1`.`service`), CONCAT_WS('',   `services1`.`service`), '') /* SERVICE */" => "SERVICE",
		"`demandes_conge_m`.`depart`" => "DATE DEPART",
		"`demandes_conge_m`.`retour`" => "DATE RETOUR",
		"`demandes_conge_m`.`raison`" => "NATURE DU CONGE",
		"`demandes_conge_m`.`date_dernier_permission`" => "DATE DERNIER CONGE",
		"`demandes_conge_m`.`jours`" => "NBR JOURS",
		"`demandes_conge_m`.`adresse_permission`" => "ADRESSE PERMISSION",
		"`demandes_conge_m`.`justificatif_permission`" => "JUSTIFICATIF",
		"`demandes_conge_m`.`observation`" => "OBSERVATION"
	);

	// Fields that can be quick searched
	$x->QueryFieldsQS = array(   
		"`demandes_conge_m`.`iddemande_permission`" => "iddemande_permission",
		"if(`demandes_conge_m`.`date_demande_p`,date_format(`demandes_conge_m`.`date_demande_p`,'%d/%m/%Y'),'')" => "date_demande_p",
		"`demandes_conge_m`.`numero`" => "numero",
		"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(    CHAR_LENGTH(if(`dossier_individuel1`.`date_recrutement`,date_format(`dossier_individuel1`.`date_recrutement`,'%d/%m/%Y'),'')), CONCAT_WS('',   if(`dossier_individuel1`.`date_recrutement`,date_format(`dossier_individuel1`.`date_recrutement`,'%d/%m/%Y'),'')), '') /* DATE DE RECRUTEMENT */" => "date_recrutement",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* FONCTION */" => "fonction",
		"IF(    CHAR_LENGTH(`divisions1`.`division`), CONCAT_WS('',   `divisions1`.`division`), '') /* DIVISION */" => "division",
		"IF(    CHAR_LENGTH(`directions1`.`direction`), CONCAT_WS('',   `directions1`.`direction`), '') /* DIRECTION */" => "direction",
		"IF(    CHAR_LENGTH(`services1`.`service`), CONCAT_WS('',   `services1`.`service`), '') /* SERVICE */" => "service",
		"if(`demandes_conge_m`.`depart`,date_format(`demandes_conge_m`.`depart`,'%d/%m/%Y'),'')" => "depart",
		"if(`demandes_conge_m`.`retour`,date_format(`demandes_conge_m`.`retour`,'%d/%m/%Y'),'')" => "retour",
		"`demandes_conge_m`.`raison`" => "raison",
		"if(`demandes_conge_m`.`date_dernier_permission`,date_format(`demandes_conge_m`.`date_dernier_permission`,'%d/%m/%Y'),'')" => "date_dernier_permission",
		"`demandes_conge_m`.`jours`" => "jours",
		"`demandes_conge_m`.`adresse_permission`" => "adresse_permission",
		"`demandes_conge_m`.`justificatif_permission`" => "justificatif_permission",
		"`demandes_conge_m`.`observation`" => "observation"
	);

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

	$x->QueryFrom = "`demandes_conge_m` LEFT JOIN `dossier_individuel` as dossier_individuel1 ON `dossier_individuel1`.`iddindividuel`=`demandes_conge_m`.`matricule` LEFT JOIN `fonctions` as fonctions1 ON `fonctions1`.`idfonction`=`dossier_individuel1`.`fonction` LEFT JOIN `divisions` as divisions1 ON `divisions1`.`iddivision`=`dossier_individuel1`.`division` LEFT JOIN `directions` as directions1 ON `directions1`.`iddirection`=`dossier_individuel1`.`direction` LEFT JOIN `services` as services1 ON `services1`.`idservice`=`dossier_individuel1`.`service` ";
	$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 = "demandes_conge_m_view.php";
	$x->RedirectAfterInsert = "demandes_conge_m_view.php?SelectedID=#ID#";
	$x->TableTitle = "DEMANDES CONGE";
	$x->TableIcon = "resources/table_icons/folder_table.png";
	$x->PrimaryKey = "`demandes_conge_m`.`iddemande_permission`";
	$x->DefaultSortField = '1';
	$x->DefaultSortDirection = 'desc';

	$x->ColWidth   = array(  150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150);
	$x->ColCaption = array("N&#176;", "DATE DE DEMANDE", "NUMERO", "DATE DE RECRUTEMENT", "FONCTION", "DIVISION", "DIRECTION", "SERVICE", "DATE DEPART", "DATE RETOUR", "NATURE DU CONGE", "DATE DERNIER CONGE");
	$x->ColFieldName = array('iddemande_permission', 'date_demande_p', 'numero', 'date_recrutement', 'fonction', 'division', 'direction', 'service', 'depart', 'retour', 'raison', 'date_dernier_permission');
	$x->ColNumber  = array(1, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14);

	// template paths below are based on the app main directory
	$x->Template = 'templates/demandes_conge_m_templateTV.html';
	$x->SelectedTemplate = 'templates/demandes_conge_m_templateTVS.html';
	$x->TemplateDV = 'templates/demandes_conge_m_templateDV.html';
	$x->TemplateDVP = 'templates/demandes_conge_m_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 `demandes_conge_m`.`iddemande_permission`=membership_userrecords.pkValue and membership_userrecords.tableName='demandes_conge_m' 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 `demandes_conge_m`.`iddemande_permission`=membership_userrecords.pkValue and membership_userrecords.tableName='demandes_conge_m' 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 = '`demandes_conge_m`';
		$x->QueryWhere = '';
		$x->DefaultSortField = '';
	}
	// hook: demandes_conge_m_init
	$render=TRUE;
	if(function_exists('demandes_conge_m_init')){
		$args=array();
		$render=demandes_conge_m_init($x, getMemberInfo(), $args);
	}

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

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