<?php
$active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );

$plugins = array();
$plugins['idc'] = array(
    'name'	=>	'ID Commerce',
    'slug'	=>	'idcommerce/idcommerce.php',
    'url'	=>	'https://files.ignitiondeck.com/idc_latest.zip'
);
$plugins['idcf'] = array(
    'name'	=>	'IgnitionDeck Crowdfunding',
    'slug'	=>	'ignitiondeck-crowdfunding/ignitiondeck.php',
    'url'	=>	'https://files.ignitiondeck.com/idcf_latest.zip'
);
$installed = 'active';
foreach($plugins as $plugin) {
    if ( in_array( $plugin['slug'], $active_plugins ) ) {
        //$installed = 'active';
    } else {
        $installed = 'not';
    }
}

$license = 'free';
if(get_option('is_idc_licensed')) {
    $license = 'echelon';
    if(get_option('is_id_pro')) {
        $license = 'enterprise';
    }
} else {
    $license = get_option('is_id_basic') ?? 'free';
}
if(empty($license)) {
    $license = 'free';
}
$license_name = get_option('idf_license_name');

$idc_checked = get_option('idf_commerce_platform')=="idc"?'checked="checked"':'';
$woo_checked = ( get_option('idf_commerce_platform')=="wc" && get_option('is_idc_licensed') )?'checked="checked"':false;
if(!get_option('idf_commerce_platform') || !$woo_checked) {
    $idc_checked = 'checked="checked"';
    update_option( 'idf_commerce_platform', 'idc' );
}
$payments = '<strong>Which e-commerce platform will you use for payments?</strong>
<ul class="payment-platform">
<li><input type="radio" name="payment-platform" value="idc" '.$idc_checked.' /> IgnitionDeck Commerce</li>';
$wc_class = '';
$wc_disabled = '';
$wc_title = '';
if ( !in_array( 'woocommerce/woocommerce.php', $active_plugins ) ) {
    $wc_class = 'disabled';
    $wc_disabled = 'disabled="disabled"';
}
$wc_title = '<ul>
        <li>The WooCommerce plugin must be installed and activated to be selected.</li>
        <li>WooCommerce can be used instead of IgnitionDeck Commerce to manage products, payment gateways, and user accounts.</li>
        <li>Front-end creator functionality will be DISABLED with WooCommerce as the crowdfunding commerce platform.</li>
        <li>For more information, see <a style="color: #1F6CBD;" href="https://docs.ignitiondeck.com/article/133-woocommerce-ignitiondeck" target="_blank">IgnitionDeck & WooCommerce documentation</a></li>
    </ul>';
$wc_tooltip = '<span class="dashicons dashicons-editor-help idf-tooltip" style="cursor: pointer;" data-tippy-content="' . esc_attr($wc_title) . '"></span>';
$enterprise_notice = $license=='enterprise'?'notice="true"':'notice="false"';
$payments .= '<li class="'.$wc_class.'"><input type="radio" name="payment-platform" value="wc" '.$woo_checked.' '.$wc_disabled.' '.$enterprise_notice.' /> WooCommerce '.$wc_tooltip.'</li>';
$payments .= '</ul>';

$payments .= '<div class="button-group">';
if(get_option('idf_commerce_platform')) {
    $payments .= '<a href="' . esc_url(admin_url('admin.php?page=idf-themes')) . '" class="wiz-button">Continue</a>';
} else {
    $payments .= '<button type="button" class="wiz-button" onclick="wizard_action(\'save_payment\',this)">Save</button>';
}
$payments .= '<div class="clearfix"></div></div>';

$core_upgrade_url = 'https://members.ignitiondeck.com/?edd_action=add_to_cart&download_id=83885';
if ($license=='echelon') {
    // Echelon users get a special price if they're upgrading their license to Core
    $core_upgrade_url = 'https://members.ignitiondeck.com/checkout/?edd_action=sl_license_upgrade&license_id='.get_option('id_license_key').'&upgrade_id=3';
}

$core_promo = '<h3>Upgrade to Core</h3>
<p>Everything you need to launch your own crowdfunding platform on servers that you control. The ultimate self-hosted crowdfunding platform.</p>
<ul>
<li>Collect a fee from funds raised on your platform</li>
<li>Allow visitors to create their own projects</li>
<li>Accept payments with Stripe, Coinpayments, and <a href="https://docs.ignitiondeck.com/article/46-choosing-payment-gateways" target="_blank">more</a>.</li>
<li>Use WooCommerce for your checkout and member management</li>
<li>Activate any of the <a href="https://www.ignitiondeck.com/crowdfunding/modules/" target="_blank">IgnitionDeck Modules</a></li>
</ul>
<p><a href="'.$core_upgrade_url.'" target="_blank" class="wiz-button">Upgrade to Core</a></p>';

