| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2009 Polytechnique.org * |
| 4 | * http://opensource.polytechnique.org/ * |
| 5 | * * |
| 6 | * This program is free software; you can redistribute it and/or modify * |
| 7 | * it under the terms of the GNU General Public License as published by * |
| 8 | * the Free Software Foundation; either version 2 of the License, or * |
| 9 | * (at your option) any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program; if not, write to the Free Software * |
| 18 | * Foundation, Inc., * |
| 19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
| 20 | ***************************************************************************/ |
| 21 | |
| 22 | function education_options($current = 0) |
| 23 | { |
| 24 | $html = '<option value="-1"></option>'; |
| 25 | $res = XDB::iterator("SELECT e.id AS id, g.pays AS country, |
| 26 | IF(CHAR_LENGTH(e.name) > 76, e.abbreviation, e.name) AS name |
| 27 | FROM profile_education_enum AS e |
| 28 | LEFT JOIN geoloc_pays AS g ON (e.country = g.a2) |
| 29 | WHERE EXISTS (SELECT * |
| 30 | FROM profile_education_degree AS d |
| 31 | WHERE e.id = d.eduid) |
| 32 | ORDER BY g.pays, e.name"); |
| 33 | $country = ""; |
| 34 | while ($arr_edu = $res->next()) { |
| 35 | if ($arr_edu["country"] != $country) { |
| 36 | $country = $arr_edu["country"]; |
| 37 | $html .= "<optgroup label=" . $country . ">"; |
| 38 | } |
| 39 | $html .= '<option value="' . $arr_edu["id"] . '"'; |
| 40 | if ($arr_edu["id"] == $current) { |
| 41 | $html .= " selected='selected'"; |
| 42 | } |
| 43 | $html .= '>' . htmlspecialchars($arr_edu["name"]) . "</option>\n"; |
| 44 | } |
| 45 | return $html; |
| 46 | } |
| 47 | |
| 48 | /** pour appeller education_options depuis smarty |
| 49 | */ |
| 50 | function _education_options_smarty($params) |
| 51 | { |
| 52 | if(!isset($params['selected'])) { |
| 53 | $params['selected'] = 0; |
| 54 | } |
| 55 | return education_options($params['selected']); |
| 56 | } |
| 57 | Platal::page()->register_function('education_options', '_education_options_smarty'); |
| 58 | |
| 59 | /** affiche un Array javascript contenant les diplômes de chaque formation |
| 60 | */ |
| 61 | function education_degree() |
| 62 | { |
| 63 | $html = ""; |
| 64 | $res = XDB::iterRow("SELECT d.eduid, d.degreeid |
| 65 | FROM profile_education_enum AS e |
| 66 | INNER JOIN profile_education_degree AS d ON (e.id = d.eduid) |
| 67 | LEFT JOIN geoloc_pays AS g ON (e.country = g.a2) |
| 68 | ORDER BY g.pays, e.name"); |
| 69 | if ($edu_degree = $res->next()) { |
| 70 | $eduid = $edu_degree['0']; |
| 71 | $html .= "["; |
| 72 | $html .= $edu_degree['1']; |
| 73 | $edu_degree = $res->next(); |
| 74 | while ($edu_degree['0'] == $eduid) { |
| 75 | $html .= "," . $edu_degree['1']; |
| 76 | $edu_degree = $res->next(); |
| 77 | } |
| 78 | $html .= "]"; |
| 79 | } |
| 80 | while ($edu_degree) { |
| 81 | $eduid = $edu_degree['0']; |
| 82 | $html .= ",\n["; |
| 83 | $html .= $edu_degree['1']; |
| 84 | $edu_degree = $res->next(); |
| 85 | while ($edu_degree['0'] == $eduid) { |
| 86 | $html .= "," . $edu_degree['1']; |
| 87 | $edu_degree = $res->next(); |
| 88 | } |
| 89 | $html .= "]"; |
| 90 | } |
| 91 | return $html; |
| 92 | } |
| 93 | Platal::page()->register_function('education_degree', 'education_degree'); |
| 94 | |
| 95 | /** affiche tous les types possibles de diplômes |
| 96 | */ |
| 97 | function education_degree_all() |
| 98 | { |
| 99 | $res = XDB::query("SELECT id |
| 100 | FROM profile_education_degree_enum |
| 101 | ORDER BY id"); |
| 102 | return implode(',', $res->fetchColumn()); |
| 103 | } |
| 104 | Platal::page()->register_function('education_degree_all', 'education_degree_all'); |
| 105 | |
| 106 | /** affiche les noms de tous les diplômes possibles |
| 107 | */ |
| 108 | function education_degree_name() |
| 109 | { |
| 110 | $res = XDB::query("SELECT degree |
| 111 | FROM profile_education_degree_enum |
| 112 | ORDER BY id"); |
| 113 | return '"' . implode('","', $res->fetchColumn()) . '"'; |
| 114 | } |
| 115 | Platal::page()->register_function('education_degree_name', 'education_degree_name'); |
| 116 | |
| 117 | /** formatte une formation pour l'affichage |
| 118 | */ |
| 119 | function education_fmt($name, $url, $degree, $grad_year, $field, $program, $sexe, $long) |
| 120 | { |
| 121 | $field = strtolower($field); |
| 122 | $txt = ""; |
| 123 | |
| 124 | if ($grad_year || $field || $program) { |
| 125 | $txt .= "<span title=\"("; |
| 126 | if ($program) { |
| 127 | $txt .= $program; |
| 128 | if ($grad_year || $field) { |
| 129 | $txt .= ", "; |
| 130 | } |
| 131 | } |
| 132 | if ($grad_year) { |
| 133 | if ($sexe) { |
| 134 | $txt .= "diplômée en $grad_year"; |
| 135 | } else { |
| 136 | $txt .= "diplômé en $grad_year"; |
| 137 | } |
| 138 | if ($field) { |
| 139 | $txt .= ", "; |
| 140 | } |
| 141 | } |
| 142 | if ($field) { |
| 143 | $txt .= "domaine : $field)\">"; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | if (($degree != "Lic.") || ($long)) { |
| 148 | if (($degree != "Ing.") && ($degree != "Dipl.")) { |
| 149 | $txt .= $degree; |
| 150 | } |
| 151 | if ($name) { |
| 152 | $txt .= ' '; |
| 153 | } |
| 154 | if ($url != ' ') { |
| 155 | $txt .= "<a href=\"$url\" onclick=\"return popup(this)\">$name</a>"; |
| 156 | } else { |
| 157 | $txt .= $name; |
| 158 | } |
| 159 | } |
| 160 | $txt .= "</span>"; |
| 161 | |
| 162 | return $txt; |
| 163 | } |
| 164 | |
| 165 | function _education_fmt($params, &$smarty) |
| 166 | { |
| 167 | extract($params); |
| 168 | return education_fmt($name, $url, $degree, $grad_year, $field, $program, $sexe, $long); |
| 169 | } |
| 170 | Platal::page()->register_function('education_fmt', '_education_fmt'); |
| 171 | |
| 172 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 173 | ?> |