<?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/c001_ref_colaborar.php");
	include_once("{$currDir}/c001_ref_colaborar_dml.php");

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

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

	// Fields that can be displayed in the table view
	$x->QueryFieldsTV = [
		"`c001_ref_colaborar`.`id`" => "id",
		"IF(    CHAR_LENGTH(`c0011`.`id`), CONCAT_WS('',   `c0011`.`id`), '') /* Id categoria */" => "id_categoria",
		"DATE_FORMAT(`c001_ref_colaborar`.`data`, '%e/%c/%Y')" => "data",
		"`c001_ref_colaborar`.`nome`" => "nome",
		"`c001_ref_colaborar`.`cpf`" => "cpf",
		"`c001_ref_colaborar`.`celular`" => "celular",
		"`c001_ref_colaborar`.`email`" => "email",
		"`c001_ref_colaborar`.`cidade`" => "cidade",
		"`c001_ref_colaborar`.`uf`" => "uf",
		"`c001_ref_colaborar`.`espaco`" => "espaco",
		"`c001_ref_colaborar`.`colaboracao`" => "colaboracao",
		"`c001_ref_colaborar`.`regiao`" => "regiao",
		"`c001_ref_colaborar`.`quantidade`" => "quantidade",
		"IF(    CHAR_LENGTH(`unidades1`.`unidade`), CONCAT_WS('',   `unidades1`.`unidade`), '') /* Unidade */" => "unidade",
		"`c001_ref_colaborar`.`valor`" => "valor",
		"`c001_ref_colaborar`.`uta`" => "uta",
		"`c001_ref_colaborar`.`obs`" => "obs",
		"`c001_ref_colaborar`.`situacao`" => "situacao",
	];
	// mapping incoming sort by requests to actual query fields
	$x->SortFields = [
		1 => '`c001_ref_colaborar`.`id`',
		2 => '`c0011`.`id`',
		3 => '`c001_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 = [
		"`c001_ref_colaborar`.`id`" => "id",
		"IF(    CHAR_LENGTH(`c0011`.`id`), CONCAT_WS('',   `c0011`.`id`), '') /* Id categoria */" => "id_categoria",
		"DATE_FORMAT(`c001_ref_colaborar`.`data`, '%e/%c/%Y')" => "data",
		"`c001_ref_colaborar`.`nome`" => "nome",
		"`c001_ref_colaborar`.`cpf`" => "cpf",
		"`c001_ref_colaborar`.`celular`" => "celular",
		"`c001_ref_colaborar`.`email`" => "email",
		"`c001_ref_colaborar`.`cidade`" => "cidade",
		"`c001_ref_colaborar`.`uf`" => "uf",
		"`c001_ref_colaborar`.`espaco`" => "espaco",
		"`c001_ref_colaborar`.`colaboracao`" => "colaboracao",
		"`c001_ref_colaborar`.`regiao`" => "regiao",
		"`c001_ref_colaborar`.`quantidade`" => "quantidade",
		"IF(    CHAR_LENGTH(`unidades1`.`unidade`), CONCAT_WS('',   `unidades1`.`unidade`), '') /* Unidade */" => "unidade",
		"`c001_ref_colaborar`.`valor`" => "valor",
		"`c001_ref_colaborar`.`uta`" => "uta",
		"`c001_ref_colaborar`.`obs`" => "obs",
		"`c001_ref_colaborar`.`situacao`" => "situacao",
	];
	// Fields that can be filtered
	$x->QueryFieldsFilters = [
		"`c001_ref_colaborar`.`id`" => "ID",
		"IF(    CHAR_LENGTH(`c0011`.`id`), CONCAT_WS('',   `c0011`.`id`), '') /* Id categoria */" => "Id categoria",
		"`c001_ref_colaborar`.`data`" => "Data",
		"`c001_ref_colaborar`.`nome`" => "Nome Completo",
		"`c001_ref_colaborar`.`cpf`" => "CPF",
		"`c001_ref_colaborar`.`celular`" => "Celular",
		"`c001_ref_colaborar`.`email`" => "E-mail",
		"`c001_ref_colaborar`.`cidade`" => "Cidade",
		"`c001_ref_colaborar`.`uf`" => "UF",
		"`c001_ref_colaborar`.`espaco`" => "   ",
		"`c001_ref_colaborar`.`colaboracao`" => "Sua Colabora&#231;&#227;o:",
		"`c001_ref_colaborar`.`regiao`" => "Regi&#227;o/UF",
		"`c001_ref_colaborar`.`quantidade`" => "Qdade",
		"IF(    CHAR_LENGTH(`unidades1`.`unidade`), CONCAT_WS('',   `unidades1`.`unidade`), '') /* Unidade */" => "Unidade",
		"`c001_ref_colaborar`.`valor`" => "Valor",
		"`c001_ref_colaborar`.`uta`" => "UTA",
		"`c001_ref_colaborar`.`obs`" => "Observa&#231;&#227;o",
		"`c001_ref_colaborar`.`situacao`" => "Situa&#231;&#227;o",
	];

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

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

	$x->QueryFrom = "`c001_ref_colaborar` LEFT JOIN `c001` as c0011 ON `c0011`.`id`=`c001_ref_colaborar`.`id_categoria` LEFT JOIN `unidades` as unidades1 ON `unidades1`.`id`=`c001_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 = 'c001_ref_colaborar_view.php';
	$x->RedirectAfterInsert = 'c001_ref_colaborar_view.php?SelectedID=#ID#';
	$x->TableTitle = 'Quero Colaborar';
	$x->TableIcon = 'table.gif';
	$x->PrimaryKey = '`c001_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/c001_ref_colaborar_templateTV.html';
	$x->SelectedTemplate = 'templates/c001_ref_colaborar_templateTVS.html';
	$x->TemplateDV = 'templates/c001_ref_colaborar_templateDV.html';
	$x->TemplateDVP = 'templates/c001_ref_colaborar_templateDVP.html';

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

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

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

	// hook: c001_ref_colaborar_header
	$headerCode = '';
	if(function_exists('c001_ref_colaborar_header')) {
		$args = [];
		$headerCode = c001_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: c001_ref_colaborar_footer
	$footerCode = '';
	if(function_exists('c001_ref_colaborar_footer')) {
		$args = [];
		$footerCode = c001_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);
	}
