Fixes X emails display in email combobox.
[platal.git] / include / emails.combobox.inc.php
CommitLineData
b715c1e1
SJ
1<?php
2/***************************************************************************
12262f13 3 * Copyright (C) 2003-2011 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
188dc0be 22function fill_email_combobox(PlPage $page, $user = null, $profile = null)
b715c1e1 23{
4e698dc9 24 if (is_null($user)) {
e5bcd851 25 $user = S::user();
4e698dc9
SJ
26 }
27 if (is_null($profile)) {
28 /* Always refetch the profile. */
29 $profile = $user->profile(true);
e5bcd851 30 }
b4503762 31 $email_type = 'directory';
b715c1e1 32
e5bcd851 33 if ($profile) {
ce0b2c6f 34 $email_directory = $profile->email_directory;
b4503762 35 $page->assign('email_directory', $email_directory);
ce0b2c6f 36
b4503762
SJ
37 $res = XDB::fetchAllAssoc('SELECT email
38 FROM profile_job
39 WHERE pid = {?}', $profile->id());
ce0b2c6f
FB
40 $pro = array();
41 foreach ($res as $res_it) {
42 if ($res_it['email'] != '') {
43 $pro[] = $res_it['email'];
44 if ($email_directory == $res_it['email']) {
45 $email_type = "pro";
46 }
47 }
48 }
49 $page->assign('list_email_pro', $pro);
b715c1e1
SJ
50 }
51
e5bcd851 52 if ($user) {
8231a859 53 $res = XDB::fetchAllAssoc('SELECT CONCAT(s.email, \'@\', d.name) AS email
b4503762
SJ
54 FROM email_source_account AS s
55 INNER JOIN email_virtual_domains AS m ON (s.domain = m.id)
56 INNER JOIN email_virtual_domains AS d ON (d.aliasing = m.id)
57 WHERE s.uid = {?}
58 ORDER BY s.email, d.name', $user->id());
e5bcd851 59 $page->assign('list_email_X', $res);
b4503762
SJ
60 foreach ($res as $res_it) {
61 if ($email_directory == $res_it) {
62 $email_type = 'X';
b715c1e1
SJ
63 }
64 }
b715c1e1 65
e5bcd851
FB
66 require_once 'emails.inc.php';
67 $redirect = new Redirect($user);
68 $redir = array();
69 foreach ($redirect->emails as $redirect_it) {
b4503762 70 if ($redirect_it->is_redirection()) {
e5bcd851
FB
71 $redir[] = $redirect_it->email;
72 if ($email_directory == $redirect_it->email) {
b4503762 73 $email_type = 'redir';
e5bcd851 74 }
b715c1e1
SJ
75 }
76 }
e5bcd851 77 $page->assign('list_email_redir', $redir);
e5bcd851 78 $page->assign('email_type', $email_type);
e5bcd851
FB
79 } else {
80 $page->assign('list_email_X', array());
81 $page->assign('list_email_redir', array());
82 $page->assign('list_email_pro', array());
83 }
b715c1e1
SJ
84}
85
86// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
87?>