<?php

/* -----------------------------------------------------------------
 * 	$Id: blog.php 1113 2014-06-19 11:32:53Z akausch $
 * 	Copyright (c) 2011-2021 commerce:SEO by Webdesign Erfurt
 * Copyright by H&S eCom 
 * @author little Pit(S.B.)
 * 	http://www.commerce-seo.de : www.indiv-style.de
 * ------------------------------------------------------------------
 * 	based on:
 * 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
 * 	(c) 2002-2003 osCommerce - www.oscommerce.com
 * 	(c) 2003     nextcommerce - www.nextcommerce.org
 * 	(c) 2005     xt:Commerce - www.xt-commerce.com
 * 	Released under the GNU General Public License
 * --------------------------------------------------------------- */

require_once('includes/application_top.php');
require_once('includes/application_blog.php');
require_once (DIR_WS_CLASSES . 'class.blog.php');
require_once (DIR_WS_CLASSES . 'class.image_manipulator_gd2.php');
$coo_text_mgr = new LanguageTextManager('blog', $_SESSION['languages_id']);

$smarty = new Smarty;
$smarty->assign('txt', $coo_text_mgr->v_section_content_array['blog']);
$languages = xtc_get_languages();

$comment_count = xtc_db_fetch_array(xtc_db_query("SELECT COUNT(*) as count FROM " . TABLE_BLOG_COMMENT . " WHERE comment_status != '1';"));
$data = xtc_db_fetch_array(xtc_db_query("SELECT code FROM " . TABLE_LANGUAGES . " WHERE languages_id='" . (int)$_SESSION['languages_id'] . "';"));

if ($_GET['action']) {
    switch ($_GET['action']) {

        case 'delete_item' :
            xtc_db_query("DELETE FROM blog_items WHERE item_id = " . $_GET['item'] . " ");
            xtc_db_query("DELETE FROM blog_item_article WHERE item_id = " . $_GET['item'] . " ");
            xtc_db_query("DELETE FROM blog_item_images WHERE item_id = " . $_GET['item'] . " ");
            xtc_db_query("DELETE FROM blog_item_item WHERE item_id = " . $_GET['item'] . " ");
            xtc_db_query("DELETE FROM blog_item_kat WHERE item_id = " . $_GET['item'] . " ");
            xtc_db_query("DELETE FROM blog_item_text WHERE item_id = " . $_GET['item'] . " ");
            xtc_redirect(xtc_href_link(FILENAME_BLOG));
            break;
        case 'save_category' :
            blogCategories($_POST, $_POST['action']);
            xtc_redirect(xtc_href_link(FILENAME_BLOG));
            break;

        case 'set' :
            SetFlag($_POST, $_GET);
            if ((int) $_GET['cat'])
                xtc_redirect(xtc_href_link(FILENAME_BLOG, 'action=showitems&cat=' . (int) $_GET['cat']));
            else
                xtc_redirect(xtc_href_link(FILENAME_BLOG));
            break;

        case 'save_item' :
            blogItem($_POST, $_POST['action']);
            // xtc_redirect(xtc_href_link(FILENAME_BLOG, 'action=showitems&cat=' . $_POST['categories_id']));
            break;

        case 'save_start' :
            blogStart($_POST, $_POST['action']);
            xtc_redirect(xtc_href_link(FILENAME_BLOG));
            break;

        case 'blog_setting':
            $save_value_query = xtc_db_query("SELECT blog_key, wert FROM " . TABLE_BLOG_SETTINGS . "");
            while ($save_value = xtc_db_fetch_array($save_value_query)) {
                xtc_db_query("UPDATE " . TABLE_BLOG_SETTINGS . " SET wert = '" . $_POST[$save_value['blog_key']] . "' WHERE blog_key='" . $save_value['blog_key'] . "'");
            }
            $success = SAVE_SUCCESS;
            xtc_redirect(FILENAME_BLOG . '?action=settings');
            break;
    }
}

require_once(DIR_WS_INCLUDES . 'header.php');
$counter = '';
if ($comment_count['count']) {
	$counter = '<span class="label label-danger">'.$comment_count['count'].'</span>';
}
$smarty->assign('COUNTER', $counter);
$smarty->assign('TITLE', HEADING_TITLE_BLOG);
$smarty->assign('FILENAME_BLOG', FILENAME_BLOG);
$smarty->assign('TABLE_HEADING_NAVIGATION_OVERVIEW', TABLE_HEADING_NAVIGATION_OVERVIEW);
$smarty->assign('TABLE_HEADING_NAVIGATION_NEWCATEGORIE', TABLE_HEADING_NAVIGATION_NEWCATEGORIE);
$smarty->assign('TABLE_HEADING_NAVIGATION_STARTSITE', TABLE_HEADING_NAVIGATION_STARTSITE);
$smarty->assign('TABLE_HEADING_NAVIGATION_SETTINGS', TABLE_HEADING_NAVIGATION_SETTINGS);
$smarty->assign('TABLE_HEADING_NAVIGATION_COMMENTS', TABLE_HEADING_NAVIGATION_COMMENTS);

if (USE_WYSIWYG == 'true') {
    echo '<script src="includes/editor/ckeditor/ckeditor.js" type="text/javascript"></script>';
    echo '<script src="includes/editor/ckfinder/ckfinder.js" type="text/javascript"></script>';
}

switch ($_GET['action']) {
    case 'newcategorie' :
    case 'editcategories' :
        include(DIR_WS_MODULES . 'blog_categories_edit.php');
        break;

    case 'startsite' :
        include(DIR_WS_MODULES . 'blog_start.php');
        break;

    case 'edit_item' :
    case 'new_item' :
        include(DIR_WS_MODULES . 'blog_item_edit.php');
        break;

    case 'showitems' :
        include(DIR_WS_MODULES . 'blog_item_list.php');
        break;

    case 'comments' :
        include(DIR_WS_MODULES . 'blog_comments.php');
        break;

    case 'settings' :
        include(DIR_WS_MODULES . 'blog_settings.php');
        break;

    default :
        include(DIR_WS_MODULES . 'blog_categories_list.php');
        break;
}


$smarty->assign('language', $_SESSION['language']);
$smarty->assign('logo_path', HTTP_SERVER . DIR_WS_CATALOG . 'templates/' . CURRENT_TEMPLATE . '/img/');
$smarty->caching = false;
$smarty->template_dir = DIR_FS_CATALOG . 'admin/templates/';
$smarty->compile_dir = DIR_FS_CATALOG . 'admin/templates_c';
$smarty->display(CURRENT_ADMIN_TEMPLATE . '/blog.html');

require(DIR_WS_INCLUDES . 'footer.php');
require(DIR_WS_INCLUDES . 'application_bottom.php');
