Example #1
0
             $ERRORSTR[] = "There was a problem updating the 'allow non-member posts' option for the home page of the community. Please contact the application administrator and inform them of this error.";
             application_log("error", "There was an error updating this page option. Database said: " . $db->ErrorMsg());
         }
     } else {
         if (!$ERROR) {
             $url = ENTRADA_URL . "/community" . $community_details["community_url"] . ":pages";
             $SUCCESS++;
             $SUCCESSSTR[] = "You have successfully updated the home page of the community.<br /><br />You will now be redirected to the page management index; this will happen <strong>automatically</strong> in 5 seconds or <a href=\"" . $url . "\" style=\"font-weight: bold\">click here</a> to continue.";
             $HEAD[] = "<script type=\"text/javascript\"> setTimeout('window.location=\\'" . $url . "\\'', 5000); </script>";
             application_log("success", "Home Page [" . $PAGE_ID . "] updated in the system.");
         }
     }
 } else {
     communities_log_history($COMMUNITY_ID, $PAGE_ID, 0, "community_history_edit_page", 1);
     if ($PROCESSED["menu_title"] != $page_details["menu_title"]) {
         communities_set_children_urls($PAGE_ID, $PROCESSED["page_url"]);
     }
     if (isset($PROCESSED["page_order"]) && $PROCESSED["page_order"] != $page_details["page_order"]) {
         /**
          * Go through this process the second time to ensure each page is in the correct order.
          */
         $query = "SELECT `cpage_id`, `page_order` FROM `community_pages` WHERE `community_id` = " . $db->qstr($COMMUNITY_ID) . " AND `parent_id` = " . $db->qstr($PROCESSED["parent_id"]) . " AND `page_url` != '' ORDER BY `page_order` ASC";
         $results = $db->GetAll($query);
         if ($results) {
             foreach ($results as $key => $result) {
                 $order = $key;
                 if ((int) $order != (int) $result["page_order"]) {
                     $query = "UPDATE `community_pages` SET `page_order` = " . $db->qstr($order) . " WHERE `cpage_id` = " . $db->qstr($result["cpage_id"]);
                     if (!$db->Execute($query)) {
                         application_log("error", "Unable to update the page order of page_id " . $result["page_id"]);
                     }
/**
 * This function recieves a page URL and ID from a community page that has been
 * moved from its' current location and sets the children of that page to have
 * the correct URL based on their new location.
 *
 * @param int $parent_id
 * @param string $parent_url
 */
function communities_set_children_urls($parent_id, $parent_url)
{
    global $ERROR, $ERRORSTR, $COMMUNITY_RESERVED_PAGES, $db;
    $child_data = array();
    $query = "SELECT * FROM `community_pages` WHERE `parent_id` = " . $db->qstr($parent_id) . " AND `page_active` = '1'";
    $child_records = $db->GetAll($query);
    if ($child_records) {
        foreach ($child_records as $child_record) {
            $page_url = clean_input($child_record["menu_title"], array("lower", "underscores", "page_url"));
            $page_url = $parent_url . "/" . $page_url;
            if (in_array($page_url, $COMMUNITY_RESERVED_PAGES)) {
                $ERROR++;
                $ERRORSTR[] = "The <strong>Menu Title</strong> you have chosen is reserved, please try again.";
            } else {
                $child_data["page_url"] = $page_url;
                $query = "SELECT * FROM `community_pages` WHERE `page_url` = " . $db->qstr($child_data["page_url"], get_magic_quotes_gpc()) . " AND `page_active` = '1' AND `community_id` = " . $db->qstr($child_record["community_id"]) . " AND `cpage_id` != " . $db->qstr($child_record["cpage_id"]);
                $result = $db->GetRow($query);
                if ($result) {
                    $ERROR++;
                    $ERRORSTR[] = "The new <strong>Page URL</strong> already exists in this community; Page URLs must be unique.";
                } else {
                    if ($db->AutoExecute("community_pages", $child_data, "UPDATE", "cpage_id = " . $child_record["cpage_id"])) {
                        if ($db->GetRow("SELECT * FROM `community_pages` WHERE `parent_id` = " . $db->qstr($child_record["cpage_id"]))) {
                            communities_set_children_urls($child_record["cpage_id"], $child_data["page_url"]);
                        }
                    } else {
                        $ERROR++;
                        $ERRORSTR[] = "There was an error changing a child page URL. Database said: " . $db->ErrorMsg();
                    }
                }
            }
        }
    }
}