+++ /dev/null
-<?php
-/**
- * Plugin Support Functions for the Custom Fields plugin
- *
- */
-/**
- * customFieldsSaveMemberInfoFields
- *
- * Save the data for the Member Info custom fields.
- * Uses the $_REQUEST variable glm_custom_field.
- *
- * @param mixed $entityID Id for the member info record
- *
- * @access public
- * @return void
- */
-function customFieldsSaveFields( $entityID ){
- global $wpdb;
- $fieldFail = array();
- // If no data for custom field then return
- if ( !isset( $_REQUEST['glm_custom_field'] ) ) {
- return false;
- }
- //echo "Trying to save entity of type $uid";
-// print_r(customFieldsGetFields($entityID));
- // See if this memberInfo has current field data
- $currentCustomFields = customFieldsGetFieldData( $entityID );
- // Insert the custom field record
- $fieldDataFormat = array(
- '%d',
- '%d',
- '%s'
- );
- $sql = "SELECT * FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_fields WHERE required=1";
- $required = $wpdb->get_results($sql);
-
- if(!empty($required)){
- foreach($required as $req){
- $requiredFields[] = $req->id;
- }
-
- foreach($_REQUEST['glm_custom_field'] as $fieldID =>$fieldValue){
- $cfData[$fieldID] = $fieldValue;
- if( in_array( $fieldID,$requiredFields )){
- if($fieldValue === ''){
- $fieldFail['fieldFail'][$fieldID] = true;
- }
- }
- }
- }
- if(!empty($fieldFail)){
- $fieldFailData = $cfData + $fieldFail;
- return $fieldFailData;
- }
- // Loop through the glm_custom_field array
- foreach ( $_REQUEST['glm_custom_field'] as $fieldId => $fieldValue ) {
- $fieldData =array(
- 'entity_id' => $entityID,
- 'field_id' => $fieldId,
- 'field_data' => wp_kses_post(stripslashes($fieldValue))
- );
- if ( !isset($currentCustomFields[$fieldId]) ) {
- // Insert Entries
- $wpdb->insert(
- GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_field_data",
- $fieldData,
- $fieldDataFormat
- );
- } else {
- // Update Entries
- $wpdb->update(
- GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_field_data",
- $fieldData,
- array(
- 'entity_id' => $entityID,
- 'field_id' => $fieldId
- ),
- $fieldDataFormat,
- '%d'
- );
- }
- }
- return true;
-}
-
-function customFieldsCloneFields( $oldId, $newId )
-{
- global $wpdb;
- $customFields = customFieldsGetFields( $oldId );
- $fieldDataFormat = array(
- '%d',
- '%d',
- '%s'
- );
- if ( isset( $customFields ) ) {
- foreach ( $customFields as $fieldId => $fieldData ) {
- $fieldData =array(
- 'entity_id' => $newId,
- 'field_id' => $fieldId,
- 'field_data' => $fieldData
- );
- $wpdb->insert(
- GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_field_data",
- $fieldData,
- $fieldDataFormat
- );
- }
- }
-}
-
-/**
- * customFieldsGetMemberInfoFields
- *
- * Pull the member info custom field data.
- * This will be used more for admin side.
- *
- * @param mixed $entityID Id for the member info record
- *
- * @access public
- * @return void
- */
-function customFieldsGetFieldData( $entityID )
-{
- global $wpdb;
- if ( !$entityID ) {
- return false;
- }
- $data = array();
- $sql = "
- SELECT *
- FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_field_data
- WHERE entity_id = %d";
- $fieldData = $wpdb->get_results( $wpdb->prepare( $sql, $entityID ), ARRAY_A );
- if ( $fieldData ) {
- foreach ( $fieldData as $key => $val ) {
- $data[$val['field_id']] = $val['field_data'];
- }
- return $data;
- } else {
- return false;
- }
-}
-/**
- * customFieldsGetFields
- * Pull the member info custom field data.
- * This will be used more for admin side.
- *
- * @param mixed $entityID Id for the member info record
- *
- * @access public
- * @return void
- */
-function customFieldsGetFields( $entityID, $where = ' AND true ', $uid )
-{
- global $wpdb;
- if ( !$entityID) {
- return false;
- }
- $data = array();
- $sql = "
- SELECT *
- FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_fields
- WHERE id IN (select field_id from ".GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_field_data WHERE entity_id = %d)" . $where;
- $fieldData = $wpdb->get_results( $wpdb->prepare( $sql, $uid ), ARRAY_A );
- echo '<pre>', print_r($fieldData), '</pre>';
-}
--- /dev/null
+<?php
+use No3x\WPML\ORM\Model\User;
+
+/**
+ * Gaslight Media Associate
+ * Custom Fields Support Class
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release registratiosnSupport.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link http://dev.gaslightmedia.com/
+ */
+
+require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH . '/data/dataCustomFields.php';
+require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH . '/data/dataCustomFieldsData.php';
+
+class GlmCustomFieldSupport extends GlmDataFieldsCustomFields
+{
+
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+ /**
+ * Plugin Configuration Data
+ *
+ * @var $config
+ * @access public
+ */
+ public $config;
+ /**
+ * Registration Request Cart
+ *
+ * $var $cart
+ * @access public
+ */
+ public $cart = false;
+
+ /**
+ * Constructor
+ *
+ * @param object $d database connection
+ * @param array $config Configuration array
+ * @param bool $limitedEdit Flag to say indicate limited edit requested
+ *
+ * @return void
+ * @access public
+ */
+ public function __construct($wpdb, $config)
+ {
+
+ // If this class is not being extended along with existing $wpdb and $config
+ if (!$this->wpdb) {
+
+ // Save WordPress Database object
+ $this->wpdb = $wpdb;
+
+ // Save plugin configuration object
+ $this->config = $config;
+
+ // Run constructor for members data class
+ parent::__construct(false, false);
+
+ }
+
+ }
+
+
+ /**
+ * Process submitted custom fields form
+ *
+ * Note: this function does not store the data. If this function returns good data with
+ * no submit problems, the calling code may simply call the storeForm() function with the
+ * data returned from this function along with a submission ID to have it stored.
+ *
+ * @param $fid string A form ID
+ * @param $recordId integer Record ID for this submission.
+ * Note that this should be false unless this is a re-submission - NOT YET SUPPORTED
+ * @param $store boolean Call storeForm() after processing form
+ *
+ * @return array See code below - False if unable to find the form or process input
+ *
+ * @access public
+ */
+ public function submitForm($fid, $recordId, $store = false)
+ {
+
+ $formId = false;
+ $haveForm = false;
+
+ if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) {
+ trigger_error('CustomFieldSupport Class: submitForm() called', E_USER_NOTICE);
+ }
+
+ // Initialize result array
+ $result = array(
+ 'status' => true,
+ 'formFields' => false,
+ 'messages' => array(),
+ 'submitData' => array(), // For use in storing and displaying result of submission
+ 'required' => false
+ );
+
+ // Make sure we have a valid FID
+ $formId = filter_var($fid, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_LOW);
+
+ // Try to retrieve the form
+ $result['formFields'] = $this->getList("T.fid = '$fid'");
+
+ if ($result['formFields'] && count($result['formFields']) > 0) {
+
+ $haveForm = true;
+
+ // Also add default input values and fieldFail content
+ foreach ($result['formFields'] as $fieldKey => $fieldVal) {
+ $result['formFields'][$fieldKey]['submitted'] = false;
+ $result['formFields'][$fieldKey]['field_fail'] = false;
+ }
+
+ }
+
+ /*
+ * Process each input field
+ */
+
+ // If the form fields were found
+ if ($haveForm) {
+
+ // For each of the fields
+ foreach ($result['formFields'] as $fieldKey => $fieldVal) {
+
+ $fieldId = 'glmCustomFormField_'.$fieldKey;
+
+ // Defaults for field data array
+ $fieldRes = array(
+ 'field_name' => $fieldVal['field_name'],
+ 'field_prompt' => $fieldVal['field_prompt'],
+ 'field_type' => $fieldVal['field_type']['name'],
+ 'field_data' => false
+ );
+
+ // Get field data
+ switch ($fieldVal['field_type']['name']) {
+
+ case 'text':
+ case 'textarea':
+
+ $formField[$fieldId] = '';
+
+ // If the expected form field exists
+ if (isset($_REQUEST) && isset($_REQUEST[$fieldId])) {
+ $in = filter_var($_REQUEST[$fieldId], FILTER_SANITIZE_STRING);
+ $result['formFields'][$fieldKey]['submitted'] = $in;
+ $fieldRes['field_data'] = $in;
+ } else {
+ $result['status'] = false;
+ trigger_error("customFieldSupport Class: submitForm() - Field '".$fieldVal['field_name']."' is missing from form submission.", E_USER_WARNING);
+ }
+
+ // If we had a submission problem (missing required)
+ if ($fieldVal['required']['value'] && trim($result['formFields'][$fieldKey]['submitted']) == '') {
+ $result['formFields'][$fieldKey]['field_fail'] = true;
+ $result['status'] = false;
+ $result['required'] = true;
+ }
+
+ break;
+
+ case 'checkbox':
+
+ $in = (isset($_REQUEST) && isset($_REQUEST[$fieldId]) && $_REQUEST[$fieldId] == 'on');
+
+ $result['formFields'][$fieldKey]['submitted'] = $in;
+ $fieldRes['field_data'] = ($in ? 'Yes' : 'No');
+
+ break;
+
+ default:
+ break;
+
+
+ }
+
+ // Add data to submitData array
+ $fieldRes['field_data'] = $result['formFields'][$fieldKey]['submitted'];
+ $result['submitData'][] = $fieldRes;
+
+ }
+
+ if($result['required']) {
+ $messages[] = 'Some required information was not submitted.';
+ }
+
+ }
+
+ // if a store request was included - do that now
+ if ($store) {
+ $result = $this->storeForm($fid, $recordId, $result);
+ }
+
+ return $result;
+
+ }
+
+ /**
+ * Store submitted custom fields data retured by submitForm()
+ *
+ * Note: this function does not process input data. That is performed by submitForm().
+ * After collecting submitted data using submitForm() and checking that all submitted
+ * data is complete, the calling code should use this function to store the data.
+ *
+ * Note also that it is not necessary to store this data unless it's needed for searches later.
+ *
+ * @param $fid string A form ID
+ * @param $recordId integer Record ID for this submission.
+ * @param $submitResult array Array of data supplied by submitForm()
+ *
+ * @return array Array of result data (below) - False if not success.
+ * array (
+ * 'stored_id' => array(
+ * 'field_name' => {short field name},
+ * 'field_prompt' => {prompt issued for this field},
+ * 'data' => {submitted data})
+ * )
+ * )
+ *
+ * @access public
+ */
+ public function storeForm($fid, $recordId, $submitResult)
+ {
+
+ $formId = false;
+ $formUpdate = false;
+
+ if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) {
+ trigger_error('CustomFieldSupport Class: storeForm() called', E_USER_NOTICE);
+ }
+
+ // Is the Form ID valid and current
+ // Make sure we have a valid FID
+ $formId = filter_var($fid, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_LOW);
+
+ // Try to retrieve the form
+ $fields = $this->getList("T.fid = '$fid'");
+ if ($fields && count($fields) <= 0) {
+ return false;
+ }
+
+ // Do we have proper submitted data with field results - (note that fields may have been added/deleted since user input)
+ if (!is_array($submitResult) || !isset($submitResult['formFields']) || count($submitResult['formFields']) <= 0) {
+ return false;
+ }
+
+ // Build a list of form field IDs to use in checking for any existing submitted data for this fid and record ID combination
+ $fieldIds = '';
+ $sep = '';
+ foreach ($submitResult['formFields'] as $field) {
+ $fieldIds .= $sep.$field['id'];
+ $sep = ',';
+ }
+
+ // Get any data already stored for these fid / record ID combination
+ $CustomFieldsData = new GlmDataFieldsCustomFieldsData($this->wpdb, $this->config);
+ $formUpdate = $CustomFieldsData->getList("field_id in ($fieldIds) AND record_id = $recordId");
+
+ $this->wpdb->query("START TRANSACTION");
+
+ // For each field
+ foreach ($submitResult['formFields'] as $field) {
+
+ $fType = $field['field_type']['name'];
+
+ // If this is an update of existing data
+ if ($formUpdate) {
+
+ $text_data = ($fType=='text'||$fType=='textarea' ? $field['submitted'] : '');
+ $checkbox_data = ($fType=='checkbox' ? $field['submitted'] : false);
+ $integer_data = ($fType=='integer' ? $field['submitted'] : false);
+ $float_data = ($fType=='float' ? $field['submitted'] : false);
+
+ $res = $this->wpdb->update(
+ GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX.'custom_field_data',
+ array(
+ 'text_data' => $text_data,
+ 'checkbox_data' => $checkbox_data,
+ 'integer_data' => $integer_data,
+ 'float_data' => $float_data,
+ ),
+ array(
+ 'field_id' => $field['id'],
+ 'record_id' => $recordId
+ ),
+ array(
+ '%s',
+ '%d',
+ '%d',
+ '%f'
+ ),
+ array('%d', '%d')
+ );
+
+ } else {
+
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX.'custom_field_data',
+ array(
+ 'field_id' => $field['id'],
+ 'record_id' => $recordId,
+ 'text_data' => ($fType=='text'||$fType=='textarea' ? $field['submitted'] : ''),
+ 'checkbox_data' => ($fType=='checkbox' ? $field['submitted'] : false),
+ 'integer_data' => ($fType=='integer' ? $field['submitted'] : false),
+ 'float_data' => ($fType=='float' ? $field['submitted'] : false),
+ ),
+ array(
+ '%d',
+ '%d',
+ '%s',
+ '%d',
+ '%d',
+ '%f'
+ )
+ );
+
+ }
+
+ // If there was a failure, roll back all changes
+ if ($res === false) {
+ $this->wpdb->query("ROLLBACK");
+ return false;
+ }
+
+ }
+
+ $this->wpdb->query("COMMIT");
+
+ return $submitResult['submitData'];
+
+ }
+}
\ No newline at end of file
'use' => 'a'
),
- // Event ID
+ // Form ID
+ 'fid' => array (
+ 'field' => 'fid',
+ 'type' => 'text',
+ 'view_only' => false,
+ 'use' => 'a'
+ ),
+
+ // Field Name
'field_name' => array(
'field' => 'field_name',
'type' => 'text',
'required' => true,
'use' => 'a'
),
- // group id
- 'uid' => array (
- 'field' => 'uid',
- 'type' => 'text',
- 'view_only' => false,
- 'use' => 'a'
+
+ // User Prompt
+ 'field_prompt' => array(
+ 'field' => 'field_prompt',
+ 'type' => 'text',
+ 'required' => true,
+ 'use' => 'a'
),
- // Category ID
+
+ // Field Type
'field_type' => array(
'field' => 'field_type',
'type' => 'list',
'required' => true,
'use' => 'a'
),
+
+ // Field Order
+ 'field_order' => array(
+ 'field' => 'field_order',
+ 'type' => 'integer',
+ 'view_only' => true,
+ 'use' => 'a'
+ ),
+
// required field
'required' => array(
'field' => 'required',
'type' => 'checkbox',
'use' => 'a'
- ),
- // admin_search flag
- 'admin_search' => array (
- 'field' => 'admin_search',
- 'type' => 'checkbox',
- 'use' => 'a'
- ),
+ )
);
'use' => 'a'
),
// Entity ID (event, member, package)
- 'entity_id' => array (
- 'field' => 'entity_id',
+ 'record_id' => array (
+ 'field' => 'record_id',
'type' => 'integer',
'view_only' => false,
'use' => 'a'
'use' => 'a'
),
- 'field_data' => array(
- 'field' => 'field_data',
+ 'text_data' => array(
+ 'field' => 'text_data',
'type' => 'text',
'required' => true,
'use' => 'a'
// NOTE: Plugin & Database versions are defined in "/glm-member-db.php".
define('GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_NAME', 'GLM Members Database Custom Fields');
-define('GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_SHORT_NAME', 'Fields');
+define('GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_SHORT_NAME', 'Custom Fields');
define('GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_SLUG', 'glm-member-db-customfields');
// Database table prefixes - change if using add-on tables
* version from this plugin.
*/
define('GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_VERSION', '1.0.0');
-define('GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_VERSION', '1.0.0');
+define('GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_VERSION', '1.0.1');
// This is the minimum version of the GLM Members DB plugin require for this plugin.
define('GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.8.0');
--- /dev/null
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Admin Data Import
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version 0.1
+ */
+require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH.'/data/dataCustomFieldsData.php';
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMemberInfo.php';
+/*
+ * This class performs the work for the default action of the "Import" menu
+ * option.
+ *
+ */
+class GlmMembersAdmin_import_fields extends GlmDataFieldsCustomFieldsData
+{
+
+ const CSV_CHARS_PER_LINE = 6000;
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+ /**
+ * Plugin Configuration Data
+ *
+ * @var $config
+ * @access public
+ */
+ public $config;
+
+ /**
+ * errors
+ *
+ * @var $errors
+ * @access public
+ */
+ public $errors = array();
+
+ /**
+ * numberProcessed
+ *
+ * @var float
+ * @access public
+ */
+ public $numberProcessed = 0;
+
+ /**
+ * totalFields
+ *
+ * @var float
+ * @access public
+ */
+ public $totalFields = 0;
+
+ /**
+ * processingComplete
+ *
+ * @var bool
+ * @access public
+ */
+ public $processingComplete = false;
+
+ /**
+ * Constructor
+ *
+ * This contractor 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 successful 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)
+ {
+ // Set the view file
+ $view = 'fields.html';
+ $failure = false;
+ $option = 'fields';
+ $clearData = false;
+ $importRet = false;
+ $haveMembers = false;
+ $fileExists = false;
+ $isValid = false;
+ // Check to see if they have members
+ $haveMembers = $this->wpdb->get_var(
+ "SELECT count(id)
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members"
+ );
+ // $fileData - The main files needed for the member import
+ // - field: input field name
+ // - name: file name
+ // - exists: Does file exists. Set to false at first.
+ // - validate: Validation array. Header line must match this.
+ // - type: Type of file. Used in the processing function.
+ $fileData = array(
+ 'Fields' => array(
+ 'field' => 'fields_file',
+ 'name' => 'fieldsData.csv',
+ 'exists' => false,
+ 'validate' => array( 'member_id', 'field_name', 'field_value' ),
+ 'type' => 'fields',
+ ),
+ );
+ // Setting readyToProcess to false (initialize)
+ $readyToProcess = false;
+
+ // Set the $option if found in $_REQUEST array
+ if (isset($_REQUEST['option']) && $_REQUEST['option'] != '') {
+ $option = $_REQUEST['option'];
+ }
+
+ // Set the $option2 if found in $_REQUEST array
+ if (isset($_REQUEST['option2']) && $_REQUEST['option2'] != '') {
+ $option2 = $_REQUEST['option2'];
+ }
+
+ // Set variable for the upload directory
+ $wpUploadDir = wp_get_upload_dir();
+
+ // Set the $uploadPath for import files
+ $uploadPath = $wpUploadDir['basedir'] . '/' . 'glm-member-import';
+
+ // If the folder for the upload import files doesn't exists create one.
+ if ( !is_dir( $uploadPath ) ) {
+ // Get old umask
+ $oldMask = umask(0);
+ // Set folder permission
+ mkdir( $uploadPath, 0770 );
+ // reset old umask
+ umask( $oldMask );
+ }
+
+ switch( $option ) {
+
+ case 'fieldsValidate';
+ $validFiles = 0;
+ // Set the view file
+ $view = 'fieldsValidate.html';
+ $fileCount = count( $fileData );
+ // Move any files uploaded
+ if ( isset( $_FILES ) ) {
+ foreach ( $fileData as $fileHeader => $file ) {
+ if ( !$_FILES[$file['field']]['error'] ) {
+ move_uploaded_file( $_FILES[$file['field']]['tmp_name'], $uploadPath . '/'. $file['name'] );
+ }
+ }
+ }
+ // Check that each file exists
+ foreach ( $fileData as $fileHeader => $file ) {
+ if ( is_file( $uploadPath . '/' . $file['name'] ) ) {
+ $fileData[$fileHeader]['exists'] = true;
+ $fData = $this->readCSVFileHeaders( $uploadPath . '/' . $file['name'] );
+ $isValid = ( $file['validate'] == $fData );
+ if ( $isValid ) {
+ $validFiles++;
+ }
+ $fileData[$fileHeader]['data'] = $fData;
+ $fileData[$fileHeader]['isValid'] = $isValid;
+ }
+ }
+ $readyToProcess = ( $validFiles == $fileCount );
+ break;
+
+ case 'fieldsProcess':
+ $memberInfoData = new GlmDataMemberInfo( $this->wpdb, $this->config );
+ foreach ( $fileData as $fileHeader => $file ) {
+ if ( is_file( $uploadPath . '/' . $file['name'] ) ) {
+ $fields = $this->readCSVFields( $uploadPath . '/'. $file['name'] );
+ //echo '<pre>$fields: ' . print_r( $fields, true ) . '</pre>';
+ $this->totalFields = count( $fields );
+ // Clear the custom field data table
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_field_data" );
+ foreach ( $fields as $customRow ) {
+ // Need to first get the member id from the database
+ // It will match from the old_member_id field
+ $memberId = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+ WHERE old_member_id = %d",
+ $customRow[0]
+ )
+ );
+ // get the active member info id
+ $memberInfoId =
+ $memberInfoData->getActiveInfoIdForMember( $memberId );
+ $customFieldId = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_fields
+ WHERE field_name = %s",
+ $customRow[1]
+ )
+ );
+ if ( $customFieldId ) {
+ $newId = $this->wpdb->insert(
+ GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . 'custom_field_data',
+ array(
+ 'ref_dest' => $memberInfoId,
+ 'field_id' => $customFieldId,
+ 'field_data' => $customRow[2],
+ ),
+ array(
+ '%d',
+ '%d',
+ '%s'
+ )
+ );
+ $this->numberProcessed++;
+ }
+ }
+ $importRet = array();
+ }
+ }
+ if ( count( $this->errors ) == 0 ) {
+ $readyToProcess = true;
+ }
+ // Here we need to check to see if we processed all members.
+ // Also the counter has to increment the total processed so far.
+ if ( $this->numberProcessed == $this->totalFields ) {
+ $this->processingComplete = true;
+ }
+ // Set the view file:<
+ $view = 'fieldsProcess.html';
+ break;
+
+ case 'fields':
+ default:
+ // Set the view file
+ $view = 'fields.html';
+ // check upload dir to see if they have any files in yet
+ foreach ( $fileData as $fileHeader => $file ) {
+ if ( is_file( $uploadPath . '/' . $file['name'] ) ) {
+ $fileData[$fileHeader]['exists'] = true;
+ $fileData[$fileHeader]['mtime'] = filemtime( $uploadPath . '/' . $file['name'] );
+ }
+ }
+
+ break;
+
+ }
+
+ // Setup the template data array
+ $templateData = array(
+ 'fileExists' => $fileExists,
+ 'option' => $option,
+ 'errors' => $this->errors,
+ 'numberProcessed' => $this->numberProcessed,
+ 'totalFields' => $this->totalFields,
+ 'completed' => $this->processingComplete,
+ 'data' => false,
+ 'fileData' => $fileData,
+ 'clearData' => $clearData,
+ 'importRet' => $importRet,
+ 'csvData' => '<pre>$fileData: ' . print_r( $fileData, true ) . '</pre>',
+ 'readyToProcess' => $readyToProcess,
+ 'haveMembers' => $haveMembers,
+ 'isValid' => $isValid,
+ 'sampleFileUrl' => GLM_MEMBERS_PLUGIN_BASE_URL . '/sample-files/',
+ );
+
+ // Return status, suggested view, and data to controller
+ return array(
+ 'status' => true,
+ 'menuItemRedirect' => false,
+ 'modelRedirect' => false,
+ 'view' => 'admin/import/' . $view,
+ 'data' => $templateData,
+ );
+
+ }
+
+ /**
+ * Read in fields from a csv file
+ *
+ * Header line as follows. Data follows immediately below this line. this
+ * line and all above it are ignored.
+ *
+ * 'member_id','member_name','member_login','member_passwd','contact_email'
+ *
+ * @param string $csv Temporary file name of csv file upload
+ *
+ * @return array Array of data from CSV file or an error message
+ *
+ */
+ public function readCSVFields($csv)
+ {
+
+ $fields = array();
+ $startImport = false;
+
+ // Try to open file
+ if (($handle = fopen($csv, "r")) !== false) {
+
+ // For each line in the file
+ while (($c = fgetcsv($handle, 1000, ",")) !== false) {
+
+ // If we're past the header, the first item is numeric, and we have at least 5 fields
+ if($startImport && ($c[0]-0) > 0 && count($c) >= 3) {
+
+ // Add this line of data to Contacts
+ $fields[] = $c;
+
+ }
+
+ // If we find the header, assume all data is below that
+ if ($c[0] == 'member_id') {
+ $startImport = true;
+ }
+
+ }
+
+ fclose($handle);
+
+ } else {
+ return "No file submitted.";
+ }
+
+ // If we never found the header
+ if (!$startImport) {
+ return "Required header not found in file.";
+ }
+
+ // If we found no data below the header
+ if (count($fields) == 0) {
+ return "Header found but no data followed";
+ }
+
+ return $fields;
+
+ }
+
+ /**
+ * readCSVFileHeaders
+ *
+ * Read the cvs file. Just the first line is read.
+ *
+ * @param mixed $fileName Name of the file (path)
+
+ * @access public
+ * @return void
+ */
+ public function readCSVFileHeaders( $fileName )
+ {
+ $fileHeaders = array();
+ if ( ( $fp = fopen( $fileName, 'r' ) ) !== false ) {
+ // get first line to use as headers
+ $fileHeaders = fgetcsv( $fp, SELF::CSV_CHARS_PER_LINE, ',' );
+ fclose( $fp );
+ }
+
+ return $fileHeaders;
+ }
+}
+++ /dev/null
-<?php
-
-/**
- * Gaslight Media Members Database
- * Admin Data Import
- *
- * PHP version 5.5
- *
- * @category glmWordPressPlugin
- * @package glmMembersDatabase
- * @author Chuck Scott <cscott@gaslightmedia.com>
- * @license http://www.gaslightmedia.com Gaslightmedia
- * @version 0.1
- */
-require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH.'/data/dataCustomFieldsData.php';
-require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMemberInfo.php';
-/*
- * This class performs the work for the default action of the "Import" menu
- * option.
- *
- */
-class GlmMembersAdmin_import_fields extends GlmDataFieldsCustomFieldsData
-{
-
- const CSV_CHARS_PER_LINE = 6000;
- /**
- * WordPress Database Object
- *
- * @var $wpdb
- * @access public
- */
- public $wpdb;
- /**
- * Plugin Configuration Data
- *
- * @var $config
- * @access public
- */
- public $config;
-
- /**
- * errors
- *
- * @var $errors
- * @access public
- */
- public $errors = array();
-
- /**
- * numberProcessed
- *
- * @var float
- * @access public
- */
- public $numberProcessed = 0;
-
- /**
- * totalFields
- *
- * @var float
- * @access public
- */
- public $totalFields = 0;
-
- /**
- * processingComplete
- *
- * @var bool
- * @access public
- */
- public $processingComplete = false;
-
- /**
- * Constructor
- *
- * This contractor 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 successful 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)
- {
- // Set the view file
- $view = 'fields.html';
- $failure = false;
- $option = 'fields';
- $clearData = false;
- $importRet = false;
- $haveMembers = false;
- $fileExists = false;
- $isValid = false;
- // Check to see if they have members
- $haveMembers = $this->wpdb->get_var(
- "SELECT count(id)
- FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members"
- );
- // $fileData - The main files needed for the member import
- // - field: input field name
- // - name: file name
- // - exists: Does file exists. Set to false at first.
- // - validate: Validation array. Header line must match this.
- // - type: Type of file. Used in the processing function.
- $fileData = array(
- 'Fields' => array(
- 'field' => 'fields_file',
- 'name' => 'fieldsData.csv',
- 'exists' => false,
- 'validate' => array( 'member_id', 'field_name', 'field_value' ),
- 'type' => 'fields',
- ),
- );
- // Setting readyToProcess to false (initialize)
- $readyToProcess = false;
-
- // Set the $option if found in $_REQUEST array
- if (isset($_REQUEST['option']) && $_REQUEST['option'] != '') {
- $option = $_REQUEST['option'];
- }
-
- // Set the $option2 if found in $_REQUEST array
- if (isset($_REQUEST['option2']) && $_REQUEST['option2'] != '') {
- $option2 = $_REQUEST['option2'];
- }
-
- // Set variable for the upload directory
- $wpUploadDir = wp_get_upload_dir();
-
- // Set the $uploadPath for import files
- $uploadPath = $wpUploadDir['basedir'] . '/' . 'glm-member-import';
-
- // If the folder for the upload import files doesn't exists create one.
- if ( !is_dir( $uploadPath ) ) {
- // Get old umask
- $oldMask = umask(0);
- // Set folder permission
- mkdir( $uploadPath, 0770 );
- // reset old umask
- umask( $oldMask );
- }
-
- switch( $option ) {
-
- case 'fieldsValidate';
- $validFiles = 0;
- // Set the view file
- $view = 'fieldsValidate.html';
- $fileCount = count( $fileData );
- // Move any files uploaded
- if ( isset( $_FILES ) ) {
- foreach ( $fileData as $fileHeader => $file ) {
- if ( !$_FILES[$file['field']]['error'] ) {
- move_uploaded_file( $_FILES[$file['field']]['tmp_name'], $uploadPath . '/'. $file['name'] );
- }
- }
- }
- // Check that each file exists
- foreach ( $fileData as $fileHeader => $file ) {
- if ( is_file( $uploadPath . '/' . $file['name'] ) ) {
- $fileData[$fileHeader]['exists'] = true;
- $fData = $this->readCSVFileHeaders( $uploadPath . '/' . $file['name'] );
- $isValid = ( $file['validate'] == $fData );
- if ( $isValid ) {
- $validFiles++;
- }
- $fileData[$fileHeader]['data'] = $fData;
- $fileData[$fileHeader]['isValid'] = $isValid;
- }
- }
- $readyToProcess = ( $validFiles == $fileCount );
- break;
-
- case 'fieldsProcess':
- $memberInfoData = new GlmDataMemberInfo( $this->wpdb, $this->config );
- foreach ( $fileData as $fileHeader => $file ) {
- if ( is_file( $uploadPath . '/' . $file['name'] ) ) {
- $fields = $this->readCSVFields( $uploadPath . '/'. $file['name'] );
- //echo '<pre>$fields: ' . print_r( $fields, true ) . '</pre>';
- $this->totalFields = count( $fields );
- // Clear the custom field data table
- $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_field_data" );
- foreach ( $fields as $customRow ) {
- // Need to first get the member id from the database
- // It will match from the old_member_id field
- $memberId = $this->wpdb->get_var(
- $this->wpdb->prepare(
- "SELECT id
- FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
- WHERE old_member_id = %d",
- $customRow[0]
- )
- );
- // get the active member info id
- $memberInfoId =
- $memberInfoData->getActiveInfoIdForMember( $memberId );
- $customFieldId = $this->wpdb->get_var(
- $this->wpdb->prepare(
- "SELECT id
- FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_fields
- WHERE field_name = %s",
- $customRow[1]
- )
- );
- if ( $customFieldId ) {
- $newId = $this->wpdb->insert(
- GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . 'custom_field_data',
- array(
- 'ref_dest' => $memberInfoId,
- 'field_id' => $customFieldId,
- 'field_data' => $customRow[2],
- ),
- array(
- '%d',
- '%d',
- '%s'
- )
- );
- $this->numberProcessed++;
- }
- }
- $importRet = array();
- }
- }
- if ( count( $this->errors ) == 0 ) {
- $readyToProcess = true;
- }
- // Here we need to check to see if we processed all members.
- // Also the counter has to increment the total processed so far.
- if ( $this->numberProcessed == $this->totalFields ) {
- $this->processingComplete = true;
- }
- // Set the view file:<
- $view = 'fieldsProcess.html';
- break;
-
- case 'fields':
- default:
- // Set the view file
- $view = 'fields.html';
- // check upload dir to see if they have any files in yet
- foreach ( $fileData as $fileHeader => $file ) {
- if ( is_file( $uploadPath . '/' . $file['name'] ) ) {
- $fileData[$fileHeader]['exists'] = true;
- $fileData[$fileHeader]['mtime'] = filemtime( $uploadPath . '/' . $file['name'] );
- }
- }
-
- break;
-
- }
-
- // Setup the template data array
- $templateData = array(
- 'fileExists' => $fileExists,
- 'option' => $option,
- 'errors' => $this->errors,
- 'numberProcessed' => $this->numberProcessed,
- 'totalFields' => $this->totalFields,
- 'completed' => $this->processingComplete,
- 'data' => false,
- 'fileData' => $fileData,
- 'clearData' => $clearData,
- 'importRet' => $importRet,
- 'csvData' => '<pre>$fileData: ' . print_r( $fileData, true ) . '</pre>',
- 'readyToProcess' => $readyToProcess,
- 'haveMembers' => $haveMembers,
- 'isValid' => $isValid,
- 'sampleFileUrl' => GLM_MEMBERS_PLUGIN_BASE_URL . '/sample-files/',
- );
-
- // Return status, suggested view, and data to controller
- return array(
- 'status' => true,
- 'menuItemRedirect' => false,
- 'modelRedirect' => false,
- 'view' => 'admin/import/' . $view,
- 'data' => $templateData,
- );
-
- }
-
- /**
- * Read in fields from a csv file
- *
- * Header line as follows. Data follows immediately below this line. this
- * line and all above it are ignored.
- *
- * 'member_id','member_name','member_login','member_passwd','contact_email'
- *
- * @param string $csv Temporary file name of csv file upload
- *
- * @return array Array of data from CSV file or an error message
- *
- */
- public function readCSVFields($csv)
- {
-
- $fields = array();
- $startImport = false;
-
- // Try to open file
- if (($handle = fopen($csv, "r")) !== false) {
-
- // For each line in the file
- while (($c = fgetcsv($handle, 1000, ",")) !== false) {
-
- // If we're past the header, the first item is numeric, and we have at least 5 fields
- if($startImport && ($c[0]-0) > 0 && count($c) >= 3) {
-
- // Add this line of data to Contacts
- $fields[] = $c;
-
- }
-
- // If we find the header, assume all data is below that
- if ($c[0] == 'member_id') {
- $startImport = true;
- }
-
- }
-
- fclose($handle);
-
- } else {
- return "No file submitted.";
- }
-
- // If we never found the header
- if (!$startImport) {
- return "Required header not found in file.";
- }
-
- // If we found no data below the header
- if (count($fields) == 0) {
- return "Header found but no data followed";
- }
-
- return $fields;
-
- }
-
- /**
- * readCSVFileHeaders
- *
- * Read the cvs file. Just the first line is read.
- *
- * @param mixed $fileName Name of the file (path)
-
- * @access public
- * @return void
- */
- public function readCSVFileHeaders( $fileName )
- {
- $fileHeaders = array();
- if ( ( $fp = fopen( $fileName, 'r' ) ) !== false ) {
- // get first line to use as headers
- $fileHeaders = fgetcsv( $fp, SELF::CSV_CHARS_PER_LINE, ',' );
- fclose( $fp );
- }
-
- return $fileHeaders;
- }
-}
$customField = $this->insertEntry();
-trigger_error($_REQUEST['required'],E_USER_NOTICE);
-
if (!is_array($customField) || !$customField['status']) {
echo "0";
} else {
-
$viewFile = 'admin/ajax/newField.html';
$newFieldHtml = $this->generateHTML($customField, $viewFile);
echo $newFieldHtml;
$haveCustomFields = false;
$where = ' TRUE ';
+ $option = 'list';
if (isset($_REQUEST['option2'])) {
$option = $_REQUEST['option2'];
}
$id = $_REQUEST['id']-0;
}
- $uid = 0;
+ $fid = false;
- if (isset($actionData['uid'])) {
- $uid = $actionData['uid'];
+ // Look for the form ID (fid)
+ if (isset($actionData['fid'])) {
+ $fid = $actionData['fid'];
}
switch ($option) {
}
- $where .= " AND uid = '$uid' ";
+ $where .= " AND fid = '$fid' ";
// Get list of Custom Fields
$custom_fields = $this->getList( $where );
'custom_fields' => $custom_fields,
'field_types' => $this->config['custom_field_types'],
'haveCustomFields' => $haveCustomFields,
- 'uid' => $uid,
+ 'fid' => $fid,
'glm_action' => $glm_action
);
--- /dev/null
+<?php
+/**
+ * Gaslight Media Members Database
+ * GLM Members DB - Custom Fields Add-On - Form Segment Display
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release formDisplay,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link http://dev.gaslightmedia.com/
+ */
+
+require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH . '/data/dataCustomFields.php';
+require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH . '/data/dataCustomFieldsData.php';
+
+/**
+ * GlmMembersFront_customFields_formDisplay
+ *
+ * @uses GlmDataFields
+ * @package GlmMemberFields
+ * @version 0.0.1
+ * @copyright Copyright (c) 2010 All rights reserved.
+ * @license PHP Version 3.0 {@link http://www.php.net/license/3_0.txt}
+ */
+class GlmMembersFront_customFields_formDisplay extends GlmDataFieldsCustomFields
+{
+
+ /**
+ * 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 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.
+ *
+ */
+ public function modelAction( $actionData = false )
+ {
+
+ $formId = false;
+ $formFields = false;
+ $haveForm = false;
+ $view = 'displayForm.html';
+ $parentFormId = $actionData['request']['parent-form-id'];
+
+ if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) {
+ trigger_error('Shortcode Called: glm-members-customfields-form-display', E_USER_NOTICE);
+ }
+
+ // Make sure we have a valid FID and that the form exists
+ if (isset($actionData['request']) && isset($actionData['request']['fid'])) {
+
+ $formId = filter_var($actionData['request']['fid'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_LOW);
+
+ // Try to retrieve the form
+ $formFields = $this->getList("T.fid = '$formId'");
+ if ($formFields && count($formFields) > 0) {
+
+ $haveForm = true;
+
+ // Also add default fieldFail flags
+ foreach ($formFields as $fieldKey => $fieldVal) {
+ $form[$fieldKey]['field_fail'] = '';
+ }
+
+ }
+
+ }
+
+ // Compile template data
+ $templateData = array(
+ 'formId' => $formId,
+ 'formFields' => $formFields,
+ 'haveForm' => $haveForm,
+ 'parentFormId' => $parentFormId
+ );
+
+ return array(
+ 'status' => true,
+ 'modelRedirect' => false,
+ 'view' => 'front/customFields/'.$view,
+ 'data' => $templateData
+ );
+ }
+}
+
* {use} can be a description of the use or where it used (i.e. "reg-event-edit")
* {id} should be an ID of the record these fields are associated with, for example a registration event ID
*/
-add_filter( 'glm-members-customfields-edit', function( $content, $uid ){
+add_filter( 'glm-members-customfields-edit', function( $content, $fid ){
unset( $_REQUEST['glm_action'] );
- $content .= $this->controller( 'customFields', 'index', array( 'uid' => $uid ), true );
+ $content .= $this->controller( 'customFields', 'index', array( 'fid' => $fid ), true );
return $content;
}, 10, 2 );
-/**
- * Filter returns the html for the form segment
- */
-add_filter( 'glm-members-custom-fields-form', function( $content, $uid, $id,$cfData = false ){
- unset( $_REQUEST['glm_action'] );
- // echo "CONTENT: " . $content . " UID: " . $uid . " ID: " . $id . '<br>';
- $content .= $this->controller( 'entity', 'fields', array( 'uid' => $uid, 'entityID' => $id,'cfData'=>$cfData ), true);
- return $content;
-}, 10, 4 );
-
/**
* Filter Captured Data Success Status
*
return true;
}, 10, 1 );
+
+/**
+ * Does the specified Form ID have any input fields
+ *
+ * @param $content string Default state (supply false). This will be overridden if result is true.
+ * @param $fid string Unique ID of form
+ *
+ * returns an array with status and HTML for editing the form.
+ */
+add_filter( 'glm-members-customfields-have-fields', function( $haveFields, $fid){
+
+ if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) {
+ trigger_error('Custom Fields Filter Called: glm-members-customfields-have-fields', E_USER_NOTICE);
+ }
+
+ // Get the number of custom fields for this Form ID
+ require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH.'/data/dataCustomFields.php';
+ $CustomFields = new GlmDataFieldsCustomFields($this->wpdb, $this->config);
+ $fieldStats = $CustomFields->getStats("T.fid = '$fid'");
+
+ if ($fieldStats) {
+ $haveFields = true;
+ }
+
+ return $haveFields;
+
+}, 10, 4 );
+
+/**
+ * Return HTML for a custom fields form segment
+ *
+ * @param $content string Any supplied content. Form will be appended to this
+ * @param $fid string Unique ID of form
+ * @param $recordId integer Optional ID for instance of this form (generally the ID of the associated record)
+ * If this is 0 then it's assumed this is a new form with no existing data.
+ * @param $submitId string Optional ID of the submit button for the form this will be part of.
+ * @param $formData array Optional array of data used to populate form (Not sure we're going to keep this)
+ *
+ * returns an array with status and HTML for editing the form.
+ */
+add_filter( 'glm-members-customfields-form-display', function( $content, $fid, $recordId = 0, $parentFormId = false, $formData = false ){
+
+ if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) {
+ trigger_error('Custom Fields Filter Called: glm-members-customfields-form-display', E_USER_NOTICE);
+ }
+
+ // Call form display shortcode to do this work
+ $content .= do_shortcode('[glm-members-customfields-form-display fid='.$fid.' record-id='.$recordId.' parent-form-id='.$parentFormId.' form-data='.$formData.']');
+
+ return $content;
+
+}, 10, 4 );
+
+/**
+ * Submit a specific custom fields form segment
+ *
+ * @param $content string Any supplied content. Form will be appended to this
+ * @param $fid string Unique ID of form
+ * @param $recordId integer Optional ID for instance of this form (generally the ID of the associated record)
+ * If this is 0 then it's assumed this is a new form with no existing data.
+ * @param $store boolean Flag to request that submitted data also be stored
+ *
+ * returns an array with status and HTML for editing the form.
+ */
+add_filter( 'glm-members-customfields-form-submit', function( $content, $fid, $recordId = 0, $store = false ){
+
+ if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) {
+ trigger_error('Custom Fields Filter Called: glm-members-customfields-form-submit', E_USER_NOTICE);
+ }
+
+ require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH.'/customFieldSupport.php';
+ $CustomFieldSupport = new GlmCustomFieldSupport($this->wpdb, $this->config);
+
+ $content = $CustomFieldSupport->submitForm($fid, $recordId, $store);
+
+ return $content;
+
+}, 10, 4 );
+
+/**
+ * Store data from a call to the "glm-members-customfields-form-submit" filter
+ *
+ * @param $content string Any supplied content. Form will be appended to this
+ * @param $fid string Unique ID of form
+ * @param $recordId integer ID for instance of this form (generally the ID of the associated record) - Required
+ * @param $formData array Copy of the array returned by the "glm-members-customfields-form-submit" filter.
+ *
+ * returns an array with status and HTML for editing the form.
+ */
+add_filter( 'glm-members-customfields-form-store', function( $content, $fid, $recordId = 0, $submitData = false ){
+
+ if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) {
+ trigger_error('Custom Fields Filter Called: glm-members-customfields-form-store', E_USER_NOTICE);
+ }
+
+ require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH.'/customFieldSupport.php';
+ $CustomFieldSupport = new GlmCustomFieldSupport($this->wpdb, $this->config);
+
+ $content .= $CustomFieldSupport->storeForm($fid, $recordId, $submitData);
+
+ return $content;
+
+}, 10, 4 );
+
+
+
+
+++ /dev/null
--- Gaslight Media Members Database - Fields Add-On
--- File Created: 2017-03-27
--- Database Version: 1.0.0
--- Database Creation Script
---
--- This file is called to create a new set of tables for this
--- add-on for the most recent database version for this add-on.
---
--- There should only be one such file in this directory
---
--- To permit each query below to be executed separately,
--- all queries must be separated by a line with four dashes
-
-
--- Field Setup Table
-CREATE TABLE {prefix}custom_fields (
- id INT NOT NULL AUTO_INCREMENT,
- field_name TINYTEXT NOT NULL DEFAULT '', -- Field Name
- field_type TINYTEXT NOT NULL DEFAULT '', -- Field Type
- field_order SMALLINT NOT NULL DEFAULT 0, -- Order for Field
- admin_search BOOLEAN NOT NULL DEFAULT '0', -- If the field is added to member list filters.
- required BOOLEAN NOT NULL DEFAULT '0', -- If the field is required.
- uid varchar(255) NOT NULL DEFAULT '', -- id for the series of custom fields associated with an entity
- PRIMARY KEY (id),
- INDEX(field_name(20))
-);
-
-----
-
--- Data Table
-CREATE TABLE {prefix}custom_field_data (
- id INT NOT NULL AUTO_INCREMENT,
- field_id INT NOT NULL DEFAULT 0, -- Field Id -- Member Info Id
- field_data TEXT NOT NULL DEFAULT '', -- Data for the field
- entity_id INT NOT NULL DEFAULT 0, -- id for the specific field associated with an entity
- PRIMARY KEY (id),
- INDEX(field_id),
- INDEX(entity_id)
-);
--- /dev/null
+-- Gaslight Media Members Database - Fields Add-On
+-- File Created: 2017-03-27
+-- Database Version: 1.0.0
+-- Database Creation Script
+--
+-- This file is called to create a new set of tables for this
+-- add-on for the most recent database version for this add-on.
+--
+-- There should only be one such file in this directory
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+
+
+-- Field Setup Table
+CREATE TABLE {prefix}custom_fields (
+ id INT NOT NULL AUTO_INCREMENT,
+ fid TEXT NOT NULL DEFAULT '', -- Unique ID for this form (group of these fields)
+ field_name TINYTEXT NOT NULL DEFAULT '', -- Field reference name
+ field_prompt TINYTEXT NOT NULL DEFAULT '', -- Prompt to display on form to user
+ field_type TINYTEXT NOT NULL DEFAULT '', -- Field Type
+ field_order SMALLINT NOT NULL DEFAULT 0, -- Order for Field
+ required BOOLEAN NOT NULL DEFAULT '0', -- If the field is required.
+ PRIMARY KEY (id),
+ INDEX (field_name(40))
+);
+
+----
+
+-- Data Table
+CREATE TABLE {prefix}custom_field_data (
+ id INT NOT NULL AUTO_INCREMENT,
+ field_id INT NOT NULL DEFAULT 0, -- Pointer to ID of custom_fields table for this field
+ record_id INT NOT NULL DEFAULT 0, -- id for this submission of this form
+ text_data TEXT NOT NULL DEFAULT '', -- Data for a text field
+ checkbox_data BOOLEAN NOT NULL DEFAULT '', -- Data for a boolean field
+ integer_data INTEGER NOT NULL DEFAULT '', -- Data for an integer field
+ float_data FLOAT NOT NULL DEFAULT '', -- Data for a float field
+ PRIMARY KEY (id),
+ INDEX (field_id),
+ INDEX (record_id)
+);
*/
$glmMembersCustomFieldsDbVersions = array(
- '1.0.0' => array('version' => '1.0.0', 'tables' => 2, 'date' => '12/01/2017')
+ '1.0.0' => array('version' => '1.0.0', 'tables' => 2, 'date' => '12/01/2017'),
+ '1.0.1' => array('version' => '1.0.1', 'tables' => 2, 'date' => '12/05/2017')
);
--- /dev/null
+-- Gaslight Media Members Database - Registratiuons Add-On
+-- File Created: 08/30/16 09:47:15
+-- Database Version: 0.0.7
+-- Database Update From Previous Version Script
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+
+
+ALTER TABLE {prefix}custom_fields CHANGE uid fid TEXT;
+
+----
+
+ALTER TABLE {prefix}custom_fields DROP COLUMN admin_search;
+
+----
+
+DROP INDEX entity_id ON {prefix}custom_field_data;
+
+----
+
+ALTER TABLE {prefix}custom_field_data CHANGE entity_id record_id INTEGER;
+
+----
+
+CREATE INDEX record_id ON {prefix}custom_field_data (record_id);
+
+----
+
+ALTER TABLE {prefix}custom_field_data CHANGE field_data text_data TEXT;
+
+----
+
+ALTER TABLE {prefix}custom_field_data ADD COLUMN checkbox_data BOOLEAN;
+
+----
+
+ALTER TABLE {prefix}custom_field_data ADD COLUMN integer_data INTEGER;
+
+----
+
+ALTER TABLE {prefix}custom_field_data ADD COLUMN float_data FLOAT;
+
+----
+
+ALTER TABLE {prefix}custom_fields ADD COLUMN field_prompt TINYTEXT;
*
* *** Also note that parameters will be in the context of the main front controller constructor. ***
*/
-add_filter('glm-member-db-front-members-detail-sidebar', function($content, $id) {
- $fieldData = do_shortcode('[glm-members-fields-detail member='.$id.', template="detail-sidemenu" order="title"]');
- $content .= $fieldData;
- return $content;
- },
- 10,
- 2
-);
-add_filter('glm-member-db-front-members-list-info', function($content, $id) {
- $fieldData = do_shortcode('[glm-members-fields-list member='.$id.', template="detail-sidemenu" order="title"]');
- $content .= $fieldData;
- return $content;
- },
- 10,
- 2
-);
-add_filter( 'glm-member-db-front-search-query', function( $queryParts ) {
- // Get all custom fields
- $customFields = $this->wpdb->get_results(
- "SELECT *
- FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_fields",
- ARRAY_A
- );
- if ( isset( $customFields ) && count( $customFields ) > 0 ) {
- foreach ( $customFields as $key => $field ) {
- switch ( $field['field_type'] ) {
- case 'text':
- case 'textarea':
- $field_name = preg_replace( '/[ -]/', '_', strtolower( $field['field_name'] ) );
- if ( isset( $_REQUEST[$field_name] ) && filter_var( $_REQUEST[$field_name], FILTER_SANITIZE_STRING ) ) {
- $textSearch = $this->wpdb->esc_like( $_REQUEST[$field_name] );
- $queryParts[] = " T.id IN (
- SELECT entity_id
- FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_field_data
- WHERE field_data like '%" . $textSearch . "%'
- AND field_id = (SELECT id
- FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_fields
- WHERE field_name = '" . esc_sql( $field['field_name'] ) . "')
- ) ";
- }
-
- break;
- case 'checkbox':
- // convert name to lower case and replace spaces with _
- $field_name = preg_replace( '/[ -]/', '_', strtolower( $field['field_name'] ) );
- if ( isset( $_REQUEST[$field_name] ) && filter_var( $_REQUEST[$field_name], FILTER_VALIDATE_BOOLEAN ) ) {
- $queryParts[] = " T.id IN (
- SELECT entity_id
- FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_field_data
- WHERE field_data = 'Yes'
- AND field_id = (SELECT id
- FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_fields
- WHERE field_name = '" . esc_sql( $field['field_name'] ) . "')
- ) ";
- }
- break;
- }
- }
- }
- return $queryParts;
-});
-add_filter( 'glm-member-db-front-search-request', function( $actionData ) {
- global $wpdb;
- // Get all custom fields
- $customFields = $wpdb->get_results(
- "SELECT *
- FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_fields",
- ARRAY_A
- );
- if ( isset( $customFields ) && count( $customFields ) > 0 ) {
- foreach ( $customFields as $key => $field ) {
- // convert name to lower case and replace spaces with _
- $field_name = preg_replace( '/[ -]/', '_', strtolower( $field['field_name'] ) );
- if ( isset( $actionData['request'][$field_name] ) && $actionData['request'][$field_name]) {
- $_REQUEST[$field_name] = $actionData['request'][$field_name];
- }
- }
- }
- return $actionData;
-}, 10, 1);
-add_filter( 'glm-member-db-customfields-front-list-query-params', function( $query ){
- $queryParams = array();
- // Get all custom fields
- $customFields = $this->wpdb->get_results(
- "SELECT field_name,field_type
- FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_fields",
- ARRAY_A
- );
- foreach ( $customFields as $field ) {
- switch ( $field['field_type'] ) {
- case 'checkbox':
- $fieldName = preg_replace( '/[ -]/', '_', strtolower( $field['field_name'] ) );
- if ( isset( $_REQUEST[$fieldName] ) ) {
- $queryParams[] = "$fieldName={$_REQUEST[$fieldName]}";
- }
- break;
- }
- }
- return ( !empty( $queryParams ) ? $query . '&'.implode( '&', $queryParams): $query);
-},10, 1);
-
-add_filter('get_glm_custom_fields', function($uid,$entity_id) {
- global $wpdb;
- $fieldsTable = GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_fields";
- $dataTable = GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_field_data";
-
- $query = "SELECT $dataTable.field_data, $fieldsTable.field_type, $fieldsTable.field_name "
- . "FROM $dataTable "
- . "LEFT JOIN $fieldsTable "
- . "ON $dataTable.field_id = $fieldsTable.id WHERE $dataTable.entity_id = $entity_id;";
-
- $result = $this->wpdb->get_results( $query, ARRAY_A );
- foreach($result as $key=>$value){
- if ($result[$key]['field_type'] == 'textarea') {
- $result[$key]['field_data'] = wpautop($result[$key]['field_data']);
- }
- }
-
-// echo "<pre>AA" . print_r($result) . "ZZ";
- return $result;
- },
- 10,
- 2
-);
-add_filter('glm_custom_fields', function($attribute, $id = 0) {
-
- global $wpdb;
- $query = "SELECT D.field_data, F.field_type FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_field_data D, ".GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX."custom_fields F "
- . "WHERE D.entity_id = $id "
- . "AND D.field_id IN (SELECT id FROM ".GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX."custom_fields WHERE field_name LIKE '$attribute' ) "
- . "AND F.field_name LIKE '$attribute'";
-
- $result = $this->wpdb->get_row( $query, ARRAY_A );
- if ($result['field_type'] == 'textarea') {
- $result['field_data'] = wpautop($result['field_data']);
- }
-// echo "<pre>AA" . print_r($result) . "ZZ";
- return $result['field_data'];
- },
- 10,
- 2
-);
-add_filter('glm_custom_fields_member_types', function() {
-
- $query = "SELECT name FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_type";
- $result = $this->wpdb->get_results( $query, ARRAY_A );
- return $result;
- },
- 10,
- 2
-);
-
-/**
- * Filter: glm-get-custom-field-count
- * Usage: apply_filters( 'glm-get-custom-field-count','reviewed','Yes' )
- */
-add_filter( 'glm-get-custom-field-count', function( $field_name, $field_value = '' ){
- if ( $field_name ) {
- global $wpdb;
- $sql = "SELECT count(field_data) FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_field_data WHERE field_data LIKE '$field_value'"
- . " AND field_id IN (SELECT id FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_fields WHERE field_name LIKE '$field_name')";
- $count = $wpdb->get_var(
- $sql
- );
- return $count;
- }
- return false;
-},
-10,
-2
-);
<tr>
<td>glm-members-customfields-edit</td>
<td>FILTER</td>
- <td>$content, $uid</td>
+ <td>$content, $fid</td>
<td>
- Return HTML for field add/delete/edit for the specified form ($uid).
+ Return HTML for field add/delete/edit for the specified form ($fid).
<p>
The $content parameter should be an empty string when this filter is applied.
Any HTML returned from this filter will be appended to the supplied text.
resulting string that's returned.
</p>
<p>
- The $uid parameter is a text string that is a unique identifier for the the form that is to
+ The $fid parameter is a text string that is a unique identifier for the the form that is to
be edited. This should include the slug of the plugin that is calling
for this form and a name or other identifier for the specific form. This might
typically be specified in the form of a slug with hyphens between the words.
</tr>
<tr><th colspan="3">Fields Use</th></tr>
<tr>
- <td>glm-members-custom-fields-form</td>
+ <td>glm-members-customfields-form-display</td>
<td>FILTER</td>
- <td>$content, $uid, $id, $cfData</td>
+ <td>$content, $fid, $id, ,$parentFormId, $cfData</td>
<td>
- Displays a specific custom fields from to request user input.
+ Displays a specific custom fields form to request user input.
<p>
The $content parameter should be an empty string when this filter is applied.
Any HTML returned from this filter will be appended to the supplied text.
resulting string that's returned.
</p>
<p>
- The $uid parameter is a text string that is a unique identifier for the the form that is to
+ The $fid parameter is a text string that is a unique identifier for the the form that is to
be edited. This should include the slug of the plugin that is calling
for this form and a name or other identifier for the specific form. This might
typically be specified in the form of a slug with hyphens between the words.
</p>
<p>
The $id parameter is an INTEGER that is unique to this specific use of the form
- specified by $uid. For example, if $uid points to a form with added fields to
+ specified by $fid. For example, if $fid points to a form with added fields to
be used along with the usual fields in a contact information form, the $id
parameter might be the 'id' field from the record containing the contact that's
being edited. Any results submitted will be stored along with this $id. If
- this $uid and $id pair are used anywhere else, data submitted there will replace
+ this $fid and $id pair are used anywhere else, data submitted there will replace
the other uses of the same form and id.
</p>
+ <p>
+ If the $parentFormId parameter is supplied, additional JAVAScript code will be included
+ in the form segment output to link into the submit process and check for all required
+ data in the form segment. If that segment has any required fields that are not
+ completed, it will display a notice and block submission of the form. Note that
+ this requires jQuery to be loaded and available.
+ </p>
<p>
The $cfData field is an array that contains field data to use as the default
when the form is displayed. This will usually come from a previous submission
*/
$glmMembersCustomFieldsShortcodes = array(
- 'glm-members-fields-detail' => array(
+ 'glm-members-customfields-form-display' => array(
'plugin' => GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_SLUG,
- 'menu' => 'fields',
- 'action' => 'detail',
+ 'menu' => 'customFields',
+ 'action' => 'formDisplay',
'table' => false,
'attributes' => array(
- 'type' => 'all',
- 'order' => 'title',
- 'member' => false,
- 'template' => false,
- 'limit' => null,
- 'featured' => null,
- 'current' => null,
+ 'fid' => false,
+ 'record-id' => false,
+ 'parent-form-id' => false,
+ 'form-data' => false
)
),
- 'glm-members-fields-list' => array(
+ 'glm-members-customfields-form-submit' => array(
'plugin' => GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_SLUG,
- 'menu' => 'fields',
- 'action' => 'list',
+ 'menu' => 'customFields',
+ 'action' => 'formDisplay',
'table' => false,
'attributes' => array(
- 'type' => 'all',
- 'order' => 'title',
- 'member' => false,
- 'template' => false,
- 'limit' => null,
- 'featured' => null,
- 'current' => null,
+ 'fid' => false,
+ 'record-id' => false,
+ 'parent-form-id' => false,
+ 'form-data' => false
)
- ),
+ )
);
-$glmMembersCustomFieldsShortcodesDescription = '';
+$glmMembersCustomFieldsShortcodesDescription = '
+<tr>
+ <th>[glm-members-customfields-form-display]</th>
+ <td> </td>
+ <td width="50%">
+ Displays a specific custom form for a specific record.
+ </td>
+</tr>
+<tr>
+ <td> </td>
+ <th>fid="{Form ID String}"</th>
+ <td>
+ The "fid" attribute is the Form ID string that is unique to the
+ custom form created using admin "glm-members-customfields-edit" filter.
+ <p>
+ The standard for this for ID is "{add-on-slug}-customfields-{descr-slug}-{optional-id}.<br>
+ where:<br>
+ {add-on-slug} is the calling add-on\'s slug<br>
+ {descr-slug} is a short slug describing the use of this form<br>
+ {optional-id} is the optional ID of a record this form is always associated with<br>
+ </p>
+ <p>
+ The {optional-id} would be required if there are multiple uses of this form. For example, if
+ the form is for added fields for a registrant to an event, the each event would have a form
+ of this type (which might be different). In that case the event ID could be use as the
+ {optional-id} to distinguish the form for one event from anohter event. Also in this case
+ there would be mulitple registrants for a specific event, so another specific ID will be used for each
+ registrant. This is the "record-id" specified when using the form for input or retrieving that
+ data later.
+ </p>
+ </td>
+</tr>
+<tr>
+ <td> </td>
+ <th>record-id="{Record ID Number}"</th>
+ <td>
+ The "record-id" attribute is a unique numberic id for a specific instance (use) of this custom form.
+ This is optional. If it\'s not supplied the default is 0. Using the default would be appropriate for
+ situations where there only be a single use of this form, which is probably unusual.
+ </td>
+</tr>
+<tr>
+ <td> </td>
+ <th>parent-form-id="{ID of Parent Form}"</th>
+ <td>
+ If the "parent-form-id" attribute is supplied, the custom form segment will include jQuery scripting
+ that will hook into the checkout action of the form. If any of the custom fields that are required
+ are not completed, this code will display a notice to the user and block form submission.<br>
+ <br>
+ If you have code on that page that intercepts the submit action, use the following code to determine
+ if submit has been blocked by a custom fields form before taking other action.
+ <pre>
+ if (e.isDefautPrevented()) {
+ return false;
+ }
+ </pre>
+ </td>
+</tr>
+<tr>
+ <td> </td>
+ <th>form-data="{serialized data}"</th>
+ <td>
+ The "form-data" attribute is a serialized compilation of default data for this form. (might not use this here)
+ This attribute is optional. If not supplied, the default form values are used.
+ </td>
+</tr>
+<tr>
+ <th>[glm-members-customfields-form-submit]</th>
+ <td> </td>
+ <td width="50%">
+ Processes submission of a specific form segment.
+ </td>
+</tr>
+<tr>
+ <td> </td>
+ <th colspan="3">NOT WRITTEN YET</th>
+</tr>
+';
)
),
'frontActions' => array(
- 'fields' => array(
-// 'list' => GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_SLUG,
-// 'detail' => GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_SLUG,
+ 'customFields' => array(
+ 'formDisplay' => GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_SLUG
),
)
);
{* A single line for the custom fields edit table *}
- <tr id="glmCustomFieldsFieldRow_{$fieldData.id}">
- <td><div>{$fieldData.field_name}</div></td>
+ <tr id="FieldRow_{$fieldData.id}">
+ <td>{$fieldData.field_name}</td>
<td id="editFieldType_{$fieldData.id}">{$fieldData.field_type.name}</td>
<td>{$fieldData.required.name}</td>
<td>
-<!-- <div class="glmCustomFieldsEditFieldButton button button-secondary glm-button-small" data-fieldID="{$fieldData.id}" data-fieldType="{$fieldData.field_type.name|escape:'html'}" data-adminSearch="{$fieldData.admin_search.value}" data-required="{$fieldData.required.value}">Edit</div>
+<!-- <div class="glmCustomFieldsEditFieldButton button button-secondary glm-button-small" data-fieldID="{$fieldData.id}" data-fieldName="{$fieldData.field_name|escape:'html'}" data-fieldPrompt="{$fieldData.field_prompt|escape:'html'}" data-fieldType="{$fieldData.field_type.name|escape:'html'}" data-adminSearch="{$fieldData.admin_search.value}" data-required="{$fieldData.required.value}">Edit</div>
-->
- <div class="glmCustomFieldsDeleteFieldButton button button-secondary glm-button-small glm-right" data-fieldID="{$fieldData.id}">Delete</div>
+ <div class="{$fieldData.fid}_DeleteFieldButton button button-secondary glm-button-small" data-fieldID="{$fieldData.id}">Delete</div>
</td>
</tr>
+ <tr><td colspan="4" style="padding-left: 2rem;">Prompt: {$fieldData.field_prompt}</td></tr>
\ No newline at end of file
<!-- Add Custom Field Button and Dialog Box -->
-<div id="newFieldButton" class="button button-primary glm-right">Add a Custom Field</div>
{* New field form *}
-<div id="glmCustomFieldsNewFieldDialog" class="glm-dialog-box" title="Enter a New Custom Field">
- <table class="glm-admin-table">
+<div id="{$fid}_NewFieldDialog" class="glm-dialog-box" style="width: 100%" title="Enter a New Custom Field">
+ <table class="glm-admin-table" style="width: 100%">
<tr>
<th class="glm-required">Field Name:</th>
- <td>
- <input id="glmCustomFieldsNewFieldName" type="text" name="field_name" class="glm-form-text-input">
- </td>
+ <td><input id="{$fid}_NewFieldName" type="text" name="field_name" class="glm-form-text-input-small"></td>
+ </tr>
+ <tr>
+ <th class="glm-required" style="width: 20%; white-space: nowrap;">User Prompt:</th>
+ <td><input id="{$fid}_NewFieldPrompt" type="text" name="field_prompt" class="glm-form-text-input"></td>
</tr>
<tr>
- <th class="glm-required">Field Type:</th>
+ <th style="width: 20%; white-space: nowrap;" class="glm-required">Field Type:</th>
<td>
- <select id="glmCustomFieldsNewFieldType" name="field_type">
+ <select id="{$fid}_NewFieldType" name="field_type">
+ <option value=""></option>
{foreach $field_types as $val => $label}
<option value="{$val}">{$label}</option>
{/foreach}
</td>
</tr>
<tr>
- <th>Required?</th>
- <td>
- <input id="glmCustomFieldsNewFieldRequired" type="checkbox" name="required">
- </td>
+ <th style="width: 20%; white-space: nowrap;">Required?</th>
+ <td><input id="{$fid}_NewFieldRequired" type="checkbox" name="required"></td>
</tr>
- <input type="hidden" name="uid" value="{$uid}">
</table>
<p><span class="glm-required">*</span> Required</p>
- <div id="glmCustomFieldsNewFieldCancel" class="button button-primary glm-right">Cancel</div>
- <div id="glmCustomFieldsNewFieldSubmit" class="button button-primary">Add new Custom Field</div>
- <div id="glmCustomFieldsNewFieldDialogError" class="glm-error" style="display: none;"><p>Unable to create custom field. Did you supply all required information?</p></div>
+ <div id="{$fid}_NewFieldCancel" class="button button-primary glm-right">Cancel</div>
+ <div id="{$fid}_NewFieldSubmit" class="button button-primary">Add new Custom Field</div>
+ <div id="{$fid}_NewFieldDialogError" class="glm-error" style="display: none;"><p>Unable to create custom field. Did you supply all required information?</p></div>
</div>
{* Delete field button confirmation dialog box *}
-<div id="glmCustomFieldsDeleteFieldDialog" class="glm-dialog-box" title="Delete Field">
+<div id="{$fid}_DeleteFieldDialog" class="glm-dialog-box" title="Delete Field">
<center>
<p>Are you sure you want to delete this field?</p>
- <p><div id="glmCustomFieldsDeleteFieldConfirm" class="button button-primary">Yes, delete this field</div></p>
- <p><div id="glmCustomFieldsDeleteFieldCancel" class="button button-primary">Cancel</div></p>
+ <p><div id="{$fid}_DeleteFieldConfirm" class="button button-primary">Yes, delete this field</div></p>
+ <p><div id="{$fid}_DeleteFieldCancel" class="button button-primary">Cancel</div></p>
</center>
</div>
{* Edit field dialog box *}
-<div id="editFieldDialog" class="glm-dialog-box" title="Edit this Field">
- <form action="{$thisUrl}?page={$thisPage}&glm_action={$glm_action}&option=customfields" method="post" enctype="multipart/form-data">
- <input type="hidden" name="glm_action" value="{$glm_action}">
- <input type="hidden" name="option" value="customfields">
- <input type="hidden" name="option2" value="update">
- <input id="editFieldID" type="hidden" name="id" value="">
- <table class="glm-admin-table">
+<div id="{$fid}_editFieldDialog" class="glm-dialog-box" title="Edit this Field">
+ <table class="glm-admin-table" style="width: 100%;">
<tr>
- <th class="glm-required">Field Name:</th>
- <td>
- <input id="editFieldName" type="text" name="field_name" class="glm-form-text-input">
- </td>
+ <th class="glm-required" style="width: 20%; white-space: nowrap;">Field Name:</th>
+ <td><input id="{$fid}_editFieldName" type="text" name="field_name" class="glm-form-text-input"></td>
</tr>
<tr>
- <th class="glm-required">Field Type:</th>
+ <th class="glm-required" style="width: 20%; white-space: nowrap;">User Prompt:</th>
+ <td><input id="{$fid}_editFieldPrompt" type="text" name="field_prompt" class="glm-form-text-input"></td>
+ </tr>
+ <tr>
+ <th class="glm-required" style="width: 20%; white-space: nowrap;">Field Type:</th>
<td>
- <select id="editFieldType" name="field_type">
+ <select id="{$fid}_editFieldType" name="field_type">
+ <option value=""></option>
{foreach $field_types as $val => $label}
<option value="{$val}">{$label}</option>
{/foreach}
</select>
</td>
</tr>
- <!-- The UID check below is just a TEMPORARY measure until we have search filters implemented on plugins beyond glm-member-db -->
- {if $uid == 'glm-member-db'}
- <tr>
- <th>Admin Searchable</th>
- <td>
- <input type="hidden" name="admin_search" value="0" />
- <input type="checkbox" id="editAdminSearch" name="admin_search" value="1" />
- (text or checkbox only)
- </td>
- </tr>
- {/if}
<tr>
<th>Required?</th>
- <td>
- <input type="hidden" name="required" value="0" />
- <input type="checkbox" id="editRequired" name="required" value="1" />
- </td>
+ <td><input type="checkbox" id="{$fid}_editRequired" name="required" value="1" /></td>
</tr>
- <input type="hidden" name="uid" value="{$uid}">
</table>
<p><span class="glm-required">*</span> Required</p>
- <a id="editFieldCancel" class="button button-primary glm-right">Cancel</a>
+ <a id="{$fid}_editFieldCancel" class="button button-primary glm-right">Cancel</a>
<input type="submit" value="Update this Field">
- </form>
</div>
{* Update and error messages *}
</table>
{* Fields Table *}
-<table class="glm-admin-table glm-settings-table">
+<table class="glm-admin-table glm-settings-table" style="width: 100%">
<thead>
<tr>
<th>Field Name</th>
<th>Type</th>
<th>Required</th>
- <th> </th>
+ <th>
+ <div id="{$fid}_newFieldButton" class="button button-primary glm-button-small">Add a Custom Field</div>
+
+
+ </th>
</tr>
</thead>
- <tbody id="glmCustomFieldsListBody">
+ <tbody id="{$fid}_FieldsListBody">
{if $haveCustomFields}
{foreach $custom_fields as $t}
- <tr id="glmCustomFieldsFieldRow_{$t.id}">
- <td>
- <div>
- {$t.field_name}
- </div>
- </td>
+ <tr id="FieldRow_{$t.id}">
+ <td>{$t.field_name}</td>
<td id="editFieldType_{$t.id}">
{$t.field_type.name}
</td>
<td>
{$t.required.name}
</td>
- <td>
-<!-- <div class="glmCustomFieldsEditFieldButton button button-secondary glm-button-small" data-fieldID="{$t.id}" data-fieldName="{$t.field_namme}" data-fieldType="{$t.field_type.name|escape:'html'}" data-adminSearch="{$t.admin_search.value}" data-required="{$t.required.value}">Edit</div>
+ <td style="width: 10%;">
+<!-- <div class="{$fid}_EditFieldButton button button-secondary glm-button-small" data-fieldId="{$t.id}" data-fieldName="{$t.field_name|escape:'html'}" data-fieldPrompt="{$t.field_prompt|escape:'html'}" data-fieldType="{$t.field_type.name|escape:'html'}" data-required="{$t.required.value}">Edit</div>
-->
- <div class="glmCustomFieldsDeleteFieldButton button button-secondary glm-button-small" data-fieldID="{$t.id}">Delete</div>
+ <div class="{$fid}_DeleteFieldButton button button-secondary glm-button-small" data-fieldId="{$t.id}">Delete</div>
</td>
</tr>
+ <tr><td colspan="4" style="padding-left: 2rem;">Prompt: {$t.field_prompt}</td></tr>
{/foreach}
{else}
- <tr id="noCustomFieldsNotice" class="alternate"><td colspan="2">(no custom fields listed)</td></tr>
+ <tr id="{$fid}_noCustomFieldsNotice" class="alternate"><td colspan="2">(no custom fields listed)</td></tr>
{/if}
</tbody>
</table>
<!-- Tests -->
-<script type="text/javascript">glmCustomFieldsNewFieldCancel
+<script type="text/javascript">
jQuery(document).ready(function($) {
- var deleteId = false;
+ var {$fid}_deleteId = false;
/*
* New field dialog box
*/
// Ssetup
- $("#glmCustomFieldsNewFieldDialog").dialog({
+ $("#{$fid}_NewFieldDialog").dialog({
autoOpen: false,
minWidth: 600,
dialogClass: "glm-dialog-no-close"
});
- // Display form
- $('#newFieldButton').click( function() {
- $("#glmCustomFieldsNewFieldDialog").dialog("open");
+ // Display form and reset all input
+ $('#{$fid}_newFieldButton').click( function() {
+ $("#{$fid}_NewFieldDialog").dialog("open");
+ $('#{$fid}_NewFieldName').val(''),
+ $('#{$fid}_NewFieldPrompt').val(''),
+ $('#{$fid}_NewFieldType').prop('selectedIndex',0),
+ $('#{$fid}_NewFieldRequired').removeAttr('checked')
});
// Submit form
- $('#glmCustomFieldsNewFieldSubmit').click( function() {
+ $('#{$fid}_NewFieldSubmit').click( function() {
// Collect the new field data
var formData = {
'action': 'glm_members_admin_ajax',
'glm_action': 'customFields',
'option': 'addNewField',
- 'uid': '{$uid}',
- 'field_name': $('#glmCustomFieldsNewFieldName').val(),
- 'field_type': $('#glmCustomFieldsNewFieldType').val(),
- 'required': $('#glmCustomFieldsNewFieldRequired').is(':checked'),
- 'admin_search': 0
+ 'fid': '{$fid}',
+ 'field_name': $('#{$fid}_NewFieldName').val(),
+ 'field_prompt': $('#{$fid}_NewFieldPrompt').val(),
+ 'field_type': $('#{$fid}_NewFieldType').val(),
+ 'required': $('#{$fid}_NewFieldRequired').is(':checked')
};
// Submit new field data - expect field new ID back
})
.done( function(fieldHtml) {
if (fieldHtml == '') {
- flashElement('glmCustomFieldsNewFieldDialogError');
+ flashElement('{$fid}_NewFieldDialogError');
} else {
- $('#glmCustomFieldsListBody').append(fieldHtml);
- $('#noCustomFieldsNotice').hide();
- $("#glmCustomFieldsNewFieldDialog").dialog("close");
-
- // Need to rebind delete field buttons
- $('.glmCustomFieldsEditFieldButton').unbind('click', editFieldButton);
- $('.glmCustomFieldsEditFieldButton').click(editFieldButton);
+
+ $('#{$fid}_FieldsListBody').append(fieldHtml);
+ $('#{$fid}_noCustomFieldsNotice').hide();
+ $("#{$fid}_NewFieldDialog").dialog("close");
+ // Need to rebind edit field buttons
+ $('body').off('click', '.{$fid}_EditFieldButton', {$fid}_editFieldButton);
+ $('body').on('click', '.{$fid}_EditFieldButton', {$fid}_editFieldButton);
+
// Need to rebind delete field buttons
- $('.glmCustomFieldsDeleteFieldButton').unbind('click', deleteFieldButton);
- $('.glmCustomFieldsDeleteFieldButton').click(deleteFieldButton);
+ $('body').off('click', '.{$fid}_DeleteFieldButton', {$fid}_deleteFieldButton);
+ $('body').on('click', '.{$fid}_DeleteFieldButton', {$fid}_deleteFieldButton);
}
});
});
// Cancel
- $('#glmCustomFieldsNewFieldCancel').click( function() {
- $("#glmCustomFieldsNewFieldDialog").dialog("close");
+ $('#{$fid}_NewFieldCancel').click( function() {
+ $("#{$fid}_NewFieldDialog").dialog("close");
});
/*
dialogClass: "glm-dialog-no-close"
});
// Display form
- $('.glmCustomFieldsEditFieldButton').click(editFieldButton);
- function editFieldButton() {
- var fieldID = $(this).attr('data-fieldID');
- var fieldName = $(this).attr('data-fiedlName');
+ $('body').on('click', '.{$fid}_EditFieldButton', {$fid}_editFieldButton);
+ function {$fid}_editFieldButton() {
+ var fieldID = $(this).attr('data-fieldId');
+ var fieldName = $(this).attr('data-fieldName');
+ var fieldPrompt = $(this).attr('data-fieldPrompt');
var fieldType = $(this).attr('data-fieldType');
- var adminSearch = $(this).attr('data-adminSearch');
var required = $(this).attr('data-required');
$('#editFieldID').val(fieldID);
$('#editFieldName').val(fieldName.trim());
+ $('#editFieldPrompt').val(fieldPrompt.trim());
$('#editFieldType').val(fieldType);
- if (adminSearch === '1') {
- console.log('setting the checked to true');
- $('#editAdminSearch').prop('checked', true);
- } else {
- console.log('setting the checked to false');
- $('#editAdminSearch').prop('checked', false);
- }
// check required fields
if (required === '1') {
$('#editRequired').prop('checked', true);
* Delete field dialog box
*/
// Setup
- $("#glmCustomFieldsDeleteFieldDialog").dialog({
+ $("#{$fid}_DeleteFieldDialog").dialog({
autoOpen: false,
minWidth: 400,
dialogClass: "glm-dialog-no-close"
});
// Display form
- $('.glmCustomFieldsDeleteFieldButton').click(deleteFieldButton);
- function deleteFieldButton() {
- deleteId = $(this).attr('data-fieldID');
- $("#glmCustomFieldsDeleteFieldDialog").dialog("open");
+ $('body').on('click', '.{$fid}_DeleteFieldButton', {$fid}_deleteFieldButton);
+ function {$fid}_deleteFieldButton() {
+ $('#{$fid}_DeleteFieldConfirm').data('data-fieldId', $(this).attr('data-fieldId'));
+ $("#{$fid}_DeleteFieldDialog").dialog("open");
}
// Delete confirmed
- $('#glmCustomFieldsDeleteFieldConfirm').click( function() {
+ $('#{$fid}_DeleteFieldConfirm').click( function() {
- // Collect the new field data
+ var {$fid}_deleteId = $('#{$fid}_DeleteFieldConfirm').data('data-fieldId');
+
+ // Delete the selected form and remove it from the display
var formData = {
'action': 'glm_members_admin_ajax',
'glm_action': 'customFields',
'option': 'deleteField',
- 'id': deleteId
+ 'id': {$fid}_deleteId,
+ 'fid': '{$fid}'
};
-
- // Submit new field data - expect field new ID back
$.ajax({
type: 'POST',
url: '{$ajaxUrl}',
dataType: 'text'
})
.done( function(deleted) {
- $('#glmCustomFieldsFieldRow_' + deleteId).remove();
- $("#glmCustomFieldsDeleteFieldDialog").dialog("close");
- deleleteId = false;
+ $('#FieldRow_' + {$fid}_deleteId).remove();
+ $("#{$fid}_DeleteFieldDialog").dialog("close");
});
});
// Cancel
- $('#glmCustomFieldsDeleteFieldCancel').click( function() {
- $("#glmCustomFieldsDeleteFieldDialog").dialog("close");
+ $('#{$fid}_DeleteFieldCancel').click( function() {
+ $("#{$fid}_DeleteFieldDialog").dialog("close");
});
// Flash an element for a short time
--- /dev/null
+{if $haveForm}
+ {foreach $formFields as $field}
+ {if $field.field_type.name == 'text'}
+ <div class="glm-row">
+ <div class="glm-small-12 glm-large-12 glm-columns glm-nowrap{if $field.required.value} glm-required{/if}">{$field.field_prompt}</div>
+ <div class="glm-small-12 glm-large-12 glm-columns{if $field.field_fail} glm-fail{/if}">
+ <input id="glmCustomFormField_{$field.id}" type="text" name="glmCustomFormField_{$field.id}" value=""{if $field.required.value} required{/if}>
+ </div>
+ </div>
+ {/if}
+ {if $field.field_type.name == 'textarea'}
+ <div class="glm-row">
+ <div class="glm-small-12 glm-large-12 glm-columns glm-nowrap{if $field.required.value} glm-required{/if}">{$field.field_prompt}</div>
+ <div class="glm-small-12 glm-large-12 glm-columns{if $field.field_fail} glm-fail{/if}">
+ <textarea id="glmCustomFormField_{$field.id}" name="glmCustomFormField_{$field.id}" value="" rows="2" cols="50"{if $field.required.value} required{/if}></textarea>
+ </div>
+ </div>
+ {/if}
+ {if $field.field_type.name == 'checkbox'}
+ <div class="glm-row">
+ <div class="glm-small-12 glm-large-12 glm-columns glm-nowrap{if $field.required.value} glm-required{/if}">
+ <input id="glmCustomFormField_{$field.id}" type="checkbox" name="glmCustomFormField_{$field.id}"> {$field.field_prompt}
+ </div>
+ </div>
+ {/if}
+ {/foreach}
+{/if}
+
+{if $parentFormId}
+ <script type="text/javascript">
+ jQuery(function($){
+
+ // When the form is submitted
+ $('#{$parentFormId}').submit(function(e){
+
+ // If there's any required fields that aren't filled in
+ if (
+ {assign var="testSep" value=''}
+ {foreach $formFields as $field}
+ {if $field.required.value && ( $field.field_type.name == 'text' || $field.field_type.name == 'text' ) }
+ {$testSep} $('#glmCustomFormField_{$field.id}').val() == ''
+ {$testSep='||'}
+ {/if}
+ {/foreach}
+ ) {
+
+ // Block checkout
+ e.preventDefault();
+ alert('Please check all required input');
+ }
+
+ });
+ });
+ </script>
+{/if}
+
\ No newline at end of file
--- /dev/null
+<h5>Specifications</h5>
+{foreach $field_values as $key=>$value}
+ {if $value.slash === true }
+ <div class="glm-row field-container slash-price">
+ <div class="glm-small-6 glm-medium-12 glm-large-6 glm-columns field-name detail-{$key}-key">{$value.nice}</div>
+ <div class="glm-small-6 glm-medium-12 glm-large-6 glm-columns field-value detail-{$key}-value">{$value.data}</div>
+ </div>
+ {elseif $value.data !== 'Yes' && $value.data !== 'No'}
+ <div class="glm-row field-container">
+ <div class="glm-small-6 glm-medium-12 glm-large-6 glm-columns field-name detail-{$key}-key">{$value.nice}</div>
+ <div class="glm-small-6 glm-medium-12 glm-large-6 glm-columns field-value detail-{$key}-value">{$value.data}</div>
+ </div>
+ {/if}
+{/foreach}
+{$stock = $field_values.stock.data}
+{$msrp = $field_values.msrp.data}
+{$sale = $field_values['sale-price'].data}
+{$prod = $member_name}
+ <a class="contact-sales" href="{apply_filters('get_form_permalink', 286)}?prod={$prod}&stock={$stock}&msrp={$msrp}&sale={$sale}">Contact Sales</a>
\ No newline at end of file
--- /dev/null
+{foreach $field_values as $key=>$value}
+ {if $value.slash === true}
+ <div class="glm-row field-container slash-price {if $key === 'red-hot-deal' && $value.data === 'Yes'} red-hot {/if}">
+ {else}
+ <div class="glm-row field-container {if $key === 'red-hot-deal' && $value.data === 'Yes'} red-hot {/if}">
+ {/if}
+ {if $value.type == 'Home'}
+ <div class="glm-small-3 glm-large-4 glm-columns list-field-name home {$key}-key">{$value.nice}</div>
+ <div class="glm-small-9 glm-large-8 glm-columns list-field-value home {$key}-value">{$value.data}</div>
+ {else}
+ <div class="glm-small-3 glm-large-4 glm-columns list-field-name {$key}-key">{$value.nice}</div>
+ <div class="glm-small-9 glm-large-8 glm-columns list-field-value {$key}-value">{$value.data}</div>
+ {/if}
+ {if $key === 'red-hot-deal' && $value.data === 'Yes'}
+ <div class="glm-small-12 glm-columns field-value {$key}-logo-container">
+ <img src="{$assets_dir}/redhotdeals.gif">
+ </div>
+ {/if}
+ </div>
+{/foreach}
+++ /dev/null
-<h5>Specifications</h5>
-{foreach $field_values as $key=>$value}
- {if $value.slash === true }
- <div class="glm-row field-container slash-price">
- <div class="glm-small-6 glm-medium-12 glm-large-6 glm-columns field-name detail-{$key}-key">{$value.nice}</div>
- <div class="glm-small-6 glm-medium-12 glm-large-6 glm-columns field-value detail-{$key}-value">{$value.data}</div>
- </div>
- {elseif $value.data !== 'Yes' && $value.data !== 'No'}
- <div class="glm-row field-container">
- <div class="glm-small-6 glm-medium-12 glm-large-6 glm-columns field-name detail-{$key}-key">{$value.nice}</div>
- <div class="glm-small-6 glm-medium-12 glm-large-6 glm-columns field-value detail-{$key}-value">{$value.data}</div>
- </div>
- {/if}
-{/foreach}
-{$stock = $field_values.stock.data}
-{$msrp = $field_values.msrp.data}
-{$sale = $field_values['sale-price'].data}
-{$prod = $member_name}
- <a class="contact-sales" href="{apply_filters('get_form_permalink', 286)}?prod={$prod}&stock={$stock}&msrp={$msrp}&sale={$sale}">Contact Sales</a>
\ No newline at end of file
+++ /dev/null
-{foreach $field_values as $key=>$value}
- {if $value.slash === true}
- <div class="glm-row field-container slash-price {if $key === 'red-hot-deal' && $value.data === 'Yes'} red-hot {/if}">
- {else}
- <div class="glm-row field-container {if $key === 'red-hot-deal' && $value.data === 'Yes'} red-hot {/if}">
- {/if}
- {if $value.type == 'Home'}
- <div class="glm-small-3 glm-large-4 glm-columns list-field-name home {$key}-key">{$value.nice}</div>
- <div class="glm-small-9 glm-large-8 glm-columns list-field-value home {$key}-value">{$value.data}</div>
- {else}
- <div class="glm-small-3 glm-large-4 glm-columns list-field-name {$key}-key">{$value.nice}</div>
- <div class="glm-small-9 glm-large-8 glm-columns list-field-value {$key}-value">{$value.data}</div>
- {/if}
- {if $key === 'red-hot-deal' && $value.data === 'Yes'}
- <div class="glm-small-12 glm-columns field-value {$key}-logo-container">
- <img src="{$assets_dir}/redhotdeals.gif">
- </div>
- {/if}
- </div>
-{/foreach}