/** * Function will delete all pages below the specified parent_id. * * @param int $parent_id * @return true */ function communities_pages_delete($cpage_id = 0, $exclude_ids = array()) { global $db, $COMMUNITY_ID; static $level = 0; if ($level > 99) { application_log("error", "Stopped an infinite loop in the communities_pages_delete() function."); return false; } if ($cpage_id = (int) $cpage_id) { if (!is_array($exclude_ids) || !in_array($cpage_id, $exclude_ids)) { $query = "SELECT `cpage_id` FROM `community_pages` WHERE `community_id` = " . $db->qstr($COMMUNITY_ID) . " AND `page_active` = '1' AND `parent_id` = " . $db->qstr($cpage_id); $results = $db->GetAll($query); if ($results) { foreach ($results as $result) { if (!is_array($exclude_ids) || !in_array($result["cpage_id"], $exclude_ids)) { $level++; communities_pages_delete($result["cpage_id"], $exclude_ids); } } } $query = "UPDATE `community_pages` SET `page_active` = '0', `page_url` = CONCAT(`page_url`, '.trash') WHERE `cpage_id` = " . $db->qstr($cpage_id) . " AND `community_id` = " . $db->qstr($COMMUNITY_ID) . " AND `page_url` != ''"; if (!$db->Execute($query)) { application_log("error", "Unable to deactivate cpage_id [" . $cpage_id . "] from community_id [" . $COMMUNITY_ID . "]. Database said: " . $db->ErrorMsg()); } else { communities_deactivate_history($COMMUNITY_ID, $cpage_id, 0); } } } return true; }
} $i++; } } } if (!$pages) { header("Location: " . COMMUNITY_URL . $community_details["community_url"] . ":pages"); exit; } break; } // Display Page switch ($STEP) { case 2: foreach ($pages as $page) { communities_pages_delete($page["CPAGE_ID"]); $query = "SELECT `cpage_id`, `page_order` FROM `community_pages` WHERE `community_id` = " . $db->qstr($COMMUNITY_ID) . " AND `parent_id` = " . $db->qstr($parent_id) . " AND `page_order` > " . $db->qstr($page_order); $moving_pages = $db->GetAll($query); if ($moving_pages) { foreach ($moving_pages as $moving_page) { $query = "UPDATE `community_pages` SET `page_order` = " . $db->qstr($moving_page["page_order"] - 1) . " WHERE `cpage_id` = " . $db->qstr($moving_page["cpage_id"]); $db->Execute($query); } } } header("Location: " . COMMUNITY_URL . $community_details["community_url"] . ":pages"); exit; break; case 1: default: if ($ERROR) {