PageRenderTime 67ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/application/libraries/Admin_Form.php

https://github.com/danpette/sourceshop
PHP | 126 lines | 85 code | 23 blank | 18 comment | 7 complexity | 1f49dcfcc2f86a476d73c8d7b24d2675 MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * Html in this class should be put in view files??????
  4. */
  5. class Admin_Form {
  6. public function __construct() {
  7. }
  8. public function create($type, $key, $label, $value, $options = null, $helper = "", $placeholder = "") {
  9. switch ($type) {
  10. case 1:
  11. $this->show_varchar($key, $label, $value, $helper, $placeholder);
  12. break;
  13. case 2:
  14. $this->show_select($key, $label, $value, $options, $helper);
  15. break;
  16. case 3:
  17. $this->show_radio($key, $label, $value, $options, $helper);
  18. break;
  19. case 4:
  20. $this->show_text($key, $label, $value, $helper, $placeholder);
  21. break;
  22. case 5:
  23. $this->show_color($key, $label, $value, $helper, $placeholder);
  24. break;
  25. case 6:
  26. $this->show_file($key, $label, $value, $helper, false);
  27. break;
  28. case 7:
  29. $this->show_file($key, $value, $helper, true);
  30. break;
  31. }
  32. }
  33. public function show_varchar($key, $label, $value, $helper, $placeholder) {
  34. $return = $this->append_label($label);
  35. $return .= '<input type="text" class="type_varchar" id="' . $key . '" value="' . $value . '"' . ((!empty($placeholder)) ? ' placeholder="' . $placeholder . '"' : '') . '>';
  36. $return .= $this->append_help_text($helper);
  37. return $return;
  38. }
  39. public function show_select($key, $label, $value, $options, $helper) {
  40. $value = strtolower($value);
  41. $return = $this->append_label($label);
  42. $return .= '<select class="type_select" id="'.$key.'">';
  43. foreach($options as $option){
  44. if(strtolower($option) == $value) $return .= '<option value="'.strtolower($option).'" selected="selected">'.ucfirst($option).'</option>';
  45. else $return .= '<option value="'.strtolower($option).'">'.ucfirst($option).'</option>';
  46. }
  47. $return .= '</select>';
  48. $return .= $this->append_help_text($helper);
  49. return $return;
  50. }
  51. public function show_radio($key, $label, $value, $options, $helper){
  52. $value = strtolower($value);
  53. $return = $this->append_label($label);
  54. $return .= '<ul>';
  55. foreach($options as $option){
  56. $return .= '<li><input type="radio" name="'.$key.'" value="'.$option.'"'.((strtolower($option) == $value) ? ' checked' : '').'><li>';
  57. }
  58. $return .= '</ul>';
  59. $return .= $this->append_help_text($helper);
  60. return $return;
  61. }
  62. public function show_text($key, $label, $value, $helper, $placeholder){
  63. $value = strtolower($value);
  64. $return = $this->append_label($label);
  65. $return .= '<textarea id="'.$key.'">'.$value.'</textarea>';
  66. $return .= $this->append_help_text($helper);
  67. return $return;
  68. }
  69. /**
  70. * Using: http://www.digitalmagicpro.com/jPicker/
  71. * @param type $key
  72. * @param type $label
  73. * @param type $value
  74. * @param type $helper
  75. * @param type $placeholder
  76. */
  77. public function show_color($key, $label, $value, $helper, $placeholder){
  78. $value = strtolower($value);
  79. $return = $this->append_label($label);
  80. $return .= '<input type="text" class="admin-colorpicker" id="'.$key.'" value="'.$value.'" />';
  81. $return .= $this->append_help_text($helper);
  82. return $return;
  83. }
  84. /**
  85. * Using: https://github.com/blueimp/jQuery-File-Upload/wiki
  86. * @param type $key
  87. * @param type $value
  88. * @param type $helper
  89. * @param type $multi_upload
  90. */
  91. public function show_file($key, $value, $helper, $multi_upload){
  92. }
  93. public function append_help_text($helper) {
  94. if (!empty($helper)) {
  95. return '<span>' . $helper . '</span>';
  96. }
  97. return;
  98. }
  99. public function append_label($label){
  100. return '<label>' . __('label') . '</label>';
  101. }
  102. }
  103. ?>