/openshift/adei

To get this branch, use:
bzr branch http://darksoft.org/webbzr/openshift/adei

« back to all changes in this revision

Viewing changes to services/email.php

  • Committer: Suren A. Chilingaryan
  • Date: 2011-01-26 02:48:39 UTC
  • mto: This revision was merged to the branch mainline in revision 212.
  • Revision ID: csa@dside.dyndns.org-20110126024839-nv6qp2ie9stmd2dn
Support of Appled devices by Toni Pirhonen

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
header("Content-type: text/xml");
 
3
header("Cache-Control: no-cache, must-revalidate");
 
4
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
 
5
 
 
6
//require("../classes/email.php");
 
7
 
 
8
global $ADEI;
 
9
global $ADEI_ROOTDIR;
 
10
$ADEI->RequireClass("email");
 
11
$EMAIL = new EMAIL();
 
12
 
 
13
function genEmailContent($props) {
 
14
    $host = $_SERVER['HTTP_HOST'];
 
15
    $location = $props['url'];
 
16
    $query;
 
17
    $i=1;
 
18
    foreach($props as $key => $value)
 
19
    {
 
20
        if ($key != 'from' && $key != 'to' && $key != 'message' && $key != 'attachement' && $key != 'adei_session' && $key != 'task' && $key != 'service' && $key != 'url') {
 
21
            $query .= "&". $key . "=" . $value;
 
22
        }
 
23
    }
 
24
    $filearray = explode('/',$props['attachement']);
 
25
    $file = $filearray[count($file)-1];
 
26
    $url ="$location". "#" ."$query";
 
27
    $message = "<html><head><title>Adei Graph</title></head><body><p>";
 
28
    $message .= "<p>". $props['message'] ."</p>";
 
29
    $message .= "<p><a href='". $url ."'>Link to Graph</a></p>";
 
30
    $message .= "<p><img src='$file' /></p>";
 
31
    $message .="</body></html>";
 
32
    return $message;
 
33
}
 
34
 
 
35
if (isset($_GET['task'])) {
 
36
    switch ($_GET['task']) {
 
37
      case "Send":
 
38
        if (isset($_GET['to']) && isset($_GET['message']) && isset($_GET['from']) && isset($_GET['attachement'])) {
 
39
            $mail = $_GET['to'];
 
40
            $path = $_GET['attachement'];
 
41
            $from = $_GET['from'];
 
42
            foreach($_GET as $key => $value)
 
43
            {
 
44
                $props[$key] = $value;
 
45
            }
 
46
            $msg = genEmailContent($props);
 
47
            $vlues = array('email' => $mail, 'message'=>$msg, 'attachement'=>$path, 'from' => $from);
 
48
            $result = $EMAIL->sendMail($vlues);
 
49
            echo $result;
 
50
            if ($result != 'phpmailerException' || $result != 'exception') unlink($path);
 
51
        }
 
52
        break;
 
53
      case "genpic":
 
54
        $pic .= $_GET['picname'];
 
55
        foreach($_GET as $key => $value)
 
56
        {
 
57
            $props[$key] = $value;
 
58
        }
 
59
        $r = $EMAIL->createFolder();
 
60
        if ($r!="Success") echo "FAIL";
 
61
        else {
 
62
            $result = $EMAIL->createPNG($props);
 
63
            if ($result!="FAILED") echo $ADEI_ROOTDIR ."". $result;
 
64
            else echo "FAIL";
 
65
        }
 
66
        break;
 
67
      case "getSensorList":
 
68
        foreach($_GET as $key => $value) {
 
69
            $opts[$key]= $value;
 
70
        }
 
71
        $details = $EMAIL->listSensors($opts);
 
72
        $return = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><result>";
 
73
        if ($error = $details['error'])
 
74
        {
 
75
            $return .= "<value>". $details['error'] ."</value>";
 
76
        }
 
77
        else {
 
78
//                              $return .= "<value>Success</value></result>";
 
79
            foreach($details['groups'] as $gid => $itemlist) {
 
80
                $return .= "<value><groupname>". $gid ."</groupname>";
 
81
                foreach($itemlist as $item => $info) {
 
82
                    $return .= "<item><itemid>". $info['id'] ."</itemid><itemname>". $info['name'] ."</itemname></item>";
 
83
                }
 
84
                $return .= "</value>";
 
85
            }
 
86
        }
 
87
        $return .="</result>";
 
88
        echo $return;
 
89
        break;
 
90
      default:
 
91
        $return = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><result>";
 
92
        $return .= "<heading>Emaili</heading>";
 
93
        $return .= "<value name='From' id='from'/>";
 
94
        $return .= "<value name='Recipient' id='tomail'/>";
 
95
        $return .= "<value name='Message' id='message'/>";
 
96
        $return .= "<value name=\"$result\" id='ressu'/>";
 
97
        $return .= "</result>";
 
98
        echo $return;
 
99
        break;
 
100
    }
 
101
} else {
 
102
    $return = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><result>";
 
103
    $return .= "<heading>Email</heading>";
 
104
    $return .= "<value name='From' id='from'/>";
 
105
    $return .= "<value name='Recipient' id='tomail'/>";
 
106
    $return .= "<value name='Message' id='message'/>";
 
107
    $return .= "</result>";
 
108
    echo $return;
 
109
}
 
110
?>
 
 
b'\\ No newline at end of file'