<?php

/****************************************/
// ИНФОРМАЦИЯ:
// ==== Форум: LogicBoard
// ==== Автор: Никита Курдин (ShapeShifter)
// ==== Copyright © Никита Курдин Игоревич 2011
// ==== Данный код защищен авторскими правами
// ==== Официальный сайт: http://logicboard.ru

/****************************************/

if (! defined('LogicBoard_ADMIN') )
{
	@include '../../logs/save_log.php';
	exit ( "Error, wrong way to file.<br><a href=\"/\">Go to main</a>." );
}

$link_speddbar = "<a href=\"".$redirect_url."?do=logs\">Журнал логов</a>|MySQL ошибки";
$control_center->header("Журнал логов", $link_speddbar);
$onl_location = "Журнал логов &raquo; MySQL ошибки";

$control_center->errors = array ();

$log_result = 20;

if (isset ( $_REQUEST['page'] ))
	$page = intval ( $_GET['page'] );
else
	$page = 0;

if ($page < 0)
	$page = 0;

if ($page)
{
	$page = $page - 1;
	$page = $page * $log_result;
}

$i = $page;

if (isset($_POST['del_checked']))
{
	if (!$_POST['secret_key'] OR $_POST['secret_key'] != $secret_key)
	{
		exit ( "Error, wrong secret key.<br><a href=\"/\">Go to main</a>." );
	}

	if ($_POST['act'] == 1)
	{
		$selected = $_POST['selected_all'];
		if ($selected AND control_center_admins($member_cca['logs']['mysqldel']))
		{
			$j = 0;
			foreach	($selected as $id)
			{
				$j ++;
				$id = intval($id);
				$DB->delete("id = '{$id}'", "logs_mysql");
			}

			$info = "<font color=red>Удаление</font> логов MySQL ошибок (".$j.")";
			$DB->insert("member_name = '{$member_id['name']}', date = '{$time}', ip = '{$_IP}', module = '{$do}', op = '{$op}', info = '{$info}'", "logs_actions_cc");

			header( "Location: {$redirect_url}?do=logs&op=mysql_errors" );
            exit();
		}
        elseif(!control_center_admins($member_cca['logs']['mysqldel']))
        {
            $control_center->errors[] = "У вас недостаточно прав, чтобы удалять логи MySQL ошибок.";
			$control_center->errors_title = "Доступ закры.";
        }
		else
		{
			$control_center->errors[] = "Вы не выбрали логи для удаления.";
			$control_center->errors_title = "Ошибка!";
		}
	}
	else
	{
		$control_center->errors[] = "Вы не выбрали действие.";
		$control_center->errors_title = "Ошибка!";
	}
}

if (isset($_REQUEST['where_search']) AND isset($_REQUEST['word']))
{
	require LB_CLASS . '/safehtml.php';
	$safehtml = new safehtml( );
	$ws = $DB->addslashes( $safehtml->parse( trim( $_REQUEST['where_search'] ) ) );
	$word = $DB->addslashes( $safehtml->parse( trim( $_REQUEST['word'] ) ) );

	unset ($safehtml);
	$link_nav = $redirect_url."?do=logs&op=mysql_errors&where_search=".$ws."&word=".$word."&page=";
}
else
{
	$word = "";
	$ws = "";
	$link_nav = $redirect_url."?do=logs&op=mysql_errors&page=";
}

if ($word AND $ws)
{
	require LB_CLASS . '/sql_search.php';
	$sql_search = new SQL_Search;

	if ($ws == "date")
	{
		$word_s = explode ("|", $word);
		$word_s[0] = strtotime ($word_s[0]);
		if ($word_s[1])
			$word_s[1] = strtotime($word_s[1]);
		else
			$word_s[1] = time ();
		$where = "date >= '".$word_s[0]."' AND date <= '".$word_s[1]."'";
	}
	elseif ($ws == "ip")
	{
		$where = $sql_search->regexp_ip ($word);
	}

	unset ($sql_search);

}
else
	$where = "";

$control_center->message();

echo <<<HTML

<script language='JavaScript' type="text/javascript">
<!--
function checkbox_all() {
    var frm = document.logs_box;
    for (var i=0;i<frm.elements.length;i++) {
        var elmnt = frm.elements[i];
        if (elmnt.type=='checkbox') {
            if(frm.master_box.checked == true){ elmnt.checked=false; }
            else{ elmnt.checked=true; }
        }
    }
    if(frm.master_box.checked == true){ frm.master_box.checked = false; }
    else{ frm.master_box.checked = true; }
}

