Have glm-members-customfields-edit admin filter working except for edit.
Marked much of the code as OLD to make sure we delete anything that's not used when it's all working.
'required' => array(
'field' => 'required',
'type' => 'checkbox',
- 'default' => false,
'use' => 'a'
),
// admin_search flag
'admin_search' => array (
'field' => 'admin_search',
'type' => 'checkbox',
- 'default' => false,
'use' => 'a'
),
--- /dev/null
+<?php
+/**
+ * Gaslight Media Members Database
+ * GLM Members DB - Fields Add-on - Management Fields Tab
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release fields.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link http://dev.gaslightmedia.com/
+ */
+
+// Load Management Fields data abstract
+require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH.'/data/dataCustomFields.php';
+
+/**
+ * GlmMembersAdmin_management_fields
+ *
+ * PHP version 5
+ *
+ * @category Model
+ * @package GLM Member DB
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott
+ * Exp $
+ */
+class GlmMembersAdmin_entity_fields extends GlmDataFieldsCustomFields
+{
+
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+ /**
+ * dbh Postgres database connection
+ *
+ * @var mixed
+ * @access public
+ */
+ public $dbh;
+ /**
+ * settings used for the schema and tablenames
+ *
+ * @var mixed
+ * @access public
+ */
+ public $settings = array();
+ /**
+ * categories
+ *
+ * @var bool
+ * @access public
+ */
+ public $categories = array();
+ public $oldCatMap = array();
+ /**
+ * fields
+ *
+ * @var bool
+ * @access public
+ */
+ public $fields = array();
+ public $image_owner;
+
+ /**
+ * 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 members data class
+ parent::__construct(false, false);
+
+ }
+
+ /**
+ * modelAction
+ *
+ * @param bool $actionData
+ * @access public
+ * @return void
+ */
+ public function modelAction($actionData = false)
+ {
+ $option = false;
+ $customFields = false;
+ $haveCustomFields = false;
+ $customFieldData = false;
+ $where = 'true';
+ $uid = '';
+
+ if (isset($_REQUEST['option'])) {
+ $option = $_REQUEST['option'];
+ }
+
+ // Check if a field ID is supplied
+ $id = 0;
+ if (isset($_REQUEST['id'])) {
+ $id = $_REQUEST['id']-0;
+ }
+ $entityID = 0;
+ if (isset($actionData)) {
+ $entityID = $actionData['entityID'];
+ $uid = $actionData['uid'];
+ $fieldFail = $actionData['cfData'];
+// print_r($fieldFail);
+ }
+
+ switch ($option) {
+
+ default:
+ // Make sure option is set if default
+ $option = 'list';
+
+ break;
+
+ }
+ // $where .= " AND field_id in (select id from " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX ."custom_fields where uid = 'glm-member-db')";
+ $where .= " AND uid = '$uid'";
+ // Get list of Custom Fields
+ $customFields = $this->getList( $where, 'field_order,id' );
+ if ( isset($customFields) && $customFields && count( $customFields ) > 0 ) {
+ $haveCustomFields = true;
+ }
+
+ require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH . '/customFieldPluginSupport.php';
+ // is array ensures that the data passed BAD
+ if(is_array($fieldFail)){
+ $customFieldsData = $fieldFail;
+ }else {
+ $customFieldsData = customFieldsGetFieldData( $entityID );
+ }
+
+
+ // Compile template data
+ $template_data = array(
+ 'prefix' => 'glm_custom_field',
+ 'customFields' => $customFields,
+ 'customFieldsData' => $customFieldsData,
+ 'fieldFail' => $fieldFail,
+ 'fieldTypes' => $this->config['custom_field_types'],
+ 'haveCustomFields' => $haveCustomFields,
+ 'uid' => $uid
+ );
+
+ // Return status, suggested view, and data to controller
+ return array(
+ 'status' => true,
+ 'menuItemRedirect' => false,
+ 'modelRedirect' => false,
+ 'view' => 'admin/entity/fields.html',
+ 'data' => $template_data
+ );
+
+
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * Gaslight Media Members Database
+ * GLM Members DB - Fields Add-on - Management Fields Tab
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release fields.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link http://dev.gaslightmedia.com/
+ */
+
+// Load Management Fields data abstract
+require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH.'/data/dataCustomFields.php';
+
+/**
+ * GlmMembersAdmin_management_fields
+ *
+ * PHP version 5
+ *
+ * @category Model
+ * @package GLM Member DB
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott
+ * Exp $
+ */
+class GlmMembersAdmin_management_fields extends GlmDataFieldsCustomFields
+{
+
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+ /**
+ * dbh Postgres database connection
+ *
+ * @var mixed
+ * @access public
+ */
+ public $dbh;
+ /**
+ * settings used for the schema and tablenames
+ *
+ * @var mixed
+ * @access public
+ */
+ public $settings = array();
+ /**
+ * categories
+ *
+ * @var bool
+ * @access public
+ */
+ public $categories = array();
+ public $oldCatMap = array();
+ /**
+ * fields
+ *
+ * @var bool
+ * @access public
+ */
+ public $fields = array();
+ public $image_owner;
+
+ /**
+ * 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 members data class
+ parent::__construct(false, false);
+
+ }
+
+ /**
+ * modelAction
+ *
+ * @param bool $actionData
+ * @access public
+ * @return void
+ */
+ public function modelAction($actionData = false)
+ {
+ $glm_action = '';
+ $option = false;
+ $settings_updated = false;
+ $settings_update_error = false;
+ $custom_fields = false;
+ $haveCustomFields = false;
+ $where = ' TRUE ';
+
+ if (isset($_REQUEST['option2'])) {
+ $option = $_REQUEST['option2'];
+ }
+
+ if (isset($_GET['glm_action'])) {
+ $glm_action = $_GET['glm_action'];
+ }
+
+ // Check if a field ID is supplied
+ $id = 0;
+ if (isset($_REQUEST['id'])) {
+ $id = $_REQUEST['id']-0;
+ }
+
+ $uid = 0;
+
+ if (isset($actionData['uid'])) {
+ $uid = $actionData['uid'];
+ }
+
+ switch ($option) {
+
+ case 'addNew':
+ $this->insertEntry();
+ break;
+
+ case 'update':
+ if ($id > 0) {
+ $this->updateEntry($id);
+ }
+ break;
+
+ case 'delete':
+ if ($id > 0) {
+ $this->deleteEntry($id, true);
+
+ // Also delete any data entries
+ $this->wpdb->delete(
+ GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . 'custom_field_data',
+ array( 'field_id' => $id )
+ );
+ }
+ break;
+
+ default:
+ // Make sure option is set if default
+ $option = 'list';
+
+ // Determine if current user can edit configurations
+ if (!current_user_can('glm_members_management')) {
+ return array(
+ 'status' => false,
+ 'menuItemRedirect' => 'error',
+ 'modelRedirect' => 'index',
+ 'view' => 'admin/error/index.html',
+ 'data' => array(
+ 'reason' => 'User does not have rights to make configuration changes.'
+ )
+ );
+ }
+
+ break;
+
+ }
+
+ $where .= " AND uid = '$uid' ";
+
+ // Get list of Custom Fields
+ $custom_fields = $this->getList( $where );
+ // echo "<pre>REQUEST " . print_r($_REQUEST, true) . "</pre>";
+ // echo "<pre>GET " . print_r($_GET, true) . "</pre>";
+ if ( isset($custom_fields) && $custom_fields && count( $custom_fields ) > 0 ) {
+ $haveCustomFields = true;
+ }
+
+ // Compile template data
+ $template_data = array(
+ 'option2' => $option,
+ 'settingsUpdated' => $settings_updated,
+ 'settingsUpdateError' => $settings_update_error,
+ 'custom_fields' => $custom_fields,
+ 'field_types' => $this->config['custom_field_types'],
+ 'haveCustomFields' => $haveCustomFields,
+ 'uid' => $uid,
+ 'glm_action' => $glm_action
+ );
+ // echo "<pre>Template data:" . print_r($template_data, true) . "</pre>";
+
+ // Return status, suggested view, and data to controller
+ return array(
+ 'status' => true,
+ 'menuItemRedirect' => false,
+ 'modelRedirect' => false,
+ 'view' => 'admin/management/fields.html',
+ 'data' => $template_data
+ );
+
+
+ }
+
+}
--- /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
+ * Custom Fields Form Management
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version 0.1
+ */
+
+// Load Management Fields data abstract
+require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH.'/data/dataCustomFields.php';
+
+
+/*
+ * This class performs the work of handling images passed to it via
+ * an AJAX call that goes through the WorPress AJAX Handler.
+ *
+ */
+class GlmMembersAdmin_ajax_customFields 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 data class
+ parent::__construct(false, false);
+
+ }
+ /**
+ * getModelEventsData
+ *
+ * Return the array of events.
+ *
+ * @param integer $categoryId Id of the category for filtering events (optional)
+ * @param integer $limit Number of events to return (optional)
+ * @param integer $memberID Member ID if filtering by member
+ *
+ * @access public
+ * @return array events
+ */
+
+
+ /*
+ * Perform Model Action
+ *
+ * This modelAction takes an AJAX image upload and stores the image in the
+ * media/images directory of the plugin.
+ *
+ * This model action does not return, it simply does it's work then calls die();
+ *
+ * @param $actionData
+ *
+ * @return No return is expected from this model. Content should be output then wp_die();
+ */
+ public function modelAction ($actionData = false)
+ {
+
+ trigger_error(print_r($_REQUEST,1),E_USER_NOTICE);
+
+ switch($_REQUEST['option']) {
+
+ case 'addNewField':
+
+ $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;
+ }
+
+ wp_die();
+ break;
+
+ case 'deleteField':
+
+ $fieldId = false;
+
+ if (isset($_REQUEST['id'])) {
+ $fieldId = $_REQUEST['id'] - 0;
+ if ($fieldId <= 0) {
+ echo false;
+ wp_die();
+ }
+ }
+
+ // Delete this custom field
+ $this->deleteEntry($fieldId, true);
+ echo true;
+ wp_die();
+
+ break;
+
+ default:
+
+ wp_die();
+ }
+
+ wp_die();
+ }
+
+
+ /**
+ * Merge template and data to produce HTML
+ *
+ * Checks the theme's view directories and the view directories for
+ * this plugin for a matching view file.
+ *
+ * Note that $viewFile needs to have the proper view directory path
+ * includes. (i.e. "/views/front/registrations/summary.html")
+ *
+ * @param $data array Array of data to merge with the template
+ * @param $view string Path added to
+ *
+ * @access public
+ * @return void
+ */
+ function generateHTML($data, $viewFile)
+ {
+
+ // If a view file is specified
+ if ($viewFile) {
+
+ // Get the specified view file - check theme first
+ $viewPath = GLM_MEMBERS_PLUGIN_CURRENT_THEME_DIR."/views";
+ $viewPath2 = GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_PATH . "views"; // Save default
+
+ // If the view is not found in the theme, fall back to views in the plugin
+ if (!is_file($viewPath.'/'.$viewFile)) {
+
+ // Next try the plugin/add-on
+ $viewPath = GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_PATH . "/views";
+
+ if (!is_file($viewPath.'/'.$viewFile)) {
+
+ if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) {
+ trigger_error("Bad or missing view file when generating checkout HTML: $viewPath/$viewFile", E_USER_NOTICE);
+ }
+
+ }
+
+ }
+
+ }
+
+ // Load Smarty Template support
+ $smarty = new smartyTemplateSupport();
+
+ // Add standard parameters
+ require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php';
+
+ // Add data from model to Smarty template
+ if (is_array($data) && count($data) > 0) {
+ foreach ($data as $k => $d) {
+ $smarty->templateAssign($k, $d);
+ }
+ }
+
+ // Update the Smarty view path
+ $smarty->template->setTemplateDir($viewPath);
+
+ // If the view path doesn't match the default, add the default (using theme view)
+ if ($viewPath2 != $viewPath) {
+ $smarty->template->addTemplateDir($viewPath2);
+ }
+
+ // Generate output from model data and view
+ $out = $smarty->template->fetch($viewFile);
+
+ return $out;
+
+ }
+
+
+
+}
+++ /dev/null
-<?php
-
-/**
- * Gaslight Media Members Database
- * Get events for a monty for AJAX call
- *
- * PHP version 5.5
- *
- * @category glmWordPressPlugin
- * @package glmMembersDatabase
- * @author Chuck Scott <cscott@gaslightmedia.com>
- * @license http://www.gaslightmedia.com Gaslightmedia
- * @version 0.1
- */
-
-// Load Event Times data abstract
-require_once GLM_MEMBERS_PLUGIN_CLASS_PATH .'/data/dataCategories.php';
-
-
-/*
- * This class performs the work of handling images passed to it via
- * an AJAX call that goes through the WorPress AJAX Handler.
- *
- */
-class GlmMembersAdmin_ajax_filterSearch extends GlmDataCategories
-{
-
- /**
- * 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);
-
- }
- /**
- * getModelEventsData
- *
- * Return the array of events.
- *
- * @param integer $categoryId Id of the category for filtering events (optional)
- * @param integer $limit Number of events to return (optional)
- * @param integer $memberID Member ID if filtering by member
- *
- * @access public
- * @return array events
- */
-
-
- /*
- * Perform Model Action
- *
- * This modelAction takes an AJAX image upload and stores the image in the
- * media/images directory of the plugin.
- *
- * This model action does not return, it simply does it's work then calls die();
- *
- * @param $actionData
- *
- * Echos JSON string as response and does not return
- */
- public function modelAction ($actionData = false)
- {
-
- global $wpdb;
-//
-// $category_ids = $_REQUEST['cat_ids'];
-// $category_names = $_REQUEST['cat_names'];
-//
-// // get cat ids by name
-// foreach($category_names as $cat_name){
-// $sql = 'SELECT id FROM ' . GLM_MEMBERS_PLUGIN_DB_PREFIX . "categories WHERE name = '$cat_name';";
-// $cat_id = $wpdb->get_var($sql);
-//
-// // get the
-// }
-//
-//
-// $categories = $this->getListSortedParentChild();
-// $categories = $categories[$category_id];
- $return = array(
-// 'manufacturers' => $category_ids,
-// 'brands' => $cat_id
- );
-
- header('Content-type:application/json;charset=utf-8', true);
- echo json_encode($return);
- wp_die();
- }
-}
--- /dev/null
+<?php
+/**
+ * Gaslight Media Members Database
+ * GLM Members DB - Fields Add-on - Management Fields Tab
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release fields.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link http://dev.gaslightmedia.com/
+ */
+
+// Load Management Fields data abstract
+require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH.'/data/dataCustomFields.php';
+
+/**
+ * GlmMembersAdmin_management_fields
+ *
+ * PHP version 5
+ *
+ * @category Model
+ * @package GLM Member DB
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott
+ * Exp $
+ */
+class GlmMembersAdmin_customFields_index extends GlmDataFieldsCustomFields
+{
+
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+ /**
+ * dbh Postgres database connection
+ *
+ * @var mixed
+ * @access public
+ */
+ public $dbh;
+ /**
+ * settings used for the schema and tablenames
+ *
+ * @var mixed
+ * @access public
+ */
+ public $settings = array();
+ /**
+ * categories
+ *
+ * @var bool
+ * @access public
+ */
+ public $categories = array();
+ public $oldCatMap = array();
+ /**
+ * fields
+ *
+ * @var bool
+ * @access public
+ */
+ public $fields = array();
+ public $image_owner;
+
+ /**
+ * 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 members data class
+ parent::__construct(false, false);
+
+ }
+
+ /**
+ * modelAction
+ *
+ * @param bool $actionData
+ * @access public
+ * @return void
+ */
+ public function modelAction($actionData = false)
+ {
+ $viewFile = 'index.html';
+ $glm_action = '';
+ $option = false;
+ $settings_updated = false;
+ $settings_update_error = false;
+ $custom_fields = false;
+ $haveCustomFields = false;
+ $where = ' TRUE ';
+
+ if (isset($_REQUEST['option2'])) {
+ $option = $_REQUEST['option2'];
+ }
+
+ if (isset($_GET['glm_action'])) {
+ $glm_action = $_GET['glm_action'];
+ }
+
+ // Check if a field ID is supplied
+ $id = 0;
+ if (isset($_REQUEST['id'])) {
+ $id = $_REQUEST['id']-0;
+ }
+
+ $uid = 0;
+
+ if (isset($actionData['uid'])) {
+ $uid = $actionData['uid'];
+ }
+
+ switch ($option) {
+
+ case 'addNew':
+ $this->insertEntry();
+ break;
+
+ case 'update':
+ if ($id > 0) {
+ $this->updateEntry($id);
+ }
+ break;
+
+ case 'delete':
+ if ($id > 0) {
+ $this->deleteEntry($id, true);
+
+ // Also delete any data entries
+ $this->wpdb->delete(
+ GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . 'custom_field_data',
+ array( 'field_id' => $id )
+ );
+ }
+ break;
+
+ default:
+
+ // Make sure option is set if default
+ $option = 'list';
+
+ break;
+
+ }
+
+ $where .= " AND uid = '$uid' ";
+
+ // Get list of Custom Fields
+ $custom_fields = $this->getList( $where );
+
+ if ( isset($custom_fields) && $custom_fields && count( $custom_fields ) > 0 ) {
+ $haveCustomFields = true;
+ }
+
+ // Compile template data
+ $template_data = array(
+ 'option2' => $option,
+ 'settingsUpdated' => $settings_updated,
+ 'settingsUpdateError' => $settings_update_error,
+ 'custom_fields' => $custom_fields,
+ 'field_types' => $this->config['custom_field_types'],
+ 'haveCustomFields' => $haveCustomFields,
+ 'uid' => $uid,
+ 'glm_action' => $glm_action
+ );
+
+ // echo "<pre>Template data:" . print_r($template_data, true) . "</pre>";
+
+ // Return status, suggested view, and data to controller
+ return array(
+ 'status' => true,
+ 'menuItemRedirect' => false,
+ 'modelRedirect' => false,
+ 'view' => 'admin/customFields/'.$viewFile,
+ 'data' => $template_data
+ );
+
+
+ }
+
+}
+++ /dev/null
-<?php
-/**
- * Gaslight Media Members Database
- * GLM Members DB - Fields Add-on - Management Fields Tab
- *
- * PHP version 5.5
- *
- * @category glmWordPressPlugin
- * @package glmMembersDatabase
- * @author Chuck Scott <cscott@gaslightmedia.com>
- * @license http://www.gaslightmedia.com Gaslightmedia
- * @release fields.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
- * @link http://dev.gaslightmedia.com/
- */
-
-// Load Management Fields data abstract
-require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH.'/data/dataCustomFields.php';
-
-/**
- * GlmMembersAdmin_management_fields
- *
- * PHP version 5
- *
- * @category Model
- * @package GLM Member DB
- * @author Chuck Scott <cscott@gaslightmedia.com>
- * @license http://www.gaslightmedia.com Gaslightmedia
- * @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott
- * Exp $
- */
-class GlmMembersAdmin_entity_fields extends GlmDataFieldsCustomFields
-{
-
- /**
- * WordPress Database Object
- *
- * @var $wpdb
- * @access public
- */
- public $wpdb;
- /**
- * dbh Postgres database connection
- *
- * @var mixed
- * @access public
- */
- public $dbh;
- /**
- * settings used for the schema and tablenames
- *
- * @var mixed
- * @access public
- */
- public $settings = array();
- /**
- * categories
- *
- * @var bool
- * @access public
- */
- public $categories = array();
- public $oldCatMap = array();
- /**
- * fields
- *
- * @var bool
- * @access public
- */
- public $fields = array();
- public $image_owner;
-
- /**
- * 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 members data class
- parent::__construct(false, false);
-
- }
-
- /**
- * modelAction
- *
- * @param bool $actionData
- * @access public
- * @return void
- */
- public function modelAction($actionData = false)
- {
- $option = false;
- $customFields = false;
- $haveCustomFields = false;
- $customFieldData = false;
- $where = 'true';
- $uid = '';
-
- if (isset($_REQUEST['option'])) {
- $option = $_REQUEST['option'];
- }
-
- // Check if a field ID is supplied
- $id = 0;
- if (isset($_REQUEST['id'])) {
- $id = $_REQUEST['id']-0;
- }
- $entityID = 0;
- if (isset($actionData)) {
- $entityID = $actionData['entityID'];
- $uid = $actionData['uid'];
- $fieldFail = $actionData['cfData'];
-// print_r($fieldFail);
- }
-
- switch ($option) {
-
- default:
- // Make sure option is set if default
- $option = 'list';
-
- break;
-
- }
- // $where .= " AND field_id in (select id from " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX ."custom_fields where uid = 'glm-member-db')";
- $where .= " AND uid = '$uid'";
- // Get list of Custom Fields
- $customFields = $this->getList( $where, 'field_order,id' );
- if ( isset($customFields) && $customFields && count( $customFields ) > 0 ) {
- $haveCustomFields = true;
- }
-
- require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH . '/customFieldPluginSupport.php';
- // is array ensures that the data passed BAD
- if(is_array($fieldFail)){
- $customFieldsData = $fieldFail;
- }else {
- $customFieldsData = customFieldsGetFieldData( $entityID );
- }
-
-
- // Compile template data
- $template_data = array(
- 'prefix' => 'glm_custom_field',
- 'customFields' => $customFields,
- 'customFieldsData' => $customFieldsData,
- 'fieldFail' => $fieldFail,
- 'fieldTypes' => $this->config['custom_field_types'],
- 'haveCustomFields' => $haveCustomFields,
- 'uid' => $uid
- );
-
- // Return status, suggested view, and data to controller
- return array(
- 'status' => true,
- 'menuItemRedirect' => false,
- 'modelRedirect' => false,
- 'view' => 'admin/entity/fields.html',
- 'data' => $template_data
- );
-
-
- }
-
-}
+++ /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
- * GLM Members DB - Fields Add-on - Management Fields Tab
- *
- * PHP version 5.5
- *
- * @category glmWordPressPlugin
- * @package glmMembersDatabase
- * @author Chuck Scott <cscott@gaslightmedia.com>
- * @license http://www.gaslightmedia.com Gaslightmedia
- * @release fields.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
- * @link http://dev.gaslightmedia.com/
- */
-
-// Load Management Fields data abstract
-require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH.'/data/dataCustomFields.php';
-
-/**
- * GlmMembersAdmin_management_fields
- *
- * PHP version 5
- *
- * @category Model
- * @package GLM Member DB
- * @author Chuck Scott <cscott@gaslightmedia.com>
- * @license http://www.gaslightmedia.com Gaslightmedia
- * @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott
- * Exp $
- */
-class GlmMembersAdmin_management_fields extends GlmDataFieldsCustomFields
-{
-
- /**
- * WordPress Database Object
- *
- * @var $wpdb
- * @access public
- */
- public $wpdb;
- /**
- * dbh Postgres database connection
- *
- * @var mixed
- * @access public
- */
- public $dbh;
- /**
- * settings used for the schema and tablenames
- *
- * @var mixed
- * @access public
- */
- public $settings = array();
- /**
- * categories
- *
- * @var bool
- * @access public
- */
- public $categories = array();
- public $oldCatMap = array();
- /**
- * fields
- *
- * @var bool
- * @access public
- */
- public $fields = array();
- public $image_owner;
-
- /**
- * 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 members data class
- parent::__construct(false, false);
-
- }
-
- /**
- * modelAction
- *
- * @param bool $actionData
- * @access public
- * @return void
- */
- public function modelAction($actionData = false)
- {
- $glm_action = '';
- $option = false;
- $settings_updated = false;
- $settings_update_error = false;
- $custom_fields = false;
- $haveCustomFields = false;
- $where = ' TRUE ';
-
- if (isset($_REQUEST['option2'])) {
- $option = $_REQUEST['option2'];
- }
-
- if (isset($_GET['glm_action'])) {
- $glm_action = $_GET['glm_action'];
- }
-
- // Check if a field ID is supplied
- $id = 0;
- if (isset($_REQUEST['id'])) {
- $id = $_REQUEST['id']-0;
- }
-
- $uid = 0;
-
- if (isset($actionData['uid'])) {
- $uid = $actionData['uid'];
- }
-
- switch ($option) {
-
- case 'addNew':
- $this->insertEntry();
- break;
-
- case 'update':
- if ($id > 0) {
- $this->updateEntry($id);
- }
- break;
-
- case 'delete':
- if ($id > 0) {
- $this->deleteEntry($id, true);
-
- // Also delete any data entries
- $this->wpdb->delete(
- GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . 'custom_field_data',
- array( 'field_id' => $id )
- );
- }
- break;
-
- default:
- // Make sure option is set if default
- $option = 'list';
-
- // Determine if current user can edit configurations
- if (!current_user_can('glm_members_management')) {
- return array(
- 'status' => false,
- 'menuItemRedirect' => 'error',
- 'modelRedirect' => 'index',
- 'view' => 'admin/error/index.html',
- 'data' => array(
- 'reason' => 'User does not have rights to make configuration changes.'
- )
- );
- }
-
- break;
-
- }
-
- $where .= " AND uid = '$uid' ";
-
- // Get list of Custom Fields
- $custom_fields = $this->getList( $where );
- // echo "<pre>REQUEST " . print_r($_REQUEST, true) . "</pre>";
- // echo "<pre>GET " . print_r($_GET, true) . "</pre>";
- if ( isset($custom_fields) && $custom_fields && count( $custom_fields ) > 0 ) {
- $haveCustomFields = true;
- }
-
- // Compile template data
- $template_data = array(
- 'option2' => $option,
- 'settingsUpdated' => $settings_updated,
- 'settingsUpdateError' => $settings_update_error,
- 'custom_fields' => $custom_fields,
- 'field_types' => $this->config['custom_field_types'],
- 'haveCustomFields' => $haveCustomFields,
- 'uid' => $uid,
- 'glm_action' => $glm_action
- );
- // echo "<pre>Template data:" . print_r($template_data, true) . "</pre>";
-
- // Return status, suggested view, and data to controller
- return array(
- 'status' => true,
- 'menuItemRedirect' => false,
- 'modelRedirect' => false,
- 'view' => 'admin/management/fields.html',
- 'data' => $template_data
- );
-
-
- }
-
-}
);
/**
- * Filter will return true if the plugin is active.
- */
-add_filter( 'glm-members-customfields-active', function( $active ){
- return true;
-}, 10, 1 );
-
-/**
- * Filter returns html from the management -> fields model.
+ * Filter to edit custom fields for a specific UID
+ *
+ * Requires UID - a unique string that identifies this group of field.
+ * Recommended to use "{plugin-slug}-customfields-edit-{use}-{id}"
+ * {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 ){
unset( $_REQUEST['glm_action'] );
- $content .= $this->controller( 'management', 'fields', array( 'uid' => $uid ), true );
+ $content .= $this->controller( 'customFields', 'index', array( 'uid' => $uid ), true );
return $content;
}, 10, 2 );
+
+
+
+
+
+
+
/**
* Filter returns the html for the form segment
*/
*/
/*
- * Place Misc Hooks and Filters that should be available to both admin and front processes here.
+ * Place Misc Hooks and Filters that should be available to both admin and front processes here.
* If this file exists, it will be included by the main plugin script.
*
* Note that filter and hook callback functions must be included in-line as shown below...
* Also note that parameters will be in the context of the main admin controller constructor.
*/
+/**
+ * Filter will return true if the plugin is active.
+ */
+add_filter( 'glm-members-customfields-active', function( $active ){
+ return true;
+}, 10, 1 );
+
$glmMembersCustomFieldsAddOnValidActions = array(
'adminActions' => array(
'ajax' => array(
- 'filterSearch' => GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_SLUG,
- ),
- 'entity' => array(
- 'fields' => GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_SLUG,
- ),
- 'management' => array(
- 'fields' => GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_SLUG,
- ),
- 'import' => array(
- 'fields' => GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_SLUG,
+ 'customFields' => GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_SLUG
),
+ 'customFields' => array(
+ 'index' => GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_SLUG
+ )
),
'frontActions' => array(
'fields' => array(
- 'list' => GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_SLUG,
- 'detail' => GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_SLUG,
+// 'list' => GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_SLUG,
+// 'detail' => GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_SLUG,
),
)
);
--- /dev/null
+<div id="glm-members-custom-fields-{$uid}" class="glm-row glm-custom-field-group glm-admin-custom-fields">
+ {foreach $customFields as $field}
+ <div class="glm-small-12 glm-large-2 glm-columns glm-custom-field-label {if $field.required.value == 1} glm-required {/if}">{$field.field_name}</div>
+ <div class="glm-small-12 glm-large-9 glm-columns glm-custom-field">
+ <input type="hidden" name="custom-required" value="{$field.required.value}">
+
+ {$fail = ''}
+ {if is_array($customFieldsData)}
+ {if array_key_exists('fieldFail', $customFieldsData)}
+ {if array_key_exists($field.id,$customFieldsData['fieldFail'])}
+ {$fail = 'glm-form-bad-input'}
+ {/if}
+ {/if}
+ {/if}
+ <div class="glm-input-wrapper {$fail}">
+ {if $field.field_type.name == 'text'}
+
+ <input class="glm-input glm-form-text-input-medium" type="text" name="{$prefix}[{$field.id}]" value="{if isset($customFieldsData[$field.id])}{$customFieldsData[$field.id]|escape}{/if}" {if $field.required.value == 1} required{/if}>
+ {elseif $field.field_type.name == 'textarea'}
+ {php}
+ wp_editor('{if isset($customFieldsData[$field.id])}{$customFieldsData[$field.id]|escape:quotes}{/if}', 'custom-field-{$field.id}', array(
+ 'media_buttons' => false,
+ // 'quicktags' => false,
+ // 'wpautop' => false, NOTE: Dont's use. Problem when numerous spaces before text.
+ 'textarea_name' => '{$prefix}[{$field.id}]',
+ 'editor_height' => 200, // Height in px, overrides editor_rows
+ // 'textarea_rows' => 8,
+ {if $field.required.value == 1}'editor_class' => 'glm-required' {/if}
+ ));
+ {/php}
+ {elseif $field.field_type.name == 'checkbox'}
+ <input type="hidden" name="{$prefix}[{$field.id}]" value="No" {if !isset($customFieldsData[$field.id]) || $customFieldsData[$field.id] == 'No'}checked{/if}>
+ <input type="checkbox" name="{$prefix}[{$field.id}]" value="Yes" {if isset($customFieldsData[$field.id]) && $customFieldsData[$field.id] == 'Yes'}checked{/if} {if $field.required.value == 1} required{/if}>
+ {/if}
+ </div>
+ </div>
+ {/foreach}
+</div>
--- /dev/null
+{include file='admin/import/header.html'}
+
+ <h2>Social Data Import Step 1: Upload file</h2>
+
+ <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+ <input type="hidden" name="glm_action" value="fields" />
+ <input type="hidden" name="option" value="fieldsValidate" />
+
+ <table class="glm-admin-table" border="0" cellspacing="5" cellpadding="10">
+ <tr>
+ <th>File Type</th>
+ <th>New File</th>
+ <th>Sample File</th>
+ <th>Current File</th>
+ <th>Updated</th>
+ </tr>
+ {$count = 0}
+ {foreach $fileData as $fileHeader => $file}
+ <tr{if $count%2 == 0} class="alternate"{/if}>
+ <td class="glm-import-td">
+ {$fileHeader}
+ </td>
+ <td class="glm-import-td">
+ <input type="file" name="{$file.field}">
+ </td>
+ <td class="glm-import-td">
+ <a href="{$sampleFileUrl}{$file.name}">Sample {$fileHeader} File</a>
+ </td>
+ <td class="glm-import-td">
+ {if $file.exists}
+ {$fileHeader} File
+ {/if}
+ </td>
+ <td class="glm-import-td">
+ {if $file.exists}
+ {$file.mtime|date_format:"%D %I:%M %p"}
+ {/if}
+ </td>
+ </tr>
+ {$count = $count + 1}
+ {/foreach}
+ </table>
+
+ <input type="submit" value="Continue" class="button button-primary submit-import">
+
+ </form>
+
+{include file='admin/footer.html'}
--- /dev/null
+{include file='admin/import/header.html'}
+
+ <h2>Data Import Step 3: Process Fields File</h2>
+ <table class="glm-admin-table">
+ <tr>
+ <th>Total Records</th>
+ <td>{$totalFields}</td>
+ </tr>
+ <tr>
+ <th>Processed Records</th>
+ <td>{$numberProcessed}</td>
+ </tr>
+
+ </table>
+
+{include file='admin/footer.html'}
--- /dev/null
+{include file='admin/import/header.html'}
+
+ <h2>Secial Import Step 2: Validate Fields file</h2>
+
+ <table class="glm-admin-table">
+ {foreach $fileData as $fileHeader => $file}
+ <tr>
+ <td>
+ {if $file.exists}
+ {$fileHeader} File
+ {/if}
+ </td>
+ <td>
+ {if $file.isValid}
+ Is Valid
+ {else}
+ Not Valid
+ {/if}
+ </td>
+ </tr>
+ {/foreach}
+
+ {if $readyToProcess}
+ <tr>
+ <td colspan="2">
+ <a href="{$thisUrl}?page={$thisPage}&glm_action=fields&option=fieldsProcess" class="button">Process Files</a>
+ </td>
+ </tr>
+ {else}
+ <tr>
+ <td colspan="2">
+ <p>One or more of your files are not the correct csv format. Please go back and try again.</p>
+ <a href="{$thisUrl}?page={$thisPage}&glm_action=fields" class="button">Go Back</a>
+ </td>
+ </tr>
+ {/if}
+
+ </table>
+
+{include file='admin/footer.html'}
--- /dev/null
+<!-- 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">
+ <tr>
+ <th class="glm-required">Field Name:</th>
+ <td>
+ <input id="glmCustomFieldsNewFieldName" type="text" name="field_name" class="glm-form-text-input">
+ </td>
+ </tr>
+ <tr>
+ <th class="glm-required">Field Type:</th>
+ <td>
+ <select id="glmCustomFieldsNewFieldType" name="field_type">
+ {foreach $field_types as $val => $label}
+ <option value="{$val}">{$label}</option>
+ {/foreach}
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <th>Required?</th>
+ <td>
+ <input id="glmCustomFieldsNewFieldRequired" type="checkbox" name="required" value="1">
+ </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>
+
+{* Delete field button confirmation dialog box *}
+<div id="deleteFieldDialog" class="glm-dialog-box" title="Delete Field">
+ <center>
+ <p>Are you sure you want to delete this field?</p>
+ <p><div id="deleteFieldConfirm" class="button button-primary">Yes, delete this field</div></p>
+ <p><div id="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">
+ <tr>
+ <th class="glm-required">Field Name:</th>
+ <td>
+ <input id="editFieldName" type="text" name="field_name" class="glm-form-text-input">
+ </td>
+ </tr>
+ <tr>
+ <th class="glm-required">Field Type:</th>
+ <td>
+ <select id="editFieldType" name="field_type">
+ {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>
+ </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>
+ <input type="submit" value="Update this Field">
+ </form>
+</div>
+
+{* Update and error messages *}
+<table class="glm-admin-table glm-settings-table{if $option2!='settings'} glm-hidden{/if}">
+ <tr>
+ <td colspan="2">
+ {if $settingsUpdated}<h2 class="glm-notice glm-flash-updated glm-right">Settings Updated</h2>{/if}
+ {if $settingsUpdateError}<span class="glm-error glm-flash-updated glm-right">Settings Update Error</span>{/if}
+ <h2>Custom Fields</h2>
+ </td>
+ </tr>
+</table>
+
+{* Fields Table *}
+<table class="glm-admin-table glm-settings-table">
+ <thead>
+ <tr>
+ <th>ID</th>
+ <th>Field</th>
+ <th>Type</th>
+ <th>UID/Entity</th>
+ <th>Required</th>
+ <!-- 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'}<th>Admin Searchable</th>{/if}
+ <th> </th>
+ </tr>
+ </thead>
+ <tbody>
+ {if $haveCustomFields}
+ {assign var="i" value="0"}
+ {foreach $custom_fields as $t}
+ {if $i++ is odd by 1}
+ <tr>
+ {else}
+ <tr class="alternate">
+ {/if}
+ <td>{$t.id}</td>
+ <td>
+ <div>
+ <a class="editField" data-fieldID="{$t.id}" data-fieldType="{$t.field_type.name|escape:'html'}" data-adminSearch="{$t.admin_search.value}" data-required="{$t.required.value}">{$t.field_name}</a>
+ </div>
+ </td>
+ <td id="editFieldType_{$t.id}">
+ {$t.field_type.name}
+ </td>
+ <td>
+ {$t.uid}
+ </td>
+ <td>
+ {$t.required.name}
+ </td>
+ <td>
+ {$t.admin_search.name}
+ </td>
+ <td>
+ <div class="deleteFieldButton button button-secondary glm-button-small glm-right" data-fieldID="{$t.id}">Delete</div>
+ </td>
+ </tr>
+ {/foreach}
+ {else}
+ <tr class="alternate"><td colspan="2">(no custom fields listed)</td></tr>
+ {/if}
+ </tbody>
+</table>
+<!-- Tests -->
+
+<script type="text/javascript">
+jQuery(document).ready(function($) {
+
+ var id = false;
+
+ /*
+ * New field dialog box
+ */
+ // Ssetup
+ $("#glmCustomFieldsNewFieldDialog").dialog({
+ autoOpen: false,
+ minWidth: 400,
+ dialogClass: "glm-dialog-no-close"
+ });
+ // Display form
+ $('#newFieldButton').click( function() {
+ $("#glmCustomFieldsNewFieldDialog").dialog("open");
+ });
+ // Submit form
+ $('#glmCustomFieldsNewFieldSubmit').click( function() {
+
+ // Collect the new field data
+ var formData = {
+ 'action': 'glm_members_admin_ajax',
+ 'glm_action': 'customfields',
+ 'option': 'addNewField',
+ 'field_name': $('#glmCustomFieldsNewFieldName').val(),
+ 'field_type': $('#glmCustomFieldsNewFieldType').val(),
+ 'required': $('#glmCustomFieldsNewFieldRequired').is(':checked')
+ };
+
+ // Submit new field data - expect field new ID back
+ $.ajax({
+ type: 'POST',
+ url: '{$ajaxUrl}',
+ data: formData,
+ encode: true,
+ dataType: 'text'
+ })
+ .done( function(data) {
+ alert(data);
+ });
+
+ });
+ // Cancel
+ $('#glmCustomFieldsNewFieldCancel').click( function() {
+ $("#glmCustomFieldsNewFieldDialog").dialog("close");
+ });
+
+ /*
+ * Edit field dialog box
+ */
+ // Setup
+ $("#editFieldDialog").dialog({
+ autoOpen: false,
+ minWidth: 400,
+ dialogClass: "glm-dialog-no-close"
+ });
+ // Display form
+ $('.editField').click( function() {
+ var fieldID = $(this).attr('data-fieldID');
+ var fieldName = $(this).text();
+ 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());
+ $('#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);
+ } else {
+ console.log('setting the checked to false');
+ $('#editRequired').prop('checked', false);
+ }
+ $("#editFieldDialog").dialog("open");
+ });
+ // Cancel
+ $('#editFieldCancel').click( function() {
+ $("#editFieldDialog").dialog("close");
+ });
+
+ /*
+ * Delete field dialog box
+ */
+ // Setup
+ $("#deleteFieldDialog").dialog({
+ autoOpen: false,
+ minWidth: 400,
+ dialogClass: "glm-dialog-no-close"
+ });
+ // Dispaly form
+ $('.deleteFieldButton').click( function() {
+ id = $(this).attr('data-fieldID');
+ $("#deleteFieldDialog").dialog("open");
+ });
+ // Delete confirmed
+ $('#deleteFieldConfirm').click( function() {
+ $("#deleteFieldDialog").dialog("close");
+ window.location.href = "{$thisUrl}?page={$thisPage}&glm_action={$glm_action}&option=customfields&option2=delete&id=" + id;
+ });
+ // Cancel
+ $('#deleteFieldCancel').click( function() {
+ $("#deleteFieldDialog").dialog("close");
+ });
+
+ // 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).fadeIn(500).fadeOut(500);
+});
+</script>
--- /dev/null
+{* A single line for the custom fields edit table *}
+ <tr id="glmCustomFieldsFieldRow_{$fieldData.id}">
+ <td><div>{$fieldData.field_name}</div></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="glmCustomFieldsDeleteFieldButton button button-secondary glm-button-small glm-right" data-fieldID="{$fieldData.id}">Delete</div>
+ </td>
+ </tr>
--- /dev/null
+<!-- 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">
+ <tr>
+ <th class="glm-required">Field Name:</th>
+ <td>
+ <input id="glmCustomFieldsNewFieldName" type="text" name="field_name" class="glm-form-text-input">
+ </td>
+ </tr>
+ <tr>
+ <th class="glm-required">Field Type:</th>
+ <td>
+ <select id="glmCustomFieldsNewFieldType" name="field_type">
+ {foreach $field_types as $val => $label}
+ <option value="{$val}">{$label}</option>
+ {/foreach}
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <th>Required?</th>
+ <td>
+ <input id="glmCustomFieldsNewFieldRequired" 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>
+
+{* Delete field button confirmation dialog box *}
+<div id="glmCustomFieldsDeleteFieldDialog" 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>
+ </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">
+ <tr>
+ <th class="glm-required">Field Name:</th>
+ <td>
+ <input id="editFieldName" type="text" name="field_name" class="glm-form-text-input">
+ </td>
+ </tr>
+ <tr>
+ <th class="glm-required">Field Type:</th>
+ <td>
+ <select id="editFieldType" name="field_type">
+ {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>
+ </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>
+ <input type="submit" value="Update this Field">
+ </form>
+</div>
+
+{* Update and error messages *}
+<table class="glm-admin-table glm-settings-table{if $option2!='settings'} glm-hidden{/if}">
+ <tr>
+ <td colspan="2">
+ {if $settingsUpdated}<h2 class="glm-notice glm-flash-updated glm-right">Settings Updated</h2>{/if}
+ {if $settingsUpdateError}<span class="glm-error glm-flash-updated glm-right">Settings Update Error</span>{/if}
+ <h2>Custom Fields</h2>
+ </td>
+ </tr>
+</table>
+
+{* Fields Table *}
+<table class="glm-admin-table glm-settings-table">
+ <thead>
+ <tr>
+ <th>Field Name</th>
+ <th>Type</th>
+ <th>Required</th>
+ <th> </th>
+ </tr>
+ </thead>
+ <tbody id="glmCustomFieldsListBody">
+{if $haveCustomFields}
+ {foreach $custom_fields as $t}
+ <tr id="glmCustomFieldsFieldRow_{$t.id}">
+ <td>
+ <div>
+ {$t.field_name}
+ </div>
+ </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>
+ -->
+ <div class="glmCustomFieldsDeleteFieldButton button button-secondary glm-button-small" data-fieldID="{$t.id}">Delete</div>
+ </td>
+ </tr>
+ {/foreach}
+ {else}
+ <tr id="noCustomFieldsNotice" class="alternate"><td colspan="2">(no custom fields listed)</td></tr>
+{/if}
+ </tbody>
+</table>
+<!-- Tests -->
+
+<script type="text/javascript">glmCustomFieldsNewFieldCancel
+jQuery(document).ready(function($) {
+
+ var deleteId = false;
+
+ /*
+ * New field dialog box
+ */
+ // Ssetup
+ $("#glmCustomFieldsNewFieldDialog").dialog({
+ autoOpen: false,
+ minWidth: 600,
+ dialogClass: "glm-dialog-no-close"
+ });
+ // Display form
+ $('#newFieldButton').click( function() {
+ $("#glmCustomFieldsNewFieldDialog").dialog("open");
+ });
+ // Submit form
+ $('#glmCustomFieldsNewFieldSubmit').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
+ };
+
+ // Submit new field data - expect field new ID back
+ $.ajax({
+ type: 'POST',
+ url: '{$ajaxUrl}',
+ data: formData,
+ encode: true,
+ dataType: 'text'
+ })
+ .done( function(fieldHtml) {
+ if (fieldHtml == '') {
+ flashElement('glmCustomFieldsNewFieldDialogError');
+ } else {
+ $('#glmCustomFieldsListBody').append(fieldHtml);
+ $('#noCustomFieldsNotice').hide();
+ $("#glmCustomFieldsNewFieldDialog").dialog("close");
+
+ // Need to rebind delete field buttons
+ $('.glmCustomFieldsEditFieldButton').unbind('click', editFieldButton);
+ $('.glmCustomFieldsEditFieldButton').click(editFieldButton);
+
+ // Need to rebind delete field buttons
+ $('.glmCustomFieldsDeleteFieldButton').unbind('click', deleteFieldButton);
+ $('.glmCustomFieldsDeleteFieldButton').click(deleteFieldButton);
+ }
+ });
+
+ });
+ // Cancel
+ $('#glmCustomFieldsNewFieldCancel').click( function() {
+ $("#glmCustomFieldsNewFieldDialog").dialog("close");
+ });
+
+ /*
+ * Edit field dialog box
+ */
+ // Setup
+ $("#editFieldDialog").dialog({
+ autoOpen: false,
+ minWidth: 400,
+ dialogClass: "glm-dialog-no-close"
+ });
+ // Display form
+ $('.glmCustomFieldsEditFieldButton').click(editFieldButton);
+ function editFieldButton() {
+ var fieldID = $(this).attr('data-fieldID');
+ var fieldName = $(this).attr('data-fiedlName');
+ 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());
+ $('#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);
+ } else {
+ console.log('setting the checked to false');
+ $('#editRequired').prop('checked', false);
+ }
+ $("#editFieldDialog").dialog("open");
+ }
+ // Cancel
+ $('#editFieldCancel').click( function() {
+ $("#editFieldDialog").dialog("close");
+ });
+
+ /*
+ * Delete field dialog box
+ */
+ // Setup
+ $("#glmCustomFieldsDeleteFieldDialog").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");
+ }
+ // Delete confirmed
+ $('#glmCustomFieldsDeleteFieldConfirm').click( function() {
+
+ // Collect the new field data
+ var formData = {
+ 'action': 'glm_members_admin_ajax',
+ 'glm_action': 'customFields',
+ 'option': 'deleteField',
+ 'id': deleteId
+ };
+
+ // Submit new field data - expect field new ID back
+ $.ajax({
+ type: 'POST',
+ url: '{$ajaxUrl}',
+ data: formData,
+ encode: true,
+ dataType: 'text'
+ })
+ .done( function(deleted) {
+ $('#glmCustomFieldsFieldRow_' + deleteId).remove();
+ $("#glmCustomFieldsDeleteFieldDialog").dialog("close");
+ deleleteId = false;
+ });
+
+ });
+ // Cancel
+ $('#glmCustomFieldsDeleteFieldCancel').click( function() {
+ $("#glmCustomFieldsDeleteFieldDialog").dialog("close");
+ });
+
+ // Flash an element for a short time
+ function flashElement(id) {
+
+ $("#" + id).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
+ }
+});
+</script>
+++ /dev/null
-<div id="glm-members-custom-fields-{$uid}" class="glm-row glm-custom-field-group glm-admin-custom-fields">
- {foreach $customFields as $field}
- <div class="glm-small-12 glm-large-2 glm-columns glm-custom-field-label {if $field.required.value == 1} glm-required {/if}">{$field.field_name}</div>
- <div class="glm-small-12 glm-large-9 glm-columns glm-custom-field">
- <input type="hidden" name="custom-required" value="{$field.required.value}">
-
- {$fail = ''}
- {if is_array($customFieldsData)}
- {if array_key_exists('fieldFail', $customFieldsData)}
- {if array_key_exists($field.id,$customFieldsData['fieldFail'])}
- {$fail = 'glm-form-bad-input'}
- {/if}
- {/if}
- {/if}
- <div class="glm-input-wrapper {$fail}">
- {if $field.field_type.name == 'text'}
-
- <input class="glm-input glm-form-text-input-medium" type="text" name="{$prefix}[{$field.id}]" value="{if isset($customFieldsData[$field.id])}{$customFieldsData[$field.id]|escape}{/if}" {if $field.required.value == 1} required{/if}>
- {elseif $field.field_type.name == 'textarea'}
- {php}
- wp_editor('{if isset($customFieldsData[$field.id])}{$customFieldsData[$field.id]|escape:quotes}{/if}', 'custom-field-{$field.id}', array(
- 'media_buttons' => false,
- // 'quicktags' => false,
- // 'wpautop' => false, NOTE: Dont's use. Problem when numerous spaces before text.
- 'textarea_name' => '{$prefix}[{$field.id}]',
- 'editor_height' => 200, // Height in px, overrides editor_rows
- // 'textarea_rows' => 8,
- {if $field.required.value == 1}'editor_class' => 'glm-required' {/if}
- ));
- {/php}
- {elseif $field.field_type.name == 'checkbox'}
- <input type="hidden" name="{$prefix}[{$field.id}]" value="No" {if !isset($customFieldsData[$field.id]) || $customFieldsData[$field.id] == 'No'}checked{/if}>
- <input type="checkbox" name="{$prefix}[{$field.id}]" value="Yes" {if isset($customFieldsData[$field.id]) && $customFieldsData[$field.id] == 'Yes'}checked{/if} {if $field.required.value == 1} required{/if}>
- {/if}
- </div>
- </div>
- {/foreach}
-</div>
+++ /dev/null
-{include file='admin/import/header.html'}
-
- <h2>Social Data Import Step 1: Upload file</h2>
-
- <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
- <input type="hidden" name="glm_action" value="fields" />
- <input type="hidden" name="option" value="fieldsValidate" />
-
- <table class="glm-admin-table" border="0" cellspacing="5" cellpadding="10">
- <tr>
- <th>File Type</th>
- <th>New File</th>
- <th>Sample File</th>
- <th>Current File</th>
- <th>Updated</th>
- </tr>
- {$count = 0}
- {foreach $fileData as $fileHeader => $file}
- <tr{if $count%2 == 0} class="alternate"{/if}>
- <td class="glm-import-td">
- {$fileHeader}
- </td>
- <td class="glm-import-td">
- <input type="file" name="{$file.field}">
- </td>
- <td class="glm-import-td">
- <a href="{$sampleFileUrl}{$file.name}">Sample {$fileHeader} File</a>
- </td>
- <td class="glm-import-td">
- {if $file.exists}
- {$fileHeader} File
- {/if}
- </td>
- <td class="glm-import-td">
- {if $file.exists}
- {$file.mtime|date_format:"%D %I:%M %p"}
- {/if}
- </td>
- </tr>
- {$count = $count + 1}
- {/foreach}
- </table>
-
- <input type="submit" value="Continue" class="button button-primary submit-import">
-
- </form>
-
-{include file='admin/footer.html'}
+++ /dev/null
-{include file='admin/import/header.html'}
-
- <h2>Data Import Step 3: Process Fields File</h2>
- <table class="glm-admin-table">
- <tr>
- <th>Total Records</th>
- <td>{$totalFields}</td>
- </tr>
- <tr>
- <th>Processed Records</th>
- <td>{$numberProcessed}</td>
- </tr>
-
- </table>
-
-{include file='admin/footer.html'}
+++ /dev/null
-{include file='admin/import/header.html'}
-
- <h2>Secial Import Step 2: Validate Fields file</h2>
-
- <table class="glm-admin-table">
- {foreach $fileData as $fileHeader => $file}
- <tr>
- <td>
- {if $file.exists}
- {$fileHeader} File
- {/if}
- </td>
- <td>
- {if $file.isValid}
- Is Valid
- {else}
- Not Valid
- {/if}
- </td>
- </tr>
- {/foreach}
-
- {if $readyToProcess}
- <tr>
- <td colspan="2">
- <a href="{$thisUrl}?page={$thisPage}&glm_action=fields&option=fieldsProcess" class="button">Process Files</a>
- </td>
- </tr>
- {else}
- <tr>
- <td colspan="2">
- <p>One or more of your files are not the correct csv format. Please go back and try again.</p>
- <a href="{$thisUrl}?page={$thisPage}&glm_action=fields" class="button">Go Back</a>
- </td>
- </tr>
- {/if}
-
- </table>
-
-{include file='admin/footer.html'}
+++ /dev/null
-<!-- Add Custom Field Button and Dialog Box -->
-<div id="newFieldButton" class="button button-primary glm-right">Add a Custom Field</div>
-<div id="newFieldDialog" class="glm-dialog-box" title="Enter a New Custom 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="addNew">
-
- <table class="glm-admin-table">
- <tr>
- <th class="glm-required">Field Name:</th>
- <td>
- <input type="text" name="field_name" class="glm-form-text-input">
- </td>
- </tr>
- <tr>
- <th class="glm-required">Field Type:</th>
- <td>
- <select name="field_type">
- {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" 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" name="required" value="1" />
- </td>
- </tr>
- <input type="hidden" name="uid" value="{$uid}">
- </table>
- <p><span class="glm-required">*</span> Required</p>
- <a id="newFieldCancel" class="button button-primary glm-right">Cancel</a>
- <input type="submit" value="Add new Custom Field" class="button button-primary">
- </form>
-</div>
-
-<!-- Delete Field Button and Dialog Box -->
-<div id="deleteFieldDialog" class="glm-dialog-box" title="Delete Field">
- <center>
- <p>Are you sure you want to delete this field?</p>
- <p><div id="deleteFieldConfirm" class="button button-primary">Yes, delete this field</div></p>
- <p><div id="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">
- <tr>
- <th class="glm-required">Field Name:</th>
- <td>
- <input id="editFieldName" type="text" name="field_name" class="glm-form-text-input">
- </td>
- </tr>
- <tr>
- <th class="glm-required">Field Type:</th>
- <td>
- <select id="editFieldType" name="field_type">
- {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>
- </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>
- <input type="submit" value="Update this Field">
- </form>
-</div>
-<table id="glm-table-settings" class="glm-admin-table glm-settings-table{if $option2!='settings'} glm-hidden{/if}">
- <tr>
- <td colspan="2">
- {if $settingsUpdated}<h2 class="glm-notice glm-flash-updated glm-right">Settings Updated</h2>{/if}
- {if $settingsUpdateError}<span class="glm-error glm-flash-updated glm-right">Settings Update Error</span>{/if}
- <h2>Custom Fields</h2>
- </td>
- </tr>
-</table>
-<table id="glm-table-settings" class="glm-admin-table glm-settings-table">
- <thead>
- <tr>
- <th>ID</th>
- <th>Field</th>
- <th>Type</th>
- <th>UID/Entity</th>
- <th>Required</th>
- <!-- 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'}<th>Admin Searchable</th>{/if}
- <th> </th>
- </tr>
- </thead>
- <tbody>
- {if $haveCustomFields}
- {assign var="i" value="0"}
- {foreach $custom_fields as $t}
- {if $i++ is odd by 1}
- <tr>
- {else}
- <tr class="alternate">
- {/if}
- <td>{$t.id}</td>
- <td>
- <div>
- <a class="editField" data-fieldID="{$t.id}" data-fieldType="{$t.field_type.name|escape:'html'}" data-adminSearch="{$t.admin_search.value}" data-required="{$t.required.value}">{$t.field_name}</a>
- </div>
- </td>
- <td id="editFieldType_{$t.id}">
- {$t.field_type.name}
- </td>
- <td>
- {$t.uid}
- </td>
- <td>
- {$t.required.name}
- </td>
- <td>
- {$t.admin_search.name}
- </td>
- <td>
- <div class="deleteFieldButton button button-secondary glm-button-small glm-right" data-fieldID="{$t.id}">Delete</div>
- </td>
- </tr>
- {/foreach}
- {else}
- <tr class="alternate"><td colspan="2">(no custom fields listed)</td></tr>
- {/if}
- </tbody>
-</table>
-<!-- Tests -->
-
-<script type="text/javascript">
-jQuery(document).ready(function($) {
-
- /*
- * Edit area tabs
- */
- $('.glm-settings-tab').click( function() {
-
- // Clear table highlights and hide all tables
- $('.glm-settings-tab').removeClass('nav-tab-active');
- $('.glm-settings-table').addClass('glm-hidden');
-
- // Highlight selected tab
- $(this).addClass('nav-tab-active');
-
- // Show selected table
- var table = $(this).attr('data-show-table');
- $('#' + table).removeClass('glm-hidden');
-
- });
- $("#newFieldDialog").dialog({
- autoOpen: false,
- minWidth: 400,
- dialogClass: "glm-dialog-no-close"
- });
- $("#editFieldDialog").dialog({
- autoOpen: false,
- minWidth: 400,
- dialogClass: "glm-dialog-no-close"
- });
- $("#deleteFieldDialog").dialog({
- autoOpen: false,
- minWidth: 400,
- dialogClass: "glm-dialog-no-close"
- });
- $('#newFieldButton').click( function() {
- $("#newFieldDialog").dialog("open");
- });
- $('.editField').click( function() {
- var fieldID = $(this).attr('data-fieldID');
- var fieldName = $(this).text();
- 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());
- $('#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);
- } else {
- console.log('setting the checked to false');
- $('#editRequired').prop('checked', false);
- }
- $("#editFieldDialog").dialog("open");
- });
- $('#editFieldCancel').click( function() {
- $("#editFieldDialog").dialog("close");
- });
- $('#newFieldCancel').click( function() {
- $("#newFieldDialog").dialog("close");
- });
-
- var id = false;
- $('.deleteFieldButton').click( function() {
- id = $(this).attr('data-fieldID');
- $("#deleteFieldDialog").dialog("open");
- });
- $('#deleteFieldConfirm').click( function() {
- $("#deleteFieldDialog").dialog("close");
- window.location.href = "{$thisUrl}?page={$thisPage}&glm_action={$glm_action}&option=customfields&option2=delete&id=" + id;
- });
- $('#deleteFieldCancel').click( function() {
- $("#deleteFieldDialog").dialog("close");
- });
-
- // 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).fadeIn(500).fadeOut(500);
-});
-</script>