File size: 6.45Kb
<?php
define('_IN_JOHNCMS', 1);
$headmod = 'lib';
$textl = 'Библиотека';
require_once ("../incfiles/core.php");
require_once ("./inc/conf.php");
// Ограничиваем доступ к Библиотеке
if (!$set['mod_lib'] && $rights < 7)
{$error = 'Библиотека закрыта';}
elseif ($set['mod_lib'] == 1 && !$user_id)
{$error = 'Доступ в Библиотеку открыт только <a href="../in.php">авторизованным</a> посетителям';}
elseif ($dos_load == "0")
{$error = 'Скачивание статей запрешенно!';}
if ($error) {
require_once ("../incfiles/head.php");
echo '<div class="rmenu"><p>' . $error . '</p></div>';
require_once ("../incfiles/end.php");
exit;
}
require_once ("../incfiles/head.php");
if($rights == 5 || $rights >= 6)
{
echo '<div class="gmenu"><a href="admin.php"><strong>Управление библиотекой</strong></a></div>';
}
if(empty($_POST['submit']))
{
$cod = rand(1000, 9999);
$_SESSION['code'] = $cod;
echo '<form method="post" action="load.php?id='.$id.'"><p>';
echo 'Выберете тип:<br/><select name="type">';
echo '<option value="1">ZIP</option><option value="2">JAR</option><option value="3">TXT</option>';
echo '</select><br/>';
echo '<img src="../code.php" alt=""/><br />';
echo 'Код с картинки:<br/><input type="text" size="4" maxlength="4" name="kod"/></p>';
echo '<input value="Скачать" type="submit" name="submit"/></form>';
}else{
$type = trim($_POST['type']);
if($_POST['kod'] != $_SESSION['code'])
{
$error = 'Проверочный код не верен!';
}elseif(empty($_POST['kod']))
{
$error = 'Проверочный код неведен!';
}
if(empty($error))
{
switch($type)
{
case "1":
include_once './inc/zip.class.php';
$sql = mysql_query("select `text` from `library` where `id` = '".$id."' LIMIT 1");
$cou = mysql_num_rows($sql);
if($cou > 0)
{
$res = mysql_fetch_array($sql);
$text = stripslashes($res['text']).'';
$Zip = new createZip;
$Zip -> addFile($text, 'text_'.$id.'.txt');
$fileName = "file/txt_".$user_id.".zip";
if(file_exists($fileName))
{
@unlink($fileName);
}
$fd = fopen ($fileName, "wb");
fwrite ($fd, $Zip -> getZippedfile());
fclose ($fd);
echo 'Вы можете скачать ZIP-Архив<br/><a href="file/'.$fileName.'">Скачать</a> ('.formatsize(filesize($fileName)).')<br/>';
}else{
echo '<div class="rmenu">Такой стаьи не существует</div>';
}
break;
case "2":
include_once './inc/zip.class2.php';
$sql = mysql_query("select `text` from `library` where `id` = '".$id."' LIMIT 1");
$cou = mysql_num_rows($sql);
if($cou > 0)
{
$res = mysql_fetch_array($sql);
$MANIF = file_get_contents('./jar/META-INF/MANIFEST.MF');
$aclass = file_get_contents('./jar/a.class');
$bclass = file_get_contents('./jar/b.class');
$cclass = file_get_contents('./jar/c.class');
$dclass = file_get_contents('./jar/d.class');
$eclass = file_get_contents('./jar/e.class');
$fclass = file_get_contents('./jar/f.class');
$gclass = file_get_contents('./jar/g.class');
$hclass = file_get_contents('./jar/h.class');
$iclass = file_get_contents('./jar/i.class');
$jclass = file_get_contents('./jar/j.class');
$charsets = file_get_contents('./jar/charsets');
$files = file_get_contents('./jar/files');
$htxt = file_get_contents('./jar/h.txt');
$mainclass = file_get_contents('./jar/main.class');
$windows866 = file_get_contents('./jar/windows-866');
$windows1251 = file_get_contents('./jar/windows-1251');
$epng = file_get_contents('./jar/e.png');
$cpng = file_get_contents('./jar/c.png');
$text = '<encoding="UTF-8">'."\n".stripslashes($res['text']);
$createZip = new createZip;
$createZip -> addDirectory('META-INF/');
$createZip -> addFile($text, 'text.txt');
$createZip -> addFile($MANIF, 'META-INF/'.'MANIFEST.MF');
$createZip -> addFile($aclass, 'a.class');
$createZip -> addFile($bclass, 'b.class');
$createZip -> addFile($cclass, 'c.class');
$createZip -> addFile($dclass, 'd.class');
$createZip -> addFile($eclass, 'e.class');
$createZip -> addFile($fclass, 'f.class');
$createZip -> addFile($gclass, 'g.class');
$createZip -> addFile($hclass, 'h.class');
$createZip -> addFile($iclass, 'i.class');
$createZip -> addFile($jclass, 'j.class');
$createZip -> addFile($charsets, 'charsets');
$createZip -> addFile($files, 'files');
$createZip -> addFile($htxt, 'h.txt');
$createZip -> addFile($windows866, 'windows-866');
$createZip -> addFile($windows1251, 'windows-1251');
$createZip -> addFile($mainclass, 'main.class');
$createZip -> addFile($epng, 'e.png');
$createZip -> addFile($cpng, 'c.png');
$fileName = "file/txt_".$user_id.".jar";
if(file_exists($fileName))
{
@unlink($fileName);
}
$fd = fopen ($fileName, "wb");
fwrite ($fd, $createZip -> getZippedfile());
fclose ($fd);
echo 'Вы можете скачать JAR-Архив<br/><a href="file/'.$fileName.'">Скачать</a> ('.formatsize(filesize($fileName)).')<br/>';
}else{
echo '<div class="rmenu">Такой стаьи не существует</div>';
}
break;
case "3":
$sql = mysql_query("select `name`,`text` from `library` where `id` = '".$id."' LIMIT 1");
$cou = mysql_num_rows($sql);
if($cou > 0)
{
$res = mysql_fetch_array($sql);
$text = stripslashes($res['text']);
$name = $res['name'];
header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename="text_'.$name.'.txt"');
echo $text;
}
break;
}
}else{
echo '<div class="rmenu">'.$error.'</div>';
}
}
require_once ('../incfiles/end.php');
?>