Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

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

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

1
<?php
2
/*
3
 * @version $Id: reminder.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: Jean-mathieu Doléans
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
/// Reminder class
42
class Reminder extends CommonDBTM {
43

    
44
        /**
45
         * Constructor
46
        **/
47
        function Reminder () {
48
                $this->table="glpi_reminder";
49
                $this->type=REMINDER_TYPE;
50
                $this->entity_assign=true;
51
                $this->may_be_recursive=true;
52
                $this->may_be_private=true;
53
        }
54

    
55
        function prepareInputForAdd($input) {
56
                global $LANG;
57

    
58
                if(empty($input["name"])) $input["name"]=$LANG["reminder"][15];
59

    
60
                $input["begin"] = $input["end"] = "0000-00-00 00:00:00";
61

    
62
                if (isset($input['plan'])){
63
                        $input['_plan']=$input['plan'];
64
                        unset($input['plan']);
65
                        $input['rv']="1";
66
                        $input["begin"] = $input['_plan']["begin_date"]." ".$input['_plan']["begin_hour"].":00";
67
                        $input["end"] = $input['_plan']["end_date"]." ".$input['_plan']["end_hour"].":00";
68
                }        
69

    
70
                if ($input['recursive']&&!$input['private']){
71
                        if (!haveRecursiveAccessToEntity($input["FK_entities"])){
72
                                unset($input['recursive']);
73
                                addMessageAfterRedirect($LANG["common"][75]);
74
                        }
75
                }
76

    
77
                // set new date.
78
                $input["date"] = $_SESSION["glpi_currenttime"];
79

    
80
                return $input;
81
        }
82

    
83
        function prepareInputForUpdate($input) {
84
                global $LANG;
85

    
86
                if(empty($input["name"])) $input["name"]=$LANG["reminder"][15];
87

    
88

    
89
                if (isset($input['plan'])){
90
                        $input['_plan']=$input['plan'];
91
                        unset($input['plan']);
92
                        $input['rv']="1";
93
                        $input["begin"] = $input['_plan']["begin_date"]." ".$input['_plan']["begin_hour"].":00";
94
                        $input["end"] = $input['_plan']["end_date"]." ".$input['_plan']["end_hour"].":00";
95
                        $input["state"] = $input['_plan']["state"];
96
                }        
97
                if ($input['recursive']&&!$input['private']){
98
                        if (!haveRecursiveAccessToEntity($input["FK_entities"])){
99
                                unset($input['recursive']);
100
                                addMessageAfterRedirect($LANG["common"][75]);
101
                        }
102
                }
103

    
104
                return $input;
105
        }
106

    
107

    
108
        function pre_updateInDB($input,$updates) {
109
                if ($this->fields['FK_users']==0){
110
                        $input['FK_users']=$_SESSION["glpiID"];
111
                        $this->fields['FK_users']=$_SESSION["glpiID"];
112
                        $updates[]="FK_users";
113
                }
114
                return array($input,$updates);
115
        }
116

    
117
        function post_getEmpty () {
118
                global $LANG;
119
                $this->fields["name"]=$LANG["reminder"][6];
120
                $this->fields["FK_users"]=$_SESSION['glpiID'];
121
                $this->fields["private"]=1;
122
                $this->fields["FK_entities"]=$_SESSION["glpiactive_entity"];
123
        }
124

    
125
        /**
126
         * Print the reminder form
127
         *
128
         *@param $target filename : where to go when done.
129
         *@param $ID Integer : Id of the item to print
130
         *
131
         **/
