コード例 #1
0
ファイル: rbt_helper.php プロジェクト: robotys/sacl
function rbt_make_inputs($inputs, $default = array(), $clear_form = false)
{
    shout_dev();
    echo validation_errors('<div class="alert alert-error">', '</div>');
    //$CI=&get_instance();
    //$data = $CI->input->post();
    $datepicker = FALSE;
    foreach ($inputs as $name => $input) {
        $default_value = '';
        if (array_key_exists($name, $default)) {
            $default_value = $default[$name];
        }
        if ($input['type'] == 'text') {
            echo '<p>' . $input['display'];
            if (strpos($input['rules'], 'required') !== false) {
                echo '<span title="required" style="color: #F00; font-weight: bold">*</span>';
            }
            echo '<br/>';
            if (!$clear_form) {
                echo '<input type="text" name="' . $name . '" value="' . set_value($name, $default_value) . '" id="' . $input['id'] . '" class="' . $input['class'] . '"/></p>';
            }
            if ($clear_form) {
                echo '<input type="text" name="' . $name . '" value="" id="' . $input['id'] . '" class="' . $input['class'] . '"/></p>';
            }
        } elseif ($input['type'] == 'datetime' or $input['type'] == 'date') {
            echo '<p>' . $input['display'];
            if (strpos($input['rules'], 'required') !== false) {
                echo '<span title="required" style="color: #F00; font-weight: bold">*</span>';
            }
            echo '<br/>';
            if (!$clear_form) {
                echo '<input type="text" name="' . $name . '" value="' . set_value($name, $default_value) . '" id="' . $input['id'] . '" class="' . $input['class'] . ' datepicker"/></p>';
            }
            if ($clear_form) {
                echo '<input type="text" name="' . $name . '" value="" id="' . $input['id'] . '" class="' . $input['class'] . ' datepicker"/></p>';
            }
        } elseif ($input['type'] == 'password') {
            echo '<p>' . $input['display'];
            if (strpos($input['rules'], 'required') !== false) {
                echo '<span title="required" style="color: #F00; font-weight: bold">*</span>';
            }
            echo '<br/>';
            if (!$clear_form) {
                echo '<input type="password" name="' . $name . '" value="' . set_value($name, $default_value) . '" id="' . $input['id'] . '" class="' . $input['class'] . '"/></p>';
            }
            if ($clear_form) {
                echo '<input type="password" name="' . $name . '" value="" id="' . $input['id'] . '" class="' . $input['class'] . '"/></p>';
            }
        } elseif ($input['type'] == 'textarea') {
            echo '<p>' . $input['display'];
            if (strpos($input['rules'], 'required') !== false) {
                echo '<span title="required" style="color: #F00; font-weight: bold">*</span>';
            }
            echo '<br/>';
            if (!$clear_form) {
                echo '<textarea name="' . $name . '" id="' . $input['id'] . '" class="' . $input['class'] . '">' . set_value($name, $default_value) . '</textarea></p>';
            }
            if ($clear_form) {
                echo '<textarea name="' . $name . '" id="' . $input['id'] . '" class="' . $input['class'] . '"></textarea></p>';
            }
        } elseif ($input['type'] == 'upload') {
            echo '<p>' . $input['display'];
            if (strpos($input['rules'], 'required') !== false) {
                echo '<span title="required" style="color: #F00; font-weight: bold">*</span>';
            }
            echo '<br/>';
            if (!$clear_form) {
                //get file path
                $exp = explode('|', $input['rules']);
                foreach ($exp as $ex) {
                    if (strpos($ex, 'path') !== FALSE) {
                        $path = str_replace('upload_path:./', '', $ex);
                        $path = trim($path, '/') . '/' . $default_value;
                        $src = base_url($path);
                        $ext = pathinfo($path, PATHINFO_EXTENSION);
                        if ($default_value != NULL) {
                            if ($ext == 'png' or $ext == 'jpg' or $ext == 'gif') {
                                echo '<img class="upload_default ' . $name . '" src="' . $src . '"/><br/>';
                            } else {
                                echo '<div class="alert"><a href="' . $path . '">' . $default_value . '</a></div>';
                            }
                        }
                    }
                }
            }
            echo '<input type="file" name="' . $name . '" id="' . $input['id'] . '" class="' . $input['class'] . '"/></p>';
        } elseif ($input['type'] == 'hidden') {
            //echo '<p>'.$input['display'].'<br/>';
            echo '<input type="hidden" name="' . $name . '" value="' . $input['value'] . '" id="' . $input['id'] . '" class="' . $input['class'] . '"/></p>';
        } elseif ($input['type'] == 'radio') {
            echo '<p>' . $input['display'];
            if (strpos($input['rules'], 'required') !== false) {
                echo '<span title="required" style="color: #F00; font-weight: bold">*</span>';
            }
            echo ': ';
            foreach ($input['options'] as $disp => $value) {
                echo '<input type="radio" name="' . $name . '" value="' . $value . '" id="' . $input['id'] . '" class="' . $input['class'] . '" ' . set_radio($name, $value) . '> ' . ucfirst($disp) . ' &nbsp;';
            }
            echo '</p>';
            //echo '<input type="hidden" name="'.$name.'" value="'.$input['value'].'"/></p>';
        } elseif ($input['type'] == 'checkbox') {
            echo '<p>' . $input['display'];
            if (strpos($input['rules'], 'required') !== false) {
                echo '<span title="required" style="color: #F00; font-weight: bold">*</span>';
            }
            echo ': ';
            foreach ($input['options'] as $disp => $value) {
                $checked = '';
                if ($default_value != "") {
                    if (array_search($value, $default_value) !== false) {
                        $checked = 'checked="checked"';
                    }
                }
                echo '<input type="checkbox" name="' . $name . '[]" value="' . $value . '" id="' . $input['id'] . '" class="' . $input['class'] . '" ' . $checked . '> ' . ucfirst($disp) . ' &nbsp;';
            }
            echo '</p>';
            //echo '<input type="hidden" name="'.$name.'" value="'.$input['value'].'"/></p>';
        } elseif ($input['type'] == 'select') {
            echo '<p>' . $input['display'];
            if (strpos($input['rules'], 'required') !== false) {
                echo '<span title="required" style="color: #F00; font-weight: bold">*</span>';
            }
            echo ': ';
            echo '<select name="' . $name . '" id="' . $input['id'] . '" class="' . $input['class'] . '">';
            foreach ($input['options'] as $disp => $value) {
                echo '<option value="' . $value . '"';
                if (!$clear_form && $value == $default_value) {
                    echo 'selected="selected"';
                }
                echo '> ' . ucfirst($disp) . '</option>';
            }
            echo '</select></p>';
            //echo '<input type="hidden" name="'.$name.'" value="'.$input['value'].'"/></p>';
        }
        if ($input['id'] == 'datepicker' && $datepicker == FALSE) {
            $datepicker = TRUE;
        }
    }
    if ($datepicker) {
        echo '<style type="text/css">@import url(' . base_url('assets/css/smoothness/jquery-ui-1.8.10.custom.css') . ')</style>';
        echo '<script src="' . base_url('assets/js/jquery-ui-1.8.10.custom.min.js') . '"></script>';
        echo '<script type="text/javascript">$("#datepicker").datepicker()</script>';
        //echo 'DatePicker On!';
    } else {
        //echo 'WTF!!';
    }
}
コード例 #2
0
ファイル: rbt_helper.php プロジェクト: robotys/fitfatfut
function rbt_make_inputs($inputs, $default = array(), $block = false)
{
    shout_dev();
    // echo validation_errors('<div class="alert alert-error">','</div>');
    $error_before = '<div class="alert alert-danger">';
    $error_after = '</div>';
    //$CI=&get_instance();
    //$data = $CI->input->post();
    $datepicker = FALSE;
    $color = FALSE;
    foreach ($inputs as $name => $input) {
        $default_value = '';
        if (array_key_exists($name, $default)) {
            $default_value = $default[$name];
        }
        if (array_key_exists('id', $input) == FALSE) {
            $input['id'] = '';
        }
        if (array_key_exists('class', $input) == FALSE) {
            $input['class'] = 'form-control';
        }
        if (array_key_exists($name, $default)) {
            $default_value = $default[$name];
        }
        if ($input['type'] == 'text') {
            echo '<p><label>' . $input['display'] . '</label><br/>' . form_error($name, $error_before, $error_after);
            echo '<input type="text" name="' . $name . '" value="' . set_value($name, $default_value) . '" id="' . $input['id'] . '" class="' . $input['class'] . '" placeholder="' . $input['display'] . '"/></p>';
            // if($clear_form) echo '<input type="text" name="'.$name.'" value="" id="'.$input['id'].'" class="'.$input['class'].'" placeholder="'.$input['display'].'/></p>';
        }
        if ($input['type'] == 'color') {
            echo '<p><label>' . $input['display'] . '</label><br/>' . form_error($name, $error_before, $error_after);
            echo '<input type="color" name="' . $name . '" value="' . set_value($name, $default_value) . '" id="' . $input['id'] . '" class="' . $input['class'] . '"/></p>';
            // if($clear_form) echo '<input type="color" name="'.$name.'" value="" id="'.$input['id'].'" class="'.$input['class'].'"/></p>';
        }
        if ($input['type'] == 'datetime' || $input['type'] == 'date') {
            echo '<p><label>' . $input['display'] . '</label><br/>' . form_error($name, $error_before, $error_after);
            echo '<input type="text" name="' . $name . '" value="' . set_value($name, $default_value) . '" id="' . $input['id'] . '" class="' . $input['class'] . ' datepicker"/></p>';
            // if($clear_form) echo '<input type="text" name="'.$name.'" value="" id="'.$input['id'].'" class="'.$input['class'].' datepicker"/></p>';
        }
        if ($input['type'] == 'password') {
            echo '<p><label>' . $input['display'] . '</label><br/>' . form_error($name, $error_before, $error_after);
            echo '<input type="password" name="' . $name . '" value="' . set_value($name, $default_value) . '" id="' . $input['id'] . '" class="' . $input['class'] . '"/></p>';
            // if($clear_form) echo '<input type="password" name="'.$name.'" value="" id="'.$input['id'].'" class="'.$input['class'].'"/></p>';
        }
        if ($input['type'] == 'textarea') {
            echo '<p><label>' . $input['display'] . '</label><br/>' . form_error($name, $error_before, $error_after);
            echo '<textarea name="' . $name . '" id="' . $input['id'] . '" class="' . $input['class'] . '">' . set_value($name, $default_value) . '</textarea></p>';
            // if($clear_form) echo '<textarea name="'.$name.'" id="'.$input['id'].'" class="'.$input['class'].'"></textarea></p>';
        }
        if ($input['type'] == 'upload') {
            echo '<p><label>' . $input['display'] . '</label><br/>' . form_error($name, $error_before, $error_after);
            if (!$clear_form) {
                //get file path
                $exp = explode('|', $input['rules']);
                foreach ($exp as $ex) {
                    if (strpos($ex, 'path') !== FALSE) {
                        $path = str_replace('upload_path:./', '', $ex);
                        $path = trim($path, '/') . '/' . $default_value;
                        $src = base_url($path);
                        echo '<img class="upload_default ' . $name . '" src="' . $src . '" style="max-height: 80px"/><br/>';
                    }
                }
            }
            echo '<input type="file" name="' . $name . '" id="' . $input['id'] . '" class="' . $input['class'] . '"/></p>';
        }
        if ($input['type'] == 'hidden') {
            //echo '<p>'.$input['display'].'<br/>';
            echo '<input type="hidden" name="' . $name . '" value="' . $input['value'] . '" id="' . $input['id'] . '" class="' . $input['class'] . '"/></p>';
        }
        if ($input['type'] == 'radio') {
            echo '<p><label>' . $input['display'] . ':</label> ';
            foreach ($input['options'] as $disp => $value) {
                $checked = '';
                if ($value == $default_value && !$clear_form) {
                    $checked = 'checked="checked"';
                }
                echo '<input type="radio" name="' . $name . '" value="' . $value . '" id="' . $input['id'] . '" class="' . $input['class'] . '" ' . set_radio($name, $value) . ' ' . $checked . '> ' . ucfirst($disp) . ' &nbsp;';
            }
            echo '</p>' . form_error($name, $error_before, $error_after);
            //echo '<input type="hidden" name="'.$name.'" value="'.$input['value'].'"/></p>';
        }
        if ($input['type'] == 'checkbox') {
            echo '<p><label>' . $input['display'] . ': </label>';
            foreach ($input['options'] as $disp => $value) {
                $checked = '';
                if ($value == $default_value && !$clear_form) {
                    $checked = 'checked="checked"';
                }
                echo '<input type="checkbox" name="' . $name . '" value="' . $value . '" id="' . $input['id'] . '" class="' . $input['class'] . '" ' . set_checkbox($name, $value) . ' ' . $checked . '> ' . ucfirst($disp) . ' &nbsp;';
            }
            echo '</p>' . form_error($name, $error_before, $error_after);
            //echo '<input type="hidden" name="'.$name.'" value="'.$input['value'].'"/></p>';
        }
        if ($input['type'] == 'select') {
            echo '<p><label>' . $input['display'] . ': </label>';
            echo '<select name="' . $name . '" id="' . $input['id'] . '" class="' . $input['class'] . '">';
            foreach ($input['options'] as $disp => $value) {
                echo '<option value="' . $value . '"';
                if (!$clear_form && $value == $default_value) {
                    echo 'selected="selected"';
                }
                echo '> ' . ucfirst($disp) . '</option>';
            }
            echo '</select></p>' . form_error($name, $error_before, $error_after);
            //echo '<input type="hidden" name="'.$name.'" value="'.$input['value'].'"/></p>';
        }
        if ($input['id'] == 'datepicker' && $datepicker == FALSE) {
            $datepicker = TRUE;
        }
        if ($input['id'] == 'color' && $color == FALSE) {
            $color = TRUE;
        }
    }
    if ($datepicker) {
        echo '<style type="text/css">@import url(' . base_url('assets/css/smoothness/jquery-ui-1.8.10.custom.css') . ')</style>';
        echo '<script src="' . base_url('assets/js/jquery-ui-1.8.10.custom.min.js') . '"></script>';
        echo '<script type="text/javascript">$("#datepicker").datepicker()</script>';
        //echo 'DatePicker On!';
    }
    if ($color) {
        echo '<style type="text/css">@import url(' . base_url('assets/css/spectrum.css') . ')</style>';
        echo '<script src="' . base_url('assets/js/spectrum.js') . '"></script>';
    }
}