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

1.1       www         1: # The LearningOnline Network
                      2: # Syllabus
                      3: #
1.149   ! raeburn     4: # $Id: lonsyllabus.pm,v 1.148 2020/01/20 16:27:54 raeburn Exp $
1.1       www         5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: 
                     29: package Apache::lonsyllabus;
                     30: 
                     31: use strict;
1.70      amueller   32: use Apache::lontemplate;
1.1       www        33: use Apache::Constants qw(:common);
                     34: use Apache::loncommon;
                     35: use Apache::lonnet;
1.5       www        36: use Apache::lontexconvert;
1.11      www        37: use Apache::lonfeedback;
1.133     raeburn    38: use Apache::lonhtmlgateway;
1.19      www        39: use Apache::lonannounce;
1.23      www        40: use Apache::lonlocal;
1.32      www        41: use Apache::lonhtmlcommon;
1.38      www        42: use Apache::lonspeller();
1.54      albertel   43: use HTML::Entities();
1.1       www        44: 
                     45: sub handler {
                     46:     my $r = shift;
1.46      www        47:     &Apache::loncommon::content_type($r,'text/html');
                     48:     $r->send_http_header;
                     49:     return OK if $r->header_only;
1.45      www        50: 
1.46      www        51:     my $target=$env{'form.grade_target'};
1.45      www        52: # --------------------------------------------------- Get course info from URL
                     53:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.46      www        54: # ------------------------------------------------------------ Get query string
                     55:     &Apache::loncommon::get_unprocessed_cgi
1.116     raeburn    56:                         ($ENV{'QUERY_STRING'},['register','forceedit','todocs',
1.132     raeburn    57:                                                'folderpath','title','only_body']);
1.45      www        58: # ----------------------------------------------------- Is this even a course?
                     59:     my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom);
                     60:     if ($homeserver eq 'no_host') {
                     61:         &Apache::loncommon::content_type($r,'text/html');
                     62:         $r->send_http_header;
1.106     faziophi   63:         &Apache::loncommon::simple_error_page($r,'No syllabus available',
1.91      amueller   64:                           'No syllabus available');
1.45      www        65:         return OK;
1.113     raeburn    66:     } elsif (!&Apache::lonnet::is_course($cdom,$cnum)) {
                     67:         &Apache::loncommon::content_type($r,'text/html');
                     68:         $r->send_http_header;
                     69:         &Apache::loncommon::simple_error_page($r,'No syllabus available',
                     70:                           'The course/community for which the syllabus was requested does not exist.');
                     71:         return OK;
1.45      www        72:     }
                     73: # ------------------------------------- There is such a course, get environment
                     74:     my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.125     raeburn    75:     my $crstype = &Apache::loncommon::course_type();
1.46      www        76: 
1.117     raeburn    77: # --------------------------------------------------------------- Force Student
                     78:     my ($forceedit,$forcestudent);
                     79:     if ($env{'form.forceedit'}) { $forceedit=1; }
                     80:     if (!$forceedit) {
                     81:         $forcestudent=1;
                     82:     }
                     83: 
                     84: # --------------------------------------------------------------- Check Privileges
                     85:     my $allowed = 0;
                     86:     if ($env{'user.environment'}) {
                     87: # does this user have privileges to post, etc?
                     88:         if ($env{'request.course.id'}
                     89:         && $cdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}
                     90:         && $cnum eq $env{'course.'.$env{'request.course.id'}.'.num'}) {
                     91:             $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
                     92:             if ($forcestudent or $target eq 'tex') { $allowed=0; }
                     93:         }
                     94:     }
                     95: 
1.46      www        96: # -------------------------------------------------- Let's see who handles this
1.117     raeburn    97:     my $external=$courseenv{'externalsyllabus'};
                     98:     my $uploaded=$courseenv{'uploadedsyllabus'};
