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