Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

ryxeo-glpi-git / inc / contact.class.php @ b67d8923

Historique | Voir | Annoter | Télécharger (8,51 ko)

1
<?php
2
/*
3
 * @version $Id: contact.class.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
/// Contact class
42
class Contact extends CommonDBTM{
43

    
44
        /**
45
         * Constructor
46
         **/
47
        function Contact () {
48
                $this->table="glpi_contacts";
49
                $this->type=CONTACT_TYPE;
50
                $this->entity_assign=true;
51
                $this->may_be_recursive=true;
52
        }
53

    
54
        function cleanDBonPurge($ID) {
55
                global $DB;
56

    
57
                $query = "DELETE from glpi_contact_enterprise WHERE FK_contact = '$ID'";
58
                $DB->query($query);
59
        }
60

    
61
        function defineOnglets($withtemplate){
62
                global $LANG;
63
                $ong[1]=$LANG["title"][26];
64
                if (haveRight("document","r"))        
65
                        $ong[5]=$LANG["Menu"][27];
66
                if (haveRight("link","r"))        
67
                        $ong[7]=$LANG["title"][34];
68
                if (haveRight("notes","r"))
69
                        $ong[10]=$LANG["title"][37];
70
                return $ong;
71
        }
72

    
73

    
74
        /**
75
         * Get address of the contact (company one)
76
         *
77
         *@return string containing the address
78
         *
79
         **/
80
        function GetAddress() {
81
                global $DB;
82

    
83
                $query = "SELECT  glpi_enterprises.name, glpi_enterprises.address, glpi_enterprises.postcode, glpi_enterprises.town, glpi_enterprises.state, glpi_enterprises.country FROM glpi_enterprises,glpi_contact_enterprise WHERE glpi_contact_enterprise.FK_contact = '".$this->fields["ID"]."' AND glpi_contact_enterprise.FK_enterprise = glpi_enterprises.ID";
84

    
85
                if ($result = $DB->query($query)) 
86
                        if ($DB->numrows($result)){
87
                                if ($data=$DB->fetch_assoc($result))        
88
                                        return $data;
89
                        } 
90

    
91
                return "";
92

    
93
        }
94

    
95
        /**
96
         * Get website of the contact (company one)
97
         *
98
         *@return string containing the website
99
         *
100
         **/
101
        function GetWebsite() {
102
                global $DB;
103

    
104
                $query = "SELECT  glpi_enterprises.website as website FROM glpi_enterprises,glpi_contact_enterprise WHERE glpi_contact_enterprise.FK_contact = '".$this->fields["ID"]."' AND glpi_contact_enterprise.FK_enterprise = glpi_enterprises.ID";
105

    
106
                if ($result = $DB->query($query)) 
107
                        if ($DB->numrows($result)){
108
                                return $DB->result($result, 0, "website");
109
                        } else {
110
                                return "";
111
                        }
112
        }
113

    
114
        /**
115
         * Print the contact form
116
         *
117
         *@param $target filename : where to go when done.
118
         *@param $ID Integer : Id of the contact to print
119
         *@param $withtemplate='' boolean : template or basic item
120
         *
121
         *
122
         *@return Nothing (display)
123
         *
124
         **/
