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