1.122     raeburn    99:     my $minimal=$courseenv{'minimalsyllabus'};
1.49      albertel  100: 
1.132     raeburn   101:     if (($minimal =~/\w/) || ($uploaded =~/\w/)) {
1.137     raeburn   102:         my ($item,$is_pdf);
1.122     raeburn   103:         if ($minimal =~/\w/) {
                    104:             if ($external =~ m{\Q$minimal\E$}) {
                    105:                 undef($external);
                    106:             }
                    107:             $item = $minimal;
                    108:         } elsif ($uploaded =~/\w/) {
                    109:             if ($external =~ m{\Q$uploaded\E$}) {
                    110:                 undef($external);
                    111:             }
                    112:             $item = $uploaded;
1.137     raeburn   113:             if ($item =~ /\.pdf$/i) {
                    114:                 $is_pdf = 1;
                    115:             }
1.117     raeburn   116:         }
                    117:         unless ($allowed && $forceedit) {
1.122     raeburn   118:             my $file=&Apache::lonnet::filelocation("",$item);
1.141     raeburn   119:             if ($file =~ /\.(tex|x?html?)$/) {
1.125     raeburn   120:                 my $filetype = $1;
1.117     raeburn   121:                 my $filecontents=&Apache::lonnet::getfile($file);
                    122:                 if ($filecontents eq -1) {
                    123:                     $r->print(&mt('Syllabus file unavailable'));
1.125     raeburn   124:                 } elsif ($filetype eq 'tex') {
1.130     raeburn   125:                     if ($target eq 'tex') {
                    126:                         $r->print($filecontents);
                    127:                     } else {
1.140     raeburn   128:                         my $texengine = $env{'form.texengine'};
                    129:                         if ($texengine eq '') {
                    130:                             $texengine = 'tth';
                    131:                         } elsif (lc($texengine) eq 'jsmath') {
                    132:                             $texengine = 'MathJax';
                    133:                         }
                    134:                         my $result = &Apache::lontexconvert::converted(\$filecontents,$texengine);
1.130     raeburn   135:                         my %args;
                    136:                         &get_breadcrumbs($cdom,$cnum,$crstype,\%args);
1.132     raeburn   137:                         if ($env{'form.only_body'}) {
                    138:                             $args{'only_body'} = 1;
                    139:                         }
1.137     raeburn   140:                         if ($env{'request.use_absolute'}) {
                    141:                             $args{'use_absolute'} = $env{'request.use_absolute'};
                    142:                         }
1.130     raeburn   143:                         $r->print(&Apache::loncommon::start_page("Syllabus",undef,\%args).
                    144:                                   $result.
                    145:                                   &Apache::loncommon::end_page());
                    146:                     }
1.125     raeburn   147:                 } else {
1.117     raeburn   148:                     my %mystyle;
1.130     raeburn   149:                     unless ($target eq 'tex') {
                    150:                         $target = 'web';
                    151:                     }
1.117     raeburn   152:                     &Apache::structuretags::reset_problem_globals();
                    153:                     my $oldfile = $env{'request.filename'};
1.122     raeburn   154:                     $env{'request.filename'} = $item;
1.130     raeburn   155:                     my $result = &Apache::lonxml::xmlparse($r,$target,$filecontents,
1.125     raeburn   156:                                                            '',%mystyle);
1.117     raeburn   157:                     &Apache::structuretags::reset_problem_globals();
                    158:                     &Apache::lonhomework::finished_parsing();
                    159:                     $env{'request.filename'} = $oldfile;
                    160:                     &Apache::lonxml::add_messages(\$result);
                    161:                     $r->print($result);
                    162:                 }
                    163:             } else {
1.130     raeburn   164:                 if ($target eq 'tex') {
                    165:                     $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}).
                    166:                               ' \strut \\\\ \textbf{'.&mt('Syllabus').'} \strut \\\\ '.
                    167:                               &mt('Unsupported file type.').' \strut \\\\ '.
                    168:                               &mt('Print the syllabus directly from your web browser').
                    169:                               '\end{document}');
                    170:                 } else {
1.141     raeburn   171:                     my $brcrum;
                    172:                     if ($env{'form.folderpath'} =~ /^supplemental/) {
                    173:                         my $title = $env{'form.title'};
                    174:                         if ($title eq '') {
                    175:                             $title = &mt('Syllabus');
                    176:                         }
                    177:                         $brcrum =
                    178:                             &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
                    179:                     }
1.146     raeburn   180:                     $r->print(&Apache::lonwrapper::wrapper($r,$item,$brcrum,$env{'request.use_absolute'},
1.147     raeburn   181:                                                            undef,$is_pdf,undef,'','',&mt('Syllabus')));
1.130     raeburn   182:                 }
1.117     raeburn   183:             }
                    184:             return OK;
                    185:         }
                    186:     } elsif ($external=~/\w/) {
                    187:         unless ($allowed && $forceedit) {
1.148     raeburn   188:             if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public') &&
                    189:                 ($ENV{'SERVER_PORT'} == 443) && ($external =~ m{^http://}) && !($env{'form.usehttp'})) {
1.149   ! raeburn   190:                 my $hostname = $r->hostname();
        !           191:                 unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.148     raeburn   192:                     &redirect_to_http($r);
                    193:                     return OK;
                    194:                 }
                    195:             }
1.130     raeburn   196:             if ($target eq 'tex') {
                    197:                 $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}).
                    198:                          ' \strut \\\\ \textbf{'.&mt('Syllabus').'} \strut \\\\ '.$external.' '.
                    199:                          ' \strut \\\\ '.&mt('Print the syllabus directly from your web browser').
                    200:                          '\end{document}');
                    201:             } else {
1.137     raeburn   202:                 my $is_ext = 1;
1.141     raeburn   203:                 my ($is_pdf,$brcrum);
1.137     raeburn   204:                 if ($external =~ /\.pdf$/i) {
                    205:                     $is_pdf = 1;
                    206:                 }
1.141     raeburn   207:                 if ($env{'form.folderpath'} =~ /^supplemental/) {
                    208:                     my $title = $env{'form.title'};
                    209:                     if ($title eq '') {
                    210:                         $title = &mt('Syllabus');
                    211:                     }
                    212:                     $brcrum =
                    213:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
                    214:                 }
1.146     raeburn   215:                 $r->print(&Apache::lonwrapper::wrapper($r,$external,$brcrum,$env{'request.use_absolute'},
1.147     raeburn   216:                                                        $is_ext,$is_pdf,undef,'','',&mt('Syllabus')));
1.130     raeburn   217:             }
1.117     raeburn   218:             return OK;
                    219:         }
1.90      amueller  220:     }
1.42      www       221: 
1.130     raeburn   222: # ------------------------------------------------------------ Print the screen
                    223: 
                    224:     if ($target eq 'tex') {
                    225:         $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
                    226:     }
1.120     raeburn   227: 
1.46      www       228: # ------------------------------ The buck stops here: internal syllabus display
1.5       www       229: # --------------------------------------------------------- The syllabus fields
1.23      www       230:     my %syllabusfields=&Apache::lonlocal::texthash(
1.5       www       231:        'aaa_instructorinfo' => 'Instructor Information',
                    232:        'bbb_description'    => 'Course Description',
                    233:        'ccc_prereq'         => 'Prerequisites',
1.7       www       234:        'cdc_classhours'     => 'Class Hours',
1.5       www       235:        'ddd_officehours'    => 'Office Hours',
                    236:        'eee_helproom'       => 'Helproom Hours',
1.7       www       237:        'efe_projectinfo'    => 'Project Information',
1.5       www       238:        'fff_examinfo'       => 'Exam Information',
1.7       www       239:        'fgf_deadlines'      => 'Deadlines',
1.5       www       240:        'ggg_grading'        => 'Grading Information',
1.7       www       241:        'hhh_readings'       => 'Readings',
                    242:        'iii_coursepack'     => 'Coursepack',
                    243:        'jjj_weblinks'       => 'Web Links',
1.9       www       244:        'kkk_textbook'       => 'Textbook',
                    245:        'lll_includeurl'     => 'URLs To Include in Syllabus');
