Moving to GitHub.
[platal.git] / include / education.func.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
c441aabe 3 * Copyright (C) 2003-2014 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{
9fce7016 24 $html = '<option value="-1">&nbsp;</option>';
1c305d4c 25 $res = XDB::iterator("SELECT e.id AS id, gc.country,
2700a4f5 26 IF(CHAR_LENGTH(e.name) > 76, e.abbreviation, e.name) AS name
a5e30e55 27 FROM profile_education_enum AS e
e4cd7a1f 28 LEFT JOIN geoloc_countries AS gc ON (e.country = gc.iso_3166_1_a2)
c7eac294
SJ
29 WHERE EXISTS (SELECT *
30 FROM profile_education_degree AS d
fb052bde
SJ
31 WHERE e.id = d.eduid) AND e.name != {?}
32 ORDER BY gc.country, e.name",
33 Profile::EDU_X);
a5e30e55 34 $country = "";
f711b03f 35 while ($arr_edu = $res->next()) {
a5e30e55 36 if ($arr_edu["country"] != $country) {
9fce7016
PC
37 if ($country) {
38 $html .= '</optgroup>';
39 }
a5e30e55 40 $country = $arr_edu["country"];
9fce7016 41 $html .= '<optgroup label="' . $country . '">';
a5e30e55 42 }
f711b03f 43 $html .= '<option value="' . $arr_edu["id"] . '"';
58acfe8b 44 if ($arr_edu["id"] == $current) {
043bbacf
SJ
45 $html .= " selected='selected'";
46 }
f711b03f 47 $html .= '>' . htmlspecialchars($arr_edu["name"]) . "</option>\n";
0337d704 48 }
9fce7016
PC
49 if ($country) {
50 $html .= '</optgroup>';
51 }
0337d704 52 return $html;
53}
043bbacf 54
f711b03f 55/** pour appeller education_options depuis smarty
0337d704 56 */
f711b03f 57function _education_options_smarty($params)
043bbacf
SJ
58{
59 if(!isset($params['selected'])) {
b34046e9 60 $params['selected'] = 0;
043bbacf 61 }
f711b03f 62 return education_options($params['selected']);
0337d704 63}
f711b03f 64Platal::page()->register_function('education_options', '_education_options_smarty');
0337d704 65
f711b03f 66/** affiche un Array javascript contenant les diplômes de chaque formation
0337d704 67 */
f711b03f 68function education_degree()
043bbacf 69{
6505acf7
SJ
70 $html = '';
71 $res = XDB::iterRow("SELECT eduid, degreeid
72 FROM profile_education_degree
73 ORDER BY eduid");
74 $edu_degree = $res->next();
75 for ($eduid = 1; $edu_degree; ++$eduid) {
76 $html .= '[';
77 if ($edu_degree['0'] == $eduid) {
78 $html .= $edu_degree['1'];
f711b03f 79 $edu_degree = $res->next();
6505acf7
SJ
80 while ($edu_degree['0'] == $eduid) {
81 $html .= ',' . $edu_degree['1'];
82 $edu_degree = $res->next();
83 }
043bbacf 84 }
6505acf7
SJ
85 $html .= ']';
86 if ($edu_degree) {
87 $html .= ",\n";
043bbacf 88 }
0337d704 89 }
90 return $html;
91}
f711b03f 92Platal::page()->register_function('education_degree', 'education_degree');
0337d704 93
f711b03f 94/** affiche tous les types possibles de diplômes
0337d704 95 */
f711b03f 96function education_degree_all()
043bbacf 97{
043bbacf
SJ
98 $res = XDB::query("SELECT id
99 FROM profile_education_degree_enum
100 ORDER BY id");
101 return implode(',', $res->fetchColumn());
102}
f711b03f 103Platal::page()->register_function('education_degree_all', 'education_degree_all');
043bbacf 104
f711b03f 105/** affiche les noms de tous les diplômes possibles
043bbacf 106 */
f711b03f 107function education_degree_name()
043bbacf 108{
043bbacf 109 $res = XDB::query("SELECT degree
c7eac294
SJ
110 FROM profile_education_degree_enum
111 ORDER BY id");
112 return '"' . implode('","', $res->fetchColumn()) . '"';
0337d704 113}
f711b03f 114Platal::page()->register_function('education_degree_name', 'education_degree_name');
0337d704 115
448c8cdc 116// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
0337d704 117?>