ui-lib conversion, tabs, general cleanup
authorJamie Cameron <jcameron@webmin.com>
Thu, 3 Jan 2008 01:25:00 +0000 (01:25 +0000)
committerJamie Cameron <jcameron@webmin.com>
Thu, 3 Jan 2008 01:25:00 +0000 (01:25 +0000)
time/CHANGELOG
time/apply.cgi
time/index.cgi
time/lang/en
time/save_timezone.cgi
time/time-lib.pl

index dd96f37..2d1708c 100644 (file)
@@ -13,3 +13,6 @@ When the hardware or system time is not editable due to module access control re
 Added check for empty timeservers field.
 ---- Changes since 1.380 ----
 Display a more complete message if unable to get the hardware time from hwclock.
+---- Changes since 1.390 ----
+Changed the main page to use tabs to split up the system time, timezone and sync sections.
+Re-wrote all user interface code to use Webmin's new UI library.
index 3d1c2d5..9a1bfa1 100755 (executable)
@@ -12,6 +12,7 @@ if (!$in{'action'}) {
        # user probably hit return in the time server field
        $in{'action'} = $text{ 'action_timeserver_sys' };
        }
+$mode = "time";
 
 if( $in{ 'action' } eq $text{ 'action_apply' } )
 {
@@ -85,7 +86,8 @@ if( $in{ 'action' } eq $text{ 'action_apply' } )
   &unlock_file(&cron::cron_file($job));
 
   &webmin_log("remote", $in{'action'} eq $text{'action_timeserver_sys'} ?  "date" : "hwclock", $rawtime, \%in);
+  $mode = "sync";
 }
 
-&redirect("");
+&redirect("index.cgi?mode=$mode");
 
index 6f3e452..cd887a9 100755 (executable)
@@ -4,6 +4,7 @@ require "./time-lib.pl";
 
 local ($rawdate, $rawhwdate, %system_date, $rawtime, %hw_date, $txt);
 $txt = "";
+&ReadParse();
 
 &error( $text{ 'acl_error' } ) if( $access{ 'sysdate' } && $access{ 'hwdate' } );
 
@@ -29,6 +30,17 @@ if (!$access{'hwdate'} && $config{'hwtime'} && !&has_command("hwclock")) {
        exit;
        }
 
+# Show tabs for times, timezones and syncing
+@tabs = ( );
+push(@tabs, [ "time", $text{'index_tabtime'}, "index.cgi?mode=time" ]);
+if ($access{'timezone'} && &has_timezone()) {
+       push(@tabs, [ "zone", $text{'index_tabzone'}, "index.cgi?mode=zone" ]);
+       }
+if ($access{'ntp'}) {
+       push(@tabs, [ "sync", $text{'index_tabsync'}, "index.cgi?mode=sync" ]);
+       }
+print &ui_tabs_start(\@tabs, "mode", $in{'mode'} || $tabs[0]->[0], 1);
+
 # Get the system time
 @tm = &get_system_time();
 $system_date{ 'second' } = $tm[0];
@@ -39,15 +51,19 @@ $system_date{ 'month' } = &number_to_month($tm[4]);
 $system_date{ 'year' } = $tm[5]+1900;
 $system_date{ 'day' } = &number_to_weekday($tm[6]);
 
