More ui-lib conversion
authorJamie Cameron <jcameron@webmin.com>
Sat, 24 Jan 2009 01:33:12 +0000 (01:33 +0000)
committerJamie Cameron <jcameron@webmin.com>
Sat, 24 Jan 2009 01:33:12 +0000 (01:33 +0000)
spam/edit_header.cgi
spam/edit_simple.cgi
spam/spam-lib.pl

index ef52fb6..deed855 100755 (executable)
@@ -10,71 +10,68 @@ require './spam-lib.pl';
 $conf = &get_config();
 
 print "$text{'header_desc'}<p>\n";
-&start_form("save_header.cgi", $text{'header_header'}."\n".
+&start_form("save_header.cgi", $text{'header_header'},
            "<a href='edit_simple.cgi?file=".&urlize($in{'file'}).
            "&title=".&urlize($in{'title'}).
            "'>$text{'header_switch'}</a>");
 
+# Allow user-defined rules?
 if (!$module_info{'usermin'}) {
-       print "<tr> <td><b>$text{'header_allow'}</b></td> <td nowrap colspan=3>";
        $allow = &find("allow_user_rules", $conf);
-       &yes_no_field("allow_user_rules", $allow, 0);
-       print "</td> </tr>\n";
+       print &ui_table_row($text{'header_allow'},
+               &yes_no_field("allow_user_rules", $allow, 0));
        }
 
+# Header tests
 @header = &find("header", $conf);
-print "<tr> <td valign=top><b>$text{'header_test'}</b></td> <td colspan=3>\n";
-&edit_table("header",
+print &ui_table_row($text{'header_test'},
+       &edit_table("header",
            [ $text{'header_tname'}, $text{'header_name'}, $text{'header_op'},
              $text{'header_pat'}, $text{'header_default'} ],
-           [ map { [ &split_header($_->{'value'}) ] } @header ], [ ], \&header_conv, 2);
-print "</td> </tr>\n";
+           [ map { [ &split_header($_->{'value'}) ] } @header ], [ ], \&header_conv, 2));
 
-print "<tr> <td colspan=4><hr></td> </tr>\n";
+print &ui_table_hr();
 
 push(@body, map { [ &split_body($_->{'value'}), 0 ] } &find("body", $conf));
 push(@body, map { [ &split_body($_->{'value'}), 1 ] } &find("rawbody", $conf));
 push(@body, map { [ &split_body($_->{'value'}), 2 ] } &find("fullbody", $conf));
 push(@body, map { [ &split_body($_->{'value'}), 3 ] } &find("full", $conf));
-print "<tr> <td valign=top><b>$text{'header_body'}</b></td> <td colspan=3>\n";
-&edit_table("body",
+print &ui_table_row($text{'header_body'},
+       &edit_table("body",
            [ $text{'header_tname'}, $text{'header_mode'}, $text{'header_op'},
-             $text{'header_pat'} ], \@body, [ ], \&body_conv, 2);
+             $text{'header_pat'} ], \@body, [ ], \&body_conv, 2));
 
-print "<tr> <td colspan=4><hr></td> </tr>\n";
+print &ui_table_hr();
 
 @uri = &find("uri", $conf);
-print "<tr> <td valign=top><b>$text{'header_uri'}</b></td> <td colspan=3>\n";
-&edit_table("uri",
+print &ui_table_row($text{'header_uri'},
+       &edit_table("uri",
            [ $text{'header_tname'}, $text{'header_pat'} ],
-           [ map { $_->{'words'} } @uri ], [ 20, 40 ], undef, 2);
-print "</td> </tr>\n";
+           [ map { $_->{'words'} } @uri ], [ 20, 40 ], undef, 2));
 
-print "<tr> <td colspan=4><hr></td> </tr>\n";
+print &ui_table_hr();
 
 @meta = &find("meta", $conf);
