<?php
/**
 * Check activated plugins
 * @return boolean
 */
if ( ! function_exists( 'dt_booking_check_plugin_active' ) ) {

	function dt_booking_check_plugin_active($plugin) {
		return in_array( $plugin, (array) get_option( 'active_plugins', array() ) ) || dt_booking_check_plugin_active_for_network( $plugin );
	}
}

if ( ! function_exists( 'dt_booking_check_plugin_active_for_network' ) ) {

	function dt_booking_check_plugin_active_for_network( $plugin ) {
		if ( !is_multisite() )
			return false;

		$plugins = get_site_option( 'active_sitewide_plugins');
		if ( isset($plugins[$plugin]) )
			return true;

		return false;
	}
}

/**
 * Returns the value if file exists.
 * @return boolean
 */
function dt_booking_theme_has_codestar() {

	if ( function_exists( 'cs_framework_init') && class_exists('CSFramework') ) {
		return true;
	}

	return false;
}

/**
 * Returns the value of excerpt content.
 * @return html content
 */
function dt_booking_post_excerpt($limit = NULL) {
	$limit = !empty($limit) ? $limit : 10;

	$excerpt = explode(' ', get_the_excerpt(), $limit);
	$excerpt = array_filter($excerpt);

	if (!empty($excerpt)) {
		if (count($excerpt) >= $limit) {
			array_pop($excerpt);
			$excerpt = implode(" ", $excerpt).'...';
		} else {
			$excerpt = implode(" ", $excerpt);
		}
		$excerpt = preg_replace('`\[[^\]]*\]`', '', $excerpt);
		$excerpt = str_replace('&nbsp;', '', $excerpt);
		if(!empty ($excerpt))
			return "<p>{$excerpt}</p>";
	}
}

/**
 * Returns the value from codestar array.
 * @return any value
 */
if ( ! function_exists( 'dt_booking_cs_get_option' ) ) {

	function dt_booking_cs_get_option( $key, $value = '' ) {

		$v = cs_get_option( $key );

		if ( !empty( $v ) ) {
			return $v;
		} else {
			return $value;
		}
	}
}

/**
 * Returns string for time duration.
 */
if ( ! function_exists( 'dt_booking_duration_to_string' ) ) {

	function dt_booking_duration_to_string( $duration ) {

		$hours   = (int)( $duration / 3600 );
		$minutes = (int)( ( $duration % 3600 ) / 60 );
		$result  = '';
		if ( $hours > 0 ) {
			$result = sprintf( __( '%d hr', 'dt-reservation-plugin' ), $hours );
			if ( $minutes > 0 ) {
				$result .= ' ';
			}
		}

		if ( $minutes > 0 ) {
			$result .= sprintf( __( '%d min', 'dt-reservation-plugin' ), $minutes );
		}
		return $result;
	}
}

/**
 * Returns time for string.
 */
if ( ! function_exists( 'dt_booking_string_to_time' ) ) {

	function dt_booking_string_to_time( $str ) {
		return strtotime( sprintf( '1985-03-17 %s', $str ) );
	}
}

/**
 * Returns posts array with price.
 */
if ( ! function_exists( 'dt_booking_get_posts_array' ) ) {

	function dt_booking_get_posts_array( $post_type = 'service' ) {

		$result_arr = array();
		$symbol = dt_booking_get_currency_symbol();
		$args = array( 'post_type' => 'dt_'.$post_type, 'order' => 'ASC', 'post_status' => 'publish', 'posts_per_page' => -1 );

		$the_query = new WP_Query( $args );
		if( $the_query->have_posts() ) {

			while ( $the_query->have_posts() ){
				$the_query->the_post();
				$id = get_the_ID();
				$title = get_the_title();

				$post_meta = get_post_meta($id ,'_custom_settings',TRUE);
				$post_meta = is_array($post_meta) ? $post_meta : array();

				$price = !empty( $post_meta[$post_type.'-price'] ) ? $post_meta[$post_type.'-price'] : '0';

				$result_arr[$id] = $title.' ( '.$symbol.' '.dt_booking_number_format($price).' )';
				
			}
			wp_reset_postdata();
		}

		return $result_arr;
	}
}

/**
 * Get Base Currency Code.
 * @return string
 */
function dt_booking_get_currency() {
	return apply_filters( 'dt_booking_currency', cs_get_option( 'book-currency' ) );
}

