dd635915e99c7667de775a5d0f70858c20ed318d
[platal.git] / include / education.func.inc.php
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, gc.countryFR 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_countries AS gc ON (e.country = gc.iso_3166_1_a2)
29 WHERE EXISTS (SELECT *
30 FROM profile_education_degree AS d
31 WHERE e.id = d.eduid)
32 ORDER BY gc.countryFR, 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 eduid, degreeid
65 FROM profile_education_degree
66 ORDER BY eduid");
67 $edu_degree = $res->next();
68 for ($eduid = 1; $edu_degree; ++$eduid) {
69 $html .= '[';
70 if ($edu_degree['0'] == $eduid) {
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 }
78 $html .= ']';
79 if ($edu_degree) {
80 $html .= ",\n";
81 }
82 }
83 return $html;
84 }
85 Platal::page()->register_function('education_degree', 'education_degree');
86
87 /** affiche tous les types possibles de diplômes
88 */
89 function education_degree_all()
90 {
91 $res = XDB::query("SELECT id
92 FROM profile_education_degree_enum
93 ORDER BY id");
94 return implode(',', $res->fetchColumn());
95 }
96 Platal::page()->register_function('education_degree_all', 'education_degree_all');
97
98 /** affiche les noms de tous les diplômes possibles
99 */
100 function education_degree_name()
101 {
102 $res = XDB::query("SELECT degree
103 FROM profile_education_degree_enum
104 ORDER BY id");
105 return '"' . implode('","', $res->fetchColumn()) . '"';
106 }
107 Platal::page()->register_function('education_degree_name', 'education_degree_name');
108
109 /** formatte une formation pour l'affichage
110 */
111 function education_fmt($name, $url, $degree, $grad_year, $field, $program, $sexe, $long)
112 {
113 $field = strtolower($field);
114 $txt = "";
115
116 if ($grad_year || $field || $program) {
117 $txt .= "<span title=\"(";
118 if ($program) {
119 $txt .= $program;
120 if ($grad_year || $field) {
121 $txt .= ", ";
122 }
123 }
124 if ($grad_year) {
125 if ($sexe) {
126 $txt .= "diplômée en $grad_year";
127 } else {
128 $txt .= "diplômé en $grad_year";
129 }
130 if ($field) {
131 $txt .= ", ";
132 }
133 }
134 if ($field) {
135 $txt .= "domaine : $field)\">";
136 }
137 }
138
139 if (($degree != "Lic.") || ($long)) {
140 if (($degree != "Ing.") && ($degree != "Dipl.")) {
141 $txt .= $degree;
142 }
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 }
152 $txt .= "</span>";
153
154 return $txt;
155 }
156
157 function _education_fmt($params, &$smarty)
158 {
159 $params = new PlDict($params);
160 $edu = $params->v('edu');
161 if (!$params->has('sex')) {
162 $profile = $params->v('profile');
163 $sex = $profile->isFemale();
164 } else {
165 $sex = $params->b('sex');
166 }
167 return education_fmt($edu['school_short'], $edu['school_url'], $edu['degree_short'], $edu['grad_year'],
168 $edu['field'], $edu['program'], $sex, $params->b('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 ?>