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

1.1       www         1: # The LearningOnline Network
                      2: # Syllabus
                      3: #
1.120   ! raeburn     4: # $Id: lonsyllabus.pm,v 1.119 2013/05/05 02:21:20 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.19      www        38: use Apache::lonannounce;
1.23      www        39: use Apache::lonlocal;
1.32      www        40: use Apache::lonhtmlcommon;
1.38      www        41: use Apache::lonspeller();
1.54      albertel   42: use HTML::Entities();
1.1       www        43: 
                     44: sub handler {
                     45:     my $r = shift;
1.46      www        46:     &Apache::loncommon::content_type($r,'text/html');
                     47:     $r->send_http_header;
                     48:     return OK if $r->header_only;
1.45      www        49: 
1.46      www        50:     my $target=$env{'form.grade_target'};
1.45      www        51: # --------------------------------------------------- Get course info from URL
                     52:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.46      www        53: # ------------------------------------------------------------ Get query string
                     54:     &Apache::loncommon::get_unprocessed_cgi
1.116     raeburn    55:                         ($ENV{'QUERY_STRING'},['register','forceedit','todocs',
1.115     raeburn    56:                                                'folderpath','title']);
1.45      www        57: # ----------------------------------------------------- Is this even a course?
                     58:     my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom);
                     59:     if ($homeserver eq 'no_host') {
                     60:         &Apache::loncommon::content_type($r,'text/html');
                     61:         $r->send_http_header;
1.106     faziophi   62:         &Apache::loncommon::simple_error_page($r,'No syllabus available',
1.91      amueller   63:                           'No syllabus available');
1.45      www        64:         return OK;
1.113     raeburn    65:     } elsif (!&Apache::lonnet::is_course($cdom,$cnum)) {
                     66:         &Apache::loncommon::content_type($r,'text/html');
                     67:         $r->send_http_header;
                     68:         &Apache::loncommon::simple_error_page($r,'No syllabus available',
                     69:                           'The course/community for which the syllabus was requested does not exist.');
                     70:         return OK;
1.45      www        71:     }
                     72: # ------------------------------------- There is such a course, get environment
                     73:     my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.46      www        74: 
1.1       www        75: # ------------------------------------------------------------ Print the screen
1.49      albertel   76: 
                     77:     if ($target eq 'tex') {
1.91      amueller   78:         $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.86      bisitz     79:     }
1.117     raeburn    80: 
                     81: # --------------------------------------------------------------- Force Student
                     82:     my ($forceedit,$forcestudent);
                     83:     if ($env{'form.forceedit'}) { $forceedit=1; }
                     84:     if (!$forceedit) {
                     85:         $forcestudent=1;
                     86:     }
                     87: 
                     88: # --------------------------------------------------------------- Check Privileges
                     89:     my $allowed = 0;
                     90:     if ($env{'user.environment'}) {
                     91: # does this user have privileges to post, etc?
                     92:         if ($env{'request.course.id'}
                     93:         && $cdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}
                     94:         && $cnum eq $env{'course.'.$env{'request.course.id'}.'.num'}) {
                     95:             $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
                     96:             if ($forcestudent or $target eq 'tex') { $allowed=0; }
                     97:         }
                     98:     }
                     99: 
1.46      www       100: # -------------------------------------------------- Let's see who handles this
1.117     raeburn   101:     my $external=$courseenv{'externalsyllabus'};
                    102:     my $uploaded=$courseenv{'uploadedsyllabus'};
1.49      albertel  103: 
1.117     raeburn   104:     if ($uploaded =~/\w/) {
                    105:         if ($external =~ m{\Q$uploaded\E$}) {
                    106:             undef($external);
                    107:         }
                    108:         unless ($allowed && $forceedit) {
                    109:             my $file=&Apache::lonnet::filelocation("",$uploaded);
                    110:             if ($file =~ /\.(sty|css|js|txt|tex|html?)$/) {  
                    111:                 my $filetype;
                    112:                 if ($file =~ /\.(sty|css|js|txt|tex)$/) {
                    113:                     $filetype=$1;
                    114:                 } else {
                    115:                     $filetype='html';
                    116:                 }
                    117:                 my $result = '';
                    118:                 my $filecontents=&Apache::lonnet::getfile($file);
                    119:                 if ($filecontents eq -1) {
                    120:                     $r->print(&mt('Syllabus file unavailable'));
                    121:                 } elsif ($filetype eq 'html') {
                    122:                     my %mystyle;
                    123:                     &Apache::structuretags::reset_problem_globals();
                    124:                     my $oldfile = $env{'request.filename'};
                    125:                     $env{'request.filename'} = $uploaded;
                    126:                     $result = &Apache::lonxml::xmlparse($r,'web',$filecontents,
                    127:                                                         '',%mystyle);
                    128:                     &Apache::structuretags::reset_problem_globals();
                    129:                     &Apache::lonhomework::finished_parsing();
                    130:                     $env{'request.filename'} = $oldfile;
                    131:                     &Apache::lonxml::add_messages(\$result);
                    132:                     $r->print($result);
                    133:                 }
                    134:             } else {
                    135:                 $r->print(&Apache::lonwrapper::wrapper($uploaded));
                    136:             }
                    137:             return OK;
                    138:         }
                    139:     } elsif ($external=~/\w/) {
                    140:         unless ($allowed && $forceedit) {
                    141:             $r->print(&Apache::lonwrapper::wrapper($external));
                    142:             return OK;
                    143:         }
1.90      amueller  144:     }
1.42      www       145: 
1.120   ! raeburn   146:     my $crstype = &Apache::loncommon::course_type();
        !           147: 
1.46      www       148: # ------------------------------ The buck stops here: internal syllabus display
1.5       www       149: # --------------------------------------------------------- The syllabus fields
1.23      www       150:     my %syllabusfields=&Apache::lonlocal::texthash(
1.5       www       151:        'aaa_instructorinfo' => 'Instructor Information',
                    152:        'bbb_description'    => 'Course Description',
                    153:        'ccc_prereq'         => 'Prerequisites',
1.7       www       154:        'cdc_classhours'     => 'Class Hours',
1.5       www       155:        'ddd_officehours'    => 'Office Hours',
                    156:        'eee_helproom'       => 'Helproom Hours',
1.7       www       157:        'efe_projectinfo'    => 'Project Information',
1.5       www       158:        'fff_examinfo'       => 'Exam Information',
1.7       www       159:        'fgf_deadlines'      => 'Deadlines',
1.5       www       160:        'ggg_grading'        => 'Grading Information',
1.7       www       161:        'hhh_readings'       => 'Readings',
                    162:        'iii_coursepack'     => 'Coursepack',
                    163:        'jjj_weblinks'       => 'Web Links',
1.9       www       164:        'kkk_textbook'       => 'Textbook',
                    165:        'lll_includeurl'     => 'URLs To Include in Syllabus');
