Файл: sources/admin/approve.php
Строк: 314
<?php
if (!defined('VAPHP'))
{
die("Этот файл недоступен.");
}
class approve extends base
{
function approve()
{
global $FORM, $LNG, $TMPL;
$TMPL['header'] = $LNG['a_approve_header'];
if (!isset($FORM['id']))
{
$this->form();
}
else
{
$this->process();
}
}
function form()
{
global $CONF, $DB, $LNG, $TMPL, $FORM;
list($num_sites) = $DB->fetch("SELECT COUNT(*) FROM {$CONF['sql_prefix']}_sites WHERE check_admin = '0' ORDER BY {$CONF['site_sorting_field']} {$CONF['site_sorting']}", __FILE__, __LINE__);
if ($num_sites)
{
//адрес этой страницы
$template_href="{$CONF['site_url']}?a=admin&b=approve";
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_sites/$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_sites > $pp) //проверка необходимости в постраничном выводе
{
$TMPL['page_menu'] = '';
$num_page = ceil($num_sites/$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_sites) {$num_final_site = $num_sites;}
$LNG['g_number_of_all'] = sprintf($LNG['g_number_of_all'], $num_first_site, $num_final_site, $num_sites);
if ($num_sites != 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_sites_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" method="post" name="approve">
EndHTML;
$alt = '';
$num = 0;
$result = $DB->select_limit("SELECT id, idsubcat, description, name, URL, email, visib, num_views, check_flag, check_possible, user_ip, banner_url FROM {$CONF['sql_prefix']}_sites where check_admin = '0' order by `id` ASC", $pp, $start, __FILE__, __LINE__);
while (list($id, $idsubcat, $description, $name, $url, $email, $visib, $num_views, $check_flag, $check_possible, $user_ip, $banner_url) = $DB->fetch_array($result))
{
list($subcatname) = $DB->fetch("SELECT name FROM {$CONF['sql_prefix']}_subcat WHERE id='{$idsubcat}'", __FILE__, __LINE__);
if(strlen($description) > $CONF['cut_descr'] and $CONF['cut_descr']!=0)
{
$description = substr($description, 0, $CONF['cut_descr']);
$description .= "...";
if($CONF['type_link']) {$html_cod="<a href="{$url}" target=blank><b>{$name}</b></a><br>{$description}";}
else {$html_cod="<a href="{$CONF['site_url']}/?a=redirect&id={$id}" target=blank><b>{$name}</b></a><br>{$description}";}
}else
{
if($CONF['type_link']) {$html_cod="<a href="{$url}" target=blank><b>{$name}</b></a><br>{$description}";}
else {$html_cod="<a href="{$CONF['site_url']}/?a=redirect&id={$id}" target=blank><b>{$name}</b></a><br>{$description}";}
}
$bl_status='';
if($CONF['backlink_require'])
{
if($check_possible)
{
if($visib and $check_flag) $bl_status = "<a href="{$TMPL['site_url']}/index.php?a=admin&b=check_backlink&id={$id}" target="blank">{$LNG['a_add_bl_fnd']}</a>";
if(!$visib and $check_flag) $bl_status = "<a href="{$TMPL['site_url']}/index.php?a=admin&b=check_backlink&id={$id}" target="blank">{$LNG['a_add_bl_notfnd']}</a>";
if(!$visib and !$check_flag) $bl_status = "<a href="{$TMPL['site_url']}/index.php?a=admin&b=check_backlink&id={$id}" target="blank">{$LNG['a_add_bl_notch']}</a>";
}
else {$bl_status = $LNG['a_add_bl_empty'];}
}
else {$bl_status = $LNG['a_add_bl_notreq'];}
$TMPL['admin_content'] .= <<<EndHTML
<table cellpadding="1" cellspacing="0" width="100%" border=0 class="ListSitesTable">
<tr>
<td width=3% align="center"><input type="checkbox" name="id[]" value="{$id}" id="checkbox_{$num}" /></td>
<td>
<table cellpadding="1" cellspacing="1" width="100%" border=0>
<tr align="center"><td colspan="3">{$html_cod}</td></tr>
<tr class="lightbgalt"><td width=15%>{$LNG['a_add_site_id']}</td><td><a href="{$CONF['site_url']}/?a=site&id=$id" target=blank>{$id}</a></td><td width=15%></td></tr>
<tr class="lightbg"><td> {$LNG['a_add_site']}</td><td><a href="{$url}" target=blank>{$url}</a></td><td></td></tr>
<tr class="lightbgalt"><td> {$LNG['a_man_site_banner']}</td><td><a href="{$url}" target=blank><img src="{$banner_url}" width="{$CONF['max_banner_width']}" height="{$CONF['max_banner_height']}" border="0" title="{$name}"></a></td><td></td></tr>
<tr class="lightbg"><td> {$LNG['g_email']}</td><td>{$email}</td><td></td></tr>
<tr class="lightbgalt"><td> {$LNG['a_add_site_cat']}</td><td>{$subcatname}</td><td></td></tr>
<tr class="lightbg"><td> {$LNG['a_add_site_bl']}</td><td>{$bl_status}</td><td >{$bl_action}</td></tr>
<tr class="lightbgalt"><td>{$LNG['g_add_from_ip']}</td><td>{$user_ip}</td><td></td></tr>
<tr class="lightbg"><td> {$LNG['g_views']}</td><td>$num_views</td><td></td></tr>
<tr class="lightbgblue"><td><a href="{$TMPL['site_url']}/index.php?a=admin&b=edit_site&id={$id}">{$LNG['a_cat_edit']}</a></td><td><a href="{$TMPL['site_url']}/index.php?a=admin&b=approve&id={$id}">{$LNG['a_approve']}</a></td><td><a href="{$TMPL['site_url']}/index.php?a=admin&b=delete_site&id={$id}">{$LNG['a_cat_delete']}</a></td></tr>
</table>
</td>
</tr>
</table><br>
EndHTML;
}
$TMPL['admin_content'] .= <<<EndHTML
<br>
<a href="javascript:void;" onclick="check('approve', 'id[]', true)">{$LNG['a_man_all']}</a> |
<a href="javascript:void;" onclick="check('approve', 'id[]', false)">{$LNG['a_man_none']}</a><br><br>
{$LNG['a_approve_sel']}<br>
<select name="b">
<option value="approve">{$LNG['a_approve']}</option>
<option value="delete_site">{$LNG['a_man_delete']}</option>
</select>
<input type="submit" value="{$LNG['g_form_submit_short']}" />
</form>
EndHTML;
}
else
{
$TMPL['admin_content'] = $this->error($LNG['a_approve_none'], 'admin');
}
}
function process()
{
global $DB, $FORM, $LNG, $TMPL, $CONF;
if (is_array($FORM['id']) && count($FORM['id']) > 1)
{
$TMPL['id'] = "array";
$LNG['a_approve_done'] = $LNG['a_approve_dones'];
}
else
{
if (is_array($FORM['id']) && count($FORM['id']) == 1)
{
$TMPL['id'] = intval($FORM['id'][0]);
}
else
{
$TMPL['id'] = intval($FORM['id']);
}
list($TMPL['id']) = $DB->fetch("SELECT id FROM {$CONF['sql_prefix']}_sites WHERE id = {$TMPL['id']} and check_admin = '0'", __FILE__, __LINE__);
}
if ($TMPL['id'])
{
if (is_array($FORM['id']) && count($FORM['id']) > 1)
{
foreach ($FORM['id'] as $id)
{
$this->do_approve($id);
}
}
else
{
$this->do_approve($TMPL['id']);
}
$TMPL['admin_content'] = $LNG['a_approve_done'];
}
else
{
$this->error($LNG['a_approve_invalid_id'], 'admin');
}
}
function do_approve($id)
{
global $CONF, $DB, $LNG, $TMPL;
$DB->query("UPDATE {$CONF['sql_prefix']}_sites SET check_admin = '1', visib = '1', check_flag = '{$CONF['backlink_require']}' WHERE id = '{$id}' and check_admin = '0'", __FILE__, __LINE__);
$TMPL['static_url'] = "{$CONF['site_url']}/?a=site&id=$id";
list($TMPL['email']) = $DB->fetch("SELECT email FROM {$CONF['sql_prefix']}_sites WHERE id = '{$id}'", __FILE__, __LINE__);
$LNG['add_welcome'] = sprintf($LNG['add_welcome'], $TMPL['list_name']);
$add_email = new skin('add_email');
$add_email->send_email($TMPL['email']);
}
}
?>