die($msg); } // Confirm no cloned pages exist if ($rs[0]['clonable']) { $rs2 = $DB->select(K_TBL_PAGES, array('*'), "template_id='" . $DB->sanitize($tpl_id) . "'"); if (count($rs2)) { die('Template has existing cloned pages'); } } else { // delete default page for the template $PAGE = new KWebpage($tpl_id, null); if ($PAGE->error) { ob_end_clean(); die('ERROR: ' . $PAGE->err_msg); } $PAGE->delete(); } // remove template along with the fields and folders defined for it $rs = $DB->delete(K_TBL_TEMPLATES, "id='" . $DB->sanitize($tpl_id) . "'"); if ($rs == -1) { die("ERROR: Unable to delete template from K_TBL_TEMPLATES"); } $rs = $DB->delete(K_TBL_FIELDS, "template_id='" . $DB->sanitize($tpl_id) . "'"); if ($rs == -1) { die("ERROR: Unable to delete template data from K_TBL_FIELDS"); } $rs = $DB->delete(K_TBL_FOLDERS, "template_id='" . $DB->sanitize($tpl_id) . "'"); if ($rs == -1) { die("ERROR: Unable to delete template data from K_TBL_FOLDERS"); } // HOOK: template_deleted
function db_delete($params, $node) { global $FUNCS, $DB, $CTX; if (count($node->children)) { die("ERROR: Tag \"" . $node->name . "\" is a self closing tag"); } // handle params extract($FUNCS->get_named_vars(array('masterpage' => '', 'page_id' => '', 'invalidate_cache' => '0'), $params)); $masterpage = trim($masterpage); if (!$masterpage) { die("ERROR: Tag \"" . $node->name . "\": 'masterpage' attribute missing"); } $page_id = isset($page_id) && $FUNCS->is_non_zero_natural($page_id) ? (int) $page_id : null; if (!$page_id) { die("ERROR: Tag \"" . $node->name . "\": 'page_id' required"); } // get down to business $rs = $DB->select(K_TBL_TEMPLATES, array('id', 'clonable'), "name='" . $DB->sanitize($masterpage) . "'"); if (!count($rs)) { die("ERROR: Tag \"" . $node->name . "\" - masterpage does not exist"); } if (!$rs[0]['clonable']) { die("ERROR: Tag \"" . $node->name . "\" - cannot delete non-clonable template"); } $pg = new KWebpage($rs[0]['id'], $page_id); if ($pg->error) { die("ERROR: Tag \"" . $node->name . "\" - " . $pg->err_msg); } // delete.. $pg->delete(); // if we are here, delete was successful (script would have died otherwise) $pg->destroy(); unset($pg); if ($invalidate_cache) { $FUNCS->invalidate_cache(); } }
if ($FUNCS->is_non_zero_natural($v)) { $draft_id = intval($v); if (!$tpl_id) { $rs = $DB->select(K_TBL_PAGES, array('template_id'), "id = '" . $DB->sanitize($draft_id) . "'"); $_tpl_id = $rs[0]['template_id']; } else { $_tpl_id = $tpl_id; } $PAGE = new KWebpage($_tpl_id, $draft_id); if ($PAGE->error) { ob_end_clean(); die('ERROR in deletion: ' . $PAGE->err_msg); } // execute action if ($_POST['bulk-action'] == 'delete') { $PAGE->delete(1); } elseif ($_POST['bulk-action'] == 'apply') { $DB->begin(); $res = $PAGE->update_parent(); if ($FUNCS->is_error($res)) { ob_end_clean(); die($res->err_msg); } $PAGE->delete(1); $DB->commit(1); } } } } } // list all available drafts