<?php
/***************************************************************************
 *                              obmen.php
 *                            -------------------
 *  Полнлценный модуль Файлобменника под phpBB-WAP
 *	Автор модуля: SatanHell
 *  2011 год
 ***************************************************************************/

define('IN_PHPBB', 1);
$no_page_header = TRUE;
$phpbb_root_path = './../';

if( !empty($setmodules) )
{
	$filename = basename(__FILE__);
$module['Файлобменник']['Управление каталогами'] = $filename;

	return;
}

require($phpbb_root_path . 'extension.inc');
require('./pagestart.' . $phpEx);
include($phpbb_root_path . 'includes/functions_obmen.'.$phpEx);
$id = isset($_REQUEST['id']) ? abs(intval($_REQUEST['id'])) : false;
$mod = isset($_REQUEST['mod']) ? trim($_REQUEST['mod']) : false;

switch($mod)
{
case 'catalog':
	$sql = "SELECT*FROM `" . UPLOAD_RAZD_TABLE . "` WHERE `raz_id`='".$id."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_razd information', '', __LINE__, __FILE__, $sql);
	}
if(!mysql_num_rows($result))
    {
        message_die(GENERAL_MESSAGE, 'Раздел не существует!');
    }
$catalog = $db->sql_fetchrow($result);
require('./page_header_admin.'.$phpEx);
$total = mysql_result(mysql_query("SELECT COUNT(*) FROM `" . UPLOAD_CATS_TABLE . "` WHERE `cat_rid`='".$catalog['raz_id']."'"),0);
echo '<table width="100%" cellpadding="4" cellspacing="0" border="0" class="forumline">
<tr><td class="catSides"><span class="cattitle">Категории файлобменника</span></td></tr>';
if($total)
{
	$sql = "SELECT * FROM `" . UPLOAD_CATS_TABLE . "` WHERE `cat_rid`='".$catalog['raz_id']."' ORDER BY `cat_name` ASC";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_cats information', '', __LINE__, __FILE__, $sql);
	}
while ($categories = $db->sql_fetchrow($result))
	{
		$categories_link = append_sid("?mod=editcat&amp;id=".$categories['cat_id']);
		$categories_name = text_obmen($categories['cat_name']);
	$delcat = append_sid("?mod=delcat&amp;id=".$categories['cat_id']);
echo '<tr><td class="row1"><a href="'.$categories_link.'">'.$categories_name.'</a> [<a href="'.$delcat.'">Уд</a>]</td></tr>'; 
	}
	}
else
{
echo '<tr><td class="row1">Категорий нет</td></tr>';
}
$addcat = append_sid("?mod=addcat&amp;id=".$catalog['raz_id']);
echo '</table><p><a href="'.$addcat.'">Добавить категорию</a><br/>
<a href="'.append_sid('index.'.$phpEx.'?pane=left').'">Вернуться на главную страницу администраторского раздела</a></p>';
break;

case 'addcat':
	$sql = "SELECT*FROM `" . UPLOAD_RAZD_TABLE . "` WHERE `raz_id`='".$id."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_razd information', '', __LINE__, __FILE__, $sql);
	}
if(!mysql_num_rows($result))
    {
        message_die(GENERAL_MESSAGE, 'Раздел не существует!');
    }
$razdel = $db->sql_fetchrow($result);
if(isset($_POST['submit']))
{
if(empty($_POST['name']))
	{
        message_die(GENERAL_MESSAGE, 'Вы не ввели название категории!');		
	}
$name = mysql_real_escape_string(trim($_POST['name']));	
$description = mysql_real_escape_string(trim($_POST['description']));	
if(!$razdel['raz_ero'])
	{
		$ero = abs(intval($_POST['ero']));	
	}
	else
	{
		$ero = 0;
	}
if(!$razdel['raz_login'])
	{		
		$login = abs(intval($_POST['login']));
	}
	else
	{
		$login = 1;
	}
	$sql = "INSERT INTO `" . UPLOAD_CATS_TABLE . "` SET `cat_rid`='".$razdel['raz_id']."', `cat_name`='".$name."', `cat_description`='".$description."', `cat_ero`='".$ero."', `cat_login`='".$login."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_cats information', '', __LINE__, __FILE__, $sql);
	}
 message_die(GENERAL_MESSAGE, 'Категория успешно добавлена!');	
}
require('./page_header_admin.'.$phpEx);	
$addcat = append_sid("?mod=addcat&amp;id=".$razdel['raz_id']);
echo '<table width="100%" cellpadding="4" cellspacing="0" border="0" class="forumline">
<tr><td class="catSides"><span class="cattitle">Добавление категории в '.text_obmen($razdel['raz_name']).'</span></td></tr>';
echo '<form action="'.$addcat.'" method="post" />';

