Diff for /loncom/interface/groupboards.pm between versions 1.13 and 1.18

version 1.13, 2009/02/02 14:31:58 version 1.18, 2013/07/19 18:24:17
Line 1 Line 1
 # The LearningOnline Network  # The LearningOnline Network
 # Group Bulletin Boards Manager  # Group Bulletin Boards Manager
 #  #
   # $Id$
   #
 # Copyright Michigan State University Board of Trustees  # Copyright Michigan State University Board of Trustees
 #  #
 # This file is part of the LearningOnline Network with CAPA (LON-CAPA).  # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
Line 103  sub handler { Line 105  sub handler {
         if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {          if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
             $r->print(&boards_header($cdom,$cnum,$group,$description,$gpterm,              $r->print(&boards_header($cdom,$cnum,$group,$description,$gpterm,
                                      $ucgpterm,$bodytitle,$refarg));                                       $ucgpterm,$bodytitle,$refarg));
             my ($outcome,$newurl,$bbtitle,$dellockoutcome) =               my ($outcome,$newurl,$bbtitle,$lockfreed) = 
  &create_board($cdom,$cnum,$group,$env{'form.newbul'});   &create_board($cdom,$cnum,$group,$env{'form.newbul'});
             if ($outcome eq 'ok') {              if ($outcome eq 'ok') {
                 my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);                  my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
                 $r->print(&mt('The new discussion board was added successfully.<br />'));                  $r->print(&mt('The new discussion board was added successfully.').'<br />');
                 $r->print('<table border="0"><tr><td>'.                  $r->print('<table border="0"><tr><td>'.
                           '<a href="'.$newurl.'?group='.$group.'&amp;'.$refarg.                            '<a href="'.$newurl.'?group='.$group.'&amp;'.$refarg.
                           '">'.&mt('Edit [_1] board',$bbtitle).'</a></td>'.                            '">'.&mt('Edit [_1] board',$bbtitle).'</a></td>'.
Line 115  sub handler { Line 117  sub handler {
                           '<a href="/adm/groupboards?group='.$group.'&amp;'.                            '<a href="/adm/groupboards?group='.$group.'&amp;'.
                           $refarg.'">'.&mt('View all group discussion boards').                            $refarg.'">'.&mt('View all group discussion boards').
                           '</a></td></tr></table>');                            '</a></td></tr></table>');
                 if ($dellockoutcome ne 'ok') {                  if ($lockfreed ne 'ok') {
                     $r->print(&mt('There was a problem removing a lockfile for the group ([_1]). This may prevent creation of additional bulletin boards in this group.  Please contact the system administrator for your LON-CAPA domain.'));                      $r->print(&mt('There was a problem removing a lockfile for the group ([_1]).',$description).'<br />'.
                                 &mt('This may prevent creation of additional bulletin boards in this group.').'<br />'.
                                 &mt('Please contact the domain coordinator for your LON-CAPA domain.'));
                 }                  }
             } else {              } else {
                 $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.'">'.                  $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.'">'.
Line 148  function makebulboard() { Line 152  function makebulboard() {
         $r->print('<br /><form method="post" name="newbb" action="/adm/groupboards">'.          $r->print('<br /><form method="post" name="newbb" action="/adm/groupboards">'.
                   "\n".'<input type="button" name="bbbutton" value="'.                    "\n".'<input type="button" name="bbbutton" value="'.
                   &mt('New Discussion Board').                    &mt('New Discussion Board').
                   '" onClick="javascript:makebulboard();" />'."\n".                    '" onclick="javascript:makebulboard();" />'."\n".
                   '<input type="hidden" name="newbul" />'."\n".                    '<input type="hidden" name="newbul" />'."\n".
                   '<input type="hidden" name="group" value="'.$group.'" />'.                    '<input type="hidden" name="group" value="'.$group.'" />'.
                   '<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />'.                    '<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />'.
Line 189  function makebulboard() { Line 193  function makebulboard() {
   
 sub create_board {  sub create_board {
     my ($cdom,$cnum,$group,$bbtitle) = @_;      my ($cdom,$cnum,$group,$bbtitle) = @_;
     my ($outcome,$boardid,$newurl);      my ($outcome,$newurl,$idtype);
     $bbtitle=&unescape($bbtitle);      $bbtitle=&unescape($bbtitle);
     # get lock on nohist_groupboards file      $idtype = 'inc';
     my $lockhash = {      my ($boardid,$dellock,$error) = 
                   $group."\0".'locked_boardids' => $env{'user.name'}.          &Apache::lonnet::get_timebased_id($group,'boardids','groupboards',
                                                        ':'.$env{'user.domain'},                                            $cdom,$cnum);
                    };      if ($boardid) {
     my $tries = 0;           $newurl = '/adm/'.$cdom.'/'.$cnum.'/'.$boardid.'/bulletinboard';
     my $gotlock = &Apache::lonnet::newput('nohist_groupboards',$lockhash,$cdom,$cnum);  
     my $dellockoutcome;  
     while (($gotlock ne 'ok') && $tries <3) {  
         $tries ++;  
         sleep 1;  
         $gotlock = &Apache::lonnet::newput('nohist_groupboards',$lockhash,$cdom,$cnum);  
     }  
     if ($gotlock eq 'ok') {  
        my %curr_boards = &Apache::lonnet::dump('nohist_groupboards',$cdom,$cnum,$group);  
        $boardid = time;  
        my $idtries = 0;  
        while(exists($curr_boards{$group."\0".$boardid}) && $idtries < 20) {  
            $boardid ++;  
            $idtries ++;  
        }  
        if (!exists($curr_boards{$group."\0".$boardid})) {  
            my %new_board = (  
                           $group."\0".$boardid => $env{'user.name'}.':'.  
                                                   $env{'user.domain'},  
            );  
            my $putresult = &Apache::lonnet::put('nohist_groupboards',\%new_board,  
                                                 $cdom,$cnum);  
            if ($putresult ne 'ok') {  
                $outcome = 'error saving new board: '.$putresult;  
            } else {  
                $newurl = '/adm/'.$cdom.'/'.$cnum.'/'.$boardid.  
                          '/bulletinboard';  
            }  
        } else {  
             $outcome = ('error: no unique ID for the new board available.');  
        }  
        #  remove lock  
        my @del_lock = ($group."\0".'locked_boardids');  
        $dellockoutcome = &Apache::lonnet::del('nohist_groupboards',\@del_lock,$cdom,$cnum);  
     } else {      } else {
         $outcome = "error: could not obtain lockfile\n";           return ($error,$newurl,$bbtitle,$dellock);
         $dellockoutcome = 'ok';  
     }  
     if (!$newurl) {  
         return ($outcome,$newurl,$bbtitle,$dellockoutcome);  
     }      }
     $newurl=&unescape($newurl);  
     # need to check here if group_boards_$group.sequence is in the course      # need to check here if group_boards_$group.sequence is in the course
     # if not - add it as an item in group_folder_$group.sequence       # if not - add it as an item in group_folder_$group.sequence 
     my $allbbsmap = &Apache::longroup::get_bbfolder_url($cdom,$cnum,$group);      my $allbbsmap = &Apache::longroup::get_bbfolder_url($cdom,$cnum,$group);
Line 249  sub create_board { Line 215  sub create_board {
             $LONCAPA::map::resources[$newidx]=$bbtitle.':'.$newurl.              $LONCAPA::map::resources[$newidx]=$bbtitle.':'.$newurl.
                                                    ':false:normal:res';                                                     ':false:normal:res';
             push(@LONCAPA::map::order,$newidx);              push(@LONCAPA::map::order,$newidx);
             my ($errtext,$fatal)=&LONCAPA::map::storemap($allbbsmap,1);              my ($errtext,$fatal)=&LONCAPA::map::storemap($allbbsmap,1,1);
             if ($fatal) {              if ($fatal) {
                 $outcome = "error: failed to save discussion boards map - $errtext\n";                  $outcome = "error: failed to save discussion boards map - $errtext\n";
             } else {              } else {
Line 266  sub create_board { Line 232  sub create_board {
         $outcome = 'error: discussion boards folder absent, '.          $outcome = 'error: discussion boards folder absent, '.
                    'or in unexpected location - '.$allbbsmap."\n";                     'or in unexpected location - '.$allbbsmap."\n";
     }      }
     return ($outcome,$newurl,$bbtitle,$dellockoutcome);      return ($outcome,$newurl,$bbtitle,$dellock);
 }  }
   
 sub display_error {  sub display_error {

Removed from v.1.13  
changed lines
  Added in v.1.18


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