-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
156 lines (144 loc) · 5.72 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
<?php
require "DataBase.php";
$empresas = array("Vivo", "Claro", "Tim", "GVT");
$client = new SoapClient("http://localhost:8081/Middleware/Middleware?WSDL");
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if($_POST != null){
foreach ($_POST as $key => $value) {
$value = filter_input(INPUT_POST, $key);
$post[$key] = $value;
}
if($post['acao'] == "compra_ou_venda"){
if($post['interesse'] == "comprar"){
$res = $client->comprar(array('ciente' => $url,'empresa' => $post['empresa'],'quantidade'=>$post['quantidade'],'preco'=>$post['preco'],'tempo'=>$post['tempo']));
}elseif($post['interesse'] == "vender"){
$res = $client->vender(array('ciente' => $url,'empresa' => $post['empresa'],'quantidade'=>$post['quantidade'],'preco'=>$post['preco'],'tempo'=>$post['tempo']));
}
}elseif($post['acao'] == "monitorar"){
$res = $client->monitorar(array('ciente' => $url,'empresa' => $post['empresa']));
}
}
//cadastra empresa no Servidor
foreach ($empresas as $key => $value) {
$res = $client->cadastrarEmpresa(array('empresa' => $value));
//print_r($res);
}
$db = new DataBase();
$rows = $db->query("SELECT COUNT(*) as count FROM acoes");
$row = $rows->fetchArray();
$numRows = $row['count'];
if ($numRows == 0) {
// zero rows
for ($i = 0; $i < 4; $i++) {
$quantidade = rand(1, 100);
$preco = rand(1, 1000) / 100;
$sql = "INSERT INTO acoes (empresa, quantidade, preco) VALUES ('$empresas[$i]','$quantidade','$preco')";
$ret = $db->exec($sql);
if (!$ret) {
echo $db->lastErrorMsg();
} else {
//echo "Acao criada";
}
}
}
?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title>CLiente</title>
<style>
#container { width: 800px; margin: auto;}
table { margin-top: 20px; text-align: center; border-style: dotted; padding: 5px;}
input, select {margin-top: 5px;}
form { margin-top: 50px; border-style: dotted; padding: 5px;}
</style>
</head>
<body>
<div id="container">
<table>
<thead>
<tr><th>Minhas Açoes</th></tr>
<tr><th>Empresa</th><th>Quantidade</th><th>Valor</th></tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM acoes";
$ret = $db->query($sql);
while ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
echo "<tr><td>{$row['empresa']}</td><td>{$row['quantidade']}</td><td>{$row['preco']}</td></tr>";
}
?>
</tbody>
</table>
<table>
<thead>
<tr><th>Açoes no Servidor</th></tr>
</thead>
<tbody>
<?php
$obj = $client->listarEmpresas();
$return = $obj->return;
foreach ($return as $key => $value) {
echo "<tr><td>$value</td></tr>";
}
?>
</tbody>
</table>
<table>
<thead>
<tr><th>Monitorando</th></tr>
<tr><th>Empresa</th><th>Interesse</th><th>Quantidade</th><th>Valor</th></tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM monitorando";
$ret = $db->query($sql);
while ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
echo "<tr><td>{$row['empresa']}</td><td>{$row['interesse']}</td><td>{$row['quantidade']}</td><td>{$row['preco']}</td></tr>";
}
?>
</tbody>
</table>
<form method="post">
<h3>Comprar ou Vender</h3>
<input type="hidden" name="acao" value="compra_ou_venda"/>
<label for="empresa">Empresa</label>
<input id="empresa" name="empresa" type="text"/>
<select name="interesse">
<option value="comprar">Comprar</option>
<option value="vender">Vender</option>
</select>
<label for="preco">Preço</label>
<input id="preco" name="preco" type="text"/>
<label for="quantidade">Quantidade</label>
<input id="quantidade" name="quantidade" type="text"/></br>
<label for="tempo">Tempo em segundos</label>
<input id="tempo" name="tempo" type="text"/>
<input type="submit" value="Enviar"/>
</form>
<form method="post">
<h3>Monitorar</h3>
<input type="hidden" name="acao" value="monitorar"/>
<label for="empresa">Empresa</label>
<input id="empresa" name="empresa" type="text"/>
<input type="submit" value="Monitorar"/>
</form>
</div>
<?php
$sql = "SELECT * FROM notificacoes";
$ret = $db->query($sql);
while ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
echo "<script language=\"javascript\" type=\"text/javascript\">
alert('".$row['texto']."');
</script>";
}
$db->close();
?>
</body>
</html>