かんたん作成【HTML CSS JavaScript PHP CGI Perl Ruby Python .htaccess】

カレンダー(今年1月〜12月, 前年次年リンク付)

#! /usr/local/bin/ruby

today = Time.now

min = 1902
max = 2037

if ENV['QUERY_STRING'] == nil
    year = today.year
else
    year = ENV['QUERY_STRING'].to_i
    year = today.year if year < min or year > max
end

pre = year - 1
nex = year + 1
pre = today.year if pre < min
nex = today.year if nex > max

print "Content-type: text/html; charset=Shift_JIS\n\n"
print <<END
    <html>
    <head>
    <title>#{year}年カレンダー</title>
    </head>
    <body>
    <table align="center" cellpadding="5">
    <tr>
        <td><a href="#{ENV['SCRIPT_NAME']}?#{pre}">#{pre}≪</a></td>
        <th style="font-size:large">#{year}年</th>
        <td align="right"><a href="#{ENV['SCRIPT_NAME']}?#{nex}">≫#{nex}</a></td>
    </tr>
END
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]            # 月の日数(うるう年の2月は+1)
days[1] += 1 if year % 4 == 0 and year % 100 != 0 or year % 400 == 0
for m in 1..12                                # カレンダー表示(1月〜12月)
    startday = Time.local(year, m, 1)                # 1日
    endday = days[m - 1]                        # 最後の日
    print "<tr>\n" if m % 3 == 1
    print <<"    END"
        <td valign="top">
        <table border="2" bordercolor="#009900" cellspacing="0" cellpadding="5">
        <tr>
            <th colspan="7">#{m}<span style="font-size:xx-small">月</span></th>
        </tr>
        <tr>
            <td align="center" style="font-size:xx-small;color:red">日</td>
            <td align="center" style="font-size:xx-small">月</td>
            <td align="center" style="font-size:xx-small">火</td>
            <td align="center" style="font-size:xx-small">水</td>
            <td align="center" style="font-size:xx-small">木</td>
            <td align="center" style="font-size:xx-small">金</td>
            <td align="center" style="font-size:xx-small;color:blue">土</font></td>
        </tr>
    END
    count = 0
    i = 0
    while i < startday.wday                        # 1日までの空欄
        print "<tr>" if count % 7 == 0
        print "<td> </td>"
        count += 1
        i += 1
    end
    i = 1
    while i <= endday                        # 日付を書き込む
        print "<tr>" if count % 7 == 0
        print "<td align=\"right\""
        print " style=\"color:red\"" if count % 7 == 0
        print " style=\"color:blue\"" if count % 7 == 6
        print ">"
        print i
        print "</td>"
        count += 1
        print "</tr>\n" if count % 7 == 0
        i += 1
    end
    while count % 7 != 0                        # 最後の日からの空欄
        print "<td> </td>"
        count += 1
        print "</tr>\n" if count % 7 == 0
    end
    print <<"    END"
        </table>
        </td>
    END
    print "</tr>\n" if m % 3 == 0
end
print <<END
    </table>
    </body>
    </html>
END

exit
CGI(Ruby)
Hello world ! ユーザーエージェント取得・表示(ENV['HTTP_USER_AGENT'])
IPアドレス取得・表示(ENV['REMOTE_ADDR']) リンク元取得・表示(ENV['HTTP_REFERER'])
URL取得・表示(ENV['HTTP_HOST'], ENV['REQUEST_URI']) 環境変数一覧(ENV.each)
日時を取得・表示(Time.now) 指定の日までの日数を表示
時刻によって挨拶文を変える 日によって背景色を変える
見るたびに背景色を変える 見るたびに背景画像を変える
おみくじ(rand) カラーチャート
グラフ(横棒グラフ) アクセスカウンター
アクセスカウンター(画像) 訪問回数(クッキー)
パスワード認証 クッションページ(ENV['QUERY_STRING'])
クッションページ(ENV['PATH_INFO']) カレンダー
カレンダー(今年1月〜12月) カレンダー(今年1月〜12月, 前年次年リンク付)
掲示板 ディレクトリ内ファイル一覧表示
リダイレクト(Location) 条件指定リダイレクト(Location)
条件指定アクセス拒否(ステータスコードを返す) HTMLファイル読み込み・表示
HTMLファイル読み込み・パスワード認証 HTMLファイル読み込み・条件指定アクセス拒否
HTMLファイル読み込み・条件指定リダイレクト 外部CGIファイル読み込み(require)
画像ファイル読み込み・表示
かんたん作成【HTML CSS JavaScript PHP CGI Perl Ruby Python .htaccess】