-->

  $(document).ready(function(){
    
    $("#show_ip").click(function () {
      $("div #date_info").hide(300);
      $("div #ip_info").show(500);
    });
    
    $("#show_date").click(function () {
      $("div #ip_info").hide(300);  
      $("div #date_info").show(500);
    });

  }); 
  
</script>

                    <div class="headerGray">
                        <div class="headerGrayL"></div>
                        <div class="headerGrayR"></div>
                        <div class="headerGrayBg">MySQL ошибки</div>
                    </div>
		<form action="" method="post" name="logs_box">
		<table class="colorTable">
                        <tr>
				<td align=left><h6>IP</h6></td>
				<td align=left><h6>Страница</h6></td>
				<td align=center><h6>Дата</h6></td>
				<td align=center><h6>№ ошибки</h6></td>
				<td align=center><h6>Информация</h6></td>
				<td align=right><input type="checkbox" name="master_box" title="Отметить все" onclick="javascript:checkbox_all()"></td>
                        </tr>
HTML;

$DB->select( "*", "logs_mysql", $where, "ORDER BY date DESC LIMIT ".$page.", ".$log_result."" );

while ( $row = $DB->get_row() )
{
	$i++;

	if ($i%2)
		$class = "appLine";
	else
		$class = "appLine dark";

	$row['date'] = formatdate( $row['date'] );
	$info_user = unserialize($row['info_user']);
    
	if( utf8_strlen( $info_user['file'] ) > 60 )
        $info_user['file'] = utf8_substr( $info_user['file'], 0, 60 ) . "...";

echo <<<HTML
                        <tr class="{$class}">
                        	<td align=left class="blueHeader">{$row['ip']}</td>
                        	<td align=left>{$info_user['file']}</td>
                       	 	<td align=center>{$row['date']}</td>
                       	 	<td align=center>{$row['error_number']}</td>
                        	<td align=center><a href="#" onclick="window.open('{$redirect_url}?do=infopage&op=logs&type=mysql_errors&id={$row['id']}','MySQL ошибки','width=600,height=670,toolbar=1,location=0,scrollbars=1'); return false;" title="Просмотреть подробную информацию."><img src="{$redirect_url}template/images/info_link.gif" alt="Подробнее..." /></a></td>
				<td align=right><input type="checkbox" name="selected_all[]" value="{$row['id']}" /></td>
                        </tr>
HTML;

}

echo <<<HTML
		</table>
	        <div class="clear" style="height:10px;"></div>

		<table><tr><td align=right>
		<select name="act">
		<option value="0">Выберите действие</option>
		<option value="1">- Удалить</option>
		</select>
		<input type="submit" name="del_checked" value="Выполнить">
		<input type="hidden" name="secret_key" value="{$secret_key}" />
		</td></tr>
		</table>
		</form>

		<div class="clear" style="height:10px;"></div>
HTML;

if ($i > 0)
{
	$nav = $DB->one_select( "COUNT(*) as count", "logs_mysql", $where);
	$nav_all = $nav['count'];
	$DB->free($nav);
	if ($nav_all > $log_result)
	{
		include LB_CLASS.'/navigation.php';
		$navigation = new navigation;
		$navigation->creat($page, $nav_all, $log_result, $link_nav, "3");

echo <<<HTML
<table>
<tr><td align=center style="padding:8px;"><h6>{$navigation->result}</6></td></tr>
</table>
HTML;
		unset($navigation);
	}
}

$word = htmlspecialchars($word);

$where_s = array();
$where_s[0] = "ip";
$where_s[1] = "date";

$j = 0;
$where_s2 = array();
foreach ($where_s as $where_ws)
{
	if ($where_ws == $ws)
		$where_s2[$j] = "selected";
	else
		$where_s2[$j] = "";
	$j ++;
}

echo <<<HTML
<form action="{$link_nav}1" method="post" name="logs">
<table width="100%" border=0>
<tr>
<td align=left width="350">Поиск: <input type="text" name="word" value="{$word}" class="inputText" style="width:300px" /></td>
<td align=left style="padding-left:5px;"><select name="where_search">
<option value="ip" id="show_ip" {$where_s2[0]}>IP</option>
<option value="date" id="show_date" {$where_s2[1]}>Дата</option>
</select> <input type="submit" name="search" value="Найти" /></td>
</tr>
<tr><td colspan=2 align=left>
<div class="clear" style="height:10px;"></div>
<div id="ip_info">
<font class="smalltext">
Поиск по IP: 255.255.255.255; 255.255.*; 255.*.255.255
</font>
</div>
<div id="date_info" style="display:none;">
<font class="smalltext">
Поиск по дате: 21-03-2010 10:33 | 25-03-2010 (с | по); 21-03-2010
</font>
</div>
</td></tr>
</table>
</form>
HTML;

?>