| 1 | #!/usr/bin/php5 -q |
| 2 | <?php |
| 3 | /*************************************************************************** |
| 4 | * Copyright (C) 2003-2011 Polytechnique.org * |
| 5 | * http://opensource.polytechnique.org/ * |
| 6 | * * |
| 7 | * This program is free software; you can redistribute it and/or modify * |
| 8 | * it under the terms of the GNU General Public License as published by * |
| 9 | * the Free Software Foundation; either version 2 of the License, or * |
| 10 | * (at your option) any later version. * |
| 11 | * * |
| 12 | * This program is distributed in the hope that it will be useful, * |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 15 | * GNU General Public License for more details. * |
| 16 | * * |
| 17 | * You should have received a copy of the GNU General Public License * |
| 18 | * along with this program; if not, write to the Free Software * |
| 19 | * Foundation, Inc., * |
| 20 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
| 21 | ***************************************************************************/ |
| 22 | |
| 23 | require './connect.db.inc.php'; |
| 24 | require '../include/name.func.inc.php'; |
| 25 | |
| 26 | $globals->debug = 0; // Do not store backtraces |
| 27 | |
| 28 | $opts = getopt('f:p:'); |
| 29 | |
| 30 | if (empty($opts['f']) || empty($opts['p'])) { |
| 31 | print "File name missing (-f=file_name) or promotion missing (-p=file_name).\n"; |
| 32 | exit; |
| 33 | } |
| 34 | |
| 35 | $file = $opts['f']; |
| 36 | $handle = fopen($file, 'r'); |
| 37 | $promo_year = $opts['p']; |
| 38 | |
| 39 | $already = array(); |
| 40 | $new = array(); |
| 41 | $ambiguous = array(); |
| 42 | |
| 43 | while ($line = trim(fgets($handle))) { |
| 44 | $data = explode(';', $line); |
| 45 | $cond = new PFC_And(new UFC_NameTokens(split_name_for_search($data[0]), array(), false, false, Profile::LASTNAME)); |
| 46 | $cond->addChild(new UFC_NameTokens(split_name_for_search($data[1]), array(), false, false, Profile::FIRSTNAME)); |
| 47 | $uf = new UserFilter($cond); |
| 48 | $profiles = $uf->getProfiles(); |
| 49 | switch (count($profiles)) { |
| 50 | case 0: |
| 51 | $new[] = $line; |
| 52 | break; |
| 53 | case 1: |
| 54 | foreach ($profiles as $profile) { |
| 55 | $already[] = $profile->hrid(); |
| 56 | } |
| 57 | break; |
| 58 | default: |
| 59 | $hrids = array(); |
| 60 | foreach ($profiles as $profile) { |
| 61 | $hrids[] = $profile->hrid(); |
| 62 | } |
| 63 | $ambiguous[] = $line . ': ' . implode(', ', $hrids); |
| 64 | break; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | $cond = new UFC_Promo('=', UserFilter::GRADE_MST, $promo_year); |
| 69 | $uf = new UserFilter($cond); |
| 70 | $profiles = $uf->getProfiles(); |
| 71 | $promo = array(); |
| 72 | foreach ($profiles as $profile) { |
| 73 | $promo[] = $profile->hrid(); |
| 74 | } |
| 75 | |
| 76 | $intersect = array_intersect($promo, $already); |
| 77 | if (count($intersect) != count($already)) { |
| 78 | print "There seems to be a problem: intersection of this promo and already found users differ.\n"; |
| 79 | } |
| 80 | $to_remove = array_diff($promo, $intersect); |
| 81 | |
| 82 | sort($new); |
| 83 | sort($ambiguous); |
| 84 | sort($to_remove); |
| 85 | |
| 86 | print "New users:\n" . implode("\n", $new) . "\n\n"; |
| 87 | print "Ambiguous users:\n" . implode("\n", $ambiguous) . "\n\n"; |
| 88 | print "Users to remove (louk out for ambiguous users before!):\n" . implode("\n", $to_remove) . "\n"; |
| 89 | |
| 90 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 91 | ?> |