function create_trait($profile_id, $trait_id, $trait_type, $trait_value, $trait_discrete) { global $connection; $statement = $connection->prepare("select count(*) from traits where active=1 and type=? and value=?"); $statement->bindValue(1, $trait_type, PDO::PARAM_STR); $statement->bindValue(2, $trait_value, PDO::PARAM_STR); $statement->execute(); if (!$statement->fetchColumn()) { $rank = fetch_rank($trait_id); $statement = $connection->prepare("insert into traits (owner, type, value, rank, discrete) values (?, ?, ?, ?, ?)"); $statement->bindValue(1, $profile_id, PDO::PARAM_INT); $statement->bindValue(2, $trait_type, PDO::PARAM_STR); $statement->bindValue(3, $trait_value, PDO::PARAM_STR); $statement->bindValue(4, $rank, PDO::PARAM_INT); $statement->bindValue(5, $trait_discrete, PDO::PARAM_BOOL); $statement->execute(); } else { echo "0 There is already a trait with that value registered for that person."; } }
/** * Any checks to run immediately before saving. If returning false, the save will not take place. * * @param boolean Do the query? * * @return boolean True on success; false if an error occurred */ function pre_save($doquery = true) { if ($this->presave_called !== null) { return $this->presave_called; } // USERGROUP CHECKS $usergroups_changed = $this->usergroups_changed(); if ($usergroups_changed) { // VALIDATE USERGROUPID / MEMBERGROUPIDS $usergroupid = $this->fetch_field('usergroupid'); $membergroupids = $this->fetch_field('membergroupids'); if (strpos(",{$membergroupids},", ",{$usergroupid},") !== false) { // usergroupid/membergroups conflict $this->error('usergroup_equals_secondary'); return false; } // if changing usergroups, validate the displaygroup $displaygroupid = $this->fetch_field('displaygroupid'); $this->verify_displaygroupid($displaygroupid); // this will edit the value if necessary $this->do_set('displaygroupid', $displaygroupid); } if ($this->condition) { $wasadmin = $this->is_admin($this->existing['usergroupid'], $this->existing['membergroupids']); $isadmin = $this->is_admin($this->fetch_field('usergroupid'), $this->fetch_field('membergroupids')); // if usergroups changed, check we are not de-admining the last admin if ($usergroups_changed and $wasadmin and !$isadmin and $this->count_other_admins($this->existing['userid']) == 0) { $this->error('cant_de_admin_last_admin'); return false; } $updateinfractions = false; // primary usergroup change, update infractions if (isset($this->user['usergroupid']) and ($usergroupid = $this->user['usergroupid']) != $this->existing['usergroupid'] and $this->existing['ipoints'] > 0) { $ipoints = $this->existing['ipoints']; $updateinfractions = true; } else { if (is_int($this->user['ipoints']) and $this->user['ipoints'] != $this->existing['ipoints']) { $updateinfractions = true; $ipoints = $this->user['ipoints']; } } if ($updateinfractions) { // If user groups aren't changed, then $usergroupid is not set.... if (empty($usergroupid)) { $usergroupid = $this->fetch_field('usergroupid'); } $infractiongroups = array(); $infractiongroupid = 0; $groups = $this->registry->db->query_read_slave("\n\t\t\t\t\tSELECT orusergroupid, override\n\t\t\t\t\tFROM " . TABLE_PREFIX . "infractiongroup AS infractiongroup\n\t\t\t\t\tWHERE infractiongroup.usergroupid IN (-1, {$usergroupid})\n\t\t\t\t\t\tAND infractiongroup.pointlevel <= {$ipoints}\n\t\t\t\t\tORDER BY pointlevel\n\t\t\t\t"); while ($group = $this->registry->db->fetch_array($groups)) { if ($group['override']) { $infractiongroupid = $group['orusergroupid']; } $infractiongroups["{$group['orusergroupid']}"] = true; } $this->set('infractiongroupids', !empty($infractiongroups) ? implode(',', array_keys($infractiongroups)) : ''); $this->set('infractiongroupid', $infractiongroupid); } } // Attempt to detect if we need a new rank or usertitle if ($this->rawfields['posts']) { // posts = posts + 1 / posts - 1 was specified so we need existing posts to determine how many posts we will have if ($this->existing['posts'] != null) { $posts = $this->existing['posts'] + preg_replace('#^.*posts\\s*([+-])\\s*(\\d+?).*$#sU', '\\1\\2', $this->fetch_field('posts')); } } else { if ($this->fetch_field('posts') !== null) { $posts = $this->fetch_field('posts'); } } if (($this->setfields['membergroupids'] or $this->setfields['posts'] or $this->setfields['usergroupid'] or $this->setfields['displaygroupid']) and !$this->setfields['rank'] and isset($posts) and $userid = $this->fetch_field('userid')) { // item affecting user's rank is changing and a new rank hasn't been given to us $userinfo = array('userid' => $userid, 'posts' => $posts); if (($userinfo['usergroupid'] =& $this->fetch_field('usergroupid')) !== null and ($userinfo['displaygroupid'] =& $this->fetch_field('displaygroupid')) !== null and ($userinfo['membergroupids'] =& $this->fetch_field('membergroupids')) !== null) { require_once DIR . '/includes/functions_ranks.php'; $userrank =& fetch_rank($userinfo); if ($userrank != $this->existing['rank']) { $this->setr('rank', $userrank); } } } $return_value = true; ($hook = vBulletinHook::fetch_hook('userdata_presave')) ? eval($hook) : false; $this->presave_called = $return_value; return $return_value; }
$userupdates["{$promotion['userid']}"]['title'] = $title; } else { break; } } } } $user['displaygroupid'] = $user['displaygroupid'] == $user['usergroupid'] ? $joinusergroupid : $user['displaygroupid']; $user['usergroupid'] = $joinusergroupid; } else { $secondaryupdates["{$joinusergroupid}"] .= ",{$promotion['userid']}"; $secondarynames["{$joinusergroupid}"] .= iif($secondarynames["{$joinusergroupid}"], ", {$promotion['username']}", $promotion['username']); $user['membergroupids'] .= ($user['membergroupids'] != '' ? ',' : '') . $joinusergroupid; } require_once DIR . '/includes/functions_ranks.php'; $userrank =& fetch_rank($user); if ($promotion['rank'] != $userrank) { $userupdates["{$promotion['userid']}"]['rank'] = $userrank; } } } } if (!empty($primaryupdates)) { $infractiongroupids = array(); $groups = $vbulletin->db->query_read("\n\t\tSELECT usergroupid, orusergroupid, pointlevel, override\n\t\tFROM " . TABLE_PREFIX . "infractiongroup AS infractiongroup\n\t\tWHERE usergroupid IN (-1," . implode(',', array_keys($primaryupdates)) . ")\n\t\tORDER BY pointlevel\n\t"); while ($group = $vbulletin->db->fetch_array($groups)) { $infractiongroupids["{$group['usergroupid']}"]["{$group['pointlevel']}"] = array('orusergroupid' => $group['orusergroupid'], 'override' => $group['override']); } foreach (array_keys($primaryupdates) as $usergroupid) { if (empty($infractiongroupids["{$usergroupid}"])) { $infractiongroupids["{$usergroupid}"] = array();