/** * Delete a category, and all sub-categories, and all ads * * @param integer $id Category ID to delete * @return boolean True on success, False on failure */ public static function Delete($id) { global $_TABLES, $_CONF_ADVT; $id = (int) $id; // find all sub-categories of this one and delete them. $sql = "SELECT cat_id FROM {$_TABLES['ad_category']} \n WHERE papa_id={$id}"; $result = DB_query($sql); if ($result) { while ($row = DB_fetcharray($result)) { if (!adCategory::Delete($row['cat_id'])) { return false; } } } // now delete any ads associated with this category $sql = "SELECT ad_id FROM {$_TABLES['ad_ads']} \n WHERE cat_id={$id}"; $result = DB_query($sql); if ($result) { while ($row = DB_fetcharray($result)) { if (adDelete($row['ad_id'], true) != 0) { return false; } } } // Delete this category // First, see if there's an image to delete $img_name = DB_getItem($_TABLES['ad_category'], 'image', "cat_id={$id}"); if ($img_name != '' && file_exists($this->imgPath . $img_name)) { unlink($this->imgPath . $img_name); } DB_delete($_TABLES['ad_category'], 'cat_id', $id); // If we made it this far, must have worked ok return true; }
break; } switch ($actionval) { case 'cat': if (isset($_POST['cat_id'])) { $cat_id = (int) $_POST['cat_id']; } elseif (isset($_GET['cat_id'])) { $cat_id = (int) $_GET['cat_id']; } else { $cat_id = 0; } if ($cat_id > 0) { //USES_classifieds_categories(); //catDelete($_REQUEST['cat_id']); USES_classifieds_class_category(); adCategory::Delete($_REQUEST['cat_id']); $view = 'admin'; } break; case 'ad': default: if ($type == 'submission' || $type == 'editsubmission' || $type == 'moderate') { CLASSIFIEDS_auditLog("Deleting submission {$ad_id}"); adDelete($ad_id, true, 'ad_submission'); $view = 'moderation'; } else { adDelete($ad_id, true); $view = 'admin'; $actionval = 'ad'; } break;