Merge commit 'origin/master' into fusionax
[platal.git] / include / education.func.inc.php
index 2cca09b..04a98ca 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2008 Polytechnique.org                              *
+ *  Copyright (C) 2003-2009 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
 function education_options($current = 0)
 {
     $html = '<option value="-1"></option>';
-    $res  = XDB::iterator("SELECT  *
-                             FROM  profile_education_enum
-                         ORDER BY  name");
+    $res  = XDB::iterator("SELECT  e.id AS id, g.pays AS country,
+                                   IF(CHAR_LENGTH(e.name) > 76, e.abbreviation, e.name) AS name
+                             FROM  profile_education_enum AS e
+                        LEFT JOIN  geoloc_pays            AS g ON (e.country = g.a2)
+                     WHERE EXISTS  (SELECT  *
+                                      FROM  profile_education_degree AS d
+                                     WHERE  e.id = d.eduid)
+                         ORDER BY  g.pays, e.name");
+    $country = "";
     while ($arr_edu = $res->next()) {
+        if ($arr_edu["country"] != $country) {
+            $country = $arr_edu["country"];
+            $html .= "<optgroup label=" . $country . ">";
+        }
         $html .= '<option value="' . $arr_edu["id"] . '"';
         if ($arr_edu["id"] == $current) {
             $html .= " selected='selected'";
@@ -51,10 +61,11 @@ Platal::page()->register_function('education_options', '_education_options_smart
 function education_degree()
 {
     $html = "";
-    $res = XDB::iterRow("SELECT  eduid, degreeid
-                           FROM  profile_education_degree AS d
-                     INNER JOIN  profile_education_enum   AS e ON (e.id = d.eduid)
-                       ORDER BY  e.name");
+    $res = XDB::iterRow("SELECT  d.eduid, d.degreeid
+                           FROM  profile_education_enum   AS e
+                     INNER JOIN  profile_education_degree AS d ON (e.id = d.eduid)
+                      LEFT JOIN  geoloc_pays              AS g ON (e.country = g.a2)
+                       ORDER BY  g.pays, e.name");
     if ($edu_degree = $res->next()) {
         $eduid = $edu_degree['0'];
         $html .= "[";
@@ -85,7 +96,6 @@ Platal::page()->register_function('education_degree', 'education_degree');
  */
 function education_degree_all()
 {
-    $html = "";
     $res = XDB::query("SELECT  id
                          FROM  profile_education_degree_enum
                      ORDER BY  id");
@@ -97,11 +107,10 @@ Platal::page()->register_function('education_degree_all', 'education_degree_all'
  */
 function education_degree_name()
 {
-    $html = "";
     $res = XDB::query("SELECT  degree
-                           FROM  profile_education_degree_enum
-                       ORDER BY  id");
-    return '\'' . implode('\',\'', $res->fetchColumn()) . '\'';
+                         FROM  profile_education_degree_enum
+                     ORDER BY  id");
+    return '"' . implode('","', $res->fetchColumn()) . '"';
 }
 Platal::page()->register_function('education_degree_name', 'education_degree_name');
 
@@ -135,19 +144,17 @@ function education_fmt($name, $url, $degree, $grad_year, $field, $program, $sexe
         }
     }
 
-    if (($degree != "Licence") || ($long)) {
-        if (($degree != "Ingénieur") && ($degree != "Diplôme")) {
+    if (($degree != "Lic.") || ($long)) {
+        if (($degree != "Ing.") && ($degree != "Dipl.")) {
             $txt .= $degree;
         }
-        if ($name != "Université") {
-            if ($name) {
-                $txt .= ' ';
-            }
-            if ($url != ' ') {
-                $txt .= "<a href=\"$url\" onclick=\"return popup(this)\">$name</a>";
-            } else {
-                $txt .= $name;
-            }
+        if ($name) {
+            $txt .= ' ';
+        }
+        if ($url != ' ') {
+            $txt .= "<a href=\"$url\" onclick=\"return popup(this)\">$name</a>";
+        } else {
+            $txt .= $name;
         }
     }
     $txt .= "</span>";