/**
  * prints the form open tag and all hidden fields
  * 
  * The incoming hidden fields are merged with the default fields
  * 
  * @param array $hidden array of hidden fields to print
  * @return null
  */
 protected function _print_form_head($hidden = '')
 {
     $uri_components = parse_url($_SERVER['REQUEST_URI']);
     echo '<form method="post" enctype="multipart/form-data"  autocomplete="' . $this->shortcode_atts['autocomplete'] . '" action="' . $_SERVER['REQUEST_URI'] . '" >';
     $default_hidden_fields = array('action' => $this->module, 'subsource' => Participants_Db::PLUGIN_NAME, 'shortcode_page' => $uri_components['path'] . (isset($uri_components['query']) ? '?' . $uri_components['query'] : ''), 'thanks_page' => $this->submission_page, 'instance_index' => $this->instance_index, 'pdb_data_keys' => $this->_form_data_keys(), 'session_hash' => Participants_Db::nonce(Participants_Db::$main_submission_nonce_key));
     if ($this->get_form_status() === 'multipage') {
         $default_hidden_fields['previous_multipage'] = $default_hidden_fields['shortcode_page'];
     }
     $hidden = is_array($hidden) ? $hidden : array();
     $hidden_fields = $this->hidden_fields + $hidden + $default_hidden_fields;
     PDb_FormElement::print_hidden_fields($hidden_fields);
 }
 /**
  * prints a series of hidden fields
  * 
  * @param array $fields name => value pairs
  * @param bool $print true to print, false to return
  */
 public static function print_hidden_fields($fields, $print = true)
 {
     $hidden_fields = PDb_FormElement::print_hidden_fields($fields, false);
     if ($print) {
         echo $hidden_fields;
     } else {
         return $hidden_fields;
     }
 }
 /**
  * creates the math captcha
  * 
  * @return null
  */
 protected function math_capcha()
 {
     if (is_array($this->value)) {
         $this->value = $this->value[1];
     }
     $this->size = 3;
     $operators = array('&times;' => 'bcmul', '+' => 'bcadd', '&minus;' => 'bcsub');
     /*
      * if the last CAPTCHA submission was correct, we display it again
      */
     if ($this->last_challenge_met() && !empty($this->value)) {
         extract(Participants_Db::$session->getArray('captcha_vars'));
     } else {
         /* generate the math question. We try to make it a simple arithmetic problem
          */
         Participants_Db::$session->clear('captcha_result');
         $o = array_rand($operators);
         switch ($o) {
             case '&times;':
                 $a = rand(1, 10);
                 $b = rand(1, 5);
                 break;
             case '&minus;':
                 $a = rand(2, 10);
                 do {
                     $b = rand(1, 9);
                 } while ($b >= $a);
                 break;
             default:
                 $a = rand(1, 10);
                 $b = rand(1, 10);
         }
         Participants_Db::$session->set('captcha_vars', compact('a', 'o', 'b'));
     }
     $prompt_string = $a . ' <span class="' . Participants_Db::$prefix . 'operator">' . $o . '</span> ' . $b . ' <span class="' . Participants_Db::$prefix . 'operator">=</span> ?';
     $this->HTML = '<span class="math-captcha">' . $prompt_string . '</span>';
     $this->HTML .= PDb_FormElement::get_element(array('type' => 'text', 'name' => $this->name, 'value' => $this->value, 'group' => true));
     try {
         $regex_value = call_user_func($operators[$o], $a, $b);
     } catch (Exception $e) {
         error_log(Participants_Db::$plugin_title . ' bcmath function could not be called: using alternative method. ');
         $regex_value = $this->compute($o, $a, $b);
     }
     $this->validation = '#^' . $regex_value . '$#';
     $this->captcha_params = array('a' => $a, 'o' => $o, 'b' => $b);
 }
