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

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

	// Fields that can be displayed in the table view
	$x->QueryFieldsTV = array(   
		"`etat_paiements`.`id_etat_paiement`" => "id_etat_paiement",
		"IF(    CHAR_LENGTH(`paiements1`.`to_etat_paiements`), CONCAT_WS('',   `paiements1`.`to_etat_paiements`), '') /* From paiements */" => "from_paiements",
		"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(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* FONCTION */" => "fonction",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`prime_ts`), CONCAT_WS('',   `dossier_individuel1`.`prime_ts`), '') /* PRIME */" => "prime",
		"`etat_paiements`.`montant`" => "montant",
		"`etat_paiements`.`qte`" => "qte",
		"`etat_paiements`.`total`" => "total",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`compte`), CONCAT_WS('',   `dossier_individuel1`.`compte`), '') /* N&#176; 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_paiements`.`id_etat_paiement`',
		2 => '`paiements1`.`to_etat_paiements`',
		3 => '`dossier_individuel1`.`matricule`',
		4 => '`dossier_individuel1`.`nom_prenom`',
		5 => 5,
		6 => 6,
		7 => '`etat_paiements`.`montant`',
		8 => '`etat_paiements`.`qte`',
		9 => '`etat_paiements`.`total`',
		10 => '`dossier_individuel1`.`compte`',
		11 => 11
	);

	// Fields that can be displayed in the csv file
	$x->QueryFieldsCSV = array(   
		"`etat_paiements`.`id_etat_paiement`" => "id_etat_paiement",
		"IF(    CHAR_LENGTH(`paiements1`.`to_etat_paiements`), CONCAT_WS('',   `paiements1`.`to_etat_paiements`), '') /* From paiements */" => "from_paiements",
		"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(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* FONCTION */" => "fonction",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`prime_ts`), CONCAT_WS('',   `dossier_individuel1`.`prime_ts`), '') /* PRIME */" => "prime",
		"`etat_paiements`.`montant`" => "montant",
		"`etat_paiements`.`qte`" => "qte",
		"`etat_paiements`.`total`" => "total",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`compte`), CONCAT_WS('',   `dossier_individuel1`.`compte`), '') /* N&#176; 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_paiements`.`id_etat_paiement`" => "ID",
		"IF(    CHAR_LENGTH(`paiements1`.`to_etat_paiements`), CONCAT_WS('',   `paiements1`.`to_etat_paiements`), '') /* From paiements */" => "From paiements",
		"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(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* FONCTION */" => "FONCTION",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`prime_ts`), CONCAT_WS('',   `dossier_individuel1`.`prime_ts`), '') /* PRIME */" => "PRIME",
		"`etat_paiements`.`montant`" => "MONTANT",
		"`etat_paiements`.`qte`" => "Qte",
		"`etat_paiements`.`total`" => "Total",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`compte`), CONCAT_WS('',   `dossier_individuel1`.`compte`), '') /* N&#176; COMPTE */" => "N&#176; COMPTE",
		"IF(    CHAR_LENGTH(`les_banques1`.`banque`), CONCAT_WS('',   `les_banques1`.`banque`), '') /* BANQUE */" => "BANQUE"
	);

	// Fields that can be quick searched
	$x->QueryFieldsQS = array(   
		"`etat_paiements`.`id_etat_paiement`" => "id_etat_paiement",
		"IF(    CHAR_LENGTH(`paiements1`.`to_etat_paiements`), CONCAT_WS('',   `paiements1`.`to_etat_paiements`), '') /* From paiements */" => "from_paiements",
		"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(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* FONCTION */" => "fonction",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`prime_ts`), CONCAT_WS('',   `dossier_individuel1`.`prime_ts`), '') /* PRIME */" => "prime",
		"`etat_paiements`.`montant`" => "montant",
		"`etat_paiements`.`qte`" => "qte",
		"`etat_paiements`.`total`" => "total",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`compte`), CONCAT_WS('',   `dossier_individuel1`.`compte`), '') /* N&#176; 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_paiements' => 'From paiements', 'matricule' => 'MATRICULE');

	$x->QueryFrom = "`etat_paiements` LEFT JOIN `paiements` as paiements1 ON `paiements1`.`id_paiement`=`etat_paiements`.`from_paiements` LEFT JOIN `dossier_individuel` as dossier_individuel1 ON `dossier_individuel1`.`iddindividuel`=`etat_paiements`.`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 = 1000;
	$x->QuickSearch = 1;
	$x->QuickSearchText = $Translation["quick search"];
	$x->ScriptFileName = "etat_paiements_view.php";
	$x->RedirectAfterInsert = "etat_paiements_view.php?SelectedID=#ID#";
	$x->TableTitle = "LISTE ETAT PAIEMENT";
	$x->TableIcon = "resources/table_icons/coins_in_hand.png";
	$x->PrimaryKey = "`etat_paiements`.`id_etat_paiement`";
	$x->DefaultSortField = '1';
	$x->DefaultSortDirection = 'asc';

	$x->ColWidth   = array(  150, 150, 150, 150, 150, 150);
	$x->ColCaption = array("MATRICULE", "NOM ET PRENOM", "FONCTION", "MONTANT", "N&#176; 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_paiements_templateTV.html';
	$x->SelectedTemplate = 'templates/etat_paiements_templateTVS.html';
	$x->TemplateDV = 'templates/etat_paiements_templateDV.html';
	$x->TemplateDVP = 'templates/etat_paiements_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_paiements`.`id_etat_paiement`=membership_userrecords.pkValue and membership_userrecords.tableName='etat_paiements' 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_paiements`.`id_etat_paiement`=membership_userrecords.pkValue and membership_userrecords.tableName='etat_paiements' 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_paiements`';
		$x->QueryWhere = '';
		$x->DefaultSortField = '';
	}
	// hook: etat_paiements_init
	$render=TRUE;
	if(function_exists('etat_paiements_init')){
		$args=array();
		$render=etat_paiements_init($x, getMemberInfo(), $args);
	}

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

	// hook: etat_paiements_header
	$headerCode='';
	if(function_exists('etat_paiements_header')){
		$args=array();
		$headerCode=etat_paiements_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_paiements_footer
	$footerCode='';
	if(function_exists('etat_paiements_footer')){
		$args=array();
		$footerCode=etat_paiements_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);
	}
?>