<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


 // About page directory path
            $pluginName = "Wpforms" ; 

            if (!defined('ESIGN_'. strtoupper(preg_replace("/\s+/", "", $pluginName)) . '_ABOUT_PATH'))
                    define('ESIGN_'. strtoupper(preg_replace("/\s+/", "", $pluginName)) . '_ABOUT_PATH', dirname(__FILE__));
            
            if (!defined('ESIGN_'. strtoupper(preg_replace("/\s+/", "", $pluginName)) . '_ABOUT_URL'))
                    define('ESIGN_'. strtoupper(preg_replace("/\s+/", "", $pluginName)) . '_ABOUT_URL', plugins_url("/", __FILE__));

require_once( plugin_dir_path( __FILE__ ) . 'includes/esig-activations-states.php' );
require_once( plugin_dir_path( __FILE__ ) . 'includes/esig-about-load.php' );



$esigAbout = new esig_Addon_About($pluginName);
$esigAbout->hooks();

add_action('admin_notices', array($esigAbout, 'requirement'));
if (strpos(esig_wpform_get("page"), "esign-wpforms-about") === false) {
add_action('esig_admin_notices', array($esigAbout, 'requirement'));
}

function wpforms_message($esigStatus,$pluginName)
        {
            $screen = get_current_screen();
            $screenName = "admin_page_esign-wpforms-about";
            $asterisk = "" ; 
            
            if($screen->id == $screenName)
            {
               $asterisk = "*"; 
            }

            $wpformsID = strpos($screen->id, 'wpforms');
            if($wpformsID === false && $screen->id != 'plugins') return;
            
            switch ($esigStatus){

                case 'wpe_inactive':
                  return '<h4> ' . esc_attr($asterisk) . 'Your WP E-Signature Core plugin is not enabled. Please install and activate it to use WP E-Signature. <a class="about-button" href="'. esig_plugin_activation_link("e-signature/e-signature.php") .'">Activate WP E-Signature</a></h4>';
                  break;
                case 'wpe_expired':
                  return '<h4>' . esc_attr($asterisk) . 'You willl need to activate your WP E-Signature license to run the WPForms Signature add-on.  <a class="about-button" href="admin.php?page=esign-licenses-general">Enter your license here</a> </h4>';
                  break;
                case 'wpe_active_basic':
                  return '<h4>' . esc_attr($asterisk) . 'Your WP E-Signature Add-on plugin is not installed. Please install and activate it to use WP E-Signature.  <a class="about-button" href="'. admin_url("admin.php?page=esign-addons") .'">Install WP E-Signature Add-on</a></h4>';
                  break;
                case 'wpe_inactive_pro':
                  return '<h4>' . esc_attr($asterisk) . 'Your WP E-Signature Add-on plugin is not enabled. Please install and activate it to use WP E-Signature. <a class="about-button" href="'. esig_plugin_activation_link("e-signature-business-add-ons/e-signature-business-add-ons.php") .'">Enable Add-Ons</a></h4>';
                  break;
                case 'wpe_active_pro':

                  if (!function_exists('wpforms')) {// Notice about add-on dependent 3rd party plugin if not installed
                   return '<h4>WPForms is not installed. Please install it to use the E-Signature add-on you have enabled in the Integrations tab. <a href="https://wordpress.org/plugins/wpforms-lite/">Get it here now</a></h4>';
                  }
                  elseif(!class_exists('WpEsignSad\Hooks\Admin\SadAdmin')){// Notice about stand alone documents if not enabled
                    return '<h4>WP E-Signature <a href="https://www.approveme.com/wpesign-features/stand-alone-documents/?utm_source=wprepo&utm_medium=link&utm_campaign=wpforms" target="_blank">"Stand Alone Documents"</a> Add-on is not active. Please enable WP E-Signature Stand Alone Documents  <a class="about-button" href="'. admin_url("admin.php?page=esign-addons&tab=disable&esig_action=enable&plugin_url=esig-stand-alone-docs%2Fesig-sad.php&plugin_name=WP%20E-Signature%20-%20Stand%20Alone%20Documents") .'">Enable it now </a> </h4>';
                  }

                  break;
                case 'no_wpe':
                    return ' <h4>' . esc_attr($asterisk) . 'Your WP E-Signature Core plugin is not installed. Please install and activate it to use WP E-Signature.  &nbsp; <span class="button-container"><a class="about-button" href="https://www.approveme.com/wpforms-signature-special/?utm_campaign=wprepo&">Get your WP E-Signature license</a></span></h4>';
                    break;
                default:
                  return false;
                  break;
              }
        }

  /**
  *  Remove all admin notices from e-signature pages. 
  */
 add_action('in_admin_header', function () {

      $page  = isset($_GET['page']) ? esig_wpform_get('page') : false ;

      if (empty($page)) {
        return false;
      }
      
      if(!empty($page)  && !preg_match("/esign-/i",$page))
      {
        return false;
      }
      
      remove_all_actions('admin_notices');
      remove_all_actions('all_admin_notices');

},1000);


