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

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

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