Annotation of loncom/interface/lonsyllabus.pm, revision 1.106.2.1
1.1 www 1: # The LearningOnline Network
2: # Syllabus
3: #
1.106.2.1! faziophi 4: # $Id: lonsyllabus.pm,v 1.106 2010/01/31 06:03:55 faziophi 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;
1.70 amueller 32: use Apache::lontemplate;
1.1 www 33: use Apache::Constants qw(:common);
34: use Apache::loncommon;
35: use Apache::lonnet;
1.5 www 36: use Apache::lontexconvert;
1.11 www 37: use Apache::lonfeedback;
1.19 www 38: use Apache::lonannounce;
1.23 www 39: use Apache::lonlocal;
1.32 www 40: use Apache::lonhtmlcommon;
1.38 www 41: use Apache::lonspeller();
1.54 albertel 42: use HTML::Entities();
1.106.2.1! faziophi 43: use Digest::MD5 qw(md5_hex);
! 44: use Storable qw(freeze thaw);
! 45:
! 46: # These are strings representing types of fields
! 47: # that will used to parse/display a field correctly
! 48: use constant {
! 49: TYPE_TEXT_HTML => 'html', #<-- default
! 50: TYPE_TEXT_PLAIN => 'text',
! 51: TYPE_URL_INCLUDE => 'include-url',
! 52: };
1.1 www 53:
54: sub handler {
55: my $r = shift;
1.46 www 56: &Apache::loncommon::content_type($r,'text/html');
57: $r->send_http_header;
58: return OK if $r->header_only;
1.45 www 59:
1.46 www 60: my $target=$env{'form.grade_target'};
1.45 www 61: # --------------------------------------------------- Get course info from URL
62: my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.46 www 63: # ------------------------------------------------------------ Get query string
64: &Apache::loncommon::get_unprocessed_cgi
1.106.2.1! faziophi 65: ($ENV{'QUERY_STRING'},['delete', 'field', 'forcestudent','register','forceedit','forceflush','wrapperdisplay']);
1.45 www 66: # ----------------------------------------------------- Is this even a course?
67: my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom);
68: if ($homeserver eq 'no_host') {
69: &Apache::loncommon::content_type($r,'text/html');
70: $r->send_http_header;
1.106 faziophi 71: &Apache::loncommon::simple_error_page($r,'No syllabus available',
1.91 amueller 72: 'No syllabus available');
1.45 www 73: return OK;
74: }
75: # ------------------------------------- There is such a course, get environment
76: my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.46 www 77:
1.1 www 78: # ------------------------------------------------------------ Print the screen
1.49 albertel 79: if ($target eq 'tex') {
1.91 amueller 80: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.86 bisitz 81: }
1.106.2.1! faziophi 82:
1.46 www 83: # -------------------------------------------------- Let's see who handles this
1.47 www 84: my $externalsyllabus=$courseenv{'externalsyllabus'};
1.46 www 85: if ($externalsyllabus=~/\w/) {
1.47 www 86: if ($env{'form.wrapperdisplay'} eq 'menu') {
1.91 amueller 87: $r->print(&Apache::lonwrapper::simple_menu());
1.86 bisitz 88: } else {
1.91 amueller 89: $r->print(&Apache::lonwrapper::wrapper("/public/$cdom/$cnum/syllabus?wrapperdisplay=menu",
90: $externalsyllabus));
1.50 albertel 91: }
92: return OK;
1.90 amueller 93: }
1.42 www 94:
1.106.2.1! faziophi 95: # --------------------------------------------------------- The old syllabus fields
1.23 www 96: my %syllabusfields=&Apache::lonlocal::texthash(
1.5 www 97: 'aaa_instructorinfo' => 'Instructor Information',
98: 'bbb_description' => 'Course Description',
99: 'ccc_prereq' => 'Prerequisites',
1.7 www 100: 'cdc_classhours' => 'Class Hours',
1.5 www 101: 'ddd_officehours' => 'Office Hours',
102: 'eee_helproom' => 'Helproom Hours',
1.7 www 103: 'efe_projectinfo' => 'Project Information',
1.5 www 104: 'fff_examinfo' => 'Exam Information',
1.7 www 105: 'fgf_deadlines' => 'Deadlines',
1.5 www 106: 'ggg_grading' => 'Grading Information',
1.7 www 107: 'hhh_readings' => 'Readings',
108: 'iii_coursepack' => 'Coursepack',
109: 'jjj_weblinks' => 'Web Links',
1.9 www 110: 'kkk_textbook' => 'Textbook',
111: 'lll_includeurl' => 'URLs To Include in Syllabus');
1.106.2.1! faziophi 112:
1.6 www 113: # --------------------------------------------------------------- Force Student
114: my $forcestudent='';
1.40 albertel 115: if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.27 www 116: my $forceedit='';
1.40 albertel 117: if ($env{'form.forceedit'}) { $forceedit='edit'; }
1.86 bisitz 118:
119: # ----------------------------------------------------------------- Make header
1.28 sakharuk 120: if ($target ne 'tex') {
1.91 amueller 121: my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
1.65 raeburn 122: my $js;
123: if ($env{'form.backto'} eq 'coursecatalog') {
124: $js .= <<"ENDSCRIPT";
125:
126: <script type="text/javascript">
127: function ToCatalog(caller) {
128: numidx = getIndexByName('coursenum');
1.90 amueller 129: if (numidx > -1) {
130: if (caller != 'details') {
131: document.backtocat.elements[numidx].value = '';
132: }
1.65 raeburn 133: }
134: document.backtocat.submit();
135: }
136:
137: function getIndexByName(item) {
138: for (var i=0;i<document.backtocat.elements.length;i++) {
139: if (document.backtocat.elements[i].name == item) {
140: return i;
141: }
142: }
143: return -1;
144: }
145:
146: </script>
147:
148: ENDSCRIPT
149: }
1.91 amueller 150: my $start_page =
151: &Apache::loncommon::start_page("Syllabus", $rss_link.$js,
1.97 amueller 152: {'function' => undef,
1.91 amueller 153: 'domain' => $cdom,
154: 'force_register' =>
155: $env{'form.register'},});
1.49 albertel 156:
1.91 amueller 157: $r->print($start_page);
1.65 raeburn 158: if ($env{'form.backto'} eq 'coursecatalog') {
159: &Apache::lonhtmlcommon::clear_breadcrumbs();
160: &Apache::lonhtmlcommon::add_breadcrumb
1.90 amueller 161: ({href=>"javascript:ToCatalog()",
1.100 bisitz 162: text=>"Course/Community Catalog"});
1.65 raeburn 163: if ($env{'form.coursenum'} ne '') {
164: &Apache::lonhtmlcommon::add_breadcrumb
1.90 amueller 165: ({href=>"javascript:ToCatalog('details')",
166: text=>"Course details"});
1.65 raeburn 167: }
168: &Apache::lonhtmlcommon::add_breadcrumb
1.90 amueller 169: ({href=>$r->uri,
170: text=>"Course syllabus"});
1.65 raeburn 171: $r->print(&Apache::lonhtmlcommon::breadcrumbs());
1.86 bisitz 172: }
1.17 www 173: }
174: # ---------------------------------------------------------- Load syllabus info
1.106.2.1! faziophi 175: my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum); # load db
! 176: my $allowed=0; # can we edit this page?
1.27 www 177: my $privileged=0;
1.106.2.1! faziophi 178: my %data;
! 179: if ($env{'form.forceflush'}) {
! 180: delete $syllabus{'data.fields'};
! 181: &Apache::lonnet::del('syllabus', ['data.fields'], $cdom, $cnum);
! 182: delete $syllabus{'properties.v2_conflict'};
! 183: &Apache::lonnet::del('syllabus', ['properties.v2_conflict'], $cdom, $cnum);
! 184: delete $syllabus{'properties.v2_conflict_fail'};
! 185: &Apache::lonnet::del('syllabus', ['properties.v2_conflict_fail'], $cdom, $cnum);
! 186: delete $syllabus{'properties.last_modified'};
! 187: &Apache::lonnet::del('syllabus', ['properties.last_modified'], $cdom, $cnum);
! 188: delete $syllabus{'properties.v2_converted'};
! 189: &Apache::lonnet::del('syllabus', ['properties.v2_converted'], $cdom, $cnum);
! 190: delete $syllabus{'data.old_new_map'};
! 191: &Apache::lonnet::del('syllabus', ['data.old_new_map'], $cdom, $cnum);
! 192: %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum); # load db
! 193: $r->print("Flushed syllabus DB file.<br />");
! 194: $r->print("Syllabus conflict: ".$syllabus{'properties.v2_conflict'}."<br />");
! 195: }
! 196: $r->print("Existing fields: ".$syllabus{'data.fields'}."<br />");
! 197: $r->print("Old-new map: ".$syllabus{'data.old_new_map'}."<br />");
! 198: if (!exists($syllabus{'data.fields'})) {
! 199: # convert existing 2.x data to new DB fields
! 200: # which become new primary data source for document
! 201: %data = %{convert_from_v2($r, \%syllabus, \%syllabusfields, 0)};
! 202: $r->print("New fields order: ".$data{'data.fields'}."<br />");
! 203: &Apache::lonnet::put('syllabus',\%data,$cdom,$cnum);
! 204: } elsif ( !exists($syllabus{'properties.v2_converted'}) &&
! 205: exists($syllabus{'uploaded.lastmodified'}) &&
! 206: exists($syllabus{'properties.last_modified'}) &&
! 207: ($syllabus{'uploaded.lastmodified'} !=
! 208: $syllabus{'properties.last_modified'})) {
! 209: # if the document has been saved in 3.x and later edited in
! 210: # 2.x, reconvert the existing document, with extra warning
! 211: %data = %{convert_from_v2($r, \%syllabus, \%syllabusfields, 1)};
! 212: delete $data{'properties.v2_converted'};
! 213: &Apache::lonnet::del('syllabus', ['properties.v2_converted'], $cdom, $cnum);
! 214: $data{'properties.v2_conflict'} = 1;
! 215: &Apache::lonnet::put('syllabus',\%data,$cdom,$cnum);
! 216: } else {
! 217: %data = %syllabus;
! 218:
! 219: }
1.4 www 220:
1.2 www 221: # ----------------------------------------------------- Only if not public call
1.106.2.1! faziophi 222: if ($env{'user.environment'}) { # does this user have privileges to post, etc?
1.90 amueller 223: if ($env{'request.course.id'}
1.91 amueller 224: && $cdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}
225: && $cnum eq $env{'course.'.$env{'request.course.id'}.'.num'}) {
1.90 amueller 226: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.91 amueller 227: $privileged=$allowed;
1.106.2.1! faziophi 228: if (($data{'uploaded.lastmodified'}) && (!$forceedit)) {
1.91 amueller 229: $forcestudent='student';
230: }
1.90 amueller 231: if ($forcestudent or $target eq 'tex') { $allowed=0; }
232: }
1.98 amueller 233: #store what the user typed in
1.106.2.1! faziophi 234: my @fields = @{thaw($data{'data.fields'})};
! 235: if (($allowed) && ($env{'form.delete'})) {
! 236: my $field = $env{'form.delete'};
! 237: chomp($field);
! 238: #allow only numbers, underscores
! 239: $field=~s/[^0-9_]//g;
! 240: #check if the field exists
! 241: #do not delete if file in v2 conversion mode
! 242: if (exists($data{'data.field.'.$field}) &&
! 243: !exists($data{'properties.v2_converted'})) {
! 244: $r->print("Field can be deleted.<br />");
! 245: }
! 246: }
1.90 amueller 247: if (($allowed) && ($env{'form.storesyl'})) {
1.106.2.1! faziophi 248: foreach my $syl_field (@fields) {
1.90 amueller 249: my $field=$env{'form.'.$syl_field};
1.106.2.1! faziophi 250: my $type;
! 251: my %field_hash;
! 252: # only update a field if it already exists!
! 253: if (exists($data{'data.field.'.$syl_field})) {
! 254: $r->print("Creating/updated field ".$syl_field."<br />");
! 255: %field_hash = exists($data{'data.field.'.$syl_field}) ?
! 256: %{thaw($data{'data.field.'.$syl_field})} :
! 257: ();
! 258: $type = exists($field_hash{type}) ? $field_hash{type} : TYPE_TEXT_HTML;
! 259: chomp($field);
! 260: $field=~s/\s+$//s;
! 261: $field=~s/^\s+//s;
! 262: $field=~s/\<br\s*\/*\>$//s;
! 263: $field=&Apache::lonfeedback::clear_out_html($field,1);
! 264: $field_hash{content}=$field;
! 265: if ($type eq TYPE_URL_INCLUDE) { # clean up included URLs
! 266: my $field='';
! 267: foreach my $value (split(/\n/,$field_hash{content})) {
! 268: my $url=$value;
! 269: # get rid of leading and trailing spaces
! 270: $url=~s/^\s+//;
! 271: $url=~s/\s+$//;
! 272: if ($url=~m|^https?\://([^/]+)/(.+)$|) {
! 273: my $host = $1;
! 274: my $remainder=$2;
! 275: # remove the hostname from internal URLs
! 276: my $hostname = &Apache::lonnet::hostname($host);
! 277: my %all_hostnames = &Apache::lonnet::all_hostnames();
! 278: foreach my $possible_host (keys(%all_hostnames)) {
! 279: if ($possible_host =~ /\Q$hostname\E/i) {
! 280: $url=$remainder;
! 281: }
! 282: }
! 283: }
! 284: # norm internal URLs
! 285: unless ($url=~/^https?\:/) {
! 286: $url=&Apache::lonnet::clutter($url);
! 287: }
! 288: # re-assemble field
! 289: if ($url) {
! 290: $field.=$url."\n";
! 291: }
! 292: }
! 293: $field_hash{content}=$field;
! 294: $field_hash{type}=TYPE_URL_INCLUDE;
! 295: }
! 296: $data{'data.field.'.$syl_field} = freeze(\%field_hash);
! 297: }
! 298: }
! 299: $data{'uploaded.domain'}=$env{'user.domain'};
! 300: $data{'uploaded.name'}=$env{'user.name'};
! 301: my $time = $^T;
! 302: $data{'uploaded.lastmodified'}=$time;
! 303: $data{'properties.last_modified'}=$time;
! 304: delete $data{'properties.v2_converted'};
! 305: delete $data{'properties.v2_conflict'};
! 306: delete $data{'properties.v2_conflict_fail'};
! 307: &Apache::lonnet::del('syllabus', ['properties.v2_converted',
! 308: 'properties.v2_conflict', 'properties.v2_conflict_fail'], $cdom, $cnum);
! 309:
! 310: #2.x compatibility: write to old fields with new mapped fields
! 311: my %old_new_map = %{thaw($data{'data.old_new_map'})};
! 312: foreach my $old_field (keys(%old_new_map)) {
! 313: $r->print("Looking for: ".$old_field." at ".$old_new_map{$old_field}."<br />");
! 314: if (exists($data{'data.field.'.$old_new_map{$old_field}})) {
! 315: $r->print("updating old field ".$old_field."<br />");
! 316: my %new_field = %{thaw($data{'data.field.'.$old_new_map{$old_field}})};
! 317: $data{$old_field} = $new_field{content};
! 318: }
1.90 amueller 319: }
1.106.2.1! faziophi 320:
! 321: &Apache::lonnet::put('syllabus',\%data,$cdom,$cnum);
1.90 amueller 322: }
1.4 www 323: }
1.85 bisitz 324:
1.93 bisitz 325: #--------Functions
1.94 droeschl 326: if( ($allowed || $privileged) && $target ne 'tex') {
327: my $functions=&Apache::lonhtmlcommon::start_funclist();
328: if ($allowed) {
1.97 amueller 329: #if you have the register flag, keep it
330: if($env{'form.register'} == 1) {
331: $functions.=&Apache::lonhtmlcommon::add_item_funclist(
1.99 amueller 332: '<a href="'.$r->uri.'?forcestudent=1&register=1">'
1.97 amueller 333: .&mt('Show Public View').'</a>'
334: .&Apache::loncommon::help_open_topic(
335: 'Uploaded_Templates_PublicView'));
336: } else {
337: $functions.=&Apache::lonhtmlcommon::add_item_funclist(
1.94 droeschl 338: '<a href="'.$r->uri.'?forcestudent=1">'
339: .&mt('Show Public View').'</a>'
340: .&Apache::loncommon::help_open_topic(
341: 'Uploaded_Templates_PublicView'));
1.97 amueller 342: }
1.93 bisitz 343: } elsif ($privileged) {
1.97 amueller 344: if($env{'form.register'} == 1) {
345: $functions.=&Apache::lonhtmlcommon::add_item_funclist(
1.99 amueller 346: '<a href="'.$r->uri.'?forceedit=1&register=1">'
1.97 amueller 347: .&mt('Edit').'</a>');
348: } else {
349: $functions.=&Apache::lonhtmlcommon::add_item_funclist(
1.94 droeschl 350: '<a href="'.$r->uri.'?forceedit=1">'
351: .&mt('Edit').'</a>');
1.97 amueller 352: }
1.93 bisitz 353: }
1.94 droeschl 354:
1.93 bisitz 355: $functions.=&Apache::lonhtmlcommon::end_funclist();
356: $r->print(&Apache::loncommon::head_subbox($functions));
357: }
358:
1.94 droeschl 359: #---------------------Print External URL Syllabus Info and Help Text
1.90 amueller 360: if( ($allowed) && ($target ne 'tex') ) {
1.91 amueller 361: my $protocol = $Apache::lonnet::protocol{$homeserver};
362: $protocol = 'http' if ($protocol ne 'https');
1.85 bisitz 363: $r->print('<p class="LC_info">'
364: .&mt('This syllabus can be publicly viewed at [_1]'
365: ,'<tt>'.$protocol.'://'.&Apache::lonnet::hostname($homeserver).$r->uri.'</tt>')
366: .' '.&Apache::loncommon::help_open_topic('Syllabus_ExtLink')
367: .'</p>'
368: .'<p class="LC_info">'
1.96 raeburn 369: .&mt('Instead of using this template you can specify an external URL as Syllabus in the [_1]Course Configuration[_2].'
1.99 amueller 370: ,'<a href="/adm/courseprefs?actions=courseinfo&phase=display">','</a>')
1.85 bisitz 371: .'</p>'
372: );
1.94 droeschl 373: #-Print Help Text
374: $r->print(&Apache::loncommon::help_open_topic(
375: 'Uploaded_Templates_TextBoxes',
376: &mt('Help with filling in text boxes')));
1.90 amueller 377: }
1.85 bisitz 378:
1.88 amueller 379: #----------Print last update
1.90 amueller 380: my $lastmod=$syllabus{'uploaded.lastmodified'};
381: $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
382: my $who = &Apache::loncommon::aboutmewrapper(
383: &Apache::loncommon::plainname($syllabus{'uploaded.name'},
384: $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
385: $syllabus{'uploaded.domain'});
386: if ($target ne 'tex') {
1.91 amueller 387: $r->print('<div class="LC_info">'.&mt('Last updated').': '.
388: $lastmod . ' '.
389: ($who ? &mt('by').' '.$who
1.89 bisitz 390: : '' ) .
1.88 amueller 391: '</div>' );
1.89 bisitz 392:
1.90 amueller 393: } else {
1.91 amueller 394: $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.
395: ($who? &mt('by').'\\\\ '.
396: &Apache::loncommon::plainname($syllabus{'uploaded.name'},$syllabus{'uploaded.domain'})
397: :'')
398: .'\\\\');
1.90 amueller 399: }
1.106.2.1! faziophi 400: if ($allowed && $data{'properties.v2_converted'} == 1) {
! 401: $r->print("<em>This document was created with LON-CAPA 2.x. Modifying it may cause it to not display correctly on older servers.</em><br/>");
! 402: }
! 403: if ($allowed && $data{'properties.v2_conflict'} == 1) {
! 404: $r->print("<em>This document was saved with LON-CAPA 3.x, then further edited in LON-CAPA 2.x.</em><br/>");
! 405: if ($data{'properties.v2_conflict_fail'} == 1) {
! 406: $r->print("<em>Some fields in LON-CAPA 2.x no longer have an equivalent in LON-CAPA 3.x. These fields were appended; some fields may be duplicated or not match.</em><br />");
! 407: } else {
! 408: $r->print("<em>These changes were automatically transferred to LON-CAPA 3.x</em>");
! 409: }
! 410: }
! 411:
1.80 neumanie 412: #----------------------------Print Headtitle
1.90 amueller 413: if ($target ne 'tex') {
1.91 amueller 414: $r->print('<h1>'.$courseenv{'description'}.'</h1>');
415: $r->print('<h3>'. &Apache::lonnet::domain($cdom,'description').'</h3>');
1.90 amueller 416: } else {
1.91 amueller 417: $r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
418: &Apache::lonnet::domain($cdom,'description').'}\\\\');
1.90 amueller 419: }
1.106.2.1! faziophi 420:
1.80 neumanie 421: # -------------------------------------------------------- Get course personnel
422: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
423: if ($target ne 'tex') {
1.91 amueller 424: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1.80 neumanie 425: } else {
1.91 amueller 426: $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
1.80 neumanie 427: }
428: my @personnel=sort(keys(%coursepersonnel));
429: my $lastpers=$personnel[$#personnel];
430: foreach my $element (@personnel) {
1.91 amueller 431: if ($target ne 'tex') {
432: $r->print(&Apache::lonhtmlcommon::row_title($element));
433: } else {
434: $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & ');
435: }
1.80 neumanie 436: foreach (split(/\,/,$coursepersonnel{$element})) {
1.91 amueller 437: my ($puname,$pudom)=split(/\:/,$_);
438: if ($target ne 'tex') {
1.80 neumanie 439: my $courseperson = &Apache::loncommon::plainname($puname,$pudom);
440: if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
441: ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
1.91 amueller 442: $r->print(' '.$courseperson);
1.80 neumanie 443: } else {
444: $r->print(' '.&Apache::loncommon::aboutmewrapper($courseperson,
445: $puname,$pudom));
446: }
1.91 amueller 447: } else {
448: $r->print(' '.&Apache::loncommon::plainname($puname,
1.80 neumanie 449: $pudom).' ');
1.91 amueller 450: }
451: }
452: if ($target ne 'tex') {
1.80 neumanie 453: my $lastclose=$element eq $lastpers?1:0;
454: $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
1.91 amueller 455: } else {
456: $r->print('\\\\ \hline');
457: }
1.80 neumanie 458: }
459: if ($target ne 'tex') {
1.91 amueller 460: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1.80 neumanie 461: } else {
1.91 amueller 462: $r->print('\end{tabular}\\\\');
1.80 neumanie 463: }
1.79 neumanie 464: # -------------------------------------------------------------- Announcements?
465: my $day = &Apache::lonannounce::showday(time,2,
1.91 amueller 466: &Apache::lonannounce::readcalendar($cdom.'_'.$cnum));
1.80 neumanie 467: if ($target ne 'tex') {
1.91 amueller 468: if ($allowed) {
1.92 bisitz 469: &Apache::lontemplate::print_start_template($r,'RSS Feeds and Blogs','LC_Box');
1.91 amueller 470: $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit));
471: my $editurl= &Apache::lonnet::absolute_url().'/adm/'.$cdom.'/'.$cnum.'/_rss.html';
472: $r->print( '<a href="'.$editurl.'">'.&mt('New RSS Feed or Blog').'</a>');
473: &Apache::lontemplate::print_end_template($r);
474: } elsif (&Apache::lonrss::advertisefeeds($cnum,$cdom) ne '') {
1.92 bisitz 475: &Apache::lontemplate::print_start_template($r,'RSS Feeds and Blogs','LC_Box');
1.91 amueller 476: $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit));
477: &Apache::lontemplate::print_end_template($r);
478: }
1.86 bisitz 479:
1.79 neumanie 480: } else {
1.91 amueller 481: $r->print(&Apache::lonxml::xmlparse($r,'tex',$day));
1.86 bisitz 482: }
1.106.2.1! faziophi 483:
1.79 neumanie 484: # ---------------------------------------------------------------- Get syllabus
1.86 bisitz 485: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.90 amueller 486: if ($allowed) {
1.95 bisitz 487: $r->print('<form method="post" action="">'.
1.91 amueller 488: '<input type="hidden" name="forceedit" value="edit" />');
1.90 amueller 489: }
490: my @htmlids=();
1.106 faziophi 491: my $url_include_handler = sub {
1.106.2.1! faziophi 492: my ($r, $field, $json_ref, $group, $target, $allowed) = @_;
! 493: my $message = $json_ref->{items}{$field}{content};
! 494: my $title = $json_ref->{items}{$field}{title};
! 495: my $urls = $message;
1.106 faziophi 496: foreach my $filelink (split(/\n/,$urls)) {
497: my $output='';
498: # embed style?
499: my ($curfext)=($filelink=~/\.([^\.]+)$/);
500: my $embstyle=&Apache::loncommon::fileembstyle($curfext);
501: if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {# make ssi call and remove everything but the body contents
502: $output=&Apache::lonnet::ssi_body($filelink);
503: } elsif ($embstyle eq 'img') {# embed as an image
504: $output='<img src="'.$filelink.'" />';
505: }
506: if ($output ne '') {
1.106.2.1! faziophi 507: $message='';
1.106 faziophi 508: if ($target ne 'tex') {
509: $message.='<p>'.$output.'</p>';
510: } else {
511: $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
512: }
513: }
514: }
515: if ($allowed) {
516: &Apache::lonfeedback::newline_to_br(\$urls);
1.106.2.1! faziophi 517: &Apache::lontemplate::print_start_template($r,$title.
1.106 faziophi 518: &Apache::loncommon::help_open_topic('Syllabus_URLs'),'LC_Box');
519: $r->print($urls);
520: $r->print("<br /><div>");
1.106.2.1! faziophi 521: &Apache::lontemplate::print_textarea_template($r, $message,
1.106 faziophi 522: $field, Apache::lontemplate->RICH_TEXT_ALWAYS_OFF);
523: &Apache::lontemplate::print_saveall_template($r);
524: $r->print("</div>");
525: &Apache::lontemplate::print_end_template($r);
1.86 bisitz 526:
1.106 faziophi 527: } else {
528: $r->print($message);
529: }
530: };
1.106.2.1! faziophi 531: my %custom_hash = ( TYPE_URL_INCLUDE() => $url_include_handler );
! 532: @htmlids = &print_template_new_fields($r, \%data,
! 533: $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_hash);
1.90 amueller 534: if ($allowed) {
1.91 amueller 535: $r->print('</form>'.
536: &Apache::lonhtmlcommon::htmlareaselectactive(@htmlids));
1.90 amueller 537: }
1.4 www 538: } else {
1.91 amueller 539: if ($target ne 'tex') {$r->print('<p>');} else {$r->print('\par ');}
540: $r->print(&mt('No syllabus information provided.'));
541: if ($target ne 'tex') {$r->print('</p>');}
1.1 www 542: }
1.86 bisitz 543: if ($target ne 'tex') {
1.65 raeburn 544: if ($env{'form.backto'} eq 'coursecatalog') {
545: $r->print('<form name="backtocat" method="post" action="/adm/coursecatalog">'.
1.66 raeburn 546: &Apache::lonhtmlcommon::echo_form_input(['backto','courseid']).
1.65 raeburn 547: '</form>');
548: }
1.91 amueller 549: $r->print(&Apache::loncommon::end_page());
1.48 albertel 550: } else {
1.91 amueller 551: $r->print('\end{document}');
1.48 albertel 552: }
1.1 www 553: return OK;
1.86 bisitz 554: }
1.1 www 555:
1.106.2.1! faziophi 556: sub print_template_new_fields {
! 557: my ($r, $data_ref, $target, $allowed, $default_rich_text, $custom_handlers_ref, $group) = @_;
! 558: my @html_ids = ();
! 559: my %data = %{$data_ref};
! 560: my @fields = @{thaw($data{'data.fields'})};
! 561: my %custom_handlers = %{$custom_handlers_ref};
! 562:
! 563: foreach my $key (@fields) {
! 564: my %field = %{thaw($data{'data.field.'.$key})};
! 565: my $title = $field{title};
! 566: my $raw_message = $field{content};
! 567: my $type = $field{type};
! 568: my $message = $raw_message if (($raw_message=~/\w/) || ($allowed));
! 569: if ((%custom_handlers) && exists($custom_handlers{$type})) {
! 570: #$custom_handlers{$type}->($r, $field, $json_ref, $group, $target, $allowed);
! 571: } else {
! 572: if (($raw_message=~/\w/) || ($allowed)) {
! 573: if (!&Apache::lonfeedback::contains_block_html($message)) {
! 574: &Apache::lonfeedback::newline_to_br(\$message);
! 575: } else {
! 576: $message = &Apache::lonfeedback::tidy_html($message);
! 577: }
! 578: $message=&Apache::lonhtmlcommon::raw_href_to_link($message);
! 579: if ($allowed) {
! 580: $message=&Apache::lonspeller::markeduptext($message);
! 581: }
! 582: $message=&Apache::lontexconvert::msgtexconverted($message);
! 583: if ($target ne 'tex') {
! 584: #output of syllabusfields will be generated here.
! 585: &Apache::lontemplate::print_start_template($r,$title,'LC_Box');
! 586: $r->print($message);
! 587: if ($allowed) {
! 588: $r->print("<br /><div>");
! 589: &Apache::lontemplate::print_textarea_template($r, $raw_message,
! 590: $key, $default_rich_text);
! 591: &Apache::lontemplate::print_saveall_template($r);
! 592: if (!exists($data{'properties.v2_converted'})) {
! 593: $r->print("<a href='?delete=$key&forceedit=1'>Delete</a>");
! 594: }
! 595: $r->print("</div>");
! 596: }
! 597: &Apache::lontemplate::print_end_template($r);
! 598: } else {
! 599: my $safeinit;
! 600: $r->print(&Apache::lonxml::xmlparse($r,'tex','<h3>'.$title.'</h3>'));
! 601: $r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
! 602: }
! 603: push(@html_ids,"hello");
! 604: }
! 605: }
! 606: }
! 607:
! 608: return @html_ids;
! 609: }
! 610:
! 611: sub convert_from_v2 {
! 612: my ($r, $data_ref, $fields_ref, $conflict) = @_;
! 613: my %data = %{$data_ref};
! 614: my %fields = %{$fields_ref};
! 615: my @fields_order = (!$conflict) ? () : @{thaw($data{'data.fields'})};
! 616: my %old_new_map = (!$conflict) ? () : %{thaw($data{'data.old_new_map'})};
! 617: my $repeat_int = 0; #ensure fields with created timestamp are unique
! 618: foreach my $element (sort(keys(%fields))) {
! 619: my %new_element = ();
! 620: my $title = $fields{$element};
! 621: my $title_hash = time."_".$$;
! 622: if (exists($data{'data.field.'.$title_hash})) {
! 623: $title_hash .= "_".$repeat_int++;
! 624: }
! 625: my $content = $data{$element};
! 626: $new_element{title} = $title;
! 627: $new_element{content} = $content;
! 628: if ($element eq 'lll_includeurl') {
! 629: $new_element{type} = TYPE_URL_INCLUDE;
! 630: } else {
! 631: $new_element{type} = TYPE_TEXT_HTML;
! 632: }
! 633: if (!$conflict) {
! 634: $r->print("Creating new field with ID: ".$title_hash."<br />");
! 635: $data{'data.field.'.$title_hash} = freeze(\%new_element);
! 636: $old_new_map{$element} = $title_hash;
! 637: push(@fields_order, $title_hash);
! 638: } else {
! 639: if (exists($old_new_map{$element})) {
! 640: $r->print("Transferring old field ".$element." to new ID: ".$old_new_map{$element}."<br />");
! 641: if (exists($data{'data.field.'.$old_new_map{$element}})) {
! 642: my %new_field = %{thaw($data{'data.field.'.$old_new_map{$element}})};
! 643: $new_field{content} = $content;
! 644: $data{'data.field.'.$old_new_map{$element}} = freeze(\%new_field);
! 645: }
! 646: } else {
! 647: $data{'data.field.'.$title_hash} = freeze(\%new_element);
! 648: $old_new_map{$element} = $title_hash;
! 649: $data{'properties.v2_conflict_fail'} = 1;
! 650: push(@fields_order, $title_hash);
! 651: }
! 652: }
! 653: }
! 654: $data{'data.fields'} = freeze(\@fields_order);
! 655: $data{'data.old_new_map'} = freeze(\%old_new_map);
! 656: $data{'properties.last_modified'} = time;
! 657: $data{'properties.v2_converted'} = 1;
! 658: $data{'properties.type'} = 'syllabus';
! 659:
! 660: return \%data;
! 661: }
! 662:
1.1 www 663: 1;
664: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>