Exemplo n.º 1
0
 }
 $field_class = ($column->validation != 'no' ? "required-field" : '') . (in_array($column->form_element, array('text-line', 'date')) ? ' regular-text' : '');
 if (isset($column->value)) {
     //error_log(basename(__FILE__) . ' ' . $column->name . ':' . $column->value);
     //                if ($column->name == 'last_accessed' && (!isset($column->value) or '0000-00-00 00:00:00' == $column->value ))
     //                  $column->value = false;
     switch ($column->form_element) {
         //                  case 'timestamp':
         case 'date':
             /*
              * if it's not a timestamp, format it for display; if it is a
              * timestamp, it will be formatted by the xnau_FormElement class
              */
             if (!empty($column->value)) {
                 //$column->value = xnau_FormElement::get_field_value_display($column);
                 $column->value = Participants_Db::parse_date($column->value);
             }
             break;
         case 'image-upload':
             $column->value = empty($column->value) ? '' : $column->value;
             break;
         case 'multi-select-other':
         case 'multi-checkbox':
             $column->value = is_array($column->value) ? $column->value : explode(',', $column->value);
             break;
         case 'password':
             $column->value = '';
             break;
         case 'hidden':
             $column->form_element = 'text-line';
             break;
 /**
  * returns an internationalized date string from a UNIX timestamp
  * 
  * @param int $timestamp a UNIX timestamp
  * @param bool $time if true, adds the time of day to the format
  * @return string a formatted date or input string if invalid
  */
 public static function format_date($timestamp, $time = false)
 {
     // if it's not a timestamp, we attempt to convert it to one
     if (!Participants_Db::is_valid_timestamp($timestamp)) {
         $timestamp = Participants_Db::parse_date($timestamp);
     }
     if (Participants_Db::is_valid_timestamp($timestamp)) {
         $format = Participants_Db::plugin_setting_is_true('strict_dates') ? Participants_Db::plugin_setting('input_date_format') : Participants_Db::$date_format;
         if ($time) {
             $format .= ' ' . get_option('time_format');
         }
         return date_i18n($format, $timestamp);
     } else {
         // not a timestamp: return unchanged
         return $timestamp;
     }
 }
 /**
  * adds a List_Query_Filter object to the where clauses
  * 
  * @param string $column      the name of the field to target
  * @param string $operator     the operator
  * @param string $search_term the term to filter by
  * @param string $logic       the logic term to add to the array
  * @param bool   $shortcode   true if the current filter is from the shortcode
  * @return null
  */
 private function _add_single_statement($column, $operator, $search_term = '', $logic = 'AND', $shortcode = false)
 {
     /*
      * don't add an 'id = 0' clause if there is a user search. This gives us a 
      * way to create a "search results only" list if the shortcode contains 
      * a filter for 'id=0'
      * 
      * we flag it for suppression. Later, if there is no other clause for the ID 
      * column, the list display will be suppressed
      */
     if ($column == 'id' and $search_term == '0') {
         $this->suppress = true;
         return false;
     }
     /*
      * if the column is not valid skip this statement
      */
     if (!Participants_Db::is_column($column)) {
         return false;
     }
     $field_atts = Participants_Db::get_column($column);
     $filter = new PDb_List_Query_Filter(array('field' => $column, 'logic' => $logic, 'shortcode' => $shortcode, 'term' => trim(urldecode($search_term)), 'index' => $this->clause_index));
     $this->increment_clause_index();
     $statement = false;
     /*
      * set up special-case field types
      */
     if (in_array($field_atts->form_element, array('date', 'timestamp')) and $filter->is_string_search()) {
         /*
          * if we're dealing with a date element, the target value needs to be 
          * conditioned to get a correct comparison
          */
         $search_term = Participants_Db::parse_date($filter->get_raw_term(), $field_atts);
         // if we don't get a valid date, skip this statement
         if ($search_term === false) {
             return false;
         }
         $operator = in_array($operator, array('>', '<')) ? $operator : '=';
         if ($field_atts->form_element == 'timestamp') {
             //$statement = 'DATE(p.' . $column . ') ' . $operator . ' CONVERT_TZ(FROM_UNIXTIME(' . $search_term . '), @@session.time_zone, "+00:00") ';
             $statement = 'DATE(p.' . $column . ') ' . $operator . ' DATE(FROM_UNIXTIME(' . $search_term . ')) ';
         } else {
             $statement = 'p.' . $column . ' ' . $operator . ' CAST(' . $search_term . ' AS SIGNED)';
         }
     } elseif ($filter->is_empty_search()) {
         if ($operator === 'NOT LIKE' or $operator === '!') {
             $pattern = '(p.%1$s IS NOT NULL AND p.%1$s <> "")';
         } else {
             $pattern = '(p.%1$s IS NULL OR p.%1$s = "")';
         }
         $statement = sprintf($pattern, $column);
     } else {
         if ($operator === NULL) {
             $operator = 'LIKE';
         }
         $delimiter = array('"', '"');
         /*
          * set the operator and delimiters
          */
         switch ($operator) {
             case '~':
             case 'LIKE':
                 $operator = 'LIKE';
                 $delimiter = $filter->wildcard_present() ? array('"', '"') : array('"%', '%"');
                 break;
             case '!':
             case 'NOT LIKE':
                 $operator = 'NOT LIKE';
                 $delimiter = $filter->wildcard_present() ? array('"', '"') : array('"%', '%"');
                 break;
             case 'ne':
             case '!=':
             case '<>':
                 $operator = '<>';
                 break;
             case 'eq':
             case '=':
                 /*
                  * if the field's exact value will be found in an array (actually a 
                  * serialized array), we must prepare a special statement to search 
                  * for the double quotes surrounding the value in the serialization
                  */
                 if (in_array($field_atts->form_element, array('multi-checkbox', 'multi-select-other', 'link', 'array'))) {
                     $delimiter = array('\'%"', '"%\'');
                     $operator = 'LIKE';
                     /* 
                      * this is so the search term will be treated as a comparison string 
                      * in a LIKE statement
                      */
                     $filter->like_term = true;
                 } elseif ($filter->wildcard_present()) {
                     $operator = 'LIKE';
                 } else {
                     $operator = '=';
                 }
                 break;
             case 'gt':
             case '>':
                 $operator = '>=';
                 break;
             case 'lt':
             case '<':
                 $operator = '<';
                 break;
             default:
                 // invalid operator: don't add the statement
                 return false;
         }
         $statement = sprintf('p.%s %s %s%s%s', $column, $operator, $delimiter[0], $filter->get_term(), $delimiter[1]);
     }
     if ($statement) {
         $filter->update_parameters(array('statement' => $statement));
         $this->subclauses[$column][] = $filter;
     }
 }
 /**
  * print a date string from a UNIX timestamp
  * 
  * @param int|string $value timestamp or date string
  * @param string $format format to use to override plugin settings
  * @param bool $print if true, echo the output
  * @return string formatted date value
  */
 public function show_date($value, $format = false, $print = true)
 {
     $time = Participants_Db::is_valid_timestamp($value) ? $value : Participants_Db::parse_date($value);
     $dateformat = $format ? $format : Participants_Db::$date_format;
     if ($print) {
         echo date_i18n($dateformat, $time);
     } else {
         return date_i18n($dateformat, $time);
     }
 }
 /**
  * processes an incoming timestamp
  * 
  * timestamps are usually handled by the plugin automatically, but when records 
  * are being imported via CSV, they should be imported
  * 
  * @var string $timestamp a timestamp value, could be unix timestamp or text date
  * @return bool|string if the timestamp is valid, a MySQL timestamp is returns; 
  *                     bool false otherwise
  */
 public static function import_timestamp($timestamp)
 {
     $post_date = $timestamp !== null ? Participants_Db::parse_date($timestamp) : false;
     $new_value = $post_date !== false ? date('Y-m-d H:i:s', $post_date) : false;
     return $new_value;
 }
Exemplo n.º 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 
    }
 /**
  * maps a sets of values to "tags"in a template, replacing the tags with the values
  * 
  * @param string $text the tag-containing template string
  * @param array  $data array of record values: $name => $value
  * 
  * @return string template with all matching tags replaced with values
  */
 private function replace_tags($text, array $data)
 {
     $values = $tags = array();
     foreach ($data as $name => $value) {
         $tags[] = '[' . $name . ']';
         $values[] = $value;
     }
     // add the "record_link" tag
     if (isset($data['private_id'])) {
         $tags[] = '[record_link]';
         $values[] = Participants_Db::get_record_link($data['private_id']);
     }
     // add the date tag
     $tags[] = '[date]';
     $values[] = date_i18n(Participants_Db::$date_format, Participants_Db::parse_date());
     // add the time tag
     $tags[] = '[time]';
     $values[] = date_i18n(get_option('time_format'), Participants_Db::parse_date());
     $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);
 }
    /**
     * 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 
    }