<?php

          include '../../system/core.php';
      
 $_title = 'Обменник';
          include '../../system/header.php';



          if(!$user['id'])
          {
 
          header('Location: /index.php/?m=guest'); exit;
  
          }





        switch($_GET['m'])
        {
    case 'new':

          echo '<div class="tegi"><a href="/zc">Назад</a> | Новые файлы</div>';
	
  $cop = 10;
  $ca = mysql_result(mysql_query("SELECT COUNT(*) FROM `zc_f` where `time` > '".(time()-((60*60)*24))."'"),0);
  $cp = ceil($ca/$cop);
  if(isset($_GET['p']) && is_numeric($_GET['p'])){
  $p = $_GET['p'];
  if($_GET['p']>$cp) $p = $cp;
  if($_GET['p']<1)$p = 1;
  }else{
  $p = 1;
  }
  $start = $p*$cop-$cop;
  
  $new = mysql_query("select * from `zc_f` where `time` > '".(time()-((60*60)*24))."' and `status`='0' order by `time` desc limit $start,$cop");
  while($new2 = mysql_fetch_assoc($new)){
  
  echo '<a href="/zc/f'.$new2['id'].'"><div class="post2"><img src="/images/box.png"/> '.$new2['name'].'</div></a>';
    

  }

 


  echo '</div><div class="spis">Стр. ';
  if($p-2>0) echo '<a href="/zc/new?p=1"><<</a> ';
  if($p-1>0) echo '<a href="/zc/new?p='.($p-1).'"><</a> ';

  if($p-3>0) echo '<a href="/pc/new?p='.($p-3).'">'.($p-3).'</a> | ';
  if($p-2>0) echo '<a href="/zc/new?p='.($p-2).'">'.($p-2).'</a> | ';  
  if($p-1>0) echo '<a href="/zc/new?p='.($p-1).'">'.($p-1).'</a> | ';
  
  echo '<b>'.$p.'</b>';
  if($p+1<=$cp) echo ' | <a href="/zc/new?p='.($p+1).'">'.($p+1).'</a>';
  if($p+2<=$cp) echo ' | <a href="/zc/new?p='.($p+2).'">'.($p+2).'</a>';
  if($p+3<=$cp) echo ' | <a href="/zc/new?p='.($p+3).'">'.($p+3).'</a>';

  if($p+1<=$cp) echo ' <a href="/zc/new?p='.($p+1).'">></a>';
  if($p+2<=$cp) echo ' <a href="/zc/new?p='.ceil($ca/$cop).'">>></a>';
  echo '</div>';

  break;

        default: 
  
    
     $id = TextGuard($id);

  $zc_r = mysql_fetch_array(mysql_query('select * from `zc_r` where `moder` = '.$user['id'].''));

  
  
  if($user['status'] == 4){
  echo '<div class="tegi">Админ-панель</div><div class="msg"><a href="/zc/nr">Добавить раздел</a> | <a href="/zc/moder">Модерация</a></div>';
  } 
  
  echo '<div class="tegi">Обменник</div><div class="post2">Файлы <a href="/zc/new">Новые</a> ('.mysql_result(mysql_query('select count(`id`) from `zc_f` where `time` > "'.(time()-((60*60)*24)).'" and `status` = "0"'),0).')</a> | <a href="/us'.$user['id'].'?m=files">Мои</a></div>';
   
 
  
  $cop = $user['on_page'];
  $ca = mysql_result(mysql_query("SELECT COUNT(*) FROM `zc_r`"),0);
  $cp = ceil($ca/$cop);
  if(isset($_GET['p']) && is_numeric($_GET['p'])){
  $p = $_GET['p'];
  if($_GET['p']>$cp) $p = $cp;
  if($_GET['p']<1)$p = 1;
  }else{
  $p = 1;
  }
  $start = $p*$cop-$cop;
  $zc_r = mysql_query("SELECT * FROM `zc_r` ORDER BY `id` LIMIT $start,$cop");
  while($zc_r2 = mysql_fetch_assoc($zc_r)){
echo '<div class="post2"><img src="/img/papka.png" wight="20" height="20"> <a href="/zc/r'.$zc_r2['id'].'">';
  echo ''.$zc_r2['name'].'</a>';
  
  if($user['status'] == 4) echo '  [<a href="/zc/prdel'.$zc_r2['id'].'">уд</a>] [<a href="/zc/red'.$zc_r2['id'].'">ред</a>]';
  
  echo '</br>'.$zc_r2['about'].'</div>';
  }
//////////////////////////////////////////////////////////
 if(mysql_result(mysql_query('select count(`id`) from `zc_f` where `time` > "'.(time()-((60*60)*24)).'" and `status` = "0"'),0) != 0) $files_new = '/<font color="red"><b>+'.mysql_result(mysql_query('select count(`id`) from `zc_f` where `time` > "'.(time()-((60*60)*24)).'" and `status` = "0"'),0).'</b></font>';
 
 
          /////////////////////////////////////////////////////////
  echo '</div><div class="spis">Стр. ';
  if($p-2>0) echo '<a href="/zc/p1"><<</a> ';
  if($p-1>0) echo '<a href="/zc/p'.($p-1).'"><</a> ';

  if($p-3>0) echo '<a href="/zc/p'.($p-3).'">'.($p-3).'</a> | ';
  if($p-2>0) echo '<a href="/zc/p'.($p-2).'">'.($p-2).'</a> | ';  
  if($p-1>0) echo '<a href="/zc/p'.($p-1).'">'.($p-1).'</a> | ';
  
  echo '<b>'.$p.'</b>';
  if($p+1<=$cp) echo ' | <a href="/zc/p'.($p+1).'">'.($p+1).'</a>';
  if($p+2<=$cp) echo ' | <a href="/zc/p'.($p+2).'">'.($p+2).'</a>';
  if($p+3<=$cp) echo ' | <a href="/zc/p'.($p+3).'">'.($p+3).'</a>';

  if($p+1<=$cp) echo ' <a href="/zc/p'.($p+1).'">></a>';
  if($p+2<=$cp) echo ' <a href="/zc/p'.ceil($ca/$cop).'">>></a>';
  echo '</div>';
  
  break;
  
  case 'r':
 
   $id = TextGuard($_GET['id']);
  $zc_r = mysql_fetch_array(mysql_query('select * from `zc_r` where `id` = '.$id.''));
  if(empty($id) or !is_numeric($id) or $zc_r == 0){
  header('Location: /zc'); exit;
  }
  
      
          echo "<div class='tegi'>Загруз-центр</div>";
	
echo '</div>';
   include '../../system/nvg.php';
  
  if($user['status'] >= 3){
  echo '<div class="msg"><a href="/zc/npr'.$id.'">Новый подраздел</a></div>';
  } 

  $cop = $user['on_page'];
  $ca = mysql_result(mysql_query("SELECT COUNT(*) FROM `zc_pr` where `r` = '".$id."'"),0);
  $cp = ceil($ca/$cop);
  if(isset($_GET['p']) && is_numeric($_GET['p'])){
  $p = $_GET['p'];
  if($_GET['p']>$cp) $p = $cp;
  if($_GET['p']<1)$p = 1;
  }else{
  $p = 1;
  }
  $start = $p*$cop-$cop;
  $zc_pr = mysql_query("SELECT * FROM `zc_pr` where `r` = '".$id."' ORDER BY `id` DESC LIMIT $start,$cop");
  while($zc_pr2 = mysql_fetch_assoc($zc_pr)){
  echo '<div class="post2"><img src="/modules/zc/images/unknown.png"/> <a href="/zc/pr'.$zc_pr2['id'].'">'.$zc_pr2['name'].'</a> ('.mysql_result(mysql_query('select count(`id`) from `zc_f` where `pr` = "'.$zc_pr2['id'].'" and `status` = "0"'),0).')';
  
  if($user['status'] == 4) echo '  [<a href="/zc/pred'.$zc_pr2['id'].'">ред</a>]';

  
  echo '</div>';
  }

  echo '</div><div class="spis">Стр. ';
  if($p-2>0) echo '<a href="/zc/r'.$id.'?p=1"><<</a> ';
  if($p-1>0) echo '<a href="/zc/r'.$id.'?p='.($p-1).'"><</a> ';

  if($p-3>0) echo '<a href="/zc/r'.$id.'?p='.($p-3).'">'.($p-3).'</a> | ';
  if($p-2>0) echo '<a href="/zc/r'.$id.'?p='.($p-2).'">'.($p-2).'</a> | ';  
  if($p-1>0) echo '<a href="/zc/r'.$id.'?p='.($p-1).'">'.($p-1).'</a> | ';
  
  echo '<b>'.$p.'</b>';
  if($p+1<=$cp) echo ' | <a href="/zc/r'.$id.'?p='.($p+1).'">'.($p+1).'</a>';
  if($p+2<=$cp) echo ' | <a href="/zc/r'.$id.'?p='.($p+2).'">'.($p+2).'</a>';
  if($p+3<=$cp) echo ' | <a href="/zc/r'.$id.'?p='.($p+3).'">'.($p+3).'</a>';

  if($p+1<=$cp) echo ' <a href="/zc/r'.$id.'?p='.($p+1).'">></a>';
  if($p+2<=$cp) echo ' <a href="/zc/r'.$id.'?p='.ceil($ca/$cop).'">>></a>';
  echo '</div>';
  
  break;
  
  case 'pr':
  
$id = TextGuard($_GET['id']);

  $zc_pr = mysql_fetch_array(mysql_query('select * from `zc_pr` where `id` = '.$id.''));

  $zc_r = mysql_fetch_array(mysql_query('select * from `zc_r` where `id` = '.$zc_pr['r'].''));


 echo '<div class="tegi"><a href="/zc">Назад</a> | Категории</div>';
      
  
  echo '<div class="msg"><a href="/zc/up'.$id.'"><b>Добавить файл</b></a>
  </div>';
  
  $cop = 10;
  $ca = mysql_result(mysql_query("SELECT COUNT(*) FROM `zc_f` where `pr` = '".$id."' and `status` = '0'"),0);
  $cp = ceil($ca/$cop);
  if(isset($_GET['p']) && is_numeric($_GET['p'])){
  $p = $_GET['p'];
  if($_GET['p']>$cp) $p = $cp;
  if($_GET['p']<1)$p = 1;
  }else{
  $p = 1;
  }
  $start = $p*$cop-$cop;

  $zc_f = mysql_query('select * from `zc_f` where `pr` = '.$id.' and `status` = "0"');

  while($zc_f2 = mysql_fetch_assoc($zc_f)){
  echo '<a href="/zc/f'.$zc_f2['id'].'"><div class="post2"><img src="/modules/zc/images/archive.png"/> '.$zc_f2['name'].' ('.round(filesize('files/'.$zc_f2['file'].'')/1024).' кб)</div></a>';
  }

  echo '</div><div class="spis">Стр. ';
  if($p-2>0) echo '<a href="/zc/pr'.$id.'?p=1"><<</a> ';
  if($p-1>0) echo '<a href="/zc/pr'.$id.'?p='.($p-1).'"><</a> ';

  if($p-3>0) echo '<a href="/zc/pr'.$id.'?p='.($p-3).'">'.($p-3).'</a> | ';
  if($p-2>0) echo '<a href="/zc/pr'.$id.'?p='.($p-2).'">'.($p-2).'</a> | ';  
  if($p-1>0) echo '<a href="/zc/pr'.$id.'?p='.($p-1).'">'.($p-1).'</a> | ';
  
  echo '<b>'.$p.'</b>';
  if($p+1<=$cp) echo ' | <a href="/zc/pr'.$id.'?p='.($p+1).'">'.($p+1).'</a>';
  if($p+2<=$cp) echo ' | <a href="/zc/pr'.$id.'?p='.($p+2).'">'.($p+2).'</a>';
  if($p+3<=$cp) echo ' | <a href="/zc/pr'.$id.'?p='.($p+3).'">'.($p+3).'</a>';

  if($p+1<=$cp) echo ' <a href="/zc/pr'.$id.'?p='.($p+1).'">></a>';
  if($p+2<=$cp) echo ' <a href="/zc/pr'.$id.'?p='.ceil($ca/$cop).'">>></a>';
  echo '</div>';
  
  break;
  
 
 case 'imp':

  $id = TextGuard($_GET['id']);

  $zc_pr = mysql_fetch_array(mysql_query('select * from `zc_pr` where `id` = '.$id.''));

  $zc_r = mysql_fetch_array(mysql_query('select * from `zc_r` where `id` = '.$zc_pr['r'].''));


  
      
          echo "<div class='tegi'><a href='/zc'>Обменник</a> | Импорт</div>";

  
 if(isset($_POST['import'])){
  
  $name = TextGuard($_POST['name']);
 $url = TextGuard($_POST['url']);

  if(empty($name)) $err[] = 'Название осталось пустым...';
  $about = TextGuard($_POST['about']);
  if(empty($about)) $err[] = 'Описание осталось пустым...';
  $rating = TextGuard($_POST['rating']);
  if(empty($rating)) $rating = 0;
  if($rating > $user['rating']) $err[] = 'Вы не можете поставить рейтинг для скачивание больше чем ваш.';
  if(!is_numeric($rating)) $err[] = 'Ошибка ввода рейтинга...';
  
    $path_info = pathinfo($url); // Информация о файле
    if ($path_info['extension'] == 'php' || $path_info['extension'] == 'js' || $path_info['extension'] == 'htaccess') $err[] = 'Запрещенный тип файла!<br />';
	
    if(!$err) {
$fn = date('dmY').'_fn'.rand(1234,5678).'_'.$_FILES['filename']['name'];  
  move_uploaded_file($_FILES['filename']['tmp_name'], "files/".$fn."");

			mysql_query("INSERT INTO `zc_f`(
			`r`,
			`pr`,
			`name`,
      `about`,
      `author`,
      `rating`,
      `downs`,
      `ldown`,
      `time`,
      `status`,
      `file`
			)VALUES(
      '".$zc_r['id']."',
      '".$zc_pr['id']."',
      '".$name."',
      '".$about."',
      '".$user['id']."',
      '".$rating."',
      '0',
      '".time()."',
      '".time()."',
      '1',
      '".$fn."'
			)");
  echo '<div class="msg"><b>Файл успешно выставлен на модерацию</b></div>';
  
  }else{
  echo '<div class="err"><b>';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</b></div>';
  
 
			}
		}
echo '<div class="tegi">Импортировать файл</div>
<div class="post2"><form action="?import" method="post">
Название файла:<br/>
<input type="text" name="name"><br/>
Описание:<br/>
<textarea name="about"></textarea><br/>
Рейтинг для скачивания файла: <input name="rating" size="2"/><br>
<textarea name="text"></textarea><br/>
Ссылка для импорта:<br/>
<input type="text" name="url" value="http://"><br/>
<input type="submit" name="import" value="Импортировать">
</form></div>';

  break;
  case 'up':

  $id = TextGuard($_GET['id']);

  $zc_pr = mysql_fetch_array(mysql_query('select * from `zc_pr` where `id` = '.$id.''));

  $zc_r = mysql_fetch_array(mysql_query('select * from `zc_r` where `id` = '.$zc_pr['r'].''));


  
      
          echo "<div class='tegi'><a href='/zc'>Обменник</a> | Добавить файл</div>";

  
  if(isset($_POST['submit'])){
  
  $name = TextGuard($_POST['name']);
$img = TextGuard($_POST['img']);
  if(empty($name)) $err[] = 'Название осталось пустым...';
  $about = TextGuard($_POST['about']);
  if(empty($about)) $err[] = 'Описание осталось пустым...';
  $rating = TextGuard($_POST['rating']);
  if(empty($rating)) $rating = 0;
  if($rating > $user['rating']) $err[] = 'Вы не можете поставить рейтинг для скачивание больше чем ваш.';
  if(!is_numeric($rating)) $err[] = 'Ошибка ввода рейтинга...';
  
  
  if(!@file_exists($_FILES['filename']['tmp_name'])) $err[] = 'Вы не выбрали файл...';
  if($_FILES['filename']['size'] != 0 and $_FILES['filename']['size'] > 1002400000) $err[] = 'Слишком большой файл...';
  $filetype = array ( 'jpg', 'gif', 'png', 'jpeg', 'bmp', 'zip', 'rar', '7z', 'txt', 'mp3', 'avi', 'mp4', '3gp' );
  $upfiletype = substr($_FILES['filename']['name'],  strrpos( $_FILES['filename']['name'], "." )+1);
  if(!in_array($upfiletype,$filetype)) $err[] = 'Вы пытаетесь загрузить недопустимый формат файла...';

  if(!$err){

  $fn = date('dmY').'_fn'.rand(1234,5678).'_'.$_FILES['filename']['name'];  
  move_uploaded_file($_FILES['filename']['tmp_name'], "files/".$fn."");

			mysql_query("INSERT INTO `zc_f`(
			`r`,
			`pr`,
			`name`,
      `about`,
      `author`,
      `rating`,
      `downs`,
      `ldown`,
      `time`,
      `status`,
      `file`
			)VALUES(
      '".$zc_r['id']."',
      '".$zc_pr['id']."',
      '".$name."',
      '".$about."',
      '".$user['id']."',
      '".$rating."',
      '0',
      '".time()."',
      '".time()."',
      '1',
      '".$fn."'
			)");

  $fid = mysql_insert_id();

    	
  echo '<div class="msg"><b>Файл успешно выставлен добавлен</b></div>';
  
  }else{
  echo '<div class="err"><b>';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</b></div>';
  }
  }

  echo '<div class="post2">
  <form action="/zc/up'.$id.'" method="post" enctype="multipart/form-data">
  Название:<br><input name="name"/><br>
  Описание:<br><textarea name="about" style="width:98%;" rows="3"></textarea><br>
  Рейтинг для скачивания файла: <input name="rating" size="2"/><br>
  Файл:<br><input type="file" name="filename"/><br>
Скриншот:<br>Пока не работает…<br>
  <input type="submit" value="Загрузить" name="submit"/>  
  </form></div></div>';

  break;
 
  case 'f':
  
 $id = TextGuard($_GET['id']);

  $zc_f = mysql_fetch_array(mysql_query('select * from `zc_f` where `id` = '.$id.' and `status` = "0"'));

  $zc_pr = mysql_fetch_array(mysql_query('select * from `zc_pr` where `id` = '.$id.''));

  $zc_r = mysql_fetch_array(mysql_query('select * from `zc_r` where `id` = '.$zc_pr['r'].''));


 
  if(empty($id) or !is_numeric($id) or $zc_pr == 0 or $zc_r == 0 or $zc_f == 0){
  header('Location: /zc'); exit;
  }
  
      
  

  
  if(isset($_GET['del'])){
  
  unlink('files/'.$zc_f['file'].'');
  mysql_query("DELETE FROM `zc_f` WHERE `id`='".$id."'");
  header('Location: /zc/pr'.$zc_pr['id'].''); exit;
  
  }
  

  
  
  echo '<div class="tegi"><a href="/zc">Обменник</a> | '.$zc_f['name'].'</div>';

  
 if($zc_f['rating'] > 0) echo '<div class="post2"><font color="red">!</font> Для скачивания файла необходимо иметь <font clolor="green">'.$zc_f['rating'].'</font> рейтинга</div>';

  echo '<div class="post2">Название:<b>'.$zc_f['name'].'</b></div>';

echo '<div class="post2"><center>';
   
 if(!$zc_f['scrin']){
echo '<img src="/modules/zc/scrin/noscrin.png" alt="Skrin" width="80" height="80"/>';
  }else{
  echo '<a href="/modules/zc/scrin/'.$zc_f['scrin'].'">
  <img src="/modules/zc/scrin/'.$zc_f['scrin'].'" alt="*" width="80" height="80"/></a>';
  } 
echo '</center></div>'; 
  echo '<div class="post2"><b>Описание:</b><br/>
'.smiles(bbcode($zc_f['about'])).'<br/>';
  
  echo '<b>Загрузил:</b> '.ustatus($zc_f['author']).' <a href="/us'.$zc_f['author'].'">'.uname($zc_f['author']).'</a> '.uaccess($zc_f['author']).'<br/>
<b>Размер:</b> '.round(filesize('files/'.$zc_f['file'].'')/1024).' кб.<br/>
<b>Добавлен:</b> '.times($zc_f['time']).'</div>';
  
 
  
  if($zc_f['rating'] <= $user['rating']){
  echo '<a href="/zc/upf'.$id.'"><div class="msg"><b>Скачать</b> ('.$zc_f['downs'].' раз)</div></a><div class="post2">
  Ссылка на файл:<br/><input type="text" value="http://forcss.ru/zc/f'.$id.'"/><br/>
  Экспорт:<br/><input type="text" value="http://forcss.ru/upf'.$id.'"/>
  </div>';
 
  
 if($user['status'] == 4){
  
   echo '<a href="/zc/f'.$id.'?del"><div class="msg">Удалить файл</div></a>';
  
  
  }
}

  if(isset($_GET['v'])){
  
  $go = TextGuard($_GET['go']);

  $zc_frating = mysql_fetch_array(mysql_query('select * from `zc_frating` where `f` = '.$id.' and `who` = "'.$user['id'].'"'));

  if(empty($go) or $go != "p" && $go != "m" or $zc_frating != 0 or $user['id'] == $zc_f['author']){
  header('Location: /zc/f'.$id.''); exit;
  }
  
  if($go == "p") $status = 1; elseif($go == "m") $status = 2;

  		mysql_query("INSERT INTO `zc_frating`(
			`f`,
			`who`,
			`status`,
			`time`
			)VALUES(
			'".$id."',
			'".$user['id']."',
			'".$status."',
			'".time()."'
			)");


  $zc_f_author = mysql_fetch_array(mysql_query('select * from `user` where `id` = "'.$zc_f['author'].'"'));
  if($zc_f_author != 0){
  
  if($status == 1){
  
  mysql_query("UPDATE `user` SET `rating`='".($zc_f_author['rating']+0.01)."' WHERE `id`='".$zc_f_author['id']."' limit 1");
  
    	 mysql_query("INSERT INTO `op`(
			`who`,
			`ho`,
			`text`,
      `time`,
      `read`,
      `sort`
			)VALUES(
      '".$zc_f_author['id']."',
      '".$user['id']."',
      'оценил [b]положительно[/b] ваш [url=/zc/f".$id."]файл[/url]!',
      '".time()."',
      '0',
      '3'
			)");

  }elseif($status == 2){

  mysql_query("UPDATE `user` SET `rating`='".($zc_f_author['rating']-0.01)."' WHERE `id`='".$zc_f_author['id']."' limit 1");
  
    	 mysql_query("INSERT INTO `op`(
			`who`,
			`ho`,
			`text`,
      `time`,
      `read`,
      `sort`
			)VALUES(
      '".$zc_f_author['id']."',
      '".$user['id']."',
      'оценил [b]отрицательно[/b] ваш [url=/zc/f".$id."]файл[/url]!',
      '".time()."',
      '0',
      '3'
			)");

  }
  
  }
  
  }

  
  echo '<div class="post2">
  Рейтинг: ';

  $all = mysql_result(mysql_query('select count(`id`) from `zc_frating` where `f`= "'.$id.'" and `status` = "1"'),0)-mysql_result(mysql_query('select count(`id`) from `zc_frating` where  `f`= "'.$id.'" and`status` = "2"'),0);
    
  $zc_frating = mysql_fetch_array(mysql_query('select * from `zc_frating` where `f` = '.$id.' and `who` = "'.$user['id'].'"'));
  
  
  
  if($zc_frating == 0 && $user['id'] != $zc_f['author']) echo '<a href="/zc/f'.$id.'?v&amp;go=p">+</a> | <a href="/zc/f'.$id.'?v&amp;go=m">-</a>';

  echo ' ';

  if($all < 0) echo '<font color="red"><big><b>'.$all.'</b></big></font>';
  elseif($all == 0) echo '<font color="red"><big><b>0</b></big></font>';
  elseif($all > 0) echo '<font color="green"><big><b>'.$all.'</b></big></font>';

  
  echo ' (<font color="green">'.mysql_result(mysql_query('select count(`id`) from `zc_frating` where `f`= "'.$id.'" and `status` = "1"'),0).'</font>/<font color="red">'.mysql_result(mysql_query('select count(`id`) from `zc_frating` where  `f`= "'.$id.'" and`status` = "2"'),0).'</font>)<br>
  </div><div class="post2"><a href="/zc/fcom'.$id.'"><b>Комментарии</a> ('.mysql_result(mysql_query('select count(`id`) from `zc_fcom` where `f` = "'.$id.'"'),0).')
  </b></div></div>';
  
  break;

  case 'upf':

  $id = TextGuard($id);

$id = TextGuard($_GET['id']);

  $zc_f = mysql_fetch_array(mysql_query('select * from `zc_f` where `id` = '.$id.' and `status` = "0"'));

  $zc_pr = mysql_fetch_array(mysql_query('select * from `zc_pr` where `id` = '.$id.''));

  $zc_r = mysql_fetch_array(mysql_query('select * from `zc_r` where `id` = '.$zc_pr['r'].''));


 
  if(empty($id) or !is_numeric($id) or $zc_pr == 0 or $zc_r == 0 or $zc_f == 0){
  header('Location: /zc'); exit;
  }
  
  
  if($zc_f['rating'] > $user['rating']){
  header('Location: /zc/f'.$id.''); exit;
  }
  
  mysql_query("UPDATE `zc_f` SET `downs`='".($zc_f['downs']+1)."',`ldown`='".time()."' WHERE `id` = '".$id."' limit 1");

  header('Location: /modules/zc/files/'.$zc_f['file'].'');
  
  break;
  
  case 'moder':

$id = TextGuard($_GET['id']);
 
 $zc_r = mysql_fetch_array(mysql_query('select * from `zc_r` where `moder` = '.$user['id'].''));

  if($zc_r == 0){
  header('Location: /zc'); exit;
  }
       

  if(isset($_GET['ok0'])){
  $id = TextGuard($_GET['id']);
  
  $zc_f = mysql_fetch_array(mysql_query('select * from `zc_f` where `id` = "'.$id.'"'));
  
  if(empty($id) or $zc_f == 0){
  header('Location: /zc/moder'); exit;
  }
  mysql_query("UPDATE `zc_f` SET `status`='0' WHERE `id`='".$id."' limit 1");
  
       mysql_query("INSERT INTO `op`(
			`who`,
			`ho`,
			`text`,
      `time`,
      `read`,
      `sort`
			)VALUES(
      '".$zc_f['author']."',
      '".$user['id']."',
      'добавил ваш [url=/zc/f".$id."]файл[/url] в обменик!',
      '".time()."',
      '0',
      '3'
			)");
  
  header('Location: /zc/f'.$id.''); exit;
  }
  
  if(isset($_GET['ok1'])){
$id = TextGuard($_GET['id']);
  $zc_f = mysql_fetch_array(mysql_query('select * from `zc_f` where `id` = "'.$id.'"'));
  
  if(empty($id) or $zc_f == 0){
  header('Location: /zc/moder'); exit;
  }

  unlink('files/'.$zc_f['file'].'');
  mysql_query("DELETE FROM `zc_f` WHERE `id`='".$id."'");
  header('Location: /zc/moder'); exit;
  }

 $cop = 10;
  $ca = mysql_result(mysql_query("SELECT COUNT(*) FROM `zc_f` where `time` > '".(time()-((60*60)*24))."'"),0);
  $cp = ceil($ca/$cop);
  if(isset($_GET['p']) && is_numeric($_GET['p'])){
  $p = $_GET['p'];
  if($_GET['p']>$cp) $p = $cp;
  if($_GET['p']<1)$p = 1;
  }else{
  $p = 1;
  }
  $start = $p*$cop-$cop;
 echo '<div class="tegi"><a href="/zc">Назад</a> | Модерация файлов</div>';
      $zc_f = mysql_query('select * from `zc_f` where `status` = "1" order by `time` desc limit 10');
  while($zc_f2 = mysql_fetch_assoc($zc_f)){
  echo '<div class="post2">'.$zc_f2['name'].' (<a href="/modules/zc/files/'.$zc_f2['file'].'">'.$zc_f2['file'].'</a>) ('.round(filesize('files/'.$zc_f2['file'].'')/1024).' кб)<br>
  Описание: '.smiles(bbcode($zc_f2['about'])).'<br>
  Загрузил: '.ustatus($zc_f2['author']).' <a href="/us'.$zc_f2['author'].'">'.uname($zc_f2['author']).'</a> '.uaccess($zc_f2['author']).'</div><div class="cit">
  <a href="/zc/moder?ok0&amp;id='.$zc_f2['id'].'"><input type="submit" value="принять"/></a> <a href="/zc/moder?ok1&amp;id='.$zc_f2['id'].'"><input type="submit" value="отклонить"/></a></div>';
  }


  echo '</div><div class="spis">Стр. ';
  if($p-2>0) echo '<a href="/zc/moder?p=1"><<</a> ';
  if($p-1>0) echo '<a href="/zc/moder?p='.($p-1).'"><</a> ';

  if($p-3>0) echo '<a href="/zc/moder?p'.($p-3).'">'.($p-3).'</a> | ';
  if($p-2>0) echo '<a href="/zc/moder?p='.($p-2).'">'.($p-2).'</a> | ';  
  if($p-1>0) echo '<a href="/zc/moder?p='.($p-1).'">'.($p-1).'</a> | ';
  
  echo '<b>'.$p.'</b>';
  if($p+1<=$cp) echo ' | <a href="/zc/moder?p='.($p+1).'">'.($p+1).'</a>';
  if($p+2<=$cp) echo ' | <a href="/zc/moder?p='.($p+2).'">'.($p+2).'</a>';
  if($p+3<=$cp) echo ' | <a href="/zc/moder?p='.($p+3).'">'.($p+3).'</a>';

  if($p+1<=$cp) echo ' <a href="/zc/moder?p='.($p+1).'">></a>';
  if($p+2<=$cp) echo ' <a href="/zc/moder?p='.ceil($ca/$cop).'">>></a>';
  echo '</div>';
  
  break;
  
  case 'nr':

      
          echo "<a href='/'><div class='logo'><img src='/images/cornerhat.png' class='snoww'><span style='font-family: drunkC; font-size:22px;'>Загруз-центр</span></div> </a>";
	
echo '</div>';
echo '<div class="start">';
         /////////////////////////////////////////////////		 
$rek = mysql_query("SELECT * FROM `ads` WHERE `mode` = '1'");
echo '<div class="rek"><div class="rekl"><img src="/images/r.png" alt="*"> <a href="/bl?bl=rek">Купить рекламу</a></br>';
while($rek2 = mysql_fetch_array($rek))
{
echo '<img src="/images/r.png" alt="*"> <a href="'.$rek2['link'].'">'.$rek2['name'].'</a></br>';
}
echo '</div>';
echo '</div>';
include 'system/nvg.php'; 
if($user['id']) {
echo ' <div class="start">'; 
echo '<div class="s" style="border-bottom:none;">';
echo '<table style="width:100%" cellspacing="0" cellpadding="0">';
echo '<tbody><tr><td style="vertical-align:top;width:10%;">';
echo '<center>';
echo '<a href="/cab" title="Кабинет"><img class="ico" align="middle" src="/images/vcard.png" alt="*"></a></center></td>';
echo '<td style="vertical-align:top;width:10%;">';
echo '<center>';
echo '<a href="/privat/" title="Почта"><img class="ico" align="middle" src="/images/mail2.png" alt="*"></a>'; 
if($user['id']){
$c = mysql_result(mysql_query('select count(`id`) from `privat` where `ho` = "'.$user['id'].'" and `read` = "0"'),0);
if($c != 0) echo ' <b> (+'.$c.')</b>';
}
echo '</center></td>';
echo '<td style="vertical-align:top;width:10%;">';
echo '<center><a href="/op/" title="Оповещения"><img class="ico" align="middle" src="/images/warning.png" alt="*"></a>';
if($user['id']){
$c = mysql_result(mysql_query('select count(`id`) from `op` where `who` = "'.$user['id'].'" and `read` = "0"'),0);
if($c != 0) echo '<b> (+'.$c.')</b>';
}
echo '</center></td>';
echo '</tr></tbody></table>';
echo '</div>';
}
//////////////////////////////////////////////////////
   include '../../system/nvg.php';
   
  if(isset($_POST['submit'])){
  
  $name = TextGuard($_POST['name']);
 if(empty($name)) $err[] = 'Вы не ввели название раздела...';

  $about = TextGuard($_POST['about']);
 if(empty($about)) $err[] = 'Вы не ввели описание раздела...';

  $moder = TextGuard($_POST['moder']);
 if(empty($moder) or !is_numeric($moder)) $err[] = 'Вы не выбрали модератора раздела...';

  $moder_user = mysql_fetch_array(mysql_query('select * from `user` where `id` = "'.$moder.'"'));
  if($moder_user == 0) $err[] = 'Такого пользователя не существует...';

  if(!$err){
  
  		mysql_query("INSERT INTO `zc_r`(
			`name`,
			`about`,
			`moder`
			)VALUES(
			'".$name."',
			'".$about."',
			'".$moder."'
			)");
    
  header('Location: /zc'); exit;
  
  }else{
  echo '<div class="err">';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</div>';
  }
  
  }

 
  echo '<div class="post2">
  <form action="?m=nr" method="post">
  Название:<br><input name="name"/><br>
  Описание:<br><textarea name="about" style="width:98%;" rows="3"></textarea><br>
  Модератор:<br><input name="moder"/></div><div class="lst">
  <input type="submit" value="Добавить" name="submit"/>
  </form></div>';
    
  break;
  case 'red':
  
   $id = TextGuard($_GET['id']);
  $zc_r = mysql_fetch_array(mysql_query('select * from `zc_r` where `id` = '.$id.''));

  if(empty($id) or !is_numeric($id) or $zc_r == 0 or $user['status'] < 4){
  header('Location: /zc'); exit;
  }
 
          echo "<div class='tegi'><a href='/zc'>Назад</a> | Редактировать раздел</div>";
	

   
  if(isset($_POST['submit'])){

  $text  = TextGuard($_POST['text']);
  if(empty($text)) $err[] = 'Название осталось пустым...';

  $about  = TextGuard($_POST['about']);
  if(empty($about)) $err[] = 'Описание осталось пустым...';

  $moder = TextGuard($_POST['moder']);
 if(empty($moder) or !is_numeric($moder)) $err[] = 'Вы не выбрали модератора раздела...';

  $moder_user = mysql_fetch_array(mysql_query('select * from `user` where `id` = "'.$moder.'"'));
  if($moder_user == 0) $err[] = 'Такого пользователя не существует...';
  
  if(!$err){
  mysql_query("UPDATE `zc_r` SET `name`='".$text."',`moder`='".$moder."',`about`='".$about."' WHERE `id` = '".$id."' limit 1");
  header('Location: /zc'); exit;
  }else{
  echo '<div class="err">';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</div>';
  }
  }

  echo '<div class="post2">
  <form action="" method="post">
  Название:<br><input name="text" value="'.$zc_r['name'].'"/><br>
  Описание:<br><textarea name="about" style="width:98%;" rows="3">'.$zc_r['about'].'</textarea><br>
  Модератор ('.ustatus($zc_r['moder']).' <a href="/us'.$zc_r['moder'].'">'.uname($zc_r['moder']).'</a> '.uaccess($zc_r['moder']).') <input name="moder" value="'.$zc_r['moder'].'" size="2"/><br>

  <input type="submit" value="Сохранить" name="submit"/>
  </form></div></div>';

  
  break;
  case 'rdel':

 $id = TextGuard($_GET['id']);
  $zc_r = mysql_fetch_array(mysql_query('select * from `zc_r` where `id` = '.$id.''));

  if(empty($id) or !is_numeric($id) or $zc_r == 0 or $user['status'] < 4){
  header('Location: /zc'); exit;
  }

 
  $zc_pr = mysql_query('select * from `forum_pr` where `r` = "'.$id.'"');
  while($zc_pr2 = mysql_fetch_array($zc_pr)){
  mysql_query("DELETE FROM `zc_pr` WHERE `id` = '".$zc_pr2['id']."'");
  }

  $zc_f = mysql_query('select * from `forum_f` where `r` = "'.$id.'"');
  while($zc_f2 = mysql_fetch_array($zc_f)){
  unlink('files/'.$zc_f2['file'].'');
  mysql_query("DELETE FROM `zc_f` WHERE `id` = '".$zc_f2['id']."'");
  }

  mysql_query("DELETE FROM `zc_r` WHERE `id` = '$id'");

  header('Location: /zc/'); exit;
  break;
  case 'npr':

 $id = TextGuard($_GET['id']);
  $zc_r = mysql_fetch_array(mysql_query('select * from `zc_r` where `id` = '.$id.''));

  if(empty($id) or !is_numeric($id) or $zc_r == 0 or $user['status'] < 4){
  header('Location: /zc'); exit;
  }

 

  
      
          echo "<div class='tegi'>Загруз-центр</div>";
	
echo '</div>';

  
   
  if(isset($_POST['submit'])){
  
 $name = TextGuard($_POST['name']);
 if(empty($name)) $err[] = 'Вы не ввели название подраздела...';

  if(!$err){
  
  		mysql_query("INSERT INTO `zc_pr`(
  		`r`,
			`name`
			)VALUES(
			'".$id."',
			'".$name."'
			)");
    
  header('Location: /zc/r'.$id.''); exit;
  
  }else{
  echo '<div class="err">';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</div>';
  }
  
  }

 
  echo '<div class="post2">
  <form action="" method="post">
  Название:<br><input name="name"/><br>
  <input type="submit" value="Добавить" name="submit"/>
  </form></div></div>';
  break;
  case 'pred':

$id = TextGuard($_GET['id']);
 
 $zc_pr = mysql_fetch_array(mysql_query('select * from `zc_pr` where `id` = '.$id.''));

  if(empty($id) or !is_numeric($id) or $zc_pr == 0){
  header('Location: /zc'); exit;
  }

 

 

 
      
          echo "<div class='logo'><a href='/zc'>Назад</a> | Редактировать</div>";
	

  if(isset($_POST['submit'])){

  $text  = TextGuard($_POST['text']);
  if(empty($text)) $err[] = 'Название осталось пустым...';
  
  if(!$err){
  mysql_query("UPDATE `zc_pr` SET `name`='".$text."' WHERE `id` = '".$id."' limit 1");
  header('Location: /zc'); exit;
  }else{
  echo '<div class="pet">';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</div>';
  }
  }

  echo '<div class="post2">
  <form action="" method="post">
  Название:<br><input name="text" value="'.$zc_pr['name'].'"/><br>
  <input type="submit" value="Сохранить" name="submit"/>
  </form></div></div>';

  
  break;
  case 'prdel':

  $id = TextGuard($_GET['id']);
  $zc_r = mysql_fetch_array(mysql_query('select * from `zc_r` where `id` = '.$id.''));

 $zc_pr = mysql_fetch_array(mysql_query('select * from `zc_pr` where `id` = '.$id.''));
  if(empty($id) or !is_numeric($id) or $zc_r == 0 or $user['status'] < 4){
  header('Location: /zc'); exit;
  }

  
  $zc_f = mysql_query('select * from `forum_f` where `pr` = "'.$id.'"');
  while($zc_f2 = mysql_fetch_array($zc_f)){
  unlink('files/'.$zc_f2['file'].'');
  mysql_query("DELETE FROM `zc_f` WHERE `id` = '".$zc_f2['id']."'");
  }

  mysql_query("DELETE FROM `zc_pr` WHERE `id` = '$id'");

  header('Location: /zc/r'.$zc_pr['r'].''); exit;
  break;
  case 'fcom':
  $id = TextGuard($_GET['id']);

 $zc_f = mysql_fetch_array(mysql_query('select * from `zc_f` where `id` = '.$id.' and `status` = "0"'));

  $zc_pr = mysql_fetch_array(mysql_query('select * from `zc_pr` where `id` = '.$id.''));

  $zc_r = mysql_fetch_array(mysql_query('select * from `zc_r` where `id` = '.$zc_pr['r'].''));

 
  if(empty($id) or !is_numeric($id) or $zc_pr == 0 or $zc_r == 0 or $zc_f == 0){
  header('Location: /zc'); exit;
  }
  
  
      
		echo '<div class="tegi"><a href="/zc/f'.$id.'">'.$zc_f['name'].'</a> | Коментарии</div>';
		
        

   
 

  echo '<div class="glav"><form action="" method="post">
  Сообщение:<br><textarea name="text" style="width:98%;" rows="3"></textarea><br>
  <input type="submit" name="submit" value="Написать"/>
  </form></div>';

  if(isset($_POST['submit'])){
  
  $text = TextGuard($_POST['text']);
    
  if(empty($text)) $err[] = 'Сообщение осталось пустым...';
  $ncm = mysql_query("SELECT * FROM `zc_fcom` WHERE `who`='".$user['id']."' ORDER BY `time` desc");
  while($ncm2 = mysql_fetch_assoc($ncm)){  
  $ncm_timeout = $ncm2['time'];
  
    if((time()-$ncm_timeout) < 5) $err[] = 'Писать можно только раз в 5 секунд...';

  } 
  
         
    
  $ncm_rep = mysql_fetch_array(mysql_query('select * from `zc_fcom` where `who` = "'.$user['id'].'" and `text` = "'.$text.'"'));
  
  if($ncm_rep != 0) $err[] = 'Вы уже писали подобное сообщение...';

  if(!$err){

			mysql_query("INSERT INTO `zc_fcom`(
			`f`,
			`who`,
			`text`,
            `time`
		)VALUES(
			'".$id."',
			'".$user['id']."',
			'".$text."',
			'".time()."'
			)");

    	 mysql_query("INSERT INTO `op`(
			`who`,
			`ho`,
			`text`,
      `time`,
      `read`,
      `sort`
			)VALUES(
      '".$zc_f['author']."',
      '".$user['id']."',
      'написал [url=/zc/fcom".$id."]комментарий[/url] к вашему [url=/zc/f".$id."]файлу[/url]!',
      '".time()."',
      '0',
      '3'
			)");

  header('Location: /zc/fcom'.$id.''); exit;
  }else{
  echo '<div class="err"><b>';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</b></div>';  
  }
  }

  $cop = 10;
  $ca = mysql_result(mysql_query("SELECT COUNT(*) FROM `zc_fcom` where `f` = '".$id."'"),0);
  $cp = ceil($ca/$cop);
  if(isset($_GET['p']) && is_numeric($_GET['p']) && $ca != 0){
  $p = $_GET['p'];
  if($_GET['p']>$cp) $p = $cp;
  if($_GET['p']<1)$p = 1;
  }else{
  $p = 1;
  }
  $start = $p*$cop-$cop;
  
  if($ca != 0){
  $zc_fcom = mysql_query("SELECT * FROM `zc_fcom` where `f` = '".$id."' ORDER BY `id` DESC LIMIT $start,$cop");
  while($zc_fcom2 = mysql_fetch_assoc($zc_fcom)){
  echo '<div class="post2">'.ustatus($zc_fcom2['who']).' <a href="/us'.$zc_fcom2['who'].'">'.uname($zc_fcom2['who']).'</a> '.uaccess($zc_fcom2['who']).' ('.times($zc_fcom2['time']).')';
  
  if($user['status'] >= 1) echo ' [<a href="/zc/fcom'.$id.'?p='.$p.'&amp;dp&amp;pid='.$zc_fcom2['id'].'">уд</a>]';
  
  echo '<br>'.smiles(bbcode($zc_fcom2['text'])).'</div>';
  }}

  if(isset($_GET['dp']) && $user['status'] >= 1){
  $pid = TextGuard($_GET['pid']);
  
  $posts = mysql_fetch_array(mysql_query('select * from `zc_fcom` where `id` = "'.$pid.'" limit 1'));
  if($posts == 0 or empty($pid) or !is_numeric($pid)){
  header('Location: /zc/fcom'.$id.'?p='.$p.''); exit;
  }
  
  mysql_query("DELETE FROM `zc_fcom` WHERE `id`='".$pid."'");
  header('Location: /zc/fcom'.$id.'?p='.$p.''); exit;
  }


  echo '</div><div class="spis">Стр. ';
  if($p-2>0) echo '<a href="/zc/fcom'.$id.'?p=1"><<</a> ';
  if($p-1>0) echo '<a href="/zc/fcom'.$id.'?p='.($p-1).'"><</a> ';

  if($p-3>0) echo '<a href="/zc/fcom'.$id.'?p'.($p-3).'">'.($p-3).'</a> | ';
  if($p-2>0) echo '<a href="/zc/fcom'.$id.'?p='.($p-2).'">'.($p-2).'</a> | ';  
  if($p-1>0) echo '<a href="/zc/fcom'.$id.'?p='.($p-1).'">'.($p-1).'</a> | ';
  
  echo '<b>'.$p.'</b>';
  if($p+1<=$cp) echo ' | <a href="/zc/fcom'.$id.'?p='.($p+1).'">'.($p+1).'</a>';
  if($p+2<=$cp) echo ' | <a href="/zc/fcom'.$id.'?p='.($p+2).'">'.($p+2).'</a>';
  if($p+3<=$cp) echo ' | <a href="/zc/fcom'.$id.'?p='.($p+3).'">'.($p+3).'</a>';

  if($p+1<=$cp) echo ' <a href="/zc/fcom'.$id.'?p='.($p+1).'">></a>';
  if($p+2<=$cp) echo ' <a href="/zc/fcom'.$id.'?p='.ceil($ca/$cop).'">>></a>';
  
          echo '</div>';
 
          break;
  
  
          case 'fe':
  
          $id = TextGuard($id);

          $zc_f = mysql_fetch_array(mysql_query('select * from `zc_f` where `id` = '.$id.' and `status` = "0"'));

          $zc_pr = mysql_fetch_array(mysql_query('select * from `zc_pr` where `id` = '.$zc_f['pr'].''));

          $zc_r = mysql_fetch_array(mysql_query('select * from `zc_r` where `id` = '.$zc_f['r'].''));

          if(empty($id) or !is_numeric($id) or $zc_pr == 0 or $zc_r == 0 or $zc_f == 0)
          {
  
          header('Location: /zc'); exit;
  
          }
  
          echo '<div class="verh"><a href="/zc"><b>Загруз-Центр</a> | <a href="/zc/r'.$zc_r['id'].'">'.$zc_r['name'].'</a> | <a href="/zc/pr'.$zc_pr['id'].'">'.$zc_pr['name'].'</a> | <a href="/zc/f'.$id.'">'.$zc_f['name'].'</a></b></div>';
          include '../../system/nvg.php';
          break;
  
  
          }
  
          
          include '../../system/footer.php';

?>
