ryxeo-glpi-git / inc / tracking.class.php @ b67d8923
Historique | Voir | Annoter | Télécharger (42 ko)
1 |
<?php
|
---|---|
2 |
/*
|
3 |
* @version $Id: tracking.class.php 7875 2009-01-23 15:16:47Z 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:
|
33 |
// Purpose of file:
|
34 |
// ----------------------------------------------------------------------
|
35 |
|
36 |
|
37 |
if (!defined('GLPI_ROOT')){ |
38 |
die("Sorry. You can't access directly to this file"); |
39 |
} |
40 |
|
41 |
/// Tracking class
|
42 |
class Job extends CommonDBTM{ |
43 |
/// Hardware datas used by getFromDBwithData
|
44 |
var $hardwaredatas = array(); |
45 |
/// Is a hardware found in getHardwareData / getFromDBwithData : hardware link to the job
|
46 |
var $computerfound = 0; |
47 |
|
48 |
/**
|
49 |
* Constructor
|
50 |
**/
|
51 |
function Job(){ |
52 |
$this->table="glpi_tracking"; |
53 |
$this->type=TRACKING_TYPE; |
54 |
} |
55 |
|
56 |
/**
|
57 |
* Retrieve an item from the database with datas associated (hardwares)
|
58 |
*
|
59 |
*@param $ID ID of the item to get
|
60 |
*@param $purecontent boolean : true : nothing change / false : convert to HTML display
|
61 |
*@return true if succeed else false
|
62 |
**/
|
63 |
function getFromDBwithData ($ID,$purecontent) { |
64 |
|
65 |
global $DB,$LANG; |
66 |
|
67 |
if ($this->getFromDB($ID)){ |
68 |
|
69 |
if (!$purecontent) { |
70 |
$this->fields["contents"] = nl2br(preg_replace("/\r\n\r\n/","\r\n",$this->fields["contents"])); |
71 |
} |
72 |
|
73 |
$this->getHardwareData();
|
74 |
return true; |
75 |
} else {
|
76 |
return false; |
77 |
} |
78 |
} |
79 |
|
80 |
/**
|
81 |
* Retrieve data of the hardware linked to the ticket if exists
|
82 |
*
|
83 |
*@return nothing : set computerfound to 1 if founded
|
84 |
**/
|
85 |
function getHardwareData(){ |
86 |
$m= new CommonItem; |
87 |
if ($m->getFromDB($this->fields["device_type"],$this->fields["computer"])){ |
88 |
$this->hardwaredatas=$m; |
89 |
$this->computerfound=0; |
90 |
} else {
|
91 |
$this->hardwaredatas=$m; |
92 |
$this->computerfound=1; |
93 |
} |
94 |
} |
95 |
function cleanDBonPurge($ID) { |
96 |
global $DB; |
97 |
|
98 |
$query="SELECT ID FROM glpi_followups WHERE tracking = '$ID'"; |
99 |
$result=$DB->query($query); |
100 |
if ($DB->numrows($result)>0) |
101 |
while ($data=$DB->fetch_array($result)){ |
102 |
$querydel="DELETE FROM glpi_tracking_planning WHERE id_followup = '".$data['ID']."'"; |
103 |
$DB->query($querydel); |
104 |
} |
105 |
$query1="DELETE FROM glpi_followups WHERE tracking = '$ID'"; |
106 |
$DB->query($query1); |
107 |
|
108 |
} |
109 |
|
110 |
function prepareInputForUpdate($input) { |
111 |
global $LANG,$CFG_GLPI; |
112 |
// Security checks
|
113 |
if (!haveRight("assign_ticket","1")){ |
114 |
if (isset($input["assign"])){ |
115 |
// Can not steal or can steal and not assign to me
|
116 |
if (!haveRight("steal_ticket","1")||$input["assign"]!=$_SESSION["glpiID"]){ |
117 |
unset($input["assign"]); |
118 |
} |
119 |
} |
120 |
if (isset($input["assign_ent"])){ |
121 |
unset($input["assign_ent"]); |
122 |
} |
123 |
if (isset($input["assign_group"])){ |
124 |
unset($input["assign_group"]); |
125 |
} |
126 |
|
127 |
} |
128 |
|
129 |
if (!haveRight("update_ticket","1")){ |
130 |
// Manage assign and steal right
|
131 |
if (isset($input["assign"])){ |
132 |
$ret["assign"]=$input["assign"]; |
133 |
} |
134 |
if (isset($input["assign_ent"])){ |
135 |
$ret["assign_ent"]=$input["assign_ent"]; |
136 |
} |
137 |
if (isset($input["assign_group"])){ |
138 |
$ret["assign_group"]=$input["assign_group"]; |
139 |
} |
140 |
// Can only update contents if no followups already added
|
141 |
$ret["ID"]=$input["ID"]; |
142 |
if (isset($input["contents"])){ |
143 |
$ret["contents"]=$input["contents"]; |
144 |
} |
145 |
if (isset($input["name"])){ |
146 |
$ret["name"]=$input["name"]; |
147 |
} |
148 |
$input=$ret; |
149 |
} |
150 |
|
151 |
// NEEDED ????
|
152 |
if (isset($input["type"])&& $input["type"]==0&&!isset($input["item"])){ |
153 |
$input["computer"]=0; |
154 |
$input["device_type"]=$input["type"]; |
155 |
} else if (isset($input["item"])&& $input["item"]!=0&&isset($input["type"])&& $input["type"]!=0){ |
156 |
$input["computer"]=$input["item"]; |
157 |
$input["device_type"]=$input["type"]; |
158 |
} |
159 |
|
160 |
if (isset($input["computer"])&&$input["computer"]>=0&&isset($input["device_type"])&&$input["device_type"]>=0){ |
161 |
if (isset($this->fields['FK_group'])&&$this->fields['FK_group']){ |
162 |
$ci=new CommonItem; |
163 |
$ci->getFromDB($input["device_type"],$input["computer"]); |
164 |
if ($tmp=$ci->getField('FK_groups')){ |
165 |
$input["FK_group"] = $tmp; |
166 |
} |
167 |
} |
168 |
} else if (isset($input["device_type"])&&$input["device_type"]==0){ |
169 |
$input["computer"]=0; |
170 |
} else {
|
171 |
unset($input["computer"]); |
172 |
unset($input["device_type"]); |
173 |
} |
174 |
|
175 |
|
176 |
if ( isset($_FILES['multiple']) ) { |
177 |
unset($_FILES['multiple']); |
178 |
$TMPFILE = $_FILES; |
179 |
} else {
|
180 |
$TMPFILE = array( $_FILES ); |
181 |
} |
182 |
foreach ($TMPFILE as $_FILES) { |
183 |
// add Document if exists
|
184 |
if (isset($_FILES['filename'])&&count($_FILES['filename'])>0&&$_FILES['filename']["size"]>0){ |
185 |
$input2=array(); |
186 |
$input2["name"]=addslashes(resume_text($LANG["tracking"][24]." ".$input["ID"],200)); |
187 |
$input2["FK_tracking"]=$input["ID"]; |
188 |
$input2["rubrique"]=$CFG_GLPI["default_rubdoc_tracking"]; |
189 |
$this->getFromDB($input["ID"]); |
190 |
$input2["FK_entities"]=$this->fields["FK_entities"]; |
191 |
$input2["_only_if_upload_succeed"]=1; |
192 |
$doc=new Document(); |
193 |
if ($docID=$doc->add($input2)){ |
194 |
addDeviceDocument($docID,TRACKING_TYPE,$input["ID"]); |
195 |
// force update date_mod
|
196 |
$input["date_mod"]=$_SESSION["glpi_currenttime"]; |
197 |
if ($CFG_GLPI["followup_on_update_ticket"]){ |
198 |
$input['_doc_added']=stripslashes($doc->fields["name"]); |
199 |
} |
200 |
} |
201 |
} else if (!empty($_FILES['filename']['name'])&&isset($_FILES['filename']['error'])&&$_FILES['filename']['error']){ |
202 |
addMessageAfterRedirect($LANG["document"][46]); |
203 |
} |
204 |
} |
205 |
|
206 |
if (isset($input["document"])&&$input["document"]>0){ |
207 |
addDeviceDocument($input["document"],TRACKING_TYPE,$input["ID"]); |
208 |
$doc=new Document(); |
209 |
$doc->getFromDB($input["document"]); |
210 |
unset($input["document"]); |
211 |
// Force date_mod of tracking
|
212 |
$input["date_mod"]=$_SESSION["glpi_currenttime"]; |
213 |
$input['_doc_added']=$doc->fields["name"]; |
214 |
} |
215 |
|
216 |
// Old values for add followup in change
|
217 |
if ($CFG_GLPI["followup_on_update_ticket"]){ |
218 |
$this->getFromDB($input["ID"]); |
219 |
$input["_old_assign_name"]=getAssignName($this->fields["assign"],USER_TYPE); |
220 |
$input["_old_assign"]=$this->fields["assign"]; |
221 |
$input["_old_assign_ent_name"]=getAssignName($this->fields["assign_ent"],ENTERPRISE_TYPE); |
222 |
$input["_old_assign_group_name"]=getAssignName($this->fields["assign_group"],GROUP_TYPE); |
223 |
$input["_old_category"]=$this->fields["category"]; |
224 |
$input["_old_item"]=$this->fields["computer"]; |
225 |
$input["_old_item_type"]=$this->fields["device_type"]; |
226 |
$input["_old_author"]=$this->fields["author"]; |
227 |
$input["_old_recipient"]=$this->fields["recipient"]; |
228 |
$input["_old_group"]=$this->fields["FK_group"]; |
229 |
$input["_old_priority"]=$this->fields["priority"]; |
230 |
$input["_old_status"]=$this->fields["status"]; |
231 |
$input["_old_request_type"]=$this->fields["request_type"]; |
232 |
$input["_old_cost_time"]=$this->fields["cost_time"]; |
233 |
$input["_old_cost_fixed"]=$this->fields["cost_fixed"]; |
234 |
$input["_old_cost_material"]=$this->fields["cost_material"]; |
235 |
$input["_old_date"]=$this->fields["date"]; |
236 |
$input["_old_closedate"]=$this->fields["closedate"]; |
237 |
} |
238 |
|
239 |
return $input; |
240 |
} |
241 |
|
242 |
function pre_updateInDB($input,$updates) { |
243 |
global $LANG; |
244 |
|
245 |
// Status close : check dates
|
246 |
if (ereg("old_",$this->fields["status"])&&(in_array("date",$updates)||in_array("closedate",$updates))){ |
247 |
// Invalid dates : no change
|
248 |
if ($this->fields["closedate"]<$this->fields["date"]){ |
249 |
addMessageAfterRedirect($LANG["tracking"][3]); |
250 |
if (($key=array_search('date',$updates))!==false){ |
251 |
unset($updates[$key]); |
252 |
} |
253 |
if (($key=array_search('closedate',$updates))!==false){ |
254 |
unset($updates[$key]); |
255 |
} |
256 |
} |
257 |
} |
258 |
|
259 |
|
260 |
|
261 |
if (((in_array("assign",$updates)&&$input["assign"]>0)||(in_array("assign_ent",$updates)&&$input["assign_ent"]>0)||(in_array("assign_group",$updates)&&$input["assign_group"]>0))&&$this->fields["status"]=="new"){ |
262 |
$updates[]="status"; |
263 |
$this->fields["status"]="assign"; |
264 |
} |
265 |
if (isset($input["status"])){ |
266 |
if (isset($input["assign_ent"])&&$input["assign_ent"]==0&&isset($input["assign_group"])&&$input["assign_group"]==0&& |
267 |
isset($input["assign"])&&$input["assign"]==0&&$input["status"]=="assign"){ |
268 |
$updates[]="status"; |
269 |
$this->fields["status"]="new"; |
270 |
} |
271 |
|
272 |
if (in_array("status",$updates)&&ereg("old_",$input["status"])){ |
273 |
$updates[]="closedate"; |
274 |
$this->fields["closedate"]=$_SESSION["glpi_currenttime"]; |
275 |
// If invalid date : set open date
|
276 |
if ($this->fields["closedate"]<$this->fields["date"]){ |
277 |
$this->fields["closedate"]=$this->fields["date"]; |
278 |
} |
279 |
} |
280 |
} |
281 |
|
282 |
if (in_array("author",$updates)){ |
283 |
$user=new User; |
284 |
$user->getFromDB($input["author"]); |
285 |
if (!empty($user->fields["email"])){ |
286 |
$updates[]="uemail"; |
287 |
$this->fields["uemail"]=$user->fields["email"]; |
288 |
} |
289 |
} |
290 |
|
291 |
return array($input,$updates); |
292 |
} |
293 |
|
294 |
function post_updateItem($input,$updates,$history=1) { |
295 |
global $CFG_GLPI,$LANG; |
296 |
|
297 |
if (count($updates)){ |
298 |
// New values for add followup in change
|
299 |
$change_followup_content=""; |
300 |
if (isset($input['_doc_added'])){ |
301 |
$change_followup_content=$LANG["mailing"][26]." ".$input['_doc_added']; |
302 |
} |
303 |
$global_mail_change_count=0; |
304 |
|
305 |
// Update Ticket Tco
|
306 |
if (in_array("realtime",$updates)||in_array("cost_time",$updates)|| in_array("cost_fixed",$updates)||in_array("cost_material",$updates)){ |
307 |
$ci=new CommonItem; |
308 |
if ($ci->getFromDB($this->fields["device_type"],$this->fields["computer"])){ |
309 |
$newinput=array(); |
310 |
$newinput['ID']=$this->fields["computer"]; |
311 |
$newinput['ticket_tco']=computeTicketTco($this->fields["device_type"],$this->fields["computer"]); |
312 |
$ci->obj->update($newinput); |
313 |
} |
314 |
} |
315 |
|
316 |
if ($CFG_GLPI["followup_on_update_ticket"]&&count($updates)){ |
317 |
|
318 |
|
319 |
foreach ($updates as $key) |
320 |
switch ($key) { |
321 |
case "name": |
322 |
$change_followup_content.=$LANG["mailing"][45]."\n"; |
323 |
$global_mail_change_count++;
|
324 |
break;
|
325 |
case "contents": |
326 |
$change_followup_content.=$LANG["mailing"][46]."\n"; |
327 |
$global_mail_change_count++;
|
328 |
break;
|
329 |
case "date": |
330 |
$change_followup_content.=$LANG["mailing"][48].": ".$input["_old_date"]." -> ".$this->fields["date"]."\n"; |
331 |
|
332 |
$global_mail_change_count++;
|
333 |
break;
|
334 |
case "closedate": |
335 |
// if update status from an not closed status : no mail for change closedate
|
336 |
if (!in_array("status",$updates)||!ereg("old_",$input["status"])){ |
337 |
$change_followup_content.=$LANG["mailing"][49].": ".$input["_old_closedate"]." -> ".$this->fields["closedate"]."\n"; |
338 |
|
339 |
$global_mail_change_count++;
|
340 |
} |
341 |
break;
|
342 |
case "status": |
343 |
$new_status=$this->fields["status"]; |
344 |
$change_followup_content.=$LANG["mailing"][27].": ".getStatusName($input["_old_status"])." -> ".getStatusName($new_status)."\n"; |
345 |
|
346 |
if (ereg("old_",$new_status)) |
347 |
$newinput["add_close"]="add_close"; |
348 |
|
349 |
if (in_array("closedate",$updates)) |
350 |
$global_mail_change_count++; // Manage closedate |
351 |
|
352 |
$global_mail_change_count++;
|
353 |
break;
|
354 |
case "author": |
355 |
$author=new User; |
356 |
$author->getFromDB($input["_old_author"]); |
357 |
$old_author_name=$author->getName(); |
358 |
$author->getFromDB($this->fields["author"]); |
359 |
$new_author_name=$author->getName(); |
360 |
$change_followup_content.=$LANG["mailing"][18].": $old_author_name -> ".$new_author_name."\n"; |
361 |
|
362 |
$global_mail_change_count++;
|
363 |
break;
|
364 |
case "recipient": |
365 |
$recipient=new User; |
366 |
$recipient->getFromDB($input["_old_recipient"]); |
367 |
$old_recipient_name=$recipient->getName(); |
368 |
$recipient->getFromDB($this->fields["recipient"]); |
369 |
$new_recipient_name=$recipient->getName(); |
370 |
$change_followup_content.=$LANG["mailing"][50].": $old_recipient_name -> ".$new_recipient_name."\n"; |
371 |
|
372 |
$global_mail_change_count++;
|
373 |
break;
|
374 |
case "FK_group" : |
375 |
$new_group=$this->fields["FK_group"]; |
376 |
$old_group_name=ereg_replace(" ",$LANG["mailing"][109],getDropdownName("glpi_groups",$input["_old_group"])); |
377 |
$new_group_name=ereg_replace(" ",$LANG["mailing"][109],getDropdownName("glpi_groups",$new_group)); |
378 |
$change_followup_content.=$LANG["mailing"][20].": ".$old_group_name." -> ".$new_group_name."\n"; |
379 |
$global_mail_change_count++;
|
380 |
break;
|
381 |
case "priority" : |
382 |
$new_priority=$this->fields["priority"]; |
383 |
$change_followup_content.=$LANG["mailing"][15].": ".getPriorityName($input["_old_priority"])." -> ".getPriorityName($new_priority)."\n"; |
384 |
$global_mail_change_count++;
|
385 |
break;
|
386 |
case "category": |
387 |
$new_category=$this->fields["category"]; |
388 |
$old_category_name=ereg_replace(" ",$LANG["mailing"][100],getDropdownName("glpi_dropdown_tracking_category",$input["_old_category"])); |
389 |
$new_category_name=ereg_replace(" ",$LANG["mailing"][100],getDropdownName("glpi_dropdown_tracking_category",$new_category)); |
390 |
$change_followup_content.=$LANG["mailing"][14].": ".$old_category_name." -> ".$new_category_name."\n"; |
391 |
$global_mail_change_count++;
|
392 |
break;
|
393 |
case "request_type": |
394 |
$new_request_type=$this->fields["request_type"]; |
395 |
$old_request_type_name=getRequestTypeName($input["_old_request_type"]); |
396 |
$new_request_type_name=getRequestTypeName($new_request_type); |
397 |
$change_followup_content.=$LANG["mailing"][21].": ".$old_request_type_name." -> ".$new_request_type_name."\n"; |
398 |
$global_mail_change_count++;
|
399 |
break;
|
400 |
case "computer" : |
401 |
case "device_type": |
402 |
if (isset($already_done_computer_device_type_update)){ |
403 |
break;
|
404 |
} else {
|
405 |
$already_done_computer_device_type_update=true; |
406 |
} |
407 |
$ci=new CommonItem; |
408 |
$ci->getFromDB($input["_old_item_type"],$input["_old_item"]); |
409 |
$old_item_name=$ci->getName(); |
410 |
if ($old_item_name=="N/A"||empty($old_item_name)) |
411 |
$old_item_name=$LANG["mailing"][107]; |
412 |
$ci->getFromDB($this->fields["device_type"],$this->fields["computer"]); |
413 |
$new_item_name=$ci->getName(); |
414 |
if ($new_item_name=="N/A"||empty($new_item_name)) |
415 |
$new_item_name=$LANG["mailing"][107]; |
416 |
|
417 |
$change_followup_content.=$LANG["mailing"][17].": $old_item_name -> ".$new_item_name."\n"; |
418 |
if (in_array("computer",$updates)) $global_mail_change_count++; |
419 |
if (in_array("device_type",$updates)) $global_mail_change_count++; |
420 |
break;
|
421 |
case "assign" : |
422 |
$new_assign_name=getAssignName($this->fields["assign"],USER_TYPE); |
423 |
if ($input["_old_assign"]==0){ |
424 |
$input["_old_assign_name"]=$LANG["mailing"][105]; |
425 |
} |
426 |
$change_followup_content.=$LANG["mailing"][12].": ".$input["_old_assign_name"]." -> ".$new_assign_name."\n"; |
427 |
$global_mail_change_count++;
|
428 |
break;
|
429 |
case "assign_ent" : |
430 |
$new_assign_ent_name=getAssignName($this->fields["assign_ent"],ENTERPRISE_TYPE); |
431 |
$change_followup_content.=$LANG["mailing"][12].": ".$input["_old_assign_ent_name"]." -> ".$new_assign_ent_name."\n"; |
432 |
$global_mail_change_count++;
|
433 |
break;
|
434 |
case "assign_group" : |
435 |
$new_assign_group_name=getAssignName($this->fields["assign_group"],GROUP_TYPE); |
436 |
$change_followup_content.=$LANG["mailing"][12].": ".$input["_old_assign_group_name"]." -> ".$new_assign_group_name."\n"; |
437 |
$global_mail_change_count++;
|
438 |
break;
|
439 |
case "cost_time": |
440 |
$change_followup_content.=$LANG["mailing"][42].": ".formatNumber($input["_old_cost_time"])." -> ".formatNumber($this->fields["cost_time"])."\n"; |
441 |
$global_mail_change_count++;
|
442 |
break;
|
443 |
case "cost_fixed" : |
444 |
$change_followup_content.=$LANG["mailing"][43].": ".formatNumber($input["_old_cost_fixed"])." -> ".formatNumber($this->fields["cost_fixed"])."\n"; |
445 |
$global_mail_change_count++;
|
446 |
break;
|
447 |
case "cost_material" : |
448 |
$change_followup_content.=$LANG["mailing"][44].": ".formatNumber($input["_old_cost_material"])." -> ".formatNumber($this->fields["cost_material"])."\n"; |
449 |
$global_mail_change_count++;
|
450 |
break;
|
451 |
case "emailupdates": |
452 |
if ($this->fields["emailupdates"]){ |
453 |
$change_followup_content.=$LANG["mailing"][101]."\n"; |
454 |
} else {
|
455 |
$change_followup_content.=$LANG["mailing"][102]."\n"; |
456 |
} |
457 |
$global_mail_change_count++;
|
458 |
break;
|
459 |
} |
460 |
} |
461 |
if (!in_array("assign",$updates)){ |
462 |
unset($input["_old_assign"]); |
463 |
} |
464 |
$mail_send=false; |
465 |
|
466 |
if (!empty($change_followup_content)){ // Add followup if not empty |
467 |
$newinput=array(); |
468 |
$newinput["contents"]=addslashes($change_followup_content); |
469 |
$newinput["author"]=$_SESSION['glpiID']; |
470 |
$newinput["private"]=0; |
471 |
$newinput["hour"]=$newinput["minute"]=0; |
472 |
$newinput["tracking"]=$this->fields["ID"]; |
473 |
$newinput["type"]="update"; |
474 |
$newinput["_do_not_check_author"]=true; |
475 |
// pass _old_assign if assig changed
|
476 |
if (isset($input["_old_assign"])){ |
477 |
$newinput["_old_assign"]=$input["_old_assign"]; |
478 |
} |
479 |
if (isset($input["status"])&&in_array("status",$updates)&&ereg("old_",$input["status"])){ |
480 |
$newinput["type"]="finish"; |
481 |
} |
482 |
$fup=new Followup(); |
483 |
$fup->add($newinput); |
484 |
$mail_send=true; |
485 |
} |
486 |
|
487 |
|
488 |
// Clean content to mail
|
489 |
$this->fields["contents"]=stripslashes($this->fields["contents"]); |
490 |
|
491 |
if (!$mail_send&&count($updates)>$global_mail_change_count&&$CFG_GLPI["mailing"]){ |
492 |
$user=new User; |
493 |
$user->getFromDB($_SESSION["glpiID"]); |
494 |
$mailtype="update"; |
495 |
if ($input["status"]&&in_array("status",$updates)&&ereg("old_",$input["status"])){ |
496 |
$mailtype="finish"; |
497 |
} |
498 |
if (isset($input["_old_assign"])){ |
499 |
$this->fields["_old_assign"]=$input["_old_assign"]; |
500 |
} |
501 |
$mail = new Mailing($mailtype,$this,$user); |
502 |
$mail->send();
|
503 |
} |
504 |
} |
505 |
} |
506 |
|
507 |
|
508 |
function prepareInputForAdd($input) { |
509 |
global $CFG_GLPI,$LANG; |
510 |
|
511 |
// print_r($input);
|
512 |
// exit();
|
513 |
// Check mandatory
|
514 |
$mandatory_ok=true; |
515 |
|
516 |
// Do not check mandatory on auto import (mailgates)
|
517 |
if (!isset($input['_auto_import'])){ |
518 |
|
519 |
$_SESSION["helpdeskSaved"]=$input; |
520 |
|
521 |
if ($CFG_GLPI["ticket_content_mandatory"]&&(!isset($input['contents'])||empty($input['contents']))){ |
522 |
addMessageAfterRedirect($LANG["tracking"][8]); |
523 |
$mandatory_ok=false; |
524 |
} |
525 |
if ($CFG_GLPI["ticket_title_mandatory"]&&(!isset($input['name'])||empty($input['name']))){ |
526 |
addMessageAfterRedirect($LANG["help"][40]); |
527 |
$mandatory_ok=false; |
528 |
} |
529 |
if ($CFG_GLPI["ticket_category_mandatory"]&&(!isset($input['category'])||empty($input['category']))){ |
530 |
addMessageAfterRedirect($LANG["help"][41]); |
531 |
$mandatory_ok=false; |
532 |
} |
533 |
if (isset($input['emailupdates'])&&$input['emailupdates']&&(!isset($input['uemail'])||empty($input['uemail']))){ |
534 |
addMessageAfterRedirect($LANG["help"][16]); |
535 |
$mandatory_ok=false; |
536 |
} |
537 |
|
538 |
if (!$mandatory_ok){ |
539 |
return false; |
540 |
} |
541 |
} |
542 |
unset($_SESSION["helpdeskSaved"]); |
543 |
|
544 |
// Manage helpdesk.html submission type
|
545 |
unset($input["type"]); |
546 |
|
547 |
// No Auto set Import for external source
|
548 |
if (!isset($input['_auto_import'])){ |
549 |
if (!isset($input["author"])){ |
550 |
if (isset($_SESSION["glpiID"])&&$_SESSION["glpiID"]>0) |
551 |
$input["author"]=$_SESSION["glpiID"]; |
552 |
} |
553 |
} |
554 |
|
555 |
// No Auto set Import for external source
|
556 |
if (isset($_SESSION["glpiID"])&&!isset($input['_auto_import'])) { |
557 |
$input["recipient"]=$_SESSION["glpiID"]; |
558 |
} else if ($input["author"]) { |
559 |
$input["recipient"]=$input["author"]; |
560 |
} |
561 |
|
562 |
if (!isset($input["request_type"])) $input["request_type"]=1; |
563 |
if (!isset($input["status"])) $input["status"]="new"; |
564 |
if (!isset($input["assign"])) $input["assign"]=0; |
565 |
|
566 |
$user=new User(); |
567 |
if ($user->getFromDB($input["author"])){ |
568 |
$input['author_location']=$user->fields['location']; |
569 |
} |
570 |
|
571 |
if (!isset($input["date"])||$input["date"]=='0000-00-00 00:00'){ |
572 |
$input["date"] = $_SESSION["glpi_currenttime"]; |
573 |
} |
574 |
|
575 |
if (isset($input["computer"])&&$input["computer"]==0){ |
576 |
$input["device_type"]=0; |
577 |
} |
578 |
|
579 |
if ($input["device_type"]==0){ |
580 |
$input["computer"]=0; |
581 |
} |
582 |
|
583 |
// Auto group define
|
584 |
if (isset($input["computer"])&&$input["computer"]&&$input["device_type"]){ |
585 |
$ci=new CommonItem; |
586 |
$ci->getFromDB($input["device_type"],$input["computer"]); |
587 |
if ($tmp=$ci->getField('FK_groups')){ |
588 |
$input["FK_group"] = $tmp; |
589 |
} |
590 |
} |
591 |
|
592 |
if ($CFG_GLPI["auto_assign"]&&$input["assign"]==0&&isset($input["computer"])&&$input["computer"]>0&&isset($input["device_type"])&&$input["device_type"]>0){ |
593 |
$ci=new CommonItem; |
594 |
$ci->getFromDB($input["device_type"],$input["computer"]); |
595 |
if ($tmp=$ci->getField('tech_num')){ |
596 |
$input["assign"] = $tmp; |
597 |
if ($input["assign"]>0){ |
598 |
$input["status"] = "assign"; |
599 |
} |
600 |
} |
601 |
} |
602 |
|
603 |
// Process Business Rules
|
604 |
$rules=new TrackingBusinessRuleCollection(); |
605 |
|
606 |
$input=$rules->processAllRules($input,$input); |
607 |
|
608 |
if (isset($input["emailupdates"])&&$input["emailupdates"]&&empty($input["uemail"])){ |
609 |
$user=new User(); |
610 |
$user->getFromDB($input["author"]); |
611 |
$input["uemail"]=$user->fields["email"]; |
612 |
} |
613 |
|
614 |
if (((isset($input["assign"])&&$input["assign"]>0) |
615 |
||(isset($input["assign_group"])&&$input["assign_group"]>0) |
616 |
||(isset($input["assign_ent"])&&$input["assign_ent"]>0)) |
617 |
&&$input["status"]=="new"){ |
618 |
$input["status"] = "assign"; |
619 |
} |
620 |
|
621 |
if (isset($input["hour"])&&isset($input["minute"])){ |
622 |
$input["realtime"]=$input["hour"]+$input["minute"]/60; |
623 |
$input["_hour"]=$input["hour"]; |
624 |
$input["_minute"]=$input["minute"]; |
625 |
unset($input["hour"]); |
626 |
unset($input["minute"]); |
627 |
} |
628 |
|
629 |
if (isset($input["status"])&&strstr($input["status"],"old_")){ |
630 |
if (isset($input["date"])){ |
631 |
$input["closedate"]=$input["date"]; |
632 |
} else {
|
633 |
$input["closedate"]=$_SESSION["glpi_currenttime"]; |
634 |
} |
635 |
} |
636 |
|
637 |
if (empty($input["name"])) { |
638 |
$input["name"]=preg_replace('/\r\n/',' ',$input['contents']); |
639 |
$input["name"]=preg_replace('/\n/',' ',$input['name']); |
640 |
$input["name"]=substr($input['name'],0,70); |
641 |
} |
642 |
|
643 |
return $input; |
644 |
} |
645 |
|
646 |
function post_addItem($newID,$input) { |
647 |
global $LANG,$CFG_GLPI; |
648 |
|
649 |
// add Document if exists
|
650 |
if (isset($_FILES['multiple']) ) { |
651 |
unset($_FILES['multiple']); |
652 |
$TMPFILE = $_FILES; |
653 |
} else {
|
654 |
$TMPFILE = array( $_FILES ); |
655 |
} |
656 |
foreach ($TMPFILE as $_FILES) { |
657 |
if (isset($_FILES['filename'])&&count($_FILES['filename'])>0&&$_FILES['filename']["size"]>0){ |
658 |
$input2=array(); |
659 |
$input2["name"]=$LANG["tracking"][24]." $newID"; |
660 |
$input2["FK_tracking"]=$newID; |
661 |
$input2["FK_entities"]=$input["FK_entities"]; |
662 |
$input2["rubrique"]=$CFG_GLPI["default_rubdoc_tracking"]; |
663 |
$input2["_only_if_upload_succeed"]=1; |
664 |
$doc=new Document(); |
665 |
if ($docID=$doc->add($input2)) |
666 |
addDeviceDocument($docID,TRACKING_TYPE,$newID); |
667 |
} |
668 |
} |
669 |
|
670 |
// Log this event
|
671 |
logEvent($newID,"tracking",4,"tracking",getUserName($input["author"])." ".$LANG["log"][20]); |
672 |
|
673 |
$already_mail=false; |
674 |
if (((isset($input["_followup"])&&is_array($input["_followup"])&&strlen($input["_followup"]['contents']))||isset($input["plan"])) |
675 |
||(isset($input["_hour"])&&isset($input["_minute"])&&isset($input["realtime"])&&$input["realtime"]>0)){ |
676 |
|
677 |
$fup=new Followup(); |
678 |
$type="new"; |
679 |
if (isset($this->fields["status"])&&ereg("old_",$this->fields["status"])) $type="finish"; |
680 |
$toadd=array("type"=>$type,"tracking"=>$newID); |
681 |
if (isset($input["_hour"])) $toadd["hour"]=$input["_hour"]; |
682 |
if (isset($input["_minute"])) $toadd["minute"]=$input["_minute"]; |
683 |
if (isset($input["_followup"]['contents'])&&strlen($input["_followup"]['contents'])) $toadd["contents"]=$input["_followup"]['contents']; |
684 |
if (isset($input["_followup"]['private'])) $toadd["private"]=$input["_followup"]['private']; |
685 |
if (isset($input["plan"])) $toadd["plan"]=$input["plan"]; |
686 |
$fup->add($toadd); |
687 |
$already_mail=true; |
688 |
} |
689 |
|
690 |
// Processing Email
|
691 |
if ($CFG_GLPI["mailing"]&&!$already_mail) |
692 |
{ |
693 |
$user=new User(); |
694 |
$user->getFromDB($input["author"]); |
695 |
|
696 |
$this->fields=stripslashes_deep($this->fields); |
697 |
$type="new"; |
698 |
if (isset($this->fields["status"])&&ereg("old_",$this->fields["status"])) $type="finish"; |
699 |
$mail = new Mailing($type,$this,$user); |
700 |
$mail->send();
|
701 |
} |
702 |
|
703 |
} |
704 |
|
705 |
// SPECIFIC FUNCTIONS
|
706 |
/**
|
707 |
* Number of followups of the ticket
|
708 |
*
|
709 |
*@param $with_private boolean : true : all ticket / false : only public ones
|
710 |
*@return followup count
|
711 |
**/
|
712 |
function numberOfFollowups($with_private=1){ |
713 |
global $DB; |
714 |
$RESTRICT=""; |
715 |
if ($with_private!=1) $RESTRICT = " AND private='0'"; |
716 |
// Set number of followups
|
717 |
$query = "SELECT count(*) FROM glpi_followups WHERE tracking = '".$this->fields["ID"]."' $RESTRICT"; |
718 |
$result = $DB->query($query); |
719 |
return $DB->result($result,0,0); |
720 |
|
721 |
} |
722 |
|
723 |
/**
|
724 |
* Update realtime of the ticket based on realtim of the followups
|
725 |
*
|
726 |
*@param $ID ID of the ticket
|
727 |
*@return boolean : success
|
728 |
**/
|
729 |
function updateRealTime($ID) { |
730 |
// update Status of Job
|
731 |
|
732 |
global $DB; |
733 |
$query = "SELECT SUM(realtime) FROM glpi_followups WHERE tracking = '$ID'"; |
734 |
if ($result = $DB->query($query)) { |
735 |
$sum=$DB->result($result,0,0); |
736 |
if (is_null($sum)) $sum=0; |
737 |
$query2="UPDATE glpi_tracking SET realtime='".$sum."' WHERE ID='$ID'"; |
738 |
$DB->query($query2); |
739 |
return true; |
740 |
} else {
|
741 |
return false; |
742 |
} |
743 |
} |
744 |
|
745 |
/**
|
746 |
* Update date mod of the ticket
|
747 |
*
|
748 |
*@param $ID ID of the ticket
|
749 |
**/
|
750 |
function updateDateMod($ID) { |
751 |
global $DB; |
752 |
$query="UPDATE glpi_tracking SET date_mod='".$_SESSION["glpi_currenttime"]."' WHERE ID='$ID'"; |
753 |
$DB->query($query); |
754 |
} |
755 |
|
756 |
/**
|
757 |
* Get text describing Followups
|
758 |
*
|
759 |
* @param $format text or html
|
760 |
* @param $sendprivate true if both public and private followups have to be printed in the email
|
761 |
*/
|
762 |
function textFollowups($format="text", $sendprivate=false) { |
763 |
// get the last followup for this job and give its contents as
|
764 |
global $DB,$LANG; |
765 |
|
766 |
if (isset($this->fields["ID"])){ |
767 |
$query = "SELECT * FROM glpi_followups WHERE tracking = '".$this->fields["ID"]."' ".($sendprivate?"":" AND private = '0' ")." ORDER by date DESC"; |
768 |
$result=$DB->query($query); |
769 |
$nbfollow=$DB->numrows($result); |
770 |
if($format=="html"){ |
771 |
$message = "<div class='description'><strong>".$LANG["mailing"][4]." : $nbfollow<br></strong></div>\n"; |
772 |
|
773 |
if ($nbfollow>0){ |
774 |
$fup=new Followup(); |
775 |
while ($data=$DB->fetch_array($result)){ |
776 |
$fup->getFromDB($data['ID']); |
777 |
$message .= "<strong>[ ".convDateTime($fup->fields["date"])." ] ".($fup->fields["private"]?"<i>".$LANG["common"][77]."</i>":"")."</strong>\n"; |
778 |
$message .= "<span style='color:#8B8C8F; font-weight:bold; text-decoration:underline; '>".$LANG["job"][4].":</span> ".$fup->getAuthorName()."<br>"; |
779 |
$message .= "<span style='color:#8B8C8F; font-weight:bold; text-decoration:underline; '>".$LANG["mailing"][3]."</span>:<br>".ereg_replace("\n","<br>",$fup->fields["contents"])."\n"; |
780 |
if ($fup->fields["realtime"]>0) |
781 |
$message .= "<span style='color:#8B8C8F; font-weight:bold; text-decoration:underline; '>".$LANG["mailing"][104].":</span> ".getRealtime($fup->fields["realtime"])."\n"; |
782 |
|
783 |
$message.="<span style='color:#8B8C8F; font-weight:bold; text-decoration:underline; '>".$LANG["mailing"][25]."</span> "; |
784 |
$query2="SELECT * from glpi_tracking_planning WHERE id_followup='".$data['ID']."'"; |
785 |
$result2=$DB->query($query2); |
786 |
if ($DB->numrows($result2)==0) |
787 |
$message.=$LANG["job"][32]."\n"; |
788 |
else {
|
789 |
$data2=$DB->fetch_array($result2); |
790 |
$message.=convDateTime($data2["begin"])." -> ".convDateTime($data2["end"])."\n"; |
791 |
} |
792 |
|
793 |
$message.=$LANG["mailing"][0]."\n"; |
794 |
} |
795 |
} |
796 |
}else{ // text format |
797 |
$message = $LANG["mailing"][1]."\n".$LANG["mailing"][4]." : $nbfollow\n".$LANG["mailing"][1]."\n"; |
798 |
|
799 |
if ($nbfollow>0){ |
800 |
$fup=new Followup(); |
801 |
while ($data=$DB->fetch_array($result)){ |
802 |
$fup->getFromDB($data['ID']); |
803 |
$message .= "[ ".convDateTime($fup->fields["date"])." ]".($fup->fields["private"]?"\t".$LANG["common"][77]:"")."\n"; |
804 |
$message .= $LANG["job"][4].": ".$fup->getAuthorName()."\n"; |
805 |
$message .= $LANG["mailing"][3].":\n".$fup->fields["contents"]."\n"; |
806 |
if ($fup->fields["realtime"]>0) |
807 |
$message .= $LANG["mailing"][104].": ".getRealtime($fup->fields["realtime"])."\n"; |
808 |
|
809 |
$message.=$LANG["mailing"][25]." "; |
810 |
$query2="SELECT * from glpi_tracking_planning WHERE id_followup='".$data['ID']."'"; |
811 |
$result2=$DB->query($query2); |
812 |
if ($DB->numrows($result2)==0) |
813 |
$message.=$LANG["job"][32]."\n"; |
814 |
else {
|
815 |
$data2=$DB->fetch_array($result2); |
816 |
$message.=convDateTime($data2["begin"])." -> ".convDateTime($data2["end"])."\n"; |
817 |
} |
818 |
|
819 |
$message.=$LANG["mailing"][0]."\n"; |
820 |
} |
821 |
} |
822 |
|
823 |
|
824 |
} |
825 |
return $message; |
826 |
} else return ""; |
827 |
} |
828 |
|
829 |
/**
|
830 |
* Get text describing ticket
|
831 |
*
|
832 |
* @param $format text or html
|
833 |
*/
|
834 |
function textDescription($format="text"){ |
835 |
global $DB,$LANG; |
836 |
|
837 |
|
838 |
$name=$LANG["help"][30]; |
839 |
$contact=''; |
840 |
$tech=''; |
841 |
$name=$this->hardwaredatas->getType()." ".$this->hardwaredatas->getName(); |
842 |
if ($this->hardwaredatas->obj!=NULL){ |
843 |
if (isset($this->hardwaredatas->obj->fields["serial"])&&!empty($this->hardwaredatas->obj->fields["serial"])){ |
844 |
$name.=" - #".$this->hardwaredatas->obj->fields["serial"]; |
845 |
} |
846 |
if (isset($this->hardwaredatas->obj->fields["model"])&&$this->hardwaredatas->obj->fields["model"]>0){ |
847 |
$add=""; |
848 |
switch ($this->fields['device_type']){ |
849 |
case MONITOR_TYPE: |
850 |
$add='_monitors'; |
851 |
break;
|
852 |
case NETWORKING_TYPE: |
853 |
$add='_networking'; |
854 |
break;
|
855 |
case PERIPHERAL_TYPE: |
856 |
$add='_peripherals'; |
857 |
break;
|
858 |
case PHONE_TYPE: |
859 |
$add='_phones'; |
860 |
break;
|
861 |
case PRINTER_TYPE: |
862 |
$add='_printers'; |
863 |
break;
|
864 |
} |
865 |
$name.=" - ".getDropdownName("glpi_dropdown_model".$add,$this->hardwaredatas->obj->fields["model"]); |
866 |
} |
867 |
if (isset($this->hardwaredatas->obj->fields["tech_num"])&&$this->hardwaredatas->obj->fields["tech_num"]>0){ |
868 |
$tech=getUserName($this->hardwaredatas->obj->fields["tech_num"]); |
869 |
} |
870 |
if (isset($this->hardwaredatas->obj->fields["contact"])){ |
871 |
$contact=$this->hardwaredatas->obj->fields["contact"]; |
872 |
} |
873 |
if (isset($this->hardwaredatas->obj->fields["FK_users"])){ |
874 |
$contact=getUserName($this->hardwaredatas->obj->fields["FK_users"]); |
875 |
} |
876 |
if (isset($this->hardwaredatas->obj->fields["FK_groups"])){ |
877 |
if (!empty($contact)) $contact.=" / "; |
878 |
$contact.=getDropdownName("glpi_groups",$this->hardwaredatas->obj->fields["FK_groups"]); |
879 |
} |
880 |
} |
881 |
|
882 |
if($format=="html"){ |
883 |
$message= "<html><head> <style type=\"text/css\">"; |
884 |
$message.=".description{ color: inherit; background: #ebebeb; border-style: solid; border-color: #8d8d8d; border-width: 0px 1px 1px 0px; }"; |
885 |
$message.=" </style></head><body>"; |
886 |
|
887 |
$message.="<div class='description'><strong>".$LANG["mailing"][5]."</strong></div>\n"; |
888 |
$message.="<span style='color:#8B8C8F; font-weight:bold; text-decoration:underline; '>".$LANG["common"][57].":</span> ".$this->fields["name"]."\n"; |
889 |
$author=$this->getAuthorName(); |
890 |
if (empty($author)) $author=$LANG["mailing"][108]; |
891 |
$message.="<span style='color:#8B8C8F; font-weight:bold; text-decoration:underline; '>".$LANG["job"][4].":</span> ".$author."\n"; |
892 |
$message.="<span style='color:#8B8C8F; font-weight:bold; text-decoration:underline; '>". $LANG["search"][8].":</span> ".convDateTime($this->fields["date"])."\n"; |
893 |
$message.="<span style='color:#8B8C8F; font-weight:bold; text-decoration:underline; '>". $LANG["job"][44].":</span> ".getRequestTypeName($this->fields["request_type"])."\n"; |
894 |
$message.="<span style='color:#8B8C8F; font-weight:bold; text-decoration:underline; '>". $LANG["mailing"][7].":</span> ".$name."\n"; |
895 |
if (!empty($tech)) |
896 |
$message.="<span style='color:#8B8C8F; font-weight:bold; text-decoration:underline; '>". $LANG["common"][10].":</span> ".$tech."\n"; |
897 |
$message.= "<span style='color:#8B8C8F; font-weight:bold; text-decoration:underline; '>".$LANG["joblist"][0].":</span> ".getStatusName($this->fields["status"])."\n"; |
898 |
$assign=getAssignName($this->fields["assign"],USER_TYPE); |
899 |
$assign_group=""; |
900 |
if (isset($this->fields["assign_group"])){ |
901 |
$assign_group=getAssignName($this->fields["assign_group"],GROUP_TYPE); |
902 |
} |
903 |
if ($assign=="[Nobody]"){ |
904 |
if (!empty($assign_group)){ |
905 |
$assign=$assign_group; |
906 |
} else {
|
907 |
$assign=$LANG["mailing"][105]; |
908 |
} |
909 |
} else {
|
910 |
if (!empty($assign_group)){ |
911 |
$assign.=" / ".$assign_group; |
912 |
} |
913 |
} |
914 |
$message.= "<span style='color:#8B8C8F; font-weight:bold; text-decoration:underline; '>".$LANG["mailing"][8].":</span> ".$assign."\n"; |
915 |
$message.="<span style='color:#8B8C8F; font-weight:bold; text-decoration:underline; '>".$LANG["joblist"][2].":</span> ".getPriorityName($this->fields["priority"])."\n"; |
916 |
if ($this->fields["device_type"]!=SOFTWARE_TYPE&&!empty($contact)) |
917 |
$message.= "<span style='color:#8B8C8F; font-weight:bold; text-decoration:underline; '>".$LANG["common"][18].":</span> ".$contact."\n"; |
918 |
if (isset($this->fields["emailupdates"]) && $this->fields["emailupdates"]){ |
919 |
$message.="<span style='color:#8B8C8F; font-weight:bold; text-decoration:underline; '>".$LANG["mailing"][103].":</span> ".$LANG["choice"][1]."\n"; |
920 |
} else {
|
921 |
$message.="<span style='color:#8B8C8F; font-weight:bold; text-decoration:underline; '>".$LANG["mailing"][103].":</span> ".$LANG["choice"][0]."\n"; |
922 |
} |
923 |
|
924 |
$message.= "<span style='color:#8B8C8F; font-weight:bold; text-decoration:underline; '>".$LANG["common"][36].":</span> "; |
925 |
if (isset($this->fields["category"])&&$this->fields["category"]){ |
926 |
$message.= getDropdownName("glpi_dropdown_tracking_category",$this->fields["category"]); |
927 |
} else $message.=$LANG["mailing"][100]; |
928 |
$message.= "\n"; |
929 |
$message.="<span style='color:#8B8C8F; font-weight:bold; text-decoration:underline; '>". $LANG["mailing"][3].":</span><br>".ereg_replace("\n","<br>",$this->fields["contents"])."<br>\n"; |
930 |
|
931 |
}else{ //text format |
932 |
$message = $LANG["mailing"][1]."\n*".$LANG["mailing"][5]."*\n".$LANG["mailing"][1]."\n"; |
933 |
|
934 |
$message.=mailRow($LANG["common"][57],$this->fields["name"]); |
935 |
$author=$this->getAuthorName(); |
936 |
if (empty($author)) $author=$LANG["mailing"][108]; |
937 |
$message.=mailRow($LANG["job"][4],$author); |
938 |
$message.=mailRow($LANG["search"][8],convDateTime($this->fields["date"])); |
939 |
$message.=mailRow($LANG["job"][44],getRequestTypeName($this->fields["request_type"])); |
940 |
$message.=mailRow($LANG["mailing"][7],$name); |
941 |
if (!empty($tech)) |
942 |
$message.= mailRow($LANG["common"][10],$tech); |
943 |
$message.= mailRow($LANG["joblist"][0],getStatusName($this->fields["status"])); |
944 |
$assign=getAssignName($this->fields["assign"],USER_TYPE); |
945 |
$assign_group=""; |
946 |
if (isset($this->fields["assign_group"])){ |
947 |
$assign_group=getAssignName($this->fields["assign_group"],GROUP_TYPE); |
948 |
} |
949 |
if ($assign=="[Nobody]"){ |
950 |
if (!empty($assign_group)){ |
951 |
$assign=$assign_group; |
952 |
} else {
|
953 |
$assign=$LANG["mailing"][105]; |
954 |
} |
955 |
} else {
|
956 |
if (!empty($assign_group)){ |
957 |
$assign.=" / ".$assign_group; |
958 |
} |
959 |
} |
960 |
|
961 |
$message.= mailRow($LANG["mailing"][8],$assign); |
962 |
$message.= mailRow($LANG["joblist"][2],getPriorityName($this->fields["priority"])); |
963 |
if ($this->fields["device_type"]!=SOFTWARE_TYPE&&!empty($contact)) |
964 |
$message.= mailRow($LANG["common"][18],$contact); |
965 |
if (isset($this->fields["emailupdates"]) && $this->fields["emailupdates"]){ |
966 |
$message.=mailRow($LANG["mailing"][103],$LANG["choice"][1]); |
967 |
} else {
|
968 |
$message.=mailRow($LANG["mailing"][103],$LANG["choice"][0]); |
969 |
} |
970 |
|
971 |
|
972 |
if (isset($this->fields["category"])&&$this->fields["category"]){ |
973 |
$message.= mailRow($LANG["common"][36],getDropdownName("glpi_dropdown_tracking_category",$this->fields["category"])); |
974 |
} else $message.=mailRow($LANG["common"][36],$LANG["mailing"][100]); |
975 |
$message.= "--\n"; |
976 |
$message.= $LANG["mailing"][3]." : \n".$this->fields["contents"]."\n"; |
977 |
$message.="\n\n"; |
978 |
|
979 |
} |
980 |
|
981 |
return $message; |
982 |
} |
983 |
|
984 |
|
985 |
/**
|
986 |
* Get author name
|
987 |
*
|
988 |
* @param $link boolean with link ?
|
989 |
* @return string author name
|
990 |
*/
|
991 |
function getAuthorName($link=0){ |
992 |
return getUserName($this->fields["author"],$link); |
993 |
} |
994 |
|
995 |
/**
|
996 |
* Is the current user have right to add followups to the current ticket ?
|
997 |
*
|
998 |
* @return boolean
|
999 |
*/
|
1000 |
function canAddFollowups(){ |
1001 |
return ((haveRight("comment_ticket","1")&&$this->fields["author"]==$_SESSION["glpiID"]) |
1002 |
||haveRight("comment_all_ticket","1") |
1003 |
||(isset($_SESSION["glpiID"])&&$this->fields["assign"]==$_SESSION["glpiID"]) |
1004 |
||(isset($_SESSION["glpigroups"])&&in_array($this->fields["assign_group"],$_SESSION['glpigroups'])) |
1005 |
); |
1006 |
} |
1007 |
/**
|
1008 |
* Is the current user have right to show the current ticket ?
|
1009 |
*
|
1010 |
* @return boolean
|
1011 |
*/
|
1012 |
function canShowTicket(){ |
1013 |
return (
|
1014 |
haveRight("show_all_ticket","1") |
1015 |
|| (isset($_SESSION["glpiID"])&&$this->fields["author"]==$_SESSION["glpiID"]) |
1016 |
|| (haveRight("show_group_ticket",'1')&&isset($_SESSION["glpigroups"])&&in_array($this->fields["FK_group"],$_SESSION["glpigroups"])) |
1017 |
|| (haveRight("show_assign_ticket",'1')&&( |
1018 |
(isset($_SESSION["glpiID"])&&$this->fields["assign"]==$_SESSION["glpiID"]) |
1019 |
||(isset($_SESSION["glpigroups"])&&in_array($this->fields["assign_group"],$_SESSION["glpigroups"])) |
1020 |
) |
1021 |
) |
1022 |
); |
1023 |
} |
1024 |
|
1025 |
} |
1026 |
|
1027 |
/// Followup class
|
1028 |
class Followup extends CommonDBTM { |
1029 |
|
1030 |
/**
|
1031 |
* Constructor
|
1032 |
**/
|
1033 |
function Followup () { |
1034 |
$this->table="glpi_followups"; |
1035 |
$this->type=-1; |
1036 |
} |
1037 |
|
1038 |
function cleanDBonPurge($ID) { |
1039 |
global $DB; |
1040 |
$querydel="DELETE FROM glpi_tracking_planning WHERE id_followup = '$ID'"; |
1041 |
$DB->query($querydel); |
1042 |
} |
1043 |
|
1044 |
function post_deleteFromDB($ID){ |
1045 |
$job=new Job(); |
1046 |
$job->updateRealtime($this->fields['tracking']); |
1047 |
$job->updateDateMod($this->fields["tracking"]); |
1048 |
} |
1049 |
|
1050 |
|
1051 |
function prepareInputForUpdate($input) { |
1052 |
|
1053 |
$input["realtime"]=$input["hour"]+$input["minute"]/60; |
1054 |
if (isset($_SESSION["glpiID"])){ |
1055 |
$input["author"]=$_SESSION["glpiID"]; |
1056 |
} |
1057 |
|
1058 |
if (isset($input["plan"])){ |
1059 |
$input["_plan"]=$input["plan"]; |
1060 |
unset($input["plan"]); |
1061 |
} |
1062 |
return $input; |
1063 |
} |
1064 |
|
1065 |
function post_updateItem($input,$updates,$history=1) { |
1066 |
global $CFG_GLPI; |
1067 |
|
1068 |
$job=new Job; |
1069 |
$mailsend=false; |
1070 |
if ($job->getFromDB($input["tracking"])){ |
1071 |
$job->updateDateMod($input["tracking"]); |
1072 |
|
1073 |
if (count($updates)){ |
1074 |
|
1075 |
if ($CFG_GLPI["mailing"]&& |
1076 |
(in_array("contents",$updates)||isset($input['_need_send_mail']))){ |
1077 |
$user=new User; |
1078 |
$user->getFromDB($_SESSION["glpiID"]); |
1079 |
$mail = new Mailing("followup",$job,$user,(isset($input["private"]) && $input["private"])); |
1080 |
$mail->send();
|
1081 |
$mailsend=true; |
1082 |
} |
1083 |
|
1084 |
if (in_array("realtime",$updates)) { |
1085 |
$job->updateRealTime($input["tracking"]); |
1086 |
} |
1087 |
} |
1088 |
} |
1089 |
|
1090 |
if (isset($input["_plan"])){ |
1091 |
|
1092 |
$pt=new PlanningTracking(); |
1093 |
// Update case
|
1094 |
if (isset($input["_plan"]["ID"])){ |
1095 |
$input["_plan"]['id_followup']=$input["ID"]; |
1096 |
$input["_plan"]['id_tracking']=$input['tracking']; |
1097 |
$input["_plan"]['_nomail']=$mailsend; |
1098 |
|
1099 |
if (!$pt->update($input["_plan"])){ |
1100 |
return false; |
1101 |
} |
1102 |
unset($input["_plan"]); |
1103 |
// Add case
|
1104 |
} else {
|
1105 |
$input["_plan"]['id_followup']=$input["ID"]; |
1106 |
$input["_plan"]['id_tracking']=$input['tracking']; |
1107 |
$input["_plan"]['_nomail']=1; |
1108 |
|
1109 |
if (!$pt->add($input["_plan"])){ |
1110 |
return false; |
1111 |
} |
1112 |
unset($input["_plan"]); |
1113 |
$input['_need_send_mail']=true; |
1114 |
} |
1115 |
} |
1116 |
} |
1117 |
|
1118 |
function prepareInputForAdd($input) { |
1119 |
|
1120 |
$input["_isadmin"]=haveRight("comment_all_ticket","1"); |
1121 |
|
1122 |
$input["_job"]=new Job; |
1123 |
if ($input["_job"]->getFromDB($input["tracking"])){ |
1124 |
// Security to add unauthorized followups
|
1125 |
if (!isset($input['_do_not_check_author']) |
1126 |
&&$input["_job"]->fields["author"]!=$_SESSION["glpiID"] |
1127 |
&&!$input["_job"]->canAddFollowups()) { |
1128 |
return false; |
1129 |
} |
1130 |
} else {
|
1131 |
return false; |
1132 |
} |
1133 |
|
1134 |
// Pass old assign From Job in case of assign change
|
1135 |
if (isset($input["_old_assign"])){ |
1136 |
$input["_job"]->fields["_old_assign"]=$input["_old_assign"]; |
1137 |
} |
1138 |
|
1139 |
|
1140 |
if (!isset($input["type"])) $input["type"]="followup"; |
1141 |
$input["_type"]=$input["type"]; |
1142 |
unset($input["type"]); |
1143 |
|
1144 |
$input['_close']=0; |
1145 |
unset($input["add"]); |
1146 |
|
1147 |
if (!isset($input["author"])) |
1148 |
$input["author"]=$_SESSION["glpiID"]; |
1149 |
|
1150 |
if ($input["_isadmin"]&&$input["_type"]!="update"){ |
1151 |
if (isset($input['plan'])){ |
1152 |
$input['_plan']=$input['plan']; |
1153 |
unset($input['plan']); |
1154 |
} |
1155 |
if (isset($input["add_close"])) $input['_close']=1; |
1156 |
unset($input["add_close"]); |
1157 |
|
1158 |
if (!isset($input["hour"])){ |
1159 |
$input["hour"]=0; |
1160 |
} |
1161 |
if (!isset($input["minute"])){ |
1162 |
$input["minute"]=0; |
1163 |
} |
1164 |
if ($input["hour"]>0||$input["minute"]>0) |
1165 |
$input["realtime"]=$input["hour"]+$input["minute"]/60; |
1166 |
} |
1167 |
|
1168 |
unset($input["minute"]); |
1169 |
unset($input["hour"]); |
1170 |
|
1171 |
$input["date"] = $_SESSION["glpi_currenttime"]; |
1172 |
|
1173 |
return $input; |
1174 |
} |
1175 |
|
1176 |
function post_addItem($newID,$input) { |
1177 |
global $CFG_GLPI; |
1178 |
|
1179 |
$job=new Job(); |
1180 |
$job->getFromDB($input["tracking"]); |
1181 |
|
1182 |
$job->updateDateMod($input["tracking"]); |
1183 |
|
1184 |
if (isset($input["realtime"])&&$input["realtime"]>0) { |
1185 |
$job->updateRealTime($input["tracking"]); |
1186 |
} |
1187 |
|
1188 |
|
1189 |
if ($input["_isadmin"]&&$input["_type"]!="update"){ |
1190 |
|
1191 |
if (isset($input["_plan"])){ |
1192 |
$input["_plan"]['id_followup']=$newID; |
1193 |
$input["_plan"]['id_tracking']=$input['tracking']; |
1194 |
$input["_plan"]['_nomail']=1; |
1195 |
$pt=new PlanningTracking(); |
1196 |
|
1197 |
if (!$pt->add($input["_plan"])){ |
1198 |
return false; |
1199 |
} |
1200 |
} |
1201 |
|
1202 |
|
1203 |
if ($input["_close"]&&$input["_type"]!="update"&&$input["_type"]!="finish"){ |
1204 |
$updates[]="status"; |
1205 |
$updates[]="closedate"; |
1206 |
$input["_job"]->fields["status"]="old_done"; |
1207 |
$input["_job"]->fields["closedate"] = $_SESSION["glpi_currenttime"]; |
1208 |
$input["_job"]->updateInDB($updates); |
1209 |
} |
1210 |
|
1211 |
} |
1212 |
|
1213 |
if ($CFG_GLPI["mailing"]){ |
1214 |
if ($input["_close"]) $input["_type"]="finish"; |
1215 |
$user=new User; |
1216 |
if (!isset($input['_auto_import'])&&isset($_SESSION["glpiID"])){ |
1217 |
$user->getFromDB($_SESSION["glpiID"]); |
1218 |
} |
1219 |
$mail = new Mailing($input["_type"],$input["_job"],$user, |
1220 |
(isset($input["private"])&&$input["private"])); |
1221 |
$mail->send();
|
1222 |
} |
1223 |
} |
1224 |
|
1225 |
|
1226 |
// SPECIFIC FUNCTIONS
|
1227 |
|
1228 |
/**
|
1229 |
* Get the author name of the followup
|
1230 |
* @param $link insert link ?
|
1231 |
*
|
1232 |
*@return string of the author name
|
1233 |
**/
|
1234 |
function getAuthorName($link=0){ |
1235 |
return getUserName($this->fields["author"],$link); |
1236 |
} |
1237 |
|
1238 |
} |
1239 |
|
1240 |
|
1241 |
|
1242 |
?>
|