2024.8.23
Loading...
Searching...
No Matches
ActionEditAlias Class Reference

Public Member Functions

 __construct ($args)
 
 processWindow ($window, $id, $ctrl, $param1, $param2)
 

Data Fields

const GAUGE_DELETE = 2
 
const GAUGE_SAVE = 2
 

Private Attributes

 $initName
 
 $wbBtnCancel
 
 $wbBtnDelete
 
 $wbBtnDest
 
 $wbBtnSave
 
 $wbInputDest
 
 $wbInputName
 
 $wbLabelDest
 
 $wbLabelExp
 
 $wbLabelName
 
 $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.

Constructor & Destructor Documentation

◆ __construct()

ActionEditAlias::__construct ( $args)

ActionEditAlias constructor. Initializes the alias editing window and its components.

Parameters
array$argsCommand line arguments passed to the script.

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

39 {
40 global $bearsamppRoot, $bearsamppLang, $bearsamppBins, $bearsamppWinbinder;
41
42 if (isset($args[0]) && !empty($args[0])) {
43 $filePath = $bearsamppRoot->getAliasPath() . '/' . $args[0] . '.conf';
44 $fileContent = file_get_contents($filePath);
45 if (preg_match('/^Alias \/' . $args[0] . ' "(.+)"/', $fileContent, $match)) {
46 $this->initName = $args[0];
47 $initDest = Util::formatWindowsPath($match[1]);
48 $apachePortUri = $bearsamppBins->getApache()->getPort() != 80 ? ':' . $bearsamppBins->getApache()->getPort() : '';
49
50 $bearsamppWinbinder->reset();
51 $this->wbWindow = $bearsamppWinbinder->createAppWindow(sprintf($bearsamppLang->getValue(Lang::EDIT_ALIAS_TITLE), $this->initName), 490, 200, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP);
52
53 $this->wbLabelName = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::ALIAS_NAME_LABEL) . ' :', 15, 15, 85, null, WBC_RIGHT);
54 $this->wbInputName = $bearsamppWinbinder->createInputText($this->wbWindow, $this->initName, 105, 13, 150, null);
55
56 $this->wbLabelDest = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::ALIAS_DEST_LABEL) . ' :', 15, 45, 85, null, WBC_RIGHT);
57 $this->wbInputDest = $bearsamppWinbinder->createInputText($this->wbWindow, $initDest, 105, 43, 190, null, null, WBC_READONLY);
58 $this->wbBtnDest = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_BROWSE), 300, 43, 110);
59
60 $this->wbLabelExp = $bearsamppWinbinder->createLabel($this->wbWindow, sprintf($bearsamppLang->getValue(Lang::ALIAS_EXP_LABEL), $apachePortUri, $this->initName, $initDest), 15, 80, 470, 50);
61
62 $this->wbProgressBar = $bearsamppWinbinder->createProgressBar($this->wbWindow, self::GAUGE_SAVE + 1, 15, 137, 190);
63 $this->wbBtnSave = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_SAVE), 215, 132);
64 $this->wbBtnDelete = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_DELETE), 300, 132);
65 $this->wbBtnCancel = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_CANCEL), 385, 132);
66
67 $bearsamppWinbinder->setHandler($this->wbWindow, $this, 'processWindow');
68 $bearsamppWinbinder->mainLoop();
69 $bearsamppWinbinder->reset();
70 }
71 }
72 }
global $bearsamppBins
global $bearsamppLang
global $bearsamppRoot
const ALIAS_DEST_LABEL
const BUTTON_CANCEL
const ALIAS_NAME_LABEL
const BUTTON_SAVE
const ALIAS_EXP_LABEL
const EDIT_ALIAS_TITLE
const BUTTON_BROWSE
const BUTTON_DELETE
static formatWindowsPath($path)

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

Member Function Documentation

◆ processWindow()

ActionEditAlias::processWindow ( $window,
$id,
$ctrl,
$param1,
$param2 )

Processes window events and handles user interactions.

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

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

