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

1.1       www         1: # The LearningOnline Network
                      2: # Syllabus
                      3: #
1.122   ! raeburn     4: # $Id: lonsyllabus.pm,v 1.121 2013/05/09 05:43:30 raeburn 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.1       www        43: 
                     44: sub handler {
                     45:     my $r = shift;
1.46      www        46:     &Apache::loncommon::content_type($r,'text/html');
                     47:     $r->send_http_header;
                     48:     return OK if $r->header_only;
1.45      www        49: 
1.46      www        50:     my $target=$env{'form.grade_target'};
1.45      www        51: # --------------------------------------------------- Get course info from URL
                     52:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.46      www        53: # ------------------------------------------------------------ Get query string
                     54:     &Apache::loncommon::get_unprocessed_cgi
1.116     raeburn    55:                         ($ENV{'QUERY_STRING'},['register','forceedit','todocs',
1.115     raeburn    56:                                                'folderpath','title']);
1.45      www        57: # ----------------------------------------------------- Is this even a course?
                     58:     my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom);
                     59:     if ($homeserver eq 'no_host') {
                     60:         &Apache::loncommon::content_type($r,'text/html');
                     61:         $r->send_http_header;
1.106     faziophi   62:         &Apache::loncommon::simple_error_page($r,'No syllabus available',
1.91      amueller   63:                           'No syllabus available');
1.45      www        64:         return OK;
1.113     raeburn    65:     } elsif (!&Apache::lonnet::is_course($cdom,$cnum)) {
                     66:         &Apache::loncommon::content_type($r,'text/html');
                     67:         $r->send_http_header;
                     68:         &Apache::loncommon::simple_error_page($r,'No syllabus available',
                     69:                           'The course/community for which the syllabus was requested does not exist.');
                     70:         return OK;
1.45      www        71:     }
                     72: # ------------------------------------- There is such a course, get environment
                     73:     my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.46      www        74: 
1.1       www        75: # ------------------------------------------------------------ Print the screen
1.49      albertel   76: 
                     77:     if ($target eq 'tex') {
1.91      amueller   78:         $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.86      bisitz     79:     }
1.117     raeburn    80: 
                     81: # --------------------------------------------------------------- Force Student
                     82:     my ($forceedit,$forcestudent);
                     83:     if ($env{'form.forceedit'}) { $forceedit=1; }
                     84:     if (!$forceedit) {
                     85:         $forcestudent=1;
                     86:     }
                     87: 
                     88: # --------------------------------------------------------------- Check Privileges
                     89:     my $allowed = 0;
                     90:     if ($env{'user.environment'}) {
                     91: # does this user have privileges to post, etc?
                     92:         if ($env{'request.course.id'}
                     93:         && $cdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}
                     94:         && $cnum eq $env{'course.'.$env{'request.course.id'}.'.num'}) {
                     95:             $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
                     96:             if ($forcestudent or $target eq 'tex') { $allowed=0; }
                     97:         }
                     98:     }
                     99: 
1.46      www       100: # -------------------------------------------------- Let's see who handles this
1.117     raeburn   101:     my $external=$courseenv{'externalsyllabus'};
                    102:     my $uploaded=$courseenv{'uploadedsyllabus'};
1.122   ! raeburn   103:     my $minimal=$courseenv{'minimalsyllabus'};
1.49      albertel  104: 
1.122   ! raeburn   105:     if (($minimal =~/\w/) || ($uploaded =~/\w/)) { 
        !           106:         my $item;
        !           107:         if ($minimal =~/\w/) {
        !           108:             if ($external =~ m{\Q$minimal\E$}) {
        !           109:                 undef($external);
        !           110:             }
        !           111:             $item = $minimal;
        !           112:         } elsif ($uploaded =~/\w/) {
        !           113:             if ($external =~ m{\Q$uploaded\E$}) {
        !           114:                 undef($external);
        !           115:             }
        !           116:             $item = $uploaded;
1.117     raeburn   117:         }
                    118:         unless ($allowed && $forceedit) {
1.122   ! raeburn   119:             my $file=&Apache::lonnet::filelocation("",$item);
1.117     raeburn   120:             if ($file =~ /\.(sty|css|js|txt|tex|html?)$/) {  
                    121:                 my $filetype;
                    122:                 if ($file =~ /\.(sty|css|js|txt|tex)$/) {
                    123:                     $filetype=$1;
                    124:                 } else {
                    125:                     $filetype='html';
                    126:                 }
                    127:                 my $result = '';
                    128:                 my $filecontents=&Apache::lonnet::getfile($file);
                    129:                 if ($filecontents eq -1) {
                    130:                     $r->print(&mt('Syllabus file unavailable'));
                    131:                 } elsif ($filetype eq 'html') {
                    132:                     my %mystyle;
                    133:                     &Apache::structuretags::reset_problem_globals();
                    134:                     my $oldfile = $env{'request.filename'};
1.122   ! raeburn   135:                     $env{'request.filename'} = $item;
1.117     raeburn   136:                     $result = &Apache::lonxml::xmlparse($r,'web',$filecontents,
                    137:                                                         '',%mystyle);
                    138:                     &Apache::structuretags::reset_problem_globals();
                    139:                     &Apache::lonhomework::finished_parsing();
                    140:                     $env{'request.filename'} = $oldfile;
                    141:                     &Apache::lonxml::add_messages(\$result);
                    142:                     $r->print($result);
                    143:                 }
                    144:             } else {
1.122   ! raeburn   145:                 $r->print(&Apache::lonwrapper::wrapper($item));
1.117     raeburn   146:             }
                    147:             return OK;
                    148:         }
                    149:     } elsif ($external=~/\w/) {
                    150:         unless ($allowed && $forceedit) {
                    151:             $r->print(&Apache::lonwrapper::wrapper($external));
                    152:             return OK;
                    153:         }
1.90      amueller  154:     }
1.42      www       155: 
1.120     raeburn   156:     my $crstype = &Apache::loncommon::course_type();
                    157: 
1.46      www       158: # ------------------------------ The buck stops here: internal syllabus display
1.5       www       159: # --------------------------------------------------------- The syllabus fields
1.23      www       160:     my %syllabusfields=&Apache::lonlocal::texthash(
1.5       www       161:        'aaa_instructorinfo' => 'Instructor Information',
                    162:        'bbb_description'    => 'Course Description',
                    163:        'ccc_prereq'         => 'Prerequisites',
1.7       www       164:        'cdc_classhours'     => 'Class Hours',
1.5       www       165:        'ddd_officehours'    => 'Office Hours',
                    166:        'eee_helproom'       => 'Helproom Hours',
1.7       www       167:        'efe_projectinfo'    => 'Project Information',
1.5       www       168:        'fff_examinfo'       => 'Exam Information',
1.7       www       169:        'fgf_deadlines'      => 'Deadlines',
1.5       www       170:        'ggg_grading'        => 'Grading Information',
1.7       www       171:        'hhh_readings'       => 'Readings',
                    172:        'iii_coursepack'     => 'Coursepack',
                    173:        'jjj_weblinks'       => 'Web Links',
1.9       www       174:        'kkk_textbook'       => 'Textbook',
                    175:        'lll_includeurl'     => 'URLs To Include in Syllabus');
1.121     raeburn   176: # ---------------------------------------------------------- Load syllabus info
                    177:     my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
                    178:     my ($output,%displayfields,%noshow);
1.65      raeburn   179: 
1.121     raeburn   180: # This handler might be called anonymously ...
                    181: # ----------------------------------------------------- Only if not public call
                    182:     if ($allowed) {
1.122   ! raeburn   183:         if (($env{'form.choice'} =~ /^(template|minimal|url|file)$/) ||
1.121     raeburn   184:             ($env{'form.phase'} =~ /^(upload|check)_embedded$/)) {
                    185:             my $earlyout;
1.122   ! raeburn   186:             ($earlyout,$uploaded,$external,$minimal,$output) =
        !           187:                 &save_changes($cnum,$cdom,$uploaded,$external,$minimal,
        !           188:                               \%syllabus,\%syllabusfields,\%courseenv);
        !           189:             if (($env{'form.choice'} eq 'minimal') && 
        !           190:                 ($minimal eq "/uploaded/$cdom/$cnum/portfolio/syllabus/loncapa.html")) { 
        !           191:                 delete($env{'form.symb'});
        !           192:                 delete($env{'request.symb'});
        !           193:                 $r->internal_redirect("$minimal?editmode=1&forceedit=1");
        !           194:                 return OK;
        !           195:             }
1.121     raeburn   196:             if ($earlyout) {
                    197:                 if ($target ne 'tex') {
                    198:                     &print_header($r,$cnum,$cdom,$crstype,$allowed,$forceedit,
                    199:                                   \%syllabus,\%syllabusfields);
1.122   ! raeburn   200:                     $r->print($output.
        !           201:                               &Apache::loncommon::end_page());
1.121     raeburn   202:                 }
                    203:                 return OK;
1.90      amueller  204:             }
1.65      raeburn   205:         }
                    206:     }
