function AdkDownloadDeleteCategory() { global $context, $smcFunc, $boarddir, $adkFolder; //Check the session checkSession('get'); //Get id_cat if (!empty($_REQUEST['id']) && is_numeric($_REQUEST['id'])) { $id_cat = (int) $_REQUEST['id']; } else { fatal_lang_error('adkfatal_invalid_id_category', false); } //Get All id_files of this category $sql = $smcFunc['db_query']('', ' SELECT id_file FROM {db_prefix}adk_down_file WHERE id_cat = {int:cat}', array('cat' => $id_cat)); while ($row = $smcFunc['db_fetch_assoc']($sql)) { $files[] = $row['id_file']; } $smcFunc['db_free_result']($sql); //Get all attachments... and delete it (if this category has a download if (!empty($files)) { $get = $smcFunc['db_query']('', 'SELECT filename FROM {db_prefix}adk_down_attachs WHERE id_file IN ({array_int:file})', array('file' => $files)); while ($row = $smcFunc['db_fetch_assoc']($get)) { if (file_exists($adkFolder['eds'] . '/' . $row['filename'])) { @unlink($adkFolder['eds'] . '/' . $row['filename']); } } $smcFunc['db_free_result']($get); //Delete attachs deleteEntry('adk_down_attachs', 'id_file IN ({array_int:files})', array('files' => $files)); //Delete downloads deleteEntry('adk_down_file', 'id_cat = {int:cat}', array('cat' => $id_cat)); } //Update row orders $sql = $smcFunc['db_query']('', 'SELECT roworder FROM {db_prefix}adk_down_cat WHERE id_cat = {int:cat}', array('cat' => $id_cat)); list($roworder) = $smcFunc['db_fetch_row']($sql); $smcFunc['db_free_result']($sql); $smcFunc['db_query']('', 'UPDATE {db_prefix}adk_down_cat SET roworder = roworder - 1 WHERE roworder > {int:roworder}', array('roworder' => $roworder)); //Finally... delete category deleteEntry('adk_down_cat', 'id_cat = {int:cat}', array('cat' => $id_cat)); //Set an error of this categorys setCategoryError($id_cat); redirectexit('action=admin;area=adkdownloads;sa=allcategories;' . $context['session_var'] . '=' . $context['session_id']); }
function setCategoryError($id_cat) { global $smcFunc; //Set the error to the subcategories $smcFunc['db_query']('', 'UPDATE {db_prefix}adk_down_cat SET error = {int:error} WHERE id_parent = {int:cat}', array('error' => 1, 'cat' => $id_cat)); //But maybe... this sub categories has a sub sub category.... please check it $sql = $smcFunc['db_query']('', ' SELECT id_cat FROM {db_prefix}adk_down_cat WHERE id_parent = {int:cat}', array('cat' => $id_cat)); while ($row = $smcFunc['db_fetch_assoc']($sql)) { //Set again setCategoryError($row['id_cat']); } $smcFunc['db_free_result']($sql); }