Example #1
0
 /**
  * Returns table row.
  *
  * @param array $row
  * @param array $formdata
  * @param array $errors (optional)
  *
  * @return string
  */
 public function table_row($row, $formdata, $errors = array())
 {
     if (empty($row['tip'])) {
         $tip = '';
     } else {
         $tip = html("i", array('class' => 'at at-tip', 'data-tooltip' => APP_ToolTips::supports_wp_pointer() ? $row['tip'] : __('Click for more info', APP_TD)));
         if (!APP_ToolTips::supports_wp_pointer()) {
             $tip .= html("div class='tip-content'", $row['tip']);
         }
     }
     if (isset($row['desc'])) {
         $row['desc'] = html('span class="app-description"', $row['desc']);
     }
     $input = scbForms::input($row, $formdata);
     // If row has an error, highlight it
     $style = in_array($row['name'], $errors) ? 'style= "background-color: #FFCCCC"' : '';
     return html('tr', html("th {$style} scope='row'", html('label for="' . esc_attr($row['title']) . '"', $row['title']) . $tip), html("td {$style}", $input));
 }
Example #2
0
 public function table_row($field, $formdata = false)
 {
     if (empty($field['tip'])) {
         $tip = '';
     } else {
         $tip = html('i', array('class' => 'at at-tip', 'data-tooltip' => APP_ToolTips::supports_wp_pointer() ? $field['tip'] : __('Click for more info', APP_TD)));
         if (!APP_ToolTips::supports_wp_pointer()) {
             $tip .= html("div class='tip-content'", $field['tip']);
         }
     }
     if (isset($field['desc'])) {
         // wrap textareas and regular-text fields in <p> tag
         // TODO: doesn't catch wrap_upload() instances for buttons
         if (in_array($field['type'], array('text', 'textarea', 'submit'))) {
             if (!isset($field['extra']['class']) || strpos($field['extra']['class'], 'small-text') === false) {
                 $field['desc'] = html('p class="description"', $field['desc']);
             }
         }
     }
     $input = scbForms::input($field, $formdata);
     // wrap radio buttons in a <fieldset> tag following what WP also does
     if ('radio' == $field['type']) {
         $input = html('fieldset', $input);
     }
     return html("tr", html("th scope='row app-row'", html('label for="' . esc_attr($field['title']) . '"', $field['title']) . $tip), html("td", $input));
 }
Example #3
0
/**
 * Creates a form for adding/editing form layout or form field.
 */
function cp_admin_db_fields($options, $cp_table = '', $cp_id = '')
{
    global $wpdb;
    $action = 'new';
    if ($cp_table) {
        $action = 'edit';
        // gat all the admin fields
        $results = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . $cp_table . " WHERE " . $cp_id . " = %d", $_GET['id']));
        if (!$results) {
            return;
        }
    }
    $field_type = !empty($results->field_type) ? $results->field_type : '';
    $field_perm = !empty($results->field_perm) ? $results->field_perm : '';
    ?>

	<table class="form-table cp-custom">
		<tbody>
