Annotation of loncom/interface/lonsyllabus.pm, revision 1.106.2.5

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>