Bearsampp 2026.3.26
API documentation
Loading...
Searching...
No Matches
ActionEditAlias Class Reference
Inheritance diagram for ActionEditAlias:

Protected Member Functions

 createFormFields ($bearsamppWinbinder)
 deleteItem ()
 getDeleteConfirmMessage ()
 getDeleteDialogTitle ()
 getDeleteErrorMessage ()
 getDeleteSuccessMessage ()
 getDialogTitle ()
 getFormValues ($bearsamppWinbinder)
 getSaveErrorMessage ()
 getSaveSuccessMessage ($values)
 getWindowTitle ()
 handleCustomEvent ($window, $id, $ctrl, $param1, $param2)
 initializeDialog ($args)
 itemExists ($values)
 restartService ()
 saveItem ($values)
 validateInput ($values)
Protected Member Functions inherited from ActionDialogBase
 createButtons ($bearsamppWinbinder)
 getGaugeDelete ()
 getGaugeSave ()
 handleDelete ($window)
 handleSave ($window)
 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 ActionEditAlias Handles the editing of Apache aliases within the Bearsampp application.

Definition at line 14 of file class.action.editAlias.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 63 of file class.action.editAlias.php.

64 {
66
67 // Load existing alias data
68 $filePath = $bearsamppRoot->getAliasPath() . '/' . $this->initValue . '.conf';
69 $fileContent = file_get_contents($filePath);
70 preg_match('/^Alias \/' . $this->initValue . ' "(.+)"/', $fileContent, $match);
71 $initDest = Util::formatWindowsPath($match[1]);
72 $apachePortUri = $bearsamppBins->getApache()->getPort() != 80 ? ':' . $bearsamppBins->getApache()->getPort() : '';
73
74 $this->wbLabelName = $bearsamppWinbinder->createLabel(
75 $this->wbWindow,
76 $bearsamppLang->getValue(Lang::ALIAS_NAME_LABEL) . ' :',
77 15, 15, 85, null, WBC_RIGHT
78 );
79 $this->wbInputName = $bearsamppWinbinder->createInputText(
80 $this->wbWindow,
81 $this->initValue,
82 105, 13, 150, null
83 );
84
85 $this->wbLabelDest = $bearsamppWinbinder->createLabel(
86 $this->wbWindow,
87 $bearsamppLang->getValue(Lang::ALIAS_DEST_LABEL) . ' :',
88 15, 45, 85, null, WBC_RIGHT
89 );
90 $this->wbInputDest = $bearsamppWinbinder->createInputText(
91 $this->wbWindow,
92 $initDest,
93 105, 43, 190, null, null, WBC_READONLY
94 );
95 $this->wbBtnDest = $bearsamppWinbinder->createButton(
96 $this->wbWindow,
98 300, 43, 110
99 );
100
101 $this->wbLabelExp = $bearsamppWinbinder->createLabel(
102 $this->wbWindow,
103 sprintf($bearsamppLang->getValue(Lang::ALIAS_EXP_LABEL), $apachePortUri, $this->initValue, $initDest),
104 15, 80, 470, 50
105 );
106 }
global $bearsamppBins
global $bearsamppLang
global $bearsamppRoot
const BUTTON_BROWSE
const ALIAS_DEST_LABEL
const ALIAS_NAME_LABEL
const ALIAS_EXP_LABEL
static formatWindowsPath($path)

References $bearsamppBins, $bearsamppLang, $bearsamppRoot, Lang\ALIAS_DEST_LABEL, Lang\ALIAS_EXP_LABEL, Lang\ALIAS_NAME_LABEL, Lang\BUTTON_BROWSE, and Util\formatWindowsPath().

◆ deleteItem()

deleteItem ( )
protected

Delete the item

Returns
bool True on success, false on failure

Reimplemented from ActionDialogBase.

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

157 {
158 global $bearsamppRoot;
159
160 return @unlink($bearsamppRoot->getAliasPath() . '/' . $this->initValue . '.conf');
161 }

References $bearsamppRoot.

◆ getDeleteConfirmMessage()

getDeleteConfirmMessage ( )
protected

Get delete confirmation message

Returns
string The confirmation message

Reimplemented from ActionDialogBase.

Definition at line 183 of file class.action.editAlias.php.

184 {
185 global $bearsamppLang;
186 return sprintf($bearsamppLang->getValue(Lang::DELETE_ALIAS), $this->initValue);
187 }
const DELETE_ALIAS

References $bearsamppLang, and Lang\DELETE_ALIAS.

◆ 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.editAlias.php.

36 {
37 global $bearsamppLang;
39 }
const DELETE_ALIAS_TITLE

References $bearsamppLang, and Lang\DELETE_ALIAS_TITLE.

◆ getDeleteErrorMessage()

getDeleteErrorMessage ( )
protected

Get error message after delete failure

Returns
string The error message

Reimplemented from ActionDialogBase.

Definition at line 195 of file class.action.editAlias.php.

196 {
198 return sprintf(
200 $bearsamppRoot->getAliasPath() . '/' . $this->initValue . '.conf'
201 );
202 }
const ALIAS_REMOVE_ERROR

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

◆ getDeleteSuccessMessage()

getDeleteSuccessMessage ( )
protected

Get success message after delete

Returns
string The success message

Reimplemented from ActionDialogBase.

Definition at line 189 of file class.action.editAlias.php.

190 {
191 global $bearsamppLang;
192 return sprintf($bearsamppLang->getValue(Lang::ALIAS_REMOVED), $this->initValue);
193 }
const ALIAS_REMOVED

References $bearsamppLang, and Lang\ALIAS_REMOVED.

◆ 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.editAlias.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 108 of file class.action.editAlias.php.

