Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

ryxeo-glpi-git / inc / entity.function.php @ b67d8923

Historique | Voir | Annoter | Télécharger (7,47 ko)

1
<?php
2
/*
3
 * @version $Id: entity.function.php 7763 2009-01-06 18:44:50Z 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: Julien Dombre
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
 * Show users of an entity
42
 *
43
 * @param $target string : where to go on action
44
 * @param $ID integer : enterprise ID
45
 */
46
function showEntityUser($target,$ID){
47
        global $DB,$CFG_GLPI, $LANG;
48
        
49
        if (!haveRight("entity","r")||!haveRight("user","r"))        return false;
50

    
51
        $canedit=haveRight("entity","w");
52
        $canshowuser=haveRight("user","r");
53
        $nb_per_line=3;
54
        if ($canedit) $headerspan=$nb_per_line*2;
55
        else $headerspan=$nb_per_line;
56

    
57
        echo "<form name='entityuser_form' id='entityuser_form' method='post' action=\"$target\">";
58

    
59
        $entity=new Entity();
60
        
61
        if ($entity->getFromDB($ID)||$ID==0){
62
                if ($canedit){
63
        
64
                        echo "<div class='center'>";
65
                        echo "<table  class='tab_cadre_fixe'>";
66
                        echo "<tr class='tab_bg_1'><th colspan='5'>".$LANG["setup"][603]."</tr><tr><td class='tab_bg_2' align='center'>";
67
                        echo "<input type='hidden' name='FK_entities' value='$ID'>";
68
                        dropdownAllUsers("FK_users",0,1);
69
                        echo "</td><td align='center' class='tab_bg_2'>";
70
                        echo $LANG["profiles"][22].":";
71
                        dropdownUnderProfiles("FK_profiles");
72
                        echo "</td><td align='center' class='tab_bg_2'>";
73
                        echo $LANG["profiles"][28].":";
74
                        dropdownYesNo("recursive",0);
75
                        echo "</td><td align='center' class='tab_bg_2'>";
76
                        echo "<input type='submit' name='adduser' value=\"".$LANG["buttons"][8]."\" class='submit'>";
77
                        echo "</td></tr>";
78
        
79
                        echo "</table></div><br>";
80
        
81
                }
82
        
83
        
84
        
85
                echo "<div class='center'><table class='tab_cadrehov'><tr><th colspan='$headerspan'>".$LANG["Menu"][14]." (D=".$LANG["profiles"][29].", R=".$LANG["profiles"][28].")</th></tr>";
86

    
87

    
88

    
89

    
90
                $query="SELECT DISTINCT glpi_profiles.ID, glpi_profiles.name 
91
                                FROM glpi_users_profiles 
92
                                LEFT JOIN glpi_profiles ON (glpi_users_profiles.FK_profiles = glpi_profiles.ID)
93
                                LEFT JOIN glpi_users ON (glpi_users.ID = glpi_users_profiles.FK_users)
94
                                WHERE glpi_users_profiles.FK_entities='$ID' AND glpi_users.deleted=0;";
95
        
96
                $result=$DB->query($query);
97
                if ($DB->numrows($result)>0){
98
        
99
                        while ($data=$DB->fetch_array($result)){
100
                                echo "<tr><th colspan='$headerspan'>".$data["name"]."</th></tr>";
101

    
102
                                $query="SELECT glpi_users.*,glpi_users_profiles.ID as linkID,glpi_users_profiles.recursive,glpi_users_profiles.dynamic
103
                                        FROM glpi_users_profiles 
104
                                        LEFT JOIN glpi_users ON (glpi_users.ID = glpi_users_profiles.FK_users) 
105
                                        WHERE glpi_users_profiles.FK_entities='$ID' AND glpi_users.deleted=0 AND glpi_users_profiles.FK_profiles='".$data['ID']."'   
106
                                        ORDER BY glpi_users_profiles.FK_profiles, glpi_users.name, glpi_users.realname, glpi_users.firstname";
107
                                $result2=$DB->query($query);
108
                                if ($DB->numrows($result2)>0){
109
                                        $i=0;
110
                                        while ($data2=$DB->fetch_array($result2)){
111
        
112
                                                if ($i%$nb_per_line==0) {
113
                                                        if ($i!=0) echo "</tr>";
114
                                                        echo "<tr class='tab_bg_1'>";
115
                                                }
116
                                                if ($canedit){
117
                                                        echo "<td width='10'>";
118
                                                        $sel="";
119
                                                        if (isset($_GET["select"])&&$_GET["select"]=="all") $sel="checked";
120
                                                        echo "<input type='checkbox' name='item[".$data2["linkID"]."]' value='1' $sel>";
121
                                                        echo "</td>";
122
                                                }
123
                        
124
                                                echo "<td>";
125
                        
126
                                                echo formatUserName($data2["ID"],$data2["name"],$data2["realname"],$data2["firstname"],$canshowuser);
127
                                                if ($data2["dynamic"]||$data2["recursive"]){
128
                                                        echo "<strong>&nbsp;(";
129
                                                        if ($data2["dynamic"]) echo "D";
130
                                                        if ($data2["dynamic"]&&$data2["recursive"]) echo ", ";
131
                                                        if ($data2["recursive"]) echo "R";
132
                                                        echo ")</strong>";
133
                                                }
134
                                                echo "</td>";
135
                                                $i++;
136
                                        }
137
                                        while ($i%$nb_per_line!=0){
138
                                                echo "<td>&nbsp;</td>";
139
                                                if ($canedit) echo "<td>&nbsp;</td>";
140
                                                $i++;
141
                                        }
142
                                        echo "</tr>";
143

    
144
                                } else {
145
                                        echo "<tr colspan='$headerspan'>".$LANG["common"][54]."</tr>";
146
                                }
147

    
148

    
149

    
150
                        }
151

    
152
                }
153
        
154
                echo "</table></div>";
155
        
156
                if ($canedit){
157
                        echo "<div class='center'>";
158
                        echo "<table width='80%'>";
159
                        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&amp;select=all'>".$LANG["buttons"][18]."</a></td>";
160
        
161
                        echo "<td>/</td><td class='center'><a onclick= \"if ( unMarkAllRows('entityuser_form') ) return false;\" href='".$_SERVER['PHP_SELF']."?ID=$ID&amp;select=none'>".$LANG["buttons"][19]."</a>";
162
                        echo "</td><td align='left' width='80%'>";
163
                        echo "<input type='submit' name='deleteuser' value=\"".$LANG["buttons"][6]."\" class='submit'>";
164
                        echo "</td>";
165
                        echo "</table>";
166
        
167
                        echo "</div>";
168
        
169
                }
170
                echo "</form>";
171
        }
172
}
173

    
174
/**
175
 * Add a right to a user 
176
 *
177
 * @param $input array : parameters : need FK_entities / FK_users / FK_profiles optional : recurisve=0 / dynamic=0
178
 * @return new glpi_users_profiles ID
179
 */
