Merge branch 'xorg/1.0.2/master'
[platal.git] / modules / fusionax.php
index 857f0d2..d180c6d 100644 (file)
@@ -42,7 +42,8 @@ class FusionAxModule extends PLModule
                 '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/edu'              => $this->make_hook('edu',      AUTH_MDP, 'admin'),
+                'fusionax/corps'            => $this->make_hook('corps',    AUTH_MDP, 'admin')
             );
         } elseif (Platal::globals()->merge->state == 'done') {
             return array(
@@ -199,29 +200,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.';
@@ -235,7 +236,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) {
@@ -255,12 +256,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,
@@ -454,7 +455,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
@@ -475,7 +476,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);
@@ -580,20 +581,20 @@ class FusionAxModule extends PLModule
     {
         $page->changeTpl('fusionax/education.tpl');
 
-        $missingEducation = XDB::rawIterator("SELECT  DISTINCT(f.Intitule_diplome)
+        $missingEducation = XDB::rawIterator("SELECT  DISTINCT(f.Intitule_formation)
                                                 FROM  fusionax_formations AS f
-                                               WHERE  f.Intitule_diplome != '' AND NOT EXISTS (SELECT  *
-                                                                                                 FROM  profile_education_enum AS e
-                                                                                                WHERE  f.Intitule_diplome = e.name)");
-        $missingDegree = XDB::rawIterator("SELECT  DISTINCT(f.Intitule_formation)
+                                               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_formation != '' AND NOT EXISTS (SELECT  *
-                                                                                                FROM  profile_education_degree_enum AS e
-                                                                                               WHERE  f.Intitule_formation = e.abbreviation)");
-        $missingCouple = XDB::rawIterator("SELECT  DISTINCT(f.Intitule_diplome) AS edu, f.Intitule_formation AS degree, ee.id AS eduid, de.id AS degreeid
+                                            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_diplome = ee.name)
-                                       INNER JOIN  profile_education_degree_enum AS de ON (f.Intitule_formation = de.abbreviation)
+                                       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
@@ -607,6 +608,27 @@ class FusionAxModule extends PLModule
         $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');