echo'<tr>
<td class="row1">Название категории:<br/><input type="text" name="name"/></td>
</tr>
<tr>
<td class="row1">
Описание: <br/>
<textarea name="description" rows="5" cols="15" style="width: 235px;"></textarea>
</td>
</tr>';

if(!$razdel['raz_ero'])
{
echo'<tr>
<td class="row1">
Категория для взрослых: <br/>
<select name="ero">
<option value="0">Нет</option>
<option value="1">Да</option>
</select>
</td>
</tr>';
}
if(!$razdel['raz_login'])
{
echo'<tr>
<td class="row1">
Закрыть от гостей: <br/>
<select name="login">
<option value="0">Нет</option>
<option value="1">Да</option>
</select>
</td>
</tr>';
}
echo '<tr>
<td class="row1">
<input type="submit" name="submit" value="Добавить"/></form></td>
</tr>';
break;

case 'editcat':
	$sql = "SELECT*FROM `" . UPLOAD_CATS_TABLE . "` WHERE `cat_id`='".$id."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_cats information', '', __LINE__, __FILE__, $sql);
	}
if(!mysql_num_rows($result))
    {
        message_die(GENERAL_MESSAGE, 'Категория не существует!');
    }
$catalog = $db->sql_fetchrow($result);
	$sql = "SELECT*FROM `" . UPLOAD_RAZD_TABLE . "` WHERE `raz_id`='".$catalog['cat_id']."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_razd information', '', __LINE__, __FILE__, $sql);
	}
$razdel = $db->sql_fetchrow($result);
if(isset($_POST['submit']))
{
if(empty($_POST['name']))
	{
        message_die(GENERAL_MESSAGE, 'Вы не ввели название категории!');		
	}
$name = mysql_real_escape_string(trim($_POST['name']));	
$description = mysql_real_escape_string(trim($_POST['description']));	
if(!$razdel['raz_ero'])
	{
		$ero = abs(intval($_POST['ero']));	
	}
	else
	{
		$ero = 0;
	}
if(!$razdel['raz_login'])
	{		
		$login = abs(intval($_POST['login']));
	}
	else
	{
		$login = 1;
	}
	$sql = "UPDATE `" . UPLOAD_CATS_TABLE . "` SET `cat_name`='".$name."', `cat_description`='".$description."', `cat_ero`='".$ero."', `cat_login`='".$login."' WHERE `cat_id`='".$catalog['cat_id']."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_cats information', '', __LINE__, __FILE__, $sql);
	}
 message_die(GENERAL_MESSAGE, 'Категория отредактированна!');	
}
require('./page_header_admin.'.$phpEx);	
$addcat = append_sid("?mod=editcat&amp;id=".$catalog['cat_id']);
echo '<table width="100%" cellpadding="4" cellspacing="0" border="0" class="forumline">
<tr><td class="catSides"><span class="cattitle">Редактирование категории '.text_obmen($catalog['cat_name']).'</span></td></tr>';
echo '<form action="'.$addcat.'" method="post" />';

echo'<tr>
<td class="row1">Название категории:<br/><input type="text" name="name" value="'.text_obmen_form($catalog['cat_name']).'" /></td>
</tr>
<tr>
<td class="row1">
Описание: <br/>
<textarea name="description" rows="5" cols="15" style="width: 235px;">'.text_obmen_form($catalog['cat_description']).'</textarea>
</td>
</tr>';

