Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

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

Historique | Voir | Annoter | Télécharger (9,69 ko)

1
<?php
2
/*
3
 * @version $Id: enterprise.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
/**
42
 * Print the HTML array for infocoms linked 
43
 *
44
 * Print the HTML array for infocoms linked 
45
 *
46
 *@param $instID array : Manufacturer identifier.
47
 *
48
 *@return Nothing (display)
49
 *
50
 **/
51
function showInfocomEnterprise($instID) {
52

    
53
        global $DB,$CFG_GLPI, $LANG,$INFOFORM_PAGES,$LINK_ID_TABLE,$SEARCH_PAGES;
54

    
55
        if (!haveRight("contact_enterprise","r")) return false;
56

    
57
        $query = "SELECT DISTINCT device_type FROM glpi_infocoms WHERE FK_enterprise = '$instID' ORDER BY device_type";
58

    
59
        $result = $DB->query($query);
60
        $number = $DB->numrows($result);
61
        $i = 0;
62

    
63
        echo "<br><br><div class='center'><table class='tab_cadrehov'>";
64
        echo "<tr><th colspan='2'>";
65
        printPagerForm($_SERVER["REQUEST_URI"]);
66
        echo "</th><th colspan='3'>".$LANG["document"][19].":</th></tr>";
67
        echo "<tr><th>".$LANG["common"][17]."</th>";
68
        echo "<th>".$LANG["entity"][0]."</th>";
69
        echo "<th>".$LANG["common"][16]."</th>";
70
        echo "<th>".$LANG["common"][19]."</th>";
71
        echo "<th>".$LANG["common"][20]."</th>";
72
        echo "</tr>";
73
        $ci=new CommonItem;
74
        $num=0;
75
        while ($i < $number) {
76
                $type=$DB->result($result, $i, "device_type");
77
                if (haveTypeRight($type,"r")&&$type!=CONSUMABLE_ITEM_TYPE&&$type!=CARTRIDGE_ITEM_TYPE&&$type!=LICENSE_TYPE){
78
                        $query = "SELECT ".$LINK_ID_TABLE[$type].".* "
79
                                ." FROM glpi_infocoms "
80
                                ." INNER JOIN ".$LINK_ID_TABLE[$type]." ON (".$LINK_ID_TABLE[$type].".ID = glpi_infocoms.FK_device) "
81
                                ." WHERE glpi_infocoms.device_type='$type' AND glpi_infocoms.FK_enterprise = '$instID' "
82
                                . getEntitiesRestrictRequest(" AND",$LINK_ID_TABLE[$type]) 
83
                                ." ORDER BY FK_entities, ".$LINK_ID_TABLE[$type].".name";
84
                                
85
                        $result_linked=$DB->query($query);
86
                        $nb=$DB->numrows($result_linked);
87
                        $ci->setType($type);
88
                        if ($nb>$_SESSION["glpilist_limit"] && isset($SEARCH_PAGES["$type"])) {
89
                                
90
                                echo "<tr class='tab_bg_1'>";
91
                                echo "<td class='center'>".$ci->getType()."<br />$nb</td>";
92
                                echo "<td class='center' colspan='2'><a href='"
93
                                        . $CFG_GLPI["root_doc"]."/".$SEARCH_PAGES["$type"] . "?" . rawurlencode("contains[0]") . "=" . rawurlencode('$$$$'.$instID) . "&" . rawurlencode("field[0]") . "=53&sort=80&order=ASC&deleted=0&start=0"
94
                                        . "'>" . $LANG["reports"][57]."</a></td>";
95
                                
96
                                echo "<td class='center'>-</td><td class='center'>-</td></tr>";                
97
                        } else if ($nb){
98
                                for ($prem=true;$data=$DB->fetch_assoc($result_linked);$prem=false){
99
                                        $ID="";
100
                                        if($CFG_GLPI["view_ID"]||empty($data["name"])) $ID= " (".$data["ID"].")";
101
                                        $name= "<a href=\"".$CFG_GLPI["root_doc"]."/".$INFOFORM_PAGES[$type]."?ID=".$data["ID"]."\">".$data["name"]."$ID</a>";
102

    
103
                                        echo "<tr class='tab_bg_1'>";
104
                                        if ($prem) {
105
                                                echo "<td class='center' rowspan='$nb' valign='top'>".$ci->getType()
106
                                                        .($nb>1?"<br />$nb</td>":"</td>");
107
                                        }
108
                                        echo "<td class='center'>".getDropdownName("glpi_entities",$data["FK_entities"])."</td>";
109
                                        
110
                                        echo "<td class='center' ".(isset($data['deleted'])&&$data['deleted']?"class='tab_bg_2_2'":"").">".$name."</td>";
111
                                        echo "<td class='center'>".(isset($data["serial"])? "".$data["serial"]."" :"-")."</td>";
112
                                        echo "<td class='center'>".(isset($data["otherserial"])? "".$data["otherserial"]."" :"-")."</td>";
113
                                        echo "</tr>";
114
                                }
115
                        }
116
                        $num+=$nb;                
117
                }
118
                $i++;
119
        }
120
        echo "<tr class='tab_bg_2'><td class='center'>$num</td><td colspan='4'>&nbsp;</td></tr> ";
121
        echo "</table></div>"    ;
122

    
123

    
124
}
125

    
126

    
127
/**
128
 * Show contacts asociated to an enterprise
129
 *
130
 * @param $instID enterprise ID
131
 */
