PHP WinBinder: Alternative control 3: Difference between revisions

Proofreading and grammatical changes; some minor reformatting
(New page: {{Nav PHP WinBinder}} '''''Alternative control part 3''''' This page is a continuation of the alternative control. It covers adding functionality to the following buttons Logs, Edit and T...)
 
(Proofreading and grammatical changes; some minor reformatting)
Line 2: Line 2:
'''''Alternative control part 3'''''
'''''Alternative control part 3'''''


This page is a continuation of the alternative control. It covers adding functionality to the following buttons Logs, Edit and Test. However each button needs to access several files one solution is to use pop-up windows containing additional buttons to access the appropriate files. This is far from ideal and would be extremely messy.
This page is a continuation of the alternative control. It covers adding functionality to the following buttons: Logs, Edit and Test. Each of these buttons needs to access several files. One solution is to use pop-up windows containing additional buttons to access the appropriate files. This is far from ideal and would be extremely messy.


A more appropriate solution would be to use dropdown menus. WinBinder makes this task extremely easy. Advantage of using this solution, application remains compact, requires minimal changes and offers expandability.
A more appropriate solution would be to use dropdown menus. WinBinder makes this task extremely easy. The advantage of using this solution is that the application remains compact, requires minimal changes and offers expandability.


== Menu ==
== Menu ==
Line 10: Line 10:
|-valign="top"
|-valign="top"
|
|
Adding a menu control is easy it forces a menu across the top of your application.
Adding a menu control is easy.  It forces a menu across the top of your application.
 
All you need to do is re-size your application to fit.
All you need to do is re-size your application to fit.


From my point of view it carries baggage that is not required, keyboard short cuts never use them.  
From my point of view, it carries baggage that is not required, such as:
 
*keyboard short cuts, which I never use.  
Images to the side of a menu item! Suppose to be intuitive never had a clue what most of them do.
*Images to the side of a menu item! This is supposed to be intuitive, but I never had a clue what most of them do.


Yep! I like lean and clean.
Yep! I like lean and clean.


Please remember this is not a commercial product a menu item must be of use.  
Please remember this is not a commercial product. A menu item must be useful.  


|
|
Line 45: Line 44:
|-valign="top"
|-valign="top"
|
|
<br />In WinBinder most parameters are optional hence the code can be reduced to this
<br />In WinBinder most parameters are optional, hence the code can be reduced to this


Absolutely no baggage; just clean drop down menus.
Absolutely no baggage; just clean drop down menus.


It really is an elegant structure and easy to use.
This really is an elegant structure and easy to use.


* Define any ID used, remember must be unique  
* Define any ID used, remembering that it must be unique  
* Add menu text to be displayed to a user
* Add menu text to be displayed to a user
* That’s it


Click a menu item and it's ID is sent to the handler function for processing.
That’s it!
 
Click a menu item and its ID is sent to the handler function for processing.
|
|
<pre>
<pre>
Line 78: Line 78:
</pre>
</pre>
|}
|}
Our new UniController has a common set of buttons that are specific to the servers. They are interlocked providing an easy to use interface and prevents a user killing the servers.
Our new UniController has a common set of buttons that are specific to the servers. They are interlocked providing an easy to use interface which prevents a user killing the servers.


The drop down menu now allows a user to access lower levels of the server and change say ports with ease. To implement this a menu item can open another window to make appropriate changes.
The drop down menu now allows a user to access lower levels of the server and, for example, change the ports with ease. To implement this, a menu item can open another window to make appropriate changes.


