Moving to GitHub.
[platal.git] / include / emails.combobox.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2014 Polytechnique.org *
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
22 function fill_email_combobox(PlPage $page, array $retrieve, $user = null)
23 {
24 require_once 'emails.inc.php';
25 if (is_null($user)) {
26 $user = S::user();
27 }
28 /* Always refetch the profile. */
29 $profile = $user->profile(true);
30
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 }
41
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;
48 }
49 }
50 }
51
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());
58 }
59
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)) {
72 $is_redirect = XDB::fetchOneCell('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);
78 }
79 }
80 }
81 }
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);
94 }
95 $page->assign('emails_count', $emails_count);
96 $page->assign('email_lists', $emails);
97 }
98
99 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
100 ?>