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

1.1       www         1: # The LearningOnline Network
                      2: # Syllabus
                      3: #
1.156   ! raeburn     4: # $Id: lonsyllabus.pm,v 1.155 2024/01/25 22:23:32 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},
1.156   ! raeburn   524: 					$field, $fields{$field}, Apache::lontemplate->RICH_TEXT_ALWAYS_OFF);
1.106     faziophi  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:     }
1.156   ! raeburn   863:     my $urllabeltext = &HTML::Entities::encode(&mt('Enter URL'),'"&<>');
1.117     raeburn   864:     $output .= '</fieldset></div>'."\n".
                    865:                '<div id="url" class="LC_left_float" style="display: '.$display{'url'}.'">'."\n".
                    866:                '<fieldset><legend>'.$lt{'chourl'}.'</legend><span class="LC_nobreak">'."\n".
1.142     raeburn   867:                '<a href="javascript:extUrlPreview('."'syllabusurl','$protocol'".');">'.$lt{'pr'}.'</a></span>&nbsp;'."\n".
1.156   ! raeburn   868:                '<input type="text" id="syllabusurl" name="externalsyllabus" value="'.$external.'" size="55" aria-label="'.$urllabeltext.'" />'."\n".
1.117     raeburn   869:                '&nbsp;<input type="submit" name="storeurl" value="'.$lt{'save'}.'" />'."\n".
                    870:                '</fieldset></div>'."\n".
1.122     raeburn   871:                '<div id="minimal" class="LC_left_float" style="display: '.$display{'minimal'}.'">'."\n".
                    872:                '<fieldset><legend>'.$lt{'minimal'}.'</legend>';
                    873:     if ($minimal) {
1.150     raeburn   874:         my ($absurl,$filename,$depbutton) = &syllabus_file_info($r,$minimal,$cnum,$cdom,$lonhost,'minimal');
1.122     raeburn   875:         $output .= '<a href="javascript:extUrlPreview('."'currminimal'".');">'.$lt{'pr'}.'</a>'.
                    876:                    '<input type="hidden" name="minimalfile" value="'.&HTML::Entities::encode($absurl).'?inhibitmenu=yes" id="currminimal" />'.
                    877:                    $depbutton;
                    878:     } else {
1.156   ! raeburn   879:         $output .= '<label>'.&mt('Title of Syllabus Page:').'&nbsp;'.
        !           880:                    '<input type="text" id="minimaltitle" name="syllabustitle" value="'.&mt('Syllabus').'" size="30" /></label>'."\n".
1.122     raeburn   881:                    '&nbsp;<input type="submit" name="storeminimal" value="'.$lt{'sved'}.'" />'."\n";
                    882:     }
                    883:     $output .= '</fieldset></div>'."\n".
                    884:                '<div id="file" class="LC_left_float" style="display: '.$display{'file'}.'">'."\n".
                    885:                '<fieldset><legend>'.$lt{'file'}.'</legend>';
1.117     raeburn   886:     if ($uploaded) {
1.150     raeburn   887:         my ($absurl,$filename,$depbutton) = &syllabus_file_info($r,$uploaded,$cnum,$cdom,$lonhost,'file');
1.117     raeburn   888:         $output .= '<span class="LC_nobreak">'.$lt{'curr'}.'&nbsp;'.
                    889:                    '<input type="hidden" name="uploadedfile" value="'.&HTML::Entities::encode($absurl).'?inhibitmenu=yes" id="currfile" />'.
1.118     raeburn   890:                    '<a href="javascript:extUrlPreview('."'currfile'".');">'.$filename.'</a></span>'.$depbutton.
                    891:                    '<br /><br />'.$lt{'rep'};
1.117     raeburn   892:     } else {
                    893:         $output .= $lt{'upl'};
                    894:     }
1.156   ! raeburn   895:     my $labeltext = &HTML::Entities::encode(&mt('Choose syllabus file'),'"&<>');
1.117     raeburn   896:     $output .= '<br />'."\n".
                    897:                '<span class="LC_nobreak">'.
1.156   ! raeburn   898:                '<input type="file" name="syllabusfile" size="55" aria-label="'.$labeltext.'" />'."\n".
1.117     raeburn   899:                '&nbsp;<input type="submit" name="storefile" value="'.$lt{'save'}.'" />'.
                    900:                '</span><br />'.
                    901:                '<label>'.
                    902:                '<input type="checkbox" name="parserflag" checked="checked" />'.
                    903:                $lt{'parse'}.
                    904:                '</label>'.
                    905:                '</fieldset></div>'.
                    906:                '<div id="templatebox" class="LC_left_float" style="display: '.
                    907:                $display{'templatebox'}.';"><fieldset><legend>'.$lt{'templateboxes'}.
                    908:                '&nbsp;<input type="button" value="'.&mt('check all').'" '.
                    909:                'onclick="javascript:checkAll('."document.syllabus.showfield".');javascript:toggleBox('."'all'".');" />'.
                    910:                ('&nbsp;'x2).
                    911:                '<input type="button" value="'.&mt('uncheck all').'" '.
                    912:                'onclick="javascript:uncheckAll('."document.syllabus.showfield".');javascript:toggleBox('."'all'".');" />'.
                    913:                '</legend>'.
                    914:                &fields_check_uncheck($fields,$values).
1.121     raeburn   915:                '</fieldset><br />'.
                    916:                '<input type="submit" name="storesyl" value="'.&mt('Save All').'" />'.
1.117     raeburn   917:                '</div>';
1.121     raeburn   918:     $output .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.117     raeburn   919:     return $output;
                    920: }
                    921: 