if(!$razdel['raz_ero'])
{
echo'<tr>
<td class="row1">
Категория для взрослых: <br/>
<select name="ero">
<option value="0"'.($catalog['cat_ero']==0 ? ' selected="selected"' : '').'>Нет</option>
<option value="1"'.($catalog['cat_ero']==1 ? ' selected="selected"' : '').'>Да</option>
</select>
</td>
</tr>';
}
if(!$razdel['raz_login'])
{
echo'<tr>
<td class="row1">
Закрыть от гостей: <br/>
<select name="login">
<option value="0"'.($catalog['cat_login']==0 ? ' selected="selected"' : '').'>Нет</option>
<option value="1"'.($catalog['cat_login']==1 ? ' selected="selected"' : '').'>Да</option>
</select>
</td>
</tr>';
}
echo '<tr>
<td class="row1">
<input type="submit" name="submit" value="Изменить"/></form></td>
</tr>';
break;

case 'delcat':
	$sql = "SELECT*FROM `" . UPLOAD_CATS_TABLE . "` WHERE `cat_id`='".$id."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_cats information', '', __LINE__, __FILE__, $sql);
	}
if(!mysql_num_rows($result))
    {
        message_die(GENERAL_MESSAGE, 'Категория не существует!');
    }
$catalog = $db->sql_fetchrow($result);
	if(isset($_POST['no']))
{
	$URL = append_sid("?mod=catalog&id=".$catalog['cat_rid']);
			header ("Location: $URL");	
}
if(isset($_POST['yes']))
{
	$sql = "SELECT*FROM `" . UPLOAD_FILES_TABLE . "` WHERE `file_cid`='".$catalog['cat_id']."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_files information', '', __LINE__, __FILE__, $sql);
	}
while($last = $db->sql_fetchrow($result))
{
unlink('../upload/'.$last['file_url']);

if(!empty($last['file_screen']))
{
unlink('../screen/'.$last['file_screen']);
}
mysql_query("DELETE FROM `" . UPLOAD_COMMENTS_TABLE . "` WHERE `comment_fid`='".$last['file_id']."'");
mysql_query("DELETE FROM `" . UPLOAD_ABUSE_TABLE . "` WHERE `abuse_fid`='".$last['file_id']."'");
mysql_query("DELETE FROM `" . UPLOAD_RATING_TABLE . "` WHERE `rating_fid`='".$last['file_id']."'");
mysql_query("UPDATE `" . USERS_TABLE . "` SET `upload_count`=`upload_count`-1, `upload_size`=`upload_size`-".$last['file_size']." WHERE `user_id` = '".$last['file_user_id']."'");
}
$sql = "DELETE FROM `" . UPLOAD_FILES_TABLE . "` WHERE `file_cid`='".$catalog['cat_id']."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_files information', '', __LINE__, __FILE__, $sql);
	}

$sql = "UPDATE `" . UPLOAD_RAZD_TABLE . "` SET `raz_count`=`raz_count`-".$catalog['cat_count'].", `raz_size`=`raz_size`-".$catalog['cat_size']." WHERE `raz_id`='".$catalog['cat_rid']."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get users information', '', __LINE__, __FILE__, $sql);
	}

$sql = "DELETE FROM `" . UPLOAD_CATS_TABLE . "` WHERE `cat_id`='".$catalog['cat_id']."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_cats information', '', __LINE__, __FILE__, $sql);
	}
$sql = "OPTIMIZE TABLE `" . UPLOAD_FILES_TABLE . "`";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_razd information', '', __LINE__, __FILE__, $sql);
	}	
$sql = "OPTIMIZE TABLE `" . UPLOAD_COMMENTS_TABLE . "`";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_comments information', '', __LINE__, __FILE__, $sql);
	}	
$sql = "OPTIMIZE TABLE `" . UPLOAD_CATS_TABLE . "`";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_razd information', '', __LINE__, __FILE__, $sql);
	}	
$sql = "OPTIMIZE TABLE `" . UPLOAD_ABUSE_TABLE . "`";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_comments information', '', __LINE__, __FILE__, $sql);
	}