1.121     raeburn   207:     if ($target ne 'tex') {
                    208:         &print_header($r,$cnum,$cdom,$crstype,$allowed,$forceedit,\%syllabus,
                    209:                       \%syllabusfields);
                    210:         $r->print($output);
1.117     raeburn   211:     }
                    212: 
1.121     raeburn   213: # -------------------------------------------- Determine which fields are shown 
1.117     raeburn   214: 
1.121     raeburn   215:     if ($syllabus{'uploaded.fields'}) {
                    216:         if ($syllabus{'uploaded.fields'} eq 'none') {
                    217:             foreach my $field (keys(%syllabusfields)) {
                    218:                 $displayfields{$field} = ' style="display:none;"';
                    219:                 $noshow{$field} = 1;
1.117     raeburn   220:             }
                    221:         } else {
1.121     raeburn   222:             my %included;
                    223:             map { $included{$_} = 1; } split(/,/,$syllabus{'uploaded.fields'});
                    224:             foreach my $field (keys(%syllabusfields)) {
                    225:                 my ($prefix) = split(/_/,$field);
                    226:                 if ($included{$prefix}) {
                    227:                     $displayfields{$field} = ' style="display:block;"';
1.117     raeburn   228:                 } else {
1.121     raeburn   229:                     $displayfields{$field} = ' style="display:none;"';
                    230:                     $noshow{$field} = 1;
1.117     raeburn   231:                 }
                    232:             }
                    233:         }
1.121     raeburn   234:     } else {
1.117     raeburn   235:         foreach my $field (keys(%syllabusfields)) {
                    236:             if ($syllabus{$field} ne '') {
                    237:                 $displayfields{$field} = ' style="display:block;"';
                    238:             } else {
                    239:                 $displayfields{$field} = ' style="display:none;"';
                    240:             }
1.90      amueller  241:         }
1.4       www       242:     }
1.85      bisitz    243: 
1.113     raeburn   244:     if ($allowed) {
                    245: #---------------------------------- Print External URL Syllabus Info if editing
                    246:         if ($target ne 'tex') {
                    247:             my $protocol = $Apache::lonnet::protocol{$homeserver};
                    248:             $protocol = 'http' if ($protocol ne 'https');
1.119     raeburn   249:             my $link = $protocol.'://'.&Apache::lonnet::hostname($homeserver).$r->uri;
                    250:             $r->print('<div class="LC_left_float">'
                    251:                      .'<span class="LC_help_open_topic LC_info">'
                    252:                      .'<span class="LC_info">'
                    253:                      .&mt('Public link (no log-in): [_1]','<tt>'.$link.'</tt>')
                    254:                      .'&nbsp;</span>'.&Apache::loncommon::help_open_topic('Syllabus_ExtLink')
                    255:                      .'</span>'
1.121     raeburn   256:                      .'</div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n");
1.117     raeburn   257:             my $lonhost = $r->dir_config('lonHostID');
1.122   ! raeburn   258:             $r->print(&chooser($external,$uploaded,$minimal,$cdom,$cnum,$lonhost,
        !           259:                                \%syllabusfields,\%syllabus));
1.93      bisitz    260:         }
1.109     bisitz    261:     } else {
1.113     raeburn   262: #--------------------------------------------- Print last update unless editing
                    263:         my $lastmod=$syllabus{'uploaded.lastmodified'};
                    264:         $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
                    265:         my $who;
                    266:         if ($syllabus{'uploaded.lastmodified'}) {
                    267:             if (($env{'user.name'} ne 'public') && ($env{'user.domain'} ne 'public')) {
                    268:                 $who = &Apache::loncommon::aboutmewrapper(
                    269:                        &Apache::loncommon::plainname($syllabus{'uploaded.name'},
                    270:                        $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
                    271:                        $syllabus{'uploaded.domain'});
                    272:             } else {
                    273: # Public user?
                    274: # Only display name of user, but no link to personal information page
                    275:                 $who = &Apache::loncommon::plainname(
                    276:                            $syllabus{'uploaded.name'},
                    277:                            $syllabus{'uploaded.domain'});
                    278:             }
                    279:         }
                    280:         if ($target ne 'tex') {
                    281:             $r->print('<div class="LC_info">'.&mt('Last updated').': '.
                    282:                       $lastmod . ' '.
                    283:                       ($who ? &mt('by').' '.$who
                    284:                            : '' ) .
                    285:                       '</div>' );
                    286:         } else {
                    287:             $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.
                    288:                      ($who? &mt('by').'\\\\ '.
                    289:                      &Apache::loncommon::plainname($syllabus{'uploaded.name'},$syllabus{'uploaded.domain'})
                    290:                      :'')
                    291:                     .'\\\\');
                    292:         }
1.109     bisitz    293:     }
                    294: 
1.113     raeburn   295: #-------------------------------------------------------------- Print Headtitle
1.90      amueller  296:     if ($target ne 'tex') {
1.117     raeburn   297:         my $display = 'block';
1.122   ! raeburn   298:         if ($external || $uploaded || $minimal) {
1.117     raeburn   299:             $display = 'none';
                    300:         }
                    301:         $r->print('<div class="LC_Box" id="template" style="display: '.$display.'">'.
1.113     raeburn   302:                    '<h2 class="LC_hcell">'.$courseenv{'description'}.'</h2>');
                    303:         if ($allowed) {
1.121     raeburn   304:             $r->print('<div style="margin: 0; float:left;">'.
                    305:                       '<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>'.
                    306:                       '</div>');
1.113     raeburn   307: # Print Help Text if editing at right side of screen
1.121     raeburn   308:             $r->print('<div style="margin: 0; float:right;">'.
                    309:                       &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).
                    310:                       '</div><br clear="all" />');
1.113     raeburn   311:         } else {
                    312:             $r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>');
                    313:         }
1.90      amueller  314:     } else {
1.91      amueller  315:         $r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
                    316:         &Apache::lonnet::domain($cdom,'description').'}\\\\');
1.90      amueller  317:     }
1.80      neumanie  318: # -------------------------------------------------------- Get course personnel
1.121     raeburn   319:     my $hidepersonnel;
                    320:     if (($syllabus{'uploaded.fields'}) &&
                    321:         (($syllabus{'uploaded.fields'} eq 'none') ||
                    322:          ($syllabus{'uploaded.fields'} !~ /000/))) {
                    323:         $hidepersonnel = 1;
                    324:     }
1.80      neumanie  325:     if ($target ne 'tex') {
1.121     raeburn   326:         if ($allowed) {
                    327:             my $display = ' style="display:block;"';
                    328:             if ($hidepersonnel) {
                    329:                 $display = ' style="display:none;"';
                    330:             }
                    331:             &Apache::lontemplate::print_start_template($r,&mt('Personnel'),'LC_Box',
                    332:                                                        'box_000_showpeople',$display);
                    333:             $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed));
                    334:             &Apache::lontemplate::print_end_template($r);
1.91      amueller  335:         } else {
1.121     raeburn   336:             unless ($hidepersonnel) {
                    337:                 &Apache::lontemplate::print_start_template($r,&mt('Personnel'),'LC_Box');
                    338:                 $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed));  
                    339:                 &Apache::lontemplate::print_end_template($r);
1.91      amueller  340:             }
                    341:         }
1.121     raeburn   342:     } else {
                    343:         unless ($hidepersonnel) {
                    344:             $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed));
1.91      amueller  345:         }
1.80      neumanie  346:     }
1.79      neumanie  347: # -------------------------------------------------------------- Announcements?
                    348:     my $day = &Apache::lonannounce::showday(time,2,
1.91      amueller  349:              &Apache::lonannounce::readcalendar($cdom.'_'.$cnum));
1.121     raeburn   350:     my $hidefeeds;
                    351:     if (($syllabus{'uploaded.fields'}) &&
                    352:         (($syllabus{'uploaded.fields'} eq 'none') ||
                    353:          ($syllabus{'uploaded.fields'} !~ /111/))) {
                    354:         $hidefeeds = 1;
                    355:     }
