Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

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

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

1
<?php
2
/*
3
 * @version $Id: document.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

    
42
class Document extends CommonDBTM {
43

    
44
        /**
45
         * Constructor
46
        **/
47
        function Document () {
48
                $this->table="glpi_docs";
49
                $this->type=DOCUMENT_TYPE;
50
                $this->entity_assign=true;
51
                $this->may_be_recursive=true;
52
        }
53
        /**
54
         * Retrieve an item from the database using the filename
55
         *
56
         *@param $filename filename of the document
57
         *@return true if succeed else false
58
        **/        
59
        function getFromDBbyFilename($filename){
60
                global $DB;
61
                $query="SELECT ID FROM glpi_docs WHERE filename='$filename'";
62
                $result=$DB->query($query);
63
                if ($DB->numrows($result)==1){
64
                        return $this->getFromDB($DB->result($result,0,0));
65
                } 
66
                return false;
67
        }        
68

    
69
        function cleanDBonPurge($ID) {
70
                global $DB,$CFG_GLPI,$LANG;
71

    
72
                $query3 = "DELETE FROM glpi_doc_device WHERE (FK_doc = '$ID')";
73
                $result3 = $DB->query($query3);
74

    
75
                // UNLINK DU FICHIER
76
                if (!empty($this->fields["filename"]))
77
                        if(is_file(GLPI_DOC_DIR."/".$this->fields["filename"])&& !is_dir(GLPI_DOC_DIR."/".$this->fields["filename"])) {
78
                                if (unlink(GLPI_DOC_DIR."/".$this->fields["filename"])){
79
                                        addMessageAfterRedirect($LANG["document"][24].GLPI_DOC_DIR."/".$this->fields["filename"]);
80
                                 } else {
81
                                        addMessageAfterRedirect($LANG["document"][25].GLPI_DOC_DIR."/".$this->fields["filename"]);
82
                                }
83
                        }
84
        }
85

    
86
        function defineOnglets($withtemplate){
87
                global $LANG;
88
                $ong[1]=$LANG["title"][26];
89
                $ong[5]=$LANG["Menu"][27];
90
                if (haveRight("notes","r"))
91
                        $ong[10]=$LANG["title"][37];
92
                return $ong;
93
        }
94

    
95
        function prepareInputForAdd($input) {
96
                global $LANG;
97

    
98
                $input["FK_users"] = $_SESSION["glpiID"];
99

    
100
                if (isset($_FILES['filename']['type'])&&!empty($_FILES['filename']['type'])){
101
                        $input['mime']=$_FILES['filename']['type'];
102
                }
103

    
104
                if (isset($input["item"])&&isset($input["type"])&&$input["type"]>0&&$input["item"]>0){
105
                        $ci=new CommonItem();
106
                        $ci->getFromDB($input["type"],$input["item"]);
107
                        $input["name"]=addslashes(resume_text($LANG["document"][18]." ".$ci->getType()." - ".$ci->getNameID(),200));
108
                }
109
                
110
                if (isset($input["upload_file"])&&!empty($input["upload_file"])){
111
                        $input['filename']=moveUploadedDocument($input["upload_file"]);
112
                } else if (isset($_FILES)&&isset($_FILES['filename']))        {
113
                        $input['filename']= uploadDocument($_FILES['filename']);
114
                } 
115

    
116
                if (!isset($input['name'])&&isset($input['filename'])){
117
                        $input['name']=$input['filename'];
118
                }
119

    
120
                unset($input["upload_file"]);
121
                if (!isset($input["_only_if_upload_succeed"])||!$input["_only_if_upload_succeed"]||!empty($input['filename'])) {
122
                        return $input;
123
                }
124
                else {
125
                        return false;
126
                }
127
        }
128

    
129
        function post_addItem($newID,$input) {
130
                global $LANG;
131
                if (isset($input["item"])&&isset($input["type"])&&$input["item"]>0&&$input["type"]>0){
132

    
133
                        addDeviceDocument($newID,$input['type'],$input['item']);
134
                        logEvent($newID, "documents", 4, "document", $_SESSION["glpiname"]." ".$LANG["log"][32]);
135
                }
136

    
137

    
138
        }
139

    
140
        function prepareInputForUpdate($input) {
141
                if (isset($_FILES['filename']['type'])&&!empty($_FILES['filename']['type']))
142
                        $input['mime']=$_FILES['filename']['type'];
143

    
144
                if (isset($input['current_filename']))
145
                if (isset($input["upload_file"])&&!empty($input["upload_file"])){
146
                        $input['filename']=moveUploadedDocument($input["upload_file"],$input['current_filename']);
147
                } else         $input['filename']= uploadDocument($_FILES['filename'],$input['current_filename']);
148

    
149
                if (empty($input['filename'])) unset($input['filename']);
150
                unset($input['current_filename']);        
151

    
152
                return $input;
153
        }