Example #4
0
 /**
  * supplied for backwards compatibility
  * 
  * the original func has been superceded, but this will allow the old func to be used
  * 
  * @var string $value
  * @var string $form_element
  * @return string
  */
 public static function prep_field_for_display($value, $form_element)
 {
     $field = (object) array('value' => $value, 'form_element' => $form_element, 'module' => 'single');
     return PDb_FormElement::get_field_value_display($field);
 }
        $this->the_record();
        // each record is one row
        ?>
      <tr>
        <?php 
        while ($this->have_fields()) {
            $this->the_field();
            // each field is one cell
            ?>

                <?php 
            if ($this->field->has_content()) {
                ?>
          <td>
          	<?php 
                echo PDb_FormElement::get_field_value_display($this->field);
                ?>
            </td>
            
        <?php 
            } else {
                // if the field is empty
                ?>
        <td></td>
        <?php 
            }
            ?>
        
			<?php 
        }
        // each field
 /**
  * adds a link value to a field object
  * 
  * @param string $name
  * @param string $href
  */
 private function _set_link($name, $href)
 {
     if (PDb_FormElement::field_is_linkable($this->fields->{$name})) {
         switch ($this->base_type) {
             case 'PDb_List':
                 $this->fields->{$name}->link = $href;
                 break;
             case 'PDb_Signup':
             case 'PDb_Single':
             case 'PDb_Record':
             default:
                 $group = $this->fields->{$name}->group;
                 $field = $this->record->{$group}->fields->{$name}->link = $href;
         }
     }
 }