132
function showAssociatedContact($instID) {
133
        global $DB,$CFG_GLPI, $LANG;
134

    
135
        $enterprise=new Enterprise();
136
        if (!$enterprise->can($instID,'r')){
137
                return false;
138
        }
139
        $canedit=$enterprise->can($instID,'w');
140

    
141
        $query = "SELECT glpi_contacts.*, glpi_contact_enterprise.ID as ID_ent, glpi_entities.ID as entity "
142
                . " FROM glpi_contact_enterprise, glpi_contacts "
143
                . " LEFT JOIN glpi_entities ON (glpi_entities.ID=glpi_contacts.FK_entities) "
144
                . " WHERE glpi_contact_enterprise.FK_contact=glpi_contacts.ID AND glpi_contact_enterprise.FK_enterprise = '$instID' "
145
                . getEntitiesRestrictRequest(" AND","glpi_contacts",'','',true) 
146
                . " ORDER BY glpi_entities.completename, glpi_contacts.name";
147

    
148
        $result = $DB->query($query);
149
        $number = $DB->numrows($result);
150
        $i = 0;
151

    
152

    
153
        echo "<br><div class='center'><table class='tab_cadre_fixe'>";
154
        echo "<tr><th colspan='9'>".$LANG["financial"][46].":</th></tr>";
155
        echo "<tr><th>".$LANG["common"][16]."</th><th>".$LANG["entity"][0]."</th><th>".$LANG["help"][35]."</th>";
156
        echo "<th>".$LANG["help"][35]." 2</th><th>".$LANG["common"][42]."</th><th>".$LANG["financial"][30]."</th>";
157
        echo "<th>".$LANG["setup"][14]."</th><th>".$LANG["common"][17]."</th>";
158
        echo "<th>&nbsp;</th></tr>";
159

    
160
        $used=array();
161
        if ($number) while ($data=$DB->fetch_array($result)) {
162
                $ID=$data["ID_ent"];
163
                $used[$data["ID"]]=$data["ID"];
164
                echo "<tr class='tab_bg_1".($data["deleted"]?"_2":"")."'>";
165
                echo "<td class='center'><a href='".$CFG_GLPI["root_doc"]."/front/contact.form.php?ID=".$data["ID"]."'>".$data["name"]." ".$data["firstname"]."</a></td>";
166
                echo "<td align='center'  width='100'>".getDropdownName("glpi_entities",$data["entity"])."</td>";
167
                echo "<td align='center'  width='100'>".$data["phone"]."</td>";
168
                echo "<td align='center'  width='100'>".$data["phone2"]."</td>";
169
                echo "<td align='center'  width='100'>".$data["mobile"]."</td>";
170
                echo "<td align='center'  width='100'>".$data["fax"]."</td>";
171
                echo "<td class='center'><a href='mailto:".$data["email"]."'>".$DB->result($result, $i, "glpi_contacts.email")."</a></td>";
172
                echo "<td class='center'>".getDropdownName("glpi_dropdown_contact_type",$data["type"])."</td>";
173
                echo "<td align='center' class='tab_bg_2'>";
174
                if ($canedit)
175
                        echo "<a href='".$_SERVER['PHP_SELF']."?deletecontact=deletecontact&amp;ID=$ID&amp;eID=$instID'><strong>".$LANG["buttons"][6]."</strong></a>";
176
                else echo "&nbsp;";
177
                echo "</td></tr>";
178
                $i++;
179
        }
180

    
181
        echo "</table><br>"    ;
182
        if ($canedit){
183
                if ($enterprise->fields["recursive"]) {
184
                        $nb=countElementsInTableForEntity("glpi_contacts",getEntitySons($enterprise->fields["FK_entities"]));
185
                } else {
186
                        $nb=countElementsInTableForEntity("glpi_contacts",$enterprise->fields["FK_entities"]);
187
                }
188
                if ($nb>count($used)) {
189
                        echo "<form method='post' action=\"".$CFG_GLPI["root_doc"]."/front/enterprise.form.php\">";
190
                        echo "<table  class='tab_cadre_fixe'>";
191
                        echo "<tr class='tab_bg_1'><th colspan='2'>".$LANG["financial"][33]."</tr><tr><td class='tab_bg_2' align='center'>";
192
                        echo "<input type='hidden' name='eID' value='$instID'>";
193
                        if ($enterprise->fields["recursive"]) {
194
                                dropdown("glpi_contacts","cID",1,getEntitySons($enterprise->fields["FK_entities"]),$used);
195
                        } else {
196
                                dropdown("glpi_contacts","cID",1,$enterprise->fields["FK_entities"],$used);
197
                        }
198
                        echo "</td><td align='center' class='tab_bg_2'>";
199
                        echo "<input type='submit' name='addcontact' value=\"".$LANG["buttons"][8]."\" class='submit'>";
200
                        echo "</td></tr>";
201
                }
202
                echo "</table></form>";
203
        }
204
        echo "</div>";
205

    
206
}
207

    
208
/**
209
 * Add a contact to an enterprise
210
 *
211
 * @param $eID enterprise ID
212
 * @param $cID contact ID
213
 */
214
function addContactEnterprise($eID,$cID){
215
        global $DB;
216
        if ($eID>0&&$cID>0){
217

    
218
                $query="INSERT INTO glpi_contact_enterprise (FK_enterprise,FK_contact ) VALUES ('$eID','$cID');";
219
                $result = $DB->query($query);
220
        }
221
}
222
/**
223
 * Delete a contact to an enterprise
224
 *
225
 * @param $ID contact_enterprise ID
226
 */
227
function deleteContactEnterprise($ID){
228

    
229
        global $DB;
230
        $query="DELETE FROM glpi_contact_enterprise WHERE ID= '$ID';";
231
        $result = $DB->query($query);
232
}
233

    
234
/**
235
 * Get links for an enterprise (website / edit)
236
 *
237
 * @param $value integer : enterprise ID
238
 * @param $withname boolean : also display name ?
239
 */
240
function getEnterpriseLinks($value,$withname=false){
241
        global $CFG_GLPI,$LANG;
242
        $ret="";
243

    
244
        $ent=new Enterprise();
245
        if ($ent->getFromDB($value)){
246

    
247
                if ($withname){
248
                        $ret.=$ent->fields["name"];
249
                }
250

    
251
                if (!empty($ent->fields['website'])){
252
                        $ret.= "&nbsp;&nbsp;";
253
                        $ret.= "<a href='".formatOutputWebLink($ent->fields['website'])."' target='_blank'><img src='".$CFG_GLPI["root_doc"]."/pics/web.png' class='middle' alt='".$LANG["common"][4]."' title='".$LANG["common"][4]."' ></a>";
254
                }
255
                $ret.= "&nbsp;&nbsp;&nbsp;&nbsp;";
256
                $ret.= "<a href='".$CFG_GLPI["root_doc"]."/front/enterprise.form.php?ID=".$ent->fields['ID']."'><img src='".$CFG_GLPI["root_doc"]."/pics/edit.png' class='middle' alt='".$LANG["buttons"][14]."' title='".$LANG["buttons"][14]."'></a>";
257
        }
258

    
259
        return $ret;
260
}
261
?>
Redmine Appliance - Powered by TurnKey Linux