-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertcheckboxes.php
More file actions
51 lines (43 loc) · 1.65 KB
/
convertcheckboxes.php
File metadata and controls
51 lines (43 loc) · 1.65 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
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$sqlpath = $_SERVER['DOCUMENT_ROOT'];
$sqlpath .= "/sql-connect.php";
include_once($sqlpath);
$parsepath = $_SERVER['DOCUMENT_ROOT'];
$parsepath .= "/plugins/Parsedown.php";
include_once($parsepath);
$parsedown = new Parsedown();
// Fetch the data from your database
$sql = "SELECT * FROM notes";
$sqldata = mysqli_query($dbcon, $sql) or die('Error getting data');
// Loop through each record
while ($row = mysqli_fetch_assoc($sqldata)) {
$noteID = $row['id']; // Assuming there's an 'id' column in your 'notes' table
$htmlContent = $row['body']; // Get the already parsed HTML content
// Replace Markdown checkboxes with HTML checkboxes
$htmlContent = preg_replace_callback(
'/\[\s?([x ]?)\]/', // Match [ ] or [x]
function($matches) {
// If the box is checked ([x]), add the checked attribute
$checked = ($matches[1] === 'x') ? 'checked' : '';
return '<input type="checkbox" ' . $checked . ' disabled>';
},
$htmlContent
);
// Update the content in the database with the new HTML checkboxes
$updateSql = "UPDATE notes SET body = ? WHERE id = ?";
$stmt = $dbcon->prepare($updateSql);
if (!$stmt) {
die('Statement preparation failed: ' . $dbcon->error);
}
$stmt->bind_param("si", $htmlContent, $noteID); // 's' for string, 'i' for integer
$stmt->execute();
if ($stmt->affected_rows > 0) {
echo "Note ID $noteID updated successfully.<br>";
} else {
echo "Error updating Note ID $noteID.<br>";
}
}
echo "All selected notes processed and updated with checkboxes.";
?>