Файл: sources/admin/add_site.php
Строк: 332
<?php
if (!defined('VAPHP'))
{
die("Этот файл недоступен.");
}
class add_site extends base
{
function add_site()
{
global $CONF, $DB, $FORM, $LNG, $TMPL;
$TMPL['header'] = $LNG['a_add_header'];
if (!isset($FORM['submit']))
{
$this->form();
}
else
{
$this->process();
}
}
function form()
{
global $CONF, $FORM, $LNG, $TMPL, $DB;
$categories_menu = "<select name="category" class="LongInput">n";
foreach ($CONF['categories'] as $idcat => $cat)
{
$categories_menu .= "<option value="">{$cat}</option>n";
if(!isset($CONF['subcategories'][$idcat])) continue;
foreach ($CONF['subcategories'][$idcat] as $id => $subcat)
{
$categories_menu .= "<option value="{$id}"> - {$subcat}</option>n";
}
}
$categories_menu .= "</select>";
$urlbl_menu = '';
if($CONF['backlink_require'])
{
$urlbl_menu = <<<EndHTML
{$LNG['a_add_urlbl']}<br>
<input type="text" name="urlbl" class="LongInput"><br><br>
<input type="checkbox" name="bl" value="1"/>
{$LNG['a_add_urlbl_later']}<br><br>
EndHTML;
}
$TMPL['admin_content'] .= <<<EndHTML
<form action="{$TMPL['site_url']}/index.php?a=admin&b=add_site" method="post">
<span class="SeparatorLabel">{$LNG['a_add_header']}</span>
{$LNG['a_add_category']}<br>
{$categories_menu}<br><br>
{$LNG['a_add_html']}<br>
<textarea name="html_cod" class="LongInput" rows="7"></textarea><br><br>
{$urlbl_menu}
<input name="submit" class="ButtonNormal" type="submit" value="{$LNG['a_add_header']}" />
</form>
EndHTML;
list($num_sites) = $DB->fetch("SELECT COUNT(*) FROM {$CONF['sql_prefix']}_sites where add_admin='1'", __FILE__, __LINE__);
//адрес этой страницы
$template_href="{$CONF['site_url']}?a=admin&b=add_site";
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&b=delete_site" method="post" name="manage">
EndHTML;
$alt = '';
$num = 0;
$result = $DB->select_limit("SELECT id, idsubcat, description, name, URL, visib, num_views, check_flag, check_possible FROM {$CONF['sql_prefix']}_sites where add_admin='1' ORDER BY {$CONF['site_sorting_field']} {$CONF['site_sorting']}", $pp, $start, __FILE__, __LINE__);
while (list($id, $idsubcat, $description, $name, $url, $visib, $num_views, $check_flag, $check_possible) = $DB->fetch_array($result))
{
list($subcatname) = $DB->fetch("SELECT name FROM {$CONF['sql_prefix']}_subcat WHERE id='{$idsubcat}'", __FILE__, __LINE__);
$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">{$description}</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_cat']}</td><td>{$subcatname}</td><td></td></tr>
<tr class="lightbgalt"><td> {$LNG['a_add_site_bl']}</td><td>{$bl_status}</td><td >{$bl_action}</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></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('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 process()
{
global $CONF, $FORM, $LNG, $TMPL, $DB;
$TMPL['category'] = intval($FORM['category']);
$TMPL['html_cod'] = $DB->escape($FORM['html_cod']);
$TMPL['urlbl'] = $DB->escape($FORM['urlbl']);
$TMPL['bl'] = intval($FORM['bl']);
$check_flag ='0';
if(!$TMPL['category']) $this->error($LNG['a_add_err_cat'], 'admin');
if(!$TMPL['html_cod']) $this->error($LNG['a_add_err_html'], 'admin');
if($CONF['backlink_require'] and !$TMPL['bl'])
{
if(!$TMPL['urlbl']) $this->error($LNG['a_add_err_urlbl'], 'admin');
$p_urlbl=@parse_url($TMPL['urlbl']);
$url="http://".$p_urlbl['host'];
$url_host = $p_urlbl['host'];
list($exist) = $DB->fetch("select URL_host from {$CONF['sql_prefix']}_sites where URL_host like '%$url_host%'", __FILE__, __LINE__);
if($exist) $this->error($LNG['a_add_exist'], 'admin');
if(!$p_urlbl) $this->error($LNG['a_add_err_urlbl'], 'admin');
if(!$this->is_backlink($TMPL['urlbl'])) $this->error($LNG['a_add_err_blempty'], 'admin');
$check_flag = 1;
}
$TMPL['banner_url'] = "{$CONF['skins_image']}/nobanner.gif";
$timecheck_next=time()+86400*$CONF['backlink_check'];
$add_date = date('Y-m-d', time());
$add_admin = 1;
$DB->query("INSERT INTO {$CONF['sql_prefix']}_sites (idsubcat, URL_host, URL, banner_url, URL_backlink, description, timecheck_next, check_flag, check_possible, add_admin, add_date)
VALUES ('{$TMPL['category']}', '{$url_host}', '{$url}', '{$TMPL['banner_url']}', '{$TMPL['urlbl']}','{$TMPL['html_cod']}', '{$timecheck_next}', '{$check_flag}', '{$check_flag}', '{$add_admin}', '{$add_date}')", __FILE__, __LINE__);
$id=mysql_insert_id();
$TMPL['static_url'] = "{$CONF['site_url']}/site/$id";
$TMPL['admin_content'] = <<<EndHTML
{$LNG['a_add_done']}<br>
{$LNG['a_add_staturl']} {$TMPL['static_url']}
EndHTML;
}
}
?>