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