OpenBiz Document 1.1.1IntroductionOpenBiz provides a PHP framework that assists you to build complicated web application in an easy way. OpenBiz is designed as a multi-layer architecture as the figure below.
Usually a business application can be modulated to 3 layers - Data layer, Business Logic layer and Presentation layer. In OpenBiz architecture, these 3 layers map to 3 packages, Presentation layer is refined to logic which is implemented by BizView package and GUI layers which is implemented by jbForm javascript package. Business Logic layer is implemented by BizObj package. 3rd party package ADODB handles Database layer. Package BizObjClasses
Functionalities
Package BizViewClasses
Functionalities
Package jbForm (javascript bizForm)Class
Functionalities
Package ADODBThis is an abstract database connection package which can connects to all major databases from different vendors. It can be downloaded from http://php.weblogs.com/ADODB Installation1. Running environmentOpenBiz is written by PHP4 scripts, it runs at web server side. The typical running environment could be Web Server + PHP 4.x. To ensure the performance and reliability, we recommend users to use latest web server and php engine. For example
If you have the administrator permission, you can configure PHP running as an Apache module. Some php performance software, such as mmcache, works under Apache module. This url http://www.thesitewizard.com/archive/php4install.shtml is the guide to setting up PHP 4 to run with Apache on Windows. For better performance, please enable dom xml extension under PHP4. Please refer to http://us4.php.net/domxml. domxml extension is required to run Design Studio. Support web browsers - IE5.x, Netscape 7.x and Mozillar 1.x 2. Install OpenBizDownload the zip file and unzip it to a directory under your web access root. Please read through the sysheader.inc under openbiz_root/ directory. Important notices:
Source tree structure:
In Unix or Linux box, you need to give write permission to web users on log, metadata, session, bin/tmpfiles and bin/templates_c directories. 3. Install necessary third party packagesThe following package are necessary - they are included in openbiz package
We recommend you install PHP optimization packages.
4. Windows Installer with AppServFor Windows users who want to install Web Server + PHP + Openbiz, an installer is available since B10110. Please follow the steps below:
Build Your Application1. Specify requirement of your applicationOpenBiz is a perfect tool that help you develop your complicated web application easily and comprehensively. Based on its 3-layer architecture, your application will be on a clear logic model. It takes care the basic and advanced feature of the data-oriented application. In order to tell whether OpenBiz can help building your application, you need ask these questions:
If the answers are YES, OpenBiz is the right framework for developing your application! 2. Create your database modelModeling your business data with Relational database tables is the necessary base for building your whole application. Populate the demo database to see how demo works
Create a new database
Use existing database (assume each table has single auto-generated id column)
3. Create metadata xml filesDevelopers can choose use XML editor to edit medata files or use Openbiz Designer to visually edit metadata files. For more detail of Openbiz designer, Please refer to Openbiz designer user manual. 3.1 Organize metadata by packageIn a big application, user may need to build lots of objects, therefore they have big metadata file list. If they put these files under a single metadata directory, managing the metadata files is a painful thing. From openbiz 1.1, metadata files can be organized by package name. Bear in mind, metadata package is different with the (BizObj, BizView ...) packages which are the code units. Metadata package is a naming system, different package maps to different directory. It is like the package concept used in Java. PackageX.PackageY.metaA.xml refers to the metaA.xml under META_PATH/PackageA/PackageB directory. Where META_PATH is the root metadata directory. This macro is defined in sysheader.inc with define ("META_PATH", "../metadata/"). 3.1.1 How to configure package in metadata files? Let's explain it with the demo example. After you unzip the source, find the demo directory under metadata directory. Open FMRegist.xml file with a text editor. You'll see a Package="demo" attribute in the BizForm element. This attribute is to say the default package of any type of openbiz object is under "demo" package. Here the openbiz objects refer to the following object types.
If an object name doesn't contain dot symbol ("."), the system uses the package attribute defined in the object root element as its package. Otherwise, if an object name has format as aaa.objectname, the system thinks such object under package "aaa" and will locate such object under aaa directory. Go back to the example, you can find <BizForm Name="FMRegist" Package="demo" ... BizObj="BORegist"...>, <BizCtrl Name="reg_attdln" ... SelectBizForm="AttendeePopup"...> and <BizCtrl Name="reg_fee" ... SelectFrom="Selection(Fee)"...>. They all use default package, so the system will try to locate the metadata files as demo/BORegist.xml, demo/AttendeePopup.xml and demo/Selection.xml. If you want to refer to an object under other package, just add the package name as the prefix of the object name. Notice, there're a Selection.xml under /demo directory and another Selection.xml under /design directory, they belong to different packages. In FMRegist, whose package is "demo", you can use <BizCtrl ... SelectFrom="design.Selection(Mode)" ...> to configure a comboBox whose values are from the "Mode" element of "design/Selection.xml". 3.1.2 How to configure package with Openbiz Design Tool? From openbiz 1.1, in the object browser view of Design Tool, user can give "Package" name for each object. If the object is not found under the directory (META_PATH/package/) mapping to the given package, a sample metadata file (copied from object type template) is created under that directory. If no package name is specified, a sample metadata file (copied from object type template) is created under META_PATH/ directory.
3.2 Use object metadata inheritanceIf you have a complex application, you want to reuse the existing object to different places, but you want the object behave a little differently in different scenarios. Object inheritance will solve the above problem. Since in openbiz framework objects maps to metadata file, object inheritance becomes metadata file inheritance. 3.2.1 How to specify inheritance between metadata files? Specify an object attribute, InheritFrom = "parent object name". For example, in demo application, BOEventX has <BizObj Name="BOEventX" Description="Event BizObj Extended from BOEvent" Package="demo" Class="BizObj" InheritFrom="demo.BOEvent"...>. This indicates that is BOEventX is inherited from BOEvent. Metadata file inheritance is similar with class inheritance in programming languages, child object can inherit (if not defined in child object, but defined in parent object) or override (if same attribute defined in both child object and parent object) the parent object attributes.
3.3 Create an object record in ObjBrowse viewOpen design.htm in browser to access OpenBiz Design Studio. In unix, make sure your metadata directory has write permission open for web clients. Put focus on a record, click "Design" button
3.4 Build BizObj metadataBizObj metadata file describes the mapping between database tables and BizObj. It's a xml file with following DTD.
Open Design Studio screenshot - BizObj Design. Click "Go Back to object browser" button
Important Notes:
3.4.1 Composite keys support Most database table designers recommend each table have its unique primary key column which is also called ID column. In Openbiz BizObj, Id field is a required field for all BizObj. If table has ID column, it's easy to map such column to Id BizField. But there's still many tables are given composite keys. Openbiz provide the following solution to map composite keys to Id BizField. On the Id BizField of a BizObj, user can specify >1 column names in the BaseColumn attribute. For example, <BizField Name="Id" ... BaseColumn="key1,key2,key3" ...>. But you need to make sure all BizFields mapping to the composite keys are marked as "Required='Y'". 3.4.2 Efficiently use memory by specifying cache mode Openbiz leverages server side BizObj cache (storing database query results temporally) to maintain the session data so that users can feel smooth interaction just as they are using desktop rich client. But many web interfaces simply provide navigation only functionality. To help openbiz use memory efficiently, BizObj cache mode can be turned off. There're two ways to control the cache mode. 1) Set CacheMode attribute in BizObj metadata file. <BizObj Name=... CacheMode = "0|1" ...>. 0 means no cache is used, 1 means query data is cached. If no value is given, default cache mode = 1. 2) Call BizObj::Home($cacheMode) to reset the ResultSet and set the cache mode. The default $cacheMode is 1. Keep in mind, no cache mode is suggested to be used in navigation only BizForm. 3.5 Build BizForm metadataBizForm metadata file describes the mapping between BizObj and BizForm as well as other UI controls in BizForm. It's a xml file with following DTD.
Open Design Studio screenshot - BizForm Design.
3.6 Build BizView metadata BizView metadata file describes the BizForms and their relationship in the BizView. It's a xml file with following DTD.
Open Design Studio screenshot - BizView Design.
3.7 Build BizPopup metadataBizPopup is a special BizView. It has only one BizForm and uses BizForm.dtd file as its XML schema. Because the BizPopup is mainly used in record selection, it makes sense to provide only navigation and query for its BizForm, meanwhile only need to show most critical columns. Open Design Studio screenshot - BizPopup Design
3.8 Build BizFormTree metadataBizFormTree is a special BizForm. It uses BizForm.dtd file as its XML schema. BizFormTree is designed to represent the tree hierarchy relationship within a database table. For example, event table schema: (every record has PARENT_ID and CHILD_FLAG columns which build tree hierarchy relationship between the records in the same table)
Open Design Studio screenshot - BizFormTree Design |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| BizCtrl/BizForm | BizField/BizObj | |
| Base BizForm | Ctrl_1/FM_1 | Fld_1/BO_1 |
| Popup BizForm | Ctrl_2/FM_2 | Fld_2/BO_2 |
Step1: Give SelectBizObj=BO_2 and SelectField=Fld_2 for the Fld_1 in BO_1 xml file
Step2: Create a Popup_2.xml whose BizForm is FM_2
Step3: In FM_1.xml set SelectBizForm=FM_2 for Ctrl_1
Please see the example in demo xml files (BORegist, FMRegist, BOEvent, EventPopup). In this example, it is configured to select event data to populate multiple fields on FMRegist. Click here to see the screenshot.
5.4 Link 2 BizForm with dependent relationship
You can define the dependency relationship between BizForms in a same view. Records in a child BizForm is dynamically changed along the record change on it parent BizForm. Such relationship is defined in BizView xml file.
<BizView ... >
<ControlList>
<Control Name="fm_1" Form="ParentForm" SubCtrls="ChildForm"/>
<Control Name="fm_2" Form="ChildForm" Dependency="ChildBizCtrl=ParentForm.ParentBizCtrl"/>
</ControlList>
</BizView>
Please see the exmaple in demo xml files - RegistView.xml. It defines that Registration BizForm depends on Player BizForm (RegForm.PlayerId = PlyForm.PlayerId). Click here to see the screenshot.
5.5 Data type, format and validation
5.5.1 Openbiz support following data types and formats (attributes of BizField)
| Type | Format | Syntax | Format Example |
| Text | none | ||
| Number | format supported by printf | <BizField ... Type="Number" Format="%..." ...> | %5.2f to print a float number |
| "Int" - integer format according locale | <BizField ... Type="Number" Format="Int" ...> | If locale=enu, 12345.678 is displayed as 12,346 | |
| "Float"- float format according locale | <BizField ... Type="Number" Format="Float" ...> | If locale=enu, 12345.678 is displayed as 12,345.68 | |
| Date | In default read-only mode, a date can be formatted according to the Date format. | <BizField ... Type="Date" Format="date format" ...> | 6/21/2003 can be formatted as %A, %b %d %Y - Saturday, Jun 21 2003 if system locale is enu |
| In edit/query mode, a date is formatted as YYYY-MM-DD (ISO 8601) | 12/31/2003 can be formatted as 2003-12-31 | ||
| Datetime | In default read-only mode, a date can be formatted according to the Date format. | <BizField ... Type="Datetime" Format="datetime format" ...> | 6/22/2003 9:30am can be formatted as %m/%d/%Y %H:%M:%S - 06/22/2003 09:30:00 if system locale is enu |
| In edit/query mode, a date is formatted as YYYY-MM-DD hh:mm:ss (ISO 8601) | 6/22/2003 9:30am can be formatted as 2003-06-22 09:30:00 |
||
| Currency | Formatted according to locale setting | <BizField ... Type="Currency" Format="Currency" ...> | 1456.89 is formatted as $1,456.89 (enu) 1456.89 is formatted as F1 456,89 (fra) |
| Phone | Formatted according to given mask # | <BizField ... Type="Phone" Format="mask string" ...> | 1234567890 is formatted as mask=(###) ###-####, phone=(123) 456-7890 mask=###-###-####, phone=123-456-7890 |
| If a phone number starting with "*", it represents international phone number, it won't be formatted | *123 4567890 is treated as international number |
5.5.2 Openbiz support following data validations
| Validation Type | Example |
| Required - indicates the field can not be empty | <BizField Name="Name" Required="Y" BaseTable="players" BaseColumn="NAME"/> |
| Validator - php statments that returns a boolean value | <BizField Name="Fee" Type="Currency" Format="Currency" Validator="return [Fee]>=15;" BaseTable="regist" BaseColumn="FEE"> |
5.6 Present data with various HTML elements
From B10107, customer can present their data with various HTML elements by specifying element type and attributes in BizForm xml files. HTML elements are displayed in edit/query modes
|
Attributes of FieldControl element in BizForm |
|||||||||
| Type | Width | Height | HTMLAttr* | Style** | SeclectFrom | Caption | Function | Image | Comments |
| Text | x | x | x |
x | x OnChange |
Single line text input. Default type | |||
| Textarea | x | x | x | x | x OnChange |
Multi-line Text input | |||
| ListBox | x | x | x |
x | x |
x OnChange |
ListBox or ComboBox | ||
| CheckBox | x | x | x | x | x |
x OnClick |
CheckBox | ||
| Radio | x |
x | x | x | x |
x OnClick |
Radio buttons | ||
| HTMLButton | x | x | x | x | x | x OnClick |
Standard HTML Button | ||
| SubmitButton | x | x | x | x | x | x OnClick |
Standard HTML Submit Button | ||
| ResetButton | x | x | x | x | x | x OnClick |
Standard HTML Reset Button | ||
| Password | x | x | x | x | HTML password | ||||
| Button | x | x | x | x | x | x OnClick |
x | OpenBiz image button | |
| Date | x | x | x | x | Textbox with date picker icon | ||||
| Datetime | x | x | x | x | Textbox with datetime picker icon | ||||
| HTMLBlock | x | x | x | x |
Caption is treated as HTML block | ||||
| FunctionColumn | x | x | x | x | x | x | This type doesn't map to a data field | ||
* HTMLAttr field can contain any valid additional HTML attribute applied on the HTML element type
** Style field can contain any valid style properties (css)
HTMLAttr="maxlength=N" to limit the maximum number of characters that the user can enter in a text control.
By default show comboBox. If HTMLAttr="size=N", show N-row listbox.
SelectFrom="XmlFile(Key)" means this field control is a listbox or radio buttons whose data is from the "Key" elements in XmlFile.
SelectFrom="Value" means this checkbox returns the Value when user check the checkbox.
By default the radion buttons are arranged horiztionally. If HTMLAttr="wide=1", you can force them arranged vertically.
"<" and ">" used in HTML block have to be replaced by "<" and ">".
5.7 Use the aggregation SQL functions
You can assign a BizField with SQL functions provided by the database engine. The syntax is
<BizField Name="FieldName" BaseTable="TableName" BaseColumn="FUNC(ColumnName)"...>
For example:
<BizField Name="SumFee" BaseTable="regist" BaseColumn="SUM(FEE)"...>
5.8 Usage of SearchRule, SortRule and OtherSQLRule
| Syntax | Example | |
| SearchRule | SearchRule = SQL Where clause* | SearchRule = "[LastName]='Yao' OR [FirstName]='James'" |
| SortRule | SortRule = SQL Order By clause* | SortRule = "[Id] ASC" |
| OtherSQLRule | OtherSQLRule = any SQL clause* | OtherSQLRule = "GROUP BY [EvtId] HAVING [SumFee]>10" |
* Replace the Column name with BizField name.
5.9 Usage of rule in calling GoToView from client
The most useful client side javascript function is GoToView(view, rule, loadPageTarget).
| Argument | Description | Sample |
| view | the view name | |
| rule | the search rule of a bizform who is not depent on (a subctrl of) another bizform
syntax is "form.ctrl operator value". |
FMSponsor.spr_exp>=12000
FMSponsor.spr_name=\'Midas Auto\' OR FMSponsor.spr_id=\'SPSR_2\' FMSponsor.spr_name LIKE \'S%\' |
| loadPageTarget | the window or frame target to load the page |
In the demo application, EvtMenu.htm consists of a list of hyperlinks that call GoToView functions.
5.10 Make your own calendar and timestamp picker
- Change the look-and-feel of calendar and timestamp picker
Modify the stylesheet file popcalendar.css under openbiz_root/css. - Change the text shown on the calendar and timestamp picker
Modify the variables definition part of popcalendar.js under openbiz_root/.
Advanced: build your application by extending OpenBiz
OpenBiz provide many functionalities to building a complicated web application. But different application has different requirement, so you may extend OpenBiz packages to build customer oriented application.
Because OpenBiz packages are based on object-oriented design, you can easily build up your own object by extending these packages and inherit all useful functions provided by them.
Since B10107, extended classes are automatically loaded on demand. Customers can put their library files under /bin or /bin/usrlib/. Extended class must be included in a file with format as ClassName.php.
1. Extend BizObj and BizForm
/**
* class BOUser is the BizObj class to implement USER logic object
*/
class BOUser extends BizObj
{
function BOUser($xmlFile=null) {}
function my_special_function() {} // new function
}
/**
* class FMUser is the BizForm class to implement USER UI object
*/
class FMUser extends BizForm
{
function FMUser($xmlFile=null) {}
function my_special_function() {} // new function
function Render() {} // override Render()
}
2. Implement Plug-in Service Interface
From openbiz 1.1, customer can write their special logic by implement Plug-in Service Interface.
- Define the caller function in BizForm metadata file
<... Function="CallService(ClassName,MethodName)"...> is to call a method "MethodName" of the service "ClassName". ClassName is a class which defined in ClassName.php under bin/usrlib/ directory - Implement the class and method in the ClassName.php
A input argument of the method are the caller's object name (a BizForm name) and the input data string (a collection of form values from client browser). It implements the user-specific business logic and returns void. See the following code snippet.
class chartService
{
function chartService() {}function render($objname, $inputDataStr)
{
$kvArray = ExtractInputToArray($inputDataStr);
$chartName = $kvArray['__this']; // get the value of the control that issues the call// get the current UI bizobj and its querySQL, create a new bizobj and search with the same sql
$bizform = &sys_getobj($objname); // get the existing bizform object// copy to a new bizobj, not touch the bizobj belong to UI, syntax may change in PHP5
$bizobj = $bizform->m_BizObj;
...
}
Three examples can be found in bin/usrlib/
- pdfService.php - prints PDF report. Use FPDF library http://www.fpdf.org/
class PDF_SQL_Table is the base class to print a pdf table based on sql query. It provide the capability for users to configure title, title font, table header font, table row font and table color theme easily. - excelService.php - print Excel output with HTML or CSV formats
- chartService.php - draw business charts based on chart xml definition file. Use Jpgraph library http://www.aditus.nu/jpgraph/
Please refer to the chart service document to understand how to configure chart xml file.
3. Implement View Access Control
By assigning a customer function call to the "AccessControl" attribute of BizView, access control can be added to a view. The syntax is
<BizView ... AccessControl="ClassName.MethodName"...>
Or <BizView ... AccessControl="I"...>. If I=0 access denied; if I=1 view readonly; if I=2 view is read+write.
You can control the access level of each control by assign "Access" attribute (READ/WRITE) to a control in BizForm. If no Access attribute is given, openbiz treates it have "WRITE" permission.
<Control Name="SearchButton" ... Access="READ">
<Control Name="EditButton" ... Access="WRITE">
Then implement this function call as a class method with a input argument as view name. The function should return an integer value.
| Return Value | Meaning |
| 0 | Cannot access the view. System will show an error page "viewdenied.tpl" |
| 1 | View is read-only |
| 2 | View is editable |
/* Example: method CanAccessView of class ViewControl.
BizView config as AccessControl="ViewControl.CanAccessView" */
function CanAccessView($view)
{
//$userid = _SESSION["login"];
//check if this user can access this view
//if view is not accessible
// echo "$view is not accessible!";
// exit;
//else
// return; // (0,1,2) - (no view, read, write)
}
API Document
OpenBiz API Document is generated by PhpDocumentor http://phpdocu.sourceforge.net/
Debug Strategies
- The error is logged under /log/log_error.html, open it and you may find out what's wrong
- Open the sysheader.inc under /bin, turn on debug log by changing define("DEBUG", 1); Then you'll see some debug information in /log/log_debug.html. This debug file records mainly the database calls and other operations
-
- Printer-friendly version
- Login to post comments
















