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