Merge commit 'origin/master' into fusionax
[platal.git] / include / education.func.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
179afa7f 3 * Copyright (C) 2003-2008 Polytechnique.org *
0337d704 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
58acfe8b 22function education_options($current = 0)
043bbacf 23{
58acfe8b 24 $html = '<option value="-1"></option>';
a5e30e55
SJ
25 $res = XDB::iterator("SELECT e.id AS id, e.name AS name, g.pays AS country
26 FROM profile_education_enum AS e
27 INNER JOIN geoloc_pays AS g ON (e.country = g.a2)
28 ORDER BY g.pays, e.name");
29 $country = "";
f711b03f 30 while ($arr_edu = $res->next()) {
a5e30e55
SJ
31 if ($arr_edu["country"] != $country) {
32 $country = $arr_edu["country"];
33 $html .= "<optgroup label=" . $country . ">";
34 }
f711b03f 35 $html .= '<option value="' . $arr_edu["id"] . '"';
58acfe8b 36 if ($arr_edu["id"] == $current) {
043bbacf
SJ
37 $html .= " selected='selected'";
38 }
f711b03f 39 $html .= '>' . htmlspecialchars($arr_edu["name"]) . "</option>\n";
0337d704 40 }
41 return $html;
42}
043bbacf 43
f711b03f 44/** pour appeller education_options depuis smarty
0337d704 45 */
f711b03f 46function _education_options_smarty($params)
043bbacf
SJ
47{
48 if(!isset($params['selected'])) {
b34046e9 49 $params['selected'] = 0;
043bbacf 50 }
f711b03f 51 return education_options($params['selected']);
0337d704 52}
f711b03f 53Platal::page()->register_function('education_options', '_education_options_smarty');
0337d704 54
f711b03f 55/** affiche un Array javascript contenant les diplômes de chaque formation
0337d704 56 */
f711b03f 57function education_degree()
043bbacf 58{
0337d704 59 $html = "";
043bbacf
SJ
60 $res = XDB::iterRow("SELECT eduid, degreeid
61 FROM profile_education_degree AS d
62 INNER JOIN profile_education_enum AS e ON (e.id = d.eduid)
a5e30e55
SJ
63 INNER JOIN geoloc_pays AS g ON (e.country = g.a2)
64 ORDER BY g.pays, e.name");
f711b03f
SJ
65 if ($edu_degree = $res->next()) {
66 $eduid = $edu_degree['0'];
043bbacf 67 $html .= "[";
f711b03f
SJ
68 $html .= $edu_degree['1'];
69 $edu_degree = $res->next();
70 while ($edu_degree['0'] == $eduid) {
71 $html .= "," . $edu_degree['1'];
72 $edu_degree = $res->next();
043bbacf
SJ
73 }
74 $html .= "]";
0337d704 75 }
f711b03f
SJ
76 while ($edu_degree) {
77 $eduid = $edu_degree['0'];
043bbacf 78 $html .= ",\n[";
f711b03f
SJ
79 $html .= $edu_degree['1'];
80 $edu_degree = $res->next();
81 while ($edu_degree['0'] == $eduid) {
82 $html .= "," . $edu_degree['1'];
83 $edu_degree = $res->next();
043bbacf
SJ
84 }
85 $html .= "]";
0337d704 86 }
87 return $html;
88}
f711b03f 89Platal::page()->register_function('education_degree', 'education_degree');
0337d704 90
f711b03f 91/** affiche tous les types possibles de diplômes
0337d704 92 */
f711b03f 93function education_degree_all()
043bbacf
SJ
94{
95 $html = "";
96 $res = XDB::query("SELECT id
97 FROM profile_education_degree_enum
98 ORDER BY id");
99 return implode(',', $res->fetchColumn());
100}
f711b03f 101Platal::page()->register_function('education_degree_all', 'education_degree_all');
043bbacf 102
f711b03f 103/** affiche les noms de tous les diplômes possibles
043bbacf 104 */
f711b03f 105function education_degree_name()
043bbacf
SJ
106{
107 $html = "";
108 $res = XDB::query("SELECT degree
109 FROM profile_education_degree_enum
110 ORDER BY id");
111 return '\'' . implode('\',\'', $res->fetchColumn()) . '\'';
0337d704 112}
f711b03f 113Platal::page()->register_function('education_degree_name', 'education_degree_name');
0337d704 114
f711b03f 115/** formatte une formation pour l'affichage
0337d704 116 */
1504ac45 117function education_fmt($name, $url, $degree, $grad_year, $field, $program, $sexe, $long)
043bbacf
SJ
118{
119 $field = strtolower($field);
120 $txt = "";
121
1504ac45 122 if ($grad_year || $field || $program) {
58acfe8b 123 $txt .= "<span title=\"(";
1504ac45
SJ
124 if ($program) {
125 $txt .= $program;
126 if ($grad_year || $field) {
127 $txt .= ", ";
128 }
129 }
043bbacf
SJ
130 if ($grad_year) {
131 if ($sexe) {
132 $txt .= "diplômée en $grad_year";
133 } else {
134 $txt .= "diplômé en $grad_year";
135 }
136 if ($field) {
137 $txt .= ", ";
138 }
139 }
140 if ($field) {
141 $txt .= "domaine : $field)\">";
142 }
b34046e9 143 }
043bbacf
SJ
144
145 if (($degree != "Licence") || ($long)) {
146 if (($degree != "Ingénieur") && ($degree != "Diplôme")) {
147 $txt .= $degree;
148 }
149 if ($name != "Université") {
150 if ($name) {
151 $txt .= ' ';
152 }
153 if ($url != ' ') {
154 $txt .= "<a href=\"$url\" onclick=\"return popup(this)\">$name</a>";
155 } else {
156 $txt .= $name;
157 }
158 }
0337d704 159 }
043bbacf
SJ
160 $txt .= "</span>";
161
0337d704 162 return $txt;
163}
043bbacf 164
f711b03f 165function _education_fmt($params, &$smarty)
043bbacf 166{
0337d704 167 extract($params);
1504ac45 168 return education_fmt($name, $url, $degree, $grad_year, $field, $program, $sexe, $long);
0337d704 169}
f711b03f 170Platal::page()->register_function('education_fmt', '_education_fmt');
0337d704 171
a7de4ef7 172// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0337d704 173?>