Bearsampp
2026.7.11
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-2024 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
{
16
private
$wbLabelName
;
17
private
$wbInputName
;
18
private
$wbLabelDest
;
19
private
$wbInputDest
;
20
private
$wbBtnDest
;
21
private
$wbLabelExp
;
22
23
protected
function
getWindowTitle
()
24
{
25
global
$bearsamppLang
;
26
return
$bearsamppLang
->getValue(
Lang::ADD_ALIAS_TITLE
);
27
}
28
29
protected
function
getDialogTitle
()
30
{
31
global
$bearsamppLang
;
32
return
$bearsamppLang
->getValue(
Lang::ADD_ALIAS_TITLE
);
33
}
34
35
protected
function
getDeleteDialogTitle
()
36
{
37
// Not used in add mode
38
return
''
;
39
}
40
41
protected
function
createFormFields
($bearsamppWinbinder)
42
{
43
global
$bearsamppLang
,
$bearsamppBins
;
44
45
$initName =
'test'
;
46
$initDest =
'C:\\'
;
47
$apachePortUri =
$bearsamppBins
->getApache()->getPort() != 80 ?
':'
.
$bearsamppBins
->getApache()->getPort() :
''
;
48
49
$this->wbLabelName = $bearsamppWinbinder->createLabel(
50
$this->wbWindow,
51
$bearsamppLang
->getValue(
Lang::ALIAS_NAME_LABEL
) .
' :'
,
52
15, 15, 85,
null
, WBC_RIGHT
53
);
54
$this->wbInputName = $bearsamppWinbinder->createInputText(
55
$this->wbWindow,
56
$initName,
57
105, 13, 150,
null
58
);
59
60
$this->wbLabelDest = $bearsamppWinbinder->createLabel(
61
$this->wbWindow,
62
$bearsamppLang
->getValue(
Lang::ALIAS_DEST_LABEL
) .
' :'
,
63
15, 45, 85,
null
, WBC_RIGHT
64
);
65
$this->wbInputDest = $bearsamppWinbinder->createInputText(
66
$this->wbWindow,
67
$initDest,
68
105, 43, 190,
null
,
null
, WBC_READONLY
69
);
70
$this->wbBtnDest = $bearsamppWinbinder->createButton(
71
$this->wbWindow,
72
$bearsamppLang
->getValue(
Lang::BUTTON_BROWSE
),
73
300, 43, 110
74
);
75
76
$this->wbLabelExp = $bearsamppWinbinder->createLabel(
77
$this->wbWindow,
78
sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_EXP_LABEL
), $apachePortUri, $initName, $initDest),
79
15, 80, 470, 50
80
);
81
}
82
83
protected
function
getFormValues
($bearsamppWinbinder)
84
{
85
return
[
86
'name'
=> $bearsamppWinbinder->getText($this->wbInputName[
WinBinder::CTRL_OBJ
]),
87
'dest'
=> $bearsamppWinbinder->getText($this->wbInputDest[
WinBinder::CTRL_OBJ
])
88
];
89
}
90
91
protected
function
validateInput
($values)
92
{
93
global
$bearsamppLang
;
94
95
if
(!ctype_alnum($values[
'name'
])) {
96
return
[
97
'valid'
=>
false
,
98
'error'
=> sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_NOT_VALID_ALPHA
), $values[
'name'
])
99
];
100
}
101
102
return
[
'valid'
=>
true
];
103
}
104
105
protected
function
itemExists
($values)
106
{
107
global
$bearsamppRoot
,
$bearsamppLang
, $bearsamppWinbinder;
108
109
if
(is_file(
Path::getAliasPath
() .
'/'
. $values[
'name'
] .
'.conf'
)) {
110
$bearsamppWinbinder->messageBoxError(
111
sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_ALREADY_EXISTS
), $values[
'name'
]),
112
$this->getDialogTitle()
113
);
114
return
true
;
115
}
116
117
return
false
;
118
}
119
120
protected
function
saveItem
($values)
121
{
122
global
$bearsamppRoot
,
$bearsamppBins
;
123
124
return
file_put_contents(
125
Path::getAliasPath
() .
'/'
. $values[
'name'
] .
'.conf'
,
126
$bearsamppBins
->getApache()->getAliasContent($values[
'name'
], $values[
'dest'
])
127
) !==
false
;
128
}
129
130
protected
function
deleteItem
()
131
{
132
// Not used in add mode
133
return
false
;
134
}
135
136
protected
function
getSaveSuccessMessage
($values)
137
{
138
global
$bearsamppLang
,
$bearsamppBins
;
139
140
$apachePortUri =
$bearsamppBins
->getApache()->getPort() != 80 ?
':'
.
$bearsamppBins
->getApache()->getPort() :
''
;
141
return
sprintf(
142
$bearsamppLang
->getValue(
Lang::ALIAS_CREATED
),
143
$values[
'name'
],
144
$apachePortUri,
145
$values[
'name'
],
146
$values[
'dest'
]
147
);
148
}
149
150
protected
function
getSaveErrorMessage
()
151
{
152
global
$bearsamppLang
;
153
return
$bearsamppLang
->getValue(
Lang::ALIAS_CREATED_ERROR
);
154
}
155
156
protected
function
getDeleteConfirmMessage
()
157
{
158
// Not used in add mode
159
return
''
;
160
}
161
162
protected
function
getDeleteSuccessMessage
()
163
{
164
// Not used in add mode
165
return
''
;
166
}
167
168
protected
function
getDeleteErrorMessage
()
169
{
170
// Not used in add mode
171
return
''
;
172
}
173
174
protected
function
restartService
()
175
{
176
global
$bearsamppBins
;
177
$bearsamppBins
->getApache()->getService()->restart();
178
}
179
180
protected
function
handleCustomEvent
($window, $id, $ctrl, $param1, $param2)
181
{
182
global
$bearsamppLang
,
$bearsamppBins
, $bearsamppWinbinder;
183
184
$apachePortUri =
$bearsamppBins
->getApache()->getPort() != 80 ?
':'
.
$bearsamppBins
->getApache()->getPort() :
''
;
185
$aliasName = $bearsamppWinbinder->getText($this->wbInputName[
WinBinder::CTRL_OBJ
]);
186
$aliasDest = $bearsamppWinbinder->getText($this->wbInputDest[
WinBinder::CTRL_OBJ
]);
187
188
// Handle name input change
189
if
($id == $this->wbInputName[
WinBinder::CTRL_ID
]) {
190
$bearsamppWinbinder->setText(
191
$this->wbLabelExp[
WinBinder::CTRL_OBJ
],
192
sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_EXP_LABEL
), $apachePortUri, $aliasName, $aliasDest)
193
);
194
$bearsamppWinbinder->setEnabled(
195
$this->wbBtnSave[
WinBinder::CTRL_OBJ
],
196
!empty($aliasName)
197
);
198
}
199
200
// Handle browse button
201
if
($id == $this->wbBtnDest[
WinBinder::CTRL_ID
]) {
202
$aliasDest = $bearsamppWinbinder->sysDlgPath(
203
$window,
204
$bearsamppLang
->getValue(
Lang::ALIAS_DEST_PATH
),
205
$aliasDest
206
);
207
if
($aliasDest && is_dir($aliasDest)) {
208
$bearsamppWinbinder->setText($this->wbInputDest[
WinBinder::CTRL_OBJ
], $aliasDest .
'\\'
);
209
$bearsamppWinbinder->setText(
210
$this->wbLabelExp[
WinBinder::CTRL_OBJ
],
211
sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_EXP_LABEL
), $apachePortUri, $aliasName, $aliasDest .
'\\'
)
212
);
213
}
214
}
215
}
216
}
217
$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:41
ActionAddAlias\$wbInputDest
$wbInputDest
Definition
class.action.addAlias.php:19
ActionAddAlias\$wbLabelExp
$wbLabelExp
Definition
class.action.addAlias.php:21
ActionAddAlias\$wbLabelName
$wbLabelName
Definition
class.action.addAlias.php:16
ActionAddAlias\getDeleteSuccessMessage
getDeleteSuccessMessage()
Definition
class.action.addAlias.php:162
ActionAddAlias\handleCustomEvent
handleCustomEvent($window, $id, $ctrl, $param1, $param2)
Definition
class.action.addAlias.php:180
ActionAddAlias\$wbBtnDest
$wbBtnDest
Definition
class.action.addAlias.php:20
ActionAddAlias\$wbLabelDest
$wbLabelDest
Definition
class.action.addAlias.php:18
ActionAddAlias\validateInput
validateInput($values)
Definition
class.action.addAlias.php:91
ActionAddAlias\getSaveSuccessMessage
getSaveSuccessMessage($values)
Definition
class.action.addAlias.php:136
ActionAddAlias\getDeleteDialogTitle
getDeleteDialogTitle()
Definition
class.action.addAlias.php:35
ActionAddAlias\getSaveErrorMessage
getSaveErrorMessage()
Definition
class.action.addAlias.php:150
ActionAddAlias\restartService
restartService()
Definition
class.action.addAlias.php:174
ActionAddAlias\getDeleteErrorMessage
getDeleteErrorMessage()
Definition
class.action.addAlias.php:168
ActionAddAlias\$wbInputName
$wbInputName
Definition
class.action.addAlias.php:17
ActionAddAlias\getDialogTitle
getDialogTitle()
Definition
class.action.addAlias.php:29
ActionAddAlias\saveItem
saveItem($values)
Definition
class.action.addAlias.php:120
ActionAddAlias\deleteItem
deleteItem()
Definition
class.action.addAlias.php:130
ActionAddAlias\getDeleteConfirmMessage
getDeleteConfirmMessage()
Definition
class.action.addAlias.php:156
ActionAddAlias\getWindowTitle
getWindowTitle()
Definition
class.action.addAlias.php:23
ActionAddAlias\getFormValues
getFormValues($bearsamppWinbinder)
Definition
class.action.addAlias.php:83
ActionAddAlias\itemExists
itemExists($values)
Definition
class.action.addAlias.php:105
ActionDialogBase
Definition
class.action.dialogBase.php:18
Lang\BUTTON_BROWSE
const BUTTON_BROWSE
Definition
class.lang.php:373
Lang\ADD_ALIAS_TITLE
const ADD_ALIAS_TITLE
Definition
class.lang.php:217
Lang\ALIAS_DEST_LABEL
const ALIAS_DEST_LABEL
Definition
class.lang.php:219
Lang\ALIAS_NAME_LABEL
const ALIAS_NAME_LABEL
Definition
class.lang.php:218
Lang\ALIAS_DEST_PATH
const ALIAS_DEST_PATH
Definition
class.lang.php:221
Lang\ALIAS_CREATED
const ALIAS_CREATED
Definition
class.lang.php:224
Lang\ALIAS_ALREADY_EXISTS
const ALIAS_ALREADY_EXISTS
Definition
class.lang.php:223
Lang\ALIAS_EXP_LABEL
const ALIAS_EXP_LABEL
Definition
class.lang.php:220
Lang\ALIAS_NOT_VALID_ALPHA
const ALIAS_NOT_VALID_ALPHA
Definition
class.lang.php:222
Lang\ALIAS_CREATED_ERROR
const ALIAS_CREATED_ERROR
Definition
class.lang.php:225
Path\getAliasPath
static getAliasPath($aetrayPath=false)
Definition
class.path.php:331
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