コード例 #1
0
    public static function settings_page($tabs)
    {
        $current_tab = isset($_GET['tab']) ? $_GET['tab'] : HA_Common::GENERAL_SETTINGS_TAB;
        ?>
		<div class="wrap">
			<?php 
        HA_Admin_Page_View::page_header('Settings');
        HA_Admin_Page_View::show_page_tabs(HA_Common::SETTINGS_PAGE_SLUG, $tabs, $current_tab);
        if (isset($_GET['updated']) && isset($_GET['page'])) {
            add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated');
        }
        settings_errors();
        if ($current_tab == HA_Common::GENERAL_SETTINGS_TAB) {
            HA_Admin_Page_View::show_settings_form(HA_Common::GENERAL_SETTINGS_KEY);
        } else {
            if ($current_tab == HA_Common::SCHEDULE_SETTINGS_TAB) {
                HA_Admin_Page_View::show_settings_form(HA_Common::SCHEDULE_SETTINGS_KEY);
            } else {
                if ($current_tab == HA_Common::HEAT_MAP_SETTINGS_TAB) {
                    HA_Admin_Page_View::show_settings_form(HA_Common::HEAT_MAP_SETTINGS_KEY);
                } else {
                    if ($current_tab == HA_Common::URL_FILTERS_SETTINGS_TAB) {
                        HA_Admin_Page_View::show_settings_form(HA_Common::URL_FILTERS_SETTINGS_KEY);
                    } else {
                        if ($current_tab == HA_Common::DATABASE_SETTINGS_TAB) {
                            ?>
				<form method="post" name="<?php 
                            echo HA_Common::DATABASE_SETTINGS_KEY;
                            ?>
" action="options.php" class="hut-settings-form">
					<?php 
                            wp_nonce_field('update-options');
                            settings_fields(HA_Common::DATABASE_SETTINGS_KEY);
                            do_settings_sections(HA_Common::DATABASE_SETTINGS_KEY);
                            ?>
					<p class="submit">
						<?php 
                            submit_button(null, 'primary', 'submit', false, null);
                            submit_button('Clear Database', 'delete', 'clear-database', false, null);
                            ?>
					</p>
					<input type="hidden" name="clear-database-flag" id="clear-database-flag" value="false" />
				</form>
				<?php 
                        } else {
                            if ($current_tab == HA_Common::CUSTOM_EVENTS_SETTINGS_TAB) {
                                echo '<h3>Custom Events</h3>';
                                if (isset($_POST['eventType']) && isset($_POST['customEvent'])) {
                                    $event_type = isset($_POST['eventType']) ? $_POST['eventType'] : '';
                                    $custom_event = isset($_POST['customEvent']) ? $_POST['customEvent'] : '';
                                    $description = isset($_POST['description']) ? $_POST['description'] : '';
                                    $url = isset($_POST['url']) ? trim($_POST['url']) : '';
                                    $url = HA_Common::normalize_url($url);
                                    $url = addslashes($url);
                                    $is_form_submit = isset($_POST['isFormSubmit']) ? true : false;
                                    $is_mouse_click = isset($_POST['isMouseClick']) ? true : false;
                                    $is_touchscreen_tap = isset($_POST['isTouchscreenTap']) ? true : false;
                                    $valid_input = true;
                                    if (strlen(trim($custom_event)) == 0) {
                                        echo '<div class="error"><p>An event type is required.</p></div>';
                                        $valid_input = false;
                                    }
                                    if (strlen(trim($custom_event)) == 0) {
                                        echo '<div class="error"><p>A custom event jQuery selector is required.</p></div>';
                                        $valid_input = false;
                                    }
                                    if ($valid_input == true) {
                                        global $wpdb;
                                        try {
                                            $results = $wpdb->insert($wpdb->prefix . HA_Common::CUSTOM_EVENT_TBL_NAME, array(HA_Common::DESCRIPTION_COLUMN => $description, HA_Common::CUSTOM_EVENT_COLUMN => $custom_event, HA_Common::EVENT_TYPE_COLUMN => $event_type, HA_Common::URL_COLUMN => $url, HA_Common::IS_FORM_SUBMIT_COLUMN => $is_form_submit, HA_Common::IS_MOUSE_CLICK_COLUMN => $is_mouse_click, HA_Common::IS_TOUCHSCREEN_TAP_COLUMN => $is_touchscreen_tap));
                                            echo '<div class="success"><p>Custom event added successfully.</p></div>';
                                        } catch (Exception $e) {
                                            echo '<div class="error"><p>An error occurred. ' . $e->getMessage() . '</p></div>';
                                        }
                                    }
                                }
                                ?>
				<form method="post">
					<table class="form-table">
						<tbody>
							<tr valign="top">
								<th scope="row">Custom Event</th>
								<td>
									<input type="text" name="customEvent" id="customEvent" value="" />
									<p class="description">Enter a jQuery element selector.</p>
								</td>
							</tr>
							<tr valign="top">
								<th scope="row">Event Type</th>
								<td>
									<input type="text" name="eventType" id="eventType" value="" />
									<p class="description">Categorise the event with a named type.</p>
								</td>
							</tr>
							<tr valign="top">
								<th scope="row">Trigger events</th>
								<td>
									<input type="checkbox" name="isMouseClick" id="isMouseClick" value="" checked="checked"/>
									<label for="isMouseClick">Mouse click?</label><br />
									<input type="checkbox" name="isToushcreenTap" id="isToushcreenTap" value="" />
									<label for="isTouchscreenTap">Touchscreen tap?</label><br />
									<input type="checkbox" name="isFormSubmit" id="isFormSubmit" value="" />
									<label for="isTouchscreenTap">Form submit?</label>
									<p class="description">Is the custom event associated with a form submit JavaScript event? If none are checked, mouse click is defaulted.</p>
								</td>
							</tr>
							<tr valign="top">
								<th scope="row">Description</th>
								<td>
									<input type="text" name="description" id="description" value="" />
									<p class="description">Add a description of the event.</p>
								</td>
							</tr>
							
							<tr valign="top">
								<th scope="row">URL</th>
								<td>
									<input class="regular-text" type="text" name="url" id="url" value="" />&nbsp(Optional, leave empty to target all URLs)
									<p class="description">You can enter a URL to target a specific page.</p>
								</td>
							</tr>
						</tbody>
					</table>
					
					<input type="submit" class="button button-secondary" value="Add Custom Event" />
				</form>
		
				<br />
							
				<form method="post">
					<?php 
                                $custom_event_table = new HA_Custom_Event_Table();
                                $custom_event_table->prepare_items();
                                $custom_event_table->display();
                                ?>
				</form>
				<?php 
                            }
                        }
                    }
                }
            }
        }
        ?>
			
		</div>
		<div class="clear" />
		<?php 
    }