Пример #1
0
             *
             * if you do this, check out the case below where we make a clickable
             * link: it does the same test so we don't duplicate the field. You'll
             * have to modify that in the same way
             */
            if ($this->field->is_single_record_link()) {
                /*
                 * normally, when a value is empty, nothing is shown...but if the field 
                 * has been designated as the single record link, we must have something 
                 * to click on, so, we use the default value of the field if there is no 
                 * stored value. This makes it possible to create a 'static' link to the 
                 * single record by defining a read-only field with a default value
                 */
                $value = empty($value) ? $this->field->default : $value;
                // add the record ID to the single record link
                $single_record_uri = Participants_Db::add_uri_conjunction($single_record_link) . 'pdb=' . $this->record->record_id;
                /*
                 * print the opening tag of the single record link
                 */
                echo '<a class="single-record-link" href="' . $single_record_uri . '" >';
            }
            ?>

            <?php 
            /*
             * here is where we determine how each field value is presented,
             * depending on what kind of field it is
             */
            switch ($this->field->form_element) {
                case 'image-upload':
                    $image = new PDb_Image(array('filename' => $value, 'mode' => 'image', 'module' => 'list'));
 /**
  * determines if the field should be wrapped in a link and sets the link property of the field object
  * 
  * sets the link property of the field, right now only for the single record link
  * 
  * @param object $field field data object
  */
 protected function _set_field_link($field)
 {
     $link = '';
     //check for single record link
     if (!in_array($this->module, array('single', 'signup')) && Participants_Db::is_single_record_link($field) && isset($this->participant_values['id'])) {
         $url = get_permalink(Participants_Db::plugin_setting('single_record_page'));
         $link = Participants_Db::add_uri_conjunction($url) . 'pdb=' . $this->participant_values['id'];
     }
     $field->link = $link;
 }
Пример #3
0
 /**
  * prints a private link retrieval link
  * 
  * @param string $linktext
  */
 public function print_retrieve_link($linktext = '', $open_tag = '<span class="pdb-retrieve-link">', $close_tag = '</span>')
 {
     $linktext = empty($linktext) ? Participants_Db::$plugin_options['retrieve_link_text'] : $linktext;
     if ($this->options['show_retrieve_link'] != 0) {
         $retrieve_link = $this->options['link_retrieval_page'] !== 'none' ? get_permalink($this->options['link_retrieval_page']) : $_SERVER['REQUEST_URI'];
         echo $open_tag . '<a href="' . Participants_Db::add_uri_conjunction($retrieve_link) . 'm=r">' . $linktext . '</a>' . $close_tag;
     }
 }
 /**
  * outputs a single record link
  *
  * @param string $template an optional template for showing the link
  *
  * @return string the HTML for the single record link
  *
  */
 public function output_single_record_link($template = false)
 {
     $template = $template ? $template : '<a class="single-record-link" href="%1$s" title="%2$s" >%2$s</a>';
     $url = get_permalink(Participants_Db::$plugin_options['single_record_page']);
     $url = Participants_Db::add_uri_conjunction($url) . 'pdb=' . $this->record_id;
     return sprintf($template, $url, empty($this->value) ? $this->default : $this->value);
 }
Пример #5
0
 /**
  * determines if the field should be wrapped in a link and sets the link property of the field object
  * 
  * sets the link property of the field, right now only for the single record link
  * 
  * @param object $field field data object
  */
 protected function _set_field_link($field)
 {
     $link = '';
     //check for single record link
     if (!in_array($this->module, array('single', 'signup')) && isset($this->options['single_record_link_field']) && $field->name == $this->options['single_record_link_field'] && !empty($this->options['single_record_page']) && isset($this->participant_values['id'])) {
         $url = get_permalink($this->options['single_record_page']);
         $link = Participants_Db::add_uri_conjunction($url) . 'pdb=' . $this->participant_values['id'];
     }
     //error_log(__METHOD__.' setting the link to '.$link.' for '.$field->name.' if:'.$this->options['single_record_link_field'].' and '. $this->options['single_record_page'].' with id:'.$this->participant_values['id']);
     $field->link = $link;
 }
Пример #6
0
    /**
     * 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 = '')
    {
        ?>

        <table class="wp-list-table widefat fixed pages pdb-list stuffbox" cellspacing="0" >
          <?php 
        // template for printing the registration page link in the admin
        $PID_pattern = '<td><a href="%2$s">%1$s</a></td>';
        $head_pattern = '
<th class="%2$s" scope="col">
  <span>%1$s</span>
</th>
';
        //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($head_pattern);
                ?>
                </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($head_pattern);
                ?>
                </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_options['plugin_admin_capability'])) {
                    ?>
                      <input type="checkbox" name="pid[]" value="<?php 
                    echo $value['id'];
                    ?>
" onClick="addSelects(this.checked)">
                    <?php 
                }
                ?>
                          <a href="admin.php?page=<?php 
                echo 'participants-database';
                ?>
-edit_participant&action=edit&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' => self::$options['admin_thumbnails'] ? 'image' : 'filename');
                            if (isset(self::$options['single_record_link_field']) && $column->name == self::$options['single_record_link_field'] && !empty(self::$options['single_record_page'])) {
                                $page_link = get_permalink(self::$options['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_options['show_time'] == 1 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
                            $display_value = is_serialized($value[$column->name]) ? implode(', ', unserialize($value[$column->name])) : $value[$column->name];
                            break;
                        case 'link':
                            if (is_serialized($value[$column->name])) {
                                $params = unserialize($value[$column->name]);
                                if (empty($params)) {
                                    $page_link = array('', '');
                                }
                                if (count($params) == 1) {
                                    $params[1] = $params[0];
                                }
                            } else {
                                // in case we got old unserialized data in there
                                $params = array_fill(0, 2, $value[$column->name]);
                            }
                            $display_value = Participants_Db::make_link($params[0], $params[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 (isset(self::$options['single_record_link_field']) && $column->name == self::$options['single_record_link_field'] && !empty(self::$options['single_record_page'])) {
                                $url = get_permalink(self::$options['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 (self::$options['make_links']) {
                                $display_value = Participants_Db::make_link($value[$column->name]);
                            } else {
                                $display_value = NULL === $value[$column->name] ? $column->default : esc_html($value[$column->name]);
                            }
                            break;
                        case 'hidden':
                            $display_value = NULL === $value[$column->name] ? '' : esc_html($value[$column->name]);
                            break;
                        default:
                            $display_value = NULL === $value[$column->name] ? $column->default : esc_html($value[$column->name]);
                    }
                    if ($column->name == 'private_id') {
                        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>
      </form>
              <?php 
    }
    /**
     * 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 
    }
 /**
  * prints a private link retrieval link
  * 
  * @param string $linktext
  */
 public function print_retrieve_link($linktext = '', $open_tag = '<span class="pdb-retrieve-link">', $close_tag = '</span>')
 {
     $linktext = empty($linktext) ? Participants_Db::$plugin_options['retrieve_link_text'] : $linktext;
     if (Participants_Db::plugin_setting_is_true('show_retrieve_link')) {
         $retrieve_link = Participants_Db::plugin_setting('link_retrieval_page') !== 'none' ? get_permalink(Participants_Db::plugin_setting('link_retrieval_page')) : $_SERVER['REQUEST_URI'];
         echo $open_tag . '<a href="' . Participants_Db::add_uri_conjunction($retrieve_link) . 'm=r">' . Participants_Db::set_filter('translate_string', $linktext) . '</a>' . $close_tag;
     }
 }