-print "<tr> <td valign=top><b>$text{'header_meta'}</b></td> <td colspan=3>\n";
-&edit_table("meta",
+print &ui_table_row($text{'header_meta'},
+       &edit_table("meta",
            [ $text{'header_tname'}, $text{'header_bool'} ],
            [ map { $_->{'value'} =~ /^(\S+)\s*(.*)$/ ? [ $1, $2 ] : [ ] } @meta ],
-           [ 20, 40 ], undef, 2);
+           [ 20, 40 ], undef, 2));
 
-print "<tr> <td colspan=4><hr></td> </tr>\n";
+print &ui_table_hr();
 
 @score = &find("score", $conf);
-print "<tr> <td valign=top><b>$text{'score_score'}</b></td> <td colspan=3>\n";
-&edit_table("score",
-           [ $text{'score_name'}, $text{'score_points'} ],
-           [ map { $_->{'words'} } @score ], [ 30, 6 ]);
-print "</td> </tr>\n";
+print &ui_table_row($text{'score_score'},
+       &edit_table("score",
+                   [ $text{'score_name'}, $text{'score_points'} ],
+                   [ map { $_->{'words'} } @score ], [ 30, 6 ]));
 
 @describe = &find("describe", $conf);
-print "<tr> <td valign=top><b>$text{'score_describe'}</b></td> <td colspan=3>\n";
-&edit_table("describe",
+print &ui_table_row($text{'score_describe'},
+       &edit_table("describe",
            [ $text{'score_name'}, $text{'score_descr'} ],
            [ map { $_->{'value'} =~ /^(\S+)\s*(.*)/ ? [ $1, $2 ] : [ ] }
-             @describe ], [ 30, 40 ]);
-print "</td> </tr>\n";
+             @describe ], [ 30, 40 ]));
 
 &end_form(undef, $text{'save'});
 &ui_print_footer($redirect_url, $text{'index_return'});
@@ -83,34 +80,26 @@ print "</td> </tr>\n";
 sub header_conv
 {
 if ($_[0] == 0) {
-       return sprintf "<input name=$_[1] size=20 value='%s'>",
-               &html_escape($_[3]);
+       return &ui_textbox($_[1], $_[3], 20);
        }
 elsif ($_[0] == 1) {
        local $h = $_[3] =~ /^exists:(\S+)$/ ? $1 : $_[3] =~ /^eval:/ ? "" : $_[3];
-       return sprintf "<input name=$_[1] size=15 value='%s'>",
-               &html_escape($h);
+       return &ui_textbox($_[1], $h, 15);
        }
 elsif ($_[0] == 2) {
-       local $rv = "<select name=$_[1]>\n";
-       $rv .= sprintf "<option value='=~' %s>%s\n",
-               $_[3] eq '=~' ? "selected" : "", $text{'header_op0'};
-       $rv .= sprintf "<option value='!~' %s>%s\n",
-               $_[3] eq '!~' ? "selected" : "", $text{'header_op1'};
-       $rv .= sprintf "<option value='exists' %s>%s\n",
-               $_[4]->[1] =~ /^exists:/ ? "selected" : "", $text{'header_op2'};
-       $rv .= sprintf "<option value='eval' %s>%s\n",
-               $_[4]->[1] =~ /^eval:/ ? "selected" : "", $text{'header_op3'};
-       $rv .= "</select>\n";
-       return $rv;
+       local $v = $_[4]->[1] =~ /^exists:/ ? 'exists' :
+                  $_[4]->[1] =~ /^eval:/ ? 'eval' : $_[3];
+       return &ui_select($_[1], $v,
+                         [ [ '=~', $text{'header_op0'} ],
+                           [ '!~', $text{'header_op1'} ],
+                           [ 'exists', $text{'header_op2'} ],
+                           [ 'eval', $text{'header_op3'} ] ], 1, 0, $v);
        }
 elsif ($_[0] == 3) {
-       return sprintf "<input name=$_[1] size=20 value='%s'>",
-               &html_escape($_[4]->[1] =~ /^eval:(.*)/ ? $1 : $_[3]);
+       return &ui_textbox($_[1], $_[4]->[1] =~ /^eval:(.*)/ ? $1 : $_[3], 20);
        }
 elsif ($_[0] == 4) {
-       return sprintf "<input name=$_[1] size=15 value='%s'>",
-               &html_escape($_[3]);
+       return &ui_textbox($_[1], $_[3], 15);
        }
 }
 
