| 1 |
<?php</span> |
|---|
| 2 |
<span class="code-lang">$root_path = './'; |
|---|
| 3 |
require ($root_path . 'include/config.php'); |
|---|
| 4 |
|
|---|
| 5 |
$userdata = session_pagestart($user_ip); |
|---|
| 6 |
init_userprefs($userdata); |
|---|
| 7 |
loggedinorreturn(); |
|---|
| 8 |
|
|---|
| 9 |
$action = request_var('action', '');</span> |
|---|
| 10 |
<span class="code-lang"> |
|---|
| 11 |
if ( $action == 'add' ) { |
|---|
| 12 |
require_once ($root_path . 'include/ajax.php'); |
|---|
| 13 |
$JsHttpRequest = new JsHttpRequest(); |
|---|
| 14 |
|
|---|
| 15 |
$db->sql_return_on_error(true); |
|---|
| 16 |
|
|---|
| 17 |
$current_time = time(); |
|---|
| 18 |
$resp_type = request_var('type', 0); |
|---|
| 19 |
$targetid = request_var('targetid', 0); |
|---|
| 20 |
$state = request_var('state', 0); |
|---|
| 21 |
$current_reputation = request_var('current_reputation', ''); |
|---|
| 22 |
|
|---|
| 23 |
if ( !isset($ranks) ) { |
|---|
| 24 |
$ranks = $cache->obtain_ranks(); |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 27 |
foreach ( $ranks AS $rank_id => $rank_ary ) { |
|---|
| 28 |
if ( $rank_id == $userdata['user_rank_id'] ) { |
|---|
| 29 |
$rank_settings = $rank_ary; |
|---|
| 30 |
break; |
|---|
| 31 |
} |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
if ( $rank_settings['rank_simpaty_limit'] == 0 ) { |
|---|
| 35 |
return $_RESULT = array( 'status' => 'error', 'errorMessage' => $lang['no_simpaty_low_level'] ); |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
$todayTime = strtotime('today'); |
|---|
| 39 |
|
|---|
| 40 |
$sql = 'SELECT COUNT(*) AS resp_count |
|---|
| 41 |
FROM ' . SIMPATY_TABLE . ' |
|---|
| 42 |
WHERE fromuserid = ' . $userdata['uid'] . ' AND respect_time >= ' . $todayTime; |
|---|
| 43 |
$result = $db->sql_query($sql); |
|---|
| 44 |
$count = ( $row = $db->sql_fetchrow($result) ) ? $row['resp_count'] : 0; |
|---|
| 45 |
|
|---|
| 46 |
if ( $count >= $rank_settings['rank_simpaty_limit'] ) { |
|---|
| 47 |
return $_RESULT = array( 'status' => 'error', 'errorMessage' => sprintf($lang['you_reached_simpaty_limit'], $rank_settings['rank_simpaty_limit'], create_date($todayTime + 1 * 24 * 60 * 60 + 1, 'Y-m-d H:i:s') ) ); |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
$sql = 'SELECT COUNT(*) AS resp_count FROM ' . SIMPATY_TABLE . ' WHERE fromuserid = ' . $userdata['uid'] . ' AND simpid = ' . $targetid . ' AND type = ' . $resp_type; |
|---|
| 51 |
$result = $db->sql_query($sql); |
|---|
| 52 |
$count = ( $row = $db->sql_fetchrow($result) ) ? $row['resp_count'] : 0; |
|---|
| 53 |
if ( $count ) { |
|---|
| 54 |
return $_RESULT = array( 'status' => 'error', 'errorMessage' => $lang['already_simpaty'] ); |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
$state_upd = ( $state == 1 ? 1 : -1 ); |
|---|
| 58 |
|
|---|
| 59 |
switch ( $resp_type ) { |
|---|
| 60 |
case SIMPATY_COMMENT: |
|---|
| 61 |
$sql = 'SELECT comment_user AS user_id, user_reputation, user_reputation_level, user_rank_id, uid |
|---|
| 62 |
FROM ' . COMMENTS_TABLE . ' c, ' . USERS_TABLE . ' u |
|---|
| 63 |
WHERE c.comment_user = u.uid |
|---|
| 64 |
AND comment_id = ' . $targetid; |
|---|
| 65 |
|
|---|
| 66 |
$sql_update_1 = 'UPDATE ' . COMMENTS_TABLE . ' SET comment_reputation = comment_reputation + ' . $state_upd . ' WHERE comment_id = ' . $targetid; |
|---|
| 67 |
break; |
|---|
| 68 |
|
|---|
| 69 |
case SIMPATY_FORUM_POST: |
|---|
| 70 |
$sql = 'SELECT poster_id AS user_id, user_reputation, user_reputation_level, user_rank_id, uid |
|---|
| 71 |
FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u |
|---|
| 72 |
WHERE p.poster_id = u.uid |
|---|
| 73 |
AND post_id = ' . $targetid; |
|---|
| 74 |
|
|---|
| 75 |
$sql_update_1 = 'UPDATE ' . POSTS_TABLE . ' SET post_reputation = post_reputation + ' . $state_upd . ' WHERE post_id = ' . $targetid; |
|---|
| 76 |
break; |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
$result = $db->sql_query($sql); |
|---|
| 80 |
|
|---|
| 81 |
if ( !$row = $db->sql_fetchrow($result) ) { |
|---|
| 82 |
return $_RESULT = array( 'status' => 'error', 'errorMessage' => sprintf($lang['invalid_id'], $targetid) ); |
|---|
| 83 |
} |
|---|
| 84 |
else { |
|---|
| 85 |
if ( $row['user_id'] == $userdata['uid'] ) { |
|---|
| 86 |
return $_RESULT = array( 'status' => 'error', 'errorMessage' => $lang['no_simpaty_to_your_self'] ); |
|---|
| 87 |
} |
|---|
| 88 |
if ( $row['user_id'] == ANONYMOUS ) { |
|---|
| 89 |
return $_RESULT = array( 'status' => 'error', 'errorMessage' => sprintf($lang['invalid_id'], $targetid) ); |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
$db->sql_query($sql_update_1); |
|---|
| 93 |
|
|---|
| 94 |
update_reputation($row, $resp_type, $state); |
|---|
| 95 |
|
|---|
| 96 |
$ins_ary = array( |
|---|
| 97 |
'touserid' => $row['user_id'], |
|---|
| 98 |
'fromuserid' => $userdata['uid'], |
|---|
| 99 |
'simpaty' => $state, |
|---|
| 100 |
'type' => $resp_type, |
|---|
| 101 |
'simpid' => $targetid, |
|---|
| 102 |
'respect_time' => $current_time |
|---|
| 103 |
); |
|---|
| 104 |
|
|---|
| 105 |
$sql = 'INSERT INTO ' . SIMPATY_TABLE . ' ' . $db->sql_build_array('INSERT', $ins_ary); |
|---|
| 106 |
$db->sql_query($sql); |
|---|
| 107 |
|
|---|
| 108 |
$sql = 'SELECT s.simpaty, u.name, u.uid |
|---|
| 109 |
FROM ' . SIMPATY_TABLE . ' s, ' . USERS_TABLE . ' u |
|---|
| 110 |
WHERE s.fromuserid = u.uid |
|---|
| 111 |
AND simpid = ' . $targetid . ' |
|---|
| 112 |
AND type = ' . $resp_type; |
|---|
| 113 |
$result = $db->sql_query($sql); |
|---|
| 114 |
|
|---|
| 115 |
$userslist = ''; |
|---|
| 116 |
while ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 117 |
$userslist .= ( $userslist ? ', ' : '' ); |
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
$seo->set_user_url($row['name'], $row['uid']); |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
$userslist .= '<a href="' . append_sid($root_path . 'userdetails.php?id=' . $row['uid']) . '"><span class="' . ( $row['simpaty'] ? 'usergoodResp' : 'userbadResp' ) . '">' . $row['name'] . '</span></a>'; |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
return $_RESULT = array( 'status' => 'ok', 'respCount' => $current_reputation + $state_upd, 'userList' => $userslist ); |
|---|
| 127 |
} |
|---|
| 128 |
} |
|---|
| 129 |
else { |
|---|
| 130 |
trigger_error($lang['bad_type']); |
|---|
| 131 |
} |
|---|
| 132 |
?> |
|---|