Annotation of loncom/interface/groupboards.pm, revision 1.4

1.1       raeburn     1: # The LearningOnline Network
                      2: # Group Bulletin Boards Manager
                      3: #
                      4: # Copyright Michigan State University Board of Trustees
                      5: #
                      6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      7: #
                      8: # LON-CAPA is free software; you can redistribute it and/or modify
                      9: # it under the terms of the GNU General Public License as published by
                     10: # the Free Software Foundation; either version 2 of the License, or
                     11: # (at your option) any later version.
                     12: #
                     13: # LON-CAPA is distributed in the hope that it will be useful,
                     14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     16: # GNU General Public License for more details.
                     17: #
                     18: # You should have received a copy of the GNU General Public License
                     19: # along with LON-CAPA; if not, write to the Free Software
                     20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     21: #
                     22: # /home/httpd/html/adm/gpl.txt
                     23: #
                     24: # http://www.lon-capa.org/
                     25: #
                     26: 
                     27: package Apache::groupboards;
1.2       albertel   28: 
1.1       raeburn    29: use strict;
                     30: use Apache::Constants qw(:common :http);
                     31: use Apache::loncommon;
                     32: use Apache::lonnet;
                     33: use Apache::lonnavmaps;
                     34: use Apache::lonuserstate;
                     35: use Apache::lonratedt;
                     36: use Apache::lonlocal;
                     37: use LONCAPA;
                     38: 
                     39: sub handler {
                     40:     my ($r) = @_;
                     41:     &Apache::loncommon::content_type($r,'text/html');
                     42:     $r->send_http_header;
                     43:     return OK if $r->header_only;
                     44: 
                     45:     #  Needs to be in a course
                     46:     if (! ($env{'request.course.fn'})) {
                     47:         # Not in a course
                     48:         $env{'user.error.msg'}=
                     49:      "/adm/groupboards:mdg:0:0:Cannot edit or view course groups";
                     50:         return HTTP_NOT_ACCEPTABLE;
                     51:     }
                     52: 
                     53:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                     54:                         ['group']);
                     55: 
                     56:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                     57:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                     58:     my $now = time;
                     59:     my $crstype = &Apache::loncommon::course_type();
                     60:     my $gpterm =  &Apache::loncommon::group_term();
                     61:     my $bodytitle = &mt('[_1] Discussion Boards',$crstype);
                     62:     my $group = $env{'form.group'};
                     63:     if (!defined($group)) {
                     64:         $r->print(&Apache::loncommon::start_page($bodytitle));
                     65:         $r->print(&mt('No [_1] defined, so there are no [_1] discussion boards to display',$gpterm));
                     66:         $r->print(&Apache::loncommon::end_page());
                     67:         return OK;
                     68:     }
                     69:     my $can_create=&Apache::lonnet::allowed('cgb',$env{'request.course.id'}.
                     70:                                             '/'.$group);
                     71:     my $can_view=&Apache::lonnet::allowed('pgd',$env{'request.course.id'}.
                     72:                                           '/'.$group);
                     73:     if (defined($env{'form.newbul'})) {
                     74:         if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
                     75:             $r->print(&Apache::loncommon::start_page($bodytitle));
1.4     ! raeburn    76:             my ($outcome,$newurl,$bbtitle) = 
1.2       albertel   77: 		&create_board($cdom,$cnum,$group,$env{'form.newbul'});
1.1       raeburn    78:             if ($outcome eq 'ok') {
                     79:                 my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
                     80:                 $r->print(&mt('The new discussion board was added successfully.<br />'));
                     81:                 $r->print('<table border="0"><tr><td>'.
1.3       raeburn    82:                           '<a href="'.$newurl.'?group='.$group.'">'.
1.1       raeburn    83:                           &mt('Edit [_1] board',$bbtitle).'</a></td>'.
                     84:                            '<td>&nbsp;&nbsp;</td><td>'.
                     85:                           '<a href="/adm/groupboards?group='.$group.'">'.
                     86:                           &mt('View all group discussion boards').
                     87:                           '</a></td></tr></table>');
                     88:             } else {
1.2       albertel   89:                 $r->print(&mt('There was a problem creating the new discussion board - [_1]','<span class="LC_error">'.$outcome.'</span>').'<br /><a href="/adm/groupboards?group='.$group.'">'.
1.1       raeburn    90:                          &mt('Return to discussion boards').'</a>');
                     91:             }
                     92:             $r->print(&Apache::loncommon::end_page());
                     93:             return OK;
                     94:         }
                     95:     }
                     96:     my $jscript;
                     97:     if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
                     98:         $jscript = qq|
                     99: function makebulboard() {
                    100:    var title=prompt('Discussion Board Title');
                    101:    if (title) {
                    102:     this.document.forms.newbb.newbul.value=
                    103:         title+'=/adm/$cdom/$cnum/$now/bulletinboard';
                    104:     this.document.forms.newbb.submit();
                    105:    }
                    106: }
                    107: |;
                    108:     }
                    109:     $r->print(&Apache::loncommon::start_page($bodytitle,
                    110:                                        '<script type="text/javascript">'.
                    111:                                        $jscript.'</script>'));
                    112:     if (!$can_view) {
                    113:         $r->print(&mt('You do not have privileges to view discussion boards in this [_1]',$crstype));
                    114:         return OK;
                    115:     }
                    116:     my $navmap = Apache::lonnavmaps::navmap->new();
