~ubuntu-branches/debian/squeeze/alpine/squeeze

« back to all changes in this revision

Viewing changes to web/src/cgi.tcl-1.10/example/vclock.cgi

  • Committer: Bazaar Package Importer
  • Author(s): Asheesh Laroia
  • Date: 2007-02-17 13:17:42 UTC
  • Revision ID: james.westby@ubuntu.com-20070217131742-99x5c6cpg1pbkdhw
Tags: upstream-0.82+dfsg
ImportĀ upstreamĀ versionĀ 0.82+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/depot/path/tclsh
 
2
 
 
3
# This script implements the "Virtual Clock" used as the example in the
 
4
# paper describing CGI.pm, a perl module for generating CGI.
 
5
# Stein, L., "CGI.pm: A Perl Module for Creating Dynamic HTML Documents
 
6
# with CGI Scripts", SANS 96, May '96.
 
7
 
 
8
# Do you think it is more readable than the other version?
 
9
# (If you remove the comments and blank lines, it's exactly
 
10
# the same number of lines.)  See other comments after script. - Don
 
11
 
 
12
package require cgi
 
13
 
 
14
cgi_eval {
 
15
    source example.tcl
 
16
 
 
17
    cgi_input
 
18
 
 
19
    set format ""
 
20
    if {[llength [cgi_import_list]]} {
 
21
        if 0==[catch {cgi_import time}] {
 
22
            append format [expr {[cgi_import type] == "12-hour"?"%r ":"%T "}]
 
23
        }
 
24
        catch {cgi_import day;          append format "%A "}
 
25
        catch {cgi_import month;        append format "%B "}
 
26
        catch {cgi_import day-of-month; append format "%d "}
 
27
        catch {cgi_import year;         append format "%Y "}
 
28
    } else {
 
29
        append format "%r %A %B %d %Y"
 
30
    }
 
31
 
 
32
    set time [clock format [clock seconds] -format $format]
 
33
 
 
34
    cgi_title "Virtual Clock"
 
35
 
 
36
    cgi_body {
 
37
        puts "At the tone, the time will be [strong $time]"
 
38
        hr
 
39
        h2 "Set Clock Format"
 
40
 
 
41
        cgi_form vclock {
 
42
            puts "Show: "
 
43
            foreach x {time day month day-of-month year} {
 
44
                cgi_checkbox $x checked
 
45
                put $x
 
46
            }
 
47
            br
 
48
            puts "Time style: "
 
49
            cgi_radio_button type=12-hour checked;put "12-hour"
 
50
            cgi_radio_button type=24-hour        ;put "24-hour"
 
51
            br
 
52
            cgi_reset_button
 
53
            cgi_submit_button =Set          
 
54
        }
 
55
    }
 
56
}
 
57
 
 
58
# Notes:
 
59
 
 
60
# Time/date generation is built-in to Tcl.  Thus, no extra processes
 
61
# are necessary and the result is portable.  In contrast, CGI.pm
 
62
# only runs on UNIX.
 
63
 
 
64
# Displaying checkboxes side by side the way that CGI.pm does by
 
65
# default is awful.  The problem is that with enough buttons, it's not
 
66
# immediately clear if the button goes with the label on the right or
 
67
# left.  So cgi.tcl does not supply a proc to generate such a
 
68
# grouping.  I've followed CGI.pm's style here only to show that it's
 
69
# trivial to get the same affect, but the formatting in any real form
 
70
# is more wisely left to the user.
 
71
 
 
72
# Footer generation (<hr><address>...  at end of CGI.pm) is replaced
 
73
# by "source example.tcl".  Both take one line.