Commit | Line | Data |
---|---|---|
b9ad0878 PC |
1 | <?php |
2 | /*************************************************************************** | |
c441aabe | 3 | * Copyright (C) 2003-2014 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 | 36 | if (Platal::globals()->merge->state == 'pending') { |
12419b5b | 37 | return array( |
bfe9f4c7 SJ |
38 | 'fusionax' => $this->make_hook('index', AUTH_PASSWD, 'admin'), |
39 | 'fusionax/import' => $this->make_hook('import', AUTH_PASSWD, 'admin'), | |
40 | 'fusionax/view' => $this->make_hook('view', AUTH_PASSWD, 'admin'), | |
41 | 'fusionax/ids' => $this->make_hook('ids', AUTH_PASSWD, 'admin'), | |
42 | 'fusionax/deceased' => $this->make_hook('deceased', AUTH_PASSWD, 'admin'), | |
43 | 'fusionax/promo' => $this->make_hook('promo', AUTH_PASSWD, 'admin'), | |
44 | 'fusionax/names' => $this->make_hook('names', AUTH_PASSWD, 'admin'), | |
45 | 'fusionax/edu' => $this->make_hook('edu', AUTH_PASSWD, 'admin'), | |
46 | 'fusionax/corps' => $this->make_hook('corps', AUTH_PASSWD, 'admin') | |
12419b5b | 47 | ); |
654caec5 | 48 | } elseif (Platal::globals()->merge->state == 'done') { |
12419b5b | 49 | return array( |
bfe9f4c7 SJ |
50 | 'fusionax' => $this->make_hook('index', AUTH_PASSWD, 'admin,edit_directory'), |
51 | 'fusionax/issues' => $this->make_hook('issues', AUTH_PASSWD, 'admin,edit_directory'), | |
52 | 'fusionax/issues/deathdate' => $this->make_hook('issues_deathdate', AUTH_PASSWD, 'admin,edit_directory'), | |
53 | 'fusionax/issues/promo' => $this->make_hook('issues_promo', AUTH_PASSWD, 'admin,edit_directory'), | |
12419b5b | 54 | ); |
654caec5 | 55 | } |
b9ad0878 | 56 | } |
c15c0053 PC |
57 | |
58 | ||
26ba053e | 59 | function handler_index($page) |
b9ad0878 | 60 | { |
654caec5 SJ |
61 | if (Platal::globals()->merge->state == 'pending') { |
62 | $page->changeTpl('fusionax/index.tpl'); | |
63 | } elseif (Platal::globals()->merge->state == 'done') { | |
12419b5b SJ |
64 | $issueList = array( |
65 | 'name' => 'noms', | |
66 | 'job' => 'emplois', | |
67 | 'address' => 'adresses', | |
68 | 'promo' => 'promotions', | |
69 | 'deathdate' => 'dates de décès', | |
70 | 'phone' => 'téléphones', | |
71 | 'education' => 'formations', | |
72 | ); | |
654caec5 SJ |
73 | $issues = XDB::rawFetchOneAssoc("SELECT COUNT(*) AS total, |
74 | SUM(FIND_IN_SET('name', issues)) DIV 1 AS name, | |
75 | SUM(FIND_IN_SET('job', issues)) DIV 2 AS job, | |
76 | SUM(FIND_IN_SET('address', issues)) DIV 3 AS address, | |
77 | SUM(FIND_IN_SET('promo', issues)) DIV 4 AS promo, | |
78 | SUM(FIND_IN_SET('deathdate', issues)) DIV 5 AS deathdate, | |
79 | SUM(FIND_IN_SET('phone', issues)) DIV 6 AS phone, | |
80 | SUM(FIND_IN_SET('education', issues)) DIV 7 AS education | |
81 | FROM profile_merge_issues | |
82 | WHERE issues IS NOT NULL OR issues != ''"); | |
654caec5 | 83 | $page->changeTpl('fusionax/issues.tpl'); |
12419b5b SJ |
84 | $page->assign('issues', $issues); |
85 | $page->assign('issueList', $issueList); | |
654caec5 | 86 | } |
b9ad0878 | 87 | } |
22f043e4 | 88 | |
73be4434 | 89 | /** Import de l'annuaire de l'AX depuis l'export situé dans le home de jacou */ |
26ba053e | 90 | function handler_import($page, $action = 'index', $file = '') |
b9ad0878 | 91 | { |
85ea1310 | 92 | global $globals; |
b9ad0878 PC |
93 | if ($action == 'index') { |
94 | $page->changeTpl('fusionax/import.tpl'); | |
b9ad0878 PC |
95 | return; |
96 | } | |
22f043e4 | 97 | |
cc8ea8b2 | 98 | // toutes les actions sont faites en ajax en utilisant jquery |
ddc4c642 | 99 | header('Content-type: text/javascript; charset=utf-8'); |
22f043e4 | 100 | |
cc8ea8b2 PC |
101 | // log des actions |
102 | $report = array(); | |
22f043e4 | 103 | |
73be4434 | 104 | $modulepath = realpath(dirname(__FILE__) . '/fusionax/') . '/'; |
ddc4c642 | 105 | $spoolpath = realpath(dirname(__FILE__) . '/../spool/fusionax/') . '/'; |
22f043e4 | 106 | |
b9ad0878 | 107 | if ($action == 'launch') { |
ddc4c642 SJ |
108 | if ($file == '') { |
109 | $report[] = 'Nom de fichier non renseigné.'; | |
110 | } elseif (!file_exists(dirname(__FILE__) . '/../spool/fusionax/' . $file)) { | |
111 | $report[] = 'Le fichier ne se situe pas au bon endroit.'; | |
112 | } else { | |
113 | // séparation de l'archive en fichiers par tables | |
114 | $file = $spoolpath . $file; | |
ddc4c642 SJ |
115 | // Split export into specialised files |
116 | exec('grep "^AD" ' . $file . ' > ' . $spoolpath . 'Adresses.txt'); | |
117 | exec('grep "^AN" ' . $file . ' > ' . $spoolpath . 'Anciens.txt'); | |
0efb08e6 SJ |
118 | exec('grep "^FO.[0-9]\{4\}[MD][0-9]\{3\}.Etudiant" ' . $file . ' > ' . $spoolpath . 'Formations_MD.txt'); |
119 | exec('grep "^FO.[0-9]\{4\}[MD][0-9]\{3\}.Doct. de" ' . $file . ' >> ' . $spoolpath . 'Formations_MD.txt'); | |
ddc4c642 SJ |
120 | exec('grep "^FO" ' . $file . ' > ' . $spoolpath . 'Formations.txt'); |
121 | exec('grep "^AC" ' . $file . ' > ' . $spoolpath . 'Activites.txt'); | |
122 | exec('grep "^EN" ' . $file . ' > ' . $spoolpath . 'Entreprises.txt'); | |
123 | exec($modulepath . 'formation.pl'); | |
124 | exec('mv -f ' . $spoolpath . 'Formations_out.txt ' . $spoolpath . 'Formations.txt'); | |
0efb08e6 | 125 | exec('mv -f ' . $spoolpath . 'Formations_MD_out.txt ' . $spoolpath . 'Formations_MD.txt'); |
ddc4c642 SJ |
126 | $report[] = 'Fichier parsé.'; |
127 | $report[] = 'Import dans la base en cours...'; | |
9a2876cb SJ |
128 | XDB::execute("UPDATE profiles |
129 | SET ax_id = NULL | |
130 | WHERE ax_id = ''"); | |
149360d4 | 131 | $next = 'integrateSQL'; |
ddc4c642 | 132 | } |
73be4434 | 133 | } elseif ($action == 'integrateSQL') { |
cc8ea8b2 PC |
134 | // intégration des données dans la base MySQL |
135 | // liste des fichiers sql à exécuter | |
136 | $filesSQL = array( | |
ddc4c642 SJ |
137 | 0 => 'Activites.sql', |
138 | 1 => 'Adresses.sql', | |
139 | 2 => 'Anciens.sql', | |
140 | 3 => 'Formations.sql', | |
0efb08e6 SJ |
141 | 4 => 'Entreprises.sql', |
142 | 5 => 'Formations_MD.sql' | |
ddc4c642 SJ |
143 | ); |
144 | if ($file != '') { | |
cc8ea8b2 | 145 | // récupère le contenu du fichier sql |
ddc4c642 | 146 | $queries = explode(';', file_get_contents($modulepath . $filesSQL[$file])); |
85ea1310 AL |
147 | $db = mysqli_init(); |
148 | $db->options(MYSQLI_OPT_LOCAL_INFILE, true); | |
149 | $db->real_connect($globals->dbhost, $globals->dbuser, $globals->dbpwd, $globals->dbdb); | |
150 | $db->autocommit(true); | |
151 | $db->set_charset($globals->dbcharset); | |
73be4434 SJ |
152 | foreach ($queries as $q) { |
153 | if (trim($q)) { | |
154 | // coupe le fichier en requêtes individuelles | |
155 | if (substr($q, 0, 2) == '--') { | |
156 | // affiche les commentaires dans le report | |
157 | $lines = explode("\n", $q); | |
158 | $l = $lines[0]; | |
159 | $report[] = addslashes($l); | |
160 | } | |
161 | // exécute la requête | |
85ea1310 AL |
162 | $res = $db->query(str_replace('{?}', $spoolpath, $q)); |
163 | if ($res === false) { | |
164 | throw new XDBException($q, $db->error); | |
165 | } | |
b9ad0878 | 166 | } |
b9ad0878 | 167 | } |
85ea1310 | 168 | $db->close(); |
cc8ea8b2 | 169 | // trouve le prochain fichier à exécuter |
ddc4c642 | 170 | $nextfile = $file + 1; |
b9ad0878 PC |
171 | } else { |
172 | $nextfile = 0; | |
173 | } | |
0efb08e6 | 174 | if ($nextfile > 5) { |
ddc4c642 SJ |
175 | // tous les fichiers ont été exécutés, on passe à l'étape suivante |
176 | $next = 'adds1920'; | |
b9ad0878 | 177 | } else { |
cc8ea8b2 | 178 | // on passe au fichier suivant |
ddc4c642 SJ |
179 | $next = 'integrateSQL/' . $nextfile; |
180 | } | |
181 | } elseif ($action == 'adds1920') { | |
182 | // Adds promotion 1920 from AX db. | |
183 | $report[] = 'Ajout de la promotion 1920'; | |
184 | $res = XDB::iterator('SELECT prenom, Nom_complet, ax_id | |
185 | FROM fusionax_anciens | |
186 | WHERE promotion_etude = 1920;'); | |
187 | ||
ddc4c642 SJ |
188 | $eduSchools = DirEnum::getOptions(DirEnum::EDUSCHOOLS); |
189 | $eduSchools = array_flip($eduSchools); | |
190 | $eduDegrees = DirEnum::getOptions(DirEnum::EDUDEGREES); | |
191 | $eduDegrees = array_flip($eduDegrees); | |
192 | $degreeid = $eduDegrees[Profile::DEGREE_X]; | |
193 | $entry_year = 1920; | |
194 | $grad_year = 1923; | |
195 | $promo = 'X1920'; | |
149360d4 SJ |
196 | $hrpromo = '1920'; |
197 | $sex = 'male'; | |
ddc4c642 SJ |
198 | $xorgId = 19200000; |
199 | $type = 'x'; | |
200 | ||
149360d4 SJ |
201 | while ($new = $res->next()) { |
202 | $firstname = $new['prenom']; | |
203 | $lastname = $new['Nom_complet']; | |
204 | $ax_id = $new['ax_id']; | |
205 | $hrid = User::makeHrid($firstname, $lastname, $hrpromo); | |
ddc4c642 SJ |
206 | $res1 = XDB::query('SELECT COUNT(*) |
207 | FROM accounts | |
208 | WHERE hruid = {?}', $hrid); | |
209 | $res2 = XDB::query('SELECT COUNT(*) | |
210 | FROM profiles | |
211 | WHERE hrpid = {?}', $hrid); | |
212 | if (is_null($hrid) || $res1->fetchOneCell() > 0 || $res2->fetchOneCell() > 0) { | |
213 | $report[] = $ax_id . ' non ajouté'; | |
214 | } | |
215 | $fullName = $firstname . ' ' . $lastname; | |
216 | $directoryName = $lastname . ' ' . $firstname; | |
217 | ++$xorgId; | |
218 | ||
00ba8a74 SJ |
219 | XDB::execute('INSERT INTO profiles (hrpid, xorg_id, ax_id, sex) |
220 | VALUES ({?}, {?}, {?}, {?})', | |
ddc4c642 SJ |
221 | $hrid, $xorgId, $ax_id, $sex); |
222 | $pid = XDB::insertId(); | |
149360d4 SJ |
223 | XDB::execute('INSERT INTO profile_public_names (pid, lastname_initial, firstname_initial, lastname_main, firstname_main) |
224 | VALUES ({?}, {?}, {?}, {?}, {?})', | |
225 | $pid, $lastname, $firstname, $lastname, $firstname); | |
00ba8a74 SJ |
226 | XDB::execute('INSERT INTO profile_display (pid, yourself, public_name, private_name, |
227 | directory_name, short_name, sort_name, promo) | |
228 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', | |
ddc4c642 | 229 | $pid, $firstname, $fullName, $fullName, $directoryName, $fullName, $directoryName, $promo); |
00ba8a74 SJ |
230 | XDB::execute('INSERT INTO profile_education (pid, eduid, degreeid, entry_year, grad_year, flags) |
231 | VALUES ({?}, {?}, {?}, {?}, {?}, {?})', | |
ddc4c642 | 232 | $pid, $eduSchools[Profile::EDU_X], $degreeid, $entry_year, $grad_year, 'primary'); |
ad1c9939 | 233 | XDB::execute('INSERT INTO accounts (hruid, type, is_admin, state, full_name, directory_name, display_name, lastname, firstname, sex) |
149360d4 SJ |
234 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', |
235 | $hrid, $type, 0, 'pending', $fullName, $directoryName, $firstname, $lastname, $firstname, $sex); | |
ddc4c642 | 236 | $uid = XDB::insertId(); |
00ba8a74 SJ |
237 | XDB::execute('INSERT INTO account_profiles (uid, pid, perms) |
238 | VALUES ({?}, {?}, {?})', | |
ddc4c642 | 239 | $uid, $pid, 'owner'); |
b9ad0878 | 240 | } |
ddc4c642 SJ |
241 | $report[] = 'Promo 1920 ajoutée.'; |
242 | $next = 'view'; | |
243 | } elseif ($action == 'view') { | |
244 | XDB::execute('CREATE OR REPLACE ALGORITHM=MERGE VIEW fusionax_xorg_anciens AS | |
245 | SELECT p.pid, p.ax_id, pd.promo, pd.private_name, pd.public_name, | |
246 | pd.sort_name, pd.short_name, pd.directory_name | |
247 | FROM profiles AS p | |
ad1c9939 | 248 | INNER JOIN profile_display AS pd ON (pd.pid = p.pid)'); |
ddc4c642 | 249 | $next = 'clean'; |
73be4434 | 250 | } elseif ($action == 'clean') { |
cc8ea8b2 | 251 | // nettoyage du fichier temporaire |
0efb08e6 | 252 | //exec('rm -Rf ' . $spoolpath); |
ddc4c642 | 253 | $report[] = 'Import finit.'; |
b9ad0878 | 254 | } |
73be4434 | 255 | foreach($report as $t) { |
cc8ea8b2 | 256 | // affiche les lignes de report |
ddc4c642 | 257 | echo "$('#fusionax').append('" . $t . "<br/>');\n"; |
73be4434 | 258 | } |
b9ad0878 | 259 | if (isset($next)) { |
cc8ea8b2 | 260 | // lance le prochain script s'il y en a un |
ddc4c642 | 261 | echo "$.getScript('fusionax/import/" . $next . "');"; |
b9ad0878 | 262 | } |
cc8ea8b2 | 263 | // exit pour ne pas afficher la page template par défaut |
b9ad0878 PC |
264 | exit; |
265 | } | |
22f043e4 | 266 | |
26ba053e | 267 | function handler_view($page, $action = '') |
29459c49 | 268 | { |
29459c49 SJ |
269 | $page->changeTpl('fusionax/view.tpl'); |
270 | if ($action == 'create') { | |
271 | XDB::execute('DROP VIEW IF EXISTS fusionax_deceased'); | |
723ea674 | 272 | XDB::execute("CREATE VIEW fusionax_deceased AS |
ddc4c642 SJ |
273 | SELECT p.pid, a.ax_id, pd.private_name, pd.promo, p.deathdate AS deces_xorg, a.Date_deces AS deces_ax |
274 | FROM profiles AS p | |
275 | INNER JOIN profile_display AS pd ON (p.pid = pd.pid) | |
276 | INNER JOIN fusionax_anciens AS a ON (a.ax_id = p.ax_id) | |
723ea674 | 277 | WHERE p.deathdate != a.Date_deces OR (p.deathdate IS NULL AND a.Date_deces != '0000-00-00')"); |
29459c49 | 278 | XDB::execute('DROP VIEW IF EXISTS fusionax_promo'); |
bb375055 | 279 | XDB::execute("CREATE VIEW fusionax_promo AS |
9a2876cb | 280 | SELECT p.pid, p.ax_id, pd.private_name, pd.promo, pe.entry_year AS promo_etude_xorg, f.groupe_promo, |
ddc4c642 SJ |
281 | f.promotion_etude AS promo_etude_ax, pe.grad_year AS promo_sortie_xorg |
282 | FROM profiles AS p | |
283 | INNER JOIN profile_display AS pd ON (p.pid = pd.pid) | |
caa04db8 | 284 | INNER JOIN profile_education AS pe ON (p.pid = pe.pid AND FIND_IN_SET('primary', pe.flags)) |
ddc4c642 | 285 | INNER JOIN fusionax_anciens AS f ON (p.ax_id = f.ax_id) |
bb375055 | 286 | WHERE (f.groupe_promo = 'X' AND pd.promo != CONCAT('X', f.promotion_etude) |
caa04db8 SJ |
287 | AND !(f.promotion_etude = pe.entry_year + 1 AND pe.grad_year = pe.entry_year + 4) |
288 | AND !(f.promotion_etude = pe.entry_year + 2 AND pe.grad_year = pe.entry_year + 5) | |
289 | AND f.promotion_etude != 0) | |
bb375055 SJ |
290 | OR (f.groupe_promo = 'D' AND f.promotion_etude != pe.grad_year) |
291 | OR (f.groupe_promo = 'M' AND f.promotion_etude != pe.entry_year) | |
292 | GROUP BY p.pid"); | |
ddc4c642 | 293 | $page->trigSuccess('Les VIEW ont bien été créées.'); |
29459c49 SJ |
294 | } |
295 | } | |
296 | ||
297 | /* Mets à NULL le matricule_ax de ces camarades pour marquer le fait qu'ils ne figurent pas dans l'annuaire de l'AX */ | |
ddc4c642 | 298 | private static function clear_wrong_in_xorg($pid) |
29459c49 | 299 | { |
ddc4c642 SJ |
300 | $res = XDB::execute('UPDATE fusionax_xorg_anciens |
301 | SET ax_id = NULL | |
302 | WHERE pid = {?}', $pid); | |
29459c49 SJ |
303 | if (!$res) { |
304 | return 0; | |
305 | } | |
306 | return XDB::affectedRows() / 2; | |
307 | } | |
308 | ||
aab2ffdd | 309 | /* Cherche les les anciens présents dans Xorg avec un matricule_ax ne correspondant à rien dans la base de l'AX |
1a31fce8 | 310 | * (mises à part les promo 1921, 1922, 1923, 1924, 1925, 1927, 1928, 1929 qui ne figurent pas dans les données de l'AX)*/ |
29459c49 SJ |
311 | private static function find_wrong_in_xorg($limit = 10) |
312 | { | |
2743241f | 313 | return XDB::iterator('SELECT u.promo, u.pid, u.private_name, u.ax_id |
29459c49 SJ |
314 | FROM fusionax_xorg_anciens AS u |
315 | WHERE NOT EXISTS (SELECT * | |
316 | FROM fusionax_anciens AS f | |
ddc4c642 | 317 | WHERE f.ax_id = u.ax_id) |
1a31fce8 NI |
318 | AND u.ax_id IS NOT NULL |
319 | AND promo NOT IN (\'X1921\', \'X1922\', \'X1923\', \'X1924\', \'X1925\', \'X1927\', \'X1928\', \'X1929\')'); | |
29459c49 SJ |
320 | } |
321 | ||
b65beb64 PC |
322 | /** Lier les identifiants d'un ancien dans les deux annuaires |
323 | * @param user_id identifiant dans l'annuaire X.org | |
324 | * @param matricule_ax identifiant dans l'annuaire de l'AX | |
325 | * @return 0 si la liaison a échoué, 1 sinon | |
22f043e4 | 326 | */ |
ddc4c642 | 327 | private static function link_by_ids($pid, $ax_id) |
b9ad0878 | 328 | { |
ddc4c642 | 329 | $res = XDB::execute('UPDATE fusionax_import AS i |
73be4434 | 330 | INNER JOIN fusionax_xorg_anciens AS u |
ddc4c642 SJ |
331 | SET u.ax_id = i.ax_id, |
332 | i.pid = u.pid, | |
73be4434 | 333 | i.date_match_id = NOW() |
ddc4c642 SJ |
334 | WHERE i.ax_id = {?} AND u.pid = {?} |
335 | AND (u.ax_id != {?} OR u.ax_id IS NULL | |
336 | OR i.pid != {?} OR i.pid IS NULL)', | |
337 | $ax_id, $pid, $ax_id, $pid); | |
73be4434 | 338 | if (!$res) { |
b9ad0878 PC |
339 | return 0; |
340 | } | |
73be4434 | 341 | return XDB::affectedRows() / 2; |
b9ad0878 | 342 | } |
22f043e4 | 343 | |
b65beb64 PC |
344 | /** Recherche automatique d'anciens à lier entre les deux annuaires |
345 | * @param limit nombre d'anciens à trouver au max | |
346 | * @param sure si true, ne trouve que des anciens qui sont quasi sûrs | |
e8591429 | 347 | * @return un XOrgDBIterator sur les entrées avec display_name, promo, |
ddc4c642 | 348 | * pid, ax_id et display_name_ax |
22f043e4 | 349 | */ |
b65beb64 | 350 | private static function find_easy_to_link($limit = 10, $sure = false) |
b9ad0878 | 351 | { |
e8591429 | 352 | $easy_to_link = XDB::iterator(" |
ddc4c642 | 353 | SELECT u.private_name, u.promo, u.pid, ax.ax_id, |
ad1c9939 | 354 | CONCAT(ax.prenom, ' ', ax.nom_complet, ' (', ax.groupe_promo, ax.promotion_etude, ')') AS display_name_ax, |
73be4434 | 355 | COUNT(*) AS nbMatches |
29459c49 | 356 | FROM fusionax_anciens AS ax |
ddc4c642 SJ |
357 | INNER JOIN fusionax_import AS i ON (i.ax_id = ax.ax_id AND i.pid IS NULL) |
358 | LEFT JOIN fusionax_xorg_anciens AS u ON (u.ax_id IS NULL | |
ad1c9939 | 359 | AND u.promo = CONCAT(ax.groupe_promo, ax.promotion_etude) |
ddc4c642 SJ |
360 | AND (CONCAT(ax.prenom, ' ', ax.nom_complet) = u.private_name |
361 | OR CONCAT(ax.prenom, ' ', ax.nom_complet) = u.public_name | |
362 | OR CONCAT(ax.prenom, ' ', ax.nom_complet) = u.short_name)) | |
363 | GROUP BY u.pid | |
364 | HAVING u.pid IS NOT NULL AND nbMatches = 1" . ($limit ? (' LIMIT ' . $limit) : '')); | |
b65beb64 PC |
365 | if ($easy_to_link->total() > 0 || $sure) { |
366 | return $easy_to_link; | |
367 | } | |
73be4434 | 368 | return XDB::iterator(" |
ddc4c642 | 369 | SELECT u.private_name, u.promo, u.pid, ax.ax_id, |
ad1c9939 | 370 | CONCAT(ax.prenom, ' ', ax.nom_complet, ' (', ax.groupe_promo, ax.promotion_etude, ')') AS display_name_ax, |
73be4434 | 371 | COUNT(*) AS nbMatches |
29459c49 | 372 | FROM fusionax_anciens AS ax |
ddc4c642 SJ |
373 | INNER JOIN fusionax_import AS i ON (i.ax_id = ax.ax_id AND i.pid IS NULL) |
374 | LEFT JOIN fusionax_xorg_anciens AS u ON (u.ax_id IS NULL | |
375 | AND (CONCAT(ax.prenom, ' ', ax.nom_complet) = u.private_name | |
376 | OR CONCAT(ax.prenom, ' ', ax.nom_complet) = u.public_name | |
377 | OR CONCAT(ax.prenom, ' ', ax.nom_complet) = u.short_name) | |
ad1c9939 SJ |
378 | AND u.promo < CONCAT(ax.groupe_promo, ax.promotion_etude + 2) |
379 | AND u.promo > CONCAT(ax.groupe_promo, ax.promotion_etude - 2)) | |
ddc4c642 SJ |
380 | GROUP BY u.pid |
381 | HAVING u.pid IS NOT NULL AND nbMatches = 1" . ($limit ? (' LIMIT ' . $limit) : '')); | |
b9ad0878 | 382 | } |
22f043e4 | 383 | |
b65beb64 | 384 | /** Module de mise en correspondance les ids */ |
26ba053e | 385 | function handler_ids($page, $part = 'main', $pid = null, $ax_id = null) |
b9ad0878 | 386 | { |
29459c49 | 387 | $nbToLink = 100; |
29459c49 | 388 | $page->assign('xorg_title', 'Polytechnique.org - Fusion - Mise en correspondance simple'); |
ddc4c642 | 389 | |
73be4434 | 390 | if ($part == 'missingInAX') { |
b9ad0878 PC |
391 | // locate all persons from this database that are not in AX's |
392 | $page->changeTpl('fusionax/idsMissingInAx.tpl'); | |
ddc4c642 | 393 | $missingInAX = XDB::iterator('SELECT promo, pid, private_name |
29459c49 | 394 | FROM fusionax_xorg_anciens |
ad1c9939 SJ |
395 | WHERE ax_id IS NULL |
396 | ORDER BY promo'); | |
b9ad0878 PC |
397 | $page->assign('missingInAX', $missingInAX); |
398 | return; | |
399 | } | |
73be4434 | 400 | if ($part == 'missingInXorg') { |
b9ad0878 PC |
401 | // locate all persons from AX's database that are not here |
402 | $page->changeTpl('fusionax/idsMissingInXorg.tpl'); | |
ddc4c642 | 403 | $missingInXorg = XDB::iterator("SELECT CONCAT(a.prenom, ' ', a.Nom_usuel) AS private_name, |
ad1c9939 | 404 | CONCAT(a.groupe_promo, a.promotion_etude) AS promo, a.ax_id |
73be4434 | 405 | FROM fusionax_import |
ddc4c642 | 406 | INNER JOIN fusionax_anciens AS a USING (ax_id) |
ad1c9939 SJ |
407 | WHERE fusionax_import.pid IS NULL |
408 | ORDER BY promo"); | |
b9ad0878 PC |
409 | $page->assign('missingInXorg', $missingInXorg); |
410 | return; | |
411 | } | |
29459c49 SJ |
412 | if ($part == 'wrongInXorg') { |
413 | // locate all persons from Xorg database that have a bad AX id | |
414 | $page->changeTpl('fusionax/idswrongInXorg.tpl'); | |
415 | $wrongInXorg = FusionAxModule::find_wrong_in_xorg($nbToLink); | |
416 | $page->assign('wrongInXorg', $wrongInXorg); | |
417 | return; | |
418 | } | |
419 | if ($part == 'cleanwronginxorg') { | |
420 | $linksToDo = FusionAxModule::find_wrong_in_xorg($nbToLink); | |
421 | while ($l = $linksToDo->next()) { | |
ddc4c642 | 422 | FusionAxModule::clear_wrong_in_xorg($l['pid']); |
29459c49 SJ |
423 | } |
424 | pl_redirect('fusionax/ids/wrongInXorg'); | |
425 | } | |
426 | if ($part == 'lier') { | |
427 | if (Post::has('user_id') && Post::has('matricule_ax')) { | |
ddc4c642 | 428 | FusionAxModule::link_by_ids(Post::i('pid'), Post::v('ax_id')); |
29459c49 SJ |
429 | } |
430 | } | |
73be4434 | 431 | if ($part == 'link') { |
ddc4c642 | 432 | FusionAxModule::link_by_ids($pid, $ax_id); |
b65beb64 | 433 | exit; |
b9ad0878 | 434 | } |
73be4434 | 435 | if ($part == 'linknext') { |
29459c49 | 436 | $linksToDo = FusionAxModule::find_easy_to_link($nbToLink); |
73be4434 | 437 | while ($l = $linksToDo->next()) { |
ddc4c642 | 438 | FusionAxModule::link_by_ids($l['pid'], $l['ax_id']); |
b9ad0878 | 439 | } |
b65beb64 | 440 | pl_redirect('fusionax/ids#autolink'); |
b9ad0878 | 441 | } |
73be4434 | 442 | if ($part == 'linkall') { |
b9ad0878 | 443 | $linksToDo = FusionAxModule::find_easy_to_link(0); |
73be4434 | 444 | while ($l = $linksToDo->next()) { |
ddc4c642 | 445 | FusionAxModule::link_by_ids($l['pid'], $l['ax_id']); |
b9ad0878 PC |
446 | } |
447 | } | |
448 | { | |
449 | $page->changeTpl('fusionax/ids.tpl'); | |
73be4434 | 450 | $missingInAX = XDB::query('SELECT COUNT(*) |
ddc4c642 SJ |
451 | FROM fusionax_xorg_anciens |
452 | WHERE ax_id IS NULL'); | |
73be4434 | 453 | if ($missingInAX) { |
b9ad0878 PC |
454 | $page->assign('nbMissingInAX', $missingInAX->fetchOneCell()); |
455 | } | |
73be4434 | 456 | $missingInXorg = XDB::query('SELECT COUNT(*) |
ddc4c642 SJ |
457 | FROM fusionax_import |
458 | WHERE pid IS NULL'); | |
73be4434 SJ |
459 | if ($missingInXorg) { |
460 | $page->assign('nbMissingInXorg', $missingInXorg->fetchOneCell()); | |
b9ad0878 | 461 | } |
29459c49 SJ |
462 | $wrongInXorg = FusionAxModule::find_wrong_in_xorg($nbToLink); |
463 | if ($wrongInXorg->total() > 0) { | |
464 | $page->assign('wrongInXorg', $wrongInXorg->total()); | |
465 | } | |
466 | $easyToLink = FusionAxModule::find_easy_to_link($nbToLink); | |
467 | if ($easyToLink->total() > 0) { | |
468 | $page->assign('nbMatch', $easyToLink->total()); | |
b9ad0878 PC |
469 | $page->assign('easyToLink', $easyToLink); |
470 | } | |
471 | } | |
472 | } | |
22f043e4 | 473 | |
26ba053e | 474 | function handler_deceased($page, $action = '') |
b9ad0878 | 475 | { |
29459c49 SJ |
476 | if ($action == 'updateXorg') { |
477 | XDB::execute('UPDATE fusionax_deceased | |
478 | SET deces_xorg = deces_ax | |
22648cc5 | 479 | WHERE deces_xorg IS NULL'); |
29459c49 SJ |
480 | } |
481 | if ($action == 'updateAX') { | |
482 | XDB::execute('UPDATE fusionax_deceased | |
483 | SET deces_ax = deces_xorg | |
484 | WHERE deces_ax = "0000-00-00"'); | |
485 | } | |
486 | if ($action == 'update') { | |
ddc4c642 | 487 | if (Post::has('pid') && Post::has('date')) { |
29459c49 SJ |
488 | XDB::execute('UPDATE fusionax_deceased |
489 | SET deces_ax = {?}, deces_xorg = {?} | |
ddc4c642 SJ |
490 | WHERE pid = {?}', |
491 | Post::v('date'), Post::v('date'), Post::i('pid')); | |
29459c49 SJ |
492 | } |
493 | } | |
494 | $page->changeTpl('fusionax/deceased.tpl'); | |
b9ad0878 | 495 | // deceased |
73be4434 SJ |
496 | $deceasedErrorsSql = XDB::query('SELECT COUNT(*) FROM fusionax_deceased'); |
497 | $page->assign('deceasedErrors', $deceasedErrorsSql->fetchOneCell()); | |
ddc4c642 SJ |
498 | $res = XDB::iterator('SELECT pid, ax_id, promo, private_name, deces_ax |
499 | FROM fusionax_deceased | |
22648cc5 | 500 | WHERE deces_xorg IS NULL |
29459c49 SJ |
501 | LIMIT 10'); |
502 | $page->assign('nbDeceasedMissingInXorg', $res->total()); | |
503 | $page->assign('deceasedMissingInXorg', $res); | |
ddc4c642 SJ |
504 | $res = XDB::iterator('SELECT pid, ax_id, promo, private_name, deces_xorg |
505 | FROM fusionax_deceased | |
506 | WHERE deces_ax = "0000-00-00" | |
29459c49 SJ |
507 | LIMIT 10'); |
508 | $page->assign('nbDeceasedMissingInAX', $res->total()); | |
509 | $page->assign('deceasedMissingInAX', $res); | |
ddc4c642 SJ |
510 | $res = XDB::iterator('SELECT pid, ax_id, promo, private_name, deces_xorg, deces_ax |
511 | FROM fusionax_deceased | |
512 | WHERE deces_xorg != "0000-00-00" AND deces_ax != "0000-00-00"'); | |
29459c49 SJ |
513 | $page->assign('nbDeceasedDifferent', $res->total()); |
514 | $page->assign('deceasedDifferent', $res); | |
b9ad0878 | 515 | } |
c7eac294 | 516 | |
26ba053e | 517 | function handler_promo($page, $action = '') |
c7eac294 SJ |
518 | { |
519 | $page->changeTpl('fusionax/promo.tpl'); | |
a0de7c6b | 520 | $res = XDB::iterator("SELECT pid, ax_id, private_name, promo_etude_xorg, promo_sortie_xorg, promo_etude_ax, promo |
c8ab27eb | 521 | FROM fusionax_promo |
a3f12425 SJ |
522 | WHERE !(promo_etude_ax + 1 = promo_etude_xorg AND promo_etude_xorg + 3 = promo_sortie_xorg) |
523 | AND !(promo_etude_ax + 1 = promo_etude_xorg AND promo_etude_xorg + 4 = promo_sortie_xorg) | |
9a2876cb SJ |
524 | AND !(promo_etude_ax = promo_etude_xorg + 1) AND groupe_promo = 'X' |
525 | ORDER BY promo_etude_xorg"); | |
c7eac294 | 526 | $nbMissmatchingPromos = $res->total(); |
a3f12425 SJ |
527 | $page->assign('nbMissmatchingPromos', $res->total()); |
528 | $page->assign('missmatchingPromos', $res); | |
529 | ||
a0de7c6b | 530 | $res = XDB::iterator("SELECT pid, ax_id, private_name, promo_etude_xorg, promo_sortie_xorg, promo_etude_ax, promo |
a3f12425 | 531 | FROM fusionax_promo |
9a2876cb SJ |
532 | WHERE promo_etude_ax = promo_etude_xorg + 1 AND groupe_promo = 'X' |
533 | ORDER BY promo_etude_xorg"); | |
a3f12425 | 534 | $nbMissmatchingPromos += $res->total(); |
c7eac294 SJ |
535 | $page->assign('nbMissmatchingPromos1', $res->total()); |
536 | $page->assign('missmatchingPromos1', $res); | |
a3f12425 | 537 | |
a0de7c6b | 538 | $res = XDB::iterator("SELECT pid, ax_id, private_name, promo_etude_xorg, promo_sortie_xorg, promo_etude_ax, promo |
c7eac294 | 539 | FROM fusionax_promo |
9a2876cb SJ |
540 | WHERE promo_etude_ax + 1 = promo_etude_xorg AND promo_etude_xorg + 3 = promo_sortie_xorg AND groupe_promo = 'X' |
541 | ORDER BY promo_etude_xorg"); | |
c7eac294 SJ |
542 | $nbMissmatchingPromos += $res->total(); |
543 | $page->assign('nbMissmatchingPromos2', $res->total()); | |
544 | $page->assign('missmatchingPromos2', $res); | |
a3f12425 | 545 | |
a0de7c6b | 546 | $res = XDB::iterator("SELECT pid, ax_id, private_name, promo_etude_xorg, promo_sortie_xorg, promo_etude_ax, promo |
a3f12425 | 547 | FROM fusionax_promo |
9a2876cb SJ |
548 | WHERE promo_etude_ax + 1 = promo_etude_xorg AND promo_etude_xorg + 4 = promo_sortie_xorg AND groupe_promo = 'X' |
549 | ORDER BY promo_etude_xorg"); | |
a3f12425 SJ |
550 | $nbMissmatchingPromos += $res->total(); |
551 | $page->assign('nbMissmatchingPromos3', $res->total()); | |
552 | $page->assign('missmatchingPromos3', $res); | |
553 | ||
a0de7c6b | 554 | $res = XDB::iterator("SELECT pid, ax_id, private_name, promo_etude_xorg, promo_sortie_xorg, promo_etude_ax, promo |
bb375055 SJ |
555 | FROM fusionax_promo |
556 | WHERE groupe_promo = 'M' | |
557 | ORDER BY promo_etude_xorg"); | |
558 | $nbMissmatchingPromos += $res->total(); | |
559 | $page->assign('nbMissmatchingPromosM', $res->total()); | |
560 | $page->assign('missmatchingPromosM', $res); | |
561 | ||
562 | ||
a0de7c6b | 563 | $res = XDB::iterator("SELECT pid, ax_id, private_name, promo_etude_xorg, promo_sortie_xorg, promo_etude_ax, promo |
bb375055 SJ |
564 | FROM fusionax_promo |
565 | WHERE groupe_promo = 'D' | |
566 | ORDER BY promo_etude_xorg"); | |
567 | $nbMissmatchingPromos += $res->total(); | |
568 | $page->assign('nbMissmatchingPromosD', $res->total()); | |
569 | $page->assign('missmatchingPromosD', $res); | |
570 | ||
a3f12425 SJ |
571 | $page->assign('nbMissmatchingPromosTotal', $nbMissmatchingPromos); |
572 | } | |
573 | ||
5bc0014e SJ |
574 | private function format($string) |
575 | { | |
576 | return preg_replace('/(\s+|\-)/', '', $string); | |
577 | } | |
578 | ||
579 | private function retrieve_firstnames() | |
580 | { | |
581 | $res = XDB::rawFetchAllAssoc('SELECT p.pid, p.ax_id, p.hrpid, | |
582 | f.prenom, ppn.firstname_initial, ppn.firstname_main, ppn.firstname_ordinary | |
583 | FROM fusionax_anciens AS f | |
584 | INNER JOIN profiles AS p ON (f.ax_id = p.ax_id) | |
585 | INNER JOIN profile_public_names AS ppn ON (p.pid = ppn.pid) | |
586 | WHERE f.prenom NOT IN (ppn.firstname_initial, ppn.firstname_main, ppn.firstname_ordinary)'); | |
587 | ||
588 | $issues = array(); | |
589 | foreach ($res as $item) { | |
590 | if (!($item['firstname_ordinary'] != '' || $item['firstname_main'] != $item['firstname_initial'])) { | |
591 | $ax = $this->format(mb_strtolower(replace_accent($item['prenom']))); | |
592 | $xorg = $this->format(mb_strtolower(replace_accent($item['firstname_main']))); | |
593 | if ($ax != $xorg) { | |
594 | $issues[] = $item; | |
595 | } | |
596 | } | |
597 | } | |
598 | ||
599 | return $issues; | |
600 | } | |
601 | ||
a876b1ef | 602 | function handler_names($page, $action = '', $csv = false) |
a3f12425 SJ |
603 | { |
604 | $page->changeTpl('fusionax/names.tpl'); | |
605 | ||
193affc6 | 606 | if ($action == 'first') { |
5bc0014e | 607 | $res = $this->retrieve_firstnames(); |
a876b1ef SJ |
608 | if ($csv) { |
609 | pl_cached_content_headers('text/x-csv', 'utf-8', 1, 'firstnames.csv'); | |
610 | ||
611 | $csv = fopen('php://output', 'w'); | |
612 | fputcsv($csv, array('pid', 'ax_id', 'hrpid', 'AX', 'initial', 'principal', 'ordinaire'), ';'); | |
613 | foreach ($res as $item) { | |
614 | fputcsv($csv, $item, ';'); | |
615 | } | |
616 | fclose($csv); | |
617 | exit(); | |
618 | } else { | |
619 | $page->assign('firstnameIssues', $res); | |
620 | } | |
08aaf92e | 621 | } elseif ($action == 'last' || $action == 'last3' || $action == 'last2' || $action == 'last1') { |
63c386f8 NI |
622 | // Define some variables to build queries |
623 | function sql_trim_partic($sqlstring) { | |
624 | $sqlstring = 'TRIM(LEADING \'d\\\'\' FROM ' . $sqlstring . ')'; | |
625 | $sqlstring = 'TRIM(LEADING \'D\\\'\' FROM ' . $sqlstring . ')'; | |
626 | $sqlstring = 'TRIM(LEADING \'de \' FROM ' . $sqlstring . ')'; | |
627 | $sqlstring = 'TRIM(LEADING \'De \' FROM ' . $sqlstring . ')'; | |
628 | $sqlstring = 'TRIM(LEADING \'du \' FROM ' . $sqlstring . ')'; | |
629 | $sqlstring = 'TRIM(LEADING \'Du \' FROM ' . $sqlstring . ')'; | |
630 | return $sqlstring; | |
631 | } | |
632 | //$field_ax_patro = 'IF(f.partic_patro, CONCAT(f.partic_patro, CONCAT(\' \', f.Nom_patronymique)), f.Nom_patronymique)'; | |
633 | //$field_ax_usuel = 'IF(f.partic_nom, CONCAT(f.partic_nom, CONCAT(\' \', f.Nom_usuel)), f.Nom_usuel)'; | |
634 | $fields_p_list = '(' . \ | |
635 | sql_trim_partic('ppn.lastname_initial') . ', ' . \ | |
636 | sql_trim_partic('ppn.lastname_main') . ', ' . \ | |
637 | sql_trim_partic('ppn.lastname_marital') . ', ' . \ | |
638 | sql_trim_partic('ppn.lastname_ordinary') . ')'; | |
639 | $ax_patro = '(' . sql_trim_partic('f.Nom_patronymique') . ' NOT IN ' . $fields_p_list . ')'; | |
640 | $ax_ordinary = '(' . sql_trim_partic('f.Nom_usuel') . ' NOT IN ' . $fields_p_list . ')'; | |
641 | $ax_full = '(' . sql_trim_partic('f.Nom_complet') . ' NOT IN ' . $fields_p_list . ')'; | |
08aaf92e SJ |
642 | |
643 | switch ($action) { | |
644 | case 'last': | |
645 | $where = $ax_patro . ' OR ' . $ax_ordinary . ' OR ' . $ax_full; | |
646 | break; | |
647 | case 'last3': | |
648 | $where = $ax_patro . ' AND ' . $ax_ordinary . ' AND ' . $ax_full; | |
649 | break; | |
650 | case 'last2': | |
651 | $where = '(' . $ax_patro . ' AND ' . $ax_ordinary . ' AND NOT ' . $ax_full . ') OR (' | |
652 | . $ax_patro . ' AND NOT ' . $ax_ordinary . ' AND ' . $ax_full . ') OR (' | |
653 | . 'NOT ' . $ax_patro . ' AND ' . $ax_ordinary . ' AND ' . $ax_full . ')'; | |
654 | break; | |
655 | case 'last1': | |
656 | $where = '(' . $ax_patro . ' AND NOT ' . $ax_ordinary . ' AND NOT ' . $ax_full . ') OR (' | |
657 | . 'NOT ' . $ax_patro . ' AND NOT ' . $ax_ordinary . ' AND ' . $ax_full . ') OR (' | |
658 | . 'NOT ' . $ax_patro . ' AND ' . $ax_ordinary . ' AND NOT ' . $ax_full . ')'; | |
659 | break; | |
660 | } | |
661 | ||
662 | $res = XDB::rawFetchAllAssoc('SELECT p.pid, p.ax_id, p.hrpid, | |
193affc6 | 663 | f.Nom_patronymique, f.Nom_usuel, f.Nom_complet, |
94bde753 NI |
664 | ppn.lastname_initial, ppn.lastname_main, ppn.lastname_marital, ppn.lastname_ordinary, |
665 | ' . $ax_patro . ' AS cond_patro, | |
666 | ' . $ax_ordinary . ' AS cond_ordinary, | |
667 | ' . $ax_full . ' AS cond_full | |
193affc6 SJ |
668 | FROM fusionax_anciens AS f |
669 | INNER JOIN profiles AS p ON (f.ax_id = p.ax_id) | |
247ca43b | 670 | INNER JOIN profile_public_names AS ppn ON (p.pid = ppn.pid) |
63c386f8 NI |
671 | WHERE ' . $where . ' |
672 | ORDER BY p.ax_id'); | |
193affc6 | 673 | |
a876b1ef | 674 | if ($csv) { |
08aaf92e SJ |
675 | function format($string) |
676 | { | |
677 | $string = preg_replace('/\-/', ' ', $string); | |
678 | return preg_replace('/\s+/', ' ', $string); | |
679 | } | |
680 | ||
681 | ||
a876b1ef SJ |
682 | pl_cached_content_headers('text/x-csv', 'utf-8', 1, 'lastnames.csv'); |
683 | ||
684 | $csv = fopen('php://output', 'w'); | |
63c386f8 NI |
685 | fputcsv($csv, array( |
686 | 'pid', 'ax_id', 'hrpid', | |
687 | 'AX patro', 'AX usuel', 'AX complet', | |
688 | 'initial', 'principal', 'marital', 'ordinaire', | |
689 | 'pb patro', 'pb usuel', 'pb complet'), ';'); | |
a876b1ef | 690 | foreach ($res as $item) { |
08aaf92e SJ |
691 | $ax = array( |
692 | 'Nom_patronymique' => format(mb_strtolower(replace_accent($item['Nom_patronymique']))), | |
693 | 'Nom_usuel' => format(mb_strtolower(replace_accent($item['Nom_usuel']))), | |
694 | 'Nom_complet' => format(mb_strtolower(replace_accent($item['Nom_complet']))) | |
695 | ); | |
696 | $xorg = array( | |
697 | 'lastname_initial' => format(mb_strtolower(replace_accent($item['lastname_initial']))), | |
698 | 'lastname_main' => format(mb_strtolower(replace_accent($item['lastname_main']))), | |
699 | 'lastname_ordinary' => format(mb_strtolower(replace_accent($item['lastname_ordinary']))) | |
700 | ); | |
701 | ||
702 | if (!in_array($ax['Nom_patronymique'], $xorg) || !in_array($ax['Nom_usuel'], $xorg) || !in_array($ax['Nom_complet'], $xorg)) { | |
703 | fputcsv($csv, $item, ';'); | |
704 | } | |
a876b1ef SJ |
705 | } |
706 | fclose($csv); | |
707 | exit(); | |
708 | } else { | |
709 | $page->assign('lastnameIssues', $res); | |
08aaf92e SJ |
710 | $page->assign('total', count($res)); |
711 | $page->assign('issuesTypes', array( | |
712 | 'last' => "1, 2 ou 3 noms de l'AX manquant", | |
713 | 'last1' => "1 nom de l'AX manquant", | |
714 | 'last2' => "2 noms de l'AX manquant", | |
715 | 'last3' => "3 noms de l'AX manquant" | |
716 | )); | |
a876b1ef | 717 | } |
193affc6 SJ |
718 | } else { |
719 | $res = XDB::query('SELECT COUNT(*) | |
720 | FROM fusionax_anciens AS f | |
721 | INNER JOIN profiles AS p ON (f.ax_id = p.ax_id)'); | |
722 | $page->assign('total', $res->fetchOneCell()); | |
723 | ||
724 | $res = XDB::rawFetchOneCell("SELECT COUNT(*) | |
725 | FROM fusionax_anciens AS f | |
726 | INNER JOIN profiles AS p ON (f.ax_id = p.ax_id) | |
247ca43b | 727 | INNER JOIN profile_public_names AS ppn ON (p.pid = ppn.pid) |
193affc6 | 728 | 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) |
9a13e83f SJ |
729 | 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) |
730 | OR f.Nom_complet NOT IN (ppn.lastname_initial, ppn.lastname_main, ppn.lastname_marital, ppn.lastname_ordinary)"); | |
193affc6 SJ |
731 | $page->assign('lastnameIssues', $res); |
732 | ||
733 | $res = XDB::rawFetchOneCell('SELECT COUNT(*) | |
734 | FROM fusionax_anciens AS f | |
735 | INNER JOIN profiles AS p ON (f.ax_id = p.ax_id) | |
736 | INNER JOIN profile_public_names AS ppn ON (p.pid = ppn.pid) | |
737 | WHERE f.prenom NOT IN (ppn.firstname_initial, ppn.firstname_main, ppn.firstname_ordinary)'); | |
5bc0014e | 738 | $page->assign('firstnameIssues', count($this->retrieve_firstnames())); |
193affc6 SJ |
739 | } |
740 | $page->assign('action', $action); | |
c7eac294 | 741 | } |
12419b5b | 742 | |
26ba053e | 743 | function handler_edu($page, $action = '') |
2fad6caa SJ |
744 | { |
745 | $page->changeTpl('fusionax/education.tpl'); | |
746 | ||
95b1a6d8 | 747 | $missingEducation = XDB::rawIterator("SELECT DISTINCT(f.Intitule_formation) |
2fad6caa | 748 | FROM fusionax_formations AS f |
95b1a6d8 SJ |
749 | WHERE f.Intitule_formation != '' AND NOT EXISTS (SELECT * |
750 | FROM profile_education_enum AS e | |
751 | WHERE f.Intitule_formation = e.name)"); | |
752 | $missingDegree = XDB::rawIterator("SELECT DISTINCT(f.Intitule_diplome) | |
2fad6caa | 753 | FROM fusionax_formations AS f |
95b1a6d8 SJ |
754 | WHERE f.Intitule_diplome != '' AND NOT EXISTS (SELECT * |
755 | FROM profile_education_degree_enum AS e | |
756 | WHERE f.Intitule_diplome = e.abbreviation)"); | |
757 | $missingCouple = XDB::rawIterator("SELECT DISTINCT(f.Intitule_formation) AS edu, f.Intitule_diplome AS degree, ee.id AS eduid, de.id AS degreeid | |
2fad6caa | 758 | FROM fusionax_formations AS f |
95b1a6d8 SJ |
759 | INNER JOIN profile_education_enum AS ee ON (f.Intitule_formation = ee.name) |
760 | INNER JOIN profile_education_degree_enum AS de ON (f.Intitule_diplome = de.abbreviation) | |
2fad6caa SJ |
761 | WHERE f.Intitule_diplome != '' AND f.Intitule_formation != '' |
762 | AND NOT EXISTS (SELECT * | |
763 | FROM profile_education_degree AS d | |
764 | WHERE ee.id = d.eduid AND de.id = d.degreeid)"); | |
765 | ||
766 | $page->assign('missingEducation', $missingEducation); | |
767 | $page->assign('missingDegree', $missingDegree); | |
768 | $page->assign('missingCouple', $missingCouple); | |
769 | $page->assign('missingEducationCount', $missingEducation->total()); | |
770 | $page->assign('missingDegreeCount', $missingDegree->total()); | |
771 | $page->assign('missingCoupleCount', $missingCouple->total()); | |
772 | } | |
773 | ||
26ba053e | 774 | function handler_corps($page) |
551e00c1 SJ |
775 | { |
776 | $page->changeTpl('fusionax/corps.tpl'); | |
777 | ||
778 | $missingCorps = XDB::rawIterator('SELECT DISTINCT(f.corps_sortie) AS name | |
779 | FROM fusionax_anciens AS f | |
780 | WHERE NOT EXISTS (SELECT * | |
781 | FROM profile_corps_enum AS c | |
782 | WHERE f.corps_sortie = c.abbreviation)'); | |
783 | $missingGrade = XDB::rawIterator('SELECT DISTINCT(f.grade) AS name | |
784 | FROM fusionax_anciens AS f | |
785 | WHERE NOT EXISTS (SELECT * | |
786 | FROM profile_corps_rank_enum AS c | |
787 | WHERE f.grade = c.name)'); | |
788 | ||
789 | $page->assign('missingCorps', $missingCorps); | |
790 | $page->assign('missingGrade', $missingGrade); | |
791 | $page->assign('missingCorpsCount', $missingCorps->total()); | |
792 | $page->assign('missingGradeCount', $missingGrade->total()); | |
793 | } | |
794 | ||
26ba053e | 795 | function handler_issues_deathdate($page, $action = '') |
12419b5b SJ |
796 | { |
797 | $page->changeTpl('fusionax/deathdate_issues.tpl'); | |
798 | if ($action == 'edit') { | |
799 | S::assert_xsrf_token(); | |
800 | ||
801 | $issues = XDB::rawIterRow('SELECT p.pid, pd.directory_name, pd.promo, pm.deathdate_ax, p.deathdate | |
802 | FROM profile_merge_issues AS pm | |
803 | INNER JOIN profiles AS p ON (pm.pid = p.pid) | |
804 | INNER JOIN profile_display AS pd ON (pd.pid = p.pid) | |
805 | WHERE FIND_IN_SET(\'deathdate\', pm.issues) | |
806 | ORDER BY pd.directory_name'); | |
807 | while (list($pid, $name, $promo, $deathAX, $deathXorg) = $issues->next()) { | |
808 | $choiceAX = Post::has('AX_' . $pid); | |
809 | $choiceXorg = Post::has('XORG_' . $pid); | |
810 | if (!($choiceAX || $choiceXorg)) { | |
811 | continue; | |
812 | } | |
813 | ||
814 | if ($choiceAX) { | |
815 | XDB::execute('UPDATE profiles AS p | |
816 | INNER JOIN profile_merge_issues AS pm ON (pm.pid = p.pid) | |
817 | SET p.deathdate = pm.deathdate_ax, p.deathdate_rec = NOW() | |
818 | WHERE p.pid = {?}', $pid); | |
819 | } | |
820 | XDB::execute("UPDATE profile_merge_issues | |
821 | SET issues = REPLACE(issues, 'deathdate', '') | |
822 | WHERE pid = {?}", $pid()); | |
823 | $page->trigSuccess("La date de décès de $name ($promo) a bien été corrigée."); | |
824 | } | |
825 | } | |
826 | ||
827 | $issues = XDB::rawFetchAllAssoc('SELECT p.pid, p.hrpid, pd.directory_name, pd.promo, pm.deathdate_ax, p.deathdate | |
828 | FROM profile_merge_issues AS pm | |
829 | INNER JOIN profiles AS p ON (pm.pid = p.pid) | |
830 | INNER JOIN profile_display AS pd ON (pd.pid = p.pid) | |
831 | WHERE FIND_IN_SET(\'deathdate\', pm.issues) | |
832 | ORDER BY pd.directory_name'); | |
833 | $page->assign('issues', $issues); | |
834 | $page->assign('total', count($issues)); | |
835 | } | |
836 | ||
26ba053e | 837 | function handler_issues_promo($page, $action = '') |
12419b5b SJ |
838 | { |
839 | $page->changeTpl('fusionax/promo_issues.tpl'); | |
840 | if ($action == 'edit') { | |
841 | S::assert_xsrf_token(); | |
842 | ||
843 | $issues = XDB::rawIterRow('SELECT p.pid, pd.directory_name, pd.promo, pm.entry_year_ax, pe.entry_year, pe.grad_year | |
844 | FROM profile_merge_issues AS pm | |
845 | INNER JOIN profiles AS p ON (pm.pid = p.pid) | |
846 | INNER JOIN profile_display AS pd ON (pd.pid = p.pid) | |
847 | INNER JOIN profile_education AS pe ON (pe.pid = p.pid AND FIND_IN_SET(\'primary\', pe.flags)) | |
848 | WHERE FIND_IN_SET(\'promo\', pm.issues) | |
849 | ORDER BY pd.directory_name'); | |
850 | while (list($pid, $name, $promo, $deathAX, $deathXorgEntry, $deathXorgGrad) = $issues->next()) { | |
851 | $choiceXorg = Post::has('XORG_' . $pid); | |
852 | if (!(Post::has('display_' . $pid) && Post::has('entry_' . $pid) && Post::has('grad_' . $pid))) { | |
853 | continue; | |
854 | } | |
855 | ||
856 | $display = Post::i('display_' . $pid); | |
857 | $entry = Post::i('entry_' . $pid); | |
858 | $grad = Post::i('grad_' . $pid); | |
859 | if (!(($grad <= $entry + 5 && $grad >= $entry + 3) && ($display >= $entry && $display <= $grad - 3))) { | |
860 | $page->trigError("La promotion de $name n'a pas été corrigée."); | |
861 | continue; | |
862 | } | |
863 | XDB::execute('UPDATE profile_display | |
864 | SET promo = {?} | |
865 | WHERE pid = {?}', 'X' . $display, $pid); | |
866 | XDB::execute('UPDATE profile_education | |
867 | SET entry_year = {?}, grad_year = {?} | |
868 | WHERE pid = {?} AND FIND_IN_SET(\'primary\', flags)', $entry, $grad, $pid); | |
869 | $page->trigSuccess("La promotion de $name a bien été corrigée."); | |
870 | } | |
871 | } | |
872 | ||
873 | $issues = XDB::rawFetchAllAssoc('SELECT p.pid, p.hrpid, pd.directory_name, pd.promo, pm.entry_year_ax, pe.entry_year, pe.grad_year | |
874 | FROM profile_merge_issues AS pm | |
875 | INNER JOIN profiles AS p ON (pm.pid = p.pid) | |
876 | INNER JOIN profile_display AS pd ON (pd.pid = p.pid) | |
877 | INNER JOIN profile_education AS pe ON (pe.pid = p.pid AND FIND_IN_SET(\'primary\', pe.flags)) | |
878 | WHERE FIND_IN_SET(\'promo\', pm.issues) | |
879 | ORDER BY pd.directory_name'); | |
880 | $page->assign('issues', $issues); | |
881 | $page->assign('total', count($issues)); | |
882 | } | |
883 | ||
26ba053e | 884 | function handler_issues($page, $action = '') |
12419b5b SJ |
885 | { |
886 | static $issueList = array( | |
887 | 'name' => 'noms', | |
888 | 'phone' => 'téléphones', | |
889 | 'education' => 'formations', | |
890 | 'address' => 'adresses', | |
891 | 'job' => 'emplois' | |
892 | ); | |
d20f50cf SJ |
893 | static $typeList = array( |
894 | 'name' => 'general', | |
895 | 'phone' => 'general', | |
896 | 'education' => 'general', | |
897 | 'address' => 'adresses', | |
898 | 'job' => 'emploi' | |
899 | ); | |
12419b5b SJ |
900 | |
901 | if (!array_key_exists($action, $issueList)) { | |
902 | pl_redirect('fusionax'); | |
903 | } else { | |
904 | $total = XDB::fetchOneCell('SELECT COUNT(*) | |
905 | FROM profile_merge_issues | |
906 | WHERE FIND_IN_SET({?}, issues)', $action); | |
907 | if ($total == 0) { | |
908 | pl_redirect('fusionax'); | |
909 | } | |
910 | ||
911 | $issues = XDB::fetchAllAssoc('SELECT p.hrpid, pd.directory_name, pd.promo | |
912 | FROM profile_merge_issues AS pm | |
913 | INNER JOIN profiles AS p ON (pm.pid = p.pid) | |
914 | INNER JOIN profile_display AS pd ON (pd.pid = p.pid) | |
915 | WHERE FIND_IN_SET({?}, pm.issues) | |
916 | ORDER BY pd.directory_name | |
917 | LIMIT 100', $action); | |
918 | ||
919 | $page->changeTpl('fusionax/other_issues.tpl'); | |
920 | $page->assign('issues', $issues); | |
921 | $page->assign('issue', $issueList[$action]); | |
d20f50cf | 922 | $page->assign('type', $typeList[$action]); |
12419b5b SJ |
923 | $page->assign('total', $total); |
924 | } | |
925 | } | |
b9ad0878 | 926 | } |
e8591429 | 927 | |
448c8cdc | 928 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: |
a3f12425 | 929 | ?> |