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

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

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