1.86      bisitz    166: # ----------------------------------------------------------------- Make header
1.28      sakharuk  167:     if ($target ne 'tex') {
1.91      amueller  168:         my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
1.65      raeburn   169:         my $js;
                    170:         if ($env{'form.backto'} eq 'coursecatalog') {
                    171:             $js .= <<"ENDSCRIPT";
                    172: 
                    173: <script type="text/javascript">
1.117     raeburn   174: // <![CDATA[
                    175: 
1.65      raeburn   176: function ToCatalog(caller) {
                    177:     numidx = getIndexByName('coursenum');
1.90      amueller  178:         if (numidx > -1) {
                    179:             if (caller != 'details') {
                    180:                 document.backtocat.elements[numidx].value = '';
                    181:             }
1.65      raeburn   182:         }
                    183:     document.backtocat.submit();
                    184: }
                    185: 
                    186: function getIndexByName(item) {
                    187:     for (var i=0;i<document.backtocat.elements.length;i++) {
                    188:         if (document.backtocat.elements[i].name == item) {
                    189:             return i;
                    190:         }
                    191:     }
                    192:     return -1;
                    193: }
                    194: 
1.117     raeburn   195: // ]]>
                    196: </script>
                    197: 
                    198: ENDSCRIPT
                    199:         }
                    200:         if ($allowed && $forceedit) {
                    201:             my $check_uncheck = &Apache::loncommon::check_uncheck_jscript();
                    202:             my $invurl = &mt('Invalid URL');
                    203:             my $urlregexp = <<'ENDREGEXP';
                    204: /^([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
                    205: ENDREGEXP
                    206: 
                    207:             $js .= <<"ENDSCRIPT";
                    208: 
                    209: <script type="text/javascript">
                    210: // <![CDATA[
                    211: 
                    212: function toggleEditor(pick) {
                    213:     var choices = new Array('template','url','file','templatebox');
                    214:     for (var i=0; i<choices.length; i++) {
                    215:         if (((choices[i] == 'templatebox') && (pick == 'template')) ||
                    216:             (choices[i] == pick)) {
                    217:             document.getElementById(choices[i]).style.display='block';
                    218:         } else { 
                    219:             document.getElementById(choices[i]).style.display='none';
                    220:         }
                    221:     }
                    222:     return;
                    223: }
                    224: 
                    225: var regexp = $urlregexp;
                    226: 
                    227: function extUrlPreview(caller) {
                    228:     if (document.getElementById(caller)) {
                    229:         var url = document.getElementById(caller).value;
                    230:         if (regexp.test(url)) {
                    231:             openMyModal(url,500,400,'yes');
                    232:         } else {
                    233:             alert("$invurl");
                    234:         }
                    235:     }
                    236: }
                    237: 
                    238: function toggleBox(name,caller) {
                    239:     if (name == 'all') {
                    240:         if (document.syllabus.showfield.length > 0) {
                    241:             for (var i=0; i<document.syllabus.showfield.length; i++) {
                    242:                 if (document.syllabus.showfield[i].checked) {
                    243:                     if (document.getElementById('box_'+document.syllabus.showfield[i].value)) {
                    244:                         document.getElementById('box_'+document.syllabus.showfield[i].value).style.display='block';
                    245:                     }   
                    246:                 } else {
                    247:                     if (document.getElementById('box_'+document.syllabus.showfield[i].value)) {
                    248:                         document.getElementById('box_'+document.syllabus.showfield[i].value).style.display='none';
                    249:                     }
                    250:                 }
                    251:             }
                    252:         }
                    253:     } else { 
                    254:         if (caller.checked) {
                    255:             if (document.getElementById('box_'+caller.value)) {
                    256:                 document.getElementById('box_'+caller.value).style.display='block';
                    257:             }
                    258:         } else {
                    259:             if (document.getElementById('box_'+caller.value)) {
                    260:                 document.getElementById('box_'+caller.value).style.display='none';
                    261:             }
                    262:         }
                    263:     }
                    264:     return;
                    265: }
                    266: 
                    267: $check_uncheck
                    268: 
                    269: // ]]>
1.65      raeburn   270: </script>
                    271: 
                    272: ENDSCRIPT
                    273:         }
1.115     raeburn   274:         my $args = {'function'       => undef,
                    275:                     'domain'         => $cdom};
1.113     raeburn   276:         my $forcereg;
                    277:         if ($env{'form.register'}) {
                    278:             $forcereg = 1;
1.115     raeburn   279:             $args->{'force_register'} = $forcereg;
1.113     raeburn   280:         }
                    281:         if ($env{'form.backto'} eq 'coursecatalog') {
                    282:             &Apache::lonhtmlcommon::clear_breadcrumbs();
1.115     raeburn   283:             my $brcrum = [{href=>"javascript:ToCatalog();",
                    284:                            text=>&mt('Course/Community Catalog'),
                    285:                            no_mt=>1}
                    286:                          ];
1.113     raeburn   287:             if ($env{'form.coursenum'} ne '') {
                    288:                 push(@{$brcrum},
                    289:                       {href=>"javascript:ToCatalog('details')",
                    290:                        text=>"Course details"});
                    291:             }
                    292:             push(@{$brcrum},
                    293:                   {href=>$r->uri,
                    294:                    text=>"Course syllabus"});
1.114     raeburn   295:             $args->{'bread_crumbs'} = $brcrum;
1.115     raeburn   296:         } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
                    297:             my $title = $env{'form.title'};
                    298:             if ($title eq '') {
                    299:                 $title = &mt('Syllabus');
                    300:             }
                    301:             my $brcrum =
                    302:                 &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
                    303:             if (ref($brcrum) eq 'ARRAY') {
                    304:                 $args->{'bread_crumbs'} = $brcrum;
                    305:             }
1.114     raeburn   306:         }
1.91      amueller  307:         my $start_page =
1.114     raeburn   308:             &Apache::loncommon::start_page("Syllabus", $rss_link.$js,$args);
1.91      amueller  309:         $r->print($start_page);
1.17      www       310:     }
                    311: # ---------------------------------------------------------- Load syllabus info
1.4       www       312:     my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
1.117     raeburn   313:     my %displayfields;
1.4       www       314: 
1.2       www       315: # This handler might be called anonymously ...
                    316: # ----------------------------------------------------- Only if not public call
1.117     raeburn   317:     if ($allowed) {
                    318: #store what the user typed in to the template
                    319:         if ($env{'form.storesyl'}) {
1.91      amueller  320:             foreach my $syl_field (keys(%syllabusfields)) {
1.90      amueller  321:                 my $field=$env{'form.'.$syl_field};
1.91      amueller  322:                 chomp($field);
1.90      amueller  323:                 $field=~s/\s+$//s;
1.91      amueller  324:                 $field=~s/^\s+//s;
                    325:                 $field=~s/\<br\s*\/*\>$//s;
                    326:                 $field=&Apache::lonfeedback::clear_out_html($field,1);
1.98      amueller  327: 				#here it will be stored
1.91      amueller  328:                 $syllabus{$syl_field}=$field;
1.90      amueller  329:                 if ($syl_field eq 'lll_includeurl') { # clean up included URLs
                    330:                     my $field='';
1.91      amueller  331:                     foreach my $value (split(/\n/,$syllabus{$syl_field})) {
                    332:                         my $url=$value;
1.9       www       333: # get rid of leading and trailing spaces
1.90      amueller  334:                         $url=~s/^\s+//;
                    335:                         $url=~s/\s+$//;
                    336:                         if ($url=~m|^https?\://([^/]+)/(.+)$|) {
1.91      amueller  337:                             my $host = $1;
1.90      amueller  338:                             my $remainder=$2;
1.9       www       339: # remove the hostname from internal URLs
1.91      amueller  340:                             my $hostname = &Apache::lonnet::hostname($host);
                    341:                             my %all_hostnames = &Apache::lonnet::all_hostnames();
                    342:                             foreach my $possible_host (keys(%all_hostnames)) {
1.90      amueller  343:                                 if ($possible_host =~ /\Q$hostname\E/i) {
1.91      amueller  344:                                     $url=$remainder;
                    345:                                 }
                    346:                             }
                    347:                         }
1.9       www       348: # norm internal URLs
1.90      amueller  349:                         unless ($url=~/^https?\:/) {
1.91      amueller  350:                             $url=&Apache::lonnet::clutter($url);
1.90      amueller  351:                         }
1.9       www       352: # re-assemble field
1.90      amueller  353:                         if ($url) {
1.91      amueller  354:                             $field.=$url."\n";
1.90      amueller  355:                         }
1.91      amueller  356:                     }
1.90      amueller  357:                     $syllabus{$syl_field}=$field;
1.91      amueller  358:                 }
1.90      amueller  359:             }
                    360:             $syllabus{'uploaded.domain'}=$env{'user.domain'};
                    361:             $syllabus{'uploaded.name'}=$env{'user.name'};
                    362:             $syllabus{'uploaded.lastmodified'}=time;
                    363:             &Apache::lonnet::put('syllabus',\%syllabus,$cdom,$cnum);
1.117     raeburn   364:             my %storehash;
                    365:             if ($courseenv{'uploadedsyllabus'}) {
                    366:                 &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus');
                    367:                 $storehash{'uploadedsyllabus'} = '';
                    368:             }
                    369:             if ($courseenv{'externalsyllabus'}) {
                    370:                 &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus');
                    371:                 $storehash{'externalsyllabus'} = '';
                    372:             }
                    373:             if ($courseenv{'externalsyllabus'} || $courseenv{'uploadedsyllabus'}) {
                    374:                 &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
                    375:                 undef($uploaded);
                    376:                 undef($external);
                    377:             }
                    378:         } elsif ($env{'form.storeurl'}) {
                    379:             if ($env{'form.externalsyllabus'} =~ m{^https?://}) {
                    380:                 if ($env{'form.externalsyllabus'} eq $external) {
                    381:                     $r->print('<div class="LC_info">'.
                    382:                               &mt('External URL unchanged.').
                    383:                               '</div>');
                    384:                     if ($uploaded) {
                    385:                         my $prefix;
                    386:                         my $home=&Apache::lonnet::homeserver($cnum,$cdom);
                    387:                         if ($home ne 'no_host') {
                    388:                             my $protocol = $Apache::lonnet::protocol{$home};
                    389:                             $protocol = 'http' if ($protocol ne 'https');
                    390:                             $prefix = $protocol.'://'.&Apache::lonnet::hostname($home);
                    391:                         }
                    392:                         unless ($external =~ m{^\Q$prefix/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
                    393:                             &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus');
                    394:                             &Apache::lonnet::put('environment',{uploadedsyllabus => ''},
                    395:                                                  $cdom,$cnum);
                    396:                             undef($uploaded);
                    397:                         }
                    398:                     }
                    399:                 } else {
                    400:                     $external=$env{'form.externalsyllabus'};
                    401:                     $external =~ s/(`)//g;
                    402:                     my $putres =
                    403:                         &Apache::lonnet::put('environment',{externalsyllabus=>$external},
                    404:                                              $cdom,$cnum);
                    405:                     if ($putres eq 'ok') {
                    406:                         &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.externalsyllabus' => $external});
                    407:                         $r->print('<div>'.
                    408:                                   &Apache::lonhtmlcommon::confirm_success(&mt('External URL saved.')).
                    409:                                   '</div>');
                    410:                         if ($uploaded) {
                    411:                             my $prefix;
                    412:                             my $home=&Apache::lonnet::homeserver($cnum,$cdom);
                    413:                             if ($home ne 'no_host') {
                    414:                                 my $protocol = $Apache::lonnet::protocol{$home};
                    415:                                 $protocol = 'http' if ($protocol ne 'https');
                    416:                                 $prefix = $protocol.'://'.&Apache::lonnet::hostname($home);
                    417:                             }
                    418:                             unless ($external =~ m{^\Q$prefix/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
                    419:                                 &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus');
                    420:                                 &Apache::lonnet::put('environment',{uploadedsyllabus => ''},
                    421:                                                      $cdom,$cnum);
                    422:                                 undef($uploaded);
                    423:                             }
                    424:                         }
                    425:                     } else {
                    426:                         $r->print('<div class="LC_error">'.
                    427:                                   &mt('An error occurred storing the external URL: [_1]',$putres).
                    428:                                   '</div>');
                    429:                     }
                    430:                 }
                    431:             } else {
                    432:                 $r->print('<div class="LC_error">'.
                    433:                           &mt('External URL not saved -- invalid URL.').
                    434:                           '</div>');
                    435:             }
                    436:         } elsif ($env{'form.storefile'}) {
                    437:             # Process file upload - phase one - upload and parse primary file.
                    438:             my %allfiles = ();
                    439:             my %codebase = ();
                    440:             my ($upload_result,$upload_output,$uploadphase);
                    441:             if ($env{'form.syllabusfile.filename'}) {
                    442:                 my ($url,$needlink) = &process_upload(\$upload_output,$cnum,$cdom,
                    443:                                                       \%allfiles,\%codebase);
                    444:                 $r->print($upload_output);
                    445:                 if ($url =~ m{^/uploaded/\Q$cdom\E/\Q$cnum\E.*/[^/]+$}) {
                    446:                     my $exturl;
                    447:                     my $home=&Apache::lonnet::homeserver($cnum,$cdom);
                    448:                     if ($home ne 'no_host') {
                    449:                         my $protocol = $Apache::lonnet::protocol{$home};
                    450:                         $protocol = 'http' if ($protocol ne 'https');
                    451:                         $exturl = $protocol.'://'.&Apache::lonnet::hostname($home).$url;
                    452:                     }
                    453:                     my %storehash = (
                    454:                                        uploadedsyllabus => $url,
                    455:                                     );
                    456:                     if ($exturl) {
                    457:                         $storehash{'externalsyllabus'} = $exturl;
                    458:                         if ($exturl =~ /\.(html?|txt|js|css)$/) {
                    459:                             $exturl .= '?inhibitmenu=yes';
                    460:                         }
                    461:                     } else {
                    462:                         $storehash{'externalsyllabus'} = '',
                    463:                     }
                    464:                     my $putres =
                    465:                         &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
                    466:                     if ($putres eq 'ok') {
                    467:                         &Apache::lonnet::make_public_indefinitely($url);
                    468:                         foreach my $key (keys(%storehash)) {
                    469:                             &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash{$key}});
                    470:                         }
                    471:                         $uploaded = $url;
                    472:                         if ($needlink) {
                    473:                             $r->print(&return_to_editor($cdom,$cnum).
                    474:                                       &Apache::loncommon::end_page());
                    475:                             return OK;
                    476:                         }
                    477:                     }
                    478:                 }
                    479:             }
                    480:         } elsif ($env{'form.phase'} eq 'upload_embedded') {
                    481:             # Process file upload - phase two - upload embedded objects
                    482:             my $uploadphase = 'check_embedded';
                    483:             my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');   
                    484:             my $state = &embedded_form_elems($uploadphase,$primaryurl);
                    485:             my $url_root = '/uploaded/'.$cdom.'/'.$cnum;
                    486:             my $actionurl = "/public/$cdom/$cnum/syllabus";
                    487:             my ($result,$flag,$numpathchgs) =
                    488:                 &Apache::loncommon::upload_embedded('syllabus','portfolio/syllabus',
                    489:                     $cnum,$cdom,'/userfiles',$url_root,undef,undef,undef,$state,
                    490:                     $actionurl);
                    491:             unless ($numpathchgs) {
                    492:                 my $modres =
                    493:                     &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
                    494:                                                          $cnum,$cdom,
                    495:                                                          '/userfiles',$env{'form.primaryurl'});
                    496:                 $result .= $modres;
                    497:             }
                    498:             $r->print($result.&return_to_editor($cdom,$cnum).
                    499:                       &Apache::loncommon::end_page());
                    500:             return OK;
                    501:         } elsif ($env{'form.phase'} eq 'check_embedded') {
                    502:             # Process file upload - phase three - modify references in HTML file
                    503:             my $uploadphase = 'modified_orightml';
                    504:             my $result =
                    505:                 &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
                    506:                                                      $cnum,$cdom,
                    507:                                                      '/userfiles',$env{'form.primaryurl'});
                    508:             $r->print($result.&return_to_editor($cdom,$cnum).
                    509:                       &Apache::loncommon::end_page());
                    510:             return OK;
                    511:         }
                    512:         foreach my $field (keys(%syllabusfields)) {
                    513:             if ($syllabus{$field} ne '') {
                    514:                 $displayfields{$field} = ' style="display:block;"';
                    515:             } else {
                    516:                 $displayfields{$field} = ' style="display:none;"';
                    517:             }
1.90      amueller  518:         }
1.4       www       519:     }
1.85      bisitz    520: 
1.113     raeburn   521:     if ($allowed) {
                    522: #---------------------------------- Print External URL Syllabus Info if editing
                    523:         if ($target ne 'tex') {
                    524:             my $protocol = $Apache::lonnet::protocol{$homeserver};
                    525:             $protocol = 'http' if ($protocol ne 'https');
1.119     raeburn   526:             my $link = $protocol.'://'.&Apache::lonnet::hostname($homeserver).$r->uri;
                    527:             $r->print('<div class="LC_left_float">'
                    528:                      .'<span class="LC_help_open_topic LC_info">'
                    529:                      .'<span class="LC_info">'
                    530:                      .&mt('Public link (no log-in): [_1]','<tt>'.$link.'</tt>')
                    531:                      .'&nbsp;</span>'.&Apache::loncommon::help_open_topic('Syllabus_ExtLink')
                    532:                      .'</span>'
                    533:                      .'</div><div style="padding:0;clear:both;margin:0;border:0"></div>');
1.117     raeburn   534:             my $lonhost = $r->dir_config('lonHostID');
1.118     raeburn   535:             $r->print(&chooser($external,$uploaded,$cdom,$cnum,$lonhost,\%syllabusfields,\%syllabus));
1.93      bisitz    536:         }
1.109     bisitz    537:     } else {
1.113     raeburn   538: #--------------------------------------------- Print last update unless editing
                    539:         my $lastmod=$syllabus{'uploaded.lastmodified'};
                    540:         $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
                    541:         my $who;
                    542:         if ($syllabus{'uploaded.lastmodified'}) {
                    543:             if (($env{'user.name'} ne 'public') && ($env{'user.domain'} ne 'public')) {
                    544:                 $who = &Apache::loncommon::aboutmewrapper(
                    545:                        &Apache::loncommon::plainname($syllabus{'uploaded.name'},
                    546:                        $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
                    547:                        $syllabus{'uploaded.domain'});
                    548:             } else {
                    549: # Public user?
                    550: # Only display name of user, but no link to personal information page
                    551:                 $who = &Apache::loncommon::plainname(
                    552:                            $syllabus{'uploaded.name'},
                    553:                            $syllabus{'uploaded.domain'});
                    554:             }
                    555:         }
                    556:         if ($target ne 'tex') {
                    557:             $r->print('<div class="LC_info">'.&mt('Last updated').': '.
                    558:                       $lastmod . ' '.
                    559:                       ($who ? &mt('by').' '.$who
                    560:                            : '' ) .
                    561:                       '</div>' );
                    562:         } else {
                    563:             $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.
                    564:                      ($who? &mt('by').'\\\\ '.
                    565:                      &Apache::loncommon::plainname($syllabus{'uploaded.name'},$syllabus{'uploaded.domain'})
                    566:                      :'')
                    567:                     .'\\\\');
                    568:         }
1.109     bisitz    569:     }
                    570: 
