Annotation of loncom/interface/lonsyllabus.pm, revision 1.106.2.4
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.2 faziophi 65: ($ENV{'QUERY_STRING'},['delete', 'rename', '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.106.2.3 faziophi 150: $js .= <<'ENDSCRIPT';
151:
152: <style type="text/css">
153: .LC_Sortable ul { list-style-type: none; margin: 0px; padding: 0px}
1.106.2.4! faziophi 154: .LC_Sortable li { list-style-type: none; cursor: pointer; margin: 0px 5px 5px 5px; padding: 5px; padding-left: 1.5em; width: 200px; font-size:90% }
! 155: .LC_Sortable li span.left { float: left; cursor: move; margin-left: -1.5em; }
! 156: .LC_Sortable li span.right { float: right; cursor: auto; margin-right: 0em }
1.106.2.3 faziophi 157: .LC_EllipseOverflow { overflow: hidden; text-overflow: ellipsis; -o-text-overflow: ellipsis; white-space: nowrap; }
1.106.2.4! faziophi 158: .LC_ActivityBarButton-IconLeft { padding-left: 20px }
! 159: .LC_ActivityBarButton-IconLeft .ui-icon { float:left; margin-left: -18px; }
! 160: #scrollable-fields-container {float:left; background-color: white; width: 235px; border: 1px solid grey; margin: 0px; -moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px;}
! 161: #syllabus-fields-actions {text-align: center}
1.106.2.3 faziophi 162: #syllabus-content {margin-left: 245px}
1.106.2.4! faziophi 163: #activity-bar {-moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px; border: solid 1px grey; background-color: #dddddd; padding: 0px 0px;margin: 5px 0 2px 0;}
! 164: #activity-bar button { font-size: 100%; vertical-align: middle }
1.106.2.3 faziophi 165: </style>
166:
167: <script type="text/javascript">
168: // public domain code to emulate text-overflow:ellipsis in Firefox using jQuery
169: (function($) {
170: $.fn.ellipsis = function(enableUpdating){
171: var s = document.documentElement.style;
172: if (!('textOverflow' in s || 'OTextOverflow' in s)) {
173: return this.each(function(){
174: var el = $(this);
175: if(el.css("overflow") == "hidden"){
176: var originalText = el.html();
177: var w = el.width();
178:
179: var t = $(this.cloneNode(true)).hide().css({
180: 'position': 'absolute',
181: 'width': 'auto',
182: 'overflow': 'visible',
183: 'max-width': 'inherit'
184: });
185: el.after(t);
186:
187: var text = originalText;
188: while(text.length > 0 && t.width() > el.width()){
189: text = text.substr(0, text.length - 1);
190: t.html(text + "...");
191: }
192: el.html(t.html());
193:
194: t.remove();
195:
196: if(enableUpdating == true){
197: var oldW = el.width();
198: setInterval(function(){
199: if(el.width() != oldW){
200: oldW = el.width();
201: el.html(originalText);
202: el.ellipsis();
203: }
204: }, 200);
205: }
206: }
207: });
208: } else return this;
209: };
210: })(jQuery);
211:
1.106.2.4! faziophi 212: var changesMade = false;
! 213: var changesBreakVersion = false;
1.106.2.3 faziophi 214:
215: jQuery(document).ready(function() {
216: jQuery('.LC_EllipseOverflow').ellipsis();
1.106.2.4! faziophi 217: jQuery('#syllabus-fields li').click(function() {
! 218: jQuery(this).parent().children('li').removeClass('ui-state-highlight');
! 219: jQuery(this).addClass('ui-state-highlight');
! 220: var id = /title-([0-9_]+)/i.exec(jQuery(this).attr('id'));
! 221: jQuery('#syllabus-form .LC_Box').hide();
! 222: jQuery('#box-'+id[1]).show();
! 223: });
1.106.2.3 faziophi 224: jQuery('#syllabus-fields').sortable({
225: revert: true,
1.106.2.4! faziophi 226: axis: 'y',
! 227: cursor: 'move',
! 228: placeholder: 'ui-state-highlight',
! 229: handle: 'span.ui-icon-arrowthick-2-n-s',
! 230: forcePlaceholderSize: true,
1.106.2.3 faziophi 231: start: function(event, ui) {
232: jQuery(ui.item).css('font-style', 'italic');
233: },
234: stop: function(event, ui) {
235: var order = [];
236: jQuery(ui.item).parent().children('li').each(function() {
237: var id = /title-([0-9_]+)/i.exec(jQuery(this).attr('id'));
238: order.push(id[1]);
239: });
1.106.2.4! faziophi 240: if (!changesMade) {
! 241: changesMade = true;
! 242: $('#save-button').addClass('ui-state-highlight');
! 243: $('#save-button').removeClass('ui-state-disabled');
! 244: }
1.106.2.3 faziophi 245: }
246: });
1.106.2.4! faziophi 247: jQuery('#syllabus-fields li').disableSelection();
! 248: jQuery('.RemoveSection').hide();
! 249: jQuery('#syllabus-fields li').hover(
! 250: function(){
! 251: jQuery(this).find('.RemoveSection').toggle();
! 252: },
! 253: function(){
! 254: jQuery(this).find('.RemoveSection').toggle();
! 255: }
! 256: );
! 257: jQuery('#syllabus-fields li span.right').hover(
! 258: function(){
! 259: jQuery(this).css('background-image', 'url("/adm/jQuery/css/smoothness/images/ui-icons_2e83ff_256x240.png")');
! 260: },
! 261: function(){
! 262: jQuery(this).css('background-image', 'url("/adm/jQuery/css/smoothness/images/ui-icons_454545_256x240.png")');
! 263: }
! 264: );
1.106.2.3 faziophi 265: jQuery('#syllabus-form .LC_Box').hide();
1.106.2.4! faziophi 266: jQuery('.LC_ActivityBarButton').hover(
! 267: function(){
! 268: $(this).addClass("ui-state-hover");
! 269: },
! 270: function(){
! 271: $(this).removeClass("ui-state-hover");
! 272: }
! 273: );
1.106.2.3 faziophi 274: });
275: </script>
276: ENDSCRIPT
1.91 amueller 277: my $start_page =
278: &Apache::loncommon::start_page("Syllabus", $rss_link.$js,
1.97 amueller 279: {'function' => undef,
1.91 amueller 280: 'domain' => $cdom,
281: 'force_register' =>
282: $env{'form.register'},});
1.49 albertel 283:
1.91 amueller 284: $r->print($start_page);
1.65 raeburn 285: if ($env{'form.backto'} eq 'coursecatalog') {
286: &Apache::lonhtmlcommon::clear_breadcrumbs();
287: &Apache::lonhtmlcommon::add_breadcrumb
1.90 amueller 288: ({href=>"javascript:ToCatalog()",
1.100 bisitz 289: text=>"Course/Community Catalog"});
1.65 raeburn 290: if ($env{'form.coursenum'} ne '') {
291: &Apache::lonhtmlcommon::add_breadcrumb
1.90 amueller 292: ({href=>"javascript:ToCatalog('details')",
293: text=>"Course details"});
1.65 raeburn 294: }
295: &Apache::lonhtmlcommon::add_breadcrumb
1.90 amueller 296: ({href=>$r->uri,
297: text=>"Course syllabus"});
1.65 raeburn 298: $r->print(&Apache::lonhtmlcommon::breadcrumbs());
1.86 bisitz 299: }
1.17 www 300: }
301: # ---------------------------------------------------------- Load syllabus info
1.106.2.1 faziophi 302: my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum); # load db
303: my $allowed=0; # can we edit this page?
1.27 www 304: my $privileged=0;
1.106.2.1 faziophi 305: my %data;
306: if ($env{'form.forceflush'}) {
307: delete $syllabus{'data.fields'};
308: &Apache::lonnet::del('syllabus', ['data.fields'], $cdom, $cnum);
309: delete $syllabus{'properties.v2_conflict'};
310: &Apache::lonnet::del('syllabus', ['properties.v2_conflict'], $cdom, $cnum);
311: delete $syllabus{'properties.v2_conflict_fail'};
312: &Apache::lonnet::del('syllabus', ['properties.v2_conflict_fail'], $cdom, $cnum);
313: delete $syllabus{'properties.last_modified'};
314: &Apache::lonnet::del('syllabus', ['properties.last_modified'], $cdom, $cnum);
315: delete $syllabus{'properties.v2_converted'};
316: &Apache::lonnet::del('syllabus', ['properties.v2_converted'], $cdom, $cnum);
317: delete $syllabus{'data.old_new_map'};
318: &Apache::lonnet::del('syllabus', ['data.old_new_map'], $cdom, $cnum);
1.106.2.2 faziophi 319: delete $syllabus{'data.deleted_fields'};
320: &Apache::lonnet::del('syllabus', ['data.deleted_fields'], $cdom, $cnum);
1.106.2.1 faziophi 321: %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum); # load db
322: $r->print("Flushed syllabus DB file.<br />");
323: $r->print("Syllabus conflict: ".$syllabus{'properties.v2_conflict'}."<br />");
324: }
1.106.2.3 faziophi 325: #$r->print("Existing fields: ".$syllabus{'data.fields'}."<br />");
326: #$r->print("Old-new map: ".$syllabus{'data.old_new_map'}."<br />");
327: #$r->print("Deleted fields: ".$syllabus{'data.deleted_fields'}."<br />");
1.106.2.1 faziophi 328: if (!exists($syllabus{'data.fields'})) {
329: # convert existing 2.x data to new DB fields
330: # which become new primary data source for document
331: %data = %{convert_from_v2($r, \%syllabus, \%syllabusfields, 0)};
1.106.2.3 faziophi 332: #$r->print("New fields order: ".$data{'data.fields'}."<br />");
1.106.2.1 faziophi 333: &Apache::lonnet::put('syllabus',\%data,$cdom,$cnum);
334: } elsif ( !exists($syllabus{'properties.v2_converted'}) &&
335: exists($syllabus{'uploaded.lastmodified'}) &&
336: exists($syllabus{'properties.last_modified'}) &&
337: ($syllabus{'uploaded.lastmodified'} !=
338: $syllabus{'properties.last_modified'})) {
339: # if the document has been saved in 3.x and later edited in
340: # 2.x, reconvert the existing document, with extra warning
341: %data = %{convert_from_v2($r, \%syllabus, \%syllabusfields, 1)};
342: delete $data{'properties.v2_converted'};
343: &Apache::lonnet::del('syllabus', ['properties.v2_converted'], $cdom, $cnum);
344: $data{'properties.v2_conflict'} = 1;
345: &Apache::lonnet::put('syllabus',\%data,$cdom,$cnum);
346: } else {
347: %data = %syllabus;
348:
349: }
1.4 www 350:
1.2 www 351: # ----------------------------------------------------- Only if not public call
1.106.2.1 faziophi 352: if ($env{'user.environment'}) { # does this user have privileges to post, etc?
1.90 amueller 353: if ($env{'request.course.id'}
1.91 amueller 354: && $cdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}
355: && $cnum eq $env{'course.'.$env{'request.course.id'}.'.num'}) {
1.90 amueller 356: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.91 amueller 357: $privileged=$allowed;
1.106.2.1 faziophi 358: if (($data{'uploaded.lastmodified'}) && (!$forceedit)) {
1.91 amueller 359: $forcestudent='student';
360: }
1.90 amueller 361: if ($forcestudent or $target eq 'tex') { $allowed=0; }
362: }
1.98 amueller 363: #store what the user typed in
1.106.2.1 faziophi 364: my @fields = @{thaw($data{'data.fields'})};
365: if (($allowed) && ($env{'form.delete'})) {
366: my $field = $env{'form.delete'};
367: chomp($field);
368: #allow only numbers, underscores
369: $field=~s/[^0-9_]//g;
370: #check if the field exists
371: #do not delete if file in v2 conversion mode
372: if (exists($data{'data.field.'.$field}) &&
373: !exists($data{'properties.v2_converted'})) {
1.106.2.3 faziophi 374: #$r->print("Field '$field' can be deleted.<br />");
1.106.2.2 faziophi 375: # linearly parse "data.fields" and remove it
376: for (my $i = 0; $i < length(@fields); $i++) {
377: if ($fields[$i] eq $field) {
378: splice(@fields, $i, 1);
1.106.2.3 faziophi 379: #$r->print("Removed entry $i from 'data.fields'<br />");
1.106.2.2 faziophi 380: }
381: }
382: # if "data.deleted" does not exist, create it
383: my @deleted;
384: if (!exists($data{'data.deleted_fields'})) {
385: @deleted = [];
386: } else {
387: @deleted = @{thaw($data{'data.deleted_fields'})};
388: }
389: # only if deleted does not exist in 'data.deleted', push it
390: my $push = 1;
391: for (my $i = 0; $i < length(@deleted); $i++) {
392: if ($deleted[$i] eq $field) {
393: $push = 0;
394: last;
395: }
396: }
397: unless (!$push) {
398: push(@deleted, $field);
399: }
400: $data{'data.fields'} = freeze(\@fields);
401: $data{'data.deleted_fields'} = freeze(\@deleted);
402:
403: &Apache::lonnet::put('syllabus',\%data,$cdom,$cnum);
404: }
405: }
406: if (($allowed) && ($env{'form.rename'})) {
407: my $field = $env{'form.rename'};
408: my $new_title = "Hello, World!";
409: chomp($field);
410: $field=~s/[^0-9_]//g;
411: #check if the field exists
412: #do not delete if file in v2 conversion mode
413: if (exists($data{'data.field.'.$field}) &&
414: !exists($data{'properties.v2_converted'})) {
415: #sanitize HTML content
1.106.2.3 faziophi 416: #$r->print("Rename -- field found.<br />");
1.106.2.2 faziophi 417: my %db_entry = %{thaw($data{'data.field.'.$field})};
418: $new_title = &Apache::lonfeedback::clear_out_html($new_title, 1);
419: $db_entry{title} = $new_title;
420: $data{'data.field.'.$field} = freeze(\%db_entry);
421: &Apache::lonnet::put('syllabus',\%data,$cdom,$cnum);
1.106.2.1 faziophi 422: }
423: }
1.90 amueller 424: if (($allowed) && ($env{'form.storesyl'})) {
1.106.2.1 faziophi 425: foreach my $syl_field (@fields) {
1.90 amueller 426: my $field=$env{'form.'.$syl_field};
1.106.2.1 faziophi 427: my $type;
428: my %field_hash;
429: # only update a field if it already exists!
430: if (exists($data{'data.field.'.$syl_field})) {
1.106.2.3 faziophi 431: #$r->print("Creating/updated field ".$syl_field."<br />");
1.106.2.1 faziophi 432: %field_hash = exists($data{'data.field.'.$syl_field}) ?
1.106.2.2 faziophi 433: %{thaw($data{'data.field.'.$syl_field})} : ();
1.106.2.1 faziophi 434: $type = exists($field_hash{type}) ? $field_hash{type} : TYPE_TEXT_HTML;
435: chomp($field);
436: $field=~s/\s+$//s;
437: $field=~s/^\s+//s;
438: $field=~s/\<br\s*\/*\>$//s;
439: $field=&Apache::lonfeedback::clear_out_html($field,1);
440: $field_hash{content}=$field;
441: if ($type eq TYPE_URL_INCLUDE) { # clean up included URLs
442: my $field='';
443: foreach my $value (split(/\n/,$field_hash{content})) {
444: my $url=$value;
445: # get rid of leading and trailing spaces
446: $url=~s/^\s+//;
447: $url=~s/\s+$//;
448: if ($url=~m|^https?\://([^/]+)/(.+)$|) {
449: my $host = $1;
450: my $remainder=$2;
451: # remove the hostname from internal URLs
452: my $hostname = &Apache::lonnet::hostname($host);
453: my %all_hostnames = &Apache::lonnet::all_hostnames();
454: foreach my $possible_host (keys(%all_hostnames)) {
455: if ($possible_host =~ /\Q$hostname\E/i) {
456: $url=$remainder;
457: }
458: }
459: }
460: # norm internal URLs
461: unless ($url=~/^https?\:/) {
462: $url=&Apache::lonnet::clutter($url);
463: }
464: # re-assemble field
465: if ($url) {
466: $field.=$url."\n";
467: }
468: }
469: $field_hash{content}=$field;
470: $field_hash{type}=TYPE_URL_INCLUDE;
471: }
472: $data{'data.field.'.$syl_field} = freeze(\%field_hash);
473: }
474: }
475: $data{'uploaded.domain'}=$env{'user.domain'};
476: $data{'uploaded.name'}=$env{'user.name'};
477: my $time = $^T;
478: $data{'uploaded.lastmodified'}=$time;
479: $data{'properties.last_modified'}=$time;
480: delete $data{'properties.v2_converted'};
481: delete $data{'properties.v2_conflict'};
482: delete $data{'properties.v2_conflict_fail'};
483: &Apache::lonnet::del('syllabus', ['properties.v2_converted',
484: 'properties.v2_conflict', 'properties.v2_conflict_fail'], $cdom, $cnum);
485:
486: #2.x compatibility: write to old fields with new mapped fields
487: my %old_new_map = %{thaw($data{'data.old_new_map'})};
488: foreach my $old_field (keys(%old_new_map)) {
1.106.2.3 faziophi 489: #$r->print("Looking for: ".$old_field." at ".$old_new_map{$old_field}."<br />");
1.106.2.1 faziophi 490: if (exists($data{'data.field.'.$old_new_map{$old_field}})) {
1.106.2.3 faziophi 491: #$r->print("updating old field ".$old_field."<br />");
1.106.2.1 faziophi 492: my %new_field = %{thaw($data{'data.field.'.$old_new_map{$old_field}})};
493: $data{$old_field} = $new_field{content};
494: }
1.90 amueller 495: }
1.106.2.1 faziophi 496:
497: &Apache::lonnet::put('syllabus',\%data,$cdom,$cnum);
1.90 amueller 498: }
1.4 www 499: }
1.85 bisitz 500:
1.93 bisitz 501: #--------Functions
1.94 droeschl 502: if( ($allowed || $privileged) && $target ne 'tex') {
503: my $functions=&Apache::lonhtmlcommon::start_funclist();
504: if ($allowed) {
1.97 amueller 505: #if you have the register flag, keep it
506: if($env{'form.register'} == 1) {
507: $functions.=&Apache::lonhtmlcommon::add_item_funclist(
1.99 amueller 508: '<a href="'.$r->uri.'?forcestudent=1&register=1">'
1.97 amueller 509: .&mt('Show Public View').'</a>'
510: .&Apache::loncommon::help_open_topic(
511: 'Uploaded_Templates_PublicView'));
512: } else {
513: $functions.=&Apache::lonhtmlcommon::add_item_funclist(
1.94 droeschl 514: '<a href="'.$r->uri.'?forcestudent=1">'
515: .&mt('Show Public View').'</a>'
516: .&Apache::loncommon::help_open_topic(
517: 'Uploaded_Templates_PublicView'));
1.97 amueller 518: }
1.93 bisitz 519: } elsif ($privileged) {
1.97 amueller 520: if($env{'form.register'} == 1) {
521: $functions.=&Apache::lonhtmlcommon::add_item_funclist(
1.99 amueller 522: '<a href="'.$r->uri.'?forceedit=1&register=1">'
1.97 amueller 523: .&mt('Edit').'</a>');
524: } else {
525: $functions.=&Apache::lonhtmlcommon::add_item_funclist(
1.94 droeschl 526: '<a href="'.$r->uri.'?forceedit=1">'
527: .&mt('Edit').'</a>');
1.97 amueller 528: }
1.93 bisitz 529: }
1.94 droeschl 530:
1.93 bisitz 531: $functions.=&Apache::lonhtmlcommon::end_funclist();
532: $r->print(&Apache::loncommon::head_subbox($functions));
533: }
534:
1.94 droeschl 535: #---------------------Print External URL Syllabus Info and Help Text
1.90 amueller 536: if( ($allowed) && ($target ne 'tex') ) {
1.91 amueller 537: my $protocol = $Apache::lonnet::protocol{$homeserver};
538: $protocol = 'http' if ($protocol ne 'https');
1.85 bisitz 539: $r->print('<p class="LC_info">'
540: .&mt('This syllabus can be publicly viewed at [_1]'
541: ,'<tt>'.$protocol.'://'.&Apache::lonnet::hostname($homeserver).$r->uri.'</tt>')
542: .' '.&Apache::loncommon::help_open_topic('Syllabus_ExtLink')
543: .'</p>'
544: .'<p class="LC_info">'
1.96 raeburn 545: .&mt('Instead of using this template you can specify an external URL as Syllabus in the [_1]Course Configuration[_2].'
1.99 amueller 546: ,'<a href="/adm/courseprefs?actions=courseinfo&phase=display">','</a>')
1.85 bisitz 547: .'</p>'
548: );
1.94 droeschl 549: #-Print Help Text
550: $r->print(&Apache::loncommon::help_open_topic(
551: 'Uploaded_Templates_TextBoxes',
552: &mt('Help with filling in text boxes')));
1.90 amueller 553: }
1.85 bisitz 554:
1.88 amueller 555: #----------Print last update
1.90 amueller 556: my $lastmod=$syllabus{'uploaded.lastmodified'};
557: $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
558: my $who = &Apache::loncommon::aboutmewrapper(
559: &Apache::loncommon::plainname($syllabus{'uploaded.name'},
560: $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
561: $syllabus{'uploaded.domain'});
562: if ($target ne 'tex') {
1.91 amueller 563: $r->print('<div class="LC_info">'.&mt('Last updated').': '.
564: $lastmod . ' '.
565: ($who ? &mt('by').' '.$who
1.89 bisitz 566: : '' ) .
1.88 amueller 567: '</div>' );
1.89 bisitz 568:
1.90 amueller 569: } else {
1.91 amueller 570: $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.
571: ($who? &mt('by').'\\\\ '.
572: &Apache::loncommon::plainname($syllabus{'uploaded.name'},$syllabus{'uploaded.domain'})
573: :'')
574: .'\\\\');
1.90 amueller 575: }
1.106.2.1 faziophi 576: if ($allowed && $data{'properties.v2_converted'} == 1) {
577: $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/>");
578: }
579: if ($allowed && $data{'properties.v2_conflict'} == 1) {
580: $r->print("<em>This document was saved with LON-CAPA 3.x, then further edited in LON-CAPA 2.x.</em><br/>");
581: if ($data{'properties.v2_conflict_fail'} == 1) {
582: $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 />");
583: } else {
584: $r->print("<em>These changes were automatically transferred to LON-CAPA 3.x</em>");
585: }
586: }
587:
1.80 neumanie 588: #----------------------------Print Headtitle
1.90 amueller 589: if ($target ne 'tex') {
1.91 amueller 590: $r->print('<h1>'.$courseenv{'description'}.'</h1>');
591: $r->print('<h3>'. &Apache::lonnet::domain($cdom,'description').'</h3>');
1.90 amueller 592: } else {
1.91 amueller 593: $r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
594: &Apache::lonnet::domain($cdom,'description').'}\\\\');
1.90 amueller 595: }
1.106.2.1 faziophi 596:
1.80 neumanie 597: # -------------------------------------------------------- Get course personnel
598: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
599: if ($target ne 'tex') {
1.91 amueller 600: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1.80 neumanie 601: } else {
1.91 amueller 602: $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
1.80 neumanie 603: }
604: my @personnel=sort(keys(%coursepersonnel));
605: my $lastpers=$personnel[$#personnel];
606: foreach my $element (@personnel) {
1.91 amueller 607: if ($target ne 'tex') {
608: $r->print(&Apache::lonhtmlcommon::row_title($element));
609: } else {
610: $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & ');
611: }
1.80 neumanie 612: foreach (split(/\,/,$coursepersonnel{$element})) {
1.91 amueller 613: my ($puname,$pudom)=split(/\:/,$_);
614: if ($target ne 'tex') {
1.80 neumanie 615: my $courseperson = &Apache::loncommon::plainname($puname,$pudom);
616: if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
617: ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
1.91 amueller 618: $r->print(' '.$courseperson);
1.80 neumanie 619: } else {
620: $r->print(' '.&Apache::loncommon::aboutmewrapper($courseperson,
621: $puname,$pudom));
622: }
1.91 amueller 623: } else {
624: $r->print(' '.&Apache::loncommon::plainname($puname,
1.80 neumanie 625: $pudom).' ');
1.91 amueller 626: }
627: }
628: if ($target ne 'tex') {
1.80 neumanie 629: my $lastclose=$element eq $lastpers?1:0;
630: $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
1.91 amueller 631: } else {
632: $r->print('\\\\ \hline');
633: }
1.80 neumanie 634: }
635: if ($target ne 'tex') {
1.91 amueller 636: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1.80 neumanie 637: } else {
1.91 amueller 638: $r->print('\end{tabular}\\\\');
1.80 neumanie 639: }
1.79 neumanie 640: # -------------------------------------------------------------- Announcements?
641: my $day = &Apache::lonannounce::showday(time,2,
1.91 amueller 642: &Apache::lonannounce::readcalendar($cdom.'_'.$cnum));
1.80 neumanie 643: if ($target ne 'tex') {
1.106.2.3 faziophi 644: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.106.2.4! faziophi 645: &print_activity_bar($r, \%data, $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML);
1.106.2.3 faziophi 646: &print_field_sortable($r, \%data, $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML);
1.91 amueller 647: }
1.106.2.3 faziophi 648: $r->print("<div id='syllabus-content'>\n");
1.86 bisitz 649:
1.79 neumanie 650: } else {
1.91 amueller 651: $r->print(&Apache::lonxml::xmlparse($r,'tex',$day));
1.86 bisitz 652: }
1.106.2.1 faziophi 653:
1.79 neumanie 654: # ---------------------------------------------------------------- Get syllabus
1.86 bisitz 655: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.90 amueller 656: if ($allowed) {
1.106.2.3 faziophi 657: $r->print('<form id="syllabus-form" method="post" action="">'.
1.91 amueller 658: '<input type="hidden" name="forceedit" value="edit" />');
1.90 amueller 659: }
660: my @htmlids=();
1.106 faziophi 661: my $url_include_handler = sub {
1.106.2.1 faziophi 662: my ($r, $field, $json_ref, $group, $target, $allowed) = @_;
663: my $message = $json_ref->{items}{$field}{content};
664: my $title = $json_ref->{items}{$field}{title};
665: my $urls = $message;
1.106 faziophi 666: foreach my $filelink (split(/\n/,$urls)) {
667: my $output='';
668: # embed style?
669: my ($curfext)=($filelink=~/\.([^\.]+)$/);
670: my $embstyle=&Apache::loncommon::fileembstyle($curfext);
671: if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {# make ssi call and remove everything but the body contents
672: $output=&Apache::lonnet::ssi_body($filelink);
673: } elsif ($embstyle eq 'img') {# embed as an image
674: $output='<img src="'.$filelink.'" />';
675: }
676: if ($output ne '') {
1.106.2.1 faziophi 677: $message='';
1.106 faziophi 678: if ($target ne 'tex') {
679: $message.='<p>'.$output.'</p>';
680: } else {
681: $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
682: }
683: }
684: }
685: if ($allowed) {
686: &Apache::lonfeedback::newline_to_br(\$urls);
1.106.2.1 faziophi 687: &Apache::lontemplate::print_start_template($r,$title.
1.106 faziophi 688: &Apache::loncommon::help_open_topic('Syllabus_URLs'),'LC_Box');
689: $r->print($urls);
690: $r->print("<br /><div>");
1.106.2.1 faziophi 691: &Apache::lontemplate::print_textarea_template($r, $message,
1.106 faziophi 692: $field, Apache::lontemplate->RICH_TEXT_ALWAYS_OFF);
693: &Apache::lontemplate::print_saveall_template($r);
694: $r->print("</div>");
695: &Apache::lontemplate::print_end_template($r);
1.86 bisitz 696:
1.106 faziophi 697: } else {
698: $r->print($message);
699: }
700: };
1.106.2.1 faziophi 701: my %custom_hash = ( TYPE_URL_INCLUDE() => $url_include_handler );
702: @htmlids = &print_template_new_fields($r, \%data,
703: $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_hash);
1.90 amueller 704: if ($allowed) {
1.106.2.4! faziophi 705: $r->print('</form>');
! 706: #&Apache::lonhtmlcommon::htmlareaselectactive(@htmlids));
1.90 amueller 707: }
1.106.2.3 faziophi 708: if ($target ne 'tex') {$r->print('</div><p style="clear:both"> </p>');}
709: if ($allowed) {
710: &Apache::lontemplate::print_start_template($r,'RSS Feeds and Blogs','LC_Box');
711: $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit));
712: my $editurl= &Apache::lonnet::absolute_url().'/adm/'.$cdom.'/'.$cnum.'/_rss.html';
713: $r->print( '<a href="'.$editurl.'">'.&mt('New RSS Feed or Blog').'</a>');
714: &Apache::lontemplate::print_end_template($r);
715: } elsif (&Apache::lonrss::advertisefeeds($cnum,$cdom) ne '') {
716: &Apache::lontemplate::print_start_template($r,'RSS Feeds and Blogs','LC_Box');
717: $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit));
718: &Apache::lontemplate::print_end_template($r);
719: }
1.4 www 720: } else {
1.91 amueller 721: if ($target ne 'tex') {$r->print('<p>');} else {$r->print('\par ');}
722: $r->print(&mt('No syllabus information provided.'));
723: if ($target ne 'tex') {$r->print('</p>');}
1.1 www 724: }
1.86 bisitz 725: if ($target ne 'tex') {
1.65 raeburn 726: if ($env{'form.backto'} eq 'coursecatalog') {
727: $r->print('<form name="backtocat" method="post" action="/adm/coursecatalog">'.
1.66 raeburn 728: &Apache::lonhtmlcommon::echo_form_input(['backto','courseid']).
1.65 raeburn 729: '</form>');
730: }
1.91 amueller 731: $r->print(&Apache::loncommon::end_page());
1.48 albertel 732: } else {
1.91 amueller 733: $r->print('\end{document}');
1.48 albertel 734: }
1.1 www 735: return OK;
1.86 bisitz 736: }
1.1 www 737:
1.106.2.4! faziophi 738: sub print_activity_bar {
! 739: my ($r, $data_ref, $target, $allowed, $default_rich_text, $group) = @_;
! 740: $r->print("<div id='activity-bar'>
! 741: <button id='save-button' type='button' class='LC_ActivityBarButton LC_ActivityBarButton-IconLeft ui-state-default ui-priority-primary ui-corner-all'>
! 742: <span class='ui-icon ui-icon-disk'></span><a href='#'>Save</a>
! 743: </button>
! 744:
! 745: </div>");
! 746: }
! 747:
1.106.2.3 faziophi 748: sub print_field_sortable {
749: my ($r, $data_ref, $target, $allowed, $default_rich_text, $group) = @_;
750: my %data = %{$data_ref};
751: my @fields = @{thaw($data{'data.fields'})};
752: $r->print("<div id='scrollable-fields-container'>
753: <div id='syllabus-fields-container'>
754: <ui id='syllabus-fields' class='LC_Sortable LC_SyllabusFields'>\n");
755: foreach my $key (@fields) {
756: my %field = %{thaw($data{'data.field.'.$key})};
1.106.2.4! faziophi 757: $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 left'></span><span id='remove-$key' class='RemoveSection right ui-icon ui-icon-closethick' title='Delete'></span>$field{title}</li>\n");
1.106.2.3 faziophi 758: }
759: $r->print("
760: </ui>
761: </div>
1.106.2.4! faziophi 762: <div id='syllabus-fields-actions'>
! 763: <button id='add-section-button' type='button' class='LC_ActivityBarButton LC_ActivityBarButton-IconLeft ui-state-default ui-priority-secondary ui-corner-all'>
! 764: <span class='ui-icon ui-icon-circle-plus'></span><a href='#'>Add Section</a>
! 765: </button>
! 766: <button id='revert-order-button' type='button' class='LC_ActivityBarButton LC_ActivityBarButton-IconLeft ui-state-default ui-priority-secondary ui-corner-all'>
! 767: <span class='ui-icon ui-icon-arrowreturnthick-1-w'></span><a href='#'>Revert Order</a>
! 768: </button>
! 769: </div>
1.106.2.3 faziophi 770: </div>\n");
771: }
772:
1.106.2.1 faziophi 773: sub print_template_new_fields {
774: my ($r, $data_ref, $target, $allowed, $default_rich_text, $custom_handlers_ref, $group) = @_;
775: my @html_ids = ();
776: my %data = %{$data_ref};
777: my @fields = @{thaw($data{'data.fields'})};
778: my %custom_handlers = %{$custom_handlers_ref};
779:
780: foreach my $key (@fields) {
781: my %field = %{thaw($data{'data.field.'.$key})};
782: my $title = $field{title};
783: my $raw_message = $field{content};
784: my $type = $field{type};
785: my $message = $raw_message if (($raw_message=~/\w/) || ($allowed));
786: if ((%custom_handlers) && exists($custom_handlers{$type})) {
787: #$custom_handlers{$type}->($r, $field, $json_ref, $group, $target, $allowed);
788: } else {
789: if (($raw_message=~/\w/) || ($allowed)) {
790: if (!&Apache::lonfeedback::contains_block_html($message)) {
791: &Apache::lonfeedback::newline_to_br(\$message);
792: } else {
793: $message = &Apache::lonfeedback::tidy_html($message);
794: }
795: $message=&Apache::lonhtmlcommon::raw_href_to_link($message);
796: if ($allowed) {
797: $message=&Apache::lonspeller::markeduptext($message);
798: }
799: $message=&Apache::lontexconvert::msgtexconverted($message);
800: if ($target ne 'tex') {
801: #output of syllabusfields will be generated here.
1.106.2.3 faziophi 802: &Apache::lontemplate::print_start_template($r,$title,'LC_Box', 'box-'.$key);
1.106.2.1 faziophi 803: $r->print($message);
804: if ($allowed) {
805: $r->print("<br /><div>");
806: &Apache::lontemplate::print_textarea_template($r, $raw_message,
807: $key, $default_rich_text);
808: &Apache::lontemplate::print_saveall_template($r);
809: if (!exists($data{'properties.v2_converted'})) {
1.106.2.2 faziophi 810: $r->print("<a href='?delete=$key&forceedit=1'>Delete</a> ");
811: $r->print("<a href='?rename=$key&forceedit=1'>Rename to \"Hello, World!\"</a>");
1.106.2.1 faziophi 812: }
813: $r->print("</div>");
814: }
815: &Apache::lontemplate::print_end_template($r);
816: } else {
817: my $safeinit;
818: $r->print(&Apache::lonxml::xmlparse($r,'tex','<h3>'.$title.'</h3>'));
819: $r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
820: }
821: push(@html_ids,"hello");
822: }
823: }
824: }
825:
826: return @html_ids;
827: }
828:
829: sub convert_from_v2 {
830: my ($r, $data_ref, $fields_ref, $conflict) = @_;
831: my %data = %{$data_ref};
832: my %fields = %{$fields_ref};
833: my @fields_order = (!$conflict) ? () : @{thaw($data{'data.fields'})};
834: my %old_new_map = (!$conflict) ? () : %{thaw($data{'data.old_new_map'})};
835: my $repeat_int = 0; #ensure fields with created timestamp are unique
836: foreach my $element (sort(keys(%fields))) {
837: my %new_element = ();
838: my $title = $fields{$element};
839: my $title_hash = time."_".$$;
840: if (exists($data{'data.field.'.$title_hash})) {
841: $title_hash .= "_".$repeat_int++;
842: }
843: my $content = $data{$element};
844: $new_element{title} = $title;
845: $new_element{content} = $content;
846: if ($element eq 'lll_includeurl') {
847: $new_element{type} = TYPE_URL_INCLUDE;
848: } else {
849: $new_element{type} = TYPE_TEXT_HTML;
850: }
851: if (!$conflict) {
852: $r->print("Creating new field with ID: ".$title_hash."<br />");
853: $data{'data.field.'.$title_hash} = freeze(\%new_element);
854: $old_new_map{$element} = $title_hash;
855: push(@fields_order, $title_hash);
856: } else {
857: if (exists($old_new_map{$element})) {
858: $r->print("Transferring old field ".$element." to new ID: ".$old_new_map{$element}."<br />");
859: if (exists($data{'data.field.'.$old_new_map{$element}})) {
860: my %new_field = %{thaw($data{'data.field.'.$old_new_map{$element}})};
861: $new_field{content} = $content;
862: $data{'data.field.'.$old_new_map{$element}} = freeze(\%new_field);
863: }
864: } else {
865: $data{'data.field.'.$title_hash} = freeze(\%new_element);
866: $old_new_map{$element} = $title_hash;
867: $data{'properties.v2_conflict_fail'} = 1;
868: push(@fields_order, $title_hash);
869: }
870: }
871: }
872: $data{'data.fields'} = freeze(\@fields_order);
873: $data{'data.old_new_map'} = freeze(\%old_new_map);
874: $data{'properties.last_modified'} = time;
875: $data{'properties.v2_converted'} = 1;
876: $data{'properties.type'} = 'syllabus';
877:
878: return \%data;
879: }
880:
1.1 www 881: 1;
882: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>