Bearsampp 2026.3.26
API documentation
Loading...
Searching...
No Matches
ActionAddAlias Class Reference
Inheritance 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 form fields specific to the dialog This method should create all input fields, labels, and buttons

Parameters
object$bearsamppWinbinderThe WinBinder instance
Returns
void

Reimplemented from ActionDialogBase.

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

42 {
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,
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 }
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 item

Returns
bool True on success, false on failure

Reimplemented from ActionDialogBase.

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

131 {
132 // Not used in add mode
133 return false;
134 }

◆ getDeleteConfirmMessage()

getDeleteConfirmMessage ( )
protected

Get delete confirmation message

Returns
string The confirmation message

Reimplemented from ActionDialogBase.

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

157 {
158 // Not used in add mode
159 return '';
160 }

◆ getDeleteDialogTitle()

getDeleteDialogTitle ( )
protected

Get the delete dialog title

Returns
string The delete dialog title

Reimplemented from ActionDialogBase.

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

36 {
37 // Not used in add mode
38 return '';
39 }

◆ getDeleteErrorMessage()

getDeleteErrorMessage ( )
protected

Get error message after delete failure

Returns
string The error message

Reimplemented from ActionDialogBase.

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

169 {
170 // Not used in add mode
171 return '';
172 }

◆ getDeleteSuccessMessage()

getDeleteSuccessMessage ( )
protected

Get success message after delete

Returns
string The success message

Reimplemented from ActionDialogBase.

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

163 {
164 // Not used in add mode
165 return '';
166 }

◆ getDialogTitle()

getDialogTitle ( )
protected

Get the dialog title for messages

Returns
string The dialog title

Reimplemented from ActionDialogBase.

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

30 {
31 global $bearsamppLang;
32 return $bearsamppLang->getValue(Lang::ADD_ALIAS_TITLE);
33 }
const ADD_ALIAS_TITLE

References $bearsamppLang, and Lang\ADD_ALIAS_TITLE.

◆ getFormValues()

getFormValues ( $bearsamppWinbinder)
protected

Get the current form values

Parameters
object$bearsamppWinbinderThe WinBinder instance
Returns
array Associative array of form values

Reimplemented from ActionDialogBase.

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

84 {
85 return [
86 'name' => $bearsamppWinbinder->getText($this->wbInputName[WinBinder::CTRL_OBJ]),
87 'dest' => $bearsamppWinbinder->getText($this->wbInputDest[WinBinder::CTRL_OBJ])
88 ];
89 }

References WinBinder\CTRL_OBJ.

◆ getSaveErrorMessage()

getSaveErrorMessage ( )
protected

Get error message after save failure

Returns
string The error message

Reimplemented from ActionDialogBase.

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

151 {
152 global $bearsamppLang;
154 }
const ALIAS_CREATED_ERROR

References $bearsamppLang, and Lang\ALIAS_CREATED_ERROR.

◆ getSaveSuccessMessage()

getSaveSuccessMessage ( $values)
protected

Get success message after save

Parameters
array$valuesThe form values
Returns
string The success message

Reimplemented from ActionDialogBase.

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

137 {
139
140 $apachePortUri = $bearsamppBins->getApache()->getPort() != 80 ? ':' . $bearsamppBins->getApache()->getPort() : '';
141 return sprintf(
143 $values['name'],
144 $apachePortUri,
145 $values['name'],
146 $values['dest']
147 );
148 }
const ALIAS_CREATED

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

◆ getWindowTitle()

getWindowTitle ( )
protected

Get the dialog window title

Returns
string The window title

Reimplemented from ActionDialogBase.

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

24 {
25 global $bearsamppLang;
26 return $bearsamppLang->getValue(Lang::ADD_ALIAS_TITLE);
27 }

References $bearsamppLang, and Lang\ADD_ALIAS_TITLE.

◆ handleCustomEvent()

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

Handle custom events (can be overridden by child classes)

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 180 of file class.action.addAlias.php.

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,
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 }
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 the item already exists (for add/edit operations)

Parameters
array$valuesThe form values
Returns
bool True if exists, false otherwise

Reimplemented from ActionDialogBase.

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

106 {
107 global $bearsamppRoot, $bearsamppLang, $bearsamppWinbinder;
108
109 if (is_file($bearsamppRoot->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 }
global $bearsamppRoot
const ALIAS_ALREADY_EXISTS

References $bearsamppLang, $bearsamppRoot, and Lang\ALIAS_ALREADY_EXISTS.

◆ restartService()

restartService ( )
protected

Restart the service after save/delete

Returns
void

Reimplemented from ActionDialogBase.

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

175 {
176 global $bearsamppBins;
177 $bearsamppBins->getApache()->getService()->restart();
178 }

References $bearsamppBins.

◆ saveItem()

saveItem ( $values)
protected

Save the item (create or update)

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

Reimplemented from ActionDialogBase.

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

121 {
123
124 return file_put_contents(
125 $bearsamppRoot->getAliasPath() . '/' . $values['name'] . '.conf',
126 $bearsamppBins->getApache()->getAliasContent($values['name'], $values['dest'])
127 ) !== false;
128 }

References $bearsamppBins, and $bearsamppRoot.

◆ 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 91 of file class.action.addAlias.php.

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

References $bearsamppLang, and Lang\ALIAS_NOT_VALID_ALPHA.

Field Documentation

◆ $wbBtnDest

$wbBtnDest
private

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

◆ $wbInputDest

$wbInputDest
private

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

◆ $wbInputName

$wbInputName
private

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

◆ $wbLabelDest

$wbLabelDest
private

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

◆ $wbLabelExp

$wbLabelExp
private

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

◆ $wbLabelName

$wbLabelName
private

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


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