Annotation of loncom/interface/lonbulletin.pm, revision 1.49

1.1       www         1: # The LearningOnline Network
1.5       www         2: # Bulletin Board Handler
1.1       www         3: #
1.49    ! bisitz      4: # $Id: lonbulletin.pm,v 1.48 2009/04/04 21:47:40 bisitz 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::lonbulletin;
                     30: 
                     31: use strict;
                     32: use Apache::Constants qw(:common);
                     33: use Apache::loncommon;
                     34: use Apache::lonnet;
                     35: use Apache::lontexconvert;
1.6       www        36: use Apache::lonfeedback;
1.15      www        37: use Apache::lonlocal;
1.36      raeburn    38: use Apache::lonhtmlcommon;
1.39      albertel   39: use HTML::Entities();
1.36      raeburn    40: use LONCAPA;
1.1       www        41: 
                     42: sub handler {
                     43:     my $r = shift;
1.16      www        44:     &Apache::loncommon::content_type($r,'text/html');
1.1       www        45:     $r->send_http_header;
                     46:     return OK if $r->header_only;
1.29      albertel   47:     my $target=$env{'form.grade_target'};
1.23      sakharuk   48: 
1.1       www        49: # ------------------------------------------------------------ Print the screen
1.32      albertel   50:     if ($target eq 'tex') {
1.49    ! bisitz     51:         $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.23      sakharuk   52:     }
1.2       www        53:     my (undef,undef,undef,undef,$marker)=split(/\//,$r->uri);
1.1       www        54: # Is this even in a course?
1.32      albertel   55:     if (!$env{'request.course.id'}) {
1.49    ! bisitz     56:         &Apache::loncommon::simple_error_page($r,'Not in a course',
        !            57:                                               'Not in a course');
1.1       www        58:         return OK;
                     59:     }
                     60: 
                     61:     $marker=~s/\D//g;
                     62: 
1.32      albertel   63:     if (!$marker) {
1.49    ! bisitz     64:         &Apache::loncommon::simple_error_page($r,'Invalid Call',
        !            65:                                               'Invalid Call');
1.1       www        66:         return OK;
                     67:     }
                     68: 
1.29      albertel   69:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                     70:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.36      raeburn    71:     my ($group,$grp_desc);
1.1       www        72: 
                     73: # --------------------------------------------------------- The syllabus fields
1.17      www        74:     my %syllabusfields=&Apache::lonlocal::texthash(
1.2       www        75:        'aaa_title'         => 'Topic',
                     76:        'bbb_content'       => 'Task',
1.1       www        77:        'ccc_webreferences' => 'Web References');
                     78: 
1.7       www        79: # ------------------------------------------------------------ Get Query String
                     80:     &Apache::loncommon::get_unprocessed_cgi
1.36      raeburn    81:                 ($ENV{'QUERY_STRING'},['forcestudent','forceedit','register',
1.37      raeburn    82:                                        'origpage','group','ref']);
1.7       www        83: # ----------------------------------------------------- Force menu registration
1.35      albertel   84:     my %addentries;
                     85:     if ($env{'form.origpage'}) {
1.49    ! bisitz     86:         $addentries{'onload'} = "document.location='#newpost';";
1.7       www        87:     }
1.1       www        88: # --------------------------------------------------------------- Force Student
                     89:     my $forcestudent='';
1.29      albertel   90:     if ($env{'form.forcestudent'}) { $forcestudent='student'; }
1.19      www        91: 
                     92:     my $forceedit='';
1.29      albertel   93:     if ($env{'form.forceedit'}) { $forceedit='edit'; }
1.37      raeburn    94:     my $refarg = '';
                     95:     if (exists($env{'form.ref'})) { $refarg = 'ref='.$env{'form.ref'}; }
1.1       www        96: 
                     97:     my %syllabus=&Apache::lonnet::dump('bulletinpage_'.$marker,$dom,$crs);
1.36      raeburn    98: 
                     99:     my $boardurl = $r->uri;
                    100:     if ($boardurl =~ m|/adm/\Q$dom\E/\Q$crs\E/\d+/bulletinboard|) {
                    101:         if (!exists($syllabus{'group'})) {
                    102:             &Apache::loncommon::simple_error_page($r,'Group information missing',
                    103:                                                  'Group information missing');
                    104: 
                    105:             return OK;
                    106:         } else {
                    107:             $group = $syllabus{'group'};
                    108:             if ($group eq '') {
                    109:                 &Apache::loncommon::simple_error_page($r,'Invalid group',
                    110:                                                      'Invalid group');
                    111:                 return OK;
                    112:             }
                    113:             my %curr_groups = &Apache::longroup::coursegroups($dom,$crs,$group);
                    114:             if (!defined($curr_groups{$group})) {
                    115:                 &Apache::loncommon::simple_error_page($r,'Invalid group',
                    116:                                                      'Invalid group');
                    117:                 return OK;
                    118:             } else {
                    119:                 my %content = &Apache::longroup::get_group_settings(
                    120:                                                           $curr_groups{$group});
                    121:                 $grp_desc = &unescape($content{'description'});
                    122:             }
                    123:         }
                    124:     }
1.49    ! bisitz    125: 
1.1       www       126: # --------------------------------------- There is such a user, get environment
1.49    ! bisitz    127:     if ($target ne 'tex') {
        !           128:         my $course_or_group;
        !           129:         if($group eq '') {
        !           130:             $course_or_group="Course";
        !           131:         } else {
        !           132:             $course_or_group="Group";
        !           133:         }
        !           134:         my $start_page =
        !           135:             &Apache::loncommon::start_page("$course_or_group Discussion Board",undef,
        !           136:                                            {'function'       => $forcestudent,
        !           137:                                             'add_entries'    => \%addentries,
        !           138:                                             'domain'         => $dom,
        !           139:                                             'force_register' =>
        !           140:                                                 $env{'form.register'}});
        !           141:         $r->print($start_page);
1.36      raeburn   142:         if ($group ne '' && $env{'form.group'} eq $group) {
                    143:             my $gpterm =  &Apache::loncommon::group_term();
                    144:             my $ucgpterm = $gpterm;
                    145:             $ucgpterm =~ s/^(\w)/uc($1)/e;
1.37      raeburn   146:             my ($groupboards,$boards) =
                    147:                 &Apache::longroup::get_group_bbinfo($dom,$crs,$group,$boardurl);
                    148:             my $boardtitle;
                    149:             if ((ref($groupboards) eq 'ARRAY') && (@{$groupboards} > 0)) {
                    150:                 $boardtitle = $$boards{$$groupboards[0]}{'title'};
                    151:             }
1.36      raeburn   152:             $boardurl .= '?register=1&group='.$group;
1.37      raeburn   153:             $r->print(&groupboard_breadcrumbs($dom,$crs,$group,$refarg,$gpterm,
1.36      raeburn   154:                                 $ucgpterm,$grp_desc,$boardurl,$boardtitle));
                    155:         }
                    156:     }
                    157:     my ($allowed);
                    158:     if ($group ne '') {
1.37      raeburn   159:         $allowed=&Apache::lonnet::allowed('mdg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.36      raeburn   160:         if (!$allowed) {
                    161:             $allowed = &Apache::lonnet::allowed('cgb',$env{'request.course.id'}.
                    162:                                                 '/'.$group);
                    163:         }
                    164:         if (!$allowed) {
1.37      raeburn   165:             if ((!&Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) &&
1.36      raeburn   166:                (!&Apache::lonnet::allowed('vgb',$env{'request.course.id'}.
1.49    ! bisitz    167:                                                 '/'.$group))) {
1.36      raeburn   168:                  &print_end_page($r,$target);
1.49    ! bisitz    169:                  return OK;
1.36      raeburn   170:             }
                    171:         }
                    172:     } else {
                    173:         $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.23      sakharuk  174:     }
1.1       www       175: 
1.19      www       176:     my $privileged=$allowed;
                    177:     if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
1.49    ! bisitz    178:         $forcestudent='student';
1.19      www       179:     }
1.27      albertel  180:     if ($target ne 'tex') { $r->print('<table><tr><td>'); }
1.49    ! bisitz    181:     if ($forcestudent or $target eq 'tex') { $allowed=0; }
        !           182: 
        !           183:     if ($allowed) {
        !           184:         my $query_str = 'forcestudent=1';
        !           185:         if (($group ne '') && ($env{'form.group'} eq $group)) {
        !           186:             $query_str.='&amp;group='.$group.'&amp;'.$refarg;
        !           187:         }
        !           188:         $r->print(
        !           189:             '<p>'.
        !           190:             &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).'<br /><a href="'.$r->uri.'?'.$query_str.'"><font size="+1">'.&mt('Show Student View').'</font></a>'.
        !           191:              &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
        !           192:     }  elsif ($privileged and $target ne 'tex') {
        !           193:         my $query_str = 'forceedit=edit';
        !           194:         if (($group ne '') && ($env{'form.group'} eq $group)) {
        !           195:             $query_str.='&amp;group='.$group.'&amp;'.$refarg;
        !           196:         }
        !           197:         $r->print('<a href="'.$r->uri.'?'.$query_str.'"><font size="+1">'
        !           198:                      .&mt('Edit').'</font></a>');
        !           199:     }
        !           200: 
        !           201:     if (($env{'form.uploaddoc.filename'}) &&
        !           202:         ($env{'form.storeupl'}) && ($allowed)) {
        !           203:         if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
        !           204:             if ($syllabus{'uploaded.photourl'}) {
        !           205:                 &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
        !           206:             }
        !           207:             if ($group ne '') {
        !           208:                 $syllabus{'uploaded.photourl'}=
        !           209:                     &Apache::lonnet::userfileupload('uploaddoc',1,
        !           210:                                                     'bulletin/'.$group.'/'.$marker);
        !           211:             } else {
        !           212:                 $syllabus{'uploaded.photourl'}=
        !           213:                     &Apache::lonnet::userfileupload('uploaddoc',1,
1.38      raeburn   214:                                                       'bulletin/'.$marker);
1.49    ! bisitz    215:             }
        !           216:         }
        !           217:         $syllabus{'uploaded.lastmodified'}=time;
        !           218:         &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
        !           219:     }
        !           220:     if (($allowed) && ($env{'form.storesyl'})) {
        !           221:         foreach my $syl_field (keys(%syllabusfields)) {
        !           222:             my $field=$env{'form.'.$syl_field};
        !           223:             $field=~s/\s+$//s;
        !           224:             $field=&Apache::lonfeedback::clear_out_html($field,1);
        !           225:             $syllabus{$syl_field}=$field;
        !           226:         }
        !           227:         $syllabus{'uploaded.lastmodified'}=time;
        !           228:         &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
        !           229:     }
