Bearsampp
2026.9.23
Toggle main menu visibility
Loading...
Searching...
No Matches
class.action.addAlias.php
Go to the documentation of this file.
1
<?php
2
/*
3
* Copyright (c) 2021-2026 Bearsampp
4
* License: GNU General Public License version 3 or later; see LICENSE.txt
5
* Author: Bear
6
* Website: https://bearsampp.com
7
* Github: https://github.com/Bearsampp
8
*/
9
14
class
ActionAddAlias
extends
ActionDialogBase
15
{
17
private
$wbLabelName
;
19
private
$wbInputName
;
21
private
$wbLabelDest
;
23
private
$wbInputDest
;
25
private
$wbBtnDest
;
27
private
$wbLabelExp
;
28
34
protected
function
getWindowTitle
()
35
{
36
global
$bearsamppLang
;
37
38
return
$bearsamppLang
->getValue(
Lang::ADD_ALIAS_TITLE
);
39
}
40
46
protected
function
getDialogTitle
()
47
{
48
global
$bearsamppLang
;
49
50
return
$bearsamppLang
->getValue(
Lang::ADD_ALIAS_TITLE
);
51
}
52
58
protected
function
getDeleteDialogTitle
()
59
{
60
// Not used in add mode
61
return
''
;
62
}
63
71
protected
function
createFormFields
($bearsamppWinbinder)
72
{
73
global
$bearsamppLang
,
$bearsamppBins
;
74
75
$initName =
'test'
;
76
$initDest =
'C:\\'
;
77
$apachePortUri =
$bearsamppBins
->getApache()->getPort() != 80 ?
':'
.
$bearsamppBins
->getApache()->getPort() :
''
;
78
79
$this->wbLabelName = $bearsamppWinbinder->createLabel(
80
$this->wbWindow,
81
$bearsamppLang
->getValue(
Lang::ALIAS_NAME_LABEL
) .
' :'
,
82
15,
83
15,
84
85,
85
null
,
86
WBC_RIGHT
87
);
88
$this->wbInputName = $bearsamppWinbinder->createInputText(
89
$this->wbWindow,
90
$initName,
91
105,
92
13,
93
150,
94
null
95
);
96
97
$this->wbLabelDest = $bearsamppWinbinder->createLabel(
98
$this->wbWindow,
99
$bearsamppLang
->getValue(
Lang::ALIAS_DEST_LABEL
) .
' :'
,
100
15,
101
45,
102
85,
103
null
,
104
WBC_RIGHT
105
);
106
$this->wbInputDest = $bearsamppWinbinder->createInputText(
107
$this->wbWindow,
108
$initDest,
109
105,
110
43,
111
190,
112
null
,
113
null
,
114
WBC_READONLY
115
);
116
$this->wbBtnDest = $bearsamppWinbinder->createButton(
117
$this->wbWindow,
118
$bearsamppLang
->getValue(
Lang::BUTTON_BROWSE
),
119
300,
120
43,
121
110
122
);
123
124
$this->wbLabelExp = $bearsamppWinbinder->createLabel(
125
$this->wbWindow,
126
sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_EXP_LABEL
), $apachePortUri, $initName, $initDest),
127
15,
128
80,
129
470,
130
50
131
);
132
}
133
141
protected
function
getFormValues
($bearsamppWinbinder)
142
{
143
return
[
144
'name'
=> $bearsamppWinbinder->getText($this->wbInputName[
WinBinder::CTRL_OBJ
]),
145
'dest'
=> $bearsamppWinbinder->getText($this->wbInputDest[
WinBinder::CTRL_OBJ
])
146
];
147
}
148
156
protected
function
validateInput
($values)
157
{
158
global
$bearsamppLang
;
159
160
if
(!ctype_alnum($values[
'name'
])) {
161
return
[
162
'valid'
=>
false
,
163
'error'
=> sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_NOT_VALID_ALPHA
), $values[
'name'
])
164
];
165
}
166
167
return
[
'valid'
=>
true
];
168
}
169
177
protected
function
itemExists
($values)
178
{
179
global
$bearsamppRoot
,
$bearsamppLang
, $bearsamppWinbinder;
180
181
if
(is_file(
Path::getAliasPath
() .
'/'
. $values[
'name'
] .
'.conf'
)) {
182
$bearsamppWinbinder->messageBoxError(
183
sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_ALREADY_EXISTS
), $values[
'name'
]),
184
$this->getDialogTitle()
185
);
186
187
return
true
;
188
}
189
190
return
false
;
191
}
192
200
protected
function
saveItem
($values)
201
{
202
global
$bearsamppRoot
,
$bearsamppBins
;
203
204
return
file_put_contents(
205
Path::getAliasPath
() .
'/'
. $values[
'name'
] .
'.conf'
,
206
$bearsamppBins
->getApache()->getAliasContent($values[
'name'
], $values[
'dest'
])
207
) !==
false
;
208
}
209
215
protected
function
deleteItem
()
216
{
217
// Not used in add mode
218
return
false
;
219
}
220
228
protected
function
getSaveSuccessMessage
($values)
229
{
230
global
$bearsamppLang
,
$bearsamppBins
;
231
232
$apachePortUri =
$bearsamppBins
->getApache()->getPort() != 80 ?
':'
.
$bearsamppBins
->getApache()->getPort() :
''
;
233
234
return
sprintf(
235
$bearsamppLang
->getValue(
Lang::ALIAS_CREATED
),
236
$values[
'name'
],
237
$apachePortUri,
238
$values[
'name'
],
239
$values[
'dest'
]
240
);
241
}
242
248
protected
function
getSaveErrorMessage
()
249
{
250
global
$bearsamppLang
;
251
252
return
$bearsamppLang
->getValue(
Lang::ALIAS_CREATED_ERROR
);
253
}
254
260
protected
function
getDeleteConfirmMessage
()
261
{
262
// Not used in add mode
263
return
''
;
264
}
265
271
protected
function
getDeleteSuccessMessage
()
272
{
273
// Not used in add mode
274
return
''
;
275
}
276
282
protected
function
getDeleteErrorMessage
()
283
{
284
// Not used in add mode
285
return
''
;
286
}
287
293
protected
function
restartService
()
294
{
295
global
$bearsamppBins
;
296
$bearsamppBins
->getApache()->getService()->restart();
297
}
298
310
protected
function
handleCustomEvent
($window, $id, $ctrl, $param1, $param2)
311
{
312
global
$bearsamppLang
,
$bearsamppBins
, $bearsamppWinbinder;
313
314
$apachePortUri =
$bearsamppBins
->getApache()->getPort() != 80 ?
':'
.
$bearsamppBins
->getApache()->getPort() :
''
;
315
$aliasName = $bearsamppWinbinder->getText($this->wbInputName[
WinBinder::CTRL_OBJ
]);
316
$aliasDest = $bearsamppWinbinder->getText($this->wbInputDest[
WinBinder::CTRL_OBJ
]);
317
318
// Handle name input change
319
if
($id == $this->wbInputName[
WinBinder::CTRL_ID
]) {
320
$bearsamppWinbinder->setText(
321
$this->wbLabelExp[
WinBinder::CTRL_OBJ
],
322
sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_EXP_LABEL
), $apachePortUri, $aliasName, $aliasDest)
323
);
324
$bearsamppWinbinder->setEnabled(
325
$this->wbBtnSave[
WinBinder::CTRL_OBJ
],
326
!empty($aliasName)
327
);
328
}
329
330
// Handle browse button
331
if
($id == $this->wbBtnDest[
WinBinder::CTRL_ID
]) {
332
$aliasDest = $bearsamppWinbinder->sysDlgPath(
333
$window,
334
$bearsamppLang
->getValue(
Lang::ALIAS_DEST_PATH
),
335
$aliasDest
336
);
337
if
($aliasDest && is_dir($aliasDest)) {
338
$bearsamppWinbinder->setText($this->wbInputDest[
WinBinder::CTRL_OBJ
], $aliasDest .
'\\'
);
339
$bearsamppWinbinder->setText(
340
$this->wbLabelExp[
WinBinder::CTRL_OBJ
],
341
sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_EXP_LABEL
), $apachePortUri, $aliasName, $aliasDest .
'\\'
)
342
);
343
}
344
}
345
}
346
}
347
$bearsamppBins
global $bearsamppBins
Definition
ajax.apache.php:16
$bearsamppLang
global $bearsamppLang
Definition
ajax.apache.php:16
$bearsamppRoot
global $bearsamppRoot
Definition
ajax.apache.php:16
ActionAddAlias
Definition
class.action.addAlias.php:15
ActionAddAlias\createFormFields
createFormFields($bearsamppWinbinder)
Definition
class.action.addAlias.php:71
ActionAddAlias\$wbInputDest
$wbInputDest
Definition
class.action.addAlias.php:23
ActionAddAlias\$wbLabelExp
$wbLabelExp
Definition
class.action.addAlias.php:27
ActionAddAlias\$wbLabelName
$wbLabelName
Definition
class.action.addAlias.php:17
ActionAddAlias\getDeleteSuccessMessage
getDeleteSuccessMessage()
Definition
class.action.addAlias.php:271
ActionAddAlias\handleCustomEvent
handleCustomEvent($window, $id, $ctrl, $param1, $param2)
Definition
class.action.addAlias.php:310
ActionAddAlias\$wbBtnDest
$wbBtnDest
Definition
class.action.addAlias.php:25
ActionAddAlias\$wbLabelDest
$wbLabelDest
Definition
class.action.addAlias.php:21
ActionAddAlias\validateInput
validateInput($values)
Definition
class.action.addAlias.php:156
ActionAddAlias\getSaveSuccessMessage
getSaveSuccessMessage($values)
Definition
class.action.addAlias.php:228
ActionAddAlias\getDeleteDialogTitle
getDeleteDialogTitle()
Definition
class.action.addAlias.php:58
ActionAddAlias\getSaveErrorMessage
getSaveErrorMessage()
Definition
class.action.addAlias.php:248
ActionAddAlias\restartService
restartService()
Definition
class.action.addAlias.php:293
ActionAddAlias\getDeleteErrorMessage
getDeleteErrorMessage()
Definition
class.action.addAlias.php:282
ActionAddAlias\$wbInputName
$wbInputName
Definition
class.action.addAlias.php:19
ActionAddAlias\getDialogTitle
getDialogTitle()
Definition
class.action.addAlias.php:46
ActionAddAlias\saveItem
saveItem($values)
Definition
class.action.addAlias.php:200
ActionAddAlias\deleteItem
deleteItem()
Definition
class.action.addAlias.php:215
ActionAddAlias\getDeleteConfirmMessage
getDeleteConfirmMessage()
Definition
class.action.addAlias.php:260
ActionAddAlias\getWindowTitle
getWindowTitle()
Definition
class.action.addAlias.php:34
ActionAddAlias\getFormValues
getFormValues($bearsamppWinbinder)
Definition
class.action.addAlias.php:141
ActionAddAlias\itemExists
itemExists($values)
Definition
class.action.addAlias.php:177
ActionDialogBase
Definition
class.action.dialogBase.php:18
Lang\BUTTON_BROWSE
const BUTTON_BROWSE
Definition
class.lang.php:380
Lang\ADD_ALIAS_TITLE
const ADD_ALIAS_TITLE
Definition
class.lang.php:218
Lang\ALIAS_DEST_LABEL
const ALIAS_DEST_LABEL
Definition
class.lang.php:220
Lang\ALIAS_NAME_LABEL
const ALIAS_NAME_LABEL
Definition
class.lang.php:219
Lang\ALIAS_DEST_PATH
const ALIAS_DEST_PATH
Definition
class.lang.php:222
Lang\ALIAS_CREATED
const ALIAS_CREATED
Definition
class.lang.php:225
Lang\ALIAS_ALREADY_EXISTS
const ALIAS_ALREADY_EXISTS
Definition
class.lang.php:224
Lang\ALIAS_EXP_LABEL
const ALIAS_EXP_LABEL
Definition
class.lang.php:221
Lang\ALIAS_NOT_VALID_ALPHA
const ALIAS_NOT_VALID_ALPHA
Definition
class.lang.php:223
Lang\ALIAS_CREATED_ERROR
const ALIAS_CREATED_ERROR
Definition
class.lang.php:226
Path\getAliasPath
static getAliasPath($aetrayPath=false)
Definition
class.path.php:348
WinBinder\CTRL_ID
const CTRL_ID
Definition
class.winbinder.php:21
WinBinder\CTRL_OBJ
const CTRL_OBJ
Definition
class.winbinder.php:22
sandbox
core
classes
actions
class.action.addAlias.php
Generated by
1.17.0