Repository navigation
Expand file tree
/
Copy pathservicoEdit.php
More file actions
200 lines (179 loc) · 8.34 KB
/
Copy pathservicoEdit.php
File metadata and controls
200 lines (179 loc) · 8.34 KB
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
<?php
/* CLEAR CACHE */
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
//header("Content-Type: application/xml; charset=utf-8");
require_once 'appConfig.php';
include_once 'api/config/database.php';
include_once 'api/objects/servico.php';
include_once 'api/objects/cliente.php';
if(empty($_SESSION['key'])) {
header ('location:./');
}
// get database connection
$database = new Database();
$db = $database->getConnection();
// prepare objects
$servico = new Servico($db);
$cliente = new Cliente($db);
// GET variables
$py_idservico = md5('idservico');
$sql = $servico->readSingle($_GET[''.$py_idservico.'']);
if($sql->rowCount() > 0) {
#while($row = $sql->fetch(PDO::FETCH_OBJ)) {}
$row = $sql->fetch(PDO::FETCH_OBJ);
?>
<form class="form-edit-servico">
<div class="modal-header">
<h4 class="modal-title">
<span>Editar solicitação</span>
<span class="text-muted">
<small>(<i class="fas fa-bell"></i> Campo obrigatório)</small>
</span>
</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<input type="hidden" name="rand" id="rand_edit" value="<?php echo md5(mt_rand()); ?>">
<input type="hidden" name="idservico" id="idservico" value="<?php echo $_GET[''.$py_idservico.'']; ?>">
<div class="form-group">
<label for="ticket" class="lead text-success">Ticket <?php echo $row->ticket; ?></label>
</div>
<div class="row">
<div class="col">
<div class="form-group">
<label for="datado"><i class="fas fa-bell"></i> Data Inicial</label>
<input type="date" name="datado" id="datado_edit" maxlength="10" value="<?php echo $row->data_inicio; ?>" class="form-control" placeholder="Data Inicial" disabled>
</div>
</div>
<div class="col">
<div class="form-group">
<label for="data_fim_edit">Data Final</label>
<input type="date" name="data_fim" id="data_fim_edit" maxlength="10" value="<?php echo $row->data_fim; ?>" class="form-control" placeholder="Data Final">
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="form-group">
<label for="inicio"><i class="fas fa-bell"></i> Hora Inicial</label>
<input type="time" name="inicio" id="inicio_edit" maxlength="8" min="08:30" max="18:00" value="<?php echo $row->hora_inicio; ?>" class="form-control" placeholder="Hora Inicial" disabled>
</div>
</div>
<div class="col">
<div class="form-group">
<label for="hora_fim_edit">Hora Final</label>
<input type="time" name="hora_fim" id="hora_fim_edit" maxlength="8" min="08:30" max="18:00" value="<?php echo $row->hora_fim; ?>" class="form-control" placeholder="Hora Final">
</div>
</div>
</div>
<div class="form-group">
<label for="situacao"><i class="fas fa-bell"></i> Situação</label>
<select name="situacao" id="situacao_edit" class="form-control" data-placeholder="Busque a situação" style="width: 100%;" required>
<?php
$sql = $servico->readAllStatus();
if($sql->rowCount() > 0) {
while($row2 = $sql->fetch(PDO::FETCH_OBJ)) {
if($row2->idsituacao == $row->situacao_idsituacao) {
echo'<option value="'.$row2->idsituacao.'" selected>'.$row2->descricao.'</option>';
} else {
echo'<option value="'.$row2->idsituacao.'">'.$row2->descricao.'</option>';
}
}
} else {
echo'<option value="" selected>Nenhum solicitante cadastrado</option>';
}
?>
</select>
</div>
<div class="form-group">
<label for="solicitante"><i class="fas fa-bell"></i> Solicitante</label>
<select name="solicitante" id="solicitante_edit" class="form-control" data-placeholder="Busque o solicitante" style="width: 100%;" required>
<?php
$sql = $cliente->readAll();
if($sql->rowCount() > 0) {
while($row2 = $sql->fetch(PDO::FETCH_OBJ)) {
if($row2->idsolicitante == $row->solicitante_idsolicitante) {
echo'<option value="'.$row2->idsolicitante.'" selected>'.$row2->cliente.': '.$row2->solicitante.'</option>';
} else {
echo'<option value="'.$row2->idsolicitante.'">'.$row2->cliente.': '.$row2->solicitante.'</option>';
}
}
} else {
echo'<option value="" selected>Nenhum solicitante cadastrado</option>';
}
?>
</select>
</div>
<div class="form-group">
<label for="assunto">Assunto</label>
<input type="text" name="assunto" id="assunto_edit" maxlength="45" class="form-control" value="<?php echo $row->assunto; ?>" placeholder="Assunto">
</div>
<div class="form-group">
<label for="solicitacao"><i class="fas fa-bell"></i> Solicitação</label>
<input type="text" name="solicitacao" id="solicitacao_edit" maxlength="100" class="form-control" value="<?php echo $row->solicitacao; ?>" placeholder="Solicitação" required>
</div>
<div class="form-group">
<label for="procedimento">Procedimento</label>
<textarea name="procedimento" id="procedimento_edit" rows="3" class="form-control" placeholder="Procedimento"><?php echo $row->procedimento; ?></textarea>
</div>
</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
<button type="submit" class="btn btn-primary btn-edit-servico">Salvar</button>
</div>
</form>
<script defer>
$(document).ready(function() {
const fade = 150, delay = 100,
Toast = Swal.mixin({
toast: true,
position: 'top-end',
showConfirmButton: false,
timer: 2000
});
/* SELECT MULTIPLE */
$('#solicitante_edit').show(function () {
$('#solicitante_edit').select2({
tags: true
});
});
$('#situacao_edit').show(function () {
$('#situacao_edit').select2({
tags: true
});
});
/* EDITAR SERVIÇO */
$('.form-edit-servico').submit(function(e) {
e.preventDefault();
$.post('api/servico/update.php', $(this).serialize(), function(data) {
$('.btn-edit-servico').html('<img src="dist/img/rings.svg" class="loader-svg">').fadeTo(fade, 1);
switch(data) {
case 'true':
Toast.fire({icon: 'success',title: 'Solicitação editada.'}).then((result) => {
window.setTimeout("location.href='inicio'", delay);
});
break;
default:
Toast.fire({icon: 'error',title: data});
break;
}
$('.btn-edit-servico').html('Salvar').fadeTo(fade, 1);
});
return false;
});
});
</script>
<?php
} else {
echo'
<blockquote class="quote-danger">
<h5>Erro</h5>
<p>A solicitação não foi encontrada.</p>
</blockquote>';
}
?>