<?php
	function EWD_FEUP_One_Click_Install_Pages_List() {
		$Pages = get_pages();
	
		echo "<option value='Edit Profile (Newly Created)'>" . esc_html__("Edit Profile", 'front-end-only-users') . " (" . esc_html__("Newly Created", 'front-end-only-users') . ")</option>";
		echo "<option value='Register (Newly Created)'>" . esc_html__("Register", 'front-end-only-users') . " (" . esc_html__("Newly Created", 'front-end-only-users') . ")</option>";
		echo "<option value='Login (Newly Created)'>" . esc_html__("Login", 'front-end-only-users') . " (" . esc_html__("Newly Created", 'front-end-only-users') . ")</option>";
		echo "<option value='Logout (Newly Created)'>" . esc_html__("Logout", 'front-end-only-users') . " (" . esc_html__("Newly Created", 'front-end-only-users') . ")</option>";
		echo "<option value='Forgot Password (Newly Created)'>" . esc_html__("Forgot Password", 'front-end-only-users') . " (" . esc_html__("Newly Created", 'front-end-only-users') . ")</option>";
		echo "<option value='Confirm Forgot Password (Newly Created)'>" . esc_html__("Confirm Forgot Password", 'front-end-only-users') . " (" . esc_html__("New", 'front-end-only-users') . ")</option>";
		echo "<option value='Change Password (Newly Created)'>" . esc_html__("Change Password", 'front-end-only-users') . " (" . esc_html__("Newly Created", 'front-end-only-users') . ")</option>";
		echo "<option value='Login Logout Toggle (Newly Created)'>" . esc_html__("Login-Logout Toggle", 'front-end-only-users') . " (" . esc_html__("Newly Created", 'front-end-only-users') . ")</option>";
		echo "<option value='User Profile (Newly Created)'>" . esc_html__("User Profile", 'front-end-only-users') . " (" . esc_html__("Newly Created", 'front-end-only-users') . ")</option>";
		echo "<option value='User Search (Newly Created)'>" . esc_html__("User Search", 'front-end-only-users') . " (" . esc_html__("Newly Created", 'front-end-only-users') . ")</option>";
		echo "<option value='User List (Newly Created)'>" . esc_html__("User List", 'front-end-only-users') . " (" . esc_html__("Newly Created", 'front-end-only-users') . ")</option>";
		echo "<option value='User Data (Newly Created)'>" . esc_html__("User Data", 'front-end-only-users') . " (" . esc_html__("Newly Created", 'front-end-only-users') . ")</option>";
	
		foreach ($Pages as $Page) {
			echo '<option value="' . esc_attr($Page->post_title) . '">' . esc_html(mb_substr($Page->post_title, 0, 35)) . '</option>';
		}
	}
	
	function EWD_FEUP_One_Click_Install_Fields_List() {
		global $wpdb;
		global $ewd_feup_fields_table_name;
	
		$Fields = $wpdb->get_results("SELECT * FROM $ewd_feup_fields_table_name ORDER BY Field_Order");
	
		foreach ($Fields as $Field) {
			echo '<option value="' . esc_attr($Field->Field_Name) . '">' . esc_html($Field->Field_Name) . '</option>';
		}
	}
	
	function EWD_FEUP_Insert_Attribute_Input($Page, $Attribute) {
		$input_name = esc_attr($Page['Input_Name'] . "_" . $Page['Attribute_' . $Attribute]);
		if ($Page['Attribute_' . $Attribute . '_Type'] == "page") {
			echo "<select name='{$input_name}'>";
			EWD_FEUP_One_Click_Install_Pages_List();
			echo "</select>";
		}
		elseif ($Page['Attribute_' . $Attribute . '_Type'] == "plugin field") {
			echo "<select name='{$input_name}'>";
			EWD_FEUP_One_Click_Install_Fields_List();
			echo "</select>";
		}
		elseif ($Page['Attribute_' . $Attribute . '_Type'] == "boolean") {
			echo "<select name='{$input_name}'>";
			echo "<option value='No'>" . esc_html__('No', 'front-end-only-users') . "</option>";
			echo "<option value='Yes'>" . esc_html__('Yes', 'front-end-only-users') . "</option>";
			echo "</select>";
		}
		elseif ($Page['Attribute_' . $Attribute . '_Type'] == "text") {
			echo "<input type='text' name='{$input_name}'>";
		}
	}

	$Page_Options[0]['Name'] = __("Edit Profile", 'front-end-only-users');
	$Page_Options[0]['Input_Name'] = "Edit_Profile";
	$Page_Options[0]['Attribute_One'] = "redirect_page";
	$Page_Options[0]['Attribute_One_Label'] = "Redirect To:";
	$Page_Options[0]['Attribute_One_Type'] = "page";
	$Page_Options[0]['Attribute_Two'] = "login_page";
	$Page_Options[0]['Attribute_Two_Label'] = "Login Page:";
	$Page_Options[0]['Attribute_Two_Type'] = "page";
	$Page_Options[0]['Attribute_Three'] = "";
	$Page_Options[0]['Attribute_Three_Label'] = "";
	$Page_Options[0]['Attribute_Three_Type'] = "";

	$Page_Options[1]['Name'] = __("Register", 'front-end-only-users');
	$Page_Options[1]['Input_Name'] = "Register";
	$Page_Options[1]['Attribute_One'] = "redirect_page";
	$Page_Options[1]['Attribute_One_Label'] = "Redirect To:";
	$Page_Options[1]['Attribute_One_Type'] = "page";
	$Page_Options[1]['Attribute_Two'] = "";
	$Page_Options[1]['Attribute_Two_Label'] = "";
	$Page_Options[1]['Attribute_Two_Type'] = "";
	$Page_Options[1]['Attribute_Three'] = "";
	$Page_Options[1]['Attribute_Three_Label'] = "";
	$Page_Options[1]['Attribute_Three_Type'] = "";

	$Page_Options[2]['Name'] = __("Login", 'front-end-only-users');
	$Page_Options[2]['Input_Name'] = "Login";
	$Page_Options[2]['Attribute_One'] = "redirect_page";
	$Page_Options[2]['Attribute_One_Label'] = "Redirect To:";
	$Page_Options[2]['Attribute_One_Type'] = "page";
	$Page_Options[2]['Attribute_Two'] = "";
	$Page_Options[2]['Attribute_Two_Label'] = "";
	$Page_Options[2]['Attribute_Two_Type'] = "";
	$Page_Options[2]['Attribute_Three'] = "";
	$Page_Options[2]['Attribute_Three_Label'] = "";
	$Page_Options[2]['Attribute_Three_Type'] = "";

	$Page_Options[3]['Name'] = __("Logout", 'front-end-only-users');
	$Page_Options[3]['Input_Name'] = "Logout";
	$Page_Options[3]['Attribute_One'] = "redirect_page";
	$Page_Options[3]['Attribute_One_Label'] = "Redirect To:";
	$Page_Options[3]['Attribute_One_Type'] = "page";
	$Page_Options[3]['Attribute_Two'] = "no_message";
	$Page_Options[3]['Attribute_Two_Label'] = "Display Logout Message:";
	$Page_Options[3]['Attribute_Two_Type'] = "boolean";
	$Page_Options[3]['Attribute_Three'] = "";
	$Page_Options[3]['Attribute_Three_Label'] = "";
	$Page_Options[3]['Attribute_Three_Type'] = "";

	$Page_Options[4]['Name'] = __("Forgot Password", 'front-end-only-users');
	$Page_Options[4]['Input_Name'] = "Forgot_Password";
	$Page_Options[4]['Attribute_One'] = "redirect_page";
	$Page_Options[4]['Attribute_One_Label'] = "Redirect To:";
	$Page_Options[4]['Attribute_One_Type'] = "page";
	$Page_Options[4]['Attribute_Two'] = "loggedin_page";
	$Page_Options[4]['Attribute_Two_Label'] = "Logged in Redirect Page:";
	$Page_Options[4]['Attribute_Two_Type'] = "page";
	$Page_Options[4]['Attribute_Three'] = "reset_email_url";
	$Page_Options[4]['Attribute_Three_Label'] = "Reset Email Page URL:";
	$Page_Options[4]['Attribute_Three_Type'] = "page";

	$Page_Options[5]['Name'] = __("Confirm Forgotten Password", 'front-end-only-users');
	$Page_Options[5]['Input_Name'] = "Confirm_Forgot_Password";
	$Page_Options[5]['Attribute_One'] = "redirect_page";
	$Page_Options[5]['Attribute_One_Label'] = "Redirect To:";
	$Page_Options[5]['Attribute_One_Type'] = "page";
	$Page_Options[5]['Attribute_Two'] = "login_page";
	$Page_Options[5]['Attribute_Two_Label'] = "Login Page:";
	$Page_Options[5]['Attribute_Two_Type'] = "page";
	$Page_Options[5]['Attribute_Three'] = "";
	$Page_Options[5]['Attribute_Three_Label'] = "";
	$Page_Options[5]['Attribute_Three_Type'] = "";

	$Page_Options[6]['Name'] = __("Change Password", 'front-end-only-users');
	$Page_Options[6]['Input_Name'] = "Change_Password";
	$Page_Options[6]['Attribute_One'] = "redirect_page";
	$Page_Options[6]['Attribute_One_Label'] = "Redirect To:";
	$Page_Options[6]['Attribute_One_Type'] = "page";
	$Page_Options[6]['Attribute_Two'] = "login_page";
	$Page_Options[6]['Attribute_Two_Label'] = "Login Page:";
	$Page_Options[6]['Attribute_Two_Type'] = "page";
	$Page_Options[6]['Attribute_Three'] = "";
	$Page_Options[6]['Attribute_Three_Label'] = "";
	$Page_Options[6]['Attribute_Three_Type'] = "";

	$Page_Options[7]['Name'] = __("Login-Logout Toggle (Optional)", 'front-end-only-users');
	$Page_Options[7]['Input_Name'] = "Login_Logout_Toggle";
	$Page_Options[7]['Attribute_One'] = "login_redirect_page";
	$Page_Options[7]['Attribute_One_Label'] = "Login Redirect To:";
	$Page_Options[7]['Attribute_One_Type'] = "page";
	$Page_Options[7]['Attribute_Two'] = "logout_redirect_page";
	$Page_Options[7]['Attribute_Two_Label'] = "Logout Redirect To:";
	$Page_Options[7]['Attribute_Two_Type'] = "page";
	$Page_Options[7]['Attribute_Three'] = "";
	$Page_Options[7]['Attribute_Three_Label'] = "";
	$Page_Options[7]['Attribute_Three_Type'] = "";

	$Page_Options[8]['Name'] = __("User Profile (Optional)", 'front-end-only-users');
	$Page_Options[8]['Input_Name'] = "User_Profile";
	$Page_Options[8]['Attribute_One'] = "login_page";
	$Page_Options[8]['Attribute_One_Label'] = "Login Page:";
	$Page_Options[8]['Attribute_One_Type'] = "page";
	$Page_Options[8]['Attribute_Two'] = "omit_fields";
	$Page_Options[8]['Attribute_Two_Label'] = "Don't Display:";
	$Page_Options[8]['Attribute_Two_Type'] = "plugin field";
	$Page_Options[8]['Attribute_Three'] = "login_necessary";
	$Page_Options[8]['Attribute_Three_Label'] = "Login to See Profiles?";
	$Page_Options[8]['Attribute_Three_Type'] = "boolean";

	$Page_Options[9]['Name'] = __("User Search (Optional)", 'front-end-only-users');
	$Page_Options[9]['Input_Name'] = "User_Search";
	$Page_Options[9]['Attribute_One'] = "login_page";
	$Page_Options[9]['Attribute_One_Label'] = "Login Page:";
	$Page_Options[9]['Attribute_One_Type'] = "page";
	$Page_Options[9]['Attribute_Two'] = "search_fields";
	$Page_Options[9]['Attribute_Two_Label'] = "Search Fields:";
	$Page_Options[9]['Attribute_Two_Type'] = "plugin field";
	$Page_Options[9]['Attribute_Three'] = "user_profile_page";
	$Page_Options[9]['Attribute_Three_Label'] = "User Profile Page:";
	$Page_Options[9]['Attribute_Three_Type'] = "page";

	$Page_Options[10]['Name'] = __("User List (Optional)", 'front-end-only-users');
	$Page_Options[10]['Input_Name'] = "User_List";
	$Page_Options[10]['Attribute_One'] = "field_name";
	$Page_Options[10]['Attribute_One_Label'] = "Field to Match:";
	$Page_Options[10]['Attribute_One_Type'] = "plugin field";
	$Page_Options[10]['Attribute_Two'] = "field_value";
	$Page_Options[10]['Attribute_Two_Label'] = "Value to Match:";
	$Page_Options[10]['Attribute_Two_Type'] = "text";
	$Page_Options[10]['Attribute_Three'] = "user_profile_page";
	$Page_Options[10]['Attribute_Three_Label'] = "User Profile Page:";
	$Page_Options[10]['Attribute_Three_Type'] = "page";

	$Page_Options[11]['Name'] = __("User Data (Optional)", 'front-end-only-users');
	$Page_Options[11]['Input_Name'] = "User_Data";
	$Page_Options[11]['Attribute_One'] = "field_name";
	$Page_Options[11]['Attribute_One_Label'] = "Field to Display:";
	$Page_Options[11]['Attribute_One_Type'] = "plugin field";
	$Page_Options[11]['Attribute_Two'] = "plain_text";
	$Page_Options[11]['Attribute_Two_Label'] = "Text Only:";
	$Page_Options[11]['Attribute_Two_Type'] = "boolean";
	$Page_Options[11]['Attribute_Three'] = "";
	$Page_Options[11]['Attribute_Three_Label'] = "";
	$Page_Options[11]['Attribute_Three_Type'] = "";