125
        function showForm ($target,$ID,$withtemplate='') {
126

    
127
                global $CFG_GLPI, $LANG;
128

    
129
                if (!haveRight("contact_enterprise","r")) return false;
130

    
131
                $spotted = false;
132
                $use_cache=true;
133

    
134

    
135
                if ($ID>0) {
136
                        if($this->can($ID,'r')) {
137
                                $spotted = true;        
138
                        }
139
                } else {
140
                        $use_cache=false;
141
                        if ($this->can(-1,'w')){
142
                                $spotted = true;        
143
                        }
144
                } 
145

    
146

    
147
                if ($spotted){
148
                        $canedit=$this->can($ID,'w');
149

    
150
                        $this->showOnglets($ID, $withtemplate,$_SESSION['glpi_onglet']);
151

    
152
                        if ($canedit) {
153
                                echo "<form method='post' name=form action=\"$target\"><div class='center'>";
154
                                if (empty($ID)||$ID<0){
155
                                        echo "<input type='hidden' name='FK_entities' value='".$_SESSION["glpiactive_entity"]."'>";
156
                                }
157
                        }
158

    
159
                        echo "<table class='tab_cadre_fixe' cellpadding='2' >";
160
                        echo "<tr><th>";
161
                        if (empty($ID)||$ID<0){
162
                                echo $LANG["financial"][33];
163
                        } else {
164
                                echo $LANG["common"][2]." $ID";
165
                        }
166
                        if (isMultiEntitiesMode()){
167
                                echo "&nbsp;(".getDropdownName("glpi_entities",$this->fields["FK_entities"]).")";
168
                        }
169
                        if ($ID) {                                
170
                                echo "&nbsp;<a href='".$CFG_GLPI["root_doc"]."/front/contact.vcard.php?ID=$ID'>".$LANG["common"][46]."</a>";
171
                        }                
172

    
173
                        echo "</th>";
174
                        echo "<th>";
175
                        if (isMultiEntitiesMode()){
176
                                echo $LANG["entity"][9].":&nbsp;";
177
                        
178
                                if ($this->can($ID,'recursive')) {
179
                                        dropdownYesNo("recursive",$this->fields["recursive"]);                                        
180
                                } else {
181
                                        echo getYesNo($this->fields["recursive"]);
182
                                }
183
                        } else {
184
                                echo "&nbsp;";
185
                        }
186
                        echo "</th>";
187
                        echo "</tr>";
188

    
189
                        
190
                        if (!$use_cache||!($CFG_GLPI["cache"]->start($ID."_".$_SESSION["glpilanguage"],"GLPI_".$this->type))) {
191
                                echo "<tr><td class='tab_bg_1' valign='top'>";
192
        
193
                                echo "<table cellpadding='1' cellspacing='0' border='0'>\n";
194
        
195
                                echo "<tr><td>".$LANG["common"][48].":        </td>";
196
                                echo "<td>";
197
                                autocompletionTextField("name","glpi_contacts","name",$this->fields["name"],30,$this->fields["FK_entities"]);        
198
                                echo "</td></tr>";
199
        
200
                                echo "<tr><td>".$LANG["common"][43].":        </td>";
201
                                echo "<td>";
202
                                autocompletionTextField("firstname","glpi_contacts","firstname",$this->fields["firstname"],30,$this->fields["FK_entities"]);        
203
                                echo "</td></tr>";
204
        
205
                                echo "<tr><td>".$LANG["help"][35].":         </td>";
206
                                echo "<td>";
207
                                autocompletionTextField("phone","glpi_contacts","phone",$this->fields["phone"],30,$this->fields["FK_entities"]);        
208
        
209
                                echo "</td></tr>";
210
        
211
                                echo "<tr><td>".$LANG["help"][35]." 2:        </td><td>";
212
                                autocompletionTextField("phone2","glpi_contacts","phone2",$this->fields["phone2"],30,$this->fields["FK_entities"]);
213
                                echo "</td></tr>";
214
        
215
                                echo "<tr><td>".$LANG["common"][42].":        </td><td>";
216
                                autocompletionTextField("mobile","glpi_contacts","mobile",$this->fields["mobile"],30,$this->fields["FK_entities"]);
217
                                echo "</td></tr>";
218
        
219
        
220
                                echo "<tr><td>".$LANG["financial"][30].":        </td><td>";
221
                                autocompletionTextField("fax","glpi_contacts","fax",$this->fields["fax"],30,$this->fields["FK_entities"]);
222
                                echo "</td></tr>";
223
                                echo "<tr><td>".$LANG["setup"][14].":        </td><td>";
224
                                autocompletionTextField("email","glpi_contacts","email",$this->fields["email"],30,$this->fields["FK_entities"]);
225
                                echo "</td></tr>";
226

    
227
                                echo "<tr><td>".$LANG["common"][17].":        </td>";
228
                                echo "<td>";
229
                                dropdownValue("glpi_dropdown_contact_type","type",$this->fields["type"]);
230
                                echo "</td>";
231
                                echo "</tr>";
232
        
233
                                echo "</table>";
234
        
235
                                echo "</td>\n";        
236
        
237
                                echo "<td class='tab_bg_1' valign='top'>";
238
        
239
                                echo "<table cellpadding='1' cellspacing='0' border='0'><tr><td>";
240
                                echo $LANG["common"][25].":        </td></tr>";
241
                                echo "<tr><td class='center'><textarea cols='45' rows='4' name='comments' >".$this->fields["comments"]."</textarea>";
242
                                echo "</td></tr></table>";
243
        
244
                                echo "</td>";
245
                                echo "</tr>";
246
                                if ($use_cache){
247
                                        $CFG_GLPI["cache"]->end();
248
                                }
249
                        }
250

    
251
                        if ($canedit) {
252
                                if ($ID>0){
253
                                        echo "<tr>";
254
                                        echo "<td class='tab_bg_2' valign='top'>";
255
                                        echo "<input type='hidden' name='ID' value=\"$ID\">\n";
256
                                        echo "<div class='center'><input type='submit' name='update' value=\"".$LANG["buttons"][7]."\" class='submit' ></div>";
257
                                        echo "</td>\n\n";
258
                                        echo "<td class='tab_bg_2' valign='top'>\n";
259
                                        if (!$this->fields["deleted"])
260
                                                echo "<div class='center'><input type='submit' name='delete' value=\"".$LANG["buttons"][6]."\" class='submit'></div>";
261
                                        else {
262
                                                echo "<div class='center'><input type='submit' name='restore' value=\"".$LANG["buttons"][21]."\" class='submit'>";
263

    
264
                                                echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' name='purge' value=\"".$LANG["buttons"][22]."\" class='submit'></div>";
265
                                        }
266
                                        echo "</td>";
267
                                        echo "</tr>";
268

    
269
                                } else {
270

    
271
                                        echo "<tr>";
272
                                        echo "<td class='tab_bg_2' valign='top' colspan='2'>";
273
                                        echo "<div class='center'><input type='submit' name='add' value=\"".$LANG["buttons"][8]."\" class='submit'></div>";
274
                                        echo "</td>";
275
                                        echo "</tr>";
276
                                }
277
                                echo "</table></div></form>";
278
                        } else { // canedit
279
                                echo "</table></div>";
280
                        }
281

    
282
                } else { // con_spotted
283
                        echo "<div class='center'><strong>".$LANG["common"][54]."</strong></div>";
284
                        return false;
285

    
286
                }
287
                return true;
288
        }
289

    
290

    
291
}
292

    
293
?>
Redmine Appliance - Powered by TurnKey Linux