1.1       www       230: 
                    231: # ---------------------------------------------------------------- Get syllabus
                    232:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.49    ! bisitz    233:         if ($syllabus{'uploaded.photourl'}) {
        !           234:             &Apache::lonnet::allowuploaded('/adm/syllabus',
        !           235:                                            $syllabus{'uploaded.photourl'});
        !           236:             $r->print('<img src="'.$syllabus{'uploaded.photourl'}.
        !           237:             '" align="right" />');
        !           238:         }
        !           239:         if ($allowed) {
        !           240:             $r->print(
        !           241:                 '<form method="post" enctype="multipart/form-data">'.
        !           242:                 '<input type="hidden" name="forceedit" value="edit" />'.
        !           243:                 '<h3>'.&mt('Upload a Photo').'</h3>'.
        !           244:                 '<input type="file" name="uploaddoc" size="50" />'.
        !           245:                 '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />'.
        !           246:                 '</form><form method="post">'.
        !           247:                 '<input type="hidden" name="forceedit" value="edit" />');
        !           248:         }
        !           249:         foreach my $field (sort(keys(%syllabusfields))) {
        !           250:             if (($syllabus{$field}) || ($allowed)) {
        !           251:                 my $message=$syllabus{$field};
        !           252:                 &Apache::lonfeedback::newline_to_br(\$message);
        !           253:                 $message
        !           254:                     =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.2       www       255:                 if ($allowed) {
1.49    ! bisitz    256:                     $message=&Apache::lonspeller::markeduptext($message);
        !           257:                 }
        !           258:                 $message=&Apache::lontexconvert::msgtexconverted($message);
        !           259:                 unless ($field eq 'aaa_title') {
        !           260:                     if (($field ne 'bbb_content') || ($allowed)) {
        !           261:                         if ($target ne 'tex') {
        !           262:                             $r->print('<h3>'.$syllabusfields{$field}.'</h3>');
        !           263:                         } else {
        !           264:                             $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\');
        !           265:                         }
        !           266:                     }
        !           267:                     if ($target ne 'tex') {
        !           268:                         $r->print('<blockquote>'.
        !           269:                                   $message.'</blockquote>');
        !           270:                     } else {
        !           271:                         $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$message).' ');
        !           272:                     }
        !           273:                     if ($allowed) {
        !           274:                         $r->print('<br /><textarea cols="80" rows="10" name="'.$field.'">'.
        !           275:                                   &HTML::Entities::encode($syllabus{$field},'&"<>').
        !           276:                                   '</textarea><input type="submit" name="storesyl" value="'.&mt('Save').'" />');
        !           277:                     }
        !           278:                 } else {
        !           279:                     if ($target ne 'tex') {
        !           280:                         $r->print('<h1>'.$message.'</h1>');
        !           281:                     } else {
        !           282:                         $r->print('\\\\\textbf{'.&Apache::lonxml::xmlparse($r,'tex',$message).'}\\\\');
        !           283:                     }
        !           284:                     if ($allowed) {
        !           285:                         $r->print(
        !           286:                             '<br />'.&mt('Topic').'<br /><textarea cols="80" rows="2" name="'.$field.'">'.
        !           287:                             &HTML::Entities::encode($syllabus{$field},'&"<>').
        !           288:                             '</textarea><input type="submit" name="storesyl" value="'.&mt('Save').'" />');
        !           289:                     }
1.2       www       290:                 }
                    291:             }