+print &ui_tabs_start_tab("mode", "time");
+print $text{'index_desctime'},"<p>\n";
+
 if( !$access{'sysdate'} )
 {
   # Show system time for editing
-  print( 
-"<form action=apply.cgi>",
-  &tabletime( &hlink( $text{ 'sys_title' }, "system_time" ), 0, %system_date ),
-  "<input type=submit name=action value=\"", $text{ 'action_apply' }, "\">",
-  $config{'hwtime'} ? " <input type=submit name=action value=\"$text{'action_sync'}\">\n" : "");
-print "</form><p>";
+  print &ui_form_start("apply.cgi");
+  print &tabletime(&hlink($text{'sys_title'}, "system_time"), 0, %system_date);
+  print &ui_submit($text{'action_apply'}, "action");
+  if ($config{'hwtime'}) {
+       print &ui_submit($text{'action_sync'}, "action");
+  }
+  print &ui_form_end();
 }
 else
 {
@@ -73,29 +89,34 @@ if ($config{'hwtime'}) {
                    $hw_date{ 'second' } = $system_date{ 'second' } if( $hw_date{ 'second' } - $system_date{ 'second' } <= $config{ 'lease' } );
                        }
            
-               print( 
-               "<p><form action=apply.cgi>",
-                 &tabletime( &hlink( $text{ 'hw_title' }, "hardware_time" ), 0, %hw_date ),
-                 "<input type=submit name=action value=\"", $text{ 'action_save' }, "\">",
-                 $config{'hwtime'} ? " <input type=submit name=action value=\"".$text{ 'action_sync_s' }."\">" : "", "</form><p>" );
+               print &ui_form_start("apply.cgi");
+               print &tabletime(&hlink($text{'hw_title'}, "hardware_time"),
+                                0, %hw_date);
+               print &ui_submit($text{'action_save'}, "action");
+               if ($config{'hwtime'}) {
+                       print &ui_submit($text{'action_sync_s'}, "action");
+                       }
+               print &ui_form_end();
                }
        else {
                # Show show the hardware time
-               print "<p>",&tabletime( &hlink( $text{ 'hw_title' }, "hardware_time" ), 1, %hw_date ),"<p>\n";
+               print &tabletime(&hlink($text{'hw_title'}, "hardware_time"),
+                                1, %hw_date ),"<p>\n";
                }
        }
