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

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

	// Fields that can be displayed in the table view
	$x->QueryFieldsTV = array(   
		"`fiche_pointages`.`id_fiche_pointage`" => "id_fiche_pointage",
		"IF(    CHAR_LENGTH(`pointages1`.`to_fiche_pointage`), CONCAT_WS('',   `pointages1`.`to_fiche_pointage`), '') /* From pointage */" => "from_pointage",
		"if(`fiche_pointages`.`date_fiche_pointage`,date_format(`fiche_pointages`.`date_fiche_pointage`,'%d/%m/%Y'),'')" => "date_fiche_pointage",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`nom_prenom`), CONCAT_WS('',   `dossier_individuel1`.`nom_prenom`), '') /* NOM ET PRENOM */" => "nom_prenom_fp",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* FONCTION */" => "fonction_fp",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`nni`), CONCAT_WS('',   `dossier_individuel1`.`nni`), '') /* NNI */" => "nni_fp",
		"`fiche_pointages`.`heure_arrive`" => "heure_arrive",
		"`fiche_pointages`.`heure_depart`" => "heure_depart",
		"`fiche_pointages`.`emargement`" => "emargement"
	);
	// mapping incoming sort by requests to actual query fields
	$x->SortFields = array(   
		1 => '`fiche_pointages`.`id_fiche_pointage`',
		2 => '`pointages1`.`to_fiche_pointage`',
		3 => '`fiche_pointages`.`date_fiche_pointage`',
		4 => '`dossier_individuel1`.`nom_prenom`',
		5 => 5,
		6 => '`dossier_individuel1`.`nni`',
		7 => '`fiche_pointages`.`heure_arrive`',
		8 => '`fiche_pointages`.`heure_depart`',
		9 => 9
	);

	// Fields that can be displayed in the csv file
	$x->QueryFieldsCSV = array(   
		"`fiche_pointages`.`id_fiche_pointage`" => "id_fiche_pointage",
		"IF(    CHAR_LENGTH(`pointages1`.`to_fiche_pointage`), CONCAT_WS('',   `pointages1`.`to_fiche_pointage`), '') /* From pointage */" => "from_pointage",
		"if(`fiche_pointages`.`date_fiche_pointage`,date_format(`fiche_pointages`.`date_fiche_pointage`,'%d/%m/%Y'),'')" => "date_fiche_pointage",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`nom_prenom`), CONCAT_WS('',   `dossier_individuel1`.`nom_prenom`), '') /* NOM ET PRENOM */" => "nom_prenom_fp",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* FONCTION */" => "fonction_fp",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`nni`), CONCAT_WS('',   `dossier_individuel1`.`nni`), '') /* NNI */" => "nni_fp",
		"`fiche_pointages`.`heure_arrive`" => "heure_arrive",
		"`fiche_pointages`.`heure_depart`" => "heure_depart",
		"`fiche_pointages`.`emargement`" => "emargement"
	);
	// Fields that can be filtered
	$x->QueryFieldsFilters = array(   
		"`fiche_pointages`.`id_fiche_pointage`" => "ID",
		"IF(    CHAR_LENGTH(`pointages1`.`to_fiche_pointage`), CONCAT_WS('',   `pointages1`.`to_fiche_pointage`), '') /* From pointage */" => "From pointage",
		"`fiche_pointages`.`date_fiche_pointage`" => "DATE",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`nom_prenom`), CONCAT_WS('',   `dossier_individuel1`.`nom_prenom`), '') /* NOM ET PRENOM */" => "NOM ET PRENOM",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* FONCTION */" => "FONCTION",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`nni`), CONCAT_WS('',   `dossier_individuel1`.`nni`), '') /* NNI */" => "NNI",
		"`fiche_pointages`.`heure_arrive`" => "HEURE / ARRIVEE",
		"`fiche_pointages`.`heure_depart`" => "HEURE / DEPART",
		"`fiche_pointages`.`emargement`" => "EMARGEMENT"
	);

	// Fields that can be quick searched
	$x->QueryFieldsQS = array(   
		"`fiche_pointages`.`id_fiche_pointage`" => "id_fiche_pointage",
		"IF(    CHAR_LENGTH(`pointages1`.`to_fiche_pointage`), CONCAT_WS('',   `pointages1`.`to_fiche_pointage`), '') /* From pointage */" => "from_pointage",
		"if(`fiche_pointages`.`date_fiche_pointage`,date_format(`fiche_pointages`.`date_fiche_pointage`,'%d/%m/%Y'),'')" => "date_fiche_pointage",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`nom_prenom`), CONCAT_WS('',   `dossier_individuel1`.`nom_prenom`), '') /* NOM ET PRENOM */" => "nom_prenom_fp",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* FONCTION */" => "fonction_fp",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`nni`), CONCAT_WS('',   `dossier_individuel1`.`nni`), '') /* NNI */" => "nni_fp",
		"`fiche_pointages`.`heure_arrive`" => "heure_arrive",
		"`fiche_pointages`.`heure_depart`" => "heure_depart",
		"`fiche_pointages`.`emargement`" => "emargement"
	);

	// Lookup fields that can be used as filterers
	$x->filterers = array(  'from_pointage' => 'From pointage', 'nom_prenom_fp' => 'NOM ET PRENOM');

	$x->QueryFrom = "`fiche_pointages` LEFT JOIN `pointages` as pointages1 ON `pointages1`.`id_pointages`=`fiche_pointages`.`from_pointage` LEFT JOIN `dossier_individuel` as dossier_individuel1 ON `dossier_individuel1`.`iddindividuel`=`fiche_pointages`.`nom_prenom_fp` LEFT JOIN `fonctions` as fonctions1 ON `fonctions1`.`idfonction`=`dossier_individuel1`.`fonction` ";
	$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 = "fiche_pointages_view.php";
	$x->RedirectAfterInsert = "fiche_pointages_view.php?SelectedID=#ID#";
	$x->TableTitle = "LISTE POINTAGES";
	$x->TableIcon = "resources/table_icons/session_idle_time.png";
	$x->PrimaryKey = "`fiche_pointages`.`id_fiche_pointage`";
	$x->DefaultSortField = '`fiche_pointages`.`date_fiche_pointage`';
	$x->DefaultSortDirection = 'desc';

	$x->ColWidth   = array(  150, 150, 150, 150, 150, 150, 150);
	$x->ColCaption = array("DATE", "NOM ET PRENOM", "FONCTION", "NNI", "HEURE / ARRIVEE", "HEURE / DEPART", "EMARGEMENT");
	$x->ColFieldName = array('date_fiche_pointage', 'nom_prenom_fp', 'fonction_fp', 'nni_fp', 'heure_arrive', 'heure_depart', 'emargement');
	$x->ColNumber  = array(3, 4, 5, 6, 7, 8, 9);

	// template paths below are based on the app main directory
	$x->Template = 'templates/fiche_pointages_templateTV.html';
	$x->SelectedTemplate = 'templates/fiche_pointages_templateTVS.html';
	$x->TemplateDV = 'templates/fiche_pointages_templateDV.html';
	$x->TemplateDVP = 'templates/fiche_pointages_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 `fiche_pointages`.`id_fiche_pointage`=membership_userrecords.pkValue and membership_userrecords.tableName='fiche_pointages' 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 `fiche_pointages`.`id_fiche_pointage`=membership_userrecords.pkValue and membership_userrecords.tableName='fiche_pointages' 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 = '`fiche_pointages`';
		$x->QueryWhere = '';
		$x->DefaultSortField = '';
	}
	// hook: fiche_pointages_init
	$render=TRUE;
	if(function_exists('fiche_pointages_init')){
		$args=array();
		$render=fiche_pointages_init($x, getMemberInfo(), $args);
	}

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

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