* */ if (!defined("COMMUNITY_INCLUDED") || !defined("IN_SHARES")) { exit; } elseif (!$COMMUNITY_LOAD) { exit; } if ($RECORD_ID) { $query = "\n\t\t\t\t\tSELECT a.*, b.`file_title`, b.`file_active` AS `parent_file_active`\n\t\t\t\t\tFROM `community_share_file_versions` AS a\n\t\t\t\t\tLEFT JOIN `community_share_files` AS b\n\t\t\t\t\tON a.`csfile_id` = b.`csfile_id`\n\t\t\t\t\tLEFT JOIN `community_shares` AS c\n\t\t\t\t\tON a.`cshare_id` = c.`cshare_id`\n\t\t\t\t\tWHERE a.`csfversion_id` = " . $db->qstr($RECORD_ID) . "\n\t\t\t\t\tAND c.`cpage_id` = " . $db->qstr($PAGE_ID) . "\n\t\t\t\t\tAND a.`community_id` = " . $db->qstr($COMMUNITY_ID); $file_record = $db->GetRow($query); if ($file_record) { if ((int) $file_record["file_active"] && (int) $file_record["parent_file_active"]) { if (shares_file_module_access($file_record["csfile_id"], "delete-revision")) { if ($db->AutoExecute("community_share_file_versions", array("file_active" => 0, "updated_date" => time(), "updated_by" => $ENTRADA_USER->getID()), "UPDATE", "`csfversion_id` = " . $db->qstr($RECORD_ID) . " AND `csfile_id` = " . $db->qstr($file_record["csfile_id"]) . " AND `cshare_id` = " . $db->qstr($file_record["cshare_id"]) . " AND `community_id` = " . $db->qstr($COMMUNITY_ID))) { add_statistic("community:" . $COMMUNITY_ID . ":shares", "revision_delete", "csfversion_id", $RECORD_ID); communities_deactivate_history($COMMUNITY_ID, $PAGE_ID, $RECORD_ID); } else { application_log("error", "Failed to deactivate [" . $RECORD_ID . "] file version from community. Database said: " . $db->ErrorMsg()); } } } else { application_log("error", "The provided file revision id [" . $RECORD_ID . "] is already deactivated."); } header("Location: " . COMMUNITY_URL . $COMMUNITY_URL . ":" . $PAGE_URL . "?section=view-file&id=" . $file_record["csfile_id"]); exit; } else { application_log("error", "The provided file revision id [" . $RECORD_ID . "] was invalid."); } } else { application_log("error", "No file revision id was provided for deactivation."); }
/** * 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; }