Example #7
0
/**
 * 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');
    }
}
 /**
  * outputs a set of hidden inputs
  *
  * @param array $fields name=>value pairs for each hidden input tag
  */
 public static function print_hidden_fields($fields, $print = true)
 {
     PDb_FormElement::print_hidden_fields($fields, $print);
 }
 /**
  * prints the submit button
  *
  * @param string $class a classname for the submit button, defaults to 'button-primary'
  * @param string $button_value submit button text
  * 
  */
 public function print_submit_button($class = 'button-primary', $button_value = false)
 {
     $button_value = $button_value ? $button_value : $this->shortcode_atts['submit_button'];
     PDb_FormElement::print_element(array('type' => 'submit', 'value' => $button_value, 'name' => 'submit_button', 'class' => $class . ' pdb-submit', 'module' => $this->module));
 }
 /**
  * 
  * @param bool $print
  * @return null|string
  */
 public function sort_form($print = true)
 {
     $value = $this->list_query->current_filter('sort_field');
     $options = array();
     if (!in_array($value, $this->sortables)) {
         $options = array('null_select' => '');
     }
     $element = array('type' => 'dropdown', 'name' => 'sortBy', 'value' => $value, 'options' => $options + $this->sortables, 'class' => 'search-item');
     $output[] = PDb_FormElement::get_element($element);
     $element = array('type' => 'radio', 'name' => 'ascdesc', 'value' => $this->list_query->current_filter('sort_order'), 'class' => 'checkbox inline search-item', 'options' => array(__('Ascending', 'participants-database') => 'ASC', __('Descending', 'participants-database') => 'DESC'));
     $output[] = PDb_FormElement::get_element($element);
     $output[] = '<input name="submit_button" data-submit="sort" type="submit" value="' . esc_attr($this->i18n['sort']) . '" />';
     if ($print) {
         echo $this->output_HTML($output);
     } else {
         return $this->output_HTML($output);
     }
 }
 /**
  * sets the search term property
  * 
  * @param string $term
  * @return null
  */
 public function set_search_term($term)
 {
     if ($term === 'null' || $term === '' || is_null($term)) {
         $this->term = '';
     } else {
         $term = PDb_FormElement::get_title_value($term, $this->field->name);
         $this->term = self::_esc_like($term);
     }
 }
    /**
     * prints the general list form controls for the admin lising: deleting and items-per-page selector
     */
    private static function _general_list_form_top()
    {
        ?>

      <form id="list_form"  method="post">
            <?php 
        PDb_FormElement::print_hidden_fields(array('action' => 'list_action'));
        ?>
        <input type="hidden" id="select_count" value="0" />
                <table class="form-table"><tbody><tr><td>
        <fieldset class="widefat inline-controls">
          <?php 
        if (current_user_can(Participants_Db::$plugin_options['plugin_admin_capability'])) {
            ?>
          <span style="padding-right:20px" ><input type="submit" name="submit-button" class="button button-default" value="<?php 
            echo self::$i18n['delete_checked'];
            ?>
" onClick="return delete_confirm();" id="delete_button"  ></span>
          <?php 
        }
        ?>
            <?php 
        $list_limit = PDb_FormElement::get_element(array('type' => 'text-line', 'name' => 'list_limit', 'value' => self::$page_list_limit, 'attributes' => array('style' => 'width:2.8em', 'maxLength' => '3')));
        ?>
          <?php 
        printf(__('Show %s items per page.', 'participants-database'), $list_limit);
        ?>
      <?php 
        PDb_FormElement::print_element(array('type' => 'submit', 'name' => 'submit-button', 'class' => 'button button-default', 'value' => self::$i18n['change']));
        ?>
          
        </fieldset>
              </td></tr></tbody>
        <?php 
    }
 /**
  * replace the tags in text messages
  *
  * a tag contains the column name for the value to use: [column_name]
  *
  * also processes the [record_link] tag
  *
  * @param string $text   the unporcessed text with tags
  * @param array  $values the values to replace the tags with
  * @param array  $tags   the tags to look for in the text
  *
  * @return string the text with the replacements made
  *
  */
 protected function _proc_tags($text, $values = array(), $tags = array())
 {
     if (empty($values)) {
         foreach ($this->columns as $column) {
             $tags[] = '[' . $column->name . ']';
             $column->value = $this->participant_values[$column->name];
             $values[] = PDb_FormElement::get_field_value_display($column, false);
         }
     }
     // add some extra tags
     foreach (array('id', 'private_id') as $v) {
         $tags[] = '[' . $v . ']';
         $values[] = $this->participant_values[$v];
     }
     $tags[] = '[record_link]';
     $values[] = $this->registration_page;
     $tags[] = '[admin_record_link]';
     $values[] = Participants_Db::get_admin_record_link($this->participant_values['id']);
     $placeholders = array();
     for ($i = 1; $i <= count($tags); $i++) {
         $placeholders[] = '%' . $i . '$s';
     }
     // replace the tags with variables
     $pattern = str_replace($tags, $placeholders, $text);
     // replace the variables with strings
     return vsprintf($pattern, $values);
 }
    /**
     * installs the plugin database tables and default fields
     */
    private function _fresh_install()
    {
        global $wpdb;
        // define the arrays for loading the initial db records
        $this->_define_init_arrays();
        // create the field values table
        $sql = 'CREATE TABLE ' . Participants_Db::$fields_table . ' (
          `id` INT(3) NOT NULL AUTO_INCREMENT,
          `order` INT(3) NOT NULL DEFAULT 0,
          `name` VARCHAR(64) NOT NULL,
          `title` TINYTEXT NOT NULL,
          `default` TINYTEXT NULL,
          `group` VARCHAR(64) NOT NULL,
          `help_text` TEXT NULL,
          `form_element` TINYTEXT NULL,
          `values` LONGTEXT NULL,
          `validation` TINYTEXT NULL,
          `display_column` INT(3) DEFAULT 0,
          `admin_column` INT(3) DEFAULT 0,
          `sortable` BOOLEAN DEFAULT 0,
          `CSV` BOOLEAN DEFAULT 0,
          `persistent` BOOLEAN DEFAULT 0,
          `signup` BOOLEAN DEFAULT 0,
					`readonly` BOOLEAN DEFAULT 0,
          UNIQUE KEY  ( `name` ),
          INDEX  ( `order` ),
          INDEX  ( `group` ),
          PRIMARY KEY  ( `id` )
          )
          DEFAULT CHARACTER SET utf8
          COLLATE utf8_unicode_ci
          AUTO_INCREMENT = 0
          ';
        $wpdb->query($sql);
        // create the groups table
        $sql = 'CREATE TABLE ' . Participants_Db::$groups_table . ' (
          `id` INT(3) NOT NULL AUTO_INCREMENT,
          `order` INT(3) NOT NULL DEFAULT 0,
          `display` BOOLEAN DEFAULT 1,
          `admin` BOOLEAN NOT NULL DEFAULT 0,
          `title` TINYTEXT NOT NULL,
          `name` VARCHAR(64) NOT NULL,
          `description` TEXT NULL,
          UNIQUE KEY ( `name` ),
          PRIMARY KEY ( `id` )
          )
          DEFAULT CHARACTER SET utf8
          COLLATE utf8_unicode_ci
          AUTO_INCREMENT = 1
          ';
        $wpdb->query($sql);
        // create the main data table
        $sql = 'CREATE TABLE ' . Participants_Db::$participants_table . ' (
          `id` int(6) NOT NULL AUTO_INCREMENT,
          `private_id` VARCHAR(9) NULL,
          ';
        foreach (array_keys(self::$field_groups) as $group) {
            // these are not added to the sql in the loop
            if ($group == 'internal') {
                continue;
            }
            foreach (self::${$group . '_fields'} as $name => &$defaults) {
                if (!isset($defaults['form_element'])) {
                    $defaults['form_element'] = 'text-line';
                }
                $datatype = PDb_FormElement::get_datatype($defaults['form_element']);
                $sql .= '`' . $name . '` ' . $datatype . ' NULL, ';
            }
        }
        $sql .= '`date_recorded` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
          `date_updated` TIMESTAMP NULL DEFAULT NULL,
          `last_accessed` TIMESTAMP NULL DEFAULT NULL,
          PRIMARY KEY  (`id`)
          )
          DEFAULT CHARACTER SET utf8
          COLLATE utf8_unicode_ci
          ;';
        $wpdb->query($sql);
        // save the db version
        add_option(Participants_Db::$db_version_option);
        update_option(Participants_Db::$db_version_option, Participants_Db::$db_version);
        // now load the default values into the database
        $i = 0;
        unset($defaults);
        foreach (array_keys(self::$field_groups) as $group) {
            foreach (self::${$group . '_fields'} as $name => $defaults) {
                $defaults['name'] = $name;
                $defaults['group'] = $group;
                $defaults['order'] = $i;
                $defaults['validation'] = isset($defaults['validation']) ? $defaults['validation'] : 'no';
                if (isset($defaults['values']) && is_array($defaults['values'])) {
                    $defaults['values'] = serialize($defaults['values']);
                }
                $wpdb->insert(Participants_Db::$fields_table, $defaults);
                $i++;
            }
        }
        // put in the default groups
        $i = 1;
        $defaults = array();
        foreach (self::$field_groups as $group => $title) {
            $defaults['name'] = $group;
            $defaults['title'] = $title;
            $defaults['display'] = in_array($group, array('internal', 'admin', 'source')) ? 0 : 1;
            $defaults['order'] = $i;
            $wpdb->insert(Participants_Db::$groups_table, $defaults);
            $i++;
        }
    }
    /**
     * prints the main body of the list, including headers
     *
     * @param string $mode dtermines the print mode: 'noheader' skips headers, (other choices to be determined)
     */
    private static function _main_table($mode = '')
    {
        $hscroll = Participants_Db::plugin_setting_is_true('admin_horiz_scroll');
        ?>
            <?php 
        if ($hscroll) {
            ?>
            <div class="pdb-horiz-scroll-scroller">
              <div class="pdb-horiz-scroll-width" style="width: <?php 
            echo count(self::$display_columns) * 10;
            ?>
em">
    <?php 
        }
        ?>
        <table class="wp-list-table widefat fixed pages pdb-list stuffbox" cellspacing="0" >
          <?php 
        $PID_pattern = '<td><a href="%2$s">%1$s</a></td>';
        //template for outputting a column
        $col_pattern = '<td>%s</td>';
        if (count(self::$participants) > 0) {
            if ($mode != 'noheader') {
                ?>
              <thead>
                <tr>
        <?php 
                self::_print_header_row();
                ?>
                </tr>
              </thead>
              <?php 
            }
            // table header row
            // print the table footer row if there is a long list
            if ($mode != 'noheader' && count(self::$participants) > 10) {
                ?>
              <tfoot>
                <tr>
        <?php 
                self::_print_header_row();
                ?>
                </tr>
              </tfoot>
              <?php 
            }
            // table footer row
            ?>
            <tbody>
            <?php 
            // output the main list
            foreach (self::$participants as $value) {
                ?>
                <tr>
        <?php 
                // print delete check
                ?>
                  <td>
                          <?php 
                if (current_user_can(Participants_Db::plugin_capability('plugin_admin_capability', 'delete participants'))) {
                    ?>
                            <input type="checkbox" class="delete-check" name="pid[]" value="<?php 
                    echo $value['id'];
                    ?>
" />
                    <?php 
                }
                ?>
                            <a href="admin.php?page=<?php 
                echo 'participants-database';
                ?>
-edit_participant&amp;action=edit&amp;id=<?php 
                echo $value['id'];
                ?>
" title="<?php 
                _e('Edit', 'participants-database');
                ?>
"><span class="glyphicon glyphicon-edit"></span></a>
                  </td>
              <?php 
                foreach (self::$display_columns as $column) {
                    // this is where we place form-element-specific text transformations for display
                    switch ($column->form_element) {
                        case 'image-upload':
                            $image_params = array('filename' => basename($value[$column->name]), 'link' => '', 'mode' => Participants_Db::plugin_setting_is_true('admin_thumbnails') ? 'image' : 'filename');
                            if (Participants_Db::is_single_record_link($column)) {
                                $page_link = get_permalink(Participants_Db::plugin_setting('single_record_page'));
                                $image_params['link'] = Participants_Db::add_uri_conjunction($page_link) . 'pdb=' . $value['id'];
                            }
                            // this is to display the image as a linked thumbnail
                            $image = new PDb_Image($image_params);
                            $display_value = $image->get_image_html();
                            break;
                        case 'date':
                        case 'timestamp':
                            if (!empty($value[$column->name])) {
                                $format = Participants_Db::$date_format;
                                if (Participants_Db::plugin_setting_is_true('show_time') and $column->form_element == 'timestamp') {
                                    // replace spaces with &nbsp; so the time value stays together on a broken line
                                    $format .= ' ' . str_replace(' ', '&\\nb\\sp;', get_option('time_format'));
                                }
                                $time = Participants_Db::is_valid_timestamp($value[$column->name]) ? (int) $value[$column->name] : Participants_Db::parse_date($value[$column->name], $column->name, $column->form_element == 'date');
                                $display_value = $value[$column->name] == '0000-00-00 00:00:00' ? '' : date_i18n($format, $time);
                                //$display_value = date_i18n($format, $time);
                            } else {
                                $display_value = '';
                            }
                            break;
                        case 'multi-select-other':
                        case 'multi-checkbox':
                            // multi selects are displayed as comma separated lists
                            $column->value = $value[$column->name];
                            $display_value = PDb_FormElement::get_field_value_display($column, false);
                            //$display_value = is_serialized($value[$column->name]) ? implode(', ', unserialize($value[$column->name])) : $value[$column->name];
                            break;
                        case 'link':
                            $link_value = maybe_unserialize($value[$column->name]);
                            if (count($link_value) === 1) {
                                $link_value = array_fill(0, 2, current((array) $link_value));
                            }
                            $display_value = Participants_Db::make_link($link_value[0], $link_value[1]);
                            break;
                        case 'rich-text':
                            if (!empty($value[$column->name])) {
                                $display_value = '<span class="textarea">' . $value[$column->name] . '</span>';
                            } else {
                                $display_value = '';
                            }
                            break;
                        case 'text-line':
                            if (Participants_Db::is_single_record_link($column)) {
                                $url = get_permalink(Participants_Db::plugin_setting('single_record_page'));
                                $template = '<a href="%1$s" >%2$s</a>';
                                $delimiter = false !== strpos($url, '?') ? '&' : '?';
                                $url = $url . $delimiter . 'pdb=' . $value['id'];
                                $display_value = sprintf($template, $url, $value[$column->name]);
                            } elseif (Participants_Db::plugin_setting_is_true('make_links')) {
                                $field = new stdClass();
                                $field->value = $value[$column->name];
                                $display_value = PDb_FormElement::make_link($field);
                            } else {
                                $display_value = $value[$column->name] === '' ? $column->default : esc_html($value[$column->name]);
                            }
                            break;
                        case 'hidden':
                            $display_value = $value[$column->name] === '' ? '' : esc_html($value[$column->name]);
                            break;
                        default:
                            $column->value = $value[$column->name];
                            $display_value = PDb_FormElement::get_field_value_display($column, false);
                    }
                    if ($column->name === 'private_id' && Participants_Db::plugin_setting_is_set('registration_page')) {
                        printf($PID_pattern, $display_value, Participants_Db::get_record_link($display_value));
                    } else {
                        printf($col_pattern, $display_value);
                    }
                }
                ?>
                </tr>
                <?php 
            }
            ?>
            </tbody>

              <?php 
        } else {
            // if there are no records to show; do this
            ?>
            <tbody>
              <tr>
                <td><?php 
            _e('No records found', 'participants-database');
            ?>
</td>
              </tr>
            </tbody>
              <?php 
        }
        // participants array
        ?>
        </table>
                  <?php 
        if ($hscroll) {
            ?>
              </div>
            </div>
    <?php 
        }
        ?>
      </form>
              <?php 
    }
