/application/libraries/Admin_Form.php
PHP | 126 lines | 85 code | 23 blank | 18 comment | 7 complexity | 1f49dcfcc2f86a476d73c8d7b24d2675 MD5 | raw file
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
-
- /**
- * Html in this class should be put in view files??????
- */
- class Admin_Form {
-
- public function __construct() {
-
- }
-
- public function create($type, $key, $label, $value, $options = null, $helper = "", $placeholder = "") {
- switch ($type) {
-
- case 1:
- $this->show_varchar($key, $label, $value, $helper, $placeholder);
- break;
-
- case 2:
- $this->show_select($key, $label, $value, $options, $helper);
- break;
-
- case 3:
- $this->show_radio($key, $label, $value, $options, $helper);
- break;
-
- case 4:
- $this->show_text($key, $label, $value, $helper, $placeholder);
- break;
-
- case 5:
- $this->show_color($key, $label, $value, $helper, $placeholder);
- break;
-
- case 6:
- $this->show_file($key, $label, $value, $helper, false);
- break;
-
- case 7:
- $this->show_file($key, $value, $helper, true);
- break;
- }
- }
-
- public function show_varchar($key, $label, $value, $helper, $placeholder) {
- $return = $this->append_label($label);
- $return .= '<input type="text" class="type_varchar" id="' . $key . '" value="' . $value . '"' . ((!empty($placeholder)) ? ' placeholder="' . $placeholder . '"' : '') . '>';
- $return .= $this->append_help_text($helper);
- return $return;
- }
-
- public function show_select($key, $label, $value, $options, $helper) {
- $value = strtolower($value);
- $return = $this->append_label($label);
- $return .= '<select class="type_select" id="'.$key.'">';
- foreach($options as $option){
- if(strtolower($option) == $value) $return .= '<option value="'.strtolower($option).'" selected="selected">'.ucfirst($option).'</option>';
- else $return .= '<option value="'.strtolower($option).'">'.ucfirst($option).'</option>';
-
- }
- $return .= '</select>';
- $return .= $this->append_help_text($helper);
- return $return;
- }
-
- public function show_radio($key, $label, $value, $options, $helper){
- $value = strtolower($value);
- $return = $this->append_label($label);
- $return .= '<ul>';
- foreach($options as $option){
- $return .= '<li><input type="radio" name="'.$key.'" value="'.$option.'"'.((strtolower($option) == $value) ? ' checked' : '').'><li>';
- }
- $return .= '</ul>';
- $return .= $this->append_help_text($helper);
- return $return;
- }
-
- public function show_text($key, $label, $value, $helper, $placeholder){
- $value = strtolower($value);
- $return = $this->append_label($label);
- $return .= '<textarea id="'.$key.'">'.$value.'</textarea>';
- $return .= $this->append_help_text($helper);
- return $return;
- }
-
- /**
- * Using: http://www.digitalmagicpro.com/jPicker/
- * @param type $key
- * @param type $label
- * @param type $value
- * @param type $helper
- * @param type $placeholder
- */
- public function show_color($key, $label, $value, $helper, $placeholder){
- $value = strtolower($value);
- $return = $this->append_label($label);
- $return .= '<input type="text" class="admin-colorpicker" id="'.$key.'" value="'.$value.'" />';
- $return .= $this->append_help_text($helper);
- return $return;
- }
-
- /**
- * Using: https://github.com/blueimp/jQuery-File-Upload/wiki
- * @param type $key
- * @param type $value
- * @param type $helper
- * @param type $multi_upload
- */
- public function show_file($key, $value, $helper, $multi_upload){
-
- }
-
- public function append_help_text($helper) {
- if (!empty($helper)) {
- return '<span>' . $helper . '</span>';
- }
- return;
- }
-
- public function append_label($label){
- return '<label>' . __('label') . '</label>';
- }
-
- }
-
- ?>