<commit_before><?php require_once 'src/TemplateRenderer.class.php';

include('php/database.php');
$connection = connectToDB();

function getNormalSql($normalTable, $joinColumn) {
	return		"SELECT np.name heading, 
						d.id id,  
						if(RIGHT(np.name, 
								LOCATE(' ', REVERSE(np.name)) - 1)
							<>'',
							RIGHT(np.name, 
								LOCATE(' ', REVERSE(np.name)) - 1) , 
								np.name) surname,
						d.title title,
						d.summary summary
					FROM {$normalTable} np
					INNER JOIN Document d 
					ON np.id=d.{$joinColumn} 
					UNION
					SELECT 'Unclear' heading,
					d.id id,
					'zzzzz' surname,
					d.title title,
					d.summary summary
					from Document d
					where d.{$joinColumn} is null
					ORDER BY surname, heading";
	
}

function getNormalPlaceSql($joinColumn) {
	return 	   "SELECT np.name heading,
					d.id id,
					d.title title,
					d.summary summary,
					np.name order_key 
				FROM NormalizedPlace np
				INNER JOIN Document d 
				ON np.id=d.sentFromPlace
				UNION
				SELECT 'Undefined' heading,
					d.id id,
					d.title title,
					d.summary summary,
					'zzzzzzzzzz' order_key
				FROM Document d
				WHERE d.{$joinColumn} is null 
				ORDER BY order_key, title";
}


function getResult($targetBrowseBy) {
	$sqlStatements = 
		array('date' => 
				"SELECT left(creation,4) heading, id, title, summary from Document order by creation",
			'page' =>
				"SELECT concat('Page ', trim(leading '0' from right(id,4))) heading, id, title, summary from Document order by id",
			'author' =>
				getNormalSql('NormalizedPerson', 'sentFromPerson'),
			'recipient' =>
				getNormalSql('NormalizedPerson', 'sentToPerson'),
			'origin' =>
				getNormalPlaceSql('sentFromPlace'),
			'destination' =>
				getNormalPlaceSql('sentToPlace')								
			);



	$sql = $sqlStatements[$targetBrowseBy];
	logString($sql);
	return mysqli_query($GLOBALS["___mysqli_ston"], $sql);	
}

// $browseBy is sent to the template
if (array_key_exists('browseBy', $_GET)) {
  $browseBy = $_GET['browseBy'];
} else {
    $browseBy = 'date';
}

$result = getResult($browseBy);
$oldHeading = 'DEADBEEF';
// $results_list is sent to the template
$results_list = array();
while ($row = mysqli_fetch_array($result))
{
  $heading = $row['heading'];
  $id = $row['id'];
  $title = $row['title'];
  $summary = $row['summary'];

  if($heading != $oldHeading) {
    # print the header
    if($heading=='0000') {
      $cleanHeading = 'Undated';
    } else {
      $cleanHeading = $heading;
    }
  }
  $results_list[$cleanHeading][$id] = array(
    'document_title' => $title,
    'document_summary' => $summary,);

  $oldHeading=$heading;
}

// $sortCategories is sent to the template
$sortCategories = array('date', 'author',
  'recipient', 'origin', 'destination', 'page');

$template = new TemplateRenderer();
// Include any variables as an array in the second param
print $template->render('browse.html.twig', array(
  'browseBy'        => $browseBy,<commit_msg>removed 'page' from browsable groups.<commit_after><?php require_once 'src/TemplateRenderer.class.php';

include('php/database.php');
$connection = connectToDB();

function getNormalSql($normalTable, $joinColumn) {
	return		"SELECT np.name heading, 
						d.id id,  
						if(RIGHT(np.name, 
								LOCATE(' ', REVERSE(np.name)) - 1)
							<>'',
							RIGHT(np.name, 
								LOCATE(' ', REVERSE(np.name)) - 1) , 
								np.name) surname,
						d.title title,
						d.summary summary
					FROM {$normalTable} np
					INNER JOIN Document d 
					ON np.id=d.{$joinColumn} 
					UNION
					SELECT 'Unclear' heading,
					d.id id,
					'zzzzz' surname,
					d.title title,
					d.summary summary
					from Document d
					where d.{$joinColumn} is null
					ORDER BY surname, heading";
	
}

function getNormalPlaceSql($joinColumn) {
	return 	   "SELECT np.name heading,
					d.id id,
					d.title title,
					d.summary summary,
					np.name order_key 
				FROM NormalizedPlace np
				INNER JOIN Document d 
				ON np.id=d.sentFromPlace
				UNION
				SELECT 'Undefined' heading,
					d.id id,
					d.title title,
					d.summary summary,
					'zzzzzzzzzz' order_key
				FROM Document d
				WHERE d.{$joinColumn} is null 
				ORDER BY order_key, title";
}


function getResult($targetBrowseBy) {
	$sqlStatements = 
		array('date' => 
				"SELECT left(creation,4) heading, id, title, summary from Document order by creation",
			'page' =>
				"SELECT concat('Page ', trim(leading '0' from right(id,4))) heading, id, title, summary from Document order by id",
			'author' =>
				getNormalSql('NormalizedPerson', 'sentFromPerson'),
			'recipient' =>
				getNormalSql('NormalizedPerson', 'sentToPerson'),
			'origin' =>
				getNormalPlaceSql('sentFromPlace'),
			'destination' =>
				getNormalPlaceSql('sentToPlace')								
			);



	$sql = $sqlStatements[$targetBrowseBy];
	logString($sql);
	return mysqli_query($GLOBALS["___mysqli_ston"], $sql);	
}

// $browseBy is sent to the template
if (array_key_exists('browseBy', $_GET)) {
  $browseBy = $_GET['browseBy'];
} else {
    $browseBy = 'date';
}

$result = getResult($browseBy);
$oldHeading = 'DEADBEEF';
// $results_list is sent to the template
$results_list = array();
while ($row = mysqli_fetch_array($result))
{
  $heading = $row['heading'];
  $id = $row['id'];
  $title = $row['title'];
  $summary = $row['summary'];

  if($heading != $oldHeading) {
    # print the header
    if($heading=='0000') {
      $cleanHeading = 'Undated';
    } else {
      $cleanHeading = $heading;
    }
  }
  $results_list[$cleanHeading][$id] = array(
    'document_title' => $title,
    'document_summary' => $summary,);

  $oldHeading=$heading;
}

// $sortCategories is sent to the template
$sortCategories = array('date', 'author',
  'recipient', 'origin', 'destination');

$template = new TemplateRenderer();
// Include any variables as an array in the second param
print $template->render('browse.html.twig', array(
  'browseBy'        => $browseBy,
{'fraction_non_alphanumeric': 0.1463578382007385, 'fraction_numerical': 0.0030211480362537764, 'mean_word_length': 3.253390435403283, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7602696', 'n_tokens_mistral': 2455, 'n_tokens_neox': 1993, 'n_words': 482}