<?
  ##########################################
## Автор: -=ШАХТЕР=-                        #                                                                                                                                                                                      ## Сайт: http://masteram.us                 #                 															                      ## ICQ  :  46-92-90                         #                 														 		           ## Версия 4.0 Лицензионная                  #
## Данная версия скрипта является ПЛАТНОЙ,  #
## вы НЕ ИМЕЕТЕ ПРАВА распрострянять данный #
##  скрипт или какие-либо части его кода... #
  #########################################
require'../config.php';
$align='left';
$title='Обменник';
aut();
head();
who_add(0,'enter');

require 'kodirovka.php';


// Проверка переменных
$file = check(intval($_GET['file']));
//$file2 = intval($_GET['id2']);
$page = check(intval($_GET['page']));
// Получаем инфу о файле
$d = mysql_fetch_assoc($db->sql_query('SELECT * FROM `fo_files` WHERE `id` = '.$file));
if(!is_file($d['path'])){
die('Файл не существует');
}


$cat2 = @$db->sql_fetchrow($db->sql_query("select * from  `fo_cat2` where path = '".$d['infolder']."'" ));
$cat = @$db->sql_fetchrow($db->sql_query("select * from  `fo_cat` where id = '".$cat2['fid']."'" ));
echo menu.'<a href="/fo">Oбменник</a>|<a href="/fo/'.$cat['id'].'">'.$cat['name'].'</a>|<a href="/fo/'.$cat['id'].'/'.$cat2['id'].'">'.$cat2['name'].'</a>'.div;

if(isset($_GET['pass'])) $pass = $_GET['pass'];
else if(isset($_POST['pass'])) $pass = $_POST['pass'];

