USER_MOD)
{
message($lang_common['No permission']);
}
else if ($forum_user['g_id'] < USER_GUEST)
{
$result = $db->query('SELECT group_id FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result))
{
message($lang_common['Bad request']);
}
if ($configuration['p_mod_edit_users'] == '0' || $db->result($result) < USER_GUEST)
{
$EXPERTISE_VIEWER = "regular";
}
else
{
$EXPERTISE_VIEWER = "moderator";
}
}
}
else
{
$EXPERTISE_VIEWER = "self";
}
$result = $db->query('SELECT u.username, u.id, u.realname, g.g_id, g.g_user_title FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result)) message($lang_common['Bad request']);
$user = $db->fetch_assoc($result);
if ($_SERVER['REQUEST_METHOD'] == 'GET')
{
if (isset($_GET['tag']))
{
$look_up_this_tag = intval(trim($_GET['tag']));
$users_tagged = array();
$sql = "SELECT l.taggee_id, count(l.taggee_id) as count, u.username FROM ". $db->prefix.'expertise_links' ." l, ".$db->prefix."users u WHERE l.tag_id = ".$look_up_this_tag." AND l.confirmed = '1' AND l.taggee_id = u.id GROUP BY l.taggee_id";
$result = $db->query($sql) or error('Could not get tagged users from table '. $db->prefix.'expertise_links' .'', __FILE__, __LINE__, $db->error()) or die (mysql_error());
while ($row = $db->fetch_assoc($result))
{
$users_tagged[$row['taggee_id']]['taggee_id'] = $row['taggee_id'];
$users_tagged[$row['taggee_id']]['count'] = $row['count'];
$users_tagged[$row['taggee_id']]['username'] = $row['username'];
}
$sql = "SELECT name FROM ". $db->prefix.'expertise_tags' ." WHERE id = ".$look_up_this_tag."";
$result = $db->query($sql) or error('Could not get tag name from table '. $db->prefix.'expertise_tags' .'', __FILE__, __LINE__, $db->error());
while ($row = $db->fetch_assoc($result))
{
$tag_of_interest = $row['name'];
}
}
$expertise_tags = array();
$sql = "SELECT DISTINCT t.id, t.name FROM ". $db->prefix.'expertise_tags' ." t, ". $db->prefix.'expertise_links' ." l WHERE (l.tagger_id = ". $user['id'] ." OR l.taggee_id = ". $user['id'] .") AND t.id = l.tag_id";
$result = $db->query($sql) or error('Could not get tag data from tables '. $db->prefix.'expertise_tags' . ' and '. $db->prefix.'expertise_links' .'', __FILE__, __LINE__, $db->error());
while ($row = $db->fetch_assoc($result))
{
$expertise_tags[$row['id']] = $row['name'];
}
$expertise_users = array();
$sql = "SELECT DISTINCT u.id, u.username FROM ".$db->prefix."users u, ". $db->prefix.'expertise_links' ." l WHERE (l.taggee_id = ". $user['id'] .") AND u.id = l.tagger_id";
$result = $db->query($sql) or error('Could not get tagging users data from tables users and '. $db->prefix.'expertise_links' .'', __FILE__, __LINE__, $db->error());
while ($row = $db->fetch_assoc($result))
{
$expertise_users[$row['id']] = $row['username'];
}
$expertise_incoming = array();
$sql = 'SELECT tagger_id, tag_id, taggee_id, confirmed FROM ' . $db->prefix.'expertise_links' . ' WHERE taggee_id = ' . $user['id'];
$result = $db->query($sql) or error('Could not get tagger data from table '. $db->prefix.'expertise_links' . '', __FILE__, __LINE__, $db->error());
while ($row = $db->fetch_assoc($result))
{
$expertise_incoming[$row['tagger_id']][] = $row;
}
$expertise_self = array();
$sql = 'SELECT tagger_id, tag_id, taggee_id FROM ' . $db->prefix.'expertise_links' . ' WHERE taggee_id = ' . $user['id'] . ' AND tagger_id = ' . $user['id'];
$result = $db->query($sql) or error('Could not get self-tagging data from table '. $db->prefix.'expertise_links' . '', __FILE__, __LINE__, $db->error());
while ($row = $db->fetch_assoc($result))
{
array_push($expertise_self, $row['tag_id']);
}
$expertise_allothers = array();
$sql = "SELECT tag_id, count(tag_id) as howmany FROM ". $db->prefix.'expertise_links' ." WHERE taggee_id = '".$user['id']."' AND confirmed = '1' GROUP BY tag_id ORDER BY howmany DESC";
$result = $db->query($sql) or error('Could not get all-others data from table '. $db->prefix.'expertise_links' . '', __FILE__, __LINE__, $db->error());
while ($row = $db->fetch_assoc($result))
{
$expertise_allothers[$row['tag_id']] = $row['howmany'];
}
$page_title = convert_htmlspecialchars($configuration['o_board_title'])." (Powered By WWWThreads Forums)".' / '.$lang_common['Profile'];
require FORUM_ROOT.'header.php';
// if ($EXPERTISE_VIEWER == "self" || $EXPERTISE_VIEWER == "moderator")
generate_profile_menu('expertise');
?>
\n";
?>
$two)
{
$new_tags[$two] = rtrim($two, ",");
if ($new_tags[$two] == ""){unset($new_tags[$two]);}
}
$old_tags = array();
$sql = "SELECT DISTINCT t.id, t.name FROM ". $db->prefix.'expertise_tags' ." t, ". $db->prefix.'expertise_links' ." l WHERE (l.tagger_id = ". $user['id'] ." AND l.taggee_id = ". $user['id'] .") AND t.id = l.tag_id";
$result = $db->query($sql) or error('Could not get tag data from tables '. $db->prefix.'expertise_tags' . ' and '. $db->prefix.'expertise_links' .'', __FILE__, __LINE__, $db->error());
while ($row = $db->fetch_assoc($result))
{
$old_tags[$row['id']] = $row['name'];
}
foreach ($old_tags as $one => $two)
{
if (in_array($two,$new_tags))
{
unset($new_tags[$two]);
}
else
{
$sql = "DELETE FROM " . $db->prefix.'expertise_links' . " WHERE tag_id = " . intval($one) . " AND " . " tagger_id = " . intval($id) . " AND " . " taggee_id = " . intval($id);
$result = $db->query($sql) or error('Could not delete a self tag from table ' . $db->prefix.'expertise_links' . '', __FILE__, __LINE__, $db->error());
}
}
foreach ($new_tags as $one => $two)
{
$sql = "INSERT IGNORE INTO " . $db->prefix.'expertise_tags' . " SET name='$two'";
$result = $db->query($sql) or error('Could not insert a new tag 1 into table ' . $db->prefix.'expertise_tags' . '', __FILE__, __LINE__, $db->error());
$sql = "SELECT id, name FROM " . $db->prefix.'expertise_tags' . " WHERE name = '$two'";
$result = $db->query($sql) or error('Could not get tag id from table '. $db->prefix.'expertise_tags' . '', __FILE__, __LINE__, $db->error());
while ($row = $db->fetch_assoc($result))
{
$fresh_id = $row['id'];
}
$sql = "INSERT IGNORE INTO " . $db->prefix.'expertise_links' . " SET tagger_id='$id', taggee_id='$id', tag_id='$fresh_id', confirmed='1', created_at=now(), confirmed_at=now()";
$result = $db->query($sql) or error('Could not insert a new link into table ' . $db->prefix.'expertise_links' . '', __FILE__, __LINE__, $db->error());
}
$old_confirmations = array();
$sql = 'SELECT tagger_id, tag_id, confirmed FROM ' . $db->prefix.'expertise_links' . ' WHERE taggee_id = ' . $user['id'];
$result = $db->query($sql) or error('Could not get confirmation data from table '. $db->prefix.'expertise_links' . '', __FILE__, __LINE__, $db->error());
while ($row = $db->fetch_assoc($result))
{
$old_confirmations[$row['tagger_id']][$row['tag_id']] = $row['confirmed'];
}
$new_confirmations = $_POST['confirmation'];
foreach ($old_confirmations as $from_user => $from_tags)
{
if ($id != $from_user)
{
foreach ($from_tags as $tagno => $confirmed)
{
$new_confirmations[$from_user][$tagno] = isset($new_confirmations[$from_user][$tagno]) ? $new_confirmations[$from_user][$tagno] : 0;
if ($confirmed == $new_confirmations[$from_user][$tagno])
{
unset($new_confirmations[$from_user][$tagno]);
}
else
{
$toggled = ($confirmed == "1") ? 0 : 1;
if ($toggled == 1){ $new_confirm = ", confirmed_at = now() ";}
$update_confirm = ($toggled == 1) ? "now() " : "NULL";
$sql = "UPDATE " . $db->prefix.'expertise_links' . " SET " . "confirmed = $toggled" . " , confirmed_at = $update_confirm" . " WHERE tagger_id = " . intval($from_user) . " AND " . " tag_id = " . intval($tagno) . " AND " . " taggee_id = " . intval($id);
$result = $db->query($sql) or error('Could not update confirmation data from table ' . $db->prefix.'expertise_links' . '', __FILE__, __LINE__, $db->error());
}
}
}
}
$new_deletions = $_POST['delete_tag'];
foreach ($new_deletions as $one => $two)
{
foreach ($two as $deletetagid => $trash)
{
$sql = "DELETE FROM " . $db->prefix.'expertise_links' . " WHERE tag_id = " . intval($deletetagid) . " AND " . " tagger_id = " . intval($one) . " AND " . " taggee_id = " . intval($forum_user['id']);
$result = $db->query($sql) or error('Could not delete a granted tag from table ' . $db->prefix.'expertise_links' . '', __FILE__, __LINE__, $db->error());
}
}
}
else if (isset($_POST['grant_expertise']))
{
if (isset($_POST['grant_self_expertise'])){
$grant_self_expertise = addslashes($_POST['grant_self_expertise']);
$grant_self_expertise = trim($grant_self_expertise);
$split_tags = preg_split("/[\s]+/", $grant_self_expertise);
if ($split_tags[0] == ""){unset($split_tags);}
foreach ($split_tags as $one => $two)
{
$new_tags[$two] = rtrim($two, ",");
if ($new_tags[$two] == ""){unset($new_tags[$two]);}
}
$old_tags = array();
$sql = "SELECT DISTINCT t.id, t.name FROM ". $db->prefix.'expertise_tags' ." t, ". $db->prefix.'expertise_links' ." l WHERE (l.tagger_id = ". $user['id'] ." AND l.taggee_id = ". $user['id'] .") AND t.id = l.tag_id";
$result = $db->query($sql) or error('Could not get tag data from tables '. $db->prefix.'expertise_tags' . ' and '. $db->prefix.'expertise_links' .'', __FILE__, __LINE__, $db->error());
while ($row = $db->fetch_assoc($result))
{
$old_tags[$row['id']] = $row['name'];
}
foreach ($old_tags as $one => $two)
{
if (in_array($two,$new_tags))
{
unset($new_tags[$two]);
}
else
{
$sql = "DELETE FROM " . $db->prefix.'expertise_links' . " WHERE tag_id = " . intval($one) . " AND " . " tagger_id = " . intval($id) . " AND " . " taggee_id = " . intval($id);
$result = $db->query($sql) or error('Could not delete a self tag from table ' . $db->prefix.'expertise_links' . '', __FILE__, __LINE__, $db->error());
}
}
foreach ($new_tags as $one => $two)
{
$sql = "INSERT IGNORE INTO " . $db->prefix.'expertise_tags' . " SET name='$two'";
$result = $db->query($sql) or error('Could not insert a new tag woot into table ' . $db->prefix.'expertise_tags' . '', __FILE__, __LINE__, $db->error());
$sql = "SELECT id, name FROM " . $db->prefix.'expertise_tags' . " WHERE name = '$two'";
$result = $db->query($sql) or error('Could not get tag id from table '. $db->prefix.'expertise_tags' . '', __FILE__, __LINE__, $db->error());
while ($row = $db->fetch_assoc($result))
{
$fresh_id = $row['id'];
}
$sql = "INSERT IGNORE INTO " . $db->prefix.'expertise_links' . " SET tagger_id='$id', taggee_id='$id', tag_id='$fresh_id', confirmed='1', created_at=now(), confirmed_at=now()";
$result = $db->query($sql) or error('Could not insert a new link into table ' . $db->prefix.'expertise_links' . '', __FILE__, __LINE__, $db->error());
}
}
$new_deletions = $_POST['delete_tag'];
foreach ($new_deletions as $one => $two)
{
$sql = "DELETE FROM " . $db->prefix.'expertise_links' . " WHERE tag_id = " . intval($one) . " AND " . " tagger_id = " . intval($forum_user['id']) . " AND " . " taggee_id = " . intval($id);
$result = $db->query($sql) or error('Could not delete a granted tag from table ' . $db->prefix.'expertise_links' . '', __FILE__, __LINE__, $db->error());
}
unset($new_tags);
unset($old_tags);
unset($split_tags);
$grant_expertise = addslashes($_POST['grant_expertise']);
$grant_expertise = trim($grant_expertise);
$split_tags = preg_split("/[\s]+/", $grant_expertise);
if ($split_tags[0] == ""){unset($split_tags);}
foreach ($split_tags as $one => $two)
{
$new_tags[$two] = rtrim($two, ",");
if ($new_tags[$two] == ""){unset($new_tags[$two]);}
}
$old_tags = array();
$sql = "SELECT DISTINCT t.id, t.name FROM ". $db->prefix.'expertise_tags' ." t, ". $db->prefix.'expertise_links' ." l WHERE (l.tagger_id = ". $forum_user['id'] ." AND l.taggee_id = ". $user['id'] .") AND t.id = l.tag_id";
$result = $db->query($sql) or error('Could not get tag data from tables '. $db->prefix.'expertise_tags' . ' and '. $db->prefix.'expertise_links' .'', __FILE__, __LINE__, $db->error());
while ($row = $db->fetch_assoc($result))
{
$old_tags[$row['id']] = $row['name'];
}
foreach ($old_tags as $one => $two)
{
if (in_array($two,$new_tags))
{
unset($new_tags[$two]);
}
}
foreach ($new_tags as $one => $two)
{
$sql = "INSERT IGNORE INTO " . $db->prefix.'expertise_tags' . " SET name='$two'";
$result = $db->query($sql) or error('Could not insert a new tag 2 into table ' . $db->prefix.'expertise_tags' . '', __FILE__, __LINE__, $db->error());
$sql = "SELECT id, name FROM " . $db->prefix.'expertise_tags' . " WHERE name = '$two'";
$result = $db->query($sql) or error('Could not get tag id from table '. $db->prefix.'expertise_tags' . '', __FILE__, __LINE__, $db->error());
while ($row = $db->fetch_assoc($result))
{
$fresh_id = $row['id'];
}
$sql = "INSERT IGNORE INTO " . $db->prefix.'expertise_links' . " SET tagger_id='".$forum_user['id']."', taggee_id='".$user['id']."', tag_id='$fresh_id', created_at=now()";
$result = $db->query($sql) or error('Could not insert a new link into table ' . $db->prefix.'expertise_links' . '', __FILE__, __LINE__, $db->error());
}
}
if ($EXPERTISE_VIEWER == "self")
{
redirect('expertise.php?id='.$id, $lang_expertise['Self - Update']);
}
else
{
redirect('expertise.php?id='.$id, $lang_expertise['Another - Update']);
}
}
?>