3 /***************************************************************************
4 * Copyright (C) 2003-2011 Polytechnique.org *
5 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
21 ***************************************************************************/
23 require '../../bin/connect.db.inc.php';
25 $globals->debug
= 0; // Do not store backtraces
27 $res = XDB
::rawFetchAllAssoc("SELECT p.pid, p.ax_id, p.hrpid,
28 f.Nom_patronymique, f.Nom_usuel, f.Nom_complet,
29 ppn.lastname_initial, ppn.lastname_main, ppn.lastname_marital, ppn.lastname_ordinary
30 FROM fusionax_anciens AS f
31 INNER JOIN profiles AS p ON (f.ax_id = p.ax_id)
32 INNER JOIN profile_public_names AS ppn ON (p.pid = ppn.pid)
33 WHERE IF(f.partic_patro, CONCAT(f.partic_patro, CONCAT(' ', f.Nom_patronymique)), f.Nom_patronymique) NOT IN (ppn.lastname_initial, ppn.lastname_main, ppn.lastname_marital, ppn.lastname_ordinary)
34 OR IF(f.partic_nom, CONCAT(f.partic_nom, CONCAT(' ', f.Nom_usuel)), f.Nom_usuel) NOT IN (ppn.lastname_initial, ppn.lastname_main, ppn.lastname_marital, ppn.lastname_ordinary)
35 OR f.Nom_complet NOT IN (ppn.lastname_initial, ppn.lastname_main, ppn.lastname_marital, ppn.lastname_ordinary)");
37 function fix_ax_particles($ax, $xorg, $item)
40 foreach ($ax as $ax_key => $ax_name) {
41 if (!in_array($ax_name, $xorg)) {
43 foreach ($xorg as $xorg_key => $xorg_name) {
44 if ($xorg_name && strpos($xorg_name, $ax_name) !== false
) {
45 if ($xorg_name == 'de ' . $ax_name) {
46 $new_name = 'de ' . $item[$ax_key];
47 } elseif ($xorg_name == "d'" . $ax_name) {
48 $new_name = "d'" . $item[$ax_key];
49 } elseif ($xorg_name == 'du ' . $ax_name) {
50 $new_name = 'du ' . $item[$ax_key];
54 XDB
::execute("UPDATE fusionax_anciens
57 $new_name, $item['ax_id']);
66 foreach ($ax as $ax_key2 => $ax_name2) {
67 if ($ax_name2 && strpos($ax_name2, $ax_name) !== false
) {
68 if ($ax_name2 == 'de ' . $ax_name) {
69 $new_name = 'de ' . $item[$ax_key];
70 } elseif ($ax_name2 == "d'" . $ax_name) {
71 $new_name = "d'" . $item[$ax_key];
72 } elseif ($ax_name2 == 'du ' . $ax_name) {
73 $new_name = 'du ' . $item[$ax_key];
77 XDB
::execute("UPDATE fusionax_anciens
80 $new_name, $item['ax_id']);
92 function fix_xorg_particles($ax, $xorg, $item)
95 foreach ($ax as $ax_key => $ax_name) {
96 if (!in_array($ax_name, $xorg)) {
97 foreach ($xorg as $xorg_key => $xorg_name) {
99 if ($xorg_name && strpos($ax_name, $xorg_name) !== false
) {
100 if ($ax_name == 'de ' . $xorg_name) {
101 $new_name = 'de ' . $item[$xorg_key];
102 } elseif ($ax_name == "d'" . $xorg_name) {
103 $new_name = "d'" . $item[$xorg_key];
104 } elseif ($ax_name == 'du ' . $xorg_name) {
105 $new_name = 'du ' . $item[$xorg_key];
109 XDB
::execute("UPDATE profile_public_names
112 $new_name, $item['pid']);
124 function fix_xorg_full_name($ax, $xorg, $item)
127 if (!in_array($ax['Nom_complet'], $xorg) && strpos($ax['Nom_complet'], $xorg['lastname_main']) !== false
&& $xorg['lastname_ordinary'] == '') {
128 XDB
::execute("UPDATE profile_public_names
129 SET lastname_main = {?}, lastname_ordinary = {?}
131 $item['Nom_complet'], $item['lastname_main'], $item['pid']);
138 function fix_xorg_ordinary_name($ax, $xorg, $item)
141 if (!in_array($ax['Nom_usuel'], $xorg) && $xorg['lastname_ordinary'] == '') {
142 XDB
::execute("UPDATE profile_public_names
143 SET lastname_ordinary = {?}
145 $item['Nom_usuel'], $item['pid']);
152 function format($string)
154 $string = preg_replace('/\-/', ' ', $string);
155 return preg_replace('/\s+/', ' ', $string);
160 $total = count($res);
161 foreach($res as $item) {
162 array_map('trim', $item);
164 'Nom_patronymique' => format(mb_strtolower(replace_accent($item['Nom_patronymique']))),
165 'Nom_usuel' => format(mb_strtolower(replace_accent($item['Nom_usuel']))),
166 'Nom_complet' => format(mb_strtolower(replace_accent($item['Nom_complet'])))
169 'lastname_initial' => format(mb_strtolower(replace_accent($item['lastname_initial']))),
170 'lastname_main' => format(mb_strtolower(replace_accent($item['lastname_main']))),
171 'lastname_ordinary' => format(mb_strtolower(replace_accent($item['lastname_ordinary'])))
174 $updates_count +
= fix_ax_particles($ax, $xorg, $item);
175 $updates_count +
= fix_xorg_particles($ax, $xorg, $item);
176 $updates_count +
= fix_xorg_full_name($ax, $xorg, $item);
177 $updates_count +
= fix_xorg_ordinary_name($ax, $xorg, $item);
178 printf("\r%u / %u", $count, $total);
181 printf("\r%u / %u\n\n", $count, $total);
183 echo "Nombre de mises à jour effectuées : " . $updates_count . ".\n";
185 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: