-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoiceedit.php
More file actions
212 lines (186 loc) · 8.21 KB
/
voiceedit.php
File metadata and controls
212 lines (186 loc) · 8.21 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
201
202
203
204
205
206
207
208
209
210
211
212
<?php
include('../db_conn.php');
session_start();
$id = $_SESSION['gate'];
$row = array(); // Initialize $row as an empty array
// Check if the editvoiceid is set and not empty
if (isset($_GET['editvoiceid']) && !empty($_GET['editvoiceid'])) {
$hashedEditVoiceId = $_GET['editvoiceid'];
// Assuming you have fetched the data from the database here and stored it in $sql
$sql = mysqli_query($conn, "SELECT * FROM button WHERE status = 4 AND user = '$id' ORDER BY id DESC");
// Fetch the data as an associative array
$data = array();
while ($row = mysqli_fetch_assoc($sql)) {
$data[] = $row;
}
// Decode the hashed ID to get the original ID
$editvoiceid = array_search($hashedEditVoiceId, array_map('md5', array_column($data, 'id')));
// Use the original ID to fetch the data
$getData = mysqli_query($conn, "SELECT * FROM button WHERE id = '$editvoiceid'");
$row = mysqli_fetch_assoc($getData);
}
?>
<section class="content d-flex align-items-center justify-content-center" style="height: 70vh;">
<div class="col-md-6">
<div class="card">
<div class="card-body">
<!-- Add a warning button -->
<div class="alert alert-warning" role="alert">
<h1 class="text-center">Edit Voice Audio</h1>
</div>
<form id="frmeditevent" enctype="multipart/form-data">
<div class="form-group">
<label for="title" class="control-label">Title</label>
<input type="text" name="title" id="title" class="form-control form-control-sm rounded-0" value="<?php echo $row['label']; ?>" required/>
</div>
<div class="form-group">
<label for="" class="control-label">Music Banner</label>
<div class="custom-file">
<input type="file" class="custom-file-input rounded-circle" id="customFile1" accept="image/*" onchange="previewImage(event, 'bannerPreview')">
<label class="custom-file-label" for="customFile1">Choose file</label>
<div class="container mt-2">
<!-- Image code here -->
<h6>Old Image</h6>
<a href="../images/<?php echo $row['icon']?>" target="_blank">
<img style="height: 50px;" class="img-fluid img-thumbnail" src="../images/<?php echo $row['icon']?>" alt="Your Image">
</a>
</div>
</div>
<!-- Image preview -->
<img id="bannerPreview" src="#" alt="Banner Preview" class="mt-2" style="max-width: 100%; height: auto; display: none;">
</div>
<div class="form-group">
<label for="" class="control-label">Audio File</label>
<div class="custom-file mb-2">
<input type="file" class="custom-file-input rounded-circle" id="customFile2" accept="audio/*" onchange="previewAudio(event)">
<label class="custom-file-label" for="customFile2">Choose file</label>
<div class="container mt-2">
<h6>Old Audio</h6>
<?php
$audioFile = '../images/audio/' . $row['voice_audio'];
if (file_exists($audioFile)) {
echo '<audio controls>';
echo '<source src="' . $audioFile . '" type="audio/mpeg">';
echo 'Your browser does not support the audio element.';
echo '</audio>';
} else {
echo 'Audio file not found.';
}
?>
</div>
</div>
<!-- Audio preview -->
<audio id="audioPreview" controls style="display: none;"></audio>
</div>
<div class="form-group">
<label for="categories" class="control-label">Categories</label>
<select name="categories" id="categories" class="form-control form-control-sm rounded-0" required="required">
<?php
// Fetch the categories from the database
$pdo = new PDO('mysql:host=localhost;dbname=capstone', 'root', '');
$stmt = $pdo->prepare('SELECT * FROM voice_categ');
$stmt->execute();
$categories = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Get the selected category ID (assuming it's stored in $selectedCategoryId)
$selectedCategoryId = $row['categ']; // Replace with your actual selected category ID
// Generate the options for the select element
foreach ($categories as $category) {
$categoryId = $category['voice_id'];
$categoryName = $category['voice_name'];
// Check if the current category ID matches the selected category ID
$selected = ($categoryId == $selectedCategoryId) ? 'selected' : '';
echo "<option value=\"$categoryId\" $selected>$categoryName</option>";
}
?>
</select>
</div>
<!-- Add the Submit button -->
<input id="btnupdateevent" editvoiceide="<?php echo $editvoiceid; ?> " type="button" value="Update" class="btn btn-primary btn-block">
</form>
</div>
</div>
</div>
</section>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
function previewImage(event, previewId) {
var input = event.target;
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
var previewElement = document.getElementById(previewId);
previewElement.src = e.target.result;
previewElement.style.display = "block";
}
reader.readAsDataURL(input.files[0]);
}
}
function previewAudio(event) {
var input = event.target;
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
var audioPreview = document.getElementById('audioPreview');
audioPreview.src = e.target.result;
audioPreview.style.display = "block";
}
reader.readAsDataURL(input.files[0]);
}
}
$(document).ready(function () {
var editvoiceid = 0;
$("#btnupdateevent").click(function () {
editvoiceid = $(this).attr('editvoiceide');
updateevent(event);
});
function updateevent(event) {
event.preventDefault();
var form = document.getElementById('frmeditevent');
var formData = new FormData(form);
// Get feature image file and append it to the form data
var customFile1 = document.getElementById('customFile1').files[0];
formData.append('customFile1', customFile1);
var customFile2 = document.getElementById('customFile2').files[0];
formData.append('customFile2', customFile2);
formData.append('editvoiceid', editvoiceid);
// Send Ajax request to the server using jQuery
$.ajax({
url: 'voiceupdate.php',
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function (response) {
if (response === 'success') {
Swal.fire({
title: 'Do you want to save the changes?',
showDenyButton: true,
showCancelButton: false,
confirmButtonText: 'Update',
denyButtonText: `Don't update`,
}).then((result) => {
if (result.isConfirmed) {
Swal.fire({
title: 'Updated!',
icon: 'success',
confirmButtonText: 'OK',
}).then(() => {
location.reload();
});
} else if (result.isDenied) {
Swal.fire('Changes are not updated', '', 'info');
}
});
} else {
// Error occurred during the server-side processing
Swal.fire('Error occurred', '', 'error');
}
},
error: function (xhr, status, error) {
// Error occurred during the request
Swal.fire('Error occurred', 'Error: ' + error, 'error');
}
});
}
});
</script>