1.113     raeburn   571: #-------------------------------------------------------------- Print Headtitle
1.90      amueller  572:     if ($target ne 'tex') {
1.117     raeburn   573:         my $display = 'block';
                    574:         if ($external || $uploaded) {
                    575:             $display = 'none';
                    576:         }
                    577:         $r->print('<div class="LC_Box" id="template" style="display: '.$display.'">'.
1.113     raeburn   578:                    '<h2 class="LC_hcell">'.$courseenv{'description'}.'</h2>');
                    579:         if ($allowed) {
                    580:              $r->print('<div style="margin: 0; float:left;">'.
                    581:                        '<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>'.
                    582:                        '</div>');
                    583: # Print Help Text if editing at right side of screen
                    584:              $r->print('<div style="margin: 0; float:right;">'.
                    585:                        &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).
                    586:                        '</div><br clear="all" />');
                    587:         } else {
                    588:             $r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>');
                    589:         }
1.90      amueller  590:     } else {
1.91      amueller  591:         $r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
                    592:         &Apache::lonnet::domain($cdom,'description').'}\\\\');
1.90      amueller  593:     }
1.80      neumanie  594: # -------------------------------------------------------- Get course personnel
                    595:     my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
                    596:     if ($target ne 'tex') {
1.91      amueller  597:         $r->print(&Apache::lonhtmlcommon::start_pick_box());
1.80      neumanie  598:     } else {
1.91      amueller  599:         $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
1.80      neumanie  600:     }
                    601:     my @personnel=sort(keys(%coursepersonnel));
                    602:     my $lastpers=$personnel[$#personnel];
                    603:     foreach my $element (@personnel) {
1.91      amueller  604:         if ($target ne 'tex') {
                    605:             $r->print(&Apache::lonhtmlcommon::row_title($element));
                    606:         } else {
                    607:             $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & ');
                    608:         }
1.111     christia  609:         my @coursepersonlist;
1.80      neumanie  610:         foreach (split(/\,/,$coursepersonnel{$element})) {
1.91      amueller  611:             my ($puname,$pudom)=split(/\:/,$_);
                    612:             if ($target ne 'tex') {
1.80      neumanie  613:                 my $courseperson = &Apache::loncommon::plainname($puname,$pudom);
                    614:                 if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
                    615:                     ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
1.111     christia  616:                     push(@coursepersonlist,$courseperson);
1.80      neumanie  617:                 } else {
1.111     christia  618:                     push(@coursepersonlist,&Apache::loncommon::aboutmewrapper($courseperson,
1.80      neumanie  619:                               $puname,$pudom));
                    620:                 }
1.91      amueller  621:             } else {
1.111     christia  622:                 push(@coursepersonlist,&Apache::loncommon::plainname($puname,
1.80      neumanie  623:                               $pudom).' ');
1.91      amueller  624:             }
                    625:         }
1.111     christia  626:         $r->print(join(", ",@coursepersonlist));
1.91      amueller  627:         if ($target ne 'tex') {
1.80      neumanie  628:             my $lastclose=$element eq $lastpers?1:0;
                    629:             $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
1.91      amueller  630:         } else {
                    631:             $r->print('\\\\ \hline');
                    632:         }
1.80      neumanie  633:     }
                    634:     if ($target ne 'tex') {
1.91      amueller  635:         $r->print(&Apache::lonhtmlcommon::end_pick_box());
1.80      neumanie  636:     } else {
1.91      amueller  637:         $r->print('\end{tabular}\\\\');
1.80      neumanie  638:     }
1.79      neumanie  639: # -------------------------------------------------------------- Announcements?
                    640:     my $day = &Apache::lonannounce::showday(time,2,
1.91      amueller  641:              &Apache::lonannounce::readcalendar($cdom.'_'.$cnum));
1.80      neumanie  642:     if ($target ne 'tex') {
1.91      amueller  643:         if ($allowed) {
1.117     raeburn   644:             my $display = ' style="display:block;"';
                    645:             if ($syllabus{'000_showrssfeeds'} eq 'no') {
                    646:                 $display = ' style="display:none;"';
                    647:             }
                    648:             &Apache::lontemplate::print_start_template($r,&mt('RSS Feeds and Blogs'),'LC_Box',
                    649:                                                        'box_000_showrssfeeds',$display);
1.120   ! raeburn   650:             my ($numfeeds,$hiddenfeeds,$rsslinktext);
        !           651:             my $feeds=&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit,\$numfeeds,\$hiddenfeeds);
        !           652:             if ($numfeeds) {
        !           653:                 $r->print($feeds);
        !           654:                 $rsslinktext = &mt('New RSS Feed or Blog');
        !           655:             } else {
        !           656:                 my $msg = '<br />'.
        !           657:                           &mt("RSS Feeds and Blogs item is not included in a student's view of the syllabus.");
        !           658:                 if ($hiddenfeeds) {
        !           659:                     $r->print('<p class="LC_info">'.
        !           660:                               &mt('All feeds currently hidden').
        !           661:                               $msg.
        !           662:                               '</p>');
        !           663:                 } else {
        !           664:                     $r->print('<p class="LC_info">'.
        !           665:                               &mt('No current feeds').
        !           666:                               $msg.
        !           667:                               '</p>');
        !           668:                 }
        !           669:                 $rsslinktext = &mt('Manage Course RSS Feeds/Blogs');
        !           670:                 if ($crstype eq 'Community') {
        !           671:                     $rsslinktext = &mt('Manage Communiity RSS Feeds/Blogs');
        !           672:                 }
        !           673:             }
1.91      amueller  674:             my $editurl= &Apache::lonnet::absolute_url().'/adm/'.$cdom.'/'.$cnum.'/_rss.html';
1.120   ! raeburn   675:             $r->print( '<a href="'.$editurl.'">'.$rsslinktext.'</a>');
1.91      amueller  676:             &Apache::lontemplate::print_end_template($r);
1.117     raeburn   677:         } else {
                    678:             unless ($syllabus{'000_showrssfeeds'} eq 'no') {
1.120   ! raeburn   679:                 my $feeds = &Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit);
        !           680:                 if ($feeds ne '') {
1.117     raeburn   681:                     &Apache::lontemplate::print_start_template($r,&mt('RSS Feeds and Blogs'),'LC_Box');
1.120   ! raeburn   682:                     $r->print($feeds);
1.117     raeburn   683:                     &Apache::lontemplate::print_end_template($r);
                    684:                 }
                    685:             }