1.121     raeburn   246: # ---------------------------------------------------------- Load syllabus info
                    247:     my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
                    248:     my ($output,%displayfields,%noshow);
1.65      raeburn   249: 
1.121     raeburn   250: # This handler might be called anonymously ...
                    251: # ----------------------------------------------------- Only if not public call
                    252:     if ($allowed) {
1.122     raeburn   253:         if (($env{'form.choice'} =~ /^(template|minimal|url|file)$/) ||
1.121     raeburn   254:             ($env{'form.phase'} =~ /^(upload|check)_embedded$/)) {
                    255:             my $earlyout;
1.122     raeburn   256:             ($earlyout,$uploaded,$external,$minimal,$output) =
                    257:                 &save_changes($cnum,$cdom,$uploaded,$external,$minimal,
                    258:                               \%syllabus,\%syllabusfields,\%courseenv);
                    259:             if (($env{'form.choice'} eq 'minimal') && 
                    260:                 ($minimal eq "/uploaded/$cdom/$cnum/portfolio/syllabus/loncapa.html")) { 
                    261:                 delete($env{'form.symb'});
                    262:                 delete($env{'request.symb'});
                    263:                 $r->internal_redirect("$minimal?editmode=1&forceedit=1");
                    264:                 return OK;
                    265:             }
1.121     raeburn   266:             if ($earlyout) {
                    267:                 if ($target ne 'tex') {
                    268:                     &print_header($r,$cnum,$cdom,$crstype,$allowed,$forceedit,
                    269:                                   \%syllabus,\%syllabusfields);
1.122     raeburn   270:                     $r->print($output.
                    271:                               &Apache::loncommon::end_page());
1.121     raeburn   272:                 }
                    273:                 return OK;
1.90      amueller  274:             }
1.65      raeburn   275:         }
                    276:     }
1.121     raeburn   277:     if ($target ne 'tex') {
                    278:         &print_header($r,$cnum,$cdom,$crstype,$allowed,$forceedit,\%syllabus,
                    279:                       \%syllabusfields);
                    280:         $r->print($output);
1.117     raeburn   281:     }
                    282: 
1.121     raeburn   283: # -------------------------------------------- Determine which fields are shown 
1.117     raeburn   284: 
1.121     raeburn   285:     if ($syllabus{'uploaded.fields'}) {
                    286:         if ($syllabus{'uploaded.fields'} eq 'none') {
                    287:             foreach my $field (keys(%syllabusfields)) {
                    288:                 $displayfields{$field} = ' style="display:none;"';
                    289:                 $noshow{$field} = 1;
1.117     raeburn   290:             }
                    291:         } else {
1.121     raeburn   292:             my %included;
                    293:             map { $included{$_} = 1; } split(/,/,$syllabus{'uploaded.fields'});
                    294:             foreach my $field (keys(%syllabusfields)) {
                    295:                 my ($prefix) = split(/_/,$field);
                    296:                 if ($included{$prefix}) {
                    297:                     $displayfields{$field} = ' style="display:block;"';
1.117     raeburn   298:                 } else {
1.121     raeburn   299:                     $displayfields{$field} = ' style="display:none;"';
                    300:                     $noshow{$field} = 1;
1.117     raeburn   301:                 }
                    302:             }
                    303:         }
1.121     raeburn   304:     } else {
1.117     raeburn   305:         foreach my $field (keys(%syllabusfields)) {
                    306:             if ($syllabus{$field} ne '') {
                    307:                 $displayfields{$field} = ' style="display:block;"';
                    308:             } else {
                    309:                 $displayfields{$field} = ' style="display:none;"';
                    310:             }
1.90      amueller  311:         }
1.4       www       312:     }
1.85      bisitz    313: 
1.113     raeburn   314:     if ($allowed) {
                    315: #---------------------------------- Print External URL Syllabus Info if editing
                    316:         if ($target ne 'tex') {
1.144     raeburn   317:             my $hostname = &Apache::lonnet::hostname($homeserver);
1.113     raeburn   318:             my $protocol = $Apache::lonnet::protocol{$homeserver};
                    319:             $protocol = 'http' if ($protocol ne 'https');
1.148     raeburn   320:             my $link = $protocol.'://'.$hostname.$r->uri;
1.119     raeburn   321:             $r->print('<div class="LC_left_float">'
                    322:                      .'<span class="LC_help_open_topic LC_info">'
                    323:                      .'<span class="LC_info">'
                    324:                      .&mt('Public link (no log-in): [_1]','<tt>'.$link.'</tt>')
                    325:                      .'&nbsp;</span>'.&Apache::loncommon::help_open_topic('Syllabus_ExtLink')
                    326:                      .'</span>'
1.121     raeburn   327:                      .'</div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n");
1.117     raeburn   328:             my $lonhost = $r->dir_config('lonHostID');
1.122     raeburn   329:             $r->print(&chooser($external,$uploaded,$minimal,$cdom,$cnum,$lonhost,
                    330:                                \%syllabusfields,\%syllabus));
1.93      bisitz    331:         }
1.109     bisitz    332:     } else {
1.113     raeburn   333: #--------------------------------------------- Print last update unless editing
                    334:         my $lastmod=$syllabus{'uploaded.lastmodified'};
                    335:         $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
                    336:         my $who;
                    337:         if ($syllabus{'uploaded.lastmodified'}) {
                    338:             if (($env{'user.name'} ne 'public') && ($env{'user.domain'} ne 'public')) {
                    339:                 $who = &Apache::loncommon::aboutmewrapper(
                    340:                        &Apache::loncommon::plainname($syllabus{'uploaded.name'},
                    341:                        $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
                    342:                        $syllabus{'uploaded.domain'});
                    343:             } else {
                    344: # Public user?
                    345: # Only display name of user, but no link to personal information page
                    346:                 $who = &Apache::loncommon::plainname(
                    347:                            $syllabus{'uploaded.name'},
                    348:                            $syllabus{'uploaded.domain'});
                    349:             }
                    350:         }
                    351:         if ($target ne 'tex') {
                    352:             $r->print('<div class="LC_info">'.&mt('Last updated').': '.
                    353:                       $lastmod . ' '.
                    354:                       ($who ? &mt('by').' '.$who
                    355:                            : '' ) .
                    356:                       '</div>' );
                    357:         } else {
                    358:             $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.
                    359:                      ($who? &mt('by').'\\\\ '.
                    360:                      &Apache::loncommon::plainname($syllabus{'uploaded.name'},$syllabus{'uploaded.domain'})
                    361:                      :'')
                    362:                     .'\\\\');
                    363:         }
1.109     bisitz    364:     }
                    365: 
1.113     raeburn   366: #-------------------------------------------------------------- Print Headtitle
1.90      amueller  367:     if ($target ne 'tex') {
1.117     raeburn   368:         my $display = 'block';
1.122     raeburn   369:         if ($external || $uploaded || $minimal) {
1.117     raeburn   370:             $display = 'none';
                    371:         }
                    372:         $r->print('<div class="LC_Box" id="template" style="display: '.$display.'">'.
1.113     raeburn   373:                    '<h2 class="LC_hcell">'.$courseenv{'description'}.'</h2>');
                    374:         if ($allowed) {
1.121     raeburn   375:             $r->print('<div style="margin: 0; float:left;">'.
                    376:                       '<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>'.
                    377:                       '</div>');
1.113     raeburn   378: # Print Help Text if editing at right side of screen
1.121     raeburn   379:             $r->print('<div style="margin: 0; float:right;">'.
                    380:                       &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).
                    381:                       '</div><br clear="all" />');
1.113     raeburn   382:         } else {
                    383:             $r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>');
                    384:         }
1.90      amueller  385:     } else {
1.91      amueller  386:         $r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
                    387:         &Apache::lonnet::domain($cdom,'description').'}\\\\');
