1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46:
47: class TextBox {
48: 49: 50: 51: 52: 53:
54: public $textObject;
55:
56: 57: 58: 59: 60: 61:
62: public $label;
63:
64: 65: 66: 67: 68: 69:
70: public $name;
71:
72: 73: 74: 75: 76: 77:
78: public $rows;
79:
80: 81: 82: 83: 84: 85:
86: public $identifier;
87:
88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98:
99: public function __construct($text, $label, $name, $rows=5, $identifier=0) {
100: global $config;
101:
102: if($text instanceof Text)
103: $this->textObject = $text;
104: else
105: throw new IllegalArguementException('Text object passed ['.var_export($text, true).'] is not a valid Text object!');
106:
107: $this->label = $label;
108: $this->name = $name;
109: $this->rows = $rows;
110: $this->identifier = $identifier;
111: }
112:
113: 114: 115: 116: 117: 118: 119: 120:
121: public function render($tableTags=true, $markdown=false) {
122: global $config;
123:
124: $html = '';
125:
126: if($tableTags) {
127: $html .= '<tr><th colspan="2" style="text-align:center;">';
128: $html .= $this->label;
129: $html .= '</th></tr>';
130:
131: $html .= '<tr><td colspan="2">';
132: }
133:
134: if($markdown) {
135: $html .= '<input type="hidden" id="markdownTextBoxRows" name="markdownTextBoxRows" value=""/>';
136: }
137: $html .= '<textarea class="checkMax" maxlength="'.$this->textObject->getSize().'" id="text_field_'.$this->name.'_'.$this->identifier.'" style="width:100%;" rows="'.$this->rows.'" name="'.$this->name.'">';
138:
139: if($this->textObject->getAllowHTML())
140: $html .= InputFilter::decode($this->textObject->getValue(), true);
141: else
142: $html .= InputFilter::decode($this->textObject->getValue());
143:
144: $html .= '</textarea><br>';
145:
146: if($tableTags) {
147: $html .= '</td></tr>';
148: $html .= '<tr><td colspan="2">';
149: }
150:
151: if($markdown) {
152: $increaseTextArea = new Button("document.getElementById('text_field_".$this->name."_".$this->identifier."').rows = ".
153: "(parseInt(document.getElementById('text_field_".$this->name."_".$this->identifier."').rows) + 10);".
154: "document.getElementById('markdownTextBoxRows').value = (parseInt(document.getElementById('text_field_".$this->name."_".$this->identifier."').rows));",
155: "Increase text area", $this->name."IncBut", $config->get('app.url')."/alpha/images/icons/arrow_down.png");
156: }else{
157: $increaseTextArea = new Button("document.getElementById('text_field_".$this->name."_".$this->identifier."').rows = ".
158: "(parseInt(document.getElementById('text_field_".$this->name."_".$this->identifier."').rows) + 10);",
159: "Increase text area", $this->name."IncBut", $config->get('app.url')."/alpha/images/icons/arrow_down.png");
160: }
161:
162: $html .= $increaseTextArea->render();
163:
164: if($markdown) {
165: $decreaseTextArea = new Button("if(document.getElementById('text_field_".$this->name."_".$this->identifier."').rows > 10) ".
166: "{document.getElementById('text_field_".$this->name."_".$this->identifier."').rows = (parseInt(document.getElementById('text_field_".
167: $this->name."_".$this->identifier."').rows) - 10)};".
168: "document.getElementById('markdownTextBoxRows').value = (parseInt(document.getElementById('text_field_".$this->name."_".$this->identifier."').rows));",
169: "Decrease text area", $this->name."DecBut", $config->get('app.url')."/alpha/images/icons/arrow_up.png");
170: }else{
171: $decreaseTextArea = new Button("if(document.getElementById('text_field_".$this->name."_".$this->identifier."').rows > 10) ".
172: "{document.getElementById('text_field_".$this->name."_".$this->identifier."').rows = (parseInt(document.getElementById('text_field_".
173: $this->name."_".$this->identifier."').rows) - 10)};",
174: "Decrease text area", $this->name."DecBut", $config->get('app.url')."/alpha/images/icons/arrow_up.png");
175: }
176:
177: $html .= $decreaseTextArea->render();
178:
179: if($tableTags)
180: $html .= '</td></tr>';
181:
182: if($this->textObject->getRule() != '') {
183: $html .= '<input type="hidden" id="'.$this->name.'_msg" value="'.$this->textObject->getHelper().'"/>';
184: $html .= '<input type="hidden" id="'.$this->name.'_rule" value="'.$this->textObject->getRule().'"/>';
185: }
186:
187: return $html;
188: }
189:
190: 191: 192: 193: 194: 195: 196:
197: public function setTextObject($text) {
198: if($text instanceof Text)
199: $this->text = $text;
200: else
201: throw new IllegalArguementException('Text object passed ['.var_export($text, true).'] is not a valid Text object!');
202: }
203:
204: 205: 206: 207: 208: 209:
210: function getTextObject() {
211: return $this->textObject;
212: }
213: }
214:
215: ?>