@@ -118,31 +107,23 @@ elsif ($_[0] == 4) {
 sub body_conv
 {
 if ($_[0] == 0) {
-       return sprintf "<input name=$_[1] size=20 value='%s'>",
-               &html_escape($_[4]->[0]);
+       return &ui_textbox($_[1], $_[4]->[0], 20);
        }
 elsif ($_[0] == 1) {
-       local $rv = "<select name=$_[1]>\n";
-       local $m;
-       foreach $m (0 .. 3) {
-               $rv .= sprintf "<option value=%d %s>%s\n",
-                  $m, $m == $_[4]->[2] ? "selected" : "", $text{'header_mode'.$m};
-               }
-       $rv .= "</select>\n";
-       return $rv;
+       return &ui_select($_[1], $_[4]->[2],
+                       [ [ 0, $text{'header_mode0'} ],
+                         [ 1, $text{'header_mode1'} ],
+                         [ 2, $text{'header_mode2'} ],
+                         [ 3, $text{'header_mode3'} ] ]);
        }
 elsif ($_[0] == 2) {
-       local $rv = "<select name=$_[1]>\n";
-       $rv .= sprintf "<option value=0 %s>%s\n",
-               $_[4]->[1] =~ /^eval:/ ? "" : "selected", $text{'header_op0'};
-       $rv .= sprintf "<option value=1 %s>%s\n",
-               $_[4]->[1] =~ /^eval:/ ? "selected" : "", $text{'header_op3'};
-       $rv .= "</select>\n";
-       return $rv;
+       return &ui_select($_[1], $_[4]->[1] =~ /^eval:/ ? 1 : 0,
+                         [ [ 0, $text{'header_op0'} ],
+                           [ 1, $text{'header_op3'} ] ]);
        }
 elsif ($_[0] == 3) {
-       return sprintf "<input name=$_[1] size=40 value='%s'>",
-               &html_escape($_[4]->[1] =~ /^eval:(.*)$/ ? $1 : $_[4]->[1]);
+       return &ui_textbox($_[1], $_[4]->[1] =~ /^eval:(.*)$/ ? $1 : $_[4]->[1],
+                          40);
        }
 }
 
index d890057..32f13ee 100755 (executable)
@@ -9,7 +9,7 @@ require './spam-lib.pl';
 $conf = &get_config();
 
 print "$text{'simple_desc'}<p>\n";
-&start_form("save_simple.cgi", "post",
+&start_form("save_simple.cgi", $text{'simple_header'},
            "<a href='edit_header.cgi?file=".&urlize($in{'file'}).
            "&title=".&urlize($in{'title'}).
            "'>$text{'simple_switch'}</a>");
index bdce349..62ac285 100644 (file)
@@ -368,25 +368,21 @@ return map { { 'name' => $_[0],
 sub edit_table
 {
 local ($h, $v);
-print "<table border>\n";
-print "<tr $tb>\n";
-foreach $h (@{$_[1]}) {
-       print "<td><b>$h</b></td>\n";
-       }
-print "</tr>\n";
+local $rv = &ui_columns_start($_[1]);
 local $i = 0;
 local $cfunc = $_[4] || \&default_convfunc;
 local $blanks = $_[5] || 1;
 foreach $v (@{$_[2]}, map { [ ] } (1 .. $blanks)) {
-       print "<tr $cb>\n";
+       local @cols;
        for($j=0; $j<@{$_[1]}; $j++) {
-               print "<td>",&$cfunc($j, "$_[0]_${i}_${j}", $_[3]->[$j],
-                                    $v->[$j], $v),"</td>";
+               push(@cols, &$cfunc($j, "$_[0]_${i}_${j}", $_[3]->[$j],
+                                    $v->[$j], $v));
                }
-       print "</tr>\n";
+       $rv .= &ui_columns_row(\@cols);
        $i++;
        }
-print "</table>\n";
+$rv .= &ui_columns_end();
+return $rv;
 }
 
 # default_convfunc(column, name, size, value)