109 {
110 return [
111 'name' => $bearsamppWinbinder->getText($this->wbInputName[WinBinder::CTRL_OBJ]),
112 'dest' => $bearsamppWinbinder->getText($this->wbInputDest[WinBinder::CTRL_OBJ])
113 ];
114 }

References WinBinder\CTRL_OBJ.

◆ getSaveErrorMessage()

getSaveErrorMessage ( )
protected

Get error message after save failure

Returns
string The error message

Reimplemented from ActionDialogBase.

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

178 {
179 global $bearsamppLang;
181 }
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 163 of file class.action.editAlias.php.

164 {
166
167 $apachePortUri = $bearsamppBins->getApache()->getPort() != 80 ? ':' . $bearsamppBins->getApache()->getPort() : '';
168 return sprintf(
170 $values['name'],
171 $apachePortUri,
172 $values['name'],
173 $values['dest']
174 );
175 }
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.editAlias.php.

24 {
25 global $bearsamppLang;
26 return sprintf($bearsamppLang->getValue(Lang::EDIT_ALIAS_TITLE), $this->initValue);
27 }
const EDIT_ALIAS_TITLE

References $bearsamppLang, and Lang\EDIT_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 210 of file class.action.editAlias.php.

211 {
212 global $bearsamppLang, $bearsamppBins, $bearsamppWinbinder;
213
214 $apachePortUri = $bearsamppBins->getApache()->getPort() != 80 ? ':' . $bearsamppBins->getApache()->getPort() : '';
215 $aliasName = $bearsamppWinbinder->getText($this->wbInputName[WinBinder::CTRL_OBJ]);
216 $aliasDest = $bearsamppWinbinder->getText($this->wbInputDest[WinBinder::CTRL_OBJ]);
217
218 // Handle name input change
219 if ($id == $this->wbInputName[WinBinder::CTRL_ID]) {
220 $bearsamppWinbinder->setText(
221 $this->wbLabelExp[WinBinder::CTRL_OBJ],
222 sprintf($bearsamppLang->getValue(Lang::ALIAS_EXP_LABEL), $apachePortUri, $aliasName, $aliasDest)
223 );
224 $bearsamppWinbinder->setEnabled(
225 $this->wbBtnSave[WinBinder::CTRL_OBJ],
226 !empty($aliasName)
227 );
228 }
229
230 // Handle browse button
231 if ($id == $this->wbBtnDest[WinBinder::CTRL_ID]) {
232 $aliasDest = $bearsamppWinbinder->sysDlgPath(
233 $window,
235 $aliasDest
236 );
237 if ($aliasDest && is_dir($aliasDest)) {
238 $bearsamppWinbinder->setText($this->wbInputDest[WinBinder::CTRL_OBJ], $aliasDest . '\\');
239 $bearsamppWinbinder->setText(
240 $this->wbLabelExp[WinBinder::CTRL_OBJ],
241 sprintf($bearsamppLang->getValue(Lang::ALIAS_EXP_LABEL), $apachePortUri, $aliasName, $aliasDest . '\\')
242 );
243 }
244 }
245 }
const ALIAS_DEST_PATH

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

◆ initializeDialog()

initializeDialog ( $args)
protected

Initialize the dialog window

Parameters
array$argsCommand line arguments
Returns
bool True if initialization successful, false otherwise

Reimplemented from ActionDialogBase.

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

42 {
43 global $bearsamppRoot;
44
45 if (!isset($args[0]) || empty($args[0])) {
46 return false;
47 }
48
49 $filePath = $bearsamppRoot->getAliasPath() . '/' . $args[0] . '.conf';
50 if (!file_exists($filePath)) {
51 return false;
52 }
53
54 $fileContent = file_get_contents($filePath);
55 if (!preg_match('/^Alias \/' . $args[0] . ' "(.+)"/', $fileContent, $match)) {
56 return false;
57 }
58
59 $this->initValue = $args[0];
60 return true;
61 }

References $bearsamppRoot.

◆ 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 130 of file class.action.editAlias.php.

131 {
132 global $bearsamppRoot, $bearsamppLang, $bearsamppWinbinder;
133
134 // Only check if name changed
135 if ($values['name'] != $this->initValue && is_file($bearsamppRoot->getAliasPath() . '/' . $values['name'] . '.conf')) {
136 $bearsamppWinbinder->messageBoxError(
137 sprintf($bearsamppLang->getValue(Lang::ALIAS_ALREADY_EXISTS), $values['name']),
138 $this->getDialogTitle()
139 );
140 return true;
141 }
142
143 return false;
144 }
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 204 of file class.action.editAlias.php.

205 {
206 global $bearsamppBins;
207 $bearsamppBins->getApache()->getService()->restart();
208 }

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 146 of file class.action.editAlias.php.

147 {
149
150 return file_put_contents(
151 $bearsamppRoot->getAliasPath() . '/' . $values['name'] . '.conf',
152 $bearsamppBins->getApache()->getAliasContent($values['name'], $values['dest'])
153 ) !== false;
154 }

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 116 of file class.action.editAlias.php.

117 {
118 global $bearsamppLang;
119
120 if (!ctype_alnum($values['name'])) {
121 return [
122 'valid' => false,
123 'error' => sprintf($bearsamppLang->getValue(Lang::ALIAS_NOT_VALID_ALPHA), $values['name'])
124 ];
125 }
126
127 return ['valid' => true];
128 }
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.editAlias.php.

◆ $wbInputDest

$wbInputDest
private

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

◆ $wbInputName

$wbInputName
private

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

◆ $wbLabelDest

$wbLabelDest
private

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

◆ $wbLabelExp

$wbLabelExp
private

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

◆ $wbLabelName

$wbLabelName
private

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


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