<commit_before><?php

namespace publin\install;

use PDO;
use PDOException;
use publin\config\Config;
use publin\src\Auth;
use publin\src\MailHandler;

spl_autoload_register(function ($class) {

	$path = str_replace('\\', '/', $class);
	$root = substr(__DIR__, 0, -(strlen(__NAMESPACE__)));
	$file = $root.$path.'.php';

	if (file_exists($file)) {
		/** @noinspection PhpIncludeInspection */
		require $file;
	}
});

Config::setup();

$required_php_version = '5.3.14';
$required_extensions = array('mbstring', 'fileinfo');
$upload_file_path = Config::FILE_PATH;
$required_mysql_version = '5.5.38';
$sql_host = Config::SQL_HOST;
$sql_db = Config::SQL_DATABASE;
$sql_user = Config::SQL_USER;
$admin_mail = Config::ADMIN_MAIL;
$sql_dump_file = __DIR__.'/database.sql';


function db_connect() {

	$dsn = 'mysql:host='.Config::SQL_HOST.';dbname='.Config::SQL_DATABASE.';charset=UTF8';
	$options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);

	try {
		$pdo = new PDO($dsn, Config::SQL_USER, Config::SQL_PASSWORD, $options);
		if (version_compare(phpversion(), '5.3.6', '<')) {
			$pdo->exec('SET NAMES UTF8');
		}

		return $pdo;
	}
	catch (PDOException $e) {
		return false;
	}
}

function db_import($sql_dump_file) {

	if ($pdo = db_connect()) {
		$sql = file_get_contents($sql_dump_file);
		try {
			$pdo->beginTransaction();
			$pdo->exec($sql);
			$pdo->exec("INSERT INTO `study_fields` VALUES (1,'Computer Science',NULL);");
			$pdo->exec("INSERT INTO `types` VALUES (1,'article',NULL),(2,'book',NULL),(3,'inproceedings',NULL),(4,'incollection',NULL),(5,'techreport',NULL),(6,'masterthesis',NULL),(7,'phdthesis',NULL),(8,'unpublished',NULL),(9,'misc',NULL);");
			$pdo->exec("INSERT INTO `permissions` VALUES (1,'access_hidden_files'),(2,'access_restricted_files'),(3,'author_delete'),(4,'author_edit'),(5,'keyword_delete'),(6,'keyword_edit'),(7,'manage'),(8,'publication_delete'),(9,'publication_edit'),(10,'publication_submit');");
			$pdo->exec("INSERT INTO `roles` VALUES (1,'Admin'),(2,'Editor'),(3,'Member'),(4,'Guest');");

			$pdo->exec("INSERT INTO `roles_permissions` VALUES (1,1,1),(2,1,2),(3,1,3),(4,1,4),(5,1,5),(6,1,6),(7,1,7),(8,1,8),(9,1,9),(10,1,10);");
			$pdo->commit();
			return true;
		}
		catch (PDOException $e) {
			$pdo->rollBack();
			echo '<p class="error">'.$e->getMessage().'</p>';

			return false;
		}
	}
}


if (isset($_GET['page']) && is_numeric($_GET['page'])) {
	$page = $_GET['page'];
}<commit_msg>fixed bug: "inbook" is not inserted into db when installing<commit_after><?php

namespace publin\install;

use PDO;
use PDOException;
use publin\config\Config;
use publin\src\Auth;
use publin\src\MailHandler;

spl_autoload_register(function ($class) {

	$path = str_replace('\\', '/', $class);
	$root = substr(__DIR__, 0, -(strlen(__NAMESPACE__)));
	$file = $root.$path.'.php';

	if (file_exists($file)) {
		/** @noinspection PhpIncludeInspection */
		require $file;
	}
});

Config::setup();

$required_php_version = '5.3.14';
$required_extensions = array('mbstring', 'fileinfo');
$upload_file_path = Config::FILE_PATH;
$required_mysql_version = '5.5.38';
$sql_host = Config::SQL_HOST;
$sql_db = Config::SQL_DATABASE;
$sql_user = Config::SQL_USER;
$admin_mail = Config::ADMIN_MAIL;
$sql_dump_file = __DIR__.'/database.sql';


function db_connect() {

	$dsn = 'mysql:host='.Config::SQL_HOST.';dbname='.Config::SQL_DATABASE.';charset=UTF8';
	$options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);

	try {
		$pdo = new PDO($dsn, Config::SQL_USER, Config::SQL_PASSWORD, $options);
		if (version_compare(phpversion(), '5.3.6', '<')) {
			$pdo->exec('SET NAMES UTF8');
		}

		return $pdo;
	}
	catch (PDOException $e) {
		return false;
	}
}

function db_import($sql_dump_file) {

	if ($pdo = db_connect()) {
		$sql = file_get_contents($sql_dump_file);
		try {
			$pdo->beginTransaction();
			$pdo->exec($sql);
			$pdo->exec("INSERT INTO `study_fields` VALUES (1,'Computer Science',NULL);");
			$pdo->exec("INSERT INTO `types` VALUES (1,'article',NULL),(2,'book',NULL),(3,'inproceedings',NULL),(4,'incollection',NULL),(5,'inbook',NULL),(6,'techreport',NULL),(7,'masterthesis',NULL),(8,'phdthesis',NULL),(9,'unpublished',NULL),(10,'misc',NULL);");
			$pdo->exec("INSERT INTO `permissions` VALUES (1,'access_hidden_files'),(2,'access_restricted_files'),(3,'author_delete'),(4,'author_edit'),(5,'keyword_delete'),(6,'keyword_edit'),(7,'manage'),(8,'publication_delete'),(9,'publication_edit'),(10,'publication_submit');");
			$pdo->exec("INSERT INTO `roles` VALUES (1,'Admin'),(2,'Editor'),(3,'Member'),(4,'Guest');");

			$pdo->exec("INSERT INTO `roles_permissions` VALUES (1,1,1),(2,1,2),(3,1,3),(4,1,4),(5,1,5),(6,1,6),(7,1,7),(8,1,8),(9,1,9),(10,1,10);");
			$pdo->commit();
			return true;
		}
		catch (PDOException $e) {
			$pdo->rollBack();
			echo '<p class="error">'.$e->getMessage().'</p>';

			return false;
		}
	}
}


if (isset($_GET['page']) && is_numeric($_GET['page'])) {
	$page = $_GET['page'];
}
{'fraction_non_alphanumeric': 0.23702806379971733, 'fraction_numerical': 0.029073288915808602, 'mean_word_length': 6.789308176100629, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '6566151', 'n_tokens_mistral': 2086, 'n_tokens_neox': 1907, 'n_words': 269}