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

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

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

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

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

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

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

	$x->QueryFrom = "`c004_ref_inativas` LEFT JOIN `c004` as c0041 ON `c0041`.`id`=`c004_ref_inativas`.`id_categoria` ";
	$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 = 'c004_ref_inativas_view.php';
	$x->RedirectAfterInsert = 'c004_ref_inativas_view.php?SelectedID=#ID#';
	$x->TableTitle = 'Refer&#234;ncias Gerais';
	$x->TableIcon = 'table.gif';
	$x->PrimaryKey = '`c004_ref_inativas`.`id`';
	$x->DefaultSortField = '10';
	$x->DefaultSortDirection = 'asc';

	$x->ColWidth = [150, 150, 150, 150, 150, 150, ];
	$x->ColCaption = ['Regi&#227;o/UF', 'Qdade', 'Unidade', 'UTA', 'Valor', 'Situa&#231;&#227;o', ];
	$x->ColFieldName = ['regiao', 'quantidade', 'unidade', 'uta', 'valor', 'situacao', ];
	$x->ColNumber  = [10, 11, 12, 13, 14, 16, ];

	// template paths below are based on the app main directory
	$x->Template = 'templates/c004_ref_inativas_templateTV.html';
	$x->SelectedTemplate = 'templates/c004_ref_inativas_templateTVS.html';
	$x->TemplateDV = 'templates/c004_ref_inativas_templateDV.html';
	$x->TemplateDVP = 'templates/c004_ref_inativas_templateDVP.html';

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

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

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

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