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