$deployed_upgrade_url = 'https://members.ignitiondeck.com/?edd_action=add_to_cart&download_id=138068';
if ($license_name=='Core') {
    // Core users get a special price if they're upgrading to Deployed
    $deployed_upgrade_url = 'https://members.ignitiondeck.com/checkout/?edd_action=sl_license_upgrade&license_id='.get_option('id_license_key').'&upgrade_id=1';
}

$deployed_promo = '<h3>Upgrade to Deployed</h3>
<p>Get your crowdfunding platform up and running quickly, and get ongoing premium support from IgnitionDeck Experts.</p>
<ul>
<li>Includes a Core license that unlocks all functionality</li>
<li>Initial installation and setup by IgnitionDeck experts</li>
<li>Hands-on support, troubleshooting, and configuration</li>
<li>Annual account review</li>
</ul>
<p><a href="'.$deployed_upgrade_url.'" target="_blank" class="wiz-button">Upgrade to Deployed</a></p>';

$managed_promo = '<h3>Upgrade to Managed</h3>
<p>We\'ll take care of your website for you so you can concentrate on operating your crowdfunding platform.</p>
<ul>
<li>Includes a Core license that unlocks all functionality</li>
<li>Rock-solid, worry-free website hosting</li>
<li>Monthly maintenance and daily backups</li>
<li>Initial installation and setup by IgnitionDeck experts</li>
<li>Hands-on support, troubleshooting, and configuration</li>
<li>Annual account review</li>
</ul>
<p><a href="https://www.ignitiondeck.com/book-a-demo/" target="_blank" class="wiz-button">Book a Demo</a></p>';

$support_promo = '<h3>Hands-On Support</h3>
<p>Your plan includes hands-on support from IgnitionDeck Experts, don\'t forget to use it!</p>
<ul>
<li>IgnitionDeck setup and configuration</li>
<li>Basic theme customizations</li>
<li>Troubleshooting</li>
</ul>
<p>Send an email to <a href="mailto:support@ignitionwp.com">support@ignitionwp.com</a> to ask for help.</p>';

$customizations_promo = '<h3>Customization Requests</h3>
<p>Your crowdfunding site can be customized by IgnitionDeck Experts however you like.</p>
<ul>
<li>Customize or create a theme for you with your design and brand choices</li>
<li>Integrate with other vendors, plugins, and payment gateways</li>
<li>Configure your plugins to customize your user experience</li>
<li>Build custom software that does exactly what you want for your vision and business model</li>
<li>…and probably anything else you could ask for.</li>
</ul>
<p>Email us at <a href="mailto:support@ignitionwp.com">support@ignitionwp.com</a> or <a href="https://www.ignitiondeck.com/ignitiondeck-customizations/" target="_blank">submit your customization request</a> to get the process started.</p>';


$button_text = 'Activate';
$license_expiry = get_option('license_expiry');
$item_id = get_option('license_item_id');
$license_post_id = get_option('license_post_id');

// Set the default $button_text and $expiry based on the license type.
if(empty($license) || $license=='free') {
    $button_text = 'Activate';
    $expiry = '<p>You are currently using the <b>Free</b> Edition of IgnitionDeck. The free version includes all the essential features to create and manage crowdfunding projects. Upgrade anytime to unlock additional features. If you have already purchased a license, you will find your key in your <a href="https://members.ignitiondeck.com/my-account/view-licenses/" target="_blank">IgnitionDeck Account</a>.</p>';
} else {
    $button_text = 'Activated';
    $expiry = '<p>You are currently using the <b>'.ucfirst($license_name).'</b> Edition of IgnitionDeck.<br>Your license will renew automatically on ['. gmdate('F d, Y', strtotime($license_expiry)) .']</p>';
}

