--- loncom/interface/lonmsgdisplay.pm	2006/10/04 20:28:21	1.35.2.6
+++ loncom/interface/lonmsgdisplay.pm	2006/06/30 02:05:22	1.36
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines for messaging display
 #
-# $Id: lonmsgdisplay.pm,v 1.35.2.6 2006/10/04 20:28:21 albertel Exp $
+# $Id: lonmsgdisplay.pm,v 1.36 2006/06/30 02:05:22 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -270,14 +270,12 @@ sub discourse {
 	    &Apache::lonselstudent::get_people_in_class($env{'request.course.sec'});
     unshift @$current_members, (@$course_personnel);
     my %defaultUsers;
-    
-    $result .= '<input type="hidden" name="sendmode" value="group" />'."\n";
 
-    $result .= &Apache::lonselstudent::render_student_list($current_members,
-							   "compemail",
-							   "current",
-							   \%defaultUsers,
-							   1,"selectedusers",1);
+    $result = &Apache::lonselstudent::render_student_list($current_members,
+							  "compemail",
+							  "current",
+							  \%defaultUsers,
+							  1,"selectedusers",1);
 
     $result .= &Apache::lonselstudent::render_student_list($expired_members,
 							   "compemail",
@@ -292,191 +290,6 @@ sub discourse {
     return $result;
 }
 
-sub disgroup {
-    my ($cdom,$cnum,$group,$viewgrps,$editgrps) = @_;
-    my $result;
-    #  Needs to be in a course
-    if (!($env{'request.course.fn'})) {
-        $result = &mt('Error: you must have a course role selected to be able to send a broadcast message to a group in the course.');
-        return $result;
-    }
-    if ($cdom eq '' || $cnum eq '') {
-        $result = &mt('Error: could not determine domain or number of course');
-        return $result;
-    }
-    my ($memberinfo,$numitems) =
-                 &Apache::longroup::group_memberlist($cdom,$cnum,$group,{},[]);
-    my @statustypes = ('active');
-    if ($viewgrps || $editgrps) {
-        push(@statustypes,('future','previous'));
-    }
-    if (keys(%{$memberinfo}) == 0) {
-        $result = &mt('As this group has no members, there are no '.
-                      'recipients to select.');
-        return $result;
-    } else {
-        $result = &mt('Select message recipients from the group members listed below.<br />');  
-        my %Sortby = (
-                         active   => {},
-                         previous => {},
-                         future   => {},
-                     );
-        my %lt = &Apache::lonlocal::texthash(
-                                     'name'     => 'Name',
-                                     'usnm'     => 'Username',
-                                     'doma'     => 'Domain',
-                                     'active'   => 'Active Members',
-                                     'previous' => 'Former Members',
-                                     'future'   => 'Future Members',
-                                    );
-        foreach my $user (sort(keys(%{$memberinfo}))) {
-            my $status = $$memberinfo{$user}{status};
-            if ($env{'form.'.$status.'.sortby'} eq 'fullname') {
-                push(@{$Sortby{$status}{$$memberinfo{$user}{fullname}}},$user);
-            } elsif ($env{'form.'.$status.'.sortby'} eq 'username') {
-                push(@{$Sortby{$status}{$$memberinfo{$user}{uname}}},$user);
-            } elsif ($env{'form.'.$status.'.sortby'} eq 'domain') {
-                push(@{$Sortby{$status}{$$memberinfo{$user}{udom}}},$user);
-            } else {
-                push(@{$Sortby{$status}{$$memberinfo{$user}{fullname}}},$user);
-            }
-        }
-        $result .= &group_check_uncheck();
-        $result .= '<table border="0" cellspacing="8" cellpadding="2">'.
-                   '<tr>';
-        foreach my $status (@statustypes)  {
-            if (ref($numitems) eq 'HASH') {
-                if ((defined($$numitems{$status})) && ($$numitems{$status})) {
-                    $result.='<td valign="top">'.
-                             '<fieldset><legend><b>'.$lt{$status}.
-                             '</b></legend><nobr>'.
-                             '<input type="button" value="check all" '.
-                             'onclick="javascript:toggleAll('."'".$status."','check'".')" />'.
-                             '&nbsp;&nbsp;'.
-                             '<input type="button" value="uncheck all" '.
-                             'onclick="javascript:toggleAll('."'".$status."','uncheck'".')" />'.
-                             '</nobr></fieldset><br />'.
-                             &Apache::loncommon::start_data_table().
-                             &Apache::loncommon::start_data_table_header_row();
-                    $result .= "<th>$lt{'name'}</a></th>".
-                               "<th>$lt{'usnm'}</a></th>".
-                               "<th>$lt{'doma'}</a></th>".
-                    &Apache::loncommon::end_data_table_header_row();
-                    foreach my $key (sort(keys(%{$Sortby{$status}}))) {
-                        foreach my $user (@{$Sortby{$status}{$key}}) {
-                            $result .=
-                                &Apache::loncommon::start_data_table_row().
-                                '<td><input type="checkbox" '.
-                                'name="selectedusers_forminput" value="'.
-                                $user.':'.$status.'" />'.
-                                $$memberinfo{$user}{'fullname'}.'</td>'.
-                                '<td>'.$$memberinfo{$user}{'uname'}.'</td>'.
-                                '<td>'.$$memberinfo{$user}{'udom'}.'</td>'.
-                                &Apache::loncommon::end_data_table_row();
-                        }
-                    }
-                    $result .= &Apache::loncommon::end_data_table();
-                }
-            }
-            $result .= '</td><td>&nbsp;&nbsp;</td>';
-        }
-        $result .= '</tr></table>';
-    }
-    return $result;
-}
-
-sub group_check_uncheck {
-    my $output = qq|
-<script type="text/javascript">
-function toggleAll(caller,action) {
-    var pattern = new RegExp(":"+caller+"\$");
-    if (typeof(document.compemail.selectedusers_forminput.length)=="undefined") {
-        if (document.compemail.selectedusers_forminput.value.match(pattern)) {
-            if (action == 'check') {
-                document.groupmail.selectedusers_forminput.checked = true;
-            } else {
-                document.groupmail.selectedusers_forminput.checked = false;
-            }
-        }
-    } else {
-        for (var i=0; i<document.compemail.selectedusers_forminput.length; i++) {
-            if (document.compemail.selectedusers_forminput[i].value.match(pattern)) {
-                if (action == 'check') {
-                    document.compemail.selectedusers_forminput[i].checked = true;
-                } else {
-                    document.compemail.selectedusers_forminput[i].checked = false;
-                }
-            }
-        }
-    }
-}
-</script>
-    |;
-}
-
-sub groupmail_header {
-    my ($action,$group,$cdom,$cnum) = @_;
-    my ($description,$refarg);
-    if (!$cdom || !$cnum) {
-        $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
-        $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
-    }
-    if (exists($env{'form.ref'})) {
-        $refarg = 'ref='.$env{'form.ref'};
-    }
-    if (!$group) {
-        $group = $env{'form.group'};
-    }
-    if ($group eq '') {
-        return  '';
-    } else {
-        my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
-        if (defined($curr_groups{$group})) {
-            my %groupinfo =
-                    &Apache::longroup::get_group_settings($curr_groups{$group});
-            $description = &unescape($groupinfo{'description'});
-        }
-    }
-    &Apache::lonhtmlcommon::clear_breadcrumbs();
-    if ($refarg) {
-        &Apache::lonhtmlcommon::add_breadcrumb
-            ({href=>"/adm/coursegroups",
-              text=>"Groups",
-              title=>"View course groups"});
-    }
-    &Apache::lonhtmlcommon::add_breadcrumb
-        ({href=>"/adm/$cdom/$cnum/$group/smppg?$refarg",
-          text=>"Group: $description",
-          title=>"Go to group's home page"},
-         {href=>"/adm/email?compose=group&amp;group=".
-                "$env{'form.group'}&amp;$refarg",
-          text=>"Send a Message in a Group",
-          title=>"Compose Group Email Message"},);
-    if ($action eq 'sending') {
-            &Apache::lonhtmlcommon::add_breadcrumb
-                         ({text=>"Messages being sent.",
-                           title=>"Messages sent"},);
-    }
-    my $groupheader = &Apache::loncommon::start_page('Group Email');
-    $groupheader .= &Apache::lonhtmlcommon::breadcrumbs
-                ('Group - '.$env{'form.group'}.' Email');
-    return $groupheader;
-}
-
-sub groupmail_sent {
-    my ($group,$cdom,$cnum) = @_;
-    my $refarg;
-    if (exists($env{'form.ref'})) {
-        $refarg = 'ref='.$env{'form.ref'};
-    }
-    my $output .= '<br /><br /><a href="/adm/email?compose=group&amp;group='.
-                  $group.'&amp;'.$refarg.'">'.
-                  &mt('Send another group email').'</a>'.'&nbsp;&nbsp;&nbsp;'.
-                  '<a href="/adm/'.$cdom.'/'.$cnum.'/'.$group.'/smppg?'.
-                  $refarg.'">'. &mt('Return to group page').'</a>';
-    return $output;
-}
-
 # ==================================================== Display Critical Message
 
 sub discrit {
@@ -507,7 +320,7 @@ $content{'sendername'}.':'.
     # Check to see if there were any messages.
     if ($result eq '') {
         $result = "<h2>".&mt('You have no critical messages.')."</h2>".
-	    '<a href="/adm/roles">'.&mt('Select a course').'</a><br />'.
+	    '<a href="/adm/roles">'.&mt('Select a course or group').'</a><br />'.
             '<a href="/adm/email">'.&mt('Communicate').'</a>';
     } else {
         $r->print($header);
@@ -640,7 +453,7 @@ sub disnew {
     my %lt=&Apache::lonlocal::texthash(
 				       'nm' => 'New Messages',
 				       'su' => 'Subject',
-                                       'co' => 'Course',
+                                       'co' => 'Course/Group',
 				       'da' => 'Date',
 				       'us' => 'Username',
 				       'op' => 'Open',
@@ -809,9 +622,9 @@ ENDDISHEADER
     }
     $r->print('</th><th>');
     if ($env{'form.sortedby'} eq "revcourse") {
-        $r->print('<a href = "?sortedby=course'.$fsqs.'">'.&mt('Course').'</a>');
+        $r->print('<a href = "?sortedby=course'.$fsqs.'">'.&mt('Course/Group').'</a>');
     } else {
-        $r->print('<a href = "?sortedby=revcourse'.$fsqs.'">'.&mt('Course').'</a>');
+        $r->print('<a href = "?sortedby=revcourse'.$fsqs.'">'.&mt('Course/Group').'</a>');
     }
     $r->print('</th><th>');
     if ($env{'form.sortedby'} eq "revstatus") {
@@ -896,14 +709,8 @@ ENDDISHEADER
 sub compout {
     my ($r,$forwarding,$replying,$broadcast,$replycrit,$folder,$dismode)=@_;
     my $suffix=&Apache::lonmsg::foldersuffix($folder);
-    my ($cdom,$cnum,$group,$refarg);
-    if (exists($env{'form.group'})) {
-        $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
-        $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
-        $group = $env{'form.group'};
-        my $action = 'composing';
-        $r->print(&groupmail_header($action,$group,$cdom,$cnum));
-    } elsif ($broadcast eq 'individual') {
+
+    if ($broadcast eq 'individual') {
 	&printheader($r,'/adm/email?compose=individual',
 	     'Send a Message');
     } elsif ($broadcast) {
@@ -995,34 +802,15 @@ sub compout {
 	}
     }
     my $citation=&displayresource(%content);
-    my ($can_grp_broadcast,$viewgrps,$editgrps);
     if ($env{'form.recdom'}) { $defdom=$env{'form.recdom'}; }
     if ($env{'form.text'}) { $dismsg=$env{'form.text'}; }
     if ($env{'form.subject'}) { $dissub=$env{'form.subject'}; }
     $r->print(
                 '<form action="/adm/email"  name="compemail" method="post"'.
                 ' enctype="multipart/form-data">'."\n".
-                '<input type="hidden" name="sendmail" value="on" />'."\n");
-    if ($broadcast eq 'group' && $env{'form.group'} ne '') {
-        $can_grp_broadcast = 
-                &Apache::lonnet::allowed('sgb',$env{'request.course.id'}.'/'.
-                                         $group);
-        $viewgrps = 
-               &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.
-               ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
-        $editgrps = 
-               &Apache::lonnet::allowed('mdg',$env{'request.course.id'}.
-               ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
-        if ($viewgrps || $editgrps || $can_grp_broadcast) {
-            $r->print(&disgroup($cdom,$cnum,$group,$viewgrps,$editgrps));
-        }
-    }
-    $r->print('<table>');
-    if (($broadcast eq 'group') && ($group ne '') && 
-        (!$can_grp_broadcast && !$viewgrps && !$editgrps)) {
-        $r->print(&recipient_input_row($cdom,%lt));
-    } 
-    if (($broadcast ne 'group') && ($broadcast ne 'upload')) {
+                '<input type="hidden" name="sendmail" value="on" />'."\n".
+                '<table>');
+    unless (($broadcast eq 'group') || ($broadcast eq 'upload')) {
 	if ($replying) {
 	    $r->print('<tr><td colspan="2">'.&mt('Replying to').' '.
 		      &Apache::loncommon::aboutmewrapper(
@@ -1033,7 +821,14 @@ sub compout {
 		      '<input type="hidden" name="recdomain" value="'.$content{'senderdomain'}.'" />'.
 		      '</td></tr>');
 	} else {
-            $r->print(&recipient_input_row($defdom,%lt));
+	    my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
+	    my $selectlink=&Apache::loncommon::selectstudent_link
+	    ('compemail','recuname','recdomain');
+	    $r->print(<<"ENDREC");
+<tr><td>$lt{'us'}:</td><td><input type="text" size="12" name="recuname" value="$env{'form.recname'}" /></td><td rowspan="2">$selectlink</td></tr>
+<tr><td>$lt{'do'}:</td>
+<td>$domform</td></tr>
+ENDREC
         }
     }
     my $latexHelp = Apache::loncommon::helpLatexCheatsheet();
@@ -1055,14 +850,6 @@ $disbase
 <input type="submit" name="cancel" value="$lt{'ca'}" /><hr />
 $citation
 ENDCOMP
-        if (exists($env{'form.ref'})) {
-            $r->print('<input type="hidden" name="ref" value="'.
-                      $env{'form.ref'}.'" />');
-        }
-        if (exists($env{'form.group'})) {
-            $r->print('<input type="hidden" name="group" value="'.
-                      $env{'form.group'}.'" />');
-        }
     } else { # $broadcast is 'upload'
 	$r->print(<<ENDUPLOAD);
 <input type="hidden" name="sendmode" value="upload" />
@@ -1092,10 +879,9 @@ $dispcrit
 ENDUPLOAD
     }
     if ($broadcast eq 'group') {
-       if ($group eq '') {
-           my $studentsel = &discourse();
-           $r->print($studentsel);
-       }
+       &discourse($r);
+       my $studentsel = &discourse();
+       $r->print($studentsel);
     }
     if ($env{'form.displayedcrit'}) {
 	$r->print('<input type="hidden" name="displayedcrit" value="true" />');
@@ -1107,20 +893,6 @@ ENDUPLOAD
 
 # ---------------------------------------------------- Display all face to face
 
-sub recipient_input_row {
-    my ($dom,%lt) = @_;
-    my $domform = &Apache::loncommon::select_dom_form($dom,'recdomain');
-    my $selectlink=
-      &Apache::loncommon::selectstudent_link('compemail','recuname',
-                                             'recdomain');
-    my $output = <<"ENDREC";
-<tr><td>$lt{'us'}:</td><td><input type="text" size="12" name="recuname" value="$env{'form.recname'}" /></td><td rowspan="2">$selectlink</td></tr>
-<tr><td>$lt{'do'}:</td>
-<td>$domform</td></tr>
-ENDREC
-    return $output;
-}
-
 sub retrieve_instructor_comments {
     my ($user,$domain)=@_;
     my $target=$env{'form.grade_target'};
@@ -1610,7 +1382,7 @@ sub build_block_table {
     my ($r,$startblock,$endblock,$setters) = @_;
     my %lt = &Apache::lonlocal::texthash(
         'cacb' => 'Currently active communication blocks',
-        'cour' => 'Course',
+        'cour' => 'Course/Group',
         'dura' => 'Duration',
         'blse' => 'Block set by'
     );
@@ -1790,12 +1562,13 @@ sub header {
     
     my $extra = &Apache::loncommon::studentbrowser_javascript();
     if ($baseurl) {
-	$extra .= "<base href=\"".&Apache::lonnet::absolute_url()."/$baseurl\" />";
+	$extra .= "<base href=\"http://$ENV{'SERVER_NAME'}/$baseurl\" />";
     }
     $r->print(&Apache::loncommon::start_page('Communication and Messages',
- 					$extra));
+					     $extra));
     $r->print(&Apache::lonhtmlcommon::breadcrumbs
-     		(($title?$title:'Communication and Messages')));
+	      (($title?$title:'Communication and Messages')));
+
 }
 
 # ---------------------------------------------------------------- Print header
@@ -1851,20 +1624,8 @@ sub sendoffmail {
     my $sendstatus='';
     my %specialmsg_status;
     my $numspecial = 0;
-    my ($cdom,$cnum,$group);
-    if (exists($env{'form.group'})) {
-        $group = $env{'form.group'};
-    }
-    if (exists($env{'request.course.id'})) {
-        $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
-        $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
-    }
     if ($env{'form.send'}) {
-        if ($group eq '') {
-	    &printheader($r,'','Messages being sent.');
-        } else {
-            $r->print(&groupmail_header('sending',$group));
-        }
+	&printheader($r,'','Messages being sent.');
 	$r->rflush();
 	my %content=();
 	undef %content;
@@ -1884,7 +1645,7 @@ sub sendoffmail {
 	}
 
 	my @to =
-	    &Apache::loncommon::get_env_multiple('form.selectedusers_forminput');
+	    &Apache::loncommon::get_env_multiple('form.selectedusers.forminput');
 	my $mode = $env{'form.sendmode'};
 
 	my %toaddr;
@@ -1989,6 +1750,8 @@ sub sendoffmail {
                 $subj_prefix = 'Broadcast.';
             }
             my ($specialmsgid,$specialresult);
+            my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+            my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
             my $course_str = &escape('['.$cnum.':'.$cdom.']');
 
             if ($numspecial) {
@@ -2044,9 +1807,6 @@ sub sendoffmail {
 	$r->print('<br /><span class="LC_success">'.&mt('Completed.').'</span>');
 	if ($env{'form.displayedcrit'}) {
 	    &discrit($r);
-        }
-        if ($group ne '') {
-            $r->print(&groupmail_sent($group,$cdom,$cnum)); 
 	} else {
 	    &Apache::loncommunicate::menu($r);
 	}
@@ -2073,7 +1833,7 @@ sub handler {
         ['display','replyto','forward','markread','markdel','markunread',
          'sendreply','compose','sendmail','critical','recname','recdom',
          'recordftf','sortedby','block','folder','startdis','interdis',
-	 'showcommentbaseurl','dismode','group','subject','text','ref']);
+	 'showcommentbaseurl','dismode','group','subject','text']);
     $sqs='&sortedby='.$env{'form.sortedby'};
 
 # ------------------------------------------------------ They checked for email
@@ -2241,15 +2001,15 @@ sub handler {
 	&sendoffmail($r,$folder);
 	if ($env{'form.storebasecomment'}) {
 	    &storecomment($r);
-        }
+	}
 	if (($env{'form.rsspost'}) && ($env{'request.course.id'})) {
-	        &Apache::lonrss::addentry($env{'course.'.$env{'request.course.id'}.'.num'},
+	    &Apache::lonrss::addentry($env{'course.'.$env{'request.course.id'}.'.num'},
 				      $env{'course.'.$env{'request.course.id'}.'.domain'},
 				      'Course_Announcements',
 				      $env{'form.subject'},
 				      $env{'form.message'},'/adm/communicate','public');
 	}
-	if ((!exists($env{'form.group'})) && (!$env{'form.displayedcrit'})) {
+	if (!$env{'form.displayedcrit'}) {
 	    &disall($r,($folder?$folder:$dismode));
 	}
     } elsif ($env{'form.newfolder'}) {
@@ -2279,3 +2039,9 @@ sub handler {
 
 __END__
 
+
+
+
+
+
+