View file publs_v1_0/read.php

File size: 9.12Kb
<?php
if (defined('BASEDIR')) {
	exit (header('Location: /index.php'));
}

$headmod = 'pub';
$textl = 'Публикации';
$start = isset($_GET['start']) ?  abs(intval($_GET['start'])) : 0; 

require_once ('../includes/start.php');
require_once ('../includes/functions.php');
require_once ('../includes/header.php');
include_once ('../themes/header.php');

require_once ("./inc/conf.php");

// Ограничиваем доступ к Библиотеке
/*
if	(!$set['mod_lib'] && $rights < 7) {
	$error = 'Публикации закрыты';
}	else if ($set['mod_lib'] == 1 && !$user_id) {
	$error = 'Доступ в публикации открыт только <a href="../in.php">авторизованным</a> посетителям';
}
*/
if ($error) {
	require_once ("../incfiles/head.php");
	echo '<div class="rmenu"><p>' . $error . '</p></div>';
	include_once ('../themes/footer.php');
	exit;
}


include_once ("panel.dat");


$sql = DB::run() -> query("select * from `pub_arts` where `id` = ? LIMIT 1;", array($id));
if (empty($sql)) {
	echo 'Файла не существует<br />';
}	else {
	$res = $sql -> fetch();
	if	(empty($_SESSION['lib'])) {
		$_SESSION['lib'] = NULL;
	}
	if	($_SESSION['lib'] !== $id) {
		$_SESSION['lib'] = $id;
		$libcount = intval($res['count']) + 1;
		//mysql_query("update `pub_arts` set  `count`='".$libcount."' where id='".$id."';");
		DB::run() -> query("update `pub_arts` set  `count`='".$libcount."' where id=?;", array($id));
		
	}
	
	$as = DB::run() -> queryFetch("select `id`, `name` from `pub_arts` where `id` = ? LIMIT 1;", array($res['fid']));
	echo '<ol class="breadcrumb">';
	echo '<li><a href="/index.php?"> <i class="fa fa-home fa-lg text-muted"></i> </a></li>';
	echo '<li class=""><a href="index.php?">Публикации</a></li>';
	echo '<li class="active"><a href="index.php?id='.$as['id'].'"><strong>'.$as['name'].'</strong></a></li>';
	echo '</ol> ';

	#	Заголовок статьи
	echo '<p><h1><b>'.htmlentities($res['name'], ENT_QUOTES, 'UTF-8').'</b></h1></p>';
	
	$tx = $res['text'];

	#	для постраничного вывода используется модифицированный код от hintoz #
	$strrpos = mb_strrpos($tx, " ");
	$pages = 1;
	#	Вычисляем номер страницы
	if	(isset ($_GET['page'])) {
		$page = abs(intval($_GET['page']));
		if	($page == 0) {
			$page = 1;
		}
		$start = $page - 1;
	}	else {
		$page = $start + 1;
	}

	$t_si = 0;
	if	($strrpos) {
		while ($t_si < $strrpos) {
			$string = mb_substr($tx, $t_si, $simvol);
			$t_ki = mb_strrpos($string, " ");
			$m_sim = $t_ki;
			$strings[$pages] = $string;
			$t_si = $t_ki + $t_si;
			if	($page == $pages) {
				$page_text = $strings[$pages];
			}
			if	($strings[$pages] == "") {
				$t_si = $strrpos++;
			}	else {
				$pages++;
			}
		}

		if	($page >= $pages) {
			$page = $pages - 1;
			$page_text = $strings[$page];
		}
		$pages = $pages - 1;
		if	($page != $pages) {
			$prb = mb_strrpos($page_text, " ");
			$page_text = mb_substr($page_text, 0, $prb);
		}
	}	else {
		$page_text = $tx;
	}

	$page_text = htmlentities($page_text, ENT_QUOTES, 'UTF-8');
	$page_text = bb_code($page_text);
	echo '<p class="list2">'.($page_text).'</p>';

	$c = DB::run() -> querySingle("select COUNT(*) from `pub_file` where `fid` = '".$id."';");
			if ($c > 0) {
				$sql1 = DB::run() -> query("SELECT * FROM `pub_file` WHERE `fid` = '".$id."'");
				echo '<br />';
				echo '</small>Прикрепленные файлы: <br />';
				while ($res = $sql1 -> fetch()) {
					echo '<i class="fa fa-download"></i> <a href="file.php?act=look&amp;id='.$res['id'].'">
					'.htmlentities($res['name']).'.'.$res['format'].'</a> ('.formatsize($res['size']).') / ('.$res['last_load'].'), <br /> ';
				}
				echo '</small>';
			}
	
	
	
	echo '<hr /><p>';
	echo '<nav aria-label="Page navigation example">
  <ul class="pagination justify-content-center">';
	$next = $page + 1;
	$prev = $page - 1;
	if	($pages > 1) {
		//echo 'Страницы: <br />';
		if	($page > 1) {
			echo '<li class="page-item"><a href="read.php?id='.$id.'&amp;page='.$prev.'">&lt;&lt;</a></li>';
			echo '<li class="page-item"><a href="read.php?id='.$id.'&amp;page=1">1</a></li>';
		}

		if	($prev > 2) {
			echo '<li class="page-item disabled"><a class="page-link"  tabindex="-1" aria-disabled="true">..</a></li>';
		}
		$page2 = $pages - $page;
		$pa = ceil($page / 2);
		$paa = ceil($page / 3);
		$pa2 = $page + floor($page2 / 2);
		$paa2 = $page + floor($page2 / 3);
		$paa3 = $page + (floor($page2 / 3) * 2);
		/*if	($page > 13) {
			echo 
				'<li class="page-item"><a class="page-link" href="read.php?id='.$id.'&amp;page='.$paa.'">'.$paa.'</a></li>' .
				'<li class="page-item"><a class="page-link" href="read.php?id='.$id.'&amp;page='.($paa + 1).'">'.($paa + 1).'</a></li>' .
				'<li class="page-item disabled"><a class="page-link" href="#" tabindex="-1" aria-disabled="true">..</a></li>' .
				'<li class="page-item"><a class="page-link" href="read.php?id='.$id.'&amp;page='.($paa * 2).'">'.($paa * 2).'</a></li>' .
				'<li class="page-item"><a class="page-link" href="read.php?id='.$id.'&amp;page='.($paa * 2 + 1).'">'.($paa * 2 + 1).'</a></li>' .
				'<li class="page-item disabled"><a class="page-link" href="#" tabindex="-1" aria-disabled="true">..</a></li>'
			;
		}	else if ($page > 7) {
			echo 
				'<li class="page-item"><a class="page-link" href="read.php?id='.$id.'&amp;page='.$pa.'">'.$pa.'</a></li>' .
				'<li class="page-item"><a class="page-link" href="read.php?id='.$id.'&amp;page='.($pa + 1).'">'.($pa + 1).'</a></li>' .
				'<li class="page-item disabled"><a class="page-link" href="#" tabindex="-1" aria-disabled="true">..</a></li>'
			;
		}*/
		if	($prev > 1) {
			echo '<li class="page-item"><a class="page-link" href="read.php?id='.$id.'&amp;page='.$prev.'">'.$prev.'</a></li>';
		}
		echo '<li class="page-item disabled "><a class="page-link bg bg-warning text-dark" tabindex="-1" aria-disabled="true"><b>'.$page.'</b></a></li>';
		if	($next < $pages) {
			echo '<li class="page-item"><a class="page-link" href="read.php?id='.$id.'&amp;page='.$next.'">'.$next.'</a></li>';
		}
		/*if	($page2 > 12) {
			echo 
				'<li class="page-item disabled"><a class="page-link" href="#" tabindex="-1" aria-disabled="true">..</a></li>' .
				'<li class="page-item"><a class="page-link" href="read.php?id='.$id.'&amp;page='.$paa2.'">'.$paa2.'</a></li>' .
				'<li class="page-item"><a class="page-link" href="read.php?id='.$id.'&amp;page='.($paa2 + 1).'">'.($paa2 + 1).'</a></li>' .
				'<li class="page-item disabled"><a class="page-link" href="#" tabindex="-1" aria-disabled="true">..</a></li>' .
				'<li class="page-item"><a class="page-link" href="read.php?id='.$id.'&amp;page='.($paa3).'">'.($paa3).'</a></li>' .
				'<li class="page-item"><a class="page-link" href="read.php?id='.$id.'&amp;page='.($paa3 + 1).'">'.($paa3 + 1).'</a></li>'
			;
		}	else if ($page2 > 6) {
			echo 
				'<li class="page-item disabled"><a class="page-link" href="#" tabindex="-1" aria-disabled="true">..</a></li>' .
				'<li class="page-item"><a class="page-link" href="read.php?id='.$id.'&amp;page='.$pa2.'">'.$pa2.'</a> </li>' .
				'<li class="page-item"><a class="page-link" href="read.php?id='.$id.'&amp;page='.($pa2 + 1).'">'.($pa2 + 1).'</a> </li>'
			;
		}*/
		if	($next < ($pages - 1)) {
			echo '<li class="page-item disabled"><a class="page-link" href="#" tabindex="-1" aria-disabled="true">..</a></li>';
		}
		if	($page < $pages) {
			echo '<li class="page-item"><a class="page-link" href="read.php?id='.$id.'&amp;page='.$pages.'">'.$pages.'</a> </li>';
		}
		if	($page < $pages) {
			echo '<li class="page-item"><a class="page-link" href="read.php?id='.$id.'&amp;page='.$next.'">&gt;&gt;</a> </li>';
		} else {
			echo '<li class="page-item disabled"><a class="page-link" href="read.php?id='.$id.'&amp;page='.$next.'">&gt;&gt;</a> </li>';
		}
		echo '</ul><ul class="pagination justify-content-center mt-0 mb-0">'. 
			'<form action="read.php" method="get">' .
			'<input type="hidden" name="id" value="'.$id.'"/>' .
			'<input type="text" name="page" value="'.$page.'" size="2">' .
			'<input type="submit" value=" >>"></form>';
	}
	echo '</ul></nav>';

	echo '<hr/>';
	if ($dos_load) {
		echo '<i class="fa fa-download"></i> <a href="load.php?id='.$id.'">Скачать</a><br/>';
	}
	echo '<a href="komm.php?id='.$id.'">Коменатрии</a>('.count_komm($id).') <br />';
	if	(empty($_SESSION['rat'])) {
		$_SESSION['rat'] = NULL;
	}
	if	($_SESSION['rat'] !== $id) {
		echo 'Оценить: <br/> <form method="post" action="file.php?act=rat&amp;id='.$id.'">';
		echo '<select name="rat">';
		echo '<option value="10">Отлично</option>';
		echo '<option value="8">Хорошо</option>';
		echo '<option value="6">Нормально</option>';
		echo '<option value="4">Плохо</option>';
		echo '<option value="2">Отстой</option>';
		echo '</select><input type="submit" value="Ok!"/></form><br/>';
	}
	echo '<a href="index.php?id='.$as['id'].'">Назад</a><br/>';
}


include_once ('../themes/footer.php');
?>