1.122     raeburn   922: sub syllabus_file_info {
1.150     raeburn   923:     my ($r,$item,$cnum,$cdom,$lonhost,$context) = @_;
1.144     raeburn   924:     my $hostname = &Apache::lonnet::hostname($lonhost);
1.122     raeburn   925:     my $protocol = $Apache::lonnet::protocol{$lonhost};
                    926:     $protocol = 'http' if ($protocol ne 'https');
1.150     raeburn   927:     my $alias = &Apache::lonnet::use_proxy_alias($r,$lonhost);
                    928:     $hostname = $alias if ($alias ne '');
1.144     raeburn   929:     my $absurl = $protocol.'://'.$hostname.$item;
1.122     raeburn   930:     my ($filename) = ($item =~ m{([^/]+)$});
                    931:     my $file=&Apache::lonnet::filelocation("",$item);
1.125     raeburn   932:     my ($depbutton,$filetype,$editable);
                    933:     if ($file =~ /\.(xhtml|xml|tex|html|htm)$/) {
                    934:         $filetype=$1;
                    935:     }
                    936:     if ($filetype) {
                    937:         unless ($filetype eq 'tex') {
                    938:             $filetype='html';
                    939:         }
                    940:     }
                    941:     if ($filetype eq 'html') {
1.122     raeburn   942:         my $filecontents=&Apache::lonnet::getfile($file);
                    943:         unless ($filecontents eq -1) {
                    944:             my $mm = new File::MMagic;
                    945:             my $mimetype = $mm->checktype_contents($filecontents);
                    946:             if ($mimetype eq 'text/html') {
                    947:                 my (%codebase,%allfiles);
                    948:                 my $parse_result = &Apache::lonnet::extract_embedded_items($item,\%allfiles,
                    949:                                                                            \%codebase,\$filecontents);
                    950:                 my $actionurl = "/public/$cdom/$cnum/syllabus";
                    951:                 my ($ignore,$num,$numpathchanges,$existing,$mapping) =
                    952:                     &Apache::loncommon::ask_for_embedded_content($actionurl,undef,\%allfiles,
                    953:                                                                  \%codebase,
                    954:                                                                  {'context' => 'rewrites',
                    955:                                                                   'ignore_remote_references' => 1,});
1.125     raeburn   956:                 $editable = 1;
1.122     raeburn   957:             }
                    958:         }
                    959:     }
1.125     raeburn   960:     $depbutton = ('&nbsp;' x 3).
                    961:                  &editfile_button($item,$context,$editable).
                    962:                  &editbutton_js();
1.122     raeburn   963:     return ($absurl,$filename,$depbutton);
                    964: }
                    965: 
1.117     raeburn   966: sub fields_check_uncheck {
                    967:     my ($fields,$values) = @_;
                    968:     return unless ((ref($fields) eq 'HASH') && (ref($values) eq 'HASH'));
                    969:     my $numinrow = 4;
                    970:     my $table;
                    971:     my @fieldnames = sort(keys(%{$fields}));
1.121     raeburn   972:     unshift(@fieldnames,'000_showpeople','111_showrssfeeds'); 
1.117     raeburn   973:     my $numfields = scalar(@fieldnames);
1.121     raeburn   974:     my %included;
                    975:     if (($values->{'uploaded.fields'}) && ($values->{'uploaded.fields'} ne 'none')) {
                    976:         map { $included{$_} = 1; } split(/,/,$values->{'uploaded.fields'});
                    977:     }
1.117     raeburn   978:     for (my $i=0; $i<$numfields; $i++) {
1.121     raeburn   979:         my ($name,$checked);
                    980:         if ($fieldnames[$i] eq '000_showpeople') {
                    981:             $name = &mt('Personnel');
                    982:         } elsif ($fieldnames[$i] eq '111_showrssfeeds') {
1.117     raeburn   983:             $name = &mt('RSS Feeds and Blogs');
1.121     raeburn   984:         } else {
                    985:             $name = $fields->{$fieldnames[$i]};
                    986:         }
                    987:         if ($values->{'uploaded.fields'}) {
                    988:             unless ($values->{'uploaded.fields'} eq 'none') {
                    989:                 my ($prefix) = split(/_/,$fieldnames[$i]);
                    990:                 if ($included{$prefix}) {
                    991:                     $checked = ' checked="checked"';
                    992:                 }
                    993:             }
                    994:         } else {
                    995:             if ($fieldnames[$i] eq '000_showpeople') {
                    996:                 $checked = ' checked="checked"';
                    997:             } elsif ($fieldnames[$i] eq '111_showrssfeeds') {
1.117     raeburn   998:                 $checked = ' checked="checked"';
1.121     raeburn   999:             } else {
                   1000:                 if ($values->{$fieldnames[$i]} ne '') {
                   1001:                     $checked = ' checked="checked"';
                   1002:                 }
1.117     raeburn  1003:             }
                   1004:         }
                   1005:         my $rem = $i%($numinrow);
                   1006:         if ($rem == 0) {
1.121     raeburn  1007:             if (($i > 0) && ($i < $numfields)) {
1.117     raeburn  1008:                 $table .= '</tr>';
                   1009:             }
1.121     raeburn  1010:             if ($i < $numfields) {
1.117     raeburn  1011:                 $table .= '<tr>';
                   1012:             }
                   1013:         }
1.121     raeburn  1014:         if ($i == $numfields-1) {
                   1015:             my $rem = $numfields%($numinrow);
                   1016:             my $colsleft = $numinrow - $rem;
                   1017:             if ($colsleft > 1) {
                   1018:                 $table .= '<td colspan="'.$colsleft.'">';
                   1019:             } else {
                   1020:                 $table .= '</td>';
                   1021:             }
                   1022:         } else {
                   1023:             $table .= '<td>';
                   1024:         }
1.117     raeburn  1025:         $table .=
1.121     raeburn  1026:             '<label><input type="checkbox" name="showfield" value="'.$fieldnames[$i].'" '.
1.117     raeburn  1027:             $checked.' id="showfield_'.$i.'" onclick="javascript:toggleBox('."'$fieldnames[$i]',this".');" />'.
                   1028:             $name.'</label></td>'."\n";
                   1029:     }
                   1030:     if ($table ne '') {
                   1031:         my $rem = $numfields%($numinrow);
                   1032:         my $colsleft = $numinrow - $rem;
                   1033:         if ($colsleft > 1 ) {
                   1034:             $table .= '<td colspan="'.$colsleft.'">&nbsp;</td>';
                   1035:         } elsif ($colsleft == 1) {
                   1036:             $table .= '<td>&nbsp;</td>';
                   1037:         }
                   1038:         $table = '<table>'.$table.'</tr></table>';
                   1039:     }
                   1040:     return $table;
                   1041: }
                   1042: 
