home *** CD-ROM | disk | FTP | other *** search
/ pc.louisiana.edu/pub/unix/ / Louisiana_UNIX.tar / Louisiana_UNIX / bbusernames5 < prev    next >
Text File  |  2001-08-08  |  3KB  |  71 lines

  1. #!/usr/local/bin/perl
  2. #
  3. # bbusernames -a|-n|-d
  4. #  will display all (-a), or registered but not enrolled in any course (-n),
  5. #  or de-activated/unavailable (-d),
  6. #  users of Blackboard Courseinfo 5.x (5.5 tested 6/2001).
  7. # User lists are sent to stdout in a format suitable for bulk-deletion.
  8. # V5.5 requires only the UserID ... we also provide optional Lname,Fname .
  9. # Written by ljc9020@louisiana.edu and jpd@louisiana.edu
  10. # See blackboard/bin/admin/search.pl for coding examples...
  11. #
  12. use DBI;
  13. use strict;
  14.  
  15. my $driver;
  16. my ($database,$hostname,$hostport);
  17. my ($dsn,$dbh);
  18. my ($username, $userpass);
  19. my ($sth, $ref);
  20. my $user_id;
  21. my ($showall,$showdeact);
  22.  
  23.  
  24. if ($ARGV[0] eq "-a"){ $showall=1; $showdeact=0; }
  25. elsif ($ARGV[0] eq "-n"){ $showall=0; $showdeact=0; }
  26. elsif ($ARGV[0] eq "-d"){ $showall=1; $showdeact=1; }
  27. else {
  28.     printf("Usage:  bbusernames -a      [to dump all blackboard users]\n");
  29.     printf("        bbusernames -n      [to dump all blackboard users not enrolled in courses]\n");
  30.     printf("        bbusernames -d      [to dump all deactivated blackboard users]\n");
  31.     exit(1);
  32. }
  33.  
  34.  
  35. $driver = "mysql";
  36. $database = "bb50";
  37. $hostname = "DATABASE_HOSTNAME_HERE";
  38. $hostport = "3307";  # 3306 is std. for MySQL
  39. $username = "bb50";
  40. $userpass = "PASSWD_GOES_HERE";
  41.  
  42. $dsn = "DBI:$driver:database=$database;host=$hostname;port=$hostport";
  43.  
  44. $dbh = DBI ->connect($dsn,$username,$userpass);
  45.  
  46. $sth = $dbh -> prepare ("SELECT firstname,lastname,user_id,system_role, pk1, sos_id_pk2, available_ind,row_status FROM  users");
  47. #maybe add:     WHERE user_id NOT LIKE 'Bb_BB50_Portal_User_Type_#%'
  48.  
  49. $sth -> execute();
  50. while($ref = $sth->fetchrow_hashref()){
  51.   unless ($showall) {
  52.       $user_id=$ref->{'user_id'};
  53.       next if ($user_id eq "administrator");    # skip explicit administrator or guest
  54.       next if ($user_id eq "guest");
  55.       next if ($ref->{'system_role'} =~ /[zuhca]/); # skip support roles too
  56.       my $enrolled_numrows=$dbh->selectrow_array("SELECT count(*) FROM  course_users WHERE users_pk1 = '$ref->{'pk1'}' and users_sos_id_pk2 = '$ref->{'sos_id_pk2'}'");
  57.       next if($enrolled_numrows ne "0");    # skip if is enrolled in a course
  58.   }
  59.   elsif ($showdeact) {
  60.       next if ($ref->{'available_ind'} ne 'N');
  61.   }
  62.  
  63. # printf STDOUT ("\"%s\",\"%s\",\"%s\"\t%s,%s\n", $ref->{'user_id'},$ref->{'lastname'}, $ref->{'firstname'}, $ref->{'row_status'}, $ref->{'system_role'});
  64.   printf STDOUT ("\"%s\",\"%s\",\"%s\"\n", $ref->{'user_id'},$ref->{'lastname'}, $ref->{'firstname'});
  65. }
  66.  
  67. $sth->finish();
  68. $dbh->disconnect();
  69. 0;
  70.  
  71.