<?php
  /***************************************************************************\
  *  Expresso - Expresso Messenger                                            *
  *  	- Alexandre Correia / Rodrigo Souza							          *
  *  	- JETI - http://jeti-im.org/										  *
  * ------------------------------------------------------------------------- *
  *  This program is free software; you can redistribute it and/or modify it  *
  *  under the terms of the GNU General Public License as published by the    *
  *  Free Software Foundation; either version 2 of the License, or (at your   *
  *  option) any later version.                                               *
  \***************************************************************************/

$size_of_acl = sizeof($GLOBALS['phpgw_info']['user']['acl']);

for( $i = 0; $i < $size_of_acl && $GLOBALS['phpgw_info']['user']['acl'] != "jabberit_messenger"; $i++ )
{
	$apps = unserialize($GLOBALS['phpgw_info']['server']['apps_jabberit']);
	$flag = false;

	if( is_array($apps) )
	{
		foreach($apps as $tmp)
		{
			$app_enabled = substr($tmp,0,strpos($tmp,";"));
			if( $GLOBALS['phpgw_info']['flags']['currentapp'] == $app_enabled )
				$flag = true;
		}	
	}
	
	if ( $GLOBALS['phpgw_info']['user']['acl'][$i]['appname'] == 'jabberit_messenger' && ( $flag || $GLOBALS['phpgw_info']['flags']['currentapp'] == 'jabberit_messenger' ))
	{

		$ldapManager = CreateObject('contactcenter.bo_ldap_manager');
		$_SESSION['phpgw_info']['jabberit_messenger']['ldapManager'] = $ldapManager->srcs[1];
		
		$webserver_url = $GLOBALS['phpgw_info']['server']['webserver_url'];
		$webserver_url = ( !empty($webserver_url) ) ? $webserver_url : '/';

		if(strrpos($webserver_url,'/') === false || strrpos($webserver_url,'/') != (strlen($webserver_url)-1))
			$webserver_url .= '/';

		$webserver_url = $webserver_url . 'jabberit_messenger/'; 
		
		require_once PHPGW_SERVER_ROOT . '/jabberit_messenger/inc/jabberit_sessions.inc.php';
		
		$_SESSION['phpgw_info']['jabberit_messenger']['webserver_url'] = $webserver_url;
		
		$ExternalParticipants = ""; 
		if(isset($_SESSION['phpgw_info']['jabberit_messenger']['conf_organization_jabberit']))
			$ExternalParticipants = explode(",",$_SESSION['phpgw_info']['jabberit_messenger']['conf_organization_jabberit']);
		
		if(is_array($ExternalParticipants))	
		{
			natcasesort($ExternalParticipants);
			$ExternalParticipants = implode(",", $ExternalParticipants);
		}
		
		require_once dirname(__FILE__) . '/load_lang.php';
		
		$var_js  = "var path_jabberit='".$webserver_url."';";
		$var_js	.= "var externalParticipantsJabberit='".$ExternalParticipants."';";

		echo "<script type=\"text/javascript\">".$var_js."</script>";

		$js = array(
				'connector',
				'xtools',
				'dragdrop',
				'windows',	
				'ldap',
				'images',
				'show_hidden',
				'load',
				'editSelect'
				);

		require_once dirname(__FILE__) . '/Controller.class.php';

		$controller = new Controller;
		$script = '';
		foreach( $js as $key => $val ) 
		{
			$val = array('act' => 'j.' . $val );
			$script .= $controller->exec($val);
		}	
		
		printf("<script type=\"text/javascript\">%s</script>", $script);
		
		print '<link rel="stylesheet" type="text/css" href="' . $webserver_url . 'templates/default/css/window.css">';
		print '<link rel="stylesheet" type="text/css" href="' . $webserver_url . 'templates/default/css/common.css">';
		print '<link rel="stylesheet" type="text/css" href="' . $webserver_url . 'templates/default/css/selectEditStyle.css">';		

		break;
	}
	
}
?>