1.121     raeburn  1043: sub get_personnel {
1.127     raeburn  1044:     my ($r,$target,$cdom,$cnum,$allowed,$crstype,$syllabus) = @_;
                   1045:     my (%hiddenroles,%hiddenusers);
                   1046:     if (ref($syllabus) eq 'HASH') {
                   1047:         if (ref($syllabus->{'personnel'}) eq 'HASH') {
                   1048:             if ($syllabus->{'personnel'}{'hiderole'}) {
                   1049:                 map { $hiddenroles{$_} = 1; } split(/,/,$syllabus->{'personnel'}{'hiderole'});
                   1050:             }
                   1051:             if ($syllabus->{'personnel'}{'hideuser'}) {
                   1052:                 map { $hiddenusers{$_} = 1; } split(/,/,$syllabus->{'personnel'}{'hideuser'});
                   1053:             }
                   1054:         }
                   1055:     }
1.121     raeburn  1056:     my $output;
1.127     raeburn  1057:     my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum,1);
1.121     raeburn  1058:     if ($target ne 'tex') {
1.127     raeburn  1059:         if ($allowed) {
                   1060:             $r->print(&Apache::loncommon::start_data_table().
                   1061:                       &Apache::loncommon::start_data_table_header_row().
1.156   ! raeburn  1062:                       '<th>'.&mt('Role (hidden if checked)').'</th>'.
1.127     raeburn  1063:                       '<th>'.&mt('Personnel (hidden if checked)').'</th>'.
                   1064:                       &Apache::loncommon::end_data_table_header_row());
                   1065:         } else {
                   1066:             $r->print(&Apache::lonhtmlcommon::start_pick_box());
                   1067:         }
1.121     raeburn  1068:     } else {
                   1069:         $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
                   1070:     }
                   1071:     my @personnel=sort(keys(%coursepersonnel));
                   1072:     my $lastpers=$personnel[$#personnel];
                   1073:     foreach my $element (@personnel) {
1.127     raeburn  1074:         unless ($allowed) {
                   1075:             next if ($hiddenroles{$element}) 
                   1076:         }
                   1077:         my ($role,$sec);
                   1078:         if ($element =~ /:/) {
                   1079:             ($role,$sec) = split(/:/,$element);
                   1080:         } else {
                   1081:             $role = $element;
                   1082:         }
                   1083:         my $roletext = &Apache::lonnet::plaintext($role,$crstype);
                   1084:         if ($sec) {
                   1085:             $roletext .=' ('.&Apache::lonlocal::mt('Section [_1]',$sec).')';
                   1086:         }
1.121     raeburn  1087:         if ($target ne 'tex') {
1.127     raeburn  1088:             if ($allowed) {
                   1089:                 my $checked;
                   1090:                 if ($hiddenroles{$element}) {
                   1091:                     $checked = ' checked="checked"';
                   1092:                 }
                   1093:                 $r->print(&Apache::loncommon::start_data_table_row().
1.156   ! raeburn  1094:                           '<td><span class="LC_nobreak"><label>'.
1.127     raeburn  1095:                           '<input type="checkbox" name="hiderole" value="'.$element.'" '.
1.156   ! raeburn  1096:                           $checked.' />'.$roletext.'</label></span></td><td>');
1.127     raeburn  1097:             } else {
                   1098:                 $r->print(&Apache::lonhtmlcommon::row_title($roletext));
                   1099:             }
1.121     raeburn  1100:         } else {
1.127     raeburn  1101:             $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$roletext).' & ');
1.121     raeburn  1102:         }
                   1103:         my @coursepersonlist;
                   1104:         foreach my $user (split(/\,/,$coursepersonnel{$element})) {
                   1105:             my ($puname,$pudom)=split(/\:/,$user);
                   1106:             if ($target ne 'tex') {
                   1107:                 my $courseperson = &Apache::loncommon::plainname($puname,$pudom);
1.127     raeburn  1108:                 my $checked;
                   1109:                 if ($hiddenusers{$element.'&'.$puname.':'.$pudom}) {
                   1110:                     $checked = ' checked="checked"';
                   1111:                 }
                   1112:                 if ($allowed) {
                   1113:                     my $item = '<span class="LC_nobreak"><label>'.
1.129     raeburn  1114:                                '<input type="checkbox" name="hideuser" value="'.$element.'&amp;'.$puname.':'.$pudom.'"'.$checked.' />'.
1.127     raeburn  1115:                                &Apache::loncommon::aboutmewrapper($courseperson
                   1116: ,
                   1117:                                                $puname,$pudom).
                   1118:                                '</label>'.('&nbsp;'x2).'</span> ';
                   1119:                     push(@coursepersonlist,$item);
                   1120: 
1.121     raeburn  1121:                 } else {
1.127     raeburn  1122:                     next if ($hiddenusers{$element.'&'.$puname.':'.$pudom});
                   1123:                     if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
                   1124:                         ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
                   1125:                         push(@coursepersonlist,$courseperson);
                   1126:                     } else {
                   1127:                         push(@coursepersonlist,&Apache::loncommon::aboutmewrapper($courseperson,
                   1128:                                                $puname,$pudom));
                   1129:                     }
1.121     raeburn  1130:                 }
                   1131:             } else {
                   1132:                 push(@coursepersonlist,&Apache::loncommon::plainname($puname,
                   1133:                               $pudom).' ');
                   1134:             }
                   1135:         }
1.127     raeburn  1136:         if ($allowed) {
                   1137:             $r->print(join('',@coursepersonlist));
                   1138:         } else {
                   1139:             $r->print(join(', ',@coursepersonlist));
                   1140:         }
