This manual describes how to program your own modules for Xentral.
Each module consists of at least one .php file and matching templates. The structure of the .php file is predefined. A comprehensive example can be found in Xentral (vorlage.php).
The .php file is always in the www/pages folder. The name of the file corresponds to the module name. The templates are located in the www/pages/content folder.
Example:
It is important that these naming conventions are adhered to, since the framework can automatically load the modules based on these names, or e.g. also the the rights system can automatically recognize the actions.
The name of the app, or the module or simply said the .php file is called in Xentral module. In the file is everything that belongs to a module or app. To appear in Xentral as an interface, the user must have the appropriate permissions. So that Xentral knows separate "actions" have to be written for individual sub-surfaces or actions. How these are divided is in principle up to the user. It must only be known that in the rights management these actions can be given to a user by the rights or not. Typical actions are:

If possible, this method should always be followed. It is e.g. that "list" will automatically try to start if the module is called without action.
The call of the modules with the appropriate actions can be done via the URL.
index.php?module=mymodule&action=list
A further exemption to be noted is that as GET parameter currently mostly only "id" for passing the primary key for the current record and "cmd" for passing a "subcommand for the action", if necessary, are to be used.
All other parameters are passed as POST.
A file looks minimally like this:
<?php
//WAWIFILEONLYON VERSION=ALL
class mymodule {
var $app;
function __construct(&$app, $internal = false) {
$this->app=&$app;
if($internal)return;
$this->app->ActionHandlerInit($this);
// from here define all action handlers the module has
$this->app->ActionHandler("list", "MymodulList");
$this->app->ActionHandler("create", "MyModuleCreate");
$this->app->ActionHandler("edit", "MyModuleEdit");
$this->app->ActionHandlerListen($app);
}
function MyModuleList()
{
$this->app->Tpl->Parse("PAGE", "existenzgruender_list.tpl");
}
Fitting the template in
www/pages/content/mymodule_list.tpl
<!-- WAWIFILEONLYON VERSION=ALL -->
<!-- belongs to tabview -->
<div id="tabs">
<ul>
<li><a href="#tabs-1">test</a></li>
</ul>
<!-- end belongs to tabview -->
<!-- first tab -->
<div id="tabs-1">
[MESSAGE.]
[TAB1]
[TAB1NEXT]
</div>
<!-- close tab view -->
</div>
In the constructor you can see the definition of the ActionHandler. These are the individual sub-surfaces. Xentral allows the call only, if the user has the appropriate rights. I.e. it does not have to care whether the user is currently allowed to do this or not, because the framework takes care of this independently.
Each action must be registered in the constructor.
$this->app->ActionHandler("edit", "MyModuleEdit");
The first parameter contains the name specified by index.php?module=mymodule&action=edit. In the second parameter is the local method name. I.e. in this file there must be a method MyModuleEdit, which will be automatically called.
function MyModuleEdit()
{
}
There is a template system for the output of interfaces. Basically these .tpl files are the HTML pieces or parts of the user interface that are passed so that the user can see his surfaces. In the PHP file should not contain complete HTML structures, but only content that is listed will be filled. If a special table has to be created in PHP (knowing that there are mechanisms or tables in Xentral) it would be fine if the table contents are created by PHP (i.e. the and tags). But that's all it should be. Everything else can go directly into the .tpl file. Content always comes into the .tpl file via template variables. These are in square brackets completely capitalized variables e.g. [DATE], [STREET], [FORMVAL1_ADDRESS] These values in the template can be filled with the two methods "Set" and "Add", the complete content of the variable is overwritten. With Add the existing contents, which were defined before with Set or Add,remains and is appended accordingly at the end.
Examples:
$this->app->Tpl->Set("NAME", $name_from_db);
$this->app->Tpl->Add("NAME", "Hans");
The complete content of a template can be passed to a template variable. So e.g. the surface of an ActionHandler can be passed to Xentral in which the template is output to [PAGE].
Therefore, at the end of the ActionHandler there is usually the following line:
$this->app->Tpl->Parse("PAGE", "mymodule_list.tpl");
I.e. the template with all the previously filled variables is written into the new variable PAGE. Xentral outputs this later, when the necessary permissions, etc. have been assigned.
$output = $this->app->Tpl->Output("mymodule_list.tpl);
git the template directly into the $output variable.
The following describes how standard functions are mapped with Xentral. All modules should be developed according to this scheme.
The database is accessed with Xentral via the module $this->app->DB. There are different methods here. You should always use this one and not other methods. For example, to get the address data of an address, the method SelectArr can be used:
$this->app->DB->SelectArr("SELECT * FROM ...");
outputs a two-dimensional array
$this->app->DB->Select("SELECT number FROM article WHERE id = '$id' LIMIT 1");
This outputs a single value, if exactly one column and one row results from the query. Otherwise an array is output
Query without direct output
$query = $this->app->DB->Query("SELECT * FROM article WHERE project = '$project'");
Get the next row from the query
$row = $this->app->DB->Fetch_Array($query);
Releasing the resource
$this->app->DB->free($query);
Add records:
$this->app->DB->Insert("INSERT INTO article (number, name_en) VALUES ('10000','examplearticle');
Get the record id after the insert
$id = $this->app->DB->GetInsertID();
To change a record:
$this->app->DB->Update("UPDATE article SET project = '1' WHERE id = '$id'");
Variables of a form are always accessed via the Secure module. This ensures, among other things, that the contents do not contain SQL injection or similar. In xentral, $_GET and $_POST must never be accessed directly.
Examples:
It is often necessary to know which user is currently performing something, because e.g. in the own time recording the data records are linked with the own ID or in general, if something is to be executed or stored user-specific.
For many standard widgets there are ready-made mechanisms in xentral.
A DatePicker can be activated easily:
$this->app->YUI->DatePicker("date");
<input type="text" id="date" name="date">
Often there are fields in Xentral where you type and then other things are suggested. This is e.g. an AutoComplete
Available variables
$heading $heading is an array with the table headers $heading = array ('document no', 'customer no', 'customer', 'sales', 'menu');
$width specifies the widths of the columns in %. $width = array('20%','20%','29%','10','1%');
$findcols For each column, you must specify the sorting audprint $findcols = array('a.voucher_number','adr.customer_number','adr.name','a.sales_net','a.id');
$searchsql Specifies the columns / expressions to search in. $searchsql = array('a.documentnr', 'adr.customernumber', 'adr.name', 'adr.location'); $defaultorderGives specifies the column to sort by by default (counting starts from 1).
$defaultorder = 5;//sort by id
$defaultorderdesc Specifies whether the default sorting should be ascending (0) or descending (1). $defaultorderdesc = 1; //Descending sorted
$sql Contains the SQL query with columns and FROM part, but without WHERE, GROUP BY, SORT or LIMIT $sql = "SELECT SQL_CALC_FOUND_ROWS a.id,a.voucher_nr, adr.customernumber,a.name,format(a.sales_net,2) , a.id FROM order a LEFT JOIN address adr ON a.address = a.id"
$where Contains the components of the WHERE query without the WHERE keyword. $where = "a.status != 'created'";
$count Specifies the complete query that returns the number of records. $count = "SELECT count(id) FROM order WHERE status != 'created'";
$menucol Specifies the position of the menu column. This is necessary if minidetails are included. $menucol = 5;
$alignright If columns are to be displayed right-aligned (e.g. for amounts), this can be specified in the variable $alignright. This is done in an array with the column numbers as elements. $alignright = array(4); //Turnover column will be right-justified
$sumcol A summation of the displayed data records can be displayed in the footer of the table $sumcol = 4; the sales will be displayed summed up. 16.4 this can also be written as an array if multiple columns are summed.
Xentral automatically pulls information from the ActionHandler in the constructor, the info for the rights management.
In order to extend a widget, the original widget must be included and the original class must be appended with a custom and overloaded. Example order widget:
<?php
include_once ("widget.order.php");
class WidgetOrderCustom extends WidgetOrder
{
...
To simplify the programming the line 'error_reporting(E_ERROR);' in www/index.php can be changed to 'error_reporting E_ALL);'. This way syntax errors are no longer swallowed by the parser. However, the option should be reset to the original state when it is no longer needed, since sensitive data can be output.