1.91      amueller  686:         }
1.79      neumanie  687:     } else {
1.91      amueller  688:         $r->print(&Apache::lonxml::xmlparse($r,'tex',$day));
1.86      bisitz    689:     }
1.79      neumanie  690: # ---------------------------------------------------------------- Get syllabus
1.86      bisitz    691:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.90      amueller  692:         if ($allowed) {
1.95      bisitz    693:             $r->print('<form method="post" action="">'.
1.113     raeburn   694:             '<input type="hidden" name="forceedit" value="'.$env{'form.forceedit'}.'" />');
1.90      amueller  695:         }
1.117     raeburn   696: 
1.106     faziophi  697: 		my $url_include_handler = sub {
1.117     raeburn   698: 			my ($r, $field, $message, $group, $data_ref, $fields_ref, $target, $allowed, $display) = @_;
1.106     faziophi  699: 			my %data = %{$data_ref};
                    700: 			my %fields = %{$fields_ref};
                    701: 			my $urls=$message;
                    702: 			$message='';
                    703: 			foreach my $filelink (split(/\n/,$urls)) {
                    704: 				my $output='';
                    705: 			   # embed style?
                    706: 				my ($curfext)=($filelink=~/\.([^\.]+)$/);
                    707: 				my $embstyle=&Apache::loncommon::fileembstyle($curfext);
                    708: 				if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {# make ssi call and remove everything but the body contents
                    709: 					$output=&Apache::lonnet::ssi_body($filelink);
                    710: 				} elsif ($embstyle eq 'img') {# embed as an image
                    711: 					$output='<img src="'.$filelink.'" />';
                    712: 				}
                    713: 				if ($output ne '') {
                    714: 					   if ($target ne 'tex') {
                    715: 						   $message.='<p>'.$output.'</p>';
                    716: 					   } else {
                    717: 						   $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
                    718: 					   }
                    719: 				}
                    720: 			}
                    721: 			if ($allowed) {
                    722: 				 &Apache::lonfeedback::newline_to_br(\$urls);
                    723: 				 &Apache::lontemplate::print_start_template($r,$fields{$field}.
1.117     raeburn   724: 						  &Apache::loncommon::help_open_topic('Syllabus_URLs'),'LC_Box',
                    725:                                                   'box_'.$field,$display);
1.106     faziophi  726: 				 $r->print($urls);
                    727: 				 $r->print("<br /><div>");
                    728: 				 &Apache::lontemplate::print_textarea_template($r, $data{$field},
                    729: 					$field, Apache::lontemplate->RICH_TEXT_ALWAYS_OFF);
                    730: 				 &Apache::lontemplate::print_saveall_template($r);                         
                    731: 				 $r->print("</div>");
                    732: 				 &Apache::lontemplate::print_end_template($r);
1.86      bisitz    733: 
1.106     faziophi  734: 			} else {
                    735: 				$r->print($message);
                    736: 			}
                    737: 		};
                    738: 		my %custom_hash = ( 'lll_includeurl' => $url_include_handler );
