Index: trunk/LATMOS-Accounts-Web/MANIFEST
===================================================================
--- trunk/LATMOS-Accounts-Web/MANIFEST	(revision 1132)
+++ trunk/LATMOS-Accounts-Web/MANIFEST	(revision 1135)
@@ -15,4 +15,5 @@
 lib/LATMOS/Accounts/Web/Controller/Admin/Requests.pm
 lib/LATMOS/Accounts/Web/Controller/Ajax.pm
+lib/LATMOS/Accounts/Web/Controller/Ajax/Services/Mailing.pm
 lib/LATMOS/Accounts/Web/Controller/Aliases.pm
 lib/LATMOS/Accounts/Web/Controller/Create.pm
@@ -25,4 +26,5 @@
 lib/LATMOS/Accounts/Web/Controller/Rpc.pm
 lib/LATMOS/Accounts/Web/Controller/Search.pm
+lib/LATMOS/Accounts/Web/Controller/Services/Mailing.pm
 lib/LATMOS/Accounts/Web/Controller/Sites.pm
 lib/LATMOS/Accounts/Web/Controller/Summary/Departments.pm
@@ -54,4 +56,6 @@
 root/html/ajax/select_freeip_select.tt
 root/html/ajax/select_objects_list.tt
+root/html/ajax/services/mailing/dest_list.tt
+root/html/ajax/services/mailing/users_list.tt
 root/html/ajax/set_attrs.tt
 root/html/ajax/user_to_group_form.tt
@@ -95,4 +99,8 @@
 root/html/request/recorded.tt
 root/html/search/index.tt
+root/html/services/mailing/filter.tt
+root/html/services/mailing/index.tt
+root/html/services/mailing/send.tt
+root/html/services/mailing/to.tt
 root/html/sites/default.tt
 root/html/sites/index.tt
@@ -122,7 +130,9 @@
 root/static/icons/document-save-as.png
 root/static/icons/document-save.png
+root/static/icons/editclear.png
 root/static/icons/emblem-favorite.png
 root/static/icons/emblem-urgent.png
 root/static/icons/expired.png
+root/static/icons/find.png
 root/static/icons/gnome-session-logout.png
 root/static/icons/gnome-stock-mail-snd.png
@@ -139,4 +149,5 @@
 root/static/icons/gtk-home.png
 root/static/icons/gtk-jump-to-rtl.png
+root/static/icons/gtk-refresh.png
 root/static/icons/help-contents.png
 root/static/icons/icon_edit.png
@@ -198,4 +209,5 @@
 t/04config_load.t
 t/controller_About.t
+t/controller_Ajax-Services-Mailing.t
 t/controller_Ajax.t
 t/controller_Aliases.t
@@ -206,4 +218,5 @@
 t/controller_Request.t
 t/controller_Search.t
+t/controller_Services-Mailing.t
 t/controller_Sites.t
 t/controller_Summary-Department.t
Index: trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Ajax.pm
===================================================================
--- trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Ajax.pm	(revision 1132)
+++ trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Ajax.pm	(revision 1135)
@@ -46,7 +46,7 @@
 
 sub displayattr : Local {
-    my ($self, $c, $otype) = @_;
-    my $attribute = $c->model('Accounts')->db->attribute($otype,
-        $c->req->param('attr')) or return;
+    my ($self, $c, $otype, $attr) = @_;
+    $attr ||= $c->req->param('attr');
+    my $attribute = $c->model('Accounts')->db->attribute($otype, $attr) or return;
     $c->stash->{value} = $attribute->display($c->req->param('id'));
 }
@@ -56,8 +56,9 @@
 
     my $base = $c->model('Accounts')->db;
-    my $val = $c->req->param('val');
-    $c->stash->{'complete'} = $c->prototype->auto_complete_result([
+    my $val = $c->req->param('val') || '';
+    $c->stash->{values} = [
+        sort
         grep { /^\Q$val\E/ } $base->attributes_summary($otype, $attr)
-    ]);
+    ];
 
 }
