phpGW logoDevelopers Guide

phpGroupWare Application Development

phpGroupWare Documentation Team - phpgroupware-docteam at

v0.9.16.001 5 September 2004

This document explains phpGroupWare's infrastructure and API, along with what is required to integrate applications into it.
Please If you want to use phpGroupware + LDAP + other tools like Samba tools Read the file ldap/README_LDAP_WITH_OTHER_TOOLS Thanks Caeies


  1. Introduction
    1. Overview of application writing
    2. What does the phpGroupWare API provide?
  2. Guidelines
    1. Requirements
    2. Writing/porting your application
  3. Installing your application
    1. Overview
    2. Automatic features
    3. Adding files, directories and icons.
    4. Making phpGroupWare aware of your application
    5. Hooking into Administration page
    6. Hooking into Preferences page
  4. Infrastructure
    1. Overview
    2. Directory tree
    3. Translations
  5. The API
    1. Introduction
    2. Basic functions
    3. Application Functions
    4. File functions
    5. Email/NNTP Functions
  6. Configuration Variables
    1. Introduction
    2. User information
    3. Group information
    4. Server information
    5. Database information
    6. Mail information
    7. NNTP information
    8. Application information
  7. Using Language Support
    1. Overview
    2. How to use lang support
    3. Common return codes
  8. Using Templates
    1. Overview
    2. How to use PHPLIB templates
    3. How to use XSLT templates
  9. About this document
    1. New versions
    3. History
    4. Copyrights and Trademarks
    5. Acknowledgments and Thanks

1 Introduction

phpGroupWare is a web based groupware application framework (API), for writing applications. Integrated applications such as email, calendar, todo list, address book, and file manager are included.

1.1 Overview of application writing

We have attempted to make writing application for phpGroupWare as painless as possible. We hope any pain and suffering is cause by making your application work, but not dealing with phpGroupWare itself.

1.2 What does the phpGroupWare API provide?

The phpGroupWare API handles session management, user/group management, has support for multiple databases, using the PHPLIB database abstraction method, we support templates using the PHPLIB Templates class, a file system interface, and even a network i/o interface.

On top of these standard functions, phpGroupWare provides several functions to give you the information you need about the users environment, and to properly plug into phpGroupWare.

2 Guidelines

2.1 Requirements

These guidelines must be followed for any application that wants considered for inclusion into the phpGroupWare distribution:

2.2 Writing/porting your application

Include files

Each PHP page you write will need to include the along with a few variables.
This is done by putting this at the top of each PHP page.

$GLOBALS['phpgw_info']['flags']['currentapp'] = 'appname';

Of course change application name to fit.
This include will provide the following things:

3 Installing your application

3.1 Overview

It is fairly simple to add and delete applications to/from phpGroupWare.

3.2 Automatic features

To make things easy for developers we go ahead and load the following files.

3.3 Adding files, directories and icons.

You will need to create the following directories for your code
(replace 'appname' with your application name)



  |   |

  |   |

  |   |

  |   |



  |   |--base

  |   +--js_package_name


  |   |

  |   |




3.4 Making phpGroupWare aware of your application

To make the application aware of your application, add your application details to the applications table. This can be done via the GUI administration screen, or via a SQL script. The script below should only be used during initial development. You should use the phpGroupWare setup system for install and updating the final version of your application.

INSERT INTO phpgw_applications (app_name, app_title, app_enabled)
        VALUES('appname', 'The App name', 1);

3.5 Hooking into Administration page

When a user goes to the Administration page, it starts appname/inc/ for each application that is enabled, in alphabetical order of application title. If the file exists, it is include()d in the hopes it will display a selection of links to configure that application.

