Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FormTrait.php « traits « src - github.com/HuasoFoundries/phpPgAdmin6.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bb4ccd3cab84a1ac6802ee811a1412300906ccff (plain)
1
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php

/**
 * PHPPgAdmin6
 */

namespace PHPPgAdmin\Traits;

/**
 * Common trait to print form parts that appear on different controller dialogs.
 */
trait FormTrait
{
    public $misc;

    /**
     * Prints inputs for action, table and submit/cancel buttons.
     *
     * @param string $action value for action input
     * @param string $table  value for table input
     * @param string $add    text for add button
     * @param string $cancel text for cancel button
     *
     * @return string
     */
    public function getActionTableAndButtons($action, $table, $add, $cancel)
    {
        $content = $this->view->form;
        $content .= \sprintf('<input type="hidden" name="action" value="%s" />%s', $action, \PHP_EOL);
        $content .= \sprintf('<input type="hidden" name="table" value="%s" />%s', $table, \PHP_EOL);
        $content .= \sprintf('<input type="submit" value="%s" />%s', $add, \PHP_EOL);
        $content .= \sprintf('<input type="submit" name="cancel" value="%s" />', $cancel);

        return $content;
    }

    /**
     * Prints inputs for action, table and submit/cancel buttons.
     *
     * @param array $inputs   array of inputs with their name, type and value
     * @param array $buttons  array of buttons with their name, type and value
     * @param array $cheboxes array of cheboxes with their name, id, checked state, type and text for label
     *
     * @return string
     */
    public function getFormInputsAndButtons($inputs, $buttons, $cheboxes = [])
    {
        $content = $this->view->form;

        foreach ($cheboxes as $checkbox) {
            $content .= \sprintf('<p>%s', \PHP_EOL);
            $content .= \sprintf('<input type="%s" name="%s" id="%s" %s />', $checkbox['type'], $checkbox['name'], $checkbox['id'], $checkbox['checked'] ? 'checked="checked"' : '');
            $content .= \sprintf('<label for="%s">%s</label>', $checkbox['id'], $checkbox['labeltext']);
            $content .= \sprintf('</p>%s', \PHP_EOL);
        }

        foreach ($inputs as $input) {
            $content .= \sprintf('<input type="%s" name="%s" value="%s" />%s', $input['type'], $input['name'], $input['value'], \PHP_EOL);
        }

        $content .= \sprintf('<p>%s', \PHP_EOL);

        foreach ($buttons as $button) {
            $content .= \sprintf('<input type="%s" name="%s" value="%s" />%s', $button['type'], $button['name'], $button['value'], \PHP_EOL);
        }

        $content .= \sprintf('</p>%s', \PHP_EOL);

        return $content;
    }
}