1.121     raeburn  1141:         if ($target ne 'tex') {
1.127     raeburn  1142:             if ($allowed) {
1.129     raeburn  1143:                 $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1.127     raeburn  1144:             } else {
                   1145:                 my $lastclose=$element eq $lastpers?1:0;
                   1146:                 $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
                   1147:             }
1.121     raeburn  1148:         } else {
                   1149:             $r->print('\\\\ \hline');
                   1150:         }
                   1151:     }
                   1152:     if ($target ne 'tex') {
1.127     raeburn  1153:         if ($allowed) {
                   1154:             $r->print(&Apache::loncommon::end_data_table());
                   1155:         } else {
                   1156:             $r->print(&Apache::lonhtmlcommon::end_pick_box());
                   1157:         }
1.121     raeburn  1158:     } else {
                   1159:         $r->print('\end{tabular}\\\\');
                   1160:     }
                   1161:     return;
                   1162: }
                   1163: 
                   1164: sub save_changes {
1.122     raeburn  1165:     my ($cnum,$cdom,$uploaded,$external,$minimal,$syllabus,$syllabusfields,$courseenv) = @_;
1.121     raeburn  1166:     my ($earlyout,$output);
1.131     raeburn  1167:     unless ((ref($syllabus) eq 'HASH') && (ref($syllabusfields) eq 'HASH') ||
                   1168:             (ref($courseenv) eq 'HASH')) {
1.122     raeburn  1169:         return ($earlyout,$uploaded,$external,$minimal,$output);
1.121     raeburn  1170:     }
1.142     raeburn  1171:     my ($was_ext,$is_ext,$putres);
                   1172:     if ($external) {
                   1173:         $was_ext = $external;
                   1174:     }
1.128     raeburn  1175:     if (($env{'form.deleteuploaded_file'}) || ($env{'form.deleteuploaded_minimal'})) {
1.122     raeburn  1176:         my %storehash;
                   1177:         if (($env{'form.choice'} eq 'file') && 
1.128     raeburn  1178:             ($env{'form.deleteuploaded_file'}) && ($uploaded =~ /\w/)) {
1.131     raeburn  1179:             if ($courseenv->{'uploadedsyllabus'} =~ m{^\Q/uploaded/$cdom/$cnum/portfolio\E(/syllabus/.+)$}) {
                   1180:                 my $filename = $1;
                   1181:                 &update_access_permissions($cdom,$cnum,$filename);
                   1182:             }
1.122     raeburn  1183:             &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus');
                   1184:             &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus');
                   1185:             $storehash{'uploadedsyllabus'} = '';
                   1186:             $storehash{'externalsyllabus'} = '';
1.142     raeburn  1187:             $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
1.122     raeburn  1188:             undef($uploaded);
                   1189:             undef($external);
                   1190:         } elsif (($env{'form.choice'} eq 'minimal') &&
1.128     raeburn  1191:                  ($env{'form.deleteuploaded_minimal'}) && ($minimal =~ /\w/)) {
1.131     raeburn  1192:             my $minimalurl = "/uploaded/$cdom/$cnum/portfolio/syllabus/loncapa.html";
                   1193:             if ($courseenv->{'minimalsyllabus'} eq "$minimalurl") {
                   1194:                 my $filecontents=&Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$minimalurl));
                   1195:                 unless ($filecontents eq -1) {
                   1196:                     $env{'form.output'} = $filecontents; 
                   1197:                     &Apache::lonnet::finishuserfileupload($cnum,$cdom,'output',
                   1198:                                                           'portfolio/syllabus/loncapa.html.bak');
                   1199:                     $minimalurl = &default_minimal_syllabus($cnum,$cdom);
                   1200:                 }
                   1201:             }
                   1202:             &update_access_permissions($cdom,$cnum,'/syllabus/loncapa.html');
1.122     raeburn  1203:             &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus');
                   1204:             &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.minimalsyllabus');
                   1205:             $storehash{'externalsyllabus'} = '';
                   1206:             $storehash{'minimalsyllabus'} = '';
1.142     raeburn  1207:             $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
1.122     raeburn  1208:             undef($external);
                   1209:             undef($minimal);
                   1210:         }
                   1211:     } elsif ($env{'form.choice'} eq 'template') {
1.121     raeburn  1212: #store what the user typed in to the template
                   1213:         my @shown = &Apache::loncommon::get_env_multiple('form.showfield');
                   1214:         $syllabus->{'uploaded.fields'} = '';
                   1215:         if (@shown == 0) {
                   1216:             $syllabus->{'uploaded.fields'} = 'none';
                   1217:         } else {
                   1218:             foreach my $field (sort(@shown)) {
                   1219:                 if (($field eq '000_showpeople') ||
                   1220:                     ($field eq '111_showrssfeeds') ||
                   1221:                     ($syllabusfields->{$field})) {
                   1222:                     my ($prefix) = split(/_/,$field);
                   1223:                     $syllabus->{'uploaded.fields'} .= $prefix.',';
                   1224:                 }
1.127     raeburn  1225:                 if ($field eq '000_showpeople') {
                   1226:                     my @hideusers = &Apache::loncommon::get_env_multiple('form.hideuser');
                   1227:                     my @hideroles = &Apache::loncommon::get_env_multiple('form.hiderole');
                   1228:                     my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum,1);
                   1229:                     my %personnel;
                   1230:                     foreach my $key (keys(%coursepersonnel)) {
                   1231:                         map { $personnel{$key}{$_} = 1; } split(/,/,$coursepersonnel{$key});
                   1232:                     }
                   1233:                     %{$syllabus->{'personnel'}} = ();
                   1234:                     $syllabus->{'personnel'}{'hideuser'} = '';
                   1235:                     $syllabus->{'personnel'}{'hiderole'} = '';
                   1236:                     foreach my $role (@hideroles) {
                   1237:                         if (exists($personnel{$role})) {
                   1238:                             $syllabus->{'personnel'}{'hiderole'} .= $role.',';
                   1239:                         }
                   1240:                     }
                   1241:                     foreach my $item (@hideusers) {
                   1242:                         my ($role,$user) = split(/\&/,$item);
                   1243:                         if (ref($personnel{$role}) eq 'HASH') {
                   1244:                             if ($personnel{$role}{$user}) {
                   1245:                                 $syllabus->{'personnel'}{'hideuser'} .= $item.',';
                   1246:                             }
                   1247:                         }
                   1248:                     }
                   1249:                     $syllabus->{'personnel'}{'hideuser'} =~ s/,$//;
                   1250:                     $syllabus->{'personnel'}{'hiderole'} =~ s/,$//;
                   1251:                 }
1.121     raeburn  1252:             }
                   1253:             $syllabus->{'uploaded.fields'} =~ s/,$//;
                   1254:         }
                   1255:         foreach my $syl_field (keys(%{$syllabusfields})) {
                   1256:             my $field=$env{'form.'.$syl_field};
                   1257:             chomp($field);
1.133     raeburn  1258:             my $gateway = Apache::lonhtmlgateway->new();
                   1259:             $field = $gateway->process_incoming_html($field,1);
1.121     raeburn  1260:                             #here it will be stored
                   1261:             $syllabus->{$syl_field}=$field;
                   1262:             if ($syl_field eq 'lll_includeurl') { # clean up included URLs
                   1263:                 my $field='';
                   1264:                 foreach my $value (split(/\n/,$syllabus->{$syl_field})) {
                   1265:                     my $url=$value;
                   1266: # get rid of leading and trailing spaces
                   1267:                     $url=~s/^\s+//;
                   1268:                     $url=~s/\s+$//;
                   1269:                     if ($url=~m|^https?\://([^/]+)/(.+)$|) {
                   1270:                         my $host = $1;
                   1271:                         my $remainder=$2;
                   1272: # remove the hostname from internal URLs
                   1273:                         my $hostname = &Apache::lonnet::hostname($host);
                   1274:                         my %all_hostnames = &Apache::lonnet::all_hostnames();
                   1275:                         foreach my $possible_host (keys(%all_hostnames)) {
                   1276:                             if ($possible_host =~ /\Q$hostname\E/i) {
                   1277:                                 $url=$remainder;
                   1278:                             }
                   1279:                         }
                   1280:                     }
                   1281: # norm internal URLs
                   1282:                     unless ($url=~/^https?\:/) {
                   1283:                         $url=&Apache::lonnet::clutter($url);
                   1284:                     }
                   1285: # re-assemble field
                   1286:                     if ($url) {
                   1287:                         $field.=$url."\n";
                   1288:                     }
                   1289:                 }
                   1290:                 $syllabus->{$syl_field}=$field;
                   1291:             }
                   1292:         }
                   1293:         my $now = time;
                   1294:         $syllabus->{'uploaded.domain'}=$env{'user.domain'};
                   1295:         $syllabus->{'uploaded.name'}=$env{'user.name'};
                   1296:         $syllabus->{'uploaded.lastmodified'} = $now;