if(empty($d['pass'])||$pass==$d['pass']||$pass==$d['pass']){

if(session_start()){
if(!empty($_SESSION["font"]) AND !empty($_POST['font'])){
$_SESSION["font"]=$_POST['font'];
}
elseif(empty($_SESSION["font"]) AND !empty($_POST['font']))
{
 $font=$_POST['font'];
 session_register ("font") ;
}


if(!empty($_SESSION["number"]) AND !empty($_POST['number']))
$_SESSION["number"]=$_POST['number'];
elseif(empty($_SESSION["number"]) AND !empty($_POST['number']))
{
 $number=$_POST['number'];
 session_register ("number") ;
}
 }
 if(!$_SESSION["number"]) $_SESSION["number"]=2000;
 if(! $_SESSION["font"])  $_SESSION["font"]=2;
$font= intval($_SESSION["font"]);
$number= intval($_SESSION["number"]);
###################################################
$text=file_get_contents($d['path']);
$nf = pathinfo($d['path']);
$filename = $nf['basename'];



function highlight_code($code)

{

  $code = stripslashes($code);
  $code = trim($code);
  return highlight_string($code,true);

}
///echo $text;
//$text=str_replace('<','&lt;',$text);
//$text=str_replace('>','&gt',$text);
//$text=str_replace("\n",'<br />',$text);
  $simvol = $number; // Число символов на страницу по умолчанию
                $tx =$text;
                if (!empty($_GET['page']))
                {
                    $page = intval($_GET['page']);
                } else
                {
                    $page = 1;
                }

                # для постраничного вывода используется модифицированный код от hintoz #
               // $strrpos = mb_strrpos($tx, " ");
                $pages = 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=highlight_code($page_text);
                 $page_text=charset_x_win($page_text);
                 $page_text=iconv("windows-1251", "UTF-8", "$page_text");
                // Текст статьи
              /*  $page_text = htmlentities($page_text, ENT_QUOTES, 'UTF-8');
                $page_text = str_replace("\n",'<br />', $page_text); */
                echo '<font size="'.intval($font).'">'.$page_text.'</font>';
                echo '<hr />';
                $next = $page + 1;
                $prev = $page - 1;
                if ($pages > 1)
                {

                    if ($page > 1)
                    {
                        print " <a href=\"?page=$prev\">&lt;&lt;</a> ";
                    }
                    if ($offpg != 1)
                    {
                        if ($page > 1)
                        {
                            print "<a href=\"?page=1\">1</a> ";
                        }
                        if ($prev > 2)
                        {
                            print " .. ";
                        }
                        $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 ' <a href="?page=' . $paa . '">' . $paa . '</a> <a href="?page=' . ($paa + 1) . '">' . ($paa + 1) . '</a> .. <a href="?page=' . ($paa * 2) . '">' . ($paa *
                                2) . '</a> <a href="?page=' . ($paa * 2 + 1) . '">' . ($paa * 2 + 1) . '</a> .. ';
                        } elseif ($page > 7)
                        {
                            echo ' <a href="?page=' . $pa . '">' . $pa . '</a> <a href=?page=' . ($pa + 1) . '">' . ($pa + 1) . '</a> .. ';
                        }
                        if ($prev > 1)
                        {
                            print "<a href=\"?page=$prev\">$prev</a> ";
                        }
                        echo "<b>$page</b> ";
                        if ($next < $pages)
                        {
                            print "<a href=\"?page=$next\">$next</a> ";
                        }
                        if ($page2 > 12)
                        {
                            echo ' .. <a href="?page=' . $paa2 . '">' . $paa2 . '</a> <a href="?page=' . ($paa2 + 1) . '">' . ($paa2 + 1) . '</a> .. <a href="?page=' . ($paa3) . '">' . ($paa3) .
                                '</a> <a href="?page=' . ($paa3 + 1) . '">' . ($paa3 + 1) . '</a> ';
                        } elseif ($page2 > 6)
                        {
                            echo ' .. <a href="?page=' . $pa2 . '">' . $pa2 . '</a> <a href="?page=' . ($pa2 + 1) . '">' . ($pa2 + 1) . '</a> ';
                        }
                        if ($next < ($pages - 1))
                        {
                            print " .. ";
                        }
                        if ($page < $pages)
                        {
                            print "<a href=\"?page=$pages\">$pages</a> ";
                        }
                    } else
                    {
                        echo "<b>[$page]</b>";
                    }
                    if ($page < $pages)
                    {
                        print " <a href=\"?page=$next\">&gt;&gt;</a>";
                    }
                    echo '<form action="?">Стр:<input type="hidden" name="read" value="' . $read .'"/>
                                                                          <input type="hidden" name="id" value="' . $file .'"/>
                        <input class="enter" name="page" type="text" maxlength="4" size="2" value="' . $page .'"/>
&nbsp;<input class="buttom" type="submit" value="GO"/>
</form>';
                }
###################################################
echo '<form action="?page='.$page.'" method="post">
Размер шрифта:<br />
<select class="buttom" size="1" width="70" name="font"><option value="'.$font.'">'.$font.'</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><br />
Количество символов на страницу:<br />
<select class="buttom" size="1" width="70" name="number"><option value="'.$number.'">'.$number.'</option><option value="500">500</option><option value="1000">1000</option><option value="2000">2000</option><option value="3000">3000</option><option value="4000">4000</option><option value="5000">5000</option><option value="6000">6000</option><option value="7000">7000</option></select><br />
<input type="submit" class="ibutton" value="OK"/></form>
<br />
';

