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

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

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