1.49    ! bisitz    292:         }
        !           293:         if ($allowed) {
        !           294:             $r->print('</form>');
        !           295:         }
        !           296:         if ($target ne 'tex') {$r->print('</p>');} else {$r->print('\\\\');}
1.1       www       297:     } else {
1.49    ! bisitz    298:         $r->print('<p>'.&mt('No page information provided.').'</p>');
1.1       www       299:     }
1.27      albertel  300:     if ($target ne 'tex') { $r->print('</td></tr></table>'); }
1.23      sakharuk  301:     if ($target ne 'tex') {
1.49    ! bisitz    302:         $r->print(&Apache::lonfeedback::list_discussion
        !           303:                       ('board','OPEN','bulletin___'.$marker.'___'.
        !           304:                        $r->uri,undef,$group));
1.23      sakharuk  305:     } else {
1.49    ! bisitz    306:         $r->print('\\\\'.&Apache::lonxml::xmlparse($r,'tex',&Apache::lonfeedback::list_discussion
        !           307:                      ('board','OPEN','bulletin___'.$marker.'___'.
        !           308:                       $r->uri,undef,$group)));
1.23      sakharuk  309:     }
1.36      raeburn   310:     &print_end_page($r,$target);
                    311:     return OK;
                    312: }
                    313: 
                    314: sub print_end_page {
                    315:     my ($r,$target) = @_;
1.32      albertel  316:     if ($target ne 'tex') {
1.36      raeburn   317:         $r->print(&Apache::loncommon::end_page());
1.32      albertel  318:     } else {
1.36      raeburn   319:         $r->print('\end{document}');
1.32      albertel  320:     }
1.36      raeburn   321: }
                    322: 
                    323: sub groupboard_breadcrumbs {
1.37      raeburn   324:     my ($cdom,$cnum,$group,$refarg,$gpterm,$ucgpterm,$description,$boardurl,
                    325:         $boardtitle)= @_;
1.36      raeburn   326:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.37      raeburn   327:     if ($refarg ne '') {
                    328:         &Apache::lonhtmlcommon::add_breadcrumb
                    329:             ({href=>"/adm/coursegroups",
                    330:               text=>"Groups",
                    331:               title=>"View course groups"});
                    332:     }
1.36      raeburn   333:     &Apache::lonhtmlcommon::add_breadcrumb
1.37      raeburn   334:         ({href=>"/adm/$cdom/$cnum/$group/smppg?$refarg",
1.36      raeburn   335:           text=>"$ucgpterm: $description",
                    336:           title=>"Go to group's home page"},
1.37      raeburn   337:          {href=>"/adm/groupboards?group=$group&amp;$refarg",
1.36      raeburn   338:           text=>"Discussion Boards",
                    339:           title=>"Display group discussion boards"},
                    340:          {href=>"$boardurl",
                    341:           text=>"$boardtitle",
                    342:           title=>"$boardtitle"},
                    343:         );
                    344:     my $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('[_1] discussion boards - [_2]',$gpterm,$description));
                    345:     return $output;
                    346: }
1.1       www       347: 
                    348: 1;
                    349: __END__

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