Commit b3a9486e authored by Reto Da Forno's avatar Reto Da Forno
Browse files

image name and description can now be modified on the website

parent b8b9f695
......@@ -129,20 +129,40 @@
} else if (isset($_POST['s'])) {
if ($_POST['s'] == 'title' && isset($_POST['id']) && isset($_POST['val'])) {
// set the test title
if (isset($_POST['id']) && isset($_POST['val'])) {
$rs = false;
$db = db_connect();
$sql = "UPDATE tbl_serv_tests SET title='". mysqli_real_escape_string($db, $_POST['val']) ."' WHERE serv_tests_key=". intval($_POST['id']) ." AND owner_fk=". $_SESSION['serv_users_key'] ." LIMIT 1";
$rs = mysqli_query($db, $sql);
mysqli_close($db);
if ($_POST['s'] == 'title') {
// set the test title
$sql = "UPDATE tbl_serv_tests SET title='". mysqli_real_escape_string($db, $_POST['val']) ."' WHERE serv_tests_key=". intval($_POST['id']) ." AND owner_fk=". $_SESSION['serv_users_key'] ." LIMIT 1";
$rs = mysqli_query($db, $sql);
} else if ($_POST['s'] == 'desc' && isset($_POST['id']) && isset($_POST['val'])) {
// set the test description
$db = db_connect();
$sql = "UPDATE tbl_serv_tests SET description='". mysqli_real_escape_string($db, $_POST['val']) ."' WHERE serv_tests_key=". intval($_POST['id']) ." AND owner_fk=". $_SESSION['serv_users_key'] ." LIMIT 1";
$rs = mysqli_query($db, $sql);
} else if ($_POST['s'] == 'desc') {
// set the test description
$sql = "UPDATE tbl_serv_tests SET description='". mysqli_real_escape_string($db, $_POST['val']) ."' WHERE serv_tests_key=". intval($_POST['id']) ." AND owner_fk=". $_SESSION['serv_users_key'] ." LIMIT 1";
$rs = mysqli_query($db, $sql);
} else if ($_POST['s'] == 'imgname') {
// set the image name
$sql = "UPDATE tbl_serv_targetimages SET name='". mysqli_real_escape_string($db, $_POST['val']) ."' WHERE serv_targetimages_key=". intval($_POST['id']) ." AND owner_fk=". $_SESSION['serv_users_key'] ." LIMIT 1";
$rs = mysqli_query($db, $sql);
} else if ($_POST['s'] == 'imgdesc') {
// set the image description
$sql = "UPDATE tbl_serv_targetimages SET description='". mysqli_real_escape_string($db, $_POST['val']) ."' WHERE serv_targetimages_key=". intval($_POST['id']) ." AND owner_fk=". $_SESSION['serv_users_key'] ." LIMIT 1";
$rs = mysqli_query($db, $sql);
} else {
echo json_encode(array('status' => 'error', 'output' => 'invalid command'));
}
mysqli_close($db);
if ($rs) {
echo json_encode(array('status' => 'ok'));
} else {
echo json_encode(array('status' => 'error'));
}
} else {
echo json_encode(array('status' => 'error', 'output' => 'invalid API usage'));
}
......
......@@ -34,8 +34,28 @@
<?php require_once('include/layout.php');require_once('include/presets.php'); ?>
<script type="text/javascript" src="scripts/jquery.cookie.js"></script>
<script type="text/javascript">
var editingTitle = 0;
var editingDesc = 0;
function editTitle(testid) {
if (editingTitle == 0) {
editingTitle = testid;
val = $("#title" + testid).text();
$("#title" + testid).html("<input type='text' style='overflow:visible' id='newtitle" + testid + "' value='" + val + "' />");
}
}
function editDesc(testid) {
if (editingDesc == 0) {
editingDesc = testid;
val = $("#desc" + testid).text();
$("#desc" + testid).html("<input type='text' id='newdesc" + testid + "' value='" + val + "' />");
}
}
$(document).ready(function() {
var table_rows = Math.max(Math.floor(($(window).height() - 300) / 25),10);
var table_rows = Math.max(Math.floor(($(window).height() - 300) / 40),10);
$("#pager_num_rows").attr('value', table_rows);
$("#test_overview")
.tablesorter({widgets: ['zebra']})
......@@ -60,6 +80,27 @@
$.cookie('flocklab.imgsort', {s:$("#test_overview").data('tablesorter').sortList, p:$("#test_overview").data('tablesorter').page});
});
});
$(document).mousedown(function(evt) {
if(editingTitle > 0 && evt.target.id != "newtitle" + editingTitle) {
newtitle = $("#newtitle" + editingTitle).val();
if (confirm("save changes?")) {
$.post("api.php", "s=imgname&id=" + editingTitle + "&val=" + newtitle, function() { location.reload(); });
} else {
$("#title" + editingTitle).text(newtitle);
}
editingTitle = 0;
}
if(editingDesc > 0 && evt.target.id != "newdesc" + editingDesc) {
newdesc = $("#newdesc" + editingDesc).val();
if (confirm("save changes?")) {
$.post("api.php", "s=imgdesc&id=" + editingDesc + "&val=" + newdesc, function() { location.reload(); });
} else {
$("#desc" + editingDesc).text(newdesc);
}
editingDesc = 0;
}
});
</script>
<h1>Manage Images for <?php echo $_SESSION['firstname'] . " " . $_SESSION['lastname'];?></h1>
<?php
......@@ -136,12 +177,12 @@
}
echo "<td>" . $row['serv_targetimages_key'] . "</td>";
// Name. If longer than $max_len characters, display as tooltip:
echo "<td class='qtip_show' title='" . $row['name'] . "'>" . $row['name'] . "</td>";
echo "<td class='qtip_show' title='" . $row['name'] . "' id='title".$row['serv_targetimages_key']."' ondblclick='editTitle(".$row['serv_targetimages_key'].")'>" . $row['name'] . "</td>";
// Description. If longer than $max_len characters, display as tooltip:
if (strlen($row['description']) <= $max_len)
echo "<td>" . $row['description'] . "</td>";
echo "<td id='desc".$row['serv_targetimages_key']."' ondblclick='editDesc(".$row['serv_targetimages_key'].")'>" . $row['description'] . "</td>";
else
echo "<td class='qtip_show' title='" . $row['description'] . "'>" . substr($row['description'], 0, $max_len) . "...</td>";
echo "<td class='qtip_show' title='" . $row['description'] . "' id='desc".$row['serv_targetimages_key']."' ondblclick='editDesc(".$row['serv_targetimages_key'].")'>" . substr($row['description'], 0, $max_len) . "...</td>";
// Platform. If longer than $max_len characters, display as tooltip:
$corenum = in_array($row['platform_name'], $multicore)?': '.$row['core_desc']:'';
echo "<td class='qtip_show' title='" . $row['platform_name'] .$corenum. "'>" . $row['platform_name'] .$corenum. "</td>";
......@@ -170,6 +211,8 @@
</tbody>
</table>
<br />
<br />
<i>Note: you can edit the test title and description with a double click.</i>
<?php
}
?>
......
......@@ -200,6 +200,8 @@
newtitle = $("#newtitle" + editingTitle).val();
if (confirm("save changes?")) {
$.post("api.php", "s=title&id=" + editingTitle + "&val=" + newtitle, function() { location.reload(); });
} else {
$("#title" + editingTitle).text(newtitle);
}
editingTitle = 0;
}
......@@ -207,6 +209,8 @@
newdesc = $("#newdesc" + editingDesc).val();
if (confirm("save changes?")) {
$.post("api.php", "s=desc&id=" + editingDesc + "&val=" + newdesc, function() { location.reload(); });
} else {
$("#desc" + editingDesc).text(newdesc);
}
editingDesc = 0;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment