Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

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

Historique | Voir | Annoter | Télécharger (6,4 ko)

1
<?php
2
/*
3
 * @version $Id: group.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:
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
/**
42
 * Show devices of a group
43
 *
44
 * @param $ID integer : group ID
45
 */
46
function showGroupDevice($ID){
47
        global $DB,$CFG_GLPI, $LANG,$LINK_ID_TABLE,$INFOFORM_PAGES;
48

    
49
        $ci=new CommonItem();
50
        echo "<div class='center'><table class='tab_cadre'><tr><th>".$LANG["common"][17]."</th><th>".$LANG["common"][16]."</th></tr>";
51
        foreach ($CFG_GLPI["linkuser_types"] as $type){
52
                $query="SELECT * from ".$LINK_ID_TABLE[$type]." WHERE FK_groups='$ID'";
53
                $result=$DB->query($query);
54
                if ($DB->numrows($result)>0){
55
                        $ci->setType($type);
56
                        $type_name=$ci->getType();
57
                        $cansee=haveTypeRight($type,"r");
58
                        while ($data=$DB->fetch_array($result)){
59
                                $link=$data["name"];
60
                                if ($cansee) $link="<a href='".$CFG_GLPI["root_doc"]."/".$INFOFORM_PAGES[$type]."?ID=".$data["ID"]."'>".$link."</a>";
61
                                $linktype="";
62
                                echo "<tr class='tab_bg_1'><td>$type_name</td><td>$link</td></tr>";
63
                        }
64
                }
65

    
66
        }
67
        echo "</table></div>";
68
}
69

    
70
/**
71
 * Show users of a group
72
 *
73
 * @param $target string : where to go on action
74
 * @param $ID integer : group ID
75
 */
76
function showGroupUsers($target,$ID){
77
        global $DB,$CFG_GLPI, $LANG;
78

    
79
        if (!haveRight("user","r")||!haveRight("group","r"))        return false;
80

    
81
        $canedit=haveRight("group","w");
82

    
83
        $nb_per_line=3;
84
        if ($canedit) $headerspan=$nb_per_line*2;
85
        else $headerspan=$nb_per_line;
86

    
87

    
88
        $group=new Group();
89

    
90
        if ($group->getFromDB($ID)){
91
        
92
                if ($canedit) {
93
                        echo "<form name='groupuser_form' id='groupuser_form' method='post' action=\"$target\">";
94
                }
95
                echo "<div class='center'><table class='tab_cadrehov'><tr><th colspan='$headerspan'>".$LANG["Menu"][14]."</th></tr>";
96
                $query="SELECT glpi_users.*,glpi_users_groups.ID as linkID from glpi_users_groups LEFT JOIN glpi_users ON (glpi_users.ID = glpi_users_groups.FK_users) WHERE glpi_users_groups.FK_groups='$ID' ORDER BY glpi_users.name, glpi_users.realname, glpi_users.firstname";
97
        
98
                $used = array();
99

    
100
                $result=$DB->query($query);
101
                if ($DB->numrows($result)>0){
102
                        $i=0;
103
        
104
                        while ($data=$DB->fetch_array($result)){
105
                                if ($i%$nb_per_line==0) {
106
                                        if ($i!=0) echo "</tr>";
107
                                        echo "<tr class='tab_bg_1'>";
108
                                }
109
                                if ($canedit){
110
                                        echo "<td width='10'>";
111
                                        $sel="";
112
                                        if (isset($_GET["select"])&&$_GET["select"]=="all") $sel="checked";
113
                                        echo "<input type='checkbox' name='item[".$data["linkID"]."]' value='1' $sel>";
114
                                        echo "</td>";
115
                                }
116
        
117
                                $used[$data["ID"]]=$data["ID"];
118
                                
119
                                echo "<td>";
120
                                echo formatUserName($data["ID"],$data["name"],$data["realname"],$data["firstname"],1);
121
                                echo "</td>";
122
                                $i++;
123
                        }
124
                        while ($i%$nb_per_line!=0){
125
                                echo "<td>&nbsp;</td>";
126
                                if ($canedit) echo "<td>&nbsp;</td>";
127
                                $i++;
128
                        }
129
                        echo "</tr>";
130
                }
131
        
132
                echo "</table></div>";
133
        
134
                if ($canedit){
135

    
136
                        echo "<div class='center'>";
137
                        echo "<table width='80%'>";
138
                        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&amp;select=all'>".$LANG["buttons"][18]."</a></td>";
139
        
140
                        echo "<td>/</td><td class='center'><a onclick= \"if ( unMarkAllRows('groupuser_form') ) return false;\" href='".$_SERVER['PHP_SELF']."?ID=$ID&amp;select=none'>".$LANG["buttons"][19]."</a>";
141
                        echo "</td><td align='left' width='80%'>";
142
                        echo "<input type='hidden' name='FK_groups' value='$ID'>";
143
                        echo "<input type='submit' name='deleteuser' value=\"".$LANG["buttons"][6]."\" class='submit'>";
144
                        echo "</td>";
145
                        echo "</table>";
146
                        echo "</div>";
147

    
148
                        $res=dropdownUsersSelect (true, "all", $group->fields["FK_entities"], 0, $used);
149
                        $nb=($res ? $DB->result($res,0,"CPT") : 0);
150
                        
151
                        if ($nb) {                
152
                                echo "<div class='center'>";
153
                                echo "<table  class='tab_cadre_fixe'>";
154
                                echo "<tr class='tab_bg_1'><th colspan='2'>".$LANG["setup"][603]."</tr><tr><td class='tab_bg_2' align='center'>";
155
                                dropdownUsers("FK_users",0,"all",-1,1,$group->fields["FK_entities"],0,$used);
156
                                //dropdownAllUsers("FK_users",0,1,$group->fields["FK_entities"],0,$used);
157
                                echo "</td><td align='center' class='tab_bg_2'>";
158
                                echo "<input type='submit' name='adduser' value=\"".$LANG["buttons"][8]."\" class='submit'>";
159
                                echo "</td></tr>";
160
                
161
                                echo "</table></div><br>";
162
                        }
163
        
164
                        echo "</form>";
165
                }
166
        }
167
}
168

    
169
/**
170
 * Add a group to a user 
171
 *
172
 * @param $uID integer : user ID
173
 * @param $gID integer : group ID
174
 */
175
function addUserGroup($uID,$gID){
176
        global $DB;
177
        if ($uID>0&&$gID>0){
178

    
179
                $query="INSERT INTO glpi_users_groups (FK_users,FK_groups ) VALUES ('$uID','$gID');";
180
                $result = $DB->query($query);
181
        }
182
}
183

    
184
/**
185
 * Delete a group to a user 
186
 *
187
 * @param $ID integer : glpi_users_groups ID
188
 */
189
function deleteUserGroup($ID){
190

    
191
        global $DB;
192
        $query="DELETE FROM glpi_users_groups WHERE ID= '$ID';";
193
        $result = $DB->query($query);
194
}
195

    
196
/* // NOT_USED
197
function searchGroupID($name,$FK_entities){
198
        global $DB;
199
        $query ="SELECT ID from glpi_groups where name='$name' AND FK_entities='$FK_entities'";
200
        $result = $DB->query($query);
201
        if ($DB->numrows($result) > 0){
202
                $data= $DB->fetch_array($result);
203
                $groupID = $data['ID'];
204
                return $groupID;
205
        } 
206
        else return -1;
207
}
208
*/
209
?>
Redmine Appliance - Powered by TurnKey Linux