/** * 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; } }
} else { output_error("[Row " . $row_count . "]\tUnable to insert community_members record for proxy_id [" . $proxy_id . "] and application_id [" . AUTH_APP_ID . "]. Database said: " . $db->ErrorMsg()); } } else { output_error("[Row " . $row_count . "]\tUnable to insert user_access record for proxy_id [" . $proxy_id . "] and application_id [" . AUTH_APP_ID . "]. Database said: " . $db->ErrorMsg()); } } else { output_error("[Row " . $row_count . "]\tUnable to insert user_data record for staff / student number [" . $user["number"] . "]. Database said: " . $db->ErrorMsg()); } } } else { output_error("[Row " . $row_count . "]\tThe provided community_id [" . $user["community_id"] . "] does not exist or is not active in the CSV file."); } } } else { output_notice("[Row " . $row_count . "]\tStaff / student number [" . $user["number"] . "] does not have a valid e-mail address."); } } } fclose($handle); } else { output_error("Unable to open the provided CSV file [" . $CSV_FILE . "]."); } break; case "-usage": default: echo "\nUsage: import-community-guests.php [options] /path/to/import-file.csv"; echo "\n -usage Brings up this help screen."; echo "\n -emailadminimport Proceeds with import to database, but e-mails notifications are sent to admin vs. user."; echo "\n -emailskipimport Proceeds with import to database, but e-mails notifications are skipped."; echo "\n -validate Goes through the import file and validates the data.";
$group = $db->GetRow("SELECT * FROM `groups` WHERE `group_id` = " . $db->qstr($GROUP_ID)); while (!$group) { print "\nPlease ensure you enter a valid Group ID: " . $db->ErrorMsg(); fscanf(STDIN, "%d\n", $GROUP_ID); // reads number from STDIN $group = $db->GetRow("SELECT * FROM `groups` WHERE `group_id` = " . $db->qstr($GROUP_ID)); } print "\nPlease enter Community ID: "; fscanf(STDIN, "%d\n", $COMMUNITY_ID); // reads number from STDIN $result = $db->GetRow("SELECT * FROM `communities` WHERE `community_id` = " . $db->qstr($COMMUNITY_ID)); while (!$result) { print "\nPlease ensure you enter a valid Community ID: "; fscanf(STDIN, "%d\n", $COMMUNITY_ID); // reads number from STDIN $result = $db->GetRow("SELECT * FROM `communities` WHERE `community_id` = " . $db->qstr($COMMUNITY_ID)); } output_notice("Step 2: The group members will be synced with the community."); $group_members = "SELECT `proxy_id` FROM `group_members` WHERE `group_id` = " . $db->qstr($GROUP_ID); $new_community_members = array(); foreach ($group_members as $gmember) { if (!($community_members = "SELECT `proxy_id` FROM `community_members` WHERE `community_id` = " . $db->qstr($COMMUNITY_ID) . " AND `proxy_id` = " . $db->qstr($gmember['proxy_id']))) { $new_community_members[] = $gmember['proxy_id']; } } $community_member = array('community_id' => $COMMUNITY_ID, 'member_active' => 1, 'member_joined' => time(), 'member_acl' => 0); foreach ($new_community_members as $member) { $community_member['proxy_id'] = $member; $db->AutoExecute('community_members', $community_member, 'INSERT'); } print "\n\n";