add new matching page

This commit is contained in:
/jedi/ 2019-03-02 02:19:17 +01:00
parent e5e47d5741
commit 6dd8041fe4
3 changed files with 120 additions and 1 deletions

View file

@ -85,6 +85,44 @@ switch($_GET["action"]) {
$errormsg = "all values have to be set"; $errormsg = "all values have to be set";
} }
break; break;
case "add_match":
$successmsg = "one match added";
if (hasval($_POST["found_id"]) && hasval($_POST["lost_id"])) {
/* Prepared statement, stage 1: prepare */
if (!($stmt = $mysqli->prepare("INSERT INTO matches(f_id, l_id) VALUES (?, ?)"))) {
$errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
if (!$stmt->bind_param("ii", $_POST["found_id"], $_POST["lost_id"])) {
$errormsg = "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}
if (!$stmt->execute()) {
$errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
}else if (hasval($_POST["found_id"]) && hasval($_POST["ticket_id"])) {
if (!($stmt = $mysqli->prepare("INSERT INTO lost_items(was) VALUES (?)"))) {
$errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
if (!$stmt->bind_param("s", $_POST["ticket_id"])) {
$errormsg = "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}
if (!$stmt->execute()) {
$errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
$lost_id = $mysqli->insert_id;
/* Prepared statement, stage 1: prepare */
if (!($stmt = $mysqli->prepare("INSERT INTO matches(f_id, l_id) VALUES (?, ?)"))) {
$errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
if (!$stmt->bind_param("ii", $_POST["found_id"], $lost_id)) {
$errormsg = "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}
if (!$stmt->execute()) {
$errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
}else{
$errormsg = "all values have to be set";
}
break;
case "get_stats"; case "get_stats";
echo json_encode(array("status"=>"ok","stats"=>get_stats())); echo json_encode(array("status"=>"ok","stats"=>get_stats()));
break; break;

View file

@ -55,7 +55,7 @@
</td> </td>
<td> <td>
<div class="btn-group" role="group"> <div class="btn-group" role="group">
<button type="button" class="btn btn-outline-secondary"><i class="fas fa-fw fa-check-circle"></i></button> <a href="/match/<?php echo $item["id"]; ?>/" class="btn btn-outline-success" title="match"><i class="fas fa-fw fa-check-circle"></i></a>
<!--<a href="/found_item_edit/<?php echo $item["id"]; ?>/" type="button" class="btn btn-outline-secondary"><i class="fas fa-fw fa-edit"></i></a>--> <!--<a href="/found_item_edit/<?php echo $item["id"]; ?>/" type="button" class="btn btn-outline-secondary"><i class="fas fa-fw fa-edit"></i></a>-->
<button type="button" class="btn btn-outline-secondary" data-toggle="modal" data-target="#exampleModal" <button type="button" class="btn btn-outline-secondary" data-toggle="modal" data-target="#exampleModal"
onclick='fill_edit_form(<?php echo json_encode($item); ?>);' title="edit"> onclick='fill_edit_form(<?php echo json_encode($item); ?>);' title="edit">

81
templates/match.php Normal file
View file

@ -0,0 +1,81 @@
<?php
/**
* Created by PhpStorm.
* User: jedi
* Date: 12/27/18
* Time: 1:49 PM
*/
?>
<div class="container-fluid">
<!-- Breadcrumbs-->
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="#">Dashboard</a>
</li>
<li class="breadcrumb-item">Matches</li>
<li class="breadcrumb-item active">Add</li>
</ol>
<div id="alertmessage" class="collapse alert alert-danger" role="alert">
This is a danger alert—check it out!
</div>
<div id="successmessage" class="collapse alert alert-success" role="alert">
A simple success alert—check it out!
</div>
<!-- Area Chart Example-->
<div class="card mb-3">
<div class="card-header">
<i class="fas fa-plus"></i>
Insert Item into DB
</div>
<div class="card-body">
<form method="POST" id="match_form" action="/action.php?action=tinder">
<div class="form-group">
<input type="text" class="form-control" placeholder="FUND-ID" name="found_id" <?php if(isset($_GET["id"])) echo "value=\"".$_GET["id"]."\" readonly" ?>></div>
<div class="form-group">
<label>Only fill out one of these:</label>
<div class="input-group">
<input type="text" class="form-control" placeholder="LOST-ID" name="lost_id">
<input type="text" class="form-control" placeholder="TICKET-ID" name="ticket_id">
</div>
</div>
<div class="form-group">
<button type="submit" class="form-control" onclick="add_match(); return false;">Submit</button>
</div>
</form>
</div>
<div class="card-footer small text-muted">Updated yesterday at 11:59 PM</div>
</div>
</div>
<script>
function add_match(){
$.post( "/ajax.php?action=add_match", $( "#match_form" ).serialize() ).done(function( data ) {
reply = JSON.parse(data);
if(reply.status == "ok"){
//update_found_table();
$("#alertmessage").collapse('hide');
$("#successmessage").html(reply.message).collapse('show');
setTimeout(function(){ window.location.assign("/table/") }, 1000);
}else{
$("#successmessage").collapse('hide');
$("#alertmessage").html(reply.message).collapse('show');
}
}).fail(function() {
$("#successmessage").collapse('hide');
$("#alertmessage").html("error").collapse('show');
});
}
</script>
<!-- /.container-fluid -->
<!-- /.content-wrapper -->