154

    
155

    
156
        /**
157
         * Print the document form
158
         *
159
         *@param $target form target
160
         *@param $ID Integer : Id of the computer or the template to print
161
         *@param $withtemplate='' boolean : template or basic computer
162
         *
163
         *@return Nothing (display)
164
         **/
165
        function showForm ($target,$ID,$withtemplate='') {
166
                global $CFG_GLPI,$LANG;
167

    
168
                if (!haveRight("document","r"))        return false;
169

    
170

    
171
                $spotted=false;
172
                $use_cache=true;
173
                if ($ID>0) {
174
                        if($this->can($ID,'r')) {
175
                                $spotted = true;        
176
                        }
177
                } else {
178
                        $use_cache=false;
179
                        if ($this->can(-1,'w')){
180
                                $spotted = true;        
181
                        }
182
                } 
183

    
184
                if ($spotted){
185
                        $canedit=$this->can($ID,'w');
186

    
187
                        $canrecu=$this->can($ID,'recursive');
188

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

    
191
                        if ($canedit) {
192
                                echo "<form name='form' method='post' action=\"$target\" enctype=\"multipart/form-data\">";
193
                                if (empty($ID)||$ID<0){
194
                                        echo "<input type='hidden' name='FK_entities' value='".$_SESSION["glpiactive_entity"]."'>";
195
                                }
196
                        }
197

    
198
                        echo "<div class='center'><table class='tab_cadre_fixe'>";
199
                        echo "<tr>";
200
                        if ($ID>0) {
201
                                echo "<th>";
202
                                echo $LANG["common"][2]." $ID";
203
                                if (isMultiEntitiesMode()){
204
                                        echo "&nbsp;(".getDropdownName("glpi_entities",$this->fields["FK_entities"]).")";
205
                                }
206
                                echo "</th>";
207
                                echo "<th>";
208
                                if ($this->fields["FK_users"]>0){
209
                                        echo $LANG["document"][42]." ".getUserName($this->fields["FK_users"],1);
210
                                } else {
211
                                        echo "&nbsp;";
212
                                }
213
                                echo "</th>";
214
                                echo "<th>".$LANG["common"][26].": ".convDateTime($this->fields["date_mod"])."</th>";
215
                                echo "<th>";
216
                                if (isMultiEntitiesMode()){
217
                                        echo $LANG["entity"][9].":&nbsp;";
218
                                
219
                                        if ($this->can($ID,'recursive')) {
220
                                                dropdownYesNo("recursive",$this->fields["recursive"]);                                        
221
                                        } else {
222
                                                echo getYesNo($this->fields["recursive"]);
223
                                        }
224
                                } else {
225
                                        echo "&nbsp;";
226
                                }
227
                                echo "</th>";
228
                        } else {
229
                                echo "<th colspan='2'>";
230
                                echo $LANG["document"][16];
231
                                if (isMultiEntitiesMode()){
232
                                        echo "&nbsp;(".getDropdownName("glpi_entities",$this->fields["FK_entities"]).")";
233
                                }
234
                                echo "</th>";
235
                                echo "<th colspan='2'>";
236
                                if (isMultiEntitiesMode()){
237
                                        echo $LANG["entity"][9].":&nbsp;";
238
                                
239
                                        if ($this->can($ID,'recursive')) {
240
                                                dropdownYesNo("recursive",$this->fields["recursive"]);                                        
241
                                        } else {
242
                                                echo getYesNo($this->fields["recursive"]);
243
                                        }
244
                                } else {
245
                                        echo "&nbsp;";
246
                                }
247
                                echo "</th>";
248
                        } 
249
                        echo "</tr>";
250
                        if (!$use_cache||!($CFG_GLPI["cache"]->start($ID."_".$_SESSION["glpilanguage"],"GLPI_".$this->type))) {
251
                                echo "<tr class='tab_bg_1'><td colspan='2'>".$LANG["common"][16].":                </td>";
252
                                echo "<td colspan='2'>";
253
                                autocompletionTextField("name","glpi_docs","name",$this->fields["name"],80,$this->fields["FK_entities"]);
254
                                echo "</td></tr>";
255
        
256
                                if (!empty($ID)){
257
                                        echo "<tr class='tab_bg_1'><td colspan='2'>".$LANG["document"][22].":                </td>";
258
                                        echo "<td colspan='2'>".getDocumentLink($this->fields["filename"])."";
259
                                        echo "<input type='hidden' name='current_filename' value='".$this->fields["filename"]."'>";
260
                                        echo "</td></tr>";
261
                                }
262
                                $max_size=return_bytes_from_ini_vars(ini_get("upload_max_filesize"));
263
                                $max_size/=1024*1024;
264
                                $max_size=round($max_size,1);
265
        
266
                                echo "<tr class='tab_bg_1'><td colspan='2'>".$LANG["document"][2]." (".$max_size." Mb max):        </td>";
267
                                echo "<td colspan='2'><input type='file' name='filename' value=\"".$this->fields["filename"]."\" size='25'></td>";
268
                                echo "</tr>";
269
        
270
                                echo "<tr class='tab_bg_1'><td colspan='2'>".$LANG["document"][36].":                </td>";
271
                                echo "<td colspan='2'>";
272
                                showUploadedFilesDropdown("upload_file");
273
                                echo "</td></tr>";
274
        
275
        
276
                                echo "<tr class='tab_bg_1'><td colspan='2'>".$LANG["document"][33].":                </td>";
277
                                echo "<td colspan='2'>";
278
                                autocompletionTextField("link","glpi_docs","link",$this->fields["link"],40,$this->fields["FK_entities"]);
279
                                echo "</td></tr>";
280
        
281
                                echo "<tr class='tab_bg_1'><td colspan='2'>".$LANG["document"][3].":                </td>";
282
                                echo "<td colspan='2'>";
283
                                dropdownValue("glpi_dropdown_rubdocs","rubrique",$this->fields["rubrique"]);
284
                                echo "</td></tr>";
285
        
286
                                echo "<tr class='tab_bg_1'><td colspan='2'>".$LANG["document"][4].":                </td>";
287
                                echo "<td colspan='2'>";
288
                                autocompletionTextField("mime","glpi_docs","mime",$this->fields["mime"],25,$this->fields["FK_entities"]);
289
                                echo "</td></tr>";
290
        
291
                                echo "<tr>";
292
                                echo "<td class='tab_bg_1' valign='top' colspan='2'>";
293
        
294
                                // table commentaires
295
                                echo $LANG["common"][25].":        </td>";
296
                                echo "<td colspan='2'  class='tab_bg_1'><textarea cols='70' rows='4' name='comments' >".$this->fields["comments"]."</textarea>";
297
        
298
                                echo "</td>";
299
                                echo "</tr>";
300
                                if ($use_cache){
301
                                        $CFG_GLPI["cache"]->end();
302
                                }
303
                        }
304

    
305
                        if ($canedit){
306
                                echo "<tr>";
307

    
308
                                if ($ID>0) {
309

    
310
                                        echo "<td class='tab_bg_2' valign='top' colspan='2'>";
311
                                        echo "<input type='hidden' name='ID' value=\"$ID\">\n";
312
                                        echo "<div class='center'><input type='submit' name='update' value=\"".$LANG["buttons"][7]."\" class='submit'></div>";
313
                                        echo "</td>\n\n";
314
                
315
                                        echo "<td class='tab_bg_2' valign='top'  colspan='2'>\n";
316
                                        echo "<input type='hidden' name='ID' value=\"$ID\">\n";
317
                                        if (!$this->fields["deleted"])
318
                                                echo "<div class='center'><input type='submit' name='delete' value=\"".$LANG["buttons"][6]."\" class='submit'></div>";
319
                                        else {
320
                                                echo "<div class='center'><input type='submit' name='restore' value=\"".$LANG["buttons"][21]."\" class='submit'>";
321
                
322
                                                echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' name='purge' value=\"".$LANG["buttons"][22]."\" class='submit'></div>";
323
                                        }
324
                
325
                                        echo "</td></tr>";
326
                                } else {
327

    
328
                                        echo "<td class='tab_bg_2' valign='top' colspan='4'>";
329
                                        echo "<div class='center'><input type='submit' name='add' value=\"".$LANG["buttons"][8]."\" class='submit'></div>";
330
                                        echo "</td></tr>";
331
                
332
                                }
333
                                echo "</table></div></form>";
334
                                
335
                        } else { //  can't edit
336
                                echo "</table></div>";                        
337
                        } 
338
                } else {
339
                        echo "<div class='center'><strong>".$LANG["common"][54]."</strong></div>";
340
                        return false;
341

    
342
                }
343

    
344
                return true;
345

    
346
        }
347

    
348
}
349

    
350
?>
Redmine Appliance - Powered by TurnKey Linux