1.80      neumanie  356:     if ($target ne 'tex') {
1.91      amueller  357:         if ($allowed) {
1.117     raeburn   358:             my $display = ' style="display:block;"';
1.121     raeburn   359:             if ($hidefeeds) {
1.117     raeburn   360:                 $display = ' style="display:none;"';
                    361:             }
                    362:             &Apache::lontemplate::print_start_template($r,&mt('RSS Feeds and Blogs'),'LC_Box',
1.121     raeburn   363:                                                        'box_111_showrssfeeds',$display);
1.120     raeburn   364:             my ($numfeeds,$hiddenfeeds,$rsslinktext);
1.121     raeburn   365:             my $feeds=&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit,\$numfeeds,
                    366:                                                       \$hiddenfeeds);
1.120     raeburn   367:             if ($numfeeds) {
                    368:                 $r->print($feeds);
                    369:                 $rsslinktext = &mt('New RSS Feed or Blog');
                    370:             } else {
                    371:                 my $msg = '<br />'.
                    372:                           &mt("RSS Feeds and Blogs item is not included in a student's view of the syllabus.");
                    373:                 if ($hiddenfeeds) {
                    374:                     $r->print('<p class="LC_info">'.
                    375:                               &mt('All feeds currently hidden').
                    376:                               $msg.
                    377:                               '</p>');
                    378:                 } else {
                    379:                     $r->print('<p class="LC_info">'.
                    380:                               &mt('No current feeds').
                    381:                               $msg.
                    382:                               '</p>');
                    383:                 }
                    384:                 $rsslinktext = &mt('Manage Course RSS Feeds/Blogs');
                    385:                 if ($crstype eq 'Community') {
                    386:                     $rsslinktext = &mt('Manage Communiity RSS Feeds/Blogs');
                    387:                 }
                    388:             }
1.91      amueller  389:             my $editurl= &Apache::lonnet::absolute_url().'/adm/'.$cdom.'/'.$cnum.'/_rss.html';
1.120     raeburn   390:             $r->print( '<a href="'.$editurl.'">'.$rsslinktext.'</a>');
1.91      amueller  391:             &Apache::lontemplate::print_end_template($r);
1.117     raeburn   392:         } else {
1.121     raeburn   393:             unless ($hidefeeds) {
1.120     raeburn   394:                 my $feeds = &Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit);
                    395:                 if ($feeds ne '') {
1.117     raeburn   396:                     &Apache::lontemplate::print_start_template($r,&mt('RSS Feeds and Blogs'),'LC_Box');
1.120     raeburn   397:                     $r->print($feeds);
1.117     raeburn   398:                     &Apache::lontemplate::print_end_template($r);
                    399:                 }
                    400:             }
1.91      amueller  401:         }
1.79      neumanie  402:     } else {
1.91      amueller  403:         $r->print(&Apache::lonxml::xmlparse($r,'tex',$day));
1.86      bisitz    404:     }
1.79      neumanie  405: # ---------------------------------------------------------------- Get syllabus
1.86      bisitz    406:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.90      amueller  407:         if ($allowed) {
1.121     raeburn   408:             $r->print('<form method="post" action="">');
1.90      amueller  409:         }
1.117     raeburn   410: 
1.106     faziophi  411: 		my $url_include_handler = sub {
1.117     raeburn   412: 			my ($r, $field, $message, $group, $data_ref, $fields_ref, $target, $allowed, $display) = @_;
1.106     faziophi  413: 			my %data = %{$data_ref};
                    414: 			my %fields = %{$fields_ref};
                    415: 			my $urls=$message;
                    416: 			$message='';
                    417: 			foreach my $filelink (split(/\n/,$urls)) {
                    418: 				my $output='';
                    419: 			   # embed style?
                    420: 				my ($curfext)=($filelink=~/\.([^\.]+)$/);
                    421: 				my $embstyle=&Apache::loncommon::fileembstyle($curfext);
                    422: 				if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {# make ssi call and remove everything but the body contents
                    423: 					$output=&Apache::lonnet::ssi_body($filelink);
                    424: 				} elsif ($embstyle eq 'img') {# embed as an image
                    425: 					$output='<img src="'.$filelink.'" />';
                    426: 				}
                    427: 				if ($output ne '') {
                    428: 					   if ($target ne 'tex') {
                    429: 						   $message.='<p>'.$output.'</p>';
                    430: 					   } else {
                    431: 						   $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
                    432: 					   }
                    433: 				}
                    434: 			}
                    435: 			if ($allowed) {
                    436: 				 &Apache::lonfeedback::newline_to_br(\$urls);
                    437: 				 &Apache::lontemplate::print_start_template($r,$fields{$field}.
1.117     raeburn   438: 						  &Apache::loncommon::help_open_topic('Syllabus_URLs'),'LC_Box',
                    439:                                                   'box_'.$field,$display);
1.106     faziophi  440: 				 $r->print($urls);
                    441: 				 $r->print("<br /><div>");
                    442: 				 &Apache::lontemplate::print_textarea_template($r, $data{$field},
                    443: 					$field, Apache::lontemplate->RICH_TEXT_ALWAYS_OFF);
                    444: 				 &Apache::lontemplate::print_saveall_template($r);                         
                    445: 				 $r->print("</div>");
                    446: 				 &Apache::lontemplate::print_end_template($r);
1.86      bisitz    447: 
1.106     faziophi  448: 			} else {
                    449: 				$r->print($message);
                    450: 			}
                    451: 		};
                    452: 		my %custom_hash = ( 'lll_includeurl' => $url_include_handler );