Index: trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Ajax/Services/Mailing.pm
===================================================================
--- trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Ajax/Services/Mailing.pm	(revision 1135)
+++ trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Ajax/Services/Mailing.pm	(revision 1135)
@@ -0,0 +1,106 @@
+package LATMOS::Accounts::Web::Controller::Ajax::Services::Mailing;
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Catalyst::Controller'; }
+
+=head1 NAME
+
+LATMOS::Accounts::Web::Controller::Ajax::Services::Mailing - Catalyst Controller
+
+=head1 DESCRIPTION
+
+Catalyst Controller.
+
+=head1 METHODS
+
+=cut
+
+
+=head2 index
+
+=cut
+
+sub index :Path :Args(0) {
+    my ( $self, $c ) = @_;
+
+    $c->response->body('Matched LATMOS::Accounts::Web::Controller::Ajax::Services::Mailing in Ajax::Services::Mailing.');
+}
+
+sub users_list :Local {
+    my ( $self, $c ) = @_;
+
+    $c->req->params->{attr} =    [ 'active', 'mail' ];
+    $c->req->params->{attrval} = [ '1',    , '*'    ];
+
+    for ($c->req->param('type')) {
+
+        /^dpmt$/ and do {
+            push(@{ $c->req->params->{attr} }, 'department');
+            push(@{ $c->req->params->{attrval} }, $c->req->param('obj'));
+            last;
+        };
+        /^dpmt_assoc$/ and do {
+            push(@{ $c->req->params->{attr} }, 'memberOf');
+            push(@{ $c->req->params->{attrval} }, $c->req->param('obj'));
+            last;
+        };
+        /^quick$/ and do {
+            last;
+        };
+
+        # Else
+        push(@{ $c->req->params->{attr} }, $_);
+        push(@{ $c->req->params->{attrval} }, $c->req->param('toto'));
+    }
+    $c->stash->{ofilter} = $c->model('AttrFilter', 'user');
+}
+
+sub dest_list :Private {}
+
+sub quick_input :Private {}
+
+sub empty :Local {
+    my ( $self, $c ) = @_;
+    $c->session->{to} = {};
+    $c->go('dest_list');
+}
+
+sub mod_to :Local {
+    my ( $self, $c ) = @_;
+
+    for ($c->req->param('act' || '')) {
+        /add_to/ and do {
+            foreach ($c->req->param('user')) {
+                $c->session->{to}{$_} = 1;
+            }
+        };
+        /remove_to/ and do {
+            foreach ($c->req->param('user')) {
+                delete($c->session->{to}{$_});
+            }
+        };
+    }
+
+    $c->go('dest_list');
+}
+
+sub end : Private {
+    my ( $self, $c ) = @_;
+    $c->forward($c->view('TTpart'));
+}
+
+=head1 AUTHOR
+
+olivier
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+__PACKAGE__->meta->make_immutable;
+
+1;
Index: trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Services/Mailing.pm
===================================================================
--- trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Services/Mailing.pm	(revision 1135)
+++ trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Services/Mailing.pm	(revision 1135)
@@ -0,0 +1,138 @@
+package LATMOS::Accounts::Web::Controller::Services::Mailing;
+use Moose;
+use namespace::autoclean;
+use Email::MIME::Creator;
+use Email::Sender::Simple qw(sendmail);
+use Email::Sender::Transport::SMTP::Persistent qw();
+
+
+BEGIN { extends 'Catalyst::Controller'; }
+
+=head1 NAME
+
+LATMOS::Accounts::Web::Controller::Services::Mailing - Catalyst Controller
+
+=head1 DESCRIPTION
+
+Catalyst Controller.
+
+=head1 METHODS
+
+=cut
+
+
+=head2 index
+
+=cut
+
+sub index :Path :Args(0) {
+    my ( $self, $c ) = @_;
+
+    if ($c->req->param('sto')) {
+        $c->session->{mailing}{subject} = $c->req->param('subject');
+        $c->session->{mailing}{body} = $c->req->param('body');
+        $c->go('to');
+    }
+    if ($c->req->param('add_to')) {
+        $c->go('to');
+    }
+    if ($c->req->param('remove_to')) {
+        $c->go('to');
+    }
+
+    if ($c->req->param('send')) {
+        $c->go('send');
+    }
+}
+
+sub to :Private {
+    my ( $self, $c ) = @_;
+}
+
+sub filter :Local {
+    my ( $self, $c ) = @_;
+    for ($c->req->param('filter') || '') {
+    /^dpmt/ and do {
+        $c->req->params->{attr} = [ qw(sutype) ];
+        $c->req->params->{attrval} = [ qw(dpmt) ];
+        $c->go('/ajax/select_objects_list', [ 'group', ]);
+        last;
+    };
+    /^quick$/ and do {
+        $c->go('/ajax/services/mailing/quick_input', [ ]);
+        last; 
+    };
+
+    # Else
+    $c->go('/ajax/attrvalues', [ 'user', $_ ]);
+    }
+}
+
+sub send :Private {
+    my ( $self, $c ) = @_;
+
+    my $from = $c->model('Accounts')->base->get_object(
+        'user', $c->user->username
+    )->get_attributes('mail');
+
+    my $bodypart = Email::MIME->create(
+        attributes => {
+            content_type => 'text/plain',
+            disposition  => 'attachment',
+            charset      => 'utf-8',
+            encoding     => '8bit',
+        },
+        body => $c->req->param('body'),
+    );
+
+    my $email = Email::MIME->create(
+        header_str => [
+            From => $from,
+        ],
+        attributes => {
+            charset      => 'utf-8',
+        },
+        parts      => [ $bodypart ],
+    );
+    $email->header_set( Subject => $c->req->param('subject') );
+
+    warn $email->as_string;
+    foreach (sort (keys %{ $c->session->{to} })) {
+        my $obj = $c->model('Accounts')->base->get_object(
+            'user', $_
+        ) or next;
+        my $email_addr = $obj->get_attributes('mail') or next;
+        my $to = sprintf(
+            '%s <%s>',
+            $obj->get_attributes('displayName'),
+            $email_addr
+        );
+        $email->header_set( To => $to );
+        sendmail(
+            $email,
+            {
+                from => $from,
+                transport => Email::Sender::Transport::SMTP::Persistent->new({
+                        host => 'localhost',
+                        port => 25,
+                })
+            }
+        );
+    }
+
+}
+
+=head1 AUTHOR
+
+olivier
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+__PACKAGE__->meta->make_immutable;
+
+1;
Index: trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/AttrFilter.pm
===================================================================
--- trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/AttrFilter.pm	(revision 1132)
+++ trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/AttrFilter.pm	(revision 1135)
@@ -41,18 +41,25 @@
 
     my @objlist = ();