1.142     raeburn  1297:         $putres = &Apache::lonnet::put('syllabus',$syllabus,$cdom,$cnum);
1.121     raeburn  1298:         if ($putres eq 'ok') {
1.123     raeburn  1299:             ($uploaded,$minimal,$external) = 
                   1300:                 &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
                   1301:                                      $minimal,$external);
1.121     raeburn  1302:             $output = '<div>'.
                   1303:                       &Apache::lonhtmlcommon::confirm_success(&mt('Template saved.')).
                   1304:                       '</div>';
                   1305:         } else {
                   1306:             $output = '<div class="LC_error">'.
                   1307:                       &mt('An error occurred storing the template: [_1]',$putres).
                   1308:                       '</div>';
                   1309:         }
                   1310:     } elsif ($env{'form.choice'} eq 'url') {
                   1311:         if ($env{'form.externalsyllabus'} =~ m{^https?://}) {
                   1312:             if ($env{'form.externalsyllabus'} eq $external) {
                   1313:                 $output = '<div class="LC_info">'.
                   1314:                           &mt('External URL unchanged.').
                   1315:                           '</div>';
1.123     raeburn  1316:                 ($uploaded,$minimal,$external) =
                   1317:                     &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
                   1318:                                          $minimal,$external);
1.121     raeburn  1319:             } else {
                   1320:                 $external=$env{'form.externalsyllabus'};
                   1321:                 $external =~ s/(`)//g;
1.142     raeburn  1322:                 $putres =
1.121     raeburn  1323:                     &Apache::lonnet::put('environment',{externalsyllabus=>$external},
                   1324:                                          $cdom,$cnum);
                   1325:                 if ($putres eq 'ok') {
                   1326:                     &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.externalsyllabus' => $external});
                   1327:                     $output = '<div>'.
                   1328:                               &Apache::lonhtmlcommon::confirm_success(&mt('External URL saved.')).
                   1329:                              '</div>';
1.123     raeburn  1330:                     ($uploaded,$minimal,$external) =
                   1331:                         &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
                   1332:                                              $minimal,$external);
1.121     raeburn  1333:                 } else {
                   1334:                     $output = '<div class="LC_error">'.
                   1335:                               &mt('An error occurred storing the external URL: [_1]',$putres).
                   1336:                               '</div>';
                   1337:                 }
                   1338:             }
1.142     raeburn  1339:             $is_ext = $external;
1.121     raeburn  1340:         } else {
                   1341:             $output = '<div class="LC_error">'.
                   1342:                       &mt('External URL not saved -- invalid URL.').
                   1343:                       '</div>';
                   1344:         }
1.122     raeburn  1345:     } elsif (($env{'form.choice'} eq 'file') || ($env{'form.choice'} eq 'minimal')) {
1.121     raeburn  1346:         # Process file upload - phase one - upload and parse primary file.
1.122     raeburn  1347:         my ($upload_result,$uploadphase,$url,$needlink,$error,$errormsg);
                   1348:         if ($env{'form.choice'} eq 'file') {
                   1349:             if ($env{'form.syllabusfile.filename'}) {
                   1350:                 my %allfiles = ();
                   1351:                 my %codebase = ();
                   1352:                 ($url,$needlink) = &process_upload(\$output,$cnum,$cdom,
                   1353:                                                    \%allfiles,\%codebase);
                   1354:             } else {
1.134     raeburn  1355:                 $output = '<div class="LC_info">'.
1.122     raeburn  1356:                           &mt('No file uploaded').
                   1357:                           '</div>';
                   1358:             }
                   1359:         } elsif ($env{'form.choice'} eq 'minimal') {
1.131     raeburn  1360:             $url = "/uploaded/$cdom/$cnum/portfolio/syllabus/loncapa.html";
                   1361:             my $filecontents=&Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$url));
                   1362:             if ($filecontents eq -1) {
                   1363:                 $url = &default_minimal_syllabus($cnum,$cdom);
1.122     raeburn  1364:             }
                   1365:         }
                   1366:         if ($url =~ m{^/uploaded/\Q$cdom\E/\Q$cnum\E.*/[^/]+$}) {
1.123     raeburn  1367:             my $exturl = &home_http_host($cdom,$cnum);
                   1368:             if ($exturl) {
                   1369:                 $exturl .= $url;
1.122     raeburn  1370:             }
                   1371:             my %storehash;
                   1372:             if ($env{'form.choice'} eq 'minimal') {
                   1373:                 $storehash{'minimalsyllabus'} = $url;
                   1374:             } else {
                   1375:                 $storehash{'uploadedsyllabus'} = $url;
                   1376:             }
                   1377:             if ($exturl) {
                   1378:                 $storehash{'externalsyllabus'} = $exturl;
                   1379:                 if ($exturl =~ /\.(html?|txt|js|css)$/) {
                   1380:                     $exturl .= '?inhibitmenu=yes';
                   1381:                 }
                   1382:             } else {
                   1383:                 $storehash{'externalsyllabus'} = '',
                   1384:             }
1.142     raeburn  1385:             $putres =
1.122     raeburn  1386:                 &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
                   1387:             if ($putres eq 'ok') {
                   1388:                 &Apache::lonnet::make_public_indefinitely($url);
                   1389:                 foreach my $key (keys(%storehash)) {
                   1390:                     &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash{$key}});
                   1391:                 }
                   1392:                 if ($env{'form.choice'} eq 'minimal') {
                   1393:                     $minimal = $url;
1.121     raeburn  1394:                 } else {
1.122     raeburn  1395:                     $uploaded = $url;
1.121     raeburn  1396:                 }
1.122     raeburn  1397:                 if ($needlink) {
                   1398:                     $output .= &return_to_editor($cdom,$cnum);
                   1399:                     $earlyout = 1;
1.121     raeburn  1400:                 }
1.123     raeburn  1401:                 ($uploaded,$minimal,$external) =
                   1402:                     &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
                   1403:                                          $minimal,$external);
1.122     raeburn  1404:             } else {
                   1405:                 $error = 1;
                   1406:                 $errormsg = $putres;
                   1407:             }
                   1408:         } else {
                   1409:             $error = 1;
                   1410:         }
                   1411:         if ($error) {
                   1412:             $output = '<div class="LC_error">';
                   1413:             if ($env{'form.choice'} eq 'minimal') {
                   1414:                 $output = &mt('An error occurred creating the minimal template file [_1]',$errormsg);
                   1415:             } else {
                   1416:                 $output = &mt('An error occurred storing the uploaded file [_1]',$errormsg);
1.121     raeburn  1417:             }
1.122     raeburn  1418:             $output .= '</div>';
1.121     raeburn  1419:         }
                   1420:     } elsif ($env{'form.phase'} eq 'upload_embedded') {
                   1421:         # Process file upload - phase two - upload embedded objects
                   1422:         my $uploadphase = 'check_embedded';
                   1423:         my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
                   1424:         my $state = &embedded_form_elems($uploadphase,$primaryurl);
                   1425:         my $url_root = '/uploaded/'.$cdom.'/'.$cnum;
                   1426:         my $actionurl = "/public/$cdom/$cnum/syllabus";
                   1427:         my ($result,$flag,$numpathchgs) =
                   1428:             &Apache::loncommon::upload_embedded('syllabus','portfolio/syllabus',
                   1429:                 $cnum,$cdom,'/userfiles',$url_root,undef,undef,undef,$state,
                   1430:                 $actionurl);
                   1431:         unless ($numpathchgs) {
                   1432:             my $modres =
                   1433:                 &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
                   1434:                                                      $cnum,$cdom,
                   1435:                                                      '/userfiles',$env{'form.primaryurl'});
                   1436:             $result .= $modres;
                   1437:         }
1.122     raeburn  1438:         $output = $result.&return_to_editor($cdom,$cnum);
1.121     raeburn  1439:         $earlyout = 1;
                   1440:     } elsif ($env{'form.phase'} eq 'check_embedded') {
                   1441:         # Process file upload - phase three - modify references in HTML file
                   1442:         my $uploadphase = 'modified_orightml';
                   1443:         my $result =
                   1444:             &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
                   1445:                                                  $cnum,$cdom,
                   1446:                                                  '/userfiles',$env{'form.primaryurl'});
1.122     raeburn  1447:         $output = $result.&return_to_editor($cdom,$cnum);
1.121     raeburn  1448:         $earlyout = 1;
                   1449:     }
1.142     raeburn  1450:     if ($putres eq 'ok') {
                   1451:         if ((($is_ext) && ($is_ext ne $was_ext)) || ($was_ext)) {
                   1452:             my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
                   1453:             unless ($chome eq 'no_host') {
                   1454:                 my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
                   1455:                 if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
                   1456:                     if ($external =~ m{^http://}) {
                   1457:                         $crsinfo{$cdom.'_'.$cnum}{'extsyllplain'} = 1;
                   1458:                     } elsif ($crsinfo{$cdom.'_'.$cnum}{'extsyllplain'}) {
                   1459:                         delete($crsinfo{$cdom.'_'.$cnum}{'extsyllplain'});
                   1460:                     }
                   1461:                     &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
                   1462:                 }
                   1463:             }
                   1464:         }
                   1465:     }
1.122     raeburn  1466:     return ($earlyout,$uploaded,$external,$minimal,$output);
1.121     raeburn  1467: }
                   1468: 
1.131     raeburn  1469: sub default_minimal_syllabus {
                   1470:     my ($cnum,$cdom) = @_;
                   1471:     my $title;
                   1472:     if ($env{'form.syllabustitle'}) {
                   1473:         $title = $env{'form.syllabustitle'};
                   1474:         $title =~ s{`}{}g;
                   1475:         $title=~s/^\s+//;
                   1476:         $title=~s/\s+$//;
                   1477:     }
                   1478:     if ($title eq '') {
                   1479:         $title = &mt('Syllabus');
                   1480:     }
                   1481:     my $initialtext = &mt('Replace with your own content.');
                   1482:     my $newhtml = <<END;
                   1483: <html>
                   1484: <head>
                   1485: <title>$title</title>
                   1486: </head>
                   1487: <body bgcolor="#ffffff">
                   1488: <h2>$title</h2>
                   1489: $initialtext
                   1490: </body>
                   1491: </html>
                   1492: END
                   1493:     $env{'form.output'}=$newhtml;
                   1494:     return &Apache::lonnet::finishuserfileupload($cnum,$cdom,'output',
                   1495:                                                  'portfolio/syllabus/loncapa.html');
                   1496: }
                   1497: 
1.123     raeburn  1498: sub update_syllabus_env {
1.124     raeburn  1499:     my ($cdom,$cnum,$courseenv,$saved,$uploaded,$minimal,$external) = @_;
1.125     raeburn  1500:     return ($uploaded,$minimal,$external) unless(ref($courseenv) eq 'HASH');
1.123     raeburn  1501:     my $now = time;
                   1502:     my (@envkeys,%storehash);
                   1503:     if ($saved eq 'template') {
1.131     raeburn  1504:         if ($uploaded || $env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) {
1.123     raeburn  1505:             push(@envkeys,'uploaded');
                   1506:         }
1.131     raeburn  1507:         if ($minimal || $env{'course.'.$env{'request.course.id'}.'.minimalsyllabus'}) {
1.123     raeburn  1508:             push(@envkeys,'minimal');
                   1509:         }
1.131     raeburn  1510:         if ($external || $env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) {
1.123     raeburn  1511:             push(@envkeys,'external');
                   1512:         }
                   1513:         $storehash{'updatedsyllabus'} = $now;
                   1514:         &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.updatedsyllabus' => $now
                   1515: });
                   1516:     } elsif ($saved eq 'url') {
                   1517:         my $prefix = &home_http_host($cdom,$cnum);
                   1518:         if ($external =~ m{^\Q$prefix/uploaded/$cdom/$cnum/portfolio/syllabus/\E(.+)$}) {
                   1519:             my $file = $1;
                   1520:             if ($file eq 'loncapa.html') {
1.131     raeburn  1521:                 if ($uploaded || $env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) {
1.123     raeburn  1522:                     push(@envkeys,'uploaded');
                   1523:                 }
1.131     raeburn  1524:             } elsif ($minimal || $env{'course.'.$env{'request.course.id'}.'.minimalsyllabus'}) {
1.123     raeburn  1525:                 push(@envkeys,'minimal');
                   1526:             }
                   1527:         } else {
1.131     raeburn  1528:             if ($uploaded || $env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) {
1.123     raeburn  1529:                 push(@envkeys,'uploaded');
                   1530:             }
1.131     raeburn  1531:             if ($minimal || $env{'course.'.$env{'request.course.id'}.'.minimalsyllabus'}) {
1.123     raeburn  1532:                 push(@envkeys,'minimal');
                   1533:             }
                   1534:         }
                   1535:     } elsif ($saved eq 'file') {
1.131     raeburn  1536:         if ($minimal || $env{'course.'.$env{'request.course.id'}.'.minimalsyllabus'}) {
1.123     raeburn  1537:             push(@envkeys,'minimal');
                   1538:         }
                   1539:     } elsif ($saved eq 'minimal') {
1.131     raeburn  1540:         if ($uploaded || $env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) {
1.123     raeburn  1541:             push(@envkeys,'uploaded');
                   1542:         }
                   1543:     }
                   1544:     if (@envkeys > 0) {
                   1545:         foreach my $item (@envkeys) {
                   1546:             my $key = $item.'syllabus';
1.130     raeburn  1547:             if ($courseenv->{$key} ne '') {
1.123     raeburn  1548:                 &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
1.131     raeburn  1549:                 if ($item eq 'minimal') {
                   1550:                     &update_access_permissions($cdom,$cnum,'/syllabus/loncapa.html');
                   1551:                 } elsif ($item eq 'uploaded') {
                   1552:                     if ($courseenv->{$key} =~ m{^\Q/uploaded/$cdom/$cnum/portfolio\E(/syllabus/.+)$}) {
                   1553:                         my $filename = $1;
                   1554:                         &update_access_permissions($cdom,$cnum,$filename);
                   1555:                     }
                   1556:                 }
1.123     raeburn  1557:                 $storehash{$key} = '';
1.131     raeburn  1558:             } elsif ($env{'course.'.$env{'request.course.id'}.'.'.$key} ne '') {
                   1559:                 &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
1.123     raeburn  1560:             }
                   1561:             if ($item eq 'uploaded') {
                   1562:                 undef($uploaded);
                   1563:             }
                   1564:             if ($item eq 'external') {
                   1565:                 undef($external);
                   1566:             }
                   1567:             if ($item eq 'minimal') {
                   1568:                 undef($minimal);
                   1569:             }
                   1570:         }
                   1571:     }
                   1572:     if (keys(%storehash) > 0) {
                   1573:         &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
                   1574:     }
                   1575:     return ($uploaded,$minimal,$external);
                   1576: }
                   1577: 