Real point a simple change to a menu offers real expandability.
The main point is that a simple change to a menu offers real expandability.


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
== Menu - Example==
== Menu - Example==
{|
{|
Line 95: Line 94:
The applications main buttons are generally all that is required to run the servers.
The applications main buttons are generally all that is required to run the servers.


However using a drop down menu allows various parts of the server to be accessed a few possibilities viewing log files, put servers on-line and setting passwords.
Using a drop down menu allows various aspects of the server to be accessed. A few possibilities are viewing log files, putting servers on-line and setting passwords.


To the right are additional items that you may wish to include a semi-working menu can be found in example '''test_7.phpw''' to see this in action run '''test_7.bat'''.   
To the right are additional items that you may wish to include.  A semi-working menu can be found in example '''test_7.phpw'''. To see this in action, run '''test_7.bat'''.   


'''''Activation'':'''
'''''Activation'':'''
Line 105: Line 104:
'''''Unique'':'''
'''''Unique'':'''


Most menu items use similar code I have included code that is unique for a particular task. This introduces more WinBinder features not previously covered.
Most menu items use similar code. I have included code that is unique for a particular task. This introduces more WinBinder features not previously covered.




'''''Tasks'':'''
'''''Tasks'':'''


* Local requires displaying a web page on the local server in a users default browser
* Local requires displaying a web page on the local server in a user's default browser


* View and Edit requires running a users default text editor.
* View and Edit requires running a user's default text editor.


* Directly changing a server variable requires a pop-up menu
* Directly changing a server variable requires a pop-up menu.


* MySQL password restore requires running a batch file. In addition you require feedback from a user that is what they really intend to do.
* MySQL password restore requires running a batch file. In addition, you require verification from a user that what they called for is what they really intend to do.


Each of these tasks are covered in the next section including working example code  
Each of these tasks are covered in the next section, including working example code.


'''''Function'': - wb_exec'''  
'''''Function'': - wb_exec'''  
Line 190: Line 189:
'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
== Function'': - wb_exec() ==
== Function'': - wb_exec() ==
This function is used extensively in processing menu items three uses are shown below.
This function is used extensively in processing menu items. Three uses are shown below.


'''''[[#top | Top]]'''''
=== Display a local web page ===
=== Display a local web page ===
To display a local web page use the following format:
To display a local web page, use the following format:
<pre>
<pre>
wb_exec("http://localhost/path_to_page");
wb_exec("http://localhost/path_to_page");
</pre>
</pre>
For example to display index page use
For example, to display index page use:
<pre>
<pre>
wb_exec("http://localhost/index.php");
wb_exec("http://localhost/index.php");
</pre>
</pre>
For our application the above is too specific.
For our application, the above is too specific.


An index page can use one of several file extensions hence do not specify an index page.
An index page can use one of several file extensions, so we do not want to specify an index page.
 
We'll let Apache choose one from the list defined in its configuration file:
Let Apache choose one from the list defined in its configuration file:


DirectoryIndex index.html index.shtml index.html.var index.htm index.php3 index.php index.pl index.cgi
DirectoryIndex index.html index.shtml index.html.var index.htm index.php3 index.php index.pl index.cgi


A user can change the Apache port this needs to be read from the configuration file and included in the Internet address hence the following format is required:
A user can change the Apache port. This needs to be read from the configuration file and included in the Internet address, so the following format is required:
<pre>
<pre>
wb_exec("http://localhost:port_number/");
wb_exec("http://localhost:port_number/");
Line 220: Line 217:
To display the root www index page requires the following handler code:
To display the root www index page requires the following handler code:


The Apache port is read from the configuration file. If the value is 80 (standard) there is no need to include this in the address all browsers understand and assume port 80.
The Apache port is read from the configuration file. If the value is 80 (standard), there is no need to include this in the address; all browsers understand and assume port 80.


However if included the code can be reduced to this
However, if it is included, the code can be reduced to this:
<pre>
<pre>
case ID_ROOT: // Server root WWW
case ID_ROOT: // Server root WWW
Line 249: Line 246:
</pre>
</pre>
|}
|}
'''''[[#top | Top]]'''''


=== Edit or display text files ===
=== Edit or display text files ===
To edit or display the content of a text file we use Windows '''notepad''' this is contained some where on the system path.
To edit or display the content of a text file, we use Windows '''notepad'''. This is contained somewhere on the system path.


To obtain the full path to this file use function '''wb_find_file()''' it looks in the Windows and System directories. The path is required by function wb_exec(). This function also allows you to pass a parameter to a file.
To obtain the full path to this file, use function '''wb_find_file()'''. It looks in the Windows and System directories. The path is required by function wb_exec(). This function also allows you to pass a parameter to a file.


The handler code for viewing Apache error.log file is shown below.
The handler code for viewing the Apache error.log file is shown below.
<pre>
<pre>
   //--Logs
   //--Logs
Line 266: Line 261:
   break;
   break;
</pre>
</pre>
'''''Note 1'':''' The variable '''$us_apache''' must be declaied as '''local''' at the top of the handler function. ($us_apache is a UniServer core variable)
'''''Note 1'':''' The variable '''$us_apache''' must be declared as '''local''' at the top of the handler function. ($us_apache is a UniServer core variable)


'''''Note 2'':''' A user may have deleted the file (can become large generally a good idea to delete) hence the check for existence otherwise an error is generated.
'''''Note 2'':''' A user may have deleted the file (can become large; generally a good idea to delete), so we must check for existence, otherwise an error is generated.


'''''[[#top | Top]]'''''


=== Run another WinBinder application ===
=== Run another WinBinder application ===
Change MySQL password requires user input. Our current application has been purposefully made minimal hence there are no input fields. A solution is to use a second WinBinder application that is run from the dropdown menu.
Change MySQL password requires user input. Our current application has been purposefully made minimal, therefore there are no input fields. A solution is to use a second WinBinder application that is run from the dropdown menu.


From the examples folder I copied and renamed file test_1.phpw to test7b.phpw and placed it in folder alt_con_1. This application would contain a input field and code to change the MySQL port. However it is used to demonstrate how to run a second application from our main application.
From the examples folder I copied and renamed file test_1.phpw to test7b.phpw and placed it in folder alt_con_1. This application would contain an input field and code to change the MySQL port. It is used here to demonstrate how to run a second application from our main application.


