-
Notifications
You must be signed in to change notification settings - Fork 0
/
form_cad_agenda.php
121 lines (104 loc) · 4.89 KB
/
form_cad_agenda.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
<?php
include_once 'includes/conexao.php';
include_once 'includes/functions.php';
session_start();
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<?php include 'includes/head.html'; ?>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Cadastro Agenda</title>
</head>
<body>
<?php
if (login_check($mysqli) == true) {
include 'includes/cabecalho.php';
if ($resultado=$mysqli->query("SELECT api_key, calendar_id FROM gab_calendar_key")){
if ($resultado->num_rows){
$aux=1;
$linha=$resultado->fetch_object();
}
}
?>
<div class="container" id="main">
<?php
if (isset($_GET['msg'])){
echo '<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert" aria-label="close">×</a><strong>'.$_GET['msg'].'</strong></div>';
}else if (isset($_GET['err'])){
echo '<div class="alert alert-warning fade in "><a href="#" class="close" data-dismiss="alert" aria-label="close">×</a><strong>'.$_GET['err'].'</strong></div>';
}
?>
<h1 class="h2">Cadastro das Chaves do Google Agenda</h1>
<form id="formId" name="form" class="form-horizontal" action="action_cad_agenda.php" method="post" autocomplete="off">
<?php
if (isset($aux)){
echo "<input type='hidden' name='alt' id='alt'>";
}
?>
<div class="form-group">
<label class="col-md-2 control-label" for="googleCalendarApiKey" autocomplete="on">Google Calendar API:</label>
<div class="col-md-8">
<input id="googleCalendarApiKey" name="api_key" type="text" required placeholder="" class="form-control input-md"
value="<?php if (isset($aux)) {echo escape($linha->api_key);}?>">
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="googleCalendarId" autocomplete="on">Google Calendar ID:</label>
<div class="col-md-8">
<input id="googleCalendarId" name="calendar_id" type="text" required placeholder="" class="form-control input-md"
value="<?php if (isset($aux)) {echo escape($linha->calendar_id);}?>">
</div>
</div>
<div class="form-group">
<div class="col-md-3 text-right">
<input id="submitButton" type="submit" class="btn btn-default" <?php if (isset($aux)) { echo "value='Alterar'";} else {echo "value='Cadastrar'";}?>>
<input type="reset" class="btn btn-default" value="Limpar">
</div>
</div>
<div id="main" class="container" style="margin-top: 20px;">
<p>Para esclarecer dúvidas na obtenção das chaves do Google Agenda, favor acessar o <a href="form_manual.php">Manual do Usuário.</a></p>
</div>
</form>
</div>
<script>
$('#submitButton').click(function(e){
e.preventDefault();
var
apiKey = document.getElementById("googleCalendarApiKey").value,
calendarId = document.getElementById("googleCalendarId").value,
url = 'https://www.googleapis.com/calendar/v3/calendars/'+calendarId+'/events?key='+apiKey;
var errmsg = `<div class="alert alert-warning fade in">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Por favor, insira um par de credenciais válidos.</strong>
</div>`;
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 400) {
console.log('Request Sucessful', xhr);
$('#formId').submit();
return true;
} else {
if($('.alert').length){
$('.alert').remove();
}
$('#main').prepend(errmsg);
console.log('Request failed', xhr);
return false;
}
};
xhr.onerror = function () {
console.log('Request failed', xhr);
return false;
};
xhr.send();
});
</script>
<?php include 'includes/footer.html';
} else { ?>
<p><span class="error">Você não tem autorização para acessar esta página.</span> Please <a href="index.php">login</a>.</p>
<?php } ?>
</body>