if (false === $participant_id) { $action = 'insert'; $page_title = __('Add New Participant Record', 'participants-database'); $participant_values = Participants_Db::get_default_record(); } else { $action = 'update'; $page_title = __('Edit Existing Participant Record', 'participants-database'); $participant_values = Participants_Db::get_participant($participant_id); } /* * if we have a valid ID or are creating a new record, show the form */ if ($participant_values) { //error_log( basename( __FILE__).' default record:'.print_r( $participant_values,1)); //get the groups info $groups = Participants_Db::get_groups(); // get the current user's info get_currentuserinfo(); $options = get_option(self::$participants_db_options); // set up the hidden fields $hidden = array('action' => $action, 'subsource' => Participants_Db::PLUGIN_NAME); foreach (array('id', 'private_id') as $i) { if (isset($participant_values[$i])) { $hidden[$i] = $participant_values[$i]; } } $section = ''; ?> <div class="wrap admin-edit-participant"> <h2><?php echo $page_title;
/** * displays an edit field for a field attribute * * @param string $field name of the field * @return array contains parameters to use in instantiating the xnau_FormElement object */ function PDb_get_edit_field_type($field) { switch ($field) { // small integer fields case 'id': return array('type' => 'hidden'); case 'order': return array('type' => 'drag-sort'); case 'admin_column': case 'display_column': return array('type' => 'text', 'attributes' => array('class' => 'digit')); // all the booleans // all the booleans case 'persistent': case 'sortable': case 'CSV': case 'signup': case 'readonly': return array('type' => 'checkbox', 'options' => array(1, 0)); // field names can't be edited // field names can't be edited case 'name': return array('type' => 'text', 'attributes' => array('readonly' => 'readonly')); // all the text-area fields // all the text-area fields case 'values': case 'help_text': return array('type' => 'text-area'); // drop-down fields // drop-down fields case 'form_element': // populate the dropdown with the available field types from the xnau_FormElement class return array('type' => 'dropdown', 'options' => array_flip(PDb_FormElement::get_types()) + array('null_select' => false)); case 'validation': return array('type' => 'dropdown-other', 'options' => array(__('Not Required', 'participants-database') => 'no', __('Required', 'participants-database') => 'yes', __('Email', 'participants-database') => 'email-regex', 'CAPTCHA' => 'captcha', 'null_select' => false), 'attributes' => array('other' => 'regex/match')); case 'group': // these options are defined on the "settings" page return array('type' => 'dropdown', 'options' => Participants_Db::get_groups('name', 'internal') + array('null_select' => false)); case 'link': case 'title': default: return array('type' => 'text'); } }
/** * sets up the template iteration object * * this takes all the fields that are going to be displayed and organizes them * under their group so we can easily run through them in the template */ protected function _setup_iteration() { $this->_setup_hidden_fields(); $this->record = new stdClass(); $groups = Participants_Db::get_groups(); foreach ($this->display_groups as $group_name) { $group_fields = $this->_get_group_fields($group_name); $this->record->{$group_name} = (object) $groups[$group_name]; $this->record->{$group_name}->fields = new stdClass(); $field_count = 0; $all_empty_fields = true; foreach ($group_fields as $field) { // set the current value of the field $this->_set_field_value($field); /* * hidden fields are stored separately for modules that use them as * hidden input fields */ if ($field->form_element !== 'hidden') { $this->_set_field_link($field); /* * add the field object to the record object */ if (in_array($field->name, $this->display_columns)) { $field_count++; if (!$this->_empty($field->value)) { $all_empty_fields = false; } /** * @version 1.6 'pdb-before_field_added_to_iterator' filter * @param $field object */ $this->record->{$group_name}->fields->{$field->name} = Participants_Db::set_filter('before_field_added_to_iterator', $field); } } } } if ($field_count === 0) { // remove the empty group from the iterator unset($this->record->{$group_name}); } elseif ($all_empty_fields) { $this->record->{$group_name}->class[] = 'empty-field-group'; } // save the number of groups $this->group_count = count((array) $this->record); }
/** * sets up the template iteration object * * this takes all the fields that are going to be displayed and organizes them * under their group so we can easily run through them in the template */ protected function _setup_iteration() { $this->record = new stdClass(); // get a list list of groups not displayed. We iterate through these because // we need to pick out the hidden fields $skip_groups = $this->_get_display_groups(false); foreach (Participants_Db::get_groups('`title`,`name`,`description`') as $group) { if ($this->_has_group_fields($group['name'])) { if (!in_array($group['name'], $skip_groups)) { //add the group array as an object $this->record->{$group}['name'] = (object) $group; // create an object for the groups fields $this->record->{$group}['name']->fields = new stdClass(); } //error_log ( __METHOD__.' group fields: '. print_r( $this->_get_group_fields( $group['name'] ), 1 ) ); foreach ($this->_get_group_fields($group['name']) as $field) { // add the module property //$field->module = $this->module; // set the current value of the field $this->_set_field_value($field); /* * hidden fields are stored separately for modules that use them as * hidden input fields */ if ($field->form_element == 'hidden' and in_array($this->module, array('signup', 'record'))) { $this->hidden_fields[$field->name] = $field->value; } elseif (!in_array($group['name'], $skip_groups)) { $this->_set_field_link($field); // add the field to the list of fields $this->columns[$field->name] = $field; /* * add the field object to the record object */ $this->record->{$group}['name']->fields->{$field->name} = $field; } } } } // save the number of groups $this->group_count = count((array) $this->record); }