1.131     raeburn  1578: sub update_access_permissions {
                   1579:     my ($cdom,$cnum,$file_name) = @_;
                   1580:     my $current_permissions = &Apache::lonnet::get_portfile_permissions($cdom,$cnum);
                   1581:     my %access_controls =
                   1582:         &Apache::lonnet::get_access_controls($current_permissions,'',$file_name);
                   1583:     if (keys(%access_controls) > 0) {
                   1584:         my %changes;
                   1585:         foreach my $key (keys(%{$access_controls{$file_name}})) {
                   1586:             $changes{'delete'}{$key} = 1;
                   1587:         }
                   1588:         if (keys(%changes) > 0) {
                   1589:             my ($outcome,$deloutcome,$new_values,$translation) =
                   1590:                 &Apache::lonnet::modify_access_controls($file_name,\%changes,
                   1591:                                                         $cdom,$cnum);
                   1592:         }
                   1593:     }
                   1594:     return; 
                   1595: }
                   1596: 
1.123     raeburn  1597: sub home_http_host {
                   1598:     my ($cdom,$cnum) = @_;
                   1599:     my $home=&Apache::lonnet::homeserver($cnum,$cdom);
                   1600:     if ($home ne 'no_host') {
1.144     raeburn  1601:         my $hostname = &Apache::lonnet::hostname($home);
1.123     raeburn  1602:         my $protocol = $Apache::lonnet::protocol{$home};
                   1603:         $protocol = 'http' if ($protocol ne 'https');
1.144     raeburn  1604:         return $protocol.'://'.$hostname;
1.123     raeburn  1605:     }
                   1606:     return;
                   1607: }
                   1608: 
