Файл: sources/admin/manage_ban.php
Строк: 338
<?php
if (!defined('VAPHP')) {
die("Этот файл недоступен.");
}
class manage_ban extends base
{
function manage_ban()
{
global $FORM, $LNG, $TMPL;
$TMPL['header'] = $LNG['a_man_ban_header'];
if ((!isset($FORM['string']) && !isset($FORM['field']) && !isset($FORM['matching'])) || !$FORM['string'])
{
$this->main();
}
else
{
$this->ban();
}
}
function main() {
global $CONF, $DB, $FORM, $LNG, $TMPL;
$TMPL['admin_content'] = <<<EndHTML
{$LNG['a_man_ban_instructions']}<br><br>
{$LNG['a_man_ban_instructions_matching']}<br><br>
<form action="index.php" method="get">
<input type="hidden" name="a" value="admin" />
<input type="hidden" name="b" value="manage_ban" />
<table cellspacing="0" cellpadding="0" width="100%" border=0>
<tr>
<td width="25%">
{$LNG['a_man_ban_string']}
</td>
<td width="25%">
{$LNG['a_man_ban_field']}
</td>
<td width="25%">
{$LNG['a_man_bad_words_matching']}
</td>
</tr>
<tr>
<td>
<input type="text" name="string" class="SmallInput"/>
</td>
<td>
<select name="field" class="SmallInput">
<option value="url">{$LNG['g_short_url']}</option>
<option value="email">{$LNG['g_email']}</option>
<option value="ip">{$LNG['g_ip']}</option>
</select>
</td>
<td>
<select name="matching" class="SmallInput">
<option value="1">{$LNG['a_man_bad_words_exact']}</option>
<option value="0">{$LNG['a_man_bad_words_global']}</option>
</select>
</td>
<td rowspan="2" width="20%">
<input type="submit" class="ButtonNormal" value="{$LNG['a_man_ban_submit']}" />
</td>
</tr>
</table>
</form><br>
EndHTML;
list($num_bans) = $DB->fetch("SELECT COUNT(*) FROM {$CONF['sql_prefix']}_ban", __FILE__, __LINE__);
//адрес этой страницы
$template_href="{$CONF['site_url']}?a=admin&b=manage_ban";
if ($FORM['pp'])
{
$pp = intval($FORM['pp']);
if ($pp < $CONF['sites_per_page'][0]) {$pp = $CONF['sites_per_page'][0];}
}
else {$pp = $CONF['sites_per_page'][0];}
foreach($CONF['sites_per_page'] as $value)
{
if ($pp == $value) {$per_page_menu.= "<b>$value</b> ";}
else{
$per_page_menu.=<<<EndHTML
<a href="{$template_href}&pp=$value">{$value}</a>
EndHTML;
}
}
if (isset($FORM['p']))
{
$p = intval ($FORM['p']);
if ($p > ceil($num_bans/$pp) || $p < 1) {$p=1;} //если номер страницы больше максимально возможного - присваиваем ему значение 1
$start = intval($p - 1);
if ($start < 0) $start=0;
$start = $start * $pp;
}
else
{
$p = 1;
$start = 0;
}
if($num_bans > $pp) //проверка необходимости в постраничном выводе
{
$TMPL['page_menu'] = '';
$num_page = ceil($num_bans/$pp); //количество страниц
$PrevPage = $p-1;
$NextPage = $p+1;
//определение переменных для счетчика цикла
if($num_page > $CONF['lenght_pp_block']){
$left_pages = floor(($CONF['lenght_pp_block']-1)/2);
$number_start_page = $p-$left_pages;
if($number_start_page <= 0) {$number_start_page = 1;}
$number_end_page = $number_start_page + $CONF['lenght_pp_block']-1;
if($number_end_page > $num_page) {$number_end_page = $num_page; $number_start_page = $number_end_page-$CONF['lenght_pp_block']+1;}
}else
{
$number_start_page = 1;
$number_end_page = $num_page;
}
//само построение кода постраничного вывода
if($number_start_page > 1) {
$prev_page = $number_start_page-1;
$TMPL['page_menu'] .= "<a href="{$template_href}&p=1&pp=$pp">1</a> "; //ссылка на самую первую страницу
$TMPL['page_menu'] .= "<a href="{$template_href}&p={$prev_page}&pp=$pp">...</a> "; //
}
for($i=$number_start_page; $i<=$number_end_page; $i++)
{
if($i == $p)
$TMPL['page_menu'] .= "<b>$i</b> ";
else
$TMPL['page_menu'] .= "<a href="{$template_href}&p=$i&pp=$pp">$i</a> ";
}
if($number_end_page < $num_page) {
$next_page = $number_end_page+1;
$TMPL['page_menu'] .= "<a href="{$template_href}&p={$next_page}&pp=$pp">...</a> ";
$TMPL['page_menu'] .= "<a href="{$template_href}&p={$num_page}&pp=$pp">$num_page</a> ";
}
if($p <= 1) {$TMPL['AtStart'] = "<span class=AtStart><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" src="{$CONF['skins_image']}/button_prev.gif"></span>";}
else {$TMPL['AtStart'] = "<a href="{$template_href}&p={$PrevPage}&pp={$pp}" class=AtStart><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" src="{$CONF['skins_image']}/button_prev_act.gif"></a>";}
if($p >= $num_page) {$TMPL['AtEnd']="<a class=AtEnd><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" src="{$CONF['skins_image']}/button_next.gif"></a>";}
else {$TMPL['AtEnd']="<a href="{$template_href}&p={$NextPage}&pp={$pp}" class=AtEnd><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" src="{$CONF['skins_image']}/button_next_act.gif"></a>";}
$TMPL['page_menu'] = $TMPL['AtStart'].$TMPL['page_menu'].$TMPL['AtEnd'];
$TMPL['page_menu']="<div class="PagingStrip">".$TMPL['page_menu']."</div>";
//конец построения кода постраничного вывода
}
$num_first_site = $start + 1;
$num_final_site = $num_first_site + $pp - 1;
if ($num_final_site > $num_bans) {$num_final_site = $num_bans;}
$LNG['g_number_of_all'] = sprintf($LNG['g_number_of_all'], $num_first_site, $num_final_site, $num_bans);
if ($num_bans != 0) $TMPL['admin_content'] .= <<<EndHTML
<table width="100%">
<tr><td colspan="2">
<table width="100%" border=0>
<tr>
<td width="33%"></td>
<td width="33%" align="center"><span class="GreyTextNormal">{$LNG['g_number_of_all']}</span></td>
<td width="33%" align="right"><span class="GreyTextSmall">{$LNG['g_string_per_page']} <img src="{$CONF['skins_image']}/arrow_right.gif"> $per_page_menu</span></td>
</tr>
</table>
</td></tr>
<tr><td colspan="2"><hr width=100% size="1" class="SeparatorHr2"></td></tr>
<tr><td colspan="2" align=center>{$TMPL['page_menu']}</td></tr>
<tr><td colspan="2"><hr width=100% size="1" class="SeparatorHr"></td></tr>
</table>
EndHTML;
$TMPL['admin_content'] .= <<<EndHTML
<script language="javascript">
function check(form_name, field_name, value)
{
var check_boxes = document.forms[form_name].elements[field_name];
var num_check_boxes = check_boxes.length;
if (!num_check_boxes)
{
check_boxes.checked = value;
}
else {
for(var i = 0; i < num_check_boxes; i++)
{
check_boxes[i].checked = value;
}
}
}
</script>
<form action="{$TMPL['site_url']}/index.php?a=admin&b=delete_ban" method="post" name="manage">
<table cellpadding="5" cellspacing="1" width="100%">
<tr class="TableHeader">
<td width="18px"></td>
<td width="30%">{$LNG['a_man_ban_string']}</td>
<td>{$LNG['a_man_ban_field']}</td>
<td>{$LNG['a_man_ban_matching']}</td>
<td align="center" colspan="2">{$LNG['a_man_ban_actions']}</td>
</tr>
EndHTML;
$alt = '';
$num = 0;
$result = $DB->select_limit("SELECT id, string, field, matching FROM {$CONF['sql_prefix']}_ban ORDER BY id ASC", $pp, $start, __FILE__, __LINE__);
while (list($id, $string, $field, $matching) = $DB->fetch_array($result))
{
if ($matching) {
$matching = $LNG['a_man_bad_words_exact'];
}
else {
$matching = $LNG['a_man_bad_words_global'];
}
$TMPL['admin_content'] .= <<<EndHTML
<tr class="lightbg{$alt}">
<td><input type="checkbox" name="id[]" value="{$id}" id="checkbox_{$num}" /></td>
<td>{$string}</td>
<td>{$field}</td>
<td>{$matching}</td>
<td align="center"><a href="{$TMPL['site_url']}/index.php?a=admin&b=edit_ban&id={$id}">{$LNG['a_man_edit']}</a></td>
<td align="center"><a href="{$TMPL['site_url']}/index.php?a=admin&b=delete_ban&id={$id}">{$LNG['a_man_delete']}</a></td>
</tr>
EndHTML;
if ($alt) { $alt = ''; }
else { $alt = 'alt'; }
$num++;
}
$TMPL['admin_content'] .= <<<EndHTML
</table><br>
<a href="javascript:void;" onclick="check('manage', 'id[]', true)">{$LNG['a_man_all']}</a> |
<a href="javascript:void;" onclick="check('manage', 'id[]', false)">{$LNG['a_man_none']}</a><br><br>
<input type="submit" class="ButtonNormal" value="{$LNG['a_man_del_sel']}" />
</form>
EndHTML;
}
function ban()
{
global $CONF, $DB, $FORM, $LNG, $TMPL;
$TMPL['string'] = $DB->escape($FORM['string']);
$TMPL['field'] = $DB->escape($FORM['field']);
$TMPL['matching'] = intval($FORM['matching']);
$DB->query("INSERT INTO {$CONF['sql_prefix']}_ban (string, field, matching) VALUES ('{$TMPL['string']}', '{$TMPL['field']}', {$TMPL['matching']})", __FILE__, __LINE__);
$string = strip_tags($FORM['string']);
$TMPL['admin_content'] = sprintf($LNG['a_man_ban_filtered'], $string);
}
}
?>