447a12f164a6ed62bf2d76d31af006a4ed4d8786
[old-projects.git] / philter / philter / index.php
1 <?php
2 /********************************************************************************
3 * index.php : index page
4 * ---------
5 *
6 * This file is part of the philter distribution
7 * Copyright: See COPYING files that comes with this distribution
8 ********************************************************************************/
9
10 require("include/header.inc.php");
11 require("include/philter.inc.php");
12 require("include/config.inc.php");
13
14 $mail_pool = new EmailPool(get_user_id());
15 $filter = new Filter(get_user_id());
16
17 if(count($_POST)) { // a FORM has been submitted
18 if(isset($_POST['global'])) { // FORM global
19 foreach($philter->config['global_plugins'] as $id=>$g_plugin)
20 if(isset($_POST['global'][$id]))
21 $filter->set_global_data($id,$_POST['global'][$id]);
22 $filter->rules[0]->sql_store(get_user_id(),0);
23 }
24 if(isset($_POST['emails'])) // FORM emails
25 if(!$mail_pool->handle_form())
26 echo "<p style=\"color:red;\">".$philter->error()."</p>\n";
27
28 if(!empty($_POST['order']['action'])) // FORM order
29 if($_POST['order']['action']=='submit') {
30 foreach($filter->rules as $id=>$rule)
31 if(isset($_POST['order'][$id]))
32 $filter->rules[$id]->move_to($_POST['order'][$id], $filter->uid, $id);
33 uasort($filter->rules, 'rule_cmp');
34 } elseif($_POST['order']['action']=='delete' && !empty($_POST['order']['select'])) {
35 $filter->delete_rule($_POST['order']['select']);
36 $_POST['order']['select'] = min(count($filter->rules),$_POST['order']['select']);
37 }
38
39 if(!empty($_POST['rule'])) // FORM rule
40 if(!$filter->handle_form())
41 echo "<p style=\"color:red;\">".$philter->error()."</p>\n";
42 }
43
44 require("include/js_factory.inc.php");
45
46 /********** globals plugins **********/
47 ?>
48 <div class="rubrique"><?php i18n('global_title'); ?></div>
49 <?php
50 i18n('global_help');
51 if(count($philter->config['global_plugins'])) {
52 echo "<form action=\"{$_SERVER['REQUEST_URI']}\" method=\"post\">\n"
53 ."<table width=\"95%\" class=\"bicol\" cellspacing=\"1\" cellpadding=\"1\" align=\"center\">\n";
54
55 foreach($philter->config['global_plugins'] as $id=>$g_plugin) {
56 echo "<tr><td>\n";
57 echo $g_plugin->to_form($filter->get_global_data($id));
58 echo "</td></tr>\n";
59
60 }
61 echo "<tr><td align='center'><input type='submit' name='global[submit]' value='"._i18n('apply_changes')."'/></td></tr>\n"
62 ."</table>\n"
63 ."</form>\n";
64 }
65
66 /********** emails **********/
67 ?>
68 <br />
69 <div class="rubrique"><?php i18n('pool_title'); ?></div>
70 <?php
71 i18n('pool_help');
72 echo $mail_pool->to_form();
73
74 /********** filters **********/
75 ?>
76
77 <br />
78 <div class="rubrique"><?php i18n('filter_title'); ?></div>
79 <?php
80 i18n('filter_help');
81 ?>
82 <table width="95%" cellspacing="0" cellpadding="2" align="center">
83 <tr><td width="25%" valign="top">
84 <form action="<?php echo $_SERVER['REQUEST_URI']?>" method="post" id="order" name="order" onsubmit="return false;">
85 <table class="bicol" width="100%" cellpadding="1" cellspacing="1">
86 <tr><th><?php i18n('filter_list_title');?></th></tr>
87 <tr><td>
88 <?php
89 foreach($filter->rules as $id=>$rule)
90 if($id)
91 echo "<input type=\"hidden\" id=\"order$id\" name=\"order[$id]\" value=\"{$rule->rank}\" />\n";
92
93 $presel = (isset($_POST['rule']['id']) ? $_POST['rule']['id']
94 : (isset($_POST['order']['select']) ? $_POST['order']['select'] : 0));
95
96 echo "<select size=\"16\" style=\"width:100%;\" id=\"orderSelect\" name=\"order[select]\" onchange=\"createRuleForm()\">\n";
97 echo "<option value=\"0\" ".($presel ? "" : " selected=\"selected\"").">";
98 i18n('new_rule');
99 echo "</option>\n";
100
101 foreach($filter->rules as $id=>$rule)
102 if($id)
103 echo "<option value=\"$id\""
104 .($presel==$id ? " selected=\"selected\"":"")
105 .">{$rule->name}</option>\n";
106 ?>
107 </select>
108 </td></tr><tr><td>
109 <input type="submit" value="<?php i18n('up');?>" name="order[up]" onclick="order_up();" />
110 <input type="submit" value="<?php i18n('dn');?>" name="order[dn]" onclick="order_dn();" /><br />
111 <input type="submit" value="<?php i18n('del');?>" name="order[delete]" onclick="order_submit(this)" />
112 <input type="submit" value="<?php i18n('submit');?>" name="order[submit]" onclick="order_submit(this)" />
113 <input type="hidden" value="" name="order[action]" />
114 </td></tr>
115 </table>
116 </form>
117 </td>
118 <td valign="top">
119 <form action="<?php echo $_SERVER['REQUEST_URI']?>" method="post" id="rule" name="rule" onsubmit="return false;">
120 <table width="100%" class="bicol" cellspacing="1" cellpadding="1">
121 <tr><th><?php i18n('rule_name'); ?>
122 </th></tr><tr><td>
123 <input type="text" value="" id="ruleName" name="rule[name]" style="width: 100%;"
124 onfocus="text_onfocus(this,'<?php i18n('new_rule');?>')"
125 onblur="text_onblur(this,'<?php i18n('new_rule');?>')" />
126 </td></tr>
127 <tr class="impair"><th><?php i18n('filter_rule_conf');?>
128 </th></tr><tr class="impair"><td>
129 <input type="radio" value="1" id="ruleAll1" name="rule[all]" /><?php i18n('all_matches');?>
130 <input type="radio" value="0" id="ruleAll0" name="rule[all]" /><?php i18n('one_match');?>
131 <br />
132 <input type="checkbox" checked="checked" id="ruleBlock" name="rule[block]" />
133 <?php i18n('blocking_rule');?>
134 </td></tr><tr class="impair"><th><?php i18n('filter_matches_list');?>
135 </th></tr><tr class="impair"><td id="matchesRow">
136 </td></tr><tr class="impair"><th><?php i18n('filter_actions_list');?>
137 </th></tr><tr class="impair"><td id="actionsRow">
138 </td></tr><tr class="impair"><td>
139 <input type="hidden" value="0" id="ruleId" name="rule[id]" />
140 <input type="submit" value="<?php i18n('new_match');?>" name="rule[new_match]" onclick="newMatch() "/>
141 <input type="submit" value="<?php i18n('new_action');?>" name="rule[new_action]" onclick="newAction()" />
142 <input type="submit" value="<?php i18n('submit');?>" name="rule[submit]" onclick="this.form.submit()" />
143 </td></tr>
144 </table>
145 </form>
146 </td>
147 </tr>
148 </table>
149
150 <script type="text/javascript">
151 createRuleForm();
152 </script>
153
154 <?php
155 /********** footer **********/
156
157 require("include/footer.inc.php");
158
159 /********************************************************************************
160 * $id: header.inc.php,v 1.2 2003/08/03 16:02:41 madcoder exp $
161 * vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100:
162 ********************************************************************************/
163 ?>