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