Form now submits
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 4 May 2018 18:52:16 +0000 (14:52 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 4 May 2018 18:52:16 +0000 (14:52 -0400)
Submits the form to the saved options.

assets/lifeB.png [new file with mode: 0755]
assets/send.png [new file with mode: 0755]
css/admin.css [new file with mode: 0644]
defines.php
models/admin/settings/support.php [new file with mode: 0644]
models/admin/support/index.php
setup/adminTabs.php
setup/validActions.php
views/admin/settings/support.html [new file with mode: 0644]
views/admin/support/index.html
views/admin/support/thankyou.html [new file with mode: 0644]

diff --git a/assets/lifeB.png b/assets/lifeB.png
new file mode 100755 (executable)
index 0000000..e3c39e1
Binary files /dev/null and b/assets/lifeB.png differ
diff --git a/assets/send.png b/assets/send.png
new file mode 100755 (executable)
index 0000000..e57df49
Binary files /dev/null and b/assets/send.png differ
diff --git a/css/admin.css b/css/admin.css
new file mode 100644 (file)
index 0000000..334ca44
--- /dev/null
@@ -0,0 +1,96 @@
+/* glm-support-setting-form */
+.glm-support-setting-form {
+    margin: 10px 0;
+    max-width: 400px;
+    padding: 20px 12px 10px 20px;
+    font-size: .813rem;
+}
+.glm-support-field {
+    width: 100%;
+    padding: 0;
+    margin: 3px 0 0 0;
+}
+.glm-support-label {
+    width: 100%;
+    font-weight; bold;
+    padding: 0;
+    margin: 7px 0 0 0;
+}
+.glm-support-left-half {
+    width: 49%;
+    float: left;
+    margin: 3px 3px 0 0;
+}
+.glm-support-right-half {
+    width: 49%;
+    float: left;
+    margin: 3px 0 0 3px;
+    clear: right;
+}
+.glm-support-input {
+    padding: 3px 0;
+}
+.glm-support-input label {
+    width: 100%;
+    display: block;
+}
+.glm-support-input input[type=text],
+.glm-support-input input[type=date],
+.glm-support-input input[type=datetime],
+.glm-support-input input[type=number],
+.glm-support-input input[type=search],
+.glm-support-input input[type=time],
+.glm-support-input input[type=url],
+.glm-support-input input[type=email],
+.glm-support-input textarea,
+.glm-support-input select{
+    height: 2rem;
+    box-sizing: border-box;
+    -webkit-box-sizing: border-box;
+    -moz-box-sizing: border-box;
+    border:1px solid #BEBEBE;
+    padding: 4px;
+    margin:0px;
+    -webkit-transition: all 0.30s ease-in-out;
+    -moz-transition: all 0.30s ease-in-out;
+    -ms-transition: all 0.30s ease-in-out;
+    -o-transition: all 0.30s ease-in-out;
+    outline: none;
+    width: 100%;
+}
+.glm-support-input input[type=text]:focus,
+.glm-support-input input[type=date]:focus,
+.glm-support-input input[type=datetime]:focus,
+.glm-support-input input[type=number]:focus,
+.glm-support-input input[type=search]:focus,
+.glm-support-input input[type=time]:focus,
+.glm-support-input input[type=url]:focus,
+.glm-support-input input[type=email]:focus,
+.glm-support-input textarea:focus,
+.glm-support-input select:focus{
+    -moz-box-shadow: 0 0 8px #88D5E9;
+    -webkit-box-shadow: 0 0 8px #88D5E9;
+    box-shadow: 0 0 8px #88D5E9;
+    border: 1px solid #88D5E9;
+}
+.glm-support-input table {
+    width: 100%;
+}
+.glm-support-setting-form fieldset legend {
+    font-size: 1rem;
+    font-weight: bold;
+    margin-top: 2rem;
+}
+
+.glm-support-setting-form input[type=submit] {
+    margin-top: 20px;
+}
+
+@media only screen and (max-width: 600px) {
+    .glm-support-left-half {
+        width: 100%;
+    }
+    .glm-support-right-half {
+        width: 100%;
+    }
+}
index c19ee20..3269821 100644 (file)
@@ -69,3 +69,5 @@ define('GLM_MEMBERS_SUPPORT_MAIN_PLUGIN_PATH', $pluginsPath.'/glm-member-db');
 define('GLM_MEMBERS_SUPPORT_MAIN_PLUGIN_LIB_PATH', GLM_MEMBERS_SUPPORT_MAIN_PLUGIN_PATH.'/lib');
 define('GLM_MEMBERS_SUPPORT_PLUGIN_LIB_PATH', GLM_MEMBERS_SUPPORT_PLUGIN_PATH.'/lib');
 
+// Setting option
+define('GLM_MEMBERS_SUPPORT_SETTING_OPTION_NAME', 'glmMembersSupportSettingOption');
diff --git a/models/admin/settings/support.php b/models/admin/settings/support.php
new file mode 100644 (file)
index 0000000..c84e1e4
--- /dev/null
@@ -0,0 +1,156 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Event Email Notification
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+/*
+ * This class performs the work for the default action of the "Members" menu
+ * option, which is to display the members dashboard.
+ *
+ */
+class GlmMembersAdmin_settings_support //extends GlmDataEmailNotifications
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    /*
+     * Constructor
+     *
+     * This contructor sets up this model. At this time that only includes
+     * storing away the WordPress data object.
+     *
+     * @return object Class object
+     *
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+        // Run constructor for members data class
+        // parent::__construct(false, false);
+
+    }
+
+    /*
+     * Perform Model Action
+     *
+     * This method does the work for this model and returns any resulting data
+     *
+     * @return array Status and data array
+     *
+     * 'status'
+     *
+     * True if successfull and false if there was a fatal failure.
+     *
+     * 'menuItemRedirect'
+     *
+     * If not false, provides a menu item the controller should
+     * execute after this one. Normally if this is used, there would also be a
+     * modelRedirect value supplied as well.
+     *
+     * 'modelRedirect'
+     *
+     * If not false, provides an action the controller should execute after
+     * this one.
+     *
+     * 'view'
+     *
+     * A suggested view name that the controller should use instead of the
+     * default view for this model or false to indicate that the default view
+     * should be used.
+     *
+     * 'data'
+     *
+     * Data that the model is returning for use in merging with the view to
+     * produce output.
+     *
+     */
+    public function modelAction ($actionData = false)
+    {
+
+        $success        = true;
+        $error          = false;
+        $email_settings = false;
+
+        // If there's an action option
+        if (isset($_REQUEST['option'])) {
+
+            switch($_REQUEST['option']) {
+
+                case 'update':
+
+                    // serialize the request
+                    $value = array(
+                        'support_email'      => $_REQUEST['support_email'],
+                        'support_from_name'  => $_REQUEST['support_from_name'],
+                        'support_from_email' => $_REQUEST['support_from_email'],
+                    );
+                    $option_value = serialize( $value );
+
+                    update_option( GLM_MEMBERS_SUPPORT_SETTING_OPTION_NAME, $option_value );
+
+                    break;
+            }
+
+        }
+
+        $support_option_array = get_option( GLM_MEMBERS_SUPPORT_SETTING_OPTION_NAME );
+        if ( $support_option_array ) {
+            $email_settings = unserialize( $support_option_array );
+        }
+
+        // If we had a fatal error, redirect to the error page
+        if ($error) {
+            return array(
+                'status' => $success,
+                'menuItemRedirect' => 'error',
+                'modelRedirect'    => 'index',
+                'view'             => 'admin/error/index.html',
+                'data'             => false
+            );
+        }
+
+        // Compile template data
+        $templateData = array(
+            'settings'    => $email_settings
+        );
+
+        // Return status, suggested view, and data to controller
+        return array(
+            'status'           => $success,
+            'menuItemRedirect' => false,
+            'modelRedirect'    => false,
+            'view'             => 'admin/settings/support.html',
+            'data'             => $templateData
+        );
+
+    }
+
+}
index 286f6cc..724f512 100644 (file)
@@ -79,25 +79,86 @@ class GlmMembersAdmin_support_index // extends GlmDataLeadEntry
 
     public function modelAction($actionData = false)
     {
-        $view = 'index';
+        $view           = 'index';
+        $email_settings = false;
+        $option         = false;
+
+        if ( isset( $_REQUEST['option'] ) ) {
+            $option = filter_var( $_REQUEST['option'], FILTER_SANITIZE_STRING );
+        }
 
         switch ( $option ) {
+        case 'submit':
+            $view = 'thankyou';
+
+            $support_option_array = get_option( GLM_MEMBERS_SUPPORT_SETTING_OPTION_NAME );
+            if ( $support_option_array ) {
+                $email_settings = unserialize( $support_option_array );
+                $email          = $email_settings['support_email'];
+                $from_name      = $email_settings['support_from_name'];
+                $from           = $email_settings['support_from_email'];
+            }
+
+            if ($email) {
+                // Setup the Headers.
+                $hdrs  = 'From: '.$from_name.' <' . $from  . '>';
+                $hdrs .= "\nReply-To: {$values['name']} <{$values['email']}>";
+
+                // Setup the message.
+                $msg = 'Name: ' . $values['name'] . "\n" .
+                    'Email: ' . $values['email'] . "\n" .
+                    'Problem:' . stripslashes($values['problem']) . "\n\n\n" .
+                    'SiteName: ' . get_bloginfo('name') . "\n" .
+                    'SiteUrl: ' . get_bloginfo('url') . "\n" .
+                    'Date: ' . date('m/d/Y') . "\n" .
+                    'Time: ' . date('H:i:s ') . "\n" .
+                    'User-Agent: ' . $_SERVER['HTTP_USER_AGENT'] . "\n" .
+                    'Remote-Addr: ' . $_SERVER['REMOTE_ADDR'] . "\n";
+
+                // Check for any uploaded files.
+                $attachment = '';
+                if ( isset( $_FILES ) && is_array( $_FILES )
+                    && isset( $_FILES['file_upload'] ) && !$_FILES['file_upload']['error'] ) {
+                    // Create a directory in uploads for support files if needed
+                    $upPath   = wp_upload_dir();
+                    $filePath = $upPath['basedir'] . '/glm--member-db-support';
+                    if ( !is_dir( $filePath ) ) {
+                        $oldumask = umask( 0 );
+                        mkdir( $filePath, 0770 );
+                        umask( $oldumask );
+                    }
+                    // move the uploaded file
+                    $fileName     = wp_unique_filename( $filePath, $_FILES['file_upload']['name'] );
+                    $fileUploaded = move_uploaded_file( $_FILES['file_upload']['tmp_name'], $fileName );
+                    if ( $fileUploaded && $fileName ) {
+                        $attachment = $fileName;
+                    }
+                }
+
+                wp_mail(
+                    $email.','.$values['email'],
+                    'Support Form',
+                    $msg,
+                    $hdrs,
+                    $attachment
+                );
+
+
+                // If there's a file attachment then delete file from server
+                if ( isset( $fileName ) && $fileName && is_file( $filePath . '/' . $fileName ) ) {
+                    unlink( $filePath . '/' . $fileName );
+                }
+            }
+            break;
 
         default:
+            $view = 'index';
             break;
         }
 
-        // Get the email options
-        $email_options = array(
-            array(
-                'value' => 'steve@gaslightmedia.com',
-                'label' => 'Admin help',
-            )
-        );
-
         // Common things to place into the $templateData array
         $templateData = array(
-            'email_options' => $email_options,
+            'pluginAsset' => GLM_MEMBERS_SUPPORT_PLUGIN_URL . '/assets'
         );
 
 
index 5fe4bb3..55a7eba 100644 (file)
  * );
  *
  */
