Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

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

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

1
<?php
2

    
3
/*
4
 * @version $Id: bookmark.class.php 7882 2009-01-23 18:24:05Z moyo $
5
 -------------------------------------------------------------------------
6
 GLPI - Gestionnaire Libre de Parc Informatique
7
 Copyright (C) 2003-2009 by the INDEPNET Development Team.
8

9
 http://indepnet.net/   http://glpi-project.org
10
 -------------------------------------------------------------------------
11

12
 LICENSE
13

14
 This file is part of GLPI.
15

16
 GLPI is free software; you can redistribute it and/or modify
17
 it under the terms of the GNU General Public License as published by
18
 the Free Software Foundation; either version 2 of the License, or
19
 (at your option) any later version.
20

21
 GLPI is distributed in the hope that it will be useful,
22
 but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 GNU General Public License for more details.
25

26
 You should have received a copy of the GNU General Public License
27
 along with GLPI; if not, write to the Free Software
28
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29
 --------------------------------------------------------------------------
30
 */
31

    
32
if (!defined('GLPI_ROOT')) {
33
        die("Sorry. You can't access directly to this file");
34
}
35

    
36
/// Bookmark class
37
class Bookmark extends CommonDBTM {
38

    
39
        /**
40
         * Constructor
41
         **/
42
        function Bookmark() {
43
                global $CFG_GLPI;
44
                $this->table = "glpi_bookmark";
45
                $this->entity_assign=true;
46
                $this->may_be_recursive=true;
47
                $this->may_be_private=true;
48
                // To allow "can" method (canView & canCreate)
49
                $this->type = BOOKMARK_TYPE;
50
        }
51

    
52

    
53
        function prepareInputForAdd($input) {
54
                if (!isset($input['url'])||!isset($input['type'])){
55
                        return false;
56
                }
57

    
58
                $taburl = parse_url(rawurldecode($input['url']));
59

    
60
                $index = strpos($taburl["path"],"plugins");
61
                if (!$index)
62
                        $index = strpos($taburl["path"],"front");
63
                $input['path'] = substr($taburl["path"],$index,strlen($taburl["path"]) - $index);
64

    
65
                $query_tab=array();
66
                
67
                if (isset($taburl["query"])){
68
                        parse_str($taburl["query"],$query_tab);
69
                }
70

    
71
                $input['query']=append_params($this->prepareQueryToStore($input['type'],$query_tab,$input['device_type']));
72

    
73
                return $input;
74
        }
75

    
76
        function pre_updateInDB($input,$updates) {
77
                if ($this->fields['FK_users']==0){
78
                        $input['FK_users']=$_SESSION["glpiID"];
79
                        $this->fields['FK_users']=$_SESSION["glpiID"];
80
                        $updates[]="FK_users";
81
                }
82
                return array($input,$updates);
83
        }
84

    
85
        function post_getEmpty () {
86
                global $LANG;
87
                $this->fields["FK_users"]=$_SESSION['glpiID'];
88
                $this->fields["private"]=1;
89
                $this->fields["recursive"]=0;
90
                $this->fields["FK_entities"]=$_SESSION["glpiactive_entity"];
91
        }
92

    
93
        /**
94
        * Print the bookmark form
95
        *
96
        * @param $target target for the form
97
        * @param $ID ID of the item
98
        * @param $type bookmark type when adding a new bookmark
99
        * @param $url url when adding a new bookmark
100
        * @param $device_type device_type when adding a new bookmark
101
        **/
102
        function showForm($target,$ID,$type=0,$url='',$device_type=0) {
103

    
104

    
105
                global $CFG_GLPI,$LANG;
106

    
107
                $canedit=false;
108
                
109
                if ($ID>0) {
110
                        if($this->can($ID,'w')) {
111
                                $canedit = true;        
112
                        }
113
                } else {
114
                        if ($this->can(-1,'w')){
115
                                $canedit = true;
116
                        }
117
                } 
118
                echo '<br>';
119
                if ( $canedit){
120
                        echo "<form method='post' name='form_save_query' action=\"$target\">";
121
                        echo "<div class='center'>";
122
                        if ($device_type!=0){
123
                                echo "<input type='hidden' name='device_type' value='$device_type'>";
124
                        }
125
                        if ($type!=0){
126
                                echo "<input type='hidden' name='type' value='$type'>";
127
                        }
128

    
129
                        if (!empty($url)) {
130
                                echo "<input type='hidden' name='url' value='" . rawurlencode($url) . "'>";
131
                        }
132

    
133
                        echo "<table class='tab_cadre' width='500'>";
134
                        echo "<tr><th>&nbsp;</th><th>";
135
                        if ($ID>0) {
136
                                echo $LANG["common"][2]." $ID";
137
                        } else {
138
                                echo $LANG["bookmark"][4];
139
                        }                
140

    
141
                        echo "</th></tr>";
142

    
143

    
144
                        echo "<tr><td class='tab_bg_1'>".$LANG["common"][16]."</td>"; 
145

    
146
                        echo "<td class='tab_bg_1'>";
147
                        autocompletionTextField("name",$this->table,"name",$this->fields['name'],40);                                
148
                        echo "</td></tr>"; 
149

    
150
                        echo "<tr class='tab_bg_2'><td>".$LANG["common"][17].":                </td>";
151
                        echo "<td>";
152

    
153
                        if(haveRight("bookmark_public","w")) { 
154
                                privatePublicSwitch($this->fields["private"],$this->fields["FK_entities"],$this->fields["recursive"]);
155
                        }else{
156
                                if ($this->fields["private"]){
157
                                        echo $LANG["common"][77];
158
                                } else {
159
                                        echo $LANG["common"][76];
160
                                }
161
                        }
162

    
163
                        echo "</td></tr>";
164

    
165
                        if ($ID<=0) { // add
166
                                echo "<tr>";
167
                                echo "<td class='tab_bg_2' valign='top' colspan='2'>";
168
                                echo "<input type='hidden' name='FK_users' value=\"".$this->fields['FK_users']."\">\n";
169
                                echo "<div class='center'><input type='submit' name='add' value=\"".$LANG["buttons"][8]."\" class='submit'></div>";
170
                                echo "</td>";
171
                                echo "</tr>";
172
                        } else { 
173
                                echo "<tr>";
174

    
175
                                echo "<td class='tab_bg_2' valign='top' colspan='2'>";
176
                                echo "<input type='hidden' name='ID' value=\"$ID\">\n";
177
                                echo "<div class='center'><input type='submit' name='update' value=\"".$LANG["buttons"][7]."\" class='submit'>";
178

    
179
                                echo "<input type='hidden' name='ID' value=\"$ID\">\n";
180

    
181
                                echo "<input type='submit' name='delete' value=\"".$LANG["buttons"][6]."\" class='submit'></div>";
182

    
183
                                echo "</td>";
184
                                echo "</tr>";
185
                        }
186

    
187
                        echo "</table>";
188
                        echo "</div>";
189
                        echo "</form>";
190
                } else {
191
                        echo "<div class='center'><strong>".$LANG["common"][54]."</strong></div>";
192

    
193
                }
194
                
195
        }
196

    
197
        /**
198
        * Prepare query to store depending of the type
199
        *
200
        * @param $type bookmark type
201
        * @param $query_tab parameters array
202
        * @param $device_type device type
203
        * @return clean query array
204
        **/
205
        function prepareQueryToStore($type,$query_tab,$device_type=0){
206
                switch ($type){
207
                        case BOOKMARK_SEARCH :
208
                                if (isset($query_tab['start'])){
209
                                        unset($query_tab['start']);
210
                                }
211
                                // Manage glpisearchcount / dclean if needed + store
212
                                if (isset($query_tab['glpisearchcount'])){
213
                                        unset($query_tab['glpisearchcount']);
214
                                }
215
                                if (isset($_SESSION["glpisearchcount"][$device_type])){
216
                                        $query_tab['glpisearchcount']=$_SESSION["glpisearchcount"][$device_type];
217
                                } else {
218
                                        $query_tab['glpisearchcount']=1;
219
                                }
220

    
221
                                // Manage glpisearchcount2 / dclean if needed + store
222
                                if (isset($query_tab['glpisearchcount2'])){
223
                                        unset($query_tab['glpisearchcount2']);
224
                                }
225
                                if (isset($_SESSION["glpisearchcount2"][$device_type])){
226
                                        $query_tab['glpisearchcount2']=$_SESSION["glpisearchcount2"][$device_type];
227
                                }else {
228
                                        $query_tab['glpisearchcount2']=0;
229
                                }
230
                        break;
231
                }
232
                
233
                return $query_tab;
234
        }
235
        /**
236
        * Prepare query to use depending of the type
237
        *
238
        * @param $type bookmark type
239
        * @param $query_tab parameters array
240
        * @return prepared query array
241
        **/
242
        function prepareQueryToUse($type,$query_tab){
243
                switch ($type){
244
                        case BOOKMARK_SEARCH :
245
                                $query_tab['reset_before']=1;
246
                        break;
247
                }
248
                
249
                return $query_tab;
250
        }
251

    
252
        /**
253
        * load a bookmark
254
        *
255
        * @param $ID ID of the bookmark
256
        * @return nothing
257
        **/
258
        function load($ID){
259
                
260
                $this->getFromDB($ID);
261
                $url = GLPI_ROOT."/".rawurldecode($this->fields["path"]);
262
                $query_tab=array();
263
                parse_str($this->fields["query"],$query_tab);
264
                $params=$this->prepareQueryToUse($this->fields["type"],$query_tab);
265
                $url.="?".append_params($params);
266
                echo "<script type='text/javascript' >\n";
267
                        echo "window.opener.location.href='$url';";
268
                        //echo "window.close();";
269
                echo "</script>";
270
        }
271
        
272
        /**
273
        * Show bookmarks list
274
        *
275
        * @param $target target to use for links
276
        * @param $private show private of public bookmarks ?
277
        * @return nothing
278
        **/
279
        function showBookmarkList($target,$private=1) {
280
                global $DB,$LANG,$CFG_GLPI;
281

    
282
                if (!$private && !haveRight('bookmark_public','r')){ 
283
                        return false;
284
                }
285
        
286
                $query="SELECT * FROM `".$this->table."` WHERE ";
287
                        
288
                if ($private){
289
                        $query.="(private=1 AND FK_users='".$_SESSION['glpiID']."') ";
290
                } else {
291
                        $query.="(private=0  ".getEntitiesRestrictRequest("AND",$this->table,"","",true) . ")";
292
                }
293
                        
294
                $query.=" ORDER BY device_type,name";
295

    
296
                if ($result = $DB->query($query)){
297
                        echo "<br>";
298
        
299
        
300
                        echo "<form method='post' id='form_load_bookmark' action=\"$target\">";
301
                        echo "<div class='center'>";
302
        
303
                        echo "<div id='barre_onglets_percent'><ul id='onglet'>";
304
                        echo "<li ".($private?"class='actif'":"")."><a href='$target?onglet=1&amp;popup=load_bookmark'>".$LANG["common"][77]."</a></li>";
305
                        if (haveRight('bookmark_public','r')){
306
                                echo "<li ".(!$private?"class='actif'":"")."><a href='$target?onglet=0&amp;popup=load_bookmark'>".$LANG["common"][76]."</a></li>";
307
                        }
308
                        echo "</ul></div>";
309
        
310
        
311
                        echo "<table class='tab_cadrehov'>";
312
                        echo "<tr><th align='center' colspan='3'>".$LANG["buttons"][52]." ".$LANG["bookmark"][1]."</th><th width='20px'>&nbsp;</th>";
313
        
314
                        
315
                        if( $DB->numrows($result)){
316
                                $ci=new CommonItem();
317
                                $current_type=-1;
318
                                $current_type_name="&nbsp;";
319
                                while ($this->fields = $DB->fetch_assoc($result)){
320
                                        if ($current_type!=$this->fields['device_type']){
321
                                                $current_type=$this->fields['device_type'];
322
                                                $ci->setType($current_type);
323
                                                $current_type_name=$ci->getType();
324
                                        }
325
                                        $canedit=$this->can($this->fields["ID"],"w");
326

    
327
                                        echo "<tr class='tab_bg_1'>";
328
                                        echo "<td width='10px'>";
329
                                        if ($canedit) {
330
                                                $sel="";
331
                                                if (isset($_GET["select"])&&$_GET["select"]=="all") $sel="checked";
332
                                                echo "<input type='checkbox' name='bookmark[" . $this->fields["ID"] . "]' " . $sel . ">";
333
                                        } else {
334
                                                echo "&nbsp;";
335
                                        }
336
                                        echo "</td>";
337
                                        echo "<td>$current_type_name</td>";
338
                                        echo "<td>";
339
                                        echo "<a href=\"".GLPI_ROOT."/front/popup.php?popup=load_bookmark&amp;bookmark_id=".$this->fields["ID"]."\">".$this->fields["name"]."</a>";
340
                                        echo "</td>";
341
                                        if ($canedit) {
342
                                                echo "<td><a href=\"".GLPI_ROOT."/front/popup.php?popup=edit_bookmark&amp;ID=".$this->fields["ID"]."\"><img src='".$CFG_GLPI["root_doc"]."/pics/edit.png' alt='".$LANG["buttons"][14]."'></a></td>";
343
                                        } else {
344
                                                echo "<td>&nbsp;</td>";                                        
345
                                        }
346
                                        echo "</tr>";
347
                                }
348
                                echo "</table>";
349
                                echo "</div>";
350
                                
351
                                echo "<div class='center'>";
352
                                echo "<table width='80%'>";
353
                                echo "<tr><td><img src=\"".$CFG_GLPI["root_doc"]."/pics/arrow-left.png\" alt=''></td><td class='center'><a onclick= \"if ( markAllRows('form_load_bookmark') ) return false;\" href='".$_SERVER['PHP_SELF']."?select=all'>".$LANG["buttons"][18]."</a></td>";
354
                                echo "<td>/</td><td class='center'><a onclick= \"if ( unMarkAllRows('form_load_bookmark') ) return false;\" href='".$_SERVER['PHP_SELF']."?select=none'>".$LANG["buttons"][19]."</a>";
355
                                echo "</td><td align='left' width='80%'>";
356
                                echo "<input type='submit' name='delete_several' value=\"".$LANG["buttons"][6]."\" class='submit'>";
357
                                echo "</td></tr>";
358
                                echo "</table>";
359
                
360
                        }
361
                        else {
362
                                echo "<tr class='tab_bg_1'><td colspan='4'>".$LANG["bookmark"][3]."</td></tr></table>";
363
                        }
364
                        echo '</div>';
365
                        echo "</form>";
366
                }
367
        }
368
}
369
?>
Redmine Appliance - Powered by TurnKey Linux