Initiates pages to fix merge related possible errors.
[platal.git] / modules / fusionax.php
index e5d853d..dfde915 100644 (file)
@@ -33,21 +33,50 @@ class FusionAxModule extends PLModule
 {
     function handlers()
     {
+        if (Platal::globals()->merge->state == 'pending') {
+            $auth = 'admin';
+        } elseif (Platal::globals()->merge->state == 'done') {
+            $auth = 'admin,edit_directory';
+        }
+
         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'                  => $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'),
         );
     }
 
 
     function handler_index(&$page)
     {
-        $page->changeTpl('fusionax/index.tpl');
-        $page->assign('xorg_title', 'Polytechnique.org - Fusion des annuaires');
+        if (Platal::globals()->merge->state == 'pending') {
+            $page->changeTpl('fusionax/index.tpl');
+        } elseif (Platal::globals()->merge->state == 'done') {
+            $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,
+                                                     SUM(FIND_IN_SET('address', issues))   DIV 3 AS address,
+                                                     SUM(FIND_IN_SET('promo', issues))     DIV 4 AS promo,
+                                                     SUM(FIND_IN_SET('deathdate', issues)) DIV 5 AS deathdate,
+                                                     SUM(FIND_IN_SET('phone', issues))     DIV 6 AS phone,
+                                                     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');
+        }
     }
 
     /** Import de l'annuaire de l'AX depuis l'export situĂ© dans le home de jacou */
@@ -462,18 +491,85 @@ class FusionAxModule extends PLModule
         $page->changeTpl('fusionax/promo.tpl');
         $res = XDB::iterator('SELECT  pid, private_name, promo_etude_xorg, promo_sortie_xorg, promo_etude_ax, promo
                                 FROM  fusionax_promo
-                               WHERE  !(promo_etude_ax + 1 = promo_etude_xorg AND promo_etude_xorg + 3 = promo_sortie_xorg)');
+                               WHERE  !(promo_etude_ax + 1 = promo_etude_xorg AND promo_etude_xorg + 3 = promo_sortie_xorg)
+                                      AND !(promo_etude_ax + 1 = promo_etude_xorg AND promo_etude_xorg + 4 = promo_sortie_xorg)
+                                      AND !(promo_etude_ax = promo_etude_xorg + 1)
+                            ORDER BY  promo_etude_xorg');
         $nbMissmatchingPromos = $res->total();
+        $page->assign('nbMissmatchingPromos', $res->total());
+        $page->assign('missmatchingPromos', $res);
+
+        $res = XDB::iterator('SELECT  pid, private_name, promo_etude_xorg, promo_sortie_xorg, promo_etude_ax, promo
+                                FROM  fusionax_promo
+                               WHERE  promo_etude_ax = promo_etude_xorg + 1
+                            ORDER BY  promo_etude_xorg');
+        $nbMissmatchingPromos += $res->total();
         $page->assign('nbMissmatchingPromos1', $res->total());
         $page->assign('missmatchingPromos1', $res);
+
         $res = XDB::iterator('SELECT  pid, private_name, promo_etude_xorg, promo_sortie_xorg, promo_etude_ax, promo
                                 FROM  fusionax_promo
-                               WHERE  promo_etude_ax + 1 = promo_etude_xorg AND promo_etude_xorg + 3 = promo_sortie_xorg');
+                               WHERE  promo_etude_ax + 1 = promo_etude_xorg AND promo_etude_xorg + 3 = promo_sortie_xorg
+                            ORDER BY  promo_etude_xorg');
         $nbMissmatchingPromos += $res->total();
         $page->assign('nbMissmatchingPromos2', $res->total());
         $page->assign('missmatchingPromos2', $res);
-        $page->assign('nbMissmatchingPromos', $nbMissmatchingPromos);
+
+        $res = XDB::iterator('SELECT  pid, private_name, promo_etude_xorg, promo_sortie_xorg, promo_etude_ax, promo
+                                FROM  fusionax_promo
+                               WHERE  promo_etude_ax + 1 = promo_etude_xorg AND promo_etude_xorg + 4 = promo_sortie_xorg
+                            ORDER BY  promo_etude_xorg');
+        $nbMissmatchingPromos += $res->total();
+        $page->assign('nbMissmatchingPromos3', $res->total());
+        $page->assign('missmatchingPromos3', $res);
+
+        $page->assign('nbMissmatchingPromosTotal', $nbMissmatchingPromos);
+    }
+
+    function handler_names(&$page, $action = '')
+    {
+        $page->changeTpl('fusionax/names.tpl');
+
+        $res = XDB::query('SELECT  COUNT(*)
+                             FROM  fusionax_anciens AS f
+                       INNER JOIN  profiles         AS p    ON (f.ax_id = p.ax_id)');
+        $page->assign('total', $res->fetchOneCell());
+
+        // To be checked:
+        // | lastname           |  1 |
+        // | lastname_marital   |  2 |
+        // | lastname_ordinary  |  3 |
+        // | firstname          |  4 |
+        // | firstname_ordinary |  7 |
+        // | firstname_other    |  8 |
+        // | name_other         |  9 |
+        // | name_ini           | 10 |
+        // | firstname_ini      | 11 |
+        $res = XDB::query("SELECT  COUNT(*)
+                             FROM  fusionax_anciens AS f
+                       INNER JOIN  profiles         AS p   ON (f.ax_id = p.ax_id)
+                        LEFT JOIN  profile_name     AS pnp ON (p.pid = pnp.pid AND pnp.typeid = 1)
+                        LEFT JOIN  profile_name     AS pnm ON (p.pid = pnm.pid AND pnm.typeid = 2)
+                        LEFT JOIN  profile_name     AS pno ON (p.pid = pno.pid AND pno.typeid = 3)
+                        LEFT JOIN  profile_name     AS pne ON (p.pid = pne.pid AND pne.typeid = 9)
+                        LEFT JOIN  profile_name     AS pni ON (p.pid = pni.pid AND pni.typeid = 10)
+                            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)
+                                   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)
+                                   OR f.Nom_complet NOT IN (pnp.name, pno.name, pnm.name, pne.name, pni.name)");
+        $page->assign('lastnameIssues', $res->fetchOneCell());
+
+        $res = XDB::query('SELECT  COUNT(*)
+                             FROM  fusionax_anciens AS f
+                       INNER JOIN  profiles         AS p   ON (f.ax_id = p.ax_id)
+                        LEFT JOIN  profile_name     AS pnf ON (p.pid = pnf.pid AND pnf.typeid = 4)
+                        LEFT JOIN  profile_name     AS pno ON (p.pid = pno.pid AND pno.typeid = 7)
+                        LEFT JOIN  profile_name     AS pne ON (p.pid = pne.pid AND pne.typeid = 8)
+                        LEFT JOIN  profile_name     AS pni ON (p.pid = pni.pid AND pni.typeid = 11)
+                            WHERE  f.prenom NOT IN (pnf.name, pno.name, pne.name, pni.name)');
+        $page->assign('firstnameIssues', $res->fetchOneCell());
+
     }
 }
 
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:?>
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>