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

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;
        !            28:                                                                                 
        !            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));
        !            76:             my ($outcome,$symb,$newurl,$bbtitle) = &create_board($cdom,$cnum,
        !            77:                                                                  $group,
        !            78:                                                           $env{'form.newbul'});
        !            79:             if ($outcome eq 'ok') {
        !            80:                 my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
        !            81:                 $r->print(&mt('The new discussion board was added successfully.<br />'));
        !            82:                 $r->print('<table border="0"><tr><td>'.
        !            83:                           '<a href="'.$newurl.'?register=1&symb='.$symb.
        !            84:                           '&group='.$group.'">'.
        !            85:                           &mt('Edit [_1] board',$bbtitle).'</a></td>'.
        !            86:                            '<td>&nbsp;&nbsp;</td><td>'.
        !            87:                           '<a href="/adm/groupboards?group='.$group.'">'.
        !            88:                           &mt('View all group discussion boards').
        !            89:                           '</a></td></tr></table>');
        !            90:             } else {
        !            91:                 $r->print(&mt('There was a problem creating the new discussion board - [_1]',$outcome).'<br /><a href="/adm/groupboards?group='.$group.'">'.
        !            92:                          &mt('Return to discussion boards').'</a>');
        !            93:             }
        !            94:             $r->print(&Apache::loncommon::end_page());
        !            95:             return OK;
        !            96:         }
        !            97:     }
        !            98:     my $jscript;
        !            99:     if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
        !           100:         $jscript = qq|
        !           101: function makebulboard() {
        !           102:    var title=prompt('Discussion Board Title');
        !           103:    if (title) {
        !           104:     this.document.forms.newbb.newbul.value=
        !           105:         title+'=/adm/$cdom/$cnum/$now/bulletinboard';
        !           106:     this.document.forms.newbb.submit();
        !           107:    }
        !           108: }
        !           109: |;
        !           110:     }
        !           111:     $r->print(&Apache::loncommon::start_page($bodytitle,
        !           112:                                        '<script type="text/javascript">'.
        !           113:                                        $jscript.'</script>'));
        !           114:     if (!$can_view) {
        !           115:         $r->print(&mt('You do not have privileges to view discussion boards in this [_1]',$crstype));
        !           116:         return OK;
        !           117:     }
        !           118:     my $navmap = Apache::lonnavmaps::navmap->new();
        !           119:     my @groupboards;
        !           120:     my %boards;
        !           121:     my $grpbbmap = &get_bbfolder_url($cdom,$cnum,$group);
        !           122:     if ($grpbbmap) {
        !           123:         my $bbfolderres = $navmap->getResourceByUrl($grpbbmap);
        !           124:         if ($bbfolderres) {
        !           125:             my @boards = $navmap->retrieveResources($bbfolderres,undef,0,0);
        !           126:             foreach my $res (@boards) {
        !           127:                 my $url = $res->src();
        !           128:                 my $title = $res->title();
        !           129:                 my $symb = $res->symb();
        !           130:                 if ($url =~ m|^/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard|) {
        !           131:                     push(@groupboards,$symb);
        !           132:                     %{$boards{$symb}} = (
        !           133:                                         title => $title,
        !           134:                                         url => $url,
        !           135:                                      );
        !           136:                 }
        !           137:             }
        !           138:         }
        !           139:     }
        !           140:     if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
        !           141:         $r->print('<form method="post" name="newbb" action="/adm/groupboards">'.
        !           142:                   "\n".'<input type="button" name="bbbutton" value="'.
        !           143:                   &mt('New Discussion Board').
        !           144:                   '" onClick="javascript:makebulboard();" />'."\n".
        !           145:                   '  <input type="hidden" name="newbul" />'."\n".
        !           146:                   '  <input type="hidden" name="group" value="'.$group.'" />'.
        !           147:                   "\n".'</form><br />');
        !           148:     }
        !           149:     if (@groupboards) {
        !           150:         foreach my $board (@groupboards) {
        !           151:             $r->print('<a href="'.$boards{$board}{'url'}.'?register=1&symb='.$board.'&group='.$group.'">'.$boards{$board}{'title'}.'</a><br />');
        !           152:         }
        !           153:     } else {
        !           154:         $r->print(&mt('There are currently no discussion boards in this [_1].',
        !           155:                       $gpterm));
        !           156:     }
        !           157:     $r->print(&Apache::loncommon::end_page());
        !           158:     return OK;
        !           159: }
        !           160: 
        !           161: sub create_board {
        !           162:     my ($cdom,$cnum,$group,$newboard,$symb) = @_;
        !           163:     my ($bbtitle,$newurl)=split(/\=/,$newboard);
        !           164:     $bbtitle=&unescape($bbtitle);
        !           165:     $newurl=&unescape($newurl);
        !           166:     my $allbbsmap = &get_bbfolder_url($cdom,$cnum,$group);
        !           167:     my ($outcome,$symb);
        !           168:     if ($allbbsmap =~ m|^/uploaded|) {
        !           169:         my ($errtext,$fatal)=&Apache::lonratedt::mapread($allbbsmap);
        !           170:         if (!$fatal) {
        !           171:             my $newidx=&Apache::lonratedt::getresidx($newurl);
        !           172:             $Apache::lonratedt::resources[$newidx]=$bbtitle.':'.$newurl.
        !           173:                                                    ':false:normal:res';
        !           174:             $Apache::lonratedt::order[1+$#Apache::lonratedt::order]=$newidx;
        !           175:             my ($errtext,$fatal)=&Apache::lonratedt::storemap($allbbsmap,1);
        !           176:             if ($fatal) {
        !           177:                 $outcome = "Error: failed to store discussion boards map - $errtext\n";
        !           178:             } else {
        !           179:                 $outcome = 'ok';
        !           180:                 $symb = &Apache::lonnet::encode_symb($allbbsmap,$newidx,$newurl);
        !           181:             }
        !           182:         } else {
        !           183:             $outcome = "Error: failed to read all discussion boards map - $errtext\n";
        !           184:         }
        !           185:     } else {
        !           186:         $outcome = 'Error: discussion boards folder absent, '.
        !           187:                    'or in unexpected location - '.$allbbsmap."\n";
        !           188:     }
        !           189:     return ($outcome,$symb,$newurl,$bbtitle);
        !           190: }
        !           191: 
        !           192: sub get_bbfolder_url {
        !           193:     my ($cdom,$cnum,$group) = @_;
        !           194:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
        !           195:     my $grpbbmap;
        !           196:     if (%curr_groups) {
        !           197:         my %group_info =  &Apache::longroup::get_group_settings(
        !           198:                                                     $curr_groups{$group});
        !           199:         my $creation = $group_info{'creation'};
        !           200:         my $bbfolder = $creation + 1;
        !           201:         my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
        !           202:         $grpbbmap = $crspath.'default_'.$bbfolder.'.sequence';
        !           203:     }
        !           204:     return $grpbbmap;
        !           205: }
        !           206: 
        !           207: 1;

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