Annotation of loncom/interface/lonhtmlcommon.pm, revision 1.9
1.2 www 1: # The LearningOnline Network with CAPA
2: # a pile of common html routines
3: #
1.9 ! stredwic 4: # $Id: lonhtmlcommon.pm,v 1.8 2002/08/21 17:18:08 www 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";
1.9 ! stredwic 82:
! 83: $Str .= '</select>'."\n";
! 84:
! 85: return $Str;
! 86: }
! 87:
! 88: sub ProblemOptions {
! 89: my ($data, $page, $map, $formName)=@_;
! 90: my $Str = '';
! 91: $Str .= '<select name="';
! 92: $Str .= (($page)?$page:'').'ProblemSelect"';
! 93: if($formName) {
! 94: $Str .= ' onchange="document.'.$formName.'.submit()"';
! 95: }
! 96: $Str .= '>'."\n";
! 97:
! 98: my $selected = 0;
! 99: foreach my $sequence (split(':',$data->{'orderedSequences'})) {
! 100: if($data->{$sequence.':title'} eq $map || $map eq 'All Maps') {
! 101: foreach my $problem (split(':', $data->{$sequence.':problems'})) {
! 102: $Str .= '<option';
! 103: if($data->{$page.'ProblemSelect'} eq
! 104: $data->{$problem.':title'}) {
! 105: $Str .= ' selected';
! 106: $selected = 1;
! 107: }
! 108: $Str .= '>'.$data->{$problem.':title'}.'</option>'."\n";
! 109: }
! 110: }
! 111: }
! 112: $Str .= '<option';
! 113: if(!$selected) {
! 114: $Str .= ' selected';
! 115: }
! 116: $Str .= '>All Problems</option>'."\n";
! 117:
! 118: $Str .= '</select>'."\n";
! 119:
! 120: return $Str;
! 121: }
! 122:
! 123: sub PartOptions {
! 124: my ($data, $page, $parts, $formName)=@_;
! 125: my $Str = '';
! 126:
! 127: if(!defined($parts)) {
! 128: return '';
! 129: }
! 130:
! 131: $Str .= '<select name="';
! 132: $Str .= (($page)?$page:'').'PartSelect"';
! 133: if($formName) {
! 134: $Str .= ' onchange="document.'.$formName.'.submit()"';
! 135: }
! 136: $Str .= '>'."\n";
! 137:
! 138: my $selected = 0;
! 139: foreach my $part (@$parts) {
! 140: $Str .= '<option';
! 141: if($data->{$page.'PartSelect'} eq $part) {
! 142: $Str .= ' selected';
! 143: $selected = 1;
! 144: }
! 145: $Str .= '>'.$part.'</option>'."\n";
! 146: }
! 147: $Str .= '<option';
! 148: if(!$selected) {
! 149: $Str .= ' selected';
! 150: }
! 151: $Str .= '>All Parts</option>'."\n";
1.1 stredwic 152:
153: $Str .= '</select>'."\n";
154:
155: return $Str;
156: }
157:
158: sub StudentOptions {
1.4 stredwic 159: my ($cache, $students, $selectedName, $page, $formName)=@_;
1.1 stredwic 160:
161: my $Str = '';
1.4 stredwic 162: $Str .= '<select name="'.(($page)?$page:'').'Student"';
163: if($formName) {
164: $Str .= ' onchange="document.'.$formName.'.submit()"';
165: }
166: $Str .= '>'."\n";
1.1 stredwic 167:
168: my $selected=0;
169:
170: foreach (@$students) {
171: $Str .= '<option';
172: if($selectedName eq $_) {
173: $Str .= ' selected';
174: $selected = 1;
175: }
176: $Str .= '>';
177: $Str .= $cache->{$_.':fullname'};
178: $Str .= '</option>'."\n";
179: }
180:
181: $Str .= '<option';
1.3 stredwic 182: if($selectedName eq 'No Student Selected') {
183: $Str .= ' selected';
184: $selected = 1;
185: }
186: $Str .= '>No Student Selected</option>'."\n";
187:
188: $Str .= '<option';
1.1 stredwic 189: if(!$selected) {
190: $Str .= ' selected';
191: }
1.3 stredwic 192: $Str .= '>All Students</option>'."\n";
1.1 stredwic 193:
194: $Str .= '</select>'."\n";
195:
196: return $Str;
197: }
198:
199: sub StatusOptions {
200: my ($status, $formName)=@_;
201:
202: my $OpSel1 = '';
203: my $OpSel2 = '';
204: my $OpSel3 = '';
205:
206: if($status eq 'Any') { $OpSel3 = ' selected'; }
207: elsif($status eq 'Expired' ) { $OpSel2 = ' selected'; }
208: else { $OpSel1 = ' selected'; }
209:
210: my $Str = '';
211: $Str .= '<select name="Status"';
212: if(defined($formName) && $formName ne '') {
213: $Str .= ' onchange="document.'.$formName.'.submit()"';
214: }
215: $Str .= '>'."\n";
216: $Str .= '<option'.$OpSel1.'>Active</option>'."\n";
217: $Str .= '<option'.$OpSel2.'>Expired</option>'."\n";
218: $Str .= '<option'.$OpSel3.'>Any</option>'."\n";
219: $Str .= '</select>'."\n";
220: }
221:
1.5 stredwic 222: sub MultipleSectionSelect {
223: my ($sections,$selectedSections)=@_;
224:
225: my $Str = '';
1.7 stredwic 226: $Str .= '<select name="Section" multiple="true" size="4">'."\n";
1.5 stredwic 227:
228: foreach (@$sections) {
229: $Str .= '<option';
230: foreach my $selected (@$selectedSections) {
231: if($_ eq $selected) {
232: $Str .= ' selected=""';
233: }
234: }
235: $Str .= '>'.$_.'</option>'."\n";
236: }
237: $Str .= '</select>'."\n";
238:
239: return $Str;
240: }
241:
1.1 stredwic 242: sub Title {
243: my ($pageName)=@_;
244:
245: my $Str = '';
246:
247: $Str .= '<html><head><title>'.$pageName.'</title></head>'."\n";
1.8 www 248: $Str .= &Apache::loncommon::bodytag($pageName)."\n";
1.1 stredwic 249: $Str .= '<script>window.focus(); window.width=500;window.height=500;';
250: $Str .= '</script>'."\n";
251:
252: return $Str;
253: }
254:
255: =pod
256:
257: =item &CreateTableHeadings()
258:
259: This function generates the column headings for the chart.
260:
261: =over 4
262:
1.4 stredwic 263: Inputs: $CacheData, $keyID, $headings, $spacePadding
1.1 stredwic 264:
265: $CacheData: pointer to a hash tied to the cached data database
266:
1.4 stredwic 267: $keyID: a pointer to an array containing the names of the data
1.1 stredwic 268: held in a column and is used as part of a key into $CacheData
269:
270: $headings: The names of the headings for the student information
271:
272: $spacePadding: The spaces to go between columns
273:
274: Output: $Str
275:
276: $Str: A formatted string of the table column headings.
277:
278: =back
279:
280: =cut
281:
1.4 stredwic 282: sub CreateHeadings {
283: my ($data,$keyID,$headings,$displayString,$format)=@_;
1.1 stredwic 284: my $Str='';
1.4 stredwic 285: my $formatting = '';
1.1 stredwic 286:
287: for(my $index=0; $index<(scalar @$headings); $index++) {
1.4 stredwic 288: my $currentHeading=$headings->[$index];
289: if($format eq 'preformatted') {
290: my @dataLength=split(//,$currentHeading);
291: my $length=scalar @dataLength;
292: $formatting = (' 'x
293: ($data->{$keyID->[$index].':columnWidth'}-$length));
294: }
295: my $linkdata=$keyID->[$index];
296:
1.1 stredwic 297: my $tempString = $displayString;
298: $tempString =~ s/LINKDATA/$linkdata/;
1.4 stredwic 299: $tempString =~ s/DISPLAYDATA/$currentHeading/;
300: $tempString =~ s/FORMATTING/$formatting/;
301:
1.1 stredwic 302: $Str .= $tempString;
303: }
304:
305: return $Str;
306: }
307:
308: =pod
309:
310: =item &FormatStudentInformation()
311:
312: This function produces a formatted string of the student's information:
313: username, domain, section, full name, and PID.
314:
315: =over 4
316:
1.4 stredwic 317: Input: $cache, $name, $keyID, $spacePadding
1.1 stredwic 318:
319: $cache: This is a pointer to a hash that is tied to the cached data
320:
321: $name: The name and domain of the current student in name:domain format
322:
1.4 stredwic 323: $keyID: A pointer to an array holding the names used to
1.1 stredwic 324:
325: remove data from the hash. They represent the name of the data to be removed.
326:
327: $spacePadding: Extra spaces that represent the space between columns
328:
329: Output: $Str
330:
331: $Str: Formatted string.
332:
333: =back
334:
335: =cut
336:
337: sub FormatStudentInformation {
1.4 stredwic 338: my ($data,$name,$keyID,$displayString,$format)=@_;
1.1 stredwic 339: my $Str='';
1.4 stredwic 340: my $currentColumn;
341:
342: for(my $index=0; $index<(scalar @$keyID); $index++) {
343: $currentColumn=$data->{$name.':'.$keyID->[$index]};
1.1 stredwic 344:
1.4 stredwic 345: if($format eq 'preformatted') {
346: my @dataLength=split(//,$currentColumn);
347: my $length=scalar @dataLength;
348: $currentColumn.= (' 'x
349: ($data->{$keyID->[$index].':columnWidth'}-$length));
1.1 stredwic 350: }
351:
1.4 stredwic 352: my $tempString = $displayString;
353: $tempString =~ s/DISPLAYDATA/$currentColumn/;
354:
355: $Str .= $tempString;
1.1 stredwic 356: }
357:
358: return $Str;
1.7 stredwic 359: }
360:
361: # Create progress
362: sub Create_PrgWin {
363: my ($r, $title, $heading)=@_;
364: $r->print('<script>'.
365: "popwin=open(\'\',\'popwin\',\'width=400,height=100\');".
366: "popwin.document.writeln(\'<html><body bgcolor=\"#88DDFF\">".
367: "<title>$title</title>".
368: "<h4>$heading</h4>".
369: "<form name=popremain>".
370: "<input type=text size=35 name=remaining value=Starting></form>".
371: "</body></html>\');".
372: "popwin.document.close();".
373: "</script>");
374:
375: $r->rflush();
376: }
377:
378: # update progress
379: sub Update_PrgWin {
380: my ($displayString,$r)=@_;
381: $r->print('<script>popwin.document.popremain.remaining.value="'.
382: $displayString.'";</script>');
383: $r->rflush();
384: }
385:
386: # close Progress Line
387: sub Close_PrgWin {
388: my ($r)=@_;
389: $r->print('<script>popwin.close()</script>'."\n");
390: $r->rflush();
1.1 stredwic 391: }
392:
393: 1;
394: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>