X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Ffusionax.php;h=1b076983ab415b7a03a7523744670bbe49383b67;hb=164566891eef6e4027b2dfccda0040d37f10605b;hp=dfde915f7d14c39e00b7f7525e22cb2b9c6c3125;hpb=654caec538912e37949b1942f81b8e7d0e2b2deb;p=platal.git diff --git a/modules/fusionax.php b/modules/fusionax.php index dfde915..1b07698 100644 --- a/modules/fusionax.php +++ b/modules/fusionax.php @@ -34,28 +34,25 @@ class FusionAxModule extends PLModule function handlers() { if (Platal::globals()->merge->state == 'pending') { - $auth = 'admin'; + return array( + 'fusionax' => $this->make_hook('index', AUTH_MDP, 'admin'), + 'fusionax/import' => $this->make_hook('import', AUTH_MDP, 'admin'), + 'fusionax/view' => $this->make_hook('view', AUTH_MDP, 'admin'), + 'fusionax/ids' => $this->make_hook('ids', AUTH_MDP, 'admin'), + 'fusionax/deceased' => $this->make_hook('deceased', AUTH_MDP, 'admin'), + 'fusionax/promo' => $this->make_hook('promo', AUTH_MDP, 'admin'), + 'fusionax/names' => $this->make_hook('names', AUTH_MDP, 'admin'), + 'fusionax/edu' => $this->make_hook('edu', AUTH_MDP, 'admin'), + 'fusionax/corps' => $this->make_hook('corps', AUTH_MDP, 'admin') + ); } elseif (Platal::globals()->merge->state == 'done') { - $auth = 'admin,edit_directory'; + return array( + 'fusionax' => $this->make_hook('index', AUTH_MDP, 'admin,edit_directory'), + 'fusionax/issues' => $this->make_hook('issues', AUTH_MDP, 'admin,edit_directory'), + 'fusionax/issues/deathdate' => $this->make_hook('issues_deathdate', AUTH_MDP, 'admin,edit_directory'), + 'fusionax/issues/promo' => $this->make_hook('issues_promo', AUTH_MDP, 'admin,edit_directory'), + ); } - - return array( - 'fusionax' => $this->make_hook('index', AUTH_MDP, $auth), - 'fusionax/import' => $this->make_hook('import', AUTH_MDP, 'admin'), - 'fusionax/view' => $this->make_hook('view', AUTH_MDP, 'admin'), - 'fusionax/ids' => $this->make_hook('ids', AUTH_MDP, 'admin'), - 'fusionax/deceased' => $this->make_hook('deceased', AUTH_MDP, 'admin'), - 'fusionax/promo' => $this->make_hook('promo', AUTH_MDP, 'admin'), - 'fusionax/names' => $this->make_hook('names', AUTH_MDP, 'admin'), - - 'fusionax/deathdate_issues' => $this->make_hook('deathdate_issue', AUTH_MDP, 'admin,edit_directory'), - 'fusionax/promo_issues' => $this->make_hook('promo_issue', AUTH_MDP, 'admin,edit_directory'), - 'fusionax/name_issues' => $this->make_hook('name_issue', AUTH_MDP, 'admin,edit_directory'), - 'fusionax/phone_issues' => $this->make_hook('phone_issue', AUTH_MDP, 'admin,edit_directory'), - 'fusionax/education_issues' => $this->make_hook('education_issue', AUTH_MDP, 'admin,edit_directory'), - 'fusionax/address_issues' => $this->make_hook('address_issue', AUTH_MDP, 'admin,edit_directory'), - 'fusionax/job_issues' => $this->make_hook('job_issue', AUTH_MDP, 'admin,edit_directory'), - ); } @@ -64,6 +61,15 @@ class FusionAxModule extends PLModule if (Platal::globals()->merge->state == 'pending') { $page->changeTpl('fusionax/index.tpl'); } elseif (Platal::globals()->merge->state == 'done') { + $issueList = array( + 'name' => 'noms', + 'job' => 'emplois', + 'address' => 'adresses', + 'promo' => 'promotions', + 'deathdate' => 'dates de décès', + 'phone' => 'téléphones', + 'education' => 'formations', + ); $issues = XDB::rawFetchOneAssoc("SELECT COUNT(*) AS total, SUM(FIND_IN_SET('name', issues)) DIV 1 AS name, SUM(FIND_IN_SET('job', issues)) DIV 2 AS job, @@ -74,8 +80,9 @@ class FusionAxModule extends PLModule SUM(FIND_IN_SET('education', issues)) DIV 7 AS education FROM profile_merge_issues WHERE issues IS NOT NULL OR issues != ''"); - $page->assign('issues', $issues); $page->changeTpl('fusionax/issues.tpl'); + $page->assign('issues', $issues); + $page->assign('issueList', $issueList); } } @@ -104,17 +111,17 @@ class FusionAxModule extends PLModule } else { // séparation de l'archive en fichiers par tables $file = $spoolpath . $file; - // Removes master and doctorate students - exec('grep -v "^[A-Z]\{2\}.[0-9]\{4\}[MD][0-9]\{3\}" ' . $file . ' > ' . $file . '.tmp'); - exec('mv -f ' . $file . '.tmp ' . $file); // Split export into specialised files exec('grep "^AD" ' . $file . ' > ' . $spoolpath . 'Adresses.txt'); exec('grep "^AN" ' . $file . ' > ' . $spoolpath . 'Anciens.txt'); + exec('grep "^FO.[0-9]\{4\}[MD][0-9]\{3\}.Etudiant" ' . $file . ' > ' . $spoolpath . 'Formations_MD.txt'); + exec('grep "^FO.[0-9]\{4\}[MD][0-9]\{3\}.Doct. de" ' . $file . ' >> ' . $spoolpath . 'Formations_MD.txt'); exec('grep "^FO" ' . $file . ' > ' . $spoolpath . 'Formations.txt'); exec('grep "^AC" ' . $file . ' > ' . $spoolpath . 'Activites.txt'); exec('grep "^EN" ' . $file . ' > ' . $spoolpath . 'Entreprises.txt'); exec($modulepath . 'formation.pl'); exec('mv -f ' . $spoolpath . 'Formations_out.txt ' . $spoolpath . 'Formations.txt'); + exec('mv -f ' . $spoolpath . 'Formations_MD_out.txt ' . $spoolpath . 'Formations_MD.txt'); $report[] = 'Fichier parsé.'; $report[] = 'Import dans la base en cours...'; $next = 'integrateSQL'; @@ -127,7 +134,8 @@ class FusionAxModule extends PLModule 1 => 'Adresses.sql', 2 => 'Anciens.sql', 3 => 'Formations.sql', - 4 => 'Entreprises.sql' + 4 => 'Entreprises.sql', + 5 => 'Formations_MD.sql' ); if ($file != '') { // récupère le contenu du fichier sql @@ -150,7 +158,7 @@ class FusionAxModule extends PLModule } else { $nextfile = 0; } - if ($nextfile > 4) { + if ($nextfile > 5) { // tous les fichiers ont été exécutés, on passe à l'étape suivante $next = 'adds1920'; } else { @@ -193,29 +201,29 @@ class FusionAxModule extends PLModule $directoryName = $lastname . ' ' . $firstname; ++$xorgId; - XDB::execute('REPLACE INTO profiles (hrpid, xorg_id, ax_id, sex) - VALUES ({?}, {?}, {?}, {?})', + XDB::execute('INSERT INTO profiles (hrpid, xorg_id, ax_id, sex) + VALUES ({?}, {?}, {?}, {?})', $hrid, $xorgId, $ax_id, $sex); $pid = XDB::insertId(); - XDB::execute('REPLACE INTO profile_name (pid, name, typeid) - VALUES ({?}, {?}, {?})', + XDB::execute('INSERT INTO profile_name (pid, name, typeid) + VALUES ({?}, {?}, {?})', $pid, $lastname, $nameTypes['name_ini']); - XDB::execute('REPLACE INTO profile_name (pid, name, typeid) - VALUES ({?}, {?}, {?})', + XDB::execute('INSERT INTO profile_name (pid, name, typeid) + VALUES ({?}, {?}, {?})', $pid, $firstname, $nameTypes['firstname_ini']); - XDB::execute('REPLACE INTO profile_display (pid, yourself, public_name, private_name, - directory_name, short_name, sort_name, promo) - VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', + XDB::execute('INSERT INTO profile_display (pid, yourself, public_name, private_name, + directory_name, short_name, sort_name, promo) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', $pid, $firstname, $fullName, $fullName, $directoryName, $fullName, $directoryName, $promo); - XDB::execute('REPLACE INTO profile_education (pid, eduid, degreeid, entry_year, grad_year, flags) - VALUES ({?}, {?}, {?}, {?}, {?}, {?})', + XDB::execute('INSERT INTO profile_education (pid, eduid, degreeid, entry_year, grad_year, flags) + VALUES ({?}, {?}, {?}, {?}, {?}, {?})', $pid, $eduSchools[Profile::EDU_X], $degreeid, $entry_year, $grad_year, 'primary'); - XDB::execute('REPLACE INTO accounts (hruid, type, is_admin, state, full_name, directory_name, display_name, sex) - VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})', + XDB::execute('INSERT INTO accounts (hruid, type, is_admin, state, full_name, directory_name, display_name, sex) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})', $hrid, $type, 0, 'active', $fullName, $directoryName, $lastname, $sex); $uid = XDB::insertId(); - XDB::execute('REPLACE INTO account_profiles (uid, pid, perms) - VALUES ({?}, {?}, {?})', + XDB::execute('INSERT INTO account_profiles (uid, pid, perms) + VALUES ({?}, {?}, {?})', $uid, $pid, 'owner'); } $report[] = 'Promo 1920 ajoutée.'; @@ -229,7 +237,7 @@ class FusionAxModule extends PLModule $next = 'clean'; } elseif ($action == 'clean') { // nettoyage du fichier temporaire - exec('rm -Rf ' . $spoolpath); + //exec('rm -Rf ' . $spoolpath); $report[] = 'Import finit.'; } foreach($report as $t) { @@ -249,12 +257,12 @@ class FusionAxModule extends PLModule $page->changeTpl('fusionax/view.tpl'); if ($action == 'create') { XDB::execute('DROP VIEW IF EXISTS fusionax_deceased'); - XDB::execute('CREATE VIEW fusionax_deceased AS + XDB::execute("CREATE VIEW fusionax_deceased AS SELECT p.pid, a.ax_id, pd.private_name, pd.promo, p.deathdate AS deces_xorg, a.Date_deces AS deces_ax FROM profiles AS p INNER JOIN profile_display AS pd ON (p.pid = pd.pid) INNER JOIN fusionax_anciens AS a ON (a.ax_id = p.ax_id) - WHERE p.deathdate != a.Date_deces'); + WHERE p.deathdate != a.Date_deces OR (p.deathdate IS NULL AND a.Date_deces != '0000-00-00')"); XDB::execute('DROP VIEW IF EXISTS fusionax_promo'); XDB::execute('CREATE VIEW fusionax_promo AS SELECT p.pid, p.ax_id, pd.private_name, pd.promo, pe.entry_year AS promo_etude_xorg, @@ -448,7 +456,7 @@ class FusionAxModule extends PLModule if ($action == 'updateXorg') { XDB::execute('UPDATE fusionax_deceased SET deces_xorg = deces_ax - WHERE deces_xorg = "0000-00-00"'); + WHERE deces_xorg IS NULL'); } if ($action == 'updateAX') { XDB::execute('UPDATE fusionax_deceased @@ -469,7 +477,7 @@ class FusionAxModule extends PLModule $page->assign('deceasedErrors', $deceasedErrorsSql->fetchOneCell()); $res = XDB::iterator('SELECT pid, ax_id, promo, private_name, deces_ax FROM fusionax_deceased - WHERE deces_xorg = "0000-00-00" + WHERE deces_xorg IS NULL LIMIT 10'); $page->assign('nbDeceasedMissingInXorg', $res->total()); $page->assign('deceasedMissingInXorg', $res); @@ -569,6 +577,190 @@ class FusionAxModule extends PLModule $page->assign('firstnameIssues', $res->fetchOneCell()); } + + function handler_edu(&$page, $action = '') + { + $page->changeTpl('fusionax/education.tpl'); + + $missingEducation = XDB::rawIterator("SELECT DISTINCT(f.Intitule_formation) + FROM fusionax_formations AS f + WHERE f.Intitule_formation != '' AND NOT EXISTS (SELECT * + FROM profile_education_enum AS e + WHERE f.Intitule_formation = e.name)"); + $missingDegree = XDB::rawIterator("SELECT DISTINCT(f.Intitule_diplome) + FROM fusionax_formations AS f + WHERE f.Intitule_diplome != '' AND NOT EXISTS (SELECT * + FROM profile_education_degree_enum AS e + WHERE f.Intitule_diplome = e.abbreviation)"); + $missingCouple = XDB::rawIterator("SELECT DISTINCT(f.Intitule_formation) AS edu, f.Intitule_diplome AS degree, ee.id AS eduid, de.id AS degreeid + FROM fusionax_formations AS f + INNER JOIN profile_education_enum AS ee ON (f.Intitule_formation = ee.name) + INNER JOIN profile_education_degree_enum AS de ON (f.Intitule_diplome = de.abbreviation) + WHERE f.Intitule_diplome != '' AND f.Intitule_formation != '' + AND NOT EXISTS (SELECT * + FROM profile_education_degree AS d + WHERE ee.id = d.eduid AND de.id = d.degreeid)"); + + $page->assign('missingEducation', $missingEducation); + $page->assign('missingDegree', $missingDegree); + $page->assign('missingCouple', $missingCouple); + $page->assign('missingEducationCount', $missingEducation->total()); + $page->assign('missingDegreeCount', $missingDegree->total()); + $page->assign('missingCoupleCount', $missingCouple->total()); + } + + function handler_corps(&$page) + { + $page->changeTpl('fusionax/corps.tpl'); + + $missingCorps = XDB::rawIterator('SELECT DISTINCT(f.corps_sortie) AS name + FROM fusionax_anciens AS f + WHERE NOT EXISTS (SELECT * + FROM profile_corps_enum AS c + WHERE f.corps_sortie = c.abbreviation)'); + $missingGrade = XDB::rawIterator('SELECT DISTINCT(f.grade) AS name + FROM fusionax_anciens AS f + WHERE NOT EXISTS (SELECT * + FROM profile_corps_rank_enum AS c + WHERE f.grade = c.name)'); + + $page->assign('missingCorps', $missingCorps); + $page->assign('missingGrade', $missingGrade); + $page->assign('missingCorpsCount', $missingCorps->total()); + $page->assign('missingGradeCount', $missingGrade->total()); + } + + function handler_issues_deathdate(&$page, $action = '') + { + $page->changeTpl('fusionax/deathdate_issues.tpl'); + if ($action == 'edit') { + S::assert_xsrf_token(); + + $issues = XDB::rawIterRow('SELECT p.pid, pd.directory_name, pd.promo, pm.deathdate_ax, p.deathdate + FROM profile_merge_issues AS pm + INNER JOIN profiles AS p ON (pm.pid = p.pid) + INNER JOIN profile_display AS pd ON (pd.pid = p.pid) + WHERE FIND_IN_SET(\'deathdate\', pm.issues) + ORDER BY pd.directory_name'); + while (list($pid, $name, $promo, $deathAX, $deathXorg) = $issues->next()) { + $choiceAX = Post::has('AX_' . $pid); + $choiceXorg = Post::has('XORG_' . $pid); + if (!($choiceAX || $choiceXorg)) { + continue; + } + + if ($choiceAX) { + XDB::execute('UPDATE profiles AS p + INNER JOIN profile_merge_issues AS pm ON (pm.pid = p.pid) + SET p.deathdate = pm.deathdate_ax, p.deathdate_rec = NOW() + WHERE p.pid = {?}', $pid); + } + XDB::execute("UPDATE profile_merge_issues + SET issues = REPLACE(issues, 'deathdate', '') + WHERE pid = {?}", $pid()); + $page->trigSuccess("La date de décès de $name ($promo) a bien été corrigée."); + } + } + + $issues = XDB::rawFetchAllAssoc('SELECT p.pid, p.hrpid, pd.directory_name, pd.promo, pm.deathdate_ax, p.deathdate + FROM profile_merge_issues AS pm + INNER JOIN profiles AS p ON (pm.pid = p.pid) + INNER JOIN profile_display AS pd ON (pd.pid = p.pid) + WHERE FIND_IN_SET(\'deathdate\', pm.issues) + ORDER BY pd.directory_name'); + $page->assign('issues', $issues); + $page->assign('total', count($issues)); + } + + function handler_issues_promo(&$page, $action = '') + { + $page->changeTpl('fusionax/promo_issues.tpl'); + if ($action == 'edit') { + S::assert_xsrf_token(); + + $issues = XDB::rawIterRow('SELECT p.pid, pd.directory_name, pd.promo, pm.entry_year_ax, pe.entry_year, pe.grad_year + FROM profile_merge_issues AS pm + INNER JOIN profiles AS p ON (pm.pid = p.pid) + INNER JOIN profile_display AS pd ON (pd.pid = p.pid) + INNER JOIN profile_education AS pe ON (pe.pid = p.pid AND FIND_IN_SET(\'primary\', pe.flags)) + WHERE FIND_IN_SET(\'promo\', pm.issues) + ORDER BY pd.directory_name'); + while (list($pid, $name, $promo, $deathAX, $deathXorgEntry, $deathXorgGrad) = $issues->next()) { + $choiceXorg = Post::has('XORG_' . $pid); + if (!(Post::has('display_' . $pid) && Post::has('entry_' . $pid) && Post::has('grad_' . $pid))) { + continue; + } + + $display = Post::i('display_' . $pid); + $entry = Post::i('entry_' . $pid); + $grad = Post::i('grad_' . $pid); + if (!(($grad <= $entry + 5 && $grad >= $entry + 3) && ($display >= $entry && $display <= $grad - 3))) { + $page->trigError("La promotion de $name n'a pas été corrigée."); + continue; + } + XDB::execute('UPDATE profile_display + SET promo = {?} + WHERE pid = {?}', 'X' . $display, $pid); + XDB::execute('UPDATE profile_education + SET entry_year = {?}, grad_year = {?} + WHERE pid = {?} AND FIND_IN_SET(\'primary\', flags)', $entry, $grad, $pid); + $page->trigSuccess("La promotion de $name a bien été corrigée."); + } + } + + $issues = XDB::rawFetchAllAssoc('SELECT p.pid, p.hrpid, pd.directory_name, pd.promo, pm.entry_year_ax, pe.entry_year, pe.grad_year + FROM profile_merge_issues AS pm + INNER JOIN profiles AS p ON (pm.pid = p.pid) + INNER JOIN profile_display AS pd ON (pd.pid = p.pid) + INNER JOIN profile_education AS pe ON (pe.pid = p.pid AND FIND_IN_SET(\'primary\', pe.flags)) + WHERE FIND_IN_SET(\'promo\', pm.issues) + ORDER BY pd.directory_name'); + $page->assign('issues', $issues); + $page->assign('total', count($issues)); + } + + function handler_issues(&$page, $action = '') + { + static $issueList = array( + 'name' => 'noms', + 'phone' => 'téléphones', + 'education' => 'formations', + 'address' => 'adresses', + 'job' => 'emplois' + ); + static $typeList = array( + 'name' => 'general', + 'phone' => 'general', + 'education' => 'general', + 'address' => 'adresses', + 'job' => 'emploi' + ); + + if (!array_key_exists($action, $issueList)) { + pl_redirect('fusionax'); + } else { + $total = XDB::fetchOneCell('SELECT COUNT(*) + FROM profile_merge_issues + WHERE FIND_IN_SET({?}, issues)', $action); + if ($total == 0) { + pl_redirect('fusionax'); + } + + $issues = XDB::fetchAllAssoc('SELECT p.hrpid, pd.directory_name, pd.promo + FROM profile_merge_issues AS pm + INNER JOIN profiles AS p ON (pm.pid = p.pid) + INNER JOIN profile_display AS pd ON (pd.pid = p.pid) + WHERE FIND_IN_SET({?}, pm.issues) + ORDER BY pd.directory_name + LIMIT 100', $action); + + $page->changeTpl('fusionax/other_issues.tpl'); + $page->assign('issues', $issues); + $page->assign('issue', $issueList[$action]); + $page->assign('type', $typeList[$action]); + $page->assign('total', $total); + } + } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: