2 // vim: tabstop=2:shiftwidth=2
4 // Nucleus Admin section;
8 include($strRel . 'config.php');
10 include($DIR_LIBS . 'PLUGINADMIN.php');
12 if ($blogid) {$isblogadmin = $member->isBlogAdmin($blogid);}
13 else $isblogadmin = 0;
15 if (!($member->isAdmin() || $isblogadmin)) {
16 $oPluginAdmin = new PluginAdmin('SpamBayes');
17 $pbl_config = array();
18 $oPluginAdmin->start();
19 echo "<p>"._ERROR_DISALLOWED."</p>";
25 $action = requestVar('page');
26 $aActionsNotToCheck = array(
29 if (!in_array($action, $aActionsNotToCheck)) {
30 if (!$manager->checkTicket()) doError(_ERROR_BADTICKET);
33 if (isset($_GET['page'])) {$action = $_GET['page'];}
34 if (isset($_POST['page'])) {$action = $_POST['page'];}
36 // Okay; we are allowed. let's go
37 // create the admin area page
38 $oPluginAdmin = new PluginAdmin('SpamBayes');
39 $oPluginAdmin->start();
41 if( !$oPluginAdmin->plugin->getOption('appid') ){
42 echo '<h2>Plugin Error!</h2>';
43 echo '<h3>Yahoo!Japan Application ID is not set.</h3>';
48 $action = requestVar('page');
49 if ($action == 'clearlog') {
50 $filter = requestVar('filter') ? requestVar('filter') : 'all';
51 $filtertype = requestVar('filtertype') ? requestVar('filtertype') : 'all';
52 $ipp = requestVar('ipp') ? requestVar('ipp') : 10;
53 $keyword = requestVar('keyword');
54 $oPluginAdmin->plugin->spambayes->nbs->clearlog($filter, $filtertype, $keyword, $ipp);
56 // reset values to no filter; otherwise the view will be empty
57 if ($_REQUEST['amount'] <> 'cp' ) {
58 $_REQUEST['filter'] = 'all';
59 $_REQUEST['filtertype'] = 'all';
60 $_REQUEST['keyword'] = '';
64 sb_nucmenu($oPluginAdmin->plugin->getOption('enableTrainall'),$oPluginAdmin->plugin->getOption('enableLogging'));
68 $oPluginAdmin->plugin->spambayes->updateProbabilities();
113 case 'trainspamtbnew':
125 case 'trainblockednew':
126 sb_trainblockednew();
130 $cats = $oPluginAdmin->plugin->spambayes->nbs->getCategories();
132 $keys = array_keys($cats);
133 echo '<fieldset><legend>Baysian DB statistics</legend><table>';
134 echo '<tr><th>category</th><th>probability</th><th>wordcount</th></tr>';
135 foreach($cats as $category) {
136 echo "<tr><td><b>$keys[$i]</b></td>";
137 foreach($category as $key => $value) {
138 echo '<td>'.$value.'</td>';
143 echo '</table></fieldset>';
145 function getPluginOption($name) {
147 return $pbl_config[$name];
149 function getPlugid() {
150 global $oPluginAdmin;
151 return $oPluginAdmin->plugin->plugid;
154 function sb_train() {
155 global $oPluginAdmin;
156 if (requestVar('catcode') > '' && requestVar('expression') > '') {
157 $docid = $oPluginAdmin->plugin->spambayes->nbs->nextdocid();
158 $oPluginAdmin->plugin->spambayes->train($docid,requestVar('catcode'),requestVar('expression'));
159 $oPluginAdmin->plugin->spambayes->updateProbabilities();
163 function sb_trainlog() {
164 global $oPluginAdmin;
165 if (requestVar('catcode') > '' && requestVar('id') > 0) {
166 $query = 'select content from '.$oPluginAdmin->plugin->table_log.' where id = '.intval(requestVar('id'));
167 $res = sql_query($query);
168 $arr = mysql_fetch_array($res);
169 if ($arr['content']) {
170 $docid = $oPluginAdmin->plugin->spambayes->nbs->nextdocid();
171 $oPluginAdmin->plugin->spambayes->train($docid,requestVar('catcode'),$arr['content']);
172 $oPluginAdmin->plugin->spambayes->updateProbabilities();
173 echo '<h3>document added to the database as: '.requestVar('catcode').'</h3>';
175 echo 'An error occured';
181 global $oPluginAdmin;
182 $expression = requestVar('expression');
183 if ($expression > '') {
184 $score = $oPluginAdmin->plugin->spambayes->categorize($expression);
185 if ((float)$score['spam'] > (float)$oPluginAdmin->plugin->getOption('probability')) {
186 echo '<h2>Testresult: Spam! [score:'.$score['spam'].']</h2>';
188 echo '<h2>Testresult: Ham! [score:'.$score['ham'].']</h2>';
190 echo '<fieldset style="width:90%;"><legend>Tested:</legend>';
191 echo htmlspecialchars($expression,ENT_QUOTES);
196 function sb_trainall() {
197 global $oPluginAdmin;
198 // now train spam bayes with all current comments as ham!!
199 $res = sql_query("select * from ".sql_table('comment'));
200 while ($arr = mysql_fetch_array($res)) {
201 $oPluginAdmin->plugin->spambayes->train($arr['cnumber'], 'ham', $arr['cbody'].' '.$arr['chost'].' '.$arr['cip']);
203 $oPluginAdmin->plugin->spambayes->updateProbabilities();
206 function sb_traintb() {
207 global $oPluginAdmin;
208 // now train spam bayes with all current trackbacks as ham!!
209 $res = sql_query("select * from ".sql_table('plugin_tb').' where block = 0');
210 while ($arr = mysql_fetch_array($res)) {
211 $oPluginAdmin->plugin->spambayes->train($arr['id']+100000000, 'ham', $arr['title'].' '.$arr['excerpt'].' '.$arr['blog_name'].' '.$arr['url']);
213 $oPluginAdmin->plugin->spambayes->updateProbabilities();
216 function sb_traintbnew() {
217 global $oPluginAdmin;
218 // now train spam bayes with all current trackbacks as ham!!
219 $res = sql_query("select * from ".sql_table('plugin_tb').' where block = 0');
220 while ($arr = mysql_fetch_array($res)) {
221 $oPluginAdmin->plugin->spambayes->trainnew($arr['id']+100000000, 'ham', $arr['title'].' '.$arr['excerpt'].' '.$arr['blog_name'].' '.$arr['url']);
223 $oPluginAdmin->plugin->spambayes->updateProbabilities();
226 function sb_trainspamtb() {
227 global $oPluginAdmin;
228 // now train spam bayes with all blocked trackbacks as spam!!
229 $res = sql_query("select * from ".sql_table('plugin_tb').' where block = 1');
230 while ($arr = mysql_fetch_array($res)) {
231 $oPluginAdmin->plugin->spambayes->train($arr['id']+100000000, 'spam', $arr['title'].' '.$arr['excerpt'].' '.$arr['blog_name'].' '.$arr['url']);
233 $oPluginAdmin->plugin->spambayes->updateProbabilities();
236 function sb_trainspamtbnew() {
237 global $oPluginAdmin;
238 // now train spam bayes with all blocked trackbacks as spam!!
239 $res = sql_query("select * from ".sql_table('plugin_tb').' where block = 1');
240 while ($arr = mysql_fetch_array($res)) {
241 $oPluginAdmin->plugin->spambayes->trainnew($arr['id']+100000000, 'spam', $arr['title'].' '.$arr['excerpt'].' '.$arr['blog_name'].' '.$arr['url']);
243 $oPluginAdmin->plugin->spambayes->updateProbabilities();
246 function sb_trainnew() {
247 global $oPluginAdmin;
248 // now train spam bayes with all current comments as ham!!
249 $res = sql_query("select * from ".sql_table('comment'));
250 while ($arr = mysql_fetch_array($res)) {
251 $oPluginAdmin->plugin->spambayes->trainnew($arr['cnumber'], 'ham', $arr['cbody'].' '.$arr['chost'].' '.$arr['cip']);
253 $oPluginAdmin->plugin->spambayes->updateProbabilities();
256 function sb_trainblocked() {
257 global $oPluginAdmin;
258 // now train spam bayes with all current comments as ham!!
259 $res = sql_query("select * from ".sql_table('plug_cc_pending')." where processed = 1");
260 while ($arr = mysql_fetch_array($res)) {
261 $oPluginAdmin->plugin->spambayes->train($arr['id']+200000000, 'spam', $arr['cbody'].' '.$arr['chost'].' '.$arr['cip']);
263 $oPluginAdmin->plugin->spambayes->updateProbabilities();
266 function sb_trainblockednew() {
267 global $oPluginAdmin;
268 // now train spam bayes with all current comments as ham!!
269 $res = sql_query("select * from ".sql_table('plug_cc_pending')." where processed = 1");
270 while ($arr = mysql_fetch_array($res)) {
271 $oPluginAdmin->plugin->spambayes->trainnew($arr['id']+200000000, 'spam', $arr['cbody'].' '.$arr['chost'].' '.$arr['cip']);
273 $oPluginAdmin->plugin->spambayes->updateProbabilities();
276 function sb_untrainall() {
277 global $oPluginAdmin;
278 // now untrain spam bayes with all current comments as ham!!
279 $res = sql_query("select * from ".sql_table('comment'));
280 while ($arr = mysql_fetch_array($res)) {
281 $oPluginAdmin->plugin->spambayes->untrain($arr['cnumber']);
283 $oPluginAdmin->plugin->spambayes->updateProbabilities();
286 function sb_untrain() {
287 global $oPluginAdmin, $manager;
288 if (requestVar('ref') > 0) {
289 $oPluginAdmin->plugin->spambayes->untrain(requestVar('ref'));
290 $oPluginAdmin->plugin->spambayes->updateProbabilities();
291 echo '<h3>document untrained</h3>';
293 // build document table ...
294 $startpos = requestVar('startpos') ? requestVar('startpos') : 0;
295 $filterform = '<td></td>';
296 $total = $oPluginAdmin->plugin->spambayes->nbs->countreftable();
298 $pager = buildpager($startpos, $total, $filter, $filtertype, $filterform,'untrain', $keyword, 10);
299 $res = $oPluginAdmin->plugin->spambayes->nbs->getreftable($startpos);
301 echo '<h2>Spam Bayesian: Training data ['.$total.'] </h2>';
304 echo '<tr><th>Type</th><th>content</th><th>action</th></tr>';
306 while ($arr = mysql_fetch_array($res)) {
307 echo '<tr><td>'.$arr['catcode'].'</td><td>'.htmlspecialchars($arr['content'],ENT_QUOTES).'</td><td><a href="'.htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF').'?page=untrain&ref='.$arr['ref']),ENT_QUOTES).'">untrain</a></td></tr>';
313 function sb_explain(){
314 global $oPluginAdmin;
315 $id = requestVar('id');
316 echo '<h2>Explain: Scorelog unweighed results (sorted on ham scores)</h2>';
317 $arr = $oPluginAdmin->plugin->spambayes->nbs->getLogevent($id);
319 $oPluginAdmin->plugin->spambayes->explain($arr['content']);
322 function sb_promote(){
323 global $oPluginAdmin;
324 $id = requestVar('id');
325 echo '<h2>Promoting to blog: '.$id.'</h2>';
326 $arr = $oPluginAdmin->plugin->spambayes->nbs->getLogevent($id);
327 $itemid = explode('itemid:', $arr['log']);
328 $itemid = $itemid[1];
329 echo 'itemid: '.$itemid.'<br />';
330 $blogid = getBlogIDFromItemID($itemid);
331 $comment = explode('^^',$arr['content']);
333 $body = addslashes($comment[0]);
334 $host = addslashes($comment[1]);
335 $name = addslashes($comment[2]);
336 $url = addslashes($comment[3]);
337 $ip = addslashes($comment[4]);
339 $timestamp = $arr['logtime'];
342 $query = 'INSERT INTO '.sql_table('comment').' (CUSER, CMAIL, CMEMBER, CBODY, CITEM, CTIME, CHOST, CIP, CBLOG) '
343 . "VALUES ('$name', '$url', $memberid, '$body', $itemid, '$timestamp', '$host', '$ip', '$blogid')";
345 echo '<b>comment added</b><br />';
346 echo '-- end promote --';
349 function sb_batch() {
350 global $oPluginAdmin;
351 $logids = requestIntArray('batch');
352 $action = requestVar('batchaction');
353 //debug: var_dump($logids);
354 if ($logids) foreach ($logids as $id) {
358 $ar = $oPluginAdmin->plugin->spambayes->nbs->getLogevent($id);
359 $docid = $oPluginAdmin->plugin->spambayes->nbs->nextdocid();
360 $cat = substr($action,1);
361 $oPluginAdmin->plugin->spambayes->train($docid,$cat,$ar['content']);
362 echo 'train '.$cat.': '.$id.'<br />';
365 echo 'delete: '.$id.'<br />';
366 $oPluginAdmin->plugin->spambayes->nbs->removeLogevent($id);
370 echo '--end of batch--';
373 function sb_nucmenu($trainall, $logging) {
374 global $oPluginAdmin, $manager;
377 <!-- sorry, it's stronger then me :-) this javascript less popup's are styled using: http://meyerweb.com/eric/css/edge/popups/demo.html -->
378 <style type="text/css">
382 .adminmenu a:hover span {
385 text-decoration: none;
389 background-color:#ffff7d;
393 border: 1px solid black;
397 background-color: #ffff7d;
401 $total = $oPluginAdmin->plugin->spambayes->nbs->countlogtable('all');
402 echo "<h2>SpamBayes menu</h2>\n";
403 echo "<ul class=\"adminmenu\">\n";
404 echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=train"),ENT_QUOTES)."\">Spam Bayes training<span>Use this to train the Spam Bayesian filter with either 'ham' (not spam) or 'spam' messages. Your Bayessian filter needs both type of messages. The filter will become better with each message submitted.</span></a></li>\n";
405 echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=untrain"),ENT_QUOTES)."\">Spam Bayes untraining<span>Use this to remove references to a earlier trained document.</span></a></li>\n";
406 if ($logging == 'yes') {
407 echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=log"),ENT_QUOTES)."\">Spam Bayes log ($total)<span>This page shows you the logging of Spam Bayes. You can browse through all 'ham' and 'spam' messages and train the filter with them if you like. (Especially usefull when SpamBayes got it wrong).</span></a></li>\n";
409 if ($trainall == 'yes') {
410 echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=trainall"),ENT_QUOTES)."\">Train HAM (not spam) with all comments<span>Use this to train the Spam Bayesian filter with all your comments as 'ham' (not spam). This can take a while but you don't have to do anything. Just sit back and relax. Once you've run this option it's save to remove it from the menu. (See options)</span></a></li>\n";
411 //echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=trainblocked"),ENT_QUOTES)."\">Train spam with all blocked comments</a></li>\n";
412 echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=traintb"),ENT_QUOTES)."\">Train ham with all trackbacks.</a></li>\n";
413 echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=trainspamtb"),ENT_QUOTES)."\">Train spam with all blocked trackbacks.</a></li>\n";
414 echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=untrainall"),ENT_QUOTES)."\">Remove all comments from the HAM (not spam).<span>Use this to untrain the Spam Bayesian filter. This can take a while but you don't have to do anything. Just sit back and relax. Use only if you think earlier training went wrong.</span></a></li>\n";
416 echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=trainnew"),ENT_QUOTES)."\">Train HAM (not spam) with all NEW comments<span>Use this to train the Spam Bayesian filter with all your yet untrained comments as 'ham' (not spam). This can take a while but you don't have to do anything. Just sit back and relax. You can use this option as much as you like. Only untrained comments will be added.</span></a></li>\n";
417 //echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=trainblockednew"),ENT_QUOTES)."\">Train spam with all NEW blocked comments</a></li>\n";
418 echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=traintbnew"),ENT_QUOTES)."\">Train HAM (not spam) with all NEW trackbacks.</a></li>\n";
419 echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=trainspamtbnew"),ENT_QUOTES)."\">Train spam with all NEW blocked trackbacks.</a></li>\n";
420 //echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=update"),ENT_QUOTES)."\">Update probabilities<span>After some training, you must use this to finalise</span></a></li>\n";
421 echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=test"),ENT_QUOTES)."\">Spam Bayes Test<span>Use this to test if a certain message would be considered 'ham' (not spam) or 'spam' message</span></a></li>\n";
422 echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(dirname(serverVar('PHP_SELF'))."/../../index.php?action=pluginoptions&plugid=".getPlugid()),ENT_QUOTES)."\">Spam Bayes options<span>This will take you to the plugins options page. This menu is NOT available on that page. Sorry for this. Use the quickmenu option to show a quicklink to the admin page!</span></a></li>\n";
427 global $oPluginAdmin, $manager;
428 $ticket = $manager->_generateTicket();
430 $startpos = requestVar('startpos') ? requestVar('startpos') : 0;
431 $filter = requestVar('filter') ? requestVar('filter') : 'all';
432 $filtertype = requestVar('filtertype') ? requestVar('filtertype') : 'all';
433 $ipp = requestVar('ipp') ? requestVar('ipp') : 10;
434 $keyword = requestVar('keyword');
435 $filterform = buildfilterform($filter,$filtertype,$keyword,$ipp);
437 $total = $oPluginAdmin->plugin->spambayes->nbs->countlogtable($filter, $filtertype, $keyword);
438 if ($filter == 'all') {
439 $htotal = $oPluginAdmin->plugin->spambayes->nbs->countlogtable('ham',$filtertype, $keyword);
440 $stotal = $oPluginAdmin->plugin->spambayes->nbs->countlogtable('spam',$filtertype, $keyword);
441 echo '<h2>Spam Bayesian: Log [total events: '.$total.' (ham: '.$htotal.' spam: '.$stotal.') ]</h2>';
443 echo '<h2>Spam Bayesian: Log [total '.$filter.' events: '.$total.']</h2>';
446 $res = $oPluginAdmin->plugin->spambayes->nbs->getlogtable($startpos,$filter, $filtertype, $keyword, $ipp);
447 $pager = buildpager($startpos, $total, $filter, $filtertype, $filterform,'log', $keyword, $ipp);
448 if ($total % $ipp == 0) {
449 $ap = intval(floor($total / $ipp));
451 $ap = intval(floor($total / $ipp)) + 1;
453 $cp = intval($startpos + $ipp) / $ipp;
455 echo '<tr><th colspan="2">Page '.$cp.' of '.$ap.'</th><td colspan="2">Browse: <form style="display:inline"><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="text" size="3" name="ipp" value="'.$ipp.'" /> items per page. <input type="submit" value="Go" /><input type="hidden" name="amount" value="cp" /><input type="hidden" name="filter" value="'.$filter.'" /><input type="hidden" name="filtertype" value="'.$filtertype.'" /><input type="hidden" name="keyword" value="'.$keyword.'" /><input type="hidden" name="page" value="log" /></form>';
456 echo '<span style="text-align:right" class="batchoperations">';
457 if ($filter <> 'all') {
458 echo ' type: <b>'.$filter.'</b>';
460 if ($filtertype <> 'all') {
461 echo ' event: <b>'.$filtertype.'</b>';
464 echo ' keyword: <b>'.$keyword.'</b>';
466 echo '</span></td></tr>';
468 $extraaction = '&filter='.$filter.'&filtertype='.urlencode($filtertype).'&startpos='.$startpos.'&keyword='.$keyword.'&ipp='.$ipp.'&ticket='.$ticket;
469 echo '<tr><th>Date</th><th>event</th><th>content</th><th>action</th></tr><form method="post"><input type="hidden" name="ticket" value="'.$ticket.'" />';
471 while ($arr = mysql_fetch_array($res)) {
472 echo '<tr onmouseover="focusRow(this);" onmouseout="blurRow(this);"><td>'.$arr['logtime'].'<br /><b>'.$arr['catcode'].'</b></td><td>'.$arr['log'].'</td><td><input id="batch'.$i.'" name="batch['.$i.']" value="'.$arr['id'].'" type="checkbox"><label for="batch'.$i.'">'.htmlspecialchars(str_replace('^^', ' ',$arr['content']),ENT_QUOTES).'</label></td>';
473 echo '<td><a href="'.htmlspecialchars(serverVar('PHP_SELF').'?page=trainlog&catcode=ham&id='.$arr['id'].$extraaction,ENT_QUOTES).'"><nobr>train ham</nobr></a>';
474 echo ' <a href="'.htmlspecialchars(serverVar('PHP_SELF').'?page=trainlog&catcode=spam&id='.$arr['id'].$extraaction,ENT_QUOTES).'"><nobr>train spam</nobr></a>';
475 echo '<br /><a href="'.htmlspecialchars(serverVar('PHP_SELF').'?page=explain&id='.$arr['id'].$extraaction,ENT_QUOTES).'"><nobr>explain</nobr></a>';
476 if (strstr($arr['log'], 'itemid:')) {
477 echo '<br /><br /><a style="color:red" href="'.htmlspecialchars(serverVar('PHP_SELF').'?page=promote&id='.$arr['id'].$extraaction,ENT_QUOTES).'"><nobr>publish</nobr></a>';
483 if (mysql_num_rows($res) == 0) {
484 echo '<tr><td colspan="4"><b>Eventlog is empty</b></td></tr>';
486 echo '<tr><td colspan="4"><div class="batchoperations">with selected:<select name="batchaction">';
487 echo '<option value="tspam">Train spam</option>';
488 echo '<option value="tham">Train ham</option>';
489 echo '<option value="delete">Delete</option></select><input name="page" value="batch" type="hidden">';
490 echo '<input type="hidden" name="ipp" value="'.$ipp.'"/><input type="hidden" name="filter" value="'.$filter.'" /><input type="hidden" name="filtertype" value="'.$filtertype.'" /><input type="hidden" name="keyword" value="'.$keyword.'" />';
491 echo '<input value="Execute" type="submit">(
492 <a href="" onclick="if (event && event.preventDefault) event.preventDefault(); return batchSelectAll(1); ">select all</a> -
493 <a href="" onclick="if (event && event.preventDefault) event.preventDefault(); return batchSelectAll(0); ">deselect all</a>
495 </div></td></tr></form>';
496 echo '<tr><td colspan="4"><div class="batchoperations"><form action="" method="get" style="display:inline"><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="hidden" name="ipp" value="'.$ipp.'"/><input type="hidden" name="page" value="clearlog" /><input type="hidden" name="amount" value="cp" /><input type="hidden" name="filter" value="'.$filter.'" /><input type="hidden" name="filtertype" value="'.$filtertype.'" /><input type="hidden" name="keyword" value="'.$keyword.'" /><input type="submit" value="Clear first '.$ipp.'" /></form> <form action="" method="get" style="display:inline"><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="hidden" name="ipp" value="'.$ipp.'"/><input type="hidden" name="page" value="clearlog" /><input type="hidden" name="amount" value="cf" /><input type="hidden" name="filter" value="'.$filter.'" /><input type="hidden" name="filtertype" value="'.$filtertype.'" /><input type="hidden" name="keyword" value="'.$keyword.'" /><input type="submit" value="Clear current filtered logs" /></form> <form action="" method="get" style="display:inline"><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="hidden" name="page" value="clearlog" /><input type="submit" value="Clear complete log" /></form></div></td></tr>';
497 echo '<tr><th colspan="2">Page '.$cp.' of '.$ap.'</th><td colspan="2">Browse: <form style="display:inline"><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="text" size="3" name="ipp" value="'.$ipp.'" /> items per page. <input type="submit" value="Go" /><input type="hidden" name="amount" value="cp" /><input type="hidden" name="filter" value="'.$filter.'" /><input type="hidden" name="filtertype" value="'.$filtertype.'" /><input type="hidden" name="keyword" value="'.$keyword.'" /><input type="hidden" name="page" value="log" /></form></td></tr>';
502 function sb_trainform() {
504 echo "<form action=\"".serverVar('PHP_SELF')."\" method=\"get\">\n";
505 echo $manager->addTicketHidden();
506 echo "<input type=\"hidden\" name=\"page\" value=\"train\" />\n";
507 echo "<select name=\"catcode\"><option value=\"ham\">Ham (not spam)</option><option value=\"spam\" selected=\"1\">Spam</option></select><br />";
508 echo "<textarea class=\"sb_textinput\" cols=\"60\" rows=\"6\" name=\"expression\" ></textarea><br />";
509 echo "<input type=\"submit\" value=\"Train\" />\n";
513 function sb_testform() {
515 echo "<h2>Enter a message that needs to be tested against Spam Bayes</h2>";
516 echo "<form action=\"".serverVar('PHP_SELF')."\" method=\"get\">\n";
517 echo $manager->addTicketHidden();
518 echo "<input type=\"hidden\" name=\"page\" value=\"test\" />\n";
519 echo "<textarea class=\"sb_textinput\" cols=\"60\" rows=\"6\" name=\"expression\" ></textarea><br />";
520 echo "<input type=\"submit\" value=\"Test this!\" />\n";
524 function buildpager($startpos, $total, $filter, $filtertype, $filterform, $action, $keyword, $ipp) {
526 $ticket = $manager->_generateTicket();
529 if ($startpos >= $ipp) {
530 $pager .= '<td><form action="" method="get" style="display:inline"><input type="hidden" name="page" value="'.$action.'" />';
531 $pager .= '<input type="hidden" value="'.($startpos - $ipp).'" name="startpos" /><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="submit" value="Previous page" /><input type="hidden" name="filter" value="'.$filter.'" /><input type="hidden" name="filtertype" value="'.$filtertype.'" /><input type="hidden" name="keyword" value="'.$keyword.'" /><input type="hidden" name="ipp" value="'.$ipp.'"/></form></td>'.$filterform;
533 $pager .= '<td></td>'.$filterform;
535 if (($total - $ipp) > $startpos) {
536 $pager .= '<td><form action="" method="get" style="display:inline"><input type="hidden" name="page" value="'.$action.'" />';
537 $pager .= '<input type="hidden" value="'.($startpos + $ipp).'" name="startpos" /><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="submit" value="Next page" /><input type="hidden" name="filter" value="'.$filter.'" /><input type="hidden" name="filtertype" value="'.$filtertype.'" /><input type="hidden" name="keyword" value="'.$keyword.'" /><input type="hidden" name="ipp" value="'.$ipp.'"/></form></td>';
539 $pager .= '<td></td>';
545 function buildfilterform($filter,$filtertype, $keyword, $ipp) {
546 global $oPluginAdmin, $manager;
547 $ticket = $manager->_generateTicket();
549 $selected = $filter == 'all' ? 'selected':'';
550 $filterform = '<td colspan="2"><form style="display:inline">Show: <select name="filter"><option value="all" '.$selected.'>All</option>';
551 $selected = $filter == 'ham' ? 'selected':'';
552 $filterform .= '<option value="ham" '.$selected.'>Ham (not spam)</option>';
553 $selected = $filter == 'spam' ? 'selected':'';
554 $filterform .= '<option value="spam" '.$selected.'>Spam</option></select> <input type="hidden" name="page" value="log"/><input type="hidden" name="ipp" value="'.$ipp.'"/>';
556 $logtypes = $oPluginAdmin->plugin->spambayes->nbs->getlogtypes();
557 $selected = $filtertype == 'all' ? 'selected':'';
558 $filterform .= '<select name="filtertype"><option value="all" '.$selected.'>All events</option>';
559 foreach($logtypes as $logtype) {
560 $selected = $filtertype == $logtype ? 'selected' : '';
561 $show = explode(' ',$logtype);
562 $show = $show[0] == 'event' ? $show[1] : $show[0];
563 $filterform .= '<option value="'.$logtype.'" '.$selected.'>'.$show.'</option>';
565 $filterform .= '</select><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="submit" value="Apply filter" /></form>';
566 $filterform .= ' | <form style="display:inline"><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="hidden" name="page" value="log"/><input type="hidden" name="filter" value="'.$filter.'"/><input type="hidden" name="filtertype" value="'.$filtertype.'"/><input type="hidden" name="ipp" value="'.$ipp.'"/><input type="text" name="keyword" value="'.$keyword.'" /><input type="submit" value="search" /></form>';
567 $filterform .= '</td>';
570 $oPluginAdmin->end();