The ability to delete entries has been added.
authorocto <octo>
Sat, 30 Apr 2005 15:01:26 +0000 (15:01 +0000)
committerocto <octo>
Sat, 30 Apr 2005 15:01:26 +0000 (15:01 +0000)
Phone numbers now may contain spaces and dashes.
Internal changes in LiCoM::Person.

lib/LiCoM/Person.pm
licom.cgi

index cbc2eab..564d208 100644 (file)
@@ -29,7 +29,8 @@ our %ValidFields =
        labeledURI                      => 1,
        mail                            => 1,
        mobile                          => 1,
        labeledURI                      => 1,
        mail                            => 1,
        mobile                          => 1,
-       o                               => 1
+       o                               => 1,
+       userPassword                    => 0
 );
 
 our %ExternalNames =
 );
 
 our %ExternalNames =
@@ -44,7 +45,8 @@ our %ExternalNames =
        uri             => 'labeledURI',
        mail            => 'mail',
        cellphone       => 'mobile',
        uri             => 'labeledURI',
        mail            => 'mail',
        cellphone       => 'mobile',
-       group           => 'o'
+       group           => 'o',
+       password        => 'userPassword'
 );
 
 our $Ldap;
 );
 
 our $Ldap;
@@ -291,7 +293,16 @@ sub search
                        
                if (@disjunc)
                {
                        
                if (@disjunc)
                {
-                       push (@konjunct, join ('', '(|', @disjunc, ')'));
+                       my $tmp;
+                       if (scalar (@disjunc) == 1)
+                       {
+                               $tmp = $disjunc[0];
+                       }
+                       else
+                       {
+                               $tmp = join ('', '(|', @disjunc, ')');
+                       }
+                       push (@konjunct, $tmp);
                }
        }
 
                }
        }
 
@@ -433,7 +444,8 @@ sub name
 
 =item I<$obj>-E<gt>B<group> ([I<@groups>])
 
 
 =item I<$obj>-E<gt>B<group> ([I<@groups>])
 
-Get or set the attribute.
+Get or set the attribute. This is the same as calling S<I<$obj>-E<gt>B<set>
+(I<$field>, I<\@values>)> or S<I<$obj>-E<gt>B<get> (I<$field>)>.
 
 =cut
 
 
 =cut
 
@@ -450,14 +462,34 @@ sub AUTOLOAD
        return (set ($obj, $field, @values ? [@values] : undef))
 }
 
        return (set ($obj, $field, @values ? [@values] : undef))
 }
 
+=item I<$obj>-E<gt>B<get> (I<$field>)
+
+Returs the value(s) of field I<$field>.
+
+=cut
+
 sub get
 {
        my $obj = shift;
        my $field = shift;
 
 sub get
 {
        my $obj = shift;
        my $field = shift;
 
-       return (set ($obj, $field, undef));
+       if (wantarray ())
+       {
+               return (set ($obj, $field, undef));
+       }
+       else
+       {
+               return (scalar (set ($obj, $field, undef)));
+       }
 }
 
 }
 
+=item I<$obj>-E<gt>B<set> (I<$field>, I<\@values>)
+
+Sets the field I<$field> to the value(s) I<\@valued>. Pass an empty array-ref
+to delete the field.
+
+=cut
+
 sub set
 {
        my $obj = shift;
 sub set
 {
        my $obj = shift;
@@ -544,23 +576,6 @@ sub get_user
        return ($cn, $id);
 }
 
        return ($cn, $id);
 }
 
-sub password
-{
-       my $obj = shift;
-       my $entry = $obj->{'ldap'};
-       my $pwd;
-
-       if (@_)
-       {
-               $pwd = shift;
-               $entry->changetype ('modify');
-               $entry->replace (userPassword => $pwd);
-               $entry->update ($Ldap);
-       }
-
-       $pwd = $entry->get_value ('userPassword');
-}
-
 =back
 
 =head1 AUTHOR
 =back
 
 =head1 AUTHOR
