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

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

	// Fields that can be displayed in the table view
	$x->QueryFieldsTV = array(   
		"`conges`.`id_conge`" => "id_conge",
		"`conges`.`numero`" => "numero",
		"if(`conges`.`date`,date_format(`conges`.`date`,'%d/%m/%Y'),'')" => "date",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`nom_prenom`), CONCAT_WS('',   `dossier_individuel1`.`nom_prenom`), '') /* NOM ET PRENOM DU BENEFICIAIRE */" => "nom_prenom",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`matricule`), CONCAT_WS('',   `dossier_individuel1`.`matricule`), '') /* MATRICULE */" => "matricule",
		"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",
		"`conges`.`num_fiche`" => "num_fiche",
		"`conges`.`nature`" => "nature",
		"if(`conges`.`date_debut`,date_format(`conges`.`date_debut`,'%d/%m/%Y'),'')" => "date_debut",
		"if(`conges`.`date_fin`,date_format(`conges`.`date_fin`,'%d/%m/%Y'),'')" => "date_fin",
		"`conges`.`jours`" => "jours",
		"`conges`.`directeur`" => "directeur"
	);
	// mapping incoming sort by requests to actual query fields
	$x->SortFields = array(   
		1 => '`conges`.`id_conge`',
		2 => 2,
		3 => '`conges`.`date`',
		4 => '`dossier_individuel1`.`nom_prenom`',
		5 => '`dossier_individuel1`.`matricule`',
		6 => 6,
		7 => 7,
		8 => 8,
		9 => 9,
		10 => 10,
		11 => '`conges`.`date_debut`',
		12 => '`conges`.`date_fin`',
		13 => '`conges`.`jours`',
		14 => 14
	);

	// Fields that can be displayed in the csv file
	$x->QueryFieldsCSV = array(   
		"`conges`.`id_conge`" => "id_conge",
		"`conges`.`numero`" => "numero",
		"if(`conges`.`date`,date_format(`conges`.`date`,'%d/%m/%Y'),'')" => "date",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`nom_prenom`), CONCAT_WS('',   `dossier_individuel1`.`nom_prenom`), '') /* NOM ET PRENOM DU BENEFICIAIRE */" => "nom_prenom",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`matricule`), CONCAT_WS('',   `dossier_individuel1`.`matricule`), '') /* MATRICULE */" => "matricule",
		"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",
		"`conges`.`num_fiche`" => "num_fiche",
		"`conges`.`nature`" => "nature",
		"if(`conges`.`date_debut`,date_format(`conges`.`date_debut`,'%d/%m/%Y'),'')" => "date_debut",
		"if(`conges`.`date_fin`,date_format(`conges`.`date_fin`,'%d/%m/%Y'),'')" => "date_fin",
		"`conges`.`jours`" => "jours",
		"`conges`.`directeur`" => "directeur"
	);
	// Fields that can be filtered
	$x->QueryFieldsFilters = array(   
		"`conges`.`id_conge`" => "N&#176;",
		"`conges`.`numero`" => "NOTE DE SERVICE DE CONGE N&#176;",
		"`conges`.`date`" => "DATE",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`nom_prenom`), CONCAT_WS('',   `dossier_individuel1`.`nom_prenom`), '') /* NOM ET PRENOM DU BENEFICIAIRE */" => "NOM ET PRENOM DU BENEFICIAIRE",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`matricule`), CONCAT_WS('',   `dossier_individuel1`.`matricule`), '') /* MATRICULE */" => "MATRICULE",
		"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",
		"`conges`.`num_fiche`" => "N&#176; FICHE DE LA DEMANDE DE CONGE",
		"`conges`.`nature`" => "NATURE DU CONGE ANNUEL",
		"`conges`.`date_debut`" => "DATE DE DEBUT DE CONGE",
		"`conges`.`date_fin`" => "DATE DE FIN DE CONGE",
		"`conges`.`jours`" => "NOMBRE DE JOUR",
		"`conges`.`directeur`" => "LE SECRETAIRE GENERAL"
	);

	// Fields that can be quick searched
	$x->QueryFieldsQS = array(   
		"`conges`.`id_conge`" => "id_conge",
		"`conges`.`numero`" => "numero",
		"if(`conges`.`date`,date_format(`conges`.`date`,'%d/%m/%Y'),'')" => "date",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`nom_prenom`), CONCAT_WS('',   `dossier_individuel1`.`nom_prenom`), '') /* NOM ET PRENOM DU BENEFICIAIRE */" => "nom_prenom",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`matricule`), CONCAT_WS('',   `dossier_individuel1`.`matricule`), '') /* MATRICULE */" => "matricule",
		"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",
		"`conges`.`num_fiche`" => "num_fiche",
		"`conges`.`nature`" => "nature",
		"if(`conges`.`date_debut`,date_format(`conges`.`date_debut`,'%d/%m/%Y'),'')" => "date_debut",
		"if(`conges`.`date_fin`,date_format(`conges`.`date_fin`,'%d/%m/%Y'),'')" => "date_fin",
		"`conges`.`jours`" => "jours",
		"`conges`.`directeur`" => "directeur"
	);

	// Lookup fields that can be used as filterers
	$x->filterers = array(  'nom_prenom' => 'NOM ET PRENOM DU BENEFICIAIRE');

	$x->QueryFrom = "`conges` LEFT JOIN `dossier_individuel` as dossier_individuel1 ON `dossier_individuel1`.`iddindividuel`=`conges`.`nom_prenom` LEFT JOIN `fonctions` as fonctions1 ON `fonctions1`.`idfonction`=`dossier_individuel1`.`fonction` 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 = "conges_view.php";
	$x->RedirectAfterInsert = "conges_view.php?SelectedID=#ID#";
	$x->TableTitle = "NOTE DE SERVICE DE CONGE";
	$x->TableIcon = "resources/table_icons/folder_page_white.png";
	$x->PrimaryKey = "`conges`.`id_conge`";
	$x->DefaultSortField = '`conges`.`date`';
	$x->DefaultSortDirection = 'desc';

	$x->ColWidth   = array(  150, 150, 150, 150, 150, 150, 150, 150, 150);
	$x->ColCaption = array("N&#176;", "DATE", "NOM ET PRENOM DU BENEFICIAIRE", "MATRICULE", "N&#176; FICHE DE LA DEMANDE DE CONGE", "NATURE DU CONGE ANNUEL", "DATE DE DEBUT DE CONGE", "DATE DE FIN DE CONGE", "NOMBRE DE JOUR");
	$x->ColFieldName = array('id_conge', 'date', 'nom_prenom', 'matricule', 'num_fiche', 'nature', 'date_debut', 'date_fin', 'jours');
	$x->ColNumber  = array(1, 3, 4, 5, 9, 10, 11, 12, 13);

	// template paths below are based on the app main directory
	$x->Template = 'templates/conges_templateTV.html';
	$x->SelectedTemplate = 'templates/conges_templateTVS.html';
	$x->TemplateDV = 'templates/conges_templateDV.html';
	$x->TemplateDVP = 'templates/conges_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`.`id_conge`=membership_userrecords.pkValue and membership_userrecords.tableName='conges' 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`.`id_conge`=membership_userrecords.pkValue and membership_userrecords.tableName='conges' 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`';
		$x->QueryWhere = '';
		$x->DefaultSortField = '';
	}
	// hook: conges_init
	$render=TRUE;
	if(function_exists('conges_init')){
		$args=array();
		$render=conges_init($x, getMemberInfo(), $args);
	}

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

	// hook: conges_header
	$headerCode='';
	if(function_exists('conges_header')){
		$args=array();
		$headerCode=conges_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_footer
	$footerCode='';
	if(function_exists('conges_footer')){
		$args=array();
		$footerCode=conges_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);
	}
?>