*********************************************************/ // this should include all sites that the user owns as well. $userOwnedSlots = slot::getSlotInfoWhereUserOwner($_GET['user']); if (!array_key_exists($_GET['user'], $userOwnedSlots)) { $userOwnedSlots[$_GET['user']] = array(); $userOwnedSlots[$_GET['user']]['slot_name'] = $_GET['user']; $userOwnedSlots[$_GET['user']]['slot_type'] = 'personal'; $userOwnedSlots[$_GET['user']]['slot_owner'] = $_GET['user']; $userOwnedSlots[$_GET['user']]['site_exits'] = false; } // Add any user-owned groups that aren't already in the slot list $userOwnedGroups = group::getGroupsOwnedBy($_GET['user']); foreach ($userOwnedGroups as $classSiteName) { if (!isset($userOwnedSlots[$classSiteName])) { $userOwnedSlots[$classSiteName] = array(); $userOwnedSlots[$classSiteName]['slot_name'] = $classSiteName; $userOwnedSlots[$classSiteName]['slot_type'] = 'class'; $userOwnedSlots[$classSiteName]['slot_owner'] = $_GET['user']; $userOwnedSlots[$classSiteName]['site_exits'] = false; } } $siteLevelEditorSites = segue::getSiteInfoWhereUserIsSiteLevelEditor($_GET['user']); if (!is_array($siteLevelEditorSites)) { $siteLevelEditorSites = array(); } // $anyLevelEditorSites = segue::getSiteInfoWhereUserIsEditor($_GET['user']); $allSlots = array_merge($userOwnedSlots, $userOwnedGroups, $siteLevelEditorSites); foreach ($allSlots as $slotInfo) { printSlotLine($slotInfo); } print "\n</slotList>";
print "background-color: #F33;"; $cantmovehere = 1; if ($siteObj->sections[$_REQUEST['section']]->pages[$_REQUEST['page']]->getField("type") != "page") { $cantmovereason = "This is not a page which you can {$actionlc} this story to."; } else { $cantmovereason = "You do not have permission to {$actionlc} this story here."; } } } if ($siteObj->sections[$_REQUEST['section']]->pages[$_REQUEST['page']]->id == $_SESSION['origPage']) { print "font-weight: bold;"; } print "'>"; foreach ($siteObj->sections[$_REQUEST['section']]->pages as $p => $v) { $title = $siteObj->sections[$_REQUEST['section']]->pages[$p]->getField("title"); $title = segue::cropString($title, 25); print "<option value='{$p}'"; print $siteObj->sections[$_REQUEST['section']]->pages[$p]->id == $_REQUEST['page'] ? " selected" : ""; print " style='"; print !$siteObj->sections[$_REQUEST['section']]->pages[$p]->movePermission($_REQUEST['action'], $_SESSION['auser'], $_SESSION['origSite'], $_SESSION['type']) || $siteObj->sections[$_REQUEST['section']]->pages[$p]->id == $_SESSION['origPage'] && $_REQUEST['action'] == "MOVE" ? "background-color: #F33;" : "background-color: #FFF;"; if ($siteObj->sections[$_REQUEST['section']]->pages[$p]->id == $_SESSION['origPage']) { print "font-weight: bold;"; } else { print "font-weight: normal;"; } print "'>{$title}\n"; } print "</select>"; } else { print "No Pages."; $cantmovehere = 1;
/** * Build an array of all of the sites and slots that the user * is either the owner of or an editor (has permission add, edit, and delete) of */ function allSitesSlots($user) { global $classes, $usersFutureClasses; $allsites = array(); // The user's personal site if ($user == slot::getOwner($user) || !slot::exists($user)) { $allsites[$user] = array(); $allsites[$user]['slot_name'] = $user; $allsites[$user]['slot_type'] = 'personal'; $allsites[$user]['owner_uname'] = $user; $allsites[$user]['site_exits'] = false; } // Add slots that the user is an owner of. // This will include all of the created sites as well $allsites = array_merge($allsites, $slots); // Add the sites that the user is a Site-Level Editor for. $allsites = array_merge($allsites, segue::getSiteInfoWhereUserIsSiteLevelEditor($user)); $sitesEditorOf = segue::getSiteInfoWhereUserIsSiteLevelEditor($user); $usersAllClasses = array(); if ($_SESSION[atype] == 'prof') { foreach ($classes as $n => $v) { $usersAllClasses[] = $n; } foreach ($usersFutureClasses as $n => $v) { $usersAllClasses[] = $n; } } printpre($allsites); printpre($usersAllClasses); printpre($sitesEditorOf); printpre($sitesOwnerOf); printpre($slots); $allsites = array_unique(array_merge($allsites, $usersAllClasses, $sitesOwnerOf, $sitesEditorOf, $slots)); $allGroups = group::getGroupsOwnedBy($user); $sitesInGroups = array(); foreach ($allGroups as $n => $g) { $sitesInGroups = array_unique(array_merge($sitesInGroups, group::getClassesFromName($g))); } foreach ($allsites as $n => $site) { if (!in_array($site, $sitesInGroups)) { $allsites2[] = $site; } } $allsites = array_merge($allsites2, $allGroups); asort($allsites); /* print "<pre>"; print_r($usersAllClasses); print "</pre>"; */ $sites = array(); $slots = array(); foreach ($allsites as $n => $site) { $siteObj =& new site($site); $exists = $siteObj->fetchFromDB(); if ($exists) { $sites[] = $site; } else { $slots[] = $site; } } return array($sites, $slots); }
function getSlotInfoForSlots($slotNameArray) { global $dbhost, $dbuser, $dbpass, $dbdb; $ar = array(); if (!count($slotNameArray)) { return $ar; } $query = "\n\t\t\tSELECT\n\t\t\t\tslot_name,\n\t\t\t\tslot_type,\n\t\t\t\tslot_owner.user_uname AS owner_uname,\n\t\t\t\t(site_id IS NOT NULL) AS site_exists,\n\t\t\t\tsite_title,\n\t\t\t\t(classgroup_id IS NOT NULL) AS is_classgroup,\n\t\t\t\tcreatedby.user_uname AS site_addedby,\n\t\t\t\tsite_created_tstamp,\n\t\t\t\teditedby.user_uname AS site_editedby,\n\t\t\t\tsite_updated_tstamp,\n\t\t\t\tsite_activate_tstamp,\n\t\t\t\tsite_deactivate_tstamp,\n\t\t\t\t(\tsite_active = '1'\n\t\t\t\t\tAND (site_activate_tstamp = '00000000000000'\n\t\t\t\t\t\tOR site_activate_tstamp < CURRENT_TIMESTAMP())\n\t\t\t\t\tAND (site_deactivate_tstamp = '00000000000000'\n\t\t\t\t\t\tOR site_deactivate_tstamp > CURRENT_TIMESTAMP())\n\t\t\t\t) AS is_active\n\t\t\tFROM\n\t\t\t\tslot\n\t\t\t\t\tINNER JOIN\n\t\t\t\t\t\tuser AS slot_owner ON (\n\t\t\t\t\t\t\t\t\t\t\t\tslot.FK_owner = slot_owner.user_id\n\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t\t("; $i = 0; foreach ($slotNameArray as $slot) { $query .= "\t\t\t\t\t\t\t\t\t\t"; if ($i > 0) { $query .= "OR "; } $query .= "slot.slot_name = '" . addslashes($slot) . "'"; $i++; } $query .= "\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\tLEFT JOIN\n\t\t\t\tsite ON slot.FK_site = site_id\n\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t\tuser AS createdby ON site.FK_createdby = createdby.user_id\n\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t\tuser AS editedby ON site.FK_updatedby = editedby.user_id\n\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t\tclassgroup ON slot_name = classgroup_name\n\t\t\tGROUP BY\n\t\t\t\tslot_name\n\t\t\t\t\t"; $r = db_query($query); if (db_num_rows($r)) { while ($a = db_fetch_assoc($r)) { segue::addRowToSiteInfoArray($ar, $a); } } return $ar; }
function getSiteInfoWhereUserOwner($user = '') { global $dbhost, $dbuser, $dbpass, $dbdb; if ($user == '') { $user = $_SESSION[auser]; } $query = "\n\t\t\tSELECT\n\t\t\t\tslot_name,\n\t\t\t\tslot_type,\n\t\t\t\tslot_owner.user_uname AS owner_uname,\n\t\t\t\t(site_id IS NOT NULL) AS site_exists,\n\t\t\t\tsite_title,\n\t\t\t\t(classgroup_id IS NOT NULL) AS is_classgroup,\n\t\t\t\tcreatedby.user_uname AS site_addedby,\n\t\t\t\tsite_created_tstamp,\n\t\t\t\teditedby.user_uname AS site_editedby,\n\t\t\t\tsite_updated_tstamp,\n\t\t\t\tsite_activate_tstamp,\n\t\t\t\tsite_deactivate_tstamp,\n\t\t\t\t(\tsite_active = '1'\n\t\t\t\t\tAND (site_activate_tstamp = '00000000000000'\n\t\t\t\t\t\tOR site_activate_tstamp < CURRENT_TIMESTAMP())\n\t\t\t\t\tAND (site_deactivate_tstamp = '00000000000000'\n\t\t\t\t\t\tOR site_deactivate_tstamp > CURRENT_TIMESTAMP())\n\t\t\t\t) AS is_active\n\t\t\tFROM\n\t\t\t\tslot\n\t\t\t\t\tINNER JOIN\n\t\t\t\t\t\tuser AS slot_owner ON (\n\t\t\t\t\t\t\t\t\t\t\t\tslot.FK_owner = slot_owner.user_id\n\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t\tslot_owner.user_uname = '" . addslashes($user) . "'\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\tINNER JOIN\n\t\t\t\tsite ON slot.FK_site = site_id\n\t\t\t\t\tINNER JOIN\n\t\t\t\t\t\tuser AS createdby ON site.FK_createdby = createdby.user_id\n\t\t\t\t\tINNER JOIN\n\t\t\t\t\t\tuser AS editedby ON site.FK_updatedby = editedby.user_id\n\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t\tclassgroup ON slot_name = classgroup_name\n\t\t\tGROUP BY\n\t\t\t\tslot_name\n\t\t"; $r = db_query($query); if (db_num_rows($r)) { while ($a = db_fetch_assoc($r)) { segue::addRowToSiteInfoArray($ar, $a); } } return $ar; }
function insertDB($down = 0, $newsite = null, $newsection = 0, $newpage = 0, $removeOrigional = 0, $keepaddedby = 0, $keepDiscussions = 0, $storyTags = null) { $origsite = $this->owning_site; $origid = $this->id; if ($newsite) { $this->owning_site = $newsite; unset($this->owningSiteObj); } if ($newsection) { $this->owning_section = $newsection; unset($this->owningSectionObj); } if ($newpage) { $this->owning_page = $newpage; unset($this->owningPageObj); } $this->fetchUp(1); /********************************************************* * Re-Key the ordering of the rest of the stories in the * section to make sure that there are no holes *********************************************************/ foreach ($this->owningPageObj->getField("stories") as $order => $storyId) { $query = "UPDATE\n\t\t\t\t\tstory\n\t\t\t\tSET\n\t\t\t\t\tstory_order = '" . addslashes($order) . "'\n\t\t\t\tWHERE\n\t\t\t\t\tstory_id = '" . $storyId . "'"; // printpre($query); db_query($query); } // if moving to a new site, copy the media if ($origsite != $this->owning_site && $down) { $images = array(); if ($this->getField("type") == "image" || $this->getField("type") == "rss" || $this->getField("type") == "file") { $media_id = $this->getField("longertext"); $this->setField("longertext", copy_media($media_id, $newsite)); } else { if ($this->getField("type") == "story") { // These do some moving of files based on a ####id##### syntax // for storing inline images. // Adam 2005-06-27: I don't believe that these were ever used, but // I'll leave them here so as not to break any old data that uses them. $ids = segue::getMediaIDs("shorttext"); segue::replaceMediaIDs($ids, "shorttext", $newsite); $ids = segue::getMediaIDs("longertext"); segue::replaceMediaIDs($ids, "longertext", $newsite); // Search for and copy images that use the "[[mediapath]]/filename.ext" // syntax. preg_match_all("/\\[\\[mediapath\\]\\]\\/([^'\"]+)/", $this->getField("shorttext") . $this->getField("longertext"), $matches); $fnames = array_unique($matches[1]); foreach ($fnames as $fname) { copy_media_with_fname($fname, $origsite, $newsite); } } } } $a = $this->createSQLArray(1); if (!$keepaddedby) { $a[] = "FK_createdby='" . addslashes($_SESSION[aid]) . "'"; $a[] = $this->_datafields[addedtimestamp][1][0] . "=NOW()"; $a[] = "FK_updatedby='" . addslashes($_SESSION[aid]) . "'"; } else { $a[] = "FK_createdby=" . db_get_value("user", "user_id", "user_uname='" . addslashes($this->getField("addedby")) . "'"); $a[] = $this->_datafields[addedtimestamp][1][0] . "='" . addslashes($this->getField("addedtimestamp")) . "'"; $a[] = "FK_updatedby=" . db_get_value("user", "user_id", "user_uname='" . addslashes($this->getField("editedby")) . "'"); $a[] = $this->_datafields[editedtimestamp][1][0] . "='" . addslashes($this->getField("editedtimestamp")) . "'"; } // insert media (url) if ($this->data[url] && ($this->data['type'] == 'link' || $this->data['type'] == 'rss')) { // first see, if media item already exists in media table $query = "\n\t\t\t\tSELECT\n\t\t\t\t\tmedia_id\n\t\t\t\tFROM\n\t\t\t\t\tmedia\n\t\t\t\tWHERE\n\t\t\t\t\tFK_site = '" . addslashes($this->owningSiteObj->id) . "' AND\n\t\t\t\t\tFK_createdby = '" . addslashes($_SESSION[aid]) . "' AND\n\t\t\t\t\tmedia_tag = '" . addslashes($this->data[url]) . "' AND\n\t\t\t\t\tmedia_location = 'remote'\n\t\t\t"; $r = db_query($query); // if not in media table insert it if (!db_num_rows($r)) { $query = "\n\t\t\t\t\tINSERT INTO \n\t\t\t\t\t\tmedia\n\t\t\t\t\tSET\n\t\t\t\t\t\tFK_site = '" . addslashes($this->owningSiteObj->id) . "',\n\t\t\t\t\t\tFK_createdby = '" . addslashes($_SESSION[aid]) . "',\n\t\t\t\t\t\tmedia_tag = '" . addslashes($this->data[url]) . "',\n\t\t\t\t\t\tmedia_location = 'remote',\n\t\t\t\t\t\tFK_updatedby = '" . addslashes($_SESSION[aid]) . "'\n\t\t\t\t"; db_query($query); $a[] = "FK_media=" . lastid(); } else { $arr = db_fetch_assoc($r); $a[] = "FK_media='" . addslashes($arr[media_id]) . "'"; } } $query = "INSERT INTO story SET " . implode(",", $a); db_query($query); $this->id = lastid(); /****************************************************************************** * get story text, convert wiki links to internal links ******************************************************************************/ // $text = $this->getField("shorttext"); // $text = convertWikiMarkupToLinks($this->owning_site, $this->owning_section, $this->owning_page, $this->id, "page", $text); // $text = recordInternalLinks ($_SESSION[settings][site],$_SESSION[settings][section],$_SESSION[settings][page], $page_title, $text); // $shorttext = convertInteralLinksToTags($this->owning_site, $text); // $text = $this->getField("longertext"); // $text = convertWikiMarkupToLinks($this->owning_site, $this->owning_section, $this->owning_page, $this->id, "page", $text); // $text = recordInternalLinks ($_SESSION[settings][site],$_SESSION[settings][section],$_SESSION[settings][page], $page_title, $text); // $longertext = convertInteralLinksToTags($this->owning_site, $text); // update table with new short and long text // $query = "UPDATE // story // SET // story_text_short ='".addslashes($shorttext)."', // story_text_long ='".addslashes($longertext)."' // WHERE // story_id ='".addslashes($this->id)."' // "; // // db_query($query); // // See if there is a site hash (meaning that we are being copied). // If so, try to match our id with the hash entry for 'NEXT'. if ($GLOBALS['__site_hash']['stories'] && ($oldId = array_search('NEXT', $GLOBALS['__site_hash']['stories']))) { $GLOBALS['__site_hash']['stories'][$oldId] = $this->id; } $this->fetchUp(); /* $this->owningPageObj->addStory($this->id); */ if ($removeOrigional) { $this->owningPageObj->delStory($origid, 0); $this->owningPageObj->updateDB(); } /****************************************************************************** * update the page updated timestamp ******************************************************************************/ $query = "\n\t\t\t\tUPDATE \n\t\t\t\t\tpage \n\t\t\t\tSET \n\t\t\t\t\tpage_updated_tstamp = NOW()\n\t\t\t\tWHERE \n\t\t\t\t\tpage_id='" . addslashes($this->getField("page_id")) . "'\n\t\t\t"; db_query($query); /****************************************************************************** * Update version table ******************************************************************************/ save_version($this->getField("shorttext"), $this->getField("longertext"), $this->id, $this->version_comments); // add new permissions entry.. force update $this->updatePermissionsDB(1); if ($keepDiscussions && $this->fetcheddown && $this->data[discussions]) { $idMapping = array(); $discussionData = array(); // The discussions objects are way to f****d up to use to copy the // posts so we are going to have to do this 'maunally'. // Fetch all of the discussling data foreach ($this->data[discussions] as $discussionId) { // Get all the posts and dump their properties into an array. $query = "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\t*\n\t\t\t\t\tFROM\n\t\t\t\t\t\tdiscussion\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tdiscussion_id='" . addslashes($discussionId) . "'"; $r = db_query($query); $discussionData[$discussionId] = db_fetch_assoc($r); } // Insert new posts, pointing to the new story foreach (array_keys($discussionData) as $oldId) { // Insert the post $query = "INSERT INTO\n\t\t\t\t\t\tdiscussion\n\t\t\t\t\tSET"; // Set the FK_story to our new story ID $discussionData[$oldId]['FK_story'] = $this->id; // Add the rest of the fields. $i = 0; foreach ($discussionData[$oldId] as $field => $val) { if ($field != 'discussion_id' && $val) { $query .= "\n\t" . ($i == 0 ? "" : ", ") . $field . "='" . addslashes($val) . "'"; $i++; } } $r = db_query($query); // store the id mapping $idMapping[$oldId] = lastid(); if ($GLOBALS['__site_hash']['discussions']) { $GLOBALS['__site_hash']['discussions'][$oldId] = lastid(); } } // go through and update all of the FK_parents to point to the new Ids. // Also, rebuild the discussions array in case we try to access it after // the copy. $this->data[discussions] = array(); foreach (array_keys($discussionData) as $oldId) { $newId = $idMapping[$oldId]; $this->data[discussions][] = $newId; // If we were a reply, update our parent key if ($discussionData[$oldId]['FK_parent']) { $query = "\n\t\t\t\t\t\tUPDATE\n\t\t\t\t\t\t\tdiscussion\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\tFK_parent = '" . addslashes($idMapping[$discussionData[$oldId]['FK_parent']]) . "',\n\t\t\t\t\t\t\tdiscussion_tstamp = '" . addslashes($discussionData[$oldId]['discussion_tstamp']) . "'\n\t\t\t\t\t\t\t\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tdiscussion_id = '" . addslashes($newId) . "'\n\t\t\t\t\t"; // printpre($query); $res = db_query($query); } } } // Update any story tags if (is_array($storyTags)) { save_record_tags($storyTags, null, $this->id, $_SESSION[aid], "story"); } return true; }
function addClasses($classes) { if (is_array($classes)) { $classes2 = array(); foreach ($classes as $n => $class) { if (segue::siteExists($class)) { if (!segue::siteExists($this->name)) { $siteObj =& new site($class); $siteObj->fetchDown(1); $siteObj->copySite($this->name, FALSE, TRUE); $siteObj =& new site($class); $siteObj->fetchDown(1); $siteObj->delete(); $classes2[] = $class; } else { error("You can not add an existing site to a group that already has a site created"); } } else { $classes2[] = $class; } } $this->classes = array_unique(array_merge($this->classes, $classes2)); } }