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

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

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

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

	// Fields that can be quick searched
	$x->QueryFieldsQS = [
		"`referencias_inativas`.`id`" => "id",
		"`referencias_inativas`.`data`" => "data",
		"IF(    CHAR_LENGTH(`c0011`.`categoria`) || CHAR_LENGTH(`c0011`.`atividade`), CONCAT_WS('',   `c0011`.`categoria`, ' / ', `c0011`.`atividade`), '') /* Categoria */" => "id_categoria",
		"`referencias_inativas`.`nome`" => "nome",
		"`referencias_inativas`.`cpf`" => "cpf",
		"`referencias_inativas`.`celular`" => "celular",
		"`referencias_inativas`.`email`" => "email",
		"`referencias_inativas`.`cidade`" => "cidade",
		"`referencias_inativas`.`uf`" => "uf",
		"`referencias_inativas`.`regiao`" => "regiao",
		"`referencias_inativas`.`quantidade`" => "quantidade",
		"`referencias_inativas`.`unidade`" => "unidade",
		"`referencias_inativas`.`uta`" => "uta",
		"`referencias_inativas`.`valor`" => "valor",
		"`referencias_inativas`.`obs`" => "obs",
		"`referencias_inativas`.`situacao`" => "situacao",
	];

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

	$x->QueryFrom = "`referencias_inativas` LEFT JOIN `c001` as c0011 ON `c0011`.`id`=`referencias_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 = 1;
	$x->QuickSearchText = $Translation['quick search'];
	$x->ScriptFileName = 'referencias_inativas_view.php';
	$x->RedirectAfterInsert = 'referencias_inativas_view.php?SelectedID=#ID#';
	$x->TableTitle = 'Refer&#234;ncias (Inativas)';
	$x->TableIcon = 'resources/table_icons/note_delete.png';
	$x->PrimaryKey = '`referencias_inativas`.`id`';
	$x->DefaultSortField = '10';
	$x->DefaultSortDirection = 'asc';

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

	// template paths below are based on the app main directory
	$x->Template = 'templates/referencias_inativas_templateTV.html';
	$x->SelectedTemplate = 'templates/referencias_inativas_templateTVS.html';
	$x->TemplateDV = 'templates/referencias_inativas_templateDV.html';
	$x->TemplateDVP = 'templates/referencias_inativas_templateDVP.html';

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

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

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

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