From: Chuck Scott Date: Mon, 4 Dec 2017 21:15:57 +0000 (-0500) Subject: Starting rework to remove legacy code get custom fields working cleanly. X-Git-Tag: v1.0.0^2~41 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=c52cda7df2726c9875019dd398636f54f61e7f33;p=WP-Plugins%2Fglm-member-db-customfields.git Starting rework to remove legacy code get custom fields working cleanly. 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. --- diff --git a/classes/data/dataCustomFields.php b/classes/data/dataCustomFields.php index 814118d..e5ef93c 100644 --- a/classes/data/dataCustomFields.php +++ b/classes/data/dataCustomFields.php @@ -148,14 +148,12 @@ class GlmDataFieldsCustomFields extends GlmDataAbstract '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' ), diff --git a/models/admin/OLD-entity/fields.php b/models/admin/OLD-entity/fields.php new file mode 100644 index 0000000..6049837 --- /dev/null +++ b/models/admin/OLD-entity/fields.php @@ -0,0 +1,192 @@ + + * @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 + * @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 + ); + + + } + +} diff --git a/models/admin/OLD-management/fields.php b/models/admin/OLD-management/fields.php new file mode 100644 index 0000000..cc22962 --- /dev/null +++ b/models/admin/OLD-management/fields.php @@ -0,0 +1,228 @@ + + * @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 + * @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 "
REQUEST " . print_r($_REQUEST, true) . "
"; + // echo "
GET " . print_r($_GET, true) . "
"; + 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 "
Template data:" . print_r($template_data, true) . "
"; + + // Return status, suggested view, and data to controller + return array( + 'status' => true, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'admin/management/fields.html', + 'data' => $template_data + ); + + + } + +} diff --git "a/models/admin/OL\357\200\242D-import/fields.php" "b/models/admin/OL\357\200\242D-import/fields.php" new file mode 100644 index 0000000..6736069 --- /dev/null +++ "b/models/admin/OL\357\200\242D-import/fields.php" @@ -0,0 +1,411 @@ + + * @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 '
$fields: ' . print_r( $fields, true ) . '
'; + $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' => '
$fileData: ' . print_r( $fileData, true ) . '
', + '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; + } +} diff --git a/models/admin/ajax/customFields.php b/models/admin/ajax/customFields.php new file mode 100644 index 0000000..c735748 --- /dev/null +++ b/models/admin/ajax/customFields.php @@ -0,0 +1,217 @@ + + * @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; + + } + + + +} diff --git a/models/admin/ajax/filterSearch.php b/models/admin/ajax/filterSearch.php deleted file mode 100644 index 18fb75a..0000000 --- a/models/admin/ajax/filterSearch.php +++ /dev/null @@ -1,119 +0,0 @@ - - * @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(); - } -} diff --git a/models/admin/customFields/index.php b/models/admin/customFields/index.php new file mode 100644 index 0000000..8bd56c1 --- /dev/null +++ b/models/admin/customFields/index.php @@ -0,0 +1,217 @@ + + * @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 + * @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 "
Template data:" . print_r($template_data, true) . "
"; + + // Return status, suggested view, and data to controller + return array( + 'status' => true, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'admin/customFields/'.$viewFile, + 'data' => $template_data + ); + + + } + +} diff --git a/models/admin/entity/fields.php b/models/admin/entity/fields.php deleted file mode 100644 index 6049837..0000000 --- a/models/admin/entity/fields.php +++ /dev/null @@ -1,192 +0,0 @@ - - * @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 - * @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 - ); - - - } - -} diff --git a/models/admin/import/fields.php b/models/admin/import/fields.php deleted file mode 100644 index 6736069..0000000 --- a/models/admin/import/fields.php +++ /dev/null @@ -1,411 +0,0 @@ - - * @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 '
$fields: ' . print_r( $fields, true ) . '
'; - $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' => '
$fileData: ' . print_r( $fileData, true ) . '
', - '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; - } -} diff --git a/models/admin/management/fields.php b/models/admin/management/fields.php deleted file mode 100644 index cc22962..0000000 --- a/models/admin/management/fields.php +++ /dev/null @@ -1,228 +0,0 @@ - - * @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 - * @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 "
REQUEST " . print_r($_REQUEST, true) . "
"; - // echo "
GET " . print_r($_GET, true) . "
"; - 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 "
Template data:" . print_r($template_data, true) . "
"; - - // Return status, suggested view, and data to controller - return array( - 'status' => true, - 'menuItemRedirect' => false, - 'modelRedirect' => false, - 'view' => 'admin/management/fields.html', - 'data' => $template_data - ); - - - } - -} diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 803d3b1..8a7ce61 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -44,21 +44,26 @@ add_filter('glm-member-db-admin-management-hooksHelp', function($content) { ); /** - * 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 */ diff --git a/setup/commonHooks.php b/setup/commonHooks.php index 76c044a..009a0ca 100644 --- a/setup/commonHooks.php +++ b/setup/commonHooks.php @@ -15,7 +15,7 @@ */ /* - * 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... @@ -27,3 +27,10 @@ * 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 ); + diff --git a/setup/validActions.php b/setup/validActions.php index fac0518..f6a0815 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -60,22 +60,16 @@ $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, ), ) ); diff --git a/views/admin/OLD-entity/fields.html b/views/admin/OLD-entity/fields.html new file mode 100644 index 0000000..2c69862 --- /dev/null +++ b/views/admin/OLD-entity/fields.html @@ -0,0 +1,38 @@ +
+ {foreach $customFields as $field} +
{$field.field_name}
+
+ + + {$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} +
+ {if $field.field_type.name == 'text'} + + + {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'} + + + {/if} +
+
+ {/foreach} +
diff --git a/views/admin/OLD-import/fields.html b/views/admin/OLD-import/fields.html new file mode 100644 index 0000000..0b17672 --- /dev/null +++ b/views/admin/OLD-import/fields.html @@ -0,0 +1,48 @@ +{include file='admin/import/header.html'} + +

Social Data Import Step 1: Upload file

+ +
+ + + + + + + + + + + + {$count = 0} + {foreach $fileData as $fileHeader => $file} + + + + + + + + {$count = $count + 1} + {/foreach} +
File TypeNew FileSample FileCurrent FileUpdated
+ {$fileHeader} + + + + Sample {$fileHeader} File + + {if $file.exists} + {$fileHeader} File + {/if} + + {if $file.exists} + {$file.mtime|date_format:"%D %I:%M %p"} + {/if} +
+ + + +
+ +{include file='admin/footer.html'} diff --git a/views/admin/OLD-import/fieldsProcess.html b/views/admin/OLD-import/fieldsProcess.html new file mode 100644 index 0000000..dab58af --- /dev/null +++ b/views/admin/OLD-import/fieldsProcess.html @@ -0,0 +1,16 @@ +{include file='admin/import/header.html'} + +

Data Import Step 3: Process Fields File

+ + + + + + + + + + +
Total Records{$totalFields}
Processed Records{$numberProcessed}
+ +{include file='admin/footer.html'} diff --git a/views/admin/OLD-import/fieldsValidate.html b/views/admin/OLD-import/fieldsValidate.html new file mode 100644 index 0000000..9ff514d --- /dev/null +++ b/views/admin/OLD-import/fieldsValidate.html @@ -0,0 +1,40 @@ +{include file='admin/import/header.html'} + +

Secial Import Step 2: Validate Fields file

+ + + {foreach $fileData as $fileHeader => $file} + + + + + {/foreach} + + {if $readyToProcess} + + + + {else} + + + + {/if} + +
+ {if $file.exists} + {$fileHeader} File + {/if} + + {if $file.isValid} + Is Valid + {else} + Not Valid + {/if} +
+ Process Files +
+

One or more of your files are not the correct csv format. Please go back and try again.

+ Go Back +
+ +{include file='admin/footer.html'} diff --git a/views/admin/OLD-management/fields.html b/views/admin/OLD-management/fields.html new file mode 100644 index 0000000..8834912 --- /dev/null +++ b/views/admin/OLD-management/fields.html @@ -0,0 +1,277 @@ + +
Add a Custom Field
+ +{* New field form *} +
+ + + + + + + + + + + + + + +
Field Name: + +
Field Type: + +
Required? + +
+

* Required

+
Cancel
+
Add new Custom Field
+
+ +{* Delete field button confirmation dialog box *} +
+
+

Are you sure you want to delete this field?

+

Yes, delete this field

+

Cancel

+
+
+ +{* Edit field dialog box *} +
+
+ + + + + + + + + + + + + + + {if $uid == 'glm-member-db'} + + + + + {/if} + + + + + +
Field Name: + +
Field Type: + +
Admin Searchable + + + (text or checkbox only) +
Required? + + +
+

* Required

+ Cancel + +
+
+ +{* Update and error messages *} + + + + +
+ {if $settingsUpdated}

Settings Updated

{/if} + {if $settingsUpdateError}Settings Update Error{/if} +

Custom Fields

+
+ +{* Fields Table *} + + + + + + + + + + {if $uid == 'glm-member-db'}{/if} + + + + + {if $haveCustomFields} + {assign var="i" value="0"} + {foreach $custom_fields as $t} + {if $i++ is odd by 1} + + {else} + + {/if} + + + + + + + + + {/foreach} + {else} + + {/if} + +
IDFieldTypeUID/EntityRequiredAdmin Searchable 
{$t.id} + + + {$t.field_type.name} + + {$t.uid} + + {$t.required.name} + + {$t.admin_search.name} + +
Delete
+
(no custom fields listed)
+ + + diff --git a/views/admin/ajax/newField.html b/views/admin/ajax/newField.html new file mode 100644 index 0000000..6f9955a --- /dev/null +++ b/views/admin/ajax/newField.html @@ -0,0 +1,11 @@ +{* A single line for the custom fields edit table *} + +
{$fieldData.field_name}
+ {$fieldData.field_type.name} + {$fieldData.required.name} + + +
Delete
+ + diff --git a/views/admin/customFields/index.html b/views/admin/customFields/index.html new file mode 100644 index 0000000..20c52eb --- /dev/null +++ b/views/admin/customFields/index.html @@ -0,0 +1,306 @@ + +
Add a Custom Field
+ +{* New field form *} +
+ + + + + + + + + + + + + + +
Field Name: + +
Field Type: + +
Required? + +
+

* Required

+
Cancel
+
Add new Custom Field
+ +
+ +{* Delete field button confirmation dialog box *} +
+
+

Are you sure you want to delete this field?

+

Yes, delete this field

+

Cancel

+
+
+ +{* Edit field dialog box *} +
+
+ + + + + + + + + + + + + + + {if $uid == 'glm-member-db'} + + + + + {/if} + + + + + +
Field Name: + +
Field Type: + +
Admin Searchable + + + (text or checkbox only) +
Required? + + +
+

* Required

+ Cancel + +
+
+ +{* Update and error messages *} + + + + +
+ {if $settingsUpdated}

Settings Updated

{/if} + {if $settingsUpdateError}Settings Update Error{/if} +

Custom Fields

+
+ +{* Fields Table *} + + + + + + + + + + +{if $haveCustomFields} + {foreach $custom_fields as $t} + + + + + + + {/foreach} + {else} + +{/if} + +
Field NameTypeRequired 
+
+ {$t.field_name} +
+
+ {$t.field_type.name} + + {$t.required.name} + + +
Delete
+
(no custom fields listed)
+ + + diff --git a/views/admin/entity/fields.html b/views/admin/entity/fields.html deleted file mode 100644 index 2c69862..0000000 --- a/views/admin/entity/fields.html +++ /dev/null @@ -1,38 +0,0 @@ -
- {foreach $customFields as $field} -
{$field.field_name}
-
- - - {$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} -
- {if $field.field_type.name == 'text'} - - - {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'} - - - {/if} -
-
- {/foreach} -
diff --git a/views/admin/import/fields.html b/views/admin/import/fields.html deleted file mode 100644 index 0b17672..0000000 --- a/views/admin/import/fields.html +++ /dev/null @@ -1,48 +0,0 @@ -{include file='admin/import/header.html'} - -

Social Data Import Step 1: Upload file

- -
- - - - - - - - - - - - {$count = 0} - {foreach $fileData as $fileHeader => $file} - - - - - - - - {$count = $count + 1} - {/foreach} -
File TypeNew FileSample FileCurrent FileUpdated
- {$fileHeader} - - - - Sample {$fileHeader} File - - {if $file.exists} - {$fileHeader} File - {/if} - - {if $file.exists} - {$file.mtime|date_format:"%D %I:%M %p"} - {/if} -
- - - -
- -{include file='admin/footer.html'} diff --git a/views/admin/import/fieldsProcess.html b/views/admin/import/fieldsProcess.html deleted file mode 100644 index dab58af..0000000 --- a/views/admin/import/fieldsProcess.html +++ /dev/null @@ -1,16 +0,0 @@ -{include file='admin/import/header.html'} - -

Data Import Step 3: Process Fields File

- - - - - - - - - - -
Total Records{$totalFields}
Processed Records{$numberProcessed}
- -{include file='admin/footer.html'} diff --git a/views/admin/import/fieldsValidate.html b/views/admin/import/fieldsValidate.html deleted file mode 100644 index 9ff514d..0000000 --- a/views/admin/import/fieldsValidate.html +++ /dev/null @@ -1,40 +0,0 @@ -{include file='admin/import/header.html'} - -

Secial Import Step 2: Validate Fields file

- - - {foreach $fileData as $fileHeader => $file} - - - - - {/foreach} - - {if $readyToProcess} - - - - {else} - - - - {/if} - -
- {if $file.exists} - {$fileHeader} File - {/if} - - {if $file.isValid} - Is Valid - {else} - Not Valid - {/if} -
- Process Files -
-

One or more of your files are not the correct csv format. Please go back and try again.

- Go Back -
- -{include file='admin/footer.html'} diff --git a/views/admin/management/fields.html b/views/admin/management/fields.html deleted file mode 100644 index fdd0d80..0000000 --- a/views/admin/management/fields.html +++ /dev/null @@ -1,259 +0,0 @@ - -
Add a Custom Field
-
-
- - - - - - - - - - - - - - - {if $uid == 'glm-member-db'} - - - - - {/if} - - - - - -
Field Name: - -
Field Type: - -
Admin Searchable - - - (text or checkbox only) -
Required? - - -
-

* Required

- Cancel - -
-
- - -
-
-

Are you sure you want to delete this field?

-

Yes, delete this field

-

Cancel

-
-
- - -
-
- - - - - - - - - - - - - - - {if $uid == 'glm-member-db'} - - - - - {/if} - - - - - -
Field Name: - -
Field Type: - -
Admin Searchable - - - (text or checkbox only) -
Required? - - -
-

* Required

- Cancel - -
-
- - - - -
- {if $settingsUpdated}

Settings Updated

{/if} - {if $settingsUpdateError}Settings Update Error{/if} -

Custom Fields

-
- - - - - - - - - - {if $uid == 'glm-member-db'}{/if} - - - - - {if $haveCustomFields} - {assign var="i" value="0"} - {foreach $custom_fields as $t} - {if $i++ is odd by 1} - - {else} - - {/if} - - - - - - - - - {/foreach} - {else} - - {/if} - -
IDFieldTypeUID/EntityRequiredAdmin Searchable 
{$t.id} - - - {$t.field_type.name} - - {$t.uid} - - {$t.required.name} - - {$t.admin_search.name} - -
Delete
-
(no custom fields listed)
- - -