132
        function showForm ($target,$ID) {
133
                // Show Reminder or blank form
134

    
135
                global $CFG_GLPI,$LANG;
136

    
137
                $onfocus="";
138

    
139
                $spotted=false;
140
                if ($ID>0) {
141
                        if($this->can($ID,'r')) {
142
                                $spotted = true;        
143
                        }
144
                } else {
145
                        if ($this->can(-1,'w')){
146
                                $spotted = true;
147
                                $onfocus="onfocus=\"this.value=''\"";
148
                        }
149
                } 
150

    
151
                if ($spotted){
152
                        $canedit=$this->can($ID,'w');
153

    
154

    
155
                        if($canedit) {
156
                                echo "<form method='post' name='remind' action=\"$target\">";
157
                        }
158
        
159
                        echo "<div class='center'><table class='tab_cadre' width='450'>";
160
                        echo "<tr><th>&nbsp;</th><th>";
161
                        if (!$ID) {
162
                                echo $LANG["reminder"][6];
163
                        } else {
164
                                echo $LANG["common"][2]." $ID";
165
                        }                
166

    
167
                        echo "</th></tr>";
168

    
169
                        echo "<tr class='tab_bg_2'><td>".$LANG["common"][57].":                </td>";
170
                        echo "<td>";
171
                        autocompletionTextField("name",$this->table,"name",$this->fields['name'],80,-1,$onfocus);        
172
                        echo "</td></tr>";
173

    
174
                        if(!$canedit) { 
175
                                echo "<tr class='tab_bg_2'><td>".$LANG["planning"][9].":                </td>";
176
                                echo "<td>";
177
                                echo getUserName($this->fields["FK_users"]);
178
                                echo "</td></tr>";
179
                        }
180

    
181
                        echo "<tr class='tab_bg_2'><td>".$LANG["common"][17].":                </td>";
182
                        echo "<td>";
183

    
184
                        if($canedit&&haveRight("reminder_public","w")) { 
185

    
186
                                if (!$ID){
187
                                        if (isset($_GET["private"])){
188
                                                $this->fields["private"]=$_GET["private"];
189
                                        }
190
                                        if (isset($_GET["recursive"])){
191
                                                $this->fields["recursive"]=$_GET["recursive"];
192
                                        }
193
                                }
194
        
195
                                privatePublicSwitch($this->fields["private"],$this->fields["FK_entities"],$this->fields["recursive"]);
196
                        }else{
197
                                if ($this->fields["private"]){
198
                                        echo $LANG["common"][77];
199
                                } else {
200
                                        echo $LANG["common"][76];
201
                                }
202
                        }
203

    
204
                        echo "</td></tr>";
205

    
206

    
207
                        echo "<tr class='tab_bg_2'><td >".$LANG["buttons"][15].":                </td>";
208

    
209

    
210

    
211

    
212

    
213
                        echo "<td class='center'>";
214

    
215
                        if($canedit) { 
216
                                echo "<script type='text/javascript' >\n";
217
                                echo "function showPlan(){\n";
218
                                        echo "window.document.getElementById('plan').style.display='none';";
219
                                        $params=array('form'=>'remind');
220
                                        if ($ID&&$this->fields["rv"]){
221
                                                $params['state']=$this->fields["state"];
222
                                                $params['begin_date']=$this->fields["begin"];
223
                                                $params['end_date']=$this->fields["end"];
224
                                        }
225
                                        ajaxUpdateItemJsCode('viewplan',$CFG_GLPI["root_doc"]."/ajax/planning.php",$params,false);
226
                                echo "}";
227
                                
228
                                echo "</script>\n";
229
                        }
230
                        
231
                        if(!$ID||$this->fields["rv"]==0){
232
                                if($canedit) { 
233
                                        echo "<div id='plan'  onClick='showPlan()'>\n";
234
                                        echo "<span class='showplan'>".$LANG["reminder"][12]."</span>";
235
                                }
236
                        }else{
237
                                if($canedit) {
238
                                        echo "<div id='plan'  onClick='showPlan()'>\n";
239
                                        echo "<span class='showplan'>";
240
                                }
241
                                echo getPlanningState($this->fields["state"]).": ".convDateTime($this->fields["begin"])."->".convDateTime($this->fields["end"]);
242
                                if($canedit){
243
                                        echo "</span>";
244
                                }
245
                        }        
246
                        
247
                        if($canedit) { 
248
                                echo "</div>\n";
249
                                echo "<div id='viewplan'>\n";
250
                                echo "</div>\n";        
251
                        }
252
                        echo "</td>";
253

    
254

    
255
                        echo "</tr>";
256

    
257
                        echo "<tr class='tab_bg_2'><td>".$LANG["reminder"][9].":                </td><td>";
258
                        if($canedit) { 
259
                                echo "<textarea cols='80' rows='15' name='text'>".$this->fields["text"]."</textarea>";
260
                        }else{
261
                                echo nl2br($this->fields["text"]);
262
                        }
263
                        echo "</td></tr>";
264

    
265
                        if (!$ID) { // add
266
                                echo "<tr>";
267
                                echo "<td class='tab_bg_2' valign='top' colspan='2'>";
268
                                echo "<input type='hidden' name='FK_users' value=\"".$this->fields['FK_users']."\">\n";
269
                                echo "<div class='center'><input type='submit' name='add' value=\"".$LANG["buttons"][8]."\" class='submit'></div>";
270
                                echo "</td>";
271
                                echo "</tr>";
272
                        } elseif($canedit) { 
273
                                echo "<tr>";
274

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

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

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

    
283
                                echo "</td>";
284
                                echo "</tr>";
285
                        }
286

    
287
                        echo "</table></div>";
288
                        if($canedit){
289
                                echo "</form>";
290
                        }
291
                } else {
292
                        echo "<div class='center'><strong>".$LANG["common"][54]."</strong></div>";
293

    
294
                }
295

    
296
                return true;
297

    
298
        }
299

    
300

    
301
}
302

    
303
?>
Redmine Appliance - Powered by TurnKey Linux