Adapts bin scripts to new mail chain.
[platal.git] / bin / cron / profile_modification.php
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_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, s.email
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 email_source_account AS s ON (a.uid = s.uid AND FIND_IN_SET(\'bestalias\', s.flags))
34 WHERE pm.type = \'third_party\' AND pm.field != \'deathdate\'
35 ORDER BY pm.pid, pm.field, pm.timestamp');
36
37 if ($res->total() > 0) {
38 $date = time();
39 $values = $res->next();
40
41 $pid = $values['pid'];
42 $sex = ($values['sex'] == 'female') ? 1 : 0;
43 $yourself = $values['yourself'];
44 $alias = $values['email'];
45 $hrpid = $values['hrpid'];
46 $modifications = array();
47 $modifications[] = array(
48 'full_name' => $values['full_name'],
49 'field' => $values['field'],
50 'oldText' => $values['oldText'],
51 'newText' => $values['newText'],
52 );
53
54 while ($values = $res->next()) {
55 if ($values['pid'] != $pid) {
56 $mailer = new PlMailer('profile/notification.mail.tpl');
57 $mailer->addTo($alias . '@' . $globals->mail->domain);
58 $mailer->assign('modifications', $modifications);
59 $mailer->assign('yourself', $yourself);
60 $mailer->assign('hrpid', $hrpid);
61 $mailer->assign('sex', $sex);
62 $mailer->assign('date', $date);
63 $mailer->send();
64 $modifications = array();
65 }
66 $pid = $values['pid'];
67 $sex = ($values['sex'] == 'female') ? 1 : 0;
68 $yourself = $values['yourself'];
69 $alias = $values['alias'];
70 $hrpid = $values['hrpid'];
71 $modifications[] = array(
72 'full_name' => $values['full_name'],
73 'field' => $values['field'],
74 'oldText' => $values['oldText'],
75 'newText' => $values['newText'],
76 );
77 }
78 $mailer = new PlMailer('profile/notification.mail.tpl');
79 $mailer->addTo($alias . '@' . $globals->mail->domain);
80 $mailer->assign('modifications', $modifications);
81 $mailer->assign('yourself', $yourself);
82 $mailer->assign('hrpid', $hrpid);
83 $mailer->assign('sex', $sex);
84 $mailer->assign('date', $date);
85 $mailer->send();
86
87 XDB::execute('DELETE FROM profile_modifications
88 WHERE type = \'third_party\'');
89 }
90
91 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
92 ?>