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

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

	// Fields that can be displayed in the table view
	$x->QueryFieldsTV = array(
		"`oumras`.`idoumra`" => "idoumra",
		"if(`oumras`.`date`,date_format(`oumras`.`date`,'%d/%m/%Y'),'')" => "date",
		"IF(    CHAR_LENGTH(`clients1`.`nom_prenom`), CONCAT_WS('',   `clients1`.`nom_prenom`), '') /* Client */" => "client",
		"IF(    CHAR_LENGTH(`clients1`.`adresse`), CONCAT_WS('',   `clients1`.`adresse`), '') /* Adresse */" => "adresse",
		"IF(    CHAR_LENGTH(`clients1`.`passport`), CONCAT_WS('',   `clients1`.`passport`), '') /* Passeport */" => "passeport",
		"if(`oumras`.`date_depart`,date_format(`oumras`.`date_depart`,'%d/%m/%Y'),'')" => "date_depart",
		"if(`oumras`.`date_retour`,date_format(`oumras`.`date_retour`,'%d/%m/%Y'),'')" => "date_retour",
		"IF(    CHAR_LENGTH(`compagnies1`.`compagnie`), CONCAT_WS('',   `compagnies1`.`compagnie`), '') /* Compagnie */" => "compagnie",
		"`oumras`.`billet`" => "billet",
		"IF(    CHAR_LENGTH(`programmes1`.`programme`), CONCAT_WS('',   `programmes1`.`programme`), '') /* Programme */" => "programme",
		"if(`oumras`.`debut_visa`,date_format(`oumras`.`debut_visa`,'%d/%m/%Y'),'')" => "debut_visa",
		"if(`oumras`.`fin_visa`,date_format(`oumras`.`fin_visa`,'%d/%m/%Y'),'')" => "fin_visa",
		"`oumras`.`duree_visa`" => "duree_visa",
		"`oumras`.`statut`" => "statut",
		"`oumras`.`dossier`" => "dossier",
		"`oumras`.`obs`" => "obs",
	);
	// mapping incoming sort by requests to actual query fields
	$x->SortFields = array(
		1 => '`oumras`.`idoumra`',
		2 => '`oumras`.`date`',
		3 => '`clients1`.`nom_prenom`',
		4 => '`clients1`.`adresse`',
		5 => '`clients1`.`passport`',
		6 => '`oumras`.`date_depart`',
		7 => '`oumras`.`date_retour`',
		8 => '`compagnies1`.`compagnie`',
		9 => 9,
		10 => '`programmes1`.`programme`',
		11 => '`oumras`.`debut_visa`',
		12 => '`oumras`.`fin_visa`',
		13 => 13,
		14 => 14,
		15 => 15,
		16 => 16,
	);

	// Fields that can be displayed in the csv file
	$x->QueryFieldsCSV = array(
		"`oumras`.`idoumra`" => "idoumra",
		"if(`oumras`.`date`,date_format(`oumras`.`date`,'%d/%m/%Y'),'')" => "date",
		"IF(    CHAR_LENGTH(`clients1`.`nom_prenom`), CONCAT_WS('',   `clients1`.`nom_prenom`), '') /* Client */" => "client",
		"IF(    CHAR_LENGTH(`clients1`.`adresse`), CONCAT_WS('',   `clients1`.`adresse`), '') /* Adresse */" => "adresse",
		"IF(    CHAR_LENGTH(`clients1`.`passport`), CONCAT_WS('',   `clients1`.`passport`), '') /* Passeport */" => "passeport",
		"if(`oumras`.`date_depart`,date_format(`oumras`.`date_depart`,'%d/%m/%Y'),'')" => "date_depart",
		"if(`oumras`.`date_retour`,date_format(`oumras`.`date_retour`,'%d/%m/%Y'),'')" => "date_retour",
		"IF(    CHAR_LENGTH(`compagnies1`.`compagnie`), CONCAT_WS('',   `compagnies1`.`compagnie`), '') /* Compagnie */" => "compagnie",
		"`oumras`.`billet`" => "billet",
		"IF(    CHAR_LENGTH(`programmes1`.`programme`), CONCAT_WS('',   `programmes1`.`programme`), '') /* Programme */" => "programme",
		"if(`oumras`.`debut_visa`,date_format(`oumras`.`debut_visa`,'%d/%m/%Y'),'')" => "debut_visa",
		"if(`oumras`.`fin_visa`,date_format(`oumras`.`fin_visa`,'%d/%m/%Y'),'')" => "fin_visa",
		"`oumras`.`duree_visa`" => "duree_visa",
		"`oumras`.`statut`" => "statut",
		"`oumras`.`dossier`" => "dossier",
		"`oumras`.`obs`" => "obs",
	);
	// Fields that can be filtered
	$x->QueryFieldsFilters = array(
		"`oumras`.`idoumra`" => "ID",
		"`oumras`.`date`" => "Date",
		"IF(    CHAR_LENGTH(`clients1`.`nom_prenom`), CONCAT_WS('',   `clients1`.`nom_prenom`), '') /* Client */" => "Client",
		"IF(    CHAR_LENGTH(`clients1`.`adresse`), CONCAT_WS('',   `clients1`.`adresse`), '') /* Adresse */" => "Adresse",
		"IF(    CHAR_LENGTH(`clients1`.`passport`), CONCAT_WS('',   `clients1`.`passport`), '') /* Passeport */" => "Passeport",
		"`oumras`.`date_depart`" => "Date d&#233;part",
		"`oumras`.`date_retour`" => "Date retour",
		"IF(    CHAR_LENGTH(`compagnies1`.`compagnie`), CONCAT_WS('',   `compagnies1`.`compagnie`), '') /* Compagnie */" => "Compagnie",
		"`oumras`.`billet`" => "N&#176; Billet",
		"IF(    CHAR_LENGTH(`programmes1`.`programme`), CONCAT_WS('',   `programmes1`.`programme`), '') /* Programme */" => "Programme",
		"`oumras`.`debut_visa`" => "Debut visa",
		"`oumras`.`fin_visa`" => "Fin visa",
		"`oumras`.`duree_visa`" => "Dur&#233;e visa",
		"`oumras`.`statut`" => "Statut",
		"`oumras`.`dossier`" => "Dossier",
		"`oumras`.`obs`" => "Obs",
	);

	// Fields that can be quick searched
	$x->QueryFieldsQS = array(
		"`oumras`.`idoumra`" => "idoumra",
		"if(`oumras`.`date`,date_format(`oumras`.`date`,'%d/%m/%Y'),'')" => "date",
		"IF(    CHAR_LENGTH(`clients1`.`nom_prenom`), CONCAT_WS('',   `clients1`.`nom_prenom`), '') /* Client */" => "client",
		"IF(    CHAR_LENGTH(`clients1`.`adresse`), CONCAT_WS('',   `clients1`.`adresse`), '') /* Adresse */" => "adresse",
		"IF(    CHAR_LENGTH(`clients1`.`passport`), CONCAT_WS('',   `clients1`.`passport`), '') /* Passeport */" => "passeport",
		"if(`oumras`.`date_depart`,date_format(`oumras`.`date_depart`,'%d/%m/%Y'),'')" => "date_depart",
		"if(`oumras`.`date_retour`,date_format(`oumras`.`date_retour`,'%d/%m/%Y'),'')" => "date_retour",
		"IF(    CHAR_LENGTH(`compagnies1`.`compagnie`), CONCAT_WS('',   `compagnies1`.`compagnie`), '') /* Compagnie */" => "compagnie",
		"`oumras`.`billet`" => "billet",
		"IF(    CHAR_LENGTH(`programmes1`.`programme`), CONCAT_WS('',   `programmes1`.`programme`), '') /* Programme */" => "programme",
		"if(`oumras`.`debut_visa`,date_format(`oumras`.`debut_visa`,'%d/%m/%Y'),'')" => "debut_visa",
		"if(`oumras`.`fin_visa`,date_format(`oumras`.`fin_visa`,'%d/%m/%Y'),'')" => "fin_visa",
		"`oumras`.`duree_visa`" => "duree_visa",
		"`oumras`.`statut`" => "statut",
		"`oumras`.`dossier`" => "dossier",
		"`oumras`.`obs`" => "obs",
	);

	// Lookup fields that can be used as filterers
	$x->filterers = array('client' => 'Client', 'compagnie' => 'Compagnie', 'programme' => 'Programme', );

	$x->QueryFrom = "`oumras` LEFT JOIN `clients` as clients1 ON `clients1`.`matricule_client`=`oumras`.`client` LEFT JOIN `compagnies` as compagnies1 ON `compagnies1`.`idcompagnie`=`oumras`.`compagnie` LEFT JOIN `programmes` as programmes1 ON `programmes1`.`idprogramme`=`oumras`.`programme` ";
	$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 = "oumras_view.php";
	$x->RedirectAfterInsert = "oumras_view.php?SelectedID=#ID#";
	$x->TableTitle = "OUMRA";
	$x->TableIcon = "resources/table_icons/heart.png";
	$x->PrimaryKey = "`oumras`.`idoumra`";
	$x->DefaultSortField = '`oumras`.`date`';
	$x->DefaultSortDirection = 'asc';

	$x->ColWidth   = array(  150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150);
	$x->ColCaption = array("Date", "Client", "Adresse", "Passeport", "Date d&#233;part", "Date retour", "Compagnie", "N&#176; Billet", "Programme", "Debut visa", "Fin visa", "Dur&#233;e visa", "Statut");
	$x->ColFieldName = array('date', 'client', 'adresse', 'passeport', 'date_depart', 'date_retour', 'compagnie', 'billet', 'programme', 'debut_visa', 'fin_visa', 'duree_visa', 'statut');
	$x->ColNumber  = array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);

	// template paths below are based on the app main directory
	$x->Template = 'templates/oumras_templateTV.html';
	$x->SelectedTemplate = 'templates/oumras_templateTVS.html';
	$x->TemplateDV = 'templates/oumras_templateDV.html';
	$x->TemplateDVP = 'templates/oumras_templateDVP.html';

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

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

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

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