[LON-CAPA-cvs] cvs: loncom /interface domainprefs.pm loncommon.pm lonerrorhandler.pm /metadata_database searchcat.pl

raeburn raeburn at source.lon-capa.org
Mon Aug 12 12:52:01 EDT 2013


raeburn		Mon Aug 12 16:52:01 2013 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm loncommon.pm lonerrorhandler.pm 
    /loncom/metadata_database	searchcat.pl 
  Log:
  - Domain Configuration (Contacts)
    - Enable/Disable e-mail sent to LON-CAPA when: 
      (a) error form is submitted
      (b) domain defaults (authentication type or language) are changed.
    - E-mail recipient can be specified when bi-nightly searchcat.pl detects
      situation where a student/employeeID is used for more than one user in 
      server's domain. 
  
  
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.202 loncom/interface/domainprefs.pm:1.203
--- loncom/interface/domainprefs.pm:1.202	Thu Aug  8 00:53:32 2013
+++ loncom/interface/domainprefs.pm	Mon Aug 12 16:51:57 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.202 2013/08/08 00:53:32 raeburn Exp $
+# $Id: domainprefs.pm,v 1.203 2013/08/12 16:51:57 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -526,7 +526,7 @@
     } elsif ($action eq 'contacts') {
         $output = &modify_contacts($dom,%domconfig);
     } elsif ($action eq 'defaults') {
-        $output = &modify_defaults($dom,$r);
+        $output = &modify_defaults($dom,$r,%domconfig);
     } elsif ($action eq 'scantron') {
         $output = &modify_scantron($r,$dom,$confname,%domconfig);
     } elsif ($action eq 'coursecategories') {
@@ -2309,7 +2309,7 @@
     my @contacts = ('adminemail','supportemail');
     my (%checked,%to,%otheremails,%bccemails);
     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
-                    'requestsmail','updatesmail');
+                    'requestsmail','updatesmail','idconflictsmail');
     foreach my $type (@mailings) {
         $otheremails{$type} = '';
     }
@@ -2346,21 +2346,21 @@
         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
         $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
+        $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
     }
     my ($titles,$short_titles) = &contact_titles();
     my $rownum = 0;
     my $css_class;
     foreach my $item (@contacts) {
-        $rownum ++;
         $css_class = $rownum%2?' class="LC_odd_row"':'';
         $datatable .= '<tr'.$css_class.'>'. 
                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   '</span></td><td class="LC_right_item">'.
                   '<input type="text" name="'.$item.'" value="'.
                   $to{$item}.'" /></td></tr>';
+        $rownum ++;
     }
     foreach my $type (@mailings) {
-        $rownum ++;
         $css_class = $rownum%2?' class="LC_odd_row"':'';
         $datatable .= '<tr'.$css_class.'>'.
                       '<td><span class="LC_nobreak">'.
@@ -2383,7 +2383,21 @@
                           'value="'.$bccemails{$type}.'"  />';
         }
         $datatable .= '</td></tr>'."\n";
+        $rownum ++;
     }
+    my %choices;
+    $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
+                                   &Apache::loncommon::modal_link('http://loncapa.org/core.html',
+                                   &mt('LON-CAPA core group - MSU'),600,500));
+    $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
+                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
+                                    &mt('LON-CAPA core group - MSU'),600,500));
+    my @toggles = ('reporterrors','reportupdates');
+    my %defaultchecked = ('reporterrors'  => 'on',
+                          'reportupdates' => 'on');
+    (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
+                                               \%choices,$rownum);
+    $datatable .= $reports;
     $$rowtotal += $rownum;
     return $datatable;
 }
@@ -3301,6 +3315,7 @@
                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
                    'requestsmail' => 'E-mail from course requests requiring approval',
                    'updatesmail'  => 'E-mail from nightly check of LON-CAPA module integrity/updates',
+                   'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
                  );
     my %short_titles = &Apache::lonlocal::texthash (
                            adminemail   => 'Admin E-mail address',
@@ -6672,7 +6687,8 @@
     my (%others,%to,%bcc);
     my @contacts = ('supportemail','adminemail');
     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
-                    'requestsmail','updatesmail');
+                    'requestsmail','updatesmail','idconflictsmail');
+    my @toggles = ('reporterrors','reportupdates');
     foreach my $type (@mailings) {
         @{$newsetting{$type}} = 
             &Apache::loncommon::get_env_multiple('form.'.$type);
@@ -6694,6 +6710,11 @@
         $to{$item} = $env{'form.'.$item};
         $contacts_hash{'contacts'}{$item} = $to{$item};
     }
