<?php
/*
PHPwebmail is a webmail client written in php.
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
session_start();
require("not_registered.php");
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
</head>
<body bgcolor="<?php echo $bg_color_main; ?>" text="<?php echo $fg_color; ?>" link="<?php echo $link_color; ?>" vlink="<?php echo $link_color; ?>" alink="<?php echo $alink_color; ?>">
<font face="arial" size=2>
<?php
// main entry point
if ($action == "change") {
// get user prefs account from DB
if ($db_link = mysql_connect($sql_host,$sql_user,$sql_pw)) {
@mysql_select_db("phpwebmail");
$sql_query = "SELECT textmode FROM prefs WHERE user='$name'";
$result = mysql_query($sql_query);
// catch SQL errors
if (mysql_errno()) echo ("ERROR ".mysql_error());
$row = mysql_fetch_row($result);
$textmode = $row[0];
mysql_close($db_link);
} // if db_link ends
// check if "Sent" folder is not there and create it
$mailbox = imap_open("{".$imap_server."}".$folder, $name, $passwd);
if ($mailbox) {
$mailboxes = imap_lsub($mailbox, "{".$imap_server.":143}", "*");
if (count($mailboxes) > 0) {
for ($index = 0; $index < count($mailboxes); $index++) {
$the_folder = substr(stristr($mailboxes[$index],"}"),1);
if ($the_folder == $folder_pre."/Sent") $sent_exists = 1;
}
}
imap_close($mailbox);
}
if ($store_sent == "imap" && !$sent_exists) {
$mailbox = imap_open("{".$imap_server.":143}INBOX", $name, $passwd);
$the_new_folder = imap_utf7_encode("{".$imap_server.":143}".imap_8bit($folder_pre."/Sent"));
if(@imap_createmailbox($mailbox,$the_new_folder)) {
echo "<b>Mail folder ";
if (!$textmode) echo "<img src=\"images/folder.gif\"> ";
echo "Sent created.<br>";
$result = imap_subscribe ($mailbox, $the_new_folder);
} else {
echo "<b>ERROR - mail folder ";
if (!$textmode) echo "<img src=\"images/folder.gif\"> ";
echo "Sent not created.<br>";
$store_sent = "db";
}
$dummy = imap_close($mailbox);
// use JavaScript to update the folder index
echo "<script language=\"JavaScript\">
parent.frames[0].location.href='iconbar.php?<?=SID?>'
</script>";
} // if ends
// write changes to DB
if ($db_link = mysql_connect($sql_host,$sql_user,$sql_pw)) {
@mysql_select_db("phpwebmail");
$sql_query = "UPDATE prefs SET name='".$new_name."', email='".$new_email."', sent='".$store_sent."', folder='".$folder_pre."', textmode=$gui_mode, nummsgs='".$nummsgs."' WHERE user='".$name."'";
if (eregi("@",$new_email) && $new_name) {
$result = mysql_query($sql_query);
// catch SQL errors
if (mysql_errno()) echo ("<p class=\"standard_forms\">ERROR ".mysql_error());
else {
echo "<b>Preferences changed.";
// use JavaScript to update the folder index
echo "<script language=\"JavaScript\">
parent.frames[0].location.href='iconbar.php?<?=SID?>'
parent.frames[1].location.href='mail_index.php?<?=SID?>'
</script>";
}
}
mysql_close($db_link);
}
} // if new ends
else {
// get user prefs account from DB
if ($db_link = mysql_connect($sql_host,$sql_user,$sql_pw)) {
@mysql_select_db("phpwebmail");
$sql_query = "SELECT name, email, sent, folder, textmode, nummsgs FROM prefs WHERE user='$name'";
$result = mysql_query($sql_query);
// catch SQL errors
if (mysql_errno()) echo ("ERROR ".mysql_error());
$row = mysql_fetch_row($result);
$username = strip_tags(htmlspecialchars($row[0]));
$usermail = strip_tags(htmlspecialchars($row[1]));
$usersent = $row[2];
$folder_pre = $row[3];
$textmode = $row[4];
$nummsgs = $row[5];
mysql_close($db_link);
} // if db_link ends
echo "<h3>Your Preferences:</h3>";
if ($first_time) echo "<b>Since this seems to be the first time you are logging into PHPwebmail, please set your preferences.<br>See the \"help\" menu button for details about using PHPwebmail.</b><br>";
?>
<form target="_self" method="post">
<table cellspacing=8><tr valign="center">
<td><font face="arial" size=2><b>Name: <input type="text" size=25 name="new_name" value="<?php echo $username; ?>"></td>
<td><font face="arial" size=2><b>Email: <input type="text" size=25 name="new_email" value="<?php echo $usermail; ?>"></td><tr>
<tr valign="top">
<td><br><font face="arial" size=2><b>Save sent messages:</td>
<td><br><input type="radio" name="store_sent" value="db" <?php if ($usersent != "imap") echo "checked"; ?>><font face="arial" size=2><b>In the PHPwebmail database</b><br> (sent mails can only be read with PHPwebmail)<br>
<br>
<input type="radio" name="store_sent" value="imap" <?php if ($usersent == "imap") echo "checked"; ?>><font face="arial" size=2><b>In the IMAP mail folder "Sent"</b><br> (might not work with all mail servers)</td></tr>
<tr valign="top">
<td><br><font face="arial" size=2><b>User Interface:</td>
<td><br><input type="radio" name="gui_mode" value=0 <?php if (!$textmode) echo "checked"; ?>><font face="arial" size=2><b>Graphical</b><br> (nice icons but slower)<br>
<br>
<input type="radio" name="gui_mode" value=1 <?php if ($textmode) echo "checked"; ?>><font face="arial" size=2><b>Textmode</b><br> (saves bandwidth)</td></tr>
<tr valign="center">
<td><font face="arial" size=2><b>Prefix for IMAP folders:</b><br>(leave as is if you don't know what it means)</td>
<td><font face="arial" size=2><input type="text" size=25 name="folder_pre" value="<?php echo $folder_pre; ?>"></td><tr>
<tr><td><font face="arial" size=2><b>
<tr valign="center">
<td><font face="arial" size=2><b>Number of messages to display:</b></td>
<td><font face="arial" size=2>
<select name="nummsgs" value="<?php echo $nummsgs; ?>">
<option <?php if ($nummsgs == 10) echo selected; ?>>10</option>
<option <?php if ($nummsgs == 50) echo selected; ?>>50</option>
<option <?php if ($nummsgs == 100) echo selected; ?>>100</option>
<option <?php if ($nummsgs == 150) echo selected; ?>>150</option>
<option <?php if ($nummsgs == 200) echo selected; ?>>200</option>
</select>
</td><tr>
<tr><td><font face="arial" size=2><b>
<?php if ($textmode) echo "<input type=submit value=\" change \">"; else echo "<input type=image src=images/_change.gif border=0 alt=\"change\">"; ?>
<input type="hidden" name="action" value="change"></td><td></td>
</tr></table></form>
<?php
} // else ends
?>
</BODY></HTML>