/**
 * Get full list of currency codes.
 * @return array
 */
function dt_booking_get_currencies() {
	return array_unique(
		apply_filters( 'dt_booking_currencies',
			array(
				'AED' => __( 'United Arab Emirates dirham', 'dt-reservation-plugin' ),
				'AFN' => __( 'Afghan afghani', 'dt-reservation-plugin' ),
				'ALL' => __( 'Albanian lek', 'dt-reservation-plugin' ),
				'AMD' => __( 'Armenian dram', 'dt-reservation-plugin' ),
				'ANG' => __( 'Netherlands Antillean guilder', 'dt-reservation-plugin' ),
				'AOA' => __( 'Angolan kwanza', 'dt-reservation-plugin' ),
				'ARS' => __( 'Argentine peso', 'dt-reservation-plugin' ),
				'AUD' => __( 'Australian dollar', 'dt-reservation-plugin' ),
				'AWG' => __( 'Aruban florin', 'dt-reservation-plugin' ),
				'AZN' => __( 'Azerbaijani manat', 'dt-reservation-plugin' ),
				'BAM' => __( 'Bosnia and Herzegovina convertible mark', 'dt-reservation-plugin' ),
				'BBD' => __( 'Barbadian dollar', 'dt-reservation-plugin' ),
				'BDT' => __( 'Bangladeshi taka', 'dt-reservation-plugin' ),
				'BGN' => __( 'Bulgarian lev', 'dt-reservation-plugin' ),
				'BHD' => __( 'Bahraini dinar', 'dt-reservation-plugin' ),
				'BIF' => __( 'Burundian franc', 'dt-reservation-plugin' ),
				'BMD' => __( 'Bermudian dollar', 'dt-reservation-plugin' ),
				'BND' => __( 'Brunei dollar', 'dt-reservation-plugin' ),
				'BOB' => __( 'Bolivian boliviano', 'dt-reservation-plugin' ),
				'BRL' => __( 'Brazilian real', 'dt-reservation-plugin' ),
				'BSD' => __( 'Bahamian dollar', 'dt-reservation-plugin' ),
				'BTC' => __( 'Bitcoin', 'dt-reservation-plugin' ),
				'BTN' => __( 'Bhutanese ngultrum', 'dt-reservation-plugin' ),
				'BWP' => __( 'Botswana pula', 'dt-reservation-plugin' ),
				'BYR' => __( 'Belarusian ruble', 'dt-reservation-plugin' ),
				'BZD' => __( 'Belize dollar', 'dt-reservation-plugin' ),
				'CAD' => __( 'Canadian dollar', 'dt-reservation-plugin' ),
				'CDF' => __( 'Congolese franc', 'dt-reservation-plugin' ),
				'CHF' => __( 'Swiss franc', 'dt-reservation-plugin' ),
				'CLP' => __( 'Chilean peso', 'dt-reservation-plugin' ),
				'CNY' => __( 'Chinese yuan', 'dt-reservation-plugin' ),
				'COP' => __( 'Colombian peso', 'dt-reservation-plugin' ),
				'CRC' => __( 'Costa Rican col&oacute;n', 'dt-reservation-plugin' ),
				'CUC' => __( 'Cuban convertible peso', 'dt-reservation-plugin' ),
				'CUP' => __( 'Cuban peso', 'dt-reservation-plugin' ),
				'CVE' => __( 'Cape Verdean escudo', 'dt-reservation-plugin' ),
				'CZK' => __( 'Czech koruna', 'dt-reservation-plugin' ),
				'DJF' => __( 'Djiboutian franc', 'dt-reservation-plugin' ),
				'DKK' => __( 'Danish krone', 'dt-reservation-plugin' ),
				'DOP' => __( 'Dominican peso', 'dt-reservation-plugin' ),
				'DZD' => __( 'Algerian dinar', 'dt-reservation-plugin' ),
				'EGP' => __( 'Egyptian pound', 'dt-reservation-plugin' ),
				'ERN' => __( 'Eritrean nakfa', 'dt-reservation-plugin' ),
				'ETB' => __( 'Ethiopian birr', 'dt-reservation-plugin' ),
				'EUR' => __( 'Euro', 'dt-reservation-plugin' ),
				'FJD' => __( 'Fijian dollar', 'dt-reservation-plugin' ),
				'FKP' => __( 'Falkland Islands pound', 'dt-reservation-plugin' ),
				'GBP' => __( 'Pound sterling', 'dt-reservation-plugin' ),
				'GEL' => __( 'Georgian lari', 'dt-reservation-plugin' ),
				'GGP' => __( 'Guernsey pound', 'dt-reservation-plugin' ),
				'GHS' => __( 'Ghana cedi', 'dt-reservation-plugin' ),
				'GIP' => __( 'Gibraltar pound', 'dt-reservation-plugin' ),
				'GMD' => __( 'Gambian dalasi', 'dt-reservation-plugin' ),
				'GNF' => __( 'Guinean franc', 'dt-reservation-plugin' ),
				'GTQ' => __( 'Guatemalan quetzal', 'dt-reservation-plugin' ),
				'GYD' => __( 'Guyanese dollar', 'dt-reservation-plugin' ),
				'HKD' => __( 'Hong Kong dollar', 'dt-reservation-plugin' ),
				'HNL' => __( 'Honduran lempira', 'dt-reservation-plugin' ),
				'HRK' => __( 'Croatian kuna', 'dt-reservation-plugin' ),
				'HTG' => __( 'Haitian gourde', 'dt-reservation-plugin' ),
				'HUF' => __( 'Hungarian forint', 'dt-reservation-plugin' ),
				'IDR' => __( 'Indonesian rupiah', 'dt-reservation-plugin' ),
				'ILS' => __( 'Israeli new shekel', 'dt-reservation-plugin' ),
				'IMP' => __( 'Manx pound', 'dt-reservation-plugin' ),
				'INR' => __( 'Indian rupee', 'dt-reservation-plugin' ),
				'IQD' => __( 'Iraqi dinar', 'dt-reservation-plugin' ),
				'IRR' => __( 'Iranian rial', 'dt-reservation-plugin' ),
				'IRT' => __( 'Iranian toman', 'dt-reservation-plugin' ),
				'ISK' => __( 'Icelandic kr&oacute;na', 'dt-reservation-plugin' ),
				'JEP' => __( 'Jersey pound', 'dt-reservation-plugin' ),
				'JMD' => __( 'Jamaican dollar', 'dt-reservation-plugin' ),
				'JOD' => __( 'Jordanian dinar', 'dt-reservation-plugin' ),
				'JPY' => __( 'Japanese yen', 'dt-reservation-plugin' ),
				'KES' => __( 'Kenyan shilling', 'dt-reservation-plugin' ),
				'KGS' => __( 'Kyrgyzstani som', 'dt-reservation-plugin' ),
				'KHR' => __( 'Cambodian riel', 'dt-reservation-plugin' ),
				'KMF' => __( 'Comorian franc', 'dt-reservation-plugin' ),
				'KPW' => __( 'North Korean won', 'dt-reservation-plugin' ),
				'KRW' => __( 'South Korean won', 'dt-reservation-plugin' ),
				'KWD' => __( 'Kuwaiti dinar', 'dt-reservation-plugin' ),
				'KYD' => __( 'Cayman Islands dollar', 'dt-reservation-plugin' ),
				'KZT' => __( 'Kazakhstani tenge', 'dt-reservation-plugin' ),
				'LAK' => __( 'Lao kip', 'dt-reservation-plugin' ),
				'LBP' => __( 'Lebanese pound', 'dt-reservation-plugin' ),
				'LKR' => __( 'Sri Lankan rupee', 'dt-reservation-plugin' ),
				'LRD' => __( 'Liberian dollar', 'dt-reservation-plugin' ),
				'LSL' => __( 'Lesotho loti', 'dt-reservation-plugin' ),
				'LYD' => __( 'Libyan dinar', 'dt-reservation-plugin' ),
				'MAD' => __( 'Moroccan dirham', 'dt-reservation-plugin' ),
				'MDL' => __( 'Moldovan leu', 'dt-reservation-plugin' ),
				'MGA' => __( 'Malagasy ariary', 'dt-reservation-plugin' ),
				'MKD' => __( 'Macedonian denar', 'dt-reservation-plugin' ),
				'MMK' => __( 'Burmese kyat', 'dt-reservation-plugin' ),
				'MNT' => __( 'Mongolian t&ouml;gr&ouml;g', 'dt-reservation-plugin' ),
				'MOP' => __( 'Macanese pataca', 'dt-reservation-plugin' ),
				'MRO' => __( 'Mauritanian ouguiya', 'dt-reservation-plugin' ),
				'MUR' => __( 'Mauritian rupee', 'dt-reservation-plugin' ),
				'MVR' => __( 'Maldivian rufiyaa', 'dt-reservation-plugin' ),
				'MWK' => __( 'Malawian kwacha', 'dt-reservation-plugin' ),
				'MXN' => __( 'Mexican peso', 'dt-reservation-plugin' ),
				'MYR' => __( 'Malaysian ringgit', 'dt-reservation-plugin' ),
				'MZN' => __( 'Mozambican metical', 'dt-reservation-plugin' ),
				'NAD' => __( 'Namibian dollar', 'dt-reservation-plugin' ),
				'NGN' => __( 'Nigerian naira', 'dt-reservation-plugin' ),
				'NIO' => __( 'Nicaraguan c&oacute;rdoba', 'dt-reservation-plugin' ),
				'NOK' => __( 'Norwegian krone', 'dt-reservation-plugin' ),
				'NPR' => __( 'Nepalese rupee', 'dt-reservation-plugin' ),
				'NZD' => __( 'New Zealand dollar', 'dt-reservation-plugin' ),
				'OMR' => __( 'Omani rial', 'dt-reservation-plugin' ),
				'PAB' => __( 'Panamanian balboa', 'dt-reservation-plugin' ),
				'PEN' => __( 'Peruvian nuevo sol', 'dt-reservation-plugin' ),
				'PGK' => __( 'Papua New Guinean kina', 'dt-reservation-plugin' ),
				'PHP' => __( 'Philippine peso', 'dt-reservation-plugin' ),
				'PKR' => __( 'Pakistani rupee', 'dt-reservation-plugin' ),
				'PLN' => __( 'Polish z&#x142;oty', 'dt-reservation-plugin' ),
				'PRB' => __( 'Transnistrian ruble', 'dt-reservation-plugin' ),
				'PYG' => __( 'Paraguayan guaran&iacute;', 'dt-reservation-plugin' ),
				'QAR' => __( 'Qatari riyal', 'dt-reservation-plugin' ),
				'RON' => __( 'Romanian leu', 'dt-reservation-plugin' ),
				'RSD' => __( 'Serbian dinar', 'dt-reservation-plugin' ),
				'RUB' => __( 'Russian ruble', 'dt-reservation-plugin' ),
				'RWF' => __( 'Rwandan franc', 'dt-reservation-plugin' ),
				'SAR' => __( 'Saudi riyal', 'dt-reservation-plugin' ),
				'SBD' => __( 'Solomon Islands dollar', 'dt-reservation-plugin' ),
				'SCR' => __( 'Seychellois rupee', 'dt-reservation-plugin' ),
				'SDG' => __( 'Sudanese pound', 'dt-reservation-plugin' ),
				'SEK' => __( 'Swedish krona', 'dt-reservation-plugin' ),
				'SGD' => __( 'Singapore dollar', 'dt-reservation-plugin' ),
				'SHP' => __( 'Saint Helena pound', 'dt-reservation-plugin' ),
				'SLL' => __( 'Sierra Leonean leone', 'dt-reservation-plugin' ),
				'SOS' => __( 'Somali shilling', 'dt-reservation-plugin' ),
				'SRD' => __( 'Surinamese dollar', 'dt-reservation-plugin' ),
				'SSP' => __( 'South Sudanese pound', 'dt-reservation-plugin' ),
				'STD' => __( 'S&atilde;o Tom&eacute; and Pr&iacute;ncipe dobra', 'dt-reservation-plugin' ),
				'SYP' => __( 'Syrian pound', 'dt-reservation-plugin' ),
				'SZL' => __( 'Swazi lilangeni', 'dt-reservation-plugin' ),
				'THB' => __( 'Thai baht', 'dt-reservation-plugin' ),
				'TJS' => __( 'Tajikistani somoni', 'dt-reservation-plugin' ),
				'TMT' => __( 'Turkmenistan manat', 'dt-reservation-plugin' ),
				'TND' => __( 'Tunisian dinar', 'dt-reservation-plugin' ),
				'TOP' => __( 'Tongan pa&#x2bb;anga', 'dt-reservation-plugin' ),
				'TRY' => __( 'Turkish lira', 'dt-reservation-plugin' ),
				'TTD' => __( 'Trinidad and Tobago dollar', 'dt-reservation-plugin' ),
				'TWD' => __( 'New Taiwan dollar', 'dt-reservation-plugin' ),
				'TZS' => __( 'Tanzanian shilling', 'dt-reservation-plugin' ),
				'UAH' => __( 'Ukrainian hryvnia', 'dt-reservation-plugin' ),
				'UGX' => __( 'Ugandan shilling', 'dt-reservation-plugin' ),
				'USD' => __( 'United States dollar', 'dt-reservation-plugin' ),
				'UYU' => __( 'Uruguayan peso', 'dt-reservation-plugin' ),
				'UZS' => __( 'Uzbekistani som', 'dt-reservation-plugin' ),
				'VEF' => __( 'Venezuelan bol&iacute;var', 'dt-reservation-plugin' ),
				'VND' => __( 'Vietnamese &#x111;&#x1ed3;ng', 'dt-reservation-plugin' ),
				'VUV' => __( 'Vanuatu vatu', 'dt-reservation-plugin' ),
				'WST' => __( 'Samoan t&#x101;l&#x101;', 'dt-reservation-plugin' ),
				'XAF' => __( 'Central African CFA franc', 'dt-reservation-plugin' ),
				'XCD' => __( 'East Caribbean dollar', 'dt-reservation-plugin' ),
				'XOF' => __( 'West African CFA franc', 'dt-reservation-plugin' ),
				'XPF' => __( 'CFP franc', 'dt-reservation-plugin' ),
				'YER' => __( 'Yemeni rial', 'dt-reservation-plugin' ),
				'ZAR' => __( 'South African rand', 'dt-reservation-plugin' ),
				'ZMW' => __( 'Zambian kwacha', 'dt-reservation-plugin' ),
			)
		)
	);
}

