| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2006 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 | // {{{ class AliasReq |
| 23 | |
| 24 | class AliasReq extends Validate |
| 25 | { |
| 26 | // {{{ properties |
| 27 | |
| 28 | var $alias; |
| 29 | var $raison; |
| 30 | var $unique = true; |
| 31 | |
| 32 | var $old=''; |
| 33 | var $public='private'; |
| 34 | |
| 35 | var $rules = "Interdire ce qui peut nous servir (virus@, postmaster@, ...), |
| 36 | les alias vulgaires, et les prenom.nom (sauf si c'est pour l'utilisateur prenom.nom). |
| 37 | Pas de contrainte pour les tirets ou les points, en revanche le souligné (_) est interdit"; |
| 38 | |
| 39 | // }}} |
| 40 | // {{{ constructor |
| 41 | |
| 42 | function AliasReq ($_uid, $_alias, $_raison, $_public, $_stamp=0) |
| 43 | { |
| 44 | global $globals; |
| 45 | $this->Validate($_uid, true, 'alias', $_stamp); |
| 46 | $this->alias = $_alias.'@'.$globals->mail->alias_dom; |
| 47 | $this->raison = $_raison; |
| 48 | $this->public = $_public; |
| 49 | |
| 50 | $res = $globals->xdb->query(" |
| 51 | SELECT v.alias |
| 52 | FROM virtual_redirect AS vr |
| 53 | INNER JOIN virtual AS v ON (v.vid=vr.vid AND v.alias LIKE '%@{$globals->mail->alias_dom}') |
| 54 | WHERE vr.redirect={?} OR vr.redirect={?}", |
| 55 | "{$this->forlife}@{$globals->mail->domain}", "{$this->forlife}@{$globals->mail->domain2}"); |
| 56 | $this->old = $res->fetchOneCell(); |
| 57 | if (empty($this->old)) { unset($this->old); } |
| 58 | } |
| 59 | |
| 60 | // }}} |
| 61 | // {{{ function get_request() |
| 62 | |
| 63 | function get_request($uid) |
| 64 | { |
| 65 | return parent::get_request($uid,'alias'); |
| 66 | } |
| 67 | |
| 68 | // }}} |
| 69 | // {{{ function formu() |
| 70 | |
| 71 | function formu() |
| 72 | { return 'include/form.valid.aliases.tpl'; } |
| 73 | |
| 74 | // }}} |
| 75 | // {{{ function _mail_subj |
| 76 | |
| 77 | function _mail_subj() |
| 78 | { |
| 79 | return "[Polytechnique.org/MELIX] Demande de l'alias {$this->alias}"; |
| 80 | } |
| 81 | |
| 82 | // }}} |
| 83 | // {{{ function _mail_body |
| 84 | |
| 85 | function _mail_body($isok) |
| 86 | { |
| 87 | if ($isok) { |
| 88 | return " L'adresse mail {$this->alias} que tu avais demandée vient d'être créée, tu peux désormais l'utiliser à ta convenance.".(($this->public == 'public')?" A ta demande, cette adresse apparaît maintenant sur ta fiche.":""); |
| 89 | } else { |
| 90 | return " La demande que tu avais faite pour l'alias {$this->alias} a été refusée."; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | // }}} |
| 95 | // {{{ function commit() |
| 96 | |
| 97 | function commit () |
| 98 | { |
| 99 | global $globals; |
| 100 | |
| 101 | $globals->xdb->execute("UPDATE auth_user_quick SET emails_alias_pub = {?} WHERE user_id = {?}", $this->public, $this->uid); |
| 102 | |
| 103 | if ($this->old) { |
| 104 | return $globals->xdb->execute('UPDATE virtual SET alias={?} WHERE alias={?}', $this->alias, $this->old); |
| 105 | } else { |
| 106 | $globals->xdb->execute('INSERT INTO virtual SET alias={?},type="user"', $this->alias); |
| 107 | $vid = mysql_insert_id(); |
| 108 | $dom = $globals->mail->shorter_domain(); |
| 109 | return $globals->xdb->query('INSERT INTO virtual_redirect (vid,redirect) VALUES ({?}, {?})', $vid, $this->forlife.'@'.$dom); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | // }}} |
| 114 | } |
| 115 | |
| 116 | // }}} |
| 117 | |
| 118 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: |
| 119 | ?> |