180
function addUserProfileEntity($input){
181
        global $DB;
182
        if (!isset($input['FK_entities'])||$input['FK_entities']<0
183
                ||!isset($input['FK_users'])||$input['FK_users']==0
184
                ||!isset($input['FK_profiles'])||$input['FK_profiles']==0) {
185
                return false;
186
        }
187
        if (!isset($input['recursive'])){
188
                $input['recursive']=0;
189
        }
190
        if (!isset($input['dynamic'])){
191
                $input['dynamic']=0;
192
        }
193

    
194
        $user=new User();
195
        $user->cleanCache($input['FK_users']);
196
        $query="INSERT INTO `glpi_users_profiles` ( `FK_users` , `FK_profiles` , `FK_entities` , `recursive` , `dynamic` )
197
                VALUES ('".$input['FK_users']."', '".$input['FK_profiles']."', '".$input['FK_entities']."', '".$input['recursive']."', '".$input['dynamic']."');";
198
        
199
        return $DB->query($query);
200
}
201

    
202
/**
203
 * Delete a right to a user 
204
 *
205
 * @param $ID integer : glpi_users_profiles ID
206
 */
207
function deleteUserProfileEntity($ID){
208

    
209
        global $DB;
210

    
211
        $query="SELECT FK_users FROM glpi_users_profiles WHERE ID= '$ID';";
212
        $result = $DB->query($query);
213
        $data=$DB->fetch_assoc($result);
214
        $user=new User();
215
        $user->cleanCache($data['FK_users']);
216
        
217
        $query="DELETE FROM glpi_users_profiles WHERE ID= '$ID';";
218
        $result = $DB->query($query);
219
}
220

    
221
/**
222
 * Move a right to another entity
223
 *
224
 * @param $ID integer : glpi_users_profiles ID
225
 * @param $FK_entities integer : new entity ID
226
 */
227
function moveUserProfileEntity($ID,$FK_entities){
228

    
229
        global $DB;
230
        $query="UPDATE glpi_users_profiles SET FK_entities='$FK_entities' WHERE ID= '$ID';";
231
        return $DB->query($query);
232
}
233

    
234
?>
Redmine Appliance - Powered by TurnKey Linux