1.90      amueller  388:     }
1.80      neumanie  389: # -------------------------------------------------------- Get course personnel
1.121     raeburn   390:     my $hidepersonnel;
                    391:     if (($syllabus{'uploaded.fields'}) &&
                    392:         (($syllabus{'uploaded.fields'} eq 'none') ||
                    393:          ($syllabus{'uploaded.fields'} !~ /000/))) {
                    394:         $hidepersonnel = 1;
                    395:     }
1.80      neumanie  396:     if ($target ne 'tex') {
1.121     raeburn   397:         if ($allowed) {
                    398:             my $display = ' style="display:block;"';
                    399:             if ($hidepersonnel) {
                    400:                 $display = ' style="display:none;"';
                    401:             }
                    402:             &Apache::lontemplate::print_start_template($r,&mt('Personnel'),'LC_Box',
                    403:                                                        'box_000_showpeople',$display);
1.127     raeburn   404:             $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed,$crstype,\%syllabus));
1.121     raeburn   405:             &Apache::lontemplate::print_end_template($r);
1.91      amueller  406:         } else {
1.121     raeburn   407:             unless ($hidepersonnel) {
                    408:                 &Apache::lontemplate::print_start_template($r,&mt('Personnel'),'LC_Box');
1.127     raeburn   409:                 $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed,$crstype,\%syllabus));  
1.121     raeburn   410:                 &Apache::lontemplate::print_end_template($r);
1.91      amueller  411:             }
                    412:         }
1.121     raeburn   413:     } else {
                    414:         unless ($hidepersonnel) {
1.127     raeburn   415:             $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed,$crstype,%syllabus));
1.91      amueller  416:         }
1.80      neumanie  417:     }
1.79      neumanie  418: # -------------------------------------------------------------- Announcements?
                    419:     my $day = &Apache::lonannounce::showday(time,2,
1.91      amueller  420:              &Apache::lonannounce::readcalendar($cdom.'_'.$cnum));
1.121     raeburn   421:     my $hidefeeds;
                    422:     if (($syllabus{'uploaded.fields'}) &&
                    423:         (($syllabus{'uploaded.fields'} eq 'none') ||
                    424:          ($syllabus{'uploaded.fields'} !~ /111/))) {
                    425:         $hidefeeds = 1;
                    426:     }
1.80      neumanie  427:     if ($target ne 'tex') {
1.91      amueller  428:         if ($allowed) {
1.117     raeburn   429:             my $display = ' style="display:block;"';
1.121     raeburn   430:             if ($hidefeeds) {
1.117     raeburn   431:                 $display = ' style="display:none;"';
                    432:             }
                    433:             &Apache::lontemplate::print_start_template($r,&mt('RSS Feeds and Blogs'),'LC_Box',
1.121     raeburn   434:                                                        'box_111_showrssfeeds',$display);
1.120     raeburn   435:             my ($numfeeds,$hiddenfeeds,$rsslinktext);
1.121     raeburn   436:             my $feeds=&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit,\$numfeeds,
                    437:                                                       \$hiddenfeeds);
1.120     raeburn   438:             if ($numfeeds) {
                    439:                 $r->print($feeds);
                    440:                 $rsslinktext = &mt('New RSS Feed or Blog');
                    441:             } else {
                    442:                 my $msg = '<br />'.
                    443:                           &mt("RSS Feeds and Blogs item is not included in a student's view of the syllabus.");
                    444:                 if ($hiddenfeeds) {
                    445:                     $r->print('<p class="LC_info">'.
                    446:                               &mt('All feeds currently hidden').
                    447:                               $msg.
                    448:                               '</p>');
                    449:                 } else {
                    450:                     $r->print('<p class="LC_info">'.
                    451:                               &mt('No current feeds').
                    452:                               $msg.
                    453:                               '</p>');
                    454:                 }
                    455:                 $rsslinktext = &mt('Manage Course RSS Feeds/Blogs');
                    456:                 if ($crstype eq 'Community') {
1.135     raeburn   457:                     $rsslinktext = &mt('Manage Community RSS Feeds/Blogs');
1.120     raeburn   458:                 }
                    459:             }
1.91      amueller  460:             my $editurl= &Apache::lonnet::absolute_url().'/adm/'.$cdom.'/'.$cnum.'/_rss.html';
1.120     raeburn   461:             $r->print( '<a href="'.$editurl.'">'.$rsslinktext.'</a>');
1.91      amueller  462:             &Apache::lontemplate::print_end_template($r);
1.117     raeburn   463:         } else {
1.121     raeburn   464:             unless ($hidefeeds) {
1.120     raeburn   465:                 my $feeds = &Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit);
                    466:                 if ($feeds ne '') {
1.117     raeburn   467:                     &Apache::lontemplate::print_start_template($r,&mt('RSS Feeds and Blogs'),'LC_Box');
1.120     raeburn   468:                     $r->print($feeds);
1.117     raeburn   469:                     &Apache::lontemplate::print_end_template($r);
                    470:                 }
                    471:             }