1.110     raeburn   453: 		&Apache::lontemplate::print_template_fields($r, \%syllabus, \%syllabusfields, 
1.117     raeburn   454: 			$target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_hash,
1.121     raeburn   455:                         undef,\%displayfields,\%noshow);
1.90      amueller  456:         if ($allowed) {
1.91      amueller  457:             $r->print('</form>'.
1.110     raeburn   458:             &Apache::lonhtmlcommon::htmlareaselectactive());
1.90      amueller  459:         }
1.4       www       460:     } else {
1.112     bisitz    461:         if ($target ne 'tex') {$r->print('<p class="LC_info">');} else {$r->print('\par ');}
1.91      amueller  462:         $r->print(&mt('No syllabus information provided.'));
                    463:         if ($target ne 'tex') {$r->print('</p>');}
1.1       www       464:     }
1.86      bisitz    465:     if ($target ne 'tex') {
1.65      raeburn   466:         if ($env{'form.backto'} eq 'coursecatalog') {
                    467:             $r->print('<form name="backtocat" method="post" action="/adm/coursecatalog">'.
1.66      raeburn   468:                       &Apache::lonhtmlcommon::echo_form_input(['backto','courseid']).
1.65      raeburn   469:                       '</form>');
                    470:         }
1.91      amueller  471:         $r->print(&Apache::loncommon::end_page());
1.48      albertel  472:     } else {
1.91      amueller  473:         $r->print('\end{document}');
1.48      albertel  474:     }
1.1       www       475:     return OK;
1.86      bisitz    476: }
1.1       www       477: 
1.121     raeburn   478: sub print_header {
                    479:     my ($r,$cnum,$cdom,$crstype,$allowed,$forceedit,$syllabus,$syllabusfields) = @_;
                    480:     return unless ((ref($syllabus) eq 'HASH') || (ref($syllabusfields) eq 'HASH'));
                    481: # ----------------------------------------------------------------- Make header
                    482:     my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
                    483:     my $js;
                    484:     if ($env{'form.backto'} eq 'coursecatalog') {
                    485:         $js .= <<"ENDSCRIPT";
                    486: 
                    487: <script type="text/javascript">
                    488: // <![CDATA[
                    489: 
                    490: function ToCatalog(caller) {
                    491:     numidx = getIndexByName('coursenum');
                    492:         if (numidx > -1) {
                    493:             if (caller != 'details') {
                    494:                 document.backtocat.elements[numidx].value = '';
                    495:             }
                    496:         }
                    497:     document.backtocat.submit();
                    498: }
                    499: 
                    500: function getIndexByName(item) {
                    501:     for (var i=0;i<document.backtocat.elements.length;i++) {
                    502:         if (document.backtocat.elements[i].name == item) {
                    503:             return i;
                    504:         }
                    505:     }
                    506:     return -1;
                    507: }
                    508: 
                    509: // ]]>
                    510: </script>
                    511: 
                    512: ENDSCRIPT
                    513:     }
                    514:     if ($allowed && $forceedit) {
                    515:         my $check_uncheck = &Apache::loncommon::check_uncheck_jscript();
                    516:         my @fieldnames = sort(keys(%{$syllabusfields}));
                    517:         unshift(@fieldnames,'000_showpeople','111_showrssfeeds');
                    518:         my (@checked,@unchecked);
                    519:         if ($syllabus->{'uploaded.fields'} eq 'none') {
                    520:             my $lastidx = scalar(@fieldnames)-1;
                    521:             @unchecked = (0..$lastidx);
                    522:         } elsif ($syllabus->{'uploaded.fields'}) {
                    523:             my %included;
                    524:             map { $included{$_} = 1; } split(/,/,$syllabus->{'uploaded.fields'});
                    525:             for (my $i=0; $i<@fieldnames; $i++) {
                    526:                 my ($prefix) = split(/_/,$fieldnames[$i]);
                    527:                 if ($included{$prefix}) {
                    528:                     push(@checked,$i);
                    529:                 } else {
                    530:                     push(@unchecked,$i);
                    531:                 }
                    532:             }
                    533:         } else {
                    534:             @checked = (0,1);
                    535:             for (my $i=2; $i<@fieldnames; $i++) {
                    536:                 if ($syllabus->{$fieldnames[$i]}) {
                    537:                     push(@checked,$i);
                    538:                 } else {
                    539:                     push(@unchecked,$i);
                    540:                 }
                    541:             }
                    542:         }
                    543:         my $fieldstr = "var fields = new Array('".join("','",@fieldnames)."');";
                    544:         my $checkedstr = "var include = new Array('".join("','",@checked)."');";
                    545:         my $uncheckedstr = "var exclude = new Array('".join("','",@unchecked)."');";
                    546:         my $invurl = &mt('Invalid URL');
                    547:         my $urlregexp = <<'ENDREGEXP';
                    548: /^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i
                    549: ENDREGEXP
                    550: 
                    551:         $js .= <<"ENDSCRIPT";
                    552: 
                    553: <script type="text/javascript">
                    554: // <![CDATA[
                    555: 
                    556: function toggleEditor(pick) {
1.122   ! raeburn   557:     var choices = new Array('template','minimal','url','file','templatebox');
1.121     raeburn   558:     for (var i=0; i<choices.length; i++) {
                    559:         if (((choices[i] == 'templatebox') && (pick == 'template')) ||
                    560:             (choices[i] == pick)) {
                    561:             document.getElementById(choices[i]).style.display='block';
                    562:         } else {
                    563:             document.getElementById(choices[i]).style.display='none';
                    564:         }
                    565:     }
                    566:     return;
                    567: }
                    568: 
                    569: var regexp = $urlregexp;
                    570: 
                    571: function extUrlPreview(caller) {
                    572:     if (document.getElementById(caller)) {
                    573:         var url = document.getElementById(caller).value;
                    574:         if (regexp.test(url)) {
                    575:             openMyModal(url,500,400,'yes');
                    576:         } else {
                    577:             alert("$invurl");
                    578:         }
                    579:     }
                    580: }
                    581: 
                    582: function toggleBox(name,caller) {
                    583:     if (name == 'all') {
                    584:         if (document.syllabus.showfield.length > 0) {
                    585:             for (var i=0; i<document.syllabus.showfield.length; i++) {
                    586:                 if (document.syllabus.showfield[i].checked) {
                    587:                     if (document.getElementById('box_'+document.syllabus.showfield[i].value)) {
                    588:                         document.getElementById('box_'+document.syllabus.showfield[i].value).style.display='block';
                    589:                     }
                    590:                 } else {
                    591:                     if (document.getElementById('box_'+document.syllabus.showfield[i].value)) {
                    592:                         document.getElementById('box_'+document.syllabus.showfield[i].value).style.display='none';
                    593:                     }
                    594:                 }
                    595:             }
                    596:         }
                    597:     } else {
                    598:         if (caller.checked) {
                    599:             if (document.getElementById('box_'+caller.value)) {
                    600:                 document.getElementById('box_'+caller.value).style.display='block';
                    601:             }
                    602:         } else {
                    603:             if (document.getElementById('box_'+caller.value)) {
                    604:                 document.getElementById('box_'+caller.value).style.display='none';
                    605:             }
                    606:         }
                    607:     }
                    608:     return;
                    609: }
                    610: 
                    611: function setTemplateBoxes() {
                    612:     $fieldstr
                    613:     $checkedstr
                    614:     $uncheckedstr
                    615:     if (include.length > 0) {
                    616:         for (var i=0; i<include.length; i++) {
                    617:             if (document.getElementById('showfield_'+include[i])) {
                    618:                 document.getElementById('showfield_'+include[i]).checked = true;
                    619:                 if (document.getElementById('box_'+fields[include[i]])) {
                    620:                     document.getElementById('box_'+fields[include[i]]).style.display='block';
                    621:                 }
                    622:             }
                    623:         }
                    624:     }
                    625:     if (exclude.length > 0) {
                    626:         for (var i=0; i<exclude.length; i++) {
                    627:             if (document.getElementById('showfield_'+exclude[i])) {
                    628:                 document.getElementById('showfield_'+exclude[i]).checked = false;
                    629:                 if (document.getElementById('box_'+fields[exclude[i]])) {
                    630:                     document.getElementById('box_'+fields[exclude[i]]).style.display='none';
                    631:                 }
                    632:             }
                    633:         }
                    634:     }
                    635:     return;
                    636: }
                    637: 
                    638: $check_uncheck
                    639: 
                    640: // ]]>
                    641: </script>
                    642: 
                    643: ENDSCRIPT
                    644:     }
                    645:     my $args = {'function'       => undef,
                    646:                 'domain'         => $cdom};
                    647:     my $forcereg;
                    648:     if ($env{'form.register'}) {
                    649:         $forcereg = 1;
                    650:         $args->{'force_register'} = $forcereg;
                    651:     }
                    652:     if ($env{'form.backto'} eq 'coursecatalog') {
                    653:         &Apache::lonhtmlcommon::clear_breadcrumbs();
                    654:         my $brcrum = [{href=>"javascript:ToCatalog();",
                    655:                        text=>&mt('Course/Community Catalog'),
                    656:                        no_mt=>1}
                    657:                      ];
                    658:         if ($env{'form.coursenum'} ne '') {
                    659:             push(@{$brcrum},
                    660:                   {href=>"javascript:ToCatalog('details')",
                    661:                    text=>"Course details"});
                    662:         }
                    663:         push(@{$brcrum},
                    664:               {href=>$r->uri,
                    665:                text=>"Course syllabus"});
                    666:         $args->{'bread_crumbs'} = $brcrum;
                    667:     } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
                    668:         my $title = $env{'form.title'};
                    669:         if ($title eq '') {
                    670:             $title = &mt('Syllabus');
                    671:         }
                    672:         my $brcrum =
                    673:             &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
                    674:         if (ref($brcrum) eq 'ARRAY') {
                    675:             $args->{'bread_crumbs'} = $brcrum;
                    676:         }
                    677:     } else {
                    678:         if ((&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus"))
                    679:                  && (($env{'form.symb'}) || ($env{'form.register'}))) {
                    680:             &Apache::lonhtmlcommon::clear_breadcrumbs();
                    681:         } else {
                    682:             $args->{'bread_crumbs'} = [
                    683:                                         {'href' => "/public/$cdom/$cnum/syllabus",
                    684:                                          'text' => 'Syllabus'},
                    685:                                       ];
                    686:         }
                    687:     }
                    688:     if ($allowed) {
                    689:         my %loaditem = (
                    690:                          onload => 'setTemplateBoxes();',
                    691:                        );
                    692:         $args->{'add_entries'} = \%loaditem;
                    693:     }
                    694:     my $start_page =
                    695:         &Apache::loncommon::start_page("Syllabus", $rss_link.$js,$args);
1.122   ! raeburn   696:     if ($start_page) {
        !           697:         $r->print($start_page);
        !           698:     }
1.121     raeburn   699: }
                    700: 
