[LON-CAPA-cvs] cvs: modules /raeburn/register register.pm

raeburn raeburn@source.lon-capa.org
Fri, 08 Apr 2011 22:22:04 -0000


This is a MIME encoded message

--raeburn1302301324
Content-Type: text/plain

raeburn		Fri Apr  8 22:22:04 2011 EDT

  Modified files:              
    /modules/raeburn/register	register.pm 
  Log:
  - LON-CAPA Events Registration
    - Support for differential fees for registrants from hosting institution
    - SSL for s10
    - Routines to determine status of MSU registrants (i.e., faculty or staff).
    - Dropdown lists for choosing domains including dynamically populated domain
      lists.
  
  
--raeburn1302301324
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20110408222204.txt"

Index: modules/raeburn/register/register.pm
diff -u modules/raeburn/register/register.pm:1.17 modules/raeburn/register/register.pm:1.18
--- modules/raeburn/register/register.pm:1.17	Sat Apr 19 13:52:36 2008
+++ modules/raeburn/register/register.pm	Fri Apr  8 22:22:04 2011
@@ -3,14 +3,18 @@
 # Session-based registration for conferences/workshops
 # Data read/written from MySQL database.
 #
-# $Id: register.pm,v 1.17 2008/04/19 13:52:36 raeburn Exp $
+# $Id: register.pm,v 1.18 2011/04/08 22:22:04 raeburn Exp $
 #
 # Stuart P Raeburn
 #
 ##########################################################
 package Apache::LON::register;
 
-use strict;
+BEGIN {
+  use strict;
+  $ENV{'SYBASE'} = '/usr/local/freetds';
+}
+
 use Apache::RequestRec();
 use Apache::Const qw(OK SERVER_ERROR);
 use HTML::Entities;
@@ -23,6 +27,7 @@
 use Time::Local;
 use Date::Manip;
 use POSIX "floor";
+use Net::LDAP;
 
 sub handler {
     my $r = shift;
@@ -50,6 +55,7 @@
     if ($user eq '') {
         return SERVER_ERROR
     }
+
     my $quoted_user = $dbh->quote( $user );
     my %params = ();
     my %qry_items = ();
@@ -87,7 +93,7 @@
     my $domain = $params{'domain'};
     my %feeinfo;
     my @consortium;
-    my ($page,$year,$event,$portal,$returnpage,$event_id,$webpath,$year_quoted,$event_quoted,$fees,$condmail,$feesmsg);
+    my ($page,$year,$event,$portal,$returnpage,$event_id,$webpath,$year_quoted,$event_quoted,$fees,$condmail,$feesmsg,$localfeesmsg);
     if (exists $params{'return'}) {
         $returnpage = $params{'return'};
     }
@@ -118,7 +124,7 @@
             $sponsorinfo{$name}{orientation} = $orientation;
         }
         $sth->finish;