<?php 
    foreach ($options as $value) {
        if (empty($value['tip'])) {
            $tooltip = '';
        } else {
            $tooltip = html('i', array('class' => 'dashicons-before tip-icon', 'data-tooltip' => APP_ToolTips::supports_wp_pointer() ? $value['tip'] : __('Click for more info', APP_TD)));
            if (!APP_ToolTips::supports_wp_pointer()) {
                $tooltip .= html("div class='tip-content'", $value['tip']);
            }
        }
        switch ($value['type']) {
            case 'title':
                ?>
					<thead>
						<tr>
							<th scope="col"><?php 
                echo esc_html($value['name']);
                ?>
</th>
							<th class="tip">&nbsp;</th>
							<th scope="col"><?php 
                if (isset($value['desc'])) {
                    echo $value['desc'];
                }
                ?>
&nbsp;</th>
						</tr>
					</thead>
			<?php 
                break;
            case 'text':
                // don't show the meta name field used by WP. This is automatically created by CP.
                if ('new' == $action && $value['id'] == 'field_name') {
                    break;
                }
                $args = array('name' => $value['id'], 'id' => $value['id'], 'type' => $value['type'], 'class' => array(), 'style' => $value['css']);
                if ('edit' == $action) {
                    $args['value'] = $results->{$value}['id'];
                } else {
                    $args['value'] = get_option($value['id']) ? get_option($value['id']) : $value['std'];
                }
                if (!empty($value['req'])) {
                    $args['class'][] = 'required';
                }
                if (!empty($value['altclass'])) {
                    $args['class'][] = $value['altclass'];
                }
                $args['class'] = implode(' ', $args['class']);
                if (!empty($value['min'])) {
                    $args['minlength'] = $value['min'];
                }
                if ($value['id'] == 'field_name') {
                    $args['readonly'] = 'readonly';
                }
                ?>
					<tr <?php 
                echo $value['vis'] == '0' ? 'id="' . ('edit' == $action ? esc_attr($value['id']) . '_row"' : (!empty($value['visid']) ? $value['visid'] : 'field_values')) . '" style="display:none;" ' : 'id="' . esc_attr($value['id']) . '_row"';
                ?>
>
						<th scope="row app-row">
							<label for="<?php 
                esc_attr($value['name']);
                ?>
"><?php 
                echo esc_html($value['name']);
                ?>
</label><?php 
                echo $tooltip;
                ?>
						</th>
						<td>
							<label>
								<?php 
                echo html('input', $args);
                ?>
								<p class="description"><?php 
                echo $value['desc'];
                ?>
</p>
							</label>
						</td>
					</tr>
			<?php 
                break;
            case 'select':
                ?>
					<tr id="<?php 
                echo $value['id'];
                ?>
_row">
						<th scope="row app-row">
							<label for="<?php 
                esc_attr($value['name']);
                ?>
"><?php 
                echo esc_html($value['name']);
                ?>
</label><?php 
                echo $tooltip;
                ?>
						</th>
						<td>
							<label>
								<select <?php 
                if ($value['js']) {
                    echo $value['js'];
                }
                ?>
 <?php 
                disabled(in_array($field_perm, array(1, 2)));
                ?>
 name="<?php 
                echo esc_attr($value['id']);
                ?>
" id="<?php 
                echo esc_attr($value['id']);
                ?>
" style="<?php 
                echo esc_attr($value['css']);
                ?>
">
									<?php 
                foreach ($value['options'] as $key => $val) {
                    ?>
										<?php 
                    if ('edit' == $action) {
                        ?>
											<option value="<?php 
                        echo esc_attr($key);
                        ?>
"<?php 
                        if (isset($results->{$value}['id']) && $results->{$value}['id'] == $key) {
                            selected(true);
                            $field_type_out = $field_type;
                        }
                        ?>
><?php 
                        echo $val;
                        ?>
</option>
										<?php 
                    } else {
                        ?>
											<option value="<?php 
                        echo esc_attr($key);
                        ?>
" <?php 
                        selected(get_option($value['id']) == $key);
                        ?>
><?php 
                        echo $val;
                        ?>
</option>
										<?php 
                    }
                    ?>
									<?php 
                }
                ?>
								</select>
								<p class="description"><?php 
                echo $value['desc'];
                ?>
</p>
								<?php 
                // have to submit this field as a hidden value if perms are 1 or 2 since the DISABLED option won't pass anything into the $_POST
                if (in_array($field_perm, array(1, 2))) {
                    echo html('input', array('type' => 'hidden', 'name' => esc_attr($value['id']), 'value' => esc_attr($field_type_out)));
                }
                ?>
							</label>
						</td>
					</tr>
			<?php 
                break;
            case 'textarea':
                $args = array();
                $args['class'] = array();
                if (!empty($value['altclass'])) {
                    $args['class'][] = $value['altclass'];
                }
                if ('edit' == $action) {
                    $args['value'] = $results->{$value}['id'];
                } else {
                    $args['value'] = get_option($value['id']);
                }
                ?>
					<tr id="<?php 
                echo esc_attr($value['id']);
                ?>
_row"<?php 
                if ($value['id'] == 'field_values') {
                    ?>
 style="display: none;" <?php 
                }
                ?>
>
						<th scope="row app-row">
							<label for="<?php 
                esc_attr($value['name']);
                ?>
"><?php 
                echo esc_html($value['name']);
                ?>
</label><?php 
                echo $tooltip;
                ?>
						</th>
						<td>
							<label>
								<textarea rows="10" cols="50" class="<?php 
                echo implode(' ', $args['class']);
                ?>
" <?php 
                if (!empty($field_perm) && in_array($field_perm, array(1, 2)) && !in_array($value['id'], array('field_tooltip', 'field_values'))) {
                    ?>
readonly="readonly"<?php 
                }
                ?>
 name="<?php 
                echo esc_attr($value['id']);
                ?>
" id="<?php 
                echo esc_attr($value['id']);
                ?>
" style="<?php 
                echo esc_attr($value['css']);
                ?>
"><?php 
                echo esc_textarea($args['value']);
                ?>
</textarea>
								<p class="description"><?php 
                echo $value['desc'];
                ?>
</p>
							</label>
						</td>
					</tr>
			<?php 
                break;
            case 'checkbox':
                if ('edit' == $action) {
                    $args['value'] = $results->{$value}['id'];
                } else {
                    $args['value'] = get_option($value['id']);
                }
                ?>
					<tr id="<?php 
                echo $value['id'];
                ?>
_row">
						<th scope="row app-row">
							<label for="<?php 
                esc_attr($value['name']);
                ?>
"><?php 
                echo esc_html($value['name']);
                ?>
</label><?php 
                echo $tooltip;
                ?>
						</th>
						<td>
							<label>
								<input type="checkbox" name="<?php 
                echo $value['id'];
                ?>
" id="<?php 
                echo $value['id'];
                ?>
" value="1" style="<?php 
                echo $value['css'];
                ?>
" <?php 
                checked(!empty($args['value']));
                ?>
 />
								<p class="description"><?php 
                echo $value['desc'];
                ?>
</p>
							</label>
					</tr>
			<?php 
                break;
            case 'cat_checklist':
                ?>
					<tr id="<?php 
                echo $value['id'];
                ?>
_row">
						<th scope="row app-row">
							<label for="<?php 
                esc_attr($value['name']);
                ?>
"><?php 
                echo esc_html($value['name']);
                ?>
</label><?php 
                echo $tooltip;
                ?>
						</th>
						<td class="forminp">
							<label>
								<div id="form-categorydiv">
									<div class="tabs-panel" id="categories-all" style="<?php 
                echo $value['css'];
                ?>
">
										<ul class="list:category categorychecklist form-no-clear" id="categorychecklist">
											<?php 
                if ('edit' == $action) {
                    ?>
												<?php 
                    echo cp_category_checklist(unserialize($results->form_cats), cp_exclude_cats($results->id));
                    ?>
											<?php 
                } else {
                    ?>
												<?php 
                    $catcheck = cp_category_checklist(0, cp_exclude_cats());
                    ?>
												<?php 
                    if ($catcheck) {
                        echo $catcheck;
                    } else {
                        wp_die('<p style="color:red;">' . __('All your categories are currently being used. You must remove at least one category from another form layout before you can continue.', APP_TD) . '</p>');
                    }
                    ?>
											<?php 
                }
                ?>
										</ul>
									</div>
									<a href="#" class="checkall"><?php 
                _e('check all', APP_TD);
                ?>
</a>
								</div>
								<p class="description"><?php 
                echo $value['desc'];
                ?>
</p>
							</label>
						</td>
					</tr>
			<?php 
                break;
        }
        // end switch
    }
    // endforeach
    ?>
		</tbody>
	</table>
<?php 
}