ryxeo-glpi-git / inc / user.function.php @ b67d8923
Historique | Voir | Annoter | Télécharger (19,3 ko)
1 | b67d8923 | Eric Seigne | <?php
|
---|---|---|---|
2 | /*
|
||
3 | * @version $Id: user.function.php 7876 2009-01-23 15:50:37Z moyo $
|
||
4 | -------------------------------------------------------------------------
|
||
5 | GLPI - Gestionnaire Libre de Parc Informatique
|
||
6 | Copyright (C) 2003-2009 by the INDEPNET Development Team.
|
||
7 | |||
8 | http://indepnet.net/ http://glpi-project.org
|
||
9 | -------------------------------------------------------------------------
|
||
10 | |||
11 | LICENSE
|
||
12 | |||
13 | This file is part of GLPI.
|
||
14 | |||
15 | GLPI is free software; you can redistribute it and/or modify
|
||
16 | it under the terms of the GNU General Public License as published by
|
||
17 | the Free Software Foundation; either version 2 of the License, or
|
||
18 | (at your option) any later version.
|
||
19 | |||
20 | GLPI is distributed in the hope that it will be useful,
|
||
21 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
23 | GNU General Public License for more details.
|
||
24 | |||
25 | You should have received a copy of the GNU General Public License
|
||
26 | along with GLPI; if not, write to the Free Software
|
||
27 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||
28 | --------------------------------------------------------------------------
|
||
29 | */
|
||
30 | |||
31 | // ----------------------------------------------------------------------
|
||
32 | // Original Author of file:
|
||
33 | // Purpose of file:
|
||
34 | // ----------------------------------------------------------------------
|
||
35 | |||
36 | if (!defined('GLPI_ROOT')){ |
||
37 | die("Sorry. You can't access directly to this file"); |
||
38 | } |
||
39 | |||
40 | |||
41 | /** Simple add user form for external auth
|
||
42 | * @param $target where to go on action
|
||
43 | */
|
||
44 | function showAddExtAuthUserForm($target){ |
||
45 | global $LANG; |
||
46 | |||
47 | if (!haveRight("user","w")) return false; |
||
48 | |||
49 | |||
50 | echo "<div class='center'>\n"; |
||
51 | echo "<form method='get' action=\"$target\">\n"; |
||
52 | |||
53 | echo "<table class='tab_cadre'>\n"; |
||
54 | echo "<tr><th colspan='4'>".$LANG["setup"][126]."</th></tr>\n"; |
||
55 | echo "<tr class='tab_bg_1'><td>".$LANG["login"][6]."</td>\n"; |
||
56 | echo "<td>"; |
||
57 | echo "<input type='text' name='login'>"; |
||
58 | echo "</td>"; |
||
59 | echo "<td align='center' class='tab_bg_2'>\n"; |
||
60 | echo "<input type='hidden' name='ext_auth' value='1'>\n"; |
||
61 | echo "<input type='submit' name='add_ext_auth_ldap' value=\"".$LANG["buttons"][8]." ".$LANG["login"][2]."\" class='submit'>\n"; |
||
62 | echo "</td>"; |
||
63 | echo "<td align='center' class='tab_bg_2'>\n"; |
||
64 | echo "<input type='submit' name='add_ext_auth_simple' value=\"".$LANG["buttons"][8]." ".$LANG["common"][62]."\" class='submit'>\n"; |
||
65 | echo "</td>"; |
||
66 | |||
67 | echo "</tr>\n"; |
||
68 | |||
69 | echo "</table>"; |
||
70 | echo "</form>\n"; |
||
71 | |||
72 | echo "</div>\n"; |
||
73 | |||
74 | } |
||
75 | /** Show items of a user
|
||
76 | * @param $ID user ID
|
||
77 | */
|
||
78 | function showDeviceUser($ID){ |
||
79 | global $DB,$CFG_GLPI, $LANG, $LINK_ID_TABLE,$INFOFORM_PAGES; |
||
80 | |||
81 | $group_where=""; |
||
82 | $groups=array(); |
||
83 | $query="SELECT glpi_users_groups.FK_groups, glpi_groups.name FROM glpi_users_groups LEFT JOIN glpi_groups ON (glpi_groups.ID = glpi_users_groups.FK_groups) WHERE glpi_users_groups.FK_users='$ID';"; |
||
84 | $result=$DB->query($query); |
||
85 | if ($DB->numrows($result)>0){ |
||
86 | $first=true; |
||
87 | while ($data=$DB->fetch_array($result)){ |
||
88 | if ($first){ |
||
89 | $first=false; |
||
90 | } else {
|
||
91 | $group_where.=" OR "; |
||
92 | } |
||
93 | $group_where.=" FK_groups = '".$data["FK_groups"]."' "; |
||
94 | $groups[$data["FK_groups"]]=$data["name"]; |
||
95 | } |
||
96 | } |
||
97 | |||
98 | |||
99 | $ci=new CommonItem(); |
||
100 | echo "<div class='center'><table class='tab_cadre_fixe'><tr><th>".$LANG["common"][17]."</th><th>".$LANG["common"][16]."</th><th>".$LANG["common"][19]."</th><th>".$LANG["common"][20]."</th><th> </th></tr>"; |
||
101 | |||
102 | foreach ($CFG_GLPI["linkuser_types"] as $type){ |
||
103 | if (haveTypeRight($type,'r')){ |
||
104 | $query="SELECT * FROM ".$LINK_ID_TABLE[$type]." WHERE FK_users='$ID'"; |
||
105 | |||
106 | if (in_array($LINK_ID_TABLE[$type],$CFG_GLPI["template_tables"])){ |
||
107 | $query.=" AND is_template=0 "; |
||
108 | } |
||
109 | if (in_array($LINK_ID_TABLE[$type],$CFG_GLPI["deleted_tables"])){ |
||
110 | $query.=" AND deleted=0 "; |
||
111 | } |
||
112 | |||
113 | $result=$DB->query($query); |
||
114 | if ($DB->numrows($result)>0){ |
||
115 | $ci->setType($type); |
||
116 | $type_name=$ci->getType(); |
||
117 | $cansee=haveTypeRight($type,"r"); |
||
118 | while ($data=$DB->fetch_array($result)){ |
||
119 | $link=$data["name"]; |
||
120 | if ($cansee) $link="<a href='".$CFG_GLPI["root_doc"]."/".$INFOFORM_PAGES[$type]."?ID=".$data["ID"]."'>".$link.(($CFG_GLPI["view_ID"]||empty($link))?" (".$data["ID"].")":"")."</a>"; |
||
121 | $linktype=""; |
||
122 | if ($data["FK_users"]==$ID){ |
||
123 | $linktype=$LANG["common"][34]; |
||
124 | } |
||
125 | echo "<tr class='tab_bg_1'><td class='center'>$type_name</td><td class='center'>$link</td>"; |
||
126 | echo "<td class='center'>"; |
||
127 | if (isset($data["serial"])&&!empty($data["serial"])){ |
||
128 | echo $data["serial"]; |
||
129 | } else echo ' '; |
||
130 | echo "</td><td class='center'>"; |
||
131 | if (isset($data["otherserial"])&&!empty($data["otherserial"])) { |
||
132 | echo $data["otherserial"]; |
||
133 | } else echo ' '; |
||
134 | |||
135 | echo "<td class='center'>$linktype</td></tr>"; |
||
136 | } |
||
137 | } |
||
138 | } |
||
139 | } |
||
140 | echo "</table></div><br>"; |
||
141 | |||
142 | if (!empty($group_where)){ |
||
143 | echo "<div class='center'><table class='tab_cadre_fixe'><tr><th>".$LANG["common"][17]."</th><th>".$LANG["common"][16]."</th><th>".$LANG["common"][19]."</th><th>".$LANG["common"][20]."</th><th> </th></tr>"; |
||
144 | |||
145 | foreach ($CFG_GLPI["linkuser_types"] as $type){ |
||
146 | $query="SELECT * FROM ".$LINK_ID_TABLE[$type]." WHERE $group_where"; |
||
147 | |||
148 | if (in_array($LINK_ID_TABLE[$type],$CFG_GLPI["template_tables"])){ |
||
149 | $query.=" AND is_template=0 "; |
||
150 | } |
||
151 | if (in_array($LINK_ID_TABLE[$type],$CFG_GLPI["deleted_tables"])){ |
||
152 | $query.=" AND deleted=0 "; |
||
153 | } |
||
154 | |||
155 | $result=$DB->query($query); |
||
156 | if ($DB->numrows($result)>0){ |
||
157 | $ci->setType($type); |
||
158 | $type_name=$ci->getType(); |
||
159 | $cansee=haveTypeRight($type,"r"); |
||
160 | while ($data=$DB->fetch_array($result)){ |
||
161 | $link=$data["name"]; |
||
162 | if ($cansee) $link="<a href='".$CFG_GLPI["root_doc"]."/".$INFOFORM_PAGES[$type]."?ID=".$data["ID"]."'>".$link.(($CFG_GLPI["view_ID"]||empty($link))?" (".$data["ID"].")":"")."</a>"; |
||
163 | $linktype=""; |
||
164 | if (isset($groups[$data["FK_groups"]])){ |
||
165 | $linktype=$LANG["common"][35]." ".$groups[$data["FK_groups"]]; |
||
166 | } |
||
167 | echo "<tr class='tab_bg_1'><td class='center'>$type_name</td><td class='center'>$link</td>"; |
||
168 | echo "<td class='center'>"; |
||
169 | if (isset($data["serial"])&&!empty($data["serial"])){ |
||
170 | echo $data["serial"]; |
||
171 | } else echo ' '; |
||
172 | echo "</td><td class='center'>"; |
||
173 | if (isset($data["otherserial"])&&!empty($data["otherserial"])) { |
||
174 | echo $data["otherserial"]; |
||
175 | } else echo ' '; |
||
176 | echo "</td><td class='center'>$linktype</td></tr>"; |
||
177 | } |
||
178 | } |
||
179 | |||
180 | } |
||
181 | echo "</table></div><br>"; |
||
182 | } |
||
183 | } |
||
184 | |||
185 | /** Show groups of a user
|
||
186 | * @param $ID user ID
|
||
187 | * @param $target where to go on action
|
||
188 | */
|
||
189 | function showGroupAssociated($target,$ID){ |
||
190 | global $DB,$CFG_GLPI, $LANG; |
||
191 | |||
192 | if (!haveRight("user","r")||!haveRight("group","r")) return false; |
||
193 | |||
194 | $canedit=haveRight("user","w"); |
||
195 | $strict_entities=getUserEntities($ID,false); |
||
196 | if (!haveAccessToOneOfEntities($strict_entities)&&!isViewAllEntities()){ |
||
197 | $canedit=false; |
||
198 | } |
||
199 | |||
200 | $nb_per_line=3; |
||
201 | if ($canedit) $headerspan=$nb_per_line*2; |
||
202 | else $headerspan=$nb_per_line; |
||
203 | |||
204 | echo "<form name='groupuser_form' id='groupuser_form' method='post' action=\"$target\">"; |
||
205 | |||
206 | if ($canedit){ |
||
207 | echo "<div class='center'>"; |
||
208 | echo "<table class='tab_cadre_fixe'>"; |
||
209 | |||
210 | echo "<tr class='tab_bg_1'><th colspan='2'>".$LANG["setup"][604]."</tr><tr><td class='tab_bg_2' align='center'>"; |
||
211 | echo "<input type='hidden' name='FK_users' value='$ID'>"; |
||
212 | $query="SELECT glpi_groups.ID, glpi_groups.name, glpi_entities.completename FROM glpi_groups LEFT JOIN glpi_entities ON (glpi_groups.FK_entities=glpi_entities.ID) WHERE glpi_groups.FK_entities IN (SELECT FK_entities FROM glpi_users_profiles WHERE FK_users = '$ID')"; |
||
213 | $result=$DB->query($query); |
||
214 | if ($DB->numrows($result)>0){ |
||
215 | $groups=array(); |
||
216 | while ($data=$DB->fetch_array($result)){ |
||
217 | $groups[$data['ID']]=$data['name']; |
||
218 | if (!empty($data['completename'])){ |
||
219 | $groups[$data['ID']].= ' - '.$data['completename']; |
||
220 | } |
||
221 | } |
||
222 | dropdownArrayValues("FK_groups",$groups); |
||
223 | |||
224 | } |
||
225 | echo "</td><td align='center' class='tab_bg_2'>"; |
||
226 | echo "<input type='submit' name='addgroup' value=\"".$LANG["buttons"][8]."\" class='submit'>"; |
||
227 | echo "</td></tr>"; |
||
228 | |||
229 | echo "</table></div><br>"; |
||
230 | } |
||
231 | |||
232 | echo "<div class='center'><table class='tab_cadrehov'><tr><th colspan='$headerspan'>".$LANG["Menu"][36]."</th></tr>"; |
||
233 | $query="SELECT glpi_groups.*, glpi_users_groups.ID AS IDD,glpi_users_groups.ID as linkID from glpi_users_groups LEFT JOIN glpi_groups ON (glpi_groups.ID = glpi_users_groups.FK_groups) WHERE glpi_users_groups.FK_users='$ID' ORDER BY glpi_groups.name"; |
||
234 | |||
235 | $result=$DB->query($query); |
||
236 | if ($DB->numrows($result)>0){ |
||
237 | $i=0; |
||
238 | |||
239 | while ($data=$DB->fetch_array($result)){ |
||
240 | if ($i%$nb_per_line==0) { |
||
241 | if ($i!=0) echo "</tr>"; |
||
242 | echo "<tr class='tab_bg_1'>"; |
||
243 | } |
||
244 | |||
245 | if ($canedit){ |
||
246 | echo "<td width='10'>"; |
||
247 | $sel=""; |
||
248 | if (isset($_GET["select"])&&$_GET["select"]=="all") $sel="checked"; |
||
249 | echo "<input type='checkbox' name='item[".$data["linkID"]."]' value='1' $sel>"; |
||
250 | echo "</td>"; |
||
251 | } |
||
252 | |||
253 | echo "<td><a href='".$CFG_GLPI["root_doc"]."/front/group.form.php?ID=".$data["ID"]."'>".$data["name"].($CFG_GLPI["view_ID"]?" (".$data["ID"].")":"")."</a>"; |
||
254 | echo " "; |
||
255 | |||
256 | echo "</td>"; |
||
257 | $i++;
|
||
258 | } |
||
259 | while ($i%$nb_per_line!=0){ |
||
260 | echo "<td> </td>"; |
||
261 | $i++;
|
||
262 | } |
||
263 | echo "</tr>"; |
||
264 | } |
||
265 | |||
266 | echo "</table></div>"; |
||
267 | |||
268 | if ($canedit){ |
||
269 | echo "<div class='center'>"; |
||
270 | echo "<table width='80%'>"; |
||
271 | echo "<tr><td><img src=\"".$CFG_GLPI["root_doc"]."/pics/arrow-left.png\" alt=''></td><td class='center'><a onclick= \"if ( markAllRows('groupuser_form') ) return false;\" href='".$_SERVER['PHP_SELF']."?ID=$ID&select=all'>".$LANG["buttons"][18]."</a></td>"; |
||
272 | |||
273 | echo "<td>/</td><td class='center'><a onclick= \"if ( unMarkAllRows('groupuser_form') ) return false;\" href='".$_SERVER['PHP_SELF']."?ID=$ID&select=none'>".$LANG["buttons"][19]."</a>"; |
||
274 | echo "</td><td align='left' width='80%'>"; |
||
275 | echo "<input type='submit' name='deletegroup' value=\"".$LANG["buttons"][6]."\" class='submit'>"; |
||
276 | echo "</td></tr>"; |
||
277 | echo "</table>"; |
||
278 | |||
279 | echo "</div>"; |
||
280 | |||
281 | } |
||
282 | |||
283 | echo "</form>"; |
||
284 | |||
285 | } |
||
286 | |||
287 | /** Show rights of a user
|
||
288 | * @param $ID user ID
|
||
289 | * @param $target where to go on action
|
||
290 | */
|
||
291 | function showUserRights($target,$ID){ |
||
292 | global $DB,$CFG_GLPI, $LANG; |
||
293 | |||
294 | if (!haveRight("user","r")) return false; |
||
295 | |||
296 | $canedit=haveRight("user","w"); |
||
297 | |||
298 | $strict_entities=getUserEntities($ID,false); |
||
299 | if (!haveAccessToOneOfEntities($strict_entities)&&!isViewAllEntities()){ |
||
300 | $canedit=false; |
||
301 | } |
||
302 | |||
303 | $canshowentity=haveRight("entity","r"); |
||
304 | |||
305 | echo "<form name='entityuser_form' id='entityuser_form' method='post' action=\"$target\">"; |
||
306 | |||
307 | if ($canedit){ |
||
308 | echo "<div class='center'>"; |
||
309 | echo "<table class='tab_cadre_fixe'>"; |
||
310 | |||
311 | echo "<tr class='tab_bg_1'><th colspan='4'>".$LANG["entity"][3]."</tr><tr class='tab_bg_2'><td class='center'>"; |
||
312 | echo "<input type='hidden' name='FK_users' value='$ID'>"; |
||
313 | |||
314 | dropdownValue("glpi_entities","FK_entities",0,1,$_SESSION['glpiactiveentities']); |
||
315 | echo "</td><td class='center'>"; |
||
316 | |||
317 | echo $LANG["profiles"][22].":"; |
||
318 | dropdownUnderProfiles("FK_profiles");
|
||
319 | echo "</td><td class='center'>"; |
||
320 | echo $LANG["profiles"][28].":"; |
||
321 | dropdownYesNo("recursive",0); |
||
322 | echo "</td><td class='center'>"; |
||
323 | echo "<input type='submit' name='addright' value=\"".$LANG["buttons"][8]."\" class='submit'>"; |
||
324 | echo "</td></tr>"; |
||
325 | |||
326 | echo "</table></div><br>"; |
||
327 | } |
||
328 | |||
329 | echo "<div class='center'><table class='tab_cadrehov'><tr><th colspan='2'>".$LANG["Menu"][37]."</th><th>".$LANG["profiles"][22]." (D=".$LANG["profiles"][29].", R=".$LANG["profiles"][28].")</th></tr>"; |
||
330 | |||
331 | $query="SELECT DISTINCT glpi_users_profiles.ID as linkID, glpi_profiles.ID, glpi_profiles.name, glpi_users_profiles.recursive, |
||
332 | glpi_users_profiles.dynamic, glpi_entities.completename, glpi_users_profiles.FK_entities
|
||
333 | FROM glpi_users_profiles
|
||
334 | LEFT JOIN glpi_profiles ON (glpi_users_profiles.FK_profiles = glpi_profiles.ID)
|
||
335 | LEFT JOIN glpi_entities ON (glpi_users_profiles.FK_entities = glpi_entities.ID)
|
||
336 | WHERE glpi_users_profiles.FK_users='$ID'
|
||
337 | ORDER BY glpi_profiles.name, glpi_entities.completename;";
|
||
338 | |||
339 | $result=$DB->query($query); |
||
340 | if ($DB->numrows($result)>0){ |
||
341 | $i=0; |
||
342 | |||
343 | while ($data=$DB->fetch_array($result)){ |
||
344 | echo "<tr class='tab_bg_1'>"; |
||
345 | |||
346 | echo "<td width='10'>"; |
||
347 | if ($canedit&&in_array($data["FK_entities"],$_SESSION['glpiactiveentities'])){ |
||
348 | $sel=""; |
||
349 | if (isset($_GET["select"])&&$_GET["select"]=="all") $sel="checked"; |
||
350 | echo "<input type='checkbox' name='item[".$data["linkID"]."]' value='1' $sel>"; |
||
351 | } else {
|
||
352 | echo " "; |
||
353 | } |
||
354 | echo "</td>"; |
||
355 | |||
356 | if ($data["FK_entities"]==0) { |
||
357 | $data["completename"]=$LANG["entity"][2]; |
||
358 | } |
||
359 | echo "<td>"; |
||
360 | if ($canshowentity){ |
||
361 | echo "<a href='".$CFG_GLPI["root_doc"]."/front/entity.form.php?ID=".$data["FK_entities"]."'>"; |
||
362 | } |
||
363 | echo $data["completename"].($CFG_GLPI["view_ID"]?" (".$data["FK_entities"].")":""); |
||
364 | if ($canshowentity){ |
||
365 | echo "</a>"; |
||
366 | } |
||
367 | echo "</td>"; |
||
368 | echo "<td>".$data["name"]; |
||
369 | if ($data["dynamic"]||$data["recursive"]){ |
||
370 | echo "<strong> ("; |
||
371 | if ($data["dynamic"]) echo "D"; |
||
372 | if ($data["dynamic"]&$data["recursive"]) echo ", "; |
||
373 | if ($data["recursive"]) echo "R"; |
||
374 | echo ")</strong>"; |
||
375 | } |
||
376 | |||
377 | echo "</td>"; |
||
378 | $i++;
|
||
379 | } |
||
380 | echo "</tr>"; |
||
381 | } |
||
382 | |||
383 | echo "</table></div>"; |
||
384 | |||
385 | if ($canedit){ |
||
386 | echo "<div class='center'>"; |
||
387 | echo "<table width='80%'>"; |
||
388 | echo "<tr><td><img src=\"".$CFG_GLPI["root_doc"]."/pics/arrow-left.png\" alt=''></td><td class='center'><a onclick= \"if ( markAllRows('entityuser_form') ) return false;\" href='".$_SERVER['PHP_SELF']."?ID=$ID&select=all'>".$LANG["buttons"][18]."</a></td>"; |
||
389 | |||
390 | echo "<td>/</td><td class='center'><a onclick= \"if ( unMarkAllRows('entityuser_form') ) return false;\" href='".$_SERVER['PHP_SELF']."?ID=$ID&select=none'>".$LANG["buttons"][19]."</a>"; |
||
391 | echo "</td><td align='left' width='80%'>"; |
||
392 | echo "<input type='submit' name='deleteright' value=\"".$LANG["buttons"][6]."\" class='submit'>"; |
||
393 | echo "</td></tr>"; |
||
394 | echo "</table>"; |
||
395 | |||
396 | echo "</div>"; |
||
397 | |||
398 | } |
||
399 | |||
400 | echo "</form>"; |
||
401 | |||
402 | } |
||
403 | |||
404 | |||
405 | |||
406 | /** Generate vcard for an user
|
||
407 | * @param $ID user ID
|
||
408 | */
|
||
409 | function generateUserVcard($ID){ |
||
410 | |||
411 | $user = new User; |
||
412 | $user->getFromDB($ID); |
||
413 | |||
414 | // build the Vcard
|
||
415 | |||
416 | $vcard = new vCard(); |
||
417 | |||
418 | if (!empty($user->fields["realname"])||!empty($user->fields["firstname"])) $vcard->setName($user->fields["realname"], $user->fields["firstname"], "", ""); |
||
419 | else $vcard->setName($user->fields["name"], "", "", ""); |
||
420 | |||
421 | $vcard->setPhoneNumber($user->fields["phone"], "PREF;WORK;VOICE"); |
||
422 | $vcard->setPhoneNumber($user->fields["phone2"], "HOME;VOICE"); |
||
423 | $vcard->setPhoneNumber($user->fields["mobile"], "WORK;CELL"); |
||
424 | |||
425 | //if ($user->birthday) $vcard->setBirthday($user->birthday);
|
||
426 | |||
427 | $vcard->setEmail($user->fields["email"]); |
||
428 | |||
429 | $vcard->setNote($user->fields["comments"]); |
||
430 | |||
431 | // send the VCard
|
||
432 | |||
433 | $output = $vcard->getVCard(); |
||
434 | |||
435 | |||
436 | $filename =$vcard->getFileName(); // "xxx xxx.vcf" |
||
437 | |||
438 | @Header("Content-Disposition: attachment; filename=\"$filename\""); |
||
439 | @Header("Content-Length: ".strlen($output)); |
||
440 | @Header("Connection: close"); |
||
441 | @Header("content-type: text/x-vcard; charset=UTF-8"); |
||
442 | |||
443 | echo $output; |
||
444 | |||
445 | } |
||
446 | |||
447 | /** Get entities for which a user have a right
|
||
448 | * @param $ID user ID
|
||
449 | * @param $recursive check also using recurisve rights
|
||
450 | */
|
||
451 | function getUserEntities($ID,$recursive=true){ |
||
452 | global $DB; |
||
453 | |||
454 | $query="SELECT DISTINCT FK_entities, recursive |
||
455 | FROM glpi_users_profiles
|
||
456 | WHERE FK_users='$ID';";
|
||
457 | $result=$DB->query($query); |
||
458 | if ($DB->numrows($result)>0){ |
||
459 | $entities=array(); |
||
460 | while ($data=$DB->fetch_assoc($result)){ |
||
461 | if ($data['recursive']&&$recursive){ |
||
462 | $tab=getSonsOfTreeItem('glpi_entities',$data['FK_entities']); |
||
463 | $entities=array_merge($tab,$entities); |
||
464 | } else {
|
||
465 | $entities[]=$data['FK_entities']; |
||
466 | } |
||
467 | } |
||
468 | return $entities; |
||
469 | } |
||
470 | |||
471 | return array(); |
||
472 | } |
||
473 | |||
474 | /** Get all the authentication methods parameters for a specific auth_method and id_auth and return it as an array
|
||
475 | * @param $auth_method Authentication method
|
||
476 | * @param $id_auth Authentication method ID
|
||
477 | */
|
||
478 | function getAuthMethodsByID($auth_method, $id_auth) { |
||
479 | global $DB; |
||
480 | |||
481 | $auth_methods = array (); |
||
482 | $sql = ""; |
||
483 | |||
484 | switch ($auth_method) { |
||
485 | case AUTH_X509 : |
||
486 | case AUTH_EXTERNAL : |
||
487 | case AUTH_CAS : |
||
488 | if ($id_auth>0){ |
||
489 | //Get all the ldap directories
|
||
490 | $sql = "SELECT * FROM glpi_auth_ldap WHERE ID='" . $id_auth."'"; |
||
491 | } |
||
492 | break;
|
||
493 | case AUTH_LDAP : |
||
494 | //Get all the ldap directories
|
||
495 | $sql = "SELECT * FROM glpi_auth_ldap WHERE ID='" . $id_auth."'"; |
||
496 | break;
|
||
497 | case AUTH_MAIL : |
||
498 | //Get all the pop/imap servers
|
||
499 | $sql = "SELECT * FROM glpi_auth_mail WHERE ID='" . $id_auth."'"; |
||
500 | break;
|
||
501 | } |
||
502 | |||
503 | if ($sql != "") { |
||
504 | $result = $DB->query($sql); |
||
505 | if ($DB->numrows($result) > 0) { |
||
506 | $auth_methods = $DB->fetch_array($result); |
||
507 | } |
||
508 | } |
||
509 | //Return all the authentication methods in an array
|
||
510 | return $auth_methods; |
||
511 | } |
||
512 | |||
513 | /** Get name of an authentication method
|
||
514 | * @param $auth_method Authentication method
|
||
515 | * @param $id_auth Authentication method ID
|
||
516 | * @param $link show links to config page ?
|
||
517 | * @param $name override the name if not empty
|
||
518 | */
|
||
519 | function getAuthMethodName($auth_method, $id_auth, $link=0,$name=''){ |
||
520 | global $LANG,$CFG_GLPI; |
||
521 | switch ($auth_method) { |
||
522 | case AUTH_LDAP : |
||
523 | if (empty($name)){ |
||
524 | $method = getAuthMethodsByID($auth_method,$id_auth); |
||
525 | $name=$method["name"]; |
||
526 | } |
||
527 | $out= $LANG["login"][2]; |
||
528 | if ($link && haveRight("config", "w")){ |
||
529 | return $out."  " . $LANG["common"][52] . " <a href=\"" . $CFG_GLPI["root_doc"] . "/front/setup.auth.php?next=extauth_ldap&ID=" . $id_auth . "\">" . $name . "</a>"; |
||
530 | } else {
|
||
531 | return $out."  " . $LANG["common"][52] . " " . $name; |
||
532 | } |
||
533 | break;
|
||
534 | case AUTH_MAIL : |
||
535 | if (empty($name)){ |
||
536 | $method = getAuthMethodsByID($auth_method,$id_auth); |
||
537 | $name=$method["name"]; |
||
538 | } |
||
539 | $out= $LANG["login"][3]; |
||
540 | if ($link && haveRight("config", "w")){ |
||
541 | return $out. "  " . $LANG["common"][52] . " <a href=\"" . $CFG_GLPI["root_doc"] . "/front/setup.auth.php?next=extauth_mail&ID=" . $id_auth . "\">" . $name . "</a>"; |
||
542 | } else {
|
||
543 | return $out. "  " . $LANG["common"][52] . " " . $name; |
||
544 | } |
||
545 | break;
|
||
546 | case AUTH_CAS : |
||
547 | return $LANG["login"][4]; |
||
548 | break;
|
||
549 | case AUTH_X509 : |
||
550 | return $LANG["setup"][190]; |
||
551 | break;
|
||
552 | case AUTH_EXTERNAL : |
||
553 | return $LANG["common"][62]; |
||
554 | break;
|
||
555 | case AUTH_DB_GLPI : |
||
556 | return $LANG["login"][18]; |
||
557 | break;
|
||
558 | case NOT_YET_AUTHENTIFIED : |
||
559 | return $LANG["login"][9]; |
||
560 | break;
|
||
561 | } |
||
562 | } |
||
563 | |||
564 | /** Get LDAP fields to sync to GLPI data from a glpi_auth_ldap array
|
||
565 | * @param $auth_method_array Authentication method config array
|
||
566 | */
|
||
567 | function getLDAPSyncFields($auth_method_array){ |
||
568 | |||
569 | $ret=array(); |
||
570 | |||
571 | $fields=array('ldap_login'=>'name', |
||
572 | 'ldap_field_email'=>'email', |
||
573 | 'ldap_field_realname'=>'realname', |
||
574 | 'ldap_field_firstname'=>'firstname', |
||
575 | 'ldap_field_phone'=>'phone', |
||
576 | 'ldap_field_phone2'=>'phone2', |
||
577 | 'ldap_field_mobile'=>'mobile', |
||
578 | 'ldap_field_comments'=>'comments', |
||
579 | ); |
||
580 | foreach ($fields as $key => $val){ |
||
581 | if (isset($auth_method_array[$key])){ |
||
582 | $ret[$val]=$auth_method_array[$key]; |
||
583 | } |
||
584 | } |
||
585 | return $ret; |
||
586 | } |
||
587 | |||
588 | /** Show onglets for user preferences
|
||
589 | * @param $target where to go on action
|
||
590 | * @param $actif active onglet
|
||
591 | */
|
||
592 | function showUserPreferencesOnglets($target,$actif) { |
||
593 | global $LANG,$PLUGIN_HOOKS; |
||
594 | if (isset($PLUGIN_HOOKS['user_preferences'])&&count($PLUGIN_HOOKS['user_preferences'])){ |
||
595 | echo "<div id='barre_onglets'><ul id='onglet'>"; |
||
596 | echo "<li ".($actif=="my"?"class='actif'":"")."><a href='$target?onglet=my'>".$LANG["title"][26]."</a></li>"; |
||
597 | echo "<li ".($actif=="plugins"?"class='actif'":"")."><a href='$target?onglet=plugins'>".$LANG["common"][29]."</a></li>"; |
||
598 | // echo "<li class='invisible'> </li>";
|
||
599 | // echo "<li ".($actif=="all"?"class='actif'":"")."><a href='$target?onglet=all'>".$LANG["common"][66]."</a></li>";
|
||
600 | |||
601 | echo "</ul></div>"; |
||
602 | } |
||
603 | } |
||
604 | ?> |