-        ($event_id,$webpath,$fees,$condmail,$feesmsg) = $dbh->selectrow_array("SELECT event_id,webpath,fees,condmail,feesmsg FROM event_config WHERE year=$year_quoted AND event=$event_quoted");
+        ($event_id,$webpath,$fees,$condmail,$feesmsg,$localfeesmsg) = $dbh->selectrow_array("SELECT event_id,webpath,fees,condmail,feesmsg,localfeesmsg FROM event_config WHERE year=$year_quoted AND event=$event_quoted");
         $portal = $webpath.$returnpage;
         if ($event_id eq '') {
             &invalid_event($r,$dbh,$page,$year,$event,$portal,$returnpage,$exitpage,\@sponsors,\%sponsorinfo,$domain);
@@ -126,9 +132,9 @@
         } else {
 # check for fees
             if ($fees) {
-                $sth = $dbh->prepare("SELECT iid,description,cost,required,longdesc,type,waiver,infotext,displayorder,dependency FROM products WHERE event_id = '$event_id'");
+                $sth = $dbh->prepare("SELECT iid,description,cost,required,longdesc,type,waiver,infotext,displayorder,dependency,displayoptional,localdiscount FROM products WHERE event_id = '$event_id'");
                 $sth->execute;
-                while ( my ($iid,$desc,$cost,$reqd,$longdesc,$type,$waiver,$infotext,$displayorder,$dependency) = $sth->fetchrow_array) {
+                while ( my ($iid,$desc,$cost,$reqd,$longdesc,$type,$waiver,$infotext,$displayorder,$dependency,$displayoptional,$localdiscount) = $sth->fetchrow_array) {
                     $feeinfo{$iid}{desc} = $desc;
                     $feeinfo{$iid}{cost} = $cost;
                     $feeinfo{$iid}{reqd} = $reqd;
@@ -138,6 +144,8 @@
                     $feeinfo{$iid}{infotext} = $infotext;
                     $feeinfo{$iid}{displayorder} = $displayorder;
                     $feeinfo{$iid}{dependency} = $dependency;
+                    $feeinfo{$iid}{displayoptional} = $displayoptional;
+                    $feeinfo{$iid}{localdiscount} = $localdiscount;
                 }
                 $sth->finish;
                 $sth = $dbh->prepare("SELECT user_id FROM consortium");
@@ -180,11 +188,37 @@
             $sth->execute();
             while (my ($name,$type,$multivalued,$contents,$v_position,$h_position,$required,$title,$rowtitle,$preamble,$preamblerow,$text_position,$alignment,$size,$tablename) = $sth->fetchrow_array) {
                 $form_elements{$name}{'multivalued'} = $multivalued;
-                $form_elements{$name}{'contents'} = $contents;
                 $form_elements{$name}{'v_position'} = $v_position;
                 $form_elements{$name}{'h_position'} = $h_position;
                 $form_elements{$name}{'required'} = $required;
                 $form_elements{$name}{'title'} = $title;
+               
+                if ($type eq 'alldomslong') {
+                    $type = 'selectbox';
+                    $contents = 'No domain=No domain&other=Other domain&';
+                    my $dominfo;
+                    if (&get_domains(\$dominfo,'long') eq 'ok') {
+                        my @entries = split('___&&___',$dominfo);
+                        foreach my $entry (@entries) {
+                            my ($dom,$desc) = map { &unescape($_); } (split(':',$entry));
+                            $desc =~ s/\s*&\s*/ and /g;
+                            $contents .= $dom.'='.$desc.'&';
+                        }
+                    }
+                    $contents =~ s/\&$//;
+                } elsif ($type eq 'alldoms') {
+                    $type = 'selectbox';
+                    $contents = '';
+                    my $dominfo;
+                    if (&get_domains(\$dominfo) eq 'ok') {
+                        my @domains = split(',',$dominfo);
+                        foreach my $dom (@domains) {
+                            $contents .= $dom.'='.$dom.'&';
+                        }
+                    }
+                    $contents =~ s/\&$//;
+                }
+                $form_elements{$name}{'contents'} = $contents;
                 $form_elements{$name}{'type'} = $type;
                 $form_elements{$name}{'rowtitle'} = $rowtitle;
                 $form_elements{$name}{'preamble'} = $preamble;
@@ -218,7 +252,7 @@
         return OK;
     }
     my $contact_email = "helpdesk\@lon-capa.org";
-    my $contact_name = "LON-CAPA support team";
+    my $contact_name = "MSU LON-CAPA group";
 
 # figure out what page we're on and where we're heading.
     $page = $params{'page'};
@@ -230,8 +264,9 @@
     } elsif ($current_page == 2) {
         &display_two($r,$event,$year,$event_id,\%params,$user,$domain,$portal,$returnpage,$exitpage,\%items,\@info,\@workshop,$dbh,$current_page,$contact_email,$contact_name,\%form_elements,\@rowitems,\@rowtitles,\@sponsors,\%sponsorinfo,$fees,\%feeinfo,\@consortium,$condmail);
     } else {
-        &display_one($r,$event_id,\%params,$user,\$domain,$portal,$returnpage,$exitpage,\%items,\@info,\@workshop,$dbh,$current_page,$contact_email,$contact_name,\%form_elements,\@rowitems,\@rowtitles,\@sponsors,\%sponsorinfo,$fees,\%feeinfo,\@consortium,$feesmsg);
+        &display_one($r,$event_id,\%params,$user,\$domain,$portal,$returnpage,$exitpage,\%items,\@info,\@workshop,$dbh,$current_page,$contact_email,$contact_name,\%form_elements,\@rowitems,\@rowtitles,\@sponsors,\%sponsorinfo,$fees,\%feeinfo,\@consortium,$feesmsg,$localfeesmsg);
     }
+    $dbh->disconnect;
     return OK;
 }
 
@@ -309,7 +344,7 @@
 }
 
 sub display_one() {
-    my ($r,$event_id,$params,$user,$domain,$portal,$returnpage,$exitpage,$items,$info,$workshop,$dbh,$page,$contact_email,$contact_name,$form_elements,$rowitems,$rowtitles,$sponsors,$sponsorinfo,$fees,$feeinfo,$consortium,$feesmsg) = @_;
+    my ($r,$event_id,$params,$user,$domain,$portal,$returnpage,$exitpage,$items,$info,$workshop,$dbh,$page,$contact_email,$contact_name,$form_elements,$rowitems,$rowtitles,$sponsors,$sponsorinfo,$fees,$feeinfo,$consortium,$feesmsg,$localfeesmsg) = @_;
     my $year = $$params{'year'};
     my $event = $$params{'event'};
     my $quoted_user = $dbh->quote( $user );
@@ -383,17 +418,17 @@
             $curr{'attendancedays'} = '"'.$curr_attendancedays[0].'"';
         }
         if (@curr_attendancedays > 0) {
-            my %check_ok;
-            $statement = "SELECT iid FROM products WHERE event_id = '$event_id' AND registration = 'Y'";
+            my (%check_ok,%regtype);
+            $statement = "SELECT iid,description FROM products WHERE event_id = '$event_id' AND registration = 'Y'";
             my $sth = $dbh->prepare($statement);
             $sth->execute();
-            while (my $iid =  $sth->fetchrow_array()) {
-                $check_ok{$iid} = &check_conditions($dbh,$iid,$event_id,$quoted_user);
+            while (my ($iid,$desc) =  $sth->fetchrow_array()) {
+                $check_ok{$iid} = &check_conditions($dbh,$iid,$event_id,$quoted_user);               $regtype{$iid} = $desc;
             }
             $sth->finish;
             foreach my $iid (keys(%check_ok)) {
                 if ($check_ok{$iid}) {
-                    $curr{'registration'} = 'Y';
+                    $curr{$regtype{$iid}} = 'Y';
                 }
             }
         }
@@ -479,7 +514,7 @@
                 } elsif ($curr{$$feeinfo{$iid}{desc}} eq 'Y') {
                     if ($$feeinfo{$iid}{'type'} eq 'accomm') {
                         my $quoted_type = $dbh->quote( $$feeinfo{$iid}{desc} );
-                        my $nights = $dbh->selectrow_array("SELECT nights FROM event_accommodation WHERE (user_id = $quoted_user AND $event_id = '$event_id' AND type = $quoted_type)"); 
+                        my $nights = $dbh->selectrow_array("SELECT nights FROM event_accommodation WHERE (user_id = $quoted_user AND event_id = '$event_id' AND type = $quoted_type)");
                         $total{$iid} = $nights;
                     } elsif ($$feeinfo{$iid}{'type'} eq 'conditional') {
                         my $check_ok = &check_conditions($dbh,$iid,$event_id,$quoted_user);
@@ -500,9 +535,12 @@
                 }
             }
         }