index 40bb8a3..8a52ef4 100755 (executable)
--- a/licom.cgi
+++ b/licom.cgi
@@ -44,6 +44,8 @@ our %Actions =
        save    => [\&html_start, \&action_save,    \&html_end],
        search  => [\&html_start, \&action_search,  \&html_end],
        verify  => [\&html_start, \&action_verify,  \&html_end],
        save    => [\&html_start, \&action_save,    \&html_end],
        search  => [\&html_start, \&action_search,  \&html_end],
        verify  => [\&html_start, \&action_verify,  \&html_end],
+       delete  => [\&html_start, \&action_ask_del,  \&html_end],
+       expunge => [\&html_start, \&action_do_del,  \&html_end],
        vcard   => \&action_vcard
 );
 
        vcard   => \&action_vcard
 );
 
@@ -322,6 +324,7 @@ EOF
                        [<a href="$MySelf?action=verify&cn=$cn_esc">Verify</a>]
                        [<a href="$MySelf?action=vcard&cn=$cn_esc">vCard</a>]
                        [<a href="$MySelf?action=edit&cn=$cn_esc">Edit</a>]
                        [<a href="$MySelf?action=verify&cn=$cn_esc">Verify</a>]
                        [<a href="$MySelf?action=vcard&cn=$cn_esc">vCard</a>]
                        [<a href="$MySelf?action=edit&cn=$cn_esc">Edit</a>]
+                       [<a href="$MySelf?action=delete&cn=$cn_esc">Delete</a>]
                </div>
 
 EOF
                </div>
 
 EOF
@@ -787,6 +790,49 @@ EOM
        return (1);
 }
 
        return (1);
 }
 
+sub action_ask_del
+{
+       my $cn = param ('cn');
+       $cn or die;
+
+       my $person = LiCoM::Person->load ($cn);
+       $person or die;
+
+       my $cn_esc = uri_escape ($cn);
+
+       print <<EOF;
+               <h2>Really delete $cn?</h2>
+
+               <div>
+                       You are about to delete <strong>$cn</strong>. Are you
+                       totally, absolutely sure you want to do this?
+               </div>
+
+               <div class="menu">
+                       [<a href="$MySelf?action=expunge&cn=$cn_esc">Yes, delete</a>]
+                       [<a href="$MySelf?action=detail&cn=$cn_esc">No, keep</a>]
+               </div>
+
+EOF
+}
+
+sub action_do_del
+{
+       my $cn = param ('cn');
+       $cn or die;
+
+       my $person = LiCoM::Person->load ($cn);
+       $person or die;
+
+       $person->delete ();
+
+       print <<EOF;
+               <div>$cn has been deleted.</div>
+
+EOF
+       action_browse ();
+}
+
 sub html_start
 {
        my $title = shift;
 sub html_start
 {
        my $title = shift;
@@ -1101,9 +1147,9 @@ sub verify_fields
                my $number = $_;
                next unless ($number);
 
                my $number = $_;
                next unless ($number);
 
-               if ($number !~ m/^\+/)
+               if ($number !~ m/^\+[0-9 \-]+$/)
                {
                {
-                       push (@errors, 'Telephone numbers have to begin with the country code, e.g. &quot;+49 911 123456&quot;');
+                       push (@errors, 'Telephone numbers have to begin with the country code and only numbers, spaces and dashes are allowed, e.g. &quot;+49 911-123456&quot;');
                        last;
                }
        }
                        last;
                }
        }
@@ -1136,8 +1182,8 @@ sub get_contacts
                {
                        for (@values)
                        {
                {
                        for (@values)
                        {
-                               $_ =~ s/\D//g;
-                               $_ = '+' . $_;
+                               $_ =~ s/[^0-9 \-]//g;
+                               $_ = '+' . $_ if ($_);
                        }
                }
                
                        }
                }