Added the possibility to change a groups description.
authorFlorian Forster <octo@verplant.org>
Sun, 11 Jun 2006 15:07:26 +0000 (17:07 +0200)
committerFlorian Forster <octo@verplant.org>
Sun, 11 Jun 2006 15:07:26 +0000 (17:07 +0200)
Future plans could be:
- Change the name of the group (requires changing the `dn', I guess)
- Manage users (at least remove them from the group)

lib/LiCoM/Group.pm
licom.cgi

index 7bdc500..39fd540 100644 (file)
@@ -296,7 +296,7 @@ sub description
                $obj->{'description'} = shift;
 
                $entry->changetype ('modify');
-               $entry->replace (description => $obj->{'description'});
+               $entry->replace (description => [$obj->{'description'}]);
                $entry->update ($Ldap);
        }
 
index 190a9b6..ffc4a36 100755 (executable)
--- a/licom.cgi
+++ b/licom.cgi
@@ -63,7 +63,9 @@ our %Actions =
        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,
+       edit_group => [\&html_start, \&action_edit_group, \&html_end],
+       save_group => [\&html_start, \&action_save_group, \&html_end]
 );
 
 read_config ();
@@ -98,7 +100,7 @@ if (!$UserCN)
 
 if (!defined ($Actions{$Action}))
 {
-       die;
+       die ("No such action: $Action");
 }
 
 if (ref ($Actions{$Action}) eq 'CODE')
@@ -129,17 +131,17 @@ sub action_browse
        {
                my @groups = LiCoM::Group->all ();
 
-               print qq(\t\t<h2>Contact Groups</h2>\n\t\t<ul class="groups">\n);
+               print qq(\t\t<h2>Contact groups</h2>\n\t\t<ul class="groups">\n);
                for (@groups)
                {
                        my $group = $_;
                        my @members = $group->get_members ();
                        my $members = scalar (@members);
                        my $group_name = $group->name ();
-                       my $group_esc  = uri_escape ($group_name);
+                       my $group_uri  = uri_escape ($group_name);
                        my $desc = $group->description ();
 
-                       print qq#\t\t\t<li><a href="$MySelf?action=browse&group=$group_esc">#,
+                       print qq#\t\t\t<li><a href="$MySelf?action=browse&group=$group_uri">#,
                        encode_entities ($group_name),
                        qq#</a> ($members Member#, ($members == 1 ? ')' : 's)');
                        print qq(<br />\n\t\t\t\t<span class="description">),
@@ -159,26 +161,31 @@ EOF
        }
        else
        {
-               my $group_obj = LiCoM::Group->load ($group);
-               my $group_esc = uri_escape ($group_obj->name ());
+               my $group_obj    = LiCoM::Group->load ($group);
+               my $group_uri    = uri_escape ($group_obj->name ());
+               my $group_html   = encode_entities ($group_obj->name ());
                my @member_names = $group_obj->get_members ();
+               my $desc         = $group_obj->description ();
+               my $desc_html    = encode_entities ($desc || '');
                
-               print qq(\t\t<h2>Contact Group &quot;$group&quot;</h2>\n),
-               qq(\t\t<ul class="results">\n);
+               print qq(\t\t<h2>Contact group &quot;$group_html&quot;</h2>\n);
+               print qq(\t\t<div>$desc_html</div>\n) if ($desc);
+               print qq(\t\t<ul class="results">\n);
                for (sort (@member_names))
                {
                        my $cn = $_;
-                       my $cn_esc = uri_escape ($cn);
+                       my $cn_uri  = uri_escape ($cn);
+                       my $cn_html = encode_entities ($cn);
 
-                       print qq(\t\t\t<li><a href="$MySelf?action=detail&cn=$cn_esc">$cn</a></li>\n);
+                       print qq(\t\t\t<li><a href="$MySelf?action=detail&cn=$cn_uri">$cn_html</a></li>\n);
                }
                
                print <<EOF;
                </ul>
                <div class="menu">
-                       [<a href="$MySelf?action=list&group=$group_esc">List</a>]
+                       [<a href="$MySelf?action=list&group=$group_uri">List</a>]
                        [<a href="$MySelf?action=browse">Back</a>]
-                       [Edit]
+                       [<a href="$MySelf?action=edit_group&group=$group_uri">Edit</a>]
                </div>
 EOF
        }
@@ -976,6 +983,67 @@ EOF
        action_browse ();
 }
 
+sub action_edit_group
+{
+       my $group_name = param ('group') or die;
+
+       my $group_name_html = encode_entities ($group_name);
+
+       my $group_obj = LiCoM::Group->load ($group_name);
+
+       if (!$group_obj)
+       {
+               print qq(\t<div class="error">Group &quot;$group_name_html&quot; does not exist or could not be loaded.</div>\n);
+               return;
+       }
+
+       $group_name_html = encode_entities ($group_obj->name ());
+
+       my $desc_html = encode_entities ($group_obj->description () || '');
+
+       print <<HTML;
+       <h2>Edit contact group &quot;$group_name_html&quot;</h2>
+       <form action="$MySelf" method="post">
+         <input type="hidden" name="action" value="save_group" />
+         <input type="hidden" name="group" value="$group_name_html" />
+         <table>
+           <tr>
+             <th>Group Name</th>
+             <td>$group_name_html</td>
+           </tr>
+           <tr>
+             <th>Description</th>
+             <td><input type="text" name="description" value="$desc_html" /></td>
+           </tr>
+           <tr>
+             <th colspan="2"><input type="submit" name="button" value="Save" /></th>
+           </tr>
+         </table>
+       </form>
+HTML
+}
+
+sub action_save_group
+{
+       my $group_name = param ('group') or die;
+
+       my $group_name_html = encode_entities ($group_name);
+
+       my $group_obj = LiCoM::Group->load ($group_name);
+
+       if (!$group_obj)
+       {
+               print qq(\t<div class="error">Group &quot;$group_name_html&quot; does not exist or could not be loaded.</div>\n);
+               return;
+       }
+
+       my $desc = param ('description');
+       $group_obj->description ($desc);
+
+       action_browse ();
+       return;
+}
+
 sub html_start
 {
        my $title = shift;