1.117     raeburn   701: sub chooser {
1.122   ! raeburn   702:     my ($external,$uploaded,$minimal,$cdom,$cnum,$lonhost,$fields,$values) = @_;
1.117     raeburn   703:     my %lt = &Apache::lonlocal::texthash(
                    704:                  'type'          => 'Syllabus Type',
                    705:                  'url'           => 'External URL',
1.122   ! raeburn   706:                  'file'          => 'Uploaded file',
        !           707:                  'minimal'       => 'Minimal template',
        !           708:                  'template'      => 'Standard template',
1.117     raeburn   709:                  'templateboxes' => 'Choose template items ... ',
                    710:                  'curr'          => 'Current:',
                    711:                  'rep'           => 'Replace:',
                    712:                  'upl'           => 'Upload:',
                    713:                  'pr'            => 'Preview',
                    714:                  'save'          => 'Save',
1.122   ! raeburn   715:                  'sved'          => 'Save and Edit',
        !           716:                  'chourl'        => 'External URL',
1.117     raeburn   717:                  'chofile'       => 'Uploaded syllabus file',
                    718:                  'parse'         => 'Upload embedded images/multimedia files if HTML file',
                    719:     );
                    720:     my %checked = (
                    721:                     file     => '',
1.122   ! raeburn   722:                     minimal  => '',
1.117     raeburn   723:                     url      => '',
                    724:                     template => '',
                    725:                   );
                    726:     my %display = (
                    727:                     file        => 'none',
1.122   ! raeburn   728:                     minimal     => 'none',
1.117     raeburn   729:                     url         => 'none',
                    730:                     templatebox => 'none',
                    731:                   );
                    732:     my $check = ' checked="checked" ';
                    733:     if ($uploaded) {
                    734:         $checked{'file'} = $check;
                    735:         $display{'file'} = 'block';
                    736:     } elsif ($external) {
                    737:         $checked{'url'}  = $check;
                    738:         $display{'url'} = 'block';
1.122   ! raeburn   739:     } elsif ($minimal) {
        !           740:         $checked{'minimal'} = $check;
        !           741:         $display{'minimal'} = 'block';
1.117     raeburn   742:     } else {
                    743:         $checked{'template'} = $check;
                    744:         $checked{'templatebox'} = $check;
                    745:         $display{'templatebox'} = 'block';
                    746:     }
                    747: 
                    748:     my $output = 
                    749:         '<form name="syllabus" method="post" enctype="multipart/form-data" action="">'."\n".
                    750:         '<input type="hidden" name="forceedit" value="1" />'."\n".
                    751:         '<div class="LC_left_float"><fieldset><legend>'.$lt{'type'}.'</legend>';
1.122   ! raeburn   752:     foreach my $item ('minimal','template','url','file') {
1.117     raeburn   753:         $output .= '<label><input type="radio" name="choice" value="'.$item.'" '.$checked{$item}.' onclick="toggleEditor('."'$item'".')" />'.
                    754:                    $lt{$item}.'</label><br />';
                    755:     }
                    756:     $output .= '</fieldset></div>'."\n".
                    757:                '<div id="url" class="LC_left_float" style="display: '.$display{'url'}.'">'."\n".
                    758:                '<fieldset><legend>'.$lt{'chourl'}.'</legend><span class="LC_nobreak">'."\n".
                    759:                '<a href="javascript:extUrlPreview('."'syllabusurl'".');">'.$lt{'pr'}.'</a></span>&nbsp;'."\n".
                    760:                '<input type="text" id="syllabusurl" name="externalsyllabus" value="'.$external.'" size="55" />'."\n".
                    761:                '&nbsp;<input type="submit" name="storeurl" value="'.$lt{'save'}.'" />'."\n".
                    762:                '</fieldset></div>'."\n".
1.122   ! raeburn   763:                '<div id="minimal" class="LC_left_float" style="display: '.$display{'minimal'}.'">'."\n".
        !           764:                '<fieldset><legend>'.$lt{'minimal'}.'</legend>';
        !           765:     if ($minimal) {
        !           766:         my ($absurl,$filename,$depbutton) = &syllabus_file_info($minimal,$cnum,$cdom,$lonhost,'minimal');
        !           767:         $output .= '<a href="javascript:extUrlPreview('."'currminimal'".');">'.$lt{'pr'}.'</a>'.
        !           768:                    '<input type="hidden" name="minimalfile" value="'.&HTML::Entities::encode($absurl).'?inhibitmenu=yes" id="currminimal" />'.
        !           769:                    $depbutton;
        !           770:     } else {
        !           771:         $output .= &mt('Title of Syllabus Page:').'&nbsp;'.
        !           772:                    '<input type="text" id="minimaltitle" name="syllabustitle" value="'.&mt('Syllabus').'" size="30" />'."\n".
        !           773:                    '&nbsp;<input type="submit" name="storeminimal" value="'.$lt{'sved'}.'" />'."\n";
        !           774:     }
        !           775:     $output .= '</fieldset></div>'."\n".
        !           776:                '<div id="file" class="LC_left_float" style="display: '.$display{'file'}.'">'."\n".
        !           777:                '<fieldset><legend>'.$lt{'file'}.'</legend>';
1.117     raeburn   778:     if ($uploaded) {
1.122   ! raeburn   779:         my ($absurl,$filename,$depbutton) = &syllabus_file_info($uploaded,$cnum,$cdom,$lonhost,'file');
1.117     raeburn   780:         $output .= '<span class="LC_nobreak">'.$lt{'curr'}.'&nbsp;'.
                    781:                    '<input type="hidden" name="uploadedfile" value="'.&HTML::Entities::encode($absurl).'?inhibitmenu=yes" id="currfile" />'.
1.118     raeburn   782:                    '<a href="javascript:extUrlPreview('."'currfile'".');">'.$filename.'</a></span>'.$depbutton.
                    783:                    '<br /><br />'.$lt{'rep'};
1.117     raeburn   784:     } else {
                    785:         $output .= $lt{'upl'};
                    786:     }
                    787:     $output .= '<br />'."\n".
                    788:                '<span class="LC_nobreak">'.
                    789:                '<input type="file" name="syllabusfile" size="55" />'."\n".
                    790:                '&nbsp;<input type="submit" name="storefile" value="'.$lt{'save'}.'" />'.
                    791:                '</span><br />'.
                    792:                '<label>'.
                    793:                '<input type="checkbox" name="parserflag" checked="checked" />'.
                    794:                $lt{'parse'}.
                    795:                '</label>'.
                    796:                '</fieldset></div>'.
                    797:                '<div id="templatebox" class="LC_left_float" style="display: '.
                    798:                $display{'templatebox'}.';"><fieldset><legend>'.$lt{'templateboxes'}.
                    799:                '&nbsp;<input type="button" value="'.&mt('check all').'" '.
                    800:                'onclick="javascript:checkAll('."document.syllabus.showfield".');javascript:toggleBox('."'all'".');" />'.
                    801:                ('&nbsp;'x2).
                    802:                '<input type="button" value="'.&mt('uncheck all').'" '.
                    803:                'onclick="javascript:uncheckAll('."document.syllabus.showfield".');javascript:toggleBox('."'all'".');" />'.
                    804:                '</legend>'.
                    805:                &fields_check_uncheck($fields,$values).
1.121     raeburn   806:                '</fieldset><br />'.
                    807:                '<input type="submit" name="storesyl" value="'.&mt('Save All').'" />'.
1.117     raeburn   808:                '</div>';
1.121     raeburn   809:     $output .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.117     raeburn   810:     return $output;
                    811: }
                    812: 
1.122   ! raeburn   813: sub syllabus_file_info {
        !           814:     my ($item,$cnum,$cdom,$lonhost,$context) = @_;
        !           815:     my $protocol = $Apache::lonnet::protocol{$lonhost};
        !           816:     $protocol = 'http' if ($protocol ne 'https');
        !           817:     my $absurl = $protocol.'://'.&Apache::lonnet::hostname($lonhost).$item;
        !           818:     my ($filename) = ($item =~ m{([^/]+)$});
        !           819:     my $file=&Apache::lonnet::filelocation("",$item);
        !           820:     my $depbutton;
        !           821:     if ($file =~ /\.html?$/) {
        !           822:         my $filecontents=&Apache::lonnet::getfile($file);
        !           823:         unless ($filecontents eq -1) {
        !           824:             my $mm = new File::MMagic;
        !           825:             my $mimetype = $mm->checktype_contents($filecontents);
        !           826:             if ($mimetype eq 'text/html') {
        !           827:                 my (%codebase,%allfiles);
        !           828:                 my $parse_result = &Apache::lonnet::extract_embedded_items($item,\%allfiles,
        !           829:                                                                            \%codebase,\$filecontents);
        !           830:                 my $actionurl = "/public/$cdom/$cnum/syllabus";
        !           831:                 my ($ignore,$num,$numpathchanges,$existing,$mapping) =
        !           832:                     &Apache::loncommon::ask_for_embedded_content($actionurl,undef,\%allfiles,
        !           833:                                                                  \%codebase,
        !           834:                                                                  {'context' => 'rewrites',
        !           835:                                                                   'ignore_remote_references' => 1,});
        !           836:                 $depbutton = ('&nbsp;' x 3).
        !           837:                              &editfile_button($item,$context).
        !           838:                              &editbutton_js();
        !           839:             }
        !           840:         }
        !           841:     }
        !           842:     return ($absurl,$filename,$depbutton);
        !           843: }
        !           844: 