1.117     raeburn  1609: sub process_upload {
                   1610:     my ($upload_output,$cnum,$cdom,$allfiles,$codebase) = @_;
                   1611:     my ($parseaction,$showupload,$mimetype);
                   1612:     my $dest = 'portfolio/syllabus';
                   1613:     if ($env{'form.parserflag'}) {
                   1614:         $parseaction = 'parse';
                   1615:     }
                   1616:     my $url=&Apache::lonnet::userfileupload('syllabusfile','syllabus',$dest,
                   1617:                                             $parseaction,$allfiles,
                   1618:                                             $codebase,undef,undef,undef,undef,
                   1619:                                             undef,undef,\$mimetype);
                   1620:     if ($url =~ m{^/uploaded/\Q$cdom\E/\Q$cnum\E.*/([^/]+)$}) {
                   1621:         my $stored = $1;
                   1622:         $showupload = '<p>'.&mt('Uploaded [_1]',
                   1623:                                 '<span class="LC_filename">'.$stored.'</span>').
                   1624:                       '</p>';
                   1625:     } else {
                   1626:         my ($filename) = ($env{'form.syllabusfile.filename'} =~ m{([^/]+)$});
                   1627:         $$upload_output = '<div class="LC_error" id="uploadfileresult">'.
                   1628:                           &mt('Unable to save file [_1].',
                   1629:                               '<span class="LC_filename">'.$filename.'</span>').
                   1630:                           '</div>';
                   1631:         return (); 
                   1632:     }
                   1633:     my $needlink;
                   1634:     if (($parseaction eq 'parse') && ($mimetype eq 'text/html')) {
                   1635:         $$upload_output = $showupload;
                   1636:         my $total_embedded = scalar(keys(%{$allfiles}));
                   1637:         if ($total_embedded > 0) {
                   1638:             my $uploadphase = 'upload_embedded';
                   1639:             my $primaryurl = &HTML::Entities::encode($url,'<>&"');
                   1640:             my $state = &embedded_form_elems($uploadphase,$primaryurl);
                   1641:             my $actionurl = "/public/$cdom/$cnum/syllabus";
                   1642:             my ($embedded,$num,$numpathchanges,$existing);
                   1643:             ($embedded,$num,$numpathchanges,$existing) =
                   1644:                 &Apache::loncommon::ask_for_embedded_content($actionurl,$state,
                   1645:                                                              $allfiles,$codebase,
                   1646:                                                             {'error_on_invalid_names'   => 1,
                   1647:                                                              'ignore_remote_references' => 1,});
                   1648:             if ($embedded) {
                   1649:                 $needlink = 1;
                   1650:                 if ($num) {
                   1651:                     $$upload_output .=
                   1652:                         '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
                   1653:                 } elsif ($numpathchanges) {
                   1654:                     $$upload_output .= $embedded;
                   1655:                 } else {
                   1656:                     $$upload_output .= $embedded;
                   1657:                     &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
                   1658:                                                          $cnum,$cdom,'/userfiles',$url);
                   1659:                 }
                   1660:             } else {
                   1661:                 $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
                   1662:                 &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
                   1663:                                                      $cnum,$cdom,'/userfiles',$url);
                   1664: 
                   1665:             }
                   1666:         } else {
                   1667:             $$upload_output .= &mt('No embedded items identified').'<br />';
                   1668:         }
                   1669:         $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
                   1670:     }
                   1671:     return ($url,$needlink);
                   1672: }
                   1673: 
                   1674: sub embedded_form_elems {
                   1675:     my ($phase,$primaryurl) = @_;
                   1676:     return <<STATE;
                   1677:     <input type="hidden" name="forceedit" value="1" />
                   1678:     <input type="hidden" name="cmd" value="upload_embedded" />
                   1679:     <input type="hidden" name="phase" value="$phase" />
                   1680:     <input type="hidden" name="primaryurl" value="$primaryurl" />
                   1681: STATE
                   1682: }
                   1683: 
                   1684: sub return_to_editor {
                   1685:     my ($cdom,$cnum) = @_;
                   1686:     my $actionurl = "/public/$cdom/$cnum/syllabus";
                   1687:     return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'.
                   1688:            '<input type="hidden" name="forceedit" value="1" />'."\n".
                   1689:            '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
                   1690:            '</a></p>';
                   1691: }
                   1692: 
