<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}
//Callback for deactivatin plugins for the search version
function eos_dp_search_callback(){
	if( !current_user_can( 'activate_plugins' ) ){
	?>
		<h2><?php _e( 'Sorry, you have not the right for this page','eos-dp' ); ?></h2>
		<?php
		return;
	}
	$active_plugins = eos_dp_active_plugins();
	$plugins = eos_dp_get_plugins();
	$search = eos_dp_get_option( 'eos_dp_search' );
	wp_nonce_field( 'eos_dp_search_setts', 'eos_dp_search_setts' );
	eos_dp_alert_plain_permalink();
	eos_dp_navigation();
	?>
	<section id="eos-dp-search-section" class="eos-dp-section">
		<h2><span class="dashicons dashicons-search"></span><?php _e( 'Search results page.','eos-dp' ); ?></h2>
		<div style="margin-bottom:12px;margin-top:32px">
			<span class="eos-dp-active-wrp eos-dp-icon-wrp"><input style="width:20px;height:20px;margin:0" type="checkbox"></span>
			<span class="eos-dp-legend-txt"><?php _e( 'Plugin active','eos-dp' ); ?></span>
			<span class="eos-dp-not-active-wrp eos-dp-icon-wrp"><input style="width:20px;height:20px;margin:0" type="checkbox" checked=""></span>
			<span class="eos-dp-legend-txt"><?php _e( 'Plugin not active','eos-dp' ); ?></span>
		</div>
		<div style="margin:32px 0 16px 0">
			<span id="fdp-select-all-single-post" class="button"><?php _e( 'Enable All','eos-dp' ); ?></span>
			<span id="fdp-unselect-all-single-post" class="button"><?php _e( 'Disable All','eos-dp' ); ?></span>
		</div>
		<div id="eos-dp-wrp" style="margin-top:32px">
			<table id="eos-dp-setts">
				<tbody>
				<?php
				$n = 0;
				foreach( $active_plugins as $p ){
					if( isset( $plugins[$p] ) ){
						$plugin_name = strtoupper( str_replace( '-',' ',dirname( $p ) ) );
						$checked = $search && in_array( $p,$search ) ? '' : ' checked';
						$details_url = add_query_arg(
							array(
								'tab' => 'plugin-information',
								'plugin' => dirname( $p ),
								'TB_iframe' => true,
								'eos_dp' => $p,
								'eos_dp_info' => 'true'
							),
							admin_url( 'plugin-install.php' )
						);
						?>
						<tr>
							<td class="eos-dp-mobile-chk-col <?php echo '' !== $checked ? 'eos-dp-active' : ''; ?>">
								<div class="eos-dp-td-chk-wrp">
									<input id="eos-dp-search-<?php echo $n + 1; ?>" class="eos-dp-search" title="<?php printf( __( 'Activate/deactivate %s everywhere on search','eos-dp' ),esc_attr( $plugin_name ) ); ?>" data-path="<?php echo $p; ?>" type="checkbox"<?php echo $checked; ?> />
								</div>
							</td>
							<td class="eos-dp-name-td"><span class="dashicons dashicons-admin-plugins"></span><a title="<?php _e( 'View details','eos-dp' ); ?>" target="_blank" class="eos-dp-no-decoration" href="<?php echo esc_url( $details_url ); ?>"><?php echo esc_html( $plugin_name ); ?></a></td>
						</tr>
						<?php
						++$n;
					}
				}
				?>
				</tbody>
			</table>
		</div>
		<?php eos_dp_save_button(); ?>
	</section>
	<?php
}