/*
<br /><a href="/fo/load/'.$file.'">Скачать</a><br/>
<a href="/fo/txt_zip/'.$file.'">Скачать ZIP</a><br/>
<a href="/fo/txt_jar/'.$file.'">Скачать JAR</a><br/>*/

}else{
if($d['pass']!=$pass){
$buy_ok = '';
if(isset($_GET['buy'])){
if ($user['rur']<$d['price']){$buy_ok = 'Недостаточно средств!';
}else{
// Забераем рубли
$rur = $user['rur']-$d['price'];
$db->sql_query('UPDATE `users` SET `rur` = "'.$rur.'" WHERE `id` = "'.$user['id'].'"');
// Начисляем рубли
$rur2 = user_inf($d['user_id'],'rur')+$d['price'];
$db->sql_query('UPDATE `users` SET `rur` = "'.$rur2.'" WHERE `id` = "'.$d['user_id'].'"');

$buy_ok = $d['pass'];
}

}
if(isset($pass))echo '<b>Неверный пароль!</b><br />';
echo 'Файл защищен паролем!<br />';
if($d['price']!=0&&$buy_ok=='')echo '<a href="?buy">Купить пароль('.$d['price'].' рублей)</a><br />';
if ($ver!='wml')echo '<form action="?'.SID.'" method="post">';

echo 'Пароль:<br/>';
echo '<input type="text" name="pass" value="'.$buy_ok.'" maxlength="50" title="Пароль"/><br/>';

if ($ver=='wml'){
echo '<br /><anchor title="go">Скачать<go href="?'.SID.'" method="post">';
echo '<postfield name="pass" value="$pass"/>
</go></anchor>';
echo '<br/><br />';
}else{
echo '<br /><input type="submit" class="ibutton" value="Скачать"/></form><br /><br />';
}
echo "<br/>";
echo gb.'<a href="/fo">Обменник</a>'.div;
echo gb.'<a href="/enter">Прихожая</a>'.div;

foot();
}else{

if(session_start()){
if(!empty($_SESSION["font"]) AND !empty($_POST['font'])){
$_SESSION["font"]=$_POST['font'];
}
elseif(empty($_SESSION["font"]) AND !empty($_POST['font']))
{
 $font=$_POST['font'];
 session_register ("font") ;
}


if(!empty($_SESSION["number"]) AND !empty($_POST['number']))
$_SESSION["number"]=$_POST['number'];
elseif(empty($_SESSION["number"]) AND !empty($_POST['number']))
{
 $number=$_POST['number'];
 session_register ("number") ;
}
 }
 if(!$_SESSION["number"]) $_SESSION["number"]=2000;
 if(! $_SESSION["font"])  $_SESSION["font"]=2;
$font= intval($_SESSION["font"]);
$number= intval($_SESSION["number"]);
###################################################
$text=file_get_contents($d['path']);
$nf = pathinfo($d['path']);
$filename = $nf['basename'];



function highlight_code($code)

{

  $code = stripslashes($code);
  $code = trim($code);
  return highlight_string($code,true);

}
///echo $text;
//$text=str_replace('<','&lt;',$text);
//$text=str_replace('>','&gt',$text);
//$text=str_replace("\n",'<br />',$text);
  $simvol = $number; // Число символов на страницу по умолчанию
                $tx =$text;
                if (!empty($_GET['page']))
                {
                    $page = intval($_GET['page']);
                } else
                {
                    $page = 1;
                }

                # для постраничного вывода используется модифицированный код от hintoz #
               // $strrpos = mb_strrpos($tx, " ");
                $pages = 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=highlight_code($page_text);
                 $page_text=charset_x_win($page_text);
                 $page_text=iconv("windows-1251", "UTF-8", "$page_text");
                // Текст статьи
              /*  $page_text = htmlentities($page_text, ENT_QUOTES, 'UTF-8');
                $page_text = str_replace("\n",'<br />', $page_text); */
                echo '<font size="'.intval($font).'">'.$page_text.'</font>';
                echo '<hr />';
                $next = $page + 1;
                $prev = $page - 1;
                if ($pages > 1)
                {

                    if ($page > 1)
                    {
                        print " <a href=\"?pass='.$pass.'&amp;page=$prev\">&lt;&lt;</a> ";
                    }
                    if ($offpg != 1)
                    {
                        if ($page > 1)
                        {
                            print "<a href=\"?pass='.$pass.'&amp;page=1\">1</a> ";
                        }
                        if ($prev > 2)
                        {
                            print " .. ";
                        }
                        $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 ' <a href="?pass='.$pass.'&amp;page=' . $paa . '">' . $paa . '</a> <a href="?page=' . ($paa + 1) . '">' . ($paa + 1) . '</a> .. <a href="?pass='.$pass.'&amp;page=' . ($paa * 2) . '">' . ($paa *
                                2) . '</a> <a href="?pass='.$pass.'&amp;page=' . ($paa * 2 + 1) . '">' . ($paa * 2 + 1) . '</a> .. ';
                        } elseif ($page > 7)
                        {
                            echo ' <a href="?pass='.$pass.'&amp;page=' . $pa . '">' . $pa . '</a> <a href=?page=' . ($pa + 1) . '">' . ($pa + 1) . '</a> .. ';
                        }
                        if ($prev > 1)
                        {
                            print "<a href=\"?pass='.$pass.'&amp;page=$prev\">$prev</a> ";
                        }
                        echo "<b>$page</b> ";
                        if ($next < $pages)
                        {
                            print "<a href=\"?pass='.$pass.'&amp;page=$next\">$next</a> ";
                        }
                        if ($page2 > 12)
                        {
                            echo ' .. <a href="?page=' . $paa2 . '">' . $paa2 . '</a> <a href="?page=' . ($paa2 + 1) . '">' . ($paa2 + 1) . '</a> .. <a href="?page=' . ($paa3) . '">' . ($paa3) .
                                '</a> <a href="?pass='.$pass.'&amp;page=' . ($paa3 + 1) . '">' . ($paa3 + 1) . '</a> ';
                        } elseif ($page2 > 6)
                        {
                            echo ' .. <a href="?pass='.$pass.'&amp;page=' . $pa2 . '">' . $pa2 . '</a> <a href="?page=' . ($pa2 + 1) . '">' . ($pa2 + 1) . '</a> ';
                        }
                        if ($next < ($pages - 1))
                        {
                            print " .. ";
                        }
                        if ($page < $pages)
                        {
                            print "<a href=\"?pass='.$pass.'&amp;page=$pages\">$pages</a> ";
                        }
                    } else
                    {
                        echo "<b>[$page]</b>";
                    }
                    if ($page < $pages)
                    {
                        print " <a href=\"?pass='.$pass.'&amp;page=$next\">&gt;&gt;</a>";
                    }
                    echo '<form action="?pass='.$pass.'&amp;">Стр:<input type="hidden" name="read" value="' . $read .'"/>
                                                                          <input type="hidden" name="id" value="' . $file .'"/>
                        <input class="enter" name="page" type="text" maxlength="4" size="2" value="' . $page .'"/>
&nbsp;<input class="buttom" type="submit" value="GO"/>
</form>';
                }
###################################################
echo '<form action="?pass='.$pass.'&amp;page='.$page.'" method="post">
Размер шрифта:<br />
<select class="buttom" size="1" width="70" name="font"><option value="'.$font.'">'.$font.'</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><br />
Количество символов на страницу:<br />
<select class="buttom" size="1" width="70" name="number"><option value="'.$number.'">'.$number.'</option><option value="500">500</option><option value="1000">1000</option><option value="2000">2000</option><option value="3000">3000</option><option value="4000">4000</option><option value="5000">5000</option><option value="6000">6000</option><option value="7000">7000</option></select><br />
<input type="submit" class="ibutton" value="OK"/></form>
<br />
';

/*
<br /><a href="/fo/load/'.$file.'">Скачать</a><br/>
<a href="/fo/txt_zip/'.$file.'">Скачать ZIP</a><br/>
<a href="/fo/txt_jar/'.$file.'">Скачать JAR</a><br/>*/

}



}


echo gb.'<a href="/fo/down/'.$file.'">К файлу</a>'.div;
echo gb.'<a href="/fo/'.$cat['id'].'/'.$cat2['id'].'">В категорию</a>'.div;
echo gb.'<a href="/fo">Обменник</a>'.div;
echo gb.'<a href="/enter">Прихожая</a>'.div;

foot();

?>
