Moving to GitHub.
[platal.git] / include / emails.combobox.inc.php
CommitLineData
b715c1e1
SJ
1<?php
2/***************************************************************************
c441aabe 3 * Copyright (C) 2003-2014 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
17c6e7bb 22function fill_email_combobox(PlPage $page, array $retrieve, $user = null)
b715c1e1 23{
17c6e7bb 24 require_once 'emails.inc.php';
4e698dc9 25 if (is_null($user)) {
e5bcd851 26 $user = S::user();
4e698dc9 27 }
17c6e7bb
SJ
28 /* Always refetch the profile. */
29 $profile = $user->profile(true);
b715c1e1 30
17c6e7bb
SJ
31 $emails = array();
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)
37 WHERE s.uid = {?}
38 ORDER BY s.email, d.name',
39 $user->id());
40 }
ce0b2c6f 41
17c6e7bb
SJ
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()) {
75350c28 47 $emails['Redirections'][] = $redirect_it->email;
ce0b2c6f
FB
48 }
49 }
b715c1e1
SJ
50 }
51
17c6e7bb
SJ
52 if ($profile) {
53 if (in_array('job', $retrieve)) {
54 $emails['Emails professionels'] = XDB::fetchColumn('SELECT email
55 FROM profile_job
56 WHERE pid = {?} AND email IS NOT NULL AND email != \'\'',
57 $profile->id());
b715c1e1 58 }
b715c1e1 59
17c6e7bb
SJ
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]);
66 }
67 }
68 }
69 $emails['Email annuaire AX'] = array($profile->email_directory);
70 } elseif (in_array('stripped_directory', $retrieve)) {
71 if (User::isForeignEmailAddress($profile->email_directory)) {
0cfb2bcb 72 $is_redirect = XDB::fetchOneCell('SELECT COUNT(*)
17c6e7bb
SJ
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);
78 }
e5bcd851 79 }
b715c1e1
SJ
80 }
81 }
17c6e7bb
SJ
82
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]);
87 }
88 }
89 }
90
91 $emails_count = 0;
92 foreach ($emails as $email_list) {
93 $emails_count += count($email_list);
e5bcd851 94 }
17c6e7bb
SJ
95 $page->assign('emails_count', $emails_count);
96 $page->assign('email_lists', $emails);
b715c1e1
SJ
97}
98
448c8cdc 99// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
b715c1e1 100?>