This manual is deprecated. Please visit https://groupoffice.readthedocs.io for the latest documentation.

Event handling

From Group-Office Groupware and CRM Documentation
Revision as of 20:52, 7 October 2008 by Mschering (Talk | contribs) (New page: Group-Office modules can interact with eachother with event handling. For example you might want to do something in a custom module when a particular thing happens in another module. Som...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Group-Office modules can interact with eachother with event handling. For example you might want to do something in a custom module when a particular thing happens in another module.

Some practical examples:

  1. The IMAP authentication module checks access when a user logs in.
  2. When an order status changes in the webshop of group-office.com, an event handler enables the download for the customer
  3. When a password is change in Group-Office. A system account can be updated.
  4. etc.

How does it work? I'll explain the IMAP authentication example.

When a user logs in, an event is fired in classes/base/auth.class.inc.php:

$params = array('username'=>$username, 'password'=>$password);
$GO_MODULES->fire_event('before_login', $params);

The fire_event function searches for a function in each module class. It does it in this way.

  1. It searches for the file "module/<module_id>/classes/<module_id>.class.inc.php" and includes it.
  2. It checks if class <module_id> is available.
  3. It checks if the <module_id>::__on_<event_name>() is defined.

In the imapauth module I have created this function:

class imapauth extends db
{
	
	var $config;
	
	public function __construct(){
		
		global $GO_MODULES;
		
		$this->db();
		
		if(file_exists($GO_MODULES->modules['imapauth']['path'].'config.inc.php'))
		{
			require($GO_MODULES->modules['imapauth']['path'].'config.inc.php');
			$this->config=$config;
		}
	}

	public function __on_before_login($arguments)
	{
	
	...

	}
}

So now just before a user is logged in this function is called. The function connects to the IMAP server using the supplied password. If it succeeds it will add a user account and e-mail account or update the password if necessary.

The same could be done with any application/protocol like Joomla, PhpBB, LDAP etc. You'll just have to write it!


Defined events