Example #16
0
 public function sort_form($print = true)
 {
     $element = array('type' => 'dropdown', 'name' => 'sortBy', 'value' => $this->get_first_in_list($this->filter['sortBy']), 'options' => array('null_select' => true) + $this->sortables, 'class' => 'search-item');
     $output[] = PDb_FormElement::get_element($element);
     $element = array('type' => 'radio', 'name' => 'ascdesc', 'value' => strtoupper($this->get_first_in_list($this->filter['ascdesc'])), 'class' => 'checkbox inline search-item', 'options' => array(__('Ascending', 'participants-database') => 'ASC', __('Descending', 'participants-database') => 'DESC'));
     $output[] = PDb_FormElement::get_element($element);
     $output[] = '<input name="submit_button" type="submit" value="' . $this->i18n['sort'] . '" />';
     if ($print) {
         echo $this->output_HTML($output);
     } else {
         return $this->output_HTML($output);
     }
 }
 /**
  * prints the element
  */
 public function _print()
 {
     PDb_FormElement::print_element(array('type' => $this->form_element, 'value' => $this->value, 'name' => $this->name, 'options' => $this->values, 'class' => $this->field_class, 'attributes' => $this->attributes, 'module' => $this->module));
 }
Example #18
0
 public function print_submit_button($class = 'button-primary', $value = false)
 {
     PDb_FormElement::print_element(array('type' => 'submit', 'value' => $value === false ? $this->options['signup_button_text'] : $value, 'name' => 'submit_button', 'class' => $class . ' pdb-submit', 'module' => $this->module));
 }
 /** 
  * returns a form element
  *
  * @param array $parameters (same as __construct() )
  * @static
  */
 public static function get_element($parameters)
 {
     $Element = new PDb_FormElement($parameters);
     return $Element->_output();
 }
 /**
  * prints a settings form element
  *
  * @access public because it's called by WP
  *
  * @param array $input
  *    name - setting slug (required)
  *    type - the type of form element to use
  *    value - the current value of the field
  *    help_text - extra text for the setting page
  *    options - if an array type setting, the values of the settings, array
  *    attributes - any additional attributes to add
  *    class - a CSS class name to add
  */
 public function print_settings_field($input)
 {
     //error_log(__METHOD__.' name:'.$input['name'].' type:'.$input['type'].' title:'.$input['title']);
     if (!isset($input['name'])) {
         return NULL;
     }
     if ($input['type'] == 'header') {
         //echo '<h3>' . $input['title'] . '</h3>';
     } else {
         $options = get_option($this->WP_setting);
         $args = wp_parse_args($input, array('options' => false, 'attributes' => '', 'value' => ''));
         // supply the value of the field from the saved option or the default as defined in the settings init
         $args['value'] = isset($options[$input['name']]) ? $options[$input['name']] : $args['value'];
         $args['name'] = $this->WP_setting . '[' . $input['name'] . ']';
         PDb_FormElement::print_element($args);
         if (!empty($args['help_text'])) {
             printf($this->help_text_wrap, trim($args['help_text']));
         }
     }
 }
    /**
     * displays a settings page form using the WP Settings API
     *
     * this function is called by the plugin on it's settings page
     *
     * @return null
     */
    public function show_settings_form()
    {
        ?>
    <div class="wrap participants_db settings-class">
      <?php 
        Participants_Db::admin_page_heading(Participants_Db::$plugin_title . ' ' . __('Settings', 'participants-database'));
        ?>
      <?php 
        settings_errors();
        ?>
      <form action="options.php" method="post" >
        <div class="ui-tabs">
          <?php 
        /* ?>
           <h2 class="nav-tab-wrapper">
             <?php foreach ($this->sections as $id => $title)
               printf('<a class="nav-tab" href="#%s">%s</a>', Participants_Db::make_anchor($id), $title);
             ?>
           </h2>
           <?php */
        ?>
          <ul class="ui-tabs-nav">
            <?php 
        foreach ($this->sections as $id => $title) {
            printf('<li><a href="#%s">%s</a></li>', Participants_Db::make_anchor($id), $title);
        }
        ?>
          </ul>
          <?php 
        settings_fields($this->WP_setting);
        do_settings_sections($this->settings_page);
        ?>
        </div>

        <?php 
        $args = array('type' => 'submit', 'class' => $this->submit_class, 'value' => $this->submit_button, 'name' => 'submit');
        printf($this->submit_wrap, PDb_FormElement::get_element($args));
        ?>
      </form>

    </div>
    <?php 
    }
 /**
  * 
  * prints a formatted field value
  * 
  * @var string $name name of the field to print
  */
 public function _print($name)
 {
     if (isset($this->fields->{$name})) {
         echo PDb_FormElement::get_field_value_display($this->fields->{$name});
     }
 }