$sql = "OPTIMIZE TABLE `" . UPLOAD_RATING_TABLE . "`";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_comments information', '', __LINE__, __FILE__, $sql);
	}		
	        message_die(GENERAL_MESSAGE, 'Категория удалена!');	
}
$delete = append_sid("?mod=delcat&id=".$catalog['cat_id']);
message_die(GENERAL_MESSAGE, 'Вы уверены, что хотите удалить эту категорию?<br/><form action="'.$delete.'" method="post" />
<input type="submit" name="yes" value="Да" /> <input type="submit" name="no" value="Нет" />
</form>');	
break;

case 'addraz':
if(isset($_POST['submit']))
{
if(empty($_POST['name']))
	{
        message_die(GENERAL_MESSAGE, 'Вы не ввели название раздела!');		
	}
if(empty($_POST['ext']))
	{
        message_die(GENERAL_MESSAGE, 'Вы не ввели допустимые расширения!');		
	}	
$name = mysql_real_escape_string(trim($_POST['name']));	
$description = mysql_real_escape_string(trim($_POST['description']));
$ext = mysql_real_escape_string(trim($_POST['ext']));
$ero = abs(intval($_POST['ero']));
$points = abs(intval($_POST['points']));
$login = abs(intval($_POST['login']));
$level = abs(intval($_POST['level']));

	$sql = "INSERT INTO `" . UPLOAD_RAZD_TABLE . "` SET `raz_name`='".$name."', `raz_description`='".$description."', `raz_ext`='".$ext."', `raz_points`='".$points."', `raz_ero`='".$ero."', `raz_login`='".$login."', `raz_level`='".$level."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_razd information', '', __LINE__, __FILE__, $sql);
	}
 message_die(GENERAL_MESSAGE, 'Раздел добавлен!');	
}
require('./page_header_admin.'.$phpEx);	
$addraz = append_sid("?mod=addraz");
echo '<table width="100%" cellpadding="4" cellspacing="0" border="0" class="forumline">
<tr><td class="catSides"><span class="cattitle">Добавление раздела</span></td></tr>
<form action="'.$addraz.'" method="post" />
<tr>
<td class="row1">Название раздела:<br/><input type="text" name="name"/></td>
</tr>
<tr>
<td class="row1">
Описание: <br/>
<textarea name="description" rows="5" cols="15" style="width: 235px;"></textarea>
</td>
</tr>
<tr>
<td class="row1">
Допустимые расширения через запятую, например ext, ext, ext: <br/>
<input type="text" name="ext" />
</td>
</tr>
<tr>
<td class="row1">
Сколько монет выдавать за загрузку файла: <br/>
<input type="text" name="points" value="0" size="2"/>
</td>
</tr>
<tr>
<td class="row1">
Раздел для взрослых: <br/>
<select name="ero">
<option value="0">Нет</option>
<option value="1">Да</option>
</select>
</td>
</tr>
<tr>
<td class="row1">
Закрыть доступ гостям: <br/>
<select name="login">
<option value="0">Нет</option>
<option value="1">Да</option>
</select>
</td>
</tr>
<tr>
<td class="row1">
Загружать файлы могут: <br/>
<select name="level">
<option value="0">Все пользователи</option>
<option value="1">Только администрация</option>
</select>
</td>
</tr>
<tr>
<td class="row1">
<input type="submit" name="submit" value="Добавить"/></form></td>
</tr>';
break;

case 'editraz':
	$sql = "SELECT*FROM `" . UPLOAD_RAZD_TABLE . "` WHERE `raz_id`='".$id."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_razd information', '', __LINE__, __FILE__, $sql);
	}
if(!mysql_num_rows($result))
    {
        message_die(GENERAL_MESSAGE, 'Раздел не существует!');
    }