Simple Example:

	// Old linear script style
	$file['Site Configuration'] = $GLOBALS['phpgw']->link('myapp/myAdminPage.php');
	// OR - OOP Style
	$file['Site Configuration'] = $GLOBALS['phpgw']->link('/index.php',
                                        array(menuaction => 'myapp.uiobj.admin_method');

Look at headlines/inc/ and admin/inc/ for more examples.

Things to note:

The standard $GLOBALS['phpgw'] and $GLOBALS['phpgw_info'] variables are in-scope, as is $appname which corresponds to the application name in the path.

3.6 Hooking into Preferences page

The mechanism to hook into the preferences page is identical to the one used to hook into the administration page, however it looks for appname/inc/ instead of appname/inc/ The same functions and variables are defined.

4< Infrastructure

4.1 Overview

phpGroupWare attempts to provide developers with a sound directory structure to work from.
The directory layout may seem complex at first, but after some use, you will see that it is designed to accommodate a large number of applications and functions.

4.2 Directory tree

  +--docs (installation docs)
  +--files (Note: must be out of webserver document root!)
  |   |
  |   +--groups
  |   |
  |   +--homes
  |   |
  |   +--users
  |   |
  |   +--cron (phpgroupware's optional daemons)
  |   |
  |   +--doc (developers docs)
  |   |
  |   +--inc
  |   |   |
  |   |
  |   |   |
  |   |
  |   |   |
  |   |
  |   |   |
  |   |   +--etc..
  |   |
  |   +--js (javascript)
  |   |   |
  |   |   +--base
  |   |   |
  |   |   +--js_package_name
  |   |
  |   +--manual
  |   |
  |   +--setup
  |   |   |
  |   |
  |   |   |
  |   |
  |   |   |
  |   |
  |   |   |
  |   |
  |   |
  |   +--templates
  |   |   |
  |   |   +--default
  |   |   |   |
  |   |   |   +--images
  |   |   |
  |   |   +--verilak
  |   |       |
  |   |       +--images
  |   |
  |   +--themes
  |       |
  |       +--default.theme

4.3 Translations

See section 7, where this is explained in detail.

5 The API

5.1 Introduction

phpGroupWare attempts to provide developers with a useful API to handle common tasks.

To do this we have created a multi-dimensional class $GLOBALS['phpgw']->.

This allows for terrific code organization, and help developers easily identify the file that the function is in. All the files that are part of this class are in the inc/core directory and are named to match the sub-class.

Example: $phpgw->send->msg() is in the inc/phpgwapi/ file.

5.2 Basic functions


$GLOBALS['phpgw']->link($url, $args)
Add support for session management. ALL links must use this, that includes href's form actions and header location's.

If you are just doing a form action back to the same page, you can use it without any parameters.

This function is right at the core of the class because it is used so often, we wanted to save developers a few keystrokes. Example:

<form name=copy method=post action="<?php echo $GLOBALS['phpgw']->link();?>">
/* If session management is done via passing url parameters */
/* The the result would be */
/* <form name=copy method=post action="somepage.php?sessionid=87687693276?kp3=kjh98u80"> */

5.3 Application Functions


Print out the start of the HTML page, including the navigation bar and includes appname/inc/header.php, if using deprecated linear scripts style.


Prints the system footer, and includes appname/inc/footer.php


Store important information session information that your application needs.
$GLOBALS['phpgw']->appsession will return the value of your session data is you leave the parameter empty [i.e. $GLOBALS['phpgw']->appsession()], otherwise it will store whatever data you send to it.
You can also store a comma delimited string and use explode() to turn it back into an array when you receive the value back.


echo "Dir: " . $GLOBALS['phpgw']->common->appsession();

5.4 File functions

See Virtual File System (VFS) Developers Guide for more info.

5.5 Email/NNTP Functions


$phpgw->msg->send($service, $to, $subject, $body, $msgtype, $cc, $bcc)
Send a message via email or NNTP and returns any error codes.

      $to = '';
      $subject = 'Hello buddy';
      $body = "Give me a call\n Been wondering what your up to.";
      $errors = $GLOBALS['phpgw']->msg->send('email', $to, $subject, $body);

6 Configuration Variables

6.1 Introduction

phpGroupWare attempts to provide developers with as much information about the user, group, server, and application configuration as possible.

To do this we provide a multi-dimensional array called "$GLOBALS['phpgw_info']", which includes all the information about your environment.

Due to the multi-dimensional array approach. getting these values is easy.

Here are some examples:

	// To do a hello username
	echo "Hello " . $GLOBALS['phpgw_info']['user']['fullname'];
	//If username first name is John and last name is Doe, prints: 'Hello John Doe'
	// To find out the location of the imap server
	echo 'IMAP Server is named: ' . $GLOBALS['phpgw_info']['server']['imap_server']; 
	//If imap is running on localhost, prints: 'IMAP Server is named: localhost'

6.2 User information

$GLOBALS['phpgw_info']['user']['userid'] = The user ID.

$GLOBALS['phpgw_info']['user']['sessionid'] = The session ID

$GLOBALS['phpgw_info']['user']['theme'] = Selected theme

$GLOBALS['phpgw_info']['user']['private_dir'] = Users private dir. 
	Use phpGroupWare core functions for access to the files.

$GLOBALS['phpgw_info']['user']['firstname'] = Users first name

$GLOBALS['phpgw_info']['user']['lastname'] = Users last name

$GLOBALS['phpgw_info']['user']['fullname'] = Users Full Name

$GLOBALS['phpgw_info']['user']['groups'] = Groups the user is a member of

$GLOBALS['phpgw_info']['user']['app_perms'] = If the user has access to the current application

$GLOBALS['phpgw_info']['user']['lastlogin'] = Last time the user logged in.

$GLOBALS['phpgw_info']['user']['lastloginfrom'] = Where they logged in from the last time.

$GLOBALS['phpgw_info']['user']['lastpasswd_change'] = Last time they changed their password.

$GLOBALS['phpgw_info']['user']['passwd'] = Hashed password.

$GLOBALS['phpgw_info']['user']['status'] = If the user is enabled.

$GLOBALS['phpgw_info']['user']['logintime'] = Time they logged into their current session.

$GLOBALS['phpgw_info']['user']['session_dla'] = Last time they did anything in their current session

$GLOBALS['phpgw_info']['user']['session_ip'] = Current IP address

6.3 Group information

$GLOBALS['phpgw_info']['group']['group_names'] = List of groups.

6.4 Server information

$GLOBALS['phpgw_info']['server']['server_root'] = Main installation directory

$GLOBALS['phpgw_info']['server']['include_root'] = Location of the 'inc' directory.

$GLOBALS['phpgw_info']['server']['temp_dir'] = Directory that can be used for temporarily storing files

$GLOBALS['phpgw_info']['server']['files_dir'] = Directory user and group files are stored

$GLOBALS['phpgw_info']['server'']['common_include_dir'] = Location of the core/shared include files.

$GLOBALS['phpgw_info']['server']['template_dir'] = Active template files directory. 
	This is defaulted by the server, and changeable by the user. 

$GLOBALS['phpgw_info']['server']['dir_separator'] = Allows compatibility with WindowsNT directory format 
	- same as php constant SEP

$GLOBALS['phpgw_info']['server']['encrpytkey'] = Key used for encryption functions

$GLOBALS['phpgw_info']['server']['site_title'] = Site Title will show in the title bar of each webpage.

$GLOBALS['phpgw_info']['server']['webserver_url'] = URL to phpGroupWare installation.

$GLOBALS['phpgw_info']['server']['hostname'] = Name of the server phpGroupWare is installed upon.

$GLOBALS['phpgw_info']['server']['charset'] = user's charset, default:iso-8859-1

$GLOBALS['phpgw_info']['server']['version'] = phpGroupWare version.

6.5 Database information

It is unlikely you will need these, because $GLOBALS['phpgw']->db will already be loaded as a database for you to use.

$GLOBALS['phpgw_info']['server']['db_host'] = Address of the database server. 
	Usually this is set to localhost - but don't assume.

$GLOBALS['phpgw_info']['server']['db_name'] = Database name.

$GLOBALS['phpgw_info']['server']['db_user'] = User name.

$GLOBALS['phpgw_info']['server']['db_pass'] = Password

$GLOBALS['phpgw_info']['server']['db_type'] = Type of database. 
	Currently M$ SQL Server, MySQL and PostgreSQL are supported.

6.6 Mail information

It is unlikely you will need these, because most email needs are services thru core phpGroupWare functions.

$GLOBALS['phpgw_info']['server']['mail_server'] = Address of the IMAP server. 
	Usually this is set to localhost.

$GLOBALS['phpgw_info']['server']['mail_server_type'] = IMAP or POP3

$GLOBALS['phpgw_info']['server']['imap_server_type'] = Courier/Cyrus, Uwash or UW-Maildir

$GLOBALS['phpgw_info']['server']['imap_port'] = This is usually 143.  
	Should only be changed if there is a good reason.

$GLOBALS['phpgw_info']['server']['mail_suffix'] = This is the domain name, used to add to email address

$GLOBALS['phpgw_info']['server']['mail_login_type'] = This adds support for VMailMgr. 
	Generally this should be set to 'standard'.

$GLOBALS['phpgw_info']['server']['smtp_server'] = Address of the SMTP server. 
	Usually this is set to localhost.

$GLOBALS['phpgw_info']['server']['smtp_port'] = This is usually 25.
	Should only be changed if there is a good reason

6.7 NNTP information

$GLOBALS['phpgw_info']['server']['nntp_server'] = Address of the NNTP server.

$GLOBALS['phpgw_info']['server']['nntp_port'] = This is usually 119.
	Should only be changed if there is a good reason.

$GLOBALS['phpgw_info']['server']['nntp_sender'] = Unknown

$GLOBALS['phpgw_info']['server']['nntp_organization'] = Unknown

$GLOBALS['phpgw_info']['server']['nntp_admin'] = Unknown

6.8 Application information

Each application has the following information available.

$GLOBALS['phpgw_info']['apps'][$appname]['title'] = The title of the application.

$GLOBALS['phpgw_info']['apps'][$appname]['enabled'] = If the application is enabled. True or False.

$GLOBALS['phpgw_info']['server']['app_include_dir'] = Location of the current application include files.

$GLOBALS['phpgw_info']['server']['app_template_dir'] = Location of the current application tpl files.

$GLOBALS['phpgw_info']['server']['app_lang_dir'] = Location of the current lang directory.

$GLOBALS['phpgw_info']['server']['app_auth'] = DEPRECATED?
	If the server and current user have access to current application

$GLOBALS['phpgw_info']['server']['app_current'] = name of the current application.

7 Using Language Support

7.1 Overview

phpGroupWare is built using a multi-language support scheme. This means the pages can be translated to other languages very easily. Translations of text strings are stored in the phpGroupWare database, and can be modified by the phpGroupWare administrator.

7.2 How to use lang support

The lang() function is your application's interface to phpGroupWare's internationalization support.

While developing your application, just wrap all your text output with calls to lang(), as in the following code:

$x = 42;
echo lang('The counter is %1', $x).'<br />';

This will attempt to translate ``The counter is %1'', and return a translated version based on the current application and language in use. Note how the position that $x will end up is controlled by the format string, not by building up the string in your code. This allows your application to be translated to languages where the actual number is not placed at the end of the string.

When a translation is not found, the original text will be returned with a * after the string. This makes it easy to develop your application, then go back and add missing translations (identified by the *) later.

Without a specific translation in the lang table, the above code will print:

The counter is 42*<br />

If the current user speaks Italian, the string returned will be:

il contatore è 42<br />

The lang function

lang($key, $m1="", $m2="", $m3="", $m4="", $m5="", $m6="", $m7="", $m8="", $m9="", $m10="")

is the string to translate and may contain replacement directives of the form %n. This string should be lower case.


is the first replacement value or may be an array of replacement values (in which case $m2 and above are ignored).

[$m2 - $m10]

the 2nd through 10th replacement values if $m1 is not an array.

The database is searched for rows with a lang.message_id that matches $key. If a translation is not found, the original $key is used. The translation engine then replaces all tokens of the form %N with the Nth parameter (either $m1[N] or $mN).

Adding translation data

An application called Translation Tools has been developed to make this easier. Please use this application or edit the lang files manually. The table information is here as a reference, but direct database insertions should not be used.

The lang table

The translation class uses the lang table for all translations. We are concerned with 4 of the columns to create a translation:


The key to identify the message (the $key passed to the lang() function). This is written in English.


The application the translation applies to, or common if it is common across multiple applications.


The code for the language the translation is in.


The translated string.


The translations are now being done thru the database, and may be configurable to use other mechanisms in future releases.

You can use the developer_tools translations application for creating the "lang files", which will be installed through the setup application. Alternatively you can edit the files manually. The file naming convention for the lang files is phpgw_<langcode>.lang. The files are stored in the app/setup directory. The format of the files is as follows:

english phrase in lower case    appname 	**      Translated phrase in desired case.

translating the content to reflect the message_id string in the lang language. If the string is specific to your application, put your application name in for app_name otherwise use the name common. The message_id should be in lower case for a small increase in speed.

7.3 Common return codes

If you browse through the phpGroupWare sources, you may notice a pattern to the return codes used in the higher-level functions. The codes used are partially documented in the doc/developers/CODES file.

Codes are used as a simple way to communicate common error and progress conditions back to the user. They are mapped to a text string through the check_code() function, which passes the strings through lang() before returning.

For example, calling

echo check_code(13);

Would print

Your message has been sent

translated into the current language.

8 Using Templates

8.1 Overview

phpGroupWare is built using a templates based design. This means the display pages, stored in tpl files, can be translated to other languages, made to look completely different.

phpGroupWare is changing template engines for the 0.9.18 release. All versions of phpGroupWare upto 0.9.16 use the PHPLIB template engine. As of the 0.9.18 release phpGroupWare will use a "home grown" XSLT based template engine.

8.2 How to use PHPLIB templates

For Further info read the PHPLIBs documentation for their template class.

8.3 How to use XSLT templates

Whoops, there is no documentation available on this - hassle the docteam to produce something.

9 About this document

9.1 New versions

The newest version of this document can be found on our website as HTML and plain text.


Comments on this HOWTO should be directed to the phpGroupWare developers mailing list phpgroupware-docteam at

To subscribe, go to

9.3 History

9.4 Copyrights and Trademarks

Copyright © Free Software Foundarion. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation.

A copy of the license is available at

9.5 Acknowledgments and Thanks

Thanks to Joesph Engo for starting phpGroupWare (at the time called webdistro). Thanks to all the developers and users who contribute to making phpGroupWare such a success.