Merge branch 'account'
[platal.git] / include / emails.combobox.inc.php
CommitLineData
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 22function fill_email_combobox(PlPage& $page, $user = null, $profile = null)
b715c1e1
SJ
23{
24 global $globals;
25
e5bcd851
FB
26 if (is_null($user) && is_null($profile)) {
27 $user = S::user();
28 $profile = $user->profile();
29 }
b715c1e1
SJ
30 $email_type = "directory";
31
e5bcd851 32 if ($profile) {
ce0b2c6f 33 $email_directory = $profile->email_directory;
e5bcd851
FB
34 if ($email_directory) {
35 $page->assign('email_directory', $email_directory);
36 list($alias, $domain) = explode('@', $email_directory);
37 } else {
38 $page->assign('email_directory', '');
39 $email_type = NULL;
40 $alias = $domain = '';
41 }
ce0b2c6f
FB
42
43 $res = XDB::query(
44 "SELECT email
45 FROM profile_job
46 WHERE pid = {?}", $profile->id());
47 $res = $res->fetchAllAssoc();
48 $pro = array();
49 foreach ($res as $res_it) {
50 if ($res_it['email'] != '') {
51 $pro[] = $res_it['email'];
52 if ($email_directory == $res_it['email']) {
53 $email_type = "pro";
54 }
55 }
56 }
57 $page->assign('list_email_pro', $pro);
b715c1e1
SJ
58 }
59
e5bcd851
FB
60 if ($user) {
61 $melix = $user->emailAlias();
62 if ($melix) {
63 list($melix) = explode('@', $melix);
64 $page->assign('melix', $melix);
65 if (($domain == $globals->mail->alias_dom) || ($domain == $globals->mail->alias_dom2)) {
66 $email_type = "melix";
67 }
b715c1e1 68 }
b715c1e1 69
e5bcd851
FB
70 $res = XDB::query(
71 "SELECT alias
72 FROM aliases
fe13bc1d 73 WHERE uid={?} AND (type='a_vie' OR type='alias')", $user->id());
e5bcd851
FB
74 $res = $res->fetchAllAssoc();
75 $page->assign('list_email_X', $res);
76 if (($domain == $globals->mail->domain) || ($domain == $globals->mail->domain2)) {
77 foreach ($res as $res_it) {
78 if ($alias == $res_it['alias']) {
79 $email_type = "X";
80 }
b715c1e1
SJ
81 }
82 }
b715c1e1 83
e5bcd851
FB
84 require_once 'emails.inc.php';
85 $redirect = new Redirect($user);
86 $redir = array();
87 foreach ($redirect->emails as $redirect_it) {
88 if ($redirect_it instanceof EmailRedirection) {
89 $redir[] = $redirect_it->email;
90 if ($email_directory == $redirect_it->email) {
91 $email_type = "redir";
92 }
b715c1e1
SJ
93 }
94 }
e5bcd851 95 $page->assign('list_email_redir', $redir);
e5bcd851 96 $page->assign('email_type', $email_type);
e5bcd851
FB
97 } else {
98 $page->assign('list_email_X', array());
99 $page->assign('list_email_redir', array());
100 $page->assign('list_email_pro', array());
101 }
b715c1e1
SJ
102}
103
104// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
105?>