<?php

/**
 * Included file to display admin options
 */
WpSolrExtensions::require_once_wpsolr_extension(WpSolrExtensions::OPTION_LICENSES, true);
// Options name
$option_name = OptionLicenses::get_option_name(WpSolrExtensions::OPTION_LICENSES);
// Options object
$license_manager = new OptionLicenses();
?>

	<script>
		jQuery(document).on("click", "#<?php 
echo OptionLicenses::AJAX_VERIFY_LICENCE;
?>
, #<?php 
echo OptionLicenses::AJAX_ACTIVATE_LICENCE;
?>
, #<?php 
echo OptionLicenses::AJAX_DEACTIVATE_LICENCE;
?>
", function (e) {

			// Remember this for ajax
			var current = this;

			// Show progress
			var button_clicked = jQuery(this);
			var button_form = button_clicked.parents('.wpsolr_form_license');
			var buttonText = button_clicked.val(); // Remmember button text
function wpsolr_activate()
{
    if (!is_multisite()) {
        /**
         * Mark licenses
         */
        WpSolrExtensions::require_once_wpsolr_extension(WpSolrExtensions::OPTION_LICENSES, true);
        OptionLicenses::upgrade_licenses();
    }
}
function wpsolr_admin_init()
{
    WpSolrExtensions::require_once_wpsolr_extension(WpSolrExtensions::OPTION_INDEXES, true);
    register_setting(OptionIndexes::get_option_name(WpSolrExtensions::OPTION_INDEXES), OptionIndexes::get_option_name(WpSolrExtensions::OPTION_INDEXES));
    WpSolrExtensions::require_once_wpsolr_extension(WpSolrExtensions::OPTION_LICENSES, true);
    register_setting(OptionIndexes::get_option_name(WpSolrExtensions::OPTION_LICENSES), OptionLicenses::get_option_name(WpSolrExtensions::OPTION_LICENSES));
    register_setting('solr_form_options', 'wdm_solr_form_data');
    register_setting('solr_res_options', 'wdm_solr_res_data');
    register_setting('solr_facet_options', 'wdm_solr_facet_data');
    register_setting('solr_search_field_options', WPSOLR_Option::OPTION_SEARCH_FIELDS);
    register_setting('solr_sort_options', WPSOLR_Option::OPTION_SORTBY);
    register_setting('solr_localization_options', 'wdm_solr_localization_data');
    register_setting('solr_extension_groups_options', 'wdm_solr_extension_groups_data');
    register_setting('solr_extension_s2member_options', 'wdm_solr_extension_s2member_data');
    register_setting('solr_extension_wpml_options', 'wdm_solr_extension_wpml_data');
    register_setting('solr_extension_polylang_options', 'wdm_solr_extension_polylang_data');
    register_setting('solr_extension_qtranslatex_options', 'wdm_solr_extension_qtranslatex_data');
    register_setting('solr_operations_options', 'wdm_solr_operations_data');
    register_setting('solr_extension_woocommerce_options', 'wdm_solr_extension_woocommerce_data');
    register_setting('solr_extension_acf_options', 'wdm_solr_extension_acf_data');
    register_setting('solr_extension_types_options', 'wdm_solr_extension_types_data');
    register_setting('solr_extension_bbpress_options', 'wdm_solr_extension_bbpress_data');
    register_setting('extension_embed_any_document_opt', WPSOLR_Option::OPTION_EMBED_ANY_DOCUMENT);
    register_setting('extension_pdf_embedder_opt', WPSOLR_Option::OPTION_PDF_EMBEDDER);
    register_setting('extension_google_doc_embedder_opt', WPSOLR_Option::OPTION_GOOGLE_DOC_EMBEDDER);
}
    /**
     * Metabox callback
     *
     * @param $post Post
     *
     * @return string
     */
    public function action_add_meta_boxes_callback($post)
    {
        if (!$this->get_is_show_meta_box($post)) {
            return;
        }
        $license_manager = new OptionLicenses();
        wp_nonce_field(basename(__FILE__), self::METABOX_NONCE_ID);
        $post_meta = get_post_meta($post->ID);
        ?>

		<?php 
        // Include license activation popup boxes in all admin tabs
        add_thickbox();
        if (!(defined('DOING_AJAX') && DOING_AJAX)) {
            // Do not load in Ajax
            require_once WPSOLR_PLUGIN_DIR . '/classes/extensions/licenses/admin_options.inc.php';
        }
        ?>


		<div class="wpsolr-metabox-row-content">
			<label for="<?php 
        echo esc_attr(self::METABOX_FIELD_IS_DO_NOT_INDEX);
        ?>
">
				<input type="checkbox" name="<?php 
        echo esc_attr(self::METABOX_FIELD_IS_DO_NOT_INDEX);
        ?>
"
				       id="<?php 
        echo esc_attr(self::METABOX_FIELD_IS_DO_NOT_INDEX);
        ?>
"
				       value="<?php 
        echo esc_attr(self::METABOX_CHECKBOX_YES);
        ?>
" <?php 
        if (isset($post_meta[self::METABOX_FIELD_IS_DO_NOT_INDEX])) {
            checked($post_meta[self::METABOX_FIELD_IS_DO_NOT_INDEX][0], self::METABOX_CHECKBOX_YES);
        }
        ?>
 />
				<?php 
        _e('Do not search', 'wpsolr');
        ?>
			</label>
		</div>

		<div class="wpsolr-metabox-row-content">
			<label for="<?php 
        echo esc_attr(self::METABOX_FIELD_IS_DO_INDEX_ACF_FIELD_FILES);
        ?>
">
				<input type="checkbox"
				       name="<?php 
        echo esc_attr(self::METABOX_FIELD_IS_DO_INDEX_ACF_FIELD_FILES);
        ?>
"
				       id="<?php 
        echo esc_attr(self::METABOX_FIELD_IS_DO_INDEX_ACF_FIELD_FILES);
        ?>
"
				       value="<?php 
        echo esc_attr(self::METABOX_CHECKBOX_YES);
        ?>
" <?php 
        if (isset($post_meta[self::METABOX_FIELD_IS_DO_INDEX_ACF_FIELD_FILES])) {
            checked($post_meta[self::METABOX_FIELD_IS_DO_INDEX_ACF_FIELD_FILES][0], self::METABOX_CHECKBOX_YES);
        }
        ?>
					<?php 
        echo $license_manager->get_license_enable_html_code(OptionLicenses::LICENSE_PACKAGE_ACF);
        ?>
				/>
				<?php 
        echo $license_manager->show_premium_link(OptionLicenses::LICENSE_PACKAGE_ACF, _x('Search in ACF fields file content', 'wpsolr'), true, true);
        ?>
			</label>
		</div>

		<?php 
        /*
        ?>
        <div class="wpsolr-metabox-row-content">
        	<label for="<?php echo esc_attr( self::METABOX_FIELD_IS_DO_INDEX_EMBED_ANY_DOCUMENT ); ?>">
        		<input type="checkbox"
        		       name="<?php echo esc_attr( self::METABOX_FIELD_IS_DO_INDEX_EMBED_ANY_DOCUMENT ); ?>"
        		       id="<?php echo esc_attr( self::METABOX_FIELD_IS_DO_INDEX_EMBED_ANY_DOCUMENT ); ?>"
        		       value="<?php echo esc_attr( self::METABOX_CHECKBOX_YES ); ?>" <?php if ( isset ( $post_meta[ self::METABOX_FIELD_IS_DO_INDEX_EMBED_ANY_DOCUMENT ] ) ) {
        	checked( $post_meta[ self::METABOX_FIELD_IS_DO_INDEX_EMBED_ANY_DOCUMENT ][0], self::METABOX_CHECKBOX_YES );
        } ?>
        			<?php echo $license_manager->get_license_enable_html_code( OptionLicenses::LICENSE_PACKAGE_EMBED_ANY_DOCUMENT ); ?>
        		/>
        		<?php echo $license_manager->show_premium_link( OptionLicenses::LICENSE_PACKAGE_EMBED_ANY_DOCUMENT, _x( 'Search in Embed Any Document', 'wpsolr' ), true, true ); ?>
        	</label>
        </div>
        */
        ?>

	<?php 
    }
 /**
  * Get all activated licenses
  *
  * @return array
  */
 public static function get_activated_licenses_titles()
 {
     $results = array();
     $option_licenses = new OptionLicenses();
     $licenses = $option_licenses->get_licenses();
     foreach ($licenses as $license_code => $license) {
         if ($option_licenses->get_license_is_activated($license_code)) {
             array_push($results, $option_licenses->get_license_title($license_code));
         }
     }
     return $results;
 }