[system] / trunk / webwork2 / lib / WeBWorK / DB / Record / User.pm Repository:
ViewVC logotype

View of /trunk/webwork2/lib/WeBWorK/DB/Record/User.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5319 - (download) (as text) (annotate)
Mon Aug 13 22:59:59 2007 UTC (12 years, 6 months ago) by sh002i
File size: 3411 byte(s)
updated copyright dates

    1 ################################################################################
    2 # WeBWorK Online Homework Delivery System
    3 # Copyright  2000-2007 The WeBWorK Project, http://openwebwork.sf.net/
    4 # $CVSHeader: webwork2/lib/WeBWorK/DB/Record/User.pm,v 1.12 2006/10/02 15:04:27 sh002i Exp $
    5 #
    6 # This program is free software; you can redistribute it and/or modify it under
    7 # the terms of either: (a) the GNU General Public License as published by the
    8 # Free Software Foundation; either version 2, or (at your option) any later
    9 # version, or (b) the "Artistic License" which comes with this package.
   10 #
   11 # This program is distributed in the hope that it will be useful, but WITHOUT
   12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   13 # FOR A PARTICULAR PURPOSE.  See either the GNU General Public License or the
   14 # Artistic License for more details.
   15 ################################################################################
   16 
   17 package WeBWorK::DB::Record::User;
   18 use base WeBWorK::DB::Record;
   19 
   20 =head1 NAME
   21 
   22 WeBWorK::DB::Record::User - represent a record from the user table.
   23 
   24 =cut
   25 
   26 use strict;
   27 use warnings;
   28 
   29 BEGIN {
   30   __PACKAGE__->_fields(
   31     user_id       => { type=>"TINYBLOB NOT NULL", key=>1 },
   32     first_name    => { type=>"TEXT" },
   33     last_name     => { type=>"TEXT" },
   34     email_address => { type=>"TEXT" },
   35     student_id    => { type=>"TEXT" },
   36     status        => { type=>"TEXT" },
   37     section       => { type=>"TEXT" },
   38     recitation    => { type=>"TEXT" },
   39     comment       => { type=>"TEXT" },
   40   );
   41 }
   42 
   43 sub full_name {
   44   my ($self) = @_;
   45 
   46   my $first = $self->first_name;
   47   my $last = $self->last_name;
   48 
   49   if (defined $first and $first ne "" and defined $last and $last ne "") {
   50     return "$first $last";
   51   } elsif (defined $first and $first ne "") {
   52     return $first;
   53   } elsif (defined $last and $last ne "") {
   54     return $last;
   55   } else {
   56     return "";
   57   }
   58 }
   59 
   60 # phrase      =  1*word                       ; Sequence of words
   61 # word        =  atom / quoted-string
   62 # atom        =  1*<any CHAR except specials, SPACE and CTLs>
   63 # specials    =  "(" / ")" / "<" / ">" / "@"  ; Must be in quoted-
   64 #             /  "," / ";" / ":" / "\" / <">  ;  string, to use
   65 #             /  "." / "[" / "]"              ;  within a word.
   66 # SPACE       =  <ASCII SP, space>            ; (     40,      32.)
   67 # CTL         =  <any ASCII control           ; (  0- 37,  0.- 31.)
   68 #                 character and DEL>          ; (    177,     127.)
   69 # quoted-string = <"> *(qtext/quoted-pair) <">; Regular qtext or
   70 #                                             ;   quoted chars.
   71 # qtext       =  <any CHAR excepting <">,     ; => may be folded
   72 #                "\" & CR, and including
   73 #                linear-white-space>
   74 # CR          =  <ASCII CR, carriage return>  ; (     15,      13.)
   75 # quoted-pair =  "\" CHAR                     ; may quote any char
   76 
   77 sub rfc822_mailbox {
   78   my ($self) = @_;
   79 
   80   my $full_name = $self->full_name;
   81   my $address = $self->email_address;
   82 
   83   if (defined $address and $address ne "") {
   84     if (defined $full_name and $full_name ne "") {
   85       # see if we need to quote the phrase
   86       # (this regex matches CTL, SPACE, and specials)
   87       if ($full_name =~ /[\0-\037\177 ()<>@,;:\\".\[\]]/) {
   88         $full_name =~ s/(["\\\r])/\\$1/g; # escape <">, "\", or CR
   89         $full_name = "\"$full_name\"";
   90       }
   91       return "$full_name <$address>";
   92     } else {
   93       return $address;
   94     }
   95   } else {
   96     return "";
   97   }
   98 }
   99 
  100 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9