summaryrefslogtreecommitdiff
path: root/resources/views/setup/step-4-database-mysql.phtml
blob: bb3c9c7412c1c114272830ea239976ae92b7496d (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php

declare(strict_types=1);

use Fisharebest\Webtrees\I18N;
use Illuminate\Support\Collection;

/**
 * @var string                 $dbhost
 * @var string                 $dbname
 * @var string                 $dbpass
 * @var string                 $dbport
 * @var string                 $dbtype
 * @var string                 $dbuser
 * @var Collection<int,string> $errors
 * @var string                 $lang
 * @var string                 $mysql_local
 * @var string                 $tblpfx
 * @var Collection<int,string> $warnings
 * @var string                 $wtemail
 * @var string                 $wtname
 * @var string                 $wtpass
 * @var string                 $wtuser
 */

?>

<form method="post" autocomplete="off">
    <input name="lang" type="hidden" value="<?= e($lang) ?>">
    <input name="dbtype" type="hidden" value="<?= e($dbtype) ?>">
    <input name="wtname" type="hidden" value="<?= e($wtname) ?>">
    <input name="wtuser" type="hidden" value="<?= e($wtuser) ?>">
    <input name="wtpass" type="hidden" value="<?= e($wtpass) ?>">
    <input name="wtemail" type="hidden" value="<?= e($wtemail) ?>">

    <h2>
        <?= I18N::translate('Database connection') ?> – MySQL / MariaDB / Percona
    </h2>

    <?php foreach ($errors as $error) : ?>
        <p class="alert alert-danger"><?= $error ?></p>
    <?php endforeach ?>

    <?php foreach ($warnings as $warning) : ?>
        <p class="alert alert-warning"><?= $warning ?></p>
    <?php endforeach ?>

    <div class="row mb-3">
        <div class="col">
            <?= I18N::translate('Connection type') ?>
        </div>
    </div>

    <div class="row mb-3">
        <div class="col-sm-3">
            <div class="form-check">
                <input type="radio" name="mysql-type" id="mysql-type-local" class="form-check-input" <?= ($dbhost === '' || $dbhost === 'localhost') ? 'checked="checked"' : '' ?>">
                <label class="form-check-label" for="mysql-type-local">
                    <?= I18N::translate('local') ?>
                </label>
            </div>
        </div>

        <div class="col-sm-9">
            <input type="text" value="<?= e($mysql_local) ?>" class="form-control" disabled="disabled">
        </div>
    </div>

    <div class="row mb-3">
        <div class="col-sm-3">
            <div class="form-check">
                <input type="radio" name="mysql-type" id="mysql-type-network" class="form-check-input" <?= ($dbhost === '' || $dbhost === 'localhost') ? '' : 'checked="checked"' ?>">
                <label class="form-check-label" for="mysql-type-network">
                    <?= I18N::translate('network') ?>
                </label>
            </div>
        </div>

        <div class="col-sm-9">
            <div class="row">
                <div class="col-8">
                    <label class="form-label" for="dbhost">
                        <?= I18N::translate('Server name') ?>
                    </label>
                </div>
                <div class="col-4">
                    <label class="form-label" for="dbport">
                        <?= I18N::translate('Port number') ?>
                    </label>
                </div>
            </div>

            <div class="row">
                <div class="col-8">
                    <input class="form-control" id="dbhost" name="dbhost" type="text" value="<?= e($dbhost === 'localhost' ? '' : $dbhost) ?>" dir="ltr">
                </div>
                <div class="col-4">
                    <input class="form-control" id="dbport" name="dbport" pattern="\d+" type="text" value="<?= e($dbport ?: '3306') ?>" dir="ltr">
                </div>
            </div>
        </div>
    </div>

    <div class="row mb-3">
        <label class="col-form-label col-sm-3" for="dbuser">
            <?= I18N::translate('Database user account') ?>
        </label>

        <div class="col-sm-9">
            <input class="form-control" id="dbuser" name="dbuser" type="text" value="<?= e($dbuser) ?>" dir="ltr">
        </div>
    </div>

    <div class="row mb-3">
        <label class="col-form-label col-sm-3" for="dbpass">
            <?= I18N::translate('Database password') ?>
        </label>

        <div class="col-sm-9">
            <?= view('edit/password', ['id' => 'dbpass', 'value' => $dbpass]) ?>
        </div>
    </div>

    <div class="row mb-3">
        <label class="col-form-label col-sm-3" for="dbname">
            <?= I18N::translate('Database name') ?>
        </label>

        <div class="col-sm-9">
            <input class="form-control" dir="ltr" id="dbname" name="dbname" pattern="[^`'&quot;]{1,64}" type="text" value="<?= e($dbname) ?>">
        </div>
    </div>

    <div class="row mb-3">
        <label class="col-form-label col-sm-3" for="tblpfx">
            <?= I18N::translate('Table prefix') ?>
        </label>
        <div class="col-sm-9">
            <input class="form-control" dir="ltr" id="tblpfx" maxlength="15"  name="tblpfx" pattern="[a-zA-Z0-9_]+" type="text" value="<?= e($tblpfx) ?>">
            <div class="form-text">
                <?= I18N::translate('The prefix is optional, but recommended. By giving the table names a unique prefix you can let several different applications share the same database.') ?>
                <?= I18N::translate('Use letters A-Z, a-z, digits 0-9, or underscores') ?>
            </div>
        </div>
    </div>

    <hr>

    <div class="d-flex justify-content-between">
        <button class="btn btn-primary" name="step" type="submit" value="5">
            <?= I18N::translate('next') ?>
        </button>

        <button class="btn btn-secondary" name="step" type="submit" value="3">
            <?= I18N::translate('previous') ?>
        </button>
    </div>
</form>

<script>
  (function () {
    const inputDbHost = document.getElementById('dbhost');

    document.getElementById('mysql-type-local').addEventListener('click', () => inputDbHost.value = '');

    inputDbHost.addEventListener('change', () => {
      if (inputDbHost.value === 'localhost') {
        inputDbHost.value = '';
      }
      if (inputDbHost.value === '') {
        document.getElementById('mysql-type-local').click();
      } else {
        document.getElementById('mysql-type-network').click();
      }
    });

    document.querySelector('form').addEventListener('submit', () => {
      if (inputDbHost.value === '') {
        inputDbHost.value = 'localhost'
      }
    });
  })();
</script>