Commit | Line | Data |
---|---|---|
b715c1e1 SJ |
1 | <?php |
2 | /*************************************************************************** | |
d4c08d89 | 3 | * Copyright (C) 2003-2010 Polytechnique.org * |
b715c1e1 SJ |
4 | * http://opensource.polytechnique.org/ * |
5 | * * | |
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. * | |
10 | * * | |
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. * | |
15 | * * | |
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 * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
e5bcd851 | 22 | function fill_email_combobox(PlPage& $page, $user = null, $profile = null) |
b715c1e1 SJ |
23 | { |
24 | global $globals; | |
25 | ||
4e698dc9 | 26 | if (is_null($user)) { |
e5bcd851 | 27 | $user = S::user(); |
4e698dc9 SJ |
28 | } |
29 | if (is_null($profile)) { | |
30 | /* Always refetch the profile. */ | |
31 | $profile = $user->profile(true); | |
e5bcd851 | 32 | } |
b715c1e1 SJ |
33 | $email_type = "directory"; |
34 | ||
e5bcd851 | 35 | if ($profile) { |
ce0b2c6f | 36 | $email_directory = $profile->email_directory; |
e5bcd851 FB |
37 | if ($email_directory) { |
38 | $page->assign('email_directory', $email_directory); | |
39 | list($alias, $domain) = explode('@', $email_directory); | |
40 | } else { | |
41 | $page->assign('email_directory', ''); | |
42 | $email_type = NULL; | |
43 | $alias = $domain = ''; | |
44 | } | |
ce0b2c6f FB |
45 | |
46 | $res = XDB::query( | |
47 | "SELECT email | |
48 | FROM profile_job | |
49 | WHERE pid = {?}", $profile->id()); | |
50 | $res = $res->fetchAllAssoc(); | |
51 | $pro = array(); | |
52 | foreach ($res as $res_it) { | |
53 | if ($res_it['email'] != '') { | |
54 | $pro[] = $res_it['email']; | |
55 | if ($email_directory == $res_it['email']) { | |
56 | $email_type = "pro"; | |
57 | } | |
58 | } | |
59 | } | |
60 | $page->assign('list_email_pro', $pro); | |
b715c1e1 SJ |
61 | } |
62 | ||
e5bcd851 FB |
63 | if ($user) { |
64 | $melix = $user->emailAlias(); | |
65 | if ($melix) { | |
66 | list($melix) = explode('@', $melix); | |
67 | $page->assign('melix', $melix); | |
68 | if (($domain == $globals->mail->alias_dom) || ($domain == $globals->mail->alias_dom2)) { | |
69 | $email_type = "melix"; | |
70 | } | |
b715c1e1 | 71 | } |
b715c1e1 | 72 | |
e5bcd851 FB |
73 | $res = XDB::query( |
74 | "SELECT alias | |
75 | FROM aliases | |
fe13bc1d | 76 | WHERE uid={?} AND (type='a_vie' OR type='alias')", $user->id()); |
e5bcd851 FB |
77 | $res = $res->fetchAllAssoc(); |
78 | $page->assign('list_email_X', $res); | |
79 | if (($domain == $globals->mail->domain) || ($domain == $globals->mail->domain2)) { | |
80 | foreach ($res as $res_it) { | |
81 | if ($alias == $res_it['alias']) { | |
82 | $email_type = "X"; | |
83 | } | |
b715c1e1 SJ |
84 | } |
85 | } | |
b715c1e1 | 86 | |
e5bcd851 FB |
87 | require_once 'emails.inc.php'; |
88 | $redirect = new Redirect($user); | |
89 | $redir = array(); | |
90 | foreach ($redirect->emails as $redirect_it) { | |
91 | if ($redirect_it instanceof EmailRedirection) { | |
92 | $redir[] = $redirect_it->email; | |
93 | if ($email_directory == $redirect_it->email) { | |
94 | $email_type = "redir"; | |
95 | } | |
b715c1e1 SJ |
96 | } |
97 | } | |
e5bcd851 | 98 | $page->assign('list_email_redir', $redir); |
e5bcd851 | 99 | $page->assign('email_type', $email_type); |
e5bcd851 FB |
100 | } else { |
101 | $page->assign('list_email_X', array()); | |
102 | $page->assign('list_email_redir', array()); | |
103 | $page->assign('list_email_pro', array()); | |
104 | } | |
b715c1e1 SJ |
105 | } |
106 | ||
107 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
108 | ?> |