1<?php 2 3require_once dirname(__FILE__).'/accesscheck.php'; 4 5if (isset($_GET['type']) && $_GET['type'] == 'candidate') { 6 $type = 'candidate'; 7 $url = '&type=candidate'; 8} else { 9 $type = 'active'; 10 $url = '&type=active'; 11} 12 13if (isset($_POST['tagaction']) && isset($_POST['tagged']) && is_array($_POST['tagged']) && count($_POST['tagged'])) { 14 switch ($_POST['tagaction']) { 15 case 'delete': 16 foreach ($_POST['tagged'] as $key => $val) { 17 Sql_Query(sprintf('delete from %s where id = %d', $GLOBALS['tables']['bounceregex'], $key)); 18 } 19 break; 20 case 'activate': 21 foreach ($_POST['tagged'] as $key => $val) { 22 Sql_Query(sprintf('update %s set status = "active" where id = %d', $GLOBALS['tables']['bounceregex'], 23 $key)); 24 } 25 break; 26 case 'deactivate': 27 foreach ($_POST['tagged'] as $key => $val) { 28 Sql_Query(sprintf('update %s set status = "candidate" where id = %d', $GLOBALS['tables']['bounceregex'], 29 $key)); 30 } 31 break; 32 } 33 Redirect('bouncerules'.$url); 34} 35 36if (isset($_POST['listorder']) && is_array($_POST['listorder'])) { 37 foreach ($_POST['listorder'] as $ruleid => $order) { 38 Sql_Query(sprintf('update %s set listorder = %d where id = %d', $GLOBALS['tables']['bounceregex'], $order, 39 $ruleid)); 40 } 41} 42 43if (isset($_GET['del']) && $_GET['del']) { 44 Sql_Query(sprintf('delete from %s where id = %d', $GLOBALS['tables']['bounceregex'], $_GET['del'])); 45 Redirect('bouncerules'.$url); 46} 47 48if (isset($_POST['newrule']) && $_POST['newrule']) { 49 Sql_Query(sprintf('insert into %s (regex, regexhash, action,comment,admin,status) values("%s","%s","%s","%s",%d,"active")', 50 $GLOBALS['tables']['bounceregex'], sql_escape($_POST['newrule']), md5(sql_escape($_POST['newrule'])), sql_escape($_POST['action']), 51 sql_escape($_POST['comment']), $_SESSION['logindetails']['id']), 1); 52 $num = Sql_Affected_Rows(); 53 if ($num < 0) { 54 echo '<p class="actionresult alert alert-info">'.$GLOBALS['I18N']->get('That rule exists already').'</p>'; 55 } else { 56 Redirect('bouncerules'.$url); 57 } 58} 59$count = Sql_Query(sprintf('select status, count(*) as num from %s group by status', 60 $GLOBALS['tables']['bounceregex'])); 61while ($row = Sql_Fetch_Array($count)) { 62 printf($GLOBALS['I18N']->get('Number of %s rules: %d').'<br/>', $row['status'], $row['num']); 63} 64 65$tabs = new WebblerTabs(); 66$tabs->addTab($GLOBALS['I18N']->get('active'), PageUrl2('bouncerules&type=active')); 67$tabs->addTab($GLOBALS['I18N']->get('candidate'), PageUrl2('bouncerules&type=candidate')); 68if ($type == 'candidate') { 69 $tabs->setCurrent($GLOBALS['I18N']->get('candidate')); 70} else { 71 $tabs->setCurrent($GLOBALS['I18N']->get('active')); 72} 73echo "<p><div class='minitabs'>\n"; 74echo $tabs->display(); 75echo "</div></p>\n"; 76 77$some = 1; 78$req = Sql_Query(sprintf('select * from %s where status = "%s" order by listorder,regex', 79 $GLOBALS['tables']['bounceregex'], $type)); 80$ls = new WebblerListing($GLOBALS['I18N']->get('Bounce Regular Expressions')); 81if (!Sql_Num_Rows($req)) { 82 echo $GLOBALS['I18N']->get('No Rules found'); 83 $some = 0; 84} else { 85 echo formStart('class="bouncerulesListing"'); 86} 87 88while ($row = Sql_Fetch_Array($req)) { 89 $element = $GLOBALS['I18N']->get('rule').' '.$row['id']; 90 $ls->addElement($element, PageUrl2('bouncerule&id='.$row['id'])); 91 if ($type == 'candidate') { 92 // check if it matches an active rule 93 $activerule = matchedBounceRule($row['regex'], 1); 94 if ($activerule) { 95 $ls->addColumn($element, $GLOBALS['I18N']->get('match'), 96 PageLink2('bouncerule&id='.$activerule, $GLOBALS['I18N']->get('match'))); 97 } 98 } 99 100 $ls->addColumn($element, $GLOBALS['I18N']->get('expression'), 101 '<a name="'.$row['id'].'"></a>'.shortenTextDisplay(htmlspecialchars($row['regex']), 50)); 102 $ls->addColumn($element, $GLOBALS['I18N']->get('action'), $GLOBALS['bounceruleactions'][$row['action']]); 103// $num = Sql_Fetch_Row_Query(sprintf('select count(*) from %s where regex = %d',$GLOBALS['tables']['bounceregex_bounce'],$row['id'])); 104// $ls->addColumn($element,$GLOBALS['I18N']->get('#bncs'),$num[0]); 105 $ls->addColumn($element, $GLOBALS['I18N']->get('#bncs'), $row['count']); 106 107 $ls->addColumn($element, $GLOBALS['I18N']->get('tag'), 108 sprintf('<input type="checkbox" name="tagged[%d]" value="%d">', $row['id'], $row['listorder'])); 109 $ls->addColumn($element, $GLOBALS['I18N']->get('order'), 110 sprintf('<input type="text" name="listorder[%d]" value="%d" size=3>', $row['id'], $row['listorder'])); 111 $ls->addColumn($element, $GLOBALS['I18N']->get('del'), 112 PageLink2('bouncerules&del='.$row['id'].$url, $GLOBALS['I18N']->get('del'))); 113} 114echo $ls->display(); 115if ($some) { 116 echo '<p class="information">'.$GLOBALS['I18N']->get('with tagged rules: ').' '; 117 printf('<b>%s</b> <input type="checkbox" name="tagaction" value="delete"><br/>', $GLOBALS['I18N']->get('delete')); 118 if ($type == 'candidate') { 119 printf('<b>%s</b> <input type="checkbox" name="tagaction" value="activate"><br/>', 120 $GLOBALS['I18N']->get('make active')); 121 } else { 122 printf('<b>%s</b> <input type="checkbox" name="tagaction" value="deactivate"><br/>', 123 $GLOBALS['I18N']->get('make inactive')); 124 } 125 echo ' <p class="submit"><input type="submit" name="doit" value="'.$GLOBALS['I18N']->get('Save Changes').'"></p>'; 126 echo '</form>'; 127} 128echo '<hr/>'; 129echo '<h3>'.$GLOBALS['I18N']->get('add a new rule').'</h3>'; 130echo '<form method=post>'; 131echo '<table class="bouncerulesAction">'; 132printf('<tr><td>%s</td><td><input type=text name="newrule" size=30></td></tr>', 133 $GLOBALS['I18N']->get('Regular Expression')); 134printf('<tr><td>%s</td><td><select name="action">', $GLOBALS['I18N']->get('Action')); 135foreach ($GLOBALS['bounceruleactions'] as $action => $desc) { 136 printf('<option value="%s">%s</option>', $action, $desc); 137} 138echo '</select></td></tr>'; 139printf('<tr><td colspan="2">%s</td></tr><tr><td colspan="2"><textarea name="comment" rows=10 cols=65></textarea></td></tr>', 140 $GLOBALS['I18N']->get('Memo for this rule')); 141echo '<tr><td colspan="2"><p class="submit"><input type="submit" name="add" value="'.$GLOBALS['I18N']->get('Add new Rule').'"></td></tr>'; 142echo '</table></form>'; 143