+print &ui_tabs_end_tab();
 
 if ($access{'timezone'} && &has_timezone()) {
-       print "<form action=save_timezone.cgi>\n";
-       print "<table border width=100%>\n";
-       print "<tr $tb> <td><b>$text{'index_tzheader'}</b></td> </tr>\n";
-       print "<tr $cb> <td><table>\n";
+       print &ui_tabs_start_tab("mode", "zone");
+       print $text{'index_desczone'},"<p>\n";
+
+       print &ui_form_start("save_timezone.cgi");
+       print &ui_table_start($text{'index_tzheader'}, "width=100%", 2);
 
        @zones = &list_timezones();
        $cz = &get_current_timezone();
        $found = 0;
-       print "<tr> <td><b>$text{'index_tz'}</b></td>\n";
-       print "<td><select name=zone>\n";
+       @opts = ( );
        foreach $z (@zones) {
                if ($z->[0] =~ /^(.*)\/(.*)$/) {
                        $pfx = $1;
@@ -104,68 +125,61 @@ if ($access{'timezone'} && &has_timezone()) {
                        $pfx = undef;
                        }
                if ($pfx ne $lastpfx && $z ne $zones[0]) {
-                       print "<option value=''>----------\n";
+                       push(@opts, [ '', '----------' ]);
                        }
                $lastpfx = $pfx;
-               printf "<option value=%s %s>%s\n",
-                       $z->[0], $cz eq $z->[0] ? "selected" : "",
-                       $z->[1] ? "$z->[0] ($z->[1])" : $z->[0];
-               $found = 1 if ($cz eq $z->[0]);
-               }
-       if (!$found && $cz) {
-               printf "<option value=%s %s>%s\n",
-                       $cz, "selected", $cz;
+               push(@opts, [ $z->[0], $z->[1] ? "$z->[0] ($z->[1])"
+                                              : $z->[0] ]);
                }
        print "</select></td> </tr>\n";
+       print &ui_table_row($text{'index_tz'},
+               &ui_select("zone", $cz, \@opts, 1, 0, $cz ? 1 : 0));
 
-       print "</table></td></tr></table>\n";
-       print "<input type=submit value='$text{'save'}'></form>\n";
+       print &ui_table_end();
+       print &ui_form_end([ [ undef, $text{'save'} ] ]);
+       print &ui_tabs_end_tab();
        }
 
-if( ( !$access{ 'sysdate' } && &has_command( "date" ) || !$access{ 'hwdate' } && &has_command( "hwclock" ) ) && $access{'ntp'} )
+if ( ( !$access{ 'sysdate' } && &has_command( "date" ) || !$access{ 'hwdate' } && &has_command( "hwclock" ) ) && $access{'ntp'} )
 {
        # Show time server input
-       print(
-       "<p><form action=apply.cgi>",
-         "<table nosave border width=\"100%\">",
-               "<tr $tb>",
-                 "<td colspan=2><b>", &hlink( $text{ 'index_timeserver' }, "timeserver" ), "</b></td>",
-               "</tr>",
-               "<tr $cb><td><table width=100%>",
-                 "<td><b>",$text{ 'index_addresses' }, "</b></td>",
-                 "<td>",&p_entry( "timeserver", $config{'timeserver'}, 40 ),
-                 "</td> </tr>\n");
+       print &ui_tabs_start_tab("mode", "sync");
+       print $text{'index_descsync'},"<p>\n";
+
+       print &ui_form_start("apply.cgi");
+       print &ui_table_start(&hlink($text{'index_timeserver'}, "timeserver"),
+                             "width=100%", 2, [ "width=30%" ]);
+
+       print &ui_table_row($text{'index_addresses'},
+               &ui_textbox("timeserver", $config{'timeserver'}, 60));
 
        # Show hardware time checkbox
        if ($config{'hwtime'}) {
-               print "<tr $cb> <td></td> <td>\n";
-               printf "<input type=checkbox name=hardware value=1 %s> %s\n",
-                       $config{'timeserver_hardware'} ? "checked" : "",
-                       $text{'index_hardware2'};
-               print "</td> </tr>\n";
+               print &ui_table_row(" ",
+                       &ui_checkbox("hardware", 1, $text{'index_hardware2'},
+                                    $config{'timeserver_hardware'}));
                }
 
        # Show schedule input
        &foreign_require("cron", "cron-lib.pl");
        $job = &find_cron_job();
-       print "<tr $cb> <td><b>$text{'index_sched'}</b></td>\n";
-       printf "<td><input type=radio name=sched value=0 %s> %s\n",
-               $job ? "" : "checked", $text{'no'};
-       printf "<input type=radio name=sched value=1 %s> %s</td> </tr>\n",
-               $job ? "checked" : "", $text{'index_schedyes'};
-
-       print "<tr $cb> <td colspan=2><table border width=100%>\n";
+       print &ui_table_row($text{'index_sched'},
+               &ui_radio("sched", $job ? 1 : 0,
+                 [ [ 0, $text{'no'} ], [ 1, $text{'index_schedyes'} ] ]));
        $job ||= { 'mins' => '0',
                   'hours' => '0',
                   'days' => '*',
                   'months' => '*',
                   'weekdays' => '*' };
-       &cron::show_times_input($job);
-       print "</table></td> </tr>\n";
+       print &ui_table_row(undef, "<table border width=100%>".
+               &capture_function_output(\&cron::show_times_input, $job).
+               "</table>", 2);
 
-       print "</table></td></tr></table>\n";
-       print "<input type=submit name=action value='$text{'index_sync'}'></form>";
+       print &ui_table_end();
+       print &ui_form_end([ [ undef, $text{'index_sync'} ] ]);
+       print &ui_tabs_end_tab();
 }
+print &ui_tabs_end(1);
 
 
 &ui_print_footer( "/", $text{ 'index' } );
@@ -177,34 +191,36 @@ sub tabletime
   %assoc_day = ( "Mon", $text{ 'day_1' }, "Tue", $text{ 'day_2' }, "Wed", $text{ 'day_3' }, "Thu", $text{ 'day_4' }, "Fri", $text{ 'day_5' }, "Sat", $text{ 'day_6' }, "Sun", $text{ 'day_0' } ),
   %assoc_month = ( "Jan", $text{ 'month_1' }, "Feb", $text{ 'month_2' }, "Mar", $text{ 'month_3' }, "Apr", $text{ 'month_4' }, "May", $text{ 'month_5' }, "Jun", $text{ 'month_6' }, "Jul", $text{ 'month_7' }, "Aug", $text{ 'month_8' }, "Sep", $text{ 'month_9' }, "Oct", $text{ 'month_10' }, "Nov", $text{ 'month_11' }, "Dec", $text{ 'month_12' } );
 
-$rv =
-"<table nosave border width=\"100%\"><tr ". $tb. "><td>". $label. "</td></tr></table>\n".
-"<table nosave border width=\"100%\">".
-  "<tr ". $cb. ">".
-       "<td nosave><b>". $text{ 'day' }. "</b></td>\n".
-       "<td nosave><b>". $text{ 'date' }. "</b></td>\n".
-       "<td nosave><b>". $text{ 'month' }. "</b></td>\n".
-       "<td nosave><b>". $text{ 'year' }. "</b></td>\n".
-       "<td><b>". $text{ 'hour' }. "</b></td>\n".
-  "</tr>\n";
+$rv = &ui_table_start($label, "width=100%", 2);
+local @grid;
+push(@grid, "<b>$text{'day'}</b>", "<b>$text{'date'}</b>",
+           "<b>$text{'month'}</b>", "<b>$text{'year'}</b>",
+           "<b>$text{'hourminsec'}</b>" );
+
 if (!$ro) {
-       $rv .= "<tr ". $cb. ">".
-               "<td>". ($assoc_day{ $src{ 'day' } } || $src{'day'})."</td>\n".
-               "<td>". &p_select( "date", $src{ 'date' }, ( 1..31 ) ). "</td>\n".
-               "<td>". &p_select_wdl( "month", $assoc_month{ $src{ 'month' } }, "01",( $text{ 'month_1' }, "02", $text{ 'month_2' }, "03", $text{ 'month_3' }, "04", $text{ 'month_4' }, "05", $text{ 'month_5' }, "06", $text{ 'month_6' }, "07", $text{ 'month_7' }, "08", $text{ 'month_8' }, "09", $text{ 'month_9' }, "10", $text{ 'month_10' }, "11", $text{ 'month_11' }, "12", $text{ 'month_12' } ) ). "</td>\n".
-               "<td>". &p_select( "year", $src{ 'year' }, ( 1969..2037 ) ). "</td>\n".
-               "<td>". &p_select( "hour", &zeropad($src{ 'hour' }, 2), ( "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", 10..23 ) ). "\n:". &p_select( "minute", &zeropad($src{ 'minute' }, 2), ( "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", 10..59) ). ":". &p_select( "second", &zeropad($src{ 'second' }, 2), ( "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", 10..59 ) ). "</td>\n".
-         "</tr>\n".
-       "</table>";
+       push(@grid,
+           ($assoc_day{ $src{ 'day' } } || $src{'day'}),
+           &ui_select("date", $src{'date'}, [ 1 .. 31 ]),
+           &ui_select("month", &zeropad(&month_to_number($src{'month'})+1, 2),
+                      [ map { [ &zeropad($_, 2), $text{'month_'.$_} ] }
+                            ( 1 .. 12 ) ]),
+           &ui_select("year", $src{'year'}, [ 1969 .. 2037 ]),
+           &ui_select("hour", &zeropad($src{'hour'}, 2),
+                      [ map { &zeropad($_, 2) } (00 .. 23) ]).":".
+           &ui_select("minute", &zeropad($src{'minute'}, 2),
+                      [ map { &zeropad($_, 2) } (00 .. 59) ]).":".
+           &ui_select("second", &zeropad($src{'second'}, 2),
+                      [ map { &zeropad($_, 2) } (00 .. 59) ]),
+           );
        }
 else {
-       $rv .= "<tr $cb>".
-              "<td>".($assoc_day{ $src{ 'day' } } || $src{'day'})."</td>\n".
-              "<td>".$src{'date'}."</td>\n".
-              "<td>".$src{'month'}."</td>\n".
-              "<td>".$src{'year'}."</td>\n".
-              "<td>".$src{'hour'}.":".$src{'minute'}.":".$src{'second'}."</td>\n".
-               "</tr></table>\n";
+       push(@grid, ($assoc_day{ $src{ 'day' } } || $src{'day'}),
+                   $src{'date'},
+                   $src{'month'},
+                   $src{'year'},
+                   $src{'hour'}.":".$src{'minute'}.":".$src{'second'});
        }
+$rv .= &ui_table_row(undef, &ui_grid_table(\@grid, 5, 100), 2);
+$rv .= &ui_table_end();
 return $rv;
 }
