1/*
2 *	aegis - project change supervisor
3 *	Copyright (C) 1997, 1998, 2002, 2003, 2005-2008 Peter Miller
4 *
5 *	This program is free software; you can redistribute it and/or modify
6 *	it under the terms of the GNU General Public License as published by
7 *	the Free Software Foundation; either version 3 of the License, or
8 *	(at your option) any later version.
9 *
10 *	This program is distributed in the hope that it will be useful,
11 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 *	GNU General Public License for more details.
14 *
15 *	You should have received a copy of the GNU General Public License
16 *	along with this program. If not, see
17 *	<http://www.gnu.org/licenses/>.
18 */
19
20auto pn, p;
21pn = project_name();
22
23auto script_name;
24script_name = getenv("SCRIPT_NAME");
25if (script_name == "")
26	script_name = "http://localhost/cgi-bin/aegis.cgi";
27
28
29auto ps, cs;
30ps = project[project_name()].state;
31auto ph, when, n, max, href;
32
33auto t, month, year;
34if (count(arg) > 0)
35	t = mktime(arg[0]);
36else
37	t = now();
38month = 0 + strftime("%m", t);
39year = 0 + strftime("%Y", t);
40
41columns({width = 1000; });
42print("Content-Type: text/html");
43print("");
44print("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"");
45print("                      \"http://www.w3.org/TR/REC-html40/loose.dtd\">");
46
47print("<html><head>");
48print("<meta name=\"ROBOTS\" content=\"NOINDEX, NOFOLLOW\">");
49print("<meta name=\"GENERATOR\" content=\"" ## script_name ## "\">");
50print("<meta http-equiv=\"Content-Type\" "
51	## "content=\"text/html; charset=ISO-8859-1\">");
52print("<style type=\"text/css\"> "
53	## "tr.even-group { background-color: #CCCCCC; }"
54	## "body { background-color: white; }"
55	## "</style>");
56/*
57 * Netscape 4.x has numerous CSS bugs, two of which need mentioning.
58 * 1. If a style sheet is not present Netscape says 404 Not found, when
59 * it should silently ignore it.  2. Style sheets who's media is not
60 * "screen" will be ignored.  Fortunately we can use (2) to get around (1).
61 */
62print("<link rel=\"stylesheet\" type=\"text/css\" href=\"/aedefault.css\" "
63	## "media=\"all\">");
64auto stack, depth, bn;
65depth=0;
66stack[depth] = project[pn].state.name;
67while ("" != ( bn = project[stack[depth]].state.parent_name )) {
68  stack[++depth] = bn;
69}
70while ( depth >= 0) {
71    print("<link rel=\"stylesheet\" type=\"text/css\" href=\"/" ##
72      stack[depth--] ## ".css\" " ## "media=\"all\">");
73}
74print("<title>");
75print("Project " ## quote_html(pn) ## ", Change Histogram");
76print("</title><head><body><h1 align=center>");
77
78print("<a href=\"" ## script_name ## "\">Project</a>");
79auto long_project_name;
80auto prj_name_parts;
81prj_name_parts = split(pn, '.');
82href = script_name ## "?file@proj_menu+project@"
83	## quote_url(prj_name_parts[0]);
84long_project_name = "<a href=\"" ## href ## "\" >"
85	## quote_html(prj_name_parts[0]) ## "</a>";
86auto j;
87for (j = 1; j < count(prj_name_parts); j++)
88{
89    href ##= '.' ## prj_name_parts[j];
90    long_project_name ##= ".<a href=\"" ## href ## "\" >"
91    	## quote_html(prj_name_parts[j]) ## "</a>";
92};
93long_project_name = "&ldquo;" ## long_project_name ## "&rdquo;,<br>";
94/* HTTP limits lines to 510 characters */
95for (j in wrap(long_project_name, 510))
96    print(j);
97
98href = script_name ## "?file@proj_hstgm+project@" ## quote_url(pn);
99print("Change <a href=\"" ## href ## "\">Histogram</a><br>");
100print(strftime("%B", t));
101href = script_name ## "?file@proj_hstg2+project@" ## quote_url(pn)
102        ## "+" ## year;
103print("<a href=\"" ## href ## "\">" ## strftime("%Y", t) ## "</a>");
104print("</h1>");
105print("<div class=\"information\">");
106
107auto earliest_mday, latest_mday;
108
109auto bucket, mday, last_mday;
110bucket = {};
111for (ph in ps.branch.history)
112{
113	cs = ps.branch.change[ph.change_number];
114	when = cs.history[count(cs.history) - 1].when;
115	if (year != 0 + strftime("%Y", when))
116		continue;
117	if (month != 0 + strftime("%m", when))
118		continue;
119	mday = 0 + strftime("%d", when);
120	bucket[mday]++;
121}
122
123max = 1;
124for (mday in keys(bucket))
125{
126	n = 0 + bucket[mday];
127	if (n > max)
128		max = n;
129}
130max = 400. / max;
131
132last_mday = 28;
133for (n = 28; n < 32; ++n)
134{
135	when = mktime(strftime("1-%b-%Y 00:00:00", t));
136	when += (n - 1) * (24 * 60 * 60);
137	if (strftime("%m", when) + 0 != month)
138		break;
139	last_mday = n;
140}
141
142print("<table align=center>");
143print("<tr><th>Day</th><th>Count</th></tr>");
144for (mday = 1; mday <= last_mday; ++mday)
145{
146	n = 0 + bucket[mday];
147	print("<tr><td align=right>");
148	print(mday);
149	print("</td><td align=right>");
150	print(n);
151	print("</td><td>");
152	if (n > 0)
153	{
154		n = round(n * max);
155		if (n < 3)
156			n = 3;
157		href = script_name ## "?file@rect+" ## n ## "+12";
158		print("<img src=\"" ## href ## "\" width="##n## " height=12>");
159	}
160	print("</td></tr>");
161}
162
163print("</table>");
164print("</div>");
165
166print("<hr>");
167print("<p align=center class=\"navbar\">[");
168print("<a href=\"" ## script_name ## "\">Project List</a> |");
169href = script_name ## "?file@proj_menu+project@" ## quote_url(pn);
170print("<a href=\"" ## href ## "\">Project Menu</a> |");
171href = script_name ## "?file@changes+project@" ## quote_url(pn);
172print("<a href=\"" ## href ## "\">Change List</a> |");
173href = script_name ## "?file@proj_hstgm+project@" ## quote_url(pn);
174print("<a href=\"" ## href ## "\">Project Histogram</a> |");
175href = script_name ## "?file@proj_hstg2+project@" ## quote_url(pn)
176	## "+" ## year;
177print("<a href=\"" ## href ## "\">Year Histogram</a>");
178print("]</p>");
179
180print("<hr>");
181print("This page was generated " ## now() ## ".");
182print("</body></html>");
183