1.4     ! raeburn   117:     my ($groupboards,$boards) = &Apache::longroup::get_group_bbinfo($cdom,$cnum,
        !           118:                                                                     $group);
1.1       raeburn   119:     if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
                    120:         $r->print('<form method="post" name="newbb" action="/adm/groupboards">'.
                    121:                   "\n".'<input type="button" name="bbbutton" value="'.
                    122:                   &mt('New Discussion Board').
                    123:                   '" onClick="javascript:makebulboard();" />'."\n".
                    124:                   '  <input type="hidden" name="newbul" />'."\n".
                    125:                   '  <input type="hidden" name="group" value="'.$group.'" />'.
                    126:                   "\n".'</form><br />');
                    127:     }
1.4     ! raeburn   128:     if (@{$groupboards} > 0) {
        !           129:         foreach my $board (@{$groupboards}) {
        !           130:             $r->print('<a href="'.$$boards{$board}{'url'}.'?group='.$group.'">'.$$boards{$board}{'title'}.'</a><br />');
1.1       raeburn   131:         }
                    132:     } else {
                    133:         $r->print(&mt('There are currently no discussion boards in this [_1].',
                    134:                       $gpterm));
                    135:     }
                    136:     $r->print(&Apache::loncommon::end_page());
                    137:     return OK;
                    138: }
                    139: 
                    140: sub create_board {
1.4     ! raeburn   141:     my ($cdom,$cnum,$group,$newboard) = @_;
1.1       raeburn   142:     my ($bbtitle,$newurl)=split(/\=/,$newboard);
                    143:     $bbtitle=&unescape($bbtitle);
                    144:     $newurl=&unescape($newurl);
1.4     ! raeburn   145:     my $allbbsmap = &Apache::longroup::get_bbfolder_url($cdom,$cnum,$group);
        !           146:     my ($outcome);
1.1       raeburn   147:     if ($allbbsmap =~ m|^/uploaded|) {
                    148:         my ($errtext,$fatal)=&Apache::lonratedt::mapread($allbbsmap);
                    149:         if (!$fatal) {
                    150:             my $newidx=&Apache::lonratedt::getresidx($newurl);
                    151:             $Apache::lonratedt::resources[$newidx]=$bbtitle.':'.$newurl.
                    152:                                                    ':false:normal:res';
1.2       albertel  153:             push(@Apache::lonratedt::order,$newidx);
1.1       raeburn   154:             my ($errtext,$fatal)=&Apache::lonratedt::storemap($allbbsmap,1);
                    155:             if ($fatal) {
1.2       albertel  156:                 $outcome = "error: failed to store discussion boards map - $errtext\n";
1.1       raeburn   157:             } else {
                    158:                 $outcome = 'ok';
                    159:             }
                    160:         } else {
1.2       albertel  161:             $outcome = "error: failed to read all discussion boards map - $errtext\n";
1.1       raeburn   162:         }
                    163:     } else {
1.2       albertel  164:         $outcome = 'error: discussion boards folder absent, '.
1.1       raeburn   165:                    'or in unexpected location - '.$allbbsmap."\n";
                    166:     }
1.4     ! raeburn   167:     return ($outcome,$newurl,$bbtitle);
1.1       raeburn   168: }
                    169: 
                    170: 1;

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