Annotation of loncom/interface/lonhtmlcommon.pm, revision 1.8
1.2 www 1: # The LearningOnline Network with CAPA
2: # a pile of common html routines
3: #
1.8 ! www 4: # $Id: lonhtmlcommon.pm,v 1.7 2002/08/13 00:37:18 stredwic Exp $
1.2 www 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
1.1 stredwic 29: package Apache::lonhtmlcommon;
30:
31: use strict;
32:
1.6 stredwic 33: sub AscendOrderOptions {
34: my ($order, $page, $formName)=@_;
35:
36: my $OpSel1 = '';
37: my $OpSel2 = '';
38:
39: if($order eq 'Ascending') {
40: $OpSel1 = ' selected';
41: } else {
42: $OpSel2 = ' selected';
43: }
44:
45: my $Str = '';
46: $Str .= '<select name="'.(($page)?$page:'').'Ascend"';
47: if($formName) {
48: $Str .= ' onchange="document.'.$formName.'.submit()"';
49: }
50: $Str .= '>'."\n";
51: $Str .= '<option'.$OpSel1.'>Ascending</option>'."\n".
52: '<option'.$OpSel2.'>Descending</option>'."\n";
53: $Str .= '</select>'."\n";
54:
55: return $Str;
56: }
57:
1.1 stredwic 58: sub MapOptions {
1.6 stredwic 59: my ($data, $page, $formName)=@_;
1.1 stredwic 60: my $Str = '';
61: $Str .= '<select name="';
1.6 stredwic 62: $Str .= (($page)?$page:'').'Maps"';
63: if($formName) {
64: $Str .= ' onchange="document.'.$formName.'.submit()"';
65: }
66: $Str .= '>'."\n";
1.1 stredwic 67:
68: my $selected = 0;
69: foreach my $sequence (split(':',$data->{'orderedSequences'})) {
70: $Str .= '<option';
1.7 stredwic 71: if($data->{$page.'Maps'} eq $data->{$sequence.':title'}) {
1.1 stredwic 72: $Str .= ' selected';
73: $selected = 1;
74: }
75: $Str .= '>'.$data->{$sequence.':title'}.'</option>'."\n";
76: }
77: $Str .= '<option';
78: if(!$selected) {
79: $Str .= ' selected';
80: }
81: $Str .= '>All Maps</option>'."\n";
82:
83: $Str .= '</select>'."\n";
84:
85: return $Str;
86: }
87:
88: sub StudentOptions {
1.4 stredwic 89: my ($cache, $students, $selectedName, $page, $formName)=@_;
1.1 stredwic 90:
91: my $Str = '';
1.4 stredwic 92: $Str .= '<select name="'.(($page)?$page:'').'Student"';
93: if($formName) {
94: $Str .= ' onchange="document.'.$formName.'.submit()"';
95: }
96: $Str .= '>'."\n";
1.1 stredwic 97:
98: my $selected=0;
99:
100: foreach (@$students) {
101: $Str .= '<option';
102: if($selectedName eq $_) {
103: $Str .= ' selected';
104: $selected = 1;
105: }
106: $Str .= '>';
107: $Str .= $cache->{$_.':fullname'};
108: $Str .= '</option>'."\n";
109: }
110:
111: $Str .= '<option';
1.3 stredwic 112: if($selectedName eq 'No Student Selected') {
113: $Str .= ' selected';
114: $selected = 1;
115: }
116: $Str .= '>No Student Selected</option>'."\n";
117:
118: $Str .= '<option';
1.1 stredwic 119: if(!$selected) {
120: $Str .= ' selected';
121: }
1.3 stredwic 122: $Str .= '>All Students</option>'."\n";
1.1 stredwic 123:
124: $Str .= '</select>'."\n";
125:
126: return $Str;
127: }
128:
129: sub StatusOptions {
130: my ($status, $formName)=@_;
131:
132: my $OpSel1 = '';
133: my $OpSel2 = '';
134: my $OpSel3 = '';
135:
136: if($status eq 'Any') { $OpSel3 = ' selected'; }
137: elsif($status eq 'Expired' ) { $OpSel2 = ' selected'; }
138: else { $OpSel1 = ' selected'; }
139:
140: my $Str = '';
141: $Str .= '<select name="Status"';
142: if(defined($formName) && $formName ne '') {
143: $Str .= ' onchange="document.'.$formName.'.submit()"';
144: }
145: $Str .= '>'."\n";
146: $Str .= '<option'.$OpSel1.'>Active</option>'."\n";
147: $Str .= '<option'.$OpSel2.'>Expired</option>'."\n";
148: $Str .= '<option'.$OpSel3.'>Any</option>'."\n";
149: $Str .= '</select>'."\n";
150: }
151:
1.5 stredwic 152: sub MultipleSectionSelect {
153: my ($sections,$selectedSections)=@_;
154:
155: my $Str = '';
1.7 stredwic 156: $Str .= '<select name="Section" multiple="true" size="4">'."\n";
1.5 stredwic 157:
158: foreach (@$sections) {
159: $Str .= '<option';
160: foreach my $selected (@$selectedSections) {
161: if($_ eq $selected) {
162: $Str .= ' selected=""';
163: }
164: }
165: $Str .= '>'.$_.'</option>'."\n";
166: }
167: $Str .= '</select>'."\n";
168:
169: return $Str;
170: }
171:
1.1 stredwic 172: sub Title {
173: my ($pageName)=@_;
174:
175: my $Str = '';
176:
177: $Str .= '<html><head><title>'.$pageName.'</title></head>'."\n";
1.8 ! www 178: $Str .= &Apache::loncommon::bodytag($pageName)."\n";
1.1 stredwic 179: $Str .= '<script>window.focus(); window.width=500;window.height=500;';
180: $Str .= '</script>'."\n";
181:
182: return $Str;
183: }
184:
185: =pod
186:
187: =item &CreateTableHeadings()
188:
189: This function generates the column headings for the chart.
190:
191: =over 4
192:
1.4 stredwic 193: Inputs: $CacheData, $keyID, $headings, $spacePadding
1.1 stredwic 194:
195: $CacheData: pointer to a hash tied to the cached data database
196:
1.4 stredwic 197: $keyID: a pointer to an array containing the names of the data
1.1 stredwic 198: held in a column and is used as part of a key into $CacheData
199:
200: $headings: The names of the headings for the student information
201:
202: $spacePadding: The spaces to go between columns
203:
204: Output: $Str
205:
206: $Str: A formatted string of the table column headings.
207:
208: =back
209:
210: =cut
211:
1.4 stredwic 212: sub CreateHeadings {
213: my ($data,$keyID,$headings,$displayString,$format)=@_;
1.1 stredwic 214: my $Str='';
1.4 stredwic 215: my $formatting = '';
1.1 stredwic 216:
217: for(my $index=0; $index<(scalar @$headings); $index++) {
1.4 stredwic 218: my $currentHeading=$headings->[$index];
219: if($format eq 'preformatted') {
220: my @dataLength=split(//,$currentHeading);
221: my $length=scalar @dataLength;
222: $formatting = (' 'x
223: ($data->{$keyID->[$index].':columnWidth'}-$length));
224: }
225: my $linkdata=$keyID->[$index];
226:
1.1 stredwic 227: my $tempString = $displayString;
228: $tempString =~ s/LINKDATA/$linkdata/;
1.4 stredwic 229: $tempString =~ s/DISPLAYDATA/$currentHeading/;
230: $tempString =~ s/FORMATTING/$formatting/;
231:
1.1 stredwic 232: $Str .= $tempString;
233: }
234:
235: return $Str;
236: }
237:
238: =pod
239:
240: =item &FormatStudentInformation()
241:
242: This function produces a formatted string of the student's information:
243: username, domain, section, full name, and PID.
244:
245: =over 4
246:
1.4 stredwic 247: Input: $cache, $name, $keyID, $spacePadding
1.1 stredwic 248:
249: $cache: This is a pointer to a hash that is tied to the cached data
250:
251: $name: The name and domain of the current student in name:domain format
252:
1.4 stredwic 253: $keyID: A pointer to an array holding the names used to
1.1 stredwic 254:
255: remove data from the hash. They represent the name of the data to be removed.
256:
257: $spacePadding: Extra spaces that represent the space between columns
258:
259: Output: $Str
260:
261: $Str: Formatted string.
262:
263: =back
264:
265: =cut
266:
267: sub FormatStudentInformation {
1.4 stredwic 268: my ($data,$name,$keyID,$displayString,$format)=@_;
1.1 stredwic 269: my $Str='';
1.4 stredwic 270: my $currentColumn;
271:
272: for(my $index=0; $index<(scalar @$keyID); $index++) {
273: $currentColumn=$data->{$name.':'.$keyID->[$index]};
1.1 stredwic 274:
1.4 stredwic 275: if($format eq 'preformatted') {
276: my @dataLength=split(//,$currentColumn);
277: my $length=scalar @dataLength;
278: $currentColumn.= (' 'x
279: ($data->{$keyID->[$index].':columnWidth'}-$length));
1.1 stredwic 280: }
281:
1.4 stredwic 282: my $tempString = $displayString;
283: $tempString =~ s/DISPLAYDATA/$currentColumn/;
284:
285: $Str .= $tempString;
1.1 stredwic 286: }
287:
288: return $Str;
1.7 stredwic 289: }
290:
291: # Create progress
292: sub Create_PrgWin {
293: my ($r, $title, $heading)=@_;
294: $r->print('<script>'.
295: "popwin=open(\'\',\'popwin\',\'width=400,height=100\');".
296: "popwin.document.writeln(\'<html><body bgcolor=\"#88DDFF\">".
297: "<title>$title</title>".
298: "<h4>$heading</h4>".
299: "<form name=popremain>".
300: "<input type=text size=35 name=remaining value=Starting></form>".
301: "</body></html>\');".
302: "popwin.document.close();".
303: "</script>");
304:
305: $r->rflush();
306: }
307:
308: # update progress
309: sub Update_PrgWin {
310: my ($displayString,$r)=@_;
311: $r->print('<script>popwin.document.popremain.remaining.value="'.
312: $displayString.'";</script>');
313: $r->rflush();
314: }
315:
316: # close Progress Line
317: sub Close_PrgWin {
318: my ($r)=@_;
319: $r->print('<script>popwin.close()</script>'."\n");
320: $r->rflush();
1.1 stredwic 321: }
322:
323: 1;
324: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>