MongoDB Tutorial 3: Main Application

From The Uniform Server Wiki
Jump to navigation Jump to search


MongoDB Production Standalone
UniServer 6-Carbo.

Main Application


We currently have a number of utilities that require integrating into our main application.

One solution is to add additional buttons; one per utility. Disadvantage of this approach it breaks the otherwise simplistic interface. In the future we may want to add other utilities this would require another user interface change. Clearly this inflexibility is not an ideal solution.

Preferred solution is to retain simple user interface and add drop down menus to main application. These are easy to implement and very flexible. This page covers adding dropdown menus to run our utilities.


Our main application is shown on right

It consists of four buttons these will be rearranged grouping them into two sections.

To accommodate drop down menus width needs to increase.

Mongo a initial 1.gif


Drop-down Menu

To create a drop-down menu lefts define menu title and items we require

File Configuration Databases Users Help
Exit Change Port Create Database Add User Information
  Change Admin Password Drop Database Delete User About

Menu Items

Menu items when clicked create an event this is passed to the handler function for processing.

Like any other button requires a unique ID this is detected using a case statement and appropriate code run.

Define constants

Edit file z_mongo\mongodb_1\control\mongo_db.php add the following constants:


define('ID_CHANGE_PORT',       1210);
define('ID_CHANGE_ADMIN_PASS', 1220);

define('ID_CREATE_DATABASE',   1310);
define('ID_DROP_DATABASE',     1320);

define('ID_ADD_USER',          1410);
define('ID_DELETE_USER',       1420);

define('ID_M_HELP',           1510);
define('ID_M_ABOUT',          1520);

At start of component section add the following:

//=== Create main menu
$mainmenu = wb_create_control($win_mongo, Menu, array( 
       array(IDCLOSE,                 "Exit"),

       array(ID_CHANGE_PORT,        "Change Port"),
       null,                        // separator 
       array(ID_CHANGE_ADMIN_PASS,  "Change Admin Password"),

       array(ID_CREATE_DATABASE,    "Create Database"),
       array(ID_DROP_DATABASE,      "Drop Database"),


       array(ID_ADD_USER,      "Add User"),
       array(ID_DELETE_USER,   "Delete User"),

       array(ID_M_HELP,        "Help "),
       array(ID_M_ABOUT,       "About...")

  • The drop-down menus are created using function wb_create_control()
    • This is associate with window $win_mongo
    • Menu defines type of component to create
    • An array is passed defining menu headings and menu items.
  • Format is easy to follow
    • Define a menu heading
    • Add menu items for that heading
  • Repeat

Note: A menu item of null inserts a separator

Utilities to run

With menu defined all that is required is to add case statements to the handler function.

We want to run the following functions:



Handler code

Add the following to the handler code

 //=== Process menu items ====================

  case ID_CHANGE_PORT:                // Change server port
  case ID_CHANGE_ADMIN_PASS:          // Change Admin password

  case ID_CREATE_DATABASE:             // Create database

  case ID_DROP_DATABASE:              // Delete database


  case ID_ADD_USER:                   // Add user

  case ID_DELETE_USER:                // Delete user

  case ID_M_HELP:                     // Display help info

  case ID_M_ABOUT:                    // Display About
   $str  = "";
   $str .= "Windows interface by Uniform Server\n";
   $str .= "mongo_pro_standalone_v1_0\n\n";

   $str .= "Core component MongoDB server \n";
   $str .= "Winbinder stub – from phpack v0.7.5\n";
   $str .= "Uniform Server utilities\n";

   wb_message_box($window, $str,"About", WBC_INFO); 

  //=== END Process menu items ====================



That concludes this tutorial finished application shown on right.

Although fully functional consider it a starting point where you can add extra functionality as required.

To download this application; check the download page for details.

See user support page for additional information.

Mongo c initial 8.gif

Components in this application are reusable final application is to produce a Uniform Server plugin version covered in the next tutorial.