-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwelcome.php
208 lines (164 loc) · 6.27 KB
/
welcome.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
<?php
require_once "config.php";
session_start();
//if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
// header("location: login.php");
// exit;
//}
$templates = Array();
$sql = "SELECT id, title, content FROM templates";
$result = $link->query($sql);
if ($result->num_rows > 0) {
$temp = Array();
while($row = $result->fetch_assoc()) {
$temp['id'] = $row['id'];
$temp['title'] = $row['title'];
$temp['content'] = $row['content'];
$templates[] = $temp;
}
} else {
echo "There is not any text templates. Please run templates seeder!<hr />";
}
$link->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Welcome</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<style type="text/css">
body{ font: 14px sans-serif; text-align: center; }
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<div class="page-header">
<h1>Hi, <b><?php echo htmlspecialchars($_SESSION["username"]); ?></b>. Welcome to our site.</h1>
</div>
<p>
<a href="reset-password.php" class="btn btn-warning">Reset Your Password</a>
<a href="logout.php" class="btn btn-danger">Sign Out of Your Account</a>
</p>
<div class="wrapper col-md-offset-3 col-md-6">
<h2>Text sample</h2>
<p>You can manipulate with text here.</p>
<form id="tcpdf_form" action="tcpdf.php" method="POST">
<div class="form-group <?php echo (!empty($foo_err)) ? 'has-error' : ''; ?>">
<label>Variable "foo"</label>
<input id="foo" type="text" name="foo" class="form-control" value="">
<?php if(!empty($bar_err)) { ?>
<span class="help-block"><?php echo $foo_err; ?></span>
<?php } ?>
</div>
<div class="form-group <?php echo (!empty($bar_err)) ? 'has-error' : ''; ?>">
<label>Variable "bar"</label>
<input id="bar" type="text" name="bar" class="form-control" value="">
<?php if(!empty($bar_err)) { ?>
<span class="help-block"><?php echo $bar_err; ?></span>
<?php } ?>
</div>
<div class="form-group">
<button type="button" id="print" disabled="disabled" class="btn btn-success">Print</button>
</div>
<div class="form-group <?php echo (!empty($template_err)) ? 'has-error' : ''; ?>">
<label>Text field</label>
<textarea name="template" id="template" class="form-control" style="height: 100px"></textarea>
<div id="hidden_template" style="display: none;"></div>
<?php if(!empty($template_err)) { ?>
<span class="help-block"><?php echo $template_err; ?></span>
<?php } ?>
</div>
<div class="form-group" style="display: inline-block">
<select id="current_template" class="form-control pull-left col-md-3">
<option value="">Select template</option>
<?php foreach ($templates as $template) { ?>
<option value="<?= $template['id'] ?>"><?= $template['title'] ?></option>
<?php } ?>
</select>
</div>
<div class="form-group" style="display: inline-block">
<button type="button" id="load" disabled="disabled" class="btn btn-warning pull-right">Load</button>
</div>
</form>
</div>
<script>
$(document).ready(function () {
var data,
template_value = "",
foo_value = "",
bar_value = "",
convertedText = "",
template_id = 0;
function downloadPDF(convertedText) {
$.ajax({
async: true,
type: "POST",
url: document.location.origin + '/download-pdf.php',
data: {
'template_id': template_id
},
success: function (response) {
data = JSON.parse(response);
if(data.result){
$('#template').val(data.template.content);
$('#print').prop('disabled', false);
} else {
alert(data.message);
}
}
});
console.log(convertedText, 123);
}
function convertTemplate(template_value, foo_value, bar_value){
$('#hidden_template .foo').each(function (i, e) {
$(this).html(foo_value);
});
$('#hidden_template .bar').each(function (i, e) {
$(this).html(bar_value);
});
}
$('#load').on('click', function () {
template_id = $('#current_template').val();
$.ajax({
async: true,
type: "POST",
url: document.location.origin + '/get-template.php',
data: {
'template_id': template_id
},
success: function (response) {
data = JSON.parse(response);
if(data.result){
$('#template').val(data.template.content);
$('#hidden_template').html(data.template.content);
$('#print').prop('disabled', false);
} else {
alert(data.message);
}
}
});
});
$('#print').on('click', function () {
template_value = $('#template').val();
foo_value = $('#foo').val();
bar_value = $('#bar').val();
if(template_value.length === 0 ||
foo_value.length === 0 ||
bar_value.length === 0) {
alert("Please fill necessary data!");
}
else {
convertTemplate(template_value, foo_value, bar_value);
// downloadPDF(convertedText);
$('#template').val($('#hidden_template').html());
$('#tcpdf_form').submit();
}
});
$('#current_template').on('change', function() {
$('#load').prop('disabled', false);
});
});
</script>
</body>
</html>