1<?php 2 3declare(strict_types=1); 4 5use Fisharebest\Webtrees\I18N; 6use Illuminate\Support\Collection; 7 8/** 9 * @var string $dbhost 10 * @var string $dbname 11 * @var string $dbpass 12 * @var string $dbport 13 * @var string $dbtype 14 * @var string $dbuser 15 * @var Collection<int,string> $errors 16 * @var string $lang 17 * @var string $tblpfx 18 * @var Collection<int,string> $warnings 19 * @var string $wtemail 20 * @var string $wtname 21 * @var string $wtpass 22 * @var string $wtuser 23 */ 24 25?> 26 27<form method="post" autocomplete="off"> 28 <input name="lang" type="hidden" value="<?= e($lang) ?>"> 29 <input name="dbtype" type="hidden" value="<?= e($dbtype) ?>"> 30 <input name="wtname" type="hidden" value="<?= e($wtname) ?>"> 31 <input name="wtuser" type="hidden" value="<?= e($wtuser) ?>"> 32 <input name="wtpass" type="hidden" value="<?= e($wtpass) ?>"> 33 <input name="wtemail" type="hidden" value="<?= e($wtemail) ?>"> 34 35 <h2> 36 <?= I18N::translate('Database connection') ?> – MySQL / MariaDB / Percona 37 </h2> 38 39 <?php foreach ($errors as $error) : ?> 40 <p class="alert alert-danger"><?= $error ?></p> 41 <?php endforeach ?> 42 43 <?php foreach ($warnings as $warning) : ?> 44 <p class="alert alert-warning"><?= $warning ?></p> 45 <?php endforeach ?> 46 47 <div class="row mb-3"> 48 <div class="col"> 49 <?= I18N::translate('Connection type') ?> 50 </div> 51 </div> 52 53 <div class="row mb-3"> 54 <div class="col-sm-3"> 55 <div class="form-check"> 56 <input type="radio" name="mysql-type" id="mysql-type-local" class="form-check-input" <?= ($dbhost === '' || $dbhost === 'localhost') ? 'checked="checked"' : '' ?>"> 57 <label class="form-check-label" for="mysql-type-local"> 58 <?= I18N::translate('local') ?> 59 </label> 60 </div> 61 </div> 62 63 <div class="col-sm-9"> 64 <input type="text" value="localhost:<?= ini_get('pdo_mysql.default_socket') ?>" class="form-control" readonly="readonly"> 65 </div> 66 </div> 67 68 <div class="row mb-3"> 69 <div class="col-sm-3"> 70 <div class="form-check"> 71 <input type="radio" name="mysql-type" id="mysql-type-network" class="form-check-input" <?= ($dbhost === '' || $dbhost === 'localhost') ? '' : 'checked="checked"' ?>"> 72 <label class="form-check-label" for="mysql-type-network"> 73 <?= I18N::translate('network') ?> 74 </label> 75 </div> 76 </div> 77 78 <div class="col-sm-9"> 79 <div class="row"> 80 <div class="col-8"> 81 <label class="form-label" for="dbhost"> 82 <?= I18N::translate('Server name') ?> 83 </label> 84 </div> 85 <div class="col-4"> 86 <label class="form-label" for="dbport"> 87 <?= I18N::translate('Port number') ?> 88 </label> 89 </div> 90 </div> 91 92 <div class="row"> 93 <div class="col-8"> 94 <input class="form-control" id="dbhost" name="dbhost" type="text" value="<?= e($dbhost === 'localhost' ? '' : $dbhost) ?>" dir="ltr"> 95 </div> 96 <div class="col-4"> 97 <input class="form-control" id="dbport" name="dbport" pattern="\d+" type="text" value="<?= e($dbport ?: '3306') ?>" dir="ltr"> 98 </div> 99 </div> 100 </div> 101 </div> 102 103 <div class="row mb-3"> 104 <label class="col-form-label col-sm-3" for="dbuser"> 105 <?= I18N::translate('Database user account') ?> 106 </label> 107 108 <div class="col-sm-9"> 109 <input class="form-control" id="dbuser" name="dbuser" type="text" value="<?= e($dbuser) ?>" dir="ltr"> 110 </div> 111 </div> 112 113 <div class="row mb-3"> 114 <label class="col-form-label col-sm-3" for="dbpass"> 115 <?= I18N::translate('Database password') ?> 116 </label> 117 118 <div class="col-sm-9"> 119 <input class="form-control" id="dbpass" name="dbpass" type="password" value="<?= e($dbpass) ?>" dir="ltr" autocomplete="off" data-wt-show-password-text="<?= e(I18N::translate('show')) ?>" data-wt-show-password-title="<?= e(I18N::translate('Show password')) ?>" data-wt-hide-password-text="<?= e(I18N::translate('hide')) ?>" data-wt-hide-password-title="<?= e(I18N::translate('Hide password')) ?>"> 120 </div> 121 </div> 122 123 <div class="row mb-3"> 124 <label class="col-form-label col-sm-3" for="dbname"> 125 <?= I18N::translate('Database name') ?> 126 </label> 127 128 <div class="col-sm-9"> 129 <input class="form-control" dir="ltr" id="dbname" name="dbname" pattern="[^`'"]{1,64}" type="text" value="<?= e($dbname) ?>"> 130 </div> 131 </div> 132 133 <div class="row mb-3"> 134 <label class="col-form-label col-sm-3" for="tblpfx"> 135 <?= I18N::translate('Table prefix') ?> 136 </label> 137 <div class="col-sm-9"> 138 <input class="form-control" dir="ltr" id="tblpfx" maxlength="15" name="tblpfx" pattern="[a-zA-Z0-9_]+" type="text" value="<?= e($tblpfx) ?>"> 139 <div class="form-text"> 140 <?= 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.') ?> 141 <?= I18N::translate('Use letters A-Z, a-z, digits 0-9, or underscores') ?> 142 </div> 143 </div> 144 </div> 145 146 <hr> 147 148 <div class="d-flex justify-content-between"> 149 <button class="btn btn-primary" name="step" type="submit" value="5"> 150 <?= I18N::translate('next') ?> 151 </button> 152 153 <button class="btn btn-secondary" name="step" type="submit" value="3"> 154 <?= I18N::translate('previous') ?> 155 </button> 156 </div> 157</form> 158 159<script> 160 (function () { 161 const inputDbHost = document.getElementById('dbhost'); 162 163 document.getElementById('mysql-type-local').addEventListener('click', () => inputDbHost.value = ''); 164 165 inputDbHost.addEventListener('change', () => { 166 if (inputDbHost.value === 'localhost') { 167 inputDbHost.value = ''; 168 } 169 if (inputDbHost.value === '') { 170 document.getElementById('mysql-type-local').click(); 171 } else { 172 document.getElementById('mysql-type-network').click(); 173 } 174 }); 175 176 document.querySelector('form').addEventListener('submit', () => { 177 if (inputDbHost.value === '') { 178 inputDbHost.value = 'localhost' 179 } 180 }); 181 })(); 182</script> 183