-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamerajson.php
50 lines (41 loc) · 1.38 KB
/
camerajson.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
<?php
include("cameraservice.php");
if (is_ajax()) {
if (isset($_POST["action"]) && !empty($_POST["action"])) { //Checks if action value exists
$action = $_POST["action"];
switch($action) { //Switch case for value of action
case "test": test_function(); break;
}
}
}
//Function to check if the request is an AJAX request
function is_ajax() {
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
}
function test_function(){
$return = $_POST;
$id = $return["id"];
$c = new CameraService();
$camera = $c->getCameraById($id);
$return["camera"] = $camera;
$textoCamera = getTextoCamera($camera);
$return["texto"] = $textoCamera;
//Do what you need to do with the info. The following are some examples.
//if ($return["favorite_beverage"] == ""){
// $return["favorite_beverage"] = "Coke";
//}
//$return["favorite_restaurant"] = "McDonald's";
$return["json"] = json_encode($return);
echo json_encode($return);
}
function getTextoCamera($c){
$lmax = ($c['lentemaximo'])*10;
$lmin = ($c['lenteminimo'])*10;
$texto = "";
foreach ($c as $key => $value) {
$texto .= "{$key}:{$value}; ";
}
$texto = "Câmera: <b>{$c['modelo']} / {$c['tipo']}" . (($c["ip"])?" / IP":"") . (($c["analogica"])?" / Analógica":"") . " / Lente: Mínima({$lmax}mm) Máxima({$lmin}mm)</b>";
return $texto;
}
?>