egroupware_official/doc/developers/phpGW_Developers-HOWTO.sgml

644 lines
26 KiB
Plaintext
Raw Normal View History

2000-08-18 05:24:22 +02:00
<!doctype linuxdoc system>
<!-- LinuxDoc file was created by hand by <Dan Kuykendall> 7 July 2000 -->
<!--
$Log$
Revision 1.6 2000/09/29 05:24:17 sjb4891
Added $phpgw->common->phpgw_footer() function, and changed all
places that were including the footer.inc.php to use the function.
Re-arrange phpgw.inc.php to include optional classes after reading the DB config
misc bugfixes.
-->
2000-08-18 05:24:22 +02:00
<article>
<title>
phpGroupWare Application Development
</title>
<author>
Dan Kuykendall &lt;dan@kuykendall.org&gt;
</author>
<date>
v0.9 29 September 2000
2000-08-18 05:24:22 +02:00
</date>
<abstract>
This document explains phpGroupWare's infrastructure and API, along with what is required to integrate applications into it.
2000-08-18 05:24:22 +02:00
</abstract>
<toc>
<sect>Introduction
<p>
phpGroupWare is a web based groupware application framework (API), for writing applications. Integrated applications such as
2000-08-31 08:05:46 +02:00
email, calendar, todo list, address book, and file manager are included.
2000-08-18 05:24:22 +02:00
</p>
<sect1>Overview of application writing
<p>
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.
</p>
<sect1>What does the phpGroupWare API provide?
<p>
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.<newline>
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.
2000-08-18 05:24:22 +02:00
</p>
<sect>Guidelines
<sect1>Requirements
<p>
2000-08-31 08:05:46 +02:00
These guidelines must be followed for any application that wants considered for inclusion into phpGroupWare deluxe.
2000-08-18 05:24:22 +02:00
</P>
<P>
It must run on PHP3 and PHP4. <newline>
SQL statements must be compatible with both MySQL and PostgreSQL.<newline>
It must use our default header.inc.php include.<newline>
It must use our <tt>$phpgw_link($url)</tt> for all links (this is for session support).<newline>
It must use "post" for forms.<newline>
2000-08-18 05:24:22 +02:00
It must respect phpGW group rights and phpGW user permissions.<newline>
It must use our directory structure, template support and lang (multi-language) support.<newline>
Where possible it should run on both Unix and NT platforms.
</p>
<p>
For applications that do not meet these requirements, they can be available to users via the phpGroupWare Apps project, or whatever means the developers decide.<newline>
2000-08-18 05:24:22 +02:00
If you need help converting your application to templates and our lang support, we will try to connect you with someone to help.
</P>
<sect1>Writing/porting your application
<sect2>Include files
<p>
Each PHP page you write will need to include the header.inc.php along with a few variables.<newline>
This is done by putting this at the top of each PHP page.
<code>
<?php
$phpgw_info["flags"]["currentapp"] = "appname";
2000-08-18 05:24:22 +02:00
include("../header.inc.php");
?>
</code>
Of course change application name to fit.<newline>
2000-08-31 08:05:46 +02:00
This include will provide the following things:
<itemize>
<item> The phpgwAPI - The phpGroupWare API will be loaded.
<item> The phpGW navbar will be loaded (by default, but can be disabled until a later point.
<item> appname/inc/functions.inc.php - This file is loaded just after the phpgwAPI and before any HTML code is generated. This file should include all your application specific functions.. You are welcome to include any additional files you need from within this file.
2000-08-31 08:05:46 +02:00
<item> appname/inc/header.inc.php - This file is loaded just after the system header/navbar, and allows developers to use it for whatever they need to load.
<item> appname/inc/footer.inc.php - This file is loaded just before the system footer, allowing developers to close connections and whatever else they need.
2000-08-31 08:05:46 +02:00
<item> The phpGW footer will be loaded, which closes several connections.
</itemize>
2000-08-18 05:24:22 +02:00
</p>
<sect>Installing your application
<sect1>Overview
<P>
It is fairly simple to add and delete applications to/from phpGroupWare.
</p>
<sect1>Automatic features
<P>
To make things easy for developers we go ahead and load the following files.
<itemize>
2000-08-31 08:05:46 +02:00
<item> appname/inc/functions.inc.php - This file should include all your application specific functions.
<item> appname/inc/header.inc.php - This file is loaded by <tt>$phpgw->common->header</tt> just after the system header/navbar, and allows developers to use it for whatever they need to load.
<item> appname/inc/footer.inc.php - This file is loaded by <tt>$phpgw->common->footer</tt> just before the system footer, allowing developers to close connections and whatever else they need.
2000-08-18 05:24:22 +02:00
</itemize>
</p>
<sect1>Adding files, directories and icons.
<p>
You will need to create the following directories for your code <newline>
2000-08-31 08:05:46 +02:00
(replace 'appname' with your application name)<newline>
2000-08-18 05:24:22 +02:00
<verb>
2000-08-31 08:05:46 +02:00
`-- appname
`-- images
2000-08-18 05:24:22 +02:00
| `-- navbar.gif
`-- inc
2000-08-31 08:05:46 +02:00
| |-- functions.inc.php
2000-08-18 05:24:22 +02:00
| |-- header.inc.php
| |-- footer.inc.php
| |-- preferences.inc.php
| `-- admin.inc.php
2000-08-31 08:05:46 +02:00
`-- templates
2000-08-18 05:24:22 +02:00
`-- default
</verb>
</p>
<sect1>Making phpGroupWare aware of your application
<p>
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.
2000-08-18 05:24:22 +02:00
<verb>
2000-08-31 08:05:46 +02:00
insert into applications (app_name, app_title, app_enabled) values ('appname', 'The App name', 1);
2000-08-18 05:24:22 +02:00
</verb>
</p>
<sect1>Hooking into Administration page
<P>
When a user goes to the Administration page, it stats appname/inc/admin.inc.php
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:
<code>
&lt;?php
$img = "/" . $appname . "/images/navbar.gif";
section_start("My Application",$img);
echo "&lt;a HREF=\"" . $phpgw->link("myAdminPage.php") . "\"&gt;";
echo lang("Change myApp settings") . "&lt;/a&gt;";
section_end();
?>
</code>
Look at headlines/inc/admin.inc.php and admin/inc/admin.inc.php for more examples.
Things to note:
<itemize>
<item>Links are relative to the admin/index.php file, not your application's
base directory. (so use <tt>$appname</tt> in your <tt>link()</tt> calls)</item>
<item>The file is brought in with include() so be careful to not pollute the name-space too much</item>
</itemize>
The standard $phpgw and $phpgw_info variables are in-scope, as is $appname
which corresponds to the application name in the path.
There are 2 functions to coordinate the display of each application's links,
section_start() and section_end()
<sect2>section_start
<P>
<tt>section_start($title,$icon_url)</tt>
starts the section for your application. <tt>$title</tt> is passed through <tt>lang()</tt>
for you. <tt>$icon_url</tt> should be page-relative to admin/index.php or an absolute URL.
<sect2>section_end
<P>
<tt>section_end()</tt> closes the section that was started with section_start().
<sect1>Hooking into Preferences page
<P>
The mechanism to hook into the preferences page is identical to the one used to
hook into the administration page, however it looks for
<tt>appname/inc/preferences.inc.php</tt> instead of
<tt>appname/inc/admin.inc.php</tt>. The same functions and variables are defined.
<sect>Infrastructure
2000-08-18 05:24:22 +02:00
<sect1>Overview
<P>
phpGroupWare attempts to provide developers with a sound directory structure to work from.<newline>
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.
2000-08-18 05:24:22 +02:00
</p>
<sect1>Directory tree
<p>
<verb>
.-- addressbook
2000-08-31 08:05:46 +02:00
| `-- images
| | `-- navbar.gif
| `-- inc
| | |-- functions.inc.php
| | |-- header.inc.php
| | `-- footer.inc.php
| `-- templates
| `-- default
2000-08-18 05:24:22 +02:00
|-- admin
2000-08-31 08:05:46 +02:00
| `-- images
| | `-- navbar.gif
| `-- inc
| | |-- functions.inc.php
| | |-- header.inc.php
| | |-- footer.inc.php
| | `-- admin.inc.php
2000-08-31 08:05:46 +02:00
| `-- templates
| `-- default
2000-08-18 05:24:22 +02:00
|-- calendar
2000-08-31 08:05:46 +02:00
| `-- images
| | `-- navbar.gif
| `-- inc
| | |-- functions.inc.php
| | |-- header.inc.php
| | `-- footer.inc.php
| `-- templates
| `-- default
2000-08-18 05:24:22 +02:00
|-- cron
|-- doc
|-- email
2000-08-31 08:05:46 +02:00
| `-- images
| | `-- navbar.gif
| `-- inc
| | |-- functions.inc.php
| | |-- header.inc.php
| | |-- footer.inc.php
| | |-- preferences.inc.php
| | `-- admin.inc.php
2000-08-31 08:05:46 +02:00
| `-- templates
| `-- default
2000-08-18 05:24:22 +02:00
|-- filemanager
|-- files
| |-- groups
| `-- users
|-- inc
2000-08-31 08:05:46 +02:00
| |-- phpgwapi
| | |-- phpgw.inc.php
| | |-- phpgw_info.inc.php
| | |-- phpgw_common.inc.php
2000-08-31 08:05:46 +02:00
| | `-- etc...
2000-08-18 05:24:22 +02:00
| `-- templates
| |-- default
| | |-- addressbook
| | |-- admin
| | |-- calendar
| | |-- common
| | |-- email
| | |-- filemanager
| | |-- headlines
| | |-- preferences
| | |-- todo
| | `-- tts
| `-- icons
| |-- email
| |-- calendar
| `-- tts
|-- preferences
2000-08-31 08:05:46 +02:00
| `-- images
| | `-- navbar.gif
| `-- inc
| | |-- functions.inc.php
| | |-- header.inc.php
| | |-- footer.inc.php
| | `-- preferences.inc.php
2000-08-31 08:05:46 +02:00
| `-- templates
| `-- default
2000-08-18 05:24:22 +02:00
|-- themes
2000-08-31 08:05:46 +02:00
`-- todo
`-- images
| `-- navbar.gif
`-- inc
| |-- functions.inc.php
| |-- header.inc.php
| `-- footer.inc.php
`-- templates
`-- default
2000-08-18 05:24:22 +02:00
</verb>
</p>
2000-08-31 08:05:46 +02:00
<sect1>Translations
2000-08-18 05:24:22 +02:00
<p>
The translations are now being done thru the database, and will be configurable to use other mechanisms.<newline>
We are completing a program called Transy, which will provide developers/translators a nice GUI for building and updating translations.<newline>
In the mean time you will need to create a SQL script yourself and name it lang.sql. You can copy the one in doc/lang.sql and use it as a template.
2000-08-18 05:24:22 +02:00
</p>
<sect>The API
<sect1>Introduction
<p>
phpGroupWare attempts to provide developers with a useful API to handle common tasks.<newline>
To do this we have created a multi-dimensional class $phpgw->.<newline>
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.<newline>
2000-08-18 05:24:22 +02:00
Example:
2000-08-31 08:05:46 +02:00
<tt>$phpgw->send->msg()</tt> is in the <tt>inc/phpgwapi/phpgw_send.inc.php</tt> file.
2000-08-18 05:24:22 +02:00
<sect1>Basic functions
<sect2>$phpgw->link
<p>
<tt>$phpgw->link($url)</tt><newline>
Add support for session management. ALL links must use this, that includes href's form actions and header location's.<newline>
If you are just doing a form action back to the same page, you can use it without any parameters.<newline>
2000-08-18 05:24:22 +02:00
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:
<code>
<form name=copy method=post action="<?php echo $phpgw->link();?>">
/* If session management is done via passing url parameters */
2000-08-18 05:24:22 +02:00
/* The the result would be */
/* <form name=copy method=post action="somepage.php?sessionid=87687693276?kp3=kjh98u80"> */
</code>
</p>
<sect1>Application Functions
<p>
<sect2>$phpgw->common->phpgw_header
<p>
<tt>$phpgw->phpgw_header()</tt><newline>
Print out the start of the HTML page, including the navigation bar
and includes <tt>appname/inc/header.php</tt>
</p>
<sect2>$phpgw->common->phpgw_footer
<p>
<tt>$phpgw->phpgw_footer()</tt><newline>
Prints the system footer, and includes <tt>appname/inc/footer.php</tt>
</p>
2000-08-18 05:24:22 +02:00
<sect2>$phpgw->common->appsession
<p>
<tt>$phpgw->common->appsession($data)</tt><newline>
Store important information session information that your application needs.<newline>
<tt>$phpgw->appsession</tt> will return the value of your session data is you leave the parameter empty [i.e. <tt>$phpgw->appsession("")</tt>], otherwise it will store whatever data you send to it.<newline>
You can also store a comma delimited string and use <tt>explode()</tt> to turn it back into an array when you receive the value back.<newline>
2000-08-18 05:24:22 +02:00
Example:
<code>
$phpgw->common->appsession("/path/to/something");
echo "Dir: " . $phpgw->common->appsession();
</code>
</p>
<sect1>File functions
<sect2>$phpgw->vfs->read_file
<p>
<tt>$phpgw->vfs->read_file($file)</tt><newline>
Returns the data from $file.<newline>
You must send the complete path to the file.<newline>
Example:
<code>
$data = $phpgw->vfs->read_file("/some/dir/to/file.txt");
</code>
<sect2>$phpgw->vfs->write_file
<p>
<tt>$phpgw->vfs->write_file($file, $contents)</tt><newline>
Write data to $file.<newline>
You must send the complete path to the file.<newline>
Example:
<code>
$data = $phpgw->vfs->write_file("/some/dir/to/file.txt");
</code>
<sect2>$phpgw->vfs->read_userfile
<p>
<tt>$phpgw->vfs->read_userfile($file)</tt><newline>
Returns the data from $file, which resides in the users private dir.<newline>
Example:
<code>
$data = $phpgw->vfs->read_userfile("file.txt");
</code>
<sect2>$phpgw->vfs->write_userfile
<p>
<tt>$phpgw->write_userfile($file, $contents)</tt><newline>
Writes data to $file, which resides in the users private dir.<newline>
Example:
<code>
$data = $phpgw->vfs->write_userfile("file.txt");
</code>
<sect2>$phpgw->vfs->list_userfiles
<p>
<tt>$phpgw->vfs->list_userfiles()</tt><newline>
Returns an array which has the list of files in the users private dir.<newline>
Example:
<code>
$filelist = array();
$filelist = $phpgw->vfs->list_userfiles();
</code>
</p>
<sect1>Email/NNTP Functions
<p>
<sect2>$phpgw->send->msg
<p>
<tt>$phpgw->msg->send($service, $to, $subject, $body, $msgtype, $cc, $bcc)</tt><newline>
Send a message via email or NNTP and returns any error codes.<newline>
Example:
<code>
$to = "someuser@domain.com";
$subject = "Hello buddy";
$body = "Give me a call\n Been wondering what your up to.";
$errors = $phpgw->msg->send("email", $to, $subject, $body);
</code>
</p>
<sect>Configuration Variables
<sect1>Introduction
<p>
phpGroupWare attempt to provide developers with as much information about the user, group, server, and application configuration as possible.<newline>
To do this we provide a multi-dimensional array called '$phpgw_info[]', which includes all the information about your environment.<newline>
Due to the multi-dimensional array approach. getting these values is easy. <newline>
Here are some examples:
<code>
<?php
// To do a hello username
echo "Hello " . $phpgw_info["user"]["fullname"];
//If username first name is John and last name is Doe, prints: 'Hello John Doe'
?>
<?php
// To find out the location of the imap server
echo "IMAP Server is named: " . $phpgw_info["server"]["imap_server"];
//If imap is running on localhost, prints: 'IMAP Server is named: localhost'
?>
</code>
</p>
<sect1>User information
<p>
<tt>$phpgw_info["user"]["userid"] = </tt>The user ID.<newline>
<tt>$phpgw_info["user"]["sessionid"] = </tt>The session ID<newline>
<tt>$phpgw_info["user"]["theme"] = </tt>Selected theme<newline>
<tt>$phpgw_info["user"]["private_dir"] = </tt>Users private dir. Use phpGroupWare core functions for access to the files.<newline>
2000-08-18 05:24:22 +02:00
<tt>$phpgw_info["user"]["firstname"] = </tt>Users first name<newline>
<tt>$phpgw_info["user"]["lastname"] = </tt>Users last name<newline>
<tt>$phpgw_info["user"]["fullname"] = </tt>Users Full Name<newline>
<tt>$phpgw_info["user"]["groups"] = </tt>Groups the user is a member of<newline>
<tt>$phpgw_info["user"]["app_perms"] = </tt>If the user has access to the current application<newline>
<tt>$phpgw_info["user"]["lastlogin"] = </tt>Last time the user logged in.<newline>
<tt>$phpgw_info["user"]["lastloginfrom"] = </tt>Where they logged in from the last time.<newline>
<tt>$phpgw_info["user"]["lastpasswd_change"] = </tt>Last time they changed their password.<newline>
<tt>$phpgw_info["user"]["passwd"] = </tt>Hashed password.<newline>
<tt>$phpgw_info["user"]["status"] = </tt>If the user is enabled.<newline>
<tt>$phpgw_info["user"]["logintime"] = </tt>Time they logged into their current session.<newline>
<tt>$phpgw_info["user"]["session_dla"] = </tt>Last time they did anything in their current session<newline>
<tt>$phpgw_info["user"]["session_ip"] = </tt>Current IP address<newline>
</p>
<sect1>Group information
<p>
<tt>$phpgw_info["group"]["group_names"] = </tt>List of groups.<newline>
</p>
<sect1>Server information
<p>
<tt>$phpgw_info["server"]["server_root"] = </tt>Main installation directory<newline>
<tt>$phpgw_info["server"]["include_root"] = </tt>Location of the '<tt>inc</tt>' directory.<newline>
<tt>$phpgw_info["server"]["temp_dir"] = </tt>Directory that can be used for temporarily storing files<newline>
<tt>$phpgw_info["server"]["files_dir"] = </tt>Directory er and group files are stored<newline>
2000-08-18 05:24:22 +02:00
<tt>$phpgw_info["server"]["common_include_dir"] = </tt>Location of the core/shared include files.<newline>
<tt>$phpgw_info["server"]["template_dir"] = </tt>Active template files directory. This is defaulted by the server, and changeable by the user.<newline>
<tt>$phpgw_info["server"]["dir_separator"] = </tt>Allows compatibility with WindowsNT directory format,<newline>
<tt>$phpgw_info["server"]["encrpytkey"] = </tt>Key used for encryption functions<newline>
2000-08-18 05:24:22 +02:00
<tt>$phpgw_info["server"]["site_title"] = </tt>Site Title will show in the title bar of each webpage.<newline>
<tt>$phpgw_info["server"]["webserver_url"] = </tt>URL to phpGroupWare installation.<newline>
<tt>$phpgw_info["server"]["hostname"] = </tt>Name of the server phpGroupWare is installed upon.<newline>
<tt>$phpgw_info["server"]["charset"] = </tt>default charset, default:<tt>iso-8859-1</tt><newline>
2000-08-18 05:24:22 +02:00
<tt>$phpgw_info["server"]["version"] = </tt>phpGroupWare version.<newline>
</p>
<sect1>Database information
<p>
It is unlikely you will need these, because $phpgw_info_db will already be loaded as a database for you to use.
<tt>$phpgw_info["server"]["db_host"] = </tt>Address of the database server. Usually this is set to localhost.<newline>
<tt>$phpgw_info["server"]["db_name"] = </tt>Database name.<newline>
<tt>$phpgw_info["server"]["db_user"] = </tt>User name.<newline>
<tt>$phpgw_info["server"]["db_pass"] = </tt>Password<newline>
<tt>$phpgw_info["server"]["db_type"] = </tt>Type of database. Currently MySQL and PostgreSQL are supported.<newline>
</p>
<sect1>Mail information
<p>
It is unlikely you will need these, because most email needs are services thru core phpGroupWare functions.
<tt>$phpgw_info["server"]["mail_server"] = </tt>Address of the IMAP server. Usually this is set to localhost.<newline>
<tt>$phpgw_info["server"]["mail_server_type"] = </tt>IMAP or POP3<newline>
<tt>$phpgw_info["server"]["imap_server_type"] = </tt>Cyrus or Uwash<newline>
<tt>$phpgw_info["server"]["imap_port"] = </tt>This is usually 143, and should only be changed if there is a good reason.<newline>
<tt>$phpgw_info["server"]["mail_suffix] = </tt>This is the domain name, used to add to email address<newline>
<tt>$phpgw_info["server"]["mail_login_type"] = </tt>This adds support for VMailMgr. Generally this should be set to '<tt>standard</tt>'.<newline>
2000-08-18 05:24:22 +02:00
<tt>$phpgw_info["server"]["smtp_server"] = </tt>Address of the SMTP server. Usually this is set to localhost.<newline>
<tt>$phpgw_info["server"]["smtp_port"] = </tt>This is usually 25, and should only be changed if there is a good reason.<newline>
</p>
<sect1>NNTP information
<p>
<tt>$phpgw_info["server"]["nntp_server"] = </tt>Address of the NNTP server.<newline>
<tt>$phpgw_info["server"]["nntp_port"] = </tt>This is usually XX, and should only be changed if there is a good reason.<newline>
<tt>$phpgw_info["server"]["nntp_sender"] = </tt>Unknown<newline>
<tt>$phpgw_info["server"]["nntp_organization"] = </tt>Unknown<newline>
<tt>$phpgw_info["server"]["nntp_admin"] = </tt>Unknown<newline>
2000-08-18 05:24:22 +02:00
</p>
<sect1>Application information
<p>
Each application has the following information available.
2000-08-18 05:24:22 +02:00
<tt>$phpgw_info["apps"]["appname"]["title"] = </tt>The title of the application.<newline>
<tt>$phpgw_info["apps"]["appname"]["enabled"] = </tt>If the application is enabled. True or False.<newline>
<tt>$phpgw_info["server"]["app_include_dir"] = </tt>Location of the current application include files.<newline>
<tt>$phpgw_info["server"]["app_template_dir"] = </tt>Location of the current application tpl files.<newline>
<tt>$phpgw_info["server"]["app_lang_dir"] = </tt>Location of the current lang directory.<newline>
<tt>$phpgw_info["server"]["app_auth"] = </tt>If the server and current user have access to current application<newline>
<tt>$phpgw_info["server"]["app_current"] = </tt>name of the current application.<newline>
</p>
<sect>Using Language Support
<sect1>Overview
<P>
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.
2000-08-18 05:24:22 +02:00
</p>
<sect1>How to use lang support
<p>
The <tt>lang()</tt> 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:
<code>
$x = 42;
echo lang("The counter is %1",$x)."&lt;br&gt;";
</code>
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
<tt>$x</tt> will end up is controlled by the format string, <bf>not</bf> 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:
2000-08-18 05:24:22 +02:00
<verb>
The counter is 42*&lt;br&gt;
2000-08-18 05:24:22 +02:00
</verb>
If the current user speaks Italian, they string returned may instead be:
<verb>
il contatore <20> 42&lt;br&gt;
</verb>
<sect2>The lang function
<p>
<verb>lang($key, $m1="", $m2="", $m3="", $m4="", $m5="",
$m6="", $m7="", $m8="", $m9="", $m10="")</verb>
<descrip>
<tag/$key/ is the string to translate and may contain replacement directives of the form <tt>%n</tt>.<newline>
<tag/$m1/ is the first replacement value or may be an array of replacement values
(in which case $m2 and above are ignored).
<tag/$m2 - $m10/ the 2nd through 10th replacement values if $m1 is not an array.
</descrip>
The database is searched for rows with a <tt>lang.message_id</tt> that matches <tt>$key</tt>.
If a translation is not found, the original <tt>$key</tt> is used. The translation engine then replaces
all tokens of the form <tt>%N</tt> with the Nth parameter (either <tt>$m1[N]</tt> or <tt>$mN</tt>).
</p>
<sect2>Adding translation data
<p>
An application called <bf>Transy</bf> is being developed to make this easier, until then you can create
the translation data manually.
<sect3>The lang table
<P>
The translation class uses the lang table for all translations.
We are concerned with 4 of the columns to create a translation:
<descrip>
<tag/message_id/The key to identify the message (the <tt>$key</tt> passed
to the <tt>lang()</tt> function). This is written in English.
<tag/app_name/The application the translation applies to, or
<tt>common</tt> if it is common across multiple applications.
<tag/lang/The code for the language the translation is in.
<tag/content/The translated string.
</descrip>
<sect3>lang.sql
<P>
Currently all applications, and the core phpGroupWare source tree
have a <tt>lang.sql</tt> file. This is the place to add translation
data. Just add lines of the form:
<code>
REPLACE INTO lang (message_id, app_name, lang, content)
VALUES( 'account has been deleted','common','en','Account has been deleted');
</code>
translating the <tt>content</tt> to reflect the <tt>message_id</tt> string in the <tt>lang</tt> language.
If the string is specific to your application, put your application name in for <tt>app_name</tt>
otherwise use the name <tt>common</tt>. The <tt>message_id</tt> should be in lower case for a small
increase in speed.
2000-08-18 05:24:22 +02:00
</p>
<sect1>Common return codes
<P>
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 <tt>doc/developers/CODES</tt>
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
<tt>check_code()</tt> function, which passes the strings through
<tt>lang()</tt> before returning.
For example, calling
<code>
echo check_code(13);
</code>
Would print
<verb>
Your message has been sent
</verb>
translated into the current language.
2000-08-18 05:24:22 +02:00
<sect>Using Templates
<sect1>Overview
<P>
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.
</p>
<sect1>How to use templates
<p>
Some instructions on using templates<newline>
For Further info read the PHPLIBs documentation for their template class.
</p>
<sect>About this document
<sect1>New versions
<p>
The newest version of this document can be found on our website <url url="http://www.phpgroupware.org"> as SGML source, as HTML and as TEXT.
</p>
<sect1>Comments
<p>
Comments on this HOWTO should be directed to the phpGroupWare developers mailing list
<url url="mailto:phpgroupware-developers@lists.sourceforge.net" name="phpgroupware-developers@lists.sourceforge.net">.<P>
To subscribe, go to <url url="http://sourceforge.net/mail/?group_id=7305"
</p>
<sect1>History
<p>
This document was written by Dan Kuykendall.
2000-09-25 documentation on lang(), codes, administration and preferences extension added by Steve Brown.
2000-08-18 05:24:22 +02:00
</p>
<sect1>Copyrights and Trademarks
<p>
Copyright (c) Dan Kuykendall.
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
</p>
<p>
A copy of the license is available at
<url url="http://www.gnu.org/copyleft/fdl.txt" name="GNU Free Documentation License">.
</p>
<sect1>Acknowledgments and Thanks
2000-08-18 05:24:22 +02:00
<p>
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.
</p>
</article>