Annotation of loncom/interface/lonsyllabus.pm, revision 1.20
1.1 www 1: # The LearningOnline Network
2: # Syllabus
3: #
1.20 ! www 4: # $Id: lonsyllabus.pm,v 1.19 2003/05/21 20:10:53 www Exp $
1.1 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:
29: package Apache::lonsyllabus;
30:
31: use strict;
32: use Apache::Constants qw(:common);
33: use Apache::loncommon;
34: use Apache::lonnet;
1.5 www 35: use Apache::lontexconvert;
1.11 www 36: use Apache::lonfeedback;
1.19 www 37: use Apache::lonannounce;
1.1 www 38:
39: sub handler {
40: my $r = shift;
41: $r->content_type('text/html');
42: $r->send_http_header;
43: return OK if $r->header_only;
44:
45: # ------------------------------------------------------------ Print the screen
46: $r->print(<<ENDDOCUMENT);
47: <html>
48: <head>
49: <title>The LearningOnline Network with CAPA</title>
50: ENDDOCUMENT
1.2 www 51: my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.3 www 52: # Is this even a course?
1.7 www 53: my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom);
54: if ($homeserver eq 'no_host') {
1.15 www 55: $r->print('</head><body>No syllabus available</body></html>');
1.3 www 56: return OK;
57: }
1.5 www 58: # --------------------------------------------------------- The syllabus fields
59: my %syllabusfields=(
60: 'aaa_instructorinfo' => 'Instructor Information',
61: 'bbb_description' => 'Course Description',
62: 'ccc_prereq' => 'Prerequisites',
1.7 www 63: 'cdc_classhours' => 'Class Hours',
1.5 www 64: 'ddd_officehours' => 'Office Hours',
65: 'eee_helproom' => 'Helproom Hours',
1.7 www 66: 'efe_projectinfo' => 'Project Information',
1.5 www 67: 'fff_examinfo' => 'Exam Information',
1.7 www 68: 'fgf_deadlines' => 'Deadlines',
1.5 www 69: 'ggg_grading' => 'Grading Information',
1.7 www 70: 'hhh_readings' => 'Readings',
71: 'iii_coursepack' => 'Coursepack',
72: 'jjj_weblinks' => 'Web Links',
1.9 www 73: 'kkk_textbook' => 'Textbook',
74: 'lll_includeurl' => 'URLs To Include in Syllabus');
1.5 www 75:
1.14 www 76: # ------------------------------------------------------------ Get query string
77: &Apache::loncommon::get_unprocessed_cgi
78: ($ENV{'QUERY_STRING'},['forcestudent','register']);
79: # ----------------------------------------------------- Force menu registration
80: my $addentries='';
81: if ($ENV{'form.register'}) {
82: $addentries=' onLoad="'.&Apache::lonmenu::loadevents().
83: '" onUnload="'.&Apache::lonmenu::unloadevents().'"';
84: $r->print(&Apache::lonmenu::registerurl(1));
85: }
1.6 www 86: # --------------------------------------------------------------- Force Student
87: my $forcestudent='';
88: if ($ENV{'form.forcestudent'}) { $forcestudent='student'; };
1.5 www 89:
1.3 www 90: # ------------------------------------- There is such a course, get environment
1.2 www 91: my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.14 www 92: $r->print('</head>'.&Apache::loncommon::bodytag
1.15 www 93: ("Syllabus",$forcestudent,$addentries,'',$cdom,$ENV{'form.register'}));
1.2 www 94: $r->print('<h1>'.$courseenv{'description'}.'</h1><h3>'.
95: $Apache::lonnet::domaindescription{$cdom}.'</h3>');
1.19 www 96: # -------------------------------------------------------------- Announcements?
97: $r->print(&Apache::lonannounce::showday(time,2,
98: &Apache::lonannounce::readcalendar($cdom.'_'.$cnum)));
1.17 www 99: # -------------------------------------------------------- Get course personnel
100: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
101: $r->print('<table border="2">');
1.18 www 102: foreach (sort keys %coursepersonnel) {
1.17 www 103: $r->print('<tr><td>'.$_.'</td><td>');
104: foreach (split(/\,/,$coursepersonnel{$_})) {
105: my ($puname,$pudom)=split(/\:/,$_);
106: $r->print(' '.&Apache::loncommon::aboutmewrapper(
107: &Apache::loncommon::plainname($puname,
108: $pudom),$puname,$pudom));
109: }
110: $r->print('</td></tr>');
111: }
112: $r->print('</table>');
113: # ---------------------------------------------------------- Load syllabus info
1.4 www 114: my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
1.5 www 115: my $allowed=0;
1.4 www 116:
1.2 www 117: # This handler might be called anonymously ...
118: # ----------------------------------------------------- Only if not public call
119: if ($ENV{'user.environment'}) {
1.1 www 120: # does this user have privileges to post, etc?
1.2 www 121: if ($ENV{'request.course.id'}) {
122: $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
1.6 www 123: if ($forcestudent) { $allowed=0; }
1.2 www 124: }
1.6 www 125: if ($allowed) {
1.12 www 126: $r->print('<p>'.
1.16 www 127: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').'</p><p>This syllabus can be publicly viewed at <tt>http://'.
1.10 www 128: $Apache::lonnet::hostname{$homeserver}.$r->uri.'</tt>'.
129: &Apache::loncommon::help_open_topic('Syllabus_ExtLink').'</p>'.
130: '<p><a href="'.$r->uri.'?forcestudent=1">Show Student View</a>'.
131: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').
132: '</p>');
1.6 www 133: }
1.5 www 134: if (($allowed) && ($ENV{'form.storesyl'})) {
135: foreach (keys %syllabusfields) {
136: my $field=$ENV{'form.'.$_};
137: $field=~s/\s+$//s;
1.11 www 138: $field=&Apache::lonfeedback::clear_out_html($field,1);
1.7 www 139: $syllabus{$_}=$field;
1.9 www 140: if ($_ eq 'lll_includeurl') { # clean up included URLs
141: my $field='';
142: foreach (split(/\n/,$syllabus{$_})) {
143: my $url=$_;
144: # get rid of leading and trailing spaces
145: $url=~s/^\s+//;
146: $url=~s/\s+$//;
147: if ($url=~/^http\:\/\/([^\/]+)\/(.+)$/) {
148: my $remainder=$2;
149: # remove the hostname from internal URLs
150: foreach (keys %Apache::lonnet::hostname) {
151: if ($1=~/$Apache::lonnet::hostname{$_}/i) {
152: $url=$remainder;
153: }
154: }
155: }
156: # norm internal URLs
157: unless ($url=~/^http\:/) {
158: $url=&Apache::lonnet::clutter($url);
159: }
160: # re-assemble field
161: if ($url) {
162: $field.=$url."\n";
163: }
164: }
165: $syllabus{$_}=$field;
166: }
1.5 www 167: }
168: $syllabus{'uploaded.domain'}=$ENV{'user.domain'};
169: $syllabus{'uploaded.name'}=$ENV{'user.name'};
170: $syllabus{'uploaded.lastmodified'}=time;
171: &Apache::lonnet::put('syllabus',\%syllabus,$cdom,$cnum);
172: }
1.4 www 173: }
174: # ---------------------------------------------------------------- Get syllabus
1.5 www 175: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.8 www 176: my $lastmod=$syllabus{'uploaded.lastmodified'};
177: $lastmod=($lastmod?localtime($lastmod):'never');
178:
1.4 www 179: $r->print('<table><tr><td>Uploaded:</td><td>'.
1.7 www 180: &Apache::loncommon::aboutmewrapper(
1.4 www 181: &Apache::loncommon::plainname($syllabus{'uploaded.name'},
1.7 www 182: $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
1.4 www 183: $syllabus{'uploaded.domain'}).
1.8 www 184: '</td></tr><tr><td>Last updated:</td><td>'.
185: $lastmod.
1.5 www 186: '</td></tr></table><p>');
187: if ($allowed) {
188: $r->print('<form method="post">');
189: }
190: foreach (sort keys %syllabusfields) {
191: if (($syllabus{$_}) || ($allowed)) {
192: my $message=$syllabus{$_};
1.9 www 193: if ($_ eq 'lll_includeurl') { # this is the "included" field
194: my $urls=$message;
195: $message='';
196: foreach my $filelink (split(/\n/,$urls)) {
197: my $output='';
198: # embed style?
199: my ($curfext)=($filelink=~/\.([^\.]+)$/);
200: my $embstyle=&Apache::loncommon::fileembstyle($curfext);
1.12 www 201: if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {
1.9 www 202: # make ssi call and remove everything but the body contents
1.13 www 203: $output=&Apache::lonnet::ssi_body($filelink);
1.9 www 204: } elsif ($embstyle eq 'img') {
205: # embed as an image
206: $output='<img src="'.$filelink.'" />';
207: }
208: $message.='<p>'.$output.'</p>';
209: }
210: if ($allowed) {
211: $r->print('<h3>'.$syllabusfields{$_}.
1.10 www 212: &Apache::loncommon::help_open_topic('Syllabus_URLs').'</h3>'.
213: '<p><a href="'.$r->uri.'?forcestudent=1">Show Student View</a>'.
214: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
1.9 www 215: } else {
216: $r->print($message);
217: }
218: } else {
219: $message=~s/\n/\<br \/\>/g;
220: $message
1.20 ! www 221: =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.9 www 222: $message=&Apache::lontexconvert::msgtexconverted($message);
223: $r->print('<h3>'.$syllabusfields{$_}.'</h3><blockquote>'.
1.5 www 224: $message.'</blockquote>');
1.9 www 225: }
1.5 www 226: if ($allowed) {
227: $r->print('<br /><textarea cols="80" rows="6" name="'.$_.'">'.
228: $syllabus{$_}.
229: '</textarea><input type="submit" name="storesyl" value="Store" />');
230: }
231: }
232: }
233: if ($allowed) {
234: $r->print('</form>');
235: }
236: $r->print('</p>');
1.4 www 237: } else {
238: $r->print('<p>No syllabus information provided.</p>');
1.1 www 239: }
240: $r->print('</body></html>');
241: return OK;
242: }
243:
244: 1;
245: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>