<?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 bayes_keys(){
		return array("use_bayes","bayes_path","bayes_file_mode","bayes_use_hapaxes","bayes_use_chi2_combining",
		"bayes_expiry_min_db_size","bayes_expiry_scan_count","bayes_ignore_header");
	}

	function bayes_html(){

		$init_bayes = get_pref("use_bayes");
		if($init_bayes == "") $init_bayes = "1";

		$init_hapaxes = get_pref("use_hapaxes");
		if($init_hapaxes == "") $init_hapaxes = "1";

		$init_chi2_combining = get_pref("use_chi2_combining");
		if($init_chi2_combining == "") $init_chi2_combining = "0";

		$init_bayes_path = (get_pref("bayes_path") != "") ? get_pref("bayes_path") : "/home/spamd/.spamassassin/bayes";
		$init_bayes_file_mode = (get_pref("bayes_file_mode") != "") ? get_pref("bayes_file_mode") : "0666";
		$init_bayes_expiry_min_db_size = (get_pref("bayes_expiry_min_db_size") != "") ? get_pref("bayes_expiry_min_db_size") : "100000";
		$init_bayes_expiry_scan_count = (get_pref("bayes_expiry_scan_count") != "") ? get_pref("bayes_expiry_scan_count") : "5000";
		$init_bayes_ignore_header = (get_pref("bayes_ignore_header") != "") ? get_pref("bayes_ignore_header") : "X-Remote-IP:127.0.0.1";

		$bayes_checked = ($init_bayes == "1") ? "CHECKED" : "";
		$hapaxes_checked = ($init_hapaxes == "1") ? "CHECKED" : "";
		$chi2_combining_checked	= ($init_chi2_combining == "1") ? "CHECKED" : "";


		echo "<b>Bayes Options</b><br />

			Spamassassin can use a statistical, \"Bayesian\" analysis system to determine whether each message is spam 
			based on previous examples of spam and nonspam.<br /><br />

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

			    <tr>
			      <td rowspan=\"1\" colspan=\"2\" />
			      <input type=\"checkbox\" name=\"bayes_control\" value=\"1\" $bayes_checked /> Use Bayes System | 
			      <input type=\"checkbox\" name=\"hapaxes_control\" value=\"1\" $hapaxes_checked /> Use Hapaxes | 
			      <input type=\"checkbox\" name=\"chi2_combining_control\" value=\"1\" $chi2_combining_checked /> Use chi2 Combining
			      </td>
			    </tr>

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

			    <tr>
			      <td align=\"right\" />Bayes Expiry Min Db Size:</td>
			      <td><input type=\"text\" name=\"bayes_expiry_min_db_size_control\" value=\"$init_bayes_expiry_min_db_size\" size=\"10\" maxlength=\"24\" /></td>
			    </tr>

			    <tr>
			      <td align=\"right\" />Bayes Expiry Scan Count:</td>
			      <td><input type=\"text\" name=\"bayes_expiry_scan_count_control\" value=\"$init_bayes_expiry_scan_count\" size=\"10\" maxlength=\"24\" /></td>
			    </tr>

			    <tr>
			      <td align=\"right\" />Bayes Ignore Header:</td>
			      <td><input type=\"text\" name=\"bayes_ignore_header_control\" value=\"$init_bayes_ignore_header\" size=\"44\" maxlength=\"128\" /></td>
			    </tr>

			    <tr>
			      <td align=\"right\" />Bayes File Mode:</td>
			      <td><input type=\"text\" name=\"bayes_file_mode_control\" value=\"$init_bayes_file_mode\" size=\"4\" maxlength=\"4\" /></td>
			    </tr>

			    <tr>
			      <td align=\"right\" />Bayes Path:</td>
			      <td><input type=\"text\" name=\"bayes_path_control\" value=\"$init_bayes_path\" size=\"44\" maxlength=\"128\" /></td>
			    </tr>

			</table>
		";

	}

	function bayes_apply(){

		$bayes = ($_POST[bayes_control] != "") ? "1" : "0";
		$hapaxes = ($_POST[hapaxes_control] != "") ? "1" : "0";
		$chi2_combining = ($_POST[chi2_combining_control] != "") ? "1" : "0";

		set_pref("use_bayes",$bayes);
		set_pref("bayes_use_hapaxes",$hapaxes);
		set_pref("bayes_use_chi2_combining",$chi2_combining);

		if($_POST[bayes_path_control] != ""){
			set_pref("bayes_path",$_POST[bayes_path_control]);
		}

		if($_POST[bayes_file_mode_control] != ""){
			set_pref("bayes_file_mode",$_POST[bayes_file_mode_control]);
		}

		if($_POST[bayes_expiry_min_db_size_control] != ""){
			set_pref("bayes_expiry_min_db_size",$_POST[bayes_expiry_min_db_size_control]);
		}

		if($_POST[bayes_expiry_scan_count_control] != ""){
			set_pref("bayes_expiry_scan_count",$_POST[bayes_expiry_scan_count_control]);
		}

		if($_POST[bayes_ignore_header_control] != ""){
			set_pref("bayes_ignore_header",$_POST[bayes_ignore_header_control]);
		}


	}

?>