1.91      amueller  472:         }
1.79      neumanie  473:     } else {
1.91      amueller  474:         $r->print(&Apache::lonxml::xmlparse($r,'tex',$day));
1.86      bisitz    475:     }
1.79      neumanie  476: # ---------------------------------------------------------------- Get syllabus
1.86      bisitz    477:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.106     faziophi  478: 		my $url_include_handler = sub {
1.117     raeburn   479: 			my ($r, $field, $message, $group, $data_ref, $fields_ref, $target, $allowed, $display) = @_;
1.106     faziophi  480: 			my %data = %{$data_ref};
                    481: 			my %fields = %{$fields_ref};
                    482: 			my $urls=$message;
                    483: 			$message='';
                    484: 			foreach my $filelink (split(/\n/,$urls)) {
                    485: 				my $output='';
                    486: 			   # embed style?
                    487: 				my ($curfext)=($filelink=~/\.([^\.]+)$/);
                    488: 				my $embstyle=&Apache::loncommon::fileembstyle($curfext);
                    489: 				if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {# make ssi call and remove everything but the body contents
                    490: 					$output=&Apache::lonnet::ssi_body($filelink);
                    491: 				} elsif ($embstyle eq 'img') {# embed as an image
                    492: 					$output='<img src="'.$filelink.'" />';
                    493: 				}
                    494: 				if ($output ne '') {
                    495: 					   if ($target ne 'tex') {
                    496: 						   $message.='<p>'.$output.'</p>';
                    497: 					   } else {
                    498: 						   $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
                    499: 					   }
                    500: 				}
                    501: 			}
                    502: 			if ($allowed) {
                    503: 				 &Apache::lonfeedback::newline_to_br(\$urls);
                    504: 				 &Apache::lontemplate::print_start_template($r,$fields{$field}.
1.117     raeburn   505: 						  &Apache::loncommon::help_open_topic('Syllabus_URLs'),'LC_Box',
                    506:                                                   'box_'.$field,$display);
1.106     faziophi  507: 				 $r->print($urls);
                    508: 				 $r->print("<br /><div>");
                    509: 				 &Apache::lontemplate::print_textarea_template($r, $data{$field},
                    510: 					$field, Apache::lontemplate->RICH_TEXT_ALWAYS_OFF);
                    511: 				 &Apache::lontemplate::print_saveall_template($r);                         
                    512: 				 $r->print("</div>");
                    513: 				 &Apache::lontemplate::print_end_template($r);
1.86      bisitz    514: 
1.106     faziophi  515: 			} else {
                    516: 				$r->print($message);
                    517: 			}
                    518: 		};
                    519: 		my %custom_hash = ( 'lll_includeurl' => $url_include_handler );
