Annotation of loncom/interface/lonsyllabus.pm, revision 1.54
1.1 www 1: # The LearningOnline Network
2: # Syllabus
3: #
1.54 ! albertel 4: # $Id: lonsyllabus.pm,v 1.53 2006/08/01 13:55:07 albertel 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.23 www 38: use Apache::lonlocal;
1.32 www 39: use Apache::lonhtmlcommon;
1.38 www 40: use Apache::lonspeller();
1.54 ! albertel 41: use HTML::Entities();
1.1 www 42:
43: sub handler {
44: my $r = shift;
1.46 www 45: &Apache::loncommon::content_type($r,'text/html');
46: $r->send_http_header;
47: return OK if $r->header_only;
1.45 www 48:
1.46 www 49: my $target=$env{'form.grade_target'};
1.45 www 50: # --------------------------------------------------- Get course info from URL
51: my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.46 www 52: # ------------------------------------------------------------ Get query string
53: &Apache::loncommon::get_unprocessed_cgi
1.47 www 54: ($ENV{'QUERY_STRING'},['forcestudent','register','forceedit','wrapperdisplay']);
1.45 www 55: # ----------------------------------------------------- Is this even a course?
56: my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom);
57: if ($homeserver eq 'no_host') {
58: &Apache::loncommon::content_type($r,'text/html');
59: $r->send_http_header;
1.49 albertel 60: &Apache::loncommon::simple_error_page($r,'No syllabus available',
61: 'No syllabus available');
1.45 www 62: return OK;
63: }
64: # ------------------------------------- There is such a course, get environment
65: my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.46 www 66:
1.1 www 67: # ------------------------------------------------------------ Print the screen
1.49 albertel 68:
69: my $rss_link =
70: &Apache::lonrss::rss_link('http://'.$ENV{'HTTP_HOST'}.'/public/'.$cdom.'/'.$cnum.'/Course_Announcements.rss');
71:
72: if ($target eq 'tex') {
1.40 albertel 73: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.28 sakharuk 74: }
1.46 www 75: # -------------------------------------------------- Let's see who handles this
1.47 www 76: my $externalsyllabus=$courseenv{'externalsyllabus'};
1.49 albertel 77:
1.46 www 78: if ($externalsyllabus=~/\w/) {
1.50 albertel 79:
1.47 www 80: if ($env{'form.wrapperdisplay'} eq 'menu') {
1.50 albertel 81: $r->print(&Apache::lonwrapper::simple_menu());
82: } else {
83: $r->print(&Apache::lonwrapper::wrapper("/public/$cdom/$cnum/syllabus?wrapperdisplay=menu",
84: $externalsyllabus));
85: }
86: return OK;
1.47 www 87: }
1.42 www 88:
1.46 www 89: # ------------------------------ The buck stops here: internal syllabus display
1.5 www 90: # --------------------------------------------------------- The syllabus fields
1.23 www 91: my %syllabusfields=&Apache::lonlocal::texthash(
1.5 www 92: 'aaa_instructorinfo' => 'Instructor Information',
93: 'bbb_description' => 'Course Description',
94: 'ccc_prereq' => 'Prerequisites',
1.7 www 95: 'cdc_classhours' => 'Class Hours',
1.5 www 96: 'ddd_officehours' => 'Office Hours',
97: 'eee_helproom' => 'Helproom Hours',
1.7 www 98: 'efe_projectinfo' => 'Project Information',
1.5 www 99: 'fff_examinfo' => 'Exam Information',
1.7 www 100: 'fgf_deadlines' => 'Deadlines',
1.5 www 101: 'ggg_grading' => 'Grading Information',
1.7 www 102: 'hhh_readings' => 'Readings',
103: 'iii_coursepack' => 'Coursepack',
104: 'jjj_weblinks' => 'Web Links',
1.9 www 105: 'kkk_textbook' => 'Textbook',
106: 'lll_includeurl' => 'URLs To Include in Syllabus');
1.6 www 107: # --------------------------------------------------------------- Force Student
108: my $forcestudent='';
1.40 albertel 109: if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.27 www 110: my $forceedit='';
1.40 albertel 111: if ($env{'form.forceedit'}) { $forceedit='edit'; }
1.5 www 112:
1.45 www 113: # ----------------------------------------------------------------- Make header
1.28 sakharuk 114: if ($target ne 'tex') {
1.49 albertel 115: my $start_page =
116: &Apache::loncommon::start_page("Syllabus", $rss_link,
117: {'function' => $forcestudent,
118: 'domain' => $cdom,
119: 'force_register' =>
120: $env{'form.register'},});
121:
122: $r->print($start_page.'<h1>'.$courseenv{'description'}.'</h1><h3>'.
1.28 sakharuk 123: $Apache::lonnet::domaindescription{$cdom}.'</h3>');
124: } else {
1.29 sakharuk 125: $r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
1.28 sakharuk 126: $Apache::lonnet::domaindescription{$cdom}.'}\\\\');
127: }
1.19 www 128: # -------------------------------------------------------------- Announcements?
1.49 albertel 129: my $day = &Apache::lonannounce::showday(time,2,
130: &Apache::lonannounce::readcalendar($cdom.'_'.$cnum));
1.35 sakharuk 131: if ($target ne 'tex') {
1.52 www 132: $r->print($day. &Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit));
1.35 sakharuk 133: } else {
1.49 albertel 134: $r->print(&Apache::lonxml::xmlparse($r,'tex',$day));
1.35 sakharuk 135: }
1.49 albertel 136:
1.17 www 137: # -------------------------------------------------------- Get course personnel
138: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.28 sakharuk 139: if ($target ne 'tex') {
140: $r->print('<table border="2">');
141: } else {
1.37 sakharuk 142: $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
1.28 sakharuk 143: }
1.36 sakharuk 144: foreach my $element (sort keys %coursepersonnel) {
1.28 sakharuk 145: if ($target ne 'tex') {
1.36 sakharuk 146: $r->print('<tr><td>'.$element.'</td><td>');
1.28 sakharuk 147: } else {
1.36 sakharuk 148: $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & ');
1.28 sakharuk 149: }
1.36 sakharuk 150: foreach (split(/\,/,$coursepersonnel{$element})) {
1.17 www 151: my ($puname,$pudom)=split(/\:/,$_);
1.28 sakharuk 152: if ($target ne 'tex') {
153: $r->print(' '.&Apache::loncommon::aboutmewrapper(
154: &Apache::loncommon::plainname($puname,
155: $pudom),$puname,$pudom));
156: } else {
157: $r->print(' '.&Apache::loncommon::plainname($puname,
158: $pudom).' ');
159: }
1.17 www 160: }
1.28 sakharuk 161: if ($target ne 'tex') {
162: $r->print('</td></tr>');
163: } else {
164: $r->print('\\\\ \hline');
165: }
166: }
167: if ($target ne 'tex') {
168: $r->print('</table>');
169: } else {
170: $r->print('\end{tabular}\\\\');
1.17 www 171: }
172: # ---------------------------------------------------------- Load syllabus info
1.4 www 173: my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
1.5 www 174: my $allowed=0;
1.27 www 175: my $privileged=0;
1.4 www 176:
1.2 www 177: # This handler might be called anonymously ...
178: # ----------------------------------------------------- Only if not public call
1.40 albertel 179: if ($env{'user.environment'}) {
1.1 www 180: # does this user have privileges to post, etc?
1.53 albertel 181: if ($env{'request.course.id'}
182: && $cdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}
183: && $cnum eq $env{'course.'.$env{'request.course.id'}.'.num'}) {
1.40 albertel 184: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.27 www 185: $privileged=$allowed;
186: if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
187: $forcestudent='student';
188: }
1.30 sakharuk 189: if ($forcestudent or $target eq 'tex') { $allowed=0; }
1.2 www 190: }
1.6 www 191: if ($allowed) {
1.12 www 192: $r->print('<p>'.
1.23 www 193: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').'</p><p>'.&mt('This syllabus can be publicly viewed at')
194: .' <tt>http://'.
1.10 www 195: $Apache::lonnet::hostname{$homeserver}.$r->uri.'</tt>'.
196: &Apache::loncommon::help_open_topic('Syllabus_ExtLink').'</p>'.
1.47 www 197: '<p>'.&mt('You can specify an external URL as Syllabus in the [_1].','<a href="/adm/parmset?action=crsenv">'.&mt('Course Parameters').'</a>').'</p>'.
1.27 www 198: '<p><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.
199: &mt('Show Public View').'</font></a>'.
1.10 www 200: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').
201: '</p>');
1.27 www 202: } elsif ($privileged) {
1.28 sakharuk 203: if ($target ne 'tex') {
204: $r->print('<p><a href="'.$r->uri.'?forceedit=1"><font size="+1">'.
205: &mt('Edit').'</font></a>');
206: }
1.6 www 207: }
1.40 albertel 208: if (($allowed) && ($env{'form.storesyl'})) {
1.5 www 209: foreach (keys %syllabusfields) {
1.40 albertel 210: my $field=$env{'form.'.$_};
1.33 www 211: chomp($field);
1.5 www 212: $field=~s/\s+$//s;
1.33 www 213: $field=~s/^\s+//s;
214: $field=~s/\<br\s*\/*\>$//s;
215: $field=&Apache::lonfeedback::clear_out_html($field,1);
1.7 www 216: $syllabus{$_}=$field;
1.9 www 217: if ($_ eq 'lll_includeurl') { # clean up included URLs
218: my $field='';
219: foreach (split(/\n/,$syllabus{$_})) {
220: my $url=$_;
221: # get rid of leading and trailing spaces
222: $url=~s/^\s+//;
223: $url=~s/\s+$//;
224: if ($url=~/^http\:\/\/([^\/]+)\/(.+)$/) {
225: my $remainder=$2;
226: # remove the hostname from internal URLs
227: foreach (keys %Apache::lonnet::hostname) {
228: if ($1=~/$Apache::lonnet::hostname{$_}/i) {
229: $url=$remainder;
230: }
231: }
232: }
233: # norm internal URLs
234: unless ($url=~/^http\:/) {
235: $url=&Apache::lonnet::clutter($url);
236: }
237: # re-assemble field
238: if ($url) {
239: $field.=$url."\n";
240: }
241: }
242: $syllabus{$_}=$field;
243: }
1.5 www 244: }
1.40 albertel 245: $syllabus{'uploaded.domain'}=$env{'user.domain'};
246: $syllabus{'uploaded.name'}=$env{'user.name'};
1.5 www 247: $syllabus{'uploaded.lastmodified'}=time;
248: &Apache::lonnet::put('syllabus',\%syllabus,$cdom,$cnum);
249: }
1.4 www 250: }
251: # ---------------------------------------------------------------- Get syllabus
1.5 www 252: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.8 www 253: my $lastmod=$syllabus{'uploaded.lastmodified'};
1.25 www 254: $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
1.26 albertel 255: my $who = &Apache::loncommon::aboutmewrapper(
256: &Apache::loncommon::plainname($syllabus{'uploaded.name'},
1.7 www 257: $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
1.26 albertel 258: $syllabus{'uploaded.domain'});
1.28 sakharuk 259: if ($target ne 'tex') {
260: $r->print('<table><tr><td>'.&mt('Last updated').':</td><td>'.
261: $lastmod.'</td><td>'.&mt('by').' '.$who.
262: '</td></tr></table><p>');
263: } else {
264: $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.&mt('by').'\\\\ '.
265: &Apache::loncommon::plainname($syllabus{'uploaded.name'},
266: $syllabus{'uploaded.domain'}).'\\\\');
267: }
1.5 www 268: if ($allowed) {
1.27 www 269: $r->print('<form method="post">'.
270: '<input type="hidden" name="forceedit" value="edit" />');
1.5 www 271: }
1.33 www 272: my @htmlids=();
1.5 www 273: foreach (sort keys %syllabusfields) {
1.32 www 274: if (($syllabus{$_}=~/\w/) || ($allowed)) {
1.5 www 275: my $message=$syllabus{$_};
1.9 www 276: if ($_ eq 'lll_includeurl') { # this is the "included" field
277: my $urls=$message;
278: $message='';
279: foreach my $filelink (split(/\n/,$urls)) {
280: my $output='';
281: # embed style?
282: my ($curfext)=($filelink=~/\.([^\.]+)$/);
283: my $embstyle=&Apache::loncommon::fileembstyle($curfext);
1.12 www 284: if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {
1.9 www 285: # make ssi call and remove everything but the body contents
1.13 www 286: $output=&Apache::lonnet::ssi_body($filelink);
1.9 www 287: } elsif ($embstyle eq 'img') {
288: # embed as an image
289: $output='<img src="'.$filelink.'" />';
290: }
1.34 sakharuk 291: if ($target ne 'tex') {
292: $message.='<p>'.$output.'</p>';
293: } else {
294: $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
295: }
1.9 www 296: }
297: if ($allowed) {
298: $r->print('<h3>'.$syllabusfields{$_}.
1.10 www 299: &Apache::loncommon::help_open_topic('Syllabus_URLs').'</h3>'.
1.27 www 300: '<p><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.&mt('Show Public View').'</font></a>'.
1.10 www 301: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
1.9 www 302: } else {
303: $r->print($message);
304: }
305: } else {
1.41 albertel 306: &Apache::lonfeedback::newline_to_br(\$message);
1.9 www 307: $message
1.20 www 308: =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.38 www 309: if ($allowed) {
310: $message=&Apache::lonspeller::markeduptext($message);
311: }
1.9 www 312: $message=&Apache::lontexconvert::msgtexconverted($message);
1.28 sakharuk 313: if ($target ne 'tex') {
314: $r->print('<h3>'.$syllabusfields{$_}.'</h3><blockquote>'.
315: $message.'</blockquote>');
316: } else {
317: $r->print('\\\\\textbf{'.$syllabusfields{$_}.'}\\\\'.
1.31 sakharuk 318: &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
1.28 sakharuk 319: }
1.33 www 320: push @htmlids,$_;
1.9 www 321: }
1.5 www 322: if ($allowed) {
1.33 www 323: $r->print(
324: '<br /><textarea cols="80" rows="12" name="'.$_.'" id="'.$_.'">'.
1.54 ! albertel 325: &HTML::Entities::encode($syllabus{$_},'"&<>').
1.33 www 326: '</textarea> <input type="submit" name="storesyl" value="Store" />');
1.5 www 327: }
328: }
329: }
330: if ($allowed) {
1.32 www 331: $r->print('</form>'.
1.33 www 332: &Apache::lonhtmlcommon::htmlareaselectactive(@htmlids));
1.5 www 333: }
1.28 sakharuk 334: if ($target ne 'tex') {$r->print('</p>');} else {$r->print('\\\\');}
1.4 www 335: } else {
1.36 sakharuk 336: if ($target ne 'tex') {$r->print('<p>');} else {$r->print('\par ');}
337: $r->print('No syllabus information provided.');
338: if ($target ne 'tex') {$r->print('</p>');}
1.1 www 339: }
1.48 albertel 340: if ($target ne 'tex') {
341: $r->print(&Apache::loncommon::end_page());
342: } else {
343: $r->print('\end{document}');
344: }
1.1 www 345: return OK;
346: }
347:
348: 1;
349: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>