Changes

Jump to navigation Jump to search

PHP WinBinder: Alternative control 3

105 bytes added, 19:33, 30 January 2010
Proofreading and grammatical changes; some minor reformatting
'''''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 Each of these buttons needs to access several files one . 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 The advantage of using this solution, is that the application remains compact, requires minimal changes and offers expandability.
== Menu ==
|-valign="top"
|
Adding a menu control is easy it . It forces a menu across the top of your application. 
All you need to do is re-size your application to fit.
From my point of view , it carries baggage that is not required, such as: *keyboard short cuts , which I never use them.  *Images to the side of a menu item! Suppose This is supposed to be intuitive , but I never had a clue what most of them do.
Yep! I like lean and clean.
Please remember this is not a commercial product a . A menu item must be of useuseful.
|
|-valign="top"
|
<br />In WinBinder most parameters are optional , hence the code can be reduced to this
Absolutely no baggage; just clean drop down menus.
It This really is an elegant structure and easy to use.
* Define any ID used, remember remembering that it must be unique
* Add menu text to be displayed to a user
* That’s it
That’s it! Click a menu item and it's its ID is sent to the handler function for processing.
|
<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 which prevents a user killing the servers.
The drop down menu now allows a user to access lower levels of the server and , for example, change say the ports with ease. To implement this , a menu item can open another window to make appropriate changes.
Real The main point is that a simple change to a menu offers real expandability.
'''''[[#top | Top]]'''''
 
== Menu - Example==
{|
The applications main buttons are generally all that is required to run the servers.
However using Using a drop down menu allows various parts aspects of the server to be accessed a . A few possibilities are viewing log files, put putting servers on-line and setting passwords.
To the right are additional items that you may wish to include a . A semi-working menu can be found in example '''test_7.phpw''' to . To see this in action , run '''test_7.bat'''.
'''''Activation'':'''
'''''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.
'''''Tasks'':'''
* Local requires displaying a web page on the local server in a users user's default browser
* View and Edit requires running a users user's default text editor.
* Directly changing a server variable requires a pop-up menu.
* MySQL password restore requires running a batch file. In addition , you require feedback 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 .
'''''Function'': - wb_exec'''
'''''[[#top | Top]]'''''
== Function'': - wb_exec() ==
This function is used extensively in processing menu items three . Three uses are shown below.
'''''[[#top | Top]]'''''
=== Display a local web page ===
To display a local web page , use the following format:
<pre>
wb_exec("http://localhost/path_to_page");
</pre>
For example , to display index page use:
<pre>
wb_exec("http://localhost/index.php");
</pre>
For our application , the above is too specific.
An index page can use one of several file extensions hence , so we do not want to specify an index page. Let We'll 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
A user can change the Apache port this . This needs to be read from the configuration file and included in the Internet address hence , so the following format is required:
<pre>
wb_exec("http://localhost:port_number/");
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.
However , if it is included , the code can be reduced to this:
<pre>
case ID_ROOT: // Server root WWW
</pre>
|}
 
'''''[[#top | Top]]'''''
=== Edit or display text files ===
To edit or display the content of a text file , we use Windows '''notepad''' this . This is contained some where somewhere on the system path.
To obtain the full path to this file , use function '''wb_find_file()''' it . 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 the Apache error.log file is shown below.
<pre>
//--Logs
break;
</pre>
'''''Note 1'':''' The variable '''$us_apache''' must be declaied 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 , so we must check for existence , otherwise an error is generated.
'''''[[#top | Top]]'''''
=== Run another WinBinder application ===
Change MySQL password requires user input. Our current application has been purposefully made minimal hence , 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 an input field and code to change the MySQL port. However it 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.
<pre>
wb_exec("complete_path_of_program_to_run"),"pass_any_parameters" );
</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
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
An optional parameter or parameters can be passed to the script '''test7b.phpw'''
Putting all this together , the line of code looks like this:
<pre>
wb_exec("..\php\php-win.exe", "-c ..\php\php-wb.ini test_7b.phpw 23456"); // Run second window app.
break;
</pre>
'''''[[#top | Top]]'''''
=== Are you sure WBC_YESNO ===
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.
The pop-up box contains two buttons : “YES” and “NO” clicking . Clicking yes returns TRUE and click “NO” returns FALSE.
The handler for restore MySQL password uses this code shown below:
break;
</pre>
An "if" tests the returned value. Pressing the YES button returns true and the restore batch file is run.
'''''[[#top | Top]]'''''
 
== 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 that something is wrong.
A progress bar could be used , however the layout does not justify using one. An alterative alternative is to use another indicator with a different colour linked to the main timer.This indicator flashes , providing a user with feedback when . When the main indicators change , it is turned off.
There are two images blue and blank. These are created as follows:
'''''[[#top | Top]]'''''
 
== Test ==
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 the 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) .
After testing , close both Servers and the application script.
'''''[[#top | Top]]'''''
 
== Summary ==
Essentially that completes the alternative control however there . There is a remaining issue.
You will have noticed a button named refresh, this . 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.
'''''[[#top | Top]]'''''

Navigation menu