Example #23
0
                    break;
                case 'hidden':
                    $column->form_element = 'text-line';
                    break;
                case 'timestamp':
                    if (Participants_Db::import_timestamp($column->value) === false) {
                        $column->value = '';
                    }
                    break;
            }
        }
        if ('rich-text' == $column->form_element) {
            wp_editor($column->value, preg_replace('#[0-9_-]#', '', Participants_Db::$prefix . $column->name), array('media_buttons' => false, 'textarea_name' => $column->name, 'editor_class' => $field_class));
        } else {
            $params = array('type' => $column->form_element, 'value' => $column->value, 'name' => $column->name, 'options' => $column->values, 'class' => $field_class, 'attributes' => $attributes, 'module' => 'admin-edit');
            PDb_FormElement::print_element($params);
        }
        if (!empty($column->help_text)) {
            ?>
                <span class="helptext"><?php 
            echo stripslashes(trim($column->help_text));
            ?>
</span>
    <?php 
        }
        ?>
            </td>
          </tr>
          <?php 
    }
    ?>
 /**
  * builds a dropdown setting element
  * 
  * @param array $values array of setting values
  * 
  * @return string HTML
  */
 protected function _build_dropdown($values)
 {
     $selectstring = $this->set_selectstring($values[1]);
     $html = '';
     $pattern = "\n" . '<option %9$s value="%4$s" ><span>%5$s</span></option>';
     $html .= "\n" . '<div class="dropdown-group ' . $values[1] . ' ' . $values[4] . '" ><select name="' . $this->settings_name() . '[' . $values[0] . ']" >';
     if (PDb_FormElement::is_assoc($values[7])) {
         foreach ($values[7] as $name => $title) {
             $values[8] = $name == $values[2] ? $selectstring : '';
             $values[3] = $name;
             $values[4] = $title;
             $html .= vsprintf($pattern, $values);
         }
     } else {
         foreach ($values[7] as $value) {
             $values[8] = $value == $values[2] ? $selectstring : '';
             $values[3] = $value;
             $values[4] = $value;
             $html .= vsprintf($pattern, $values);
         }
     }
     $html .= "\n" . '</select></div>';
     if (!empty($values[6])) {
         $html .= "\n" . '<p class="description">' . $values[6] . '</p>';
     }
     return $html;
 }