/**
 * This function will insert a single page into the community_pages table if
 * it is an active page.
 * @param ADONewConnection $db The database connection
 * @param array $page An array containing a single row from the community_pages table.
 * @param integer $new_community_id The id of the new community.
 * @param integer $proxy_id The integer representation of the user inserting the page
 * 							(found in the medtech_auth.user_data table.
 * @return the cpage_id of the inserted page.
 */
function insert_community_page($db, $page, $new_community_id, $proxy_id)
{
    //Insert new page if it is active
    if ($page["page_active"] != 0) {
        //if this is a default page make it a course page so that it cannot be removed.
        if (strcmp($page["page_type"], "default") == 0) {
            $page["page_type"] = "course";
        }
        //check the page content for intra-community URL's and rename for the new community
        $query = "\tSELECT *\n\t\t\tFROM " . DATABASE_NAME . ".`communities`\n\t\t\tWHERE `community_id` = " . $db->qstr($new_community_id);
        $community = $db->GetRow($query);
        $page["page_content"] = str_replace("pgme_generic", $community["community_shortname"], $page["page_content"]);
        $page["page_content"] = str_replace("pgme_rheumatology", $community["community_shortname"], $page["page_content"]);
        //if there is an image file on this page find the old photo id and replace with new one
        $pos1 = strpos($page["page_content"], "view-photo&id=");
        if (is_int($pos1) && $pos1 !== 0) {
            $pos2 = strpos($page["page_content"], "&", $pos1 + 18);
            $old_photo_id = substr($page["page_content"], $pos1 + 18, $pos2 - ($pos1 + 18));
            $new_photo_id = find_photo_id($db, $old_photo_id, $new_community_id);
            if ($new_photo_id > 0) {
                $old_page = $page["page_content"];
                $page["page_content"] = str_replace("view-photo&id=" . $old_photo_id, "view-photo&id=" . $new_photo_id, $page["page_content"]);
                if (strcmp($old_page, $page["page_content"]) == 0) {
                    output_error("String replace failed for the photo ID.");
                }
            } else {
                output_notice("New photo ID not found.");
            }
        }
        $query = "\tINSERT INTO " . DATABASE_NAME . ".`community_pages`\n\t\t\t\t\t\t(`community_id`,\n\t\t\t\t\t\t`parent_id`,\n\t\t\t\t\t\t`page_order`,\n\t\t\t\t\t\t`page_type`,\n\t\t\t\t\t\t`menu_title`,\n\t\t\t\t\t\t`page_title`,\n\t\t\t\t\t\t`page_url`,\n\t\t\t\t\t\t`page_content`,\n\t\t\t\t\t\t`page_active`,\n\t\t\t\t\t\t`page_visible`,\n\t\t\t\t\t\t`allow_member_view`,\n\t\t\t\t\t\t`allow_troll_view`,\n\t\t\t\t\t\t`allow_public_view`,\n\t\t\t\t\t\t`updated_date`,\n\t\t\t\t\t\t`updated_by`)\n\t\t\t\t\t\tVALUES(\n\t\t\t\t\t\t" . $db->qstr($new_community_id) . ",\n\t\t\t\t\t\t" . $db->qstr($page["parent_id"]) . ",\n\t\t\t\t\t\t" . $db->qstr($page["page_order"]) . ",\n\t\t\t\t\t\t" . $db->qstr($page["page_type"]) . ",\n\t\t\t\t\t\t" . $db->qstr($page["menu_title"]) . ",\n\t\t\t\t\t\t" . $db->qstr($page["page_title"]) . ",\n\t\t\t\t\t\t" . $db->qstr($page["page_url"]) . ",\n\t\t\t\t\t\t" . $db->qstr($page["page_content"]) . ",\n\t\t\t\t\t\t" . $db->qstr($page["page_active"]) . ",\n\t\t\t\t\t\t" . $db->qstr($page["page_visible"]) . ",\n\t\t\t\t\t\t" . $db->qstr($page["allow_member_view"]) . ",\n\t\t\t\t\t\t" . $db->qstr($page["allow_troll_view"]) . ",\n\t\t\t\t\t\t" . $db->qstr($page["allow_public_view"]) . ",\n\t\t\t\t\t\t" . $db->qstr(time()) . ",\n\t\t\t\t\t\t" . $db->qstr($proxy_id) . ")";
        if (!$db->Execute($query)) {
            output_error("There was a problem while inserting page " . $page["cpage_id"] . " into the new community where Community ID is (" . $new_community_id . "). Database said: " . $db->ErrorMsg());
        }
        $new_cpage_id = $db->Insert_Id();
        return $new_cpage_id;
    }
}
Esempio n. 2
0
 /**
  * See ADONewConnection::qstr()
  *
  * @access  public
  * @param   mixed
  * @return  mixed
  */
 public function _quote($str)
 {
     return $this->db->qstr($str, CONTREXX_ESCAPE_GPC);
 }