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

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

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