<?php
// This script and data application were generated by AppGini 5.81
// 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/bon_passage.php");
	include("$currDir/bon_passage_dml.php");

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

	// Fields that can be displayed in the table view
	$x->QueryFieldsTV = array(
		"`bon_passage`.`idbon`" => "idbon",
		"if(`bon_passage`.`date`,date_format(`bon_passage`.`date`,'%d/%m/%Y'),'')" => "date",
		"`bon_passage`.`pnr`" => "pnr",
		"`bon_passage`.`nous_prions`" => "nous_prions",
		"`bon_passage`.`au_nom_de`" => "au_nom_de",
		"`bon_passage`.`parcours`" => "parcours",
		"if(`bon_passage`.`depart`,date_format(`bon_passage`.`depart`,'%d/%m/%Y'),'')" => "depart",
		"if(`bon_passage`.`retour`,date_format(`bon_passage`.`retour`,'%d/%m/%Y'),'')" => "retour",
		"REPLACE(FORMAT(`bon_passage`.`total_ht`, 0), ',', ' ')" => "total_ht",
		"`bon_passage`.`commissions`" => "commissions",
		"REPLACE(FORMAT(`bon_passage`.`total_ttc`, 0), ',', ' ')" => "total_ttc",
		"REPLACE(FORMAT(`bon_passage`.`frais_pta`, 0), ',', ' ')" => "frais_pta",
		"REPLACE(FORMAT(`bon_passage`.`net_payer`, 0), ',', ' ')" => "net_payer",
		"`bon_passage`.`num_billet`" => "num_billet",
		"`bon_passage`.`statut`" => "statut",
		"`bon_passage`.`observations`" => "observations",
	);
	// mapping incoming sort by requests to actual query fields
	$x->SortFields = array(
		1 => '`bon_passage`.`idbon`',
		2 => '`bon_passage`.`date`',
		3 => 3,
		4 => 4,
		5 => 5,
		6 => 6,
		7 => '`bon_passage`.`depart`',
		8 => '`bon_passage`.`retour`',
		9 => '`bon_passage`.`total_ht`',
		10 => '`bon_passage`.`commissions`',
		11 => '`bon_passage`.`total_ttc`',
		12 => '`bon_passage`.`frais_pta`',
		13 => '`bon_passage`.`net_payer`',
		14 => 14,
		15 => 15,
		16 => 16,
	);

	// Fields that can be displayed in the csv file
	$x->QueryFieldsCSV = array(
		"`bon_passage`.`idbon`" => "idbon",
		"if(`bon_passage`.`date`,date_format(`bon_passage`.`date`,'%d/%m/%Y'),'')" => "date",
		"`bon_passage`.`pnr`" => "pnr",
		"`bon_passage`.`nous_prions`" => "nous_prions",
		"`bon_passage`.`au_nom_de`" => "au_nom_de",
		"`bon_passage`.`parcours`" => "parcours",
		"if(`bon_passage`.`depart`,date_format(`bon_passage`.`depart`,'%d/%m/%Y'),'')" => "depart",
		"if(`bon_passage`.`retour`,date_format(`bon_passage`.`retour`,'%d/%m/%Y'),'')" => "retour",
		"REPLACE(FORMAT(`bon_passage`.`total_ht`, 0), ',', ' ')" => "total_ht",
		"`bon_passage`.`commissions`" => "commissions",
		"REPLACE(FORMAT(`bon_passage`.`total_ttc`, 0), ',', ' ')" => "total_ttc",
		"REPLACE(FORMAT(`bon_passage`.`frais_pta`, 0), ',', ' ')" => "frais_pta",
		"REPLACE(FORMAT(`bon_passage`.`net_payer`, 0), ',', ' ')" => "net_payer",
		"`bon_passage`.`num_billet`" => "num_billet",
		"`bon_passage`.`statut`" => "statut",
		"`bon_passage`.`observations`" => "observations",
	);
	// Fields that can be filtered
	$x->QueryFieldsFilters = array(
		"`bon_passage`.`idbon`" => "N&#176;",
		"`bon_passage`.`date`" => "Date",
		"`bon_passage`.`pnr`" => "PNR",
		"`bon_passage`.`nous_prions`" => "Nous prions",
		"`bon_passage`.`au_nom_de`" => "Au nom de",
		"`bon_passage`.`parcours`" => "Sur le parcours",
		"`bon_passage`.`depart`" => "D&#233;part le",
		"`bon_passage`.`retour`" => "Retour le",
		"`bon_passage`.`total_ht`" => "Total HT",
		"`bon_passage`.`commissions`" => "Commissions",
		"`bon_passage`.`total_ttc`" => "Total TTC",
		"`bon_passage`.`frais_pta`" => "Frais PTA",
		"`bon_passage`.`net_payer`" => "Net &#224; payer",
		"`bon_passage`.`num_billet`" => "N&#176; Billet",
		"`bon_passage`.`statut`" => "Statut",
		"`bon_passage`.`observations`" => "Observations",
	);

	// Fields that can be quick searched
	$x->QueryFieldsQS = array(
		"`bon_passage`.`idbon`" => "idbon",
		"if(`bon_passage`.`date`,date_format(`bon_passage`.`date`,'%d/%m/%Y'),'')" => "date",
		"`bon_passage`.`pnr`" => "pnr",
		"`bon_passage`.`nous_prions`" => "nous_prions",
		"`bon_passage`.`au_nom_de`" => "au_nom_de",
		"`bon_passage`.`parcours`" => "parcours",
		"if(`bon_passage`.`depart`,date_format(`bon_passage`.`depart`,'%d/%m/%Y'),'')" => "depart",
		"if(`bon_passage`.`retour`,date_format(`bon_passage`.`retour`,'%d/%m/%Y'),'')" => "retour",
		"REPLACE(FORMAT(`bon_passage`.`total_ht`, 0), ',', ' ')" => "total_ht",
		"`bon_passage`.`commissions`" => "commissions",
		"REPLACE(FORMAT(`bon_passage`.`total_ttc`, 0), ',', ' ')" => "total_ttc",
		"REPLACE(FORMAT(`bon_passage`.`frais_pta`, 0), ',', ' ')" => "frais_pta",
		"REPLACE(FORMAT(`bon_passage`.`net_payer`, 0), ',', ' ')" => "net_payer",
		"`bon_passage`.`num_billet`" => "num_billet",
		"`bon_passage`.`statut`" => "statut",
		"`bon_passage`.`observations`" => "observations",
	);

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

	$x->QueryFrom = "`bon_passage` ";
	$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 = 10;
	$x->QuickSearch = 1;
	$x->QuickSearchText = $Translation["quick search"];
	$x->ScriptFileName = "bon_passage_view.php";
	$x->RedirectAfterInsert = "bon_passage_view.php?SelectedID=#ID#";
	$x->TableTitle = "BON DE PASSAGE";
	$x->TableIcon = "resources/table_icons/marega.png";
	$x->PrimaryKey = "`bon_passage`.`idbon`";
	$x->DefaultSortField = '`bon_passage`.`date`';
	$x->DefaultSortDirection = 'desc';

	$x->ColWidth   = array(  150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150);
	$x->ColCaption = array("N&#176;", "Date", "PNR", "Nous prions", "Au nom de", "Sur le parcours", "D&#233;part le", "Retour le", "Total HT", "Commissions", "Total TTC", "Frais PTA", "Net &#224; payer", "N&#176; Billet", "Statut");
	$x->ColFieldName = array('idbon', 'date', 'pnr', 'nous_prions', 'au_nom_de', 'parcours', 'depart', 'retour', 'total_ht', 'commissions', 'total_ttc', 'frais_pta', 'net_payer', 'num_billet', 'statut');
	$x->ColNumber  = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);

	// template paths below are based on the app main directory
	$x->Template = 'templates/bon_passage_templateTV.html';
	$x->SelectedTemplate = 'templates/bon_passage_templateTVS.html';
	$x->TemplateDV = 'templates/bon_passage_templateDV.html';
	$x->TemplateDVP = 'templates/bon_passage_templateDVP.html';

	$x->ShowTableHeader = 1;
	$x->TVClasses = "";
	$x->DVClasses = "";
	$x->HighlightColor = '#FFF0C2';
	$x->HasCalculatedFields = false;

	// 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 `bon_passage`.`idbon`=membership_userrecords.pkValue and membership_userrecords.tableName='bon_passage' 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 `bon_passage`.`idbon`=membership_userrecords.pkValue and membership_userrecords.tableName='bon_passage' 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 = '`bon_passage`';
		$x->QueryWhere = '';
		$x->DefaultSortField = '';
	}
	// hook: bon_passage_init
	$render=TRUE;
	if(function_exists('bon_passage_init')) {
		$args=array();
		$render=bon_passage_init($x, getMemberInfo(), $args);
	}

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

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