2 /***************************************************************************
3 * Copyright (C) 2003-2011 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 function fill_email_combobox(PlPage
$page, array $retrieve, $user = null
)
24 require_once 'emails.inc.php';
28 /* Always refetch the profile. */
29 $profile = $user->profile(true
);
32 if (in_array('source', $retrieve)) {
33 $emails['Emails polytechniciens'] = XDB
::fetchColumn('SELECT CONCAT(s.email, \'@\', d.name)
34 FROM email_source_account AS s
35 INNER JOIN email_virtual_domains AS m ON (s.domain = m.id)
36 INNER JOIN email_virtual_domains AS d ON (d.aliasing = m.id)
38 ORDER BY s.email, d.name',
42 if (in_array('redirect', $retrieve)) {
43 $redirect = new Redirect($user);
44 $emails['Redirections'] = array();
45 foreach ($redirect->emails
as $redirect_it) {
46 if ($redirect_it->is_redirection()) {
47 $emails['Redirections'][] = $redirect_it->email
;
53 if (in_array('job', $retrieve)) {
54 $emails['Emails professionels'] = XDB
::fetchColumn('SELECT email
56 WHERE pid = {?} AND email IS NOT NULL AND email != \'\'',
60 if ($profile->email_directory
) {
61 if (in_array('directory', $retrieve)) {
62 foreach ($emails as &$email_list) {
63 foreach ($email_list as $key => $email) {
64 if ($profile->email_directory
== $email) {
65 unset($email_list[$key]);
69 $emails['Email annuaire AX'] = array($profile->email_directory
);
70 } elseif (in_array('stripped_directory', $retrieve)) {
71 if (User
::isForeignEmailAddress($profile->email_directory
)) {
72 $is_redirect = XDB
::fecthOneCell('SELECT COUNT(*)
73 FROM email_redirect_account
74 WHERE uid = {?} AND redirect = {?}',
75 $user->id(), $profile->email_directory
);
76 if ($is_redirect == 0) {
77 $emails['Email annuaire AX'] = array($profile->email_directory
);
83 if (isset($emails['Emails professionels']) && isset($emails['Redirections'])) {
84 $intersect = array_intersect($emails['Emails professionels'], $emails['Redirections']);
85 foreach ($intersect as $key => $email) {
86 unset($emails['Emails professionels'][$key]);
92 foreach ($emails as $email_list) {
93 $emails_count +
= count($email_list);
95 $page->assign('emails_count', $emails_count);
96 $page->assign('email_lists', $emails);
99 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: