Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

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

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

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

    
43
class PlanningTracking extends CommonDBTM {
44

    
45
        /**
46
         * Constructor
47
        **/
48
        function PlanningTracking () {
49
                $this->table="glpi_tracking_planning";
50
        }
51

    
52
        function update($input,$history=1){
53
                global $LANG,$CFG_GLPI;
54
                // Update a Planning Tracking
55

    
56
                $this->getFromDB($input["ID"]);
57

    
58
                list($begin_year,$begin_month,$begin_day)=split("-",$input["begin_date"]);
59
                list($end_year,$end_month,$end_day)=split("-",$input["end_date"]);
60

    
61
                list($begin_hour,$begin_min)=split(":",$input["begin_hour"]);
62
                list($end_hour,$end_min)=split(":",$input["end_hour"]);
63
                $input["begin"]=date("Y-m-d H:i:00",mktime($begin_hour,$begin_min,0,$begin_month,$begin_day,$begin_year));
64
                $input["end"]=date("Y-m-d H:i:00",mktime($end_hour,$end_min,0,$end_month,$end_day,$end_year));
65

    
66
                // Fill the update-array with changes
67
                $x=0;
68
                foreach ($input as $key => $val) {
69
                        if (array_key_exists($key,$this->fields) && $this->fields[$key] != $input[$key]) {
70
                                $this->fields[$key] = $input[$key];
71
                                $updates[$x] = $key;
72
                                $x++;
73
                        }
74
                }
75

    
76
                if (!$this->test_valid_date()){
77
                        $this->displayError("date");
78
                        return false;
79
                }
80

    
81
                if ($this->is_alreadyplanned()){
82
                        $this->displayError("is_res");
83
                        return false;
84
                }
85

    
86
                // Auto update Status
87
                $job=new Job();
88
                $job->getFromDB($input["id_tracking"]);
89
                if ($job->fields["status"]=="new"||$job->fields["status"]=="assign"){
90
                        $job->fields["status"]="plan";
91
                        $updates[]="status";
92
                        $job->updateInDB($updates);                
93
                }
94

    
95
                // Auto update realtime
96
                $fup=new Followup();
97
                $fup->getFromDB($input["id_followup"]);
98
                $tmp_beg=split(" ",$input["begin"]);
99
                $tmp_end=split(" ",$input["end"]);
100
                $tmp_dbeg=split("-",$tmp_beg[0]);
101
                $tmp_dend=split("-",$tmp_end[0]);
102
                $tmp_hbeg=split(":",$tmp_beg[1]);
103
                $tmp_hend=split(":",$tmp_end[1]);
104

    
105
                $dateDiff = mktime($tmp_hend[0],$tmp_hend[1],$tmp_hend[2],$tmp_dend[1],$tmp_dend[2],$tmp_dend[0]) 
106
                        - mktime($tmp_hbeg[0],$tmp_hbeg[1],$tmp_hbeg[2],$tmp_dbeg[1],$tmp_dbeg[2],$tmp_dbeg[0]);                
107
                $updates2[]="realtime";
108
                $fup->fields["realtime"]=$dateDiff/60/60;
109
                $fup->updateInDB($updates2);
110
                $job->updateRealTime($input["id_tracking"]);
111

    
112
                if (isset($updates)){
113
                        $this->updateInDB($updates);
114

    
115
                        if ((!isset($input["_nomail"])||$input["_nomail"]==0)&&count($updates)>0&&$CFG_GLPI["mailing"]){
116
                                $user=new User;
117
                                $user->getFromDB($_SESSION["glpiID"]);
118
                                $mail = new Mailing("followup",$job,$user,$fup->fields["private"]);
119
                                $mail->send();
120
                        }
121

    
122
                }
123
                return true;
124
        }
125

    
126
        function add($input){
127
                global $LANG,$CFG_GLPI;
128
                // set new date.
129
                $this->fields["id_followup"] = $input["id_followup"];
130
                $this->fields["id_assign"] = $input["id_assign"];
131
                $this->fields["state"] = $input["state"];
132
                $this->fields["begin"] = $input["begin_date"]." ".$input["begin_hour"].":00";
133
                $this->fields["end"] = $input["end_date"]." ".$input["end_hour"].":00";
134

    
135
                //        if (!empty($target)){
136
                if (!$this->test_valid_date()){
137
                        $this->displayError("date");
138
                        return false;
139
                }
140

    
141
                if ($this->is_alreadyplanned()){
142
                        $this->displayError("is_res");
143
                        return false;
144
                }
145
                
146
                // Auto update Status
147
                $job=new Job();
148
                $job->getFromDB($input["id_tracking"]);
149
                if ($job->fields["status"]=="new"||$job->fields["status"]=="assign"){
150
                        $job->fields["status"]="plan";
151
                        $updates[]="status";
152
                        $job->updateInDB($updates);                
153
                }
154

    
155
                // Auto update realtime
156
                $fup=new Followup();
157
                $fup->getFromDB($input["id_followup"]);
158

    
159
                if ($fup->fields["realtime"]==0){
160
                        $tmp_beg=split(" ",$this->fields["begin"]);
161
                        $tmp_end=split(" ",$this->fields["end"]);
162
                        $tmp_dbeg=split("-",$tmp_beg[0]);
163
                        $tmp_dend=split("-",$tmp_end[0]);
164
                        $tmp_hbeg=split(":",$tmp_beg[1]);
165
                        $tmp_hend=split(":",$tmp_end[1]);
166

    
167
                        $dateDiff = mktime($tmp_hend[0],$tmp_hend[1],$tmp_hend[2],$tmp_dend[1],$tmp_dend[2],$tmp_dend[0]) 
168
                                - mktime($tmp_hbeg[0],$tmp_hbeg[1],$tmp_hbeg[2],$tmp_dbeg[1],$tmp_dbeg[2],$tmp_dbeg[0]);                
169
                        $updates2[]="realtime";
170
                        $fup->fields["realtime"]=$dateDiff/60/60;
171
                        $fup->updateInDB($updates2);
172
                        $job->updateRealTime($input["id_tracking"]);
173
                }
174

    
175
                if ($input["id_tracking"]>0)
176
                        $return=$this->addToDB();
177
                else $return = true;
178

    
179
                if ((!isset($input["_nomail"])||$input["_nomail"]==0)&&$CFG_GLPI["mailing"])
180
                {
181
                        $user=new User;
182
                        $user->getFromDB($_SESSION["glpiID"]);
183
                        $mail = new Mailing("followup",$job,$user,$fup->fields["private"]);
184
                        $mail->send();
185
                }
186

    
187

    
188
                return $return;
189
        }
190

    
191
        function pre_deleteItem($ID) {
192

    
193
                if ($this->getFromDB($ID)){
194
                        if (isset($this->fields["id_assign"])&&($this->fields["id_assign"]==$_SESSION["glpiID"]||haveRight("comment_all_ticket","1"))){
195
                                // Auto update realtime
196
                                $fup=new Followup();
197
                                $fup->getFromDB($this->fields["id_followup"]);
198
                                $updates2[]="realtime";
199
                                $fup->fields["realtime"]=0;
200
                                $fup->updateInDB($updates2);
201
                        }
202
                } 
203
                return true;
204
        }
205

    
206

    
207
        // SPECIFIC FUNCTIONS
208

    
209
        /**
210
         * Is the user assigned to the current planning already planned ?
211
         *
212
         *@return boolean
213
         **/
214
        function is_alreadyplanned(){
215
                global $DB;
216
                if (!isset($this->fields["id_assign"])||empty($this->fields["id_assign"]))
217
                        return true;
218

    
219
                // When modify a planning do not itself take into account 
220
                $ID_where="";
221
                if(isset($this->fields["ID"]))
222
                        $ID_where=" (ID <> '".$this->fields["ID"]."') AND ";
223

    
224
                $query = "SELECT * FROM glpi_tracking_planning".
225
                        " WHERE $ID_where (id_assign = '".$this->fields["id_assign"]."') AND ".
226
                        " ( ('".$this->fields["begin"]."' < begin AND '".$this->fields["end"]."' > begin) ".
227
                        " OR ('".$this->fields["begin"]."' < end AND '".$this->fields["end"]."' >= end) ".
228
                        " OR ('".$this->fields["begin"]."' >= begin AND '".$this->fields["end"]."' < end))";
229
                //                echo $query."<br>";
230
                if ($result=$DB->query($query)){
231
                        return ($DB->numrows($result)>0);
232
                }
233
                return true;
234
        }
235
        /**
236
         * Current dates are valid ? begin before end
237
         *
238
         *@return boolean
239
         **/
240
        function test_valid_date(){
241
                return (strtotime($this->fields["begin"])<strtotime($this->fields["end"]));
242
        }
243

    
244
        /**
245
         * Add error message to message after redirect
246
         * @param $type error type : date / is_res / other
247
         *@return nothing
248
         **/
249
        function displayError($type){
250
                global $LANG;
251

    
252
                switch ($type){
253
                        case "date":
254
                                addMessageAfterRedirect($LANG["planning"][1]);
255
                        break;
256
                        case "is_res":
257
                                addMessageAfterRedirect($LANG["planning"][0]);
258
                        break;
259
                        default :
260
                                addMessageAfterRedirect($LANG["common"][61]);
261
                        break;
262
                }
263
        }
264

    
265
}
266

    
267

    
268
?>
Redmine Appliance - Powered by TurnKey Linux