Commit c78db823 authored by jlopez's avatar jlopez
Browse files

Fix delete and download container

parent ee8ea03d
......@@ -89,7 +89,30 @@ if($action == "create") {
$container->escape($db);
$db->update($container);
} else if ($action == "delete") {
$db->delete($container);
$cnt = $db->getContainerWithId($container->ID);
if($cnt->author == $author) {
$db->delete($container);
}
} else if($action == "download") {
$cnt = $db->getContainerWithId($container->ID);
if(($cnt->author == $author) || ($container->visibility == 0)) {
$content = $cnt->value;
$name = $cnt->name;
$file = fopen($name,"wb");
fwrite($file);
fclose($file);
header('Content-Type: charset=utf-8');
header("Content-disposition: attachment; filename=$name");
print $content;
}
}
header("Location: ../container.php");
//header("Location: ../container.php");
......@@ -157,16 +157,16 @@ $containers = $db->getContainers();
echo '<td>';
echo '<div class="btn-group" mr-3><a class="btn btn-success btn-sm" href="#" >show</a></div>';
//echo '<div class="btn-group" mr-3><a class="btn btn-success btn-sm" href="#" >show</a></div>';
echo '<div class="btn-group" mr-3><a class="btn btn-primary btn-sm" href="#" >dowload</a></div>';
echo '<div class="btn-group" mr-3><a class="btn btn-primary btn-sm" href="./action/action_container.php?action=download&containerid='.$container->ID.'">dowload</a></div>';
if($container->author == $_SESSION['username'] || $_SESSION['manage'] ) {
echo '<div class="btn-group mr-3"><a class="btn btn-danger btn-sm" href="#" >delete</a></div>';
echo '<div class="btn-group mr-3"><a class="btn btn-danger btn-sm" href="./action/action_container.php?action=delete&containerid='.$container->ID.'" >delete</a></div>';
}
echo '</div></td>';
echo '</td>';
echo '</tr>';
}
......@@ -184,14 +184,12 @@ $containers = $db->getContainers();
</div>
<!-- jQuery Version 1.11.1 -->
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script >
<script type="text/javascript">
</script>
</body>
......
......@@ -70,4 +70,8 @@
.badge {
margin-right: 5px;
}
.btn-group > .btn:first-child {
margin-left: 5px !important;
}
\ No newline at end of file
......@@ -170,6 +170,17 @@ class DBquery
return $results;
}
public function getContainerWithId($id) {
$sql = "SELECT * FROM `Container` WHERE `ID` = '$id';";
$result = mysqli_query($this->dbh, $sql);
$results = array();
while($row = mysqli_fetch_assoc($result)){
$cnt = new Container($row['ID'], $row['name'], $row['value'], $row['type'], $row['visibility'], $row['description'], $row['author'], $row['date']);
return $cnt;
}
return $results;
}
public function getLabels() {
$sql = "SELECT * FROM `Label`;";
$result = mysqli_query($this->dbh, $sql);
......
......@@ -134,6 +134,24 @@ $( "#generateButton" ).click(function() {
}
});
function downloadFile2(name, value) {
var filename = name;
var isSingularity = document.getElementById("singularityRadio").checked;
var text = value;
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
function downloadFile() {
if(PREVIEW !== "") {
......
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