-    if ($c->req->params->{'q'}) {
-        my %objs;
-        foreach my $attr (@{ $c->config->{objects}{$otype}{quick_search} || [ 'cn' ]}) {
-            foreach ($base->search_objects(
-                    $otype, "$attr~" . $c->req->params->{'q'})) {
-                $objs{$_} = 1;
+    if ($c->req->params->{'q'} || exists($c->req->params->{'attr'}) ) {
+        my %objs = ();
+        if ($c->req->params->{'q'}) {
+            foreach my $attr (@{ $c->config->{objects}{$otype}{quick_search} || [ 'cn' ]}) {
+                foreach ($base->search_objects(
+                        $otype, "$attr~" . $c->req->params->{'q'})) {
+                    $objs{$_} = 1;
+                }
+                @objlist = sort keys %objs;
             }
-            @objlist = sort keys %objs;
         }
-    } elsif (exists($c->req->params->{'attr'})) {
-        $self->{filter}{'attr'} = [ $c->req->param('attr') ];
-        $self->{filter}{'attrval'} = [ $c->req->param('attrval') ];
-        my @filter = $self->filter;
-        @objlist = $base->search_objects($otype, @filter);
+
+        if (exists($c->req->params->{'attr'})) {
+            $self->{filter}{'attr'} = [ $c->req->param('attr') ];
+            $self->{filter}{'attrval'} = [ $c->req->param('attrval') ];
+            my @filter = $self->filter;
+            @objlist = $base->search_objects($otype, @filter);
+            if ($c->req->params->{'q'}) {
+                @objlist = grep { $objs{$_} } @objlist;
+            }
+        }
     } else {
         @objlist = $base->list_objects($otype);
Index: trunk/LATMOS-Accounts-Web/root/html/ajax/attrvalues.tt
===================================================================
--- trunk/LATMOS-Accounts-Web/root/html/ajax/attrvalues.tt	(revision 1132)
+++ trunk/LATMOS-Accounts-Web/root/html/ajax/attrvalues.tt	(revision 1135)
@@ -1,1 +1,10 @@
-[% complete %]
+[% IF c.req.param('type') == 'select' %]
+<select name="toto">
+<option value="">--</option>
+[% FOREACH v = values %]
+<option value="[% v | html %]">[% v | html %]</option>
+[% END %]
+</select>
+[% ELSE %]
+[% c.prototype.auto_complete_result(values) %]
+[% END %]
Index: trunk/LATMOS-Accounts-Web/root/html/ajax/services/mailing/dest_list.tt
===================================================================
--- trunk/LATMOS-Accounts-Web/root/html/ajax/services/mailing/dest_list.tt	(revision 1135)
+++ trunk/LATMOS-Accounts-Web/root/html/ajax/services/mailing/dest_list.tt	(revision 1135)
@@ -0,0 +1,25 @@
+
+<p>[% c.session.to.keys.size %] destinataires</p>
+
+<div style="height: 20em; overflow: auto">
+[% FOREACH u = c.session.to.keys.sort %]
+[% IF loop.first %]
+<table>
+[% END %]
+<tr>
+<td>[% u | html %]</td>
+<td>
+[%  c.prototype.link_to_remote( 'Sup', {
+    update => 'destlist',
+    url    => c.uri_for('/ajax', 'services', 'mailing', 'mod_to', {
+        'act'  => 'remove_to',
+        'user' => u,
+    })
+} ) %]
+</td>
+</tr>
+[% IF loop.last %]
+<table>
+[% END %]
+[% END %]
+</div>
Index: trunk/LATMOS-Accounts-Web/root/html/ajax/services/mailing/users_list.tt
===================================================================
--- trunk/LATMOS-Accounts-Web/root/html/ajax/services/mailing/users_list.tt	(revision 1135)
+++ trunk/LATMOS-Accounts-Web/root/html/ajax/services/mailing/users_list.tt	(revision 1135)
@@ -0,0 +1,20 @@
+[% FOREACH u = ofilter.objectslist %]
+[% IF loop.first %]
+<table>
+[% END %]
+<tr>
+    <td>[% u | html %]</td>
+    <td><input type=checkbox name="user" checked=1 value="[% u | html %]">
+[%  c.prototype.link_to_remote( '+', {
+    update => 'destlist',
+    url    => c.uri_for('/ajax', 'services', 'mailing', 'mod_to', {
+        'act'  => 'add_to',
+        'user' => u,
+    })
+} ) %]
+    </td>
+</tr>
+[% IF loop.last %]
+</table>
+[% END %]
+[% END %]
Index: trunk/LATMOS-Accounts-Web/root/html/includes/select_objects_list.tt
===================================================================
--- trunk/LATMOS-Accounts-Web/root/html/includes/select_objects_list.tt	(revision 1132)
+++ trunk/LATMOS-Accounts-Web/root/html/includes/select_objects_list.tt	(revision 1135)
@@ -9,6 +9,10 @@
 [% IF objectslist.size < 20 %]
 [% object = c.model('Accounts').db.get_object(ofilter.otype, name) %]
-<option value="[% name | html %]">[% name | html %] ([%
-object.get_attributes('displayName') | html %])</option>
+<option value="[% name | html %]">[% name | html %]
+[% disp = object.get_attributes('displayName') %]
+[% IF disp %]
+([%disp | html %])
+[% END %]
+</option>
 [% ELSE %]
 <option value="[% name | html %]">[% name | html %]</option>
Index: trunk/LATMOS-Accounts-Web/root/html/services/mailing/index.tt
===================================================================
--- trunk/LATMOS-Accounts-Web/root/html/services/mailing/index.tt	(revision 1135)
+++ trunk/LATMOS-Accounts-Web/root/html/services/mailing/index.tt	(revision 1135)
@@ -0,0 +1,14 @@
+<form action="[% c.uri_for() %]" method="POST">
+<label for="subject">Sujet</label><br>
+<input type="text" name="subject" value="[% c.session.mailing.subject | html %]">
+<br>
+
+<input type="submit" name="sto" value="To ...">
+[% IF c.session.to.keys.size > 0 %][% c.session.to.keys.size %] destinataires[% END %]
+<br>
+<textarea name="body" rows="6" cols="60">
+[%- c.session.mailing.body | html -%]
+</textarea><br>
+<input type="submit" name="send" value="send">
+
+</form>
Index: trunk/LATMOS-Accounts-Web/root/html/services/mailing/send.tt
===================================================================
--- trunk/LATMOS-Accounts-Web/root/html/services/mailing/send.tt	(revision 1135)
+++ trunk/LATMOS-Accounts-Web/root/html/services/mailing/send.tt	(revision 1135)
@@ -0,0 +1,1 @@
+Sent
Index: trunk/LATMOS-Accounts-Web/root/html/services/mailing/to.tt
===================================================================
--- trunk/LATMOS-Accounts-Web/root/html/services/mailing/to.tt	(revision 1135)
+++ trunk/LATMOS-Accounts-Web/root/html/services/mailing/to.tt	(revision 1135)
@@ -0,0 +1,71 @@
+<div style="float:left; border: solid;">
+<p>Rechercher:</p>
+[% c.prototype.form_remote_tag({
+    update => 'dest',
+    url => c.uri_for('/ajax', 'services', 'mailing', 'users_list'),
+ }) %]
+<select name="type" id="to_type">
+<option value="quick">Nom contient:</option>
+<option value="memberOf">Membre du groupe...</option>
+<option value="company">SociÃ©tÃ©...</option>
+[% IF \c.model('Accounts').db.search_objects(
+    'group',
+    'exported=*',
+    'sutype=dpmt').size > 0 %]
+<option value="dpmt">Du dÃ©partement...</option>
+<option value="dpmt_assoc">Du dÃ©partement ou associÃ©...</option>
+[% END %]
+</select>
+<br>
+<span id="to_res">
+[% INCLUDE 'ajax/services/mailing/quick_input.tt' %]
+</span>
+<br>
+<input type="image" src="[% c.uri_for('/static/icons/find.png') %]" width="24" height="24">
+[% c.prototype.observe_field( 'to_type', {
+    update => 'to_res',
+    url => c.uri_for('/services', 'mailing', 'filter'),
+    frequency => 1,
+    with   => "'type=select&filter=' + element.value",
+}) %]
+</form>
+<hr>
+
+[% c.prototype.form_remote_tag({
+    update => 'destlist',
+    url => c.uri_for('/ajax', 'services', 'mailing', 'mod_to'),
+ }) %]
+<div style="float: left; width:15em;">
+RÃ©sultat:
+<div id="dest" style="height: 20em; overflow: auto">
+</div>
+</div>
+<div style="float: right">
+<input type=hidden name=act value="" id=act>
+<input type="submit" name="add_to"
+    value="Ajouter >>" onclick="document.getElementById('act').value='add_to';"><br>
+<input type="submit" name="add_to"
+    value="Supprimer >>" onclick="document.getElementById('act').value='remove_to';"><br>
+</div>
+</div>
+
+</form>
+
+<div style="width: 20em; float:left; border: solid;">
+[%  c.prototype.link_to_remote(
+    '<img src="' _ c.uri_for('/static/icons', 'editclear.png') _ '">',
+    {
+    update => 'destlist',
+    url    => c.uri_for('/ajax', 'services', 'mailing', 'empty'),
+}, { entities => '' } ) %]
+
+<span style="float: right">
+<a href="[% c.uri_for('/services', 'mailing') %]">
+<img src="[% c.uri_for('/static/icons', 'emblem-default.png') %]">
+</a>
+</span>
+<hr style="clear: both;">
+<div id="destlist">
+[% INCLUDE 'ajax/services/mailing/dest_list.tt' %]
+</div>
+</div>
Index: trunk/LATMOS-Accounts-Web/t/controller_Ajax-Services-Mailing.t
===================================================================
--- trunk/LATMOS-Accounts-Web/t/controller_Ajax-Services-Mailing.t	(revision 1135)
+++ trunk/LATMOS-Accounts-Web/t/controller_Ajax-Services-Mailing.t	(revision 1135)
@@ -0,0 +1,10 @@
+use strict;
+use warnings;
+use Test::More;
+
+
+use Catalyst::Test 'LATMOS::Accounts::Web';
+use LATMOS::Accounts::Web::Controller::Ajax::Services::Mailing;
+
+ok( request('/ajax/services/mailing')->is_success, 'Request should succeed' );
+done_testing();
Index: trunk/LATMOS-Accounts-Web/t/controller_Services-Mailing.t
===================================================================
--- trunk/LATMOS-Accounts-Web/t/controller_Services-Mailing.t	(revision 1135)
+++ trunk/LATMOS-Accounts-Web/t/controller_Services-Mailing.t	(revision 1135)
@@ -0,0 +1,10 @@
+use strict;
+use warnings;
+use Test::More;
+
+
+use Catalyst::Test 'LATMOS::Accounts::Web';
+use LATMOS::Accounts::Web::Controller::Services::Mailing;
+
+ok( request('/services/mailing')->is_success, 'Request should succeed' );
+done_testing();
