Blame view

php/classes/FeedbackMgr.php 2.7 KB
16035364   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
 * @class FeedbackMgr
 * @version $Id: FeedbackMgr.php 1804 2013-09-23 16:28:52Z elena $
 *    
 */

  class FeedbackMgr
  {
  	protected $feedXml, $feedXmlName;
  	
  	protected $emails = 'amda@irap.omp.eu';
  	
  	function __construct()
  	{

  	}
  	
  	function addFeedback($user, $interface, $subject, $userText, $userAgent, $attach)
  	{
  		 if ($user == null)
  	    return 'err_user';
  		
  	  //send feedback to emails list
  	  $this->sendEmail($user, $interface, $userText, $attach);
  		
  	  //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';
      
      //get feed id - ToDo - to improve
  	  $N = $this->feedXml->getElementsByTagName("issue")->length > 0 ? $this->feedXml->getElementsByTagName("issue")->length : 0;
      
  	  $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); 

      $rootElement->appendChild($issue);
      $this->feedXml->save($this->feedXmlName);
      
      return 'none';
  	}
  	
    protected function sendEmail($user, $interface, $userText, $attach)
  	{
  		  $amda = new AmdaClient();
   	  $result = $amda->getUserInfo($user);
   	  
   	  if ($result['success'])
   	  {
   	  	 $from = $result['email'];
   	  	 $to   = $this->emails.",".$result['email'];
   	  }
   	  else
   	  {
   	  	 $from = $user;
   	  	 $to   = $this->emails;
   	  }
  		
      $subject = 'AMDA FEEDBACK: '.$interface;
      $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);
  	}
  	
  }

?>