+    foreach my $item (@toggles) {
+        if ($env{'form.'.$item} =~ /^(0|1)$/) {
+            $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
+        }
+    }
     if (keys(%currsetting) > 0) {
         foreach my $item (@contacts) {
             if ($to{$item} ne $currsetting{$item}) {
@@ -6732,7 +6753,7 @@
         foreach my $item (@contacts) {
            if ($to{$item} ne $default{$item}) {
               $changes{$item} = 1;
-           } 
+           }
         }
         foreach my $type (@mailings) {
             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
@@ -6749,6 +6770,14 @@
             }
         }
     }
+    foreach my $item (@toggles) {
+        if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
+            $changes{$item} = 1;
+        } elsif ((!$env{'form.'.$item}) &&
+                 (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
+            $changes{$item} = 1;
+        }
+    }
     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                                              $dom);
     if ($putresult eq 'ok') {
@@ -6783,6 +6812,23 @@
                     $resulttext .= '</li>';
                 }
             }
+            my @offon = ('off','on');
+            if ($changes{'reporterrors'}) {
+                $resulttext .= '<li>'.
+                               &mt('E-mail error reports to [_1] set to "'.
+                                   $offon[$env{'form.reporterrors'}].'".',
+                                   &Apache::loncommon::modal_link('http://loncapa.org/core.html',
+                                       &mt('LON-CAPA core group - MSU'),600,500)).
+                               '</li>';
+            }
+            if ($changes{'reportupdates'}) {
+                $resulttext .= '<li>'.
+                                &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
+                                    $offon[$env{'form.reportupdates'}].'".',
+                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
+                                        &mt('LON-CAPA core group - MSU'),600,500)).
+                                '</li>';
+            }
             $resulttext .= '</ul>';
         } else {
             $resulttext = &mt('No changes made to contact information');
@@ -7377,7 +7423,7 @@
 }
 
 sub modify_defaults {
-    my ($dom,$r) = @_;
+    my ($dom,$r,%domconfig) = @_;
     my ($resulttext,$mailmsgtxt,%newvalues,%changes, at errors);
     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
@@ -7463,8 +7509,17 @@
             my $cachetime = 24*60*60;
             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
-                my $sysmail = $r->dir_config('lonSysEMail');
-                &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
+                my $notify = 1;
+                if (ref($domconfig{'contacts'}) eq 'HASH') {
+                    if ($domconfig{'contacts'}{'reportupdates'} == 0) {
+                        $notify = 0;
+                    }
+                }
+                if ($notify) {
+                    &Apache::lonmsg::sendemail('installrecord at loncapa.org',
+                                               "LON-CAPA Domain Settings Change - $dom",
+                                               $mailmsgtext);
+                }
             }
         } else {
             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1143 loncom/interface/loncommon.pm:1.1144
--- loncom/interface/loncommon.pm:1.1143	Wed Aug  7 00:03:25 2013
+++ loncom/interface/loncommon.pm	Mon Aug 12 16:51:57 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1143 2013/08/07 00:03:25 raeburn Exp $
+# $Id: loncommon.pm,v 1.1144 2013/08/12 16:51:57 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -13106,16 +13106,20 @@
 
 =item * &build_recipient_list()
 
-Build recipient lists for five types of e-mail:
+Build recipient lists for following types of e-mail:
 (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
-(d) Help requests, (e) Course requests needing approval,  generated by
-lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
-loncoursequeueadmin.pm respectively.
+(d) Help requests, (e) Course requests needing approval, (f) loncapa
+module change checking, student/employee ID conflict checks, as
+generated by lonerrorhandler.pm, CHECKRPMS, loncron,
+lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
 
 Inputs:
 defmail (scalar - email address of default recipient), 
-mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
+mailing type (scalar: errormail, packagesmail, helpdeskmail,
+requestsmail, updatesmail, or idconflictsmail).
+
 defdom (domain for which to retrieve configuration settings),
+
 origmail (scalar - email address of recipient from loncapa.conf, 
 i.e., predates configuration by DC via domainprefs.pm 
 
Index: loncom/interface/lonerrorhandler.pm
diff -u loncom/interface/lonerrorhandler.pm:1.23 loncom/interface/lonerrorhandler.pm:1.24
--- loncom/interface/lonerrorhandler.pm:1.23	Thu Feb 12 21:15:47 2009
+++ loncom/interface/lonerrorhandler.pm	Mon Aug 12 16:51:58 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Internal Server Error Handler
 #
-# $Id: lonerrorhandler.pm,v 1.23 2009/02/12 21:15:47 schafran Exp $
+# $Id: lonerrorhandler.pm,v 1.24 2013/08/12 16:51:58 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -83,8 +83,18 @@
 $lt{'env'}:
 $env{'form.environment'}
 ENDMESSAGE
-        my $sysmail = $r->dir_config('lonSysEMail');
         my $defdom = $r->dir_config('lonDefDomain');
+        my $sysmail;
+        my $notify = 1;
+        my %domconfig = &Apache::lonnet::get_dom('configuration',['contacts']);
+        if (ref($domconfig{'contacts'}) eq 'HASH') {
+            if ($domconfig{'contacts'}{'reporterrors'} == 0) {
+                $notify = 0;
+            }
+        }
+        if ($notify) {
+            $sysmail = 'errorrecord at loncapa.org';
+        }
         my $origmail = $r->dir_config('lonAdmEMail');
         my $recipients = &Apache::loncommon::build_recipient_list($sysmail,
                                              'errormail',$defdom,$origmail);
Index: loncom/metadata_database/searchcat.pl
diff -u loncom/metadata_database/searchcat.pl:1.79 loncom/metadata_database/searchcat.pl:1.80
--- loncom/metadata_database/searchcat.pl:1.79	Thu Jul 25 19:11:10 2013
+++ loncom/metadata_database/searchcat.pl	Mon Aug 12 16:52:00 2013
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # searchcat.pl "Search Catalog" batch script
 #
-# $Id: searchcat.pl,v 1.79 2013/07/25 19:11:10 raeburn Exp $
+# $Id: searchcat.pl,v 1.80 2013/08/12 16:52:00 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -74,6 +74,7 @@
 use HTML::TokeParser;
 use GDBM_File;
 use POSIX qw(strftime mktime);
+use Mail::Send;
 
 use Apache::lonnet();
 
@@ -209,6 +210,7 @@
     if ($oneuser) {
         @homeusers=($oneuser);
     }
+
     #
     # Loop through the users
     foreach my $user (@homeusers) {
@@ -315,9 +317,6 @@
                 if (exists($idstoadd{$addid})) {
                     push(@{$duplicates{$addid}},$uname);
                 } else {
-                    if ((exists($names_by_id{$addid})) && ($names_by_id{$addid} ne $uname)) {
-                        &log(0,"In ids.db ($dom) $addid => $names_by_id{$addid} will be replaced by $addid => $uname");
-                    }
                     $idstoadd{$addid} = $uname;
                 }
             }
@@ -344,13 +343,47 @@
             }
         }
         if (keys(%idstoadd) > 0) {
-            my $putresult = &Apache::lonnet::put_dom('ids',\%idstoadd,$dom,$hostid);
-            if ($putresult eq 'ok') {
-                foreach my $id (sort(keys(%idstoadd))) {
-                    &log(0,"Record added to ids.db for $dom -- $id => ".$idstoadd{$id});
+            my $idmessage = '';
+            my %newids;
+            foreach my $addid (sort(keys(%idstoadd))) {
+                if ((exists($names_by_id{$addid})) && ($names_by_id{$addid} ne $idstoadd{$addid})  && !($idstodelete{$addid})) {
+                    &log(0,"Two usernames associated with a single ID $addid in domain: $dom: $names_by_id{$addid} (current) and $idstoadd{$addid}\n");
+                    $idmessage .= "$addid,$names_by_id{$addid},$idstoadd{$addid}\n";
+                } else {
+                    $newids{$addid} = $idstoadd{$addid};
+                }
+            }
+            if (keys(%newids) > 0) {
+                my $putresult = &Apache::lonnet::put_dom('ids',\%idstoadd,$dom,$hostid);
+                if ($putresult eq 'ok') {
+                    foreach my $id (sort(keys(%idstoadd))) {
+                        &log(0,"Record added to ids.db for $dom -- $id => ".$idstoadd{$id});
+                    }
+                } else {
+                    &log(0,"Error: '$putresult' occurred when attempting to add records to ids.db for $dom"); 
+                }
+            }
+            if ($idmessage) {
+                my $to = &Apache::loncommon::build_recipient_list(undef,'idconflictsmail',$dom);
+                if ($to ne '') {
+                    my $msg = new Mail::Send;
+                    $msg->to($to);
+                    $msg->subject('LON-CAPA studentIDs conflict');
+                    my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
+                    my $hostname = &Apache::lonnet::hostname($lonhost);
+                    my $replytoaddress = 'do-not-reply@'.$hostname;
+                    $msg->add('Reply-to',$replytoaddress);
+                    $msg->add('From',"www@$hostname");
+                    $msg->add('Content-type','text/plain; charset=UTF-8');
+                    if (my $fh = $msg->open()) {
+                        print $fh 
+                            'The following IDs are used for more than one user in your domain:'."\n".
+                            'Each row contains: Student/Employee ID, Current username in ids.db file, '.
+                            'Additional username'."\n\n".
+                            $idmessage;
+                        $fh->close;
+                    }
                 }
-            } else {
-                &log(0,"Error: '$putresult' occurred when attempting to add records to ids.db for $dom"); 
             }
         }
         if (keys(%duplicates) > 0) {


More information about the LON-CAPA-cvs mailing list