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

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

	// Fields that can be displayed in the table view
	$x->QueryFieldsTV = array(   
		"`etat_banques`.`id_etat_banque`" => "id_etat_banque",
		"IF(    CHAR_LENGTH(`banques1`.`to_etat_banques`), CONCAT_WS('',   `banques1`.`to_etat_banques`), '') /* From banque */" => "from_banque",
		"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 prenom */" => "nom_prenom",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* Fonction */" => "fonction",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`salaire`), CONCAT_WS('',   `dossier_individuel1`.`salaire`), '') /* SALAIRE */" => "salaire",
		"`etat_banques`.`montant`" => "montant",
		"REPLACE(FORMAT(`etat_banques`.`qte`, 0), ',', ' ')" => "qte",
		"REPLACE(FORMAT(`etat_banques`.`total`, 0), ',', ' ')" => "total",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`compte`), CONCAT_WS('',   `dossier_individuel1`.`compte`), '') /* N compte */" => "n_compte",
		"IF(    CHAR_LENGTH(`les_banques1`.`banque`), CONCAT_WS('',   `les_banques1`.`banque`), '') /* Banque */" => "banque"
	);
	// mapping incoming sort by requests to actual query fields
	$x->SortFields = array(   
		1 => '`etat_banques`.`id_etat_banque`',
		2 => '`banques1`.`to_etat_banques`',
		3 => '`dossier_individuel1`.`matricule`',
		4 => '`dossier_individuel1`.`nom_prenom`',
		5 => 5,
		6 => '`dossier_individuel1`.`salaire`',
		7 => '`etat_banques`.`montant`',
		8 => '`etat_banques`.`qte`',
		9 => '`etat_banques`.`total`',
		10 => '`dossier_individuel1`.`compte`',
		11 => 11
	);

	// Fields that can be displayed in the csv file
	$x->QueryFieldsCSV = array(   
		"`etat_banques`.`id_etat_banque`" => "id_etat_banque",
		"IF(    CHAR_LENGTH(`banques1`.`to_etat_banques`), CONCAT_WS('',   `banques1`.`to_etat_banques`), '') /* From banque */" => "from_banque",
		"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 prenom */" => "nom_prenom",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* Fonction */" => "fonction",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`salaire`), CONCAT_WS('',   `dossier_individuel1`.`salaire`), '') /* SALAIRE */" => "salaire",
		"`etat_banques`.`montant`" => "montant",
		"REPLACE(FORMAT(`etat_banques`.`qte`, 0), ',', ' ')" => "qte",
		"REPLACE(FORMAT(`etat_banques`.`total`, 0), ',', ' ')" => "total",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`compte`), CONCAT_WS('',   `dossier_individuel1`.`compte`), '') /* N compte */" => "n_compte",
		"IF(    CHAR_LENGTH(`les_banques1`.`banque`), CONCAT_WS('',   `les_banques1`.`banque`), '') /* Banque */" => "banque"
	);
	// Fields that can be filtered
	$x->QueryFieldsFilters = array(   
		"`etat_banques`.`id_etat_banque`" => "ID",
		"IF(    CHAR_LENGTH(`banques1`.`to_etat_banques`), CONCAT_WS('',   `banques1`.`to_etat_banques`), '') /* From banque */" => "From banque",
		"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 prenom */" => "Nom prenom",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* Fonction */" => "Fonction",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`salaire`), CONCAT_WS('',   `dossier_individuel1`.`salaire`), '') /* SALAIRE */" => "SALAIRE",
		"`etat_banques`.`montant`" => "MONTANT",
		"`etat_banques`.`qte`" => "Qte",
		"`etat_banques`.`total`" => "Total",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`compte`), CONCAT_WS('',   `dossier_individuel1`.`compte`), '') /* N compte */" => "N compte",
		"IF(    CHAR_LENGTH(`les_banques1`.`banque`), CONCAT_WS('',   `les_banques1`.`banque`), '') /* Banque */" => "Banque"
	);

	// Fields that can be quick searched
	$x->QueryFieldsQS = array(   
		"`etat_banques`.`id_etat_banque`" => "id_etat_banque",
		"IF(    CHAR_LENGTH(`banques1`.`to_etat_banques`), CONCAT_WS('',   `banques1`.`to_etat_banques`), '') /* From banque */" => "from_banque",
		"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 prenom */" => "nom_prenom",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* Fonction */" => "fonction",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`salaire`), CONCAT_WS('',   `dossier_individuel1`.`salaire`), '') /* SALAIRE */" => "salaire",
		"`etat_banques`.`montant`" => "montant",
		"REPLACE(FORMAT(`etat_banques`.`qte`, 0), ',', ' ')" => "qte",
		"REPLACE(FORMAT(`etat_banques`.`total`, 0), ',', ' ')" => "total",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`compte`), CONCAT_WS('',   `dossier_individuel1`.`compte`), '') /* N compte */" => "n_compte",
		"IF(    CHAR_LENGTH(`les_banques1`.`banque`), CONCAT_WS('',   `les_banques1`.`banque`), '') /* Banque */" => "banque"
	);

	// Lookup fields that can be used as filterers
	$x->filterers = array(  'from_banque' => 'From banque', 'matricule' => 'Matricule');

	$x->QueryFrom = "`etat_banques` LEFT JOIN `banques` as banques1 ON `banques1`.`id_banque`=`etat_banques`.`from_banque` LEFT JOIN `dossier_individuel` as dossier_individuel1 ON `dossier_individuel1`.`iddindividuel`=`etat_banques`.`matricule` LEFT JOIN `fonctions` as fonctions1 ON `fonctions1`.`idfonction`=`dossier_individuel1`.`fonction` LEFT JOIN `les_banques` as les_banques1 ON `les_banques1`.`id`=`dossier_individuel1`.`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 = 100;
	$x->QuickSearch = 1;
	$x->QuickSearchText = $Translation["quick search"];
	$x->ScriptFileName = "etat_banques_view.php";
	$x->RedirectAfterInsert = "etat_banques_view.php?SelectedID=#ID#";
	$x->TableTitle = "LISTE ETAT BANQUES";
	$x->TableIcon = "resources/table_icons/card_bank.png";
	$x->PrimaryKey = "`etat_banques`.`id_etat_banque`";
	$x->DefaultSortField = '1';
	$x->DefaultSortDirection = 'asc';

	$x->ColWidth   = array(  150, 150, 150, 150, 150, 150);
	$x->ColCaption = array("Matricule", "Nom prenom", "Fonction", "MONTANT", "N compte", "Banque");
	$x->ColFieldName = array('matricule', 'nom_prenom', 'fonction', 'montant', 'n_compte', 'banque');
	$x->ColNumber  = array(3, 4, 5, 7, 10, 11);

	// template paths below are based on the app main directory
	$x->Template = 'templates/etat_banques_templateTV.html';
	$x->SelectedTemplate = 'templates/etat_banques_templateTVS.html';
	$x->TemplateDV = 'templates/etat_banques_templateDV.html';
	$x->TemplateDVP = 'templates/etat_banques_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 `etat_banques`.`id_etat_banque`=membership_userrecords.pkValue and membership_userrecords.tableName='etat_banques' 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 `etat_banques`.`id_etat_banque`=membership_userrecords.pkValue and membership_userrecords.tableName='etat_banques' 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 = '`etat_banques`';
		$x->QueryWhere = '';
		$x->DefaultSortField = '';
	}
	// hook: etat_banques_init
	$render=TRUE;
	if(function_exists('etat_banques_init')){
		$args=array();
		$render=etat_banques_init($x, getMemberInfo(), $args);
	}

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

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