| 1 | #!/usr/bin/php5 -q |
| 2 | <?php |
| 3 | /*************************************************************************** |
| 4 | * Copyright (C) 2003-2010 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_once 'connect.db.inc.php'; |
| 24 | require_once 'plmailer.php'; |
| 25 | global $globals; |
| 26 | |
| 27 | $res = XDB::iterator('SELECT p.hrpid, pm.pid, a.full_name, pm.field, pm.oldText, pm.newText, p.sex, pd.yourself, al.alias |
| 28 | FROM profile_modifications AS pm |
| 29 | INNER JOIN accounts AS a ON (pm.uid = a.uid) |
| 30 | INNER JOIN profiles AS p ON (pm.pid = p.pid) |
| 31 | INNER JOIN profile_display AS pd ON (pm.pid = pd.pid) |
| 32 | INNER JOIN account_profiles AS ap ON (pm.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms)) |
| 33 | INNER JOIN aliases AS al ON (ap.uid = al.uid AND FIND_IN_SET(\'bestalias\', al.flags)) |
| 34 | ORDER BY pm.pid, pm.field'); |
| 35 | |
| 36 | if ($res->total() > 0) { |
| 37 | $date = time(); |
| 38 | $values = $res->next(); |
| 39 | |
| 40 | $pid = $values['pid']; |
| 41 | $sex = ($values['sex'] == 'female') ? 1 : 0; |
| 42 | $yourself = $values['yourself']; |
| 43 | $alias = $values['alias']; |
| 44 | $hrpid = $values['hrpid']; |
| 45 | $modifications = array(); |
| 46 | $modifications[] = array( |
| 47 | 'full_name' => $values['full_name'], |
| 48 | 'field' => $values['field'], |
| 49 | 'oldText' => $values['oldText'], |
| 50 | 'newText' => $values['newText'], |
| 51 | ); |
| 52 | |
| 53 | while ($values = $res->next()) { |
| 54 | if ($values['pid'] != $pid) { |
| 55 | $mailer = new PlMailer('profile/notification.mail.tpl'); |
| 56 | $mailer->addTo($alias . '@' . $globals->mail->domain); |
| 57 | $mailer->assign('modifications', $modifications); |
| 58 | $mailer->assign('yourself', $yourself); |
| 59 | $mailer->assign('hrpid', $hrpid); |
| 60 | $mailer->assign('sex', $sex); |
| 61 | $mailer->assign('date', $date); |
| 62 | $mailer->send(); |
| 63 | $modifications = array(); |
| 64 | } |
| 65 | $pid = $values['pid']; |
| 66 | $sex = ($values['sex'] == 'female') ? 1 : 0; |
| 67 | $yourself = $values['yourself']; |
| 68 | $alias = $values['alias']; |
| 69 | $hrpid = $values['hrpid']; |
| 70 | $modifications[] = array( |
| 71 | 'full_name' => $values['full_name'], |
| 72 | 'field' => $values['field'], |
| 73 | 'oldText' => $values['oldText'], |
| 74 | 'newText' => $values['newText'], |
| 75 | ); |
| 76 | } |
| 77 | $mailer = new PlMailer('profile/notification.mail.tpl'); |
| 78 | $mailer->addTo($alias . '@' . $globals->mail->domain); |
| 79 | $mailer->assign('modifications', $modifications); |
| 80 | $mailer->assign('yourself', $yourself); |
| 81 | $mailer->assign('hrpid', $hrpid); |
| 82 | $mailer->assign('sex', $sex); |
| 83 | $mailer->assign('date', $date); |
| 84 | $mailer->send(); |
| 85 | |
| 86 | XDB::execute('DELETE FROM profile_modifications'); |
| 87 | } |
| 88 | |
| 89 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 90 | ?> |