/**
 * Get Currency symbol.
 * @param string $currency (default: '')
 * @return string
 */
function dt_booking_get_currency_symbol( $currency = '' ) {
	if ( ! $currency ) {
		$currency = dt_booking_get_currency();
	}

	$symbols = apply_filters( 'dt_booking_currency_symbols', array(
		'AED' => '&#x62f;.&#x625;',
		'AFN' => '&#x60b;',
		'ALL' => 'L',
		'AMD' => 'AMD',
		'ANG' => '&fnof;',
		'AOA' => 'Kz',
		'ARS' => '&#36;',
		'AUD' => '&#36;',
		'AWG' => 'Afl.',
		'AZN' => 'AZN',
		'BAM' => 'KM',
		'BBD' => '&#36;',
		'BDT' => '&#2547;&nbsp;',
		'BGN' => '&#1083;&#1074;.',
		'BHD' => '.&#x62f;.&#x628;',
		'BIF' => 'Fr',
		'BMD' => '&#36;',
		'BND' => '&#36;',
		'BOB' => 'Bs.',
		'BRL' => '&#82;&#36;',
		'BSD' => '&#36;',
		'BTC' => '&#3647;',
		'BTN' => 'Nu.',
		'BWP' => 'P',
		'BYR' => 'Br',
		'BZD' => '&#36;',
		'CAD' => '&#36;',
		'CDF' => 'Fr',
		'CHF' => '&#67;&#72;&#70;',
		'CLP' => '&#36;',
		'CNY' => '&yen;',
		'COP' => '&#36;',
		'CRC' => '&#x20a1;',
		'CUC' => '&#36;',
		'CUP' => '&#36;',
		'CVE' => '&#36;',
		'CZK' => '&#75;&#269;',
		'DJF' => 'Fr',
		'DKK' => 'DKK',
		'DOP' => 'RD&#36;',
		'DZD' => '&#x62f;.&#x62c;',
		'EGP' => 'EGP',
		'ERN' => 'Nfk',
		'ETB' => 'Br',
		'EUR' => '&euro;',
		'FJD' => '&#36;',
		'FKP' => '&pound;',
		'GBP' => '&pound;',
		'GEL' => '&#x10da;',
		'GGP' => '&pound;',
		'GHS' => '&#x20b5;',
		'GIP' => '&pound;',
		'GMD' => 'D',
		'GNF' => 'Fr',
		'GTQ' => 'Q',
		'GYD' => '&#36;',
		'HKD' => '&#36;',
		'HNL' => 'L',
		'HRK' => 'Kn',
		'HTG' => 'G',
		'HUF' => '&#70;&#116;',
		'IDR' => 'Rp',
		'ILS' => '&#8362;',
		'IMP' => '&pound;',
		'INR' => '&#8377;',
		'IQD' => '&#x639;.&#x62f;',
		'IRR' => '&#xfdfc;',
		'IRT' => '&#x062A;&#x0648;&#x0645;&#x0627;&#x0646;',
		'ISK' => 'kr.',
		'JEP' => '&pound;',
		'JMD' => '&#36;',
		'JOD' => '&#x62f;.&#x627;',
		'JPY' => '&yen;',
		'KES' => 'KSh',
		'KGS' => '&#x441;&#x43e;&#x43c;',
		'KHR' => '&#x17db;',
		'KMF' => 'Fr',
		'KPW' => '&#x20a9;',
		'KRW' => '&#8361;',
		'KWD' => '&#x62f;.&#x643;',
		'KYD' => '&#36;',
		'KZT' => 'KZT',
		'LAK' => '&#8365;',
		'LBP' => '&#x644;.&#x644;',
		'LKR' => '&#xdbb;&#xdd4;',
		'LRD' => '&#36;',
		'LSL' => 'L',
		'LYD' => '&#x644;.&#x62f;',
		'MAD' => '&#x62f;.&#x645;.',
		'MDL' => 'MDL',
		'MGA' => 'Ar',
		'MKD' => '&#x434;&#x435;&#x43d;',
		'MMK' => 'Ks',
		'MNT' => '&#x20ae;',
		'MOP' => 'P',
		'MRO' => 'UM',
		'MUR' => '&#x20a8;',
		'MVR' => '.&#x783;',
		'MWK' => 'MK',
		'MXN' => '&#36;',
		'MYR' => '&#82;&#77;',
		'MZN' => 'MT',
		'NAD' => '&#36;',
		'NGN' => '&#8358;',
		'NIO' => 'C&#36;',
		'NOK' => '&#107;&#114;',
		'NPR' => '&#8360;',
		'NZD' => '&#36;',
		'OMR' => '&#x631;.&#x639;.',
		'PAB' => 'B/.',
		'PEN' => 'S/.',
		'PGK' => 'K',
		'PHP' => '&#8369;',
		'PKR' => '&#8360;',
		'PLN' => '&#122;&#322;',
		'PRB' => '&#x440;.',
		'PYG' => '&#8370;',
		'QAR' => '&#x631;.&#x642;',
		'RMB' => '&yen;',
		'RON' => 'lei',
		'RSD' => '&#x434;&#x438;&#x43d;.',
		'RUB' => '&#8381;',
		'RWF' => 'Fr',
		'SAR' => '&#x631;.&#x633;',
		'SBD' => '&#36;',
		'SCR' => '&#x20a8;',
		'SDG' => '&#x62c;.&#x633;.',
		'SEK' => '&#107;&#114;',
		'SGD' => '&#36;',
		'SHP' => '&pound;',
		'SLL' => 'Le',
		'SOS' => 'Sh',
		'SRD' => '&#36;',
		'SSP' => '&pound;',
		'STD' => 'Db',
		'SYP' => '&#x644;.&#x633;',
		'SZL' => 'L',
		'THB' => '&#3647;',
		'TJS' => '&#x405;&#x41c;',
		'TMT' => 'm',
		'TND' => '&#x62f;.&#x62a;',
		'TOP' => 'T&#36;',
		'TRY' => '&#8378;',
		'TTD' => '&#36;',
		'TWD' => '&#78;&#84;&#36;',
		'TZS' => 'Sh',
		'UAH' => '&#8372;',
		'UGX' => 'UGX',
		'USD' => '&#36;',
		'UYU' => '&#36;',
		'UZS' => 'UZS',
		'VEF' => 'Bs F',
		'VND' => '&#8363;',
		'VUV' => 'Vt',
		'WST' => 'T',
		'XAF' => 'Fr',
		'XCD' => '&#36;',
		'XOF' => 'Fr',
		'XPF' => 'Fr',
		'YER' => '&#xfdfc;',
		'ZAR' => '&#82;',
		'ZMW' => 'ZK',
	) );

	$currency_symbol = isset( $symbols[ $currency ] ) ? $symbols[ $currency ] : '';

	return apply_filters( 'dt_booking_currency_symbol', $currency_symbol, $currency );
}