1.118     raeburn  1693: sub editfile_button {
1.125     raeburn  1694:     my ($url,$context,$editable) = @_;
1.122     raeburn  1695:     my $edittext=&mt('Edit');
                   1696:     my $deltext=&mt('Delete');
1.125     raeburn  1697:     my $output;
                   1698:     if ($editable) {
                   1699:         $output = '
                   1700:                 <input type="button" value="'.$edittext.'" onclick="javascript:gotoeditor('."'$url'".');" name="edit_'.$context.'" />
                   1701:                 &nbsp;&nbsp;&nbsp;';
                   1702:     }
                   1703:     $output .= '
                   1704:                 <input type="button" value="'.$deltext.'" onclick="javascript:dodelete('."'$context'".');" name="del_'.$context.'" />
1.128     raeburn  1705:                 <input type="hidden" value="" name="deleteuploaded_'.$context.'" id="deleteuploaded_'.$context.'" />
1.125     raeburn  1706:     ';
                   1707:     return $output;
1.118     raeburn  1708: }
                   1709: 
                   1710: sub editbutton_js {
1.138     damieng  1711:     my %js_lt = &Apache::lonlocal::texthash(
1.126     raeburn  1712:                min    => 'Are you sure you want to delete the contents of the syllabus template?',
                   1713:                file   => 'Are you sure you want to delete the uploaded syllabus file?',
                   1714:                noundo => 'This action cannot be reversed.'
                   1715:              );
1.138     damieng  1716:     &js_escape(\%js_lt);
1.118     raeburn  1717:     return <<ENDJS;
                   1718:                 <script type="text/javascript">
                   1719:                 // <![CDATA[
1.122     raeburn  1720:                   function gotoeditor(url) {
                   1721:                       document.location.href = url+'?editmode=1&forceedit=1';
                   1722:                   }
                   1723:                   function dodelete(caller,url) {
1.128     raeburn  1724:                       if (document.getElementById('deleteuploaded_'+caller)) {
                   1725:                           document.getElementById('deleteuploaded_'+caller).value=1;
                   1726:                           if (caller == 'minimal') {
1.138     damieng  1727:                               if (confirm("$js_lt{'min'}"+"\\n"+"$js_lt{'noundo'}")) {
1.128     raeburn  1728:                                   document.syllabus.submit();
                   1729:                               }
1.126     raeburn  1730:                           }
1.128     raeburn  1731:                           if (caller == 'file') {
1.138     damieng  1732:                               if (confirm("$js_lt{'file'}"+"\\n"+"$js_lt{'noundo'}")) {
1.128     raeburn  1733:                                   document.syllabus.submit();
                   1734:                               }
1.126     raeburn  1735:                           }
                   1736:                       }
                   1737:                       return;   
1.118     raeburn  1738:                   }
                   1739:                 // ]]>
                   1740:                 </script>
                   1741: ENDJS
                   1742: }
                   1743: 
1.148     raeburn  1744: sub redirect_to_http {
                   1745:     my ($r) = @_;
                   1746:     &Apache::loncommon::content_type($r,'text/html');
                   1747:     &Apache::loncommon::no_cache($r);
                   1748:     $r->send_http_header;
                   1749:     my $url = 'http://'.$r->hostname().$r->uri().'?usehttp=1';
                   1750:     $r->print(&Apache::loncommon::start_page(undef,undef,
                   1751:                                              {'redirect' => [0,$url],}).
                   1752:               &Apache::loncommon::end_page());
                   1753:     return;
                   1754: }
                   1755: 
1.1       www      1756: 1;
                   1757: __END__

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