Compare commits

2 Commits

7 changed files with 54 additions and 22 deletions

View File

@@ -86,9 +86,7 @@ Both tables are automatically removed when the plugin is uninstalled.
| Club | Yes | Club name |
| Rank | Yes | Go rank (30k to 9p) |
| Rating | No | EGD rating (auto-calculated from rank if missing) |
| Email | No | Email address |
| EGD Number | No | European Go Database PIN |
| Comment | No | Additional notes |
## Hooks

View File

@@ -0,0 +1,51 @@
-- ========== Original Plugin Tables ==========
CREATE TABLE wp_go_form_forms (
id int NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
created_at datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE wp_go_form_entries (
id int NOT NULL AUTO_INCREMENT,
form_id int DEFAULT 1,
first_name varchar(100) NOT NULL,
last_name varchar(100) NOT NULL,
country varchar(100) DEFAULT NULL,
club varchar(100) DEFAULT NULL,
rank tinyint(2) DEFAULT 0,
rating smallint(5) DEFAULT 0,
egd_number varchar(20) DEFAULT NULL,
created_at date DEFAULT CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (form_id) REFERENCES wp_go_form_forms(id) ON DELETE CASCADE,
INDEX (form_id)
);
-- ========== Custom Fields Tables ==========
CREATE TABLE wp_go_form_custom_fields (
id int NOT NULL AUTO_INCREMENT,
form_id int NOT NULL,
field_name varchar(100) NOT NULL,
field_type enum('select','text','checkbox', 'email') NOT NULL DEFAULT 'text',
field_options text,
is_public tinyint(1) NOT NULL DEFAULT 0,
is_required tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY (id),
FOREIGN KEY (form_id) REFERENCES wp_go_form_forms(id) ON DELETE CASCADE,
INDEX (form_id)
);
CREATE TABLE wp_go_form_entry_custom_values (
id int NOT NULL AUTO_INCREMENT,
entry_id int NOT NULL,
field_id int NOT NULL,
value text,
PRIMARY KEY (id),
FOREIGN KEY (entry_id) REFERENCES wp_go_form_entries(id) ON DELETE CASCADE,
FOREIGN KEY (field_id) REFERENCES wp_go_form_custom_fields(id) ON DELETE CASCADE,
INDEX (entry_id),
INDEX (field_id)
);

View File

@@ -15,7 +15,7 @@ header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="go-form-' . sanitize_title($form_name) . '-export.csv"');
$output = fopen('php://output', 'w');
fputcsv($output, ['ID', 'First Name', 'Last Name', 'Country', 'Club', 'Rank', 'Rating', 'Email', 'EGD Number', 'Comment', 'Date Added']);
fputcsv($output, ['ID', 'First Name', 'Last Name', 'Country', 'Club', 'Rank', 'Rating', 'EGD Number', 'Date Added']);
foreach ($entries as $e) {
global $ranks;
@@ -27,9 +27,7 @@ foreach ($entries as $e) {
$e->club,
$ranks[$e->rank] ?? '',
$e->rating,
$e->email,
$e->egd_number,
$e->comment,
$e->created_at
]);
}

View File

@@ -28,9 +28,7 @@ function go_form_activate()
club varchar(100) DEFAULT NULL,
rank tinyint(2) DEFAULT 0,
rating smallint(5) DEFAULT 0,
email varchar(255) DEFAULT NULL,
egd_number varchar(20) DEFAULT NULL,
comment text DEFAULT NULL,
created_at date DEFAULT CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (form_id) REFERENCES $forms(id) ON DELETE CASCADE
@@ -113,9 +111,7 @@ function go_form_handle_submission()
'club' => sanitize_text_field($_POST['club'] ?? ''),
'rank' => $rank,
'rating' => $rating,
'email' => sanitize_email($_POST['email'] ?? ''),
'egd_number' => sanitize_text_field($_POST['egd_number'] ?? ''),
'comment' => sanitize_textarea_field($_POST['comment'] ?? '')
];
if (empty($data['first_name']) || empty($data['last_name'])) {
@@ -248,7 +244,7 @@ function action_button($action, $name, $confirm_massage, $value_one)
{
echo '
<form method="post" action="' . admin_url('admin-post.php') . '">
' . wp_nonce_field($action . '_action', $action . '_nonce', true, false) . '
' . wp_nonce_field("{$action}_action", "{$action}_nonce", true, false) . '
<input type="hidden" name="action" value="' . $action . '">
<input type="hidden" name="value_one" value="' . $value_one . '">
<input type="submit" value="' . $name . '" class="button" onclick="return confirm(\'' . $confirm_massage . '\')">

View File

@@ -99,14 +99,7 @@
<label for="egd_number">EGD Number:</label><input type="text" name="egd_number" id="egd_number">
</div>
<div>
<label for="email">Email:</label><input type="email" name="email" id="email">
</div>
</div>
<label for="comment">Comment</label>
<textarea name="comment" id="comment" rows="3"></textarea>
<p>* Required fields</p>
<input type="submit" name="go_form_submit" value="Submit">

View File

@@ -10,9 +10,7 @@
<th>Date Added</th>
<?php if ($show_admin): ?>
<th>Rating</th>
<th>Email</th>
<th>Action</th>
<th>Comment</th>
<?php endif; ?>
</tr>
</thead>
@@ -32,11 +30,9 @@
<?php if ($show_admin): ?>
<td> <?= esc_html($e->rating) ?> </td>
<td> <?= esc_html($e->email) ?> </td>
<td>
<?php action_button('go_form_delete_entry', 'Delete', 'Delete this entry?', $e->id); ?>
</td>
<td> <?= esc_html($e->comment) ?> </td>
<?php endif; ?>

View File

@@ -2,7 +2,7 @@
/**
* Plugin Name: Go Form Plugin
* Description: Form plugin for Go players
* Version: 0.04
* Version: 0.05-WIP
* Author: Nikola Petrov
*/