Файл: sources/admin/delete_cat.php
Строк: 53
<?php
if (!defined('VAPHP')) {
die("Этот файл недоступен.");
}
class delete_cat extends base
{
function delete_cat()
{
global $CONF, $DB, $FORM, $LNG, $TMPL;
if (is_array($FORM['id']) && count($FORM['id']) > 1)
{
$TMPL['id'] = "array";
$LNG['a_del_cat_header'] = $LNG['a_del_cat_headers'];
$LNG['a_del_cat_done'] = $LNG['a_del_cat_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']}_cat WHERE id = {$TMPL['id']}", __FILE__, __LINE__);
}
$TMPL['header'] = $LNG['a_del_cat_header'];
if ($TMPL['id'])
{
if (!isset($FORM['submit']))
{
$this->warning();
}
else
{
$this->process();
}
}
else
{
$this->error($LNG['a_del_cat_invalid_id'], 'admin');
}
}
function warning()
{
global $FORM, $LNG, $TMPL;
$ids = '';
if (is_array($FORM['id']) && count($FORM['id']) > 1)
{
$del_warn = $LNG['a_del_cat_warns'];
foreach ($FORM['id'] as $id)
{
$ids .= "<input type="hidden" name="id[]" value="{$id}" />n";
}
}
else
{
$del_warn = $LNG['a_del_cat_warn'];
$ids .= "<input type="hidden" name="id[]" value="{$TMPL['id']}" />n";
}
$TMPL['admin_content'] = <<<EndHTML
{$del_warn}<br><br>
<form action="index.php?a=admin&b=delete_cat" method="post">
{$ids}<input type="submit" class="ButtonNormal" name="submit" value="{$LNG['a_del_cat_header']}" />
</form>
EndHTML;
}
function process()
{
global $FORM, $LNG, $TMPL;
if (is_array($FORM['id']) && count($FORM['id']) > 1)
{
foreach ($FORM['id'] as $id)
{
$this->do_delete($id);
}
}
else
{
$this->do_delete($TMPL['id']);
}
$TMPL['admin_content'] = $LNG['a_del_cat_done'];
}
function do_delete($id)
{
global $CONF, $DB;
$result_subcat = $DB->query("SELECT id FROM {$CONF['sql_prefix']}_subcat WHERE idcat='{$id}'", __FILE__, __LINE__);
while (list($idsubcat) = $DB->fetch_array($result_subcat))
{
$DB->query("DELETE FROM {$CONF['sql_prefix']}_sites WHERE idsubcat='{$idsubcat}'", __FILE__, __LINE__);
}
$DB->query("DELETE FROM {$CONF['sql_prefix']}_subcat WHERE idcat='{$id}'", __FILE__, __LINE__);
$DB->query("DELETE FROM {$CONF['sql_prefix']}_cat WHERE id='{$id}'", __FILE__, __LINE__);
}
}
?>