$sql = mysql_query("SELECT rank,rid,flags,name FROM rules WHERE uid='$_uid' ORDER BY rank");
while(list($_rank,$_rid,$_flags,$_name) = mysql_fetch_row($sql)) {
- $this->rules[$_rid] = new Rule($_rank,$_flags,$_name,true);
+ $this->rules[$_rid] = new Rule($_rank,$_flags,$_name);
$this->rules[$_rid]->sql_get_matches($_uid,$_rid);
$this->rules[$_rid]->sql_get_actions($_uid,$_rid);
}
}
+
+ function get_global_data($_plug_id) {
+ if(isset($this->rules[0]))
+ foreach($this->rules[0]->matches as $match)
+ if($match[0] == $_plug_id)
+ return $match;
+ return(Array($_plug_id,0));
+ }
+
+ function set_global_data($_plug_id, $data) {
+ if(!isset($this->rules[0]))
+ $this->rules[0] = new Rule(0,'','GLOBAL');
+ foreach($this->rules[0]->matches as $id=>$match)
+ if($match[0] == $_plug_id) {
+ $this->rules[0]->matches[$id] = $data;
+ return;
+ }
+ $this->rules[0]->matches[] = $data;
+ }
function to_string() {
return "";
$res = "filter[0] = { all: 1, block:1, name:'"._i18n('new_rule')."', matches: [], actions: [] };\n";
foreach($this->rules as $id=>$rule)
- $res .= "filter[$id] = ".$rule->to_js().";\n";
+ if($id)
+ $res .= "filter[$id] = ".$rule->to_js().";\n";
return $res;
}
'path' => array('procmail', 'spool'),
'match_plugins' => array(),
'action_plugins' => array(),
- 'global_plugin' => array(),
+ 'global_plugins' => array(),
'i18n' => array()
);
$this->err = "";
return false;
}
- if(isset($this->config['global_plugin'][$rtti])) {
+ if(isset($this->config['global_plugins'][$rtti])) {
$this->err = "Philter::register_global_plugin : a plugin is already registerd";
return false;
}
- $this->config['global_plugin'][$rtti] = $_plugin;
+ $this->config['global_plugins'][$rtti] = $_plugin;
return true;
}
$this->global=$_glob;
}
+ function sql_store($_uid, $_rid, $_data) {
+ if($this->global)
+ mysql_query("INSERT INTO actions SET uid='$_uid',rid='0',pid='{$_data[0]}',data='{$_data[1]}'");
+ else
+ mysql_query("INSERT INTO actions SET uid='$_uid',rid='$_rid',pid='{$_data[0]}',data='{$_data[1]}'");
+ }
+
/** true if the plugin is used as global rule
* overload with (return false) if the plugin can not be used as a global rule
* overload with (return true) if the plugin can not be used as a normal rule
* @return true if usable as a global rule, false else
*/
- function is_global() { return $global; }
+ function is_global() { return $this->global; }
}
/********************************************************************************
class BogoPlugin extends MatchPlugin {
function BogoPlugin($_glob=false) { $this->MatchPlugin($_glob); }
function rtti() { return 1; }
- function name() { return "AntiSpam"; }
+ function name() { return _i18n('1_bogo'); }
/* the plugin is only global */
function is_global() { return true; }
- function sql_store($_uid, $_rid, $_data) {
- return "INSERT INTO matches SET uid='$_uid',rid='$_rid',pid='".$this->rtti()."',data='{$_data['data']}';\n";
- }
-
function to_string($_data) {
if($_data['data']=='off')
return "";
return $res;
}
- function to_form() {
+ function to_form($_data) {
$res = "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"1\">\n"
. "<tr><th width=\"25%\">BogoFilter</th>\n";
- $res .= "<td>TODO</td>\n";
+ $res .= "<td><input type='hidden' name='global[1][0]' value='1' />\n"
+ . " <input type='radio' name='global[1][1]' value='0' "
+ . ($_data[1]==0 ? 'checked="checked "' : '')."/>"._i18n('1_bogo_off')."<br />\n"
+ . " <input type='radio' name='global[1][1]' value='1' "
+ . ($_data[1]==1 ? 'checked="checked "' : '')."/>"._i18n('1_bogo_on')."<br />\n"
+ . " <input type='radio' name='global[1][1]' value='2' "
+ . ($_data[1]==2 ? 'checked="checked "' : '')."/>"._i18n('1_bogo_drop')."<br />\n"
+ . "</td>\n";
$res .= "</tr>\n"
. "</table>\n";
mysql_query("INSERT INTO rules SET uid='$_uid',rid='$_rid',rank='{$this->rank}',flags='$flags',name='{$this->name}'");
- foreach($this->matches as $match)
- $philter->config['match_plugins'][$match[0]]->sql_store($_uid, $_rid, $action);
-
- foreach($this->actions as $action)
- $philter->config['action_plugins'][$action[0]]->sql_store($_uid, $_rid, $action);
+ if($_rid) {
+ foreach($this->matches as $match)
+ $philter->config['match_plugins'][$match[0]]->sql_store($_uid, $_rid, $match);
+
+ foreach($this->actions as $action)
+ $philter->config['action_plugins'][$action[0]]->sql_store($_uid, $_rid, $action);
+ } else
+ foreach($this->matches as $match)
+ $philter->config['global_plugins'][$match[0]]->sql_store($_uid, $_rid, $match);
}
function to_js() {
$filter = new Filter(get_user_id());
if(count($_POST)) { // a FORM has been submitted
+ if(isset($_POST['global'])) { // FORM global
+ foreach($philter->config['global_plugins'] as $id=>$g_plugin)
+ if(isset($_POST['global'][$id]))
+ $filter->set_global_data($id,$_POST['global'][$id]);
+ $filter->rules[0]->sql_store(get_user_id(),0);
+ }
if(isset($_POST['emails'])) // FORM emails
if(!$mail_pool->handle_form())
echo "<p style=\"color:red;\">".$philter->error()."</p>\n";
<div class="rubrique"><?php i18n('global_title'); ?></div>
<?php
i18n('global_help');
-if(count($philter->config['global_plugin'])) {
+if(count($philter->config['global_plugins'])) {
echo "<form action=\"{$_SERVER['REQUEST_URI']}\" method=\"post\">\n"
."<table width=\"95%\" class=\"bicol\" cellspacing=\"1\" cellpadding=\"1\" align=\"center\">\n";
- foreach($philter->config['global_plugin'] as $g_plugin) {
+ foreach($philter->config['global_plugins'] as $id=>$g_plugin) {
echo "<tr><td>\n";
- echo $g_plugin->to_form(/* data */);
+ echo $g_plugin->to_form($filter->get_global_data($id));
echo "</td></tr>\n";
}
-
- echo "</table>\n"
+ echo "<tr><td align='center'><input type='submit' name='global[submit]' value='"._i18n('apply_changes')."'/></td></tr>\n"
+ ."</table>\n"
."</form>\n";
}
<tr><td>
<?php
foreach($filter->rules as $id=>$rule)
- echo "<input type=\"hidden\" id=\"order$id\" name=\"order[$id]\" value=\"{$rule->rank}\" />\n";
+ if($id)
+ echo "<input type=\"hidden\" id=\"order$id\" name=\"order[$id]\" value=\"{$rule->rank}\" />\n";
$presel = (isset($_POST['rule']['id']) ? $_POST['rule']['id']
: (isset($_POST['order']['select']) ? $_POST['order']['select'] : 0));
echo "</option>\n";
foreach($filter->rules as $id=>$rule)
- echo "<option value=\"$id\""
- .($presel==$id ? " selected=\"selected\"":"")
- .">{$rule->name}</option>\n";
+ if($id)
+ echo "<option value=\"$id\""
+ .($presel==$id ? " selected=\"selected\"":"")
+ .">{$rule->name}</option>\n";
?>
</select>
</td></tr><tr><td>
--- /dev/null
+<?php
+/********************************************************************************
+* i18n file
+*
+* This file is part of the philter distribution
+* Copyright: See COPYING files that comes with this distribution
+********************************************************************************/
+
+$philter->config['i18n']['1_bogo'] = 'AntiSpam';
+$philter->config['i18n']['1_bogo_off'] = 'AntiSpam is off';
+$philter->config['i18n']['1_bogo_on'] = 'AntiSpam is on, and only marks emails';
+$philter->config['i18n']['1_bogo_drop'] = 'AntiSpam is on, and drops the emails considered as spams';
+
+/********************************************************************************
+* $Id$
+* vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100:
+********************************************************************************/
+?>
--- /dev/null
+<?php
+/********************************************************************************
+* i18n file
+*
+* This file is part of the philter distribution
+* Copyright: See COPYING files that comes with this distribution
+********************************************************************************/
+
+$philter->config['i18n']['1_bogo'] = 'AntiSpam';
+$philter->config['i18n']['1_bogo_off'] = 'le filtre anti-spam est coupé';
+$philter->config['i18n']['1_bogo_on'] = 'le filtre anti-spam est activé, et marque les mails';
+$philter->config['i18n']['1_bogo_drop'] = 'le filtre anti-spam est activé, et jette les mails détectés comme spams';
+
+/********************************************************************************
+* $Id$
+* vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100:
+********************************************************************************/
+?>