<?php

/*
 
 File: prefs.php3
 $Author: chuck $
 $Revision: 1.57 $
 $Date: 1999/04/11 01:56:31 $
 
 IMP: Copyright 1999 Charles J. Hagenbuch <chuck@horde.org>
 
 You should have received a copy of the GNU Public
 License along with this package; if not, write to the
 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.
 
 */

$need_horde_db = 1;
$db_lib_loaded = 0;
if (!defined("HORDE_LIB")) include ('../lib/horde.lib');
require( './lib/imp.lib' );              /* IMPlib is the IMP function library  */
require( './config/defaults.php3' );     /* Defaults configuration file */

/* Html styles configuration */
require('./config/html.php3');
/* Mailbox configuration */
require('./config/mailbox.php3');
/* include mime and language configuration */
require('./config/mime.php3');
require('./config/lang.php3');


$language = select_lang();
require ("./locale/$language/prefs.lang");
require ('./locale/local/prefs.lang');

error_reporting($default->error_level);  /* set error level from imp.lib   */

/* send headers to ensure that the page will reload correctly. */
caching_headers();

/* retrieve authentication information from session */
$session = create_session_object();
$user    = $session->get_user();
$pass    = $session->get_password();
$server  = $session->get_server();
$port    = $session->get_port();
$folders = $session->get_folder();
$mailbox = '';

/* proceed only with a valid login */
$mbox = validate_login($server, $port, $mailbox, $user, $pass, OP_HALFOPEN);
$errormsg = '';


/* Run through the action handlers */
if (isset($actionID)) {
   switch($actionID) {
    case NO_ACTION:
      break;
      
    case UPDATE_PREFS:
      if (isset($signature) && ($signature != $old_signature)) {
	 if (!(imp_set_signature(addslashes($signature), $user, $server))) {
	    $errormsg .= $lang->signature_error;
	 }
      }
      
      if (isset($new_lang) && ($new_lang != $old_lang)) {
	 if (!(imp_set_lang($new_lang, $user, $server))) {
	    $errormsg .= $lang->language_error;
	 }
	 $session->set_lang($new_lang);
	 $language = $new_lang;
	 include("./locale/$language/prefs.lang");
      }
      
      if (isset($from) && ($from != $old_from)) {
	 if (!(imp_set_from($from,$user,$server))) {
	    $errormsg .= $lang->from_error;
	 }
      }
      
      if (isset($fullname) && ($fullname != $old_fullname)) {
	 if (!(imp_set_fullname(addslashes($fullname),$user,$server))) {
	    $errormsg .= $lang->fullname_error;
	 }
      }
      break;
   }
}

$langs = '<select name="new_lang">';
//while (list($key, $val) = each($default->lang)) {
while (list($key, $val) = each($lang->lang)) {
   if ($key == $language) $sel = ' SELECTED';
   else $sel = '';
   $langs .= "<option value=\"$key\"$sel>$val</option>\n";
}
$langs .= '</select>';

$title = $lang->prefs_title;
$sidebar = false;

require( "$default->include_dir/doctype.inc" );
require( "$default->include_dir/generic-header.inc" );
require( "$default->include_dir/prefs/begin.inc" );
require( "$default->include_dir/prefs/signature.inc" );
if ($default->user_change_fullname) include( "$default->include_dir/prefs/fullname.inc");
if ($default->user_change_from) include( "$default->include_dir/prefs/from.inc" );
require( "$default->include_dir/prefs/lang.inc" );
require( "$default->include_dir/prefs/end.inc" );
require( "$default->include_dir/generic-footer.inc" );

?>
