Fix the group-list action.
authorFlorian Forster <octo@verplant.org>
Sun, 11 Jun 2006 20:18:23 +0000 (22:18 +0200)
committerFlorian Forster <octo@verplant.org>
Sun, 11 Jun 2006 20:18:23 +0000 (22:18 +0200)
It was broken: It used LiCoM::search to search for group-members, which is a
dumb idea..

licom.cgi

index 68e3581..78270c8 100755 (executable)
--- a/licom.cgi
+++ b/licom.cgi
@@ -193,21 +193,46 @@ EOF
 
 sub action_list
 {
-       my $group = param ('group');
-       $group = shift if (@_);
-       $group ||= '';
+       my $group_name = param ('group');
+       $group_name = shift if (@_);
+       $group_name ||= '';
 
-       my $title = $group ? "List of group &quot;$group&quot;" : 'List of all addresses';
+       my $group_name_html = encode_entities ($group_name || '');
+
+       my $title = $group_name
+               ? "List of group &quot;$group_name_html&quot;"
+               : 'List of all addresses';
        my @fields = (qw(address homephone cellphone officephone fax mail));
 
        my @all = ();
-       if ($group)
+       if ($group_name)
        {
-               @all = LiCoM::Person->search ([[group => $group]]);
+               my $group_obj = LiCoM::Group->load ($group_name);
+               if (!$group_obj)
+               {
+                       print <<HTML;
+               <div class="error">
+                       Unable to load group &quot;$group_name_html&quot;.
+               </div>
+HTML
+                       return;
+               }
+               for ($group_obj->get_members ())
+               {
+                       my $cn = $_;
+                       my $person_obj = LiCoM::Person->load ($cn);
+
+                       if (!$person_obj)
+                       {
+                               print STDERR "Unable to load cn = $cn;\n";
+                               next;
+                       }
+                       push (@all, $person_obj);
+               }
        }
        else
        {
-               @all = LiCoM::Person->search ();
+               @all = LiCoM::Person->search ([[group => $group_name]]);
        }
 
        print <<EOF;
@@ -226,11 +251,15 @@ EOF
        for (sort { $a->name () cmp $b->name () } (@all))
        {
                my $person = $_;
+               my $cn = $person->name ();
                my $sn = $person->lastname ();
                my $gn = $person->firstname ();
 
+               my $cn_uri  = uri_escape ($cn);
+               my $cn_html = encode_entities ("$sn, $gn");
+
                print "\t\t\t<tr>\n",
-               "\t\t\t\t<td>$sn, $gn</td>\n";
+               qq(\t\t\t\t<td><a href="$MySelf?action=detail&cn=$cn_uri">$cn_html</a></td>\n);
 
                for (@fields)
                {
@@ -243,9 +272,9 @@ EOF
        }
        print "\t\t</table>\n\n";
 
-       if ($group)
+       if ($group_name)
        {
-               my $group_esc = uri_escape ($group);
+               my $group_esc = uri_escape ($group_name);
                print qq(\t\t<div class="menu">[<a href="$MySelf?action=browse&group=$group_esc">Back</a>]</div>\n);
        }
        else