<?php
/*
 *      Patrick Bores - WebUserPrefs - SpamAssassin user_prefs file editor
 *      Copyright (C) 2003  Patrick Bores
 *      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.
 *
 *      This drop in module was coded by Oden Eriksson <oden.eriksson@imega.se>
 *      Copyright (C) 2003 Oden Eriksson - [ imega ] System AB
 *      http://www.imega.se
 *
 */
	function learning_keys(){
		return array("auto_learn","auto_learn_threshold_nonspam","auto_learn_threshold_spam",
		"auto_whitelist_factor","auto_whitelist_file_mode","auto_whitelist_path");
	}

	function learning_html(){

		$init_auto_learn = get_pref("use_auto_learn");
		if($init_auto_learn == "") $init_auto_learn = "1";

		$init_nonspam = (get_pref("learn_threshold_nonspam") != "") ? get_pref("learn_threshold_nonspam") : "-2.0";
		$init_spam = (get_pref("learn_threshold_spam") != "") ? get_pref("learn_threshold_spam") : "15.0";
		$init_whitelist_factor = (get_pref("auto_whitelist_factor") != "") ? get_pref("auto_whitelist_factor") : "0.5";
		$init_whitelist_file_mode = (get_pref("auto_whitelist_file_mode") != "") ? get_pref("auto_whitelist_file_mode") : "0666";
		$init_whitelist_path = (get_pref("auto_whitelist_path") != "") ? get_pref("auto_whitelist_path") : "/home/spamd/.spamassassin/auto-whitelist";

		$auto_learn_checked = ($init_auto_learn == "1") ? "CHECKED" : "";

		echo "<b>Learning Options</b><br />
			SpamAssassin can automatically train its Bayes database by analyzing messages that have a score that 
			strongly suggests that they are spam or nonspam.<br /><br />

			<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">

			    <tr>
			      <td rowspan=\"1\" colspan=\"2\" />
			      <input type=\"checkbox\" name=\"auto_learn_control\" value=\"1\" $auto_learn_checked /> Use Auto Learning
			      </td>
			    </tr>

			    <tr>
			      <td rowspan=\"1\" colspan=\"2\" /><hr></td>
			    </tr>

			    <tr>
			      <td align=\"right\" />Nonspam Threshold:</td>
			      <td><input type=\"text\" name=\"nonspam_control\" value=\"$init_nonspam\" size=\"4\" maxlength=\"4\" /></td>
			    </tr>

			    <tr>
			      <td align=\"right\" />Spam Threshold:</td>
			      <td><input type=\"text\" name=\"spam_control\" value=\"$init_spam\" size=\"4\" maxlength=\"4\" /></td>
			    </tr>

			    <tr>
			      <td align=\"right\" />Whitelist Factor:</td>
			      <td><input type=\"text\" name=\"whitelist_control\" value=\"$init_whitelist_factor\" size=\"4\" maxlength=\"4\" /></td>
			    </tr>

			    <tr>
			      <td align=\"right\" />Whitelist File Mode:</td>
			      <td><input type=\"text\" name=\"whitelist_file_mode_control\" value=\"$init_whitelist_file_mode\" size=\"4\" maxlength=\"4\" /></td>
			    </tr>

			    <tr>
			      <td align=\"right\" />Whitelist Path:</td>
			      <td><input type=\"text\" name=\"whitelist_path_control\" value=\"$init_whitelist_path\" size=\"44\" maxlength=\"128\" /></td>
			    </tr>

			</table>
		";

	}

	function learning_apply(){

		$auto_learn = ($_POST[auto_learn_control] != "") ? "1" : "0";

		set_pref("auto_learn",$auto_learn);

		if($_POST[nonspam_control] != ""){
			set_pref("auto_learn_threshold_nonspam",$_POST[nonspam_control]);
		}

		if($_POST[spam_control] != ""){
			set_pref("auto_learn_threshold_spam",$_POST[spam_control]);
		}

	    	if($_POST[whitelist_control] != ""){
			set_pref("auto_whitelist_factor",$_POST[whitelist_control]);
		}

	    	if($_POST[whitelist_file_mode_control] != ""){
			set_pref("auto_whitelist_file_mode",$_POST[whitelist_file_mode_control]);
		}

	    	if($_POST[whitelist_path_control] != ""){
			set_pref("auto_whitelist_path",$_POST[whitelist_path_control]);
		}


	}

?>
