<commit_before><?php
	require_once('../config.php');
?>
<!doctype html>
<html lang="en">
<head>
	<title>Downloads &mdash; Lotus Base</title>
	<?php
		$document_header = new \LotusBase\Component\DocumentHeader();
		$document_header->set_meta_tags(array(
			'description' => 'Downloadable resources from Lotus Base.'
			));
		echo $document_header->get_document_header();
	?>
</head>
<body class="data downloads">

	<div id="wrap">
	<?php
		$header = new \LotusBase\Component\PageHeader();
		$header->set_header_content('<h1>Downloadable Resources</h1>
		<p>You will find a list of downloadable resources we have made available to the public. Click on the file names to initiate download.</p>
		<form id="downloads-filter" class="search-form" action="#" method="get">
			<input type="search" id="filter" name="q" value="" placeholder="Filter downloads using keywords" autocomplete="off">
			<button type="submit"><span class="pictogram icon-search">Filter</span></button>
		</form>
		');
		echo $header->get_header();

		$breadcrumbs = new \LotusBase\Component\Breadcrumbs();
		$breadcrumbs->set_page_title('Downloads');
		echo $breadcrumbs->get_breadcrumbs();
	?>

	<section class="wrapper">
		<?php
			if(isset($_SESSION['download_error'])) {
				echo '<p class="user-message warning">'.$_SESSION['download_error'].'</p>';
				unset($_SESSION['download_error']);
			}

			echo '<p id="download__user-message" class="user-message warning hidden"></p>';
		?>
		<?php

			// Database connection
			try {
				$db = new PDO("mysql:host=".DB_HOST.";dbname=".DB_NAME.";port=3306;charset=utf8", DB_USER, DB_PASS);
				$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
				$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);		

				// Prepare and execute statement
				$q = $db->prepare("SELECT
						t1.FileName AS FileName,
						t1.FilePath AS FilePath,
						t1.FileExtension AS FileExtension,
						t1.Title AS Title,
						t1.Description AS Description,
						t1.Tags AS Tags,
						t1.Count AS Count,
						t1.PMID AS PMID,
						t1.FileKey AS FileKey,
						GROUP_CONCAT(t2.AuthGroup) AS AuthGroups
					FROM download AS t1
					LEFT JOIN download_auth AS t2 ON
						t1.FileKey = t2.FileKey
					GROUP BY t1.FileKey
					ORDER BY t1.Category, t1.FileName");
				$q->execute();

				// Retrieve results
				if($q->rowCount() > 0) {
					echo '<ul class="list--big" id="downloads__file-list">';
					while($row = $q->fetch(PDO::FETCH_ASSOC)) {
						$count = $row['Count'];
						$tags = explode(',', $row['Tags']);
						$fileMeta = array($row['FileName']);
						$filePath = DOC_ROOT.'/'.$row['FilePath'].$row['FileName'];
						if(file_exists($filePath)) {
							$fileMeta[] = human_filesize(filesize($filePath));
						}

						// Show file when AuthGroup is null, or when is not null, is found in the user
						$user_auth = is_logged_in();
						$user_groups = explode(',', $row['AuthGroups']);
						if ($row['AuthGroups'] !== null && !in_array($user_auth['UserGroup'], $user_groups)) {
							continue;
						}<commit_msg>Downloads can now be sorted by custom order<commit_after><?php
	require_once('../config.php');
?>
<!doctype html>
<html lang="en">
<head>
	<title>Downloads &mdash; Lotus Base</title>
	<?php
		$document_header = new \LotusBase\Component\DocumentHeader();
		$document_header->set_meta_tags(array(
			'description' => 'Downloadable resources from Lotus Base.'
			));
		echo $document_header->get_document_header();
	?>
</head>
<body class="data downloads">

	<div id="wrap">
	<?php
		$header = new \LotusBase\Component\PageHeader();
		$header->set_header_content('<h1>Downloadable Resources</h1>
		<p>You will find a list of downloadable resources we have made available to the public. Click on the file names to initiate download.</p>
		<form id="downloads-filter" class="search-form" action="#" method="get">
			<input type="search" id="filter" name="q" value="" placeholder="Filter downloads using keywords" autocomplete="off">
			<button type="submit"><span class="pictogram icon-search">Filter</span></button>
		</form>
		');
		echo $header->get_header();

		$breadcrumbs = new \LotusBase\Component\Breadcrumbs();
		$breadcrumbs->set_page_title('Downloads');
		echo $breadcrumbs->get_breadcrumbs();
	?>

	<section class="wrapper">
		<?php
			if(isset($_SESSION['download_error'])) {
				echo '<p class="user-message warning">'.$_SESSION['download_error'].'</p>';
				unset($_SESSION['download_error']);
			}

			echo '<p id="download__user-message" class="user-message warning hidden"></p>';
		?>
		<?php

			// Database connection
			try {
				$db = new PDO("mysql:host=".DB_HOST.";dbname=".DB_NAME.";port=3306;charset=utf8", DB_USER, DB_PASS);
				$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
				$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);		

				// Prepare and execute statement
				$q = $db->prepare("SELECT
						t1.FileName AS FileName,
						t1.FilePath AS FilePath,
						t1.FileExtension AS FileExtension,
						t1.Title AS Title,
						t1.Description AS Description,
						t1.Tags AS Tags,
						t1.Count AS Count,
						t1.PMID AS PMID,
						t1.FileKey AS FileKey,
						GROUP_CONCAT(t2.AuthGroup) AS AuthGroups
					FROM download AS t1
					LEFT JOIN download_auth AS t2 ON
						t1.FileKey = t2.FileKey
					GROUP BY t1.FileKey
					ORDER BY t1.SortOrder, t1.Category, t1.FileName");
				$q->execute();

				// Retrieve results
				if($q->rowCount() > 0) {
					echo '<ul class="list--big" id="downloads__file-list">';
					while($row = $q->fetch(PDO::FETCH_ASSOC)) {
						$count = $row['Count'];
						$tags = explode(',', $row['Tags']);
						$fileMeta = array($row['FileName']);
						$filePath = DOC_ROOT.'/'.$row['FilePath'].$row['FileName'];
						if(file_exists($filePath)) {
							$fileMeta[] = human_filesize(filesize($filePath));
						}

						// Show file when AuthGroup is null, or when is not null, is found in the user
						$user_auth = is_logged_in();
						$user_groups = explode(',', $row['AuthGroups']);
						if ($row['AuthGroups'] !== null && !in_array($user_auth['UserGroup'], $user_groups)) {
							continue;
						}
{'fraction_non_alphanumeric': 0.166721044045677, 'fraction_numerical': 0.00831973898858075, 'mean_word_length': 3.8428120063191153, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 33, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4988541', 'n_tokens_mistral': 2473, 'n_tokens_neox': 2019, 'n_words': 448}