/** * This function deletes all images in a category and the category */ function delete_category() { global $xoopsSecurity; $id = rmc_server_var($_GET, 'id', 0); if (!$xoopsSecurity->check()) { redirectMsg('images.php?action=showcats', __('Operation not allowed!', 'rmcommon'), 1); die; } if ($id <= 0) { redirectMsg('images.php?action=showcats', __('Category ID not provided', 'rmcommon'), 1); die; } $cat = new RMImageCategory($id); if ($cat->isNew()) { redirectMsg('images.php?action=showcats', __('Category not found', 'rmcommon'), 1); die; } $sizes = array(); foreach ($cat->getVar('sizes') as $size) { if ($size['width'] <= 0) { continue; } $sizes[] = '_' . $size['width'] . 'x' . $size['height']; } $db = Database::getInstance(); $sql = "SELECT * FROM " . $db->prefix("rmc_images") . " WHERE cat='" . $cat->id() . "'"; $result = $db->query($sql); while ($row = $db->fetchArray($result)) { $image = new RMImage(); $image->assignVars($row); $updir = XOOPS_UPLOAD_PATH . '/' . date('Y', $image->getVar('date')) . '/' . date('m', time()); $fd = pathinfo($image->getVar('file')); foreach ($sizes as $size) { $file = $updir . '/sizes/' . $fd['filename'] . $size . '.' . $fd['extension']; @unlink($file); } $file = $updir . '/' . $image->getVar('file'); @unlink($file); $image->delete(); } if ($cat->delete()) { redirectMsg('images.php?action=showcats', __('Category deleted successfully!', 'rmcommon'), 0); } else { redirectMsg('images.php?action=showcats', __('Errors ocurred while deleting the category', 'rmcommon') . '<br />' . $cat->errors(), 0); } }