<?php if (!defined('ABSPATH')) die('No direct access allowed'); ?>
<?php wp_enqueue_script('app_mail_subscriber_newsletters', Application_Mail_Subscriber::get_application_uri() . '/js/newsletters_subscriptions.js') ?>

<div class="widget widget_newsletter_subscription">

    <?php if (!empty($instance['title'])): ?>
        <h3 class="widget-title"><?php echo $instance['title']; ?></h3>
    <?php endif; ?>

	<div class="entry-holder">
    <?php if (is_user_logged_in()): ?>
        <?php
        $user = wp_get_current_user();
        $subscription_hash = Application_Mail_Subscriber::dsCrypt($user->data->user_email, false);
        $user_subscribe_page = ThemeMakersThemeModel::get_option("user_subscribe_page", THEMEMAKERS_APP_MAIL_SUBSCRIBER_PREFIX);
        ?>
        <a href="<?php echo home_url() ?>/?p=<?php echo $user_subscribe_page ?>&subscription=<?php echo $subscription_hash ?>"><?php _e('Manage your subscriptions', THEMEMAKERS_THEME_FOLDER_NAME) ?></a><br />
    <?php else: ?>

        <p>
            <?php echo $instance['text'] ?>
        </p>


        <?php $unique_id = uniqid() ?>
		
        <form name="newsletter_subscription_<?php echo $unique_id ?>" action="/" onsubmit="return app_mail_subscriber_newsletters.subscribe_user('<?php echo $unique_id ?>')">
			<p class="input-block">
				<label><?php _e('Your name*', THEMEMAKERS_THEME_FOLDER_NAME) ?></label>
				<input type="text" name="newsletter_subscription_name" id="newsletter_subscription_name_<?php echo $unique_id ?>" value="" />
			</p>
			<p class="input-block">
				<label><?php _e('Your e-mail address*', THEMEMAKERS_THEME_FOLDER_NAME) ?></label>
				<input type="text" name="newsletter_subscription_email" id="newsletter_subscription_email_<?php echo $unique_id ?>" value="" />
			</p>
			<input type="submit" class="button default yellow" value="<?php _e('Sign Up', THEMEMAKERS_THEME_FOLDER_NAME) ?>" />
        </form>

        <ul style="display: none" id="newsletter_subscription_info_<?php echo $unique_id ?>"></ul>

    <?php endif; ?>
	</div>
</div>


