| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2011 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 | |
| 23 | class BulkAccountsReq extends Validate |
| 24 | { |
| 25 | // {{{ properties |
| 26 | |
| 27 | private $limit = 50; |
| 28 | public $users; |
| 29 | public $group; |
| 30 | |
| 31 | public $rules = "Accepter si les adresses email paraissent correctes, et pas |
| 32 | absurdes et si le demandeur est de confiance."; |
| 33 | // }}} |
| 34 | // {{{ constructor |
| 35 | |
| 36 | public function __construct(User $user, array $uids, $group) |
| 37 | { |
| 38 | parent::__construct($user, false, 'bulkaccounts'); |
| 39 | $this->group = $group; |
| 40 | $this->users = XDB::fetchAllAssoc('SELECT uid, hruid, email |
| 41 | FROM accounts |
| 42 | WHERE uid IN {?}', |
| 43 | $uids); |
| 44 | } |
| 45 | |
| 46 | // }}} |
| 47 | // {{{ function formu() |
| 48 | |
| 49 | public function formu() |
| 50 | { |
| 51 | return 'include/form.valid.bulk_accounts.tpl'; |
| 52 | } |
| 53 | |
| 54 | // }}} |
| 55 | // {{{ function _mail_subj |
| 56 | |
| 57 | protected function _mail_subj() |
| 58 | { |
| 59 | return "[Polytechnique.org] Création de comptes Polytechnique.net"; |
| 60 | } |
| 61 | |
| 62 | // }}} |
| 63 | // {{{ function _mail_body |
| 64 | |
| 65 | protected function _mail_body($isok) |
| 66 | { |
| 67 | if ($isok) { |
| 68 | return " Un email vient d'être envoyé aux personnes concernées pour qu'elles puissent activer leur compte sur Polytechnique.net."; |
| 69 | } else { |
| 70 | return " Nous n'avons pas jugé bon d'activer les comptes Polytechnique.net demandés."; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | // }}} |
| 75 | // {{{ function commit() |
| 76 | |
| 77 | public function commit() |
| 78 | { |
| 79 | $values = array(); |
| 80 | $i = 0; |
| 81 | foreach ($this->users as $user) { |
| 82 | $values[] = XDB::format('({?}, {?}, {?}, NOW(), {?}, {?}, {?})', |
| 83 | $user['uid'], $user['hruid'], $user['email'], rand_url_id(12), $this->user->fullName(), $this->group); |
| 84 | |
| 85 | if ($i == $this->limit) { |
| 86 | XDB::rawExecute('INSERT INTO register_pending_xnet (uid, hruid, email, date, hash, sender_name, group_name) |
| 87 | VALUES ' . implode(', ', $values)); |
| 88 | $i = 0; |
| 89 | $values = array(); |
| 90 | } else { |
| 91 | ++$i; |
| 92 | } |
| 93 | } |
| 94 | XDB::rawExecute('INSERT INTO register_pending_xnet (uid, hruid, email, date, hash, sender_name, group_name) |
| 95 | VALUES ' . implode(', ', $values)); |
| 96 | |
| 97 | return true; |
| 98 | } |
| 99 | |
| 100 | // }}} |
| 101 | // {{{ function isPending() |
| 102 | |
| 103 | static public function isPending($uid) |
| 104 | { |
| 105 | $res = XDB::iterRow('SELECT data |
| 106 | FROM requests |
| 107 | WHERE type = \'bulk_accounts\' |
| 108 | ORDER BY stamp'); |
| 109 | |
| 110 | while (list($data) = $res->next()) { |
| 111 | $request = Validate::unserialize($data); |
| 112 | foreach ($request->users as $user) { |
| 113 | if ($user['uid'] == $uid) { |
| 114 | return true; |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | // }}} |
| 122 | } |
| 123 | |
| 124 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 125 | ?> |