AdminPage.Menu.class.php
4 years ago
AdminPage.Submenu.class.php
4 years ago
AdminPage.Themes.class.php
4 years ago
AdminPage.class.php
4 years ago
AdminPageSection.class.php
4 years ago
AdminPageSetting.Address.class.php
4 years ago
AdminPageSetting.Checkbox.class.php
4 years ago
AdminPageSetting.ColorPicker.class.php
4 years ago
AdminPageSetting.Count.class.php
4 years ago
AdminPageSetting.Editor.class.php
4 years ago
AdminPageSetting.FileUpload.class.php
4 years ago
AdminPageSetting.HTML.class.php
4 years ago
AdminPageSetting.Image.class.php
4 years ago
AdminPageSetting.InfiniteTable.class.php
4 years ago
AdminPageSetting.McApiKey.class.php
4 years ago
AdminPageSetting.McListMerge.class.php
4 years ago
AdminPageSetting.Number.class.php
4 years ago
AdminPageSetting.OpeningHours.class.php
4 years ago
AdminPageSetting.Ordering.class.php
4 years ago
AdminPageSetting.Radio.class.php
4 years ago
AdminPageSetting.Scheduler.class.php
4 years ago
AdminPageSetting.Select.class.php
4 years ago
AdminPageSetting.SelectMenu.class.php
4 years ago
AdminPageSetting.SelectPost.class.php
4 years ago
AdminPageSetting.SelectTaxonomy.class.php
4 years ago
AdminPageSetting.Text.class.php
4 years ago
AdminPageSetting.Textarea.class.php
4 years ago
AdminPageSetting.Time.class.php
4 years ago
AdminPageSetting.Toggle.class.php
4 years ago
AdminPageSetting.WarningTip.class.php
4 years ago
AdminPageSetting.class.php
4 years ago
Library.class.php
4 years ago
AdminPageSetting.InfiniteTable.class.php
216 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Register, display and save an option with multiple checkboxes. |
| 5 | * |
| 6 | * This setting accepts the following arguments in its constructor function. |
| 7 | * |
| 8 | * $args = array( |
| 9 | * 'id' => 'setting_id', // Unique id |
| 10 | * 'title' => 'My Setting', // Title or label for the setting |
| 11 | * 'add_label' => 'Add Row', // Text for the "Add Row" button |
| 12 | * 'description' => 'Description', // Help text description |
| 13 | * 'fields' => array( |
| 14 | * 'field' => array( |
| 15 | * 'type' => 'text' //text, select |
| 16 | * 'label' => 'Name' |
| 17 | * 'required' => false, |
| 18 | * 'options' => array() |
| 19 | * ) |
| 20 | * ) // The attributes and labels for the fields |
| 21 | * ); |
| 22 | * |
| 23 | * @since 2.0 |
| 24 | * @package Simple Admin Pages |
| 25 | */ |
| 26 | |
| 27 | class sapAdminPageSettingInfiniteTable_2_6_1 extends sapAdminPageSetting_2_6_1 { |
| 28 | |
| 29 | public $sanitize_callback = 'sanitize_textarea_field'; |
| 30 | |
| 31 | /** |
| 32 | * Add in the JS requried for rows to be added and the values to be stored |
| 33 | * @since 2.0 |
| 34 | */ |
| 35 | public $scripts = array( |
| 36 | 'sap-infinite-table' => array( |
| 37 | 'path' => 'js/infinite_table.js', |
| 38 | 'dependencies' => array( 'jquery' ), |
| 39 | 'version' => SAP_VERSION, |
| 40 | 'footer' => true, |
| 41 | ), |
| 42 | ); |
| 43 | |
| 44 | /** |
| 45 | * Add in the CSS requried for rows to be displayed correctly |
| 46 | * @since 2.0 |
| 47 | */ |
| 48 | public $styles = array( |
| 49 | 'sap-infinite-table' => array( |
| 50 | 'path' => 'css/infinite_table.css', |
| 51 | 'dependencies' => array( ), |
| 52 | 'version' => SAP_VERSION, |
| 53 | 'media' => 'all', |
| 54 | ), |
| 55 | ); |
| 56 | |
| 57 | /** |
| 58 | * Display this setting |
| 59 | * @since 2.0 |
| 60 | */ |
| 61 | public function display_setting() { |
| 62 | |
| 63 | $input_name = $this->get_input_name(); |
| 64 | $values = json_decode( html_entity_decode( $this->value ) ); |
| 65 | |
| 66 | if ( ! is_array( $values ) ) |
| 67 | $values = array(); |
| 68 | |
| 69 | $fields = ''; |
| 70 | foreach ($this->fields as $field_id => $field) { |
| 71 | $fields .= $field_id . ","; |
| 72 | } |
| 73 | $fields = trim($fields, ','); |
| 74 | |
| 75 | ?> |
| 76 | |
| 77 | <fieldset <?php $this->print_conditional_data(); ?>> |
| 78 | <div class='sap-infinite-table <?php echo ( $this->disabled ? 'disabled' : ''); ?>' data-fieldids='<?php echo $fields; ?>'> |
| 79 | <input type='hidden' id="sap-infinite-table-main-input" name='<?php echo $input_name; ?>' value='<?php echo $this->value; ?>' /> |
| 80 | <table> |
| 81 | <thead> |
| 82 | <tr> |
| 83 | <?php foreach ($this->fields as $field) { ?> |
| 84 | <th><?php echo $field['label']; ?></th> |
| 85 | <?php } ?> |
| 86 | <th></th> |
| 87 | </tr> |
| 88 | </thead> |
| 89 | <tbody> |
| 90 | <?php foreach ($values as $row) { ?> |
| 91 | <tr class='sap-infinite-table-row'> |
| 92 | <?php foreach ($this->fields as $field_id => $field) { ?> |
| 93 | <td data-field-type="<?php echo $field['type']; ?>" > |
| 94 | <?php if ($field['type'] == 'id') : ?> |
| 95 | <span class='sap-infinite-table-id-html'><?php echo $row->$field_id; ?></span> |
| 96 | <input type='hidden' data-name='<?php echo $field_id; ?>' value='<?php echo $row->$field_id; ?>' /> |
| 97 | <?php endif; ?> |
| 98 | <?php if ($field['type'] == 'text') : ?> |
| 99 | <input type='text' data-name='<?php echo $field_id; ?>' value='<?php echo $row->$field_id; ?>' /> |
| 100 | <?php endif; ?> |
| 101 | <?php if ($field['type'] == 'textarea') : ?> |
| 102 | <textarea data-name='<?php echo $field_id; ?>'><?php echo $row->$field_id; ?></textarea> |
| 103 | <?php endif; ?> |
| 104 | <?php if ($field['type'] == 'number') : ?> |
| 105 | <input type='number' data-name='<?php echo $field_id; ?>' value='<?php echo $row->$field_id; ?>' /> |
| 106 | <?php endif; ?> |
| 107 | <?php if ($field['type'] == 'hidden') : ?> |
| 108 | <span class='sap-infinite-table-hidden-value'><?php echo $row->$field_id; ?></span> |
| 109 | <input type='hidden' data-name='<?php echo $field_id; ?>' value='<?php echo $row->$field_id; ?>' /> |
| 110 | <?php endif; ?> |
| 111 | <?php if ($field['type'] == 'select') : ?> |
| 112 | <select data-name='<?php echo $field_id; ?>'> |
| 113 | <?php if ( ! empty( $field['blank_option'] ) ) { ?><option></option><?php } ?> |
| 114 | <?php $this->print_options( $field['options'], $row, $field_id ); ?> |
| 115 | </select> |
| 116 | <?php endif; ?> |
| 117 | <?php if ($field['type'] == 'toggle') : ?> |
| 118 | <label class="sap-admin-switch"> |
| 119 | <input type="checkbox" class="sap-admin-option-toggle" data-name="<?php echo $field_id; ?>" <?php if( $row->$field_id == '1' ) {echo "checked='checked'";} ?> > |
| 120 | <span class="sap-admin-switch-slider round"></span> |
| 121 | </label> |
| 122 | <?php endif; ?> |
| 123 | </td> |
| 124 | <?php } ?> |
| 125 | <td class='sap-infinite-table-row-delete'><?php echo $this->del_label; ?></td> |
| 126 | </tr> |
| 127 | <?php } ?> |
| 128 | </tbody> |
| 129 | <tfoot> |
| 130 | <tr class='sap-infinite-table-row-template sap-hidden'> |
| 131 | <?php foreach ($this->fields as $field_id => $field) { ?> |
| 132 | <td data-field-type="<?php echo $field['type']; ?>" > |
| 133 | <?php if ($field['type'] == 'id') : ?> |
| 134 | <span class='sap-infinite-table-id-html'></span> |
| 135 | <input type='hidden' data-name='<?php echo $field_id; ?>' value='' /> |
| 136 | <?php endif; ?> |
| 137 | <?php if ($field['type'] == 'text') : ?> |
| 138 | <input type='text' data-name='<?php echo $field_id; ?>' value='' /> |
| 139 | <?php endif; ?> |
| 140 | <?php if ($field['type'] == 'textarea') : ?> |
| 141 | <textarea data-name='<?php echo $field_id; ?>'></textarea> |
| 142 | <?php endif; ?> |
| 143 | <?php if ($field['type'] == 'number') : ?> |
| 144 | <input type='number' data-name='<?php echo $field_id; ?>' value='' /> |
| 145 | <?php endif; ?> |
| 146 | <?php if ($field['type'] == 'hidden') : ?> |
| 147 | <span class='sap-infinite-table-hidden-value'></span> |
| 148 | <input type='hidden' data-name='<?php echo $field_id; ?>' value='' /> |
| 149 | <?php endif; ?> |
| 150 | <?php if ($field['type'] == 'select') : ?> |
| 151 | <select data-name='<?php echo $field_id; ?>'> |
| 152 | <?php if ( ! empty( $field['blank_option'] ) ) { ?><option></option><?php } ?> |
| 153 | <?php $this->print_options( $field['options'] ); ?> |
| 154 | </select> |
| 155 | <?php endif; ?> |
| 156 | <?php if ($field['type'] == 'toggle') : ?> |
| 157 | <label class="sap-admin-switch"> |
| 158 | <input type="checkbox" class="sap-admin-option-toggle" data-name="<?php echo $field_id; ?>" checked > |
| 159 | <span class="sap-admin-switch-slider round"></span> |
| 160 | </label> |
| 161 | <?php endif; ?> |
| 162 | </td> |
| 163 | <?php } ?> |
| 164 | <td class='sap-infinite-table-row-delete'><?php echo $this->del_label; ?></td> |
| 165 | </tr> |
| 166 | <tr class='sap-infinite-table-add-row'> |
| 167 | <td colspan="<?php echo count( $this->fields ) ?>"> |
| 168 | <a class="sap-new-admin-add-button"><?php echo $this->add_label; ?></a> |
| 169 | </td> |
| 170 | </tr> |
| 171 | </tfoot> |
| 172 | </table> |
| 173 | </div> |
| 174 | |
| 175 | <?php $this->display_disabled(); ?> |
| 176 | </fieldset> |
| 177 | |
| 178 | <?php |
| 179 | |
| 180 | $this->display_description(); |
| 181 | |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Recursively print out select options |
| 186 | * @since 2.5.3 |
| 187 | */ |
| 188 | public function print_options( $options, $row = false, $field_id = 0 ) { |
| 189 | |
| 190 | foreach ( $options as $option_value => $option_name ) { |
| 191 | |
| 192 | if ( is_array( $option_name ) ) { ?> |
| 193 | |
| 194 | <optgroup label='<?php echo esc_attr( $option_value ); ?>'> |
| 195 | <?php $this->print_options( $option_name, $row, $field_id ); ?> |
| 196 | </optgroup> |
| 197 | |
| 198 | <?php |
| 199 | |
| 200 | continue; |
| 201 | } |
| 202 | |
| 203 | $selected_value = $row ? $row->$field_id : false; |
| 204 | |
| 205 | ?> |
| 206 | |
| 207 | <option value='<?php echo $option_value; ?>' <?php echo ($selected_value == $option_value ? 'selected="selected"' : ''); ?>> |
| 208 | <?php echo $option_name; ?> |
| 209 | </option> |
| 210 | |
| 211 | <?php |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | } |
| 216 |