1.117     raeburn   845: sub fields_check_uncheck {
                    846:     my ($fields,$values) = @_;
                    847:     return unless ((ref($fields) eq 'HASH') && (ref($values) eq 'HASH'));
                    848:     my $numinrow = 4;
                    849:     my $table;
                    850:     my @fieldnames = sort(keys(%{$fields}));
1.121     raeburn   851:     unshift(@fieldnames,'000_showpeople','111_showrssfeeds'); 
1.117     raeburn   852:     my $numfields = scalar(@fieldnames);
1.121     raeburn   853:     my %included;
                    854:     if (($values->{'uploaded.fields'}) && ($values->{'uploaded.fields'} ne 'none')) {
                    855:         map { $included{$_} = 1; } split(/,/,$values->{'uploaded.fields'});
                    856:     }
1.117     raeburn   857:     for (my $i=0; $i<$numfields; $i++) {
1.121     raeburn   858:         my ($name,$checked);
                    859:         if ($fieldnames[$i] eq '000_showpeople') {
                    860:             $name = &mt('Personnel');
                    861:         } elsif ($fieldnames[$i] eq '111_showrssfeeds') {
1.117     raeburn   862:             $name = &mt('RSS Feeds and Blogs');
1.121     raeburn   863:         } else {
                    864:             $name = $fields->{$fieldnames[$i]};
                    865:         }
                    866:         if ($values->{'uploaded.fields'}) {
                    867:             unless ($values->{'uploaded.fields'} eq 'none') {
                    868:                 my ($prefix) = split(/_/,$fieldnames[$i]);
                    869:                 if ($included{$prefix}) {
                    870:                     $checked = ' checked="checked"';
                    871:                 }
                    872:             }
                    873:         } else {
                    874:             if ($fieldnames[$i] eq '000_showpeople') {
                    875:                 $checked = ' checked="checked"';
                    876:             } elsif ($fieldnames[$i] eq '111_showrssfeeds') {
1.117     raeburn   877:                 $checked = ' checked="checked"';
1.121     raeburn   878:             } else {
                    879:                 if ($values->{$fieldnames[$i]} ne '') {
                    880:                     $checked = ' checked="checked"';
                    881:                 }
1.117     raeburn   882:             }
                    883:         }
                    884:         my $rem = $i%($numinrow);
                    885:         if ($rem == 0) {
1.121     raeburn   886:             if (($i > 0) && ($i < $numfields)) {
1.117     raeburn   887:                 $table .= '</tr>';
                    888:             }
1.121     raeburn   889:             if ($i < $numfields) {
1.117     raeburn   890:                 $table .= '<tr>';
                    891:             }
                    892:         }
1.121     raeburn   893:         if ($i == $numfields-1) {
                    894:             my $rem = $numfields%($numinrow);
                    895:             my $colsleft = $numinrow - $rem;
                    896:             if ($colsleft > 1) {
                    897:                 $table .= '<td colspan="'.$colsleft.'">';
                    898:             } else {
                    899:                 $table .= '</td>';
                    900:             }
                    901:         } else {
                    902:             $table .= '<td>';
                    903:         }
1.117     raeburn   904:         $table .=
1.121     raeburn   905:             '<label><input type="checkbox" name="showfield" value="'.$fieldnames[$i].'" '.
1.117     raeburn   906:             $checked.' id="showfield_'.$i.'" onclick="javascript:toggleBox('."'$fieldnames[$i]',this".');" />'.
                    907:             $name.'</label></td>'."\n";
                    908:     }
                    909:     if ($table ne '') {
                    910:         my $rem = $numfields%($numinrow);
                    911:         my $colsleft = $numinrow - $rem;
                    912:         if ($colsleft > 1 ) {
                    913:             $table .= '<td colspan="'.$colsleft.'">&nbsp;</td>';
                    914:         } elsif ($colsleft == 1) {
                    915:             $table .= '<td>&nbsp;</td>';
                    916:         }
                    917:         $table = '<table>'.$table.'</tr></table>';
                    918:     }
                    919:     return $table;
                    920: }
                    921: 
