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 "$group"" : 'List of all addresses';
+ my $group_name_html = encode_entities ($group_name || '');
+
+ my $title = $group_name
+ ? "List of group "$group_name_html""
+ : '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 "$group_name_html".
+ </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;
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)
{
}
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