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

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

	// Fields that can be displayed in the table view
	$x->QueryFieldsTV = array(
		"`reunions`.`idreunion`" => "idreunion",
		"`reunions`.`link_in`" => "link_in",
		"IF(    CHAR_LENGTH(`entete1`.`nom`), CONCAT_WS('',   `entete1`.`nom`), '') /* Ent&#234;te */" => "avec_entete",
		"`reunions`.`ordre_jour`" => "ordre_jour",
		"if(`reunions`.`date`,date_format(`reunions`.`date`,'%d/%m/%Y'),'')" => "date",
		"`reunions`.`temps`" => "temps",
		"`reunions`.`duree`" => "duree",
		"`reunions`.`lieu`" => "lieu",
		"`reunions`.`objectif`" => "objectif",
		"`reunions`.`fpdf`" => "fpdf",
		"`reunions`.`fzip`" => "fzip",
		"IF(    CHAR_LENGTH(`entete1`.`raison_sociale`), CONCAT_WS('',   `entete1`.`raison_sociale`), '') /* Rs */" => "rs",
		"IF(    CHAR_LENGTH(`entete1`.`devise`), CONCAT_WS('',   `entete1`.`devise`), '') /* Devise */" => "devise",
		"IF(    CHAR_LENGTH(`entete1`.`logo`), CONCAT_WS('',   `entete1`.`logo`), '') /* Logo */" => "logo",
		"IF(    CHAR_LENGTH(`entete1`.`description`), CONCAT_WS('',   `entete1`.`description`), '') /* Description */" => "description",
		"IF(    CHAR_LENGTH(`entete1`.`adresse`), CONCAT_WS('',   `entete1`.`adresse`), '') /* Adresse */" => "adresse",
		"IF(    CHAR_LENGTH(`entete1`.`telephone`), CONCAT_WS('',   `entete1`.`telephone`), '') /* T&#233;l&#233;phone */" => "telephone",
		"IF(    CHAR_LENGTH(`entete1`.`whatsapp`), CONCAT_WS('',   `entete1`.`whatsapp`), '') /* Whatsapp */" => "whatsapp",
		"IF(    CHAR_LENGTH(`entete1`.`email`), CONCAT_WS('',   `entete1`.`email`), '') /* Email */" => "email",
		"IF(    CHAR_LENGTH(`entete1`.`site_web`), CONCAT_WS('',   `entete1`.`site_web`), '') /* Site web */" => "site_web",
		"IF(    CHAR_LENGTH(`entete1`.`bp`), CONCAT_WS('',   `entete1`.`bp`), '') /* Bp */" => "bp",
		"IF(    CHAR_LENGTH(`entete1`.`footer_3`), CONCAT_WS('',   `entete1`.`footer_3`), '') /* Pied de page ligne 1 */" => "footer_3",
		"IF(    CHAR_LENGTH(`entete1`.`notice`), CONCAT_WS('',   `entete1`.`notice`), '') /* Notification de la date */" => "notice",
		"IF(    CHAR_LENGTH(`entete1`.`signataire`), CONCAT_WS('',   `entete1`.`signataire`), '') /* Signataire */" => "signataire",
		"`reunions`.`groupe`" => "groupe",
		"`reunions`.`agent`" => "agent",
	);
	// mapping incoming sort by requests to actual query fields
	$x->SortFields = array(
		1 => '`reunions`.`idreunion`',
		2 => 2,
		3 => '`entete1`.`nom`',
		4 => 4,
		5 => '`reunions`.`date`',
		6 => 6,
		7 => 7,
		8 => 8,
		9 => 9,
		10 => 10,
		11 => 11,
		12 => '`entete1`.`raison_sociale`',
		13 => '`entete1`.`devise`',
		14 => '`entete1`.`logo`',
		15 => '`entete1`.`description`',
		16 => '`entete1`.`adresse`',
		17 => '`entete1`.`telephone`',
		18 => '`entete1`.`whatsapp`',
		19 => '`entete1`.`email`',
		20 => '`entete1`.`site_web`',
		21 => '`entete1`.`bp`',
		22 => '`entete1`.`footer_3`',
		23 => '`entete1`.`notice`',
		24 => '`entete1`.`signataire`',
		25 => 25,
		26 => 26,
	);

	// Fields that can be displayed in the csv file
	$x->QueryFieldsCSV = array(
		"`reunions`.`idreunion`" => "idreunion",
		"`reunions`.`link_in`" => "link_in",
		"IF(    CHAR_LENGTH(`entete1`.`nom`), CONCAT_WS('',   `entete1`.`nom`), '') /* Ent&#234;te */" => "avec_entete",
		"`reunions`.`ordre_jour`" => "ordre_jour",
		"if(`reunions`.`date`,date_format(`reunions`.`date`,'%d/%m/%Y'),'')" => "date",
		"`reunions`.`temps`" => "temps",
		"`reunions`.`duree`" => "duree",
		"`reunions`.`lieu`" => "lieu",
		"`reunions`.`objectif`" => "objectif",
		"`reunions`.`fpdf`" => "fpdf",
		"`reunions`.`fzip`" => "fzip",
		"IF(    CHAR_LENGTH(`entete1`.`raison_sociale`), CONCAT_WS('',   `entete1`.`raison_sociale`), '') /* Rs */" => "rs",
		"IF(    CHAR_LENGTH(`entete1`.`devise`), CONCAT_WS('',   `entete1`.`devise`), '') /* Devise */" => "devise",
		"IF(    CHAR_LENGTH(`entete1`.`logo`), CONCAT_WS('',   `entete1`.`logo`), '') /* Logo */" => "logo",
		"IF(    CHAR_LENGTH(`entete1`.`description`), CONCAT_WS('',   `entete1`.`description`), '') /* Description */" => "description",
		"IF(    CHAR_LENGTH(`entete1`.`adresse`), CONCAT_WS('',   `entete1`.`adresse`), '') /* Adresse */" => "adresse",
		"IF(    CHAR_LENGTH(`entete1`.`telephone`), CONCAT_WS('',   `entete1`.`telephone`), '') /* T&#233;l&#233;phone */" => "telephone",
		"IF(    CHAR_LENGTH(`entete1`.`whatsapp`), CONCAT_WS('',   `entete1`.`whatsapp`), '') /* Whatsapp */" => "whatsapp",
		"IF(    CHAR_LENGTH(`entete1`.`email`), CONCAT_WS('',   `entete1`.`email`), '') /* Email */" => "email",
		"IF(    CHAR_LENGTH(`entete1`.`site_web`), CONCAT_WS('',   `entete1`.`site_web`), '') /* Site web */" => "site_web",
		"IF(    CHAR_LENGTH(`entete1`.`bp`), CONCAT_WS('',   `entete1`.`bp`), '') /* Bp */" => "bp",
		"IF(    CHAR_LENGTH(`entete1`.`footer_3`), CONCAT_WS('',   `entete1`.`footer_3`), '') /* Pied de page ligne 1 */" => "footer_3",
		"IF(    CHAR_LENGTH(`entete1`.`notice`), CONCAT_WS('',   `entete1`.`notice`), '') /* Notification de la date */" => "notice",
		"IF(    CHAR_LENGTH(`entete1`.`signataire`), CONCAT_WS('',   `entete1`.`signataire`), '') /* Signataire */" => "signataire",
		"`reunions`.`groupe`" => "groupe",
		"`reunions`.`agent`" => "agent",
	);
	// Fields that can be filtered
	$x->QueryFieldsFilters = array(
		"`reunions`.`idreunion`" => "N&#176;",
		"`reunions`.`link_in`" => "Link in",
		"IF(    CHAR_LENGTH(`entete1`.`nom`), CONCAT_WS('',   `entete1`.`nom`), '') /* Ent&#234;te */" => "Ent&#234;te",
		"`reunions`.`ordre_jour`" => "Ordre du jour",
		"`reunions`.`date`" => "Date",
		"`reunions`.`temps`" => "Temps",
		"`reunions`.`duree`" => "Duree",
		"`reunions`.`lieu`" => "Lieu",
		"`reunions`.`objectif`" => "Objectif",
		"`reunions`.`fpdf`" => "PDF",
		"`reunions`.`fzip`" => "ZIP",
		"IF(    CHAR_LENGTH(`entete1`.`raison_sociale`), CONCAT_WS('',   `entete1`.`raison_sociale`), '') /* Rs */" => "Rs",
		"IF(    CHAR_LENGTH(`entete1`.`devise`), CONCAT_WS('',   `entete1`.`devise`), '') /* Devise */" => "Devise",
		"IF(    CHAR_LENGTH(`entete1`.`logo`), CONCAT_WS('',   `entete1`.`logo`), '') /* Logo */" => "Logo",
		"IF(    CHAR_LENGTH(`entete1`.`description`), CONCAT_WS('',   `entete1`.`description`), '') /* Description */" => "Description",
		"IF(    CHAR_LENGTH(`entete1`.`adresse`), CONCAT_WS('',   `entete1`.`adresse`), '') /* Adresse */" => "Adresse",
		"IF(    CHAR_LENGTH(`entete1`.`telephone`), CONCAT_WS('',   `entete1`.`telephone`), '') /* T&#233;l&#233;phone */" => "T&#233;l&#233;phone",
		"IF(    CHAR_LENGTH(`entete1`.`whatsapp`), CONCAT_WS('',   `entete1`.`whatsapp`), '') /* Whatsapp */" => "Whatsapp",
		"IF(    CHAR_LENGTH(`entete1`.`email`), CONCAT_WS('',   `entete1`.`email`), '') /* Email */" => "Email",
		"IF(    CHAR_LENGTH(`entete1`.`site_web`), CONCAT_WS('',   `entete1`.`site_web`), '') /* Site web */" => "Site web",
		"IF(    CHAR_LENGTH(`entete1`.`bp`), CONCAT_WS('',   `entete1`.`bp`), '') /* Bp */" => "Bp",
		"IF(    CHAR_LENGTH(`entete1`.`footer_3`), CONCAT_WS('',   `entete1`.`footer_3`), '') /* Pied de page ligne 1 */" => "Pied de page ligne 1",
		"IF(    CHAR_LENGTH(`entete1`.`notice`), CONCAT_WS('',   `entete1`.`notice`), '') /* Notification de la date */" => "Notification de la date",
		"IF(    CHAR_LENGTH(`entete1`.`signataire`), CONCAT_WS('',   `entete1`.`signataire`), '') /* Signataire */" => "Signataire",
		"`reunions`.`groupe`" => "Groupe",
		"`reunions`.`agent`" => "Agent",
	);

	// Fields that can be quick searched
	$x->QueryFieldsQS = array(
		"`reunions`.`idreunion`" => "idreunion",
		"`reunions`.`link_in`" => "link_in",
		"IF(    CHAR_LENGTH(`entete1`.`nom`), CONCAT_WS('',   `entete1`.`nom`), '') /* Ent&#234;te */" => "avec_entete",
		"`reunions`.`ordre_jour`" => "ordre_jour",
		"if(`reunions`.`date`,date_format(`reunions`.`date`,'%d/%m/%Y'),'')" => "date",
		"`reunions`.`temps`" => "temps",
		"`reunions`.`duree`" => "duree",
		"`reunions`.`lieu`" => "lieu",
		"`reunions`.`objectif`" => "objectif",
		"`reunions`.`fpdf`" => "fpdf",
		"`reunions`.`fzip`" => "fzip",
		"IF(    CHAR_LENGTH(`entete1`.`raison_sociale`), CONCAT_WS('',   `entete1`.`raison_sociale`), '') /* Rs */" => "rs",
		"IF(    CHAR_LENGTH(`entete1`.`devise`), CONCAT_WS('',   `entete1`.`devise`), '') /* Devise */" => "devise",
		"IF(    CHAR_LENGTH(`entete1`.`logo`), CONCAT_WS('',   `entete1`.`logo`), '') /* Logo */" => "logo",
		"IF(    CHAR_LENGTH(`entete1`.`description`), CONCAT_WS('',   `entete1`.`description`), '') /* Description */" => "description",
		"IF(    CHAR_LENGTH(`entete1`.`adresse`), CONCAT_WS('',   `entete1`.`adresse`), '') /* Adresse */" => "adresse",
		"IF(    CHAR_LENGTH(`entete1`.`telephone`), CONCAT_WS('',   `entete1`.`telephone`), '') /* T&#233;l&#233;phone */" => "telephone",
		"IF(    CHAR_LENGTH(`entete1`.`whatsapp`), CONCAT_WS('',   `entete1`.`whatsapp`), '') /* Whatsapp */" => "whatsapp",
		"IF(    CHAR_LENGTH(`entete1`.`email`), CONCAT_WS('',   `entete1`.`email`), '') /* Email */" => "email",
		"IF(    CHAR_LENGTH(`entete1`.`site_web`), CONCAT_WS('',   `entete1`.`site_web`), '') /* Site web */" => "site_web",
		"IF(    CHAR_LENGTH(`entete1`.`bp`), CONCAT_WS('',   `entete1`.`bp`), '') /* Bp */" => "bp",
		"IF(    CHAR_LENGTH(`entete1`.`footer_3`), CONCAT_WS('',   `entete1`.`footer_3`), '') /* Pied de page ligne 1 */" => "footer_3",
		"IF(    CHAR_LENGTH(`entete1`.`notice`), CONCAT_WS('',   `entete1`.`notice`), '') /* Notification de la date */" => "notice",
		"IF(    CHAR_LENGTH(`entete1`.`signataire`), CONCAT_WS('',   `entete1`.`signataire`), '') /* Signataire */" => "signataire",
		"`reunions`.`groupe`" => "groupe",
		"`reunions`.`agent`" => "agent",
	);

	// Lookup fields that can be used as filterers
	$x->filterers = array('avec_entete' => 'Ent&#234;te', );

	$x->QueryFrom = "`reunions` LEFT JOIN `entete` as entete1 ON `entete1`.`identete`=`reunions`.`avec_entete` ";
	$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 = "reunions_view.php";
	$x->RedirectAfterInsert = "reunions_view.php?SelectedID=#ID#";
	$x->TableTitle = "GESTION DES REUNIONS";
	$x->TableIcon = "resources/table_icons/calendar_view_day.png";
	$x->PrimaryKey = "`reunions`.`idreunion`";
	$x->DefaultSortField = '`reunions`.`date`';
	$x->DefaultSortDirection = 'desc';

	$x->ColWidth   = array(  150, 150, 150, 150, 150, 150, 150);
	$x->ColCaption = array("Ordre du jour", "Date", "Temps", "Duree", "Lieu", "Groupe", "Agent");
	$x->ColFieldName = array('ordre_jour', 'date', 'temps', 'duree', 'lieu', 'groupe', 'agent');
	$x->ColNumber  = array(4, 5, 6, 7, 8, 25, 26);

	// template paths below are based on the app main directory
	$x->Template = 'templates/reunions_templateTV.html';
	$x->SelectedTemplate = 'templates/reunions_templateTVS.html';
	$x->TemplateDV = 'templates/reunions_templateDV.html';
	$x->TemplateDVP = 'templates/reunions_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 `reunions`.`idreunion`=membership_userrecords.pkValue and membership_userrecords.tableName='reunions' 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 `reunions`.`idreunion`=membership_userrecords.pkValue and membership_userrecords.tableName='reunions' 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 = '`reunions`';
		$x->QueryWhere = '';
		$x->DefaultSortField = '';
	}
	// hook: reunions_init
	$render=TRUE;
	if(function_exists('reunions_init')) {
		$args=array();
		$render=reunions_init($x, getMemberInfo(), $args);
	}

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

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