<?php defined('ABSPATH') or die('Direct Access Restricted!');
add_action('admin_notices', 'o365_plugin_admin_notice');
function o365_menu_o365_settings()
{
	if (!function_exists('is_plugin_active')) {
		require_once(ABSPATH . '/wp-admin/includes/plugin.php');
	}

?>
	<div class="wrap wrap_message">
		<?php
		
		$network_shared_settings = '';
		$network_shared_settings = o365_get_setting('shared_settings');
		if (isset($_POST['o365_user_auth_settings_nonce']) && wp_verify_nonce($_POST['o365_user_auth_settings_nonce'], 'o365_user_auth_settings_nonce') && current_user_can('administrator')) {
			$file_name = "";
			$file_url = "";
			$azure_group_mapping_with_wprole = "";
			$role_based_redirect_url = "";
			if( is_multisite() ) {
				$o365_settings = get_site_option('o365_settings'); // get setting option
			} else {
				$o365_settings = get_option('o365_settings'); // get setting option
			}
			if ( is_multisite() && isset($o365_settings['b2b_shared_settings']) && $o365_settings['b2b_shared_settings'] == "yes")
			{
				$azure_login_setting_flow = get_site_option( 'azure_login_setting_flow', '' );
			} else {
				$azure_login_setting_flow = get_option( 'azure_login_setting_flow', '' );
			}
			$azure_login_setting_flow = json_decode($azure_login_setting_flow);
			if( ! is_object( $azure_login_setting_flow ) ) {
				$azure_login_setting_flow = json_decode($azure_login_setting_flow);	
			}

			$tenant_login_mapping = '';
			$tenant_role_based_redirect_url = '';
			
			if (!empty($_FILES) && !empty($_FILES['azure_image_login_link']['name'])) {
				$upload_dir = wp_upload_dir();
				$tmp_name = $_FILES['azure_image_login_link']['tmp_name'];
				$file_name = $_FILES['azure_image_login_link']['name'];
				if (wp_mkdir_p($upload_dir['path'])) {
					$file = $upload_dir['path'] . '/' . $file_name;
					$file_url = $upload_dir['url'] . '/' . $file_name;
				} else {
					$file = $upload_dir['basedir'] . '/' . $file_name;
					$file_url = $upload_dir['baseurl'] . '/' . $file_name;
				}
				move_uploaded_file($tmp_name, $file);
			} else {
				if (isset($azure_login_setting_flow->azure_image_login_link)) {
					$file_url = $azure_login_setting_flow->azure_image_login_link;
				}
			}
			$azure_login_link_text = sanitize_text_field($_POST['azure_login_link_text']);
			$azure_print_login_link = sanitize_text_field($_POST['azure_print_login_link']);

			/*added new fields:start*/
			$azure_login_css_text = htmlspecialchars($_POST['azure_login_css_text']);
			
			if (isset($_POST['logout_redirect_uri']) && !empty($_POST['logout_redirect_uri'])) {
				$logout_redirect_uri = $_POST['logout_redirect_uri'];
			} else {
				$logout_redirect_uri = site_url('wp-login.php', 'login');
			}

			/*added new fields:end*/
			$azure_image_login_link = sanitize_text_field($file_url);
			$azure_login_client_id = o365_get_setting("client_id");
			$azure_login_client_secret = o365_get_setting("client_secret");
			$block_edit_profile = "";
			$block_edit_profile_picture = "";
			$azure_login_nested_groups_login = '';
			$azure_login_endpoint_type = '';
			$o365_user_auth_multi_tenant_active = "";
			$o365_user_auth_allow_all_domain_user = '';
			$o365_user_auth_domain = "";
			$o365_user_auth_allow_azure_group = "";
			if (isset($_POST['o365_user_auth_multi_tenant_active'])) {
				$o365_user_auth_multi_tenant_active = $_POST['o365_user_auth_multi_tenant_active'];
				$o365_user_auth_domain = htmlspecialchars(isset($_POST['o365_user_auth_domain']) ? $_POST['o365_user_auth_domain'] : '');
			}
			//Allow all domain user
			if (isset($_POST['o365_user_auth_allow_all_domain_user'])) {
				$o365_user_auth_allow_all_domain_user = $_POST['o365_user_auth_allow_all_domain_user'];
			} else if (isset($_POST['o365_user_auth_allow_azure_group']) && $_POST['o365_user_auth_allow_azure_group'] != "") {
				$o365_user_auth_allow_azure_group = serialize($_POST['o365_user_auth_allow_azure_group']);
			}
			if (isset($_POST['block_edit_profile'])) {
				$block_edit_profile = $_POST['block_edit_profile'];
			}
			if (isset($_POST['block_edit_profile_picture'])) {
				$block_edit_profile_picture = $_POST['block_edit_profile_picture'];
			}

			if (isset($_POST['azure_login_endpoint_type'])) {
				$azure_login_endpoint_type = $_POST['azure_login_endpoint_type'];
			}

			if (isset($_POST['azure_login_nested_groups_login'])) {
				$azure_login_nested_groups_login = $_POST['azure_login_nested_groups_login'];
			}
			
			if (isset($_POST['login_mapping'])) {
				$azure_group_mapping_with_wprole = serialize($_POST['login_mapping']);
			}
			//Azure Tenant Name mapped with WP Role
			if (isset($_POST['tenant_login_mapping'])) {
				$tenant_login_mapping = serialize($_POST['tenant_login_mapping']);
			}
			//Redirect URL based on Tenant Name and User role
			if (isset($_POST['tenant_role_based_redirect_url'])) {
				$tenant_role_based_redirect_url = serialize($_POST['tenant_role_based_redirect_url']);
			}
			
			if (isset($_POST['default_wp_role']) && !empty($_POST['default_wp_role'])) {
				$default_wp_role = $_POST['default_wp_role'];
			} else {
				$default_wp_role = 'subscriber';
			}
			$user_auth_mapping_fields =  serialize($_POST['user_auth_fields_mapping']);
			
			if (isset($_POST['default_role_redirect_url']) && !empty($_POST['default_role_redirect_url'])) {
				$default_role_redirect_url = $_POST['default_role_redirect_url'];
			} else {
				$default_role_redirect_url = home_url();
			}
			
			if (isset($_POST['role_based_redirect_url'])) {
				$role_based_redirect_url = serialize($_POST['role_based_redirect_url']);
			}
			
			if (isset($_POST['o365_user_auth_redirect_after_login'])) {
				$azure_login_setting_flow->after_login_redirect_url =  $_POST['o365_user_auth_redirect_after_login'];
			}
			if ($azure_login_setting_flow) {
				$azure_login_setting_flow->azure_login_link_text = $azure_login_link_text;
				/*added new fields:start*/
				$azure_login_setting_flow->azure_login_css_text = $azure_login_css_text;
				/*added new fields:end*/
				$azure_login_setting_flow->client_id = $azure_login_client_id;
				$azure_login_setting_flow->client_secret = $azure_login_client_secret;
				$azure_login_setting_flow->azure_print_login_link = $azure_print_login_link;
				$azure_login_setting_flow->azure_image_login_link = $azure_image_login_link;
				$azure_login_setting_flow->azure_group_mapping_with_wprole = $azure_group_mapping_with_wprole;
				$azure_login_setting_flow->default_wp_role = $default_wp_role;
				$azure_login_setting_flow->role_based_redirect_url = $role_based_redirect_url;
				$azure_login_setting_flow->default_role_redirect_url = $default_role_redirect_url;
				$azure_login_setting_flow->user_auth_mapping_fields = $user_auth_mapping_fields;
				$azure_login_setting_flow->o365_user_auth_multi_tenant_active = $o365_user_auth_multi_tenant_active;
				$azure_login_setting_flow->o365_user_auth_domain = $o365_user_auth_domain;
				$azure_login_setting_flow->o365_user_auth_allow_azure_group = $o365_user_auth_allow_azure_group;
				$azure_login_setting_flow->block_edit_profile = $block_edit_profile;
				$azure_login_setting_flow->azure_login_endpoint_type = $azure_login_endpoint_type;
				$azure_login_setting_flow->azure_login_nested_groups_login = $azure_login_nested_groups_login;
				$azure_login_setting_flow->block_edit_profile_picture = $block_edit_profile_picture;
				$azure_login_setting_flow->logout_redirect_uri = $logout_redirect_uri;
				$azure_login_setting_flow->tenant_login_mapping = $tenant_login_mapping;
				$azure_login_setting_flow->tenant_role_based_redirect_url = $tenant_role_based_redirect_url;
				$azure_login_setting_flow->o365_user_auth_allow_all_domain_user = $o365_user_auth_allow_all_domain_user;
				$azure_newJsonString = json_encode($azure_login_setting_flow);
				$o365_settings = o365_get_settings();
				
				if( is_multisite() && ! empty($o365_settings['b2b_shared_settings']) && $o365_settings['b2b_shared_settings'] == 'yes' ) {
					update_site_option('azure_login_setting_flow', $azure_newJsonString);
				} else {
					update_option('azure_login_setting_flow', $azure_newJsonString);
				}
			}
			echo '<div class="updated"><p><strong>SUCCESS: </strong>User Settings Updated successfully.</p></div>';
		}
		//wp_register_script( 'o365_settings_tab_panels_script', O365_URL. 'js/SpryTabbedPanels.js' );
		//wp_enqueue_script( 'o365_settings_tab_panels_script' );
		/* register, localize and enqueue tabbed javascript start*/
		wp_register_script('o365_settings_script', O365_URL . 'js/o365_settings.js');
		if (isset($_GET['bt']) && $_GET['bt'] == 'user') {
			$js_obj_array = array("active_tab" => "1");
		} else if (isset($_GET['bt']) && $_GET['bt'] == 'webhooks') {
			$js_obj_array = array("active_tab" => "2");
		} if (isset($_GET['bt']) && $_GET['bt'] == 'revoketoken') {
			$js_obj_array = array("active_tab" => "5");
		} else {
			$js_obj_array = array("active_tab" => "0");
		}

		$js_obj_array['site_url'] = site_url();

		wp_localize_script('o365_settings_script', 'o365_js_obj', $js_obj_array);
		wp_enqueue_script('o365_settings_script');

		/* register, localize and enqueue tabbed javascript end*/
		//wp_enqueue_style( 'connection-style', O365_URL."css/o365_settings.css" );

		$fields = array(
			'client_id'					=> array('Application (client) ID', '', 'text', 'Please enter the Application ID, taken from the app registration created in your azure portal.'),
			'client_secret'				=> array('Application Key', '', 'text', 'Please enter the Application Key, taken from the app registration\'s >> setting section created in your azure portal.'),
			'tenant_name'				=> array('Tenant Name', '', 'text', 'Please enter the Tenant Name, this is the prefix section of the microsoft specific subdomains example: "myTenantName" taken form myTenantName.onmicrosoft.com or myTenantName.sharepoint.com, taken from the "domain name" section associated your active directory account.'),
			'tenant_id'					=> array('Directory (tenant) ID', '', 'text', 'Please enter the Tenant ID, taken from the "domain name" section associated your active directory account.'),
			'o365_national_endpoints'	=> array('Authorization Endpoint', '', 'text', ' Please choose an endpoint for authorizations. This URL will used in all Plugins as a Authorization Endpoint.'),
			// 'o365_auth_version'			=> array('Authorization Version', '', 'text', ' Please choose a Graph Version for API. This URL will used in all Plugins for API endpoints.'),
			'o365_graph_endpoints'		=> array('Graph Endpoint', '', 'text', ' Please choose an endpoint for authorizations. This URL will used in all Plugins for calling API.'),
			'client_object'				=> array('Application Object ID', '', 'text', 'Please enter the Application Object ID, taken from the app registration created in your azure portal.'),
			'o365_display_user_id'		=> array('M365 User ID', '', 'text', ' Please enter the Application Object ID, taken from the Azure AD. This user id will used in OneDrive and OutLook Display Plugins.'),
			'o365_dynamic_crm_url'		=> array('M365 Dynamic CRM', '', 'text', ' Please enter the URL of Dynamic CRM. This URL will used in Dynamic CRM Display Plugins.'),
		);
		?>
		<div class="office-365-add-ons">
			<div class="office-365-add-ons-wp-list-table">
				<div class="head-office-365-add-ons">
					<div class="an_left_column">
						<span>Office 365 : Settings</span>
					</div>
					<div class="an_right_column">
						<div class="head-right-office-365-add-ons">
							<div class="an_display_cell">
								<div class="an_display_cell_inner"></div>
							</div>
							<div class="an_display_cell">
								<div class="an_display_cell_inner"></div>
							</div>
							<div class="an_display_cell">
								<div class="an_display_cell_inner">
									<a target="_blank" href="https://www.wpintegrate.com/support/"><img src="<?php echo o365_get_image('help-picture.png'); ?>" width="25px" height="25px" /> <span>Support</span></a>
								</div>
							</div>
							<div class="an_clear"></div>
						</div>
					</div>
					<div class="an_clear"></div>
				</div>
			</div>
		</div>
		<div id="TabbedPanels1" class="TabbedPanels">
			<ul class="TabbedPanelsTabGroup">
				<li class="TabbedPanelsTab" tabindex="0">General</li>
				<?php do_action("o365_user_auth_tab_title"); ?>
				<?php do_action("o365_subscription_addon_tab_title"); ?>
				<?php if( is_plugin_active( 'o365-wp-ms-booking/o365-wp-ms-booking.php' )) {?>
					<li class="TabbedPanelsTab" tabindex="0" id="msbooking_payment_details">Payment</li>
				<?php }?>
				<li class="TabbedPanelsTab" tabindex="0">Server Info</li>
				<li class="TabbedPanelsTab" tabindex="0">Premium Plans</li>
				<?php
				$allWpOfficePlugins = o365_get_all_plugins_info();
				$show_revoke_tab = 0;
				foreach ($allWpOfficePlugins as $plugin_folder => $plugin_details) {
					$plugin = $plugin_folder . '/' . $plugin_details['file'];
					if (is_plugin_active($plugin) && (isset($plugin_details['access_token_used']) && $plugin_details['access_token_used'] == "yes")) {
						$show_revoke_tab = 1;
					}
				}
				if (!empty($show_revoke_tab) && $show_revoke_tab == 1) {
				?>
					<li class="TabbedPanelsTab" tabindex="0" id="o365_revoke_token_tab">Token Manager</li>
				<?php
				} ?>
			</ul>
			<div class="TabbedPanelsContentGroup">
				<div class="TabbedPanelsContent" style="display: block;">
					<form action="" method="post" class="o365_settings_general">
						<input type="hidden" name="o365_settings_nonce" value="<?php echo wp_create_nonce('o365_settings_nonce'); ?>" />
						<table class="form-table">
							<tr class="settings-area-header">
								<th colspan="2">
									<h3 style="margin: 0px;">Application Registration</h3>
								</th>
							</tr>
							<?php foreach ($fields as $name => $label) :
								if ($name == "client_object") {
									$check_display = "";
									if (!is_plugin_active('o365-user-auth/o365-user-auth.php')) {
										$check_display = 'style="display:none"';
									}
									?>
										<tr <?php echo $check_display; ?> class="form-field">
											<td><label for="<?php echo $name ?>" class="settings_label"><?php echo $label[0]; ?> </label>
												<span class="ques_img"><span class="ques_img1"></span>
													<div class="question_block">
														<h6><?php echo $label[0]; ?></h6>
														<?php echo $label[3]; ?>
													</div>
												</span>
												<div class="settings_label_one"><?php echo $label[1]; ?></div>
											</td>
											<td><?php $value = o365_get_setting($name); ?>
												<input type="<?php echo $label[2]; ?>" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_attr($value); ?>" />
												<br /></td>
										</tr>
									<?php
								} else if ($name == "o365_display_user_id") {
									$check_display = "";
									$check_required = "";
									if (!is_plugin_active('o365-wp-onedrive-display/o365-wp-onedrive-display.php') && !is_plugin_active('o365-wp-outlook-display/o365-wp-outlook-display.php')) {
										$check_display = 'style="display:none"';
										$check_required = 'required="required"';
									}
									?>
										<tr <?php echo $check_display; ?> class="form-field">
											<td><label for="<?php echo $name ?>" class="settings_label"><?php echo $label[0]; ?> </label>
												<span class="ques_img"><span class="ques_img1"></span>
													<div class="question_block">
														<h6><?php echo $label[0]; ?></h6>
														<?php echo $label[3]; ?>
													</div>
												</span>
												<div class="settings_label_one"><?php echo $label[1]; ?></div>
											</td>
											<td><?php $value = o365_get_setting($name); ?>
												<input <?php echo $check_required; ?> type="<?php echo $label[2]; ?>" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_attr($value); ?>" />
												<br /></td>
										</tr>
									<?php
								} else if ($name == "o365_dynamic_crm_url") {
									$check_display = "";
									$check_required = "";
									if (!is_plugin_active('o365-wp-crm-display/o365-wp-crm-display.php')) {
										$check_display = 'style="display:none"';
										$check_required = 'required="required"';
									}
									?>
									<tr <?php echo $check_display; ?> class="form-field">
										<td><label for="<?php echo $name ?>" class="settings_label"><?php echo $label[0]; ?> </label>
											<span class="ques_img"><span class="ques_img1"></span>
												<div class="question_block">
													<h6><?php echo $label[0]; ?></h6>
													<?php echo $label[3]; ?>
												</div>
											</span>
											<div class="settings_label_one"><?php echo $label[1]; ?></div>
										</td>
										<td><?php $value = o365_get_setting($name); ?>
											<input <?php echo $check_required; ?> type="<?php echo $label[2]; ?>" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_attr($value); ?>" />
											<br /></td>
									</tr>
									<?php
								} 
								/*else if( $name == "o365_auth_version" ) {
									?>
									<tr class="form-field">
										<td><label for="<?php echo $name ?>" class="settings_label"><?php echo $label[0]; ?> </label>
											<span class="ques_img"><span class="ques_img1"></span>
												<div class="question_block">
													<h6><?php echo $label[0]; ?></h6>
													<?php echo $label[3]; ?>
												</div>
											</span>
											<div class="settings_label_one"><?php echo $label[1]; ?></div>
										</td>
										<td><?php $value = o365_get_setting($name);?>
											<select required="required" id="<?php echo $name; ?>" name="<?php echo $name; ?>">
												<option value="v1.0" <?php echo ($value == 'v1.0')?'selected':''; ?>>v1.0</option>
												<option value="v2.0" <?php echo ($value == 'v2.0')?'selected':''; ?>>v2.0</option>
											</select>
										</td>
									</tr>
									<?php
								}*/ 
								else if( $name == "o365_national_endpoints" ) {
									?>
									<tr class="form-field">
										<td><label for="<?php echo $name ?>" class="settings_label"><?php echo $label[0]; ?> </label>
											<span class="ques_img"><span class="ques_img1"></span>
												<div class="question_block">
													<h6><?php echo $label[0]; ?></h6>
													<?php echo $label[3]; ?>
												</div>
											</span>
											<div class="settings_label_one"><?php echo $label[1]; ?></div>
										</td>
										<td><?php $value = o365_get_setting($name); ?>
											<input required="required" type="<?php echo $label[2]; ?>" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo !empty($value)?$value:'https://login.microsoftonline.com'; ?>" />
										</td>
									</tr>
									<?php
								} else if( $name == "o365_graph_endpoints" ) {
										?>
										<tr class="form-field">
											<td><label for="<?php echo $name ?>" class="settings_label"><?php echo $label[0]; ?> </label>
												<span class="ques_img"><span class="ques_img1"></span>
													<div class="question_block">
														<h6><?php echo $label[0]; ?></h6>
														<?php echo $label[3]; ?>
													</div>
												</span>
												<div class="settings_label_one"><?php echo $label[1]; ?></div>
											</td>
											<td><?php $value = o365_get_setting($name); ?>
												<input required="required" type="<?php echo $label[2]; ?>" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo !empty($value)?$value:'https://graph.microsoft.com'; ?>" />
											</td>
										</tr>
										<?php
								} else {
									?>
									<tr class="form-field">
										<td><label for="<?php echo $name ?>" class="settings_label"><?php echo $label[0]; ?> </label>
											<span class="ques_img"><span class="ques_img1"></span>
												<div class="question_block">
													<h6><?php echo $label[0]; ?></h6>
													<?php echo $label[3]; ?>
												</div>
											</span>
											<div class="settings_label_one"><?php echo $label[1]; ?></div>
										</td>
										<td><?php $value = o365_get_setting($name); ?>
											<input required="required" type="<?php echo $label[2]; ?>" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_attr($value); ?>" />
											<br />
											<?php if ($name == 'tenant_name') {
												echo '<span style="font-size: 11px;">Example: [dwsnow].onmicrosoft.com, should just be entered as "dwsnow".</span>';
											} ?>
										</td>
									</tr>
									<?php
								}
							endforeach; ?>
							<?php
							include_once(ABSPATH . 'wp-admin/includes/plugin.php');
							if (is_plugin_active('o365-wp-sp-calendar-display/o365-wp-sp-calendar-display.php')) {
								$sp_display_clean_cache_button_tr = apply_filters('o365_sp_display_clean_cache_button', "");
								echo $sp_display_clean_cache_button_tr;
							} elseif (is_plugin_active('o365-wp-outlook-display/o365-wp-outlook-display.php')) {
								$clean_cache_button_tr = apply_filters('o365_clean_cache_button', "");
								echo $clean_cache_button_tr;
							}
							if (is_plugin_active('o365-wp-yammer-display/o365-wp-yammer-display.php')) {
								$sp_display_clean_cache_button_tr = apply_filters('o365_wp_yammer_ci_cs_setting', "");
								echo $sp_display_clean_cache_button_tr;
							}

							// User Name and Password used in the powerBI plugin
							$settings_content = apply_filters("o365_base_addons_settings_content", "");
							if (isset($settings_content) && $settings_content != "") {
							?>
								<!-- <tr class="settings-area-header">
									<th colspan="2"><h3 style="margin: 0px;">System User Credentials</h3></th>
								</tr> -->
							<?php
								echo $settings_content;
							}
							?>
							<tr>
								<td></td>
								<?php
								if (is_multisite() && $network_shared_settings == 'yes') {
									$o365_base_verify = get_site_option('o365_base_plugin_is_verify');
								} else {
									$o365_base_verify = get_option('o365_base_plugin_is_verify');
								}
								//$o365_base_verify = get_option( 'o365_base_plugin_is_verify' );
								if ($o365_base_verify == '1') {
									echo "<td style='color:#0C0'>This plugin has been verified</td>";
								} else {
									echo "<td style='color:#F00'>This plugin has been un-verified</td>";
								}
								?></td>
							</tr>
							<?php if (is_multisite() && is_network_admin()) { ?>
								<tr class="form-field">
									<td><label for="shared_settings" class="settings_label">Multisite Shared Settings</label><span class="ques_img"><span class="ques_img1"></span>
											<div class="question_block">
												<h6>Multisite Shared Settings</h6>
												If checked, settings will be shared for all sites, another need to configure settings separately in all sub-sites.
											</div>
										</span></td>
									<td><input type="checkbox" name="shared_settings" id="shared_settings" value="yes" <?php echo o365_get_setting('shared_settings') == 'yes' ? 'checked' : ''; ?> />
									</td>
								</tr>
								<?php if( is_plugin_active('o365-user-auth/o365-user-auth.php')) {?>
									<tr class="form-field">
										<td>
											<label for="b2b_shared_settings" class="settings_label">User Auth Multisite Shared Settings</label><span class="ques_img"><span class="ques_img1"></span>
												<div class="question_block">
													<h6>User Auth Multisite Shared Settings</h6>
													If checked, settings will be shared for all sites, another need to configure settings separately in all sub-sites.
												</div>
											</span>
										</td>
										<td>
											<input type="checkbox" name="b2b_shared_settings" id="b2b_shared_settings" value="yes" <?php echo o365_get_setting('b2b_shared_settings') == 'yes' ? 'checked' : ''; ?> />
										</td>
									</tr>
								<?php } ?>
							<?php } ?>
							<tr title="">
								<td><label for="delete_settings" class="settings_label">Delete Settings on Deactivation</label>
									<span class="ques_img"><span class="ques_img1"></span>
										<div class="question_block">
											<h6>Delete settings on deactivation</h6>
											If checked, this option will delete all the settings associated with the O365 plugins, when they are deactivated.
										</div>
									</span></td>
								<td><input type="checkbox" name="delete_settings" id="delete_settings" value="yes" <?php echo o365_get_setting('delete_settings') == 'yes' ? 'checked' : ''; ?> />
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<?php 
									$network_shared_settings = o365_get_setting('shared_settings');
									if ( is_multisite() && $network_shared_settings == 'yes' && ! is_network_admin() ) {
										?>
										<p class="submit">
                                            <!--<input type="submit" class="button button-primary" value="Save settings & Get Authentication"/>-->
                                            <input type="button" class="button button-primary" id="save_settings_get_authentication" name="save_settings_get_authentication" value="Save settings & Get Authentication" disabled />
                                        </p>
										<?php
									}
									else
									{
										?>
										<p class="submit">
                                            <!--<input type="submit" class="button button-primary" value="Save settings & Get Authentication"/>-->
                                            <input type="button" class="button button-primary" id="save_settings_get_authentication" name="save_settings_get_authentication" value="Save settings & Get Authentication" />
                                        </p>
										<?php
									}
								?>
								</td>
							</tr>
						</table>
					</form>
					<div>
						<b>Please Note:</b>
						</br>
						If you changed the Application ID, Application Key or Tenant Name, please create and configure a new app registration in your azure portal.
						<?php
						if (is_plugin_active('o365-user-auth/o365-user-auth.php')) {
							echo '</br>If you changed the Application ID, Application Key or Tenant Name, please re-configure User Auth settings.';
						}
						?>

					</div>

				</div>
				<?php do_action("o365_user_auth_html_content"); ?>
				<?php do_action("o365_subscription_addon_html_content"); ?>
				<?php if( is_plugin_active( 'o365-wp-ms-booking/o365-wp-ms-booking.php' )) {?>
					<div class="TabbedPanelsContent">
						<?php
							$o365wp_booking_data = apply_filters("o365wp_booking_data","");
							echo $o365wp_booking_data;
						?>
    				</div>
				<?php }?>
				<div class="TabbedPanelsContent">
					<table class="current_sync_table">
						<tr class="current_sync_head_top">
							<td>Name</td>
							<td>Info</td>
							<td>Requirement</td>
						</tr>
						<tr>
							<td>
								Curl
							</td>
							<td>
								<?php
								$check_curl_function =  function_exists('curl_version');
								if (isset($check_curl_function) && $check_curl_function == '1') {
									echo "ON";
								} else {
									echo "OFF";
								}
								?>
							</td>
							<td>ON</td>
						</tr>
						<tr>
							<td>
								PHP
							</td>
							<td>
								<?php echo $version = phpversion(); ?>
							</td>
							<td>7+</td>
						</tr>
						<tr>
							<td>
								Server execution Time
							</td>
							<td>
								<?php echo $sync_max_execution_time = ini_get('max_execution_time'); ?>
							</td>
							<td> Minimum 1500</td>
						</tr>
						<tr>
							<td>
								MySql
							</td>
							<td>
								<?php
								$check_curl_function =  function_exists('mysql_get_server_info');
								$check_mysqli_function = function_exists('mysqli_get_server_info');
								if (isset($check_curl_function) && $check_curl_function == '1') {
									echo "MySql";
								} else if (isset($check_mysqli_function) && $check_mysqli_function == '1') {
									echo "MySqli";
								} else {
									echo "No";
								}
								?>
							</td>
							<td>MySql</td>
						</tr>
						<tr>
							<td>
								Server Type
							</td>
							<td>
								<?php
								echo $_SERVER['SERVER_SOFTWARE'];
								?>
							</td>
							<td>Apache</td>
						</tr>
						<tr>
							<td>
								HTTP_AUTHORIZATION
								<!--Authorization Server Variable-->
							</td>
							<td>
								<?php
								if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
									echo "Enable";
								} else {
									echo "Disable";
								}
								?>
							</td>
							<td>Enable</td>
						</tr>
					</table>
				</div>
				<div class="TabbedPanelsContent">
					<?php
					$o365_flow_license_plan_content = apply_filters("o365_license_plan_html_content", "");
					echo $o365_flow_license_plan_content;
					?>
				</div>
				<!-- Revoke Tokens Tab -->
				<?php
				if (!empty($show_revoke_tab) && $show_revoke_tab == 1) {
				?>
					<div class="TabbedPanelsContent">
						<div class="office-365-license" id="office-365-license">
							<div class="products_heading">
								<h3 class="h1_heading">Revoke Tokens</h3>
							</div>
							<div class="wrapper">
								<ul>
									<?php
									$o365wp_refresh_tokens_content = apply_filters("o365wp_refresh_tokens_content", "");
									echo $o365wp_refresh_tokens_content;
									?>
								</ul>
							</div>
						</div>
					</div>
				<?php } ?>
				<!-- Revoke Tokens Tab -->
			</div>
		</div>
		<div id="please-wait-bg" style="display:none;"> <span style="text-align: center;position: absolute;top: 50%;"> <img src="<?php echo o365_get_image('loader/loader.gif'); ?>" /> </span> </div>
	</div>
<?php
}  // End of function