index ea0c919..cdf8c44 100644 (file)
@@ -10,6 +10,12 @@ index_hardware2=Set hardware time too
 index_tzheader=Time Zone
 index_tz=Change timezone to
 index_ehwclock=$1 failed : $2
+index_tabtime=Set time
+index_tabzone=Change timezone
+index_tabsync=Time server sync
+index_desctime=This form is for changing the system's current time, which is used by all running processes. On operating systems that have a separate hardware clock, it can be used to set that too.
+index_desczone=This form allows you to set the system's default time zone, which is used to convert the system time to a human-readable format and offset.
+index_descsync=This form is for configuring the system to automatically synchronize the time with a remote server. Synchronization will be done using the Unix <tt>time</tt> protocol or NTP, depending on which commands are installed and what the remote system supports.
 
 action_save=Save
 action_apply=Apply
@@ -38,6 +44,7 @@ month=Month
 date=Date
 hour=Hour
 year=Year
+hourminsec=Hour, minute and second
 
 error_cnf=Error : $1 command not found
 error_hw=Can't set the hardware time : $1
index bff808f..8bfcf2a 100755 (executable)
@@ -10,5 +10,5 @@ $in{'zone'} || &error($text{'timezone_enone'});
 &set_current_timezone($in{'zone'});
 &restart_miniserv();
 &webmin_log("timezone", undef, $in{'zone'});