// Override the $button_text and $expiry if the license is expired or has no activations left.
if($license_expiry=='no_activations_left') {
    $button_text = 'Activate';
    $expiry = '<p>Activation limit exceeded. Please remove unused domains to activate here. <a href="https://members.ignitiondeck.com/checkout/purchase-history/?action=manage_licenses&payment_id='.get_option('license_payment_id').'&license_id='.get_option('id_license_key').'" target="_blank">Manage License</a></p>';
} elseif($license_expiry=='expired') {
    $button_text = 'Expired';
    $expiry = '<p>Your IgnitionDeck license is expired. Please <a href="https://members.ignitiondeck.com/?edd_action=add_to_cart&edd_license_key='.get_option('id_license_key').'&download_id='.$item_id.'" target="_blank">renew</a> your license for full functionality.</p>';
} elseif($license_expiry=='lifetime' && $license!='free') {
    $button_text = 'Activated';
    $expiry = '<p>You are currently using the <b>Lifetime '.ucfirst($license_name).'</b> Edition of IgnitionDeck.</p>';
} elseif($license_expiry=='missing') {
    $button_text = 'Activate';
    $expiry = '<p>You are currently using the <b>Free</b> Edition of IgnitionDeck. The free version includes all the essential features to create and manage crowdfunding projects. Upgrade anytime to unlock additional features. If you have already purchased a license, you will find your key in your <a href="https://members.ignitiondeck.com/my-account/view-licenses/" target="_blank">IgnitionDeck Account</a>.</p>';
}
?>
<h2 id="wiz-upgrade">Upgrade IgnitionDeck</h2>
<div id="license-details" data-license="<?php echo esc_attr( $license ); ?>">
    <p class="wix-form-group">License Key</p>
    <div class="wizard-license-box">
    <input type="text" class="wiz-control-inline" placeholder="Your IgnitionDeck License Key" value="<?php echo esc_attr(get_option('id_license_key')); ?>" />
    <button type="button" class="wiz-button" onclick="wizard_action('verify_license', this)" data-license="<?php echo esc_attr($license); ?>" <?php echo ($installed === 'active') ? '' : 'disabled="disabled" data-title="Please install and activate all dependencies"'; ?>>
        <?php echo esc_html($button_text); ?>
    </button>
    </div>
    <?php
    $allowed_tags = wp_kses_allowed_html( 'post' );
    $allowed_tags['input']=array(
      'type'        => true,
      'name'        => true,
      'value'       => true,
      'placeholder' => true,
      'class'       => true,
      'id'          => true,
      'style'       => true,
      'onclick'       => true,
      'disabled'       => true,
      'checked'       => true,

    );
    $allowed_tags['button']=array(
      'type'        => true,
      'name'        => true,
      'value'       => true,
      'placeholder' => true,
      'class'       => true,
      'id'          => true,
      'style'       => true,
      'onclick'       => true,
      'disabled'       => true,
      'checked'       => true,

    );
    
    echo wp_kses( $expiry.$payments, $allowed_tags );
    ?>
    <div class="license-details">
        <?php
        // don't display the promo boxes if the license is expired, just keep them focused on the renewal
        if (($license_expiry!='expired') && $license_expiry!='no_activations_left') {
            $html = '<br /><br /><div class="license-details-content">';
            switch($license_name) {
                case 'Echelon':
                    $html .= '<div class="wiz-half">
                    '.$core_promo.'
                    </div>
                    <div class="wiz-half">
                    '.$managed_promo.'
                    </div>';
                    break;
                case 'Core':
                    if ($license_expiry=='lifetime' && $license!='free') {
                        // Special promos for Lifetime Enterprise users
                        $html .= '<div class="wiz-half">
                        '.$core_promo.'
                        </div>
                        <div class="wiz-half">
                        '.$managed_promo.'
                        </div>';
                    } else {
                        $html .= '<div class="wiz-half">
                        '.$deployed_promo.'
                        </div>
                        <div class="wiz-half">
                        '.$managed_promo.'
                        </div>';
                    }
                    break;           
                case 'Deployed':
                    $html .= '<div class="wiz-half">
                    '.$customizations_promo.'
                    </div>
                    <div class="wiz-half">
                    '.$managed_promo.'
                    </div>';
                    break;           
                case 'Managed':
                    $html .= '<div class="wiz-half">
                    '.$customizations_promo.'
                    </div>
                    <div class="wiz-half">
                    '.$support_promo.'
                    </div>';
                    break;           
                default: // Free
                    $html .= '<div class="wiz-half">
                    '.$core_promo.'
                    </div>
                    <div class="wiz-half">
                    '.$deployed_promo.'
                    </div>';
                    break;           
            }
            $html .= '</div>';
            
            // Use wp_kses with the custom allowed tags
            echo wp_kses($html, $allowed_tags);
        }
        ?>
        </div>
    </div><br /><br />
<a class="skip" href="<?php echo esc_url( admin_url( 'admin.php?page=idf-themes' ) ); ?>">Skip this step</a>
