Bearsampp 2026.9.23
Loading...
Searching...
No Matches
ActionAddAlias Class Reference
Inheritance diagram for ActionAddAlias:
Collaboration diagram for ActionAddAlias:

Protected Member Functions

 createFormFields ($bearsamppWinbinder)
 deleteItem ()
 getDeleteConfirmMessage ()
 getDeleteDialogTitle ()
 getDeleteErrorMessage ()
 getDeleteSuccessMessage ()
 getDialogTitle ()
 getFormValues ($bearsamppWinbinder)
 getSaveErrorMessage ()
 getSaveSuccessMessage ($values)
 getWindowTitle ()
 handleCustomEvent ($window, $id, $ctrl, $param1, $param2)
 itemExists ($values)
 restartService ()
 saveItem ($values)
 validateInput ($values)
Protected Member Functions inherited from ActionDialogBase
 createButtons ($bearsamppWinbinder)
 getGaugeDelete ()
 getGaugeSave ()
 handleDelete ($window)
 handleSave ($window)
 initializeDialog ($args)
 isEditMode ()

Private Attributes

 $wbBtnDest
 $wbInputDest
 $wbInputName
 $wbLabelDest
 $wbLabelExp
 $wbLabelName

Additional Inherited Members

Public Member Functions inherited from ActionDialogBase
 __construct ($args)
 processWindow ($window, $id, $ctrl, $param1, $param2)
Data Fields inherited from ActionDialogBase
const GAUGE_DELETE = 2
const GAUGE_SAVE = 2
Protected Attributes inherited from ActionDialogBase
 $initValue
 $wbBtnCancel
 $wbBtnDelete
 $wbBtnSave
 $wbProgressBar
 $wbWindow

Detailed Description

Class ActionAddAlias Handles the creation of a new alias in the Bearsampp application.

Definition at line 14 of file class.action.addAlias.php.

Member Function Documentation

◆ createFormFields()

createFormFields ( $bearsamppWinbinder)
protected

Create the form fields for the add alias dialog.

Parameters
object$bearsamppWinbinderThe WinBinder instance.
Returns
void

Reimplemented from ActionDialogBase.

Definition at line 71 of file class.action.addAlias.php.

72 {
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,
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 }
global $bearsamppBins
global $bearsamppLang
const BUTTON_BROWSE
const ALIAS_DEST_LABEL
const ALIAS_NAME_LABEL
const ALIAS_EXP_LABEL

References $bearsamppBins, $bearsamppLang, Lang\ALIAS_DEST_LABEL, Lang\ALIAS_EXP_LABEL, Lang\ALIAS_NAME_LABEL, and Lang\BUTTON_BROWSE.

◆ deleteItem()

deleteItem ( )
protected

Delete the alias. Not used in add mode.

Returns
bool Always returns false.

Reimplemented from ActionDialogBase.

Definition at line 215 of file class.action.addAlias.php.

216 {
217 // Not used in add mode
218 return false;
219 }

◆ getDeleteConfirmMessage()

getDeleteConfirmMessage ( )
protected

Get the delete confirmation message. Not used in add mode.

Returns
string Empty string.

Reimplemented from ActionDialogBase.

Definition at line 260 of file class.action.addAlias.php.

261 {
262 // Not used in add mode
263 return '';
264 }

◆ getDeleteDialogTitle()

getDeleteDialogTitle ( )
protected

Get the delete dialog title.

Returns
string Empty string, not used in add mode.

Reimplemented from ActionDialogBase.

Definition at line 58 of file class.action.addAlias.php.

59 {
60 // Not used in add mode
61 return '';
62 }

◆ getDeleteErrorMessage()

getDeleteErrorMessage ( )
protected

Get the error message after delete failure. Not used in add mode.

Returns
string Empty string.

Reimplemented from ActionDialogBase.

Definition at line 282 of file class.action.addAlias.php.

283 {
284 // Not used in add mode
285 return '';
286 }

◆ getDeleteSuccessMessage()

getDeleteSuccessMessage ( )
protected

Get the success message after delete. Not used in add mode.

Returns
string Empty string.

Reimplemented from ActionDialogBase.

Definition at line 271 of file class.action.addAlias.php.

272 {
273 // Not used in add mode
274 return '';
275 }

◆ getDialogTitle()

getDialogTitle ( )
protected

Get the dialog title for message boxes.

Returns
string The localized dialog title.

Reimplemented from ActionDialogBase.

Definition at line 46 of file class.action.addAlias.php.

47 {
48 global $bearsamppLang;
49
50 return $bearsamppLang->getValue(Lang::ADD_ALIAS_TITLE);
51 }
const ADD_ALIAS_TITLE

References $bearsamppLang, and Lang\ADD_ALIAS_TITLE.

◆ getFormValues()

getFormValues ( $bearsamppWinbinder)
protected

Get the current form values from the input controls.

Parameters
object$bearsamppWinbinderThe WinBinder instance.
Returns
array Associative array with 'name' and 'dest' keys.

Reimplemented from ActionDialogBase.

Definition at line 141 of file class.action.addAlias.php.

