Ejemplo n.º 1
0
function form_builder($json, $arr = array())
{
    $option['id'] = isset($arr['id']) ? $arr['id'] : 0;
    $option['name'] = isset($arr['name']) ? $arr['name'] : 'extra';
    $option['price'] = isset($arr['price']) ? $arr['price'] : '00';
    $option['class'] = isset($arr['class']) ? 'class="' . $arr['class'] . '"' : 'class="form"';
    $option['extra_name'] = isset($arr['extra_name']) ? $arr['extra_name'] : '';
    $option['currency'] = isset($arr['currency']) ? $arr['currency'] : 'EUR';
    $option['user_currency'] = isset($arr['user_currency']) ? $arr['user_currency'] : 'EUR';
    $option['currency_rate'] = isset($arr['currency_rate']) ? $arr['currency_rate'] : '1';
    $option['button'] = isset($arr['button']) ? $arr['button'] : true;
    //start form fields
    $output = '';
    $json = json_decode($json);
    if (is_array($json) and count($json) > 0) {
        $output .= '<div class="' . $option['name'] . '-form ' . $option['name'] . '_form' . $option['id'] . '">';
        //eğer preferecences ise forma guest name surname ekle
        if ($option['name'] == 'pref') {
            $output .= '<div class="f-row">
		    <span class="frm-label">
		    Full Guest Name:<span class="c-f00">*</span>
		    </span>';
            $output .= '<span class="frm-val">
			<input type="text" name="' . $option['name'] . '[' . $option['id'] . '][guest_name]" ' . $option['class'] . ' value="Guest Name">
			</span>
			</div>
			';
            //$output .= '<br />';
        }
        foreach ($json as $key => $form) {
            //if field = text
            if (@$form->field_type == 'text') {
                $output .= '<div class="f-row">
			    <span class="frm-label">
			    ' . $form->label . ' :<span class="c-f00">*</span>
			    </span>';
                $output .= '<span class="frm-val">
				<input type="text" name="' . $option['name'] . '[' . $option['id'] . '][' . replace_chars($form->label) . ']" ' . $option['class'] . '>
				</span>
				</div>
				';
            }
            //if field = paragraph
            if (@$form->field_type == 'paragraph') {
                $output .= '<div class="f-row">
			    <span class="frm-label">
			    ' . $form->label . ' :<span class="c-f00">*</span>
			    </span>';
                $output .= '<span class="frm-val">
				<textarea name="' . $option['name'] . '[' . $option['id'] . '][' . replace_chars($form->label) . ']" ' . $option['class'] . '></textarea>
				</span>
				</div>
				';
            }
            //if field = time
            /*
            if($form->field_type == 'time'){
            	$output .= '<div class="f-row">
                <span class="frm-label">
                '.$form->label.' :<span class="c-f00">*</span>
                </span>';
                $output .='<span class="frm-val">';
            	$output .= '<input type="text" name="'.$option['name'].'['.$option['id'].']['.$form->label.'][hh]" '.$option['class'].' style="width:30px">';
            	$output .= '<input type="text" name="'.$option['name'].'['.$option['id'].']['.$form->label.'][mm]" '.$option['class'].' style="width:30px">';
            	$output .= '<input type="text" name="'.$option['name'].'['.$option['id'].']['.$form->label.'][ss]" '.$option['class'].' style="width:30px">';
            	$output .= '</span>
            	</div>';
            }
            */
            //if field = time
            if (@$form->field_type == 'time') {
                //set hours select option
                $hours = '<select name="' . $option['name'] . '[' . $option['id'] . '][' . replace_chars($form->label) . '][hh]" />';
                for ($i = 0; $i <= 24; $i++) {
                    $hours .= '<option value="' . $i . ':00">' . $i . ':00</option>';
                }
                $hours .= '</select>';
                //set minutes select option
                //set hours select option
                $minutes = '<select name="' . $option['name'] . '[' . $option['id'] . '][' . replace_chars($form->label) . '][mm]" />';
                for ($i = 0; $i <= 6; $i++) {
                    $k = $i * 10;
                    $minutes .= '<option value="' . $k . '">' . $k . '</option>';
                }
                $minutes .= '</select>';
                $output .= '<div class="f-row">
			    <span class="frm-label">
			    ' . $form->label . ' :<span class="c-f00">*</span>
			    </span>';
                $output .= '<span class="frm-val">';
                $output .= $hours;
                $output .= $minutes;
                $output .= '</span>
				</div>';
            }
            //if field = date
            if (@$form->field_type == 'date') {
                $class = substr_replace($option['class'], ' datepicker"', -1);
                $output .= '<div class="f-row">
			    <span class="frm-label">
			    ' . $form->label . ' :<span class="c-f00">*</span>
			    </span>';
                $output .= '<span class="frm-val">
				<input type="text" name="' . $option['name'] . '[' . $option['id'] . '][' . replace_chars($form->label) . ']" ' . $class . '>
				</span>
				</div>';
            }
            //if field = checkbox
            if (@$form->field_type == 'checkboxes') {
                $output .= '<div class="f-row">
			    <span class="frm-label">
			    ' . $form->label . ' :<span class="c-f00">*</span>
			    </span>';
                $output .= '<span class="frm-val">';
                foreach ($form->field_options->options as $opt => $checkbox) {
                    $checked = $checkbox->checked === true ? 'checked="checked"' : '';
                    $output .= '<input type="checkbox" value="' . $checkbox->label . '" name="' . $option['name'] . '[' . $option['id'] . '][' . replace_chars($form->label) . '][]" ' . $option['class'] . ' ' . $checked . '>';
                    $output .= $checkbox->label;
                }
                if (isset($form->field_options->include_other_option) and $form->field_options->include_other_option == 1) {
                    $output .= '<input type="text" name="' . $option['name'] . '[' . $option['id'] . '][' . replace_chars($form->label) . ']" ' . $option['class'] . '>';
                    $output .= 'Other';
                }
                $output .= ' </span>
				</div>';
            }
            //if field = radio
            if (@$form->field_type == 'radio') {
                $output .= '<div class="f-row">
			    <span class="frm-label">
			    ' . $form->label . ' :<span class="c-f00">*</span>
			    </span>';
                $output .= '<span class="frm-val">';
                foreach ($form->field_options->options as $opt => $checkbox) {
                    $checked = $checkbox->checked === true ? 'checked="checked"' : '';
                    $output .= '<input type="radio" value="' . $checkbox->label . '" name="' . $option['name'] . '[' . $option['id'] . '][' . replace_chars($form->label) . ']" ' . $option['class'] . ' ' . $checked . '>';
                    $output .= $checkbox->label;
                }
                if (isset($form->field_options->include_other_option) and $form->field_options->include_other_option == 1) {
                    $output .= '<input type="text" name="' . $option['name'] . '[' . $option['id'] . '][' . replace_chars($form->label) . ']" ' . $option['class'] . '>';
                    $output .= 'Other';
                }
                $output .= '   </span>
				</div>';
            }
            //if field = dropdown
            if (@$form->field_type == 'dropdown') {
                $output .= '<div class="f-row">
			    <span class="frm-label">
			    ' . $form->label . ' :<span class="c-f00">*</span>
			    </span>';
                $output .= '<span class="frm-val">';
                $output .= '<select name="' . $option['name'] . '[' . $option['id'] . '][' . replace_chars($form->label) . ']" ' . $option['class'] . '>';
                foreach ($form->field_options->options as $opt => $checkbox) {
                    $selected = $checkbox->checked === true ? 'checked="checked"' : '';
                    $output .= '<option value="' . $checkbox->label . '" ' . $selected . '>' . $checkbox->label . '</option>';
                }
                $output .= '</select>';
                $output .= '   </span>
				</div>';
            }
            //$output .= '<br>';
        }
        if ($output != '' and $option['button'] != false) {
            $output .= '<input type="hidden" name="' . $option['name'] . '_id" value="' . $option['id'] . '">';
            $output .= '<input type="hidden" name="' . $option['name'] . '_name" value="' . $option['extra_name'] . '">';
            $output .= '<input type="hidden" name="currency" value="' . $option['currency'] . '">';
            $output .= '<input type="hidden" name="user_currency" value="' . $option['user_currency'] . '">';
            $output .= '<input type="hidden" name="currency_rate" value="' . $option['currency_rate'] . '">';
            //$output .= '<input type="button" value="Add" id="button'.$option['id'].'" />';
            $output .= '<input type="hidden" name="type' . $option['id'] . '" id="extra_type' . $option['id'] . '" value="add">';
            $output .= '<script>';
            $output .= "\n\t\t\t\$(function() {\n\t\t\t\$('#button" . $option['id'] . "').click(function () {\n\t\t\t\tform_to_arr('.extra_form" . $option['id'] . "','add');\n\t\t\t\tvar pack = \$(this).parents('.extra-pack');\n\t\t\t    \$('.p-btn-book', pack).html('<img src=\"" . site_url('assets/front/img') . "/check.png\" alt=\"Ok\" />');\n\t\t\t\tCloseForm(\$(this));\n\t\t\t\t\$('#button" . $option['id'] . "').fadeOut();\n\t\t\t    \n\t\t\t})\n\n\t\t\t\$('#cancel" . $option['id'] . "').click(function () {\n\t\t\t\tform_to_arr('.extra_form" . $option['id'] . "','delete');\n\t\t\t\tvar pack = \$(this).parents('.extra-pack');\n\t\t    \t\$('.p-btn-book', pack).html('Book');\n\t\t\t    CloseForm(\$(this));\n\t\t\t\t\$('#button" . $option['id'] . "').fadeIn();\n\t\t\t    \n\t\t\t})\n\t\t\t});\n\t\t\t";
            /*
            $output .= "$('#button".$option['id']."').click(function () {
            			    form_to_arr('.extra_form".$option['id']."');
            			});";
            */
            $output .= '</script>';
            //$output .= '<input type="button" value="Add" id="button'.$option['id'].'" />';
            $output .= '
                    <a class="btn-cancel" id="cancel' . $option['id'] . '">cancel</a>
                    <a class="p-btn p-btn-confirm" id="button' . $option['id'] . '">Confirm</a>';
        }
        $output .= '</div>';
        return $output;
    } else {
        return false;
    }
}
Ejemplo n.º 2
0
/**
 * Converts a string to make it suitable for use in a title tag.
 *
 * Similar to <slug_name>, but keeps spaces.
 *
 * @return The sanitized string
 */
function sanitize_title_text($string)
{
    $sanitized_text = strip_special_chars($string);
    $sanitized_text = replace_chars($sanitized_text, $replacements = array('&amp;' => 'and', '&' => 'and', '/' => '-', 'Dr ' => 'Dr. '));
    return $sanitized_text;
}