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

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

	// Fields that can be displayed in the table view
	$x->QueryFieldsTV = array(
		"`oumrah`.`idoumrah`" => "idoumrah",
		"IF(    CHAR_LENGTH(`annees1`.`annee`), CONCAT_WS('',   `annees1`.`annee`), '') /* Ann&#233;e */" => "Pelerinage",
		"`oumrah`.`Prenom`" => "Prenom",
		"`oumrah`.`Nom`" => "Nom",
		"if(`oumrah`.`Datedenaissance`,date_format(`oumrah`.`Datedenaissance`,'%d/%m/%Y'),'')" => "Datedenaissance",
		"`oumrah`.`Lieudenaissance`" => "Lieudenaissance",
		"`oumrah`.`Adresse`" => "Adresse",
		"`oumrah`.`Sexe`" => "Sexe",
		"`oumrah`.`Numropasseport`" => "Numropasseport",
		"`oumrah`.`Remarque`" => "Remarque",
		"`oumrah`.`Tlphoneplerin`" => "Tlphoneplerin",
		"`oumrah`.`Tlphonefamille`" => "Tlphonefamille",
		"`oumrah`.`Personnecontacter`" => "Personnecontacter",
		"`oumrah`.`Squence`" => "Squence",
		"`oumrah`.`Profession`" => "Profession",
		"`oumrah`.`Ethnie`" => "Ethnie",
		"`oumrah`.`Region`" => "Region",
		"REPLACE(FORMAT(`oumrah`.`total_entree`, 0), ',', ' ')" => "total_entree",
		"REPLACE(FORMAT(`oumrah`.`total_sortie`, 0), ',', ' ')" => "total_sortie",
		"REPLACE(FORMAT(`oumrah`.`solde`, 0), ',', ' ')" => "solde",
		"`oumrah`.`groupe`" => "groupe",
		"`oumrah`.`agent`" => "agent",
	);
	// mapping incoming sort by requests to actual query fields
	$x->SortFields = array(
		1 => '`oumrah`.`idoumrah`',
		2 => '`annees1`.`annee`',
		3 => 3,
		4 => 4,
		5 => '`oumrah`.`Datedenaissance`',
		6 => 6,
		7 => 7,
		8 => 8,
		9 => 9,
		10 => 10,
		11 => 11,
		12 => 12,
		13 => 13,
		14 => 14,
		15 => 15,
		16 => 16,
		17 => 17,
		18 => '`oumrah`.`total_entree`',
		19 => '`oumrah`.`total_sortie`',
		20 => '`oumrah`.`solde`',
		21 => 21,
		22 => 22,
	);

	// Fields that can be displayed in the csv file
	$x->QueryFieldsCSV = array(
		"`oumrah`.`idoumrah`" => "idoumrah",
		"IF(    CHAR_LENGTH(`annees1`.`annee`), CONCAT_WS('',   `annees1`.`annee`), '') /* Ann&#233;e */" => "Pelerinage",
		"`oumrah`.`Prenom`" => "Prenom",
		"`oumrah`.`Nom`" => "Nom",
		"if(`oumrah`.`Datedenaissance`,date_format(`oumrah`.`Datedenaissance`,'%d/%m/%Y'),'')" => "Datedenaissance",
		"`oumrah`.`Lieudenaissance`" => "Lieudenaissance",
		"`oumrah`.`Adresse`" => "Adresse",
		"`oumrah`.`Sexe`" => "Sexe",
		"`oumrah`.`Numropasseport`" => "Numropasseport",
		"`oumrah`.`Remarque`" => "Remarque",
		"`oumrah`.`Tlphoneplerin`" => "Tlphoneplerin",
		"`oumrah`.`Tlphonefamille`" => "Tlphonefamille",
		"`oumrah`.`Personnecontacter`" => "Personnecontacter",
		"`oumrah`.`Squence`" => "Squence",
		"`oumrah`.`Profession`" => "Profession",
		"`oumrah`.`Ethnie`" => "Ethnie",
		"`oumrah`.`Region`" => "Region",
		"REPLACE(FORMAT(`oumrah`.`total_entree`, 0), ',', ' ')" => "total_entree",
		"REPLACE(FORMAT(`oumrah`.`total_sortie`, 0), ',', ' ')" => "total_sortie",
		"REPLACE(FORMAT(`oumrah`.`solde`, 0), ',', ' ')" => "solde",
		"`oumrah`.`groupe`" => "groupe",
		"`oumrah`.`agent`" => "agent",
	);
	// Fields that can be filtered
	$x->QueryFieldsFilters = array(
		"`oumrah`.`idoumrah`" => "ID",
		"IF(    CHAR_LENGTH(`annees1`.`annee`), CONCAT_WS('',   `annees1`.`annee`), '') /* Ann&#233;e */" => "Ann&#233;e",
		"`oumrah`.`Prenom`" => "Pr&#233;nom",
		"`oumrah`.`Nom`" => "Nom",
		"`oumrah`.`Datedenaissance`" => "Date de naissance",
		"`oumrah`.`Lieudenaissance`" => "Lieu de naissance",
		"`oumrah`.`Adresse`" => "Adresse",
		"`oumrah`.`Sexe`" => "Sexe",
		"`oumrah`.`Numropasseport`" => "Num&#233;ro passeport",
		"`oumrah`.`Remarque`" => "Remarque",
		"`oumrah`.`Tlphoneplerin`" => "T&#233;l&#233;phone p&#233;lerin",
		"`oumrah`.`Tlphonefamille`" => "T&#233;l&#233;phone famille",
		"`oumrah`.`Personnecontacter`" => "Personne &#224; contacter",
		"`oumrah`.`Squence`" => "S&#233;quence ",
		"`oumrah`.`Profession`" => "Profession",
		"`oumrah`.`Ethnie`" => "Langues",
		"`oumrah`.`Region`" => "Region",
		"`oumrah`.`total_entree`" => "A PAYER",
		"`oumrah`.`total_sortie`" => "DEJA PAY&#201;",
		"`oumrah`.`solde`" => "RESTE A PAYER",
		"`oumrah`.`groupe`" => "Groupe",
		"`oumrah`.`agent`" => "Agent",
	);

	// Fields that can be quick searched
	$x->QueryFieldsQS = array(
		"`oumrah`.`idoumrah`" => "idoumrah",
		"IF(    CHAR_LENGTH(`annees1`.`annee`), CONCAT_WS('',   `annees1`.`annee`), '') /* Ann&#233;e */" => "Pelerinage",
		"`oumrah`.`Prenom`" => "Prenom",
		"`oumrah`.`Nom`" => "Nom",
		"if(`oumrah`.`Datedenaissance`,date_format(`oumrah`.`Datedenaissance`,'%d/%m/%Y'),'')" => "Datedenaissance",
		"`oumrah`.`Lieudenaissance`" => "Lieudenaissance",
		"`oumrah`.`Adresse`" => "Adresse",
		"`oumrah`.`Sexe`" => "Sexe",
		"`oumrah`.`Numropasseport`" => "Numropasseport",
		"`oumrah`.`Remarque`" => "Remarque",
		"`oumrah`.`Tlphoneplerin`" => "Tlphoneplerin",
		"`oumrah`.`Tlphonefamille`" => "Tlphonefamille",
		"`oumrah`.`Personnecontacter`" => "Personnecontacter",
		"`oumrah`.`Squence`" => "Squence",
		"`oumrah`.`Profession`" => "Profession",
		"`oumrah`.`Ethnie`" => "Ethnie",
		"`oumrah`.`Region`" => "Region",
		"REPLACE(FORMAT(`oumrah`.`total_entree`, 0), ',', ' ')" => "total_entree",
		"REPLACE(FORMAT(`oumrah`.`total_sortie`, 0), ',', ' ')" => "total_sortie",
		"REPLACE(FORMAT(`oumrah`.`solde`, 0), ',', ' ')" => "solde",
		"`oumrah`.`groupe`" => "groupe",
		"`oumrah`.`agent`" => "agent",
	);

	// Lookup fields that can be used as filterers
	$x->filterers = array('Pelerinage' => 'Ann&#233;e', );

	$x->QueryFrom = "`oumrah` LEFT JOIN `annees` as annees1 ON `annees1`.`idannee`=`oumrah`.`Pelerinage` ";
	$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 = "oumrah_view.php";
	$x->RedirectAfterInsert = "oumrah_view.php?SelectedID=#ID#";
	$x->TableTitle = "OUMRAH";
	$x->TableIcon = "resources/table_icons/kaaba.png";
	$x->PrimaryKey = "`oumrah`.`idoumrah`";
	$x->DefaultSortField = '3';
	$x->DefaultSortDirection = 'asc';

	$x->ColWidth   = array(  150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150);
	$x->ColCaption = array("Ann&#233;e", "Pr&#233;nom", "Nom", "Date de naissance", "Lieu de naissance", "Adresse", "Sexe", "Num&#233;ro passeport", "Remarque", "T&#233;l&#233;phone p&#233;lerin", "T&#233;l&#233;phone famille", "Personne &#224; contacter", "S&#233;quence ", "Profession", "Langues", "Region", "A PAYER", "DEJA PAY&#201;", "RESTE A PAYER", "Groupe", "Agent");
	$x->ColFieldName = array('Pelerinage', 'Prenom', 'Nom', 'Datedenaissance', 'Lieudenaissance', 'Adresse', 'Sexe', 'Numropasseport', 'Remarque', 'Tlphoneplerin', 'Tlphonefamille', 'Personnecontacter', 'Squence', 'Profession', 'Ethnie', 'Region', 'total_entree', 'total_sortie', 'solde', 'groupe', 'agent');
	$x->ColNumber  = array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22);

	// template paths below are based on the app main directory
	$x->Template = 'templates/oumrah_templateTV.html';
	$x->SelectedTemplate = 'templates/oumrah_templateTVS.html';
	$x->TemplateDV = 'templates/oumrah_templateDV.html';
	$x->TemplateDVP = 'templates/oumrah_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 `oumrah`.`idoumrah`=membership_userrecords.pkValue and membership_userrecords.tableName='oumrah' 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 `oumrah`.`idoumrah`=membership_userrecords.pkValue and membership_userrecords.tableName='oumrah' 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 = '`oumrah`';
		$x->QueryWhere = '';
		$x->DefaultSortField = '';
	}
	// hook: oumrah_init
	$render=TRUE;
	if(function_exists('oumrah_init')) {
		$args=array();
		$render=oumrah_init($x, getMemberInfo(), $args);
	}

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

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