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

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

	// Fields that can be displayed in the table view
	$x->QueryFieldsTV = array(   
		"`envois_colis`.`idenvois_coli`" => "idenvois_coli",
		"IF(    CHAR_LENGTH(`colis1`.`link_envoi_colis`), CONCAT_WS('',   `colis1`.`link_envoi_colis`), '') /* Link colis */" => "link_colis",
		"`envois_colis`.`description`" => "description",
		"IF(    CHAR_LENGTH(`agences1`.`agence`), CONCAT_WS('',   `agences1`.`agence`), '') /* Destination */" => "destination",
		"IF(    CHAR_LENGTH(`villes1`.`ville`), CONCAT_WS('',   `villes1`.`ville`), '') /* Agence */" => "ville",
		"`envois_colis`.`prix_unitaire`" => "prix_unitaire",
		"`envois_colis`.`qts`" => "qts",
		"`envois_colis`.`prix_total`" => "prix_total",
		"`envois_colis`.`beneficiaire`" => "beneficiaire",
		"`envois_colis`.`telephone_beneficiaire`" => "telephone_beneficiaire",
		"`envois_colis`.`nni_beneficiaire`" => "nni_beneficiaire",
		"if(`envois_colis`.`date_reception`,date_format(`envois_colis`.`date_reception`,'%d/%m/%Y'),'')" => "date_reception",
		"`envois_colis`.`statut`" => "statut",
		"`envois_colis`.`observation`" => "observation"
	);
	// mapping incoming sort by requests to actual query fields
	$x->SortFields = array(   
		1 => '`envois_colis`.`idenvois_coli`',
		2 => '`colis1`.`link_envoi_colis`',
		3 => 3,
		4 => '`agences1`.`agence`',
		5 => 5,
		6 => '`envois_colis`.`prix_unitaire`',
		7 => '`envois_colis`.`qts`',
		8 => '`envois_colis`.`prix_total`',
		9 => 9,
		10 => 10,
		11 => 11,
		12 => '`envois_colis`.`date_reception`',
		13 => 13,
		14 => 14
	);

	// Fields that can be displayed in the csv file
	$x->QueryFieldsCSV = array(   
		"`envois_colis`.`idenvois_coli`" => "idenvois_coli",
		"IF(    CHAR_LENGTH(`colis1`.`link_envoi_colis`), CONCAT_WS('',   `colis1`.`link_envoi_colis`), '') /* Link colis */" => "link_colis",
		"`envois_colis`.`description`" => "description",
		"IF(    CHAR_LENGTH(`agences1`.`agence`), CONCAT_WS('',   `agences1`.`agence`), '') /* Destination */" => "destination",
		"IF(    CHAR_LENGTH(`villes1`.`ville`), CONCAT_WS('',   `villes1`.`ville`), '') /* Agence */" => "ville",
		"`envois_colis`.`prix_unitaire`" => "prix_unitaire",
		"`envois_colis`.`qts`" => "qts",
		"`envois_colis`.`prix_total`" => "prix_total",
		"`envois_colis`.`beneficiaire`" => "beneficiaire",
		"`envois_colis`.`telephone_beneficiaire`" => "telephone_beneficiaire",
		"`envois_colis`.`nni_beneficiaire`" => "nni_beneficiaire",
		"if(`envois_colis`.`date_reception`,date_format(`envois_colis`.`date_reception`,'%d/%m/%Y'),'')" => "date_reception",
		"`envois_colis`.`statut`" => "statut",
		"`envois_colis`.`observation`" => "observation"
	);
	// Fields that can be filtered
	$x->QueryFieldsFilters = array(   
		"`envois_colis`.`idenvois_coli`" => "ID",
		"IF(    CHAR_LENGTH(`colis1`.`link_envoi_colis`), CONCAT_WS('',   `colis1`.`link_envoi_colis`), '') /* Link colis */" => "Link colis",
		"`envois_colis`.`description`" => "Description",
		"IF(    CHAR_LENGTH(`agences1`.`agence`), CONCAT_WS('',   `agences1`.`agence`), '') /* Destination */" => "Destination",
		"IF(    CHAR_LENGTH(`villes1`.`ville`), CONCAT_WS('',   `villes1`.`ville`), '') /* Agence */" => "Agence",
		"`envois_colis`.`prix_unitaire`" => "Prix unitaire",
		"`envois_colis`.`qts`" => "Quantit&#233;",
		"`envois_colis`.`prix_total`" => "Net &#224; payer",
		"`envois_colis`.`beneficiaire`" => "B&#233;n&#233;ficiaire",
		"`envois_colis`.`telephone_beneficiaire`" => "T&#233;l&#233;phone b&#233;n&#233;ficiaire",
		"`envois_colis`.`nni_beneficiaire`" => "NNI b&#233;n&#233;ficiaire",
		"`envois_colis`.`date_reception`" => "Date de reception",
		"`envois_colis`.`statut`" => "Statut",
		"`envois_colis`.`observation`" => "Observation"
	);

	// Fields that can be quick searched
	$x->QueryFieldsQS = array(   
		"`envois_colis`.`idenvois_coli`" => "idenvois_coli",
		"IF(    CHAR_LENGTH(`colis1`.`link_envoi_colis`), CONCAT_WS('',   `colis1`.`link_envoi_colis`), '') /* Link colis */" => "link_colis",
		"`envois_colis`.`description`" => "description",
		"IF(    CHAR_LENGTH(`agences1`.`agence`), CONCAT_WS('',   `agences1`.`agence`), '') /* Destination */" => "destination",
		"IF(    CHAR_LENGTH(`villes1`.`ville`), CONCAT_WS('',   `villes1`.`ville`), '') /* Agence */" => "ville",
		"`envois_colis`.`prix_unitaire`" => "prix_unitaire",
		"`envois_colis`.`qts`" => "qts",
		"`envois_colis`.`prix_total`" => "prix_total",
		"`envois_colis`.`beneficiaire`" => "beneficiaire",
		"`envois_colis`.`telephone_beneficiaire`" => "telephone_beneficiaire",
		"`envois_colis`.`nni_beneficiaire`" => "nni_beneficiaire",
		"if(`envois_colis`.`date_reception`,date_format(`envois_colis`.`date_reception`,'%d/%m/%Y'),'')" => "date_reception",
		"`envois_colis`.`statut`" => "statut",
		"`envois_colis`.`observation`" => "observation"
	);

	// Lookup fields that can be used as filterers
	$x->filterers = array(  'link_colis' => 'Link colis', 'destination' => 'Destination');

	$x->QueryFrom = "`envois_colis` LEFT JOIN `colis` as colis1 ON `colis1`.`idcoli`=`envois_colis`.`link_colis` LEFT JOIN `agences` as agences1 ON `agences1`.`idagence`=`envois_colis`.`destination` LEFT JOIN `villes` as villes1 ON `villes1`.`idville`=`agences1`.`ville` ";
	$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 = 500;
	$x->QuickSearch = 1;
	$x->QuickSearchText = $Translation["quick search"];
	$x->ScriptFileName = "envois_colis_view.php";
	$x->RedirectAfterInsert = "envois_colis_view.php?SelectedID=#ID#";
	$x->TableTitle = "LISTE ENVOIS COLI";
	$x->TableIcon = "resources/table_icons/lorry.png";
	$x->PrimaryKey = "`envois_colis`.`idenvois_coli`";

	$x->ColWidth   = array(  150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150);
	$x->ColCaption = array("Description", "Destination", "Agence", "Prix unitaire", "Quantit&#233;", "Net &#224; payer", "B&#233;n&#233;ficiaire", "T&#233;l&#233;phone b&#233;n&#233;ficiaire", "NNI b&#233;n&#233;ficiaire", "Date de reception", "Statut");
	$x->ColFieldName = array('description', 'destination', 'ville', 'prix_unitaire', 'qts', 'prix_total', 'beneficiaire', 'telephone_beneficiaire', 'nni_beneficiaire', 'date_reception', 'statut');
	$x->ColNumber  = array(3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);

	// template paths below are based on the app main directory
	$x->Template = 'templates/envois_colis_templateTV.html';
	$x->SelectedTemplate = 'templates/envois_colis_templateTVS.html';
	$x->TemplateDV = 'templates/envois_colis_templateDV.html';
	$x->TemplateDVP = 'templates/envois_colis_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 `envois_colis`.`idenvois_coli`=membership_userrecords.pkValue and membership_userrecords.tableName='envois_colis' 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 `envois_colis`.`idenvois_coli`=membership_userrecords.pkValue and membership_userrecords.tableName='envois_colis' 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 = '`envois_colis`';
		$x->QueryWhere = '';
		$x->DefaultSortField = '';
	}
	// hook: envois_colis_init
	$render=TRUE;
	if(function_exists('envois_colis_init')){
		$args=array();
		$render=envois_colis_init($x, getMemberInfo(), $args);
	}

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

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