-&redirect("");
+&redirect("index.cgi?mode=zone");
 
index 1f35d43..7ae19dd 100755 (executable)
@@ -9,65 +9,6 @@ if ($config{'zone_style'}) {
        do "$config{'zone_style'}-lib.pl";
        }
 
-sub p_link
-{
-    my ( $dest, $text ) = @_;
-    return "<a href=\"". $dest. "\">". $text. "</a>";
-}
-
-sub p_radio
-{
-    my ( $name, $checked, @list ) = @_;
-    local ($out, $size, $i);
-    $size = @list; $i = 0;
-
-    do
-    {
-       $out .= " <input type=radio name=".$name." value=".$list[$i];
-       $out .= " checked" if( $checked eq $list[$i++] );
-       $out .="> ".$list[$i++];
-    } while( $i < $size );
-
-    return $out;
-}
-
-sub p_entry
-{
-    my ( $name, $value, $size ) = @_;
-
-    $size ? return "<input name=". $name. " size=". $size." value=\"". $value."\">" : return "<input name=". $name. " value=\"". $value."\">";
-}
-
-sub p_select_wdl
-{
-  my ( $name, $selected, @list ) = @_;
-  local $out = "<select name=$name>";
-  local $i = 0;
-  local $size = @list;
-
-  do
-  {
-       $out .= "<option value=$list[$i++]";
-       $out .= " selected" if( $selected eq $list[$i] );
-       $out .= ">$list[$i++]";
-  } while( $i < $size );
-  $out .= "</select>";
-
-}
-
-sub p_select
-{
-  my ( $name, $selected, @list ) = @_;
-  local (@newlist, $item);
-
-  foreach $item ( @list )
-  {
-       push( @newlist, $item, $item );
-  }
-
-  p_select_wdl( $name, $selected, @newlist );
-}
-
 sub find_cron_job
 {
 &foreign_require("cron", "cron-lib.pl");