/** * load in the Activities for the given SQL statement * * @param string $sql * @param array $params the parameters that go into the sql statement * @param String $style (optional - default 'long') may be 'short' or 'long' or 'cif' * @return ActivitySet (this) */ function load($sql, $params, $style = 'long') { global $DB; if (!isset($params)) { $params = array(); } // get records $resArray = $DB->select($sql, $params); if ($resArray !== false) { $count = count($resArray); for ($i = 0; $i < $count; $i++) { $array = $resArray[$i]; $a = new Activity(); $xml = $array['XML']; $activity = $a->load($array['ItemID'], $array['UserID'], $array['Type'], $array['ModificationDate'], $array['ChangeType'], $xml, $style); if (!$activity instanceof Error) { $this->add($a); } } $this->totalno = count($this->activities); } else { return database_error(); } return $this; }
/** * Sets up the default link types for the given user * * @param string $userid * @return true if all went well or Error object */ function setUpDefaultLinkTypes($userid) { global $CFG, $DB, $LNG, $HUB_SQL; //really need to change the way the unique identifier is created. //have increased to 14, but can't go any bigger or ID will exceed limit of 50 chars. $params = array(); $params[0] = $userid; $params[1] = $userid; $params[2] = $CFG->defaultUserID; $res = $DB->insert($HUB_SQL->DATAMODEL_LINKTYPE_UPDATE_DEFAULT_LINKTYPES, $params); if (!$res) { return database_error(); } else { //add the default groupings for these $params = array(); $params[0] = $CFG->defaultUserID; $res2 = $DB->insert($HUB_SQL->DATAMODEL_LINKTYPE_UPDATE_DEFAULT_LINKTYPES_GROUP, $params); if (!$res2) { return database_error(); } } return true; }
function cm_banning() { global $txt, $settings, $username, $REMOTE_ADDR, $db_prefix, $UDB_DB_NAME_PREFIX; // ALL TYPES OF BANNING AT ONCE (SpeedUpBoardIndex mod) $remote_ip = $REMOTE_ADDR; $ipparts = explode(".", $REMOTE_ADDR); $registeredUserString = $username != 'Guest' ? "OR (type='email' AND value='{$settings['2']}') OR (type='username' AND value='{$username}')" : ''; $request = mysql_query("SELECT value FROM {$db_prefix}banned WHERE (type='ip' AND (value='{$remote_ip}' OR value='{$ipparts['0']}.{$ipparts['1']}.{$ipparts['2']}.*' OR value='{$ipparts['0']}.{$ipparts['1']}.*.*')) {$registeredUserString};") or database_error(__FILE__, __LINE__); if (mysql_num_rows($request) != 0) { $registeredUserString2 = $username != 'Guest' ? ',email' : ''; $registeredUserString3 = $username != 'Guest' ? ",'{$settings['2']}'" : ''; $request = mysql_query("INSERT INTO {$db_prefix}log_banned (ip {$registeredUserString2},logTime) VALUES ('{$remote_ip}' {$registeredUserString3}," . time() . ");") or database_error(__FILE__, __LINE__); $username = "******"; cpg_die(ERROR, "You are BANNED, go away!", __FILE__, __LINE__); return; } }
/** * Update the status for this user * * @return User object (this) (or Error object) */ function updateStatus($status) { global $DB, $CFG, $USER, $HUB_SQL, $HUB_CACHE; if (isset($HUB_CACHE)) { $HUB_CACHE->deleteData($this->userid . $this->style); } $dt = time(); $params = array(); $params[0] = $status; $params[1] = $dt; $params[2] = $this->userid; $res = $DB->insert($HUB_SQL->DATAMODEL_USER_STATUS_UPDATE, $params); if (!$res) { return database_error(); } else { $this->status = $status; return $this; } }
/** * Remove the viewnode item and also any related viewconnection items and their connections * return the ViewNode removed or Error; */ function removeNode($nodeid, $userid) { $vn = new ViewNode($this->nodeid, $nodeid, $userid); $vn = $vn->delete(); if (!$vn instanceof Error) { // delete any associated connections. if (!isset($this->connections)) { // load connections $params = array(); $params[0] = $this->nodeid; $resArray = $DB->select($HUB_SQL->DATAMODEL_VIEW_SELECT_CONNECTIONS, $params); if ($resArray !== false) { $count = count($resArray); for ($i = 0; $i < $count; $i++) { $array = $resArray[$i]; $next = new ViewConnection($array['ViewID'], $array['TripleID'], $array['UserID']); $next = $next->load($style); if (!$next instanceof Error) { array_push($this->connections, $next); } } } else { return database_error(); } } $count = count($this->connections); for ($i = 0; $i < $count; $i++) { $viewconnection = $this->connections[$i]; $connection = $viewconnection->connection; $from = $connection->from; $to = $connection->to; if (!$from instanceof Error && !$to instanceof Error) { if ($to->nodeid == $nodeid || $from->nodeid == $nodeid) { $viewconnection->delete(); } } } } return $vn; }
/** * Delete this tag * * @return Result object (or Error object) */ function delete() { global $DB, $CFG, $USER, $HUB_SQL, $HUB_CACHE; try { $this->candelete(); } catch (Exception $e) { return access_denied_error(); } if (isset($HUB_CACHE)) { $HUB_CACHE->deleteData($this->tagid); } $currentuser = ''; if (isset($USER->userid)) { $currentuser = $USER->userid; } $params = array(); $params[0] = $currentuser; $params[1] = $this->tagid; $res = $DB->delete($HUB_SQL->DATAMODEL_TAG_DELETE, $params); if (!$res) { return database_error(); } return new Result("deleted", "true"); }
function delete() { global $DB, $CFG, $USER, $HUB_SQL; try { $this->candelete(); } catch (Exception $e) { return access_denied_error(); } $currentuser = ''; if (isset($USER->userid)) { $currentuser = $USER->userid; } $params = array(); $params[0] = $this->itemid; $params[1] = $currentuser; $res = $DB->delete($HUB_SQL->DATAMODEL_FOLLOW_DELETE, $params); if (!$res) { return database_error(); } $this->load(); return $this; }
/** * Set the privacy setting of this Connection * * @return Connection object (this) (or Error object) */ function setPrivacy($private) { global $DB, $CFG, $USER, $HUB_SQL; //check user owns the Connection try { $this->canedit(); } catch (Exception $e) { return access_denied_error(); } $dt = time(); $params = array(); $params[0] = $private; $params[1] = $dt; $params[2] = $this->connid; $res = $DB->insert($HUB_SQL->DATAMODEL_CONNECTION_PRIVACY_UPDATE, $params); if (!$res) { return database_error(); } return $this->load(); }
/** * Get the connections for the given network search parameters from the given node. * * @param string $nodeid the id of the node to search outward from. * @param string $linklabels the string of link types. * @param string $userid optional for searching only a specified user's data. (only used if scope is 'all') - NOT USED AT PRESENT * @param string $scope (either 'all' or 'my', default 'all') * @param string $linkgroup (optional, either Positive, Negative, or Neutral - default: empty string); * @param integer $depth (optional, 1-7, or 7 for full depth; * @param string $direction (optional, 'outgoing', 'incoming', or 'both - default: 'both', * @param string $labelmatch (optional, 'true', 'false' - default: false; * @param string $nodetypes a comman separated list of the node type names to include in the search. * @param String $style (optional - default 'long') may be 'short' or 'long' * @param integer $status, defaults to 0. (0 - active, 1 - reported, 2 - retired) * @return ConnectionSet or Error */ function getConnectionsByPath($nodeid, $linklabels, $userid, $scope = 'all', $linkgroup = '', $depth = 7, $direction = "both", $labelmatch = 'false', $nodetypes = '', $style = 'long', $status = 0) { global $DB, $USER, $CFG; $searchLinkLabels = ""; $searchLinkLabelsArray = array(); //$searchLinkLabels = getSQLForLinkTypeIDsForLabels(&$searchLinkLabelsArray, $linklabels) if ($linklabels != "" && $linkgroup == "") { $pieces = explode(",", $linklabels); $loopCount = 0; foreach ($pieces as $value) { $searchLinkLabelsArray[$loopCount] = $value; if ($loopCount == 0) { $searchLinkLabels .= "?"; } else { $searchLinkLabels .= ",?"; } $loopCount++; } } $nodeTypeNames = ""; $nodeTypeNamesArray = array(); //$nodeTypeNames = getSQLForNodeTypeIDsForLabels($nodeTypeNamesArray,$nodetypes); if ($nodetypes != "") { $nodeTypeNames = ""; $pieces = explode(",", $nodetypes); $loopCount = 0; foreach ($pieces as $value) { $nodeTypeNamesArray[$loopCount] = $value; if ($loopCount == 0) { $nodeTypeNames .= "?"; } else { $nodeTypeNames .= ",?"; } $loopCount++; } } // GET TEXT FOR PASSED IDEA ID IF REQUIRED $text = ""; if ($labelmatch == 'true') { $params = array(); $params[0] = $nodeid; $qry = $HUB_SQL->APILIB_NODE_NAME_BY_ID_SELECT; $resArray = $DB->select($sql, $params); if ($resArray !== false && count($resArray) > 0) { $text = $resArray[0]['Name']; } else { return database_error(); } } $matchesFound = array(); if ($labelmatch == 'true' && $text != "" || $labelmatch == 'false' && $nodeid != "") { $checkConnections = array(); $matchedConnections = null; if ($labelmatch == 'true') { $nextNodes[0] = $text; } else { $nextNodes[0] = $nodeid; } $matchesFound = searchNetworkConnections($checkConnections, $matchedConnections, $nextNodes, $searchLinkLabels, $searchLinkLabelsArray, $linkgroup, $labelmatch, $depth, 0, $direction, $nodeTypeNames, $nodeTypeNamesArray, $scope, $status); } //return database_error($matchesFound); //print_r($matchesFound); $cs = new ConnectionSet($matchesFound); return $cs->loadConnections($matchesFound, $style); }
/** * Mark that this user was removed from the group by marking thier requested record as reported * Only group admins can run this function. * * @param string $userid of the user to mark as reported * @return Group object (this) */ function reportpendingmember($userid) { global $DB, $CFG, $USER, $HUB_SQL, $LNG; //check user can edit the group if (!$this->isgroupadmin($USER->userid)) { return access_denied_error(); } // check user exists $user = new User($userid); if ($user->load() instanceof Error) { global $ERROR; $ERROR = new error(); return $ERROR->createUserNotFoundError($userid); } // now add the user $params = array(); $params[0] = $USER->userid; $params[1] = time(); $params[2] = $this->groupid; $params[3] = $userid; $res = $DB->insert($HUB_SQL->DATAMODEL_GROUP_JOIN_REPORT, $params); if (!$res) { return database_error(); } return $this; }
/** * Gets the default RoleID for the current user * * @return String of default role id or Error */ function getDefaultRoleID() { global $CFG, $USER, $DB, $HUB_SQL; $currentuser = ''; if (isset($USER->userid)) { $currentuser = $USER->userid; } $params = array(); $params[0] = $currentuser; $params[1] = $CFG->DEFAULT_NODE_TYPE; $resArray = $DB->select($HUB_SQL->DATAMODEL_ROLE_DEFAULT_SELECT, $params); if ($resArray !== false) { $count = count($resArray); if ($count > 0) { for ($i = 0; $i < $count; $i++) { $array = $resArray[$i]; return $array['NodeTypeID']; } } else { // if there is no default role then add one $nr = new Role(); $nr->add($CFG->DEFAULT_NODE_TYPE); return $nr->roleid; } } else { return database_error(); } }
/** * Delete node * * @return ViewNode object that was deleted (or Error object) */ function delete() { global $DB, $CFG, $USER, $HUB_FLM, $HUB_SQL; $this->load(); try { $this->candelete(); } catch (Exception $e) { return access_denied_error(); } $params = array(); $params[0] = $this->viewid; $params[1] = $this->nodeid; $params[2] = $this->userid; $res = $DB->delete($HUB_SQL->DATAMODEL_VIEWNODE_DELETE, $params); if ($res) { auditViewNode($USER->userid, $this->viewid, $this->nodeid, $this->xpos, $this->ypos, $CFG->actionDelete); } else { return database_error(); } return $this; }
/** * Return the list of userids stored for the given obfuscation id * * @param $obfuscationid the obfuscation record id for the user list required. * @return String of comma separated userids stored for the given obfuscation id, or Error object. */ function getObfuscationUsers($obfuscationid) { global $DB, $HUB_SQL; $params = array(); $params[0] = $obfuscationid; $resArray = $DB->select($HUB_SQL->DATAMODEL_UTIL_GET_OBFUSCATION_USERS, $params); $array = array(); if ($resArray !== false) { // should only be one results ever; if ($resArray[0]) { return $resArray[0]['Users']; } else { return database_error(); } } else { return database_error(); } }
/** * Get all the maps that the node with the given nodeid is in * @param nodeid the id of the node to get the maps for. * @return NodeSet a set of the map nodes that the given node is part of. */ function getMapsForNode($nodeid, $start = 0, $max = 20, $orderby = 'date', $sort = 'DESC', $style = 'long') { global $USER, $HUB_SQL, $DB; if (!isset($nodeid) || $nodeid == "") { return database_error(); } $params = array(); $currentuser = ''; if (isset($USER->userid)) { $currentuser = $USER->userid; } $params[0] = $nodeid; $sql = $HUB_SQL->APILIB_MAPS_FOR_NODE_SELECT; // PERMISSIONS //if($scope == 'my'){ // $params[count($params)] = currentuser; // $sql .= $HUB_SQL->APILIB_NODES_PERMISSIONS_MY; //} else { $params[count($params)] = 'N'; $params[count($params)] = $currentuser; $params[count($params)] = $currentuser; $sql .= $HUB_SQL->AND . $HUB_SQL->APILIB_NODES_PERMISSIONS_ALL; //} //error_log("Search=".$sql); $ns = new NodeSet(); return $ns->load($sql, $params, $start, $max, $orderby, $sort, $style); }
function deleteNodeProperty($property) { global $DB, $HUB_SQL, $CFG; try { $this->candelete(); } catch (Exception $e) { return access_denied_error(); } $dt = time(); $params = array(); $params[0] = $this->nodeid; $params[1] = $property; $res = $DB->delete($HUB_SQL->DATAMODEL_NODE_PROPERTY_DELETE, $params); if (!$res) { return database_error(); } else { $temp = $this->load(); auditIdea($USER->userid, $temp->nodeid, $temp->name, $temp->description, $CFG->actionEdit, format_object('xml', $temp)); return $temp; } }
/** * Update the status for this url * * @return URL object (this) (or Error object) */ function updateStatus($status) { global $DB, $CFG, $USER, $HUB_SQL, $HUB_CACHE; // Should this not be checking if can edit? // Maybe used by admin code? in which case should check if admin // What about reporting spam which can be anyone? // only used in Cohere really. //check user can edit the URL or is an admin /*try { $this->canedit(); } catch (Exception $e) { if ($USER->getIsAdmin() != "Y") { return access_denied_error(); } }*/ if (isset($HUB_CACHE)) { $HUB_CACHE->deleteData($this->urlid . $this->style); } $dt = time(); $params = array(); $params[0] = $status; $params[1] = $dt; $params[2] = $this->urlid; $res = $DB->insert($HUB_SQL->DATAMODEL_URL_STATUS_UPDATE, $params); if (!$res) { return database_error(); } return $this->load(); }
/** * Get users registration key */ function getRegistrationKey() { global $DB, $HUB_SQL; $params = array(); $params[0] = $this->authid; $resArray = $DB->select($HUB_SQL->DATAMODEL_USER_AUTH_REGISTRATION_KEY_SELECT, $params); if ($resArray !== false) { $count = count($resArray); if ($count > 0) { return $resArray[0]['RegistrationKey']; } } else { return database_error(); } return ""; }
function loadNegativeConnectionVotes() { global $DB, $USER, $HUB_SQL; //$loggedin = api_check_login(); //if($loggedin instanceof Error){ // return $loggedin; //} $this->negativeconnvoteslist = array(); $params = array(); $params[0] = $this->id; $params[1] = $this->id; $params[2] = 'N'; $resArray = $DB->select($HUB_SQL->DATAMODEL_VOTING_USER_CONN, $params); if ($resArray !== false) { $count = count($resArray); for ($i = 0; $i < $count; $i++) { $array = $resArray[$i]; $vi = new Vote(); $vi->id = $array['ItemID']; $vi->type = $array['VoteType']; $vi->date = $array['CreationDate']; $vi->userid = $array['UserID']; $vi->username = $array['Name']; array_push($this->negativeconnvoteslist, $vi); } } else { return database_error(); } return $this; }
/** * Delete node * * @return Result object (or Error object) */ function delete() { global $DB, $CFG, $USER, $HUB_FLM, $HUB_SQL; $this->load(); try { $this->candelete(); } catch (Exception $e) { return access_denied_error(); } $dt = time(); $params = array(); $params[0] = $this->viewid; $params[1] = $this->userid; $params[2] = $this->connid; $res = $DB->delete($HUB_SQL->DATAMODEL_VIEWCONNECTION_DELETE, $params); if ($res) { // Need to bypass check. // If you can delete the viewconnection you can delete it's underlying connection which needs to be deleted. $xml = format_object('xml', $this->connection); $params = array(); $params[0] = $this->connection->connid; $res2 = $DB->delete($HUB_SQL->DATAMODEL_CONNECTION_DELETE, $params); if ($res2) { auditConnection($USER->userid, $this->connection->connid, "", $this->connection->from->nodeid, $this->connection->to->nodeid, $this->connection->linktype->linktypeid, $this->connection->fromrole->roleid, $this->connection->torole->roleid, $CFG->actionDelete, $xml); } auditViewTriple($USER->userid, $this->viewid, $this->connid, $CFG->actionDelete); } else { return database_error(); } return new Result("deleted", "true"); }