<?php
/**
 * Healthcoach Framework: messages subsystem
 *
 * @package	healthcoach
 * @since	healthcoach 1.0
 */

// Disable direct call
if ( ! defined( 'ABSPATH' ) ) { exit; }

// Theme init
if (!function_exists('healthcoach_messages_theme_setup')) {
	add_action( 'healthcoach_action_before_init_theme', 'healthcoach_messages_theme_setup' );
	function healthcoach_messages_theme_setup() {
		// Core messages strings
		add_filter('healthcoach_filter_localize_script', 'healthcoach_messages_localize_script');
	}
}


/* Session messages
------------------------------------------------------------------------------------- */

if (!function_exists('healthcoach_get_error_msg')) {
	function healthcoach_get_error_msg() {
		return healthcoach_storage_get('error_msg');
	}
}

if (!function_exists('healthcoach_set_error_msg')) {
	function healthcoach_set_error_msg($msg) {
		$msg2 = healthcoach_get_error_msg();
		healthcoach_storage_set('error_msg', trim($msg2) . ($msg2=='' ? '' : '<br />') . trim($msg));
	}
}

if (!function_exists('healthcoach_get_success_msg')) {
	function healthcoach_get_success_msg() {
		return healthcoach_storage_get('success_msg');
	}
}

if (!function_exists('healthcoach_set_success_msg')) {
	function healthcoach_set_success_msg($msg) {
		$msg2 = healthcoach_get_success_msg();
		healthcoach_storage_set('success_msg', trim($msg2) . ($msg2=='' ? '' : '<br />') . trim($msg));
	}
}

if (!function_exists('healthcoach_get_notice_msg')) {
	function healthcoach_get_notice_msg() {
		return healthcoach_storage_get('notice_msg');
	}
}

if (!function_exists('healthcoach_set_notice_msg')) {
	function healthcoach_set_notice_msg($msg) {
		$msg2 = healthcoach_get_notice_msg();
		healthcoach_storage_set('notice_msg', trim($msg2) . ($msg2=='' ? '' : '<br />') . trim($msg));
	}
}


/* System messages (save when page reload)
------------------------------------------------------------------------------------- */
if (!function_exists('healthcoach_set_system_message')) {
	function healthcoach_set_system_message($msg, $status='info', $hdr='') {
		update_option(healthcoach_storage_get('options_prefix') . '_message', array('message' => $msg, 'status' => $status, 'header' => $hdr));
	}
}

if (!function_exists('healthcoach_get_system_message')) {
	function healthcoach_get_system_message($del=false) {
		$msg = get_option(healthcoach_storage_get('options_prefix') . '_message', false);
		if (!$msg)
			$msg = array('message' => '', 'status' => '', 'header' => '');
		else if ($del)
			healthcoach_del_system_message();
		return $msg;
	}
}

if (!function_exists('healthcoach_del_system_message')) {
	function healthcoach_del_system_message() {
		delete_option(healthcoach_storage_get('options_prefix') . '_message');
	}
}


/* Messages strings
------------------------------------------------------------------------------------- */

if (!function_exists('healthcoach_messages_localize_script')) {
	
	function healthcoach_messages_localize_script($vars) {
		$vars['strings'] = array(
			'ajax_error'		=> esc_html__('Invalid server answer', 'healthcoach'),
			'bookmark_add'		=> esc_html__('Add the bookmark', 'healthcoach'),
            'bookmark_added'	=> esc_html__('Current page has been successfully added to the bookmarks. You can see it in the right panel on the tab \'Bookmarks\'', 'healthcoach'),
            'bookmark_del'		=> esc_html__('Delete this bookmark', 'healthcoach'),
            'bookmark_title'	=> esc_html__('Enter bookmark title', 'healthcoach'),
            'bookmark_exists'	=> esc_html__('Current page already exists in the bookmarks list', 'healthcoach'),
			'search_error'		=> esc_html__('Error occurs in AJAX search! Please, type your query and press search icon for the traditional search way.', 'healthcoach'),
			'email_confirm'		=> esc_html__('On the e-mail address "%s" we sent a confirmation email. Please, open it and click on the link.', 'healthcoach'),
			'reviews_vote'		=> esc_html__('Thanks for your vote! New average rating is:', 'healthcoach'),
			'reviews_error'		=> esc_html__('Error saving your vote! Please, try again later.', 'healthcoach'),
			'error_like'		=> esc_html__('Error saving your like! Please, try again later.', 'healthcoach'),
			'error_global'		=> esc_html__('Global error text', 'healthcoach'),
			'name_empty'		=> esc_html__('The name can\'t be empty', 'healthcoach'),
			'name_long'			=> esc_html__('Too long name', 'healthcoach'),
			'email_empty'		=> esc_html__('Too short (or empty) email address', 'healthcoach'),
			'email_long'		=> esc_html__('Too long email address', 'healthcoach'),
			'email_not_valid'	=> esc_html__('Invalid email address', 'healthcoach'),
			'subject_empty'		=> esc_html__('The subject can\'t be empty', 'healthcoach'),
			'subject_long'		=> esc_html__('Too long subject', 'healthcoach'),
			'text_empty'		=> esc_html__('The message text can\'t be empty', 'healthcoach'),
			'text_long'			=> esc_html__('Too long message text', 'healthcoach'),
			'send_complete'		=> esc_html__("Send message complete!", 'healthcoach'),
			'send_error'		=> esc_html__('Transmit failed!', 'healthcoach'),
			'geocode_error'			=> esc_html__('Geocode was not successful for the following reason:', 'healthcoach'),
			'googlemap_not_avail'	=> esc_html__('Google map API not available!', 'healthcoach'),
			'editor_save_success'	=> esc_html__("Post content saved!", 'healthcoach'),
			'editor_save_error'		=> esc_html__("Error saving post data!", 'healthcoach'),
			'editor_delete_post'	=> esc_html__("You really want to delete the current post?", 'healthcoach'),
			'editor_delete_post_header'	=> esc_html__("Delete post", 'healthcoach'),
			'editor_delete_success'	=> esc_html__("Post deleted!", 'healthcoach'),
			'editor_delete_error'	=> esc_html__("Error deleting post!", 'healthcoach'),
			'editor_caption_cancel'	=> esc_html__('Cancel', 'healthcoach'),
			'editor_caption_close'	=> esc_html__('Close', 'healthcoach')
			);
		return $vars;
	}
}
?>