?>

<form action='admin.php?page=EWD-FEUP-options&DisplayPage=Dashboard&Action=EWD_FEUP_OneClickInstall' method='post'>
	<?php wp_nonce_field( 'EWD_FEUP_Admin_Nonce', 'EWD_FEUP_Admin_Nonce' ); ?>

	<br />

	<div class="ewd-feup-admin-section-heading"><?php esc_html_e('One Click Setup', 'front-end-only-users'); ?></div>
	
	<table class="form-table">
		<thead>
			<tr>
				<th class="ewd-feup-admin-no-info-button"><?php esc_html_e('Include?', 'front-end-only-users'); ?></th>
				<th class="ewd-feup-admin-no-info-button"><?php esc_html_e('Page Name', 'front-end-only-users'); ?></th>
				<th class="ewd-feup-admin-no-info-button"><?php esc_html_e('Attribute One', 'front-end-only-users'); ?></th>
				<th class="ewd-feup-admin-no-info-button"><?php esc_html_e('Attribute Two', 'front-end-only-users'); ?></th>
				<th class="ewd-feup-admin-no-info-button"><?php esc_html_e('Attribute Three', 'front-end-only-users'); ?></th>
			</tr>
		</thead>
		<tbody>
			<?php foreach ($Page_Options as $Page) { ?>
				<tr>
					<input type='hidden' name="<?php echo esc_attr($Page['Input_Name']); ?>_attribute_one" value="<?php echo esc_attr($Page['Attribute_One']); ?>" />
					<input type='hidden' name="<?php echo esc_attr($Page['Input_Name']); ?>_attribute_two" value="<?php echo esc_attr($Page['Attribute_Two']); ?>" />
					<input type='hidden' name="<?php echo esc_attr($Page['Input_Name']); ?>_attribute_three" value="<?php echo esc_attr($Page['Attribute_Three']); ?>" />
					<td>
						<input type='checkbox' name='page[]' value="<?php echo esc_attr($Page['Input_Name']); ?>" />
					</td>
					<td>
						<label for="<?php echo esc_attr($Page['Input_Name']); ?>"><?php echo esc_html($Page['Name']); ?></label>
					</td>
					<td>
						<?php echo esc_html($Page['Attribute_One_Label']); ?><br />
						<?php EWD_FEUP_Insert_Attribute_Input($Page, "One"); ?>
					</td>
					<td>
						<?php echo esc_html($Page['Attribute_Two_Label']); ?><br />
						<?php EWD_FEUP_Insert_Attribute_Input($Page, "Two"); ?>
					</td>
					<td>
						<?php echo esc_html($Page['Attribute_Three_Label']); ?><br />
						<?php EWD_FEUP_Insert_Attribute_Input($Page, "Three"); ?>
					</td>
				</tr>
			<?php } ?>
		</tbody>
	</table>

	<?php 
		if ($EWD_FEUP_Full_Version == "Yes") {
			echo "<input type='submit' class='button button-primary feup-one-click-submit' name='One_Click_Install_Submit' value='" . esc_attr__('Create Pages', 'front-end-only-users') . "' />";
		} else {
			echo "<input type='submit' class='button button-primary feup-one-click-submit' name='One_Click_Install_Submit' value='" . esc_attr__('Upgrade to Use!', 'front-end-only-users') . "' disabled />";
		}
	?>
</form>
