1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +02:00
Daniel Neto 2025-01-03 19:05:10 -03:00
parent 3b90d31087
commit 9f9c6bb74a
3 changed files with 15 additions and 6 deletions

View file

@ -913,16 +913,21 @@ class Category
public function delete()
{
global $categoryDeleteMessage;
$categoryDeleteMessage = '';
if (!self::canCreateCategory()) {
$categoryDeleteMessage = 'You cannot delete a category';
return false;
}
if (!self::userCanEditCategory($this->id)) {
$categoryDeleteMessage = 'This category does not belong to you';
return false;
}
// cannot delete default category
if ($this->id == 1) {
$categoryDeleteMessage = 'You cannot delete the main category';
return false;
}
@ -934,9 +939,12 @@ class Category
if ($categories_id) {
$sql = "UPDATE videos SET categories_id = ? WHERE categories_id = ?";
sqlDAL::writeSql($sql, "ii", [$categories_id, $this->id]);
$sql = "UPDATE live_transmitions SET categories_id = ? WHERE categories_id = ?";
sqlDAL::writeSql($sql, "ii", [$categories_id, $this->id]);
}
$sql = "DELETE FROM categories WHERE id = ?";
} else {
$categoryDeleteMessage = 'Id is empty';
return false;
}
self::deleteAssets($this->id);

View file

@ -14,4 +14,7 @@ require_once 'category.php';
$obj = new Category($_POST['id']);
$response = $obj->delete();
echo '{"status":"' . $response . '"}';
$resp = array('error'=> empty($response), 'msg'=>$categoryDeleteMessage);
echo json_encode($resp);

View file

@ -397,17 +397,15 @@
modal.showPleaseWait();
$.ajax({
url: '<?php echo $global['webSiteRootURL'] . "objects/categoryDelete.json.php"; ?>',
url: webSiteRootURL+'objects/categoryDelete.json.php',
data: {
"id": row.id
},
type: 'post',
success: function(response) {
if (response.status === "1") {
avideoResponse(response);
if(empty(response.error)){
$("#grid").bootgrid("reload");
avideoToast("<?php echo __("Your category has been deleted!"); ?>");
} else {
avideoAlert("<?php echo __("Sorry!"); ?>", "<?php echo __("Your category has NOT been deleted!"); ?>", "error");
}
modal.hidePleaseWait();
}