Example #1
0
function pcud_add_user_fields($fdata, $user_id)
{
    include_once PCUD_DIR . '/functions.php';
    include_once PC_DIR . '/classes/pc_form_framework.php';
    $form_fw = new pc_form();
    $custom_f_indexes = pcud_sorted_fields_indexes();
    if (empty($custom_f_indexes)) {
        return false;
    }
    $code = '
	<h3 style="border: none !important;">User Data add-on - ' . __('custom fields', 'pcud_ml') . '</h3>
	<table class="widefat pc_table pc_add_user" style="margin-bottom: 25px;">
      <tbody>';
    $a = 0;
    foreach ($custom_f_indexes as $f_index) {
        $f = $form_fw->fields[$f_index];
        // user data exists?
        $val = !empty($fdata) && isset($fdata[$f_index]) ? $fdata[$f_index] : false;
        // specific cases
        $placeh = isset($f['placeh']) ? 'placeholder="' . $f['placeh'] . '"' : '';
        // start code
        if (!$a) {
            $code .= '<tr>';
        }
        $left_border = !$a ? '' : 'style="border-left: 1px solid #DFDFDF;"';
        $code .= '<td class="pc_label_td" ' . $left_border . '>' . $f['label'] . '</td>';
        // field type switch
        if ($f['type'] == 'text') {
            $dp_class = $f['subtype'] == 'eu_date' || $f['subtype'] == 'us_date' ? 'class="pcud_datepicker pcud_dp_' . $f['subtype'] . '"' : '';
            $code .= '
			  <td class="pc_field_td">
			  	<input type="' . $f['type'] . '" name="' . $f_index . '" value="' . pc_sanitize_input($val) . '" maxlength="' . $f['maxlen'] . '" ' . $placeh . ' ' . $dp_class . ' autocomplete="off" />
			  </td>';
        } elseif ($f['type'] == 'textarea') {
            $code .= '
			  <td class="pc_field_td">
			  	<textarea name="' . $f_index . '" autocomplete="off" ' . $placeh . ' style="width: 90%; height: 45px;">' . $val . '</textarea>
			  </td>';
        } elseif ($f['type'] == 'select' || $f['type'] == 'checkbox') {
            $opts = $form_fw->get_field_options($f['opt']);
            $multiple = $f['type'] == 'checkbox' || isset($f['multiple']) && $f['multiple'] ? 'multiple="multiple"' : '';
            $multi_name = $multiple ? '[]' : '';
            $code .= '
			  <td class="pc_field_td">
			  	<select name="' . $f_index . $multi_name . '"  class="lcweb-chosen" ' . $multiple . ' data-placeholder="' . __('Select values', 'pcud_ml') . ' .." autocomplete="off" style="width: 90%;">';
            foreach ($opts as $opt) {
                $sel = in_array($opt, (array) $val) ? 'selected="selected"' : false;
                $code .= '<option value="' . $opt . '" ' . $sel . '>' . $opt . '</option>';
            }
            $code .= '
				  </select>
			  </td>';
        } elseif ($f['type'] == 'single_checkbox') {
            $checked = empty($val) ? '' : 'checked="checked"';
            $code .= '
			  <td class="pc_field_td">
			  	<input type="checkbox" name="' . $f_index . '" value="1" ' . $checked . ' class="ip_checks" autocomplete="off" />
			  </td>';
        }
        if ($a == 1) {
            $code .= '</tr>';
            $a = 0;
        } else {
            $a++;
        }
    }
    // if missing a TD - add it
    if ($a !== 0) {
        $code .= '<td style="border-left: 1px solid #DFDFDF;" colspan="2"></td></tr>';
    }
    // add-user button utility
    $btn_val = empty($fdata) ? __('Add User', 'pc_ml') : __('Update User', 'pc_ml');
    $code .= '
	<tr>
		<td colspan="2" style="width: 50%;">
			<input type="submit" name="pc_man_user_submit" value="' . $btn_val . '" class="button-primary" />
		</td>
		<td colspan="2" style="width: 50%;"></td>
	</tr>
	';
    $code .= "\r\n\t<!-- datepicker init -->\r\n\t<script type='text/javascript'>\r\n\tjQuery(document).ready(function() {\r\n\t\tif(jQuery('.pcud_datepicker').size() > 0) {\r\n\t\t\t// dynamically add datepicker style\r\n\t\t\tjQuery('head').append(\"<link rel='stylesheet' href='" . PCUD_URL . "/css/datepicker/light/pcud_light.theme.min.css' type='text/css' media='all' />\");\r\n\t\t\t\r\n\t\t\tvar pcud_datepicker_init = function(type) {\r\n\t\t\t\treturn {\r\n\t\t\t\t\tdateFormat : (type == 'eu') ? 'dd/mm/yy' : 'mm/dd/yy',\r\n\t\t\t\t\tbeforeShow: function(input, inst) {\r\n\t\t\t\t\t\tjQuery('#ui-datepicker-div').wrap('<div class=\"pcud_dp\"></div>');\r\n\t\t\t\t\t},\r\n\t\t\t\t\tmonthNames: \t\tpcud_datepick_str.monthNames,\r\n\t\t\t\t\tmonthNamesShort: \tpcud_datepick_str.monthNamesShort,\r\n\t\t\t\t\tdayNames: \t\t\tpcud_datepick_str.dayNames,\r\n\t\t\t\t\tdayNamesShort: \t\tpcud_datepick_str.dayNamesShort,\r\n\t\t\t\t\tdayNamesMin:\t\tpcud_datepick_str.dayNamesMin,\r\n\t\t\t\t\tisRTL:\t\t\t\tpcud_datepick_str.isRTL\r\n\t\t\t\t};\t\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tjQuery('.pcud_dp_eu_date').datepicker( pcud_datepicker_init('eu') );\r\n\t\t\tjQuery('.pcud_dp_us_date').datepicker( pcud_datepicker_init('us') );\r\n\t\t}\r\n\t});\r\n\t</script>\r\n\t";
    echo $code;
}