/**
 * Get number format
 * @return number with format
 */
function dt_booking_number_format($n = 1) {

	$d = cs_get_option('price-decimal');
	
	return number_format($n, $d);
}

/**
 * Get formatted price
 * @return html
 */
function dt_booking_get_formatted_price($price = 30.55, $symbol = '$', $pos = 'left') {

	$symbol = dt_booking_get_currency_symbol();
	$pos 	= cs_get_option('currency-pos');

	switch($pos):
		case 'left':
		default:
			return $symbol.dt_booking_number_format($price);
			break;

		case 'left-with-space':
			return $symbol.' '.dt_booking_number_format($price);
			break;

		case 'right-with-space':
			return dt_booking_number_format($price).' '.$symbol;
			break;

		case 'right':
			return dt_booking_number_format($price).$symbol;
			break;
	endswitch;
}

/**
 * Get date range
 * @return dates
 */
function dt_booking_dates_range( $start_date, $end_date, $days = array() ){

    $interval = new DateInterval( 'P1D' );

    $realEnd = new DateTime( $end_date );
    $realEnd->add( $interval );

    $period = new DatePeriod( new DateTime( $start_date ), $interval, $realEnd );
    $dates = array();

    foreach ( $period as $date ) {
        $dates[] = in_array( strtolower( $date->format('l')) , $days ) ? $date->format( 'Y-m-d l' ) : '';
    }
    
    $dates = array_filter($dates);
    return $dates;
}

/**
 * Get replace values
 * @return array
 */
function dt_booking_replace( $content , $array ){
    $replace = array(
	 '[ADMIN_NAME]' => $array['admin_name'],
     '[STAFF_NAME]' => $array['staff_name'],
     '[SERVICE]' => $array['service_name'],
     '[CLIENT_NAME]' => $array['client_name'],
     '[CLIENT_PHONE]' => $array['client_phone'],
     '[CLIENT_EMAIL]' => $array['client_email'],
     '[APPOINTMENT_ID]' => $array['appointment_id'],
     '[APPOINTMENT_TIME]' => $array['appointment_time'],
     '[APPOINTMENT_DATE]' => $array['appointment_date'],
     '[APPOINTMENT_TITLE]' => $array['appointment_title'],   
     '[APPOINTMENT_BODY]' => $array['appointment_body'],
     '[AMOUNT]' => $array['amount'],
     '[COMPANY_LOGO]' => $array['company_logo'],
     '[COMPANY_NAME]' => $array['company_name'],
     '[COMPANY_PHONE]' => $array['company_phone'],
     '[COMPANY_ADDRESS]' => $array['company_address'],
     '[COMPANY_WEBSITE]' => $array['company_website']);

    return str_replace( array_keys( $replace ), array_values( $replace ), $content );
}

