+<?php
+
+/**
+ * Admin.php
+ *
+ * PHP version 5.3
+ *
+ * @category Toolkit
+ * @package Package
+ * @author Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license Gaslight Media
+ * @version SVN: (0.1)
+ * @link <>
+ */
+
+/**
+ * Toolkit_Package_Admin
+ *
+ * Description of Admin
+ *
+ * @category Toolkit
+ * @package Package
+ * @author Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license Gaslight Media
+ * @release Release: (0.1)
+ * @link <>
+ */
+class GlmHomeAway_Admin_Controller
+{
+ public $path;
+
+ public function __construct($path)
+ {
+ $this->path = $path;
+ add_action('admin_menu', array($this, 'glm_homeaway_add_admin_menu'));
+ add_action('admin_init', array($this, 'glm_homeaway_settings_init'));
+ }
+
+ static public function activate_plugin()
+ {
+ GlmHomeAway_Admin_Controller::add_capability();
+ }
+
+ static public function deactivate_plugin()
+ {
+ GlmHomeAway_Admin_Controller::remove_capability();
+ }
+
+ static public function add_capability()
+ {
+ $roles = get_editable_roles();
+ foreach ($GLOBALS['wp_roles']->role_objects as $key => $role) {
+ if (isset($roles[$key]) && $role->has_cap(GLM_HOMEAWAY_BUILT_IN_CAPABILITY)) {
+ $role->add_cap(GLM_HOMEAWAY_NEW_CAPABILITY);
+ }
+ }
+ }
+
+ static public function remove_capability()
+ {
+ $roles = get_editable_roles();
+ foreach ($GLOBALS['wp_roles']->role_objects as $key => $role) {
+ if (isset($roles[$key]) && $role->has_cap(GLM_HOMEAWAY_NEW_CAPABILITY)) {
+ $role->remove_cap(GLM_HOMEAWAY_NEW_CAPABILITY);
+ }
+ }
+ }
+
+ static public function glm_homeaway_uninstall()
+ {
+ delete_option(GLM_HOMEAWAY_SETTINGS);
+ }
+
+ public function glm_homeaway_add_admin_menu()
+ {
+ add_options_page(
+ 'HomeAway',
+ 'HomeAway',
+ GLM_HOMEAWAY_NEW_CAPABILITY,
+ 'glm_homeaway',
+ array($this, 'glm_homeaway_options_page'),
+ 'dashicons-admin-network'
+ );
+ }
+
+ public function glm_homeaway_settings_exist()
+ {
+ if (false == get_option(GLM_HOMEAWAY_SETTINGS)) {
+ add_option(GLM_HOMEAWAY_SETTINGS);
+ }
+ }
+
+ public function glm_homeawayAddSettingTextField($name, $label, $type)
+ {
+ switch ($type) {
+ case 'text':
+ $callback = 'glm_homeawayRenderText';
+ break;
+ case 'textarea':
+ $callback = 'glm_homeawayRenderTextArea';
+ break;
+ default:
+ return false;
+ break;
+ }
+ add_settings_field(
+ $name,
+ __($label, 'wordpress'),
+ array($this, $callback),
+ GLM_HOMEAWAY_OPTION_GROUP,
+ 'glm_homeaway_' . GLM_HOMEAWAY_OPTION_GROUP . '_section',
+ $name
+ );
+ }
+
+ public function glm_homeaway_settings_init()
+ {
+ register_setting(GLM_HOMEAWAY_OPTION_GROUP, GLM_HOMEAWAY_SETTINGS);
+ add_filter(
+ 'option_page_capability_' . GLM_HOMEAWAY_OPTION_GROUP,
+ array($this, 'glm_homeaway_option_page_capability')
+ );
+ add_settings_section(
+ 'glm_homeaway_' . GLM_HOMEAWAY_OPTION_GROUP . '_section',
+ __('Edit Setting', 'wordpress'),
+ array($this, 'glm_homeaway_settings_section_callback'),
+ GLM_HOMEAWAY_OPTION_GROUP
+ );
+
+ $fieldNames = array(
+ array(
+ 'name' => 'user_id',
+ 'label' => 'User Id',
+ 'type' => 'text'
+ ),
+ array(
+ 'name' => 'password',
+ 'label' => 'Password',
+ 'type' => 'text'
+ ),
+ array(
+ 'name' => 'coid',
+ 'label' => 'COID',
+ 'type' => 'text'
+ ),
+ );
+
+ foreach ($fieldNames as $field) {
+ $this->glm_homeawayAddSettingTextField(
+ $field['name'],
+ $field['label'],
+ $field['type']
+ );
+ }
+ }
+
+ public function glm_homeawayRenderText($fieldName)
+ {
+ static $options;
+ if (!$options) {
+ $options = get_option(GLM_HOMEAWAY_SETTINGS);
+ }
+ include $this->path . 'views/text.php';
+ }
+
+ public function glm_homeawayRenderTextArea($fieldName)
+ {
+ static $options;
+ $options = get_option(GLM_HOMEAWAY_SETTINGS);
+ include $this->path . 'views/textArea.php';
+ }
+
+ public function glm_homeaway_settings_section_callback()
+ {
+ echo __('HomeAway Creds', 'wordpress');
+ }
+
+ public function glm_homeaway_option_page_capability($capability)
+ {
+ return GLM_HOMEAWAY_NEW_CAPABILITY;
+ }
+
+ public function glm_homeaway_options_page()
+ {
+ if (current_user_can(GLM_HOMEAWAY_NEW_CAPABILITY)) {
+ include $this->path . 'views/optionsPage.php';
+ } else {
+ include $this->path . 'views/deniedAccess.php';
+ }
+ }
+
+}