<?php

  include '../../system/core.php';
  $_title = 'Доска позора';
  include '../../system/header.php';

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

	
  switch($_GET['m']){
  
  #Главная
  default:
  
  
  
  
  
  
  
  echo '<div class="tegi"><b>Доска позора</b></div>';
/////////////////////////////////////////////////		 
if($user['status'] >= 2){
  echo '<div class="post2"><a href="?m=add">+ Добавить мошенника</a>';
 echo '</div>';
}
 
  
  
  
  $cop = $user['on_page'];
  $ca = mysql_result(mysql_query("SELECT COUNT(*) FROM `ced`"),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;

  $news = mysql_query("SELECT * FROM `ced` where `mode` = '1' ORDER BY `time` DESC LIMIT $start,$cop");
  while($news2 = mysql_fetch_assoc($news)){
  echo '<div class="mist"><b>Логин:</b> '.ustatus($news2['login']).' <a href="/us'.$news2['login'].'">'.uname($news2['login']).'</a> '.uaccess($news2['login']).'<br><b>Причина:</b> '.smiles(bbcode($news2['text'])).'<br><b>Имя:</b> '.smiles(bbcode($news2['name'])).'<br><b>Доп. Инфо.:</b> '.smiles(bbcode($news2['din'])).'<br>
  <b>WMID:</b> '.smiles(bbcode($news2['wmid'])).'<br>
  Добавил: '.ustatus($news2['author']).' <a href="/us'.$news2['author'].'">'.uname($news2['author']).'</a> '.uaccess($news2['author']).' ('.times($news2['time']).')';
  
  if($user['status'] >= 4) echo ' [<a href="?m=del&amp;id='.$news2['id'].'">уд</a>] [<a href="?m=edit&amp;id='.$news2['id'].'">ред</a>]';
  
  echo '</div></div>';
  }

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

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

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

  break;
  
  case 'del':
  
 if($user['status'] >= 4){
  
  $id = TextGuard($_GET['id']);
  $news = mysql_fetch_array(mysql_query('select * from `ced` where `id` = "'.$id.'" limit 1'));

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

  $news_com = mysql_query('select * from `ced_com` where `ced` = "'.$id.'"');
  while($news_com2 = mysql_fetch_array($news_com)){
  mysql_query("DELETE FROM `ced_com` WHERE `id` = '".$news_com2['id']."'");
  }

  mysql_query("DELETE FROM `ced` WHERE `id` = '$id'");
  
  header('Location: /ced'); exit;
}else{
   header('Location: /ced'); exit;
  }

  break;
  case 'add':
if($user['status'] >= 2){


  echo '<div class="tegi"><a href="/ced"><b>Доска позора</a> | Добавить</b></div>';
include '../../system/nvg.php';
  if(isset($_POST['submit'])){
  
  $text = TextGuard($_POST['text']);
  if(empty($text)) $err[] = 'Сообщение осталось пустым...';
  $login2 = TextGuard($_POST['login2']);
  if(empty($login2)) $err[] = 'ID мошенника не введен...';
  $name= TextGuard($_POST['name']);
  if(empty($name)) $err[] = 'Имя осталось пустым...';
  $wmid= TextGuard($_POST['wmid']);
  if(empty($wmid)) $err[] = 'wmid незаполнен...';
  $din= TextGuard($_POST['din']);
  if(empty($din)) $err[] = 'Незаполнено...';
  
  if(!$err){
  		mysql_query("INSERT INTO `ced`(
			`author`,
			`text`,
			`login2`,
			`name`,
			`din`,
			`wmid`,
      `time`,
      `mode`
 			)VALUES(
			'".$user['id']."',
			'".$text."',
			'".$login2."',
			'".$name."',
			'".$din."',
			
			'".$wmid."',
			'".time()."',
			'0'
			)"); 
			
			    $ar = mysql_query("SELECT * FROM `user` WHERE `status` > '1'");
  while($ar2 = mysql_fetch_assoc($ar)){
 
     	 mysql_query("INSERT INTO `op`(
			`who`,
			`ho`,
			`text`,
      `time`,
      `read`
			)VALUES(
      '".$ar2['id']."',
      '".$user['id']."',
      'Хочет добавить [url=/admin?m=ne]мошенника[/url]',
      '".time()."',
      '0'
			)");
			
}
  header('Location: /ced'); exit;
  }else{
  echo '<div class="pet">';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</div>';
  }
  }

  echo '<div class="mist">
  <form action="/ced?m=add" method="post">
  Имя:<br><textarea style="width:98%" name="name" rows="3"></textarea><br>
  Причина:<br><textarea style="width:98%" name="text" rows="3"></textarea><br>
  ID (мошенника на сайте):<br><textarea style="width:98%" name="login2" rows="3"></textarea><br>
  Доп. Инфо.:<br><textarea style="width:98%" name="din" rows="3"></textarea><br>
  WMID:<br><textarea style="width:98%" name="wmid" rows="3"></textarea><br>
  <input type="submit" value="Добавить" name="submit"/>
  </form></div>';
 } else {
header('Location: /ced'); exit;
}
  break;
  case 'edit':
  
 if($user['status'] >= 4){


  $id = TextGuard($_GET['id']);
  $news = mysql_fetch_array(mysql_query('select * from `ced` where `id` = "'.$id.'" limit 1'));

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

  echo '<div class="tegi"><a href="/ced"><b>Доска позора</a> | Редактировать</b></div>';
include '../../system/nvg.php';
  if(isset($_POST['submit'])){
  
  $text = TextGuard($_POST['text']);
  if(empty($text)) $err[] = 'Сообщение осталось пустым...';
  
  if(!$err){
  mysql_query("UPDATE `ced` SET `text`='".$text."' WHERE `id` = '".$id."' limit 1");
  header('Location: /ced'); exit;
  }else{
  echo '<div class="pet">';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</div>';
  }
  }

  echo '<div class="mist">
  <form action="/ced?m=edit&amp;id='.$id.'" method="post">
  Текст:<br><textarea style="width:98%" name="text" rows="3">'.$news['text'].'</textarea><br>
  <input type="submit" value="Добавить" name="submit"/>
  </form></div>';
} else {
header('Location: /ced'); exit;
}
  break;
  
  
  }

  

  include '../../system/footer.php';

?>