Again we use function wb_exec() I have reworded the parameters it takes.  
Again we use function wb_exec(). I have reworded the parameters it takes.  
<pre>
<pre>
wb_exec("complete_path_of_program_to_run"),"pass_any_parameters" );  
wb_exec("complete_path_of_program_to_run","pass_any_parameters" );  
</pre>
</pre>
* The first parameter can be either an absolute path (C:/path/prog.exe) or a relative path (../../path/prog.exe)<br />'''../../path/prog.exe''' This means from the current working folder move up two folder levels and down into folder prog and run prog.exe
* The first parameter can be either an absolute path (C:/path/prog.exe) or a relative path (../../path/prog.exe)<br />'''../../path/prog.exe''' This means from the current working folder move up two folder levels and down into folder prog and run prog.exe
Line 288: Line 282:
We want to run our second application '''test7b.phpw''' with program '''php-win.exe''' (php-win.exe hides the command window).
We want to run our second application '''test7b.phpw''' with program '''php-win.exe''' (php-win.exe hides the command window).


PHP will use a default configuration hence the need to force it to use php-wb.ini
PHP will use a default configuration, hence the need to force it to use php-wb.ini


An optional parameter or parameters can be passed to the script '''test7b.phpw'''  
An optional parameter or parameters can be passed to the script '''test7b.phpw'''  


Putting all this together the line of code looks like this:
Putting all this together, the line of code looks like this:
<pre>
<pre>
wb_exec("..\php\php-win.exe", "-c ..\php\php-wb.ini test_7b.phpw 23456"); // Run second window app.  
wb_exec("..\php\php-win.exe", "-c ..\php\php-wb.ini test_7b.phpw 23456"); // Run second window app.  
Line 302: Line 296:
  break;
  break;
</pre>
</pre>
'''''[[#top | Top]]'''''
 
=== Are you sure WBC_YESNO ===
=== Are you sure WBC_YESNO ===
There are situations requiring confirmation from a user for example overwriting critical data in a file.
There are situations requiring confirmation from a user, for example, overwriting critical data in a file.


A very easy way to obtain this information is to use a message box with style WBC_YESNO.
A very easy way to obtain this information is to use a message box with style WBC_YESNO.


The pop-up box contains two buttons “YES” and “NO” clicking yes returns TRUE and click “NO” returns FALSE.
The pop-up box contains two buttons: “YES” and “NO”. Clicking yes returns TRUE and click “NO” returns FALSE.


The handler for restore MySQL password uses this code shown below:
The handler for restore MySQL password uses this code shown below:
Line 319: Line 313:
break;
break;
</pre>
</pre>
An "if" tests the returned value. Pressing YES button returns true and the restore batch file is run.
An "if" tests the returned value. Pressing the YES button returns true and the restore batch file is run.


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
== User feedback ==
== User feedback ==
For any number of reasons the servers may take a relatively long time to either start or stop. If the indicators (red or green) remain static for this period it gives a user the impression something is wrong.
For any number of reasons the servers may take a relatively long time to either start or stop. If the indicators (red or green) remain static for this period it gives a user the impression that something is wrong.


A progress bar could be used however the layout does not justify using one. An alterative is to use another indicator with a different colour linked to the main timer.
A progress bar could be used, however the layout does not justify using one. An alternative is to use another indicator with a different colour linked to the main timer.
This indicator flashes providing a user with feedback when the main indicators change it is turned off.
This indicator flashes, providing a user with feedback. When the main indicators change, it is turned off.


There are two images blue and blank. These are created as follows:  
There are two images blue and blank. These are created as follows:  
Line 369: Line 362:


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
== Test ==
== Test ==
To see this code in action run '''test_7.bat''' (code contained in test_7.phpw)
To see this code in action, run '''test_7.bat''' (code contained in test_7.phpw).


Run Uniform Server, start and stop each server observe button and indicator states.
Run Uniform Server; start and stop each server; observe the button and indicator states.


Start and stop both servers again observe button and indicator states.
Start and stop both servers; again observe the button and indicator states.


Try the menu (only a minimum number of items work)     
Try the menu (only a minimum number of items work).    


After testing close both Servers and application script.
After testing, close both Servers and the application script.


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
== Summary ==
== Summary ==
Essentially that completes the alternative control however there is a remaining issue.
Essentially that completes the alternative control. There is a remaining issue.


You will have noticed a button named refresh, this serves no real purpose other than to update buttons and indicators (runs function main_init ) after restoring the application using the tray icon.
You will have noticed a button named refresh. This serves no real purpose other than to update buttons and indicators (runs function main_init ) after restoring the application using the tray icon.


A solution is provided on the [[PHP WinBinder: Alternative control 4 | '''next page''']] that removes the need for this button
A solution is provided on the [[PHP WinBinder: Alternative control 4 | '''next page''']] that removes the need for this button.


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''