Initial revision
[old-projects.git] / philter / philter / index.php
diff --git a/philter/philter/index.php b/philter/philter/index.php
new file mode 100644 (file)
index 0000000..fa5b890
--- /dev/null
@@ -0,0 +1,148 @@
+<?php
+/********************************************************************************
+* index.php : index page
+* ---------
+*
+* This file is part of the philter distribution
+* Copyright: See COPYING files that comes with this distribution
+********************************************************************************/
+
+require("include/header.inc.php");
+require("include/philter.inc.php");
+require("include/config.inc.php");
+
+$mail_pool = new EmailPool(get_user_id());
+$filter = new Filter(get_user_id());
+
+if(count($_POST)) {                             // a FORM has been submitted
+    if(isset($_POST['emails']))                 //      FORM emails
+        if(!$mail_pool->handle_form())
+            echo "<p style=\"color:red;\">".$philter->error()."</p>\n";
+
+    if(!empty($_POST['order']['action']))       //      FORM order
+        if($_POST['order']['action']=='submit') {
+            foreach($filter->rules as $id=>$rule)
+                if(isset($_POST['order'][$id]))
+                    $filter->rules[$id]->move_to($_POST['order'][$id], $filter->uid, $id);
+            uasort($filter->rules, 'rule_cmp');
+        } elseif($_POST['order']['action']=='delete' && !empty($_POST['order']['select'])) {
+            $filter->delete_rule($_POST['order']['select']);
+            $_POST['order']['select'] = min(count($filter->rules),$_POST['order']['select']);
+        }
+
+    if(!empty($_POST['rule']))                  //      FORM rule
+        if(!$filter->handle_form())
+            echo "<p style=\"color:red;\">".$philter->error()."</p>\n";
+}
+
+require("include/js_factory.inc.php");
+
+/********** globals plugins **********/
+
+if(count($philter->config['global_plugin'])) {
+    echo "<tr><td>\n"
+        ."<form action=\"{$_SERVER['REQUEST_URI']}\" method=\"post\">\n"
+        ."<table width=\"100%\">\n"
+        ."<tr><th>Global rules</th></tr>";
+
+    foreach($philter->config['global_plugin'] as $g_plugin) {
+        echo "<tr><td>\n";
+        echo $g_plugin->to_form(/* data */);
+        echo "</td></tr>\n";
+        
+    }
+
+    echo "</table>\n"
+        ."</form>\n";
+}
+
+/********** emails **********/
+?>
+
+<table width="100%">
+<tr><th>Emails pool</th></tr>
+<tr><td>
+<?php
+echo $mail_pool->to_form();
+
+echo "</td></tr>\n</table>\n";
+
+/********** filters **********/
+?>
+
+<table width="100%">
+<tr><th colspan="2">Filtering rules</th></tr>
+<tr><td width="25%" valign="top">
+        <form action="<?php echo $_SERVER['REQUEST_URI']?>" method="post" name="order" onsubmit="return false;">
+        <table width="100%">
+        <tr><td>
+<?php
+            foreach($filter->rules as $id=>$rule)
+                echo "<input type=\"hidden\" name=\"order[$id]\" value=\"{$rule->rank}\" />\n";
+           
+            $presel = (isset($_POST['rule']['id']) ? $_POST['rule']['id']
+                        : (isset($_POST['order']['select']) ? $_POST['order']['select'] : 0));
+                
+            echo "<select size=\"16\" name=\"order[select]\" onchange=\"createRuleForm()\">\n";
+            echo "<option value=\"0\" ".($presel ? "" : " selected=\"selected\"")
+                .">[ new rule ]</option>\n";
+            
+            foreach($filter->rules as $id=>$rule)
+                echo "<option value=\"$id\""
+                    .($presel==$id ? " selected=\"selected\"":"")
+                    .">{$rule->name}</option>\n";
+?>
+            </select>
+        </td></tr><tr><td>
+            <input type="submit" value="Up" name="order[up]" onclick="order_up();" />
+            <input type="submit" value="Down" name="order[dn]" onclick="order_dn();" />
+            <input type="submit" value="Delete" name="order[delete]" onclick="order_submit(this)" />
+            <input type="submit" value="Submit" name="order[submit]" onclick="order_submit(this)" />
+            <input type="hidden" value="" name="order[action]" />
+        </td></tr>
+        </table>
+        </form>
+    </td>
+    <td valign="top">
+        <form action="<?php echo $_SERVER['REQUEST_URI']?>" method="post" name="rule" onsubmit="return false;">
+        <table width="100%">
+        <tr><th>Rule Configuration
+        </th></tr><tr><td>
+            <input type="hidden" value="0" name="rule[id]" />
+            Name of this rule :
+            <input type="text" size="60" value="" name="rule[name]"
+                onfocus="text_onfocus(this,'[ new rule ]')" onblur="text_onblur(this,'[ new rule ]')" />
+            <br />
+            <input type="radio" value="1" name="rule[all]">All matches</input>
+            <input type="radio" value="0" name="rule[all]">One match</input>
+            <br />
+            <input type="checkbox" checked="checked" name="rule[block]">Blocking Rule</input>
+        </td></tr><tr><th>Matches List
+        </th></tr><tr><td name="matches_row">
+        </td></tr><tr><th>Actions List
+        </th></tr><tr><td name="actions_row">
+        </td></tr><tr><td>
+            <input type="submit" value="New Match" name="rule[new_match]" onclick="newMatch() "/>
+            <input type="submit" value="New Action" name="rule[new_action]" onclick="newAction()" />
+            <input type="submit" value="Submit" name="rule[submit]" onclick="this.form.submit()" />
+        </td></tr>
+        </table>
+        </form>
+    </td>
+</tr>
+</table>
+
+<script type="text/javascript">
+    createRuleForm();
+</script>
+
+<?php
+/********** footer **********/
+
+require("include/footer.inc.php");
+
+/********************************************************************************
+* $id: header.inc.php,v 1.2 2003/08/03 16:02:41 madcoder exp $
+* vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100:
+********************************************************************************/
+?>