Blame view

php/classes/FeedbackMgr.php 2.54 KB
16035364   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
<?php
/**
 * @class FeedbackMgr
 * @version $Id: FeedbackMgr.php 1804 2013-09-23 16:28:52Z elena $
 *    
 */

  class FeedbackMgr
  {
  	protected $feedXml, $feedXmlName;
  	
fdd6443e   Elena.Budnik   email for feedback
12
	protected $emails = 'amda@irap.omp.eu';	
16035364   Benjamin Renard   First commit
13
14
15
16
17
18
19
20
  	
  	function __construct()
  	{

  	}
  	
  	function addFeedback($user, $interface, $subject, $userText, $userAgent, $attach)
  	{
dcd07176   Elena.Budnik   Feedback manager
21
22
		if ($user == null)
			return 'err_user';
16035364   Benjamin Renard   First commit
23
  		
dcd07176   Elena.Budnik   Feedback manager
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
		//send feedback to emails list
		$this->sendEmail($user, $interface, $userText, $attach);
		
		if (!is_dir(DATAPATH.'Feedback'))
			mkdir(DATAPATH.'Feedback',755);
			
		//load feedback file		
// 		if (!file_exists(FeedbackXml))
// 				return 'err_file';
		$this->feedXmlName = FeedbackXml;
		$this->feedXml = new DomDocument("1.0","UTF-8");
		$this->feedXml->preserveWhiteSpace = false;
		$this->feedXml->formatOutput = true;
		
		if (file_exists($this->feedXmlName)) 
		{
			$this->feedXml->load($this->feedXmlName);
			$rootElement = $this->feedXml->documentElement;
		}
		else
		{
			$rootElement = $this->feedXml->createElement("root");
			$this->feedXml->appendChild($rootElement);
		}
		
		if (($this->feedXml == null) or ($rootElement == null))
			return 'err_file';
16035364   Benjamin Renard   First commit
51
      
dcd07176   Elena.Budnik   Feedback manager
52
53
		//get feed id - ToDo - to improve
		$N = $this->feedXml->getElementsByTagName("issue")->length > 0 ? $this->feedXml->getElementsByTagName("issue")->length : 0;
16035364   Benjamin Renard   First commit
54
      
dcd07176   Elena.Budnik   Feedback manager
55
56
57
58
59
60
61
62
63
64
		$issue = $this->feedXml->createElement("issue", htmlspecialchars($userText));
		$issue->setAttribute("user", $user);
		$issue->setAttribute("userAgent", $userAgent);
		$issue->setAttribute('interface',$interface);
		$issue->setAttribute('IP',getenv('REMOTE_ADDR'));
		$issue->setAttribute("date", date("Y-m-d"));
		$issue->setAttribute("xml:id", $N);
		$issue->setAttribute("subject", $subject);
		if (isset($attach) && ($attach != ''))
			$issue->setAttribute("attachement",$attach); 
16035364   Benjamin Renard   First commit
65

dcd07176   Elena.Budnik   Feedback manager
66
67
68
69
		$rootElement->appendChild($issue);
		$this->feedXml->save($this->feedXmlName);
		
		return 'none';
16035364   Benjamin Renard   First commit
70
71
  	}
  	
dcd07176   Elena.Budnik   Feedback manager
72
	protected function sendEmail($user, $interface, $userText, $attach)
16035364   Benjamin Renard   First commit
73
  	{
dcd07176   Elena.Budnik   Feedback manager
74
75
		$amda = new AmdaClient();
		$result = $amda->getUserInfo($user);
16035364   Benjamin Renard   First commit
76
   	  
dcd07176   Elena.Budnik   Feedback manager
77
78
79
80
81
82
83
84
85
86
		if ($result['success'])
		{
			$from = $result['email'];
			$to   = $this->emails.",".$result['email'];
		}
		else
		{
			$from = $user;
			$to   = $this->emails;
		}
16035364   Benjamin Renard   First commit
87
  		
1dd8ddc5   Myriam Bouchemit   add hostname in mail
88
		$subject = 'AMDA FEEDBACK from '.gethostname().': '.$interface;
dcd07176   Elena.Budnik   Feedback manager
89
90
91
92
93
94
95
96
		$message = $userText;
		if (isset($attach) && ($attach != ''))
			$message .= "\r\nAttachment : ".$attach;
		$headers = 'From: '.$from."\r\n".
			'Content-type: text/plain; charset=UTF-8';
		
		mail($to, $subject, $message, $headers);
  	} 	
16035364   Benjamin Renard   First commit
97
  }
16035364   Benjamin Renard   First commit
98
?>
1dd8ddc5   Myriam Bouchemit   add hostname in mail
99