84 {
85 global $bearsamppRoot, $bearsamppBins, $bearsamppLang, $bearsamppWinbinder;
86
87 $apachePortUri = $bearsamppBins->getApache()->getPort() != 80 ? ':' . $bearsamppBins->getApache()->getPort() : '';
88 $aliasName = $bearsamppWinbinder->getText($this->wbInputName[WinBinder::CTRL_OBJ]);
89 $aliasDest = $bearsamppWinbinder->getText($this->wbInputDest[WinBinder::CTRL_OBJ]);
90
91 switch ($id) {
92 case $this->wbInputName[WinBinder::CTRL_ID]:
93 $bearsamppWinbinder->setText(
94 $this->wbLabelExp[WinBinder::CTRL_OBJ],
95 sprintf($bearsamppLang->getValue(Lang::ALIAS_EXP_LABEL), $apachePortUri, $aliasName, $aliasDest)
96 );
97 $bearsamppWinbinder->setEnabled($this->wbBtnSave[WinBinder::CTRL_OBJ], empty($aliasName) ? false : true);
98 break;
99 case $this->wbBtnDest[WinBinder::CTRL_ID]:
100 $aliasDest = $bearsamppWinbinder->sysDlgPath($window, $bearsamppLang->getValue(Lang::ALIAS_DEST_PATH), $aliasDest);
101 if ($aliasDest && is_dir($aliasDest)) {
102 $bearsamppWinbinder->setText($this->wbInputDest[WinBinder::CTRL_OBJ], $aliasDest . '\\');
103 $bearsamppWinbinder->setText(
104 $this->wbLabelExp[WinBinder::CTRL_OBJ],
105 sprintf($bearsamppLang->getValue(Lang::ALIAS_EXP_LABEL), $apachePortUri, $aliasName, $aliasDest . '\\')
106 );
107 }
108 break;
109 case $this->wbBtnSave[WinBinder::CTRL_ID]:
110 $bearsamppWinbinder->setProgressBarMax($this->wbProgressBar, self::GAUGE_SAVE + 1);
111 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
112
113 if (!ctype_alnum($aliasName)) {
114 $bearsamppWinbinder->messageBoxError(
115 sprintf($bearsamppLang->getValue(Lang::ALIAS_NOT_VALID_ALPHA), $aliasName),
117 $bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
118 break;
119 }
120
121 if ($aliasName != $this->initName && is_file($bearsamppRoot->getAliasPath() . '/' . $aliasName . '.conf')) {
122 $bearsamppWinbinder->messageBoxError(
123 sprintf($bearsamppLang->getValue(Lang::ALIAS_ALREADY_EXISTS), $aliasName),
125 $bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
126 break;
127 }
128 if (file_put_contents($bearsamppRoot->getAliasPath() . '/' . $aliasName . '.conf', $bearsamppBins->getApache()->getAliasContent($aliasName, $aliasDest)) !== false) {
129 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
130
131 $bearsamppBins->getApache()->getService()->restart();
132 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
133
134 $bearsamppWinbinder->messageBoxInfo(
135 sprintf($bearsamppLang->getValue(Lang::ALIAS_CREATED), $aliasName, $apachePortUri, $aliasName, $aliasDest),
137 $bearsamppWinbinder->destroyWindow($window);
138 } else {
139 $bearsamppWinbinder->messageBoxError($bearsamppLang->getValue(Lang::ALIAS_CREATED_ERROR), $bearsamppLang->getValue(Lang::ADD_ALIAS_TITLE));
140 $bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
141 }
142 break;
143 case $this->wbBtnDelete[WinBinder::CTRL_ID]:
144 $bearsamppWinbinder->setProgressBarMax($this->wbProgressBar, self::GAUGE_DELETE + 1);
145
146 $boxTitle = $bearsamppLang->getValue(Lang::DELETE_ALIAS_TITLE);
147 $confirm = $bearsamppWinbinder->messageBoxYesNo(
148 sprintf($bearsamppLang->getValue(Lang::DELETE_ALIAS), $this->initName),
149 $boxTitle);
150
151 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
152
153 if ($confirm) {
154 if (@unlink($bearsamppRoot->getAliasPath() . '/' . $this->initName . '.conf')) {
155 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
156
157 $bearsamppBins->getApache()->getService()->restart();
158 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
159
160 $bearsamppWinbinder->messageBoxInfo(
161 sprintf($bearsamppLang->getValue(Lang::ALIAS_REMOVED), $this->initName),
162 $boxTitle);
163 $bearsamppWinbinder->destroyWindow($window);
164 } else {
165 $bearsamppWinbinder->messageBoxError(
166 sprintf($bearsamppLang->getValue(Lang::ALIAS_REMOVE_ERROR), $bearsamppRoot->getAliasPath() . '/' . $this->initName . '.conf'),
167 $boxTitle);
168 $bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
169 }
170 }
171 break;
172 case IDCLOSE:
173 case $this->wbBtnCancel[WinBinder::CTRL_ID]:
174 $bearsamppWinbinder->destroyWindow($window);
175 break;
176 }
177 }
const ALIAS_DEST_PATH
const ADD_ALIAS_TITLE
const ALIAS_CREATED
const ALIAS_NOT_VALID_ALPHA
const ALIAS_REMOVE_ERROR
const ALIAS_REMOVED
const ALIAS_ALREADY_EXISTS
const ALIAS_CREATED_ERROR
const DELETE_ALIAS
const DELETE_ALIAS_TITLE

References $bearsamppBins, $bearsamppLang, $bearsamppRoot, Lang\ADD_ALIAS_TITLE, Lang\ALIAS_ALREADY_EXISTS, Lang\ALIAS_CREATED, Lang\ALIAS_CREATED_ERROR, Lang\ALIAS_DEST_PATH, Lang\ALIAS_EXP_LABEL, Lang\ALIAS_NOT_VALID_ALPHA, Lang\ALIAS_REMOVE_ERROR, Lang\ALIAS_REMOVED, WinBinder\CTRL_ID, WinBinder\CTRL_OBJ, Lang\DELETE_ALIAS, and Lang\DELETE_ALIAS_TITLE.

Field Documentation

◆ $initName

ActionEditAlias::$initName
private

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

◆ $wbBtnCancel

ActionEditAlias::$wbBtnCancel
private

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

◆ $wbBtnDelete

ActionEditAlias::$wbBtnDelete
private

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

◆ $wbBtnDest

ActionEditAlias::$wbBtnDest
private

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

◆ $wbBtnSave

ActionEditAlias::$wbBtnSave
private

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

◆ $wbInputDest

ActionEditAlias::$wbInputDest
private

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

◆ $wbInputName

ActionEditAlias::$wbInputName
private

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

◆ $wbLabelDest

ActionEditAlias::$wbLabelDest
private

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

◆ $wbLabelExp

ActionEditAlias::$wbLabelExp
private

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

◆ $wbLabelName

ActionEditAlias::$wbLabelName
private

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

◆ $wbProgressBar

ActionEditAlias::$wbProgressBar
private

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

◆ $wbWindow

ActionEditAlias::$wbWindow
private

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

◆ GAUGE_DELETE

const ActionEditAlias::GAUGE_DELETE = 2

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

◆ GAUGE_SAVE

const ActionEditAlias::GAUGE_SAVE = 2

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


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