+add_filter('glm-member-db-add-tab-for-settings',
+    function($addOnTabs) {
+        $newTabs = array(
+            array(
+                'text'   => 'Support Settings',
+                'menu'   => 'settings',
+                'action' => 'support'
+            ),
 
+        );
+        $addOnTabs = array_merge($addOnTabs, $newTabs);
+        return $addOnTabs;
+    }
+);
index ad12624..73ac17f 100644 (file)
@@ -62,6 +62,9 @@ $glmMembersSupportAddOnValidActions = array(
         'support' => array(
             'index' => GLM_MEMBERS_SUPPORT_PLUGIN_SLUG,
         ),
+        'settings' => array(
+            'support' => GLM_MEMBERS_SUPPORT_PLUGIN_SLUG,
+        ),
     ),
     'frontActions' => array(
     )
diff --git a/views/admin/settings/support.html b/views/admin/settings/support.html
new file mode 100644 (file)
index 0000000..46215df
--- /dev/null
@@ -0,0 +1,48 @@
+{include file='admin/settings/header.html'}
+
+<div class="glm-support-setting-form">
+    <form action="{$thisUrl}">
+        <input type="hidden" name="page" value="{$thisPage}" />
+        <input type="hidden" name="glm_action" value="support" />
+        <input type="hidden" name="option" value="update" />
+        <fieldset>
+            <legend>Support Settings</legend>
+
+                <div class="glm-support-field">
+                    <div class="glm-support-label glm-required">
+                        To Email Address
+                    </div>
+                    <div class="glm-support-input">
+                        <input type="email" name="support_email" required
+                        value="{if isset($settings.support_email) && $settings.support_email}{$settings.support_email}{/if}">
+                    </div>
+                </div>
+
+                <div class="glm-support-field">
+                    <div class="glm-support-label glm-required">
+                        From Name
+                    </div>
+                    <div class="glm-support-input">
+                        <input type="text" name="support_from_name" required
+                        value="{if isset($settings.support_from_name) && $settings.support_from_name}{$settings.support_from_name}{/if}">
+                    </div>
+                </div>
+
+                <div class="glm-support-field">
+                    <div class="glm-support-label glm-required">
+                        From Email Address
+                    </div>
+                    <div class="glm-support-input">
+                        <input type="text" name="support_from_email" required
+                        value="{if isset($settings.support_from_email) && $settings.support_from_email}{$settings.support_from_email}{/if}">
+                    </div>
+                </div>
+
+        </fieldset>
+
+        <input class="button button-primary" type="submit" value="Save Settings">
+
+    </form>
+</div>
+
+{include file='admin/footer.html'}
index 275c11e..9154e1f 100644 (file)
@@ -7,8 +7,8 @@
         font: 16px sans-serif;
         padding: 20px 10px 20px 30px;
         margin: 0;
-        background: url(//app.gaslightmedia.com/Common/Support/images/lifeB.png) 550px -10px no-repeat;
-        background: url(//app.gaslightmedia.com/Common/Support/images/lifeB.png) 550px -10px no-repeat;
+        background: url({$pluginAsset}/lifeB.png) 550px -10px no-repeat;
+        background: url({$pluginAsset}/lifeB.png) 550px -10px no-repeat;
     }
     h1 {
         padding: 10px 0;
@@ -40,7 +40,7 @@
         padding: 0;
         margin: 0;
         text-indent: -9000px;
-        background: url(//app.gaslightmedia.com/Common/Support/images/send.png) no-repeat;
+        background: url({$pluginAsset}/send.png) no-repeat;
         border: 0;
         cursor: pointer;
     }
@@ -65,6 +65,7 @@
         margin-right: 5px;
     }
 </style>
+{debug}
 <div id="glm_support_page">
     <div id="supportWrapper">
         <h1>Support Form</h1>
             <p>If you have a screenshot to upload the file must be no larger than 1MB.</p>
         </div>
         <div>
-            <form action="<?php echo $supportFormActionUrl;?>" method="post" enctype="multipart/form-data">
+            <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+            <input type="hidden" name="page" value="{$thisPage}" />
+            <input type="hidden" name="option" value="submit" />
             <input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
                 <table>
                     <tr>
                         <td colspan="2"><b>Please help us provide the proper support</b></td>
                     </tr>
-                    <tr>
-                        <td colspan="2">
-                            <span class="req">*</span>
-                            Can you tell us which area you need assistance with?
-                        </td>
-                    </tr>
-                    <tr>
-                        <td>&nbsp;</td>
-                        <td>
-                            <select name="department" required>
-                                <option value="">-- select --</option>
-                                {foreach $email_options as $e}
-                                    <option value="{$e.value}">{$e.label}</option>
-                                {/foreach}
-                            </select>
-                        </td>
-                    </tr>
                     <tr>
                         <td>
                             <span class="req">*</span>
diff --git a/views/admin/support/thankyou.html b/views/admin/support/thankyou.html
new file mode 100644 (file)
index 0000000..5be710e
--- /dev/null
@@ -0,0 +1,70 @@
+<style>
+    .wrap {
+        margin-top: 0;
+    }
+    #glm_support_page {
+        margin-top: 0;
+        font: 16px sans-serif;
+        padding: 20px 10px 20px 30px;
+        margin: 0;
+        background: url({$pluginAsset}/lifeB.png) 550px -10px no-repeat;
+        background: url({$pluginAsset}/lifeB.png) 550px -10px no-repeat;
+    }
+    h1 {
+        padding: 10px 0;
+        margin: 0;
+    }
+    #supportWrapper {
+        width: 600px;
+        background: #eaf4eb;
+        background: rgba(255, 255, 255, .6);
+        padding: 10px 20px;
+        border: 1px solid #ccc;
+        -webkit-box-shadow: 1px 1px 2px #000; /* Saf3-4, iOS 4.0.2 - 4.2, Android 2.3+ */
+        -moz-box-shadow: 1px 1px 2px #000; /* FF3.5 - 3.6 */
+        box-shadow: 1px 1px 2px #000; /* Opera 10.5, IE9, FF4+, Chrome 6+, iOS 5 */
+    }
+    input[type=text],input[type=email] {
+        width: 300px;
+        padding: 5px;
+    }
+    textarea {
+        width: 400px;
+        height: 150px;
+        padding: 5px;
+    }
+    #submit  {
+        display: block;
+        width: 134px;
+        height: 30px;
+        padding: 0;
+        margin: 0;
+        text-indent: -9000px;
+        background: url({$pluginAsset}/send.png) no-repeat;
+        border: 0;
+        cursor: pointer;
+    }
+    td {
+        vertical-align: middle;
+    }
+    #supportIntro, #supportSucess {
+        border: 2px dashed #ddd;
+        background: #f5faf6;
+        background: rgba(255, 255, 255, .6);
+        padding: 5px 20px;
+        margin-bottom: 2em;
+    }
+    #supportIntro p {
+        margin: 1em 0;
+    }
+    table {
+        width: 600px;
+    }
+    .req {
+        color: red;
+        margin-right: 5px;
+    }
+</style>
+<div id="glm_support_page">
+    <div id="supportSucess">Your Request has been sent.</div>
+</div>