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

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

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