1.110     raeburn   739: 		&Apache::lontemplate::print_template_fields($r, \%syllabus, \%syllabusfields, 
1.117     raeburn   740: 			$target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_hash,
                    741:                         undef,\%displayfields);
1.90      amueller  742:         if ($allowed) {
1.91      amueller  743:             $r->print('</form>'.
1.110     raeburn   744:             &Apache::lonhtmlcommon::htmlareaselectactive());
1.90      amueller  745:         }
1.4       www       746:     } else {
1.112     bisitz    747:         if ($target ne 'tex') {$r->print('<p class="LC_info">');} else {$r->print('\par ');}
1.91      amueller  748:         $r->print(&mt('No syllabus information provided.'));
                    749:         if ($target ne 'tex') {$r->print('</p>');}
1.1       www       750:     }
1.86      bisitz    751:     if ($target ne 'tex') {
1.113     raeburn   752:         $r->print('</div>');
1.65      raeburn   753:         if ($env{'form.backto'} eq 'coursecatalog') {
                    754:             $r->print('<form name="backtocat" method="post" action="/adm/coursecatalog">'.
1.66      raeburn   755:                       &Apache::lonhtmlcommon::echo_form_input(['backto','courseid']).
1.65      raeburn   756:                       '</form>');
                    757:         }
1.91      amueller  758:         $r->print(&Apache::loncommon::end_page());
1.48      albertel  759:     } else {
1.91      amueller  760:         $r->print('\end{document}');
1.48      albertel  761:     }
1.1       www       762:     return OK;
1.86      bisitz    763: }
1.1       www       764: 
1.117     raeburn   765: sub chooser {
1.118     raeburn   766:     my ($external,$uploaded,$cdom,$cnum,$lonhost,$fields,$values) = @_;
1.117     raeburn   767:     my %lt = &Apache::lonlocal::texthash(
                    768:                  'type'          => 'Syllabus Type',
                    769:                  'url'           => 'External URL',
                    770:                  'file'          => 'Uploaded File',
                    771:                  'template'      => 'Syllabus Template',
                    772:                  'templateboxes' => 'Choose template items ... ',
                    773:                  'curr'          => 'Current:',
                    774:                  'rep'           => 'Replace:',
                    775:                  'upl'           => 'Upload:',
                    776:                  'pr'            => 'Preview',
                    777:                  'save'          => 'Save',
                    778:                  'chourl'        => 'Choose external URL',
                    779:                  'chofile'       => 'Uploaded syllabus file',
                    780:                  'parse'         => 'Upload embedded images/multimedia files if HTML file',
                    781:     );
                    782:     my %checked = (
                    783:                     file     => '',
                    784:                     url      => '',
                    785:                     template => '',
                    786:                   );
                    787:     my %display = (
                    788:                     file        => 'none',
                    789:                     url         => 'none',
                    790:                     templatebox => 'none',
                    791:                   );
                    792:     my $check = ' checked="checked" ';
                    793:     if ($uploaded) {
                    794:         $checked{'file'} = $check;
                    795:         $display{'file'} = 'block';
                    796:     } elsif ($external) {
                    797:         $checked{'url'}  = $check;
                    798:         $display{'url'} = 'block';
                    799:     } else {
                    800:         $checked{'template'} = $check;
                    801:         $checked{'templatebox'} = $check;
                    802:         $display{'templatebox'} = 'block';
                    803:     }
                    804: 
                    805:     my $output = 
                    806:         '<form name="syllabus" method="post" enctype="multipart/form-data" action="">'."\n".
                    807:         '<input type="hidden" name="forceedit" value="1" />'."\n".
                    808:         '<div class="LC_left_float"><fieldset><legend>'.$lt{'type'}.'</legend>';
                    809:     foreach my $item ('template','url','file') {
                    810:         $output .= '<label><input type="radio" name="choice" value="'.$item.'" '.$checked{$item}.' onclick="toggleEditor('."'$item'".')" />'.
                    811:                    $lt{$item}.'</label><br />';
                    812:     }
                    813:     $output .= '</fieldset></div>'."\n".
                    814:                '<div id="url" class="LC_left_float" style="display: '.$display{'url'}.'">'."\n".
                    815:                '<fieldset><legend>'.$lt{'chourl'}.'</legend><span class="LC_nobreak">'."\n".
                    816:                '<a href="javascript:extUrlPreview('."'syllabusurl'".');">'.$lt{'pr'}.'</a></span>&nbsp;'."\n".
                    817:                '<input type="text" id="syllabusurl" name="externalsyllabus" value="'.$external.'" size="55" />'."\n".
                    818:                '&nbsp;<input type="submit" name="storeurl" value="'.$lt{'save'}.'" />'."\n".
                    819:                '</fieldset></div>'."\n".
                    820:                '<div id="file" class="LC_left_float" style="display: '.$display{'file'}.'"><fieldset><legend>'.$lt{'file'}.'</legend>';
                    821:     if ($uploaded) {
                    822:         my $protocol = $Apache::lonnet::protocol{$lonhost};
                    823:         $protocol = 'http' if ($protocol ne 'https');
                    824:         my $absurl = $protocol.'://'.&Apache::lonnet::hostname($lonhost).$uploaded;
                    825:         my ($filename) = ($uploaded =~ m{([^/]+)$});
1.118     raeburn   826:         my $file=&Apache::lonnet::filelocation("",$uploaded);
                    827:         my $depbutton;
                    828:         if ($file =~ /\.html?$/) {
                    829:             my $filecontents=&Apache::lonnet::getfile($file);
                    830:             unless ($filecontents eq -1) {
                    831:                 my $mm = new File::MMagic;
                    832:                 my $mimetype = $mm->checktype_contents($filecontents);
                    833:                 if ($mimetype eq 'text/html') {
                    834:                     my (%codebase,%allfiles);
                    835:                     my $parse_result = &Apache::lonnet::extract_embedded_items($uploaded,\%allfiles,
                    836:                                                                                \%codebase,\$filecontents);
                    837:                     my $actionurl = "/public/$cdom/$cnum/syllabus";
                    838:                     my ($ignore,$num,$numpathchanges,$existing,$mapping) =
                    839:                         &Apache::loncommon::ask_for_embedded_content($actionurl,undef,\%allfiles,
                    840:                                                                      \%codebase,
                    841:                                                                      {'context' => 'rewrites',
                    842:                                                                       'ignore_remote_references' => 1,});
                    843:                     if (keys(%allfiles)) {
                    844:                         $depbutton = ('&nbsp;' x 3).
                    845:                                      &editfile_button().
                    846:                                      &editbutton_js($uploaded);
                    847:                     }
                    848:                 }
                    849:             }
                    850:         }
                    851: 
1.117     raeburn   852:         $output .= '<span class="LC_nobreak">'.$lt{'curr'}.'&nbsp;'.
                    853:                    '<input type="hidden" name="uploadedfile" value="'.&HTML::Entities::encode($absurl).'?inhibitmenu=yes" id="currfile" />'.
1.118     raeburn   854:                    '<a href="javascript:extUrlPreview('."'currfile'".');">'.$filename.'</a></span>'.$depbutton.
                    855:                    '<br /><br />'.$lt{'rep'};
1.117     raeburn   856:     } else {
                    857:         $output .= $lt{'upl'};
                    858:     }
                    859: 
                    860:     $output .= '<br />'."\n".
                    861:                '<span class="LC_nobreak">'.
                    862:                '<input type="file" name="syllabusfile" size="55" />'."\n".
                    863:                '&nbsp;<input type="submit" name="storefile" value="'.$lt{'save'}.'" />'.
                    864:                '</span><br />'.
                    865:                '<label>'.
                    866:                '<input type="checkbox" name="parserflag" checked="checked" />'.
                    867:                $lt{'parse'}.
                    868:                '</label>'.
                    869:                '</fieldset></div>'.
                    870:                '<div id="templatebox" class="LC_left_float" style="display: '.
                    871:                $display{'templatebox'}.';"><fieldset><legend>'.$lt{'templateboxes'}.
                    872:                '&nbsp;<input type="button" value="'.&mt('check all').'" '.
                    873:                'onclick="javascript:checkAll('."document.syllabus.showfield".');javascript:toggleBox('."'all'".');" />'.
                    874:                ('&nbsp;'x2).
                    875:                '<input type="button" value="'.&mt('uncheck all').'" '.
                    876:                'onclick="javascript:uncheckAll('."document.syllabus.showfield".');javascript:toggleBox('."'all'".');" />'.
                    877:                '</legend>'.
                    878:                &fields_check_uncheck($fields,$values).
                    879:                '</fieldset>'.
                    880:                '</div>';
                    881:     $output .= '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
                    882:                '</form>';
                    883:     return $output;
                    884: }
                    885: 
                    886: sub fields_check_uncheck {
                    887:     my ($fields,$values) = @_;
                    888:     return unless ((ref($fields) eq 'HASH') && (ref($values) eq 'HASH'));
                    889:     my $numinrow = 4;
                    890:     my $table;
                    891:     my @fieldnames = sort(keys(%{$fields}));
                    892:     unshift(@fieldnames,'000_showrssfeeds'); 
                    893:     my $numfields = scalar(@fieldnames);
                    894:     for (my $i=0; $i<$numfields; $i++) {
                    895:         my $checked;
                    896:         my $name = $fields->{$fieldnames[$i]};
                    897:         if ($fieldnames[$i] eq '000_showrssfeeds') {
                    898:             $name = &mt('RSS Feeds and Blogs');
                    899:             unless ($values->{$fieldnames[$i]} eq 'on') {
                    900:                 $checked = ' checked="checked"';
                    901:             }
                    902:         } elsif ($values->{$fieldnames[$i]} ne '') {
                    903:             $checked = ' checked="checked"';
                    904:         }
                    905:         my $rem = $i%($numinrow);
                    906:         if ($rem == 0) {
                    907:             if (($i > 0) && ($i < $numfields-1)) {
                    908:                 $table .= '</tr>';
                    909:             }
                    910:             if ($i < $numfields-1) {
                    911:                 $table .= '<tr>';
                    912:             }
                    913:         }
                    914:         $table .=
                    915:             '<td><label><input type="checkbox" name="showfield" value="'.$fieldnames[$i].'" '.
                    916:             $checked.' id="showfield_'.$i.'" onclick="javascript:toggleBox('."'$fieldnames[$i]',this".');" />'.
                    917:             $name.'</label></td>'."\n";
                    918:     }
                    919:     if ($table ne '') {
                    920:         my $rem = $numfields%($numinrow);
                    921:         my $colsleft = $numinrow - $rem;
                    922:         if ($colsleft > 1 ) {
                    923:             $table .= '<td colspan="'.$colsleft.'">&nbsp;</td>';
                    924:         } elsif ($colsleft == 1) {
                    925:             $table .= '<td>&nbsp;</td>';
                    926:         }
                    927:         $table = '<table>'.$table.'</tr></table>';
                    928:     }
                    929:     return $table;
                    930: }
                    931: 
                    932: sub process_upload {
                    933:     my ($upload_output,$cnum,$cdom,$allfiles,$codebase) = @_;
                    934:     my ($parseaction,$showupload,$mimetype);
                    935:     my $dest = 'portfolio/syllabus';
                    936:     if ($env{'form.parserflag'}) {
                    937:         $parseaction = 'parse';
                    938:     }
                    939:     my $url=&Apache::lonnet::userfileupload('syllabusfile','syllabus',$dest,
                    940:                                             $parseaction,$allfiles,
                    941:                                             $codebase,undef,undef,undef,undef,
                    942:                                             undef,undef,\$mimetype);
                    943:     if ($url =~ m{^/uploaded/\Q$cdom\E/\Q$cnum\E.*/([^/]+)$}) {
                    944:         my $stored = $1;
                    945:         $showupload = '<p>'.&mt('Uploaded [_1]',
                    946:                                 '<span class="LC_filename">'.$stored.'</span>').
                    947:                       '</p>';
                    948:     } else {
                    949:         my ($filename) = ($env{'form.syllabusfile.filename'} =~ m{([^/]+)$});
                    950:         $$upload_output = '<div class="LC_error" id="uploadfileresult">'.
                    951:                           &mt('Unable to save file [_1].',
                    952:                               '<span class="LC_filename">'.$filename.'</span>').
                    953:                           '</div>';
                    954:         return (); 
                    955:     }
                    956:     my $needlink;
                    957:     if (($parseaction eq 'parse') && ($mimetype eq 'text/html')) {
                    958:         $$upload_output = $showupload;
                    959:         my $total_embedded = scalar(keys(%{$allfiles}));
                    960:         if ($total_embedded > 0) {
                    961:             my $uploadphase = 'upload_embedded';
                    962:             my $primaryurl = &HTML::Entities::encode($url,'<>&"');
                    963:             my $state = &embedded_form_elems($uploadphase,$primaryurl);
                    964:             my $actionurl = "/public/$cdom/$cnum/syllabus";
                    965:             my ($embedded,$num,$numpathchanges,$existing);
                    966:             ($embedded,$num,$numpathchanges,$existing) =
                    967:                 &Apache::loncommon::ask_for_embedded_content($actionurl,$state,
                    968:                                                              $allfiles,$codebase,
                    969:                                                             {'error_on_invalid_names'   => 1,
                    970:                                                              'ignore_remote_references' => 1,});
                    971:             if ($embedded) {
                    972:                 $needlink = 1;
                    973:                 if ($num) {
                    974:                     $$upload_output .=
                    975:                         '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
                    976:                 } elsif ($numpathchanges) {
                    977:                     $$upload_output .= $embedded;
                    978:                 } else {
                    979:                     $$upload_output .= $embedded;
                    980:                     &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
                    981:                                                          $cnum,$cdom,'/userfiles',$url);
                    982:                 }
                    983:             } else {
                    984:                 $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
                    985:                 &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
                    986:                                                      $cnum,$cdom,'/userfiles',$url);
                    987: 
                    988:             }
                    989:         } else {
                    990:             $$upload_output .= &mt('No embedded items identified').'<br />';
                    991:         }
                    992:         $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
                    993:     }
                    994:     return ($url,$needlink);
                    995: }
                    996: 
                    997: sub embedded_form_elems {
                    998:     my ($phase,$primaryurl) = @_;
                    999:     return <<STATE;
                   1000:     <input type="hidden" name="forceedit" value="1" />
                   1001:     <input type="hidden" name="cmd" value="upload_embedded" />
                   1002:     <input type="hidden" name="phase" value="$phase" />
                   1003:     <input type="hidden" name="primaryurl" value="$primaryurl" />
                   1004: STATE
                   1005: }
                   1006: 
                   1007: sub return_to_editor {
                   1008:     my ($cdom,$cnum) = @_;
                   1009:     my $actionurl = "/public/$cdom/$cnum/syllabus";
                   1010:     return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'.
                   1011:            '<input type="hidden" name="forceedit" value="1" />'."\n".
                   1012:            '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
                   1013:            '</a></p>';
                   1014: }
                   1015: 
1.118     raeburn  1016: sub editfile_button {
                   1017:     my $buttontext=&mt('Edit');
                   1018:     return <<"END";
                   1019:                 <input type="button" value="$buttontext" onclick="javascript:gotoeditor();" />
                   1020: END
                   1021: }
                   1022: 
                   1023: sub editbutton_js {
                   1024:     my ($url) = @_;
                   1025:     return <<ENDJS;
                   1026:                 <script type="text/javascript">
                   1027:                 // <![CDATA[
                   1028:                   function gotoeditor() {
                   1029:                       document.location.href = '$url?forceedit=1';
                   1030:                   }
                   1031:                 // ]]>
                   1032:                 </script>
                   1033: ENDJS
                   1034: }
                   1035: 
1.1       www      1036: 1;
                   1037: __END__

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