$catalog = $db->sql_fetchrow($result);
if(isset($_POST['submit']))
{
if(empty($_POST['name']))
	{
        message_die(GENERAL_MESSAGE, 'Вы не ввели название раздела!');		
	}
if(empty($_POST['ext']))
	{
        message_die(GENERAL_MESSAGE, 'Вы не ввели допустимые расширения!');		
	}	
$name = mysql_real_escape_string(trim($_POST['name']));	
$description = mysql_real_escape_string(trim($_POST['description']));
$ext = mysql_real_escape_string(trim($_POST['ext']));
$ero = abs(intval($_POST['ero']));
$points = abs(intval($_POST['points']));
$login = abs(intval($_POST['login']));
$level = abs(intval($_POST['level']));

	$sql = "UPDATE `" . UPLOAD_RAZD_TABLE . "` SET `raz_name`='".$name."', `raz_description`='".$description."', `raz_ext`='".$ext."', `raz_points`='".$points."', `raz_ero`='".$ero."', `raz_login`='".$login."', `raz_level`='".$level."' WHERE `raz_id`='".$catalog['raz_id']."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_razd information', '', __LINE__, __FILE__, $sql);
	}
 message_die(GENERAL_MESSAGE, 'Раздел изменен!');	
}
require('./page_header_admin.'.$phpEx);	
$addraz = append_sid("?mod=editraz&amp;id=".$catalog['raz_id']);
echo '<table width="100%" cellpadding="4" cellspacing="0" border="0" class="forumline">
<tr><td class="catSides"><span class="cattitle">Изменение раздела</span></td></tr>
<form action="'.$addraz.'" method="post" />
<tr>
<td class="row1">Название раздела:<br/><input type="text" name="name" value="'.text_obmen_form($catalog['raz_name']).'" /></td>
</tr>
<tr>
<td class="row1">
Описание: <br/>
<textarea name="description" rows="5" cols="15" style="width: 235px;">'.text_obmen_form($catalog['raz_description']).'</textarea>
</td>
</tr>
<tr>
<td class="row1">
Допустимые расширения через запятую, например ext, ext, ext: <br/>
<input type="text" name="ext" value="'.text_obmen_form($catalog['raz_ext']).'" />
</td>
</tr>
<tr>
<td class="row1">
Сколько монет выдавать за загрузку файла: <br/>
<input type="text" name="points" value="'.$catalog['raz_points'].'" size="2"/>
</td>
</tr>
<tr>
<td class="row1">
Раздел для взрослых: <br/>
<select name="ero">
<option value="0"'.($catalog['raz_ero']==0 ? ' selected="selected"' : '').'>Нет</option>
<option value="1"'.($catalog['raz_ero']==1 ? ' selected="selected"' : '').'>Да</option>
</select>
</td>
</tr>
<tr>
<td class="row1">
Закрыть доступ гостям: <br/>
<select name="login">
<option value="0"'.($catalog['raz_login']==0 ? ' selected="selected"' : '').'>Нет</option>
<option value="1"'.($catalog['raz_login']==1 ? ' selected="selected"' : '').'>Да</option>
</select>
</td>
</tr>
<tr>
<td class="row1">
Загружать файлы могут: <br/>
<select name="level">
<option value="0"'.($catalog['raz_level']==0 ? ' selected="selected"' : '').'>Все пользователи</option>
<option value="1"'.($catalog['raz_level']==1 ? ' selected="selected"' : '').'>Только администрация</option>
</select>
</td>
</tr>
<tr>
<td class="row1">
<input type="submit" name="submit" value="Изменить"/></form></td>
</tr>';
break;

case 'delraz':
	$sql = "SELECT*FROM `" . UPLOAD_RAZD_TABLE . "` WHERE `raz_id`='".$id."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_razd information', '', __LINE__, __FILE__, $sql);
	}
if(!mysql_num_rows($result))
    {
        message_die(GENERAL_MESSAGE, 'Раздел не существует!');
    }
$catalog = $db->sql_fetchrow($result);
	if(isset($_POST['no']))
{
	$URL = append_sid("?");
			header ("Location: $URL");	
}
if(isset($_POST['yes']))
{
	$sql = "SELECT*FROM `" . UPLOAD_FILES_TABLE . "` WHERE `file_rid`='".$catalog['raz_id']."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_files information', '', __LINE__, __FILE__, $sql);
	}