142 {
143 return [
144 'name' => $bearsamppWinbinder->getText($this->wbInputName[WinBinder::CTRL_OBJ]),
145 'dest' => $bearsamppWinbinder->getText($this->wbInputDest[WinBinder::CTRL_OBJ])
146 ];
147 }

References WinBinder\CTRL_OBJ.

◆ getSaveErrorMessage()

getSaveErrorMessage ( )
protected

Get the error message after save failure.

Returns
string The localized error message.

Reimplemented from ActionDialogBase.

Definition at line 248 of file class.action.addAlias.php.

249 {
250 global $bearsamppLang;
251
253 }
const ALIAS_CREATED_ERROR

References $bearsamppLang, and Lang\ALIAS_CREATED_ERROR.

◆ getSaveSuccessMessage()

getSaveSuccessMessage ( $values)
protected

Get the success message after saving.

Parameters
array$valuesThe form values.
Returns
string The localized success message.

Reimplemented from ActionDialogBase.

Definition at line 228 of file class.action.addAlias.php.

229 {
231
232 $apachePortUri = $bearsamppBins->getApache()->getPort() != 80 ? ':' . $bearsamppBins->getApache()->getPort() : '';
233
234 return sprintf(
236 $values['name'],
237 $apachePortUri,
238 $values['name'],
239 $values['dest']
240 );
241 }
const ALIAS_CREATED

References $bearsamppBins, $bearsamppLang, and Lang\ALIAS_CREATED.

◆ getWindowTitle()

getWindowTitle ( )
protected

Get the dialog window title.

Returns
string The localized window title.

Reimplemented from ActionDialogBase.

Definition at line 34 of file class.action.addAlias.php.

35 {
36 global $bearsamppLang;
37
38 return $bearsamppLang->getValue(Lang::ADD_ALIAS_TITLE);
39 }

References $bearsamppLang, and Lang\ADD_ALIAS_TITLE.

◆ handleCustomEvent()

handleCustomEvent ( $window,
$id,
$ctrl,
$param1,
$param2 )
protected

Handle custom window events (name input change and browse button).

Parameters
resource$windowThe window resource.
int$idThe control ID.
resource$ctrlThe control resource.
mixed$param1Additional parameter 1.
mixed$param2Additional parameter 2.
Returns
void

Reimplemented from ActionDialogBase.

Definition at line 310 of file class.action.addAlias.php.

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,
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 }
const ALIAS_DEST_PATH

References $bearsamppBins, $bearsamppLang, Lang\ALIAS_DEST_PATH, Lang\ALIAS_EXP_LABEL, WinBinder\CTRL_ID, and WinBinder\CTRL_OBJ.

◆ itemExists()

itemExists ( $values)
protected

Check if an alias configuration file already exists.

Parameters
array$valuesThe form values.
Returns
bool True if the alias already exists, false otherwise.

Reimplemented from ActionDialogBase.

Definition at line 177 of file class.action.addAlias.php.

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 }
global $bearsamppRoot
const ALIAS_ALREADY_EXISTS
static getAliasPath($aetrayPath=false)

References $bearsamppLang, $bearsamppRoot, Lang\ALIAS_ALREADY_EXISTS, and Path\getAliasPath().

Here is the call graph for this function:

◆ restartService()

restartService ( )
protected

Restart the Apache service after saving.

Returns
void

Reimplemented from ActionDialogBase.

Definition at line 293 of file class.action.addAlias.php.

294 {
295 global $bearsamppBins;
296 $bearsamppBins->getApache()->getService()->restart();
297 }

References $bearsamppBins.

◆ saveItem()

saveItem ( $values)
protected

Save the alias configuration file.

Parameters
array$valuesThe form values.
Returns
bool True on success, false on failure.

Reimplemented from ActionDialogBase.

Definition at line 200 of file class.action.addAlias.php.

201 {
203
204 return file_put_contents(
205 Path::getAliasPath() . '/' . $values['name'] . '.conf',
206 $bearsamppBins->getApache()->getAliasContent($values['name'], $values['dest'])
207 ) !== false;
208 }

References $bearsamppBins, $bearsamppRoot, and Path\getAliasPath().

Here is the call graph for this function:

◆ validateInput()

validateInput ( $values)
protected

Validate the form input.

Parameters
array$valuesThe form values.
Returns
array ['valid' => bool, 'error' => string|null]

Reimplemented from ActionDialogBase.

Definition at line 156 of file class.action.addAlias.php.

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 }
const ALIAS_NOT_VALID_ALPHA

References $bearsamppLang, and Lang\ALIAS_NOT_VALID_ALPHA.

Field Documentation

◆ $wbBtnDest

$wbBtnDest
private

Definition at line 25 of file class.action.addAlias.php.

◆ $wbInputDest

$wbInputDest
private

Definition at line 23 of file class.action.addAlias.php.

◆ $wbInputName

$wbInputName
private

Definition at line 19 of file class.action.addAlias.php.

◆ $wbLabelDest

$wbLabelDest
private

Definition at line 21 of file class.action.addAlias.php.

◆ $wbLabelExp

$wbLabelExp
private

Definition at line 27 of file class.action.addAlias.php.

◆ $wbLabelName

$wbLabelName
private

Definition at line 17 of file class.action.addAlias.php.


The documentation for this class was generated from the following file: