1<?php
2	/**************************************************************************\
3	* phpGroupWare                                                             *
4	* http://www.phpgroupware.org                                              *
5	* --------------------------------------------                             *
6	*  This program is free software; you can redistribute it and/or modify it *
7	*  under the terms of the GNU General Public License as published by the   *
8	*  Free Software Foundation; either version 2 of the License, or (at your  *
9	*  option) any later version.                                              *
10	\**************************************************************************/
11
12	/* $Id: navbar.inc.php 16322 2005-12-07 23:08:55Z skwashd $ */
13
14	function parse_navbar($force = False)
15	{
16		$GLOBALS['idots_tpl'] = createobject('phpgwapi.Template',PHPGW_TEMPLATE_DIR);
17
18		$GLOBALS['idots_tpl']->set_file(
19			array(
20				'navbar' => 'navbar.tpl'
21			)
22		);
23
24		$GLOBALS['idots_tpl']->set_block('navbar','navbar_header','navbar_header');
25		$GLOBALS['idots_tpl']->set_block('navbar','extra_blocks_header','extra_block_header');
26		$GLOBALS['idots_tpl']->set_block('navbar','extra_block_row','extra_block_row');
27		$GLOBALS['idots_tpl']->set_block('navbar','extra_block_spacer','extra_block_spacer');
28		$GLOBALS['idots_tpl']->set_block('navbar','extra_blocks_footer','extra_blocks_footer');
29		$GLOBALS['idots_tpl']->set_block('navbar','navbar_footer','navbar_footer');
30
31		$var['img_root'] = $GLOBALS['phpgw_info']['server']['webserver_url'] . '/phpgwapi/templates/idots/images';
32		$var['table_bg_color'] = $GLOBALS['phpgw_info']['theme']['navbar_bg'];
33
34		$applications = '';
35		$items++;
36		foreach($GLOBALS['phpgw_info']['navbar'] as $app => $app_data)
37		{
38			if ($app != 'home' && $app != 'preferences' && $app != 'about' && $app != 'logout')
39			{
40				$title = $GLOBALS['phpgw_info']['apps'][$app]['title'];
41
42				$icon = '<img src="' . $app_data['icon'] . '" alt="' . $title .
43					'" title="'. 	$title . '" />';
44
45				$app_icons .= '<td class="navpanel"><a href="' . $app_data['url'] . '"';
46				if (isset($GLOBALS['phpgw_info']['flags']['navbar_target']) &&
47				$GLOBALS['phpgw_info']['flags']['navbar_target'])
48				{
49					$app_icons .= ' target="' . $GLOBALS['phpgw_info']['flags']['navbar_target'] . '"';
50				}
51				$app_icons .= '>' . $icon . "</a></td>\r\n";
52
53				$app_titles .= '<td align=center class="mainnote"><a href="'.$app_data['url'] . '"';
54				if (isset($GLOBALS['phpgw_info']['flags']['navbar_target']) &&
55				$GLOBALS['phpgw_info']['flags']['navbar_target'])
56				{
57					$app_titles .= ' target="' . $GLOBALS['phpgw_info']['flags']['navbar_target'] . '"';
58				}
59				$app_titles .= '>' . $title . "</a></td>\r\n";
60
61				unset($icon);
62				unset($title);
63				$items++;
64			}
65		}
66
67		$var['app_icons']  = $app_icons;
68		$var['td_span'] = intval($items);
69		$var['app_titles'] = $app_titles;
70		switch ($GLOBALS['phpgw_info']['user']['preferences']['common']['navbar_format'])
71		{
72			case 'text':
73				$var['app_icons'] = '<td colspan="' . ($items -1) . '">&nbsp;</td>';
74				break;
75
76			case 'icons':
77				$var['app_titles'] = '<td colspan="' . ($items -1) . '">&nbsp;</td>';
78				break;
79
80			default: //icons_and_text
81				//do nothing
82		}
83
84		if (isset($GLOBALS['phpgw_info']['flags']['app_header']))
85		{
86			$var['current_app_title'] = $GLOBALS['phpgw_info']['flags']['app_header'];
87		}
88		else
89		{
90			$var['current_app_title']=$GLOBALS['phpgw_info']['navbar'][$GLOBALS['phpgw_info']['flags']['currentapp']]['title'];
91		}
92
93		if (isset($GLOBALS['phpgw_info']['navbar']['admin']) && $GLOBALS['phpgw_info']['user']['preferences']['common']['show_currentusers'])
94		{
95			$var['current_users'] = '<a href="'
96			. $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicurrentsessions.list_sessions') . '">'
97			. lang('Current users') . ': ' . $GLOBALS['phpgw']->session->total() . '</a>';
98		}
99		$now = time();
100		$var['user_info'] = '<b>'.$GLOBALS['phpgw']->common->display_fullname() .'</b>'. ' - '
101		. lang($GLOBALS['phpgw']->common->show_date($now,'l')) . ' '
102		. $GLOBALS['phpgw']->common->show_date($now,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
103
104		if ( $GLOBALS['phpgw']->acl->check('changepassword', 1, 'preferences') )
105		{
106			if ( intval($GLOBALS['phpgw_info']['user']['lastpasswd_change']) == 0)
107			{
108				$api_messages = lang('You are required to change your password during your first login')
109					. '<br /> Click <a href="' . $GLOBALS['phpgw']->link('/preferences/changepassword.php') . '">here</a>';
110			}
111			else if ($GLOBALS['phpgw_info']['user']['lastpasswd_change'] < time() - (86400*30))
112			{
113				$api_messages = lang('it has been more than %1 days since you changed your password',30)
114					. '<br /> Click <a href="' . $GLOBALS['phpgw']->link('/preferences/changepassword.php') . '">' . lang('here') . '</a>';
115			}
116
117			if($api_messages)
118			{
119				$url = parse_url($GLOBALS['phpgw']->link('/preferences/changepassword.php'));
120				if($_SERVER['PHP_SELF'] != $url['path'])
121				{
122					$var['messages'] = $api_messages;
123				}
124			}
125		}
126
127		// This is gonna change
128		if (isset($cd))
129		{
130			$var['messages'] = $api_messages . '<br />' . checkcode($cd);
131		}
132
133		$GLOBALS['idots_tpl']->set_var($var);
134		$GLOBALS['idots_tpl']->pfp('out','navbar_header');
135
136		$menu_title = lang('General Menu');
137
138		$file[] = array('text' => 'Home',
139				'url' => $GLOBALS['phpgw_info']['navbar']['home']['url']);
140		if ($GLOBALS['phpgw_info']['user']['apps']['preferences'])
141		{
142			$file[] = array ('text' => 'Preferences',
143					'url' => $GLOBALS['phpgw_info']['navbar']['preferences']['url']
144							. '#' . $GLOBALS['phpgw_info']['flags']['currentapp']);
145		}
146		$file[] = array ('text' => 'About %1', 'url' => $GLOBALS['phpgw_info']['navbar']['about']['url']);
147		$file[] = array ('text' => 'Logout', 'url' => $GLOBALS['phpgw_info']['navbar']['logout']['url']);
148
149		display_sidebox('',$menu_title,$file);
150
151		$GLOBALS['phpgw']->hooks->single('sidebox_menu',$GLOBALS['phpgw_info']['flags']['currentapp']);
152
153		$GLOBALS['idots_tpl']->pparse('out','navbar_footer');
154
155		// If the application has a header include, we now include it
156		if (!@$GLOBALS['phpgw_info']['flags']['noappheader'] && @isset($GLOBALS['HTTP_GET_VARS']['menuaction']))
157		{
158			list($app,$class,$method) = explode('.',$GLOBALS['HTTP_GET_VARS']['menuaction']);
159			if (is_array($GLOBALS[$class]->public_functions) && $GLOBALS[$class]->public_functions['header'])
160			{
161				$GLOBALS[$class]->header();
162			}
163		}
164		$GLOBALS['phpgw']->hooks->process('after_navbar');
165		return;
166	}
167
168	function display_sidebox($appname, $menu_title, $file, $use_lang = True)
169	{
170
171		if(!$appname || ($appname == $GLOBALS['phpgw_info']['flags']['currentapp'] && $file))
172		{
173			$var['lang_title'] = $menu_title;
174			$GLOBALS['idots_tpl']->set_var($var);
175			$GLOBALS['idots_tpl']->pfp('out','extra_blocks_header');
176
177			foreach($file as $null => $item)
178			{
179				sidebox_menu_item($item['url'], $item['text'], $item['image'], $use_lang);
180			}
181
182			$GLOBALS['idots_tpl']->pparse('out','extra_blocks_footer');
183		}
184	}
185
186	function sidebox_menu_item($item_link='', $item_text='', $item_image='', $use_lang = True)
187	{
188		if($item_text == '_NewLine_')
189		{
190			$GLOBALS['idots_tpl']->pparse('out','extra_block_spacer');
191		}
192		else
193		{
194			$var['icon_or_star']= ($item_image ? $item_image : '*');
195			$var['lang_item'] = ($use_lang ? lang($item_text) : $item_text);
196			$var['item_link']=$item_link;
197
198			$GLOBALS['idots_tpl']->set_var($var);
199			$GLOBALS['idots_tpl']->pparse('out','extra_block_row');
200		}
201	}
202
203	function parse_navbar_end()
204	{
205		$GLOBALS['idots_tpl'] = createobject('phpgwapi.Template',PHPGW_TEMPLATE_DIR);
206
207		$GLOBALS['idots_tpl']->set_file(
208			array(
209				'footer' => 'footer.tpl'
210			)
211		);
212		$var = Array(
213			'img_root'			=> $GLOBALS['phpgw_info']['server']['webserver_url'] . '/phpgwapi/templates/idots/images',
214			'table_bg_color'	=> $GLOBALS['phpgw_info']['theme']['navbar_bg'],
215			'version'			=> $GLOBALS['phpgw_info']['server']['versions']['phpgwapi']
216		);
217		$GLOBALS['phpgw']->hooks->process('navbar_end');
218
219		$var['powered_by'] = lang('Powered by phpGroupWare version %1',$GLOBALS['phpgw_info']['server']['versions']['phpgwapi']);
220		$GLOBALS['idots_tpl']->set_var($var);
221		$GLOBALS['idots_tpl']->pfp('out','footer');
222	}
223