while($last = $db->sql_fetchrow($result))
{
unlink('../upload/'.$last['file_url']);

if(!empty($last['file_screen']))
{
unlink('../screen/'.$last['file_screen']);
}
mysql_query("DELETE FROM `" . UPLOAD_COMMENTS_TABLE . "` WHERE `comment_fid`='".$last['file_id']."'");
mysql_query("DELETE FROM `" . UPLOAD_ABUSE_TABLE . "` WHERE `abuse_fid`='".$last['file_id']."'");
mysql_query("DELETE FROM `" . UPLOAD_RATING_TABLE . "` WHERE `rating_fid`='".$last['file_id']."'");
mysql_query("UPDATE `" . USERS_TABLE . "` SET `upload_count`=`upload_count`-1, `upload_size`=`upload_size`-".$last['file_size']." WHERE `user_id` = '".$last['file_user_id']."'");
}
$sql = "DELETE FROM `" . UPLOAD_FILES_TABLE . "` WHERE `file_rid`='".$catalog['raz_id']."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_files information', '', __LINE__, __FILE__, $sql);
	}

$sql = "DELETE FROM `" . UPLOAD_CATS_TABLE . "` WHERE `cat_rid`='".$catalog['raz_id']."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_cats information', '', __LINE__, __FILE__, $sql);
	}
$sql = "DELETE FROM `" . UPLOAD_RAZD_TABLE . "` WHERE `raz_id`='".$catalog['raz_id']."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_razd information', '', __LINE__, __FILE__, $sql);
	}	
$sql = "OPTIMIZE TABLE `" . UPLOAD_FILES_TABLE . "`";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_razd information', '', __LINE__, __FILE__, $sql);
	}
$sql = "OPTIMIZE TABLE `" . UPLOAD_RAZD_TABLE . "`";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_razd information', '', __LINE__, __FILE__, $sql);
	}	
$sql = "OPTIMIZE TABLE `" . UPLOAD_COMMENTS_TABLE . "`";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_comments information', '', __LINE__, __FILE__, $sql);
	}	
$sql = "OPTIMIZE TABLE `" . UPLOAD_CATS_TABLE . "`";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_razd information', '', __LINE__, __FILE__, $sql);
	}	
$sql = "OPTIMIZE TABLE `" . UPLOAD_ABUSE_TABLE . "`";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_comments information', '', __LINE__, __FILE__, $sql);
	}
$sql = "OPTIMIZE TABLE `" . UPLOAD_RATING_TABLE . "`";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_comments information', '', __LINE__, __FILE__, $sql);
	}		
	        message_die(GENERAL_MESSAGE, 'Раздел удален!');	
}
$delete = append_sid("?mod=delraz&id=".$catalog['raz_id']);
message_die(GENERAL_MESSAGE, 'Вы уверены, что хотите удалить этот раздел?<br/><form action="'.$delete.'" method="post" />
<input type="submit" name="yes" value="Да" /> <input type="submit" name="no" value="Нет" />
</form>');	
break;
default:
require('./page_header_admin.'.$phpEx);
$total = mysql_result(mysql_query("SELECT COUNT(*) FROM `" . UPLOAD_RAZD_TABLE . "`"),0);
echo '<table width="100%" cellpadding="4" cellspacing="0" border="0" class="forumline"><tr><td class="catSides"><span class="cattitle">Разделы файлобменника</span></td></tr>';
if($total)
{
	$sql = "SELECT * FROM `" . UPLOAD_RAZD_TABLE . "`";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_razd information', '', __LINE__, __FILE__, $sql);
	}
while ($razdel = $db->sql_fetchrow($result))
	{
	$editraz = append_sid("?mod=editraz&amp;id=".$razdel['raz_id']);
	$delraz = append_sid("?mod=delraz&amp;id=".$razdel['raz_id']);
	$razlink = append_sid("?mod=catalog&amp;id=".$razdel['raz_id']);
echo '<tr><td class="row1"><a href="'.$razlink.'">'.text_obmen($razdel['raz_name']).'</a> [<a href="'.$editraz.'">Изм</a>|<a href="'.$delraz.'">Уд</a>]</td></tr>'; 		
}
}
else
{
echo '<tr><td class="row1">Разделов нет</td></tr>';
}

$addraz = append_sid("?mod=addraz");
echo '</table><p><a href="'.$addraz.'">Добавить раздел</a><br/>
<a href="'.append_sid('index.'.$phpEx.'?pane=left').'">Вернуться на главную страницу администраторского раздела</a></p>';
}
include('./page_footer_admin.'.$phpEx);
?>