--- /dev/null
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Billing Dashboard
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link http://dev.gaslightmedia.com/
+ */
+
+class GlmMembersFront_members_newMemberForm // extends GlmDataBilling
+{
+
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+ /**
+ * Plugin Configuration Data
+ *
+ * @var $config
+ * @access public
+ */
+ public $config;
+
+ /**
+ * Constructor
+ *
+ * This contructor performs the work for this model. This model returns
+ * an array containing the following.
+ *
+ * 'status'
+ *
+ * True if successfull and false if there was a fatal failure.
+ *
+ * 'view'
+ *
+ * A suggested view name that the contoller 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.
+ *
+ * @wpdb object WordPress database object
+ *
+ * @return array Array containing status, suggested view, and any data
+ */
+ public function __construct ($wpdb, $config)
+ {
+
+ // Save WordPress Database object
+ $this->wpdb = $wpdb;
+
+ // Save plugin configuration object
+ $this->config = $config;
+
+ /*
+ * Run constructor for the Billing data class
+ *
+ * Note, the third parameter is a flag that indicates to the Contacts
+ * data class that it should flag a group of fields as 'view_only'.
+ */
+ // parent::__construct(false, false, true);
+
+ }
+
+ public function modelAction( $actionData = false )
+ {
+ // Initialize Variables Here
+ $option = '';
+ $view = 'newMemberForm';
+ $management = false;
+ $messages = array();
+ $errors = array();
+ $paymentSuccess = false;
+ $paymentError = false;
+ $error = false;
+ $invoiceHtml = '';
+
+ // Check to see if a user is logged in
+ // If they are then they should not see the Become a member form at all.
+ if ( isset( $this->config['loggedInUser'] )
+ && isset( $this->config['loggedInUser']['contactUser'] )
+ && isset( $this->config['loggedInUser']['contactUser']['ref_dest'] )
+ ) {
+ $option = 'alreadyMember';
+ }
+
+ if ( isset( $_REQUEST['option'] ) ) {
+ $option = $_REQUEST['option'];
+ }
+
+ switch ( $option ) {
+ case 'alreadyMember':
+ $view = 'alreadyAMember';
+ break;
+
+ case 'newMembership':
+ if ( $this->config['settings']['recaptcha_secret_key'] ) {
+ // Check the form for reCaptcha
+ $response = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', array(
+ 'method' => 'POST',
+ 'timeout' => 45,
+ 'redirection' => 5,
+ 'httpversion' => '1.0',
+ 'blocking' => true,
+ 'headers' => array(),
+ 'body' => array(
+ 'secret' => $this->config['settings']['recaptcha_secret_key'],
+ 'response' => $_REQUEST['g-recaptcha-response'],
+ 'remoteip' => $_SERVER['REMOTE_ADDR']
+ ),
+ 'cookies' => array()
+ ) );
+
+ $response_code = wp_remote_retrieve_response_code( $response );
+ $api_response = json_decode( wp_remote_retrieve_body( $response ), true );
+ if ( $api_response['success'] != true ) {
+ $error = true;
+ $messages[] = $errors['email'] = "<span style='color: red;'>Invalid Captcha value!</span>";
+ }
+ }
+
+ // Need to see if the email address they're using is already setup as a contact.
+ // If it is then we need to give a message about it and not let them sign up again.
+
+ $email_to_check = filter_var( $_REQUEST['email'], FILTER_VALIDATE_EMAIL );
+ $verify_email = filter_var( $_REQUEST['email_verify'], FILTER_VALIDATE_EMAIL );
+ if ( !$email_to_check ) {
+ $error = true;
+ $messages[] = $errors['email'] = "<span style='color: red;'>Not a valid Email!</span>";
+ }
+ if ( $email_to_check != $verify_email ) {
+ // Emails don't match give error message
+ $error = true;
+ $messages[] = $errors['email'] = "<span style='color: red;'>Emails don't match!</span>";
+ }
+ // Check for wordpress user with same email address
+ $wpUser = get_user_by( 'email', $email_to_check );
+ if ( is_object( $wpUser ) && $wpUser->ID ) {
+ $error = true;
+ $messages[] = $errors['email'] = "<span style='color: red;'>There's a user with that email already!</span>";
+ }
+ $passwd = filter_var( $_REQUEST['password'], FILTER_SANITIZE_STRING );
+ $confirm_passwd = filter_var( $_REQUEST['confirm_password'], FILTER_SANITIZE_STRING );
+ if ( $passwd != $confirm_passwd ) {
+ $error = true;
+ $messages[] = $errors['password'] = "<span style='color: red;'>Passwords don't match!</span>";
+ }
+ // Process the main form
+ // 1. Setup the member
+ $member_fname = filter_var( $_REQUEST['fname'], FILTER_SANITIZE_STRING );
+ $member_lname = filter_var( $_REQUEST['lname'], FILTER_SANITIZE_STRING );
+ $member_name = filter_var( $_REQUEST['business_name'], FILTER_SANITIZE_STRING );
+ // Member type is based on the renewing_member field (invoice_types)
+ $member_type = 39; // TODO: This need a setting
+ if ( $member_type === false ) {
+ $error = true;
+ $messages[] = '<span style="color:red;">An error occurred! member_type</span>';
+ }
+ // Start database transaction
+ $this->wpdb->show_errors();
+ $this->wpdb->query('START TRANSACTION');
+ // $access = $this->config['access_numb']['Full'];
+ $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members',
+ array(
+ 'access' => 40, // Not Moderated
+ 'member_type' => $member_type,
+ 'created' => date( 'Y-m-d' ),
+ 'name' => $member_name,
+ 'member_slug' => sanitize_title( $member_name ),
+ ),
+ array(
+ '%d',// access
+ '%d',// member_type
+ '%s',// created
+ '%s',// name
+ '%s',// member_slug
+ )
+ );
+ $member_id = $this->wpdb->insert_id;
+ if ( !$member_id ) {
+ $error = true;
+ $messages[] = '<span style="color:red;">An error occurred! member_id</span>';
+ } else {
+ $member = $this->wpdb->get_row(
+ $this->wpdb->prepare(
+ "SELECT *
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+ WHERE id = %d",
+ $member_id
+ )
+ );
+ }
+ // 2. Setup the member_info
+ $billing_addr1 = filter_var( $_REQUEST['billing_addr1'] );
+ $billing_city = filter_var( $_REQUEST['billing_city'] );
+ $billing_city_id = $this->getCityId( $billing_city );
+ $billing_state = filter_var( $_REQUEST['billing_state'] );
+ $billing_zip = filter_var( $_REQUEST['billing_zip'] );
+ $phone = filter_var( $_REQUEST['phone'] );
+ $website = filter_var( $_REQUEST['website'] );
+ $email_on_website = filter_var( $_REQUEST['email_on_website'] );
+
+ $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX . 'member_info',
+ array(
+ 'member' => $member_id,
+ 'member_name' => $member_name,
+ 'status' => 10,
+ 'reference_name' => 'new member form',
+ 'addr1' => $billing_addr1,
+ 'city' => $billing_city_id,
+ 'state' => $billing_state,
+ 'zip' => $billing_zip,
+ 'phone' => $phone,
+ 'url' => $website,
+ 'email' => $email_on_website,
+ 'create_time' => date( 'Y-m-d' ),
+ ),
+ array(
+ '%d', // member
+ '%s', // member_name
+ '%d', // status
+ '%s', // reference_name
+ '%s', // addr1
+ '%d', // city
+ '%s', // state
+ '%s', // zip
+ '%s', // phone
+ '%s', // url
+ '%s', // email
+ '%s', // create_time
+ )
+ );
+ $member_info_id = $this->wpdb->insert_id;
+ if ( !$member_info_id ) {
+ $error = true;
+ $messages[] = '<span style="color:red;">An error occurred! member_info_id</span>';
+ } else {
+ $member_info = $this->wpdb->get_row(
+ $this->wpdb->prepare(
+ "SELECT *
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info
+ WHERE id = %d",
+ $member_info_id
+ )
+ );
+ }
+ // 3. Setup the contact (and wpUser)
+ // Determine the Worpress Role to be used for contact import - Using Entity Manager right now
+ $contactRoleNumb = $this->config['contact_role_numb']['LogInContact'];
+ $wpRole = $this->config['contact_role_wordpress'][$contactRoleNumb];
+ $memberContactEmail = filter_var( $_REQUEST['email'], FILTER_VALIDATE_EMAIL );
+ $memberLogin = filter_var( $_REQUEST['username'] );
+ $this->wpdb->insert(
+ GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . 'contacts',
+ array(
+ 'active' => true,
+ 'primary_contact' => true,
+ 'access' => $this->config['access_numb']['Full'],
+ 'fname' => $member_fname,
+ 'lname' => $member_lname,
+ 'contact_type' => $this->config['contact_type_numb']['Personal'],
+ 'contact_role' => $contactRoleNumb,
+ 'email' => $memberContactEmail,
+ 'username' => $memberLogin,
+ 'notes' => 'Become Member Form.',
+ 'create_time' => date('Y-m-d H:i:s', time()),
+ 'ref_type' => $this->config['ref_type_numb']['Member'],
+ 'ref_dest' => $member_id,
+ ),
+ array(
+ '%d', // active
+ '%d', // primary_contact
+ '%d', // access
+ '%s', // fname
+ '%s', // lname
+ '%d', // contact_type
+ '%d', // contact_role
+ '%s', // email
+ '%s', // username
+ '%s', // notes
+ '%s', // create_time
+ '%d', // ref_type
+ '%d', // ref_dest
+ )
+ );
+ $newContactID = $this->wpdb->insert_id;
+ if ( $newContactID ) {
+ $new_contact = $this->wpdb->get_row(
+ $this->wpdb->prepare(
+ "SELECT *
+ FROM " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts
+ WHERE id = %d",
+ $newContactID
+ )
+ );
+ } else {
+ $error = true;
+ $messages[] = '<span style="color:red;">An error occurred! newContactID</span>';
+ }
+ $memberPasswd = filter_var( $_REQUEST['password'] );
+ $wpUserID = wp_insert_user(
+ array(
+ 'user_email' => $memberContactEmail,
+ 'user_login' => $memberLogin,
+ 'user_pass' => $memberPasswd,
+ 'first_name' => $member_fname,
+ 'last_name' => $member_lname,
+ 'role' => $wpRole
+ )
+ );
+ if (is_int($wpUserID) && $wpUserID > 0) {
+ // Store the contact ID and active status into user meta data.
+ update_user_meta($wpUserID, 'glmMembersContactID', $newContactID);
+ update_user_meta($wpUserID, 'glmMembersContactActive', true);
+ } else if ( is_wp_error( $wpUserID ) ) {
+ $error = true;
+ $messages[''] = $errors['username'] = '<span style="color:red;">An error occurred! ' . $wpUserID->get_error_message() . '</span>';
+ } else {
+ $error = true;
+ $messages[] = '<span style="color:red;">An error occurred! wpUserID</span>';
+ }
+ // Save or rollback
+ if ( $error ) {
+ $this->wpdb->query('ROLLBACK');
+ } else {
+ $this->wpdb->query('COMMIT');
+ $view = 'thankyou';
+ }
+ break;
+
+ default:
+ break;
+
+ }
+
+ wp_register_script( 'recaptcha', 'https://www.google.com/recaptcha/api.js' );
+ wp_enqueue_script( 'recaptcha' );
+
+ // Compile template data
+ $templateData = array(
+ 'option' => $option,
+ 'billing_settings' => $this->config['billing_settings'],
+ 'messages' => $messages,
+ 'errors' => $errors,
+ 'paymentSuccess' => $paymentSuccess,
+ 'paymentError' => $paymentError,
+ 'states' => $this->config['states'],
+ 'invoiceHtml' => $invoiceHtml,
+ );
+
+ // Return status, any suggested view, and any data to controller.
+ return array(
+ 'status' => true,
+ 'modelRedirect' => false,
+ 'view' => 'front/members/'.$view.'.html',
+ 'data' => $templateData
+ );
+
+ }
+
+ public function getCityId( $city_name )
+ {
+ // First try to get city id
+ $city_id = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities
+ WHERE name = %s",
+ $city_name
+ )
+ );
+ if ( $city_id ) {
+ return $city_id;
+ }
+ $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX . 'cities',
+ array( 'name' => $city_name ),
+ array( '%s' )
+ );
+ return $this->wpdb->insert_id;
+ }
+
+
+}
--- /dev/null
+{* This template is for New Member Form *}
+<h3>Become a Member</h3>
+<div class="glm-row">
+
+ {if $paymentSuccess}<span class="glm-notice glm-flash-updated">Payment Completed</span>{/if}
+ {if $paymentError}<span class="glm-notice glm-flash-updated">Error With Payment</span>{/if}
+
+ {if $messages}
+ {foreach $messages as $message}
+ <div class="">{$message}</div>
+ {/foreach}
+ {/if}
+
+ <form action="{$thisUrl}" method="post">
+ <input type="hidden" name="option" value="newMembership" />
+
+ <fieldset>
+ <legend>Membership Information</legend>
+
+ {if isset($errors.email) && $errors.email}<div>{$errors.email}</div>{/if}
+
+ <div class="glm-row">
+ <div class="glm-columns glm-large-12 glm-small-12 glm-medium-12">
+ <label for="business_name" class="glm-required" >Business Name</label>
+ <input id="business_name" name="business_name" />
+ </div>
+ </div>
+ <div class="glm-row">
+ <div class="glm-columns glm-large-12 glm-small-12 glm-medium-12">
+ <label for="billing_addr1" class="glm-required"> Address </label>
+ <input type="text" id="billing_addr1" name="billing_addr1" {if isset($smarty.request.billing_addr1) && $smarty.request.billing_addr1}value="{$smarty.request.billing_addr1}"{/if} required />
+ </div>
+ </div>
+ <div class="glm-row">
+ <div class="glm-columns glm-large-4 glm-small-12 glm-medium-4">
+ <label for="billing_city" class="glm-required">City</label>
+ <input type="text" id="billing_city" name="billing_city" {if isset($smarty.request.billing_city) && $smarty.request.billing_city}value="{$smarty.request.billing_city}"{/if} required />
+ </div>
+ <div class="glm-columns glm-large-4 glm-small-12 glm-medium-4">
+ <label for="billing_state" class="glm-required"> State / Province </label>
+ <select name="billing_state" id="billing_state" required>
+ <option value=""></option>
+ {foreach $states as $stateAbb => $stateVal}
+ <option value="{$stateAbb}"{if isset($smarty.request.billing_state) && $smarty.request.billing_state == $stateAbb} selected="selected"{/if}>
+ {$stateVal}
+ </option>
+ {/foreach}
+ </select>
+ </div>
+ <div class="glm-columns glm-large-4 glm-small-12 glm-medium-4">
+ <label for="billing_zip" class="glm-required"> Zip </label>
+ <input type="text" id="billing_zip" name="billing_zip" {if isset($smarty.request.billing_zip) && $smarty.request.billing_zip}value="{$smarty.request.billing_zip}"{/if} required />
+ </div>
+ </div>
+ <div class="glm-row">
+ <div class="glm-columns glm-large-12 glm-small-12 glm-medium-12">
+ <label class="glm-billing-label"> Web Address </label>
+ <input type="text" id="website" name="website" {if isset($smarty.request.website) && $smarty.request.website}value="{$smarty.request.website}"{/if} />
+ </div>
+ </div>
+
+ </fieldset>
+ <fieldset>
+ <legend>Account/Contact Information</legend>
+ <div class="glm-row">
+ <div class="glm-columns glm-large-6 glm-small-12 glm-medium-6">
+ <label for="fname" class="glm-required"> First Name </label>
+ <input type="text" id="fname" name="fname" {if isset($smarty.request.fname) && $smarty.request.fname}value="{$smarty.request.fname}"{/if} required />
+ </div>
+ <div class="glm-columns glm-large-6 glm-small-12 glm-medium-6">
+ <label class="glm-required"> Last Name </label>
+ <input type="text" id="lname" name="lname" {if isset($smarty.request.lname) && $smarty.request.lname}value="{$smarty.request.lname}"{/if} required />
+ </div>
+ </div>
+ <div class="glm-row">
+ <div class="glm-columns glm-large-6 glm-small-12 glm-medium-6">
+ <label class="glm-required"> Email </label>
+ <input type="text" id="email" name="email" {if isset($smarty.request.email) && $smarty.request.email}value="{$smarty.request.email}"{/if} required />
+ </div>
+ <div class="glm-columns glm-large-6 glm-small-12 glm-medium-6">
+ <label class="glm-required"> Confirm Email </label>
+ <input type="text" id="email_verify" name="email_verify" {if isset($smarty.request.email_verify) && $smarty.request.email_verify}value="{$smarty.request.email_verify}"{/if} required />
+ </div>
+ </div>
+ <div class="glm-row">
+ <div class="glm-columns glm-large-6 glm-small-12 glm-medium-6">
+ <label class="glm-billing-label"> Phone </label>
+ <input type="text" id="phone" name="phone" {if isset($smarty.request.phone) && $smarty.request.phone}value="{$smarty.request.phone}"{/if} />
+ </div>
+ <div class="glm-columns glm-large-6 glm-small-12 glm-medium-6">
+ <label class="glm-billing-label"> Cellphone </label>
+ <input type="text" id="cellphone" name="cellphone" {if isset($smarty.request.cellphone) && $smarty.request.cellphone}value="{$smarty.request.cellphone}"{/if} />
+ </div>
+ </div>
+ <div class="glm-row">
+ <div class="glm-columns glm-large-6 glm-small-12 glm-medium-6">
+ <label class="glm-billing-label"> Fax </label>
+ <input type="text" id="fax" name="fax" {if isset($smarty.request.fax) && $smarty.request.fax}value="{$smarty.request.fax}"{/if} />
+ </div>
+ <div class="glm-columns glm-large-6 glm-small-12 glm-medium-6">
+ <label class="glm-billing-label"> Email on Website </label>
+ <input type="text" id="email_on_website" name="email_on_website" {if isset($smarty.request.email_on_website) && $smarty.request.email_on_website}value="{$smarty.request.email_on_website}"{/if} />
+ </div>
+ </div>
+
+
+ <div class="glm-row">
+ <div class="glm-columns glm-large-12 glm-small-12 glm-medium-12">
+ <label class="glm-required"> Username </label>
+ <input type="text" id="username" name="username" {if isset($smarty.request.username) && $smarty.request.username}value="{$smarty.request.username}"{/if} required />
+ {if isset($errors.username) && $errors.username}<div>{$errors.username}</div>{/if}
+ The password must be at least 8 characters and include at least one number, one letter, and at least one special character. (# . - _ , $ % & !)
+ </div>
+ </div>
+ <div class="glm-row">
+ <div class="glm-columns glm-large-6 glm-small-12 glm-medium-6">
+ <label class="glm-required"> Password </label>
+ <input type="password" id="password" name="password" {literal}pattern="(?=.*\d)(?=.*[a-z]).{6,}"{/literal} {if isset($smarty.request.password) && $smarty.request.password}value="{$smarty.request.password}"{/if} required />
+ </div>
+ <div class="glm-columns glm-large-6 glm-small-12 glm-medium-6">
+ <label class="glm-required"> Confirm Password </label>
+ <input type="password" id="confirm_password" name="confirm_password" {literal}pattern="(?=.*\d)(?=.*[a-z]).{6,}"{/literal} {if isset($smarty.request.confirm_password) && $smarty.request.confirm_password}value="{$smarty.request.confirm_password}"{/if} required />
+ </div>
+ </div>
+
+ {if isset($errors.password) && $errors.password}<div>{$errors.password}</div>{/if}
+
+ </fieldset>
+
+
+
+ <input type="hidden" name="payment_option" value="pay_by_check" />
+
+
+ {if $settings.recaptcha_site_key}
+ <div class="g-recaptcha" data-sitekey="{$settings.recaptcha_site_key}"></div>
+ {/if}
+
+ <input class="button button-primary" type="submit" value="Sign Up For Membership">
+
+ </form>
+</div>
+
+<script>
+jQuery(document).ready(function($){
+
+ // Flash certain elements for a short time after display
+ $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
+
+});
+</script>