Commit | Line | Data |
---|---|---|
b9ad0878 PC |
1 | <?php |
2 | /*************************************************************************** | |
d4c08d89 | 3 | * Copyright (C) 2003-2010 Polytechnique.org * |
b9ad0878 PC |
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 | ||
c15c0053 | 22 | /** |
ddc4c642 SJ |
23 | * Module to merge data from AX database: this will only be used once on |
24 | * production site and should be removed afterwards. | |
c15c0053 PC |
25 | * |
26 | * Module to import data from another database of alumni that had | |
27 | * different schemas. The organization that used this db is called AX | |
28 | * hence the name of this module. | |
29 | * | |
ddc4c642 | 30 | * Datas are stored in an export file. |
c15c0053 | 31 | */ |
73be4434 SJ |
32 | class FusionAxModule extends PLModule |
33 | { | |
b9ad0878 PC |
34 | function handlers() |
35 | { | |
36 | return array( | |
29459c49 SJ |
37 | 'fusionax' => $this->make_hook('index', AUTH_MDP, 'admin'), |
38 | 'fusionax/import' => $this->make_hook('import', AUTH_MDP, 'admin'), | |
39 | 'fusionax/view' => $this->make_hook('view', AUTH_MDP, 'admin'), | |
40 | 'fusionax/ids' => $this->make_hook('ids', AUTH_MDP, 'admin'), | |
41 | 'fusionax/deceased' => $this->make_hook('deceased', AUTH_MDP, 'admin'), | |
c7eac294 | 42 | 'fusionax/promo' => $this->make_hook('promo', AUTH_MDP, 'admin'), |
a3f12425 | 43 | 'fusionax/names' => $this->make_hook('names', AUTH_MDP, 'admin'), |
b9ad0878 PC |
44 | ); |
45 | } | |
c15c0053 PC |
46 | |
47 | ||
b9ad0878 PC |
48 | function handler_index(&$page) |
49 | { | |
b9ad0878 | 50 | $page->changeTpl('fusionax/index.tpl'); |
73be4434 | 51 | $page->assign('xorg_title', 'Polytechnique.org - Fusion des annuaires'); |
b9ad0878 | 52 | } |
22f043e4 | 53 | |
73be4434 | 54 | /** Import de l'annuaire de l'AX depuis l'export situé dans le home de jacou */ |
ddc4c642 | 55 | function handler_import(&$page, $action = 'index', $file = '') |
b9ad0878 PC |
56 | { |
57 | if ($action == 'index') { | |
58 | $page->changeTpl('fusionax/import.tpl'); | |
b9ad0878 PC |
59 | return; |
60 | } | |
22f043e4 | 61 | |
cc8ea8b2 | 62 | // toutes les actions sont faites en ajax en utilisant jquery |
ddc4c642 | 63 | header('Content-type: text/javascript; charset=utf-8'); |
22f043e4 | 64 | |
cc8ea8b2 PC |
65 | // log des actions |
66 | $report = array(); | |
22f043e4 | 67 | |
73be4434 | 68 | $modulepath = realpath(dirname(__FILE__) . '/fusionax/') . '/'; |
ddc4c642 | 69 | $spoolpath = realpath(dirname(__FILE__) . '/../spool/fusionax/') . '/'; |
22f043e4 | 70 | |
b9ad0878 | 71 | if ($action == 'launch') { |
ddc4c642 SJ |
72 | if ($file == '') { |
73 | $report[] = 'Nom de fichier non renseigné.'; | |
74 | } elseif (!file_exists(dirname(__FILE__) . '/../spool/fusionax/' . $file)) { | |
75 | $report[] = 'Le fichier ne se situe pas au bon endroit.'; | |
76 | } else { | |
77 | // séparation de l'archive en fichiers par tables | |
78 | $file = $spoolpath . $file; | |
79 | // Removes master and doctorate students | |
80 | exec('grep -v "^[A-Z]\{2\}.[0-9]\{4\}[MD][0-9]\{3\}" ' . $file . ' > ' . $file . '.tmp'); | |
81 | exec('mv -f ' . $file . '.tmp ' . $file); | |
82 | // Split export into specialised files | |
83 | exec('grep "^AD" ' . $file . ' > ' . $spoolpath . 'Adresses.txt'); | |
84 | exec('grep "^AN" ' . $file . ' > ' . $spoolpath . 'Anciens.txt'); | |
85 | exec('grep "^FO" ' . $file . ' > ' . $spoolpath . 'Formations.txt'); | |
86 | exec('grep "^AC" ' . $file . ' > ' . $spoolpath . 'Activites.txt'); | |
87 | exec('grep "^EN" ' . $file . ' > ' . $spoolpath . 'Entreprises.txt'); | |
88 | exec($modulepath . 'formation.pl'); | |
89 | exec('mv -f ' . $spoolpath . 'Formations_out.txt ' . $spoolpath . 'Formations.txt'); | |
90 | $report[] = 'Fichier parsé.'; | |
91 | $report[] = 'Import dans la base en cours...'; | |
92 | $next = 'integrateSQL'; | |
93 | } | |
73be4434 | 94 | } elseif ($action == 'integrateSQL') { |
cc8ea8b2 PC |
95 | // intégration des données dans la base MySQL |
96 | // liste des fichiers sql à exécuter | |
97 | $filesSQL = array( | |
ddc4c642 SJ |
98 | 0 => 'Activites.sql', |
99 | 1 => 'Adresses.sql', | |
100 | 2 => 'Anciens.sql', | |
101 | 3 => 'Formations.sql', | |
102 | 4 => 'Entreprises.sql' | |
103 | ); | |
104 | if ($file != '') { | |
cc8ea8b2 | 105 | // récupère le contenu du fichier sql |
ddc4c642 | 106 | $queries = explode(';', file_get_contents($modulepath . $filesSQL[$file])); |
73be4434 SJ |
107 | foreach ($queries as $q) { |
108 | if (trim($q)) { | |
109 | // coupe le fichier en requêtes individuelles | |
110 | if (substr($q, 0, 2) == '--') { | |
111 | // affiche les commentaires dans le report | |
112 | $lines = explode("\n", $q); | |
113 | $l = $lines[0]; | |
114 | $report[] = addslashes($l); | |
115 | } | |
116 | // exécute la requête | |
ddc4c642 | 117 | XDB::execute(str_replace('{?}', $spoolpath, $q)); |
b9ad0878 | 118 | } |
b9ad0878 | 119 | } |
cc8ea8b2 | 120 | // trouve le prochain fichier à exécuter |
ddc4c642 | 121 | $nextfile = $file + 1; |
b9ad0878 PC |
122 | } else { |
123 | $nextfile = 0; | |
124 | } | |
ddc4c642 SJ |
125 | if ($nextfile > 4) { |
126 | // tous les fichiers ont été exécutés, on passe à l'étape suivante | |
127 | $next = 'adds1920'; | |
b9ad0878 | 128 | } else { |
cc8ea8b2 | 129 | // on passe au fichier suivant |
ddc4c642 SJ |
130 | $next = 'integrateSQL/' . $nextfile; |
131 | } | |
132 | } elseif ($action == 'adds1920') { | |
133 | // Adds promotion 1920 from AX db. | |
134 | $report[] = 'Ajout de la promotion 1920'; | |
135 | $res = XDB::iterator('SELECT prenom, Nom_complet, ax_id | |
136 | FROM fusionax_anciens | |
137 | WHERE promotion_etude = 1920;'); | |
138 | ||
139 | $nameTypes = DirEnum::getOptions(DirEnum::NAMETYPES); | |
140 | $nameTypes = array_flip($nameTypes); | |
141 | $eduSchools = DirEnum::getOptions(DirEnum::EDUSCHOOLS); | |
142 | $eduSchools = array_flip($eduSchools); | |
143 | $eduDegrees = DirEnum::getOptions(DirEnum::EDUDEGREES); | |
144 | $eduDegrees = array_flip($eduDegrees); | |
145 | $degreeid = $eduDegrees[Profile::DEGREE_X]; | |
146 | $entry_year = 1920; | |
147 | $grad_year = 1923; | |
148 | $promo = 'X1920'; | |
149 | $sex = PlUser::GENDER_MALE; | |
150 | $xorgId = 19200000; | |
151 | $type = 'x'; | |
152 | ||
153 | while (list($firstname, $lastname, $ax_id) = $res->next()) { | |
154 | $hrid = self::getHrid($firstname, $lastname, $promo); | |
155 | $res1 = XDB::query('SELECT COUNT(*) | |
156 | FROM accounts | |
157 | WHERE hruid = {?}', $hrid); | |
158 | $res2 = XDB::query('SELECT COUNT(*) | |
159 | FROM profiles | |
160 | WHERE hrpid = {?}', $hrid); | |
161 | if (is_null($hrid) || $res1->fetchOneCell() > 0 || $res2->fetchOneCell() > 0) { | |
162 | $report[] = $ax_id . ' non ajouté'; | |
163 | } | |
164 | $fullName = $firstname . ' ' . $lastname; | |
165 | $directoryName = $lastname . ' ' . $firstname; | |
166 | ++$xorgId; | |
167 | ||
168 | XDB::execute('REPLACE INTO profiles (hrpid, xorg_id, ax_id, sex) | |
169 | VALUES ({?}, {?}, {?}, {?})', | |
170 | $hrid, $xorgId, $ax_id, $sex); | |
171 | $pid = XDB::insertId(); | |
172 | XDB::execute('REPLACE INTO profile_name (pid, name, typeid) | |
173 | VALUES ({?}, {?}, {?})', | |
174 | $pid, $lastname, $nameTypes['name_ini']); | |
175 | XDB::execute('REPLACE INTO profile_name (pid, name, typeid) | |
176 | VALUES ({?}, {?}, {?})', | |
177 | $pid, $firstname, $nameTypes['firstname_ini']); | |
178 | XDB::execute('REPLACE INTO profile_display (pid, yourself, public_name, private_name, | |
179 | directory_name, short_name, sort_name, promo) | |
180 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', | |
181 | $pid, $firstname, $fullName, $fullName, $directoryName, $fullName, $directoryName, $promo); | |
182 | XDB::execute('REPLACE INTO profile_education (pid, eduid, degreeid, entry_year, grad_year, flags) | |
183 | VALUES ({?}, {?}, {?}, {?}, {?}, {?})', | |
184 | $pid, $eduSchools[Profile::EDU_X], $degreeid, $entry_year, $grad_year, 'primary'); | |
185 | XDB::execute('REPLACE INTO accounts (hruid, type, is_admin, state, full_name, directory_name, display_name, sex) | |
186 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})', | |
187 | $hrid, $type, 0, 'active', $fullName, $directoryName, $lastname, $sex); | |
188 | $uid = XDB::insertId(); | |
189 | XDB::execute('REPLACE INTO account_profiles (uid, pid, perms) | |
190 | VALUES ({?}, {?}, {?})', | |
191 | $uid, $pid, 'owner'); | |
b9ad0878 | 192 | } |
ddc4c642 SJ |
193 | $report[] = 'Promo 1920 ajoutée.'; |
194 | $next = 'view'; | |
195 | } elseif ($action == 'view') { | |
196 | XDB::execute('CREATE OR REPLACE ALGORITHM=MERGE VIEW fusionax_xorg_anciens AS | |
197 | SELECT p.pid, p.ax_id, pd.promo, pd.private_name, pd.public_name, | |
198 | pd.sort_name, pd.short_name, pd.directory_name | |
199 | FROM profiles AS p | |
200 | INNER JOIN profile_display AS pd USING(pid)'); | |
201 | $next = 'clean'; | |
73be4434 | 202 | } elseif ($action == 'clean') { |
cc8ea8b2 | 203 | // nettoyage du fichier temporaire |
ddc4c642 SJ |
204 | exec('rm -Rf ' . $spoolpath); |
205 | $report[] = 'Import finit.'; | |
b9ad0878 | 206 | } |
73be4434 | 207 | foreach($report as $t) { |
cc8ea8b2 | 208 | // affiche les lignes de report |
ddc4c642 | 209 | echo "$('#fusionax').append('" . $t . "<br/>');\n"; |
73be4434 | 210 | } |
b9ad0878 | 211 | if (isset($next)) { |
cc8ea8b2 | 212 | // lance le prochain script s'il y en a un |
ddc4c642 | 213 | echo "$.getScript('fusionax/import/" . $next . "');"; |
b9ad0878 | 214 | } |
cc8ea8b2 | 215 | // exit pour ne pas afficher la page template par défaut |
b9ad0878 PC |
216 | exit; |
217 | } | |
22f043e4 | 218 | |
29459c49 SJ |
219 | function handler_view(&$page, $action = '') |
220 | { | |
29459c49 SJ |
221 | $page->changeTpl('fusionax/view.tpl'); |
222 | if ($action == 'create') { | |
223 | XDB::execute('DROP VIEW IF EXISTS fusionax_deceased'); | |
224 | XDB::execute('CREATE VIEW fusionax_deceased AS | |
ddc4c642 SJ |
225 | SELECT p.pid, a.ax_id, pd.private_name, pd.promo, p.deathdate AS deces_xorg, a.Date_deces AS deces_ax |
226 | FROM profiles AS p | |
227 | INNER JOIN profile_display AS pd ON (p.pid = pd.pid) | |
228 | INNER JOIN fusionax_anciens AS a ON (a.ax_id = p.ax_id) | |
229 | WHERE p.deathdate != a.Date_deces'); | |
29459c49 SJ |
230 | XDB::execute('DROP VIEW IF EXISTS fusionax_promo'); |
231 | XDB::execute('CREATE VIEW fusionax_promo AS | |
ddc4c642 SJ |
232 | SELECT p.pid, p.ax_id, pd.private_name, pd.promo, pe.entry_year AS promo_etude_xorg, |
233 | f.promotion_etude AS promo_etude_ax, pe.grad_year AS promo_sortie_xorg | |
234 | FROM profiles AS p | |
235 | INNER JOIN profile_display AS pd ON (p.pid = pd.pid) | |
236 | INNER JOIN profile_education AS pe ON (p.pid = pe.pid) | |
237 | INNER JOIN fusionax_anciens AS f ON (p.ax_id = f.ax_id) | |
238 | WHERE pd.promo != CONCAT(\'X\', f.promotion_etude) | |
239 | AND !(f.promotion_etude = pe.entry_year + 1 AND pe.grad_year = pe.entry_year + 4)'); | |
240 | $page->trigSuccess('Les VIEW ont bien été créées.'); | |
29459c49 SJ |
241 | } |
242 | } | |
243 | ||
244 | /* Mets à NULL le matricule_ax de ces camarades pour marquer le fait qu'ils ne figurent pas dans l'annuaire de l'AX */ | |
ddc4c642 | 245 | private static function clear_wrong_in_xorg($pid) |
29459c49 | 246 | { |
ddc4c642 SJ |
247 | $res = XDB::execute('UPDATE fusionax_xorg_anciens |
248 | SET ax_id = NULL | |
249 | WHERE pid = {?}', $pid); | |
29459c49 SJ |
250 | if (!$res) { |
251 | return 0; | |
252 | } | |
253 | return XDB::affectedRows() / 2; | |
254 | } | |
255 | ||
aab2ffdd | 256 | /* Cherche les les anciens présents dans Xorg avec un matricule_ax ne correspondant à rien dans la base de l'AX |
29459c49 SJ |
257 | * (mises à part les promo 1921 et 1923 qui ne figurent pas dans les données de l'AX)*/ |
258 | private static function find_wrong_in_xorg($limit = 10) | |
259 | { | |
ddc4c642 | 260 | return XDB::iterator('SELECT u.promo, u.pid, u.private_name |
29459c49 SJ |
261 | FROM fusionax_xorg_anciens AS u |
262 | WHERE NOT EXISTS (SELECT * | |
263 | FROM fusionax_anciens AS f | |
ddc4c642 SJ |
264 | WHERE f.ax_id = u.ax_id) |
265 | AND u.ax_id IS NOT NULL AND promo != \'X1921\' AND promo != \'X1923\''); | |
29459c49 SJ |
266 | } |
267 | ||
b65beb64 PC |
268 | /** Lier les identifiants d'un ancien dans les deux annuaires |
269 | * @param user_id identifiant dans l'annuaire X.org | |
270 | * @param matricule_ax identifiant dans l'annuaire de l'AX | |
271 | * @return 0 si la liaison a échoué, 1 sinon | |
22f043e4 | 272 | */ |
ddc4c642 | 273 | private static function link_by_ids($pid, $ax_id) |
b9ad0878 | 274 | { |
ddc4c642 | 275 | $res = XDB::execute('UPDATE fusionax_import AS i |
73be4434 | 276 | INNER JOIN fusionax_xorg_anciens AS u |
ddc4c642 SJ |
277 | SET u.ax_id = i.ax_id, |
278 | i.pid = u.pid, | |
73be4434 | 279 | i.date_match_id = NOW() |
ddc4c642 SJ |
280 | WHERE i.ax_id = {?} AND u.pid = {?} |
281 | AND (u.ax_id != {?} OR u.ax_id IS NULL | |
282 | OR i.pid != {?} OR i.pid IS NULL)', | |
283 | $ax_id, $pid, $ax_id, $pid); | |
73be4434 | 284 | if (!$res) { |
b9ad0878 PC |
285 | return 0; |
286 | } | |
73be4434 | 287 | return XDB::affectedRows() / 2; |
b9ad0878 | 288 | } |
22f043e4 | 289 | |
b65beb64 PC |
290 | /** Recherche automatique d'anciens à lier entre les deux annuaires |
291 | * @param limit nombre d'anciens à trouver au max | |
292 | * @param sure si true, ne trouve que des anciens qui sont quasi sûrs | |
e8591429 | 293 | * @return un XOrgDBIterator sur les entrées avec display_name, promo, |
ddc4c642 | 294 | * pid, ax_id et display_name_ax |
22f043e4 | 295 | */ |
b65beb64 | 296 | private static function find_easy_to_link($limit = 10, $sure = false) |
b9ad0878 | 297 | { |
e8591429 | 298 | $easy_to_link = XDB::iterator(" |
ddc4c642 SJ |
299 | SELECT u.private_name, u.promo, u.pid, ax.ax_id, |
300 | CONCAT(ax.prenom, ' ', ax.nom_complet, ' (X', ax.promotion_etude, ')') AS display_name_ax, | |
73be4434 | 301 | COUNT(*) AS nbMatches |
29459c49 | 302 | FROM fusionax_anciens AS ax |
ddc4c642 SJ |
303 | INNER JOIN fusionax_import AS i ON (i.ax_id = ax.ax_id AND i.pid IS NULL) |
304 | LEFT JOIN fusionax_xorg_anciens AS u ON (u.ax_id IS NULL | |
305 | AND u.promo = CONCAT('X', ax.promotion_etude) | |
306 | AND (CONCAT(ax.prenom, ' ', ax.nom_complet) = u.private_name | |
307 | OR CONCAT(ax.prenom, ' ', ax.nom_complet) = u.public_name | |
308 | OR CONCAT(ax.prenom, ' ', ax.nom_complet) = u.short_name)) | |
309 | GROUP BY u.pid | |
310 | HAVING u.pid IS NOT NULL AND nbMatches = 1" . ($limit ? (' LIMIT ' . $limit) : '')); | |
b65beb64 PC |
311 | if ($easy_to_link->total() > 0 || $sure) { |
312 | return $easy_to_link; | |
313 | } | |
73be4434 | 314 | return XDB::iterator(" |
ddc4c642 SJ |
315 | SELECT u.private_name, u.promo, u.pid, ax.ax_id, |
316 | CONCAT(ax.prenom, ' ', ax.nom_complet, ' (X', ax.promotion_etude, ')') AS display_name_ax, | |
73be4434 | 317 | COUNT(*) AS nbMatches |
29459c49 | 318 | FROM fusionax_anciens AS ax |
ddc4c642 SJ |
319 | INNER JOIN fusionax_import AS i ON (i.ax_id = ax.ax_id AND i.pid IS NULL) |
320 | LEFT JOIN fusionax_xorg_anciens AS u ON (u.ax_id IS NULL | |
321 | AND (CONCAT(ax.prenom, ' ', ax.nom_complet) = u.private_name | |
322 | OR CONCAT(ax.prenom, ' ', ax.nom_complet) = u.public_name | |
323 | OR CONCAT(ax.prenom, ' ', ax.nom_complet) = u.short_name) | |
324 | AND u.promo < CONCAT('X', ax.promotion_etude + 2) | |
325 | AND u.promo > CONCAT('X', ax.promotion_etude - 2)) | |
326 | GROUP BY u.pid | |
327 | HAVING u.pid IS NOT NULL AND nbMatches = 1" . ($limit ? (' LIMIT ' . $limit) : '')); | |
b9ad0878 | 328 | } |
22f043e4 | 329 | |
b65beb64 | 330 | /** Module de mise en correspondance les ids */ |
ddc4c642 | 331 | function handler_ids(&$page, $part = 'main', $pid = null, $ax_id = null) |
b9ad0878 | 332 | { |
29459c49 | 333 | $nbToLink = 100; |
29459c49 | 334 | $page->assign('xorg_title', 'Polytechnique.org - Fusion - Mise en correspondance simple'); |
ddc4c642 | 335 | |
73be4434 | 336 | if ($part == 'missingInAX') { |
b9ad0878 PC |
337 | // locate all persons from this database that are not in AX's |
338 | $page->changeTpl('fusionax/idsMissingInAx.tpl'); | |
ddc4c642 | 339 | $missingInAX = XDB::iterator('SELECT promo, pid, private_name |
29459c49 | 340 | FROM fusionax_xorg_anciens |
ddc4c642 | 341 | WHERE ax_id IS NULL'); |
b9ad0878 PC |
342 | $page->assign('missingInAX', $missingInAX); |
343 | return; | |
344 | } | |
73be4434 | 345 | if ($part == 'missingInXorg') { |
b9ad0878 PC |
346 | // locate all persons from AX's database that are not here |
347 | $page->changeTpl('fusionax/idsMissingInXorg.tpl'); | |
ddc4c642 SJ |
348 | $missingInXorg = XDB::iterator("SELECT CONCAT(a.prenom, ' ', a.Nom_usuel) AS private_name, |
349 | a.promotion_etude AS promo, a.ax_id | |
73be4434 | 350 | FROM fusionax_import |
ddc4c642 SJ |
351 | INNER JOIN fusionax_anciens AS a USING (ax_id) |
352 | WHERE fusionax_import.pid IS NULL"); | |
b9ad0878 PC |
353 | $page->assign('missingInXorg', $missingInXorg); |
354 | return; | |
355 | } | |
29459c49 SJ |
356 | if ($part == 'wrongInXorg') { |
357 | // locate all persons from Xorg database that have a bad AX id | |
358 | $page->changeTpl('fusionax/idswrongInXorg.tpl'); | |
359 | $wrongInXorg = FusionAxModule::find_wrong_in_xorg($nbToLink); | |
360 | $page->assign('wrongInXorg', $wrongInXorg); | |
361 | return; | |
362 | } | |
363 | if ($part == 'cleanwronginxorg') { | |
364 | $linksToDo = FusionAxModule::find_wrong_in_xorg($nbToLink); | |
365 | while ($l = $linksToDo->next()) { | |
ddc4c642 | 366 | FusionAxModule::clear_wrong_in_xorg($l['pid']); |
29459c49 SJ |
367 | } |
368 | pl_redirect('fusionax/ids/wrongInXorg'); | |
369 | } | |
370 | if ($part == 'lier') { | |
371 | if (Post::has('user_id') && Post::has('matricule_ax')) { | |
ddc4c642 | 372 | FusionAxModule::link_by_ids(Post::i('pid'), Post::v('ax_id')); |
29459c49 SJ |
373 | } |
374 | } | |
73be4434 | 375 | if ($part == 'link') { |
ddc4c642 | 376 | FusionAxModule::link_by_ids($pid, $ax_id); |
b65beb64 | 377 | exit; |
b9ad0878 | 378 | } |
73be4434 | 379 | if ($part == 'linknext') { |
29459c49 | 380 | $linksToDo = FusionAxModule::find_easy_to_link($nbToLink); |
73be4434 | 381 | while ($l = $linksToDo->next()) { |
ddc4c642 | 382 | FusionAxModule::link_by_ids($l['pid'], $l['ax_id']); |
b9ad0878 | 383 | } |
b65beb64 | 384 | pl_redirect('fusionax/ids#autolink'); |
b9ad0878 | 385 | } |
73be4434 | 386 | if ($part == 'linkall') { |
b9ad0878 | 387 | $linksToDo = FusionAxModule::find_easy_to_link(0); |
73be4434 | 388 | while ($l = $linksToDo->next()) { |
ddc4c642 | 389 | FusionAxModule::link_by_ids($l['pid'], $l['ax_id']); |
b9ad0878 PC |
390 | } |
391 | } | |
392 | { | |
393 | $page->changeTpl('fusionax/ids.tpl'); | |
73be4434 | 394 | $missingInAX = XDB::query('SELECT COUNT(*) |
ddc4c642 SJ |
395 | FROM fusionax_xorg_anciens |
396 | WHERE ax_id IS NULL'); | |
73be4434 | 397 | if ($missingInAX) { |
b9ad0878 PC |
398 | $page->assign('nbMissingInAX', $missingInAX->fetchOneCell()); |
399 | } | |
73be4434 | 400 | $missingInXorg = XDB::query('SELECT COUNT(*) |
ddc4c642 SJ |
401 | FROM fusionax_import |
402 | WHERE pid IS NULL'); | |
73be4434 SJ |
403 | if ($missingInXorg) { |
404 | $page->assign('nbMissingInXorg', $missingInXorg->fetchOneCell()); | |
b9ad0878 | 405 | } |
29459c49 SJ |
406 | $wrongInXorg = FusionAxModule::find_wrong_in_xorg($nbToLink); |
407 | if ($wrongInXorg->total() > 0) { | |
408 | $page->assign('wrongInXorg', $wrongInXorg->total()); | |
409 | } | |
410 | $easyToLink = FusionAxModule::find_easy_to_link($nbToLink); | |
411 | if ($easyToLink->total() > 0) { | |
412 | $page->assign('nbMatch', $easyToLink->total()); | |
b9ad0878 PC |
413 | $page->assign('easyToLink', $easyToLink); |
414 | } | |
415 | } | |
416 | } | |
22f043e4 | 417 | |
29459c49 | 418 | function handler_deceased(&$page, $action = '') |
b9ad0878 | 419 | { |
29459c49 SJ |
420 | if ($action == 'updateXorg') { |
421 | XDB::execute('UPDATE fusionax_deceased | |
422 | SET deces_xorg = deces_ax | |
423 | WHERE deces_xorg = "0000-00-00"'); | |
424 | } | |
425 | if ($action == 'updateAX') { | |
426 | XDB::execute('UPDATE fusionax_deceased | |
427 | SET deces_ax = deces_xorg | |
428 | WHERE deces_ax = "0000-00-00"'); | |
429 | } | |
430 | if ($action == 'update') { | |
ddc4c642 | 431 | if (Post::has('pid') && Post::has('date')) { |
29459c49 SJ |
432 | XDB::execute('UPDATE fusionax_deceased |
433 | SET deces_ax = {?}, deces_xorg = {?} | |
ddc4c642 SJ |
434 | WHERE pid = {?}', |
435 | Post::v('date'), Post::v('date'), Post::i('pid')); | |
29459c49 SJ |
436 | } |
437 | } | |
438 | $page->changeTpl('fusionax/deceased.tpl'); | |
b9ad0878 | 439 | // deceased |
73be4434 SJ |
440 | $deceasedErrorsSql = XDB::query('SELECT COUNT(*) FROM fusionax_deceased'); |
441 | $page->assign('deceasedErrors', $deceasedErrorsSql->fetchOneCell()); | |
ddc4c642 SJ |
442 | $res = XDB::iterator('SELECT pid, ax_id, promo, private_name, deces_ax |
443 | FROM fusionax_deceased | |
444 | WHERE deces_xorg = "0000-00-00" | |
29459c49 SJ |
445 | LIMIT 10'); |
446 | $page->assign('nbDeceasedMissingInXorg', $res->total()); | |
447 | $page->assign('deceasedMissingInXorg', $res); | |
ddc4c642 SJ |
448 | $res = XDB::iterator('SELECT pid, ax_id, promo, private_name, deces_xorg |
449 | FROM fusionax_deceased | |
450 | WHERE deces_ax = "0000-00-00" | |
29459c49 SJ |
451 | LIMIT 10'); |
452 | $page->assign('nbDeceasedMissingInAX', $res->total()); | |
453 | $page->assign('deceasedMissingInAX', $res); | |
ddc4c642 SJ |
454 | $res = XDB::iterator('SELECT pid, ax_id, promo, private_name, deces_xorg, deces_ax |
455 | FROM fusionax_deceased | |
456 | WHERE deces_xorg != "0000-00-00" AND deces_ax != "0000-00-00"'); | |
29459c49 SJ |
457 | $page->assign('nbDeceasedDifferent', $res->total()); |
458 | $page->assign('deceasedDifferent', $res); | |
b9ad0878 | 459 | } |
c7eac294 SJ |
460 | |
461 | function handler_promo(&$page, $action = '') | |
462 | { | |
463 | $page->changeTpl('fusionax/promo.tpl'); | |
ddc4c642 | 464 | $res = XDB::iterator('SELECT pid, private_name, promo_etude_xorg, promo_sortie_xorg, promo_etude_ax, promo |
c7eac294 | 465 | FROM fusionax_promo |
a3f12425 SJ |
466 | WHERE !(promo_etude_ax + 1 = promo_etude_xorg AND promo_etude_xorg + 3 = promo_sortie_xorg) |
467 | AND !(promo_etude_ax + 1 = promo_etude_xorg AND promo_etude_xorg + 4 = promo_sortie_xorg) | |
468 | AND !(promo_etude_ax = promo_etude_xorg + 1) | |
469 | ORDER BY promo_etude_xorg'); | |
c7eac294 | 470 | $nbMissmatchingPromos = $res->total(); |
a3f12425 SJ |
471 | $page->assign('nbMissmatchingPromos', $res->total()); |
472 | $page->assign('missmatchingPromos', $res); | |
473 | ||
474 | $res = XDB::iterator('SELECT pid, private_name, promo_etude_xorg, promo_sortie_xorg, promo_etude_ax, promo | |
475 | FROM fusionax_promo | |
476 | WHERE promo_etude_ax = promo_etude_xorg + 1 | |
477 | ORDER BY promo_etude_xorg'); | |
478 | $nbMissmatchingPromos += $res->total(); | |
c7eac294 SJ |
479 | $page->assign('nbMissmatchingPromos1', $res->total()); |
480 | $page->assign('missmatchingPromos1', $res); | |
a3f12425 | 481 | |
ddc4c642 | 482 | $res = XDB::iterator('SELECT pid, private_name, promo_etude_xorg, promo_sortie_xorg, promo_etude_ax, promo |
c7eac294 | 483 | FROM fusionax_promo |
a3f12425 SJ |
484 | WHERE promo_etude_ax + 1 = promo_etude_xorg AND promo_etude_xorg + 3 = promo_sortie_xorg |
485 | ORDER BY promo_etude_xorg'); | |
c7eac294 SJ |
486 | $nbMissmatchingPromos += $res->total(); |
487 | $page->assign('nbMissmatchingPromos2', $res->total()); | |
488 | $page->assign('missmatchingPromos2', $res); | |
a3f12425 SJ |
489 | |
490 | $res = XDB::iterator('SELECT pid, private_name, promo_etude_xorg, promo_sortie_xorg, promo_etude_ax, promo | |
491 | FROM fusionax_promo | |
492 | WHERE promo_etude_ax + 1 = promo_etude_xorg AND promo_etude_xorg + 4 = promo_sortie_xorg | |
493 | ORDER BY promo_etude_xorg'); | |
494 | $nbMissmatchingPromos += $res->total(); | |
495 | $page->assign('nbMissmatchingPromos3', $res->total()); | |
496 | $page->assign('missmatchingPromos3', $res); | |
497 | ||
498 | $page->assign('nbMissmatchingPromosTotal', $nbMissmatchingPromos); | |
499 | } | |
500 | ||
501 | function handler_names(&$page, $action = '') | |
502 | { | |
503 | $page->changeTpl('fusionax/names.tpl'); | |
504 | ||
505 | $res = XDB::query('SELECT COUNT(*) | |
506 | FROM fusionax_anciens AS f | |
507 | INNER JOIN profiles AS p ON (f.ax_id = p.ax_id)'); | |
508 | $page->assign('total', $res->fetchOneCell()); | |
509 | ||
510 | // To be checked: | |
511 | // | lastname | 1 | | |
512 | // | lastname_marital | 2 | | |
513 | // | lastname_ordinary | 3 | | |
514 | // | firstname | 4 | | |
515 | // | firstname_ordinary | 7 | | |
516 | // | firstname_other | 8 | | |
517 | // | name_other | 9 | | |
518 | // | name_ini | 10 | | |
519 | // | firstname_ini | 11 | | |
520 | $res = XDB::query("SELECT COUNT(*) | |
521 | FROM fusionax_anciens AS f | |
522 | INNER JOIN profiles AS p ON (f.ax_id = p.ax_id) | |
523 | LEFT JOIN profile_name AS pnp ON (p.pid = pnp.pid AND pnp.typeid = 1) | |
524 | LEFT JOIN profile_name AS pnm ON (p.pid = pnm.pid AND pnm.typeid = 2) | |
525 | LEFT JOIN profile_name AS pno ON (p.pid = pno.pid AND pno.typeid = 3) | |
526 | LEFT JOIN profile_name AS pne ON (p.pid = pne.pid AND pne.typeid = 9) | |
527 | LEFT JOIN profile_name AS pni ON (p.pid = pni.pid AND pni.typeid = 10) | |
528 | WHERE IF(f.partic_patro, CONCAT(f.partic_patro, CONCAT(' ', f.Nom_patronymique)), f.Nom_patronymique) NOT IN (pnp.name, pno.name, pnm.name, pne.name, pni.name) | |
529 | OR IF(f.partic_nom, CONCAT(f.partic_nom, CONCAT(' ', f.Nom_usuel)), f.Nom_usuel) NOT IN (pnp.name, pno.name, pnm.name, pne.name, pni.name) | |
530 | OR f.Nom_complet NOT IN (pnp.name, pno.name, pnm.name, pne.name, pni.name)"); | |
531 | $page->assign('lastnameIssues', $res->fetchOneCell()); | |
532 | ||
533 | $res = XDB::query('SELECT COUNT(*) | |
534 | FROM fusionax_anciens AS f | |
535 | INNER JOIN profiles AS p ON (f.ax_id = p.ax_id) | |
536 | LEFT JOIN profile_name AS pnf ON (p.pid = pnf.pid AND pnf.typeid = 4) | |
537 | LEFT JOIN profile_name AS pno ON (p.pid = pno.pid AND pno.typeid = 7) | |
538 | LEFT JOIN profile_name AS pne ON (p.pid = pne.pid AND pne.typeid = 8) | |
539 | LEFT JOIN profile_name AS pni ON (p.pid = pni.pid AND pni.typeid = 11) | |
540 | WHERE f.prenom NOT IN (pnf.name, pno.name, pne.name, pni.name)'); | |
541 | $page->assign('firstnameIssues', $res->fetchOneCell()); | |
542 | ||
c7eac294 | 543 | } |
b9ad0878 | 544 | } |
e8591429 | 545 | |
a3f12425 SJ |
546 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
547 | ?> |