1.121     raeburn   922: sub get_personnel {
                    923:     my ($r,$target,$cdom,$cnum,$allowed) = @_;
                    924:     my $output;
                    925:     my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
                    926:     if ($target ne 'tex') {
                    927:         $r->print(&Apache::lonhtmlcommon::start_pick_box());
                    928:     } else {
                    929:         $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
                    930:     }
                    931:     my @personnel=sort(keys(%coursepersonnel));
                    932:     my $lastpers=$personnel[$#personnel];
                    933:     foreach my $element (@personnel) {
                    934:         if ($target ne 'tex') {
                    935:             $r->print(&Apache::lonhtmlcommon::row_title($element));
                    936:         } else {
                    937:             $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & ');
                    938:         }
                    939:         my @coursepersonlist;
                    940:         foreach my $user (split(/\,/,$coursepersonnel{$element})) {
                    941:             my ($puname,$pudom)=split(/\:/,$user);
                    942:             if ($target ne 'tex') {
                    943:                 my $courseperson = &Apache::loncommon::plainname($puname,$pudom);
                    944:                 if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
                    945:                     ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
                    946:                     push(@coursepersonlist,$courseperson);
                    947:                 } else {
                    948:                     push(@coursepersonlist,&Apache::loncommon::aboutmewrapper($courseperson,
                    949:                               $puname,$pudom));
                    950:                 }
                    951:             } else {
                    952:                 push(@coursepersonlist,&Apache::loncommon::plainname($puname,
                    953:                               $pudom).' ');
                    954:             }
                    955:         }
                    956:         $r->print(join(", ",@coursepersonlist));
                    957:         if ($target ne 'tex') {
                    958:             my $lastclose=$element eq $lastpers?1:0;
                    959:             $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
                    960:         } else {
                    961:             $r->print('\\\\ \hline');
                    962:         }
                    963:     }
                    964:     if ($target ne 'tex') {
                    965:         $r->print(&Apache::lonhtmlcommon::end_pick_box());
                    966:     } else {
                    967:         $r->print('\end{tabular}\\\\');
                    968:     }
                    969:     return;
                    970: }
                    971: 
                    972: sub save_changes {
1.122   ! raeburn   973:     my ($cnum,$cdom,$uploaded,$external,$minimal,$syllabus,$syllabusfields,$courseenv) = @_;
1.121     raeburn   974:     my ($earlyout,$output);
                    975:     unless ((ref($syllabus) eq 'HASH') && (ref($syllabusfields) eq 'HASH')) {
1.122   ! raeburn   976:         return ($earlyout,$uploaded,$external,$minimal,$output);
1.121     raeburn   977:     }
1.122   ! raeburn   978:     if ($env{'form.deleteuploaded'}) {
        !           979:         my %storehash;
        !           980:         if (($env{'form.choice'} eq 'file') && 
        !           981:             ($env{'form.deleteuploaded'} eq 'file') && ($uploaded =~ /\w/)) {
        !           982:             &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus');
        !           983:             &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus');
        !           984:             $storehash{'uploadedsyllabus'} = '';
        !           985:             $storehash{'externalsyllabus'} = '';
        !           986:             my $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
        !           987:             undef($uploaded);
        !           988:             undef($external);
        !           989:         } elsif (($env{'form.choice'} eq 'minimal') &&
        !           990:                  ($env{'form.deleteuploaded'} eq 'minimal') && ($minimal =~ /\w/)) {
        !           991:             &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus');
        !           992:             &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.minimalsyllabus');
        !           993:             $storehash{'externalsyllabus'} = '';
        !           994:             $storehash{'minimalsyllabus'} = '';
        !           995:             my $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
        !           996:             undef($external);
        !           997:             undef($minimal);
        !           998:         }
        !           999:     } elsif ($env{'form.choice'} eq 'template') {
1.121     raeburn  1000: #store what the user typed in to the template
                   1001:         my @shown = &Apache::loncommon::get_env_multiple('form.showfield');
                   1002:         $syllabus->{'uploaded.fields'} = '';
                   1003:         if (@shown == 0) {
                   1004:             $syllabus->{'uploaded.fields'} = 'none';
                   1005:         } else {
                   1006:             foreach my $field (sort(@shown)) {
                   1007:                 if (($field eq '000_showpeople') ||
                   1008:                     ($field eq '111_showrssfeeds') ||
                   1009:                     ($syllabusfields->{$field})) {
                   1010:                     my ($prefix) = split(/_/,$field);
                   1011:                     $syllabus->{'uploaded.fields'} .= $prefix.',';
                   1012:                 }
                   1013:             }
                   1014:             $syllabus->{'uploaded.fields'} =~ s/,$//;
                   1015:         }
                   1016:         foreach my $syl_field (keys(%{$syllabusfields})) {
                   1017:             my $field=$env{'form.'.$syl_field};
                   1018:             chomp($field);
                   1019:             $field=~s/\s+$//s;
                   1020:             $field=~s/^\s+//s;
                   1021:             $field=~s/\<br\s*\/*\>$//s;
                   1022:             $field=&Apache::lonfeedback::clear_out_html($field,1);
                   1023:                             #here it will be stored
                   1024:             $syllabus->{$syl_field}=$field;
                   1025:             if ($syl_field eq 'lll_includeurl') { # clean up included URLs
                   1026:                 my $field='';
                   1027:                 foreach my $value (split(/\n/,$syllabus->{$syl_field})) {
                   1028:                     my $url=$value;
                   1029: # get rid of leading and trailing spaces
                   1030:                     $url=~s/^\s+//;
                   1031:                     $url=~s/\s+$//;
                   1032:                     if ($url=~m|^https?\://([^/]+)/(.+)$|) {
                   1033:                         my $host = $1;
                   1034:                         my $remainder=$2;
                   1035: # remove the hostname from internal URLs
                   1036:                         my $hostname = &Apache::lonnet::hostname($host);
                   1037:                         my %all_hostnames = &Apache::lonnet::all_hostnames();
                   1038:                         foreach my $possible_host (keys(%all_hostnames)) {
                   1039:                             if ($possible_host =~ /\Q$hostname\E/i) {
                   1040:                                 $url=$remainder;
                   1041:                             }
                   1042:                         }
                   1043:                     }
                   1044: # norm internal URLs
                   1045:                     unless ($url=~/^https?\:/) {
                   1046:                         $url=&Apache::lonnet::clutter($url);
                   1047:                     }
                   1048: # re-assemble field
                   1049:                     if ($url) {
                   1050:                         $field.=$url."\n";
                   1051:                     }
                   1052:                 }
                   1053:                 $syllabus->{$syl_field}=$field;
                   1054:             }
                   1055:         }
                   1056:         my $now = time;
                   1057:         $syllabus->{'uploaded.domain'}=$env{'user.domain'};
                   1058:         $syllabus->{'uploaded.name'}=$env{'user.name'};
                   1059:         $syllabus->{'uploaded.lastmodified'} = $now;
                   1060:         my $putres = &Apache::lonnet::put('syllabus',$syllabus,$cdom,$cnum);
                   1061:         if ($putres eq 'ok') {
                   1062:             my %storehash;
                   1063:             if ($courseenv->{'uploadedsyllabus'}) {
                   1064:                 &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus');
                   1065:                 $storehash{'uploadedsyllabus'} = '';
                   1066:             }
                   1067:             if ($courseenv->{'externalsyllabus'}) {
                   1068:                 &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus');
                   1069:                 $storehash{'externalsyllabus'} = '';
                   1070:             }
1.122   ! raeburn  1071:             if ($courseenv->{'minimalsyllabus'}) {
        !          1072:                 &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.minimalsyllabus');
        !          1073:                 $storehash{'minimalsyllabus'} = '';
        !          1074:             }
1.121     raeburn  1075:             $storehash{'updatedsyllabus'} = $now;
                   1076:             &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
                   1077:             &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.updatedsyllabus' => $now});
1.122   ! raeburn  1078:             if (($courseenv->{'externalsyllabus'} || $courseenv->{'uploadedsyllabus'}) ||
        !          1079:                 ($courseenv->{'minimalsyllabus'})) {
1.121     raeburn  1080:                 undef($uploaded);
                   1081:                 undef($external);
1.122   ! raeburn  1082:                 undef($minimal);
1.121     raeburn  1083:             }
                   1084:             $output = '<div>'.
                   1085:                       &Apache::lonhtmlcommon::confirm_success(&mt('Template saved.')).
                   1086:                       '</div>';
                   1087:         } else {
                   1088:             $output = '<div class="LC_error">'.
                   1089:                       &mt('An error occurred storing the template: [_1]',$putres).
                   1090:                       '</div>';
                   1091:         }
                   1092:     } elsif ($env{'form.choice'} eq 'url') {
                   1093:         if ($env{'form.externalsyllabus'} =~ m{^https?://}) {
                   1094:             if ($env{'form.externalsyllabus'} eq $external) {
                   1095:                 $output = '<div class="LC_info">'.
                   1096:                           &mt('External URL unchanged.').
                   1097:                           '</div>';
                   1098:                 if ($uploaded) {
                   1099:                     my $prefix;
                   1100:                     my $home=&Apache::lonnet::homeserver($cnum,$cdom);
                   1101:                     if ($home ne 'no_host') {
                   1102:                         my $protocol = $Apache::lonnet::protocol{$home};
                   1103:                         $protocol = 'http' if ($protocol ne 'https');
                   1104:                         $prefix = $protocol.'://'.&Apache::lonnet::hostname($home);
                   1105:                     }
                   1106:                     unless ($external =~ m{^\Q$prefix/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
                   1107:                         &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus');
                   1108:                         &Apache::lonnet::put('environment',{uploadedsyllabus => ''},
                   1109:                                              $cdom,$cnum);
                   1110:                         undef($uploaded);
                   1111:                     }
                   1112:                 }
                   1113:             } else {
                   1114:                 $external=$env{'form.externalsyllabus'};
                   1115:                 $external =~ s/(`)//g;
                   1116:                 my $putres =
                   1117:                     &Apache::lonnet::put('environment',{externalsyllabus=>$external},
                   1118:                                          $cdom,$cnum);
                   1119:                 if ($putres eq 'ok') {
                   1120:                     &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.externalsyllabus' => $external});
                   1121:                     $output = '<div>'.
                   1122:                               &Apache::lonhtmlcommon::confirm_success(&mt('External URL saved.')).
                   1123:                              '</div>';
                   1124:                     if ($uploaded) {
                   1125:                         my $prefix;
                   1126:                         my $home=&Apache::lonnet::homeserver($cnum,$cdom);
                   1127:                         if ($home ne 'no_host') {
                   1128:                             my $protocol = $Apache::lonnet::protocol{$home};
                   1129:                             $protocol = 'http' if ($protocol ne 'https');
                   1130:                             $prefix = $protocol.'://'.&Apache::lonnet::hostname($home);
                   1131:                         }
                   1132:                         unless ($external =~ m{^\Q$prefix/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
                   1133:                             &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus');
                   1134:                             &Apache::lonnet::put('environment',{uploadedsyllabus => ''},
                   1135:                                                  $cdom,$cnum);
                   1136:                             undef($uploaded);
                   1137:                         }
                   1138:                     }
                   1139:                 } else {
                   1140:                     $output = '<div class="LC_error">'.
                   1141:                               &mt('An error occurred storing the external URL: [_1]',$putres).
                   1142:                               '</div>';
                   1143:                 }
                   1144:             }
                   1145:         } else {
                   1146:             $output = '<div class="LC_error">'.
                   1147:                       &mt('External URL not saved -- invalid URL.').
                   1148:                       '</div>';
                   1149:         }
1.122   ! raeburn  1150:     } elsif (($env{'form.choice'} eq 'file') || ($env{'form.choice'} eq 'minimal')) {
1.121     raeburn  1151:         # Process file upload - phase one - upload and parse primary file.
1.122   ! raeburn  1152:         my ($upload_result,$uploadphase,$url,$needlink,$error,$errormsg);
        !          1153:         if ($env{'form.choice'} eq 'file') {
        !          1154:             if ($env{'form.syllabusfile.filename'}) {
        !          1155:                 my %allfiles = ();
        !          1156:                 my %codebase = ();
        !          1157:                 ($url,$needlink) = &process_upload(\$output,$cnum,$cdom,
        !          1158:                                                    \%allfiles,\%codebase);
        !          1159:             } else {
        !          1160:                 $output = '<div class="LC_info">';
        !          1161:                           &mt('No file uploaded').
        !          1162:                           '</div>';
        !          1163:             }
        !          1164:         } elsif ($env{'form.choice'} eq 'minimal') {
        !          1165:             my $title = $env{'form.syllabustitle'};
        !          1166:             $title =~ s{`}{}g;
        !          1167:             $title=~s/^\s+//;
        !          1168:             $title=~s/\s+$//;
        !          1169:             if ($title eq '') {
        !          1170:                 $title = &mt('Syllabus');
        !          1171:             }
        !          1172:             my $initialtext = &mt('Replace with your own content.');
        !          1173:             my $newhtml = <<END;
        !          1174: <html>
        !          1175: <head>
        !          1176: <title>$title</title>
        !          1177: </head>
        !          1178: <body bgcolor="#ffffff">
        !          1179: <h2>$title</h2>
        !          1180: $initialtext
        !          1181: </body>
        !          1182: </html>
        !          1183: END
        !          1184:             $env{'form.output'}=$newhtml;
        !          1185:             $url =
        !          1186:                  &Apache::lonnet::finishuserfileupload($cnum,$cdom,'output',
        !          1187:                                                        'portfolio/syllabus/loncapa.html');
        !          1188:         }
        !          1189:         if ($url =~ m{^/uploaded/\Q$cdom\E/\Q$cnum\E.*/[^/]+$}) {
        !          1190:             my $exturl;
        !          1191:             my $home=&Apache::lonnet::homeserver($cnum,$cdom);
        !          1192:             if ($home ne 'no_host') {
        !          1193:                 my $protocol = $Apache::lonnet::protocol{$home};
        !          1194:                 $protocol = 'http' if ($protocol ne 'https');
        !          1195:                 $exturl = $protocol.'://'.&Apache::lonnet::hostname($home).$url;
        !          1196:             }
        !          1197:             my %storehash;
        !          1198:             if ($env{'form.choice'} eq 'minimal') {
        !          1199:                 $storehash{'minimalsyllabus'} = $url;
        !          1200:             } else {
        !          1201:                 $storehash{'uploadedsyllabus'} = $url;
        !          1202:             }
        !          1203:             if ($exturl) {
        !          1204:                 $storehash{'externalsyllabus'} = $exturl;
        !          1205:                 if ($exturl =~ /\.(html?|txt|js|css)$/) {
        !          1206:                     $exturl .= '?inhibitmenu=yes';
        !          1207:                 }
        !          1208:             } else {
        !          1209:                 $storehash{'externalsyllabus'} = '',
        !          1210:             }
        !          1211:             my $putres =
        !          1212:                 &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
        !          1213:             if ($putres eq 'ok') {
        !          1214:                 &Apache::lonnet::make_public_indefinitely($url);
        !          1215:                 foreach my $key (keys(%storehash)) {
        !          1216:                     &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash{$key}});
        !          1217:                 }
        !          1218:                 if ($env{'form.choice'} eq 'minimal') {
        !          1219:                     $minimal = $url;
1.121     raeburn  1220:                 } else {
1.122   ! raeburn  1221:                     $uploaded = $url;
1.121     raeburn  1222:                 }
1.122   ! raeburn  1223:                 if ($needlink) {
        !          1224:                     $output .= &return_to_editor($cdom,$cnum);
        !          1225:                     $earlyout = 1;
1.121     raeburn  1226:                 }
1.122   ! raeburn  1227:             } else {
        !          1228:                 $error = 1;
        !          1229:                 $errormsg = $putres;
        !          1230:             }
        !          1231:         } else {
        !          1232:             $error = 1;
        !          1233:         }
        !          1234:         if ($error) {
        !          1235:             $output = '<div class="LC_error">';
        !          1236:             if ($env{'form.choice'} eq 'minimal') {
        !          1237:                 $output = &mt('An error occurred creating the minimal template file [_1]',$errormsg);
        !          1238:             } else {
        !          1239:                 $output = &mt('An error occurred storing the uploaded file [_1]',$errormsg);
1.121     raeburn  1240:             }
1.122   ! raeburn  1241:             $output .= '</div>';
1.121     raeburn  1242:         }
                   1243:     } elsif ($env{'form.phase'} eq 'upload_embedded') {
                   1244:         # Process file upload - phase two - upload embedded objects
                   1245:         my $uploadphase = 'check_embedded';
                   1246:         my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
                   1247:         my $state = &embedded_form_elems($uploadphase,$primaryurl);
                   1248:         my $url_root = '/uploaded/'.$cdom.'/'.$cnum;
                   1249:         my $actionurl = "/public/$cdom/$cnum/syllabus";
                   1250:         my ($result,$flag,$numpathchgs) =
                   1251:             &Apache::loncommon::upload_embedded('syllabus','portfolio/syllabus',
                   1252:                 $cnum,$cdom,'/userfiles',$url_root,undef,undef,undef,$state,
                   1253:                 $actionurl);
                   1254:         unless ($numpathchgs) {
                   1255:             my $modres =
                   1256:                 &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
                   1257:                                                      $cnum,$cdom,
                   1258:                                                      '/userfiles',$env{'form.primaryurl'});
                   1259:             $result .= $modres;
                   1260:         }
1.122   ! raeburn  1261:         $output = $result.&return_to_editor($cdom,$cnum);
1.121     raeburn  1262:         $earlyout = 1;
                   1263:     } elsif ($env{'form.phase'} eq 'check_embedded') {
                   1264:         # Process file upload - phase three - modify references in HTML file
                   1265:         my $uploadphase = 'modified_orightml';
                   1266:         my $result =
                   1267:             &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
                   1268:                                                  $cnum,$cdom,
                   1269:                                                  '/userfiles',$env{'form.primaryurl'});
1.122   ! raeburn  1270:         $output = $result.&return_to_editor($cdom,$cnum);
1.121     raeburn  1271:         $earlyout = 1;
                   1272:     }
1.122   ! raeburn  1273:     return ($earlyout,$uploaded,$external,$minimal,$output);
1.121     raeburn  1274: }
                   1275: 
1.117     raeburn  1276: sub process_upload {
                   1277:     my ($upload_output,$cnum,$cdom,$allfiles,$codebase) = @_;
                   1278:     my ($parseaction,$showupload,$mimetype);
                   1279:     my $dest = 'portfolio/syllabus';
                   1280:     if ($env{'form.parserflag'}) {
                   1281:         $parseaction = 'parse';
                   1282:     }
                   1283:     my $url=&Apache::lonnet::userfileupload('syllabusfile','syllabus',$dest,
                   1284:                                             $parseaction,$allfiles,
                   1285:                                             $codebase,undef,undef,undef,undef,
                   1286:                                             undef,undef,\$mimetype);
                   1287:     if ($url =~ m{^/uploaded/\Q$cdom\E/\Q$cnum\E.*/([^/]+)$}) {
                   1288:         my $stored = $1;
                   1289:         $showupload = '<p>'.&mt('Uploaded [_1]',
                   1290:                                 '<span class="LC_filename">'.$stored.'</span>').
                   1291:                       '</p>';
                   1292:     } else {
                   1293:         my ($filename) = ($env{'form.syllabusfile.filename'} =~ m{([^/]+)$});
                   1294:         $$upload_output = '<div class="LC_error" id="uploadfileresult">'.
                   1295:                           &mt('Unable to save file [_1].',
                   1296:                               '<span class="LC_filename">'.$filename.'</span>').
                   1297:                           '</div>';
                   1298:         return (); 
                   1299:     }
                   1300:     my $needlink;
                   1301:     if (($parseaction eq 'parse') && ($mimetype eq 'text/html')) {
                   1302:         $$upload_output = $showupload;
                   1303:         my $total_embedded = scalar(keys(%{$allfiles}));
                   1304:         if ($total_embedded > 0) {
                   1305:             my $uploadphase = 'upload_embedded';
                   1306:             my $primaryurl = &HTML::Entities::encode($url,'<>&"');
                   1307:             my $state = &embedded_form_elems($uploadphase,$primaryurl);
                   1308:             my $actionurl = "/public/$cdom/$cnum/syllabus";
                   1309:             my ($embedded,$num,$numpathchanges,$existing);
                   1310:             ($embedded,$num,$numpathchanges,$existing) =
                   1311:                 &Apache::loncommon::ask_for_embedded_content($actionurl,$state,
                   1312:                                                              $allfiles,$codebase,
                   1313:                                                             {'error_on_invalid_names'   => 1,
                   1314:                                                              'ignore_remote_references' => 1,});
                   1315:             if ($embedded) {
                   1316:                 $needlink = 1;
                   1317:                 if ($num) {
                   1318:                     $$upload_output .=
                   1319:                         '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
                   1320:                 } elsif ($numpathchanges) {
                   1321:                     $$upload_output .= $embedded;
                   1322:                 } else {
                   1323:                     $$upload_output .= $embedded;
                   1324:                     &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
                   1325:                                                          $cnum,$cdom,'/userfiles',$url);
                   1326:                 }
                   1327:             } else {
                   1328:                 $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
                   1329:                 &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
                   1330:                                                      $cnum,$cdom,'/userfiles',$url);
                   1331: 
                   1332:             }
                   1333:         } else {
                   1334:             $$upload_output .= &mt('No embedded items identified').'<br />';
                   1335:         }
                   1336:         $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
                   1337:     }
                   1338:     return ($url,$needlink);
                   1339: }
                   1340: 
                   1341: sub embedded_form_elems {
                   1342:     my ($phase,$primaryurl) = @_;
                   1343:     return <<STATE;
                   1344:     <input type="hidden" name="forceedit" value="1" />
                   1345:     <input type="hidden" name="cmd" value="upload_embedded" />
                   1346:     <input type="hidden" name="phase" value="$phase" />
                   1347:     <input type="hidden" name="primaryurl" value="$primaryurl" />
                   1348: STATE
                   1349: }
                   1350: 
                   1351: sub return_to_editor {
                   1352:     my ($cdom,$cnum) = @_;
                   1353:     my $actionurl = "/public/$cdom/$cnum/syllabus";
                   1354:     return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'.
                   1355:            '<input type="hidden" name="forceedit" value="1" />'."\n".
                   1356:            '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
                   1357:            '</a></p>';
                   1358: }
                   1359: 
1.118     raeburn  1360: sub editfile_button {
1.122   ! raeburn  1361:     my ($url,$context) = @_;
        !          1362:     my $edittext=&mt('Edit');
        !          1363:     my $deltext=&mt('Delete');
1.118     raeburn  1364:     return <<"END";
1.122   ! raeburn  1365:                 <input type="button" value="$edittext" onclick="javascript:gotoeditor('$url');" name="edit_$context" />
        !          1366:                 &nbsp;&nbsp;&nbsp;
        !          1367:                 <input type="button" value="$deltext" onclick="javascript:dodelete('$context');" name="del_$context" />
        !          1368:                 <input type="hidden" value="" name="deleteuploaded" />
1.118     raeburn  1369: END
                   1370: }
                   1371: 
                   1372: sub editbutton_js {
                   1373:     return <<ENDJS;
                   1374:                 <script type="text/javascript">
                   1375:                 // <![CDATA[
1.122   ! raeburn  1376:                   function gotoeditor(url) {
        !          1377:                       document.location.href = url+'?editmode=1&forceedit=1';
        !          1378:                   }
        !          1379:                   function dodelete(caller,url) {
        !          1380:                       document.syllabus.deleteuploaded.value=caller;
        !          1381:                       document.syllabus.submit();
1.118     raeburn  1382:                   }
                   1383:                 // ]]>
                   1384:                 </script>
                   1385: ENDJS
                   1386: }
                   1387: 
1.1       www      1388: 1;
                   1389: __END__

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