3 require_once 'connect.db.inc.php';
5 $globals->debug
= 0; //do not store backtraces
8 $res = XDB
::iterator("SELECT id, abbreviation AS name
9 FROM profile_education_degree_enum
11 foreach ($res as $item) {
12 $degree_list[$item[1]] = $item[0];
15 // get degree's level list
16 $res = XDB
::iterator("SELECT id, level AS name
17 FROM profile_education_degree_enum
19 foreach ($res as $item) {
20 $level_list [$item[1]] = $item[0];
23 // get university list
24 $res = XDB
::iterator("SELECT id, IF(abbreviation = '', name, abbreviation) AS name
25 FROM profile_education_enum
27 foreach ($res as $item) {
28 $university_list [$item[1]] = $item[0];
32 $res = XDB
::iterator("SELECT id, field AS name
33 FROM profile_education_field_enum
35 foreach ($res as $item) {
36 $field_list [$item[1]] = $item[0];
39 // get Xorg education data
40 $res = XDB
::query("SELECT p.uid, d.abbreviation AS degree, IF(e.abbreviation = '', e.name, e.abbreviation) AS university, p.program, p.id AS no
41 FROM profile_education AS p
42 INNER JOIN profile_education_enum AS e ON (p.eduid = e.id)
43 INNER JOIN profile_education_degree_enum AS d ON (p.degreeid = d.id)
46 $xorg_edu = $res->fetchAllAssoc();
48 // get AX education data
49 $res = XDB
::iterator("SELECT u.user_id AS uid, f.Intitule_diplome AS degree, f.Intitule_formation AS university,
50 CONCAT(Descr_formation, ' ', tmp_1, ' ', tmp_2, ' ', tmp_3, ' ', tmp_4) AS program
51 FROM fusionax_formations AS f
52 INNER JOIN fusionax_xorg_anciens AS u ON (f.id_ancien = u.matricule_ax)
54 $ax_edu = $res->fetchAllAssoc();
56 // merge education data
59 $xorg = next($xorg_edu);
60 while ($ax = next($ax_edu)) {
61 array_walk($ax, 'trim');
62 if (($ax['degree'] == '') && ($ax['university'] = '')) {
65 while ($xorg['uid'] && ($xorg['uid'] < $ax['uid'])) {
66 $xorg = next($xorg_edu);
70 if($xorg['uid'] == $ax['uid']) {
74 while (($xorg['uid'] == $uid) && (!merge($ax, $xorg))) {
75 $xorg = next($xorg_edu);
79 while ($xorg['uid'] == $uid) {
80 $xorg = next($xorg_edu);
90 $xorg = prev($xorg_edu);
99 XDB
::execute("REPLACE INTO profile_education (uid, degreeid, eduid, program, fieldid, id)
100 VALUES {?}, {?}, {?}, {?}, {?}, {?}",
101 $ax['uid'], $ax['degree'], $ax['university'], $ax['program'], $ax['field'], $no);
103 if (($nb_total %
1000) == 0) {
109 echo "$nb_merge_succes educations were succesfully merged among $nb_total entries.\n";
111 // auxilliary functions
113 // replaces AX data by corresponding id in Xorg database
114 function adapt_ax(&$ax)
116 if ($field_list[$ax['program']]) {
117 $ax['field'] = $field_list[$ax['program']];
118 $ax['program'] = null
;
120 $ax['degree'] = $degree_list[$ax['degree']];
121 $ax['university'] = $university_list[$ax['university']];
124 // tries to merge two educations into ax and returns 1 in case of merge
125 function merge(&$ax, $xorg)
127 if ($ax['degree'] == '') {
128 if ($ax['university'] != $xorg['university']) {
131 $ax['degree'] = $xorg['degree'];
132 $ax['university'] = $xorg['university'];
134 if ($ax['university'] == '') {
135 if (($level_list[$ax['degree']] == $level_list[$xorg['degree']]) ||
($xorg['degree'] == "Dipl.") ||
($ax['degree'] == "Dipl.")) {
136 if ($xorg['degree'] != "Dipl.") {
137 $ax['degree'] = $xorg['degree'];
139 $ax['university'] = $xorg['university'];
144 if (($ax['university'] == $xorg['university']) &&
145 (($level_list[$ax['degree']] == $level_list[$xorg['degree']]) ||
($xorg['degree'] == "Dipl.") ||
($ax['degree'] == "Dipl."))) {
146 if ($xorg['degree'] != "Dipl.") {
147 $ax['degree'] = $xorg['degree'];
154 if ($xorg['program']) {
155 $ax['field'] = $field_list[$ax['program']];
156 $ax['program'] = $xorg['program'];
158 $ax['no'] = $xorg['no'];
162 /* vim:set et sw=4 sts=4 ts=4: */