/**
 * Get replace values
 * @return array
 */
function dt_booking_replace_agenda( $content , $array ){
    $replace = array(
     '[STAFF_NAME]' => $array['staff_name'],
     '[TOMORROW]' => $array['tomorrow'],
     '[TOMORROW_AGENDA]' => $array['tomorrow_agenda'],
     '[COMPANY_LOGO]' => $array['company_logo'],
     '[COMPANY_NAME]' => $array['company_name'],
     '[COMPANY_PHONE]' => $array['company_phone'],
     '[COMPANY_ADDRESS]' => $array['company_address'],
     '[COMPANY_WEBSITE]' => $array['company_website']);

    return str_replace( array_keys( $replace ), array_values( $replace ), $content );
}

/**
 * Send email
 * @return mail
 */
function dt_booking_send_mail( $to, $subject, $message ){
	$sender_name =  cs_get_option('notification_sender_name');
	$sender_name = !empty($sender_name) ? $sender_name : get_option( 'blogname' );

	$sender_email = cs_get_option('notification_sender_email');
	$sender_email = !empty( $sender_email ) ? $sender_email : get_option( 'admin_email' );

	$from = $sender_name."<{$sender_email}>";

	$headers  = 'MIME-Version: 1.0' . "\r\n";
	$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
	$headers .= 'From: '.$from.'' . "\r\n";

	return wp_mail( $to, $subject, $message, $headers );
}