<?php
// This script and data application were generated by AppGini 5.97
// Download AppGini for free from https://bigprof.com/appgini/download/

	$currDir = dirname(__FILE__);
	include_once("{$currDir}/lib.php");
	@include_once("{$currDir}/hooks/c003_ref_colaborar.php");
	include_once("{$currDir}/c003_ref_colaborar_dml.php");

	// mm: can the current member access this page?
	$perm = getTablePermissions('c003_ref_colaborar');
	if(!$perm['access']) {
		echo error_message($Translation['tableAccessDenied']);
		exit;
	}

	$x = new DataList;
	$x->TableName = 'c003_ref_colaborar';

	// Fields that can be displayed in the table view
	$x->QueryFieldsTV = [
		"`c003_ref_colaborar`.`id`" => "id",
		"IF(    CHAR_LENGTH(`c0031`.`id`), CONCAT_WS('',   `c0031`.`id`), '') /* Id categoria */" => "id_categoria",
		"DATE_FORMAT(`c003_ref_colaborar`.`data`, '%e/%c/%Y')" => "data",
		"`c003_ref_colaborar`.`nome`" => "nome",
		"`c003_ref_colaborar`.`cpf`" => "cpf",
		"`c003_ref_colaborar`.`celular`" => "celular",
		"`c003_ref_colaborar`.`email`" => "email",
		"`c003_ref_colaborar`.`cidade`" => "cidade",
		"`c003_ref_colaborar`.`uf`" => "uf",
		"`c003_ref_colaborar`.`espaco`" => "espaco",
		"`c003_ref_colaborar`.`colaboracao`" => "colaboracao",
		"`c003_ref_colaborar`.`regiao`" => "regiao",
		"`c003_ref_colaborar`.`quantidade`" => "quantidade",
		"IF(    CHAR_LENGTH(`unidades1`.`unidade`), CONCAT_WS('',   `unidades1`.`unidade`), '') /* Unidade */" => "unidade",
		"`c003_ref_colaborar`.`valor`" => "valor",
		"`c003_ref_colaborar`.`uta`" => "uta",
		"`c003_ref_colaborar`.`obs`" => "obs",
		"`c003_ref_colaborar`.`situacao`" => "situacao",
	];
	// mapping incoming sort by requests to actual query fields
	$x->SortFields = [
		1 => '`c003_ref_colaborar`.`id`',
		2 => '`c0031`.`id`',
		3 => '`c003_ref_colaborar`.`data`',
		4 => 4,
		5 => 5,
		6 => 6,
		7 => 7,
		8 => 8,
		9 => 9,
		10 => 10,
		11 => 11,
		12 => 12,
		13 => 13,
		14 => '`unidades1`.`unidade`',
		15 => 15,
		16 => 16,
		17 => 17,
		18 => 18,
	];

	// Fields that can be displayed in the csv file
	$x->QueryFieldsCSV = [
		"`c003_ref_colaborar`.`id`" => "id",
		"IF(    CHAR_LENGTH(`c0031`.`id`), CONCAT_WS('',   `c0031`.`id`), '') /* Id categoria */" => "id_categoria",
		"DATE_FORMAT(`c003_ref_colaborar`.`data`, '%e/%c/%Y')" => "data",
		"`c003_ref_colaborar`.`nome`" => "nome",
		"`c003_ref_colaborar`.`cpf`" => "cpf",
		"`c003_ref_colaborar`.`celular`" => "celular",
		"`c003_ref_colaborar`.`email`" => "email",
		"`c003_ref_colaborar`.`cidade`" => "cidade",
		"`c003_ref_colaborar`.`uf`" => "uf",
		"`c003_ref_colaborar`.`espaco`" => "espaco",
		"`c003_ref_colaborar`.`colaboracao`" => "colaboracao",
		"`c003_ref_colaborar`.`regiao`" => "regiao",
		"`c003_ref_colaborar`.`quantidade`" => "quantidade",
		"IF(    CHAR_LENGTH(`unidades1`.`unidade`), CONCAT_WS('',   `unidades1`.`unidade`), '') /* Unidade */" => "unidade",
		"`c003_ref_colaborar`.`valor`" => "valor",
		"`c003_ref_colaborar`.`uta`" => "uta",
		"`c003_ref_colaborar`.`obs`" => "obs",
		"`c003_ref_colaborar`.`situacao`" => "situacao",
	];
	// Fields that can be filtered
	$x->QueryFieldsFilters = [
		"`c003_ref_colaborar`.`id`" => "ID",
		"IF(    CHAR_LENGTH(`c0031`.`id`), CONCAT_WS('',   `c0031`.`id`), '') /* Id categoria */" => "Id categoria",
		"`c003_ref_colaborar`.`data`" => "Data",
		"`c003_ref_colaborar`.`nome`" => "Nome Completo",
		"`c003_ref_colaborar`.`cpf`" => "CPF",
		"`c003_ref_colaborar`.`celular`" => "Celular",
		"`c003_ref_colaborar`.`email`" => "E-mail",
		"`c003_ref_colaborar`.`cidade`" => "Cidade",
		"`c003_ref_colaborar`.`uf`" => "UF",
		"`c003_ref_colaborar`.`espaco`" => "   ",
		"`c003_ref_colaborar`.`colaboracao`" => "Sua Colabora&#231;&#227;o:",
		"`c003_ref_colaborar`.`regiao`" => "Regi&#227;o/UF",
		"`c003_ref_colaborar`.`quantidade`" => "Qdade",
		"IF(    CHAR_LENGTH(`unidades1`.`unidade`), CONCAT_WS('',   `unidades1`.`unidade`), '') /* Unidade */" => "Unidade",
		"`c003_ref_colaborar`.`valor`" => "Valor",
		"`c003_ref_colaborar`.`uta`" => "UTA",
		"`c003_ref_colaborar`.`obs`" => "Observa&#231;&#227;o",
		"`c003_ref_colaborar`.`situacao`" => "Situa&#231;&#227;o",
	];

	// Fields that can be quick searched
	$x->QueryFieldsQS = [
		"`c003_ref_colaborar`.`id`" => "id",
		"IF(    CHAR_LENGTH(`c0031`.`id`), CONCAT_WS('',   `c0031`.`id`), '') /* Id categoria */" => "id_categoria",
		"DATE_FORMAT(`c003_ref_colaborar`.`data`, '%e/%c/%Y')" => "data",
		"`c003_ref_colaborar`.`nome`" => "nome",
		"`c003_ref_colaborar`.`cpf`" => "cpf",
		"`c003_ref_colaborar`.`celular`" => "celular",
		"`c003_ref_colaborar`.`email`" => "email",
		"`c003_ref_colaborar`.`cidade`" => "cidade",
		"`c003_ref_colaborar`.`uf`" => "uf",
		"`c003_ref_colaborar`.`espaco`" => "espaco",
		"`c003_ref_colaborar`.`colaboracao`" => "colaboracao",
		"`c003_ref_colaborar`.`regiao`" => "regiao",
		"`c003_ref_colaborar`.`quantidade`" => "quantidade",
		"IF(    CHAR_LENGTH(`unidades1`.`unidade`), CONCAT_WS('',   `unidades1`.`unidade`), '') /* Unidade */" => "unidade",
		"`c003_ref_colaborar`.`valor`" => "valor",
		"`c003_ref_colaborar`.`uta`" => "uta",
		"`c003_ref_colaborar`.`obs`" => "obs",
		"`c003_ref_colaborar`.`situacao`" => "situacao",
	];

	// Lookup fields that can be used as filterers
	$x->filterers = ['id_categoria' => 'Id categoria', 'unidade' => 'Unidade', ];

	$x->QueryFrom = "`c003_ref_colaborar` LEFT JOIN `c003` as c0031 ON `c0031`.`id`=`c003_ref_colaborar`.`id_categoria` LEFT JOIN `unidades` as unidades1 ON `unidades1`.`id`=`c003_ref_colaborar`.`unidade` ";
	$x->QueryWhere = '';
	$x->QueryOrder = '';

	$x->AllowSelection = 1;
	$x->HideTableView = ($perm['view'] == 0 ? 1 : 0);
	$x->AllowDelete = $perm['delete'];
	$x->AllowMassDelete = (getLoggedAdmin() !== false);
	$x->AllowInsert = $perm['insert'];
	$x->AllowUpdate = $perm['edit'];
	$x->SeparateDV = 1;
	$x->AllowDeleteOfParents = 0;
	$x->AllowFilters = 1;
	$x->AllowSavingFilters = (getLoggedAdmin() !== false);
	$x->AllowSorting = 1;
	$x->AllowNavigation = 1;
	$x->AllowPrinting = 1;
	$x->AllowPrintingDV = 1;
	$x->AllowCSV = (getLoggedAdmin() !== false);
	$x->RecordsPerPage = 5;
	$x->QuickSearch = 0;
	$x->QuickSearchText = $Translation['quick search'];
	$x->ScriptFileName = 'c003_ref_colaborar_view.php';
	$x->RedirectAfterInsert = 'c003_ref_colaborar_view.php?SelectedID=#ID#';
	$x->TableTitle = 'Quero Colaborar';
	$x->TableIcon = 'table.gif';
	$x->PrimaryKey = '`c003_ref_colaborar`.`id`';
	$x->DefaultSortField = '12';
	$x->DefaultSortDirection = 'asc';

	$x->ColWidth = [150, 150, ];
	$x->ColCaption = ['ID', 'Sua Colabora&#231;&#227;o:', ];
	$x->ColFieldName = ['id', 'colaboracao', ];
	$x->ColNumber  = [1, 11, ];

	// template paths below are based on the app main directory
	$x->Template = 'templates/c003_ref_colaborar_templateTV.html';
	$x->SelectedTemplate = 'templates/c003_ref_colaborar_templateTVS.html';
	$x->TemplateDV = 'templates/c003_ref_colaborar_templateDV.html';
	$x->TemplateDVP = 'templates/c003_ref_colaborar_templateDVP.html';

	$x->ShowTableHeader = 1;
	$x->TVClasses = "";
	$x->DVClasses = "";
	$x->HasCalculatedFields = false;
	$x->AllowConsoleLog = false;
	$x->AllowDVNavigation = true;

	// hook: c003_ref_colaborar_init
	$render = true;
	if(function_exists('c003_ref_colaborar_init')) {
		$args = [];
		$render = c003_ref_colaborar_init($x, getMemberInfo(), $args);
	}

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

	// hook: c003_ref_colaborar_header
	$headerCode = '';
	if(function_exists('c003_ref_colaborar_header')) {
		$args = [];
		$headerCode = c003_ref_colaborar_header($x->ContentType, getMemberInfo(), $args);
	}

	if(!$headerCode) {
		include_once("{$currDir}/header.php"); 
	} else {
		ob_start();
		include_once("{$currDir}/header.php");
		echo str_replace('<%%HEADER%%>', ob_get_clean(), $headerCode);
	}

	echo $x->HTML;

	// hook: c003_ref_colaborar_footer
	$footerCode = '';
	if(function_exists('c003_ref_colaborar_footer')) {
		$args = [];
		$footerCode = c003_ref_colaborar_footer($x->ContentType, getMemberInfo(), $args);
	}

	if(!$footerCode) {
		include_once("{$currDir}/footer.php"); 
	} else {
		ob_start();
		include_once("{$currDir}/footer.php");
		echo str_replace('<%%FOOTER%%>', ob_get_clean(), $footerCode);
	}
