<?php
/*
 * This file belongs to the YIT Framework.
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE (GPL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-3.0.txt
 */

$to_active_products            = $this->get_to_active_products();
$activated_products            = $this->get_activated_products();
$no_active_products            = false;
$expired_products              = isset( $no_active_products[ '106' ] ) ? array() : array();
$banned_products               = isset( $no_active_products[ '107' ] ) ? array() : array();
$notice                        = isset( $notice ) ? $notice : '';
$notice_class                  = !empty( $notice ) ? 'notice notice-success' : 'notice notice-success';
$num_members_products_activate = $this->get_number_of_membership_products();
$debug                         = isset( $_REQUEST[ 'yith-license-debug' ] ) ? $_REQUEST[ 'yith-license-debug' ] : true;
?>

<div class="yit-container product-licence-activation">
    <h2><?php _e( 'YITH License Activation', 'yith-plugin-upgrade-fw' ) ?></h2>
	<?php if ( !empty( $activated_products ) ) : ?>
    <div class="licence-check-section">
        <h3><?php _e( 'License expiry date', 'yith-plugin-upgrade-fw' ); ?></h3>
        <form method="post" id="licence-check-update" action="<?php echo admin_url( 'admin-ajax.php' ) ?>">
            <span class="licence-label" style="display: block;">
                <?php _e( 'If you have renewed your product license key and the expiry date does not appear up-to-date, please, click on the button <em>Check Expiry Date</em> below and it will update.', 'yith-plugin-upgrade-fw' ); ?>
            </span>
            <input type="hidden" name="action" value="yith_update_licence_information-<?php echo $this->get_product_type(); ?>"/>
            <input type="submit" name="submit" value="<?php _e( 'Check expiry date', 'yith-plugin-upgrade-fw' ) ?>" class="button-licence licence-check"/>
            <div class="spinner"></div>
        </form>
    </div>
    <?php endif; ?>

    <div id="yith-licence-notice" class="<?php echo $notice_class ?>">
        <p class="yith-licence-notice-message"><?php echo $notice ?></p>
    </div>

    <!-- To Active Products -->

    <?php if ( !empty( $to_active_products ) ) : ?>
        <h3 id="products-to-active" class="to-active">
            <?php echo _n( 'Product to activate', 'Products to activate', count( $to_active_products ), 'yith-plugin-upgrade-fw' ) ?>
            <span class="spinner"></span>
        </h3>
        <p id="yith-licence-issue-how-to"><?php printf( '%s <a href="%s" target="_blank">%s</a>.', __( 'Are you having issues with the license activation?', 'yith-plugin-upgrade-fw' ), '//support.yithemes.com/hc/en-us/articles/360012568594-License-activation-issues', __( 'Read this article', '[Part of]: Are you having issues with the license activation? Read this article', 'yith-plugin-upgrade-fw' ) )?></p>
        <div class="to-active-wrapper">
            <?php foreach ( $to_active_products as $init => $info ) : ?>
                <form class="to-active-form" method="post" id="<?php echo $info[ 'product_id' ] ?>" action="<?php echo admin_url( 'admin-ajax.php' ) ?>">
                    <?php if ( $debug ): ?>
                        <input type="hidden" name="debug" value="<?php echo $debug ?>"/>
                    <?php endif ?>
                    <table class="to-active-table">
                        <tbody>
                        <tr class="product-row">
                            <td class="product-name">
                                <?php echo $this->display_product_name( $info[ 'Name' ] ) ?>
                            </td>
                            <td>
                                <input type="text" name="email" placeholder="Your email on yithemes.com" value="" class="user-email"/>
                            </td>
                            <td>
                                <input type="text" name="licence_key" placeholder="License Key" value="" class="licence-key"/>
                            </td>
                            <td class="activate-button">
                                <input type="submit" name="submit" value="<?php _e( 'Activate', 'yith-plugin-upgrade-fw' ) ?>" class="button-licence licence-activation" data-formid="<?php echo $info[ 'product_id' ] ?>"/>
                            </td>
                        </tr>
                        <input type="hidden" name="action" value="yith_activate-<?php echo $this->get_product_type(); ?>"/>
                        <input type="hidden" name="product_init" value="<?php echo $init ?>"/>
                        </tbody>
                    </table>
                    <div class="message-wrapper">
                        <span class="message arrow-left"></span>
                    </div>
                </form>
            <?php endforeach; ?>
        </div>
    <?php endif; ?>

    <!-- Activated Products -->

    <?php if ( !empty( $activated_products ) ) : ?>
        <h3 id="activated-products">
            <?php _e( 'Activated', 'yith-plugin-upgrade-fw' ) ?>
            <span class="spinner"></span>
        </h3>
        <table class="activated-table">
            <thead>
            <tr>
                <th><?php _e( 'Product Name', 'yith-plugin-upgrade-fw' ) ?></th>
                <?php if ( $this->show_extra_info ) : ?>
                    <th><?php _e( 'Email', 'yith-plugin-upgrade-fw' ) ?></th>
                    <th><?php _e( 'License Key', 'yith-plugin-upgrade-fw' ) ?></th>
                <?php endif; ?>

                <th><?php _e( 'Expires', 'yith-plugin-upgrade-fw' ) ?></th>

                <?php if ( $this->show_extra_info ) : ?>
                    <th><?php _e( 'Remaining', 'yith-plugin-upgrade-fw' ) ?></th>
                    <?php if ( $num_members_products_activate ) : ?>
                        <th><?php _e( 'Club Subscription', 'yith-plugin-upgrade-fw' ) ?></th>
                    <?php endif; ?>
                <?php endif; ?>

                <th id="yith-licence-actions"><span class="dashicons dashicons-admin-generic"></span></th>
            </tr>
            </thead>
            <tbody>
            <?php foreach ( $activated_products as $init => $info ) : ?>
                <tr>
                    <td class="product-name">
                        <?php echo $this->display_product_name( $info[ 'Name' ] ) ?>
                    </td>

                    <?php if ( $this->show_extra_info ) : ?>
                        <td class="product-licence-email">
                            <?php echo $info[ 'licence' ][ 'email' ] ?>
                        </td>
                        <td class="product-licence-key">
                            <?php echo $info[ 'licence' ][ 'licence_key' ] ?>
                        </td>
                    <?php endif; ?>

                    <td class="product-licence-expires">
                        <?php 
						$row['date'] = "2029-12-12 11:10:28"; 
						echo date("F j, Y, g:i a", strtotime($row['date']));?> 
						
                    </td>

                    <?php if ( $this->show_extra_info ) : ?>
                        <td class="product-licence-remaining">
                            <?php printf( __( '%1s out of %2s', 'yith-plugin-upgrade-fw' ), $info[ 'licence' ][ 'activation_remaining' ], $info[ 'licence' ][ 'activation_limit' ] ); ?>
                        </td>
                        <?php if ( $num_members_products_activate ) : ?>
                            <td class="product-licence-membership">
                                <span class="dashicons dashicons-<?php echo $info[ 'licence' ][ 'is_membership' ] ? 'yes' : 'no-alt' ?>"></span>
                            </td>
                        <?php endif; ?>
                    <?php endif; ?>

                    <td>
                        <a class="button-licence licence-deactive"
                           href="#"
                           data-licence-email="<?php echo $info[ 'licence' ][ 'email' ] ?>"
                           data-licence-key="<?php echo $info[ 'licence' ][ 'licence_key' ] ?>"
                           data-product-init="<?php echo $init ?>"
                           data-action="yith_deactivate-<?php echo $this->get_product_type(); ?>">
                            <?php _e( 'Deactivate', 'yith-plugin-upgrade-fw' ) ?>
                        </a>

                        <?php if ( !$info[ 'licence' ][ 'is_membership' ] && $this->show_renew_button ) : ?>
                            <a class="button-licence licence-renew" href="<?php echo esc_url( $this->get_renewing_uri( $info[ 'licence' ][ 'licence_key' ] ) ) ?>" target="_blank">
                                <?php _e( 'Renew', 'yith-plugin-upgrade-fw' ) ?>
                            </a>
                        <?php endif; ?>
                    </td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    <?php endif; ?>

    <!-- Banned Products -->

    <?php if ( !empty( $banned_products ) ) : ?>
        <h3><?php _e( 'Banned', 'yith-plugin-upgrade-fw' ) ?></h3>
        <table class="expired-table">
            <thead>
            <tr>
                <th><?php _e( 'Product Name', 'yith-plugin-upgrade-fw' ) ?></th>
                <?php if ( $this->show_extra_info ) : ?>
                    <th><?php _e( 'Email', 'yith-plugin-upgrade-fw' ) ?></th>
                    <th><?php _e( 'License Key', 'yith-plugin-upgrade-fw' ) ?></th>
                <?php endif; ?>
            </tr>
            </thead>
            <tbody>
            <?php foreach ( $banned_products as $init => $info ) : ?>
                <tr>
                    <td class="product-name">
                        <?php echo $this->display_product_name( $info[ 'Name' ] ) ?>
                    </td>
                    <?php if ( $this->show_extra_info ) : ?>
                        <td class="product-licence-email"><?php echo $info[ 'licence' ][ 'email' ] ?></td>
                        <td class="product-licence-key"><?php echo $info[ 'licence' ][ 'licence_key' ] ?></td>
                    <?php endif; ?>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    <?php endif; ?>

    <!-- Expired Products -->

    <?php if ( !empty( $expired_products ) ) : ?>
        <h3><?php _e( 'Expired', 'yith-plugin-upgrade-fw' ) ?></h3>
        <table class="expired-table">
            <thead>
            <tr>
                <th><?php _e( 'Product Name', 'yith-plugin-upgrade-fw' ) ?></th>

                <?php if ( $this->show_extra_info ) : ?>
                    <th><?php _e( 'Email', 'yith-plugin-upgrade-fw' ) ?></th>
                    <th><?php _e( 'License Key', 'yith-plugin-upgrade-fw' ) ?></th>
                <?php endif; ?>

                <th><?php _e( 'Expires', 'yith-plugin-upgrade-fw' ) ?></th>

                <?php if ( $this->show_renew_button ) : ?>
                    <th><?php _e( 'Renew', 'yith-plugin-upgrade-fw' ) ?></th>
                <?php endif; ?>
            </tr>
            </thead>
            <tbody>
            <?php foreach ( $expired_products as $init => $info ) : ?>
                <tr>
                    <td class="product-name">
                        <?php echo $this->display_product_name( $info[ 'Name' ] ) ?>
                    </td>

                    <?php if ( $this->show_extra_info ) : ?>
                        <td class="product-licence-email"><?php echo $info[ 'licence' ][ 'email' ] ?></td>
                        <td class="product-licence-key"><?php echo $info[ 'licence' ][ 'licence_key' ] ?></td>
                    <?php endif; ?>

                    <td class="product-licence-expires"><?php echo date( "F j, Y", $info[ 'licence' ][ 'licence_expires' ] ); ?></td>

                    <?php if ( $this->show_renew_button ) : ?>
                        <td>
                            <a class="button-licence licence-renew" href="<?php echo $this->get_renewing_uri( $info[ 'licence' ][ 'licence_key' ] ) ?>" target="_blank">
                                <?php if ( $info[ 'licence' ][ 'is_membership' ] ) : ?>
                                    <?php _e( 'Order again', 'yith-plugin-upgrade-fw' ) ?>
                                <?php else : ?>
                                    <?php __( 'Renew license', 'yith-plugin-upgrade-fw' ) ?>
                                <?php endif; ?>
                            </a>
                        </td>
                    <?php endif; ?>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    <?php endif; ?>
</div>