1.110     raeburn   520: 		&Apache::lontemplate::print_template_fields($r, \%syllabus, \%syllabusfields, 
1.117     raeburn   521: 			$target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_hash,
1.121     raeburn   522:                         undef,\%displayfields,\%noshow);
1.90      amueller  523:         if ($allowed) {
1.129     raeburn   524:             $r->print('</div></form>'.
1.110     raeburn   525:             &Apache::lonhtmlcommon::htmlareaselectactive());
1.90      amueller  526:         }
1.4       www       527:     } else {
1.112     bisitz    528:         if ($target ne 'tex') {$r->print('<p class="LC_info">');} else {$r->print('\par ');}
1.91      amueller  529:         $r->print(&mt('No syllabus information provided.'));
                    530:         if ($target ne 'tex') {$r->print('</p>');}
1.1       www       531:     }
1.86      bisitz    532:     if ($target ne 'tex') {
1.65      raeburn   533:         if ($env{'form.backto'} eq 'coursecatalog') {
                    534:             $r->print('<form name="backtocat" method="post" action="/adm/coursecatalog">'.
1.66      raeburn   535:                       &Apache::lonhtmlcommon::echo_form_input(['backto','courseid']).
1.65      raeburn   536:                       '</form>');
                    537:         }
1.91      amueller  538:         $r->print(&Apache::loncommon::end_page());
1.48      albertel  539:     } else {
1.91      amueller  540:         $r->print('\end{document}');
1.48      albertel  541:     }
1.1       www       542:     return OK;
1.86      bisitz    543: }
1.1       www       544: 
1.121     raeburn   545: sub print_header {
                    546:     my ($r,$cnum,$cdom,$crstype,$allowed,$forceedit,$syllabus,$syllabusfields) = @_;
                    547:     return unless ((ref($syllabus) eq 'HASH') || (ref($syllabusfields) eq 'HASH'));
                    548: # ----------------------------------------------------------------- Make header
                    549:     my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
                    550:     my $js;
                    551:     if ($env{'form.backto'} eq 'coursecatalog') {
                    552:         $js .= <<"ENDSCRIPT";
                    553: 
                    554: <script type="text/javascript">
                    555: // <![CDATA[
                    556: 
                    557: function ToCatalog(caller) {
                    558:     numidx = getIndexByName('coursenum');
                    559:         if (numidx > -1) {
                    560:             if (caller != 'details') {
                    561:                 document.backtocat.elements[numidx].value = '';
                    562:             }
                    563:         }
                    564:     document.backtocat.submit();
                    565: }
                    566: 
                    567: function getIndexByName(item) {
                    568:     for (var i=0;i<document.backtocat.elements.length;i++) {
                    569:         if (document.backtocat.elements[i].name == item) {
                    570:             return i;
                    571:         }
                    572:     }
                    573:     return -1;
                    574: }
                    575: 
                    576: // ]]>
                    577: </script>
                    578: 
                    579: ENDSCRIPT
                    580:     }
                    581:     if ($allowed && $forceedit) {
                    582:         my $check_uncheck = &Apache::loncommon::check_uncheck_jscript();
                    583:         my @fieldnames = sort(keys(%{$syllabusfields}));
                    584:         unshift(@fieldnames,'000_showpeople','111_showrssfeeds');
                    585:         my (@checked,@unchecked);
                    586:         if ($syllabus->{'uploaded.fields'} eq 'none') {
                    587:             my $lastidx = scalar(@fieldnames)-1;
                    588:             @unchecked = (0..$lastidx);
                    589:         } elsif ($syllabus->{'uploaded.fields'}) {
                    590:             my %included;
                    591:             map { $included{$_} = 1; } split(/,/,$syllabus->{'uploaded.fields'});
                    592:             for (my $i=0; $i<@fieldnames; $i++) {
                    593:                 my ($prefix) = split(/_/,$fieldnames[$i]);
                    594:                 if ($included{$prefix}) {
                    595:                     push(@checked,$i);
                    596:                 } else {
                    597:                     push(@unchecked,$i);
                    598:                 }
                    599:             }
                    600:         } else {
                    601:             @checked = (0,1);
                    602:             for (my $i=2; $i<@fieldnames; $i++) {
                    603:                 if ($syllabus->{$fieldnames[$i]}) {
                    604:                     push(@checked,$i);
                    605:                 } else {
                    606:                     push(@unchecked,$i);
                    607:                 }
                    608:             }
                    609:         }
                    610:         my $fieldstr = "var fields = new Array('".join("','",@fieldnames)."');";
                    611:         my $checkedstr = "var include = new Array('".join("','",@checked)."');";
                    612:         my $uncheckedstr = "var exclude = new Array('".join("','",@unchecked)."');";
                    613:         my $invurl = &mt('Invalid URL');
1.138     damieng   614:         &js_escape(\$invurl);
1.121     raeburn   615:         my $urlregexp = <<'ENDREGEXP';
                    616: /^([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
                    617: ENDREGEXP
                    618: 
                    619:         $js .= <<"ENDSCRIPT";
                    620: 
                    621: <script type="text/javascript">
                    622: // <![CDATA[
                    623: 
                    624: function toggleEditor(pick) {
1.122     raeburn   625:     var choices = new Array('template','minimal','url','file','templatebox');
1.121     raeburn   626:     for (var i=0; i<choices.length; i++) {
                    627:         if (((choices[i] == 'templatebox') && (pick == 'template')) ||
                    628:             (choices[i] == pick)) {
                    629:             document.getElementById(choices[i]).style.display='block';
                    630:         } else {
                    631:             document.getElementById(choices[i]).style.display='none';
                    632:         }
                    633:     }
                    634:     return;
                    635: }
                    636: 
                    637: var regexp = $urlregexp;
                    638: 
1.142     raeburn   639: function extUrlPreview(caller,protocol) {
1.121     raeburn   640:     if (document.getElementById(caller)) {
                    641:         var url = document.getElementById(caller).value;
                    642:         if (regexp.test(url)) {
1.142     raeburn   643:             var http_regex = /^http\:\/\//gi;
                    644:             if ((protocol == 'https') && (http_regex.test(url))) {
                    645:                 window.open(url,"syllabuspreview","height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1");
                    646:             } else {
                    647:                 openMyModal(url,500,400,'yes');
                    648:             }
1.121     raeburn   649:         } else {
                    650:             alert("$invurl");
                    651:         }
                    652:     }
                    653: }
                    654: 
                    655: function toggleBox(name,caller) {
                    656:     if (name == 'all') {
                    657:         if (document.syllabus.showfield.length > 0) {
                    658:             for (var i=0; i<document.syllabus.showfield.length; i++) {
                    659:                 if (document.syllabus.showfield[i].checked) {
                    660:                     if (document.getElementById('box_'+document.syllabus.showfield[i].value)) {
                    661:                         document.getElementById('box_'+document.syllabus.showfield[i].value).style.display='block';
                    662:                     }
                    663:                 } else {
                    664:                     if (document.getElementById('box_'+document.syllabus.showfield[i].value)) {
                    665:                         document.getElementById('box_'+document.syllabus.showfield[i].value).style.display='none';
                    666:                     }
                    667:                 }
                    668:             }
                    669:         }
                    670:     } else {
                    671:         if (caller.checked) {
                    672:             if (document.getElementById('box_'+caller.value)) {
                    673:                 document.getElementById('box_'+caller.value).style.display='block';
                    674:             }
                    675:         } else {
                    676:             if (document.getElementById('box_'+caller.value)) {
                    677:                 document.getElementById('box_'+caller.value).style.display='none';
                    678:             }
                    679:         }
                    680:     }
                    681:     return;
                    682: }
                    683: 
                    684: function setTemplateBoxes() {
                    685:     $fieldstr
                    686:     $checkedstr
                    687:     $uncheckedstr
                    688:     if (include.length > 0) {
                    689:         for (var i=0; i<include.length; i++) {
                    690:             if (document.getElementById('showfield_'+include[i])) {
                    691:                 document.getElementById('showfield_'+include[i]).checked = true;
                    692:                 if (document.getElementById('box_'+fields[include[i]])) {
                    693:                     document.getElementById('box_'+fields[include[i]]).style.display='block';
                    694:                 }
                    695:             }
                    696:         }
                    697:     }
                    698:     if (exclude.length > 0) {
                    699:         for (var i=0; i<exclude.length; i++) {
                    700:             if (document.getElementById('showfield_'+exclude[i])) {
                    701:                 document.getElementById('showfield_'+exclude[i]).checked = false;
                    702:                 if (document.getElementById('box_'+fields[exclude[i]])) {
                    703:                     document.getElementById('box_'+fields[exclude[i]]).style.display='none';
                    704:                 }
                    705:             }
                    706:         }
                    707:     }
                    708:     return;
                    709: }
                    710: 
                    711: $check_uncheck
                    712: 
                    713: // ]]>
                    714: </script>
                    715: 
                    716: ENDSCRIPT
                    717:     }
                    718:     my $args = {'function'       => undef,
                    719:                 'domain'         => $cdom};
                    720:     my $forcereg;
                    721:     if ($env{'form.register'}) {
                    722:         $forcereg = 1;
                    723:         $args->{'force_register'} = $forcereg;
                    724:     }
                    725:     if ($env{'form.backto'} eq 'coursecatalog') {
                    726:         &Apache::lonhtmlcommon::clear_breadcrumbs();
                    727:         my $brcrum = [{href=>"javascript:ToCatalog();",
                    728:                        text=>&mt('Course/Community Catalog'),
                    729:                        no_mt=>1}
                    730:                      ];
                    731:         if ($env{'form.coursenum'} ne '') {
                    732:             push(@{$brcrum},
                    733:                   {href=>"javascript:ToCatalog('details')",
                    734:                    text=>"Course details"});
                    735:         }
                    736:         push(@{$brcrum},
                    737:               {href=>$r->uri,
                    738:                text=>"Course syllabus"});
                    739:         $args->{'bread_crumbs'} = $brcrum;
1.125     raeburn   740:     } else {
                    741:         &get_breadcrumbs($cdom,$cnum,$crstype,$args);
                    742:     }
                    743:     if ($allowed) {
                    744:         my %loaditem = (
                    745:                          onload => 'setTemplateBoxes();',
                    746:                        );
                    747:         $args->{'add_entries'} = \%loaditem;
1.137     raeburn   748:     } else {
                    749:         if ($env{'request.use_absolute'}) {
                    750:             $args->{'use_absolute'} = $env{'request.use_absolute'};
                    751:         }
1.125     raeburn   752:     }
1.132     raeburn   753:     if ($env{'form.only_body'}) {
                    754:         $args->{'only_body'} = 1;
                    755:     }
1.143     raeburn   756:     $args->{'hostname'} = $r->hostname();
1.125     raeburn   757:     my $start_page =
                    758:         &Apache::loncommon::start_page("Syllabus", $rss_link.$js,$args);
                    759:     if ($start_page) {
                    760:         $r->print($start_page);
                    761:     }
                    762: }
                    763: 
                    764: sub get_breadcrumbs{
                    765:     my ($cdom,$cnum,$crstype,$args) = @_;
                    766:     return unless (ref($args) eq 'HASH');
                    767:     if ($env{'form.folderpath'} =~ /^supplemental/) {
1.121     raeburn   768:         my $title = $env{'form.title'};
                    769:         if ($title eq '') {
                    770:             $title = &mt('Syllabus');
                    771:         }
                    772:         my $brcrum =
                    773:             &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
                    774:         if (ref($brcrum) eq 'ARRAY') {
                    775:             $args->{'bread_crumbs'} = $brcrum;
                    776:         }
                    777:     } else {
                    778:         if ((&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus"))
                    779:                  && (($env{'form.symb'}) || ($env{'form.register'}))) {
                    780:             &Apache::lonhtmlcommon::clear_breadcrumbs();
                    781:         } else {
                    782:             $args->{'bread_crumbs'} = [
                    783:                                         {'href' => "/public/$cdom/$cnum/syllabus",
                    784:                                          'text' => 'Syllabus'},
                    785:                                       ];
                    786:         }
                    787:     }
1.125     raeburn   788:     return;
1.121     raeburn   789: }
                    790: 
1.117     raeburn   791: sub chooser {
1.122     raeburn   792:     my ($external,$uploaded,$minimal,$cdom,$cnum,$lonhost,$fields,$values) = @_;
1.117     raeburn   793:     my %lt = &Apache::lonlocal::texthash(
                    794:                  'type'          => 'Syllabus Type',
                    795:                  'url'           => 'External URL',
1.122     raeburn   796:                  'file'          => 'Uploaded file',
                    797:                  'minimal'       => 'Minimal template',
                    798:                  'template'      => 'Standard template',
1.117     raeburn   799:                  'templateboxes' => 'Choose template items ... ',
                    800:                  'curr'          => 'Current:',
                    801:                  'rep'           => 'Replace:',
                    802:                  'upl'           => 'Upload:',
                    803:                  'pr'            => 'Preview',
                    804:                  'save'          => 'Save',
1.122     raeburn   805:                  'sved'          => 'Save and Edit',
                    806:                  'chourl'        => 'External URL',
1.117     raeburn   807:                  'chofile'       => 'Uploaded syllabus file',
                    808:                  'parse'         => 'Upload embedded images/multimedia files if HTML file',
                    809:     );
                    810:     my %checked = (
                    811:                     file     => '',
1.122     raeburn   812:                     minimal  => '',
1.117     raeburn   813:                     url      => '',
                    814:                     template => '',
                    815:                   );
                    816:     my %display = (
                    817:                     file        => 'none',
1.122     raeburn   818:                     minimal     => 'none',
1.117     raeburn   819:                     url         => 'none',
                    820:                     templatebox => 'none',
                    821:                   );
                    822:     my $check = ' checked="checked" ';
                    823:     if ($uploaded) {
                    824:         $checked{'file'} = $check;
                    825:         $display{'file'} = 'block';
                    826:     } elsif ($external) {
                    827:         $checked{'url'}  = $check;
                    828:         $display{'url'} = 'block';
1.122     raeburn   829:     } elsif ($minimal) {
                    830:         $checked{'minimal'} = $check;
                    831:         $display{'minimal'} = 'block';
1.117     raeburn   832:     } else {
                    833:         $checked{'template'} = $check;
                    834:         $checked{'templatebox'} = $check;
                    835:         $display{'templatebox'} = 'block';
                    836:     }
1.142     raeburn   837:     my $protocol = ($ENV{'SERVER_PORT'} == 443?'https':'http');
1.117     raeburn   838: 
                    839:     my $output = 
                    840:         '<form name="syllabus" method="post" enctype="multipart/form-data" action="">'."\n".
                    841:         '<input type="hidden" name="forceedit" value="1" />'."\n".
                    842:         '<div class="LC_left_float"><fieldset><legend>'.$lt{'type'}.'</legend>';
1.122     raeburn   843:     foreach my $item ('minimal','template','url','file') {
1.117     raeburn   844:         $output .= '<label><input type="radio" name="choice" value="'.$item.'" '.$checked{$item}.' onclick="toggleEditor('."'$item'".')" />'.
                    845:                    $lt{$item}.'</label><br />';
                    846:     }
                    847:     $output .= '</fieldset></div>'."\n".
                    848:                '<div id="url" class="LC_left_float" style="display: '.$display{'url'}.'">'."\n".
                    849:                '<fieldset><legend>'.$lt{'chourl'}.'</legend><span class="LC_nobreak">'."\n".
1.142     raeburn   850:                '<a href="javascript:extUrlPreview('."'syllabusurl','$protocol'".');">'.$lt{'pr'}.'</a></span>&nbsp;'."\n".
1.117     raeburn   851:                '<input type="text" id="syllabusurl" name="externalsyllabus" value="'.$external.'" size="55" />'."\n".
                    852:                '&nbsp;<input type="submit" name="storeurl" value="'.$lt{'save'}.'" />'."\n".
                    853:                '</fieldset></div>'."\n".
1.122     raeburn   854:                '<div id="minimal" class="LC_left_float" style="display: '.$display{'minimal'}.'">'."\n".
                    855:                '<fieldset><legend>'.$lt{'minimal'}.'</legend>';
                    856:     if ($minimal) {
                    857:         my ($absurl,$filename,$depbutton) = &syllabus_file_info($minimal,$cnum,$cdom,$lonhost,'minimal');
                    858:         $output .= '<a href="javascript:extUrlPreview('."'currminimal'".');">'.$lt{'pr'}.'</a>'.
                    859:                    '<input type="hidden" name="minimalfile" value="'.&HTML::Entities::encode($absurl).'?inhibitmenu=yes" id="currminimal" />'.
                    860:                    $depbutton;
                    861:     } else {
                    862:         $output .= &mt('Title of Syllabus Page:').'&nbsp;'.
                    863:                    '<input type="text" id="minimaltitle" name="syllabustitle" value="'.&mt('Syllabus').'" size="30" />'."\n".
                    864:                    '&nbsp;<input type="submit" name="storeminimal" value="'.$lt{'sved'}.'" />'."\n";
                    865:     }
                    866:     $output .= '</fieldset></div>'."\n".
                    867:                '<div id="file" class="LC_left_float" style="display: '.$display{'file'}.'">'."\n".
                    868:                '<fieldset><legend>'.$lt{'file'}.'</legend>';
1.117     raeburn   869:     if ($uploaded) {
1.122     raeburn   870:         my ($absurl,$filename,$depbutton) = &syllabus_file_info($uploaded,$cnum,$cdom,$lonhost,'file');
1.117     raeburn   871:         $output .= '<span class="LC_nobreak">'.$lt{'curr'}.'&nbsp;'.
                    872:                    '<input type="hidden" name="uploadedfile" value="'.&HTML::Entities::encode($absurl).'?inhibitmenu=yes" id="currfile" />'.
1.118     raeburn   873:                    '<a href="javascript:extUrlPreview('."'currfile'".');">'.$filename.'</a></span>'.$depbutton.
                    874:                    '<br /><br />'.$lt{'rep'};
1.117     raeburn   875:     } else {
                    876:         $output .= $lt{'upl'};
                    877:     }
                    878:     $output .= '<br />'."\n".
                    879:                '<span class="LC_nobreak">'.
                    880:                '<input type="file" name="syllabusfile" size="55" />'."\n".
                    881:                '&nbsp;<input type="submit" name="storefile" value="'.$lt{'save'}.'" />'.
                    882:                '</span><br />'.
                    883:                '<label>'.
                    884:                '<input type="checkbox" name="parserflag" checked="checked" />'.
                    885:                $lt{'parse'}.
                    886:                '</label>'.
                    887:                '</fieldset></div>'.
                    888:                '<div id="templatebox" class="LC_left_float" style="display: '.
                    889:                $display{'templatebox'}.';"><fieldset><legend>'.$lt{'templateboxes'}.
                    890:                '&nbsp;<input type="button" value="'.&mt('check all').'" '.
                    891:                'onclick="javascript:checkAll('."document.syllabus.showfield".');javascript:toggleBox('."'all'".');" />'.
                    892:                ('&nbsp;'x2).
                    893:                '<input type="button" value="'.&mt('uncheck all').'" '.
                    894:                'onclick="javascript:uncheckAll('."document.syllabus.showfield".');javascript:toggleBox('."'all'".');" />'.
                    895:                '</legend>'.
                    896:                &fields_check_uncheck($fields,$values).
1.121     raeburn   897:                '</fieldset><br />'.
                    898:                '<input type="submit" name="storesyl" value="'.&mt('Save All').'" />'.
1.117     raeburn   899:                '</div>';
1.121     raeburn   900:     $output .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.117     raeburn   901:     return $output;
                    902: }
                    903: 
1.122     raeburn   904: sub syllabus_file_info {
                    905:     my ($item,$cnum,$cdom,$lonhost,$context) = @_;
1.144     raeburn   906:     my $hostname = &Apache::lonnet::hostname($lonhost);
1.122     raeburn   907:     my $protocol = $Apache::lonnet::protocol{$lonhost};
                    908:     $protocol = 'http' if ($protocol ne 'https');
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>