<?php

/*
 *  슬라이더 삭제
 */
include_once './_common.php';
include_once './index.php';
if (!defined('_GNUBOARD_')) {
    exit;
}
if (!($token && get_session('ask_delete_token') == $token)) {
    alert('토큰 에러로 삭제 불가합니다.');
    exit;
}
function attach_delete($idx, $type) {
    if ($type == 'child') {
        $field = 'ac_idx';
    } else {
        $field = 'ac_parent_idx';
    }
    //첨부이미지 삭제
    $sql = "select * from ask_plugin_cslider where {$field} = '{$idx}'";
    $result = sql_query($sql);
    while ($row = sql_fetch_array($result)) {
        if ($row['ac_image_name']) {
            $filepath = G5_PATH . "/data/asktheme_attach";
            unlink($filepath . '/' . $row['ac_image_name']);
        }
    }
}

if ($idx) {
    $idx = sql_escape($idx);
    if ($type == 'child') {
        attach_delete($idx, $type);
        //페이지 삭제
        $sql = "delete from ask_plugin_cslider where ac_idx = '{$idx}' limit 1";
        sql_query($sql);
    }
    if ($type == 'parent') {
        //부모 및 자식페이지 삭제
        attach_delete($idx, $type);
        //페이지 삭제
        $sql = "delete from ask_plugin_cslider where ac_parent_idx = '{$idx}'";
        sql_query($sql);
        //부모슬라이더 삭제
        $sql = "delete from ask_plugin_cslider_parent where acp_idx = '{$idx}' limit 1";
        sql_query($sql);
    }
    goto_url(G5_PLUGIN_URL . '/asktheme/plugin/parallaxcontentslider/slider_list.php');
    exit;
} else {
    alert('잘못된 접속!!');
    exit;
}