<?php
/**
 *
 * @category        backend
 * @package         wysiwyg
 * @author          WebsiteBaker Project
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
 * @link            http://www.websitebaker.org/
 * @license         http://www.gnu.org/licenses/gpl.html
 * @platform        WebsiteBaker 2.8.4
 * @requirements    PHP 5.2.2 and higher
 * @version         $Id: save.php 1910 2013-06-07 03:14:18Z Luisehahne $
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/wysiwyg/save.php $
 * @lastmodified    $Date: 2013-06-07 05:14:18 +0200 (Fri, 07 Jun 2013) $
 *
*/

require('../../config.php');

// suppress to print the header, so no new FTAN will be set
$admin_header = false;
// Tells script to update when this page was last updated
$update_when_modified = true;
// Include WB admin wrapper script
require(WB_PATH.'/modules/admin.php');

if (!$admin->checkFTAN()) {
	$admin->print_header();
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
}
// After check print the header
$admin->print_header();

// Include the WB functions file
require_once(WB_PATH.'/framework/functions.php');
$aErrors = array();
//$sMediaUrl = WB_URL.MEDIA_DIRECTORY;
// Update the mod_wysiwygs table with the contents
if(isset($_POST['content'.$section_id])) {
	$content = $_POST['content'.$section_id];
	$content = $admin->ReplaceAbsoluteMediaUrl($content);
	// searching in $text will be much easier this way
	$content = WbDatabase::getInstance()->escapeString ($content);
	$text = umlauts_to_entities(strip_tags($content), strtoupper(DEFAULT_CHARSET), 0);
	$sql  = 'UPDATE `'.TABLE_PREFIX.'mod_wysiwyg` ';
	$sql .= 'SET `content`=\''.$content.'\', `text`=\''.$text.'\' ';
	$sql .= 'WHERE `section_id`='.(int)$section_id;
	if(!WbDatabase::getInstance()->query($sql)){
		$aErrors[] = $MESSAGE['GENERIC_NOT_UPGRADED'].((defined('DEBUG') && DEBUG) ? '<br />'.WbDatabase::getInstance()->get_error() : '');
	}
} else {
	$aErrors[] = $MESSAGE['GENERIC_NOT_UPGRADED'].((defined('DEBUG') && DEBUG) ? '<br />'.$MESSAGE['FRONTEND_SORRY_NO_ACTIVE_SECTIONS'] : '');
}

$sSectionIdPrefix = ( defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' )  ? SEC_ANCHOR : 'Sec' );
if(defined('EDIT_ONE_SECTION') and EDIT_ONE_SECTION){
	$edit_page = ADMIN_URL.'/pages/modify.php?page_id='.$page_id.'&wysiwyg='.$section_id;
} else {
	$edit_page = ADMIN_URL.'/pages/modify.php?page_id='.$page_id.'#'.$sSectionIdPrefix.$section_id;
}

// Check if there is a database error, otherwise say successful
if(sizeof($aErrors) ) {
	$admin->print_error( implode('<br />',$aErrors), $edit_page);
} else {
	$admin->print_success($MESSAGE['GENERIC_UPGRADED'], $edit_page );
}

// Print admin footer
$admin->print_footer();
