2018-04-04 23:46:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Bootstrap {
|
|
|
|
|
2018-07-25 23:42:00 +02:00
|
|
|
public static function modal($args) {
|
|
|
|
|
|
|
|
$buttonSecondary = $args['buttonSecondary'];
|
|
|
|
$buttonSecondaryClass = $args['buttonSecondaryClass'];
|
|
|
|
|
|
|
|
$buttonPrimary = $args['buttonPrimary'];
|
|
|
|
$buttonPrimaryClass = $args['buttonPrimaryClass'];
|
|
|
|
|
|
|
|
$modalText = $args['modalText'];
|
|
|
|
$modalTitle = $args['modalTitle'];
|
|
|
|
$modalId = $args['modalId'];
|
|
|
|
|
|
|
|
|
|
|
|
return <<<EOF
|
|
|
|
<div id="$modalId" class="modal fade" tabindex="-1" role="dialog">
|
|
|
|
<div class="modal-dialog" role="document">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-body">
|
|
|
|
<h3>$modalTitle</h3>
|
|
|
|
<p>$modalText</p>
|
|
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
2018-11-25 17:54:26 +01:00
|
|
|
<button type="button" class="btn $buttonSecondaryClass" data-dismiss="modal">$buttonSecondary</button>
|
2018-11-28 22:01:55 +01:00
|
|
|
<button type="button" class="btn $buttonPrimaryClass">$buttonPrimary</button>
|
2018-07-25 23:42:00 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
EOF;
|
|
|
|
}
|
|
|
|
|
2018-04-15 22:23:11 +02:00
|
|
|
public static function link($args)
|
|
|
|
{
|
|
|
|
$options = 'href="'.$args['href'].'"';
|
|
|
|
if (isset($args['class'])) {
|
|
|
|
$options .= ' class="'.$args['class'].'"';
|
|
|
|
}
|
|
|
|
if (isset($args['target'])) {
|
|
|
|
$options .= ' target="'.$args['target'].'"';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($args['icon'])) {
|
2019-05-24 19:00:22 +02:00
|
|
|
return '<a '.$options.'><span class="fa fa-'.$args['icon'].'"></span>'.$args['title'].'</a>';
|
2018-04-15 22:23:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return '<a '.$options.'>'.$args['title'].'</a>';
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function pageTitle($args)
|
|
|
|
{
|
2018-04-27 20:36:43 +02:00
|
|
|
$icon = $args['icon'];
|
|
|
|
$title = $args['title'];
|
|
|
|
return <<<EOF
|
|
|
|
<h2 class="mt-0 mb-3">
|
2019-05-18 11:54:39 +02:00
|
|
|
<span class="fa fa-$icon" style="font-size: 0.9em;"></span><span>$title</span>
|
2018-04-27 20:36:43 +02:00
|
|
|
</h2>
|
|
|
|
EOF;
|
2018-04-15 22:23:11 +02:00
|
|
|
}
|
|
|
|
|
2018-04-22 17:45:31 +02:00
|
|
|
public static function formOpen($args)
|
|
|
|
{
|
2018-04-27 20:36:43 +02:00
|
|
|
$class = empty($args['class'])?'':'class="'.$args['class'].'"';
|
|
|
|
$id = empty($args['id'])?'':'id="'.$args['id'].'"';
|
|
|
|
$enctype = empty($args['enctype'])?'':'enctype="'.$args['enctype'].'"';
|
|
|
|
$action = empty($args['action'])?'action=""':'action="'.$args['action'].'"';
|
|
|
|
$method = empty($args['method'])?'method="post"':'method="'.$args['method'].'"';
|
2018-10-17 22:35:30 +02:00
|
|
|
$style = empty($args['style'])?'':'style="'.$args['style'].'"';
|
2018-04-22 17:45:31 +02:00
|
|
|
|
2018-04-27 20:36:43 +02:00
|
|
|
return <<<EOF
|
2018-10-17 22:35:30 +02:00
|
|
|
<form $class $enctype $id $method $action $style autocomplete="off">
|
2018-04-27 20:36:43 +02:00
|
|
|
EOF;
|
2018-04-22 17:45:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function formClose()
|
|
|
|
{
|
2018-04-27 20:36:43 +02:00
|
|
|
return <<<EOF
|
|
|
|
</form>
|
|
|
|
<script>
|
|
|
|
$(document).ready(function() {
|
|
|
|
// Prevent the form submit when press enter key.
|
|
|
|
$("form").keypress(function(e) {
|
|
|
|
if ((e.which == 13) && (e.target.type !== "textarea")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
EOF;
|
2018-04-22 17:45:31 +02:00
|
|
|
}
|
|
|
|
|
2018-04-04 23:46:36 +02:00
|
|
|
public static function formTitle($args)
|
|
|
|
{
|
2018-04-27 20:36:43 +02:00
|
|
|
$title = $args['title'];
|
|
|
|
return <<<EOF
|
2018-10-30 16:12:44 +01:00
|
|
|
<h6 class="mt-4 mb-2 pb-2 border-bottom text-uppercase">$title</h6>
|
2018-04-27 20:36:43 +02:00
|
|
|
EOF;
|
2018-04-04 23:46:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function formInputTextBlock($args)
|
|
|
|
{
|
2018-10-31 17:56:32 +01:00
|
|
|
$name = $args['name'];
|
|
|
|
$disabled = empty($args['disabled'])?'':'disabled';
|
|
|
|
$placeholder = isset($args['placeholder'])?$args['placeholder']:'';
|
|
|
|
$value = isset($args['value'])?$args['value']:'';
|
2018-11-02 00:21:36 +01:00
|
|
|
|
2018-10-31 17:56:32 +01:00
|
|
|
$id = 'js'.$name;
|
2018-04-04 23:46:36 +02:00
|
|
|
if (isset($args['id'])) {
|
|
|
|
$id = $args['id'];
|
|
|
|
}
|
|
|
|
|
2018-10-31 17:56:32 +01:00
|
|
|
$tip = '';
|
|
|
|
if (isset($args['tip'])) {
|
|
|
|
$tip = '<small class="form-text text-muted">'.$args['tip'].'</small>';
|
2018-04-04 23:46:36 +02:00
|
|
|
}
|
|
|
|
|
2018-10-31 17:56:32 +01:00
|
|
|
$label = '';
|
2018-04-04 23:46:36 +02:00
|
|
|
if (isset($args['label'])) {
|
2018-10-31 17:56:32 +01:00
|
|
|
$label = '<label class="mt-4 mb-2 pb-2 border-bottom text-uppercase w-100" for="'.$id.'">'.$args['label'].'</label>';
|
2018-04-04 23:46:36 +02:00
|
|
|
}
|
|
|
|
|
2018-10-31 17:56:32 +01:00
|
|
|
$class = 'form-control';
|
|
|
|
if (isset($args['class'])) {
|
|
|
|
$class = $class.' '.$args['class'];
|
2018-04-04 23:46:36 +02:00
|
|
|
}
|
|
|
|
|
2018-10-31 17:56:32 +01:00
|
|
|
$type = 'text';
|
|
|
|
if (isset($args['type'])) {
|
|
|
|
$type = $args['type'];
|
|
|
|
}
|
2018-04-04 23:46:36 +02:00
|
|
|
|
2018-10-31 17:56:32 +01:00
|
|
|
return <<<EOF
|
|
|
|
<div class="form-group m-0">
|
|
|
|
$label
|
|
|
|
<input type="text" value="$value" class="$class" id="$id" name="$name" placeholder="$placeholder" $disabled>
|
|
|
|
$tip
|
|
|
|
</div>
|
|
|
|
EOF;
|
2018-04-04 23:46:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function formInputFile($args)
|
|
|
|
{
|
|
|
|
$id = 'js'.$args['name'];
|
|
|
|
if (isset($args['id'])) {
|
|
|
|
$id = $args['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$class = 'custom-file';
|
|
|
|
if (isset($args['class'])) {
|
|
|
|
$class = $class.' '.$args['class'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$html = '<div class="'.$class.'">';
|
|
|
|
$html .= '<input type="file" class="custom-file-input" id="'.$id.'">';
|
|
|
|
$html .= '<label class="custom-file-label" for="'.$id.'">'.$args['label'].'</label>';
|
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function formTextarea($args)
|
|
|
|
{
|
|
|
|
$id = 'js'.$args['name'];
|
|
|
|
if (isset($args['id'])) {
|
|
|
|
$id = $args['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$class = 'form-control';
|
|
|
|
if (isset($args['class'])) {
|
|
|
|
$class = $class.' '.$args['class'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$html = '<div class="form-group row">';
|
|
|
|
|
|
|
|
if (isset($args['label'])) {
|
|
|
|
$html .= '<label for="'.$id.'" class="col-sm-2 col-form-label">'.$args['label'].'</label>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$html .= '<div class="col-sm-10">';
|
2018-11-07 15:40:22 +01:00
|
|
|
$html .= '<textarea class="'.$class.'" id="'.$id.'" name="'.$args['name'].'" rows="'.$args['rows'].'" placeholder="'.$args['placeholder'].'">'.$args['value'].'</textarea>';
|
2018-04-04 23:46:36 +02:00
|
|
|
if (isset($args['tip'])) {
|
|
|
|
$html .= '<small class="form-text text-muted">'.$args['tip'].'</small>';
|
|
|
|
}
|
|
|
|
$html .= '</div>';
|
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
2018-07-07 12:04:34 +02:00
|
|
|
public static function formTextareaBlock($args)
|
|
|
|
{
|
|
|
|
$id = 'js'.$args['name'];
|
|
|
|
if (isset($args['id'])) {
|
|
|
|
$id = $args['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$class = 'form-control';
|
|
|
|
if (!empty($args['class'])) {
|
|
|
|
$class = $class.' '.$args['class'];
|
|
|
|
}
|
|
|
|
|
2018-10-30 16:12:44 +01:00
|
|
|
$html = '<div class="form-group m-0">';
|
2018-07-07 12:04:34 +02:00
|
|
|
if (!empty($args['label'])) {
|
2018-10-30 16:12:44 +01:00
|
|
|
$html .= '<label class="mt-4 mb-2 pb-2 border-bottom text-uppercase w-100" for="'.$id.'">'.$args['label'].'</label>';
|
2018-07-07 12:04:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$html .= '<textarea class="'.$class.'" id="'.$id.'" name="'.$args['name'].'" rows="'.$args['rows'].'" placeholder="'.$args['placeholder'].'">'.$args['value'].'</textarea>';
|
|
|
|
if (!empty($args['tip'])) {
|
|
|
|
$html .= '<small class="form-text text-muted">'.$args['tip'].'</small>';
|
|
|
|
}
|
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
2018-04-04 23:46:36 +02:00
|
|
|
public static function formInputText($args)
|
|
|
|
{
|
2018-10-31 17:56:32 +01:00
|
|
|
$name = $args['name'];
|
|
|
|
$disabled = empty($args['disabled'])?'':'disabled';
|
2018-12-12 18:18:48 +01:00
|
|
|
$readonly = empty($args['readonly'])?'':'readonly';
|
2018-04-27 20:36:43 +02:00
|
|
|
$placeholder = isset($args['placeholder'])?$args['placeholder']:'';
|
|
|
|
$value = isset($args['value'])?$args['value']:'';
|
2018-10-31 17:56:32 +01:00
|
|
|
|
2018-04-27 20:36:43 +02:00
|
|
|
$id = 'js'.$name;
|
2018-04-04 23:46:36 +02:00
|
|
|
if (isset($args['id'])) {
|
|
|
|
$id = $args['id'];
|
|
|
|
}
|
2018-10-31 17:56:32 +01:00
|
|
|
|
|
|
|
$tip = '';
|
|
|
|
if (isset($args['tip'])) {
|
|
|
|
$tip = '<small class="form-text text-muted">'.$args['tip'].'</small>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$label = '';
|
|
|
|
if (isset($args['label'])) {
|
2018-11-02 00:21:36 +01:00
|
|
|
$label = '<label for="'.$id.'" class="col-sm-2 col-form-label">'.$args['label'].'</label>';
|
2018-10-31 17:56:32 +01:00
|
|
|
}
|
2018-04-04 23:46:36 +02:00
|
|
|
|
|
|
|
$class = 'form-control';
|
|
|
|
if (isset($args['class'])) {
|
|
|
|
$class = $class.' '.$args['class'];
|
|
|
|
}
|
|
|
|
|
2018-04-27 20:36:43 +02:00
|
|
|
$type = 'text';
|
|
|
|
if (isset($args['type'])) {
|
|
|
|
$type = $args['type'];
|
2018-04-04 23:46:36 +02:00
|
|
|
}
|
|
|
|
|
2018-04-27 20:36:43 +02:00
|
|
|
return <<<EOF
|
|
|
|
<div class="form-group row">
|
2018-10-31 17:56:32 +01:00
|
|
|
$label
|
2018-04-27 20:36:43 +02:00
|
|
|
<div class="col-sm-10">
|
2018-12-12 18:18:48 +01:00
|
|
|
<input class="$class" id="$id" name="$name" value="$value" placeholder="$placeholder" type="$type" $disabled $readonly>
|
2018-10-31 17:56:32 +01:00
|
|
|
$tip
|
2018-04-27 20:36:43 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
EOF;
|
2018-04-04 23:46:36 +02:00
|
|
|
}
|
|
|
|
|
2018-07-10 18:37:46 +02:00
|
|
|
public static function formCheckbox($args)
|
|
|
|
{
|
|
|
|
$labelForCheckbox = isset($args['labelForCheckbox'])?$args['labelForCheckbox']:'';
|
|
|
|
$placeholder = isset($args['placeholder'])?$args['placeholder']:'';
|
2019-09-03 18:35:30 +02:00
|
|
|
$tip = isset($args['tip'])?'<small class="form-text text-muted">'.$args['tip'].'</small>':'';
|
2018-07-10 18:37:46 +02:00
|
|
|
$value = isset($args['value'])?$args['value']:'';
|
|
|
|
$name = $args['name'];
|
|
|
|
$id = 'js'.$name;
|
|
|
|
if (isset($args['id'])) {
|
|
|
|
$id = $args['id'];
|
|
|
|
}
|
|
|
|
$disabled = isset($args['disabled'])?'disabled':'';
|
|
|
|
|
2019-09-03 18:35:30 +02:00
|
|
|
$class = 'form-group m-0';
|
2018-07-10 18:37:46 +02:00
|
|
|
if (isset($args['class'])) {
|
|
|
|
$class = $class.' '.$args['class'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$type = 'text';
|
|
|
|
if (isset($args['type'])) {
|
|
|
|
$type = $args['type'];
|
|
|
|
}
|
|
|
|
|
2018-10-30 16:12:44 +01:00
|
|
|
$label = '';
|
|
|
|
if (!empty($args['label'])) {
|
|
|
|
$label = '<label class="mt-4 mb-2 pb-2 border-bottom text-uppercase w-100">'.$args['label'].'</label>';
|
|
|
|
}
|
|
|
|
|
2018-07-12 20:03:31 +02:00
|
|
|
$checked = $args['checked']?'checked':'';
|
2019-09-03 18:35:30 +02:00
|
|
|
$value = $checked?'1':'0';
|
2018-07-12 20:03:31 +02:00
|
|
|
|
2018-07-10 18:37:46 +02:00
|
|
|
return <<<EOF
|
2018-07-11 23:36:46 +02:00
|
|
|
<div class="$class">
|
2018-10-30 16:12:44 +01:00
|
|
|
$label
|
|
|
|
<div class="form-check">
|
2019-09-03 18:35:30 +02:00
|
|
|
<input type="hidden" name="$name" value="$value"><input id="$id" type="checkbox" class="form-check-input" onclick="this.previousSibling.value=1-this.previousSibling.value" $checked>
|
2018-10-30 16:12:44 +01:00
|
|
|
<label class="form-check-label" for="$id">$labelForCheckbox</label>
|
2019-09-03 18:35:30 +02:00
|
|
|
$tip
|
2018-07-10 18:37:46 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
EOF;
|
|
|
|
}
|
|
|
|
|
2018-04-04 23:46:36 +02:00
|
|
|
public static function formSelect($args)
|
|
|
|
{
|
|
|
|
$id = 'js'.$args['name'];
|
|
|
|
if (isset($args['id'])) {
|
|
|
|
$id = $args['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$class = 'custom-select';
|
|
|
|
if (isset($args['class'])) {
|
|
|
|
$class = $class.' '.$args['class'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$html = '<div class="form-group row">';
|
|
|
|
|
|
|
|
if (isset($args['label'])) {
|
|
|
|
$html .= '<label for="'.$id.'" class="col-sm-2 col-form-label">'.$args['label'].'</label>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$html .= '<div class="col-sm-10">';
|
|
|
|
$html .= '<select id="'.$id.'" name="'.$args['name'].'" class="'.$class.'">';
|
|
|
|
foreach ($args['options'] as $key=>$value) {
|
|
|
|
$html .= '<option '.(($key==$args['selected'])?'selected':'').' value="'.$key.'">'.$value.'</option>';
|
|
|
|
}
|
|
|
|
$html .= '</select>';
|
|
|
|
if (isset($args['tip'])) {
|
|
|
|
$html .= '<small class="form-text text-muted">'.$args['tip'].'</small>';
|
|
|
|
}
|
|
|
|
$html .= '</div>';
|
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
2018-04-13 23:32:29 +02:00
|
|
|
|
2018-07-07 12:04:34 +02:00
|
|
|
public static function formSelectBlock($args)
|
|
|
|
{
|
|
|
|
$id = 'js'.$args['name'];
|
|
|
|
if (isset($args['id'])) {
|
|
|
|
$id = $args['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$class = 'custom-select';
|
|
|
|
if (!empty($args['class'])) {
|
|
|
|
$class = $class.' '.$args['class'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$html = '<div class="form-group m-0">';
|
|
|
|
|
|
|
|
if (!empty($args['label'])) {
|
2018-10-30 16:12:44 +01:00
|
|
|
$html .= '<label class="mt-4 mb-2 pb-2 border-bottom text-uppercase w-100" for="'.$id.'">'.$args['label'].'</label>';
|
2018-07-07 12:04:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$html .= '<select id="'.$id.'" name="'.$args['name'].'" class="'.$class.'">';
|
|
|
|
if (!empty($args['emptyOption'])) {
|
|
|
|
$html .= '<option value="">'.$args['emptyOption'].'</option>';
|
|
|
|
}
|
|
|
|
foreach ($args['options'] as $key=>$value) {
|
|
|
|
$html .= '<option '.(($key==$args['selected'])?'selected':'').' value="'.$key.'">'.$value.'</option>';
|
|
|
|
}
|
|
|
|
$html .= '</select>';
|
|
|
|
if (!empty($args['tip'])) {
|
|
|
|
$html .= '<small class="form-text text-muted">'.$args['tip'].'</small>';
|
|
|
|
}
|
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
2018-04-13 23:32:29 +02:00
|
|
|
public static function formInputHidden($args)
|
|
|
|
{
|
|
|
|
return '<input type="hidden" id="js'.$args['name'].'" name="'.$args['name'].'" value="'.$args['value'].'">';
|
|
|
|
}
|
2018-07-20 18:36:47 +02:00
|
|
|
|
|
|
|
public static function alert($args)
|
|
|
|
{
|
|
|
|
$class = 'alert';
|
|
|
|
if (!empty($args['class'])) {
|
|
|
|
$class = $class.' '.$args['class'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$text = $args['text'];
|
|
|
|
|
|
|
|
return <<<EOF
|
|
|
|
<div class="$class" role="alert">$text</div>
|
|
|
|
EOF;
|
|
|
|
}
|
2018-04-04 23:46:36 +02:00
|
|
|
}
|