<?php
	/**************************************************************************\
	* phpGroupWare - headlines                                                 *
	* http://www.phpgroupware.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.                                              *
	\**************************************************************************/

	/* $Id: preferences.php,v 1.1.1.2.8.1 2004/09/27 03:51:46 kazuyan Exp $ */

	$phpgw_info['flags'] = array(
		'currentapp'              => 'headlines',
		'noheader'                => True,
		'nonavbar'                => True,
		'enable_nextmatchs_class' => True
	);
	include('../header.inc.php');

	if (! @$_POST['submit'])
	{
		$GLOBALS['phpgw']->common->phpgw_header();
		echo parse_navbar();
     
		$GLOBALS['phpgw']->template->set_file(array('form' => 'preferences.tpl'));
	     
		$GLOBALS['phpgw']->template->set_var('form_action',$GLOBALS['phpgw']->link('/headlines/preferences.php'));
		$GLOBALS['phpgw']->template->set_var('th_bg',$GLOBALS['phpgw_info']['theme']['th_bg']);
		$GLOBALS['phpgw']->template->set_var('lang_header',lang('select headline news sites'));
		$GLOBALS['phpgw']->template->set_var('lang_headlines',lang('Headline preferences'));

		$GLOBALS['phpgw']->db->query('SELECT con,display FROM phpgw_headlines_sites ORDER BY display asc',__LINE__,__FILE__);
		while ($GLOBALS['phpgw']->db->next_record())
		{
			$html_select .= '<option value=\'' . $GLOBALS['phpgw']->db->f('con') . '\'';
//           . $users_headlines[$GLOBALS['phpgw']->db->f('con')];

			if ($GLOBALS['phpgw_info']['user']['preferences']['headlines'][$GLOBALS['phpgw']->db->f('con')])
			{
				$html_select .= ' selected';
			}
			$html_select .= '>' . str_replace('&amp;','&',$GLOBALS['phpgw']->strip_html($GLOBALS['phpgw']->db->f('display', True))) . '</option>'."\n";
		}
		$GLOBALS['phpgw']->template->set_var('select_options',$html_select);

		$GLOBALS['phpgw']->template->set_var('tr_color_1',$GLOBALS['phpgw']->nextmatchs->alternate_row_color());
		$GLOBALS['phpgw']->template->set_var('tr_color_2',$GLOBALS['phpgw']->nextmatchs->alternate_row_color());

		$GLOBALS['phpgw']->template->set_var('lang_submit',lang('submit'));

		$GLOBALS['phpgw']->template->pparse('out','form');
	}
	else
	{
		//save the user's layout setting
		$layout = $GLOBALS['phpgw_info']['user']['preferences']['headlines']['headlines_layout'];
		
		//kill the old prefs
		$GLOBALS['phpgw']->preferences->delete('headlines', '');
	
		if (@count($_POST['headlines']))
		{
			while ($value = each($_POST['headlines']))
			{
				$GLOBALS['phpgw']->preferences->add('headlines',$value[1],'True', 'user');
			}
		}

		$GLOBALS['phpgw']->preferences->add('headlines', 'headlines_layout', $layout, 'user');

		$GLOBALS['phpgw']->preferences->save_repository(True, 'user');

		Header('Location: ' . $GLOBALS['phpgw']->link('/preferences/index.php') . '#headlines');
	}
	$GLOBALS['phpgw']->common->phpgw_footer();
?>
