1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: 12: 13: 14: 15: 16: 17: 18: 19: 20:
21: class XoopsFormRendererBootstrap3 implements XoopsFormRendererInterface
22: {
23:
24: 25: 26: 27: 28: 29: 30:
31: public function renderFormButton(XoopsFormButton $element)
32: {
33: return "<input type='" . $element->getType() . "' class='btn btn-default' name='"
34: . $element->getName() . "' id='" . $element->getName() . "' value='" . $element->getValue()
35: . "' title='" . $element->getValue() . "'" . $element->getExtra() . ' />';
36: }
37:
38: 39: 40: 41: 42: 43: 44:
45: public function renderFormButtonTray(XoopsFormButtonTray $element)
46: {
47: $ret = '';
48: if ($element->_showDelete) {
49: $ret .= '<input type="submit" class="btn btn-danger" name="delete" id="delete" value="' . _DELETE
50: . '" onclick="this.form.elements.op.value=\'delete\'"> ';
51: }
52: $ret .= '<input type="button" class="btn btn-danger" value="' . _CANCEL
53: . '" onClick="history.go(-1);return true;" /> '
54: . '<input type="reset" class="btn btn-warning" name="reset" id="reset" value="' . _RESET . '" /> '
55: . '<input type="' . $element->getType() . '" class="btn btn-success" name="' . $element->getName()
56: . '" id="' . $element->getName() . '" value="' . $element->getValue() . '"' . $element->getExtra()
57: . ' />';
58:
59: return $ret;
60: }
61:
62: 63: 64: 65: 66: 67: 68:
69: public function renderFormCheckBox(XoopsFormCheckBox $element)
70: {
71: $elementName = $element->getName();
72: $elementId = $elementName;
73: $elementOptions = $element->getOptions();
74: if (count($elementOptions) > 1 && substr($elementName, -2, 2) !== '[]') {
75: $elementName .= '[]';
76: $element->setName($elementName);
77: }
78:
79: switch ((int) ($element->columns)) {
80: case 0:
81: return $this->renderCheckedInline($element, 'checkbox', $elementId, $elementName);
82: case 1:
83: return $this->renderCheckedOneColumn($element, 'checkbox', $elementId, $elementName);
84: default:
85: return $this->renderCheckedColumnar($element, 'checkbox', $elementId, $elementName);
86: }
87: }
88:
89: 90: 91: 92: 93: 94: 95: 96: 97:
98: protected function renderCheckedInline($element, $type, $elementId, $elementName)
99: {
100: $class = $type . '-inline';
101: $ret = '';
102:
103: $idSuffix = 0;
104: $elementValue = $element->getValue();
105: $elementOptions = $element->getOptions();
106: foreach ($elementOptions as $value => $name) {
107: ++$idSuffix;
108: $ret .= '<label class="' . $class . '">';
109: $ret .= "<input type='" . $type . "' name='{$elementName}' id='{$elementId}{$idSuffix}' title='"
110: . htmlspecialchars(strip_tags($name), ENT_QUOTES) . "' value='"
111: . htmlspecialchars($value, ENT_QUOTES) . "'";
112:
113: if (is_array($elementValue) ? in_array($value, $elementValue): $value == $elementValue) {
114: $ret .= ' checked';
115: }
116: $ret .= $element->getExtra() . ' />' . $name . $element->getDelimeter();
117: $ret .= '</label>';
118: }
119:
120: return $ret;
121: }
122:
123: 124: 125: 126: 127: 128: 129: 130: 131:
132: protected function renderCheckedOneColumn($element, $type, $elementId, $elementName)
133: {
134: $class = $type;
135: $ret = '';
136:
137: $idSuffix = 0;
138: $elementValue = $element->getValue();
139: $elementOptions = $element->getOptions();
140: foreach ($elementOptions as $value => $name) {
141: ++$idSuffix;
142: $ret .= '<div class="' . $class . '">';
143: $ret .= '<label>';
144: $ret .= "<input type='" . $type . "' name='{$elementName}' id='{$elementId}{$idSuffix}' title='"
145: . htmlspecialchars(strip_tags($name), ENT_QUOTES) . "' value='"
146: . htmlspecialchars($value, ENT_QUOTES) . "'";
147:
148: if (is_array($elementValue) ? in_array($value, $elementValue): $value == $elementValue) {
149: $ret .= ' checked';
150: }
151: $ret .= $element->getExtra() . ' />' . $name . $element->getDelimeter();
152: $ret .= '</label>';
153: $ret .= '</div>';
154: }
155:
156: return $ret;
157: }
158:
159: 160: 161: 162: 163: 164: 165: 166: 167:
168: protected function renderCheckedColumnar($element, $type, $elementId, $elementName)
169: {
170: $class = $type;
171: $ret = '';
172:
173: $idSuffix = 0;
174: $elementValue = $element->getValue();
175: $elementOptions = $element->getOptions();
176: foreach ($elementOptions as $value => $name) {
177: ++$idSuffix;
178: $ret .= '<div class="' . $class . ' col-md-2">';
179: $ret .= '<label>';
180: $ret .= "<input type='" . $type . "' name='{$elementName}' id='{$elementId}{$idSuffix}' title='"
181: . htmlspecialchars(strip_tags($name), ENT_QUOTES) . "' value='"
182: . htmlspecialchars($value, ENT_QUOTES) . "'";
183:
184: if (is_array($elementValue) ? in_array($value, $elementValue): $value == $elementValue) {
185: $ret .= ' checked';
186: }
187: $ret .= $element->getExtra() . ' />' . $name . $element->getDelimeter();
188: $ret .= '</label>';
189: $ret .= '</div>';
190: }
191:
192: return $ret;
193: }
194: 195: 196: 197: 198: 199: 200:
201: public function renderFormColorPicker(XoopsFormColorPicker $element)
202: {
203: if (isset($GLOBALS['xoTheme'])) {
204: $GLOBALS['xoTheme']->addScript('include/spectrum.js');
205: $GLOBALS['xoTheme']->addStylesheet('include/spectrum.css');
206: } else {
207: echo '<script type="text/javascript" src="' . XOOPS_URL . '/include/spectrum.js"></script>';
208: echo '<link rel="stylesheet" type="text/css" href="' . XOOPS_URL . '/include/spectrum.css">';
209: }
210: return '<input class="form-control" style="width: 25%;" type="color" name="' . $element->getName()
211: . "' title='" . $element->getTitle() . "' id='" . $element->getName()
212: . '" size="7" maxlength="7" value="' . $element->getValue() . '"' . $element->getExtra() . ' />';
213: }
214:
215: 216: 217: 218: 219: 220: 221:
222: public function renderFormDhtmlTextArea(XoopsFormDhtmlTextArea $element)
223: {
224: static $js_loaded;
225:
226: xoops_loadLanguage('formdhtmltextarea');
227: $ret = '';
228:
229: $ret .= $this->renderFormDhtmlTAXoopsCode($element) . "<br>\n";
230:
231: $ret .= $this->renderFormDhtmlTATypography($element);
232:
233:
234: $ret .= "<br>\n";
235:
236: $ret .= "<textarea class='form-control' id='" . $element->getName() . "' name='" . $element->getName()
237: . "' title='" . $element->getTitle() . "' onselect=\"xoopsSavePosition('" . $element->getName()
238: . "');\" onclick=\"xoopsSavePosition('" . $element->getName()
239: . "');\" onkeyup=\"xoopsSavePosition('" . $element->getName() . "');\" cols='"
240: . $element->getCols() . "' rows='" . $element->getRows() . "'" . $element->getExtra()
241: . '>' . $element->getValue() . "</textarea>\n";
242:
243: if (empty($element->skipPreview)) {
244: if (empty($GLOBALS['xoTheme'])) {
245: $element->js .= implode('', file(XOOPS_ROOT_PATH . '/class/textsanitizer/image/image.js'));
246: } else {
247: $GLOBALS['xoTheme']->addScript(
248: '/class/textsanitizer/image/image.js',
249: array('type' => 'text/javascript')
250: );
251: }
252: $button = "<button type='button' class='btn btn-primary' onclick=\"form_instantPreview('" . XOOPS_URL
253: . "', '" . $element->getName() . "','" . XOOPS_URL . "/images', " . (int)$element->doHtml . ", '"
254: . $GLOBALS['xoopsSecurity']->createToken() . "')\" title='" . _PREVIEW . "'>" . _PREVIEW . "</button>";
255:
256: $ret .= '<br>' . "<div id='" . $element->getName() . "_hidden' style='display: block;'> "
257: . ' <fieldset>' . ' <legend>' . $button . '</legend>'
258: . " <div id='" . $element->getName() . "_hidden_data'>" . _XOOPS_FORM_PREVIEW_CONTENT
259: . '</div>' . ' </fieldset>' . '</div>';
260: }
261:
262: if (empty($js_loaded)) {
263: $javascript = ($element->js ? '<script type="text/javascript">' . $element->js . '</script>' : '')
264: . '<script type="text/javascript" src="' . XOOPS_URL . '/include/formdhtmltextarea.js"></script>';
265: $ret = $javascript . $ret;
266: $js_loaded = true;
267: }
268:
269: return $ret;
270: }
271:
272: 273: 274: 275: 276: 277: 278:
279: protected function renderFormDhtmlTAXoopsCode(XoopsFormDhtmlTextArea $element)
280: {
281: $textarea_id = $element->getName();
282: $code = '';
283: $code .= "<div class='row'><div class='col-md-12'>";
284: $code .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsCodeUrl(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTERURL, ENT_QUOTES) . "\", \"" . htmlspecialchars(_ENTERWEBTITLE, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_URL . "'><span class='fa fa-fw fa-link' aria-hidden='true'></span></button>";
285: $code .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsCodeEmail(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTEREMAIL, ENT_QUOTES) . "\", \"" . htmlspecialchars(_ENTERWEBTITLE, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_EMAIL . "'><span class='fa fa-fw fa-envelope-o' aria-hidden='true'></span></button>";
286: $code .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsCodeImg(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTERIMGURL, ENT_QUOTES) . "\", \"" . htmlspecialchars(_ENTERIMGPOS, ENT_QUOTES) . "\", \"" . htmlspecialchars(_IMGPOSRORL, ENT_QUOTES) . "\", \"" . htmlspecialchars(_ERRORIMGPOS, ENT_QUOTES) . "\", \"" . htmlspecialchars(_XOOPS_FORM_ALT_ENTERWIDTH, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_IMG . "'><span class='fa fa-fw fa-file-image-o' aria-hidden='true'></span></button>";
287: $code .= "<button type='button' class='btn btn-default btn-sm' onclick='openWithSelfMain(\"" . XOOPS_URL . "/imagemanager.php?target={$textarea_id}\",\"imgmanager\",400,430);' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_IMAGE . "'><span class='fa fa-file-image-o' aria-hidden='true'></span><small> Manager</small></button>";
288: $code .= "<button type='button' class='btn btn-default btn-sm' onclick='openWithSelfMain(\"" . XOOPS_URL . "/misc.php?action=showpopups&type=smilies&target={$textarea_id}\",\"smilies\",300,475);' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_SMILEY . "'><span class='fa fa-fw fa-smile-o' aria-hidden='true'></span></button>";
289:
290: $myts = MyTextSanitizer::getInstance();
291:
292: $extensions = array_filter($myts->config['extensions']);
293: foreach (array_keys($extensions) as $key) {
294: $extension = $myts->loadExtension($key);
295: @list($encode, $js) = $extension->encode($textarea_id);
296: if (empty($encode)) {
297: continue;
298: }
299: $code .= $encode;
300: if (!empty($js)) {
301: $element->js .= $js;
302: }
303: }
304: $code .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsCodeCode(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTERCODE, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_CODE . "'><span class='fa fa-fw fa-code' aria-hidden='true'></span></button>";
305: $code .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsCodeQuote(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTERQUOTE, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_QUOTE . "'><span class='fa fa-fw fa-quote-right' aria-hidden='true'></span></button>";
306: $code .= "</div></div>";
307:
308: $xoopsPreload = XoopsPreload::getInstance();
309: $xoopsPreload->triggerEvent('core.class.xoopsform.formdhtmltextarea.codeicon', array(&$code));
310:
311: return $code;
312: }
313:
314: 315: 316: 317: 318: 319: 320:
321: protected function renderFormDhtmlTATypography(XoopsFormDhtmlTextArea $element)
322: {
323: $textarea_id = $element->getName();
324: $hiddentext = $element->_hiddenText;
325:
326: $fontarray = !empty($GLOBALS['formtextdhtml_fonts']) ? $GLOBALS['formtextdhtml_fonts'] : array(
327: 'Arial',
328: 'Courier',
329: 'Georgia',
330: 'Helvetica',
331: 'Impact',
332: 'Verdana',
333: 'Haettenschweiler');
334:
335: $colorArray = array(
336: 'Black' => '000000',
337: 'Blue' => '38AAFF',
338: 'Brown' => '987857',
339: 'Green' => '79D271',
340: 'Grey' => '888888',
341: 'Orange' => 'FFA700',
342: 'Paper' => 'E0E0E0',
343: 'Purple' => '363E98',
344: 'Red' => 'FF211E',
345: 'White' => 'FEFEFE',
346: 'Yellow' => 'FFD628',
347: );
348:
349: $fontStr = '<div class="row"><div class="col-md-12"><div class="btn-group" role="toolbar">';
350: $fontStr .= '<div class="btn-group">'
351: . '<button type="button" class="btn btn-default btn-sm dropdown-toggle" title="'. _SIZE .'"'
352: . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
353: . '<span class = "glyphicon glyphicon-text-height"></span><span class="caret"></span></button>'
354: . '<ul class="dropdown-menu">';
355:
356: foreach ($GLOBALS['formtextdhtml_sizes'] as $value => $name) {
357: $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'size\', \'' . $value . '\', \''
358: . $textarea_id . '\', \'' . $hiddentext . '\');">' . $name . '</a></li>';
359: }
360: $fontStr .= '</ul></div>';
361:
362: $fontStr .= '<div class="btn-group">'
363: . '<button type="button" class="btn btn-default btn-sm dropdown-toggle" title="'. _FONT .'"'
364: . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
365: . '<span class = "glyphicon glyphicon-font"></span><span class="caret"></span></button>'
366: . '<ul class="dropdown-menu">';
367:
368: foreach ($fontarray as $font) {
369: $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'font\', \'' . $font . '\', \''
370: . $textarea_id . '\', \'' . $hiddentext . '\');">' . $font . '</a></li>';
371: }
372: $fontStr .= '</ul></div>';
373:
374: $fontStr .= '<div class="btn-group">'
375: . '<button type="button" class="btn btn-default btn-sm dropdown-toggle" title="'. _COLOR .'"'
376: . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
377: . '<span class = "glyphicon glyphicon-text-color"></span><span class="caret"></span></button>'
378: . '<ul class="dropdown-menu">';
379:
380: foreach ($colorArray as $color => $hex) {
381: $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'color\', \'' . $hex . '\', \''
382: . $textarea_id . '\', \'' . $hiddentext . '\');">'
383: . '<span style="color:#' . $hex . ';">' . $color .'</span></a></li>';
384: }
385: $fontStr .= '</ul></div>';
386: $fontStr .= '</div>';
387:
388:
389: $styleStr = "<div class='btn-group' role='group'>";
390: $styleStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeBold(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_BOLD . "' aria-label='Left Align'><span class='fa fa-bold' aria-hidden='true'></span></button>";
391: $styleStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeItalic(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_ITALIC . "' aria-label='Left Align'><span class='fa fa-italic' aria-hidden='true'></span></button>";
392: $styleStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeUnderline(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_UNDERLINE . "' aria-label='Left Align'>" . '<span class="fa fa-underline"></span></button>';
393: $styleStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeLineThrough(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_LINETHROUGH . "' aria-label='Left Align'>" . '<span class="fa fa-strikethrough"></span></button>';
394: $styleStr .= "</div>";
395:
396: $alignStr = "<div class='btn-group' role='group'>";
397: $alignStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeLeft(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_LEFT . "' aria-label='Left Align'><span class='fa fa-align-left' aria-hidden='true'></span></button>";
398: $alignStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeCenter(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_CENTER . "' aria-label='Left Align'><span class='fa fa-align-center' aria-hidden='true'></span></button>";
399: $alignStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeRight(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_RIGHT . "' aria-label='Left Align'><span class='fa fa-align-right' aria-hidden='true'></span></button>";
400: $alignStr .= "</div>";
401:
402: $fontStr .= " {$styleStr} {$alignStr} \n";
403:
404: $fontStr .= "<button type='button' class='btn btn-default btn-sm' onclick=\"XoopsCheckLength('"
405: . $element->getName() . "', '" . @$element->configs['maxlength'] . "', '"
406: . _XOOPS_FORM_ALT_LENGTH . "', '" . _XOOPS_FORM_ALT_LENGTH_MAX . "');\" title='"
407: . _XOOPS_FORM_ALT_CHECKLENGTH . "'><span class='fa fa-check-square-o' aria-hidden='true'></span></button>";
408: $fontStr .= "</div></div>";
409:
410: return $fontStr;
411: }
412:
413: 414: 415: 416: 417: 418: 419:
420: public function renderFormElementTray(XoopsFormElementTray $element)
421: {
422: $count = 0;
423: $ret = '<span class="form-inline">';
424: foreach ($element->getElements() as $ele) {
425: if ($count > 0) {
426: $ret .= $element->getDelimeter();
427: }
428: if ($ele->getCaption() != '') {
429: $ret .= $ele->getCaption() . ' ';
430: }
431: $ret .= $ele->render() . NWLINE;
432: if (!$ele->isHidden()) {
433: ++$count;
434: }
435: }
436: 437: 438: 439: 440: 441: 442: 443: 444:
445: $ret .= '</span>';
446: return $ret;
447: }
448:
449: 450: 451: 452: 453: 454: 455:
456: public function renderFormFile(XoopsFormFile $element)
457: {
458: return '<input class="form-control-static" type="file" name="' . $element->getName()
459: . '" id="' . $element->getName()
460: . '" title="' . $element->getTitle() . '" ' . $element->getExtra() . ' />'
461: . '<input type="hidden" name="MAX_FILE_SIZE" value="' . $element->getMaxFileSize() . '" />'
462: . '<input type="hidden" name="xoops_upload_file[]" id="xoops_upload_file[]" value="'
463: . $element->getName() . '" />';
464: }
465:
466: 467: 468: 469: 470: 471: 472:
473: public function renderFormLabel(XoopsFormLabel $element)
474: {
475: return '<div class="form-control-static">' . $element->getValue() . '</div>';
476: }
477:
478: 479: 480: 481: 482: 483: 484:
485: public function renderFormPassword(XoopsFormPassword $element)
486: {
487: return '<input class="form-control" type="password" name="'
488: . $element->getName() . '" id="' . $element->getName() . '" size="' . $element->getSize()
489: . '" maxlength="' . $element->getMaxlength() . '" value="' . $element->getValue() . '"'
490: . $element->getExtra() . ' ' . ($element->autoComplete ? '' : 'autocomplete="off" ') . '/>';
491: }
492:
493: 494: 495: 496: 497: 498: 499:
500: public function renderFormRadio(XoopsFormRadio $element)
501: {
502:
503: $elementName = $element->getName();
504: $elementId = $elementName;
505:
506: switch ((int) ($element->columns)) {
507: case 0:
508: return $this->renderCheckedInline($element, 'radio', $elementId, $elementName);
509: case 1:
510: return $this->renderCheckedOneColumn($element, 'radio', $elementId, $elementName);
511: default:
512: return $this->renderCheckedColumnar($element, 'radio', $elementId, $elementName);
513: }
514: }
515:
516: 517: 518: 519: 520: 521: 522:
523: public function renderFormSelect(XoopsFormSelect $element)
524: {
525: $ele_name = $element->getName();
526: $ele_title = $element->getTitle();
527: $ele_value = $element->getValue();
528: $ele_options = $element->getOptions();
529: $ret = '<select class="form-control" size="'
530: . $element->getSize() . '"' . $element->getExtra();
531: if ($element->isMultiple() != false) {
532: $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title
533: . '" multiple="multiple">';
534: } else {
535: $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
536: }
537: foreach ($ele_options as $value => $name) {
538: $ret .= '<option value="' . htmlspecialchars($value, ENT_QUOTES) . '"';
539: if (count($ele_value) > 0 && in_array($value, $ele_value)) {
540: $ret .= ' selected';
541: }
542: $ret .= '>' . $name . '</option>';
543: }
544: $ret .= '</select>';
545:
546: return $ret;
547: }
548: 549: 550: 551: 552: 553: 554:
555: public function renderFormText(XoopsFormText $element)
556: {
557: return "<input class='form-control' type='text' name='"
558: . $element->getName() . "' title='" . $element->getTitle() . "' id='" . $element->getName()
559: . "' size='" . $element->getSize() . "' maxlength='" . $element->getMaxlength()
560: . "' value='" . $element->getValue() . "'" . $element->getExtra() . ' />';
561: }
562:
563: 564: 565: 566: 567: 568: 569:
570: public function renderFormTextArea(XoopsFormTextArea $element)
571: {
572: return "<textarea class='form-control' name='"
573: . $element->getName() . "' id='" . $element->getName() . "' title='" . $element->getTitle()
574: . "' rows='" . $element->getRows() . "' cols='" . $element->getCols() . "'"
575: . $element->getExtra() . '>' . $element->getValue() . '</textarea>';
576: }
577:
578: 579: 580: 581: 582: 583: 584:
585: public function renderFormTextDateSelect(XoopsFormTextDateSelect $element)
586: {
587: static $included = false;
588: if (file_exists(XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/calendar.php')) {
589: include_once XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/calendar.php';
590: } else {
591: include_once XOOPS_ROOT_PATH . '/language/english/calendar.php';
592: }
593:
594: $ele_name = $element->getName();
595: $ele_value = $element->getValue(false);
596: if (is_string($ele_value)) {
597: $display_value = $ele_value;
598: $ele_value = time();
599: } else {
600: $display_value = date(_SHORTDATESTRING, $ele_value);
601: }
602:
603: $jstime = formatTimestamp($ele_value, _SHORTDATESTRING);
604: if (isset($GLOBALS['xoTheme']) && is_object($GLOBALS['xoTheme'])) {
605: $GLOBALS['xoTheme']->addScript('include/calendar.js');
606: $GLOBALS['xoTheme']->addStylesheet('include/calendar-blue.css');
607: if (!$included) {
608: $included = true;
609: $GLOBALS['xoTheme']->addScript('', '', '
610: var calendar = null;
611:
612: function selected(cal, date)
613: {
614: cal.sel.value = date;
615: }
616:
617: function closeHandler(cal)
618: {
619: cal.hide();
620: Calendar.removeEvent(document, "mousedown", checkCalendar);
621: }
622:
623: function checkCalendar(ev)
624: {
625: var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
626: for (; el != null; el = el.parentNode)
627: if (el == calendar.element || el.tagName == "A") break;
628: if (el == null) {
629: calendar.callCloseHandler(); Calendar.stopEvent(ev);
630: }
631: }
632: function showCalendar(id)
633: {
634: var el = xoopsGetElementById(id);
635: if (calendar != null) {
636: calendar.hide();
637: } else {
638: var cal = new Calendar(true, "' . $jstime . '", selected, closeHandler);
639: calendar = cal;
640: cal.setRange(1900, 2100);
641: calendar.create();
642: }
643: calendar.sel = el;
644: calendar.parseDate(el.value);
645: calendar.showAtElement(el);
646: Calendar.addEvent(document, "mousedown", checkCalendar);
647:
648: return false;
649: }
650:
651: Calendar._DN = new Array
652: ("' . _CAL_SUNDAY . '",
653: "' . _CAL_MONDAY . '",
654: "' . _CAL_TUESDAY . '",
655: "' . _CAL_WEDNESDAY . '",
656: "' . _CAL_THURSDAY . '",
657: "' . _CAL_FRIDAY . '",
658: "' . _CAL_SATURDAY . '",
659: "' . _CAL_SUNDAY . '");
660: Calendar._MN = new Array
661: ("' . _CAL_JANUARY . '",
662: "' . _CAL_FEBRUARY . '",
663: "' . _CAL_MARCH . '",
664: "' . _CAL_APRIL . '",
665: "' . _CAL_MAY . '",
666: "' . _CAL_JUNE . '",
667: "' . _CAL_JULY . '",
668: "' . _CAL_AUGUST . '",
669: "' . _CAL_SEPTEMBER . '",
670: "' . _CAL_OCTOBER . '",
671: "' . _CAL_NOVEMBER . '",
672: "' . _CAL_DECEMBER . '");
673:
674: Calendar._TT = {};
675: Calendar._TT["TOGGLE"] = "' . _CAL_TGL1STD . '";
676: Calendar._TT["PREV_YEAR"] = "' . _CAL_PREVYR . '";
677: Calendar._TT["PREV_MONTH"] = "' . _CAL_PREVMNTH . '";
678: Calendar._TT["GO_TODAY"] = "' . _CAL_GOTODAY . '";
679: Calendar._TT["NEXT_MONTH"] = "' . _CAL_NXTMNTH . '";
680: Calendar._TT["NEXT_YEAR"] = "' . _CAL_NEXTYR . '";
681: Calendar._TT["SEL_DATE"] = "' . _CAL_SELDATE . '";
682: Calendar._TT["DRAG_TO_MOVE"] = "' . _CAL_DRAGMOVE . '";
683: Calendar._TT["PART_TODAY"] = "(' . _CAL_TODAY . ')";
684: Calendar._TT["MON_FIRST"] = "' . _CAL_DISPM1ST . '";
685: Calendar._TT["SUN_FIRST"] = "' . _CAL_DISPS1ST . '";
686: Calendar._TT["CLOSE"] = "' . _CLOSE . '";
687: Calendar._TT["TODAY"] = "' . _CAL_TODAY . '";
688:
689: // date formats
690: Calendar._TT["DEF_DATE_FORMAT"] = "' . _SHORTDATESTRING . '";
691: Calendar._TT["TT_DATE_FORMAT"] = "' . _SHORTDATESTRING . '";
692:
693: Calendar._TT["WK"] = "";
694: ');
695: }
696: }
697: return '<div class="input-group">'
698: . '<input class="form-control" type="text" name="' . $ele_name . '" id="' . $ele_name
699: . '" size="' . $element->getSize() . '" maxlength="' . $element->getMaxlength()
700: . '" value="' . $display_value . '"' . $element->getExtra() . ' />'
701: . '<span class="input-group-btn"><button class="btn btn-default" type="button"'
702: . ' onclick="return showCalendar(\'' . $ele_name . '\');">'
703: . '<span class="fa fa-calendar" aria-hidden="true"></span></button>'
704: . '</span>'
705: . '</div>';
706: }
707:
708: 709: 710: 711: 712: 713: 714:
715: public function renderThemeForm(XoopsThemeForm $form)
716: {
717: $ele_name = $form->getName();
718:
719: $ret = '<div>';
720: $ret .= '<form class="form-horizontal" name="' . $ele_name . '" id="' . $ele_name . '" action="'
721: . $form->getAction() . '" method="' . $form->getMethod()
722: . '" onsubmit="return xoopsFormValidate_' . $ele_name . '();"' . $form->getExtra() . '>'
723: . '<h3>' . $form->getTitle() . '</h3>';
724: $hidden = '';
725:
726: foreach ($form->getElements() as $element) {
727: if (!is_object($element)) {
728: $ret .= $element;
729: continue;
730: }
731: if ($element->isHidden()) {
732: $hidden .= $element->render();
733: continue;
734: }
735:
736: $ret .= '<div class="form-group">';
737: if (($caption = $element->getCaption()) != '') {
738: $ret .= '<label for="' . $element->getName() . '" class="col-md-2 control-label">'
739: . $element->getCaption()
740: . ($element->isRequired() ? '<span class="caption-required">*</span>' : '')
741: . '</label>';
742: } else {
743: $ret .= '<div class="col-md-2"> </div>';
744: }
745: $ret .= '<div class="col-md-10">';
746: $ret .= $element->render();
747: if (($desc = $element->getDescription()) != '') {
748: $ret .= '<p class="help-block">' . $desc . '</p>';
749: }
750: $ret .= '</div>';
751: $ret .= '</div>';
752: }
753: $ret .= $hidden;
754: $ret .= '</form></div>';
755: $ret .= $form->renderValidationJS(true);
756:
757: return $ret;
758: }
759:
760: 761: 762: 763: 764: 765: 766: 767: 768:
769: public function addThemeFormBreak(XoopsThemeForm $form, $extra, $class)
770: {
771: $class = ($class != '') ? preg_replace('/[^A-Za-z0-9\s\s_-]/i', '', $class) : '';
772: $form->addElement('<div class="col-sm-12 ' . $class .'">'. $extra . '</div>');
773: }
774: }
775: