-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
229 lines (212 loc) · 6.98 KB
/
index.php
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
require 'config.php';
require 'classes/Calendar.class.php';
require 'classes/Heating.class.php';
$calendar = new Calendar();
if (array_key_exists('action', $_GET))
{
$heating = new Heating(true);
header('Content-Type: text/xml; charset=UTF-8');
echo '<?xml version="1.0" encoding="UTF-8" ?><responses>';
if (array_key_exists('addDay', $_GET))
{
$date = $_GET['addDay'];
$temp = $_GET['type'];
if ($heating->setDateTemperature($date, $temp))
echo '<style id="d' . $date . '">type' . $temp . '</style>';
}
echo '</responses>';
exit(0);
}
header('Content-Type: text/html; charset=UTF-8');
$heating = new Heating();
$calYear = date('Y');
if (array_key_exists('year', $_GET))
$calYear = $_GET['year'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Domoticz control</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" type="text/css" href="web/bootstrap-3.2.0-dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="web/bootstrap-3.2.0-dist/css/bootstrap-theme.min.css">
<link rel="stylesheet" type="text/css" href="web/style.css">
<script type="text/javascript" src="web/jquery-2.1.1.min.js"></script>
</head>
<body>
<div class="center-block text-center" style="padding-top: 10px">
<form class="form-inline" role="form">
<div class="input-group">
<span class="input-group-addon">Speak</span>
<input id="speechText" type="text" placeholder="Speak and order !" class="form-control" style="width: 265px">
<span class="input-group-addon">
<span id="speechButton" class="glyphicon glyphicon-ban-circle speech-mic"></span>
</span>
</div>
<button id="orderButton" type="button" class="btn btn-default">Execute</button>
</form>
<div class="container" style="padding-top: 20px">
Assign temperature:
<select id="typeDay">
<?php
foreach ($heating->getTypes() as $type)
echo "<option>$type</option>";
?>
</select>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-xs-6 text-left"><a class="btn btn-default" href="<?= $_SERVER['PHP_SELF'] ?>?year=<?= ($calYear - 1) ?>"><<</a></div>
<div class="col-xs-6 text-right"><a class="btn btn-default" href="<?= $_SERVER['PHP_SELF'] ?>?year=<?= ($calYear + 1) ?>">>></a></div>
</div>
</div>
<div align="center">
<table class="table table-bordered table-condensed text-center" style="width: auto">
<?php
$begin = mktime(0, 1, 0, 1, 1, $calYear);
$end = mktime(0, 1, 0, 1, 1, $calYear + 1);
$ret = $calendar->getDates($begin, $end);
$nbMonths = count($ret);
echo '<thead><tr>';
for ($posMonth = 0; $posMonth < $nbMonths; $posMonth++)
echo '<th>' . $ret[$posMonth][0] . '</th>';
echo '</tr></thead>';
echo '<tbody>';
for ($posDay = 1; $posDay <= 31; $posDay++)
{
echo '<tr>';
for ($posMonth = 0; $posMonth < $nbMonths; $posMonth++)
{
echo '<td';
if (array_key_exists($posDay, $ret[$posMonth]))
{
$cDate = $ret[$posMonth]["time-$posDay"];
$cText = $ret[$posMonth][$posDay];
$cTemp;
if (($typeDate = $heating->getDateType($cDate)))
{
$cType = 'type' . $typeDate;
$cTemp = $typeDate;
}
else if ($calendar->isWeekend($cDate))
{
$cType = 'weekend';
$cTemp = $heating->getDefaultType();
}
else
{
$cType = '';
$cTemp = $heating->getDefaultType();
}
echo ' id="d'.$cDate.'" class="calDate ' . $cType . '" title="' . $cTemp . '°">' . $cText;
}
else
echo ' style="border: none"> ';
echo '</td>';
}
echo '</tr>';
}
echo '</tbody>';
?>
</table>
</div>
<script>
var recognition = null;
$(function()
{
$('.calDate').click(function()
{
var calDate = $(this).attr('id').substring(1);
var typeClass = $(this).attr('class').replace('type', '');
var newTypeClass = $('#typeDay option:selected').text();
if (typeClass != newTypeClass)
$.ajax({
url: '<?= $_SERVER['PHP_SELF'] ?>',
type: 'GET',
data: 'action=js&addDay=' + calDate + '&type=' + newTypeClass,
dataType: 'xml',
success: function(data)
{
$(data).find('style').each(function()
{
var cellId = $(this).attr('id');
var cellValue = $(this).text();
$('#' + cellId).attr('class', cellValue);
$('#' + cellId).attr('title', cellValue.replace('type', '') + '°');
});
},
error: function() { alert('Arrghhh bug !'); }
});
});
try
{
recognition = new webkitSpeechRecognition();
recognition.continuous = false;
recognition.interimResults = false;
recognition.lang = '<?= SPEAK_LANGUAGE ?>';
recognition.onresult = function (event)
{
for (var i = event.resultIndex; i < event.results.length; ++i)
if (event.results[i].isFinal)
{
$('#speechText').val(event.results[i][0].transcript);
$('#orderButton').click();
break;
}
};
recognition.onend = function()
{
$('#speechButton').removeClass('speech-mic-works').addClass('speech-mic')
.removeClass('glyphicon-remove-circle').addClass('glyphicon-ok-circle');
};
$('.speech-mic').click(function()
{
$('#speechButton').removeClass('speech-mic').addClass('speech-mic-works')
.removeClass('glyphicon-ok-circle').addClass('glyphicon-remove-circle');
recognition.start();
});
$('.speech-mic-works').click(function() { recognition.stop(); });
$('#speechButton').attr('class', 'glyphicon glyphicon-ok-circle speech-mic');
}
catch(e)
{
}
$('#orderButton').click(function()
{
var orderCmd = $('#speechText').val().trim();
if (orderCmd != null && orderCmd.length > 0)
$.ajax({
url: 'order.php',
type: 'GET',
data: 'msg=' + orderCmd,
dataType: 'xml',
success: function(data)
{
$(data).find('tell').each(function()
{
try
{
var msg = new SpeechSynthesisUtterance();
msg.voiceURI = 'native';
msg.volume = 1; // 0 to 1
msg.rate = 1.5; // 0.1 (slow) to 10 (fast)
msg.pitch = 1; //0 to 2
msg.text = $(this).text();
msg.lang = '<?= SPEAK_LANGUAGE ?>';
window.speechSynthesis.speak(msg);
}
catch (e)
{
alert($(this).text());
}
});
},
error: function() { alert('Arrghhh bug !'); }
});
});
});
</script>
</body>
</html>