+        my $islocal = &is_local($user,$event_id);
         foreach my $iid (keys(%balance)) {
             if (($$feeinfo{$iid}{'waiver'} eq 'Y') && (grep/^\Q$user\E$/,@{$consortium})) {
                 $credit{$iid} = $balance{$iid};
+            } elsif (($$feeinfo{$iid}{'waiver'} eq 'Y') && ($islocal)) {
+                $credit{$iid} = $balance{$iid} - ($total{$iid}*($$feeinfo{$iid}{'cost'}-$$feeinfo{$iid}{'localdiscount'}));
             } else {
                 $credit{$iid} = $balance{$iid} - ($total{$iid} * $$feeinfo{$iid}{'cost'});
             }
@@ -560,7 +598,7 @@
         $regopen = &UnixDate($registeropen, "%s");
         $opendate = localtime($regopen);
         if ($now < $regopen) {
-            if ((!(&authorized($dbh,$quoted_user,$event_id))) && ($user ne 'raeburn:msu')) {
+            if (!(&authorized($dbh,$quoted_user,$event_id))) {
                 $regaccess = 'future';
             }
         }
@@ -657,7 +695,7 @@
     }
 
 # build function to verify form completion
-    if ($regaccess eq 'current' || $regaccess eq 'future') { 
+    if ($regaccess eq 'current' || $regaccess eq 'future' || $status eq 'enroll') {
         $verify_func = qq|
 function validForm(caller) {
   var checkok = 1
@@ -834,7 +872,7 @@
             $r->print("<b>Use this form to reactivate your cancelled registration.</b><br />");
             if ($fees) {
                 if (keys(%{$feeinfo}) > 0) {
-                    $r->print(&feedisplay($feeinfo,$feesmsg));
+                    $r->print(&feedisplay($feeinfo,$feesmsg,$localfeesmsg,$user,$event_id));
                     $r->print(&refund_info($endcredit,$now).'<br />');
                 }
             }
@@ -849,7 +887,7 @@
             $r->print("<b>Please submit your registration for the $year LON-CAPA $event.</b>");
             if ($fees) {
                 if (keys(%{$feeinfo}) > 0) {
-                    $r->print(&feedisplay($feeinfo,$feesmsg));
+                    $r->print(&feedisplay($feeinfo,$feesmsg,$localfeesmsg,$user,$event_id));
                     $r->print(&refund_info($endcredit,$now).'<br />');
                 }
             }
@@ -969,19 +1007,22 @@
                    <td align="'.$$form_elements{$$rowitems[$i][$j]}{alignment}.'">'
                 );
                 if (@{$$rowitems[$i]} > 1) {
-                    $r->print($$form_elements{$$rowitems[$i][$j]}{title});
-                    if ($$form_elements{$$rowitems[$i][$j]}{text_position} eq 'above') {
-                        $r->print('<br />');
-                    } else {
-                        if ($$form_elements{$$rowitems[$i][$j]}{title} ne '') {
-                            $r->print(':&nbsp;');
+                    if ($$form_elements{$$rowitems[$i][$j]}{type} ne 'hidden') {
+                        $r->print($$form_elements{$$rowitems[$i][$j]}{title});
+                        if ($$form_elements{$$rowitems[$i][$j]}{text_position} eq 'above') {
+                            $r->print('<br />');
+                        } else {
+                            if ($$form_elements{$$rowitems[$i][$j]}{title} ne '') { 
+                                $r->print(':&nbsp;');
+                            }
                         }
                     }
                 }
             }
             if ($$form_elements{$$rowitems[$i][$j]}{type} eq 'hidden') {
                  $r->print('<input type="hidden" name="'.$$rowitems[$i][$j].'" value="'.$$form_elements{$$rowitems[$i][$j]}{contents}.'">');
-            } elsif ($$form_elements{$$rowitems[$i][$j]}{type} eq 'textbox') {                $r->print('<input type="text" size="'.$$form_elements{$$rowitems[$i][$j]}{size}.'" name="'.$$rowitems[$i][$j].'" value="'.$userinfo->{$$rowitems[$i][$j]}.'">');
+            } elsif ($$form_elements{$$rowitems[$i][$j]}{type} eq 'textbox') {
+                $r->print('<input type="text" size="'.$$form_elements{$$rowitems[$i][$j]}{size}.'" name="'.$$rowitems[$i][$j].'" value="'.$userinfo->{$$rowitems[$i][$j]}.'">');
             } elsif ($$form_elements{$$rowitems[$i][$j]}{type} eq 'radio') {
                 my @items = split/\&/,$$form_elements{$$rowitems[$i][$j]}{contents};
                 $r->print('<nobr>');
@@ -1114,9 +1155,9 @@
 # Get fee information
     my %feehash;
     if ($fees) {
-        $sth = $dbh->prepare("SELECT iid,description,cost,required,longdesc,type,waiver,infotext,dependency FROM products WHERE event_id = '$event_id'");
+        $sth = $dbh->prepare("SELECT iid,description,cost,required,longdesc,type,waiver,infotext,dependency,localdiscount FROM products WHERE event_id = '$event_id'");
         $sth->execute;
-        while (my ($iid,$desc,$cost,$required,$longdesc,$type,$waiver,$infotext,$dependency)=$sth->fetchrow_array) {
+        while (my ($iid,$desc,$cost,$required,$longdesc,$type,$waiver,$infotext,$dependency,$localdiscount)=$sth->fetchrow_array) {
             $feehash{$desc}{'iid'} = $iid;
             $feehash{$desc}{'cost'} = $cost;
             $feehash{$desc}{'reqd'} = $required;
@@ -1125,6 +1166,7 @@
             $feehash{$desc}{'waiver'} = $waiver;
             $feehash{$desc}{'infotext'} = $infotext;
             $feehash{$desc}{'dependency'} = $dependency;
+            $feehash{$desc}{'localdiscount'} = $localdiscount;
         }
         $sth->finish;
     }
@@ -1510,7 +1552,19 @@
         if ($finaldispdat{'attendancedays'} eq '') {
             $finaldispdat{'attendancedays'} = 'None';
         } else {
-            $finaldispdat{'registration'} = 'Y';
+            my (%check_ok,%regtype);
+            $statement = "SELECT iid,description FROM products WHERE event_id = '$event_id' AND registration = 'Y'";
+            my $sth = $dbh->prepare($statement);
+            $sth->execute();
+            while (my ($iid,$desc) =  $sth->fetchrow_array()) {
+                $check_ok{$iid} = &check_conditions($dbh,$iid,$event_id,$quoted_user);               $regtype{$iid} = $desc;
+            }
+            $sth->finish;
+            foreach my $iid (keys(%check_ok)) {
+                if ($check_ok{$iid}) {
+                    $finaldispdat{$regtype{$iid}} = 'Y';
+                }
+            }
         }
     } else {
         $finaldispdat{'attendancedays'} = 'None';
@@ -1538,8 +1592,10 @@
             for (my $i=0; $i<@{$rowitems}; $i++) {
                 my $rowinfo;
                 foreach (@{$$rowitems[$i]}) {
-                    if ($finaldispdat{$_} ne '') {
-                        $rowinfo .= "$finaldispdat{$_} ";
+                    if ($$form_elements{$_}{'type'} ne 'hidden') {
+                        if ($finaldispdat{$_} ne '') {
+                            $rowinfo .= "$finaldispdat{$_} ";
+                        }
                     }
                 }
                 if ($rowinfo ne '') {
@@ -1586,6 +1642,7 @@
             }
         }
         $sth->finish;
+        my $islocal = &is_local($user,$event_id);
         foreach my $key (keys(%feehash)) {
             if (ref($feehash{$key}) eq 'HASH') {
                 if ($feehash{$key}{'dependency'} ne '') {
@@ -1593,7 +1650,6 @@
                         $finaldispdat{$key} = 'Y';
                     }
                 }
-
                 if (($feehash{$key}{reqd} eq 'Y') || ($finaldispdat{$key} eq 'Y')) {
                     if ($currstatus eq 'enroll') {
                         if ($feehash{$key}{'type'} eq 'accomm') {
@@ -1610,6 +1666,8 @@
                         }
                         if (($feehash{$key}{'waiver'} eq 'Y') && (grep/^\Q$user\E$/,@{$consortium})) {
                             $costs{$key} = 0;
+                        } elsif (($feehash{$key}{'waiver'} eq 'Y') && ($islocal)) {
+                            $costs{$key} = ($feehash{$key}{'cost'}-$feehash{$key}{'localdiscount'}) * $quantities{$key};
                         } else {
                             $costs{$key} = $feehash{$key}{'cost'} * $quantities{$key};
                         }
@@ -1705,7 +1763,7 @@
                  }
              }
          }
-         $requestmail .= "MSU LON-CAPA support team\n".
+         $requestmail .= "MSU LON-CAPA group\n".
     "$contact_email\n";
         if (open(MAIL, "|/usr/lib/sendmail -oi -t -odb")) {
             print MAIL $requestmail;
@@ -1911,8 +1969,9 @@
                 }
                 my $protocol = ($ENV{'SERVER_PORT'} == 443?'https://':'http://');
                 my $redirect = 'year='.$year.'&event='.$enc_event;
-                my $webcreditform = &webcredit($paynum,$order,$wid,\%ccard,\%total,                                               \%feehash,\%finaldispdat,\%costs,
-                                               \%quantities,$redirect);
+                my $webcreditform = &webcredit($paynum,$order,$wid,\%ccard,\%total,
+                                               \%feehash,\%finaldispdat,\%costs,
+                                               \%quantities,$redirect,$user);
                 $r->print('<br /><br />'.$webcreditform);
             }
         }
@@ -2079,7 +2138,7 @@
 #        $output = ' Any changes made to registration/dorm accommodation reservations which result in a refund will be credited to the card originally used for payment.';
     } elsif ($endcredit) {
         if ($endcredit > $now) {
-            $output = ' Any changes made by '.localtime($endcredit).' to registration which  result in a refund will be credited to the card originally used for payment.  No refunds will be processed for changes made after this date.';
+            $output = ' Any changes made to registration by '.localtime($endcredit).' EDT which result in a refund will be credited to the card originally used for payment.  No refunds will be processed for changes made after this date.';
         } else {
             $output = ' The deadline for refunds has passed.  Although you may make changes to your registration, refunds of prior payment(s) will not be made.';
         }
@@ -2089,7 +2148,7 @@
 
 
 sub feedisplay {
-    my ($feeinfo,$feesmsg) = @_;
+    my ($feeinfo,$feesmsg,$localfeesmsg,$user,$event_id) = @_;
     my $output = "<br />After submitting this form you will be directed to MSU's secure payment site to provide your credit card details, so the appropriate registration fee can be collected:<br />";
     if (keys(%{$feeinfo}) > 0) {
         my @products;
@@ -2097,9 +2156,9 @@
         foreach my $item (keys(%{$feeinfo})) {
             $products[$$feeinfo{$item}{'displayorder'}-1] = $item;
         }
-        foreach my $item (sort { $a <=> $b } @products) {  
+        foreach my $item (@products) {
             $output .= '<li>';
-            if ($$feeinfo{$item}{reqd} eq 'N') {
+            if (($$feeinfo{$item}{reqd} eq 'N') && ($$feeinfo{$item}{displayoptional} eq 'Y')) {
                 $output .= 'optional ';
             }
             if ($$feeinfo{$item}{'infotext'} eq '') {
@@ -2116,13 +2175,18 @@
         if ($feesmsg ne '') {
             $output .= "<p>$feesmsg</p>";
         }
+        if ($localfeesmsg ne '') {
+            if (&is_local($user,$event_id)) {
+                $output .= "<p>$localfeesmsg</p>";
+            }
+        }
     }
     return $output;
 }
 
 sub webcredit {
     my ($paynum,$order,$wid,$ccard,$total,$feehash,$finaldat,$costs,$quantities,
-        $redirect) = @_;
+        $redirect,$user) = @_;
     my %sort_by_id;
     $order = sprintf("%.2f",$order);
     my $checksum1 = (($order*300)+1)%307;
@@ -2134,8 +2198,9 @@
     my $citystate = $finaldat->{'citystate'};
     $citystate =~ s/\s+$//;
     my ($city,$state) = ($citystate =~ /^(.+)\s+([^\s]+)$/);
+    my $action = 'https://payments.msu.edu/process/';
     my $output .= <<END_A;
-<form name="webcredit" action="https://payments.msu.edu/process/" method="post">
+<form name="webcredit" action="$action" method="post">
 <input type="hidden" name="Identifier" Value="32546LON">
 <input type="hidden" name="Version" Value="3.2">
 <input type="hidden" name="Order_Comment" value="$redirect">
@@ -2444,7 +2509,7 @@
 
 sub getnames {
     my ($domain,$username,$userinfo) = @_;
-    my $URL = "http://s10.lite.msu.edu/cgi-bin/check_auth.pl";
+    my $URL = "https://s10.lite.msu.edu/cgi-bin/check_auth.pl";
     my $request = HTTP::Request->new(POST => $URL);
     $request->content_type('application/x-www-form-urlencoded');
     $request->content('action=getnames&username='.$username.'&domain='.$domain);
@@ -2466,7 +2531,7 @@
 
 sub getdomaininfo {
     my ($domain,$userinfo) = @_;
-    my $URL = "http://s10.lite.msu.edu/cgi-bin/check_auth.pl";
+    my $URL = "https://s10.lite.msu.edu/cgi-bin/check_auth.pl";
     my $request = HTTP::Request->new(POST => $URL);
     $request->content_type('application/x-www-form-urlencoded');
     $request->content('action=getdomaininfo&domain='.$domain);
@@ -2486,6 +2551,27 @@
     }
 }
 
+sub get_domains {
+    my ($domref,$arg) = @_;
+    my $URL = "https://s10.lite.msu.edu/cgi-bin/check_auth.pl";
+    my $request = HTTP::Request->new(POST => $URL);
+    $request->content_type('application/x-www-form-urlencoded');
+    if ($arg eq 'long') {
+        $request->content('action=longdomainlist');
+    } else {
+        $request->content('action=domainlist');
+    }
+    $request->authorization_basic("","");
+    my $res = LWP::UserAgent->new->request($request);
+    if ($res->is_success) {
+        $$domref = $res->content;
+        $$domref =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
+        return 'ok';
+    } else {
+        return 'no_doms';
+    }
+}
+
 sub custommail {
     my ($dbh,$condmail,$event_id,$params,$linefeed) = @_;
 # Get mail text
@@ -2670,4 +2756,126 @@
     $adcookie_file->clear();
     return ($adsession,$pname,$stamp);
 }
+
+sub is_local {
+    my ($user,$event_id) = @_;
+    my $count = 0;
+    return $count if ($user eq '');
+    my ($netid,$firstname,$lastname);
+    if ($event_id eq '13') {
+        if ($user =~ /^([^@]+):(msu)$/) {
+            $netid = $1;
+            $udom = $2;
+            ($firstname,$lastname) = &loncapa_search($netid,$udom);
+        } elsif ($user =~ /^[^:@]+$/) {
+            $netid = $user;
+        } elsif ($user =~ /^([^@]+)\@msu\.edu$/) {
+            $netid = $1;
+        }
+        return $count if ($netid eq '');
+
+        my $ldapfilter = '(uid='.$netid.')';
+        my ($status,$uid) = &ldap_search('netid',$ldapfilter);
+        if ($uid) {
+            if ($status eq 'Faculty') {
+                $count = 1;
+            }
+        } elsif (($lastname ne '' && $firstname ne '')) {
+            $ldapfilter = $ldapfilter = '(sn='.$lastname.')';
+            ($status,$uid) = &ldap_search('lastname',$ldapfilter,$firstname);
+            if ($status eq 'Faculty') {
+                $count = 1;
+            }
+        } else {
+            my $url = "http://localhost/cgi-bin/msustatus.pl?netid=$netid";
+            my $ua = new LWP::UserAgent;
+            my $request = new HTTP::Request('GET', "$url");
+            my $response = $ua->request($request);
+            if ($response->is_success) {
+                $count = $response->content;
+            }
+        }
+    } elsif ($event_id eq '15') {
+        if ($user =~ /^([^@]+):(acadiau)$/) {
+            $count = 1; 
+        } elsif ($user =~ /^([^@]+)\@(acadiau|dal)\.ca$/) {
+            $count = 1;
+        } elsif ($user eq 'raeburn@educog.com') {
+            $count = 1;
+        }
+     } elsif ($event_id eq '17') {
+         if ($user =~ /^([^@]+):(vcu)$/i) {
+             $count = 1;
+         } elsif ($user =~ /^([^@]+)\@vcu\.edu$/i) {
+             $count = 1;
+         } elsif ($user eq 'raeburn@educog.com') {
+             $count = 1;
+         }
+    }
+    return $count;
+}
+
+sub ldap_search {
+    my ($caller,$ldapfilter,$firstname) = @_;
+    my $outcome;
+    my $ldap = Net::LDAP->new( 'ldap.msu.edu' );
+    my ($type,$netid);
+    if ($ldap) {
+        $ldap->bind;
+        my $mesg = $ldap->search(
+                            base   => "dc=msu, dc=edu",
+                            filter => $ldapfilter,
+                            attrs  => ['sn','givenName','title','uid','mail','employeeType'],
+                          );
+        if ($mesg->code) {
+            $ldap->unbind;
+            return ($type,$netid);
+        } else {
+            $outcome = 'ok';
+        }
+        foreach my $entry ($mesg->entries) {
+            $netid = $entry->get_value('uid');
+            next if ($netid eq '');
+            my $first = $entry->get_value('givenName');
+            my $last = $entry->get_value('sn');
+            my $email = $entry->get_value('mail');
+            if (($entry->get_value('employeeType') eq 'Faculty') ||
+                ($entry->get_value('employeeType') eq 'Staff')) {
+                $type = $entry->get_value('employeeType');
+            }
+            if ($caller eq 'netid') {
+                last;
+            } elsif ($caller eq 'lastname') {
+                if ($first eq $firstname) {
+                    last;
+                }
+            }
+        }
+        $ldap->unbind;
+    }
+    return ($type,$netid);
+}
+
+sub loncapa_search {
+    my ($uname,$udom) = @_;
+    my ($firstname,$lastname);
+    my $url = "https://s10.lite.msu.edu/cgi-bin/check_auth.pl?action=getnames&username=$uname&domain=$udom";
+    my $ua = new LWP::UserAgent;
+    my $request = new HTTP::Request('GET', "$url");
+    my $response = $ua->request($request);
+    if ($response->is_success) {
+        my ($esc_first,$esc_middle,$esc_last,$esc_gen,$esc_email) = split(/%%/,$response->content);
+        $firstname = &unescape($esc_first);
+        $lastname = &unescape($esc_last);
+    }
+    return ($firstname,$lastname);
+}
+
+sub unescape {
+    my $str=shift;
+    $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
+    return $str;
+}
+
+
 1;

--raeburn1302301324--