1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +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() public function delete()
{ {
global $categoryDeleteMessage;
$categoryDeleteMessage = '';
if (!self::canCreateCategory()) { if (!self::canCreateCategory()) {
$categoryDeleteMessage = 'You cannot delete a category';
return false; return false;
} }
if (!self::userCanEditCategory($this->id)) { if (!self::userCanEditCategory($this->id)) {
$categoryDeleteMessage = 'This category does not belong to you';
return false; return false;
} }
// cannot delete default category // cannot delete default category
if ($this->id == 1) { if ($this->id == 1) {
$categoryDeleteMessage = 'You cannot delete the main category';
return false; return false;
} }
@ -934,9 +939,12 @@ class Category
if ($categories_id) { if ($categories_id) {
$sql = "UPDATE videos SET categories_id = ? WHERE categories_id = ?"; $sql = "UPDATE videos SET categories_id = ? WHERE categories_id = ?";
sqlDAL::writeSql($sql, "ii", [$categories_id, $this->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 = ?"; $sql = "DELETE FROM categories WHERE id = ?";
} else { } else {
$categoryDeleteMessage = 'Id is empty';
return false; return false;
} }
self::deleteAssets($this->id); self::deleteAssets($this->id);

View file

@ -14,4 +14,7 @@ require_once 'category.php';
$obj = new Category($_POST['id']); $obj = new Category($_POST['id']);
$response = $obj->delete(); $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(); modal.showPleaseWait();
$.ajax({ $.ajax({
url: '<?php echo $global['webSiteRootURL'] . "objects/categoryDelete.json.php"; ?>', url: webSiteRootURL+'objects/categoryDelete.json.php',
data: { data: {
"id": row.id "id": row.id
}, },
type: 'post', type: 'post',
success: function(response) { success: function(response) {
if (response.status === "1") { avideoResponse(response);
if(empty(response.error)){
$("#grid").bootgrid("reload"); $("#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(); modal.hidePleaseWait();
} }