File:
[LON-CAPA] /
loncom /
interface /
lonsyllabus.pm
Revision
1.106.2.3:
download - view:
text,
annotated -
select for diffs
Mon Feb 15 20:28:51 2010 UTC (14 years, 7 months ago) by
faziophi
Branches:
bz6209
Diff to branchpoint 1.106:
preferred,
unified
Work-in-progress commit for bug 6209.
Features the beginnings of a jQuery-based interface that meshes
with the old interface for the time being. There are a lot of things
to be prettied and improved, but this is a good stopping place for now.
1: # The LearningOnline Network
2: # Syllabus
3: #
4: # $Id: lonsyllabus.pm,v 1.106.2.3 2010/02/15 20:28:51 faziophi Exp $
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::lontemplate;
33: use Apache::Constants qw(:common);
34: use Apache::loncommon;
35: use Apache::lonnet;
36: use Apache::lontexconvert;
37: use Apache::lonfeedback;
38: use Apache::lonannounce;
39: use Apache::lonlocal;
40: use Apache::lonhtmlcommon;
41: use Apache::lonspeller();
42: use HTML::Entities();
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: };
53:
54: sub handler {
55: my $r = shift;
56: &Apache::loncommon::content_type($r,'text/html');
57: $r->send_http_header;
58: return OK if $r->header_only;
59:
60: my $target=$env{'form.grade_target'};
61: # --------------------------------------------------- Get course info from URL
62: my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
63: # ------------------------------------------------------------ Get query string
64: &Apache::loncommon::get_unprocessed_cgi
65: ($ENV{'QUERY_STRING'},['delete', 'rename', 'field', 'forcestudent','register','forceedit','forceflush','wrapperdisplay']);
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;
71: &Apache::loncommon::simple_error_page($r,'No syllabus available',
72: 'No syllabus available');
73: return OK;
74: }
75: # ------------------------------------- There is such a course, get environment
76: my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
77:
78: # ------------------------------------------------------------ Print the screen
79: if ($target eq 'tex') {
80: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
81: }
82:
83: # -------------------------------------------------- Let's see who handles this
84: my $externalsyllabus=$courseenv{'externalsyllabus'};
85: if ($externalsyllabus=~/\w/) {
86: if ($env{'form.wrapperdisplay'} eq 'menu') {
87: $r->print(&Apache::lonwrapper::simple_menu());
88: } else {
89: $r->print(&Apache::lonwrapper::wrapper("/public/$cdom/$cnum/syllabus?wrapperdisplay=menu",
90: $externalsyllabus));
91: }
92: return OK;
93: }
94:
95: # --------------------------------------------------------- The old syllabus fields
96: my %syllabusfields=&Apache::lonlocal::texthash(
97: 'aaa_instructorinfo' => 'Instructor Information',
98: 'bbb_description' => 'Course Description',
99: 'ccc_prereq' => 'Prerequisites',
100: 'cdc_classhours' => 'Class Hours',
101: 'ddd_officehours' => 'Office Hours',
102: 'eee_helproom' => 'Helproom Hours',
103: 'efe_projectinfo' => 'Project Information',
104: 'fff_examinfo' => 'Exam Information',
105: 'fgf_deadlines' => 'Deadlines',
106: 'ggg_grading' => 'Grading Information',
107: 'hhh_readings' => 'Readings',
108: 'iii_coursepack' => 'Coursepack',
109: 'jjj_weblinks' => 'Web Links',
110: 'kkk_textbook' => 'Textbook',
111: 'lll_includeurl' => 'URLs To Include in Syllabus');
112:
113: # --------------------------------------------------------------- Force Student
114: my $forcestudent='';
115: if ($env{'form.forcestudent'}) { $forcestudent='student'; };
116: my $forceedit='';
117: if ($env{'form.forceedit'}) { $forceedit='edit'; }
118:
119: # ----------------------------------------------------------------- Make header
120: if ($target ne 'tex') {
121: my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
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');
129: if (numidx > -1) {
130: if (caller != 'details') {
131: document.backtocat.elements[numidx].value = '';
132: }
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: }
150: $js .= <<'ENDSCRIPT';
151:
152: <style type="text/css">
153: .LC_Sortable ul { list-style-type: none; margin: 0px; padding: 0px}
154: .LC_Sortable li { list-style-type: none; margin: 0px 5px 5px 5px; padding: 5px; padding-left: 1.5em; width: 175px; font-size:90% }
155: .LC_Sortable li span { float: left; margin-left: -1.5em; }
156: .LC_EllipseOverflow { overflow: hidden; text-overflow: ellipsis; -o-text-overflow: ellipsis; white-space: nowrap; }
157: #scrollable-fields-container {float: left; background-color: white; width: 235px; border: 1px solid grey; margin: 0px}
158: #syllabus-fields {position:relative; top: 0;}
159: #syllabus-fields-container {padding: 0 0 0 0}
160: #syllabus-content {margin-left: 245px}
161: </style>
162:
163: <script type="text/javascript">
164: // public domain code to emulate text-overflow:ellipsis in Firefox using jQuery
165: (function($) {
166: $.fn.ellipsis = function(enableUpdating){
167: var s = document.documentElement.style;
168: if (!('textOverflow' in s || 'OTextOverflow' in s)) {
169: return this.each(function(){
170: var el = $(this);
171: if(el.css("overflow") == "hidden"){
172: var originalText = el.html();
173: var w = el.width();
174:
175: var t = $(this.cloneNode(true)).hide().css({
176: 'position': 'absolute',
177: 'width': 'auto',
178: 'overflow': 'visible',
179: 'max-width': 'inherit'
180: });
181: el.after(t);
182:
183: var text = originalText;
184: while(text.length > 0 && t.width() > el.width()){
185: text = text.substr(0, text.length - 1);
186: t.html(text + "...");
187: }
188: el.html(t.html());
189:
190: t.remove();
191:
192: if(enableUpdating == true){
193: var oldW = el.width();
194: setInterval(function(){
195: if(el.width() != oldW){
196: oldW = el.width();
197: el.html(originalText);
198: el.ellipsis();
199: }
200: }, 200);
201: }
202: }
203: });
204: } else return this;
205: };
206: })(jQuery);
207:
208:
209: jQuery(document).ready(function() {
210: jQuery('.LC_EllipseOverflow').ellipsis();
211: jQuery('#syllabus-fields').sortable({
212: revert: true,
213: start: function(event, ui) {
214: jQuery(ui.item).css('font-style', 'italic');
215: },
216: stop: function(event, ui) {
217: var order = [];
218: jQuery(ui.item).parent().children('li').each(function() {
219: var id = /title-([0-9_]+)/i.exec(jQuery(this).attr('id'));
220: order.push(id[1]);
221: });
222: }
223: });
224: jQuery('#syllabus-fields li').click(function() {
225: jQuery(this).parent().children('li').removeClass('ui-state-highlight');
226: jQuery(this).addClass('ui-state-highlight');
227: var id = /title-([0-9_]+)/i.exec(jQuery(this).attr('id'));
228: jQuery('#syllabus-form .LC_Box').hide();
229: jQuery('#box-'+id[1]).show();
230: });
231: jQuery('#syllabus-fields ui, li').disableSelection();
232: jQuery('#syllabus-fields-container').height('500px');
233: jQuery('#syllabus-fields-container').css('overflow-x', 'hidden');
234: jQuery('#syllabus-fields-container').css('overflow-y', 'auto');
235: jQuery('#syllabus-fields-container').css('position', 'relative');
236: jQuery('#syllabus-fields').css('position', 'relative');
237: jQuery('#syllabus-fields').css('top', '0px');
238: jQuery('#syllabus-fields').css('display','block');
239: jQuery('#syllabus-fields-container').scroll(function() {
240: jQuery('#syllabus-fields').sortable('refreshPositions');
241: });
242: jQuery('#syllabus-form .LC_Box').hide();
243: });
244: </script>
245: ENDSCRIPT
246: my $start_page =
247: &Apache::loncommon::start_page("Syllabus", $rss_link.$js,
248: {'function' => undef,
249: 'domain' => $cdom,
250: 'force_register' =>
251: $env{'form.register'},});
252:
253: $r->print($start_page);
254: if ($env{'form.backto'} eq 'coursecatalog') {
255: &Apache::lonhtmlcommon::clear_breadcrumbs();
256: &Apache::lonhtmlcommon::add_breadcrumb
257: ({href=>"javascript:ToCatalog()",
258: text=>"Course/Community Catalog"});
259: if ($env{'form.coursenum'} ne '') {
260: &Apache::lonhtmlcommon::add_breadcrumb
261: ({href=>"javascript:ToCatalog('details')",
262: text=>"Course details"});
263: }
264: &Apache::lonhtmlcommon::add_breadcrumb
265: ({href=>$r->uri,
266: text=>"Course syllabus"});
267: $r->print(&Apache::lonhtmlcommon::breadcrumbs());
268: }
269: }
270: # ---------------------------------------------------------- Load syllabus info
271: my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum); # load db
272: my $allowed=0; # can we edit this page?
273: my $privileged=0;
274: my %data;
275: if ($env{'form.forceflush'}) {
276: delete $syllabus{'data.fields'};
277: &Apache::lonnet::del('syllabus', ['data.fields'], $cdom, $cnum);
278: delete $syllabus{'properties.v2_conflict'};
279: &Apache::lonnet::del('syllabus', ['properties.v2_conflict'], $cdom, $cnum);
280: delete $syllabus{'properties.v2_conflict_fail'};
281: &Apache::lonnet::del('syllabus', ['properties.v2_conflict_fail'], $cdom, $cnum);
282: delete $syllabus{'properties.last_modified'};
283: &Apache::lonnet::del('syllabus', ['properties.last_modified'], $cdom, $cnum);
284: delete $syllabus{'properties.v2_converted'};
285: &Apache::lonnet::del('syllabus', ['properties.v2_converted'], $cdom, $cnum);
286: delete $syllabus{'data.old_new_map'};
287: &Apache::lonnet::del('syllabus', ['data.old_new_map'], $cdom, $cnum);
288: delete $syllabus{'data.deleted_fields'};
289: &Apache::lonnet::del('syllabus', ['data.deleted_fields'], $cdom, $cnum);
290: %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum); # load db
291: $r->print("Flushed syllabus DB file.<br />");
292: $r->print("Syllabus conflict: ".$syllabus{'properties.v2_conflict'}."<br />");
293: }
294: #$r->print("Existing fields: ".$syllabus{'data.fields'}."<br />");
295: #$r->print("Old-new map: ".$syllabus{'data.old_new_map'}."<br />");
296: #$r->print("Deleted fields: ".$syllabus{'data.deleted_fields'}."<br />");
297: if (!exists($syllabus{'data.fields'})) {
298: # convert existing 2.x data to new DB fields
299: # which become new primary data source for document
300: %data = %{convert_from_v2($r, \%syllabus, \%syllabusfields, 0)};
301: #$r->print("New fields order: ".$data{'data.fields'}."<br />");
302: &Apache::lonnet::put('syllabus',\%data,$cdom,$cnum);
303: } elsif ( !exists($syllabus{'properties.v2_converted'}) &&
304: exists($syllabus{'uploaded.lastmodified'}) &&
305: exists($syllabus{'properties.last_modified'}) &&
306: ($syllabus{'uploaded.lastmodified'} !=
307: $syllabus{'properties.last_modified'})) {
308: # if the document has been saved in 3.x and later edited in
309: # 2.x, reconvert the existing document, with extra warning
310: %data = %{convert_from_v2($r, \%syllabus, \%syllabusfields, 1)};
311: delete $data{'properties.v2_converted'};
312: &Apache::lonnet::del('syllabus', ['properties.v2_converted'], $cdom, $cnum);
313: $data{'properties.v2_conflict'} = 1;
314: &Apache::lonnet::put('syllabus',\%data,$cdom,$cnum);
315: } else {
316: %data = %syllabus;
317:
318: }
319:
320: # ----------------------------------------------------- Only if not public call
321: if ($env{'user.environment'}) { # does this user have privileges to post, etc?
322: if ($env{'request.course.id'}
323: && $cdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}
324: && $cnum eq $env{'course.'.$env{'request.course.id'}.'.num'}) {
325: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
326: $privileged=$allowed;
327: if (($data{'uploaded.lastmodified'}) && (!$forceedit)) {
328: $forcestudent='student';
329: }
330: if ($forcestudent or $target eq 'tex') { $allowed=0; }
331: }
332: #store what the user typed in
333: my @fields = @{thaw($data{'data.fields'})};
334: if (($allowed) && ($env{'form.delete'})) {
335: my $field = $env{'form.delete'};
336: chomp($field);
337: #allow only numbers, underscores
338: $field=~s/[^0-9_]//g;
339: #check if the field exists
340: #do not delete if file in v2 conversion mode
341: if (exists($data{'data.field.'.$field}) &&
342: !exists($data{'properties.v2_converted'})) {
343: #$r->print("Field '$field' can be deleted.<br />");
344: # linearly parse "data.fields" and remove it
345: for (my $i = 0; $i < length(@fields); $i++) {
346: if ($fields[$i] eq $field) {
347: splice(@fields, $i, 1);
348: #$r->print("Removed entry $i from 'data.fields'<br />");
349: }
350: }
351: # if "data.deleted" does not exist, create it
352: my @deleted;
353: if (!exists($data{'data.deleted_fields'})) {
354: @deleted = [];
355: } else {
356: @deleted = @{thaw($data{'data.deleted_fields'})};
357: }
358: # only if deleted does not exist in 'data.deleted', push it
359: my $push = 1;
360: for (my $i = 0; $i < length(@deleted); $i++) {
361: if ($deleted[$i] eq $field) {
362: $push = 0;
363: last;
364: }
365: }
366: unless (!$push) {
367: push(@deleted, $field);
368: }
369: $data{'data.fields'} = freeze(\@fields);
370: $data{'data.deleted_fields'} = freeze(\@deleted);
371:
372: &Apache::lonnet::put('syllabus',\%data,$cdom,$cnum);
373: }
374: }
375: if (($allowed) && ($env{'form.rename'})) {
376: my $field = $env{'form.rename'};
377: my $new_title = "Hello, World!";
378: chomp($field);
379: $field=~s/[^0-9_]//g;
380: #check if the field exists
381: #do not delete if file in v2 conversion mode
382: if (exists($data{'data.field.'.$field}) &&
383: !exists($data{'properties.v2_converted'})) {
384: #sanitize HTML content
385: #$r->print("Rename -- field found.<br />");
386: my %db_entry = %{thaw($data{'data.field.'.$field})};
387: $new_title = &Apache::lonfeedback::clear_out_html($new_title, 1);
388: $db_entry{title} = $new_title;
389: $data{'data.field.'.$field} = freeze(\%db_entry);
390: &Apache::lonnet::put('syllabus',\%data,$cdom,$cnum);
391: }
392: }
393: if (($allowed) && ($env{'form.storesyl'})) {
394: foreach my $syl_field (@fields) {
395: my $field=$env{'form.'.$syl_field};
396: my $type;
397: my %field_hash;
398: # only update a field if it already exists!
399: if (exists($data{'data.field.'.$syl_field})) {
400: #$r->print("Creating/updated field ".$syl_field."<br />");
401: %field_hash = exists($data{'data.field.'.$syl_field}) ?
402: %{thaw($data{'data.field.'.$syl_field})} : ();
403: $type = exists($field_hash{type}) ? $field_hash{type} : TYPE_TEXT_HTML;
404: chomp($field);
405: $field=~s/\s+$//s;
406: $field=~s/^\s+//s;
407: $field=~s/\<br\s*\/*\>$//s;
408: $field=&Apache::lonfeedback::clear_out_html($field,1);
409: $field_hash{content}=$field;
410: if ($type eq TYPE_URL_INCLUDE) { # clean up included URLs
411: my $field='';
412: foreach my $value (split(/\n/,$field_hash{content})) {
413: my $url=$value;
414: # get rid of leading and trailing spaces
415: $url=~s/^\s+//;
416: $url=~s/\s+$//;
417: if ($url=~m|^https?\://([^/]+)/(.+)$|) {
418: my $host = $1;
419: my $remainder=$2;
420: # remove the hostname from internal URLs
421: my $hostname = &Apache::lonnet::hostname($host);
422: my %all_hostnames = &Apache::lonnet::all_hostnames();
423: foreach my $possible_host (keys(%all_hostnames)) {
424: if ($possible_host =~ /\Q$hostname\E/i) {
425: $url=$remainder;
426: }
427: }
428: }
429: # norm internal URLs
430: unless ($url=~/^https?\:/) {
431: $url=&Apache::lonnet::clutter($url);
432: }
433: # re-assemble field
434: if ($url) {
435: $field.=$url."\n";
436: }
437: }
438: $field_hash{content}=$field;
439: $field_hash{type}=TYPE_URL_INCLUDE;
440: }
441: $data{'data.field.'.$syl_field} = freeze(\%field_hash);
442: }
443: }
444: $data{'uploaded.domain'}=$env{'user.domain'};
445: $data{'uploaded.name'}=$env{'user.name'};
446: my $time = $^T;
447: $data{'uploaded.lastmodified'}=$time;
448: $data{'properties.last_modified'}=$time;
449: delete $data{'properties.v2_converted'};
450: delete $data{'properties.v2_conflict'};
451: delete $data{'properties.v2_conflict_fail'};
452: &Apache::lonnet::del('syllabus', ['properties.v2_converted',
453: 'properties.v2_conflict', 'properties.v2_conflict_fail'], $cdom, $cnum);
454:
455: #2.x compatibility: write to old fields with new mapped fields
456: my %old_new_map = %{thaw($data{'data.old_new_map'})};
457: foreach my $old_field (keys(%old_new_map)) {
458: #$r->print("Looking for: ".$old_field." at ".$old_new_map{$old_field}."<br />");
459: if (exists($data{'data.field.'.$old_new_map{$old_field}})) {
460: #$r->print("updating old field ".$old_field."<br />");
461: my %new_field = %{thaw($data{'data.field.'.$old_new_map{$old_field}})};
462: $data{$old_field} = $new_field{content};
463: }
464: }
465:
466: &Apache::lonnet::put('syllabus',\%data,$cdom,$cnum);
467: }
468: }
469:
470: #--------Functions
471: if( ($allowed || $privileged) && $target ne 'tex') {
472: my $functions=&Apache::lonhtmlcommon::start_funclist();
473: if ($allowed) {
474: #if you have the register flag, keep it
475: if($env{'form.register'} == 1) {
476: $functions.=&Apache::lonhtmlcommon::add_item_funclist(
477: '<a href="'.$r->uri.'?forcestudent=1&register=1">'
478: .&mt('Show Public View').'</a>'
479: .&Apache::loncommon::help_open_topic(
480: 'Uploaded_Templates_PublicView'));
481: } else {
482: $functions.=&Apache::lonhtmlcommon::add_item_funclist(
483: '<a href="'.$r->uri.'?forcestudent=1">'
484: .&mt('Show Public View').'</a>'
485: .&Apache::loncommon::help_open_topic(
486: 'Uploaded_Templates_PublicView'));
487: }
488: } elsif ($privileged) {
489: if($env{'form.register'} == 1) {
490: $functions.=&Apache::lonhtmlcommon::add_item_funclist(
491: '<a href="'.$r->uri.'?forceedit=1&register=1">'
492: .&mt('Edit').'</a>');
493: } else {
494: $functions.=&Apache::lonhtmlcommon::add_item_funclist(
495: '<a href="'.$r->uri.'?forceedit=1">'
496: .&mt('Edit').'</a>');
497: }
498: }
499:
500: $functions.=&Apache::lonhtmlcommon::end_funclist();
501: $r->print(&Apache::loncommon::head_subbox($functions));
502: }
503:
504: #---------------------Print External URL Syllabus Info and Help Text
505: if( ($allowed) && ($target ne 'tex') ) {
506: my $protocol = $Apache::lonnet::protocol{$homeserver};
507: $protocol = 'http' if ($protocol ne 'https');
508: $r->print('<p class="LC_info">'
509: .&mt('This syllabus can be publicly viewed at [_1]'
510: ,'<tt>'.$protocol.'://'.&Apache::lonnet::hostname($homeserver).$r->uri.'</tt>')
511: .' '.&Apache::loncommon::help_open_topic('Syllabus_ExtLink')
512: .'</p>'
513: .'<p class="LC_info">'
514: .&mt('Instead of using this template you can specify an external URL as Syllabus in the [_1]Course Configuration[_2].'
515: ,'<a href="/adm/courseprefs?actions=courseinfo&phase=display">','</a>')
516: .'</p>'
517: );
518: #-Print Help Text
519: $r->print(&Apache::loncommon::help_open_topic(
520: 'Uploaded_Templates_TextBoxes',
521: &mt('Help with filling in text boxes')));
522: }
523:
524: #----------Print last update
525: my $lastmod=$syllabus{'uploaded.lastmodified'};
526: $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
527: my $who = &Apache::loncommon::aboutmewrapper(
528: &Apache::loncommon::plainname($syllabus{'uploaded.name'},
529: $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
530: $syllabus{'uploaded.domain'});
531: if ($target ne 'tex') {
532: $r->print('<div class="LC_info">'.&mt('Last updated').': '.
533: $lastmod . ' '.
534: ($who ? &mt('by').' '.$who
535: : '' ) .
536: '</div>' );
537:
538: } else {
539: $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.
540: ($who? &mt('by').'\\\\ '.
541: &Apache::loncommon::plainname($syllabus{'uploaded.name'},$syllabus{'uploaded.domain'})
542: :'')
543: .'\\\\');
544: }
545: if ($allowed && $data{'properties.v2_converted'} == 1) {
546: $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/>");
547: }
548: if ($allowed && $data{'properties.v2_conflict'} == 1) {
549: $r->print("<em>This document was saved with LON-CAPA 3.x, then further edited in LON-CAPA 2.x.</em><br/>");
550: if ($data{'properties.v2_conflict_fail'} == 1) {
551: $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 />");
552: } else {
553: $r->print("<em>These changes were automatically transferred to LON-CAPA 3.x</em>");
554: }
555: }
556:
557: #----------------------------Print Headtitle
558: if ($target ne 'tex') {
559: $r->print('<h1>'.$courseenv{'description'}.'</h1>');
560: $r->print('<h3>'. &Apache::lonnet::domain($cdom,'description').'</h3>');
561: } else {
562: $r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
563: &Apache::lonnet::domain($cdom,'description').'}\\\\');
564: }
565:
566: # -------------------------------------------------------- Get course personnel
567: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
568: if ($target ne 'tex') {
569: $r->print(&Apache::lonhtmlcommon::start_pick_box());
570: } else {
571: $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
572: }
573: my @personnel=sort(keys(%coursepersonnel));
574: my $lastpers=$personnel[$#personnel];
575: foreach my $element (@personnel) {
576: if ($target ne 'tex') {
577: $r->print(&Apache::lonhtmlcommon::row_title($element));
578: } else {
579: $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & ');
580: }
581: foreach (split(/\,/,$coursepersonnel{$element})) {
582: my ($puname,$pudom)=split(/\:/,$_);
583: if ($target ne 'tex') {
584: my $courseperson = &Apache::loncommon::plainname($puname,$pudom);
585: if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
586: ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
587: $r->print(' '.$courseperson);
588: } else {
589: $r->print(' '.&Apache::loncommon::aboutmewrapper($courseperson,
590: $puname,$pudom));
591: }
592: } else {
593: $r->print(' '.&Apache::loncommon::plainname($puname,
594: $pudom).' ');
595: }
596: }
597: if ($target ne 'tex') {
598: my $lastclose=$element eq $lastpers?1:0;
599: $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
600: } else {
601: $r->print('\\\\ \hline');
602: }
603: }
604: if ($target ne 'tex') {
605: $r->print(&Apache::lonhtmlcommon::end_pick_box());
606: } else {
607: $r->print('\end{tabular}\\\\');
608: }
609: # -------------------------------------------------------------- Announcements?
610: my $day = &Apache::lonannounce::showday(time,2,
611: &Apache::lonannounce::readcalendar($cdom.'_'.$cnum));
612: if ($target ne 'tex') {
613: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
614: $r->print("<br />");
615: &print_field_sortable($r, \%data, $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML);
616: }
617: $r->print("<div id='syllabus-content'>\n");
618:
619: } else {
620: $r->print(&Apache::lonxml::xmlparse($r,'tex',$day));
621: }
622:
623: # ---------------------------------------------------------------- Get syllabus
624: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
625: if ($allowed) {
626: $r->print('<form id="syllabus-form" method="post" action="">'.
627: '<input type="hidden" name="forceedit" value="edit" />');
628: }
629: my @htmlids=();
630: my $url_include_handler = sub {
631: my ($r, $field, $json_ref, $group, $target, $allowed) = @_;
632: my $message = $json_ref->{items}{$field}{content};
633: my $title = $json_ref->{items}{$field}{title};
634: my $urls = $message;
635: foreach my $filelink (split(/\n/,$urls)) {
636: my $output='';
637: # embed style?
638: my ($curfext)=($filelink=~/\.([^\.]+)$/);
639: my $embstyle=&Apache::loncommon::fileembstyle($curfext);
640: if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {# make ssi call and remove everything but the body contents
641: $output=&Apache::lonnet::ssi_body($filelink);
642: } elsif ($embstyle eq 'img') {# embed as an image
643: $output='<img src="'.$filelink.'" />';
644: }
645: if ($output ne '') {
646: $message='';
647: if ($target ne 'tex') {
648: $message.='<p>'.$output.'</p>';
649: } else {
650: $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
651: }
652: }
653: }
654: if ($allowed) {
655: &Apache::lonfeedback::newline_to_br(\$urls);
656: &Apache::lontemplate::print_start_template($r,$title.
657: &Apache::loncommon::help_open_topic('Syllabus_URLs'),'LC_Box');
658: $r->print($urls);
659: $r->print("<br /><div>");
660: &Apache::lontemplate::print_textarea_template($r, $message,
661: $field, Apache::lontemplate->RICH_TEXT_ALWAYS_OFF);
662: &Apache::lontemplate::print_saveall_template($r);
663: $r->print("</div>");
664: &Apache::lontemplate::print_end_template($r);
665:
666: } else {
667: $r->print($message);
668: }
669: };
670: my %custom_hash = ( TYPE_URL_INCLUDE() => $url_include_handler );
671: @htmlids = &print_template_new_fields($r, \%data,
672: $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_hash);
673: if ($allowed) {
674: $r->print('</form>'.
675: &Apache::lonhtmlcommon::htmlareaselectactive(@htmlids));
676: }
677: if ($target ne 'tex') {$r->print('</div><p style="clear:both"> </p>');}
678: if ($allowed) {
679: &Apache::lontemplate::print_start_template($r,'RSS Feeds and Blogs','LC_Box');
680: $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit));
681: my $editurl= &Apache::lonnet::absolute_url().'/adm/'.$cdom.'/'.$cnum.'/_rss.html';
682: $r->print( '<a href="'.$editurl.'">'.&mt('New RSS Feed or Blog').'</a>');
683: &Apache::lontemplate::print_end_template($r);
684: } elsif (&Apache::lonrss::advertisefeeds($cnum,$cdom) ne '') {
685: &Apache::lontemplate::print_start_template($r,'RSS Feeds and Blogs','LC_Box');
686: $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit));
687: &Apache::lontemplate::print_end_template($r);
688: }
689: } else {
690: if ($target ne 'tex') {$r->print('<p>');} else {$r->print('\par ');}
691: $r->print(&mt('No syllabus information provided.'));
692: if ($target ne 'tex') {$r->print('</p>');}
693: }
694: if ($target ne 'tex') {
695: if ($env{'form.backto'} eq 'coursecatalog') {
696: $r->print('<form name="backtocat" method="post" action="/adm/coursecatalog">'.
697: &Apache::lonhtmlcommon::echo_form_input(['backto','courseid']).
698: '</form>');
699: }
700: $r->print(&Apache::loncommon::end_page());
701: } else {
702: $r->print('\end{document}');
703: }
704: return OK;
705: }
706:
707: sub print_field_sortable {
708: my ($r, $data_ref, $target, $allowed, $default_rich_text, $group) = @_;
709: my %data = %{$data_ref};
710: my @fields = @{thaw($data{'data.fields'})};
711: $r->print("<div id='scrollable-fields-container'>
712: <!--<div id='syllabus-fields-up' class='ui-state-default' style='text-align:center'>Up</div>-->
713: <div id='syllabus-fields-container'>
714: <ui id='syllabus-fields' class='LC_Sortable LC_SyllabusFields'>\n");
715: foreach my $key (@fields) {
716: my %field = %{thaw($data{'data.field.'.$key})};
717: $r->print("<li id='title-$key' class='ui-state-default LC_EllipseOverflow' title='$field{title}'><span class='ui-icon ui-icon-arrowthick-2-n-s'></span>$field{title}</li>\n");
718: }
719: $r->print("
720: </ui>
721: </div>
722: <!--<div id='syllabus-fields-down' class='ui-state-default' style='text-align:center'>Down</div>-->
723: </div>\n");
724: }
725:
726: sub print_template_new_fields {
727: my ($r, $data_ref, $target, $allowed, $default_rich_text, $custom_handlers_ref, $group) = @_;
728: my @html_ids = ();
729: my %data = %{$data_ref};
730: my @fields = @{thaw($data{'data.fields'})};
731: my %custom_handlers = %{$custom_handlers_ref};
732:
733: foreach my $key (@fields) {
734: my %field = %{thaw($data{'data.field.'.$key})};
735: my $title = $field{title};
736: my $raw_message = $field{content};
737: my $type = $field{type};
738: my $message = $raw_message if (($raw_message=~/\w/) || ($allowed));
739: if ((%custom_handlers) && exists($custom_handlers{$type})) {
740: #$custom_handlers{$type}->($r, $field, $json_ref, $group, $target, $allowed);
741: } else {
742: if (($raw_message=~/\w/) || ($allowed)) {
743: if (!&Apache::lonfeedback::contains_block_html($message)) {
744: &Apache::lonfeedback::newline_to_br(\$message);
745: } else {
746: $message = &Apache::lonfeedback::tidy_html($message);
747: }
748: $message=&Apache::lonhtmlcommon::raw_href_to_link($message);
749: if ($allowed) {
750: $message=&Apache::lonspeller::markeduptext($message);
751: }
752: $message=&Apache::lontexconvert::msgtexconverted($message);
753: if ($target ne 'tex') {
754: #output of syllabusfields will be generated here.
755: &Apache::lontemplate::print_start_template($r,$title,'LC_Box', 'box-'.$key);
756: $r->print($message);
757: if ($allowed) {
758: $r->print("<br /><div>");
759: &Apache::lontemplate::print_textarea_template($r, $raw_message,
760: $key, $default_rich_text);
761: &Apache::lontemplate::print_saveall_template($r);
762: if (!exists($data{'properties.v2_converted'})) {
763: $r->print("<a href='?delete=$key&forceedit=1'>Delete</a> ");
764: $r->print("<a href='?rename=$key&forceedit=1'>Rename to \"Hello, World!\"</a>");
765: }
766: $r->print("</div>");
767: }
768: &Apache::lontemplate::print_end_template($r);
769: } else {
770: my $safeinit;
771: $r->print(&Apache::lonxml::xmlparse($r,'tex','<h3>'.$title.'</h3>'));
772: $r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
773: }
774: push(@html_ids,"hello");
775: }
776: }
777: }
778:
779: return @html_ids;
780: }
781:
782: sub convert_from_v2 {
783: my ($r, $data_ref, $fields_ref, $conflict) = @_;
784: my %data = %{$data_ref};
785: my %fields = %{$fields_ref};
786: my @fields_order = (!$conflict) ? () : @{thaw($data{'data.fields'})};
787: my %old_new_map = (!$conflict) ? () : %{thaw($data{'data.old_new_map'})};
788: my $repeat_int = 0; #ensure fields with created timestamp are unique
789: foreach my $element (sort(keys(%fields))) {
790: my %new_element = ();
791: my $title = $fields{$element};
792: my $title_hash = time."_".$$;
793: if (exists($data{'data.field.'.$title_hash})) {
794: $title_hash .= "_".$repeat_int++;
795: }
796: my $content = $data{$element};
797: $new_element{title} = $title;
798: $new_element{content} = $content;
799: if ($element eq 'lll_includeurl') {
800: $new_element{type} = TYPE_URL_INCLUDE;
801: } else {
802: $new_element{type} = TYPE_TEXT_HTML;
803: }
804: if (!$conflict) {
805: $r->print("Creating new field with ID: ".$title_hash."<br />");
806: $data{'data.field.'.$title_hash} = freeze(\%new_element);
807: $old_new_map{$element} = $title_hash;
808: push(@fields_order, $title_hash);
809: } else {
810: if (exists($old_new_map{$element})) {
811: $r->print("Transferring old field ".$element." to new ID: ".$old_new_map{$element}."<br />");
812: if (exists($data{'data.field.'.$old_new_map{$element}})) {
813: my %new_field = %{thaw($data{'data.field.'.$old_new_map{$element}})};
814: $new_field{content} = $content;
815: $data{'data.field.'.$old_new_map{$element}} = freeze(\%new_field);
816: }
817: } else {
818: $data{'data.field.'.$title_hash} = freeze(\%new_element);
819: $old_new_map{$element} = $title_hash;
820: $data{'properties.v2_conflict_fail'} = 1;
821: push(@fields_order, $title_hash);
822: }
823: }
824: }
825: $data{'data.fields'} = freeze(\@fields_order);
826: $data{'data.old_new_map'} = freeze(\%old_new_map);
827: $data{'properties.last_modified'} = time;
828: $data{'properties.v2_converted'} = 1;
829: $data{'properties.type'} = 'syllabus';
830:
831: return \%data;
832: }
833:
834: 1;
835: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>